* [PATCH v2] tracing: Record trace_clock and recover when reboot
@ 2025-04-17 5:17 Masami Hiramatsu (Google)
2025-04-17 14:18 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: Masami Hiramatsu (Google) @ 2025-04-17 5:17 UTC (permalink / raw)
To: Steven Rostedt
Cc: Masami Hiramatsu, Mathieu Desnoyers, linux-kernel,
linux-trace-kernel
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Record trace_clock information in the trace_scratch area and recover
the trace_clock when boot, so that reader can docode the timestamp
correctly.
Note that since most trace_clocks records the timestamp in nano-
seconds, this is not a bug. But some trace_clock, like counter and
tsc will record the counter value. Only for those trace_clock user
needs this information.
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
Changes in v2:
- instead of exposing it via last_boot_info, set the current
trace_clock as the same clock we used in the last boot.
---
include/linux/trace_clock.h | 2 ++
kernel/trace/trace.c | 17 +++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/include/linux/trace_clock.h b/include/linux/trace_clock.h
index 00e8f98c940f..2245848270d2 100644
--- a/include/linux/trace_clock.h
+++ b/include/linux/trace_clock.h
@@ -15,6 +15,8 @@
#include <asm/trace_clock.h>
+#define TRACE_CLOCK_NAME_MAX 16
+
extern u64 notrace trace_clock_local(void);
extern u64 notrace trace_clock(void);
extern u64 notrace trace_clock_jiffies(void);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8ddf6b17215c..6ce5d05ec64d 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6004,6 +6004,7 @@ struct trace_mod_entry {
};
struct trace_scratch {
+ char clock[TRACE_CLOCK_NAME_MAX];
unsigned long text_addr;
unsigned long nr_entries;
struct trace_mod_entry entries[];
@@ -6114,6 +6115,8 @@ static void update_last_data(struct trace_array *tr)
if (tr->scratch) {
struct trace_scratch *tscratch = tr->scratch;
+ strscpy(tscratch->clock, trace_clocks[tr->clock_id].name,
+ TRACE_CLOCK_NAME_MAX);
memset(tscratch->entries, 0,
flex_array_size(tscratch, entries, tscratch->nr_entries));
tscratch->nr_entries = 0;
@@ -7289,6 +7292,12 @@ int tracing_set_clock(struct trace_array *tr, const char *clockstr)
tracing_reset_online_cpus(&tr->max_buffer);
#endif
+ if (tr->scratch && !(tr->flags & TRACE_ARRAY_FL_LAST_BOOT)) {
+ struct trace_scratch *tscratch = tr->scratch;
+
+ strscpy(tscratch->clock, trace_clocks[i].name, TRACE_CLOCK_NAME_MAX);
+ }
+
mutex_unlock(&trace_types_lock);
return 0;
@@ -9514,6 +9523,14 @@ static void setup_trace_scratch(struct trace_array *tr,
/* Scan modules to make text delta for modules. */
module_for_each_mod(make_mod_delta, tr);
+
+ /* Set trace_clock as the same of the previous boot. */
+ if (tscratch->clock[0]) {
+ if (tracing_set_clock(tr, tscratch->clock) < 0) {
+ pr_info("the previous trace_clock info is not valid.");
+ goto reset;
+ }
+ }
return;
reset:
/* Invalid trace modules */
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] tracing: Record trace_clock and recover when reboot 2025-04-17 5:17 [PATCH v2] tracing: Record trace_clock and recover when reboot Masami Hiramatsu (Google) @ 2025-04-17 14:18 ` Steven Rostedt 2025-04-17 22:45 ` Masami Hiramatsu 0 siblings, 1 reply; 3+ messages in thread From: Steven Rostedt @ 2025-04-17 14:18 UTC (permalink / raw) To: Masami Hiramatsu (Google) Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel On Thu, 17 Apr 2025 14:17:29 +0900 "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote: > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -6004,6 +6004,7 @@ struct trace_mod_entry { > }; > > struct trace_scratch { > + char clock[TRACE_CLOCK_NAME_MAX]; > unsigned long text_addr; > unsigned long nr_entries; > struct trace_mod_entry entries[]; > @@ -6114,6 +6115,8 @@ static void update_last_data(struct trace_array *tr) > if (tr->scratch) { > struct trace_scratch *tscratch = tr->scratch; > > + strscpy(tscratch->clock, trace_clocks[tr->clock_id].name, Why copy the name and not the clock_id? The clock ids should not change between kernels. -- Steve > + TRACE_CLOCK_NAME_MAX); > memset(tscratch->entries, 0, > flex_array_size(tscratch, entries, tscratch->nr_entries)); > tscratch->nr_entries = 0; ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] tracing: Record trace_clock and recover when reboot 2025-04-17 14:18 ` Steven Rostedt @ 2025-04-17 22:45 ` Masami Hiramatsu 0 siblings, 0 replies; 3+ messages in thread From: Masami Hiramatsu @ 2025-04-17 22:45 UTC (permalink / raw) To: Steven Rostedt; +Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel On Thu, 17 Apr 2025 10:18:04 -0400 Steven Rostedt <rostedt@goodmis.org> wrote: > On Thu, 17 Apr 2025 14:17:29 +0900 > "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote: > > > --- a/kernel/trace/trace.c > > +++ b/kernel/trace/trace.c > > @@ -6004,6 +6004,7 @@ struct trace_mod_entry { > > }; > > > > struct trace_scratch { > > + char clock[TRACE_CLOCK_NAME_MAX]; > > unsigned long text_addr; > > unsigned long nr_entries; > > struct trace_mod_entry entries[]; > > @@ -6114,6 +6115,8 @@ static void update_last_data(struct trace_array *tr) > > if (tr->scratch) { > > struct trace_scratch *tscratch = tr->scratch; > > > > + strscpy(tscratch->clock, trace_clocks[tr->clock_id].name, > > Why copy the name and not the clock_id? The name is more robust if we rebooted in the different kernel. > > The clock ids should not change between kernels. Hmm, I thought it could be changed because we didn't define it. ---- static struct { u64 (*func)(void); const char *name; int in_ns; /* is this clock in nanoseconds? */ } trace_clocks[] = { { trace_clock_local, "local", 1 }, { trace_clock_global, "global", 1 }, { trace_clock_counter, "counter", 0 }, { trace_clock_jiffies, "uptime", 0 }, { trace_clock, "perf", 1 }, { ktime_get_mono_fast_ns, "mono", 1 }, { ktime_get_raw_fast_ns, "mono_raw", 1 }, { ktime_get_boot_fast_ns, "boot", 1 }, { ktime_get_tai_fast_ns, "tai", 1 }, ARCH_TRACE_CLOCKS }; ---- So the clock id is just an index of this array. That can be changed easily between the kernel version. If we discard the previous boot data in that case, I agree with using clock ids. (Another reason for the implementation is that tracing_set_clock() only accepts a name, but this is just due to laziness on my part. :-( ) Thank you, > > -- Steve > > > + TRACE_CLOCK_NAME_MAX); > > memset(tscratch->entries, 0, > > flex_array_size(tscratch, entries, tscratch->nr_entries)); > > tscratch->nr_entries = 0; -- Masami Hiramatsu (Google) <mhiramat@kernel.org> ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-17 22:45 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-04-17 5:17 [PATCH v2] tracing: Record trace_clock and recover when reboot Masami Hiramatsu (Google) 2025-04-17 14:18 ` Steven Rostedt 2025-04-17 22:45 ` Masami Hiramatsu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox