Skip to contentSkip to conversation

ring-buffer: set the right timestamp in the slow path of __rb_reserve_next()

PATCH In review Andrea Righi 2 participants 2 messages Nov 28, 2020 – Nov 30, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ring-buffer: set the right timestamp in the slow path of __rb_reserve_next()

In the slow path of __rb_reserve_next() a nested event(s) can happen between evaluating the timestamp delta of the current event and updating write_stamp via local_cmpxchg(); in this case the delta is not valid anymore and it should be set to 0 (same timestamp as the interrupting event), since the event that we are currently processing is not the last event in the buffer.

Fixes a389d86f7fd0 ("ring-buffer: Have nested events still record running time stamp")
---
 kernel/trace/ring_buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/ring_buffer.c +3 -3
index dc83b3fa9fe7..5e30e0cdb6ce 100644
@@ -3287,11 +3287,11 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
 		ts = rb_time_stamp(cpu_buffer->buffer);
 		barrier();
  /*E*/		if (write == (local_read(&tail_page->write) & RB_WRITE_MASK) &&
-		    info->after < ts) {
+		    info->after < ts &&
+		    rb_time_cmpxchg(&cpu_buffer->write_stamp,
+				    info->after, info->ts)) {
 			/* Nothing came after this event between C and E */
 			info->delta = ts - info->after;
-			(void)rb_time_cmpxchg(&cpu_buffer->write_stamp,
-					      info->after, info->ts);
 			info->ts = ts;
 		} else {
 			/*
Signature · 1 line
2.29.2
maintainer
#1 lore raw
Quoted 8 lines · On Sat, 28 Nov 2020 10:15:17 +0100 Andrea Righi <[email protected]>…

In the slow path of __rb_reserve_next() a nested event(s) can happen between evaluating the timestamp delta of the current event and updating write_stamp via local_cmpxchg(); in this case the delta is not valid anymore and it should be set to 0 (same timestamp as the interrupting event), since the event that we are currently processing is not the last event in the buffer.

And it looks like we have a WINNER!

Thanks! It shows someone is paying attention.

There's a few other patches I need to test, but I've queued this up for my next pull request.

-- Steve

Quoted 25 lines
Fixes a389d86f7fd0 ("ring-buffer: Have nested events still record running time stamp")
---
 kernel/trace/ring_buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/ring_buffer.c +3 -3
index dc83b3fa9fe7..5e30e0cdb6ce 100644
@@ -3287,11 +3287,11 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
 		ts = rb_time_stamp(cpu_buffer->buffer);
 		barrier();
  /*E*/		if (write == (local_read(&tail_page->write) & RB_WRITE_MASK) &&
-		    info->after < ts) {
+		    info->after < ts &&
+		    rb_time_cmpxchg(&cpu_buffer->write_stamp,
+				    info->after, info->ts)) {
 			/* Nothing came after this event between C and E */
 			info->delta = ts - info->after;
-			(void)rb_time_cmpxchg(&cpu_buffer->write_stamp,
-					      info->after, info->ts);
 			info->ts = ts;
 		} else {
 			/*