summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/kvm/lib
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2024-03-14 19:54:55 +0100
committerSean Christopherson <seanjc@google.com>2024-04-29 21:50:42 +0200
commit73369acd9fbdf6cbf3029cace886abcc626f46ad (patch)
treebf1452726af1fc9e564e86c6e9ec1887b6da4296 /tools/testing/selftests/kvm/lib
parentKVM: selftests: Provide a global pseudo-RNG instance for all tests (diff)
downloadlinux-73369acd9fbdf6cbf3029cace886abcc626f46ad.tar.xz
linux-73369acd9fbdf6cbf3029cace886abcc626f46ad.zip
KVM: selftests: Provide an API for getting a random bool from an RNG
Move memstress' random bool logic into common code to avoid reinventing the wheel for basic yes/no decisions. Provide an outer wrapper to handle the basic/common case of just wanting a 50/50 chance of something happening. Link: https://lore.kernel.org/r/20240314185459.2439072-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/testing/selftests/kvm/lib')
-rw-r--r--tools/testing/selftests/kvm/lib/memstress.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/testing/selftests/kvm/lib/memstress.c b/tools/testing/selftests/kvm/lib/memstress.c
index 3b7fe1778d7b..aa0a01988150 100644
--- a/tools/testing/selftests/kvm/lib/memstress.c
+++ b/tools/testing/selftests/kvm/lib/memstress.c
@@ -74,7 +74,7 @@ void memstress_guest_code(uint32_t vcpu_idx)
addr = gva + (page * args->guest_page_size);
- if (guest_random_u32(&rand_state) % 100 < args->write_percent)
+ if (__guest_random_bool(&rand_state, args->write_percent))
*(uint64_t *)addr = 0x0123456789ABCDEF;
else
READ_ONCE(*(uint64_t *)addr);