Skip to content

Commit 6769155

Browse files
Andrew Jonesbonzini
authored andcommitted
KVM: selftests: Make the per vcpu memory size global
Rename vcpu_memory_bytes to something with "percpu" in it in order to be less ambiguous. Also make it global to simplify things. Signed-off-by: Andrew Jones <drjones@redhat.com> Message-Id: <20201104212357.171559-7-drjones@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent f663132 commit 6769155

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

tools/testing/selftests/kvm/demand_paging_test.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
#ifdef __NR_userfaultfd
2929

30-
#define DEFAULT_GUEST_TEST_MEM_SIZE (1 << 30) /* 1G */
31-
3230
#ifdef PRINT_PER_PAGE_UPDATES
3331
#define PER_PAGE_DEBUG(...) printf(__VA_ARGS__)
3432
#else
@@ -251,8 +249,7 @@ static int setup_demand_paging(struct kvm_vm *vm,
251249
}
252250

253251
static void run_test(enum vm_guest_mode mode, bool use_uffd,
254-
useconds_t uffd_delay, int vcpus,
255-
uint64_t vcpu_memory_bytes)
252+
useconds_t uffd_delay, int vcpus)
256253
{
257254
pthread_t *vcpu_threads;
258255
pthread_t *uffd_handler_threads = NULL;
@@ -264,7 +261,7 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
264261
int vcpu_id;
265262
int r;
266263

267-
vm = create_vm(mode, vcpus, vcpu_memory_bytes);
264+
vm = create_vm(mode, vcpus, guest_percpu_mem_size);
268265

269266
perf_test_args.wr_fract = 1;
270267

@@ -276,7 +273,7 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
276273
vcpu_threads = malloc(vcpus * sizeof(*vcpu_threads));
277274
TEST_ASSERT(vcpu_threads, "Memory allocation failed");
278275

279-
add_vcpus(vm, vcpus, vcpu_memory_bytes);
276+
add_vcpus(vm, vcpus, guest_percpu_mem_size);
280277

281278
if (use_uffd) {
282279
uffd_handler_threads =
@@ -293,9 +290,9 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
293290
vm_paddr_t vcpu_gpa;
294291
void *vcpu_hva;
295292

296-
vcpu_gpa = guest_test_phys_mem + (vcpu_id * vcpu_memory_bytes);
293+
vcpu_gpa = guest_test_phys_mem + (vcpu_id * guest_percpu_mem_size);
297294
PER_VCPU_DEBUG("Added VCPU %d with test mem gpa [%lx, %lx)\n",
298-
vcpu_id, vcpu_gpa, vcpu_gpa + vcpu_memory_bytes);
295+
vcpu_id, vcpu_gpa, vcpu_gpa + guest_percpu_mem_size);
299296

300297
/* Cache the HVA pointer of the region */
301298
vcpu_hva = addr_gpa2hva(vm, vcpu_gpa);
@@ -312,7 +309,7 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
312309
&uffd_handler_threads[vcpu_id],
313310
pipefds[vcpu_id * 2],
314311
uffd_delay, &uffd_args[vcpu_id],
315-
vcpu_hva, vcpu_memory_bytes);
312+
vcpu_hva, guest_percpu_mem_size);
316313
if (r < 0)
317314
exit(-r);
318315
}
@@ -413,7 +410,6 @@ static void help(char *name)
413410
int main(int argc, char *argv[])
414411
{
415412
bool mode_selected = false;
416-
uint64_t vcpu_memory_bytes = DEFAULT_GUEST_TEST_MEM_SIZE;
417413
int vcpus = 1;
418414
unsigned int mode;
419415
int opt, i;
@@ -463,7 +459,7 @@ int main(int argc, char *argv[])
463459
"A negative UFFD delay is not supported.");
464460
break;
465461
case 'b':
466-
vcpu_memory_bytes = parse_size(optarg);
462+
guest_percpu_mem_size = parse_size(optarg);
467463
break;
468464
case 'v':
469465
vcpus = atoi(optarg);
@@ -486,7 +482,7 @@ int main(int argc, char *argv[])
486482
TEST_ASSERT(guest_modes[i].supported,
487483
"Guest mode ID %d (%s) not supported.",
488484
i, vm_guest_mode_string(i));
489-
run_test(i, use_uffd, uffd_delay, vcpus, vcpu_memory_bytes);
485+
run_test(i, use_uffd, uffd_delay, vcpus);
490486
}
491487

492488
return 0;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
/* Default guest test virtual memory offset */
2222
#define DEFAULT_GUEST_TEST_MEM 0xc0000000
2323

24+
#define DEFAULT_PER_VCPU_MEM_SIZE (1 << 30) /* 1G */
25+
2426
/*
2527
* Guest physical memory offset of the testing memory slot.
2628
* This will be set to the topmost valid physical address minus
@@ -33,6 +35,7 @@ static uint64_t guest_test_phys_mem;
3335
* Must not conflict with identity mapped test code.
3436
*/
3537
static uint64_t guest_test_virt_mem = DEFAULT_GUEST_TEST_MEM;
38+
static uint64_t guest_percpu_mem_size = DEFAULT_PER_VCPU_MEM_SIZE;
3639

3740
struct vcpu_args {
3841
uint64_t gva;

0 commit comments

Comments
 (0)