meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
linux:ntp [2019/10/28 17:57] niziaklinux:ntp [2019/10/28 22:10] – [Not synchronized clock] niziak
Line 2: Line 2:
 ====== Issues ====== ====== Issues ======
  
-===== ntp_gettime() returns code 5 (ERROR) =====+===== Not synchronized clock =====
  
-<code bash>sudo ntptime</code> +Cannot set correct time. Manual setting time by ''date'' command is ignored. 
-Reason+<code bash> 
-https://www.systutorials.com/docs/linux/man/2-adjtimex/+sudo timedatectl  
 +               Local timeMon 2019-10-28 18:11:50 CET 
 +           Universal timeMon 2019-10-28 17:11:50 UTC 
 +                 RTC time: Mon 2019-10-28 15:58:24 
 +                Time zone: Europe/Warsaw (CET, +0100) 
 +System clock synchronized: no 
 +              NTP service: inactive 
 +          RTC in local TZ: no 
 +</code>
  
-  TIME_ERROR +<code bash> 
-    The system clock is not synchronized to a reliable serverThis value is returned when any of the following holds true+$ sudo ntptime 
-          Either STA_UNSYNC or STA_CLOCKERR is set.  +ntp_gettime() returns code 5 (ERROR) 
-          STA_PPSSIGNAL is clear and either STA_PPSFREQ or STA_PPSTIME is set.  +  time e161a024.e5878318  Mon, Oct 28 2019 18:13:08.896, (.896599762), 
-          STA_PPSTIME and STA_PPSJITTER are both set.  +  maximum error 16000000 us, estimated error 16000000 us, TAI offset 0 
-          STA_PPSFREQ is set and either STA_PPSWANDER or STA_PPSJITTER is set.  +ntp_adjtime() returns code 5 (ERROR) 
-    The symbolic name TIME_BAD is a synonym for TIME_ERRORprovided for backward compatibility+  modes 0x0 (), 
 +  offset 0.000 us, frequency 93.212 ppm, interval 1 s, 
 +  maximum error 16000000 us, estimated error 16000000 us, 
 +  status 0x2041 (PLL,UNSYNC,NANO), 
 +  time constant 3, precision 0.001 us, tolerance 500 ppm, 
 +</code> 
 + 
 +Reason is: there is no possibility to set clock to past. It is possible to adjust kernel clock to slow down
 +Also some AMD platform are known for big clock drifts
 +  You can only set times in the future, setting past times with date command will do nothing and no error will be shown. Ntpd service will correct slowly the time at small steps. It's not like in Windows       where you can set any time and see the result immediately. 
 + 
 +Solution: 
 + 
 +stop all ntp daemons, delete ''/var/lib/ntp/ntp.drift'' 
 + 
 +<code bash> 
 +# set initial adjtimex params 
 +$sudo adjtimexconfig 
 +Comparing clocks (this will take 70 sec)...done. 
 +Adjusting system time by -9.67758 sec/day to agree with CMOS clock...done. 
 + 
 +# print current ticks 
 +sudo adjtimex -p 
 + 
 +         mode: 0 
 +       offset: 0 
 +    frequency: 5766574 
 +     maxerror: 16000000 
 +     esterror: 16000000 
 +       status: 8257 
 +time_constant:
 +    precision: 1 
 +    tolerance: 32768000 
 +         tick: 9998 
 +     raw time:  1572283011s 863855330ns = 1572283011.863855330 
 + 
 +# Slow down clockto do not wait few days for correction 
 +adjtimex -tick 9000  
 + 
 +# Watch how it works 
 +adjtimex -compare 
 +</code>  
 + 
 +When clock reach good valueStart ntpd. Wait some time and observe 'adjtimex -compare' output. Ntpd  will periodically makes adjustments to clock drift to keep clocks synchronized. 
 +Finally it is good to store correct time to RTC ''hwclock -w''
  
  
-You can only set times in the future, setting past times with date command will do nothing and no error will be shown. Ntpd service will correct slowly the time at small steps. It's not like in Windows where you can set any time and see the result immediately.