x86/pmu: Verify all available GP counters in check_counters_many()
PATCH 1/1 x86/pmu: Verify all available GP counters in check_counters_many()
The intent of check_counters_many() is to verify all available counters can count correctly at the same time. So an alternative event should be picked to verify the avaialbe GP counter instead of skiping the counter if the initial event is not available.
---
Please notice this patch is based on Sean's "x86: Add CPUID properties,
clean up related code" v2 patchset (https://lore.kernel.org/all/[email protected]/).
x86/pmu.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
x86/pmu.c +19 -3
@@ -457,18 +457,34 @@ static void check_fixed_counters(void) } } +static struct pmu_event *get_one_event (int idx) +{ +int i; + +if (pmu_arch_event_is_available (idx)) +return &gp_events[idx % gp_events_size]; + +for (i =0 ; i < gp_events_size; i++) { +if (pmu_arch_event_is_available (i)) +return &gp_events[i]; + } + +return NULL ; +} +static void check_counters_many (void ) { +struct pmu_event *evt;pmu_counter_t cnt[48 ];int i, n;for (i =0 , n =0 ; n < pmu.nr_gp_counters; i++) { -if (!pmu_arch_event_is_available (i)) + evt =get_one_event (i); +if (!evt)continue ; cnt[n].ctr =MSR_GP_COUNTERx (n); - cnt[n].config =EVNTSEL_OS |EVNTSEL_USR | - gp_events[i % gp_events_size].unit_sel; + cnt[n].config =EVNTSEL_OS |EVNTSEL_USR | evt->unit_sel; n++; }for (i =0 ; i < fixed_counters_num; i++) {
Signature · 1 line
2.43.0
Quoted 5 lines · Dapeng Mi
The intent of
check_counters_many()is to verify all available counters can count correctly at the same time. So an alternative event should be picked to verify the avaialbe GP counter instead of skiping the counter if the initial event is not available.
Quoted 8 lines
Signed-off-by Dapeng Mi <[email protected]>---
Please notice this patch is based on Sean's "x86: Add CPUID properties,
clean up related code" v2 patchset (https://lore.kernel.org/all/[email protected]/).x86/pmu.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
For AMD processors
Quoted 42 lines
x86/pmu.c +19
-3@@ -457,18 +457,34 @@ static void check_fixed_counters(void) } } +static struct pmu_event *get_one_event (int idx) +{ +int i; + +if (pmu_arch_event_is_available (idx)) +return &gp_events[idx % gp_events_size]; + +for (i =0 ; i < gp_events_size; i++) { +if (pmu_arch_event_is_available (i)) +return &gp_events[i]; + } + +return NULL ; +} +static void check_counters_many (void ) { +struct pmu_event *evt;pmu_counter_t cnt[48 ];int i, n;for (i =0 , n =0 ; n < pmu.nr_gp_counters; i++) { -if (!pmu_arch_event_is_available (i)) + evt =get_one_event (i); +if (!evt)continue ; cnt[n].ctr =MSR_GP_COUNTERx (n); - cnt[n].config =EVNTSEL_OS |EVNTSEL_USR | - gp_events[i % gp_events_size].unit_sel; + cnt[n].config =EVNTSEL_OS |EVNTSEL_USR | evt->unit_sel; n++; }for (i =0 ; i < fixed_counters_num; i++) {
Quoted 4 lines · Dapeng Mi
The intent of
check_counters_many()is to verify all available counters can count correctly at the same time. So an alternative event should be picked to verify the avaialbe GP counter instead of skiping the counter if the initial event is not available.
Applied to kvm-x86 next, thanks!
[1/1] x86/pmu: Verify all available GP counters in check_counters_many()
https://github.com/kvm-x86/kvm-unit-tests/commit/525bdb5d65d5