[v4,4/6] perf: imx_perf: add macro definitions for parsing config attr
Commit Message
The user can set event and counter in cmdline and the driver need to parse
it using 'config' attr value. This will add macro definitions to avoid
hard-code in driver.
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
Changes in v4:
- new patch
---
drivers/perf/fsl_imx9_ddr_perf.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
Comments
On Wed, Jan 31, 2024 at 01:58:09PM +0800, Xu Yang wrote:
> The user can set event and counter in cmdline and the driver need to parse
> it using 'config' attr value. This will add macro definitions to avoid
> hard-code in driver.
>
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
>
> ---
> Changes in v4:
> - new patch
> ---
> drivers/perf/fsl_imx9_ddr_perf.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/perf/fsl_imx9_ddr_perf.c b/drivers/perf/fsl_imx9_ddr_perf.c
> index 85aaaef7212f..94041f06c152 100644
> --- a/drivers/perf/fsl_imx9_ddr_perf.c
> +++ b/drivers/perf/fsl_imx9_ddr_perf.c
> @@ -52,6 +52,11 @@
> #define NUM_COUNTERS 11
> #define CYCLES_COUNTER 0
>
> +#define CONFIG_EVENT_MASK 0x00FF
> +#define CONFIG_EVENT_OFFSET 0
> +#define CONFIG_COUNTER_MASK 0xFF00
> +#define CONFIG_COUNTER_OFFSET 8
Can you move this patch earlier, please, so that the imx95 support can use
these new definitions immediately?
Will
Hi Will,
>
> On Wed, Jan 31, 2024 at 01:58:09PM +0800, Xu Yang wrote:
> > The user can set event and counter in cmdline and the driver need to parse
> > it using 'config' attr value. This will add macro definitions to avoid
> > hard-code in driver.
> >
> > Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> >
> > ---
> > Changes in v4:
> > - new patch
> > ---
> > drivers/perf/fsl_imx9_ddr_perf.c | 19 +++++++++++++------
> > 1 file changed, 13 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/perf/fsl_imx9_ddr_perf.c b/drivers/perf/fsl_imx9_ddr_perf.c
> > index 85aaaef7212f..94041f06c152 100644
> > --- a/drivers/perf/fsl_imx9_ddr_perf.c
> > +++ b/drivers/perf/fsl_imx9_ddr_perf.c
> > @@ -52,6 +52,11 @@
> > #define NUM_COUNTERS 11
> > #define CYCLES_COUNTER 0
> >
> > +#define CONFIG_EVENT_MASK 0x00FF
> > +#define CONFIG_EVENT_OFFSET 0
> > +#define CONFIG_COUNTER_MASK 0xFF00
> > +#define CONFIG_COUNTER_OFFSET 8
>
> Can you move this patch earlier, please, so that the imx95 support can use
> these new definitions immediately?
Yes, I will try it in next version.
Thanks,
Xu Yang
>
> Will
@@ -52,6 +52,11 @@
#define NUM_COUNTERS 11
#define CYCLES_COUNTER 0
+#define CONFIG_EVENT_MASK 0x00FF
+#define CONFIG_EVENT_OFFSET 0
+#define CONFIG_COUNTER_MASK 0xFF00
+#define CONFIG_COUNTER_OFFSET 8
+
#define to_ddr_pmu(p) container_of(p, struct ddr_pmu, pmu)
#define DDR_PERF_DEV_NAME "imx9_ddr"
@@ -381,8 +386,10 @@ static void ddr_perf_counter_local_config(struct ddr_pmu *pmu, int config,
int counter, bool enable)
{
u32 ctrl_a;
+ int event;
ctrl_a = readl_relaxed(pmu->base + PMLCA(counter));
+ event = (config & CONFIG_EVENT_MASK) >> CONFIG_EVENT_OFFSET;
if (enable) {
ctrl_a |= PMLCA_FC;
@@ -394,7 +401,7 @@ static void ddr_perf_counter_local_config(struct ddr_pmu *pmu, int config,
ctrl_a &= ~PMLCA_FC;
ctrl_a |= PMLCA_CE;
ctrl_a &= ~FIELD_PREP(PMLCA_EVENT, 0x7F);
- ctrl_a |= FIELD_PREP(PMLCA_EVENT, (config & 0x000000FF));
+ ctrl_a |= FIELD_PREP(PMLCA_EVENT, event);
writel(ctrl_a, pmu->base + PMLCA(counter));
} else {
/* Freeze counter. */
@@ -408,8 +415,8 @@ static void imx93_ddr_perf_monitor_config(struct ddr_pmu *pmu, int cfg, int cfg1
u32 pmcfg1, pmcfg2;
int event, counter;
- event = cfg & 0x000000FF;
- counter = (cfg & 0x0000FF00) >> 8;
+ event = (cfg & CONFIG_EVENT_MASK) >> CONFIG_EVENT_OFFSET;
+ counter = (cfg & CONFIG_COUNTER_MASK) >> CONFIG_COUNTER_OFFSET;
pmcfg1 = readl_relaxed(pmu->base + PMCFG1);
@@ -443,8 +450,8 @@ static void imx95_ddr_perf_monitor_config(struct ddr_pmu *pmu, int cfg, int cfg1
u32 pmcfg1, pmcfg, offset = 0;
int event, counter;
- event = cfg & 0x000000FF;
- counter = (cfg & 0x0000FF00) >> 8;
+ event = (cfg & CONFIG_EVENT_MASK) >> CONFIG_EVENT_OFFSET;
+ counter = (cfg & CONFIG_COUNTER_MASK) >> CONFIG_COUNTER_OFFSET;
pmcfg1 = readl_relaxed(pmu->base + PMCFG1);
@@ -561,7 +568,7 @@ static int ddr_perf_event_add(struct perf_event *event, int flags)
int cfg2 = event->attr.config2;
int counter;
- counter = (cfg & 0x0000FF00) >> 8;
+ counter = (cfg & CONFIG_COUNTER_MASK) >> CONFIG_COUNTER_OFFSET;
pmu->events[counter] = event;
pmu->active_events++;