]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: selftests: Sync perf_test_args to guest during VM creation
authorSean Christopherson <seanjc@google.com>
Thu, 11 Nov 2021 00:03:10 +0000 (00:03 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 16 Nov 2021 12:43:27 +0000 (07:43 -0500)
Copy perf_test_args to the guest during VM creation instead of relying on
the caller to do so at their leisure.  Ideally, tests wouldn't even be
able to modify perf_test_args, i.e. they would have no motivation to do
the sync, but enforcing that is arguably a net negative for readability.

No functional change intended.

[Set wr_fract=1 by default and add helper to override it since the new
 access_tracking_perf_test needs to set it dynamically.]

Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
Message-Id: <20211111000310.1435032-13-dmatlack@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/access_tracking_perf_test.c
tools/testing/selftests/kvm/demand_paging_test.c
tools/testing/selftests/kvm/dirty_log_perf_test.c
tools/testing/selftests/kvm/include/perf_test_util.h
tools/testing/selftests/kvm/lib/perf_test_util.c
tools/testing/selftests/kvm/memslot_modification_stress_test.c

index fdef6c9063883d52dceb4c5798e3ff951d238e1e..5364a2ed7c68133cb6d07f5ebdf769954b23d640 100644 (file)
@@ -277,8 +277,7 @@ static void run_iteration(struct kvm_vm *vm, int vcpus, const char *description)
 static void access_memory(struct kvm_vm *vm, int vcpus, enum access_type access,
                          const char *description)
 {
-       perf_test_args.wr_fract = (access == ACCESS_READ) ? INT_MAX : 1;
-       sync_global_to_guest(vm, perf_test_args);
+       perf_test_set_wr_fract(vm, (access == ACCESS_READ) ? INT_MAX : 1);
        iteration_work = ITERATION_ACCESS_MEMORY;
        run_iteration(vm, vcpus, description);
 }
index 0fee44f5e5ae23b7e0ca77e379cb7e3bcffd22bd..26f8fd8a57ec1c694e7018a5a7e866a05b20e103 100644 (file)
@@ -295,8 +295,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
        vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, 1,
                                 p->src_type, p->partition_vcpu_memory_access);
 
-       perf_test_args.wr_fract = 1;
-
        demand_paging_size = get_backing_src_pagesz(p->src_type);
 
        guest_data_prototype = malloc(demand_paging_size);
@@ -345,9 +343,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
                }
        }
 
-       /* Export the shared variables to the guest */
-       sync_global_to_guest(vm, perf_test_args);
-
        pr_info("Finished creating vCPUs and starting uffd threads\n");
 
        clock_gettime(CLOCK_MONOTONIC, &start);
index 62f9cc2a3146a70671b68cdaf8ae45b2a7dfec0d..583b4d95aa98fed51098107b750285e64733cd9b 100644 (file)
@@ -189,7 +189,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
                                 p->slots, p->backing_src,
                                 p->partition_vcpu_memory_access);
 
-       perf_test_args.wr_fract = p->wr_fract;
+       perf_test_set_wr_fract(vm, p->wr_fract);
 
        guest_num_pages = (nr_vcpus * guest_percpu_mem_size) >> vm_get_page_shift(vm);
        guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
@@ -207,8 +207,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
        vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
        TEST_ASSERT(vcpu_threads, "Memory allocation failed");
 
-       sync_global_to_guest(vm, perf_test_args);
-
        /* Start the iterations */
        iteration = 0;
        host_quit = false;
index 91804be1cf53f9182396ad7949b3ee05e84ce4e0..74e3622b3a6e9b9585a0eaa5fffc17ab3fe82da7 100644 (file)
@@ -43,4 +43,6 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
                                   bool partition_vcpu_memory_access);
 void perf_test_destroy_vm(struct kvm_vm *vm);
 
+void perf_test_set_wr_fract(struct kvm_vm *vm, int wr_fract);
+
 #endif /* SELFTEST_KVM_PERF_TEST_UTIL_H */
index 13c8bc22f4e1ff05258b107419457632b911ea90..77f9eb5667c9c4e06596a3b528398bf7fecea768 100644 (file)
@@ -94,6 +94,9 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 
        pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
 
+       /* By default vCPUs will write to memory. */
+       pta->wr_fract = 1;
+
        /*
         * Snapshot the non-huge page size.  This is used by the guest code to
         * access/dirty pages at the logging granularity.
@@ -157,6 +160,9 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 
        ucall_init(vm, NULL);
 
+       /* Export the shared variables to the guest. */
+       sync_global_to_guest(vm, perf_test_args);
+
        return vm;
 }
 
@@ -165,3 +171,9 @@ void perf_test_destroy_vm(struct kvm_vm *vm)
        ucall_uninit(vm);
        kvm_vm_free(vm);
 }
+
+void perf_test_set_wr_fract(struct kvm_vm *vm, int wr_fract)
+{
+       perf_test_args.wr_fract = wr_fract;
+       sync_global_to_guest(vm, perf_test_args);
+}
index 27af0bb8deb7174d59d61641500fdeea9183a6bc..df431d0da1ee9c4b0aefaddd80a5fb733be29ec5 100644 (file)
@@ -108,14 +108,9 @@ static void run_test(enum vm_guest_mode mode, void *arg)
                                 VM_MEM_SRC_ANONYMOUS,
                                 p->partition_vcpu_memory_access);
 
-       perf_test_args.wr_fract = 1;
-
        vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
        TEST_ASSERT(vcpu_threads, "Memory allocation failed");
 
-       /* Export the shared variables to the guest */
-       sync_global_to_guest(vm, perf_test_args);
-
        pr_info("Finished creating vCPUs\n");
 
        for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++)