[v3,2/5] random: defer seeding to EAL init
Checks
Commit Message
The RNG is documented as being seeded as part of EAL init.
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.
Fixes: 29c39cd3d54d ("random: keep PRNG state in lcore variable")
Cc: stable@dpdk.org
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Frode Nordahl <frode.nordahl@canonical.com>
---
Changes since v2:
- added assert in rte_s?rand(),
Changes since v1:
- updated commitlog,
---
lib/eal/common/eal_private.h | 6 ++++++
lib/eal/common/rte_random.c | 12 +++++++++---
lib/eal/freebsd/eal.c | 2 ++
lib/eal/linux/eal.c | 2 ++
lib/eal/windows/eal.c | 2 ++
5 files changed, 21 insertions(+), 3 deletions(-)
@@ -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.
*/
@@ -14,6 +14,8 @@
#include <rte_lcore_var.h>
#include <rte_random.h>
+#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;
@@ -129,8 +131,11 @@ struct rte_rand_state *__rte_rand_get_state(void)
idx = rte_lcore_id();
- if (unlikely(idx == LCORE_ID_ANY))
+ if (unlikely(idx == LCORE_ID_ANY)) {
+ /* Make sure rte_*rand() was called after rte_eal_init(). */
+ RTE_ASSERT(rand_state != NULL);
return &unregistered_rand_state;
+ }
return RTE_LCORE_VAR(rand_state);
}
@@ -228,7 +233,8 @@ __rte_random_initial_seed(void)
return rte_get_tsc_cycles();
}
-RTE_INIT(rte_rand_init)
+void
+eal_rand_init(void)
{
uint64_t seed;
@@ -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(),
@@ -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(),
@@ -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");