From: Nick Chan <towinchenmi@gmail.com>
To: 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>,
Catalin Marinas <catalin.marinas@arm.com>,
Janne Grunau <j@jannau.net>,
Alyssa Rosenzweig <alyssa@rosenzweig.io>,
Neal Gompa <neal@gompa.dev>, Sven Peter <sven@kernel.org>
Cc: Marc Zyngier <maz@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-perf-users@vger.kernel.org, devicetree@vger.kernel.org,
asahi@lists.linux.dev, linux-kernel@vger.kernel.org,
Nick Chan <towinchenmi@gmail.com>
Subject: [PATCH v8 04/21] drivers/perf: apple_m1: Support a per-implementation number of counters
Date: Mon, 11 Aug 2025 21:54:36 +0800 [thread overview]
Message-ID: <20250811-apple-cpmu-v8-4-c560ebd9ca46@gmail.com> (raw)
In-Reply-To: <20250811-apple-cpmu-v8-0-c560ebd9ca46@gmail.com>
Support a per-implementation number of counters to allow adding support
for implementations with less counters.
Signed-off-by: Nick Chan <towinchenmi@gmail.com>
---
drivers/perf/apple_m1_cpu_pmu.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/drivers/perf/apple_m1_cpu_pmu.c b/drivers/perf/apple_m1_cpu_pmu.c
index b4ab6a3e5df965b7ef450d7e533995f3cc8633fd..b5fe04ef186f04b4af32524fe433afb79979b791 100644
--- a/drivers/perf/apple_m1_cpu_pmu.c
+++ b/drivers/perf/apple_m1_cpu_pmu.c
@@ -20,6 +20,7 @@
#include <asm/perf_event.h>
#define M1_PMU_NR_COUNTERS 10
+#define APPLE_PMU_MAX_NR_COUNTERS 10
#define M1_PMU_CFG_EVENT GENMASK(7, 0)
@@ -459,7 +460,7 @@ static irqreturn_t m1_pmu_handle_irq(struct arm_pmu *cpu_pmu)
regs = get_irq_regs();
- for_each_set_bit(idx, cpu_pmu->cntr_mask, M1_PMU_NR_COUNTERS) {
+ for_each_set_bit(idx, cpu_pmu->cntr_mask, APPLE_PMU_MAX_NR_COUNTERS) {
struct perf_event *event = cpuc->events[idx];
struct perf_sample_data data;
@@ -506,7 +507,7 @@ static int apple_pmu_get_event_idx(struct pmu_hw_events *cpuc,
* counting on the PMU at any given time, and by placing the
* most constraining events first.
*/
- for_each_set_bit(idx, &affinity, M1_PMU_NR_COUNTERS) {
+ for_each_set_bit(idx, &affinity, APPLE_PMU_MAX_NR_COUNTERS) {
if (!test_and_set_bit(idx, cpuc->used_mask))
return idx;
}
@@ -601,13 +602,13 @@ static void m1_pmu_init_pmceid(struct arm_pmu *pmu)
}
}
-static void m1_pmu_reset(void *info)
+static void apple_pmu_reset(void *info, u32 counters)
{
int i;
__m1_pmu_set_mode(PMCR0_IMODE_OFF);
- for (i = 0; i < M1_PMU_NR_COUNTERS; i++) {
+ for (i = 0; i < counters; i++) {
m1_pmu_disable_counter(i);
m1_pmu_disable_counter_interrupt(i);
m1_pmu_write_hw_counter(0, i);
@@ -616,6 +617,11 @@ static void m1_pmu_reset(void *info)
isb();
}
+static void m1_pmu_reset(void *info)
+{
+ apple_pmu_reset(info, M1_PMU_NR_COUNTERS);
+}
+
static int m1_pmu_set_event_filter(struct hw_perf_event *event,
struct perf_event_attr *attr)
{
@@ -639,7 +645,7 @@ static int m1_pmu_set_event_filter(struct hw_perf_event *event,
return 0;
}
-static int apple_pmu_init(struct arm_pmu *cpu_pmu)
+static int apple_pmu_init(struct arm_pmu *cpu_pmu, u32 counters)
{
cpu_pmu->handle_irq = m1_pmu_handle_irq;
cpu_pmu->enable = m1_pmu_enable_event;
@@ -649,7 +655,6 @@ static int apple_pmu_init(struct arm_pmu *cpu_pmu)
cpu_pmu->clear_event_idx = m1_pmu_clear_event_idx;
cpu_pmu->start = m1_pmu_start;
cpu_pmu->stop = m1_pmu_stop;
- cpu_pmu->reset = m1_pmu_reset;
cpu_pmu->set_event_filter = m1_pmu_set_event_filter;
if (is_hyp_mode_available()) {
@@ -657,7 +662,7 @@ static int apple_pmu_init(struct arm_pmu *cpu_pmu)
m1_pmu_init_pmceid(cpu_pmu);
}
- bitmap_set(cpu_pmu->cntr_mask, 0, M1_PMU_NR_COUNTERS);
+ bitmap_set(cpu_pmu->cntr_mask, 0, 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;
@@ -669,7 +674,8 @@ static int m1_pmu_ice_init(struct arm_pmu *cpu_pmu)
cpu_pmu->name = "apple_icestorm_pmu";
cpu_pmu->get_event_idx = m1_pmu_get_event_idx;
cpu_pmu->map_event = m1_pmu_map_event;
- return apple_pmu_init(cpu_pmu);
+ cpu_pmu->reset = m1_pmu_reset;
+ return apple_pmu_init(cpu_pmu, M1_PMU_NR_COUNTERS);
}
static int m1_pmu_fire_init(struct arm_pmu *cpu_pmu)
@@ -677,7 +683,8 @@ static int m1_pmu_fire_init(struct arm_pmu *cpu_pmu)
cpu_pmu->name = "apple_firestorm_pmu";
cpu_pmu->get_event_idx = m1_pmu_get_event_idx;
cpu_pmu->map_event = m1_pmu_map_event;
- return apple_pmu_init(cpu_pmu);
+ cpu_pmu->reset = m1_pmu_reset;
+ return apple_pmu_init(cpu_pmu, M1_PMU_NR_COUNTERS);
}
static int m2_pmu_avalanche_init(struct arm_pmu *cpu_pmu)
@@ -685,7 +692,8 @@ static int m2_pmu_avalanche_init(struct arm_pmu *cpu_pmu)
cpu_pmu->name = "apple_avalanche_pmu";
cpu_pmu->get_event_idx = m1_pmu_get_event_idx;
cpu_pmu->map_event = m2_pmu_map_event;
- return apple_pmu_init(cpu_pmu);
+ cpu_pmu->reset = m1_pmu_reset;
+ return apple_pmu_init(cpu_pmu, M1_PMU_NR_COUNTERS);
}
static int m2_pmu_blizzard_init(struct arm_pmu *cpu_pmu)
@@ -693,7 +701,8 @@ static int m2_pmu_blizzard_init(struct arm_pmu *cpu_pmu)
cpu_pmu->name = "apple_blizzard_pmu";
cpu_pmu->get_event_idx = m1_pmu_get_event_idx;
cpu_pmu->map_event = m2_pmu_map_event;
- return apple_pmu_init(cpu_pmu);
+ cpu_pmu->reset = m1_pmu_reset;
+ return apple_pmu_init(cpu_pmu, M1_PMU_NR_COUNTERS);
}
static const struct of_device_id m1_pmu_of_device_ids[] = {
--
2.50.1
next prev parent reply other threads:[~2025-08-11 14:57 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 13:54 [PATCH v8 00/21] drivers/perf: apple_m1: Add Apple A7-A11, T2 SoC support Nick Chan
2025-08-11 13:54 ` [PATCH v8 01/21] dt-bindings: arm: pmu: Add Apple A7-A11 SoC CPU PMU compatibles Nick Chan
2025-08-11 13:54 ` [PATCH v8 02/21] drivers/perf: apple_m1: Only init PMUv3 remap when EL2 is available Nick Chan
2025-08-11 13:54 ` [PATCH v8 03/21] drivers/perf: apple_m1: Support per-implementation event tables Nick Chan
2025-08-11 13:54 ` Nick Chan [this message]
2025-08-11 13:54 ` [PATCH v8 05/21] drivers/perf: apple_m1: Support configuring counters for 32-bit EL0 Nick Chan
2025-08-11 13:54 ` [PATCH v8 06/21] drivers/perf: apple_m1: Support per-implementation PMU startup Nick Chan
2025-08-11 13:54 ` [PATCH v8 07/21] drivers/perf: apple_m1: Support per-implementation event attr group Nick Chan
2025-08-11 13:54 ` [PATCH v8 08/21] drivers/perf: apple_m1: Add Apple A7 support Nick Chan
2025-08-11 13:54 ` [PATCH v8 09/21] drivers/perf: apple_m1: Add Apple A8/A8X support Nick Chan
2025-08-11 13:54 ` [PATCH v8 10/21] drivers/perf: apple_m1: Add A9/A9X support Nick Chan
2025-08-11 13:54 ` [PATCH v8 11/21] drivers/perf: apple_m1: Add Apple A10/A10X/T2 Support Nick Chan
2025-08-11 13:54 ` [PATCH v8 12/21] drivers/perf: apple_m1: Add Apple A11 Support Nick Chan
2025-08-11 13:54 ` [PATCH v8 13/21] arm64: dts: apple: s5l8960x: Add CPU PMU nodes Nick Chan
2025-08-11 13:54 ` [PATCH v8 14/21] arm64: dts: apple: t7000: " Nick Chan
2025-08-11 13:54 ` [PATCH v8 15/21] arm64: dts: apple: t7001: " Nick Chan
2025-08-11 13:54 ` [PATCH v8 16/21] arm64: dts: apple: s800-0-3: " Nick Chan
2025-08-11 13:54 ` [PATCH v8 17/21] arm64: dts: apple: s8001: " Nick Chan
2025-08-11 13:54 ` [PATCH v8 18/21] arm64: dts: apple: t8010: " Nick Chan
2025-08-11 13:54 ` [PATCH v8 19/21] arm64: dts: apple: t8011: " Nick Chan
2025-08-11 13:54 ` [PATCH v8 20/21] arm64: dts: apple: t8012: " Nick Chan
2025-08-11 13:54 ` [PATCH v8 21/21] arm64: dts: apple: t8015: " Nick Chan
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=20250811-apple-cpmu-v8-4-c560ebd9ca46@gmail.com \
--to=towinchenmi@gmail.com \
--cc=alyssa@rosenzweig.io \
--cc=asahi@lists.linux.dev \
--cc=catalin.marinas@arm.com \
--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=maz@kernel.org \
--cc=neal@gompa.dev \
--cc=robh@kernel.org \
--cc=sven@kernel.org \
--cc=will@kernel.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).