zoukankan      html  css  js  c++  java
  • [daily][linux] dmesg格式里的时间为什么不准

    我们能看见dmesg的日志带有时间,用dmesg -T参数

    [root@tong ~]# dmesg -T |tail -n 4
    [Tue Jan 21 22:05:11 2020] nginx[7607]: segfault at 8 ip 00007f5323cf77a1 sp 00007fff9ce5e030 error 4 in nginx[7f5323c01000+142000]
    [Tue Jan 21 22:07:17 2020] nginx[12710]: segfault at 8 ip 00007f5323cf77a1 sp 00007fff9ce5e010 error 4 in nginx[7f5323c01000+142000]
    [Tue Jan 21 22:10:19 2020] nginx[18345]: segfault at 8 ip 00007f5323cf77a1 sp 00007fff9ce5e030 error 4 in nginx[7f5323c01000+142000]
    [Tue Jan 21 22:10:57 2020] nginx[26517]: segfault at 8 ip 00007f5323cf77a1 sp 00007fff9ce5e030 error 4 in nginx[7f5323c01000+142000]

    然后有一天,我发现,这个时间戳是不对的。如下,用混杂模式触发一条日志:

    [root@tong ~]# date
    Tue Jan 21 16:32:23 CST 2020
    [root@tong ~]# dmesg -T |tail
    [Tue Jan 21 22:01:45 2020] device eth0 left promiscuous mode
    [root@tong ~]# cat /var/log/messages |grep eth0
    Jan 21 16:32:21 A04-R068-I136-198-JDCLOUD kernel: device eth0 left promiscuous mode

    观察三个时间,dmesg里,快了7个半小时。 因为它记录的是系统启动到现在的相对时间。秒数,如原始日志

    [root@tong ~]# dmesg |tail -n 4
    [40354589.699747] nginx[7607]: segfault at 8 ip 00007f5323cf77a1 sp 00007fff9ce5e030 error 4 in nginx[7f5323c01000+142000]
    [40354715.335800] nginx[12710]: segfault at 8 ip 00007f5323cf77a1 sp 00007fff9ce5e010 error 4 in nginx[7f5323c01000+142000]
    [40354897.701943] nginx[18345]: segfault at 8 ip 00007f5323cf77a1 sp 00007fff9ce5e030 error 4 in nginx[7f5323c01000+142000]
    [40354935.607226] nginx[26517]: segfault at 8 ip 00007f5323cf77a1 sp 00007fff9ce5e030 error 4 in nginx[7f5323c01000+142000]

    计算验证一下:

    [root@tong ~]# uptime -s
    2018-10-11 20:28:43
    [root@tong ~]# date -d '2018-10-11 20:28:43' +%s
    1539260923
    [root@tong ~]# date +%s
    1579596146
    [root@tong ~]# expr 1579596146 - 1539260923
    40335223
    [root@tong ~]# dmesg |tail -n 1
    [40354935.607226] nginx[26517]: segfault at 8 ip 00007f5323cf77a1 sp 00007fff9ce5e030 error 4 in nginx[7f5323c01000+142000]

    因为参考系不同,所以出现了如上的偏差。dmesg里的时间参考CPU的时钟频率(?)。系统时间参考的时候外部时间服务器。

    也就是说,466多天的运行,使本机的计时与真实时间产生了7个小时30分钟的误差。 

    而由于ntp的存在,或手动调整过时间,使系统时间与真实时间保持了一致。

    [classic_tong @ https://www.cnblogs.com/hugetong/p/12222470.html]

  • 相关阅读:
    Spring Boot 定时+多线程执行
    Spring Boot + Vue Element实现Excel文件上传、解析、下载(含完整实现过程)
    立个flag,2020年比2019年产出提升10倍
    《Google工作法》读书笔记
    学习Go语言(二)快速入门
    学习Go语言(一)环境安装及HelloWorld
    WPF 自定义控件缩放
    上、下位机软件通信时,结构体的内存对齐问题
    C 语言能不能在头文件定义全局变量?
    注释格式
  • 原文地址:https://www.cnblogs.com/hugetong/p/12222470.html
Copyright © 2011-2022 走看看