Skip to content

Commit

Permalink
ring-buffer: Optimize rb_iter_head_event()
Browse files Browse the repository at this point in the history
As it is fine to perform several "peeks" of event data in the ring buffer
via the iterator before moving it forward, do not re-read the event, just
return what was read before. Otherwise, it can cause inconsistent results,
especially when testing multiple CPU buffers to interleave them.

Link: http://lkml.kernel.org/r/20200317213416.592032170@goodmis.org

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt (VMware) committed Mar 19, 2020
1 parent ff84c50 commit 153368c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kernel/trace/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,9 @@ rb_iter_head_event(struct ring_buffer_iter *iter)
unsigned long commit;
unsigned length;

if (iter->head != iter->next_event)
return iter->event;

/*
* When the writer goes across pages, it issues a cmpxchg which
* is a mb(), which will synchronize with the rmb here.
Expand Down

0 comments on commit 153368c

Please sign in to comment.