Skip to contentSkip to conversation

powerpc/perf: Add support for power10 PMU Hardware

PATCH In review Athira Rajeev 11 participants 51 messages Jul 17, 2020 – Jul 24, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v3 cover powerpc/perf: Add support for power10 PMU Hardware

The patch series adds support for power10 PMU hardware.

Patches 1..3 are the clean up patches which refactors the way how PMU SPR's are stored in core-book3s and in KVM book3s, as well as update data type for PMU cache_events.

Patches 12 and 13 adds base support for perf extended register capability in powerpc. Support for extended regs in power10 is covered in patches 14,15

Other patches includes main changes to support for power10 PMU.

Anju T Sudhakar (2):
powerpc/perf: Add support for outputting extended regs in perf
intr_regs
tools/perf: Add perf tools support for extended register capability in
powerpc

Athira Rajeev (10):
powerpc/perf: Update cpu_hw_event to use struct for storing MMCR
registers
KVM: PPC: Book3S HV: Cleanup updates for kvm vcpu MMCR powerpc/perf: Update Power PMU cache_events to u64 type
KVM: PPC: Book3S HV: Save/restore new PMU registers powerpc/perf: power10 Performance Monitoring support powerpc/perf: Ignore the BHRB kernel address filtering for P10 powerpc/perf: Add Power10 BHRB filter support for
PERF_SAMPLE_BRANCH_IND_CALL/COND
powerpc/perf: BHRB control to disable BHRB logic when not used powerpc/perf: Add extended regs support for power10 platform tools/perf: Add perf tools support for extended regs in power10

Madhavan Srinivasan (3):
powerpc/perf: Add support for ISA3.1 PMU SPRs
powerpc/xmon: Add PowerISA v3.1 PMU SPRs
powerpc/perf: Add power10_feat to dt_cpu_ftrs

---
Changes from v2 -> v3
- Addressed review comments from Michael Neuling, Michael Ellerman, Gautham Shenoy and Paul Mackerras

Changes from v1 -> v2
- Added support for extended regs in powerpc
for power9/power10 platform ( patches 12 to 15)
- Addressed change/removal of some event codes
in the PMU driver
---

 Documentation/virt/kvm/api.rst                  |   3 +
 arch/powerpc/include/asm/kvm_book3s_asm.h       |   2 +-
 arch/powerpc/include/asm/kvm_host.h             |   6 +-
 arch/powerpc/include/asm/perf_event_server.h    |  22 +-
 arch/powerpc/include/asm/processor.h            |   4 +
 arch/powerpc/include/asm/reg.h                  |   9 +
 arch/powerpc/include/uapi/asm/kvm.h             |   9 +-
 arch/powerpc/include/uapi/asm/perf_regs.h       |  20 +-
 arch/powerpc/kernel/asm-offsets.c               |   5 +
 arch/powerpc/kernel/cpu_setup_power.S           |   8 +
 arch/powerpc/kernel/dt_cpu_ftrs.c               |  26 ++
 arch/powerpc/kernel/sysfs.c                     |   8 +
 arch/powerpc/kvm/book3s_hv.c                    |  38 ++-
 arch/powerpc/kvm/book3s_hv_interrupts.S         |   8 +
 arch/powerpc/kvm/book3s_hv_rmhandlers.S         |  36 +-
 arch/powerpc/perf/Makefile                      |   2 +-
 arch/powerpc/perf/core-book3s.c                 | 108 ++++--
 arch/powerpc/perf/generic-compat-pmu.c          |   2 +-
 arch/powerpc/perf/internal.h                    |   1 +
 arch/powerpc/perf/isa207-common.c               |  91 +++--
 arch/powerpc/perf/isa207-common.h               |  37 ++-
 arch/powerpc/perf/mpc7450-pmu.c                 |  23 +-
 arch/powerpc/perf/perf_regs.c                   |  44 ++-
 arch/powerpc/perf/power10-events-list.h         |  70 ++++
 arch/powerpc/perf/power10-pmu.c                 | 425 ++++++++++++++++++++++++
 arch/powerpc/perf/power5+-pmu.c                 |  19 +-
 arch/powerpc/perf/power5-pmu.c                  |  19 +-
 arch/powerpc/perf/power6-pmu.c                  |  18 +-
 arch/powerpc/perf/power7-pmu.c                  |  19 +-
 arch/powerpc/perf/power8-pmu.c                  |   2 +-
 arch/powerpc/perf/power9-pmu.c                  |   8 +-
 arch/powerpc/perf/ppc970-pmu.c                  |  26 +-
 arch/powerpc/platforms/powernv/idle.c           |  22 +-
 arch/powerpc/xmon/xmon.c                        |  13 +
 tools/arch/powerpc/include/uapi/asm/kvm.h       |   9 +-
 tools/arch/powerpc/include/uapi/asm/perf_regs.h |  20 +-
 tools/perf/arch/powerpc/include/perf_regs.h     |   8 +-
 tools/perf/arch/powerpc/util/header.c           |   9 +-
 tools/perf/arch/powerpc/util/perf_regs.c        |  55 +++
 tools/perf/arch/powerpc/util/utils_header.h     |  15 +
 40 files changed, 1117 insertions(+), 152 deletions(-)
 create mode 100644 arch/powerpc/perf/power10-events-list.h
 create mode 100644 arch/powerpc/perf/power10-pmu.c
 create mode 100644 tools/perf/arch/powerpc/util/utils_header.h
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v3 1/15 powerpc/perf: Update cpu_hw_event to use `struct` for storing MMCR registers

core-book3s currently uses array to store the MMCR registers as part of per-cpu cpu_hw_events. This patch does a clean up to use struct to store mmcr regs instead of array. This will make code easier to read and reduces chance of any subtle bug that may come in the future, say when new registers are added. Patch updates all relevant code that was using MMCR array ( cpuhw->mmcr[x]) to use newly introduced struct. This includes the PMU driver code for supported platforms (power5 to power9) and ISA macros for counter support functions.

---
 arch/powerpc/include/asm/perf_event_server.h | 10 ++++--
 arch/powerpc/perf/core-book3s.c              | 53 +++++++++++++---------------
 arch/powerpc/perf/isa207-common.c            | 20 +++++------
 arch/powerpc/perf/isa207-common.h            |  4 +--
 arch/powerpc/perf/mpc7450-pmu.c              | 21 +++++++----
 arch/powerpc/perf/power5+-pmu.c              | 17 ++++-----
 arch/powerpc/perf/power5-pmu.c               | 17 ++++-----
 arch/powerpc/perf/power6-pmu.c               | 16 ++++-----
 arch/powerpc/perf/power7-pmu.c               | 17 ++++-----
 arch/powerpc/perf/ppc970-pmu.c               | 24 ++++++-------
 10 files changed, 105 insertions(+), 94 deletions(-)
arch/powerpc/include/asm/perf_event_server.h +8 -2
index 3e9703f..f9a3668 100644
@@ -17,6 +17,12 @@
 
 struct perf_event;
 
+struct mmcr_regs {
+	unsigned long mmcr0;
+	unsigned long mmcr1;
+	unsigned long mmcr2;
+	unsigned long mmcra;
+};
 /*
  * This struct provides the constants and functions needed to
  * describe the PMU on a particular POWER-family CPU.
@@ -28,7 +34,7 @@ struct power_pmu {
 	unsigned long	add_fields;
 	unsigned long	test_adder;
 	int		(*compute_mmcr)(u64 events[], int n_ev,
-				unsigned int hwc[], unsigned long mmcr[],
+				unsigned int hwc[], struct mmcr_regs *mmcr,
 				struct perf_event *pevents[]);
 	int		(*get_constraint)(u64 event_id, unsigned long *mskp,
 				unsigned long *valp);
@@ -41,7 +47,7 @@ struct power_pmu {
 	unsigned long	group_constraint_val;
 	u64             (*bhrb_filter_map)(u64 branch_sample_type);
 	void            (*config_bhrb)(u64 pmu_bhrb_filter);
-	void		(*disable_pmc)(unsigned int pmc, unsigned long mmcr[]);
+	void		(*disable_pmc)(unsigned int pmc, struct mmcr_regs *mmcr);
 	int		(*limited_pmc_event)(u64 event_id);
 	u32		flags;
 	const struct attribute_group	**attr_groups;
arch/powerpc/perf/core-book3s.c +24 -29

151 lines not on this page · raw message

arch/powerpc/perf/isa207-common.c +10 -10
index 4c86da5..2fe63f2 100644
@@ -363,7 +363,7 @@ int isa207_get_constraint(u64 event, unsigned long *maskp, unsigned long *valp)
 }
 
 int isa207_compute_mmcr(u64 event[], int n_ev,
-			       unsigned int hwc[], unsigned long mmcr[],
+			       unsigned int hwc[], struct mmcr_regs *mmcr,
 			       struct perf_event *pevents[])
 {
 	unsigned long mmcra, mmcr1, mmcr2, unit, combine, psel, cache, val;
@@ -464,30 +464,30 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
 	}
 
 	/* Return MMCRx values */
-	mmcr[0] = 0;
+	mmcr->mmcr0 = 0;
 
 	/* pmc_inuse is 1-based */
 	if (pmc_inuse & 2)
-		mmcr[0] = MMCR0_PMC1CE;
+		mmcr->mmcr0 = MMCR0_PMC1CE;
 
 	if (pmc_inuse & 0x7c)
-		mmcr[0] |= MMCR0_PMCjCE;
+		mmcr->mmcr0 |= MMCR0_PMCjCE;
 
 	/* If we're not using PMC 5 or 6, freeze them */
 	if (!(pmc_inuse & 0x60))
-		mmcr[0] |= MMCR0_FC56;
+		mmcr->mmcr0 |= MMCR0_FC56;
 
-	mmcr[1] = mmcr1;
-	mmcr[2] = mmcra;
-	mmcr[3] = mmcr2;
+	mmcr->mmcr1 = mmcr1;
+	mmcr->mmcra = mmcra;
+	mmcr->mmcr2 = mmcr2;
 
 	return 0;
 }
 
-void isa207_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+void isa207_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
 	if (pmc <= 3)
-		mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SHIFT(pmc + 1));
+		mmcr->mmcr1 &= ~(0xffUL << MMCR1_PMCSEL_SHIFT(pmc + 1));
 }
 
 static int find_alternative(u64 event, const unsigned int ev_alt[][MAX_ALT], int size)
arch/powerpc/perf/isa207-common.h +2 -2
index 63fd4f3..df968fd 100644
@@ -217,9 +217,9 @@
 
 int isa207_get_constraint(u64 event, unsigned long *maskp, unsigned long *valp);
 int isa207_compute_mmcr(u64 event[], int n_ev,
-				unsigned int hwc[], unsigned long mmcr[],
+				unsigned int hwc[], struct mmcr_regs *mmcr,
 				struct perf_event *pevents[]);
-void isa207_disable_pmc(unsigned int pmc, unsigned long mmcr[]);
+void isa207_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr);
 int isa207_get_alternatives(u64 event, u64 alt[], int size, unsigned int flags,
 					const unsigned int ev_alt[][MAX_ALT]);
 void isa207_get_mem_data_src(union perf_mem_data_src *dsrc, u32 flags,
arch/powerpc/perf/mpc7450-pmu.c +14 -7
index 4d5ef92..826de25 100644
@@ -257,7 +257,7 @@ static int mpc7450_get_alternatives(u64 event, unsigned int flags, u64 alt[])
  * Compute MMCR0/1/2 values for a set of events.
  */
 static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[],
-				unsigned long mmcr[],
+				struct mmcr_regs *mmcr,
 				struct perf_event *pevents[])
 {
 	u8 event_index[N_CLASSES][N_COUNTER];
@@ -321,9 +321,16 @@ static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[],
 		mmcr0 |= MMCR0_PMCnCE;
 
 	/* Return MMCRx values */
-	mmcr[0] = mmcr0;
-	mmcr[1] = mmcr1;
-	mmcr[2] = mmcr2;
+	mmcr->mmcr0 = mmcr0;
+	mmcr->mmcr1 = mmcr1;
+	mmcr->mmcr2 = mmcr2;
+	/*
+	 * 32-bit doesn't have an MMCRA and uses SPRN_MMCR2 to define
+	 * SPRN_MMCRA. So assign mmcra of cpu_hw_events with `mmcr2`
+	 * value to ensure that any write to this SPRN_MMCRA will
+	 * use mmcr2 value.
+	 */
+	mmcr->mmcra = mmcr2;
 	return 0;
 }
 
@@ -331,12 +338,12 @@ static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[],
  * Disable counting by a PMC.
  * Note that the pmc argument is 0-based here, not 1-based.
  */
-static void mpc7450_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void mpc7450_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
 	if (pmc <= 1)
-		mmcr[0] &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
+		mmcr->mmcr0 &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
 	else
-		mmcr[1] &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
+		mmcr->mmcr1 &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
 }
 
 static int mpc7450_generic_events[] = {
arch/powerpc/perf/power5+-pmu.c +9 -8
index f857454..5f0821e 100644
@@ -448,7 +448,8 @@ static int power5p_marked_instr_event(u64 event)
 }
 
 static int power5p_compute_mmcr(u64 event[], int n_ev,
-				unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+				unsigned int hwc[], struct mmcr_regs *mmcr,
+				struct perf_event *pevents[])
 {
 	unsigned long mmcr1 = 0;
 	unsigned long mmcra = 0;
@@ -586,20 +587,20 @@ static int power5p_compute_mmcr(u64 event[], int n_ev,
 	}
 
 	/* Return MMCRx values */
-	mmcr[0] = 0;
+	mmcr->mmcr0 = 0;
 	if (pmc_inuse & 1)
-		mmcr[0] = MMCR0_PMC1CE;
+		mmcr->mmcr0 = MMCR0_PMC1CE;
 	if (pmc_inuse & 0x3e)
-		mmcr[0] |= MMCR0_PMCjCE;
-	mmcr[1] = mmcr1;
-	mmcr[2] = mmcra;
+		mmcr->mmcr0 |= MMCR0_PMCjCE;
+	mmcr->mmcr1 = mmcr1;
+	mmcr->mmcra = mmcra;
 	return 0;
 }
 
-static void power5p_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void power5p_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
 	if (pmc <= 3)
-		mmcr[1] &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
+		mmcr->mmcr1 &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power5p_generic_events[] = {
arch/powerpc/perf/power5-pmu.c +9 -8
index da52eca..426021d 100644
@@ -379,7 +379,8 @@ static int power5_marked_instr_event(u64 event)
 }
 
 static int power5_compute_mmcr(u64 event[], int n_ev,
-			       unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+			       unsigned int hwc[], struct mmcr_regs *mmcr,
+			       struct perf_event *pevents[])
 {
 	unsigned long mmcr1 = 0;
 	unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
@@ -528,20 +529,20 @@ static int power5_compute_mmcr(u64 event[], int n_ev,
 	}
 
 	/* Return MMCRx values */
-	mmcr[0] = 0;
+	mmcr->mmcr0 = 0;
 	if (pmc_inuse & 1)
-		mmcr[0] = MMCR0_PMC1CE;
+		mmcr->mmcr0 = MMCR0_PMC1CE;
 	if (pmc_inuse & 0x3e)
-		mmcr[0] |= MMCR0_PMCjCE;
-	mmcr[1] = mmcr1;
-	mmcr[2] = mmcra;
+		mmcr->mmcr0 |= MMCR0_PMCjCE;
+	mmcr->mmcr1 = mmcr1;
+	mmcr->mmcra = mmcra;
 	return 0;
 }
 
-static void power5_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void power5_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
 	if (pmc <= 3)
-		mmcr[1] &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
+		mmcr->mmcr1 &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power5_generic_events[] = {
arch/powerpc/perf/power6-pmu.c +8 -8
index 3929cac..e343a51 100644
@@ -171,7 +171,7 @@ static int power6_marked_instr_event(u64 event)
  * Assign PMC numbers and compute MMCR1 value for a set of events
  */
 static int p6_compute_mmcr(u64 event[], int n_ev,
-			   unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+			   unsigned int hwc[], struct mmcr_regs *mmcr, struct perf_event *pevents[])
 {
 	unsigned long mmcr1 = 0;
 	unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
@@ -243,13 +243,13 @@ static int p6_compute_mmcr(u64 event[], int n_ev,
 		if (pmc < 4)
 			mmcr1 |= (unsigned long)psel << MMCR1_PMCSEL_SH(pmc);
 	}
-	mmcr[0] = 0;
+	mmcr->mmcr0 = 0;
 	if (pmc_inuse & 1)
-		mmcr[0] = MMCR0_PMC1CE;
+		mmcr->mmcr0 = MMCR0_PMC1CE;
 	if (pmc_inuse & 0xe)
-		mmcr[0] |= MMCR0_PMCjCE;
-	mmcr[1] = mmcr1;
-	mmcr[2] = mmcra;
+		mmcr->mmcr0 |= MMCR0_PMCjCE;
+	mmcr->mmcr1 = mmcr1;
+	mmcr->mmcra = mmcra;
 	return 0;
 }
 
@@ -457,11 +457,11 @@ static int p6_get_alternatives(u64 event, unsigned int flags, u64 alt[])
 	return nalt;
 }
 
-static void p6_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void p6_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
 	/* Set PMCxSEL to 0 to disable PMCx */
 	if (pmc <= 3)
-		mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
+		mmcr->mmcr1 &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power6_generic_events[] = {
arch/powerpc/perf/power7-pmu.c +9 -8
index a137813..3152336 100644
@@ -242,7 +242,8 @@ static int power7_marked_instr_event(u64 event)
 }
 
 static int power7_compute_mmcr(u64 event[], int n_ev,
-			       unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+			       unsigned int hwc[], struct mmcr_regs *mmcr,
+			       struct perf_event *pevents[])
 {
 	unsigned long mmcr1 = 0;
 	unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
@@ -298,20 +299,20 @@ static int power7_compute_mmcr(u64 event[], int n_ev,
 	}
 
 	/* Return MMCRx values */
-	mmcr[0] = 0;
+	mmcr->mmcr0 = 0;
 	if (pmc_inuse & 1)
-		mmcr[0] = MMCR0_PMC1CE;
+		mmcr->mmcr0 = MMCR0_PMC1CE;
 	if (pmc_inuse & 0x3e)
-		mmcr[0] |= MMCR0_PMCjCE;
-	mmcr[1] = mmcr1;
-	mmcr[2] = mmcra;
+		mmcr->mmcr0 |= MMCR0_PMCjCE;
+	mmcr->mmcr1 = mmcr1;
+	mmcr->mmcra = mmcra;
 	return 0;
 }
 
-static void power7_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void power7_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
 	if (pmc <= 3)
-		mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
+		mmcr->mmcr1 &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power7_generic_events[] = {
arch/powerpc/perf/ppc970-pmu.c +12 -12
index 4035d93..89a90ab 100644
@@ -253,7 +253,8 @@ static int p970_get_alternatives(u64 event, unsigned int flags, u64 alt[])
 }
 
 static int p970_compute_mmcr(u64 event[], int n_ev,
-			     unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+			     unsigned int hwc[], struct mmcr_regs *mmcr,
+			     struct perf_event *pevents[])
 {
 	unsigned long mmcr0 = 0, mmcr1 = 0, mmcra = 0;
 	unsigned int pmc, unit, byte, psel;
@@ -393,27 +394,26 @@ static int p970_compute_mmcr(u64 event[], int n_ev,
 	mmcra |= 0x2000;	/* mark only one IOP per PPC instruction */
 
 	/* Return MMCRx values */
-	mmcr[0] = mmcr0;
-	mmcr[1] = mmcr1;
-	mmcr[2] = mmcra;
+	mmcr->mmcr0 = mmcr0;
+	mmcr->mmcr1 = mmcr1;
+	mmcr->mmcra = mmcra;
 	return 0;
 }
 
-static void p970_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void p970_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
-	int shift, i;
+	int shift;
 
+	/*
+	 * Setting the PMCxSEL field to 0x08 disables PMC x.
+	 */
 	if (pmc <= 1) {
 		shift = MMCR0_PMC1SEL_SH - 7 * pmc;
-		i = 0;
+		mmcr->mmcr0 = (mmcr->mmcr0 & ~(0x1fUL << shift)) | (0x08UL << shift);
 	} else {
 		shift = MMCR1_PMC3SEL_SH - 5 * (pmc - 2);
-		i = 1;
+		mmcr->mmcr1 = (mmcr->mmcr1 & ~(0x1fUL << shift)) | (0x08UL << shift);
 	}
-	/*
-	 * Setting the PMCxSEL field to 0x08 disables PMC x.
-	 */
-	mmcr[i] = (mmcr[i] & ~(0x1fUL << shift)) | (0x08UL << shift);
 }
 
 static int ppc970_generic_events[] = {
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [v3 01/15] powerpc/perf: Update cpu_hw_event to use `struct` for storing MMCR registers

Quoted 311 lines · Athira Rajeev

core-book3s currently uses array to store the MMCR registers as part of per-cpu cpu_hw_events. This patch does a clean up to use struct to store mmcr regs instead of array. This will make code easier to read and reduces chance of any subtle bug that may come in the future, say when new registers are added. Patch updates all relevant code that was using MMCR array ( cpuhw->mmcr[x]) to use newly introduced struct. This includes the PMU driver code for supported platforms (power5 to power9) and ISA macros for counter support functions.

---
 arch/powerpc/include/asm/perf_event_server.h | 10 ++++--
 arch/powerpc/perf/core-book3s.c              | 53 +++++++++++++---------------
 arch/powerpc/perf/isa207-common.c            | 20 +++++------
 arch/powerpc/perf/isa207-common.h            |  4 +--
 arch/powerpc/perf/mpc7450-pmu.c              | 21 +++++++----
 arch/powerpc/perf/power5+-pmu.c              | 17 ++++-----
 arch/powerpc/perf/power5-pmu.c               | 17 ++++-----
 arch/powerpc/perf/power6-pmu.c               | 16 ++++-----
 arch/powerpc/perf/power7-pmu.c               | 17 ++++-----
 arch/powerpc/perf/ppc970-pmu.c               | 24 ++++++-------
 10 files changed, 105 insertions(+), 94 deletions(-)
arch/powerpc/include/asm/perf_event_server.h +8 -2
index 3e9703f..f9a3668 100644
@@ -17,6 +17,12 @@
 
 struct perf_event;
 
+struct mmcr_regs {
+       unsigned long mmcr0;
+       unsigned long mmcr1;
+       unsigned long mmcr2;
+       unsigned long mmcra;
+};
 /*
  * This struct provides the constants and functions needed to
  * describe the PMU on a particular POWER-family CPU.
@@ -28,7 +34,7 @@ struct power_pmu {
        unsigned long   add_fields;
        unsigned long   test_adder;
        int             (*compute_mmcr)(u64 events[], int n_ev,
-                               unsigned int hwc[], unsigned long mmcr[],
+                               unsigned int hwc[], struct mmcr_regs *mmcr,
                                struct perf_event *pevents[]);
        int             (*get_constraint)(u64 event_id, unsigned long *mskp,
                                unsigned long *valp);
@@ -41,7 +47,7 @@ struct power_pmu {
        unsigned long   group_constraint_val;
        u64             (*bhrb_filter_map)(u64 branch_sample_type);
        void            (*config_bhrb)(u64 pmu_bhrb_filter);
-       void            (*disable_pmc)(unsigned int pmc, unsigned long mmcr[]);
+       void            (*disable_pmc)(unsigned int pmc, struct mmcr_regs *mmcr);
        int             (*limited_pmc_event)(u64 event_id);
        u32             flags;
        const struct attribute_group    **attr_groups;
arch/powerpc/perf/core-book3s.c +24 -29
index cd6a742..18b1b6a 100644
@@ -37,12 +37,7 @@ struct cpu_hw_events {
        struct perf_event *event[MAX_HWEVENTS];
        u64 events[MAX_HWEVENTS];
        unsigned int flags[MAX_HWEVENTS];
-       /*
-        * The order of the MMCR array is:
-        *  - 64-bit, MMCR0, MMCR1, MMCRA, MMCR2
-        *  - 32-bit, MMCR0, MMCR1, MMCR2
-        */
-       unsigned long mmcr[4];
+       struct mmcr_regs mmcr;
        struct perf_event *limited_counter[MAX_LIMITED_HWCOUNTERS];
        u8  limited_hwidx[MAX_LIMITED_HWCOUNTERS];
        u64 alternatives[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES];
@@ -121,7 +116,7 @@ static void ebb_event_add(struct perf_event *event) { }
 static void ebb_switch_out(unsigned long mmcr0) { }
 static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
 {
-       return cpuhw->mmcr[0];
+       return cpuhw->mmcr.mmcr0;
 }
 
 static inline void power_pmu_bhrb_enable(struct perf_event *event) {}
@@ -590,7 +585,7 @@ static void ebb_switch_out(unsigned long mmcr0)
 
 static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
 {
-       unsigned long mmcr0 = cpuhw->mmcr[0];
+       unsigned long mmcr0 = cpuhw->mmcr.mmcr0;
 
        if (!ebb)
                goto out;
@@ -624,7 +619,7 @@ static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
         * unfreeze counters, it should not set exclude_xxx in its events and
         * instead manage the MMCR2 entirely by itself.
         */
-       mtspr(SPRN_MMCR2, cpuhw->mmcr[3] | current->thread.mmcr2);
+       mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2 | current->thread.mmcr2);
 out:
        return mmcr0;
 }
@@ -1232,9 +1227,9 @@ static void power_pmu_disable(struct pmu *pmu)
                /*
                 * Disable instruction sampling if it was enabled
                 */
-               if (cpuhw->mmcr[2] & MMCRA_SAMPLE_ENABLE) {
+               if (cpuhw->mmcr.mmcra & MMCRA_SAMPLE_ENABLE) {
                        mtspr(SPRN_MMCRA,
-                             cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE);
+                             cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
                        mb();
                        isync();
                }
@@ -1308,18 +1303,18 @@ static void power_pmu_enable(struct pmu *pmu)
         * (possibly updated for removal of events).
         */
        if (!cpuhw->n_added) {
-               mtspr(SPRN_MMCRA, cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE);
-               mtspr(SPRN_MMCR1, cpuhw->mmcr[1]);
+               mtspr(SPRN_MMCRA, cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
+               mtspr(SPRN_MMCR1, cpuhw->mmcr.mmcr1);
                goto out_enable;
        }
 
        /*
         * Clear all MMCR settings and recompute them for the new set of events.
         */
-       memset(cpuhw->mmcr, 0, sizeof(cpuhw->mmcr));
+       memset(&cpuhw->mmcr, 0, sizeof(cpuhw->mmcr));
 
        if (ppmu->compute_mmcr(cpuhw->events, cpuhw->n_events, hwc_index,
-                              cpuhw->mmcr, cpuhw->event)) {
+                              &cpuhw->mmcr, cpuhw->event)) {
                /* shouldn't ever get here */
                printk(KERN_ERR "oops compute_mmcr failed\n");
                goto out;
@@ -1333,11 +1328,11 @@ static void power_pmu_enable(struct pmu *pmu)
                 */
                event = cpuhw->event[0];
                if (event->attr.exclude_user)
-                       cpuhw->mmcr[0] |= MMCR0_FCP;
+                       cpuhw->mmcr.mmcr0 |= MMCR0_FCP;
                if (event->attr.exclude_kernel)
-                       cpuhw->mmcr[0] |= freeze_events_kernel;
+                       cpuhw->mmcr.mmcr0 |= freeze_events_kernel;
                if (event->attr.exclude_hv)
-                       cpuhw->mmcr[0] |= MMCR0_FCHV;
+                       cpuhw->mmcr.mmcr0 |= MMCR0_FCHV;
        }
 
        /*
@@ -1346,12 +1341,12 @@ static void power_pmu_enable(struct pmu *pmu)
         * Then unfreeze the events.
         */
        ppc_set_pmu_inuse(1);
-       mtspr(SPRN_MMCRA, cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE);
-       mtspr(SPRN_MMCR1, cpuhw->mmcr[1]);
-       mtspr(SPRN_MMCR0, (cpuhw->mmcr[0] & ~(MMCR0_PMC1CE | MMCR0_PMCjCE))
+       mtspr(SPRN_MMCRA, cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
+       mtspr(SPRN_MMCR1, cpuhw->mmcr.mmcr1);
+       mtspr(SPRN_MMCR0, (cpuhw->mmcr.mmcr0 & ~(MMCR0_PMC1CE | MMCR0_PMCjCE))
                                | MMCR0_FC);
        if (ppmu->flags & PPMU_ARCH_207S)
-               mtspr(SPRN_MMCR2, cpuhw->mmcr[3]);
+               mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2);
 
        /*
         * Read off any pre-existing events that need to move
@@ -1402,7 +1397,7 @@ static void power_pmu_enable(struct pmu *pmu)
                perf_event_update_userpage(event);
        }
        cpuhw->n_limited = n_lim;
-       cpuhw->mmcr[0] |= MMCR0_PMXE | MMCR0_FCECE;
+       cpuhw->mmcr.mmcr0 |= MMCR0_PMXE | MMCR0_FCECE;
 
  out_enable:
        pmao_restore_workaround(ebb);
@@ -1418,9 +1413,9 @@ static void power_pmu_enable(struct pmu *pmu)
        /*
         * Enable instruction sampling if necessary
         */
-       if (cpuhw->mmcr[2] & MMCRA_SAMPLE_ENABLE) {
+       if (cpuhw->mmcr.mmcra & MMCRA_SAMPLE_ENABLE) {
                mb();
-               mtspr(SPRN_MMCRA, cpuhw->mmcr[2]);
+               mtspr(SPRN_MMCRA, cpuhw->mmcr.mmcra);
        }
 
  out:
@@ -1550,7 +1545,7 @@ static void power_pmu_del(struct perf_event *event, int ef_flags)
                                cpuhw->flags[i-1] = cpuhw->flags[i];
                        }
                        --cpuhw->n_events;
-                       ppmu->disable_pmc(event->hw.idx - 1, cpuhw->mmcr);
+                       ppmu->disable_pmc(event->hw.idx - 1, &cpuhw->mmcr);
                        if (event->hw.idx) {
                                write_pmc(event->hw.idx, 0);
                                event->hw.idx = 0;
@@ -1571,7 +1566,7 @@ static void power_pmu_del(struct perf_event *event, int ef_flags)
        }
        if (cpuhw->n_events = 0) {
                /* disable exceptions if no events are running */
-               cpuhw->mmcr[0] &= ~(MMCR0_PMXE | MMCR0_FCECE);
+               cpuhw->mmcr.mmcr0 &= ~(MMCR0_PMXE | MMCR0_FCECE);
        }
 
        if (has_branch_stack(event))
@@ -2240,7 +2235,7 @@ static void __perf_event_interrupt(struct pt_regs *regs)
         * XXX might want to use MSR.PM to keep the events frozen until
         * we get back out of this interrupt.
         */
-       write_mmcr0(cpuhw, cpuhw->mmcr[0]);
+       write_mmcr0(cpuhw, cpuhw->mmcr.mmcr0);
 
        if (nmi)
                nmi_exit();
@@ -2262,7 +2257,7 @@ static int power_pmu_prepare_cpu(unsigned int cpu)
 
        if (ppmu) {
                memset(cpuhw, 0, sizeof(*cpuhw));
-               cpuhw->mmcr[0] = MMCR0_FC;
+               cpuhw->mmcr.mmcr0 = MMCR0_FC;
        }
        return 0;
 }
arch/powerpc/perf/isa207-common.c +10 -10
index 4c86da5..2fe63f2 100644
@@ -363,7 +363,7 @@ int isa207_get_constraint(u64 event, unsigned long *maskp, unsigned long *valp)
 }
 
 int isa207_compute_mmcr(u64 event[], int n_ev,
-                              unsigned int hwc[], unsigned long mmcr[],
+                              unsigned int hwc[], struct mmcr_regs *mmcr,
                               struct perf_event *pevents[])
 {
        unsigned long mmcra, mmcr1, mmcr2, unit, combine, psel, cache, val;
@@ -464,30 +464,30 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
        }
 
        /* Return MMCRx values */
-       mmcr[0] = 0;
+       mmcr->mmcr0 = 0;
 
        /* pmc_inuse is 1-based */
        if (pmc_inuse & 2)
-               mmcr[0] = MMCR0_PMC1CE;
+               mmcr->mmcr0 = MMCR0_PMC1CE;
 
        if (pmc_inuse & 0x7c)
-               mmcr[0] |= MMCR0_PMCjCE;
+               mmcr->mmcr0 |= MMCR0_PMCjCE;
 
        /* If we're not using PMC 5 or 6, freeze them */
        if (!(pmc_inuse & 0x60))
-               mmcr[0] |= MMCR0_FC56;
+               mmcr->mmcr0 |= MMCR0_FC56;
 
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
-       mmcr[3] = mmcr2;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
+       mmcr->mmcr2 = mmcr2;
 
        return 0;
 }
 
-void isa207_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+void isa207_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
        if (pmc <= 3)
-               mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SHIFT(pmc + 1));
+               mmcr->mmcr1 &= ~(0xffUL << MMCR1_PMCSEL_SHIFT(pmc + 1));
 }
 
 static int find_alternative(u64 event, const unsigned int ev_alt[][MAX_ALT], int size)
arch/powerpc/perf/isa207-common.h +2 -2
index 63fd4f3..df968fd 100644
@@ -217,9 +217,9 @@
 
 int isa207_get_constraint(u64 event, unsigned long *maskp, unsigned long *valp);
 int isa207_compute_mmcr(u64 event[], int n_ev,
-                               unsigned int hwc[], unsigned long mmcr[],
+                               unsigned int hwc[], struct mmcr_regs *mmcr,
                                struct perf_event *pevents[]);
-void isa207_disable_pmc(unsigned int pmc, unsigned long mmcr[]);
+void isa207_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr);
 int isa207_get_alternatives(u64 event, u64 alt[], int size, unsigned int flags,
                                        const unsigned int ev_alt[][MAX_ALT]);
 void isa207_get_mem_data_src(union perf_mem_data_src *dsrc, u32 flags,
arch/powerpc/perf/mpc7450-pmu.c +1 -1
index 4d5ef92..826de25 100644
@@ -257,7 +257,7 @@ static int mpc7450_get_alternatives(u64 event, unsigned int flags, u64 alt[])
  * Compute MMCR0/1/2 values for a set of events.
  */
 static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[],
-                               unsigned long mmcr[],
+                               struct mmcr_regs *mmcr,
                                struct perf_event *pevents[])
 {
        u8 event_index[N_CLASSES][N_COUNTER];

arch/powerpc/perf/mpc7450-pmu.c static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[], · line 326

Quoted 9 lines
arch/powerpc/perf/mpc7450-pmu.c +3 -3
@@ -321,9 +321,16 @@ static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[],
                mmcr0 |= MMCR0_PMCnCE;
 
        /* Return MMCRx values */
-       mmcr[0] = mmcr0;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcr2;
+       mmcr->mmcr0 = mmcr0;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcr2 = mmcr2;

Will this mmcr->mmcr2 be used anywere, or will it always use mmcr->mmcra?

arch/powerpc/perf/mpc7450-pmu.c static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[], · line 332

Quoted 6 lines
arch/powerpc/perf/mpc7450-pmu.c +6 -0
+       /*
+        * 32-bit doesn't have an MMCRA and uses SPRN_MMCR2 to define
+        * SPRN_MMCRA. So assign mmcra of cpu_hw_events with `mmcr2`
+        * value to ensure that any write to this SPRN_MMCRA will
+        * use mmcr2 value.
+        */

Something like this comment would probably be useful to near the struct mmcr.

Quoted 247 lines
arch/powerpc/perf/mpc7450-pmu.c +4 -3
+       mmcr->mmcra = mmcr2;
        return 0;
 }
 
@@ -331,12 +338,12 @@ static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[],
  * Disable counting by a PMC.
  * Note that the pmc argument is 0-based here, not 1-based.
  */
-static void mpc7450_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void mpc7450_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
        if (pmc <= 1)
-               mmcr[0] &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
+               mmcr->mmcr0 &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
        else
-               mmcr[1] &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
+               mmcr->mmcr1 &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
 }
 
 static int mpc7450_generic_events[] = {
arch/powerpc/perf/power5+-pmu.c +9 -8
index f857454..5f0821e 100644
@@ -448,7 +448,8 @@ static int power5p_marked_instr_event(u64 event)
 }
 
 static int power5p_compute_mmcr(u64 event[], int n_ev,
-                               unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+                               unsigned int hwc[], struct mmcr_regs *mmcr,
+                               struct perf_event *pevents[])
 {
        unsigned long mmcr1 = 0;
        unsigned long mmcra = 0;
@@ -586,20 +587,20 @@ static int power5p_compute_mmcr(u64 event[], int n_ev,
        }
 
        /* Return MMCRx values */
-       mmcr[0] = 0;
+       mmcr->mmcr0 = 0;
        if (pmc_inuse & 1)
-               mmcr[0] = MMCR0_PMC1CE;
+               mmcr->mmcr0 = MMCR0_PMC1CE;
        if (pmc_inuse & 0x3e)
-               mmcr[0] |= MMCR0_PMCjCE;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
+               mmcr->mmcr0 |= MMCR0_PMCjCE;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
        return 0;
 }
 
-static void power5p_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void power5p_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
        if (pmc <= 3)
-               mmcr[1] &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
+               mmcr->mmcr1 &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power5p_generic_events[] = {
arch/powerpc/perf/power5-pmu.c +9 -8
index da52eca..426021d 100644
@@ -379,7 +379,8 @@ static int power5_marked_instr_event(u64 event)
 }
 
 static int power5_compute_mmcr(u64 event[], int n_ev,
-                              unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+                              unsigned int hwc[], struct mmcr_regs *mmcr,
+                              struct perf_event *pevents[])
 {
        unsigned long mmcr1 = 0;
        unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
@@ -528,20 +529,20 @@ static int power5_compute_mmcr(u64 event[], int n_ev,
        }
 
        /* Return MMCRx values */
-       mmcr[0] = 0;
+       mmcr->mmcr0 = 0;
        if (pmc_inuse & 1)
-               mmcr[0] = MMCR0_PMC1CE;
+               mmcr->mmcr0 = MMCR0_PMC1CE;
        if (pmc_inuse & 0x3e)
-               mmcr[0] |= MMCR0_PMCjCE;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
+               mmcr->mmcr0 |= MMCR0_PMCjCE;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
        return 0;
 }
 
-static void power5_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void power5_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
        if (pmc <= 3)
