提交 a386b5af 编写于 作者: K Kasper Pedersen 提交者: Thomas Gleixner

time: Compensate for rounding on odd-frequency clocksources

When the clocksource is not a multiple of HZ, the clock will be off.  For
acpi_pm, HZ=1000 the error is 127.111 ppm:

The rounding of cycle_interval ends up generating a false error term in
ntp_error accumulation since xtime_interval is not exactly 1/HZ.  So, we
subtract out the error caused by the rounding.

This has been visible since 2.6.32-rc2
	commit a092ff0f
	time: Implement logarithmic time accumulation
That commit raised NTP_INTERVAL_FREQ and exposed the rounding error.

testing tool: http://n1.taur.dk/permanent/testpmt.c
Also tested with ntpd and a frequency counter.
Signed-off-by: NKasper Pedersen <kkp2010@kasperkp.dk>
Acked-by: Njohn stultz <johnstul@us.ibm.com>
Cc: John Kacur <jkacur@redhat.com>
Cc: Clark Williams <williams@redhat.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
上级 8af3c153
...@@ -32,6 +32,8 @@ struct timekeeper { ...@@ -32,6 +32,8 @@ struct timekeeper {
cycle_t cycle_interval; cycle_t cycle_interval;
/* Number of clock shifted nano seconds in one NTP interval. */ /* Number of clock shifted nano seconds in one NTP interval. */
u64 xtime_interval; u64 xtime_interval;
/* shifted nano seconds left over when rounding cycle_interval */
s64 xtime_remainder;
/* Raw nano seconds accumulated per NTP interval. */ /* Raw nano seconds accumulated per NTP interval. */
u32 raw_interval; u32 raw_interval;
...@@ -62,7 +64,7 @@ struct timekeeper timekeeper; ...@@ -62,7 +64,7 @@ struct timekeeper timekeeper;
static void timekeeper_setup_internals(struct clocksource *clock) static void timekeeper_setup_internals(struct clocksource *clock)
{ {
cycle_t interval; cycle_t interval;
u64 tmp; u64 tmp, ntpinterval;
timekeeper.clock = clock; timekeeper.clock = clock;
clock->cycle_last = clock->read(clock); clock->cycle_last = clock->read(clock);
...@@ -70,6 +72,7 @@ static void timekeeper_setup_internals(struct clocksource *clock) ...@@ -70,6 +72,7 @@ static void timekeeper_setup_internals(struct clocksource *clock)
/* Do the ns -> cycle conversion first, using original mult */ /* Do the ns -> cycle conversion first, using original mult */
tmp = NTP_INTERVAL_LENGTH; tmp = NTP_INTERVAL_LENGTH;
tmp <<= clock->shift; tmp <<= clock->shift;
ntpinterval = tmp;
tmp += clock->mult/2; tmp += clock->mult/2;
do_div(tmp, clock->mult); do_div(tmp, clock->mult);
if (tmp == 0) if (tmp == 0)
...@@ -80,6 +83,7 @@ static void timekeeper_setup_internals(struct clocksource *clock) ...@@ -80,6 +83,7 @@ static void timekeeper_setup_internals(struct clocksource *clock)
/* Go back from cycles -> shifted ns */ /* Go back from cycles -> shifted ns */
timekeeper.xtime_interval = (u64) interval * clock->mult; timekeeper.xtime_interval = (u64) interval * clock->mult;
timekeeper.xtime_remainder = ntpinterval - timekeeper.xtime_interval;
timekeeper.raw_interval = timekeeper.raw_interval =
((u64) interval * clock->mult) >> clock->shift; ((u64) interval * clock->mult) >> clock->shift;
...@@ -719,7 +723,8 @@ static cycle_t logarithmic_accumulation(cycle_t offset, int shift) ...@@ -719,7 +723,8 @@ static cycle_t logarithmic_accumulation(cycle_t offset, int shift)
/* Accumulate error between NTP and clock interval */ /* Accumulate error between NTP and clock interval */
timekeeper.ntp_error += tick_length << shift; timekeeper.ntp_error += tick_length << shift;
timekeeper.ntp_error -= timekeeper.xtime_interval << timekeeper.ntp_error -=
(timekeeper.xtime_interval + timekeeper.xtime_remainder) <<
(timekeeper.ntp_error_shift + shift); (timekeeper.ntp_error_shift + shift);
return offset; return offset;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册