kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[]
@ 2020-12-30  8:19 Like Xu
  2021-01-15  8:46 ` Like Xu
  2021-01-18 17:57 ` Paolo Bonzini
  0 siblings, 2 replies; 6+ messages in thread
From: Like Xu @ 2020-12-30  8:19 UTC (permalink / raw)
  To: Paolo Bonzini, Stephane Eranian
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel

The HW_REF_CPU_CYCLES event on the fixed counter 2 is pseudo-encoded as
0x0300 in the intel_perfmon_event_map[]. Correct its usage.

Fixes: 62079d8a4312 ("KVM: PMU: add proper support for fixed counter 2")
Signed-off-by: Like Xu <like.xu@linux.intel.com>
---
 arch/x86/kvm/vmx/pmu_intel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
index a886a47daebd..013e8d253dfa 100644
--- a/arch/x86/kvm/vmx/pmu_intel.c
+++ b/arch/x86/kvm/vmx/pmu_intel.c
@@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
 	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
 	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
 	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
-	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
+	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },
 };
 
 /* mapping between fixed pmc index and intel_arch_events array */
-- 
2.29.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[]
  2020-12-30  8:19 [PATCH] KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[] Like Xu
@ 2021-01-15  8:46 ` Like Xu
  2021-01-15 17:30   ` Sean Christopherson
  2021-01-18 17:57 ` Paolo Bonzini
  1 sibling, 1 reply; 6+ messages in thread
From: Like Xu @ 2021-01-15  8:46 UTC (permalink / raw)
  To: Paolo Bonzini, Stephane Eranian, Sean Christopherson
  Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
	linux-kernel

Ping ?

On 2020/12/30 16:19, Like Xu wrote:
> The HW_REF_CPU_CYCLES event on the fixed counter 2 is pseudo-encoded as
> 0x0300 in the intel_perfmon_event_map[]. Correct its usage.
>
> Fixes: 62079d8a4312 ("KVM: PMU: add proper support for fixed counter 2")
> Signed-off-by: Like Xu <like.xu@linux.intel.com>
> ---
>   arch/x86/kvm/vmx/pmu_intel.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
> index a886a47daebd..013e8d253dfa 100644
> --- a/arch/x86/kvm/vmx/pmu_intel.c
> +++ b/arch/x86/kvm/vmx/pmu_intel.c
> @@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
>   	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
>   	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
>   	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
> -	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
> +	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },
>   };
>   
>   /* mapping between fixed pmc index and intel_arch_events array */


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[]
  2021-01-15  8:46 ` Like Xu
@ 2021-01-15 17:30   ` Sean Christopherson
  2021-01-18  4:40     ` Xu, Like
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Christopherson @ 2021-01-15 17:30 UTC (permalink / raw)
  To: Like Xu
  Cc: Paolo Bonzini, Stephane Eranian, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel, kvm, linux-kernel

On Fri, Jan 15, 2021, Like Xu wrote:
> Ping ?
> 
> On 2020/12/30 16:19, Like Xu wrote:
> > The HW_REF_CPU_CYCLES event on the fixed counter 2 is pseudo-encoded as
> > 0x0300 in the intel_perfmon_event_map[]. Correct its usage.
> > 
> > Fixes: 62079d8a4312 ("KVM: PMU: add proper support for fixed counter 2")
> > Signed-off-by: Like Xu <like.xu@linux.intel.com>

Reviewed-by: Sean Christopherson <seanjc@google.com> 

> > ---
> >   arch/x86/kvm/vmx/pmu_intel.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
> > index a886a47daebd..013e8d253dfa 100644
> > --- a/arch/x86/kvm/vmx/pmu_intel.c
> > +++ b/arch/x86/kvm/vmx/pmu_intel.c
> > @@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
> >   	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
> >   	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
> >   	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
> > -	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
> > +	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },

In a follow up patch, would it be sane/appropriate to define these magic numbers
in asm/perf_event.h and share them between intel_perfmon_event_map and
intel_arch_events?  Without this patch, it's not at all obvious that these are
intended to align with the Core (arch?) event definitions.

