Commit 3468fd7d authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Use vm_create_with_vcpus() in max_guest_memory_test

Use vm_create_with_vcpus() in max_guest_memory_test and reference vCPUs
by their 'struct kvm_vcpu' object instead of their ID.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 46647c65
...@@ -28,8 +28,7 @@ static void guest_code(uint64_t start_gpa, uint64_t end_gpa, uint64_t stride) ...@@ -28,8 +28,7 @@ static void guest_code(uint64_t start_gpa, uint64_t end_gpa, uint64_t stride)
} }
struct vcpu_info { struct vcpu_info {
struct kvm_vm *vm; struct kvm_vcpu *vcpu;
uint32_t id;
uint64_t start_gpa; uint64_t start_gpa;
uint64_t end_gpa; uint64_t end_gpa;
}; };
...@@ -60,12 +59,13 @@ static void run_vcpu(struct kvm_vm *vm, uint32_t vcpu_id) ...@@ -60,12 +59,13 @@ static void run_vcpu(struct kvm_vm *vm, uint32_t vcpu_id)
static void *vcpu_worker(void *data) static void *vcpu_worker(void *data)
{ {
struct vcpu_info *vcpu = data; struct vcpu_info *info = data;
struct kvm_vcpu *vcpu = info->vcpu;
struct kvm_vm *vm = vcpu->vm; struct kvm_vm *vm = vcpu->vm;
struct kvm_sregs sregs; struct kvm_sregs sregs;
struct kvm_regs regs; struct kvm_regs regs;
vcpu_args_set(vm, vcpu->id, 3, vcpu->start_gpa, vcpu->end_gpa, vcpu_args_set(vm, vcpu->id, 3, info->start_gpa, info->end_gpa,
vm_get_page_size(vm)); vm_get_page_size(vm));
/* Snapshot regs before the first run. */ /* Snapshot regs before the first run. */
...@@ -89,8 +89,8 @@ static void *vcpu_worker(void *data) ...@@ -89,8 +89,8 @@ static void *vcpu_worker(void *data)
return NULL; return NULL;
} }
static pthread_t *spawn_workers(struct kvm_vm *vm, uint64_t start_gpa, static pthread_t *spawn_workers(struct kvm_vm *vm, struct kvm_vcpu **vcpus,
uint64_t end_gpa) uint64_t start_gpa, uint64_t end_gpa)
{ {
struct vcpu_info *info; struct vcpu_info *info;
uint64_t gpa, nr_bytes; uint64_t gpa, nr_bytes;
...@@ -108,8 +108,7 @@ static pthread_t *spawn_workers(struct kvm_vm *vm, uint64_t start_gpa, ...@@ -108,8 +108,7 @@ static pthread_t *spawn_workers(struct kvm_vm *vm, uint64_t start_gpa,
TEST_ASSERT(nr_bytes, "C'mon, no way you have %d CPUs", nr_vcpus); TEST_ASSERT(nr_bytes, "C'mon, no way you have %d CPUs", nr_vcpus);
for (i = 0, gpa = start_gpa; i < nr_vcpus; i++, gpa += nr_bytes) { for (i = 0, gpa = start_gpa; i < nr_vcpus; i++, gpa += nr_bytes) {
info[i].vm = vm; info[i].vcpu = vcpus[i];
info[i].id = i;
info[i].start_gpa = gpa; info[i].start_gpa = gpa;
info[i].end_gpa = gpa + nr_bytes; info[i].end_gpa = gpa + nr_bytes;
pthread_create(&threads[i], NULL, vcpu_worker, &info[i]); pthread_create(&threads[i], NULL, vcpu_worker, &info[i]);
...@@ -172,6 +171,7 @@ int main(int argc, char *argv[]) ...@@ -172,6 +171,7 @@ int main(int argc, char *argv[])
uint64_t max_gpa, gpa, slot_size, max_mem, i; uint64_t max_gpa, gpa, slot_size, max_mem, i;
int max_slots, slot, opt, fd; int max_slots, slot, opt, fd;
bool hugepages = false; bool hugepages = false;
struct kvm_vcpu **vcpus;
pthread_t *threads; pthread_t *threads;
struct kvm_vm *vm; struct kvm_vm *vm;
void *mem; void *mem;
...@@ -215,7 +215,10 @@ int main(int argc, char *argv[]) ...@@ -215,7 +215,10 @@ int main(int argc, char *argv[])
} }
} }
vm = vm_create_default_with_vcpus(nr_vcpus, 0, 0, guest_code, NULL); vcpus = malloc(nr_vcpus * sizeof(*vcpus));
TEST_ASSERT(vcpus, "Failed to allocate vCPU array");
vm = vm_create_with_vcpus(nr_vcpus, guest_code, vcpus);
max_gpa = vm_get_max_gfn(vm) << vm_get_page_shift(vm); max_gpa = vm_get_max_gfn(vm) << vm_get_page_shift(vm);
TEST_ASSERT(max_gpa > (4 * slot_size), "MAXPHYADDR <4gb "); TEST_ASSERT(max_gpa > (4 * slot_size), "MAXPHYADDR <4gb ");
...@@ -252,7 +255,10 @@ int main(int argc, char *argv[]) ...@@ -252,7 +255,10 @@ int main(int argc, char *argv[])
} }
atomic_set(&rendezvous, nr_vcpus + 1); atomic_set(&rendezvous, nr_vcpus + 1);
threads = spawn_workers(vm, start_gpa, gpa); threads = spawn_workers(vm, vcpus, start_gpa, gpa);
free(vcpus);
vcpus = NULL;
pr_info("Running with %lugb of guest memory and %u vCPUs\n", pr_info("Running with %lugb of guest memory and %u vCPUs\n",
(gpa - start_gpa) / size_1gb, nr_vcpus); (gpa - start_gpa) / size_1gb, nr_vcpus);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment