Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

PM / devfreq: rockchip-dfi: Use free running counter

The DDR_MON counters are free running counters. These are resetted to 0
when starting them over like currently done when reading the current
counter values.

Resetting the counters becomes a problem with perf support we want to
add later, because perf needs counters that are not modified elsewhere.

This patch removes resetting the counters and keeps them running
instead. That means we no longer use the absolute counter values but
instead compare them with the counter values we read last time. Not
stopping the counters also has the impact that they are running while
we are reading them. We cannot read multiple timers atomically, so
the values do not exactly fit together. The effect should be negligible
though as the time between two measurements is some orders of magnitude
bigger than the time we need to read multiple registers.

Link: https://lore.kernel.org/all/20231018061714.3553817-7-s.hauer@pengutronix.de/
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>

authored by

Sascha Hauer and committed by
Chanwoo Choi
99911664 6c29e29e

+30 -22
+30 -22
drivers/devfreq/event/rockchip-dfi.c
··· 38 38 #define DDRMON_CH1_COUNT_NUM 0x3c 39 39 #define DDRMON_CH1_DFI_ACCESS_NUM 0x40 40 40 41 - struct dmc_usage { 41 + struct dmc_count_channel { 42 42 u32 access; 43 43 u32 total; 44 + }; 45 + 46 + struct dmc_count { 47 + struct dmc_count_channel c[RK3399_DMC_NUM_CH]; 44 48 }; 45 49 46 50 /* ··· 55 51 struct rockchip_dfi { 56 52 struct devfreq_event_dev *edev; 57 53 struct devfreq_event_desc desc; 58 - struct dmc_usage ch_usage[RK3399_DMC_NUM_CH]; 54 + struct dmc_count last_event_count; 59 55 struct device *dev; 60 56 void __iomem *regs; 61 57 struct regmap *regmap_pmu; ··· 89 85 writel_relaxed(SOFTWARE_DIS, dfi_regs + DDRMON_CTRL); 90 86 } 91 87 92 - static int rockchip_dfi_get_busier_ch(struct devfreq_event_dev *edev) 88 + static void rockchip_dfi_read_counters(struct devfreq_event_dev *edev, struct dmc_count *count) 93 89 { 94 90 struct rockchip_dfi *dfi = devfreq_event_get_drvdata(edev); 95 - u32 tmp, max = 0; 96 - u32 i, busier_ch = 0; 91 + u32 i; 97 92 void __iomem *dfi_regs = dfi->regs; 98 93 99 - rockchip_dfi_stop_hardware_counter(edev); 100 - 101 - /* Find out which channel is busier */ 102 94 for (i = 0; i < RK3399_DMC_NUM_CH; i++) { 103 - dfi->ch_usage[i].access = readl_relaxed(dfi_regs + 95 + count->c[i].access = readl_relaxed(dfi_regs + 104 96 DDRMON_CH0_DFI_ACCESS_NUM + i * 20); 105 - dfi->ch_usage[i].total = readl_relaxed(dfi_regs + 97 + count->c[i].total = readl_relaxed(dfi_regs + 106 98 DDRMON_CH0_COUNT_NUM + i * 20); 107 - tmp = dfi->ch_usage[i].access; 108 - if (tmp > max) { 109 - busier_ch = i; 110 - max = tmp; 111 - } 112 99 } 113 - rockchip_dfi_start_hardware_counter(edev); 114 - 115 - return busier_ch; 116 100 } 117 101 118 102 static int rockchip_dfi_disable(struct devfreq_event_dev *edev) ··· 137 145 struct devfreq_event_data *edata) 138 146 { 139 147 struct rockchip_dfi *dfi = devfreq_event_get_drvdata(edev); 140 - int busier_ch; 148 + struct dmc_count count; 149 + struct dmc_count *last = &dfi->last_event_count; 150 + u32 access = 0, total = 0; 151 + int i; 141 152 142 - busier_ch = rockchip_dfi_get_busier_ch(edev); 153 + rockchip_dfi_read_counters(edev, &count); 143 154 144 - edata->load_count = dfi->ch_usage[busier_ch].access * 4; 145 - edata->total_count = dfi->ch_usage[busier_ch].total; 155 + /* We can only report one channel, so find the busiest one */ 156 + for (i = 0; i < RK3399_DMC_NUM_CH; i++) { 157 + u32 a = count.c[i].access - last->c[i].access; 158 + u32 t = count.c[i].total - last->c[i].total; 159 + 160 + if (a > access) { 161 + access = a; 162 + total = t; 163 + } 164 + } 165 + 166 + edata->load_count = access * 4; 167 + edata->total_count = total; 168 + 169 + dfi->last_event_count = count; 146 170 147 171 return 0; 148 172 }