Skip to content

Commit 9e965bb

Browse files
Ben Gardonbonzini
authored andcommitted
KVM: selftests: Add backing src parameter to dirty_log_perf_test
Add a parameter to control the backing memory type for dirty_log_perf_test so that the test can be run with hugepages. To: [email protected] CC: Peter Xu <[email protected]> CC: Andrew Jones <[email protected]> CC: Thomas Huth <[email protected]> Signed-off-by: Ben Gardon <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent f73a344 commit 9e965bb

File tree

8 files changed

+63
-15
lines changed

8 files changed

+63
-15
lines changed

tools/testing/selftests/kvm/demand_paging_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ static void run_test(enum vm_guest_mode mode, void *arg)
266266
int vcpu_id;
267267
int r;
268268

269-
vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size);
269+
vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size,
270+
VM_MEM_SRC_ANONYMOUS);
270271

271272
perf_test_args.wr_fract = 1;
272273

tools/testing/selftests/kvm/dirty_log_perf_test.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct test_params {
9393
uint64_t phys_offset;
9494
int wr_fract;
9595
bool partition_vcpu_memory_access;
96+
enum vm_mem_backing_src_type backing_src;
9697
};
9798

9899
static void run_test(enum vm_guest_mode mode, void *arg)
@@ -112,7 +113,8 @@ static void run_test(enum vm_guest_mode mode, void *arg)
112113
struct kvm_enable_cap cap = {};
113114
struct timespec clear_dirty_log_total = (struct timespec){0};
114115

115-
vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size);
116+
vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size,
117+
p->backing_src);
116118

117119
perf_test_args.wr_fract = p->wr_fract;
118120

@@ -242,7 +244,7 @@ static void help(char *name)
242244
{
243245
puts("");
244246
printf("usage: %s [-h] [-i iterations] [-p offset] "
245-
"[-m mode] [-b vcpu bytes] [-v vcpus] [-o]\n", name);
247+
"[-m mode] [-b vcpu bytes] [-v vcpus] [-o] [-s mem type]\n", name);
246248
puts("");
247249
printf(" -i: specify iteration counts (default: %"PRIu64")\n",
248250
TEST_HOST_LOOP_N);
@@ -259,6 +261,9 @@ static void help(char *name)
259261
printf(" -v: specify the number of vCPUs to run.\n");
260262
printf(" -o: Overlap guest memory accesses instead of partitioning\n"
261263
" them into a separate region of memory for each vCPU.\n");
264+
printf(" -s: specify the type of memory that should be used to\n"
265+
" back the guest data region.\n\n");
266+
backing_src_help();
262267
puts("");
263268
exit(0);
264269
}
@@ -270,6 +275,7 @@ int main(int argc, char *argv[])
270275
.iterations = TEST_HOST_LOOP_N,
271276
.wr_fract = 1,
272277
.partition_vcpu_memory_access = true,
278+
.backing_src = VM_MEM_SRC_ANONYMOUS,
273279
};
274280
int opt;
275281

@@ -280,7 +286,7 @@ int main(int argc, char *argv[])
280286

281287
guest_modes_append_default();
282288

