Skip to contentSkip to conversation

perf: fix ordering in perf_output_sample()

PATCH New Stephane Eranian 1 participant 1 message Jun 13, 2012 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: fix ordering in perf_output_sample()

It seems like the merge of commits a7ac67ea and bce38cd5 caused an ordering problem in perf_output_sample(). The watermark check must be done at the very end of the function and not in the middle of writing data to the buffer.

---

kernel/events/core.c +14 -14
index f85c015..721ba28 100644
@@ -3979,20 +3979,6 @@ void perf_output_sample(struct perf_output_handle *handle,
 		}
 	}
 
-	if (!event->attr.watermark) {
-		int wakeup_events = event->attr.wakeup_events;
-
-		if (wakeup_events) {
-			struct ring_buffer *rb = handle->rb;
-			int events = local_inc_return(&rb->events);
-
-			if (events >= wakeup_events) {
-				local_sub(wakeup_events, &rb->events);
-				local_inc(&rb->wakeup);
-			}
-		}
-	}
-
 	if (sample_type & PERF_SAMPLE_BRANCH_STACK) {
 		if (data->br_stack) {
 			size_t size;
@@ -4010,6 +3996,20 @@ void perf_output_sample(struct perf_output_handle *handle,
 			perf_output_put(handle, nr);
 		}
 	}
+
+	if (!event->attr.watermark) {
+		int wakeup_events = event->attr.wakeup_events;
+
+		if (wakeup_events) {
+			struct ring_buffer *rb = handle->rb;
+			int events = local_inc_return(&rb->events);
+
+			if (events >= wakeup_events) {
+				local_sub(wakeup_events, &rb->events);
+				local_inc(&rb->wakeup);
+			}
+		}
+	}
 }
 
 void perf_prepare_sample(struct perf_event_header *header,