Skip to content

Commit d819437

Browse files
khersRobert Richter
authored andcommitted
oprofile, powerpc: Handle events that raise an exception without overflowing
Commit 0837e32 fixes a situation on POWER7 where events can roll back if a specualtive event doesn't actually complete. This can raise a performance monitor exception. We need to catch this to ensure that we reset the PMC. In all cases the PMC will be less than 256 cycles from overflow. This patch lifts Anton's fix for the problem in perf and applies it to oprofile as well. Signed-off-by: Eric B Munson <emunson@mgebm.net> Cc: <stable@kernel.org> # as far back as it applies cleanly Tested-by: Maynard Johnson <maynardj@us.ibm.com> Signed-off-by: Robert Richter <robert.richter@amd.com>
1 parent 3d2606f commit d819437

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎arch/powerpc/oprofile/op_model_power4.c‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,28 @@ static int get_kernel(unsigned long pc, unsigned long mmcra)
261261
return is_kernel;
262262
}
263263

264+
static bool pmc_overflow(unsigned long val)
265+
{
266+
if ((int)val < 0)
267+
return true;
268+
269+
/*
270+
* Events on POWER7 can roll back if a speculative event doesn't
271+
* eventually complete. Unfortunately in some rare cases they will
272+
* raise a performance monitor exception. We need to catch this to
273+
* ensure we reset the PMC. In all cases the PMC will be 256 or less
274+
* cycles from overflow.
275+
*
276+
* We only do this if the first pass fails to find any overflowing
277+
* PMCs because a user might set a period of less than 256 and we
278+
* don't want to mistakenly reset them.
279+
*/
280+
if (__is_processor(PV_POWER7) && ((0x80000000 - val) <= 256))
281+
return true;
282+
283+
return false;
284+
}
285+
264286
static void power4_handle_interrupt(struct pt_regs *regs,
265287
struct op_counter_config *ctr)
266288
{
@@ -281,7 +303,7 @@ static void power4_handle_interrupt(struct pt_regs *regs,
281303

282304
for (i = 0; i < cur_cpu_spec->num_pmcs; ++i) {
283305
val = classic_ctr_read(i);
284-
if (val < 0) {
306+
if (pmc_overflow(val)) {
285307
if (oprofile_running && ctr[i].enabled) {
286308
oprofile_add_ext_sample(pc, regs, i, is_kernel);
287309
classic_ctr_write(i, reset_value[i]);

0 commit comments

Comments
 (0)