[PATCH v6 1/4] tracing: Reset last_boot_info if ring buffer is reset

Masami Hiramatsu (Google) posted 4 patches 1 week, 1 day ago
There is a newer version of this series
[PATCH v6 1/4] tracing: Reset last_boot_info if ring buffer is reset
Posted by Masami Hiramatsu (Google) 1 week, 1 day ago
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Commit 32dc0042528d ("tracing: Reset last-boot buffers when reading
out all cpu buffers") resets the last_boot_info when user read out
all data via trace_pipe* files. But it is not reset when user
resets the buffer from other files. (e.g. write `trace` file)

Reset it when the corresponding ring buffer is reset too.

Fixes: 32dc0042528d ("tracing: Reset last-boot buffers when reading out all cpu buffers")
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/trace.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 396d59202438..5c3e4a554143 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -4891,6 +4891,8 @@ static int tracing_single_release_tr(struct inode *inode, struct file *file)
 	return single_release(inode, file);
 }
 
+static bool update_last_data_if_empty(struct trace_array *tr);
+
 static int tracing_open(struct inode *inode, struct file *file)
 {
 	struct trace_array *tr = inode->i_private;
@@ -4915,6 +4917,8 @@ static int tracing_open(struct inode *inode, struct file *file)
 			tracing_reset_online_cpus(trace_buf);
 		else
 			tracing_reset_cpu(trace_buf, cpu);
+
+		update_last_data_if_empty(tr);
 	}
 
 	if (file->f_mode & FMODE_READ) {
@@ -5981,6 +5985,7 @@ tracing_set_trace_read(struct file *filp, char __user *ubuf,
 int tracer_init(struct tracer *t, struct trace_array *tr)
 {
 	tracing_reset_online_cpus(&tr->array_buffer);
+	update_last_data_if_empty(tr);
 	return t->init(tr);
 }
 
@@ -7799,6 +7804,7 @@ int tracing_set_clock(struct trace_array *tr, const char *clockstr)
 		ring_buffer_set_clock(tr->max_buffer.buffer, trace_clocks[i].func);
 	tracing_reset_online_cpus(&tr->max_buffer);
 #endif
+	update_last_data_if_empty(tr);
 
 	if (tr->scratch && !(tr->flags & TRACE_ARRAY_FL_LAST_BOOT)) {
 		struct trace_scratch *tscratch = tr->scratch;
@@ -8036,6 +8042,7 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
 				tracing_reset_online_cpus(&tr->max_buffer);
 			else
 				tracing_reset_cpu(&tr->max_buffer, iter->cpu_file);
+			update_last_data_if_empty(tr);
 		}
 		break;
 	}
Re: [PATCH v6 1/4] tracing: Reset last_boot_info if ring buffer is reset
Posted by Steven Rostedt 5 days ago
On Sun,  1 Feb 2026 12:29:07 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> @@ -8036,6 +8042,7 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
>  				tracing_reset_online_cpus(&tr->max_buffer);
>  			else
>  				tracing_reset_cpu(&tr->max_buffer, iter->cpu_file);
> +			update_last_data_if_empty(tr);

Is this needed? Memory mapped buffers (which the persistent ring buffer
is) do not have snapshot buffers.

-- Steve


>  		}
>  		break;
>  	}
Re: [PATCH v6 1/4] tracing: Reset last_boot_info if ring buffer is reset
Posted by Masami Hiramatsu (Google) 3 days, 12 hours ago
On Wed, 4 Feb 2026 20:40:49 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Sun,  1 Feb 2026 12:29:07 +0900
> "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> 
> > @@ -8036,6 +8042,7 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
> >  				tracing_reset_online_cpus(&tr->max_buffer);
> >  			else
> >  				tracing_reset_cpu(&tr->max_buffer, iter->cpu_file);
> > +			update_last_data_if_empty(tr);
> 
> Is this needed? Memory mapped buffers (which the persistent ring buffer
> is) do not have snapshot buffers.

Yeah, I did this just for consistency. But it is better to just leave
the comment here.

Thank you,

> 
> -- Steve
> 
> 
> >  		}
> >  		break;
> >  	}
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>