[lkml]   [2018]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH] perf/x86/intel: Fix inaccurate period in context switch for auto-reload
From: Kan Liang <>

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

Fixes: commit d31fc13fdcb2 ("perf/x86/intel: Fix event update for auto-reload")
Signed-off-by: Kan Liang <>
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);

return 0;
 \ /
  Last update: 2018-12-07 00:05    [W:0.023 / U:14.880 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site