Skip to contentSkip to conversation

perf: fsl_imx8_ddr: Add AXI ID PORT CHANNEL filter support

PATCH Superseded Xu Yang 3 participants 10 messages Oct 11, 2023 – Nov 9, 2023

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Xu Yang

author maintainer
#0 lore raw

PATCH v2 1/5 perf: fsl_imx8_ddr: Add AXI ID PORT CHANNEL filter support

This is the extension of AXI ID filter.

Filter is defined with 2 configuration registers per counter 1-3 (counter 0 is not used for filtering and lacks these registers).
* Counter N MASK COMP register - AXI_ID and AXI_MASKING.
* Counter N MUX CNTL register - AXI CHANNEL and AXI PORT.
-- 0: address channel
-- 1: data channel

This filter is exposed to userspace as an additional (channel, port) pair. The definition of axi_channel is inverted in userspace, and it will be reverted in driver automatically.

AXI filter of Perf Monitor in DDR Subsystem, only a single port0 exist, so axi_port is reserved which should be 0.

e.g.
perf stat -a -e imx8_ddr0/axid-read,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd perf stat -a -e imx8_ddr0/axid-write,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd

---
Changes since v2:
- no changes

---
 drivers/perf/fsl_imx8_ddr_perf.c | 39 ++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/perf/fsl_imx8_ddr_perf.c +39 -0
index 92611c98120f..d0eae2d7e64b 100644
@@ -19,6 +19,8 @@
 #define COUNTER_READ		0x20
 
 #define COUNTER_DPCR1		0x30
+#define COUNTER_MUX_CNTL	0x50
+#define COUNTER_MASK_COMP	0x54
 
 #define CNTL_OVER		0x1
 #define CNTL_CLEAR		0x2
@@ -32,6 +34,13 @@
 #define CNTL_CSV_SHIFT		24
 #define CNTL_CSV_MASK		(0xFFU << CNTL_CSV_SHIFT)
 
+#define READ_PORT_SHIFT		0
+#define READ_PORT_MASK		(0x7 << READ_PORT_SHIFT)
+#define READ_CHANNEL_REVERT	0x00000008	/* bit 3 for read channel select */
+#define WRITE_PORT_SHIFT	8
+#define WRITE_PORT_MASK		(0x7 << WRITE_PORT_SHIFT)
+#define WRITE_CHANNEL_REVERT	0x00000800	/* bit 11 for write channel select */
+
 #define EVENT_CYCLES_ID		0
 #define EVENT_CYCLES_COUNTER	0
 #define NUM_COUNTERS		4
@@ -50,6 +59,7 @@ static DEFINE_IDA(ddr_ida);
 /* DDR Perf hardware feature */
 #define DDR_CAP_AXI_ID_FILTER			0x1     /* support AXI ID filter */
 #define DDR_CAP_AXI_ID_FILTER_ENHANCED		0x3     /* support enhanced AXI ID filter */
