dt-bindings: perf: fsl-imx-ddr: Add i.MX95 compatible
Subsystems (6)
Xu Yang
maintainerPATCH v2 1/4 dt-bindings: perf: fsl-imx-ddr: Add i.MX95 compatible
i.MX95 has a DDR pmu. This will add a compatible for it.
---
Changes in v2:
- no changes
--- Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +1 -0
@@ -20,6 +20,7 @@ properties: - fsl,imx8mn-ddr-pmu - fsl,imx8mp-ddr-pmu - fsl,imx93-ddr-pmu + - fsl,imx95-ddr-pmu - items: - enum: - fsl,imx8mm-ddr-pmu
Signature · 1 line
2.34.1
Xu Yang
maintainerPATCH v2 2/4 perf: imx_perf: add support for i.MX95 platform
i.MX95 has a DDR PMU which is almostly same as i.MX93, it now supports read beat and write beat filter capabilities. This will add support for i.MX95 and enhance the driver to support specific filter handling for it.
Usage:
For read beat:
~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt2,counter=3,axi_mask=ID_MASK,axi_id=ID/ ~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt1,counter=4,axi_mask=ID_MASK,axi_id=ID/ ~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt0,counter=5,axi_mask=ID_MASK,axi_id=ID/
eg: For edma2: perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt0,counter=5,axi_mask=0x00f,axi_id=0x00c/
For write beat:
~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_wr_beat_filt,counter=2,axi_mask=ID_MASK,axi_id=ID/
eg: For edma2: perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_wr_beat_filt,counter=2,axi_mask=0x00f,axi_id=0x00c/
---
Changes in v2:
- put soc spefific axi filter events to drvdata according to franks suggestions.
- adjust pmcfg axi_id and axi_mask config
--- drivers/perf/fsl_imx9_ddr_perf.c | 203 +++++++++++++++++++++++++------ 1 file changed, 169 insertions(+), 34 deletions(-)
drivers/perf/fsl_imx9_ddr_perf.c +169 -34
@@ -11,14 +11,24 @@#include <linux/perf_event.h> /* Performance monitor configuration */ -#define PMCFG1 0x00 -#define PMCFG1_RD_TRANS_FILT_EN BIT(31) -#define PMCFG1_WR_TRANS_FILT_EN BIT(30) -#define PMCFG1_RD_BT_FILT_EN BIT(29) -#define PMCFG1_ID_MASK GENMASK(17, 0) +#define PMCFG1 0x00 +#define MX93_PMCFG1_RD_TRANS_FILT_EN BIT(31) +#define MX93_PMCFG1_WR_TRANS_FILT_EN BIT(30) +#define MX93_PMCFG1_RD_BT_FILT_EN BIT(29) +#define MX93_PMCFG1_ID_MASK GENMASK(17, 0) -#define PMCFG2 0x04 -#define PMCFG2_ID GENMASK(17, 0) +#define MX95_PMCFG1_WR_BEAT_FILT_EN BIT(31) +#define MX95_PMCFG1_RD_BEAT_FILT_EN BIT(30) + +#define PMCFG2 0x04 +#define MX93_PMCFG2_ID GENMASK(17, 0) + +#define PMCFG3 0x08 +#define PMCFG4 0x0C +#define PMCFG5 0x10 +#define PMCFG6 0x14 +#define MX95_PMCFG_ID_MASK GENMASK(9, 0) +#define MX95_PMCFG_ID GENMASK(25, 16)/* Global control register affects all counters and takes priority over local control registers */ #define PMGC0 0x40
@@ -51,6 +61,7 @@ static DEFINE_IDA(ddr_ida);struct imx_ddr_devtype_data {const char *identifier;/* system PMU identifier for userspace */ +struct attribute **attrs;/* AXI filter attributes */ };struct ddr_pmu {
@@ -67,16 +78,6 @@ struct ddr_pmu {int id; }; -static const struct imx_ddr_devtype_data imx93_devtype_data = { - .identifier ="imx93" , -}; - -static const struct of_device_id imx_ddr_pmu_dt_ids[] = { - {.compatible ="fsl,imx93-ddr-pmu" , .data = &imx93_devtype_data}, - {/* sentinel */ } -}; -MODULE_DEVICE_TABLE (of, imx_ddr_pmu_dt_ids); -static ssize_t ddr_perf_identifier_show (struct device *dev,struct device_attribute *attr,char *page)
@@ -178,7 +179,6 @@ static struct attribute *ddr_perf_events_attrs[] = {IMX9_DDR_PMU_EVENT_ATTR (ddrc_ld_wiq_6,70 ),IMX9_DDR_PMU_EVENT_ATTR (ddrc_ld_wiq_7,71 ),IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pmon_empty,72 ), -IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_trans_filt,73 ),/* counter3 specific events */ IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_row_collision_0, 64),
@@ -190,7 +190,6 @@ static struct attribute *ddr_perf_events_attrs[] = {IMX9_DDR_PMU_EVENT_ATTR (ddrc_qx_row_collision_6,70 ),IMX9_DDR_PMU_EVENT_ATTR (ddrc_qx_row_collision_7,71 ),IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pmon_full,72 ), -IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_wr_trans_filt,73 ),/* counter4 specific events */ IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_row_open_0, 64),
@@ -202,7 +201,6 @@ static struct attribute *ddr_perf_events_attrs[] = {IMX9_DDR_PMU_EVENT_ATTR (ddrc_qx_row_open_6,70 ),IMX9_DDR_PMU_EVENT_ATTR (ddrc_qx_row_open_7,71 ),IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pmon_ld_rdq2_rmw,72 ), -IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_beat_filt,73 ),/* counter5 specific events */ IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_valid_start_0, 64),
@@ -242,6 +240,28 @@ static const struct attribute_group ddr_perf_events_attr_group = { .attrs = ddr_perf_events_attrs, }; +static struct attribute *imx93_ddr_perf_events_attrs[] = { +/* counter2 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_trans_filt,73 ), +/* counter3 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_wr_trans_filt,73 ), +/* counter4 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_beat_filt,73 ), +NULL , +}; + +static struct attribute *imx95_ddr_perf_events_attrs[] = { +/* counter2 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_wr_beat_filt,73 ), +/* counter3 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_beat_filt2,73 ), +/* counter4 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_beat_filt1,73 ), +/* counter5 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_beat_filt0,73 ), +NULL , +}; +PMU_FORMAT_ATTR (event,"config:0-7" );PMU_FORMAT_ATTR (counter,"config:8-15" );PMU_FORMAT_ATTR (axi_id,"config1:0-17" );
@@ -268,6 +288,28 @@ static const struct attribute_group *attr_groups[] = { NULL, }; +static const struct imx_ddr_devtype_data imx93_devtype_data = { + .identifier ="imx93" , + .attrs = imx93_ddr_perf_events_attrs, +}; + +static const struct imx_ddr_devtype_data imx95_devtype_data = { + .identifier ="imx95" , + .attrs = imx95_ddr_perf_events_attrs, +}; + +static const struct of_device_id imx_ddr_pmu_dt_ids[] = { + { .compatible ="fsl,imx93-ddr-pmu" , .data = &imx93_devtype_data }, + { .compatible ="fsl,imx95-ddr-pmu" , .data = &imx95_devtype_data }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, imx_ddr_pmu_dt_ids); + +static inline bool is_imx93 (struct ddr_pmu *pmu) +{ +return pmu->devtype_data == &imx93_devtype_data; +} +static void ddr_perf_clear_counter (struct ddr_pmu *pmu,int counter) {if (counter ==CYCLES_COUNTER ) {
@@ -361,7 +403,7 @@ static void ddr_perf_counter_local_config(struct ddr_pmu *pmu, int config, } } -static void ddr_perf_monitor_config (struct ddr_pmu *pmu,int cfg,int cfg1,int cfg2) +static void imx93_ddr_perf_monitor_config (struct ddr_pmu *pmu,int cfg,int cfg1,int cfg2) {u32 pmcfg1, pmcfg2;int event, counter;
@@ -372,30 +414,80 @@ static void ddr_perf_monitor_config(struct ddr_pmu *pmu, int cfg, int cfg1, int pmcfg1 =readl_relaxed (pmu->base +PMCFG1 );if (counter ==2 && event ==73 ) - pmcfg1 |=PMCFG1_RD_TRANS_FILT_EN ; + pmcfg1 |=MX93_PMCFG1_RD_TRANS_FILT_EN ;else if (counter ==2 && event !=73 ) - pmcfg1 &= ~PMCFG1_RD_TRANS_FILT_EN ; + pmcfg1 &= ~MX93_PMCFG1_RD_TRANS_FILT_EN ;if (counter ==3 && event ==73 ) - pmcfg1 |=PMCFG1_WR_TRANS_FILT_EN ; + pmcfg1 |=MX93_PMCFG1_WR_TRANS_FILT_EN ;else if (counter ==3 && event !=73 ) - pmcfg1 &= ~PMCFG1_WR_TRANS_FILT_EN ; + pmcfg1 &= ~MX93_PMCFG1_WR_TRANS_FILT_EN ;if (counter ==4 && event ==73 ) - pmcfg1 |=PMCFG1_RD_BT_FILT_EN ; + pmcfg1 |=MX93_PMCFG1_RD_BT_FILT_EN ;else if (counter ==4 && event !=73 ) - pmcfg1 &= ~PMCFG1_RD_BT_FILT_EN ; + pmcfg1 &= ~MX93_PMCFG1_RD_BT_FILT_EN ; - pmcfg1 &= ~FIELD_PREP (PMCFG1_ID_MASK ,0x3FFFF ); - pmcfg1 |=FIELD_PREP (PMCFG1_ID_MASK , cfg2); + pmcfg1 &= ~FIELD_PREP (MX93_PMCFG1_ID_MASK ,0x3FFFF ); + pmcfg1 |=FIELD_PREP (MX93_PMCFG1_ID_MASK , cfg2);writel (pmcfg1, pmu->base +PMCFG1 ); pmcfg2 =readl_relaxed (pmu->base +PMCFG2 ); - pmcfg2 &= ~FIELD_PREP (PMCFG2_ID ,0x3FFFF ); - pmcfg2 |=FIELD_PREP (PMCFG2_ID , cfg1); + pmcfg2 &= ~FIELD_PREP (MX93_PMCFG2_ID ,0x3FFFF ); + pmcfg2 |=FIELD_PREP (MX93_PMCFG2_ID , cfg1);writel (pmcfg2, pmu->base +PMCFG2 ); } +static void imx95_ddr_perf_monitor_config (struct ddr_pmu *pmu,int cfg,int cfg1,int cfg2) +{ +u32 pmcfg1, pmcfg, offset =0 ; +int event, counter; + + event = cfg &0x000000FF ; + counter = (cfg &0x0000FF00 ) >>8 ; + + pmcfg1 =readl_relaxed (pmu->base +PMCFG1 ); + +if (counter ==2 && event ==73 ) { + pmcfg1 |=MX95_PMCFG1_WR_BEAT_FILT_EN ; + offset =PMCFG3 ; + }else if (counter ==2 && event !=73 ) { + pmcfg1 &= ~MX95_PMCFG1_WR_BEAT_FILT_EN ; + } + +if (counter ==3 && event ==73 ) { + pmcfg1 |=MX95_PMCFG1_RD_BEAT_FILT_EN ; + offset =PMCFG4 ; + }else if (counter ==3 && event !=73 ) { + pmcfg1 &= ~MX95_PMCFG1_RD_BEAT_FILT_EN ; + } + +if (counter ==4 && event ==73 ) { + pmcfg1 |=MX95_PMCFG1_RD_BEAT_FILT_EN ; + offset =PMCFG5 ; + }else if (counter ==4 && event !=73 ) { + pmcfg1 &= ~MX95_PMCFG1_RD_BEAT_FILT_EN ; + } + +if (counter ==5 && event ==73 ) { + pmcfg1 |=MX95_PMCFG1_RD_BEAT_FILT_EN ; + offset =PMCFG6 ; + }else if (counter ==5 && event !=73 ) { + pmcfg1 &= ~MX95_PMCFG1_RD_BEAT_FILT_EN ; + } + +writel (pmcfg1, pmu->base +PMCFG1 ); + +if (offset) { + pmcfg =readl_relaxed (pmu->base + offset); + pmcfg &= ~(FIELD_PREP (MX95_PMCFG_ID_MASK ,0x3FF ) | +FIELD_PREP (MX95_PMCFG_ID ,0x3FF )); + pmcfg |= (FIELD_PREP (MX95_PMCFG_ID_MASK , cfg2) | +FIELD_PREP (MX95_PMCFG_ID , cfg1)); +writel (pmcfg, pmu->base + offset); + } +} +static void ddr_perf_event_update (struct perf_event *event) {struct ddr_pmu *pmu =to_ddr_pmu (event->pmu);
@@ -476,12 +568,16 @@ static int ddr_perf_event_add(struct perf_event *event, int flags) hwc->idx = counter; hwc->state |=PERF_HES_STOPPED ; +if (is_imx93 (pmu)) +/* read trans, write trans, read beat */ +imx93_ddr_perf_monitor_config (pmu, cfg, cfg1, cfg2); +else +/* write beat, read beat2, read beat1, read beat */ +imx95_ddr_perf_monitor_config (pmu, cfg, cfg1, cfg2); +if (flags &PERF_EF_START )ddr_perf_event_start (event, flags); -/* read trans, write trans, read beat */ -ddr_perf_monitor_config (pmu, cfg, cfg1, cfg2); -return 0 ; }
@@ -596,6 +692,39 @@ static int ddr_perf_offline_cpu(unsigned int cpu, struct hlist_node *node)return 0 ; } +static int ddr_perf_add_events (struct ddr_pmu *pmu) +{ +int i, ret; +struct attribute **attrs = pmu->devtype_data->attrs; +struct device *pmu_dev = pmu->pmu.dev; + +if (!attrs) +return 0 ; + +for (i =0 ; attrs[i]; i++) { + ret =sysfs_add_file_to_group (&pmu_dev->kobj, attrs[i],"events" ); +if (ret) { +dev_warn (pmu->dev,"i.MX9 DDR Perf add events failed (%d)\n" , ret); +return ret; + } + } + +return 0 ; +} + +static void ddr_perf_remove_events (struct ddr_pmu *pmu) +{ +int i; +struct attribute **attrs = pmu->devtype_data->attrs; +struct device *pmu_dev = pmu->pmu.dev; + +if (!attrs) +return ; + +for (i =0 ; attrs[i]; i++) +sysfs_remove_file_from_group (&pmu_dev->kobj, attrs[i],"events" ); +} +static int ddr_perf_probe (struct platform_device *pdev) {struct ddr_pmu *pmu;
@@ -666,6 +795,10 @@ static int ddr_perf_probe(struct platform_device *pdev)if (ret) goto ddr_perf_err; + ret =ddr_perf_add_events (pmu); +if (ret) +dev_warn (&pdev->dev,"i.MX9 DDR Perf filter events are missing\n" ); +return 0 ; ddr_perf_err:
@@ -683,6 +816,8 @@ static int ddr_perf_remove(struct platform_device *pdev) {struct ddr_pmu *pmu =platform_get_drvdata (pdev); +ddr_perf_remove_events (pmu); +cpuhp_state_remove_instance_nocalls (pmu->cpuhp_state, &pmu->node);cpuhp_remove_multi_state (pmu->cpuhp_state);
Signature · 1 line
2.34.1
Xu Yang
maintainerRE: [PATCH v2 2/4] perf: imx_perf: add support for i.MX95 platform
Quoted 354 lines
Subject: [PATCH v2 2/4] perf:
imx_perf: add support for i.MX95 platformi.MX95 has a DDR PMU which is almostly same as i.MX93, it now supports read beat and write beat filter capabilities. This will add support for i.MX95 and enhance the driver to support specific filter handling for it.
Usage:
For read beat:
~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt2,counter=3,axi_mask=ID_MASK,axi_id=ID/ ~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt1,counter=4,axi_mask=ID_MASK,axi_id=ID/ ~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt0,counter=5,axi_mask=ID_MASK,axi_id=ID/
eg: For edma2: perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_rd_beat_filt0,counter=5,axi_mask=0x00f,axi_id=0x00c/For write beat:
~# perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_wr_beat_filt,counter=2,axi_mask=ID_MASK,axi_id=ID/
eg: For edma2: perf stat -a -I 1000 -e imx9_ddr0/eddrtq_pm_wr_beat_filt,counter=2,axi_mask=0x00f,axi_id=0x00c/Signed-off-by Xu Yang <[email protected]>---
Changes in v2:
- put soc spefific axi filter events to drvdata according to franks suggestions.
- adjust pmcfgaxi_idandaxi_maskconfig--- drivers/perf/fsl_imx9_ddr_perf.c | 203 +++++++++++++++++++++++++------ 1 file changed, 169 insertions(+), 34 deletions(-)drivers/perf/fsl_imx9_ddr_perf.c +169
-35@@ -11,14 +11,24 @@#include <linux/perf_event.h> /* Performance monitor configuration */ -#define PMCFG1 0x00 -#define PMCFG1_RD_TRANS_FILT_EN BIT(31) -#define PMCFG1_WR_TRANS_FILT_EN BIT(30) -#define PMCFG1_RD_BT_FILT_EN BIT(29) -#define PMCFG1_ID_MASK GENMASK(17, 0) +#define PMCFG1 0x00 +#define MX93_PMCFG1_RD_TRANS_FILT_EN BIT(31) +#define MX93_PMCFG1_WR_TRANS_FILT_EN BIT(30) +#define MX93_PMCFG1_RD_BT_FILT_EN BIT(29) +#define MX93_PMCFG1_ID_MASK GENMASK(17, 0) -#define PMCFG2 0x04 -#define PMCFG2_ID GENMASK(17, 0) +#define MX95_PMCFG1_WR_BEAT_FILT_EN BIT(31) +#define MX95_PMCFG1_RD_BEAT_FILT_EN BIT(30) + +#define PMCFG2 0x04 +#define MX93_PMCFG2_ID GENMASK(17, 0) + +#define PMCFG3 0x08 +#define PMCFG4 0x0C +#define PMCFG5 0x10 +#define PMCFG6 0x14 +#define MX95_PMCFG_ID_MASK GENMASK(9, 0) +#define MX95_PMCFG_ID GENMASK(25, 16)/* Global control register affects all counters and takes priority over local control registers */ #define PMGC0 0x40@@ -51,6 +61,7 @@ static DEFINE_IDA(ddr_ida);struct imx_ddr_devtype_data {const char *identifier;/* system PMU identifier for userspace */ +struct attribute **attrs;/* AXI filter attributes */ };struct ddr_pmu {@@ -67,16 +78,6 @@ struct ddr_pmu {int id; }; -static const struct imx_ddr_devtype_data imx93_devtype_data = { - .identifier ="imx93" , -}; - -static const struct of_device_id imx_ddr_pmu_dt_ids[] = { - {.compatible ="fsl,imx93-ddr-pmu" , .data = &imx93_devtype_data}, - {/* sentinel */ } -}; -MODULE_DEVICE_TABLE (of, imx_ddr_pmu_dt_ids); -static ssize_t ddr_perf_identifier_show (struct device *dev,struct device_attribute *attr,char *page)@@ -178,7 +179,6 @@ static struct attribute *ddr_perf_events_attrs[] = {IMX9_DDR_PMU_EVENT_ATTR (ddrc_ld_wiq_6,70 ),IMX9_DDR_PMU_EVENT_ATTR (ddrc_ld_wiq_7,71 ),IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pmon_empty,72 ), -IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_trans_filt,73 ),/* counter3 specific events */ IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_row_collision_0, 64),@@ -190,7 +190,6 @@ static struct attribute *ddr_perf_events_attrs[] = {IMX9_DDR_PMU_EVENT_ATTR (ddrc_qx_row_collision_6,70 ),IMX9_DDR_PMU_EVENT_ATTR (ddrc_qx_row_collision_7,71 ),IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pmon_full,72 ), -IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_wr_trans_filt,73 ),/* counter4 specific events */ IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_row_open_0, 64),@@ -202,7 +201,6 @@ static struct attribute *ddr_perf_events_attrs[] = {IMX9_DDR_PMU_EVENT_ATTR (ddrc_qx_row_open_6,70 ),IMX9_DDR_PMU_EVENT_ATTR (ddrc_qx_row_open_7,71 ),IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pmon_ld_rdq2_rmw,72 ), -IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_beat_filt,73 ),/* counter5 specific events */ IMX9_DDR_PMU_EVENT_ATTR(ddrc_qx_valid_start_0, 64),@@ -242,6 +240,28 @@ static const struct attribute_group ddr_perf_events_attr_group = { .attrs = ddr_perf_events_attrs, }; +static struct attribute *imx93_ddr_perf_events_attrs[] = { +/* counter2 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_trans_filt,73 ), +/* counter3 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_wr_trans_filt,73 ), +/* counter4 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_beat_filt,73 ), +NULL , +}; + +static struct attribute *imx95_ddr_perf_events_attrs[] = { +/* counter2 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_wr_beat_filt,73 ), +/* counter3 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_beat_filt2,73 ), +/* counter4 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_beat_filt1,73 ), +/* counter5 specific events */ +IMX9_DDR_PMU_EVENT_ATTR (eddrtq_pm_rd_beat_filt0,73 ), +NULL , +}; +PMU_FORMAT_ATTR (event,"config:0-7" );PMU_FORMAT_ATTR (counter,"config:8-15" );PMU_FORMAT_ATTR (axi_id,"config1:0-17" );@@ -268,6 +288,28 @@ static const struct attribute_group *attr_groups[] = { NULL, }; +static const struct imx_ddr_devtype_data imx93_devtype_data = { + .identifier ="imx93" , + .attrs = imx93_ddr_perf_events_attrs, +}; + +static const struct imx_ddr_devtype_data imx95_devtype_data = { + .identifier ="imx95" , + .attrs = imx95_ddr_perf_events_attrs, +}; + +static const struct of_device_id imx_ddr_pmu_dt_ids[] = { + { .compatible ="fsl,imx93-ddr-pmu" , .data = &imx93_devtype_data }, + { .compatible ="fsl,imx95-ddr-pmu" , .data = &imx95_devtype_data }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, imx_ddr_pmu_dt_ids); + +static inline bool is_imx93 (struct ddr_pmu *pmu) +{ +return pmu->devtype_data == &imx93_devtype_data; +} +static void ddr_perf_clear_counter (struct ddr_pmu *pmu,int counter) {if (counter ==CYCLES_COUNTER ) {@@ -361,7 +403,7 @@ static void ddr_perf_counter_local_config(struct ddr_pmu *pmu, int config, } } -static void ddr_perf_monitor_config (struct ddr_pmu *pmu,int cfg,int cfg1,int cfg2) +static void imx93_ddr_perf_monitor_config (struct ddr_pmu *pmu,int cfg,int cfg1,int cfg2) {u32 pmcfg1, pmcfg2;int event, counter;@@ -372,30 +414,80 @@ static void ddr_perf_monitor_config(struct ddr_pmu *pmu, int cfg, int cfg1, int pmcfg1 =readl_relaxed (pmu->base +PMCFG1 );if (counter ==2 && event ==73 ) - pmcfg1 |=PMCFG1_RD_TRANS_FILT_EN ; + pmcfg1 |=MX93_PMCFG1_RD_TRANS_FILT_EN ;else if (counter ==2 && event !=73 ) - pmcfg1 &= ~PMCFG1_RD_TRANS_FILT_EN ; + pmcfg1 &= ~MX93_PMCFG1_RD_TRANS_FILT_EN ;if (counter ==3 && event ==73 ) - pmcfg1 |=PMCFG1_WR_TRANS_FILT_EN ; + pmcfg1 |=MX93_PMCFG1_WR_TRANS_FILT_EN ;else if (counter ==3 && event !=73 ) - pmcfg1 &= ~PMCFG1_WR_TRANS_FILT_EN ; + pmcfg1 &= ~MX93_PMCFG1_WR_TRANS_FILT_EN ;if (counter ==4 && event ==73 ) - pmcfg1 |=PMCFG1_RD_BT_FILT_EN ; + pmcfg1 |=MX93_PMCFG1_RD_BT_FILT_EN ;else if (counter ==4 && event !=73 ) - pmcfg1 &= ~PMCFG1_RD_BT_FILT_EN ; + pmcfg1 &= ~MX93_PMCFG1_RD_BT_FILT_EN ; - pmcfg1 &= ~FIELD_PREP (PMCFG1_ID_MASK ,0x3FFFF ); - pmcfg1 |=FIELD_PREP (PMCFG1_ID_MASK , cfg2); + pmcfg1 &= ~FIELD_PREP (MX93_PMCFG1_ID_MASK ,0x3FFFF ); + pmcfg1 |=FIELD_PREP (MX93_PMCFG1_ID_MASK , cfg2);writel (pmcfg1, pmu->base +PMCFG1 ); pmcfg2 =readl_relaxed (pmu->base +PMCFG2 ); - pmcfg2 &= ~FIELD_PREP (PMCFG2_ID ,0x3FFFF ); - pmcfg2 |=FIELD_PREP (PMCFG2_ID , cfg1); + pmcfg2 &= ~FIELD_PREP (MX93_PMCFG2_ID ,0x3FFFF ); + pmcfg2 |=FIELD_PREP (MX93_PMCFG2_ID , cfg1);writel (pmcfg2, pmu->base +PMCFG2 ); } +static void imx95_ddr_perf_monitor_config (struct ddr_pmu *pmu,int cfg,int cfg1,int cfg2) +{ +u32 pmcfg1, pmcfg, offset =0 ; +int event, counter; + + event = cfg &0x000000FF ; + counter = (cfg &0x0000FF00 ) >>8 ; + + pmcfg1 =readl_relaxed (pmu->base +PMCFG1 ); + +if (counter ==2 && event ==73 ) { + pmcfg1 |=MX95_PMCFG1_WR_BEAT_FILT_EN ; + offset =PMCFG3 ; + }else if (counter ==2 && event !=73 ) { + pmcfg1 &= ~MX95_PMCFG1_WR_BEAT_FILT_EN ; + } + +if (counter ==3 && event ==73 ) { + pmcfg1 |=MX95_PMCFG1_RD_BEAT_FILT_EN ; + offset =PMCFG4 ; + }else if (counter ==3 && event !=73 ) { + pmcfg1 &= ~MX95_PMCFG1_RD_BEAT_FILT_EN ; + } + +if (counter ==4 && event ==73 ) { + pmcfg1 |=MX95_PMCFG1_RD_BEAT_FILT_EN ; + offset =PMCFG5 ; + }else if (counter ==4 && event !=73 ) { + pmcfg1 &= ~MX95_PMCFG1_RD_BEAT_FILT_EN ; + } + +if (counter ==5 && event ==73 ) { + pmcfg1 |=MX95_PMCFG1_RD_BEAT_FILT_EN ; + offset =PMCFG6 ; + }else if (counter ==5 && event !=73 ) { + pmcfg1 &= ~MX95_PMCFG1_RD_BEAT_FILT_EN ; + } + +writel (pmcfg1, pmu->base +PMCFG1 ); + +if (offset) { + pmcfg =readl_relaxed (pmu->base + offset); + pmcfg &= ~(FIELD_PREP (MX95_PMCFG_ID_MASK ,0x3FF ) | +FIELD_PREP (MX95_PMCFG_ID ,0x3FF )); + pmcfg |= (FIELD_PREP (MX95_PMCFG_ID_MASK , cfg2) | +FIELD_PREP (MX95_PMCFG_ID , cfg1)); +writel (pmcfg, pmu->base + offset); + } +} +static void ddr_perf_event_update (struct perf_event *event) {struct ddr_pmu *pmu =to_ddr_pmu (event->pmu);@@ -476,12 +568,16 @@ static int ddr_perf_event_add(struct perf_event *event, int flags) hwc->idx = counter; hwc->state |=PERF_HES_STOPPED ; +if (is_imx93 (pmu)) +/* read trans, write trans, read beat */ +imx93_ddr_perf_monitor_config (pmu, cfg, cfg1, cfg2); +else +/* write beat, read beat2, read beat1, read beat */ +imx95_ddr_perf_monitor_config (pmu, cfg, cfg1, cfg2); +if (flags &PERF_EF_START )ddr_perf_event_start (event, flags); -/* read trans, write trans, read beat */ -ddr_perf_monitor_config (pmu, cfg, cfg1, cfg2); -return 0 ; }@@ -596,6 +692,39 @@ static int ddr_perf_offline_cpu(unsigned int cpu, struct hlist_node *node)return 0 ; } +static int ddr_perf_add_events (struct ddr_pmu *pmu) +{ +int i, ret; +struct attribute **attrs = pmu->devtype_data->attrs; +struct device *pmu_dev = pmu->pmu.dev; + +if (!attrs) +return 0 ; + +for (i =0 ; attrs[i]; i++) { + ret =sysfs_add_file_to_group (&pmu_dev->kobj, attrs[i],"events" ); +if (ret) { +dev_warn (pmu->dev,"i.MX9 DDR Perf add events failed (%d)\n" , ret); +return ret; + } + } + +return 0 ; +} + +static void ddr_perf_remove_events (struct ddr_pmu *pmu) +{ +int i; +struct attribute **attrs = pmu->devtype_data->attrs; +struct device *pmu_dev = pmu->pmu.dev; + +if (!attrs) +return ; + +for (i =0 ; attrs[i]; i++) +sysfs_remove_file_from_group (&pmu_dev->kobj, attrs[i],"events" ); +} +static int ddr_perf_probe (struct platform_device *pdev) {struct ddr_pmu *pmu;@@ -666,6 +795,10 @@ static int ddr_perf_probe(struct platform_device *pdev)if (ret) goto ddr_perf_err; + ret =ddr_perf_add_events (pmu); +if (ret) +dev_warn (&pdev->dev,"i.MX9 DDR Perf filter events are missing\n" ); +return 0 ; ddr_perf_err:@@ -683,6 +816,8 @@ static int ddr_perf_remove(struct platform_device *pdev) {struct ddr_pmu *pmu =platform_get_drvdata (pdev); +ddr_perf_remove_events (pmu); +cpuhp_state_remove_instance_nocalls (pmu->cpuhp_state, &pmu->node);cpuhp_remove_multi_state (pmu->cpuhp_state); --
Quoted 1 line
2.34.1
A gentle ping.
Xu Yang
maintainerPATCH v2 3/4 perf: imx_perf: limit counter ID from user space and optimize counter usage
In reply to Xu YangThe user can pass any counter ID to perf app. However, current pmu driver doesn't judge the validity of the counter ID. This will add necessary check for counter ID from user space. Besides, this pmu has 10 counters except cycle counter which can be used to count reference events and counter specific evnets. This will also add supports to auto allocate counter if the user doesn't pass it the perf. Then, the usage of counter will be optimized.
---
Changes in v2:
- limit counter ID from user to 0-10
- combine dynamic and static allocation of counter
--- drivers/perf/fsl_imx9_ddr_perf.c | 69 +++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-)
drivers/perf/fsl_imx9_ddr_perf.c +67 -2
@@ -51,6 +51,7 @@#define NUM_COUNTERS 11#define CYCLES_COUNTER 0 +#define CYCLES_EVENT_ID 0#define to_ddr_pmu (p) container_of(p, struct ddr_pmu, pmu)
@@ -235,6 +236,14 @@ static struct attribute *ddr_perf_events_attrs[] = { NULL, }; +static bool ddr_perf_is_specific_event (int event) +{ +if (event >=64 && event <=73 ) +return true; +else +return false; +} +static const struct attribute_group ddr_perf_events_attr_group = { .name ="events" , .attrs = ddr_perf_events_attrs,
@@ -507,6 +516,7 @@ static int ddr_perf_event_init(struct perf_event *event)struct ddr_pmu *pmu =to_ddr_pmu (event->pmu);struct hw_perf_event *hwc = &event->hw;struct perf_event *sibling; +int event_id, counter;if (event->attr.type != event->pmu->type)return -ENOENT ;
@@ -519,6 +529,18 @@ static int ddr_perf_event_init(struct perf_event *event)return -EOPNOTSUPP ; } + counter = (event->attr.config &0xFF00 ) >>8 ; +if (counter >NUM_COUNTERS ) { +dev_warn (pmu->dev,"Only counter 0-10 is supported!\n" ); +return -EINVAL ; + } + + event_id = event->attr.config &0x00FF ; +if (ddr_perf_is_specific_event (event_id) && counter ==0 ) { +dev_err (pmu->dev,"Need specify counter for counter specific events!\n" ); +return -EINVAL ; + } +/* * We must NOT create groups containing mixed PMUs, although software * events are acceptable (for example to create a CCN group
@@ -552,6 +574,39 @@ static void ddr_perf_event_start(struct perf_event *event, int flags) hwc->state =0 ; } +static int ddr_perf_alloc_counter (struct ddr_pmu *pmu,int event,int counter) +{ +int i; + +if (event ==CYCLES_EVENT_ID ) { +/* +* Always map cycle event to counter 0. +* Cycles counter is dedicated for cycle event +* can't used for the other events. +*/ +if (pmu->events[CYCLES_COUNTER ] ==NULL ) +return CYCLES_COUNTER ; + }else if (counter !=0 ) { +/* +* 1. ddr_perf_event_init() will make sure counter +* is not 0 for counter specific events. +* 2. Allow specify counter for referene event too. +*/ +if (pmu->events[counter] ==NULL ) +return counter; + }else { +/* +* Counter may be 0 if user doesn't specify it. +* Auto allocate counter for referene event. +*/ +for (i =1 ; i <NUM_COUNTERS ; i++) +if (pmu->events[i] ==NULL ) +return i; + } + +return -ENOENT ; +} +static int ddr_perf_event_add (struct perf_event *event,int flags) {struct ddr_pmu *pmu =to_ddr_pmu (event->pmu);
@@ -559,9 +614,17 @@ static int ddr_perf_event_add(struct perf_event *event, int flags)int cfg = event->attr.config;int cfg1 = event->attr.config1;int cfg2 = event->attr.config2; -int counter; +int event_id, counter; - counter = (cfg &0x0000FF00 ) >>8 ; + event_id = cfg &0x00FF ; + counter = (cfg &0xFF00 ) >>8 ; + +/* check if counter is available */ + counter =ddr_perf_alloc_counter (pmu, event_id, counter); +if (counter <0 ) { +dev_dbg (pmu->dev,"There are not enough counters\n" ); +return -EOPNOTSUPP ; + } pmu->events[counter] = event; pmu->active_events++;
@@ -597,9 +660,11 @@ static void ddr_perf_event_del(struct perf_event *event, int flags) {struct ddr_pmu *pmu =to_ddr_pmu (event->pmu);struct hw_perf_event *hwc = &event->hw; +int counter = hwc->idx;ddr_perf_event_stop (event,PERF_EF_UPDATE ); + pmu->events[counter] =NULL ; pmu->active_events--; hwc->idx =-1 ; }
Signature · 1 line
2.34.1
Xu Yang
maintainerPATCH v2 4/4 perf vendor events arm64:: Add i.MX95 DDR Performane Monitor metrics
In reply to Xu YangAdd JSON metrics for i.MX95 DDR Performane Monitor.
---
Changes in v2:
- fix wrong AXI_MASK setting
- remove unnecessary metrics
- add bandwidth_usage, camera_all, disp_all metrics
--- .../arch/arm64/freescale/imx95/sys/ddrc.json | 9 + .../arm64/freescale/imx95/sys/metrics.json | 778 ++++++++++++++++++ tools/perf/pmu-events/jevents.py | 1 + 3 files changed, 788 insertions(+) create mode 100644 tools/perf/pmu-events/arch/arm64/freescale/imx95/sys/ddrc.json create mode 100644 tools/perf/pmu-events/arch/arm64/freescale/imx95/sys/metrics.json
tools/perf/pmu-events/arch/arm64/freescale/imx95/sys/ddrc.json new file +9 -0
@@ -0,0 +1,9 @@ +[ + { + "BriefDescription": "ddr cycles event", + "EventCode": "0x00", + "EventName": "imx95_ddr.cycles", + "Unit": "imx9_ddr", + "Compat": "imx95" + } +]
tools/perf/pmu-events/arch/arm64/freescale/imx95/sys/metrics.json new file +778 -0
778 lines not on this page · raw message
tools/perf/pmu-events/jevents.py +1 -0
@@ -284,6 +284,7 @@ class JsonEvent: 'hisi_sccl,hha': 'hisi_sccl,hha', 'hisi_sccl,l3c': 'hisi_sccl,l3c', 'imx8_ddr': 'imx8_ddr', + 'imx9_ddr': 'imx9_ddr', 'L3PMC': 'amd_l3', 'DFPMC': 'amd_df', 'cpu_core': 'cpu_core',
Signature · 1 line
2.34.1
Quoted 1 line · Xu Yang
i.MX95 has a DDR pmu. This will add a compatible for it.
On v1 we had a discussion because the commit message wasn't clear about whether or not the device was compatible with existing ones. For some reason, the v2 patch _removes_ information from the commit message rather than tries to explain.
This [1] message of yours, that I didn't get a chance to reply to before you sent this new version, seems to say that there should be an imx93-ddr-pmu fallback.
Cheers,
Conor.
Quoted 25 lines
Signed-off-by Xu Yang <[email protected]>---
Changes in v2:
- no changes--- Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +1
-0@@ -20,6 +20,7 @@ properties: - fsl,imx8mn-ddr-pmu - fsl,imx8mp-ddr-pmu - fsl,imx93-ddr-pmu + - fsl,imx95-ddr-pmu - items: - enum: - fsl,imx8mm-ddr-pmuSignature · 1 line
2.34.1
Xu Yang
maintainerHi Conor,
Quoted 10 lines · Xu Yang
Quoted 1 line
i.MX95 has a DDR pmu. This will add a compatible for it.
On v1 we had a discussion because the commit message wasn't clear about whether or not the device was compatible with existing ones. For some reason, the v2 patch _removes_ information from the commit message rather than tries to explain.
This [1] message of yours, that I didn't get a chance to reply to before you sent this new version, seems to say that there should be an imx93-ddr-pmu fallback.
Thanks for your comments.
Just read my previous comment in [1] and found I made a mistake. Now I'll try to clarify it here.
Imx95 and imx93 have different AXI filter configuration. I need a compatible for imx95 since the driver cannot differentiate them.
Then I need to consider below two options:
1. compatible = "fsl,imx95-ddr-pmu", "fsl,imx93-ddr-pmu"
2. compatible = "fsl,imx95-ddr-pmu"
Both of them work correctly on imx95. When I make changes in driver for imx95, imx93 is not affected.
For basic functions, imx95 is compatible with imx93. I select the 2rd form for simplicity. If the first form is optimal, I can change it in next version.
Thanks,
Xu Yang
Quoted 33 lines
Cheers,
Conor.Documentation/devicetree/bindings/perf/fsl-imx-
Quoted 11 lines
Signed-off-by Xu Yang <[email protected]>---
Changes in v2:
- no changes--- Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/perf/fsl-imx- renamed from Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +0
-0
ddr.yamlQuoted 14 lines
index
e9fad4b3de68..1bc7bf1c8368100644Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +1
-1@@ -20,6 +20,7 @@ properties: - fsl,imx8mn-ddr-pmu - fsl,imx8mp-ddr-pmu - fsl,imx93-ddr-pmu + - fsl,imx95-ddr-pmu - items: - enum: - fsl,imx8mm-ddr-pmu --2.34.1
Quoted 25 lines · Xu Yang
Hi Conor,
Quoted 10 lines · Xu Yang
Quoted 1 line
i.MX95 has a DDR pmu. This will add a compatible for it.
On v1 we had a discussion because the commit message wasn't clear about whether or not the device was compatible with existing ones. For some reason, the v2 patch _removes_ information from the commit message rather than tries to explain.
This [1] message of yours, that I didn't get a chance to reply to before you sent this new version, seems to say that there should be an imx93-ddr-pmu fallback.Thanks for your comments.
Just read my previous comment in [1] and found I made a mistake. Now I'll try to clarify it here.
Imx95 and imx93 have different AXI filter configuration. I need a compatible for imx95 since the driver cannot differentiate them.
Then I need to consider below two options:
1. compatible = "fsl,imx95-ddr-pmu", "fsl,imx93-ddr-pmu"
2. compatible = "fsl,imx95-ddr-pmu"
Quoted 6 lines
Both of them work correctly on imx95. When I make changes in driver for imx95, imx93 is not affected.
For basic functions, imx95 is compatible with imx93. I select the 2rd form for simplicity. If the first form is optimal, I can change it in next version.
The first form is preferred, yes.
Xu Yang
maintainerQuoted 28 lines
Subject: [PATCH v2 1/4] dt-bindings: perf: fsl-imx-ddr: Add i.MX95 compatible
i.MX95 has a DDR pmu. This will add a compatible for it.
Signed-off-by Xu Yang <[email protected]>---
Changes in v2:
- no changes--- Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/perf/fsl- renamed from Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +0
-0
imx-ddr.yaml
indexe9fad4b3de68..1bc7bf1c8368100644Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +1
-1@@ -20,6 +20,7 @@ properties: - fsl,imx8mn-ddr-pmu - fsl,imx8mp-ddr-pmu - fsl,imx93-ddr-pmu + - fsl,imx95-ddr-pmu - items: - enum: - fsl,imx8mm-ddr-pmu --
Quoted 1 line
2.34.1
A gentle ping.
Quoted 23 lines · Xu Yang
Quoted 23 lines
Subject: [PATCH v2 1/4] dt-bindings: perf: fsl-imx-ddr: Add i.MX95 compatible
i.MX95 has a DDR pmu. This will add a compatible for it.
Signed-off-by Xu Yang <[email protected]>---
Changes in v2:
- no changes--- Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/perf/fsl- renamed from Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +0
-0
imx-ddr.yaml
indexe9fad4b3de68..1bc7bf1c8368100644Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +0
-0@@ -20,6 +20,7 @@ properties: - fsl,imx8mn-ddr-pmu - fsl,imx8mp-ddr-pmu - fsl,imx93-ddr-pmu
Quoted 8 lines
Quoted 6 lines
Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +1
-1+ - fsl,imx95-ddr-pmu - items: - enum: - fsl,imx8mm-ddr-pmu --2.34.1
A gentle ping.
What do you mean? Weren't you asked to fix things, were you? Why do you ping then?
Best regards,
Krzysztof
Xu Yang
maintainerQuoted 35 lines · Xu Yang
Quoted 23 lines
Quoted 23 lines
Subject: [PATCH v2 1/4] dt-bindings: perf: fsl-imx-ddr: Add i.MX95 compatible
i.MX95 has a DDR pmu. This will add a compatible for it.
Signed-off-by Xu Yang <[email protected]>---
Changes in v2:
- no changes--- Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/perf/fsl- renamed from Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +0
-0
imx-ddr.yaml
indexe9fad4b3de68..1bc7bf1c8368100644Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +0
-0@@ -20,6 +20,7 @@ properties: - fsl,imx8mn-ddr-pmu - fsl,imx8mp-ddr-pmu - fsl,imx93-ddr-pmuQuoted 8 lines
Quoted 6 lines
Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +1
-1+ - fsl,imx95-ddr-pmu - items: - enum: - fsl,imx8mm-ddr-pmu --2.34.1
A gentle ping.
Quoted 2 lines
What do you mean? Weren't you asked to fix things, were you? Why do you ping then?
Sorry for inconvenience. It’s my mistake to ping this one.
Quoted 3 lines
Best regards,
Krzysztof