sched_clock: fix jiffie fallback clock
PATCH 1/1 sched_clock: fix jiffie fallback clock
David pointed out that the default sched_clock() fallback is broken in that it wraps too soon. Fix this by using the 64 bit jiffie value so that we're large enough to overflow properly.
--- arch/x86/kernel/tsc.c | 6 ++---- kernel/sched_clock.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
arch/x86/kernel/tsc.c +2 -4
@@ -46,10 +46,8 @@ u64 native_sched_clock(void)* very important for it to be as fast as the platform * can achive it. ) */ -if (unlikely (tsc_disabled)) { -/* No locking but a rare wrong value is not a big deal: */ -return (jiffies_64 -INITIAL_JIFFIES ) * (1000000000 /HZ ); - } +if (unlikely (tsc_disabled)) +return (get_jiffies_64 () -INITIAL_JIFFIES ) * (NSEC_PER_SEC /HZ );/* read the Time Stamp Counter: */ rdtscll (this_offset);
kernel/sched_clock.c +1 -1
@@ -38,7 +38,7 @@*/ unsigned long long __attribute__((weak))sched_clock (void ) { -return (unsigned long long )jiffies * (NSEC_PER_SEC /HZ ); +return (get_jiffies_64 () -INITIAL_JIFFIES ) * (NSEC_PER_SEC /HZ ); }static __read_mostly int sched_clock_running;
Ingo Molnar
AppliedQuoted 6 lines · Peter Zijlstra
David pointed out that the default
sched_clock()fallback is broken in that it wraps too soon. Fix this by using the 64 bit jiffie value so that we're large enough to overflow properly.Signed-off-by Peter Zijlstra <[email protected]>CC David Howells <[email protected]>
applied to tip/sched/urgent, thanks Peter!
Ingo
Quoted 6 lines · Peter Zijlstra
David pointed out that the default
sched_clock()fallback is broken in that it wraps too soon. Fix this by using the 64 bit jiffie value so that we're large enough to overflow properly.Signed-off-by Peter Zijlstra <[email protected]>CC David Howells <[email protected]>
FYI, -tip testing found bootup hard-lockups today on 32-bit testsystems.
I've bisected it down to this change. After some head-scratching and an hour of debugging, it turns out that this aspect:
arch/x86/kernel/tsc.c u64 native_sched_clock(void) · line 50
Quoted 10 lines
arch/x86/kernel/tsc.c +2
-4@@ -46,10 +46,8 @@ u64 native_sched_clock(void)* very important for it to be as fast as the platform * can achive it. ) */ -if (unlikely (tsc_disabled)) { -/* No locking but a rare wrong value is not a big deal: */ -return (jiffies_64 -INITIAL_JIFFIES ) * (1000000000 /HZ ); - } +if (unlikely (tsc_disabled)) +return (get_jiffies_64 () -INITIAL_JIFFIES ) * (NSEC_PER_SEC /HZ );
is the buggy one: it calls get_jiffies_64() which does:
seq = read_seqbegin(&xtime_lock);
that's not a very wise thing to do within xtime-locked sections - and we do call cpu_clock()/sched_clock() in a number of xtime-locked sections.
So i've zapped this commit for the time being, this needs to be solved differently.
Ingo