From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5304C624DE for ; Thu, 3 Sep 2026 07:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=16GO9nI+z9h3lP3iWDNg0HC9DHfO6KEMTyKs16sIM3o=; b=kXWf5Yzh2A7XmRjQXWwL9oWBO1 NAZCWle4VpMYLiRNqhIW/z35mXGPdF/3bbcXsu7WPzmWkZ4w2W16Af0GnQIYMXUX/0Mj0FvT0Rytk EC8Ryz2w2s9GZ3j08C//xvGJfrcUgig3M//QWqdYjyEygcXlLrOtO5bGTrAFCjzkafpclDWPKvLB3 iOdpdoRoUKJpyWfkaCdCtTzzWhBHey4eIwzXfDPxXi0B+Wkqj+jUPssYRNa7gzqqKYec3/Ry/RvOc pxTUS+jyl0U1RTCER/QqUmVx+BqBd7LiKrf4i+wNVvFfOXfHp3mH2KI/AD7GakmT37+k/uqtSwHGj Pie4veBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x22Fz-0000000Gh99-04Fh; Thu, 03 Sep 2026 07:53:11 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x22Fx-0000000Gh7C-3zTH for linux-arm-kernel@bombadil.infradead.org; Thu, 03 Sep 2026 07:53:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=16GO9nI+z9h3lP3iWDNg0HC9DHfO6KEMTyKs16sIM3o=; b=j28rxaNr7kiKutbZ4d9pQ7Nwyx TtRpbqkYVuOQ50+WFtr9M4xL/Rh8q5UZ6KIfTxLXhaljd2BYNkZreRYJj/f2mdj+cVc7++X9HZTUi Y/smMJ4sRs0k7MI+py/vNyheMiNkyBSyv8jsY9gFU6c7sGpWvUnaoFWHVfcwvkgQ4EAWjStj6l+h5 /yw+NzsQRgcSeiM5o+rsnqXfcNpzQUdAjZPIc6sudoRiYE2Zr6bkcjh9PqEjmiSl6VUxgw8Z3gWSo SAuXSzclIUligb2bk8gfhpz+Xhm+9vsnmgsQ/xhynJGVWWLD0GbLBaGd5eESFp3nC+7cMbvuGsaIQ VMN9f4iw==; Received: from canpmsgout04.his.huawei.com ([113.46.200.219]) by desiato.infradead.org with esmtps (Exim 4.99.2 #2 (Red Hat Linux)) id 1x22Fs-0000000Coos-33tU for linux-arm-kernel@lists.infradead.org; Thu, 03 Sep 2026 07:53:08 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=16GO9nI+z9h3lP3iWDNg0HC9DHfO6KEMTyKs16sIM3o=; b=N9HRA88Ako3kNVoQrRVKt31rjfcmDS4XKLKCK5pk15NcIehh5pqQ+xDUhWv6ar0CghtyKACML wyML2sAgs9fx+IfQRva95aYsE0tnYw7A+UAaTBK0wD9AdgohrPMYEeuGdLG79eZolv/PBRTY6iO qUMED4xvPb90DsYUt/I1DKQ= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4hbBPb2Bgfz1prlh; Thu, 3 Sep 2026 15:41:55 +0800 (CST) Received: from whupemo200004.china.huawei.com (unknown [7.152.184.18]) by mail.maildlp.com (Postfix) with ESMTPS id 8AE9540575; Thu, 3 Sep 2026 15:52:47 +0800 (CST) Received: from huawei.com (10.50.163.32) by whupemo200004.china.huawei.com (7.152.184.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Thu, 3 Sep 2026 15:52:45 +0800 From: Sizhe Liu To: , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH v3 1/8] perf hisi-ptt: Abstract trace data buf and offset Date: Thu, 3 Sep 2026 15:52:34 +0800 Message-ID: <20260903075241.1445338-2-liusizhe5@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20260903075241.1445338-1-liusizhe5@huawei.com> References: <20260903075241.1445338-1-liusizhe5@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To whupemo200004.china.huawei.com (7.152.184.18) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260903_085305_649524_C983A49A X-CRM114-Status: GOOD ( 15.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Reviewed-by: Yushan Wang Signed-off-by: Sizhe Liu --- .../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