From patchwork Fri Feb 3 08:19:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Prakash Shukla X-Patchwork-Id: 123006 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 780A041BB9; Fri, 3 Feb 2023 09:19:36 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3F3D14021E; Fri, 3 Feb 2023 09:19:36 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id D36A44014F for ; Fri, 3 Feb 2023 09:19:34 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3136DjLO002093; Fri, 3 Feb 2023 00:19:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=JZXXpWIEFrpfJ3BYegkFexQ1yE4NPATglY8ZG6lNgLg=; b=RoA5Dcypbzu477dlv+eC14EDJgucc11hr6QI5erKRJM44h+31b2CF2JOPLKBcAoKTflJ hxIP2U8AWrBQzekfzMEdccPip5q/6ZgdsmopwfMXRIDauFK0InU7quff4wIVD7UXQuwG k1Cxsa6XLikHcrPv9nd75asO/OIIqpigIfpuuyb4+GI+etJYxq2FWjy5R0VZzX2xIsP2 VzxnKntSI7ugkc5MS15HH2IBlVbn6Sc+jN/kcOTK7LF+Am9/0N+TANwuo2hV3p09zBbS isHHdXo991o6caWL33oDz0HguE+RejrJSKkJaCOLRqezbVnBlSV33EkJzj2RRaVPXuJM uQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3ngqgcrx0c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 03 Feb 2023 00:19:33 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 3 Feb 2023 00:19:32 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Fri, 3 Feb 2023 00:19:32 -0800 Received: from localhost.localdomain (unknown [10.28.36.157]) by maili.marvell.com (Postfix) with ESMTP id 4734C3F704F; Fri, 3 Feb 2023 00:19:30 -0800 (PST) From: Amit Prakash Shukla To: Reshma Pattan , Stephen Hemminger CC: , , Amit Prakash Shukla Subject: [PATCH v5 1/3] pcapng: comment option support for epb Date: Fri, 3 Feb 2023 13:49:23 +0530 Message-ID: <20230203081925.2201007-1-amitprakashs@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230124112139.1426279-1-amitprakashs@marvell.com> References: <20230124112139.1426279-1-amitprakashs@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 5cgLXA8slx8e36qO5so2S5ivWYVMdLZ_ X-Proofpoint-GUID: 5cgLXA8slx8e36qO5so2S5ivWYVMdLZ_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-03_04,2023-02-02_01,2022-06-22_01 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 This change enhances rte_pcapng_copy to have comment in enhanced packet block. Signed-off-by: Amit Prakash Shukla Acked-by: Stephen Hemminger --- v2: - Fixed code style issue - Fixed CI compilation issue on github-robot v3: - Code review suggestion from Stephen - Fixed potential memory leak v4: - Code review suggestion from Jerin v5: - Code review suggestion from Jerin app/test/test_pcapng.c | 4 ++-- doc/guides/rel_notes/release_23_03.rst | 2 ++ lib/pcapng/rte_pcapng.c | 10 +++++++++- lib/pcapng/rte_pcapng.h | 4 +++- lib/pdump/rte_pdump.c | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c index a7acbdc058..303d3d66f9 100644 --- a/app/test/test_pcapng.c +++ b/app/test/test_pcapng.c @@ -139,7 +139,7 @@ test_write_packets(void) struct rte_mbuf *mc; mc = rte_pcapng_copy(port_id, 0, orig, mp, pkt_len, - rte_get_tsc_cycles(), 0); + rte_get_tsc_cycles(), 0, NULL); if (mc == NULL) { fprintf(stderr, "Cannot copy packet\n"); return -1; @@ -255,7 +255,7 @@ test_write_over_limit_iov_max(void) struct rte_mbuf *mc; mc = rte_pcapng_copy(port_id, 0, orig, mp, pkt_len, - rte_get_tsc_cycles(), 0); + rte_get_tsc_cycles(), 0, NULL); if (mc == NULL) { fprintf(stderr, "Cannot copy packet\n"); return -1; diff --git a/doc/guides/rel_notes/release_23_03.rst b/doc/guides/rel_notes/release_23_03.rst index 73f5d94e14..dab62508c4 100644 --- a/doc/guides/rel_notes/release_23_03.rst +++ b/doc/guides/rel_notes/release_23_03.rst @@ -107,6 +107,8 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* Experimental function ``rte_pcapng_copy`` was updated to support comment + section in enhanced packet block in pcapng library. ABI Changes ----------- diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c index 80d08e1a3b..acb31a9d93 100644 --- a/lib/pcapng/rte_pcapng.c +++ b/lib/pcapng/rte_pcapng.c @@ -450,7 +450,8 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, const struct rte_mbuf *md, struct rte_mempool *mp, uint32_t length, uint64_t cycles, - enum rte_pcapng_direction direction) + enum rte_pcapng_direction direction, + const char *comment) { struct pcapng_enhance_packet_block *epb; uint32_t orig_len, data_len, padding, flags; @@ -511,6 +512,9 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, if (rss_hash) optlen += pcapng_optlen(sizeof(uint8_t) + sizeof(uint32_t)); + if (comment) + optlen += pcapng_optlen(strlen(comment)); + /* reserve trailing options and block length */ opt = (struct pcapng_option *) rte_pktmbuf_append(mc, optlen + sizeof(uint32_t)); @@ -548,6 +552,10 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue, &hash_opt, sizeof(hash_opt)); } + if (comment) + opt = pcapng_add_option(opt, PCAPNG_OPT_COMMENT, comment, + strlen(comment)); + /* Note: END_OPT necessary here. Wireshark doesn't do it. */ /* Add PCAPNG packet header */ diff --git a/lib/pcapng/rte_pcapng.h b/lib/pcapng/rte_pcapng.h index 7d2697c647..6d286cda41 100644 --- a/lib/pcapng/rte_pcapng.h +++ b/lib/pcapng/rte_pcapng.h @@ -100,6 +100,8 @@ enum rte_pcapng_direction { * The timestamp in TSC cycles. * @param direction * The direction of the packer: receive, transmit or unknown. + * @param comment + * Packet comment. * * @return * - The pointer to the new mbuf formatted for pcapng_write @@ -111,7 +113,7 @@ struct rte_mbuf * rte_pcapng_copy(uint16_t port_id, uint32_t queue, const struct rte_mbuf *m, struct rte_mempool *mp, uint32_t length, uint64_t timestamp, - enum rte_pcapng_direction direction); + enum rte_pcapng_direction direction, const char *comment); /** diff --git a/lib/pdump/rte_pdump.c b/lib/pdump/rte_pdump.c index a81544cb57..9bc4bab4f2 100644 --- a/lib/pdump/rte_pdump.c +++ b/lib/pdump/rte_pdump.c @@ -122,7 +122,7 @@ pdump_copy(uint16_t port_id, uint16_t queue, if (cbs->ver == V2) p = rte_pcapng_copy(port_id, queue, pkts[i], mp, cbs->snaplen, - ts, direction); + ts, direction, NULL); else p = rte_pktmbuf_copy(pkts[i], mp, 0, cbs->snaplen); From patchwork Fri Feb 3 08:19:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Prakash Shukla X-Patchwork-Id: 123007 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 60A8C41BB9; Fri, 3 Feb 2023 09:19:41 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 49F6E410D7; Fri, 3 Feb 2023 09:19:41 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 7E34C4014F for ; Fri, 3 Feb 2023 09:19:39 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3137ru8o002722; Fri, 3 Feb 2023 00:19:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=FjLZs3F+exokBjIC0IsVsDvRWQT/WxxjTKQ6ZpTkxYs=; b=D59wDodJifn4ErIGjoLYBU5ih/VHRcztu9/A1AV2XtrdjhW0hJd5FlawbLJMRV0UNprH EmrMK51Jjn8Rq/WDJtGpbuFz0a2dpzwCUtvhPAUin7U7BclpkxRDkuYRugAz2G2taRD6 MqBNk3PyCuYDD2Rohnfl7Y6l0GBzePG0XDVTWxbKKxS5D8ngTEfpNFKdIsZmXpmGTQkg d2OdwAQaXH/WJ9w+I/C1Y1vdXWLREUuNU7e8q4l+VjY3zv6anvltLNldljjZejJOnOBO dmZ9ypdq4w4YsTUGckMYMK7oStEgVDdwqGFzg/GDf6PFbKZX7TG5/aHHD6KdjESX+cZr cg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3ngqgcrx0r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 03 Feb 2023 00:19:38 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 3 Feb 2023 00:19:36 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Fri, 3 Feb 2023 00:19:36 -0800 Received: from localhost.localdomain (unknown [10.28.36.157]) by maili.marvell.com (Postfix) with ESMTP id E717B3F704F; Fri, 3 Feb 2023 00:19:34 -0800 (PST) From: Amit Prakash Shukla To: Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram , Anatoly Burakov CC: , Amit Prakash Shukla Subject: [PATCH v5 2/3] graph: pcap capture for graph nodes Date: Fri, 3 Feb 2023 13:49:24 +0530 Message-ID: <20230203081925.2201007-2-amitprakashs@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230203081925.2201007-1-amitprakashs@marvell.com> References: <20230124112139.1426279-1-amitprakashs@marvell.com> <20230203081925.2201007-1-amitprakashs@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: pSbRrfa76Y_2fot6zkJDMpkcS_FQW93k X-Proofpoint-GUID: pSbRrfa76Y_2fot6zkJDMpkcS_FQW93k X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-03_04,2023-02-02_01,2022-06-22_01 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 Implementation adds support to capture packets at each node with packet metadata and node name. Signed-off-by: Amit Prakash Shukla --- v2: - Fixed code style issue - Fixed CI compilation issue on github-robot v3: - Code review suggestion from Stephen - Fixed potential memory leak v4: - Code review suggestion from Jerin v5: - Code review suggestion from Jerin doc/guides/rel_notes/release_23_03.rst | 7 + lib/graph/graph.c | 17 +- lib/graph/graph_pcap.c | 216 +++++++++++++++++++++++++ lib/graph/graph_pcap_private.h | 116 +++++++++++++ lib/graph/graph_populate.c | 12 +- lib/graph/graph_private.h | 5 + lib/graph/meson.build | 3 +- lib/graph/rte_graph.h | 5 + lib/graph/rte_graph_worker.h | 9 ++ 9 files changed, 387 insertions(+), 3 deletions(-) create mode 100644 lib/graph/graph_pcap.c create mode 100644 lib/graph/graph_pcap_private.h diff --git a/doc/guides/rel_notes/release_23_03.rst b/doc/guides/rel_notes/release_23_03.rst index dab62508c4..e709df8b53 100644 --- a/doc/guides/rel_notes/release_23_03.rst +++ b/doc/guides/rel_notes/release_23_03.rst @@ -78,6 +78,10 @@ New Features ``rte_event_dev_config::nb_single_link_event_port_queues`` parameter required for eth_rx, eth_tx, crypto and timer eventdev adapters. +* **Added pcap trace support in graph library.** + + * Added support to capture packets at each graph node with packet metadata and + node name. Removed Items ------------- @@ -110,6 +114,9 @@ API Changes * Experimental function ``rte_pcapng_copy`` was updated to support comment section in enhanced packet block in pcapng library. +* Experimental structures ``struct rte_graph_param``, ``struct rte_graph`` and + ``struct graph`` were updated to support pcap trace in graph library. + ABI Changes ----------- diff --git a/lib/graph/graph.c b/lib/graph/graph.c index 3a617cc369..a839a2803b 100644 --- a/lib/graph/graph.c +++ b/lib/graph/graph.c @@ -15,6 +15,7 @@ #include #include "graph_private.h" +#include "graph_pcap_private.h" static struct graph_head graph_list = STAILQ_HEAD_INITIALIZER(graph_list); static rte_spinlock_t graph_lock = RTE_SPINLOCK_INITIALIZER; @@ -228,7 +229,12 @@ graph_mem_fixup_node_ctx(struct rte_graph *graph) node_db = node_from_name(name); if (node_db == NULL) SET_ERR_JMP(ENOLINK, fail, "Node %s not found", name); - node->process = node_db->process; + + if (graph->pcap_enable) { + node->process = graph_pcap_dispatch; + node->original_process = node_db->process; + } else + node->process = node_db->process; } return graph; @@ -242,6 +248,9 @@ graph_mem_fixup_secondary(struct rte_graph *graph) if (graph == NULL || rte_eal_process_type() == RTE_PROC_PRIMARY) return graph; + if (graph_pcap_file_open(graph->pcap_filename) || graph_pcap_mp_init()) + graph_pcap_exit(graph); + return graph_mem_fixup_node_ctx(graph); } @@ -323,11 +332,17 @@ rte_graph_create(const char *name, struct rte_graph_param *prm) if (graph_has_isolated_node(graph)) goto graph_cleanup; + /* Initialize pcap config. */ + graph_pcap_enable(prm->pcap_enable); + /* Initialize graph object */ graph->socket = prm->socket_id; graph->src_node_count = src_node_count; graph->node_count = graph_nodes_count(graph); graph->id = graph_id; + graph->num_pkt_to_capture = prm->num_pkt_to_capture; + if (prm->pcap_filename) + rte_strscpy(graph->pcap_filename, prm->pcap_filename, RTE_GRAPH_PCAP_FILE_SZ); /* Allocate the Graph fast path memory and populate the data */ if (graph_fp_mem_create(graph)) diff --git a/lib/graph/graph_pcap.c b/lib/graph/graph_pcap.c new file mode 100644 index 0000000000..9cbd1b8fdb --- /dev/null +++ b/lib/graph/graph_pcap.c @@ -0,0 +1,216 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2023 Marvell International Ltd. + */ + +#include +#include +#include +#include + +#include +#include + +#include "rte_graph_worker.h" + +#include "graph_pcap_private.h" + +#define GRAPH_PCAP_BUF_SZ 128 +#define GRAPH_PCAP_NUM_PACKETS 1024 +#define GRAPH_PCAP_PKT_POOL "graph_pcap_pkt_pool" +#define GRAPH_PCAP_FILE_NAME "dpdk_graph_pcap_capture_XXXXXX.pcapng" + +/* For multi-process, packets are captured in separate files. */ +static rte_pcapng_t *pcapng_fd; +static bool pcap_enable; +struct rte_mempool *pkt_mp; + +void +graph_pcap_enable(bool val) +{ + pcap_enable = val; +} + +int +graph_pcap_is_enable(void) +{ + return pcap_enable; +} + +void +graph_pcap_exit(struct rte_graph *graph) +{ + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + if (pkt_mp) + rte_mempool_free(pkt_mp); + + if (pcapng_fd) { + rte_pcapng_close(pcapng_fd); + pcapng_fd = NULL; + } + + /* Disable pcap. */ + graph->pcap_enable = 0; + graph_pcap_enable(0); +} + +static int +graph_pcap_default_path_get(char **dir_path) +{ + struct passwd *pwd; + char *home_dir; + + /* First check for shell environment variable */ + home_dir = getenv("HOME"); + if (home_dir == NULL) { + graph_warn("Home env not preset."); + /* Fallback to password file entry */ + pwd = getpwuid(getuid()); + if (pwd == NULL) + return -EINVAL; + + home_dir = pwd->pw_dir; + } + + /* Append default pcap file to directory */ + if (asprintf(dir_path, "%s/%s", home_dir, GRAPH_PCAP_FILE_NAME) == -1) + return -ENOMEM; + + return 0; +} + +int +graph_pcap_file_open(const char *filename) +{ + int fd; + char file_name[RTE_GRAPH_PCAP_FILE_SZ]; + char *pcap_dir; + + if (pcapng_fd) + goto done; + + if (!filename || filename[0] == '\0') { + if (graph_pcap_default_path_get(&pcap_dir) < 0) + return -1; + snprintf(file_name, RTE_GRAPH_PCAP_FILE_SZ, "%s", pcap_dir); + free(pcap_dir); + } else { + snprintf(file_name, RTE_GRAPH_PCAP_FILE_SZ, "%s_XXXXXX.pcapng", + filename); + } + + fd = mkstemps(file_name, strlen(".pcapng")); + if (fd < 0) { + graph_err("mkstemps() failure"); + return -1; + } + + graph_info("pcap filename: %s", file_name); + + /* Open a capture file */ + pcapng_fd = rte_pcapng_fdopen(fd, NULL, NULL, "Graph pcap tracer", + NULL); + if (pcapng_fd == NULL) { + graph_err("Graph rte_pcapng_fdopen failed."); + close(fd); + return -1; + } + +done: + return 0; +} + +int +graph_pcap_mp_init(void) +{ + pkt_mp = rte_mempool_lookup(GRAPH_PCAP_PKT_POOL); + if (pkt_mp) + goto done; + + /* Make a pool for cloned packets */ + pkt_mp = rte_pktmbuf_pool_create_by_ops(GRAPH_PCAP_PKT_POOL, + IOV_MAX + RTE_GRAPH_BURST_SIZE, 0, 0, + rte_pcapng_mbuf_size(RTE_MBUF_DEFAULT_BUF_SIZE), + SOCKET_ID_ANY, "ring_mp_mc"); + if (pkt_mp == NULL) { + graph_err("Cannot create mempool for graph pcap capture."); + return -1; + } + +done: + return 0; +} + +int +graph_pcap_init(struct graph *graph) +{ + struct rte_graph *graph_data = graph->graph; + + if (graph_pcap_file_open(graph->pcap_filename) < 0) + goto error; + + if (graph_pcap_mp_init() < 0) + goto error; + + /* User configured number of packets to capture. */ + if (graph->num_pkt_to_capture) + graph_data->nb_pkt_to_capture = graph->num_pkt_to_capture; + else + graph_data->nb_pkt_to_capture = GRAPH_PCAP_NUM_PACKETS; + + /* All good. Now populate data for secondary process. */ + rte_strscpy(graph_data->pcap_filename, graph->pcap_filename, RTE_GRAPH_PCAP_FILE_SZ); + graph_data->pcap_enable = 1; + + return 0; + +error: + graph_pcap_exit(graph_data); + graph_pcap_enable(0); + graph_err("Graph pcap initialization failed. Disabling pcap trace."); + return -1; +} + +uint16_t +graph_pcap_dispatch(struct rte_graph *graph, + struct rte_node *node, void **objs, + uint16_t nb_objs) +{ + struct rte_mbuf *mbuf_clones[RTE_GRAPH_BURST_SIZE]; + char buffer[GRAPH_PCAP_BUF_SZ]; + uint64_t i, num_packets; + struct rte_mbuf *mbuf; + ssize_t len; + + if (!nb_objs || (graph->nb_pkt_captured >= graph->nb_pkt_to_capture)) + goto done; + + num_packets = graph->nb_pkt_to_capture - graph->nb_pkt_captured; + /* nb_objs will never be greater than RTE_GRAPH_BURST_SIZE */ + if (num_packets > nb_objs) + num_packets = nb_objs; + + snprintf(buffer, GRAPH_PCAP_BUF_SZ, "%s: %s", graph->name, node->name); + + for (i = 0; i < num_packets; i++) { + struct rte_mbuf *mc; + mbuf = (struct rte_mbuf *)objs[i]; + + mc = rte_pcapng_copy(mbuf->port, 0, mbuf, pkt_mp, mbuf->pkt_len, + rte_get_tsc_cycles(), 0, buffer); + if (mc == NULL) + break; + + mbuf_clones[i] = mc; + } + + /* write it to capture file */ + len = rte_pcapng_write_packets(pcapng_fd, mbuf_clones, i); + rte_pktmbuf_free_bulk(mbuf_clones, i); + if (len <= 0) + goto done; + + graph->nb_pkt_captured += i; + +done: + return node->original_process(graph, node, objs, nb_objs); +} diff --git a/lib/graph/graph_pcap_private.h b/lib/graph/graph_pcap_private.h new file mode 100644 index 0000000000..2ec772072c --- /dev/null +++ b/lib/graph/graph_pcap_private.h @@ -0,0 +1,116 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2023 Marvell International Ltd. + */ + +#ifndef _RTE_GRAPH_PCAP_PRIVATE_H_ +#define _RTE_GRAPH_PCAP_PRIVATE_H_ + +#include +#include + +#include "graph_private.h" + +/** + * @internal + * + * Pcap trace enable/disable function. + * + * The function is called to enable/disable graph pcap trace functionality. + * + * @param val + * Value to be set to enable/disable graph pcap trace. + */ +void graph_pcap_enable(bool val); + +/** + * @internal + * + * Check graph pcap trace is enable/disable. + * + * The function is called to check if the graph pcap trace is enabled/disabled. + * + * @return + * - 1: Enable + * - 0: Disable + */ +int graph_pcap_is_enable(void); + +/** + * @internal + * + * Initialise graph pcap trace functionality. + * + * The function invoked to allocate mempool. + * + * @return + * 0 on success and -1 on failure. + */ +int graph_pcap_mp_init(void); + +/** + * @internal + * + * Initialise graph pcap trace functionality. + * + * The function invoked to open pcap file. + * + * @param filename + * Pcap filename. + * + * @return + * 0 on success and -1 on failure. + */ +int graph_pcap_file_open(const char *filename); + +/** + * @internal + * + * Initialise graph pcap trace functionality. + * + * The function invoked when the graph pcap trace is enabled. This function + * open's pcap file and allocates mempool. Information needed for secondary + * process is populated. + * + * @param graph + * Pointer to graph structure. + * + * @return + * 0 on success and -1 on failure. + */ +int graph_pcap_init(struct graph *graph); + +/** + * @internal + * + * Exit graph pcap trace functionality. + * + * The function is called to exit graph pcap trace and close open fd's and + * free up memory. Pcap trace is also disabled. + * + * @param graph + * Pointer to graph structure. + */ +void graph_pcap_exit(struct rte_graph *graph); + +/** + * @internal + * + * Capture mbuf metadata and node metadata to a pcap file. + * + * When graph pcap trace enabled, this function is invoked prior to each node + * and mbuf, node metadata is parsed and captured in a pcap file. + * + * @param graph + * Pointer to the graph object. + * @param node + * Pointer to the node object. + * @param objs + * Pointer to an array of objects to be processed. + * @param nb_objs + * Number of objects in the array. + */ +uint16_t graph_pcap_dispatch(struct rte_graph *graph, + struct rte_node *node, void **objs, + uint16_t nb_objs); + +#endif /* _RTE_GRAPH_PCAP_PRIVATE_H_ */ diff --git a/lib/graph/graph_populate.c b/lib/graph/graph_populate.c index 102fd6c29b..2c0844ce92 100644 --- a/lib/graph/graph_populate.c +++ b/lib/graph/graph_populate.c @@ -9,6 +9,7 @@ #include #include "graph_private.h" +#include "graph_pcap_private.h" static size_t graph_fp_mem_calc_size(struct graph *graph) @@ -75,7 +76,11 @@ graph_nodes_populate(struct graph *_graph) memset(node, 0, sizeof(*node)); node->fence = RTE_GRAPH_FENCE; node->off = off; - node->process = graph_node->node->process; + if (graph_pcap_is_enable()) { + node->process = graph_pcap_dispatch; + node->original_process = graph_node->node->process; + } else + node->process = graph_node->node->process; memcpy(node->name, graph_node->node->name, RTE_GRAPH_NAMESIZE); pid = graph_node->node->parent_id; if (pid != RTE_NODE_ID_INVALID) { /* Cloned node */ @@ -183,6 +188,8 @@ graph_fp_mem_populate(struct graph *graph) int rc; graph_header_popluate(graph); + if (graph_pcap_is_enable()) + graph_pcap_init(graph); graph_nodes_populate(graph); rc = graph_node_nexts_populate(graph); rc |= graph_src_nodes_populate(graph); @@ -227,6 +234,9 @@ graph_nodes_mem_destroy(struct rte_graph *graph) int graph_fp_mem_destroy(struct graph *graph) { + if (graph_pcap_is_enable()) + graph_pcap_exit(graph->graph); + graph_nodes_mem_destroy(graph->graph); return rte_memzone_free(graph->mz); } diff --git a/lib/graph/graph_private.h b/lib/graph/graph_private.h index f9a85c8926..7d1b30b8ac 100644 --- a/lib/graph/graph_private.h +++ b/lib/graph/graph_private.h @@ -22,6 +22,7 @@ extern int rte_graph_logtype; __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__, ))) #define graph_err(...) GRAPH_LOG(ERR, __VA_ARGS__) +#define graph_warn(...) GRAPH_LOG(WARNING, __VA_ARGS__) #define graph_info(...) GRAPH_LOG(INFO, __VA_ARGS__) #define graph_dbg(...) GRAPH_LOG(DEBUG, __VA_ARGS__) @@ -100,6 +101,10 @@ struct graph { /**< Memory size of the graph. */ int socket; /**< Socket identifier where memory is allocated. */ + uint64_t num_pkt_to_capture; + /**< Number of packets to be captured per core. */ + char pcap_filename[RTE_GRAPH_PCAP_FILE_SZ]; + /**< pcap file name/path. */ STAILQ_HEAD(gnode_list, graph_node) node_list; /**< Nodes in a graph. */ }; diff --git a/lib/graph/meson.build b/lib/graph/meson.build index c7327549e8..3526d1b5d4 100644 --- a/lib/graph/meson.build +++ b/lib/graph/meson.build @@ -14,7 +14,8 @@ sources = files( 'graph_debug.c', 'graph_stats.c', 'graph_populate.c', + 'graph_pcap.c', ) headers = files('rte_graph.h', 'rte_graph_worker.h') -deps += ['eal'] +deps += ['eal', 'pcapng'] diff --git a/lib/graph/rte_graph.h b/lib/graph/rte_graph.h index b32c4bc217..c9a77297fc 100644 --- a/lib/graph/rte_graph.h +++ b/lib/graph/rte_graph.h @@ -35,6 +35,7 @@ extern "C" { #define RTE_GRAPH_NAMESIZE 64 /**< Max length of graph name. */ #define RTE_NODE_NAMESIZE 64 /**< Max length of node name. */ +#define RTE_GRAPH_PCAP_FILE_SZ 64 /**< Max length of pcap file name. */ #define RTE_GRAPH_OFF_INVALID UINT32_MAX /**< Invalid graph offset. */ #define RTE_NODE_ID_INVALID UINT32_MAX /**< Invalid node id. */ #define RTE_EDGE_ID_INVALID UINT16_MAX /**< Invalid edge id. */ @@ -164,6 +165,10 @@ struct rte_graph_param { uint16_t nb_node_patterns; /**< Number of node patterns. */ const char **node_patterns; /**< Array of node patterns based on shell pattern. */ + + bool pcap_enable; /**< Pcap enable. */ + uint64_t num_pkt_to_capture; /**< Number of packets to capture. */ + char *pcap_filename; /**< Filename in which packets to be captured.*/ }; /** diff --git a/lib/graph/rte_graph_worker.h b/lib/graph/rte_graph_worker.h index fc6fee48c8..438595b15c 100644 --- a/lib/graph/rte_graph_worker.h +++ b/lib/graph/rte_graph_worker.h @@ -44,6 +44,12 @@ struct rte_graph { rte_graph_t id; /**< Graph identifier. */ int socket; /**< Socket ID where memory is allocated. */ char name[RTE_GRAPH_NAMESIZE]; /**< Name of the graph. */ + bool pcap_enable; /**< Pcap trace enabled. */ + /** Number of packets captured per core. */ + uint64_t nb_pkt_captured; + /** Number of packets to capture per core. */ + uint64_t nb_pkt_to_capture; + char pcap_filename[RTE_GRAPH_PCAP_FILE_SZ]; /**< Pcap filename. */ uint64_t fence; /**< Fence. */ } __rte_cache_aligned; @@ -64,6 +70,9 @@ struct rte_node { char parent[RTE_NODE_NAMESIZE]; /**< Parent node name. */ char name[RTE_NODE_NAMESIZE]; /**< Name of the node. */ + /** Original process function when pcap is enabled. */ + rte_node_process_t original_process; + /* Fast path area */ #define RTE_NODE_CTX_SZ 16 uint8_t ctx[RTE_NODE_CTX_SZ] __rte_cache_aligned; /**< Node Context. */ From patchwork Fri Feb 3 08:19:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Prakash Shukla X-Patchwork-Id: 123008 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 40C3D41BB9; Fri, 3 Feb 2023 09:19:49 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CBA9041611; Fri, 3 Feb 2023 09:19:45 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id B31C341153 for ; Fri, 3 Feb 2023 09:19:44 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31389f6v026498 for ; Fri, 3 Feb 2023 00:19:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=ZbTAfsiEDgbd3ZpxwKq26X6gYktfx/o97o8xCwn1py0=; b=NS6i+xfvJ7jdZXrN+lh0bq+ZwBhfPvbAlq9BCBTqNYhWlW8lE+hJ9hAYaXQ3AZJy/Fgo ZHKhnaxVj4wG4fgWcBO373Xny6cHedII++Ou/h5OeXO3Fw4gNTeaoKYrGXZm3G9y4QCd dMD8PJzW3S+VQJS6Uc9km0Ph9+lnXhvvwlCu0nv7bOx+EFGmsiXNUel/0Fe8mc8oBuX4 sTAFscbvoY86SWVk3mD8ypn3hOJp4LyFekfhOmD0Mfk4csha9mcR1Gx+lVF3f/OUe8Du d6p0cancGSLZKpzvF4U9+ypZSxsqJ4Z8qZpInoY8DrEpcmWOFMuhm9iWfcM9XBsIOErN 3w== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3nfjrjdkq9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 03 Feb 2023 00:19:43 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 3 Feb 2023 00:19:41 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Fri, 3 Feb 2023 00:19:41 -0800 Received: from localhost.localdomain (unknown [10.28.36.157]) by maili.marvell.com (Postfix) with ESMTP id A6CF43F704F; Fri, 3 Feb 2023 00:19:39 -0800 (PST) From: Amit Prakash Shukla To: Jerin Jacob , Kiran Kumar K , Nithin Dabilpuram CC: , Amit Prakash Shukla Subject: [PATCH v5 3/3] examples/l3fwd-graph: changes to configure pcap capture Date: Fri, 3 Feb 2023 13:49:25 +0530 Message-ID: <20230203081925.2201007-3-amitprakashs@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230203081925.2201007-1-amitprakashs@marvell.com> References: <20230124112139.1426279-1-amitprakashs@marvell.com> <20230203081925.2201007-1-amitprakashs@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: MetJZ1DOOScNBPm7fqaZtAu3P8WGaO09 X-Proofpoint-GUID: MetJZ1DOOScNBPm7fqaZtAu3P8WGaO09 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-03_04,2023-02-02_01,2022-06-22_01 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 Added support to configure pcap capture. Signed-off-by: Amit Prakash Shukla --- v2: - Fixed code style issue - Fixed CI compilation issue on github-robot v3: - Code review suggestion from Stephen - Fixed potential memory leak v4: - Code review suggestion from Jerin v5: - Code review suggestion from Jerin doc/guides/sample_app_ug/l3_forward_graph.rst | 23 +++++++ examples/l3fwd-graph/main.c | 62 ++++++++++++++++++- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/doc/guides/sample_app_ug/l3_forward_graph.rst b/doc/guides/sample_app_ug/l3_forward_graph.rst index 0a3e0d44ec..585ac8c898 100644 --- a/doc/guides/sample_app_ug/l3_forward_graph.rst +++ b/doc/guides/sample_app_ug/l3_forward_graph.rst @@ -51,6 +51,9 @@ The application has a number of command line options similar to l3fwd:: [--max-pkt-len PKTLEN] [--no-numa] [--per-port-pool] + [--pcap-enable] + [--pcap-num-cap] + [--pcap-file-name] Where, @@ -69,6 +72,12 @@ Where, * ``--per-port-pool:`` Optional, set to use independent buffer pools per port. Without this option, single buffer pool is used for all ports. +* ``--pcap-enable:`` Optional, Enables packet capture in pcap format on each node with mbuf and node metadata. + +* ``--pcap-num-cap:`` Optional, Number of packets to be captured per core. + +* ``--pcap-file-name:`` Optional, Pcap filename to capture packets in. + For example, consider a dual processor socket platform with 8 physical cores, where cores 0-7 and 16-23 appear on socket 0, while cores 8-15 and 24-31 appear on socket 1. @@ -99,6 +108,20 @@ In this command: | | | | | +----------+-----------+-----------+-------------------------------------+ +To enable pcap trace on each graph, use following command: + +.. code-block:: console + + .//examples/dpdk-l3fwd-graph -l 1,2 -n 4 -- -p 0x3 --config="(0,0,1),(1,0,2)" --pcap-enable --pcap-num-cap= --pcap-file-name "" + +In this command: + +* The --pcap-enable option enables pcap trace on graph nodes. + +* The --pcap-num-cap option enables user to configure number packets to be captured per graph. Default 1024 packets per graph are captured. + +* The --pcap-file-name option enables user to give filename in which packets are to be captured. + Refer to the *DPDK Getting Started Guide* for general information on running applications and the Environment Abstraction Layer (EAL) options. diff --git a/examples/l3fwd-graph/main.c b/examples/l3fwd-graph/main.c index 6dcb6ee92b..5feeab4f0f 100644 --- a/examples/l3fwd-graph/main.c +++ b/examples/l3fwd-graph/main.c @@ -76,6 +76,12 @@ xmm_t val_eth[RTE_MAX_ETHPORTS]; /* Mask of enabled ports */ static uint32_t enabled_port_mask; +/* Pcap trace */ +static char pcap_filename[RTE_GRAPH_PCAP_FILE_SZ]; +static uint64_t packet_to_capture; +static int pcap_trace_enable; + + struct lcore_rx_queue { uint16_t port_id; uint8_t queue_id; @@ -261,7 +267,8 @@ print_usage(const char *prgname) " [--eth-dest=X,MM:MM:MM:MM:MM:MM]" " [--max-pkt-len PKTLEN]" " [--no-numa]" - " [--per-port-pool]\n\n" + " [--per-port-pool]" + " [--num-pkt-cap]\n\n" " -p PORTMASK: Hexadecimal bitmask of ports to configure\n" " -P : Enable promiscuous mode\n" @@ -270,10 +277,30 @@ print_usage(const char *prgname) "port X\n" " --max-pkt-len PKTLEN: maximum packet length in decimal (64-9600)\n" " --no-numa: Disable numa awareness\n" - " --per-port-pool: Use separate buffer pool per port\n\n", + " --per-port-pool: Use separate buffer pool per port\n" + " --pcap-enable: Enables pcap capture\n" + " --pcap-num-cap NUMPKT: Number of packets to capture\n" + " --pcap-file-name NAME: Pcap file name\n\n", prgname); } +static uint64_t +parse_num_pkt_cap(const char *num_pkt_cap) +{ + uint64_t num_pkt; + char *end = NULL; + + /* Parse decimal string */ + num_pkt = strtoull(num_pkt_cap, &end, 10); + if ((num_pkt_cap[0] == '\0') || (end == NULL) || (*end != '\0')) + return 0; + + if (num_pkt == 0) + return 0; + + return num_pkt; +} + static int parse_max_pkt_len(const char *pktlen) { @@ -404,6 +431,9 @@ static const char short_options[] = "p:" /* portmask */ #define CMD_LINE_OPT_NO_NUMA "no-numa" #define CMD_LINE_OPT_MAX_PKT_LEN "max-pkt-len" #define CMD_LINE_OPT_PER_PORT_POOL "per-port-pool" +#define CMD_LINE_OPT_PCAP_ENABLE "pcap-enable" +#define CMD_LINE_OPT_NUM_PKT_CAP "pcap-num-cap" +#define CMD_LINE_OPT_PCAP_FILENAME "pcap-file-name" enum { /* Long options mapped to a short option */ @@ -416,6 +446,9 @@ enum { CMD_LINE_OPT_NO_NUMA_NUM, CMD_LINE_OPT_MAX_PKT_LEN_NUM, CMD_LINE_OPT_PARSE_PER_PORT_POOL, + CMD_LINE_OPT_PARSE_PCAP_ENABLE, + CMD_LINE_OPT_PARSE_NUM_PKT_CAP, + CMD_LINE_OPT_PCAP_FILENAME_CAP, }; static const struct option lgopts[] = { @@ -424,6 +457,9 @@ static const struct option lgopts[] = { {CMD_LINE_OPT_NO_NUMA, 0, 0, CMD_LINE_OPT_NO_NUMA_NUM}, {CMD_LINE_OPT_MAX_PKT_LEN, 1, 0, CMD_LINE_OPT_MAX_PKT_LEN_NUM}, {CMD_LINE_OPT_PER_PORT_POOL, 0, 0, CMD_LINE_OPT_PARSE_PER_PORT_POOL}, + {CMD_LINE_OPT_PCAP_ENABLE, 0, 0, CMD_LINE_OPT_PARSE_PCAP_ENABLE}, + {CMD_LINE_OPT_NUM_PKT_CAP, 1, 0, CMD_LINE_OPT_PARSE_NUM_PKT_CAP}, + {CMD_LINE_OPT_PCAP_FILENAME, 1, 0, CMD_LINE_OPT_PCAP_FILENAME_CAP}, {NULL, 0, 0, 0}, }; @@ -498,6 +534,23 @@ parse_args(int argc, char **argv) per_port_pool = 1; break; + case CMD_LINE_OPT_PARSE_PCAP_ENABLE: + printf("Packet capture enabled\n"); + pcap_trace_enable = 1; + break; + + case CMD_LINE_OPT_PARSE_NUM_PKT_CAP: + packet_to_capture = parse_num_pkt_cap(optarg); + printf("Number of packets to capture: %"PRIu64"\n", + packet_to_capture); + break; + + case CMD_LINE_OPT_PCAP_FILENAME_CAP: + rte_strlcpy(pcap_filename, optarg, + sizeof(pcap_filename)); + printf("Pcap file name: %s\n", pcap_filename); + break; + default: print_usage(prgname); return -1; @@ -1027,6 +1080,11 @@ main(int argc, char **argv) memset(&graph_conf, 0, sizeof(graph_conf)); graph_conf.node_patterns = node_patterns; + /* Pcap config */ + graph_conf.pcap_enable = pcap_trace_enable; + graph_conf.num_pkt_to_capture = packet_to_capture; + graph_conf.pcap_filename = pcap_filename; + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { rte_graph_t graph_id; rte_edge_t i;