From 2c877fa149842087cf24e4494601c71adf2290d5 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 9 Nov 2016 17:31:34 +0100 Subject: [PATCH] ntp: add new fields to measurements log Include reference ID, NTP mode and source of the local transmit and receive timestamp in the measurements log. --- doc/chrony.conf.adoc | 13 +++++++++++-- ntp_core.c | 18 +++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc index d95949a..9683eca 100644 --- a/doc/chrony.conf.adoc +++ b/doc/chrony.conf.adoc @@ -1469,8 +1469,8 @@ called _measurements.log_. An example line (which actually appears as a single line in the file) from the log file is shown below. + ---- -2015-10-13 05:40:50 203.0.113.15 N 2 111 111 1111 10 10 1.0 \ - -4.966e-03 2.296e-01 1.577e-05 1.615e-01 7.446e-03 +2016-11-09 05:40:50 203.0.113.15 N 2 111 111 1111 10 10 1.0 \ + -4.966e-03 2.296e-01 1.577e-05 1.615e-01 7.446e-03 CB00717B 4B D K ---- + The columns are as follows (the quantities in square brackets are the values @@ -1500,6 +1500,13 @@ from the example line above): . The peer dispersion (_epsilon_ in RFC 5905). [1.577e-05] . The root delay (_DELTA_ in RFC 5905). [1.615e-01] . The root dispersion (_EPSILON_ in RFC 5905). [7.446e-03] +. Reference ID of the server's source as a hexadecimal number. [CB00717B] +. NTP mode of the received packet (_1_=active peer, _2_=passive peer, + _3_=server, _B_=basic, _I_=interleaved). [4B] +. Source of the local transmit timestamp + (_D_=daemon, _K_=kernel, _H_=hardware). [D] +. Source of the local receive timestamp + (_D_=daemon, _K_=kernel, _H_=hardware). [K] + *statistics*::: This option logs information about the regression processing to a file called @@ -1746,6 +1753,8 @@ _SOF_TIMESTAMPING_TX_HARDWARE_, _SOF_TIMESTAMPING_RX_HARDWARE_, and the filter modes should have _HWTSTAMP_FILTER_ALL_. When *chronyd* is running, no other process should be working with the clock on the NIC. If no *hwtimestamp* directive is specified, *chronyd* will try to enable software timestamping. +The source of the timestamps is indicated in the _measurements.log_ file if +enabled by the <> directive. + An example of the directive is: + diff --git a/ntp_core.c b/ntp_core.c index 73564dd..61422ad 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -262,6 +262,10 @@ static int server_sock_fd6; static ADF_AuthTable access_auth_table; +/* Characters for printing synchronisation status and timestamping source */ +static const char leap_chars[4] = {'N', '+', '-', '?'}; +static const char tss_chars[3] = {'D', 'K', 'H'}; + /* ================================================== */ /* Forward prototypes */ @@ -340,7 +344,7 @@ NCR_Initialise(void) do_time_checks(); logfileid = CNF_GetLogMeasurements() ? LOG_FileOpen("measurements", - " Date (UTC) Time IP Address L St 123 567 ABCD LP RP Score Offset Peer del. Peer disp. Root del. Root disp.") + " Date (UTC) Time IP Address L St 123 567 ABCD LP RP Score Offset Peer del. Peer disp. Root del. Root disp. Refid MTxRx") : -1; access_auth_table = ADF_CreateTable(); @@ -1267,9 +1271,6 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr, /* Kiss-o'-Death codes */ int kod_rate; - /* Characters used to print synchronisation status */ - static const char sync_stats[4] = {'N', '+', '-', '?'}; - /* The estimated offset predicted from previous samples. The convention here is that positive means local clock FAST of reference, i.e. backwards to the way that 'offset' is defined. */ @@ -1575,16 +1576,19 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr, /* Do measurement logging */ if (logfileid != -1) { - LOG_FileWrite(logfileid, "%s %-15s %1c %2d %1d%1d%1d %1d%1d%1d %1d%1d%1d%d %2d %2d %4.2f %10.3e %10.3e %10.3e %10.3e %10.3e", + LOG_FileWrite(logfileid, "%s %-15s %1c %2d %1d%1d%1d %1d%1d%1d %1d%1d%1d%d %2d %2d %4.2f %10.3e %10.3e %10.3e %10.3e %10.3e %08X %1d%1c %1c %1c", UTI_TimeToLogForm(sample_time.tv_sec), UTI_IPToString(&inst->remote_addr.ip_addr), - sync_stats[pkt_leap], + leap_chars[pkt_leap], message->stratum, test1, test2, test3, test5, test6, test7, testA, testB, testC, testD, inst->local_poll, inst->remote_poll, inst->poll_score, offset, delay, dispersion, - pkt_root_delay, pkt_root_dispersion); + pkt_root_delay, pkt_root_dispersion, pkt_refid, + NTP_LVM_TO_MODE(message->lvm), interleaved_packet ? 'I' : 'B', + tss_chars[CLAMP(0, inst->local_tx.source, sizeof (tss_chars))], + tss_chars[CLAMP(0, rx_ts->source, sizeof (tss_chars))]); } return good_packet;