Skip to contentSkip to conversation

Enhance TLP packet decoder with field-level parsing and versioning

PATCH In review Sizhe Liu 3 participants 19 messages Sep 8 – Sep 11

Subsystems (7)
lore
Share & tools
lore

Sizhe Liu

author maintainer
#0 lore raw

v4 cover Enhance TLP packet decoder with field-level parsing and versioning

The original hisi-ptt-decoder only prints raw hex values with generic field names for DW0/DW1/DW2/DW3, without classifying TLP types or decoding DW0/DW1/DW2/DW3 fields according to the hardware-defined packet format.

This series enhances the HiSilicon PTT (PCIe Trace and Tuning) packet decoder in perf tool to provide detailed field-level parsing of TLP headers based on message type, and adds a versioning mechanism for backward compatibility both in hisi_ptt driver and perf tool.

---
Changes in v4:
- Add missing space in hisi-ptt.rst (Sashiko).
- Widen the pattern bit field in struct hisi_ptt_trace_ctrl (Sashiko).
- Add protocol defined TLP header length parsing in patch 05/08.
- Add MRd and DMRr message types parsing in patch 05/08.
- Add comment for enum hisi_ptt_pkt_msg_type in patch 05/08.
- Add DW0 and DW1 fields analysing in patch 06/08.
- Refine bit-fields parsing of DW0/DW1/DW2/DW3 based on different requests
in patch 06/08.
- Refine the description of pattern=1 in the document in patch 07/08.
- Extract the bit-field printing of v1 version into functions in
patch 08/08.
- Link to v3: https://lore.kernel.org/linux-pci/[email protected]/

Changes in v3:
- Add explicit inclusion of <stdbool.h> (Sashiko).
- Make patch 07/08 apply cleanly to mainline (Yushan).
- Pick up the reviewed-by tag (Yushan).
- Link to v2: https://lore.kernel.org/linux-pci/[email protected]/

Changes in v2:
- Split patch 01/10 and patch 02/10 from series v1 into independent patch series for backporting (Bjorn).
- Use bitwise operations instead of C bitfields for cross-platform cases (Sashiko).
- Add pattern parameter in hisi_ptt driver for layout compatibility.
- Link to v1: https://lore.kernel.org/linux-pci/[email protected]/

---
Sizhe Liu (8):
perf hisi-ptt: Abstract trace data buf and offset
perf hisi-ptt: Complete the field names for 4DW and 8DW packets perf hisi-ptt: Extract the raw data printing part
perf hisi-ptt: Merge 4DW and 8DW HEAD0 printing
perf hisi-ptt: Add parsing of supported message types and proto length perf hisi-ptt: Add field-level parsing for header DW0/DW1/DW2/DW3
hwtracing: hisi_ptt: Add pattern PMU config for trace format selection perf hisi-ptt: Pass pattern version to decoder for compatibility

 Documentation/trace/hisi-ptt.rst              |  26 +-
 drivers/hwtracing/ptt/hisi_ptt.c              |  25 +-
 drivers/hwtracing/ptt/hisi_ptt.h              |   4 +
 tools/perf/arch/arm64/util/hisi-ptt.c         |  18 +
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c   | 593 ++++++++++++++++--
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.h   | 241 ++++++-
 tools/perf/util/hisi-ptt.c                    |  51 +-
 tools/perf/util/hisi-ptt.h                    |   9 +-
 8 files changed, 872 insertions(+), 95 deletions(-)
Signature · 1 line
2.33.0
author maintainer
#1 lore raw

PATCH v4 1/8 perf hisi-ptt: Abstract trace data buf and offset

Abstract the base address, current offset, length and packet type of analysing trace data into structure hisi_ptt_pkt_buf and move the step of current offset into the corresponding functions.

---
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c   | 42 +++++++++----------
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.h   |  9 +++-
 tools/perf/util/hisi-ptt.c                    | 20 ++++-----
 3 files changed, 37 insertions(+), 34 deletions(-)
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c +21 -21
index 72a877fd7236..ef72223d3854 100644
@@ -75,16 +75,17 @@ static const char * const hisi_ptt_4dw_pkt_field_name[] = {
 	[HISI_PTT_4DW_HEAD3]	= "Header DW3",
 };
 
