Skip to content

Commit c85e986

Browse files
committed
KVM: selftests: Add a helper to query if the PMU module param is enabled
Add a helper to probe KVM's "enable_pmu" param, open coding strings in multiple places is just asking for false negatives and/or runtime errors due to typos. Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Tested-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Link: https://lore.kernel.org/r/20240109230250.424295-23-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent b55e7ad commit c85e986

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

tools/testing/selftests/kvm/include/x86_64/processor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,11 @@ static inline uint8_t xsetbv_safe(uint32_t index, uint64_t value)
12171217

12181218
bool kvm_is_tdp_enabled(void);
12191219

1220+
static inline bool kvm_is_pmu_enabled(void)
1221+
{
1222+
return get_kvm_param_bool("enable_pmu");
1223+
}
1224+
12201225
uint64_t *__vm_get_page_table_entry(struct kvm_vm *vm, uint64_t vaddr,
12211226
int *level);
12221227
uint64_t *vm_get_page_table_entry(struct kvm_vm *vm, uint64_t vaddr);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ static void test_intel_counters(void)
545545

546546
int main(int argc, char *argv[])
547547
{
548-
TEST_REQUIRE(get_kvm_param_bool("enable_pmu"));
548+
TEST_REQUIRE(kvm_is_pmu_enabled());
549549

550550
TEST_REQUIRE(host_cpu_is_intel);
551551
TEST_REQUIRE(kvm_cpu_has_p(X86_PROPERTY_PMU_VERSION));

tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ int main(int argc, char *argv[])
867867
struct kvm_vcpu *vcpu, *vcpu2 = NULL;
868868
struct kvm_vm *vm;
869869

870-
TEST_REQUIRE(get_kvm_param_bool("enable_pmu"));
870+
TEST_REQUIRE(kvm_is_pmu_enabled());
871871
TEST_REQUIRE(kvm_has_cap(KVM_CAP_PMU_EVENT_FILTER));
872872
TEST_REQUIRE(kvm_has_cap(KVM_CAP_PMU_EVENT_MASKED_EVENTS));
873873

tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ int main(int argc, char *argv[])
237237
{
238238
union perf_capabilities host_cap;
239239

240-
TEST_REQUIRE(get_kvm_param_bool("enable_pmu"));
240+
TEST_REQUIRE(kvm_is_pmu_enabled());
241241
TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_PDCM));
242242

243243
TEST_REQUIRE(kvm_cpu_has_p(X86_PROPERTY_PMU_VERSION));

0 commit comments

Comments
 (0)