Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3820724ybt; Tue, 23 Jun 2020 11:30:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0qSWgWmjiW3/9lPn9vir3v3e745ZHwfrcSCYmEyadS4xL0DP4BgrGK7vp0Puw+hT9ZEqV X-Received: by 2002:a50:e606:: with SMTP id y6mr17522811edm.303.1592937040845; Tue, 23 Jun 2020 11:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592937040; cv=none; d=google.com; s=arc-20160816; b=ZD5f0jzSVvu50xqeD5NBEAuDnuNuEfpGQoMcvEk0YUlIbhClBZ5tm9RJWWWT9xB79w iLVDPHkr/JNPxtP3yG9Q9QelwoO2jnIoJZdC9uAmE0cMNNtq2BjcSGlJxGUeEI1UiJUc moGqwKke3PAUw1Z+i/OMhQFjs/DWu5wwb82gVgLt2967lgn1oJwnqSsx0JFAVmf+frl7 QyG1NavHpqicmagJDv0tM6+KEIlqd/jL4lVaL2+McIEJj6YL5d+LUf/J22ZxZ1Un5G9m eEKvtteX61qKRbxbYQPh+BlSPoDQpan3ruVbkDvU/tEvFiz1usSbEizOB9FotbcVDDC5 cvrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=N4uvHQPLohQFKaW+tw00ZPuFyQN5HEWuKwZcAzqiWvk=; b=Gbw8KEOlgV3AqhQD8cSXfaSaWiK/iXk1QS6QHgPJwJrRo244pUZF35dlqSDh5pPEBE g803rLRadLghm/nwQwqbmCY7W5EaBMW+acBN8XxPK5CSIRV4fLWl2w/g3Ps8/vDNsqMK g1IrXS/4zQaZ3RDzjD4GYejHG3gV9nRV4sTYyXYifvf3KBqPPNiBRIgE1/Ub+K1d7J5p WdWkuN9x+I9ndXrGz8YnWCy0TtBXRsMRQqHJXTtHBJpzLZtQVxb6oNoPQtuHrnNT6glV wr8Utg0tg8p/rpmVI1gRjWgdUcFz01hWQnMQatUuAkP1p6EDbYhYcer/cObFDIajaKOE ZCyg== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q24si5320285edw.193.2020.06.23.11.30.18; Tue, 23 Jun 2020 11:30:40 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733151AbgFWS3a (ORCPT + 99 others); Tue, 23 Jun 2020 14:29:30 -0400 Received: from mga17.intel.com ([192.55.52.151]:45799 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387476AbgFWS3M (ORCPT ); Tue, 23 Jun 2020 14:29:12 -0400 IronPort-SDR: xMEBZiOUvMMmBLBG3ZIR9MeYDLHTeTJVBNxpumNDavVhsI7QV0E7nwuW7wY9CfkbzW3GmwZ2uv gfvXHpVv3b1g== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="124427886" X-IronPort-AV: E=Sophos;i="5.75,272,1589266800"; d="scan'208";a="124427886" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2020 11:29:11 -0700 IronPort-SDR: BPpIr7ZbUhLbIiM0sqnLbwkHOmTPNLMCVvSPxNbsbwcsxhJyV4o8yFG8nykExF0PsDu6EYhB1l 7BNQd69uXl3A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,272,1589266800"; d="scan'208";a="275431860" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.152]) by orsmga003.jf.intel.com with ESMTP; 23 Jun 2020 11:29:10 -0700 Date: Tue, 23 Jun 2020 11:29:10 -0700 From: Sean Christopherson To: Like Xu Cc: Paolo Bonzini , kvm@vger.kernel.org, Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , wei.huang2@amd.com, Peter Zijlstra , Thomas Gleixner , linux-kernel@vger.kernel.org, Li RongQing , Chai Wen , Jia Lina Subject: Re: [PATCH] KVM: X86: Emulate APERF/MPERF to report actual VCPU frequency Message-ID: <20200623182910.GA24107@linux.intel.com> References: <20200623063530.81917-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200623063530.81917-1-like.xu@linux.intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) 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 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?