-static void hisi_ptt_print_pkt(const unsigned char *buf, int pos, const char *desc)
+static void hisi_ptt_print_pkt(struct hisi_ptt_pkt_buf *pkt_buf,
+			       const char *desc)
 {
 	const char *color = PERF_COLOR_BLUE;
 	uint8_t byte;
 	uint32_t dw;
 	int i;
 
-	dw = get_unaligned_le32(buf + pos);
+	dw = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
 	printf(".");
-	color_fprintf(stdout, color, "  %08x: ", pos);
+	color_fprintf(stdout, color, "  %08zx: ", pkt_buf->pos);
 	for (i = 0; i < HISI_PTT_FIELD_LENGTH; i++) {
 		byte = (dw >> (24 - i * 8)) & 0xFF;
 		color_fprintf(stdout, color, "%02x ", byte);
@@ -92,36 +93,36 @@ static void hisi_ptt_print_pkt(const unsigned char *buf, int pos, const char *de
 	for (i = 0; i < HISI_PTT_MAX_SPACE_LEN; i++)
 		color_fprintf(stdout, color, "   ");
 	color_fprintf(stdout, color, "  %s\n", desc);
+	pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
 }
 
-static int hisi_ptt_8dw_pkt_desc(const unsigned char *buf, int pos)
+static int hisi_ptt_8dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 {
 	int i;
 
 	for (i = 0; i < HISI_PTT_8DW_TYPE_MAX; i++) {
 		/* Do not show 8DW check field and reserved fields */
 		if (i == HISI_PTT_8DW_CHK_AND_RSV0 || i == HISI_PTT_8DW_RSV1) {
-			pos += HISI_PTT_FIELD_LENGTH;
+			pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
 			continue;
 		}
 
-		hisi_ptt_print_pkt(buf, pos, hisi_ptt_8dw_pkt_field_name[i]);
-		pos += HISI_PTT_FIELD_LENGTH;
+		hisi_ptt_print_pkt(pkt_buf, hisi_ptt_8dw_pkt_field_name[i]);
 	}
 
 	return hisi_ptt_pkt_size[HISI_PTT_8DW_PKT];
 }
 
-static void hisi_ptt_4dw_print_dw0(const unsigned char *buf, int pos)
+static void hisi_ptt_4dw_print_dw0(struct hisi_ptt_pkt_buf *pkt_buf)
 {
 	const char *color = PERF_COLOR_BLUE;
 	uint8_t byte;
 	uint32_t dw;
 	int i;
 
-	dw = get_unaligned_le32(buf + pos);
+	dw = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
 	printf(".");
-	color_fprintf(stdout, color, "  %08x: ", pos);
+	color_fprintf(stdout, color, "  %08zx: ", pkt_buf->pos);
 	for (i = 0; i < HISI_PTT_FIELD_LENGTH; i++) {
 		byte = (dw >> (24 - i * 8)) & 0xFF;
 		color_fprintf(stdout, color, "%02x ", byte);
@@ -139,27 +140,26 @@ static void hisi_ptt_4dw_print_dw0(const unsigned char *buf, int pos)
 		      "SO", FIELD_GET(HISI_PTT_HEAD0_4DW_SO, dw),
 		      "Length", FIELD_GET(HISI_PTT_HEAD0_4DW_LEN, dw),
 		      "Time", FIELD_GET(HISI_PTT_HEAD0_4DW_TIME, dw));
+
+	pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
 }
 
-static int hisi_ptt_4dw_pkt_desc(const unsigned char *buf, int pos)
+static int hisi_ptt_4dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 {
 	int i;
 
-	hisi_ptt_4dw_print_dw0(buf, pos);
-	pos += HISI_PTT_FIELD_LENGTH;
+	hisi_ptt_4dw_print_dw0(pkt_buf);
 
-	for (i = 0; i < HISI_PTT_4DW_TYPE_MAX; i++) {
-		hisi_ptt_print_pkt(buf, pos, hisi_ptt_4dw_pkt_field_name[i]);
-		pos += HISI_PTT_FIELD_LENGTH;
-	}
+	for (i = 0; i < HISI_PTT_4DW_TYPE_MAX; i++)
+		hisi_ptt_print_pkt(pkt_buf, hisi_ptt_4dw_pkt_field_name[i]);
 
 	return hisi_ptt_pkt_size[HISI_PTT_4DW_PKT];
 }
 
-int hisi_ptt_pkt_desc(const unsigned char *buf, int pos, enum hisi_ptt_pkt_type type)
+int hisi_ptt_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 {
-	if (type == HISI_PTT_8DW_PKT)
-		return hisi_ptt_8dw_pkt_desc(buf, pos);
+	if (pkt_buf->pkt_type == HISI_PTT_8DW_PKT)
+		return hisi_ptt_8dw_pkt_desc(pkt_buf);
 
-	return hisi_ptt_4dw_pkt_desc(buf, pos);
+	return hisi_ptt_4dw_pkt_desc(pkt_buf);
 }
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h +8 -1
index 3b349fcc24ae..6747878b030e 100644
@@ -38,6 +38,13 @@ static int hisi_ptt_pkt_size[] = {
 	[HISI_PTT_8DW_PKT]	= 32,
 };
 
-int hisi_ptt_pkt_desc(const unsigned char *buf, int pos, enum hisi_ptt_pkt_type type);
+struct hisi_ptt_pkt_buf {
+	const unsigned char *buf;
+	size_t pos;
+	size_t len;
+	enum hisi_ptt_pkt_type pkt_type;
+};
+
+int hisi_ptt_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf);
 
 #endif
tools/perf/util/hisi-ptt.c +8 -12
index e73c57f9e8a4..ea659947c27f 100644
@@ -57,22 +57,18 @@ static void hisi_ptt_dump(struct hisi_ptt *ptt __maybe_unused,
 			  unsigned char *buf, size_t len)
 {
 	const char *color = PERF_COLOR_BLUE;
-	enum hisi_ptt_pkt_type type;
-	size_t pos = 0;
-	int pkt_len;
+	struct hisi_ptt_pkt_buf pkt_buf;
 
-	type = hisi_ptt_check_packet_type(buf, len);
-	len = round_down(len, hisi_ptt_pkt_size[type]);
+	pkt_buf.buf = buf;
+	pkt_buf.pos = 0;
+	pkt_buf.pkt_type = hisi_ptt_check_packet_type(buf, len);
+	pkt_buf.len = round_down(len, hisi_ptt_pkt_size[pkt_buf.pkt_type]);
 	color_fprintf(stdout, color, ". ... HISI PTT data: size %zu bytes\n",
-		      len);
+		      pkt_buf.len);
 
-	while (len > 0) {
-		pkt_len = hisi_ptt_pkt_desc(buf, pos, type);
-		if (!pkt_len)
+	while (pkt_buf.pos < pkt_buf.len) {
+		if (!hisi_ptt_pkt_desc(&pkt_buf))
 			color_fprintf(stdout, color, " Bad packet!\n");
-
-		pos += pkt_len;
-		len -= pkt_len;
 	}
 }
 
Signature · 1 line
2.33.0
#2 lore raw

Re: [PATCH v4 1/8] perf hisi-ptt: Abstract trace data buf and offset

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

Abstract the base address, current offset, length and packet type of analysing trace data into structure hisi_ptt_pkt_buf and move the step of current offset into the corresponding functions.

Sashiko has reviewed this patch and found no issues. It looks great!

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

PATCH v4 2/8 perf hisi-ptt: Complete the field names for 4DW and 8DW packets

In reply to Sizhe Liu

Add the missing HISI_PTT_4DW_HEAD0 entry to the 4DW field name table and add the HISI_PTT_8DW_CHK_AND_RSV0/HISI_PTT_8DW_RSV1 entries to the 8DW field name table so that all DW indices have corresponding names.

---
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c   | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c +12 -8
index ef72223d3854..766665414ad8 100644
@@ -54,6 +54,7 @@ enum hisi_ptt_8dw_pkt_field_type {
 };
 
 enum hisi_ptt_4dw_pkt_field_type {
+	HISI_PTT_4DW_HEAD0,
 	HISI_PTT_4DW_HEAD1,
 	HISI_PTT_4DW_HEAD2,
 	HISI_PTT_4DW_HEAD3,
@@ -61,15 +62,18 @@ enum hisi_ptt_4dw_pkt_field_type {
 };
 
 static const char * const hisi_ptt_8dw_pkt_field_name[] = {
-	[HISI_PTT_8DW_PREFIX]	= "Prefix",
-	[HISI_PTT_8DW_HEAD0]	= "Header DW0",
-	[HISI_PTT_8DW_HEAD1]	= "Header DW1",
-	[HISI_PTT_8DW_HEAD2]	= "Header DW2",
-	[HISI_PTT_8DW_HEAD3]	= "Header DW3",
-	[HISI_PTT_8DW_TIME]	= "Time"
+	[HISI_PTT_8DW_CHK_AND_RSV0]	= "CHK & RSV0",
+	[HISI_PTT_8DW_PREFIX]		= "Prefix",
+	[HISI_PTT_8DW_HEAD0]		= "Header DW0",
+	[HISI_PTT_8DW_HEAD1]		= "Header DW1",
+	[HISI_PTT_8DW_HEAD2]		= "Header DW2",
+	[HISI_PTT_8DW_HEAD3]		= "Header DW3",
+	[HISI_PTT_8DW_RSV1]		= "RSV1",
+	[HISI_PTT_8DW_TIME]		= "Time"
 };
 
 static const char * const hisi_ptt_4dw_pkt_field_name[] = {
+	[HISI_PTT_4DW_HEAD0]	= "Header DW0",
 	[HISI_PTT_4DW_HEAD1]	= "Header DW1",
 	[HISI_PTT_4DW_HEAD2]	= "Header DW2",
 	[HISI_PTT_4DW_HEAD3]	= "Header DW3",
@@ -100,7 +104,7 @@ static int hisi_ptt_8dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 {
 	int i;
 
-	for (i = 0; i < HISI_PTT_8DW_TYPE_MAX; i++) {
+	for (i = HISI_PTT_8DW_CHK_AND_RSV0; i < HISI_PTT_8DW_TYPE_MAX; i++) {
 		/* Do not show 8DW check field and reserved fields */
 		if (i == HISI_PTT_8DW_CHK_AND_RSV0 || i == HISI_PTT_8DW_RSV1) {
 			pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
@@ -150,7 +154,7 @@ static int hisi_ptt_4dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 
 	hisi_ptt_4dw_print_dw0(pkt_buf);
 
-	for (i = 0; i < HISI_PTT_4DW_TYPE_MAX; i++)
+	for (i = HISI_PTT_4DW_HEAD1; i < HISI_PTT_4DW_TYPE_MAX; i++)
 		hisi_ptt_print_pkt(pkt_buf, hisi_ptt_4dw_pkt_field_name[i]);
 
 	return hisi_ptt_pkt_size[HISI_PTT_4DW_PKT];
Signature · 1 line
2.33.0
#4 lore raw

Re: [PATCH v4 2/8] perf hisi-ptt: Complete the field names for 4DW and 8DW packets

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Add the missing HISI_PTT_4DW_HEAD0 entry to the 4DW field name table and add the HISI_PTT_8DW_CHK_AND_RSV0/HISI_PTT_8DW_RSV1 entries to the 8DW field name table so that all DW indices have corresponding names.

Sashiko has reviewed this patch and found no issues. It looks great!

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

PATCH v4 3/8 perf hisi-ptt: Extract the raw data printing part

In reply to Sizhe Liu

Extract the raw data printing part of the TLP header into hisi_ptt_print_raw_record() for reuse by subsequent patches that add field-level parsing of individual DW headers.

---
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c   | 31 +++++++++----------
 1 file changed, 15 insertions(+), 16 deletions(-)
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c +15 -16
index 766665414ad8..23ae99f33c9f 100644
@@ -79,23 +79,31 @@ static const char * const hisi_ptt_4dw_pkt_field_name[] = {
 	[HISI_PTT_4DW_HEAD3]	= "Header DW3",
 };
 
-static void hisi_ptt_print_pkt(struct hisi_ptt_pkt_buf *pkt_buf,
-			       const char *desc)
+static void hisi_ptt_print_raw_record(size_t offset, uint32_t value)
 {
 	const char *color = PERF_COLOR_BLUE;
 	uint8_t byte;
-	uint32_t dw;
 	int i;
 
-	dw = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
 	printf(".");
-	color_fprintf(stdout, color, "  %08zx: ", pkt_buf->pos);
+	color_fprintf(stdout, color, "  %08zx: ", offset);
 	for (i = 0; i < HISI_PTT_FIELD_LENGTH; i++) {
-		byte = (dw >> (24 - i * 8)) & 0xFF;
+		byte = (value >> (24 - i * 8)) & 0xFF;
 		color_fprintf(stdout, color, "%02x ", byte);
 	}
 	for (i = 0; i < HISI_PTT_MAX_SPACE_LEN; i++)
 		color_fprintf(stdout, color, "   ");
+}
+
+static void hisi_ptt_print_pkt(struct hisi_ptt_pkt_buf *pkt_buf,
+			       const char *desc)
+{
+	const char *color = PERF_COLOR_BLUE;
+	uint32_t value;
+
+	value = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
+	hisi_ptt_print_raw_record(pkt_buf->pos, value);
+
 	color_fprintf(stdout, color, "  %s\n", desc);
 	pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
 }
@@ -120,19 +128,10 @@ static int hisi_ptt_8dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 static void hisi_ptt_4dw_print_dw0(struct hisi_ptt_pkt_buf *pkt_buf)
 {
 	const char *color = PERF_COLOR_BLUE;
-	uint8_t byte;
 	uint32_t dw;
-	int i;
 
 	dw = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
-	printf(".");
-	color_fprintf(stdout, color, "  %08zx: ", pkt_buf->pos);
-	for (i = 0; i < HISI_PTT_FIELD_LENGTH; i++) {
-		byte = (dw >> (24 - i * 8)) & 0xFF;
-		color_fprintf(stdout, color, "%02x ", byte);
-	}
-	for (i = 0; i < HISI_PTT_MAX_SPACE_LEN; i++)
-		color_fprintf(stdout, color, "   ");
+	hisi_ptt_print_raw_record(pkt_buf->pos, dw);
 
 	color_fprintf(stdout, color,
 		      "  %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n",
Signature · 1 line
2.33.0
#6 lore raw

Re: [PATCH v4 3/8] perf hisi-ptt: Extract the raw data printing part

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

Extract the raw data printing part of the TLP header into hisi_ptt_print_raw_record() for reuse by subsequent patches that add field-level parsing of individual DW headers.

Sashiko has reviewed this patch and found no issues. It looks great!

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

PATCH v4 4/8 perf hisi-ptt: Merge 4DW and 8DW HEAD0 printing

In reply to Sizhe Liu

Merge the printing of HEAD0 for both 4DW and 8DW TLP headers into hisi_ptt_print_head0(). This unifies the entry point and makes it easier to add HEAD1/HEAD2/HEAD3 field parsing in subsequent patches.

---
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c   | 56 +++++++++++--------
 1 file changed, 33 insertions(+), 23 deletions(-)
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c +33 -23
index 23ae99f33c9f..00bd9309df68 100644
@@ -108,6 +108,33 @@ static void hisi_ptt_print_pkt(struct hisi_ptt_pkt_buf *pkt_buf,
 	pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
 }
 
+static void hisi_ptt_print_head0(struct hisi_ptt_pkt_buf *pkt_buf)
+{
+	const char *color = PERF_COLOR_BLUE;
+	uint32_t dw;
+
+	dw = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
+	hisi_ptt_print_raw_record(pkt_buf->pos, dw);
+
+	if (pkt_buf->pkt_type == HISI_PTT_4DW_PKT)
+		color_fprintf(stdout, color,
+			      "  %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n",
+			      "Format",
+			      FIELD_GET(HISI_PTT_HEAD0_4DW_FORMAT, dw),
+			      "Type", FIELD_GET(HISI_PTT_HEAD0_4DW_TYPE, dw),
+			      "T9", FIELD_GET(HISI_PTT_HEAD0_4DW_T9, dw),
+			      "T8", FIELD_GET(HISI_PTT_HEAD0_4DW_T8, dw),
+			      "TH", FIELD_GET(HISI_PTT_HEAD0_4DW_TH, dw),
+			      "SO", FIELD_GET(HISI_PTT_HEAD0_4DW_SO, dw),
+			      "Length", FIELD_GET(HISI_PTT_HEAD0_4DW_LEN, dw),
+			      "Time", FIELD_GET(HISI_PTT_HEAD0_4DW_TIME, dw));
+	else
+		color_fprintf(stdout, color, "  %s\n",
+			      hisi_ptt_8dw_pkt_field_name[HISI_PTT_8DW_HEAD0]);
+
+	pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
+}
+
 static int hisi_ptt_8dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 {
 	int i;
@@ -119,39 +146,22 @@ static int hisi_ptt_8dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 			continue;
 		}
 
+		if (i == HISI_PTT_8DW_HEAD0) {
+			hisi_ptt_print_head0(pkt_buf);
+			continue;
+		}
+
 		hisi_ptt_print_pkt(pkt_buf, hisi_ptt_8dw_pkt_field_name[i]);
 	}
 
 	return hisi_ptt_pkt_size[HISI_PTT_8DW_PKT];
 }
 
-static void hisi_ptt_4dw_print_dw0(struct hisi_ptt_pkt_buf *pkt_buf)
-{
-	const char *color = PERF_COLOR_BLUE;
-	uint32_t dw;
-
-	dw = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
-	hisi_ptt_print_raw_record(pkt_buf->pos, dw);
-
-	color_fprintf(stdout, color,
-		      "  %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n",
-		      "Format", FIELD_GET(HISI_PTT_HEAD0_4DW_FORMAT, dw),
-		      "Type", FIELD_GET(HISI_PTT_HEAD0_4DW_TYPE, dw),
-		      "T9", FIELD_GET(HISI_PTT_HEAD0_4DW_T9, dw),
-		      "T8", FIELD_GET(HISI_PTT_HEAD0_4DW_T8, dw),
-		      "TH", FIELD_GET(HISI_PTT_HEAD0_4DW_TH, dw),
-		      "SO", FIELD_GET(HISI_PTT_HEAD0_4DW_SO, dw),
-		      "Length", FIELD_GET(HISI_PTT_HEAD0_4DW_LEN, dw),
-		      "Time", FIELD_GET(HISI_PTT_HEAD0_4DW_TIME, dw));
-
-	pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
-}
-
 static int hisi_ptt_4dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 {
 	int i;
 
-	hisi_ptt_4dw_print_dw0(pkt_buf);
+	hisi_ptt_print_head0(pkt_buf);
 
 	for (i = HISI_PTT_4DW_HEAD1; i < HISI_PTT_4DW_TYPE_MAX; i++)
 		hisi_ptt_print_pkt(pkt_buf, hisi_ptt_4dw_pkt_field_name[i]);
Signature · 1 line
2.33.0
#8 lore raw

Re: [PATCH v4 4/8] perf hisi-ptt: Merge 4DW and 8DW HEAD0 printing

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

Merge the printing of HEAD0 for both 4DW and 8DW TLP headers into hisi_ptt_print_head0(). This unifies the entry point and makes it easier to add HEAD1/HEAD2/HEAD3 field parsing in subsequent patches.

Sashiko has reviewed this patch and found no issues. It looks great!

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

PATCH v4 5/8 perf hisi-ptt: Add parsing of supported message types and proto length

In reply to Sizhe Liu

Classify TLP messages by Header DW0 Format field and Type field for both 4DW and 8DW formats, according to PCIe r6.4 sec 2.2.1.1 & 2.2.1.2.

Parsing packets into:
- MRd (Non-posted Memory Read request)
- MWr (Posted Memory Write request)
- DMWr (Posted Deferrable Memory write request)
- Msg (Posted Message request)
- Atom (Non-Posted AtomicOP request)

- IO   (Non-Posted IO request)
- CFG  (Non-Posted Configuration request)
- CPL  (Completion request)

The parsed message type is stored in pkt_buf->pkt_msg_type and will be used by subsequent patches to select the correct field layout for DW1, DW2 and DW3 printing.

Classify protocol defined header length by Format field, according to PCIe r6.4 sec 2.2.1.1.

---
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c   | 89 +++++++++++++++++++
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.h   | 40 ++++++++-
 tools/perf/util/hisi-ptt.c                    |  1 +
 3 files changed, 126 insertions(+), 4 deletions(-)
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c +89 -0
index 00bd9309df68..c9515676ba5c 100644
@@ -79,6 +79,94 @@ static const char * const hisi_ptt_4dw_pkt_field_name[] = {
 	[HISI_PTT_4DW_HEAD3]	= "Header DW3",
 };
 
+/* TLP message parsers below according to PCIe r6.4 sec 2.2.1.1 & 2.2.1.2 */
+static bool hisi_ptt_is_mrd_tlp(uint32_t format, uint32_t type)
+{
+	return (format == 0 || format == 0x1) && (type == 0);
+}
+
+static bool hisi_ptt_is_mwr_tlp(uint32_t format, uint32_t type)
+{
+	return (format == 0x2 || format == 0x3) && (type == 0);
+}
+
+static bool hisi_ptt_is_dmwr_tlp(uint32_t format, uint32_t type)
+{
+	return (format == 0x2 || format == 0x3) && (type == 0x1b);
+}
+
+static bool hisi_ptt_is_msg_tlp(uint32_t format, uint32_t type)
+{
+	return (format == 0x1 || format == 0x3) && ((type & 0x18) == 0x10);
+}
+
+static bool hisi_ptt_is_io_tlp(uint32_t format, uint32_t type)
+{
+	return (format == 0 || format == 0x2) && (type == 0x2);
+}
+
+static bool hisi_ptt_is_atomic_tlp(uint32_t format, uint32_t type)
+{
+	return (format == 0x2 || format == 0x3) &&
+	       (type == 0xc || type == 0xd || type == 0xe);
+}
+
+static bool hisi_ptt_is_cfg_tlp(uint32_t format, uint32_t type)
+{
+	return (format == 0 || format == 0x2) && (type == 0x4 || type == 0x5);
+}
+
+static bool hisi_ptt_is_cpl_tlp(uint32_t format, uint32_t type)
+{
+	return (format == 0  || format == 0x2) && (type == 0xa || type == 0xb);
+}
+
+static int hisi_ptt_parse_pkt_msg_type(uint32_t format, uint32_t type)
+{
+	if (hisi_ptt_is_mrd_tlp(format, type))
+		return HISI_PTT_PKT_TYPE_MRD;
+	else if (hisi_ptt_is_mwr_tlp(format, type))
+		return HISI_PTT_PKT_TYPE_MWR;
+	else if (hisi_ptt_is_dmwr_tlp(format, type))
+		return HISI_PTT_PKT_TYPE_DMWR;
+	else if (hisi_ptt_is_msg_tlp(format, type))
+		return HISI_PTT_PKT_TYPE_MSG;
+	else if (hisi_ptt_is_atomic_tlp(format, type))
+		return HISI_PTT_PKT_TYPE_ATOM;
+	else if (hisi_ptt_is_io_tlp(format, type))
+		return HISI_PTT_PKT_TYPE_IO;
+	else if (hisi_ptt_is_cfg_tlp(format, type))
+		return HISI_PTT_PKT_TYPE_CFG;
+	else if (hisi_ptt_is_cpl_tlp(format, type))
+		return HISI_PTT_PKT_TYPE_CPL;
+
+	return HISI_PTT_PKT_TYPE_UNKNOWN;
+}
+
+static int hisi_ptt_parse_pkt_header_proto_len(uint32_t format)
+{
+	if (format & 0x1)
+		return HISI_PTT_4DW_HEADER_PROTO_LEN;
+
+	return HISI_PTT_3DW_HEADER_PROTO_LEN;
+}
+
+static void hisi_ptt_parse_pkt_info(struct hisi_ptt_pkt_buf *pkt_buf,
+				    uint32_t dw)
+{
+	uint32_t format, type;
+
+	format = (pkt_buf->pkt_type == HISI_PTT_4DW_PKT) ?
+		  FIELD_GET(HISI_PTT_HEAD0_4DW_FORMAT, dw) :
+		  FIELD_GET(HISI_PTT_HEAD0_8DW_FORMAT, dw);
+	type = (pkt_buf->pkt_type == HISI_PTT_4DW_PKT) ?
+		FIELD_GET(HISI_PTT_HEAD0_4DW_TYPE, dw) :
+		FIELD_GET(HISI_PTT_HEAD0_8DW_TYPE, dw);
+
+	pkt_buf->pkt_msg_type = hisi_ptt_parse_pkt_msg_type(format, type);
+	pkt_buf->proto_len = hisi_ptt_parse_pkt_header_proto_len(format);
+}
+
 static void hisi_ptt_print_raw_record(size_t offset, uint32_t value)
 {
 	const char *color = PERF_COLOR_BLUE;
@@ -114,6 +202,7 @@ static void hisi_ptt_print_head0(struct hisi_ptt_pkt_buf *pkt_buf)
 	uint32_t dw;
 
 	dw = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
+	hisi_ptt_parse_pkt_info(pkt_buf, dw);
 	hisi_ptt_print_raw_record(pkt_buf->pos, dw);
 
 	if (pkt_buf->pkt_type == HISI_PTT_4DW_PKT)
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h +36 -4
index 6747878b030e..f02ba29dfe00 100644
@@ -7,15 +7,18 @@
 #ifndef INCLUDE__HISI_PTT_PKT_DECODER_H__
 #define INCLUDE__HISI_PTT_PKT_DECODER_H__
 
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <linux/bits.h>
 #include <linux/bitfield.h>
 
-#define HISI_PTT_8DW_CHECK_MASK		GENMASK(31, 11)
-#define HISI_PTT_IS_8DW_PKT		GENMASK(31, 11)
-#define HISI_PTT_MAX_SPACE_LEN		10
-#define HISI_PTT_FIELD_LENGTH		4
+#define HISI_PTT_8DW_CHECK_MASK			GENMASK_U32(31, 11)
+#define HISI_PTT_IS_8DW_PKT			GENMASK_U32(31, 11)
+#define HISI_PTT_MAX_SPACE_LEN			10
+#define HISI_PTT_FIELD_LENGTH			4
+#define HISI_PTT_3DW_HEADER_PROTO_LEN		3
+#define HISI_PTT_4DW_HEADER_PROTO_LEN		4
 
 /* Header DW0 fields for 4DW format */
 #define HISI_PTT_HEAD0_4DW_TIME		GENMASK_U32(10, 0)
@@ -27,6 +30,10 @@
 #define HISI_PTT_HEAD0_4DW_TYPE		GENMASK_U32(29, 25)
 #define HISI_PTT_HEAD0_4DW_FORMAT	GENMASK_U32(31, 30)
 
+/* Header DW0 fields for 8DW format */
+#define HISI_PTT_HEAD0_8DW_TYPE		GENMASK_U32(28, 24)
+#define HISI_PTT_HEAD0_8DW_FORMAT	GENMASK_U32(31, 29)
+
 enum hisi_ptt_pkt_type {
 	HISI_PTT_4DW_PKT,
 	HISI_PTT_8DW_PKT,
@@ -38,11 +45,36 @@ static int hisi_ptt_pkt_size[] = {
 	[HISI_PTT_8DW_PKT]	= 32,
 };
 
+enum hisi_ptt_pkt_msg_type {
+	/* Types do not support analysis */
+	HISI_PTT_PKT_TYPE_UNKNOWN,
+	/* NP-(Memory Read requset: MRd) */
+	HISI_PTT_PKT_TYPE_MRD,
+	/* P-(Memory write request: MWr) */
+	HISI_PTT_PKT_TYPE_MWR,
+	/* P-(Deferrable Memory write request: DMWr) */
+	HISI_PTT_PKT_TYPE_DMWR,
+	/* P-(Message request: Msg, MsgD) */
+	HISI_PTT_PKT_TYPE_MSG,
+	/* NP-(AtomicOP request: FetchAdd, Swap, CAS) */
+	HISI_PTT_PKT_TYPE_ATOM,
+	/* NP-(I/O request: IORd, IOWr) */
+	HISI_PTT_PKT_TYPE_IO,
+	/* NP-(Configuration request: CfgRd0, CfgWr0, CfgRd1, CfgWr1) */
+	HISI_PTT_PKT_TYPE_CFG,
+	/* CPL-(Completion: Cpl, CplD) */
+	HISI_PTT_PKT_TYPE_CPL,
+	/* Type max in enumeration*/
+	HISI_PTT_PKT_TYPE_MAX
+};
+
 struct hisi_ptt_pkt_buf {
 	const unsigned char *buf;
 	size_t pos;
 	size_t len;
 	enum hisi_ptt_pkt_type pkt_type;
+	enum hisi_ptt_pkt_msg_type pkt_msg_type;
+	size_t proto_len;
 };
 
 int hisi_ptt_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf);
tools/perf/util/hisi-ptt.c +1 -0
index ea659947c27f..78817ae7a8ea 100644
@@ -63,6 +63,7 @@ static void hisi_ptt_dump(struct hisi_ptt *ptt __maybe_unused,
 	pkt_buf.pos = 0;
 	pkt_buf.pkt_type = hisi_ptt_check_packet_type(buf, len);
 	pkt_buf.len = round_down(len, hisi_ptt_pkt_size[pkt_buf.pkt_type]);
+	pkt_buf.pkt_msg_type = HISI_PTT_PKT_TYPE_UNKNOWN;
 	color_fprintf(stdout, color, ". ... HISI PTT data: size %zu bytes\n",
 		      pkt_buf.len);
 
Signature · 1 line
2.33.0
#10 lore raw

Re: [PATCH v4 5/8] perf hisi-ptt: Add parsing of supported message types and proto length

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 17 lines

Classify TLP messages by Header DW0 Format field and Type field for both 4DW and 8DW formats, according to PCIe r6.4 sec 2.2.1.1 & 2.2.1.2.

Parsing packets into:
- MRd (Non-posted Memory Read request)
- MWr (Posted Memory Write request)
- DMWr (Posted Deferrable Memory write request)
- Msg (Posted Message request)
- Atom (Non-Posted AtomicOP request)

- IO   (Non-Posted IO request)
- CFG  (Non-Posted Configuration request)
- CPL  (Completion request)

The parsed message type is stored in pkt_buf->pkt_msg_type and will be used by subsequent patches to select the correct field layout for DW1, DW2 and DW3 printing.

Quoted 5 lines

Classify protocol defined header length by Format field, according to PCIe r6.4 sec 2.2.1.1.

Sashiko has reviewed this patch and found no issues. It looks great!

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

PATCH v4 6/8 perf hisi-ptt: Add field-level parsing for header DW0/DW1/DW2/DW3

In reply to Sizhe Liu

Add field-level parsing of Header DW0, DW1, DW2 and DW3 of the TLP, separating the layout for different requests. The message type parsed in the previous patch is used to select the corresponding field layout.

HiSilicon PCIe trace device hardware is responsible for packet collection, parsing, extraction and fills the corresponding fields with the required positions. The packet decoder software will perform the parsing and printing of fields filled by hardware.

---
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c   | 386 +++++++++++++++++-
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.h   | 194 ++++++++-
 2 files changed, 545 insertions(+), 35 deletions(-)
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c +364 -22
index c9515676ba5c..482a50c2e9f5 100644
@@ -196,9 +196,42 @@ static void hisi_ptt_print_pkt(struct hisi_ptt_pkt_buf *pkt_buf,
 	pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
 }
 
+static void hisi_ptt_print_head0_4dw_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n",
+		      "Format", FIELD_GET(HISI_PTT_HEAD0_4DW_FORMAT, dw),
+		      "Type", FIELD_GET(HISI_PTT_HEAD0_4DW_TYPE, dw),
+		      "T9", FIELD_GET(HISI_PTT_HEAD0_4DW_T9, dw),
+		      "T8", FIELD_GET(HISI_PTT_HEAD0_4DW_T8, dw),
+		      "TH", FIELD_GET(HISI_PTT_HEAD0_4DW_TH, dw),
+		      "SO", FIELD_GET(HISI_PTT_HEAD0_4DW_SO, dw),
+		      "Length", FIELD_GET(HISI_PTT_HEAD0_4DW_LEN, dw),
+		      "Time", FIELD_GET(HISI_PTT_HEAD0_4DW_TIME, dw));
+}
+
+static void hisi_ptt_print_head0_8dw_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n",
+		      "Format",
+		      FIELD_GET(HISI_PTT_HEAD0_8DW_FORMAT, dw),
+		      "Type", FIELD_GET(HISI_PTT_HEAD0_8DW_TYPE, dw),
+		      "T9", FIELD_GET(HISI_PTT_HEAD0_8DW_T9, dw),
+		      "TC", FIELD_GET(HISI_PTT_HEAD0_8DW_TC, dw),
+		      "T8", FIELD_GET(HISI_PTT_HEAD0_8DW_T8, dw),
+		      "A2", FIELD_GET(HISI_PTT_HEAD0_8DW_A2, dw),
+		      "LN", FIELD_GET(HISI_PTT_HEAD0_8DW_LN, dw),
+		      "TH", FIELD_GET(HISI_PTT_HEAD0_8DW_TH, dw),
+		      "TD", FIELD_GET(HISI_PTT_HEAD0_8DW_TD, dw),
+		      "EP", FIELD_GET(HISI_PTT_HEAD0_8DW_EP, dw),
+		      "Attr<1:0>", FIELD_GET(HISI_PTT_HEAD0_8DW_ATTR_1_0, dw),
+		      "AT", FIELD_GET(HISI_PTT_HEAD0_8DW_AT, dw),
+		      "Length", FIELD_GET(HISI_PTT_HEAD0_8DW_LEN, dw));
+}
+
 static void hisi_ptt_print_head0(struct hisi_ptt_pkt_buf *pkt_buf)
 {
-	const char *color = PERF_COLOR_BLUE;
 	uint32_t dw;
 
 	dw = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
@@ -206,24 +239,323 @@ static void hisi_ptt_print_head0(struct hisi_ptt_pkt_buf *pkt_buf)
 	hisi_ptt_print_raw_record(pkt_buf->pos, dw);
 
 	if (pkt_buf->pkt_type == HISI_PTT_4DW_PKT)
-		color_fprintf(stdout, color,
-			      "  %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n",
-			      "Format",
-			      FIELD_GET(HISI_PTT_HEAD0_4DW_FORMAT, dw),
-			      "Type", FIELD_GET(HISI_PTT_HEAD0_4DW_TYPE, dw),
-			      "T9", FIELD_GET(HISI_PTT_HEAD0_4DW_T9, dw),
-			      "T8", FIELD_GET(HISI_PTT_HEAD0_4DW_T8, dw),
-			      "TH", FIELD_GET(HISI_PTT_HEAD0_4DW_TH, dw),
-			      "SO", FIELD_GET(HISI_PTT_HEAD0_4DW_SO, dw),
-			      "Length", FIELD_GET(HISI_PTT_HEAD0_4DW_LEN, dw),
-			      "Time", FIELD_GET(HISI_PTT_HEAD0_4DW_TIME, dw));
+		hisi_ptt_print_head0_4dw_fields(dw);
+	else if (pkt_buf->pkt_type == HISI_PTT_8DW_PKT)
+		hisi_ptt_print_head0_8dw_fields(dw);
 	else
-		color_fprintf(stdout, color, "  %s\n",
+		color_fprintf(stdout, PERF_COLOR_BLUE, "  %s\n",
 			      hisi_ptt_8dw_pkt_field_name[HISI_PTT_8DW_HEAD0]);
 
 	pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
 }
 
+static void hisi_ptt_print_head1_ar64_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x\n",
+		      "Requester ID", FIELD_GET(HISI_PTT_HEAD1_AR64_REQ_ID, dw),
+		      "Tag<7:0>", FIELD_GET(HISI_PTT_HEAD1_AR64_TAG_7_0, dw),
+		      "Last DW BE",
+		      FIELD_GET(HISI_PTT_HEAD1_AR64_LAST_DW_BE, dw),
+		      "First DW BE",
+		      FIELD_GET(HISI_PTT_HEAD1_AR64_FIRST_DW_BE, dw));
+}
+
+static void hisi_ptt_print_head1_ar32_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x\n",
+		      "Requester ID", FIELD_GET(HISI_PTT_HEAD1_AR32_REQ_ID, dw),
+		      "Tag<7:0>", FIELD_GET(HISI_PTT_HEAD1_AR32_TAG_7_0, dw),
+		      "Last DW BE",
+		      FIELD_GET(HISI_PTT_HEAD1_AR32_LAST_DW_BE, dw),
+		      "First DW BE",
+		      FIELD_GET(HISI_PTT_HEAD1_AR32_FIRST_DW_BE, dw));
+}
+
+static void hisi_ptt_print_head1_cfg_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x\n",
+		      "Requester ID", FIELD_GET(HISI_PTT_HEAD1_CFG_REQ_ID, dw),
+		      "Tag<7:0>", FIELD_GET(HISI_PTT_HEAD1_CFG_TAG_7_0, dw),
+		      "Last DW BE",
+		      FIELD_GET(HISI_PTT_HEAD1_CFG_LAST_DW_BE, dw),
+		      "First DW BE",
+		      FIELD_GET(HISI_PTT_HEAD1_CFG_FIRST_DW_BE, dw));
+}
+
+static void hisi_ptt_print_head1_cpl_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x\n",
+		      "Completer ID", FIELD_GET(HISI_PTT_HEAD1_CPL_COM_ID, dw),
+		      "Cpl Status", FIELD_GET(HISI_PTT_HEAD1_CPL_STA, dw),
+		      "BCM", FIELD_GET(HISI_PTT_HEAD1_CPL_BCM, dw),
+		      "Byte Count", FIELD_GET(HISI_PTT_HEAD1_CPL_BYTE_CNT, dw));
+}
+
+static void hisi_ptt_print_head1_msg_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x\n",
+		      "Requester ID", FIELD_GET(HISI_PTT_HEAD1_MSG_REQ_ID, dw),
+		      "Tag<7:0>", FIELD_GET(HISI_PTT_HEAD1_MSG_TAG_7_0, dw),
+		      "Message Code", FIELD_GET(HISI_PTT_HEAD1_MSG_CODE, dw));
+}
+
+static void hisi_ptt_print_head1(struct hisi_ptt_pkt_buf *pkt_buf)
+{
+	uint32_t dw;
+
+	dw = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
+	hisi_ptt_print_raw_record(pkt_buf->pos, dw);
+
+	switch (pkt_buf->pkt_msg_type) {
+	case HISI_PTT_PKT_TYPE_MRD:
+	case HISI_PTT_PKT_TYPE_MWR:
+	case HISI_PTT_PKT_TYPE_DMWR:
+	case HISI_PTT_PKT_TYPE_ATOM:
+	case HISI_PTT_PKT_TYPE_IO:
+		if (pkt_buf->proto_len == HISI_PTT_4DW_HEADER_PROTO_LEN)
+			hisi_ptt_print_head1_ar64_fields(dw);
+		else
+			hisi_ptt_print_head1_ar32_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_CFG:
+		hisi_ptt_print_head1_cfg_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_CPL:
+		hisi_ptt_print_head1_cpl_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_MSG:
+		hisi_ptt_print_head1_msg_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_UNKNOWN:
+	case HISI_PTT_PKT_TYPE_MAX:
+	default:
+		color_fprintf(stdout, PERF_COLOR_BLUE, "  %s\n",
+			      pkt_buf->pkt_type == HISI_PTT_4DW_PKT ?
+			      hisi_ptt_4dw_pkt_field_name[HISI_PTT_4DW_HEAD1] :
+			      hisi_ptt_8dw_pkt_field_name[HISI_PTT_8DW_HEAD1]);
+		break;
+	}
+
+	pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
+}
+
+static void hisi_ptt_print_head2_ar64_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n",
+		      "RSV2", FIELD_GET(HISI_PTT_HEAD2_AR64_RSV2, dw),
+		      "Request Segment",
+		      FIELD_GET(HISI_PTT_HEAD2_AR64_REQ_SEG, dw),
+		      "RSV1", FIELD_GET(HISI_PTT_HEAD2_AR64_RSV1, dw),
+		      "TV", FIELD_GET(HISI_PTT_HEAD2_AR64_TV, dw),
+		      "T", FIELD_GET(HISI_PTT_HEAD2_AR64_T, dw),
+		      "Tag<13:10>",
+		      FIELD_GET(HISI_PTT_HEAD2_AR64_TAG_13_10, dw),
+		      "Addr<47:32>",
+		      FIELD_GET(HISI_PTT_HEAD2_AR64_ADDR_47_32, dw));
+}
+
+static void hisi_ptt_print_head2_ar32_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x\n",
+		      "Addr<31:2>",
+		      FIELD_GET(HISI_PTT_HEAD2_AR32_ADDR_31_2, dw),
+		      "PH<1:0>", FIELD_GET(HISI_PTT_HEAD2_AR32_PH_1_0, dw));
+}
+
+static void hisi_ptt_print_head2_io_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x\n",
+		      "Addr<31:2>",
+		      FIELD_GET(HISI_PTT_HEAD2_AR32_ADDR_31_2, dw),
+		      "Reserved", FIELD_GET(HISI_PTT_HEAD2_AR32_IO_RSV, dw));
+}
+
+static void hisi_ptt_print_head2_cfg_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x %s %x\n",
+		      "Destination ID",
+		      FIELD_GET(HISI_PTT_HEAD2_CFG_DST_ID, dw),
+		      "RSV2", FIELD_GET(HISI_PTT_HEAD2_CFG_RSV2, dw),
+		      "Ext Reg Num",
+		      FIELD_GET(HISI_PTT_HEAD2_CFG_REG_NUM_EXT, dw),
+		      "Register Number",
+		      FIELD_GET(HISI_PTT_HEAD2_CFG_REG_NUM, dw),
+		      "RSV1", FIELD_GET(HISI_PTT_HEAD2_CFG_RSV1, dw));
+}
+
+static void hisi_ptt_print_head2_cpl_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x\n",
+		      "Requester ID", FIELD_GET(HISI_PTT_HEAD2_CPL_REQ_ID, dw),
+		      "Tag<7:0>", FIELD_GET(HISI_PTT_HEAD2_CPL_TAG_7_0, dw),
+		      "Reserved", FIELD_GET(HISI_PTT_HEAD2_CPL_RSV, dw),
+		      "Lower Address",
+		      FIELD_GET(HISI_PTT_HEAD2_CPL_LO_ADDR, dw));
+}
+
+static void hisi_ptt_print_head2(struct hisi_ptt_pkt_buf *pkt_buf)
+{
+	uint32_t dw;
+
+	dw = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
+	hisi_ptt_print_raw_record(pkt_buf->pos, dw);
+
+	switch (pkt_buf->pkt_msg_type) {
+	case HISI_PTT_PKT_TYPE_MRD:
+	case HISI_PTT_PKT_TYPE_MWR:
+	case HISI_PTT_PKT_TYPE_DMWR:
+	case HISI_PTT_PKT_TYPE_ATOM:
+		if (pkt_buf->proto_len == HISI_PTT_4DW_HEADER_PROTO_LEN)
+			hisi_ptt_print_head2_ar64_fields(dw);
+		else
+			hisi_ptt_print_head2_ar32_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_IO:
+		hisi_ptt_print_head2_io_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_CFG:
+		hisi_ptt_print_head2_cfg_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_CPL:
+		hisi_ptt_print_head2_cpl_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_MSG:
+	case HISI_PTT_PKT_TYPE_UNKNOWN:
+	case HISI_PTT_PKT_TYPE_MAX:
+	default:
+		color_fprintf(stdout, PERF_COLOR_BLUE, "  %s\n",
+			      pkt_buf->pkt_type == HISI_PTT_4DW_PKT ?
+			      hisi_ptt_4dw_pkt_field_name[HISI_PTT_4DW_HEAD2] :
+			      hisi_ptt_8dw_pkt_field_name[HISI_PTT_8DW_HEAD2]);
+		break;
+	}
+
+	pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
+}
+
+static void hisi_ptt_print_head3_ar64_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x\n",
+		      "Addr<31:2>",
+		      FIELD_GET(HISI_PTT_HEAD3_AR64_ADDR_31_2, dw),
+		      "PH<1:0>", FIELD_GET(HISI_PTT_HEAD3_AR64_PH_1_0, dw));
+}
+
+static void hisi_ptt_print_head3_ar32_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n",
+		      "Request Segment",
+		      FIELD_GET(HISI_PTT_HEAD3_AR32_REQ_SEG, dw),
+		      "ST<15:8>", FIELD_GET(HISI_PTT_HEAD3_AR32_ST_15_8, dw),
+		      "RSV2", FIELD_GET(HISI_PTT_HEAD3_AR32_RSV2, dw),
+		      "HV", FIELD_GET(HISI_PTT_HEAD3_AR32_HV, dw),
+		      "AMA", FIELD_GET(HISI_PTT_HEAD3_AR32_AMA, dw),
+		      "AV", FIELD_GET(HISI_PTT_HEAD3_AR32_AV, dw),
+		      "FM", FIELD_GET(HISI_PTT_HEAD3_AR32_FM, dw),
+		      "RSV1", FIELD_GET(HISI_PTT_HEAD3_AR32_RSV1, dw),
+		      "TV", FIELD_GET(HISI_PTT_HEAD3_AR32_TV, dw),
+		      "T", FIELD_GET(HISI_PTT_HEAD3_AR32_T, dw),
+		      "Tag<13:10>",
+		      FIELD_GET(HISI_PTT_HEAD3_AR32_TAG_13_10, dw));
+}
+
+static void hisi_ptt_print_head3_io_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n",
+		      "Request Segment",
+		      FIELD_GET(HISI_PTT_HEAD3_AR32_REQ_SEG, dw),
+		      "RSV2", FIELD_GET(HISI_PTT_HEAD3_AR32_IO_RSV2, dw),
+		      "FM", FIELD_GET(HISI_PTT_HEAD3_AR32_FM, dw),
+		      "RSV1", FIELD_GET(HISI_PTT_HEAD3_AR32_RSV1, dw),
+		      "TV", FIELD_GET(HISI_PTT_HEAD3_AR32_TV, dw),
+		      "T", FIELD_GET(HISI_PTT_HEAD3_AR32_T, dw),
+		      "Tag<13:10>",
+		      FIELD_GET(HISI_PTT_HEAD3_AR32_TAG_13_10, dw));
+}
+
+static void hisi_ptt_print_head3_cfg_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n",
+		      "RSV2", FIELD_GET(HISI_PTT_HEAD3_CFG_RSV2, dw),
+		      "Destination Segment",
+		      FIELD_GET(HISI_PTT_HEAD3_CFG_DST_SEG, dw),
+		      "DSV", FIELD_GET(HISI_PTT_HEAD3_CFG_DSV, dw),
+		      "TV", FIELD_GET(HISI_PTT_HEAD3_CFG_TV, dw),
+		      "T", FIELD_GET(HISI_PTT_HEAD3_CFG_T, dw),
+		      "Tag<13:10>", FIELD_GET(HISI_PTT_HEAD3_CFG_TAG_13_10, dw),
+		      "RSV1", FIELD_GET(HISI_PTT_HEAD3_CFG_RSV1, dw));
+}
+
+static void hisi_ptt_print_head3_cpl_fields(uint32_t dw)
+{
+	color_fprintf(stdout, PERF_COLOR_BLUE,
+		      "  %s %x %s %x %s %x %s %x %s %x %s %x %s %x\n",
+		      "Destination Segment",
+		      FIELD_GET(HISI_PTT_HEAD3_CPL_DST_SEG, dw),
+		      "Completer Segment",
+		      FIELD_GET(HISI_PTT_HEAD3_CPL_COM_SEG, dw),
+		      "DSV", FIELD_GET(HISI_PTT_HEAD3_CPL_DSV, dw),
+		      "Reserved", FIELD_GET(HISI_PTT_HEAD3_CPL_RSV, dw),
+		      "TV", FIELD_GET(HISI_PTT_HEAD3_CPL_TV, dw),
+		      "T", FIELD_GET(HISI_PTT_HEAD3_CPL_T, dw),
+		      "Tag<13:10>",
+		      FIELD_GET(HISI_PTT_HEAD3_CPL_TAG_13_10, dw));
+}
+
+static void hisi_ptt_print_head3(struct hisi_ptt_pkt_buf *pkt_buf)
+{
+	uint32_t dw;
+
+	dw = get_unaligned_le32(pkt_buf->buf + pkt_buf->pos);
+	hisi_ptt_print_raw_record(pkt_buf->pos, dw);
+
+	switch (pkt_buf->pkt_msg_type) {
+	case HISI_PTT_PKT_TYPE_MRD:
+	case HISI_PTT_PKT_TYPE_MWR:
+	case HISI_PTT_PKT_TYPE_DMWR:
+	case HISI_PTT_PKT_TYPE_ATOM:
+		if (pkt_buf->proto_len == HISI_PTT_4DW_HEADER_PROTO_LEN)
+			hisi_ptt_print_head3_ar64_fields(dw);
+		else
+			hisi_ptt_print_head3_ar32_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_IO:
+		hisi_ptt_print_head3_io_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_CFG:
+		hisi_ptt_print_head3_cfg_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_CPL:
+		hisi_ptt_print_head3_cpl_fields(dw);
+		break;
+	case HISI_PTT_PKT_TYPE_MSG:
+	case HISI_PTT_PKT_TYPE_UNKNOWN:
+	case HISI_PTT_PKT_TYPE_MAX:
+	default:
+		color_fprintf(stdout, PERF_COLOR_BLUE, "  %s\n",
+			      pkt_buf->pkt_type == HISI_PTT_4DW_PKT ?
+			      hisi_ptt_4dw_pkt_field_name[HISI_PTT_4DW_HEAD3] :
+			      hisi_ptt_8dw_pkt_field_name[HISI_PTT_8DW_HEAD3]);
+		break;
+	}
+
+	pkt_buf->pos += HISI_PTT_FIELD_LENGTH;
+}
+
 static int hisi_ptt_8dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 {
 	int i;
@@ -235,12 +567,24 @@ static int hisi_ptt_8dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 			continue;
 		}
 
