Skip to contentSkip to conversation

target/arm: Configure number of pmu counters

PATCH In review Sai Pavan Boddu 4 participants 4 messages Aug 31, 2020 – Sep 2, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: Configure number of pmu counters

Default the pmu counters to 4 and configure it a 6 for a53 cores.

---
 target/arm/cpu.c    | 3 +++
 target/arm/cpu.h    | 3 +++
 target/arm/cpu64.c  | 1 +
 target/arm/helper.c | 2 +-
 4 files changed, 8 insertions(+), 1 deletion(-)
target/arm/cpu.c +3 -0
index 6b382fc..805a692 100644
@@ -1051,6 +1051,9 @@ static void arm_cpu_initfn(Object *obj)
     cpu->psci_version = 1; /* By default assume PSCI v0.1 */
     cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
 
+    /* set number of pmu counters to 4 */
+    cpu->pmcrn = 4;
+
     if (tcg_enabled()) {
         cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
     }
target/arm/cpu.h +3 -0
index ac857bd..3b47ba8 100644
@@ -879,6 +879,9 @@ struct ARMCPU {
      */
     int32_t core_count;
 
+    /* Number of pmu counters */
+    uint8_t pmcrn;
+
     /* The instance init functions for implementation-specific subclasses
      * set these fields to specify the implementation-dependent values of
      * various constant registers and reset values of non-constant
target/arm/cpu64.c +1 -0
index dd69618..76c879a 100644
@@ -190,6 +190,7 @@ static void aarch64_a53_initfn(Object *obj)
     cpu->gic_vpribits = 5;
     cpu->gic_vprebits = 5;
     define_arm_cp_regs(cpu, cortex_a72_a57_a53_cp_reginfo);
+    cpu->pmcrn = 6;
 }
 
 static void aarch64_a72_initfn(Object *obj)
target/arm/helper.c +1 -1
index 44d6666..4afbefb 100644
@@ -6534,7 +6534,7 @@ static void define_pmu_regs(ARMCPU *cpu)
      * field as main ID register, and we implement four counters in
      * addition to the cycle count register.
      */
-    unsigned int i, pmcrn = 4;
+    unsigned int i, pmcrn = cpu->pmcrn;
     ARMCPRegInfo pmcr = {
         .name = "PMCR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 0,
         .access = PL0_RW,
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Sai Pavan Boddu

Default the pmu counters to 4 and configure it a 6 for a53 cores.

Your commit message looks like it needs a little rewording.

I would probably split this into two patches, one that adds pmcrn and another that modifies the A53.

Quoted 14 lines
---
 target/arm/cpu.c    | 3 +++
 target/arm/cpu.h    | 3 +++
 target/arm/cpu64.c  | 1 +
 target/arm/helper.c | 2 +-
 4 files changed, 8 insertions(+), 1 deletion(-)
target/arm/cpu.c +0 -0
index 6b382fc..805a692 100644

target/arm/cpu.c static void arm_cpu_initfn(Object *obj) · line 1054

Quoted 4 lines
target/arm/cpu.c +1 -0
@@ -1051,6 +1051,9 @@ static void arm_cpu_initfn(Object *obj)
     cpu->psci_version = 1; /* By default assume PSCI v0.1 */
     cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
 
+    /* set number of pmu counters to 4 */

/* Set default number of PMU counters */

That way if the default changes you don't need to edit both code and comment.

With those changes:

Quoted 48 lines
target/arm/cpu.c +2 -0
+    cpu->pmcrn = 4;
+
     if (tcg_enabled()) {
         cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
     }
target/arm/cpu.h +3 -0
index ac857bd..3b47ba8 100644
@@ -879,6 +879,9 @@ struct ARMCPU {
      */
     int32_t core_count;
 
+    /* Number of pmu counters */
+    uint8_t pmcrn;
+
     /* The instance init functions for implementation-specific subclasses
      * set these fields to specify the implementation-dependent values of
      * various constant registers and reset values of non-constant
target/arm/cpu64.c +1 -0
index dd69618..76c879a 100644
@@ -190,6 +190,7 @@ static void aarch64_a53_initfn(Object *obj)
     cpu->gic_vpribits = 5;
     cpu->gic_vprebits = 5;
     define_arm_cp_regs(cpu, cortex_a72_a57_a53_cp_reginfo);
+    cpu->pmcrn = 6;
 }
 
 static void aarch64_a72_initfn(Object *obj)
target/arm/helper.c +1 -1
index 44d6666..4afbefb 100644
@@ -6534,7 +6534,7 @@ static void define_pmu_regs(ARMCPU *cpu)
      * field as main ID register, and we implement four counters in
      * addition to the cycle count register.
      */
-    unsigned int i, pmcrn = 4;
+    unsigned int i, pmcrn = cpu->pmcrn;
     ARMCPRegInfo pmcr = {
         .name = "PMCR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 0,
         .access = PL0_RW,
Signature · 1 line
2.7.4
#2 lore raw
In reply to Sai Pavan Boddu
Quoted 30 lines · Sai Pavan Boddu

Default the pmu counters to 4 and configure it a 6 for a53 cores.

---
 target/arm/cpu.c    | 3 +++
 target/arm/cpu.h    | 3 +++
 target/arm/cpu64.c  | 1 +
 target/arm/helper.c | 2 +-
 4 files changed, 8 insertions(+), 1 deletion(-)
target/arm/cpu.c +3 -0
index 6b382fc..805a692 100644
@@ -1051,6 +1051,9 @@ static void arm_cpu_initfn(Object *obj)
     cpu->psci_version = 1; /* By default assume PSCI v0.1 */
     cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
 
+    /* set number of pmu counters to 4 */
+    cpu->pmcrn = 4;
+
     if (tcg_enabled()) {
         cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
     }
target/arm/cpu.h +0 -0
index ac857bd..3b47ba8 100644

target/arm/cpu.h struct ARMCPU { · line 887

Quoted 9 lines
target/arm/cpu.h +3 -0
@@ -879,6 +879,9 @@ struct ARMCPU {
      */
     int32_t core_count;
 
+    /* Number of pmu counters */
+    uint8_t pmcrn;
+
     /* The instance init functions for implementation-specific subclasses
      * set these fields to specify the implementation-dependent values of
      * various constant registers and reset values of non-constant

Rather than doing this, I think the better approach would be to switch to treating PMCR_EL0 as an ID register in the same way we do for other varies-per-CPU ID registers:

* new field uint64_t pmcr_el0 in the ARMISARegisters sub-struct of ARMCPU
* each CPU's initfn needs to set this (sorry, this is going to mean a fair amount of digging through TRMs to find the right values)
* define_pmu_regs() just uses the isar.pmcr_el0 field as the resetvalue for PMCR_EL0
* define_pmu_regs() needs to use pmu_num_counters() to get the number of counters for its loops

Side note: looking at the code I see we don't implement the effect that MDCR_EL2.HPMN has on this register... (and probably we don't in general get the EL2 handling of the PMU right in other places too).

thanks
-- PMM

#3 lore raw

Hi Peter,

Quoted 66 lines

-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Tuesday, September 1, 2020 6:18 PM
To: Sai Pavan Boddu <[email protected]>
Cc: Richard Henderson <[email protected]>; Philippe Mathieu- Daudé <[email protected]>; Andrew Jones <[email protected]>; Paolo Bonzini <[email protected]>; Alex Bennée <[email protected]>; Eric Auger <[email protected]>; Edgar Iglesias <[email protected]>; qemu-arm <[email protected]>; QEMU Developers <qemu- [email protected]>
Subject: Re: [PATCH] target/arm: Configure number of pmu counters

Quoted 30 lines · Sai Pavan Boddu

Default the pmu counters to 4 and configure it a 6 for a53 cores.

---
 target/arm/cpu.c    | 3 +++
 target/arm/cpu.h    | 3 +++
 target/arm/cpu64.c  | 1 +
 target/arm/helper.c | 2 +-
 4 files changed, 8 insertions(+), 1 deletion(-)
target/arm/cpu.c index renamed from target/arm/cpu.c +0 -0

6b382fc..805a692 100644

target/arm/cpu.c +3 -0
@@ -1051,6 +1051,9 @@ static void arm_cpu_initfn(Object *obj)
     cpu->psci_version = 1; /* By default assume PSCI v0.1 */
     cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
 
+    /* set number of pmu counters to 4 */
+    cpu->pmcrn = 4;
+
     if (tcg_enabled()) {
         cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
     }
target/arm/cpu.h index renamed from target/arm/cpu.h +0 -0

ac857bd..3b47ba8 100644

target/arm/cpu.h struct ARMCPU { · line 887

Quoted 9 lines
target/arm/cpu.h +3 -0
@@ -879,6 +879,9 @@ struct ARMCPU {
      */
     int32_t core_count;
 
+    /* Number of pmu counters */
+    uint8_t pmcrn;
+
     /* The instance init functions for implementation-specific subclasses
      * set these fields to specify the implementation-dependent values of
      * various constant registers and reset values of non-constant

Rather than doing this, I think the better approach would be to switch to treating PMCR_EL0 as an ID register in the same way we do for other varies- per-CPU ID registers:

* new field uint64_t pmcr_el0 in the ARMISARegisters sub-struct of ARMCPU
* each CPU's initfn needs to set this (sorry, this is going to mean a fair amount of digging through TRMs to find the right values)
* define_pmu_regs() just uses the isar.pmcr_el0 field as the resetvalue for PMCR_EL0
* define_pmu_regs() needs to use pmu_num_counters() to get the number of counters for its loops

Quoted 3 lines

Side note: looking at the code I see we don't implement the effect that MDCR_EL2.HPMN has on this register... (and probably we don't in general get the EL2 handling of the PMU right in other places too).

[Sai Pavan Boddu] Sure, I will get back on this. I need to understand more.

Thanks,
Sai Pavan

Quoted 3 lines

thanks
-- PMM