Skip to contentSkip to conversation

coresight: etm4x: Fix timestamp regression

PATCH Applied Leo Yan 3 participants 5 messages May 19, 2025 – May 20, 2025

Subsystems (2)
lore
Share & tools
lore

Leo Yan

author reviewer
#0 lore raw

v2 cover coresight: etm4x: Fix timestamp regression

The timestamp appears all zeros with latest kernel, which is caused by wrong bit field setting. The first patch fixes the regression.

The second patch refactors the ts_source_show() function. It simplifies the code for directly returning the TS value.

Changes from v1:
- Retained the older condition check (Suzuki).

Leo Yan (2):
coresight: etm4x: Fix timestamp bit field handling
coresight: etm4x: Refactor returning TS field

 drivers/hwtracing/coresight/coresight-etm4x-core.c  |  2 +-
 drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 16 ++--------------
 2 files changed, 3 insertions(+), 15 deletions(-)
Signature · 1 line
2.34.1
author reviewer
#1 lore raw

PATCH v2 1/2 coresight: etm4x: Fix timestamp bit field handling

Timestamps in the trace data appear as all zeros on recent kernels, although the feature works correctly on old kernels (e.g., v6.12).

Since commit c382ee674c8b ("arm64/sysreg/tools: Move TRFCR definitions to sysreg"), the TRFCR_ELx_TS_{VIRTUAL|GUEST_PHYSICAL|PHYSICAL} macros were updated to remove the bit shift. As a result, the driver no longer shifts bits when operates the timestamp field.

Fix this by using the FIELD_PREP() and FIELD_GET() helpers.

Fixes c382ee674c8b ("arm64/sysreg/tools: Move TRFCR definitions to sysreg")
---
 drivers/hwtracing/coresight/coresight-etm4x-core.c  | 2 +-
 drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +1 -1
index 6a5898355a83..acb4a58e4bb9 100644
@@ -1237,7 +1237,7 @@ static void cpu_detect_trace_filtering(struct etmv4_drvdata *drvdata)
 	 * tracing at the kernel EL and EL0, forcing to use the
 	 * virtual time as the timestamp.
 	 */
-	trfcr = (TRFCR_EL1_TS_VIRTUAL |
+	trfcr = (FIELD_PREP(TRFCR_EL1_TS_MASK, TRFCR_EL1_TS_VIRTUAL) |
 		 TRFCR_EL1_ExTRE |
 		 TRFCR_EL1_E0TRE);
 
drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +2 -2
index 49d5fb87a74b..ab251865b893 100644
@@ -2320,11 +2320,11 @@ static ssize_t ts_source_show(struct device *dev,
 		goto out;
 	}
 
-	switch (drvdata->trfcr & TRFCR_EL1_TS_MASK) {
+	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:
-		val = FIELD_GET(TRFCR_EL1_TS_MASK, drvdata->trfcr);
 		break;
 	default:
 		val = -1;
Signature · 1 line
2.34.1
reviewer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] coresight: etm4x: Fix timestamp bit field handling

Quoted 39 lines · Leo Yan

Timestamps in the trace data appear as all zeros on recent kernels, although the feature works correctly on old kernels (e.g., v6.12).

Since commit c382ee674c8b ("arm64/sysreg/tools: Move TRFCR definitions to sysreg"), the TRFCR_ELx_TS_{VIRTUAL|GUEST_PHYSICAL|PHYSICAL} macros were updated to remove the bit shift. As a result, the driver no longer shifts bits when operates the timestamp field.

Fix this by using the FIELD_PREP() and FIELD_GET() helpers.

Fixes c382ee674c8b ("arm64/sysreg/tools: Move TRFCR definitions to sysreg")
---
  drivers/hwtracing/coresight/coresight-etm4x-core.c  | 2 +-
  drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 4 ++--
  2 files changed, 3 insertions(+), 3 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +1 -1
index 6a5898355a83..acb4a58e4bb9 100644
@@ -1237,7 +1237,7 @@ static void cpu_detect_trace_filtering(struct etmv4_drvdata *drvdata)
  	 * tracing at the kernel EL and EL0, forcing to use the
  	 * virtual time as the timestamp.
  	 */
-	trfcr = (TRFCR_EL1_TS_VIRTUAL |
+	trfcr = (FIELD_PREP(TRFCR_EL1_TS_MASK, TRFCR_EL1_TS_VIRTUAL) |
  		 TRFCR_EL1_ExTRE |
  		 TRFCR_EL1_E0TRE);
 
drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +0 -0
index 49d5fb87a74b..ab251865b893 100644
@@ -2320,11 +2320,11 @@ static ssize_t ts_source_show(struct device *dev,
  		goto out;
  	}
 

drivers/hwtracing/coresight/coresight-etm4x-sysfs.c static ssize_t ts_source_show(struct device *dev, · line 2330

Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +2 -2
-	switch (drvdata->trfcr & TRFCR_EL1_TS_MASK) {
+	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:
-		val = FIELD_GET(TRFCR_EL1_TS_MASK, drvdata->trfcr);
  		break;
  	default:
  		val = -1;
author reviewer
#3 lore raw

PATCH v2 2/2 coresight: etm4x: Refactor returning TS field

In reply to Leo Yan

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.

---
 drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +3 -15
index ab251865b893..894393e7d90b 100644
@@ -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 (!drvdata->trfcr) {
+	if (!drvdata->trfcr)
 		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);
Signature · 1 line
2.34.1
maintainer Applied
#4 lore raw

Re: (subset) [PATCH v2 0/2] coresight: etm4x: Fix timestamp regression

In reply to Leo Yan
Quoted 10 lines · Leo Yan

The timestamp appears all zeros with latest kernel, which is caused by wrong bit field setting. The first patch fixes the regression.

The second patch refactors the ts_source_show() function. It simplifies the code for directly returning the TS value.

Changes from v1:
- Retained the older condition check (Suzuki).

[...]

Applied, thanks!

[1/2] coresight: etm4x: Fix timestamp bit field handling

      https://git.kernel.org/coresight/c/ee811bc7

Best regards,

Signature · 1 line
Suzuki K Poulose <[email protected]>