Skip to contentSkip to conversation

coresight: Pulse an ETM external output for a PMU event

PATCH Superseded Amir Ayupov 2 participants 15 messages Nov 20

Subsystems (5)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover coresight: Pulse an ETM external output for a PMU event

Add an ETMv4 configuration, pmu_pulse, that drives trace unit external output 1 on every traced cycle, so a PMU event counting it (TRCEXTOUT1) can end a fixed-length ETM window, for example with aux-action=pause. The feature only loads on an ETE whose PMU counts its external outputs.

Output 1 is fixed by the configuration; the perf command selects the matching TRCEXTOUT1 consumer separately. Output 0 is avoided because it is the trace trigger, and a detected trigger stops TRBE capture. Each window includes the counted trace cycles plus pause interrupt latency.

Patch 1 is Leo's fix for TRCIDR0.NUMEVENT decoding, which patch 6 relies on for the number of external outputs. An ARM PMU maintainer Ack is requested on patch 5 so the series can be taken through the CoreSight tree.

Changes in v5:
- Compare the class and capability fields with FIELD_GET() (Suzuki). The class check stays an intersection: built-in features name a single class, while ETMv4 devices register with both SRC_ALL and SRC_ETM4.
- Move both ARMV8_PMUV3_MAX_COMMON_EVENTS and ARMV8_PMUV3_EXT_COMMON_EVENT_BASE to linux/perf/arm_pmuv3.h and include it from linux/perf/arm_pmu.h (Suzuki, James). Add Will and Mark for an Ack on that patch.
- Rename the capability to CS_CFG_MATCH_CAP_ETE_TRCEXTOUT, as it only applies to ETE (Suzuki).
- Drop caps.trcextout and pass the probe-time result to etm4_cscfg_register() instead (Suzuki). The check reads PMCEID on the trace unit's CPU, so it stays in etm4_init_arch_data(), which runs there, while etm4_cscfg_register() may run on any CPU.
- Add James's Reviewed-by to all but patch 2, and Leo's Tested-by to all.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Fix the arm64 build: v3 defined pmuv3_event_implemented() in linux/perf/arm_pmuv3.h after including asm/arm_pmuv3.h, which broke files that include asm/arm_pmuv3.h directly, such as arch/arm64/kernel/cpufeature.c. Move it to the arm64 asm/arm_pmuv3.h, after the helpers it uses.
Breakage reported by kernel test robot.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Rebase onto coresight next, which moves the capability fields into drvdata->caps (Leo).
- Carry Leo's "coresight: etm4x: Fix event count decoding" (Leo).
- Add Leo's Reviewed-by to "Fail to enable a configuration not loaded on the device".
- Define CS_CFG_MATCH_CLASS_MASK and CS_CFG_MATCH_CAP_MASK with GENMASK_U32() and split the match check into early returns (Leo). The class check stays an intersection, as ETMv4 devices register with SRC_ALL | SRC_ETM4 while the built-in features only set SRC_ETM4.
- Remove the unused CS_CFG_MATCH_INST_ANY in a separate patch (Leo).
- Replace the per-output CS_CFG_MATCH_CAP_PMU_EXTOUT(n) bits with a single CS_CFG_MATCH_CAP_TRCEXTOUT, set on ETE only (Leo, James).
- Check the PMU events through a new pmuv3_event_implemented() helper instead of open-coding PMCEID0_EL0 in etm4x (James).
- Use PMU-agnostic event names in the documentation example (Daniel).
- Add Daniel's Reviewed-by to "Add pmu_pulse/extout_pulse".
- Link to v2: https://lore.kernel.org/r/[email protected]

Amir Ayupov (6):
coresight: syscfg: Fail to enable a configuration not loaded on the
device
coresight: syscfg: Match feature capabilities separately from device
class
coresight: syscfg: Remove unused CS_CFG_MATCH_INST_ANY
perf: arm_pmuv3: Add pmuv3_event_implemented()
coresight: etm4x: Report whether the PMU counts the external outputs
coresight: Add pmu_pulse/extout_pulse

Leo Yan (1):
coresight: etm4x: Fix event count decoding

 .../trace/coresight/coresight-config.rst      |  5 +
 .../trace/coresight/coresight-perf.rst        | 15 +++
 arch/arm64/include/asm/arm_pmuv3.h            | 20 ++++
 drivers/hwtracing/coresight/Makefile          |  1 +
 .../coresight/coresight-cfg-pmu-pulse.c       | 55 +++++++++++
 .../coresight/coresight-cfg-preload.c         |  2 +
 .../coresight/coresight-cfg-preload.h         |  2 +
 .../hwtracing/coresight/coresight-config.h    | 11 ++-
 .../hwtracing/coresight/coresight-etm4x-cfg.c |  7 +-
 .../hwtracing/coresight/coresight-etm4x-cfg.h |  2 +-
 .../coresight/coresight-etm4x-core.c          | 42 ++++++++-
 .../coresight/coresight-etm4x-sysfs.c         | 29 +++---
 .../coresight/coresight-syscfg-configfs.c     |  3 +
 .../hwtracing/coresight/coresight-syscfg.c    | 93 ++++++++++++-------
 include/linux/perf/arm_pmu.h                  |  3 +-
 include/linux/perf/arm_pmuv3.h                |  8 ++
 16 files changed, 239 insertions(+), 59 deletions(-)
 create mode 100644 drivers/hwtracing/coresight/coresight-cfg-pmu-pulse.c

base-commit: 343cfcbb3ecfdb80aa576a428cfa3b65ad783842

Signature · 1 line
2.52.1
#1 lore raw

PATCH v5 1/7 coresight: etm4x: Fix event count decoding

From: Leo Yan <[email protected]>

TRCIDR0.NUMEVENT normally encodes the number of events minus one. From ETMv4.3 onwards, including ETE, a zero TRCIDR4.NUMRSPAIR instead means that no events are implemented and NUMEVENT is zero. The sysfs event controls currently interpret this combination as one event and allow writes to unsupported event fields.

Decode NUMEVENT after NUMRSPAIR and store the actual number of events in nr_event. Use the decoded resource count so that older ETM versions, where a zero NUMRSPAIR represents one resource pair, still report at least one event. Update both sysfs event controls to use the actual count and clear their event fields when no events are implemented.

Also correct the instruction event enable mask for the single-event case to use INSTEN[0]. The existing mask uses INSTEN[1], preventing event 0 from being enabled.

This change depends on the recent driver refactoring. With no reported failures, it is not intended for stable backporting.

---
 .../coresight/coresight-etm4x-core.c          | 13 +++++++--
 .../coresight/coresight-etm4x-sysfs.c         | 29 ++++++++++---------
 2 files changed, 27 insertions(+), 15 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +11 -2
index e21be6468e9544..af017bd8a54773 100644
@@ -1451,8 +1451,6 @@ static void etm4_init_arch_data(void *info)
 	caps->trccci = !!(etmidr0 & TRCIDR0_TRCCCI);
 	/* RETSTACK, bit[9] Return stack bit */
 	caps->retstack = !!(etmidr0 & TRCIDR0_RETSTACK);
-	/* NUMEVENT, bits[11:10] Number of events field */
-	caps->nr_event = FIELD_GET(TRCIDR0_NUMEVENT_MASK, etmidr0);
 	/* QSUPP, bits[16:15] Q element support field */
 	caps->q_support = FIELD_GET(TRCIDR0_QSUPP_MASK, etmidr0);
 	if (caps->q_support)
@@ -1519,6 +1517,17 @@ static void etm4_init_arch_data(void *info)
 	caps->nr_resource = FIELD_GET(TRCIDR4_NUMRSPAIR_MASK, etmidr4);
 	if ((drvdata->arch < ETM_ARCH_V4_3) || (caps->nr_resource > 0))
 		caps->nr_resource += 1;
+
+	/*
+	 * NUMEVENT encodes the number of events minus one. From ETMv4.3,
+	 * including ETE, NUMRSPAIR == 0 means no events are implemented.
+	 * nr_resource already accounts for the pre-ETMv4.3 encoding.
+	 */
+	if (caps->nr_resource)
+		caps->nr_event = FIELD_GET(TRCIDR0_NUMEVENT_MASK, etmidr0) + 1;
+	else
+		caps->nr_event = 0;
+
 	/*
 	 * NUMSSCC, bits[23:20] the number of single-shot
 	 * comparator control for tracing. Read any status regs as these
drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +16 -13
index db9e603f97ba82..fb38f0102290a5 100644
@@ -513,19 +513,22 @@ static ssize_t event_store(struct device *dev,
 
 	raw_spin_lock(&drvdata->spinlock);
 	switch (caps->nr_event) {
-	case 0x0:
+	case 0:
+		sysfs_config->eventctrl0 = 0;
+		break;
+	case 1:
 		/* EVENT0, bits[7:0] */
 		sysfs_config->eventctrl0 = val & 0xFF;
 		break;
-	case 0x1:
-		 /* EVENT1, bits[15:8] */
+	case 2:
+		/* EVENT1, bits[15:8] */
 		sysfs_config->eventctrl0 = val & 0xFFFF;
 		break;
-	case 0x2:
+	case 3:
 		/* EVENT2, bits[23:16] */
 		sysfs_config->eventctrl0 = val & 0xFFFFFF;
 		break;
-	case 0x3:
+	case 4:
 		/* EVENT3, bits[31:24] */
 		sysfs_config->eventctrl0 = val;
 		break;
