From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 324F84252C; Wed, 6 Sep 2023 22:12:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BD3FD402B4; Wed, 6 Sep 2023 22:12:39 +0200 (CEST) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id 4E346402A9 for ; Wed, 6 Sep 2023 22:12:38 +0200 (CEST) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 079431925C for ; Wed, 6 Sep 2023 22:12:38 +0200 (CEST) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id 065791944E; Wed, 6 Sep 2023 22:12:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on hermod.lysator.liu.se X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ALL_TRUSTED, AWL, NICE_REPLY_A autolearn=disabled version=3.4.6 X-Spam-Score: -2.3 Received: from [192.168.1.59] (h-62-63-215-114.A163.priv.bahnhof.se [62.63.215.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id 9A6BE192E2; Wed, 6 Sep 2023 22:12:37 +0200 (CEST) Message-ID: <8d1d9582-3124-229d-38e1-eddc14b96c22@lysator.liu.se> Date: Wed, 6 Sep 2023 22:12:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [RFC] random: use per lcore state Content-Language: en-US To: Stephen Hemminger , dev@dpdk.org Cc: =?UTF-8?Q?Mattias_R=c3=b6nnblom?= , =?UTF-8?Q?Morten_Br=c3=b8rup?= References: <20230906172013.169846-1-stephen@networkplumber.org> <20230906125517.47fcbc4a@hermes.local> From: =?UTF-8?Q?Mattias_R=c3=b6nnblom?= In-Reply-To: <20230906125517.47fcbc4a@hermes.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 2023-09-06 21:55, Stephen Hemminger wrote: > On Wed, 6 Sep 2023 10:20:13 -0700 > Stephen Hemminger 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. If the non-EAL threads register themselves (and thus acquires a lcore id), they will get this kind of repeatability, provided the order of registration is the same. A "big if", no doubt. > Both threads would get the same sequence of numbers, but that is true > with current code.