1 diff -up ntp-4.2.4p7/include/ntp_refclock.h.sleep ntp-4.2.4p7/include/ntp_refclock.h
2 --- ntp-4.2.4p7/include/ntp_refclock.h.sleep 2006-06-06 22:16:19.000000000 +0200
3 +++ ntp-4.2.4p7/include/ntp_refclock.h 2009-07-21 16:38:47.000000000 +0200
4 @@ -260,6 +260,7 @@ extern void refclock_control P((struct s
5 struct refclockstat *));
6 extern int refclock_open P((char *, u_int, u_int));
7 extern int refclock_setup P((int, u_int, u_int));
8 +extern int refclock_timer_needed P((struct peer *));
9 extern void refclock_timer P((struct peer *));
10 extern void refclock_transmit P((struct peer *));
11 extern int refclock_ioctl P((int, u_int));
12 diff -up ntp-4.2.4p7/include/ntp_stdlib.h.sleep ntp-4.2.4p7/include/ntp_stdlib.h
13 --- ntp-4.2.4p7/include/ntp_stdlib.h.sleep 2006-12-28 13:03:05.000000000 +0100
14 +++ ntp-4.2.4p7/include/ntp_stdlib.h 2009-07-21 16:38:47.000000000 +0200
15 @@ -101,6 +101,7 @@ extern const char * FindConfig P((const
16 extern void signal_no_reset P((int, RETSIGTYPE (*func)(int)));
18 extern void getauthkeys P((const char *));
19 +extern int auth_agekeys_is_needed P((void));
20 extern void auth_agekeys P((void));
21 extern void rereadkeys P((void));
23 diff -up ntp-4.2.4p7/include/ntpd.h.sleep ntp-4.2.4p7/include/ntpd.h
24 --- ntp-4.2.4p7/include/ntpd.h.sleep 2009-07-21 16:38:47.000000000 +0200
25 +++ ntp-4.2.4p7/include/ntpd.h 2009-07-21 16:38:47.000000000 +0200
26 @@ -120,8 +120,10 @@ extern int leap_actual P((int));
27 /* ntp_loopfilter.c */
28 extern void init_loopfilter P((void));
29 extern int local_clock P((struct peer *, double));
30 -extern void adj_host_clock P((void));
31 +extern int adj_host_clock_is_needed P((void));
32 +extern void adj_host_clock P((int));
33 extern void loop_config P((int, double));
34 +extern int huffpuff_enabled P((void));
35 extern void huffpuff P((void));
36 extern u_long sys_clocktime;
37 extern u_long sys_tai;
38 @@ -221,6 +223,7 @@ extern void hack_restrict P((int, struct
40 extern void init_timer P((void));
41 extern void reinit_timer P((void));
42 +extern int when_next_event P((void));
43 extern void timer P((void));
44 extern void timer_clr_stats P((void));
45 extern void timer_interfacetimeout P((u_long));
46 diff -up ntp-4.2.4p7/libntp/authkeys.c.sleep ntp-4.2.4p7/libntp/authkeys.c
47 --- ntp-4.2.4p7/libntp/authkeys.c.sleep 2004-02-25 06:58:03.000000000 +0100
48 +++ ntp-4.2.4p7/libntp/authkeys.c 2009-07-21 16:38:47.000000000 +0200
49 @@ -394,6 +394,24 @@ auth_delkeys(void)
53 +int auth_agekeys_is_needed() {
57 + if (authnumkeys > 20)
60 + for (i = 0; i < HASHSIZE; i++) {
63 + if (sk->lifetime > 0)
72 * auth_agekeys - delete keys whose lifetimes have expired
74 diff -up ntp-4.2.4p7/ntpd/ntp_loopfilter.c.sleep ntp-4.2.4p7/ntpd/ntp_loopfilter.c
75 --- ntp-4.2.4p7/ntpd/ntp_loopfilter.c.sleep 2009-07-21 16:38:47.000000000 +0200
76 +++ ntp-4.2.4p7/ntpd/ntp_loopfilter.c 2009-07-21 16:38:47.000000000 +0200
77 @@ -752,6 +752,10 @@ local_clock(
78 #endif /* LOCKCLOCK */
81 +int adj_host_clock_is_needed() {
82 + return !(!ntp_enable || mode_ntpdate || (pll_control &&
87 * adj_host_clock - Called once every second to update the local clock.
88 @@ -761,7 +765,7 @@ local_clock(
97 @@ -776,7 +780,8 @@ adj_host_clock(
98 * maximum error and the local clock driver will pick it up and
99 * pass to the common refclock routines. Very elegant.
101 - sys_rootdispersion += clock_phi;
102 + sys_rootdispersion += clock_phi * time_elapsed;
103 + DPRINTF(2, ("loopfilter: %d\n", time_elapsed));
107 @@ -833,6 +838,11 @@ rstclock(
111 +int huffpuff_enabled()
113 + return sys_huffpuff != NULL;
117 * huff-n'-puff filter
119 diff -up ntp-4.2.4p7/ntpd/ntp_refclock.c.sleep ntp-4.2.4p7/ntpd/ntp_refclock.c
120 --- ntp-4.2.4p7/ntpd/ntp_refclock.c.sleep 2006-06-06 22:16:43.000000000 +0200
121 +++ ntp-4.2.4p7/ntpd/ntp_refclock.c 2009-07-21 16:38:47.000000000 +0200
122 @@ -309,6 +309,21 @@ refclock_unpeer(
127 +refclock_timer_needed(
128 + struct peer *peer /* peer structure pointer */
134 + clktype = peer->refclktype;
135 + unit = peer->refclkunit;
136 + if (refclock_conf[clktype]->clock_timer != noentry)
142 * refclock_timer - called once per second for housekeeping.
144 diff -up ntp-4.2.4p7/ntpd/ntp_timer.c.sleep ntp-4.2.4p7/ntpd/ntp_timer.c
145 --- ntp-4.2.4p7/ntpd/ntp_timer.c.sleep 2009-05-12 07:58:55.000000000 +0200
146 +++ ntp-4.2.4p7/ntpd/ntp_timer.c 2009-07-21 16:38:47.000000000 +0200
147 @@ -63,6 +63,7 @@ volatile u_long alarm_overflow;
154 * Stats. Number of overflows and number of calls to transmit().
155 @@ -99,6 +100,8 @@ static RETSIGTYPE alarming P((int));
159 + get_systime(&timer_base);
161 #if !defined(SYS_WINNT) && !defined(VMS)
162 # if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME)
163 timer_gettime(ntpd_timerid, &itimer);
164 @@ -132,6 +135,7 @@ reinit_timer(void)
165 setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
172 @@ -159,6 +163,8 @@ init_timer(void)
176 + get_systime(&timer_base);
178 #if !defined(SYS_WINNT)
180 * Set up the alarm interrupt. The first comes 2**EVENT_TIMEOUT
181 @@ -242,6 +248,7 @@ init_timer(void)
184 #endif /* SYS_WINNT */
188 #if defined(SYS_WINNT)
189 @@ -252,6 +259,46 @@ get_timer_handle(void)
193 +int when_next_event() {
194 + register struct peer *peer, *next_peer;
196 + int next = current_time + HOUR;
198 + if (adj_host_clock_is_needed())
200 + for (n = 0; n < NTP_HASH_SIZE; n++) {
201 + for (peer = peer_hash[n]; peer != 0; peer = next_peer) {
202 + next_peer = peer->next;
204 + if (peer->flags & FLAG_REFCLOCK && refclock_timer_needed(peer))
206 +#endif /* REFCLOCK */
207 + if (peer->action && peer->nextaction < next)
208 + next = peer->nextaction;
209 + if (peer->nextdate < next)
210 + next = peer->nextdate;
214 + if (auth_agekeys_is_needed() && keys_timer < next)
216 + if (huffpuff_enabled() && huffpuff_timer < next)
217 + next = huffpuff_timer;
219 + if (revoke_timer < next)
220 + next = revoke_timer;
221 +#endif /* OPENSSL */
222 + if (interface_interval && interface_timer < next)
223 + next = interface_timer;
224 + if (stats_timer < next)
225 + next = stats_timer;
227 + next -= current_time;
234 * timer - dispatch anyone who needs to be
236 @@ -264,14 +311,12 @@ timer(void)
240 - current_time += (1<<EVENT_TIMEOUT);
243 * Adjustment timeout first.
245 if (adjust_timer <= current_time) {
248 + adj_host_clock(current_time - adjust_timer + 1);
249 + adjust_timer = current_time + 1;
252 for (n = 0; n < NTP_HASH_SIZE; n++) {
253 diff -up ntp-4.2.4p7/ntpd/ntpd.c.sleep ntp-4.2.4p7/ntpd/ntpd.c
254 --- ntp-4.2.4p7/ntpd/ntpd.c.sleep 2009-07-21 16:38:47.000000000 +0200
255 +++ ntp-4.2.4p7/ntpd/ntpd.c 2009-07-21 16:39:29.000000000 +0200
256 @@ -179,8 +179,6 @@ extern const char *Version;
258 char const *progname;
264 * We put this here, since the argument profile is syscall-specific
265 @@ -434,6 +432,7 @@ set_process_priority(void)
266 msyslog(LOG_ERR, "set_process_priority: No way found to improve our priority");
269 +#define TS_LAST_SIZE 2
272 * Main program. Initialize us, disconnect us from the tty if necessary,
273 @@ -446,6 +445,9 @@ ntpdmain(
277 + l_fp ts_last[TS_LAST_SIZE];
278 + unsigned int ts_last_index;
280 struct recvbuf *rbuf;
281 #ifdef _AIX /* HMS: ifdef SIGDANGER? */
283 @@ -998,7 +1000,11 @@ getgroup:
284 #else /* normal I/O */
286 BLOCK_IO_AND_ALARM();
289 + for (ts_last_index = 0; ts_last_index < TS_LAST_SIZE; ts_last_index++)
290 + L_CLR(&ts_last[ts_last_index]);
291 + time_elapsed = ts_last_index = 0;
295 # if !defined(HAVE_SIGNALED_IO)
296 @@ -1009,39 +1015,66 @@ getgroup:
300 - if (alarm_flag) /* alarmed? */
306 - if (!was_alarmed && has_full_recv_buffer() == ISC_FALSE)
307 + if (has_full_recv_buffer() == ISC_FALSE)
310 * Nothing to do. Wait for something.
312 # ifndef HAVE_SIGNALED_IO
313 + extern l_fp timer_base;
318 -# if defined(VMS) || defined(SYS_VXWORKS)
319 - /* make select() wake up after one second */
324 + L_SUB(&ts3, &ts_last[ts_last_index]);
326 + /* don't call when_next_event() too often */
328 + ts2.l_ui += when_next_event();
334 + DPRINTF(2, ("main: scheduled event in %f\n", d));
338 - t1.tv_sec = 1; t1.tv_usec = 0;
340 + t1.tv_usec = (d - t1.tv_sec) * 1000000;
341 nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0,
348 + L_SUB(&ts3, &timer_base);
351 + DPRINTF(2, ("main: elapsed %f\n", d));
354 + if (ts3.l_i < 0 || ts3.l_ui > ts2.l_ui + 10) {
356 + DPRINTF(2, ("main: unexpected time jump\n"));
362 - nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0,
363 - (fd_set *)0, (struct timeval *)0);
370 + time_elapsed += ts3.l_ui;
371 + current_time += ts3.l_ui;
372 + timer_base.l_ui += ts3.l_ui;
376 (void)input_handler(&ts);
377 + ts_last[ts_last_index] = ts;
378 + ts_last_index = (ts_last_index + 1) % TS_LAST_SIZE;
380 else if (nfound == -1 && errno != EINTR)
381 netsyslog(LOG_ERR, "select() error: %m");
382 @@ -1050,17 +1083,12 @@ getgroup:
383 netsyslog(LOG_DEBUG, "select(): nfound=%d, error: %m", nfound);
385 # else /* HAVE_SIGNALED_IO */
387 +# error not supported
389 # endif /* HAVE_SIGNALED_IO */
390 - if (alarm_flag) /* alarmed? */
400 UNBLOCK_IO_AND_ALARM();
402 @@ -1068,7 +1096,7 @@ getgroup:
408 BLOCK_IO_AND_ALARM();
411 @@ -1086,19 +1114,8 @@ getgroup:
412 rbuf = get_full_recv_buffer();
420 UNBLOCK_IO_AND_ALARM();
423 - { /* avoid timer starvation during lengthy I/O handling */
429 * Call the data procedure to handle each received