linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: shannon.zhao@linaro.org (Shannon Zhao)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v10 07/21] KVM: ARM64: PMU: Add perf event map and introduce perf event creating function
Date: Fri, 29 Jan 2016 21:11:10 +0800	[thread overview]
Message-ID: <56AB64EE.5080305@linaro.org> (raw)
In-Reply-To: <20160129101812.GB4541@arm.com>



On 2016/1/29 18:18, Will Deacon wrote:
> On Fri, Jan 29, 2016 at 02:26:31PM +0800, Shannon Zhao wrote:
>> >
>> >
>> >On 2016/1/29 2:06, Will Deacon wrote:
>>> > >On Thu, Jan 28, 2016 at 04:45:36PM +0000, Marc Zyngier wrote:
>>>>> > >> >On 28/01/16 16:31, Andrew Jones wrote:
>>>>>>> > >>> > >On Wed, Jan 27, 2016 at 11:51:35AM +0800, Shannon Zhao wrote:
>>>>>>>>> > >>>> > >>From: Shannon Zhao<shannon.zhao@linaro.org>
>>>>>>>>> > >>>> > >>
>>>>>>>>> > >>>> > >>When we use tools like perf on host, perf passes the event type and the
>>>>>>>>> > >>>> > >>id of this event type category to kernel, then kernel will map them to
>>>>>>>>> > >>>> > >>hardware event number and write this number to PMU PMEVTYPER<n>_EL0
>>>>>>>>> > >>>> > >>register. When getting the event number in KVM, directly use raw event
>>>>>>>>> > >>>> > >>type to create a perf_event for it.
>>>>>>>>> > >>>> > >>
>>>>>>>>> > >>>> > >>Signed-off-by: Shannon Zhao<shannon.zhao@linaro.org>
>>>>>>>>> > >>>> > >>Reviewed-by: Marc Zyngier<marc.zyngier@arm.com>
>>>>>>>>> > >>>> > >>---
>>>>>>>>> > >>>> > >>  arch/arm64/include/asm/pmu.h |   3 ++
>>>>>>>>> > >>>> > >>  arch/arm64/kvm/Makefile      |   1 +
>>>>>>>>> > >>>> > >>  include/kvm/arm_pmu.h        |  10 ++++
>>>>>>>>> > >>>> > >>  virt/kvm/arm/pmu.c           | 122 +++++++++++++++++++++++++++++++++++++++++++
>>>>>>>>> > >>>> > >>  4 files changed, 136 insertions(+)
>>>>>>>>> > >>>> > >>  create mode 100644 virt/kvm/arm/pmu.c
>>>>>>>>> > >>>> > >>
>>>>>>>>> > >>>> > >>diff --git a/arch/arm64/include/asm/pmu.h b/arch/arm64/include/asm/pmu.h
>>>>>>>>> > >>>> > >>index 4406184..2588f9c 100644
>>>>>>>>> > >>>> > >>--- a/arch/arm64/include/asm/pmu.h
>>>>>>>>> > >>>> > >>+++ b/arch/arm64/include/asm/pmu.h
>>>>>>>>> > >>>> > >>@@ -21,6 +21,7 @@
>>>>>>>>> > >>>> > >>
>>>>>>>>> > >>>> > >>  #define ARMV8_MAX_COUNTERS      32
>>>>>>>>> > >>>> > >>  #define ARMV8_COUNTER_MASK      (ARMV8_MAX_COUNTERS - 1)
>>>>>>>>> > >>>> > >>+#define ARMV8_CYCLE_IDX         (ARMV8_MAX_COUNTERS - 1)
>>>>>>> > >>> > >
>>>>>>> > >>> > >I'm not sure we want to add this. It's name is wrong, as it's really
>>>>>>> > >>> > >PMCNTENSET_EL0.C, and just a few lines above we have the idx defined
>>>>>>> > >>> > >already (ARMV8_IDX_CYCLE_COUNTER), but as zero, because
>>>>>>> > >>> > >arch/arm64/kernel/perf_event.c maps it that way.
>>>>>>> > >>> > >
>>>>>>> > >>> > >I think we should do the same with the pmc array, i.e. map the cycle
>>>>>>> > >>> > >counter to idx zero.
>>>>> > >> >
>>>>> > >> >I tend to have the opposite view. Not for the sake of it, but because I
>>>>> > >> >find it helpful to directly map the code to the architecture
>>>>> > >> >documentation without having to bend another handful of neurons.
>>>>> > >> >
>>>>> > >> >Will probably had some good reasons to structure it that way, but I
>>>>> > >> >don't know the rational. Will?
>>> > >It was years ago, but I suspect that the cycle counter is index zero
>>> > >because its mandated, whilst the number of event counters is IMPDEF.
>> >
>> >Since PMCNTENSET/CLR, PMINTENSET/CLR, PMOVSSET/CLR and PMSWINC are using
>> >bit 31 to stands the state of cycle counter, if we make cycle counter
>> >index to zero, we always need to do translation between the idx and bit
>> >31 when we access these registers.
> Conversely, if you stick the cycle counter right at the top, then you'll
> need to rework a bunch of the perf code that iterates from
> ARMV7_IDX_COUNTER0 to pmu->num_events.

