Skip to contentSkip to conversation

coresight: etm4x: Expose default timestamp source in sysfs

PATCH In review German Gomez 1 participant 3 messages May 3, 2022 – Jun 8, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 coresight: etm4x: Expose default timestamp source in sysfs

Add a new sysfs interface in /sys/bus/coresight/devices/etm<N>/ts_source indicating the configured timestamp source when the ETM device driver was probed.

The perf tool will use this information to detect if the trace data timestamp matches the kernel time, enabling correlation of CoreSight trace with perf events.

---
v1:
- https://lore.kernel.org/all/[email protected]/
v2:
- Inline etmv4_to_ts_source() function.
- Collect review tag from Leo.

---
 arch/arm64/include/asm/sysreg.h               |  1 +
 .../coresight/coresight-etm4x-sysfs.c         | 29 +++++++++++++++++++
 2 files changed, 30 insertions(+)
arch/arm64/include/asm/sysreg.h +1 -0
index 38508e507d73a..263a7bee06f9a 100644
@@ -1146,6 +1146,7 @@
 #define SYS_MPIDR_SAFE_VAL	(BIT(31))
 
 #define TRFCR_ELx_TS_SHIFT		5
+#define TRFCR_ELx_TS_MASK		((0x3UL) << TRFCR_ELx_TS_SHIFT)
 #define TRFCR_ELx_TS_VIRTUAL		((0x1UL) << TRFCR_ELx_TS_SHIFT)
 #define TRFCR_ELx_TS_GUEST_PHYSICAL	((0x2UL) << TRFCR_ELx_TS_SHIFT)
 #define TRFCR_ELx_TS_PHYSICAL		((0x3UL) << TRFCR_ELx_TS_SHIFT)
drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +29 -0
index a0640fa5c55bd..2a48827a4e135 100644
@@ -2264,6 +2264,34 @@ static ssize_t cpu_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(cpu);
 
+static ssize_t ts_source_show(struct device *dev,
+			      struct device_attribute *attr,
+			      char *buf)
+{
+	int val;
+	struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent);
+
+	if (!drvdata->trfcr) {
+		val = -1;
+		goto out;
+	}
+
+	switch (drvdata->trfcr & TRFCR_ELx_TS_MASK) {
+	case TRFCR_ELx_TS_VIRTUAL:
+	case TRFCR_ELx_TS_GUEST_PHYSICAL:
+	case TRFCR_ELx_TS_PHYSICAL:
+		val = FIELD_GET(TRFCR_ELx_TS_MASK, drvdata->trfcr);
+		break;
+	default:
+		val = -1;
+		break;
+	}
+
+out:
+	return sysfs_emit(buf, "%d\n", val);
+}
+static DEVICE_ATTR_RO(ts_source);
+
 static struct attribute *coresight_etmv4_attrs[] = {
 	&dev_attr_nr_pe_cmp.attr,
 	&dev_attr_nr_addr_cmp.attr,
@@ -2318,6 +2346,7 @@ static struct attribute *coresight_etmv4_attrs[] = {
 	&dev_attr_vmid_val.attr,
 	&dev_attr_vmid_masks.attr,
 	&dev_attr_cpu.attr,
+	&dev_attr_ts_source.attr,
 	NULL,
 };
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 2/2 coresight: etm4x: docs: Add documentation for 'ts_source' sysfs interface

Sync sysfs documentation pages to include the new ts_source (timestamp source) interface.

---
v1:
- https://lore.kernel.org/all/[email protected]/
v2:
- Update Data, KernelVersion, and Contact fields (Date is tentative but likely).

---
 .../ABI/testing/sysfs-bus-coresight-devices-etm4x  |  8 ++++++++
 .../trace/coresight/coresight-etm4x-reference.rst  | 14 ++++++++++++++
 2 files changed, 22 insertions(+)
Documentation/ABI/testing/sysfs-bus-coresight-devices-etm4x +8 -0
index 8e53a32f81505..520dd2e27eab3 100644
@@ -516,3 +516,11 @@ Contact:	Mathieu Poirier <[email protected]>
 Description:	(Read) Returns the number of special conditional P1 right-hand keys
 		that the trace unit can use (0x194).  The value is taken
 		directly from the HW.
+
+What:		/sys/bus/coresight/devices/etm<N>/ts_source
+Date:		July 2022
+KernelVersion:	5.19
+Contact:	Mathieu Poirier <[email protected]> or Suzuki K Poulose <[email protected]>
+Description:	(Read) When FEAT_TRF is implemented, value of TRFCR_ELx.TS used for
+		trace session. Otherwise -1 indicates an unknown time source. Check
+		trcidr0.tssize to see if a global timestamp is available.
Documentation/trace/coresight/coresight-etm4x-reference.rst +14 -0
index d25dfe86af9bf..f016c7c29429b 100644
@@ -71,6 +71,20 @@ the ‘TRC’ prefix.
 
 ----
 
+:File:            ``ts_source`` (ro)
+:Trace Registers: None.
+:Notes:
+    When FEAT_TRF is implemented, value of TRFCR_ELx.TS used for trace session. Otherwise -1
+    indicates an unknown time source. Check trcidr0.tssize to see if a global timestamp is
+    available.
+
+:Example:
+    ``$> cat ts_source``
+
+    ``$> 1``
+
+----
+
 :File:            ``addr_idx`` (rw)
 :Trace Registers: None.
 :Notes:
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v2 2/2] coresight: etm4x: docs: Add documentation for 'ts_source' sysfs interface

