* [PATCH v2 0/3] POWER8 PMU bugfixes
@ 2014-07-08 6:38 Joel Stanley
2014-07-08 6:38 ` [PATCH v2 1/3] powerpc/kvm: Remove redundant save of SIER AND MMCR2 Joel Stanley
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Joel Stanley @ 2014-07-08 6:38 UTC (permalink / raw)
To: benh, paulus, mpe; +Cc: linuxppc-dev
These three patches are required for correct operation of perf counters on
POWER8 boxes when running KVM guests. There were two bugs; not clearing MMCR2
and writing over the saved value when entering a guest. However the first
obscured the second.
Thanks to who mpe helped diagnose the issue and pointed out the fix.
V2:
Add comment from mpe
Joel Stanley (3):
powerpc/kvm: Remove redundant save of SIER AND MMCR2
powerpc/perf: Add PPMU_ARCH_207S define
powerpc/perf: Clear MMCR2 when enabling PMU
arch/powerpc/include/asm/perf_event_server.h | 3 +--
arch/powerpc/kvm/book3s_hv_interrupts.S | 5 -----
arch/powerpc/perf/core-book3s.c | 9 ++++++---
arch/powerpc/perf/power8-pmu.c | 2 +-
4 files changed, 8 insertions(+), 11 deletions(-)
--
2.0.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] powerpc/kvm: Remove redundant save of SIER AND MMCR2
2014-07-08 6:38 [PATCH v2 0/3] POWER8 PMU bugfixes Joel Stanley
@ 2014-07-08 6:38 ` Joel Stanley
2014-07-08 6:38 ` [PATCH v2 2/3] powerpc/perf: Add PPMU_ARCH_207S define Joel Stanley
2014-07-08 6:38 ` [PATCH v2 3/3] powerpc/perf: Clear MMCR2 when enabling PMU Joel Stanley
2 siblings, 0 replies; 4+ messages in thread
From: Joel Stanley @ 2014-07-08 6:38 UTC (permalink / raw)
To: benh, paulus, mpe, Alexander Graf; +Cc: stable, linuxppc-dev, kvm-ppc, kvm
These two registers are already saved in the block above. Aside from
being unnecessary, by the time we get down to the second save location
r8 no longer contains MMCR2, so we are clobbering the saved value with
PMC5.
MMCR2 primarily consists of counter freeze bits. So restoring the value
of PMC5 into MMCR2 will most likely have the effect of freezing
counters.
Fixes: 72cde5a88d37 ("KVM: PPC: Book3S HV: Save/restore host PMU registers that are new in POWER8")
Cc: stable@vger.kernel.org
Signed-off-by: Joel Stanley <joel@jms.id.au>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
Acked-by: Paul Mackerras <paulus@samba.org>
Reviewed-by: Alexander Graf <agraf@suse.de>
---
V2:
- Add comments from mpe
arch/powerpc/kvm/book3s_hv_interrupts.S | 5 -----
1 file changed, 5 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_hv_interrupts.S b/arch/powerpc/kvm/book3s_hv_interrupts.S
index 8c86422..731be74 100644
--- a/arch/powerpc/kvm/book3s_hv_interrupts.S
+++ b/arch/powerpc/kvm/book3s_hv_interrupts.S
@@ -127,11 +127,6 @@ BEGIN_FTR_SECTION
stw r10, HSTATE_PMC + 24(r13)
stw r11, HSTATE_PMC + 28(r13)
END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
-BEGIN_FTR_SECTION
- mfspr r9, SPRN_SIER
- std r8, HSTATE_MMCR + 40(r13)
- std r9, HSTATE_MMCR + 48(r13)
-END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
31:
/*
--
2.0.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] powerpc/perf: Add PPMU_ARCH_207S define
2014-07-08 6:38 [PATCH v2 0/3] POWER8 PMU bugfixes Joel Stanley
2014-07-08 6:38 ` [PATCH v2 1/3] powerpc/kvm: Remove redundant save of SIER AND MMCR2 Joel Stanley
@ 2014-07-08 6:38 ` Joel Stanley
2014-07-08 6:38 ` [PATCH v2 3/3] powerpc/perf: Clear MMCR2 when enabling PMU Joel Stanley
2 siblings, 0 replies; 4+ messages in thread
From: Joel Stanley @ 2014-07-08 6:38 UTC (permalink / raw)
To: benh, paulus, mpe; +Cc: linuxppc-dev, stable
Instead of separate bits for every POWER8 PMU feature, have a single one
for v2.07 of the architecture.
This saves us adding a MMCR2 define for a future patch.
Cc: stable@vger.kernel.org
Signed-off-by: Joel Stanley <joel@jms.id.au>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
---
arch/powerpc/include/asm/perf_event_server.h | 3 +--
arch/powerpc/perf/core-book3s.c | 6 +++---
arch/powerpc/perf/power8-pmu.c | 2 +-
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/include/asm/perf_event_server.h b/arch/powerpc/include/asm/perf_event_server.h
index 9ed73714..b3e9360 100644
--- a/arch/powerpc/include/asm/perf_event_server.h
+++ b/arch/powerpc/include/asm/perf_event_server.h
@@ -61,8 +61,7 @@ struct power_pmu {
#define PPMU_SIAR_VALID 0x00000010 /* Processor has SIAR Valid bit */
#define PPMU_HAS_SSLOT 0x00000020 /* Has sampled slot in MMCRA */
#define PPMU_HAS_SIER 0x00000040 /* Has SIER */
-#define PPMU_BHRB 0x00000080 /* has BHRB feature enabled */
-#define PPMU_EBB 0x00000100 /* supports event based branch */
+#define PPMU_ARCH_207S 0x00000080 /* PMC is architecture v2.07S */
/*
* Values for flags to get_alternatives()
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index 4520c93..a2ff1bd 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -485,7 +485,7 @@ static bool is_ebb_event(struct perf_event *event)
* check that the PMU supports EBB, meaning those that don't can still
* use bit 63 of the event code for something else if they wish.
*/
- return (ppmu->flags & PPMU_EBB) &&
+ return (ppmu->flags & PPMU_ARCH_207S) &&
((event->attr.config >> PERF_EVENT_CONFIG_EBB_SHIFT) & 1);
}
@@ -777,7 +777,7 @@ void perf_event_print_debug(void)
if (ppmu->flags & PPMU_HAS_SIER)
sier = mfspr(SPRN_SIER);
- if (ppmu->flags & PPMU_EBB) {
+ if (ppmu->flags & PPMU_ARCH_207S) {
pr_info("MMCR2: %016lx EBBHR: %016lx\n",
mfspr(SPRN_MMCR2), mfspr(SPRN_EBBHR));
pr_info("EBBRR: %016lx BESCR: %016lx\n",
@@ -1696,7 +1696,7 @@ static int power_pmu_event_init(struct perf_event *event)
if (has_branch_stack(event)) {
/* PMU has BHRB enabled */
- if (!(ppmu->flags & PPMU_BHRB))
+ if (!(ppmu->flags & PPMU_ARCH_207S))
return -EOPNOTSUPP;
}
diff --git a/arch/powerpc/perf/power8-pmu.c b/arch/powerpc/perf/power8-pmu.c
index fe2763b..639cd91 100644
--- a/arch/powerpc/perf/power8-pmu.c
+++ b/arch/powerpc/perf/power8-pmu.c
@@ -792,7 +792,7 @@ static struct power_pmu power8_pmu = {
.get_constraint = power8_get_constraint,
.get_alternatives = power8_get_alternatives,
.disable_pmc = power8_disable_pmc,
- .flags = PPMU_HAS_SSLOT | PPMU_HAS_SIER | PPMU_BHRB | PPMU_EBB,
+ .flags = PPMU_HAS_SSLOT | PPMU_HAS_SIER | PPMU_ARCH_207S,
.n_generic = ARRAY_SIZE(power8_generic_events),
.generic_events = power8_generic_events,
.cache_events = &power8_cache_events,
--
2.0.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] powerpc/perf: Clear MMCR2 when enabling PMU
2014-07-08 6:38 [PATCH v2 0/3] POWER8 PMU bugfixes Joel Stanley
2014-07-08 6:38 ` [PATCH v2 1/3] powerpc/kvm: Remove redundant save of SIER AND MMCR2 Joel Stanley
2014-07-08 6:38 ` [PATCH v2 2/3] powerpc/perf: Add PPMU_ARCH_207S define Joel Stanley
@ 2014-07-08 6:38 ` Joel Stanley
2 siblings, 0 replies; 4+ messages in thread
From: Joel Stanley @ 2014-07-08 6:38 UTC (permalink / raw)
To: benh, paulus, mpe; +Cc: linuxppc-dev, stable
On POWER8 when switching to a KVM guest we set bits in MMCR2 to freeze
the PMU counters. Aside from on boot they are then never reset,
resulting in stuck perf counters for any user in the guest or host.
We now set MMCR2 to 0 whenever enabling the PMU, which provides a sane
state for perf to use the PMU counters under either the guest or the
host.
This was manifesting as a bug with ppc64_cpu --frequency:
$ sudo ppc64_cpu --frequency
WARNING: couldn't run on cpu 0
WARNING: couldn't run on cpu 8
...
WARNING: couldn't run on cpu 144
WARNING: couldn't run on cpu 152
min: 18446744073.710 GHz (cpu -1)
max: 0.000 GHz (cpu -1)
avg: 0.000 GHz
The command uses a perf counter to measure CPU cycles over a fixed
amount of time, in order to approximate the frequency of the machine.
The counters were returning zero once a guest was started, regardless of
weather it was still running or had been shut down.
By dumping the value of MMCR2, it was observed that once a guest is
running MMCR2 is set to 1s - which stops counters from running:
$ sudo sh -c 'echo p > /proc/sysrq-trigger'
CPU: 0 PMU registers, ppmu = POWER8 n_counters = 6
PMC1: 5b635e38 PMC2: 00000000 PMC3: 00000000 PMC4: 00000000
PMC5: 1bf5a646 PMC6: 5793d378 PMC7: deadbeef PMC8: deadbeef
MMCR0: 0000000080000000 MMCR1: 000000001e000000 MMCRA: 0000040000000000
MMCR2: fffffffffffffc00 EBBHR: 0000000000000000
EBBRR: 0000000000000000 BESCR: 0000000000000000
SIAR: 00000000000a51cc SDAR: c00000000fc40000 SIER: 0000000001000000
This is done unconditionally in book3s_hv_interrupts.S upon entering the
guest, and the original value is only save/restored if the host has
indicated it was using the PMU. This is okay, however the user of the
PMU needs to ensure that it is in a defined state when it starts using
it.
Fixes: e05b9b9e5c10 ("powerpc/perf: Power8 PMU support")
Cc: stable@vger.kernel.org
Signed-off-by: Joel Stanley <joel@jms.id.au>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
---
arch/powerpc/perf/core-book3s.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index a2ff1bd..bae697c 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -1300,6 +1300,9 @@ static void power_pmu_enable(struct pmu *pmu)
write_mmcr0(cpuhw, mmcr0);
+ if (ppmu->flags & PPMU_ARCH_207S)
+ mtspr(SPRN_MMCR2, 0);
+
/*
* Enable instruction sampling if necessary
*/
--
2.0.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-08 6:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-08 6:38 [PATCH v2 0/3] POWER8 PMU bugfixes Joel Stanley
2014-07-08 6:38 ` [PATCH v2 1/3] powerpc/kvm: Remove redundant save of SIER AND MMCR2 Joel Stanley
2014-07-08 6:38 ` [PATCH v2 2/3] powerpc/perf: Add PPMU_ARCH_207S define Joel Stanley
2014-07-08 6:38 ` [PATCH v2 3/3] powerpc/perf: Clear MMCR2 when enabling PMU Joel Stanley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).