Skip to content

Commit 2632a20

Browse files
mhiramatrostedt
authored andcommitted
tracing: Record trace_clock and recover when reboot
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. Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Link: https://lore.kernel.org/174720625803.1925039.1815089037443798944.stgit@mhiramat.tok.corp.google.com Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 155fd6c commit 2632a20

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

kernel/trace/trace.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6066,6 +6066,7 @@ struct trace_mod_entry {
60666066
};
60676067

60686068
struct trace_scratch {
6069+
unsigned int clock_id;
60696070
unsigned long text_addr;
60706071
unsigned long nr_entries;
60716072
struct trace_mod_entry entries[];
@@ -6181,6 +6182,7 @@ static void update_last_data(struct trace_array *tr)
61816182
if (tr->scratch) {
61826183
struct trace_scratch *tscratch = tr->scratch;
61836184

6185+
tscratch->clock_id = tr->clock_id;
61846186
memset(tscratch->entries, 0,
61856187
flex_array_size(tscratch, entries, tscratch->nr_entries));
61866188
tscratch->nr_entries = 0;
@@ -7403,6 +7405,12 @@ int tracing_set_clock(struct trace_array *tr, const char *clockstr)
74037405
tracing_reset_online_cpus(&tr->max_buffer);
74047406
#endif
74057407

7408+
if (tr->scratch && !(tr->flags & TRACE_ARRAY_FL_LAST_BOOT)) {
7409+
struct trace_scratch *tscratch = tr->scratch;
7410+
7411+
tscratch->clock_id = i;
7412+
}
7413+
74067414
mutex_unlock(&trace_types_lock);
74077415

74087416
return 0;
@@ -9628,6 +9636,15 @@ static void setup_trace_scratch(struct trace_array *tr,
96289636

96299637
/* Scan modules to make text delta for modules. */
96309638
module_for_each_mod(make_mod_delta, tr);
9639+
9640+
/* Set trace_clock as the same of the previous boot. */
9641+
if (tscratch->clock_id != tr->clock_id) {
9642+
if (tscratch->clock_id >= ARRAY_SIZE(trace_clocks) ||
9643+
tracing_set_clock(tr, trace_clocks[tscratch->clock_id].name) < 0) {
9644+
pr_info("the previous trace_clock info is not valid.");
9645+
goto reset;
9646+
}
9647+
}
96319648
return;
96329649
reset:
96339650
/* Invalid trace modules */

0 commit comments

Comments
 (0)