From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Bruce Richardson <bruce.richardson@intel.com>,
Khadem Ullah <14pwcse1224@uetpeshawar.edu.pk>,
Reshma Pattan <reshma.pattan@intel.com>
Subject: [PATCH v5 7/8] pdump: remove use of VLA
Date: Fri, 24 Oct 2025 14:54:02 -0700 [thread overview]
Message-ID: <20251024215456.282171-8-stephen@networkplumber.org> (raw)
In-Reply-To: <20251024215456.282171-1-stephen@networkplumber.org>
Replace variable length array with refactored loop so that
packets are processed in bursts of up to 32.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Khadem Ullah <14pwcse1224@uetpeshawar.edu.pk>
---
lib/pdump/meson.build | 2 --
lib/pdump/rte_pdump.c | 59 ++++++++++++++++++++++++++++---------------
2 files changed, 39 insertions(+), 22 deletions(-)
diff --git a/lib/pdump/meson.build b/lib/pdump/meson.build
index 553dfdd5e6..da8d51b616 100644
--- a/lib/pdump/meson.build
+++ b/lib/pdump/meson.build
@@ -7,8 +7,6 @@ if is_windows
subdir_done()
endif
-cflags += no_wvla_cflag
-
sources = files('rte_pdump.c')
headers = files('rte_pdump.h')
deps += ['ethdev', 'bpf', 'pcapng']
diff --git a/lib/pdump/rte_pdump.c b/lib/pdump/rte_pdump.c
index 305325847c..33914d8745 100644
--- a/lib/pdump/rte_pdump.c
+++ b/lib/pdump/rte_pdump.c
@@ -27,6 +27,8 @@ RTE_LOG_REGISTER_DEFAULT(pdump_logtype, NOTICE);
/* Used for the multi-process communication */
#define PDUMP_MP "mp_pdump"
+#define PDUMP_BURST_SIZE 32
+
/* Overly generous timeout for secondary to respond */
#define MP_TIMEOUT_S 5
@@ -135,27 +137,22 @@ pdump_cb_release(struct pdump_rxtx_cbs *cbs)
/* Create a clone of mbuf to be placed into ring. */
static void
-pdump_copy(uint16_t port_id, uint16_t queue,
- enum rte_pcapng_direction direction,
- struct rte_mbuf **pkts, uint16_t nb_pkts,
- const struct pdump_rxtx_cbs *cbs,
- struct rte_pdump_stats *stats)
+pdump_copy_burst(uint16_t port_id, uint16_t queue_id,
+ enum rte_pcapng_direction direction,
+ struct rte_mbuf **pkts, uint16_t nb_pkts,
+ const struct pdump_rxtx_cbs *cbs,
+ struct rte_pdump_stats *stats)
{
- unsigned int i;
- int ring_enq;
- uint16_t d_pkts = 0;
- struct rte_mbuf *dup_bufs[nb_pkts];
- struct rte_ring *ring;
- struct rte_mempool *mp;
- struct rte_mbuf *p;
- uint64_t rcs[nb_pkts];
+ uint16_t d_pkts = 0; /* number of duplicated packets */
+ struct rte_mbuf *dup_bufs[PDUMP_BURST_SIZE]; /* duplicated packets */
+ uint64_t rcs[PDUMP_BURST_SIZE]; /* filter result */
+
+ RTE_ASSERT(nb_pkts <= PDUMP_BURST_SIZE);
if (cbs->filter)
rte_bpf_exec_burst(cbs->filter, (void **)pkts, rcs, nb_pkts);
- ring = cbs->ring;
- mp = cbs->mp;
- for (i = 0; i < nb_pkts; i++) {
+ for (unsigned int i = 0; i < nb_pkts; i++) {
/*
* This uses same BPF return value convention as socket filter
* and pcap_offline_filter.
@@ -172,12 +169,12 @@ pdump_copy(uint16_t port_id, uint16_t queue,
* If using pcapng then want to wrap packets
* otherwise a simple copy.
*/
+ struct rte_mbuf *p;
if (cbs->ver == V2)
- p = rte_pcapng_copy(port_id, queue,
- pkts[i], mp, cbs->snaplen,
+ p = rte_pcapng_copy(port_id, queue_id, pkts[i], cbs->mp, cbs->snaplen,
direction, NULL);
else
- p = rte_pktmbuf_copy(pkts[i], mp, 0, cbs->snaplen);
+ p = rte_pktmbuf_copy(pkts[i], cbs->mp, 0, cbs->snaplen);
if (unlikely(p == NULL))
rte_atomic_fetch_add_explicit(&stats->nombuf, 1, rte_memory_order_relaxed);
@@ -185,9 +182,13 @@ pdump_copy(uint16_t port_id, uint16_t queue,
dup_bufs[d_pkts++] = p;
}
+ if (d_pkts == 0)
+ return;
+
rte_atomic_fetch_add_explicit(&stats->accepted, d_pkts, rte_memory_order_relaxed);
- ring_enq = rte_ring_enqueue_burst(ring, (void *)&dup_bufs[0], d_pkts, NULL);
+ unsigned int ring_enq
+ = rte_ring_enqueue_burst(cbs->ring, (void *)&dup_bufs[0], d_pkts, NULL);
if (unlikely(ring_enq < d_pkts)) {
unsigned int drops = d_pkts - ring_enq;
@@ -196,6 +197,24 @@ pdump_copy(uint16_t port_id, uint16_t queue,
}
}
+/* Create a clone of mbuf to be placed into ring. */
+static void
+pdump_copy(uint16_t port_id, uint16_t queue_id,
+ enum rte_pcapng_direction direction,
+ struct rte_mbuf **pkts, uint16_t nb_pkts,
+ const struct pdump_rxtx_cbs *cbs,
+ struct rte_pdump_stats *stats)
+{
+ uint16_t offs = 0;
+
+ do {
+ uint16_t n = RTE_MIN(nb_pkts - offs, PDUMP_BURST_SIZE);
+
+ pdump_copy_burst(port_id, queue_id, direction, &pkts[offs], n, cbs, stats);
+ offs += n;
+ } while (offs < nb_pkts);
+}
+
static uint16_t
pdump_rx(uint16_t port, uint16_t queue,
struct rte_mbuf **pkts, uint16_t nb_pkts,
--
2.51.0
next prev parent reply other threads:[~2025-10-24 21:55 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <250811213632.16023-1-stephen@networkplumber.org>
2025-10-19 16:56 ` [PATCH v3 0/8] packet capture bugfix and improvements Stephen Hemminger
2025-10-19 16:56 ` [PATCH v3 1/8] dumpcap: handle primary process exit Stephen Hemminger
2025-10-19 16:56 ` [PATCH v3 2/8] pdump: " Stephen Hemminger
2025-10-19 16:56 ` [PATCH v3 3/8] pdump: fix races in callbacks Stephen Hemminger
2025-10-19 16:56 ` [PATCH v3 4/8] dumpcap: handle pdump requests from primary Stephen Hemminger
2025-10-19 16:56 ` [PATCH v3 5/8] pdump: " Stephen Hemminger
2025-10-19 16:56 ` [PATCH v3 6/8] pdump: forward callback enable to secondary Stephen Hemminger
2025-10-19 16:56 ` [PATCH v3 7/8] pdump: remove use of VLA Stephen Hemminger
2025-10-19 16:56 ` [PATCH v3 8/8] doc: update documentation on pdump library Stephen Hemminger
2025-10-21 15:11 ` Stephen Hemminger
2025-10-22 17:29 ` [PATCH v3 0/8] packet capture bugfix and improvements Patrick Robb
2025-10-23 15:46 ` [PATCH v4 0/8] packet capture bugfix and secondary support Stephen Hemminger
2025-10-23 15:46 ` [PATCH v4 1/8] dumpcap: handle primary process exit Stephen Hemminger
2025-10-23 16:13 ` Bruce Richardson
2025-10-23 15:46 ` [PATCH v4 2/8] pdump: " Stephen Hemminger
2025-10-23 16:14 ` Bruce Richardson
2025-10-23 15:46 ` [PATCH v4 3/8] pdump: fix races in callbacks Stephen Hemminger
2025-10-23 15:46 ` [PATCH v4 4/8] dumpcap: handle pdump requests from primary Stephen Hemminger
2025-10-23 16:18 ` Bruce Richardson
2025-10-23 15:46 ` [PATCH v4 5/8] pdump: " Stephen Hemminger
2025-10-23 16:21 ` Bruce Richardson
2025-10-23 15:46 ` [PATCH v4 6/8] pdump: forward callback enable to secondary Stephen Hemminger
2025-10-23 15:46 ` [PATCH v4 7/8] pdump: remove use of VLA Stephen Hemminger
2025-10-23 15:46 ` [PATCH v4 8/8] doc: update documentation on pdump library Stephen Hemminger
2025-10-23 16:22 ` [PATCH v4 0/8] packet capture bugfix and secondary support Bruce Richardson
2025-10-23 16:39 ` Khadem Ullah
2025-10-24 21:53 ` [PATCH v5 0/8] packet capture bugfixes and secondary process Stephen Hemminger
2025-10-24 21:53 ` [PATCH v5 1/8] dumpcap: handle primary process exit Stephen Hemminger
2025-10-24 21:53 ` [PATCH v5 2/8] pdump: " Stephen Hemminger
2025-10-24 21:53 ` [PATCH v5 3/8] pdump: fix races in callbacks Stephen Hemminger
2025-10-24 21:53 ` [PATCH v5 4/8] dumpcap: handle pdump requests from primary Stephen Hemminger
2025-10-24 21:54 ` [PATCH v5 5/8] pdump: " Stephen Hemminger
2025-10-24 21:54 ` [PATCH v5 6/8] pdump: forward callback enable to secondary Stephen Hemminger
2025-10-24 21:54 ` Stephen Hemminger [this message]
2025-10-24 21:54 ` [PATCH v5 8/8] doc: update documentation on pdump library Stephen Hemminger
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=20251024215456.282171-8-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=14pwcse1224@uetpeshawar.edu.pk \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=reshma.pattan@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).