From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E5BD2BFC8F for ; Sat, 4 Apr 2026 02:25:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775269534; cv=none; b=HqAcXKVM9ESCU7Omc5AvzzVlwRR8dJe9P8UXM9DwHtGYOxNctqdp9uPwzHiDkiqrRj15YL/ku+XMHEbY8ZFr6kiWa6diVFstWO+KQOmu7V3D99ofwbj9VamF3SL+X/hqDHnYc8gHt4QqEKDb+923S8uKWwYY5p07t2U2IResJO0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775269534; c=relaxed/simple; bh=nUowXFSnfTSR/DpjEObO4xQTh/eJ3gqq1fj8RBEb3wQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=N1ZhjWt8Wg+T7l5INyNGhW3MmhoCCsBs383/QTq4lukj9llUvnjGmqUneNsStlhdxs3n2sMRLt6iNT1Ag6IolSIHCUwCnG5eQYrhqSeJsk+f/iYplR9nuwQgmbkCWs3AI+yLJWslWzAKM2pbTEd/sRvPLOQNJB9uPgyjBHMC8HY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eTPeRcga; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eTPeRcga" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EA43C19423; Sat, 4 Apr 2026 02:25:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775269534; bh=nUowXFSnfTSR/DpjEObO4xQTh/eJ3gqq1fj8RBEb3wQ=; h=Date:From:To:Cc:Subject:References:From; b=eTPeRcgaO0UKcN9z7fdB2eJNRD+ScXfV3HC6QG7F/13WEjLwUvfagGoCbQkl96g72 tEKt+lpdhe56RkrDr3PZoQjie7F+/JVTpcRSJJ2lKrjeNrd6L9x8uR7k73wljn7thq mmvod8oqpASWEXRVXLIFTpzLjblPoQfMBj6yOheK6wZenKNR/CranP+tp+7Zl8gkb+ Bwo2EopjXwGiMLOeVcI0pOpLB0Hmj0RF0nKz7lQonfmfk0H1u0sDrAwXTsSrohzZhb 4tnUlk2dBA1uh9PyrndztQd/WOuRAeinS2hraKa+LPj/1Au4ZpkKLS8nUcnBM4EAa1 1xGWRmtBwNLwQ== Received: from rostedt by gandalf with local (Exim 4.99.1) (envelope-from ) id 1w8qie-0000000166T-1v8V; Fri, 03 Apr 2026 22:26:40 -0400 Message-ID: <20260404022640.317560976@kernel.org> User-Agent: quilt/0.69 Date: Fri, 03 Apr 2026 22:26:23 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , John Stultz Subject: [for-next][PATCH 6/6] tracing: Allow backup to save persistent ring buffer before it starts References: <20260404022617.436859059@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: Steven Rostedt 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 Cc: Mathieu Desnoyers Cc: John Stultz Link: https://patch.msgid.link/20260331163924.6ccb3896@gandalf.local.home Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 22 ++++++++++++++++++++++ kernel/trace/trace.h | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 267671b33dd3..e9455d46ec16 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -10865,9 +10865,31 @@ __init static void enable_instances(void) tr->range_name = no_free_ptr(rname); } + /* + * Save the events to start and enabled them after all boot instances + * have been created. + */ + tr->boot_events = curr_str; + } + + /* Enable the events after all boot instances have been created */ + list_for_each_entry(tr, &ftrace_trace_arrays, list) { + + if (!tr->boot_events || !(*tr->boot_events)) { + tr->boot_events = NULL; + continue; + } + + curr_str = tr->boot_events; + + /* Clear the instance if this is a persistent buffer */ + if (tr->flags & TRACE_ARRAY_FL_LAST_BOOT) + update_last_data(tr); + while ((tok = strsep(&curr_str, ","))) { early_enable_events(tr, tok, true); } + tr->boot_events = NULL; } } diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index b001fbba0881..e68f9c2027eb 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -405,7 +405,10 @@ struct trace_array { unsigned char trace_flags_index[TRACE_FLAGS_MAX_SIZE]; unsigned int flags; raw_spinlock_t start_lock; - const char *system_names; + union { + const char *system_names; + char *boot_events; + }; struct list_head err_log; struct dentry *dir; struct dentry *options; -- 2.51.0