Skip to content

Commit e89ecd8

Browse files
Xu Yangwilldeacon
authored andcommitted
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. Signed-off-by: Xu Yang <xu.yang_2@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://lore.kernel.org/r/20230811015438.1999307-1-xu.yang_2@nxp.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 83a6d80 commit e89ecd8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

drivers/perf/fsl_imx8_ddr_perf.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@
2727
#define CNTL_CLEAR_MASK 0xFFFFFFFD
2828
#define CNTL_OVER_MASK 0xFFFFFFFE
2929

30+
#define CNTL_CP_SHIFT 16
31+
#define CNTL_CP_MASK (0xFF << CNTL_CP_SHIFT)
3032
#define CNTL_CSV_SHIFT 24
3133
#define CNTL_CSV_MASK (0xFFU << CNTL_CSV_SHIFT)
3234

3335
#define EVENT_CYCLES_ID 0
3436
#define EVENT_CYCLES_COUNTER 0
3537
#define NUM_COUNTERS 4
3638

39+
/* For removing bias if cycle counter CNTL.CP is set to 0xf0 */
40+
#define CYCLES_COUNTER_MASK 0x0FFFFFFF
3741
#define AXI_MASKING_REVERT 0xffff0000 /* AXI_MASKING(MSB 16bits) + AXI_ID(LSB 16bits) */
3842

3943
#define to_ddr_pmu(p) container_of(p, struct ddr_pmu, pmu)
@@ -426,6 +430,17 @@ static void ddr_perf_counter_enable(struct ddr_pmu *pmu, int config,
426430
writel(0, pmu->base + reg);
427431
val = CNTL_EN | CNTL_CLEAR;
428432
val |= FIELD_PREP(CNTL_CSV_MASK, config);
433+
434+
/*
435+
* On i.MX8MP we need to bias the cycle counter to overflow more often.
436+
* We do this by initializing bits [23:16] of the counter value via the
437+
* COUNTER_CTRL Counter Parameter (CP) field.
438+
*/
439+
if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER_ENHANCED) {
440+
if (counter == EVENT_CYCLES_COUNTER)
441+
val |= FIELD_PREP(CNTL_CP_MASK, 0xf0);
442+
}
443+
429444
writel(val, pmu->base + reg);
430445
} else {
431446
/* Disable counter */
@@ -465,6 +480,12 @@ static void ddr_perf_event_update(struct perf_event *event)
465480
int ret;
466481

467482
new_raw_count = ddr_perf_read_counter(pmu, counter);
483+
/* Remove the bias applied in ddr_perf_counter_enable(). */
484+
if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER_ENHANCED) {
485+
if (counter == EVENT_CYCLES_COUNTER)
486+
new_raw_count &= CYCLES_COUNTER_MASK;
487+
}
488+
468489
local64_add(new_raw_count, &event->count);
469490

470491
/*

0 commit comments

Comments
 (0)