powerpc: perf: Fix frequency calculation for overflowing counters
Subsystems (2)
PATCH 1/1 powerpc: perf: Fix frequency calculation for overflowing counters
When profiling a benchmark that is almost 100% userspace, I noticed some wildly inaccurate profiles that showed almost all time spent in the kernel. Closer examination shows we were programming a tiny number of cycles into the PMU after each overflow (about ~200 away from the next overflow). This gets us stuck in a loop which we eventually break out of by throttling the PMU (there are regular throttle/unthrottle events in the log).
It looks like we aren't setting event->hw.last_period to something same and the frequency to period calculations in perf are going haywire. With the following patch we find the correct period after a few interrupts and stay there. I also see no more throttle events.
---
arch/powerpc/kernel/perf_event.c +1 -0
@@ -1212,6 +1212,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val,if (left <=0 ) left = period; record =1 ; + event->hw.last_period = event->hw.sample_period; }if (left <0x80000000LL ) val =0x80000000LL - left;
Commit-ID: 4bca770ede796a1ef7af9c983166d5608d9ccfaf Gitweb: http://git.kernel.org/tip/4bca770ede796a1ef7af9c983166d5608d9ccfaf Author: Anton Blanchard <[email protected]> AuthorDate: Mon, 17 Jan 2011 16:17:42 +1100 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 17 Jan 2011 11:43:02 +0100
powerpc: perf: Fix frequency calculation for overflowing counters
When profiling a benchmark that is almost 100% userspace, I noticed some wildly inaccurate profiles that showed almost all time spent in the kernel.
Closer examination shows we were programming a tiny number of cycles into the PMU after each overflow (about ~200 away from the next overflow). This gets us stuck in a loop which we eventually break out of by throttling the PMU (there are regular throttle/unthrottle events in the log).
It looks like we aren't setting event->hw.last_period to something same and the frequency to period calculations in perf are going haywire.
With the following patch we find the correct period after a few interrupts and stay there. I also see no more throttle events.
LKML-Reference: <20110117161742.5feb3761@kryten>
--- arch/powerpc/kernel/perf_event.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/powerpc/kernel/perf_event.c +1 -0
@@ -1212,6 +1212,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val,if (left <=0 ) left = period; record =1 ; + event->hw.last_period = event->hw.sample_period; }if (left <0x80000000LL ) val =0x80000000LL - left;
Quoted 28 lines · On Mon, 17 Jan 2011 16:17:42 +1100 Anton Blanchard <[email protected]> wrote:
When profiling a benchmark that is almost 100% userspace, I noticed some wildly inaccurate profiles that showed almost all time spent in the kernel. Closer examination shows we were programming a tiny number of cycles into the PMU after each overflow (about ~200 away from the next overflow). This gets us stuck in a loop which we eventually break out of by throttling the PMU (there are regular throttle/unthrottle events in the log).
It looks like we aren't setting
event->hw.last_periodto something same and the frequency to period calculations in perf are going haywire. With the following patch we find the correct period after a few interrupts and stay there. I also see no more throttle events.Signed-off-by Anton Blanchard <[email protected]>---
arch/powerpc/kernel/perf_event.c +1
-0@@ -1212,6 +1212,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val,if (left <=0 ) left = period; record =1 ; + event->hw.last_period = event->hw.sample_period; }if (left <0x80000000LL ) val =0x80000000LL - left;
Quoted 5 lines
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Does perf_event_fsl_emb.c need this as well (it has almost the same record_and_restart code)?
-Scott
Quoted 1 line · Scott Wood
arch/powerpc/kernel/per=
Quoted 1 line
arch/powerpc/kernel/per= renamed from arch/powerpc/kernel/perf_event.c +0
-0
f_event.c
Quoted 4 lines
arch/powerpc/kernel/perf_event.c static void record_and_restart(struct perf_event =
Quoted 4 lines
index 5674807..ab6f6be 100644
arch/powerpc/kernel/perf_event.c +0
-0@@ -1212,6 +1212,7 @@ static void record_and_restart(struct perf_event =
*event, unsigned long val,
Quoted 4 lines
arch/powerpc/kernel/perf_event.c static void record_and_restart(struct perf_event = · line 1215
Quoted 4 lines
arch/powerpc/kernel/perf_event.c +1
-0if (left <=3D 0) left =3D period; record =3D 1; + event->hw.last_period =3D event->hw.sample_period=
;
Quoted 6 lines
arch/powerpc/kernel/perf_event.c static void record_and_restart(struct perf_event *event, unsigned long val,
Quoted 3 lines
arch/powerpc/kernel/perf_event.c +0
-0}if (left <0x80000000LL ) val =3D 0x80000000LL - left;Does
perf_event_fsl_emb.cneed this as well (it has almost the samerecord_and_restartcode)?=20
I would think so.
PATCH 1/1 powerpc: perf: Fix frequency calculation for overflowing counters (FSL version)
Quoted 5 lines
Quoted 3 lines
Does
perf_event_fsl_emb.cneed this as well (it has almost the samerecord_and_restartcode)?I would think so.
Good point:
When fixing the frequency calculations for perf on powerpc I forgot to fix the FSL version.
If we dont set event->hw.last_period the frequency to period calculations in perf go haywire and we continually throttle/unthrottle the PMU.
---
This is only compile tested.
arch/powerpc/kernel/perf_event_fsl_emb.c +1 -0
@@ -596,6 +596,7 @@ static void record_and_restart(struct peif (left <=0 ) left = period; record =1 ; + event->hw.last_period = event->hw.sample_period; }if (left <0x80000000LL ) val =0x80000000LL - left;
[tip:perf/urgent] powerpc, perf: Fix frequency calculation for overflowing counters (FSL version)
Commit-ID: 8c8a9b25b5de3f1eeac721cf34f4379e56d5d694 Gitweb: http://git.kernel.org/tip/8c8a9b25b5de3f1eeac721cf34f4379e56d5d694 Author: Anton Blanchard <[email protected]> AuthorDate: Tue, 18 Jan 2011 21:44:04 +1100 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 19 Jan 2011 20:05:42 +0100
powerpc, perf: Fix frequency calculation for overflowing counters (FSL version)
When fixing the frequency calculations for perf on powerpc I forgot to fix the FSL version.
If we dont set event->hw.last_period the frequency to period calculations in perf go haywire and we continually throttle/unthrottle the PMU.
LKML-Reference: <20110118214404.2f42e634@kryten>
--- arch/powerpc/kernel/perf_event_fsl_emb.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/powerpc/kernel/perf_event_fsl_emb.c +1 -0
@@ -596,6 +596,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val,if (left <=0 ) left = period; record =1 ; + event->hw.last_period = event->hw.sample_period; }if (left <0x80000000LL ) val =0x80000000LL - left;