Skip to contentSkip to conversation

Scorpion PMU support

PATCH Superseded Stephen Boyd 3 participants 11 messages Feb 13, 2015 – Feb 27, 2015

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Scorpion PMU support

These patches add support for the Scorpion PMU found on devices such as msm8660, qsd8x50, etc. The first patch is some groundwork to make functions more "generic". Even then we end up copying quite a bit of code from the Krait part into the Scorpion part with only subtle tweaks because two things happen:

1. We gain another "region" register, L2LPM
2. The way to access the region registers are with different cp15 instructions

I'm not sure how to make this better, suggestions are welcome.

Changes from v1:
* Added stub functions for CONFIG_CPU_V7=n
* Fixed L2LPM register accessors
* Exposed mp and !mp versions of PMU to userspace differently (mrutland)
* Dropped I-cache events that shouldn't be there (mrutland)
* Fixed branch misprediction event (mrutland)

Stephen Boyd (2):
ARM: perf: Preparatory work for Scorpion PMU support
ARM: perf: Add support for Scorpion PMUs

 Documentation/devicetree/bindings/arm/pmu.txt |   2 +
 arch/arm/kernel/perf_event_cpu.c              |   2 +
 arch/arm/kernel/perf_event_v7.c               | 504 +++++++++++++++++++++++---
 3 files changed, 467 insertions(+), 41 deletions(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

PATCH v2 1/2 ARM: perf: Preparatory work for Scorpion PMU support

Do some things to make the Krait PMU support code generic enough to be used by the Scorpion PMU support code.

* Rename the venum register functions to be venum instead of krait specific because the same registers exist on Scorpion

* Add a krait_decode_event() function to decode our Krait specific event encoding that's the same on Scorpion (modulo an extra region).

* Drop krait from krait_clear_pmresrn_group() so it can be used by Scorpion code

---
 arch/arm/kernel/perf_event_v7.c | 87 ++++++++++++++++++++++-------------------
 1 file changed, 46 insertions(+), 41 deletions(-)
arch/arm/kernel/perf_event_v7.c +46 -41
index 8993770c47de..84a3ec3bc592 100644
@@ -1141,19 +1141,19 @@ static void krait_write_pmresrn(int n, u32 val)
 	}
 }
 
-static u32 krait_read_vpmresr0(void)
+static u32 venum_read_pmresr(void)
 {
 	u32 val;
 	asm volatile("mrc p10, 7, %0, c11, c0, 0" : "=r" (val));
 	return val;
 }
 
-static void krait_write_vpmresr0(u32 val)
+static void venum_write_pmresr(u32 val)
 {
 	asm volatile("mcr p10, 7, %0, c11, c0, 0" : : "r" (val));
 }
 
-static void krait_pre_vpmresr0(u32 *venum_orig_val, u32 *fp_orig_val)
+static void venum_pre_pmresr(u32 *venum_orig_val, u32 *fp_orig_val)
 {
 	u32 venum_new_val;
 	u32 fp_new_val;
@@ -1170,7 +1170,7 @@ static void krait_pre_vpmresr0(u32 *venum_orig_val, u32 *fp_orig_val)
 	fmxr(FPEXC, fp_new_val);
 }
 
-static void krait_post_vpmresr0(u32 venum_orig_val, u32 fp_orig_val)
+static void venum_post_pmresr(u32 venum_orig_val, u32 fp_orig_val)
 {
 	BUG_ON(preemptible());
 	/* Restore FPEXC */
@@ -1188,6 +1188,21 @@ static u32 krait_get_pmresrn_event(unsigned int region)
 	return pmresrn_table[region];
 }
 
