Skip to content

Commit 0dea03e

Browse files
shemmingertmonjalo
authored andcommitted
pdump: remove use of VLA
Replace variable length array with refactored loop so that packets are processed in bursts of up to 32. Signed-off-by: Stephen Hemminger <[email protected]> Acked-by: Bruce Richardson <[email protected]> Acked-by: Khadem Ullah <[email protected]>
1 parent c3ceb87 commit 0dea03e

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

lib/pdump/meson.build

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ if is_windows
77
subdir_done()
88
endif
99

10-
cflags += no_wvla_cflag
11-
1210
sources = files('rte_pdump.c')
1311
headers = files('rte_pdump.h')
1412
deps += ['ethdev', 'bpf', 'pcapng']

lib/pdump/rte_pdump.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ RTE_LOG_REGISTER_DEFAULT(pdump_logtype, NOTICE);
2727
/* Used for the multi-process communication */
2828
#define PDUMP_MP "mp_pdump"
2929

30+
#define PDUMP_BURST_SIZE 32
31+
3032
/* Overly generous timeout for secondary to respond */
3133
#define MP_TIMEOUT_S 5
3234

@@ -135,20 +137,22 @@ pdump_cb_release(struct pdump_rxtx_cbs *cbs)
135137

136138
/* Create a clone of mbuf to be placed into ring. */
137139
static void
138-
pdump_copy(uint16_t port_id, uint16_t queue,
139-
enum rte_pcapng_direction direction,
140-
struct rte_mbuf **pkts, uint16_t nb_pkts,
141-
const struct pdump_rxtx_cbs *cbs,
142-
struct rte_pdump_stats *stats)
140+
pdump_copy_burst(uint16_t port_id, uint16_t queue_id,
141+
enum rte_pcapng_direction direction,
142+
struct rte_mbuf **pkts, uint16_t nb_pkts,
143+
const struct pdump_rxtx_cbs *cbs,
144+
struct rte_pdump_stats *stats)
143145
{
144146
unsigned int i;
145147
int ring_enq;
146148
uint16_t d_pkts = 0;
147-
struct rte_mbuf *dup_bufs[nb_pkts];
149+
struct rte_mbuf *dup_bufs[PDUMP_BURST_SIZE]; /* duplicated packets */
148150
struct rte_ring *ring;
149151
struct rte_mempool *mp;
150152
struct rte_mbuf *p;
151-
uint64_t rcs[nb_pkts];
153+
uint64_t rcs[PDUMP_BURST_SIZE]; /* filter result */
154+
155+
RTE_ASSERT(nb_pkts <= PDUMP_BURST_SIZE);
152156

153157
if (cbs->filter)
154158
rte_bpf_exec_burst(cbs->filter, (void **)pkts, rcs, nb_pkts);
@@ -173,8 +177,7 @@ pdump_copy(uint16_t port_id, uint16_t queue,
173177
* otherwise a simple copy.
174178
*/
175179
if (cbs->ver == V2)
176-
p = rte_pcapng_copy(port_id, queue,
177-
pkts[i], mp, cbs->snaplen,
180+
p = rte_pcapng_copy(port_id, queue_id, pkts[i], mp, cbs->snaplen,
178181
direction, NULL);
179182
else
180183
p = rte_pktmbuf_copy(pkts[i], mp, 0, cbs->snaplen);
@@ -185,6 +188,9 @@ pdump_copy(uint16_t port_id, uint16_t queue,
185188
dup_bufs[d_pkts++] = p;
186189
}
187190

191+
if (unlikely(d_pkts == 0))
192+
return;
193+
188194
rte_atomic_fetch_add_explicit(&stats->accepted, d_pkts, rte_memory_order_relaxed);
189195

190196
ring_enq = rte_ring_enqueue_burst(ring, (void *)&dup_bufs[0], d_pkts, NULL);
@@ -196,6 +202,24 @@ pdump_copy(uint16_t port_id, uint16_t queue,
196202
}
197203
}
198204

205+
/* Create a clone of mbuf to be placed into ring. */
206+
static void
207+
pdump_copy(uint16_t port_id, uint16_t queue_id,
208+
enum rte_pcapng_direction direction,
209+
struct rte_mbuf **pkts, uint16_t nb_pkts,
210+
const struct pdump_rxtx_cbs *cbs,
211+
struct rte_pdump_stats *stats)
212+
{
213+
uint16_t offs = 0;
214+
215+
do {
216+
uint16_t n = RTE_MIN(nb_pkts - offs, PDUMP_BURST_SIZE);
217+
218+
pdump_copy_burst(port_id, queue_id, direction, &pkts[offs], n, cbs, stats);
219+
offs += n;
220+
} while (offs < nb_pkts);
221+
}
222+
199223
static uint16_t
200224
pdump_rx(uint16_t port, uint16_t queue,
201225
struct rte_mbuf **pkts, uint16_t nb_pkts,

0 commit comments

Comments
 (0)