+#define DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER	0x4	/* support AXI ID PORT CHANNEL filter */
 
 struct fsl_ddr_devtype_data {
 	unsigned int quirks;    /* quirks needed for different DDR Perf core */
@@ -144,6 +154,7 @@ static const struct attribute_group ddr_perf_identifier_attr_group = {
 enum ddr_perf_filter_capabilities {
 	PERF_CAP_AXI_ID_FILTER = 0,
 	PERF_CAP_AXI_ID_FILTER_ENHANCED,
+	PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER,
 	PERF_CAP_AXI_ID_FEAT_MAX,
 };
 
@@ -157,6 +168,8 @@ static u32 ddr_perf_filter_cap_get(struct ddr_pmu *pmu, int cap)
 	case PERF_CAP_AXI_ID_FILTER_ENHANCED:
 		quirks &= DDR_CAP_AXI_ID_FILTER_ENHANCED;
 		return quirks == DDR_CAP_AXI_ID_FILTER_ENHANCED;
+	case PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER:
+		return !!(quirks & DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER);
 	default:
 		WARN(1, "unknown filter cap %d\n", cap);
 	}
@@ -187,6 +200,7 @@ static ssize_t ddr_perf_filter_cap_show(struct device *dev,
 static struct attribute *ddr_perf_filter_cap_attr[] = {
 	PERF_FILTER_EXT_ATTR_ENTRY(filter, PERF_CAP_AXI_ID_FILTER),
 	PERF_FILTER_EXT_ATTR_ENTRY(enhanced_filter, PERF_CAP_AXI_ID_FILTER_ENHANCED),
+	PERF_FILTER_EXT_ATTR_ENTRY(super_filter, PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER),
 	NULL,
 };
 
@@ -272,11 +286,15 @@ static const struct attribute_group ddr_perf_events_attr_group = {
 PMU_FORMAT_ATTR(event, "config:0-7");
 PMU_FORMAT_ATTR(axi_id, "config1:0-15");
 PMU_FORMAT_ATTR(axi_mask, "config1:16-31");
+PMU_FORMAT_ATTR(axi_port, "config2:0-2");
+PMU_FORMAT_ATTR(axi_channel, "config2:3-3");
 
 static struct attribute *ddr_perf_format_attrs[] = {
 	&format_attr_event.attr,
 	&format_attr_axi_id.attr,
 	&format_attr_axi_mask.attr,
+	&format_attr_axi_port.attr,
+	&format_attr_axi_channel.attr,
 	NULL,
 };
 
@@ -530,6 +548,7 @@ static int ddr_perf_event_add(struct perf_event *event, int flags)
 	int counter;
 	int cfg = event->attr.config;
 	int cfg1 = event->attr.config1;
+	int cfg2 = event->attr.config2;
 
 	if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER) {
 		int i;
@@ -553,6 +572,26 @@ static int ddr_perf_event_add(struct perf_event *event, int flags)
 		return -EOPNOTSUPP;
 	}
 
+	if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER) {
+		if (ddr_perf_is_filtered(event)) {
+			/* revert axi id masking(axi_mask) value */
+			cfg1 ^= AXI_MASKING_REVERT;
+			writel(cfg1, pmu->base + COUNTER_MASK_COMP + ((counter - 1) << 4));
+
+			if (cfg == 0x41) {
+				/* revert axi read channel(axi_channel) value */
+				cfg2 ^= READ_CHANNEL_REVERT;
+				cfg2 |= FIELD_PREP(READ_PORT_MASK, cfg2);
+			} else {
+				/* revert axi write channel(axi_channel) value */
+				cfg2 ^= WRITE_CHANNEL_REVERT;
+				cfg2 |= FIELD_PREP(WRITE_PORT_MASK, cfg2);
+			}
+
+			writel(cfg2, pmu->base + COUNTER_MUX_CNTL + ((counter - 1) << 4));
+		}
+	}
+
 	pmu->events[counter] = event;
 	hwc->idx = counter;
 
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v2 2/5 docs/perf: Add explanation for DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER quirk

Add explanation for DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER quirk.

---
Changes since v2:
- no changes

---
 Documentation/admin-guide/perf/imx-ddr.rst | 45 ++++++++++++++++++----
 1 file changed, 37 insertions(+), 8 deletions(-)
Documentation/admin-guide/perf/imx-ddr.rst +37 -8
index 90926d0fb8ec..77418ae5a290 100644
@@ -13,8 +13,8 @@ is one register for each counter. Counter 0 is special in that it always counts
 interrupt is raised. If any other counter overflows, it continues counting, and
 no interrupt is raised.
 
-The "format" directory describes format of the config (event ID) and config1
-(AXI filtering) fields of the perf_event_attr structure, see /sys/bus/event_source/
+The "format" directory describes format of the config (event ID) and config1/2
+(AXI filter setting) fields of the perf_event_attr structure, see /sys/bus/event_source/
 devices/imx8_ddr0/format/. The "events" directory describes the events types
 hardware supported that can be used with perf tool, see /sys/bus/event_source/
 devices/imx8_ddr0/events/. The "caps" directory describes filter features implemented
@@ -28,12 +28,11 @@ in DDR PMU, see /sys/bus/events_source/devices/imx8_ddr0/caps/.
 AXI filtering is only used by CSV modes 0x41 (axid-read) and 0x42 (axid-write)
 to count reading or writing matches filter setting. Filter setting is various
 from different DRAM controller implementations, which is distinguished by quirks
-in the driver. You also can dump info from userspace, filter in "caps" directory
-indicates whether PMU supports AXI ID filter or not; enhanced_filter indicates
-whether PMU supports enhanced AXI ID filter or not. Value 0 for un-supported, and
-value 1 for supported.
+in the driver. You also can dump info from userspace, "caps" directory show the
+type of AXI filter (filter, enhanced_filter and super_filter). Value 0 for
+un-supported, and value 1 for supported.
 
-* With DDR_CAP_AXI_ID_FILTER quirk(filter: 1, enhanced_filter: 0).
+* With DDR_CAP_AXI_ID_FILTER quirk(filter: 1, enhanced_filter: 0, super_filter: 0).
   Filter is defined with two configuration parts:
   --AXI_ID defines AxID matching value.
   --AXI_MASKING defines which bits of AxID are meaningful for the matching.
@@ -65,7 +64,37 @@ value 1 for supported.
 
         perf stat -a -e imx8_ddr0/axid-read,axi_id=0x12/ cmd, which will monitor ARID=0x12
 
-* With DDR_CAP_AXI_ID_FILTER_ENHANCED quirk(filter: 1, enhanced_filter: 1).
+* With DDR_CAP_AXI_ID_FILTER_ENHANCED quirk(filter: 1, enhanced_filter: 1, super_filter: 0).
   This is an extension to the DDR_CAP_AXI_ID_FILTER quirk which permits
   counting the number of bytes (as opposed to the number of bursts) from DDR
   read and write transactions concurrently with another set of data counters.
+
+* With DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER quirk(filter: 0, enhanced_filter: 0, super_filter: 1).
+  There is a limitation in previous AXI filter, it cannot filter different IDs
+  at the same time as the filter is shared between counters. This quirk is the
+  extension of AXI ID filter. One improvement is that counter 1-3 has their own
+  filter, means that it supports concurrently filter various IDs. Another
+  improvement is that counter 1-3 supports AXI PORT and CHANNEL selection. Support
+  selecting address channel or data channel.
+
+  Filter is defined with 2 configuration registers per counter 1-3.
+  --Counter N MASK COMP register - including AXI_ID and AXI_MASKING.
+  --Counter N MUX CNTL register - including AXI CHANNEL and AXI PORT.
+
+      - 0: address channel
+      - 1: data channel
+
+  PMU in DDR subsystem, only one single port0 exists, so axi_port is reserved
+  which should be 0.
+
+  .. code-block:: bash
+
+      perf stat -a -e imx8_ddr0/axid-read,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd
+      perf stat -a -e imx8_ddr0/axid-write,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd
+
+  .. note::
+
+      axi_channel is inverted in userspace, and it will be reverted in driver
+      automatically. So that users do not need specify axi_channel if want to
+      monitor data channel from DDR transactions, since data channel is more
+      meaningful.
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v2 3/5 dt-bindings: perf: fsl-imx-ddr: Add i.MX8DXL compatible

In reply to Xu Yang

Add a compatible for i.MX8DXL which is compatile with "fsl,imx8-ddr-pmu".

---
Changes since v2:
- no changes

---
 Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/perf/fsl-imx-ddr.yaml +3 -0
index e9fad4b3de68..6c96a4204e5d 100644
@@ -27,6 +27,9 @@ properties:
               - fsl,imx8mq-ddr-pmu
               - fsl,imx8mp-ddr-pmu
           - const: fsl,imx8m-ddr-pmu
+      - items:
+          - const: fsl,imx8dxl-ddr-pmu
+          - const: fsl,imx8-ddr-pmu
 
   reg:
     maxItems: 1
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH v2 4/5 perf: fsl_imx8_ddr: Add driver support for i.MX8DXL DDR Perf

In reply to Xu Yang

Add driver support for i.MX8DXL DDR Perf, which supports AXI ID PORT CHANNEL filter.

---
Changes since v2:
- no changes

---
 drivers/perf/fsl_imx8_ddr_perf.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/perf/fsl_imx8_ddr_perf.c +6 -0
index d0eae2d7e64b..7dbfaee372c7 100644
@@ -92,6 +92,11 @@ static const struct fsl_ddr_devtype_data imx8mp_devtype_data = {
 	.identifier = "i.MX8MP",
 };
 
+static const struct fsl_ddr_devtype_data imx8dxl_devtype_data = {
+	.quirks = DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER,
+	.identifier = "i.MX8DXL",
+};
+
 static const struct of_device_id imx_ddr_pmu_dt_ids[] = {
 	{ .compatible = "fsl,imx8-ddr-pmu", .data = &imx8_devtype_data},
 	{ .compatible = "fsl,imx8m-ddr-pmu", .data = &imx8m_devtype_data},
@@ -99,6 +104,7 @@ static const struct of_device_id imx_ddr_pmu_dt_ids[] = {
 	{ .compatible = "fsl,imx8mm-ddr-pmu", .data = &imx8mm_devtype_data},
 	{ .compatible = "fsl,imx8mn-ddr-pmu", .data = &imx8mn_devtype_data},
 	{ .compatible = "fsl,imx8mp-ddr-pmu", .data = &imx8mp_devtype_data},
+	{ .compatible = "fsl,imx8dxl-ddr-pmu", .data = &imx8dxl_devtype_data},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, imx_ddr_pmu_dt_ids);
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 4/5
#4 lore raw

RE: [PATCH v2 4/5] perf: fsl_imx8_ddr: Add driver support for i.MX8DXL DDR Perf

Quoted 16 lines

-----Original Message-----
From: Xu Yang <[email protected]>
Sent: Wednesday, October 11, 2023 1:09 AM
To: Frank Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; [email protected]; linux- [email protected]; [email protected]; Xu Yang <[email protected]>
Subject: [PATCH v2 4/5] perf: fsl_imx8_ddr: Add driver support for i.MX8DXL DDR Perf

Quoted 4 lines

Add driver support for i.MX8DXL DDR Perf, which supports AXI ID PORT CHANNEL filter.

Quoted 42 lines

---
Changes since v2:
- no changes

---
 drivers/perf/fsl_imx8_ddr_perf.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/perf/fsl_imx8_ddr_perf.c +5 -0
index d0eae2d7e64b..7dbfaee372c7 100644
@@ -92,6 +92,11 @@ static const struct fsl_ddr_devtype_data
 imx8mp_devtype_data = {
 	.identifier = "i.MX8MP",
 };
 
+static const struct fsl_ddr_devtype_data imx8dxl_devtype_data = {
+	.quirks = DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER,
+	.identifier = "i.MX8DXL",
+};
+
 static const struct of_device_id imx_ddr_pmu_dt_ids[] = {
 	{ .compatible = "fsl,imx8-ddr-pmu", .data = &imx8_devtype_data},

{ .compatible = "fsl,imx8m-ddr-pmu", .data =
&imx8m_devtype_data},

drivers/perf/fsl_imx8_ddr_perf.c +0 -0
@@ -99,6 +104,7 @@ static const struct of_device_id imx_ddr_pmu_dt_ids[]
 = {
 	{ .compatible = "fsl,imx8mm-ddr-pmu", .data =
 &imx8mm_devtype_data},
 	{ .compatible = "fsl,imx8mn-ddr-pmu", .data =
 &imx8mn_devtype_data},
 	{ .compatible = "fsl,imx8mp-ddr-pmu", .data =

&imx8mp_devtype_data},

drivers/perf/fsl_imx8_ddr_perf.c +1 -0
+	{ .compatible = "fsl,imx8dxl-ddr-pmu", .data =

&imx8dxl_devtype_data},
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, imx_ddr_pmu_dt_ids);
--
2.34.1

author maintainer
#5 lore raw

PATCH v2 5/5 arm64: dts: imx8dxl-ss-ddr: change ddr_pmu0 compatible

In reply to Xu Yang

i.MX8DXL's ddr pmu has port/channel filter capabilities, but it still is compatible with "fsl,imx8-ddr-pmu". This will change the compatible.

---
Changes since v2:
- fix topo

---
 arch/arm64/boot/dts/freescale/imx8dxl-ss-ddr.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/freescale/imx8dxl-ss-ddr.dtsi +1 -1
index 550f513708d8..3569abb5bb9b 100644
@@ -4,6 +4,6 @@
  */
 
 &ddr_pmu0 {
-	compatible = "fsl,imx8-ddr-pmu";
+	compatible = "fsl,imx8dxl-ddr-pmu", "fsl,imx8-ddr-pmu";
 	interrupts = <GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>;
 };
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 1/5
#6 lore raw
In reply to Xu Yang
Quoted 32 lines

-----Original Message-----
From: Xu Yang <[email protected]>
Sent: Wednesday, October 11, 2023 1:09 AM
To: Frank Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; [email protected]; linux- [email protected]; [email protected]; Xu Yang <[email protected]>
Subject: [PATCH v2 1/5] perf: fsl_imx8_ddr: Add AXI ID PORT CHANNEL filter support

This is the extension of AXI ID filter.

Filter is defined with 2 configuration registers per counter 1-3 (counter 0 is not used for filtering and lacks these registers).
* Counter N MASK COMP register - AXI_ID and AXI_MASKING.
* Counter N MUX CNTL register - AXI CHANNEL and AXI PORT.
-- 0: address channel
-- 1: data channel

This filter is exposed to userspace as an additional (channel, port) pair. The definition of axi_channel is inverted in userspace, and it will be reverted in driver automatically.

AXI filter of Perf Monitor in DDR Subsystem, only a single port0 exist, so axi_port is reserved which should be 0.

Quoted 7 lines

e.g.
perf stat -a -e imx8_ddr0/axid- read,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd perf stat -a -e imx8_ddr0/axid- write,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd

Quoted 142 lines

---
Changes since v2:
- no changes

---
 drivers/perf/fsl_imx8_ddr_perf.c | 39
++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/perf/fsl_imx8_ddr_perf.c +5 -0
index 92611c98120f..d0eae2d7e64b 100644
@@ -19,6 +19,8 @@
 #define COUNTER_READ		0x20
 
 #define COUNTER_DPCR1		0x30
+#define COUNTER_MUX_CNTL	0x50
+#define COUNTER_MASK_COMP	0x54
 
 #define CNTL_OVER		0x1
 #define CNTL_CLEAR		0x2
@@ -32,6 +34,13 @@
 #define CNTL_CSV_SHIFT		24
 #define CNTL_CSV_MASK		(0xFFU << CNTL_CSV_SHIFT)
 
+#define READ_PORT_SHIFT		0
+#define READ_PORT_MASK		(0x7 << READ_PORT_SHIFT)
+#define READ_CHANNEL_REVERT	0x00000008	/* bit 3 for read

channel select */

drivers/perf/fsl_imx8_ddr_perf.c +3 -0
+#define WRITE_PORT_SHIFT	8
+#define WRITE_PORT_MASK		(0x7 << WRITE_PORT_SHIFT)
+#define WRITE_CHANNEL_REVERT	0x00000800	/* bit 11 for write

channel select */

drivers/perf/fsl_imx8_ddr_perf.c +1 -0
+
 #define EVENT_CYCLES_ID		0
 #define EVENT_CYCLES_COUNTER	0
 #define NUM_COUNTERS		4
@@ -50,6 +59,7 @@ static DEFINE_IDA(ddr_ida);
 /* DDR Perf hardware feature */
 #define DDR_CAP_AXI_ID_FILTER			0x1     /* support AXI

ID filter */
#define DDR_CAP_AXI_ID_FILTER_ENHANCED 0x3 /* support
enhanced AXI ID filter */
+#define DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER 0x4 /* support
AXI ID PORT CHANNEL filter */

struct fsl_ddr_devtype_data {

drivers/perf/fsl_imx8_ddr_perf.c +3 -0
 	unsigned int quirks;    /* quirks needed for different DDR Perf core */
@@ -144,6 +154,7 @@ static const struct attribute_group
 ddr_perf_identifier_attr_group = {
 enum ddr_perf_filter_capabilities {
 	PERF_CAP_AXI_ID_FILTER = 0,
 	PERF_CAP_AXI_ID_FILTER_ENHANCED,
+	PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER,
 	PERF_CAP_AXI_ID_FEAT_MAX,
 };
@@ -157,6 +168,8 @@ static u32 ddr_perf_filter_cap_get(struct ddr_pmu
 *pmu, int cap)
 	case PERF_CAP_AXI_ID_FILTER_ENHANCED:
 		quirks &= DDR_CAP_AXI_ID_FILTER_ENHANCED;
 		return quirks == DDR_CAP_AXI_ID_FILTER_ENHANCED;
+	case PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER:
+		return !!(quirks & DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER);
 	default:
 		WARN(1, "unknown filter cap %d\n", cap);
drivers/perf/fsl_imx8_ddr_perf.c +1 -0
 	}
@@ -187,6 +200,7 @@ static ssize_t ddr_perf_filter_cap_show(struct device
 *dev,
 static struct attribute *ddr_perf_filter_cap_attr[] = {
 	PERF_FILTER_EXT_ATTR_ENTRY(filter, PERF_CAP_AXI_ID_FILTER),
 	PERF_FILTER_EXT_ATTR_ENTRY(enhanced_filter,
 PERF_CAP_AXI_ID_FILTER_ENHANCED),
+	PERF_FILTER_EXT_ATTR_ENTRY(super_filter,
 PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER),
drivers/perf/fsl_imx8_ddr_perf.c +5 -0
 	NULL,
 };
@@ -272,11 +286,15 @@ static const struct attribute_group
 ddr_perf_events_attr_group = {
 PMU_FORMAT_ATTR(event, "config:0-7");
 PMU_FORMAT_ATTR(axi_id, "config1:0-15");
 PMU_FORMAT_ATTR(axi_mask, "config1:16-31");
+PMU_FORMAT_ATTR(axi_port, "config2:0-2");
+PMU_FORMAT_ATTR(axi_channel, "config2:3-3");
 
 static struct attribute *ddr_perf_format_attrs[] = {
 	&format_attr_event.attr,
 	&format_attr_axi_id.attr,
 	&format_attr_axi_mask.attr,
+	&format_attr_axi_port.attr,
+	&format_attr_axi_channel.attr,
 	NULL,
 };
@@ -530,6 +548,7 @@ static int ddr_perf_event_add(struct perf_event
 *event, int flags)
 	int counter;
 	int cfg = event->attr.config;
 	int cfg1 = event->attr.config1;
+	int cfg2 = event->attr.config2;
 
 	if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER) {
drivers/perf/fsl_imx8_ddr_perf.c +8 -0
 		int i;
@@ -553,6 +572,26 @@ static int ddr_perf_event_add(struct perf_event
 *event, int flags)
 		return -EOPNOTSUPP;
 	}
 
+	if (pmu->devtype_data->quirks &
 DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER) {
+		if (ddr_perf_is_filtered(event)) {
+			/* revert axi id masking(axi_mask) value */
+			cfg1 ^= AXI_MASKING_REVERT;
+			writel(cfg1, pmu->base + COUNTER_MASK_COMP +
 ((counter - 1) << 4));
+
+			if (cfg == 0x41) {
+				/* revert axi read channel(axi_channel) value

*/

drivers/perf/fsl_imx8_ddr_perf.c +4 -0
+				cfg2 ^= READ_CHANNEL_REVERT;
+				cfg2 |= FIELD_PREP(READ_PORT_MASK, cfg2);
+			} else {
+				/* revert axi write channel(axi_channel) value

*/

drivers/perf/fsl_imx8_ddr_perf.c +2 -0
+				cfg2 ^= WRITE_CHANNEL_REVERT;
+				cfg2 |= FIELD_PREP(WRITE_PORT_MASK,

cfg2);

drivers/perf/fsl_imx8_ddr_perf.c +3 -0
+			}
+
+			writel(cfg2, pmu->base + COUNTER_MUX_CNTL +

((counter - 1) << 4));

drivers/perf/fsl_imx8_ddr_perf.c +3 -1
+		}
+	}
+
 	pmu->events[counter] = event;
 	hwc->idx = counter;
 
--

2.34.1

maintainer
#7 lore raw
In reply to Xu Yang
Quoted 90 lines · Xu Yang

This is the extension of AXI ID filter.

Filter is defined with 2 configuration registers per counter 1-3 (counter 0 is not used for filtering and lacks these registers).
* Counter N MASK COMP register - AXI_ID and AXI_MASKING.
* Counter N MUX CNTL register - AXI CHANNEL and AXI PORT.
-- 0: address channel
-- 1: data channel

This filter is exposed to userspace as an additional (channel, port) pair. The definition of axi_channel is inverted in userspace, and it will be reverted in driver automatically.

AXI filter of Perf Monitor in DDR Subsystem, only a single port0 exist, so axi_port is reserved which should be 0.

e.g.
perf stat -a -e imx8_ddr0/axid-read,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd perf stat -a -e imx8_ddr0/axid-write,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd

---
Changes since v2:
- no changes

---
 drivers/perf/fsl_imx8_ddr_perf.c | 39 ++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/perf/fsl_imx8_ddr_perf.c +14 -0
index 92611c98120f..d0eae2d7e64b 100644
@@ -19,6 +19,8 @@
 #define COUNTER_READ		0x20
 
 #define COUNTER_DPCR1		0x30
+#define COUNTER_MUX_CNTL	0x50
+#define COUNTER_MASK_COMP	0x54
 
 #define CNTL_OVER		0x1
 #define CNTL_CLEAR		0x2
@@ -32,6 +34,13 @@
 #define CNTL_CSV_SHIFT		24
 #define CNTL_CSV_MASK		(0xFFU << CNTL_CSV_SHIFT)
 
+#define READ_PORT_SHIFT		0
+#define READ_PORT_MASK		(0x7 << READ_PORT_SHIFT)
+#define READ_CHANNEL_REVERT	0x00000008	/* bit 3 for read channel select */
+#define WRITE_PORT_SHIFT	8
+#define WRITE_PORT_MASK		(0x7 << WRITE_PORT_SHIFT)
+#define WRITE_CHANNEL_REVERT	0x00000800	/* bit 11 for write channel select */
+
 #define EVENT_CYCLES_ID		0
 #define EVENT_CYCLES_COUNTER	0
 #define NUM_COUNTERS		4
@@ -50,6 +59,7 @@ static DEFINE_IDA(ddr_ida);
 /* DDR Perf hardware feature */
 #define DDR_CAP_AXI_ID_FILTER			0x1     /* support AXI ID filter */
 #define DDR_CAP_AXI_ID_FILTER_ENHANCED		0x3     /* support enhanced AXI ID filter */
+#define DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER	0x4	/* support AXI ID PORT CHANNEL filter */
 
 struct fsl_ddr_devtype_data {
 	unsigned int quirks;    /* quirks needed for different DDR Perf core */
@@ -144,6 +154,7 @@ static const struct attribute_group ddr_perf_identifier_attr_group = {
 enum ddr_perf_filter_capabilities {
 	PERF_CAP_AXI_ID_FILTER = 0,
 	PERF_CAP_AXI_ID_FILTER_ENHANCED,
+	PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER,
 	PERF_CAP_AXI_ID_FEAT_MAX,
 };
 
@@ -157,6 +168,8 @@ static u32 ddr_perf_filter_cap_get(struct ddr_pmu *pmu, int cap)
 	case PERF_CAP_AXI_ID_FILTER_ENHANCED:
 		quirks &= DDR_CAP_AXI_ID_FILTER_ENHANCED;
 		return quirks == DDR_CAP_AXI_ID_FILTER_ENHANCED;
+	case PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER:
+		return !!(quirks & DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER);
 	default:
 		WARN(1, "unknown filter cap %d\n", cap);
 	}
@@ -187,6 +200,7 @@ static ssize_t ddr_perf_filter_cap_show(struct device *dev,
 static struct attribute *ddr_perf_filter_cap_attr[] = {
 	PERF_FILTER_EXT_ATTR_ENTRY(filter, PERF_CAP_AXI_ID_FILTER),
 	PERF_FILTER_EXT_ATTR_ENTRY(enhanced_filter, PERF_CAP_AXI_ID_FILTER_ENHANCED),
+	PERF_FILTER_EXT_ATTR_ENTRY(super_filter, PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER),
 	NULL,
 };
 

drivers/perf/fsl_imx8_ddr_perf.c static const struct attribute_group ddr_perf_events_attr_group = { · line 290

Quoted 5 lines
drivers/perf/fsl_imx8_ddr_perf.c +2 -0
@@ -272,11 +286,15 @@ static const struct attribute_group ddr_perf_events_attr_group = {
 PMU_FORMAT_ATTR(event, "config:0-7");
 PMU_FORMAT_ATTR(axi_id, "config1:0-15");
 PMU_FORMAT_ATTR(axi_mask, "config1:16-31");
+PMU_FORMAT_ATTR(axi_port, "config2:0-2");
+PMU_FORMAT_ATTR(axi_channel, "config2:3-3");

Any specific reason to allocate from config2, rather than the upper 32 bits of config1?

drivers/perf/fsl_imx8_ddr_perf.c static int ddr_perf_event_add(struct perf_event *event, int flags) · line 579

Quoted 9 lines
drivers/perf/fsl_imx8_ddr_perf.c +5 -0
@@ -553,6 +572,26 @@ static int ddr_perf_event_add(struct perf_event *event, int flags)
 		return -EOPNOTSUPP;
 	}
 
+	if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER) {
+		if (ddr_perf_is_filtered(event)) {
+			/* revert axi id masking(axi_mask) value */
+			cfg1 ^= AXI_MASKING_REVERT;
+			writel(cfg1, pmu->base + COUNTER_MASK_COMP + ((counter - 1) << 4));

Please can you explain what this "reverting" is doing? It looks like a user-visible change in behaviour to me, or are you saying that the driver currently does the wrong thing on hardware that supports the new filter?

drivers/perf/fsl_imx8_ddr_perf.c static int ddr_perf_event_add(struct perf_event *event, int flags) · line 581

Quoted 2 lines
drivers/perf/fsl_imx8_ddr_perf.c +2 -0
+
+			if (cfg == 0x41) {

What is this 0x41 for?

Will

author maintainer
#8 lore raw

Hi Will,

Quoted 90 lines · Xu Yang
Quoted 89 lines

This is the extension of AXI ID filter.

Filter is defined with 2 configuration registers per counter 1-3 (counter 0 is not used for filtering and lacks these registers).
* Counter N MASK COMP register - AXI_ID and AXI_MASKING.
* Counter N MUX CNTL register - AXI CHANNEL and AXI PORT.
-- 0: address channel
-- 1: data channel

This filter is exposed to userspace as an additional (channel, port) pair. The definition of axi_channel is inverted in userspace, and it will be reverted in driver automatically.

AXI filter of Perf Monitor in DDR Subsystem, only a single port0 exist, so axi_port is reserved which should be 0.

e.g.
perf stat -a -e imx8_ddr0/axid-read,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd perf stat -a -e imx8_ddr0/axid-write,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd

---
Changes since v2:
- no changes

---
 drivers/perf/fsl_imx8_ddr_perf.c | 39 ++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/perf/fsl_imx8_ddr_perf.c +14 -0
index 92611c98120f..d0eae2d7e64b 100644
@@ -19,6 +19,8 @@
 #define COUNTER_READ         0x20
 
 #define COUNTER_DPCR1                0x30
+#define COUNTER_MUX_CNTL     0x50
+#define COUNTER_MASK_COMP    0x54
 
 #define CNTL_OVER            0x1
 #define CNTL_CLEAR           0x2
@@ -32,6 +34,13 @@
 #define CNTL_CSV_SHIFT               24
 #define CNTL_CSV_MASK                (0xFFU << CNTL_CSV_SHIFT)
 
+#define READ_PORT_SHIFT              0
+#define READ_PORT_MASK               (0x7 << READ_PORT_SHIFT)
+#define READ_CHANNEL_REVERT  0x00000008      /* bit 3 for read channel select */
+#define WRITE_PORT_SHIFT     8
+#define WRITE_PORT_MASK              (0x7 << WRITE_PORT_SHIFT)
+#define WRITE_CHANNEL_REVERT 0x00000800      /* bit 11 for write channel select */
+
 #define EVENT_CYCLES_ID              0
 #define EVENT_CYCLES_COUNTER 0
 #define NUM_COUNTERS         4
@@ -50,6 +59,7 @@ static DEFINE_IDA(ddr_ida);
 /* DDR Perf hardware feature */
 #define DDR_CAP_AXI_ID_FILTER                        0x1     /* support AXI ID filter */
 #define DDR_CAP_AXI_ID_FILTER_ENHANCED               0x3     /* support enhanced AXI ID filter */
+#define DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER   0x4     /* support AXI ID PORT CHANNEL filter */
 
 struct fsl_ddr_devtype_data {
      unsigned int quirks;    /* quirks needed for different DDR Perf core */
@@ -144,6 +154,7 @@ static const struct attribute_group ddr_perf_identifier_attr_group = {
 enum ddr_perf_filter_capabilities {
      PERF_CAP_AXI_ID_FILTER = 0,
      PERF_CAP_AXI_ID_FILTER_ENHANCED,
+     PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER,
      PERF_CAP_AXI_ID_FEAT_MAX,
 };
 
@@ -157,6 +168,8 @@ static u32 ddr_perf_filter_cap_get(struct ddr_pmu *pmu, int cap)
      case PERF_CAP_AXI_ID_FILTER_ENHANCED:
              quirks &= DDR_CAP_AXI_ID_FILTER_ENHANCED;
              return quirks == DDR_CAP_AXI_ID_FILTER_ENHANCED;
+     case PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER:
+             return !!(quirks & DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER);
      default:
              WARN(1, "unknown filter cap %d\n", cap);
      }
@@ -187,6 +200,7 @@ static ssize_t ddr_perf_filter_cap_show(struct device *dev,
 static struct attribute *ddr_perf_filter_cap_attr[] = {
      PERF_FILTER_EXT_ATTR_ENTRY(filter, PERF_CAP_AXI_ID_FILTER),
      PERF_FILTER_EXT_ATTR_ENTRY(enhanced_filter, PERF_CAP_AXI_ID_FILTER_ENHANCED),
+     PERF_FILTER_EXT_ATTR_ENTRY(super_filter, PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER),
      NULL,
 };
 
Quoted 9 lines

drivers/perf/fsl_imx8_ddr_perf.c static const struct attribute_group ddr_perf_events_attr_group = { · line 290

Quoted 6 lines
drivers/perf/fsl_imx8_ddr_perf.c +2 -0
@@ -272,11 +286,15 @@ static const struct attribute_group ddr_perf_events_attr_group = {
 PMU_FORMAT_ATTR(event, "config:0-7");
 PMU_FORMAT_ATTR(axi_id, "config1:0-15");
 PMU_FORMAT_ATTR(axi_mask, "config1:16-31");
+PMU_FORMAT_ATTR(axi_port, "config2:0-2");
+PMU_FORMAT_ATTR(axi_channel, "config2:3-3");

Any specific reason to allocate from config2, rather than the upper 32 bits of config1?

No. Either way is ok for me.

Quoted 5 lines
Quoted 5 lines
drivers/perf/fsl_imx8_ddr_perf.c +0 -0
@@ -553,6 +572,26 @@ static int ddr_perf_event_add(struct perf_event *event, int flags)
              return -EOPNOTSUPP;
      }
 
Quoted 9 lines

drivers/perf/fsl_imx8_ddr_perf.c static int ddr_perf_event_add(struct perf_event *event, int flags) · line 579

Quoted 5 lines
drivers/perf/fsl_imx8_ddr_perf.c +5 -0
+     if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER) {
+             if (ddr_perf_is_filtered(event)) {
+                     /* revert axi id masking(axi_mask) value */
+                     cfg1 ^= AXI_MASKING_REVERT;
+                     writel(cfg1, pmu->base + COUNTER_MASK_COMP + ((counter - 1) << 4));

Please can you explain what this "reverting" is doing? It looks like a user-visible change in behaviour to me, or are you saying that the driver currently does the wrong thing on hardware that supports the new filter?

In sys/metrics.json table as below,

"MetricExpr": "imx8_ddr0@axid\\-read\\,axi_mask\\=0x0000\\,axi_id\\=0x0065@",

We have set axi_mask to 0x0000 for most of the metics and assume that bit 0 is used for masking. In hardware register, bit 1 is used for masking axi id. So there exists a reverting operation. It also works for me to set actual axi mask value in sys/metrics.json. But, because this patch is just a supplement for filter, and previous axi filter already use a reverting operation for filter, so I did the same thing there.

Quoted 5 lines

drivers/perf/fsl_imx8_ddr_perf.c static int ddr_perf_event_add(struct perf_event *event, int flags) · line 581

Quoted 3 lines
drivers/perf/fsl_imx8_ddr_perf.c +2 -0
+
+                     if (cfg == 0x41) {

What is this 0x41 for?

IMX8_DDR_PMU_EVENT_ATTR(axid-read, 0x41),
This 0x41 means axi read filter event.

Thanks,
Xu Yang

Quoted 2 lines

Will

author maintainer
#9 lore raw

Hi Will,

Quoted 135 lines

Hi Will,

Quoted 90 lines · Xu Yang
Quoted 89 lines

This is the extension of AXI ID filter.

Filter is defined with 2 configuration registers per counter 1-3 (counter 0 is not used for filtering and lacks these registers).
* Counter N MASK COMP register - AXI_ID and AXI_MASKING.
* Counter N MUX CNTL register - AXI CHANNEL and AXI PORT.
-- 0: address channel
-- 1: data channel

This filter is exposed to userspace as an additional (channel, port) pair. The definition of axi_channel is inverted in userspace, and it will be reverted in driver automatically.

AXI filter of Perf Monitor in DDR Subsystem, only a single port0 exist, so axi_port is reserved which should be 0.

e.g.
perf stat -a -e imx8_ddr0/axid-read,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd perf stat -a -e imx8_ddr0/axid-write,axi_mask=0xMMMM,axi_id=0xDDDD,axi_channel=0xH/ cmd

---
Changes since v2:
- no changes

---
 drivers/perf/fsl_imx8_ddr_perf.c | 39 ++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/perf/fsl_imx8_ddr_perf.c +14 -0
index 92611c98120f..d0eae2d7e64b 100644
@@ -19,6 +19,8 @@
 #define COUNTER_READ         0x20
 
 #define COUNTER_DPCR1                0x30
+#define COUNTER_MUX_CNTL     0x50
+#define COUNTER_MASK_COMP    0x54
 
 #define CNTL_OVER            0x1
 #define CNTL_CLEAR           0x2
@@ -32,6 +34,13 @@
 #define CNTL_CSV_SHIFT               24
 #define CNTL_CSV_MASK                (0xFFU << CNTL_CSV_SHIFT)
 
+#define READ_PORT_SHIFT              0
+#define READ_PORT_MASK               (0x7 << READ_PORT_SHIFT)
+#define READ_CHANNEL_REVERT  0x00000008      /* bit 3 for read channel select */
+#define WRITE_PORT_SHIFT     8
+#define WRITE_PORT_MASK              (0x7 << WRITE_PORT_SHIFT)
+#define WRITE_CHANNEL_REVERT 0x00000800      /* bit 11 for write channel select */
+
 #define EVENT_CYCLES_ID              0
 #define EVENT_CYCLES_COUNTER 0
 #define NUM_COUNTERS         4
@@ -50,6 +59,7 @@ static DEFINE_IDA(ddr_ida);
 /* DDR Perf hardware feature */
 #define DDR_CAP_AXI_ID_FILTER                        0x1     /* support AXI ID filter */
 #define DDR_CAP_AXI_ID_FILTER_ENHANCED               0x3     /* support enhanced AXI ID filter */
+#define DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER   0x4     /* support AXI ID PORT CHANNEL filter */
 
 struct fsl_ddr_devtype_data {
      unsigned int quirks;    /* quirks needed for different DDR Perf core */
@@ -144,6 +154,7 @@ static const struct attribute_group ddr_perf_identifier_attr_group = {
 enum ddr_perf_filter_capabilities {
      PERF_CAP_AXI_ID_FILTER = 0,
      PERF_CAP_AXI_ID_FILTER_ENHANCED,
+     PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER,
      PERF_CAP_AXI_ID_FEAT_MAX,
 };
 
@@ -157,6 +168,8 @@ static u32 ddr_perf_filter_cap_get(struct ddr_pmu *pmu, int cap)
      case PERF_CAP_AXI_ID_FILTER_ENHANCED:
              quirks &= DDR_CAP_AXI_ID_FILTER_ENHANCED;
              return quirks == DDR_CAP_AXI_ID_FILTER_ENHANCED;
+     case PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER:
+             return !!(quirks & DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER);
      default:
              WARN(1, "unknown filter cap %d\n", cap);
      }
@@ -187,6 +200,7 @@ static ssize_t ddr_perf_filter_cap_show(struct device *dev,
 static struct attribute *ddr_perf_filter_cap_attr[] = {
      PERF_FILTER_EXT_ATTR_ENTRY(filter, PERF_CAP_AXI_ID_FILTER),
      PERF_FILTER_EXT_ATTR_ENTRY(enhanced_filter, PERF_CAP_AXI_ID_FILTER_ENHANCED),
+     PERF_FILTER_EXT_ATTR_ENTRY(super_filter, PERF_CAP_AXI_ID_PORT_CHANNEL_FILTER),
      NULL,
 };
 
Quoted 9 lines

drivers/perf/fsl_imx8_ddr_perf.c static const struct attribute_group ddr_perf_events_attr_group = { · line 290

Quoted 6 lines
drivers/perf/fsl_imx8_ddr_perf.c +2 -0
@@ -272,11 +286,15 @@ static const struct attribute_group ddr_perf_events_attr_group = {
 PMU_FORMAT_ATTR(event, "config:0-7");
 PMU_FORMAT_ATTR(axi_id, "config1:0-15");
 PMU_FORMAT_ATTR(axi_mask, "config1:16-31");
+PMU_FORMAT_ATTR(axi_port, "config2:0-2");
+PMU_FORMAT_ATTR(axi_channel, "config2:3-3");

Any specific reason to allocate from config2, rather than the upper 32 bits of config1?

No. Either way is ok for me.

Quoted 5 lines
Quoted 5 lines
drivers/perf/fsl_imx8_ddr_perf.c +0 -0
@@ -553,6 +572,26 @@ static int ddr_perf_event_add(struct perf_event *event, int flags)
              return -EOPNOTSUPP;
      }
 
Quoted 9 lines

drivers/perf/fsl_imx8_ddr_perf.c static int ddr_perf_event_add(struct perf_event *event, int flags) · line 579

Quoted 5 lines
drivers/perf/fsl_imx8_ddr_perf.c +5 -0
+     if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_PORT_CHANNEL_FILTER) {
+             if (ddr_perf_is_filtered(event)) {
+                     /* revert axi id masking(axi_mask) value */
+                     cfg1 ^= AXI_MASKING_REVERT;
+                     writel(cfg1, pmu->base + COUNTER_MASK_COMP + ((counter - 1) << 4));

Please can you explain what this "reverting" is doing? It looks like a user-visible change in behaviour to me, or are you saying that the driver currently does the wrong thing on hardware that supports the new filter?

In sys/metrics.json table as below,

"MetricExpr": "imx8_ddr0@axid\\-read\\,axi_mask\\=0x0000\\,axi_id\\=0x0065@",

We have set axi_mask to 0x0000 for most of the metics and assume that bit 0 is used for masking. In hardware register, bit 1 is used for masking axi id. So there exists a reverting operation. It also works for me to set actual axi mask value in sys/metrics.json. But, because this patch is just a supplement for filter, and previous axi filter already use a reverting operation for filter, so I did the same thing there.

Quoted 4 lines
Quoted 3 lines
drivers/perf/fsl_imx8_ddr_perf.c +2 -0
+
+                     if (cfg == 0x41) {
Quoted 10 lines
Quoted 1 line

What is this 0x41 for?

IMX8_DDR_PMU_EVENT_ATTR(axid-read, 0x41),
This 0x41 means axi read filter event.

Thanks,
Xu Yang

Quoted 2 lines

Will

Do these patches still need optimization?

Thanks,
Xu Yang