Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4187254pxf; Tue, 30 Mar 2021 01:12:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSBzUc0kb3kFGnfaccIuiD1bElFwr0kvPum+vhpOBdcmBVth8zl3Kd0I3J0xsQ6611PkwP X-Received: by 2002:a17:906:22d4:: with SMTP id q20mr33215120eja.54.1617091962314; Tue, 30 Mar 2021 01:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617091962; cv=none; d=google.com; s=arc-20160816; b=CdGqpMOEOtsGQkqQwAHMtYfIGAl+HaLEE2E3aBmbsSnrAECUF9k4OTsNvLIrWHi1xi x5OZCYXquN50ExBv+JKwh9PZYP4ockZ/IKo/Hp3/2y6CH7ohvWUdDD4gLO2W2LwL4CJE 2Rgl5ezCwi8ZfOcfGc9t1UjKcwGtfFN9QA2ywn3DtvEWN8C5q1i1S3jwcqd3Rv54xsjW +zoQd74pDMVr2FwsC7uF56R0dHj8A49etfHru13WHMzzdsUYzRk5wZczKsNm7NXsbi2F RYNGFmJpJToyz8Q8aRwKcvqe43LZYQ51NOWbj/f7pNbTC70He3FojBSqzkIwezfv1hsC jKZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=RW+ILiMeZtkp0b7hfEvn41vse8XrOEl7jxHbtP0JpNE=; b=ZilW7zc0odmmpaTtHWf4GQlUgWsmnGEc6mzgu0CyguINaBkcMrtjckiWp815MshoQ/ 8qFCebXp+HPgtbmGzR5dEjdEQvXdRPhHZ+SBS2W/kB8XO99P6LG5VRazoSP+kYt4MWCw 6Mk5yYTzDFH4gj+zlML+aQo2aaZb40W6yApg3VcNiH/8y8uUmLHh3YitzO3bFgArFrnU mQ94pT3Dc737RHILBe+N2lYDFd78TuG3CbngY63+9A2gYKqEyK7ICpQepYWQnkv+wMH9 kzRr3Za/WjpclKsvoVTd5fsKvpIsRtVujrvUMzyCUhSGDA63wG/pbW/qqKYgDZicIM/d KHUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u12si16050602eda.90.2021.03.30.01.12.20; Tue, 30 Mar 2021 01:12:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231460AbhC3IJR (ORCPT + 99 others); Tue, 30 Mar 2021 04:09:17 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:15102 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231337AbhC3IJM (ORCPT ); Tue, 30 Mar 2021 04:09:12 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F8hqs5767z19JqD; Tue, 30 Mar 2021 16:07:05 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 30 Mar 2021 16:09:03 +0800 From: Yanan Wang To: Paolo Bonzini , Andrew Jones , , , CC: Ben Gardon , Sean Christopherson , Vitaly Kuznetsov , Peter Xu , "Ingo Molnar" , Adrian Hunter , Jiri Olsa , Arnaldo Carvalho de Melo , Arnd Bergmann , Michael Kerrisk , Thomas Gleixner , , , Yanan Wang Subject: [PATCH v6 03/10] KVM: selftests: Use flag CLOCK_MONOTONIC_RAW for timing Date: Tue, 30 Mar 2021 16:08:49 +0800 Message-ID: <20210330080856.14940-4-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210330080856.14940-1-wangyanan55@huawei.com> References: <20210330080856.14940-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.128] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In addition to function of CLOCK_MONOTONIC, flag CLOCK_MONOTONIC_RAW can also shield possiable impact of NTP, which can provide more robustness. Suggested-by: Vitaly Kuznetsov Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon Reviewed-by: Andrew Jones --- tools/testing/selftests/kvm/demand_paging_test.c | 8 ++++---- tools/testing/selftests/kvm/dirty_log_perf_test.c | 14 +++++++------- tools/testing/selftests/kvm/lib/test_util.c | 2 +- tools/testing/selftests/kvm/steal_time.c | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index 5f7a229c3af1..efbf0c1e9130 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -53,7 +53,7 @@ static void *vcpu_worker(void *data) vcpu_args_set(vm, vcpu_id, 1, vcpu_id); run = vcpu_state(vm, vcpu_id); - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(CLOCK_MONOTONIC_RAW, &start); /* Let the guest access its memory */ ret = _vcpu_run(vm, vcpu_id); @@ -86,7 +86,7 @@ static int handle_uffd_page_request(int uffd, uint64_t addr) copy.len = perf_test_args.host_page_size; copy.mode = 0; - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(CLOCK_MONOTONIC_RAW, &start); r = ioctl(uffd, UFFDIO_COPY, ©); if (r == -1) { @@ -123,7 +123,7 @@ static void *uffd_handler_thread_fn(void *arg) struct timespec start; struct timespec ts_diff; - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(CLOCK_MONOTONIC_RAW, &start); while (!quit_uffd_thread) { struct uffd_msg msg; struct pollfd pollfd[2]; @@ -336,7 +336,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) pr_info("Finished creating vCPUs and starting uffd threads\n"); - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(CLOCK_MONOTONIC_RAW, &start); for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) { pthread_create(&vcpu_threads[vcpu_id], NULL, vcpu_worker, diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c index 04a2641261be..6cff4ccf9525 100644 --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c @@ -50,7 +50,7 @@ static void *vcpu_worker(void *data) while (!READ_ONCE(host_quit)) { int current_iteration = READ_ONCE(iteration); - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(CLOCK_MONOTONIC_RAW, &start); ret = _vcpu_run(vm, vcpu_id); ts_diff = timespec_elapsed(start); @@ -141,7 +141,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) iteration = 0; host_quit = false; - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(CLOCK_MONOTONIC_RAW, &start); for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) { vcpu_last_completed_iteration[vcpu_id] = -1; @@ -162,7 +162,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) ts_diff.tv_sec, ts_diff.tv_nsec); /* Enable dirty logging */ - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(CLOCK_MONOTONIC_RAW, &start); vm_mem_region_set_flags(vm, PERF_TEST_MEM_SLOT_INDEX, KVM_MEM_LOG_DIRTY_PAGES); ts_diff = timespec_elapsed(start); @@ -174,7 +174,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) * Incrementing the iteration number will start the vCPUs * dirtying memory again. */ - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(CLOCK_MONOTONIC_RAW, &start); iteration++; pr_debug("Starting iteration %d\n", iteration); @@ -189,7 +189,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) pr_info("Iteration %d dirty memory time: %ld.%.9lds\n", iteration, ts_diff.tv_sec, ts_diff.tv_nsec); - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(CLOCK_MONOTONIC_RAW, &start); kvm_vm_get_dirty_log(vm, PERF_TEST_MEM_SLOT_INDEX, bmap); ts_diff = timespec_elapsed(start); @@ -199,7 +199,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) iteration, ts_diff.tv_sec, ts_diff.tv_nsec); if (dirty_log_manual_caps) { - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(CLOCK_MONOTONIC_RAW, &start); kvm_vm_clear_dirty_log(vm, PERF_TEST_MEM_SLOT_INDEX, bmap, 0, host_num_pages); @@ -212,7 +212,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) } /* Disable dirty logging */ - clock_gettime(CLOCK_MONOTONIC, &start); + clock_gettime(CLOCK_MONOTONIC_RAW, &start); vm_mem_region_set_flags(vm, PERF_TEST_MEM_SLOT_INDEX, 0); ts_diff = timespec_elapsed(start); pr_info("Disabling dirty logging time: %ld.%.9lds\n", diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index 906c955384e2..c7c0627c6842 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -89,7 +89,7 @@ struct timespec timespec_elapsed(struct timespec start) { struct timespec end; - clock_gettime(CLOCK_MONOTONIC, &end); + clock_gettime(CLOCK_MONOTONIC_RAW, &end); return timespec_sub(end, start); } diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c index fcc840088c91..5bc582d3f2a2 100644 --- a/tools/testing/selftests/kvm/steal_time.c +++ b/tools/testing/selftests/kvm/steal_time.c @@ -237,11 +237,11 @@ static void *do_steal_time(void *arg) { struct timespec ts, stop; - clock_gettime(CLOCK_MONOTONIC, &ts); + clock_gettime(CLOCK_MONOTONIC_RAW, &ts); stop = timespec_add_ns(ts, MIN_RUN_DELAY_NS); while (1) { - clock_gettime(CLOCK_MONOTONIC, &ts); + clock_gettime(CLOCK_MONOTONIC_RAW, &ts); if (timespec_to_ns(timespec_sub(ts, stop)) >= 0) break; } -- 2.19.1