From: Marc Zyngier <maz@kernel.org>
To: myrialsarvay@gmail.com
Cc: Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Sven Peter <sven@kernel.org>,
Janne Grunau <j@jannau.net>, Neal Gompa <neal@gompa.dev>,
linux-arm-kernel@lists.infradead.org,
linux-perf-users@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, asahi@lists.linux.dev,
Yuvan Shen <yuvanshen09@gmail.com>,
Nick Chan <towinchenmi@gmail.com>
Subject: Re: [PATCH v2 03/15] drivers/perf: apple_m1: Support per-implementation event tables
Date: Wed, 18 Nov 2026 11:59:30 +0000 [thread overview]
Message-ID: <864ide1hb1.wl-maz@kernel.org> (raw)
In-Reply-To: <20261107-m3-plus-pmu-events-v2-3-acf1e78da039@gmail.com>
On Sat, 07 Nov 2026 10:48:50 +0000,
Myria Sarvay via B4 Relay <devnull+myrialsarvay.gmail.com@kernel.org> wrote:
>
> From: Nick Chan <towinchenmi@gmail.com>
>
> Use per-implementation event tables to allow supporting implementations
> with a different list of events and event affinities.
>
> Signed-off-by: Nick Chan <towinchenmi@gmail.com>
> Co-developed-by: Myria Sarvay <myrialsarvay@gmail.com>
> Signed-off-by: Myria Sarvay <myrialsarvay@gmail.com>
> ---
> drivers/perf/apple_m1_cpu_pmu.c | 113 ++++++++++++++++++++++++----------------
> 1 file changed, 69 insertions(+), 44 deletions(-)
>
> diff --git a/drivers/perf/apple_m1_cpu_pmu.c b/drivers/perf/apple_m1_cpu_pmu.c
> index de4026c63afd..2ff0c2e0b737 100644
> --- a/drivers/perf/apple_m1_cpu_pmu.c
> +++ b/drivers/perf/apple_m1_cpu_pmu.c
> @@ -43,9 +43,6 @@
> * moment, we don't really need to distinguish between the two because we
> * know next to nothing about the events themselves, and we already have
> * per cpu-type PMU abstractions.
> - *
> - * If we eventually find out that the events are different across
> - * implementations, we'll have to introduce per cpu-type tables.
> */
> enum m1_pmu_events {
> M1_PMU_PERFCTR_RETIRE_UOP = 0x1,
> @@ -167,7 +164,7 @@ static const u16 m1_pmu_event_affinity[M1_PMU_PERFCTR_LAST + 1] = {
> [M1_PMU_PERFCTR_UNKNOWN_fd] = ONLY_2_4_6,
> };
>
> -static const unsigned m1_pmu_perf_map[PERF_COUNT_HW_MAX] = {
> +static const unsigned int m1_pmu_perf_map[PERF_COUNT_HW_MAX] = {
> PERF_MAP_ALL_UNSUPPORTED,
> [PERF_COUNT_HW_CPU_CYCLES] = M1_PMU_PERFCTR_CORE_ACTIVE_CYCLE,
> [PERF_COUNT_HW_INSTRUCTIONS] = M1_PMU_PERFCTR_INST_ALL,
> @@ -486,11 +483,12 @@ static void m1_pmu_write_counter(struct perf_event *event, u64 value)
> isb();
> }
>
> -static int m1_pmu_get_event_idx(struct pmu_hw_events *cpuc,
> - struct perf_event *event)
> +static int apple_pmu_get_event_idx(struct pmu_hw_events *cpuc,
> + struct perf_event *event,
> + const u16 event_affinities[])
> {
> unsigned long evtype = event->hw.config_base & M1_PMU_CFG_EVENT;
> - unsigned long affinity = m1_pmu_event_affinity[evtype];
> + unsigned long affinity = event_affinities[evtype];
> int idx;
>
> /*
> @@ -509,6 +507,12 @@ static int m1_pmu_get_event_idx(struct pmu_hw_events *cpuc,
> return -EAGAIN;
> }
>
> +static int m1_pmu_get_event_idx(struct pmu_hw_events *cpuc,
> + struct perf_event *event)
> +{
> + return apple_pmu_get_event_idx(cpuc, event, m1_pmu_event_affinity);
> +}
> +
> static void m1_pmu_clear_event_idx(struct pmu_hw_events *cpuc,
> struct perf_event *event)
> {
> @@ -536,44 +540,52 @@ static void m1_pmu_stop(struct arm_pmu *cpu_pmu)
> __m1_pmu_set_mode(PMCR0_IMODE_OFF);
> }
>
> +static int apple_pmu_map_event(struct perf_event *event,
> + const unsigned int (*perf_map)[],
> + unsigned int flags)
> +{
> + event->hw.flags |= flags;
> + return armpmu_map_event(event, perf_map, NULL, M1_PMU_CFG_EVENT);
> +}
> +
> +/*
> + * Apple PMU counters have been observed to be either 48 or
> + * 64 bits wide, depending on the SoC. However, the MSB is
> + * what triggers an overflow interrupt, so we advertise the
> + * counters as being 1-bit smaller than hardware so as to
> + * mimick ARM PMU behaviour
> + */
> static int m1_pmu_map_event(struct perf_event *event)
> {
> - /*
> - * Although the counters are 48bit wide, bit 47 is what
> - * triggers the overflow interrupt. Advertise the counters
> - * being 47bit wide to mimick the behaviour of the ARM PMU.
> - */
> - event->hw.flags |= ARMPMU_EVT_47BIT;
> - return armpmu_map_event(event, &m1_pmu_perf_map, NULL, M1_PMU_CFG_EVENT);
> + return apple_pmu_map_event(event, &m1_pmu_perf_map, ARMPMU_EVT_47BIT);
> }
>
> static int m2_pmu_map_event(struct perf_event *event)
> {
> - /*
> - * Same deal as the above, except that M2 has 64bit counters.
> - * Which, as far as we're concerned, actually means 63 bits.
> - * Yes, this is getting awkward.
> - */
> - event->hw.flags |= ARMPMU_EVT_63BIT;
> - return armpmu_map_event(event, &m1_pmu_perf_map, NULL, M1_PMU_CFG_EVENT);
> + return apple_pmu_map_event(event, &m1_pmu_perf_map, ARMPMU_EVT_63BIT);
> }
>
> -static int m1_pmu_map_pmuv3_event(unsigned int eventsel)
> +static int apple_pmu_map_pmuv3_event(unsigned int eventsel, const u16 pmceid_map[])
> {
> - u16 m1_event = HW_OP_UNSUPPORTED;
> + u16 apple_event = HW_OP_UNSUPPORTED;
nit: s/apple_event/hw_event/.
>
> if (eventsel < ARMV8_PMUV3_MAX_COMMON_EVENTS)
> - m1_event = m1_pmu_pmceid_map[eventsel];
> + apple_event = pmceid_map[eventsel];
>
> - return m1_event == HW_OP_UNSUPPORTED ? -EOPNOTSUPP : m1_event;
> + return apple_event == HW_OP_UNSUPPORTED ? -EOPNOTSUPP : apple_event;
> }
>
> -static void m1_pmu_init_pmceid(struct arm_pmu *pmu)
> +static int m1_pmu_map_pmuv3_event(unsigned int eventsel)
> +{
> + return apple_pmu_map_pmuv3_event(eventsel, m1_pmu_pmceid_map);
> +}
> +
> +static void apple_pmu_init_pmceid(struct arm_pmu *pmu)
> {
> unsigned int event;
>
> for (event = 0; event < ARMV8_PMUV3_MAX_COMMON_EVENTS; event++) {
> - if (m1_pmu_map_pmuv3_event(event) >= 0)
> + if (pmu->map_pmuv3_event(event) >= 0)
> set_bit(event, pmu->pmceid_bitmap);
> }
> }
> @@ -616,33 +628,22 @@ static int m1_pmu_set_event_filter(struct hw_perf_event *event,
> return 0;
> }
>
> -static int m1_pmu_init(struct arm_pmu *cpu_pmu, u32 flags)
> +static int apple_pmu_init(struct arm_pmu *cpu_pmu)
> {
> cpu_pmu->handle_irq = m1_pmu_handle_irq;
> cpu_pmu->enable = m1_pmu_enable_event;
> cpu_pmu->disable = m1_pmu_disable_event;
> cpu_pmu->read_counter = m1_pmu_read_counter;
> cpu_pmu->write_counter = m1_pmu_write_counter;
> - cpu_pmu->get_event_idx = m1_pmu_get_event_idx;
> cpu_pmu->clear_event_idx = m1_pmu_clear_event_idx;
> cpu_pmu->start = m1_pmu_start;
> cpu_pmu->stop = m1_pmu_stop;
> -
> - if (flags & ARMPMU_EVT_47BIT)
> - cpu_pmu->map_event = m1_pmu_map_event;
> - else if (flags & ARMPMU_EVT_63BIT)
> - cpu_pmu->map_event = m2_pmu_map_event;
> - else
> - return WARN_ON(-EINVAL);
> -
> cpu_pmu->reset = m1_pmu_reset;
> cpu_pmu->set_event_filter = m1_pmu_set_event_filter;
>
> - cpu_pmu->map_pmuv3_event = m1_pmu_map_pmuv3_event;
> - m1_pmu_init_pmceid(cpu_pmu);
> + apple_pmu_init_pmceid(cpu_pmu);
>
> bitmap_set(cpu_pmu->cntr_mask, 0, M1_PMU_NR_COUNTERS);
> - cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = &m1_pmu_events_attr_group;
> cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] = &m1_pmu_format_attr_group;
> return 0;
> }
> @@ -651,25 +652,49 @@ static int m1_pmu_init(struct arm_pmu *cpu_pmu, u32 flags)
> static int m1_pmu_ice_init(struct arm_pmu *cpu_pmu)
> {
> cpu_pmu->name = "apple_icestorm_pmu";
> - return m1_pmu_init(cpu_pmu, ARMPMU_EVT_47BIT);
> + cpu_pmu->get_event_idx = m1_pmu_get_event_idx;
> + cpu_pmu->map_event = m1_pmu_map_event;
> +
> + cpu_pmu->map_pmuv3_event = m1_pmu_map_pmuv3_event;
> +
> + cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = &m1_pmu_events_attr_group;
> + return apple_pmu_init(cpu_pmu);
> }
>
Looking at the following patches, I feel that this series is taking
the long route to get to a relatively clear point: most of the
invariant that we relied on for M1, slightly relaxed for M2 (counter
width), are even more relaxed for M3+ (event width). We therefore need
to indirect things. The way you do it is to mirror the current setup,
with a whole set of callbacks per implementation and a bunch of
additional helpers.
But instead of having a set of helper functions, one per
implementation, with an ever increasing set of parameters, it really
feels like we could do with a more data-centric approach where we have
a single data structure describing an implementation, containing all
the relevant data (pointer to the event mapping table, flags, bit
indices for the user/kernel/guest/host attributes, and so on. We could
then have a single set of callbacks that work on everything.
You could convert M1/M2 to that, then just add the relevant
descriptions for M3+, which should just add data and the init
functions, nothing else.
Does this make sense to you?
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2026-11-18 11:59 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 10:48 [PATCH v2 00/15] drivers/perf: apple_m1: Add M3/M4/A18 Pro Support Myria Sarvay via B4 Relay
2026-11-07 10:48 ` [PATCH v2 01/15] dt-bindings: arm: pmu: Add Apple M3/M4/A18 Pro SoC CPU PMU compatibles Myria Sarvay via B4 Relay
2026-11-07 10:52 ` sashiko-bot
2026-11-07 10:48 ` [PATCH v2 02/15] drivers/perf: apple_m1: Remove unused variables Myria Sarvay via B4 Relay
2026-11-07 10:54 ` sashiko-bot
2026-11-18 11:13 ` Marc Zyngier
2026-11-07 10:48 ` [PATCH v2 03/15] drivers/perf: apple_m1: Support per-implementation event tables Myria Sarvay via B4 Relay
2026-11-07 10:53 ` sashiko-bot
2026-11-18 11:59 ` Marc Zyngier [this message]
2026-11-07 10:48 ` [PATCH v2 04/15] drivers/perf: apple_m1: Support per-implementation event size Myria Sarvay via B4 Relay
2026-11-07 10:53 ` sashiko-bot
2026-11-07 10:48 ` [PATCH v2 05/15] drivers/perf: apple_m1: Use macros for per-implementation init functions Myria Sarvay via B4 Relay
2026-11-07 10:52 ` sashiko-bot
2026-11-07 10:48 ` [PATCH v2 06/15] drivers/perf: apple_m1: Add Apple M3 Series Support Myria Sarvay via B4 Relay
2026-11-07 10:53 ` sashiko-bot
2026-11-08 0:42 ` kernel test robot
2026-11-07 10:48 ` [PATCH v2 07/15] drivers/perf: apple_m1: Add Apple M4 " Myria Sarvay via B4 Relay
2026-11-07 10:55 ` sashiko-bot
2026-11-07 10:48 ` [PATCH v2 08/15] drivers/perf: apple_m1: Add Apple A18 Support Myria Sarvay via B4 Relay
2026-11-07 10:53 ` sashiko-bot
2026-11-07 10:48 ` [PATCH v2 09/15] arm64: dts: apple: t603*: Add core interrupt affinities Myria Sarvay via B4 Relay
2026-11-07 10:53 ` sashiko-bot
2026-11-07 10:48 ` [PATCH v2 10/15] arm64: dts: apple: t8140: " Myria Sarvay via B4 Relay
2026-11-07 10:57 ` sashiko-bot
2026-11-07 10:48 ` [PATCH v2 11/15] arm64: dts: apple: t603x: Add PMU Device Nodes Myria Sarvay via B4 Relay
2026-11-07 10:55 ` sashiko-bot
2026-11-07 10:48 ` [PATCH v2 12/15] arm64: dts: apple: t8122: " Myria Sarvay via B4 Relay
2026-11-07 10:54 ` sashiko-bot
2026-11-07 10:49 ` [PATCH v2 13/15] arm64: dts: apple: t604x: " Myria Sarvay via B4 Relay
2026-11-07 10:55 ` sashiko-bot
2026-11-07 10:49 ` [PATCH v2 14/15] arm64: dts: apple: t8132: " Myria Sarvay via B4 Relay
2026-11-07 10:56 ` sashiko-bot
2026-11-07 10:49 ` [PATCH v2 15/15] arm64: dts: apple: t8140: " Myria Sarvay via B4 Relay
2026-11-07 10:55 ` sashiko-bot
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=864ide1hb1.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=asahi@lists.linux.dev \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=j@jannau.net \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=myrialsarvay@gmail.com \
--cc=neal@gompa.dev \
--cc=robh@kernel.org \
--cc=sven@kernel.org \
--cc=towinchenmi@gmail.com \
--cc=will@kernel.org \
--cc=yuvanshen09@gmail.com \
/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