All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] printk, Add printk.clock kernel parameter [v2]
@ 2016-01-13 12:34 Prarit Bhargava
  2016-01-13 12:34 ` [PATCH 1/2] kernel, timekeeping, add ktime_get_[boot|real|tai]_fast_ns functions Prarit Bhargava
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Prarit Bhargava @ 2016-01-13 12:34 UTC (permalink / raw)
  To: linux-kernel
  Cc: Prarit Bhargava, John Stultz, Xunlei Pang, Thomas Gleixner,
	Baolin Wang, Andrew Morton, Greg Kroah-Hartman, Petr Mladek,
	Tejun Heo, Peter Hurley, Vasily Averin, Joe Perches

The script used in the analysis below:

dmesg_with_human_timestamps () {
    $(type -P dmesg) "$@" | perl -w -e 'use strict;
        my ($uptime) = do { local @ARGV="/proc/uptime";<>}; ($uptime) = ($uptime =~ /^(\d+)\./);
        foreach my $line (<>) {
            printf( ($line=~/^\[\s*(\d+)\.\d+\](.+)/) ? ( "[%s]%s\n", scalar localtime(time - $uptime + $1), $2 ) : $line )
        }'
}

dmesg_with_human_timestamps

----8<----

Over the past years I've seen many reports of bugs that include
time-stamped kernel logs (enabled when CONFIG_PRINTK_TIME=y or
print.time=1 is specified as a kernel parameter) that do not align
with either external time stamped logs or /var/log/messages.

For example,

[root@intel-wildcatpass-06 ~]# date; echo "Hello!" > /dev/kmsg ; date
Thu Dec 17 13:58:31 EST 2015
Thu Dec 17 13:58:31 EST 2015

which displays

[83973.768912] Hello!

on the serial console.

Running a script to convert this to "boot time",

[root@intel-wildcatpass-06 ~]# ./human.sh  | tail -1
[Thu Dec 17 13:59:57 2015] Hello!

which is already off by 1 minute and 26 seconds off after ~24 hours of
uptime.

This occurs because the time stamp is obtained from a call to
local_clock() which (on x86) is a direct call to the hardware.  These
hardware clock reads are not modified by the standard ntp or ptp protocol,
while the other timestamps are, and that results in situations external
time sources are further and further offset from the kernel log
timestamps.

This patchset introduces additional NMI safe timekeeping functions and the
kernel parameter printk.clock=[local|boot|real|tai] allowing a
user to specify an adjusted clock to use with printk timestamps.  The
hardware clock, or the existing functionality, is preserved by default.

[v2]: use NMI safe timekeeping access functions

Cc: John Stultz <john.stultz@linaro.org>
Cc: Xunlei Pang <pang.xunlei@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Baolin Wang <baolin.wang@linaro.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Petr Mladek <pmladek@suse.cz>
Cc: Tejun Heo <tj@kernel.org>
Cc: Peter Hurley <peter@hurleysoftware.com>
Cc: Vasily Averin <vvs@virtuozzo.com>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Prarit Bhargava <prarit@redhat.com>


Prarit Bhargava (2):
  kernel, timekeeping, add ktime_get_[boot|real|tai]_fast_ns functions
  printk, Add printk.clock kernel parameter

 include/linux/timekeeping.h |    3 +++
 kernel/printk/printk.c      |   54 +++++++++++++++++++++++++++++++++++++++++--
 kernel/time/timekeeping.c   |   52 +++++++++++++++++++++++++++++++++--------
 3 files changed, 97 insertions(+), 12 deletions(-)

-- 
1.7.9.3

^ permalink raw reply	[flat|nested] 16+ messages in thread
* [PATCH 0/2] printk, Add a printk.clock kernel parameter
@ 2016-01-06 13:00 Prarit Bhargava
  2016-01-06 13:00 ` [PATCH 2/2] printk, Add " Prarit Bhargava
  0 siblings, 1 reply; 16+ messages in thread
