Skip to content

Commit

Permalink
random: initialize state for unregistered non-EAL threads
Browse files Browse the repository at this point in the history
[ upstream commit 3a4e21301c7a8bf709ff9e74d05628f87450a11e ]

The per-lcore PRNG was not initializing the rand_state of all
the lcores. Any usage of rte_random by an unregistered non-EAL thread
would use rand_states[RTE_MAX_LCORE] which was never initialized.

Fix by using RTE_DIM() which will get all lcores.

Fixes: 3f002f0 ("eal: replace libc-based random generation with LFSR")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
  • Loading branch information
shemminger authored and bluca committed Oct 18, 2023
1 parent b88f88c commit 681827b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/librte_eal/common/rte_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ rte_srand(uint64_t seed)
unsigned int lcore_id;

/* add lcore_id to seed to avoid having the same sequence */
for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++)
for (lcore_id = 0; lcore_id < RTE_DIM(rand_states); lcore_id++)
__rte_srand_lfsr258(seed + lcore_id, &rand_states[lcore_id]);
}

Expand Down

0 comments on commit 681827b

Please sign in to comment.