Hi,

Thanks for your comments and review in the previous submission (and sorry for not including a cover letter this time).

Do you want me to hold on this change, or update the corresponding fields with new estimates?

Thanks,
German

Quoted 56 lines · German Gomez

Sync sysfs documentation pages to include the new ts_source (timestamp source) interface.

---
v1:
- https://lore.kernel.org/all/[email protected]/
v2:
- Update Data, KernelVersion, and Contact fields (Date is tentative but likely).

---
 .../ABI/testing/sysfs-bus-coresight-devices-etm4x  |  8 ++++++++
 .../trace/coresight/coresight-etm4x-reference.rst  | 14 ++++++++++++++
 2 files changed, 22 insertions(+)
Documentation/ABI/testing/sysfs-bus-coresight-devices-etm4x +8 -0
index 8e53a32f81505..520dd2e27eab3 100644
@@ -516,3 +516,11 @@ Contact:	Mathieu Poirier <[email protected]>
 Description:	(Read) Returns the number of special conditional P1 right-hand keys
 		that the trace unit can use (0x194).  The value is taken
 		directly from the HW.
+
+What:		/sys/bus/coresight/devices/etm<N>/ts_source
+Date:		July 2022
+KernelVersion:	5.19
+Contact:	Mathieu Poirier <[email protected]> or Suzuki K Poulose <[email protected]>
+Description:	(Read) When FEAT_TRF is implemented, value of TRFCR_ELx.TS used for
+		trace session. Otherwise -1 indicates an unknown time source. Check
+		trcidr0.tssize to see if a global timestamp is available.
Documentation/trace/coresight/coresight-etm4x-reference.rst +14 -0
index d25dfe86af9bf..f016c7c29429b 100644
@@ -71,6 +71,20 @@ the ‘TRC’ prefix.
 
 ----
 
+:File:            ``ts_source`` (ro)
+:Trace Registers: None.
+:Notes:
+    When FEAT_TRF is implemented, value of TRFCR_ELx.TS used for trace session. Otherwise -1
+    indicates an unknown time source. Check trcidr0.tssize to see if a global timestamp is
+    available.
+
+:Example:
+    ``$> cat ts_source``
+
+    ``$> 1``
+
+----
+
 :File:            ``addr_idx`` (rw)
 :Trace Registers: None.
 :Notes: