Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: linux-kselftest@vger.kernel.org
CC: Peter Xu <peterx@redhat.com>
CC: Andrew Jones <drjones@redhat.com>
CC: Thomas Huth <thuth@redhat.com>
Signed-off-by: Ben Gardon <bgardon@google.com>
Message-Id: <20210202185734.1680553-28-bgardon@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Ben Gardon and committed by
Paolo Bonzini
9e965bb7 f73a3446

+63 -15
+2 -1
tools/testing/selftests/kvm/demand_paging_test.c
··· 266 266 int vcpu_id; 267 267 int r; 268 268 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); 270 271 271 272 perf_test_args.wr_fract = 1; 272 273
+11 -3
tools/testing/selftests/kvm/dirty_log_perf_test.c
··· 93 93 uint64_t phys_offset; 94 94 int wr_fract; 95 95 bool partition_vcpu_memory_access; 96 + enum vm_mem_backing_src_type backing_src; 96 97 }; 97 98 98 99 static void run_test(enum vm_guest_mode mode, void *arg) ··· 113 112 struct kvm_enable_cap cap = {}; 114 113 struct timespec clear_dirty_log_total = (struct timespec){0}; 115 114 116 - vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size); 115 + vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, 116 + p->backing_src); 117 117 118 118 perf_test_args.wr_fract = p->wr_fract; 119 119 ··· 244 242 { 245 243 puts(""); 246 244 printf("usage: %s [-h] [-i iterations] [-p offset] " 247 - "[-m mode] [-b vcpu bytes] [-v vcpus] [-o]\n", name); 245 + "[-m mode] [-b vcpu bytes] [-v vcpus] [-o] [-s mem type]\n", name); 248 246 puts(""); 249 247 printf(" -i: specify iteration counts (default: %"PRIu64")\n", 250 248 TEST_HOST_LOOP_N); ··· 261 259 printf(" -v: specify the number of vCPUs to run.\n"); 262 260 printf(" -o: Overlap guest memory accesses instead of partitioning\n" 263 261 " them into a separate region of memory for each vCPU.\n"); 262 + printf(" -s: specify the type of memory that should be used to\n" 263 + " back the guest data region.\n\n"); 264 + backing_src_help(); 264 265 puts(""); 265 266 exit(0); 266 267 } ··· 275 270 .iterations = TEST_HOST_LOOP_N, 276 271 .wr_fract = 1, 277 272 .partition_vcpu_memory_access = true, 273 + .backing_src = VM_MEM_SRC_ANONYMOUS, 278 274 }; 279 275 int opt; 280 276 ··· 286 280 287 281 guest_modes_append_default(); 288 282 289 - while ((opt = getopt(argc, argv, "hi:p:m:b:f:v:o")) != -1) { 283 + while ((opt = getopt(argc, argv, "hi:p:m:b:f:v:os:")) != -1) { 290 284 switch (opt) { 291 285 case 'i': 292 286 p.iterations = atoi(optarg); ··· 312 306 break; 313 307 case 'o': 314 308 p.partition_vcpu_memory_access = false; 309 + case 's': 310 + p.backing_src = parse_backing_src_type(optarg); 315 311 break; 316 312 case 'h': 317 313 default:
-6
tools/testing/selftests/kvm/include/kvm_util.h
··· 79 79 }; 80 80 extern const struct vm_guest_mode_params vm_guest_mode_params[]; 81 81 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 - 88 82 int kvm_check_cap(long cap); 89 83 int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap); 90 84 int vcpu_enable_cap(struct kvm_vm *vm, uint32_t vcpu_id,
+2 -1
tools/testing/selftests/kvm/include/perf_test_util.h
··· 44 44 extern uint64_t guest_test_phys_mem; 45 45 46 46 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); 48 49 void perf_test_destroy_vm(struct kvm_vm *vm); 49 50 void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus, 50 51 uint64_t vcpu_memory_bytes,
+14
tools/testing/selftests/kvm/include/test_util.h
··· 67 67 struct timespec timespec_elapsed(struct timespec start); 68 68 struct timespec timespec_div(struct timespec ts, int divisor); 69 69 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 + 70 84 #endif /* SELFTEST_KVM_TEST_UTIL_H */
+3 -3
tools/testing/selftests/kvm/lib/perf_test_util.c
··· 49 49 } 50 50 51 51 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) 53 54 { 54 55 struct kvm_vm *vm; 55 56 uint64_t guest_num_pages; ··· 94 93 pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem); 95 94 96 95 /* Add an extra memory slot for testing */ 97 - vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, 98 - guest_test_phys_mem, 96 + vm_userspace_mem_region_add(vm, backing_src, guest_test_phys_mem, 99 97 PERF_TEST_MEM_SLOT_INDEX, 100 98 guest_num_pages, 0); 101 99
+29
tools/testing/selftests/kvm/lib/test_util.c
··· 10 10 #include <limits.h> 11 11 #include <stdlib.h> 12 12 #include <time.h> 13 + #include "linux/kernel.h" 13 14 14 15 #include "test_util.h" 15 16 ··· 109 108 vprintf(fmt, ap); 110 109 va_end(ap); 111 110 puts(", skipping test"); 111 + } 112 + 113 + const struct vm_mem_backing_src_alias backing_src_aliases[] = { 114 + {"anonymous", VM_MEM_SRC_ANONYMOUS,}, 115 + {"anonymous_thp", VM_MEM_SRC_ANONYMOUS_THP,}, 116 + {"anonymous_hugetlb", VM_MEM_SRC_ANONYMOUS_HUGETLB,}, 117 + }; 118 + 119 + void backing_src_help(void) 120 + { 121 + int i; 122 + 123 + printf("Available backing src types:\n"); 124 + for (i = 0; i < ARRAY_SIZE(backing_src_aliases); i++) 125 + printf("\t%s\n", backing_src_aliases[i].name); 126 + } 127 + 128 + enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name) 129 + { 130 + int i; 131 + 132 + for (i = 0; i < ARRAY_SIZE(backing_src_aliases); i++) 133 + if (!strcmp(type_name, backing_src_aliases[i].name)) 134 + return backing_src_aliases[i].type; 135 + 136 + backing_src_help(); 137 + TEST_FAIL("Unknown backing src type: %s", type_name); 138 + return -1; 112 139 }
+2 -1
tools/testing/selftests/kvm/memslot_modification_stress_test.c
··· 97 97 struct kvm_vm *vm; 98 98 int vcpu_id; 99 99 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); 101 102 102 103 perf_test_args.wr_fract = 1; 103 104