All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Matlack <dmatlack@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com>,
	Ben Gardon <bgardon@google.com>,
	Andrew Jones <drjones@redhat.com>,
	Jim Mattson <jmattson@google.com>,
	Yanan Wang <wangyanan55@huawei.com>, Peter Xu <peterx@redhat.com>,
	Aaron Lewis <aaronlewis@google.com>,
	David Matlack <dmatlack@google.com>
Subject: [PATCH v2 12/12] KVM: selftests: Sync perf_test_args to guest during VM creation
Date: Thu, 11 Nov 2021 00:03:10 +0000	[thread overview]
Message-ID: <20211111000310.1435032-13-dmatlack@google.com> (raw)
In-Reply-To: <20211111000310.1435032-1-dmatlack@google.com>

From: Sean Christopherson <seanjc@google.com>

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.

Signed-off-by: Sean Christopherson <seanjc@google.com>
[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: David Matlack <dmatlack@google.com>
---
 .../selftests/kvm/access_tracking_perf_test.c        |  3 +--
 tools/testing/selftests/kvm/demand_paging_test.c     |  5 -----
 tools/testing/selftests/kvm/dirty_log_perf_test.c    |  4 +---
 tools/testing/selftests/kvm/include/perf_test_util.h |  2 ++
 tools/testing/selftests/kvm/lib/perf_test_util.c     | 12 ++++++++++++
 .../selftests/kvm/memslot_modification_stress_test.c |  5 -----
 6 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c
index fdef6c906388..5364a2ed7c68 100644
--- a/tools/testing/selftests/kvm/access_tracking_perf_test.c
+++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c
@@ -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);
 }
diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index 0fee44f5e5ae..26f8fd8a57ec 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -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);
diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c
index 62f9cc2a3146..583b4d95aa98 100644
--- a/tools/testing/selftests/kvm/dirty_log_perf_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c
@@ -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;
diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h
index 91804be1cf53..74e3622b3a6e 100644
--- a/tools/testing/selftests/kvm/include/perf_test_util.h
+++ b/tools/testing/selftests/kvm/include/perf_test_util.h
@@ -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 */
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index 13c8bc22f4e1..77f9eb5667c9 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -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);
+}
diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
index 27af0bb8deb7..df431d0da1ee 100644
--- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c
+++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
@@ -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++)
-- 
2.34.0.rc1.387.gb447b232ab-goog


  parent reply	other threads:[~2021-11-11  0:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
2021-11-11  0:02 ` [PATCH v2 01/12] KVM: selftests: Explicitly state indicies for vm_guest_mode_params array David Matlack
2021-11-11  0:03 ` [PATCH v2 02/12] KVM: selftests: Expose align() helpers to tests David Matlack
2021-11-11 17:43   ` Ben Gardon
2021-11-11  0:03 ` [PATCH v2 03/12] KVM: selftests: Assert mmap HVA is aligned when using HugeTLB David Matlack
2021-11-11  0:03 ` [PATCH v2 04/12] KVM: selftests: Require GPA to be aligned when backed by hugepages David Matlack
2021-11-11 17:49   ` Ben Gardon
2021-11-11 19:21     ` Sean Christopherson
2021-11-11  0:03 ` [PATCH v2 05/12] KVM: selftests: Use shorthand local var to access struct perf_tests_args David Matlack
2021-11-11  0:03 ` [PATCH v2 06/12] KVM: selftests: Capture per-vCPU GPA in perf_test_vcpu_args David Matlack
2021-11-11  0:03 ` [PATCH v2 07/12] KVM: selftests: Use perf util's per-vCPU GPA/pages in demand paging test David Matlack
2021-11-11  0:03 ` [PATCH v2 08/12] KVM: selftests: Move per-VM GPA into perf_test_args David Matlack
2021-11-11  0:03 ` [PATCH v2 09/12] KVM: selftests: Remove perf_test_args.host_page_size David Matlack
2021-11-11  0:03 ` [PATCH v2 10/12] KVM: selftests: Create VM with adjusted number of guest pages for perf tests David Matlack
2021-11-11  0:03 ` [PATCH v2 11/12] KVM: selftests: Fill per-vCPU struct during "perf_test" VM creation David Matlack
2021-11-11 17:53   ` Ben Gardon
2021-11-11  0:03 ` David Matlack [this message]
2021-11-11 17:55   ` [PATCH v2 12/12] KVM: selftests: Sync perf_test_args to guest during " Ben Gardon
2021-11-16 11:12 ` [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211111000310.1435032-13-dmatlack@google.com \
    --to=dmatlack@google.com \
    --cc=aaronlewis@google.com \
    --cc=bgardon@google.com \
    --cc=drjones@redhat.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=seanjc@google.com \
    --cc=wangyanan55@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.