Skip to contentSkip to conversation

perf/core: Accumulate lost samples in inherited group reads

PATCH New Avi Weiss 2 participants 2 messages Nov 15 perf events

lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 perf/core: Accumulate lost samples in inherited group reads

__perf_read_group_add() accumulates event counts from inherited child events, but overwrites the PERF_FORMAT_LOST fields. A child reporting no losses therefore hides nonzero parent losses while it is alive.

Accumulate lost_samples for the group leader and siblings so group reads preserve losses across inherited events.

Fixes 119a784c8127 ("perf/core: Add a new read format to get a number of lost samples")
---
 kernel/events/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/events/core.c +2 -2
index 457d75ea7142..165eb55608b6 100644
@@ -6163,14 +6163,14 @@ static int __perf_read_group_add(struct perf_event *leader,
 	if (read_format & PERF_FORMAT_ID)
 		values[n++] = primary_event_id(leader);
 	if (read_format & PERF_FORMAT_LOST)
-		values[n++] = atomic64_read(&leader->lost_samples);
+		values[n++] += atomic64_read(&leader->lost_samples);
 
 	for_each_sibling_event(sub, leader) {
 		values[n++] += perf_event_count(sub, false);
 		if (read_format & PERF_FORMAT_ID)
 			values[n++] = primary_event_id(sub);
 		if (read_format & PERF_FORMAT_LOST)
-			values[n++] = atomic64_read(&sub->lost_samples);
+			values[n++] += atomic64_read(&sub->lost_samples);
 	}
 
 unlock:

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

__perf_read_group_add() accumulates event counts from inherited child events, but overwrites the PERF_FORMAT_LOST fields. A child reporting no losses therefore hides nonzero parent losses while it is alive.

Accumulate lost_samples for the group leader and siblings so group reads preserve losses across inherited events.

Fixes 119a784c8127 ("perf/core: Add a new read format to get a number of lost samples")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1