Repository navigation
Conversation
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
suricata-review-bot
left a comment
There was a problem hiding this comment.
AI-generated review.
Verdict: comment
1 finding posted as inline comment:
- Medium (new) —
doc/userguide/upgrade.rst:130-136— This DPDK timestamp upgrade note is seven lines long.
Redmine ticket not yet In Review: #9111 (In Progress). Please set it to In Review.
Automated at commit 882bcda4c8bd using Claude Code with claude-opus-5-5/xhigh. Run: b34b156dadd1ab7d.
| - 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`. |
There was a problem hiding this comment.
Medium (new) — This DPDK timestamp upgrade note is seven lines long. Upgrade notes are meant to be about three lines. The second half repeats the backlog-timestamp explanation that the linked dpdk-rx-backlog section already gives. The backlog is new and off by default, so that half does not describe a change users hit on upgrade. Keep the per-burst timestamp sentence and cut the backlog part down to a pointer, e.g. "For rx-backlog-size, see :ref:dpdk-rx-backlog."
|
Information: QA ran without warnings. Pipeline = 36148 |
|
Follow-up in #16752 |
Follow-up of #16649 and an extension of #16748
If somebody would like to take an extra review of 2 commits (as compared to #16748 ) for the RX backlog, the merging process can be more efficient. This PR is just a feature-extension (the top 2 commits) over #16748
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:
v1 (mash-up of #16092 v14.1 and #16292 v1.3):
SV_BRANCH=OISF/suricata-verify#3584