From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 28B85A09F6; Thu, 17 Dec 2020 21:56:36 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 62D14CA37; Thu, 17 Dec 2020 21:56:34 +0100 (CET) Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by dpdk.org (Postfix) with ESMTP id 3A21FCA28 for ; Thu, 17 Dec 2020 21:56:33 +0100 (CET) Received: by mail-lf1-f47.google.com with SMTP id o13so38000878lfr.3 for ; Thu, 17 Dec 2020 12:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AxjaWqvf37u9+WvOfRci3LTehhaB0+3JbTjSJTIoV5w=; b=qlM7tLr+PN6wAUYogMYiNe4HXp+Gy77mtzSPb2eVi4baIlWSxsV4IsiCqWKSygSvxc fdgPrrJbxi1BlsTHyvlFFKLVnPIfkQsOSf3PWFwwXDEOA2VMBwXZBzgSnLWQ+XTJwqkO /3fVIwyFXRit4TQ1AwWitff/HzOlXqePaOzx8cA8caVXcRcKQHyOzNZxhjfQAu249tD+ zBsfZ1HLe9VL79plEYNOZTV5DiLEFp/Jn/XQgv9UjVnSjG1cHJ7oo7syQLe1S1AbQUYA Zki3KYtcOHyNInSs5A0A/YmCNzqlAAFGlyJl85VNsH2xwQDwoHD6cqoUhB1zHBG6CqMk 5NUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AxjaWqvf37u9+WvOfRci3LTehhaB0+3JbTjSJTIoV5w=; b=K73gt87RxD3smspctc3w7yj2ikVxbmR7WXKOoGwt2GEsr8IcQKDpfTQUcTww9Z7MU6 4IIktAEAmRMmZXFlrq+zNPkqtNp5G2b7PSg/EJQz86WefxXUsithnPUTEXRs4fZ3GqMO L6iQ9O/bEYkxTi8vdj83Hy4XH3sAUHB3UN5xcmP2aCCZxNKB5IRzXmUTHeFedGvftFRU +t1fuhN0fu2Gurz5btyJjIBtRjxCt3geAop+DB4gMeReQNY3hJrf4NmQ3esvEkhcvirE 2zeJ2Klp8zlbJnWSuMyXtCtj2QqGZ980BoD/Vd8EKNEKcahGmJtSmR+cnOB4aUjN7g4j B8ew== X-Gm-Message-State: AOAM531iAokNuc2V9pgQSUZDEhL7JQVZWA7kVUTerUtTBb6E0ih7KdQ7 8iDRRqshAKTw8iKb2zrsJXs= X-Google-Smtp-Source: ABdhPJxk8lVlZajPLipU2nNKVKapH67U/Sft1EHBWaYmxHGnzrv6U6UoQBsLPqLvCNgUXxnCyI9Ytw== X-Received: by 2002:a2e:b0c2:: with SMTP id g2mr457149ljl.505.1608238591718; Thu, 17 Dec 2020 12:56:31 -0800 (PST) Received: from sovereign (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id n84sm695250lfd.176.2020.12.17.12.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Dec 2020 12:56:31 -0800 (PST) Date: Thu, 17 Dec 2020 23:56:30 +0300 From: Dmitry Kozlyuk To: Tal Shnaiderman Cc: dev@dpdk.org, thomas@monjalon.net, pallavi.kadam@intel.com, navasile@linux.microsoft.com, dmitrym@microsoft.com, david.marchand@redhat.com, Khoa To Message-ID: <20201217235630.51f67e72@sovereign> In-Reply-To: <20201217174913.14280-1-talshn@nvidia.com> References: <20201213202437.12880-1-talshn@nvidia.com> <20201217174913.14280-1-talshn@nvidia.com> X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v3] eal: add generic thread-local-storage functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Thu, 17 Dec 2020 19:49:13 +0200, Tal Shnaiderman wrote: > Add support for tls functionality in EAL. > > The following functions are added: > rte_tls_create_key - function to create a tls data key. > rte_tls_delete_key - function to delete a tls data key. > rte_tls_set_thread_value - function to set value bound to the tls key > rte_tls_get_thread_value - function to get value bound to the tls key > > tls key will be defied by the new type rte_tls_key_t > > Signed-off-by: Tal Shnaiderman > --- > v3: switch from pthread shim to generic eal implementation [DmitryK] Hi Tal, Unix code can be placed in common/ directory, so that it can be eventually used on Windows with external pthread implementation. See more comments inline. > +++ b/lib/librte_eal/include/rte_tls.h > @@ -0,0 +1,88 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2020 Mellanox Technologies, Ltd > + */ > + > +#include > + > +#ifndef _RTE_TLS_H_ > +#define _RTE_TLS_H_ > + > +/** > + * @file > + * > + * TLS functions > + * > + * Simple TLS functionality supplied by eal. > + */ These functions are supposed to be the first part of an API that will be used instead of naked pthread in DPDK. Maybe more generic names are in order, like rte_thread.h and rte_thread_tls_create/destroy/get/set(). In particular, rte_tls_*() is confusing compared to rte_lcore_*(). > + > +/** > + * Opaque pointer for tls key. > + */ > +typedef struct eal_tls_key *rte_tls_key_t; "_t" suffix is reserved by POSIX, "rte_" prefix is sufficient. > + > +/** > + * Function to create a tls data key visible to all threads in the process Typos: "TLS", "EAL". > + * function need to be called once to create a key usable by all threads. > + * rte_tls_key_t is an opaque pointer used to store the allocated key. > + * and optional destructor can be set to be called when a thread expires. > + * > + * @param key > + * The rte_tls_key_t will cantain the allocated key Typo: "cantain". I'd say: "Pointer to store the allocated rte_tls_key". > + * @param destructor > + * The function to be called when the thread expires Typo: no period (line-break will be removed by Doxygen). > + * Not supported on Windows OS. Some drivers (net/mlx5, bus/dpaa, bus/fsmlc) rely on this feature. Admittedly, it would be hard to implement. You know net/mlx5 well, how will it be affected? Do you plan to stop relying on this feature or implement it in the future? Anyway, LGTM for now. > + * > + * @return > + * On success, zero. > + * On failure, a negative error number -ENOMEM or -ENOEXEC Let's not make POSIX codes part of the API. > + */ > +__rte_experimental > +int > +rte_tls_create_key(rte_tls_key_t *key, void (*destructor)(void *)); [...] > +int > +rte_tls_create_key(rte_tls_key_t *key, void (*destructor)(void *)) > +{ > + int err; > + > + *key = malloc(sizeof(struct eal_tls_key)); > + if ((*key) == NULL) { > + RTE_LOG(DEBUG, EAL, "Cannot allocate tls key."); > + return -ENOMEM; > + } > + err = pthread_key_create(&((*key)->thread_index), destructor); > + if (err) { > + RTE_LOG(DEBUG, EAL, "pthread_key_create failed: %s\n", > + rte_strerror(err)); Use strerror() for OS error codes here and below. > + free(*key); > + return -ENOEXEC; > + } > + return 0; > +} > + [...] > +int > +rte_tls_set_thread_value(rte_tls_key_t key, const void *value) > +{ > + if (!key) > + return -EINVAL; > + /* discard const qualifier */ > + char *p = (char *) (uintptr_t) value; Please declare all variables at the top of a block. > + > + if (!TlsSetValue(key->thread_index, p)) { > + RTE_LOG_WIN32_ERR("TlsSetValue()"); > + return -ENOEXEC; > + } > + return 0; > +} > + > +void * > +rte_tls_get_thread_value(rte_tls_key_t key) > +{ > + if (!key) > + rte_errno = EINVAL; > + void *output = TlsGetValue(key->thread_index); Same as above. > + if (GetLastError() != ERROR_SUCCESS) { > + RTE_LOG_WIN32_ERR("TlsGetValue()"); > + rte_errno = ENOEXEC; > + return NULL; > + } > + return output; > +}