-		if (i == HISI_PTT_8DW_HEAD0) {
+		switch (i) {
+		case HISI_PTT_8DW_HEAD0:
 			hisi_ptt_print_head0(pkt_buf);
-			continue;
+			break;
+		case HISI_PTT_8DW_HEAD1:
+			hisi_ptt_print_head1(pkt_buf);
+			break;
+		case HISI_PTT_8DW_HEAD2:
+			hisi_ptt_print_head2(pkt_buf);
+			break;
+		case HISI_PTT_8DW_HEAD3:
+			hisi_ptt_print_head3(pkt_buf);
+			break;
+		default:
+			hisi_ptt_print_pkt(pkt_buf,
+					   hisi_ptt_8dw_pkt_field_name[i]);
+			break;
 		}
-
-		hisi_ptt_print_pkt(pkt_buf, hisi_ptt_8dw_pkt_field_name[i]);
 	}
 
 	return hisi_ptt_pkt_size[HISI_PTT_8DW_PKT];
@@ -248,12 +592,10 @@ static int hisi_ptt_8dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 
 static int hisi_ptt_4dw_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf)
 {
-	int i;
-
 	hisi_ptt_print_head0(pkt_buf);
-
-	for (i = HISI_PTT_4DW_HEAD1; i < HISI_PTT_4DW_TYPE_MAX; i++)
-		hisi_ptt_print_pkt(pkt_buf, hisi_ptt_4dw_pkt_field_name[i]);
+	hisi_ptt_print_head1(pkt_buf);
+	hisi_ptt_print_head2(pkt_buf);
+	hisi_ptt_print_head3(pkt_buf);
 
 	return hisi_ptt_pkt_size[HISI_PTT_4DW_PKT];
 }
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h +181 -13

