adjtimex修改tick值用法举例
测试
用户态下内核时钟计数间隔,默认都是100HZ。因此单个tick代表了10^4 us。
可以设置每个tick代表的时钟长度,因此把tick增加1(即增加为10001us)的影响是每天时间快8.64s
24360010010001/10^6-243600=8.64s。
意思是:
对于正常的机器,+1 tick,一天后,ntpq -np会显示,-8640
推理:
对于异常的机器:
如果机器的时钟电路很快,一天下来,总是比正常时间快,ntpq -np总是显示负值,比如,机器A每天都会以-8640速度增加误差,- 8640 ms / ( 24h * 60 min ) = -6ms/1min,那么,应该给其tick减1
如果机器的时钟电路很慢,一天下来,总是比正常时间慢,ntpq -np总是显示正值,比如,机器B每天都会以+8640速度增加误差,+ 8640 ms / ( 24h * 60 min ) = +6ms/1min,那么,应该给其tick加1
我现在把tick值修改为10050,相当于增加50;前面我们有结论是为了让时间快一点, tick值加1,那么加50,相当于,每分钟时间快300ms,和实际测量的317毫秒基本相差不大
[root@dnstest07.tbc /home/ahao.mah]
#/home/tops/bin/adjtimex -t 10050
[root@dnstest07.tbc /home/ahao.mah]
#/home/tops/bin/adjtimex -c
WARNING: CMOS time is 30.03 min behind system clock
--- current --- -- suggested --
cmos time system-cmos error_ppm tick freq tick freq
1487621068 59055.377160
1487621078 59055.593597 21643.8 10050 20354291
1487621088 59055.830139 23654.2 10050 20354291 9816 3695129
1487621097 59056.030826 20068.7 10050 20354291 9852 2746779
1487621107 59056.262891 23206.5 10050 20354291 9821 269316
1487621117 59056.479460 21657.0 10050 20354291 9836 3513754
1487621127 59056.695908 21644.8 10050 20354291 9836 4312191
1487621137 59056.912304 21639.6 10050 20354291 9836 4654379
观察一段时间:: 发现每分钟以317ms的速度偏离;
[root@dnstest07.tbc /home/ahao.mah]
#crontab -l
* * * * * (/usr/sbin/ntpdate -q 10.210.208.8) >> /var/log/ntpdate.lo
[root@dnstest07.tbc /home/ahao.mah]
#cat /var/log/ntpdate.log
server 10.210.208.8, stratum 4, offset 0.012350, delay 0.02710
21 Feb 17:16:02 ntpdate[84349]: adjust time server 10.210.208.8 offset 0.012350 sec
server 10.210.208.8, stratum 4, offset 0.014506, delay 0.02724
21 Feb 17:17:01 ntpdate[85076]: adjust time server 10.210.208.8 offset 0.014506 sec
server 10.210.208.8, stratum 4, offset -0.024885, delay 0.02715
21 Feb 17:18:01 ntpdate[86124]: adjust time server 10.210.208.8 offset -0.024885 sec
server 10.210.208.8, stratum 4, offset -0.339125, delay 0.02711
21 Feb 17:19:01 ntpdate[86968]: adjust time server 10.210.208.8 offset -0.339125 sec
server 10.210.208.8, stratum 4, offset -0.663019, delay 0.04503
21 Feb 17:20:01 ntpdate[87306]: step time server 10.210.208.8 offset -0.663019 sec
server 10.210.208.8, stratum 4, offset -0.977446, delay 0.04320
21 Feb 17:21:01 ntpdate[87726]: step time server 10.210.208.8 offset -0.977446 sec
server 10.210.208.8, stratum 4, offset -1.281264, delay 0.02724
21 Feb 17:22:01 ntpdate[88035]: step time server 10.210.208.8 offset -1.281264 sec
server 10.210.208.8, stratum 4, offset -1.597659, delay 0.02724
21 Feb 17:23:01 ntpdate[88349]: step time server 10.210.208.8 offset -1.597659 sec
server 10.210.208.8, stratum 4, offset -1.909921, delay 0.02711
21 Feb 17:24:01 ntpdate[88669]: step time server 10.210.208.8 offset -1.909921 sec
server 10.210.208.8, stratum 4, offset -2.227171, delay 0.02721
21 Feb 17:25:01 ntpdate[89034]: step time server 10.210.208.8 offset -2.227171 sec
server 10.210.208.8, stratum 4, offset -2.543663, delay 0.02727
21 Feb 17:26:01 ntpdate[89454]: step time server 10.210.208.8 offset -2.543663 sec
server 10.210.208.8, stratum 4, offset -2.860472, delay 0.02710
21 Feb 17:27:01 ntpdate[90357]: step time server 10.210.208.8 offset -2.860472 sec
server 10.210.208.8, stratum 4, offset -3.176871, delay 0.02724
21 Feb 17:28:01 ntpdate[91362]: step time server 10.210.208.8 offset -3.176871 sec
server 10.210.208.8, stratum 4, offset -3.493564, delay 0.02713
21 Feb 17:29:01 ntpdate[92029]: step time server 10.210.208.8 offset -3.493564 sec
server 10.210.208.8, stratum 4, offset -3.810247, delay 0.02721
21 Feb 17:30:01 ntpdate[93076]: step time server 10.210.208.8 offset -3.810247 sec
server 10.210.208.8, stratum 4, offset -4.126971, delay 0.02710
21 Feb 17:31:02 ntpdate[94186]: step time server 10.210.208.8 offset -4.126971 sec
server 10.210.208.8, stratum 4, offset -4.438399, delay 0.02711
21 Feb 17:32:01 ntpdate[94848]: step time server 10.210.208.8 offset -4.438399 sec
server 10.210.208.8, stratum 4, offset -4.754996, delay 0.02724
21 Feb 17:33:01 ntpdate[95858]: step time server 10.210.208.8 offset -4.754996 sec
server 10.210.208.8, stratum 4, offset -5.071533, delay 0.02711
21 Feb 17:34:01 ntpdate[96992]: step time server 10.210.208.8 offset -5.071533 sec
server 10.210.208.8, stratum 4, offset -5.388139, delay 0.02708
muahao@aliyun.com