diff options
author | john stultz <johnstul@us.ibm.com> | 2006-06-26 03:25:07 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-26 12:58:20 -0400 |
commit | 260a42309b31cbc54eb4b6b85649e412bcad053f (patch) | |
tree | 51efc7bb51075b0d25d0e8465d3c056e6a57fe16 | |
parent | ad596171ed635c51a9eef829187af100cbf8dcf7 (diff) |
[PATCH] Time: Let user request precision from current_tick_length()
Change the current_tick_length() function so it takes an argument which
specifies how much precision to return in shifted nanoseconds. This provides
a simple way to convert between NTPs internal nanoseconds shifted by
(SHIFT_SCALE - 10) to other shifted nanosecond units that are used by the
clocksource abstraction.
Signed-off-by: John Stultz <johnstul@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | arch/powerpc/kernel/time.c | 2 | ||||
-rw-r--r-- | include/linux/timex.h | 2 | ||||
-rw-r--r-- | kernel/timer.c | 21 |
3 files changed, 19 insertions, 6 deletions
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c index d20907561f46..742f07a63161 100644 --- a/arch/powerpc/kernel/time.c +++ b/arch/powerpc/kernel/time.c | |||
@@ -534,7 +534,7 @@ static __inline__ void timer_recalc_offset(u64 cur_tb) | |||
534 | 534 | ||
535 | if (__USE_RTC()) | 535 | if (__USE_RTC()) |
536 | return; | 536 | return; |
537 | tlen = current_tick_length(); | 537 | tlen = current_tick_length(SHIFT_SCALE - 10); |
538 | offset = cur_tb - do_gtod.varp->tb_orig_stamp; | 538 | offset = cur_tb - do_gtod.varp->tb_orig_stamp; |
539 | if (tlen == last_tick_len && offset < 0x80000000u) | 539 | if (tlen == last_tick_len && offset < 0x80000000u) |
540 | return; | 540 | return; |
diff --git a/include/linux/timex.h b/include/linux/timex.h index 34d3ccff7bbb..1ba3071fcb82 100644 --- a/include/linux/timex.h +++ b/include/linux/timex.h | |||
@@ -304,7 +304,7 @@ time_interpolator_reset(void) | |||
304 | #endif /* !CONFIG_TIME_INTERPOLATION */ | 304 | #endif /* !CONFIG_TIME_INTERPOLATION */ |
305 | 305 | ||
306 | /* Returns how long ticks are at present, in ns / 2^(SHIFT_SCALE-10). */ | 306 | /* Returns how long ticks are at present, in ns / 2^(SHIFT_SCALE-10). */ |
307 | extern u64 current_tick_length(void); | 307 | extern u64 current_tick_length(long); |
308 | 308 | ||
309 | extern int do_adjtimex(struct timex *); | 309 | extern int do_adjtimex(struct timex *); |
310 | 310 | ||
diff --git a/kernel/timer.c b/kernel/timer.c index 524c7f638365..623f9ea198d8 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
@@ -780,16 +780,29 @@ static void update_wall_time_one_tick(void) | |||
780 | * Return how long ticks are at the moment, that is, how much time | 780 | * Return how long ticks are at the moment, that is, how much time |
781 | * update_wall_time_one_tick will add to xtime next time we call it | 781 | * update_wall_time_one_tick will add to xtime next time we call it |
782 | * (assuming no calls to do_adjtimex in the meantime). | 782 | * (assuming no calls to do_adjtimex in the meantime). |
783 | * The return value is in fixed-point nanoseconds with SHIFT_SCALE-10 | 783 | * The return value is in fixed-point nanoseconds shifted by the |
784 | * bits to the right of the binary point. | 784 | * specified number of bits to the right of the binary point. |
785 | * This function has no side-effects. | 785 | * This function has no side-effects. |
786 | */ | 786 | */ |
787 | u64 current_tick_length(void) | 787 | u64 current_tick_length(long shift) |
788 | { | 788 | { |
789 | long delta_nsec; | 789 | long delta_nsec; |
790 | u64 ret; | ||
790 | 791 | ||
792 | /* calculate the finest interval NTP will allow. | ||
793 | * ie: nanosecond value shifted by (SHIFT_SCALE - 10) | ||
794 | */ | ||
791 | delta_nsec = tick_nsec + adjtime_adjustment() * 1000; | 795 | delta_nsec = tick_nsec + adjtime_adjustment() * 1000; |
792 | return ((u64) delta_nsec << (SHIFT_SCALE - 10)) + time_adj; | 796 | ret = ((u64) delta_nsec << (SHIFT_SCALE - 10)) + time_adj; |
797 | |||
798 | /* convert from (SHIFT_SCALE - 10) to specified shift scale: */ | ||
799 | shift = shift - (SHIFT_SCALE - 10); | ||
800 | if (shift < 0) | ||
801 | ret >>= -shift; | ||
802 | else | ||
803 | ret <<= shift; | ||
804 | |||
805 | return ret; | ||
793 | } | 806 | } |
794 | 807 | ||
795 | /* XXX - all of this timekeeping code should be later moved to time.c */ | 808 | /* XXX - all of this timekeeping code should be later moved to time.c */ |