DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] eal: allow setting random number generator seed
@ 2026-09-11 22:58 Stephen Hemminger
  2026-09-12  6:26 ` Morten Brørup
  2026-09-12 16:16 ` [PATCH v2] " Stephen Hemminger
  0 siblings, 2 replies; 3+ messages in thread
From: Stephen Hemminger @ 2026-09-11 22:58 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Mattias Rönnblom

Many performance tests use rte_rand() and the random number
can perturb the results. Add an ability to overide the automatic
random seed on DPDK startup.

This is not a security problem since rte_rand() is documented
as not being cryptographically secure.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eal/common/rte_random.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c
index 576a32a46c..cdad60049b 100644
--- a/lib/eal/common/rte_random.c
+++ b/lib/eal/common/rte_random.c
@@ -247,7 +247,18 @@ eal_rand_init(void)
 
 	RTE_LCORE_VAR_ALLOC(rand_state);
 
-	seed = __rte_random_initial_seed();
+	const char *env = getenv("DPDK_RANDOM_SEED");
+	if (env != NULL && *env != '\0') {
+		char *end;
+
+		errno = 0;
+		seed = strtoull(env, &end, 0);
+		if (errno != 0 || *end != '\0')
+			rte_exit(EXIT_FAILURE,
+				 "invalid DPDK_RANDOM_SEED: %s\n", env);
+	} else {
+		seed = __rte_random_initial_seed();
+	}
 
 	rte_srand(seed);
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-12 16:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-11 22:58 [RFC] eal: allow setting random number generator seed Stephen Hemminger
2026-09-12  6:26 ` Morten Brørup
2026-09-12 16:16 ` [PATCH v2] " Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox