Roger Shimizu wrote:
>You tagged as minor, so I think it's just a display issue of raw time,
>and it doesn't affect adjtimex's time calculation, right?

I didn't look at the calculating parts of adjtimex, which I never use.
I use adjtimex mainly for display, and just occasionally to poke
status flags.  I tagged this bug as minor because I was only reporting
a display problem.

I've now audited adjtimex fully for nanosecond issues.  In addition to
the display problem, STA_NANO affects the interpretation of offsets input
with the -o and -s options; this is a documentation issue rather than a
functionality issue.  The parts of adjtimex that perform computations are
not affected, because they don't use the adjtimex syscall to retrieve
the time: they use gettimeofday, which yields microseconds regardless
of STA_NANO.

>And it'd be appreciated if you can kindly provide a patch.

Attached.

Would you also be interested in patches to make the interface a bit nicer?
I'm thinking of things like showing units on the values displayed with -p
(the unit for "offset" depends on STA_NANO), using symbolic names for
the status flags, and permitting input option values to use units (like
"-o +200us", whose meaning would be unaffected by STA_NANO).

-zefram
diff -ur adjtimex-1.29.orig/adjtimex.8 adjtimex-1.29/adjtimex.8
--- adjtimex-1.29.orig/adjtimex.8       2009-03-12 00:31:07.000000000 +0000
+++ adjtimex-1.29/adjtimex.8    2017-04-18 17:00:46.129859207 +0100
@@ -158,6 +158,7 @@
    1024   PPS signal wander exceeded
    2048   PPS signal calibration error
    4096   clock hardware fault
+   8192   raw time denominated in nanoseconds
 .fi
 .IP "\fB\-t\fP \fIval\fP, \fB\-\-tick\fP \fIval\fP"
 Set the number of microseconds that should be added to the system time
@@ -185,16 +186,18 @@
 To see the acceptable range for \fInewfreq\fP, use \-\-print and look at
 "tolerance", or try an illegal value (e.g. \-\-tick 0).
 .IP "\fB\-s\fP \fIadj\fP, \fB\-\-singleshot\fP \fIadj\fP"
-Slew the system clock by \fIadj\fP usec.  
+Slew the system clock by \fIadj\fP usec or nsec
+(using whichever unit the clock is presently denominated in).
 (Its rate is changed temporarily by about 1 part in 2000.)
 .IP "\fB\-o\fP \fIadj\fP, \fB\-\-offset\fP \fIadj\fP" 
-Add a time offset of \fIadj\fP usec.
+Add a time offset of \fIadj\fP usec or nsec
+(using whichever unit the clock is presently denominated in).
 The kernel code adjusts the time gradually by \fIadj\fP, 
 notes how long it has been since the last time offset, 
 and then adjusts the frequency offset to correct for the apparent drift.  
 .\"The short range of this parameter makes it almost 
 .\"totally useless except for use with ntpd:
-\fIadj\fP must be in the range -512000...512000.
+The adjustment cannot be of more than 500 ms in either direction.
 .IP "\fB\-S\fP \fIstatus\fP, \fB\-\-status\fP \fIstatus\fP"
 Set kernel system clock status register to value \fIstatus\fP. Look here
 above at the \fB\-\-print\fP switch section for the meaning of
diff -ur adjtimex-1.29.orig/adjtimex.c adjtimex-1.29/adjtimex.c
--- adjtimex-1.29.orig/adjtimex.c       2010-04-17 01:06:34.000000000 +0100
+++ adjtimex-1.29/adjtimex.c    2017-04-18 17:02:04.705080554 +0100
@@ -57,6 +57,12 @@
 #define RTC_RD_TIME  _IOR('p', 0x09, struct rtc_time) /* Read RTC time  */
 #endif /* HAVE_LINUX_RTC_H */
 
+#ifdef STA_NANO
+#define HAS_STA_NANO(f) (f & STA_NANO)
+#else
+#define HAS_STA_NANO(f) 0
+#endif
+
 int F_print = 0;
 
 #ifndef LOG_PATH
@@ -217,11 +223,11 @@
 "       -p, --print               print values of kernel time variables\n"
 "       -t, --tick val            set the kernel tick interval in usec\n"
 "       -f, --frequency newfreq   set system clock frequency offset\n"
-"       -s, --singleshot adj      slew the system clock by adj usec\n"
+"       -s, --singleshot adj      slew the system clock by adj usec or nsec\n"
 "       -S, --status val          set kernel clock status\n"
 "       -R, --reset               reset status after setting parameters\n"
 "                                 (needed for early kernels)\n"
-"       -o, --offset adj          add a time offset of adj usec\n"
+"       -o, --offset adj          add a time offset of adj usec or nsec\n"
 "       -m, --maxerror val        set maximum error (usec)\n"
 "       -e, --esterror val        set estimated error (usec)\n"
 "       -T, --timeconstant val    set phase locked loop time constant\n"
@@ -494,7 +500,7 @@
               "    precision: %ld\n"
               "    tolerance: %ld\n"
               "         tick: %ld\n"
-              "     raw time:  %ds %dus = %d.%06d\n",
+              "     raw time:  %ds %d%cs = %d.%0*d\n",
               txc.modes,
               txc.offset,
               txc.freq,
@@ -507,7 +513,9 @@
               txc.tick,
               (int)txc.time.tv_sec, 
               (int)txc.time.tv_usec,
+              HAS_STA_NANO(txc.status) ? 'n' : 'u',
               (int)txc.time.tv_sec, 
+              HAS_STA_NANO(txc.status) ? 9 : 6,
               (int)txc.time.tv_usec);
        if (saveerr == 0 && ret != 0)
            printf(" return value = %d\n", ret);

Reply via email to