@@ -565,22 +568,22 @@ static ssize_t event_instren_store(struct device *dev,
 	/* start by clearing all instruction event enable bits */
 	sysfs_config->eventctrl1 &= ~TRCEVENTCTL1R_INSTEN_MASK;
 	switch (caps->nr_event) {
-	case 0x0:
-		/* generate Event element for event 1 */
-		sysfs_config->eventctrl1 |= val & TRCEVENTCTL1R_INSTEN_1;
+	case 1:
+		/* generate Event element for event 0 */
+		sysfs_config->eventctrl1 |= val & TRCEVENTCTL1R_INSTEN_0;
 		break;
-	case 0x1:
-		/* generate Event element for event 1 and 2 */
+	case 2:
+		/* generate Event element for events 0 and 1 */
 		sysfs_config->eventctrl1 |= val & (TRCEVENTCTL1R_INSTEN_0 |
 						   TRCEVENTCTL1R_INSTEN_1);
 		break;
-	case 0x2:
-		/* generate Event element for event 1, 2 and 3 */
+	case 3:
+		/* generate Event element for events 0, 1 and 2 */
 		sysfs_config->eventctrl1 |= val & (TRCEVENTCTL1R_INSTEN_0 |
 					     TRCEVENTCTL1R_INSTEN_1 |
 					     TRCEVENTCTL1R_INSTEN_2);
 		break;
-	case 0x3:
+	case 4:
 		/* generate Event element for all 4 events */
 		sysfs_config->eventctrl1 |= val & (TRCEVENTCTL1R_INSTEN_0 |
 					     TRCEVENTCTL1R_INSTEN_1 |
Signature · 1 line
2.52.1
#2 lore raw

Re: [PATCH v5 1/7] coresight: etm4x: Fix event count decoding

Sashiko has reviewed this patch and found no issues.
Quoted 18 lines

From: Leo Yan <[email protected]>

TRCIDR0.NUMEVENT normally encodes the number of events minus one. From ETMv4.3 onwards, including ETE, a zero TRCIDR4.NUMRSPAIR instead means that no events are implemented and NUMEVENT is zero. The sysfs event controls currently interpret this combination as one event and allow writes to unsupported event fields.

Decode NUMEVENT after NUMRSPAIR and store the actual number of events in nr_event. Use the decoded resource count so that older ETM versions, where a zero NUMRSPAIR represents one resource pair, still report at least one event. Update both sysfs event controls to use the actual count and clear their event fields when no events are implemented.

Also correct the instruction event enable mask for the single-event case to use INSTEN[0]. The existing mask uses INSTEN[1], preventing event 0 from being enabled.

Quoted 7 lines

This change depends on the recent driver refactoring. With no reported failures, it is not intended for stable backporting.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH v5 2/7 coresight: syscfg: Fail to enable a configuration not loaded on the device

In reply to Amir Ayupov

cscfg_csdev_enable_active_config() looks up the selected configuration in the device's loaded configurations, and returns success when it is not there. A configuration is only loaded on devices that match at least one of its features, so a perf session or sysfs enable that selects it on any other device runs without the configuration, with no error.

Return -EINVAL instead, so enabling the source fails on that device. The function is only called with a non-zero configuration hash, so sources enabled without a configuration are unaffected.

Fixes f8cce2ff3c04 ("coresight: syscfg: Add API to activate and enable configurations")
Assisted-by Devmate:Opus-5.5
---
 .../hwtracing/coresight/coresight-syscfg.c    | 53 ++++++++++---------
 1 file changed, 28 insertions(+), 25 deletions(-)
drivers/hwtracing/coresight/coresight-syscfg.c +28 -25
index 2bfdd7b45e49c8..a816c22c87bc87 100644
@@ -1088,36 +1088,39 @@ int cscfg_csdev_enable_active_config(struct coresight_device *csdev,
 	raw_spin_unlock_irqrestore(&csdev->cscfg_csdev_lock, flags);
 
 	/*
-	 * If found, attempt to enable
+	 * The configuration is active but not loaded on this device, because
+	 * none of its features match the device. Fail rather than trace
+	 * without it.
 	 */
-	if (config_csdev_active) {
+	if (!config_csdev_active)
+		return -EINVAL;
+
+	/*
+	 * Call the generic routine that will program up the internal
+	 * driver structures prior to programming up the hardware.
+	 * This routine takes the driver spinlock saved in the configs.
+	 */
+	err = cscfg_csdev_enable_config(config_csdev_active, preset);
+	if (!err) {
 		/*
-		 * Call the generic routine that will program up the internal
-		 * driver structures prior to programming up the hardware.
-		 * This routine takes the driver spinlock saved in the configs.
+		 * Successful programming. Check the active_cscfg_ctxt
+		 * pointer to ensure no pre-emption disabled it via
+		 * cscfg_csdev_disable_active_config() before
+		 * we could start.
+		 *
+		 * Set enabled if OK, err if not.
 		 */
-		err = cscfg_csdev_enable_config(config_csdev_active, preset);
-		if (!err) {
-			/*
-			 * Successful programming. Check the active_cscfg_ctxt
-			 * pointer to ensure no pre-emption disabled it via
-			 * cscfg_csdev_disable_active_config() before
-			 * we could start.
-			 *
-			 * Set enabled if OK, err if not.
-			 */
-			raw_spin_lock_irqsave(&csdev->cscfg_csdev_lock, flags);
-			if (csdev->active_cscfg_ctxt)
-				config_csdev_active->enabled = true;
-			else
-				err = -EBUSY;
-			raw_spin_unlock_irqrestore(&csdev->cscfg_csdev_lock, flags);
-		}
-
-		if (err)
-			cscfg_config_desc_put(config_desc);
+		raw_spin_lock_irqsave(&csdev->cscfg_csdev_lock, flags);
+		if (csdev->active_cscfg_ctxt)
+			config_csdev_active->enabled = true;
+		else
+			err = -EBUSY;
+		raw_spin_unlock_irqrestore(&csdev->cscfg_csdev_lock, flags);
 	}
 
+	if (err)
+		cscfg_config_desc_put(config_desc);
+
 	return err;
 }
 EXPORT_SYMBOL_GPL(cscfg_csdev_enable_active_config);
Signature · 1 line
2.52.1
#4 lore raw

Re: [PATCH v5 2/7] coresight: syscfg: Fail to enable a configuration not loaded on the device

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] coresight: syscfg: cscfg_csdev_enable_active_config() rejects unmatched csdev --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] coresight: syscfg: cscfg_csdev_enable_active_config() rejects unmatched csdev
--

commit 963b92e15bb563c4e0e56506b797ad0f0117ff05
Author: Amir Ayupov <[email protected]>

coresight: syscfg: Fail to enable a configuration not loaded on the device

This commit makes cscfg_csdev_enable_active_config() return -EINVAL when the active configuration is not loaded on the target CoreSight device.

Quoted 6 lines
drivers/hwtracing/coresight/coresight-syscfg.c +0 -0
index 2bfdd7b45e49c..a816c22c87bc8 100644
@@ -1088,36 +1088,39 @@ int cscfg_csdev_enable_active_config(struct coresight_device *csdev,
 	raw_spin_unlock_irqrestore(&csdev->cscfg_csdev_lock, flags);

drivers/hwtracing/coresight/coresight-syscfg.c int cscfg_csdev_enable_active_config(struct coresight_device *csdev, · line 1096

Quoted 10 lines
drivers/hwtracing/coresight/coresight-syscfg.c +5 -2
 
 	/*
-	 * If found, attempt to enable
+	 * The configuration is active but not loaded on this device, because
+	 * none of its features match the device. Fail rather than trace
+	 * without it.
 	 */
-	if (config_csdev_active) {
+	if (!config_csdev_active)
+		return -EINVAL;

[Severity: High]
As reported by Mike Leach on v2 [1], should cscfg_csdev_enable_active_config() fail when a configuration is not loaded on csdev?

cscfg_csdev_enable_active_config() is a generic helper across CoreSight device classes, and its kernel-doc states that it enables the configuration only if supported on the device:

drivers/hwtracing/coresight/coresight-syscfg.c:
/**
* cscfg_csdev_enable_active_config - Enable matching active configuration for device. *
* Enables the configuration selected by @cfg_hash if the configuration is supported
* on the device and has been activated.

For perf sessions, etm_setup_aux() activates cfg_hash globally and builds paths for every CPU in event_data->mask without filtering out ETM sources that do not have the configuration loaded. Returning -EINVAL here causes etm_setup_aux() to succeed even if some or all CPUs lack the configuration, only for etm_event_start() -> coresight_enable_source() -> etm4_enable_perf() to fail at schedule-in time and stop the event with PERF_HES_STOPPED.

Incompatible ETM sources should instead be filtered out of event_data->mask during etm_setup_aux().

[1] https://lore.kernel.org/r/DB9PR08MB64756F200065042673030C848C722@DB9PR08MB6475.eurprd08.prod.outlook.com

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

PATCH v5 3/7 coresight: syscfg: Match feature capabilities separately from device class

In reply to Amir Ayupov

A feature loads on a device when the two share any match flag. That works for device classes, where a feature wants any one of them, but not for capabilities a device may or may not have: a feature that sets a class and a capability would still load on a device of that class without the capability.

Split the match flags into CS_CFG_MATCH_CLASS_MASK for device classes and CS_CFG_MATCH_CAP_MASK for capabilities. A feature now loads on a device that shares one of its classes and has all of its capabilities. Check this once in cscfg_load_feat_csdev(), which both the feature and the device registration paths call. No capability flags are defined yet, so matching is unchanged.

Assisted-by Devmate:Opus-5.5
---
 .../hwtracing/coresight/coresight-config.h    |  8 ++++
 .../hwtracing/coresight/coresight-syscfg.c    | 40 ++++++++++++++-----
 2 files changed, 37 insertions(+), 11 deletions(-)
drivers/hwtracing/coresight/coresight-config.h +8 -0
index ae6295e3081319..f04e73b91d9a63 100644
@@ -7,6 +7,7 @@
 #ifndef _CORESIGHT_CORESIGHT_CONFIG_H
 #define _CORESIGHT_CORESIGHT_CONFIG_H
 
+#include <linux/bits.h>
 #include <linux/cleanup.h>
 #include <linux/coresight.h>
 #include <linux/types.h>
@@ -30,6 +31,13 @@
  */
 #define CS_CFG_MATCH_CLASS_SRC_ALL	0x0001	/* match any source */
 #define CS_CFG_MATCH_CLASS_SRC_ETM4	0x0002	/* match any ETMv4 device */
+#define CS_CFG_MATCH_CLASS_MASK		GENMASK_U32(7, 0)
+
+/*
+ * flags defining device capabilities a feature can require. A feature loads on
+ * a device that matches one of its classes and has all of its capabilities.
+ */
+#define CS_CFG_MATCH_CAP_MASK		GENMASK_U32(15, 8)
 
 /* flags defining device instance matching - used in config match desc data. */
 #define CS_CFG_MATCH_INST_ANY		0x80000000 /* any instance of a class */
drivers/hwtracing/coresight/coresight-syscfg.c +29 -11
index a816c22c87bc87..65116b09cbc96c 100644
@@ -4,6 +4,7 @@
  * Author: Mike Leach <[email protected]>
  */
 
+#include <linux/bitfield.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
@@ -171,8 +172,24 @@ cscfg_alloc_csdev_feat(struct coresight_device *csdev, struct cscfg_feature_desc
 	return feat_csdev;
 }
 
-/* load one feature into one coresight device */
+static bool cscfg_match_feat_csdev(u32 feat_flags, u32 csdev_flags)
+{
+	/* The device must be in one of the feature's classes */
+	if (!(FIELD_GET(CS_CFG_MATCH_CLASS_MASK, feat_flags) &
+	      FIELD_GET(CS_CFG_MATCH_CLASS_MASK, csdev_flags)))
+		return false;
+
+	/* The device must have every capability the feature requires */
+	if (FIELD_GET(CS_CFG_MATCH_CAP_MASK, feat_flags) &
+	    ~FIELD_GET(CS_CFG_MATCH_CAP_MASK, csdev_flags))
+		return false;
+
+	return true;
+}
+
+/* Load the feature into the device if it matches, otherwise skip it. */
 static int cscfg_load_feat_csdev(struct coresight_device *csdev,
+				 u32 match_flags,
 				 struct cscfg_feature_desc *feat_desc,
 				 struct cscfg_csdev_feat_ops *ops)
 {
@@ -183,6 +200,9 @@ static int cscfg_load_feat_csdev(struct coresight_device *csdev,
 	if (!ops->load_feat)
 		return -EINVAL;
 
+	if (!cscfg_match_feat_csdev(feat_desc->match_flags, match_flags))
+		return 0;
+
 	feat_csdev = cscfg_alloc_csdev_feat(csdev, feat_desc);
 	if (!feat_csdev)
 		return -ENOMEM;
@@ -212,11 +232,11 @@ static int cscfg_add_feat_to_csdevs(struct cscfg_feature_desc *feat_desc)
 	int err;
 
 	list_for_each_entry(csdev_item, &cscfg_mgr->csdev_desc_list, item) {
-		if (csdev_item->match_flags & feat_desc->match_flags) {
-			err = cscfg_load_feat_csdev(csdev_item->csdev, feat_desc, &csdev_item->ops);
-			if (err)
-				return err;
-		}
+		err = cscfg_load_feat_csdev(csdev_item->csdev,
+					    csdev_item->match_flags, feat_desc,
+					    &csdev_item->ops);
+		if (err)
+			return err;
 	}
 	return 0;
 }
@@ -739,11 +759,9 @@ static int cscfg_add_feats_csdev(struct coresight_device *csdev,
 		return -EINVAL;
 
 	list_for_each_entry(feat_desc, &cscfg_mgr->feat_desc_list, item) {
-		if (feat_desc->match_flags & match_flags) {
-			err = cscfg_load_feat_csdev(csdev, feat_desc, ops);
-			if (err)
-				break;
-		}
+		err = cscfg_load_feat_csdev(csdev, match_flags, feat_desc, ops);
+		if (err)
+			break;
 	}
 	return err;
 }
Signature · 1 line
2.52.1
#6 lore raw

Re: [PATCH v5 3/7] coresight: syscfg: Match feature capabilities separately from device class

Sashiko has reviewed this patch and found no issues.
Quoted 13 lines

A feature loads on a device when the two share any match flag. That works for device classes, where a feature wants any one of them, but not for capabilities a device may or may not have: a feature that sets a class and a capability would still load on a device of that class without the capability.

Split the match flags into CS_CFG_MATCH_CLASS_MASK for device classes and CS_CFG_MATCH_CAP_MASK for capabilities. A feature now loads on a device that shares one of its classes and has all of its capabilities. Check this once in cscfg_load_feat_csdev(), which both the feature and the device registration paths call. No capability flags are defined yet, so matching is unchanged.

Quoted 4 lines
Assisted-by Devmate:Opus-5.5

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

PATCH v5 4/7 coresight: syscfg: Remove unused CS_CFG_MATCH_INST_ANY

In reply to Amir Ayupov

CS_CFG_MATCH_INST_ANY has been defined since the system configuration was introduced but is not used by any configuration, feature or device. Remove it.

---
 drivers/hwtracing/coresight/coresight-config.h | 3 ---
 1 file changed, 3 deletions(-)
drivers/hwtracing/coresight/coresight-config.h +0 -3
index f04e73b91d9a63..220bc54f8e5e1b 100644
@@ -39,9 +39,6 @@
  */
 #define CS_CFG_MATCH_CAP_MASK		GENMASK_U32(15, 8)
 
-/* flags defining device instance matching - used in config match desc data. */
-#define CS_CFG_MATCH_INST_ANY		0x80000000 /* any instance of a class */
-
 /*
  * Limit number of presets in a configuration
  * This is related to the number of bits (4) we use to select the preset on
Signature · 1 line
2.52.1
#8 lore raw

Re: [PATCH v5 4/7] coresight: syscfg: Remove unused CS_CFG_MATCH_INST_ANY

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

CS_CFG_MATCH_INST_ANY has been defined since the system configuration was introduced but is not used by any configuration, feature or device. Remove it.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#9 lore raw

PATCH v5 5/7 perf: arm_pmuv3: Add pmuv3_event_implemented()

In reply to Amir Ayupov

Drivers outside the PMU driver may need to know whether the local CPU's PMU implements a common event before relying on it, for example a trace unit driver checking that the PMU counts its external outputs as TRCEXTOUTn.

Add pmuv3_event_implemented() to the arm64 asm/arm_pmuv3.h, next to read_pmceid0() and read_pmceid1(). It reads PMCEID0/1 on the calling CPU:
the first ARMV8_PMUV3_MAX_COMMON_EVENTS events are reported in bits [31:0], and as many from ARMV8_PMUV3_EXT_COMMON_EVENT_BASE in bits [63:32] from PMUv3p1.

Move ARMV8_PMUV3_MAX_COMMON_EVENTS and ARMV8_PMUV3_EXT_COMMON_EVENT_BASE next to the event numbers in linux/perf/arm_pmuv3.h, so that both are available without CONFIG_ARM_PMU, and include it from linux/perf/arm_pmu.h, which sizes the PMCEID bitmaps with the former.

---
Will, Mark: could you Ack this so Suzuki can take it through the CoreSight tree with the rest of the series?

 arch/arm64/include/asm/arm_pmuv3.h | 20 ++++++++++++++++++++
 include/linux/perf/arm_pmu.h       |  3 +--
 include/linux/perf/arm_pmuv3.h     |  8 ++++++++
 3 files changed, 29 insertions(+), 2 deletions(-)
arch/arm64/include/asm/arm_pmuv3.h +20 -0
index 8a777dec8d88ab..f6882771ec7970 100644
@@ -173,6 +173,26 @@ static inline bool pmuv3_implemented(int pmuver)
 		 pmuver == ID_AA64DFR0_EL1_PMUVer_NI);
 }
 
+/*
+ * Whether this CPU's PMU implements a common event, as reported by
+ * PMCEID{0,1}: events 0x0000-0x003f in bits [31:0], and from PMUv3p1 events
+ * 0x4000-0x403f in bits [63:32], which read as zero before PMUv3p1.
+ * Must run on the CPU whose PMU is queried.
+ */
+static inline bool pmuv3_event_implemented(u16 event)
+{
+	bool ext = event >= ARMV8_PMUV3_EXT_COMMON_EVENT_BASE;
+	u16 id = ext ? event - ARMV8_PMUV3_EXT_COMMON_EVENT_BASE : event;
+	u64 pmceid;
+
+	if (id >= ARMV8_PMUV3_MAX_COMMON_EVENTS ||
+	    !pmuv3_implemented(read_pmuver()))
+		return false;
+
+	pmceid = id < 32 ? read_pmceid0() : read_pmceid1();
+	return pmceid & BIT_ULL(id % 32 + (ext ? 32 : 0));
+}
+
 static inline bool is_pmuv3p4(int pmuver)
 {
 	return pmuver >= ID_AA64DFR0_EL1_PMUVer_V3P4;
include/linux/perf/arm_pmu.h +1 -2
index 02d2c7f45b527d..a90867c9774c74 100644
@@ -10,6 +10,7 @@
 
 #include <linux/interrupt.h>
 #include <linux/perf_event.h>
+#include <linux/perf/arm_pmuv3.h>
 #include <linux/platform_device.h>
 #include <linux/sysfs.h>
 #include <asm/cputype.h>
@@ -122,9 +123,7 @@ struct arm_pmu {
 	bool		avoid_pmccntr;
 	u64		reg_pmmir;
 	u64		reg_brbidr;
-#define ARMV8_PMUV3_MAX_COMMON_EVENTS		0x40
 	DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
-#define ARMV8_PMUV3_EXT_COMMON_EVENT_BASE	0x4000
 	DECLARE_BITMAP(pmceid_ext_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
 
 	/* Only to be used by ACPI probing code */
include/linux/perf/arm_pmuv3.h +8 -0
index d698efba28a276..5bab0f952fd59c 100644
@@ -78,6 +78,14 @@
 #define ARMV8_PMUV3_PERFCTR_STALL_SLOT_FRONTEND			0x003E
 #define ARMV8_PMUV3_PERFCTR_STALL_SLOT				0x003F
 
+/*
+ * PMCEID{0,1} report ARMV8_PMUV3_MAX_COMMON_EVENTS common events from 0 in
+ * bits [31:0], and as many from ARMV8_PMUV3_EXT_COMMON_EVENT_BASE in bits
+ * [63:32] from PMUv3p1.
+ */
+#define ARMV8_PMUV3_MAX_COMMON_EVENTS				0x40
+#define ARMV8_PMUV3_EXT_COMMON_EVENT_BASE			0x4000
+
 /* Statistical profiling extension microarchitectural events */
 #define ARMV8_SPE_PERFCTR_SAMPLE_POP				0x4000
 #define ARMV8_SPE_PERFCTR_SAMPLE_FEED				0x4001
Signature · 1 line
2.52.1
#10 lore raw

Re: [PATCH v5 5/7] perf: arm_pmuv3: Add pmuv3_event_implemented()

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] perf: arm_pmu: build failure on 32-bit ARM without CONFIG_CPU_CP15 --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] perf: arm_pmu: build failure on 32-bit ARM without CONFIG_CPU_CP15
--

commit 35316b1d7277cb0d1201241837c2de25d95ad9c1
Author: Amir Ayupov <[email protected]>

perf: arm_pmuv3: Add pmuv3_event_implemented()

This commit adds pmuv3_event_implemented() to arch/arm64/include/asm/arm_pmuv3.h to query whether the local CPU's PMU implements a common event via PMCEID0/1, and moves ARMV8_PMUV3_MAX_COMMON_EVENTS and ARMV8_PMUV3_EXT_COMMON_EVENT_BASE from include/linux/perf/arm_pmu.h to include/linux/perf/arm_pmuv3.h.

include/linux/perf/arm_pmu.h line 16

Quoted 12 lines
include/linux/perf/arm_pmu.h +1 -0
index 02d2c7f45b527..a90867c9774c7 100644
@@ -10,6 +10,7 @@
 
 #include <linux/interrupt.h>
 #include <linux/perf_event.h>
+#include <linux/perf/arm_pmuv3.h>
 #include <linux/platform_device.h>
 #include <linux/sysfs.h>
 #include <asm/cputype.h>

[Severity: Medium]
Does unconditionally including linux/perf/arm_pmuv3.h here break 32-bit ARM builds when CONFIG_CPU_CP15 is disabled (for example on CONFIG_CPU_V7M) and CONFIG_ARM_PMU is enabled?

linux/perf/arm_pmuv3.h includes asm/arm_pmuv3.h, and on 32-bit ARM the static inline helpers in arch/arm/include/asm/arm_pmuv3.h expand read_sysreg(), write_sysreg(), __ACCESS_CP15(), and __ACCESS_CP15_64():

arch/arm/include/asm/arm_pmuv3.h:read_pmevcntrn() {
    ...
#define RETURN_READ_PMEVCNTRN(n) \
	return read_sysreg(PMEVCNTR##n)
static inline unsigned long read_pmevcntrn(int n)
{
	PMEVN_SWITCH(n, RETURN_READ_PMEVCNTRN);
	return 0;
}
    ...
}

In arch/arm/include/asm/cp15.h and arch/arm/include/asm/vdso/cp15.h, those macros are defined only under #ifdef CONFIG_CPU_CP15. Previously linux/perf/arm_pmuv3.h was only compiled on 32-bit ARM under CONFIG_ARM_PMUV3 (which depends on CPU_V7 and thus CPU_CP15), whereas CONFIG_ARM_PMU depends only on ARM || ARM64, so compiling drivers/perf/arm_pmu.c without CONFIG_CPU_CP15 fails with undeclared CP15 macros and helpers.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#11 lore raw

PATCH v5 6/7 coresight: etm4x: Report whether the PMU counts the external outputs

In reply to Amir Ayupov

Some CPUs count the trace unit's external outputs as the PMU common events TRCEXTOUT0-3 (0x4010-0x4013), which lets a configuration drive a PMU event from trace unit events. Other CPUs, Neoverse N1 for example, have no such events, and a feature relying on them would silently do nothing there.

Detect at probe, on the trace unit's CPU, whether the PMU counts every external output: the trace unit has an external output for each of its events (caps.nr_event), and pmuv3_event_implemented() reports whether the PMU implements TRCEXTOUTn. Only check ETE: per its specification, an implemented TRCEXTOUTn event counts external output n, while whether that output is also an external input is IMPLEMENTATION DEFINED.

Add a CS_CFG_MATCH_CAP_ETE_TRCEXTOUT capability match flag, set it on those trace units when registering them with the configuration manager, and show it in the feature's configfs 'matches' attribute. With capabilities matched separately from the device class, a feature that requires it only loads on those trace units.

Assisted-by Devmate:Opus-5.5
---
 .../hwtracing/coresight/coresight-config.h    |  2 ++
 .../hwtracing/coresight/coresight-etm4x-cfg.c |  7 +++--
 .../hwtracing/coresight/coresight-etm4x-cfg.h |  2 +-
 .../coresight/coresight-etm4x-core.c          | 29 ++++++++++++++++++-
 .../coresight/coresight-syscfg-configfs.c     |  3 ++
 5 files changed, 39 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-config.h +2 -0
index 220bc54f8e5e1b..e18143fca90f85 100644
@@ -38,6 +38,8 @@
  * a device that matches one of its classes and has all of its capabilities.
  */
 #define CS_CFG_MATCH_CAP_MASK		GENMASK_U32(15, 8)
+/* an ETE whose PMU counts its external outputs as TRCEXTOUTn */
+#define CS_CFG_MATCH_CAP_ETE_TRCEXTOUT	BIT(8)
 
 /*
  * Limit number of presets in a configuration
drivers/hwtracing/coresight/coresight-etm4x-cfg.c +5 -2
index 52cb036bb04b96..fea003e49c262a 100644
@@ -174,11 +174,14 @@ static int etm4_cfg_load_feature(struct coresight_device *csdev,
 #define CS_CFG_ETM4_MATCH_FLAGS	(CS_CFG_MATCH_CLASS_SRC_ALL | \
 				 CS_CFG_MATCH_CLASS_SRC_ETM4)
 
-int etm4_cscfg_register(struct coresight_device *csdev)
+int etm4_cscfg_register(struct coresight_device *csdev, bool ete_trcextout)
 {
 	struct cscfg_csdev_feat_ops ops;
+	u32 match_flags = CS_CFG_ETM4_MATCH_FLAGS;
 
 	ops.load_feat = &etm4_cfg_load_feature;
+	if (ete_trcextout)
+		match_flags |= CS_CFG_MATCH_CAP_ETE_TRCEXTOUT;
 
-	return cscfg_register_csdev(csdev, CS_CFG_ETM4_MATCH_FLAGS, &ops);
+	return cscfg_register_csdev(csdev, match_flags, &ops);
 }
drivers/hwtracing/coresight/coresight-etm4x-cfg.h +1 -1
index 32dab34c1dace0..d87bcc83e12491 100644
@@ -25,6 +25,6 @@
 #define ETM4_CFG_RES_MASK	0x00F
 
 /* ETMv4 specific config functions */
-int etm4_cscfg_register(struct coresight_device *csdev);
+int etm4_cscfg_register(struct coresight_device *csdev, bool ete_trcextout);
 
 #endif /* CORESIGHT_ETM4X_CFG_H */
drivers/hwtracing/coresight/coresight-etm4x-core.c +28 -1
index af017bd8a54773..ecf2a6c945cf05 100644
@@ -30,6 +30,7 @@
 #include <linux/uaccess.h>
 #include <linux/perf_event.h>
 #include <linux/perf/arm_pmu.h>
+#include <linux/perf/arm_pmuv3.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/property.h>
@@ -78,6 +79,7 @@ static enum cpuhp_state hp_online;
 struct etm4_init_arg {
 	struct device		*dev;
 	struct csdev_access	*csa;
+	bool			ete_trcextout;
 };
 
 static DEFINE_PER_CPU(struct etm4_init_arg *, delayed_probe);
@@ -1399,6 +1401,29 @@ static void etm4_fixup_wrong_ccitmin(struct etmv4_caps *caps)
 	}
 }
 
+/*
+ * Whether the PMU counts each external output of this trace unit as
+ * TRCEXTOUTn. The trace unit has an external output for each of its events.
+ * Only ETE is checked: per its specification, an implemented TRCEXTOUTn event
+ * counts external output n.
+ *
+ * Must run on the CPU that owns the trace unit.
+ */
+static bool etm4_pmu_counts_extout(struct etmv4_drvdata *drvdata)
+{
+	int n;
+
+	if (!etm4x_is_ete(drvdata) || !drvdata->caps.nr_event)
+		return false;
+
+	for (n = 0; n < drvdata->caps.nr_event; n++) {
+		if (!pmuv3_event_implemented(ARMV8_PMUV3_PERFCTR_TRCEXTOUT0 + n))
+			return false;
+	}
+
+	return true;
+}
+
 static void etm4_init_arch_data(void *info)
 {
 	u32 etmidr0;
@@ -1562,6 +1587,8 @@ static void etm4_init_arch_data(void *info)
 	/* NUMCNTR, bits[30:28] number of counters available for tracing */
 	caps->nr_cntr = FIELD_GET(TRCIDR5_NUMCNTR_MASK, etmidr5);
 
+	init_arg->ete_trcextout = etm4_pmu_counts_extout(drvdata);
+
 	coresight_clear_self_claim_tag_unlocked(csa);
 	etm4_cs_lock(drvdata, csa);
 	cpu_detect_trace_filtering(drvdata);
@@ -2265,7 +2292,7 @@ static int etm4_add_coresight_dev(struct etm4_init_arg *init_arg)
 	}
 
 	/* register with config infrastructure & load any current features */
-	ret = etm4_cscfg_register(drvdata->csdev);
+	ret = etm4_cscfg_register(drvdata->csdev, init_arg->ete_trcextout);
 	if (ret) {
 		coresight_unregister(drvdata->csdev);
 		return ret;
drivers/hwtracing/coresight/coresight-syscfg-configfs.c +3 -0
index 2b40e556be872f..6577a5085a634d 100644
@@ -250,6 +250,9 @@ static ssize_t cscfg_feat_matches_show(struct config_item *item, char *page)
 	if (match_flags & CS_CFG_MATCH_CLASS_SRC_ETM4)
 		used += scnprintf(page + used, PAGE_SIZE - used, "SRC_ETMV4 ");
 
+	if (match_flags & CS_CFG_MATCH_CAP_ETE_TRCEXTOUT)
+		used += scnprintf(page + used, PAGE_SIZE - used, "ETE_TRCEXTOUT ");
+
 	used += scnprintf(page + used, PAGE_SIZE - used, "\n");
 	return used;
 }
Signature · 1 line
2.52.1
#12 lore raw

Re: [PATCH v5 6/7] coresight: etm4x: Report whether the PMU counts the external outputs

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] coresight: etm4x: PMU coupling and 1-event match in etm4_pmu_counts_extout() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] coresight: etm4x: PMU coupling and 1-event match in etm4_pmu_counts_extout()
--

commit f0c882070427fa54aeaa9ce26f43db28f9511f4e
Author: Amir Ayupov <[email protected]>

coresight: etm4x: Report whether the PMU counts the external outputs

This commit checks at probe whether an ETE trace unit's CPU PMU implements the TRCEXTOUTn events corresponding to its external outputs and exposes the CS_CFG_MATCH_CAP_ETE_TRCEXTOUT capability match flag to CoreSight system configuration.

Quoted 4 lines
drivers/hwtracing/coresight/coresight-etm4x-core.c +0 -0
index af017bd8a5477..ecf2a6c945cf0 100644

[ ... ]

Quoted 16 lines
drivers/hwtracing/coresight/coresight-etm4x-core.c +12 -0
@@ -1399,6 +1401,29 @@ static void etm4_fixup_wrong_ccitmin(struct etmv4_caps *caps)
 	}
 }
 
+/*
+ * Whether the PMU counts each external output of this trace unit as
+ * TRCEXTOUTn. The trace unit has an external output for each of its events.
+ * Only ETE is checked: per its specification, an implemented TRCEXTOUTn event
+ * counts external output n.
+ *
+ * Must run on the CPU that owns the trace unit.
+ */
+static bool etm4_pmu_counts_extout(struct etmv4_drvdata *drvdata)
+{
+	int n;
+

drivers/hwtracing/coresight/coresight-etm4x-core.c static void etm4_fixup_wrong_ccitmin(struct etmv4_caps *caps) · line 1425

Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm4x-core.c +10 -0
+	if (!etm4x_is_ete(drvdata) || !drvdata->caps.nr_event)
+		return false;
+
+	for (n = 0; n < drvdata->caps.nr_event; n++) {
+		if (!pmuv3_event_implemented(ARMV8_PMUV3_PERFCTR_TRCEXTOUT0 + n))
+			return false;
+	}
+
+	return true;
+}

[Severity: Medium]
As reported by Mike Leach on v2 [1], should ETM/ETE configuration matching depend on the trace unit's own event resource registers (TRCIDR0 and TRCIDR4) rather than querying CPU PMU TRCEXTOUTn support inside the ETMv4 driver? Counting external outputs is a PMU feature that the PMU driver validates when a trcextoutN event is opened, whereas coupling it into a single ETM capability flag here still returns true when drvdata->caps.nr_event == 1 and only TRCEXTOUT0 exists. On such an ETE, event 1 (TRCEVENTCTL0R bits [15:8], driving external output 1) is RES0 and TRCEXTOUT1 is not checked, yet a feature like extout_pulse in commit "coresight: Add pmu_pulse/extout_pulse" that matches CS_CFG_MATCH_CAP_ETE_TRCEXTOUT and unconditionally programs event 1 will still match and load.

[1] https://lore.kernel.org/r/DB9PR08MB64752311F395D91F4FCBD0CB8C722@DB9PR08MB6475.eurprd08.prod.outlook.com

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#13 lore raw

PATCH v5 7/7 coresight: Add pmu_pulse/extout_pulse

In reply to Amir Ayupov

Add ETMv4 configuration 'pmu_pulse' with 'extout_pulse' feature which requires an ETE whose PMU counts its external outputs (CS_CFG_MATCH_CAP_ETE_TRCEXTOUT): event 1 selects the always-true resource and drives TRCEXTOUT1 PMU event which pulses on every cycle while the trace unit is enabled.

---
 .../trace/coresight/coresight-config.rst      |  5 ++
 .../trace/coresight/coresight-perf.rst        | 15 +++++
 drivers/hwtracing/coresight/Makefile          |  1 +
 .../coresight/coresight-cfg-pmu-pulse.c       | 55 +++++++++++++++++++
 .../coresight/coresight-cfg-preload.c         |  2 +
 .../coresight/coresight-cfg-preload.h         |  2 +
 6 files changed, 80 insertions(+)
 create mode 100644 drivers/hwtracing/coresight/coresight-cfg-pmu-pulse.c
Documentation/trace/coresight/coresight-config.rst +5 -0
index 6d5ffa6f73471b..3eed728bf0de1e 100644
@@ -129,6 +129,11 @@ The following steps take place in the operation of a configuration.
 
 5) At the end of the perf session, the configuration will be disabled.
 
+The built-in 'pmu_pulse' configuration pulses ETM external output 1 for a PMU
+event to count. It only pulses while the ETM is enabled, so combined with AUX
+pause and resume the PMU event can time each trace window (see
+coresight-perf.rst).
+
 
 Viewing Configurations and Features
 ===================================
Documentation/trace/coresight/coresight-perf.rst +15 -0
index 0a77741a431ef9..6770a455c6b592 100644
@@ -109,6 +109,21 @@ Example for triggering AUX pause and resume with PMU event::
         -e cycles/aux-action=pause,period=10000000/ \
         -e cycles/aux-action=resume,period=1050000/ -- sleep 1
 
+ETM-timed pause events
+~~~~~~~~~~~~~~~~~~~~~~
+
+The built-in ``pmu_pulse`` configuration pulses ETM external output 1 on every
+cycle of allowed trace, and a PMU event counting that output pauses trace after
+``N`` pulses, here 1000 cycles::
+
+  perf record -a -e cs_etm/pmu_pulse,aux-action=start-paused/u \
+    -e cycles/aux-action=resume,period=10000000/u \
+    -e trcextout1/aux-action=pause,period=1000/u \
+    -- sleep 1
+
+Each window is about ``N`` traced cycles plus the pause interrupt latency.
+The configuration only loads on an ETE whose PMU counts its external outputs.
+
 Perf test - Verify kernel and userspace perf CoreSight work
 -----------------------------------------------------------
 
drivers/hwtracing/coresight/Makefile +1 -0
index ab16d06783a572..568e797ac5a17e 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_CORESIGHT) += coresight.o
 coresight-y := coresight-core.o  coresight-etm-perf.o coresight-platform.o \
 		coresight-sysfs.o coresight-syscfg.o coresight-config.o \
 		coresight-cfg-preload.o coresight-cfg-afdo.o coresight-cfg-pstop.o \
+		coresight-cfg-pmu-pulse.o \
 		coresight-syscfg-configfs.o coresight-trace-id.o
 obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
 coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
drivers/hwtracing/coresight/coresight-cfg-pmu-pulse.c new file +55 -0

55 lines not on this page · raw message

drivers/hwtracing/coresight/coresight-cfg-preload.c +2 -0
index 4980e68483c5b9..a9a60a1c408455 100644
@@ -14,6 +14,7 @@ static struct cscfg_feature_desc *preload_feats[] = {
 #if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM4X)
 	&strobe_etm4x,
 	&gen_etrig_etm4x,
+	&extout_pulse_etm4x,
 #endif
 	NULL
 };
@@ -22,6 +23,7 @@ static struct cscfg_config_desc *preload_cfgs[] = {
 #if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM4X)
 	&afdo_etm4x,
 	&pstop_etm4x,
+	&pmu_pulse_etm4x,
 #endif
 	NULL
 };
drivers/hwtracing/coresight/coresight-cfg-preload.h +2 -0
index 291ba530a6a520..0058627f65ae5b 100644
@@ -12,4 +12,6 @@ extern struct cscfg_feature_desc strobe_etm4x;
 extern struct cscfg_config_desc afdo_etm4x;
 extern struct cscfg_feature_desc gen_etrig_etm4x;
 extern struct cscfg_config_desc pstop_etm4x;
