All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Linus Torvalds <torvalds@linuxfoundation.org>,
	Prarit Bhargava <prarit@redhat.com>,
	Mark Salyzyn <salyzyn@android.com>,
	Petr Mladek <pmladek@suse.com>, Ingo Molnar <mingo@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Joe Perches <joe@perches.com>
Subject: [RFC patch 3/7] printk: Use clock MONOTONIC for timestamps
Date: Wed, 15 Nov 2017 19:15:34 +0100	[thread overview]
Message-ID: <20171115182657.383713029@linutronix.de> (raw)
In-Reply-To: 20171115181531.322572387@linutronix.de

[-- Attachment #1: printk--Use-clock-MONOTONIC-for-timestamps.patch --]
[-- Type: text/plain, Size: 1731 bytes --]

local_clock() cannot be reliably correlated to CLOCK_MONOTONIC, which is
used by user space, e.g. systemd, to create correlation timestamps.

There are multiple reasons:

 - CLOCK_MONOTONIC is NTP adjusted, local_clock() not. Depending on the
   calibration accuracy and uptime significant drift can be observed.

 - CLOCK_MONOTONIC does not advance across suspend/resume for historical
   reasons. local_clock() might or might not depending on the properties of
   the underlying hardware counter.

Use the NMI safe accessor to clock MONOTONIC instead of local_clock(). The
access might be slower than local_clock(), but printk is not such a
performance critical hotpath that it matters.

Visible change:

The early boot timestamps are jiffies based longer than with local_clock()
depending on the platform. During suspend/resume the timestamp may become
stale when the underlying clocksource hardware is not flagged with
CLOCKSOURCE_SUSPEND_ACCESS_OK.

A horrible follow up patch demonstrates how that could be mitigated.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/printk/printk.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -624,7 +624,7 @@ static int log_store(int facility, int l
 	if (ts_nsec > 0)
 		msg->ts_nsec = ts_nsec;
 	else
-		msg->ts_nsec = local_clock();
+		msg->ts_nsec = ktime_get_mono_fast_ns();
 	memset(log_dict(msg) + dict_len, 0, pad_len);
 	msg->len = size;
 
@@ -1631,7 +1631,7 @@ static bool cont_add(int facility, int l
 		cont.facility = facility;
 		cont.level = level;
 		cont.owner = current;
-		cont.ts_nsec = local_clock();
+		cont.ts_nsec = ktime_get_mono_fast_ns();
 		cont.flags = flags;
 	}
 

  parent reply	other threads:[~2017-11-15 18:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-15 18:15 [RFC patch 0/7] printk: Switch to CLOCK_MONOTONIC and store extra time stamps Thomas Gleixner
2017-11-15 18:15 ` [RFC patch 1/7] timekeeping: Do not unconditionally suspend NMI safe timekeepers Thomas Gleixner
2017-11-15 18:15 ` [RFC patch 2/7] x86/tsc: Set clocksource CLOCK_SOURCE_SUSPEND_ACCESS_OK Thomas Gleixner
2017-11-15 18:15 ` Thomas Gleixner [this message]
2017-11-16  7:58   ` [RFC patch 3/7] printk: Use clock MONOTONIC for timestamps Sergey Senozhatsky
2017-11-15 18:15 ` [RFC patch 4/7] timekeeping: Add NMI safe accessor to mono/boot/real clocks Thomas Gleixner
2017-11-17 23:00   ` Steven Rostedt
2017-11-17 23:12     ` Linus Torvalds
2017-11-17 23:43       ` Thomas Gleixner
2017-11-15 18:15 ` [RFC patch 5/7] crash: Add VMCOREINFO_FIELD_AND_OFFSET() Thomas Gleixner
2017-11-23 12:46   ` Petr Mladek
2017-11-15 18:15 ` [RFC patch 6/7] printk: Store mono/boot/real time timestamps Thomas Gleixner
2017-11-23 13:36   ` Petr Mladek
2017-11-15 18:15 ` [RFC patch 7/7] timekeeping: Hack to use fine grained timestamps during boot Thomas Gleixner
2017-11-23 12:58   ` Petr Mladek
2017-11-28 18:43     ` Prarit Bhargava
2017-11-28 18:47       ` Thomas Gleixner
2017-12-08 11:23         ` Petr Mladek
2017-12-08 19:51           ` Thomas Gleixner
2017-11-28 19:10       ` Mark Salyzyn
2017-11-28 19:45         ` Steven Rostedt
2017-11-28 20:29           ` Mark Salyzyn
2017-11-28 20:38             ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171115182657.383713029@linutronix.de \
    --to=tglx@linutronix.de \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=prarit@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=salyzyn@android.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=torvalds@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.