Bug 204748 - ntp wakes up once per second, that's overkill
Summary: ntp wakes up once per second, that's overkill
Alias: None
Product: Fedora
Classification: Fedora
Component: ntp
Version: rawhide
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Miroslav Lichvar
QA Contact: Brian Brock
Depends On:
Blocks: wakeup
TreeView+ depends on / blocked
Reported: 2006-08-31 12:35 UTC by Arjan van de Ven
Modified: 2007-11-30 22:11 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2007-01-29 14:01:41 UTC

Attachments (Terms of Use)

Description Arjan van de Ven 2006-08-31 12:35:00 UTC
Description of problem:

we're working with RH engineers on the tickless idle kernel feature. However,
having a really idle kernel is no use if userspace applications keep waking up
at a high frequency, because then there still aren't long power save periods.

ntp is one of the apps that on an idle system wakes up regularly, and in fact in
the fedora confuration that is once per second. While once per second may not
sound excessive, there are many daemons on a Fedora system and if they all wake
up once a second there still isn't a lot of really idle time.

The once per second comes from a setting in ntp.h called EVENT_TIMEOUT;
this setting can be changed, as the example patch below does. This setting is
consistency used as 1 << EVENT_TIMOUT, so a value of 4 gives 16 seconds.

On any reasonable functioning machine, a ntp correction interval of 16 seconds
ought to be more than plenty to keep an accurate clock; after all PC clocks are
accurate in the order of seconds per *day*.

--- include/ntp.h~      2006-08-31 14:28:34.000000000 +0200
+++ include/ntp.h       2006-08-31 14:28:34.000000000 +0200
@@ -165,7 +165,7 @@
 #define UNIVAR(x)      (SQUARE(.28867513 * LOGTOD(x))) /* std uniform distr */
 #define ULOGTOD(a)     (1L << (int)(a)) /* ulog2 to double */

-#define        EVENT_TIMEOUT   0       /* one second, that is */
+#define        EVENT_TIMEOUT   4       /* 16 seconds, that is */

Comment 1 Miroslav Lichvar 2006-08-31 14:34:33 UTC
Actually system clock isn't corrected in user space at all when PLL updates in
kernel are used, so 16s would be ok in this regard. But there is other code that
needs to be executed with better accuracy than 16s, just changing EVENT_TIMEOUT
isn't sufficient.

However, I think it is possible to modify ntpd so that it will wake up just few
times per hour in usual conditions. I will check how much code needs to be modified.

Comment 2 Jeff Garzik 2006-12-19 21:19:59 UTC
Any updates?  This wakeup issue definitely burns power.

Comment 3 Miroslav Lichvar 2007-01-29 14:01:41 UTC
Fixed in ntp-4.2.4-4.fc7.

Note that ntpd still needs to wake up once per second when a refclock is used
(i.e. server 127.127.*.*) or kernel discipline is disabled.

Comment 4 Nick Lamb 2007-09-04 01:44:27 UTC
It's not clear to me how comment #3 applies to typical systems.

On this Fedora 7 machine which so far as I know doesn't have a reference clock,
NTP still wakes up once a second showing as

do_adjtimex (sync_cmos_clock)

which sounds to me like it's scribbling into the battery backed clock, certainly
not something we want to waste our time doing frequently.

I have ntp-4.2.4p2-3.fc7

How would I know if "kernel discipline is disabled" ?

Comment 5 Miroslav Lichvar 2007-09-04 11:55:48 UTC
The Local Clock (server is also a reference clock. It was enabled
by default in ntp.conf before F7.

Kernel discipline should be always enabled unless ntpd is started with -x option
or it's disabled in ntp.conf with tinker command. ntptime prints PLL in the
clock status line.

To verify that ntpd isn't causing the wakeups directly you can start ntpd with
-D 4 and watch the output.

Comment 6 Nick Lamb 2007-09-04 17:05:35 UTC
OK, powertop still blames NTP for one wakeup per second but it appears from
strace output that this is caused in fact by NTP calling adjtimex() once every
minute or so, presumably some kernel code then does... something once per
second. Micro-adjustments to the clock?

I don't know if kernel wakeups are less horrible than userspace wakeups but I'm
content that NTP waking up once per minute or so is acceptable, this bug was
properly closed and I will leave you alone, sorry for the disturbance.

Comment 7 Arjan van de Ven 2007-09-05 07:24:21 UTC
one thing to note; if you upgraded from a previous version of fedora, there is 
a /etc/ntp.conf.rpmnew, which you need to copy over /etc/ntpd.conf to have 
these changes effected.

Comment 8 Miroslav Lichvar 2007-09-05 08:11:33 UTC
Please file a bug against kernel component. I'm not sure, but I think I've seen
a similar problem while playing with different timesources.

Note You need to log in before you can comment on or make changes to this bug.