random: initialize the random state for non-eal lcores

Message ID 20230906155302.82749-1-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series random: initialize the random state for non-eal lcores |

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/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS

Commit Message

Stephen Hemminger Sept. 6, 2023, 3:53 p.m. UTC
  The per-lcore PRNG was not initializing the rand_state of all
the lcores. Any usage of rte_random by a non-EAL lcore would
use rand_states[RTE_MAX_LCORE] which was never initialized.

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

Fixes: 3f002f069612 ("eal: replace libc-based random generation with LFSR")
Cc: mattias.ronnblom@ericsson.com
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/common/mlx5/linux/mlx5_common_os.c | 2 +-
 lib/eal/common/rte_random.c                | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
  

Comments

Morten Brørup Sept. 6, 2023, 4:25 p.m. UTC | #1
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Wednesday, 6 September 2023 17.53
> 
> The per-lcore PRNG was not initializing the rand_state of all
> the lcores. Any usage of rte_random by a non-EAL lcore would
> use rand_states[RTE_MAX_LCORE] which was never initialized.
> 
> Fix by using RTE_DIM() which will get all lcores.
> 
> Fixes: 3f002f069612 ("eal: replace libc-based random generation with LFSR")
> Cc: mattias.ronnblom@ericsson.com
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  drivers/common/mlx5/linux/mlx5_common_os.c | 2 +-

With the unrelated MLX5 stuff removed,

Acked-by: Morten Brørup <mb@smartsharesystems.com>

>  lib/eal/common/rte_random.c                | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
  
Stephen Hemminger Sept. 6, 2023, 4:28 p.m. UTC | #2
On Wed,  6 Sep 2023 08:53:02 -0700
Stephen Hemminger <stephen@networkplumber.org> wrote:

> diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c
> index 2ebb8ac8b6e5..7260c1a19fd3 100644
> --- a/drivers/common/mlx5/linux/mlx5_common_os.c
> +++ b/drivers/common/mlx5/linux/mlx5_common_os.c
> @@ -266,7 +266,7 @@ mlx5_glue_path(char *buf, size_t size)
>  		goto error;
>  	return buf;
>  error:
> -	RTE_LOG(ERR, PMD, "unable to append \"-glue\" to last component of"
> +	DRV_LOG(ERR, "unable to append \"-glue\" to last component of"
>  		" RTE_EAL_PMD_PATH (\"" RTE_EAL_PMD_PATH "\"), please"
>  		" re-configure DPDK");
>  	return NULL;

Not sure how that got in, ignore it.
  

Patch

diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c
index 2ebb8ac8b6e5..7260c1a19fd3 100644
--- a/drivers/common/mlx5/linux/mlx5_common_os.c
+++ b/drivers/common/mlx5/linux/mlx5_common_os.c
@@ -266,7 +266,7 @@  mlx5_glue_path(char *buf, size_t size)
 		goto error;
 	return buf;
 error:
-	RTE_LOG(ERR, PMD, "unable to append \"-glue\" to last component of"
+	DRV_LOG(ERR, "unable to append \"-glue\" to last component of"
 		" RTE_EAL_PMD_PATH (\"" RTE_EAL_PMD_PATH "\"), please"
 		" re-configure DPDK");
 	return NULL;
diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c
index 53636331a27b..812e5b4757b5 100644
--- a/lib/eal/common/rte_random.c
+++ b/lib/eal/common/rte_random.c
@@ -84,7 +84,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]);
 }