> >   };
> >   /* mapping between fixed pmc index and intel_arch_events array */
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[]
  2021-01-15 17:30   ` Sean Christopherson
@ 2021-01-18  4:40     ` Xu, Like
  2021-01-20  1:13       ` Sean Christopherson
  0 siblings, 1 reply; 6+ messages in thread
From: Xu, Like @ 2021-01-18  4:40 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini
  Cc: Stephane Eranian, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel, Like Xu

On 2021/1/16 1:30, Sean Christopherson wrote:
> On Fri, Jan 15, 2021, Like Xu wrote:
>> Ping ?
>>
>> On 2020/12/30 16:19, Like Xu wrote:
>>> The HW_REF_CPU_CYCLES event on the fixed counter 2 is pseudo-encoded as
>>> 0x0300 in the intel_perfmon_event_map[]. Correct its usage.
>>>
>>> Fixes: 62079d8a4312 ("KVM: PMU: add proper support for fixed counter 2")
>>> Signed-off-by: Like Xu <like.xu@linux.intel.com>
> Reviewed-by: Sean Christopherson <seanjc@google.com>
thx.
>
>>> ---
>>>    arch/x86/kvm/vmx/pmu_intel.c | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
>>> index a886a47daebd..013e8d253dfa 100644
>>> --- a/arch/x86/kvm/vmx/pmu_intel.c
>>> +++ b/arch/x86/kvm/vmx/pmu_intel.c
>>> @@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
>>>    	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
>>>    	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
>>>    	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
>>> -	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
>>> +	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },
> In a follow up patch, would it be sane/appropriate to define these magic numbers
> in asm/perf_event.h and share them between intel_perfmon_event_map and
> intel_arch_events?  Without this patch, it's not at all obvious that these are
> intended to align with the Core (arch?) event definitions.

The asm/perf_event.h is x86 generic and svm has a amd_perfmon_event_map.

How about adding an interface similar to perf_get_x86_pmu_capability()
so that we can use magic numbers directly from the host perf ?
(it looks we may have a performance drop, compared to static array)

---
thx, likexu

>
>>>    };
>>>    /* mapping between fixed pmc index and intel_arch_events array */


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[]
  2020-12-30  8:19 [PATCH] KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[] Like Xu
  2021-01-15  8:46 ` Like Xu
@ 2021-01-18 17:57 ` Paolo Bonzini
  1 sibling, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2021-01-18 17:57 UTC (permalink / raw)
  To: Like Xu, Stephane Eranian
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel

On 30/12/20 09:19, Like Xu wrote:
> The HW_REF_CPU_CYCLES event on the fixed counter 2 is pseudo-encoded as
> 0x0300 in the intel_perfmon_event_map[]. Correct its usage.
> 
> Fixes: 62079d8a4312 ("KVM: PMU: add proper support for fixed counter 2")
> Signed-off-by: Like Xu <like.xu@linux.intel.com>
> ---
>   arch/x86/kvm/vmx/pmu_intel.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
> index a886a47daebd..013e8d253dfa 100644
> --- a/arch/x86/kvm/vmx/pmu_intel.c
> +++ b/arch/x86/kvm/vmx/pmu_intel.c
> @@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
>   	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
>   	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
>   	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
> -	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
> +	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },
>   };
>   
>   /* mapping between fixed pmc index and intel_arch_events array */
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[]
  2021-01-18  4:40     ` Xu, Like
@ 2021-01-20  1:13       ` Sean Christopherson
  0 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2021-01-20  1:13 UTC (permalink / raw)
  To: Xu, Like
  Cc: Paolo Bonzini, Stephane Eranian, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel, kvm, linux-kernel, Like Xu

On Mon, Jan 18, 2021, Xu, Like wrote:
> On 2021/1/16 1:30, Sean Christopherson wrote:
> > On Fri, Jan 15, 2021, Like Xu wrote:
> > > > diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
> > > > index a886a47daebd..013e8d253dfa 100644
> > > > --- a/arch/x86/kvm/vmx/pmu_intel.c
> > > > +++ b/arch/x86/kvm/vmx/pmu_intel.c
> > > > @@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
> > > >    	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
> > > >    	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
> > > >    	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
> > > > -	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
> > > > +	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },
> > In a follow up patch, would it be sane/appropriate to define these magic numbers
> > in asm/perf_event.h and share them between intel_perfmon_event_map and
> > intel_arch_events?  Without this patch, it's not at all obvious that these are
> > intended to align with the Core (arch?) event definitions.
> 
> The asm/perf_event.h is x86 generic and svm has a amd_perfmon_event_map.

Ugh, duh.

> How about adding an interface similar to perf_get_x86_pmu_capability()
> so that we can use magic numbers directly from the host perf ?
> (it looks we may have a performance drop, compared to static array)

Alternatively, you could use the existing event_map() to generate
intel_arch_events[] during init.  That might be easier since, AFAICT, the array
indices have different meaning for KVM than for perf.

Honestly, unless there are going to be new arch events in the near-ish future,
it may not be worth the effort at this point.  Until now, the above table hadn't
changed in over five years.  I.e. don't put a bunch of effort into this unless
you want to :-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-20  1:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-30  8:19 [PATCH] KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[] Like Xu
2021-01-15  8:46 ` Like Xu
2021-01-15 17:30   ` Sean Christopherson
2021-01-18  4:40     ` Xu, Like
2021-01-20  1:13       ` Sean Christopherson
2021-01-18 17:57 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).