From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 786DD60A2604 for ; Wed, 18 Nov 2026 11:59:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=0Mf8uGCi; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TLmD8M3S DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=t6a0qUAEvTRsG3736CRjvd9xj+hEAg897zrjwcV0qhs=; b=0Mf8uGCi1uoIonVmjg2b5/lxHP 8F0dg3G7IVzDSUfmz+Q7UErC681wbZyifwSZXxqC8ARPNnT6XcslRwg7uf4kE0uVcHgzA8UeGB0sr hhuVnA7wVWPqN+Rx+moXVn4yV1gFiCxcYKDsIrTw2NMi3MskXSMKBZCo+6eigT/fK19xDDGCKU2Fr 2+qz+XIyMGdvwrx0s5p6ZQ+QRVjjlo/1w/5d9y3Ef09BS9ka5jz+XGElKDhwjycfE5tyR9rMZWzc4 bE64HjPDhhhCcAElX7L7cdp/F1BKqAF4aGri77XNrH6/T6HGpF1DM37wV7NtiyAtD+pDZWe7FqsPd QieHAC1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xTeK7-00000008mCl-0r9B; Wed, 18 Nov 2026 11:59:35 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xTeK6-00000008mBl-1iK2 for linux-arm-kernel@lists.infradead.org; Wed, 18 Nov 2026 11:59:34 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 5324044832; Wed, 18 Nov 2026 11:59:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1998C1F000D0; Wed, 18 Nov 2026 11:59:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795003173; bh=t6a0qUAEvTRsG3736CRjvd9xj+hEAg897zrjwcV0qhs=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=TLmD8M3SujNa0QtYF8gLynGLwQ3o0Jh/fMNhFJ1k2eHY4Nx5voFNq08nnMqY+xbba eoJEwUtiTfULSfdPSAmMY7RExNHeRt/BM+TFfpigWTnFcmps/CrWkEWRtaP/V82F6N EAT9yfo0jBBBxeEtBbROn0qIGtHz1p7gFLFPqUaBNwoCPYy4efvTl16NexGeDr7KQo YtidpzDrMmuU+DTNQioCeedKmIdxOB4F3t9eM1yw9jNbNcFGtfJ89RD0TIFcBwBGKZ I6KM9UUU1sm2u6XnTumiQsg3L2RPe5SAd/cJpfvXEpCIVg5aXDTPlFraS6Gf8cZ+Fz v+x+x6geMX+gg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTeK3-0000000HVE0-0rV3; Wed, 18 Nov 2026 11:59:31 +0000 Date: Wed, 18 Nov 2026 11:59:30 +0000 Message-ID: <864ide1hb1.wl-maz@kernel.org> From: Marc Zyngier To: myrialsarvay@gmail.com Cc: Will Deacon , Mark Rutland , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sven Peter , Janne Grunau , Neal Gompa , 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 , Nick Chan Subject: Re: [PATCH v2 03/15] drivers/perf: apple_m1: Support per-implementation event tables In-Reply-To: <20261107-m3-plus-pmu-events-v2-3-acf1e78da039@gmail.com> References: <20261107-m3-plus-pmu-events-v2-0-acf1e78da039@gmail.com> <20261107-m3-plus-pmu-events-v2-3-acf1e78da039@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) X-Archived-By: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: myrialsarvay@gmail.com, will@kernel.org, mark.rutland@arm.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, sven@kernel.org, j@jannau.net, 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, yuvanshen09@gmail.com, towinchenmi@gmail.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Sat, 07 Nov 2026 10:48:50 +0000, Myria Sarvay via B4 Relay wrote: > > From: Nick Chan > > Use per-implementation event tables to allow supporting implementations > with a different list of events and event affinities. > > Signed-off-by: Nick Chan > Co-developed-by: Myria Sarvay > Signed-off-by: Myria Sarvay > --- > 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.