arm/pmu: fixups for AArch64
v2 cover arm/pmu: fixups for AArch64
The first patch fixes probing on ThunderX, where ID_DFR0 is zero. The second patch removes noise from most run_tests.sh runs since TCG PMU isn't really ready to be tested regularly yet.
Andrew Jones (2):
arm/pmu: fix probe on AArch64
arm/pmu: don't run tcg tests
arm/unittests.cfg | 20 ++++++++++---------- arm/pmu.c | 37 ++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 25 deletions(-)
Signature · 1 line
2.9.3
PATCH v2 1/2 arm/pmu: fix probe on AArch64
The spec for ID_DFR0_EL1 says "In an AArch64-only implementation, this register is UNKNOWN." Indeed ThunderX just returns zero when that register is read. This means we can't rely on a non-zero value to determine if we can test the PMU. For AArch64 we need to read ID_AA64DFR0_EL1. This patch has the side effect of no longer running PMU tests on TCG for AArch64. That's actually another fix, though, as TCG chooses not to implement a PMU for AArch64 at this time. The only way it worked before was probing the wrong register and proceeding even though the version was 2, which is not a valid version for AArch64. When TCG eventually implements a PMU things should "just work".
--- arm/pmu.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-)
arm/pmu.c +22 -15
@@ -28,15 +28,15 @@#define PMU_PMCR_IMP_SHIFT 24#define PMU_PMCR_IMP_MASK 0xff -#define ID_DFR0_PERFMON_SHIFT 24 -#define ID_DFR0_PERFMON_MASK 0xf - -#define PMU_CYCLE_IDX 31 +#define PMU_CYCLE_IDX 31#define NR_SAMPLES 10static unsigned int pmu_version;#if defined(__arm__) +#define ID_DFR0_PERFMON_SHIFT 24 +#define ID_DFR0_PERFMON_MASK 0xf +#define PMCR __ACCESS_CP15(c9, 0, c12, 0)#define ID_DFR0 __ACCESS_CP15(c0, 0, c1, 2)#define PMSELR __ACCESS_CP15(c9, 0, c12, 5)
@@ -50,6 +50,11 @@ static inline uint32_t get_pmcr(void) { return read_sysreg(PMCR); }static inline void set_pmcr (uint32_t v) {write_sysreg (v,PMCR ); }static inline void set_pmcntenset (uint32_t v) {write_sysreg (v,PMCNTENSET ); } +static inline uint8_t get_pmu_version (void ) +{ +return (get_id_dfr0 () >>ID_DFR0_PERFMON_SHIFT ) &ID_DFR0_PERFMON_MASK ; +} +static inline uint64_t get_pmccntr (void ) {if (pmu_version ==0x3 )
@@ -95,7 +100,10 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : "cc"); }#elif defined(__aarch64__) -static inline uint32_t get_id_dfr0 (void ) {return read_sysreg (id_dfr0_el1); } +#define ID_AA64DFR0_PERFMON_SHIFT 8 +#define ID_AA64DFR0_PERFMON_MASK 0xf + +static inline uint32_t get_id_aa64dfr0 (void ) {return read_sysreg (id_aa64dfr0_el1); }static inline uint32_t get_pmcr (void ) {return read_sysreg (pmcr_el0); }static inline void set_pmcr (uint32_t v) {write_sysreg (v, pmcr_el0); }static inline uint64_t get_pmccntr (void ) {return read_sysreg (pmccntr_el0); }
@@ -103,6 +111,12 @@ static inline void set_pmccntr(uint64_t v) { write_sysreg(v, pmccntr_el0); }static inline void set_pmcntenset (uint32_t v) {write_sysreg (v, pmcntenset_el0); }static inline void set_pmccfiltr (uint32_t v) {write_sysreg (v, pmccfiltr_el0); } +static inline uint8_t get_pmu_version (void ) +{ +uint8_t ver = (get_id_aa64dfr0 () >>ID_AA64DFR0_PERFMON_SHIFT ) &ID_AA64DFR0_PERFMON_MASK ; +return ver ==1 ?3 : ver; +} +/* * Extra instructions inserted by the compiler would be difficult to compensate * for, so hand assemble everything between, and including, the PMCR accesses
@@ -256,16 +270,9 @@ static bool check_cpi(int cpi)/* Return FALSE if no PMU found, otherwise return TRUE */ bool pmu_probe (void ) { -uint32_t dfr0; - -/* probe pmu version */ - dfr0 =get_id_dfr0 (); - pmu_version = (dfr0 >>ID_DFR0_PERFMON_SHIFT ) &ID_DFR0_PERFMON_MASK ; - -if (pmu_version) -report_info ("PMU version: %d" , pmu_version); - -return pmu_version; + pmu_version =get_pmu_version (); +report_info ("PMU version: %d" , pmu_version); +return pmu_version !=0 && pmu_version !=0xf ; }int main (int argc,char *argv[])
Signature · 1 line
2.9.3
Re: [PATCH kvm-unit-tests v2 1/2] arm/pmu: fix probe on AArch64
and it was working.
Thanks,
-Wei
Quoted 99 lines · Andrew Jones
The spec for
ID_DFR0_EL1says "In an AArch64-only implementation, this register is UNKNOWN." Indeed ThunderX just returns zero when that register is read. This means we can't rely on a non-zero value to determine if we can test the PMU. For AArch64 we need to readID_AA64DFR0_EL1. This patch has the side effect of no longer running PMU tests on TCG for AArch64. That's actually another fix, though, as TCG chooses not to implement a PMU for AArch64 at this time. The only way it worked before was probing the wrong register and proceeding even though the version was 2, which is not a valid version for AArch64. When TCG eventually implements a PMU things should "just work".Signed-off-by Andrew Jones <[email protected]>--- arm/pmu.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-)arm/pmu.c +22
-15@@ -28,15 +28,15 @@#define PMU_PMCR_IMP_SHIFT 24#define PMU_PMCR_IMP_MASK 0xff -#define ID_DFR0_PERFMON_SHIFT 24 -#define ID_DFR0_PERFMON_MASK 0xf - -#define PMU_CYCLE_IDX 31 +#define PMU_CYCLE_IDX 31#define NR_SAMPLES 10static unsigned int pmu_version;#if defined(__arm__) +#define ID_DFR0_PERFMON_SHIFT 24 +#define ID_DFR0_PERFMON_MASK 0xf +#define PMCR __ACCESS_CP15(c9, 0, c12, 0)#define ID_DFR0 __ACCESS_CP15(c0, 0, c1, 2)#define PMSELR __ACCESS_CP15(c9, 0, c12, 5)@@ -50,6 +50,11 @@ static inline uint32_t get_pmcr(void) { return read_sysreg(PMCR); }static inline void set_pmcr (uint32_t v) {write_sysreg (v,PMCR ); }static inline void set_pmcntenset (uint32_t v) {write_sysreg (v,PMCNTENSET ); } +static inline uint8_t get_pmu_version (void ) +{ +return (get_id_dfr0 () >>ID_DFR0_PERFMON_SHIFT ) &ID_DFR0_PERFMON_MASK ; +} +static inline uint64_t get_pmccntr (void ) {if (pmu_version ==0x3 )@@ -95,7 +100,10 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : "cc"); }#elif defined(__aarch64__) -static inline uint32_t get_id_dfr0 (void ) {return read_sysreg (id_dfr0_el1); } +#define ID_AA64DFR0_PERFMON_SHIFT 8 +#define ID_AA64DFR0_PERFMON_MASK 0xf + +static inline uint32_t get_id_aa64dfr0 (void ) {return read_sysreg (id_aa64dfr0_el1); }static inline uint32_t get_pmcr (void ) {return read_sysreg (pmcr_el0); }static inline void set_pmcr (uint32_t v) {write_sysreg (v, pmcr_el0); }static inline uint64_t get_pmccntr (void ) {return read_sysreg (pmccntr_el0); }@@ -103,6 +111,12 @@ static inline void set_pmccntr(uint64_t v) { write_sysreg(v, pmccntr_el0); }static inline void set_pmcntenset (uint32_t v) {write_sysreg (v, pmcntenset_el0); }static inline void set_pmccfiltr (uint32_t v) {write_sysreg (v, pmccfiltr_el0); } +static inline uint8_t get_pmu_version (void ) +{ +uint8_t ver = (get_id_aa64dfr0 () >>ID_AA64DFR0_PERFMON_SHIFT ) &ID_AA64DFR0_PERFMON_MASK ; +return ver ==1 ?3 : ver; +} +/* * Extra instructions inserted by the compiler would be difficult to compensate * for, so hand assemble everything between, and including, the PMCR accesses @@ -256,16 +270,9 @@ static bool check_cpi(int cpi)/* Return FALSE if no PMU found, otherwise return TRUE */ bool pmu_probe (void ) { -uint32_t dfr0; - -/* probe pmu version */ - dfr0 =get_id_dfr0 (); - pmu_version = (dfr0 >>ID_DFR0_PERFMON_SHIFT ) &ID_DFR0_PERFMON_MASK ; - -if (pmu_version) -report_info ("PMU version: %d" , pmu_version); - -return pmu_version; + pmu_version =get_pmu_version (); +report_info ("PMU version: %d" , pmu_version); +return pmu_version !=0 && pmu_version !=0xf ; }int main (int argc,char *argv[])
PATCH v2 2/2 arm/pmu: don't run tcg tests
In reply to Andrew JonesThe TCG PMU is barely implemented for ARM and not at all implemented for AArch64. Let's not bother running the TCG-only tests yet. We'll likely move them to a new TCG-only unittests.cfg at some point before re-enabling them too.
--- arm/unittests.cfg | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
arm/unittests.cfg +10 -10
@@ -65,15 +65,15 @@ file = pmu.flat groups = pmu # Test PMU support (TCG) with -icount IPC=1 -[pmu-tcg-icount-1] -file = pmu.flat -extra_params = -icount 0 -append '1' -groups = pmu -accel = tcg +#[pmu-tcg-icount-1] +#file = pmu.flat +#extra_params = -icount 0 -append '1' +#groups = pmu +#accel = tcg # Test PMU support (TCG) with -icount IPC=256 -[pmu-tcg-icount-256] -file = pmu.flat -extra_params = -icount 8 -append '256' -groups = pmu -accel = tcg +#[pmu-tcg-icount-256] +#file = pmu.flat +#extra_params = -icount 8 -append '256' +#groups = pmu +#accel = tcg
Signature · 1 line
2.9.3
Re: [PATCH kvm-unit-tests v2 2/2] arm/pmu: don't run tcg tests
Quoted 6 lines · Andrew Jones
The TCG PMU is barely implemented for ARM and not at all implemented for AArch64. Let's not bother running the TCG-only tests yet. We'll likely move them to a new TCG-only unittests.cfg at some point before re-enabling them too.
Signed-off-by Andrew Jones <[email protected]>
It is always safe to disable TCG tests, as proposed in this patch. However I don't think we need it because PMU will behave correctly after your PATCH 1:
1. Under TCG AArch32 mode, get_pmu_version() returns 2. This is acceptable for pmu-tcg-icount-1 and pmu-tcg-icount-256. We should allow the tests to proceed.
2. Under TCG AArch64, get_pmu_version() returns 0. pmu-tcg-icount-1 and pmu-tcg-icount-256 will skip because pmu_probe() returns FALSE. As long as there isn't an error, most people will be OK to see SKIP message.
Thanks,
-Wei
Quoted 35 lines
--- arm/unittests.cfg | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)arm/unittests.cfg +10
-10@@ -65,15 +65,15 @@ file = pmu.flat groups = pmu # Test PMU support (TCG) with -icount IPC=1 -[pmu-tcg-icount-1] -file = pmu.flat -extra_params = -icount 0 -append '1' -groups = pmu -accel = tcg +#[pmu-tcg-icount-1] +#file = pmu.flat +#extra_params = -icount 0 -append '1' +#groups = pmu +#accel = tcg # Test PMU support (TCG) with -icount IPC=256 -[pmu-tcg-icount-256] -file = pmu.flat -extra_params = -icount 8 -append '256' -groups = pmu -accel = tcg +#[pmu-tcg-icount-256] +#file = pmu.flat +#extra_params = -icount 8 -append '256' +#groups = pmu +#accel = tcg
Re: [PATCH kvm-unit-tests v2 2/2] arm/pmu: don't run tcg tests
Quoted 14 lines · Wei Huang
Quoted 6 lines · Andrew Jones
The TCG PMU is barely implemented for ARM and not at all implemented for AArch64. Let's not bother running the TCG-only tests yet. We'll likely move them to a new TCG-only unittests.cfg at some point before re-enabling them too.
Signed-off-by Andrew Jones <[email protected]>It is always safe to disable TCG tests, as proposed in this patch. However I don't think we need it because PMU will behave correctly after your PATCH 1:
Quoted 6 lines
1. Under TCG AArch32 mode,
get_pmu_version()returns 2. This is acceptable for pmu-tcg-icount-1 and pmu-tcg-icount-256. We should allow the tests to proceed.
2. Under TCG AArch64,get_pmu_version()returns 0. pmu-tcg-icount-1 and pmu-tcg-icount-256 will skip becausepmu_probe()returns FALSE. As long as there isn't an error, most people will be OK to see SKIP message.
I find it a bit annoying to be running KVM tests and need to mentally filter out results (skips or not) for TCG-only tests. I'd rather leave them off for now. Once we get a tcg-only test running framework in place we can uncomment them.
Thanks,
drew
Quoted 43 lines
Thanks,
-WeiQuoted 25 lines
--- arm/unittests.cfg | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)arm/unittests.cfg +5
-5@@ -65,15 +65,15 @@ file = pmu.flat groups = pmu # Test PMU support (TCG) with -icount IPC=1 -[pmu-tcg-icount-1] -file = pmu.flat -extra_params = -icount 0 -append '1' -groups = pmu -accel = tcg +#[pmu-tcg-icount-1] +#file = pmu.flat +#extra_params = -icount 0 -append '1' +#groups = pmu +#accel = tcg # Test PMU support (TCG) with -icount IPC=256arm/unittests.cfg file = pmu.flat · line 79
Quoted 10 lines
arm/unittests.cfg +5
-5-[pmu-tcg-icount-256] -file = pmu.flat -extra_params = -icount 8 -append '256' -groups = pmu -accel = tcg +#[pmu-tcg-icount-256] +#file = pmu.flat +#extra_params = -icount 8 -append '256' +#groups = pmu +#accel = tcg--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH kvm-unit-tests v2 2/2] arm/pmu: don't run tcg tests
In reply to Andrew JonesQuoted 4 lines · Andrew Jones
The TCG PMU is barely implemented for ARM and not at all implemented for AArch64. Let's not bother running the TCG-only tests yet. We'll likely move them to a new TCG-only unittests.cfg at some point before re-enabling them too.
ID_AA64DFR0_EL1 isn't implemented in TCG, which should be first fixed and then tested. I think and hope we're in agreement on that.
However the cycle counter, PMCCNTR, is very much implemented on AArch64 TCG. We've been successfully testing it for months.
Thanks,
Cov
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH kvm-unit-tests v2 2/2] arm/pmu: don't run tcg tests
Quoted 8 lines · Christopher Covington
Quoted 4 lines · Andrew Jones
The TCG PMU is barely implemented for ARM and not at all implemented for AArch64. Let's not bother running the TCG-only tests yet. We'll likely move them to a new TCG-only unittests.cfg at some point before re-enabling them too.
ID_AA64DFR0_EL1isn't implemented in TCG, which should be first fixed and then tested. I think and hope we're in agreement on that.
Hmm? We have
{ .name = "ID_AA64DFR0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 0,
.access = PL1_R, .type = ARM_CP_CONST,
/* We mask out the PMUVer field, because we don't currently
* implement the PMU. Not advertising it prevents the guest
* from trying to use it and getting UNDEFs on registers we
* don't implement.
*/
.resetvalue = cpu->id_aa64dfr0 & ~0xf00 },which strongly suggests that we implement it... is that buggy somehow?
thanks
-- PMM
Re: [PATCH kvm-unit-tests v2 2/2] arm/pmu: don't run tcg tests
In reply to Christopher CovingtonQuoted 8 lines · Christopher Covington
Quoted 4 lines · Andrew Jones
The TCG PMU is barely implemented for ARM and not at all implemented for AArch64. Let's not bother running the TCG-only tests yet. We'll likely move them to a new TCG-only unittests.cfg at some point before re-enabling them too.
ID_AA64DFR0_EL1isn't implemented in TCG, which should be first fixed and then tested. I think and hope we're in agreement on that.
It is implemented in TCG. The v8_idregs table has this
{ .name = "ID_AA64DFR0_EL1", .state = ARM_CP_STATE_AA64,
.opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 0,
.access = PL1_R, .type = ARM_CP_CONST,
/* We mask out the PMUVer field, because we don't currently
* implement the PMU. Not advertising it prevents the guest
* from trying to use it and getting UNDEFs on registers we
* don't implement.
*/
.resetvalue = cpu->id_aa64dfr0 & ~0xf00 },Notice the big comment stating PMUVer is zero on purpose.
Quoted 3 lines
However the cycle counter, PMCCNTR, is very much implemented on AArch64 TCG. We've been successfully testing it for months.
It's working, yes, but not because the PMU is fully implemented. Any guest that first probes (correctly) and then uses won't even try. The only probe that succeeds (arm32 ID_DFR0) returns 2, which is invalid for AArch64.
Since we're not a real kernel, but a unit testing framework, we can bypass probes when appropriate and just test to see what happens. I'm not sure it's worth it for testing TCG, which states it's not implemented yet though. If this is something you need now, then maybe we should add a command line option to this test that allows the probe to be skipped.
Thanks,
drew
Quoted 12 lines
Thanks,
CovSignature · 7 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html