DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tal Shnaiderman <talshn@nvidia.com>
To: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
	NBU-Contact-Thomas Monjalon <thomas@monjalon.net>,
	"pallavi.kadam@intel.com" <pallavi.kadam@intel.com>,
	"navasile@linux.microsoft.com" <navasile@linux.microsoft.com>,
	"dmitrym@microsoft.com" <dmitrym@microsoft.com>,
	"david.marchand@redhat.com" <david.marchand@redhat.com>,
	Khoa To <khot@microsoft.com>
Subject: Re: [dpdk-dev] [PATCH v3] eal: add generic thread-local-storage functions
Date: Fri, 18 Dec 2020 19:37:07 +0000
Message-ID: <DM6PR12MB394571D12569DE387C394CBBA4C30@DM6PR12MB3945.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20201217235630.51f67e72@sovereign>

> Subject: Re: [PATCH v3] eal: add generic thread-local-storage functions
> 
> External email: Use caution opening links or attachments
> 
> 
> 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 <talshn@nvidia.com>
> > ---
> > 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 <rte_compat.h>
> > +
> > +#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".
> 

Didn't find the EAL typo.

> > + * 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.

In net/mlx5 we will not relay on the destructor for the Windows flow and plan to do the housekeeping in the PMD, to summarize we save HANDLE for each thread using rte_tls_set_thread_value in the PMD destruction flow we call the needed release function for each terminated thread.

I used the opaque pointer in case future development might want to implement It without breaking the API, I assumed additions to the TLS key struct on Windows side will be needed.

Thanks for the review, I'll send a v4 after fixing your comments.

> 
> > + *
> > + * @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;
> > +}


  reply	other threads:[~2020-12-18 19:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-13 20:24 [dpdk-dev] [PATCH v2] eal/windows: add pthread TLS function support Tal Shnaiderman
2020-12-15 22:36 ` Dmitry Kozlyuk
2020-12-17 17:49 ` [dpdk-dev] [PATCH v3] eal: add generic thread-local-storage functions Tal Shnaiderman
2020-12-17 20:56   ` Dmitry Kozlyuk
2020-12-18 19:37     ` Tal Shnaiderman [this message]
2020-12-22  7:30   ` [dpdk-dev] [PATCH v4] " Tal Shnaiderman
2020-12-23  1:18     ` Dmitry Kozlyuk
2020-12-23 11:44       ` Tal Shnaiderman
2020-12-23 11:58         ` Dmitry Kozlyuk
2020-12-23 18:16           ` [dpdk-dev] [EXTERNAL] " Dmitry Malloy (MESHCHANINOV)
2020-12-26 16:08     ` [dpdk-dev] [PATCH v5] " Tal Shnaiderman
2020-12-29 23:13       ` Dmitry Kozlyuk
2020-12-30 10:04         ` Tal Shnaiderman
2020-12-30 11:12       ` [dpdk-dev] [PATCH v6] " Tal Shnaiderman
2021-01-01 22:16         ` Dmitry Kozlyuk
2021-01-05 11:53         ` Thomas Monjalon
2021-01-05 17:06       ` [dpdk-dev] [PATCH v7 0/2] support generic threading functions Tal Shnaiderman
2021-01-05 17:06         ` [dpdk-dev] [PATCH v7 1/2] eal: move thread affinity functions to new file Tal Shnaiderman
2021-01-06 14:40           ` Dmitry Kozlyuk
2021-01-06 19:45           ` [dpdk-dev] [PATCH v8 0/2] support generic threading functions Tal Shnaiderman
2021-01-06 19:45             ` [dpdk-dev] [PATCH v8 1/2] eal: move thread affinity functions to new file Tal Shnaiderman
2021-01-06 19:45             ` [dpdk-dev] [PATCH v8 2/2] eal: add generic thread-local-storage functions Tal Shnaiderman
2021-01-06 20:10               ` Dmitry Kozlyuk
2021-01-06 20:33                 ` Tal Shnaiderman
2021-01-06 20:35             ` [dpdk-dev] [PATCH v9 0/2] support generic threading functions Tal Shnaiderman
2021-01-06 20:35               ` [dpdk-dev] [PATCH v9 1/2] eal: move thread affinity functions to new file Tal Shnaiderman
2021-01-06 20:35               ` [dpdk-dev] [PATCH v9 2/2] eal: add generic thread-local-storage functions Tal Shnaiderman
2021-01-07 14:46                 ` Dmitry Kozlyuk
2021-02-10 13:33                 ` Burakov, Anatoly
2021-02-10 14:26                   ` Medvedkin, Vladimir
2021-02-11  7:34                     ` Tal Shnaiderman
2021-02-11  7:26                   ` Tal Shnaiderman
2021-01-11 22:33               ` [dpdk-dev] [PATCH v9 0/2] support generic threading functions Thomas Monjalon
2021-01-05 17:06         ` [dpdk-dev] [PATCH v7 2/2] eal: add generic thread-local-storage functions Tal Shnaiderman
2021-01-06 15:05           ` Dmitry Kozlyuk
2021-01-06 16:04             ` Tal Shnaiderman

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=DM6PR12MB394571D12569DE387C394CBBA4C30@DM6PR12MB3945.namprd12.prod.outlook.com \
    --to=talshn@nvidia.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=dmitrym@microsoft.com \
    --cc=khot@microsoft.com \
    --cc=navasile@linux.microsoft.com \
    --cc=pallavi.kadam@intel.com \
    --cc=thomas@monjalon.net \
    /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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git