KVM: arm64: PMUv3 Event Counter Tests
cover KVM: arm64: PMUv3 Event Counter Tests
This series implements tests exercising the PMUv3 event counters. It tests both the 32-bit and 64-bit versions. Overflow interrupts also are checked. Those tests only are written for arm64.
It allowed to reveal some issues related to SW_INCR implementation (esp. related to 64-bit implementation), some problems related to 32-bit <-> 64-bit transitions and consistency of enabled states of odd and event counters.
Overflow interrupt testing relies of one patch from Andre ("arm: gic: Provide per-IRQ helper functions") to enable the PPI 23, coming from "arm: gic: Test SPIs and interrupt groups"
(https://patchwork.kernel.org/cover/11234975/). Drew kindly provided "arm64: Provide read/write_sysreg_s".
All PMU tests can be launched with:
./run_tests.sh -g pmu
Tests also can be launched individually. For example:
./arm-run arm/pmu.flat -append 'chained-sw-incr'
With KVM:
- chain-promotion and chained-sw-incr are known to be failing.
- Problems were reported upstream.
With TCG:
- pmu-event-introspection is failing due to missing required events (we may remove this from TCG actually)
- chained-sw-incr also fails. I haven't investigated yet.
The series can be found at:
https://github.com/eauger/kut/tree/pmu_event_counters_v1
History:
v1 -> v2:
- Use new report() proto
- Style cleanup
- do not warn about ARM spec recommendations
- add a comment about PMCEID0/1 splits
Andre Przywara (1):
arm: gic: Provide per-IRQ helper functions
Andrew Jones (1):
arm64: Provide read/write_sysreg_s
Eric Auger (8):
arm: pmu: Let pmu tests take a sub-test parameter
arm: pmu: Add a pmu struct
arm: pmu: Check Required Event Support
arm: pmu: Basic event counter Tests
arm: pmu: Test chained counter
arm: pmu: test 32-bit <-> 64-bit transitions arm/arm64: gic: Introduce setup_irq() helper
arm: pmu: Test overflow interrupts
arm/gic.c | 24 +- arm/pmu.c | 783 ++++++++++++++++++++++++++++++++++++++++- arm/unittests.cfg | 55 ++- lib/arm/asm/gic-v3.h | 2 + lib/arm/asm/gic.h | 12 + lib/arm/gic.c | 101 ++++++ lib/arm64/asm/sysreg.h | 11 + 7 files changed, 950 insertions(+), 38 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/10 arm64: Provide read/write_sysreg_s
From: Andrew Jones <[email protected]>
Sometimes we need to test access to system registers which are missing assembler mnemonics.
--- lib/arm64/asm/sysreg.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
lib/arm64/asm/sysreg.h +11 -0
@@ -38,6 +38,17 @@ asm volatile("msr " xstr(r) ", %x0" : : "rZ" (__val)); \ } while (0) +#define read_sysreg_s (r) ({ \ + u64 __val; \ + asm volatile("mrs_s %0, " xstr(r) : "=r" (__val)); \ + __val; \ +}) + +#define write_sysreg_s (v, r) do { \ + u64 __val = (u64)v; \ + asm volatile("msr_s " xstr(r) ", %x0" : : "rZ" (__val));\ +} while (0) + asm(" .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n" " .equ .L__reg_num_x\\num, \\num\n"
Signature · 6 lines
2.20.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH 2/10 arm: pmu: Let pmu tests take a sub-test parameter
In reply to Eric AugerAs we intend to introduce more PMU tests, let's add a sub-test parameter that will allow to categorize them. Existing tests are in the cycle-counter category.
--- arm/pmu.c | 24 +++++++++++++++--------- arm/unittests.cfg | 7 ++++--- 2 files changed, 19 insertions(+), 12 deletions(-)
arm/pmu.c +15 -9
@@ -287,22 +287,28 @@ int main(int argc, char *argv[]) {int cpi =0 ; -if (argc >1 ) - cpi =atol (argv[1 ]); -if (!pmu_probe ()) {printf ("No PMU found, test skipped...\n" );return report_summary (); } +if (argc <2 ) +report_abort ("no test specified" ); +report_prefix_push ("pmu" ); -report (check_pmcr (),"Control register" ); -report (check_cycles_increase (), -"Monotonically increasing cycle count" ); -report (check_cpi (cpi),"Cycle/instruction ratio" ); - -pmccntr64_test (); +if (strcmp (argv[1 ],"cycle-counter" ) ==0 ) { +report_prefix_push (argv[1 ]); +if (argc >2 ) + cpi =atol (argv[2 ]); +report (check_pmcr (),"Control register" ); +report (check_cycles_increase (), +"Monotonically increasing cycle count" ); +report (check_cpi (cpi),"Cycle/instruction ratio" ); +pmccntr64_test (); + }else { +report_abort ("Unknown sub-test '%s'" , argv[1 ]); + }return report_summary (); }
arm/unittests.cfg +4 -3
@@ -61,21 +61,22 @@ file = pci-test.flat groups = pci # Test PMU support -[pmu] +[pmu-cycle-counter] file = pmu.flat groups = pmu +extra_params = -append 'cycle-counter 0' # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat -#extra_params = -icount 0 -append '1' +#extra_params = -icount 0 -append 'cycle-counter 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' +#extra_params = -icount 8 -append 'cycle-counter 256' #groups = pmu #accel = tcg
Signature · 6 lines
2.20.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [kvm-unit-tests PATCH 02/10] arm: pmu: Let pmu tests take a sub-test parameter
Quoted 5 lines · On Mon, 16 Dec 2019 21:47:49 +0100 Eric Auger <[email protected]> wrote:
As we intend to introduce more PMU tests, let's add a sub-test parameter that will allow to categorize them. Existing tests are in the cycle-counter category.
Signed-off-by Eric Auger <[email protected]>
Cheers,
Andre
Quoted 77 lines
--- arm/pmu.c | 24 +++++++++++++++--------- arm/unittests.cfg | 7 ++++--- 2 files changed, 19 insertions(+), 12 deletions(-)arm/pmu.c +15
-9@@ -287,22 +287,28 @@ int main(int argc, char *argv[]) {int cpi =0 ; -if (argc >1 ) - cpi =atol (argv[1 ]); -if (!pmu_probe ()) {printf ("No PMU found, test skipped...\n" );return report_summary (); } +if (argc <2 ) +report_abort ("no test specified" ); +report_prefix_push ("pmu" ); -report (check_pmcr (),"Control register" ); -report (check_cycles_increase (), -"Monotonically increasing cycle count" ); -report (check_cpi (cpi),"Cycle/instruction ratio" ); - -pmccntr64_test (); +if (strcmp (argv[1 ],"cycle-counter" ) ==0 ) { +report_prefix_push (argv[1 ]); +if (argc >2 ) + cpi =atol (argv[2 ]); +report (check_pmcr (),"Control register" ); +report (check_cycles_increase (), +"Monotonically increasing cycle count" ); +report (check_cpi (cpi),"Cycle/instruction ratio" ); +pmccntr64_test (); + }else { +report_abort ("Unknown sub-test '%s'" , argv[1 ]); + }return report_summary (); }arm/unittests.cfg +4
-3@@ -61,21 +61,22 @@ file = pci-test.flat groups = pci # Test PMU support -[pmu] +[pmu-cycle-counter] file = pmu.flat groups = pmu +extra_params = -append 'cycle-counter 0' # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat -#extra_params = -icount 0 -append '1' +#extra_params = -icount 0 -append 'cycle-counter 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' +#extra_params = -icount 8 -append 'cycle-counter 256' #groups = pmu #accel = tcg
PATCH 3/10 arm: pmu: Add a pmu struct
In reply to Eric AugerThis struct aims at storing information potentially used by all tests such as the pmu version, the read-only part of the PMCR, the number of implemented event counters, ...
--- arm/pmu.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
arm/pmu.c +25 -5
@@ -33,7 +33,14 @@#define NR_SAMPLES 10 -static unsigned int pmu_version; +struct pmu { +unsigned int version; +unsigned int nb_implemented_counters; +uint32_t pmcr_ro; +}; + +static struct pmu pmu; +#if defined(__arm__)#define ID_DFR0_PERFMON_SHIFT 24#define ID_DFR0_PERFMON_MASK 0xf
@@ -265,7 +272,7 @@ static bool check_cpi(int cpi)static void pmccntr64_test (void ) {#ifdef __arm__ -if (pmu_version ==0x3 ) { +if (pmu.version ==0x3 ) {if (ERRATA (9e3f7a296940 )) {write_sysreg (0xdead ,PMCCNTR64 );report (read_sysreg (PMCCNTR64 ) ==0xdead ,"pmccntr64" );
@@ -278,9 +285,22 @@ static void pmccntr64_test(void)/* Return FALSE if no PMU found, otherwise return TRUE */ static bool pmu_probe (void ) { - pmu_version =get_pmu_version (); -report_info ("PMU version: %d" , pmu_version); -return pmu_version !=0 && pmu_version !=0xf ; +uint32_t pmcr; + + pmu.version =get_pmu_version (); +report_info ("PMU version: %d" , pmu.version); + +if (pmu.version ==0 || pmu.version ==0xF ) +return false; + + pmcr =get_pmcr (); + pmu.pmcr_ro = pmcr &0xFFFFFF80 ; + pmu.nb_implemented_counters = + (pmcr >>PMU_PMCR_N_SHIFT ) &PMU_PMCR_N_MASK ; +report_info ("Implements %d event counters" , + pmu.nb_implemented_counters); + +return true; }int main (int argc,char *argv[])
Signature · 1 line
2.20.1
Re: [kvm-unit-tests PATCH 03/10] arm: pmu: Add a pmu struct
Quoted 5 lines · On Mon, 16 Dec 2019 21:47:50 +0100 Eric Auger <[email protected]> wrote:
This struct aims at storing information potentially used by all tests such as the pmu version, the read-only part of the PMCR, the number of implemented event counters, ...
Signed-off-by Eric Auger <[email protected]>
Cheers,
Andre
Quoted 59 lines
--- arm/pmu.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)arm/pmu.c +25
-5@@ -33,7 +33,14 @@#define NR_SAMPLES 10 -static unsigned int pmu_version; +struct pmu { +unsigned int version; +unsigned int nb_implemented_counters; +uint32_t pmcr_ro; +}; + +static struct pmu pmu; +#if defined(__arm__)#define ID_DFR0_PERFMON_SHIFT 24#define ID_DFR0_PERFMON_MASK 0xf@@ -265,7 +272,7 @@ static bool check_cpi(int cpi)static void pmccntr64_test (void ) {#ifdef __arm__ -if (pmu_version ==0x3 ) { +if (pmu.version ==0x3 ) {if (ERRATA (9e3f7a296940 )) {write_sysreg (0xdead ,PMCCNTR64 );report (read_sysreg (PMCCNTR64 ) ==0xdead ,"pmccntr64" );@@ -278,9 +285,22 @@ static void pmccntr64_test(void)/* Return FALSE if no PMU found, otherwise return TRUE */ static bool pmu_probe (void ) { - pmu_version =get_pmu_version (); -report_info ("PMU version: %d" , pmu_version); -return pmu_version !=0 && pmu_version !=0xf ; +uint32_t pmcr; + + pmu.version =get_pmu_version (); +report_info ("PMU version: %d" , pmu.version); + +if (pmu.version ==0 || pmu.version ==0xF ) +return false; + + pmcr =get_pmcr (); + pmu.pmcr_ro = pmcr &0xFFFFFF80 ; + pmu.nb_implemented_counters = + (pmcr >>PMU_PMCR_N_SHIFT ) &PMU_PMCR_N_MASK ; +report_info ("Implements %d event counters" , + pmu.nb_implemented_counters); + +return true; }int main (int argc,char *argv[])
PATCH 4/10 arm: pmu: Check Required Event Support
In reply to Eric AugerIf event counters are implemented check the common events required by the PMUv3 are implemented.
Some are unconditionally required (SW_INCR, CPU_CYCLES, either INST_RETIRED or INST_SPEC). Some others only are required if the implementation implements some other features.
Check those wich are unconditionally required.
This test currently fails on TCG as neither INST_RETIRED or INST_SPEC are supported.
---
v1 ->v2:
- add a comment to explain the PMCEID0/1 splits
--- arm/pmu.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 ++++ 2 files changed, 77 insertions(+)
arm/pmu.c +71 -0
@@ -101,6 +101,10 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr), [z] "r" (0) : "cc"); } + +/* event counter tests only implemented for aarch64 */ +static void test_event_introspection (void ) {} +#elif defined(__aarch64__)#define ID_AA64DFR0_PERFMON_SHIFT 8#define ID_AA64DFR0_PERFMON_MASK 0xf
@@ -139,6 +143,70 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr) : "cc"); } + +#define PMCEID1_EL0 sys_reg(11, 3, 9, 12, 7) + +static bool is_event_supported (uint32_t n,bool warn) +{ +uint64_t pmceid0 =read_sysreg (pmceid0_el0); +uint64_t pmceid1 =read_sysreg_s (PMCEID1_EL0 ); +bool supported; +uint32_t reg; + +/* +* The low 32-bits of PMCEID0/1 respectly describe +* event support for events 0-31/32-63. Their High +* 32-bits describe support for extended events +* starting at 0x4000, using the same split. +*/ +if (n >=0x0 && n <=0x1F ) + reg = pmceid0 &0xFFFFFFFF ; +else if (n >=0x4000 && n <=0x401F ) + reg = pmceid0 >>32 ; +else if (n >=0x20 && n <=0x3F ) + reg = pmceid1 &0xFFFFFFFF ; +else if (n >=0x4020 && n <=0x403F ) + reg = pmceid1 >>32 ; +else +abort (); + + supported = reg & (1 << n); +if (!supported && warn) +report_info ("event %d is not supported" , n); +return supported; +} + +static void test_event_introspection (void ) +{ +bool required_events; + +if (!pmu.nb_implemented_counters) { +report_skip ("No event counter, skip ..." ); +return ; + } + +/* PMUv3 requires an implementation includes some common events */ + required_events =is_event_supported (0x0 , true)/* SW_INCR */ && +is_event_supported (0x11 , true)/* CPU_CYCLES */ && + (is_event_supported (0x8 , true)/* INST_RETIRED */ || +is_event_supported (0x1B , true)/* INST_PREC */ ); + +if (pmu.version ==0x4 ) { +/* ARMv8.1 PMU: STALL_FRONTEND and STALL_BACKEND are required */ + required_events = required_events || +is_event_supported (0x23 , true) || +is_event_supported (0x24 , true); + } + +/* +* L1D_CACHE_REFILL(0x3) and L1D_CACHE(0x4) are only required if +* L1 data / unified cache. BR_MIS_PRED(0x10), BR_PRED(0x12) are only +* required if program-flow prediction is implemented. +*/ + +report (required_events,"Check required events are implemented" ); +} +#endif /*
@@ -326,6 +394,9 @@ int main(int argc, char *argv[]) "Monotonically increasing cycle count");report (check_cpi (cpi),"Cycle/instruction ratio" );pmccntr64_test (); + }else if (strcmp (argv[1 ],"event-introspection" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_event_introspection (); }else {report_abort ("Unknown sub-test '%s'" , argv[1 ]); }
arm/unittests.cfg +6 -0
@@ -66,6 +66,12 @@ file = pmu.flat groups = pmu extra_params = -append 'cycle-counter 0' +[pmu-event-introspection] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'event-introspection' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat
Signature · 1 line
2.20.1
Re: [kvm-unit-tests PATCH 04/10] arm: pmu: Check Required Event Support
On Mon, 16 Dec 2019 21:47:51 +0100
Eric Auger <[email protected]> wrote:
Hi Eric,
Quoted 60 lines
If event counters are implemented check the common events required by the PMUv3 are implemented.
Some are unconditionally required (
SW_INCR,CPU_CYCLES, eitherINST_RETIREDorINST_SPEC). Some others only are required if the implementation implements some other features.Check those wich are unconditionally required.
This test currently fails on TCG as neither
INST_RETIREDorINST_SPECare supported.Signed-off-by Eric Auger <[email protected]>---
v1 ->v2:
- add a comment to explain the PMCEID0/1 splits--- arm/pmu.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 ++++ 2 files changed, 77 insertions(+)arm/pmu.c +22
-0@@ -101,6 +101,10 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr), [z] "r" (0) : "cc"); } + +/* event counter tests only implemented for aarch64 */ +static void test_event_introspection (void ) {} +#elif defined(__aarch64__)#define ID_AA64DFR0_PERFMON_SHIFT 8#define ID_AA64DFR0_PERFMON_MASK 0xf@@ -139,6 +143,70 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr) : "cc"); } + +#define PMCEID1_EL0 sys_reg(11, 3, 9, 12, 7) + +static bool is_event_supported (uint32_t n,bool warn) +{ +uint64_t pmceid0 =read_sysreg (pmceid0_el0); +uint64_t pmceid1 =read_sysreg_s (PMCEID1_EL0 ); +bool supported; +uint32_t reg; + +/* +* The low 32-bits of PMCEID0/1 respectly describe +* event support for events 0-31/32-63. Their High +* 32-bits describe support for extended events +* starting at 0x4000, using the same split. +*/ +if (n >=0x0 && n <=0x1F ) + reg = pmceid0 &0xFFFFFFFF ;
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 173
Quoted 10 lines
arm/pmu.c +10
-0+else if (n >=0x4000 && n <=0x401F ) + reg = pmceid0 >>32 ; +else if (n >=0x20 && n <=0x3F ) + reg = pmceid1 &0xFFFFFFFF ; +else if (n >=0x4020 && n <=0x403F ) + reg = pmceid1 >>32 ; +else +abort (); + + supported = reg & (1 << n);
Don't we need to mask off everything but the lowest 5 bits of "n"? Probably also using "1U" is better.
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 179
Quoted 6 lines
arm/pmu.c +6
-0+if (!supported && warn) +report_info ("event %d is not supported" , n); +return supported; +} + +static void test_event_introspection (void )
"introspection" sounds quite sophisticated. Are you planning to extend this? If not, could we maybe rename it to "test_available_events"?
Quoted 8 lines
arm/pmu.c +8
-0+{ +bool required_events; + +if (!pmu.nb_implemented_counters) { +report_skip ("No event counter, skip ..." ); +return ; + } +
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 197
Quoted 10 lines
arm/pmu.c +10
-0+/* PMUv3 requires an implementation includes some common events */ + required_events =is_event_supported (0x0 , true)/* SW_INCR */ && +is_event_supported (0x11 , true)/* CPU_CYCLES */ && + (is_event_supported (0x8 , true)/* INST_RETIRED */ || +is_event_supported (0x1B , true)/* INST_PREC */ ); + +if (pmu.version ==0x4 ) { +/* ARMv8.1 PMU: STALL_FRONTEND and STALL_BACKEND are required */ + required_events = required_events || + is_event_supported(0x23, true) ||
Shouldn't those two operators be '&&' instead?
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 205
Quoted 8 lines
arm/pmu.c +8
-0+is_event_supported (0x24 , true); + } + +/* +* L1D_CACHE_REFILL(0x3) and L1D_CACHE(0x4) are only required if +* L1 data / unified cache. BR_MIS_PRED(0x10), BR_PRED(0x12) are only +* required if program-flow prediction is implemented. +*/
Is this a TODO?
Cheers,
Andre
Quoted 34 lines
arm/pmu.c +7
-0+ + report(required_events, "Check required events are implemented"); +} +#endif /* @@ -326,6 +394,9 @@ int main(int argc, char *argv[]) "Monotonically increasing cycle count");report (check_cpi (cpi),"Cycle/instruction ratio" );pmccntr64_test (); + }else if (strcmp (argv[1 ],"event-introspection" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_event_introspection (); }else {report_abort ("Unknown sub-test '%s'" , argv[1 ]); }arm/unittests.cfg +6
-0@@ -66,6 +66,12 @@ file = pmu.flat groups = pmu extra_params = -append 'cycle-counter 0' +[pmu-event-introspection] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'event-introspection' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat
Re: [kvm-unit-tests PATCH 04/10] arm: pmu: Check Required Event Support
Hi Andre,
Quoted 69 lines · Andre Przywara
On Mon, 16 Dec 2019 21:47:51 +0100
Eric Auger <[email protected]> wrote:Hi Eric,
Quoted 64 lines
If event counters are implemented check the common events required by the PMUv3 are implemented.
Some are unconditionally required (
SW_INCR,CPU_CYCLES, eitherINST_RETIREDorINST_SPEC). Some others only are required if the implementation implements some other features.Check those wich are unconditionally required.
This test currently fails on TCG as neither
INST_RETIREDorINST_SPECare supported.Signed-off-by Eric Auger <[email protected]>---
v1 ->v2:
- add a comment to explain the PMCEID0/1 splits--- arm/pmu.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 ++++ 2 files changed, 77 insertions(+)arm/pmu.c +26
-0@@ -101,6 +101,10 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr), [z] "r" (0) : "cc"); } + +/* event counter tests only implemented for aarch64 */ +static void test_event_introspection (void ) {} +#elif defined(__aarch64__)#define ID_AA64DFR0_PERFMON_SHIFT 8#define ID_AA64DFR0_PERFMON_MASK 0xf@@ -139,6 +143,70 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr) : "cc"); } + +#define PMCEID1_EL0 sys_reg(11, 3, 9, 12, 7) + +static bool is_event_supported (uint32_t n,bool warn) +{ +uint64_t pmceid0 =read_sysreg (pmceid0_el0); +uint64_t pmceid1 =read_sysreg_s (PMCEID1_EL0 ); +bool supported; +uint32_t reg; + +/* +* The low 32-bits of PMCEID0/1 respectly describe +* event support for events 0-31/32-63. Their High +* 32-bits describe support for extended events +* starting at 0x4000, using the same split. +*/ +if (n >=0x0 && n <=0x1F ) + reg = pmceid0 &0xFFFFFFFF ; +else if (n >=0x4000 && n <=0x401F ) + reg = pmceid0 >>32 ; +else if (n >=0x20 && n <=0x3F ) + reg = pmceid1 &0xFFFFFFFF ;
Quoted 8 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 173
Quoted 6 lines
arm/pmu.c +6
-0+else if (n >=0x4020 && n <=0x403F ) + reg = pmceid1 >>32 ; +else +abort (); + + supported = reg & (1 << n);Don't we need to mask off everything but the lowest 5 bits of "n"? Probably also using "1U" is better.
I added an assert to check n is less or equal than 0x3F
Quoted 9 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 179
Quoted 7 lines
arm/pmu.c +6
-0+if (!supported && warn) +report_info ("event %d is not supported" , n); +return supported; +} + +static void test_event_introspection (void )"introspection" sounds quite sophisticated. Are you planning to extend this? If not, could we maybe rename it to "
test_available_events"?
Yes this test is a placeholder for looking at the PMU characteristics and we may add some other queries there.
Quoted 13 lines
Quoted 13 lines
arm/pmu.c +12
-0+{ +bool required_events; + +if (!pmu.nb_implemented_counters) { +report_skip ("No event counter, skip ..." ); +return ; + } + +/* PMUv3 requires an implementation includes some common events */ + required_events =is_event_supported (0x0 , true)/* SW_INCR */ && + is_event_supported(0x11, true) /* CPU_CYCLES */ && + (is_event_supported(0x8, true) /* INST_RETIRED */ ||
Quoted 8 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 197
Quoted 6 lines
arm/pmu.c +6
-0+ is_event_supported(0x1B, true) /* INST_PREC */); + +if (pmu.version ==0x4 ) { +/* ARMv8.1 PMU: STALL_FRONTEND and STALL_BACKEND are required */ + required_events = required_events || + is_event_supported(0x23, true) ||Shouldn't those two operators be '&&' instead?
yes definitively
Quoted 11 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 205
Quoted 9 lines
arm/pmu.c +8
-0+is_event_supported (0x24 , true); + } + +/* +* L1D_CACHE_REFILL(0x3) and L1D_CACHE(0x4) are only required if +* L1 data / unified cache. BR_MIS_PRED(0x10), BR_PRED(0x12) are only +* required if program-flow prediction is implemented. +*/ Is this a TODO?
yes. Added TODO. I do not know how to check whether the conditions are satisfied? Do you have any idea?
Thank you for the review!
Eric
Quoted 40 lines
Cheers,
AndreQuoted 34 lines
arm/pmu.c +7
-0+ + report(required_events, "Check required events are implemented"); +} +#endif /* @@ -326,6 +394,9 @@ int main(int argc, char *argv[]) "Monotonically increasing cycle count");report (check_cpi (cpi),"Cycle/instruction ratio" );pmccntr64_test (); + }else if (strcmp (argv[1 ],"event-introspection" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_event_introspection (); }else {report_abort ("Unknown sub-test '%s'" , argv[1 ]); }arm/unittests.cfg +6
-0@@ -66,6 +66,12 @@ file = pmu.flat groups = pmu extra_params = -append 'cycle-counter 0' +[pmu-event-introspection] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'event-introspection' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat
Re: [kvm-unit-tests PATCH 04/10] arm: pmu: Check Required Event Support
On 09/01/2020 16:54, Auger Eric wrote:
Hi Eric,
Quoted 78 lines · Andre Przywara
Quoted 69 lines
On Mon, 16 Dec 2019 21:47:51 +0100
Eric Auger <[email protected]> wrote:Hi Eric,
Quoted 64 lines
If event counters are implemented check the common events required by the PMUv3 are implemented.
Some are unconditionally required (
SW_INCR,CPU_CYCLES, eitherINST_RETIREDorINST_SPEC). Some others only are required if the implementation implements some other features.Check those wich are unconditionally required.
This test currently fails on TCG as neither
INST_RETIREDorINST_SPECare supported.Signed-off-by Eric Auger <[email protected]>---
v1 ->v2:
- add a comment to explain the PMCEID0/1 splits--- arm/pmu.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 ++++ 2 files changed, 77 insertions(+)arm/pmu.c +26
-0@@ -101,6 +101,10 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr), [z] "r" (0) : "cc"); } + +/* event counter tests only implemented for aarch64 */ +static void test_event_introspection (void ) {} +#elif defined(__aarch64__)#define ID_AA64DFR0_PERFMON_SHIFT 8#define ID_AA64DFR0_PERFMON_MASK 0xf@@ -139,6 +143,70 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr) : "cc"); } + +#define PMCEID1_EL0 sys_reg(11, 3, 9, 12, 7) + +static bool is_event_supported (uint32_t n,bool warn) +{ +uint64_t pmceid0 =read_sysreg (pmceid0_el0); +uint64_t pmceid1 =read_sysreg_s (PMCEID1_EL0 ); +bool supported; +uint32_t reg; + +/* +* The low 32-bits of PMCEID0/1 respectly describe +* event support for events 0-31/32-63. Their High +* 32-bits describe support for extended events +* starting at 0x4000, using the same split. +*/ +if (n >=0x0 && n <=0x1F ) + reg = pmceid0 &0xFFFFFFFF ; +else if (n >=0x4000 && n <=0x401F ) + reg = pmceid0 >>32 ; +else if (n >=0x20 && n <=0x3F ) + reg = pmceid1 &0xFFFFFFFF ;Quoted 8 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 173
Quoted 6 lines
arm/pmu.c +6
-0+else if (n >=0x4020 && n <=0x403F ) + reg = pmceid1 >>32 ; +else +abort (); + + supported = reg & (1 << n);Don't we need to mask off everything but the lowest 5 bits of "n"? Probably also using "1U" is better.
Quoted 1 line
I added an assert to check n is less or equal than
0x3F
But "n" will definitely be bigger than that in case of an extended event, won't it? So you adjust "reg" accordingly, but miss to do something similar to "n"?
Quoted 44 lines
Quoted 9 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 179
Quoted 7 lines
arm/pmu.c +6
-0+if (!supported && warn) +report_info ("event %d is not supported" , n); +return supported; +} + +static void test_event_introspection (void )"introspection" sounds quite sophisticated. Are you planning to extend this? If not, could we maybe rename it to "
test_available_events"?Yes this test is a placeholder for looking at the PMU characteristics and we may add some other queries there.
Quoted 13 lines
Quoted 13 lines
arm/pmu.c +12
-0+{ +bool required_events; + +if (!pmu.nb_implemented_counters) { +report_skip ("No event counter, skip ..." ); +return ; + } + +/* PMUv3 requires an implementation includes some common events */ + required_events =is_event_supported (0x0 , true)/* SW_INCR */ && + is_event_supported(0x11, true) /* CPU_CYCLES */ && + (is_event_supported(0x8, true) /* INST_RETIRED */ ||Quoted 8 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 197
Quoted 6 lines
arm/pmu.c +6
-0+ is_event_supported(0x1B, true) /* INST_PREC */); + +if (pmu.version ==0x4 ) { +/* ARMv8.1 PMU: STALL_FRONTEND and STALL_BACKEND are required */ + required_events = required_events || + is_event_supported(0x23, true) ||Shouldn't those two operators be '&&' instead?
yes definitively
Quoted 11 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 205
Quoted 9 lines
arm/pmu.c +8
-0+is_event_supported (0x24 , true); + } + +/* +* L1D_CACHE_REFILL(0x3) and L1D_CACHE(0x4) are only required if +* L1 data / unified cache. BR_MIS_PRED(0x10), BR_PRED(0x12) are only +* required if program-flow prediction is implemented. +*/ Is this a TODO?
Quoted 2 lines
yes. Added TODO. I do not know how to check whether the conditions are satisfied? Do you have any idea?
Well, AFAICS KVM doesn't filter PMCEIDn, right? So some basic checks are surely fine, but I wouldn't go crazy about checking every possible aspect of it. After all you would just check the hardware, as we pass this register on.
Cheers,
Andre.
Quoted 44 lines
Thank you for the review!
Eric
Quoted 40 lines
Cheers,
AndreQuoted 34 lines
arm/pmu.c +7
-0+ + report(required_events, "Check required events are implemented"); +} +#endif /* @@ -326,6 +394,9 @@ int main(int argc, char *argv[]) "Monotonically increasing cycle count");report (check_cpi (cpi),"Cycle/instruction ratio" );pmccntr64_test (); + }else if (strcmp (argv[1 ],"event-introspection" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_event_introspection (); }else {report_abort ("Unknown sub-test '%s'" , argv[1 ]); }arm/unittests.cfg +6
-0@@ -66,6 +66,12 @@ file = pmu.flat groups = pmu extra_params = -append 'cycle-counter 0' +[pmu-event-introspection] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'event-introspection' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat
Re: [kvm-unit-tests PATCH 04/10] arm: pmu: Check Required Event Support
Hi Andre,
Quoted 82 lines · André Przywara
On 09/01/2020 16:54, Auger Eric wrote:
Hi Eric,
Quoted 78 lines · Andre Przywara
Quoted 77 lines
On Mon, 16 Dec 2019 21:47:51 +0100
Eric Auger <[email protected]> wrote:Hi Eric,
Quoted 60 lines
If event counters are implemented check the common events required by the PMUv3 are implemented.
Some are unconditionally required (
SW_INCR,CPU_CYCLES, eitherINST_RETIREDorINST_SPEC). Some others only are required if the implementation implements some other features.Check those wich are unconditionally required.
This test currently fails on TCG as neither
INST_RETIREDorINST_SPECare supported.Signed-off-by Eric Auger <[email protected]>---
v1 ->v2:
- add a comment to explain the PMCEID0/1 splits--- arm/pmu.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 ++++ 2 files changed, 77 insertions(+)arm/pmu.c +22
-0@@ -101,6 +101,10 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr), [z] "r" (0) : "cc"); } + +/* event counter tests only implemented for aarch64 */ +static void test_event_introspection (void ) {} +#elif defined(__aarch64__)#define ID_AA64DFR0_PERFMON_SHIFT 8#define ID_AA64DFR0_PERFMON_MASK 0xf@@ -139,6 +143,70 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : [pmcr] "r" (pmcr) : "cc"); } + +#define PMCEID1_EL0 sys_reg(11, 3, 9, 12, 7) + +static bool is_event_supported (uint32_t n,bool warn) +{ +uint64_t pmceid0 =read_sysreg (pmceid0_el0); +uint64_t pmceid1 =read_sysreg_s (PMCEID1_EL0 ); +bool supported; +uint32_t reg; + +/* +* The low 32-bits of PMCEID0/1 respectly describe +* event support for events 0-31/32-63. Their High +* 32-bits describe support for extended events +* starting at 0x4000, using the same split. +*/ +if (n >=0x0 && n <=0x1F ) + reg = pmceid0 &0xFFFFFFFF ;arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 173
Quoted 10 lines
arm/pmu.c +10
-0+else if (n >=0x4000 && n <=0x401F ) + reg = pmceid0 >>32 ; +else if (n >=0x20 && n <=0x3F ) + reg = pmceid1 &0xFFFFFFFF ; +else if (n >=0x4020 && n <=0x403F ) + reg = pmceid1 >>32 ; +else +abort (); + + supported = reg & (1 << n);Don't we need to mask off everything but the lowest 5 bits of "n"? Probably also using "1U" is better.
Quoted 5 lines
Quoted 1 line
I added an assert to check n is less or equal than
0x3FBut "n" will definitely be bigger than that in case of an extended event, won't it? So you adjust "reg" accordingly, but miss to do something similar to "n"?
ouch yes. Sorry. I Will do what you suggest. Nethertheless this would be test code error.
Quoted 45 lines
Quoted 45 lines
Quoted 10 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 179
Quoted 8 lines
arm/pmu.c +6
-0+if (!supported && warn) +report_info ("event %d is not supported" , n); +return supported; +} + +static void test_event_introspection (void )"introspection" sounds quite sophisticated. Are you planning to extend this? If not, could we maybe rename it to "
test_available_events"?Yes this test is a placeholder for looking at the PMU characteristics and we may add some other queries there.
Quoted 13 lines
Quoted 13 lines
arm/pmu.c +12
-0+{ +bool required_events; + +if (!pmu.nb_implemented_counters) { +report_skip ("No event counter, skip ..." ); +return ; + } + +/* PMUv3 requires an implementation includes some common events */ + required_events =is_event_supported (0x0 , true)/* SW_INCR */ && + is_event_supported(0x11, true) /* CPU_CYCLES */ && + (is_event_supported(0x8, true) /* INST_RETIRED */ ||Quoted 8 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 197
Quoted 6 lines
arm/pmu.c +6
-0+ is_event_supported(0x1B, true) /* INST_PREC */); + +if (pmu.version ==0x4 ) { +/* ARMv8.1 PMU: STALL_FRONTEND and STALL_BACKEND are required */ + required_events = required_events || + is_event_supported(0x23, true) ||Shouldn't those two operators be '&&' instead?
yes definitively
Quoted 11 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 205
Quoted 9 lines
arm/pmu.c +8
-0+is_event_supported (0x24 , true); + } + +/* +* L1D_CACHE_REFILL(0x3) and L1D_CACHE(0x4) are only required if +* L1 data / unified cache. BR_MIS_PRED(0x10), BR_PRED(0x12) are only +* required if program-flow prediction is implemented. +*/ Is this a TODO?
Quoted 7 lines
Quoted 2 lines
yes. Added TODO. I do not know how to check whether the conditions are satisfied? Do you have any idea?
Well, AFAICS KVM doesn't filter PMCEIDn, right? So some basic checks are surely fine, but I wouldn't go crazy about checking every possible aspect of it. After all you would just check the hardware, as we pass this register on.
I agree I can skip those.
Thanks
Eric
Quoted 49 lines
Cheers,
Andre.Quoted 44 lines
Thank you for the review!
Eric
Quoted 40 lines
Cheers,
AndreQuoted 34 lines
arm/pmu.c +7
-0+ + report(required_events, "Check required events are implemented"); +} +#endif /* @@ -326,6 +394,9 @@ int main(int argc, char *argv[]) "Monotonically increasing cycle count");report (check_cpi (cpi),"Cycle/instruction ratio" );pmccntr64_test (); + }else if (strcmp (argv[1 ],"event-introspection" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_event_introspection (); }else {report_abort ("Unknown sub-test '%s'" , argv[1 ]); }arm/unittests.cfg +6
-0@@ -66,6 +66,12 @@ file = pmu.flat groups = pmu extra_params = -append 'cycle-counter 0' +[pmu-event-introspection] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'event-introspection' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat
PATCH 5/10 arm: pmu: Basic event counter Tests
In reply to Eric AugerAdds the following tests:
- event-counter-config: test event counter configuration
- basic-event-count:
- programs counters #0 and #1 to count 2 required events (resp. CPU_CYCLES and INST_RETIRED). Counter #0 is preset to a value close enough to the 32b
overflow limit so that we check the overflow bit is set after the execution of the asm loop.
- mem-access: counts MEM_ACCESS event on counters #0 and #1 with and without 32-bit overflow.
--- arm/pmu.c | 261 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 18 ++++ 2 files changed, 279 insertions(+)
arm/pmu.c +261 -0
@@ -18,9 +18,15 @@#include "asm/barrier.h" #include "asm/sysreg.h" #include "asm/processor.h" +#include <bitops.h> +#include <asm/gic.h> #define PMU_PMCR_E (1 << 0) +#define PMU_PMCR_P (1 << 1)#define PMU_PMCR_C (1 << 2) +#define PMU_PMCR_D (1 << 3) +#define PMU_PMCR_X (1 << 4) +#define PMU_PMCR_DP (1 << 5)#define PMU_PMCR_LC (1 << 6)#define PMU_PMCR_N_SHIFT 11#define PMU_PMCR_N_MASK 0x1f
@@ -104,6 +110,9 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr)/* event counter tests only implemented for aarch64 */ static void test_event_introspection (void ) {} +static void test_event_counter_config (void ) {} +static void test_basic_event_count (void ) {} +static void test_mem_access (void ) {}#elif defined(__aarch64__)#define ID_AA64DFR0_PERFMON_SHIFT 8
@@ -145,6 +154,32 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) }#define PMCEID1_EL0 sys_reg(11, 3, 9, 12, 7) +#define PMCNTENSET_EL0 sys_reg(11, 3, 9, 12, 1) +#define PMCNTENCLR_EL0 sys_reg(11, 3, 9, 12, 2) + +#define PMEVTYPER_EXCLUDE_EL1 (1 << 31) +#define PMEVTYPER_EXCLUDE_EL0 (1 << 30) + +#define regn_el0 (__reg, __n) __reg ## __n ## _el0 +#define write_regn (__reg, __n, __val) \ + write_sysreg((__val), __reg ## __n ## _el0) + +#define read_regn (__reg, __n) \ + read_sysreg(__reg ## __n ## _el0) + +#define print_pmevtyper (__s, __n) do { \ + uint32_t val; \ + val = read_regn(pmevtyper, __n);\ + report_info("%s pmevtyper%d=0x%x, eventcount=0x%x (p=%ld, u=%ld nsk=%ld, nsu=%ld, nsh=%ld m=%ld, mt=%ld)", \ + (__s), (__n), val, val & 0xFFFF, \ + (BIT_MASK(31) & val) >> 31, \ + (BIT_MASK(30) & val) >> 30, \ + (BIT_MASK(29) & val) >> 29, \ + (BIT_MASK(28) & val) >> 28, \ + (BIT_MASK(27) & val) >> 27, \ + (BIT_MASK(26) & val) >> 26, \ + (BIT_MASK(25) & val) >> 25); \ + } while (0)static bool is_event_supported (uint32_t n,bool warn) {
@@ -207,6 +242,223 @@ static void test_event_introspection(void)report (required_events,"Check required events are implemented" ); } +static inline void mem_access_loop (void *addr,int loop,uint32_t pmcr) +{ +asmvolatile ( +" msr pmcr_el0, %[pmcr]\n" +" isb\n" +" mov x10, %[loop]\n" +"1: sub x10, x10, #1\n" +" mov x8, %[addr]\n" +" ldr x9, [x8]\n" +" cmp x10, #0x0\n" +" b.gt 1b\n" +" msr pmcr_el0, xzr\n" +" isb\n" + : + : [addr]"r" (addr), [pmcr]"r" (pmcr), [loop]"r" (loop) + : ); +} + + +static void pmu_reset (void ) +{ +/* reset all counters, counting disabled at PMCR level*/ +set_pmcr (pmu.pmcr_ro |PMU_PMCR_LC |PMU_PMCR_C |PMU_PMCR_P ); +/* Disable all counters */ +write_sysreg_s (0xFFFFFFFF ,PMCNTENCLR_EL0 ); +/* clear overflow reg */ +write_sysreg (0xFFFFFFFF , pmovsclr_el0); +/* disable overflow interrupts on all counters */ +write_sysreg (0xFFFFFFFF , pmintenclr_el1); +isb (); +} + +static void test_event_counter_config (void ) +{ +int i; + +if (!pmu.nb_implemented_counters) { +report_skip ("No event counter, skip ..." ); +return ; + } + +pmu_reset (); + +/* +* Test setting through PMESELR/PMXEVTYPER and PMEVTYPERn read, +* select counter 0 +*/ +write_sysreg (1 ,PMSELR_EL0 ); +/* program this counter to count unsupported event */ +write_sysreg (0xEA ,PMXEVTYPER_EL0 ); +write_sysreg (0xdeadbeef ,PMXEVCNTR_EL0 ); +report ((read_regn (pmevtyper,1 ) &0xFFF ) ==0xEA , +"PMESELR/PMXEVTYPER/PMEVTYPERn" ); +report ((read_regn (pmevcntr,1 ) ==0xdeadbeef ), +"PMESELR/PMXEVCNTR/PMEVCNTRn" ); + +/* try configure an unsupported event within the range [0x0, 0x3F] */ +for (i =0 ; i <=0x3F ; i++) { +if (!is_event_supported (i, false)) + goto test_unsupported; + } +report_skip ("pmevtyper: all events within [0x0, 0x3F] are supported" ); + +test_unsupported: +/* select counter 0 */ +write_sysreg (0 ,PMSELR_EL0 ); +/* program this counter to count unsupported event */ +write_sysreg (i,PMXEVCNTR_EL0 ); +/* read the counter value */ +read_sysreg (PMXEVCNTR_EL0 ); +report (read_sysreg (PMXEVCNTR_EL0 ) == i, +"read of a counter programmed with unsupported event" ); + +} + +static bool satisfy_prerequisites (uint32_t *events,unsigned int nb_events) +{ +int i; + +if (pmu.nb_implemented_counters < nb_events) { +report_skip ("Skip test as number of counters is too small (%d)" , + pmu.nb_implemented_counters); +return false; + } + +for (i =0 ; i < nb_events; i++) { +if (!is_event_supported (events[i], false)) { +report_skip ("Skip test as event %d is not supported" , + events[i]); +return false; + } + } +return true; +} + +static void test_basic_event_count (void ) +{ +uint32_t implemented_counter_mask, non_implemented_counter_mask; +uint32_t counter_mask; +uint32_t events[] = { +0x11 ,/* CPU_CYCLES */ +0x8 ,/* INST_RETIRED */ + }; + +if (!satisfy_prerequisites (events,ARRAY_SIZE (events))) +return ; + + implemented_counter_mask = (1 << pmu.nb_implemented_counters) -1 ; + non_implemented_counter_mask = ~((1 <<31 ) | implemented_counter_mask); + counter_mask = implemented_counter_mask | non_implemented_counter_mask; + +write_regn (pmevtyper,0 , events[0 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); + +/* disable all counters */ +write_sysreg_s (0xFFFFFFFF ,PMCNTENCLR_EL0 ); +report (!read_sysreg_s (PMCNTENCLR_EL0 ) && !read_sysreg_s (PMCNTENSET_EL0 ), +"pmcntenclr: disable all counters" ); + +/* +* clear cycle and all event counters and allow counter enablement +* through PMCNTENSET. LC is RES1. +*/ +set_pmcr (pmu.pmcr_ro |PMU_PMCR_LC |PMU_PMCR_C |PMU_PMCR_P ); +isb (); +report (get_pmcr () == (pmu.pmcr_ro |PMU_PMCR_LC ),"pmcr: reset counters" ); + +/* Preset counter #0 to 0xFFFFFFF0 to trigger an overflow interrupt */ +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +report (read_regn (pmevcntr,0 ) ==0xFFFFFFF0 , +"counter #0 preset to 0xFFFFFFF0" ); +report (!read_regn (pmevcntr,1 ),"counter #1 is 0" ); + +/* +* Enable all implemented counters and also attempt to enable +* not supported counters. Counting still is disabled by !PMCR.E +*/ +write_sysreg_s (counter_mask,PMCNTENSET_EL0 ); + +/* check only those implemented are enabled */ +report ((read_sysreg_s (PMCNTENSET_EL0 ) ==read_sysreg_s (PMCNTENCLR_EL0 )) && + (read_sysreg_s (PMCNTENSET_EL0 ) == implemented_counter_mask), +"pmcntenset: enabled implemented_counters" ); + +/* Disable all counters but counters #0 and #1 */ +write_sysreg_s (~0x3 ,PMCNTENCLR_EL0 ); +report ((read_sysreg_s (PMCNTENSET_EL0 ) ==read_sysreg_s (PMCNTENCLR_EL0 )) && + (read_sysreg_s (PMCNTENSET_EL0 ) ==0x3 ), +"pmcntenset: just enabled #0 and #1" ); + +/* clear overflow register */ +write_sysreg (0xFFFFFFFF , pmovsclr_el0); +report (!read_sysreg (pmovsclr_el0),"check overflow reg is 0" ); + +/* disable overflow interrupts on all counters*/ +write_sysreg (0xFFFFFFFF , pmintenclr_el1); +report (!read_sysreg (pmintenclr_el1), +"pmintenclr_el1=0, all interrupts disabled" ); + +/* enable overflow interrupts on all event counters */ +write_sysreg (implemented_counter_mask | non_implemented_counter_mask, + pmintenset_el1); +report (read_sysreg (pmintenset_el1) == implemented_counter_mask, +"overflow interrupts enabled on all implemented counters" ); + +/* Set PMCR.E, execute asm code and unset PMCR.E */ +precise_instrs_loop (20 , pmu.pmcr_ro |PMU_PMCR_E ); + +report_info ("counter #0 is 0x%lx (CPU_CYCLES)" , +read_regn (pmevcntr,0 )); +report_info ("counter #1 is 0x%lx (INST_RETIRED)" , +read_regn (pmevcntr,1 )); + +report_info ("overflow reg = 0x%lx" ,read_sysreg (pmovsclr_el0)); +report (read_sysreg (pmovsclr_el0) &0x1 , +"check overflow happened on #0 only" ); +} + +static void test_mem_access (void ) +{ +void *addr =malloc (PAGE_SIZE ); +uint32_t events[] = { +0x13 ,/* MEM_ACCESS */ +0x13 ,/* MEM_ACCESS */ + }; + +if (!satisfy_prerequisites (events,ARRAY_SIZE (events))) +return ; + +pmu_reset (); + +write_regn (pmevtyper,0 , events[0 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +isb (); +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("counter #0 is %ld (MEM_ACCESS)" ,read_regn (pmevcntr,0 )); +report_info ("counter #1 is %ld (MEM_ACCESS)" ,read_regn (pmevcntr,1 )); +/* We may not measure exactly 20 mem access. Depends on the platform */ +report ((read_regn (pmevcntr,0 ) ==read_regn (pmevcntr,1 )) && + (read_regn (pmevcntr,0 ) >=20 ) && !read_sysreg (pmovsclr_el0), +"Ran 20 mem accesses" ); + +pmu_reset (); + +write_regn (pmevcntr,0 ,0xFFFFFFFA ); +write_regn (pmevcntr,1 ,0xFFFFFFF0 ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +isb (); +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report (read_sysreg (pmovsclr_el0) ==0x3 , +"Ran 20 mem accesses with expected overflows on both counters" ); +report_info ("cnt#0 = %ld cnt#1=%ld overflow=0x%lx" , +read_regn (pmevcntr,0 ),read_regn (pmevcntr,1 ), +read_sysreg (pmovsclr_el0)); +} +#endif /*
@@ -397,6 +649,15 @@ int main(int argc, char *argv[]) }else if (strcmp (argv[1 ],"event-introspection" ) ==0 ) {report_prefix_push (argv[1 ]);test_event_introspection (); + }else if (strcmp (argv[1 ],"event-counter-config" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_event_counter_config (); + }else if (strcmp (argv[1 ],"basic-event-count" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_basic_event_count (); + }else if (strcmp (argv[1 ],"mem-access" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_mem_access (); }else {report_abort ("Unknown sub-test '%s'" , argv[1 ]); }
arm/unittests.cfg +18 -0
@@ -72,6 +72,24 @@ groups = pmu arch = arm64 extra_params = -append 'event-introspection' +[pmu-event-counter-config] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'event-counter-config' + +[pmu-basic-event-count] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'basic-event-count' + +[pmu-mem-access] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'mem-access' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat
Signature · 1 line
2.20.1
Re: [kvm-unit-tests PATCH 05/10] arm: pmu: Basic event counter Tests
On Mon, 16 Dec 2019 21:47:52 +0100
Eric Auger <[email protected]> wrote:
Hi Eric,
thanks a lot for your work on these elaborate tests! I have some PMU test extensions as well, but they are nowhere as sophisticated as yours!
Just ran this on my ThunderX2 desktop (4.15.0-65-generic #74-Ubuntu kernel, QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.21)), and it reported the following fails:
INFO: pmu: basic-event-count: counter #0 is 0x207e (CPU_CYCLES)
INFO: pmu: basic-event-count: counter #1 is 0xc89 (INST_RETIRED)
INFO: pmu: basic-event-count: overflow reg = 0x0
FAIL: pmu: basic-event-count: check overflow happened on #0 only
....
INFO: PMU version: 4
INFO: Implements 6 event counters
INFO: pmu: mem-access: counter #0 is 1297 (MEM_ACCESS)
INFO: pmu: mem-access: counter #1 is 1287 (MEM_ACCESS)
FAIL: pmu: mem-access: Ran 20 mem accesses
FAIL: pmu: mem-access: Ran 20 mem accesses with expected overflows on both counters
INFO: pmu: mem-access: cnt#0 = 1353 cnt#1=1259 overflow=0x0
Do you know about this? Is this due to kernel bugs? Because Ubuntu cleverly chose an EOL kernel for their stable distro :-P Will try to have a look and repeat on a Juno.
Comments inline ....
Quoted 48 lines
Adds the following tests:
- event-counter-config: test event counter configuration
- basic-event-count:
- programs counters #0 and #1 to count 2 required events (resp.CPU_CYCLESandINST_RETIRED). Counter #0 is preset to a value close enough to the 32b
overflow limit so that we check the overflow bit is set after the execution of the asm loop.
- mem-access: countsMEM_ACCESSevent on counters #0 and #1 with and without 32-bit overflow.Signed-off-by Eric Auger <[email protected]>--- arm/pmu.c | 261 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 18 ++++ 2 files changed, 279 insertions(+)arm/pmu.c +9
-0@@ -18,9 +18,15 @@#include "asm/barrier.h" #include "asm/sysreg.h" #include "asm/processor.h" +#include <bitops.h> +#include <asm/gic.h> #define PMU_PMCR_E (1 << 0) +#define PMU_PMCR_P (1 << 1)#define PMU_PMCR_C (1 << 2) +#define PMU_PMCR_D (1 << 3) +#define PMU_PMCR_X (1 << 4) +#define PMU_PMCR_DP (1 << 5)#define PMU_PMCR_LC (1 << 6)#define PMU_PMCR_N_SHIFT 11#define PMU_PMCR_N_MASK 0x1f@@ -104,6 +110,9 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr)/* event counter tests only implemented for aarch64 */ static void test_event_introspection (void ) {} +static void test_event_counter_config (void ) {} +static void test_basic_event_count (void ) {} +static void test_mem_access (void ) {}#elif defined(__aarch64__)#define ID_AA64DFR0_PERFMON_SHIFT 8
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 158
Quoted 5 lines
arm/pmu.c +2
-0@@ -145,6 +154,32 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) }#define PMCEID1_EL0 sys_reg(11, 3, 9, 12, 7) +#define PMCNTENSET_EL0 sys_reg(11, 3, 9, 12, 1) +#define PMCNTENCLR_EL0 sys_reg(11, 3, 9, 12, 2)
op0 (the first argument) is only two bits, so it should read "3" instead of "11" here. That's already a bug in the existing PMCEID1_EL0 definition. We get away with it because the macro masks with 3, but it should be still written correctly here. Not sure where the "11" actually comes from.
Quoted 13 lines
arm/pmu.c +13
-0+ +#define PMEVTYPER_EXCLUDE_EL1 (1 << 31) +#define PMEVTYPER_EXCLUDE_EL0 (1 << 30) + +#define regn_el0 (__reg, __n) __reg ## __n ## _el0 +#define write_regn (__reg, __n, __val) \ + write_sysreg((__val), __reg ## __n ## _el0) + +#define read_regn (__reg, __n) \ + read_sysreg(__reg ## __n ## _el0) + +#define print_pmevtyper (__s, __n) do { \ + uint32_t val; \
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 181
Quoted 10 lines
arm/pmu.c +10
-0+ val =read_regn (pmevtyper, __n);\ +report_info ("%s pmevtyper%d=0x%x, eventcount=0x%x (p=%ld, u=%ld nsk=%ld, nsu=%ld, nsh=%ld m=%ld, mt=%ld)" , \ + (__s), (__n), val, val &0xFFFF , \ + (BIT_MASK (31 ) & val) >>31 , \ + (BIT_MASK (30 ) & val) >>30 , \ + (BIT_MASK (29 ) & val) >>29 , \ + (BIT_MASK (28 ) & val) >>28 , \ + (BIT_MASK (27 ) & val) >>27 , \ + (BIT_MASK (26 ) & val) >>26 , \ + (BIT_MASK (25 ) & val) >>25 ); \
Just a nit, but later versions of the ARMv8 ARM list bit 24 as "SH", for filtering Secure EL2 events. For the sake of completeness you could add this as well, since we list the EL3 filter bit as well.
arm/pmu.c static void test_event_introspection(void) · line 245
Quoted 9 lines
arm/pmu.c +2
-0+ }while (0 ) static bool is_event_supported(uint32_t n, bool warn) {@@ -207,6 +242,223 @@ static void test_event_introspection(void)report (required_events,"Check required events are implemented" ); } +static inline void mem_access_loop (void *addr,int loop,uint32_t pmcr)
Do we really need the "inline" here? If you rely on this being inlined, we need something stronger, I believe (because inline itself is just a hint).
And can you please add a comment about what this code is supposed to do (because that's much harder to derive in assembly)? And why it needs to be in assembly?
arm/pmu.c static void test_event_introspection(void) · line 250
Quoted 5 lines
arm/pmu.c +5
-0+{ +asmvolatile ( +" msr pmcr_el0, %[pmcr]\n" +" isb\n" + " mov x10, %[loop]\n"
Given that %[loop] is just a register, do we need to use x10 at all?
arm/pmu.c static void test_event_introspection(void) · line 252
Quoted 2 lines
arm/pmu.c +2
-0+"1: sub x10, x10, #1\n" +" mov x8, %[addr]\n"
Are you doing this on purpose inside the loop? And do you actually need to move it to a new register anyway? Why not just use %[addr] directly instead of x8?
arm/pmu.c static void test_event_introspection(void) · line 253
Quoted 1 line
arm/pmu.c +1
-0+" ldr x9, [x8]\n"
I think you could declare some "asm" variable to avoid explicitly specifying a numbered register.
arm/pmu.c static void test_event_introspection(void) · line 255
Quoted 2 lines
arm/pmu.c +2
-0+" cmp x10, #0x0\n" +" b.gt 1b\n"
I think "cbnz" (Compare and Branch on Nonzero) can replace those two instructions.
arm/pmu.c static void test_event_introspection(void) · line 260
Quoted 5 lines
arm/pmu.c +5
-0+" msr pmcr_el0, xzr\n" +" isb\n" + : + : [addr] "r" (addr), [pmcr] "r" (pmcr), [loop] "r" (loop) + : );
Don't you need to tell the compiler that you clobber x8 - x10?
Quoted 36 lines
arm/pmu.c +36
-0+} + + +static void pmu_reset (void ) +{ +/* reset all counters, counting disabled at PMCR level*/ +set_pmcr (pmu.pmcr_ro |PMU_PMCR_LC |PMU_PMCR_C |PMU_PMCR_P ); +/* Disable all counters */ +write_sysreg_s (0xFFFFFFFF ,PMCNTENCLR_EL0 ); +/* clear overflow reg */ +write_sysreg (0xFFFFFFFF , pmovsclr_el0); +/* disable overflow interrupts on all counters */ +write_sysreg (0xFFFFFFFF , pmintenclr_el1); +isb (); +} + +static void test_event_counter_config (void ) +{ +int i; + +if (!pmu.nb_implemented_counters) { +report_skip ("No event counter, skip ..." ); +return ; + } + +pmu_reset (); + +/* +* Test setting through PMESELR/PMXEVTYPER and PMEVTYPERn read, +* select counter 0 +*/ +write_sysreg (1 ,PMSELR_EL0 ); +/* program this counter to count unsupported event */ +write_sysreg (0xEA ,PMXEVTYPER_EL0 ); +write_sysreg (0xdeadbeef ,PMXEVCNTR_EL0 ); + report((read_regn(pmevtyper, 1) & 0xFFF) == 0xEA,
arm/pmu.c static void test_event_introspection(void) · line 306
Quoted 10 lines
arm/pmu.c +10
-0+ "PMESELR/PMXEVTYPER/PMEVTYPERn"); +report ((read_regn (pmevcntr,1 ) ==0xdeadbeef ), +"PMESELR/PMXEVCNTR/PMEVCNTRn" ); + +/* try configure an unsupported event within the range [0x0, 0x3F] */ +for (i =0 ; i <=0x3F ; i++) { +if (!is_event_supported (i, false)) + goto test_unsupported; + } +report_skip ("pmevtyper: all events within [0x0, 0x3F] are supported" );
Doesn't report_skip just *mark* it as SKIP, but then proceeds anyway? So you would need to return here?
And I wonder if it would be nicer to use a break, then check for i being 0x40, instead of using goto.
Quoted 37 lines
arm/pmu.c +37
-0+ +test_unsupported: +/* select counter 0 */ +write_sysreg (0 ,PMSELR_EL0 ); +/* program this counter to count unsupported event */ +write_sysreg (i,PMXEVCNTR_EL0 ); +/* read the counter value */ +read_sysreg (PMXEVCNTR_EL0 ); +report (read_sysreg (PMXEVCNTR_EL0 ) == i, +"read of a counter programmed with unsupported event" ); + +} + +static bool satisfy_prerequisites (uint32_t *events,unsigned int nb_events) +{ +int i; + +if (pmu.nb_implemented_counters < nb_events) { +report_skip ("Skip test as number of counters is too small (%d)" , + pmu.nb_implemented_counters); +return false; + } + +for (i =0 ; i < nb_events; i++) { +if (!is_event_supported (events[i], false)) { +report_skip ("Skip test as event %d is not supported" , + events[i]); +return false; + } + } +return true; +} + +static void test_basic_event_count (void ) +{ +uint32_t implemented_counter_mask, non_implemented_counter_mask; +uint32_t counter_mask;
arm/pmu.c static void test_event_introspection(void) · line 353
Quoted 10 lines
arm/pmu.c +10
-0+uint32_t events[] = { +0x11 ,/* CPU_CYCLES */ +0x8 ,/* INST_RETIRED */ + }; + +if (!satisfy_prerequisites (events,ARRAY_SIZE (events))) +return ; + + implemented_counter_mask = (1 << pmu.nb_implemented_counters) -1 ; + non_implemented_counter_mask = ~((1 <<31 ) | implemented_counter_mask);
I might be paranoid, but I think it's good practise to use "1U << ...", to avoid signed shifts. Or use the BIT() macro.
Quoted 80 lines
arm/pmu.c +80
-0+ counter_mask = implemented_counter_mask | non_implemented_counter_mask; + +write_regn (pmevtyper,0 , events[0 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); + +/* disable all counters */ +write_sysreg_s (0xFFFFFFFF ,PMCNTENCLR_EL0 ); +report (!read_sysreg_s (PMCNTENCLR_EL0 ) && !read_sysreg_s (PMCNTENSET_EL0 ), +"pmcntenclr: disable all counters" ); + +/* +* clear cycle and all event counters and allow counter enablement +* through PMCNTENSET. LC is RES1. +*/ +set_pmcr (pmu.pmcr_ro |PMU_PMCR_LC |PMU_PMCR_C |PMU_PMCR_P ); +isb (); +report (get_pmcr () == (pmu.pmcr_ro |PMU_PMCR_LC ),"pmcr: reset counters" ); + +/* Preset counter #0 to 0xFFFFFFF0 to trigger an overflow interrupt */ +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +report (read_regn (pmevcntr,0 ) ==0xFFFFFFF0 , +"counter #0 preset to 0xFFFFFFF0" ); +report (!read_regn (pmevcntr,1 ),"counter #1 is 0" ); + +/* +* Enable all implemented counters and also attempt to enable +* not supported counters. Counting still is disabled by !PMCR.E +*/ +write_sysreg_s (counter_mask,PMCNTENSET_EL0 ); + +/* check only those implemented are enabled */ +report ((read_sysreg_s (PMCNTENSET_EL0 ) ==read_sysreg_s (PMCNTENCLR_EL0 )) && + (read_sysreg_s (PMCNTENSET_EL0 ) == implemented_counter_mask), +"pmcntenset: enabled implemented_counters" ); + +/* Disable all counters but counters #0 and #1 */ +write_sysreg_s (~0x3 ,PMCNTENCLR_EL0 ); +report ((read_sysreg_s (PMCNTENSET_EL0 ) ==read_sysreg_s (PMCNTENCLR_EL0 )) && + (read_sysreg_s (PMCNTENSET_EL0 ) ==0x3 ), +"pmcntenset: just enabled #0 and #1" ); + +/* clear overflow register */ +write_sysreg (0xFFFFFFFF , pmovsclr_el0); +report (!read_sysreg (pmovsclr_el0),"check overflow reg is 0" ); + +/* disable overflow interrupts on all counters*/ +write_sysreg (0xFFFFFFFF , pmintenclr_el1); +report (!read_sysreg (pmintenclr_el1), +"pmintenclr_el1=0, all interrupts disabled" ); + +/* enable overflow interrupts on all event counters */ +write_sysreg (implemented_counter_mask | non_implemented_counter_mask, + pmintenset_el1); +report (read_sysreg (pmintenset_el1) == implemented_counter_mask, +"overflow interrupts enabled on all implemented counters" ); + +/* Set PMCR.E, execute asm code and unset PMCR.E */ +precise_instrs_loop (20 , pmu.pmcr_ro |PMU_PMCR_E ); + +report_info ("counter #0 is 0x%lx (CPU_CYCLES)" , +read_regn (pmevcntr,0 )); +report_info ("counter #1 is 0x%lx (INST_RETIRED)" , +read_regn (pmevcntr,1 )); + +report_info ("overflow reg = 0x%lx" ,read_sysreg (pmovsclr_el0)); +report (read_sysreg (pmovsclr_el0) &0x1 , +"check overflow happened on #0 only" ); +} + +static void test_mem_access (void ) +{ +void *addr =malloc (PAGE_SIZE ); +uint32_t events[] = { +0x13 ,/* MEM_ACCESS */ +0x13 ,/* MEM_ACCESS */ + }; + +if (!satisfy_prerequisites (events,ARRAY_SIZE (events))) +return ; +
arm/pmu.c static void test_event_introspection(void) · line 443
Quoted 10 lines
arm/pmu.c +10
-0+pmu_reset (); + +write_regn (pmevtyper,0 , events[0 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +isb (); +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("counter #0 is %ld (MEM_ACCESS)" ,read_regn (pmevcntr,0 )); +report_info ("counter #1 is %ld (MEM_ACCESS)" ,read_regn (pmevcntr,1 )); +/* We may not measure exactly 20 mem access. Depends on the platform */
Are you thinking about speculative accesses here? Could you name this explicitly? "Platform" suggests it's something in the SoC or the board, but I believe this is a pure core choice.
Quoted 24 lines
arm/pmu.c +18
-0+report ((read_regn (pmevcntr,0 ) ==read_regn (pmevcntr,1 )) && + (read_regn (pmevcntr,0 ) >=20 ) && !read_sysreg (pmovsclr_el0), +"Ran 20 mem accesses" ); + +pmu_reset (); + +write_regn (pmevcntr,0 ,0xFFFFFFFA ); +write_regn (pmevcntr,1 ,0xFFFFFFF0 ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +isb (); +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report (read_sysreg (pmovsclr_el0) ==0x3 , +"Ran 20 mem accesses with expected overflows on both counters" ); +report_info ("cnt#0 = %ld cnt#1=%ld overflow=0x%lx" , +read_regn (pmevcntr,0 ),read_regn (pmevcntr,1 ), + read_sysreg(pmovsclr_el0)); +} +#endif /* @@ -397,6 +649,15 @@ int main(int argc, char *argv[]) }else if (strcmp (argv[1 ],"event-introspection" ) ==0 ) {report_prefix_push (argv[1 ]);
arm/pmu.c int main(int argc, char *argv[]) · line 660
Quoted 10 lines
arm/pmu.c +9
-0test_event_introspection (); + }else if (strcmp (argv[1 ],"event-counter-config" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_event_counter_config (); + }else if (strcmp (argv[1 ],"basic-event-count" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_basic_event_count (); + }else if (strcmp (argv[1 ],"mem-access" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_mem_access ();
I was wondering if we need all of them as separately selectable tests? Could this be just one "basic_counter" test?
Cheers,
Andre
Quoted 32 lines
arm/pmu.c +0
-0}else {report_abort ("Unknown sub-test '%s'" , argv[1 ]); }arm/unittests.cfg +18
-0@@ -72,6 +72,24 @@ groups = pmu arch = arm64 extra_params = -append 'event-introspection' +[pmu-event-counter-config] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'event-counter-config' + +[pmu-basic-event-count] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'basic-event-count' + +[pmu-mem-access] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'mem-access' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat
Re: [kvm-unit-tests PATCH 05/10] arm: pmu: Basic event counter Tests
Hi Andre,
Quoted 21 lines · Andre Przywara
On Mon, 16 Dec 2019 21:47:52 +0100
Eric Auger <[email protected]> wrote:Hi Eric,
thanks a lot for your work on these elaborate tests! I have some PMU test extensions as well, but they are nowhere as sophisticated as yours!
Just ran this on my ThunderX2 desktop (4.15.0-65-generic #74-Ubuntu kernel, QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.21)), and it reported the following fails:
INFO: pmu: basic-event-count: counter #0 is0x207e(CPU_CYCLES)
INFO: pmu: basic-event-count: counter #1 is0xc89(INST_RETIRED)
INFO: pmu: basic-event-count: overflow reg =0x0
FAIL: pmu: basic-event-count: check overflow happened on #0 only
....
INFO: PMU version: 4
INFO: Implements 6 event counters
INFO: pmu: mem-access: counter #0 is 1297 (MEM_ACCESS)
INFO: pmu: mem-access: counter #1 is 1287 (MEM_ACCESS)
FAIL: pmu: mem-access: Ran 20 mem accesses
FAIL: pmu: mem-access: Ran 20 mem accesses with expected overflows on both counters
INFO: pmu: mem-access: cnt#0 = 1353 cnt#1=1259 overflow=0x0
Quoted 2 lines
Do you know about this? Is this due to kernel bugs? Because Ubuntu cleverly chose an EOL kernel for their stable distro :-P Will try to have a look and repeat on a Juno.
I think this kernel version misses:30d97754b2d1 KVM: arm/arm64: Re-create event when setting counter value
In the tests I am setting the TYPER before presetting the counter #0 value so this may be related.
You may try to set the counter #0 pmevtyper again just after the pmevcntr #0 preset to validate the above.
write_regn(pmevcntr, 0, 0xFFFFFFF0); write_regn(pmevtyper, 0, events[0] | PMEVTYPER_EXCLUDE_EL0);
Besides I am only testing against the master branch.
Quoted 53 lines
Comments inline ....
Quoted 50 lines
Adds the following tests:
- event-counter-config: test event counter configuration
- basic-event-count:
- programs counters #0 and #1 to count 2 required events (resp.CPU_CYCLESandINST_RETIRED). Counter #0 is preset to a value close enough to the 32b
overflow limit so that we check the overflow bit is set after the execution of the asm loop.
- mem-access: countsMEM_ACCESSevent on counters #0 and #1 with and without 32-bit overflow.Signed-off-by Eric Auger <[email protected]>--- arm/pmu.c | 261 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 18 ++++ 2 files changed, 279 insertions(+)arm/pmu.c +9
-0@@ -18,9 +18,15 @@#include "asm/barrier.h" #include "asm/sysreg.h" #include "asm/processor.h" +#include <bitops.h> +#include <asm/gic.h> #define PMU_PMCR_E (1 << 0) +#define PMU_PMCR_P (1 << 1)#define PMU_PMCR_C (1 << 2) +#define PMU_PMCR_D (1 << 3) +#define PMU_PMCR_X (1 << 4) +#define PMU_PMCR_DP (1 << 5)#define PMU_PMCR_LC (1 << 6)#define PMU_PMCR_N_SHIFT 11#define PMU_PMCR_N_MASK 0x1f@@ -104,6 +110,9 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr)/* event counter tests only implemented for aarch64 */ static void test_event_introspection (void ) {} +static void test_event_counter_config (void ) {} +static void test_basic_event_count (void ) {} +static void test_mem_access (void ) {}#elif defined(__aarch64__)#define ID_AA64DFR0_PERFMON_SHIFT 8@@ -145,6 +154,32 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) }
Quoted 4 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 157
Quoted 2 lines
arm/pmu.c +1
-0#define PMCEID1_EL0 sys_reg(11, 3, 9, 12, 7)>> +#define PMCNTENSET_EL0 sys_reg(11, 3, 9, 12, 1) +#define PMCNTENCLR_EL0 sys_reg(11, 3, 9, 12, 2)op0 (the first argument) is only two bits, so it should read "3" instead of "11" here. That's already a bug in the existing
PMCEID1_EL0definition. We get away with it because the macro masks with 3, but it should be still written correctly here. Not sure where the "11" actually comes from.
<systemreg> op0 op1 CRn CRm op2PMCEID1_EL0 11 011 1001 1100 111
binary read as dec :-(
Quoted 18 lines
Quoted 18 lines
arm/pmu.c +17
-0+ +#define PMEVTYPER_EXCLUDE_EL1 (1 << 31) +#define PMEVTYPER_EXCLUDE_EL0 (1 << 30) + +#define regn_el0 (__reg, __n) __reg ## __n ## _el0 +#define write_regn (__reg, __n, __val) \ + write_sysreg((__val), __reg ## __n ## _el0) + +#define read_regn (__reg, __n) \ + read_sysreg(__reg ## __n ## _el0) + +#define print_pmevtyper (__s, __n) do { \ + uint32_t val; \ + val = read_regn(pmevtyper, __n);\ + report_info("%s pmevtyper%d=0x%x, eventcount=0x%x (p=%ld, u=%ld nsk=%ld, nsu=%ld, nsh=%ld m=%ld, mt=%ld)", \ + (__s), (__n), val, val & 0xFFFF, \ + (BIT_MASK(31) & val) >> 31, \
Quoted 8 lines
arm/pmu.c static inline void precise_instrs_loop(int loop, uint32_t pmcr) · line 181
Quoted 6 lines
arm/pmu.c +6
-0+ (BIT_MASK (30 ) & val) >>30 , \ + (BIT_MASK (29 ) & val) >>29 , \ + (BIT_MASK (28 ) & val) >>28 , \ + (BIT_MASK (27 ) & val) >>27 , \ + (BIT_MASK (26 ) & val) >>26 , \ + (BIT_MASK(25) & val) >> 25); \Just a nit, but later versions of the ARMv8 ARM list bit 24 as "SH", for filtering Secure EL2 events. For the sake of completeness you could add this as well, since we list the EL3 filter bit as well.
Sure. Also moved to a new ARM ARM ;-)
Quoted 9 lines
Quoted 9 lines
arm/pmu.c +1
-0+ }while (0 ) static bool is_event_supported(uint32_t n, bool warn) {@@ -207,6 +242,223 @@ static void test_event_introspection(void)report (required_events,"Check required events are implemented" ); }
Quoted 3 lines
arm/pmu.c static void test_event_introspection(void) · line 245
Quoted 1 line
arm/pmu.c +1
-0+static inline void mem_access_loop (void *addr,int loop,uint32_t pmcr)Do we really need the "inline" here? If you rely on this being inlined, we need something stronger, I believe (because inline itself is just a hint).
I got inspired of the existing
static inline void precise_instrs_loop(int loop, uint32_t pmcr)
this is not requested I think. What is important is that the counting gets enabled in the 1st instruction and stopped at the end of the sequence.
Quoted 2 lines
And can you please add a comment about what this code is supposed to do (because that's much harder to derive in assembly)? And why it needs to be in assembly?
sure I will add a similar comment as the one for precise_instrs_loop
Quoted 8 lines
arm/pmu.c static void test_event_introspection(void) · line 250
Quoted 6 lines
arm/pmu.c +5
-0+{ +asmvolatile ( +" msr pmcr_el0, %[pmcr]\n" +" isb\n" + " mov x10, %[loop]\n"Given that %[loop] is just a register, do we need to use x10 at all?
Please forgive me for those awkward asm lines
Quoted 5 lines
arm/pmu.c static void test_event_introspection(void) · line 252
Quoted 3 lines
arm/pmu.c +2
-0+"1: sub x10, x10, #1\n" +" mov x8, %[addr]\n" Are you doing this on purpose inside the loop? And do you actually need to move it to a new register anyway? Why not just use %[addr] directly instead of x8?
done
Quoted 4 lines
arm/pmu.c static void test_event_introspection(void) · line 253
Quoted 2 lines
arm/pmu.c +1
-0+" ldr x9, [x8]\n" I think you could declare some "asm" variable to avoid explicitly specifying a numbered register.
I think I am going to keep a single named reg and clobber it to keep it simple.
Quoted 5 lines
arm/pmu.c static void test_event_introspection(void) · line 255
Quoted 3 lines
arm/pmu.c +2
-0+" cmp x10, #0x0\n" +" b.gt 1b\n" I think "cbnz" (Compare and Branch on Nonzero) can replace those two instructions.
yes it does the job, thanks.
Quoted 8 lines
arm/pmu.c static void test_event_introspection(void) · line 260
Quoted 6 lines
arm/pmu.c +5
-0+" msr pmcr_el0, xzr\n" +" isb\n" + : + : [addr] "r" (addr), [pmcr] "r" (pmcr), [loop] "r" (loop) + : );Don't you need to tell the compiler that you clobber x8 - x10?
Yes I need to. I also need to clobber "memory" I think.
Quoted 41 lines
Quoted 41 lines
arm/pmu.c +40
-0+} + + +static void pmu_reset (void ) +{ +/* reset all counters, counting disabled at PMCR level*/ +set_pmcr (pmu.pmcr_ro |PMU_PMCR_LC |PMU_PMCR_C |PMU_PMCR_P ); +/* Disable all counters */ +write_sysreg_s (0xFFFFFFFF ,PMCNTENCLR_EL0 ); +/* clear overflow reg */ +write_sysreg (0xFFFFFFFF , pmovsclr_el0); +/* disable overflow interrupts on all counters */ +write_sysreg (0xFFFFFFFF , pmintenclr_el1); +isb (); +} + +static void test_event_counter_config (void ) +{ +int i; + +if (!pmu.nb_implemented_counters) { +report_skip ("No event counter, skip ..." ); +return ; + } + +pmu_reset (); + +/* +* Test setting through PMESELR/PMXEVTYPER and PMEVTYPERn read, +* select counter 0 +*/ +write_sysreg (1 ,PMSELR_EL0 ); +/* program this counter to count unsupported event */ +write_sysreg (0xEA ,PMXEVTYPER_EL0 ); +write_sysreg (0xdeadbeef ,PMXEVCNTR_EL0 ); +report ((read_regn (pmevtyper,1 ) &0xFFF ) ==0xEA , +"PMESELR/PMXEVTYPER/PMEVTYPERn" ); +report ((read_regn (pmevcntr,1 ) ==0xdeadbeef ), +"PMESELR/PMXEVCNTR/PMEVCNTRn" ); +
Quoted 8 lines
arm/pmu.c static void test_event_introspection(void) · line 306
Quoted 6 lines
arm/pmu.c +6
-0+/* try configure an unsupported event within the range [0x0, 0x3F] */ +for (i =0 ; i <=0x3F ; i++) { +if (!is_event_supported (i, false)) + goto test_unsupported; + } +report_skip ("pmevtyper: all events within [0x0, 0x3F] are supported" );Doesn't
report_skipjust *mark* it as SKIP, but then proceeds anyway? So you would need to return here?
OK
Quoted 2 lines
And I wonder if it would be nicer to use a break, then check for i being
0x40, instead of using goto.
OK
Quoted 42 lines
Quoted 42 lines
arm/pmu.c +41
-0+ +test_unsupported: +/* select counter 0 */ +write_sysreg (0 ,PMSELR_EL0 ); +/* program this counter to count unsupported event */ +write_sysreg (i,PMXEVCNTR_EL0 ); +/* read the counter value */ +read_sysreg (PMXEVCNTR_EL0 ); +report (read_sysreg (PMXEVCNTR_EL0 ) == i, +"read of a counter programmed with unsupported event" ); + +} + +static bool satisfy_prerequisites (uint32_t *events,unsigned int nb_events) +{ +int i; + +if (pmu.nb_implemented_counters < nb_events) { +report_skip ("Skip test as number of counters is too small (%d)" , + pmu.nb_implemented_counters); +return false; + } + +for (i =0 ; i < nb_events; i++) { +if (!is_event_supported (events[i], false)) { +report_skip ("Skip test as event %d is not supported" , + events[i]); +return false; + } + } +return true; +} + +static void test_basic_event_count (void ) +{ +uint32_t implemented_counter_mask, non_implemented_counter_mask; +uint32_t counter_mask; +uint32_t events[] = { +0x11 ,/* CPU_CYCLES */ +0x8 ,/* INST_RETIRED */ + };
Quoted 8 lines
arm/pmu.c static void test_event_introspection(void) · line 353
Quoted 6 lines
arm/pmu.c +6
-0+ +if (!satisfy_prerequisites (events,ARRAY_SIZE (events))) +return ; + + implemented_counter_mask = (1 << pmu.nb_implemented_counters) -1 ; + non_implemented_counter_mask = ~((1 <<31 ) | implemented_counter_mask);I might be paranoid, but I think it's good practise to use "1U << ...", to avoid signed shifts. Or use the
BIT()macro.
OK let's use the BIT macro.
Quoted 85 lines
Quoted 85 lines
arm/pmu.c +84
-0+ counter_mask = implemented_counter_mask | non_implemented_counter_mask; + +write_regn (pmevtyper,0 , events[0 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); + +/* disable all counters */ +write_sysreg_s (0xFFFFFFFF ,PMCNTENCLR_EL0 ); +report (!read_sysreg_s (PMCNTENCLR_EL0 ) && !read_sysreg_s (PMCNTENSET_EL0 ), +"pmcntenclr: disable all counters" ); + +/* +* clear cycle and all event counters and allow counter enablement +* through PMCNTENSET. LC is RES1. +*/ +set_pmcr (pmu.pmcr_ro |PMU_PMCR_LC |PMU_PMCR_C |PMU_PMCR_P ); +isb (); +report (get_pmcr () == (pmu.pmcr_ro |PMU_PMCR_LC ),"pmcr: reset counters" ); + +/* Preset counter #0 to 0xFFFFFFF0 to trigger an overflow interrupt */ +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +report (read_regn (pmevcntr,0 ) ==0xFFFFFFF0 , +"counter #0 preset to 0xFFFFFFF0" ); +report (!read_regn (pmevcntr,1 ),"counter #1 is 0" ); + +/* +* Enable all implemented counters and also attempt to enable +* not supported counters. Counting still is disabled by !PMCR.E +*/ +write_sysreg_s (counter_mask,PMCNTENSET_EL0 ); + +/* check only those implemented are enabled */ +report ((read_sysreg_s (PMCNTENSET_EL0 ) ==read_sysreg_s (PMCNTENCLR_EL0 )) && + (read_sysreg_s (PMCNTENSET_EL0 ) == implemented_counter_mask), +"pmcntenset: enabled implemented_counters" ); + +/* Disable all counters but counters #0 and #1 */ +write_sysreg_s (~0x3 ,PMCNTENCLR_EL0 ); +report ((read_sysreg_s (PMCNTENSET_EL0 ) ==read_sysreg_s (PMCNTENCLR_EL0 )) && + (read_sysreg_s (PMCNTENSET_EL0 ) ==0x3 ), +"pmcntenset: just enabled #0 and #1" ); + +/* clear overflow register */ +write_sysreg (0xFFFFFFFF , pmovsclr_el0); +report (!read_sysreg (pmovsclr_el0),"check overflow reg is 0" ); + +/* disable overflow interrupts on all counters*/ +write_sysreg (0xFFFFFFFF , pmintenclr_el1); +report (!read_sysreg (pmintenclr_el1), +"pmintenclr_el1=0, all interrupts disabled" ); + +/* enable overflow interrupts on all event counters */ +write_sysreg (implemented_counter_mask | non_implemented_counter_mask, + pmintenset_el1); +report (read_sysreg (pmintenset_el1) == implemented_counter_mask, +"overflow interrupts enabled on all implemented counters" ); + +/* Set PMCR.E, execute asm code and unset PMCR.E */ +precise_instrs_loop (20 , pmu.pmcr_ro |PMU_PMCR_E ); + +report_info ("counter #0 is 0x%lx (CPU_CYCLES)" , +read_regn (pmevcntr,0 )); +report_info ("counter #1 is 0x%lx (INST_RETIRED)" , +read_regn (pmevcntr,1 )); + +report_info ("overflow reg = 0x%lx" ,read_sysreg (pmovsclr_el0)); +report (read_sysreg (pmovsclr_el0) &0x1 , +"check overflow happened on #0 only" ); +} + +static void test_mem_access (void ) +{ +void *addr =malloc (PAGE_SIZE ); +uint32_t events[] = { +0x13 ,/* MEM_ACCESS */ +0x13 ,/* MEM_ACCESS */ + }; + +if (!satisfy_prerequisites (events,ARRAY_SIZE (events))) +return ; + +pmu_reset (); + +write_regn (pmevtyper,0 , events[0 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 );
Quoted 8 lines
arm/pmu.c static void test_event_introspection(void) · line 443
Quoted 6 lines
arm/pmu.c +6
-0+write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +isb (); +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("counter #0 is %ld (MEM_ACCESS)" ,read_regn (pmevcntr,0 )); +report_info ("counter #1 is %ld (MEM_ACCESS)" ,read_regn (pmevcntr,1 )); +/* We may not measure exactly 20 mem access. Depends on the platform */ Are you thinking about speculative accesses here? Could you name this explicitly? "Platform" suggests it's something in the SoC or the board, but I believe this is a pure core choice.
Yes I noticed different results depending on the machine. I am not sufficient expert to say whether it comes speculative differences or from PMU measurement uncertainties.
Quoted 21 lines
Quoted 21 lines
arm/pmu.c +18
-0+report ((read_regn (pmevcntr,0 ) ==read_regn (pmevcntr,1 )) && + (read_regn (pmevcntr,0 ) >=20 ) && !read_sysreg (pmovsclr_el0), +"Ran 20 mem accesses" ); + +pmu_reset (); + +write_regn (pmevcntr,0 ,0xFFFFFFFA ); +write_regn (pmevcntr,1 ,0xFFFFFFF0 ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +isb (); +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report (read_sysreg (pmovsclr_el0) ==0x3 , +"Ran 20 mem accesses with expected overflows on both counters" ); +report_info ("cnt#0 = %ld cnt#1=%ld overflow=0x%lx" , +read_regn (pmevcntr,0 ),read_regn (pmevcntr,1 ), + read_sysreg(pmovsclr_el0)); +} +#endif
Quoted 16 lines
Quoted 4 lines
arm/pmu.c +0
-0/* @@ -397,6 +649,15 @@ int main(int argc, char *argv[]) }else if (strcmp (argv[1 ],"event-introspection" ) ==0 ) {report_prefix_push (argv[1 ]);arm/pmu.c int main(int argc, char *argv[]) · line 660
Quoted 10 lines
arm/pmu.c +9
-0test_event_introspection (); + }else if (strcmp (argv[1 ],"event-counter-config" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_event_counter_config (); + }else if (strcmp (argv[1 ],"basic-event-count" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_basic_event_count (); + }else if (strcmp (argv[1 ],"mem-access" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_mem_access ();I was wondering if we need all of them as separately selectable tests? Could this be just one "
basic_counter" test?
I separated both tests because the former relies on requested events whereas MEM_ACCESS event is not requested.
Thank you for the detailed review!
Eric
Quoted 37 lines
Cheers,
AndreQuoted 32 lines
arm/pmu.c +0
-0}else {report_abort ("Unknown sub-test '%s'" , argv[1 ]); }arm/unittests.cfg +18
-0@@ -72,6 +72,24 @@ groups = pmu arch = arm64 extra_params = -append 'event-introspection' +[pmu-event-counter-config] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'event-counter-config' + +[pmu-basic-event-count] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'basic-event-count' + +[pmu-mem-access] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'mem-access' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat
PATCH 6/10 arm: pmu: Test chained counter
In reply to Eric AugerAdd 2 tests exercising chained counters. The first one uses CPU_CYCLES and the second one uses SW_INCR.
--- arm/pmu.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 12 +++++ 2 files changed, 140 insertions(+)
arm/pmu.c +128 -0
@@ -113,6 +113,8 @@ static void test_event_introspection(void) {}static void test_event_counter_config (void ) {}static void test_basic_event_count (void ) {}static void test_mem_access (void ) {} +static void test_chained_counters (void ) {} +static void test_chained_sw_incr (void ) {}#elif defined(__aarch64__)#define ID_AA64DFR0_PERFMON_SHIFT 8
@@ -459,6 +461,126 @@ static void test_mem_access(void) read_sysreg(pmovsclr_el0)); } +static void test_chained_counters (void ) +{ +uint32_t events[] = {0x11 /* CPU_CYCLES */ ,0x1E /* CHAIN */ }; + +if (!satisfy_prerequisites (events,ARRAY_SIZE (events))) +return ; + +pmu_reset (); + +write_regn (pmevtyper,0 , events[0 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); +/* enable counters #0 and #1 */ +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +/* preset counter #0 at 0xFFFFFFF0 */ +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); + +precise_instrs_loop (22 , pmu.pmcr_ro |PMU_PMCR_E ); + +report (read_regn (pmevcntr,1 ) ==1 ,"CHAIN counter #1 incremented" ); +report (!read_sysreg (pmovsclr_el0),"check no overflow is recorded" ); + +/* test 64b overflow */ + +pmu_reset (); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); + +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +write_regn (pmevcntr,1 ,0x1 ); +precise_instrs_loop (22 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("overflow reg = 0x%lx" ,read_sysreg (pmovsclr_el0)); +report (read_regn (pmevcntr,1 ) ==2 ,"CHAIN counter #1 incremented" ); +report (!read_sysreg (pmovsclr_el0),"check no overflow is recorded" ); + +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +write_regn (pmevcntr,1 ,0xFFFFFFFF ); + +precise_instrs_loop (22 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("overflow reg = 0x%lx" ,read_sysreg (pmovsclr_el0)); +report (!read_regn (pmevcntr,1 ),"CHAIN counter #1 wrapped" ); +report (read_sysreg (pmovsclr_el0) ==0x2 , +"check no overflow is recorded" ); +} + +static void test_chained_sw_incr (void ) +{ +uint32_t events[] = {0x0 /* SW_INCR */ ,0x0 /* SW_INCR */ }; +int i; + +if (!satisfy_prerequisites (events,ARRAY_SIZE (events))) +return ; + +pmu_reset (); + +write_regn (pmevtyper,0 , events[0 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); +/* enable counters #0 and #1 */ +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); + +/* preset counter #0 at 0xFFFFFFF0 */ +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); + +for (i =0 ; i <100 ; i++) +write_sysreg (0x1 , pmswinc_el0); + +report_info ("SW_INCR counter #0 has value %ld" ,read_regn (pmevcntr,0 )); +report (read_regn (pmevcntr,0 ) ==0xFFFFFFF0 , +"PWSYNC does not increment if PMCR.E is unset" ); + +pmu_reset (); + +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +set_pmcr (pmu.pmcr_ro |PMU_PMCR_E ); + +for (i =0 ; i <100 ; i++) +write_sysreg (0x3 , pmswinc_el0); + +report (read_regn (pmevcntr,0 ) ==84 ,"counter #1 after + 100 SW_INCR" ); +report (read_regn (pmevcntr,1 ) ==100 , +"counter #0 after + 100 SW_INCR" ); +report_info ("counter values after 100 SW_INCR #0=%ld #1=%ld" , +read_regn (pmevcntr,0 ),read_regn (pmevcntr,1 )); +report (read_sysreg (pmovsclr_el0) ==0x1 , +"overflow reg after 100 SW_INCR" ); + +/* 64b SW_INCR */ +pmu_reset (); + + events[1 ] =0x1E /* CHAIN */ ; +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +set_pmcr (pmu.pmcr_ro |PMU_PMCR_E ); +for (i =0 ; i <100 ; i++) +write_sysreg (0x3 , pmswinc_el0); + +report (!read_sysreg (pmovsclr_el0) && (read_regn (pmevcntr,1 ) ==1 ), +"overflow reg after 100 SW_INCR/CHAIN" ); +report_info ("overflow=0x%lx, #0=%ld #1=%ld" ,read_sysreg (pmovsclr_el0), +read_regn (pmevcntr,0 ),read_regn (pmevcntr,1 )); + +/* 64b SW_INCR and overflow on CHAIN counter*/ +pmu_reset (); + +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +write_regn (pmevcntr,1 ,0xFFFFFFFF ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +set_pmcr (pmu.pmcr_ro |PMU_PMCR_E ); +for (i =0 ; i <100 ; i++) +write_sysreg (0x3 , pmswinc_el0); + +report ((read_sysreg (pmovsclr_el0) ==0x2 ) && + (read_regn (pmevcntr,1 ) ==0 ) && + (read_regn (pmevcntr,0 ) ==84 ), +"overflow reg after 100 SW_INCR/CHAIN" ); +report_info ("overflow=0x%lx, #0=%ld #1=%ld" ,read_sysreg (pmovsclr_el0), +read_regn (pmevcntr,0 ),read_regn (pmevcntr,1 )); +} +#endif /*
@@ -658,6 +780,12 @@ int main(int argc, char *argv[]) }else if (strcmp (argv[1 ],"mem-access" ) ==0 ) {report_prefix_push (argv[1 ]);test_mem_access (); + }else if (strcmp (argv[1 ],"chained-counters" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_chained_counters (); + }else if (strcmp (argv[1 ],"chained-sw-incr" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_chained_sw_incr (); }else {report_abort ("Unknown sub-test '%s'" , argv[1 ]); }
arm/unittests.cfg +12 -0
@@ -90,6 +90,18 @@ groups = pmu arch = arm64 extra_params = -append 'mem-access' +[pmu-chained-counters] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'chained-counters' + +[pmu-chained-sw-incr] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'chained-sw-incr' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat
Signature · 1 line
2.20.1
PATCH 7/10 arm: pmu: test 32-bit <-> 64-bit transitions
In reply to Eric AugerTest configurations where we transit from 32b to 64b counters and conversely. Also tests configuration where chain counters are configured but only one counter is enabled.
--- arm/pmu.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 +++ 2 files changed, 141 insertions(+)
arm/pmu.c +135 -0
@@ -115,6 +115,7 @@ static void test_basic_event_count(void) {}static void test_mem_access (void ) {}static void test_chained_counters (void ) {}static void test_chained_sw_incr (void ) {} +static void test_chain_promotion (void ) {}#elif defined(__aarch64__)#define ID_AA64DFR0_PERFMON_SHIFT 8
@@ -581,6 +582,137 @@ static void test_chained_sw_incr(void) read_regn(pmevcntr, 0), read_regn(pmevcntr, 1)); } +static void test_chain_promotion (void ) +{ +uint32_t events[] = {0x13 /* MEM_ACCESS */ ,0x1E /* CHAIN */ }; +void *addr =malloc (PAGE_SIZE ); + +if (!satisfy_prerequisites (events,ARRAY_SIZE (events))) +return ; + +/* Only enable CHAIN counter */ +pmu_reset (); +write_regn (pmevtyper,0 , events[0 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_sysreg_s (0x2 ,PMCNTENSET_EL0 ); +isb (); + +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report (!read_regn (pmevcntr,0 ), +"chain counter not counting if even counter is disabled" ); + +/* Only enable even counter */ +pmu_reset (); +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +write_sysreg_s (0x1 ,PMCNTENSET_EL0 ); +isb (); + +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report (!read_regn (pmevcntr,1 ) && (read_sysreg (pmovsclr_el0) ==0x1 ), +"odd counter did not increment on overflow if disabled" ); +report_info ("MEM_ACCESS counter #0 has value %ld" , +read_regn (pmevcntr,0 )); +report_info ("CHAIN counter #1 has value %ld" , +read_regn (pmevcntr,1 )); +report_info ("overflow counter %ld" ,read_sysreg (pmovsclr_el0)); + +/* start at 0xFFFFFFDC, +20 with CHAIN enabled, +20 with CHAIN disabled */ +pmu_reset (); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +write_regn (pmevcntr,0 ,0xFFFFFFDC ); +isb (); + +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("MEM_ACCESS counter #0 has value 0x%lx" , +read_regn (pmevcntr,0 )); + +/* disable the CHAIN event */ +write_sysreg_s (0x2 ,PMCNTENCLR_EL0 ); +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("MEM_ACCESS counter #0 has value 0x%lx" , +read_regn (pmevcntr,0 )); +report (read_sysreg (pmovsclr_el0) ==0x1 , +"should have triggered an overflow on #0" ); +report (!read_regn (pmevcntr,1 ), +"CHAIN counter #1 shouldn't have incremented" ); + +/* start at 0xFFFFFFDC, +20 with CHAIN disabled, +20 with CHAIN enabled */ + +pmu_reset (); +write_sysreg_s (0x1 ,PMCNTENSET_EL0 ); +write_regn (pmevcntr,0 ,0xFFFFFFDC ); +isb (); +report_info ("counter #0 = 0x%lx, counter #1 = 0x%lx overflow=0x%lx" , +read_regn (pmevcntr,0 ),read_regn (pmevcntr,1 ), +read_sysreg (pmovsclr_el0)); + +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("MEM_ACCESS counter #0 has value 0x%lx" , +read_regn (pmevcntr,0 )); + +/* enable the CHAIN event */ +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +isb (); +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("MEM_ACCESS counter #0 has value 0x%lx" , +read_regn (pmevcntr,0 )); + +report ((read_regn (pmevcntr,1 ) ==1 ) && !read_sysreg (pmovsclr_el0), +"CHAIN counter #1 should have incremented and no overflow expected" ); + +report_info ("CHAIN counter #1 = 0x%lx, overflow=0x%lx" , +read_regn (pmevcntr,1 ),read_sysreg (pmovsclr_el0)); + +/* start as MEM_ACCESS/CPU_CYCLES and move to CHAIN/MEM_ACCESS */ +pmu_reset (); +write_regn (pmevtyper,0 ,0x13 /* MEM_ACCESS */ |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 ,0x11 /* CPU_CYCLES */ |PMEVTYPER_EXCLUDE_EL0 ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +write_regn (pmevcntr,0 ,0xFFFFFFDC ); +isb (); + +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("MEM_ACCESS counter #0 has value 0x%lx" , +read_regn (pmevcntr,0 )); + +/* 0 becomes CHAINED */ +write_sysreg_s (0x0 ,PMCNTENSET_EL0 ); +write_regn (pmevtyper,1 ,0x1E /* CHAIN */ |PMEVTYPER_EXCLUDE_EL0 ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); + +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("MEM_ACCESS counter #0 has value 0x%lx" , +read_regn (pmevcntr,0 )); + +report ((read_regn (pmevcntr,1 ) ==1 ) && !read_sysreg (pmovsclr_el0), +"CHAIN counter #1 should have incremented and no overflow expected" ); + +report_info ("CHAIN counter #1 = 0x%lx, overflow=0x%lx" , +read_regn (pmevcntr,1 ),read_sysreg (pmovsclr_el0)); + +/* start as CHAIN/MEM_ACCESS and move to MEM_ACCESS/CPU_CYCLES */ +pmu_reset (); +write_regn (pmevtyper,0 ,0x13 /* MEM_ACCESS */ |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 ,0x1E /* CHAIN */ |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevcntr,0 ,0xFFFFFFDC ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); + +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report_info ("counter #0=0x%lx, counter #1=0x%lx" , +read_regn (pmevcntr,0 ),read_regn (pmevcntr,1 )); + +write_sysreg_s (0x0 ,PMCNTENSET_EL0 ); +write_regn (pmevtyper,1 ,0x11 /* CPU_CYCLES */ |PMEVTYPER_EXCLUDE_EL0 ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); + +mem_access_loop (addr,20 , pmu.pmcr_ro |PMU_PMCR_E ); +report (read_sysreg (pmovsclr_el0) ==1 , +"overflow is expected on counter 0" ); +report_info ("counter #0=0x%lx, counter #1=0x%lx overflow=0x%lx" , +read_regn (pmevcntr,0 ),read_regn (pmevcntr,1 ), +read_sysreg (pmovsclr_el0)); +} +#endif /*
@@ -786,6 +918,9 @@ int main(int argc, char *argv[]) }else if (strcmp (argv[1 ],"chained-sw-incr" ) ==0 ) {report_prefix_push (argv[1 ]);test_chained_sw_incr (); + }else if (strcmp (argv[1 ],"chain-promotion" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_chain_promotion (); }else {report_abort ("Unknown sub-test '%s'" , argv[1 ]); }
arm/unittests.cfg +6 -0
@@ -102,6 +102,12 @@ groups = pmu arch = arm64 extra_params = -append 'chained-sw-incr' +[pmu-chain-promotion] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'chain-promotion' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat
Signature · 1 line
2.20.1
PATCH 8/10 arm: gic: Provide per-IRQ helper functions
In reply to Eric AugerFrom: Andre Przywara <[email protected]>
A common theme when accessing per-IRQ parameters in the GIC distributor is to set fields of a certain bit width in a range of MMIO registers. Examples are the enabled status (one bit per IRQ), the level/edge configuration (2 bits per IRQ) or the priority (8 bits per IRQ).
Add a generic helper function which is able to mask and set the respective number of bits, given the IRQ number and the MMIO offset. Provide wrappers using this function to easily allow configuring an IRQ.
For now assume that private IRQ numbers always refer to the current CPU. In a GICv2 accessing the "other" private IRQs is not easily doable (the registers are banked per CPU on the same MMIO address), so we impose the same limitation on GICv3, even though those registers are not banked there anymore.
---
initialize reg
--- lib/arm/asm/gic-v3.h | 2 + lib/arm/asm/gic.h | 9 +++++ lib/arm/gic.c | 90 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+)
lib/arm/asm/gic-v3.h +2 -0
@@ -23,6 +23,8 @@#define GICD_CTLR_ENABLE_G1A (1U << 1)#define GICD_CTLR_ENABLE_G1 (1U << 0) +#define GICD_IROUTER 0x6000 +/* Re-Distributor registers, offsets from RD_base */ #define GICR_TYPER 0x0008
lib/arm/asm/gic.h +9 -0
@@ -15,6 +15,7 @@#define GICD_IIDR 0x0008#define GICD_IGROUPR 0x0080#define GICD_ISENABLER 0x0100 +#define GICD_ICENABLER 0x0180#define GICD_ISPENDR 0x0200#define GICD_ICPENDR 0x0280#define GICD_ISACTIVER 0x0300
@@ -73,5 +74,13 @@ extern void gic_write_eoir(u32 irqstat);extern void gic_ipi_send_single (int irq,int cpu);extern void gic_ipi_send_mask (int irq,const cpumask_t *dest); +void gic_set_irq_bit (int irq,int offset); +void gic_enable_irq (int irq); +void gic_disable_irq (int irq); +void gic_set_irq_priority (int irq,u8 prio); +void gic_set_irq_target (int irq,int cpu); +void gic_set_irq_group (int irq,int group); +int gic_get_irq_group (int irq); +#endif /* !__ASSEMBLY__ */ #endif /* _ASMARM_GIC_H_ */
lib/arm/gic.c +90 -0
93 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 9/10 arm/arm64: gic: Introduce setup_irq() helper
In reply to Eric Augeripi_enable() code would be reusable for other interrupts than IPI. Let's rename it setup_irq() and pass an interrupt handler pointer. We also export it to use it in other tests such as the PMU's one.
--- arm/gic.c | 24 +++--------------------- lib/arm/asm/gic.h | 3 +++ lib/arm/gic.c | 11 +++++++++++ 3 files changed, 17 insertions(+), 21 deletions(-)
arm/gic.c +3 -21
@@ -215,20 +215,9 @@ static void ipi_test_smp(void)report_prefix_pop (); } -static void ipi_enable (void ) -{ -gic_enable_defaults (); -#ifdef __arm__ -install_exception_handler (EXCPTN_IRQ , ipi_handler); -#else -install_irq_handler (EL1H_IRQ , ipi_handler); -#endif -local_irq_enable (); -} -static void ipi_send (void ) { -ipi_enable (); +setup_irq (ipi_handler);wait_on_ready ();ipi_test_self ();ipi_test_smp ();
@@ -238,7 +227,7 @@ static void ipi_send(void)static void ipi_recv (void ) { -ipi_enable (); +setup_irq (ipi_handler);cpumask_set_cpu (smp_processor_id (), &ready);while (1 )wfi ();
@@ -295,14 +284,7 @@ static void ipi_clear_active_handler(struct pt_regs *regs __unused)static void run_active_clear_test (void ) {report_prefix_push ("active" ); -gic_enable_defaults (); -#ifdef __arm__ -install_exception_handler (EXCPTN_IRQ , ipi_clear_active_handler); -#else -install_irq_handler (EL1H_IRQ , ipi_clear_active_handler); -#endif -local_irq_enable (); - +setup_irq (ipi_clear_active_handler);ipi_test_self ();report_prefix_pop (); }
lib/arm/asm/gic.h +3 -0
@@ -82,5 +82,8 @@ void gic_set_irq_target(int irq, int cpu);void gic_set_irq_group (int irq,int group);int gic_get_irq_group (int irq); +typedef void (*handler_t)(struct pt_regs *regs __unused); +extern void setup_irq (handler_t handler); +#endif /* !__ASSEMBLY__ */ #endif /* _ASMARM_GIC_H_ */
lib/arm/gic.c +11 -0
@@ -236,3 +236,14 @@ int gic_get_irq_group(int irq) {return gic_masked_irq_bits (irq,GICD_IGROUPR ,1 ,0 ,ACCESS_READ ); } + +void setup_irq (handler_t handler) +{ +gic_enable_defaults (); +#ifdef __arm__ +install_exception_handler (EXCPTN_IRQ , handler); +#else +install_irq_handler (EL1H_IRQ , handler); +#endif +local_irq_enable (); +}
Signature · 1 line
2.20.1
PATCH 10/10 arm: pmu: Test overflow interrupts
In reply to Eric AugerTest overflows for MEM_ACCESS and SW_INCR events. Also tests overflows with 64-bit events.
--- arm/pmu.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++ arm/unittests.cfg | 6 +++ 2 files changed, 140 insertions(+)
arm/pmu.c +134 -0
@@ -45,6 +45,11 @@ struct pmu {uint32_t pmcr_ro; }; +struct pmu_stats { +unsigned long bitmap; +uint32_t interrupts[32 ]; +}; +static struct pmu pmu;#if defined(__arm__)
@@ -116,6 +121,7 @@ static void test_mem_access(void) {}static void test_chained_counters (void ) {}static void test_chained_sw_incr (void ) {}static void test_chain_promotion (void ) {} +static void test_overflow_interrupt (void ) {}#elif defined(__aarch64__)#define ID_AA64DFR0_PERFMON_SHIFT 8
@@ -263,6 +269,43 @@ asm volatile( : ); } +static struct pmu_stats pmu_stats; + +static void irq_handler (struct pt_regs *regs) +{ +uint32_t irqstat, irqnr; + + irqstat =gic_read_iar (); + irqnr =gic_iar_irqnr (irqstat); +gic_write_eoir (irqstat); + +if (irqnr ==23 ) { +unsigned long overflows =read_sysreg (pmovsclr_el0); +int i; + +report_info ("--> PMU overflow interrupt %d (counter bitmask 0x%lx)" , + irqnr, overflows); +for (i =0 ; i <32 ; i++) { +if (test_and_clear_bit (i, &overflows)) { + pmu_stats.interrupts[i]++; + pmu_stats.bitmap |=1 << i; + } + } +write_sysreg (0xFFFFFFFF , pmovsclr_el0); + }else { +report_info ("Unexpected interrupt: %d\n" , irqnr); + } +} + +static void pmu_reset_stats (void ) +{ +int i; + +for (i =0 ; i <32 ; i++) + pmu_stats.interrupts[i] =0 ; + + pmu_stats.bitmap =0 ; +}static void pmu_reset (void ) {
@@ -274,6 +317,7 @@ static void pmu_reset(void)write_sysreg (0xFFFFFFFF , pmovsclr_el0);/* disable overflow interrupts on all counters */ write_sysreg (0xFFFFFFFF , pmintenclr_el1); +pmu_reset_stats ();isb (); }
@@ -713,6 +757,93 @@ static void test_chain_promotion(void) read_sysreg(pmovsclr_el0)); } +static bool expect_interrupts (uint32_t bitmap) +{ +int i; + +if (pmu_stats.bitmap ^ bitmap) +return false; + +for (i =0 ; i <32 ; i++) { +if (test_and_clear_bit (i, &pmu_stats.bitmap)) +if (pmu_stats.interrupts[i] !=1 ) +return false; + } +return true; +} + +static void test_overflow_interrupt (void ) +{ +uint32_t events[] = {0x13 /* MEM_ACCESS */ ,0x00 /* SW_INCR */ }; +void *addr =malloc (PAGE_SIZE ); +int i; + +if (!satisfy_prerequisites (events,ARRAY_SIZE (events))) +return ; + +setup_irq (irq_handler); +gic_enable_irq (23 ); + +pmu_reset (); + +write_regn (pmevtyper,0 , events[0 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_sysreg_s (0x3 ,PMCNTENSET_EL0 ); +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +write_regn (pmevcntr,1 ,0xFFFFFFF0 ); +isb (); + +/* interrupts are disabled */ + +mem_access_loop (addr,200 , pmu.pmcr_ro |PMU_PMCR_E ); +report (expect_interrupts (0 ),"no overflow interrupt received" ); + +set_pmcr (pmu.pmcr_ro |PMU_PMCR_E ); +for (i =0 ; i <100 ; i++) +write_sysreg (0x2 , pmswinc_el0); + +set_pmcr (pmu.pmcr_ro); +report (expect_interrupts (0 ),"no overflow interrupt received" ); + +/* enable interrupts */ + +pmu_reset_stats (); + +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +write_regn (pmevcntr,1 ,0xFFFFFFF0 ); +write_sysreg (0xFFFFFFFF , pmintenset_el1); +isb (); + +mem_access_loop (addr,200 , pmu.pmcr_ro |PMU_PMCR_E ); +for (i =0 ; i <100 ; i++) +write_sysreg (0x3 , pmswinc_el0); + +mem_access_loop (addr,200 , pmu.pmcr_ro); +report_info ("overflow=0x%lx" ,read_sysreg (pmovsclr_el0)); +report (expect_interrupts (0x3 ), +"overflow interrupts expected on #0 and #1" ); + +/* promote to 64-b */ + +pmu_reset_stats (); + + events[1 ] =0x1E /* CHAIN */ ; +write_regn (pmevtyper,1 , events[1 ] |PMEVTYPER_EXCLUDE_EL0 ); +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +isb (); +mem_access_loop (addr,200 , pmu.pmcr_ro |PMU_PMCR_E ); +report (expect_interrupts (0 ), +"no overflow interrupt expected on 32b boundary" ); + +/* overflow on odd counter */ +pmu_reset_stats (); +write_regn (pmevcntr,0 ,0xFFFFFFF0 ); +write_regn (pmevcntr,1 ,0xFFFFFFFF ); +isb (); +mem_access_loop (addr,200 , pmu.pmcr_ro |PMU_PMCR_E ); +report (expect_interrupts (0x2 ), +"expect overflow interrupt on odd counter" ); +}#endif /*
@@ -921,6 +1052,9 @@ int main(int argc, char *argv[]) }else if (strcmp (argv[1 ],"chain-promotion" ) ==0 ) {report_prefix_push (argv[1 ]);test_chain_promotion (); + }else if (strcmp (argv[1 ],"overflow-interrupt" ) ==0 ) { +report_prefix_push (argv[1 ]); +test_overflow_interrupt (); }else {report_abort ("Unknown sub-test '%s'" , argv[1 ]); }
arm/unittests.cfg +6 -0
@@ -108,6 +108,12 @@ groups = pmu arch = arm64 extra_params = -append 'chain-promotion' +[overflow-interrupt] +file = pmu.flat +groups = pmu +arch = arm64 +extra_params = -append 'overflow-interrupt' + # Test PMU support (TCG) with -icount IPC=1 #[pmu-tcg-icount-1] #file = pmu.flat
Signature · 1 line
2.20.1