DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: "Mattias Rönnblom" <mattias.ronnblom@ericsson.com>
Subject: Re: [RFC] random: use per lcore state
Date: Wed, 6 Sep 2023 12:55:17 -0700	[thread overview]
Message-ID: <20230906125517.47fcbc4a@hermes.local> (raw)
In-Reply-To: <20230906172013.169846-1-stephen@networkplumber.org>

On Wed,  6 Sep 2023 10:20:13 -0700
Stephen Hemminger <stephen@networkplumber.org> wrote:

>  static __rte_always_inline
>  struct rte_rand_state *__rte_rand_get_state(void)
>  {
> -	unsigned int idx;
> +	struct rte_rand_state *rand_state = &RTE_PER_LCORE(rte_rand_state);
> +	uint64_t seed;
>  
> -	idx = rte_lcore_id();
> +	seed = __atomic_load_n(&rte_rand_seed, __ATOMIC_RELAXED);
> +	if (unlikely(seed != rand_state->seed)) {
> +		rand_state->seed = seed;
>  
> -	/* last instance reserved for unregistered non-EAL threads */
> -	if (unlikely(idx == LCORE_ID_ANY))
> -		idx = RTE_MAX_LCORE;
> +		seed += rte_thread_self().opaque_id;
> +		__rte_srand_lfsr258(seed, rand_state);
> +	}

Not sure about this.
It would change the semantics of rte_srand so that if passed the same
value across multiple runs, it would still generate different values because
thread_id is not the same.  Using rte_lcore() instead would cause repeatablity
but then there would still be a bug if two non-EAL threads used random.
Both threads would get the same sequence of numbers, but that is true
with current code.

  parent reply	other threads:[~2023-09-06 19:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-06 17:20 Stephen Hemminger
2023-09-06 17:54 ` Morten Brørup
2023-09-11 16:04   ` Stephen Hemminger
2023-09-11 16:37     ` Morten Brørup
2023-09-06 18:16 ` Morten Brørup
2023-09-06 19:55 ` Stephen Hemminger [this message]
2023-09-06 20:12   ` Mattias Rönnblom
2023-09-06 20:02 ` Mattias Rönnblom
2023-09-06 23:00   ` Stephen Hemminger
2023-09-08  7:04     ` Mattias Rönnblom
2023-09-11 16:06       ` Stephen Hemminger
2023-09-11 16:53         ` Mattias Rönnblom
2023-09-09  0:13   ` Konstantin Ananyev
2023-09-09  6:45     ` Mattias Rönnblom
2023-09-09 11:23       ` Morten Brørup
2023-09-11  9:00         ` Mattias Rönnblom
2023-09-11 16:02           ` Stephen Hemminger
2023-09-09 11:32       ` Stephen Hemminger
2023-09-10 13:26       ` Konstantin Ananyev

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=20230906125517.47fcbc4a@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=mattias.ronnblom@ericsson.com \
    /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).