Skip to content

Commit 09951bf

Browse files
vittyvksean-jc
authored andcommitted
KVM: selftests: Run clocksource dependent tests with hyperv_clocksource_tsc_page too
KVM's 'gtod_is_based_on_tsc()' recognizes two clocksources: 'tsc' and 'hyperv_clocksource_tsc_page' and enables kvmclock in 'masterclock' mode when either is in use. Transform 'sys_clocksource_is_tsc()' into 'sys_clocksource_is_based_on_tsc()' to support the later. This affects two tests: kvm_clock_test and vmx_nested_tsc_scaling_test, both seem to work well when system clocksource is 'hyperv_clocksource_tsc_page'. Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Link: https://lore.kernel.org/r/20240109141121.1619463-4-vkuznets@redhat.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 410cb01 commit 09951bf

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,6 @@ void virt_map_level(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr,
12711271
#define PFERR_GUEST_PAGE_MASK BIT_ULL(PFERR_GUEST_PAGE_BIT)
12721272
#define PFERR_IMPLICIT_ACCESS BIT_ULL(PFERR_IMPLICIT_ACCESS_BIT)
12731273

1274-
bool sys_clocksource_is_tsc(void);
1274+
bool sys_clocksource_is_based_on_tsc(void);
12751275

12761276
#endif /* SELFTEST_KVM_PROCESSOR_H */

tools/testing/selftests/kvm/lib/x86_64/processor.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,10 +1300,11 @@ void kvm_selftest_arch_init(void)
13001300
host_cpu_is_amd = this_cpu_is_amd();
13011301
}
13021302

1303-
bool sys_clocksource_is_tsc(void)
1303+
bool sys_clocksource_is_based_on_tsc(void)
13041304
{
13051305
char *clk_name = sys_get_cur_clocksource();
1306-
bool ret = !strcmp(clk_name, "tsc\n");
1306+
bool ret = !strcmp(clk_name, "tsc\n") ||
1307+
!strcmp(clk_name, "hyperv_clocksource_tsc_page\n");
13071308

13081309
free(clk_name);
13091310

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ int main(void)
143143
flags = kvm_check_cap(KVM_CAP_ADJUST_CLOCK);
144144
TEST_REQUIRE(flags & KVM_CLOCK_REALTIME);
145145

146-
TEST_REQUIRE(sys_clocksource_is_tsc());
146+
TEST_REQUIRE(sys_clocksource_is_based_on_tsc());
147147

148148
vm = vm_create_with_one_vcpu(&vcpu, guest_main);
149149

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
131131

132132
TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
133133
TEST_REQUIRE(kvm_has_cap(KVM_CAP_TSC_CONTROL));
134-
TEST_REQUIRE(sys_clocksource_is_tsc());
134+
TEST_REQUIRE(sys_clocksource_is_based_on_tsc());
135135

136136
/*
137137
* We set L1's scale factor to be a random number from 2 to 10.

0 commit comments

Comments
 (0)