283-
while ((opt = getopt(argc, argv, "hi:p:m:b:f:v:o")) != -1) {
289+
while ((opt = getopt(argc, argv, "hi:p:m:b:f:v:os:")) != -1) {
284290
switch (opt) {
285291
case 'i':
286292
p.iterations = atoi(optarg);
@@ -306,6 +312,8 @@ int main(int argc, char *argv[])
306312
break;
307313
case 'o':
308314
p.partition_vcpu_memory_access = false;
315+
case 's':
316+
p.backing_src = parse_backing_src_type(optarg);
309317
break;
310318
case 'h':
311319
default:

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ struct vm_guest_mode_params {
7979
};
8080
extern const struct vm_guest_mode_params vm_guest_mode_params[];
8181

82-
enum vm_mem_backing_src_type {
83-
VM_MEM_SRC_ANONYMOUS,
84-
VM_MEM_SRC_ANONYMOUS_THP,
85-
VM_MEM_SRC_ANONYMOUS_HUGETLB,
86-
};
87-
8882
int kvm_check_cap(long cap);
8983
int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap);
9084
int vcpu_enable_cap(struct kvm_vm *vm, uint32_t vcpu_id,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ extern struct perf_test_args perf_test_args;
4444
extern uint64_t guest_test_phys_mem;
4545

4646
struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
47-
uint64_t vcpu_memory_bytes);
47+
uint64_t vcpu_memory_bytes,
48+
enum vm_mem_backing_src_type backing_src);
4849
void perf_test_destroy_vm(struct kvm_vm *vm);
4950
void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
5051
uint64_t vcpu_memory_bytes,

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,18 @@ struct timespec timespec_sub(struct timespec ts1, struct timespec ts2);
6767
struct timespec timespec_elapsed(struct timespec start);
6868
struct timespec timespec_div(struct timespec ts, int divisor);
6969

70+
enum vm_mem_backing_src_type {
71+
VM_MEM_SRC_ANONYMOUS,
72+
VM_MEM_SRC_ANONYMOUS_THP,
73+
VM_MEM_SRC_ANONYMOUS_HUGETLB,
74+
};
75+
76+
struct vm_mem_backing_src_alias {
77+
const char *name;
78+
enum vm_mem_backing_src_type type;
79+
};
80+
81+
void backing_src_help(void);
82+
enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name);
83+
7084
#endif /* SELFTEST_KVM_TEST_UTIL_H */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ static void guest_code(uint32_t vcpu_id)
4949
}
5050

5151
struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
52-
uint64_t vcpu_memory_bytes)
52+
uint64_t vcpu_memory_bytes,
53+
enum vm_mem_backing_src_type backing_src)
5354
{
5455
struct kvm_vm *vm;
5556
uint64_t guest_num_pages;
@@ -93,8 +94,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
9394
pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem);
9495

9596
/* Add an extra memory slot for testing */
96-
vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS,
97-
guest_test_phys_mem,
97+
vm_userspace_mem_region_add(vm, backing_src, guest_test_phys_mem,
9898
PERF_TEST_MEM_SLOT_INDEX,
9999
guest_num_pages, 0);
100100

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <limits.h>
1111
#include <stdlib.h>
1212
#include <time.h>
13+
#include "linux/kernel.h"
1314

1415
#include "test_util.h"
1516

@@ -109,3 +110,31 @@ void print_skip(const char *fmt, ...)
109110
va_end(ap);
110111
puts(", skipping test");
111112
}
113+
114+
const struct vm_mem_backing_src_alias backing_src_aliases[] = {
115+
{"anonymous", VM_MEM_SRC_ANONYMOUS,},
116+
{"anonymous_thp", VM_MEM_SRC_ANONYMOUS_THP,},
117+
{"anonymous_hugetlb", VM_MEM_SRC_ANONYMOUS_HUGETLB,},
118+
};
119+
120+
void backing_src_help(void)
121+
{
122+
int i;
123+
124+
printf("Available backing src types:\n");
125+
for (i = 0; i < ARRAY_SIZE(backing_src_aliases); i++)
126+
printf("\t%s\n", backing_src_aliases[i].name);
127+
}
128+
129+
enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name)
130+
{
131+
int i;
132+
133+
for (i = 0; i < ARRAY_SIZE(backing_src_aliases); i++)
134+
if (!strcmp(type_name, backing_src_aliases[i].name))
135+
return backing_src_aliases[i].type;
136+
137+
backing_src_help();
138+
TEST_FAIL("Unknown backing src type: %s", type_name);
139+
return -1;
140+
}

tools/testing/selftests/kvm/memslot_modification_stress_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ static void run_test(enum vm_guest_mode mode, void *arg)
9797
struct kvm_vm *vm;
9898
int vcpu_id;
9999

100-
vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size);
100+
vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size,
101+
VM_MEM_SRC_ANONYMOUS);
101102

102103
perf_test_args.wr_fract = 1;
103104

0 commit comments

Comments
 (0)