From: "Mattias Rönnblom" <mattias.ronnblom@ericsson.com>
To: <dev@dpdk.org>
Cc: hofors@lysator.liu.se,
"Stephen Hemminger" <stephen@networkplumber.org>,
david.marchand@redhat.com,
"Mattias Rönnblom" <mattias.ronnblom@ericsson.com>
Subject: [PATCH] random: clarify PRNG MT safety guarantees
Date: Wed, 4 Oct 2023 12:54:49 +0200 [thread overview]
Message-ID: <20231004105449.367667-1-mattias.ronnblom@ericsson.com> (raw)
Clarify MT safety guarantees for unregistered non-EAL threads calling
PRNG functions in rte_random.h.
Clarify that rte_srand() is not MT safe in regards to calls to
rte_rand_max() and rte_drand().
Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/eal/include/rte_random.h | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/lib/eal/include/rte_random.h b/lib/eal/include/rte_random.h
index 2edf5d210b..c12eb07ea8 100644
--- a/lib/eal/include/rte_random.h
+++ b/lib/eal/include/rte_random.h
@@ -27,8 +27,8 @@ extern "C" {
* value.
*
* This function is not multi-thread safe in regards to other
- * rte_srand() calls, nor is it in relation to concurrent rte_rand()
- * calls.
+ * rte_srand() calls, nor is it in relation to concurrent rte_rand(),
+ * rte_rand_max() or rte_drand() calls.
*
* @param seedval
* The value of the seed.
@@ -41,8 +41,9 @@ rte_srand(uint64_t seedval);
*
* The generator is not cryptographically secure.
*
- * If called from EAL threads or registered non-EAL threads, this function
- * is thread-safe.
+ * rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe,
+ * with the exception that they may not be called by multiple
+ * _unregistered_ non-EAL threads in parallel.
*
* @return
* A pseudo-random value between 0 and (1<<64)-1.
@@ -56,8 +57,9 @@ rte_rand(void);
* This function returns an uniformly distributed (unbiased) random
* number less than a user-specified maximum value.
*
- * If called from EAL threads or registered non-EAL threads, this function
- * is thread-safe.
+ * rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe,
+ * with the exception that they may not be called by multiple
+ * _unregistered_ non-EAL threads in parallel.
*
* @param upper_bound
* The upper bound of the generated number.
@@ -78,8 +80,9 @@ rte_rand_max(uint64_t upper_bound);
*
* The generator is not cryptographically secure.
*
- * If called from EAL threads or registered non-EAL threads, this function
- * is thread-safe.
+ * rte_rand(), rte_rand_max() and rte_drand() are multi-thread safe,
+ * with the exception that they may not be called by multiple
+ * _unregistered_ non-EAL threads in parallel.
*
* @return
* A pseudo-random value between 0 and 1.0.
--
2.34.1
next reply other threads:[~2023-10-04 11:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-04 10:54 Mattias Rönnblom [this message]
2023-10-04 12:05 ` Morten Brørup
2023-10-10 9:40 ` David Marchand
2023-10-06 9:13 ` David Marchand
2023-10-06 12:18 ` Mattias Rönnblom
2023-10-06 15:58 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231004105449.367667-1-mattias.ronnblom@ericsson.com \
--to=mattias.ronnblom@ericsson.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=hofors@lysator.liu.se \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).