* [PATCH] sched_clock: fix jiffie fallback clock
@ 2008-09-15 18:26 Peter Zijlstra
2008-09-17 10:05 ` Ingo Molnar
2008-09-17 19:10 ` Ingo Molnar
0 siblings, 2 replies; 3+ messages in thread
From: Peter Zijlstra @ 2008-09-15 18:26 UTC (permalink / raw)
To: Ingo Molnar, David Howells; +Cc: linux-kernel
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 <a.p.zijlstra@chello.nl>
CC: David Howells <dhowells@redhat.com>
---
arch/x86/kernel/tsc.c | 6 ++----
kernel/sched_clock.c | 2 +-
2 files changed, 3 insertions(+), 5 deletions(-)
Index: linux-2.6/arch/x86/kernel/tsc.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/tsc.c 2008-09-15 18:41:26.000000000 +0200
+++ linux-2.6/arch/x86/kernel/tsc.c 2008-09-15 18:41:33.000000000 +0200
@@ -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);
Index: linux-2.6/kernel/sched_clock.c
===================================================================
--- linux-2.6.orig/kernel/sched_clock.c 2008-09-15 18:41:26.000000000 +0200
+++ linux-2.6/kernel/sched_clock.c 2008-09-15 18:41:33.000000000 +0200
@@ -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;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] sched_clock: fix jiffie fallback clock
2008-09-15 18:26 [PATCH] sched_clock: fix jiffie fallback clock Peter Zijlstra
@ 2008-09-17 10:05 ` Ingo Molnar
2008-09-17 19:10 ` Ingo Molnar
1 sibling, 0 replies; 3+ messages in thread
From: Ingo Molnar @ 2008-09-17 10:05 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: David Howells, linux-kernel
* Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
> 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 <a.p.zijlstra@chello.nl>
> CC: David Howells <dhowells@redhat.com>
applied to tip/sched/urgent, thanks Peter!
Ingo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sched_clock: fix jiffie fallback clock
2008-09-15 18:26 [PATCH] sched_clock: fix jiffie fallback clock Peter Zijlstra
2008-09-17 10:05 ` Ingo Molnar
@ 2008-09-17 19:10 ` Ingo Molnar
1 sibling, 0 replies; 3+ messages in thread
From: Ingo Molnar @ 2008-09-17 19:10 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: David Howells, linux-kernel
* Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
> 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 <a.p.zijlstra@chello.nl>
> CC: David Howells <dhowells@redhat.com>
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:
> @@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-09-17 19:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-15 18:26 [PATCH] sched_clock: fix jiffie fallback clock Peter Zijlstra
2008-09-17 10:05 ` Ingo Molnar
2008-09-17 19:10 ` Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox