[PATCH v3 04/21] KVM: selftests: Use KVM's pRNG to randomize L1's TSC ratio in TSC scaling test
From: Sean Christopherson
Date: Wed Sep 30 2026 - 13:53:54 EST
Use KVM's pRNG to randomize L1's TSC ratio in the nested TSC scaling test,
so that reproducing a failure with a specific seed is slightly easier.
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c b/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c
index c763f4cf0f62..65de46f80a3e 100644
--- a/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c
+++ b/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c
@@ -166,8 +166,7 @@ int main(int argc, char *argv[])
* referenced by both main() and l1_guest_code() and using a global
* variable does not work.
*/
- srand(time(NULL));
- l1_scale_factor = (rand() % 9) + 2;
+ l1_scale_factor = (kvm_random_u32(&kvm_rng) % 9) + 2;
printf("L1's scale down factor is: %"PRIu64"\n", l1_scale_factor);
printf("L2's scale up factor is: %llu\n", L2_SCALE_FACTOR);
--
2.56.0.rc1.315.gc6ed9934b7-goog