Skip to contentSkip to conversation

perf/x86/intel: Fix inaccurate period in context switch for auto-reload

PATCH New [email protected] 1 participant 1 message Dec 6, 2018

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

PATCH 1/1 perf/x86/intel: Fix inaccurate period in context switch for auto-reload

From: Kan Liang <[email protected]>

When a task, which is sampled by a PEBS event with a fixed period, is sched_in, the fixed period will always be used as new period for counter. It's inaccurate, because the left period from last sched_out isn't taken into account.

The auto-reload feature is implicitly enabled for a PEBS event with a fixed period. The feature has specific intel_pmu_save_and_restart_reload(), which never records the left period. The period_left, which is used in perf_event_set_period() to calculate the new period, is always the user defined fixed period.

With auto-reload, the counter always has a negative counter value. So the left period is -value. Update the period_left in intel_pmu_save_and_restart_reload().

Fixes commit d31fc13fdcb2 ("perf/x86/intel: Fix event update for auto-reload")
---
 arch/x86/events/intel/ds.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/events/intel/ds.c +2 -0
index b7b01d7..a04b52b 100644
@@ -1402,6 +1402,8 @@ intel_pmu_save_and_restart_reload(struct perf_event *event, int count)
 	old = ((s64)(prev_raw_count << shift) >> shift);
 	local64_add(new - old + count * period, &event->count);
 
+	local64_set(&hwc->period_left, -new);
+
 	perf_event_update_userpage(event);
 
 	return 0;
Signature · 1 line
2.7.4