Skip to content

Commit 9ec1eb1

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: selftests: Have perf_test_util signal when to stop vCPUs
Signal that a test run is complete through perf_test_args instead of having tests open code a similar solution. Ensure that the field resets to false at the beginning of a test run as the structure is reused between test runs, eliminating a couple of bugs: access_tracking_perf_test hangs indefinitely on a subsequent test run, as 'done' remains true. The bug doesn't amount to much right now, as x86 supports a single guest mode. However, this is a precondition of enabling the test for other architectures with >1 guest mode, like arm64. memslot_modification_stress_test has the exact opposite problem, where subsequent test runs complete immediately as 'run_vcpus' remains false. Co-developed-by: Sean Christopherson <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> [oliver: added commit message, preserve spin_wait_for_next_iteration()] Signed-off-by: Oliver Upton <[email protected]> Reviewed-by: Gavin Shan <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 30a0b95 commit 9ec1eb1

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

tools/testing/selftests/kvm/access_tracking_perf_test.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ static enum {
5858
ITERATION_MARK_IDLE,
5959
} iteration_work;
6060

61-
/* Set to true when vCPU threads should exit. */
62-
static bool done;
63-
6461
/* The iteration that was last completed by each vCPU. */
6562
static int vcpu_last_completed_iteration[KVM_MAX_VCPUS];
6663

@@ -211,7 +208,7 @@ static bool spin_wait_for_next_iteration(int *current_iteration)
211208
int last_iteration = *current_iteration;
212209

213210
do {
214-
if (READ_ONCE(done))
211+
if (READ_ONCE(perf_test_args.stop_vcpus))
215212
return false;
216213

217214
*current_iteration = READ_ONCE(iteration);
@@ -321,9 +318,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
321318
mark_memory_idle(vm, nr_vcpus);
322319
access_memory(vm, nr_vcpus, ACCESS_READ, "Reading from idle memory");
323320

324-
/* Set done to signal the vCPU threads to exit */
325-
done = true;
326-
327321
perf_test_join_vcpu_threads(nr_vcpus);
328322
perf_test_destroy_vm(vm);
329323
}

tools/testing/selftests/kvm/include/perf_test_util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ struct perf_test_args {
4040
/* Run vCPUs in L2 instead of L1, if the architecture supports it. */
4141
bool nested;
4242

43+
/* Test is done, stop running vCPUs. */
44+
bool stop_vcpus;
45+
4346
struct perf_test_vcpu_args vcpu_args[KVM_MAX_VCPUS];
4447
};
4548

tools/testing/selftests/kvm/lib/perf_test_util.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ void perf_test_start_vcpu_threads(int nr_vcpus,
267267

268268
vcpu_thread_fn = vcpu_fn;
269269
WRITE_ONCE(all_vcpu_threads_running, false);
270+
WRITE_ONCE(perf_test_args.stop_vcpus, false);
270271

271272
for (i = 0; i < nr_vcpus; i++) {
272273
struct vcpu_thread *vcpu = &vcpu_threads[i];
@@ -289,6 +290,8 @@ void perf_test_join_vcpu_threads(int nr_vcpus)
289290
{
290291
int i;
291292

293+
WRITE_ONCE(perf_test_args.stop_vcpus, true);
294+
292295
for (i = 0; i < nr_vcpus; i++)
293296
pthread_join(vcpu_threads[i].thread, NULL);
294297
}

tools/testing/selftests/kvm/memslot_modification_stress_test.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
static int nr_vcpus = 1;
3535
static uint64_t guest_percpu_mem_size = DEFAULT_PER_VCPU_MEM_SIZE;
3636

37-
static bool run_vcpus = true;
38-
3937
static void vcpu_worker(struct perf_test_vcpu_args *vcpu_args)
4038
{
4139
struct kvm_vcpu *vcpu = vcpu_args->vcpu;
@@ -45,7 +43,7 @@ static void vcpu_worker(struct perf_test_vcpu_args *vcpu_args)
4543
run = vcpu->run;
4644

4745
/* Let the guest access its memory until a stop signal is received */
48-
while (READ_ONCE(run_vcpus)) {
46+
while (!READ_ONCE(perf_test_args.stop_vcpus)) {
4947
ret = _vcpu_run(vcpu);
5048
TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret);
5149

@@ -110,8 +108,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
110108
add_remove_memslot(vm, p->memslot_modification_delay,
111109
p->nr_memslot_modifications);
112110

113-
run_vcpus = false;
114-
115111
perf_test_join_vcpu_threads(nr_vcpus);
116112
pr_info("All vCPU threads joined\n");
117113

0 commit comments

Comments
 (0)