This series is minor refactoring for trace filter and comes from the previous patch set [1].
The first patch introduces a new helper has_feat_trf() for detecing if FEAT_TRF is implemented. This is more readable.
The second patch refactors the ts_source_show() function. It simplifies to directly return the TS value when FEAT_TRF is implemented.
[1] https://lore.kernel.org/linux-arm-kernel/20250519174945.2245271-1-leo.yan@ar...
Changes from v2: - Added the has_feat_trf() helper for more readable (James Clark)
Leo Yan (2): coresight: etm4x: Introduce has_feat_trf() helper coresight: etm4x: Refactor returning TS field
drivers/hwtracing/coresight/coresight-etm4x-core.c | 8 ++++---- drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 18 +++--------------- drivers/hwtracing/coresight/coresight-etm4x.h | 9 +++++++++ 3 files changed, 16 insertions(+), 19 deletions(-)
Introduce a new helper, has_feat_trf(), to detect whether FEAT_TRF is implemented.
To avoid a SMP call for checking the system register, the function directly reads the configured value. If the value is non-zero, it indicates that the feature is present.
Signed-off-by: Leo Yan leo.yan@arm.com --- drivers/hwtracing/coresight/coresight-etm4x-core.c | 8 ++++---- drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 2 +- drivers/hwtracing/coresight/coresight-etm4x.h | 9 +++++++++ 3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index 42e5d37403ad..08deb67fe0ef 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -252,7 +252,7 @@ static void etm4x_prohibit_trace(struct etmv4_drvdata *drvdata) u64 trfcr;
/* If the CPU doesn't support FEAT_TRF, nothing to do */ - if (!drvdata->trfcr) + if (!has_feat_trf(drvdata)) return;
trfcr = drvdata->trfcr & ~(TRFCR_EL1_ExTRE | TRFCR_EL1_E0TRE); @@ -288,7 +288,7 @@ static void etm4x_allow_trace(struct etmv4_drvdata *drvdata) u64 trfcr, guest_trfcr;
/* If the CPU doesn't support FEAT_TRF, nothing to do */ - if (!drvdata->trfcr) + if (!has_feat_trf(drvdata)) return;
if (drvdata->config.mode & ETM_MODE_EXCL_HOST) @@ -1931,7 +1931,7 @@ static int etm4_cpu_save(struct etmv4_drvdata *drvdata) int ret = 0;
/* Save the TRFCR irrespective of whether the ETM is ON */ - if (drvdata->trfcr) + if (has_feat_trf(drvdata)) drvdata->save_trfcr = read_trfcr(); /* * Save and restore the ETM Trace registers only if @@ -2043,7 +2043,7 @@ static void __etm4_cpu_restore(struct etmv4_drvdata *drvdata)
static void etm4_cpu_restore(struct etmv4_drvdata *drvdata) { - if (drvdata->trfcr) + if (has_feat_trf(drvdata)) write_trfcr(drvdata->save_trfcr); if (drvdata->state_needs_restore) __etm4_cpu_restore(drvdata); diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c index ab251865b893..8afcc553bb97 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c @@ -2315,7 +2315,7 @@ static ssize_t ts_source_show(struct device *dev, int val; struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent);
- if (!drvdata->trfcr) { + if (!has_feat_trf(drvdata)) { val = -1; goto out; } diff --git a/drivers/hwtracing/coresight/coresight-etm4x.h b/drivers/hwtracing/coresight/coresight-etm4x.h index ac649515054d..1840e658eda2 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.h +++ b/drivers/hwtracing/coresight/coresight-etm4x.h @@ -1068,5 +1068,14 @@ static inline bool etm4x_is_ete(struct etmv4_drvdata *drvdata) return drvdata->arch >= ETM_ARCH_ETE; }
+static inline bool has_feat_trf(struct etmv4_drvdata *drvdata) +{ + /* + * drvdata->trfcr is initialized to a non-zero value if trace + * filtering is supported. + */ + return !!drvdata->trfcr; +} + void etm4_release_trace_id(struct etmv4_drvdata *drvdata); #endif
As TS == 0b00 is a valid value, this commit updates to return the value directly instead of converting it to -1.
Currently, only the virtual timestamp (0b01) is used, and other modes are not enabled. Therefore, this change is safe for user space tools.
Signed-off-by: Leo Yan leo.yan@arm.com --- drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c index 8afcc553bb97..653cb4ce17cf 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c @@ -2315,23 +2315,11 @@ static ssize_t ts_source_show(struct device *dev, int val; struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent);
- if (!has_feat_trf(drvdata)) { + if (!has_feat_trf(drvdata)) val = -1; - goto out; - } - - val = FIELD_GET(TRFCR_EL1_TS_MASK, drvdata->trfcr); - switch (val) { - case TRFCR_EL1_TS_VIRTUAL: - case TRFCR_EL1_TS_GUEST_PHYSICAL: - case TRFCR_EL1_TS_PHYSICAL: - break; - default: - val = -1; - break; - } + else + val = FIELD_GET(TRFCR_EL1_TS_MASK, drvdata->trfcr);
-out: return sysfs_emit(buf, "%d\n", val); } static DEVICE_ATTR_RO(ts_source);
On 21/05/2025 1:54 pm, Leo Yan wrote:
This series is minor refactoring for trace filter and comes from the previous patch set [1].
The first patch introduces a new helper has_feat_trf() for detecing if FEAT_TRF is implemented. This is more readable.
The second patch refactors the ts_source_show() function. It simplifies to directly return the TS value when FEAT_TRF is implemented.
[1] https://lore.kernel.org/linux-arm-kernel/20250519174945.2245271-1-leo.yan@ar...
Changes from v2:
- Added the has_feat_trf() helper for more readable (James Clark)
Leo Yan (2): coresight: etm4x: Introduce has_feat_trf() helper coresight: etm4x: Refactor returning TS field
drivers/hwtracing/coresight/coresight-etm4x-core.c | 8 ++++---- drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 18 +++--------------- drivers/hwtracing/coresight/coresight-etm4x.h | 9 +++++++++ 3 files changed, 16 insertions(+), 19 deletions(-)
Reviewed-by: James Clark james.clark@linaro.org