Re: [PATCH net-next 2/3] [PATCH 2/3] netem: allow using a seeded PRNG for generating random losses

From: Stephen Hemminger
Date: Mon Aug 14 2023 - 17:02:46 EST


On Mon, 14 Aug 2023 22:14:53 +0200
François Michel <francois.michel@xxxxxxxxxxxx> wrote:

> Thank you very much for your comment.
>
> I do not use prandom_u32_state() directly in order to ensure
> that the original netem behaviour is preserved when no seed is specified.
>
> But I agree that it would be cleaner to directly use prandom_u32_state()
> instead of get_random_u32(), if we are sure that we won't have problems
> (e.g. short prng cycles) with the randomly generated seeds when no seed
> is explicitly provided. If it is okay, then
> I don't see a reason to not use prandom_u32_state() directly.
>
> I'll make an update of the patch taking these comments into account and
> simplifying the patch.
>
> Thank you !
>
> François

Older versions of netem had prandom_u32_state() equivalent built inside.
The code was split out later to be usable in other places.
Over time, get_random_u32() was added because it was more random and
there were calls to unify random number usage.

The prandom was based on Tausworthe to have good long simulation cycles
and reasonable performance.

Going back to prandom always is good idea, since get_random_u32()
has addition locking and batched entropy which netem really doesn't need/want.