[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221024113445.1022147-5-wei.w.wang@intel.com>
Date: Mon, 24 Oct 2022 19:34:31 +0800
From: Wei Wang <wei.w.wang@...el.com>
To: seanjc@...gle.com, pbonzini@...hat.com
Cc: dmatlack@...gle.com, vipinsh@...gle.com, ajones@...tanamicro.com,
eric.auger@...hat.com, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, Wei Wang <wei.w.wang@...el.com>
Subject: [PATCH v1 04/18] KVM: selftests/kvm_page_table_test: vcpu related code consolidation
kvm_vm has changed to use an array of vcpu pointers (i.e. *vcpus[]) and
the vcpu thread has been included in kvm_vcpu. Remove the unnecessary
array of vcpu poniters and vcpu threads allocation. Use the helper
functions to create and join the vcpu threads.
Signed-off-by: Wei Wang <wei.w.wang@...el.com>
---
.../testing/selftests/kvm/kvm_page_table_test.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/testing/selftests/kvm/kvm_page_table_test.c
index f42c6ac6d71d..4c3df48d80fc 100644
--- a/tools/testing/selftests/kvm/kvm_page_table_test.c
+++ b/tools/testing/selftests/kvm/kvm_page_table_test.c
@@ -14,7 +14,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-#include <pthread.h>
#include <semaphore.h>
#include "test_util.h"
@@ -55,7 +54,6 @@ struct test_args {
uint64_t large_num_pages;
uint64_t host_pages_per_lpage;
enum vm_mem_backing_src_type src_type;
- struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
};
/*
@@ -255,7 +253,7 @@ static struct kvm_vm *pre_init_before_test(enum vm_guest_mode mode, void *arg)
/* Create a VM with enough guest pages */
guest_num_pages = test_mem_size / guest_page_size;
vm = __vm_create_with_vcpus(mode, nr_vcpus, guest_num_pages,
- guest_code, test_args.vcpus);
+ guest_code, NULL);
/* Align down GPA of the testing memslot */
if (!p->phys_offset)
@@ -343,7 +341,6 @@ static void vcpus_complete_new_stage(enum test_stage stage)
static void run_test(enum vm_guest_mode mode, void *arg)
{
- pthread_t *vcpu_threads;
struct kvm_vm *vm;
struct timespec start;
struct timespec ts_diff;
@@ -352,15 +349,10 @@ static void run_test(enum vm_guest_mode mode, void *arg)
/* Create VM with vCPUs and make some pre-initialization */
vm = pre_init_before_test(mode, arg);
- vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
- TEST_ASSERT(vcpu_threads, "Memory allocation failed");
-
host_quit = false;
*current_stage = KVM_BEFORE_MAPPINGS;
- for (i = 0; i < nr_vcpus; i++)
- pthread_create(&vcpu_threads[i], NULL, vcpu_worker,
- test_args.vcpus[i]);
+ vm_vcpu_threads_create(vm, vcpu_worker, 0);
vcpus_complete_new_stage(*current_stage);
pr_info("Started all vCPUs successfully\n");
@@ -407,8 +399,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
TEST_ASSERT(ret == 0, "Error in sem_post");
}
- for (i = 0; i < nr_vcpus; i++)
- pthread_join(vcpu_threads[i], NULL);
+ vm_vcpu_threads_join(vm);
ret = sem_destroy(&test_stage_updated);
TEST_ASSERT(ret == 0, "Error in sem_destroy");
@@ -416,7 +407,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
ret = sem_destroy(&test_stage_completed);
TEST_ASSERT(ret == 0, "Error in sem_destroy");
- free(vcpu_threads);
ucall_uninit(vm);
kvm_vm_free(vm);
}
--
2.27.0
Powered by blists - more mailing lists