+extern struct cscfg_feature_desc extout_pulse_etm4x;
+extern struct cscfg_config_desc pmu_pulse_etm4x;
 #endif
Signature · 1 line
2.52.1
#14 lore raw

Re: [PATCH v5 7/7] coresight: Add pmu_pulse/extout_pulse

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] coresight: extout_pulse loads on 1-event ETE lacking EVENT1 and TRCEXTOUT1 - [Low] coresight…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] coresight: extout_pulse loads on 1-event ETE lacking EVENT1 and TRCEXTOUT1
- [Low] coresight: missing coresight-cfg-preload.h include in coresight-cfg-pmu-pulse.c
--

commit e489c2f2f5183f248bad3a743fec51069d6bccc4
Author: Amir Ayupov <[email protected]>

coresight: Add pmu_pulse/extout_pulse

This commit adds a built-in pmu_pulse configuration and extout_pulse feature for ETMv4/ETE to pulse external output 1 on every traced cycle for counting via the TRCEXTOUT1 PMU event.

Quoted 7 lines
drivers/hwtracing/coresight/coresight-cfg-pmu-pulse.c new file +1 -0
new file mode 100644
index 0000000000000..76e8e6b5da0e9
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0

drivers/hwtracing/coresight/coresight-cfg-pmu-pulse.c line 11

