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.

coresight: Interpret ETMv3 config with ATTR_CFG_GET_FLD()

Currently we're programming attr->config directly into ETMCR after some
validation. This obscures which fields are being used, and also makes it
impossible to move fields around or use other configN fields in the
future.

Improve it by only reading the fields that are valid and then setting
the appropriate ETMCR bits based on each one.

The ETMCR_CTXID_SIZE part can be removed as it was never a valid option
because it's not in ETM3X_SUPPORTED_OPTIONS.

Reviewed-by: Leo Yan <leo.yan@arm.com>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
Tested-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20251128-james-cs-syncfreq-v8-6-4d319764cc58@linaro.org

authored by

James Clark and committed by
Suzuki K Poulose
a1d19cd2 458db625

+13 -11
+13 -11
drivers/hwtracing/coresight/coresight-etm3x-core.c
··· 28 28 #include <linux/uaccess.h> 29 29 #include <linux/clk.h> 30 30 #include <linux/perf_event.h> 31 + #include <linux/perf/arm_pmu.h> 31 32 #include <asm/sections.h> 32 33 33 34 #include "coresight-etm.h" ··· 340 339 if (attr->config & ~ETM3X_SUPPORTED_OPTIONS) 341 340 return -EINVAL; 342 341 343 - config->ctrl = attr->config; 342 + config->ctrl = 0; 344 343 345 - /* Don't trace contextID when runs in non-root PID namespace */ 346 - if (!task_is_in_init_pid_ns(current)) 347 - config->ctrl &= ~ETMCR_CTXID_SIZE; 344 + if (ATTR_CFG_GET_FLD(attr, cycacc)) 345 + config->ctrl |= ETMCR_CYC_ACC; 346 + 347 + if (ATTR_CFG_GET_FLD(attr, timestamp)) 348 + config->ctrl |= ETMCR_TIMESTAMP_EN; 348 349 349 350 /* 350 - * Possible to have cores with PTM (supports ret stack) and ETM 351 - * (never has ret stack) on the same SoC. So if we have a request 352 - * for return stack that can't be honoured on this core then 353 - * clear the bit - trace will still continue normally 351 + * Possible to have cores with PTM (supports ret stack) and ETM (never 352 + * has ret stack) on the same SoC. So only enable when it can be honored 353 + * - trace will still continue normally otherwise. 354 354 */ 355 - if ((config->ctrl & ETMCR_RETURN_STACK) && 356 - !(drvdata->etmccer & ETMCCER_RETSTACK)) 357 - config->ctrl &= ~ETMCR_RETURN_STACK; 355 + if (ATTR_CFG_GET_FLD(attr, retstack) && 356 + (drvdata->etmccer & ETMCCER_RETSTACK)) 357 + config->ctrl |= ETMCR_RETURN_STACK; 358 358 359 359 return 0; 360 360 }