200 lines not on this page · raw message

Signature · 1 line
2.33.0
#12 lore raw

Re: [PATCH v4 6/8] perf hisi-ptt: Add field-level parsing for header DW0/DW1/DW2/DW3

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

Add field-level parsing of Header DW0, DW1, DW2 and DW3 of the TLP, separating the layout for different requests. The message type parsed in the previous patch is used to select the corresponding field layout.

HiSilicon PCIe trace device hardware is responsible for packet collection, parsing, extraction and fills the corresponding fields with the required positions. The packet decoder software will perform the parsing and printing of fields filled by hardware.

Sashiko has reviewed this patch and found no issues. It looks great!

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

PATCH v4 7/8 hwtracing: hisi_ptt: Add pattern PMU config for trace format selection

In reply to Sizhe Liu

Introduce a pattern PMU config field (config:36-39) that controls which TLP header format the hardware traces. bit[3:1] are reserved for future extension and only bit0 is used currently:

- pattern=0 (default, compatibility mode): the driver sets bit[8] of HISI_PTT_TRACE_CTRL so the hardware traces the data in compatibility mode.
- pattern=1: the driver clears bit[8] of HISI_PTT_TRACE_CTRL so the hardware traces the data pattern including some bitfields of the TLP header defined in PCIe r6.4 sec 2.2.1.2.

