Commit f63f0b68 authored by Paolo Bonzini's avatar Paolo Bonzini

KVM: selftests: always use manual clear in dirty_log_perf_test

Nothing sets USE_CLEAR_DIRTY_LOG anymore, so anything it surrounds
is dead code.

However, it is the recommended way to use the dirty page bitmap
for new enough kernel, so use it whenever KVM has the
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 capability.
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 2259c17f
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#define TEST_HOST_LOOP_N 2UL #define TEST_HOST_LOOP_N 2UL
/* Host variables */ /* Host variables */
static u64 dirty_log_manual_caps;
static bool host_quit; static bool host_quit;
static uint64_t iteration; static uint64_t iteration;
static uint64_t vcpu_last_completed_iteration[MAX_VCPUS]; static uint64_t vcpu_last_completed_iteration[MAX_VCPUS];
...@@ -88,10 +89,6 @@ static void *vcpu_worker(void *data) ...@@ -88,10 +89,6 @@ static void *vcpu_worker(void *data)
return NULL; return NULL;
} }
#ifdef USE_CLEAR_DIRTY_LOG
static u64 dirty_log_manual_caps;
#endif
static void run_test(enum vm_guest_mode mode, unsigned long iterations, static void run_test(enum vm_guest_mode mode, unsigned long iterations,
uint64_t phys_offset, int wr_fract) uint64_t phys_offset, int wr_fract)
{ {
...@@ -106,10 +103,8 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations, ...@@ -106,10 +103,8 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
struct timespec get_dirty_log_total = (struct timespec){0}; struct timespec get_dirty_log_total = (struct timespec){0};
struct timespec vcpu_dirty_total = (struct timespec){0}; struct timespec vcpu_dirty_total = (struct timespec){0};
struct timespec avg; struct timespec avg;
#ifdef USE_CLEAR_DIRTY_LOG
struct kvm_enable_cap cap = {}; struct kvm_enable_cap cap = {};
struct timespec clear_dirty_log_total = (struct timespec){0}; struct timespec clear_dirty_log_total = (struct timespec){0};
#endif
vm = create_vm(mode, nr_vcpus, guest_percpu_mem_size); vm = create_vm(mode, nr_vcpus, guest_percpu_mem_size);
...@@ -120,11 +115,11 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations, ...@@ -120,11 +115,11 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
host_num_pages = vm_num_host_pages(mode, guest_num_pages); host_num_pages = vm_num_host_pages(mode, guest_num_pages);
bmap = bitmap_alloc(host_num_pages); bmap = bitmap_alloc(host_num_pages);
#ifdef USE_CLEAR_DIRTY_LOG if (dirty_log_manual_caps) {
cap.cap = KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2; cap.cap = KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2;
cap.args[0] = dirty_log_manual_caps; cap.args[0] = dirty_log_manual_caps;
vm_enable_cap(vm, &cap); vm_enable_cap(vm, &cap);
#endif }
vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads)); vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
TEST_ASSERT(vcpu_threads, "Memory allocation failed"); TEST_ASSERT(vcpu_threads, "Memory allocation failed");
...@@ -190,17 +185,17 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations, ...@@ -190,17 +185,17 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
pr_info("Iteration %lu get dirty log time: %ld.%.9lds\n", pr_info("Iteration %lu get dirty log time: %ld.%.9lds\n",
iteration, ts_diff.tv_sec, ts_diff.tv_nsec); iteration, ts_diff.tv_sec, ts_diff.tv_nsec);
#ifdef USE_CLEAR_DIRTY_LOG if (dirty_log_manual_caps) {
clock_gettime(CLOCK_MONOTONIC, &start); clock_gettime(CLOCK_MONOTONIC, &start);
kvm_vm_clear_dirty_log(vm, TEST_MEM_SLOT_INDEX, bmap, 0, kvm_vm_clear_dirty_log(vm, TEST_MEM_SLOT_INDEX, bmap, 0,
host_num_pages); host_num_pages);
ts_diff = timespec_diff_now(start); ts_diff = timespec_diff_now(start);
clear_dirty_log_total = timespec_add(clear_dirty_log_total, clear_dirty_log_total = timespec_add(clear_dirty_log_total,
ts_diff); ts_diff);
pr_info("Iteration %lu clear dirty log time: %ld.%.9lds\n", pr_info("Iteration %lu clear dirty log time: %ld.%.9lds\n",
iteration, ts_diff.tv_sec, ts_diff.tv_nsec); iteration, ts_diff.tv_sec, ts_diff.tv_nsec);
#endif }
} }
/* Tell the vcpu thread to quit */ /* Tell the vcpu thread to quit */
...@@ -220,12 +215,12 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations, ...@@ -220,12 +215,12 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
iterations, get_dirty_log_total.tv_sec, iterations, get_dirty_log_total.tv_sec,
get_dirty_log_total.tv_nsec, avg.tv_sec, avg.tv_nsec); get_dirty_log_total.tv_nsec, avg.tv_sec, avg.tv_nsec);
#ifdef USE_CLEAR_DIRTY_LOG if (dirty_log_manual_caps) {
avg = timespec_div(clear_dirty_log_total, iterations); avg = timespec_div(clear_dirty_log_total, iterations);
pr_info("Clear dirty log over %lu iterations took %ld.%.9lds. (Avg %ld.%.9lds/iteration)\n", pr_info("Clear dirty log over %lu iterations took %ld.%.9lds. (Avg %ld.%.9lds/iteration)\n",
iterations, clear_dirty_log_total.tv_sec, iterations, clear_dirty_log_total.tv_sec,
clear_dirty_log_total.tv_nsec, avg.tv_sec, avg.tv_nsec); clear_dirty_log_total.tv_nsec, avg.tv_sec, avg.tv_nsec);
#endif }
free(bmap); free(bmap);
free(vcpu_threads); free(vcpu_threads);
...@@ -284,16 +279,10 @@ int main(int argc, char *argv[]) ...@@ -284,16 +279,10 @@ int main(int argc, char *argv[])
int opt, i; int opt, i;
int wr_fract = 1; int wr_fract = 1;
#ifdef USE_CLEAR_DIRTY_LOG
dirty_log_manual_caps = dirty_log_manual_caps =
kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2);
if (!dirty_log_manual_caps) {
print_skip("KVM_CLEAR_DIRTY_LOG not available");
exit(KSFT_SKIP);
}
dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE |
KVM_DIRTY_LOG_INITIALLY_SET); KVM_DIRTY_LOG_INITIALLY_SET);
#endif
#ifdef __x86_64__ #ifdef __x86_64__
guest_mode_init(VM_MODE_PXXV48_4K, true, true); guest_mode_init(VM_MODE_PXXV48_4K, true, true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment