public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: Sizhe Liu <liusizhe5@huawei•com>
To: <rostedt@goodmis•org>, <mhiramat@kernel•org>,
	<mathieu.desnoyers@efficios•com>, <corbet@lwn•net>,
	<skhan@linuxfoundation•org>, <bhelgaas@google•com>,
	<yangyccccc@gmail•com>, <jic23@kernel•org>,
	<john.g.garry@oracle•com>, <will@kernel•org>,
	<james.clark@linaro•org>, <mike.leach@arm•com>,
	<leo.yan@linux•dev>, <peterz@infradead•org>, <mingo@redhat•com>,
	<acme@kernel•org>, <namhyung@kernel•org>, <mark.rutland@arm•com>,
	<alexander.shishkin@linux•intel.com>, <jolsa@kernel•org>,
	<irogers@google•com>, <adrian.hunter@intel•com>,
	<wangyushan12@huawei•com>, <shenyang39@huawei•com>,
	<gaozhihao6@h-partners•com>, <yuzhichengcheng@h-partners•com>,
	<liyihang9@h-partners•com>
Cc: <linux-kernel@vger•kernel.org>, <linux-pci@vger•kernel.org>,
	<linux-perf-users@vger•kernel.org>,
	<linux-arm-kernel@lists•infradead.org>,
	<linux-doc@vger•kernel.org>, <linuxarm@huawei•com>,
	<prime.zeng@hisilicon•com>, <fanghao11@huawei•com>,
	<wuyifan50@huawei•com>, <liusizhe5@huawei•com>
Subject: [PATCH 04/10] perf hisi-ptt: Abstract trace data buf and offset
Date: Thu, 4 Jun 2026 15:49:59 +0800	[thread overview]
Message-ID: <20260604075005.2219785-5-liusizhe5@huawei.com> (raw)
In-Reply-To: <20260604075005.2219785-1-liusizhe5@huawei.com>

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 function.

Signed-off-by: Sizhe Liu <liusizhe5@huawei•com>
---
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.c   | 39 ++++++++++---------
 .../hisi-ptt-decoder/hisi-ptt-pkt-decoder.h   |  9 ++++-
 tools/perf/util/hisi-ptt.c                    | 20 ++++------
 3 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c b/tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c
index 5daae2eaf435..201ca948c4fb 100644
--- a/tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c
+++ b/tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c
@@ -89,16 +89,17 @@ union hisi_ptt_field_data {
 	uint32_t value;
 };
 
-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;
 	uint32_t value;
 	uint8_t byte;
 	int i;
 
-	value = le32_to_cpu(*(__le32 *)(buf + pos));
+	value = le32_to_cpu(*(__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 = (value >> (24 - i * 8)) & 0xFF;
 		color_fprintf(stdout, color, "%02x ", byte);
@@ -106,36 +107,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;
 	union hisi_ptt_field_data dw;
 	uint8_t byte;
 	int i;
 
-	dw.value = le32_to_cpu(*(__le32 *)(buf + pos));
+	dw.value = le32_to_cpu(*(__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.value >> (24 - i * 8)) & 0xFF;
 		color_fprintf(stdout, color, "%02x ", byte);
@@ -149,27 +150,27 @@ static void hisi_ptt_4dw_print_dw0(const unsigned char *buf, int pos)
 		      "T9", dw.dw0_4dw.t9, "T8", dw.dw0_4dw.t8,
 		      "TH", dw.dw0_4dw.th, "SO", dw.dw0_4dw.so,
 		      "Length", dw.dw0_4dw.len, "Time", dw.dw0_4dw.time);
+
+	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;
+		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);
 }
diff --git a/tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h b/tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h
index 6772b16b817b..316f24f01068 100644
--- a/tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h
+++ b/tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h
@@ -26,6 +26,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
diff --git a/tools/perf/util/hisi-ptt.c b/tools/perf/util/hisi-ptt.c
index e4cc4785f744..4efda3f3e5f9 100644
--- a/tools/perf/util/hisi-ptt.c
+++ b/tools/perf/util/hisi-ptt.c
@@ -49,22 +49,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 = 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);
+	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;
 	}
 }
 
-- 
2.33.0



  parent reply	other threads:[~2026-06-04  7:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04  7:49 [PATCH 00/10] perf hisi-ptt: Enhance TLP packet decoder with field-level parsing and versioning Sizhe Liu
2026-06-04  7:49 ` [PATCH 01/10] perf hisi-ptt: Fix spelling and abbreviation errors Sizhe Liu
2026-06-04  7:49 ` [PATCH 02/10] perf hisi-ptt: Fix PTT trace TLP Header parsing Sizhe Liu
2026-06-04  7:49 ` [PATCH 03/10] perf hisi-ptt: Rename hisi_ptt_4dw union for reuse Sizhe Liu
2026-06-04  7:49 ` Sizhe Liu [this message]
2026-06-04  7:50 ` [PATCH 05/10] perf hisi-ptt: Complete the field names for 4DW and 8DW packets Sizhe Liu
2026-06-04  7:50 ` [PATCH 06/10] perf hisi-ptt: Extract the raw data printing part Sizhe Liu
2026-06-04  7:50 ` [PATCH 07/10] perf hisi-ptt: Merge 4DW and 8DW HEAD0 printing Sizhe Liu
2026-06-04  7:50 ` [PATCH 08/10] perf hisi-ptt: Add parsing of supported message types Sizhe Liu
2026-06-04  7:50 ` [PATCH 09/10] perf hisi-ptt: Add field-level parsing for header DW2/DW3 Sizhe Liu
2026-06-04  7:50 ` [PATCH 10/10] perf hisi-ptt: Add decoder version compatibility Sizhe Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260604075005.2219785-5-liusizhe5@huawei.com \
    --to=liusizhe5@huawei$(echo .)com \
    --cc=acme@kernel$(echo .)org \
    --cc=adrian.hunter@intel$(echo .)com \
    --cc=alexander.shishkin@linux$(echo .)intel.com \
    --cc=bhelgaas@google$(echo .)com \
    --cc=corbet@lwn$(echo .)net \
    --cc=fanghao11@huawei$(echo .)com \
    --cc=gaozhihao6@h-partners$(echo .)com \
    --cc=irogers@google$(echo .)com \
    --cc=james.clark@linaro$(echo .)org \
    --cc=jic23@kernel$(echo .)org \
    --cc=john.g.garry@oracle$(echo .)com \
    --cc=jolsa@kernel$(echo .)org \
    --cc=leo.yan@linux$(echo .)dev \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux-doc@vger$(echo .)kernel.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-pci@vger$(echo .)kernel.org \
    --cc=linux-perf-users@vger$(echo .)kernel.org \
    --cc=linuxarm@huawei$(echo .)com \
    --cc=liyihang9@h-partners$(echo .)com \
    --cc=mark.rutland@arm$(echo .)com \
    --cc=mathieu.desnoyers@efficios$(echo .)com \
    --cc=mhiramat@kernel$(echo .)org \
    --cc=mike.leach@arm$(echo .)com \
    --cc=mingo@redhat$(echo .)com \
    --cc=namhyung@kernel$(echo .)org \
    --cc=peterz@infradead$(echo .)org \
    --cc=prime.zeng@hisilicon$(echo .)com \
    --cc=rostedt@goodmis$(echo .)org \
    --cc=shenyang39@huawei$(echo .)com \
    --cc=skhan@linuxfoundation$(echo .)org \
    --cc=wangyushan12@huawei$(echo .)com \
    --cc=will@kernel$(echo .)org \
    --cc=wuyifan50@huawei$(echo .)com \
    --cc=yangyccccc@gmail$(echo .)com \
    --cc=yuzhichengcheng@h-partners$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox