perf: marvell: LLC-TAD PMU MPAM filtering support
Subsystems (2)
v4 cover perf: marvell: LLC-TAD PMU MPAM filtering support
This series extends the Marvell LLC-TAD performance driver used on CN10K and CN20K systems.
Patch 1 adds optional MPAM partition-id filtering for the subset of TAD events that support it, exposes partid / partid_en in the PMU format string, and keeps the reduced Odyssey event surface without advertising partid where it does not apply. It also fixes probe resource handling (no in-place mutation of platform_get_resource() bounds, validate MMIO window vs tad-cnt), registers CPU hotplug before perf_pmu_register with unwind, and aligns the filter-enable bit in config1 with the sysfs format (bit 9).
Patch 2 introduces CN20K LLC-TAD support: non-standard PFC/PRF offsets, additional programmable events with visibility checks so CN10K does not advertise V3-only events, CN20K-specific MPAM encoding for the V3 profile, local64_set(prev_count) on counter start, and device discovery via OF and ACPI.
Patch 3 extends the DeviceTree binding for marvell,cn20k-tad-pmu.
Changes since v3
----------------
- Add perf_ready: tad_pmu_offline_cpu skips perf_pmu_migrate_context until after successful perf_pmu_register, so a CPU offline between hotplug add and perf register does not touch perf core state for an unregistered PMU.
Changes since v2
----------------
- Validate the eventId using an appropriate mask to ensure it is restricted to 8 bits.
Changes since v1
----------------
- config1: use bit 9 for MPAM filter enable consistently with partid_en in the PMU format; allow only bits 0..9 in event_init on CN10K/CN20K paths.
- Reject reserved bits in attr.config and use the same 8-bit event index in start_counter as in event_init so MPAM validation cannot be bypassed.
- Register CPU hotplug before perf_pmu_register in probe (mainline order); add perf_ready so offline migration is skipped until after perf registration (reconciles v1 vs v2 ordering feedback).
- Hide V3-only sysfs events on V1.
- Reset prev_count when starting counters after clearing hardware.
- DT binding: explain non-fallback compatibles for CN10K vs CN20K.
Tanmay Jagdale (1):
perf: marvell: Add MPAM partid filtering to CN10K TAD PMU
Geetha sowjanya (2):
perf: marvell: Add CN20K LLC-TAD PMU support
dt-bindings: perf: marvell: Extend CN10K TAD PMU binding for CN20K
Signature · 1 line
2.25.1
PATCH v4 1/3 perf: marvell: Add MPAM partid filtering to CN10K TAD PMU
From: Tanmay Jagdale <[email protected]>
The TAD PMU exposes counters that can be filtered by MPAM partition id for a subset of allocation and hit events.
Add a 9-bit partid format attribute (config1) and route counter programming through variant-specific ops so CN10K keeps MPAM-capable programming while Odyssey keeps the reduced event set without advertising partid in sysfs.
Probe no longer mutates the platform_device MMIO resource (walk a local map_start), rejects tad-cnt / page sizes of zero, validates the memory window against tad-cnt, and registers the perf PMU before hotplug with correct unwind.
Example:
perf stat -e tad/tad_alloc_any,partid=0x12,partid_en=1/ -- <program>
---
Changelog (since v3)
--------------------
- Restore cpuhp_state_add_instance_nocalls before perf_pmu_register in probe so users cannot attach events before the hotplug instance exists; unwind removes the hotplug instance if perf registration fails.
- Add perf_ready: tad_pmu_offline_cpu skips perf_pmu_migrate_context until after successful perf_pmu_register, so a CPU offline between hotplug add and perf register does not touch perf core state for an unregistered PMU.
Changelog (since v2)
--------------------
- Validate the eventId using an appropriate mask to ensure it is restricted to 8 bits.
Changelog (since v1)
--------------------
- Fix config1 filter enable to use bit 9 consistently with the PMU format string (partid_en) and reject reserved bits with GENMASK(9, 0).
- Register perf_pmu_register before cpuhp_state_add_instance_nocalls and unregister on hotplug failure.
drivers/perf/marvell_cn10k_tad_pmu.c | 220 +++++++++++++++++++++------ 1 file changed, 171 insertions(+), 49 deletions(-)
drivers/perf/marvell_cn10k_tad_pmu.c +171 -49
@@ -7,6 +7,8 @@#define pr_fmt (fmt) "tad_pmu: " fmt#include <linux/io.h> +#include <linux/bits.h> +#include <linux/compiler.h> #include <linux/module.h> #include <linux/of.h> #include <linux/cpuhotplug.h>
@@ -14,12 +16,20 @@#include <linux/platform_device.h> #include <linux/acpi.h> -#define TAD_PFC_OFFSET 0x800 -#define TAD_PFC (counter) (TAD_PFC_OFFSET | (counter << 3))#define TAD_PRF_OFFSET 0x900 -#define TAD_PRF (counter) (TAD_PRF_OFFSET | (counter << 3)) +#define TAD_PFC_OFFSET 0x800 +#define TAD_PFC (base, counter) ((base) | ((u64)(counter) << 3)) +#define TAD_PRF (base, counter) ((base) | ((u64)(counter) << 3))#define TAD_PRF_CNTSEL_MASK 0xFF +#define TAD_PRF_MATCH_PARTID BIT(8) +#define TAD_PRF_PARTID_NS BIT(10) +/* +* config1: bits 0..8 MPAM partition id (including 0); bit 9 requests +* filtering for MPAM-capable events. All-zero config1 means no filter. +*/ +#define TAD_PARTID_FILTER_EN BIT(9)#define TAD_MAX_COUNTERS 8 +#define TAD_EVENT_SEL_MASK GENMASK(7, 0)#define to_tad_pmu (p) (container_of(p, struct tad_pmu, pmu))
@@ -27,30 +37,94 @@ struct tad_region {void __iomem *base; }; +enum mrvl_tad_pmu_version { +TAD_PMU_V1 =1 , +TAD_PMU_V2 , +}; + +struct tad_pmu_data { +int id; +u64 tad_prf_offset; +u64 tad_pfc_offset; +}; +struct tad_pmu {struct pmu pmu;struct tad_region *regions;u32 region_cnt;unsigned int cpu; +/* Set after successful perf_pmu_register(); gates offline migration. */ +bool perf_ready; +const struct tad_pmu_ops *ops; +const struct tad_pmu_data *pdata;struct hlist_node node;struct perf_event *events[TAD_MAX_COUNTERS ]; DECLARE_BITMAP(counters_map, TAD_MAX_COUNTERS); }; -enum mrvl_tad_pmu_version { -TAD_PMU_V1 =1 , -TAD_PMU_V2 , -}; - -struct tad_pmu_data { -int id; +struct tad_pmu_ops { +void (*start_counter)(struct tad_pmu *pmu,struct perf_event *event); };static int tad_pmu_cpuhp_state; +static void tad_pmu_start_counter (struct tad_pmu *pmu, +struct perf_event *event) +{ +const struct tad_pmu_data *pdata = pmu->pdata; +struct hw_perf_event *hwc = &event->hw; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u32 counter_idx = hwc->idx; +u64 partid_filter =0 ; +u64 reg_val; +u64 cfg1 = event->attr.config1; +bool use_mpam = cfg1 &TAD_PARTID_FILTER_EN ; +u32 partid = (u32)(cfg1 &GENMASK (8 ,0 )); +int i; + +for (i =0 ; i < pmu->region_cnt; i++) +writeq_relaxed (0 , pmu->regions[i].base + +TAD_PFC (pdata->tad_pfc_offset, counter_idx)); + +if (use_mpam && event_idx >0x19 && event_idx <0x21 ) { + partid_filter =TAD_PRF_MATCH_PARTID |TAD_PRF_PARTID_NS | + ((u64 )partid <<11 ); + } + + +for (i =0 ; i < pmu->region_cnt; i++) { + reg_val = event_idx &0xFF ; + reg_val |= partid_filter; +writeq_relaxed (reg_val, pmu->regions[i].base + +TAD_PRF (pdata->tad_prf_offset, counter_idx)); + } +} + +static void tad_pmu_v2_start_counter (struct tad_pmu *pmu, +struct perf_event *event) +{ +const struct tad_pmu_data *pdata = pmu->pdata; +struct hw_perf_event *hwc = &event->hw; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u32 counter_idx = hwc->idx; +u64 reg_val; +int i; + +for (i =0 ; i < pmu->region_cnt; i++) +writeq_relaxed (0 , pmu->regions[i].base + +TAD_PFC (pdata->tad_pfc_offset, counter_idx)); + +for (i =0 ; i < pmu->region_cnt; i++) { + reg_val = event_idx &0xFF ; +writeq_relaxed (reg_val, pmu->regions[i].base + +TAD_PRF (pdata->tad_prf_offset, counter_idx)); + } +} +static void tad_pmu_event_counter_read (struct perf_event *event) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata;struct hw_perf_event *hwc = &event->hw;u32 counter_idx = hwc->idx;u64 prev, new;
@@ -60,7 +134,7 @@ static void tad_pmu_event_counter_read(struct perf_event *event) prev =local64_read (&hwc->prev_count);for (i =0 , new =0 ; i < tad_pmu->region_cnt; i++) new +=readq (tad_pmu->regions[i].base + -TAD_PFC (counter_idx)); +TAD_PFC (pdata->tad_pfc_offset, counter_idx)); }while (local64_cmpxchg (&hwc->prev_count, prev, new) != prev);local64_add (new - prev, &event->count);
@@ -69,16 +143,14 @@ static void tad_pmu_event_counter_read(struct perf_event *event)static void tad_pmu_event_counter_stop (struct perf_event *event,int flags) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata;struct hw_perf_event *hwc = &event->hw;u32 counter_idx = hwc->idx;int i; -/* TAD()_PFC() stop counting on the write -* which sets TAD()_PRF()[CNTSEL] == 0 -*/ for (i =0 ; i < tad_pmu->region_cnt; i++) {writeq_relaxed (0 , tad_pmu->regions[i].base + -TAD_PRF (counter_idx)); +TAD_PRF (pdata->tad_prf_offset, counter_idx)); }tad_pmu_event_counter_read (event);
@@ -89,26 +161,10 @@ static void tad_pmu_event_counter_start(struct perf_event *event, int flags) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu);struct hw_perf_event *hwc = &event->hw; -u32 event_idx = event->attr.config; -u32 counter_idx = hwc->idx; -u64 reg_val; -int i; hwc->state =0 ; -/* Typically TAD_PFC() are zeroed to start counting */ -for (i =0 ; i < tad_pmu->region_cnt; i++) -writeq_relaxed (0 , tad_pmu->regions[i].base + -TAD_PFC (counter_idx)); - -/* TAD()_PFC() start counting on the write -* which sets TAD()_PRF()[CNTSEL] != 0 -*/ -for (i =0 ; i < tad_pmu->region_cnt; i++) { - reg_val = event_idx &0xFF ; -writeq_relaxed (reg_val, tad_pmu->regions[i].base + -TAD_PRF (counter_idx)); - } + tad_pmu->ops->start_counter (tad_pmu, event); }static void tad_pmu_event_counter_del (struct perf_event *event,int flags)
@@ -128,7 +184,6 @@ static int tad_pmu_event_counter_add(struct perf_event *event, int flags)struct hw_perf_event *hwc = &event->hw;int idx; -/* Get a free counter for this event */ idx =find_first_zero_bit (tad_pmu->counters_map,TAD_MAX_COUNTERS );if (idx ==TAD_MAX_COUNTERS )return -EAGAIN ;
@@ -148,6 +203,9 @@ static int tad_pmu_event_counter_add(struct perf_event *event, int flags)static int tad_pmu_event_init (struct perf_event *event) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u64 cfg1 = event->attr.config1;if (event->attr.type != event->pmu->type)return -ENOENT ;
@@ -158,6 +216,23 @@ static int tad_pmu_event_init(struct perf_event *event)if (event->state !=PERF_EVENT_STATE_OFF )return -EINVAL ; +if (event->attr.config & ~TAD_EVENT_SEL_MASK ) +return -EINVAL ; + +if (pdata->id ==TAD_PMU_V2 ) { +if (cfg1) +return -EINVAL ; + }else { +if ((cfg1 &GENMASK (8 ,0 )) && !(cfg1 &TAD_PARTID_FILTER_EN )) +return -EINVAL ; +if (cfg1 &TAD_PARTID_FILTER_EN ) { +if (event_idx <=0x19 || event_idx >=0x21 ) +return -EINVAL ; + } +if (cfg1 & ~GENMASK (9 ,0 )) +return -EINVAL ; + } + event->cpu = tad_pmu->cpu; event->hw.idx =-1 ; event->hw.config_base = event->attr.config;
@@ -232,7 +307,7 @@ static struct attribute *ody_tad_pmu_event_attrs[] = {TAD_PMU_EVENT_ATTR (tad_hit_ltg,0x1e ),TAD_PMU_EVENT_ATTR (tad_hit_any,0x1f ),TAD_PMU_EVENT_ATTR (tad_tag_rd,0x20 ), -TAD_PMU_EVENT_ATTR (tad_tot_cycle,0xFF ), +TAD_PMU_EVENT_ATTR (tad_tot_cycle,0xff ), NULL };
@@ -242,9 +317,13 @@ static const struct attribute_group ody_tad_pmu_events_attr_group = { };PMU_FORMAT_ATTR (event,"config:0-7" ); +PMU_FORMAT_ATTR (partid,"config1:0-8" ); +PMU_FORMAT_ATTR (partid_en,"config1:9-9" );static struct attribute *tad_pmu_format_attrs[] = { &format_attr_event.attr, + &format_attr_partid.attr, + &format_attr_partid_en.attr,NULL };
@@ -253,6 +332,16 @@ static struct attribute_group tad_pmu_format_attr_group = { .attrs = tad_pmu_format_attrs, }; +static struct attribute *ody_tad_pmu_format_attrs[] = { + &format_attr_event.attr, +NULL +}; + +static struct attribute_group ody_tad_pmu_format_attr_group = { + .name ="format" , + .attrs = ody_tad_pmu_format_attrs, +}; +static ssize_t tad_pmu_cpumask_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -281,16 +370,25 @@ static const struct attribute_group *tad_pmu_attr_groups[] = {static const struct attribute_group *ody_tad_pmu_attr_groups[] = { &ody_tad_pmu_events_attr_group, - &tad_pmu_format_attr_group, + &ody_tad_pmu_format_attr_group, &tad_pmu_cpumask_attr_group,NULL }; +static const struct tad_pmu_ops tad_pmu_ops = { + .start_counter = tad_pmu_start_counter, +}; + +static const struct tad_pmu_ops tad_pmu_v2_ops = { + .start_counter = tad_pmu_v2_start_counter, +}; +static int tad_pmu_probe (struct platform_device *pdev) {const struct tad_pmu_data *dev_data;struct device *dev = &pdev->dev;struct tad_region *regions; +resource_size_t map_start;struct tad_pmu *tad_pmu;struct resource *res;u32 tad_pmu_page_size;
@@ -298,7 +396,6 @@ static int tad_pmu_probe(struct platform_device *pdev)u32 tad_cnt;int version;int i, ret; -char *name; tad_pmu =devm_kzalloc (&pdev->dev,sizeof (*tad_pmu),GFP_KERNEL );if (!tad_pmu)
@@ -312,6 +409,7 @@ static int tad_pmu_probe(struct platform_device *pdev)return -ENODEV ; } version = dev_data->id; + tad_pmu->pdata = dev_data; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res) {
@@ -338,22 +436,31 @@ static int tad_pmu_probe(struct platform_device *pdev)dev_err (&pdev->dev,"Can't find tad-cnt property\n" );return ret; } +if (!tad_cnt || !tad_page_size || !tad_pmu_page_size) { +dev_err (&pdev->dev,"Invalid tad-cnt or page size\n" ); +return -EINVAL ; + } regions =devm_kcalloc (&pdev->dev, tad_cnt,sizeof (*regions),GFP_KERNEL );if (!regions)return -ENOMEM ; -/* ioremap the distributed TAD pmu regions */ -for (i =0 ; i < tad_cnt && res->start < res->end; i++) { - regions[i].base =devm_ioremap (&pdev->dev, - res->start, + map_start = res->start; +for (i =0 ; i < tad_cnt; i++) { +if (map_start > res->end || + tad_pmu_page_size > (resource_size_t)(res->end - map_start +1 )) { +dev_err (&pdev->dev,"TAD PMU mem window too small for tad-cnt=%u\n" , + tad_cnt); +return -EINVAL ; + } + regions[i].base =devm_ioremap (&pdev->dev, map_start, tad_pmu_page_size);if (!regions[i].base) {dev_err (&pdev->dev,"TAD%d ioremap fail\n" , i);return -ENOMEM ; } - res->start += tad_page_size; + map_start += tad_page_size; } tad_pmu->regions = regions;
@@ -374,14 +481,16 @@ static int tad_pmu_probe(struct platform_device *pdev) .read = tad_pmu_event_counter_read, }; -if (version ==TAD_PMU_V1 ) +if (version ==TAD_PMU_V1 ) { tad_pmu->pmu.attr_groups = tad_pmu_attr_groups; -else + tad_pmu->ops = &tad_pmu_ops; + }else { tad_pmu->pmu.attr_groups = ody_tad_pmu_attr_groups; + tad_pmu->ops = &tad_pmu_v2_ops; + } tad_pmu->cpu =raw_smp_processor_id (); -/* Register pmu instance for cpu hotplug */ ret =cpuhp_state_add_instance_nocalls (tad_pmu_cpuhp_state, &tad_pmu->node);if (ret) {
@@ -389,19 +498,24 @@ static int tad_pmu_probe(struct platform_device *pdev)return ret; } - name ="tad" ; - ret =perf_pmu_register (&tad_pmu->pmu, name,-1 ); -if (ret) + ret =perf_pmu_register (&tad_pmu->pmu,"tad" ,-1 ); +if (ret) { +dev_err (&pdev->dev,"Error %d registering perf PMU\n" , ret);cpuhp_state_remove_instance_nocalls (tad_pmu_cpuhp_state, &tad_pmu->node); +return ret; + } -return ret; +WRITE_ONCE (tad_pmu->perf_ready, true); + +return 0 ; }static void tad_pmu_remove (struct platform_device *pdev) {struct tad_pmu *pmu =platform_get_drvdata (pdev); +WRITE_ONCE (pmu->perf_ready, false);cpuhp_state_remove_instance_nocalls (tad_pmu_cpuhp_state, &pmu->node);perf_pmu_unregister (&pmu->pmu);
@@ -410,12 +524,17 @@ static void tad_pmu_remove(struct platform_device *pdev)#if defined(CONFIG_OF ) || defined(CONFIG_ACPI )static const struct tad_pmu_data tad_pmu_data = { .id =TAD_PMU_V1 , + .tad_prf_offset =TAD_PRF_OFFSET , + .tad_pfc_offset =TAD_PFC_OFFSET , }; +#endif #ifdef CONFIG_ACPI static const struct tad_pmu_data tad_pmu_v2_data = { .id =TAD_PMU_V2 , + .tad_prf_offset =TAD_PRF_OFFSET , + .tad_pfc_offset =TAD_PFC_OFFSET , };#endif
@@ -451,6 +570,9 @@ static int tad_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) struct tad_pmu *pmu = hlist_entry_safe(node, struct tad_pmu, node);unsigned int target; +if (!READ_ONCE (pmu->perf_ready)) +return 0 ; +if (cpu != pmu->cpu)return 0 ;
@@ -491,6 +613,6 @@ static void __exit tad_pmu_exit(void)module_init (tad_pmu_init);module_exit (tad_pmu_exit); -MODULE_DESCRIPTION ("Marvell CN10K LLC-TAD Perf driver" ); +MODULE_DESCRIPTION ("Marvell CN10K LLC-TAD perf driver" );MODULE_AUTHOR ("Bhaskara Budiredla <[email protected]>" );MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH v4 1/3] perf: marvell: Add MPAM partid filtering to CN10K TAD PMU
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The `perf_ready` early return in `tad_pmu_offline_cpu()` completely skips updating `pmu->cpu`…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The perf_ready early return in tad_pmu_offline_cpu() completely skips updating pmu->cpu, potentially pinning the PMU to an offline CPU permanently.
- [Medium] The commit message contradicts the implementation regarding the registration order of the PMU and CPU hotplug instance.
--
commit c5919d39926621f8d8420dda8d78271eeeb122e2
Author: Tanmay Jagdale <[email protected]>
Subject: perf: marvell: Add MPAM partid filtering to CN10K TAD PMU
This commit adds MPAM partition ID filtering to the CN10K TAD PMU. It updates the counter programming to use MPAM-capable filtering for specific events. It also modifies the probe function's MMIO mapping and attempts to address hotplug registration races.
Quoted 4 lines
Probe no longer mutates the
platform_deviceMMIO resource (walk a localmap_start), rejects tad-cnt / page sizes of zero, validates the memory window against tad-cnt, and registers the perf PMU before hotplug with correct unwind.
[Severity: Medium]
The commit message states that it "registers the perf PMU before hotplug with correct unwind", but looking at tad_pmu_probe(), the hotplug instance is still registered before the perf PMU:
ret = cpuhp_state_add_instance_nocalls(tad_pmu_cpuhp_state,
&tad_pmu->node);
if (ret) {
dev_err(&pdev->dev, "Error %d registering hotplug\n", ret);
return ret;
}
ret = perf_pmu_register(&tad_pmu->pmu, "tad", -1);Could the commit message be updated, or was the code reordering missed?
Quoted 4 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-0
[ ... ]
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) · line 575
Quoted 7 lines
drivers/perf/marvell_cn10k_tad_pmu.c +3
-0@@ -451,6 +570,9 @@ static int tad_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) struct tad_pmu *pmu = hlist_entry_safe(node, struct tad_pmu, node);unsigned int target; +if (!READ_ONCE (pmu->perf_ready)) +return 0 ; +
[Severity: High]
If the originally assigned CPU goes offline during the race window between cpuhp_state_add_instance_nocalls() and the setting of perf_ready = true in tad_pmu_probe(), does this early return skip reassigning pmu->cpu?
Since this driver does not define an online CPU hotplug callback, if tad_pmu_offline_cpu() returns early here, could pmu->cpu permanently remain assigned to the offline CPU and break the PMU once registration finishes?
Quoted 3 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-0if (cpu != pmu->cpu)return 0 ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v4 1/3] perf: marvell: Add MPAM partid filtering to CN10K TAD PMU
In reply to Geetha sowjanyaHi Geetha,
+CC James
Quoted 9 lines · Geetha sowjanya
From: Tanmay Jagdale <[email protected]>
The TAD PMU exposes counters that can be filtered by MPAM partition id for a subset of allocation and hit events.
Add a 9-bit partid format attribute (config1) and route counter programming through variant-specific ops so CN10K keeps MPAM-capable programming while Odyssey keeps the reduced event set without advertising partid in sysfs.
Quoted 7 lines
Probe no longer mutates the
platform_deviceMMIO resource (walk a localmap_start), rejects tad-cnt / page sizes of zero, validates the memory window against tad-cnt, and registers the perf PMU before hotplug with correct unwind.Example:
perf stat -e tad/tad_alloc_any,partid=0x12,partid_en=1/ -- <program>
Where is the user expected to get the PARTID from? The MPAM driver considers the PARTID as an internal only value.
resctrl does support a 'debug' mount option which will show the CLOSID associated with a control group. Whilst the CLOSID is often the PARTID, it is really a set of PARTIDs. When the cdp mount option is used, CLOSID maps to 2 PARTIDs and if we use PARTID narrowing to give us more monitors, as in proposed in [1], then the set of PARTIDs may be bigger. Furthermore, if the PARTID narrowing scheme is made dynamic the size of the PARTID set may change when control or monitoring groups are created or deleted.
It seems that a way to map from a resctrl control group to the set of PARTIDs is required and a mechanism to tie this to lifetime of the resctrl mount.
Perhaps some helpers along the lines of:
int resctrl_mount_generation(void)
int mpam_rdtgrp_to_partid_is_static(int mount_gen)
int resctrl_rdtgrp_generation(char *name)
int mpam_rdtgrp_to_partid_count(char *name, int rdt_gen) int mpam_rdtgrp_to_partid_array(char *name, int rdt_gen, int* partids)
The rdtgrp generation is to an attempt to avoid having to use a debug interface in anger and cope with renaming of control groups in resctrl. This does seem a bit unwieldly so hopefully there is better way to do this.
Sorry to throw a spanner in the works.
Thanks,
Ben
Quoted 471 lines
Signed-off-by Tanmay Jagdale <[email protected]>Signed-off-by Geetha sowjanya <[email protected]>---
Changelog (since v3)
--------------------
- Restorecpuhp_state_add_instance_nocallsbeforeperf_pmu_registerin probe so users cannot attach events before the hotplug instance exists; unwind removes the hotplug instance if perf registration fails.
- Addperf_ready:tad_pmu_offline_cpuskipsperf_pmu_migrate_contextuntil after successfulperf_pmu_register, so a CPU offline between hotplug add and perf register does not touch perf core state for an unregistered PMU.Changelog (since v2)
--------------------
- Validate the eventId using an appropriate mask to ensure it is restricted to 8 bits.Changelog (since v1)
--------------------
- Fix config1 filter enable to use bit 9 consistently with the PMU format string (partid_en) and reject reserved bits withGENMASK(9, 0).
- Registerperf_pmu_registerbeforecpuhp_state_add_instance_nocallsand unregister on hotplug failure.drivers/perf/marvell_cn10k_tad_pmu.c | 220 +++++++++++++++++++++------ 1 file changed, 171 insertions(+), 49 deletions(-)drivers/perf/marvell_cn10k_tad_pmu.c +171
-49@@ -7,6 +7,8 @@#define pr_fmt (fmt) "tad_pmu: " fmt#include <linux/io.h> +#include <linux/bits.h> +#include <linux/compiler.h> #include <linux/module.h> #include <linux/of.h> #include <linux/cpuhotplug.h> @@ -14,12 +16,20 @@#include <linux/platform_device.h> #include <linux/acpi.h> -#define TAD_PFC_OFFSET 0x800 -#define TAD_PFC (counter) (TAD_PFC_OFFSET | (counter << 3))#define TAD_PRF_OFFSET 0x900 -#define TAD_PRF (counter) (TAD_PRF_OFFSET | (counter << 3)) +#define TAD_PFC_OFFSET 0x800 +#define TAD_PFC (base, counter) ((base) | ((u64)(counter) << 3)) +#define TAD_PRF (base, counter) ((base) | ((u64)(counter) << 3))#define TAD_PRF_CNTSEL_MASK 0xFF +#define TAD_PRF_MATCH_PARTID BIT(8) +#define TAD_PRF_PARTID_NS BIT(10) +/* +* config1: bits 0..8 MPAM partition id (including 0); bit 9 requests +* filtering for MPAM-capable events. All-zero config1 means no filter. +*/ +#define TAD_PARTID_FILTER_EN BIT(9)#define TAD_MAX_COUNTERS 8 +#define TAD_EVENT_SEL_MASK GENMASK(7, 0)#define to_tad_pmu (p) (container_of(p, struct tad_pmu, pmu))@@ -27,30 +37,94 @@ struct tad_region {void __iomem *base; }; +enum mrvl_tad_pmu_version { +TAD_PMU_V1 =1 , +TAD_PMU_V2 , +}; + +struct tad_pmu_data { +int id; +u64 tad_prf_offset; +u64 tad_pfc_offset; +}; +struct tad_pmu {struct pmu pmu;struct tad_region *regions;u32 region_cnt;unsigned int cpu; +/* Set after successful perf_pmu_register(); gates offline migration. */ +bool perf_ready; +const struct tad_pmu_ops *ops; +const struct tad_pmu_data *pdata;struct hlist_node node;struct perf_event *events[TAD_MAX_COUNTERS ]; DECLARE_BITMAP(counters_map, TAD_MAX_COUNTERS); }; -enum mrvl_tad_pmu_version { -TAD_PMU_V1 =1 , -TAD_PMU_V2 , -}; - -struct tad_pmu_data { -int id; +struct tad_pmu_ops { +void (*start_counter)(struct tad_pmu *pmu,struct perf_event *event); };static int tad_pmu_cpuhp_state; +static void tad_pmu_start_counter (struct tad_pmu *pmu, +struct perf_event *event) +{ +const struct tad_pmu_data *pdata = pmu->pdata; +struct hw_perf_event *hwc = &event->hw; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u32 counter_idx = hwc->idx; +u64 partid_filter =0 ; +u64 reg_val; +u64 cfg1 = event->attr.config1; +bool use_mpam = cfg1 &TAD_PARTID_FILTER_EN ; +u32 partid = (u32)(cfg1 &GENMASK (8 ,0 )); +int i; + +for (i =0 ; i < pmu->region_cnt; i++) +writeq_relaxed (0 , pmu->regions[i].base + +TAD_PFC (pdata->tad_pfc_offset, counter_idx)); + +if (use_mpam && event_idx >0x19 && event_idx <0x21 ) { + partid_filter =TAD_PRF_MATCH_PARTID |TAD_PRF_PARTID_NS | + ((u64 )partid <<11 ); + } + + +for (i =0 ; i < pmu->region_cnt; i++) { + reg_val = event_idx &0xFF ; + reg_val |= partid_filter; +writeq_relaxed (reg_val, pmu->regions[i].base + +TAD_PRF (pdata->tad_prf_offset, counter_idx)); + } +} + +static void tad_pmu_v2_start_counter (struct tad_pmu *pmu, +struct perf_event *event) +{ +const struct tad_pmu_data *pdata = pmu->pdata; +struct hw_perf_event *hwc = &event->hw; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u32 counter_idx = hwc->idx; +u64 reg_val; +int i; + +for (i =0 ; i < pmu->region_cnt; i++) +writeq_relaxed (0 , pmu->regions[i].base + +TAD_PFC (pdata->tad_pfc_offset, counter_idx)); + +for (i =0 ; i < pmu->region_cnt; i++) { + reg_val = event_idx &0xFF ; +writeq_relaxed (reg_val, pmu->regions[i].base + +TAD_PRF (pdata->tad_prf_offset, counter_idx)); + } +} +static void tad_pmu_event_counter_read (struct perf_event *event) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata;struct hw_perf_event *hwc = &event->hw;u32 counter_idx = hwc->idx;u64 prev, new;@@ -60,7 +134,7 @@ static void tad_pmu_event_counter_read(struct perf_event *event) prev =local64_read (&hwc->prev_count);for (i =0 , new =0 ; i < tad_pmu->region_cnt; i++) new +=readq (tad_pmu->regions[i].base + -TAD_PFC (counter_idx)); +TAD_PFC (pdata->tad_pfc_offset, counter_idx)); }while (local64_cmpxchg (&hwc->prev_count, prev, new) != prev);local64_add (new - prev, &event->count);@@ -69,16 +143,14 @@ static void tad_pmu_event_counter_read(struct perf_event *event)static void tad_pmu_event_counter_stop (struct perf_event *event,int flags) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata;struct hw_perf_event *hwc = &event->hw;u32 counter_idx = hwc->idx;int i; -/* TAD()_PFC() stop counting on the write -* which sets TAD()_PRF()[CNTSEL] == 0 -*/ for (i =0 ; i < tad_pmu->region_cnt; i++) {writeq_relaxed (0 , tad_pmu->regions[i].base + -TAD_PRF (counter_idx)); +TAD_PRF (pdata->tad_prf_offset, counter_idx)); }tad_pmu_event_counter_read (event);@@ -89,26 +161,10 @@ static void tad_pmu_event_counter_start(struct perf_event *event, int flags) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu);struct hw_perf_event *hwc = &event->hw; -u32 event_idx = event->attr.config; -u32 counter_idx = hwc->idx; -u64 reg_val; -int i; hwc->state =0 ; -/* Typically TAD_PFC() are zeroed to start counting */ -for (i =0 ; i < tad_pmu->region_cnt; i++) -writeq_relaxed (0 , tad_pmu->regions[i].base + -TAD_PFC (counter_idx)); - -/* TAD()_PFC() start counting on the write -* which sets TAD()_PRF()[CNTSEL] != 0 -*/ -for (i =0 ; i < tad_pmu->region_cnt; i++) { - reg_val = event_idx &0xFF ; -writeq_relaxed (reg_val, tad_pmu->regions[i].base + -TAD_PRF (counter_idx)); - } + tad_pmu->ops->start_counter (tad_pmu, event); }static void tad_pmu_event_counter_del (struct perf_event *event,int flags)@@ -128,7 +184,6 @@ static int tad_pmu_event_counter_add(struct perf_event *event, int flags)struct hw_perf_event *hwc = &event->hw;int idx; -/* Get a free counter for this event */ idx =find_first_zero_bit (tad_pmu->counters_map,TAD_MAX_COUNTERS );if (idx ==TAD_MAX_COUNTERS )return -EAGAIN ;@@ -148,6 +203,9 @@ static int tad_pmu_event_counter_add(struct perf_event *event, int flags)static int tad_pmu_event_init (struct perf_event *event) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u64 cfg1 = event->attr.config1;if (event->attr.type != event->pmu->type)return -ENOENT ;@@ -158,6 +216,23 @@ static int tad_pmu_event_init(struct perf_event *event)if (event->state !=PERF_EVENT_STATE_OFF )return -EINVAL ; +if (event->attr.config & ~TAD_EVENT_SEL_MASK ) +return -EINVAL ; + +if (pdata->id ==TAD_PMU_V2 ) { +if (cfg1) +return -EINVAL ; + }else { +if ((cfg1 &GENMASK (8 ,0 )) && !(cfg1 &TAD_PARTID_FILTER_EN )) +return -EINVAL ; +if (cfg1 &TAD_PARTID_FILTER_EN ) { +if (event_idx <=0x19 || event_idx >=0x21 ) +return -EINVAL ; + } +if (cfg1 & ~GENMASK (9 ,0 )) +return -EINVAL ; + } + event->cpu = tad_pmu->cpu; event->hw.idx =-1 ; event->hw.config_base = event->attr.config;@@ -232,7 +307,7 @@ static struct attribute *ody_tad_pmu_event_attrs[] = {TAD_PMU_EVENT_ATTR (tad_hit_ltg,0x1e ),TAD_PMU_EVENT_ATTR (tad_hit_any,0x1f ),TAD_PMU_EVENT_ATTR (tad_tag_rd,0x20 ), -TAD_PMU_EVENT_ATTR (tad_tot_cycle,0xFF ), +TAD_PMU_EVENT_ATTR (tad_tot_cycle,0xff ), NULL };@@ -242,9 +317,13 @@ static const struct attribute_group ody_tad_pmu_events_attr_group = { };PMU_FORMAT_ATTR (event,"config:0-7" ); +PMU_FORMAT_ATTR (partid,"config1:0-8" ); +PMU_FORMAT_ATTR (partid_en,"config1:9-9" );static struct attribute *tad_pmu_format_attrs[] = { &format_attr_event.attr, + &format_attr_partid.attr, + &format_attr_partid_en.attr,NULL };@@ -253,6 +332,16 @@ static struct attribute_group tad_pmu_format_attr_group = { .attrs = tad_pmu_format_attrs, }; +static struct attribute *ody_tad_pmu_format_attrs[] = { + &format_attr_event.attr, +NULL +}; + +static struct attribute_group ody_tad_pmu_format_attr_group = { + .name ="format" , + .attrs = ody_tad_pmu_format_attrs, +}; +static ssize_t tad_pmu_cpumask_show (struct device *dev,struct device_attribute *attr,char *buf) {@@ -281,16 +370,25 @@ static const struct attribute_group *tad_pmu_attr_groups[] = {static const struct attribute_group *ody_tad_pmu_attr_groups[] = { &ody_tad_pmu_events_attr_group, - &tad_pmu_format_attr_group, + &ody_tad_pmu_format_attr_group, &tad_pmu_cpumask_attr_group,NULL }; +static const struct tad_pmu_ops tad_pmu_ops = { + .start_counter = tad_pmu_start_counter, +}; + +static const struct tad_pmu_ops tad_pmu_v2_ops = { + .start_counter = tad_pmu_v2_start_counter, +}; +static int tad_pmu_probe (struct platform_device *pdev) {const struct tad_pmu_data *dev_data;struct device *dev = &pdev->dev;struct tad_region *regions; +resource_size_t map_start;struct tad_pmu *tad_pmu;struct resource *res;u32 tad_pmu_page_size;@@ -298,7 +396,6 @@ static int tad_pmu_probe(struct platform_device *pdev)u32 tad_cnt;int version;int i, ret; -char *name; tad_pmu =devm_kzalloc (&pdev->dev,sizeof (*tad_pmu),GFP_KERNEL );if (!tad_pmu)@@ -312,6 +409,7 @@ static int tad_pmu_probe(struct platform_device *pdev)return -ENODEV ; } version = dev_data->id; + tad_pmu->pdata = dev_data; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res) {@@ -338,22 +436,31 @@ static int tad_pmu_probe(struct platform_device *pdev)dev_err (&pdev->dev,"Can't find tad-cnt property\n" );return ret; } +if (!tad_cnt || !tad_page_size || !tad_pmu_page_size) { +dev_err (&pdev->dev,"Invalid tad-cnt or page size\n" ); +return -EINVAL ; + } regions =devm_kcalloc (&pdev->dev, tad_cnt,sizeof (*regions),GFP_KERNEL );if (!regions)return -ENOMEM ; -/* ioremap the distributed TAD pmu regions */ -for (i =0 ; i < tad_cnt && res->start < res->end; i++) { - regions[i].base =devm_ioremap (&pdev->dev, - res->start, + map_start = res->start; +for (i =0 ; i < tad_cnt; i++) { +if (map_start > res->end || + tad_pmu_page_size > (resource_size_t)(res->end - map_start +1 )) { +dev_err (&pdev->dev,"TAD PMU mem window too small for tad-cnt=%u\n" , + tad_cnt); +return -EINVAL ; + } + regions[i].base =devm_ioremap (&pdev->dev, map_start, tad_pmu_page_size);if (!regions[i].base) {dev_err (&pdev->dev,"TAD%d ioremap fail\n" , i);return -ENOMEM ; } - res->start += tad_page_size; + map_start += tad_page_size; } tad_pmu->regions = regions;@@ -374,14 +481,16 @@ static int tad_pmu_probe(struct platform_device *pdev) .read = tad_pmu_event_counter_read, }; -if (version ==TAD_PMU_V1 ) +if (version ==TAD_PMU_V1 ) { tad_pmu->pmu.attr_groups = tad_pmu_attr_groups; -else + tad_pmu->ops = &tad_pmu_ops; + }else { tad_pmu->pmu.attr_groups = ody_tad_pmu_attr_groups; + tad_pmu->ops = &tad_pmu_v2_ops; + } tad_pmu->cpu =raw_smp_processor_id (); -/* Register pmu instance for cpu hotplug */ ret =cpuhp_state_add_instance_nocalls (tad_pmu_cpuhp_state, &tad_pmu->node);if (ret) {@@ -389,19 +498,24 @@ static int tad_pmu_probe(struct platform_device *pdev)return ret; } - name ="tad" ; - ret =perf_pmu_register (&tad_pmu->pmu, name,-1 ); -if (ret) + ret =perf_pmu_register (&tad_pmu->pmu,"tad" ,-1 ); +if (ret) { +dev_err (&pdev->dev,"Error %d registering perf PMU\n" , ret);cpuhp_state_remove_instance_nocalls (tad_pmu_cpuhp_state, &tad_pmu->node); +return ret; + } -return ret; +WRITE_ONCE (tad_pmu->perf_ready, true); + +return 0 ; }static void tad_pmu_remove (struct platform_device *pdev) {struct tad_pmu *pmu =platform_get_drvdata (pdev); +WRITE_ONCE (pmu->perf_ready, false);cpuhp_state_remove_instance_nocalls (tad_pmu_cpuhp_state, &pmu->node);perf_pmu_unregister (&pmu->pmu);@@ -410,12 +524,17 @@ static void tad_pmu_remove(struct platform_device *pdev)#if defined(CONFIG_OF ) || defined(CONFIG_ACPI )static const struct tad_pmu_data tad_pmu_data = { .id =TAD_PMU_V1 , + .tad_prf_offset =TAD_PRF_OFFSET , + .tad_pfc_offset =TAD_PFC_OFFSET , }; +#endif #ifdef CONFIG_ACPI static const struct tad_pmu_data tad_pmu_v2_data = { .id =TAD_PMU_V2 , + .tad_prf_offset =TAD_PRF_OFFSET , + .tad_pfc_offset =TAD_PFC_OFFSET , };#endif @@ -451,6 +570,9 @@ static int tad_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) struct tad_pmu *pmu = hlist_entry_safe(node, struct tad_pmu, node);unsigned int target; +if (!READ_ONCE (pmu->perf_ready)) +return 0 ; +if (cpu != pmu->cpu)return 0 ;@@ -491,6 +613,6 @@ static void __exit tad_pmu_exit(void)module_init (tad_pmu_init);module_exit (tad_pmu_exit); -MODULE_DESCRIPTION ("Marvell CN10K LLC-TAD Perf driver" ); +MODULE_DESCRIPTION ("Marvell CN10K LLC-TAD perf driver" );MODULE_AUTHOR ("Bhaskara Budiredla <[email protected]>" );MODULE_LICENSE ("GPL v2" );
RE: [EXTERNAL] Re: [PATCH v4 1/3] perf: marvell: Add MPAM partid filtering to CN10K TAD PMU
Quoted 63 lines
-----Original Message-----
From: Ben Horgan <[email protected]>
Sent: Thursday, June 25, 2026 7:23 PM
To: Geethasowjanya Akula <[email protected]>; linux-perf- [email protected]; [email protected]; linux-arm- [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXTERNAL] Re: [PATCH v4 1/3] perf: marvell: Add MPAM partid filtering to CN10K TAD PMU
Hi Geetha,+CC James
Quoted 8 lines · Geetha sowjanya
From: Tanmay Jagdale <[email protected]>
The TAD PMU exposes counters that can be filtered by MPAM partition id for a subset of allocation and hit events.
Add a 9-bit partid format attribute (config1) and route counter programming through variant-specific ops so CN10K keeps MPAM-capable programming while Odyssey keeps the reduced event set without advertising
partid in sysfs.
Quoted 8 lines
Probe no longer mutates the
platform_deviceMMIO resource (walk a localmap_start), rejects tad-cnt / page sizes of zero, validates the memory window against tad-cnt, and registers the perf PMU before hotplug with correct unwind.Example:
perf stat -e tad/tad_alloc_any,partid=0x12,partid_en=1/ -- <program>Where is the user expected to get the PARTID from? The MPAM driver considers the PARTID as an internal only value.
resctrl does support a 'debug' mount option which will show the CLOSID associated with a control group. Whilst the CLOSID is often the PARTID, it is really a set of PARTIDs. When the cdp mount option is used, CLOSID maps to 2 PARTIDs and if we use PARTID narrowing to give us more monitors, as in proposed in [1], then the set of PARTIDs may be bigger. Furthermore, if the PARTID narrowing scheme is made dynamic the size of the PARTID set may change when control or monitoring groups are created or deleted.
It seems that a way to map from a resctrl control group to the set of PARTIDs is required and a mechanism to tie this to lifetime of the resctrl mount.
Perhaps some helpers along the lines of:
int
resctrl_mount_generation(void)
intmpam_rdtgrp_to_partid_is_static(int mount_gen)intresctrl_rdtgrp_generation(char *name)intmpam_rdtgrp_to_partid_count(char *name, int rdt_gen)intmpam_rdtgrp_to_partid_array(char *name, int rdt_gen, int* partids)The rdtgrp generation is to an attempt to avoid having to use a debug interface in anger and cope with renaming of control groups in resctrl.
This does seem a bit unwieldly so hopefully there is better way to do this.Sorry to throw a spanner in the works.
Quoted 6 lines · On …, … wrote:
Where is the user expected to get the PARTID from? The MPAM driver considers the PARTID as an internal only value.
…
Perhaps some helpers along the lines of:
intresctrl_mount_generation(void)
…
Hi Ben,
Thank you for the detailed feedback — the concern you raise is valid, particularly when viewed from the perspective of resctrl-managed deployments.
However, to clarify the intent of this patch: the exposure of partid in the TAD PMU is deliberately a low-level, hardware-facing interface, and is not intended to integrate with or mirror the abstractions provided by resctrl. It is mainly meant for platform bring-up and low-level performance/debug users, who already have explicit knowledge of the MPAM configuration, typically provisioned by firmware or other privileged software layers (e.g. EL3/EL2). In such environments, PARTIDs are known out-of-band, so the expectation is that the user supplying partid is already aware of the MPAM IDs programmed on the system.
A proper “profile this resctrl group” path would require MPAM–resctrl support (e.g. something along the lines of the helpers you suggest) to resolve a group to its PARTID set. This is indeed important, but it constitutes a separate design discussion that is outside the scope of this driver patch.
We will clarify this in the commit message and avoid implying that users normally obtain PARTIDs from resctrl today.
Thanks,
Geetha
Quoted 492 lines
Thanks,
Ben
Quoted 8 lines
Signed-off-by Tanmay Jagdale <[email protected]>Signed-off-by Geetha sowjanya <[email protected]>---
Changelog (since v3)
--------------------
- Restorecpuhp_state_add_instance_nocallsbeforeperf_pmu_registerinprobe
Quoted 3 lines
so users cannot attach events before the hotplug instance exists; unwind removes the hotplug instance if perf registration fails.
- Addperf_ready:tad_pmu_offline_cpuskipsperf_pmu_migrate_contextuntil after
Quoted 1 line
successful
perf_pmu_register, so a CPU offline between hotplug add andperf
Quoted 108 lines
register does not touch perf core state for an unregistered PMU.
Changelog (since v2)
--------------------
- Validate the eventId using an appropriate mask to ensure it is restricted to 8 bits.Changelog (since v1)
--------------------
- Fix config1 filter enable to use bit 9 consistently with the PMU format string (partid_en) and reject reserved bits withGENMASK(9, 0).
- Registerperf_pmu_registerbeforecpuhp_state_add_instance_nocallsand unregister on hotplug failure.drivers/perf/marvell_cn10k_tad_pmu.c | 220 +++++++++++++++++++++------ 1 file changed, 171 insertions(+), 49 deletions(-)drivers/perf/marvell_cn10k_tad_pmu.c +41
-10@@ -7,6 +7,8 @@#define pr_fmt (fmt) "tad_pmu: " fmt#include <linux/io.h> +#include <linux/bits.h> +#include <linux/compiler.h> #include <linux/module.h> #include <linux/of.h> #include <linux/cpuhotplug.h> @@ -14,12 +16,20 @@#include <linux/platform_device.h> #include <linux/acpi.h> -#define TAD_PFC_OFFSET 0x800 -#define TAD_PFC (counter) (TAD_PFC_OFFSET | (counter << 3))#define TAD_PRF_OFFSET 0x900 -#define TAD_PRF (counter) (TAD_PRF_OFFSET | (counter << 3)) +#define TAD_PFC_OFFSET 0x800 +#define TAD_PFC (base, counter) ((base) | ((u64)(counter) << 3)) +#define TAD_PRF (base, counter) ((base) | ((u64)(counter) << 3))#define TAD_PRF_CNTSEL_MASK 0xFF +#define TAD_PRF_MATCH_PARTID BIT(8) +#define TAD_PRF_PARTID_NS BIT(10) +/* +* config1: bits 0..8 MPAM partition id (including 0); bit 9 requests +* filtering for MPAM-capable events. All-zero config1 means no filter. +*/ +#define TAD_PARTID_FILTER_EN BIT(9)#define TAD_MAX_COUNTERS 8 +#define TAD_EVENT_SEL_MASK GENMASK(7, 0)#define to_tad_pmu (p) (container_of(p, struct tad_pmu, pmu))@@ -27,30 +37,94 @@ struct tad_region {void __iomem *base; }; +enum mrvl_tad_pmu_version { +TAD_PMU_V1 =1 , +TAD_PMU_V2 , +}; + +struct tad_pmu_data { +int id; +u64 tad_prf_offset; +u64 tad_pfc_offset; +}; +struct tad_pmu {struct pmu pmu;struct tad_region *regions;u32 region_cnt;unsigned int cpu; +/* Set after successful perf_pmu_register(); gates offline migration. */ +bool perf_ready; +const struct tad_pmu_ops *ops; +const struct tad_pmu_data *pdata;struct hlist_node node;struct perf_event *events[TAD_MAX_COUNTERS ]; DECLARE_BITMAP(counters_map, TAD_MAX_COUNTERS); }; -enum mrvl_tad_pmu_version { -TAD_PMU_V1 =1 , -TAD_PMU_V2 , -}; - -struct tad_pmu_data { -int id; +struct tad_pmu_ops { +void (*start_counter)(struct tad_pmu *pmu,struct perf_event +*event); };static int tad_pmu_cpuhp_state; +static void tad_pmu_start_counter (struct tad_pmu *pmu, +struct perf_event *event) +{ +const struct tad_pmu_data *pdata = pmu->pdata; +struct hw_perf_event *hwc = &event->hw; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u32 counter_idx = hwc->idx; +u64 partid_filter =0 ; +u64 reg_val; +u64 cfg1 = event->attr.config1;drivers/perf/marvell_cn10k_tad_pmu.c struct tad_region { · line 90
Quoted 10 lines
drivers/perf/marvell_cn10k_tad_pmu.c +10
-0+bool use_mpam = cfg1 &TAD_PARTID_FILTER_EN ; +u32 partid = (u32)(cfg1 &GENMASK (8 ,0 )); +int i; + +for (i =0 ; i < pmu->region_cnt; i++) +writeq_relaxed (0 , pmu->regions[i].base + +TAD_PFC (pdata->tad_pfc_offset, counter_idx)); + +if (use_mpam && event_idx >0x19 && event_idx <0x21 ) { + partid_filter = TAD_PRF_MATCH_PARTID |
TAD_PRF_PARTID_NS|drivers/perf/marvell_cn10k_tad_pmu.c static void tad_pmu_event_counter_read(struct
Quoted 40 lines
drivers/perf/marvell_cn10k_tad_pmu.c +34
-0+ ((u64 )partid <<11 ); + } + + +for (i =0 ; i < pmu->region_cnt; i++) { + reg_val = event_idx &0xFF ; + reg_val |= partid_filter; +writeq_relaxed (reg_val, pmu->regions[i].base + +TAD_PRF (pdata->tad_prf_offset, counter_idx)); + } +} + +static void tad_pmu_v2_start_counter (struct tad_pmu *pmu, +struct perf_event *event) +{ +const struct tad_pmu_data *pdata = pmu->pdata; +struct hw_perf_event *hwc = &event->hw; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u32 counter_idx = hwc->idx; +u64 reg_val; +int i; + +for (i =0 ; i < pmu->region_cnt; i++) +writeq_relaxed (0 , pmu->regions[i].base + +TAD_PFC (pdata->tad_pfc_offset, counter_idx)); + +for (i =0 ; i < pmu->region_cnt; i++) { + reg_val = event_idx &0xFF ; +writeq_relaxed (reg_val, pmu->regions[i].base + +TAD_PRF (pdata->tad_prf_offset, counter_idx)); + } +} +static void tad_pmu_event_counter_read (struct perf_event *event) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata;struct hw_perf_event *hwc = &event->hw;u32 counter_idx = hwc->idx;u64 prev, new;@@ -60,7 +134,7 @@ static void tad_pmu_event_counter_read(struct
perf_event*event)drivers/perf/marvell_cn10k_tad_pmu.c static void tad_pmu_event_counter_read(struct perf_event *event)
Quoted 5 lines
drivers/perf/marvell_cn10k_tad_pmu.c +1
-1prev =local64_read (&hwc->prev_count);for (i =0 , new =0 ; i < tad_pmu->region_cnt; i++) new +=readq (tad_pmu->regions[i].base + -TAD_PFC (counter_idx)); + TAD_PFC(pdata->tad_pfc_offset,
counter_idx));drivers/perf/marvell_cn10k_tad_pmu.c static void tad_pmu_event_counter_read(struct perf_event *event)
Quoted 3 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-0}while (local64_cmpxchg (&hwc->prev_count, prev, new) != prev); local64_add(new - prev, &event->count); @@ -69,16 +143,14 @@static
Quoted 46 lines
void
tad_pmu_event_counter_read(struct perf_event *event)static voidtad_pmu_event_counter_stop(struct perf_event *event, int flags){drivers/perf/marvell_cn10k_tad_pmu.c +3
-21struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata;struct hw_perf_event *hwc = &event->hw;u32 counter_idx = hwc->idx;int i; -/* TAD()_PFC() stop counting on the write -* which sets TAD()_PRF()[CNTSEL] == 0 -*/ for (i =0 ; i < tad_pmu->region_cnt; i++) {writeq_relaxed (0 , tad_pmu->regions[i].base + -TAD_PRF (counter_idx)); +TAD_PRF (pdata->tad_prf_offset, counter_idx)); }tad_pmu_event_counter_read (event);@@ -89,26 +161,10 @@ static void tad_pmu_event_counter_start(struct perf_event *event, int flags) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu);struct hw_perf_event *hwc = &event->hw; -u32 event_idx = event->attr.config; -u32 counter_idx = hwc->idx; -u64 reg_val; -int i; hwc->state =0 ; -/* Typically TAD_PFC() are zeroed to start counting */ -for (i =0 ; i < tad_pmu->region_cnt; i++) -writeq_relaxed (0 , tad_pmu->regions[i].base + -TAD_PFC (counter_idx)); - -/* TAD()_PFC() start counting on the write -* which sets TAD()_PRF()[CNTSEL] != 0 -*/ -for (i =0 ; i < tad_pmu->region_cnt; i++) { - reg_val = event_idx &0xFF ; -writeq_relaxed (reg_val, tad_pmu->regions[i].base + -TAD_PRF (counter_idx)); - } + tad_pmu->ops->start_counter (tad_pmu, event); } static void tad_pmu_event_counter_del(struct perf_event *event, intQuoted 1 line
flags) @@ -128,7 +184,6 @@ static int tad_pmu_event_counter_add(struct
perf_event*event, int flags)drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_event_counter_add(struct perf_event *event, int flags)
Quoted 5 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-1struct hw_perf_event *hwc = &event->hw;int idx; -/* Get a free counter for this event */ idx = find_first_zero_bit(tad_pmu->counters_map,
TAD_MAX_COUNTERS);drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_event_init(struct perf_event
Quoted 13 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-0if (idx ==TAD_MAX_COUNTERS )return -EAGAIN ;@@ -148,6 +203,9 @@ static int tad_pmu_event_counter_add(struct
perf_event*event, int flags) static inttad_pmu_event_init(struct perf_event *event){drivers/perf/marvell_cn10k_tad_pmu.c +3
-0struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u64 cfg1 = event->attr.config1;if (event->attr.type != event->pmu->type)return -ENOENT ;@@ -158,6 +216,23 @@ static int tad_pmu_event_init(struct perf_event*event)
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_event_init(struct perf_event *event)
Quoted 11 lines
drivers/perf/marvell_cn10k_tad_pmu.c +8
-0if (event->state !=PERF_EVENT_STATE_OFF )return -EINVAL ; +if (event->attr.config & ~TAD_EVENT_SEL_MASK ) +return -EINVAL ; + +if (pdata->id ==TAD_PMU_V2 ) { +if (cfg1) +return -EINVAL ; + }else { + if ((cfg1 & GENMASK(8, 0)) && !(cfg1 &
TAD_PARTID_FILTER_EN))drivers/perf/marvell_cn10k_tad_pmu.c static struct attribute_group
Quoted 36 lines
drivers/perf/marvell_cn10k_tad_pmu.c +9
-0+return -EINVAL ; +if (cfg1 &TAD_PARTID_FILTER_EN ) { +if (event_idx <=0x19 || event_idx >=0x21 ) +return -EINVAL ; + } +if (cfg1 & ~GENMASK (9 ,0 )) +return -EINVAL ; + } + event->cpu = tad_pmu->cpu; event->hw.idx =-1 ; event->hw.config_base = event->attr.config; @@ -232,7 +307,7 @@static struct attribute *ody_tad_pmu_event_attrs[] = {
drivers/perf/marvell_cn10k_tad_pmu.c +5
-1TAD_PMU_EVENT_ATTR (tad_hit_ltg,0x1e ),TAD_PMU_EVENT_ATTR (tad_hit_any,0x1f ),TAD_PMU_EVENT_ATTR (tad_tag_rd,0x20 ), -TAD_PMU_EVENT_ATTR (tad_tot_cycle,0xFF ), +TAD_PMU_EVENT_ATTR (tad_tot_cycle,0xff ), NULL };@@ -242,9 +317,13 @@ static const struct attribute_group ody_tad_pmu_events_attr_group = { };PMU_FORMAT_ATTR (event,"config:0-7" ); +PMU_FORMAT_ATTR (partid,"config1:0-8" );PMU_FORMAT_ATTR (partid_en, +"config1:9-9" );static struct attribute *tad_pmu_format_attrs[] = { &format_attr_event.attr, + &format_attr_partid.attr, + &format_attr_partid_en.attr,NULL };@@ -253,6 +332,16 @@ static struct attribute_group
tad_pmu_format_attr_group= {Quoted 5 lines
drivers/perf/marvell_cn10k_tad_pmu.c +2
-0.attrs = tad_pmu_format_attrs, }; +static struct attribute *ody_tad_pmu_format_attrs[] = { + &format_attr_event.attr,drivers/perf/marvell_cn10k_tad_pmu.c static struct attribute_group tad_pmu_format_attr_group = {
Quoted 10 lines
drivers/perf/marvell_cn10k_tad_pmu.c +8
-0+NULL +}; + +static struct attribute_group ody_tad_pmu_format_attr_group = { + .name ="format" , + .attrs = ody_tad_pmu_format_attrs, +}; +static ssize_t tad_pmu_cpumask_show (struct device *dev, struct device_attribute *attr, char *buf) { @@-281,16 +370,25
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device
Quoted 25 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-0@@ static const struct attribute_group *tad_pmu_attr_groups[] = {static const struct
attribute_group*ody_tad_pmu_attr_groups[] = {drivers/perf/marvell_cn10k_tad_pmu.c +8
-1&ody_tad_pmu_events_attr_group, - &tad_pmu_format_attr_group, + &ody_tad_pmu_format_attr_group, &tad_pmu_cpumask_attr_group, NULL }; +static const struct tad_pmu_ops tad_pmu_ops = { + .start_counter = tad_pmu_start_counter, }; + +static const struct tad_pmu_ops tad_pmu_v2_ops = { + .start_counter = tad_pmu_v2_start_counter, }; +static int tad_pmu_probe (struct platform_device *pdev) {const struct tad_pmu_data *dev_data;struct device *dev = &pdev->dev;struct tad_region *regions; +resource_size_t map_start;struct tad_pmu *tad_pmu;struct resource *res;u32 tad_pmu_page_size;@@ -298,7 +396,6 @@ static int tad_pmu_probe(struct platform_device*pdev)
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device *pdev)
Quoted 6 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-1u32 tad_cnt;int version;int i, ret; -char *name; tad_pmu = devm_kzalloc(&pdev->dev, sizeof(*tad_pmu),
GFP_KERNEL);drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device
Quoted 2 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-0if (!tad_pmu)@@ -312,6 +409,7 @@ static int tad_pmu_probe(struct platform_device*pdev)
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device
Quoted 8 lines
drivers/perf/marvell_cn10k_tad_pmu.c +1
-0return -ENODEV ; } version = dev_data->id; + tad_pmu->pdata = dev_data; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res) {@@ -338,22 +436,31 @@ static int tad_pmu_probe(struct platform_device*pdev)
Quoted 11 lines
drivers/perf/marvell_cn10k_tad_pmu.c +4
-0dev_err (&pdev->dev,"Can't find tad-cnt property\n" );return ret; } +if (!tad_cnt || !tad_page_size || !tad_pmu_page_size) { +dev_err (&pdev->dev,"Invalid tad-cnt or page size\n" ); +return -EINVAL ; + } regions =devm_kcalloc (&pdev->dev, tad_cnt,sizeof (*regions),GFP_KERNEL );if (!regions)drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device *pdev)
Quoted 10 lines
drivers/perf/marvell_cn10k_tad_pmu.c +4
-4return -ENOMEM ; -/* ioremap the distributed TAD pmu regions */ -for (i =0 ; i < tad_cnt && res->start < res->end; i++) { - regions[i].base = devm_ioremap(&pdev->dev, - res->start, + map_start = res->start; + for (i = 0; i < tad_cnt; i++) { + if (map_start > res->end || + tad_pmu_page_size > (resource_size_t)(res->end -
map_start+ 1)) {drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device · line 453
Quoted 1 line
drivers/perf/marvell_cn10k_tad_pmu.c +1
-0+ dev_err(&pdev->dev, "TAD PMU mem window toosmall for tad-cnt=%u\n",
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device
Quoted 15 lines
drivers/perf/marvell_cn10k_tad_pmu.c +5
-1+ tad_cnt); +return -EINVAL ; + } + regions[i].base =devm_ioremap (&pdev->dev, map_start, tad_pmu_page_size);if (!regions[i].base) {dev_err (&pdev->dev,"TAD%d ioremap fail\n" , i);return -ENOMEM ; } - res->start += tad_page_size; + map_start += tad_page_size; } tad_pmu->regions = regions;@@ -374,14 +481,16 @@ static int tad_pmu_probe(struct platform_device*pdev)
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device
Quoted 20 lines
drivers/perf/marvell_cn10k_tad_pmu.c +5
-3.read = tad_pmu_event_counter_read, }; -if (version ==TAD_PMU_V1 ) +if (version ==TAD_PMU_V1 ) { tad_pmu->pmu.attr_groups = tad_pmu_attr_groups; -else + tad_pmu->ops = &tad_pmu_ops; + }else { tad_pmu->pmu.attr_groups = ody_tad_pmu_attr_groups; + tad_pmu->ops = &tad_pmu_v2_ops; + } tad_pmu->cpu =raw_smp_processor_id (); -/* Register pmu instance for cpu hotplug */ ret =cpuhp_state_add_instance_nocalls (tad_pmu_cpuhp_state, &tad_pmu->node);if (ret) {@@ -389,19 +498,24 @@ static int tad_pmu_probe(struct platform_device*pdev)
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_offline_cpu(unsigned int cpu,
Quoted 46 lines
drivers/perf/marvell_cn10k_tad_pmu.c +14
-4return ret; } - name ="tad" ; - ret =perf_pmu_register (&tad_pmu->pmu, name,-1 ); -if (ret) + ret =perf_pmu_register (&tad_pmu->pmu,"tad" ,-1 ); +if (ret) { +dev_err (&pdev->dev,"Error %d registering perf PMU\n" , ret);cpuhp_state_remove_instance_nocalls (tad_pmu_cpuhp_state, &tad_pmu->node); +return ret; + } -return ret; +WRITE_ONCE (tad_pmu->perf_ready, true); + +return 0 ; }static void tad_pmu_remove (struct platform_device *pdev) {struct tad_pmu *pmu =platform_get_drvdata (pdev); +WRITE_ONCE (pmu->perf_ready, false);cpuhp_state_remove_instance_nocalls (tad_pmu_cpuhp_state, &pmu->node);perf_pmu_unregister (&pmu->pmu);@@ -410,12 +524,17 @@ static void tad_pmu_remove(struct platform_device *pdev) #if defined(CONFIG_OF) || defined(CONFIG_ACPI)static const struct tad_pmu_data tad_pmu_data = { .id =TAD_PMU_V1 , + .tad_prf_offset =TAD_PRF_OFFSET , + .tad_pfc_offset =TAD_PFC_OFFSET , }; +#endif #ifdef CONFIG_ACPI static const struct tad_pmu_data tad_pmu_v2_data = { .id =TAD_PMU_V2 , + .tad_prf_offset =TAD_PRF_OFFSET , + .tad_pfc_offset =TAD_PFC_OFFSET , };#endif @@ -451,6 +570,9 @@ static int tad_pmu_offline_cpu(unsigned int cpu,struct
hlist_node*node)Quoted 16 lines
drivers/perf/marvell_cn10k_tad_pmu.c +4
-1struct tad_pmu *pmu = hlist_entry_safe(node, struct tad_pmu, node);unsigned int target; +if (!READ_ONCE (pmu->perf_ready)) +return 0 ; +if (cpu != pmu->cpu)return 0 ;@@ -491,6 +613,6 @@ static void __exit tad_pmu_exit(void)module_init (tad_pmu_init);module_exit (tad_pmu_exit); -MODULE_DESCRIPTION ("Marvell CN10K LLC-TAD Perf driver" ); +MODULE_DESCRIPTION ("Marvell CN10K LLC-TAD perf driver" );MODULE_AUTHOR ("Bhaskara Budiredla <[email protected]>" );MODULE_LICENSE ("GPL v2" );
Re: [EXTERNAL] Re: [PATCH v4 1/3] perf: marvell: Add MPAM partid filtering to CN10K TAD PMU
Hi Geetha,
Quoted 75 lines · Geethasowjanya Akula
Quoted 63 lines
-----Original Message-----
From: Ben Horgan <[email protected]>
Sent: Thursday, June 25, 2026 7:23 PM
To: Geethasowjanya Akula <[email protected]>; linux-perf- [email protected]; [email protected]; linux-arm- [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXTERNAL] Re: [PATCH v4 1/3] perf: marvell: Add MPAM partid filtering to CN10K TAD PMU
Hi Geetha,+CC James
Quoted 8 lines · Geetha sowjanya
From: Tanmay Jagdale <[email protected]>
The TAD PMU exposes counters that can be filtered by MPAM partition id for a subset of allocation and hit events.
Add a 9-bit partid format attribute (config1) and route counter programming through variant-specific ops so CN10K keeps MPAM-capable programming while Odyssey keeps the reduced event set without advertising
partid in sysfs.
Quoted 8 lines
Probe no longer mutates the
platform_deviceMMIO resource (walk a localmap_start), rejects tad-cnt / page sizes of zero, validates the memory window against tad-cnt, and registers the perf PMU before hotplug with correct unwind.Example:
perf stat -e tad/tad_alloc_any,partid=0x12,partid_en=1/ -- <program>Where is the user expected to get the PARTID from? The MPAM driver considers the PARTID as an internal only value.
resctrl does support a 'debug' mount option which will show the CLOSID associated with a control group. Whilst the CLOSID is often the PARTID, it is really a set of PARTIDs. When the cdp mount option is used, CLOSID maps to 2 PARTIDs and if we use PARTID narrowing to give us more monitors, as in proposed in [1], then the set of PARTIDs may be bigger. Furthermore, if the PARTID narrowing scheme is made dynamic the size of the PARTID set may change when control or monitoring groups are created or deleted.
It seems that a way to map from a resctrl control group to the set of PARTIDs is required and a mechanism to tie this to lifetime of the resctrl mount.
Perhaps some helpers along the lines of:
int
resctrl_mount_generation(void)
intmpam_rdtgrp_to_partid_is_static(int mount_gen)intresctrl_rdtgrp_generation(char *name)intmpam_rdtgrp_to_partid_count(char *name, int rdt_gen)intmpam_rdtgrp_to_partid_array(char *name, int rdt_gen, int* partids)The rdtgrp generation is to an attempt to avoid having to use a debug interface in anger and cope with renaming of control groups in resctrl.
This does seem a bit unwieldly so hopefully there is better way to do this.Sorry to throw a spanner in the works.
Quoted 6 lines · On …, … wrote:
Where is the user expected to get the PARTID from? The MPAM driver considers the PARTID as an internal only value.
…
Perhaps some helpers along the lines of:
intresctrl_mount_generation(void)
…Hi Ben,
Thank you for the detailed feedback — the concern you raise is valid, particularly when viewed from the perspective of resctrl-managed deployments.
Quoted 7 lines
However, to clarify the intent of this patch: the exposure of partid in the TAD PMU is deliberately a low-level, hardware-facing interface, and is not intended to integrate with or mirror the abstractions provided by resctrl. It is mainly meant for platform bring-up and low-level performance/debug users, who already have explicit knowledge of the MPAM configuration, typically provisioned by firmware or other privileged software layers (e.g. EL3/EL2). In such environments, PARTIDs are known out-of-band, so the expectation is that the user supplying partid is already aware of the MPAM IDs programmed on the system.
When this was proposed before, [1], there was feedback asking to document how to get the PARTID.
Thanks,
Ben
[1]
https://lore.kernel.org/linux-arm-kernel/[email protected]/>
Quoted 501 lines
A proper “profile this resctrl group” path would require MPAM–resctrl support (e.g. something along the lines of the helpers you suggest) to resolve a group to its PARTID set. This is indeed important, but it constitutes a separate design discussion that is outside the scope of this driver patch.
We will clarify this in the commit message and avoid implying that users normally obtain PARTIDs from resctrl today.
Thanks,
GeethaQuoted 492 lines
Thanks,
Ben
Quoted 8 lines
Signed-off-by Tanmay Jagdale <[email protected]>Signed-off-by Geetha sowjanya <[email protected]>---
Changelog (since v3)
--------------------
- Restorecpuhp_state_add_instance_nocallsbeforeperf_pmu_registerinprobe
Quoted 3 lines
so users cannot attach events before the hotplug instance exists; unwind removes the hotplug instance if perf registration fails.
- Addperf_ready:tad_pmu_offline_cpuskipsperf_pmu_migrate_contextuntil after
Quoted 1 line
successful
perf_pmu_register, so a CPU offline between hotplug add andperf
Quoted 108 lines
register does not touch perf core state for an unregistered PMU.
Changelog (since v2)
--------------------
- Validate the eventId using an appropriate mask to ensure it is restricted to 8 bits.Changelog (since v1)
--------------------
- Fix config1 filter enable to use bit 9 consistently with the PMU format string (partid_en) and reject reserved bits withGENMASK(9, 0).
- Registerperf_pmu_registerbeforecpuhp_state_add_instance_nocallsand unregister on hotplug failure.drivers/perf/marvell_cn10k_tad_pmu.c | 220 +++++++++++++++++++++------ 1 file changed, 171 insertions(+), 49 deletions(-)drivers/perf/marvell_cn10k_tad_pmu.c +41
-10@@ -7,6 +7,8 @@#define pr_fmt (fmt) "tad_pmu: " fmt#include <linux/io.h> +#include <linux/bits.h> +#include <linux/compiler.h> #include <linux/module.h> #include <linux/of.h> #include <linux/cpuhotplug.h> @@ -14,12 +16,20 @@#include <linux/platform_device.h> #include <linux/acpi.h> -#define TAD_PFC_OFFSET 0x800 -#define TAD_PFC (counter) (TAD_PFC_OFFSET | (counter << 3))#define TAD_PRF_OFFSET 0x900 -#define TAD_PRF (counter) (TAD_PRF_OFFSET | (counter << 3)) +#define TAD_PFC_OFFSET 0x800 +#define TAD_PFC (base, counter) ((base) | ((u64)(counter) << 3)) +#define TAD_PRF (base, counter) ((base) | ((u64)(counter) << 3))#define TAD_PRF_CNTSEL_MASK 0xFF +#define TAD_PRF_MATCH_PARTID BIT(8) +#define TAD_PRF_PARTID_NS BIT(10) +/* +* config1: bits 0..8 MPAM partition id (including 0); bit 9 requests +* filtering for MPAM-capable events. All-zero config1 means no filter. +*/ +#define TAD_PARTID_FILTER_EN BIT(9)#define TAD_MAX_COUNTERS 8 +#define TAD_EVENT_SEL_MASK GENMASK(7, 0)#define to_tad_pmu (p) (container_of(p, struct tad_pmu, pmu))@@ -27,30 +37,94 @@ struct tad_region {void __iomem *base; }; +enum mrvl_tad_pmu_version { +TAD_PMU_V1 =1 , +TAD_PMU_V2 , +}; + +struct tad_pmu_data { +int id; +u64 tad_prf_offset; +u64 tad_pfc_offset; +}; +struct tad_pmu {struct pmu pmu;struct tad_region *regions;u32 region_cnt;unsigned int cpu; +/* Set after successful perf_pmu_register(); gates offline migration. */ +bool perf_ready; +const struct tad_pmu_ops *ops; +const struct tad_pmu_data *pdata;struct hlist_node node;struct perf_event *events[TAD_MAX_COUNTERS ]; DECLARE_BITMAP(counters_map, TAD_MAX_COUNTERS); }; -enum mrvl_tad_pmu_version { -TAD_PMU_V1 =1 , -TAD_PMU_V2 , -}; - -struct tad_pmu_data { -int id; +struct tad_pmu_ops { +void (*start_counter)(struct tad_pmu *pmu,struct perf_event +*event); };static int tad_pmu_cpuhp_state; +static void tad_pmu_start_counter (struct tad_pmu *pmu, +struct perf_event *event) +{ +const struct tad_pmu_data *pdata = pmu->pdata; +struct hw_perf_event *hwc = &event->hw; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u32 counter_idx = hwc->idx; +u64 partid_filter =0 ; +u64 reg_val; +u64 cfg1 = event->attr.config1;drivers/perf/marvell_cn10k_tad_pmu.c struct tad_region { · line 90
Quoted 10 lines
drivers/perf/marvell_cn10k_tad_pmu.c +10
-0+bool use_mpam = cfg1 &TAD_PARTID_FILTER_EN ; +u32 partid = (u32)(cfg1 &GENMASK (8 ,0 )); +int i; + +for (i =0 ; i < pmu->region_cnt; i++) +writeq_relaxed (0 , pmu->regions[i].base + +TAD_PFC (pdata->tad_pfc_offset, counter_idx)); + +if (use_mpam && event_idx >0x19 && event_idx <0x21 ) { + partid_filter = TAD_PRF_MATCH_PARTID |
TAD_PRF_PARTID_NS|drivers/perf/marvell_cn10k_tad_pmu.c static void tad_pmu_event_counter_read(struct
Quoted 40 lines
drivers/perf/marvell_cn10k_tad_pmu.c +34
-0+ ((u64 )partid <<11 ); + } + + +for (i =0 ; i < pmu->region_cnt; i++) { + reg_val = event_idx &0xFF ; + reg_val |= partid_filter; +writeq_relaxed (reg_val, pmu->regions[i].base + +TAD_PRF (pdata->tad_prf_offset, counter_idx)); + } +} + +static void tad_pmu_v2_start_counter (struct tad_pmu *pmu, +struct perf_event *event) +{ +const struct tad_pmu_data *pdata = pmu->pdata; +struct hw_perf_event *hwc = &event->hw; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u32 counter_idx = hwc->idx; +u64 reg_val; +int i; + +for (i =0 ; i < pmu->region_cnt; i++) +writeq_relaxed (0 , pmu->regions[i].base + +TAD_PFC (pdata->tad_pfc_offset, counter_idx)); + +for (i =0 ; i < pmu->region_cnt; i++) { + reg_val = event_idx &0xFF ; +writeq_relaxed (reg_val, pmu->regions[i].base + +TAD_PRF (pdata->tad_prf_offset, counter_idx)); + } +} +static void tad_pmu_event_counter_read (struct perf_event *event) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata;struct hw_perf_event *hwc = &event->hw;u32 counter_idx = hwc->idx;u64 prev, new;@@ -60,7 +134,7 @@ static void tad_pmu_event_counter_read(struct
perf_event*event)drivers/perf/marvell_cn10k_tad_pmu.c static void tad_pmu_event_counter_read(struct perf_event *event)
Quoted 5 lines
drivers/perf/marvell_cn10k_tad_pmu.c +1
-1prev =local64_read (&hwc->prev_count);for (i =0 , new =0 ; i < tad_pmu->region_cnt; i++) new +=readq (tad_pmu->regions[i].base + -TAD_PFC (counter_idx)); + TAD_PFC(pdata->tad_pfc_offset,
counter_idx));drivers/perf/marvell_cn10k_tad_pmu.c static void tad_pmu_event_counter_read(struct perf_event *event)
Quoted 3 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-0}while (local64_cmpxchg (&hwc->prev_count, prev, new) != prev); local64_add(new - prev, &event->count); @@ -69,16 +143,14 @@static
Quoted 46 lines
void
tad_pmu_event_counter_read(struct perf_event *event)static voidtad_pmu_event_counter_stop(struct perf_event *event, int flags){drivers/perf/marvell_cn10k_tad_pmu.c +3
-21struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata;struct hw_perf_event *hwc = &event->hw;u32 counter_idx = hwc->idx;int i; -/* TAD()_PFC() stop counting on the write -* which sets TAD()_PRF()[CNTSEL] == 0 -*/ for (i =0 ; i < tad_pmu->region_cnt; i++) {writeq_relaxed (0 , tad_pmu->regions[i].base + -TAD_PRF (counter_idx)); +TAD_PRF (pdata->tad_prf_offset, counter_idx)); }tad_pmu_event_counter_read (event);@@ -89,26 +161,10 @@ static void tad_pmu_event_counter_start(struct perf_event *event, int flags) {struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu);struct hw_perf_event *hwc = &event->hw; -u32 event_idx = event->attr.config; -u32 counter_idx = hwc->idx; -u64 reg_val; -int i; hwc->state =0 ; -/* Typically TAD_PFC() are zeroed to start counting */ -for (i =0 ; i < tad_pmu->region_cnt; i++) -writeq_relaxed (0 , tad_pmu->regions[i].base + -TAD_PFC (counter_idx)); - -/* TAD()_PFC() start counting on the write -* which sets TAD()_PRF()[CNTSEL] != 0 -*/ -for (i =0 ; i < tad_pmu->region_cnt; i++) { - reg_val = event_idx &0xFF ; -writeq_relaxed (reg_val, tad_pmu->regions[i].base + -TAD_PRF (counter_idx)); - } + tad_pmu->ops->start_counter (tad_pmu, event); } static void tad_pmu_event_counter_del(struct perf_event *event, intQuoted 1 line
flags) @@ -128,7 +184,6 @@ static int tad_pmu_event_counter_add(struct
perf_event*event, int flags)drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_event_counter_add(struct perf_event *event, int flags)
Quoted 5 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-1struct hw_perf_event *hwc = &event->hw;int idx; -/* Get a free counter for this event */ idx = find_first_zero_bit(tad_pmu->counters_map,
TAD_MAX_COUNTERS);drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_event_init(struct perf_event
Quoted 13 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-0if (idx ==TAD_MAX_COUNTERS )return -EAGAIN ;@@ -148,6 +203,9 @@ static int tad_pmu_event_counter_add(struct
perf_event*event, int flags) static inttad_pmu_event_init(struct perf_event *event){drivers/perf/marvell_cn10k_tad_pmu.c +3
-0struct tad_pmu *tad_pmu =to_tad_pmu (event->pmu); +const struct tad_pmu_data *pdata = tad_pmu->pdata; +u32 event_idx = (u32)(event->attr.config &TAD_EVENT_SEL_MASK ); +u64 cfg1 = event->attr.config1;if (event->attr.type != event->pmu->type)return -ENOENT ;@@ -158,6 +216,23 @@ static int tad_pmu_event_init(struct perf_event*event)
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_event_init(struct perf_event *event)
Quoted 11 lines
drivers/perf/marvell_cn10k_tad_pmu.c +8
-0if (event->state !=PERF_EVENT_STATE_OFF )return -EINVAL ; +if (event->attr.config & ~TAD_EVENT_SEL_MASK ) +return -EINVAL ; + +if (pdata->id ==TAD_PMU_V2 ) { +if (cfg1) +return -EINVAL ; + }else { + if ((cfg1 & GENMASK(8, 0)) && !(cfg1 &
TAD_PARTID_FILTER_EN))drivers/perf/marvell_cn10k_tad_pmu.c static struct attribute_group
Quoted 36 lines
drivers/perf/marvell_cn10k_tad_pmu.c +9
-0+return -EINVAL ; +if (cfg1 &TAD_PARTID_FILTER_EN ) { +if (event_idx <=0x19 || event_idx >=0x21 ) +return -EINVAL ; + } +if (cfg1 & ~GENMASK (9 ,0 )) +return -EINVAL ; + } + event->cpu = tad_pmu->cpu; event->hw.idx =-1 ; event->hw.config_base = event->attr.config; @@ -232,7 +307,7 @@static struct attribute *ody_tad_pmu_event_attrs[] = {
drivers/perf/marvell_cn10k_tad_pmu.c +5
-1TAD_PMU_EVENT_ATTR (tad_hit_ltg,0x1e ),TAD_PMU_EVENT_ATTR (tad_hit_any,0x1f ),TAD_PMU_EVENT_ATTR (tad_tag_rd,0x20 ), -TAD_PMU_EVENT_ATTR (tad_tot_cycle,0xFF ), +TAD_PMU_EVENT_ATTR (tad_tot_cycle,0xff ), NULL };@@ -242,9 +317,13 @@ static const struct attribute_group ody_tad_pmu_events_attr_group = { };PMU_FORMAT_ATTR (event,"config:0-7" ); +PMU_FORMAT_ATTR (partid,"config1:0-8" );PMU_FORMAT_ATTR (partid_en, +"config1:9-9" );static struct attribute *tad_pmu_format_attrs[] = { &format_attr_event.attr, + &format_attr_partid.attr, + &format_attr_partid_en.attr,NULL };@@ -253,6 +332,16 @@ static struct attribute_group
tad_pmu_format_attr_group= {Quoted 5 lines
drivers/perf/marvell_cn10k_tad_pmu.c +2
-0.attrs = tad_pmu_format_attrs, }; +static struct attribute *ody_tad_pmu_format_attrs[] = { + &format_attr_event.attr,drivers/perf/marvell_cn10k_tad_pmu.c static struct attribute_group tad_pmu_format_attr_group = {
Quoted 10 lines
drivers/perf/marvell_cn10k_tad_pmu.c +8
-0+NULL +}; + +static struct attribute_group ody_tad_pmu_format_attr_group = { + .name ="format" , + .attrs = ody_tad_pmu_format_attrs, +}; +static ssize_t tad_pmu_cpumask_show (struct device *dev, struct device_attribute *attr, char *buf) { @@-281,16 +370,25
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device
Quoted 25 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-0@@ static const struct attribute_group *tad_pmu_attr_groups[] = {static const struct
attribute_group*ody_tad_pmu_attr_groups[] = {drivers/perf/marvell_cn10k_tad_pmu.c +8
-1&ody_tad_pmu_events_attr_group, - &tad_pmu_format_attr_group, + &ody_tad_pmu_format_attr_group, &tad_pmu_cpumask_attr_group, NULL }; +static const struct tad_pmu_ops tad_pmu_ops = { + .start_counter = tad_pmu_start_counter, }; + +static const struct tad_pmu_ops tad_pmu_v2_ops = { + .start_counter = tad_pmu_v2_start_counter, }; +static int tad_pmu_probe (struct platform_device *pdev) {const struct tad_pmu_data *dev_data;struct device *dev = &pdev->dev;struct tad_region *regions; +resource_size_t map_start;struct tad_pmu *tad_pmu;struct resource *res;u32 tad_pmu_page_size;@@ -298,7 +396,6 @@ static int tad_pmu_probe(struct platform_device*pdev)
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device *pdev)
Quoted 6 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-1u32 tad_cnt;int version;int i, ret; -char *name; tad_pmu = devm_kzalloc(&pdev->dev, sizeof(*tad_pmu),
GFP_KERNEL);drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device
Quoted 2 lines
drivers/perf/marvell_cn10k_tad_pmu.c +0
-0if (!tad_pmu)@@ -312,6 +409,7 @@ static int tad_pmu_probe(struct platform_device*pdev)
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device
Quoted 8 lines
drivers/perf/marvell_cn10k_tad_pmu.c +1
-0return -ENODEV ; } version = dev_data->id; + tad_pmu->pdata = dev_data; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res) {@@ -338,22 +436,31 @@ static int tad_pmu_probe(struct platform_device*pdev)
Quoted 11 lines
drivers/perf/marvell_cn10k_tad_pmu.c +4
-0dev_err (&pdev->dev,"Can't find tad-cnt property\n" );return ret; } +if (!tad_cnt || !tad_page_size || !tad_pmu_page_size) { +dev_err (&pdev->dev,"Invalid tad-cnt or page size\n" ); +return -EINVAL ; + } regions =devm_kcalloc (&pdev->dev, tad_cnt,sizeof (*regions),GFP_KERNEL );if (!regions)drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device *pdev)
Quoted 10 lines
drivers/perf/marvell_cn10k_tad_pmu.c +4
-4return -ENOMEM ; -/* ioremap the distributed TAD pmu regions */ -for (i =0 ; i < tad_cnt && res->start < res->end; i++) { - regions[i].base = devm_ioremap(&pdev->dev, - res->start, + map_start = res->start; + for (i = 0; i < tad_cnt; i++) { + if (map_start > res->end || + tad_pmu_page_size > (resource_size_t)(res->end -
map_start+ 1)) {drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device · line 453
Quoted 1 line
drivers/perf/marvell_cn10k_tad_pmu.c +1
-0+ dev_err(&pdev->dev, "TAD PMU mem window toosmall for tad-cnt=%u\n",
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device
Quoted 15 lines
drivers/perf/marvell_cn10k_tad_pmu.c +5
-1+ tad_cnt); +return -EINVAL ; + } + regions[i].base =devm_ioremap (&pdev->dev, map_start, tad_pmu_page_size);if (!regions[i].base) {dev_err (&pdev->dev,"TAD%d ioremap fail\n" , i);return -ENOMEM ; } - res->start += tad_page_size; + map_start += tad_page_size; } tad_pmu->regions = regions;@@ -374,14 +481,16 @@ static int tad_pmu_probe(struct platform_device*pdev)
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_probe(struct platform_device
Quoted 20 lines
drivers/perf/marvell_cn10k_tad_pmu.c +5
-3.read = tad_pmu_event_counter_read, }; -if (version ==TAD_PMU_V1 ) +if (version ==TAD_PMU_V1 ) { tad_pmu->pmu.attr_groups = tad_pmu_attr_groups; -else + tad_pmu->ops = &tad_pmu_ops; + }else { tad_pmu->pmu.attr_groups = ody_tad_pmu_attr_groups; + tad_pmu->ops = &tad_pmu_v2_ops; + } tad_pmu->cpu =raw_smp_processor_id (); -/* Register pmu instance for cpu hotplug */ ret =cpuhp_state_add_instance_nocalls (tad_pmu_cpuhp_state, &tad_pmu->node);if (ret) {@@ -389,19 +498,24 @@ static int tad_pmu_probe(struct platform_device*pdev)
drivers/perf/marvell_cn10k_tad_pmu.c static int tad_pmu_offline_cpu(unsigned int cpu,
Quoted 46 lines
drivers/perf/marvell_cn10k_tad_pmu.c +14
-4return ret; } - name ="tad" ; - ret =perf_pmu_register (&tad_pmu->pmu, name,-1 ); -if (ret) + ret =perf_pmu_register (&tad_pmu->pmu,"tad" ,-1 ); +if (ret) { +dev_err (&pdev->dev,"Error %d registering perf PMU\n" , ret);cpuhp_state_remove_instance_nocalls (tad_pmu_cpuhp_state, &tad_pmu->node); +return ret; + } -return ret; +WRITE_ONCE (tad_pmu->perf_ready, true); + +return 0 ; }static void tad_pmu_remove (struct platform_device *pdev) {struct tad_pmu *pmu =platform_get_drvdata (pdev); +WRITE_ONCE (pmu->perf_ready, false);cpuhp_state_remove_instance_nocalls (tad_pmu_cpuhp_state, &pmu->node);perf_pmu_unregister (&pmu->pmu);@@ -410,12 +524,17 @@ static void tad_pmu_remove(struct platform_device *pdev) #if defined(CONFIG_OF) || defined(CONFIG_ACPI)static const struct tad_pmu_data tad_pmu_data = { .id =TAD_PMU_V1 , + .tad_prf_offset =TAD_PRF_OFFSET , + .tad_pfc_offset =TAD_PFC_OFFSET , }; +#endif #ifdef CONFIG_ACPI static const struct tad_pmu_data tad_pmu_v2_data = { .id =TAD_PMU_V2 , + .tad_prf_offset =TAD_PRF_OFFSET , + .tad_pfc_offset =TAD_PFC_OFFSET , };#endif @@ -451,6 +570,9 @@ static int tad_pmu_offline_cpu(unsigned int cpu,struct
hlist_node*node)Quoted 16 lines
drivers/perf/marvell_cn10k_tad_pmu.c +4
-1struct tad_pmu *pmu = hlist_entry_safe(node, struct tad_pmu, node);unsigned int target; +if (!READ_ONCE (pmu->perf_ready)) +return 0 ; +if (cpu != pmu->cpu)return 0 ;@@ -491,6 +613,6 @@ static void __exit tad_pmu_exit(void)module_init (tad_pmu_init);module_exit (tad_pmu_exit); -MODULE_DESCRIPTION ("Marvell CN10K LLC-TAD Perf driver" ); +MODULE_DESCRIPTION ("Marvell CN10K LLC-TAD perf driver" );MODULE_AUTHOR ("Bhaskara Budiredla <[email protected]>" );MODULE_LICENSE ("GPL v2" );
Will Deacon
maintainerRe: [EXTERNAL] Re: [PATCH v4 1/3] perf: marvell: Add MPAM partid filtering to CN10K TAD PMU
Quoted 17 lines · Ben Horgan
Quoted 9 lines
Quoted 6 lines
Where is the user expected to get the PARTID from? The MPAM driver considers the PARTID as an internal only value.
…
Perhaps some helpers along the lines of:
intresctrl_mount_generation(void)
…Thank you for the detailed feedback — the concern you raise is valid, particularly when viewed from the perspective of resctrl-managed deployments.
Quoted 7 lines
However, to clarify the intent of this patch: the exposure of partid in the TAD PMU is deliberately a low-level, hardware-facing interface, and is not intended to integrate with or mirror the abstractions provided by resctrl. It is mainly meant for platform bring-up and low-level performance/debug users, who already have explicit knowledge of the MPAM configuration, typically provisioned by firmware or other privileged software layers (e.g. EL3/EL2). In such environments, PARTIDs are known out-of-band, so the expectation is that the user supplying partid is already aware of the MPAM IDs programmed on the system.
Quoted 2 lines
When this was proposed before, [1], there was feedback asking to document how to get the PARTID.
Yes, please can you update the documentation to cover this? I'm not necessarily asking for a programmatic way to do it, but even something like a reference to a document or a firmware table would be useful for people trying to use the driver to profile their workload. Otherwise, it's just an opaque id :/
There are also some comments from Sashiko to consider:
https://sashiko.dev/#/patchset/[email protected]?part=1
Thanks,
Will
PATCH v4 2/3 perf: marvell: Add CN20K LLC-TAD PMU support
In reply to Geetha sowjanyaAdd support for the LLC Tag-and-Data (TAD) PMU present in Marvell CN20K SoCs.
The CN20K TAD PMU is based on the CN10K design but differs in the layout of PFC/PRF register offsets relative to each TAD base, and introduces additional events. These offsets are selected by the driver based on the compatible string and are not described via DT properties.
Because of this, "marvell,cn10k-tad-pmu" cannot be used as a fallback for CN20K, as it would result in incorrect register programming.
Add support for "marvell,cn20k-tad-pmu" by:
- Introducing a TAD_PMU_V3 profile with CN20K-specific register bases
- Extending the event map for new CN20K events
- Matching the PMU via OF and ACPI (MRVL000F)
---
Changelog (since v2)
--------------------
- Validate the eventId using an appropriate mask to ensure it is restricted to 8 bits.
Changelog (since v1)
--------------------
- Hide V3-only events on CN10K via sysfs is_visible and reject them in event_init.
- Use CN20K-specific MPAM PRF bits (MATCH_MPAMNS, partid << 10) for V3; software partid is limited to nine bits so this does not collide with the fixed bit at 25.
- Reset hwc->prev_count when starting counters so reads match cleared HW.
drivers/perf/marvell_cn10k_tad_pmu.c | 54 ++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-)
drivers/perf/marvell_cn10k_tad_pmu.c +52 -2
@@ -18,11 +18,14 @@#define TAD_PRF_OFFSET 0x900#define TAD_PFC_OFFSET 0x800 +#define TAD_PRF_NS_OFFSET 0x30900 +#define TAD_PFC_NS_OFFSET 0x30800#define TAD_PFC (base, counter) ((base) | ((u64)(counter) << 3))#define TAD_PRF (base, counter) ((base) | ((u64)(counter) << 3))#define TAD_PRF_CNTSEL_MASK 0xFF#define TAD_PRF_MATCH_PARTID BIT(8)#define TAD_PRF_PARTID_NS BIT(10) +#define TAD_PRF_MATCH_MPAMNS BIT(25)/* * config1: bits 0..8 MPAM partition id (including 0); bit 9 requests * filtering for MPAM-capable events. All-zero config1 means no filter.
@@ -40,6 +43,7 @@ struct tad_region {enum mrvl_tad_pmu_version {TAD_PMU_V1 =1 ,TAD_PMU_V2 , +TAD_PMU_V3 , };struct tad_pmu_data {
@@ -89,8 +93,15 @@ static void tad_pmu_start_counter(struct tad_pmu *pmu,if (use_mpam && event_idx >0x19 && event_idx <0x21 ) { partid_filter =TAD_PRF_MATCH_PARTID |TAD_PRF_PARTID_NS | ((u64 )partid <<11 ); + +if (pdata->id ==TAD_PMU_V3 ) + partid_filter =TAD_PRF_MATCH_PARTID |TAD_PRF_MATCH_MPAMNS | + ((u64 )partid <<10 ); } +/* CN10K support events 0:24*/ +if (pdata->id ==TAD_PMU_V1 && event_idx >=0x25 ) +return ;for (i =0 ; i < pmu->region_cnt; i++) { reg_val = event_idx &0xFF ;
@@ -163,6 +174,7 @@ static void tad_pmu_event_counter_start(struct perf_event *event, int flags)struct hw_perf_event *hwc = &event->hw; hwc->state =0 ; +local64_set (&hwc->prev_count,0 ); tad_pmu->ops->start_counter (tad_pmu, event); }
@@ -223,6 +235,8 @@ static int tad_pmu_event_init(struct perf_event *event)if (cfg1)return -EINVAL ; }else { +if (pdata->id ==TAD_PMU_V1 && event_idx >=0x25 ) +return -EINVAL ;if ((cfg1 &GENMASK (8 ,0 )) && !(cfg1 &TAD_PARTID_FILTER_EN ))return -EINVAL ;if (cfg1 &TAD_PARTID_FILTER_EN ) {
@@ -249,6 +263,22 @@ static ssize_t tad_pmu_event_show(struct device *dev,return sysfs_emit (page,"event=0x%02llx\n" , pmu_attr->id); } +static umode_t tad_pmu_event_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int unused) +{ +struct pmu *pmu =dev_get_drvdata (kobj_to_dev (kobj)); +struct tad_pmu *t =to_tad_pmu (pmu); + struct device_attribute *da = container_of(attr, struct device_attribute, + attr); + struct perf_pmu_events_attr *e = container_of(da, struct perf_pmu_events_attr, + attr); +u64 id = e->id; + +if (t->pdata->id !=TAD_PMU_V3 && id >=0x25 ) +return 0 ; +return attr->mode; +} +#define TAD_PMU_EVENT_ATTR (name, config) \ PMU_EVENT_ATTR_ID(name, tad_pmu_event_show, config)
@@ -290,12 +320,25 @@ static struct attribute *tad_pmu_event_attrs[] = {TAD_PMU_EVENT_ATTR (tad_dat_rd_byp,0x22 ),TAD_PMU_EVENT_ATTR (tad_ifb_occ,0x23 ),TAD_PMU_EVENT_ATTR (tad_req_occ,0x24 ), +TAD_PMU_EVENT_ATTR (tad_req_msh_out_dtg_evict,0x25 ), +TAD_PMU_EVENT_ATTR (tad_req_msh_out_ltg_evict,0x26 ), +TAD_PMU_EVENT_ATTR (tad_rsp_msh_out_mpam,0x28 ), +TAD_PMU_EVENT_ATTR (tad_replays,0x29 ), +TAD_PMU_EVENT_ATTR (tad_req_byp0,0x2a ), +TAD_PMU_EVENT_ATTR (tad_req_byp1,0x2b ), +TAD_PMU_EVENT_ATTR (tad_txreq_byp,0x2c ), +TAD_PMU_EVENT_ATTR (tad_time_in_dslp,0x2d ), +TAD_PMU_EVENT_ATTR (tad_time_elapsed,0x2e ), +TAD_PMU_EVENT_ATTR (tad_req_msh_out_dss_rd_128mrg,0x2f ), +TAD_PMU_EVENT_ATTR (tad_req_msh_out_dss_wr_128mrg,0x30 ), +TAD_PMU_EVENT_ATTR (tad_tot_cycle,0xff ),NULL };static const struct attribute_group tad_pmu_events_attr_group = { .name ="events" , .attrs = tad_pmu_event_attrs, + .is_visible = tad_pmu_event_attr_is_visible, }; static struct attribute *ody_tad_pmu_event_attrs[] = {
@@ -481,7 +524,7 @@ static int tad_pmu_probe(struct platform_device *pdev) .read = tad_pmu_event_counter_read, }; -if (version ==TAD_PMU_V1 ) { +if (version ==TAD_PMU_V1 || version ==TAD_PMU_V3 ) { tad_pmu->pmu.attr_groups = tad_pmu_attr_groups; tad_pmu->ops = &tad_pmu_ops; }else {
@@ -528,6 +571,11 @@ static const struct tad_pmu_data tad_pmu_data = { .tad_pfc_offset = TAD_PFC_OFFSET, }; +static const struct tad_pmu_data tad_pmu_cn20k_data = { + .id =TAD_PMU_V3 , + .tad_prf_offset =TAD_PRF_NS_OFFSET , + .tad_pfc_offset =TAD_PFC_NS_OFFSET , +};#endif #ifdef CONFIG_ACPI
@@ -541,6 +589,7 @@ static const struct tad_pmu_data tad_pmu_v2_data = {#ifdef CONFIG_OF static const struct of_device_id tad_pmu_of_match[] = { { .compatible ="marvell,cn10k-tad-pmu" , .data = &tad_pmu_data }, + { .compatible ="marvell,cn20k-tad-pmu" , .data = &tad_pmu_cn20k_data }, {}, };#endif
@@ -549,6 +598,7 @@ static const struct of_device_id tad_pmu_of_match[] = {static const struct acpi_device_id tad_pmu_acpi_match[] = { {"MRVL000B" , (kernel_ulong_t)&tad_pmu_data}, {"MRVL000D" , (kernel_ulong_t)&tad_pmu_v2_data}, + {"MRVL000F" , (kernel_ulong_t)&tad_pmu_cn20k_data}, {}, };MODULE_DEVICE_TABLE (acpi, tad_pmu_acpi_match);
@@ -613,6 +663,6 @@ static void __exit tad_pmu_exit(void)module_init (tad_pmu_init);module_exit (tad_pmu_exit); -MODULE_DESCRIPTION ("Marvell CN10K LLC-TAD perf driver" ); +MODULE_DESCRIPTION ("Marvell CN10K/CN20K LLC-TAD perf driver" );MODULE_AUTHOR ("Bhaskara Budiredla <[email protected]>" );MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.25.1
PATCH v4 3/3 dt-bindings: perf: marvell: add CN20K TAD PMU support
In reply to Geetha sowjanyaMarvell CN20K SoCs integrate a Performance Monitoring Unit (PMU) associated with the LLC Tag-and-Data (TAD) blocks. The PMU provides hardware counters to monitor cache traffic and performance events via a dedicated MMIO region.
The CN20K LLC-TAD PMU is largely similar to CN10K, but differs in the layout of PFC/PRF register offsets relative to each TAD base. These offsets are derived from the compatible string in the driver and are not described through Devicetree properties.
Because of this, using "marvell,cn10k-tad-pmu" as a fallback for CN20K would result in incorrect register programming. Therefore, add a separate compatible string:
"marvell,cn20k-tad-pmu"
Update the binding to document CN20K alongside CN10K.
--- .../bindings/perf/marvell-cn10k-tad.yaml | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-)
Documentation/devicetree/bindings/perf/marvell-cn10k-tad.yaml +17 -8
@@ -4,23 +4,32 @@ $id: http://devicetree.org/schemas/perf/marvell-cn10k-tad.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Marvell CN10K LLC-TAD performance monitor +title: Marvell CN10K / CN20K LLC-TAD performance monitor maintainers: - Bhaskara Budiredla <[email protected]> + - Geetha sowjanya <[email protected]> description: | - The Tag-and-Data units (TADs) maintain coherence and contain CN10K - shared on-chip last level cache (LLC). The tad pmu measures the - performance of last-level cache. Each tad pmu supports up to eight - counters. + The Tag-and-Data units (TADs) maintain coherence and contain the + shared on-chip last level cache (LLC) on Marvell CN10K and CN20K SoCs. + The TAD PMU measures last-level cache performance. Each TAD PMU + supports up to eight counters. - The DT setup comprises of number of tad blocks, the sizes of pmu - regions, tad blocks and overall base address of the HW. + The DT setup describes the number of TAD blocks, the sizes of PMU + regions and TAD pages, and the overall MMIO base of the hardware. + + marvell,cn20k-tad-pmu is not a compatible fallback for + marvell,cn10k-tad-pmu (and vice versa): the driver selects different + PFC/PRF MMIO offsets from the compatible string, and those offsets are + not described by separate DT properties today. properties: compatible: - const: marvell,cn10k-tad-pmu + items: + - enum: + - marvell,cn10k-tad-pmu + - marvell,cn20k-tad-pmu reg: maxItems: 1
Signature · 1 line
2.25.1