From: "Uwe Kleine-König" <Uwe.Kleine-Koenig@digi.com>
To: <linux-kernel@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@elte.hu>
Subject: [PATCH, RFC] use hrtimer in sched_clock
Date: Fri, 11 Jul 2008 22:55:27 +0200 [thread overview]
Message-ID: <1215809727-28598-1-git-send-email-Uwe.Kleine-Koenig@digi.com> (raw)
This should make it unnecessary to overwrite sched_clock for a higher
precision.
With this patch I get sub-jiffie timing with CONFIG_PRINTK_TIME=y.
Signed-off-by: Uwe Kleine-König <Uwe.Kleine-Koenig@digi.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
---
Hello,
I tested the patch on arch-arm/mach-ns9xxx and it seem seams to work.
But I admit I didn't test it deeply and I didn't measure if there is any
overhead.
Best regards
Uwe
kernel/sched_clock.c | 6 +++++-
kernel/time/timekeeping.c | 16 +++++++++-------
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/kernel/sched_clock.c b/kernel/sched_clock.c
index ce05271..12daf55 100644
--- a/kernel/sched_clock.c
+++ b/kernel/sched_clock.c
@@ -242,5 +242,9 @@ EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event);
*/
unsigned long long __attribute__((weak)) sched_clock(void)
{
- return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ);
+ struct timespec ts;
+
+ ktime_get_ts(&ts);
+
+ return (long long)ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec;
}
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index e91c29f..49412f2 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -67,16 +67,18 @@ struct clocksource *clock;
static inline s64 __get_nsec_offset(void)
{
cycle_t cycle_now, cycle_delta;
- s64 ns_offset;
+ s64 ns_offset = 0;
- /* read clocksource: */
- cycle_now = clocksource_read(clock);
+ if (likely(clock)) {
+ /* read clocksource: */
+ cycle_now = clocksource_read(clock);
- /* calculate the delta since the last update_wall_time: */
- cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
+ /* calculate the delta since the last update_wall_time: */
+ cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
- /* convert to nanoseconds: */
- ns_offset = cyc2ns(clock, cycle_delta);
+ /* convert to nanoseconds: */
+ ns_offset = cyc2ns(clock, cycle_delta);
+ }
return ns_offset;
}
--
1.5.6.2
next reply other threads:[~2008-07-11 20:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-11 20:55 Uwe Kleine-König [this message]
2008-07-14 9:30 ` Thomas Gleixner
2008-07-14 9:48 ` Uwe Kleine-König
2008-07-14 10:03 ` Thomas Gleixner
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=1215809727-28598-1-git-send-email-Uwe.Kleine-Koenig@digi.com \
--to=uwe.kleine-koenig@digi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
/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®