From: Prarit Bhargava @ 2016-01-06 13:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: Prarit Bhargava, John Stultz, Xunlei Pang, Thomas Gleixner,
	Baolin Wang, Andrew Morton, Greg Kroah-Hartman, Petr Mladek,
	Tejun Heo, Peter Hurley, Vasily Averin, Joe Perches

Over the past years I've seen many reports of bugs that include
time-stamped kernel logs (enabled when CONFIG_PRINTK_TIME=y or
print.time=1 is specified as a kernel parameter) that do not align
with either external time stamped logs or /var/log/messages.

For example,

[root@intel-wildcatpass-06 ~]# date; echo "Hello!" > /dev/kmsg ; date
Thu Dec 17 13:58:31 EST 2015
Thu Dec 17 13:58:31 EST 2015

which displays

[83973.768912] Hello!

on the serial console.

Running a script to convert this to "boot time",

[root@intel-wildcatpass-06 ~]# ./human.sh  | tail -1
[Thu Dec 17 13:59:57 2015] Hello!

which is already off by 1 minute and 26 seconds off after ~24 hours of
uptime.

This occurs because the time stamp is obtained from a call to
local_clock() which (on x86) is a direct call to the hardware.  These
hardware clock reads are not modified by the standard ntp or ptp protocol,
while the other timestamps are, and that results in situations where
/var/log/messages timestamps are further and further offset from the
hardware clock timestamps.

This patch introduces printk.clock=[local|boot|real|tai] allowing a
user to specify an adjusted clock to use with printk timestamps.  The
hardware clock, or the existing functionality, is preserved by default.

Cc: John Stultz <john.stultz@linaro.org>
Cc: Xunlei Pang <pang.xunlei@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Baolin Wang <baolin.wang@linaro.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Petr Mladek <pmladek@suse.cz>
Cc: Tejun Heo <tj@kernel.org>
Cc: Peter Hurley <peter@hurleysoftware.com>
Cc: Vasily Averin <vvs@virtuozzo.com>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Prarit Bhargava <prarit@redhat.com>

Prarit Bhargava (2):
  kernel, timekeeping, add trylock option to ktime_get_with_offset()
  printk, Add printk.clock kernel parameter

 include/linux/time64.h      |    2 +
 include/linux/timekeeping.h |   50 +++++++++++++++++++--
 kernel/printk/printk.c      |  105 +++++++++++++++++++++++++++++++++++++++----
 kernel/time/timekeeping.c   |   15 ++++++-
 4 files changed, 159 insertions(+), 13 deletions(-)

-- 
1.7.9.3


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-01-22  8:05 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-13 12:34 [PATCH 0/2] printk, Add printk.clock kernel parameter [v2] Prarit Bhargava
2016-01-13 12:34 ` [PATCH 1/2] kernel, timekeeping, add ktime_get_[boot|real|tai]_fast_ns functions Prarit Bhargava
2016-01-13 12:34 ` [PATCH 2/2] printk, Add printk.clock kernel parameter Prarit Bhargava
2016-01-13 13:45 ` [PATCH 0/2] printk, Add printk.clock kernel parameter [v2] Thomas Gleixner
2016-01-13 14:36   ` Prarit Bhargava
2016-01-13 17:28     ` Thomas Gleixner
2016-01-14 12:52       ` Petr Mladek
2016-01-14 14:39         ` Prarit Bhargava
2016-01-14 14:44         ` Thomas Gleixner
2016-01-21 16:09           ` Prarit Bhargava
2016-01-22  8:04             ` Thomas Gleixner
  -- strict thread matches above, loose matches on Subject: below --
2016-01-06 13:00 [PATCH 0/2] printk, Add a printk.clock kernel parameter Prarit Bhargava
2016-01-06 13:00 ` [PATCH 2/2] printk, Add " Prarit Bhargava
2016-01-07 14:57   ` Petr Mladek
2016-01-07 15:38     ` Prarit Bhargava
2016-01-07 15:52       ` Petr Mladek
2016-01-08  9:04         ` Thomas Gleixner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.