Skip to content

Commit e327630

Browse files
committed
KVM: selftests: Remove dead code in Intel PMU counters test
Drop the local "nr_arch_events" in the Intel PMU counters test as the test asserts that "nr_arch_events <= NR_INTEL_ARCH_EVENTS", and then sets nr_arch_events to the max of the two. I.e. nr_arch_events is guaranteed to be NR_INTEL_ARCH_EVENTS for the meat of the test, just use NR_INTEL_ARCH_EVENTS directly. No functional change intended. Link: https://lore.kernel.org/r/20250117234204.2600624-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 8752e2b commit e327630

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

tools/testing/selftests/kvm/x86/pmu_counters_test.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ static void test_fixed_counters(uint8_t pmu_version, uint64_t perf_capabilities,
563563

564564
static void test_intel_counters(void)
565565
{
566-
uint8_t nr_arch_events = this_cpu_property(X86_PROPERTY_PMU_EBX_BIT_VECTOR_LENGTH);
567566
uint8_t nr_fixed_counters = kvm_cpu_property(X86_PROPERTY_PMU_NR_FIXED_COUNTERS);
568567
uint8_t nr_gp_counters = kvm_cpu_property(X86_PROPERTY_PMU_NR_GP_COUNTERS);
569568
uint8_t pmu_version = kvm_cpu_property(X86_PROPERTY_PMU_VERSION);
@@ -588,9 +587,10 @@ static void test_intel_counters(void)
588587
* This will (obviously) fail any time hardware adds support for a new
589588
* event, but it's worth paying that price to keep the test fresh.
590589
*/
591-
TEST_ASSERT(nr_arch_events <= NR_INTEL_ARCH_EVENTS,
590+
TEST_ASSERT(this_cpu_property(X86_PROPERTY_PMU_EBX_BIT_VECTOR_LENGTH) <= NR_INTEL_ARCH_EVENTS,
592591
"New architectural event(s) detected; please update this test (length = %u, mask = %x)",
593-
nr_arch_events, this_cpu_property(X86_PROPERTY_PMU_EVENTS_MASK));
592+
this_cpu_property(X86_PROPERTY_PMU_EBX_BIT_VECTOR_LENGTH),
593+
this_cpu_property(X86_PROPERTY_PMU_EVENTS_MASK));
594594

595595
/*
596596
* Iterate over known arch events irrespective of KVM/hardware support
@@ -600,8 +600,7 @@ static void test_intel_counters(void)
600600
* count correctly, even if *enumeration* of the event is unsupported
601601
* by KVM and/or isn't exposed to the guest.
602602
*/
603-
nr_arch_events = max_t(typeof(nr_arch_events), nr_arch_events, NR_INTEL_ARCH_EVENTS);
604-
for (i = 0; i < nr_arch_events; i++) {
603+
for (i = 0; i < NR_INTEL_ARCH_EVENTS; i++) {
605604
if (this_pmu_has(intel_event_to_feature(i).gp_event))
606605
hardware_pmu_arch_events |= BIT(i);
607606
}
@@ -620,8 +619,8 @@ static void test_intel_counters(void)
620619
* vector length.
621620
*/
622621
if (v == pmu_version) {
623-
for (k = 1; k < (BIT(nr_arch_events) - 1); k++)
624-
test_arch_events(v, perf_caps[i], nr_arch_events, k);
622+
for (k = 1; k < (BIT(NR_INTEL_ARCH_EVENTS) - 1); k++)
623+
test_arch_events(v, perf_caps[i], NR_INTEL_ARCH_EVENTS, k);
625624
}
626625
/*
627626
* Test single bits for all PMU version and lengths up
@@ -630,11 +629,11 @@ static void test_intel_counters(void)
630629
* host length). Explicitly test a mask of '0' and all
631630
* ones i.e. all events being available and unavailable.
632631
*/
633-
for (j = 0; j <= nr_arch_events + 1; j++) {
632+
for (j = 0; j <= NR_INTEL_ARCH_EVENTS + 1; j++) {
634633
test_arch_events(v, perf_caps[i], j, 0);
635634
test_arch_events(v, perf_caps[i], j, 0xff);
636635

637-
for (k = 0; k < nr_arch_events; k++)
636+
for (k = 0; k < NR_INTEL_ARCH_EVENTS; k++)
638637
test_arch_events(v, perf_caps[i], j, BIT(k));
639638
}
640639

0 commit comments

Comments
 (0)