[dpdk-dev] [PATCH v6] eal: add generic thread-local-storage functions

Thomas Monjalon thomas at monjalon.net
Tue Jan 5 12:53:43 CET 2021


30/12/2020 12:12, Tal Shnaiderman:
> Add support for tls functionality in EAL.

You should write TLS uppercase here and below.

There is already a TLS capability in rte_per_lcore.h,
using __thread keyword.
Note: I think the historical wording "lcore" is confusing.
We talk about lcore, assuming the thread is bound to its lcore.

Please explain in the patch why the more complex TLS functions
are required, i.e. can __thread variable be used in Windows?
limitation, etc.

> The following functions are added:
> rte_thread_tls_create_key - function to create a tls data key.
> rte_thread_tls_delete_key - function to delete a tls data key.
> rte_thread_tls_set_value - function to set value bound to the tls key
> rte_thread_tls_get_value - function to get value bound to the tls key

We can assume the TLS key logic is known,
but this patch is the right place to explain it.

> tls key will be defined by the new type rte_tls_key
> 
> Windows implementation is under librte_eal/windows and
> implemented using WIN32 API for Windows only.
> 
> common implementation is under librte_eal/common and
> implemented using pthread for UNIX and Windows compilation
> using extenral pthread libraries, when supported.

typo: external

[...]
> v3: switch from pthread shim to generic eal implementation [DmitryK]
> v4: modify file names, function names, move unix code to common
> for future external pthreads support [DmitryK]

For now, there is no external pthread library.
It did not have been discussed generally in the techboard.
As it is using the Unix pthread API, it sounds more logical
to have this implementation in the Unix sub-directory I think.

> --- a/lib/librte_eal/common/meson.build
> +++ b/lib/librte_eal/common/meson.build
> +	'rte_thread.c',
[...]
> --- a/lib/librte_eal/include/meson.build
> +++ b/lib/librte_eal/include/meson.build
> +	'rte_thread.h',

There are existing functions in rte_lcore.h and rte_per_lcore.h
which are managing threads.
I think a prior patch should move such functions in rte_thread files.
At least we can start moving the affinity functions,
which are not using pthread types as parameters.

> --- /dev/null
> +++ b/lib/librte_eal/include/rte_thread.h
> @@ -0,0 +1,88 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2020 Mellanox Technologies, Ltd
> + */
> +
> +#include <rte_compat.h>

Why do you need rte_compat?

> +/**
> + * Function to create a TLS data key visible to all threads in the process
> + * function need to be called once to create a key usable by all threads.
> + * rte_tls_key is an opaque pointer used to store the allocated key.
> + * and optional destructor can be set to be called when a thread expires.

You may explain that the key is later used to get/set a value.

> + *
> + * @param key
> + *   Pointer to store the allocated rte_tls_key
> + * @param destructor
> + *   The function to be called when the thread expires.
> + *   Not supported on Windows OS.

What happens when specifying a destructor on Windows?

> + *
> + * @return
> + *   On success, zero.
> + *   On failure, a negative number.
> + */
> +__rte_experimental
> +int
> +rte_thread_tls_create_key(rte_tls_key *key, void (*destructor)(void *));

For .h files, we have the return type on the same line (I know it is stupid).

I would suggest moving the verb "create" at the end of the function names.

[...]
> +rte_thread_tls_delete_key(rte_tls_key key);

Could be rte_thread_tls_key_delete?

[...]
> +rte_thread_tls_set_value(rte_tls_key key, const void *value);

rte_thread_tls_value_set?

> +rte_thread_tls_get_value(rte_tls_key key);

rte_thread_tls_value_get?





More information about the dev mailing list