[PATCH] perf/x86/intel: Fix inaccurate period in context switch for auto-reload
From: kan . liang
Date: Thu Dec 06 2018 - 18:04:35 EST
From: Kan Liang <kan.liang@xxxxxxxxxxxxxxx>
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")
Signed-off-by: Kan Liang <kan.liang@xxxxxxxxxxxxxxx>
---
arch/x86/events/intel/ds.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
index b7b01d7..a04b52b 100644
--- a/arch/x86/events/intel/ds.c
+++ b/arch/x86/events/intel/ds.c
@@ -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;
--
2.7.4