From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C8C7F45DE3 for ; Fri, 6 Dec 2024 12:09:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BD9AE40E0B; Fri, 6 Dec 2024 12:09:22 +0100 (CET) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id B9139402BD; Fri, 6 Dec 2024 12:09:19 +0100 (CET) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 68A7A16213; Fri, 6 Dec 2024 12:09:19 +0100 (CET) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id 540B016212; Fri, 6 Dec 2024 12:09:19 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on hermod.lysator.liu.se X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,AWL, T_SCC_BODY_TEXT_LINE autolearn=disabled version=4.0.0 X-Spam-Score: -1.2 Received: from [192.168.1.85] (h-62-63-215-114.A163.priv.bahnhof.se [62.63.215.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id 45BE416210; Fri, 6 Dec 2024 12:09:16 +0100 (CET) Message-ID: Date: Fri, 6 Dec 2024 12:09:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] random: defer seeding to EAL init To: David Marchand , dev@dpdk.org Cc: thomas@monjalon.net, frode.nordahl@canonical.com, mattias.ronnblom@ericsson.com, stable@dpdk.org, Tyler Retzlaff , Bruce Richardson , Dmitry Kozlyuk , =?UTF-8?Q?Morten_Br=C3=B8rup?= , Konstantin Ananyev , Chengwen Feng , Stephen Hemminger References: <20241205175754.1673888-1-david.marchand@redhat.com> <20241205175754.1673888-2-david.marchand@redhat.com> Content-Language: en-US From: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= In-Reply-To: <20241205175754.1673888-2-david.marchand@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org On 2024-12-05 18:57, David Marchand wrote: > The RNG is documented as being seeded as part of EAL init. > > /** > * Seed the pseudo-random generator. > * > * The generator is automatically seeded by the EAL init with a timer > * value. It may need to be re-seeded by the user with a real random > * value. > * > ... > Remove the superfluous quote. > Move the initialisation (seeding) helper out of a constructor and > call it explicitly from rte_eal_init() as it was done before commit > 3f002f069612 ("eal: replace libc-based random generation with LFSR"). > > This also moves the unconditional lcore variable allocation out of a > constructor. > > While at it, mark local symbol rand_state as static. > Reviewed-by: Mattias Rönnblom > Fixes: 29c39cd3d54d ("random: keep PRNG state in lcore variable") > Cc: stable@dpdk.org > > Signed-off-by: David Marchand > --- > lib/eal/common/eal_private.h | 6 ++++++ > lib/eal/common/rte_random.c | 7 +++++-- > lib/eal/freebsd/eal.c | 2 ++ > lib/eal/linux/eal.c | 2 ++ > lib/eal/windows/eal.c | 2 ++ > 5 files changed, 17 insertions(+), 2 deletions(-) > > diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h > index bb315dab04..a10db6a399 100644 > --- a/lib/eal/common/eal_private.h > +++ b/lib/eal/common/eal_private.h > @@ -702,6 +702,12 @@ eal_get_internal_configuration(void); > rte_usage_hook_t > eal_get_application_usage_hook(void); > > +/** > + * Initialise random subsystem. > + */ > +void > +eal_rand_init(void); > + > /** > * Instruct primary process that a secondary process wants to attach. > */ > diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c > index cf0756f26a..307c26bb7c 100644 > --- a/lib/eal/common/rte_random.c > +++ b/lib/eal/common/rte_random.c > @@ -14,6 +14,8 @@ > #include > #include > > +#include "eal_private.h" > + > struct __rte_cache_aligned rte_rand_state { > uint64_t z1; > uint64_t z2; > @@ -22,7 +24,7 @@ struct __rte_cache_aligned rte_rand_state { > uint64_t z5; > }; > > -RTE_LCORE_VAR_HANDLE(struct rte_rand_state, rand_state); > +static RTE_LCORE_VAR_HANDLE(struct rte_rand_state, rand_state); > > /* instance to be shared by all unregistered non-EAL threads */ > static struct rte_rand_state unregistered_rand_state; > @@ -228,7 +230,8 @@ __rte_random_initial_seed(void) > return rte_get_tsc_cycles(); > } > > -RTE_INIT(rte_rand_init) > +void > +eal_rand_init(void) > { > uint64_t seed; > > diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c > index a96bbf5836..d07cff8651 100644 > --- a/lib/eal/freebsd/eal.c > +++ b/lib/eal/freebsd/eal.c > @@ -777,6 +777,8 @@ rte_eal_init(int argc, char **argv) > return -1; > } > > + eal_rand_init(); > + > eal_check_mem_on_local_socket(); > > if (rte_thread_set_affinity_by_id(rte_thread_self(), > diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c > index a6220524a4..b1e63e37fc 100644 > --- a/lib/eal/linux/eal.c > +++ b/lib/eal/linux/eal.c > @@ -1173,6 +1173,8 @@ rte_eal_init(int argc, char **argv) > return -1; > } > > + eal_rand_init(); > + > eal_check_mem_on_local_socket(); > > if (rte_thread_set_affinity_by_id(rte_thread_self(), > diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c > index 5cdc053a02..5c7526f922 100644 > --- a/lib/eal/windows/eal.c > +++ b/lib/eal/windows/eal.c > @@ -410,6 +410,8 @@ rte_eal_init(int argc, char **argv) > return -1; > } > > + eal_rand_init(); > + > if (rte_thread_set_affinity_by_id(rte_thread_self(), > &lcore_config[config->main_lcore].cpuset) != 0) { > rte_eal_init_alert("Cannot set affinity");