Skip to content

Commit

Permalink
powerpc/perf: power_pmu_start restores incorrect values, breaking fre…
Browse files Browse the repository at this point in the history
…quency events

perf on POWER stopped working after commit e050e3f (perf: Fix
broken interrupt rate throttling). That patch exposed a bug in
the POWER perf_events code.

Since the PMCs count upwards and take an exception when the top bit
is set, we want to write 0x80000000 - left in power_pmu_start. We were
instead programming in left which effectively disables the counter
until we eventually hit 0x80000000. This could take seconds or longer.

With the patch applied I get the expected number of samples:

          SAMPLE events:       9948

Signed-off-by: Anton Blanchard <[email protected]>
Acked-by: Paul Mackerras <[email protected]>
Signed-off-by: Benjamin Herrenschmidt <[email protected]>
Cc: <[email protected]>
  • Loading branch information
antonblanchard authored and ozbenh committed Feb 16, 2012
1 parent 64f8c13 commit 9a45a94
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion arch/powerpc/kernel/perf_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ static void power_pmu_start(struct perf_event *event, int ef_flags)
{
unsigned long flags;
s64 left;
unsigned long val;

if (!event->hw.idx || !event->hw.sample_period)
return;
Expand All @@ -880,7 +881,12 @@ static void power_pmu_start(struct perf_event *event, int ef_flags)

event->hw.state = 0;
left = local64_read(&event->hw.period_left);
write_pmc(event->hw.idx, left);

val = 0;
if (left < 0x80000000L)
val = 0x80000000L - left;

write_pmc(event->hw.idx, val);

perf_event_update_userpage(event);
perf_pmu_enable(event->pmu);
Expand Down

0 comments on commit 9a45a94

Please sign in to comment.