Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: selftests: use unified time type for comparison

With test case kvm_page_table_test, start time is acquired with
time type CLOCK_MONOTONIC_RAW, however end time in timespec_elapsed()
is acquired with time type CLOCK_MONOTONIC. This can cause inaccurate
elapsed time calculation due to mixing timebases, e.g. LoongArch in
particular will see weirdness.

Modify kvm_page_table_test to use unified time type CLOCK_MONOTONIC for
start time.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Link: https://lore.kernel.org/r/20230731022405.854884-1-maobibo@loongson.cn
[sean: massage changelog]
Signed-off-by: Sean Christopherson <seanjc@google.com>

authored by

Bibo Mao and committed by
Sean Christopherson
b859b018 0de704d2

+4 -4
+4 -4
tools/testing/selftests/kvm/kvm_page_table_test.c
··· 200 200 if (READ_ONCE(host_quit)) 201 201 return NULL; 202 202 203 - clock_gettime(CLOCK_MONOTONIC_RAW, &start); 203 + clock_gettime(CLOCK_MONOTONIC, &start); 204 204 ret = _vcpu_run(vcpu); 205 205 ts_diff = timespec_elapsed(start); 206 206 ··· 367 367 /* Test the stage of KVM creating mappings */ 368 368 *current_stage = KVM_CREATE_MAPPINGS; 369 369 370 - clock_gettime(CLOCK_MONOTONIC_RAW, &start); 370 + clock_gettime(CLOCK_MONOTONIC, &start); 371 371 vcpus_complete_new_stage(*current_stage); 372 372 ts_diff = timespec_elapsed(start); 373 373 ··· 380 380 381 381 *current_stage = KVM_UPDATE_MAPPINGS; 382 382 383 - clock_gettime(CLOCK_MONOTONIC_RAW, &start); 383 + clock_gettime(CLOCK_MONOTONIC, &start); 384 384 vcpus_complete_new_stage(*current_stage); 385 385 ts_diff = timespec_elapsed(start); 386 386 ··· 392 392 393 393 *current_stage = KVM_ADJUST_MAPPINGS; 394 394 395 - clock_gettime(CLOCK_MONOTONIC_RAW, &start); 395 + clock_gettime(CLOCK_MONOTONIC, &start); 396 396 vcpus_complete_new_stage(*current_stage); 397 397 ts_diff = timespec_elapsed(start); 398 398