Skip to content

Commit f3ddb74

Browse files
committed
tracing: Wake up ring buffer waiters on closing of the file
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]>
1 parent 7e9fbbb commit f3ddb74

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

include/linux/trace_events.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct trace_iterator {
9292
unsigned int temp_size;
9393
char *fmt; /* modified format holder */
9494
unsigned int fmt_size;
95+
long wait_index;
9596

9697
/* trace_seq for __print_flags() and __print_symbolic() etc. */
9798
struct trace_seq tmp_seq;

kernel/trace/trace.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8160,6 +8160,12 @@ static int tracing_buffers_release(struct inode *inode, struct file *file)
81608160

81618161
__trace_array_put(iter->tr);
81628162

8163+
iter->wait_index++;
8164+
/* Make sure the waiters see the new wait_index */
8165+
smp_wmb();
8166+
8167+
ring_buffer_wake_waiters(iter->array_buffer->buffer, iter->cpu_file);
8168+
81638169
if (info->spare)
81648170
ring_buffer_free_read_page(iter->array_buffer->buffer,
81658171
info->spare_cpu, info->spare);
@@ -8313,17 +8319,26 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
83138319

83148320
/* did we read anything? */
83158321
if (!spd.nr_pages) {
8322+
long wait_index;
8323+
83168324
if (ret)
83178325
goto out;
83188326

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

8331+
wait_index = READ_ONCE(iter->wait_index);
8332+
83238333
ret = wait_on_pipe(iter, iter->tr->buffer_percent);
83248334
if (ret)
83258335
goto out;
83268336

8337+
/* Make sure we see the new wait_index */
8338+
smp_rmb();
8339+
if (wait_index != iter->wait_index)
8340+
goto out;
8341+
83278342
goto again;
83288343
}
83298344

0 commit comments

Comments
 (0)