From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH 7/9] KVM: Expose the architectural performance monitoring CPUID leaf Date: Tue, 1 Nov 2011 13:25:09 +0200 Message-ID: <20111101112509.GU17571@redhat.com> References: <1319993624-20247-1-git-send-email-gleb@redhat.com> <1319993624-20247-8-git-send-email-gleb@redhat.com> <4EAFCF49.2070508@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, mtosatti@redhat.com, mingo@elte.hu, a.p.zijlstra@chello.nl, acme@ghostprotocols.net To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:54945 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753942Ab1KAMEv (ORCPT ); Tue, 1 Nov 2011 08:04:51 -0400 Content-Disposition: inline In-Reply-To: <4EAFCF49.2070508@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Nov 01, 2011 at 12:51:53PM +0200, Avi Kivity wrote: > On 10/30/2011 06:53 PM, Gleb Natapov wrote: > > From: Avi Kivity > > > > Provide a CPUID leaf that describes the emulated PMU. > > > > Signed-off-by: Avi Kivity > > Signed-off-by: Gleb Natapov > > --- > > arch/x86/kvm/x86.c | 23 ++++++++++++++++++++++- > > 1 files changed, 22 insertions(+), 1 deletions(-) > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 5ea4cb8..56153a9 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -2543,6 +2543,28 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, > > } > > case 9: > > break; > > + case 0xa: { /* Architectural Performance Monitoring */ > > + struct x86_pmu_capability cap; > > + > > + perf_get_x86_pmu_capability(&cap); > > + > > + /* > > + * Only support guest architectural pmu on a host > > + * with architectural pmu. > > + */ > > + if (!cap.version) > > + memset(&cap, 0, sizeof(cap)); > > + > > + entry->eax = min(cap.version, 2) > > + | (cap.num_counters_gp << 8) > > + | (cap.bit_width_gp << 16) > > + | (cap.events_mask_len << 24); > > What if num_counters_gp is larger than our array? > I am using perf defines for array sizes (X86_PMC_MAX_(GENERIC|FIXED)) and perf takes care of checking num_counters_(gp|fixed) boundaries for us. > > + entry->ebx = cap.events_mask; > > + entry->ecx = 0; > > + entry->edx = cap.num_counters_fixed > > + | (cap.bit_width_fixed << 5); > > Ditto. > -- Gleb.