Skip to content

Commit 32dc004

Browse files
mhiramatrostedt
authored andcommitted
tracing: Reset last-boot buffers when reading out all cpu buffers
Reset the last-boot ring buffers when read() reads out all cpu buffers through trace_pipe/trace_pipe_raw. This prevents ftrace to unwind ring buffer read pointer next boot. Note that this resets only when all per-cpu buffers are empty, and read via read(2) syscall. For example, if you read only one of the per-cpu trace_pipe, it does not reset it. Also, reading buffer by splice(2) syscall does not reset because some data in the reader (the last) page. Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Link: https://lore.kernel.org/174792929202.496143.8184644221859580999.stgit@mhiramat.tok.corp.google.com Suggested-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent c2a0831 commit 32dc004

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

kernel/trace/trace.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6610,6 +6610,22 @@ static int tracing_wait_pipe(struct file *filp)
66106610
return 1;
66116611
}
66126612

6613+
static bool update_last_data_if_empty(struct trace_array *tr)
6614+
{
6615+
if (!(tr->flags & TRACE_ARRAY_FL_LAST_BOOT))
6616+
return false;
6617+
6618+
if (!ring_buffer_empty(tr->array_buffer.buffer))
6619+
return false;
6620+
6621+
/*
6622+
* If the buffer contains the last boot data and all per-cpu
6623+
* buffers are empty, reset it from the kernel side.
6624+
*/
6625+
update_last_data(tr);
6626+
return true;
6627+
}
6628+
66136629
/*
66146630
* Consumer reader.
66156631
*/
@@ -6641,6 +6657,9 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
66416657
}
66426658

66436659
waitagain:
6660+
if (update_last_data_if_empty(iter->tr))
6661+
return 0;
6662+
66446663
sret = tracing_wait_pipe(filp);
66456664
if (sret <= 0)
66466665
return sret;
@@ -8167,6 +8186,9 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,
81678186

81688187
if (ret < 0) {
81698188
if (trace_empty(iter) && !iter->closed) {
8189+
if (update_last_data_if_empty(iter->tr))
8190+
return 0;
8191+
81708192
if ((filp->f_flags & O_NONBLOCK))
81718193
return -EAGAIN;
81728194

0 commit comments

Comments
 (0)