perf: fix PERF_EVENT_IOC_PERIOD to force-reset the period
Subsystems (3)
PATCH 1/2 perf: fix PERF_EVENT_IOC_PERIOD to force-reset the period
From: Peter Zijlstra <[email protected]>
Vince Weaver reports that, on all architectures apart from ARM, PERF_EVENT_IOC_PERIOD doesn't actually update the period until the next event fires. This is counter-intuitive behaviour and is better dealt with in the core code.
This patch ensures that the period is forcefully reset when dealing with such a request in the core code. A subsequent patch removes the equivalent hack from the ARM back-end.
---
Peter -- I didn't want this to get lost, so I picked it up, fixed a typo
and wrote a commit message. Could I add your SoB please?
Cheers,
Will
kernel/events/core.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
kernel/events/core.c +15 -1
@@ -3527,7 +3527,7 @@ static void perf_event_for_each(struct perf_event *event,static int perf_event_period (struct perf_event *event,u64 __user *arg) {struct perf_event_context *ctx = event->ctx; -int ret =0 ; +int ret =0 , active;u64 value;if (!is_sampling_event (event))
@@ -3551,6 +3551,20 @@ static int perf_event_period(struct perf_event *event, u64 __user *arg) event->attr.sample_period = value; event->hw.sample_period = value; } + + active = (event->state ==PERF_EVENT_STATE_ACTIVE ); +if (active) { +perf_pmu_disable (ctx->pmu); + event->pmu->stop (event,PERF_EF_UPDATE ); + } + +local64_set (&event->hw.period_left,0 ); + +if (active) { + event->pmu->start (event,PERF_EF_RELOAD ); +perf_pmu_enable (ctx->pmu); + } + unlock:raw_spin_unlock_irq (&ctx->lock);
Signature · 1 line
1.8.2.2
PATCH 2/2 Revert "ARM: 7556/1: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD"
This reverts commit 3581fe0ef37ce12ac7a4f74831168352ae848edc.
Updates to the handling of PERF_EVENT_IOC_PERIOD in the core code mean we no longer have to play this horrible game.
--- arch/arm/kernel/perf_event.c | 4 ---- 1 file changed, 4 deletions(-)
arch/arm/kernel/perf_event.c +0 -4
@@ -99,10 +99,6 @@ int 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);
Signature · 1 line
1.8.2.2
tip-bot for Will Deacon
merge bot[tip:perf/core] Revert "ARM: 7556/1: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD"
Revert "ARM: 7556/1: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD"
Commit-ID: 9450d14fb959336803e5209119eb422b667b96aa Gitweb: http://git.kernel.org/tip/9450d14fb959336803e5209119eb422b667b96aa Author: Will Deacon <[email protected]> AuthorDate: Wed, 27 Nov 2013 13:54:39 +0000 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 17 Dec 2013 15:21:35 +0100
Revert "ARM: 7556/1: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD"
This reverts commit 3581fe0ef37ce12ac7a4f74831168352ae848edc.
Fixes to the handling of PERF_EVENT_IOC_PERIOD in the core code mean we no longer have to play this horrible game.
--- arch/arm/kernel/perf_event.c | 4 ---- 1 file changed, 4 deletions(-)
arch/arm/kernel/perf_event.c +0 -4
@@ -99,10 +99,6 @@ int 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);
Quoted 4 lines · Will Deacon
Vince Weaver reports that, on all architectures apart from ARM,
PERF_EVENT_IOC_PERIODdoesn't actually update the period until the next event fires. This is counter-intuitive behaviour and is better dealt with in the core code.
To be fair, it was Andreas Sandberg <[email protected]> who noticed this issue and reported it to me (in the context of the manpage being wrong). I just passed it on to the linux-kernel list.
Vince
Hi Peter,
Do you have any thoughts on the below? It would be good to add your signed-off to the patch, since you wrote it originally.
Cheers,
Will
Quoted 62 lines · Will Deacon
From: Peter Zijlstra <[email protected]>
Vince Weaver reports that, on all architectures apart from ARM,
PERF_EVENT_IOC_PERIODdoesn't actually update the period until the next event fires. This is counter-intuitive behaviour and is better dealt with in the core code.This patch ensures that the period is forcefully reset when dealing with such a request in the core code. A subsequent patch removes the equivalent hack from the ARM back-end.
Cc Vince Weaver <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Will Deacon <[email protected]>---
Peter -- I didn't want this to get lost, so I picked it up, fixed a typo
and wrote a commit message. Could I add your SoB please?Cheers,
Willkernel/events/core.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)kernel/events/core.c +15
-1@@ -3527,7 +3527,7 @@ static void perf_event_for_each(struct perf_event *event,static int perf_event_period (struct perf_event *event,u64 __user *arg) {struct perf_event_context *ctx = event->ctx; -int ret =0 ; +int ret =0 , active;u64 value;if (!is_sampling_event (event))@@ -3551,6 +3551,20 @@ static int perf_event_period(struct perf_event *event, u64 __user *arg) event->attr.sample_period = value; event->hw.sample_period = value; } + + active = (event->state ==PERF_EVENT_STATE_ACTIVE ); +if (active) { +perf_pmu_disable (ctx->pmu); + event->pmu->stop (event,PERF_EF_UPDATE ); + } + +local64_set (&event->hw.period_left,0 ); + +if (active) { + event->pmu->start (event,PERF_EF_RELOAD ); +perf_pmu_enable (ctx->pmu); + } + unlock:raw_spin_unlock_irq (&ctx->lock);Signature · 1 line
1.8.2.2
Peter Zijlstra
maintainerQuoted 5 lines · Will Deacon
Hi Peter,
Do you have any thoughts on the below? It would be good to add your signed-off to the patch, since you wrote it originally.
Picked them up, thanks will!
tip-bot for Peter Zijlstra
merge bot[tip:perf/core] perf: Fix PERF_EVENT_IOC_PERIOD to force-reset the period
In reply to Will Deaconperf: Fix PERF_EVENT_IOC_PERIOD to force-reset the period
Commit-ID: bad7192b842c83e580747ca57104dd51fe08c223 Gitweb: http://git.kernel.org/tip/bad7192b842c83e580747ca57104dd51fe08c223 Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 27 Nov 2013 13:54:38 +0000 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 17 Dec 2013 15:21:33 +0100
perf: Fix PERF_EVENT_IOC_PERIOD to force-reset the period
Vince Weaver reports that, on all architectures apart from ARM, PERF_EVENT_IOC_PERIOD doesn't actually update the period until the next event fires. This is counter-intuitive behaviour and is better dealt with in the core code.
This patch ensures that the period is forcefully reset when dealing with such a request in the core code. A subsequent patch removes the equivalent hack from the ARM back-end.
--- kernel/events/core.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
kernel/events/core.c +15 -1
@@ -3527,7 +3527,7 @@ static void perf_event_for_each(struct perf_event *event,static int perf_event_period (struct perf_event *event,u64 __user *arg) {struct perf_event_context *ctx = event->ctx; -int ret =0 ; +int ret =0 , active;u64 value;if (!is_sampling_event (event))
@@ -3551,6 +3551,20 @@ static int perf_event_period(struct perf_event *event, u64 __user *arg) event->attr.sample_period = value; event->hw.sample_period = value; } + + active = (event->state ==PERF_EVENT_STATE_ACTIVE ); +if (active) { +perf_pmu_disable (ctx->pmu); + event->pmu->stop (event,PERF_EF_UPDATE ); + } + +local64_set (&event->hw.period_left,0 ); + +if (active) { + event->pmu->start (event,PERF_EF_RELOAD ); +perf_pmu_enable (ctx->pmu); + } + unlock:raw_spin_unlock_irq (&ctx->lock);