aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (VMware) <rostedt@goodmis.org>2017-04-19 14:29:46 -0400
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2017-04-19 21:23:47 -0400
commit78f7a45dac2a2d2002f98a3a95f7979867868d73 (patch)
treeeca8234531924e7b4ad3e0f55e3506ab6fe2b998
parentdf62db5be2e5f070ecd1a5ece5945b590ee112e0 (diff)
ring-buffer: Have ring_buffer_iter_empty() return true when empty
I noticed that reading the snapshot file when it is empty no longer gives a status. It suppose to show the status of the snapshot buffer as well as how to allocate and use it. For example: ># cat snapshot # tracer: nop # # # * Snapshot is allocated * # # Snapshot commands: # echo 0 > snapshot : Clears and frees snapshot buffer # echo 1 > snapshot : Allocates snapshot buffer, if not already allocated. # Takes a snapshot of the main buffer. # echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free) # (Doesn't have to be '2' works with any number that # is not a '0' or '1') But instead it just showed an empty buffer: ># cat snapshot # tracer: nop # # entries-in-buffer/entries-written: 0/0 #P:4 # # _-----=> irqs-off # / _----=> need-resched # | / _---=> hardirq/softirq # || / _--=> preempt-depth # ||| / delay # TASK-PID CPU# |||| TIMESTAMP FUNCTION # | | | |||| | | What happened was that it was using the ring_buffer_iter_empty() function to see if it was empty, and if it was, it showed the status. But that function was returning false when it was empty. The reason was that the iter header page was on the reader page, and the reader page was empty, but so was the buffer itself. The check only tested to see if the iter was on the commit page, but the commit page was no longer pointing to the reader page, but as all pages were empty, the buffer is also. Cc: stable@vger.kernel.org Fixes: 651e22f2701b ("ring-buffer: Always reset iterator to reader page") Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r--kernel/trace/ring_buffer.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 54e7a90db848..ca47a4fa2986 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3405,11 +3405,23 @@ EXPORT_SYMBOL_GPL(ring_buffer_iter_reset);
3405int ring_buffer_iter_empty(struct ring_buffer_iter *iter) 3405int ring_buffer_iter_empty(struct ring_buffer_iter *iter)
3406{ 3406{
3407 struct ring_buffer_per_cpu *cpu_buffer; 3407 struct ring_buffer_per_cpu *cpu_buffer;
3408 struct buffer_page *reader;
3409 struct buffer_page *head_page;
3410 struct buffer_page *commit_page;
3411 unsigned commit;
3408 3412
3409 cpu_buffer = iter->cpu_buffer; 3413 cpu_buffer = iter->cpu_buffer;
3410 3414
3411 return iter->head_page == cpu_buffer->commit_page && 3415 /* Remember, trace recording is off when iterator is in use */
3412 iter->head == rb_commit_index(cpu_buffer); 3416 reader = cpu_buffer->reader_page;
3417 head_page = cpu_buffer->head_page;
3418 commit_page = cpu_buffer->commit_page;
3419 commit = rb_page_commit(commit_page);
3420
3421 return ((iter->head_page == commit_page && iter->head == commit) ||
3422 (iter->head_page == reader && commit_page == head_page &&
3423 head_page->read == commit &&
3424 iter->head == rb_page_commit(cpu_buffer->reader_page)));
3413} 3425}
3414EXPORT_SYMBOL_GPL(ring_buffer_iter_empty); 3426EXPORT_SYMBOL_GPL(ring_buffer_iter_empty);
3415 3427