| 1 |
commit ad5d5292f16c6c1d7d3e257c4c7407594286b97e
|
| 2 |
Author: Eric B Munson <emunson@mgebm.net>
|
| 3 |
Date: Mon May 23 04:22:40 2011 +0000
|
| 4 |
|
| 5 |
powerpc/oprofile: Handle events that raise an exception without overflowing
|
| 6 |
|
| 7 |
Commit 0837e3242c73566fc1c0196b4ec61779c25ffc93 fixes a situation on POWER7
|
| 8 |
where events can roll back if a specualtive event doesn't actually complete.
|
| 9 |
This can raise a performance monitor exception. We need to catch this to ensure
|
| 10 |
that we reset the PMC. In all cases the PMC will be less than 256 cycles from
|
| 11 |
overflow.
|
| 12 |
|
| 13 |
This patch lifts Anton's fix for the problem in perf and applies it to oprofile
|
| 14 |
as well.
|
| 15 |
|
| 16 |
Signed-off-by: Eric B Munson <emunson@mgebm.net>
|
| 17 |
Cc: <stable@kernel.org> # as far back as it applies cleanly
|
| 18 |
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
|
| 19 |
|
| 20 |
diff --git a/arch/powerpc/oprofile/op_model_power4.c b/arch/powerpc/oprofile/op_model_power4.c
|
| 21 |
index 8ee51a2..e6bec74 100644
|
| 22 |
--- a/arch/powerpc/oprofile/op_model_power4.c
|
| 23 |
+++ b/arch/powerpc/oprofile/op_model_power4.c
|
| 24 |
@@ -261,6 +261,28 @@ static int get_kernel(unsigned long pc, unsigned long mmcra)
|
| 25 |
return is_kernel;
|
| 26 |
}
|
| 27 |
|
| 28 |
+static bool pmc_overflow(unsigned long val)
|
| 29 |
+{
|
| 30 |
+ if ((int)val < 0)
|
| 31 |
+ return true;
|
| 32 |
+
|
| 33 |
+ /*
|
| 34 |
+ * Events on POWER7 can roll back if a speculative event doesn't
|
| 35 |
+ * eventually complete. Unfortunately in some rare cases they will
|
| 36 |
+ * raise a performance monitor exception. We need to catch this to
|
| 37 |
+ * ensure we reset the PMC. In all cases the PMC will be 256 or less
|
| 38 |
+ * cycles from overflow.
|
| 39 |
+ *
|
| 40 |
+ * We only do this if the first pass fails to find any overflowing
|
| 41 |
+ * PMCs because a user might set a period of less than 256 and we
|
| 42 |
+ * don't want to mistakenly reset them.
|
| 43 |
+ */
|
| 44 |
+ if (__is_processor(PV_POWER7) && ((0x80000000 - val) <= 256))
|
| 45 |
+ return true;
|
| 46 |
+
|
| 47 |
+ return false;
|
| 48 |
+}
|
| 49 |
+
|
| 50 |
static void power4_handle_interrupt(struct pt_regs *regs,
|
| 51 |
struct op_counter_config *ctr)
|
| 52 |
{
|
| 53 |
@@ -281,7 +303,7 @@ static void power4_handle_interrupt(struct pt_regs *regs,
|
| 54 |
|
| 55 |
for (i = 0; i < cur_cpu_spec->num_pmcs; ++i) {
|
| 56 |
val = classic_ctr_read(i);
|
| 57 |
- if (val < 0) {
|
| 58 |
+ if (pmc_overflow(val)) {
|
| 59 |
if (oprofile_running && ctr[i].enabled) {
|
| 60 |
oprofile_add_ext_sample(pc, regs, i, is_kernel);
|
| 61 |
classic_ctr_write(i, reset_value[i]);
|