Skip to content

dpdk: RX buffering + Unit tests mash-up v2.1 - #16752

Open
lukashino wants to merge 31 commits into
OISF:mainfrom
lukashino:feat/9111-6927-dpdk-buffering-unit-tests-v2.1
Open

lukashino wants to merge 31 commits into
OISF:mainfrom
lukashino:feat/9111-6927-dpdk-buffering-unit-tests-v2.1

Conversation

@lukashino

@lukashino lukashino commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up of #16749 and an extension of #16751

If somebody would like to take an extra review of 2 commits (as compared to #16751 ) for the RX backlog, the merging process can be more efficient. This PR is just a feature-extension (the top 2 commits) over #16751

DPDK Suricata, when under heavier traffic bursts (e.g. 100k packets per worker), can get under pressure. The normal operation would receive 32 packets as RX burst. If processing of those 32 packets take longer than arrival rate, the RX descriptors can quickly fill up and Suricata loses packets. I believe Intel NICs are especially prone to this as they only allow setting up to 4k descriptors.

This PR adds a configurable packet backlog to individual workers (rx-backlog-size, disabled by default). If the backlog is empty and the worker receives <32 packets at once, the operation is as usual and the packets are processed immediately. If the worker receives 32 packets, so full burst, it then switches to the backlog mode and drains additional thousand packets proactively. From then the operation alternates between backlog filling and processing until the backlog is emptied.

Basic testing and reproducer was evaluated in https://redmine.openinfosecfoundation.org/issues/9111#note-1

Link to ticket:

Describe changes:
v2.1:

  • fixed build failure in unit tests

v2:

  • unit tests + DPDK fixes split one branch; this branch is "the branch" plus the ring buffer and the RX backlog (top 2 commits)
  • upgrade note: packets held in the RX backlog are timestamped when they are processed (Copilot)
  • Copilot remark on the failure exits skipping the shutdown barrier check-in: not changed, the same exit exists on main (see the reply in the thread)
  • rebased

v1 (mash-up of #16092 v14.1 and #16292 v1.3):

  • the unit-test changes listed under v15
  • qa/live/dpdk/dpdk-testsuite.sh removed (Jason), and the SV live tests that only checked the mempool sizing too, as unit tests cover it; these SV tests still expected the old sizes, which is what made the DPDK CI of dpdk: add backlog/buffering for heavy traffic bursts v1.3 #16292 red
  • packets still queued in the backlog when Suricata stops are processed before the worker exits
  • the backlog drain stops only on a return shorter than one RX burst, as vectorized PMDs (e.g. ixgbe) return at most one burst per call
  • bond: only the descriptors are multiplied by the member count, the backlog and the RX burst reserve are added once (review bot remark in dpdk: add backlog/buffering for heavy traffic bursts v1.3 #16292)
  • unit tests for the rx-backlog-size validation and for the backlog share of the mempool size (DPDKRunmodeSetRxBacklogSize01, DPDKRunmodeSetMempoolSize09-10)
  • shutdown barrier race fix, capture counters updated on idle polls
  • upgrade guide notes for DPDK 21.11, the mempool sizing, the per-burst timestamps and rx-backlog-size
  • rx-backlog-size doc typo fixed (Copilot)
  • SV live test with the RX backlog enabled (dpdk-ids-rx-backlog)

SV_BRANCH=OISF/suricata-verify#3584

Lukas Sismis added 30 commits November 26, 2026 16:30
Define the DPDK packet and error counters emitted by the capture module
so that EVE statistics validate against the schema.
The mempool sizing cases will be covered by the DPDK unit tests in
src/runmode-dpdk.c, and the cases that need a DPDK port by the
suricata-verify live tests (dpdk-config-*, dpdk-ids-*). Keeping the
script as well means every mempool sizing change has to update two
test suites.
When Suricata exits during startup it never writes a stats event, so jq
returns an empty string and the test aborted the comparison with
"unary operator expected".
Quote the value and compare it against the expected outcome, so an empty
result fails the same way a false one does.
The configured mempool of 511 mbufs is split between the worker queues,
which limits how many workers can start. As the test runs with
"threads: auto", it refuses to start on a host with more cores than the
fixed pool can serve.
Raise the minimum supported DPDK version to 21.11 and remove compatibility
paths for older releases, including legacy bond library detection and RSS
configuration. Update the documented version requirement.
Record the acquisition time immediately after each successful receive and
pass it to packet initialization. All packets in a burst retain that time
instead of including the processing delay of preceding packets.
The processing pipeline already releases the failed Packet. Avoid releasing
it twice, and free every remaining received mbuf using the array's exclusive
end index. Return the packet acquisition failure code consistently.
Share the RX burst size with the configuration code and reserve one burst
per worker in addition to the RX and TX descriptors for both automatic
sizing and manual minimum validation. Consolidate the two requirement
calculations. On a bond port only the descriptors are per member port, so
the member count multiplies them alone and the per-worker reserve is added
once. The sizing takes the member count as an argument, the bonding helper
only reports it, and a requirement that does not fit is a configuration
error like any other.
Workers synchronize at shutdown by incrementing a shared check-in
counter and spinning until it reaches the worker count. The first
worker then reset the counter after a 20 us delay. A worker that is
descheduled between its own increment and its check of the full count
never observes it after the reset, so it spins forever and Suricata
never exits.

As the counter is never reused afterwards, we can remove the reset
and mitigate the potential race.
An empty poll in polling mode skipped the rest of the loop iteration,
so an idle worker 0 never dumped its capture counters and never served a
sync requested by the stats thread. The port-level drop counters, which
only the first worker reports, stayed stale while that worker saw no
traffic.

Run the periodic counter dump and the stats sync on every iteration.
The threads field is uint16_t, so the <= 0 comparison is misleading
as the value can never be negative. Change to == 0.
UtilAffinityGetAffinedCPUNum and UtilAffinityCpusOverlap started at the
number of online CPUs, one past the highest CPU id, and so tested a CPU
that does not exist.
The function answers a yes/no question, so return a bool instead of a
uint16_t. Also remove a temporary affinity type that was initialized
but never used.
Rename affinity public API functions to use a consistent naming
convention (e.g. GetAffinityTypeForNameAndIface to
AffinityTypeGetByIfaceOrCpuset, UtilAffinityGetAffinedCPUNum to
AffinityGetAffinedCPUNum, AffinitySetupLoadFromConfig to
AffinityLoadFromConfig, etc.).
Make ResetAffinityForTest public as AffinityReset, so unit tests of
other modules can reset the affinity state.

Ticket: 6927
To better control the values within the variables and to prepare
for the follow-up unit tests, the variable was moved into global
scope and should be accessed only by functions. This allows
reinitialization of the variable value - needed for unit tests.

Ticket: 6927
Needed by unit tests to properly reset the device list.

Ticket: 6927
A failed test returns before its own cleanup code, so the global state
it changed stays behind for the following tests.

Add UtSetTestCleanup(). The test runner calls the registered function
after the test, also after a failed one, and then forgets it.

Ticket: 6927
Some unit tests depend on the CPUs of the machine they run on, e.g. an
affinity test with the CPU range "0-3" needs at least 4 of them.

Add UtilCpuSetNumProcessorsForTests() to set the configured and the
online CPU count that util-cpu reports in unit test builds.

Ticket: 6927
AffinityReset() left all CPU sets with low priority and balanced mode,
and kept the flag of the "no CPU" warning. At startup the sets have
medium priority, and the receive and worker sets are exclusive.

Reset to the startup values, so a test starts from the same state
whether it runs first, after other tests or alone.

Ticket: 6927
The worker-cpu-set example had active priority lists up to CPU 3 and
an interface-specific set up to CPU 9. With set-cpu-affinity enabled,
they refer to CPUs that smaller systems do not have.

The following commits turn such a configuration into a startup error,
so keep these lines as commented-out examples. Without the priority
lists, all worker threads get the default (medium) priority.

Ticket: 6927
The affinity unit tests used the CPUs of the machine they ran on, so
e.g. a test with the range "0-3" needed at least 4 of them. Run the
tests on 8 simulated CPUs.

Move the setup of the tests to AffinityTestInit(). The cleanup is
registered with the test runner and resets the affinity state, the
config and the simulated CPUs, so a failed test leaves nothing behind
for the next ones.

ThreadingAffinityTest01 only checked that the worker CPU set was not
empty, check the number of its CPUs.

Ticket: 6927
On an invalid threading.cpu-affinity section, AffinityLoadFromConfig()
logged the problem and went on with the next setting or CPU set, so
Suricata started with other CPU sets than the configured ones.

Return a negative errno instead: -EINVAL for a malformed value or an
unknown *-cpu-set name, -ERANGE for a CPU range that ends past the CPUs
of the system. With set-cpu-affinity enabled, Suricata now stops at
startup on these errors.

The unit tests that load a config check the returned value.

Ticket: 6927
Only the end of a CPU range was checked against the CPUs of the
system, a single number like [ 9 ] on a 4-CPU system was accepted.
Check every number and return -ERANGE when the system does not have
that CPU, so Suricata stops at startup as on the other errors of the
affinity configuration. As for the end of a range, the limit here is
still the online CPU count.

The AF_PACKET xdp-cpu-redirect list uses the same parser. A CPU the
system does not have was skipped there with an error, it now disables
the XDP CPU redirect with a warning.

Ticket: 6927
A CPU number was valid when it was below the online CPU count, and
CPU selection and counting walked the CPUs up to that count. On a
4-CPU system with CPU 1 offline the count is 3, so CPU 3 could not be
used.

Use the highest CPU ID of the system instead: of the configured CPUs
and of the CPUs of the process CPU affinity mask. The mask matters
with musl, which counts only its CPUs as configured, e.g. 4 in a
container limited to CPUs 8-11.

Ticket: 6927
Reduce affinity unit test CPU indices to a maximum of 4 cores and
lower the simulated CPU count of the tests accordingly, so that the
tests describe the smallest layout they need. Also fix assertions in
ThreadingAffinityTest12 that were incorrectly checking hiprio_cpu
instead of cpu_set.

Ticket: 6927
Add unit tests for mempool cache size auto-calculation and for
automatic thread distribution across interfaces, including
management thread overlap scenarios.

Ticket: 6927
The DPDK unit tests run in CI only in builds without ASAN. Enable
DPDK in the Fedora job that runs the unit tests under ASAN, so memory
errors in the DPDK code paths the tests cover are caught too.

Ticket: 6927
Cover the automatic and the manual mempool size of an interface: the
descriptors and the RX burst reserved for each queue, the split of a manual
size among the queues, the multiplication of the descriptors on a bond port,
the rejected sizes and the cache size derived from the result.

The tests take the place of the suricata-verify live tests dpdk-config-*
that only checked these calculations.

Ticket: 6927
Provide reusable single-thread storage for callers that need a bounded
FIFO and direct writes into contiguous free space. Existing queues are
specialized or do not expose writable spans.

Use every configured slot, validate allocation sizes, and support
all-or-none batch transfers and explicit commits of direct writes.
Stored contents remain owned by the caller.

Add nine unit tests covering capacity, wraparound, transfer rejection,
write spans and ownership.

Ticket: 9111
Add an optional bounded FIFO owned by each RX worker. Short bursts process
directly, while a full burst triggers elastic draining into an exact-capacity
single-producer/single-consumer zero-copy ring, followed by a small FIFO
processing quantum. Handle short wraparound spans through the receive array.

Packets still queued in the backlog when Suricata stops are processed
before the worker exits, so a shutdown can take up to one backlog of
processing per worker longer.

Unit tests cover the rx-backlog-size validation and the backlog share of
the mempool size.

Ticket: 9111
Copilot AI balanced review requested due to automatic review settings November 26, 2026 23:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@suricata-review-bot suricata-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review.

Verdict: comment

2 findings posted as inline comments:

  • Medium (new) — src/runmode-dpdk.c:604 — rx-backlog-size must be a power of two, but MempoolSizeCalculate adds it to the descriptors and the RX burst and then rounds up to…
  • Medium (new) — doc/userguide/upgrade.rst:130-136 — This DPDK timestamp upgrade note runs to seven lines, and upgrade notes should be about three.

Redmine ticket not yet In Review: #9111 (In Progress). Please set it to In Review.

Automated at commit 1566c7e150e0 using Claude Code with claude-opus-5-5/xhigh. Run: 6c9204fc24c7d8a2.

Comment thread src/runmode-dpdk.c
return mp_size -
1; // mempool size should be n = (2^q - 1) to have all descriptors available for use
/* The RX burst in flight and the backlog are held once per worker. */
const uint64_t required = descriptors + iconf->rx_backlog_size + DPDK_RX_BURST_SIZE;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium (new) — rx-backlog-size must be a power of two, but MempoolSizeCalculate adds it to the descriptors and the RX burst and then rounds up to 2^q−1. The rounding predates this change. As a result, any enabled backlog at least doubles the per-queue mempool. With the documented starting value of 131072 and 4096 RX descriptors, each worker gets 262143 mbufs where about 135k are needed, which leaves roughly 300 MB of hugepages idle per worker. A manual mempool-size cannot be set lower. Add the backlog exactly and round only the descriptor share, or document the extra memory cost.

Comment thread doc/userguide/upgrade.rst
Comment on lines +130 to +136
- DPDK: all packets of one RX burst carry the same timestamp, taken when the
burst was received, instead of a timestamp taken when the processing of each
packet started. This should have none-to-minimal impact on timestamp accuracy
for most use cases. Packets held in the optional RX backlog
(``rx-backlog-size``) are timestamped when the worker starts processing
their batch, so their timestamps include the time spent in the backlog; see
:ref:`dpdk-rx-backlog`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium (new) — This DPDK timestamp upgrade note runs to seven lines, and upgrade notes should be about three. Its second half repeats the backlog-timestamp explanation that the linked dpdk-rx-backlog section already gives. The backlog is also new and off by default, so it is not something users meet on upgrade. Keep the per-burst timestamp sentence and cut the backlog part down to a :ref: pointer. This was raised on Suricata PR #16749 and is still present.

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.97436% with 86 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.95%. Comparing base (ca5de3e) to head (1566c7e).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16752      +/-   ##
==========================================
- Coverage   83.97%   83.95%   -0.02%     
==========================================
  Files        1008     1010       +2     
  Lines      286489   287133     +644     
==========================================
+ Hits       240565   241064     +499     
- Misses      45924    46069     +145     
Flag Coverage Δ
fuzzcorpus 61.58% <0.86%> (-0.05%) ⬇️
livemode 25.98% <66.25%> (+0.02%) ⬆️
netns 26.29% <3.44%> (-0.01%) ⬇️
pcap 46.17% <2.58%> (+<0.01%) ⬆️
suricata-verify 69.00% <39.65%> (-0.06%) ⬇️
unittests 59.28% <92.11%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@suricata-qa

Copy link
Copy Markdown

WARNING:

field baseline test %
SURI_TLPW2_single_stats_chk
.decoder.event.erspan.unsupported_encapsulation - 0 -
SURI_TLPW2_autofp_stats_chk
.decoder.event.erspan.unsupported_encapsulation - 0 -
SURI_TLPW1_stats_chk
.decoder.event.erspan.unsupported_encapsulation - 0 -
SURI_TLPR1_stats_chk
.uptime 644 667 103.57%
.decoder.event.erspan.unsupported_encapsulation - 0 -
IPS_AFP_stats_chk
.decoder.event.erspan.unsupported_encapsulation - 0 -
TREX_GENERIC_stats_chk
.decoder.event.erspan.unsupported_encapsulation - 0 -

Pipeline = 36153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants