Skip to content

Commit ead6ecf

Browse files
committed
ring-buffer: Have ring_buffer_empty() not depend on tracing stopped
It was complained about that when the trace file is read, that the tracing is disabled, as the iterator expects writing to the buffer it reads is not updated. Several steps are needed to make the iterator handle a writer, by testing if things have changed as it reads. This step is to make ring_buffer_empty() expect the buffer to be changing. Note if the current location of the iterator is overwritten, then it will return false as new data is being added. Note, that this means that data will be skipped. Link: http://lkml.kernel.org/r/20200317213415.870741809@goodmis.org Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent ff89510 commit ead6ecf

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

‎kernel/trace/ring_buffer.c‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,16 +3590,37 @@ int ring_buffer_iter_empty(struct ring_buffer_iter *iter)
35903590
struct buffer_page *reader;
35913591
struct buffer_page *head_page;
35923592
struct buffer_page *commit_page;
3593+
struct buffer_page *curr_commit_page;
35933594
unsigned commit;
3595+
u64 curr_commit_ts;
3596+
u64 commit_ts;
35943597

35953598
cpu_buffer = iter->cpu_buffer;
3596-
3597-
/* Remember, trace recording is off when iterator is in use */
35983599
reader = cpu_buffer->reader_page;
35993600
head_page = cpu_buffer->head_page;
36003601
commit_page = cpu_buffer->commit_page;
3602+
commit_ts = commit_page->page->time_stamp;
3603+
3604+
/*
3605+
* When the writer goes across pages, it issues a cmpxchg which
3606+
* is a mb(), which will synchronize with the rmb here.
3607+
* (see rb_tail_page_update())
3608+
*/
3609+
smp_rmb();
36013610
commit = rb_page_commit(commit_page);
3611+
/* We want to make sure that the commit page doesn't change */
3612+
smp_rmb();
3613+
3614+
/* Make sure commit page didn't change */
3615+
curr_commit_page = READ_ONCE(cpu_buffer->commit_page);
3616+
curr_commit_ts = READ_ONCE(curr_commit_page->page->time_stamp);
3617+
3618+
/* If the commit page changed, then there's more data */
3619+
if (curr_commit_page != commit_page ||
3620+
curr_commit_ts != commit_ts)
3621+
return 0;
36023622

3623+
/* Still racy, as it may return a false positive, but that's OK */
36033624
return ((iter->head_page == commit_page && iter->head == commit) ||
36043625
(iter->head_page == reader && commit_page == head_page &&
36053626
head_page->read == commit &&

0 commit comments

Comments
 (0)