[PATCH v2 2/3] KVM: arm64: selftests: Build a VM per test in vgic_lpi_stress
Fuad Tabba
fuad.tabba at linux.dev
Thu Oct 1 00:10:59 PDT 2026
vgic_lpi_stress runs its one test, the stress test, in a VM built from
the command-line configuration. Build the VM per test instead, from the
test's own configuration, guest code and IRQ handler, so that other ITS
tests can go in the same file.
The command-line configuration becomes the stress test's own
(stress_args), and each run destroys its thread barrier so the next test
can initialise it again. The guest's wait for the stop request moves to
guest_wait_for_stop(), for the other tests to share.
No functional change intended.
Suggested-by: Marc Zyngier <maz at kernel.org>
Assisted-by: LLM
Signed-off-by: Fuad Tabba <fuad.tabba at linux.dev>
---
.../selftests/kvm/arm64/vgic_lpi_stress.c | 64 ++++++++++++-------
1 file changed, 41 insertions(+), 23 deletions(-)
diff --git a/tools/testing/selftests/kvm/arm64/vgic_lpi_stress.c b/tools/testing/selftests/kvm/arm64/vgic_lpi_stress.c
index 9a69c439a0f8f..63c725b6b156c 100644
--- a/tools/testing/selftests/kvm/arm64/vgic_lpi_stress.c
+++ b/tools/testing/selftests/kvm/arm64/vgic_lpi_stress.c
@@ -29,7 +29,7 @@ static struct kvm_vm *vm;
static struct kvm_vcpu **vcpus;
static int its_fd;
-static struct test_data {
+struct test_data {
bool request_vcpus_stop;
u32 nr_cpus;
u32 nr_devices;
@@ -43,7 +43,11 @@ static struct test_data {
gpa_t lpi_prop_table;
gpa_t lpi_pend_tables;
-} test_data = {
+};
+
+static struct test_data test_data;
+
+static struct test_data stress_args = {
.nr_cpus = 1,
.nr_devices = 1,
.nr_event_ids = 16,
@@ -124,13 +128,8 @@ static void guest_setup_gic(void)
its_send_sync_cmd(test_data.cmdq_base_va, cpuid);
}
-static void guest_code(size_t nr_lpis)
+static void guest_wait_for_stop(void)
{
- guest_setup_gic();
- local_irq_enable();
-
- GUEST_SYNC(0);
-
/*
* Don't use WFI here to avoid blocking the vCPU thread indefinitely and
* never getting the stop signal.
@@ -141,6 +140,16 @@ static void guest_code(size_t nr_lpis)
GUEST_DONE();
}
+static void guest_stress_code(size_t nr_lpis)
+{
+ guest_setup_gic();
+ local_irq_enable();
+
+ GUEST_SYNC(0);
+
+ guest_wait_for_stop();
+}
+
static void setup_memslot(void)
{
size_t pages;
@@ -297,7 +306,7 @@ static void report_stats(struct timespec delta)
pr_info("Rate: %.2f LPIs/sec\n", nr_lpis / time);
}
-static void run_test(void)
+static void run_stress_test(void)
{
u32 nr_devices = test_data.nr_devices;
u32 nr_vcpus = test_data.nr_cpus;
@@ -329,10 +338,12 @@ static void run_test(void)
for (i = 0; i < nr_vcpus; i++)
kvm_pthread_join(vcpu_threads[i], NULL);
+ pthread_barrier_destroy(&test_setup_barrier);
+
report_stats(delta);
}
-static void setup_vm(void)
+static void setup_vm(void *guest_code, handler_fn irq_handler)
{
int i;
@@ -345,7 +356,7 @@ static void setup_vm(void)
for (i = 0; i < test_data.nr_cpus; i++)
vcpu_init_descriptor_tables(vcpus[i]);
- vm_install_exception_handler(vm, VECTOR_IRQ_CURRENT, guest_irq_handler);
+ vm_install_exception_handler(vm, VECTOR_IRQ_CURRENT, irq_handler);
setup_memslot();
@@ -361,12 +372,23 @@ static void destroy_vm(void)
free(vcpus);
}
+static void test_lpi_stress(void)
+{
+ test_data = stress_args;
+
+ setup_vm(guest_stress_code, guest_irq_handler);
+
+ run_stress_test();
+
+ destroy_vm();
+}
+
static void pr_usage(const char *name)
{
pr_info("%s [-v NR_VCPUS] [-d NR_DEVICES] [-e NR_EVENTS] [-i ITERS] -h\n", name);
- pr_info(" -v:\tnumber of vCPUs (default: %u)\n", test_data.nr_cpus);
- pr_info(" -d:\tnumber of devices (default: %u)\n", test_data.nr_devices);
- pr_info(" -e:\tnumber of event IDs per device (default: %u)\n", test_data.nr_event_ids);
+ pr_info(" -v:\tnumber of vCPUs (default: %u)\n", stress_args.nr_cpus);
+ pr_info(" -d:\tnumber of devices (default: %u)\n", stress_args.nr_devices);
+ pr_info(" -e:\tnumber of event IDs per device (default: %u)\n", stress_args.nr_event_ids);
pr_info(" -i:\tnumber of iterations (default: %lu)\n", nr_iterations);
}
@@ -380,13 +402,13 @@ int main(int argc, char **argv)
while ((c = getopt(argc, argv, "hv:d:e:i:")) != -1) {
switch (c) {
case 'v':
- test_data.nr_cpus = atoi(optarg);
+ stress_args.nr_cpus = atoi(optarg);
break;
case 'd':
- test_data.nr_devices = atoi(optarg);
+ stress_args.nr_devices = atoi(optarg);
break;
case 'e':
- test_data.nr_event_ids = atoi(optarg);
+ stress_args.nr_event_ids = atoi(optarg);
break;
case 'i':
nr_iterations = strtoul(optarg, NULL, 0);
@@ -398,16 +420,12 @@ int main(int argc, char **argv)
}
}
- nr_threads = test_data.nr_cpus + test_data.nr_devices;
+ nr_threads = stress_args.nr_cpus + stress_args.nr_devices;
if (nr_threads > get_nprocs())
pr_info("WARNING: running %u threads on %d CPUs; performance is degraded.\n",
nr_threads, get_nprocs());
- setup_vm();
-
- run_test();
-
- destroy_vm();
+ test_lpi_stress();
return 0;
}
--
2.39.5
More information about the linux-arm-kernel
mailing list