+static void krait_decode_event(u32 event, unsigned int *region,
+		unsigned int *group, unsigned int *code, bool *venum, bool *cpu)
+{
+	if (region)
+		*region = (event >> 12) & 0xf;
+	if (group)
+		*group  = (event >> 0)  & 0xf;
+	if (code)
+		*code   = (event >> 4) & 0xff;
+	if (venum)
+		*venum  = !!(event & VENUM_EVENT);
+	if (cpu)
+		*cpu = !!(event & KRAIT_EVENT);
+}
+
 static void krait_evt_setup(int idx, u32 config_base)
 {
 	u32 val;
@@ -1199,10 +1214,8 @@ static void krait_evt_setup(int idx, u32 config_base)
 	unsigned int group_shift;
 	bool venum_event;
 
-	venum_event = !!(config_base & VENUM_EVENT);
-	region = (config_base >> 12) & 0xf;
-	code   = (config_base >> 4) & 0xff;
-	group  = (config_base >> 0)  & 0xf;
+	krait_decode_event(config_base, &region, &group, &code, &venum_event,
+			   NULL);
 
 	group_shift = group * 8;
 	mask = 0xff << group_shift;
@@ -1220,13 +1233,13 @@ static void krait_evt_setup(int idx, u32 config_base)
 	asm volatile("mcr p15, 0, %0, c9, c15, 0" : : "r" (0));
 
 	if (venum_event) {
-		krait_pre_vpmresr0(&vval, &fval);
-		val = krait_read_vpmresr0();
+		venum_pre_pmresr(&vval, &fval);
+		val = venum_read_pmresr();
 		val &= ~mask;
 		val |= code << group_shift;
 		val |= PMRESRn_EN;
-		krait_write_vpmresr0(val);
-		krait_post_vpmresr0(vval, fval);
+		venum_write_pmresr(val);
+		venum_post_pmresr(vval, fval);
 	} else {
 		val = krait_read_pmresrn(region);
 		val &= ~mask;
@@ -1236,7 +1249,7 @@ static void krait_evt_setup(int idx, u32 config_base)
 	}
 }
 
-static u32 krait_clear_pmresrn_group(u32 val, int group)
+static u32 clear_pmresrn_group(u32 val, int group)
 {
 	u32 mask;
 	int group_shift;
@@ -1260,19 +1273,18 @@ static void krait_clearpmu(u32 config_base)
 	unsigned int group;
 	bool venum_event;
 
-	venum_event = !!(config_base & VENUM_EVENT);
-	region = (config_base >> 12) & 0xf;
-	group  = (config_base >> 0)  & 0xf;
+	krait_decode_event(config_base, &region, &group, NULL, &venum_event,
+			   NULL);
 
 	if (venum_event) {
-		krait_pre_vpmresr0(&vval, &fval);
-		val = krait_read_vpmresr0();
-		val = krait_clear_pmresrn_group(val, group);
-		krait_write_vpmresr0(val);
-		krait_post_vpmresr0(vval, fval);
+		venum_pre_pmresr(&vval, &fval);
+		val = venum_read_pmresr();
+		val = clear_pmresrn_group(val, group);
+		venum_write_pmresr(val);
+		venum_post_pmresr(vval, fval);
 	} else {
 		val = krait_read_pmresrn(region);
-		val = krait_clear_pmresrn_group(val, group);
+		val = clear_pmresrn_group(val, group);
 		krait_write_pmresrn(region, val);
 	}
 }
@@ -1350,9 +1362,9 @@ static void krait_pmu_reset(void *info)
 	krait_write_pmresrn(1, 0);
 	krait_write_pmresrn(2, 0);
 