-               mmcr[1] &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
+               mmcr->mmcr1 &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power5_generic_events[] = {
arch/powerpc/perf/power6-pmu.c +8 -8
index 3929cac..e343a51 100644
@@ -171,7 +171,7 @@ static int power6_marked_instr_event(u64 event)
  * Assign PMC numbers and compute MMCR1 value for a set of events
  */
 static int p6_compute_mmcr(u64 event[], int n_ev,
-                          unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+                          unsigned int hwc[], struct mmcr_regs *mmcr, struct perf_event *pevents[])
 {
        unsigned long mmcr1 = 0;
        unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
@@ -243,13 +243,13 @@ static int p6_compute_mmcr(u64 event[], int n_ev,
                if (pmc < 4)
                        mmcr1 |= (unsigned long)psel << MMCR1_PMCSEL_SH(pmc);
        }
-       mmcr[0] = 0;
+       mmcr->mmcr0 = 0;
        if (pmc_inuse & 1)
-               mmcr[0] = MMCR0_PMC1CE;
+               mmcr->mmcr0 = MMCR0_PMC1CE;
        if (pmc_inuse & 0xe)
-               mmcr[0] |= MMCR0_PMCjCE;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
+               mmcr->mmcr0 |= MMCR0_PMCjCE;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
        return 0;
 }
 
@@ -457,11 +457,11 @@ static int p6_get_alternatives(u64 event, unsigned int flags, u64 alt[])
        return nalt;
 }
 
-static void p6_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void p6_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
        /* Set PMCxSEL to 0 to disable PMCx */
        if (pmc <= 3)
-               mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
+               mmcr->mmcr1 &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power6_generic_events[] = {
arch/powerpc/perf/power7-pmu.c +9 -8
index a137813..3152336 100644
@@ -242,7 +242,8 @@ static int power7_marked_instr_event(u64 event)
 }
 
 static int power7_compute_mmcr(u64 event[], int n_ev,
-                              unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+                              unsigned int hwc[], struct mmcr_regs *mmcr,
+                              struct perf_event *pevents[])
 {
        unsigned long mmcr1 = 0;
        unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
@@ -298,20 +299,20 @@ static int power7_compute_mmcr(u64 event[], int n_ev,
        }
 
        /* Return MMCRx values */
-       mmcr[0] = 0;
+       mmcr->mmcr0 = 0;
        if (pmc_inuse & 1)
-               mmcr[0] = MMCR0_PMC1CE;
+               mmcr->mmcr0 = MMCR0_PMC1CE;
        if (pmc_inuse & 0x3e)
-               mmcr[0] |= MMCR0_PMCjCE;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
+               mmcr->mmcr0 |= MMCR0_PMCjCE;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
        return 0;
 }
 
-static void power7_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void power7_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
        if (pmc <= 3)
-               mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
+               mmcr->mmcr1 &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power7_generic_events[] = {
arch/powerpc/perf/ppc970-pmu.c +12 -13
index 4035d93..89a90ab 100644
@@ -253,7 +253,8 @@ static int p970_get_alternatives(u64 event, unsigned int flags, u64 alt[])
 }
 
 static int p970_compute_mmcr(u64 event[], int n_ev,
-                            unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+                            unsigned int hwc[], struct mmcr_regs *mmcr,
+                            struct perf_event *pevents[])
 {
        unsigned long mmcr0 = 0, mmcr1 = 0, mmcra = 0;
        unsigned int pmc, unit, byte, psel;
@@ -393,27 +394,26 @@ static int p970_compute_mmcr(u64 event[], int n_ev,
        mmcra |= 0x2000;        /* mark only one IOP per PPC instruction */
 
        /* Return MMCRx values */
-       mmcr[0] = mmcr0;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
+       mmcr->mmcr0 = mmcr0;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
        return 0;
 }
 
-static void p970_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void p970_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
-       int shift, i;
+       int shift;
 
+       /*
+        * Setting the PMCxSEL field to 0x08 disables PMC x.
+        */
        if (pmc <= 1) {
                shift = MMCR0_PMC1SEL_SH - 7 * pmc;
-               i = 0;
+               mmcr->mmcr0 = (mmcr->mmcr0 & ~(0x1fUL << shift)) | (0x08UL << shift);
        } else {
                shift = MMCR1_PMC3SEL_SH - 5 * (pmc - 2);
-               i = 1;
+               mmcr->mmcr1 = (mmcr->mmcr1 & ~(0x1fUL << shift)) | (0x08UL << shift);
        }
-       /*
-        * Setting the PMCxSEL field to 0x08 disables PMC x.
-        */
-       mmcr[i] = (mmcr[i] & ~(0x1fUL << shift)) | (0x08UL << shift);
 }
 
 static int ppc970_generic_events[] = {
--

1.8.3.1

#3 lore raw

Re: [v3 01/15] powerpc/perf: Update cpu_hw_event to use `struct` for storing MMCR registers

Quoted 319 lines · Jordan Niethe
Quoted 313 lines · On Sat, Jul 18, 2020 at 12:48 AM Athira Rajeev <[email protected]…

core-book3s currently uses array to store the MMCR registers as part of per-cpu cpu_hw_events. This patch does a clean up to use struct to store mmcr regs instead of array. This will make code easier to read and reduces chance of any subtle bug that may come in the future, say when new registers are added. Patch updates all relevant code that was using MMCR array ( cpuhw->mmcr[x]) to use newly introduced struct. This includes the PMU driver code for supported platforms (power5 to power9) and ISA macros for counter support functions.

---

arch/powerpc/include/asm/perf_event_server.h | 10 ++++--
arch/powerpc/perf/core-book3s.c              | 53 +++++++++++++---------------
arch/powerpc/perf/isa207-common.c            | 20 +++++------
arch/powerpc/perf/isa207-common.h            |  4 +--
arch/powerpc/perf/mpc7450-pmu.c              | 21 +++++++----
arch/powerpc/perf/power5+-pmu.c              | 17 ++++-----
arch/powerpc/perf/power5-pmu.c               | 17 ++++-----
arch/powerpc/perf/power6-pmu.c               | 16 ++++-----
arch/powerpc/perf/power7-pmu.c               | 17 ++++-----
arch/powerpc/perf/ppc970-pmu.c               | 24 ++++++-------
10 files changed, 105 insertions(+), 94 deletions(-)
arch/powerpc/include/asm/perf_event_server.h +8 -2
index 3e9703f..f9a3668 100644
@@ -17,6 +17,12 @@
 
 struct perf_event;
 
+struct mmcr_regs {
+       unsigned long mmcr0;
+       unsigned long mmcr1;
+       unsigned long mmcr2;
+       unsigned long mmcra;
+};
 /*
 * This struct provides the constants and functions needed to
 * describe the PMU on a particular POWER-family CPU.
@@ -28,7 +34,7 @@ struct power_pmu {
       unsigned long   add_fields;
       unsigned long   test_adder;
       int             (*compute_mmcr)(u64 events[], int n_ev,
-                               unsigned int hwc[], unsigned long mmcr[],
+                               unsigned int hwc[], struct mmcr_regs *mmcr,
                               struct perf_event *pevents[]);
       int             (*get_constraint)(u64 event_id, unsigned long *mskp,
                               unsigned long *valp);
@@ -41,7 +47,7 @@ struct power_pmu {
       unsigned long   group_constraint_val;
       u64             (*bhrb_filter_map)(u64 branch_sample_type);
       void            (*config_bhrb)(u64 pmu_bhrb_filter);
-       void            (*disable_pmc)(unsigned int pmc, unsigned long mmcr[]);
+       void            (*disable_pmc)(unsigned int pmc, struct mmcr_regs *mmcr);
       int             (*limited_pmc_event)(u64 event_id);
       u32             flags;
       const struct attribute_group    **attr_groups;
arch/powerpc/perf/core-book3s.c +4 -9
index cd6a742..18b1b6a 100644
@@ -37,12 +37,7 @@ struct cpu_hw_events {
       struct perf_event *event[MAX_HWEVENTS];
       u64 events[MAX_HWEVENTS];
       unsigned int flags[MAX_HWEVENTS];
-       /*
-        * The order of the MMCR array is:
-        *  - 64-bit, MMCR0, MMCR1, MMCRA, MMCR2
-        *  - 32-bit, MMCR0, MMCR1, MMCR2
-        */
-       unsigned long mmcr[4];
+       struct mmcr_regs mmcr;
       struct perf_event *limited_counter[MAX_LIMITED_HWCOUNTERS];
       u8  limited_hwidx[MAX_LIMITED_HWCOUNTERS];
       u64 alternatives[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES];
@@ -121,7 +116,7 @@ static void ebb_event_add(struct perf_event *event) { }
 static void ebb_switch_out(unsigned long mmcr0) { }
 static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
 {
-       return cpuhw->mmcr[0];
+       return cpuhw->mmcr.mmcr0;
 }
 
 static inline void power_pmu_bhrb_enable(struct perf_event *event) {}
@@ -590,7 +585,7 @@ static void ebb_switch_out(unsigned long mmcr0)
 
 static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
 {
-       unsigned long mmcr0 = cpuhw->mmcr[0];
+       unsigned long mmcr0 = cpuhw->mmcr.mmcr0;
 
       if (!ebb)
               goto out;
@@ -624,7 +619,7 @@ static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
        * unfreeze counters, it should not set exclude_xxx in its events and
        * instead manage the MMCR2 entirely by itself.
        */
-       mtspr(SPRN_MMCR2, cpuhw->mmcr[3] | current->thread.mmcr2);
+       mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2 | current->thread.mmcr2);

out:

       return mmcr0;
}
arch/powerpc/perf/core-book3s.c +20 -20
@@ -1232,9 +1227,9 @@ static void power_pmu_disable(struct pmu *pmu)
               /*
                * Disable instruction sampling if it was enabled
                */
-               if (cpuhw->mmcr[2] & MMCRA_SAMPLE_ENABLE) {
+               if (cpuhw->mmcr.mmcra & MMCRA_SAMPLE_ENABLE) {
                       mtspr(SPRN_MMCRA,
-                             cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE);
+                             cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
                       mb();
                       isync();
               }
@@ -1308,18 +1303,18 @@ static void power_pmu_enable(struct pmu *pmu)
        * (possibly updated for removal of events).
        */
       if (!cpuhw->n_added) {
-               mtspr(SPRN_MMCRA, cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE);
-               mtspr(SPRN_MMCR1, cpuhw->mmcr[1]);
+               mtspr(SPRN_MMCRA, cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
+               mtspr(SPRN_MMCR1, cpuhw->mmcr.mmcr1);
               goto out_enable;
       }
 
       /*
        * Clear all MMCR settings and recompute them for the new set of events.
        */
-       memset(cpuhw->mmcr, 0, sizeof(cpuhw->mmcr));
+       memset(&cpuhw->mmcr, 0, sizeof(cpuhw->mmcr));
 
       if (ppmu->compute_mmcr(cpuhw->events, cpuhw->n_events, hwc_index,
-                              cpuhw->mmcr, cpuhw->event)) {
+                              &cpuhw->mmcr, cpuhw->event)) {
               /* shouldn't ever get here */
               printk(KERN_ERR "oops compute_mmcr failed\n");
               goto out;
@@ -1333,11 +1328,11 @@ static void power_pmu_enable(struct pmu *pmu)
                */
               event = cpuhw->event[0];
               if (event->attr.exclude_user)
-                       cpuhw->mmcr[0] |= MMCR0_FCP;
+                       cpuhw->mmcr.mmcr0 |= MMCR0_FCP;
               if (event->attr.exclude_kernel)
-                       cpuhw->mmcr[0] |= freeze_events_kernel;
+                       cpuhw->mmcr.mmcr0 |= freeze_events_kernel;
               if (event->attr.exclude_hv)
-                       cpuhw->mmcr[0] |= MMCR0_FCHV;
+                       cpuhw->mmcr.mmcr0 |= MMCR0_FCHV;
       }
 
       /*
@@ -1346,12 +1341,12 @@ static void power_pmu_enable(struct pmu *pmu)
        * Then unfreeze the events.
        */
       ppc_set_pmu_inuse(1);
-       mtspr(SPRN_MMCRA, cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE);
-       mtspr(SPRN_MMCR1, cpuhw->mmcr[1]);
-       mtspr(SPRN_MMCR0, (cpuhw->mmcr[0] & ~(MMCR0_PMC1CE | MMCR0_PMCjCE))
+       mtspr(SPRN_MMCRA, cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
+       mtspr(SPRN_MMCR1, cpuhw->mmcr.mmcr1);
+       mtspr(SPRN_MMCR0, (cpuhw->mmcr.mmcr0 & ~(MMCR0_PMC1CE | MMCR0_PMCjCE))
                               | MMCR0_FC);
       if (ppmu->flags & PPMU_ARCH_207S)
-               mtspr(SPRN_MMCR2, cpuhw->mmcr[3]);
+               mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2);
 
       /*
        * Read off any pre-existing events that need to move
@@ -1402,7 +1397,7 @@ static void power_pmu_enable(struct pmu *pmu)
               perf_event_update_userpage(event);
       }
       cpuhw->n_limited = n_lim;
-       cpuhw->mmcr[0] |= MMCR0_PMXE | MMCR0_FCECE;
+       cpuhw->mmcr.mmcr0 |= MMCR0_PMXE | MMCR0_FCECE;
 
 out_enable:
       pmao_restore_workaround(ebb);
@@ -1418,9 +1413,9 @@ static void power_pmu_enable(struct pmu *pmu)
       /*
        * Enable instruction sampling if necessary
        */
-       if (cpuhw->mmcr[2] & MMCRA_SAMPLE_ENABLE) {
+       if (cpuhw->mmcr.mmcra & MMCRA_SAMPLE_ENABLE) {
               mb();
-               mtspr(SPRN_MMCRA, cpuhw->mmcr[2]);
+               mtspr(SPRN_MMCRA, cpuhw->mmcr.mmcra);
       }
 
 out:
@@ -1550,7 +1545,7 @@ static void power_pmu_del(struct perf_event *event, int ef_flags)
                               cpuhw->flags[i-1] = cpuhw->flags[i];
                       }
                       --cpuhw->n_events;
-                       ppmu->disable_pmc(event->hw.idx - 1, cpuhw->mmcr);
+                       ppmu->disable_pmc(event->hw.idx - 1, &cpuhw->mmcr);
                       if (event->hw.idx) {
                               write_pmc(event->hw.idx, 0);
                               event->hw.idx = 0;
@@ -1571,7 +1566,7 @@ static void power_pmu_del(struct perf_event *event, int ef_flags)
       }
       if (cpuhw->n_events == 0) {
               /* disable exceptions if no events are running */
-               cpuhw->mmcr[0] &= ~(MMCR0_PMXE | MMCR0_FCECE);
+               cpuhw->mmcr.mmcr0 &= ~(MMCR0_PMXE | MMCR0_FCECE);
       }
 
       if (has_branch_stack(event))
@@ -2240,7 +2235,7 @@ static void __perf_event_interrupt(struct pt_regs *regs)
        * XXX might want to use MSR.PM to keep the events frozen until
        * we get back out of this interrupt.
        */
-       write_mmcr0(cpuhw, cpuhw->mmcr[0]);
+       write_mmcr0(cpuhw, cpuhw->mmcr.mmcr0);
 
       if (nmi)
               nmi_exit();
@@ -2262,7 +2257,7 @@ static int power_pmu_prepare_cpu(unsigned int cpu)
 
       if (ppmu) {
               memset(cpuhw, 0, sizeof(*cpuhw));
-               cpuhw->mmcr[0] = MMCR0_FC;
+               cpuhw->mmcr.mmcr0 = MMCR0_FC;
       }
       return 0;
 }
arch/powerpc/perf/isa207-common.c +10 -10
index 4c86da5..2fe63f2 100644
@@ -363,7 +363,7 @@ int isa207_get_constraint(u64 event, unsigned long *maskp, unsigned long *valp)
 }
 
 int isa207_compute_mmcr(u64 event[], int n_ev,
-                              unsigned int hwc[], unsigned long mmcr[],
+                              unsigned int hwc[], struct mmcr_regs *mmcr,
                              struct perf_event *pevents[])
 {
       unsigned long mmcra, mmcr1, mmcr2, unit, combine, psel, cache, val;
@@ -464,30 +464,30 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
       }
 
       /* Return MMCRx values */
-       mmcr[0] = 0;
+       mmcr->mmcr0 = 0;
 
       /* pmc_inuse is 1-based */
       if (pmc_inuse & 2)
-               mmcr[0] = MMCR0_PMC1CE;
+               mmcr->mmcr0 = MMCR0_PMC1CE;
 
       if (pmc_inuse & 0x7c)
-               mmcr[0] |= MMCR0_PMCjCE;
+               mmcr->mmcr0 |= MMCR0_PMCjCE;
 
       /* If we're not using PMC 5 or 6, freeze them */
       if (!(pmc_inuse & 0x60))
-               mmcr[0] |= MMCR0_FC56;
+               mmcr->mmcr0 |= MMCR0_FC56;
 
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
-       mmcr[3] = mmcr2;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
+       mmcr->mmcr2 = mmcr2;
 
       return 0;
 }
 
-void isa207_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+void isa207_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
       if (pmc <= 3)
-               mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SHIFT(pmc + 1));
+               mmcr->mmcr1 &= ~(0xffUL << MMCR1_PMCSEL_SHIFT(pmc + 1));
 }
 
 static int find_alternative(u64 event, const unsigned int ev_alt[][MAX_ALT], int size)
arch/powerpc/perf/isa207-common.h +2 -2
index 63fd4f3..df968fd 100644
@@ -217,9 +217,9 @@
 
 int isa207_get_constraint(u64 event, unsigned long *maskp, unsigned long *valp);
 int isa207_compute_mmcr(u64 event[], int n_ev,
-                               unsigned int hwc[], unsigned long mmcr[],
+                               unsigned int hwc[], struct mmcr_regs *mmcr,
                               struct perf_event *pevents[]);
-void isa207_disable_pmc(unsigned int pmc, unsigned long mmcr[]);
+void isa207_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr);
 int isa207_get_alternatives(u64 event, u64 alt[], int size, unsigned int flags,
                                       const unsigned int ev_alt[][MAX_ALT]);
 void isa207_get_mem_data_src(union perf_mem_data_src *dsrc, u32 flags,
arch/powerpc/perf/mpc7450-pmu.c +1 -1
index 4d5ef92..826de25 100644
@@ -257,7 +257,7 @@ static int mpc7450_get_alternatives(u64 event, unsigned int flags, u64 alt[])
 * Compute MMCR0/1/2 values for a set of events.
 */
 static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[],
-                               unsigned long mmcr[],
+                               struct mmcr_regs *mmcr,
                               struct perf_event *pevents[])
 {
       u8 event_index[N_CLASSES][N_COUNTER];
@@ -321,9 +321,16 @@ static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[],
               mmcr0 |= MMCR0_PMCnCE;
 
Quoted 8 lines

arch/powerpc/perf/mpc7450-pmu.c static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[], · line 326

Quoted 7 lines
arch/powerpc/perf/mpc7450-pmu.c +3 -3
       /* Return MMCRx values */
-       mmcr[0] = mmcr0;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcr2;
+       mmcr->mmcr0 = mmcr0;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcr2 = mmcr2;

Will this mmcr->mmcr2 be used anywere, or will it always use mmcr->mmcra?

Hi Jordan

We will be actually using mmcr->mmcra in the core-book3s for mpc7450-pmu.c
I have still assigned mmcr->mmcr2 so that it will work for any future changes if made in corebook

Quoted 7 lines

arch/powerpc/perf/mpc7450-pmu.c static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[], · line 332

Quoted 6 lines
arch/powerpc/perf/mpc7450-pmu.c +6 -0
+       /*
+        * 32-bit doesn't have an MMCRA and uses SPRN_MMCR2 to define
+        * SPRN_MMCRA. So assign mmcra of cpu_hw_events with `mmcr2`
+        * value to ensure that any write to this SPRN_MMCRA will
+        * use mmcr2 value.
+        */

Something like this comment would probably be useful to near the struct mmcr.

Sure, I will add this information
Thanks for your suggestion

Athira

Quoted 246 lines
Quoted 246 lines
arch/powerpc/perf/mpc7450-pmu.c +4 -3
+       mmcr->mmcra = mmcr2;
       return 0;
 }
 
@@ -331,12 +338,12 @@ static int mpc7450_compute_mmcr(u64 event[], int n_ev, unsigned int hwc[],
 * Disable counting by a PMC.
 * Note that the pmc argument is 0-based here, not 1-based.
 */
-static void mpc7450_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void mpc7450_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
       if (pmc <= 1)
-               mmcr[0] &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
+               mmcr->mmcr0 &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
       else
-               mmcr[1] &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
+               mmcr->mmcr1 &= ~(pmcsel_mask[pmc] << pmcsel_shift[pmc]);
 }
 
 static int mpc7450_generic_events[] = {
arch/powerpc/perf/power5+-pmu.c +9 -8
index f857454..5f0821e 100644
@@ -448,7 +448,8 @@ static int power5p_marked_instr_event(u64 event)
 }
 
 static int power5p_compute_mmcr(u64 event[], int n_ev,
-                               unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+                               unsigned int hwc[], struct mmcr_regs *mmcr,
+                               struct perf_event *pevents[])
 {
       unsigned long mmcr1 = 0;
       unsigned long mmcra = 0;
@@ -586,20 +587,20 @@ static int power5p_compute_mmcr(u64 event[], int n_ev,
       }
 
       /* Return MMCRx values */
-       mmcr[0] = 0;
+       mmcr->mmcr0 = 0;
       if (pmc_inuse & 1)
-               mmcr[0] = MMCR0_PMC1CE;
+               mmcr->mmcr0 = MMCR0_PMC1CE;
       if (pmc_inuse & 0x3e)
-               mmcr[0] |= MMCR0_PMCjCE;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
+               mmcr->mmcr0 |= MMCR0_PMCjCE;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
       return 0;
 }
 
-static void power5p_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void power5p_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
       if (pmc <= 3)
-               mmcr[1] &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
+               mmcr->mmcr1 &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power5p_generic_events[] = {
arch/powerpc/perf/power5-pmu.c +9 -8
index da52eca..426021d 100644
@@ -379,7 +379,8 @@ static int power5_marked_instr_event(u64 event)
 }
 
 static int power5_compute_mmcr(u64 event[], int n_ev,
-                              unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+                              unsigned int hwc[], struct mmcr_regs *mmcr,
+                              struct perf_event *pevents[])
 {
       unsigned long mmcr1 = 0;
       unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
@@ -528,20 +529,20 @@ static int power5_compute_mmcr(u64 event[], int n_ev,
       }
 
       /* Return MMCRx values */
-       mmcr[0] = 0;
+       mmcr->mmcr0 = 0;
       if (pmc_inuse & 1)
-               mmcr[0] = MMCR0_PMC1CE;
+               mmcr->mmcr0 = MMCR0_PMC1CE;
       if (pmc_inuse & 0x3e)
-               mmcr[0] |= MMCR0_PMCjCE;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
+               mmcr->mmcr0 |= MMCR0_PMCjCE;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
       return 0;
 }
 
-static void power5_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void power5_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
       if (pmc <= 3)
-               mmcr[1] &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
+               mmcr->mmcr1 &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power5_generic_events[] = {
arch/powerpc/perf/power6-pmu.c +8 -8
index 3929cac..e343a51 100644
@@ -171,7 +171,7 @@ static int power6_marked_instr_event(u64 event)
 * Assign PMC numbers and compute MMCR1 value for a set of events
 */
 static int p6_compute_mmcr(u64 event[], int n_ev,
-                          unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+                          unsigned int hwc[], struct mmcr_regs *mmcr, struct perf_event *pevents[])
 {
       unsigned long mmcr1 = 0;
       unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
@@ -243,13 +243,13 @@ static int p6_compute_mmcr(u64 event[], int n_ev,
               if (pmc < 4)
                       mmcr1 |= (unsigned long)psel << MMCR1_PMCSEL_SH(pmc);
       }
-       mmcr[0] = 0;
+       mmcr->mmcr0 = 0;
       if (pmc_inuse & 1)
-               mmcr[0] = MMCR0_PMC1CE;
+               mmcr->mmcr0 = MMCR0_PMC1CE;
       if (pmc_inuse & 0xe)
-               mmcr[0] |= MMCR0_PMCjCE;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
+               mmcr->mmcr0 |= MMCR0_PMCjCE;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
       return 0;
 }
 
@@ -457,11 +457,11 @@ static int p6_get_alternatives(u64 event, unsigned int flags, u64 alt[])
       return nalt;
 }
 
-static void p6_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void p6_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
       /* Set PMCxSEL to 0 to disable PMCx */
       if (pmc <= 3)
-               mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
+               mmcr->mmcr1 &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power6_generic_events[] = {
arch/powerpc/perf/power7-pmu.c +9 -8
index a137813..3152336 100644
@@ -242,7 +242,8 @@ static int power7_marked_instr_event(u64 event)
 }
 
 static int power7_compute_mmcr(u64 event[], int n_ev,
-                              unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+                              unsigned int hwc[], struct mmcr_regs *mmcr,
+                              struct perf_event *pevents[])
 {
       unsigned long mmcr1 = 0;
       unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
@@ -298,20 +299,20 @@ static int power7_compute_mmcr(u64 event[], int n_ev,
       }
 
       /* Return MMCRx values */
-       mmcr[0] = 0;
+       mmcr->mmcr0 = 0;
       if (pmc_inuse & 1)
-               mmcr[0] = MMCR0_PMC1CE;
+               mmcr->mmcr0 = MMCR0_PMC1CE;
       if (pmc_inuse & 0x3e)
-               mmcr[0] |= MMCR0_PMCjCE;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
+               mmcr->mmcr0 |= MMCR0_PMCjCE;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
       return 0;
 }
 
-static void power7_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void power7_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
       if (pmc <= 3)
-               mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
+               mmcr->mmcr1 &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
 }
 
 static int power7_generic_events[] = {
arch/powerpc/perf/ppc970-pmu.c +12 -13
index 4035d93..89a90ab 100644
@@ -253,7 +253,8 @@ static int p970_get_alternatives(u64 event, unsigned int flags, u64 alt[])
 }
 
 static int p970_compute_mmcr(u64 event[], int n_ev,
-                            unsigned int hwc[], unsigned long mmcr[], struct perf_event *pevents[])
+                            unsigned int hwc[], struct mmcr_regs *mmcr,
+                            struct perf_event *pevents[])
 {
       unsigned long mmcr0 = 0, mmcr1 = 0, mmcra = 0;
       unsigned int pmc, unit, byte, psel;
@@ -393,27 +394,26 @@ static int p970_compute_mmcr(u64 event[], int n_ev,
       mmcra |= 0x2000;        /* mark only one IOP per PPC instruction */
 
       /* Return MMCRx values */
-       mmcr[0] = mmcr0;
-       mmcr[1] = mmcr1;
-       mmcr[2] = mmcra;
+       mmcr->mmcr0 = mmcr0;
+       mmcr->mmcr1 = mmcr1;
+       mmcr->mmcra = mmcra;
       return 0;
 }
 
-static void p970_disable_pmc(unsigned int pmc, unsigned long mmcr[])
+static void p970_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
 {
-       int shift, i;
+       int shift;
 
+       /*
+        * Setting the PMCxSEL field to 0x08 disables PMC x.
+        */
       if (pmc <= 1) {
               shift = MMCR0_PMC1SEL_SH - 7 * pmc;
-               i = 0;
+               mmcr->mmcr0 = (mmcr->mmcr0 & ~(0x1fUL << shift)) | (0x08UL << shift);
       } else {
               shift = MMCR1_PMC3SEL_SH - 5 * (pmc - 2);
-               i = 1;
+               mmcr->mmcr1 = (mmcr->mmcr1 & ~(0x1fUL << shift)) | (0x08UL << shift);
       }
-       /*
-        * Setting the PMCxSEL field to 0x08 disables PMC x.
-        */
-       mmcr[i] = (mmcr[i] & ~(0x1fUL << shift)) | (0x08UL << shift);
 }
 
 static int ppc970_generic_events[] = {
--

1.8.3.1

#4 lore raw

PATCH v3 2/15 KVM: PPC: Book3S HV: Cleanup updates for kvm vcpu MMCR

In reply to Athira Rajeev

Currently kvm_vcpu_arch stores all Monitor Mode Control registers in a flat array in order: mmcr0, mmcr1, mmcra, mmcr2, mmcrs Split this to give mmcra and mmcrs its own entries in vcpu and use a flat array for mmcr0 to mmcr2. This patch implements this cleanup to make code easier to read.

---
 arch/powerpc/include/asm/kvm_host.h       |  4 +++-
 arch/powerpc/include/uapi/asm/kvm.h       |  4 ++--
 arch/powerpc/kernel/asm-offsets.c         |  2 ++
 arch/powerpc/kvm/book3s_hv.c              | 16 ++++++++++++++--
 arch/powerpc/kvm/book3s_hv_rmhandlers.S   | 12 ++++++------
 tools/arch/powerpc/include/uapi/asm/kvm.h |  4 ++--
 6 files changed, 29 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/kvm_host.h +3 -1
index 7e2d061..fc115e2 100644
@@ -637,7 +637,9 @@ struct kvm_vcpu_arch {
 	u32 ccr1;
 	u32 dbsr;
 
-	u64 mmcr[5];
+	u64 mmcr[3];
+	u64 mmcra;
+	u64 mmcrs;
 	u32 pmc[8];
 	u32 spmc[2];
 	u64 siar;
arch/powerpc/include/uapi/asm/kvm.h +2 -2
index 264e266..e55d847 100644
@@ -510,8 +510,8 @@ struct kvm_ppc_cpu_char {
 
 #define KVM_REG_PPC_MMCR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
 #define KVM_REG_PPC_MMCR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
-#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
-#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
+#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
 #define KVM_REG_PPC_MMCRS	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x14)
 #define KVM_REG_PPC_SIAR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x15)
 #define KVM_REG_PPC_SDAR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x16)
arch/powerpc/kernel/asm-offsets.c +2 -0
index 6657dc6..6fa4853 100644
@@ -559,6 +559,8 @@ int main(void)
 	OFFSET(VCPU_IRQ_PENDING, kvm_vcpu, arch.irq_pending);
 	OFFSET(VCPU_DBELL_REQ, kvm_vcpu, arch.doorbell_request);
 	OFFSET(VCPU_MMCR, kvm_vcpu, arch.mmcr);
+	OFFSET(VCPU_MMCRA, kvm_vcpu, arch.mmcra);
+	OFFSET(VCPU_MMCRS, kvm_vcpu, arch.mmcrs);
 	OFFSET(VCPU_PMC, kvm_vcpu, arch.pmc);
 	OFFSET(VCPU_SPMC, kvm_vcpu, arch.spmc);
 	OFFSET(VCPU_SIAR, kvm_vcpu, arch.siar);
arch/powerpc/kvm/book3s_hv.c +14 -2
index 6bf66649..3f90eee 100644
@@ -1679,10 +1679,16 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	case KVM_REG_PPC_UAMOR:
 		*val = get_reg_val(id, vcpu->arch.uamor);
 		break;
-	case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCRS:
+	case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR2:
 		i = id - KVM_REG_PPC_MMCR0;
 		*val = get_reg_val(id, vcpu->arch.mmcr[i]);
 		break;
+	case KVM_REG_PPC_MMCRA:
+		*val = get_reg_val(id, vcpu->arch.mmcra);
+		break;
+	case KVM_REG_PPC_MMCRS:
+		*val = get_reg_val(id, vcpu->arch.mmcrs);
+		break;
 	case KVM_REG_PPC_PMC1 ... KVM_REG_PPC_PMC8:
 		i = id - KVM_REG_PPC_PMC1;
 		*val = get_reg_val(id, vcpu->arch.pmc[i]);
@@ -1900,10 +1906,16 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	case KVM_REG_PPC_UAMOR:
 		vcpu->arch.uamor = set_reg_val(id, *val);
 		break;
-	case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCRS:
+	case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR2:
 		i = id - KVM_REG_PPC_MMCR0;
 		vcpu->arch.mmcr[i] = set_reg_val(id, *val);
 		break;
+	case KVM_REG_PPC_MMCRA:
+		vcpu->arch.mmcra = set_reg_val(id, *val);
+		break;
+	case KVM_REG_PPC_MMCRS:
+		vcpu->arch.mmcrs = set_reg_val(id, *val);
+		break;
 	case KVM_REG_PPC_PMC1 ... KVM_REG_PPC_PMC8:
 		i = id - KVM_REG_PPC_PMC1;
 		vcpu->arch.pmc[i] = set_reg_val(id, *val);
arch/powerpc/kvm/book3s_hv_rmhandlers.S +6 -6
index 7194389..702eaa2 100644
@@ -3428,7 +3428,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_PMAO_BUG)
 	mtspr	SPRN_PMC6, r9
 	ld	r3, VCPU_MMCR(r4)
 	ld	r5, VCPU_MMCR + 8(r4)
-	ld	r6, VCPU_MMCR + 16(r4)
+	ld	r6, VCPU_MMCRA(r4)
 	ld	r7, VCPU_SIAR(r4)
 	ld	r8, VCPU_SDAR(r4)
 	mtspr	SPRN_MMCR1, r5
@@ -3436,14 +3436,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_PMAO_BUG)
 	mtspr	SPRN_SIAR, r7
 	mtspr	SPRN_SDAR, r8
 BEGIN_FTR_SECTION
-	ld	r5, VCPU_MMCR + 24(r4)
+	ld	r5, VCPU_MMCR + 16(r4)
 	ld	r6, VCPU_SIER(r4)
 	mtspr	SPRN_MMCR2, r5
 	mtspr	SPRN_SIER, r6
 BEGIN_FTR_SECTION_NESTED(96)
 	lwz	r7, VCPU_PMC + 24(r4)
 	lwz	r8, VCPU_PMC + 28(r4)
-	ld	r9, VCPU_MMCR + 32(r4)
+	ld	r9, VCPU_MMCRS(r4)
 	mtspr	SPRN_SPMC1, r7
 	mtspr	SPRN_SPMC2, r8
 	mtspr	SPRN_MMCRS, r9
@@ -3551,9 +3551,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 	mfspr	r8, SPRN_SDAR
 	std	r4, VCPU_MMCR(r9)
 	std	r5, VCPU_MMCR + 8(r9)
-	std	r6, VCPU_MMCR + 16(r9)
+	std	r6, VCPU_MMCRA(r9)
 BEGIN_FTR_SECTION
-	std	r10, VCPU_MMCR + 24(r9)
+	std	r10, VCPU_MMCR + 16(r9)
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 	std	r7, VCPU_SIAR(r9)
 	std	r8, VCPU_SDAR(r9)
@@ -3578,7 +3578,7 @@ BEGIN_FTR_SECTION_NESTED(96)
 	mfspr	r8, SPRN_MMCRS
 	stw	r6, VCPU_PMC + 24(r9)
 	stw	r7, VCPU_PMC + 28(r9)
-	std	r8, VCPU_MMCR + 32(r9)
+	std	r8, VCPU_MMCRS(r9)
 	lis	r4, 0x8000
 	mtspr	SPRN_MMCRS, r4
 END_FTR_SECTION_NESTED(CPU_FTR_ARCH_300, 0, 96)
tools/arch/powerpc/include/uapi/asm/kvm.h +2 -2
index 264e266..e55d847 100644
@@ -510,8 +510,8 @@ struct kvm_ppc_cpu_char {
 
 #define KVM_REG_PPC_MMCR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
 #define KVM_REG_PPC_MMCR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
-#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
-#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
+#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
 #define KVM_REG_PPC_MMCRS	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x14)
 #define KVM_REG_PPC_SIAR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x15)
 #define KVM_REG_PPC_SDAR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x16)
Signature · 1 line
1.8.3.1
#5 lore raw

Re: [v3 02/15] KVM: PPC: Book3S HV: Cleanup updates for kvm vcpu MMCR

Quoted 5 lines · Athira Rajeev

Currently kvm_vcpu_arch stores all Monitor Mode Control registers in a flat array in order: mmcr0, mmcr1, mmcra, mmcr2, mmcrs Split this to give mmcra and mmcrs its own entries in vcpu and use a flat array for mmcr0 to mmcr2. This patch implements this cleanup to make code easier to read.

Changing the way KVM stores these values internally is fine, but changing the user ABI is not. This part:

arch/powerpc/include/uapi/asm/kvm.h struct kvm_ppc_cpu_char { · line 514

Quoted 12 lines
arch/powerpc/include/uapi/asm/kvm.h +2 -2
index 264e266..e55d847 100644
@@ -510,8 +510,8 @@ struct kvm_ppc_cpu_char {
 
 #define KVM_REG_PPC_MMCR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
 #define KVM_REG_PPC_MMCR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
-#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
-#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
+#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)

means that existing userspace programs that used to work would now be broken. That is not acceptable (breaking the user ABI is only ever acceptable with a very compelling reason). So NAK to this part of the patch.

Regards,
Paul.

#6 lore raw

Re: [v3 02/15] KVM: PPC: Book3S HV: Cleanup updates for kvm vcpu MMCR

Quoted 20 lines · Paul Mackerras
Quoted 5 lines · Athira Rajeev

Currently kvm_vcpu_arch stores all Monitor Mode Control registers in a flat array in order: mmcr0, mmcr1, mmcra, mmcr2, mmcrs Split this to give mmcra and mmcrs its own entries in vcpu and use a flat array for mmcr0 to mmcr2. This patch implements this cleanup to make code easier to read.

Changing the way KVM stores these values internally is fine, but changing the user ABI is not. This part:

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +0 -0
index 264e266..e55d847 100644
@@ -510,8 +510,8 @@ struct kvm_ppc_cpu_char {
 
Quoted 11 lines

arch/powerpc/include/uapi/asm/kvm.h struct kvm_ppc_cpu_char { · line 514

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +2 -2
 #define KVM_REG_PPC_MMCR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
 #define KVM_REG_PPC_MMCR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
-#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
-#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
+#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)

means that existing userspace programs that used to work would now be broken. That is not acceptable (breaking the user ABI is only ever acceptable with a very compelling reason). So NAK to this part of the patch.

Hi Paul

Thanks for checking the patch. I understood your point on user ABI breakage that this particular change can cause. I will retain original KVM_REG_PPC_MMCRA and KVM_REG_PPC_MMCR2 order in kvm.h
And with that, additionally I will need below change ( on top of current patch ) for my clean up updates for kvm cpu MMCR to work, Because now mmcra and mmcrs will have its own entries in vcpu and is not part of the mmcr[] array
Please suggest if this looks good

Thanks
Athira

—

arch/powerpc/kvm/book3s_hv.c +8 -2
index 3f90eee261fc..b10bb404f0d5 100644
@@ -1679,10 +1679,13 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
        case KVM_REG_PPC_UAMOR:
                *val = get_reg_val(id, vcpu->arch.uamor);
                break;
-       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR2:
+       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR1:
                i = id - KVM_REG_PPC_MMCR0;
                *val = get_reg_val(id, vcpu->arch.mmcr[i]);
                break;
+       case KVM_REG_PPC_MMCR2:
+               *val = get_reg_val(id, vcpu->arch.mmcr[2]);
+               break;
        case KVM_REG_PPC_MMCRA:
                *val = get_reg_val(id, vcpu->arch.mmcra);
                break;
@@ -1906,10 +1909,13 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
        case KVM_REG_PPC_UAMOR:
                vcpu->arch.uamor = set_reg_val(id, *val);
                break;
-       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR2:
+       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR1:
                i = id - KVM_REG_PPC_MMCR0;
                vcpu->arch.mmcr[i] = set_reg_val(id, *val);
                break;
+       case KVM_REG_PPC_MMCR2:
+               vcpu->arch.mmcr[2] = set_reg_val(id, *val);
+               break;
        case KVM_REG_PPC_MMCRA:
                vcpu->arch.mmcra = set_reg_val(id, *val);
                break;

—

Quoted 3 lines

Regards,
Paul.

#7 lore raw

Re: [v3 02/15] KVM: PPC: Book3S HV: Cleanup updates for kvm vcpu MMCR

Quoted 29 lines · Athira Rajeev
Quoted 17 lines · Paul Mackerras
Quoted 5 lines · Athira Rajeev

Currently kvm_vcpu_arch stores all Monitor Mode Control registers in a flat array in order: mmcr0, mmcr1, mmcra, mmcr2, mmcrs Split this to give mmcra and mmcrs its own entries in vcpu and use a flat array for mmcr0 to mmcr2. This patch implements this cleanup to make code easier to read.

Changing the way KVM stores these values internally is fine, but changing the user ABI is not. This part:

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +0 -0
index 264e266..e55d847 100644
@@ -510,8 +510,8 @@ struct kvm_ppc_cpu_char {
 
Quoted 11 lines

arch/powerpc/include/uapi/asm/kvm.h struct kvm_ppc_cpu_char { · line 514

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +2 -2
 #define KVM_REG_PPC_MMCR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
 #define KVM_REG_PPC_MMCR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
-#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
-#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
+#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)

means that existing userspace programs that used to work would now be broken. That is not acceptable (breaking the user ABI is only ever acceptable with a very compelling reason). So NAK to this part of the patch.

Quoted 7 lines

Hi Paul

Thanks for checking the patch. I understood your point on user ABI breakage that this particular change can cause. I will retain original KVM_REG_PPC_MMCRA and KVM_REG_PPC_MMCR2 order in kvm.h
And with that, additionally I will need below change ( on top of current patch ) for my clean up updates for kvm cpu MMCR to work, Because now mmcra and mmcrs will have its own entries in vcpu and is not part of the mmcr[] array
Please suggest if this looks good

I did the same patch I think in my testing branch, it's here:

https://github.com/linuxppc/linux/commit/daea78154eff1b7e2f36be05a8f95feb5a588912

Can you please check that matches what you sent.

cheers

Quoted 40 lines
arch/powerpc/kvm/book3s_hv.c +8 -2
index 3f90eee261fc..b10bb404f0d5 100644
@@ -1679,10 +1679,13 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
        case KVM_REG_PPC_UAMOR:
                *val = get_reg_val(id, vcpu->arch.uamor);
                break;
-       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR2:
+       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR1:
                i = id - KVM_REG_PPC_MMCR0;
                *val = get_reg_val(id, vcpu->arch.mmcr[i]);
                break;
+       case KVM_REG_PPC_MMCR2:
+               *val = get_reg_val(id, vcpu->arch.mmcr[2]);
+               break;
        case KVM_REG_PPC_MMCRA:
                *val = get_reg_val(id, vcpu->arch.mmcra);
                break;
@@ -1906,10 +1909,13 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
        case KVM_REG_PPC_UAMOR:
                vcpu->arch.uamor = set_reg_val(id, *val);
                break;
-       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR2:
+       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR1:
                i = id - KVM_REG_PPC_MMCR0;
                vcpu->arch.mmcr[i] = set_reg_val(id, *val);
                break;
+       case KVM_REG_PPC_MMCR2:
+               vcpu->arch.mmcr[2] = set_reg_val(id, *val);
+               break;
        case KVM_REG_PPC_MMCRA:
                vcpu->arch.mmcra = set_reg_val(id, *val);
                break;

—

Quoted 3 lines

Regards,
Paul.

#8 lore raw

Re: [v3 02/15] KVM: PPC: Book3S HV: Cleanup updates for kvm vcpu MMCR

Quoted 42 lines · Michael Ellerman
Quoted 29 lines · Athira Rajeev <[email protected]…
Quoted 17 lines · Paul Mackerras
Quoted 5 lines · Athira Rajeev

Currently kvm_vcpu_arch stores all Monitor Mode Control registers in a flat array in order: mmcr0, mmcr1, mmcra, mmcr2, mmcrs Split this to give mmcra and mmcrs its own entries in vcpu and use a flat array for mmcr0 to mmcr2. This patch implements this cleanup to make code easier to read.

Changing the way KVM stores these values internally is fine, but changing the user ABI is not. This part:

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +0 -0
index 264e266..e55d847 100644
@@ -510,8 +510,8 @@ struct kvm_ppc_cpu_char {
 
Quoted 11 lines

arch/powerpc/include/uapi/asm/kvm.h struct kvm_ppc_cpu_char { · line 514

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +2 -2
 #define KVM_REG_PPC_MMCR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
 #define KVM_REG_PPC_MMCR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
-#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
-#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
+#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)

means that existing userspace programs that used to work would now be broken. That is not acceptable (breaking the user ABI is only ever acceptable with a very compelling reason). So NAK to this part of the patch.

Quoted 7 lines

Hi Paul

Thanks for checking the patch. I understood your point on user ABI breakage that this particular change can cause. I will retain original KVM_REG_PPC_MMCRA and KVM_REG_PPC_MMCR2 order in kvm.h
And with that, additionally I will need below change ( on top of current patch ) for my clean up updates for kvm cpu MMCR to work, Because now mmcra and mmcrs will have its own entries in vcpu and is not part of the mmcr[] array
Please suggest if this looks good

Quoted 6 lines

I did the same patch I think in my testing branch, it's here:

https://github.com/linuxppc/linux/commit/daea78154eff1b7e2f36be05a8f95feb5a588912 <https://github.com/linuxppc/linux/commit/daea78154eff1b7e2f36be05a8f95feb5a588912>

Can you please check that matches what you sent.

Hi Michael,

Yes, it matches. Thanks for making this change.

Quoted 43 lines

cheers

Quoted 40 lines
arch/powerpc/kvm/book3s_hv.c +8 -2
index 3f90eee261fc..b10bb404f0d5 100644
@@ -1679,10 +1679,13 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
       case KVM_REG_PPC_UAMOR:
               *val = get_reg_val(id, vcpu->arch.uamor);
               break;
-       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR2:
+       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR1:
               i = id - KVM_REG_PPC_MMCR0;
               *val = get_reg_val(id, vcpu->arch.mmcr[i]);
               break;
+       case KVM_REG_PPC_MMCR2:
+               *val = get_reg_val(id, vcpu->arch.mmcr[2]);
+               break;
       case KVM_REG_PPC_MMCRA:
               *val = get_reg_val(id, vcpu->arch.mmcra);
               break;
@@ -1906,10 +1909,13 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
       case KVM_REG_PPC_UAMOR:
               vcpu->arch.uamor = set_reg_val(id, *val);
               break;
-       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR2:
+       case KVM_REG_PPC_MMCR0 ... KVM_REG_PPC_MMCR1:
               i = id - KVM_REG_PPC_MMCR0;
               vcpu->arch.mmcr[i] = set_reg_val(id, *val);
               break;
+       case KVM_REG_PPC_MMCR2:
+               vcpu->arch.mmcr[2] = set_reg_val(id, *val);
+               break;
       case KVM_REG_PPC_MMCRA:
               vcpu->arch.mmcra = set_reg_val(id, *val);
               break;

—

Quoted 3 lines

Regards,
Paul.

#9 lore raw

Re: [v3 02/15] KVM: PPC: Book3S HV: Cleanup updates for kvm vcpu MMCR

In reply to Athira Rajeev
Quoted 32 lines · Athira Rajeev
Quoted 20 lines · Paul Mackerras
Quoted 5 lines · Athira Rajeev

Currently kvm_vcpu_arch stores all Monitor Mode Control registers in a flat array in order: mmcr0, mmcr1, mmcra, mmcr2, mmcrs Split this to give mmcra and mmcrs its own entries in vcpu and use a flat array for mmcr0 to mmcr2. This patch implements this cleanup to make code easier to read.

Changing the way KVM stores these values internally is fine, but changing the user ABI is not. This part:

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +0 -0
index 264e266..e55d847 100644
@@ -510,8 +510,8 @@ struct kvm_ppc_cpu_char {
 
Quoted 11 lines

arch/powerpc/include/uapi/asm/kvm.h struct kvm_ppc_cpu_char { · line 514

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +2 -2
 #define KVM_REG_PPC_MMCR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
 #define KVM_REG_PPC_MMCR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
-#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
-#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
+#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)

means that existing userspace programs that used to work would now be broken. That is not acceptable (breaking the user ABI is only ever acceptable with a very compelling reason). So NAK to this part of the patch.

Quoted 7 lines

Hi Paul

Thanks for checking the patch. I understood your point on user ABI breakage that this particular change can cause. I will retain original KVM_REG_PPC_MMCRA and KVM_REG_PPC_MMCR2 order in kvm.h
And with that, additionally I will need below change ( on top of current patch ) for my clean up updates for kvm cpu MMCR to work, Because now mmcra and mmcrs will have its own entries in vcpu and is not part of the mmcr[] array
Please suggest if this looks good

Yes, that looks fine.

By the way, is the new MMCRS register here at all related to the MMCRS that there used to be on POWER8, but which wasn't present (as far as I know) on POWER9?

Paul.

#10 lore raw

Re: [v3 02/15] KVM: PPC: Book3S HV: Cleanup updates for kvm vcpu MMCR

Quoted 31 lines · Paul Mackerras
Quoted 30 lines · Athira Rajeev
Quoted 18 lines · Paul Mackerras
Quoted 5 lines · Athira Rajeev

Currently kvm_vcpu_arch stores all Monitor Mode Control registers in a flat array in order: mmcr0, mmcr1, mmcra, mmcr2, mmcrs Split this to give mmcra and mmcrs its own entries in vcpu and use a flat array for mmcr0 to mmcr2. This patch implements this cleanup to make code easier to read.

Changing the way KVM stores these values internally is fine, but changing the user ABI is not. This part:

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +0 -0
index 264e266..e55d847 100644
@@ -510,8 +510,8 @@ struct kvm_ppc_cpu_char {
 
Quoted 10 lines

arch/powerpc/include/uapi/asm/kvm.h struct kvm_ppc_cpu_char { · line 514

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +2 -2
 #define KVM_REG_PPC_MMCR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
 #define KVM_REG_PPC_MMCR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
-#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
-#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
+#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)

means that existing userspace programs that used to work would now be broken. That is not acceptable (breaking the user ABI is only ever acceptable with a very compelling reason). So NAK to this part of the patch.

Hi Paul

Quoted 8 lines
Quoted 5 lines

Thanks for checking the patch. I understood your point on user ABI breakage that this particular change can cause. I will retain original KVM_REG_PPC_MMCRA and KVM_REG_PPC_MMCR2 order in kvm.h
And with that, additionally I will need below change ( on top of current patch ) for my clean up updates for kvm cpu MMCR to work, Because now mmcra and mmcrs will have its own entries in vcpu and is not part of the mmcr[] array
Please suggest if this looks good

Yes, that looks fine.

By the way, is the new MMCRS register here at all related to the MMCRS

Hi Paul,

We have only split the current array (mmcr[]) and separated it to mmcra and mmcrs. Only new spr that is added is mmcr3 (for Power10).

Maddy

Quoted 4 lines

that there used to be on POWER8, but which wasn't present (as far as I know) on POWER9?

Paul.

#11 lore raw

Re: [v3 02/15] KVM: PPC: Book3S HV: Cleanup updates for kvm vcpu MMCR

In reply to Paul Mackerras
Quoted 16 lines · Paul Mackerras
Quoted 5 lines · Athira Rajeev

Currently kvm_vcpu_arch stores all Monitor Mode Control registers in a flat array in order: mmcr0, mmcr1, mmcra, mmcr2, mmcrs Split this to give mmcra and mmcrs its own entries in vcpu and use a flat array for mmcr0 to mmcr2. This patch implements this cleanup to make code easier to read.

Changing the way KVM stores these values internally is fine, but changing the user ABI is not. This part:

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +0 -0
index 264e266..e55d847 100644
@@ -510,8 +510,8 @@ struct kvm_ppc_cpu_char {
 
Quoted 11 lines

arch/powerpc/include/uapi/asm/kvm.h struct kvm_ppc_cpu_char { · line 514

Quoted 6 lines
arch/powerpc/include/uapi/asm/kvm.h +2 -2
 #define KVM_REG_PPC_MMCR0	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
 #define KVM_REG_PPC_MMCR1	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
-#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
-#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)
+#define KVM_REG_PPC_MMCR2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+#define KVM_REG_PPC_MMCRA	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x13)

means that existing userspace programs that used to work would now be broken. That is not acceptable (breaking the user ABI is only ever acceptable with a very compelling reason). So NAK to this part of the patch.

I assume we don't have a KVM unit test that would have caught this?

cheers

#12 lore raw

PATCH v3 3/15 powerpc/perf: Update Power PMU cache_events to u64 type

In reply to Athira Rajeev

Events of type PERF_TYPE_HW_CACHE was described for Power PMU
as: int (*cache_events)[type][op][result];

where type, op, result values unpacked from the event attribute config value is used to generate the raw event code at runtime.

So far the event code values which used to create these cache-related events were within 32 bit and int type worked. In power10, some of the event codes are of 64-bit value and hence update the Power PMU cache_events to u64 type in power_pmu struct. Also propagate this change to existing all PMU driver code paths which are using ppmu->cache_events.

---
 arch/powerpc/include/asm/perf_event_server.h | 2 +-
 arch/powerpc/perf/core-book3s.c              | 2 +-
 arch/powerpc/perf/generic-compat-pmu.c       | 2 +-
 arch/powerpc/perf/mpc7450-pmu.c              | 2 +-
 arch/powerpc/perf/power5+-pmu.c              | 2 +-
 arch/powerpc/perf/power5-pmu.c               | 2 +-
 arch/powerpc/perf/power6-pmu.c               | 2 +-
 arch/powerpc/perf/power7-pmu.c               | 2 +-
 arch/powerpc/perf/power8-pmu.c               | 2 +-
 arch/powerpc/perf/power9-pmu.c               | 2 +-
 arch/powerpc/perf/ppc970-pmu.c               | 2 +-
 11 files changed, 11 insertions(+), 11 deletions(-)
arch/powerpc/include/asm/perf_event_server.h +1 -1
index f9a3668..14b8dc1 100644
@@ -53,7 +53,7 @@ struct power_pmu {
 	const struct attribute_group	**attr_groups;
 	int		n_generic;
 	int		*generic_events;
-	int		(*cache_events)[PERF_COUNT_HW_CACHE_MAX]
+	u64		(*cache_events)[PERF_COUNT_HW_CACHE_MAX]
 			       [PERF_COUNT_HW_CACHE_OP_MAX]
 			       [PERF_COUNT_HW_CACHE_RESULT_MAX];
 
arch/powerpc/perf/core-book3s.c +1 -1
index 18b1b6a..f4d07b5 100644
@@ -1790,7 +1790,7 @@ static void hw_perf_event_destroy(struct perf_event *event)
 static int hw_perf_cache_event(u64 config, u64 *eventp)
 {
 	unsigned long type, op, result;
-	int ev;
+	u64 ev;
 
 	if (!ppmu->cache_events)
 		return -EINVAL;
arch/powerpc/perf/generic-compat-pmu.c +1 -1
index 5e5a54d..eb8a6aaf 100644
@@ -101,7 +101,7 @@ enum {
  * 0 means not supported, -1 means nonsensical, other values
  * are event codes.
  */
-static int generic_compat_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
+static u64 generic_compat_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
 	[ C(L1D) ] = {
 		[ C(OP_READ) ] = {
 			[ C(RESULT_ACCESS) ] = 0,
arch/powerpc/perf/mpc7450-pmu.c +1 -1
index 826de25..1919e9d 100644
@@ -361,7 +361,7 @@ static void mpc7450_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
  * 0 means not supported, -1 means nonsensical, other values
  * are event codes.
  */
-static int mpc7450_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
+static u64 mpc7450_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
 	[C(L1D)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
 		[C(OP_READ)] = {	0,		0x225	},
 		[C(OP_WRITE)] = {	0,		0x227	},
arch/powerpc/perf/power5+-pmu.c +1 -1
index 5f0821e..a62b2cd 100644
@@ -619,7 +619,7 @@ static void power5p_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
  * 0 means not supported, -1 means nonsensical, other values
  * are event codes.
  */
-static int power5p_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
+static u64 power5p_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
 	[C(L1D)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
 		[C(OP_READ)] = {	0x1c10a8,	0x3c1088	},
 		[C(OP_WRITE)] = {	0x2c10a8,	0xc10c3		},
arch/powerpc/perf/power5-pmu.c +1 -1
index 426021d..8732b58 100644
@@ -561,7 +561,7 @@ static void power5_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
  * 0 means not supported, -1 means nonsensical, other values
  * are event codes.
  */
-static int power5_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
+static u64 power5_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
 	[C(L1D)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
 		[C(OP_READ)] = {	0x4c1090,	0x3c1088	},
 		[C(OP_WRITE)] = {	0x3c1090,	0xc10c3		},
arch/powerpc/perf/power6-pmu.c +1 -1
index e343a51..0e318cf 100644
@@ -481,7 +481,7 @@ static void p6_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
  * are event codes.
  * The "DTLB" and "ITLB" events relate to the DERAT and IERAT.
  */
-static int power6_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
+static u64 power6_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
 	[C(L1D)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
 		[C(OP_READ)] = {	0x280030,	0x80080		},
 		[C(OP_WRITE)] = {	0x180032,	0x80088		},
arch/powerpc/perf/power7-pmu.c +1 -1
index 3152336..5e0bf09 100644
@@ -333,7 +333,7 @@ static void power7_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
  * 0 means not supported, -1 means nonsensical, other values
  * are event codes.
  */
-static int power7_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
+static u64 power7_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
 	[C(L1D)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
 		[C(OP_READ)] = {	0xc880,		0x400f0	},
 		[C(OP_WRITE)] = {	0,		0x300f0	},
arch/powerpc/perf/power8-pmu.c +1 -1
index 3a5fcc2..5282e84 100644
@@ -253,7 +253,7 @@ static void power8_config_bhrb(u64 pmu_bhrb_filter)
  * 0 means not supported, -1 means nonsensical, other values
  * are event codes.
  */
-static int power8_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
+static u64 power8_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
 	[ C(L1D) ] = {
 		[ C(OP_READ) ] = {
 			[ C(RESULT_ACCESS) ] = PM_LD_REF_L1,
arch/powerpc/perf/power9-pmu.c +1 -1
index 08c3ef7..05dae38 100644
@@ -310,7 +310,7 @@ static void power9_config_bhrb(u64 pmu_bhrb_filter)
  * 0 means not supported, -1 means nonsensical, other values
  * are event codes.
  */
-static int power9_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
+static u64 power9_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
 	[ C(L1D) ] = {
 		[ C(OP_READ) ] = {
 			[ C(RESULT_ACCESS) ] = PM_LD_REF_L1,
arch/powerpc/perf/ppc970-pmu.c +1 -1
index 89a90ab..d35223f 100644
@@ -432,7 +432,7 @@ static void p970_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
  * 0 means not supported, -1 means nonsensical, other values
  * are event codes.
  */
-static int ppc970_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
+static u64 ppc970_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
 	[C(L1D)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
 		[C(OP_READ)] = {	0x8810,		0x3810	},
 		[C(OP_WRITE)] = {	0x7810,		0x813	},
Signature · 1 line
1.8.3.1
#13 lore raw

PATCH v3 4/15 powerpc/perf: Add support for ISA3.1 PMU SPRs

In reply to Athira Rajeev

From: Madhavan Srinivasan <[email protected]>

PowerISA v3.1 includes new performance monitoring unit(PMU) special purpose registers (SPRs). They are

Monitor Mode Control Register 3 (MMCR3)
Sampled Instruction Event Register 2 (SIER2)
Sampled Instruction Event Register 3 (SIER3)

MMCR3 is added for further sampling related configuration control. SIER2/SIER3 are added to provide additional information about the sampled instruction.

Patch adds new PPMU flag called "PPMU_ARCH_310S" to support handling of these new SPRs, updates the struct thread_struct to include these new SPRs, include MMCR3 in struct mmcr_regs. This is needed to support programming of MMCR3 SPR during event_[enable/disable]. Patch also adds the sysfs support for the MMCR3 SPR along with SPRN_ macros for these new pmu sprs.

---
 arch/powerpc/include/asm/perf_event_server.h |  2 ++
 arch/powerpc/include/asm/processor.h         |  4 ++++
 arch/powerpc/include/asm/reg.h               |  6 ++++++
 arch/powerpc/kernel/sysfs.c                  |  8 ++++++++
 arch/powerpc/perf/core-book3s.c              | 29 ++++++++++++++++++++++++++++
 5 files changed, 49 insertions(+)
arch/powerpc/include/asm/perf_event_server.h +2 -0
index 14b8dc1..832450a 100644
@@ -22,6 +22,7 @@ struct mmcr_regs {
 	unsigned long mmcr1;
 	unsigned long mmcr2;
 	unsigned long mmcra;
+	unsigned long mmcr3;
 };
 /*
  * This struct provides the constants and functions needed to
@@ -75,6 +76,7 @@ struct power_pmu {
 #define PPMU_HAS_SIER		0x00000040 /* Has SIER */
 #define PPMU_ARCH_207S		0x00000080 /* PMC is architecture v2.07S */
 #define PPMU_NO_SIAR		0x00000100 /* Do not use SIAR */
+#define PPMU_ARCH_310S		0x00000200 /* Has MMCR3, SIER2 and SIER3 */
 
 /*
  * Values for flags to get_alternatives()
arch/powerpc/include/asm/processor.h +4 -0
index 52a6783..a466e94 100644
@@ -272,6 +272,10 @@ struct thread_struct {
 	unsigned 	mmcr0;
 
 	unsigned 	used_ebb;
+	unsigned long   mmcr3;
+	unsigned long   sier2;
+	unsigned long   sier3;
+
 #endif
 };
 
arch/powerpc/include/asm/reg.h +6 -0
index 88e6c78..21a1b2d 100644
@@ -876,7 +876,9 @@
 #define   MMCR0_FCHV	0x00000001UL /* freeze conditions in hypervisor mode */
 #define SPRN_MMCR1	798
 #define SPRN_MMCR2	785
+#define SPRN_MMCR3	754
 #define SPRN_UMMCR2	769
+#define SPRN_UMMCR3	738
 #define SPRN_MMCRA	0x312
 #define   MMCRA_SDSYNC	0x80000000UL /* SDAR synced with SIAR */
 #define   MMCRA_SDAR_DCACHE_MISS 0x40000000UL
@@ -918,6 +920,10 @@
 #define   SIER_SIHV		0x1000000	/* Sampled MSR_HV */
 #define   SIER_SIAR_VALID	0x0400000	/* SIAR contents valid */
 #define   SIER_SDAR_VALID	0x0200000	/* SDAR contents valid */
+#define SPRN_SIER2	752
+#define SPRN_SIER3	753
+#define SPRN_USIER2	736
+#define SPRN_USIER3	737
 #define SPRN_SIAR	796
 #define SPRN_SDAR	797
 #define SPRN_TACR	888
arch/powerpc/kernel/sysfs.c +8 -0
index 571b325..46b4ebc 100644
@@ -622,8 +622,10 @@ void ppc_enable_pmcs(void)
 SYSFS_PMCSETUP(pmc8, SPRN_PMC8);
 
 SYSFS_PMCSETUP(mmcra, SPRN_MMCRA);
+SYSFS_PMCSETUP(mmcr3, SPRN_MMCR3);
 
 static DEVICE_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
+static DEVICE_ATTR(mmcr3, 0600, show_mmcr3, store_mmcr3);
 #endif /* HAS_PPC_PMC56 */
 
 
@@ -886,6 +888,9 @@ static int register_cpu_online(unsigned int cpu)
 #ifdef	CONFIG_PMU_SYSFS
 	if (cpu_has_feature(CPU_FTR_MMCRA))
 		device_create_file(s, &dev_attr_mmcra);
+
+	if (cpu_has_feature(CPU_FTR_ARCH_31))
+		device_create_file(s, &dev_attr_mmcr3);
 #endif /* CONFIG_PMU_SYSFS */
 
 	if (cpu_has_feature(CPU_FTR_PURR)) {
@@ -980,6 +985,9 @@ static int unregister_cpu_online(unsigned int cpu)
 #ifdef CONFIG_PMU_SYSFS
 	if (cpu_has_feature(CPU_FTR_MMCRA))
 		device_remove_file(s, &dev_attr_mmcra);
+
+	if (cpu_has_feature(CPU_FTR_ARCH_31))
+		device_remove_file(s, &dev_attr_mmcr3);
 #endif /* CONFIG_PMU_SYSFS */
 
 	if (cpu_has_feature(CPU_FTR_PURR)) {
arch/powerpc/perf/core-book3s.c +29 -0
index f4d07b5..ca32fc0 100644
@@ -72,6 +72,11 @@ struct cpu_hw_events {
 /*
  * 32-bit doesn't have MMCRA but does have an MMCR2,
  * and a few other names are different.
+ * Also 32-bit doesn't have MMCR3, SIER2 and SIER3.
+ * Define them as zero knowing that any code path accessing
+ * these registers (via mtspr/mfspr) are done under ppmu flag
+ * check for PPMU_ARCH_310S and we will not enter that code path
+ * for 32-bit.
  */
 #ifdef CONFIG_PPC32
 
@@ -85,6 +90,9 @@ struct cpu_hw_events {
 #define MMCR0_PMCC_U6		0
 
 #define SPRN_MMCRA		SPRN_MMCR2
+#define SPRN_MMCR3		0
+#define SPRN_SIER2		0
+#define SPRN_SIER3		0
 #define MMCRA_SAMPLE_ENABLE	0
 
 static inline unsigned long perf_ip_adjust(struct pt_regs *regs)
@@ -581,6 +589,11 @@ static void ebb_switch_out(unsigned long mmcr0)
 	current->thread.sdar  = mfspr(SPRN_SDAR);
 	current->thread.mmcr0 = mmcr0 & MMCR0_USER_MASK;
 	current->thread.mmcr2 = mfspr(SPRN_MMCR2) & MMCR2_USER_MASK;
+	if (ppmu->flags & PPMU_ARCH_310S) {
+		current->thread.mmcr3 = mfspr(SPRN_MMCR3);
+		current->thread.sier2 = mfspr(SPRN_SIER2);
+		current->thread.sier3 = mfspr(SPRN_SIER3);
+	}
 }
 
 static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
@@ -620,6 +633,12 @@ static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
 	 * instead manage the MMCR2 entirely by itself.
 	 */
 	mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2 | current->thread.mmcr2);
+
+	if (ppmu->flags & PPMU_ARCH_310S) {
+		mtspr(SPRN_MMCR3, current->thread.mmcr3);
+		mtspr(SPRN_SIER2, current->thread.sier2);
+		mtspr(SPRN_SIER3, current->thread.sier3);
+	}
 out:
 	return mmcr0;
 }
@@ -840,6 +859,11 @@ void perf_event_print_debug(void)
 		pr_info("EBBRR: %016lx BESCR: %016lx\n",
 			mfspr(SPRN_EBBRR), mfspr(SPRN_BESCR));
 	}
+
+	if (ppmu->flags & PPMU_ARCH_310S) {
+		pr_info("MMCR3: %016lx SIER2: %016lx SIER3: %016lx\n",
+			mfspr(SPRN_MMCR3), mfspr(SPRN_SIER2), mfspr(SPRN_SIER3));
+	}
 #endif
 	pr_info("SIAR:  %016lx SDAR:  %016lx SIER:  %016lx\n",
 		mfspr(SPRN_SIAR), sdar, sier);
@@ -1305,6 +1329,8 @@ static void power_pmu_enable(struct pmu *pmu)
 	if (!cpuhw->n_added) {
 		mtspr(SPRN_MMCRA, cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
 		mtspr(SPRN_MMCR1, cpuhw->mmcr.mmcr1);
+		if (ppmu->flags & PPMU_ARCH_310S)
+			mtspr(SPRN_MMCR3, cpuhw->mmcr.mmcr3);
 		goto out_enable;
 	}
 
@@ -1348,6 +1374,9 @@ static void power_pmu_enable(struct pmu *pmu)
 	if (ppmu->flags & PPMU_ARCH_207S)
 		mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2);
 
+	if (ppmu->flags & PPMU_ARCH_310S)
+		mtspr(SPRN_MMCR3, cpuhw->mmcr.mmcr3);
+
 	/*
 	 * Read off any pre-existing events that need to move
 	 * to another PMC.
Signature · 1 line
1.8.3.1
#14 lore raw

Re: [v3 04/15] powerpc/perf: Add support for ISA3.1 PMU SPRs

Quoted 43 lines · Athira Rajeev

From: Madhavan Srinivasan <[email protected]>

PowerISA v3.1 includes new performance monitoring unit(PMU) special purpose registers (SPRs). They are

Monitor Mode Control Register 3 (MMCR3)
Sampled Instruction Event Register 2 (SIER2)
Sampled Instruction Event Register 3 (SIER3)

MMCR3 is added for further sampling related configuration control. SIER2/SIER3 are added to provide additional information about the sampled instruction.

Patch adds new PPMU flag called "PPMU_ARCH_310S" to support handling of these new SPRs, updates the struct thread_struct to include these new SPRs, include MMCR3 in struct mmcr_regs. This is needed to support programming of MMCR3 SPR during event_[enable/disable]. Patch also adds the sysfs support for the MMCR3 SPR along with SPRN_ macros for these new pmu sprs.

---
 arch/powerpc/include/asm/perf_event_server.h |  2 ++
 arch/powerpc/include/asm/processor.h         |  4 ++++
 arch/powerpc/include/asm/reg.h               |  6 ++++++
 arch/powerpc/kernel/sysfs.c                  |  8 ++++++++
 arch/powerpc/perf/core-book3s.c              | 29 ++++++++++++++++++++++++++++
 5 files changed, 49 insertions(+)
arch/powerpc/include/asm/perf_event_server.h +1 -0
index 14b8dc1..832450a 100644
@@ -22,6 +22,7 @@ struct mmcr_regs {
        unsigned long mmcr1;
        unsigned long mmcr2;
        unsigned long mmcra;
+       unsigned long mmcr3;
 };
 /*
  * This struct provides the constants and functions needed to

arch/powerpc/include/asm/perf_event_server.h struct power_pmu { · line 79

Quoted 4 lines
arch/powerpc/include/asm/perf_event_server.h +1 -0
@@ -75,6 +76,7 @@ struct power_pmu {
 #define PPMU_HAS_SIER          0x00000040 /* Has SIER */
 #define PPMU_ARCH_207S         0x00000080 /* PMC is architecture v2.07S */
 #define PPMU_NO_SIAR           0x00000100 /* Do not use SIAR */
+#define PPMU_ARCH_310S         0x00000200 /* Has MMCR3, SIER2 and SIER3 */

We elsewhere have CPU_FTR_ARCH_31, so should this be PPMU_ARCH_31S to be consistent.

Quoted 105 lines
arch/powerpc/include/asm/perf_event_server.h +0 -0
 /*
  * Values for flags to get_alternatives()
arch/powerpc/include/asm/processor.h +4 -0
index 52a6783..a466e94 100644
@@ -272,6 +272,10 @@ struct thread_struct {
        unsigned        mmcr0;
 
        unsigned        used_ebb;
+       unsigned long   mmcr3;
+       unsigned long   sier2;
+       unsigned long   sier3;
+
 #endif
 };
 
arch/powerpc/include/asm/reg.h +6 -0
index 88e6c78..21a1b2d 100644
@@ -876,7 +876,9 @@
 #define   MMCR0_FCHV   0x00000001UL /* freeze conditions in hypervisor mode */
 #define SPRN_MMCR1     798
 #define SPRN_MMCR2     785
+#define SPRN_MMCR3     754
 #define SPRN_UMMCR2    769
+#define SPRN_UMMCR3    738
 #define SPRN_MMCRA     0x312
 #define   MMCRA_SDSYNC 0x80000000UL /* SDAR synced with SIAR */
 #define   MMCRA_SDAR_DCACHE_MISS 0x40000000UL
@@ -918,6 +920,10 @@
 #define   SIER_SIHV            0x1000000       /* Sampled MSR_HV */
 #define   SIER_SIAR_VALID      0x0400000       /* SIAR contents valid */
 #define   SIER_SDAR_VALID      0x0200000       /* SDAR contents valid */
+#define SPRN_SIER2     752
+#define SPRN_SIER3     753
+#define SPRN_USIER2    736
+#define SPRN_USIER3    737
 #define SPRN_SIAR      796
 #define SPRN_SDAR      797
 #define SPRN_TACR      888
arch/powerpc/kernel/sysfs.c +8 -0
index 571b325..46b4ebc 100644
@@ -622,8 +622,10 @@ void ppc_enable_pmcs(void)
 SYSFS_PMCSETUP(pmc8, SPRN_PMC8);
 
 SYSFS_PMCSETUP(mmcra, SPRN_MMCRA);
+SYSFS_PMCSETUP(mmcr3, SPRN_MMCR3);
 
 static DEVICE_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
+static DEVICE_ATTR(mmcr3, 0600, show_mmcr3, store_mmcr3);
 #endif /* HAS_PPC_PMC56 */
 
 
@@ -886,6 +888,9 @@ static int register_cpu_online(unsigned int cpu)
 #ifdef CONFIG_PMU_SYSFS
        if (cpu_has_feature(CPU_FTR_MMCRA))
                device_create_file(s, &dev_attr_mmcra);
+
+       if (cpu_has_feature(CPU_FTR_ARCH_31))
+               device_create_file(s, &dev_attr_mmcr3);
 #endif /* CONFIG_PMU_SYSFS */
 
        if (cpu_has_feature(CPU_FTR_PURR)) {
@@ -980,6 +985,9 @@ static int unregister_cpu_online(unsigned int cpu)
 #ifdef CONFIG_PMU_SYSFS
        if (cpu_has_feature(CPU_FTR_MMCRA))
                device_remove_file(s, &dev_attr_mmcra);
+
+       if (cpu_has_feature(CPU_FTR_ARCH_31))
+               device_remove_file(s, &dev_attr_mmcr3);
 #endif /* CONFIG_PMU_SYSFS */
 
        if (cpu_has_feature(CPU_FTR_PURR)) {
arch/powerpc/perf/core-book3s.c +8 -0
index f4d07b5..ca32fc0 100644
@@ -72,6 +72,11 @@ struct cpu_hw_events {
 /*
  * 32-bit doesn't have MMCRA but does have an MMCR2,
  * and a few other names are different.
+ * Also 32-bit doesn't have MMCR3, SIER2 and SIER3.
+ * Define them as zero knowing that any code path accessing
+ * these registers (via mtspr/mfspr) are done under ppmu flag
+ * check for PPMU_ARCH_310S and we will not enter that code path
+ * for 32-bit.
  */
 #ifdef CONFIG_PPC32
 
@@ -85,6 +90,9 @@ struct cpu_hw_events {
 #define MMCR0_PMCC_U6          0
 
 #define SPRN_MMCRA             SPRN_MMCR2
+#define SPRN_MMCR3             0
+#define SPRN_SIER2             0
+#define SPRN_SIER3             0
 #define MMCRA_SAMPLE_ENABLE    0
 
 static inline unsigned long perf_ip_adjust(struct pt_regs *regs)

arch/powerpc/perf/core-book3s.c static void ebb_switch_out(unsigned long mmcr0) · line 593

Quoted 5 lines
arch/powerpc/perf/core-book3s.c +2 -0
@@ -581,6 +589,11 @@ static void ebb_switch_out(unsigned long mmcr0)
        current->thread.sdar  = mfspr(SPRN_SDAR);
        current->thread.mmcr0 = mmcr0 & MMCR0_USER_MASK;
        current->thread.mmcr2 = mfspr(SPRN_MMCR2) & MMCR2_USER_MASK;
+       if (ppmu->flags & PPMU_ARCH_310S) {
+               current->thread.mmcr3 = mfspr(SPRN_MMCR3);

Like MMCR0_USER_MASK and MMCR2_USER_MASK do we need a MMCR3_USER_MASK here, or is there no need?

Quoted 53 lines
arch/powerpc/perf/core-book3s.c +19 -1
+               current->thread.sier2 = mfspr(SPRN_SIER2);
+               current->thread.sier3 = mfspr(SPRN_SIER3);
+       }
 }
 
 static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
@@ -620,6 +633,12 @@ static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
         * instead manage the MMCR2 entirely by itself.
         */
        mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2 | current->thread.mmcr2);
+
+       if (ppmu->flags & PPMU_ARCH_310S) {
+               mtspr(SPRN_MMCR3, current->thread.mmcr3);
+               mtspr(SPRN_SIER2, current->thread.sier2);
+               mtspr(SPRN_SIER3, current->thread.sier3);
+       }
 out:
        return mmcr0;
 }
@@ -840,6 +859,11 @@ void perf_event_print_debug(void)
                pr_info("EBBRR: %016lx BESCR: %016lx\n",
                        mfspr(SPRN_EBBRR), mfspr(SPRN_BESCR));
        }
+
+       if (ppmu->flags & PPMU_ARCH_310S) {
+               pr_info("MMCR3: %016lx SIER2: %016lx SIER3: %016lx\n",
+                       mfspr(SPRN_MMCR3), mfspr(SPRN_SIER2), mfspr(SPRN_SIER3));
+       }
 #endif
        pr_info("SIAR:  %016lx SDAR:  %016lx SIER:  %016lx\n",
                mfspr(SPRN_SIAR), sdar, sier);
@@ -1305,6 +1329,8 @@ static void power_pmu_enable(struct pmu *pmu)
        if (!cpuhw->n_added) {
                mtspr(SPRN_MMCRA, cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
                mtspr(SPRN_MMCR1, cpuhw->mmcr.mmcr1);
+               if (ppmu->flags & PPMU_ARCH_310S)
+                       mtspr(SPRN_MMCR3, cpuhw->mmcr.mmcr3);
                goto out_enable;
        }
 
@@ -1348,6 +1374,9 @@ static void power_pmu_enable(struct pmu *pmu)
        if (ppmu->flags & PPMU_ARCH_207S)
                mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2);
 
+       if (ppmu->flags & PPMU_ARCH_310S)
+               mtspr(SPRN_MMCR3, cpuhw->mmcr.mmcr3);
+
        /*
         * Read off any pre-existing events that need to move
         * to another PMC.
--

1.8.3.1

#15 lore raw

Re: [v3 04/15] powerpc/perf: Add support for ISA3.1 PMU SPRs

Quoted 47 lines · Jordan Niethe
Quoted 41 lines · On Sat, Jul 18, 2020 at 1:02 AM Athira Rajeev <[email protected]…

From: Madhavan Srinivasan <[email protected]>

PowerISA v3.1 includes new performance monitoring unit(PMU) special purpose registers (SPRs). They are

Monitor Mode Control Register 3 (MMCR3)
Sampled Instruction Event Register 2 (SIER2)
Sampled Instruction Event Register 3 (SIER3)

MMCR3 is added for further sampling related configuration control. SIER2/SIER3 are added to provide additional information about the sampled instruction.

Patch adds new PPMU flag called "PPMU_ARCH_310S" to support handling of these new SPRs, updates the struct thread_struct to include these new SPRs, include MMCR3 in struct mmcr_regs. This is needed to support programming of MMCR3 SPR during event_[enable/disable]. Patch also adds the sysfs support for the MMCR3 SPR along with SPRN_ macros for these new pmu sprs.

---

arch/powerpc/include/asm/perf_event_server.h |  2 ++
arch/powerpc/include/asm/processor.h         |  4 ++++
arch/powerpc/include/asm/reg.h               |  6 ++++++
arch/powerpc/kernel/sysfs.c                  |  8 ++++++++
arch/powerpc/perf/core-book3s.c              | 29 ++++++++++++++++++++++++++++
5 files changed, 49 insertions(+)
arch/powerpc/include/asm/perf_event_server.h +1 -0
index 14b8dc1..832450a 100644
@@ -22,6 +22,7 @@ struct mmcr_regs {
       unsigned long mmcr1;
       unsigned long mmcr2;
       unsigned long mmcra;
+       unsigned long mmcr3;
 };
 /*
Quoted 9 lines

arch/powerpc/include/asm/perf_event_server.h struct power_pmu { · line 79

Quoted 6 lines
arch/powerpc/include/asm/perf_event_server.h +1 -0
 * This struct provides the constants and functions needed to
@@ -75,6 +76,7 @@ struct power_pmu {
 #define PPMU_HAS_SIER          0x00000040 /* Has SIER */
 #define PPMU_ARCH_207S         0x00000080 /* PMC is architecture v2.07S */
 #define PPMU_NO_SIAR           0x00000100 /* Do not use SIAR */
+#define PPMU_ARCH_310S         0x00000200 /* Has MMCR3, SIER2 and SIER3 */

We elsewhere have CPU_FTR_ARCH_31, so should this be PPMU_ARCH_31S to be consistent.

Quoted 1 line

Ok,
This change will need to be done in all places which are currently using PPMU_ARCH_310S

Quoted 102 lines
Quoted 102 lines

/*
* Values for flags to get_alternatives()

arch/powerpc/include/asm/processor.h +4 -0
index 52a6783..a466e94 100644
@@ -272,6 +272,10 @@ struct thread_struct {
       unsigned        mmcr0;
 
       unsigned        used_ebb;
+       unsigned long   mmcr3;
+       unsigned long   sier2;
+       unsigned long   sier3;
+
 #endif
 };
 
arch/powerpc/include/asm/reg.h +6 -0
index 88e6c78..21a1b2d 100644
@@ -876,7 +876,9 @@
 #define   MMCR0_FCHV   0x00000001UL /* freeze conditions in hypervisor mode */
 #define SPRN_MMCR1     798
 #define SPRN_MMCR2     785
+#define SPRN_MMCR3     754
 #define SPRN_UMMCR2    769
+#define SPRN_UMMCR3    738
 #define SPRN_MMCRA     0x312
 #define   MMCRA_SDSYNC 0x80000000UL /* SDAR synced with SIAR */
 #define   MMCRA_SDAR_DCACHE_MISS 0x40000000UL
@@ -918,6 +920,10 @@
 #define   SIER_SIHV            0x1000000       /* Sampled MSR_HV */
 #define   SIER_SIAR_VALID      0x0400000       /* SIAR contents valid */
 #define   SIER_SDAR_VALID      0x0200000       /* SDAR contents valid */
+#define SPRN_SIER2     752
+#define SPRN_SIER3     753
+#define SPRN_USIER2    736
+#define SPRN_USIER3    737
 #define SPRN_SIAR      796
 #define SPRN_SDAR      797
 #define SPRN_TACR      888
arch/powerpc/kernel/sysfs.c +8 -0
index 571b325..46b4ebc 100644
@@ -622,8 +622,10 @@ void ppc_enable_pmcs(void)
 SYSFS_PMCSETUP(pmc8, SPRN_PMC8);
 
 SYSFS_PMCSETUP(mmcra, SPRN_MMCRA);
+SYSFS_PMCSETUP(mmcr3, SPRN_MMCR3);
 
 static DEVICE_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
+static DEVICE_ATTR(mmcr3, 0600, show_mmcr3, store_mmcr3);
 #endif /* HAS_PPC_PMC56 */
 
 
@@ -886,6 +888,9 @@ static int register_cpu_online(unsigned int cpu)
 #ifdef CONFIG_PMU_SYSFS
       if (cpu_has_feature(CPU_FTR_MMCRA))
               device_create_file(s, &dev_attr_mmcra);
+
+       if (cpu_has_feature(CPU_FTR_ARCH_31))
+               device_create_file(s, &dev_attr_mmcr3);
 #endif /* CONFIG_PMU_SYSFS */
 
       if (cpu_has_feature(CPU_FTR_PURR)) {
@@ -980,6 +985,9 @@ static int unregister_cpu_online(unsigned int cpu)
 #ifdef CONFIG_PMU_SYSFS
       if (cpu_has_feature(CPU_FTR_MMCRA))
               device_remove_file(s, &dev_attr_mmcra);
+
+       if (cpu_has_feature(CPU_FTR_ARCH_31))
+               device_remove_file(s, &dev_attr_mmcr3);
 #endif /* CONFIG_PMU_SYSFS */
 
       if (cpu_has_feature(CPU_FTR_PURR)) {
arch/powerpc/perf/core-book3s.c +8 -0
index f4d07b5..ca32fc0 100644
@@ -72,6 +72,11 @@ struct cpu_hw_events {
 /*
 * 32-bit doesn't have MMCRA but does have an MMCR2,
 * and a few other names are different.
+ * Also 32-bit doesn't have MMCR3, SIER2 and SIER3.
+ * Define them as zero knowing that any code path accessing
+ * these registers (via mtspr/mfspr) are done under ppmu flag
+ * check for PPMU_ARCH_310S and we will not enter that code path
+ * for 32-bit.
 */
 #ifdef CONFIG_PPC32
 
@@ -85,6 +90,9 @@ struct cpu_hw_events {
 #define MMCR0_PMCC_U6          0
 
 #define SPRN_MMCRA             SPRN_MMCR2
+#define SPRN_MMCR3             0
+#define SPRN_SIER2             0
+#define SPRN_SIER3             0
 #define MMCRA_SAMPLE_ENABLE    0
 
Quoted 9 lines

arch/powerpc/perf/core-book3s.c static void ebb_switch_out(unsigned long mmcr0) · line 593

Quoted 7 lines
arch/powerpc/perf/core-book3s.c +2 -0
 static inline unsigned long perf_ip_adjust(struct pt_regs *regs)
@@ -581,6 +589,11 @@ static void ebb_switch_out(unsigned long mmcr0)
       current->thread.sdar  = mfspr(SPRN_SDAR);
       current->thread.mmcr0 = mmcr0 & MMCR0_USER_MASK;
       current->thread.mmcr2 = mfspr(SPRN_MMCR2) & MMCR2_USER_MASK;
+       if (ppmu->flags & PPMU_ARCH_310S) {
+               current->thread.mmcr3 = mfspr(SPRN_MMCR3);

Like MMCR0_USER_MASK and MMCR2_USER_MASK do we need a MMCR3_USER_MASK here, or is there no need?

Jordan

We don’t need user mask for MMCR3 and other new SPRs ( SIER2/3) . Incase of MMCR3, we dont have any Freeze control bits and incase of SIER2/3, it is similar to SIER (where HW handles the masking of the bits), hence we didn't add any user_mask for these SPRs

Thanks
Athira

Quoted 52 lines
Quoted 52 lines
arch/powerpc/perf/core-book3s.c +9 -0
+               current->thread.sier2 = mfspr(SPRN_SIER2);
+               current->thread.sier3 = mfspr(SPRN_SIER3);
+       }
 }
 
 static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
@@ -620,6 +633,12 @@ static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
        * instead manage the MMCR2 entirely by itself.
        */
       mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2 | current->thread.mmcr2);
+
+       if (ppmu->flags & PPMU_ARCH_310S) {
+               mtspr(SPRN_MMCR3, current->thread.mmcr3);
+               mtspr(SPRN_SIER2, current->thread.sier2);
+               mtspr(SPRN_SIER3, current->thread.sier3);
+       }

out:

       return mmcr0;
}
arch/powerpc/perf/core-book3s.c +10 -1
@@ -840,6 +859,11 @@ void perf_event_print_debug(void)
               pr_info("EBBRR: %016lx BESCR: %016lx\n",
                       mfspr(SPRN_EBBRR), mfspr(SPRN_BESCR));
       }
+
+       if (ppmu->flags & PPMU_ARCH_310S) {
+               pr_info("MMCR3: %016lx SIER2: %016lx SIER3: %016lx\n",
+                       mfspr(SPRN_MMCR3), mfspr(SPRN_SIER2), mfspr(SPRN_SIER3));
+       }
 #endif
       pr_info("SIAR:  %016lx SDAR:  %016lx SIER:  %016lx\n",
               mfspr(SPRN_SIAR), sdar, sier);
@@ -1305,6 +1329,8 @@ static void power_pmu_enable(struct pmu *pmu)
       if (!cpuhw->n_added) {
               mtspr(SPRN_MMCRA, cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
               mtspr(SPRN_MMCR1, cpuhw->mmcr.mmcr1);
+               if (ppmu->flags & PPMU_ARCH_310S)
+                       mtspr(SPRN_MMCR3, cpuhw->mmcr.mmcr3);
               goto out_enable;
       }
 
@@ -1348,6 +1374,9 @@ static void power_pmu_enable(struct pmu *pmu)
       if (ppmu->flags & PPMU_ARCH_207S)
               mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2);
 
+       if (ppmu->flags & PPMU_ARCH_310S)
+               mtspr(SPRN_MMCR3, cpuhw->mmcr.mmcr3);
+
       /*
        * Read off any pre-existing events that need to move
        * to another PMC.
--

1.8.3.1

#16 lore raw

Re: [v3 04/15] powerpc/perf: Add support for ISA3.1 PMU SPRs

Quoted 178 lines · Athira Rajeev

On 22-Jul-2020, at 9:48 AM, Jordan Niethe <[email protected]> wrote:

On Sat, Jul 18, 2020 at 1:02 AM Athira Rajeev
<[email protected]> wrote:

From: Madhavan Srinivasan <[email protected]>

PowerISA v3.1 includes new performance monitoring unit(PMU) special purpose registers (SPRs). They are

Monitor Mode Control Register 3 (MMCR3)
Sampled Instruction Event Register 2 (SIER2)
Sampled Instruction Event Register 3 (SIER3)

MMCR3 is added for further sampling related configuration control. SIER2/SIER3 are added to provide additional information about the sampled instruction.

Patch adds new PPMU flag called "PPMU_ARCH_310S" to support handling of these new SPRs, updates the struct thread_struct to include these new SPRs, include MMCR3 in struct mmcr_regs. This is needed to support programming of MMCR3 SPR during event_[enable/disable]. Patch also adds the sysfs support for the MMCR3 SPR along with SPRN_ macros for these new pmu sprs.

---

arch/powerpc/include/asm/perf_event_server.h |  2 ++
arch/powerpc/include/asm/processor.h         |  4 ++++
arch/powerpc/include/asm/reg.h               |  6 ++++++
arch/powerpc/kernel/sysfs.c                  |  8 ++++++++
arch/powerpc/perf/core-book3s.c              | 29 ++++++++++++++++++++++++++++
5 files changed, 49 insertions(+)
arch/powerpc/include/asm/perf_event_server.h +2 -0
index 14b8dc1..832450a 100644
@@ -22,6 +22,7 @@ struct mmcr_regs {
       unsigned long mmcr1;
       unsigned long mmcr2;
       unsigned long mmcra;
+       unsigned long mmcr3;
 };
 /*
 * This struct provides the constants and functions needed to
@@ -75,6 +76,7 @@ struct power_pmu {
 #define PPMU_HAS_SIER          0x00000040 /* Has SIER */
 #define PPMU_ARCH_207S         0x00000080 /* PMC is architecture v2.07S */
 #define PPMU_NO_SIAR           0x00000100 /* Do not use SIAR */
+#define PPMU_ARCH_310S         0x00000200 /* Has MMCR3, SIER2 and SIER3 */
 

We elsewhere have CPU_FTR_ARCH_31, so should this be PPMU_ARCH_31S to be consistent.

Ok,
This change will need to be done in all places which are currently using PPMU_ARCH_310S

/*
* Values for flags to get_alternatives()

arch/powerpc/include/asm/processor.h +4 -0
index 52a6783..a466e94 100644
@@ -272,6 +272,10 @@ struct thread_struct {
       unsigned        mmcr0;
 
       unsigned        used_ebb;
+       unsigned long   mmcr3;
+       unsigned long   sier2;
+       unsigned long   sier3;
+
 #endif
 };
 
arch/powerpc/include/asm/reg.h +6 -0
index 88e6c78..21a1b2d 100644
@@ -876,7 +876,9 @@
 #define   MMCR0_FCHV   0x00000001UL /* freeze conditions in hypervisor mode */
 #define SPRN_MMCR1     798
 #define SPRN_MMCR2     785
+#define SPRN_MMCR3     754
 #define SPRN_UMMCR2    769
+#define SPRN_UMMCR3    738
 #define SPRN_MMCRA     0x312
 #define   MMCRA_SDSYNC 0x80000000UL /* SDAR synced with SIAR */
 #define   MMCRA_SDAR_DCACHE_MISS 0x40000000UL
@@ -918,6 +920,10 @@
 #define   SIER_SIHV            0x1000000       /* Sampled MSR_HV */
 #define   SIER_SIAR_VALID      0x0400000       /* SIAR contents valid */
 #define   SIER_SDAR_VALID      0x0200000       /* SDAR contents valid */
+#define SPRN_SIER2     752
+#define SPRN_SIER3     753
+#define SPRN_USIER2    736
+#define SPRN_USIER3    737
 #define SPRN_SIAR      796
 #define SPRN_SDAR      797
 #define SPRN_TACR      888
arch/powerpc/kernel/sysfs.c +8 -0
index 571b325..46b4ebc 100644
@@ -622,8 +622,10 @@ void ppc_enable_pmcs(void)
 SYSFS_PMCSETUP(pmc8, SPRN_PMC8);
 
 SYSFS_PMCSETUP(mmcra, SPRN_MMCRA);
+SYSFS_PMCSETUP(mmcr3, SPRN_MMCR3);
 
 static DEVICE_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
+static DEVICE_ATTR(mmcr3, 0600, show_mmcr3, store_mmcr3);
 #endif /* HAS_PPC_PMC56 */
 
 
@@ -886,6 +888,9 @@ static int register_cpu_online(unsigned int cpu)
 #ifdef CONFIG_PMU_SYSFS
       if (cpu_has_feature(CPU_FTR_MMCRA))
               device_create_file(s, &dev_attr_mmcra);
+
+       if (cpu_has_feature(CPU_FTR_ARCH_31))
+               device_create_file(s, &dev_attr_mmcr3);
 #endif /* CONFIG_PMU_SYSFS */
 
       if (cpu_has_feature(CPU_FTR_PURR)) {
@@ -980,6 +985,9 @@ static int unregister_cpu_online(unsigned int cpu)
 #ifdef CONFIG_PMU_SYSFS
       if (cpu_has_feature(CPU_FTR_MMCRA))
               device_remove_file(s, &dev_attr_mmcra);
+
+       if (cpu_has_feature(CPU_FTR_ARCH_31))
+               device_remove_file(s, &dev_attr_mmcr3);
 #endif /* CONFIG_PMU_SYSFS */
 
       if (cpu_has_feature(CPU_FTR_PURR)) {
arch/powerpc/perf/core-book3s.c +10 -0
index f4d07b5..ca32fc0 100644
@@ -72,6 +72,11 @@ struct cpu_hw_events {
 /*
 * 32-bit doesn't have MMCRA but does have an MMCR2,
 * and a few other names are different.
+ * Also 32-bit doesn't have MMCR3, SIER2 and SIER3.
+ * Define them as zero knowing that any code path accessing
+ * these registers (via mtspr/mfspr) are done under ppmu flag
+ * check for PPMU_ARCH_310S and we will not enter that code path
+ * for 32-bit.
 */
 #ifdef CONFIG_PPC32
 
@@ -85,6 +90,9 @@ struct cpu_hw_events {
 #define MMCR0_PMCC_U6          0
 
 #define SPRN_MMCRA             SPRN_MMCR2
+#define SPRN_MMCR3             0
+#define SPRN_SIER2             0
+#define SPRN_SIER3             0
 #define MMCRA_SAMPLE_ENABLE    0
 
 static inline unsigned long perf_ip_adjust(struct pt_regs *regs)
@@ -581,6 +589,11 @@ static void ebb_switch_out(unsigned long mmcr0)
       current->thread.sdar  = mfspr(SPRN_SDAR);
       current->thread.mmcr0 = mmcr0 & MMCR0_USER_MASK;
       current->thread.mmcr2 = mfspr(SPRN_MMCR2) & MMCR2_USER_MASK;
+       if (ppmu->flags & PPMU_ARCH_310S) {
+               current->thread.mmcr3 = mfspr(SPRN_MMCR3);
 

Like MMCR0_USER_MASK and MMCR2_USER_MASK do we need a MMCR3_USER_MASK here, or is there no need?

Quoted 3 lines

Jordan

We don’t need user mask for MMCR3 and other new SPRs ( SIER2/3) . Incase of MMCR3, we dont have any Freeze control bits and incase of SIER2/3, it is similar to SIER (where HW handles the masking of the bits), hence we didn't add any user_mask for these SPRs

Okay thank you for explaining that.

Quoted 58 lines

Thanks
Athira

arch/powerpc/perf/core-book3s.c +3 -0
+               current->thread.sier2 = mfspr(SPRN_SIER2);
+               current->thread.sier3 = mfspr(SPRN_SIER3);
+       }

}

static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)

arch/powerpc/perf/core-book3s.c +6 -0
@@ -620,6 +633,12 @@ static unsigned long ebb_switch_in(bool ebb, struct cpu_hw_events *cpuhw)
        * instead manage the MMCR2 entirely by itself.
        */
       mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2 | current->thread.mmcr2);
+
+       if (ppmu->flags & PPMU_ARCH_310S) {
+               mtspr(SPRN_MMCR3, current->thread.mmcr3);
+               mtspr(SPRN_SIER2, current->thread.sier2);
+               mtspr(SPRN_SIER3, current->thread.sier3);
+       }

out:

       return mmcr0;
}
arch/powerpc/perf/core-book3s.c +10 -1
@@ -840,6 +859,11 @@ void perf_event_print_debug(void)
               pr_info("EBBRR: %016lx BESCR: %016lx\n",
                       mfspr(SPRN_EBBRR), mfspr(SPRN_BESCR));
       }
+
+       if (ppmu->flags & PPMU_ARCH_310S) {
+               pr_info("MMCR3: %016lx SIER2: %016lx SIER3: %016lx\n",
+                       mfspr(SPRN_MMCR3), mfspr(SPRN_SIER2), mfspr(SPRN_SIER3));
+       }
 #endif
       pr_info("SIAR:  %016lx SDAR:  %016lx SIER:  %016lx\n",
               mfspr(SPRN_SIAR), sdar, sier);
@@ -1305,6 +1329,8 @@ static void power_pmu_enable(struct pmu *pmu)
       if (!cpuhw->n_added) {
               mtspr(SPRN_MMCRA, cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
               mtspr(SPRN_MMCR1, cpuhw->mmcr.mmcr1);
+               if (ppmu->flags & PPMU_ARCH_310S)
+                       mtspr(SPRN_MMCR3, cpuhw->mmcr.mmcr3);
               goto out_enable;
       }
 
@@ -1348,6 +1374,9 @@ static void power_pmu_enable(struct pmu *pmu)
       if (ppmu->flags & PPMU_ARCH_207S)
               mtspr(SPRN_MMCR2, cpuhw->mmcr.mmcr2);
 
+       if (ppmu->flags & PPMU_ARCH_310S)
+               mtspr(SPRN_MMCR3, cpuhw->mmcr.mmcr3);
+
       /*
        * Read off any pre-existing events that need to move
        * to another PMC.
--

1.8.3.1

#17 lore raw

Re: [v3 04/15] powerpc/perf: Add support for ISA3.1 PMU SPRs

In reply to Jordan Niethe
Quoted 5 lines · Jordan Niethe
Quoted 4 lines · Athira Rajeev

From: Madhavan Srinivasan <[email protected]>

PowerISA v3.1 includes new performance monitoring unit(PMU) special purpose registers (SPRs). They are

...

Quoted 13 lines

arch/powerpc/include/asm/perf_event_server.h struct power_pmu { · line 79

Quoted 10 lines
arch/powerpc/include/asm/perf_event_server.h +1 -0
index 14b8dc1..832450a 100644
@@ -75,6 +76,7 @@ struct power_pmu {
 #define PPMU_HAS_SIER          0x00000040 /* Has SIER */
 #define PPMU_ARCH_207S         0x00000080 /* PMC is architecture v2.07S */
 #define PPMU_NO_SIAR           0x00000100 /* Do not use SIAR */
+#define PPMU_ARCH_310S         0x00000200 /* Has MMCR3, SIER2 and SIER3 */

We elsewhere have CPU_FTR_ARCH_31, so should this be PPMU_ARCH_31S to be consistent.

The "S" is no longer needed as there's no Book S vs Book E distinction in ISA v3.1.

So I changed it to PPMU_ARCH_31.

Quoted 5 lines
Quoted 5 lines
arch/powerpc/perf/core-book3s.c +0 -0
index f4d07b5..ca32fc0 100644
@@ -581,6 +589,11 @@ static void ebb_switch_out(unsigned long mmcr0)
Quoted 8 lines

arch/powerpc/perf/core-book3s.c static void ebb_switch_out(unsigned long mmcr0) · line 593

Quoted 5 lines
arch/powerpc/perf/core-book3s.c +2 -0
        current->thread.sdar  = mfspr(SPRN_SDAR);
        current->thread.mmcr0 = mmcr0 & MMCR0_USER_MASK;
        current->thread.mmcr2 = mfspr(SPRN_MMCR2) & MMCR2_USER_MASK;
+       if (ppmu->flags & PPMU_ARCH_310S) {
+               current->thread.mmcr3 = mfspr(SPRN_MMCR3);

Like MMCR0_USER_MASK and MMCR2_USER_MASK do we need a MMCR3_USER_MASK here, or is there no need?

mmcr0 and mmcr2 are visible via ptrace, so masking them here means we don't expose any bits to userspace via ptrace that aren't also visible by reading the register.

So at least while mmcr3 is not exposed via ptrace it's safe to not mask it, if there are even any sensitive bits in it.

cheers

#18 lore raw

PATCH v3 5/15 KVM: PPC: Book3S HV: Save/restore new PMU registers

In reply to Athira Rajeev

PowerISA v3.1 has added new performance monitoring unit (PMU) special purpose registers (SPRs). They are

Monitor Mode Control Register 3 (MMCR3)
Sampled Instruction Event Register A (SIER2)
Sampled Instruction Event Register B (SIER3)

Patch addes support to save/restore these new
SPRs while entering/exiting guest. Also includes
changes to support KVM_REG_PPC_MMCR3/SIER2/SIER3.
And adds new SPRs to KVM API documentation.

---
 Documentation/virt/kvm/api.rst            |  3 +++
 arch/powerpc/include/asm/kvm_book3s_asm.h |  2 +-
 arch/powerpc/include/asm/kvm_host.h       |  4 ++--
 arch/powerpc/include/uapi/asm/kvm.h       |  5 +++++
 arch/powerpc/kernel/asm-offsets.c         |  3 +++
 arch/powerpc/kvm/book3s_hv.c              | 22 ++++++++++++++++++++--
 arch/powerpc/kvm/book3s_hv_interrupts.S   |  8 ++++++++
 arch/powerpc/kvm/book3s_hv_rmhandlers.S   | 24 ++++++++++++++++++++++++
 tools/arch/powerpc/include/uapi/asm/kvm.h |  5 +++++
 9 files changed, 71 insertions(+), 5 deletions(-)
Documentation/virt/kvm/api.rst +3 -0
index 426f945..8cb6eb7 100644
@@ -2156,9 +2156,12 @@ registers, find a list below:
   PPC     KVM_REG_PPC_MMCRA               64
   PPC     KVM_REG_PPC_MMCR2               64
   PPC     KVM_REG_PPC_MMCRS               64
+  PPC     KVM_REG_PPC_MMCR3               64
   PPC     KVM_REG_PPC_SIAR                64
   PPC     KVM_REG_PPC_SDAR                64
   PPC     KVM_REG_PPC_SIER                64
+  PPC     KVM_REG_PPC_SIER2               64
+  PPC     KVM_REG_PPC_SIER3               64
   PPC     KVM_REG_PPC_PMC1                32
   PPC     KVM_REG_PPC_PMC2                32
   PPC     KVM_REG_PPC_PMC3                32
arch/powerpc/include/asm/kvm_book3s_asm.h +1 -1
index 45704f2..078f464 100644
@@ -119,7 +119,7 @@ struct kvmppc_host_state {
 	void __iomem *xive_tima_virt;
 	u32 saved_xirr;
 	u64 dabr;
-	u64 host_mmcr[7];	/* MMCR 0,1,A, SIAR, SDAR, MMCR2, SIER */
+	u64 host_mmcr[10];	/* MMCR 0,1,A, SIAR, SDAR, MMCR2, SIER, MMCR3, SIER2/3 */
 	u32 host_pmc[8];
 	u64 host_purr;
 	u64 host_spurr;
arch/powerpc/include/asm/kvm_host.h +2 -2
index fc115e2..4f26623 100644
@@ -637,14 +637,14 @@ struct kvm_vcpu_arch {
 	u32 ccr1;
 	u32 dbsr;
 
-	u64 mmcr[3];
+	u64 mmcr[4];
 	u64 mmcra;
 	u64 mmcrs;
 	u32 pmc[8];
 	u32 spmc[2];
 	u64 siar;
 	u64 sdar;
-	u64 sier;
+	u64 sier[3];
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
 	u64 tfhar;
 	u64 texasr;
arch/powerpc/include/uapi/asm/kvm.h +5 -0
index e55d847..1cc779d 100644
@@ -640,6 +640,11 @@ struct kvm_ppc_cpu_char {
 #define KVM_REG_PPC_ONLINE	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xbf)
 #define KVM_REG_PPC_PTCR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc0)
 
+/* POWER10 registers */
+#define KVM_REG_PPC_MMCR3	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc1)
+#define KVM_REG_PPC_SIER2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc2)
+#define KVM_REG_PPC_SIER3	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc3)
+
 /* Transactional Memory checkpointed state:
  * This is all GPRs, all VSX regs and a subset of SPRs
  */
arch/powerpc/kernel/asm-offsets.c +3 -0
index 6fa4853..8711c21 100644
@@ -698,6 +698,9 @@ int main(void)
 	HSTATE_FIELD(HSTATE_SDAR, host_mmcr[4]);
 	HSTATE_FIELD(HSTATE_MMCR2, host_mmcr[5]);
 	HSTATE_FIELD(HSTATE_SIER, host_mmcr[6]);
+	HSTATE_FIELD(HSTATE_MMCR3, host_mmcr[7]);
+	HSTATE_FIELD(HSTATE_SIER2, host_mmcr[8]);
+	HSTATE_FIELD(HSTATE_SIER3, host_mmcr[9]);
 	HSTATE_FIELD(HSTATE_PMC1, host_pmc[0]);
 	HSTATE_FIELD(HSTATE_PMC2, host_pmc[1]);
 	HSTATE_FIELD(HSTATE_PMC3, host_pmc[2]);
arch/powerpc/kvm/book3s_hv.c +20 -2
index 3f90eee..d650d31 100644
@@ -1689,6 +1689,9 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	case KVM_REG_PPC_MMCRS:
 		*val = get_reg_val(id, vcpu->arch.mmcrs);
 		break;
+	case KVM_REG_PPC_MMCR3:
+		*val = get_reg_val(id, vcpu->arch.mmcr[3]);
+		break;
 	case KVM_REG_PPC_PMC1 ... KVM_REG_PPC_PMC8:
 		i = id - KVM_REG_PPC_PMC1;
 		*val = get_reg_val(id, vcpu->arch.pmc[i]);
@@ -1704,7 +1707,13 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 		*val = get_reg_val(id, vcpu->arch.sdar);
 		break;
 	case KVM_REG_PPC_SIER:
-		*val = get_reg_val(id, vcpu->arch.sier);
+		*val = get_reg_val(id, vcpu->arch.sier[0]);
+		break;
+	case KVM_REG_PPC_SIER2:
+		*val = get_reg_val(id, vcpu->arch.sier[1]);
+		break;
+	case KVM_REG_PPC_SIER3:
+		*val = get_reg_val(id, vcpu->arch.sier[2]);
 		break;
 	case KVM_REG_PPC_IAMR:
 		*val = get_reg_val(id, vcpu->arch.iamr);
@@ -1916,6 +1925,9 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	case KVM_REG_PPC_MMCRS:
 		vcpu->arch.mmcrs = set_reg_val(id, *val);
 		break;
+	case KVM_REG_PPC_MMCR3:
+		*val = get_reg_val(id, vcpu->arch.mmcr[3]);
+		break;
 	case KVM_REG_PPC_PMC1 ... KVM_REG_PPC_PMC8:
 		i = id - KVM_REG_PPC_PMC1;
 		vcpu->arch.pmc[i] = set_reg_val(id, *val);
@@ -1931,7 +1943,13 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 		vcpu->arch.sdar = set_reg_val(id, *val);
 		break;
 	case KVM_REG_PPC_SIER:
-		vcpu->arch.sier = set_reg_val(id, *val);
+		vcpu->arch.sier[0] = set_reg_val(id, *val);
+		break;
+	case KVM_REG_PPC_SIER2:
+		vcpu->arch.sier[1] = set_reg_val(id, *val);
+		break;
+	case KVM_REG_PPC_SIER3:
+		vcpu->arch.sier[2] = set_reg_val(id, *val);
 		break;
 	case KVM_REG_PPC_IAMR:
 		vcpu->arch.iamr = set_reg_val(id, *val);
arch/powerpc/kvm/book3s_hv_interrupts.S +8 -0
index 63fd81f..59822cb 100644
@@ -140,6 +140,14 @@ BEGIN_FTR_SECTION
 	std	r8, HSTATE_MMCR2(r13)
 	std	r9, HSTATE_SIER(r13)
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
+BEGIN_FTR_SECTION
+	mfspr	r5, SPRN_MMCR3
+	mfspr	r6, SPRN_SIER2
+	mfspr	r7, SPRN_SIER3
+	std	r5, HSTATE_MMCR3(r13)
+	std	r6, HSTATE_SIER2(r13)
+	std	r7, HSTATE_SIER3(r13)
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_31)
 	mfspr	r3, SPRN_PMC1
 	mfspr	r5, SPRN_PMC2
 	mfspr	r6, SPRN_PMC3
arch/powerpc/kvm/book3s_hv_rmhandlers.S +24 -0
index 702eaa2..799d6d0 100644
@@ -3436,6 +3436,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_PMAO_BUG)
 	mtspr	SPRN_SIAR, r7
 	mtspr	SPRN_SDAR, r8
 BEGIN_FTR_SECTION
+	ld      r5, VCPU_MMCR + 24(r4)
+	ld      r6, VCPU_SIER + 8(r4)
+	ld      r7, VCPU_SIER + 16(r4)
+	mtspr   SPRN_MMCR3, r5
+	mtspr   SPRN_SIER2, r6
+	mtspr   SPRN_SIER3, r7
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_31)
+BEGIN_FTR_SECTION
 	ld	r5, VCPU_MMCR + 16(r4)
 	ld	r6, VCPU_SIER(r4)
 	mtspr	SPRN_MMCR2, r5
@@ -3496,6 +3504,14 @@ BEGIN_FTR_SECTION
 	mtspr	SPRN_MMCR2, r8
 	mtspr	SPRN_SIER, r9
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
+BEGIN_FTR_SECTION
+	ld      r5, HSTATE_MMCR3(r13)
+	ld      r6, HSTATE_SIER2(r13)
+	ld      r7, HSTATE_SIER3(r13)
+	mtspr   SPRN_MMCR3, r5
+	mtspr   SPRN_SIER2, r6
+	mtspr   SPRN_SIER3, r7
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_31)
 	mtspr	SPRN_MMCR0, r3
 	isync
 	mtlr	r0
@@ -3555,6 +3571,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 BEGIN_FTR_SECTION
 	std	r10, VCPU_MMCR + 16(r9)
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
+BEGIN_FTR_SECTION
+	mfspr   r5, SPRN_MMCR3
+	mfspr   r6, SPRN_SIER2
+	mfspr   r7, SPRN_SIER3
+	std     r5, VCPU_MMCR + 24(r9)
+	std     r6, VCPU_SIER + 8(r9)
+	std     r7, VCPU_SIER + 16(r9)
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_31)
 	std	r7, VCPU_SIAR(r9)
 	std	r8, VCPU_SDAR(r9)
 	mfspr	r3, SPRN_PMC1
tools/arch/powerpc/include/uapi/asm/kvm.h +5 -0
index e55d847..1cc779d 100644
@@ -640,6 +640,11 @@ struct kvm_ppc_cpu_char {
 #define KVM_REG_PPC_ONLINE	(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xbf)
 #define KVM_REG_PPC_PTCR	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc0)
 
+/* POWER10 registers */
+#define KVM_REG_PPC_MMCR3	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc1)
+#define KVM_REG_PPC_SIER2	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc2)
+#define KVM_REG_PPC_SIER3	(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc3)
+
 /* Transactional Memory checkpointed state:
  * This is all GPRs, all VSX regs and a subset of SPRs
  */
Signature · 1 line
1.8.3.1
#19 lore raw

PATCH v3 6/15 powerpc/xmon: Add PowerISA v3.1 PMU SPRs

In reply to Athira Rajeev

From: Madhavan Srinivasan <[email protected]>

PowerISA v3.1 added three new perfromance monitoring unit (PMU) speical purpose register (SPR). They are Monitor Mode Control Register 3 (MMCR3), Sampled Instruction Event Register 2 (SIER2), Sampled Instruction Event Register 3 (SIER3).

Patch here adds a new dump function dump_310_sprs to print these SPR values.

---
 arch/powerpc/xmon/xmon.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/powerpc/xmon/xmon.c +13 -0
index 7efe4bc..16f5493 100644
@@ -2022,6 +2022,18 @@ static void dump_300_sprs(void)
 #endif
 }
 
+static void dump_310_sprs(void)
+{
+#ifdef CONFIG_PPC64
+	if (!cpu_has_feature(CPU_FTR_ARCH_31))
+		return;
+
+	printf("mmcr3  = %.16lx, sier2  = %.16lx, sier3  = %.16lx\n",
+		mfspr(SPRN_MMCR3), mfspr(SPRN_SIER2), mfspr(SPRN_SIER3));
+
+#endif
+}
+
 static void dump_one_spr(int spr, bool show_unimplemented)
 {
 	unsigned long val;
@@ -2076,6 +2088,7 @@ static void super_regs(void)
 		dump_206_sprs();
 		dump_207_sprs();
 		dump_300_sprs();
+		dump_310_sprs();
 
 		return;
 	}
Signature · 1 line
1.8.3.1
#20 lore raw

PATCH v3 7/15 powerpc/perf: Add power10_feat to dt_cpu_ftrs

In reply to Athira Rajeev

From: Madhavan Srinivasan <[email protected]>

Add power10 feature function to dt_cpu_ftrs.c along with a power10 specific init() to initialize pmu sprs, sets the oprofile_cpu_type and cpu_features. This will enable performance monitoring unit(PMU) for Power10 in CPU features with "performance-monitor-power10".

For PowerISA v3.1, BHRB disable is controlled via Monitor Mode Control Register A (MMCRA) bit, namely "BHRB Recording Disable (BHRBRD)". This patch initializes MMCRA BHRBRD to disable BHRB feature at boot for power10.

---
 arch/powerpc/include/asm/reg.h        |  3 +++
 arch/powerpc/kernel/cpu_setup_power.S |  8 ++++++++
 arch/powerpc/kernel/dt_cpu_ftrs.c     | 26 ++++++++++++++++++++++++++
 3 files changed, 37 insertions(+)
arch/powerpc/include/asm/reg.h +3 -0
index 21a1b2d..900ada1 100644
@@ -1068,6 +1068,9 @@
 #define MMCR0_PMC2_LOADMISSTIME	0x5
 #endif
 
+/* BHRB disable bit for PowerISA v3.10 */
+#define MMCRA_BHRB_DISABLE	0x0000002000000000
+
 /*
  * SPRG usage:
  *
arch/powerpc/kernel/cpu_setup_power.S +8 -0
index efdcfa7..b8e0d1e 100644
@@ -94,6 +94,7 @@ _GLOBAL(__restore_cpu_power8)
 _GLOBAL(__setup_cpu_power10)
 	mflr	r11
 	bl	__init_FSCR_power10
+	bl	__init_PMU_ISA31
 	b	1f
 
 _GLOBAL(__setup_cpu_power9)
@@ -233,3 +234,10 @@ __init_PMU_ISA207:
 	li	r5,0
 	mtspr	SPRN_MMCRS,r5
 	blr
+
+__init_PMU_ISA31:
+	li	r5,0
+	mtspr	SPRN_MMCR3,r5
+	LOAD_REG_IMMEDIATE(r5, MMCRA_BHRB_DISABLE)
+	mtspr	SPRN_MMCRA,r5
+	blr
arch/powerpc/kernel/dt_cpu_ftrs.c +26 -0
index 3a40951..f482286 100644
@@ -450,6 +450,31 @@ static int __init feat_enable_pmu_power9(struct dt_cpu_feature *f)
 	return 1;
 }
 
+static void init_pmu_power10(void)
+{
+	init_pmu_power9();
+
+	mtspr(SPRN_MMCR3, 0);
+	mtspr(SPRN_MMCRA, MMCRA_BHRB_DISABLE);
+}
+
+static int __init feat_enable_pmu_power10(struct dt_cpu_feature *f)
+{
+	hfscr_pmu_enable();
+
+	init_pmu_power10();
+	init_pmu_registers = init_pmu_power10;
+
+	cur_cpu_spec->cpu_features |= CPU_FTR_MMCRA;
+	cur_cpu_spec->cpu_user_features |= PPC_FEATURE_PSERIES_PERFMON_COMPAT;
+
+	cur_cpu_spec->num_pmcs          = 6;
+	cur_cpu_spec->pmc_type          = PPC_PMC_IBM;
+	cur_cpu_spec->oprofile_cpu_type = "ppc64/power10";
+
+	return 1;
+}
+
 static int __init feat_enable_tm(struct dt_cpu_feature *f)
 {
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
@@ -639,6 +664,7 @@ struct dt_cpu_feature_match {
 	{"pc-relative-addressing", feat_enable, 0},
 	{"machine-check-power9", feat_enable_mce_power9, 0},
 	{"performance-monitor-power9", feat_enable_pmu_power9, 0},
+	{"performance-monitor-power10", feat_enable_pmu_power10, 0},
 	{"event-based-branch-v3", feat_enable, 0},
 	{"random-number-generator", feat_enable, 0},
 	{"system-call-vectored", feat_disable, 0},
Signature · 1 line
1.8.3.1
#21 lore raw

Re: [v3 07/15] powerpc/perf: Add power10_feat to dt_cpu_ftrs

Quoted 26 lines · Athira Rajeev

From: Madhavan Srinivasan <[email protected]>

Add power10 feature function to dt_cpu_ftrs.c along with a power10 specific init() to initialize pmu sprs, sets the oprofile_cpu_type and cpu_features. This will enable performance monitoring unit(PMU) for Power10 in CPU features with "performance-monitor-power10".

For PowerISA v3.1, BHRB disable is controlled via Monitor Mode Control Register A (MMCRA) bit, namely "BHRB Recording Disable (BHRBRD)". This patch initializes MMCRA BHRBRD to disable BHRB feature at boot for power10.

---
 arch/powerpc/include/asm/reg.h        |  3 +++
 arch/powerpc/kernel/cpu_setup_power.S |  8 ++++++++
 arch/powerpc/kernel/dt_cpu_ftrs.c     | 26 ++++++++++++++++++++++++++
 3 files changed, 37 insertions(+)
arch/powerpc/include/asm/reg.h +0 -0
index 21a1b2d..900ada1 100644

arch/powerpc/include/asm/reg.h line 1072

Quoted 5 lines
arch/powerpc/include/asm/reg.h +2 -0
@@ -1068,6 +1068,9 @@
 #define MMCR0_PMC2_LOADMISSTIME        0x5
 #endif
 
+/* BHRB disable bit for PowerISA v3.10 */
+#define MMCRA_BHRB_DISABLE     0x0000002000000000

Shouldn't this go under SPRN_MMCRA with the other MMCRA_*.

arch/powerpc/kernel/cpu_setup_power.S _GLOBAL(__restore_cpu_power8) · line 97

Quoted 13 lines
arch/powerpc/include/asm/reg.h +1 -0
+
 /*
  * SPRG usage:
  *
arch/powerpc/kernel/cpu_setup_power.S +1 -0
index efdcfa7..b8e0d1e 100644
@@ -94,6 +94,7 @@ _GLOBAL(__restore_cpu_power8)
 _GLOBAL(__setup_cpu_power10)
        mflr    r11
        bl      __init_FSCR_power10
+       bl      __init_PMU_ISA31

So we set MMCRA here but then aren't we still going to call __init_PMU which will overwrite that?
Would this setting MMCRA also need to be handled in __restore_cpu_power10?

Quoted 61 lines
arch/powerpc/kernel/cpu_setup_power.S +7 -0
        b       1f
 
 _GLOBAL(__setup_cpu_power9)
@@ -233,3 +234,10 @@ __init_PMU_ISA207:
        li      r5,0
        mtspr   SPRN_MMCRS,r5
        blr
+
+__init_PMU_ISA31:
+       li      r5,0
+       mtspr   SPRN_MMCR3,r5
+       LOAD_REG_IMMEDIATE(r5, MMCRA_BHRB_DISABLE)
+       mtspr   SPRN_MMCRA,r5
+       blr
arch/powerpc/kernel/dt_cpu_ftrs.c +26 -1
index 3a40951..f482286 100644
@@ -450,6 +450,31 @@ static int __init feat_enable_pmu_power9(struct dt_cpu_feature *f)
        return 1;
 }
 
+static void init_pmu_power10(void)
+{
+       init_pmu_power9();
+
+       mtspr(SPRN_MMCR3, 0);
+       mtspr(SPRN_MMCRA, MMCRA_BHRB_DISABLE);
+}
+
+static int __init feat_enable_pmu_power10(struct dt_cpu_feature *f)
+{
+       hfscr_pmu_enable();
+
+       init_pmu_power10();
+       init_pmu_registers = init_pmu_power10;
+
+       cur_cpu_spec->cpu_features |= CPU_FTR_MMCRA;
+       cur_cpu_spec->cpu_user_features |= PPC_FEATURE_PSERIES_PERFMON_COMPAT;
+
+       cur_cpu_spec->num_pmcs          = 6;
+       cur_cpu_spec->pmc_type          = PPC_PMC_IBM;
+       cur_cpu_spec->oprofile_cpu_type = "ppc64/power10";
+
+       return 1;
+}
+
 static int __init feat_enable_tm(struct dt_cpu_feature *f)
 {
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
@@ -639,6 +664,7 @@ struct dt_cpu_feature_match {
        {"pc-relative-addressing", feat_enable, 0},
        {"machine-check-power9", feat_enable_mce_power9, 0},
        {"performance-monitor-power9", feat_enable_pmu_power9, 0},
+       {"performance-monitor-power10", feat_enable_pmu_power10, 0},
        {"event-based-branch-v3", feat_enable, 0},
        {"random-number-generator", feat_enable, 0},
        {"system-call-vectored", feat_disable, 0},
--

1.8.3.1

#22 lore raw

Re: [v3 07/15] powerpc/perf: Add power10_feat to dt_cpu_ftrs

Quoted 35 lines · Jordan Niethe
Quoted 29 lines · On Sat, Jul 18, 2020 at 1:13 AM Athira Rajeev <[email protected]…

From: Madhavan Srinivasan <[email protected]>

Add power10 feature function to dt_cpu_ftrs.c along with a power10 specific init() to initialize pmu sprs, sets the oprofile_cpu_type and cpu_features. This will enable performance monitoring unit(PMU) for Power10 in CPU features with "performance-monitor-power10".

For PowerISA v3.1, BHRB disable is controlled via Monitor Mode Control Register A (MMCRA) bit, namely "BHRB Recording Disable (BHRBRD)". This patch initializes MMCRA BHRBRD to disable BHRB feature at boot for power10.

---

arch/powerpc/include/asm/reg.h        |  3 +++
arch/powerpc/kernel/cpu_setup_power.S |  8 ++++++++
arch/powerpc/kernel/dt_cpu_ftrs.c     | 26 ++++++++++++++++++++++++++
3 files changed, 37 insertions(+)
arch/powerpc/include/asm/reg.h +0 -0
index 21a1b2d..900ada1 100644
@@ -1068,6 +1068,9 @@
 #define MMCR0_PMC2_LOADMISSTIME        0x5
 #endif
 
Quoted 3 lines

arch/powerpc/include/asm/reg.h line 1072

Quoted 2 lines
arch/powerpc/include/asm/reg.h +2 -0
+/* BHRB disable bit for PowerISA v3.10 */
+#define MMCRA_BHRB_DISABLE     0x0000002000000000

Shouldn't this go under SPRN_MMCRA with the other MMCRA_*.

Hi Jordan

Ok, the definition of MMCRA is under #ifdef for 64 bit . if I move definition of MMCRA_BHRB_DISABLE along with other SPR's, I also need to define this for 32-bit to satisfy core-book3s to compile as below:

arch/powerpc/include/asm/reg.h +2 -3
index 900ada10762c..7e271657b412 100644
@@ -888,6 +888,8 @@
 #define   MMCRA_SLOT   0x07000000UL /* SLOT bits (37-39) */
 #define   MMCRA_SLOT_SHIFT     24
 #define   MMCRA_SAMPLE_ENABLE 0x00000001UL /* enable sampling */
+/* BHRB disable bit for PowerISA v3.10 */
+#define   MMCRA_BHRB_DISABLE  0x0000002000000000
 #define   POWER6_MMCRA_SDSYNC 0x0000080000000000ULL    /* SDAR/SIAR synced */
 #define   POWER6_MMCRA_SIHV   0x0000040000000000ULL
 #define   POWER6_MMCRA_SIPR   0x0000020000000000ULL
@@ -1068,9 +1070,6 @@
 #define MMCR0_PMC2_LOADMISSTIME        0x5
 #endif
 
-/* BHRB disable bit for PowerISA v3.10 */
-#define MMCRA_BHRB_DISABLE     0x0000002000000000
-
 /*
  * SPRG usage:
  *
arch/powerpc/perf/core-book3s.c +1 -0
index 36baae666387..88068f20827c 100644
@@ -94,6 +94,7 @@ static unsigned int freeze_events_kernel = MMCR0_FCS;
 #define SPRN_SIER2             0
 #define SPRN_SIER3             0
 #define MMCRA_SAMPLE_ENABLE    0
+#define MMCRA_BHRB_DISABLE     0
 
 static inline unsigned long perf_ip_adjust(struct pt_regs *regs)
 {
Quoted 8 lines
Quoted 8 lines
arch/powerpc/include/asm/reg.h +1 -0
+
 /*
 * SPRG usage:
 *
arch/powerpc/kernel/cpu_setup_power.S +0 -0
index efdcfa7..b8e0d1e 100644
Quoted 8 lines

arch/powerpc/kernel/cpu_setup_power.S _GLOBAL(__restore_cpu_power8) · line 97

Quoted 5 lines
arch/powerpc/kernel/cpu_setup_power.S +1 -0
@@ -94,6 +94,7 @@ _GLOBAL(__restore_cpu_power8)
 _GLOBAL(__setup_cpu_power10)
       mflr    r11
       bl      __init_FSCR_power10
+       bl      __init_PMU_ISA31

So we set MMCRA here but then aren't we still going to call __init_PMU which will overwrite that?
Would this setting MMCRA also need to be handled in __restore_cpu_power10?

Thanks for this nice catch ! When I rebased code initial phase, we didn’t had power10 part filled in. It was a miss from my side in adding PMu init functions and thanks for pointing this out. Below patch will call __init_PMU functions in setup and restore. Please check if this looks good

--

arch/powerpc/kernel/cpu_setup_power.S +13 -0
index efdcfa714106..e672a6c5fd7c 100644
@@ -94,6 +94,9 @@ _GLOBAL(__restore_cpu_power8)
 _GLOBAL(__setup_cpu_power10)
 	mflr	r11
 	bl	__init_FSCR_power10
+	bl	__init_PMU
+	bl	__init_PMU_ISA31
+	bl	__init_PMU_HV
 	b	1f
 
 _GLOBAL(__setup_cpu_power9)
@@ -124,6 +127,9 @@ _GLOBAL(__setup_cpu_power9)
 _GLOBAL(__restore_cpu_power10)
 	mflr	r11
 	bl	__init_FSCR_power10
+	bl	__init_PMU
+	bl	__init_PMU_ISA31
+	bl	__init_PMU_HV
 	b	1f
 
 _GLOBAL(__restore_cpu_power9)
@@ -233,3 +239,10 @@ __init_PMU_ISA207:
 	li	r5,0
 	mtspr	SPRN_MMCRS,r5
 	blr
+
+__init_PMU_ISA31:
+	li	r5,0
+	mtspr	SPRN_MMCR3,r5
+	LOAD_REG_IMMEDIATE(r5, MMCRA_BHRB_DISABLE)
+	mtspr	SPRN_MMCRA,r5
+	blr

—

Quoted 60 lines
Quoted 60 lines
arch/powerpc/kernel/cpu_setup_power.S +7 -0
       b       1f
 
 _GLOBAL(__setup_cpu_power9)
@@ -233,3 +234,10 @@ __init_PMU_ISA207:
       li      r5,0
       mtspr   SPRN_MMCRS,r5
       blr
+
+__init_PMU_ISA31:
+       li      r5,0
+       mtspr   SPRN_MMCR3,r5
+       LOAD_REG_IMMEDIATE(r5, MMCRA_BHRB_DISABLE)
+       mtspr   SPRN_MMCRA,r5
+       blr
arch/powerpc/kernel/dt_cpu_ftrs.c +26 -1
index 3a40951..f482286 100644
@@ -450,6 +450,31 @@ static int __init feat_enable_pmu_power9(struct dt_cpu_feature *f)
       return 1;
 }
 
+static void init_pmu_power10(void)
+{
+       init_pmu_power9();
+
+       mtspr(SPRN_MMCR3, 0);
+       mtspr(SPRN_MMCRA, MMCRA_BHRB_DISABLE);
+}
+
+static int __init feat_enable_pmu_power10(struct dt_cpu_feature *f)
+{
+       hfscr_pmu_enable();
+
+       init_pmu_power10();
+       init_pmu_registers = init_pmu_power10;
+
+       cur_cpu_spec->cpu_features |= CPU_FTR_MMCRA;
+       cur_cpu_spec->cpu_user_features |= PPC_FEATURE_PSERIES_PERFMON_COMPAT;
+
+       cur_cpu_spec->num_pmcs          = 6;
+       cur_cpu_spec->pmc_type          = PPC_PMC_IBM;
+       cur_cpu_spec->oprofile_cpu_type = "ppc64/power10";
+
+       return 1;
+}
+
 static int __init feat_enable_tm(struct dt_cpu_feature *f)
 {
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
@@ -639,6 +664,7 @@ struct dt_cpu_feature_match {
       {"pc-relative-addressing", feat_enable, 0},
       {"machine-check-power9", feat_enable_mce_power9, 0},
       {"performance-monitor-power9", feat_enable_pmu_power9, 0},
+       {"performance-monitor-power10", feat_enable_pmu_power10, 0},
       {"event-based-branch-v3", feat_enable, 0},
       {"random-number-generator", feat_enable, 0},
       {"system-call-vectored", feat_disable, 0},
--

1.8.3.1

#23 lore raw

Re: [v3 07/15] powerpc/perf: Add power10_feat to dt_cpu_ftrs

Quoted 48 lines · Athira Rajeev
Quoted 33 lines · Jordan Niethe
Quoted 29 lines · On Sat, Jul 18, 2020 at 1:13 AM Athira Rajeev <[email protected]…

From: Madhavan Srinivasan <[email protected]>

Add power10 feature function to dt_cpu_ftrs.c along with a power10 specific init() to initialize pmu sprs, sets the oprofile_cpu_type and cpu_features. This will enable performance monitoring unit(PMU) for Power10 in CPU features with "performance-monitor-power10".

For PowerISA v3.1, BHRB disable is controlled via Monitor Mode Control Register A (MMCRA) bit, namely "BHRB Recording Disable (BHRBRD)". This patch initializes MMCRA BHRBRD to disable BHRB feature at boot for power10.

---

arch/powerpc/include/asm/reg.h        |  3 +++
arch/powerpc/kernel/cpu_setup_power.S |  8 ++++++++
arch/powerpc/kernel/dt_cpu_ftrs.c     | 26 ++++++++++++++++++++++++++
3 files changed, 37 insertions(+)
arch/powerpc/include/asm/reg.h +0 -0
index 21a1b2d..900ada1 100644
@@ -1068,6 +1068,9 @@
 #define MMCR0_PMC2_LOADMISSTIME        0x5
 #endif
 
Quoted 3 lines

arch/powerpc/include/asm/reg.h line 892

Quoted 2 lines
arch/powerpc/include/asm/reg.h +2 -0
+/* BHRB disable bit for PowerISA v3.10 */
+#define MMCRA_BHRB_DISABLE     0x0000002000000000

Shouldn't this go under SPRN_MMCRA with the other MMCRA_*.

Hi Jordan

Ok, the definition of MMCRA is under #ifdef for 64 bit . if I move definition of MMCRA_BHRB_DISABLE along with other SPR's, I also need to define this for 32-bit to satisfy core-book3s to compile as below:

arch/powerpc/include/asm/reg.h +0 -0
index 900ada10762c..7e271657b412 100644

arch/powerpc/include/asm/reg.h line 892

Quoted 5 lines
arch/powerpc/include/asm/reg.h +2 -0
@@ -888,6 +888,8 @@
 #define   MMCRA_SLOT   0x07000000UL /* SLOT bits (37-39) */
 #define   MMCRA_SLOT_SHIFT     24
 #define   MMCRA_SAMPLE_ENABLE 0x00000001UL /* enable sampling */
+/* BHRB disable bit for PowerISA v3.10 */
+#define   MMCRA_BHRB_DISABLE  0x0000002000000000

I changed it to:

#define MMCRA_BHRB_DISABLE 0x2000000000UL // BHRB disable bit for ISA v3.1

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
arch/powerpc/kernel/cpu_setup_power.S +0 -0
index efdcfa7..b8e0d1e 100644
Quoted 8 lines

arch/powerpc/kernel/cpu_setup_power.S _GLOBAL(__restore_cpu_power8) · line 97

Quoted 5 lines
arch/powerpc/kernel/cpu_setup_power.S +1 -0
@@ -94,6 +94,7 @@ _GLOBAL(__restore_cpu_power8)
 _GLOBAL(__setup_cpu_power10)
       mflr    r11
       bl      __init_FSCR_power10
+       bl      __init_PMU_ISA31

So we set MMCRA here but then aren't we still going to call __init_PMU which will overwrite that?
Would this setting MMCRA also need to be handled in __restore_cpu_power10?

Quoted 3 lines

Thanks for this nice catch ! When I rebased code initial phase, we didn’t had power10 part filled in. It was a miss from my side in adding PMu init functions and thanks for pointing this out. Below patch will call __init_PMU functions in setup and restore. Please check if this looks good

Actually those changes should be in a separate patch.

This one is wiring up DT CPU features, the cpu setup routines are not used by DT CPU features.

So please send a new patch I can insert into the series that adds the cpu_setup_power.S changes.

cheers

Quoted 37 lines

--

arch/powerpc/kernel/cpu_setup_power.S +13 -0
index efdcfa714106..e672a6c5fd7c 100644
@@ -94,6 +94,9 @@ _GLOBAL(__restore_cpu_power8)
 _GLOBAL(__setup_cpu_power10)
 	mflr	r11
 	bl	__init_FSCR_power10
+	bl	__init_PMU
+	bl	__init_PMU_ISA31
+	bl	__init_PMU_HV
 	b	1f
 
 _GLOBAL(__setup_cpu_power9)
@@ -124,6 +127,9 @@ _GLOBAL(__setup_cpu_power9)
 _GLOBAL(__restore_cpu_power10)
 	mflr	r11
 	bl	__init_FSCR_power10
+	bl	__init_PMU
+	bl	__init_PMU_ISA31
+	bl	__init_PMU_HV
 	b	1f
 
 _GLOBAL(__restore_cpu_power9)
@@ -233,3 +239,10 @@ __init_PMU_ISA207:
 	li	r5,0
 	mtspr	SPRN_MMCRS,r5
 	blr
+
+__init_PMU_ISA31:
+	li	r5,0
+	mtspr	SPRN_MMCR3,r5
+	LOAD_REG_IMMEDIATE(r5, MMCRA_BHRB_DISABLE)
+	mtspr	SPRN_MMCRA,r5
+	blr
#24 lore raw

Re: [v3 07/15] powerpc/perf: Add power10_feat to dt_cpu_ftrs

In reply to Athira Rajeev
Quoted 120 lines · Athira Rajeev

On 22-Jul-2020, at 10:11 AM, Jordan Niethe <[email protected]> wrote:

On Sat, Jul 18, 2020 at 1:13 AM Athira Rajeev
<[email protected]> wrote:

From: Madhavan Srinivasan <[email protected]>

Add power10 feature function to dt_cpu_ftrs.c along with a power10 specific init() to initialize pmu sprs, sets the oprofile_cpu_type and cpu_features. This will enable performance monitoring unit(PMU) for Power10 in CPU features with "performance-monitor-power10".

For PowerISA v3.1, BHRB disable is controlled via Monitor Mode Control Register A (MMCRA) bit, namely "BHRB Recording Disable (BHRBRD)". This patch initializes MMCRA BHRBRD to disable BHRB feature at boot for power10.

---

arch/powerpc/include/asm/reg.h        |  3 +++
arch/powerpc/kernel/cpu_setup_power.S |  8 ++++++++
arch/powerpc/kernel/dt_cpu_ftrs.c     | 26 ++++++++++++++++++++++++++
3 files changed, 37 insertions(+)
arch/powerpc/include/asm/reg.h +2 -0
index 21a1b2d..900ada1 100644
@@ -1068,6 +1068,9 @@
 #define MMCR0_PMC2_LOADMISSTIME        0x5
 #endif
 
+/* BHRB disable bit for PowerISA v3.10 */
+#define MMCRA_BHRB_DISABLE     0x0000002000000000
 

Shouldn't this go under SPRN_MMCRA with the other MMCRA_*.

Hi Jordan

Ok, the definition of MMCRA is under #ifdef for 64 bit . if I move definition of MMCRA_BHRB_DISABLE along with other SPR's, I also need to define this for 32-bit to satisfy core-book3s to compile as below:

arch/powerpc/include/asm/reg.h +2 -3
index 900ada10762c..7e271657b412 100644
@@ -888,6 +888,8 @@
 #define   MMCRA_SLOT   0x07000000UL /* SLOT bits (37-39) */
 #define   MMCRA_SLOT_SHIFT     24
 #define   MMCRA_SAMPLE_ENABLE 0x00000001UL /* enable sampling */
+/* BHRB disable bit for PowerISA v3.10 */
+#define   MMCRA_BHRB_DISABLE  0x0000002000000000
 #define   POWER6_MMCRA_SDSYNC 0x0000080000000000ULL    /* SDAR/SIAR synced */
 #define   POWER6_MMCRA_SIHV   0x0000040000000000ULL
 #define   POWER6_MMCRA_SIPR   0x0000020000000000ULL
@@ -1068,9 +1070,6 @@
 #define MMCR0_PMC2_LOADMISSTIME        0x5
 #endif
 
 
 
-/* BHRB disable bit for PowerISA v3.10 */
-#define MMCRA_BHRB_DISABLE     0x0000002000000000
-
 /*

* SPRG usage:
*

arch/powerpc/perf/core-book3s.c +1 -0
index 36baae666387..88068f20827c 100644
@@ -94,6 +94,7 @@ static unsigned int freeze_events_kernel = MMCR0_FCS;
 #define SPRN_SIER2             0
 #define SPRN_SIER3             0
 #define MMCRA_SAMPLE_ENABLE    0
+#define MMCRA_BHRB_DISABLE     0
 
 
 

static inline unsigned long perf_ip_adjust(struct pt_regs *regs) {

+
/*
* SPRG usage:
*

arch/powerpc/kernel/cpu_setup_power.S +1 -0
index efdcfa7..b8e0d1e 100644
@@ -94,6 +94,7 @@ _GLOBAL(__restore_cpu_power8)
 _GLOBAL(__setup_cpu_power10)
       mflr    r11
       bl      __init_FSCR_power10
+       bl      __init_PMU_ISA31
 

So we set MMCRA here but then aren't we still going to call __init_PMU which will overwrite that?
Would this setting MMCRA also need to be handled in __restore_cpu_power10?

Thanks for this nice catch ! When I rebased code initial phase, we didn’t had power10 part filled in. It was a miss from my side in adding PMu init functions and thanks for pointing this out. Below patch will call __init_PMU functions in setup and restore. Please check if this looks good

--

arch/powerpc/kernel/cpu_setup_power.S +0 -0
index efdcfa714106..e672a6c5fd7c 100644

arch/powerpc/kernel/cpu_setup_power.S _GLOBAL(__restore_cpu_power8) · line 102

Quoted 9 lines
arch/powerpc/kernel/cpu_setup_power.S +3 -0
@@ -94,6 +94,9 @@ _GLOBAL(__restore_cpu_power8)
 _GLOBAL(__setup_cpu_power10)
  mflr r11
  bl __init_FSCR_power10
+ bl __init_PMU
+ bl __init_PMU_ISA31
+ bl __init_PMU_HV
  b 1f
 
 _GLOBAL(__setup_cpu_power9)

Won't you also need to change where the label 1 is:

arch/powerpc/kernel/cpu_setup_power.S +2 -2
@@ -100,8 +100,8 @@ _GLOBAL(__setup_cpu_power10)
 _GLOBAL(__setup_cpu_power9)
        mflr    r11
        bl      __init_FSCR
-1:     bl      __init_PMU
-       bl      __init_hvmode_206
+       bl      __init_PMU
+1:     bl      __init_hvmode_206
        mtlr    r11
        beqlr
        li      r0,0
Quoted 86 lines
arch/powerpc/kernel/cpu_setup_power.S +10 -0
@@ -124,6 +127,9 @@ _GLOBAL(__setup_cpu_power9)
 _GLOBAL(__restore_cpu_power10)
  mflr r11
  bl __init_FSCR_power10
+ bl __init_PMU
+ bl __init_PMU_ISA31
+ bl __init_PMU_HV
  b 1f
 
 _GLOBAL(__restore_cpu_power9)
@@ -233,3 +239,10 @@ __init_PMU_ISA207:
  li r5,0
  mtspr SPRN_MMCRS,r5
  blr
+
+__init_PMU_ISA31:
+ li r5,0
+ mtspr SPRN_MMCR3,r5
+ LOAD_REG_IMMEDIATE(r5, MMCRA_BHRB_DISABLE)
+ mtspr SPRN_MMCRA,r5
+ blr

—

b 1f

_GLOBAL(__setup_cpu_power9)

arch/powerpc/kernel/cpu_setup_power.S +7 -0
@@ -233,3 +234,10 @@ __init_PMU_ISA207:
       li      r5,0
       mtspr   SPRN_MMCRS,r5
       blr
+
+__init_PMU_ISA31:
+       li      r5,0
+       mtspr   SPRN_MMCR3,r5
+       LOAD_REG_IMMEDIATE(r5, MMCRA_BHRB_DISABLE)
+       mtspr   SPRN_MMCRA,r5
+       blr
arch/powerpc/kernel/dt_cpu_ftrs.c +26 -1
index 3a40951..f482286 100644
@@ -450,6 +450,31 @@ static int __init feat_enable_pmu_power9(struct dt_cpu_feature *f)
       return 1;
 }
 
+static void init_pmu_power10(void)
+{
+       init_pmu_power9();
+
+       mtspr(SPRN_MMCR3, 0);
+       mtspr(SPRN_MMCRA, MMCRA_BHRB_DISABLE);
+}
+
+static int __init feat_enable_pmu_power10(struct dt_cpu_feature *f)
+{
+       hfscr_pmu_enable();
+
+       init_pmu_power10();
+       init_pmu_registers = init_pmu_power10;
+
+       cur_cpu_spec->cpu_features |= CPU_FTR_MMCRA;
+       cur_cpu_spec->cpu_user_features |= PPC_FEATURE_PSERIES_PERFMON_COMPAT;
+
+       cur_cpu_spec->num_pmcs          = 6;
+       cur_cpu_spec->pmc_type          = PPC_PMC_IBM;
+       cur_cpu_spec->oprofile_cpu_type = "ppc64/power10";
+
+       return 1;
+}
+
 static int __init feat_enable_tm(struct dt_cpu_feature *f)
 {
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
@@ -639,6 +664,7 @@ struct dt_cpu_feature_match {
       {"pc-relative-addressing", feat_enable, 0},
       {"machine-check-power9", feat_enable_mce_power9, 0},
       {"performance-monitor-power9", feat_enable_pmu_power9, 0},
+       {"performance-monitor-power10", feat_enable_pmu_power10, 0},
       {"event-based-branch-v3", feat_enable, 0},
       {"random-number-generator", feat_enable, 0},
       {"system-call-vectored", feat_disable, 0},
--

1.8.3.1

#25 lore raw

Re: [v3 07/15] powerpc/perf: Add power10_feat to dt_cpu_ftrs

Quoted 140 lines · Jordan Niethe
Quoted 120 lines · On Wed, Jul 22, 2020 at 5:55 PM Athira Rajeev <[email protected]…

On 22-Jul-2020, at 10:11 AM, Jordan Niethe <[email protected]> wrote:

On Sat, Jul 18, 2020 at 1:13 AM Athira Rajeev
<[email protected]> wrote:

From: Madhavan Srinivasan <[email protected]>

Add power10 feature function to dt_cpu_ftrs.c along with a power10 specific init() to initialize pmu sprs, sets the oprofile_cpu_type and cpu_features. This will enable performance monitoring unit(PMU) for Power10 in CPU features with "performance-monitor-power10".

For PowerISA v3.1, BHRB disable is controlled via Monitor Mode Control Register A (MMCRA) bit, namely "BHRB Recording Disable (BHRBRD)". This patch initializes MMCRA BHRBRD to disable BHRB feature at boot for power10.

---

arch/powerpc/include/asm/reg.h        |  3 +++
arch/powerpc/kernel/cpu_setup_power.S |  8 ++++++++
arch/powerpc/kernel/dt_cpu_ftrs.c     | 26 ++++++++++++++++++++++++++
3 files changed, 37 insertions(+)
arch/powerpc/include/asm/reg.h +2 -0
index 21a1b2d..900ada1 100644
@@ -1068,6 +1068,9 @@
 #define MMCR0_PMC2_LOADMISSTIME        0x5
 #endif
 
+/* BHRB disable bit for PowerISA v3.10 */
+#define MMCRA_BHRB_DISABLE     0x0000002000000000
 

Shouldn't this go under SPRN_MMCRA with the other MMCRA_*.

Hi Jordan

Ok, the definition of MMCRA is under #ifdef for 64 bit . if I move definition of MMCRA_BHRB_DISABLE along with other SPR's, I also need to define this for 32-bit to satisfy core-book3s to compile as below:

arch/powerpc/include/asm/reg.h +2 -3
index 900ada10762c..7e271657b412 100644
@@ -888,6 +888,8 @@
 #define   MMCRA_SLOT   0x07000000UL /* SLOT bits (37-39) */
 #define   MMCRA_SLOT_SHIFT     24
 #define   MMCRA_SAMPLE_ENABLE 0x00000001UL /* enable sampling */
+/* BHRB disable bit for PowerISA v3.10 */
+#define   MMCRA_BHRB_DISABLE  0x0000002000000000
 #define   POWER6_MMCRA_SDSYNC 0x0000080000000000ULL    /* SDAR/SIAR synced */
 #define   POWER6_MMCRA_SIHV   0x0000040000000000ULL
 #define   POWER6_MMCRA_SIPR   0x0000020000000000ULL
@@ -1068,9 +1070,6 @@
 #define MMCR0_PMC2_LOADMISSTIME        0x5
 #endif
 
 
 
-/* BHRB disable bit for PowerISA v3.10 */
-#define MMCRA_BHRB_DISABLE     0x0000002000000000
-
 /*

* SPRG usage:
*

arch/powerpc/perf/core-book3s.c +1 -0
index 36baae666387..88068f20827c 100644
@@ -94,6 +94,7 @@ static unsigned int freeze_events_kernel = MMCR0_FCS;
 #define SPRN_SIER2             0
 #define SPRN_SIER3             0
 #define MMCRA_SAMPLE_ENABLE    0
+#define MMCRA_BHRB_DISABLE     0
 
 
 

static inline unsigned long perf_ip_adjust(struct pt_regs *regs) {

+
/*
* SPRG usage:
*

arch/powerpc/kernel/cpu_setup_power.S +1 -0
index efdcfa7..b8e0d1e 100644
@@ -94,6 +94,7 @@ _GLOBAL(__restore_cpu_power8)
 _GLOBAL(__setup_cpu_power10)
      mflr    r11
      bl      __init_FSCR_power10
+       bl      __init_PMU_ISA31
 

So we set MMCRA here but then aren't we still going to call __init_PMU which will overwrite that?
Would this setting MMCRA also need to be handled in __restore_cpu_power10?

Thanks for this nice catch ! When I rebased code initial phase, we didn’t had power10 part filled in. It was a miss from my side in adding PMu init functions and thanks for pointing this out. Below patch will call __init_PMU functions in setup and restore. Please check if this looks good

--

arch/powerpc/kernel/cpu_setup_power.S +0 -0
index efdcfa714106..e672a6c5fd7c 100644

arch/powerpc/kernel/cpu_setup_power.S _GLOBAL(__restore_cpu_power8) · line 102

Quoted 9 lines
arch/powerpc/kernel/cpu_setup_power.S +3 -0
@@ -94,6 +94,9 @@ _GLOBAL(__restore_cpu_power8)
 _GLOBAL(__setup_cpu_power10)
 mflr r11
 bl __init_FSCR_power10
+ bl __init_PMU
+ bl __init_PMU_ISA31
+ bl __init_PMU_HV
 b 1f
 
 _GLOBAL(__setup_cpu_power9)

Won't you also need to change where the label 1 is:

arch/powerpc/kernel/cpu_setup_power.S _GLOBAL(__setup_cpu_power10) · line 107

Quoted 10 lines
arch/powerpc/kernel/cpu_setup_power.S +2 -2
@@ -100,8 +100,8 @@ _GLOBAL(__setup_cpu_power10)
 _GLOBAL(__setup_cpu_power9)
       mflr    r11
       bl      __init_FSCR
-1:     bl      __init_PMU
-       bl      __init_hvmode_206
+       bl      __init_PMU
+1:     bl      __init_hvmode_206
       mtlr    r11
       beqlr
       li      r0,0

HI Jordan

I will address these comments and include changes for cpu_setup_power.S in a separate patch as suggested by Michael Ellerman

Thanks
Athira

Quoted 85 lines
Quoted 85 lines
arch/powerpc/kernel/cpu_setup_power.S +10 -0
@@ -124,6 +127,9 @@ _GLOBAL(__setup_cpu_power9)
 _GLOBAL(__restore_cpu_power10)
 mflr r11
 bl __init_FSCR_power10
+ bl __init_PMU
+ bl __init_PMU_ISA31
+ bl __init_PMU_HV
 b 1f
 
 _GLOBAL(__restore_cpu_power9)
@@ -233,3 +239,10 @@ __init_PMU_ISA207:
 li r5,0
 mtspr SPRN_MMCRS,r5
 blr
+
+__init_PMU_ISA31:
+ li r5,0
+ mtspr SPRN_MMCR3,r5
+ LOAD_REG_IMMEDIATE(r5, MMCRA_BHRB_DISABLE)
+ mtspr SPRN_MMCRA,r5
+ blr

—

b 1f

_GLOBAL(__setup_cpu_power9)

arch/powerpc/kernel/cpu_setup_power.S +7 -0
@@ -233,3 +234,10 @@ __init_PMU_ISA207:
      li      r5,0
      mtspr   SPRN_MMCRS,r5
      blr
+
+__init_PMU_ISA31:
+       li      r5,0
+       mtspr   SPRN_MMCR3,r5
+       LOAD_REG_IMMEDIATE(r5, MMCRA_BHRB_DISABLE)
+       mtspr   SPRN_MMCRA,r5
+       blr
arch/powerpc/kernel/dt_cpu_ftrs.c +26 -1
index 3a40951..f482286 100644
@@ -450,6 +450,31 @@ static int __init feat_enable_pmu_power9(struct dt_cpu_feature *f)
      return 1;
 }
 
+static void init_pmu_power10(void)
+{
+       init_pmu_power9();
+
+       mtspr(SPRN_MMCR3, 0);
+       mtspr(SPRN_MMCRA, MMCRA_BHRB_DISABLE);
+}
+
+static int __init feat_enable_pmu_power10(struct dt_cpu_feature *f)
+{
+       hfscr_pmu_enable();
+
+       init_pmu_power10();
+       init_pmu_registers = init_pmu_power10;
+
+       cur_cpu_spec->cpu_features |= CPU_FTR_MMCRA;
+       cur_cpu_spec->cpu_user_features |= PPC_FEATURE_PSERIES_PERFMON_COMPAT;
+
+       cur_cpu_spec->num_pmcs          = 6;
+       cur_cpu_spec->pmc_type          = PPC_PMC_IBM;
+       cur_cpu_spec->oprofile_cpu_type = "ppc64/power10";
+
+       return 1;
+}
+
 static int __init feat_enable_tm(struct dt_cpu_feature *f)
 {
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
@@ -639,6 +664,7 @@ struct dt_cpu_feature_match {
      {"pc-relative-addressing", feat_enable, 0},
      {"machine-check-power9", feat_enable_mce_power9, 0},
      {"performance-monitor-power9", feat_enable_pmu_power9, 0},
+       {"performance-monitor-power10", feat_enable_pmu_power10, 0},
      {"event-based-branch-v3", feat_enable, 0},
      {"random-number-generator", feat_enable, 0},
      {"system-call-vectored", feat_disable, 0},
--

1.8.3.1

#26 lore raw

PATCH v3 8/15 powerpc/perf: power10 Performance Monitoring support

In reply to Athira Rajeev

Base enablement patch to register performance monitoring hardware support for power10. Patch introduce the raw event encoding format, defines the supported list of events, config fields for the event attributes and their corresponding bit values which are exported via sysfs.

Patch also enhances the support function in isa207_common.c to include power10 pmu hardware.

[Enablement of base PMU driver code]
[Addition of ISA macros for counter support functions]
[Fix compilation warning for missing prototype for init_power10_pmu]
---
 arch/powerpc/perf/Makefile              |   2 +-
 arch/powerpc/perf/core-book3s.c         |   2 +
 arch/powerpc/perf/internal.h            |   1 +
 arch/powerpc/perf/isa207-common.c       |  59 ++++-
 arch/powerpc/perf/isa207-common.h       |  33 ++-
 arch/powerpc/perf/power10-events-list.h |  70 ++++++
 arch/powerpc/perf/power10-pmu.c         | 410 ++++++++++++++++++++++++++++++++
 7 files changed, 566 insertions(+), 11 deletions(-)
 create mode 100644 arch/powerpc/perf/power10-events-list.h
 create mode 100644 arch/powerpc/perf/power10-pmu.c
arch/powerpc/perf/Makefile +1 -1
index 53d614e..c02854d 100644
@@ -9,7 +9,7 @@ obj-$(CONFIG_PPC_PERF_CTRS)	+= core-book3s.o bhrb.o
 obj64-$(CONFIG_PPC_PERF_CTRS)	+= ppc970-pmu.o power5-pmu.o \
 				   power5+-pmu.o power6-pmu.o power7-pmu.o \
 				   isa207-common.o power8-pmu.o power9-pmu.o \
-				   generic-compat-pmu.o
+				   generic-compat-pmu.o power10-pmu.o
 obj32-$(CONFIG_PPC_PERF_CTRS)	+= mpc7450-pmu.o
 
 obj-$(CONFIG_PPC_POWERNV)	+= imc-pmu.o
arch/powerpc/perf/core-book3s.c +2 -0
index ca32fc0..0ffb757d 100644
@@ -2332,6 +2332,8 @@ static int __init init_ppc64_pmu(void)
 		return 0;
 	else if (!init_power9_pmu())
 		return 0;
+	else if (!init_power10_pmu())
+		return 0;
 	else if (!init_ppc970_pmu())
 		return 0;
 	else
arch/powerpc/perf/internal.h +1 -0
index f755c64..80bbf72 100644
@@ -9,4 +9,5 @@
 extern int init_power7_pmu(void);
 extern int init_power8_pmu(void);
 extern int init_power9_pmu(void);
+extern int init_power10_pmu(void);
 extern int init_generic_compat_pmu(void);
arch/powerpc/perf/isa207-common.c +50 -9

132 lines not on this page · raw message

arch/powerpc/perf/isa207-common.h +32 -1
index df968fd..044de65 100644
@@ -87,6 +87,31 @@
 	 EVENT_LINUX_MASK					|	\
 	 EVENT_PSEL_MASK))
 
+/* Contants to support power10 raw encoding format */
+#define p10_SDAR_MODE_SHIFT		22
+#define p10_SDAR_MODE_MASK		0x3ull
+#define p10_SDAR_MODE(v)		(((v) >> p10_SDAR_MODE_SHIFT) & \
+					p10_SDAR_MODE_MASK)
+#define p10_EVENT_L2L3_SEL_MASK		0x1f
+#define p10_L2L3_SEL_SHIFT		3
+#define p10_L2L3_EVENT_SHIFT		40
+#define p10_EVENT_THRESH_MASK		0xffffull
+#define p10_EVENT_CACHE_SEL_MASK	0x3ull
+#define p10_EVENT_MMCR3_MASK		0x7fffull
+#define p10_EVENT_MMCR3_SHIFT		45
+
+#define p10_EVENT_VALID_MASK		\
+	((p10_SDAR_MODE_MASK   << p10_SDAR_MODE_SHIFT		|	\
+	(p10_EVENT_THRESH_MASK  << EVENT_THRESH_SHIFT)		|	\
+	(EVENT_SAMPLE_MASK     << EVENT_SAMPLE_SHIFT)		|	\
+	(p10_EVENT_CACHE_SEL_MASK  << EVENT_CACHE_SEL_SHIFT)	|	\
+	(EVENT_PMC_MASK        << EVENT_PMC_SHIFT)		|	\
+	(EVENT_UNIT_MASK       << EVENT_UNIT_SHIFT)		|	\
+	(p9_EVENT_COMBINE_MASK << p9_EVENT_COMBINE_SHIFT)	|	\
+	(p10_EVENT_MMCR3_MASK  << p10_EVENT_MMCR3_SHIFT)	|	\
+	(EVENT_MARKED_MASK     << EVENT_MARKED_SHIFT)		|	\
+	 EVENT_LINUX_MASK					|	\
+	EVENT_PSEL_MASK))
 /*
  * Layout of constraint bits:
  *
@@ -135,6 +160,9 @@
 #define CNST_CACHE_PMC4_VAL	(1ull << 54)
 #define CNST_CACHE_PMC4_MASK	CNST_CACHE_PMC4_VAL
 
+#define CNST_L2L3_GROUP_VAL(v)	(((v) & 0x1full) << 55)
+#define CNST_L2L3_GROUP_MASK	CNST_L2L3_GROUP_VAL(0x1f)
+
 /*
  * For NC we are counting up to 4 events. This requires three bits, and we need
  * the fifth event to overflow and set the 4th bit. To achieve that we bias the
@@ -191,7 +219,7 @@
 #define MMCRA_THR_CTR_EXP(v)		(((v) >> MMCRA_THR_CTR_EXP_SHIFT) &\
 						MMCRA_THR_CTR_EXP_MASK)
 
-/* MMCR1 Threshold Compare bit constant for power9 */
+/* MMCRA Threshold Compare bit constant for power9 */
 #define p9_MMCRA_THR_CMP_SHIFT	45
 
 /* Bits in MMCR2 for PowerISA v2.07 */
@@ -202,6 +230,9 @@
 #define MAX_ALT				2
 #define MAX_PMU_COUNTERS		6
 
+/* Bits in MMCR3 for PowerISA v3.10 */
+#define MMCR3_SHIFT(pmc)		(49 - (15 * ((pmc) - 1)))
+
 #define ISA207_SIER_TYPE_SHIFT		15
 #define ISA207_SIER_TYPE_MASK		(0x7ull << ISA207_SIER_TYPE_SHIFT)
 
arch/powerpc/perf/power10-events-list.h new file +70 -0

70 lines not on this page · raw message

arch/powerpc/perf/power10-pmu.c new file +410 -0

410 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#27 lore raw

PATCH v3 9/15 powerpc/perf: Ignore the BHRB kernel address filtering for P10

In reply to Athira Rajeev

commit bb19af816025 ("powerpc/perf: Prevent kernel address leak to userspace via BHRB buffer") added a check in bhrb_read() to filter the kernel address from BHRB buffer. This patch modified it to avoid that check for PowerISA v3.1 based processors, since PowerISA v3.1 allows only MSR[PR]=1 address to be written to BHRB buffer.

---
 arch/powerpc/perf/core-book3s.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/perf/core-book3s.c +4 -1
index 0ffb757d..bd125fe 100644
@@ -469,8 +469,11 @@ static void power_pmu_bhrb_read(struct perf_event *event, struct cpu_hw_events *
 			 * addresses at this point. Check the privileges before
 			 * exporting it to userspace (avoid exposure of regions
 			 * where we could have speculative execution)
+			 * Incase of ISA v3.1, BHRB will capture only user-space
+			 * addresses, hence include a check before filtering code
 			 */
-			if (is_kernel_addr(addr) && perf_allow_kernel(&event->attr) != 0)
+			if (!(ppmu->flags & PPMU_ARCH_310S) &&
+				is_kernel_addr(addr) && perf_allow_kernel(&event->attr) != 0)
 				continue;
 
 			/* Branches are read most recent first (ie. mfbhrb 0 is
Signature · 1 line
1.8.3.1
#28 lore raw

PATCH v3 10/15 powerpc/perf: Add Power10 BHRB filter support for PERF_SAMPLE_BRANCH_IND_CALL/COND

In reply to Athira Rajeev

PowerISA v3.1 introduce filtering support for PERF_SAMPLE_BRANCH_IND_CALL/COND. The patch adds BHRB filter support for "ind_call" and "cond" in power10_bhrb_filter_map().

---
 arch/powerpc/perf/power10-pmu.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
arch/powerpc/perf/power10-pmu.c +11 -2
index ba19f40..b02aabb 100644
@@ -83,6 +83,8 @@
 
 /* MMCRA IFM bits - POWER10 */
 #define POWER10_MMCRA_IFM1		0x0000000040000000UL
+#define POWER10_MMCRA_IFM2		0x0000000080000000UL
+#define POWER10_MMCRA_IFM3		0x00000000C0000000UL
 #define POWER10_MMCRA_BHRB_MASK		0x00000000C0000000UL
 
 /* Table of alternatives, sorted by column 0 */
@@ -233,8 +235,15 @@ static u64 power10_bhrb_filter_map(u64 branch_sample_type)
 	if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_RETURN)
 		return -1;
 
-	if (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL)
-		return -1;
+	if (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL) {
+		pmu_bhrb_filter |= POWER10_MMCRA_IFM2;
+		return pmu_bhrb_filter;
+	}
+
+	if (branch_sample_type & PERF_SAMPLE_BRANCH_COND) {
+		pmu_bhrb_filter |= POWER10_MMCRA_IFM3;
+		return pmu_bhrb_filter;
+	}
 
 	if (branch_sample_type & PERF_SAMPLE_BRANCH_CALL)
 		return -1;
Signature · 1 line
1.8.3.1
#29 lore raw

PATCH v3 11/15 powerpc/perf: BHRB control to disable BHRB logic when not used

In reply to Athira Rajeev

PowerISA v3.1 has few updates for the Branch History Rolling Buffer(BHRB).

BHRB disable is controlled via Monitor Mode Control Register A (MMCRA) bit, namely "BHRB Recording Disable (BHRBRD)". This field controls whether BHRB entries are written when BHRB recording is enabled by other bits. This patch implements support for this BHRB disable bit.

By setting 0b1 to this bit will disable the BHRB and by setting 0b0 to this bit will have BHRB enabled. This addresses backward compatibility (for older OS), since this bit will be cleared and hardware will be writing to BHRB by default.

This patch addresses changes to set MMCRA (BHRBRD) at boot for power10 ( there by the core will run faster) and enable this feature only on runtime ie, on explicit need from user. Also save/restore MMCRA in the restore path of state-loss idle state to make sure we keep BHRB disabled if it was not enabled on request at runtime.

---
 arch/powerpc/perf/core-book3s.c       | 20 ++++++++++++++++----
 arch/powerpc/perf/isa207-common.c     | 12 ++++++++++++
 arch/powerpc/platforms/powernv/idle.c | 22 ++++++++++++++++++++--
 3 files changed, 48 insertions(+), 6 deletions(-)
arch/powerpc/perf/core-book3s.c +16 -4
index bd125fe..31c0535 100644
@@ -1218,7 +1218,7 @@ static void write_mmcr0(struct cpu_hw_events *cpuhw, unsigned long mmcr0)
 static void power_pmu_disable(struct pmu *pmu)
 {
 	struct cpu_hw_events *cpuhw;
-	unsigned long flags, mmcr0, val;
+	unsigned long flags, mmcr0, val, mmcra;
 
 	if (!ppmu)
 		return;
@@ -1251,12 +1251,24 @@ static void power_pmu_disable(struct pmu *pmu)
 		mb();
 		isync();
 
+		val = mmcra = cpuhw->mmcr.mmcra;
+
 		/*
 		 * Disable instruction sampling if it was enabled
 		 */
-		if (cpuhw->mmcr.mmcra & MMCRA_SAMPLE_ENABLE) {
-			mtspr(SPRN_MMCRA,
-			      cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
+		if (cpuhw->mmcr.mmcra & MMCRA_SAMPLE_ENABLE)
+			val &= ~MMCRA_SAMPLE_ENABLE;
+
+		/* Disable BHRB via mmcra (BHRBRD) for p10 */
+		if (ppmu->flags & PPMU_ARCH_310S)
+			val |= MMCRA_BHRB_DISABLE;
+
+		/*
+		 * Write SPRN_MMCRA if mmcra has either disabled
+		 * instruction sampling or BHRB.
+		 */
+		if (val != mmcra) {
+			mtspr(SPRN_MMCRA, mmcra);
 			mb();
 			isync();
 		}
arch/powerpc/perf/isa207-common.c +12 -0
index 77643f3..964437a 100644
@@ -404,6 +404,13 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
 
 	mmcra = mmcr1 = mmcr2 = mmcr3 = 0;
 
+	/*
+	 * Disable bhrb unless explicitly requested
+	 * by setting MMCRA (BHRBRD) bit.
+	 */
+	if (cpu_has_feature(CPU_FTR_ARCH_31))
+		mmcra |= MMCRA_BHRB_DISABLE;
+
 	/* Second pass: assign PMCs, set all MMCR1 fields */
 	for (i = 0; i < n_ev; ++i) {
 		pmc     = (event[i] >> EVENT_PMC_SHIFT) & EVENT_PMC_MASK;
@@ -479,6 +486,11 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
 			mmcra |= val << MMCRA_IFM_SHIFT;
 		}
 
+		/* set MMCRA (BHRBRD) to 0 if there is user request for BHRB */
+		if (cpu_has_feature(CPU_FTR_ARCH_31) &&
+				(has_branch_stack(pevents[i]) || (event[i] & EVENT_WANTS_BHRB)))
+			mmcra &= ~MMCRA_BHRB_DISABLE;
+
 		if (pevents[i]->attr.exclude_user)
 			mmcr2 |= MMCR2_FCP(pmc);
 
arch/powerpc/platforms/powernv/idle.c +20 -2
index 2dd4673..1c9d0a9 100644
@@ -611,6 +611,7 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
 	unsigned long srr1;
 	unsigned long pls;
 	unsigned long mmcr0 = 0;
+	unsigned long mmcra = 0;
 	struct p9_sprs sprs = {}; /* avoid false used-uninitialised */
 	bool sprs_saved = false;
 
@@ -657,6 +658,21 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
 		  */
 		mmcr0		= mfspr(SPRN_MMCR0);
 	}
+
+	if (cpu_has_feature(CPU_FTR_ARCH_31)) {
+		/*
+		 * POWER10 uses MMCRA (BHRBRD) as BHRB disable bit.
+		 * If the user hasn't asked for the BHRB to be
+		 * written, the value of MMCRA[BHRBRD] is 1.
+		 * On wakeup from stop, MMCRA[BHRBD] will be 0,
+		 * since it is previleged resource and will be lost.
+		 * Thus, if we do not save and restore the MMCRA[BHRBD],
+		 * hardware will be needlessly writing to the BHRB
+		 * in problem mode.
+		 */
+		mmcra		= mfspr(SPRN_MMCRA);
+	}
+
 	if ((psscr & PSSCR_RL_MASK) >= pnv_first_spr_loss_level) {
 		sprs.lpcr	= mfspr(SPRN_LPCR);
 		sprs.hfscr	= mfspr(SPRN_HFSCR);
@@ -700,8 +716,6 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
 	WARN_ON_ONCE(mfmsr() & (MSR_IR|MSR_DR));
 
 	if ((srr1 & SRR1_WAKESTATE) != SRR1_WS_NOLOSS) {
-		unsigned long mmcra;
-
 		/*
 		 * We don't need an isync after the mtsprs here because the
 		 * upcoming mtmsrd is execution synchronizing.
@@ -721,6 +735,10 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
 			mtspr(SPRN_MMCR0, mmcr0);
 		}
 
+		/* Reload MMCRA to restore BHRB disable bit for POWER10 */
+		if (cpu_has_feature(CPU_FTR_ARCH_31))
+			mtspr(SPRN_MMCRA, mmcra);
+
 		/*
 		 * DD2.2 and earlier need to set then clear bit 60 in MMCRA
 		 * to ensure the PMU starts running.
Signature · 1 line
1.8.3.1
Reviewed-by on v3 11/15
#30 lore raw

Re: [v3 11/15] powerpc/perf: BHRB control to disable BHRB logic when not used

Quoted 12 lines · Athira Rajeev

PowerISA v3.1 has few updates for the Branch History Rolling Buffer(BHRB).

BHRB disable is controlled via Monitor Mode Control Register A (MMCRA) bit, namely "BHRB Recording Disable (BHRBRD)". This field controls whether BHRB entries are written when BHRB recording is enabled by other bits. This patch implements support for this BHRB disable bit.

By setting 0b1 to this bit will disable the BHRB and by setting 0b0 to this bit will have BHRB enabled. This addresses backward compatibility (for older OS), since this bit will be cleared and hardware will be writing to BHRB by default.

Quoted 7 lines

This patch addresses changes to set MMCRA (BHRBRD) at boot for power10 ( there by the core will run faster) and enable this feature only on runtime ie, on explicit need from user. Also save/restore MMCRA in the restore path of state-loss idle state to make sure we keep BHRB disabled if it was not enabled on request at runtime.

For arch/powerpc/platforms/powernv/idle.c

Quoted 5 lines
---
 arch/powerpc/perf/core-book3s.c       | 20 ++++++++++++++++----
 arch/powerpc/perf/isa207-common.c     | 12 ++++++++++++
 arch/powerpc/platforms/powernv/idle.c | 22 ++++++++++++++++++++--
 3 files changed, 48 insertions(+), 6 deletions(-)

[..snip..]

Quoted 57 lines
arch/powerpc/platforms/powernv/idle.c +20 -2
index 2dd4673..1c9d0a9 100644
@@ -611,6 +611,7 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
 	unsigned long srr1;
 	unsigned long pls;
 	unsigned long mmcr0 = 0;
+	unsigned long mmcra = 0;
 	struct p9_sprs sprs = {}; /* avoid false used-uninitialised */
 	bool sprs_saved = false;
 
@@ -657,6 +658,21 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
 		  */
 		mmcr0		= mfspr(SPRN_MMCR0);
 	}
+
+	if (cpu_has_feature(CPU_FTR_ARCH_31)) {
+		/*
+		 * POWER10 uses MMCRA (BHRBRD) as BHRB disable bit.
+		 * If the user hasn't asked for the BHRB to be
+		 * written, the value of MMCRA[BHRBRD] is 1.
+		 * On wakeup from stop, MMCRA[BHRBD] will be 0,
+		 * since it is previleged resource and will be lost.
+		 * Thus, if we do not save and restore the MMCRA[BHRBD],
+		 * hardware will be needlessly writing to the BHRB
+		 * in problem mode.
+		 */
+		mmcra		= mfspr(SPRN_MMCRA);
+	}
+
 	if ((psscr & PSSCR_RL_MASK) >= pnv_first_spr_loss_level) {
 		sprs.lpcr	= mfspr(SPRN_LPCR);
 		sprs.hfscr	= mfspr(SPRN_HFSCR);
@@ -700,8 +716,6 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
 	WARN_ON_ONCE(mfmsr() & (MSR_IR|MSR_DR));
 
 	if ((srr1 & SRR1_WAKESTATE) != SRR1_WS_NOLOSS) {
-		unsigned long mmcra;
-
 		/*
 		 * We don't need an isync after the mtsprs here because the
 		 * upcoming mtmsrd is execution synchronizing.
@@ -721,6 +735,10 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
 			mtspr(SPRN_MMCR0, mmcr0);
 		}
 
+		/* Reload MMCRA to restore BHRB disable bit for POWER10 */
+		if (cpu_has_feature(CPU_FTR_ARCH_31))
+			mtspr(SPRN_MMCRA, mmcra);
+
 		/*
 		 * DD2.2 and earlier need to set then clear bit 60 in MMCRA
 		 * to ensure the PMU starts running.
Signature · 1 line
1.8.3.1
#31 lore raw

Re: [v3 11/15] powerpc/perf: BHRB control to disable BHRB logic when not used

In reply to Athira Rajeev
Quoted 116 lines · Athira Rajeev

PowerISA v3.1 has few updates for the Branch History Rolling Buffer(BHRB).

BHRB disable is controlled via Monitor Mode Control Register A (MMCRA) bit, namely "BHRB Recording Disable (BHRBRD)". This field controls whether BHRB entries are written when BHRB recording is enabled by other bits. This patch implements support for this BHRB disable bit.

By setting 0b1 to this bit will disable the BHRB and by setting 0b0 to this bit will have BHRB enabled. This addresses backward compatibility (for older OS), since this bit will be cleared and hardware will be writing to BHRB by default.

This patch addresses changes to set MMCRA (BHRBRD) at boot for power10 ( there by the core will run faster) and enable this feature only on runtime ie, on explicit need from user. Also save/restore MMCRA in the restore path of state-loss idle state to make sure we keep BHRB disabled if it was not enabled on request at runtime.

---
 arch/powerpc/perf/core-book3s.c       | 20 ++++++++++++++++----
 arch/powerpc/perf/isa207-common.c     | 12 ++++++++++++
 arch/powerpc/platforms/powernv/idle.c | 22 ++++++++++++++++++++--
 3 files changed, 48 insertions(+), 6 deletions(-)
arch/powerpc/perf/core-book3s.c +16 -4
index bd125fe..31c0535 100644
@@ -1218,7 +1218,7 @@ static void write_mmcr0(struct cpu_hw_events *cpuhw, unsigned long mmcr0)
 static void power_pmu_disable(struct pmu *pmu)
 {
        struct cpu_hw_events *cpuhw;
-       unsigned long flags, mmcr0, val;
+       unsigned long flags, mmcr0, val, mmcra;
 
        if (!ppmu)
                return;
@@ -1251,12 +1251,24 @@ static void power_pmu_disable(struct pmu *pmu)
                mb();
                isync();
 
+               val = mmcra = cpuhw->mmcr.mmcra;
+
                /*
                 * Disable instruction sampling if it was enabled
                 */
-               if (cpuhw->mmcr.mmcra & MMCRA_SAMPLE_ENABLE) {
-                       mtspr(SPRN_MMCRA,
-                             cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
+               if (cpuhw->mmcr.mmcra & MMCRA_SAMPLE_ENABLE)
+                       val &= ~MMCRA_SAMPLE_ENABLE;
+
+               /* Disable BHRB via mmcra (BHRBRD) for p10 */
+               if (ppmu->flags & PPMU_ARCH_310S)
+                       val |= MMCRA_BHRB_DISABLE;
+
+               /*
+                * Write SPRN_MMCRA if mmcra has either disabled
+                * instruction sampling or BHRB.
+                */
+               if (val != mmcra) {
+                       mtspr(SPRN_MMCRA, mmcra);
                        mb();
                        isync();
                }
arch/powerpc/perf/isa207-common.c +12 -0
index 77643f3..964437a 100644
@@ -404,6 +404,13 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
 
        mmcra = mmcr1 = mmcr2 = mmcr3 = 0;
 
+       /*
+        * Disable bhrb unless explicitly requested
+        * by setting MMCRA (BHRBRD) bit.
+        */
+       if (cpu_has_feature(CPU_FTR_ARCH_31))
+               mmcra |= MMCRA_BHRB_DISABLE;
+
        /* Second pass: assign PMCs, set all MMCR1 fields */
        for (i = 0; i < n_ev; ++i) {
                pmc     = (event[i] >> EVENT_PMC_SHIFT) & EVENT_PMC_MASK;
@@ -479,6 +486,11 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
                        mmcra |= val << MMCRA_IFM_SHIFT;
                }
 
+               /* set MMCRA (BHRBRD) to 0 if there is user request for BHRB */
+               if (cpu_has_feature(CPU_FTR_ARCH_31) &&
+                               (has_branch_stack(pevents[i]) || (event[i] & EVENT_WANTS_BHRB)))
+                       mmcra &= ~MMCRA_BHRB_DISABLE;
+
                if (pevents[i]->attr.exclude_user)
                        mmcr2 |= MMCR2_FCP(pmc);
 
arch/powerpc/platforms/powernv/idle.c +4 -0
index 2dd4673..1c9d0a9 100644
@@ -611,6 +611,7 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
        unsigned long srr1;
        unsigned long pls;
        unsigned long mmcr0 = 0;
+       unsigned long mmcra = 0;
        struct p9_sprs sprs = {}; /* avoid false used-uninitialised */
        bool sprs_saved = false;
 
@@ -657,6 +658,21 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
                  */
                mmcr0           = mfspr(SPRN_MMCR0);
        }
+
+       if (cpu_has_feature(CPU_FTR_ARCH_31)) {
+               /*

arch/powerpc/platforms/powernv/idle.c static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on) · line 673

Quoted 10 lines
arch/powerpc/platforms/powernv/idle.c +10 -0
+                * POWER10 uses MMCRA (BHRBRD) as BHRB disable bit.
+                * If the user hasn't asked for the BHRB to be
+                * written, the value of MMCRA[BHRBRD] is 1.
+                * On wakeup from stop, MMCRA[BHRBD] will be 0,
+                * since it is previleged resource and will be lost.
+                * Thus, if we do not save and restore the MMCRA[BHRBD],
+                * hardware will be needlessly writing to the BHRB
+                * in problem mode.
+                */
+               mmcra           = mfspr(SPRN_MMCRA);

If the only thing that needs to happen is set MMCRA[BHRBRD], why save the MMCRA?

Quoted 15 lines
arch/powerpc/platforms/powernv/idle.c +2 -2
+       }
+
        if ((psscr & PSSCR_RL_MASK) >= pnv_first_spr_loss_level) {
                sprs.lpcr       = mfspr(SPRN_LPCR);
                sprs.hfscr      = mfspr(SPRN_HFSCR);
@@ -700,8 +716,6 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
        WARN_ON_ONCE(mfmsr() & (MSR_IR|MSR_DR));
 
        if ((srr1 & SRR1_WAKESTATE) != SRR1_WS_NOLOSS) {
-               unsigned long mmcra;
-
                /*
                 * We don't need an isync after the mtsprs here because the
                 * upcoming mtmsrd is execution synchronizing.

arch/powerpc/platforms/powernv/idle.c static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on) · line 744

Quoted 10 lines
arch/powerpc/platforms/powernv/idle.c +4 -0
@@ -721,6 +735,10 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
                        mtspr(SPRN_MMCR0, mmcr0);
                }
 
+               /* Reload MMCRA to restore BHRB disable bit for POWER10 */
+               if (cpu_has_feature(CPU_FTR_ARCH_31))
+                       mtspr(SPRN_MMCRA, mmcra);
+
                /*
                 * DD2.2 and earlier need to set then clear bit 60 in MMCRA
                 * to ensure the PMU starts running.

Just below here we have:

        mmcra = mfspr(SPRN_MMCRA);
        mmcra |= PPC_BIT(60);
        mtspr(SPRN_MMCRA, mmcra);
        mmcra &= ~PPC_BIT(60);
        mtspr(SPRN_MMCRA, mmcra);

It seems MMCRA[BHRBRD] could just be OR'd in someway similar to this for ISA v3.1?

Quoted 3 lines

--
1.8.3.1

#32 lore raw

Re: [v3 11/15] powerpc/perf: BHRB control to disable BHRB logic when not used

Quoted 156 lines · Jordan Niethe
Quoted 116 lines · Athira Rajeev

PowerISA v3.1 has few updates for the Branch History Rolling Buffer(BHRB).

BHRB disable is controlled via Monitor Mode Control Register A (MMCRA) bit, namely "BHRB Recording Disable (BHRBRD)". This field controls whether BHRB entries are written when BHRB recording is enabled by other bits. This patch implements support for this BHRB disable bit.

By setting 0b1 to this bit will disable the BHRB and by setting 0b0 to this bit will have BHRB enabled. This addresses backward compatibility (for older OS), since this bit will be cleared and hardware will be writing to BHRB by default.

This patch addresses changes to set MMCRA (BHRBRD) at boot for power10 ( there by the core will run faster) and enable this feature only on runtime ie, on explicit need from user. Also save/restore MMCRA in the restore path of state-loss idle state to make sure we keep BHRB disabled if it was not enabled on request at runtime.

---
 arch/powerpc/perf/core-book3s.c       | 20 ++++++++++++++++----
 arch/powerpc/perf/isa207-common.c     | 12 ++++++++++++
 arch/powerpc/platforms/powernv/idle.c | 22 ++++++++++++++++++++--
 3 files changed, 48 insertions(+), 6 deletions(-)
arch/powerpc/perf/core-book3s.c +16 -4
index bd125fe..31c0535 100644
@@ -1218,7 +1218,7 @@ static void write_mmcr0(struct cpu_hw_events *cpuhw, unsigned long mmcr0)
 static void power_pmu_disable(struct pmu *pmu)
 {
        struct cpu_hw_events *cpuhw;
-       unsigned long flags, mmcr0, val;
+       unsigned long flags, mmcr0, val, mmcra;
 
        if (!ppmu)
                return;
@@ -1251,12 +1251,24 @@ static void power_pmu_disable(struct pmu *pmu)
                mb();
                isync();
 
+               val = mmcra = cpuhw->mmcr.mmcra;
+
                /*
                 * Disable instruction sampling if it was enabled
                 */
-               if (cpuhw->mmcr.mmcra & MMCRA_SAMPLE_ENABLE) {
-                       mtspr(SPRN_MMCRA,
-                             cpuhw->mmcr.mmcra & ~MMCRA_SAMPLE_ENABLE);
+               if (cpuhw->mmcr.mmcra & MMCRA_SAMPLE_ENABLE)
+                       val &= ~MMCRA_SAMPLE_ENABLE;
+
+               /* Disable BHRB via mmcra (BHRBRD) for p10 */
+               if (ppmu->flags & PPMU_ARCH_310S)
+                       val |= MMCRA_BHRB_DISABLE;
+
+               /*
+                * Write SPRN_MMCRA if mmcra has either disabled
+                * instruction sampling or BHRB.
+                */
+               if (val != mmcra) {
+                       mtspr(SPRN_MMCRA, mmcra);
                        mb();
                        isync();
                }
arch/powerpc/perf/isa207-common.c +12 -0
index 77643f3..964437a 100644
@@ -404,6 +404,13 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
 
        mmcra = mmcr1 = mmcr2 = mmcr3 = 0;
 
+       /*
+        * Disable bhrb unless explicitly requested
+        * by setting MMCRA (BHRBRD) bit.
+        */
+       if (cpu_has_feature(CPU_FTR_ARCH_31))
+               mmcra |= MMCRA_BHRB_DISABLE;
+
        /* Second pass: assign PMCs, set all MMCR1 fields */
        for (i = 0; i < n_ev; ++i) {
                pmc     = (event[i] >> EVENT_PMC_SHIFT) & EVENT_PMC_MASK;
@@ -479,6 +486,11 @@ int isa207_compute_mmcr(u64 event[], int n_ev,
                        mmcra |= val << MMCRA_IFM_SHIFT;
                }
 
+               /* set MMCRA (BHRBRD) to 0 if there is user request for BHRB */
+               if (cpu_has_feature(CPU_FTR_ARCH_31) &&
+                               (has_branch_stack(pevents[i]) || (event[i] & EVENT_WANTS_BHRB)))
+                       mmcra &= ~MMCRA_BHRB_DISABLE;
+
                if (pevents[i]->attr.exclude_user)
                        mmcr2 |= MMCR2_FCP(pmc);
 
arch/powerpc/platforms/powernv/idle.c +4 -0
index 2dd4673..1c9d0a9 100644
@@ -611,6 +611,7 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
        unsigned long srr1;
        unsigned long pls;
        unsigned long mmcr0 = 0;
+       unsigned long mmcra = 0;
        struct p9_sprs sprs = {}; /* avoid false used-uninitialised */
        bool sprs_saved = false;
 
@@ -657,6 +658,21 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
                  */
                mmcr0           = mfspr(SPRN_MMCR0);
        }
+
+       if (cpu_has_feature(CPU_FTR_ARCH_31)) {
+               /*

arch/powerpc/platforms/powernv/idle.c static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on) · line 673

Quoted 10 lines
arch/powerpc/platforms/powernv/idle.c +10 -0
+                * POWER10 uses MMCRA (BHRBRD) as BHRB disable bit.
+                * If the user hasn't asked for the BHRB to be
+                * written, the value of MMCRA[BHRBRD] is 1.
+                * On wakeup from stop, MMCRA[BHRBD] will be 0,
+                * since it is previleged resource and will be lost.
+                * Thus, if we do not save and restore the MMCRA[BHRBD],
+                * hardware will be needlessly writing to the BHRB
+                * in problem mode.
+                */
+               mmcra           = mfspr(SPRN_MMCRA);

If the only thing that needs to happen is set MMCRA[BHRBRD], why save the MMCRA?

Quoted 15 lines
arch/powerpc/platforms/powernv/idle.c +2 -2
+       }
+
        if ((psscr & PSSCR_RL_MASK) >= pnv_first_spr_loss_level) {
                sprs.lpcr       = mfspr(SPRN_LPCR);
                sprs.hfscr      = mfspr(SPRN_HFSCR);
@@ -700,8 +716,6 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
        WARN_ON_ONCE(mfmsr() & (MSR_IR|MSR_DR));
 
        if ((srr1 & SRR1_WAKESTATE) != SRR1_WS_NOLOSS) {
-               unsigned long mmcra;
-
                /*
                 * We don't need an isync after the mtsprs here because the
                 * upcoming mtmsrd is execution synchronizing.

arch/powerpc/platforms/powernv/idle.c static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on) · line 744

Quoted 10 lines
arch/powerpc/platforms/powernv/idle.c +4 -0
@@ -721,6 +735,10 @@ static unsigned long power9_idle_stop(unsigned long psscr, bool mmu_on)
                        mtspr(SPRN_MMCR0, mmcr0);
                }
 
+               /* Reload MMCRA to restore BHRB disable bit for POWER10 */
+               if (cpu_has_feature(CPU_FTR_ARCH_31))
+                       mtspr(SPRN_MMCRA, mmcra);
+
                /*
                 * DD2.2 and earlier need to set then clear bit 60 in MMCRA
                 * to ensure the PMU starts running.

Just below here we have:

Quoted 7 lines
        mmcra = mfspr(SPRN_MMCRA);
        mmcra |= PPC_BIT(60);
        mtspr(SPRN_MMCRA, mmcra);
        mmcra &= ~PPC_BIT(60);
        mtspr(SPRN_MMCRA, mmcra);

It seems MMCRA[BHRBRD] could just be OR'd in someway similar to this for ISA v3.1?

Oh wait the user could have cleared it, just ignore me.

Quoted 3 lines
Quoted 3 lines

--
1.8.3.1

#33 lore raw

PATCH v3 12/15 powerpc/perf: Add support for outputting extended regs in perf intr_regs

In reply to Athira Rajeev

From: Anju T Sudhakar <[email protected]>

Add support for perf extended register capability in powerpc. The capability flag PERF_PMU_CAP_EXTENDED_REGS, is used to indicate the PMU which support extended registers. The generic code define the mask of extended registers as 0 for non supported architectures.

Patch adds extended regs support for power9 platform by exposing MMCR0, MMCR1 and MMCR2 registers.

REG_RESERVED mask needs update to include extended regs. PERF_REG_EXTENDED_MASK, contains mask value of the supported registers, is defined at runtime in the kernel based on platform since the supported registers may differ from one processor version to another and hence the MASK value.

with patch
----------

available registers: r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r30 r31 nip msr orig_r3 ctr link xer ccr softe trap dar dsisr sier mmcra mmcr0 mmcr1 mmcr2

PERF_RECORD_SAMPLE(IP, 0x1): 4784/4784: 0 period: 1 addr: 0 ... intr regs: mask 0xffffffffffff ABI 64-bit

.... r0    0xc00000000012b77c
.... r1    0xc000003fe5e03930
.... r2    0xc000000001b0e000
.... r3    0xc000003fdcddf800
.... r4    0xc000003fc7880000
.... r5    0x9c422724be
.... r6    0xc000003fe5e03908
.... r7    0xffffff63bddc8706
.... r8    0x9e4
.... r9    0x0
.... r10   0x1
.... r11   0x0
.... r12   0xc0000000001299c0
.... r13   0xc000003ffffc4800
.... r14   0x0
.... r15   0x7fffdd8b8b00
.... r16   0x0
.... r17   0x7fffdd8be6b8
.... r18   0x7e7076607730
.... r19   0x2f
.... r20   0xc00000001fc26c68
.... r21   0xc0002041e4227e00
.... r22   0xc00000002018fb60
.... r23   0x1
.... r24   0xc000003ffec4d900
.... r25   0x80000000
.... r26   0x0
.... r27   0x1
.... r28   0x1
.... r29   0xc000000001be1260
.... r30   0x6008010
.... r31   0xc000003ffebb7218
.... nip   0xc00000000012b910
.... msr   0x9000000000009033
.... orig_r3 0xc00000000012b86c
.... ctr   0xc0000000001299c0
.... link  0xc00000000012b77c
.... xer   0x0
.... ccr   0x28002222

.... softe 0x1
.... trap 0xf00
.... dar 0x0
.... dsisr 0x80000000000
.... sier 0x0
.... mmcra 0x80000000000
.... mmcr0 0x82008090
.... mmcr1 0x1e000000
.... mmcr2 0x0
... thread: perf:4784

[Defined PERF_REG_EXTENDED_MASK at run time to add support for different platforms ]
---
 arch/powerpc/include/asm/perf_event_server.h |  8 +++++++
 arch/powerpc/include/uapi/asm/perf_regs.h    | 14 +++++++++++-
 arch/powerpc/perf/core-book3s.c              |  1 +
 arch/powerpc/perf/perf_regs.c                | 34 +++++++++++++++++++++++++---
 arch/powerpc/perf/power9-pmu.c               |  6 +++++
 5 files changed, 59 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/perf_event_server.h +8 -0
index 832450a..bf85d1a 100644
@@ -15,6 +15,9 @@
 #define MAX_EVENT_ALTERNATIVES	8
 #define MAX_LIMITED_HWCOUNTERS	2
 
+extern u64 PERF_REG_EXTENDED_MASK;
+#define PERF_REG_EXTENDED_MASK	PERF_REG_EXTENDED_MASK
+
 struct perf_event;
 
 struct mmcr_regs {
@@ -62,6 +65,11 @@ struct power_pmu {
 	int 		*blacklist_ev;
 	/* BHRB entries in the PMU */
 	int		bhrb_nr;
+	/*
+	 * set this flag with `PERF_PMU_CAP_EXTENDED_REGS` if
+	 * the pmu supports extended perf regs capability
+	 */
+	int		capabilities;
 };
 
 /*
arch/powerpc/include/uapi/asm/perf_regs.h +13 -1
index f599064..225c64c 100644
@@ -48,6 +48,18 @@ enum perf_event_powerpc_regs {
 	PERF_REG_POWERPC_DSISR,
 	PERF_REG_POWERPC_SIER,
 	PERF_REG_POWERPC_MMCRA,
-	PERF_REG_POWERPC_MAX,
+	/* Extended registers */
+	PERF_REG_POWERPC_MMCR0,
+	PERF_REG_POWERPC_MMCR1,
+	PERF_REG_POWERPC_MMCR2,
+	/* Max regs without the extended regs */
+	PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
 };
+
+#define PERF_REG_PMU_MASK	((1ULL << PERF_REG_POWERPC_MAX) - 1)
+
+/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300 */
+#define PERF_REG_PMU_MASK_300   (((1ULL << (PERF_REG_POWERPC_MMCR2 + 1)) - 1) - PERF_REG_PMU_MASK)
+
+#define PERF_REG_MAX_ISA_300   (PERF_REG_POWERPC_MMCR2 + 1)
 #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
arch/powerpc/perf/core-book3s.c +1 -0
index 31c0535..d5a9529 100644
@@ -2316,6 +2316,7 @@ int register_power_pmu(struct power_pmu *pmu)
 		pmu->name);
 
 	power_pmu.attr_groups = ppmu->attr_groups;
+	power_pmu.capabilities |= (ppmu->capabilities & PERF_PMU_CAP_EXTENDED_REGS);
 
 #ifdef MSR_HV
 	/*
arch/powerpc/perf/perf_regs.c +31 -3
index a213a0a..b0cf68f 100644
@@ -13,9 +13,11 @@
 #include <asm/ptrace.h>
 #include <asm/perf_regs.h>
 
+u64 PERF_REG_EXTENDED_MASK;
+
 #define PT_REGS_OFFSET(id, r) [id] = offsetof(struct pt_regs, r)
 
-#define REG_RESERVED (~((1ULL << PERF_REG_POWERPC_MAX) - 1))
+#define REG_RESERVED (~(PERF_REG_EXTENDED_MASK | PERF_REG_PMU_MASK))
 
 static unsigned int pt_regs_offset[PERF_REG_POWERPC_MAX] = {
 	PT_REGS_OFFSET(PERF_REG_POWERPC_R0,  gpr[0]),
@@ -69,10 +71,26 @@
 	PT_REGS_OFFSET(PERF_REG_POWERPC_MMCRA, dsisr),
 };
 
+/* Function to return the extended register values */
+static u64 get_ext_regs_value(int idx)
+{
+	switch (idx) {
+	case PERF_REG_POWERPC_MMCR0:
+		return mfspr(SPRN_MMCR0);
+	case PERF_REG_POWERPC_MMCR1:
+		return mfspr(SPRN_MMCR1);
+	case PERF_REG_POWERPC_MMCR2:
+		return mfspr(SPRN_MMCR2);
+	default: return 0;
+	}
+}
+
 u64 perf_reg_value(struct pt_regs *regs, int idx)
 {
-	if (WARN_ON_ONCE(idx >= PERF_REG_POWERPC_MAX))
-		return 0;
+	u64 PERF_REG_EXTENDED_MAX;
+
+	if (cpu_has_feature(CPU_FTR_ARCH_300))
+		PERF_REG_EXTENDED_MAX = PERF_REG_MAX_ISA_300;
 
 	if (idx = PERF_REG_POWERPC_SIER &&
 	   (IS_ENABLED(CONFIG_FSL_EMB_PERF_EVENT) ||
@@ -85,6 +103,16 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
 	    IS_ENABLED(CONFIG_PPC32)))
 		return 0;
 
+	if (idx >= PERF_REG_POWERPC_MAX && idx < PERF_REG_EXTENDED_MAX)
+		return get_ext_regs_value(idx);
+
+	/*
+	 * If the idx is referring to value beyond the
+	 * supported registers, return 0 with a warning
+	 */
+	if (WARN_ON_ONCE(idx >= PERF_REG_EXTENDED_MAX))
+		return 0;
+
 	return regs_get_register(regs, pt_regs_offset[idx]);
 }
 
arch/powerpc/perf/power9-pmu.c +6 -0
index 05dae38..2a57e93 100644
@@ -90,6 +90,8 @@ enum {
 #define POWER9_MMCRA_IFM3		0x00000000C0000000UL
 #define POWER9_MMCRA_BHRB_MASK		0x00000000C0000000UL
 
+extern u64 PERF_REG_EXTENDED_MASK;
+
 /* Nasty Power9 specific hack */
 #define PVR_POWER9_CUMULUS		0x00002000
 
@@ -434,6 +436,7 @@ static void power9_config_bhrb(u64 pmu_bhrb_filter)
 	.cache_events		= &power9_cache_events,
 	.attr_groups		= power9_pmu_attr_groups,
 	.bhrb_nr		= 32,
+	.capabilities           = PERF_PMU_CAP_EXTENDED_REGS,
 };
 
 int init_power9_pmu(void)
@@ -457,6 +460,9 @@ int init_power9_pmu(void)
 		}
 	}
 
+	/* Set the PERF_REG_EXTENDED_MASK here */
+	PERF_REG_EXTENDED_MASK = PERF_REG_PMU_MASK_300;
+
 	rc = register_power_pmu(&power9_pmu);
 	if (rc)
 		return rc;
Signature · 1 line
1.8.3.1
#34 lore raw

Re: [v3 12/15] powerpc/perf: Add support for outputting extended regs in perf intr_regs

Thank you for the patch! Yet something to improve:

Hi Athira,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on tip/perf/core v5.8-rc5 next-20200717] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Athira-Rajeev/powerpc-perf-Add-support-for-power10-PMU-Hardware/20200717-224353
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc64-randconfig-r024-20200719 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project ed6b578040a85977026c93bf4188f996148f3218)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc64 cross compiling tool for clang build
# apt-get install binutils-powerpc64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

arch/powerpc/include/asm/io-defs.h:45:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] DEF_PCI_AC_NORET(insw, (unsigned long p, void *b, unsigned long c), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'

                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:221:1: note: expanded from here
   __do_insw
   ^
   arch/powerpc/include/asm/io.h:542:56: note: expanded from macro '__do_insw'
   #define __do_insw(p, b, n)      readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/perf/perf_regs.c:10:
   In file included from include/linux/perf_event.h:57:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:10:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:604:
   arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:223:1: note: expanded from here
   __do_insl
   ^
   arch/powerpc/include/asm/io.h:543:56: note: expanded from macro '__do_insl'
   #define __do_insl(p, b, n)      readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/perf/perf_regs.c:10:
   In file included from include/linux/perf_event.h:57:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:10:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:604:
   arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:225:1: note: expanded from here
   __do_outsb
   ^
   arch/powerpc/include/asm/io.h:544:58: note: expanded from macro '__do_outsb'
   #define __do_outsb(p, b, n)     writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/perf/perf_regs.c:10:
   In file included from include/linux/perf_event.h:57:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:10:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:604:
   arch/powerpc/include/asm/io-defs.h:51:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:227:1: note: expanded from here
   __do_outsw
   ^
   arch/powerpc/include/asm/io.h:545:58: note: expanded from macro '__do_outsw'
   #define __do_outsw(p, b, n)     writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from arch/powerpc/perf/perf_regs.c:10:
   In file included from include/linux/perf_event.h:57:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:10:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:604:
   arch/powerpc/include/asm/io-defs.h:53:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:229:1: note: expanded from here
   __do_outsl
   ^
   arch/powerpc/include/asm/io.h:546:58: note: expanded from macro '__do_outsl'
   #define __do_outsl(p, b, n)     writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
>> arch/powerpc/perf/perf_regs.c:16:5: error: expected identifier or '('
   u64 PERF_REG_EXTENDED_MASK;
       ^
   include/linux/perf_regs.h:16:32: note: expanded from macro 'PERF_REG_EXTENDED_MASK'
   #define PERF_REG_EXTENDED_MASK  0
                                   ^

12 warnings and 1 error generated.

vim +16 arch/powerpc/perf/perf_regs.c

    15	
  > 16	u64 PERF_REG_EXTENDED_MASK;
    17	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

#35 lore raw

Re: [v3 12/15] powerpc/perf: Add support for outputting extended regs in perf intr_regs

Quoted 137 lines · kernel test robot

Hi Athira,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on tip/perf/core v5.8-rc5 next-20200717] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Athira-Rajeev/powerpc-perf-Add-support-for-power10-PMU-Hardware/20200717-224353
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc64-randconfig-r024-20200719 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project ed6b578040a85977026c93bf4188f996148f3218)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc64 cross compiling tool for clang build
# apt-get install binutils-powerpc64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

arch/powerpc/include/asm/io-defs.h:45:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] DEF_PCI_AC_NORET(insw, (unsigned long p, void *b, unsigned long c), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'

                  __do_##name al;                                 \
                  ^~~~~~~~~~~~~~
  <scratch space>:221:1: note: expanded from here
  __do_insw
  ^
  arch/powerpc/include/asm/io.h:542:56: note: expanded from macro '__do_insw'
  #define __do_insw(p, b, n)      readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                         ~~~~~~~~~~~~~~~~~~~~~^
  In file included from arch/powerpc/perf/perf_regs.c:10:
  In file included from include/linux/perf_event.h:57:
  In file included from include/linux/cgroup.h:26:
  In file included from include/linux/kernel_stat.h:9:
  In file included from include/linux/interrupt.h:11:
  In file included from include/linux/hardirq.h:10:
  In file included from arch/powerpc/include/asm/hardirq.h:6:
  In file included from include/linux/irq.h:20:
  In file included from include/linux/io.h:13:
  In file included from arch/powerpc/include/asm/io.h:604:
  arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
  DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                  __do_##name al;                                 \
                  ^~~~~~~~~~~~~~
  <scratch space>:223:1: note: expanded from here
  __do_insl
  ^
  arch/powerpc/include/asm/io.h:543:56: note: expanded from macro '__do_insl'
  #define __do_insl(p, b, n)      readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                         ~~~~~~~~~~~~~~~~~~~~~^
  In file included from arch/powerpc/perf/perf_regs.c:10:
  In file included from include/linux/perf_event.h:57:
  In file included from include/linux/cgroup.h:26:
  In file included from include/linux/kernel_stat.h:9:
  In file included from include/linux/interrupt.h:11:
  In file included from include/linux/hardirq.h:10:
  In file included from arch/powerpc/include/asm/hardirq.h:6:
  In file included from include/linux/irq.h:20:
  In file included from include/linux/io.h:13:
  In file included from arch/powerpc/include/asm/io.h:604:
  arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
  DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                  __do_##name al;                                 \
                  ^~~~~~~~~~~~~~
  <scratch space>:225:1: note: expanded from here
  __do_outsb
  ^
  arch/powerpc/include/asm/io.h:544:58: note: expanded from macro '__do_outsb'
  #define __do_outsb(p, b, n)     writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
  In file included from arch/powerpc/perf/perf_regs.c:10:
  In file included from include/linux/perf_event.h:57:
  In file included from include/linux/cgroup.h:26:
  In file included from include/linux/kernel_stat.h:9:
  In file included from include/linux/interrupt.h:11:
  In file included from include/linux/hardirq.h:10:
  In file included from arch/powerpc/include/asm/hardirq.h:6:
  In file included from include/linux/irq.h:20:
  In file included from include/linux/io.h:13:
  In file included from arch/powerpc/include/asm/io.h:604:
  arch/powerpc/include/asm/io-defs.h:51:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
  DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                  __do_##name al;                                 \
                  ^~~~~~~~~~~~~~
  <scratch space>:227:1: note: expanded from here
  __do_outsw
  ^
  arch/powerpc/include/asm/io.h:545:58: note: expanded from macro '__do_outsw'
  #define __do_outsw(p, b, n)     writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
  In file included from arch/powerpc/perf/perf_regs.c:10:
  In file included from include/linux/perf_event.h:57:
  In file included from include/linux/cgroup.h:26:
  In file included from include/linux/kernel_stat.h:9:
  In file included from include/linux/interrupt.h:11:
  In file included from include/linux/hardirq.h:10:
  In file included from arch/powerpc/include/asm/hardirq.h:6:
  In file included from include/linux/irq.h:20:
  In file included from include/linux/io.h:13:
  In file included from arch/powerpc/include/asm/io.h:604:
  arch/powerpc/include/asm/io-defs.h:53:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
  DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  arch/powerpc/include/asm/io.h:601:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                  __do_##name al;                                 \
                  ^~~~~~~~~~~~~~
  <scratch space>:229:1: note: expanded from here
  __do_outsl
  ^
  arch/powerpc/include/asm/io.h:546:58: note: expanded from macro '__do_outsl'
  #define __do_outsl(p, b, n)     writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
Quoted 1 line
Quoted 1 line

arch/powerpc/perf/perf_regs.c:16:5: error: expected identifier or '('

  u64 PERF_REG_EXTENDED_MASK;
      ^
  include/linux/perf_regs.h:16:32: note: expanded from macro 'PERF_REG_EXTENDED_MASK'
  #define PERF_REG_EXTENDED_MASK  0
                                  ^
Quoted 7 lines

12 warnings and 1 error generated.

vim +16 arch/powerpc/perf/perf_regs.c

   15	
Quoted 1 line

16 u64 PERF_REG_EXTENDED_MASK;

17

Hi,

This patch defines PERF_REG_EXTENDED_MASK
in arch/powerpc/include/asm/perf_event_server.h and this header file is included conditionally based on CONFIG_PPC_PERF_CTRS in arch/powerpc/include/asm/perf_event.h.
So build breaks happens with config having CONFIG_PERF_EVENTS set
and without CONFIG_PPC_PERF_CTRS.

This will be fixed by defining PERF_REG_EXTENDED_MASK in perf_event.h as below:

—

arch/powerpc/include/asm/perf_event.h +2 -0
index eed3954082fa..b1c3a91aa6fa 100644
@@ -38,4 +38,6 @@
 
 /* To support perf_regs sier update */
 extern bool is_sier_available(void);
+extern u64 PERF_REG_EXTENDED_MASK;
+#define PERF_REG_EXTENDED_MASK	PERF_REG_EXTENDED_MASK
 #endif
arch/powerpc/include/asm/perf_event_server.h +0 -3
index bf85d1a0b59e..5d368e81445f 100644
@@ -15,9 +15,6 @@
 #define MAX_EVENT_ALTERNATIVES	8
 #define MAX_LIMITED_HWCOUNTERS	2
 
-extern u64 PERF_REG_EXTENDED_MASK;
-#define PERF_REG_EXTENDED_MASK	PERF_REG_EXTENDED_MASK
-
 struct perf_event;
 
 struct mmcr_regs {

—

We also need this patch by Madhavan Sirinivasan : https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=183203
to solve similar build break with is_sier_available

Thanks
Athira

Quoted 5 lines

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
<.config.gz>

Reviewed-by on v3 12/15
#36 lore raw

Re: [v3 12/15] powerpc/perf: Add support for outputting extended regs in perf intr_regs

In reply to Athira Rajeev
Quoted 76 lines · Athira Rajeev

From: Anju T Sudhakar <[email protected]>

Add support for perf extended register capability in powerpc. The capability flag PERF_PMU_CAP_EXTENDED_REGS, is used to indicate the PMU which support extended registers. The generic code define the mask of extended registers as 0 for non supported architectures.

Patch adds extended regs support for power9 platform by exposing MMCR0, MMCR1 and MMCR2 registers.

REG_RESERVED mask needs update to include extended regs. PERF_REG_EXTENDED_MASK, contains mask value of the supported registers, is defined at runtime in the kernel based on platform since the supported registers may differ from one processor version to another and hence the MASK value.

with patch
----------

available registers: r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r30 r31 nip msr orig_r3 ctr link xer ccr softe trap dar dsisr sier mmcra mmcr0 mmcr1 mmcr2

PERF_RECORD_SAMPLE(IP, 0x1): 4784/4784: 0 period: 1 addr: 0 ... intr regs: mask 0xffffffffffff ABI 64-bit

.... r0    0xc00000000012b77c
.... r1    0xc000003fe5e03930
.... r2    0xc000000001b0e000
.... r3    0xc000003fdcddf800
.... r4    0xc000003fc7880000
.... r5    0x9c422724be
.... r6    0xc000003fe5e03908
.... r7    0xffffff63bddc8706
.... r8    0x9e4
.... r9    0x0
.... r10   0x1
.... r11   0x0
.... r12   0xc0000000001299c0
.... r13   0xc000003ffffc4800
.... r14   0x0
.... r15   0x7fffdd8b8b00
.... r16   0x0
.... r17   0x7fffdd8be6b8
.... r18   0x7e7076607730
.... r19   0x2f
.... r20   0xc00000001fc26c68
.... r21   0xc0002041e4227e00
.... r22   0xc00000002018fb60
.... r23   0x1
.... r24   0xc000003ffec4d900
.... r25   0x80000000
.... r26   0x0
.... r27   0x1
.... r28   0x1
.... r29   0xc000000001be1260
.... r30   0x6008010
.... r31   0xc000003ffebb7218
.... nip   0xc00000000012b910
.... msr   0x9000000000009033
.... orig_r3 0xc00000000012b86c
.... ctr   0xc0000000001299c0
.... link  0xc00000000012b77c
.... xer   0x0
.... ccr   0x28002222

.... softe 0x1
.... trap 0xf00
.... dar 0x0
.... dsisr 0x80000000000
.... sier 0x0
.... mmcra 0x80000000000
.... mmcr0 0x82008090
.... mmcr1 0x1e000000
.... mmcr2 0x0
... thread: perf:4784

Quoted 5 lines
[Defined PERF_REG_EXTENDED_MASK at run time to add support for different platforms ]

---

Patch looks good to me.

Thanks,
Kajol Jain

Quoted 164 lines
 arch/powerpc/include/asm/perf_event_server.h |  8 +++++++
 arch/powerpc/include/uapi/asm/perf_regs.h    | 14 +++++++++++-
 arch/powerpc/perf/core-book3s.c              |  1 +
 arch/powerpc/perf/perf_regs.c                | 34 +++++++++++++++++++++++++---
 arch/powerpc/perf/power9-pmu.c               |  6 +++++
 5 files changed, 59 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/perf_event_server.h +8 -0
index 832450a..bf85d1a 100644
@@ -15,6 +15,9 @@
 #define MAX_EVENT_ALTERNATIVES	8
 #define MAX_LIMITED_HWCOUNTERS	2
 
+extern u64 PERF_REG_EXTENDED_MASK;
+#define PERF_REG_EXTENDED_MASK	PERF_REG_EXTENDED_MASK
+
 struct perf_event;
 
 struct mmcr_regs {
@@ -62,6 +65,11 @@ struct power_pmu {
 	int 		*blacklist_ev;
 	/* BHRB entries in the PMU */
 	int		bhrb_nr;
+	/*
+	 * set this flag with `PERF_PMU_CAP_EXTENDED_REGS` if
+	 * the pmu supports extended perf regs capability
+	 */
+	int		capabilities;
 };
 
 /*
arch/powerpc/include/uapi/asm/perf_regs.h +13 -1
index f599064..225c64c 100644
@@ -48,6 +48,18 @@ enum perf_event_powerpc_regs {
 	PERF_REG_POWERPC_DSISR,
 	PERF_REG_POWERPC_SIER,
 	PERF_REG_POWERPC_MMCRA,
-	PERF_REG_POWERPC_MAX,
+	/* Extended registers */
+	PERF_REG_POWERPC_MMCR0,
+	PERF_REG_POWERPC_MMCR1,
+	PERF_REG_POWERPC_MMCR2,
+	/* Max regs without the extended regs */
+	PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
 };
+
+#define PERF_REG_PMU_MASK	((1ULL << PERF_REG_POWERPC_MAX) - 1)
+
+/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300 */
+#define PERF_REG_PMU_MASK_300   (((1ULL << (PERF_REG_POWERPC_MMCR2 + 1)) - 1) - PERF_REG_PMU_MASK)
+
+#define PERF_REG_MAX_ISA_300   (PERF_REG_POWERPC_MMCR2 + 1)
 #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
arch/powerpc/perf/core-book3s.c +1 -0
index 31c0535..d5a9529 100644
@@ -2316,6 +2316,7 @@ int register_power_pmu(struct power_pmu *pmu)
 		pmu->name);
 
 	power_pmu.attr_groups = ppmu->attr_groups;
+	power_pmu.capabilities |= (ppmu->capabilities & PERF_PMU_CAP_EXTENDED_REGS);
 
 #ifdef MSR_HV
 	/*
arch/powerpc/perf/perf_regs.c +31 -3
index a213a0a..b0cf68f 100644
@@ -13,9 +13,11 @@
 #include <asm/ptrace.h>
 #include <asm/perf_regs.h>
 
+u64 PERF_REG_EXTENDED_MASK;
+
 #define PT_REGS_OFFSET(id, r) [id] = offsetof(struct pt_regs, r)
 
-#define REG_RESERVED (~((1ULL << PERF_REG_POWERPC_MAX) - 1))
+#define REG_RESERVED (~(PERF_REG_EXTENDED_MASK | PERF_REG_PMU_MASK))
 
 static unsigned int pt_regs_offset[PERF_REG_POWERPC_MAX] = {
 	PT_REGS_OFFSET(PERF_REG_POWERPC_R0,  gpr[0]),
@@ -69,10 +71,26 @@
 	PT_REGS_OFFSET(PERF_REG_POWERPC_MMCRA, dsisr),
 };
 
+/* Function to return the extended register values */
+static u64 get_ext_regs_value(int idx)
+{
+	switch (idx) {
+	case PERF_REG_POWERPC_MMCR0:
+		return mfspr(SPRN_MMCR0);
+	case PERF_REG_POWERPC_MMCR1:
+		return mfspr(SPRN_MMCR1);
+	case PERF_REG_POWERPC_MMCR2:
+		return mfspr(SPRN_MMCR2);
+	default: return 0;
+	}
+}
+
 u64 perf_reg_value(struct pt_regs *regs, int idx)
 {
-	if (WARN_ON_ONCE(idx >= PERF_REG_POWERPC_MAX))
-		return 0;
+	u64 PERF_REG_EXTENDED_MAX;
+
+	if (cpu_has_feature(CPU_FTR_ARCH_300))
+		PERF_REG_EXTENDED_MAX = PERF_REG_MAX_ISA_300;
 
 	if (idx == PERF_REG_POWERPC_SIER &&
 	   (IS_ENABLED(CONFIG_FSL_EMB_PERF_EVENT) ||
@@ -85,6 +103,16 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
 	    IS_ENABLED(CONFIG_PPC32)))
 		return 0;
 
+	if (idx >= PERF_REG_POWERPC_MAX && idx < PERF_REG_EXTENDED_MAX)
+		return get_ext_regs_value(idx);
+
+	/*
+	 * If the idx is referring to value beyond the
+	 * supported registers, return 0 with a warning
+	 */
+	if (WARN_ON_ONCE(idx >= PERF_REG_EXTENDED_MAX))
+		return 0;
+
 	return regs_get_register(regs, pt_regs_offset[idx]);
 }
 
arch/powerpc/perf/power9-pmu.c +6 -0
index 05dae38..2a57e93 100644
@@ -90,6 +90,8 @@ enum {
 #define POWER9_MMCRA_IFM3		0x00000000C0000000UL
 #define POWER9_MMCRA_BHRB_MASK		0x00000000C0000000UL
 
+extern u64 PERF_REG_EXTENDED_MASK;
+
 /* Nasty Power9 specific hack */
 #define PVR_POWER9_CUMULUS		0x00002000
 
@@ -434,6 +436,7 @@ static void power9_config_bhrb(u64 pmu_bhrb_filter)
 	.cache_events		= &power9_cache_events,
 	.attr_groups		= power9_pmu_attr_groups,
 	.bhrb_nr		= 32,
+	.capabilities           = PERF_PMU_CAP_EXTENDED_REGS,
 };
 
 int init_power9_pmu(void)
@@ -457,6 +460,9 @@ int init_power9_pmu(void)
 		}
 	}
 
+	/* Set the PERF_REG_EXTENDED_MASK here */
+	PERF_REG_EXTENDED_MASK = PERF_REG_PMU_MASK_300;
+
 	rc = register_power_pmu(&power9_pmu);
 	if (rc)
 		return rc;
#37 lore raw

Re: [v3 12/15] powerpc/perf: Add support for outputting extended regs in perf intr_regs

Quoted 85 lines · kajoljain
Quoted 76 lines · Athira Rajeev

From: Anju T Sudhakar <[email protected]>

Add support for perf extended register capability in powerpc. The capability flag PERF_PMU_CAP_EXTENDED_REGS, is used to indicate the PMU which support extended registers. The generic code define the mask of extended registers as 0 for non supported architectures.

Patch adds extended regs support for power9 platform by exposing MMCR0, MMCR1 and MMCR2 registers.

REG_RESERVED mask needs update to include extended regs. PERF_REG_EXTENDED_MASK, contains mask value of the supported registers, is defined at runtime in the kernel based on platform since the supported registers may differ from one processor version to another and hence the MASK value.

with patch
----------

available registers: r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r30 r31 nip msr orig_r3 ctr link xer ccr softe trap dar dsisr sier mmcra mmcr0 mmcr1 mmcr2

PERF_RECORD_SAMPLE(IP, 0x1): 4784/4784: 0 period: 1 addr: 0 ... intr regs: mask 0xffffffffffff ABI 64-bit

.... r0    0xc00000000012b77c
.... r1    0xc000003fe5e03930
.... r2    0xc000000001b0e000
.... r3    0xc000003fdcddf800
.... r4    0xc000003fc7880000
.... r5    0x9c422724be
.... r6    0xc000003fe5e03908
.... r7    0xffffff63bddc8706
.... r8    0x9e4
.... r9    0x0
.... r10   0x1
.... r11   0x0
.... r12   0xc0000000001299c0
.... r13   0xc000003ffffc4800
.... r14   0x0
.... r15   0x7fffdd8b8b00
.... r16   0x0
.... r17   0x7fffdd8be6b8
.... r18   0x7e7076607730
.... r19   0x2f
.... r20   0xc00000001fc26c68
.... r21   0xc0002041e4227e00
.... r22   0xc00000002018fb60
.... r23   0x1
.... r24   0xc000003ffec4d900
.... r25   0x80000000
.... r26   0x0
.... r27   0x1
.... r28   0x1
.... r29   0xc000000001be1260
.... r30   0x6008010
.... r31   0xc000003ffebb7218
.... nip   0xc00000000012b910
.... msr   0x9000000000009033
.... orig_r3 0xc00000000012b86c
.... ctr   0xc0000000001299c0
.... link  0xc00000000012b77c
.... xer   0x0
.... ccr   0x28002222

.... softe 0x1
.... trap 0xf00
.... dar 0x0
.... dsisr 0x80000000000
.... sier 0x0
.... mmcra 0x80000000000
.... mmcr0 0x82008090
.... mmcr1 0x1e000000
.... mmcr2 0x0
... thread: perf:4784

Quoted 5 lines
[Defined PERF_REG_EXTENDED_MASK at run time to add support for different platforms ]

---

Quoted 3 lines

Patch looks good to me.

Hi Arnaldo and Jiri,
Please let me know if you have any comments on these patches. Can you pull/ack these
patches if they seems fine to you.

Thanks,
Kajol Jain

Quoted 168 lines

Thanks,
Kajol Jain

Quoted 164 lines
 arch/powerpc/include/asm/perf_event_server.h |  8 +++++++
 arch/powerpc/include/uapi/asm/perf_regs.h    | 14 +++++++++++-
 arch/powerpc/perf/core-book3s.c              |  1 +
 arch/powerpc/perf/perf_regs.c                | 34 +++++++++++++++++++++++++---
 arch/powerpc/perf/power9-pmu.c               |  6 +++++
 5 files changed, 59 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/perf_event_server.h +8 -0
index 832450a..bf85d1a 100644
@@ -15,6 +15,9 @@
 #define MAX_EVENT_ALTERNATIVES	8
 #define MAX_LIMITED_HWCOUNTERS	2
 
+extern u64 PERF_REG_EXTENDED_MASK;
+#define PERF_REG_EXTENDED_MASK	PERF_REG_EXTENDED_MASK
+
 struct perf_event;
 
 struct mmcr_regs {
@@ -62,6 +65,11 @@ struct power_pmu {
 	int 		*blacklist_ev;
 	/* BHRB entries in the PMU */
 	int		bhrb_nr;
+	/*
+	 * set this flag with `PERF_PMU_CAP_EXTENDED_REGS` if
+	 * the pmu supports extended perf regs capability
+	 */
+	int		capabilities;
 };
 
 /*
arch/powerpc/include/uapi/asm/perf_regs.h +13 -1
index f599064..225c64c 100644
@@ -48,6 +48,18 @@ enum perf_event_powerpc_regs {
 	PERF_REG_POWERPC_DSISR,
 	PERF_REG_POWERPC_SIER,
 	PERF_REG_POWERPC_MMCRA,
-	PERF_REG_POWERPC_MAX,
+	/* Extended registers */
+	PERF_REG_POWERPC_MMCR0,
+	PERF_REG_POWERPC_MMCR1,
+	PERF_REG_POWERPC_MMCR2,
+	/* Max regs without the extended regs */
+	PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
 };
+
+#define PERF_REG_PMU_MASK	((1ULL << PERF_REG_POWERPC_MAX) - 1)
+
+/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300 */
+#define PERF_REG_PMU_MASK_300   (((1ULL << (PERF_REG_POWERPC_MMCR2 + 1)) - 1) - PERF_REG_PMU_MASK)
+
+#define PERF_REG_MAX_ISA_300   (PERF_REG_POWERPC_MMCR2 + 1)
 #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
arch/powerpc/perf/core-book3s.c +1 -0
index 31c0535..d5a9529 100644
@@ -2316,6 +2316,7 @@ int register_power_pmu(struct power_pmu *pmu)
 		pmu->name);
 
 	power_pmu.attr_groups = ppmu->attr_groups;
+	power_pmu.capabilities |= (ppmu->capabilities & PERF_PMU_CAP_EXTENDED_REGS);
 
 #ifdef MSR_HV
 	/*
arch/powerpc/perf/perf_regs.c +31 -3
index a213a0a..b0cf68f 100644
@@ -13,9 +13,11 @@
 #include <asm/ptrace.h>
 #include <asm/perf_regs.h>
 
+u64 PERF_REG_EXTENDED_MASK;
+
 #define PT_REGS_OFFSET(id, r) [id] = offsetof(struct pt_regs, r)
 
-#define REG_RESERVED (~((1ULL << PERF_REG_POWERPC_MAX) - 1))
+#define REG_RESERVED (~(PERF_REG_EXTENDED_MASK | PERF_REG_PMU_MASK))
 
 static unsigned int pt_regs_offset[PERF_REG_POWERPC_MAX] = {
 	PT_REGS_OFFSET(PERF_REG_POWERPC_R0,  gpr[0]),
@@ -69,10 +71,26 @@
 	PT_REGS_OFFSET(PERF_REG_POWERPC_MMCRA, dsisr),
 };
 
+/* Function to return the extended register values */
+static u64 get_ext_regs_value(int idx)
+{
+	switch (idx) {
+	case PERF_REG_POWERPC_MMCR0:
+		return mfspr(SPRN_MMCR0);
+	case PERF_REG_POWERPC_MMCR1:
+		return mfspr(SPRN_MMCR1);
+	case PERF_REG_POWERPC_MMCR2:
+		return mfspr(SPRN_MMCR2);
+	default: return 0;
+	}
+}
+
 u64 perf_reg_value(struct pt_regs *regs, int idx)
 {
-	if (WARN_ON_ONCE(idx >= PERF_REG_POWERPC_MAX))
-		return 0;
+	u64 PERF_REG_EXTENDED_MAX;
+
+	if (cpu_has_feature(CPU_FTR_ARCH_300))
+		PERF_REG_EXTENDED_MAX = PERF_REG_MAX_ISA_300;
 
 	if (idx == PERF_REG_POWERPC_SIER &&
 	   (IS_ENABLED(CONFIG_FSL_EMB_PERF_EVENT) ||
@@ -85,6 +103,16 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
 	    IS_ENABLED(CONFIG_PPC32)))
 		return 0;
 
+	if (idx >= PERF_REG_POWERPC_MAX && idx < PERF_REG_EXTENDED_MAX)
+		return get_ext_regs_value(idx);
+
+	/*
+	 * If the idx is referring to value beyond the
+	 * supported registers, return 0 with a warning
+	 */
+	if (WARN_ON_ONCE(idx >= PERF_REG_EXTENDED_MAX))
+		return 0;
+
 	return regs_get_register(regs, pt_regs_offset[idx]);
 }
 
arch/powerpc/perf/power9-pmu.c +6 -0
index 05dae38..2a57e93 100644
@@ -90,6 +90,8 @@ enum {
 #define POWER9_MMCRA_IFM3		0x00000000C0000000UL
 #define POWER9_MMCRA_BHRB_MASK		0x00000000C0000000UL
 
+extern u64 PERF_REG_EXTENDED_MASK;
+
 /* Nasty Power9 specific hack */
 #define PVR_POWER9_CUMULUS		0x00002000
 
@@ -434,6 +436,7 @@ static void power9_config_bhrb(u64 pmu_bhrb_filter)
 	.cache_events		= &power9_cache_events,
 	.attr_groups		= power9_pmu_attr_groups,
 	.bhrb_nr		= 32,
+	.capabilities           = PERF_PMU_CAP_EXTENDED_REGS,
 };
 
 int init_power9_pmu(void)
@@ -457,6 +460,9 @@ int init_power9_pmu(void)
 		}
 	}
 
+	/* Set the PERF_REG_EXTENDED_MASK here */
+	PERF_REG_EXTENDED_MASK = PERF_REG_PMU_MASK_300;
+
 	rc = register_power_pmu(&power9_pmu);
 	if (rc)
 		return rc;
#38 lore raw

Re: [v3 12/15] powerpc/perf: Add support for outputting extended regs in perf intr_regs

Em Thu, Jul 23, 2020 at 11:14:16AM +0530, kajoljain escreveu:

Quoted 88 lines · kajoljain
Quoted 85 lines · Athira Rajeev
Quoted 81 lines

From: Anju T Sudhakar <[email protected]>

Add support for perf extended register capability in powerpc. The capability flag PERF_PMU_CAP_EXTENDED_REGS, is used to indicate the PMU which support extended registers. The generic code define the mask of extended registers as 0 for non supported architectures.

Patch adds extended regs support for power9 platform by exposing MMCR0, MMCR1 and MMCR2 registers.

REG_RESERVED mask needs update to include extended regs. PERF_REG_EXTENDED_MASK, contains mask value of the supported registers, is defined at runtime in the kernel based on platform since the supported registers may differ from one processor version to another and hence the MASK value.

with patch
----------

available registers: r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r30 r31 nip msr orig_r3 ctr link xer ccr softe trap dar dsisr sier mmcra mmcr0 mmcr1 mmcr2

PERF_RECORD_SAMPLE(IP, 0x1): 4784/4784: 0 period: 1 addr: 0 ... intr regs: mask 0xffffffffffff ABI 64-bit

.... r0    0xc00000000012b77c
.... r1    0xc000003fe5e03930
.... r2    0xc000000001b0e000
.... r3    0xc000003fdcddf800
.... r4    0xc000003fc7880000
.... r5    0x9c422724be
.... r6    0xc000003fe5e03908
.... r7    0xffffff63bddc8706
.... r8    0x9e4
.... r9    0x0
.... r10   0x1
.... r11   0x0
.... r12   0xc0000000001299c0
.... r13   0xc000003ffffc4800
.... r14   0x0
.... r15   0x7fffdd8b8b00
.... r16   0x0
.... r17   0x7fffdd8be6b8
.... r18   0x7e7076607730
.... r19   0x2f
.... r20   0xc00000001fc26c68
.... r21   0xc0002041e4227e00
.... r22   0xc00000002018fb60
.... r23   0x1
.... r24   0xc000003ffec4d900
.... r25   0x80000000
.... r26   0x0
.... r27   0x1
.... r28   0x1
.... r29   0xc000000001be1260
.... r30   0x6008010
.... r31   0xc000003ffebb7218
.... nip   0xc00000000012b910
.... msr   0x9000000000009033
.... orig_r3 0xc00000000012b86c
.... ctr   0xc0000000001299c0
.... link  0xc00000000012b77c
.... xer   0x0
.... ccr   0x28002222

.... softe 0x1
.... trap 0xf00
.... dar 0x0
.... dsisr 0x80000000000
.... sier 0x0
.... mmcra 0x80000000000
.... mmcr0 0x82008090
.... mmcr1 0x1e000000
.... mmcr2 0x0
... thread: perf:4784

[Defined PERF_REG_EXTENDED_MASK at run time to add support for different platforms ]

---

Quoted 7 lines
Quoted 3 lines

Patch looks good to me.

Hi Arnaldo and Jiri,
Please let me know if you have any comments on these patches. Can you pull/ack these
patches if they seems fine to you.

Can you please clarify something here, I think I saw a kernel build bot complaint followed by a fix, in these cases I think, for reviewer's sake, that this would entail a v4 patchkit? One that has no such build issues?

Or have I got something wrong?

- Arnaldo

#39 lore raw

Re: [v3 12/15] powerpc/perf: Add support for outputting extended regs in perf intr_regs

Quoted 101 lines · Arnaldo Carvalho de Melo

Em Thu, Jul 23, 2020 at 11:14:16AM +0530, kajoljain escreveu:

Quoted 88 lines · kajoljain
Quoted 85 lines · Athira Rajeev
Quoted 81 lines

From: Anju T Sudhakar <[email protected]>

Add support for perf extended register capability in powerpc. The capability flag PERF_PMU_CAP_EXTENDED_REGS, is used to indicate the PMU which support extended registers. The generic code define the mask of extended registers as 0 for non supported architectures.

Patch adds extended regs support for power9 platform by exposing MMCR0, MMCR1 and MMCR2 registers.

REG_RESERVED mask needs update to include extended regs. PERF_REG_EXTENDED_MASK, contains mask value of the supported registers, is defined at runtime in the kernel based on platform since the supported registers may differ from one processor version to another and hence the MASK value.

with patch
----------

available registers: r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r20 r21 r22 r23 r24 r25 r26 r27 r28 r29 r30 r31 nip msr orig_r3 ctr link xer ccr softe trap dar dsisr sier mmcra mmcr0 mmcr1 mmcr2

PERF_RECORD_SAMPLE(IP, 0x1): 4784/4784: 0 period: 1 addr: 0 ... intr regs: mask 0xffffffffffff ABI 64-bit

.... r0    0xc00000000012b77c
.... r1    0xc000003fe5e03930
.... r2    0xc000000001b0e000
.... r3    0xc000003fdcddf800
.... r4    0xc000003fc7880000
.... r5    0x9c422724be
.... r6    0xc000003fe5e03908
.... r7    0xffffff63bddc8706
.... r8    0x9e4
.... r9    0x0
.... r10   0x1
.... r11   0x0
.... r12   0xc0000000001299c0
.... r13   0xc000003ffffc4800
.... r14   0x0
.... r15   0x7fffdd8b8b00
.... r16   0x0
.... r17   0x7fffdd8be6b8
.... r18   0x7e7076607730
.... r19   0x2f
.... r20   0xc00000001fc26c68
.... r21   0xc0002041e4227e00
.... r22   0xc00000002018fb60
.... r23   0x1
.... r24   0xc000003ffec4d900
.... r25   0x80000000
.... r26   0x0
.... r27   0x1
.... r28   0x1
.... r29   0xc000000001be1260
.... r30   0x6008010
.... r31   0xc000003ffebb7218
.... nip   0xc00000000012b910
.... msr   0x9000000000009033
.... orig_r3 0xc00000000012b86c
.... ctr   0xc0000000001299c0
.... link  0xc00000000012b77c
.... xer   0x0
.... ccr   0x28002222

.... softe 0x1
.... trap 0xf00
.... dar 0x0
.... dsisr 0x80000000000
.... sier 0x0
.... mmcra 0x80000000000
.... mmcr0 0x82008090
.... mmcr1 0x1e000000
.... mmcr2 0x0
... thread: perf:4784

[Defined PERF_REG_EXTENDED_MASK at run time to add support for different platforms ]

---

Quoted 7 lines
Quoted 3 lines

Patch looks good to me.

Hi Arnaldo and Jiri,
Please let me know if you have any comments on these patches. Can you pull/ack these
patches if they seems fine to you.

Quoted 6 lines

Can you please clarify something here, I think I saw a kernel build bot complaint followed by a fix, in these cases I think, for reviewer's sake, that this would entail a v4 patchkit? One that has no such build issues?

Or have I got something wrong?

Hi Arnaldo,

yes you are right, I will send version 4 as a new series with changes to add support for extended regs and including fix for the build issue. Thanks for your response.

Athira

Quoted 2 lines

- Arnaldo

#40 lore raw

Re: [v3 12/15] powerpc/perf: Add support for outputting extended regs in perf intr_regs

In reply to Athira Rajeev

Hi Athira,

Quoted 9 lines
arch/powerpc/perf/perf_regs.c +9 -0
+/* Function to return the extended register values */
+static u64 get_ext_regs_value(int idx)
+{
+	switch (idx) {
+	case PERF_REG_POWERPC_MMCR0:
+		return mfspr(SPRN_MMCR0);
+	case PERF_REG_POWERPC_MMCR1:
+		return mfspr(SPRN_MMCR1);
+	case PERF_REG_POWERPC_MMCR2:

arch/powerpc/perf/perf_regs.c line 90

Quoted 10 lines
arch/powerpc/perf/perf_regs.c +6 -2
+		return mfspr(SPRN_MMCR2);
+	default: return 0;
+	}
+}
+
  u64 perf_reg_value(struct pt_regs *regs, int idx)
  {
-	if (WARN_ON_ONCE(idx >= PERF_REG_POWERPC_MAX))
-		return 0;
+	u64 PERF_REG_EXTENDED_MAX;

PERF_REG_EXTENDED_MAX should be initialized. otherwise ...

arch/powerpc/perf/perf_regs.c u64 perf_reg_value(struct pt_regs *regs, int idx) · line 107

Quoted 12 lines
arch/powerpc/perf/perf_regs.c +5 -0
+
+	if (cpu_has_feature(CPU_FTR_ARCH_300))
+		PERF_REG_EXTENDED_MAX = PERF_REG_MAX_ISA_300;
 
  	if (idx == PERF_REG_POWERPC_SIER &&
  	   (IS_ENABLED(CONFIG_FSL_EMB_PERF_EVENT) ||
@@ -85,6 +103,16 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
  	    IS_ENABLED(CONFIG_PPC32)))
  		return 0;
 
+	if (idx >= PERF_REG_POWERPC_MAX && idx < PERF_REG_EXTENDED_MAX)
+		return get_ext_regs_value(idx);

On non p9/p10 machine, PERF_REG_EXTENDED_MAX may contain random value which will allow user to pass this if condition unintentionally.

Neat: PERF_REG_EXTENDED_MAX is a local variable so it should be in lowercase. Any specific reason to define it in capital?

Ravi

#41 lore raw

Re: [v3 12/15] powerpc/perf: Add support for outputting extended regs in perf intr_regs

Quoted 43 lines · Ravi Bangoria

Hi Athira,

Quoted 9 lines
arch/powerpc/perf/perf_regs.c +9 -0
+/* Function to return the extended register values */
+static u64 get_ext_regs_value(int idx)
+{
+	switch (idx) {
+	case PERF_REG_POWERPC_MMCR0:
+		return mfspr(SPRN_MMCR0);
+	case PERF_REG_POWERPC_MMCR1:
+		return mfspr(SPRN_MMCR1);
+	case PERF_REG_POWERPC_MMCR2:

arch/powerpc/perf/perf_regs.c line 90

Quoted 10 lines
arch/powerpc/perf/perf_regs.c +6 -2
+		return mfspr(SPRN_MMCR2);
+	default: return 0;
+	}
+}
+
 u64 perf_reg_value(struct pt_regs *regs, int idx)
 {
-	if (WARN_ON_ONCE(idx >= PERF_REG_POWERPC_MAX))
-		return 0;
+	u64 PERF_REG_EXTENDED_MAX;

PERF_REG_EXTENDED_MAX should be initialized. otherwise ...

arch/powerpc/perf/perf_regs.c u64 perf_reg_value(struct pt_regs *regs, int idx) · line 106

Quoted 10 lines
arch/powerpc/perf/perf_regs.c +4 -0
+
+	if (cpu_has_feature(CPU_FTR_ARCH_300))
+		PERF_REG_EXTENDED_MAX = PERF_REG_MAX_ISA_300;
   	if (idx == PERF_REG_POWERPC_SIER &&
 	   (IS_ENABLED(CONFIG_FSL_EMB_PERF_EVENT) ||
@@ -85,6 +103,16 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
 	    IS_ENABLED(CONFIG_PPC32)))
 		return 0;
 +	if (idx >= PERF_REG_POWERPC_MAX && idx < PERF_REG_EXTENDED_MAX)
+		return get_ext_regs_value(idx);

On non p9/p10 machine, PERF_REG_EXTENDED_MAX may contain random value which will allow user to pass this if condition unintentionally.

Quoted 2 lines

Neat: PERF_REG_EXTENDED_MAX is a local variable so it should be in lowercase. Any specific reason to define it in capital?

Hi Ravi

There is no specific reason. I will include both these changes in next version

Thanks
Athira Rajeev

Quoted 2 lines

Ravi

#42 lore raw

PATCH v3 13/15 tools/perf: Add perf tools support for extended register capability in powerpc

In reply to Athira Rajeev

From: Anju T Sudhakar <[email protected]>

Add extended regs to sample_reg_mask in the tool side to use with -I? option. Perf tools side uses extended mask to display the platform supported register names (with -I? option) to the user and also send this mask to the kernel to capture the extended registers in each sample. Hence decide the mask value based on the processor version.

Currently definitions for mfspr, SPRN_PVR are part of arch/powerpc/util/header.c. Move this to a header file so that these definitions can be re-used in other source files as well.

[Decide extended mask at run time based on platform]
---
 tools/arch/powerpc/include/uapi/asm/perf_regs.h | 14 ++++++-
 tools/perf/arch/powerpc/include/perf_regs.h     |  5 ++-
 tools/perf/arch/powerpc/util/header.c           |  9 +----
 tools/perf/arch/powerpc/util/perf_regs.c        | 49 +++++++++++++++++++++++++
 tools/perf/arch/powerpc/util/utils_header.h     | 15 ++++++++
 5 files changed, 82 insertions(+), 10 deletions(-)
 create mode 100644 tools/perf/arch/powerpc/util/utils_header.h
tools/arch/powerpc/include/uapi/asm/perf_regs.h +13 -1
index f599064..225c64c 100644
@@ -48,6 +48,18 @@ enum perf_event_powerpc_regs {
 	PERF_REG_POWERPC_DSISR,
 	PERF_REG_POWERPC_SIER,
 	PERF_REG_POWERPC_MMCRA,
-	PERF_REG_POWERPC_MAX,
+	/* Extended registers */
+	PERF_REG_POWERPC_MMCR0,
+	PERF_REG_POWERPC_MMCR1,
+	PERF_REG_POWERPC_MMCR2,
+	/* Max regs without the extended regs */
+	PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
 };
+
+#define PERF_REG_PMU_MASK	((1ULL << PERF_REG_POWERPC_MAX) - 1)
+
+/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300 */
+#define PERF_REG_PMU_MASK_300   (((1ULL << (PERF_REG_POWERPC_MMCR2 + 1)) - 1) - PERF_REG_PMU_MASK)
+
+#define PERF_REG_MAX_ISA_300   (PERF_REG_POWERPC_MMCR2 + 1)
 #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
tools/perf/arch/powerpc/include/perf_regs.h +4 -1
index e18a355..46ed00d 100644
@@ -64,7 +64,10 @@
 	[PERF_REG_POWERPC_DAR] = "dar",
 	[PERF_REG_POWERPC_DSISR] = "dsisr",
 	[PERF_REG_POWERPC_SIER] = "sier",
-	[PERF_REG_POWERPC_MMCRA] = "mmcra"
+	[PERF_REG_POWERPC_MMCRA] = "mmcra",
+	[PERF_REG_POWERPC_MMCR0] = "mmcr0",
+	[PERF_REG_POWERPC_MMCR1] = "mmcr1",
+	[PERF_REG_POWERPC_MMCR2] = "mmcr2",
 };
 
 static inline const char *perf_reg_name(int id)
tools/perf/arch/powerpc/util/header.c +1 -8
index d487007..1a95017 100644
@@ -7,17 +7,10 @@
 #include <string.h>
 #include <linux/stringify.h>
 #include "header.h"
+#include "utils_header.h"
 #include "metricgroup.h"
 #include <api/fs/fs.h>
 
-#define mfspr(rn)       ({unsigned long rval; \
-			 asm volatile("mfspr %0," __stringify(rn) \
-				      : "=r" (rval)); rval; })
-
-#define SPRN_PVR        0x11F	/* Processor Version Register */
-#define PVR_VER(pvr)    (((pvr) >>  16) & 0xFFFF) /* Version field */
-#define PVR_REV(pvr)    (((pvr) >>   0) & 0xFFFF) /* Revison field */
-
 int
 get_cpuid(char *buffer, size_t sz)
 {
tools/perf/arch/powerpc/util/perf_regs.c +49 -0

67 lines not on this page · raw message

tools/perf/arch/powerpc/util/utils_header.h new file +15 -0
new file mode 100644
index 0000000..5788eb1
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __PERF_UTIL_HEADER_H
+#define __PERF_UTIL_HEADER_H
+
+#include <linux/stringify.h>
+
+#define mfspr(rn)       ({unsigned long rval; \
+			asm volatile("mfspr %0," __stringify(rn) \
+				: "=r" (rval)); rval; })
+
+#define SPRN_PVR        0x11F   /* Processor Version Register */
+#define PVR_VER(pvr)    (((pvr) >>  16) & 0xFFFF) /* Version field */
+#define PVR_REV(pvr)    (((pvr) >>   0) & 0xFFFF) /* Revison field */
+
+#endif /* __PERF_UTIL_HEADER_H */
Signature · 1 line
1.8.3.1
Reviewed-by on v3 13/15
#43 lore raw

Re: [v3 13/15] tools/perf: Add perf tools support for extended register capability in powerpc

Quoted 17 lines · Athira Rajeev

From: Anju T Sudhakar <[email protected]>

Add extended regs to sample_reg_mask in the tool side to use with -I? option. Perf tools side uses extended mask to display the platform supported register names (with -I? option) to the user and also send this mask to the kernel to capture the extended registers in each sample. Hence decide the mask value based on the processor version.

Currently definitions for mfspr, SPRN_PVR are part of arch/powerpc/util/header.c. Move this to a header file so that these definitions can be re-used in other source files as well.

[Decide extended mask at run time based on platform]
Quoted 9 lines
---
 tools/arch/powerpc/include/uapi/asm/perf_regs.h | 14 ++++++-
 tools/perf/arch/powerpc/include/perf_regs.h     |  5 ++-
 tools/perf/arch/powerpc/util/header.c           |  9 +----
 tools/perf/arch/powerpc/util/perf_regs.c        | 49 +++++++++++++++++++++++++
 tools/perf/arch/powerpc/util/utils_header.h     | 15 ++++++++
 5 files changed, 82 insertions(+), 10 deletions(-)
 create mode 100644 tools/perf/arch/powerpc/util/utils_header.h

Thanks,
Kajol Jain

Quoted 159 lines
tools/arch/powerpc/include/uapi/asm/perf_regs.h +13 -1
index f599064..225c64c 100644
@@ -48,6 +48,18 @@ enum perf_event_powerpc_regs {
 	PERF_REG_POWERPC_DSISR,
 	PERF_REG_POWERPC_SIER,
 	PERF_REG_POWERPC_MMCRA,
-	PERF_REG_POWERPC_MAX,
+	/* Extended registers */
+	PERF_REG_POWERPC_MMCR0,
+	PERF_REG_POWERPC_MMCR1,
+	PERF_REG_POWERPC_MMCR2,
+	/* Max regs without the extended regs */
+	PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
 };
+
+#define PERF_REG_PMU_MASK	((1ULL << PERF_REG_POWERPC_MAX) - 1)
+
+/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300 */
+#define PERF_REG_PMU_MASK_300   (((1ULL << (PERF_REG_POWERPC_MMCR2 + 1)) - 1) - PERF_REG_PMU_MASK)
+
+#define PERF_REG_MAX_ISA_300   (PERF_REG_POWERPC_MMCR2 + 1)
 #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
tools/perf/arch/powerpc/include/perf_regs.h +4 -1
index e18a355..46ed00d 100644
@@ -64,7 +64,10 @@
 	[PERF_REG_POWERPC_DAR] = "dar",
 	[PERF_REG_POWERPC_DSISR] = "dsisr",
 	[PERF_REG_POWERPC_SIER] = "sier",
-	[PERF_REG_POWERPC_MMCRA] = "mmcra"
+	[PERF_REG_POWERPC_MMCRA] = "mmcra",
+	[PERF_REG_POWERPC_MMCR0] = "mmcr0",
+	[PERF_REG_POWERPC_MMCR1] = "mmcr1",
+	[PERF_REG_POWERPC_MMCR2] = "mmcr2",
 };
 
 static inline const char *perf_reg_name(int id)
tools/perf/arch/powerpc/util/header.c +1 -8
index d487007..1a95017 100644
@@ -7,17 +7,10 @@
 #include <string.h>
 #include <linux/stringify.h>
 #include "header.h"
+#include "utils_header.h"
 #include "metricgroup.h"
 #include <api/fs/fs.h>
 
-#define mfspr(rn)       ({unsigned long rval; \
-			 asm volatile("mfspr %0," __stringify(rn) \
-				      : "=r" (rval)); rval; })
-
-#define SPRN_PVR        0x11F	/* Processor Version Register */
-#define PVR_VER(pvr)    (((pvr) >>  16) & 0xFFFF) /* Version field */
-#define PVR_REV(pvr)    (((pvr) >>   0) & 0xFFFF) /* Revison field */
-
 int
 get_cpuid(char *buffer, size_t sz)
 {
tools/perf/arch/powerpc/util/perf_regs.c +49 -0
index 0a52429..d64ba0c 100644
@@ -6,9 +6,15 @@
 
 #include "../../../util/perf_regs.h"
 #include "../../../util/debug.h"
+#include "../../../util/event.h"
+#include "../../../util/header.h"
+#include "../../../perf-sys.h"
+#include "utils_header.h"
 
 #include <linux/kernel.h>
 
+#define PVR_POWER9		0x004E
+
 const struct sample_reg sample_reg_masks[] = {
 	SMPL_REG(r0, PERF_REG_POWERPC_R0),
 	SMPL_REG(r1, PERF_REG_POWERPC_R1),
@@ -55,6 +61,9 @@
 	SMPL_REG(dsisr, PERF_REG_POWERPC_DSISR),
 	SMPL_REG(sier, PERF_REG_POWERPC_SIER),
 	SMPL_REG(mmcra, PERF_REG_POWERPC_MMCRA),
+	SMPL_REG(mmcr0, PERF_REG_POWERPC_MMCR0),
+	SMPL_REG(mmcr1, PERF_REG_POWERPC_MMCR1),
+	SMPL_REG(mmcr2, PERF_REG_POWERPC_MMCR2),
 	SMPL_REG_END
 };
 
@@ -163,3 +172,43 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op)
 
 	return SDT_ARG_VALID;
 }
+
+uint64_t arch__intr_reg_mask(void)
+{
+	struct perf_event_attr attr = {
+		.type                   = PERF_TYPE_HARDWARE,
+		.config                 = PERF_COUNT_HW_CPU_CYCLES,
+		.sample_type            = PERF_SAMPLE_REGS_INTR,
+		.precise_ip             = 1,
+		.disabled               = 1,
+		.exclude_kernel         = 1,
+	};
+	int fd;
+	u32 version;
+	u64 extended_mask = 0, mask = PERF_REGS_MASK;
+
+	/*
+	 * Get the PVR value to set the extended
+	 * mask specific to platform.
+	 */
+	version = (((mfspr(SPRN_PVR)) >>  16) & 0xFFFF);
+	if (version == PVR_POWER9)
+		extended_mask = PERF_REG_PMU_MASK_300;
+	else
+		return mask;
+
+	attr.sample_regs_intr = extended_mask;
+	attr.sample_period = 1;
+	event_attr_init(&attr);
+
+	/*
+	 * check if the pmu supports perf extended regs, before
+	 * returning the register mask to sample.
+	 */
+	fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
+	if (fd != -1) {
+		close(fd);
+		mask |= extended_mask;
+	}
+	return mask;
+}
tools/perf/arch/powerpc/util/utils_header.h new file +15 -0
new file mode 100644
index 0000000..5788eb1
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __PERF_UTIL_HEADER_H
+#define __PERF_UTIL_HEADER_H
+
+#include <linux/stringify.h>
+
+#define mfspr(rn)       ({unsigned long rval; \
+			asm volatile("mfspr %0," __stringify(rn) \
+				: "=r" (rval)); rval; })
+
+#define SPRN_PVR        0x11F   /* Processor Version Register */
+#define PVR_VER(pvr)    (((pvr) >>  16) & 0xFFFF) /* Version field */
+#define PVR_REV(pvr)    (((pvr) >>   0) & 0xFFFF) /* Revison field */
+
+#endif /* __PERF_UTIL_HEADER_H */
#44 lore raw

Re: [v3 13/15] tools/perf: Add perf tools support for extended register capability in powerpc

In reply to Athira Rajeev

Hi Athira,

Quoted 9 lines · Athira Rajeev

From: Anju T Sudhakar <[email protected]>

Add extended regs to sample_reg_mask in the tool side to use with -I? option. Perf tools side uses extended mask to display the platform supported register names (with -I? option) to the user and also send this mask to the kernel to capture the extended registers in each sample. Hence decide the mask value based on the processor version.

Quoted 3 lines

Currently definitions for mfspr, SPRN_PVR are part of arch/powerpc/util/header.c. Move this to a header file so that these definitions can be re-used in other source files as well.

It seems this patch has a regression.

Without this patch:

  $ sudo ./perf record -I
  ^C[ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.458 MB perf.data (318 samples) ]

With this patch:

  $ sudo ./perf record -I
  Error:
  dummy:HG: PMU Hardware doesn't support sampling/overflow-interrupts. Try 'perf stat'

Ravi

#45 lore raw

Re: [v3 13/15] tools/perf: Add perf tools support for extended register capability in powerpc

Quoted 26 lines · Ravi Bangoria

Hi Athira,

Quoted 10 lines · Athira Rajeev

From: Anju T Sudhakar <[email protected]>
Add extended regs to sample_reg_mask in the tool side to use with -I? option. Perf tools side uses extended mask to display the platform supported register names (with -I? option) to the user and also send this mask to the kernel to capture the extended registers in each sample. Hence decide the mask value based on the processor version.
Currently definitions for mfspr, SPRN_PVR are part of arch/powerpc/util/header.c. Move this to a header file so that these definitions can be re-used in other source files as well.

It seems this patch has a regression.

Without this patch:

 $ sudo ./perf record -I
 ^C[ perf record: Woken up 1 times to write data ]
 [ perf record: Captured and wrote 0.458 MB perf.data (318 samples) ]
Quoted 5 lines

With this patch:

 $ sudo ./perf record -I
 Error:
 dummy:HG: PMU Hardware doesn't support sampling/overflow-interrupts. Try 'perf stat'

Hi Ravi,

Thanks for reviewing this patch and also testing. The above issue happens since
commit 0a892c1c9472 ("perf record: Add dummy event during system wide synthesis”) which adds a dummy event.

The fix for this issue is currently discussed here: https://lkml.org/lkml/2020/7/19/413
So once this fix is in, the issue will be resolved.

Thanks
Athira

Quoted 2 lines

Ravi

#46 lore raw

PATCH v3 14/15 powerpc/perf: Add extended regs support for power10 platform

In reply to Athira Rajeev

Include capability flag PERF_PMU_CAP_EXTENDED_REGS for power10 and expose MMCR3, SIER2, SIER3 registers as part of extended regs. Also introduce PERF_REG_PMU_MASK_31 to define extended mask value at runtime for power10

[Fix build failure on PPC32 platform]
---
 arch/powerpc/include/uapi/asm/perf_regs.h |  6 ++++++
 arch/powerpc/perf/perf_regs.c             | 12 +++++++++++-
 arch/powerpc/perf/power10-pmu.c           |  6 ++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
arch/powerpc/include/uapi/asm/perf_regs.h +6 -0
index 225c64c..bdf5f10 100644
@@ -52,6 +52,9 @@ enum perf_event_powerpc_regs {
 	PERF_REG_POWERPC_MMCR0,
 	PERF_REG_POWERPC_MMCR1,
 	PERF_REG_POWERPC_MMCR2,
+	PERF_REG_POWERPC_MMCR3,
+	PERF_REG_POWERPC_SIER2,
+	PERF_REG_POWERPC_SIER3,
 	/* Max regs without the extended regs */
 	PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
 };
@@ -60,6 +63,9 @@ enum perf_event_powerpc_regs {
 
 /* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300 */
 #define PERF_REG_PMU_MASK_300   (((1ULL << (PERF_REG_POWERPC_MMCR2 + 1)) - 1) - PERF_REG_PMU_MASK)
+/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_31 */
+#define PERF_REG_PMU_MASK_31   (((1ULL << (PERF_REG_POWERPC_SIER3 + 1)) - 1) - PERF_REG_PMU_MASK)
 
 #define PERF_REG_MAX_ISA_300   (PERF_REG_POWERPC_MMCR2 + 1)
+#define PERF_REG_MAX_ISA_31    (PERF_REG_POWERPC_SIER3 + 1)
 #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
arch/powerpc/perf/perf_regs.c +11 -1
index b0cf68f..11b90d5 100644
@@ -81,6 +81,14 @@ static u64 get_ext_regs_value(int idx)
 		return mfspr(SPRN_MMCR1);
 	case PERF_REG_POWERPC_MMCR2:
 		return mfspr(SPRN_MMCR2);
+#ifdef CONFIG_PPC64
+	case PERF_REG_POWERPC_MMCR3:
+		return mfspr(SPRN_MMCR3);
+	case PERF_REG_POWERPC_SIER2:
+		return mfspr(SPRN_SIER2);
+	case PERF_REG_POWERPC_SIER3:
+		return mfspr(SPRN_SIER3);
+#endif
 	default: return 0;
 	}
 }
@@ -89,7 +97,9 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
 {
 	u64 PERF_REG_EXTENDED_MAX;
 
-	if (cpu_has_feature(CPU_FTR_ARCH_300))
+	if (cpu_has_feature(CPU_FTR_ARCH_31))
+		PERF_REG_EXTENDED_MAX = PERF_REG_MAX_ISA_31;
+	else if (cpu_has_feature(CPU_FTR_ARCH_300))
 		PERF_REG_EXTENDED_MAX = PERF_REG_MAX_ISA_300;
 
 	if (idx = PERF_REG_POWERPC_SIER &&
arch/powerpc/perf/power10-pmu.c +6 -0
index b02aabb..f066ed9 100644
@@ -87,6 +87,8 @@
 #define POWER10_MMCRA_IFM3		0x00000000C0000000UL
 #define POWER10_MMCRA_BHRB_MASK		0x00000000C0000000UL
 
+extern u64 PERF_REG_EXTENDED_MASK;
+
 /* Table of alternatives, sorted by column 0 */
 static const unsigned int power10_event_alternatives[][MAX_ALT] = {
 	{ PM_RUN_CYC_ALT,		PM_RUN_CYC },
@@ -397,6 +399,7 @@ static void power10_config_bhrb(u64 pmu_bhrb_filter)
 	.cache_events		= &power10_cache_events,
 	.attr_groups		= power10_pmu_attr_groups,
 	.bhrb_nr		= 32,
+	.capabilities           = PERF_PMU_CAP_EXTENDED_REGS,
 };
 
 int init_power10_pmu(void)
@@ -408,6 +411,9 @@ int init_power10_pmu(void)
 	    strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power10"))
 		return -ENODEV;
 
+	/* Set the PERF_REG_EXTENDED_MASK here */
+	PERF_REG_EXTENDED_MASK = PERF_REG_PMU_MASK_31;
+
 	rc = register_power_pmu(&power10_pmu);
 	if (rc)
 		return rc;
Signature · 1 line
1.8.3.1
Reviewed-by on v3 14/15
#47 lore raw

Re: [v3 14/15] powerpc/perf: Add extended regs support for power10 platform

Quoted 9 lines · Athira Rajeev

Include capability flag PERF_PMU_CAP_EXTENDED_REGS for power10 and expose MMCR3, SIER2, SIER3 registers as part of extended regs. Also introduce PERF_REG_PMU_MASK_31 to define extended mask value at runtime for power10

[Fix build failure on PPC32 platform]
Quoted 6 lines
---
 arch/powerpc/include/uapi/asm/perf_regs.h |  6 ++++++
 arch/powerpc/perf/perf_regs.c             | 12 +++++++++++-
 arch/powerpc/perf/power10-pmu.c           |  6 ++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

Thanks,
Kajol Jain

Quoted 86 lines
arch/powerpc/include/uapi/asm/perf_regs.h +6 -0
index 225c64c..bdf5f10 100644
@@ -52,6 +52,9 @@ enum perf_event_powerpc_regs {
 	PERF_REG_POWERPC_MMCR0,
 	PERF_REG_POWERPC_MMCR1,
 	PERF_REG_POWERPC_MMCR2,
+	PERF_REG_POWERPC_MMCR3,
+	PERF_REG_POWERPC_SIER2,
+	PERF_REG_POWERPC_SIER3,
 	/* Max regs without the extended regs */
 	PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
 };
@@ -60,6 +63,9 @@ enum perf_event_powerpc_regs {
 
 /* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300 */
 #define PERF_REG_PMU_MASK_300   (((1ULL << (PERF_REG_POWERPC_MMCR2 + 1)) - 1) - PERF_REG_PMU_MASK)
+/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_31 */
+#define PERF_REG_PMU_MASK_31   (((1ULL << (PERF_REG_POWERPC_SIER3 + 1)) - 1) - PERF_REG_PMU_MASK)
 
 #define PERF_REG_MAX_ISA_300   (PERF_REG_POWERPC_MMCR2 + 1)
+#define PERF_REG_MAX_ISA_31    (PERF_REG_POWERPC_SIER3 + 1)
 #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
arch/powerpc/perf/perf_regs.c +11 -1
index b0cf68f..11b90d5 100644
@@ -81,6 +81,14 @@ static u64 get_ext_regs_value(int idx)
 		return mfspr(SPRN_MMCR1);
 	case PERF_REG_POWERPC_MMCR2:
 		return mfspr(SPRN_MMCR2);
+#ifdef CONFIG_PPC64
+	case PERF_REG_POWERPC_MMCR3:
+		return mfspr(SPRN_MMCR3);
+	case PERF_REG_POWERPC_SIER2:
+		return mfspr(SPRN_SIER2);
+	case PERF_REG_POWERPC_SIER3:
+		return mfspr(SPRN_SIER3);
+#endif
 	default: return 0;
 	}
 }
@@ -89,7 +97,9 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
 {
 	u64 PERF_REG_EXTENDED_MAX;
 
-	if (cpu_has_feature(CPU_FTR_ARCH_300))
+	if (cpu_has_feature(CPU_FTR_ARCH_31))
+		PERF_REG_EXTENDED_MAX = PERF_REG_MAX_ISA_31;
+	else if (cpu_has_feature(CPU_FTR_ARCH_300))
 		PERF_REG_EXTENDED_MAX = PERF_REG_MAX_ISA_300;
 
 	if (idx == PERF_REG_POWERPC_SIER &&
arch/powerpc/perf/power10-pmu.c +6 -0
index b02aabb..f066ed9 100644
@@ -87,6 +87,8 @@
 #define POWER10_MMCRA_IFM3		0x00000000C0000000UL
 #define POWER10_MMCRA_BHRB_MASK		0x00000000C0000000UL
 
+extern u64 PERF_REG_EXTENDED_MASK;
+
 /* Table of alternatives, sorted by column 0 */
 static const unsigned int power10_event_alternatives[][MAX_ALT] = {
 	{ PM_RUN_CYC_ALT,		PM_RUN_CYC },
@@ -397,6 +399,7 @@ static void power10_config_bhrb(u64 pmu_bhrb_filter)
 	.cache_events		= &power10_cache_events,
 	.attr_groups		= power10_pmu_attr_groups,
 	.bhrb_nr		= 32,
+	.capabilities           = PERF_PMU_CAP_EXTENDED_REGS,
 };
 
 int init_power10_pmu(void)
@@ -408,6 +411,9 @@ int init_power10_pmu(void)
 	    strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power10"))
 		return -ENODEV;
 
+	/* Set the PERF_REG_EXTENDED_MASK here */
+	PERF_REG_EXTENDED_MASK = PERF_REG_PMU_MASK_31;
+
 	rc = register_power_pmu(&power10_pmu);
 	if (rc)
 		return rc;
#48 lore raw

PATCH v3 15/15 tools/perf: Add perf tools support for extended regs in power10

In reply to Athira Rajeev

Added support for supported regs which are new in power10 ( MMCR3, SIER2, SIER3 ) to sample_reg_mask in the tool side to use with -I? option. Also added PVR check to send extended mask for power10 at kernel while capturing extended regs in each sample.

---
 tools/arch/powerpc/include/uapi/asm/perf_regs.h | 6 ++++++
 tools/perf/arch/powerpc/include/perf_regs.h     | 3 +++
 tools/perf/arch/powerpc/util/perf_regs.c        | 6 ++++++
 3 files changed, 15 insertions(+)
tools/arch/powerpc/include/uapi/asm/perf_regs.h +6 -0
index 225c64c..bdf5f10 100644
@@ -52,6 +52,9 @@ enum perf_event_powerpc_regs {
 	PERF_REG_POWERPC_MMCR0,
 	PERF_REG_POWERPC_MMCR1,
 	PERF_REG_POWERPC_MMCR2,
+	PERF_REG_POWERPC_MMCR3,
+	PERF_REG_POWERPC_SIER2,
+	PERF_REG_POWERPC_SIER3,
 	/* Max regs without the extended regs */
 	PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
 };
@@ -60,6 +63,9 @@ enum perf_event_powerpc_regs {
 
 /* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300 */
 #define PERF_REG_PMU_MASK_300   (((1ULL << (PERF_REG_POWERPC_MMCR2 + 1)) - 1) - PERF_REG_PMU_MASK)
+/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_31 */
+#define PERF_REG_PMU_MASK_31   (((1ULL << (PERF_REG_POWERPC_SIER3 + 1)) - 1) - PERF_REG_PMU_MASK)
 
 #define PERF_REG_MAX_ISA_300   (PERF_REG_POWERPC_MMCR2 + 1)
+#define PERF_REG_MAX_ISA_31    (PERF_REG_POWERPC_SIER3 + 1)
 #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
tools/perf/arch/powerpc/include/perf_regs.h +3 -0
index 46ed00d..63f3ac9 100644
@@ -68,6 +68,9 @@
 	[PERF_REG_POWERPC_MMCR0] = "mmcr0",
 	[PERF_REG_POWERPC_MMCR1] = "mmcr1",
 	[PERF_REG_POWERPC_MMCR2] = "mmcr2",
+	[PERF_REG_POWERPC_MMCR3] = "mmcr3",
+	[PERF_REG_POWERPC_SIER2] = "sier2",
+	[PERF_REG_POWERPC_SIER3] = "sier3",
 };
 
 static inline const char *perf_reg_name(int id)
tools/perf/arch/powerpc/util/perf_regs.c +6 -0
index d64ba0c..2b6d470 100644
@@ -14,6 +14,7 @@
 #include <linux/kernel.h>
 
 #define PVR_POWER9		0x004E
+#define PVR_POWER10		0x0080
 
 const struct sample_reg sample_reg_masks[] = {
 	SMPL_REG(r0, PERF_REG_POWERPC_R0),
@@ -64,6 +65,9 @@
 	SMPL_REG(mmcr0, PERF_REG_POWERPC_MMCR0),
 	SMPL_REG(mmcr1, PERF_REG_POWERPC_MMCR1),
 	SMPL_REG(mmcr2, PERF_REG_POWERPC_MMCR2),
+	SMPL_REG(mmcr3, PERF_REG_POWERPC_MMCR3),
+	SMPL_REG(sier2, PERF_REG_POWERPC_SIER2),
+	SMPL_REG(sier3, PERF_REG_POWERPC_SIER3),
 	SMPL_REG_END
 };
 
@@ -194,6 +198,8 @@ uint64_t arch__intr_reg_mask(void)
 	version = (((mfspr(SPRN_PVR)) >>  16) & 0xFFFF);
 	if (version = PVR_POWER9)
 		extended_mask = PERF_REG_PMU_MASK_300;
+	else if (version = PVR_POWER10)
+		extended_mask = PERF_REG_PMU_MASK_31;
 	else
 		return mask;
 
Signature · 1 line
1.8.3.1
Reviewed-by on v3 15/15
#49 lore raw

Re: [v3 15/15] tools/perf: Add perf tools support for extended regs in power10

Quoted 6 lines · Athira Rajeev

Added support for supported regs which are new in power10 ( MMCR3, SIER2, SIER3 ) to sample_reg_mask in the tool side to use with -I? option. Also added PVR check to send extended mask for power10 at kernel while capturing extended regs in each sample.

Quoted 7 lines
---
 tools/arch/powerpc/include/uapi/asm/perf_regs.h | 6 ++++++
 tools/perf/arch/powerpc/include/perf_regs.h     | 3 +++
 tools/perf/arch/powerpc/util/perf_regs.c        | 6 ++++++
 3 files changed, 15 insertions(+)

Thanks,
Kajol Jain

Quoted 70 lines
tools/arch/powerpc/include/uapi/asm/perf_regs.h +6 -0
index 225c64c..bdf5f10 100644
@@ -52,6 +52,9 @@ enum perf_event_powerpc_regs {
 	PERF_REG_POWERPC_MMCR0,
 	PERF_REG_POWERPC_MMCR1,
 	PERF_REG_POWERPC_MMCR2,
+	PERF_REG_POWERPC_MMCR3,
+	PERF_REG_POWERPC_SIER2,
+	PERF_REG_POWERPC_SIER3,
 	/* Max regs without the extended regs */
 	PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
 };
@@ -60,6 +63,9 @@ enum perf_event_powerpc_regs {
 
 /* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300 */
 #define PERF_REG_PMU_MASK_300   (((1ULL << (PERF_REG_POWERPC_MMCR2 + 1)) - 1) - PERF_REG_PMU_MASK)
+/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_31 */
+#define PERF_REG_PMU_MASK_31   (((1ULL << (PERF_REG_POWERPC_SIER3 + 1)) - 1) - PERF_REG_PMU_MASK)
 
 #define PERF_REG_MAX_ISA_300   (PERF_REG_POWERPC_MMCR2 + 1)
+#define PERF_REG_MAX_ISA_31    (PERF_REG_POWERPC_SIER3 + 1)
 #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
tools/perf/arch/powerpc/include/perf_regs.h +3 -0
index 46ed00d..63f3ac9 100644
@@ -68,6 +68,9 @@
 	[PERF_REG_POWERPC_MMCR0] = "mmcr0",
 	[PERF_REG_POWERPC_MMCR1] = "mmcr1",
 	[PERF_REG_POWERPC_MMCR2] = "mmcr2",
+	[PERF_REG_POWERPC_MMCR3] = "mmcr3",
+	[PERF_REG_POWERPC_SIER2] = "sier2",
+	[PERF_REG_POWERPC_SIER3] = "sier3",
 };
 
 static inline const char *perf_reg_name(int id)
tools/perf/arch/powerpc/util/perf_regs.c +6 -0
index d64ba0c..2b6d470 100644
@@ -14,6 +14,7 @@
 #include <linux/kernel.h>
 
 #define PVR_POWER9		0x004E
+#define PVR_POWER10		0x0080
 
 const struct sample_reg sample_reg_masks[] = {
 	SMPL_REG(r0, PERF_REG_POWERPC_R0),
@@ -64,6 +65,9 @@
 	SMPL_REG(mmcr0, PERF_REG_POWERPC_MMCR0),
 	SMPL_REG(mmcr1, PERF_REG_POWERPC_MMCR1),
 	SMPL_REG(mmcr2, PERF_REG_POWERPC_MMCR2),
+	SMPL_REG(mmcr3, PERF_REG_POWERPC_MMCR3),
+	SMPL_REG(sier2, PERF_REG_POWERPC_SIER2),
+	SMPL_REG(sier3, PERF_REG_POWERPC_SIER3),
 	SMPL_REG_END
 };
 
@@ -194,6 +198,8 @@ uint64_t arch__intr_reg_mask(void)
 	version = (((mfspr(SPRN_PVR)) >>  16) & 0xFFFF);
 	if (version == PVR_POWER9)
 		extended_mask = PERF_REG_PMU_MASK_300;
+	else if (version == PVR_POWER10)
+		extended_mask = PERF_REG_PMU_MASK_31;
 	else
 		return mask;
 
#50 lore raw
In reply to Athira Rajeev
Quoted 11 lines · Athira Rajeev

The patch series adds support for power10 PMU hardware.

Patches 1..3 are the clean up patches which refactors the way how PMU SPR's are stored in core-book3s and in KVM book3s, as well as update data type for PMU cache_events.

Patches 12 and 13 adds base support for perf extended register capability in powerpc. Support for extended regs in power10 is covered in patches 14,15

[...]

Patches 1-11 applied to powerpc/next.

[01/15] powerpc/perf: Update cpu_hw_event to use struct for storing MMCR registers

        https://git.kernel.org/powerpc/c/78d76819e6f04672989506e7792895a51438516e
[02/15] KVM: PPC: Book3S HV: Cleanup updates for kvm vcpu MMCR
        https://git.kernel.org/powerpc/c/7e4a145e5b675d5a9182f756950f001eaa256795
[03/15] powerpc/perf: Update Power PMU cache_events to u64 type
        https://git.kernel.org/powerpc/c/9d4fc86dcd510dab5521a6c891f9bf379b85a7e0
[04/15] powerpc/perf: Add support for ISA3.1 PMU SPRs
        https://git.kernel.org/powerpc/c/c718547e4a92d74089f862457adf1f617c498e16
[05/15] KVM: PPC: Book3S HV: Save/restore new PMU registers
        https://git.kernel.org/powerpc/c/5752fe0b811bb3cee531c52074921c6dd09dc42d
[06/15] powerpc/xmon: Add PowerISA v3.1 PMU SPRs
        https://git.kernel.org/powerpc/c/1979ae8c7215718c7a98f038bad0122034ad6529
[07/15] powerpc/perf: Add Power10 PMU feature to DT CPU features
        https://git.kernel.org/powerpc/c/9908c826d5ed150637a3a4c0eec5146a0c438f21
[08/15] powerpc/perf: power10 Performance Monitoring support
        https://git.kernel.org/powerpc/c/a64e697cef23b3d24bac700f6d66c8e2bf8efccc
[09/15] powerpc/perf: Ignore the BHRB kernel address filtering for P10
        https://git.kernel.org/powerpc/c/bfe3b1945d5e0531103b3d4ab3a367a1a156d99a
[10/15] powerpc/perf: Add Power10 BHRB filter support for PERF_SAMPLE_BRANCH_IND_CALL/COND
        https://git.kernel.org/powerpc/c/80350a4bac992e3404067d31ff901ae9ff76aaa8
[11/15] powerpc/perf: BHRB control to disable BHRB logic when not used
        https://git.kernel.org/powerpc/c/1cade527f6e9bec6a6412d0641643c359ada8096

cheers