Skip to contentSkip to conversation

powerpc: perf: Fix frequency calculation for overflowing counters

PATCH In review Anton Blanchard 3 participants 6 messages Jan 17, 2011 – Jan 19, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 5674807..ab6f6be 100644
@@ -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;
#1 lore raw
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
index 5674807..ab6f6be 100644
@@ -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;
#2 lore raw
In reply to Anton Blanchard
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_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
index 5674807..ab6f6be 100644
@@ -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

#3 lore raw
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 -0
                      if (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.c need this as well (it has almost the same record_and_restart code)?=20

I would think so.

#4 lore raw

PATCH 1/1 powerpc: perf: Fix frequency calculation for overflowing counters (FSL version)

Quoted 5 lines
Quoted 3 lines

Does perf_event_fsl_emb.c need this as well (it has almost the same record_and_restart code)?

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
Index: powerpc.git/arch/powerpc/kernel/perf_event_fsl_emb.c
===================================================================
@@ -596,6 +596,7 @@ static void record_and_restart(struct pe
 			if (left <= 0)
 				left = period;
 			record = 1;
+			event->hw.last_period = event->hw.sample_period;
 		}
 		if (left < 0x80000000LL)
 			val = 0x80000000LL - left;
#5 lore raw

[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
index 4dcf5f8..b0dc8f7 100644
@@ -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;