|WARNING| [RFC] eal: allow setting random number generator seed
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Sat Sep 12 01:18:22 CEST 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/169429
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-09-11
# DPDK Patch Review
## Summary
This patch adds the ability to override the automatic random seed via the `DPDK_RANDOM_SEED` environment variable. Overall, the implementation is straightforward, but there are several issues that need to be addressed.
---
## Errors
### 1. Missing documentation (Error)
The `DPDK_RANDOM_SEED` environment variable is undocumented. All environment variables must be documented in the EAL programmer's guide and release notes.
**Fix:**
- Add documentation to `doc/guides/prog_guide/env_abstraction_layer.rst` describing the variable, its format, and its purpose
- Add a release notes entry in `doc/guides/rel_notes/release_26_03.rst` (or current release)
### 2. `getenv()` in library code (Error)
The guidelines forbid `getenv()` in `lib/` directories. See Forbidden Tokens section.
**Rationale:** Environment variable access creates hidden dependencies and makes behavior non-deterministic across deployments.
**Fix:**
Add a new EAL command-line option instead:
```c
--random-seed <value>
```
This makes the configuration explicit and visible in application invocation, and follows DPDK's standard pattern for runtime configuration.
---
## Warnings
### 1. Missing test coverage (Warning)
New functionality should have test coverage in `app/test`. There should be a test that:
- Sets the seed via the new mechanism
- Verifies that `rte_rand()` produces the expected deterministic sequence
- Verifies that different seeds produce different sequences
- Verifies that an invalid seed format returns an error
**Suggested test:**
```c
static int
test_rand_seed_override(void)
{
uint64_t seed = 0x123456789ABCDEF0ULL;
uint64_t val1, val2;
/* Set seed and get first value */
rte_srand(seed);
val1 = rte_rand();
/* Reset with same seed, should get same sequence */
rte_srand(seed);
val2 = rte_rand();
TEST_ASSERT_EQUAL(val1, val2, "Same seed should produce same sequence");
return TEST_SUCCESS;
}
```
### 2. No validation of seed value range (Warning)
`strtoull()` accepts any value from 0 to `UINT64_MAX`, but seeds of 0 may produce degenerate RNG behavior depending on the algorithm. Consider whether seed=0 should be rejected or documented as potentially producing low-quality randomness.
### 3. Error message has trailing newline (Warning)
The `rte_exit()` format string includes `\n`, but `rte_exit()` already adds a newline.
**Fix:**
```c
rte_exit(EXIT_FAILURE,
"invalid DPDK_RANDOM_SEED: %s", env);
```
---
## Style Issues
### 4. Implicit comparison (Info)
The condition `*env != '\0'` follows DPDK style (explicit comparison). However, `env != NULL` could optionally use `likely()` if this is a hot path during initialization (though it's only called once at startup, so this is purely informational).
Current code is acceptable per guidelines.
---
## Additional Observations
### Variable scope
The variable `env` could be declared at point of use (C99 style):
```c
const char *env = getenv("DPDK_RANDOM_SEED");
```
This is already done correctly.
### errno handling
The errno check is correct: `strtoull()` sets `errno` to `ERANGE` on overflow, and checking `errno != 0` catches this. The subsequent check `*end != '\0'` catches invalid characters.
---
## Recommendation
The patch needs two changes before acceptance:
1. **Replace `getenv()` with an EAL command-line option** (Error) - see Forbidden Tokens
2. **Add documentation** (Error) - both programmer's guide and release notes
The test coverage (Warning) should be added for completeness, though lack of tests is not a blocker for an RFC.
After addressing the errors, this is a useful feature for reproducible performance testing.
More information about the test-report
mailing list