[RFC,2/3] Add 32-bit version of rte_rand

Message ID 20190408123029.6701-2-mattias.ronnblom@ericsson.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [RFC,1/3] Replace lrand48-based rte_rand with LFSR generator |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Mattias Rönnblom April 8, 2019, 12:30 p.m. UTC
  Signed-off-by: Mattias Rönnblom <mattias.ronnblom@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(-)
  

Patch

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;