[v1,1/1] eal/random: fix random state initialization for non-eal threads
Checks
Commit Message
Currently, the rte_rand() state is initialized with seed, and each
rand state is initialized up until RTE_MAX_LCORE'th rand state. However,
rand state also has one extra rand state reserved for non-EAL threads,
which is not initialized. Fix it by initializing this extra state.
Fixes: 3f002f069612 ("eal: replace libc-based random generation with LFSR")
Cc: mattias.ronnblom@ericsson.com
Cc: stable@dpdk.org
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
lib/eal/common/rte_random.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 2023-08-28 14:06, Anatoly Burakov wrote:
> Currently, the rte_rand() state is initialized with seed, and each
> rand state is initialized up until RTE_MAX_LCORE'th rand state. However,
> rand state also has one extra rand state reserved for non-EAL threads,
> which is not initialized. Fix it by initializing this extra state.
>
> Fixes: 3f002f069612 ("eal: replace libc-based random generation with LFSR")
> Cc: mattias.ronnblom@ericsson.com
> Cc: stable@dpdk.org
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
> lib/eal/common/rte_random.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c
> index 565f2401ce..e5691813a4 100644
> --- a/lib/eal/common/rte_random.c
> +++ b/lib/eal/common/rte_random.c
> @@ -83,7 +83,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_MAX_LCORE + 1; lcore_id++)
> __rte_srand_lfsr258(seed + lcore_id, &rand_states[lcore_id]);
> }
>
Acked-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
> From: Mattias Rönnblom [mailto:hofors@lysator.liu.se]
> Sent: Monday, 28 August 2023 14.23
>
> On 2023-08-28 14:06, Anatoly Burakov wrote:
> > Currently, the rte_rand() state is initialized with seed, and each
> > rand state is initialized up until RTE_MAX_LCORE'th rand state.
> However,
> > rand state also has one extra rand state reserved for non-EAL threads,
> > which is not initialized. Fix it by initializing this extra state.
> >
> > Fixes: 3f002f069612 ("eal: replace libc-based random generation with
> LFSR")
> > Cc: mattias.ronnblom@ericsson.com
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> > ---
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Hello guys,
On Mon, Aug 28, 2023 at 2:07 PM Anatoly Burakov
<anatoly.burakov@intel.com> wrote:
>
> Currently, the rte_rand() state is initialized with seed, and each
> rand state is initialized up until RTE_MAX_LCORE'th rand state. However,
> rand state also has one extra rand state reserved for non-EAL threads,
> which is not initialized. Fix it by initializing this extra state.
>
> Fixes: 3f002f069612 ("eal: replace libc-based random generation with LFSR")
> Cc: mattias.ronnblom@ericsson.com
> Cc: stable@dpdk.org
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
We have two series for fixing related issues.
Stephen alternative patch 1 handles Anatoly fix here.
https://patchwork.dpdk.org/project/dpdk/list/?series=29449&state=%2A&archive=both
I see Anatoly was acked by Mattias and Morten, though Stephen
(RTE_DIM) fix is more elegant.
How do you guys want me to proceed?
Thanks.
> From: David Marchand [mailto:david.marchand@redhat.com]
> Sent: Monday, 2 October 2023 10.26
>
> Hello guys,
>
> On Mon, Aug 28, 2023 at 2:07 PM Anatoly Burakov
> <anatoly.burakov@intel.com> wrote:
> >
> > Currently, the rte_rand() state is initialized with seed, and each
> > rand state is initialized up until RTE_MAX_LCORE'th rand state. However,
> > rand state also has one extra rand state reserved for non-EAL threads,
> > which is not initialized. Fix it by initializing this extra state.
> >
> > Fixes: 3f002f069612 ("eal: replace libc-based random generation with LFSR")
> > Cc: mattias.ronnblom@ericsson.com
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
>
> We have two series for fixing related issues.
>
> Stephen alternative patch 1 handles Anatoly fix here.
> https://patchwork.dpdk.org/project/dpdk/list/?series=29449&state=%2A&archive=b
> oth
>
> I see Anatoly was acked by Mattias and Morten, though Stephen
> (RTE_DIM) fix is more elegant.
> How do you guys want me to proceed?
Please use patch 1 from Stephen, which I have now thoroughly reviewed, instead of this patch from Anatoly.
On 2023-10-02 10:25, David Marchand wrote:
> Hello guys,
>
> On Mon, Aug 28, 2023 at 2:07 PM Anatoly Burakov
> <anatoly.burakov@intel.com> wrote:
>>
>> Currently, the rte_rand() state is initialized with seed, and each
>> rand state is initialized up until RTE_MAX_LCORE'th rand state. However,
>> rand state also has one extra rand state reserved for non-EAL threads,
>> which is not initialized. Fix it by initializing this extra state.
>>
>> Fixes: 3f002f069612 ("eal: replace libc-based random generation with LFSR")
>> Cc: mattias.ronnblom@ericsson.com
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
>
> We have two series for fixing related issues.
>
> Stephen alternative patch 1 handles Anatoly fix here.
> https://patchwork.dpdk.org/project/dpdk/list/?series=29449&state=%2A&archive=both
>
> I see Anatoly was acked by Mattias and Morten, though Stephen
> (RTE_DIM) fix is more elegant.
Stephen hadn't posted his fix when I acked this, I believe.
RTE_DIM() makes the thing more readable. I'm fine with either
"RTE_MAX_LCORE + 1" or "RTE_DIM()", but I would prefer the latter.
> How do you guys want me to proceed?
>
>
> Thanks.
On 10/2/2023 9:25 AM, David Marchand wrote:
> Hello guys,
>
> On Mon, Aug 28, 2023 at 2:07 PM Anatoly Burakov
> <anatoly.burakov@intel.com> wrote:
>>
>> Currently, the rte_rand() state is initialized with seed, and each
>> rand state is initialized up until RTE_MAX_LCORE'th rand state. However,
>> rand state also has one extra rand state reserved for non-EAL threads,
>> which is not initialized. Fix it by initializing this extra state.
>>
>> Fixes: 3f002f069612 ("eal: replace libc-based random generation with LFSR")
>> Cc: mattias.ronnblom@ericsson.com
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
>
> We have two series for fixing related issues.
>
> Stephen alternative patch 1 handles Anatoly fix here.
> https://patchwork.dpdk.org/project/dpdk/list/?series=29449&state=%2A&archive=both
>
> I see Anatoly was acked by Mattias and Morten, though Stephen
> (RTE_DIM) fix is more elegant.
> How do you guys want me to proceed?
>
>
> Thanks.
I'm OK with either, so please feel free to merge Stephen's patch :)
@@ -83,7 +83,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_MAX_LCORE + 1; lcore_id++)
__rte_srand_lfsr258(seed + lcore_id, &rand_states[lcore_id]);
}