selftests: KVM: Move dirty logging functions to memstress.(c|h)
RFC 1/2 selftests: KVM: Move dirty logging functions to memstress.(c|h)
Move some helper functions from dirty_log_perf_test.c to the memstress library so that they can be used in a future commit which tests page splitting during dirty logging.
--- .../selftests/kvm/dirty_log_perf_test.c | 84 ++----------------- .../testing/selftests/kvm/include/memstress.h | 8 ++ tools/testing/selftests/kvm/lib/memstress.c | 72 ++++++++++++++++ 3 files changed, 87 insertions(+), 77 deletions(-)
tools/testing/selftests/kvm/dirty_log_perf_test.c +7 -77
@@ -136,77 +136,6 @@ struct test_params {bool random_access; }; -static void toggle_dirty_logging (struct kvm_vm *vm,int slots,bool enable) -{ -int i; - -for (i =0 ; i < slots; i++) { -int slot =MEMSTRESS_MEM_SLOT_INDEX + i; -int flags = enable ?KVM_MEM_LOG_DIRTY_PAGES :0 ; - -vm_mem_region_set_flags (vm, slot, flags); - } -} - -static inline void enable_dirty_logging (struct kvm_vm *vm,int slots) -{ -toggle_dirty_logging (vm, slots, true); -} - -static inline void disable_dirty_logging (struct kvm_vm *vm,int slots) -{ -toggle_dirty_logging (vm, slots, false); -} - -static void get_dirty_log (struct kvm_vm *vm,unsigned long *bitmaps[],int slots) -{ -int i; - -for (i =0 ; i < slots; i++) { -int slot =MEMSTRESS_MEM_SLOT_INDEX + i; - -kvm_vm_get_dirty_log (vm, slot, bitmaps[i]); - } -} - -static void clear_dirty_log (struct kvm_vm *vm,unsigned long *bitmaps[], -int slots,uint64_t pages_per_slot) -{ -int i; - -for (i =0 ; i < slots; i++) { -int slot =MEMSTRESS_MEM_SLOT_INDEX + i; - -kvm_vm_clear_dirty_log (vm, slot, bitmaps[i],0 , pages_per_slot); - } -} - -static unsigned long **alloc_bitmaps (int slots,uint64_t pages_per_slot) -{ -unsigned long **bitmaps; -int i; - - bitmaps =malloc (slots *sizeof (bitmaps[0 ])); -TEST_ASSERT (bitmaps,"Failed to allocate bitmaps array." ); - -for (i =0 ; i < slots; i++) { - bitmaps[i] =bitmap_zalloc (pages_per_slot); -TEST_ASSERT (bitmaps[i],"Failed to allocate slot bitmap." ); - } - -return bitmaps; -} - -static void free_bitmaps (unsigned long *bitmaps[],int slots) -{ -int i; - -for (i =0 ; i < slots; i++) -free (bitmaps[i]); - -free (bitmaps); -} -static void run_test (enum vm_guest_mode mode,void *arg) {struct test_params *p = arg;
@@ -236,7 +165,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) host_num_pages =vm_num_host_pages (mode, guest_num_pages); pages_per_slot = host_num_pages / p->slots; - bitmaps =alloc_bitmaps (p->slots, pages_per_slot); + bitmaps =memstress_alloc_bitmaps (p->slots, pages_per_slot);if (dirty_log_manual_caps) vm_enable_cap(vm, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2,
@@ -277,7 +206,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)/* Enable dirty logging */ clock_gettime (CLOCK_MONOTONIC , &start); -enable_dirty_logging (vm, p->slots); +memstress_enable_dirty_logging (vm, p->slots); ts_diff =timespec_elapsed (start);pr_info ("Enabling dirty logging time: %ld.%.9lds\n\n" , ts_diff.tv_sec, ts_diff.tv_nsec);
@@ -306,7 +235,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); -get_dirty_log (vm, bitmaps, p->slots); +memstress_get_dirty_log (vm, bitmaps, p->slots); ts_diff =timespec_elapsed (start); get_dirty_log_total =timespec_add (get_dirty_log_total, ts_diff);
@@ -315,7 +244,8 @@ static void run_test(enum vm_guest_mode mode, void *arg)if (dirty_log_manual_caps) {clock_gettime (CLOCK_MONOTONIC , &start); -clear_dirty_log (vm, bitmaps, p->slots, pages_per_slot); +memstress_clear_dirty_log (vm, bitmaps, p->slots, + pages_per_slot); ts_diff =timespec_elapsed (start); clear_dirty_log_total =timespec_add (clear_dirty_log_total, ts_diff);
@@ -334,7 +264,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)/* Disable dirty logging */ clock_gettime (CLOCK_MONOTONIC , &start); -disable_dirty_logging (vm, p->slots); +memstress_disable_dirty_logging (vm, p->slots); ts_diff =timespec_elapsed (start);pr_info ("Disabling dirty logging time: %ld.%.9lds\n" , ts_diff.tv_sec, ts_diff.tv_nsec);
@@ -359,7 +289,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) clear_dirty_log_total.tv_nsec, avg.tv_sec, avg.tv_nsec); } -free_bitmaps (bitmaps, p->slots); +memstress_free_bitmaps (bitmaps, p->slots);arch_cleanup_vm (vm);memstress_destroy_vm (vm); }
tools/testing/selftests/kvm/include/memstress.h +8 -0
@@ -72,4 +72,12 @@ void memstress_guest_code(uint32_t vcpu_id);uint64_t memstress_nested_pages (int nr_vcpus);void memstress_setup_nested (struct kvm_vm *vm,int nr_vcpus,struct kvm_vcpu *vcpus[]); +void memstress_enable_dirty_logging (struct kvm_vm *vm,int slots); +void memstress_disable_dirty_logging (struct kvm_vm *vm,int slots); +void memstress_get_dirty_log (struct kvm_vm *vm,unsigned long *bitmaps[],int slots); +void memstress_clear_dirty_log (struct kvm_vm *vm,unsigned long *bitmaps[], +int slots,uint64_t pages_per_slot); +unsigned long **memstress_alloc_bitmaps (int slots,uint64_t pages_per_slot); +void memstress_free_bitmaps (unsigned long *bitmaps[],int slots); +#endif /* SELFTEST_KVM_MEMSTRESS_H */
tools/testing/selftests/kvm/lib/memstress.c +72 -0
81 lines not on this page · raw message
Signature · 1 line
2.39.1.405.gd4c25cc71f-goog
RFC 2/2 selftests: KVM: Add page splitting test
Add a test for page splitting during dirty logging and for hugepage recovery after dirty logging.
Page splitting represents non-trivial behavior, which is complicated by MANUAL_PROTECT mode, which causes pages to be split on the first clear, instead of when dirty logging is enabled.
Add a test which makes asserions about page counts to help define the expected behavior of page splitting and to provid needed coverage of the behavior. This also helps ensure that a failure in eager page splitting is not covered up by splitting in the vCPU path.
Tested by running the test on an Intel Haswell machine w/wo MANUAL_PROTECT.
--- tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/include/kvm_util_base.h | 1 + .../kvm/x86_64/page_splitting_test.c | 311 ++++++++++++++++++ 3 files changed, 313 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/page_splitting_test.c
tools/testing/selftests/kvm/Makefile +1 -0
@@ -76,6 +76,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test TEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test TEST_GEN_PROGS_x86_64 += x86_64/monitor_mwait_test TEST_GEN_PROGS_x86_64 += x86_64/nested_exceptions_test +TEST_GEN_PROGS_x86_64 += x86_64/page_splitting_test TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test TEST_GEN_PROGS_x86_64 += x86_64/pmu_event_filter_test TEST_GEN_PROGS_x86_64 += x86_64/set_boot_cpu_id
tools/testing/selftests/kvm/include/kvm_util_base.h +1 -0
@@ -402,6 +402,7 @@ static inline uint64_t vm_get_stat(struct kvm_vm *vm, const char *stat_name)uint64_t data;__vm_get_stat (vm, stat_name, &data,1 ); +return data; }
tools/testing/selftests/kvm/x86_64/page_splitting_test.c new file +311 -0
311 lines not on this page · raw message
Signature · 1 line
2.39.1.405.gd4c25cc71f-goog
Sean Christopherson
reviewerPlease provide cover letters for multi-patch series, regardless of how trivial the series is.
This series especially needs a cover explaining why it's tagged "RFC".
Woops! I did not mean to tag this RFC. Sorry about that. I will include a cover letter in the future and can resend these with one if preferred.
Quoted 5 lines · Sean Christopherson
Please provide cover letters for multi-patch series, regardless of how trivial the series is.
This series especially needs a cover explaining why it's tagged "RFC".
Sean Christopherson
reviewerQuoted 1 line · Ben Gardon
Woops!
Heh, and top posting too. Me thinks you had too long of a break ;-)
Quoted 2 lines
I did not mean to tag this RFC. Sorry about that. I will include a cover letter in the future and can resend these with one if preferred.
Eh, no need, damage done. I was just confused.
Quoted 6 lines · Sean Christopherson
Quoted 5 lines
Please provide cover letters for multi-patch series, regardless of how trivial the series is.
This series especially needs a cover explaining why it's tagged "RFC".
Quoted 5 lines · Sean Christopherson
Quoted 1 line · Ben Gardon
Woops!
Heh, and top posting too. Me thinks you had too long of a break ;-)
Oh no, I'm in shambles (^:
Quoted 5 lines
Quoted 3 lines
I did not mean to tag this RFC. Sorry about that. I will include a cover letter in the future and can resend these with one if preferred.
Eh, no need, damage done. I was just confused.
I sent a revised version anyway because I realized it probably made sense to have test skip itself if TDP MMU or Eager Page Splitting was disabled.
Quoted 7 lines
Quoted 7 lines · Sean Christopherson
Quoted 5 lines
Please provide cover letters for multi-patch series, regardless of how trivial the series is.
This series especially needs a cover explaining why it's tagged "RFC".