aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel/perf_counter.c
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2009-09-08 21:26:03 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2009-09-10 21:27:58 -0400
commita6dbf93a2ad853585409e715eb96dca9177e3c39 (patch)
tree617b29b2ae800d71f459288d232045a6efc6dfd0 /arch/powerpc/kernel/perf_counter.c
parent757cbd46d11cfa7506b7dd5dd6657ae645bf6a17 (diff)
powerpc: Fix bug where perf_counters breaks oprofile
Currently there is a bug where if you use oprofile on a pSeries machine, then use perf_counters, then use oprofile again, oprofile will not work correctly; it will lose the PMU configuration the next time the hypervisor does a partition context switch, and thereafter won't count anything. Maynard Johnson identified the sequence causing the problem: - oprofile setup calls ppc_enable_pmcs(), which calls pseries_lpar_enable_pmcs, which tells the hypervisor that we want to use the PMU, and sets the "PMU in use" flag in the lppaca. This flag tells the hypervisor whether it needs to save and restore the PMU config. - The perf_counter code sets and clears the "PMU in use" flag directly as it context-switches the PMU between tasks, and leaves it clear when it finishes. - oprofile setup, called for a new oprofile run, calls ppc_enable_pmcs, which does nothing because it has already been called. In particular it doesn't set the "PMU in use" flag. This fixes the problem by arranging for ppc_enable_pmcs to always set the "PMU in use" flag. It makes the perf_counter code call ppc_enable_pmcs also rather than calling the lower-level function directly, and removes the setting of the "PMU in use" flag from pseries_lpar_enable_pmcs, since that is now done in its caller. This also removes the declaration of pasemi_enable_pmcs because it isn't defined anywhere. Reported-by: Maynard Johnson <mpjohn@us.ibm.com> Signed-off-by: Paul Mackerras <paulus@samba.org> Cc: <stable@kernel.org) Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc/kernel/perf_counter.c')
-rw-r--r--arch/powerpc/kernel/perf_counter.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/arch/powerpc/kernel/perf_counter.c b/arch/powerpc/kernel/perf_counter.c
index 70e1f57f7dd8..ccd6b2135642 100644
--- a/arch/powerpc/kernel/perf_counter.c
+++ b/arch/powerpc/kernel/perf_counter.c
@@ -62,7 +62,6 @@ static inline unsigned long perf_ip_adjust(struct pt_regs *regs)
62{ 62{
63 return 0; 63 return 0;
64} 64}
65static inline void perf_set_pmu_inuse(int inuse) { }
66static inline void perf_get_data_addr(struct pt_regs *regs, u64 *addrp) { } 65static inline void perf_get_data_addr(struct pt_regs *regs, u64 *addrp) { }
67static inline u32 perf_get_misc_flags(struct pt_regs *regs) 66static inline u32 perf_get_misc_flags(struct pt_regs *regs)
68{ 67{
@@ -93,11 +92,6 @@ static inline unsigned long perf_ip_adjust(struct pt_regs *regs)
93 return 0; 92 return 0;
94} 93}
95 94
96static inline void perf_set_pmu_inuse(int inuse)
97{
98 get_lppaca()->pmcregs_in_use = inuse;
99}
100
101/* 95/*
102 * The user wants a data address recorded. 96 * The user wants a data address recorded.
103 * If we're not doing instruction sampling, give them the SDAR 97 * If we're not doing instruction sampling, give them the SDAR
@@ -531,8 +525,7 @@ void hw_perf_disable(void)
531 * Check if we ever enabled the PMU on this cpu. 525 * Check if we ever enabled the PMU on this cpu.
532 */ 526 */
533 if (!cpuhw->pmcs_enabled) { 527 if (!cpuhw->pmcs_enabled) {
534 if (ppc_md.enable_pmcs) 528 ppc_enable_pmcs();
535 ppc_md.enable_pmcs();
536 cpuhw->pmcs_enabled = 1; 529 cpuhw->pmcs_enabled = 1;
537 } 530 }
538 531
@@ -594,7 +587,7 @@ void hw_perf_enable(void)
594 mtspr(SPRN_MMCRA, cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE); 587 mtspr(SPRN_MMCRA, cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE);
595 mtspr(SPRN_MMCR1, cpuhw->mmcr[1]); 588 mtspr(SPRN_MMCR1, cpuhw->mmcr[1]);
596 if (cpuhw->n_counters == 0) 589 if (cpuhw->n_counters == 0)
597 perf_set_pmu_inuse(0); 590 ppc_set_pmu_inuse(0);
598 goto out_enable; 591 goto out_enable;
599 } 592 }
600 593
@@ -627,7 +620,7 @@ void hw_perf_enable(void)
627 * bit set and set the hardware counters to their initial values. 620 * bit set and set the hardware counters to their initial values.
628 * Then unfreeze the counters. 621 * Then unfreeze the counters.
629 */ 622 */
630 perf_set_pmu_inuse(1); 623 ppc_set_pmu_inuse(1);
631 mtspr(SPRN_MMCRA, cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE); 624 mtspr(SPRN_MMCRA, cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE);
632 mtspr(SPRN_MMCR1, cpuhw->mmcr[1]); 625 mtspr(SPRN_MMCR1, cpuhw->mmcr[1]);
633 mtspr(SPRN_MMCR0, (cpuhw->mmcr[0] & ~(MMCR0_PMC1CE | MMCR0_PMCjCE)) 626 mtspr(SPRN_MMCR0, (cpuhw->mmcr[0] & ~(MMCR0_PMC1CE | MMCR0_PMCjCE))