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>, <wuzongyu1@huawei.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>, <liusizhe5@huawei.com>
Subject: [PATCH v2 1/8] perf hisi-ptt: Abstract trace data buf and offset
Date: Thu, 27 Aug 2026 22:04:35 +0800 [thread overview]
Message-ID: <20260827140442.2031128-2-liusizhe5@huawei.com> (raw)
In-Reply-To: <20260827140442.2031128-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 functions.
Signed-off-by: Sizhe Liu <liusizhe5@huawei.com>
---
.../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(-)
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 72a877fd7236..ef72223d3854 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
@@ -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);
}
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 3b349fcc24ae..6747878b030e 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
@@ -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
diff --git a/tools/perf/util/hisi-ptt.c b/tools/perf/util/hisi-ptt.c
index e73c57f9e8a4..ea659947c27f 100644
--- a/tools/perf/util/hisi-ptt.c
+++ b/tools/perf/util/hisi-ptt.c
@@ -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;
}
}
--
2.33.0
next prev parent reply other threads:[~2026-08-27 14:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 14:04 [PATCH v2 0/8] Enhance TLP packet decoder with field-level parsing and versioning Sizhe Liu
2026-08-27 14:04 ` Sizhe Liu [this message]
2026-08-27 14:14 ` [PATCH v2 1/8] perf hisi-ptt: Abstract trace data buf and offset sashiko-bot
2026-08-27 14:04 ` [PATCH v2 2/8] perf hisi-ptt: Complete the field names for 4DW and 8DW packets Sizhe Liu
2026-08-27 14:10 ` sashiko-bot
2026-08-27 14:04 ` [PATCH v2 3/8] perf hisi-ptt: Extract the raw data printing part Sizhe Liu
2026-08-27 14:09 ` sashiko-bot
2026-08-27 14:04 ` [PATCH v2 4/8] perf hisi-ptt: Merge 4DW and 8DW HEAD0 printing Sizhe Liu
2026-08-27 14:10 ` sashiko-bot
2026-08-27 14:04 ` [PATCH v2 5/8] perf hisi-ptt: Add parsing of supported message types Sizhe Liu
2026-08-27 14:12 ` sashiko-bot
2026-08-27 14:04 ` [PATCH v2 6/8] perf hisi-ptt: Add field-level parsing for header DW2/DW3 Sizhe Liu
2026-08-27 14:10 ` sashiko-bot
2026-08-27 14:04 ` [PATCH v2 7/8] hwtracing: hisi_ptt: Add pattern PMU config for trace format selection Sizhe Liu
2026-08-27 14:13 ` sashiko-bot
2026-09-01 1:31 ` Yushan Wang
2026-09-02 3:30 ` Sizhe Liu
2026-08-27 14:04 ` [PATCH v2 8/8] perf hisi-ptt: Pass pattern version to decoder for compatibility Sizhe Liu
2026-08-27 14:13 ` sashiko-bot
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=20260827140442.2031128-2-liusizhe5@huawei.com \
--to=liusizhe5@huawei.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=corbet@lwn.net \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jic23@kernel.org \
--cc=john.g.garry@oracle.com \
--cc=jolsa@kernel.org \
--cc=leo.yan@linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=mike.leach@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=prime.zeng@hisilicon.com \
--cc=rostedt@goodmis.org \
--cc=skhan@linuxfoundation.org \
--cc=wangyushan12@huawei.com \
--cc=will@kernel.org \
--cc=wuzongyu1@huawei.com \
--cc=yangyccccc@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.