Skip to content

Commit 7b09cc5

Browse files
Pavel TatashinIngo Molnar
authored andcommitted
sched/clock: Fix broken stable to unstable transfer
When it is determined that the clock is actually unstable, and we switch from stable to unstable, the __clear_sched_clock_stable() function is eventually called. In this function we set gtod_offset so the following holds true: sched_clock() + raw_offset == ktime_get_ns() + gtod_offset But instead of getting the latest timestamps, we use the last values from scd, so instead of sched_clock() we use scd->tick_raw, and instead of ktime_get_ns() we use scd->tick_gtod. However, later, when we use gtod_offset sched_clock_local() we do not add it to scd->tick_gtod to calculate the correct clock value when we determine the boundaries for min/max clocks. This can result in tick granularity sched_clock() values, so fix it. Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: hpa@zytor.com Fixes: 5680d80 ("sched/clock: Provide better clock continuity") Link: http://lkml.kernel.org/r/1490214265-899964-2-git-send-email-pasha.tatashin@oracle.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 698eff6 commit 7b09cc5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kernel/sched/clock.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static inline u64 wrap_max(u64 x, u64 y)
221221
*/
222222
static u64 sched_clock_local(struct sched_clock_data *scd)
223223
{
224-
u64 now, clock, old_clock, min_clock, max_clock;
224+
u64 now, clock, old_clock, min_clock, max_clock, gtod;
225225
s64 delta;
226226

227227
again:
@@ -238,9 +238,10 @@ static u64 sched_clock_local(struct sched_clock_data *scd)
238238
* scd->tick_gtod + TICK_NSEC);
239239
*/
240240

241-
clock = scd->tick_gtod + __gtod_offset + delta;
242-
min_clock = wrap_max(scd->tick_gtod, old_clock);
243-
max_clock = wrap_max(old_clock, scd->tick_gtod + TICK_NSEC);
241+
gtod = scd->tick_gtod + __gtod_offset;
242+
clock = gtod + delta;
243+
min_clock = wrap_max(gtod, old_clock);
244+
max_clock = wrap_max(old_clock, gtod + TICK_NSEC);
244245

245246
clock = wrap_max(clock, min_clock);
246247
clock = wrap_min(clock, max_clock);

0 commit comments

Comments
 (0)