From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Ingo Molnar <mingo@elte.hu>, David Howells <dhowells@redhat.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] sched_clock: fix jiffie fallback clock
Date: Mon, 15 Sep 2008 20:26:19 +0200 [thread overview]
Message-ID: <1221503179.7154.2.camel@lappy.programming.kicks-ass.net> (raw)
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;
next reply other threads:[~2008-09-15 18:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-15 18:26 Peter Zijlstra [this message]
2008-09-17 10:05 ` Ingo Molnar
2008-09-17 19:10 ` 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=1221503179.7154.2.camel@lappy.programming.kicks-ass.net \
--to=a.p.zijlstra@chello.nl \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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
all inboxes | Powered by JetHome®