Quoted 10 lines
drivers/hwtracing/coresight/coresight-cfg-pmu-pulse.c new file +10 -0
+/*
+ * Pulse ETM external output 1 on every traced cycle for a PMU event to count.
+ * Based on coresight-cfg-afdo.c
+ */
+
+#include "coresight-config.h"
+
+/* ETMv4 includes and features */
+#if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM4X)
+#include "coresight-etm4x-cfg.h"

[Severity: Low]
Should this file also include coresight-cfg-preload.h for the extern declarations of extout_pulse_etm4x and pmu_pulse_etm4x? Without it, C=1 sparse builds warn that both symbols are undeclared, as fixed for coresight-cfg-afdo.c in commit a7195f3f9383 ("coresight: Fix undeclared variable warnings from sparse checker").

Quoted 17 lines
drivers/hwtracing/coresight/coresight-cfg-pmu-pulse.c new file +17 -0
+
+/*
+ * extout_pulse feature: event 1 selects the always-true resource, so ETM
+ * external output 1 pulses on every cycle while the trace unit is enabled. A
+ * PMU event counting that output (TRCEXTOUT1), for example with
+ * aux-action=pause, then fires after as many traced cycles as its sample
+ * period. Event 0 is avoided because it is the trace unit trigger, and the
+ * TRBE driver treats a detected trigger as fatal.
+ */
+static struct cscfg_regval_desc extout_pulse_regs[] = {
+	/* event 1: resource selector 1 (always true), drives external output 1 */
+	{
+		.type = CS_CFG_REG_TYPE_STD | CS_CFG_REG_TYPE_VAL_MASK,
+		.offset = TRCEVENTCTL0R,
+		.val32 = 0x0100,
+		.mask32 = 0xff00,
+	},

drivers/hwtracing/coresight/coresight-cfg-pmu-pulse.c line 38

Quoted 10 lines
drivers/hwtracing/coresight/coresight-cfg-pmu-pulse.c new file +10 -0
+	/* end of regs */
+};
+
+struct cscfg_feature_desc extout_pulse_etm4x = {
+	.name = "extout_pulse",
+	.description = "Pulse external output 1 on every traced cycle.\n",
+	.match_flags = CS_CFG_MATCH_CLASS_SRC_ETM4 | CS_CFG_MATCH_CAP_ETE_TRCEXTOUT,
+	.nr_regs = ARRAY_SIZE(extout_pulse_regs),
+	.regs_desc = extout_pulse_regs,
+};

