From 75de777bcca6036097dba1dc094e2677a805ea83 Mon Sep 17 00:00:00 2001 From: Will Deacon Date: Wed, 15 Aug 2012 15:39:32 +0100 Subject: [PATCH] ARM: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD The PERF_EVENT_IOC_PERIOD ioctl command can be used to change the sample period of a running perf_event. Consequently, when calculating the next event period, the new period will only be considered after the previous one has overflowed. This patch changes the calculation of the remaining event ticks so that they are offset if the period has changed. Cc: Peter Zijlstra Reported-by: Andreas Sandberg Signed-off-by: Will Deacon --- arch/arm/kernel/perf_event.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/kernel/perf_event.c b/arch/arm/kernel/perf_event.c index 93971b1a4f0b..53c0304b734a 100644 --- a/arch/arm/kernel/perf_event.c +++ b/arch/arm/kernel/perf_event.c @@ -96,6 +96,10 @@ armpmu_event_set_period(struct perf_event *event, s64 period = hwc->sample_period; int ret = 0; + /* The period may have been changed by PERF_EVENT_IOC_PERIOD */ + if (unlikely(period != hwc->last_period)) + left = period - (hwc->last_period - left); + if (unlikely(left <= -period)) { left = period; local64_set(&hwc->period_left, left); -- 2.39.5