Note that bit[8] of HISI_PTT_TRACE_CTRL is inverted with respect to the pattern value: bit[8]=1 selects the legacy format, bit[8]=0 selects the new format. Bit[11:9] is still reserved, which is consistent with the PMU config field. The driver validates the 4-bit value in hisi_ptt_trace_valid_pattern() and applies it in hisi_ptt_trace_start().

Document the new parameter in Documentation/trace/hisi-ptt.rst.

---
 Documentation/trace/hisi-ptt.rst | 26 ++++++++++++++++++++++++--
 drivers/hwtracing/ptt/hisi_ptt.c | 25 ++++++++++++++++++++++++-
 drivers/hwtracing/ptt/hisi_ptt.h |  4 ++++
 3 files changed, 52 insertions(+), 3 deletions(-)
Documentation/trace/hisi-ptt.rst +24 -2
index f6a2655f99e5..a70719386159 100644
@@ -255,7 +255,29 @@ directly from the TLP header.
      DW2 [                     Header DW2                            ]
      DW3 [                     Header DW3                            ]
 
-5. Memory Management
+5. Trace pattern
+-----------------
+
+You can control whether the trace is taken with the new version of the
+TLP header format by specifying the `pattern` parameter. The default
+value is 0, which means the legacy format is used for backward
+compatibility. The parameter value is 4 bit and bit[3:1] are currently
+reserved for extension. Current supported values are shown below:
+
+- 4'b0000: legacy trace format
+    DW0 (in 8DW format), DW1, DW2 and DW3 are printed with generic field names,
+    and no message-type-based field decoding. Consider using legacy trace format
+    when the current PCIe link generation is not higher than PCIe 6.0.
+- 4'b0001: trace format v1
+    DW0, DW1, DW2 and DW3 are decoded according to the TLP message type (MRd,
+    MWr, DMWr, Msg, AtomicOP, I/O, Cpl, Cfg) with detailed field names.
+    It is recommended to use trace format v1 when the current PCIe link
+    generation is higher than PCIe 6.0.
+
+For trace data recorded by an older tracer without the `pattern` parameter,
+the decoder will work as `pattern` forced to 0.
+
+6. Memory Management
 --------------------
 
 The traced TLP headers will be written to the memory allocated
@@ -274,7 +296,7 @@ will commit the AUX buffer first and then apply for a new one with
 the same size. The size of AUX buffer is default to 16MiB. User can
 adjust the size by specifying the `-m` parameter of the perf command.
 
-6. Decoding
+7. Decoding
 -----------
 
 You can decode the traced data with `perf report -D` command (currently
drivers/hwtracing/ptt/hisi_ptt.c +24 -1
index 52f168f8b459..b63985c2b30e 100644
@@ -232,6 +232,10 @@ static int hisi_ptt_trace_start(struct hisi_ptt *hisi_ptt)
 	val |= FIELD_PREP(HISI_PTT_TRACE_CTRL_TARGET_SEL, hisi_ptt->trace_ctrl.filter);
 	if (!hisi_ptt->trace_ctrl.is_port)
 		val |= HISI_PTT_TRACE_CTRL_FILTER_MODE;
+	if (!ctrl->pattern)
+		val |= HISI_PTT_TRACE_CTRL_PATTERN;
+	else
+		val &= ~HISI_PTT_TRACE_CTRL_PATTERN;
 
 	ctrl->started = true;
 
@@ -806,12 +810,14 @@ PMU_FORMAT_ATTR(filter,		"config:0-19");
 PMU_FORMAT_ATTR(direction,	"config:20-23");
 PMU_FORMAT_ATTR(type,		"config:24-31");
 PMU_FORMAT_ATTR(format,		"config:32-35");
+PMU_FORMAT_ATTR(pattern,		"config:36-39");
 
 static struct attribute *hisi_ptt_pmu_format_attrs[] = {
 	&format_attr_filter.attr,
 	&format_attr_direction.attr,
 	&format_attr_type.attr,
 	&format_attr_format.attr,
+	&format_attr_pattern.attr,
 	NULL
 };
 
@@ -941,6 +947,15 @@ static int hisi_ptt_trace_valid_format(u32 val)
 	return -EINVAL;
 }
 
+static int hisi_ptt_trace_valid_pattern(u32 val)
+{
+	/* Currently only bit0 is used, bit[3:1] are reserved for extension. */
+	if (val <= 1)
+		return 0;
+
+	return -EINVAL;
+}
+
 static int hisi_ptt_trace_valid_filter(struct hisi_ptt *hisi_ptt, u64 config)
 {
 	unsigned long val, port_mask = hisi_ptt->port_mask;
@@ -991,6 +1006,9 @@ static void hisi_ptt_pmu_init_configs(struct hisi_ptt *hisi_ptt, struct perf_eve
 
 	val = FIELD_GET(HISI_PTT_PMU_FORMAT_MASK, event->attr.config);
 	ctrl->format = val;
+
+	val = FIELD_GET(HISI_PTT_PMU_PATTERN_MASK, event->attr.config);
+	ctrl->pattern = val;
 }
 
 static int hisi_ptt_pmu_event_init(struct perf_event *event)
@@ -1025,7 +1043,12 @@ static int hisi_ptt_pmu_event_init(struct perf_event *event)
 		return ret;
 
 	val = FIELD_GET(HISI_PTT_PMU_FORMAT_MASK, event->attr.config);
-	return hisi_ptt_trace_valid_format(val);
+	ret = hisi_ptt_trace_valid_format(val);
+	if (ret < 0)
+		return ret;
+
+	val = FIELD_GET(HISI_PTT_PMU_PATTERN_MASK, event->attr.config);
+	return hisi_ptt_trace_valid_pattern(val);
 }
 
 static void *hisi_ptt_pmu_setup_aux(struct perf_event *event, void **pages,
drivers/hwtracing/ptt/hisi_ptt.h +4 -0
index 46030aa88081..c1636676c8c8 100644
@@ -41,6 +41,7 @@
 #define   HISI_PTT_TRACE_CTRL_RST	BIT(1)
 #define   HISI_PTT_TRACE_CTRL_RXTX_SEL	GENMASK(3, 2)
 #define   HISI_PTT_TRACE_CTRL_TYPE_SEL	GENMASK(7, 4)
+#define   HISI_PTT_TRACE_CTRL_PATTERN	BIT(8)
 #define   HISI_PTT_TRACE_CTRL_DATA_FORMAT	BIT(14)
 #define   HISI_PTT_TRACE_CTRL_FILTER_MODE	BIT(15)
 #define   HISI_PTT_TRACE_CTRL_TARGET_SEL	GENMASK(31, 16)
@@ -89,6 +90,7 @@
 #define HISI_PTT_PMU_DIRECTION_MASK	GENMASK(23, 20)
 #define HISI_PTT_PMU_TYPE_MASK		GENMASK(31, 24)
 #define HISI_PTT_PMU_FORMAT_MASK	GENMASK(35, 32)
+#define HISI_PTT_PMU_PATTERN_MASK	GENMASK(39, 36)
 
 /**
  * struct hisi_ptt_tune_desc - Describe tune event for PTT tune
@@ -127,6 +129,7 @@ struct hisi_ptt_dma_buffer {
  * @filter:    filter value for tracing the TLP headers
  * @format:    format of the TLP headers to trace
  * @type:      type of the TLP headers to trace
+ * @pattern:   pattern of the TLP headers to trace
  */
 struct hisi_ptt_trace_ctrl {
 	struct hisi_ptt_dma_buffer *trace_buf;
@@ -139,6 +142,7 @@ struct hisi_ptt_trace_ctrl {
 	u32 filter:16;
 	u32 format:1;
 	u32 type:4;
+	u32 pattern:4;
 };
 
 /*
Signature · 1 line
2.33.0
#14 lore raw

Re: [PATCH v4 7/8] hwtracing: hisi_ptt: Add pattern PMU config for trace format selection

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 17 lines

Introduce a pattern PMU config field (config:36-39) that controls which TLP header format the hardware traces. bit[3:1] are reserved for future extension and only bit0 is used currently:

- pattern=0 (default, compatibility mode): the driver sets bit[8] of HISI_PTT_TRACE_CTRL so the hardware traces the data in compatibility mode.
- pattern=1: the driver clears bit[8] of HISI_PTT_TRACE_CTRL so the hardware traces the data pattern including some bitfields of the TLP header defined in PCIe r6.4 sec 2.2.1.2.

Note that bit[8] of HISI_PTT_TRACE_CTRL is inverted with respect to the pattern value: bit[8]=1 selects the legacy format, bit[8]=0 selects the new format. Bit[11:9] is still reserved, which is consistent with the PMU config field. The driver validates the 4-bit value in hisi_ptt_trace_valid_pattern() and applies it in hisi_ptt_trace_start().

Quoted 4 lines

Document the new parameter in Documentation/trace/hisi-ptt.rst.

Sashiko has reviewed this patch and found no issues. It looks great!

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

PATCH v4 8/8 perf hisi-ptt: Pass pattern version to decoder for compatibility

In reply to Sizhe Liu

On the recording side, walk the evlist in hisi_ptt_info_fill() to find the hisi_ptt event, read out the pattern bits from its config, and forward the pattern version to the decoder through auxtrace_info->priv[1] as HISI_PTT_PATTERN_LEGACY or HISI_PTT_PATTERN_V1.

On the decoding side, store the pattern version in struct hisi_ptt and propagate it to struct hisi_ptt_pkt_buf. The printers of Header DW2 and DW3 check the version: HISI_PTT_PATTERN_V1 keeps the field-level parsing introduced by the previous patches, while HISI_PTT_PATTERN_LEGACY falls back to printing only the raw "Header DW2/DW3" label so legacy traces remain decodable with the new tool.

The auxtrace priv size grows from one u64 to two. Use HISI_PTT_AUXTRACE_PRIV_SIZE_LEGACY for the minimum header size check and detect the actual priv_size at runtime to pick the pattern version. For trace data recorded by an older tracer that does not support the pattern parameter (no priv[1] in the header), the decoder defaults to legacy mode (HISI_PTT_PATTERN_LEGACY) so the new tool keeps parsing old traces correctly.

The hisi_ptt_pkt_size array is moved out of the shared header into static definitions in the two .c files that consume it to avoid multiple definitions.

---
 tools/perf/arch/arm64/util/hisi-ptt.c         |  18 +++
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c   | 123 ++++++++++++------
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.h   |   8 +-
 tools/perf/util/hisi-ptt.c                    |  28 ++--
 tools/perf/util/hisi-ptt.h                    |   9 +-
 5 files changed, 133 insertions(+), 53 deletions(-)
tools/perf/arch/arm64/util/hisi-ptt.c +18 -0
index 52257715d2b7..ae8c16b5c324 100644
@@ -6,6 +6,7 @@
 
 #include <linux/kernel.h>
 #include <linux/types.h>
+#include <linux/bitfield.h>
 #include <linux/bitops.h>
 #include <linux/log2.h>
 #include <linux/zalloc.h>
@@ -20,6 +21,7 @@
 #include "../../../util/evlist.h"
 #include "../../../util/evsel.h"
 #include "../../../util/hisi-ptt.h"
+#include "../../../util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h"
 #include "../../../util/pmu.h"
 #include "../../../util/record.h"
 #include "../../../util/session.h"
@@ -49,6 +51,8 @@ static int hisi_ptt_info_fill(struct auxtrace_record *itr,
 	struct hisi_ptt_recording *pttr =
 			container_of(itr, struct hisi_ptt_recording, itr);
 	struct perf_pmu *hisi_ptt_pmu = pttr->hisi_ptt_pmu;
+	struct evsel *evsel;
+	u32 pattern = 0;
 
 	if (priv_size != HISI_PTT_AUXTRACE_PRIV_SIZE)
 		return -EINVAL;
@@ -56,8 +60,22 @@ static int hisi_ptt_info_fill(struct auxtrace_record *itr,
 	if (!evlist__core(session->evlist)->nr_mmaps)
 		return -EINVAL;
 
+	/*
+	 * Walk the evlist to find the hisi_ptt event and read out the pattern
+	 * bits from its config, which decides the decoder version used to
+	 * parse the trace data.
+	 */
+	evlist__for_each_entry(session->evlist, evsel) {
+		if (evsel->core.attr.type == hisi_ptt_pmu->type) {
+			pattern = FIELD_GET(HISI_PTT_PMU_PATTERN_MASK,
+					    evsel->core.attr.config);
+			break;
+		}
+	}
+
 	auxtrace_info->type = PERF_AUXTRACE_HISI_PTT;
 	auxtrace_info->priv[0] = hisi_ptt_pmu->type;
+	auxtrace_info->priv[1] = pattern;
 
 	return 0;
 }
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c +85 -38

201 lines not on this page · raw message

tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h +3 -5
index 5f71cfdcb7a7..f17ee6b549ca 100644
@@ -19,6 +19,8 @@
 #define HISI_PTT_FIELD_LENGTH			4
 #define HISI_PTT_3DW_HEADER_PROTO_LEN		3
 #define HISI_PTT_4DW_HEADER_PROTO_LEN		4
+#define HISI_PTT_PATTERN_LEGACY			0
+#define HISI_PTT_PATTERN_V1			1
 
 /* Hisi PTT Header DW0 fields for 4DW format
  *
@@ -208,11 +210,6 @@ enum hisi_ptt_pkt_type {
 	HISI_PTT_PKT_MAX
 };
 
-static int hisi_ptt_pkt_size[] = {
-	[HISI_PTT_4DW_PKT]	= 16,
-	[HISI_PTT_8DW_PKT]	= 32,
-};
-
 enum hisi_ptt_pkt_msg_type {
 	/* Types do not support analysis */
 	HISI_PTT_PKT_TYPE_UNKNOWN,
@@ -243,6 +240,7 @@ struct hisi_ptt_pkt_buf {
 	enum hisi_ptt_pkt_type pkt_type;
 	enum hisi_ptt_pkt_msg_type pkt_msg_type;
 	size_t proto_len;
+	size_t pattern;
 };
 
 int hisi_ptt_pkt_desc(struct hisi_ptt_pkt_buf *pkt_buf);
tools/perf/util/hisi-ptt.c +20 -8
index 78817ae7a8ea..7cf778837337 100644
@@ -35,6 +35,12 @@ struct hisi_ptt {
 	struct perf_session *session;
 	struct machine *machine;
 	u32 pmu_type;
+	u32 pattern;
+};
+
+static int hisi_ptt_pkt_size[] = {
+	[HISI_PTT_4DW_PKT]	= 16,
+	[HISI_PTT_8DW_PKT]	= 32,
 };
 
 static enum hisi_ptt_pkt_type hisi_ptt_check_packet_type(unsigned char *buf,
@@ -53,8 +59,7 @@ static enum hisi_ptt_pkt_type hisi_ptt_check_packet_type(unsigned char *buf,
 	return HISI_PTT_4DW_PKT;
 }
 
-static void hisi_ptt_dump(struct hisi_ptt *ptt __maybe_unused,
-			  unsigned char *buf, size_t len)
+static void hisi_ptt_dump(struct hisi_ptt *ptt, unsigned char *buf, size_t len)
 {
 	const char *color = PERF_COLOR_BLUE;
 	struct hisi_ptt_pkt_buf pkt_buf;
@@ -64,8 +69,9 @@ static void hisi_ptt_dump(struct hisi_ptt *ptt __maybe_unused,
 	pkt_buf.pkt_type = hisi_ptt_check_packet_type(buf, len);
 	pkt_buf.len = round_down(len, hisi_ptt_pkt_size[pkt_buf.pkt_type]);
 	pkt_buf.pkt_msg_type = HISI_PTT_PKT_TYPE_UNKNOWN;
-	color_fprintf(stdout, color, ". ... HISI PTT data: size %zu bytes\n",
-		      pkt_buf.len);
+	pkt_buf.pattern = (size_t)ptt->pattern;
+	color_fprintf(stdout, color, ". ... HISI PTT data: size %zu bytes, pattern %zu\n",
+		      pkt_buf.len, pkt_buf.pattern);
 
 	while (pkt_buf.pos < pkt_buf.len) {
 		if (!hisi_ptt_pkt_desc(&pkt_buf))
@@ -158,12 +164,13 @@ static bool hisi_ptt_evsel_is_auxtrace(struct perf_session *session,
 	return evsel->core.attr.type == ptt->pmu_type;
 }
 
-static void hisi_ptt_print_info(__u64 type)
+static void hisi_ptt_print_info(u32 type, u32 pattern)
 {
 	if (!dump_trace)
 		return;
 
-	fprintf(stdout, "  PMU Type           %" PRId64 "\n", (s64) type);
+	fprintf(stdout, "  PMU Type           %" PRIu32 "\n", type);
+	fprintf(stdout, "  Data Pattern       %" PRIu32 "\n", pattern);
 }
 
 int hisi_ptt_process_auxtrace_info(union perf_event *event,
@@ -171,10 +178,13 @@ int hisi_ptt_process_auxtrace_info(union perf_event *event,
 {
 	struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info;
 	struct hisi_ptt *ptt;
+	size_t priv_size;
 
-	if (auxtrace_info->header.size < HISI_PTT_AUXTRACE_PRIV_SIZE +
+	if (auxtrace_info->header.size < HISI_PTT_AUXTRACE_PRIV_SIZE_LEGACY +
 				sizeof(struct perf_record_auxtrace_info))
 		return -EINVAL;
+	priv_size = auxtrace_info->header.size -
+		    sizeof(struct perf_record_auxtrace_info);
 
 	ptt = zalloc(sizeof(*ptt));
 	if (!ptt)
@@ -184,6 +194,8 @@ int hisi_ptt_process_auxtrace_info(union perf_event *event,
 	ptt->machine = &session->machines.host; /* No kvm support */
 	ptt->auxtrace_type = auxtrace_info->type;
 	ptt->pmu_type = auxtrace_info->priv[0];
+	ptt->pattern = priv_size >= HISI_PTT_AUXTRACE_PRIV_SIZE_V1 ?
+		       (u32)auxtrace_info->priv[1] : HISI_PTT_PATTERN_LEGACY;
 
 	ptt->auxtrace.process_event = hisi_ptt_process_event;
 	ptt->auxtrace.process_auxtrace_event = hisi_ptt_process_auxtrace_event;
@@ -193,7 +205,7 @@ int hisi_ptt_process_auxtrace_info(union perf_event *event,
 	ptt->auxtrace.evsel_is_auxtrace = hisi_ptt_evsel_is_auxtrace;
 	session->auxtrace = &ptt->auxtrace;
 
-	hisi_ptt_print_info(auxtrace_info->priv[0]);
+	hisi_ptt_print_info(ptt->pmu_type, ptt->pattern);
 
 	return 0;
 }
tools/perf/util/hisi-ptt.h +7 -2
index 2db9b4056214..912453b06e62 100644
@@ -7,8 +7,13 @@
 #ifndef INCLUDE__PERF_HISI_PTT_H__
 #define INCLUDE__PERF_HISI_PTT_H__
 
-#define HISI_PTT_PMU_NAME		"hisi_ptt"
-#define HISI_PTT_AUXTRACE_PRIV_SIZE	sizeof(u64)
+#include <linux/bits.h>
+
+#define HISI_PTT_PMU_NAME			"hisi_ptt"
+#define HISI_PTT_AUXTRACE_PRIV_SIZE_LEGACY	sizeof(u64)
+#define HISI_PTT_AUXTRACE_PRIV_SIZE_V1		(2 * sizeof(u64))
+#define HISI_PTT_AUXTRACE_PRIV_SIZE		HISI_PTT_AUXTRACE_PRIV_SIZE_V1
+#define HISI_PTT_PMU_PATTERN_MASK		GENMASK_ULL(39, 36)
 
 struct auxtrace_record *hisi_ptt_recording_init(int *err,
 						struct perf_pmu *hisi_ptt_pmu);
Signature · 1 line
2.33.0
#16 lore raw

Re: [PATCH v4 8/8] perf hisi-ptt: Pass pattern version to decoder for compatibility

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 20 lines

On the recording side, walk the evlist in hisi_ptt_info_fill() to find the hisi_ptt event, read out the pattern bits from its config, and forward the pattern version to the decoder through auxtrace_info->priv[1] as HISI_PTT_PATTERN_LEGACY or HISI_PTT_PATTERN_V1.

On the decoding side, store the pattern version in struct hisi_ptt and propagate it to struct hisi_ptt_pkt_buf. The printers of Header DW2 and DW3 check the version: HISI_PTT_PATTERN_V1 keeps the field-level parsing introduced by the previous patches, while HISI_PTT_PATTERN_LEGACY falls back to printing only the raw "Header DW2/DW3" label so legacy traces remain decodable with the new tool.

The auxtrace priv size grows from one u64 to two. Use HISI_PTT_AUXTRACE_PRIV_SIZE_LEGACY for the minimum header size check and detect the actual priv_size at runtime to pick the pattern version. For trace data recorded by an older tracer that does not support the pattern parameter (no priv[1] in the header), the decoder defaults to legacy mode (HISI_PTT_PATTERN_LEGACY) so the new tool keeps parsing old traces correctly.

Quoted 6 lines

The hisi_ptt_pkt_size array is moved out of the shared header into static definitions in the two .c files that consume it to avoid multiple definitions.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#17 lore raw
In reply to Sizhe Liu
Quoted 8 lines · Sizhe Liu

The original hisi-ptt-decoder only prints raw hex values with generic field names for DW0/DW1/DW2/DW3, without classifying TLP types or decoding DW0/DW1/DW2/DW3 fields according to the hardware-defined packet format.

This series enhances the HiSilicon PTT (PCIe Trace and Tuning) packet decoder in perf tool to provide detailed field-level parsing of TLP headers based on message type, and adds a versioning mechanism for backward compatibility both in hisi_ptt driver and perf tool.

Series is sashiko clean by now, has a Reviewed-by, but it touches both kernel and tools, I wouldn't have a problem if it was processed by whoever maintains the kernel part.

- Arnaldo

Quoted 52 lines

---
Changes in v4:
- Add missing space in hisi-ptt.rst (Sashiko).
- Widen the pattern bit field in struct hisi_ptt_trace_ctrl (Sashiko).
- Add protocol defined TLP header length parsing in patch 05/08.
- Add MRd and DMRr message types parsing in patch 05/08.
- Add comment for enum hisi_ptt_pkt_msg_type in patch 05/08.
- Add DW0 and DW1 fields analysing in patch 06/08.
- Refine bit-fields parsing of DW0/DW1/DW2/DW3 based on different requests
in patch 06/08.
- Refine the description of pattern=1 in the document in patch 07/08.
- Extract the bit-field printing of v1 version into functions in
patch 08/08.
- Link to v3: https://lore.kernel.org/linux-pci/[email protected]/

Changes in v3:
- Add explicit inclusion of <stdbool.h> (Sashiko).
- Make patch 07/08 apply cleanly to mainline (Yushan).
- Pick up the reviewed-by tag (Yushan).
- Link to v2: https://lore.kernel.org/linux-pci/[email protected]/

Changes in v2:
- Split patch 01/10 and patch 02/10 from series v1 into independent patch series for backporting (Bjorn).
- Use bitwise operations instead of C bitfields for cross-platform cases (Sashiko).
- Add pattern parameter in hisi_ptt driver for layout compatibility.
- Link to v1: https://lore.kernel.org/linux-pci/[email protected]/

---
Sizhe Liu (8):
perf hisi-ptt: Abstract trace data buf and offset
perf hisi-ptt: Complete the field names for 4DW and 8DW packets perf hisi-ptt: Extract the raw data printing part
perf hisi-ptt: Merge 4DW and 8DW HEAD0 printing
perf hisi-ptt: Add parsing of supported message types and proto length perf hisi-ptt: Add field-level parsing for header DW0/DW1/DW2/DW3
hwtracing: hisi_ptt: Add pattern PMU config for trace format selection perf hisi-ptt: Pass pattern version to decoder for compatibility

 Documentation/trace/hisi-ptt.rst              |  26 +-
 drivers/hwtracing/ptt/hisi_ptt.c              |  25 +-
 drivers/hwtracing/ptt/hisi_ptt.h              |   4 +
 tools/perf/arch/arm64/util/hisi-ptt.c         |  18 +
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c   | 593 ++++++++++++++++--
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.h   | 241 ++++++-
 tools/perf/util/hisi-ptt.c                    |  51 +-
 tools/perf/util/hisi-ptt.h                    |   9 +-
 8 files changed, 872 insertions(+), 95 deletions(-)
Signature · 1 line
2.33.0
author maintainer
#18 lore raw
Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 9 lines · Sizhe Liu

The original hisi-ptt-decoder only prints raw hex values with generic field names for DW0/DW1/DW2/DW3, without classifying TLP types or decoding DW0/DW1/DW2/DW3 fields according to the hardware- defined packet format.

This series enhances the HiSilicon PTT (PCIe Trace and Tuning) packet decoder in perf tool to provide detailed field-level parsing of TLP headers based on message type, and adds a versioning mechanism for backward compatibility both in hisi_ptt driver and perf tool.

Quoted 6 lines

Series is sashiko clean by now, has a Reviewed-by, but it touches both kernel and tools, I wouldn't have a problem if it was processed by whoever maintains the kernel part.

- Arnaldo

Hi Suzuki,

The series is now Sashiko-clean and has Reviewed-by tags. It touches both driver and tools. Arnaldo is fine with the tools part. Would you mind reviewing the driver part and picking it up through your tree if it looks good?

If there are any changes needed, please let me know.

Thanks for your time!
Sizhe

Quoted 44 lines
Quoted 44 lines

--- Changes in v4: - Add missing space in hisi-ptt.rst (Sashiko). - Widen the pattern bit field in struct hisi_ptt_trace_ctrl (Sashiko).
- Add protocol defined TLP header length parsing in patch 05/08. - Add MRd and DMRr message types parsing in patch 05/08. - Add comment for enum hisi_ptt_pkt_msg_type in patch 05/08. - Add DW0 and DW1 fields analysing in patch 06/08. - Refine bit-fields parsing of DW0/ DW1/DW2/DW3 based on different requests in patch 06/08. - Refine the description of pattern=1 in the document in patch 07/08. - Extract the bit-field printing of v1 version into functions in patch 08/08. - Link to v3: https://lore.kernel.org/linux-
pci/[email protected]/

Changes in v3: - Add explicit inclusion of <stdbool.h> (Sashiko). - Make patch 07/08 apply cleanly to mainline (Yushan). - Pick up the reviewed-by tag (Yushan). - Link to v2: https://lore.kernel.org/
linux-pci/[email protected]/

Changes in v2: - Split patch 01/10 and patch 02/10 from series v1 into independent patch series for backporting (Bjorn). - Use bitwise operations instead of C bitfields for cross-platform cases (Sashiko).
- Add pattern parameter in hisi_ptt driver for layout compatibility. - Link to v1: https://lore.kernel.org/linux-
pci/[email protected]/

--- Sizhe Liu (8): perf hisi-ptt: Abstract trace data buf and offset perf hisi-ptt: Complete the field names for 4DW and 8DW packets perf
hisi-ptt: Extract the raw data printing part perf hisi-ptt: Merge 4DW and 8DW HEAD0 printing perf hisi-ptt: Add parsing of supported message types and proto length perf hisi-ptt: Add field-level parsing for header DW0/DW1/DW2/DW3 hwtracing: hisi_ptt: Add pattern PMU config for trace format selection perf hisi-ptt: Pass pattern version to decoder for compatibility

Documentation/trace/hisi-ptt.rst | 26 +- drivers/
hwtracing/ptt/hisi_ptt.c | 25 +- drivers/hwtracing/ptt/
hisi_ptt.h | 4 + tools/perf/arch/arm64/util/hisi-
ptt.c | 18 + .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c
| 593 ++++++++++++++++-- .../hisi-ptt-decoder/hisi-ptt-pkt-
decoder.h | 241 ++++++- tools/perf/util/hisi-
ptt.c | 51 +- tools/perf/util/hisi-
ptt.h | 9 +- 8 files changed, 872
insertions(+), 95 deletions(-)

-- 2.33.0