Skip to content

Commit b627344

Browse files
Steven Rostedtrostedt
Steven Rostedt
authored andcommitted
tracing: Fix read blocking on trace_pipe_raw
If the ring buffer is empty, a read to trace_pipe_raw wont block. The tracing code has the infrastructure to wake up waiting readers, but the trace_pipe_raw doesn't take advantage of that. When a read is done to trace_pipe_raw without the O_NONBLOCK flag set, have the read block until there's data in the requested buffer. Signed-off-by: Steven Rostedt <[email protected]>
1 parent cc60cdc commit b627344

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

kernel/trace/trace.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4389,6 +4389,7 @@ static int tracing_buffers_open(struct inode *inode, struct file *filp)
43894389

43904390
info->iter.tr = tr;
43914391
info->iter.cpu_file = tc->cpu;
4392+
info->iter.trace = tr->current_trace;
43924393
info->spare = NULL;
43934394
/* Force reading ring buffer for first read */
43944395
info->read = (unsigned int)-1;
@@ -4428,18 +4429,29 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,
44284429
if (info->read < PAGE_SIZE)
44294430
goto read;
44304431

4432+
again:
44314433
trace_access_lock(iter->cpu_file);
44324434
ret = ring_buffer_read_page(iter->tr->buffer,
44334435
&info->spare,
44344436
count,
44354437
iter->cpu_file, 0);
44364438
trace_access_unlock(iter->cpu_file);
4437-
if (ret < 0)
4439+
4440+
if (ret < 0) {
4441+
if (trace_empty(iter)) {
4442+
if ((filp->f_flags & O_NONBLOCK))
4443+
return -EAGAIN;
4444+
iter->trace->wait_pipe(iter);
4445+
if (signal_pending(current))
4446+
return -EINTR;
4447+
goto again;
4448+
}
44384449
return 0;
4450+
}
44394451

44404452
info->read = 0;
44414453

4442-
read:
4454+
read:
44434455
size = PAGE_SIZE - info->read;
44444456
if (size > count)
44454457
size = count;
@@ -4616,7 +4628,7 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
46164628
ret = -EAGAIN;
46174629
goto out;
46184630
}
4619-
default_wait_pipe(iter);
4631+
iter->trace->wait_pipe(iter);
46204632
if (signal_pending(current)) {
46214633
ret = -EINTR;
46224634
goto out;

0 commit comments

Comments
 (0)