Skip to content

Commit 6f6be60

Browse files
committed
ring-buffer: Force before_stamp and write_stamp to be different on discard
Part of the logic of the new time stamp code depends on the before_stamp and the write_stamp to be different if the write_stamp does not match the last event on the buffer, as it will be used to calculate the delta of the next event written on the buffer. The discard logic depends on this, as the next event to come in needs to inject a full timestamp as it can not rely on the last event timestamp in the buffer because it is unknown due to events after it being discarded. But by changing the write_stamp back to the time before it, it forces the next event to use a full time stamp, instead of relying on it. The issue came when a full time stamp was used for the event, and rb_time_delta() returns zero in that case. The update to the write_stamp (which subtracts delta) made it not change. Then when the event is removed from the buffer, because the before_stamp and write_stamp still match, the next event written would calculate its delta from the write_stamp, but that would be wrong as the write_stamp is of the time of the event that was discarded. In the case that the delta change being made to write_stamp is zero, set the before_stamp to zero as well, and this will force the next event to inject a full timestamp and not use the current write_stamp. Cc: stable@vger.kernel.org Fixes: a389d86 ("ring-buffer: Have nested events still record running time stamp") Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 6926809 commit 6f6be60

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎kernel/trace/ring_buffer.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,6 +2814,17 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
28142814
write_stamp, write_stamp - delta))
28152815
return 0;
28162816

2817+
/*
2818+
* It's possible that the event time delta is zero
2819+
* (has the same time stamp as the previous event)
2820+
* in which case write_stamp and before_stamp could
2821+
* be the same. In such a case, force before_stamp
2822+
* to be different than write_stamp. It doesn't
2823+
* matter what it is, as long as its different.
2824+
*/
2825+
if (!delta)
2826+
rb_time_set(&cpu_buffer->before_stamp, 0);
2827+
28172828
/*
28182829
* If an event were to come in now, it would see that the
28192830
* write_stamp and the before_stamp are different, and assume

0 commit comments

Comments
 (0)