Skip to content

Commit

Permalink
sched_clock: widen the max and min time
Browse files Browse the repository at this point in the history
With keeping the max and min sched time within one jiffy of the gtod clock
was too tight. Just before a schedule tick the max could easily be hit, as
well as just after a schedule_tick the min could be hit. This caused the
clock to jump around by a jiffy.

This patch widens the minimum to
   last gtod + (delta_jiffies ? delta_jiffies - 1 : 0) * TICK_NSECS

and the maximum to
    last gtod + (2 + delta_jiffies) * TICK_NSECS

This keeps the minum to gtod or if one jiffy less than delta jiffies
and the maxim 2 jiffies ahead of gtod. This may cause unstable TSCs to be
a bit more sporadic, but it helps keep a clock with a stable TSC working well.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Cc: Steven Rostedt <srostedt@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Steven Rostedt authored and Ingo Molnar committed Jul 11, 2008
1 parent 62c43dd commit f7cce27
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions kernel/sched_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,21 @@ static void __update_sched_clock(struct sched_clock_data *scd, u64 now)
s64 delta = now - scd->prev_raw;

WARN_ON_ONCE(!irqs_disabled());
min_clock = scd->tick_gtod + delta_jiffies * TICK_NSEC;

min_clock = scd->tick_gtod +
(delta_jiffies ? delta_jiffies - 1 : 0) * TICK_NSEC;

if (unlikely(delta < 0)) {
clock++;
goto out;
}

max_clock = min_clock + TICK_NSEC;
/*
* The clock must stay within a jiffie of the gtod.
* But since we may be at the start of a jiffy or the end of one
* we add another jiffy buffer.
*/
max_clock = scd->tick_gtod + (2 + delta_jiffies) * TICK_NSEC;

if (unlikely(clock + delta > max_clock)) {
if (clock < max_clock)
Expand Down

0 comments on commit f7cce27

Please sign in to comment.