ring-buffer: fix bug in ring_buffer_discard_commit
commita2023556409cf7fec5d67a26f7fcfa57c5a4086d
authorTim Bird <tim.bird@am.sony.com>
Wed, 3 Jun 2009 00:06:54 +0000 (2 17:06 -0700)
committerSteven Rostedt <rostedt@goodmis.org>
Wed, 3 Jun 2009 14:15:06 +0000 (3 10:15 -0400)
tree85d8824dd8989c62dc8f28feb2ee79f570f6872f
parent0f6ce3de4ef6ff940308087c49760d068851c1a7
ring-buffer: fix bug in ring_buffer_discard_commit

There's a bug in ring_buffer_discard_commit.  The wrong
pointer is being compared in order to check if the event
can be freed from the buffer rather than discarded
(i.e. marked as PAD).

I noticed this when I was working on duration filtering.
The bug is not deadly - it just results in lots of wasted
space in the buffer.  All filtered events are left in
the buffer and marked as discarded, rather than being
removed from the buffer to make space for other events.

Unfortunately, when I fixed this bug, I got errors doing a
filtered function trace.  Multiple TIME_EXTEND
events pile up in the buffer, and trigger the
following loop overage warning in rb_iter_peek():

again:
...
if (RB_WARN_ON(cpu_buffer, ++nr_loops > 10))
return NULL;

I'm not sure what the best way is to fix this. I don't
know if I should extend the loop threshhold, or if I should
make the test more complex (ignore TIME_EXTEND
events), or just get rid of this loop check completely.

Note that if I implement a workaround for this, then I
see another problem from rb_advance_iter().  I haven't
tracked that one down yet.

In general, it seems like the case of removing filtered
events has not been working properly, and so some assumptions
about buffer invariant conditions need to be revisited.

Here's the patch for the simple fix:

Compare correct pointer for checking if an event can be
freed rather than left as discarded in the buffer.

Signed-off-by: Tim Bird <tim.bird@am.sony.com>
LKML-Reference: <4A25BE9E.5090909@am.sony.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/ring_buffer.c