Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1017862rdg; Wed, 11 Oct 2023 11:47:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEaN/AJfWBh6IRYX+sowt5501+hxaW/ZWzsEugJwfbhzwuJ3z/924gX7RGZqMVTgu5Nlh+Y X-Received: by 2002:a05:6870:b4ac:b0:1e9:a8f0:d6b6 with SMTP id y44-20020a056870b4ac00b001e9a8f0d6b6mr1132891oap.39.1697050065783; Wed, 11 Oct 2023 11:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697050065; cv=none; d=google.com; s=arc-20160816; b=m0PRj2wx8wI1Q456n+m11DyN+mQL/MmzBGXdmqR2muAXRSuKgseqSTv2Ojm0esVeKb R9TnStSwwBUS1PJLd5i1ChK5YseA7g0vXGFGoAc7E+0rbjb8HZqYkbGs5yULO9smhkNU ozTakIIV2rYB/qyhlcRMlQ5vnllBb9dZYpbqRqfzH4/VY6hKowQxLLwHXLoexdL2Fk0+ 2uMFm9y+8FOZxj5F8chgP0LCG1GIUewoOPjN0IcVK78JoUN3+SDm99cUGYJje1lGmmzn E5wnpOt5fY/fUJGDzuArs+5zJOR0gf3RWBpCG/J1wnRIR5CEwndO3Ed4AkEeCb/uLksg TMoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=5HrWpP5EB4erpGzchcXAhQqrC/kAkv5vgdG0+5+I30o=; fh=g4/GheqWGbfPSpbH1bjmHex5/H11mfCZmE/qP1zKNvw=; b=whfkIkz7iCT3yYleTFs6wFQTJoA6j70n9HDBUy/0ei2RjD5n6KQObEi5O7B1EH/OM+ U4uUvniur6O+dcgKeAf/3RC9XEg9SxIxtPWRHAXZKRdwxKgLFSikSs16TYA6Mz4omLnF kCi6pD+II8oodMEc55nR371+5oH+VikjvIAUrIcWADpYRN7HddJkjoJl85ExYB/br2C5 CG+DCwXOxfne6YPRWEUalwBb3WZiDSx46nFc5Q/lNzXrvN60n4YowWb+O2R/Dnh5YEO/ FK9D/VOqBfTiAekXDsRizjoN3fqN7z3NWWWjKyQQQ3FGNsLYjYeTv2vHH1BIFL6HD8LE Ou+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gCnD0oUO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id 22-20020a631956000000b00578e5228c76si283811pgz.505.2023.10.11.11.47.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 11:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gCnD0oUO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 81F7781CC857; Wed, 11 Oct 2023 11:47:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233159AbjJKSrk (ORCPT + 99 others); Wed, 11 Oct 2023 14:47:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233081AbjJKSrj (ORCPT ); Wed, 11 Oct 2023 14:47:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BE4990 for ; Wed, 11 Oct 2023 11:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697050010; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5HrWpP5EB4erpGzchcXAhQqrC/kAkv5vgdG0+5+I30o=; b=gCnD0oUOHLPATekyG09R/HhGfKz6uGZih+xTZ1xuz3x94atJ/jyK3uJ46DlwQzocbUIVnT i6HnoBhiD8jbbbXBvVDeh0tJpQ5MndMDLRIkPwSmilfe9H5ytp3fx1+uz2O7fkdSEATQpU cwHaPuXVK0IMbCJxc3Mfe/6EjNN+poc= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-459-4AVg9E1dOj2hglwmI15WKA-1; Wed, 11 Oct 2023 14:46:48 -0400 X-MC-Unique: 4AVg9E1dOj2hglwmI15WKA-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-32d8872a122so66019f8f.2 for ; Wed, 11 Oct 2023 11:46:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697050008; x=1697654808; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5HrWpP5EB4erpGzchcXAhQqrC/kAkv5vgdG0+5+I30o=; b=iLzEM4AdriqnB0aUywg4wR5+2IyPYPrp3qfTGQjTz0psewdLdSfticNHdELCadum4S racG0oGuqMOPz5sQsNEmL7GN17BYb8wla0bFtZDBRr5YDBkxzAPpNwJ4n90X6AWb3Fhf CoYnSUtRqMiK/FFRov/99ONHjlvOS9K403vMqaakmi3BlQDbdQLrFELPeCli5BkpLVa7 f0A0roUQdj43RkihWswiltpzy3Hg62VCQoA7uj9eQU/Bl+NibYmPfj1+LE3GhqMVjost 0+IbKo7wXMs55q3TpTXbYcS1bcj28g3Xze6ums47HSIGjzltddC2zTzaOyhZ4cRBq6TB EMhQ== X-Gm-Message-State: AOJu0Yxll2xa8FTXqlCqJAZsKobcNQ98mCPVE1W2JrFXCIeTX6HrHvLK A6vd8phNFkN+cQna1GWCJeZj7wN5A9G3omfVnjCF45MZefpR13sxNILG+LMpm+6l74JguH242oD qmSeD/1kZELnSL1yamYvMlxXM X-Received: by 2002:adf:f48e:0:b0:324:8239:2873 with SMTP id l14-20020adff48e000000b0032482392873mr21034208wro.37.1697050007822; Wed, 11 Oct 2023 11:46:47 -0700 (PDT) X-Received: by 2002:adf:f48e:0:b0:324:8239:2873 with SMTP id l14-20020adff48e000000b0032482392873mr21034195wro.37.1697050007464; Wed, 11 Oct 2023 11:46:47 -0700 (PDT) Received: from starship ([89.237.100.246]) by smtp.gmail.com with ESMTPSA id bv28-20020a0560001f1c00b0032d402f816csm5004673wrb.98.2023.10.11.11.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 11:46:47 -0700 (PDT) Message-ID: Subject: Re: [PATCH 1/1] selftests: KVM: add test to print boottime wallclock From: Maxim Levitsky To: Dongli Zhang , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, pbonzini@redhat.com, shuah@kernel.org, seanjc@google.com, dwmw2@infradead.org, joe.jin@oracle.com Date: Wed, 11 Oct 2023 21:46:45 +0300 In-Reply-To: <2604fa79-b114-60d9-c28d-0d53cd0dc5c7@oracle.com> References: <20231006175715.105517-1-dongli.zhang@oracle.com> <7c2a77bb3ec9f85f684218eb80654adcdfefd60d.camel@redhat.com> <2604fa79-b114-60d9-c28d-0d53cd0dc5c7@oracle.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 11 Oct 2023 11:47:44 -0700 (PDT) У вт, 2023-10-10 у 09:31 -0700, Dongli Zhang пише: > Hi Maxim, > > On 10/10/23 09:13, Maxim Levitsky wrote: > > У пт, 2023-10-06 у 10:57 -0700, Dongli Zhang пише: > > > As inspired by the discussion in [1], the boottime wallclock may drift due > > > to the fact that the masterclock (or host monotonic clock) and kvmclock are > > > calculated based on the algorithms in different domains. > > > > > > This is to introduce a testcase to print the boottime wallclock > > > periodically to help diagnose the wallclock drift issue in the future. > > > > > > The idea is to wrmsr the MSR_KVM_WALL_CLOCK_NEW, and read the boottime > > > wallclock nanoseconds immediately. > > > > > > References: > > > [1] https://urldefense.com/v3/__https://lore.kernel.org/all/20231001111313.77586-1-nsaenz@amazon.com__;!!ACWV5N9M2RV99hQ!MOnoujF4PlfvZ3SUuyXgIpJC5mWiE5uLUsNW6AWgirGXcObN5uil_fnthRVcYaPA0N2uoNyLChBogHC7ZS6t$ > > > > > > Cc: David Woodhouse > > > Signed-off-by: Dongli Zhang > > > --- > > > tools/testing/selftests/kvm/Makefile | 3 +- > > > .../selftests/kvm/x86_64/boottime_wallclock.c | 100 ++++++++++++++++++ > > > 2 files changed, 102 insertions(+), 1 deletion(-) > > > create mode 100644 tools/testing/selftests/kvm/x86_64/boottime_wallclock.c > > > > > > diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile > > > index a3bb36fb3cfc..fea05b0118de 100644 > > > --- a/tools/testing/selftests/kvm/Makefile > > > +++ b/tools/testing/selftests/kvm/Makefile > > > @@ -60,7 +60,8 @@ LIBKVM_riscv += lib/riscv/ucall.c > > > TEST_PROGS_x86_64 += x86_64/nx_huge_pages_test.sh > > > > > > # Compiled test targets > > > -TEST_GEN_PROGS_x86_64 = x86_64/cpuid_test > > > +TEST_GEN_PROGS_x86_64 = x86_64/boottime_wallclock > > > +TEST_GEN_PROGS_x86_64 += x86_64/cpuid_test > > > TEST_GEN_PROGS_x86_64 += x86_64/cr4_cpuid_sync_test > > > TEST_GEN_PROGS_x86_64 += x86_64/dirty_log_page_splitting_test > > > TEST_GEN_PROGS_x86_64 += x86_64/get_msr_index_features > > > diff --git a/tools/testing/selftests/kvm/x86_64/boottime_wallclock.c b/tools/testing/selftests/kvm/x86_64/boottime_wallclock.c > > > new file mode 100644 > > > index 000000000000..cc48c9b19920 > > > --- /dev/null > > > +++ b/tools/testing/selftests/kvm/x86_64/boottime_wallclock.c > > > @@ -0,0 +1,100 @@ > > > +// SPDX-License-Identifier: GPL-2.0-only > > > +/* > > > + * Copyright (C) 2023 Oracle and/or its affiliates. > > > + */ > > > + > > > +#include > > > +#include > > > + > > > +#include "kvm_util.h" > > > +#include "processor.h" > > > + > > > +static int period = 10; > > > + > > > +#define GUEST_SYNC_WALLCLOCK(__stage, __val) \ > > > + GUEST_SYNC_ARGS(__stage, __val, 0, 0, 0) > > > + > > > +static void guest_main(vm_paddr_t wc_pa, struct pvclock_wall_clock *wc) > > > +{ > > > + uint64_t wallclock; > > > + > > > + while (true) { > > > + wrmsr(MSR_KVM_WALL_CLOCK_NEW, wc_pa); > > > + > > > + wallclock = wc->sec * NSEC_PER_SEC + wc->nsec; > > > + > > > + GUEST_SYNC_WALLCLOCK(0, wallclock); > > > > Won't this fill the output very fast? > > Do you think it will be worth it to wait some time (e.g 1 second or at least 1/10 of a second) > > between each print? > > The wait time is controlled by the VMM side (of selftest) as in below. > > In the while loop at VMM side, it sleeps for a period (configurable argument), > until it runs into the guest again. > > Therefore, the user can decide the frequency to print the boottime wallclock. Sorry about this, I haven't noticed this code! Best regards, Maxim Levitsky > > +static void enter_guest(struct kvm_vcpu *vcpu) > +{ > + struct ucall uc; > + > + while (true) { > + vcpu_run(vcpu); -----------> to schedule guest vcpu here > + > + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); > + > + switch (get_ucall(vcpu, &uc)) { > + case UCALL_SYNC: > + handle_sync(&uc); > + break; > + case UCALL_ABORT: > + handle_abort(&uc); > + return; > + default: > + TEST_ASSERT(0, "unhandled ucall: %ld\n", uc.cmd); > + return; > + } > + > + sleep(period); ------------> sleep here > + } > +} > > Thank you very much! > > Dongli Zhang > > > > + } > > > +} > > > + > > > +static void handle_sync(struct ucall *uc) > > > +{ > > > + uint64_t wallclock; > > > + > > > + wallclock = uc->args[2]; > > > + > > > + pr_info("Boottime wallclock value: %"PRIu64" ns\n", wallclock); > > > +} > > > + > > > +static void handle_abort(struct ucall *uc) > > > +{ > > > + REPORT_GUEST_ASSERT(*uc); > > > +} > > > + > > > +static void enter_guest(struct kvm_vcpu *vcpu) > > > +{ > > > + struct ucall uc; > > > + > > > + while (true) { > > > + vcpu_run(vcpu); > > > + > > > + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); > > > + > > > + switch (get_ucall(vcpu, &uc)) { > > > + case UCALL_SYNC: > > > + handle_sync(&uc); > > > + break; > > > + case UCALL_ABORT: > > > + handle_abort(&uc); > > > + return; > > > + default: > > > + TEST_ASSERT(0, "unhandled ucall: %ld\n", uc.cmd); > > > + return; > > > + } > > > + > > > + sleep(period); > > > + } > > > +} > > > + > > > +int main(int argc, char *argv[]) > > > +{ > > > + struct kvm_vcpu *vcpu; > > > + struct kvm_vm *vm; > > > + vm_vaddr_t wc_gva; > > > + vm_paddr_t wc_gpa; > > > + int opt; > > > + > > > + while ((opt = getopt(argc, argv, "p:h")) != -1) { > > > + switch (opt) { > > > + case 'p': > > > + period = atoi_positive("The period (seconds)", optarg); > > > + break; > > > + case 'h': > > > + default: > > > + pr_info("usage: %s [-p period (seconds)]\n", argv[0]); > > > + exit(1); > > > + } > > > + } > > > + > > > + pr_info("Capture boottime wallclock every %d seconds.\n", period); > > > + pr_info("Stop with Ctrl + c.\n\n"); > > > + > > > + vm = vm_create_with_one_vcpu(&vcpu, guest_main); > > > + > > > + wc_gva = vm_vaddr_alloc(vm, getpagesize(), 0x10000); > > > + wc_gpa = addr_gva2gpa(vm, wc_gva); > > > + vcpu_args_set(vcpu, 2, wc_gpa, wc_gva); > > > + > > > + enter_guest(vcpu); > > > + kvm_vm_free(vm); > > > +} > > > > Best regards, > > Maxim Levitsky > > > >