Time: Experimental improved ntp error accounting for TOD work
Subsystems (3)
RFC PATCH 1/1 Time: Experimental improved ntp error accounting for TOD work
All,
This includes suggestions from Roman on improving the NTP error
accounting done by the timekeeping core. Currently this is a very ugly patch, that hurts the code's readability (which should not to be taken as a slight against Roman, this is my own interpretation of his suggestion) but I wanted to get it out for review and comment. I've added lots of comments just to document my current concerns that will be removed in the future, as well a number of spots where Roman's NTP patches will hopefully be used.
The patch drops the ntp_adj value, letting the code adjust the clocksource multiplier directly, and also uses clock shifted nanoseconds in a few places.
Unfortunately this patch does not apply against the current -mm tree, so you will have to grab the full patchset from:
http://sr71.net/~jstultz/tod/ to play with this.
Anyway, I'm kicking it out because I don't want to sit on it any longer. I think I've got the bugs out of it, but I'm sure it needs more work.
Flame on.
thanks
-john
Documentation/timekeeping.txt | 22 +--- include/asm-generic/timeofday.h | 5 - include/linux/clocksource.h | 185 +++++++++++++++++++--------------------- kernel/time/timeofday.c | 140 ++++++++++++++---------------- 4 files changed, 167 insertions(+), 185 deletions(-)
linux-2.6.16-rc4_timeofday-ntp-error-fix_B19.patch
============================================
Documentation/timekeeping.txt +7 -15
@@ -37,12 +37,6 @@ this value in cycle_last. cycle_t cycle_last; -Further since all clocks drift somewhat from each other, we use the adjustment -values provided via adjtimex() to correct our clocksource frequency for each -interval. This frequency adjustment value is stored in ntp_adj. - -long ntp_adj; - Now that we've covered the core global variables for timekeeping, lets look at how we maintain these values.
@@ -54,7 +48,7 @@ presented as: timeofday_periodic_hook(): cycle_now = read_clocksource(clock) cycle_delta = (cycle_now - cycle_last) & clock->mask - nsec = cyc2ns(clock, cycle_delta, ntp_adj) + nsec = cyc2ns(clock, cycle_delta) system_time += nsec cycle_last = cycle_now
@@ -62,10 +56,9 @@ timeofday_periodic_hook(): You can see we read the cycle value from the clocksource, calculate a cycle delta for the interval since we last called timeofday_periodic_hook(), convert -that cycle delta to a nanosecond interval (for now ignore ntp_adj), add it to -the system time and finally set our cycle_last value to cycle_now for the next -interval. Using this simple algorithm we can correctly measure and record the -passing of time. +that cycle delta to a nanosecond interval, add it to the system time and finally +set our cycle_last value to cycle_now for the next interval. Using this simple +algorithm we can correctly measure and record the passing of time. But just storing this info isn't very useful, we also want to make it available to be used elsewhere. So how do we provide a notion of how much time has passed
@@ -77,7 +70,7 @@ timeofday_peridoic_hook(). get_nsec_offset(): cycle_now = read_clocksource(clock) cycle_delta = (cycle_now - cycle_last) & clock->mask - nsec = cyc2ns(clock, cycle_delta, ntp_adj) + nsec = cyc2ns(clock, cycle_delta) return nsec Here you can see, we read the clocksource, calculate a cycle interval, and
@@ -119,14 +112,14 @@ at a safe point, we use the update_callb see "How to write a clocksource driver" below), this too must be done in-between intervals in the periodic_hook call. Finally, since the ntp adjustment made in the cyc2ns conversion is not static, we need to update the -ntp state machine and get a calculate a new adjustment value. +ntp state machine and adjust the clocksource mult value. This adds some extra pseudo code to the timeofday_periodic_hook function: timeofday_periodic_hook(): cycle_now = read_clocksource(clock) cycle_delta = (cycle_now - cycle_last) & clock->mask - nsec = cyc2ns(clock, cycle_delta, ntp_adj) + nsec = cyc2ns(clock, cycle_delta) system_time += nsec cycle_last = cycle_now
@@ -140,7 +133,6 @@ timeofday_periodic_hook(): ntp_advance(nsec) ppm = ntp_get_ppm_adjustment() - ntp_adj = ppm_to_mult_adj(clock, ppm) Unfortunately, the actual timeofday_periodic_hook code is not as simple as this
include/asm-generic/timeofday.h +2 -3
@@ -20,10 +20,9 @@ extern void sync_persistent_clock(struct#ifdef CONFIG_GENERIC_TIME_VSYSCALL extern void arch_update_vsyscall_gtod (struct timespec wall_time, -cycle_t offset_base,struct clocksource * clock, -int ntp_adj); +cycle_t offset_base,struct clocksource * clock);#else -# define arch_update_vsyscall_gtod (x,y,z,w) do { } while(0) +# define arch_update_vsyscall_gtod (x,y,z) do { } while(0)#endif /* CONFIG_GENERIC_TIME_VSYSCALL */ #endif /* CONFIG_GENERIC_TIME */
include/linux/clocksource.h +89 -96
258 lines not on this page · raw message
kernel/time/timeofday.c +69 -71
240 lines not on this page · raw message