1 diff -up ntp-4.2.6p1/include/ntp_refclock.h.sleep ntp-4.2.6p1/include/ntp_refclock.h
2 --- ntp-4.2.6p1/include/ntp_refclock.h.sleep 2009-12-09 08:36:35.000000000 +0100
3 +++ ntp-4.2.6p1/include/ntp_refclock.h 2010-03-10 19:27:46.000000000 +0100
4 @@ -260,6 +260,7 @@ extern void refclock_control (sockaddr_u
5 struct refclockstat *);
6 extern int refclock_open (char *, u_int, u_int);
7 extern int refclock_setup (int, u_int, u_int);
8 +extern int refclock_timer_needed (struct peer *);
9 extern void refclock_timer (struct peer *);
10 extern void refclock_transmit (struct peer *);
11 extern int refclock_ioctl (int, u_int);
12 diff -up ntp-4.2.6p1/include/ntp_stdlib.h.sleep ntp-4.2.6p1/include/ntp_stdlib.h
13 --- ntp-4.2.6p1/include/ntp_stdlib.h.sleep 2009-12-09 08:36:35.000000000 +0100
14 +++ ntp-4.2.6p1/include/ntp_stdlib.h 2010-03-10 19:27:46.000000000 +0100
15 @@ -116,6 +116,7 @@ extern const char * FindConfig (const ch
16 extern void signal_no_reset (int, RETSIGTYPE (*func)(int));
18 extern void getauthkeys (const char *);
19 +extern int auth_agekeys_needed (void);
20 extern void auth_agekeys (void);
21 extern void rereadkeys (void);
23 diff -up ntp-4.2.6p1/include/ntpd.h.sleep ntp-4.2.6p1/include/ntpd.h
24 --- ntp-4.2.6p1/include/ntpd.h.sleep 2009-12-09 08:36:35.000000000 +0100
25 +++ ntp-4.2.6p1/include/ntpd.h 2010-03-10 19:27:46.000000000 +0100
26 @@ -112,8 +112,10 @@ extern void block_io_and_alarm (void);
27 /* ntp_loopfilter.c */
28 extern void init_loopfilter(void);
29 extern int local_clock(struct peer *, double);
30 -extern void adj_host_clock(void);
31 +extern int adj_host_clock_needed(void);
32 +extern void adj_host_clock(int);
33 extern void loop_config(int, double);
34 +extern int huffpuff_enabled(void);
35 extern void huffpuff(void);
36 extern u_long sys_clocktime;
38 @@ -219,6 +221,8 @@ extern void hack_restrict (int, sockaddr
40 extern void init_timer (void);
41 extern void reinit_timer (void);
42 +extern double get_timeout (l_fp *);
43 +extern int timer_elapsed (l_fp, int);
44 extern void timer (void);
45 extern void timer_clr_stats (void);
46 extern void timer_interfacetimeout (u_long);
47 diff -up ntp-4.2.6p1/libntp/authkeys.c.sleep ntp-4.2.6p1/libntp/authkeys.c
48 --- ntp-4.2.6p1/libntp/authkeys.c.sleep 2009-12-09 08:36:35.000000000 +0100
49 +++ ntp-4.2.6p1/libntp/authkeys.c 2010-03-10 19:27:46.000000000 +0100
50 @@ -445,6 +445,25 @@ auth_delkeys(void)
55 +auth_agekeys_needed(void) {
59 + if (authnumkeys > 20)
62 + for (i = 0; i < HASHSIZE; i++) {
65 + if (sk->lifetime > 0)
74 * auth_agekeys - delete keys whose lifetimes have expired
76 diff -up ntp-4.2.6p1/ntpd/ntp_loopfilter.c.sleep ntp-4.2.6p1/ntpd/ntp_loopfilter.c
77 --- ntp-4.2.6p1/ntpd/ntp_loopfilter.c.sleep 2009-12-09 08:36:36.000000000 +0100
78 +++ ntp-4.2.6p1/ntpd/ntp_loopfilter.c 2010-03-10 19:27:46.000000000 +0100
79 @@ -677,6 +677,13 @@ local_clock(
80 #endif /* LOCKCLOCK */
84 +adj_host_clock_needed(void)
86 + return !(!ntp_enable || mode_ntpdate || (pll_control &&
92 * adj_host_clock - Called once every second to update the local clock.
93 @@ -686,7 +693,7 @@ local_clock(
102 @@ -698,7 +705,7 @@ adj_host_clock(
103 * since the poll interval can exceed one day, the old test
104 * would be counterproductive.
106 - sys_rootdisp += clock_phi;
107 + sys_rootdisp += clock_phi * time_elapsed;
111 @@ -819,6 +826,12 @@ set_freq(
112 #endif /* KERNEL_PLL */
116 +huffpuff_enabled(void)
118 + return sys_huffpuff != NULL;
122 * huff-n'-puff filter
124 diff -up ntp-4.2.6p1/ntpd/ntp_refclock.c.sleep ntp-4.2.6p1/ntpd/ntp_refclock.c
125 --- ntp-4.2.6p1/ntpd/ntp_refclock.c.sleep 2009-12-09 08:36:36.000000000 +0100
126 +++ ntp-4.2.6p1/ntpd/ntp_refclock.c 2010-03-10 19:27:46.000000000 +0100
127 @@ -268,6 +268,21 @@ refclock_unpeer(
132 +refclock_timer_needed(
133 + struct peer *peer /* peer structure pointer */
139 + clktype = peer->refclktype;
140 + unit = peer->refclkunit;
141 + if (refclock_conf[clktype]->clock_timer != noentry)
147 * refclock_timer - called once per second for housekeeping.
149 diff -up ntp-4.2.6p1/ntpd/ntp_timer.c.sleep ntp-4.2.6p1/ntpd/ntp_timer.c
150 --- ntp-4.2.6p1/ntpd/ntp_timer.c.sleep 2009-12-09 08:36:35.000000000 +0100
151 +++ ntp-4.2.6p1/ntpd/ntp_timer.c 2010-03-11 15:23:59.000000000 +0100
152 @@ -56,7 +56,6 @@ static u_long adjust_timer; /* second ti
153 static u_long stats_timer; /* stats timer */
154 static u_long huffpuff_timer; /* huff-n'-puff timer */
155 u_long leapsec; /* leapseconds countdown */
156 -l_fp sys_time; /* current system time */
158 static u_long revoke_timer; /* keys revoke timer */
159 static u_long keys_timer; /* session key timer */
160 @@ -74,6 +73,12 @@ volatile u_long alarm_overflow;
161 #define DAY (24 * HOUR)
163 u_long current_time; /* seconds since startup */
167 +#define TIMEOUT_TS_SIZE 2
168 +l_fp timeout_ts[TIMEOUT_TS_SIZE];
169 +unsigned int timeout_ts_index;
172 * Stats. Number of overflows and number of calls to transmit().
173 @@ -110,6 +115,8 @@ static RETSIGTYPE alarming (int);
177 + get_systime(&timer_base);
179 #if !defined(SYS_WINNT) && !defined(VMS)
180 # if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME)
181 timer_gettime(ntpd_timerid, &itimer);
182 @@ -143,6 +150,7 @@ reinit_timer(void)
183 setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
190 @@ -165,6 +173,12 @@ init_timer(void)
194 + get_systime(&timer_base);
196 + for (timeout_ts_index = 0; timeout_ts_index < TIMEOUT_TS_SIZE; timeout_ts_index++)
197 + L_CLR(&timeout_ts[timeout_ts_index]);
198 + timeout_ts_index = 0;
200 #if !defined(SYS_WINNT)
202 * Set up the alarm interrupt. The first comes 2**EVENT_TIMEOUT
203 @@ -226,6 +240,7 @@ init_timer(void)
206 #endif /* SYS_WINNT */
210 #if defined(SYS_WINNT)
211 @@ -236,6 +251,104 @@ get_timer_handle(void)
216 +get_timeout(l_fp *now)
218 + register struct peer *peer, *next_peer;
225 + L_SUB(&ts, &timeout_ts[timeout_ts_index]);
226 + timeout_ts[timeout_ts_index] = *now;
227 + timeout_ts_index = (timeout_ts_index + 1) % TIMEOUT_TS_SIZE;
229 + /* don't waste CPU time if called too frequently */
230 + if (ts.l_ui == 0) {
235 + next = current_time + HOUR;
237 + if (adj_host_clock_needed()) {
241 + for (n = 0; n < NTP_HASH_SIZE; n++) {
242 + for (peer = peer_hash[n]; peer != 0; peer = next_peer) {
243 + next_peer = peer->next;
245 + if (peer->flags & FLAG_REFCLOCK && refclock_timer_needed(peer)) {
249 +#endif /* REFCLOCK */
251 + next = min(next, peer->nextaction);
252 + next = min(next, peer->nextdate);
257 + next = min(next, leapsec);
259 + if (huffpuff_enabled())
260 + next = min(next, huffpuff_timer);
263 + if (auth_agekeys_needed())
264 + next = min(next, keys_timer);
265 + if (sys_leap != LEAP_NOTINSYNC)
266 + next = min(next, revoke_timer);
267 +#endif /* OPENSSL */
269 + if (interface_interval)
270 + next = min(next, interface_timer);
272 + next = min(next, stats_timer);
274 + next -= current_time;
283 + DPRINTF(2, ("timer: timeout %f\n", r));
290 +timer_elapsed(l_fp now, int timeout)
294 + L_SUB(&now, &timer_base);
296 + if (elapsed < 0 || elapsed > timeout + 10) {
298 + DPRINTF(2, ("timer: unexpected time jump\n"));
304 + timer_base.l_ui += elapsed;
305 + time_elapsed += elapsed;
306 + current_time += elapsed;
308 + DPRINTF(2, ("timer: time elapsed %d\n", time_elapsed));
310 + return time_elapsed;
314 * timer - event timer
316 @@ -251,11 +364,9 @@ timer(void)
317 * kiss-o'-deatch function and implement the association
321 - get_systime(&sys_time);
322 if (adjust_timer <= current_time) {
325 + adjust_timer += time_elapsed;
326 + adj_host_clock(time_elapsed);
328 for (n = 0; n < NTP_HASH_SIZE; n++) {
329 for (peer = peer_hash[n]; peer != 0; peer = next_peer) {
330 @@ -286,7 +397,7 @@ timer(void)
333 if (peer->throttle > 0)
335 + peer->throttle -= min(peer->throttle, time_elapsed);
336 if (peer->nextdate <= current_time) {
338 if (peer->flags & FLAG_REFCLOCK)
339 @@ -333,7 +444,7 @@ timer(void)
344 + leapsec -= min(leapsec, time_elapsed);
346 sys_leap = LEAP_NOWARNING;
348 @@ -398,11 +509,15 @@ timer(void)
349 * Finally, write hourly stats.
351 if (stats_timer <= current_time) {
353 + get_systime(&sys_time);
356 if (sys_tai != 0 && sys_time.l_ui > leap_expire)
357 report_event(EVNT_LEAPVAL, NULL, NULL);
364 diff -up ntp-4.2.6p1/ntpd/ntpd.c.sleep ntp-4.2.6p1/ntpd/ntpd.c
365 --- ntp-4.2.6p1/ntpd/ntpd.c.sleep 2010-03-10 19:27:46.000000000 +0100
366 +++ ntp-4.2.6p1/ntpd/ntpd.c 2010-03-10 19:27:46.000000000 +0100
367 @@ -195,8 +195,6 @@ extern const char *Version;
369 char const *progname;
375 * We put this here, since the argument profile is syscall-specific
376 @@ -1033,7 +1031,7 @@ getgroup:
377 #else /* normal I/O */
379 BLOCK_IO_AND_ALARM();
384 # if !defined(HAVE_SIGNALED_IO)
385 @@ -1041,42 +1039,39 @@ getgroup:
386 extern int maxactivefd;
391 + int nfound, time_elapsed;
393 - if (alarm_flag) /* alarmed? */
401 - if (!was_alarmed && has_full_recv_buffer() == ISC_FALSE)
402 + if (has_full_recv_buffer() == ISC_FALSE)
405 * Nothing to do. Wait for something.
407 # ifndef HAVE_SIGNALED_IO
411 -# if defined(VMS) || defined(SYS_VXWORKS)
412 - /* make select() wake up after one second */
416 + timeout = get_timeout(&now);
418 - t1.tv_sec = 1; t1.tv_usec = 0;
419 + if (timeout > 0.0) {
422 + t1.tv_sec = timeout;
423 + t1.tv_usec = (timeout - t1.tv_sec) * 1000000;
424 nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0,
428 - nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0,
429 - (fd_set *)0, (struct timeval *)0);
439 + time_elapsed = timer_elapsed(now, timeout);
441 - (void)input_handler(&ts);
444 + (void)input_handler(&now);
446 else if (nfound == -1 && errno != EINTR)
447 msyslog(LOG_ERR, "select() error: %m");
448 @@ -1085,17 +1080,13 @@ getgroup:
449 msyslog(LOG_DEBUG, "select(): nfound=%d, error: %m", nfound);
451 # else /* HAVE_SIGNALED_IO */
452 +# error not supported by sleep patch
455 # endif /* HAVE_SIGNALED_IO */
456 - if (alarm_flag) /* alarmed? */
464 + if (time_elapsed > 0)
466 UNBLOCK_IO_AND_ALARM();
468 @@ -1103,7 +1094,6 @@ getgroup:
473 BLOCK_IO_AND_ALARM();
476 @@ -1121,19 +1111,8 @@ getgroup:
477 rbuf = get_full_recv_buffer();
485 UNBLOCK_IO_AND_ALARM();
488 - { /* avoid timer starvation during lengthy I/O handling */
494 * Call the data procedure to handle each received