<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1074664152;
        mso-list-type:hybrid;
        mso-list-template-ids:-2035105978 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hello,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">As the current maintainer of the PyKdump extension, I have been investigating a reported discrepancy between the timestamps generated by crash’s log -T and PyKdump’s tslog command, which provides the same functionality of timestamping the
 kernel log entries.  What I have found is that *<b>both</b>* log -T and tslog generate some inaccurate timestamps on vmcores with more than a small amount of uptime, but in different ways.  Specifically, log -T timestamps are accurate at boot time but become
 less accurate later in the log, while tslog timestamps are just the opposite: they’re accurate around crash time but less accurate earlier in the log.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here’s an example from a panic on a kernel 3.10.0-957.5.1 system with a moderate uptime:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">        DATE: Tue Jul  6 09:50:58 +03 2021<o:p></o:p></p>
<p class="MsoNormal">      UPTIME: 32 days, 16:29:29<o:p></o:p></p>
<p class="MsoNormal">       PANIC: "BUG: unable to handle kernel "<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Crash correctly computes the boot time based on the date (crash time) and uptime shown above.  From “help -k”:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">     boot_date: Thu Jun  3 17:21:29 +03 2021<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">log -T shows the correct timestamps of the boot messages:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[Thu Jun  3 17:21:29 +03 2021] Initializing cgroup subsys cpuset<o:p></o:p></p>
<p class="MsoNormal">[Thu Jun  3 17:21:29 +03 2021] Initializing cgroup subsys cpu<o:p></o:p></p>
<p class="MsoNormal">[Thu Jun  3 17:21:29 +03 2021] Initializing cgroup subsys cpuacct<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">However, the timestamps of the BUG and surrounding messages are off by 150 seconds or 2.5 minutes (09:53:28, but the crash occurred at 09:50:58):<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[Tue Jul  6 09:53:28 +03 2021] BUG: unable to handle kernel<o:p></o:p></p>
<p class="MsoNormal">[Tue Jul  6 09:53:28 +03 2021] NULL pointer dereference at           (null)<o:p></o:p></p>
<p class="MsoNormal">[Tue Jul  6 09:53:28 +03 2021] IP: [<ffffffff91cd6e66>] scsi_uninit_cmd+0x26/0x40<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">For comparison, tslog has the correct timestamps around the crash:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">2021-07-06 09:50:58 [2824319.188837] BUG: unable to handle kernel<o:p></o:p></p>
<p class="MsoNormal">2021-07-06 09:50:58 [2824319.193440] NULL pointer dereference at           (null)<o:p></o:p></p>
<p class="MsoNormal">2021-07-06 09:50:58 [2824319.197853] IP: [<ffffffff91cd6e66>] scsi_uninit_cmd+0x26/0x40<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">But it’s off by the same 2.5-minute interval during the boot messages (17:18:59, but it should be 17:21:29):<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">2021-06-03 17:18:59 [    0.000000] Initializing cgroup subsys cpuset<o:p></o:p></p>
<p class="MsoNormal">2021-06-03 17:18:59 [    0.000000] Initializing cgroup subsys cpu<o:p></o:p></p>
<p class="MsoNormal">2021-06-03 17:18:59 [    0.000000] Initializing cgroup subsys cpuacct<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The reasons for these inaccuracies are:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoListParagraph" style="margin-left:.25in;text-indent:-.25in;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="mso-list:Ignore">1.<span style="font:7.0pt "Times New Roman"">      
</span></span><![endif]>log -T computes boot time as (crash time minus uptime), and then adds the seconds part of the time stored in each log entry to generate the entry’s timestamp.<o:p></o:p></p>
<p class="MsoListParagraph" style="margin-left:.25in"><o:p> </o:p></p>
<p class="MsoListParagraph" style="margin-left:.25in;text-indent:-.25in;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="mso-list:Ignore">2.<span style="font:7.0pt "Times New Roman"">      
</span></span><![endif]>tslog computes a base time as (crash time minus seconds part of the final log entry) and then adds the seconds part of the time stored in each log entry.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoListParagraph" style="margin-left:.25in;text-indent:-.25in;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="mso-list:Ignore">3.<span style="font:7.0pt "Times New Roman"">      
</span></span><![endif]>The key to the problem: printk() stores the log entry timestamp based on a call to local_clock(), which provides the raw time in the local CPU, which is not adjusted by NTP.  As such, inaccuracy accumulates as the clock drifts over time;
 in the example above, the discrepancy has reached 150 seconds by the time of the crash. 
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have seen this now in numerous vmcores from kernels 3.0 through 4.12, which is the latest version I’ve checked.  The discrepancy exists in all of them with more than a few hours of uptime and can be positive or negative.  In one vmcore
 it was over 13 hours after 239 days of uptime.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">From the PyKdump perspective, I could live with the current tslog behavior because it’s accurate for log entries near the crash time, which are generally the most useful for crash analysis.  But in an attempt to improve it, I’m testing
 an experimental version of tslog that smooths out the discrepancy.  It computes the boot time the same way that crash does (crash time minus uptime) and a scale factor for the time discrepancy equal to (uptime)/(seconds part of final log entry).  Then each
 log entry’s timestamp is computed as (boot time) + (seconds part of log entry)*(scale factor).  This version results in correct timestamps at both ends of the log:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">2021-06-03 17:21:29 [    0.000000] Initializing cgroup subsys cpuset<o:p></o:p></p>
<p class="MsoNormal">2021-06-03 17:21:29 [    0.000000] Initializing cgroup subsys cpu<o:p></o:p></p>
<p class="MsoNormal">2021-06-03 17:21:29 [    0.000000] Initializing cgroup subsys cpuacct<o:p></o:p></p>
<p class="MsoNormal">    :<o:p></o:p></p>
<p class="MsoNormal">2021-07-06 09:50:58 [2824319.188837] BUG: unable to handle kernel<o:p></o:p></p>
<p class="MsoNormal">2021-07-06 09:50:58 [2824319.193440] NULL pointer dereference at           (null)<o:p></o:p></p>
<p class="MsoNormal">2021-07-06 09:50:58 [2824319.197853] IP: [<ffffffff91cd6e66>] scsi_uninit_cmd+0x26/0x40<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This is something of a hack since there’s no guarantee that the clock will drift uniformly during the system uptime, so timestamps in the middle of the log may still be somewhat inaccurate (but probably more accurate than without this adjustment).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regards,<o:p></o:p></p>
<p class="MsoNormal">Martin<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Explore the HPE digital support experience: <a href="https://support.hpe.com">
<span style="color:#0563C1">https://support.hpe.com</span></a><span style="font-size:10.0pt;color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;color:#1F497D">Martin Moore<br>
Linux Engineering Resolution Team<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;color:#1F497D">HPE Pointnext Services<br>
Hewlett Packard Enterprise<br>
<br>
<a href="mailto:Martin.Moore@hpe.com"><span style="color:#0563C1">Martin.Moore@hpe.com</span></a> <br>
8AM-5PM EDT (UTC-4) Monday-Friday<br>
Manager: Becky McBride (<a href="mailto:becky.mcbride@hpe.com"><span style="color:#0563C1">becky.mcbride@hpe.com</span></a>)<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>