x86/pmu: Explicitly zero PERF_GLOBAL_CTRL at start of PMU test
Sean Christopherson
reviewerPATCH 1/1 x86/pmu: Explicitly zero PERF_GLOBAL_CTRL at start of PMU test
Explicitly zero PERF_GLOBAL_CTRL at the start of the PMU test as the architectural RESET value of PERF_GLOBAL_CTRL is to set all enable bits for general purpose counters (for backwards compatibility with software that was written for v1 PMUs). Leaving PERF_GLOBAL_CTRL set can result in false failures due to counters unexpectedly being left active.
--- x86/pmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
x86/pmu.c +3 -3
@@ -905,9 +905,6 @@ static void set_ref_cycle_expectations(void)if (!pmu.nr_gp_counters || !pmu_gp_counter_is_available (2 ))return ; -if (this_cpu_has_perf_global_ctrl ()) -wrmsr (pmu.msr_global_ctl,0 ); - t0 =fenced_rdtsc ();start_event (&cnt); t1 =fenced_rdtsc ();
@@ -956,6 +953,9 @@ int main(int ac, char **av)handle_irq (PMI_VECTOR , cnt_overflow); buf =malloc (N *64 ); +if (this_cpu_has_perf_global_ctrl ()) +wrmsr (pmu.msr_global_ctl,0 ); +check_invalid_rdpmc_gp ();if (pmu.is_intel) {
base-commit: 72d110d8286baf1b355301cc8c8bdb42be2663fb
Signature · 1 line
2.49.0.1204.g71687c7c1d-goog
Quoted 36 lines · Sean Christopherson
Explicitly zero
PERF_GLOBAL_CTRLat the start of the PMU test as the architectural RESET value ofPERF_GLOBAL_CTRLis to set all enable bits for general purpose counters (for backwards compatibility with software that was written for v1 PMUs). LeavingPERF_GLOBAL_CTRLset can result in false failures due to counters unexpectedly being left active.Signed-off-by Sean Christopherson <[email protected]>--- x86/pmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)x86/pmu.c +3
-3@@ -905,9 +905,6 @@ static void set_ref_cycle_expectations(void)if (!pmu.nr_gp_counters || !pmu_gp_counter_is_available (2 ))return ; -if (this_cpu_has_perf_global_ctrl ()) -wrmsr (pmu.msr_global_ctl,0 ); - t0 =fenced_rdtsc ();start_event (&cnt); t1 =fenced_rdtsc ();@@ -956,6 +953,9 @@ int main(int ac, char **av)handle_irq (PMI_VECTOR , cnt_overflow); buf =malloc (N *64 ); +if (this_cpu_has_perf_global_ctrl ()) +wrmsr (pmu.msr_global_ctl,0 ); +check_invalid_rdpmc_gp ();if (pmu.is_intel) {
Quoted 1 line
base-commit:
72d110d8286baf1b355301cc8c8bdb42be2663fb
Quoted 8 lines · Sean Christopherson
Explicitly zero
PERF_GLOBAL_CTRLat the start of the PMU test as the architectural RESET value ofPERF_GLOBAL_CTRLis to set all enable bits for general purpose counters (for backwards compatibility with software that was written for v1 PMUs). LeavingPERF_GLOBAL_CTRLset can result in false failures due to counters unexpectedly being left active.[...]
Applied to kvm-x86 next, thanks!
[1/1] x86/pmu: Explicitly zero PERF_GLOBAL_CTRL at start of PMU test
https://github.com/kvm-x86/kvm-unit-tests/commit/0bd5a078d1d1