From 0845df7684f4597ab9ff7a6e9aadf01895b93887 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 16 Mar 2023 16:59:18 +0100 Subject: [PATCH] cmdmon: add timestamp counters to serverstats report Add the new RX/TX daemon/kernel/hardware timestamp counters to the serverstats report. --- candm.h | 10 +++++++++- client.c | 16 ++++++++++++++-- cmdmon.c | 10 +++++++++- doc/chrony.conf.adoc | 11 +++++++---- doc/chronyc.adoc | 24 ++++++++++++++++++++++++ pktlength.c | 3 ++- test/simulation/110-chronyc | 8 +++++++- test/system/007-cmdmon | 8 +++++++- 8 files changed, 79 insertions(+), 11 deletions(-) diff --git a/candm.h b/candm.h index e742323..2fba7f4 100644 --- a/candm.h +++ b/candm.h @@ -530,7 +530,8 @@ typedef struct { #define RPY_SERVER_STATS2 22 #define RPY_SELECT_DATA 23 #define RPY_SERVER_STATS3 24 -#define N_REPLY_TYPES 25 +#define RPY_SERVER_STATS4 25 +#define N_REPLY_TYPES 26 /* Status codes */ #define STT_SUCCESS 0 @@ -676,6 +677,13 @@ typedef struct { uint32_t ntp_interleaved_hits; uint32_t ntp_timestamps; uint32_t ntp_span_seconds; + uint32_t ntp_daemon_rx_timestamps; + uint32_t ntp_daemon_tx_timestamps; + uint32_t ntp_kernel_rx_timestamps; + uint32_t ntp_kernel_tx_timestamps; + uint32_t ntp_hw_rx_timestamps; + uint32_t ntp_hw_tx_timestamps; + uint32_t reserved[4]; int32_t EOR; } RPY_ServerStats; diff --git a/client.c b/client.c index 414c761..44b875d 100644 --- a/client.c +++ b/client.c @@ -2478,7 +2478,7 @@ process_cmd_serverstats(char *line) CMD_Reply reply; request.command = htons(REQ_SERVER_STATS); - if (!request_reply(&request, &reply, RPY_SERVER_STATS3, 0)) + if (!request_reply(&request, &reply, RPY_SERVER_STATS4, 0)) return 0; print_report("NTP packets received : %U\n" @@ -2491,7 +2491,13 @@ process_cmd_serverstats(char *line) "Authenticated NTP packets : %U\n" "Interleaved NTP packets : %U\n" "NTP timestamps held : %U\n" - "NTP timestamp span : %U\n", + "NTP timestamp span : %U\n" + "NTP daemon RX timestamps : %U\n" + "NTP daemon TX timestamps : %U\n" + "NTP kernel RX timestamps : %U\n" + "NTP kernel TX timestamps : %U\n" + "NTP hardware RX timestamps : %U\n" + "NTP hardware TX timestamps : %U\n", (unsigned long)ntohl(reply.data.server_stats.ntp_hits), (unsigned long)ntohl(reply.data.server_stats.ntp_drops), (unsigned long)ntohl(reply.data.server_stats.cmd_hits), @@ -2503,6 +2509,12 @@ process_cmd_serverstats(char *line) (unsigned long)ntohl(reply.data.server_stats.ntp_interleaved_hits), (unsigned long)ntohl(reply.data.server_stats.ntp_timestamps), (unsigned long)ntohl(reply.data.server_stats.ntp_span_seconds), + (unsigned long)ntohl(reply.data.server_stats.ntp_daemon_rx_timestamps), + (unsigned long)ntohl(reply.data.server_stats.ntp_daemon_tx_timestamps), + (unsigned long)ntohl(reply.data.server_stats.ntp_kernel_rx_timestamps), + (unsigned long)ntohl(reply.data.server_stats.ntp_kernel_tx_timestamps), + (unsigned long)ntohl(reply.data.server_stats.ntp_hw_rx_timestamps), + (unsigned long)ntohl(reply.data.server_stats.ntp_hw_tx_timestamps), REPORT_END); return 1; diff --git a/cmdmon.c b/cmdmon.c index cdb1d86..96b66a7 100644 --- a/cmdmon.c +++ b/cmdmon.c @@ -1177,7 +1177,7 @@ handle_server_stats(CMD_Request *rx_message, CMD_Reply *tx_message) RPT_ServerStatsReport report; CLG_GetServerStatsReport(&report); - tx_message->reply = htons(RPY_SERVER_STATS3); + tx_message->reply = htons(RPY_SERVER_STATS4); tx_message->data.server_stats.ntp_hits = htonl(report.ntp_hits); tx_message->data.server_stats.nke_hits = htonl(report.nke_hits); tx_message->data.server_stats.cmd_hits = htonl(report.cmd_hits); @@ -1189,6 +1189,14 @@ handle_server_stats(CMD_Request *rx_message, CMD_Reply *tx_message) tx_message->data.server_stats.ntp_interleaved_hits = htonl(report.ntp_interleaved_hits); tx_message->data.server_stats.ntp_timestamps = htonl(report.ntp_timestamps); tx_message->data.server_stats.ntp_span_seconds = htonl(report.ntp_span_seconds); + tx_message->data.server_stats.ntp_daemon_rx_timestamps = htonl(report.ntp_daemon_rx_timestamps); + tx_message->data.server_stats.ntp_daemon_tx_timestamps = htonl(report.ntp_daemon_tx_timestamps); + tx_message->data.server_stats.ntp_kernel_rx_timestamps = htonl(report.ntp_kernel_rx_timestamps); + tx_message->data.server_stats.ntp_kernel_tx_timestamps = htonl(report.ntp_kernel_tx_timestamps); + tx_message->data.server_stats.ntp_hw_rx_timestamps = htonl(report.ntp_hw_rx_timestamps); + tx_message->data.server_stats.ntp_hw_tx_timestamps = htonl(report.ntp_hw_tx_timestamps); + memset(tx_message->data.server_stats.reserved, 0xff, + sizeof (tx_message->data.server_stats.reserved)); } /* ================================================== */ diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc index 49d5168..852d6b9 100644 --- a/doc/chrony.conf.adoc +++ b/doc/chrony.conf.adoc @@ -2536,10 +2536,13 @@ physical clock created by writing to _/sys/class/ptp/ptpX/n_vclocks_. This feature is available on Linux 5.14 and newer. + If the kernel supports software timestamping, it will be enabled for all -interfaces. The source of timestamps (i.e. hardware, kernel, or daemon) is -indicated in the _measurements.log_ file if enabled by the <> directive, and the <> report in -*chronyc*. +interfaces automatically. ++ +The source of timestamps (i.e. hardware, kernel, or daemon) is indicated on the +client side in the _measurements.log_ file (if enabled by the <> +directive) and the <> report. On the server +side, the number of served timestamps from each source is provided in the +<> report. + This directive can be used multiple times to enable HW timestamping on multiple interfaces. If the specified interface is _*_, *chronyd* will try to enable HW diff --git a/doc/chronyc.adoc b/doc/chronyc.adoc index a1d2de2..b04aaeb 100644 --- a/doc/chronyc.adoc +++ b/doc/chronyc.adoc @@ -1158,6 +1158,12 @@ Authenticated NTP packets : 189 Interleaved NTP packets : 43 NTP timestamps held : 44 NTP timestamp span : 120 +NTP daemon RX timestamps : 0 +NTP daemon TX timestamps : 1537 +NTP kernel RX timestamps : 1590 +NTP kernel TX timestamps : 43 +NTP hardware RX timestamps : 0 +NTP hardware TX timestamps : 0 ---- + The fields have the following meaning: @@ -1192,6 +1198,24 @@ The number of pairs of receive and transmit timestamps that the server is currently holding in memory for clients using the interleaved mode. *NTP timestamp span*::: The interval (in seconds) covered by the currently held NTP timestamps. +*NTP daemon RX timestamps*::: +The number of NTP responses which included a receive timestamp captured by the +daemon. +*NTP daemon TX timestamps*::: +The number of NTP responses which included a transmit timestamp captured by the +daemon. +*NTP kernel RX timestamps*::: +The number of NTP responses which included a receive timestamp captured by the +kernel. +*NTP kernel TX timestamps*::: +The number of NTP responses (in the interleaved mode) which included a transmit +timestamp captured by the kernel. +*NTP hardware RX timestamps*::: +The number of NTP responses which included a receive timestamp captured by the +NIC. +*NTP hardware TX timestamps*::: +The number of NTP responses (in the interleaved mode) which included a transmit +timestamp captured by the NIC. {blank}:: + Note that the numbers reported by this command overflow to zero after diff --git a/pktlength.c b/pktlength.c index 263b16d..d7ed272 100644 --- a/pktlength.c +++ b/pktlength.c @@ -157,7 +157,8 @@ static const uint16_t reply_lengths[] = { RPY_LENGTH_ENTRY(client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX3 */ 0, /* SERVER_STATS2 - not supported */ RPY_LENGTH_ENTRY(select_data), /* SELECT_DATA */ - RPY_LENGTH_ENTRY(server_stats), /* SERVER_STATS3 */ + 0, /* SERVER_STATS3 - not supported */ + RPY_LENGTH_ENTRY(server_stats), /* SERVER_STATS4 */ }; /* ================================================== */ diff --git a/test/simulation/110-chronyc b/test/simulation/110-chronyc index 2529cec..33d204b 100755 --- a/test/simulation/110-chronyc +++ b/test/simulation/110-chronyc @@ -260,7 +260,13 @@ NTS-KE connections dropped : 0 Authenticated NTP packets : 0 Interleaved NTP packets : 0 NTP timestamps held : 0 -NTP timestamp span : 0$" || test_fail +NTP timestamp span : 0 +NTP daemon RX timestamps : 0 +NTP daemon TX timestamps : 1 +NTP kernel RX timestamps : 1 +NTP kernel TX timestamps : 0 +NTP hardware RX timestamps : 0 +NTP hardware TX timestamps : 0$" || test_fail chronyc_conf=" deny all diff --git a/test/system/007-cmdmon b/test/system/007-cmdmon index 301d01c..f9541d3 100755 --- a/test/system/007-cmdmon +++ b/test/system/007-cmdmon @@ -115,7 +115,13 @@ NTS-KE connections dropped : 0 Authenticated NTP packets : 0 Interleaved NTP packets : 0 NTP timestamps held : 0 -NTP timestamp span : 0$"|| test_fail +NTP timestamp span : 0 +NTP daemon RX timestamps : 0 +NTP daemon TX timestamps : [0-9]+ +NTP kernel RX timestamps : [0-9]+ +NTP kernel TX timestamps : 0 +NTP hardware RX timestamps : 0 +NTP hardware TX timestamps : 0$"|| test_fail run_chronyc "manual on" || test_fail check_chronyc_output "^200 OK$" || test_fail