Received: by 2002:a25:d80c:0:0:0:0:0 with SMTP id p12csp12489ybg; Tue, 23 Jun 2020 13:38:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrL+e1/F865lmWN+SyojKmcZUaZaK/2phx5tBMWr0eg9Ct2y0xIap4txfSmQRYdgjYbyxi X-Received: by 2002:a17:906:945:: with SMTP id j5mr21933911ejd.52.1592944700853; Tue, 23 Jun 2020 13:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592944700; cv=none; d=google.com; s=arc-20160816; b=yifV5FM1HLvrLrk9RBAfjoQb5vslj/QkR3jgMCySsxCm8tdodCswfvVNLWKxryGZeY JUuXBOnHuSb+mBfZauXayvqSaL61kDoupG8Y55ZD5p3HWfag42WfdOc3V78yMqLRMSG7 QmdUbm3E07H+6uqXF8/InSAq3c8H05zkLKZnuZgF5A+kXjUKOPOp4qBDpCQzk5l/lv7U fNx9EGcbqvZ+bDQwjT64R5eEmrb8AsiFXrjaSn5h8LG8ERhuEwOzmsDZpKklhKhWZTgd zKr1nWdaQ31OoX0rBDT64kOiIr8db3yJWBLRaMeXRRe30WiYMHRVE9qV+E1/81WfeNH9 mJdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=rUiCHEG4ixMC5q0G/sMhdsDeiOjcEJ6AH6URjseTZ2I=; b=dscHJZbEo0+cpn9PNuElF7WIqbRIZBPjzGaBNU2g52UGje+ksM9gl6JeLP4QfZPaBP 9X7UWPjYGNI4p+Bk+onuKqlIzwOsVybM0BtSAJxKmOD+Q9ZtXQqXRXq/Hn21uONtksdo iJcH7PJDt+DKhWJ24Mi2k5zC0TQKCszQukzoZ2enWmsLG7vzJywe/V0KktYG7CVEkk4i UroTcT3DLmLjImU3Ef3mLYG2NIIV2zGDVdG02SJneRJPh+DqIG6UCTmHIShLoTMMKEH4 C70r921bko7XtEaezoU8ML29/SxWCgDgAeYGN0kGdTQG8hQlad9r1fd533MYXXXimLEV M+vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jS7aQ3o7; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gt15si4980296ejb.747.2020.06.23.13.37.57; Tue, 23 Jun 2020 13:38:20 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=jS7aQ3o7; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403778AbgFWUeh (ORCPT + 99 others); Tue, 23 Jun 2020 16:34:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391546AbgFWUeb (ORCPT ); Tue, 23 Jun 2020 16:34:31 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2272C061573 for ; Tue, 23 Jun 2020 13:34:31 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id i25so25528713iog.0 for ; Tue, 23 Jun 2020 13:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rUiCHEG4ixMC5q0G/sMhdsDeiOjcEJ6AH6URjseTZ2I=; b=jS7aQ3o7RZ0sGf7Y6qNQMZ73+JgsgYaV6djG8um9Xh0EJx3rlZHQq9i1WM8uSYY7L7 3UuWr3RTyQQALhaPmjJFrCRQWjiA4oyuIkj4MrE8gCT+yjWOo4+QFz6XBPeWMRkjR0B6 S44OQf0pHhD2hYe/8iFO/qAepNbPD7AZjGmUFicmouMAuAB2eZPuMG0B5qTmXtU88viJ d7nXJ1B8DACEohbJSj4vQuwC1qEnZH9y84RQSEguVuQw6/GIJ169SJKIppfkb4QCpRFT fOLmxWuc5o4LyfCm3z6PgWlob05vqqzyCsxClnr3yIx+iOUf2zUAN9kR3ZTBtC+DN3lW MGzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rUiCHEG4ixMC5q0G/sMhdsDeiOjcEJ6AH6URjseTZ2I=; b=F1rgPxP8boZ5cZrtybVNjXhFO8OnELDeZxpj8FVvb+XIWYVclamIcfJwHK7uSOmj3O P+uB0RYULJbjcitEFp3FbZ0+PsUIvwgAP9QBQQCkrC7DQyXsQYDnwbdMsXNEly+Dhcyk Tv/8Gt1qebgAhv0/0UFy7E8+VRMS5t0mB/PdOrDIXAIf7B6551R25CFFrfiiHDsyGov3 MkIXN9uFYDfpa2Sgse4sKO9oKxSMPwh8jJyaTRcpOENbtkZCY2wL7Qb8ZB/qFIkP/VLh zz49QXuxluM0JPCkXJqN+mCPvhO86N+btBYvme71d2RUE94i6je5ewYfJP62D0N8Bd2d h8pg== X-Gm-Message-State: AOAM533jpcGdkozJRGOtRR2iujOidT7427QJUtAN1x1c4foNxJ3e2hlh yRWeuzEuo6sALjjpLYRxMQyQj9H0hbEUKLRBsPxbCw== X-Received: by 2002:a05:6638:979:: with SMTP id o25mr24234722jaj.24.1592944471021; Tue, 23 Jun 2020 13:34:31 -0700 (PDT) MIME-Version: 1.0 References: <20200623063530.81917-1-like.xu@linux.intel.com> <20200623182910.GA24107@linux.intel.com> <20200623190504.GC24107@linux.intel.com> In-Reply-To: <20200623190504.GC24107@linux.intel.com> From: Jim Mattson Date: Tue, 23 Jun 2020 13:34:19 -0700 Message-ID: Subject: Re: [PATCH] KVM: X86: Emulate APERF/MPERF to report actual VCPU frequency To: Sean Christopherson Cc: Like Xu , Paolo Bonzini , kvm list , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , wei.huang2@amd.com, Peter Zijlstra , Thomas Gleixner , LKML , Li RongQing , Chai Wen , Jia Lina Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 23, 2020 at 12:05 PM Sean Christopherson wrote: > > On Tue, Jun 23, 2020 at 11:39:16AM -0700, Jim Mattson wrote: > > On Tue, Jun 23, 2020 at 11:29 AM Sean Christopherson > > wrote: > > > > > > On Tue, Jun 23, 2020 at 02:35:30PM +0800, Like Xu wrote: > > > > The aperf/mperf are used to report current CPU frequency after 7d5905dc14a > > > > "x86 / CPU: Always show current CPU frequency in /proc/cpuinfo". But guest > > > > kernel always reports a fixed VCPU frequency in the /proc/cpuinfo, which > > > > may confuse users especially when turbo is enabled on the host. > > > > > > > > Emulate guest APERF/MPERF capability based their values on the host. > > > > > > > > Co-developed-by: Li RongQing > > > > Signed-off-by: Li RongQing > > > > Reviewed-by: Chai Wen > > > > Reviewed-by: Jia Lina > > > > Signed-off-by: Like Xu > > > > --- > > > > > > ... > > > > > > > @@ -8312,7 +8376,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > > > > dm_request_for_irq_injection(vcpu) && > > > > kvm_cpu_accept_dm_intr(vcpu); > > > > fastpath_t exit_fastpath; > > > > - > > > > + u64 enter_mperf = 0, enter_aperf = 0, exit_mperf = 0, exit_aperf = 0; > > > > bool req_immediate_exit = false; > > > > > > > > if (kvm_request_pending(vcpu)) { > > > > @@ -8516,8 +8580,17 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > > > > vcpu->arch.switch_db_regs &= ~KVM_DEBUGREG_RELOAD; > > > > } > > > > > > > > + if (unlikely(vcpu->arch.hwp.hw_coord_fb_cap)) > > > > + get_host_amperf(&enter_mperf, &enter_aperf); > > > > + > > > > exit_fastpath = kvm_x86_ops.run(vcpu); > > > > > > > > + if (unlikely(vcpu->arch.hwp.hw_coord_fb_cap)) { > > > > + get_host_amperf(&exit_mperf, &exit_aperf); > > > > + vcpu_update_amperf(vcpu, get_amperf_delta(enter_aperf, exit_aperf), > > > > + get_amperf_delta(enter_mperf, exit_mperf)); > > > > + } > > > > + > > > > > > Is there an alternative approach that doesn't require 4 RDMSRs on every VMX > > > round trip? That's literally more expensive than VM-Enter + VM-Exit > > > combined. > > > > > > E.g. what about adding KVM_X86_DISABLE_EXITS_APERF_MPERF and exposing the > > > MSRs for read when that capability is enabled? > > > > When would you load the hardware MSRs with the guest/host values? > > Ugh, I was thinking the MSRs were read-only. EVen if they were read-only, they should power on to zero, and they will most likely not be zero when a guest powers on. > Doesn't this also interact with TSC scaling? Yes, it should!