KVM: selftests: Cleanups, take 2
v4 cover KVM: selftests: Cleanups, take 2
This series attempts to clean up demand_paging_test, dirty_log_perf_test, and dirty_log_test by factoring out common code, creating some new API along the way. It also splits include/perf_test_util.h into a more conventional header and source pair.
I've tested on x86 and AArch64 (one config each), but not s390x.
v4:
- dropped "KVM: selftests: dirty_log_test: Remove create_vm" patch
- Rebased on latest kvm/queue (patches applied cleanly)
- Ensured dirty-ring was enabled on x86 when testing
v3:
- Rebased remaining four patches from v2 onto kvm/queue
- Picked up r-b's from Peter and Ben
v2: https://www.spinics.net/lists/kvm/msg228711.html
Thanks,
drew
Andrew Jones (3):
KVM: selftests: Factor out guest mode code
KVM: selftests: Use vm_create_with_vcpus in create_vm
KVM: selftests: Implement perf_test_util more conventionally
tools/testing/selftests/kvm/Makefile | 2 +- .../selftests/kvm/demand_paging_test.c | 118 ++++--------- .../selftests/kvm/dirty_log_perf_test.c | 145 +++++---------- tools/testing/selftests/kvm/dirty_log_test.c | 125 ++++--------- .../selftests/kvm/include/guest_modes.h | 21 +++ .../testing/selftests/kvm/include/kvm_util.h | 9 + .../selftests/kvm/include/perf_test_util.h | 167 ++---------------- tools/testing/selftests/kvm/lib/guest_modes.c | 70 ++++++++ tools/testing/selftests/kvm/lib/kvm_util.c | 9 +- .../selftests/kvm/lib/perf_test_util.c | 134 ++++++++++++++ 10 files changed, 363 insertions(+), 437 deletions(-) create mode 100644 tools/testing/selftests/kvm/include/guest_modes.h create mode 100644 tools/testing/selftests/kvm/lib/guest_modes.c create mode 100644 tools/testing/selftests/kvm/lib/perf_test_util.c
Signature · 1 line
2.26.2
PATCH v4 1/3 KVM: selftests: Factor out guest mode code
demand_paging_test, dirty_log_test, and dirty_log_perf_test have redundant guest mode code. Factor it out.
Also, while adding a new include, remove the ones we don't need.
--- tools/testing/selftests/kvm/Makefile | 2 +- .../selftests/kvm/demand_paging_test.c | 107 ++++----------- .../selftests/kvm/dirty_log_perf_test.c | 121 +++++------------ tools/testing/selftests/kvm/dirty_log_test.c | 125 ++++++------------ .../selftests/kvm/include/guest_modes.h | 21 +++ tools/testing/selftests/kvm/lib/guest_modes.c | 70 ++++++++++ 6 files changed, 189 insertions(+), 257 deletions(-) create mode 100644 tools/testing/selftests/kvm/include/guest_modes.h create mode 100644 tools/testing/selftests/kvm/lib/guest_modes.c
tools/testing/selftests/kvm/Makefile +1 -1
@@ -33,7 +33,7 @@ ifeq ($(ARCH),s390) UNAME_M := s390x endif -LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c +LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c
tools/testing/selftests/kvm/demand_paging_test.c +26 -81
184 lines not on this page · raw message
tools/testing/selftests/kvm/dirty_log_perf_test.c +34 -87
214 lines not on this page · raw message
tools/testing/selftests/kvm/dirty_log_test.c +37 -88
210 lines not on this page · raw message
tools/testing/selftests/kvm/include/guest_modes.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2020, Red Hat, Inc. +*/ +#include "kvm_util.h" + +struct guest_mode { +bool supported; +bool enabled; +}; + +extern struct guest_mode guest_modes[NUM_VM_MODES ]; + +#define guest_mode_append (mode, supported, enabled) ({ \ + guest_modes[mode] = (struct guest_mode){ supported, enabled }; \ +}) + +void guest_modes_append_default (void ); +void for_each_guest_mode (void (*func)(enum vm_guest_mode ,void *),void *arg); +void guest_modes_help (void ); +void guest_modes_cmdline (const char *arg);
tools/testing/selftests/kvm/lib/guest_modes.c new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v4 2/3 KVM: selftests: Use vm_create_with_vcpus in create_vm
In reply to Andrew Jones--- .../selftests/kvm/demand_paging_test.c | 2 +- .../selftests/kvm/dirty_log_perf_test.c | 2 - .../testing/selftests/kvm/include/kvm_util.h | 8 ++++ .../selftests/kvm/include/perf_test_util.h | 47 +++++-------------- tools/testing/selftests/kvm/lib/kvm_util.c | 9 +--- 5 files changed, 21 insertions(+), 47 deletions(-)
tools/testing/selftests/kvm/demand_paging_test.c +1 -1
@@ -7,7 +7,7 @@* Copyright (C) 2019, Google, Inc. */ -#define _GNU_SOURCE/* for program_invocation_name and pipe2 */ +#define _GNU_SOURCE/* for pipe2 */ #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/dirty_log_perf_test.c +0 -2
@@ -8,8 +8,6 @@* Copyright (C) 2020, Google, Inc. */ -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <time.h>
tools/testing/selftests/kvm/include/kvm_util.h +8 -0
@@ -70,6 +70,14 @@ enum vm_guest_mode {#define vm_guest_mode_string (m) vm_guest_mode_string[m]extern const char *const vm_guest_mode_string[]; +struct vm_guest_mode_params { +unsigned int pa_bits; +unsigned int va_bits; +unsigned int page_size; +unsigned int page_shift; +}; +extern const struct vm_guest_mode_params vm_guest_mode_params[]; +enum vm_mem_backing_src_type {VM_MEM_SRC_ANONYMOUS ,VM_MEM_SRC_ANONYMOUS_THP ,
tools/testing/selftests/kvm/include/perf_test_util.h +11 -36
87 lines not on this page · raw message
tools/testing/selftests/kvm/lib/kvm_util.c +1 -8
@@ -153,14 +153,7 @@ const char * const vm_guest_mode_string[] = {_Static_assert (sizeof (vm_guest_mode_string)/sizeof (char *) ==NUM_VM_MODES ,"Missing new mode strings?" ); -struct vm_guest_mode_params { -unsigned int pa_bits; -unsigned int va_bits; -unsigned int page_size; -unsigned int page_shift; -}; - -static const struct vm_guest_mode_params vm_guest_mode_params[] = { +const struct vm_guest_mode_params vm_guest_mode_params[] = { {52 ,48 ,0x1000 ,12 }, {52 ,48 ,0x10000 ,16 }, {48 ,48 ,0x1000 ,12 },
Signature · 1 line
2.26.2
PATCH v4 3/3 KVM: selftests: Implement perf_test_util more conventionally
In reply to Andrew JonesIt's not conventional C to put non-inline functions in header files. Create a source file for the functions instead. Also reduce the amount of globals and rename the functions to something less generic.
--- tools/testing/selftests/kvm/Makefile | 2 +- .../selftests/kvm/demand_paging_test.c | 11 +- .../selftests/kvm/dirty_log_perf_test.c | 22 +-- .../testing/selftests/kvm/include/kvm_util.h | 1 + .../selftests/kvm/include/perf_test_util.h | 142 ++---------------- .../selftests/kvm/lib/perf_test_util.c | 134 +++++++++++++++++ 6 files changed, 166 insertions(+), 146 deletions(-) create mode 100644 tools/testing/selftests/kvm/lib/perf_test_util.c
tools/testing/selftests/kvm/Makefile +1 -1
@@ -33,7 +33,7 @@ ifeq ($(ARCH),s390) UNAME_M := s390x endif -LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c +LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c lib/perf_test_util.c LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c
tools/testing/selftests/kvm/demand_paging_test.c +6 -5
@@ -36,12 +36,14 @@#define PER_VCPU_DEBUG (...) _no_printf(__VA_ARGS__)#endif +static int nr_vcpus =1 ; +static uint64_t guest_percpu_mem_size =DEFAULT_PER_VCPU_MEM_SIZE ;static char *guest_data_prototype;static void *vcpu_worker (void *data) {int ret; -struct vcpu_args *vcpu_args = (struct vcpu_args *)data; +struct perf_test_vcpu_args *vcpu_args = (struct perf_test_vcpu_args *)data;int vcpu_id = vcpu_args->vcpu_id;struct kvm_vm *vm = perf_test_args.vm;struct kvm_run *run;
@@ -263,7 +265,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)int vcpu_id;int r; - vm =create_vm (mode, nr_vcpus, guest_percpu_mem_size); + vm =perf_test_create_vm (mode, nr_vcpus, guest_percpu_mem_size); perf_test_args.wr_fract =1 ;
@@ -275,7 +277,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) vcpu_threads =malloc (nr_vcpus *sizeof (*vcpu_threads));TEST_ASSERT (vcpu_threads,"Memory allocation failed" ); -add_vcpus (vm, nr_vcpus, guest_percpu_mem_size); +perf_test_setup_vcpus (vm, nr_vcpus, guest_percpu_mem_size);if (p->use_uffd) { uffd_handler_threads =
@@ -359,8 +361,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) perf_test_args.vcpu_args[0 ].pages * nr_vcpus / ((double)ts_diff.tv_sec + (double)ts_diff.tv_nsec / 100000000.0)); -ucall_uninit (vm); -kvm_vm_free (vm); +perf_test_destroy_vm (vm);free (guest_data_prototype);free (vcpu_threads);
tools/testing/selftests/kvm/dirty_log_perf_test.c +12 -10
@@ -22,11 +22,14 @@/* How many host loops to run by default (one KVM_GET_DIRTY_LOG for each loop)*/ #define TEST_HOST_LOOP_N 2UL +static int nr_vcpus =1 ; +static uint64_t guest_percpu_mem_size =DEFAULT_PER_VCPU_MEM_SIZE ; +/* Host variables */ static u64 dirty_log_manual_caps;static bool host_quit;static uint64_t iteration; -static uint64_t vcpu_last_completed_iteration[MAX_VCPUS ]; +static uint64_t vcpu_last_completed_iteration[KVM_MAX_VCPUS ];static void *vcpu_worker (void *data) {
@@ -38,7 +41,7 @@ static void *vcpu_worker(void *data)struct timespec ts_diff;struct timespec total = (struct timespec ){0 };struct timespec avg; -struct vcpu_args *vcpu_args = (struct vcpu_args *)data; +struct perf_test_vcpu_args *vcpu_args = (struct perf_test_vcpu_args *)data;int vcpu_id = vcpu_args->vcpu_id;vcpu_args_set (vm, vcpu_id,1 , vcpu_id);
@@ -108,7 +111,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)struct kvm_enable_cap cap = {};struct timespec clear_dirty_log_total = (struct timespec ){0 }; - vm =create_vm (mode, nr_vcpus, guest_percpu_mem_size); + vm =perf_test_create_vm (mode, nr_vcpus, guest_percpu_mem_size); perf_test_args.wr_fract = p->wr_fract;
@@ -126,7 +129,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) vcpu_threads =malloc (nr_vcpus *sizeof (*vcpu_threads));TEST_ASSERT (vcpu_threads,"Memory allocation failed" ); -add_vcpus (vm, nr_vcpus, guest_percpu_mem_size); +perf_test_setup_vcpus (vm, nr_vcpus, guest_percpu_mem_size);sync_global_to_guest (vm, perf_test_args);
@@ -152,7 +155,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)/* Enable dirty logging */ clock_gettime (CLOCK_MONOTONIC , &start); -vm_mem_region_set_flags (vm,TEST_MEM_SLOT_INDEX , +vm_mem_region_set_flags (vm,PERF_TEST_MEM_SLOT_INDEX ,KVM_MEM_LOG_DIRTY_PAGES ); ts_diff =timespec_diff_now (start); pr_info("Enabling dirty logging time: %ld.%.9lds\n\n",
@@ -179,7 +182,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) iteration, ts_diff.tv_sec, ts_diff.tv_nsec);clock_gettime (CLOCK_MONOTONIC , &start); -kvm_vm_get_dirty_log (vm,TEST_MEM_SLOT_INDEX , bmap); +kvm_vm_get_dirty_log (vm,PERF_TEST_MEM_SLOT_INDEX , bmap); ts_diff =timespec_diff_now (start); get_dirty_log_total = timespec_add(get_dirty_log_total,
@@ -189,7 +192,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)if (dirty_log_manual_caps) {clock_gettime (CLOCK_MONOTONIC , &start); -kvm_vm_clear_dirty_log (vm,TEST_MEM_SLOT_INDEX , bmap,0 , +kvm_vm_clear_dirty_log (vm,PERF_TEST_MEM_SLOT_INDEX , bmap,0 , host_num_pages); ts_diff =timespec_diff_now (start);
@@ -207,7 +210,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)/* Disable dirty logging */ clock_gettime (CLOCK_MONOTONIC , &start); -vm_mem_region_set_flags (vm,TEST_MEM_SLOT_INDEX ,0 ); +vm_mem_region_set_flags (vm,PERF_TEST_MEM_SLOT_INDEX ,0 ); ts_diff =timespec_diff_now (start);pr_info ("Disabling dirty logging time: %ld.%.9lds\n" , ts_diff.tv_sec, ts_diff.tv_nsec);
@@ -226,8 +229,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)free (bmap);free (vcpu_threads); -ucall_uninit (vm); -kvm_vm_free (vm); +perf_test_destroy_vm (vm); }static void help (char *name)
tools/testing/selftests/kvm/include/kvm_util.h +1 -0
@@ -16,6 +16,7 @@#include "sparsebit.h" +#define KVM_MAX_VCPUS 512/* * Callers of kvm_util only have an incomplete/opaque description of the
tools/testing/selftests/kvm/include/perf_test_util.h +12 -130
166 lines not on this page · raw message
tools/testing/selftests/kvm/lib/perf_test_util.c new file +134 -0
134 lines not on this page · raw message
Signature · 1 line
2.26.2
Quoted 38 lines · Andrew Jones
This series attempts to clean up
demand_paging_test,dirty_log_perf_test, anddirty_log_testby factoring out common code, creating some new API along the way. It also splitsinclude/perf_test_util.hinto a more conventional header and source pair.I've tested on x86 and AArch64 (one config each), but not s390x.
v4:
- dropped "KVM: selftests:dirty_log_test: Removecreate_vm" patch
- Rebased on latest kvm/queue (patches applied cleanly)
- Ensured dirty-ring was enabled on x86 when testingv3:
- Rebased remaining four patches from v2 onto kvm/queue
- Picked up r-b's from Peter and Benv2: https://www.spinics.net/lists/kvm/msg228711.html
Thanks,
drewAndrew Jones (3):
KVM: selftests: Factor out guest mode code
KVM: selftests: Usevm_create_with_vcpusincreate_vm
KVM: selftests: Implementperf_test_utilmore conventionallytools/testing/selftests/kvm/Makefile | 2 +- .../selftests/kvm/demand_paging_test.c | 118 ++++--------- .../selftests/kvm/dirty_log_perf_test.c | 145 +++++---------- tools/testing/selftests/kvm/dirty_log_test.c | 125 ++++--------- .../selftests/kvm/include/guest_modes.h | 21 +++ .../testing/selftests/kvm/include/kvm_util.h | 9 + .../selftests/kvm/include/perf_test_util.h | 167 ++---------------- tools/testing/selftests/kvm/lib/guest_modes.c | 70 ++++++++ tools/testing/selftests/kvm/lib/kvm_util.c | 9 +- .../selftests/kvm/lib/perf_test_util.c | 134 ++++++++++++++ 10 files changed, 363 insertions(+), 437 deletions(-)
Quoted 4 lines
create mode 100644
tools/testing/selftests/kvm/include/guest_modes.hcreate mode 100644tools/testing/selftests/kvm/lib/guest_modes.ccreate mode 100644tools/testing/selftests/kvm/lib/perf_test_util.c
Queued, thanks.
Paolo