Signed-off-by: Mattias Rönnblom <mattias.ronnb...@ericsson.com> --- lib/librte_eal/common/include/rte_random.h | 15 +++++++++++---- lib/librte_eal/common/rte_random.c | 10 ++++++++++ lib/librte_eal/rte_eal_version.map | 1 + 3 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/lib/librte_eal/common/include/rte_random.h b/lib/librte_eal/common/include/rte_random.h index bca85a672..a96fc7f96 100644 --- a/lib/librte_eal/common/include/rte_random.h +++ b/lib/librte_eal/common/include/rte_random.h @@ -35,11 +35,18 @@ void rte_srand(uint64_t seedval); /** - * Get a pseudo-random value. + * Generates a 32-bit pseudo-random number. * - * This function generates pseudo-random numbers using the linear - * congruential algorithm and 48-bit integer arithmetic, called twice - * to generate a 64-bit value. + * If called from lcore threads, this function is thread-safe. + * + * @return + * A pseudo-random value between 0 and (1<<32)-1. + */ +uint32_t +rte_rand32(void); + +/** + * Generates a 64-bit pseudo-random number. * * If called from lcore threads, this function is thread-safe. * diff --git a/lib/librte_eal/common/rte_random.c b/lib/librte_eal/common/rte_random.c index b8fb7006e..c6dac2fc7 100644 --- a/lib/librte_eal/common/rte_random.c +++ b/lib/librte_eal/common/rte_random.c @@ -83,6 +83,16 @@ struct rte_rand_state *__rte_rand_get_state(void) return &rand_states[lcore_id]; } +uint32_t __rte_experimental +rte_rand32(void) +{ + struct rte_rand_state *state; + + state = __rte_rand_get_state(); + + return __rte_rand32(state); +} + uint64_t __rte_experimental rte_rand(void) { diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 0d60668fa..027a22fe5 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -366,6 +366,7 @@ EXPERIMENTAL { rte_mp_request_async; rte_mp_sendmsg; rte_option_register; + rte_rand32; rte_rand; rte_realloc_socket; rte_service_lcore_attr_get; -- 2.17.1