* [PATCH] random: clarify PRNG MT safety guarantees
@ 2023-10-04 10:54 Mattias Rönnblom
2023-10-04 12:05 ` Morten Brørup
2023-10-06 9:13 ` David Marchand
0 siblings, 2 replies; 6+ messages in thread
From: Mattias Rönnblom @ 2023-10-04 10:54 UTC (permalink / raw)
To: dev; +Cc: hofors, Stephen Hemminger, david.marchand, Mattias Rönnblom
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] random: clarify PRNG MT safety guarantees
2023-10-04 10:54 [PATCH] random: clarify PRNG MT safety guarantees Mattias Rönnblom
@ 2023-10-04 12:05 ` Morten Brørup
2023-10-10 9:40 ` David Marchand
2023-10-06 9:13 ` David Marchand
1 sibling, 1 reply; 6+ messages in thread
From: Morten Brørup @ 2023-10-04 12:05 UTC (permalink / raw)
To: Mattias Rönnblom, dev; +Cc: hofors, Stephen Hemminger, david.marchand
> From: Mattias Rönnblom [mailto:mattias.ronnblom@ericsson.com]
> Sent: Wednesday, 4 October 2023 12.55
random: clarify PRNG MT safety guarantees
>
> 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>
> ---
Acked-by: Morten Brørup <mb@smartsharesystems.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] random: clarify PRNG MT safety guarantees
2023-10-04 10:54 [PATCH] random: clarify PRNG MT safety guarantees Mattias Rönnblom
2023-10-04 12:05 ` Morten Brørup
@ 2023-10-06 9:13 ` David Marchand
2023-10-06 12:18 ` Mattias Rönnblom
1 sibling, 1 reply; 6+ messages in thread
From: David Marchand @ 2023-10-06 9:13 UTC (permalink / raw)
To: Mattias Rönnblom; +Cc: dev, hofors, Stephen Hemminger, Morten Brørup
On Wed, Oct 4, 2023 at 1:00 PM Mattias Rönnblom
<mattias.ronnblom@ericsson.com> wrote:
>
> 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().
>
> Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
Should it be backported along 3a4e21301c7a ("random: initialize state
for unregistered non-EAL threads") ?
--
David Marchand
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] random: clarify PRNG MT safety guarantees
2023-10-06 9:13 ` David Marchand
@ 2023-10-06 12:18 ` Mattias Rönnblom
2023-10-06 15:58 ` Stephen Hemminger
0 siblings, 1 reply; 6+ messages in thread
From: Mattias Rönnblom @ 2023-10-06 12:18 UTC (permalink / raw)
To: David Marchand, Mattias Rönnblom
Cc: dev, Stephen Hemminger, Morten Brørup
On 2023-10-06 11:13, David Marchand wrote:
> On Wed, Oct 4, 2023 at 1:00 PM Mattias Rönnblom
> <mattias.ronnblom@ericsson.com> wrote:
>>
>> 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().
>>
>> Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
>> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
>
> Should it be backported along 3a4e21301c7a ("random: initialize state
> for unregistered non-EAL threads") ?
>
>
I don't think that's worth the trouble, but if someone has a different
opinion, I also don't mind if it is.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] random: clarify PRNG MT safety guarantees
2023-10-06 12:18 ` Mattias Rönnblom
@ 2023-10-06 15:58 ` Stephen Hemminger
0 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2023-10-06 15:58 UTC (permalink / raw)
To: Mattias Rönnblom
Cc: David Marchand, Mattias Rönnblom, dev, Morten Brørup
On Fri, 6 Oct 2023 14:18:25 +0200
Mattias Rönnblom <hofors@lysator.liu.se> wrote:
> On 2023-10-06 11:13, David Marchand wrote:
> > On Wed, Oct 4, 2023 at 1:00 PM Mattias Rönnblom
> > <mattias.ronnblom@ericsson.com> wrote:
> >>
> >> 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().
> >>
> >> Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
> >> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
> >
> > Should it be backported along 3a4e21301c7a ("random: initialize state
> > for unregistered non-EAL threads") ?
> >
> >
>
> I don't think that's worth the trouble, but if someone has a different
> opinion, I also don't mind if it is.
Agree. The initialization patch should be backported, but not this one.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] random: clarify PRNG MT safety guarantees
2023-10-04 12:05 ` Morten Brørup
@ 2023-10-10 9:40 ` David Marchand
0 siblings, 0 replies; 6+ messages in thread
From: David Marchand @ 2023-10-10 9:40 UTC (permalink / raw)
To: Mattias Rönnblom; +Cc: dev, Morten Brørup, hofors, Stephen Hemminger
On Wed, Oct 4, 2023 at 2:06 PM Morten Brørup <mb@smartsharesystems.com> wrote:
>
> > From: Mattias Rönnblom [mailto:mattias.ronnblom@ericsson.com]
> > Sent: Wednesday, 4 October 2023 12.55
> random: clarify PRNG MT safety guarantees
> >
> > 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().
> >
> > Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
> > Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
Applied, thanks Mattias.
--
David Marchand
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-10-10 9:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-04 10:54 [PATCH] random: clarify PRNG MT safety guarantees Mattias Rönnblom
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
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).