Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tracing: Allow backup to save persistent ring buffer before it starts

When the persistent ring buffer was first introduced, it did not make
sense to start tracing for it on the kernel command line. That's because
if there was a crash, the start of events would invalidate the events from
the previous boot that had the crash.

But now that there's a "backup" instance that can take a snapshot of the
persistent ring buffer when boot starts, it is possible to have the
persistent ring buffer start events at boot up and not lose the old events.

Update the code where the boot events start after all boot time instances
are created. This will allow the backup instance to copy the persistent
ring buffer from the previous boot, and allow the persistent ring buffer
to start tracing new events for the current boot.

reserve_mem=100M:12M:trace trace_instance=boot_mapped^@trace,sched trace_instance=backup=boot_mapped

The above will create a boot_mapped persistent ring buffer and enabled the
scheduler events. If there's a crash, a "backup" instance will be created
holding the events of the persistent ring buffer from the previous boot,
while the persistent ring buffer will once again start tracing scheduler
events of the current boot.

Now the user doesn't have to remember to start the persistent ring buffer.
It will always have the events started at each boot.

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: John Stultz <jstultz@google.com>
Link: https://patch.msgid.link/20260331163924.6ccb3896@gandalf.local.home
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+26 -1
+22
kernel/trace/trace.c
··· 10865 10865 tr->range_name = no_free_ptr(rname); 10866 10866 } 10867 10867 10868 + /* 10869 + * Save the events to start and enabled them after all boot instances 10870 + * have been created. 10871 + */ 10872 + tr->boot_events = curr_str; 10873 + } 10874 + 10875 + /* Enable the events after all boot instances have been created */ 10876 + list_for_each_entry(tr, &ftrace_trace_arrays, list) { 10877 + 10878 + if (!tr->boot_events || !(*tr->boot_events)) { 10879 + tr->boot_events = NULL; 10880 + continue; 10881 + } 10882 + 10883 + curr_str = tr->boot_events; 10884 + 10885 + /* Clear the instance if this is a persistent buffer */ 10886 + if (tr->flags & TRACE_ARRAY_FL_LAST_BOOT) 10887 + update_last_data(tr); 10888 + 10868 10889 while ((tok = strsep(&curr_str, ","))) { 10869 10890 early_enable_events(tr, tok, true); 10870 10891 } 10892 + tr->boot_events = NULL; 10871 10893 } 10872 10894 } 10873 10895
+4 -1
kernel/trace/trace.h
··· 405 405 unsigned char trace_flags_index[TRACE_FLAGS_MAX_SIZE]; 406 406 unsigned int flags; 407 407 raw_spinlock_t start_lock; 408 - const char *system_names; 408 + union { 409 + const char *system_names; 410 + char *boot_events; 411 + }; 409 412 struct list_head err_log; 410 413 struct dentry *dir; 411 414 struct dentry *options;