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]

  • 相关阅读:
    <html>
    poj 2676 Sudoku
    百亿互金平台救火故事
    Retrofit三步理解之中的一个 ------------------ Retrofit的简单使用总结
    精简版—愤慨的小鸟
    POJ 1095 Trees Made to Order
    Android Studio 错误: 非法字符: &#39;ufeff&#39; 解决方式|错误: 须要class, interface或enum
    使用CodePush实时更新 React Native 和 Cordova 应用
    获取url地址参数
    利用jQuery 通用文件导出前端实现,MVC文件导出
  • 原文地址:https://www.cnblogs.com/hugetong/p/12222470.html
Copyright © 2011-2022 走看看