Re: [PATCH] sched_clock: prevent scd->clock from moving backwards
From: Ingo Molnar
Date: Thu Oct 09 2008 - 05:07:30 EST
* Peter Zijlstra <a.p.zijlstra@xxxxxxxxx> wrote:
> On Wed, 2008-10-08 at 08:00 -0500, Dave Kleikamp wrote:
> > sched_clock: prevent scd->clock from moving backwards
> >
> > 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.
>
> Ah, yes indeed, this comes from the tick not happening at the same time
> on different cpus, so if we use a local timestamp to move a remote clock
> forward, this scenario could indeed happen.
>
> The fix looks good to me, good catch, thanks shaggy!
>
> A related 'fix' which I'm still not quite sure about is making the
> window 'tick_gtod + 2*TICK_NSEC'. That increases the max observed
> difference to 4 jiffies, but allows ticks to be 'late' a bit without
> first holding back time and then jumping ahead again.
>
> > Signed-off-by: Dave Kleikamp <shaggy@xxxxxxxxxxxxxxxxxx>
> > Cc: Ingo Molnar <mingo@xxxxxxx>
> > Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
>
> Acked-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
applied to tip/sched/core, thanks!
Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/