But actually this doesn't affect the perf code now because it's just a 
internal PMC array index of kvm arm guest pmu codes.
And having a look at the ARMv8 SPEC, it says
"
PMCCFILTR_EL0 can also be accessed by using PMXEVTYPER_EL0 with 
PMSELR_EL0.SEL set to 0b11111.
"
Apparently it treats the index of cycle counter as 31 not zero. Also 
regarding the PMCR.N field my understanding is that it just stands the 
number of counters not the counter's order or index. Looking at the 
description of PMSEL.SEL field, it says "This field can take any value 
from 0 (0b00000) to (PMCR.N)-1, or 31 (0b11111)." while it's not "This 
field can take any value from 1 (0b00001) to (PMCR.N), or 0."

Thanks,
-- 
Shannon

  reply	other threads:[~2016-01-29 13:11 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-27  3:51 [PATCH v10 00/21] KVM: ARM64: Add guest PMU support Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 01/21] ARM64: Move PMU register related defines to asm/pmu.h Shannon Zhao
2016-02-10 10:36   ` Will Deacon
2016-01-27  3:51 ` [PATCH v10 02/21] KVM: ARM64: Define PMU data structure for each vcpu Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 03/21] KVM: ARM64: Add offset defines for PMU registers Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 04/21] KVM: ARM64: Add access handler for PMCR register Shannon Zhao
2016-01-28 15:36   ` Andrew Jones
2016-01-28 20:43     ` Andrew Jones
2016-01-29  2:07       ` Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 05/21] KVM: ARM64: Add access handler for PMSELR register Shannon Zhao
2016-01-28 20:10   ` Andrew Jones
2016-01-27  3:51 ` [PATCH v10 06/21] KVM: ARM64: Add access handler for PMCEID0 and PMCEID1 register Shannon Zhao
2016-01-28 20:34   ` Andrew Jones
2016-01-29  3:47     ` Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 07/21] KVM: ARM64: PMU: Add perf event map and introduce perf event creating function Shannon Zhao
2016-01-28 16:31   ` Andrew Jones
2016-01-28 16:45     ` Marc Zyngier
2016-01-28 18:06       ` Will Deacon
2016-01-29  6:14         ` Shannon Zhao
2016-01-29  6:26         ` Shannon Zhao
2016-01-29 10:18           ` Will Deacon
2016-01-29 13:11             ` Shannon Zhao [this message]
2016-01-27  3:51 ` [PATCH v10 08/21] KVM: ARM64: Add access handler for event type register Shannon Zhao
2016-01-28 20:11   ` Andrew Jones
2016-01-29  1:42     ` Shannon Zhao
2016-01-29 11:25       ` Andrew Jones
2016-01-27  3:51 ` [PATCH v10 09/21] KVM: ARM64: Add access handler for event counter register Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 10/21] KVM: ARM64: Add access handler for PMCNTENSET and PMCNTENCLR register Shannon Zhao
2016-01-28 18:08   ` Andrew Jones
2016-01-28 18:12     ` Andrew Jones
2016-01-27  3:51 ` [PATCH v10 11/21] KVM: ARM64: Add access handler for PMINTENSET and PMINTENCLR register Shannon Zhao
2016-01-28 18:18   ` Andrew Jones
2016-01-27  3:51 ` [PATCH v10 12/21] KVM: ARM64: Add access handler for PMOVSSET and PMOVSCLR register Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 13/21] KVM: ARM64: Add access handler for PMSWINC register Shannon Zhao
2016-01-28 18:37   ` Andrew Jones
2016-01-27  3:51 ` [PATCH v10 14/21] KVM: ARM64: Add helper to handle PMCR register bits Shannon Zhao
2016-01-28 19:15   ` Andrew Jones
2016-01-27  3:51 ` [PATCH v10 15/21] KVM: ARM64: Add access handler for PMUSERENR register Shannon Zhao
2016-01-28 19:58   ` Andrew Jones
2016-01-29  7:37     ` Shannon Zhao
2016-01-29 11:08       ` Andrew Jones
2016-01-29 13:17         ` Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 16/21] KVM: ARM64: Add PMU overflow interrupt routing Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 17/21] KVM: ARM64: Reset PMU state when resetting vcpu Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 18/21] KVM: ARM64: Free perf event of PMU when destroying vcpu Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 19/21] KVM: ARM64: Add a new feature bit for PMUv3 Shannon Zhao
2016-01-28 20:54   ` Andrew Jones
2016-01-27  3:51 ` [PATCH v10 20/21] KVM: ARM: Introduce per-vcpu kvm device controls Shannon Zhao
2016-01-27  3:51 ` [PATCH v10 21/21] KVM: ARM64: Add a new vcpu device control group for PMUv3 Shannon Zhao
2016-01-28 21:12   ` Andrew Jones
2016-01-28 21:30 ` [PATCH v10 00/21] KVM: ARM64: Add guest PMU support Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56AB64EE.5080305@linaro.org \
    --to=shannon.zhao@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).