From 362bf585ea14cf04e18092edf9b80a4e53c4dbaa Mon Sep 17 00:00:00 2001 From: Dave Hart Date: Sat, 19 Mar 2011 16:38:10 +0000 Subject: [PATCH] Add "ntpq -c iostats" similar to "ntpdc -c iostats". Compare entire timestamp to reject duplicates in refclock_pps(). bk: 4d84dbf2c652nZVz4FygKtSFm8enNg --- ChangeLog | 1 + ntpd/ntp_control.c | 75 ++++++++++++++++++++++++- ntpd/ntp_refclock.c | 2 +- ntpq/ntpq-subs.c | 35 +++++++++++- ports/winnt/ntpd/ntp_iocompletionport.c | 10 +++- 5 files changed, 117 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3db03fda9..f209a0396 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* Add "ntpq -c iostats" similar to "ntpdc -c iostats". (4.2.7p140) 2011/03/17 Released by Harlan Stenn * [Bug 1848] ntpd 4.2.7p139 --disable-thread-support does not compile. * Add --disable-thread-support to one flock-build variation. diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index 64878b3b4..e247238c4 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -197,7 +197,19 @@ static const struct ctl_proc control_codes[] = { #define CS_K_PPS_STBEXC 72 #define CS_KERN_FIRST CS_K_OFFSET #define CS_KERN_LAST CS_K_PPS_STBEXC -#define CS_MAX_NOAUTOKEY CS_KERN_LAST +#define CS_IOSTATS_RESET 73 +#define CS_TOTAL_RBUF 74 +#define CS_FREE_RBUF 75 +#define CS_USED_RBUF 76 +#define CS_RBUF_LOWATER 77 +#define CS_IO_DROPPED 78 +#define CS_IO_IGNORED 79 +#define CS_IO_RECEIVED 80 +#define CS_IO_SENT 81 +#define CS_IO_SENDFAILED 82 +#define CS_IO_WAKEUPS 83 +#define CS_IO_GOODWAKEUPS 84 +#define CS_MAX_NOAUTOKEY CS_IO_GOODWAKEUPS #ifdef AUTOKEY #define CS_FLAGS (1 + CS_MAX_NOAUTOKEY) #define CS_HOST (2 + CS_MAX_NOAUTOKEY) @@ -376,6 +388,18 @@ static const struct ctl_var sys_var[] = { { CS_K_PPS_CALIBERRS, RO, "kppscaliberrs" }, /* 70 */ { CS_K_PPS_JITEXC, RO, "kppsjitexc" }, /* 71 */ { CS_K_PPS_STBEXC, RO, "kppsstbexc" }, /* 72 */ + { CS_IOSTATS_RESET, RO, "iostats_reset" }, /* 73 */ + { CS_TOTAL_RBUF, RO, "total_rbuf" }, /* 74 */ + { CS_FREE_RBUF, RO, "free_rbuf" }, /* 75 */ + { CS_USED_RBUF, RO, "used_rbuf" }, /* 76 */ + { CS_RBUF_LOWATER, RO, "rbuf_lowater" }, /* 77 */ + { CS_IO_DROPPED, RO, "io_dropped" }, /* 78 */ + { CS_IO_IGNORED, RO, "io_ignored" }, /* 79 */ + { CS_IO_RECEIVED, RO, "io_received" }, /* 80 */ + { CS_IO_SENT, RO, "io_sent" }, /* 81 */ + { CS_IO_SENDFAILED, RO, "io_sendfailed" }, /* 82 */ + { CS_IO_WAKEUPS, RO, "io_wakeups" }, /* 83 */ + { CS_IO_GOODWAKEUPS, RO, "io_goodwakeups" }, /* 84 */ #ifdef AUTOKEY { CS_FLAGS, RO, "flags" }, /* 1 + CS_MAX_NOAUTOKEY */ { CS_HOST, RO, "host" }, /* 2 + CS_MAX_NOAUTOKEY */ @@ -2126,6 +2150,55 @@ ctl_putsys( (sys_var[varid].text, ntx.stbcnt) ); break; + + case CS_IOSTATS_RESET: + ctl_putuint(sys_var[varid].text, + current_time - io_timereset); + break; + + case CS_TOTAL_RBUF: + ctl_putuint(sys_var[varid].text, total_recvbuffs()); + break; + + case CS_FREE_RBUF: + ctl_putuint(sys_var[varid].text, free_recvbuffs()); + break; + + case CS_USED_RBUF: + ctl_putuint(sys_var[varid].text, full_recvbuffs()); + break; + + case CS_RBUF_LOWATER: + ctl_putuint(sys_var[varid].text, lowater_additions()); + break; + + case CS_IO_DROPPED: + ctl_putuint(sys_var[varid].text, packets_dropped); + break; + + case CS_IO_IGNORED: + ctl_putuint(sys_var[varid].text, packets_ignored); + break; + + case CS_IO_RECEIVED: + ctl_putuint(sys_var[varid].text, packets_received); + break; + + case CS_IO_SENT: + ctl_putuint(sys_var[varid].text, packets_sent); + break; + + case CS_IO_SENDFAILED: + ctl_putuint(sys_var[varid].text, packets_notsent); + break; + + case CS_IO_WAKEUPS: + ctl_putuint(sys_var[varid].text, handler_calls); + break; + + case CS_IO_GOODWAKEUPS: + ctl_putuint(sys_var[varid].text, handler_pkts); + break; #ifdef AUTOKEY case CS_FLAGS: if (crypto_flags) diff --git a/ntpd/ntp_refclock.c b/ntpd/ntp_refclock.c index 8711dd8e9..026ad8d75 100644 --- a/ntpd/ntp_refclock.c +++ b/ntpd/ntp_refclock.c @@ -1323,7 +1323,7 @@ refclock_pps( else return (0); - if (timeout.tv_sec == ap->ts.tv_sec) + if (0 == memcmp(&timeout, &ap->ts, sizeof(timeout))) return (0); /* diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index 35371a98a..cf9b9ac28 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -73,6 +73,7 @@ static void sysstats (struct parse *, FILE *); static void sysinfo (struct parse *, FILE *); static void kerninfo (struct parse *, FILE *); static void monstats (struct parse *, FILE *); +static void iostats (struct parse *, FILE *); /* * Commands we understand. Ntpdc imports this. @@ -189,6 +190,9 @@ struct xcmd opcmds[] = { { "authinfo", authinfo, { NO, NO, NO, NO }, { "", "", "", "" }, "display symmetric authentication counters" }, + { "iostats", iostats, { NO, NO, NO, NO }, + { "", "", "", "" }, + "display network input and output counters" }, { 0, 0, { NO, NO, NO, NO }, { "-4|-6", "", "", "" }, "" } }; @@ -3420,7 +3424,36 @@ monstats( /* - * monstats - implements ntpq -c monstats + * iostats - ntpq -c iostats - network input and output counters + */ +static void +iostats( + struct parse *pcmd, + FILE *fp + ) +{ + static vdc iostats_vdc[] = { + { "iostats_reset", "time since reset: ", NTP_STR }, + { "total_rbuf", "receive buffers: ", NTP_STR }, + { "free_rbuf", "free receive buffers: ", NTP_STR }, + { "used_rbuf", "used receive buffers: ", NTP_STR }, + { "rbuf_lowater", "low water refills: ", NTP_STR }, + { "io_dropped", "dropped packets: ", NTP_STR }, + { "io_ignored", "ignored packets: ", NTP_STR }, + { "io_received", "received packets: ", NTP_STR }, + { "io_sent", "packets sent: ", NTP_STR }, + { "io_sendfailed", "packet send failures: ", NTP_STR }, + { "io_wakeups", "input wakeups: ", NTP_STR }, + { "io_goodwakeups", "useful input wakeups: ", NTP_STR }, + { NULL, NULL, 0 } + }; + + collect_display_vdc(0, iostats_vdc, FALSE, fp); +} + + +/* + * authinfo - implements ntpq -c authinfo */ static void authinfo( diff --git a/ports/winnt/ntpd/ntp_iocompletionport.c b/ports/winnt/ntpd/ntp_iocompletionport.c index e2ff0fbff..125b71919 100644 --- a/ports/winnt/ntpd/ntp_iocompletionport.c +++ b/ports/winnt/ntpd/ntp_iocompletionport.c @@ -198,6 +198,7 @@ iocompletionthread(void *NotUsed) DPRINTF(2, ("Overlapped IO Thread Exiting\n")); break; /* fail */ } + handler_calls++; lpo = CONTAINEROF(pol, olplus, ol); rio = (struct refclockio *)key; @@ -584,8 +585,9 @@ OnSerialReadComplete( buff->recv_length = (int) Bytes; buff->receiver = rio->clock_recv; buff->dstadr = NULL; - buff->recv_srcclock = rio->srcclock; + buff->recv_peer = rio->srcclock; packets_received++; + handler_pkts++; /* * Eat the first line of input as it's possibly * partial and if a PPS is present, it may not @@ -610,7 +612,7 @@ OnSerialReadComplete( buff->fd = rio->fd; buff->receiver = rio->clock_recv; buff->dstadr = NULL; - buff->recv_srcclock = rio->srcclock; + buff->recv_peer = rio->srcclock; add_full_recv_buffer(buff); /* * Now signal we have something to process @@ -677,9 +679,10 @@ OnRawSerialReadComplete( rbufp->dstadr = NULL; rbufp->recv_time = arrival_time; rbufp->receiver = rio->clock_recv; - rbufp->recv_srcclock = rio->srcclock; + rbufp->recv_peer = rio->srcclock; rbufp->fd = rio->fd; /* was handle */ packets_received++; + handler_pkts++; add_full_recv_buffer(rbufp); /* * Now signal we have something to process @@ -847,6 +850,7 @@ OnSocketRecv(ULONG_PTR i, olplus *lpo, DWORD Bytes, int errstatus) buff->receiver = &receive; buff->dstadr = inter; packets_received++; + handler_pkts++; inter->received++; add_full_recv_buffer(buff); -- 2.47.3