[Severity: Medium]
Can extout_pulse_etm4x match and load on an ETE that only implements a single event (caps.nr_event == 1), where EVENT1 and TRCEXTOUT1 do not exist?

CS_CFG_MATCH_CAP_ETE_TRCEXTOUT is set by etm4_pmu_counts_extout(), which only checks up to drvdata->caps.nr_event:

drivers/hwtracing/coresight/coresight-etm4x-core.c:etm4_pmu_counts_extout() {
	if (!etm4x_is_ete(drvdata) || !drvdata->caps.nr_event)
		return false;

	for (n = 0; n < drvdata->caps.nr_event; n++) {
		if (!pmuv3_event_implemented(ARMV8_PMUV3_PERFCTR_TRCEXTOUT0 + n))
			return false;
	}

	return true;
}

When TRCIDR0.NUMEVENT is 0 (so caps.nr_event == 1) and TRCEXTOUT0 is implemented, etm4_pmu_counts_extout() returns true and etm4_cfg_map_reg_offset() accepts TRCEVENTCTL0R without checking caps.nr_event >= 2. Enabling pmu_pulse on such a device succeeds instead of returning -EINVAL, writing 0x0100 to the unimplemented TRCEVENTCTL0R.EVENT1 (bits [15:8]) field with no external output pulses.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7