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 922EC42550; Sat, 9 Sep 2023 09:00:45 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D88C940295; Sat, 9 Sep 2023 09:00:44 +0200 (CEST) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id ACCF14027F for ; Sat, 9 Sep 2023 09:00:43 +0200 (CEST) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 5F79D1F476 for ; Sat, 9 Sep 2023 09:00:43 +0200 (CEST) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id 5E1601F8A8; Sat, 9 Sep 2023 09:00:43 +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 B63A51FB87; Sat, 9 Sep 2023 09:00:42 +0200 (CEST) Message-ID: Date: Sat, 9 Sep 2023 09:00:42 +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: [PATCH v2 2/2] random: make rte_rand() thread safe for non-EAL threads Content-Language: en-US To: Stephen Hemminger Cc: dev@dpdk.org, =?UTF-8?Q?Mattias_R=c3=b6nnblom?= , Bruce Richardson References: <20230906155302.82749-1-stephen@networkplumber.org> <20230907152456.20570-1-stephen@networkplumber.org> <20230907152456.20570-3-stephen@networkplumber.org> <136fb174-ca02-577e-e690-f770a0328f10@lysator.liu.se> <20230908135602.4a9026c0@hermes.local> From: =?UTF-8?Q?Mattias_R=c3=b6nnblom?= In-Reply-To: <20230908135602.4a9026c0@hermes.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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-08 22:56, Stephen Hemminger wrote: > On Fri, 8 Sep 2023 22:48:54 +0200 > Mattias Rönnblom wrote: > >> On 2023-09-07 17:24, Stephen Hemminger wrote: >>> Add missing locking so that if two non-EAL threads call rte_rand() >>> they will not corrupt the per-thread state. >>> >>> Fixes: 3f002f069612 ("eal: replace libc-based random generation with LFSR") >> >> The API documentation clearly states that no MT safety guarantees are >> given for unregistered non-EAL threads. So this patch doesn't fix anything. >> >> rte_rand() is MT safe for *registered* non-EAL threads. > > Reading the documentation, it only guarantees safety if registered. > We should add an otherwise clause rather than leaving case as undefined. I agree. It is MT safe in case only single unregistered non-EAL thread uses the API (or multiple such threads, provided they are properly [externally] serialized). "If called from EAL threads, registered non-EAL threads or a *single* unregistered non-EAL thread, this function is thread-safe. Multiple unregistered non-EAL threads may not safely call this function in parallel (i.e., must use external serialization)." A lot of words, unfortunately. Maybe this is better: "rte_xxx() is MT safe, with the exception it may not be called from multiple *unregistered* non-EAL threads in parallel." Then of course comes the issue that nobody knows what is an registered non-EAL thread is. DPDK threading terminology is a big mess, so no wonder.