* [PATCH] tracing: Record trace_clock in last_boot_info
@ 2025-04-16 14:46 Masami Hiramatsu (Google)
2025-04-16 15:12 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: Masami Hiramatsu (Google) @ 2025-04-16 14:46 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 show
it via `last_boot_info` so that reader can docode the timestamp
correctly.
With this change, the first line of the last_boot_info becomes
trace_clock which is used when the trace was recorded. E.g.
/sys/kernel/tracing/instances/boot_mapped # cat last_boot_info
trace_clock: mono
ffffffff81000000 [kernel]
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
include/linux/trace_clock.h | 2 ++
kernel/trace/trace.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)
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..e59826fa4cb3 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;
@@ -7000,9 +7003,10 @@ static void show_last_boot_header(struct seq_file *m, struct trace_array *tr)
* Otherwise it shows the KASLR address from the previous boot which
* should not be the same as the current boot.
*/
- if (tscratch && (tr->flags & TRACE_ARRAY_FL_LAST_BOOT))
+ if (tscratch && (tr->flags & TRACE_ARRAY_FL_LAST_BOOT)) {
+ seq_printf(m, "trace_clock: %s\n", tscratch->clock);
seq_printf(m, "%lx\t[kernel]\n", tscratch->text_addr);
- else
+ } else
seq_puts(m, "# Current\n");
}
@@ -7289,6 +7293,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;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tracing: Record trace_clock in last_boot_info
2025-04-16 14:46 [PATCH] tracing: Record trace_clock in last_boot_info Masami Hiramatsu (Google)
@ 2025-04-16 15:12 ` Steven Rostedt
2025-04-17 5:09 ` Masami Hiramatsu
0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2025-04-16 15:12 UTC (permalink / raw)
To: Masami Hiramatsu (Google)
Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel
On Wed, 16 Apr 2025 23:46:38 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> Record trace_clock information in the trace_scratch area and show
> it via `last_boot_info` so that reader can docode the timestamp
> correctly.
> With this change, the first line of the last_boot_info becomes
> trace_clock which is used when the trace was recorded. E.g.
>
> /sys/kernel/tracing/instances/boot_mapped # cat last_boot_info
> trace_clock: mono
> ffffffff81000000 [kernel]
>
As this will not go in this cycle, which means tools may be built
around this.
Either we put it at the end, or we make it:
# trace_clock: mono
ffffffff81000000 [kernel]
Where "info" like "trace_clock" will be in the comment section, and all
non comments will be addresses.
Tooling can then just ignore the comment section, or read it for more
information.
-- Steve
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tracing: Record trace_clock in last_boot_info
2025-04-16 15:12 ` Steven Rostedt
@ 2025-04-17 5:09 ` Masami Hiramatsu
0 siblings, 0 replies; 3+ messages in thread
From: Masami Hiramatsu @ 2025-04-17 5:09 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Mathieu Desnoyers, linux-kernel, linux-trace-kernel
On Wed, 16 Apr 2025 11:12:27 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Wed, 16 Apr 2025 23:46:38 +0900
> "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
>
> > Record trace_clock information in the trace_scratch area and show
> > it via `last_boot_info` so that reader can docode the timestamp
> > correctly.
> > With this change, the first line of the last_boot_info becomes
> > trace_clock which is used when the trace was recorded. E.g.
> >
> > /sys/kernel/tracing/instances/boot_mapped # cat last_boot_info
> > trace_clock: mono
> > ffffffff81000000 [kernel]
> >
>
> As this will not go in this cycle, which means tools may be built
> around this.
>
> Either we put it at the end, or we make it:
>
> # trace_clock: mono
> ffffffff81000000 [kernel]
>
> Where "info" like "trace_clock" will be in the comment section, and all
> non comments will be addresses.
OK. Anyway, as we discussed offline, I'll update it to just set the
value to the "trace_clock" file instead of using "last_boot_info".
Thank you,
>
> Tooling can then just ignore the comment section, or read it for more
> information.
>
> -- Steve
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-17 5:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16 14:46 [PATCH] tracing: Record trace_clock in last_boot_info Masami Hiramatsu (Google)
2025-04-16 15:12 ` Steven Rostedt
2025-04-17 5:09 ` Masami Hiramatsu
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).