Add an option to skip sanity check of number of still idle pages,
and force it on, in case hypervisor or NUMA balancing
is detected.

Signed-off-by: Maxim Levitsky <mlevi...@redhat.com>
---
 .../selftests/kvm/access_tracking_perf_test.c | 23 +++++++++++++++++--
 .../testing/selftests/kvm/include/test_util.h |  1 +
 tools/testing/selftests/kvm/lib/test_util.c   | 22 ++++++++++++++++++
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c 
b/tools/testing/selftests/kvm/access_tracking_perf_test.c
index 3c7defd34f56..eafaecf086c4 100644
--- a/tools/testing/selftests/kvm/access_tracking_perf_test.c
+++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c
@@ -65,6 +65,8 @@ static int vcpu_last_completed_iteration[KVM_MAX_VCPUS];
 /* Whether to overlap the regions of memory vCPUs access. */
 static bool overlap_memory_access;
 
+static bool skip_sanity_check;
+
 struct test_params {
        /* The backing source for the region of memory. */
        enum vm_mem_backing_src_type backing_src;
@@ -185,7 +187,7 @@ static void mark_vcpu_memory_idle(struct kvm_vm *vm,
         */
        if (still_idle >= pages / 10) {
 #ifdef __x86_64__
-               TEST_ASSERT(this_cpu_has(X86_FEATURE_HYPERVISOR),
+               TEST_ASSERT(skip_sanity_check,
                            "vCPU%d: Too many pages still idle (%lu out of 
%lu)",
                            vcpu_idx, still_idle, pages);
 #endif
@@ -342,6 +344,8 @@ static void help(char *name)
        printf(" -v: specify the number of vCPUs to run.\n");
        printf(" -o: Overlap guest memory accesses instead of partitioning\n"
               "     them into a separate region of memory for each vCPU.\n");
+       printf(" -u: Skip check that after dirtying the guest memory, most 
(90%%) of\n"
+              "it is reported as dirty again");
        backing_src_help("-s");
        puts("");
        exit(0);
@@ -359,7 +363,7 @@ int main(int argc, char *argv[])
 
        guest_modes_append_default();
 
-       while ((opt = getopt(argc, argv, "hm:b:v:os:")) != -1) {
+       while ((opt = getopt(argc, argv, "hm:b:v:os:u")) != -1) {
                switch (opt) {
                case 'm':
                        guest_modes_cmdline(optarg);
@@ -376,6 +380,9 @@ int main(int argc, char *argv[])
                case 's':
                        params.backing_src = parse_backing_src_type(optarg);
                        break;
+               case 'u':
+                       skip_sanity_check = true;
+                       break;
                case 'h':
                default:
                        help(argv[0]);
@@ -386,6 +393,18 @@ int main(int argc, char *argv[])
        page_idle_fd = open("/sys/kernel/mm/page_idle/bitmap", O_RDWR);
        __TEST_REQUIRE(page_idle_fd >= 0,
                       "CONFIG_IDLE_PAGE_TRACKING is not enabled");
+
+
+       if (skip_sanity_check == false) {
+               if (this_cpu_has(X86_FEATURE_HYPERVISOR)) {
+                       printf("Skipping idle page count sanity check, because 
the test is run nested\n");
+                       skip_sanity_check = true;
+               } else if (is_numa_balancing_enabled()) {
+                       printf("Skipping idle page count sanity check, because 
NUMA balance is enabled\n");
+                       skip_sanity_check = true;
+               }
+       }
+
        close(page_idle_fd);
 
        for_each_guest_mode(run_test, &params);
diff --git a/tools/testing/selftests/kvm/include/test_util.h 
b/tools/testing/selftests/kvm/include/test_util.h
index 3e473058849f..1bc9b0a92427 100644
--- a/tools/testing/selftests/kvm/include/test_util.h
+++ b/tools/testing/selftests/kvm/include/test_util.h
@@ -153,6 +153,7 @@ bool is_backing_src_hugetlb(uint32_t i);
 void backing_src_help(const char *flag);
 enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name);
 long get_run_delay(void);
+bool is_numa_balancing_enabled(void);
 
 /*
  * Whether or not the given source type is shared memory (as opposed to
diff --git a/tools/testing/selftests/kvm/lib/test_util.c 
b/tools/testing/selftests/kvm/lib/test_util.c
index 8ed0b74ae837..1271863613fa 100644
--- a/tools/testing/selftests/kvm/lib/test_util.c
+++ b/tools/testing/selftests/kvm/lib/test_util.c
@@ -163,6 +163,28 @@ size_t get_trans_hugepagesz(void)
        return size;
 }
 
+
+bool is_numa_balancing_enabled(void)
+{
+       int ret;
+       int val;
+       struct stat statbuf;
+       FILE *f;
+
+       ret = stat("/proc/sys/kernel/numa_balancing", &statbuf);
+       TEST_ASSERT(ret == 0 || (ret == -1 && errno == ENOENT),
+                       "Error in stating /proc/sys/kernel/numa_balancing");
+
+       if (ret != 0)
+               return false;
+
+       f = fopen("/proc/sys/kernel/numa_balancing", "r");
+       ret = fscanf(f, "%d", &val);
+
+       TEST_ASSERT(val == 0 || val == 1, "Unexpected value in 
/proc/sys/kernel/numa_balancing");
+       return val == 1;
+}
+
 size_t get_def_hugetlb_pagesz(void)
 {
        char buf[64];
-- 
2.26.3


Reply via email to