From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B35D042996; Thu, 20 Apr 2023 12:09:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AA3F342D12; Thu, 20 Apr 2023 12:08:48 +0200 (CEST) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2063.outbound.protection.outlook.com [40.107.223.63]) by mails.dpdk.org (Postfix) with ESMTP id E399042D0D for ; Thu, 20 Apr 2023 12:08:45 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FCxK2w9zzcJtArclvc4vQamXnHrUHQ5Ai0M7ELvO9c5Ngolnv23NR8Hc5+WjXp51F6x4ce1GcTofXX17VrBKkekbIqN6+VPdV14TuYNqK/EHp0VB4C3cDgfHfnPNUW51UjcffIBDNtGn1eF064Vc50ADdwcjy2rLEbRzMseuE3+/8IBbCJCIXrQFh+CkMcYMfj4laVHgzGAiyALx7VcDOuz7+w6wFtrkjws9gfiOdm0tBTRNlWJH3oKD43anSjrf0/u472GqzU/G492hiuc0zqxgre3crthGtAz30Aaneyjly1uAbKncDqD4+ifS56I4HludajLO7SHWYnBwZPN8oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MYiacIuwMsvJ4xeh+TMKQLFoa38kzzHwJ+42WXNm0ZU=; b=L/zWtOMx7yV7NLl7j6Xr8pvLu+IzKkfxbFmi57lWLdSqR+FLbL2rjyXV8ytI91Qn7LeopNsA6GgzcUoBeGwfkDy/CqWJA9hAnRZifWkYepsVxv8hoft+aTL1nwBknZOBWhZ21qlBYlI4tw2GxIsNCHBNRTnGezDC6ue4zGaaSIFA0qhIyfCIzK/uTWX0Vl1OQG/IMJZSkJ2go11I2FfkVyvclKXd+m4tEhPp2FeobYNVuPCeyWfjRw3MWxBpBn56Sbivd9wi2vNTG91ABDe5bqlGHrHiA34lJi9g7isMogqWyE+9Ez27vlk59veytVkn7N62/kBxBUpdd0E5sTxi8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MYiacIuwMsvJ4xeh+TMKQLFoa38kzzHwJ+42WXNm0ZU=; b=FvIdFrNbVBoFyoNeR84F/PB+K8NFsBe9yyRawE99YGvh8SSf2iGvZz/VoWJOqqZYJ0+DG3Mh3TQcfWv/jRbTOuUKVZgKm1KPxHX/qQRN2sZkZ7KXbg0vHdpiZVsy+nyFbNWXRAg3KAiuxoDuLa2jYqC1LaU/XaUnHV202Pe8VYYm/zV0lpZ0GdU44yYGmaz0vEkghlI62ITzTQaDKZPfQFZ1ZbCPpyUx60NaTpTWZBMZ8MRjAzMFfzYrSpHiZ/eXIV1Zi4739HcbQ+X8h4oPCFzyDzfNqT58Jhk4QDe0VG/nJzcpD74s8UP6wtwu2hfHGG2Ki6+FE98iJFT+JECl0A== Received: from DM6PR02CA0095.namprd02.prod.outlook.com (2603:10b6:5:1f4::36) by SJ1PR12MB6196.namprd12.prod.outlook.com (2603:10b6:a03:456::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.21; Thu, 20 Apr 2023 10:08:44 +0000 Received: from DM6NAM11FT087.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1f4:cafe::f) by DM6PR02CA0095.outlook.office365.com (2603:10b6:5:1f4::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.25 via Frontend Transport; Thu, 20 Apr 2023 10:08:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DM6NAM11FT087.mail.protection.outlook.com (10.13.172.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22 via Frontend Transport; Thu, 20 Apr 2023 10:08:43 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Thu, 20 Apr 2023 03:08:32 -0700 Received: from nvidia.com (10.126.230.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Thu, 20 Apr 2023 03:08:31 -0700 From: Viacheslav Ovsiienko To: Subject: [RFC 5/5] net/mlx5: add Tx datapath trace analyzing script Date: Thu, 20 Apr 2023 13:08:03 +0300 Message-ID: <20230420100803.494-6-viacheslavo@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20230420100803.494-1-viacheslavo@nvidia.com> References: <20230420100803.494-1-viacheslavo@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.230.37] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT087:EE_|SJ1PR12MB6196:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c7f966b-d9f3-42b3-9d8e-08db41873942 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ylhbbba2sLdngZNJRGLzbmRwjoyMp+q9gokc3/HY5YSyP+HsSvu2HDdMYnmvOn/tAl4l9Q9MJsdK6Cu1ir2uFBmABK1ESQ33fgMk9oyyQo4tuk5ArlL9soXNOTaoEtEMA7cxgLlfGlIB8rtXccwmUk5MnN/UrSUCOCNJboA7mr5rVZ2icxZs1anYULlTdSoYf7OjCgjsGCghJz640/SCdiXwq+a7B8UANYg+gBvtZngVJWPlKno5aYphAB/uKaeYvHaAC0skbrIAObbafRuTVpywRu1iCuIjWIm+vT3JP+4+lG5QX+1r9ak9xnx2YWZmJfkNBDtF48mcA6+TMTfcr8vqyEWwzMAoRtbTLuKmRX5xcbvbE3S6ci6lbfuR/fHSISwMA3Fe1HVOYGToMdY2rz+6NDHUD3zvp6Jc5cqD8UYcLNiV9wGy86uu/fpLUtXgxSpTSBettoRNBtUctFkC0qv6WvX9iJq3AHBZ2vneL3RPCHDx3jlhKW5/bjwbcJJS4Pm2l6DdIuCIGNufe+NXKOs1nETz9YB4CjDx1fBuBBpqOLLQbg/KkpyacthkthYBM4o7JpbuLkQCSqVBGHlZBKRXttlxcIxW/sbqzIHk/bCyM1RaqUWlV/3TsCFWM6UvjgOvEMMbILnyqLC+kllT8od1sH1QMtbP2NR/KgxVQnqqWCRVJyJ7Wff6Q/1cN4fGEx0RSV24KFQk3RH9r489HXApGm/rxWfpnDlA5GneKlzVF1NURI2ZTbN3MmmFIinp/1dMwnME4G35lN9FkcgFZxqMgF33ucQjwRZICC81vl8= X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(396003)(376002)(136003)(346002)(451199021)(36840700001)(46966006)(40470700004)(40480700001)(55016003)(82310400005)(6916009)(316002)(1076003)(16526019)(186003)(40460700003)(26005)(6286002)(47076005)(36860700001)(478600001)(426003)(2616005)(41300700001)(336012)(83380400001)(356005)(6666004)(82740400003)(7696005)(70206006)(70586007)(7636003)(8936002)(86362001)(36756003)(2906002)(34020700004)(8676002)(5660300002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 10:08:43.8708 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3c7f966b-d9f3-42b3-9d8e-08db41873942 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT087.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6196 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The Python script is intended to analyze mlx5 PMD datapath traces and report: - tx_burst routine timings - how packets are pushed to WQEs - how packet sending is completed with timings Signed-off-by: Viacheslav Ovsiienko --- drivers/net/mlx5/tools/mlx5_trace.py | 271 +++++++++++++++++++++++++++ 1 file changed, 271 insertions(+) create mode 100755 drivers/net/mlx5/tools/mlx5_trace.py diff --git a/drivers/net/mlx5/tools/mlx5_trace.py b/drivers/net/mlx5/tools/mlx5_trace.py new file mode 100755 index 0000000000..c8fa63a7b9 --- /dev/null +++ b/drivers/net/mlx5/tools/mlx5_trace.py @@ -0,0 +1,271 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (c) 2023 NVIDIA Corporation & Affiliates + +''' +Analyzing the mlx5 PMD datapath tracings +''' +import sys +import argparse +import pathlib +import bt2 + +PFX_TX = "pmd.net.mlx5.tx." +PFX_TX_LEN = len(PFX_TX) + +tx_blst = {} # current Tx bursts per CPU +tx_qlst = {} # active Tx queues per port/queue +tx_wlst = {} # wait timestamp list per CPU + +class mlx5_queue(object): + def __init__(self): + self.done_burst = [] # completed bursts + self.wait_burst = [] # waiting for completion + self.pq_id = 0 + + def log(self): + for txb in self.done_burst: + txb.log() + + +class mlx5_mbuf(object): + def __init__(self): + self.wqe = 0 # wqe id + self.ptr = None # first packet mbuf pointer + self.len = 0 # packet data length + self.nseg = 0 # number of segments + + def log(self): + out = " %X: %u" % (self.ptr, self.len) + if self.nseg != 1: + out += " (%d segs)" % self.nseg + print(out) + + +class mlx5_wqe(object): + def __init__(self): + self.mbuf = [] # list of mbufs in WQE + self.wait_ts = 0 # preceding wait/push timestamp + self.comp_ts = 0 # send/recv completion timestamp + self.opcode = 0 + + def log(self): + id = (self.opcode >> 8) & 0xFFFF + op = self.opcode & 0xFF + fl = self.opcode >> 24 + out = " %04X: " % id + if op == 0xF: + out += "WAIT" + elif op == 0x29: + out += "EMPW" + elif op == 0xE: + out += "TSO " + elif op == 0xA: + out += "SEND" + else: + out += "0x%02X" % op + if self.comp_ts != 0: + out += " (%d, %d)" % (self.wait_ts, self.comp_ts - self.wait_ts) + else: + out += " (%d)" % self.wait_ts + print(out) + for mbuf in self.mbuf: + mbuf.log() + + # return 0 if WQE in not completed + def comp(self, wqe_id, ts): + if self.comp_ts != 0: + return 1 + id = (self.opcode >> 8) & 0xFFFF + if id > wqe_id: + id -= wqe_id + if id <= 0x8000: + return 0 + else: + id = wqe_id - id + if id >= 0x8000: + return 0 + self.comp_ts = ts + return 1 + + +class mlx5_burst(object): + def __init__(self): + self.wqes = [] # issued burst WQEs + self.done = 0 # number of sent/recv packets + self.req = 0 # requested number of packets + self.call_ts = 0 # burst routine invocation + self.done_ts = 0 # burst routine done + self.queue = None + + def log(self): + port = self.queue.pq_id >> 16 + queue = self.queue.pq_id & 0xFFFF + if self.req == 0: + print("%u: tx(p=%u, q=%u, %u/%u pkts (incomplete)" % + (self.call_ts, port, queue, self.done, self.req)) + else: + print("%u: tx(p=%u, q=%u, %u/%u pkts in %u" % + (self.call_ts, port, queue, self.done, self.req, + self.done_ts - self.call_ts)) + for wqe in self.wqes: + wqe.log() + + # return 0 if not all of WQEs in burst completed + def comp(self, wqe_id, ts): + wlen = len(self.wqes) + if wlen == 0: + return 0 + for wqe in self.wqes: + if wqe.comp(wqe_id, ts) == 0: + return 0 + return 1 + + +def do_tx_entry(msg): + event = msg.event + cpu_id = event["cpu_id"] + burst = tx_blst.get(cpu_id) + if burst is not None: + # continue existing burst after WAIT + return + # allocate the new burst and append to the queue + burst = mlx5_burst() + burst.call_ts = msg.default_clock_snapshot.ns_from_origin + tx_blst[cpu_id] = burst + pq_id = event["port_id"] << 16 | event["queue_id"] + queue = tx_qlst.get(pq_id) + if queue is None: + # queue does not exist - allocate the new one + queue = mlx5_queue(); + queue.pq_id = pq_id + tx_qlst[pq_id] = queue + burst.queue = queue + queue.wait_burst.append(burst) + + +def do_tx_exit(msg): + event = msg.event + cpu_id = event["cpu_id"] + burst = tx_blst.get(cpu_id) + if burst is None: + return + burst.done_ts = msg.default_clock_snapshot.ns_from_origin + burst.req = event["nb_req"] + burst.done = event["nb_sent"] + tx_blst.pop(cpu_id) + + +def do_tx_wqe(msg): + event = msg.event + cpu_id = event["cpu_id"] + burst = tx_blst.get(cpu_id) + if burst is None: + return + wqe = mlx5_wqe() + wqe.wait_ts = tx_wlst.get(cpu_id) + if wqe.wait_ts is None: + wqe.wait_ts = msg.default_clock_snapshot.ns_from_origin + wqe.opcode = event["opcode"] + burst.wqes.append(wqe) + + +def do_tx_wait(msg): + event = msg.event + cpu_id = event["cpu_id"] + tx_wlst[cpu_id] = event["ts"] + + +def do_tx_push(msg): + event = msg.event + cpu_id = event["cpu_id"] + burst = tx_blst.get(cpu_id) + if burst is None: + return + if not burst.wqes: + return + wqe = burst.wqes[-1] + mbuf = mlx5_mbuf() + mbuf.wqe = event["wqe_id"] + mbuf.ptr = event["mbuf"] + mbuf.len = event["mbuf_pkt_len"] + mbuf.nseg = event["mbuf_nb_segs"] + wqe.mbuf.append(mbuf) + + +def do_tx_complete(msg): + event = msg.event + pq_id = event["port_id"] << 16 | event["queue_id"] + queue = tx_qlst.get(pq_id) + if queue is None: + return + qlen = len(queue.wait_burst) + if qlen == 0: + return + wqe_id = event["wqe_id"] + ts = event["ts"] + rmv = 0 + while rmv < qlen: + burst = queue.wait_burst[rmv] + if burst.comp(wqe_id, ts) == 0: + break + rmv += 1 + # mode completed burst to done list + if rmv != 0: + idx = 0 + while idx < rmv: + queue.done_burst.append(burst) + idx += 1 + del queue.wait_burst[0:rmv] + + +def do_tx(msg): + name = msg.event.name[PFX_TX_LEN:] + if name == "entry": + do_tx_entry(msg) + elif name == "exit": + do_tx_exit(msg) + elif name == "wqe": + do_tx_wqe(msg) + elif name == "wait": + do_tx_wait(msg) + elif name == "push": + do_tx_push(msg) + elif name == "complete": + do_tx_complete(msg) + else: + print("Error: unrecognized Tx event name: %s" % msg.event.name) + sys.exit(1) + + +def do_log(msg_it): + for msg in msg_it: + if type(msg) is not bt2._EventMessageConst: + continue + event = msg.event + if event.name.startswith(PFX_TX): + do_tx(msg) + # Handling of other log event cathegories can be added here + + +def do_print(): + for pq_id in tx_qlst: + queue = tx_qlst.get(pq_id) + queue.log() + + +def main(args): + parser = argparse.ArgumentParser() + parser.add_argument("path", + nargs = 1, + type = str, + help = "input trace folder") + args = parser.parse_args() + + msg_it = bt2.TraceCollectionMessageIterator(args.path) + do_log(msg_it) + do_print() + exit(0) + +if __name__ == "__main__": + main(sys.argv) -- 2.18.1