perf/imx_ddr: speed up overflow frequency of cycle counter
Xu Yang
maintainerPATCH 1/3 perf/imx_ddr: speed up overflow frequency of cycle counter
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.
--- drivers/perf/fsl_imx8_ddr_perf.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/perf/fsl_imx8_ddr_perf.c +16 -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,20 @@ 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); + +/* +* Workaround for i.MX8MP: +* Common counters and byte counters share the same COUNTER_CNTL, +* and byte counters could overflow before cycle counter. Need set +* counter parameter(CP) of cycle counter to give it initial value +* which can speed up cycle counter overflow frequency. +*/ +if ((pmu->devtype_data->quirks &DDR_CAP_AXI_ID_FILTER_ENHANCED ) == +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 */
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 2/3 perf/imx_ddr: adjust counter result after read cycle counter
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.
--- drivers/perf/fsl_imx8_ddr_perf.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/perf/fsl_imx8_ddr_perf.c +7 -0
@@ -482,6 +482,13 @@ static void ddr_perf_event_update(struct perf_event *event)int ret; new_raw_count =ddr_perf_read_counter (pmu, counter); +/* Workaround for i.MXMP */ +if ((pmu->devtype_data->quirks &DDR_CAP_AXI_ID_FILTER_ENHANCED ) == +DDR_CAP_AXI_ID_FILTER_ENHANCED ) { +if (counter ==EVENT_CYCLES_COUNTER ) + new_raw_count -=0xF0000000 ; + } +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
Frank Li
maintainerRE: [PATCH 2/3] perf/imx_ddr: adjust counter result after read cycle counter
Quoted 36 lines
-----Original Message-----
From: Xu Yang <[email protected]>
Sent: Wednesday, July 5, 2023 5:48 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]; Xu Yang <[email protected]>
Subject: [PATCH 2/3] perf/imx_ddr: adjust counter result after read cycle counterBecause 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]>--- drivers/perf/fsl_imx8_ddr_perf.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/perf/fsl_imx8_ddr_perf.c +2
-0@@ -482,6 +482,13 @@ static void ddr_perf_event_update(struct perf_event *event)int ret; new_raw_count =ddr_perf_read_counter (pmu, counter); +/* Workaround for i.MXMP */ + if ((pmu->devtype_data->quirks &
DDR_CAP_AXI_ID_FILTER_ENHANCED) ==
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_event_update(struct perf_event *event) · line 487
Quoted 1 line
drivers/perf/fsl_imx8_ddr_perf.c +1
-0+ DDR_CAP_AXI_ID_FILTER_ENHANCED) {
Supposed below check should be enough.
if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER_ENHANCED)
Quoted 9 lines
drivers/perf/fsl_imx8_ddr_perf.c +4
-1+if (counter ==EVENT_CYCLES_COUNTER ) + new_raw_count -=0xF0000000 ; + } +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
maintainerRE: [PATCH 2/3] perf/imx_ddr: adjust counter result after read cycle counter
Hi Frank,
Quoted 40 lines
-----Original Message-----
From: Frank Li <[email protected]>
Sent: Wednesday, July 5, 2023 10:53 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 2/3] perf/imx_ddr: adjust counter result after read cycle counterQuoted 30 lines
-----Original Message-----
From: Xu Yang <[email protected]>
Sent: Wednesday, July 5, 2023 5:48 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]; Xu Yang <[email protected]>
Subject: [PATCH 2/3] perf/imx_ddr: adjust counter result after read cycle counterBecause 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]>--- drivers/perf/fsl_imx8_ddr_perf.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/perf/fsl_imx8_ddr_perf.c +0
-0@@ -482,6 +482,13 @@ static void ddr_perf_event_update(struct perf_event *event)int ret;
Quoted 7 lines
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_event_update(struct perf_event *event) · line 487
Quoted 5 lines
drivers/perf/fsl_imx8_ddr_perf.c +2
-0new_raw_count =ddr_perf_read_counter (pmu, counter); +/* Workaround for i.MXMP */ + if ((pmu->devtype_data->quirks &
DDR_CAP_AXI_ID_FILTER_ENHANCED) ==drivers/perf/fsl_imx8_ddr_perf.c +1
-0+ DDR_CAP_AXI_ID_FILTER_ENHANCED) {Supposed below check should be enough.
No, this workaround is only for imx8mp. We need this condition to filter it. For other platforms, we'd better let cycle counter start counting from 0.
Thanks,
Xu Yang
Quoted 9 lines
if (
pmu->devtype_data->quirks&DDR_CAP_AXI_ID_FILTER_ENHANCED)Quoted 6 lines
drivers/perf/fsl_imx8_ddr_perf.c +4
-0+if (counter ==EVENT_CYCLES_COUNTER ) + new_raw_count -=0xF0000000 ; + } +local64_add (new_raw_count, &event->count);
Quoted 3 lines
Quoted 3 lines
/*
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Xu Yang
maintainerPATCH 3/3 perf/imx_ddr: don't enable counter0 if none of 4 counters are used
In reply to Xu YangIn 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.
--- drivers/perf/fsl_imx8_ddr_perf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/perf/fsl_imx8_ddr_perf.c +6 -2
@@ -591,7 +591,9 @@ 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 ) +if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL && + (ddr_pmu->events[0 ] || ddr_pmu->events[1 ] || + ddr_pmu->events[2 ] || ddr_pmu->events[3 ])) ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER,
@@ -602,7 +604,9 @@ 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 ) +if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL && + (ddr_pmu->events[0 ] || ddr_pmu->events[1 ] || + ddr_pmu->events[2 ] || ddr_pmu->events[3 ])) ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER,
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 3/3] perf/imx_ddr: don't enable counter0 if none of 4 counters are used
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_pmu_enable(struct pmu *pmu) · line 594
Quoted 12 lines
drivers/perf/fsl_imx8_ddr_perf.c +1
-1@@ -591,7 +591,9 @@ 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 ) + if (ddr_pmu->events[EVENT_CYCLES_COUNTER] == NULL &&
EVENT_CYCLES_COUNTER is 0, if only enable cycles counter, below logic
Will failure. Then counter will not work.
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_pmu_enable(struct pmu *pmu) · line 596
Quoted 2 lines
drivers/perf/fsl_imx8_ddr_perf.c +2
-0+ (ddr_pmu->events[0 ] || ddr_pmu->events[1 ] || + ddr_pmu->events[2] || ddr_pmu->events[3]))
I suggest maintain a enabled_event counter,
If(ddr_pmu->active_num==0) ddr_perf_counter_enable(..., true); ddr_pmu->active_num++;
At disable function()
{
ddr_pmu->active_num --;
if( ddr_pmu->active_num == 0)
ddr_perf_counter_enable(.., false);
}Quoted 15 lines
drivers/perf/fsl_imx8_ddr_perf.c +3
-2ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER,@@ -602,7 +604,9 @@ 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 ) +if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL && + (ddr_pmu->events[0 ] || ddr_pmu->events[1 ] || + ddr_pmu->events[2 ] || ddr_pmu->events[3 ])) ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER, --
Quoted 1 line
2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Xu Yang
maintainerRE: [PATCH 3/3] perf/imx_ddr: don't enable counter0 if none of 4 counters are used
Hi Frank,
Quoted 17 lines
-----Original Message-----
From: Frank Li <[email protected]>
Sent: Wednesday, July 5, 2023 10:51 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 3/3] perf/imx_ddr: don't enable counter0 if none of 4 counters are usedQuoted 9 lines
drivers/perf/fsl_imx8_ddr_perf.c +0
-0@@ -591,7 +591,9 @@ static void ddr_perf_pmu_enable(struct pmu *pmu)struct ddr_pmu *ddr_pmu =to_ddr_pmu (pmu);
Quoted 6 lines
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_pmu_enable(struct pmu *pmu) · line 594
Quoted 3 lines
drivers/perf/fsl_imx8_ddr_perf.c +1
-1/* enable cycle counter if cycle is not active event list */ -if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL ) + if (ddr_pmu->events[EVENT_CYCLES_COUNTER] == NULL &&
EVENT_CYCLES_COUNTERis 0, if only enable cycles counter, below logic
Will failure. Then counter will not work.
Yes, cycle counter will not be enabled for counting at this point. However, cycle counter will be enabled after perf_pmu_enable() is called. My understanding is that ddr_perf_pmu_enable() is used to enable cycle counter when other counters is used for counting since other counters depends on cycle counter.
Quoted 10 lines
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_pmu_enable(struct pmu *pmu) · line 596
Quoted 3 lines
drivers/perf/fsl_imx8_ddr_perf.c +2
-0+ (ddr_pmu->events[0 ] || ddr_pmu->events[1 ] || + ddr_pmu->events[2] || ddr_pmu->events[3]))I suggest maintain a
enabled_eventcounter,If(ddr_pmu->active_num==0) ddr_perf_counter_enable(..., true); ddr_pmu->active_num++;
Quoted 6 lines
At disable
function(){ ddr_pmu->active_num --; if( ddr_pmu->active_num == 0) ddr_perf_counter_enable(.., false); }
Will try to maintain a enabled_event counter.
Thanks,
Xu Yang
Quoted 9 lines
Quoted 9 lines
drivers/perf/fsl_imx8_ddr_perf.c +0
-0ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER,@@ -602,7 +604,9 @@ static void ddr_perf_pmu_disable(struct pmu *pmu) {struct ddr_pmu *ddr_pmu =to_ddr_pmu (pmu);
Quoted 9 lines
Quoted 9 lines
drivers/perf/fsl_imx8_ddr_perf.c +3
-2-if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL ) +if (ddr_pmu->events[EVENT_CYCLES_COUNTER ] ==NULL && + (ddr_pmu->events[0 ] || ddr_pmu->events[1 ] || + ddr_pmu->events[2 ] || ddr_pmu->events[3 ])) ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER, --2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Frank Li
maintainerQuoted 13 lines
drivers/perf/fsl_imx8_ddr_perf.c +4
-0+ +/* +* Workaround for i.MX8MP: +* Common counters and byte counters share the same
COUNTER_CNTL,(quoted diff) +1
-0+ * and byte counters could overflow before cycle counter.Need set
(quoted diff) +1
-0+ * counter parameter(CP) of cycle counter to give it initialvalue
drivers/perf/fsl_imx8_ddr_perf.c +3
-0+* which can speed up cycle counter overflow frequency. +*/ + 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 441
Quoted 1 line
drivers/perf/fsl_imx8_ddr_perf.c +1
-0+ DDR_CAP_AXI_ID_FILTER_ENHANCED) {
needn't ==
if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER_ENHANCED)
Did you fixed cycle counter also? Dose cycle counter read get correct value?
Frank
Quoted 9 lines
drivers/perf/fsl_imx8_ddr_perf.c +4
-1+if (counter ==EVENT_CYCLES_COUNTER ) + val |=FIELD_PREP (CNTL_CP_MASK ,0xf0 ); + } +writel (val, pmu->base + reg); }else {/* Disable counter */ --2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Xu Yang
maintainerHi Frank,
Quoted 17 lines
-----Original Message-----
From: Frank Li <[email protected]>
Sent: Wednesday, July 5, 2023 10:57 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 1/3] perf/imx_ddr: speed up overflow frequency of cycle counterQuoted 9 lines
drivers/perf/fsl_imx8_ddr_perf.c +4
-0+ +/* +* Workaround for i.MX8MP: +* Common counters and byte counters share the same
COUNTER_CNTL,(quoted diff) +1
-0+ * and byte counters could overflow before cycle counter.Need set
(quoted diff) +1
-0+ * counter parameter(CP) of cycle counter to give it initialvalue
Quoted 8 lines
drivers/perf/fsl_imx8_ddr_perf.c static void ddr_perf_counter_enable(struct ddr_pmu *pmu, int config, · line 441
Quoted 5 lines
drivers/perf/fsl_imx8_ddr_perf.c +3
-0+* which can speed up cycle counter overflow frequency. +*/ + if ((pmu->devtype_data->quirks &
DDR_CAP_AXI_ID_FILTER_ENHANCED) ==drivers/perf/fsl_imx8_ddr_perf.c +1
-0+ DDR_CAP_AXI_ID_FILTER_ENHANCED) {needn't
==
if (pmu->devtype_data->quirks&DDR_CAP_AXI_ID_FILTER_ENHANCED)
No, this workaround is only for imx8mp. We need this condition to filter it.
Quoted 2 lines
Did you fixed cycle counter also? Dose cycle counter read get correct value?
Does cycle counter has some issues? I have tested it and can get correct value from cycle counter.
Thanks,
Xu Yang
Quoted 12 lines
Frank
Quoted 9 lines
drivers/perf/fsl_imx8_ddr_perf.c +4
-1+if (counter ==EVENT_CYCLES_COUNTER ) + val |=FIELD_PREP (CNTL_CP_MASK ,0xf0 ); + } +writel (val, pmu->base + reg); }else {/* Disable counter */ --2.34.1
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel