aboutsummaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm/lib/perf_test_util.c
diff options
context:
space:
mode:
authorColton Lewis <coltonlewis@google.com>2022-11-07 18:22:08 +0000
committerSean Christopherson <seanjc@google.com>2022-11-16 10:57:22 -0800
commitc967a4752ac66cc0ef8c0b1f4914151ca8758709 (patch)
tree623ba8abeeee88b27b7484ff7ab7fd349df4e948 /tools/testing/selftests/kvm/lib/perf_test_util.c
parent6864c6442f4dfa02c7cf48199cf3ea6bb1fe74ed (diff)
downloadlinux-c967a4752ac66cc0ef8c0b1f4914151ca8758709.tar.gz
linux-c967a4752ac66cc0ef8c0b1f4914151ca8758709.tar.bz2
linux-c967a4752ac66cc0ef8c0b1f4914151ca8758709.zip
KVM: selftests: randomize page access order
Create the ability to randomize page access order with the -a argument. This includes the possibility that the same pages may be hit multiple times during an iteration or not at all. Population has random access as false to ensure all pages will be touched by population and avoid page faults in late dirty memory that would pollute the test results. Signed-off-by: Colton Lewis <coltonlewis@google.com> Reviewed-by: David Matlack <dmatlack@google.com> Link: https://lore.kernel.org/r/20221107182208.479157-5-coltonlewis@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/testing/selftests/kvm/lib/perf_test_util.c')
-rw-r--r--tools/testing/selftests/kvm/lib/perf_test_util.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index 15000f71cdee..3a9a3ea01a97 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -51,6 +51,8 @@ void perf_test_guest_code(uint32_t vcpu_idx)
struct guest_random_state rand_state;
uint64_t gva;
uint64_t pages;
+ uint64_t addr;
+ uint64_t page;
int i;
rand_state = new_guest_random_state(pta->random_seed + vcpu_idx);
@@ -63,7 +65,12 @@ void perf_test_guest_code(uint32_t vcpu_idx)
while (true) {
for (i = 0; i < pages; i++) {
- uint64_t addr = gva + (i * pta->guest_page_size);
+ if (pta->random_access)
+ page = guest_random_u32(&rand_state) % pages;
+ else
+ page = i;
+
+ addr = gva + (page * pta->guest_page_size);
if (guest_random_u32(&rand_state) % 100 < pta->write_percent)
*(uint64_t *)addr = 0x0123456789ABCDEF;
@@ -240,6 +247,12 @@ void perf_test_set_random_seed(struct kvm_vm *vm, uint32_t random_seed)
sync_global_to_guest(vm, perf_test_args.random_seed);
}
+void perf_test_set_random_access(struct kvm_vm *vm, bool random_access)
+{
+ perf_test_args.random_access = random_access;
+ sync_global_to_guest(vm, perf_test_args.random_access);
+}
+
uint64_t __weak perf_test_nested_pages(int nr_vcpus)
{
return 0;