From: Martin Schwidefsky <schwidefsky@de.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
john stultz <johnstul@us.ibm.com>,
Daniel Walker <dwalker@fifo99.com>,
Martin Schwidefsky <schwidefsky@de.ibm.com>
Subject: [RFC][patch 09/12] add xtime_shift and ntp_error_shift to struct timekeeper
Date: Wed, 29 Jul 2009 15:41:34 +0200 [thread overview]
Message-ID: <20090729134231.269077552@de.ibm.com> (raw)
In-Reply-To: 20090729134125.313191633@de.ibm.com
[-- Attachment #1: timekeeper-shift.diff --]
[-- Type: text/plain, Size: 4897 bytes --]
From: Martin Schwidefsky <schwidefsky@de.ibm.com>
The xtime_nsec value in the timekeeper structure is shifted by a few
bits to improve precision. This happens to be the same value as the
clock->shift. To improve readability add xtime_shift to the timekeeper
and use it instead of the clock->shift. Likewise add ntp_error_shift
and replace all (NTP_SCALE_SHIFT - clock->shift) expressions.
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: john stultz <johnstul@us.ibm.com>
Cc: Daniel Walker <dwalker@fifo99.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
---
kernel/time/timekeeping.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
Index: linux-2.6/kernel/time/timekeeping.c
===================================================================
--- linux-2.6.orig/kernel/time/timekeeping.c
+++ linux-2.6/kernel/time/timekeeping.c
@@ -27,6 +27,8 @@ struct timekeeper {
u32 raw_interval;
u64 xtime_nsec;
s64 ntp_error;
+ int xtime_shift;
+ int ntp_error_shift;
};
struct timekeeper timekeeper;
@@ -66,8 +68,10 @@ static void timekeeper_setup_internals(s
((u64) interval * clock->mult_orig) >> clock->shift;
timekeeper.xtime_nsec = 0;
+ timekeeper.xtime_shift = clock->shift;
timekeeper.ntp_error = 0;
+ timekeeper.ntp_error_shift = NTP_SCALE_SHIFT - clock->shift;
}
/*
@@ -621,8 +625,7 @@ static __always_inline int timekeeping_b
* Now calculate the error in (1 << look_ahead) ticks, but first
* remove the single look ahead already included in the error.
*/
- tick_error = tick_length >>
- (NTP_SCALE_SHIFT - timekeeper.clock->shift + 1);
+ tick_error = tick_length >> (timekeeper.ntp_error_shift + 1);
tick_error -= timekeeper.xtime_interval >> 1;
error = ((error - tick_error) >> look_ahead) + tick_error;
@@ -653,8 +656,7 @@ static void timekeeping_adjust(s64 offse
s64 error, interval = timekeeper.cycle_interval;
int adj;
- error = timekeeper.ntp_error >>
- (NTP_SCALE_SHIFT - timekeeper.clock->shift - 1);
+ error = timekeeper.ntp_error >> (timekeeper.ntp_error_shift - 1);
if (error > interval) {
error >>= 2;
if (likely(error <= interval))
@@ -676,7 +678,7 @@ static void timekeeping_adjust(s64 offse
timekeeper.xtime_interval += interval;
timekeeper.xtime_nsec -= offset;
timekeeper.ntp_error -= (interval - offset) <<
- (NTP_SCALE_SHIFT - timekeeper.clock->shift);
+ timekeeper.ntp_error_shift;
}
/**
@@ -688,7 +690,7 @@ void update_wall_time(void)
{
struct clocksource *clock;
cycle_t offset;
- s64 nsecs;
+ u64 nsecs;
/* Make sure we're fully resumed: */
if (unlikely(timekeeping_suspended))
@@ -700,7 +702,7 @@ void update_wall_time(void)
#else
offset = timekeeper.cycle_interval;
#endif
- timekeeper.xtime_nsec = (s64)xtime.tv_nsec << clock->shift;
+ timekeeper.xtime_nsec = (s64)xtime.tv_nsec << timekeeper.xtime_shift;
/* normally this loop will run just once, however in the
* case of lost or late ticks, it will accumulate correctly.
@@ -711,8 +713,9 @@ void update_wall_time(void)
clock->cycle_last += timekeeper.cycle_interval;
timekeeper.xtime_nsec += timekeeper.xtime_interval;
- if (timekeeper.xtime_nsec >= (u64)NSEC_PER_SEC << clock->shift) {
- timekeeper.xtime_nsec -= (u64)NSEC_PER_SEC << clock->shift;
+ nsecs = (u64) NSEC_PER_SEC << timekeeper.xtime_shift;
+ if (timekeeper.xtime_nsec >= nsecs) {
+ timekeeper.xtime_nsec -= nsecs;
xtime.tv_sec++;
second_overflow();
}
@@ -726,7 +729,7 @@ void update_wall_time(void)
/* accumulate error between NTP and clock interval */
timekeeper.ntp_error += tick_length;
timekeeper.ntp_error -= timekeeper.xtime_interval <<
- (NTP_SCALE_SHIFT - clock->shift);
+ timekeeper.ntp_error_shift;
}
/* correct the clock when NTP error is too big */
@@ -751,16 +754,16 @@ void update_wall_time(void)
if (unlikely((s64)timekeeper.xtime_nsec < 0)) {
s64 neg = -(s64)timekeeper.xtime_nsec;
timekeeper.xtime_nsec = 0;
- timekeeper.ntp_error += neg << (NTP_SCALE_SHIFT - clock->shift);
+ timekeeper.ntp_error += neg << timekeeper.ntp_error_shift;
}
/* store full nanoseconds into xtime after rounding it up and
* add the remainder to the error difference.
*/
- xtime.tv_nsec = ((s64)timekeeper.xtime_nsec >> clock->shift) + 1;
- timekeeper.xtime_nsec -= (s64)xtime.tv_nsec << clock->shift;
- timekeeper.ntp_error += timekeeper.xtime_nsec <<
- (NTP_SCALE_SHIFT - clock->shift);
+ xtime.tv_nsec = ((s64) timekeeper.xtime_nsec >> timekeeper.xtime_shift) + 1;
+ timekeeper.xtime_nsec -= (s64) xtime.tv_nsec << timekeeper.xtime_shift;
+ timekeeper.ntp_error += timekeeper.xtime_nsec <<
+ timekeeper.ntp_error_shift;
nsecs = clocksource_cyc2ns(offset, clock->mult, clock->shift);
update_xtime_cache(nsecs);
--
blue skies,
Martin.
"Reality continues to ruin my life." - Calvin.
next prev parent reply other threads:[~2009-07-29 13:45 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-29 13:41 [RFC][patch 00/12] clocksource / timekeeping rework V2 Martin Schwidefsky
2009-07-29 13:41 ` [RFC][patch 01/12] introduce timekeeping_leap_insert Martin Schwidefsky
2009-07-30 21:02 ` john stultz
2009-07-29 13:41 ` [RFC][patch 02/12] remove clocksource inline functions Martin Schwidefsky
2009-07-29 14:15 ` Daniel Walker
2009-07-30 21:46 ` Christoph Hellwig
2009-07-30 21:05 ` john stultz
2009-07-29 13:41 ` [RFC][patch 03/12] cleanup clocksource selection Martin Schwidefsky
2009-07-29 13:41 ` [RFC][patch 04/12] clocksource watchdog highres enablement Martin Schwidefsky
2009-07-29 13:41 ` [RFC][patch 05/12] clocksource watchdog resume logic Martin Schwidefsky
2009-07-29 13:41 ` [RFC][patch 06/12] clocksource watchdog refactoring Martin Schwidefsky
2009-07-29 13:41 ` [RFC][patch 07/12] clocksource watchdog work Martin Schwidefsky
2009-07-29 13:41 ` [RFC][patch 08/12] introduce struct timekeeper Martin Schwidefsky
2009-07-29 13:41 ` Martin Schwidefsky [this message]
2009-07-30 22:15 ` [RFC][patch 09/12] add xtime_shift and ntp_error_shift to " john stultz
2009-07-31 8:13 ` Martin Schwidefsky
2009-07-29 13:41 ` [RFC][patch 10/12] move NTP adjusted clock multiplier " Martin Schwidefsky
2009-07-30 22:04 ` john stultz
2009-07-31 7:52 ` Martin Schwidefsky
2009-07-31 8:12 ` john stultz
2009-07-31 8:27 ` Martin Schwidefsky
2009-07-31 9:00 ` Martin Schwidefsky
2009-07-31 23:32 ` john stultz
2009-08-03 8:02 ` Martin Schwidefsky
2009-08-13 11:15 ` Linus Walleij
2009-08-13 11:23 ` Martin Schwidefsky
2009-07-29 13:41 ` [RFC][patch 11/12] timekeeper read clock helper functions Martin Schwidefsky
2009-07-30 21:39 ` john stultz
2009-07-31 7:45 ` Martin Schwidefsky
2009-07-31 8:11 ` john stultz
2009-07-29 13:41 ` [RFC][patch 12/12] update clocksource with stop_machine Martin Schwidefsky
2009-07-29 15:10 ` [RFC][patch 00/12] clocksource / timekeeping rework V2 Daniel Walker
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=20090729134231.269077552@de.ibm.com \
--to=schwidefsky@de.ibm.com \
--cc=dwalker@fifo99.com \
--cc=johnstul@us.ibm.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