]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
sched_clock: prevent scd->clock from moving backwards
authorDave Kleikamp <shaggy@linux.vnet.ibm.com>
Thu, 9 Oct 2008 18:21:30 +0000 (13:21 -0500)
committerIngo Molnar <mingo@elte.hu>
Fri, 10 Oct 2008 09:17:04 +0000 (11:17 +0200)
When sched_clock_cpu() couples the clocks between two cpus, it may
increment scd->clock beyond the GTOD tick window that __update_sched_clock()
uses to clamp the clock.  A later call to __update_sched_clock() may move
the clock back to scd->tick_gtod + TICK_NSEC, violating the clock's
monotonic property.

This patch ensures that scd->clock will not be set backward.

Signed-off-by: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
kernel/sched_clock.c

index e8ab096ddfe399dc3007e32b169b46d02ed9cb48..81787248b60fda5bc58b6231be84a6a54a763cb0 100644 (file)
@@ -118,13 +118,13 @@ static u64 __update_sched_clock(struct sched_clock_data *scd, u64 now)
 
        /*
         * scd->clock = clamp(scd->tick_gtod + delta,
-        *                    max(scd->tick_gtod, scd->clock),
-        *                    scd->tick_gtod + TICK_NSEC);
+        *                    max(scd->tick_gtod, scd->clock),
+        *                    max(scd->clock, scd->tick_gtod + TICK_NSEC));
         */
 
        clock = scd->tick_gtod + delta;
        min_clock = wrap_max(scd->tick_gtod, scd->clock);
-       max_clock = scd->tick_gtod + TICK_NSEC;
+       max_clock = wrap_max(scd->clock, scd->tick_gtod + TICK_NSEC);
 
        clock = wrap_max(clock, min_clock);
        clock = wrap_min(clock, max_clock);