Skip to content

Commit

Permalink
tracing: Wake up ring buffer waiters on closing of the file
Browse files Browse the repository at this point in the history
commit f3ddb74 upstream.

When the file that represents the ring buffer is closed, there may be
waiters waiting on more input from the ring buffer. Call
ring_buffer_wake_waiters() to wake up any waiters when the file is
closed.

Link: https://lkml.kernel.org/r/[email protected]

Cc: [email protected]
Cc: Ingo Molnar <[email protected]>
Cc: Andrew Morton <[email protected]>
Fixes: e30f53a ("tracing: Do not busy wait in buffer splice")
Signed-off-by: Steven Rostedt (Google) <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
rostedt authored and gregkh committed Oct 24, 2022
1 parent 220d170 commit 5544f41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/linux/trace_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct trace_iterator {
unsigned int temp_size;
char *fmt; /* modified format holder */
unsigned int fmt_size;
long wait_index;

/* trace_seq for __print_flags() and __print_symbolic() etc. */
struct trace_seq tmp_seq;
Expand Down
15 changes: 15 additions & 0 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -8160,6 +8160,12 @@ static int tracing_buffers_release(struct inode *inode, struct file *file)

__trace_array_put(iter->tr);

iter->wait_index++;
/* Make sure the waiters see the new wait_index */
smp_wmb();

ring_buffer_wake_waiters(iter->array_buffer->buffer, iter->cpu_file);

if (info->spare)
ring_buffer_free_read_page(iter->array_buffer->buffer,
info->spare_cpu, info->spare);
Expand Down Expand Up @@ -8313,17 +8319,26 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,

/* did we read anything? */
if (!spd.nr_pages) {
long wait_index;

if (ret)
goto out;

ret = -EAGAIN;
if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK))
goto out;

wait_index = READ_ONCE(iter->wait_index);

ret = wait_on_pipe(iter, iter->tr->buffer_percent);
if (ret)
goto out;

/* Make sure we see the new wait_index */
smp_rmb();
if (wait_index != iter->wait_index)
goto out;

goto again;
}

Expand Down

0 comments on commit 5544f41

Please sign in to comment.