LKML Archive on
help / color / mirror / Atom feed
From: Chris Wilson <>
	Chris Wilson <>,
	Steven Rostedt <>
Subject: [PATCH v3] trace: Default to using trace_global_clock if sched_clock is unstable
Date: Wed,  4 Apr 2018 21:51:02 +0100	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

Across suspend, we may see a very large drift in timestamps if the sched
clock is unstable, prompting the global trace's ringbuffer code to warn
and suggest switching to the global clock. Preempt this request by
detecting when the sched clock is unstable (determined during
late_initcall) and automatically switching the default clock over to

This should prevent requiring user interaction to resolve warnings such

    Delta way too big! 18446743856563626466 ts=18446744054496180323 write stamp = 197932553857
    If you just came from a suspend/resume,
    please switch to the trace global clock:
    echo global > /sys/kernel/debug/tracing/trace_clock

Signed-off-by: Chris Wilson <>
Cc: Steven Rostedt (VMware) <>
v2: Tell the user what's happening and what they can do to correct it.
v3: Restore the correct logic to switch only if the default trace clock
(no override) is found to be *not* stable.
 kernel/trace/trace.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 13baf85b27d8..a1810b053f65 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -41,6 +41,7 @@
 #include <linux/nmi.h>
 #include <linux/fs.h>
 #include <linux/trace.h>
+#include <linux/sched/clock.h>
 #include <linux/sched/rt.h>
 #include "trace.h"
@@ -8505,3 +8506,21 @@ __init static int clear_boot_tracer(void)
+__init static int tracing_set_default_clock(void)
+	/* sched_clock_stable() is determined in late_initcall */
+	if (!trace_boot_clock && !sched_clock_stable()) {
+		printk(KERN_WARNING
+		       "Unstable clock detected, switching default tracing clock to \"global\"\n"
+		       "If you want to keep using the local clock, then add:\n"
+		       "  \"trace_clock=local\"\n"
+		       "on the kernel command line\n");
+		tracing_set_clock(&global_trace, "global");
+	}
+	return 0;

  parent reply	other threads:[~2018-04-04 20:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-30 15:01 [PATCH v2 1/2] " Chris Wilson
2018-03-30 15:01 ` [PATCH v2 2/2] trace: Mention trace_clock=global when warning about unstable clocks Chris Wilson
2018-04-02 15:17 ` [PATCH v2 1/2] trace: Default to using trace_global_clock if sched_clock is unstable Steven Rostedt
2018-04-04 20:46 ` Chris Wilson
2018-04-04 20:51 ` Chris Wilson [this message]
2018-04-04 20:56   ` [PATCH v3] " Steven Rostedt
2018-04-04 21:24     ` [PATCH] trace: Fixup logic inversion on setting trace_global_clock defaults Chris Wilson
2018-04-05 11:48       ` Steven Rostedt

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:

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

  git send-email \ \ \ \ \ \
    --subject='Re: [PATCH v3] trace: Default to using trace_global_clock if sched_clock is unstable' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).