perf/imx_ddr: speed up overflow frequency of cycle
Xu Yang
maintainerPATCH v3 1/2 perf/imx_ddr: speed up overflow frequency of cycle
For i.MX8MP, we cannot ensure that cycle counter overflow occurs at least 4 times as often as other events. Due to byte counters will count for any event configured, it will overflow more often. And if byte counters overflow that related counters would stop since they share the COUNTER_CNTL. We can speed up cycle counter overflow frequency by setting counter parameter (CP) field of cycle counter. In this way, we can avoid stop counting byte counters when interrupt didn't come and the byte counters can be fetched or updated from each cycle counter overflow interrupt.
Because we initialize CP filed to shorten counter0 overflow time, the cycle counter will start couting from a fixed/base value each time. We need to remove the base from the result too. Therefore, we could get precise result from cycle counter.
---
Changes in v3:
- modify the comments as suggested from Mark
- use mask to remove bias value
- merge two patches to one
Changes in v2:
- improve if condition
--- drivers/perf/fsl_imx8_ddr_perf.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/perf/fsl_imx8_ddr_perf.c +21 -0
@@ -28,6 +28,8 @@#define CNTL_CLEAR_MASK 0xFFFFFFFD#define CNTL_OVER_MASK 0xFFFFFFFE +#define CNTL_CP_SHIFT 16 +#define CNTL_CP_MASK (0xFF << CNTL_CP_SHIFT)#define CNTL_CSV_SHIFT 24#define CNTL_CSV_MASK (0xFFU << CNTL_CSV_SHIFT)
@@ -427,6 +429,17 @@ static void ddr_perf_counter_enable(struct ddr_pmu *pmu, int config,writel (0 , pmu->base + reg); val =CNTL_EN |CNTL_CLEAR ; val |=FIELD_PREP (CNTL_CSV_MASK , config); + +/* +* On i.MX8MP we need to bias the cycle counter to overflow more often. +* We do this by initializing bits [31:28] of the counter value via the +* COUNTER_CTRL Counter Parameter (CP) field. +*/ +if (pmu->devtype_data->quirks &DDR_CAP_AXI_ID_FILTER_ENHANCED ) { +if (counter ==EVENT_CYCLES_COUNTER ) + val |=FIELD_PREP (CNTL_CP_MASK ,0xf0 ); + } +writel (val, pmu->base + reg); }else {/* Disable counter */
@@ -466,6 +479,14 @@ static void ddr_perf_event_update(struct perf_event *event)int ret; new_raw_count =ddr_perf_read_counter (pmu, counter); +/* +* Remove the bias applied in ddr_perf_counter_enable(). +*/ +if (pmu->devtype_data->quirks &DDR_CAP_AXI_ID_FILTER_ENHANCED ) { +if (counter ==EVENT_CYCLES_COUNTER ) + new_raw_count &=0x0fffffff ; + } +local64_add (new_raw_count, &event->count);/*
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Xu Yang
maintainerPATCH v3 2/2 perf/imx_ddr: don't enable counter0 if none of 4 counters
In current driver, counter0 will be enabled after ddr_perf_pmu_enable() is called even though none of the 4 counters are used. This will cause counter0 continue to count until ddr_perf_pmu_disabled() is called. If pmu is not disabled all the time, the pmu interrupt will be asserted from time to time due to counter0 will overflow and irq handler will clear it. It's not an expected behavior. This patch will not enable counter0 if none of 4 counters are used.
---
Changes in v3:
- don't differentiate cycle counter and other counters
- modify logic in pmu_enable()/pmu_disable()
Changes in v2:
- add active events count as suggested from Frank
--- drivers/perf/fsl_imx8_ddr_perf.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/perf/fsl_imx8_ddr_perf.c +15 -7
@@ -103,6 +103,7 @@ struct ddr_pmu {const struct fsl_ddr_devtype_data *devtype_data;int irq;int id; +int active_count; }; static ssize_t ddr_perf_identifier_show(struct device *dev,
@@ -516,6 +517,7 @@ static void ddr_perf_event_start(struct perf_event *event, int flags)ddr_perf_counter_enable (pmu, event->attr.config, counter, true); + pmu->active_count++; hwc->state =0 ; }
@@ -569,6 +571,7 @@ static void ddr_perf_event_stop(struct perf_event *event, int flags)ddr_perf_counter_enable (pmu, event->attr.config, counter, false);ddr_perf_event_update (event); + pmu->active_count--; hwc->state |=PERF_HES_STOPPED ; }
@@ -588,8 +591,11 @@ static void ddr_perf_pmu_enable(struct pmu *pmu) {struct ddr_pmu *ddr_pmu =to_ddr_pmu (pmu); -/* enable cycle counter if cycle is not active event list */ -if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL ) +/* +* Because counter 1-3 depend on cycle counter, treat cycle +* counter as main switch when any counter of the 4 need to run. +*/ +if (ddr_pmu->active_count >0 ) ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER,
@@ -600,11 +606,13 @@ static void ddr_perf_pmu_disable(struct pmu *pmu) {struct ddr_pmu *ddr_pmu =to_ddr_pmu (pmu); -if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL ) -ddr_perf_counter_enable (ddr_pmu, -EVENT_CYCLES_ID , -EVENT_CYCLES_COUNTER , - false); +/* +* Counting should be stopped. Disable cycle counter unconditionally. +*/ +ddr_perf_counter_enable (ddr_pmu, +EVENT_CYCLES_ID , +EVENT_CYCLES_COUNTER , + false); } static int ddr_perf_init(struct ddr_pmu *pmu, void __iomem *base,
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Frank Li
maintainerRE: [PATCH v3 2/2] perf/imx_ddr: don't enable counter0 if none of 4 counters
Quoted 86 lines
-----Original Message-----
From: Xu Yang <[email protected]>
Sent: Tuesday, August 8, 2023 2:28 AM
To: Frank Li <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; [email protected]
Subject: [PATCH v3 2/2] perf/imx_ddr: don't enable counter0 if none of 4 countersIn current driver, counter0 will be enabled after
ddr_perf_pmu_enable()is called even though none of the 4 counters are used. This will cause counter0 continue to count untilddr_perf_pmu_disabled()is called. If pmu is not disabled all the time, the pmu interrupt will be asserted from time to time due to counter0 will overflow and irq handler will clear it. It's not an expected behavior. This patch will not enable counter0 if none of 4 counters are used.Fixes 9a66d36cc7ac ("drivers/perf: imx_ddr: Add DDR performance countersupport to perf")
Signed-off-by Xu Yang <[email protected]>---
Changes in v3:
- don't differentiate cycle counter and other counters
- modify logic in pmu_enable()/pmu_disable()
Changes in v2:
- add active events count as suggested from Frank--- drivers/perf/fsl_imx8_ddr_perf.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)drivers/perf/fsl_imx8_ddr_perf.c +8
-4@@ -103,6 +103,7 @@ struct ddr_pmu {const struct fsl_ddr_devtype_data *devtype_data;int irq;int id; +int active_count; }; static ssize_t ddr_perf_identifier_show(struct device *dev,@@ -516,6 +517,7 @@ static void ddr_perf_event_start(struct perf_event *event, int flags)ddr_perf_counter_enable (pmu, event->attr.config, counter, true); + pmu->active_count++; hwc->state =0 ; }@@ -569,6 +571,7 @@ static void ddr_perf_event_stop(struct perf_event *event, int flags)ddr_perf_counter_enable (pmu, event->attr.config, counter, false);ddr_perf_event_update (event); + pmu->active_count--; hwc->state |=PERF_HES_STOPPED ; }@@ -588,8 +591,11 @@ static void ddr_perf_pmu_enable(struct pmu *pmu) {struct ddr_pmu *ddr_pmu =to_ddr_pmu (pmu); -/* enable cycle counter if cycle is not active event list */ -if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL ) +/* +* Because counter 1-3 depend on cycle counter, treat cycle +* counter as main switch when any counter of the 4 need to run. +*/ +if (ddr_pmu->active_count >0 ) ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER,@@ -600,11 +606,13 @@ static void ddr_perf_pmu_disable(struct pmu *pmu) {struct ddr_pmu *ddr_pmu =to_ddr_pmu (pmu); -if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL ) - ddr_perf_counter_enable(ddr_pmu,
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_pmu_disable(struct pmu · line 616
Quoted 10 lines
drivers/perf/fsl_imx8_ddr_perf.c +7
-3-EVENT_CYCLES_ID , -EVENT_CYCLES_COUNTER , - false); +/* +* Counting should be stopped. Disable cycle counter unconditionally. +*/ +ddr_perf_counter_enable (ddr_pmu, +EVENT_CYCLES_ID , +EVENT_CYCLES_COUNTER , + false);
What's happen if one event is running in back ground, but another event try to disable it.
Quoted 5 lines
drivers/perf/fsl_imx8_ddr_perf.c +0
-0}static int ddr_perf_init(struct
ddr_pmu*pmu, void__iomem*base,
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Xu Yang
maintainerRE: [PATCH v3 2/2] perf/imx_ddr: don't enable counter0 if none of 4 counters
Quoted 93 lines
-----Original Message-----
From: Frank Li <[email protected]>
Sent: Tuesday, August 8, 2023 10:43 PM
To: Xu Yang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]
Subject: RE: [PATCH v3 2/2] perf/imx_ddr: don't enable counter0 if none of 4 countersQuoted 82 lines
-----Original Message-----
From: Xu Yang <[email protected]>
Sent: Tuesday, August 8, 2023 2:28 AM
To: Frank Li <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; [email protected]
Subject: [PATCH v3 2/2] perf/imx_ddr: don't enable counter0 if none of 4 countersIn current driver, counter0 will be enabled after
ddr_perf_pmu_enable()is called even though none of the 4 counters are used. This will cause counter0 continue to count untilddr_perf_pmu_disabled()is called. If pmu is not disabled all the time, the pmu interrupt will be asserted from time to time due to counter0 will overflow and irq handler will clear it. It's not an expected behavior. This patch will not enable counter0 if none of 4 counters are used.Fixes 9a66d36cc7ac ("drivers/perf: imx_ddr: Add DDR performance countersupport to perf")
Signed-off-by Xu Yang <[email protected]>---
Changes in v3:
- don't differentiate cycle counter and other counters
- modify logic in pmu_enable()/pmu_disable()
Changes in v2:
- add active events count as suggested from Frank--- drivers/perf/fsl_imx8_ddr_perf.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)drivers/perf/fsl_imx8_ddr_perf.c +8
-2@@ -103,6 +103,7 @@ struct ddr_pmu {const struct fsl_ddr_devtype_data *devtype_data;int irq;int id; +int active_count; }; static ssize_t ddr_perf_identifier_show(struct device *dev,@@ -516,6 +517,7 @@ static void ddr_perf_event_start(struct perf_event *event, int flags)ddr_perf_counter_enable (pmu, event->attr.config, counter, true); + pmu->active_count++; hwc->state =0 ; }@@ -569,6 +571,7 @@ static void ddr_perf_event_stop(struct perf_event *event, int flags)ddr_perf_counter_enable (pmu, event->attr.config, counter, false);ddr_perf_event_update (event); + pmu->active_count--; hwc->state |=PERF_HES_STOPPED ; }@@ -588,8 +591,11 @@ static void ddr_perf_pmu_enable(struct pmu *pmu) {struct ddr_pmu *ddr_pmu =to_ddr_pmu (pmu); -/* enable cycle counter if cycle is not active event list */ -if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL ) +/* +* Because counter 1-3 depend on cycle counter, treat cycle +* counter as main switch when any counter of the 4 need to run. +*/ +if (ddr_pmu->active_count >0 ) ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER,@@ -600,11 +606,13 @@ static void ddr_perf_pmu_disable(struct pmu *pmu) {struct ddr_pmu *ddr_pmu =to_ddr_pmu (pmu);
Quoted 15 lines
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_pmu_disable(struct pmu *pmu) · line 615
Quoted 12 lines
drivers/perf/fsl_imx8_ddr_perf.c +7
-5-if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL ) -ddr_perf_counter_enable (ddr_pmu, -EVENT_CYCLES_ID , -EVENT_CYCLES_COUNTER , - false); +/* +* Counting should be stopped. Disable cycle counter unconditionally. +*/ +ddr_perf_counter_enable (ddr_pmu, +EVENT_CYCLES_ID , +EVENT_CYCLES_COUNTER , + false);What's happen if one event is running in back ground, but another event try to disable it.
pmu_enable() will be called at the end. cycle counter will be reopened finally.
Quoted 6 lines
Quoted 6 lines
drivers/perf/fsl_imx8_ddr_perf.c +0
-0}static int ddr_perf_init(struct
ddr_pmu*pmu, void__iomem*base,
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Frank Li
maintainerQuoted 69 lines
-----Original Message-----
From: Xu Yang <[email protected]>
Sent: Tuesday, August 8, 2023 2:28 AM
To: Frank Li <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; [email protected]
Subject: [PATCH v3 1/2] perf/imx_ddr: speed up overflow frequency of cycleFor i.MX8MP, we cannot ensure that cycle counter overflow occurs at least 4 times as often as other events. Due to byte counters will count for any event configured, it will overflow more often. And if byte counters overflow that related counters would stop since they share the
COUNTER_CNTL. We can speed up cycle counter overflow frequency by setting
counter parameter (CP) field of cycle counter. In this way, we can avoid stop counting byte counters when interrupt didn't come and the byte counters can be fetched or updated from each cycle counter overflow interrupt.Because we initialize CP filed to shorten counter0 overflow time, the cycle counter will start couting from a fixed/base value each time. We need to remove the base from the result too. Therefore, we could get precise result from cycle counter.
Signed-off-by Xu Yang <[email protected]>---
Changes in v3:
- modify the comments as suggested from Mark
- use mask to remove bias value
- merge two patches to one
Changes in v2:
- improve if condition--- drivers/perf/fsl_imx8_ddr_perf.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)drivers/perf/fsl_imx8_ddr_perf.c +5
-0@@ -28,6 +28,8 @@#define CNTL_CLEAR_MASK 0xFFFFFFFD#define CNTL_OVER_MASK 0xFFFFFFFE +#define CNTL_CP_SHIFT 16 +#define CNTL_CP_MASK (0xFF << CNTL_CP_SHIFT)#define CNTL_CSV_SHIFT 24#define CNTL_CSV_MASK (0xFFU << CNTL_CSV_SHIFT)@@ -427,6 +429,17 @@ static void ddr_perf_counter_enable(struct ddr_pmu *pmu, int config, writel(0, pmu->base + reg); val =CNTL_EN |CNTL_CLEAR ; val |=FIELD_PREP (CNTL_CSV_MASK , config); + +/* +* On i.MX8MP we need to bias the cycle counter to overflow more often.
drivers/perf/fsl_imx8_ddr_perf.c +1
-0+* We do this by initializing bits [31:28] of the counter value via the
drivers/perf/fsl_imx8_ddr_perf.c +3
-0+* COUNTER_CTRL Counter Parameter (CP) field. +*/ + if (pmu->devtype_data->quirks &
DDR_CAP_AXI_ID_FILTER_ENHANCED) {
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_counter_enable(struct ddr_pmu *pmu, int config, · line 440
Quoted 2 lines
drivers/perf/fsl_imx8_ddr_perf.c +2
-0+if (counter ==EVENT_CYCLES_COUNTER ) + val |=FIELD_PREP (CNTL_CP_MASK ,0xf0 );
Comment said init bits 31: 28, CNTL_CP_MASK is 0xFF << 16. It is bits 24:16.
Quoted 7 lines
drivers/perf/fsl_imx8_ddr_perf.c +2
-0+ } +writel (val, pmu->base + reg); }else {/* Disable counter */ @@ -466,6 +479,14 @@ static void ddr_perf_event_update(struct perf_event *event)
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_event_update(struct · line 489
Quoted 10 lines
drivers/perf/fsl_imx8_ddr_perf.c +6
-0int ret; new_raw_count =ddr_perf_read_counter (pmu, counter); +/* +* Remove the bias applied in ddr_perf_counter_enable(). +*/ +if (pmu->devtype_data->quirks &DDR_CAP_AXI_ID_FILTER_ENHANCED ) { +if (counter ==EVENT_CYCLES_COUNTER ) + new_raw_count &=0x0fffffff ;
Is it ~ CNTL_CP_MASK?
Quoted 7 lines
drivers/perf/fsl_imx8_ddr_perf.c +2
-0+ } +local64_add (new_raw_count, &event->count);/*
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Xu Yang
maintainerQuoted 64 lines
Quoted 64 lines
-----Original Message-----
From: Xu Yang <[email protected]>
Sent: Tuesday, August 8, 2023 2:28 AM
To: Frank Li <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; [email protected]
Subject: [PATCH v3 1/2] perf/imx_ddr: speed up overflow frequency of cycleFor i.MX8MP, we cannot ensure that cycle counter overflow occurs at least 4 times as often as other events. Due to byte counters will count for any event configured, it will overflow more often. And if byte counters overflow that related counters would stop since they share the
COUNTER_CNTL. We can speed up cycle counter overflow frequency by setting
counter parameter (CP) field of cycle counter. In this way, we can avoid stop counting byte counters when interrupt didn't come and the byte counters can be fetched or updated from each cycle counter overflow interrupt.Because we initialize CP filed to shorten counter0 overflow time, the cycle counter will start couting from a fixed/base value each time. We need to remove the base from the result too. Therefore, we could get precise result from cycle counter.
Signed-off-by Xu Yang <[email protected]>---
Changes in v3:
- modify the comments as suggested from Mark
- use mask to remove bias value
- merge two patches to one
Changes in v2:
- improve if condition--- drivers/perf/fsl_imx8_ddr_perf.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)drivers/perf/fsl_imx8_ddr_perf.c +5
-0@@ -28,6 +28,8 @@#define CNTL_CLEAR_MASK 0xFFFFFFFD#define CNTL_OVER_MASK 0xFFFFFFFE +#define CNTL_CP_SHIFT 16 +#define CNTL_CP_MASK (0xFF << CNTL_CP_SHIFT)#define CNTL_CSV_SHIFT 24#define CNTL_CSV_MASK (0xFFU << CNTL_CSV_SHIFT)@@ -427,6 +429,17 @@ static void ddr_perf_counter_enable(struct ddr_pmu *pmu, int config, writel(0, pmu->base + reg); val =CNTL_EN |CNTL_CLEAR ; val |=FIELD_PREP (CNTL_CSV_MASK , config); + +/* +* On i.MX8MP we need to bias the cycle counter to overflow more often.
drivers/perf/fsl_imx8_ddr_perf.c +1
-0+* We do this by initializing bits [31:28] of the counter value via the
Quoted 8 lines
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_counter_enable(struct ddr_pmu *pmu, int config, · line 440
Quoted 6 lines
drivers/perf/fsl_imx8_ddr_perf.c +3
-0+* COUNTER_CTRL Counter Parameter (CP) field. +*/ + if (pmu->devtype_data->quirks &
DDR_CAP_AXI_ID_FILTER_ENHANCED) {drivers/perf/fsl_imx8_ddr_perf.c +2
-0+if (counter ==EVENT_CYCLES_COUNTER ) + val |=FIELD_PREP (CNTL_CP_MASK ,0xf0 );Comment said init bits 31: 28,
CNTL_CP_MASKis0xFF<< 16. It is bits 24:16.
Yes.
Quoted 10 lines
Quoted 10 lines
drivers/perf/fsl_imx8_ddr_perf.c +2
-0+ } +writel (val, pmu->base + reg); }else {/* Disable counter */ @@ -466,6 +479,14 @@ static void ddr_perf_event_update(struct perf_event *event)int ret;
Quoted 10 lines
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_event_update(struct perf_event *event) · line 487
Quoted 8 lines
drivers/perf/fsl_imx8_ddr_perf.c +6
-0new_raw_count =ddr_perf_read_counter (pmu, counter); +/* +* Remove the bias applied in ddr_perf_counter_enable(). +*/ +if (pmu->devtype_data->quirks &DDR_CAP_AXI_ID_FILTER_ENHANCED ) { +if (counter ==EVENT_CYCLES_COUNTER ) + new_raw_count &=0x0fffffff ;Is it ~
CNTL_CP_MASK?
Not. ~ CNTL_CP_MASK is 0xFF00FFFF.
Quoted 8 lines
Quoted 8 lines
drivers/perf/fsl_imx8_ddr_perf.c +2
-0+ } +local64_add (new_raw_count, &event->count);/*
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel