From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>,
Steven Rostedt <srostedt@redhat.com>, Ingo Molnar <mingo@elte.hu>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] sched_clock: prevent scd->clock from moving backwards
Date: Thu, 09 Oct 2008 01:05:04 +0200 [thread overview]
Message-ID: <1223507104.7382.6.camel@lappy.programming.kicks-ass.net> (raw)
In-Reply-To: <1223470854.6336.15.camel@norville.austin.ibm.com>
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@linux.vnet.ibm.com>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
>
> diff --git a/kernel/sched_clock.c b/kernel/sched_clock.c
> index e8ab096..a989d64 100644
> --- a/kernel/sched_clock.c
> +++ b/kernel/sched_clock.c
> @@ -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),
> + * min(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_min(scd->clock, scd->tick_gtod + TICK_NSEC);
>
> clock = wrap_max(clock, min_clock);
> clock = wrap_min(clock, max_clock);
>
>
next prev parent reply other threads:[~2008-10-08 23:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-23 21:04 Definition of sched_clock broken Jeremy Fitzhardinge
2008-10-08 12:59 ` Dave Kleikamp
2008-10-08 13:00 ` [PATCH] sched_clock: prevent scd->clock from moving backwards Dave Kleikamp
2008-10-08 23:05 ` Peter Zijlstra [this message]
2008-10-09 9:06 ` Ingo Molnar
2008-10-09 15:17 ` Ingo Molnar
2008-10-09 17:54 ` Dave Kleikamp
2008-10-09 18:21 ` Dave Kleikamp
2008-10-10 9:17 ` Ingo Molnar
2008-10-09 21:22 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1223507104.7382.6.camel@lappy.programming.kicks-ass.net \
--to=a.p.zijlstra@chello.nl \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=shaggy@linux.vnet.ibm.com \
--cc=srostedt@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox