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

arm: pmu: Share user ABI format mechanism with SPE

This mechanism makes it much easier to define and read new attributes
so move it to the arm_pmu.h header so that it can be shared. At the same
time update the existing format attributes to use it.

GENMASK has to be changed to GENMASK_ULL because the config fields are
64 bits even on arm32 where this will also be used now.

Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-7-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>

authored by

James Clark and committed by
Will Deacon
f6da8696 3115ee02

+38 -27
+16 -5
drivers/perf/arm_pmuv3.c
··· 299 299 .is_visible = armv8pmu_event_attr_is_visible, 300 300 }; 301 301 302 - PMU_FORMAT_ATTR(event, "config:0-15"); 303 - PMU_FORMAT_ATTR(long, "config1:0"); 304 - PMU_FORMAT_ATTR(rdpmc, "config1:1"); 302 + /* User ABI */ 303 + #define ATTR_CFG_FLD_event_CFG config 304 + #define ATTR_CFG_FLD_event_LO 0 305 + #define ATTR_CFG_FLD_event_HI 15 306 + #define ATTR_CFG_FLD_long_CFG config1 307 + #define ATTR_CFG_FLD_long_LO 0 308 + #define ATTR_CFG_FLD_long_HI 0 309 + #define ATTR_CFG_FLD_rdpmc_CFG config1 310 + #define ATTR_CFG_FLD_rdpmc_LO 1 311 + #define ATTR_CFG_FLD_rdpmc_HI 1 312 + 313 + GEN_PMU_FORMAT_ATTR(event); 314 + GEN_PMU_FORMAT_ATTR(long); 315 + GEN_PMU_FORMAT_ATTR(rdpmc); 305 316 306 317 static int sysctl_perf_user_access __read_mostly; 307 318 308 319 static bool armv8pmu_event_is_64bit(struct perf_event *event) 309 320 { 310 - return event->attr.config1 & 0x1; 321 + return ATTR_CFG_GET_FLD(&event->attr, long); 311 322 } 312 323 313 324 static bool armv8pmu_event_want_user_access(struct perf_event *event) 314 325 { 315 - return event->attr.config1 & 0x2; 326 + return ATTR_CFG_GET_FLD(&event->attr, rdpmc); 316 327 } 317 328 318 329 static struct attribute *armv8_pmuv3_format_attrs[] = {
-22
drivers/perf/arm_spe_pmu.c
··· 206 206 #define ATTR_CFG_FLD_inv_event_filter_LO 0 207 207 #define ATTR_CFG_FLD_inv_event_filter_HI 63 208 208 209 - /* Why does everything I do descend into this? */ 210 - #define __GEN_PMU_FORMAT_ATTR(cfg, lo, hi) \ 211 - (lo) == (hi) ? #cfg ":" #lo "\n" : #cfg ":" #lo "-" #hi 212 - 213 - #define _GEN_PMU_FORMAT_ATTR(cfg, lo, hi) \ 214 - __GEN_PMU_FORMAT_ATTR(cfg, lo, hi) 215 - 216 - #define GEN_PMU_FORMAT_ATTR(name) \ 217 - PMU_FORMAT_ATTR(name, \ 218 - _GEN_PMU_FORMAT_ATTR(ATTR_CFG_FLD_##name##_CFG, \ 219 - ATTR_CFG_FLD_##name##_LO, \ 220 - ATTR_CFG_FLD_##name##_HI)) 221 - 222 - #define _ATTR_CFG_GET_FLD(attr, cfg, lo, hi) \ 223 - ((((attr)->cfg) >> lo) & GENMASK(hi - lo, 0)) 224 - 225 - #define ATTR_CFG_GET_FLD(attr, name) \ 226 - _ATTR_CFG_GET_FLD(attr, \ 227 - ATTR_CFG_FLD_##name##_CFG, \ 228 - ATTR_CFG_FLD_##name##_LO, \ 229 - ATTR_CFG_FLD_##name##_HI) 230 - 231 209 GEN_PMU_FORMAT_ATTR(ts_enable); 232 210 GEN_PMU_FORMAT_ATTR(pa_enable); 233 211 GEN_PMU_FORMAT_ATTR(pct_enable);
+22
include/linux/perf/arm_pmu.h
··· 183 183 #define ARMV8_SPE_PDEV_NAME "arm,spe-v1" 184 184 #define ARMV8_TRBE_PDEV_NAME "arm,trbe" 185 185 186 + /* Why does everything I do descend into this? */ 187 + #define __GEN_PMU_FORMAT_ATTR(cfg, lo, hi) \ 188 + (lo) == (hi) ? #cfg ":" #lo "\n" : #cfg ":" #lo "-" #hi 189 + 190 + #define _GEN_PMU_FORMAT_ATTR(cfg, lo, hi) \ 191 + __GEN_PMU_FORMAT_ATTR(cfg, lo, hi) 192 + 193 + #define GEN_PMU_FORMAT_ATTR(name) \ 194 + PMU_FORMAT_ATTR(name, \ 195 + _GEN_PMU_FORMAT_ATTR(ATTR_CFG_FLD_##name##_CFG, \ 196 + ATTR_CFG_FLD_##name##_LO, \ 197 + ATTR_CFG_FLD_##name##_HI)) 198 + 199 + #define _ATTR_CFG_GET_FLD(attr, cfg, lo, hi) \ 200 + ((((attr)->cfg) >> lo) & GENMASK_ULL(hi - lo, 0)) 201 + 202 + #define ATTR_CFG_GET_FLD(attr, name) \ 203 + _ATTR_CFG_GET_FLD(attr, \ 204 + ATTR_CFG_FLD_##name##_CFG, \ 205 + ATTR_CFG_FLD_##name##_LO, \ 206 + ATTR_CFG_FLD_##name##_HI) 207 + 186 208 #endif /* __ARM_PMU_H__ */