[v1,1/1] eal/random: fix random state initialization for non-eal threads

Message ID 366f5750e01894c56d5d486c75d312e85c404277.1693224396.git.anatoly.burakov@intel.com (mailing list archive)
State Rejected, archived
Delegated to: David Marchand
Headers
Series [v1,1/1] eal/random: fix random state initialization for non-eal threads |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS

Commit Message

Anatoly Burakov Aug. 28, 2023, 12:06 p.m. UTC
  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

Mattias Rönnblom Aug. 28, 2023, 12:22 p.m. UTC | #1
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>
  
Morten Brørup Aug. 28, 2023, 12:48 p.m. UTC | #2
> 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>
  
David Marchand Oct. 2, 2023, 8:25 a.m. UTC | #3
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.
  
Morten Brørup Oct. 2, 2023, 9:02 a.m. UTC | #4
> 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.
  
Mattias Rönnblom Oct. 2, 2023, 12:22 p.m. UTC | #5
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.
  
Anatoly Burakov Oct. 4, 2023, 11:37 a.m. UTC | #6
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 :)
  

Patch

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]);
 }