-	krait_pre_vpmresr0(&vval, &fval);
-	krait_write_vpmresr0(0);
-	krait_post_vpmresr0(vval, fval);
+	venum_pre_pmresr(&vval, &fval);
+	venum_write_pmresr(0);
+	venum_post_pmresr(vval, fval);
 }
 
 static int krait_event_to_bit(struct perf_event *event, unsigned int region,
@@ -1386,26 +1398,20 @@ static int krait_pmu_get_event_idx(struct pmu_hw_events *cpuc,
 {
 	int idx;
 	int bit = -1;
-	unsigned int prefix;
 	unsigned int region;
 	unsigned int code;
 	unsigned int group;
-	bool krait_event;
+	bool venum_event, krait_event;
 	struct hw_perf_event *hwc = &event->hw;
 
-	region = (hwc->config_base >> 12) & 0xf;
-	code   = (hwc->config_base >> 4) & 0xff;
-	group  = (hwc->config_base >> 0) & 0xf;
-	krait_event = !!(hwc->config_base & KRAIT_EVENT_MASK);
+	krait_decode_event(hwc->config_base, &region, &group, &code,
+			   &venum_event, &krait_event);
 
-	if (krait_event) {
+	if (venum_event || krait_event) {
 		/* Ignore invalid events */
 		if (group > 3 || region > 2)
 			return -EINVAL;
-		prefix = hwc->config_base & KRAIT_EVENT_MASK;
-		if (prefix != KRAIT_EVENT && prefix != VENUM_EVENT)
-			return -EINVAL;
-		if (prefix == VENUM_EVENT && (code & 0xe0))
+		if (venum_event && (code & 0xe0))
 			return -EINVAL;
 
 		bit = krait_event_to_bit(event, region, group);
@@ -1427,13 +1433,12 @@ static void krait_pmu_clear_event_idx(struct pmu_hw_events *cpuc,
 	struct hw_perf_event *hwc = &event->hw;
 	unsigned int region;
 	unsigned int group;
-	bool krait_event;
+	bool venum_event, krait_event;
 
-	region = (hwc->config_base >> 12) & 0xf;
-	group  = (hwc->config_base >> 0) & 0xf;
-	krait_event = !!(hwc->config_base & KRAIT_EVENT_MASK);
+	krait_decode_event(hwc->config_base, &region, &group, NULL,
+			   &venum_event, &krait_event);
 
-	if (krait_event) {
+	if (venum_event || krait_event) {
 		bit = krait_event_to_bit(event, region, group);
 		clear_bit(bit, cpuc->used_mask);
 	}
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#4 lore raw

PATCH v2 2/2 ARM: perf: Add support for Scorpion PMUs

In reply to Stephen Boyd

Scorpion supports a set of local performance monitor event selection registers (LPM) sitting behind a cp15 based interface that extend the architected PMU events to include Scorpion CPU and Venum VFP specific events. To use these events the user is expected to program the lpm register with the event code shifted into the group they care about and then point the PMNx event at that region+group combo by writing a LPMn_GROUPx event. Add support for this hardware.

Note: the raw event number is a pure software construct that allows us to map the multi-dimensional number space of regions, groups, and event codes into a flat event number space suitable for use by the perf framework.

This is based on code originally written by Ashwin Chaugule and Neil Leeder [1] massaged to become similar to the Krait PMU support code.

[1] https://www.codeaurora.org/cgit/quic/la/kernel/msm/tree/arch/arm/kernel/perf_event_msm.c?h=msm-3.4

Cc Mark Rutland <[email protected]>
Cc Neil Leeder <[email protected]>
Cc Ashwin Chaugule <[email protected]>
---
 Documentation/devicetree/bindings/arm/pmu.txt |   2 +
 arch/arm/kernel/perf_event_cpu.c              |   2 +
 arch/arm/kernel/perf_event_v7.c               | 417 ++++++++++++++++++++++++++
 3 files changed, 421 insertions(+)
Documentation/devicetree/bindings/arm/pmu.txt +2 -0
index 75ef91d08f3b..6e54a9d88b7a 100644
@@ -18,6 +18,8 @@ Required properties:
 	"arm,arm11mpcore-pmu"
 	"arm,arm1176-pmu"
 	"arm,arm1136-pmu"
+	"qcom,scorpion-pmu"
+	"qcom,scorpion-mp-pmu"
 	"qcom,krait-pmu"
 - interrupts : 1 combined interrupt or 1 per core. If the interrupt is a per-cpu
                interrupt (PPI) then 1 interrupt should be specified.
arch/arm/kernel/perf_event_cpu.c +2 -0
index dd9acc95ebc0..4fbf1085f75a 100644
@@ -243,6 +243,8 @@ static struct of_device_id cpu_pmu_of_device_ids[] = {
 	{.compatible = "arm,arm1176-pmu",	.data = armv6_1176_pmu_init},
 	{.compatible = "arm,arm1136-pmu",	.data = armv6_1136_pmu_init},
 	{.compatible = "qcom,krait-pmu",	.data = krait_pmu_init},
+	{.compatible = "qcom,scorpion-pmu",	.data = scorpion_pmu_init},
+	{.compatible = "qcom,scorpion-mp-pmu",	.data = scorpion_mp_pmu_init},
 	{},
 };
 
arch/arm/kernel/perf_event_v7.c +417 -0

445 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw

Re: [PATCH v2 1/2] ARM: perf: Preparatory work for Scorpion PMU support

In reply to Stephen Boyd
Quoted 16 lines · Stephen Boyd

Do some things to make the Krait PMU support code generic enough to be used by the Scorpion PMU support code.

* Rename the venum register functions to be venum instead of krait specific because the same registers exist on Scorpion

* Add a krait_decode_event() function to decode our Krait specific event encoding that's the same on Scorpion (modulo an extra region).

* Drop krait from krait_clear_pmresrn_group() so it can be used by Scorpion code

---
 arch/arm/kernel/perf_event_v7.c | 87 ++++++++++++++++++++++-------------------
 1 file changed, 46 insertions(+), 41 deletions(-)

[...]

Quoted 4 lines
arch/arm/kernel/perf_event_v7.c +4 -0
+static void krait_decode_event(u32 event, unsigned int *region,
+		unsigned int *group, unsigned int *code, bool *venum, bool *cpu)
+{
+	if (region)

arch/arm/kernel/perf_event_v7.c static u32 krait_get_pmresrn_event(unsigned int region) · line 1204

Quoted 10 lines
arch/arm/kernel/perf_event_v7.c +10 -0
+		*region = (event >> 12) & 0xf;
+	if (group)
+		*group  = (event >> 0)  & 0xf;
+	if (code)
+		*code   = (event >> 4) & 0xff;
+	if (venum)
+		*venum  = !!(event & VENUM_EVENT);
+	if (cpu)
+		*cpu = !!(event & KRAIT_EVENT);
+}

Maybe worth sticking these fields in a struct? Failing that, just using macros for each one and using them in-line isn't so bad.

Will

#5 lore raw

Re: [PATCH v2 2/2] ARM: perf: Add support for Scorpion PMUs

In reply to Stephen Boyd
Quoted 30 lines · Stephen Boyd

Scorpion supports a set of local performance monitor event selection registers (LPM) sitting behind a cp15 based interface that extend the architected PMU events to include Scorpion CPU and Venum VFP specific events. To use these events the user is expected to program the lpm register with the event code shifted into the group they care about and then point the PMNx event at that region+group combo by writing a LPMn_GROUPx event. Add support for this hardware.

Note: the raw event number is a pure software construct that allows us to map the multi-dimensional number space of regions, groups, and event codes into a flat event number space suitable for use by the perf framework.

This is based on code originally written by Ashwin Chaugule and Neil Leeder [1] massaged to become similar to the Krait PMU support code.

[1] https://www.codeaurora.org/cgit/quic/la/kernel/msm/tree/arch/arm/kernel/perf_event_msm.c?h=msm-3.4

Cc Mark Rutland <[email protected]>
Cc Neil Leeder <[email protected]>
Cc Ashwin Chaugule <[email protected]>
---
 Documentation/devicetree/bindings/arm/pmu.txt |   2 +
 arch/arm/kernel/perf_event_cpu.c              |   2 +
 arch/arm/kernel/perf_event_v7.c               | 417 ++++++++++++++++++++++++++
 3 files changed, 421 insertions(+)

[...]

Quoted 18 lines
arch/arm/kernel/perf_event_v7.c +18 -0
+static void scorpion_evt_setup(int idx, u32 config_base)
+{
+       u32 val;
+       u32 mask;
+       u32 vval, fval;
+       unsigned int region;
+       unsigned int group;
+       unsigned int code;
+       unsigned int group_shift;
+       bool venum_event;
+
+       krait_decode_event(config_base, &region, &group, &code, &venum_event,
+                          NULL);
+
+       group_shift = group * 8;
+       mask = 0xff << group_shift;
+
+       /* Configure evtsel for the region and group */

arch/arm/kernel/perf_event_v7.c static int krait_pmu_init(struct arm_pmu *cpu_pmu) · line 1649

Quoted 10 lines
arch/arm/kernel/perf_event_v7.c +10 -0
+       if (venum_event)
+               val = SCORPION_VLPM_GROUP0;
+       else
+               val = scorpion_get_pmresrn_event(region);
+       val += group;
+       /* Mix in mode-exclusion bits */
+       val |= config_base & (ARMV7_EXCLUDE_USER | ARMV7_EXCLUDE_PL1);
+       armv7_pmnc_write_evtsel(idx, val);
+
+       asm volatile("mcr p15, 0, %0, c9, c15, 0" : : "r" (0));

What's this guy doing?

Quoted 7 lines
arch/arm/kernel/perf_event_v7.c +7 -0
+static int scorpion_pmu_get_event_idx(struct pmu_hw_events *cpuc,
+                                  struct perf_event *event)
+{
+       int idx;
+       int bit = -1;
+       unsigned int region;
+       unsigned int code;

arch/arm/kernel/perf_event_v7.c static int krait_pmu_init(struct arm_pmu *cpu_pmu) · line 1813

Quoted 10 lines
arch/arm/kernel/perf_event_v7.c +10 -0
+       unsigned int group;
+       bool venum_event, scorpion_event;
+       struct hw_perf_event *hwc = &event->hw;
+
+       krait_decode_event(hwc->config_base, &region, &group, &code,
+                          &venum_event, &scorpion_event);
+
+       if (venum_event || scorpion_event) {
+               /* Ignore invalid events */
+               if (group > 3 || region > 3)

Where does the 3 come from?

Will

#6 lore raw

Re: [PATCH v2 2/2] ARM: perf: Add support for Scorpion PMUs

Quoted 24 lines · Will Deacon
Quoted 22 lines · Stephen Boyd
arch/arm/kernel/perf_event_v7.c +22 -0
+static void scorpion_evt_setup(int idx, u32 config_base)
+{
+       u32 val;
+       u32 mask;
+       u32 vval, fval;
+       unsigned int region;
+       unsigned int group;
+       unsigned int code;
+       unsigned int group_shift;
+       bool venum_event;
+
+       krait_decode_event(config_base, &region, &group, &code, &venum_event,
+                          NULL);
+
+       group_shift = group * 8;
+       mask = 0xff << group_shift;
+
+       /* Configure evtsel for the region and group */
+       if (venum_event)
+               val = SCORPION_VLPM_GROUP0;
+       else
+               val = scorpion_get_pmresrn_event(region);
Quoted 8 lines

arch/arm/kernel/perf_event_v7.c static int krait_pmu_init(struct arm_pmu *cpu_pmu) · line 1649

Quoted 6 lines
arch/arm/kernel/perf_event_v7.c +6 -0
+       val += group;
+       /* Mix in mode-exclusion bits */
+       val |= config_base & (ARMV7_EXCLUDE_USER | ARMV7_EXCLUDE_PL1);
+       armv7_pmnc_write_evtsel(idx, val);
+
+       asm volatile("mcr p15, 0, %0, c9, c15, 0" : : "r" (0));

What's this guy doing?

This is the same as Krait. It's clearing some implementation defined register. From what I can tell it's a per-event register (i.e. PMSELR decides which event this register write actually affects) and we do this here to reset this register to some defined value, zero. Otherwise the reset value of this register is UNPREDICTABLE and that would be bad. I think we might be able to move it to the pmu reset path, but I don't know. Ashwin?

Quoted 12 lines
Quoted 12 lines
arch/arm/kernel/perf_event_v7.c +11 -0
+static int scorpion_pmu_get_event_idx(struct pmu_hw_events *cpuc,
+                                  struct perf_event *event)
+{
+       int idx;
+       int bit = -1;
+       unsigned int region;
+       unsigned int code;
+       unsigned int group;
+       bool venum_event, scorpion_event;
+       struct hw_perf_event *hwc = &event->hw;
+
Quoted 9 lines

arch/arm/kernel/perf_event_v7.c static int krait_pmu_init(struct arm_pmu *cpu_pmu) · line 1813

Quoted 6 lines
arch/arm/kernel/perf_event_v7.c +6 -0
+       krait_decode_event(hwc->config_base, &region, &group, &code,
+                          &venum_event, &scorpion_event);
+
+       if (venum_event || scorpion_event) {
+               /* Ignore invalid events */
+               if (group > 3 || region > 3)

Where does the 3 come from?

There are four "R"s and "G"s in the ascii art. This checks to make sure we're within the range of possible pmresr and groups. Krait has 3 "R"s and 4 "G"s.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#3 lore raw

Re: [PATCH v2 1/2] ARM: perf: Preparatory work for Scorpion PMU support

In reply to Will Deacon
Quoted 29 lines · Will Deacon
Quoted 16 lines · Stephen Boyd

Do some things to make the Krait PMU support code generic enough to be used by the Scorpion PMU support code.

* Rename the venum register functions to be venum instead of krait specific because the same registers exist on Scorpion

* Add a krait_decode_event() function to decode our Krait specific event encoding that's the same on Scorpion (modulo an extra region).

* Drop krait from krait_clear_pmresrn_group() so it can be used by Scorpion code

---
 arch/arm/kernel/perf_event_v7.c | 87 ++++++++++++++++++++++-------------------
 1 file changed, 46 insertions(+), 41 deletions(-)

[...]

Quoted 9 lines
arch/arm/kernel/perf_event_v7.c +9 -0
+static void krait_decode_event(u32 event, unsigned int *region,
+		unsigned int *group, unsigned int *code, bool *venum, bool *cpu)
+{
+	if (region)
+		*region = (event >> 12) & 0xf;
+	if (group)
+		*group  = (event >> 0)  & 0xf;
+	if (code)
+		*code   = (event >> 4) & 0xff;
Quoted 9 lines

arch/arm/kernel/perf_event_v7.c static u32 krait_get_pmresrn_event(unsigned int region) · line 1204

Quoted 5 lines
arch/arm/kernel/perf_event_v7.c +5 -0
+	if (venum)
+		*venum  = !!(event & VENUM_EVENT);
+	if (cpu)
+		*cpu = !!(event & KRAIT_EVENT);
+}

Maybe worth sticking these fields in a struct? Failing that, just using macros for each one and using them in-line isn't so bad.

Ok let's see how a macro goes. Is there any advantage either way?

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#7 lore raw

Re: [PATCH v2 2/2] ARM: perf: Add support for Scorpion PMUs

In reply to Stephen Boyd
Quoted 34 lines · Stephen Boyd
Quoted 24 lines · Will Deacon
Quoted 22 lines · Stephen Boyd
arch/arm/kernel/perf_event_v7.c +22 -0
+static void scorpion_evt_setup(int idx, u32 config_base)
+{
+       u32 val;
+       u32 mask;
+       u32 vval, fval;
+       unsigned int region;
+       unsigned int group;
+       unsigned int code;
+       unsigned int group_shift;
+       bool venum_event;
+
+       krait_decode_event(config_base, &region, &group, &code, &venum_event,
+                          NULL);
+
+       group_shift = group * 8;
+       mask = 0xff << group_shift;
+
+       /* Configure evtsel for the region and group */
+       if (venum_event)
+               val = SCORPION_VLPM_GROUP0;
+       else
+               val = scorpion_get_pmresrn_event(region);
Quoted 8 lines

arch/arm/kernel/perf_event_v7.c static int krait_pmu_init(struct arm_pmu *cpu_pmu) · line 1649

Quoted 6 lines
arch/arm/kernel/perf_event_v7.c +6 -0
+       val += group;
+       /* Mix in mode-exclusion bits */
+       val |= config_base & (ARMV7_EXCLUDE_USER | ARMV7_EXCLUDE_PL1);
+       armv7_pmnc_write_evtsel(idx, val);
+
+       asm volatile("mcr p15, 0, %0, c9, c15, 0" : : "r" (0));

What's this guy doing?

Quoted 7 lines

This is the same as Krait. It's clearing some implementation defined register. From what I can tell it's a per-event register (i.e. PMSELR decides which event this register write actually affects) and we do this here to reset this register to some defined value, zero. Otherwise the reset value of this register is UNPREDICTABLE and that would be bad. I think we might be able to move it to the pmu reset path, but I don't know. Ashwin?

Will have to check once I get to office tomorrow.

#8 lore raw

Re: [PATCH v2 2/2] ARM: perf: Add support for Scorpion PMUs

Quoted 35 lines · Ashwin Chaugule
Quoted 34 lines · Stephen Boyd
Quoted 32 lines · Will Deacon
Quoted 18 lines · Stephen Boyd
arch/arm/kernel/perf_event_v7.c +18 -0
+static void scorpion_evt_setup(int idx, u32 config_base)
+{
+       u32 val;
+       u32 mask;
+       u32 vval, fval;
+       unsigned int region;
+       unsigned int group;
+       unsigned int code;
+       unsigned int group_shift;
+       bool venum_event;
+
+       krait_decode_event(config_base, &region, &group, &code, &venum_event,
+                          NULL);
+
+       group_shift = group * 8;
+       mask = 0xff << group_shift;
+
+       /* Configure evtsel for the region and group */

arch/arm/kernel/perf_event_v7.c static int krait_pmu_init(struct arm_pmu *cpu_pmu) · line 1649

Quoted 10 lines
arch/arm/kernel/perf_event_v7.c +10 -0
+       if (venum_event)
+               val = SCORPION_VLPM_GROUP0;
+       else
+               val = scorpion_get_pmresrn_event(region);
+       val += group;
+       /* Mix in mode-exclusion bits */
+       val |= config_base & (ARMV7_EXCLUDE_USER | ARMV7_EXCLUDE_PL1);
+       armv7_pmnc_write_evtsel(idx, val);
+
+       asm volatile("mcr p15, 0, %0, c9, c15, 0" : : "r" (0));

What's this guy doing?

Quoted 8 lines
Quoted 7 lines

This is the same as Krait. It's clearing some implementation defined register. From what I can tell it's a per-event register (i.e. PMSELR decides which event this register write actually affects) and we do this here to reset this register to some defined value, zero. Otherwise the reset value of this register is UNPREDICTABLE and that would be bad. I think we might be able to move it to the pmu reset path, but I don't know. Ashwin?

Its a count control register (PMxEVCNTCR). Theres various conditions on which you can select when to start/stop counting. e.g. start when another counter register overflows. Setting it to 0 was the recommended default value on Scorpions and Kraits. Reset value is unpredictable. So, just need to make sure this is set every time a counter is setup. Will that still work if this is moved to the reset path?

Cheers,
Ashwin.

#9 lore raw

Re: [PATCH v2 2/2] ARM: perf: Add support for Scorpion PMUs

Quoted 42 lines · Ashwin Chaugule
Quoted 33 lines · Ashwin Chaugule
Quoted 32 lines · Stephen Boyd
Quoted 31 lines · Will Deacon
Quoted 18 lines · Stephen Boyd
arch/arm/kernel/perf_event_v7.c +18 -0
+static void scorpion_evt_setup(int idx, u32 config_base)
+{
+       u32 val;
+       u32 mask;
+       u32 vval, fval;
+       unsigned int region;
+       unsigned int group;
+       unsigned int code;
+       unsigned int group_shift;
+       bool venum_event;
+
+       krait_decode_event(config_base, &region, &group, &code, &venum_event,
+                          NULL);
+
+       group_shift = group * 8;
+       mask = 0xff << group_shift;
+
+       /* Configure evtsel for the region and group */

arch/arm/kernel/perf_event_v7.c static int krait_pmu_init(struct arm_pmu *cpu_pmu) · line 1649

Quoted 10 lines
arch/arm/kernel/perf_event_v7.c +10 -0
+       if (venum_event)
+               val = SCORPION_VLPM_GROUP0;
+       else
+               val = scorpion_get_pmresrn_event(region);
+       val += group;
+       /* Mix in mode-exclusion bits */
+       val |= config_base & (ARMV7_EXCLUDE_USER | ARMV7_EXCLUDE_PL1);
+       armv7_pmnc_write_evtsel(idx, val);
+
+       asm volatile("mcr p15, 0, %0, c9, c15, 0" : : "r" (0));

What's this guy doing?

Quoted 7 lines
Quoted 7 lines

This is the same as Krait. It's clearing some implementation defined register. From what I can tell it's a per-event register (i.e. PMSELR decides which event this register write actually affects) and we do this here to reset this register to some defined value, zero. Otherwise the reset value of this register is UNPREDICTABLE and that would be bad. I think we might be able to move it to the pmu reset path, but I don't know. Ashwin?

Quoted 9 lines

Its a count control register (PMxEVCNTCR). Theres various conditions on which you can select when to start/stop counting. e.g. start when another counter register overflows. Setting it to 0 was the recommended default value on Scorpions and Kraits. Reset value is unpredictable. So, just need to make sure this is set every time a counter is setup. Will that still work if this is moved to the reset path?

I don't think anything in this register changes unless we reset the CPU or software changes it, right? We already have a hotplug notifier to handle the case where the CPU is hotplugged out (and may get reset) and we need to reset the PMU. The other case is deep idle, which we don't have yet but we'll need to do a save/reset/restore across idle when we get there. So it seems possible to move it to the PMU reset path.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#10 lore raw

Re: [PATCH v2 2/2] ARM: perf: Add support for Scorpion PMUs

Quoted 9 lines · Stephen Boyd
Quoted 7 lines · Ashwin Chaugule

Its a count control register (PMxEVCNTCR). Theres various conditions on which you can select when to start/stop counting. e.g. start when another counter register overflows. Setting it to 0 was the recommended default value on Scorpions and Kraits. Reset value is unpredictable. So, just need to make sure this is set every time a counter is setup. Will that still work if this is moved to the reset path?

Quoted 6 lines

I don't think anything in this register changes unless we reset the CPU or software changes it, right? We already have a hotplug notifier to handle the case where the CPU is hotplugged out (and may get reset) and we need to reset the PMU. The other case is deep idle, which we don't have yet but we'll need to do a save/reset/restore across idle when we get there. So it seems possible to move it to the PMU reset path.

That would be my preference! Please respin the patches and I'll take another look.

Will