Register external threads as lcore
cover Register external threads as lcore
OVS and some other applications have been hacking into DPDK internals to fake EAL threads and avoid performance penalty of only having non-EAL threads.
This series proposes to add a new type of lcores and maps those external threads to such lcores.
Those threads won't run the DPDK eal mainloop and as a consequence part of the EAL threads API cannot work.
Having new lcores appearing during the process lifetime is not expected by some DPDK components. This is addressed by notifying of such lcore hotplug.
This patchset has still some more work (like refusing new lcore type in incompatible EAL threads API, updating the documentation and adding unit tests) but I am sending it anyway as I would like to get this in for 20.08.
For the interested parties, I have a patch [1] against dpdk-latest OVS branch that makes use of this series.
1: https://github.com/david-marchand/ovs/commit/dpdk-latest-external-lcores
Signature · 31 lines
David Marchand David Marchand (7): eal: relocate per thread symbols to common eal: fix multiple definition of per lcore thread id eal: introduce thread init helper eal: introduce thread uninit helper eal: register non-EAL threads as lcore eal: dump lcores eal: add lcore hotplug notifications doc/guides/howto/debug_troubleshoot.rst | 5 +- lib/librte_eal/common/eal_common_lcore.c | 167 +++++++++++++++++++++- lib/librte_eal/common/eal_common_thread.c | 143 ++++++++++++++---- lib/librte_eal/common/eal_common_trace.c | 49 ++++++- lib/librte_eal/common/eal_private.h | 43 ++++++ lib/librte_eal/common/eal_thread.h | 26 +++- lib/librte_eal/common/eal_trace.h | 1 + lib/librte_eal/freebsd/eal.c | 16 ++- lib/librte_eal/freebsd/eal_thread.c | 38 +---- lib/librte_eal/include/rte_eal.h | 12 +- lib/librte_eal/include/rte_lcore.h | 112 +++++++++++++-- lib/librte_eal/linux/eal.c | 17 ++- lib/librte_eal/linux/eal_thread.c | 38 +---- lib/librte_eal/rte_eal_version.map | 14 ++ lib/librte_eal/windows/eal.c | 3 +- lib/librte_eal/windows/eal_thread.c | 14 +- 16 files changed, 536 insertions(+), 162 deletions(-) -- 2.23.0
PATCH 1/7 eal: relocate per thread symbols to common
We have per lcore thread symbols scattered in OS implementations but common code relies on them.
Move all of them in common.
RTE_PER_LCORE(_socket_id) and RTE_PER_LCORE(_cpuset) have public accessors and are not exported through the library map, they can be made static.
--- lib/librte_eal/common/eal_common_thread.c | 5 ++++- lib/librte_eal/freebsd/eal_thread.c | 4 ---- lib/librte_eal/include/rte_lcore.h | 1 - lib/librte_eal/linux/eal_thread.c | 4 ---- lib/librte_eal/windows/eal_thread.c | 4 ---- 5 files changed, 4 insertions(+), 14 deletions(-)
lib/librte_eal/common/eal_common_thread.c +4 -1
@@ -23,7 +23,10 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DECLARE_PER_LCORE (unsigned , _socket_id); +RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = + (unsigned int )SOCKET_ID_ANY ; +static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);unsigned rte_socket_id (void ) {
lib/librte_eal/freebsd/eal_thread.c +0 -4
@@ -25,10 +25,6 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; -RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
lib/librte_eal/include/rte_lcore.h +0 -1
@@ -23,7 +23,6 @@ extern "C" {#define LCORE_ID_ANY UINT32_MAX/**< Any lcore. */ RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ -RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */ /** * Get a lcore's role.
lib/librte_eal/linux/eal_thread.c +0 -4
@@ -25,10 +25,6 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; -RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
lib/librte_eal/windows/eal_thread.c +0 -4
@@ -16,10 +16,6 @@#include "eal_private.h" #include "eal_windows.h" -RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; -RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int)SOCKET_ID_ANY; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
Signature · 1 line
2.23.0
PATCH 2/7 eal: fix multiple definition of per lcore thread id
In reply to David MarchandBecause of the inline accessor + static declaration in rte_gettid(), we end up with multiple symbols for RTE_PER_LCORE(_thread_id). Each compilation unit will pay a cost when accessing this information for the first time.
$ nm build/app/dpdk-testpmd | grep per_lcore__thread_id 0000000000000054 d per_lcore__thread_id.5037 0000000000000040 d per_lcore__thread_id.5103 0000000000000048 d per_lcore__thread_id.5259 000000000000004c d per_lcore__thread_id.5259 0000000000000044 d per_lcore__thread_id.5933 0000000000000058 d per_lcore__thread_id.6261 0000000000000050 d per_lcore__thread_id.7378 000000000000005c d per_lcore__thread_id.7496 000000000000000c d per_lcore__thread_id.8016 0000000000000010 d per_lcore__thread_id.8431
Make it global as part of the DPDK_21 stable ABI.
--- lib/librte_eal/common/eal_common_thread.c | 1 + lib/librte_eal/include/rte_eal.h | 3 ++- lib/librte_eal/rte_eal_version.map | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_thread.c +1 -0
@@ -24,6 +24,7 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +RTE_DEFINE_PER_LCORE (int, _thread_id) =-1 ; static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int )SOCKET_ID_ANY ; static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
lib/librte_eal/include/rte_eal.h +2 -1
@@ -447,6 +447,8 @@ enum rte_intr_mode rte_eal_vfio_intr_mode(void);*/ int rte_sys_gettid (void ); +RTE_DECLARE_PER_LCORE (int, _thread_id); +/** * Get system unique thread id. *
@@ -456,7 +458,6 @@ int rte_sys_gettid(void);*/ static inline int rte_gettid (void ) { - static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;if (RTE_PER_LCORE (_thread_id) ==-1 )RTE_PER_LCORE (_thread_id) =rte_sys_gettid ();return RTE_PER_LCORE (_thread_id);
lib/librte_eal/rte_eal_version.map +7 -0
@@ -221,6 +221,13 @@ DPDK_20.0 { local: *; }; +DPDK_21 { + global: + + per_lcore__thread_id; + +} DPDK_20.0; + EXPERIMENTAL { global:
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH 2/7] eal: fix multiple definition of per lcore thread id
Quoted 68 lines · David Marchand
Because of the inline accessor + static declaration in
rte_gettid(), we end up with multiple symbols forRTE_PER_LCORE(_thread_id). Each compilation unit will pay a cost when accessing this information for the first time.$ nm build/app/dpdk-testpmd | grep per_lcore__thread_id 0000000000000054 d per_lcore__thread_id.5037 0000000000000040 d per_lcore__thread_id.5103 0000000000000048 d per_lcore__thread_id.5259 000000000000004c d per_lcore__thread_id.5259 0000000000000044 d per_lcore__thread_id.5933 0000000000000058 d per_lcore__thread_id.6261 0000000000000050 d per_lcore__thread_id.7378 000000000000005c d per_lcore__thread_id.7496 000000000000000c d per_lcore__thread_id.8016 0000000000000010 d per_lcore__thread_id.8431Make it global as part of the
DPDK_21stable ABI.Fixes ef76436c6834 ("eal: get unique thread id")Signed-off-by David Marchand <[email protected]>--- lib/librte_eal/common/eal_common_thread.c | 1 + lib/librte_eal/include/rte_eal.h | 3 ++- lib/librte_eal/rte_eal_version.map | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-)lib/librte_eal/common/eal_common_thread.c +1
-0@@ -24,6 +24,7 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +RTE_DEFINE_PER_LCORE (int, _thread_id) =-1 ; static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int )SOCKET_ID_ANY ; static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);lib/librte_eal/include/rte_eal.h +2
-1@@ -447,6 +447,8 @@ enum rte_intr_mode rte_eal_vfio_intr_mode(void);*/ int rte_sys_gettid (void ); +RTE_DECLARE_PER_LCORE (int, _thread_id); +/** * Get system unique thread id. * @@ -456,7 +458,6 @@ int rte_sys_gettid(void);*/ static inline int rte_gettid (void ) { - static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;if (RTE_PER_LCORE (_thread_id) ==-1 )RTE_PER_LCORE (_thread_id) =rte_sys_gettid ();return RTE_PER_LCORE (_thread_id);lib/librte_eal/rte_eal_version.map +0
-0@@ -221,6 +221,13 @@ DPDK_20.0 { local: *; };
lib/librte_eal/rte_eal_version.map DPDK_20.0 { · line 232
Quoted 10 lines
lib/librte_eal/rte_eal_version.map +7
-0+DPDK_21 { + global: + + per_lcore__thread_id; + +} DPDK_20.0; + EXPERIMENTAL { global:
PATCH 3/7 eal: introduce thread init helper
In reply to David MarchandIntroduce a helper responsible for initialising the per thread context. We can then have a unified context for EAL and non-EAL threads and remove copy/paste'd OS-specific helpers.
Per EAL thread CPU affinity setting is separated from the thread init. It is to accommodate with Windows EAL where CPU affinity is not set at the moment.
Besides, having affinity set by the master lcore in FreeBSD and Linux will make it possible to detect errors rather than panic in the child thread. But the cleanup when such an event happens is left for later.
Document Windows limitation wrt recursive locks not working because of lack of gettid().
--- lib/librte_eal/common/eal_common_thread.c | 58 ++++++++++++++--------- lib/librte_eal/common/eal_thread.h | 8 ++-- lib/librte_eal/freebsd/eal.c | 14 +++++- lib/librte_eal/freebsd/eal_thread.c | 32 +------------ lib/librte_eal/linux/eal.c | 15 +++++- lib/librte_eal/linux/eal_thread.c | 32 +------------ lib/librte_eal/windows/eal.c | 3 +- lib/librte_eal/windows/eal_thread.c | 10 +--- 8 files changed, 72 insertions(+), 100 deletions(-)
lib/librte_eal/common/eal_common_thread.c +36 -22
@@ -73,20 +73,10 @@ eal_cpuset_socket_id(rte_cpuset_t *cpusetp)return socket_id; } -int -rte_thread_set_affinity (rte_cpuset_t *cpusetp) +static void +thread_update_affinity (rte_cpuset_t *cpusetp) { -int s; -unsigned lcore_id; -pthread_t tid; - - tid =pthread_self (); - - s =pthread_setaffinity_np (tid,sizeof (rte_cpuset_t), cpusetp); -if (s !=0 ) { -RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); -return -1 ; - } +unsigned int lcore_id =rte_lcore_id ();/* store socket_id in TLS for quick access */ RTE_PER_LCORE(_socket_id) =
@@ -96,14 +86,24 @@ rte_thread_set_affinity(rte_cpuset_t *cpusetp)memmove (&RTE_PER_LCORE (_cpuset), cpusetp,sizeof (rte_cpuset_t)); - lcore_id =rte_lcore_id ();if (lcore_id != (unsigned )LCORE_ID_ANY ) {/* EAL thread will update lcore_config */ lcore_config[lcore_id].socket_id =RTE_PER_LCORE (_socket_id);memmove (&lcore_config[lcore_id].cpuset, cpusetp,sizeof (rte_cpuset_t)); } +} + +int +rte_thread_set_affinity (rte_cpuset_t *cpusetp) +{ +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + cpusetp) !=0 ) { +RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); +return -1 ; + } +thread_update_affinity (cpusetp);return 0 ; }
@@ -149,6 +149,25 @@ eal_thread_dump_affinity(char *str, unsigned size)return ret; } +void +rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) +{ +/* set the lcore ID in per-lcore memory area */ +RTE_PER_LCORE (_lcore_id) = lcore_id; + +#ifndef RTE_EXEC_ENV_WINDOWS +/* acquire system unique id */ +rte_gettid (); +#else +/* FIXME: gettid unimplemented => recursive locks can't work */ +#endif + +thread_update_affinity (cpuset); + +#ifndef RTE_EXEC_ENV_WINDOWS +__rte_trace_mem_per_thread_alloc (); +#endif +}struct rte_thread_ctrl_params {void *(*start_routine)(void *);
@@ -156,16 +175,14 @@ struct rte_thread_ctrl_params {pthread_barrier_t configured; }; -static void *rte_thread_init (void *arg) +static void *ctrl_thread_init (void *arg) {int ret; -rte_cpuset_t *cpuset = &internal_config.ctrl_cpuset;struct rte_thread_ctrl_params *params = arg;void *(*start_routine)(void *) = params->start_routine;void *routine_arg = params->arg; -/* Store cpuset in TLS for quick access */ -memmove (&RTE_PER_LCORE (_cpuset), cpuset,sizeof (rte_cpuset_t)); +rte_thread_init (rte_lcore_id (), &internal_config.ctrl_cpuset); ret =pthread_barrier_wait (¶ms->configured);if (ret ==PTHREAD_BARRIER_SERIAL_THREAD ) {
@@ -173,9 +190,6 @@ static void *rte_thread_init(void *arg)free (params); } -#ifndef RTE_EXEC_ENV_WINDOWS -__rte_trace_mem_per_thread_alloc (); -#endif return start_routine (routine_arg); }
@@ -197,7 +211,7 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_barrier_init (¶ms->configured,NULL ,2 ); - ret =pthread_create (thread, attr, rte_thread_init, (void *)params); + ret =pthread_create (thread, attr, ctrl_thread_init, (void *)params);if (ret !=0 ) {free (params);return -ret;
lib/librte_eal/common/eal_thread.h +5 -3
@@ -16,12 +16,14 @@ __rte_noreturn void *eal_thread_loop(void *arg);/** -* Init per-lcore info for master thread +* Init per-lcore info in current thread. * * @param lcore_id -* identifier of master lcore +* identifier of lcore. +* @param cpuset +* CPU affinity for this thread. */ -void eal_thread_init_master (unsigned lcore_id); +void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset);/** * Get the NUMA socket id from cpu id.
lib/librte_eal/freebsd/eal.c +13 -1
@@ -877,7 +877,14 @@ rte_eal_init(int argc, char **argv)eal_check_mem_on_local_socket (); -eal_thread_init_master (rte_config.master_lcore); +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + &lcore_config[rte_config.master_lcore].cpuset) !=0 ) { +rte_eal_init_alert ("Cannot set affinity" ); + rte_errno =EINVAL ; +return -1 ; + } +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset));
@@ -908,6 +915,11 @@ rte_eal_init(int argc, char **argv)snprintf (thread_name,sizeof (thread_name),"lcore-slave-%d" , i);rte_thread_setname (lcore_config[i].thread_id, thread_name); + + ret =pthread_setaffinity_np (lcore_config[i].thread_id, +sizeof (rte_cpuset_t), &lcore_config[i].cpuset); +if (ret !=0 ) +rte_panic ("Cannot set affinity\n" ); }/*
lib/librte_eal/freebsd/eal_thread.c +1 -31
@@ -66,29 +66,6 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)return rc; } -/* set affinity for current thread */ -static int -eal_thread_set_affinity (void ) -{ -unsigned lcore_id =rte_lcore_id (); - -/* acquire system unique id */ -rte_gettid (); - -/* update EAL thread core affinity */ -return rte_thread_set_affinity (&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master (unsigned lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); -} -/* main loop of threads */ __rte_noreturn void * eal_thread_loop(__rte_unused void *arg)
@@ -113,19 +90,12 @@ eal_thread_loop(__rte_unused void *arg) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , lcore_id, thread_id, cpuset, ret ==0 ?"" :"..." ); -__rte_trace_mem_per_thread_alloc ();rte_eal_trace_thread_lcore_ready (lcore_id, cpuset);/* read on our pipe to get commands */
lib/librte_eal/linux/eal.c +13 -2
@@ -1205,10 +1205,16 @@ rte_eal_init(int argc, char **argv)eal_check_mem_on_local_socket (); -eal_thread_init_master (rte_config.master_lcore); +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + &lcore_config[rte_config.master_lcore].cpuset) !=0 ) { +rte_eal_init_alert ("Cannot set affinity" ); + rte_errno =EINVAL ; +return -1 ; + } +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , rte_config.master_lcore, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
@@ -1240,6 +1246,11 @@ rte_eal_init(int argc, char **argv)if (ret !=0 )RTE_LOG (DEBUG ,EAL ,"Cannot set name for lcore thread\n" ); + + ret =pthread_setaffinity_np (lcore_config[i].thread_id, +sizeof (rte_cpuset_t), &lcore_config[i].cpuset); +if (ret !=0 ) +rte_panic ("Cannot set affinity\n" ); }/*
lib/librte_eal/linux/eal_thread.c +1 -31
@@ -66,29 +66,6 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)return rc; } -/* set affinity for current EAL thread */ -static int -eal_thread_set_affinity (void ) -{ -unsigned lcore_id =rte_lcore_id (); - -/* acquire system unique id */ -rte_gettid (); - -/* update EAL thread core affinity */ -return rte_thread_set_affinity (&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master (unsigned lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); -} -/* main loop of threads */ __rte_noreturn void * eal_thread_loop(__rte_unused void *arg)
@@ -113,19 +90,12 @@ eal_thread_loop(__rte_unused void *arg) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." ); -__rte_trace_mem_per_thread_alloc ();rte_eal_trace_thread_lcore_ready (lcore_id, cpuset);/* read on our pipe to get commands */
lib/librte_eal/windows/eal.c +2 -1
@@ -244,7 +244,8 @@ rte_eal_init(int argc, char **argv)if (fctret <0 )exit (1 ); -eal_thread_init_master (rte_config.master_lcore); +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset);RTE_LCORE_FOREACH_SLAVE (i) {
lib/librte_eal/windows/eal_thread.c +1 -9
@@ -53,13 +53,6 @@ rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int slave_id)return 0 ; } -void -eal_thread_init_master (unsigned int lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; -} -static inline pthread_t eal_thread_self (void ) {
@@ -90,8 +83,7 @@ eal_thread_loop(void *arg __rte_unused) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset);RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset);
Signature · 1 line
2.23.0
PATCH 4/7 eal: introduce thread uninit helper
In reply to David MarchandThis is a preparation step for dynamically unregistering external threads.
Since we explicitly allocate a per thread trace buffer in rte_thread_init, add an internal helper to free this buffer.
Note: I preferred renaming the current internal function to free all threads trace buffers (new name trace_mem_free()) and reuse the previous name (trace_mem_per_thread_free()) when freeing this buffer for a given thread.
--- lib/librte_eal/common/eal_common_thread.c | 9 +++++ lib/librte_eal/common/eal_common_trace.c | 49 +++++++++++++++++++---- lib/librte_eal/common/eal_thread.h | 5 +++ lib/librte_eal/common/eal_trace.h | 1 + 4 files changed, 57 insertions(+), 7 deletions(-)
lib/librte_eal/common/eal_common_thread.c +9 -0
@@ -22,6 +22,7 @@#include "eal_internal_cfg.h" #include "eal_private.h" #include "eal_thread.h" +#include "eal_trace.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;RTE_DEFINE_PER_LCORE (int, _thread_id) =-1 ;
@@ -169,6 +170,14 @@ rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset)#endif } +void +rte_thread_uninit (void ) +{ +#ifndef RTE_EXEC_ENV_WINDOWS +trace_mem_per_thread_free (); +#endif +} +struct rte_thread_ctrl_params {void *(*start_routine)(void *);void *arg;
lib/librte_eal/common/eal_common_trace.c +42 -7
73 lines not on this page · raw message
lib/librte_eal/common/eal_thread.h +5 -0
@@ -25,6 +25,11 @@ __rte_noreturn void *eal_thread_loop(void *arg);*/ void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset); +/** +* Uninitialize per-lcore info for current thread. +*/ +void rte_thread_uninit (void ); +/** * Get the NUMA socket id from cpu id. * This function is private to EAL.
lib/librte_eal/common/eal_trace.h +1 -0
@@ -106,6 +106,7 @@ int trace_metadata_create(void);void trace_metadata_destroy (void );int trace_mkdir (void );int trace_epoch_time_save (void ); +void trace_mem_free (void );void trace_mem_per_thread_free (void );/* EAL interface */
Signature · 1 line
2.23.0
PATCH 5/7 eal: register non-EAL threads as lcore
In reply to David MarchandDPDK allows calling some part of its API from a non-EAL thread but this has some limitations.
OVS (and other applications) has its own thread management but still want to avoid such limitations by hacking RTE_PER_LCORE(_lcore_id) and faking EAL threads potentially unknown of some DPDK component.
Introduce a new API to register non-EAL thread and associate them to a free lcore with a new EXTERNAL role.
This role denotes lcores that do not run DPDK mainloop and as such prevents use of rte_eal_wait_lcore() and consorts.
--- doc/guides/howto/debug_troubleshoot.rst | 5 ++- lib/librte_eal/common/eal_common_lcore.c | 44 +++++++++++++++++-- lib/librte_eal/common/eal_common_thread.c | 45 ++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 17 ++++++++ lib/librte_eal/include/rte_eal.h | 9 ---- lib/librte_eal/include/rte_lcore.h | 52 +++++++++++++++++------ lib/librte_eal/rte_eal_version.map | 4 ++ 7 files changed, 147 insertions(+), 29 deletions(-)
doc/guides/howto/debug_troubleshoot.rst +3 -2
@@ -307,8 +307,9 @@ Custom worker function :numref:`dtg_distributor_worker`. #. Configuration issue isolation - * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF and - SERVICE. Check performance functions are mapped to run on the cores. + * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF, + SERVICE and EXTERNAL. Check performance functions are mapped to run on the + cores. * For high-performance execution logic ensure running it on correct NUMA and non-master core.
lib/librte_eal/common/eal_common_lcore.c +40 -4
56 lines not on this page · raw message
lib/librte_eal/common/eal_common_thread.c +45 -0
54 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +17 -0
@@ -274,6 +274,23 @@ uint64_t get_tsc_freq(void);*/ uint64_t get_tsc_freq_arch (void ); +/** +* Ask for a free lcore to associate to a non-EAL thread. +* +* @return +* The id of a lcore with role ROLE_EXTERNAL or RTE_MAX_LCORE if none was +* available. +*/ +unsigned int eal_lcore_external_reserve (void ); + +/** +* Release an external lcore. +* +* @param lcore_id +* The lcore with role ROLE_EXTERNAL to release. +*/ +void eal_lcore_external_release (unsigned int lcore_id); +/** * Prepare physical memory mapping * i.e. hugepages on Linux and
lib/librte_eal/include/rte_eal.h +0 -9
@@ -31,15 +31,6 @@ extern "C" {/* Maximum thread_name length. */ #define RTE_MAX_THREAD_NAME_LEN 16 -/** -* The lcore role (used in RTE or not). -*/ -enum rte_lcore_role_t { -ROLE_RTE , -ROLE_OFF , -ROLE_SERVICE , -}; -/** * The type of process in a linux, multi-process setup */
lib/librte_eal/include/rte_lcore.h +38 -14
76 lines not on this page · raw message
lib/librte_eal/rte_eal_version.map +4 -0
@@ -393,4 +393,8 @@ EXPERIMENTAL { rte_trace_point_lookup; rte_trace_regexp; rte_trace_save; + + # added in 20.08 + rte_thread_register; + rte_thread_unregister; };
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH 5/7] eal: register non-EAL threads as lcore
Quoted 297 lines · David Marchand
DPDK allows calling some part of its API from a non-EAL thread but this has some limitations.
OVS (and other applications) has its own thread management but still want to avoid such limitations by hackingRTE_PER_LCORE(_lcore_id)and faking EAL threads potentially unknown of some DPDK component.Introduce a new API to register non-EAL thread and associate them to a free lcore with a new EXTERNAL role.
This role denotes lcores that do not run DPDK mainloop and as such prevents use ofrte_eal_wait_lcore()and consorts.Signed-off-by David Marchand <[email protected]>--- doc/guides/howto/debug_troubleshoot.rst | 5 ++- lib/librte_eal/common/eal_common_lcore.c | 44 +++++++++++++++++-- lib/librte_eal/common/eal_common_thread.c | 45 ++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 17 ++++++++ lib/librte_eal/include/rte_eal.h | 9 ---- lib/librte_eal/include/rte_lcore.h | 52 +++++++++++++++++------ lib/librte_eal/rte_eal_version.map | 4 ++ 7 files changed, 147 insertions(+), 29 deletions(-)doc/guides/howto/debug_troubleshoot.rst +3
-2@@ -307,8 +307,9 @@ Custom worker function :numref:`dtg_distributor_worker`. #. Configuration issue isolation - * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF and - SERVICE. Check performance functions are mapped to run on the cores. + * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF, + SERVICE and EXTERNAL. Check performance functions are mapped to run on the + cores. * For high-performance execution logic ensure running it on correct NUMA and non-master core.lib/librte_eal/common/eal_common_lcore.c +40
-4@@ -6,13 +6,15 @@#include <limits.h> #include <string.h> -#include <rte_errno.h> -#include <rte_log.h> -#include <rte_eal.h> -#include <rte_lcore.h> #include <rte_common.h> #include <rte_debug.h> +#include <rte_eal.h> +#include <rte_errno.h> +#include <rte_lcore.h> +#include <rte_log.h> +#include <rte_spinlock.h> +#include "eal_internal_cfg.h" #include "eal_private.h" #include "eal_thread.h" @@ -209,3 +211,37 @@ rte_socket_id_by_idx(unsigned int idx) }return config->numa_nodes[idx]; } + +rte_spinlock_t external_lcore_lock =RTE_SPINLOCK_INITIALIZER ; + +unsigned int +eal_lcore_external_reserve (void ) +{ +struct rte_config *cfg =rte_eal_get_configuration (); +unsigned int lcore_id; + +rte_spinlock_lock (&external_lcore_lock); +for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +if (rte_eal_lcore_role (lcore_id) !=ROLE_OFF ) +continue ; + cfg->lcore_role[lcore_id] =ROLE_EXTERNAL ; + cfg->lcore_count++; +break ; + } +rte_spinlock_unlock (&external_lcore_lock); + +return lcore_id; +} + +void +eal_lcore_external_release (unsigned int lcore_id) +{ +struct rte_config *cfg =rte_eal_get_configuration (); + +rte_spinlock_lock (&external_lcore_lock); +if (rte_eal_lcore_role (lcore_id) ==ROLE_EXTERNAL ) { + cfg->lcore_role[lcore_id] =ROLE_OFF ; + cfg->lcore_count--; + } +rte_spinlock_unlock (&external_lcore_lock); +}lib/librte_eal/common/eal_common_thread.c +45
-0@@ -29,6 +29,7 @@ RTE_DEFINE_PER_LCORE(int, _thread_id) = -1; static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int )SOCKET_ID_ANY ; static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset); +static RTE_DEFINE_PER_LCORE(bool, thread_registered);unsigned rte_socket_id (void ) {@@ -255,3 +256,47 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_join (*thread,NULL );return -ret; } + +void +rte_thread_register (void ) +{ +unsigned int lcore_id; +rte_cpuset_t cpuset; + +/* EAL init flushes all lcores, we can't register before. */ +assert (internal_config.init_complete ==1 ); + +if (RTE_PER_LCORE (thread_registered)) +return ; + +if (pthread_getaffinity_np (pthread_self (),sizeof (cpuset), + &cpuset) !=0 ) +CPU_ZERO (&cpuset); + + lcore_id =eal_lcore_external_reserve (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ; + +rte_thread_init (lcore_id, &cpuset); + +RTE_LOG (DEBUG ,EAL ,"Registered thread as lcore %u.\n" , lcore_id); +RTE_PER_LCORE (thread_registered) = true; +} + +void +rte_thread_unregister (void ) +{ +unsigned int lcore_id; + +if (!RTE_PER_LCORE (thread_registered)) +return ; + + lcore_id =RTE_PER_LCORE (_lcore_id); +if (lcore_id !=LCORE_ID_ANY ) +eal_lcore_external_release (lcore_id); + +rte_thread_uninit (); + +RTE_LOG (DEBUG ,EAL ,"Unregistered thread (was lcore %u).\n" , lcore_id); +RTE_PER_LCORE (thread_registered) = false; +}lib/librte_eal/common/eal_private.h +17
-0@@ -274,6 +274,23 @@ uint64_t get_tsc_freq(void);*/ uint64_t get_tsc_freq_arch (void ); +/** +* Ask for a free lcore to associate to a non-EAL thread. +* +* @return +* The id of a lcore with role ROLE_EXTERNAL or RTE_MAX_LCORE if none was +* available. +*/ +unsigned int eal_lcore_external_reserve (void ); + +/** +* Release an external lcore. +* +* @param lcore_id +* The lcore with role ROLE_EXTERNAL to release. +*/ +void eal_lcore_external_release (unsigned int lcore_id); +/** * Prepare physical memory mapping * i.e. hugepages on Linux and lib/librte_eal/include/rte_eal.h +0
-9@@ -31,15 +31,6 @@ extern "C" {/* Maximum thread_name length. */ #define RTE_MAX_THREAD_NAME_LEN 16 -/** -* The lcore role (used in RTE or not). -*/ -enum rte_lcore_role_t { -ROLE_RTE , -ROLE_OFF , -ROLE_SERVICE , -}; -/** * The type of process in a linux, multi-process setup */ lib/librte_eal/include/rte_lcore.h +38
-14@@ -24,6 +24,16 @@ extern "C" {RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ +/** +* The lcore role (used in RTE or not). +*/ +enum rte_lcore_role_t { +ROLE_RTE , +ROLE_OFF , +ROLE_SERVICE , +ROLE_EXTERNAL , +}; +/** * Get a lcore's role. * @@ -34,6 +44,20 @@ RTE_DECLARE_PER_LCORE(unsigned, _lcore_id); /**< Per thread "lcore id". */*/ enum rte_lcore_role_t rte_eal_lcore_role (unsigned int lcore_id); +/** +* Test if the core supplied has a specific role +* +* @param lcore_id +* The identifier of the lcore, which MUST be between 0 and +* RTE_MAX_LCORE-1. +* @param role +* The role to be checked against. +* @return +* Boolean value: positive if test is true; otherwise returns 0. +*/ +int +rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role); +/** * Return the Application thread ID of the execution unit. * @@ -256,6 +280,20 @@ int rte_thread_setname(pthread_t id, const char *name);__rte_experimental int rte_thread_getname(pthread_t id, char *name, size_t len); +/** +* Register current non-EAL thread as a lcore. +*/ +__rte_experimental +void +rte_thread_register (void ); + +/** +* Unregister current thread and release lcore if one was associated. +*/ +__rte_experimental +void +rte_thread_unregister (void ); +/** * Create a control thread. * @@ -283,20 +321,6 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); -/** -* Test if the core supplied has a specific role -* -* @param lcore_id -* The identifier of the lcore, which MUST be between 0 and -* RTE_MAX_LCORE-1. -* @param role -* The role to be checked against. -* @return -* Boolean value: positive if test is true; otherwise returns 0. -*/ -int -rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role); - #ifdef __cplusplus }#endif lib/librte_eal/rte_eal_version.map +0
-0
lib/librte_eal/rte_eal_version.map EXPERIMENTAL { · line 400
Quoted 8 lines
lib/librte_eal/rte_eal_version.map +4
-0@@ -393,4 +393,8 @@ EXPERIMENTAL { rte_trace_point_lookup; rte_trace_regexp; rte_trace_save; + + # added in 20.08 + rte_thread_register; + rte_thread_unregister; };
PATCH 6/7 eal: dump lcores
In reply to David MarchandAdd a little helper to dump all lcores.
--- lib/librte_eal/common/eal_common_lcore.c | 32 +++++++++++++++++++++++ lib/librte_eal/common/eal_common_thread.c | 16 ++++++++---- lib/librte_eal/common/eal_thread.h | 13 +++++++-- lib/librte_eal/freebsd/eal.c | 2 +- lib/librte_eal/freebsd/eal_thread.c | 2 +- lib/librte_eal/include/rte_lcore.h | 10 +++++++ lib/librte_eal/linux/eal.c | 2 +- lib/librte_eal/linux/eal_thread.c | 2 +- lib/librte_eal/rte_eal_version.map | 1 + 9 files changed, 69 insertions(+), 11 deletions(-)
lib/librte_eal/common/eal_common_lcore.c +32 -0
@@ -245,3 +245,35 @@ eal_lcore_external_release(unsigned int lcore_id) }rte_spinlock_unlock (&external_lcore_lock); } + +void +rte_lcore_dump (FILE *f) +{ +char cpuset[RTE_CPU_AFFINITY_STR_LEN ]; +unsigned int lcore_id; +const char *role; +int ret; + +rte_spinlock_lock (&external_lcore_lock); +for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +switch (rte_eal_lcore_role (lcore_id)) { +case ROLE_RTE : + role ="RTE" ; +break ; +case ROLE_SERVICE : + role ="SERVICE" ; +break ; +case ROLE_EXTERNAL : + role ="EXTERNAL" ; +break ; +default : +continue ; + } + + ret =eal_thread_dump_affinity (&lcore_config[lcore_id].cpuset, + cpuset,sizeof (cpuset)); +fprintf (f,"lcore %u, role %s, cpuset %s%s\n" , lcore_id, role, + cpuset, ret ==0 ?"" :"..." ); + } +rte_spinlock_unlock (&external_lcore_lock); +}
lib/librte_eal/common/eal_common_thread.c +11 -5
@@ -118,17 +118,14 @@ rte_thread_get_affinity(rte_cpuset_t *cpusetp) }int -eal_thread_dump_affinity (char *str,unsigned size) +eal_thread_dump_affinity (rte_cpuset_t *cpuset,char *str,unsigned int size) { -rte_cpuset_t cpuset;unsigned cpu;int ret;unsigned int out =0 ; -rte_thread_get_affinity (&cpuset); -for (cpu =0 ; cpu <CPU_SETSIZE ; cpu++) { -if (!CPU_ISSET (cpu, &cpuset)) +if (!CPU_ISSET (cpu, cpuset))continue ; ret = snprintf(str + out,
@@ -151,6 +148,15 @@ eal_thread_dump_affinity(char *str, unsigned size)return ret; } +int +eal_thread_dump_current_affinity (char *str,unsigned int size) +{ +rte_cpuset_t cpuset; + +rte_thread_get_affinity (&cpuset); +return eal_thread_dump_affinity (&cpuset, str, size); +} +void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) {
lib/librte_eal/common/eal_thread.h +11 -2
@@ -47,13 +47,15 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);#define RTE_CPU_AFFINITY_STR_LEN 256/** -* Dump the current pthread cpuset. +* Dump the cpuset as a human readable string. * This function is private to EAL. * * Note: * If the dump size is greater than the size of given buffer, * the string will be truncated and with '\0' at the end. * +* @param cpuset +* The CPU affinity object to dump. * @param str * The string buffer the cpuset will dump to. * @param size
@@ -62,6 +64,13 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);* 0 for success, -1 if truncation happens. */ int -eal_thread_dump_affinity (char *str,unsigned size); +eal_thread_dump_affinity (rte_cpuset_t *cpuset,char *str,unsigned int size); + +/** +* Dump the current thread cpuset. +* This is a wrapper on eal_thread_dump_affinity(). +*/ +int +eal_thread_dump_current_affinity (char *str,unsigned int size);#endif /* EAL_THREAD_H */
lib/librte_eal/freebsd/eal.c +1 -1
@@ -886,7 +886,7 @@ rte_eal_init(int argc, char **argv)rte_thread_init (rte_config.master_lcore, &lcore_config[rte_config.master_lcore].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset)); RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n", rte_config.master_lcore, thread_id, cpuset,
lib/librte_eal/freebsd/eal_thread.c +1 -1
@@ -92,7 +92,7 @@ eal_thread_loop(__rte_unused void *arg)rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , lcore_id, thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/include/rte_lcore.h +10 -0
@@ -228,6 +228,16 @@ unsigned int rte_get_next_lcore(unsigned int i, int skip_master, int wrap); i<RTE_MAX_LCORE ; \ i = rte_get_next_lcore(i, 1, 0)) +/** +* List all lcores. +* +* @param f +* The output stream where the dump should be sent. +*/ +__rte_experimental +void +rte_lcore_dump (FILE *f); +/** * Set core affinity of the current thread. * Support both EAL and non-EAL thread and update TLS.
lib/librte_eal/linux/eal.c +1 -1
@@ -1214,7 +1214,7 @@ rte_eal_init(int argc, char **argv)rte_thread_init (rte_config.master_lcore, &lcore_config[rte_config.master_lcore].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , rte_config.master_lcore, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/linux/eal_thread.c +1 -1
@@ -92,7 +92,7 @@ eal_thread_loop(__rte_unused void *arg)rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/rte_eal_version.map +1 -0
@@ -395,6 +395,7 @@ EXPERIMENTAL { rte_trace_save; # added in 20.08 + rte_lcore_dump; rte_thread_register; rte_thread_unregister; };
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH 6/7] eal: dump lcores
Quoted 42 lines · David Marchand
Add a little helper to dump all lcores.
Signed-off-by David Marchand <[email protected]>--- lib/librte_eal/common/eal_common_lcore.c | 32 +++++++++++++++++++++++ lib/librte_eal/common/eal_common_thread.c | 16 ++++++++---- lib/librte_eal/common/eal_thread.h | 13 +++++++-- lib/librte_eal/freebsd/eal.c | 2 +- lib/librte_eal/freebsd/eal_thread.c | 2 +- lib/librte_eal/include/rte_lcore.h | 10 +++++++ lib/librte_eal/linux/eal.c | 2 +- lib/librte_eal/linux/eal_thread.c | 2 +- lib/librte_eal/rte_eal_version.map | 1 + 9 files changed, 69 insertions(+), 11 deletions(-)lib/librte_eal/common/eal_common_lcore.c +19
-0@@ -245,3 +245,35 @@ eal_lcore_external_release(unsigned int lcore_id) }rte_spinlock_unlock (&external_lcore_lock); } + +void +rte_lcore_dump (FILE *f) +{ +char cpuset[RTE_CPU_AFFINITY_STR_LEN ]; +unsigned int lcore_id; +const char *role; +int ret; + +rte_spinlock_lock (&external_lcore_lock); +for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +switch (rte_eal_lcore_role (lcore_id)) { +case ROLE_RTE : + role ="RTE" ; +break ; +case ROLE_SERVICE : + role ="SERVICE" ; +break ; +case ROLE_EXTERNAL :
lib/librte_eal/common/eal_common_lcore.c eal_lcore_external_release(unsigned int lcore_id) · line 276
Quoted 10 lines
lib/librte_eal/common/eal_common_lcore.c +10
-0+ role ="EXTERNAL" ; +break ; +default : +continue ; + } + + ret =eal_thread_dump_affinity (&lcore_config[lcore_id].cpuset, + cpuset,sizeof (cpuset)); +fprintf (f,"lcore %u, role %s, cpuset %s%s\n" , lcore_id, role, + cpuset, ret ==0 ?"" :"..." );
Out of interest - why fprintf instead of rte_log?
Quoted 164 lines
lib/librte_eal/common/eal_common_lcore.c +3
-0+ } +rte_spinlock_unlock (&external_lcore_lock); +}lib/librte_eal/common/eal_common_thread.c +11
-5@@ -118,17 +118,14 @@ rte_thread_get_affinity(rte_cpuset_t *cpusetp) }int -eal_thread_dump_affinity (char *str,unsigned size) +eal_thread_dump_affinity (rte_cpuset_t *cpuset,char *str,unsigned int size) { -rte_cpuset_t cpuset;unsigned cpu;int ret;unsigned int out =0 ; -rte_thread_get_affinity (&cpuset); -for (cpu =0 ; cpu <CPU_SETSIZE ; cpu++) { -if (!CPU_ISSET (cpu, &cpuset)) +if (!CPU_ISSET (cpu, cpuset))continue ; ret = snprintf(str + out,@@ -151,6 +148,15 @@ eal_thread_dump_affinity(char *str, unsigned size)return ret; } +int +eal_thread_dump_current_affinity (char *str,unsigned int size) +{ +rte_cpuset_t cpuset; + +rte_thread_get_affinity (&cpuset); +return eal_thread_dump_affinity (&cpuset, str, size); +} +void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) {lib/librte_eal/common/eal_thread.h +11
-2@@ -47,13 +47,15 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);#define RTE_CPU_AFFINITY_STR_LEN 256/** -* Dump the current pthread cpuset. +* Dump the cpuset as a human readable string. * This function is private to EAL. * * Note: * If the dump size is greater than the size of given buffer, * the string will be truncated and with '\0' at the end. * +* @param cpuset +* The CPU affinity object to dump. * @param str * The string buffer the cpuset will dump to. * @param size @@ -62,6 +64,13 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);* 0 for success, -1 if truncation happens. */ int -eal_thread_dump_affinity (char *str,unsigned size); +eal_thread_dump_affinity (rte_cpuset_t *cpuset,char *str,unsigned int size); + +/** +* Dump the current thread cpuset. +* This is a wrapper on eal_thread_dump_affinity(). +*/ +int +eal_thread_dump_current_affinity (char *str,unsigned int size);#endif /* EAL_THREAD_H */ lib/librte_eal/freebsd/eal.c +1
-1@@ -886,7 +886,7 @@ rte_eal_init(int argc, char **argv)rte_thread_init (rte_config.master_lcore, &lcore_config[rte_config.master_lcore].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset)); RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n", rte_config.master_lcore, thread_id, cpuset,lib/librte_eal/freebsd/eal_thread.c +1
-1@@ -92,7 +92,7 @@ eal_thread_loop(__rte_unused void *arg)rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , lcore_id, thread_id, cpuset, ret ==0 ?"" :"..." );lib/librte_eal/include/rte_lcore.h +10
-0@@ -228,6 +228,16 @@ unsigned int rte_get_next_lcore(unsigned int i, int skip_master, int wrap); i<RTE_MAX_LCORE ; \ i = rte_get_next_lcore(i, 1, 0)) +/** +* List all lcores. +* +* @param f +* The output stream where the dump should be sent. +*/ +__rte_experimental +void +rte_lcore_dump (FILE *f); +/** * Set core affinity of the current thread. * Support both EAL and non-EAL thread and update TLS. lib/librte_eal/linux/eal.c +1
-1@@ -1214,7 +1214,7 @@ rte_eal_init(int argc, char **argv)rte_thread_init (rte_config.master_lcore, &lcore_config[rte_config.master_lcore].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , rte_config.master_lcore, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );lib/librte_eal/linux/eal_thread.c +1
-1@@ -92,7 +92,7 @@ eal_thread_loop(__rte_unused void *arg)rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );lib/librte_eal/rte_eal_version.map +1
-0@@ -395,6 +395,7 @@ EXPERIMENTAL { rte_trace_save; # added in 20.08 + rte_lcore_dump; rte_thread_register; rte_thread_unregister; };
PATCH 7/7 eal: add lcore hotplug notifications
In reply to David MarchandNow that lcores can be dynamically allocated/freed, we will have to notify DPDK components and applications of such events for cases where per lcore context must be allocated/initialised.
--- lib/librte_eal/common/eal_common_lcore.c | 91 +++++++++++++++++++++++ lib/librte_eal/common/eal_common_thread.c | 11 ++- lib/librte_eal/common/eal_private.h | 26 +++++++ lib/librte_eal/include/rte_lcore.h | 49 ++++++++++++ lib/librte_eal/rte_eal_version.map | 2 + 5 files changed, 178 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_lcore.c +91 -0
@@ -212,6 +212,47 @@ rte_socket_id_by_idx(unsigned int idx)return config->numa_nodes[idx]; } +struct lcore_notifier { +TAILQ_ENTRY (lcore_notifier) next; +rte_lcore_notifier_cb cb; +void *arg; +}; +static TAILQ_HEAD(lcore_notifiers_head, lcore_notifier) lcore_notifiers = +TAILQ_HEAD_INITIALIZER (lcore_notifiers); +static rte_spinlock_t lcore_notifiers_lock =RTE_SPINLOCK_INITIALIZER ; + +void * +rte_lcore_notifier_register (rte_lcore_notifier_cb cb,void *arg) +{ +struct lcore_notifier *notifier; + +if (cb ==NULL ) +return NULL ; + + notifier =calloc (1 ,sizeof (*notifier)); +if (notifier ==NULL ) +return NULL ; + + notifier->cb = cb; + notifier->arg = arg; +rte_spinlock_lock (&lcore_notifiers_lock); +TAILQ_INSERT_TAIL (&lcore_notifiers, notifier, next); +rte_spinlock_unlock (&lcore_notifiers_lock); + +return notifier; +} + +void +rte_lcore_notifier_unregister (void *handle) +{ +struct lcore_notifier *notifier = handle; + +rte_spinlock_lock (&lcore_notifiers_lock); +TAILQ_REMOVE (&lcore_notifiers, notifier, next); +rte_spinlock_unlock (&lcore_notifiers_lock); +free (notifier); +} +rte_spinlock_t external_lcore_lock =RTE_SPINLOCK_INITIALIZER ;unsigned int
@@ -277,3 +318,53 @@ rte_lcore_dump(FILE *f) }rte_spinlock_unlock (&external_lcore_lock); } + +int +eal_lcore_external_notify_allocated (unsigned int lcore_id) +{ +struct lcore_notifier *notifier; +int ret =0 ; + +RTE_LOG (DEBUG ,EAL ,"New lcore %u.\n" , lcore_id); +rte_spinlock_lock (&lcore_notifiers_lock); + TAILQ_FOREACH(notifier, &lcore_notifiers, next) { +if (notifier->cb (lcore_id,RTE_LCORE_EVENT_NEW_EXTERNAL , + notifier->arg) ==0 ) +continue ; + +/* Some notifier refused the new lcore, inform all notifiers +* that acked it. +*/ +RTE_LOG (DEBUG ,EAL ,"A lcore notifier refused new lcore %u.\n" , + lcore_id); + + notifier =TAILQ_PREV (notifier, lcore_notifiers_head, next); +while (notifier !=NULL ) { + notifier->cb (lcore_id, +RTE_LCORE_EVENT_RELEASE_EXTERNAL , + notifier->arg); + notifier =TAILQ_PREV (notifier, lcore_notifiers_head, + next); + } + ret =-1 ; +break ; + } +rte_spinlock_unlock (&lcore_notifiers_lock); + +return ret; +} + +void +eal_lcore_external_notify_removed (unsigned int lcore_id) +{ +struct lcore_notifier *notifier; + +RTE_LOG (DEBUG ,EAL ,"Released lcore %u.\n" , lcore_id); +rte_spinlock_lock (&lcore_notifiers_lock); +TAILQ_FOREACH_REVERSE (notifier, &lcore_notifiers, lcore_notifiers_head, + next) { + notifier->cb (lcore_id,RTE_LCORE_EVENT_RELEASE_EXTERNAL , + notifier->arg); + } +rte_spinlock_unlock (&lcore_notifiers_lock); +}
lib/librte_eal/common/eal_common_thread.c +10 -1
@@ -285,6 +285,12 @@ rte_thread_register(void)rte_thread_init (lcore_id, &cpuset); +if (lcore_id !=LCORE_ID_ANY && +eal_lcore_external_notify_allocated (lcore_id) <0 ) { +eal_lcore_external_release (lcore_id); +RTE_PER_LCORE (_lcore_id) = lcore_id =LCORE_ID_ANY ; + } +RTE_LOG (DEBUG ,EAL ,"Registered thread as lcore %u.\n" , lcore_id);RTE_PER_LCORE (thread_registered) = true; }
@@ -298,8 +304,11 @@ rte_thread_unregister(void)return ; lcore_id =RTE_PER_LCORE (_lcore_id); -if (lcore_id !=LCORE_ID_ANY ) +if (lcore_id !=LCORE_ID_ANY ) { +eal_lcore_external_notify_removed (lcore_id);eal_lcore_external_release (lcore_id); +RTE_PER_LCORE (_lcore_id) =LCORE_ID_ANY ; + }rte_thread_uninit ();
lib/librte_eal/common/eal_private.h +26 -0
@@ -283,6 +283,21 @@ uint64_t get_tsc_freq_arch(void);*/ unsigned int eal_lcore_external_reserve (void ); +/** +* Evaluate all lcore notifiers with a RTE_LCORE_EVENT_NEW_EXTERNAL event for +* the passed lcore. +* If an error is returned by one of them, then this change is rolled back: +* all previous lcore notifiers that had acked the RTE_LCORE_EVENT_NEW_EXTERNAL +* event receive a RTE_LCORE_EVENT_RELEASE_EXTERNAL event for the passed lcore. +* +* @param lcore_id +* The lcore to consider. +* @return +* - 0 if all notifiers agreed on the new lcore +* - -1 if one of them refused +*/ +int eal_lcore_external_notify_allocated (unsigned int lcore_id); +/** * Release an external lcore. *
@@ -291,6 +306,17 @@ unsigned int eal_lcore_external_reserve(void);*/ void eal_lcore_external_release (unsigned int lcore_id); +/** +* Evaluate all lcore notifiers with a RTE_LCORE_EVENT_RELEASE_EXTERNAL event +* for the passed lcore. +* This function must be called with a lcore that successfully passed +* eal_lcore_external_notify_allocated(). +* +* @param lcore_id +* The lcore with role ROLE_EXTERNAL to release. +*/ +void eal_lcore_external_notify_removed (unsigned int lcore_id); +/** * Prepare physical memory mapping * i.e. hugepages on Linux and
lib/librte_eal/include/rte_lcore.h +49 -0
55 lines not on this page · raw message
lib/librte_eal/rte_eal_version.map +2 -0
@@ -396,6 +396,8 @@ EXPERIMENTAL { # added in 20.08 rte_lcore_dump; + rte_lcore_notifier_register; + rte_lcore_notifier_unregister; rte_thread_register; rte_thread_unregister; };
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH 7/7] eal: add lcore hotplug notifications
From ABI PoV, you are 100%.
Is the agreed term 'callback'?, not 'notifier' for example rte_dev_event_callback_register, rte_mem_event_callback_register
I did wonder however, if all these cb's would be better handled through a EventDev event notification style approach.
Ray K
Quoted 266 lines · David Marchand
Now that lcores can be dynamically allocated/freed, we will have to notify DPDK components and applications of such events for cases where per lcore context must be allocated/initialised.
Signed-off-by David Marchand <[email protected]>--- lib/librte_eal/common/eal_common_lcore.c | 91 +++++++++++++++++++++++ lib/librte_eal/common/eal_common_thread.c | 11 ++- lib/librte_eal/common/eal_private.h | 26 +++++++ lib/librte_eal/include/rte_lcore.h | 49 ++++++++++++ lib/librte_eal/rte_eal_version.map | 2 + 5 files changed, 178 insertions(+), 1 deletion(-)lib/librte_eal/common/eal_common_lcore.c +91
-0@@ -212,6 +212,47 @@ rte_socket_id_by_idx(unsigned int idx)return config->numa_nodes[idx]; } +struct lcore_notifier { +TAILQ_ENTRY (lcore_notifier) next; +rte_lcore_notifier_cb cb; +void *arg; +}; +static TAILQ_HEAD(lcore_notifiers_head, lcore_notifier) lcore_notifiers = +TAILQ_HEAD_INITIALIZER (lcore_notifiers); +static rte_spinlock_t lcore_notifiers_lock =RTE_SPINLOCK_INITIALIZER ; + +void * +rte_lcore_notifier_register (rte_lcore_notifier_cb cb,void *arg) +{ +struct lcore_notifier *notifier; + +if (cb ==NULL ) +return NULL ; + + notifier =calloc (1 ,sizeof (*notifier)); +if (notifier ==NULL ) +return NULL ; + + notifier->cb = cb; + notifier->arg = arg; +rte_spinlock_lock (&lcore_notifiers_lock); +TAILQ_INSERT_TAIL (&lcore_notifiers, notifier, next); +rte_spinlock_unlock (&lcore_notifiers_lock); + +return notifier; +} + +void +rte_lcore_notifier_unregister (void *handle) +{ +struct lcore_notifier *notifier = handle; + +rte_spinlock_lock (&lcore_notifiers_lock); +TAILQ_REMOVE (&lcore_notifiers, notifier, next); +rte_spinlock_unlock (&lcore_notifiers_lock); +free (notifier); +} +rte_spinlock_t external_lcore_lock =RTE_SPINLOCK_INITIALIZER ;unsigned int @@ -277,3 +318,53 @@ rte_lcore_dump(FILE *f) }rte_spinlock_unlock (&external_lcore_lock); } + +int +eal_lcore_external_notify_allocated (unsigned int lcore_id) +{ +struct lcore_notifier *notifier; +int ret =0 ; + +RTE_LOG (DEBUG ,EAL ,"New lcore %u.\n" , lcore_id); +rte_spinlock_lock (&lcore_notifiers_lock); + TAILQ_FOREACH(notifier, &lcore_notifiers, next) { +if (notifier->cb (lcore_id,RTE_LCORE_EVENT_NEW_EXTERNAL , + notifier->arg) ==0 ) +continue ; + +/* Some notifier refused the new lcore, inform all notifiers +* that acked it. +*/ +RTE_LOG (DEBUG ,EAL ,"A lcore notifier refused new lcore %u.\n" , + lcore_id); + + notifier =TAILQ_PREV (notifier, lcore_notifiers_head, next); +while (notifier !=NULL ) { + notifier->cb (lcore_id, +RTE_LCORE_EVENT_RELEASE_EXTERNAL , + notifier->arg); + notifier =TAILQ_PREV (notifier, lcore_notifiers_head, + next); + } + ret =-1 ; +break ; + } +rte_spinlock_unlock (&lcore_notifiers_lock); + +return ret; +} + +void +eal_lcore_external_notify_removed (unsigned int lcore_id) +{ +struct lcore_notifier *notifier; + +RTE_LOG (DEBUG ,EAL ,"Released lcore %u.\n" , lcore_id); +rte_spinlock_lock (&lcore_notifiers_lock); +TAILQ_FOREACH_REVERSE (notifier, &lcore_notifiers, lcore_notifiers_head, + next) { + notifier->cb (lcore_id,RTE_LCORE_EVENT_RELEASE_EXTERNAL , + notifier->arg); + } +rte_spinlock_unlock (&lcore_notifiers_lock); +}lib/librte_eal/common/eal_common_thread.c +10
-1@@ -285,6 +285,12 @@ rte_thread_register(void)rte_thread_init (lcore_id, &cpuset); +if (lcore_id !=LCORE_ID_ANY && +eal_lcore_external_notify_allocated (lcore_id) <0 ) { +eal_lcore_external_release (lcore_id); +RTE_PER_LCORE (_lcore_id) = lcore_id =LCORE_ID_ANY ; + } +RTE_LOG (DEBUG ,EAL ,"Registered thread as lcore %u.\n" , lcore_id);RTE_PER_LCORE (thread_registered) = true; }@@ -298,8 +304,11 @@ rte_thread_unregister(void)return ; lcore_id =RTE_PER_LCORE (_lcore_id); -if (lcore_id !=LCORE_ID_ANY ) +if (lcore_id !=LCORE_ID_ANY ) { +eal_lcore_external_notify_removed (lcore_id);eal_lcore_external_release (lcore_id); +RTE_PER_LCORE (_lcore_id) =LCORE_ID_ANY ; + }rte_thread_uninit ();lib/librte_eal/common/eal_private.h +26
-0@@ -283,6 +283,21 @@ uint64_t get_tsc_freq_arch(void);*/ unsigned int eal_lcore_external_reserve (void ); +/** +* Evaluate all lcore notifiers with a RTE_LCORE_EVENT_NEW_EXTERNAL event for +* the passed lcore. +* If an error is returned by one of them, then this change is rolled back: +* all previous lcore notifiers that had acked the RTE_LCORE_EVENT_NEW_EXTERNAL +* event receive a RTE_LCORE_EVENT_RELEASE_EXTERNAL event for the passed lcore. +* +* @param lcore_id +* The lcore to consider. +* @return +* - 0 if all notifiers agreed on the new lcore +* - -1 if one of them refused +*/ +int eal_lcore_external_notify_allocated (unsigned int lcore_id); +/** * Release an external lcore. * @@ -291,6 +306,17 @@ unsigned int eal_lcore_external_reserve(void);*/ void eal_lcore_external_release (unsigned int lcore_id); +/** +* Evaluate all lcore notifiers with a RTE_LCORE_EVENT_RELEASE_EXTERNAL event +* for the passed lcore. +* This function must be called with a lcore that successfully passed +* eal_lcore_external_notify_allocated(). +* +* @param lcore_id +* The lcore with role ROLE_EXTERNAL to release. +*/ +void eal_lcore_external_notify_removed (unsigned int lcore_id); +/** * Prepare physical memory mapping * i.e. hugepages on Linux and lib/librte_eal/include/rte_lcore.h +49
-0@@ -238,6 +238,55 @@ __rte_experimentalvoid rte_lcore_dump (FILE *f); +enum rte_lcore_event_type { +RTE_LCORE_EVENT_NEW_EXTERNAL , +RTE_LCORE_EVENT_RELEASE_EXTERNAL , +}; + +/** +* Callback prototype for getting lcore events. +* +* @param lcore_id +* The lcore to consider for this event. +* @param event +* The type of event on the lcore. +* @param arg +* An opaque pointer passed at notifier registration. +* @return +* - -1 when refusing this event, +* - 0 otherwise. +*/ +typedef int (*rte_lcore_notifier_cb )(unsigned int lcore_id, +enum rte_lcore_event_type event,void *arg); + +/** +* Register a lcore notifier. +* +* @param cb +* The callback invoked for each lcore event with the arg argument. +* See rte_lcore_notifier_cb description. +* @param arg +* An optional argument that gets passed to the callback when it gets +* invoked. +* @return +* On success, returns an opaque pointer for the created notifier. +* NULL on failure. +*/ +__rte_experimental +void * +rte_lcore_notifier_register (rte_lcore_notifier_cb cb,void *arg); + +/** +* Unregister a lcore notifier. +* +* @param handle +* The handle pointer returned by a former successful call to +* rte_lcore_notifier_register. +*/ +__rte_experimental +void +rte_lcore_notifier_unregister (void *handle); +/** * Set core affinity of the current thread. * Support both EAL and non-EAL thread and update TLS. lib/librte_eal/rte_eal_version.map +2
-0@@ -396,6 +396,8 @@ EXPERIMENTAL { # added in 20.08 rte_lcore_dump; + rte_lcore_notifier_register; + rte_lcore_notifier_unregister; rte_thread_register; rte_thread_unregister; };
Re: [dpdk-dev] [PATCH 7/7] eal: add lcore hotplug notifications
Quoted 6 lines · Ray
From ABI PoV, you are 100%.
Is the agreed term 'callback'?, not 'notifier' for example
rte_dev_event_callback_register,rte_mem_event_callback_registerI did wonder however, if all these cb's would be better handled through a EventDev event notification style approach.
I am reconsidering the term.
callback seems better yes and, actually, there is no need for a lcore event framework.
Cooking a v2 for this week.
Signature · 1 line
David Marchand
Quoted 10 lines · David Marchand
OVS and some other applications have been hacking into DPDK internals to fake EAL threads and avoid performance penalty of only having non-EAL threads.
This series proposes to add a new type of lcores and maps those external threads to such lcores.
Those threads won't run the DPDK eal mainloop and as a consequence part of the EAL threads API cannot work.
Quoted 8 lines
Having new lcores appearing during the process lifetime is not expected by some DPDK components. This is addressed by notifying of such lcore hotplug.
This patchset has still some more work (like refusing new lcore type in incompatible EAL threads API, updating the documentation and adding unit tests) but I am sending it anyway as I would like to get this in for 20.08.
Cool feature.
Is mempool's lcore local cache working for external cores with this scheme?
Quoted 5 lines
For the interested parties, I have a patch [1] against dpdk-latest OVS branch that makes use of this series.
1: https://github.com/david-marchand/ovs/commit/dpdk-latest-external-lcores
Usage is clear from the example code,
Looking forward to having documentation and UT for the new API in the next version.
Quoted 34 lines
--
David MarchandDavid Marchand (7):
eal: relocate per thread symbols to common
eal: fix multiple definition of per lcore thread id
eal: introduce thread init helper
eal: introduce thread uninit helper
eal: register non-EAL threads as lcore
eal: dump lcores
eal: add lcore hotplug notificationsdoc/guides/howto/debug_troubleshoot.rst | 5 +- lib/librte_eal/common/eal_common_lcore.c | 167 +++++++++++++++++++++- lib/librte_eal/common/eal_common_thread.c | 143 ++++++++++++++---- lib/librte_eal/common/eal_common_trace.c | 49 ++++++- lib/librte_eal/common/eal_private.h | 43 ++++++ lib/librte_eal/common/eal_thread.h | 26 +++- lib/librte_eal/common/eal_trace.h | 1 + lib/librte_eal/freebsd/eal.c | 16 ++- lib/librte_eal/freebsd/eal_thread.c | 38 +---- lib/librte_eal/include/rte_eal.h | 12 +- lib/librte_eal/include/rte_lcore.h | 112 +++++++++++++-- lib/librte_eal/linux/eal.c | 17 ++- lib/librte_eal/linux/eal_thread.c | 38 +---- lib/librte_eal/rte_eal_version.map | 14 ++ lib/librte_eal/windows/eal.c | 3 +- lib/librte_eal/windows/eal_thread.c | 14 +- 16 files changed, 536 insertions(+), 162 deletions(-)--
2.23.0
Quoted 16 lines · Jerin Jacob
Quoted 14 lines · David Marchand
OVS and some other applications have been hacking into DPDK internals to fake EAL threads and avoid performance penalty of only having non-EAL threads.
This series proposes to add a new type of lcores and maps those external threads to such lcores.
Those threads won't run the DPDK eal mainloop and as a consequence part of the EAL threads API cannot work.Having new lcores appearing during the process lifetime is not expected by some DPDK components. This is addressed by notifying of such lcore hotplug.
Quoted 7 lines
Quoted 4 lines
This patchset has still some more work (like refusing new lcore type in incompatible EAL threads API, updating the documentation and adding unit tests) but I am sending it anyway as I would like to get this in for 20.08.
Cool feature.
+1 for this, this is something that I think has been needed for a long time. Thanks!
Quoted 4 lines
Is mempool's lcore local cache working for external cores with this scheme?
Quoted 1 line
Quoted 9 lines
Quoted 4 lines
For the interested parties, I have a patch [1] against dpdk-latest OVS branch that makes use of this series.
1: https://github.com/david-marchand/ovs/commit/dpdk-latest-external-lcores
Usage is clear from the example code,
Looking forward to having documentation and UT for the new API in the next version.
Yes, I think we need a doc update explaining usage. The EAL chapter of the programmers guide needs an update [1], and I think a description in the howto would be good also [2].
[1] https://doc.dpdk.org/guides-20.05/prog_guide/env_abstraction_layer.html
[2] https://doc.dpdk.org/guides-20.05/howto/index.html
Regards,
/Bruce
Quoted 17 lines · Jerin Jacob
Quoted 14 lines · David Marchand
OVS and some other applications have been hacking into DPDK internals to fake EAL threads and avoid performance penalty of only having non-EAL threads.
This series proposes to add a new type of lcores and maps those external threads to such lcores.
Those threads won't run the DPDK eal mainloop and as a consequence part of the EAL threads API cannot work.Having new lcores appearing during the process lifetime is not expected by some DPDK components. This is addressed by notifying of such lcore hotplug.
Quoted 8 lines
Quoted 4 lines
This patchset has still some more work (like refusing new lcore type in incompatible EAL threads API, updating the documentation and adding unit tests) but I am sending it anyway as I would like to get this in for 20.08.
Cool feature.
Is mempool's lcore local cache working for external cores with this scheme?
Yes, as it is stateless, all we need is a unique lcore_id in [0, RTE_MAX_LCORE-1] range.
We could imagine flushing such caches on unregistering.
And we can fix other mempool drivers like the bucket driver.
Signature · 1 line
David Marchand
Quoted 24 lines · David Marchand
Quoted 22 lines · Jerin Jacob
Quoted 18 lines · David Marchand
OVS and some other applications have been hacking into DPDK internals to fake EAL threads and avoid performance penalty of only having non-EAL threads.
This series proposes to add a new type of lcores and maps those external threads to such lcores.
Those threads won't run the DPDK eal mainloop and as a consequence part of the EAL threads API cannot work.Having new lcores appearing during the process lifetime is not expected by some DPDK components. This is addressed by notifying of such lcore hotplug.
This patchset has still some more work (like refusing new lcore type in incompatible EAL threads API, updating the documentation and adding unit tests) but I am sending it anyway as I would like to get this in for 20.08.
Quoted 6 lines
Quoted 3 lines
Cool feature.
Is mempool's lcore local cache working for external cores with this scheme?
Yes, as it is stateless, all we need is a unique
lcore_idin [0, RTE_MAX_LCORE-1] range.
Was it the case when lcore registered and then mempool created? What about other case, mempool created and then lcore registered?
Quoted 7 lines
We could imagine flushing such caches on unregistering.
And we can fix other mempool drivers like the bucket driver.
--
David Marchand
Quoted 29 lines · Jerin Jacob
Quoted 26 lines · David Marchand
Quoted 24 lines · Jerin Jacob
Quoted 10 lines · David Marchand
OVS and some other applications have been hacking into DPDK internals to fake EAL threads and avoid performance penalty of only having non-EAL threads.
This series proposes to add a new type of lcores and maps those external threads to such lcores.
Those threads won't run the DPDK eal mainloop and as a consequence part of the EAL threads API cannot work.Quoted 8 lines
Having new lcores appearing during the process lifetime is not expected by some DPDK components. This is addressed by notifying of such lcore hotplug.
This patchset has still some more work (like refusing new lcore type in incompatible EAL threads API, updating the documentation and adding unit tests) but I am sending it anyway as I would like to get this in for 20.08.
Cool feature.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Is mempool's lcore local cache working for external cores with this scheme?
Yes, as it is stateless, all we need is a unique
lcore_idin [0, RTE_MAX_LCORE-1] range.Was it the case when lcore registered and then mempool created? What about other case, mempool created and then lcore registered?
- All caches are initialised for all possible lcores for each mempool.
https://git.dpdk.org/dpdk/tree/lib/librte_mempool/rte_mempool.c#n965
So any order is fine wrt the local mempool cache.
- If the mempool drivers want to initialise per lcore data on demand [1], the driver have to register a lcore notifier per mempool.
1: https://git.dpdk.org/dpdk/tree/drivers/mempool/bucket/rte_mempool_bucket.c#n437
But this current series implementation does not handle registering in any order. I will fix this in v2 (and rework the locking which is quite ugly) hopefully this week.
Signature · 1 line
David Marchand
v2 cover Register non-EAL threads as lcore
In reply to David MarchandOVS and some other applications have been hacking into DPDK internals to fake EAL threads and avoid performance penalty of only having non-EAL threads.
This series proposes to add a new type of lcores and maps those threads to such lcores.
non-EAL threads won't run the DPDK eal mainloop.
As a consequence, part of the EAL threads API cannot work.
Having new lcores appearing during the process lifetime is not expected by some DPDK components. This is addressed by introducing init/uninit callacks invoked when hotplugging of such lcore.
There is still some work:
- refuse new lcore role in incompatible EAL threads API (or document it only as those API were already incompatible?),
- finish unit tests in patch 7,
- think about deprecation notices for existing RTE_FOREACH_LCORE macros and consorts, it is probably worth discussing on how to iterate over lcores,
For the interested parties, I have a patch [1] against dpdk-latest OVS branch that makes use of this series.
1: https://github.com/david-marchand/ovs/commit/dpdk-latest-external-lcores
Changes since v1:
- rebased on master (conflicts on merged Windows series),
- separated lcore role code cleanup in a patch,
- tried to use a single naming, so kept non-EAL threads as the main notion. non-EAL threads are then distinguished between registered and unregistered non-EAL threads,
- added unit tests (still missing some coverage, marked with a FIXME),
- reworked callbacks call under a common rwlock lock which protects lcores allocations and callbacks registration,
- introduced lcore iterators and converted the bucket mempool driver,
Signature · 43 lines
David Marchand David Marchand (9): eal: relocate per thread symbols to common eal: fix multiple definition of per lcore thread id eal: introduce thread init helper eal: introduce thread uninit helper eal: move lcore role code eal: register non-EAL threads as lcores eal: add lcore init callbacks eal: add lcore iterators mempool/bucket: handle non-EAL lcores MAINTAINERS | 1 + app/test/Makefile | 1 + app/test/autotest_data.py | 6 + app/test/meson.build | 2 + app/test/test_lcores.c | 234 +++++++++++++++++ doc/guides/howto/debug_troubleshoot.rst | 5 +- .../prog_guide/env_abstraction_layer.rst | 22 +- doc/guides/prog_guide/mempool_lib.rst | 2 +- drivers/mempool/bucket/rte_mempool_bucket.c | 131 ++++++---- lib/librte_eal/common/eal_common_lcore.c | 241 +++++++++++++++++- lib/librte_eal/common/eal_common_thread.c | 126 ++++++--- lib/librte_eal/common/eal_common_trace.c | 49 +++- lib/librte_eal/common/eal_private.h | 19 ++ lib/librte_eal/common/eal_thread.h | 26 +- lib/librte_eal/common/eal_trace.h | 1 + lib/librte_eal/freebsd/eal.c | 16 +- lib/librte_eal/freebsd/eal_thread.c | 38 +-- lib/librte_eal/include/rte_eal.h | 12 +- lib/librte_eal/include/rte_lcore.h | 167 ++++++++++-- lib/librte_eal/linux/eal.c | 17 +- lib/librte_eal/linux/eal_thread.c | 38 +-- lib/librte_eal/rte_eal_version.map | 15 ++ lib/librte_eal/windows/eal.c | 3 +- lib/librte_eal/windows/eal_thread.c | 14 +- lib/librte_mempool/rte_mempool.h | 11 +- 25 files changed, 960 insertions(+), 237 deletions(-) create mode 100644 app/test/test_lcores.c -- 2.23.0
PATCH v2 1/9 eal: relocate per thread symbols to common
We have per lcore thread symbols scattered in OS implementations but common code relies on them.
Move all of them in common.
RTE_PER_LCORE(_socket_id) and RTE_PER_LCORE(_cpuset) have public accessors and are not exported through the library map, they can be made static.
--- lib/librte_eal/common/eal_common_thread.c | 5 ++++- lib/librte_eal/freebsd/eal_thread.c | 4 ---- lib/librte_eal/include/rte_lcore.h | 1 - lib/librte_eal/linux/eal_thread.c | 4 ---- lib/librte_eal/windows/eal_thread.c | 4 ---- 5 files changed, 4 insertions(+), 14 deletions(-)
lib/librte_eal/common/eal_common_thread.c +4 -1
@@ -21,7 +21,10 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DECLARE_PER_LCORE (unsigned , _socket_id); +RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = + (unsigned int )SOCKET_ID_ANY ; +static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);unsigned rte_socket_id (void ) {
lib/librte_eal/freebsd/eal_thread.c +0 -4
@@ -25,10 +25,6 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; -RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
lib/librte_eal/include/rte_lcore.h +0 -1
@@ -23,7 +23,6 @@ extern "C" {#define LCORE_ID_ANY UINT32_MAX/**< Any lcore. */ RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ -RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */ /** * Get a lcore's role.
lib/librte_eal/linux/eal_thread.c +0 -4
@@ -25,10 +25,6 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; -RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
lib/librte_eal/windows/eal_thread.c +0 -4
@@ -16,10 +16,6 @@#include "eal_private.h" #include "eal_windows.h" -RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; -RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int)SOCKET_ID_ANY; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
Signature · 1 line
2.23.0
PATCH v2 2/9 eal: fix multiple definition of per lcore thread id
In reply to David MarchandBecause of the inline accessor + static declaration in rte_gettid(), we end up with multiple symbols for RTE_PER_LCORE(_thread_id). Each compilation unit will pay a cost when accessing this information for the first time.
$ nm build/app/dpdk-testpmd | grep per_lcore__thread_id 0000000000000054 d per_lcore__thread_id.5037 0000000000000040 d per_lcore__thread_id.5103 0000000000000048 d per_lcore__thread_id.5259 000000000000004c d per_lcore__thread_id.5259 0000000000000044 d per_lcore__thread_id.5933 0000000000000058 d per_lcore__thread_id.6261 0000000000000050 d per_lcore__thread_id.7378 000000000000005c d per_lcore__thread_id.7496 000000000000000c d per_lcore__thread_id.8016 0000000000000010 d per_lcore__thread_id.8431
Make it global as part of the DPDK_21 stable ABI.
--- lib/librte_eal/common/eal_common_thread.c | 1 + lib/librte_eal/include/rte_eal.h | 3 ++- lib/librte_eal/rte_eal_version.map | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_thread.c +1 -0
@@ -22,6 +22,7 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +RTE_DEFINE_PER_LCORE (int, _thread_id) =-1 ; static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int )SOCKET_ID_ANY ; static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
lib/librte_eal/include/rte_eal.h +2 -1
@@ -447,6 +447,8 @@ enum rte_intr_mode rte_eal_vfio_intr_mode(void);*/ int rte_sys_gettid (void ); +RTE_DECLARE_PER_LCORE (int, _thread_id); +/** * Get system unique thread id. *
@@ -456,7 +458,6 @@ int rte_sys_gettid(void);*/ static inline int rte_gettid (void ) { - static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;if (RTE_PER_LCORE (_thread_id) ==-1 )RTE_PER_LCORE (_thread_id) =rte_sys_gettid ();return RTE_PER_LCORE (_thread_id);
lib/librte_eal/rte_eal_version.map +7 -0
@@ -221,6 +221,13 @@ DPDK_20.0 { local: *; }; +DPDK_21 { + global: + + per_lcore__thread_id; + +} DPDK_20.0; + EXPERIMENTAL { global:
Signature · 1 line
2.23.0
PATCH v2 3/9 eal: introduce thread init helper
In reply to David MarchandIntroduce a helper responsible for initialising the per thread context. We can then have a unified context for EAL and non-EAL threads and remove copy/paste'd OS-specific helpers.
Per EAL thread CPU affinity setting is separated from the thread init. It is to accommodate with Windows EAL where CPU affinity is not set at the moment.
Besides, having affinity set by the master lcore in FreeBSD and Linux will make it possible to detect errors rather than panic in the child thread. But the cleanup when such an event happens is left for later.
---
Changes since v1:
- rebased on master, removed Windows workarounds wrt gettid and traces support,
--- lib/librte_eal/common/eal_common_thread.c | 51 +++++++++++++---------- lib/librte_eal/common/eal_thread.h | 8 ++-- lib/librte_eal/freebsd/eal.c | 14 ++++++- lib/librte_eal/freebsd/eal_thread.c | 32 +------------- lib/librte_eal/linux/eal.c | 15 ++++++- lib/librte_eal/linux/eal_thread.c | 32 +------------- lib/librte_eal/windows/eal.c | 3 +- lib/librte_eal/windows/eal_thread.c | 10 +---- 8 files changed, 66 insertions(+), 99 deletions(-)
lib/librte_eal/common/eal_common_thread.c +30 -21
@@ -71,20 +71,10 @@ eal_cpuset_socket_id(rte_cpuset_t *cpusetp)return socket_id; } -int -rte_thread_set_affinity (rte_cpuset_t *cpusetp) +static void +thread_update_affinity (rte_cpuset_t *cpusetp) { -int s; -unsigned lcore_id; -pthread_t tid; - - tid =pthread_self (); - - s =pthread_setaffinity_np (tid,sizeof (rte_cpuset_t), cpusetp); -if (s !=0 ) { -RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); -return -1 ; - } +unsigned int lcore_id =rte_lcore_id ();/* store socket_id in TLS for quick access */ RTE_PER_LCORE(_socket_id) =
@@ -94,14 +84,24 @@ rte_thread_set_affinity(rte_cpuset_t *cpusetp)memmove (&RTE_PER_LCORE (_cpuset), cpusetp,sizeof (rte_cpuset_t)); - lcore_id =rte_lcore_id ();if (lcore_id != (unsigned )LCORE_ID_ANY ) {/* EAL thread will update lcore_config */ lcore_config[lcore_id].socket_id =RTE_PER_LCORE (_socket_id);memmove (&lcore_config[lcore_id].cpuset, cpusetp,sizeof (rte_cpuset_t)); } +} +int +rte_thread_set_affinity (rte_cpuset_t *cpusetp) +{ +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + cpusetp) !=0 ) { +RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); +return -1 ; + } + +thread_update_affinity (cpusetp);return 0 ; }
@@ -147,6 +147,19 @@ eal_thread_dump_affinity(char *str, unsigned size)return ret; } +void +rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) +{ +/* set the lcore ID in per-lcore memory area */ +RTE_PER_LCORE (_lcore_id) = lcore_id; + +/* acquire system unique id */ +rte_gettid (); + +thread_update_affinity (cpuset); + +__rte_trace_mem_per_thread_alloc (); +}struct rte_thread_ctrl_params {void *(*start_routine)(void *);
@@ -154,16 +167,14 @@ struct rte_thread_ctrl_params {pthread_barrier_t configured; }; -static void *rte_thread_init (void *arg) +static void *ctrl_thread_init (void *arg) {int ret; -rte_cpuset_t *cpuset = &internal_config.ctrl_cpuset;struct rte_thread_ctrl_params *params = arg;void *(*start_routine)(void *) = params->start_routine;void *routine_arg = params->arg; -/* Store cpuset in TLS for quick access */ -memmove (&RTE_PER_LCORE (_cpuset), cpuset,sizeof (rte_cpuset_t)); +rte_thread_init (rte_lcore_id (), &internal_config.ctrl_cpuset); ret =pthread_barrier_wait (¶ms->configured);if (ret ==PTHREAD_BARRIER_SERIAL_THREAD ) {
@@ -171,8 +182,6 @@ static void *rte_thread_init(void *arg)free (params); } -__rte_trace_mem_per_thread_alloc (); -return start_routine (routine_arg); }
@@ -194,7 +203,7 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_barrier_init (¶ms->configured,NULL ,2 ); - ret =pthread_create (thread, attr, rte_thread_init, (void *)params); + ret =pthread_create (thread, attr, ctrl_thread_init, (void *)params);if (ret !=0 ) {free (params);return -ret;
lib/librte_eal/common/eal_thread.h +5 -3
@@ -16,12 +16,14 @@ __rte_noreturn void *eal_thread_loop(void *arg);/** -* Init per-lcore info for master thread +* Init per-lcore info in current thread. * * @param lcore_id -* identifier of master lcore +* identifier of lcore. +* @param cpuset +* CPU affinity for this thread. */ -void eal_thread_init_master (unsigned lcore_id); +void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset);/** * Get the NUMA socket id from cpu id.
lib/librte_eal/freebsd/eal.c +13 -1
@@ -877,7 +877,14 @@ rte_eal_init(int argc, char **argv)eal_check_mem_on_local_socket (); -eal_thread_init_master (rte_config.master_lcore); +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + &lcore_config[rte_config.master_lcore].cpuset) !=0 ) { +rte_eal_init_alert ("Cannot set affinity" ); + rte_errno =EINVAL ; +return -1 ; + } +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset));
@@ -908,6 +915,11 @@ rte_eal_init(int argc, char **argv)snprintf (thread_name,sizeof (thread_name),"lcore-slave-%d" , i);rte_thread_setname (lcore_config[i].thread_id, thread_name); + + ret =pthread_setaffinity_np (lcore_config[i].thread_id, +sizeof (rte_cpuset_t), &lcore_config[i].cpuset); +if (ret !=0 ) +rte_panic ("Cannot set affinity\n" ); }/*
lib/librte_eal/freebsd/eal_thread.c +1 -31
@@ -66,29 +66,6 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)return rc; } -/* set affinity for current thread */ -static int -eal_thread_set_affinity (void ) -{ -unsigned lcore_id =rte_lcore_id (); - -/* acquire system unique id */ -rte_gettid (); - -/* update EAL thread core affinity */ -return rte_thread_set_affinity (&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master (unsigned lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); -} -/* main loop of threads */ __rte_noreturn void * eal_thread_loop(__rte_unused void *arg)
@@ -113,19 +90,12 @@ eal_thread_loop(__rte_unused void *arg) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , lcore_id, thread_id, cpuset, ret ==0 ?"" :"..." ); -__rte_trace_mem_per_thread_alloc ();rte_eal_trace_thread_lcore_ready (lcore_id, cpuset);/* read on our pipe to get commands */
lib/librte_eal/linux/eal.c +13 -2
@@ -1205,10 +1205,16 @@ rte_eal_init(int argc, char **argv)eal_check_mem_on_local_socket (); -eal_thread_init_master (rte_config.master_lcore); +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + &lcore_config[rte_config.master_lcore].cpuset) !=0 ) { +rte_eal_init_alert ("Cannot set affinity" ); + rte_errno =EINVAL ; +return -1 ; + } +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , rte_config.master_lcore, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
@@ -1240,6 +1246,11 @@ rte_eal_init(int argc, char **argv)if (ret !=0 )RTE_LOG (DEBUG ,EAL ,"Cannot set name for lcore thread\n" ); + + ret =pthread_setaffinity_np (lcore_config[i].thread_id, +sizeof (rte_cpuset_t), &lcore_config[i].cpuset); +if (ret !=0 ) +rte_panic ("Cannot set affinity\n" ); }/*
lib/librte_eal/linux/eal_thread.c +1 -31
@@ -66,29 +66,6 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)return rc; } -/* set affinity for current EAL thread */ -static int -eal_thread_set_affinity (void ) -{ -unsigned lcore_id =rte_lcore_id (); - -/* acquire system unique id */ -rte_gettid (); - -/* update EAL thread core affinity */ -return rte_thread_set_affinity (&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master (unsigned lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); -} -/* main loop of threads */ __rte_noreturn void * eal_thread_loop(__rte_unused void *arg)
@@ -113,19 +90,12 @@ eal_thread_loop(__rte_unused void *arg) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." ); -__rte_trace_mem_per_thread_alloc ();rte_eal_trace_thread_lcore_ready (lcore_id, cpuset);/* read on our pipe to get commands */
lib/librte_eal/windows/eal.c +2 -1
@@ -354,7 +354,8 @@ rte_eal_init(int argc, char **argv)return -1 ; } -eal_thread_init_master (rte_config.master_lcore); +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset);RTE_LCORE_FOREACH_SLAVE (i) {
lib/librte_eal/windows/eal_thread.c +1 -9
@@ -53,13 +53,6 @@ rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int slave_id)return 0 ; } -void -eal_thread_init_master (unsigned int lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; -} -/* main loop of threads */ void * eal_thread_loop(void *arg __rte_unused)
@@ -84,8 +77,7 @@ eal_thread_loop(void *arg __rte_unused) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset);RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset);
Signature · 1 line
2.23.0
PATCH v2 4/9 eal: introduce thread uninit helper
In reply to David MarchandThis is a preparation step for dynamically unregistering threads.
Since we explicitly allocate a per thread trace buffer in rte_thread_init, add an internal helper to free this buffer.
---
Note: I preferred renaming the current internal function to free all threads trace buffers (new name trace_mem_free()) and reuse the previous name (trace_mem_per_thread_free()) when freeing this buffer for a given thread.
Changes since v1:
- rebased on master, removed Windows workaround wrt traces support,
--- lib/librte_eal/common/eal_common_thread.c | 9 +++++ lib/librte_eal/common/eal_common_trace.c | 49 +++++++++++++++++++---- lib/librte_eal/common/eal_thread.h | 5 +++ lib/librte_eal/common/eal_trace.h | 1 + 4 files changed, 57 insertions(+), 7 deletions(-)
lib/librte_eal/common/eal_common_thread.c +9 -0
@@ -20,6 +20,7 @@#include "eal_internal_cfg.h" #include "eal_private.h" #include "eal_thread.h" +#include "eal_trace.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;RTE_DEFINE_PER_LCORE (int, _thread_id) =-1 ;
@@ -161,6 +162,14 @@ rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset)__rte_trace_mem_per_thread_alloc (); } +void +rte_thread_uninit (void ) +{ +trace_mem_per_thread_free (); + +RTE_PER_LCORE (_lcore_id) =LCORE_ID_ANY ; +} +struct rte_thread_ctrl_params {void *(*start_routine)(void *);void *arg;
lib/librte_eal/common/eal_common_trace.c +42 -7
73 lines not on this page · raw message
lib/librte_eal/common/eal_thread.h +5 -0
@@ -25,6 +25,11 @@ __rte_noreturn void *eal_thread_loop(void *arg);*/ void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset); +/** +* Uninitialize per-lcore info for current thread. +*/ +void rte_thread_uninit (void ); +/** * Get the NUMA socket id from cpu id. * This function is private to EAL.
lib/librte_eal/common/eal_trace.h +1 -0
@@ -106,6 +106,7 @@ int trace_metadata_create(void);void trace_metadata_destroy (void );int trace_mkdir (void );int trace_epoch_time_save (void ); +void trace_mem_free (void );void trace_mem_per_thread_free (void );/* EAL interface */
Signature · 1 line
2.23.0
PATCH v2 5/9 eal: move lcore role code
In reply to David MarchandFor consistency sake, move all lcore role code in the dedicated compilation unit / header.
--- lib/librte_eal/common/eal_common_lcore.c | 11 +++++++ lib/librte_eal/common/eal_common_thread.c | 11 ------- lib/librte_eal/include/rte_eal.h | 9 ------ lib/librte_eal/include/rte_lcore.h | 37 ++++++++++++++--------- 4 files changed, 34 insertions(+), 34 deletions(-)
lib/librte_eal/common/eal_common_lcore.c +11 -0
@@ -63,6 +63,17 @@ rte_eal_lcore_role(unsigned int lcore_id)return cfg->lcore_role[lcore_id]; } +int +rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role) +{ +struct rte_config *cfg =rte_eal_get_configuration (); + +if (lcore_id >=RTE_MAX_LCORE ) +return -EINVAL ; + +return cfg->lcore_role[lcore_id] == role; +} +int rte_lcore_is_enabled (unsigned int lcore_id) {struct rte_config *cfg =rte_eal_get_configuration ();
lib/librte_eal/common/eal_common_thread.c +0 -11
@@ -33,17 +33,6 @@ unsigned rte_socket_id(void)return RTE_PER_LCORE (_socket_id); } -int -rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role) -{ -struct rte_config *cfg =rte_eal_get_configuration (); - -if (lcore_id >=RTE_MAX_LCORE ) -return -EINVAL ; - -return cfg->lcore_role[lcore_id] == role; -} -static int eal_cpuset_socket_id (rte_cpuset_t *cpusetp) {
lib/librte_eal/include/rte_eal.h +0 -9
@@ -31,15 +31,6 @@ extern "C" {/* Maximum thread_name length. */ #define RTE_MAX_THREAD_NAME_LEN 16 -/** -* The lcore role (used in RTE or not). -*/ -enum rte_lcore_role_t { -ROLE_RTE , -ROLE_OFF , -ROLE_SERVICE , -}; -/** * The type of process in a linux, multi-process setup */
lib/librte_eal/include/rte_lcore.h +23 -14
@@ -24,6 +24,15 @@ extern "C" {RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ +/** +* The lcore role (used in RTE or not). +*/ +enum rte_lcore_role_t { +ROLE_RTE , +ROLE_OFF , +ROLE_SERVICE , +}; +/** * Get a lcore's role. *
@@ -34,6 +43,20 @@ RTE_DECLARE_PER_LCORE(unsigned, _lcore_id); /**< Per thread "lcore id". */*/ enum rte_lcore_role_t rte_eal_lcore_role (unsigned int lcore_id); +/** +* Test if the core supplied has a specific role +* +* @param lcore_id +* The identifier of the lcore, which MUST be between 0 and +* RTE_MAX_LCORE-1. +* @param role +* The role to be checked against. +* @return +* Boolean value: positive if test is true; otherwise returns 0. +*/ +int +rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role); +/** * Return the Application thread ID of the execution unit. *
@@ -283,20 +306,6 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); -/** -* Test if the core supplied has a specific role -* -* @param lcore_id -* The identifier of the lcore, which MUST be between 0 and -* RTE_MAX_LCORE-1. -* @param role -* The role to be checked against. -* @return -* Boolean value: positive if test is true; otherwise returns 0. -*/ -int -rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role); - #ifdef __cplusplus }#endif
Signature · 1 line
2.23.0
PATCH v2 6/9 eal: register non-EAL threads as lcores
In reply to David MarchandDPDK allows calling some part of its API from a non-EAL thread but this has some limitations.
OVS (and other applications) has its own thread management but still want to avoid such limitations by hacking RTE_PER_LCORE(_lcore_id) and faking EAL threads potentially unknown of some DPDK component.
Introduce a new API to register non-EAL thread and associate them to a free lcore with a new NON_EAL role.
This role denotes lcores that do not run DPDK mainloop and as such prevents use of rte_eal_wait_lcore() and consorts.
---
Changes since v1:
- moved cleanup on lcore role code in patch 5,
- added unit test,
- updated documentation,
- changed naming from "external thread" to "registered non-EAL thread"
--- MAINTAINERS | 1 + app/test/Makefile | 1 + app/test/autotest_data.py | 6 + app/test/meson.build | 2 + app/test/test_lcores.c | 139 ++++++++++++++++++ doc/guides/howto/debug_troubleshoot.rst | 5 +- .../prog_guide/env_abstraction_layer.rst | 22 +-- doc/guides/prog_guide/mempool_lib.rst | 2 +- lib/librte_eal/common/eal_common_lcore.c | 44 +++++- lib/librte_eal/common/eal_common_thread.c | 33 +++++ lib/librte_eal/common/eal_private.h | 18 +++ lib/librte_eal/include/rte_lcore.h | 18 ++- lib/librte_eal/rte_eal_version.map | 4 + lib/librte_mempool/rte_mempool.h | 11 +- 14 files changed, 284 insertions(+), 22 deletions(-) create mode 100644 app/test/test_lcores.c
MAINTAINERS +1 -0
@@ -183,6 +183,7 @@ F: app/test/test_debug.c F: app/test/test_eal* F: app/test/test_errno.c F: app/test/test_interrupts.c +F: app/test/test_lcores.c F: app/test/test_logs.c F: app/test/test_memcpy* F: app/test/test_per_lcore.c
app/test/Makefile +1 -0
@@ -97,6 +97,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_FLOW_CLASSIFY) += test_flow_classify.c endif SRCS-y += test_rwlock.c +SRCS-y += test_lcores.c SRCS-$(CONFIG_RTE_LIBRTE_STACK) += test_stack.c SRCS-$(CONFIG_RTE_LIBRTE_STACK) += test_stack_perf.c
app/test/autotest_data.py +6 -0
@@ -62,6 +62,12 @@ "Func": rwlock_autotest, "Report": None, }, + { + "Name": "Lcores autotest", + "Command": "lcores_autotest", + "Func": default_autotest, + "Report": None, + }, { "Name": "Logs autotest", "Command": "logs_autotest",
app/test/meson.build +2 -0
@@ -67,6 +67,7 @@ test_sources = files('commands.c', 'test_ipsec_perf.c', 'test_kni.c', 'test_kvargs.c', + 'test_lcores.c', 'test_logs.c', 'test_lpm.c', 'test_lpm6.c',
@@ -206,6 +207,7 @@ fast_tests = [ ['hash_autotest', true], ['interrupt_autotest', true], ['ipfrag_autotest', false], + ['lcores_autotest', true], ['logs_autotest', true], ['lpm_autotest', true], ['lpm6_autotest', true],
app/test/test_lcores.c new file +139 -0
139 lines not on this page · raw message
doc/guides/howto/debug_troubleshoot.rst +3 -2
@@ -307,8 +307,9 @@ Custom worker function :numref:`dtg_distributor_worker`. #. Configuration issue isolation - * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF and - SERVICE. Check performance functions are mapped to run on the cores. + * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF, + SERVICE and NON_EAL. Check performance functions are mapped to run on the + cores. * For high-performance execution logic ensure running it on correct NUMA and non-master core.
doc/guides/prog_guide/env_abstraction_layer.rst +13 -9
@@ -564,9 +564,13 @@ It's also compatible with the pattern of corelist('-l') option. non-EAL pthread support ~~~~~~~~~~~~~~~~~~~~~~~ -It is possible to use the DPDK execution context with any user pthread (aka. Non-EAL pthreads). -In a non-EAL pthread, the *_lcore_id* is always LCORE_ID_ANY which identifies that it is not an EAL thread with a valid, unique, *_lcore_id*. -Some libraries will use an alternative unique ID (e.g. TID), some will not be impacted at all, and some will work but with limitations (e.g. timer and mempool libraries). +It is possible to use the DPDK execution context with any user pthread (aka. non-EAL pthreads). +There are two kinds of non-EAL pthreads: + +- a registered non-EAL pthread with a valid *_lcore_id* that was successfully assigned by calling ``rte_thread_register()``, +- a non registered non-EAL pthread with a LCORE_ID_ANY, + +For non registered non-EAL pthread (with a LCORE_ID_ANY *_lcore_id*), some libraries will use an alternative unique ID (e.g. TID), some will not be impacted at all, and some will work but with limitations (e.g. timer and mempool libraries). All these impacts are mentioned in :ref:`known_issue_label` section.
@@ -613,9 +617,9 @@ Known Issues + rte_mempool The rte_mempool uses a per-lcore cache inside the mempool. - For non-EAL pthreads, ``rte_lcore_id()`` will not return a valid number. - So for now, when rte_mempool is used with non-EAL pthreads, the put/get operations will bypass the default mempool cache and there is a performance penalty because of this bypass. - Only user-owned external caches can be used in a non-EAL context in conjunction with ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()`` that accept an explicit cache parameter. + For unregistered non-EAL pthreads, ``rte_lcore_id()`` will not return a valid number. + So for now, when rte_mempool is used with unregistered non-EAL pthreads, the put/get operations will bypass the default mempool cache and there is a performance penalty because of this bypass. + Only user-owned external caches can be used in an unregistered non-EAL context in conjunction with ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()`` that accept an explicit cache parameter. + rte_ring
@@ -660,15 +664,15 @@ Known Issues + rte_timer - Running ``rte_timer_manage()`` on a non-EAL pthread is not allowed. However, resetting/stopping the timer from a non-EAL pthread is allowed. + Running ``rte_timer_manage()`` on an unregistered non-EAL pthread is not allowed. However, resetting/stopping the timer from a non-EAL pthread is allowed. + rte_log - In non-EAL pthreads, there is no per thread loglevel and logtype, global loglevels are used. + In unregistered non-EAL pthreads, there is no per thread loglevel and logtype, global loglevels are used. + misc - The debug statistics of rte_ring, rte_mempool and rte_timer are not supported in a non-EAL pthread. + The debug statistics of rte_ring, rte_mempool and rte_timer are not supported in an unregistered non-EAL pthread. cgroup control ~~~~~~~~~~~~~~
doc/guides/prog_guide/mempool_lib.rst +1 -1
@@ -103,7 +103,7 @@ The maximum size of the cache is static and is defined at compilation time (CONF Alternatively to the internal default per-lcore local cache, an application can create and manage external caches through the ``rte_mempool_cache_create()``, ``rte_mempool_cache_free()`` and ``rte_mempool_cache_flush()`` calls. These user-owned caches can be explicitly passed to ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()``. The ``rte_mempool_default_cache()`` call returns the default internal cache if any. -In contrast to the default caches, user-owned caches can be used by non-EAL threads too. +In contrast to the default caches, user-owned caches can be used by unregistered non-EAL threads too. Mempool Handlers ------------------------
lib/librte_eal/common/eal_common_lcore.c +40 -4
55 lines not on this page · raw message
lib/librte_eal/common/eal_common_thread.c +33 -0
@@ -236,3 +236,36 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_join (*thread,NULL );return -ret; } + +void +rte_thread_register (void ) +{ +unsigned int lcore_id; +rte_cpuset_t cpuset; + +/* EAL init flushes all lcores, we can't register before. */ +assert (internal_config.init_complete ==1 ); +if (pthread_getaffinity_np (pthread_self (),sizeof (cpuset), + &cpuset) !=0 ) +CPU_ZERO (&cpuset); + lcore_id =eal_lcore_non_eal_allocate (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ; +rte_thread_init (lcore_id, &cpuset); +if (lcore_id !=LCORE_ID_ANY ) +RTE_LOG (DEBUG ,EAL ,"Registered non-EAL thread as lcore %u.\n" , + lcore_id); +} + +void +rte_thread_unregister (void ) +{ +unsigned int lcore_id =rte_lcore_id (); + +if (lcore_id !=LCORE_ID_ANY ) +eal_lcore_non_eal_release (lcore_id); +rte_thread_uninit (); +if (lcore_id !=LCORE_ID_ANY ) +RTE_LOG (DEBUG ,EAL ,"Unregistered non-EAL thread (was lcore %u).\n" , + lcore_id); +}
lib/librte_eal/common/eal_private.h +18 -0
@@ -396,6 +396,24 @@ uint64_t get_tsc_freq(void);*/ uint64_t get_tsc_freq_arch (void ); +/** +* Allocate a free lcore to associate to a non-EAL thread. +* +* @return +* - the id of a lcore with role ROLE_NON_EAL on success. +* - RTE_MAX_LCORE if none was available. +*/ +unsigned int eal_lcore_non_eal_allocate (void ); + +/** +* Release the lcore used by a non-EAL thread. +* Counterpart of eal_lcore_non_eal_allocate(). +* +* @param lcore_id +* The lcore with role ROLE_NON_EAL to release. +*/ +void eal_lcore_non_eal_release (unsigned int lcore_id); +/** * Prepare physical memory mapping * i.e. hugepages on Linux and
lib/librte_eal/include/rte_lcore.h +17 -1
@@ -31,6 +31,7 @@ enum rte_lcore_role_t {ROLE_RTE ,ROLE_OFF ,ROLE_SERVICE , + ROLE_NON_EAL, };/**
@@ -67,7 +68,8 @@ rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role);* to run threads with lcore IDs 0, 1, 2 and 3 on physical core 10.. * * @return -* Logical core ID (in EAL thread) or LCORE_ID_ANY (in non-EAL thread) +* Logical core ID (in EAL thread or registered non-EAL thread) or +* LCORE_ID_ANY (in unregistered non-EAL thread) */ static inline unsigned rte_lcore_id (void )
@@ -279,6 +281,20 @@ int rte_thread_setname(pthread_t id, const char *name);__rte_experimental int rte_thread_getname(pthread_t id, char *name, size_t len); +/** +* Register current non-EAL thread as a lcore. +*/ +__rte_experimental +void +rte_thread_register (void ); + +/** +* Unregister current thread and release lcore if one was associated. +*/ +__rte_experimental +void +rte_thread_unregister (void ); +/** * Create a control thread. *
lib/librte_eal/rte_eal_version.map +4 -0
@@ -393,6 +393,10 @@ EXPERIMENTAL { rte_trace_point_lookup; rte_trace_regexp; rte_trace_save; + + # added in 20.08 + rte_thread_register; + rte_thread_unregister; }; INTERNAL {
lib/librte_mempool/rte_mempool.h +6 -5
@@ -28,9 +28,9 @@* rte_mempool_get() or rte_mempool_put() are designed to be called from an EAL * thread due to the internal per-lcore cache. Due to the lack of caching, * rte_mempool_get() or rte_mempool_put() performance will suffer when called -* by non-EAL threads. Instead, non-EAL threads should call -* rte_mempool_generic_get() or rte_mempool_generic_put() with a user cache -* created with rte_mempool_cache_create(). +* by unregistered non-EAL threads. Instead, unregistered non-EAL threads +* should call rte_mempool_generic_get() or rte_mempool_generic_put() with a +* user cache created with rte_mempool_cache_create(). */ #include <stdio.h>
@@ -1233,7 +1233,7 @@ void rte_mempool_dump(FILE *f, struct rte_mempool *mp);/** * Create a user-owned mempool cache. * -* This can be used by non-EAL threads to enable caching when they +* This can be used by unregistered non-EAL threads to enable caching when they * interact with a mempool. * * @param size
@@ -1264,7 +1264,8 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache);* @param lcore_id * The logical core id. * @return -* A pointer to the mempool cache or NULL if disabled or non-EAL thread. +* A pointer to the mempool cache or NULL if disabled or unregistered non-EAL +* thread. */ static __rte_always_inline struct rte_mempool_cache *rte_mempool_default_cache (struct rte_mempool *mp,unsigned lcore_id)
Signature · 1 line
2.23.0
PATCH v2 7/9 eal: add lcore init callbacks
In reply to David MarchandDPDK components and applications can have their say when a new lcore is initialized. For this, they can register a callback for initializing and releasing their private data.
---
Changes since v1:
- added unit test (since missing some coverage, for v3),
- preferred callback and removed mention of notification,
--- app/test/test_lcores.c | 95 ++++++++++++++++ lib/librte_eal/common/eal_common_lcore.c | 139 ++++++++++++++++++++++- lib/librte_eal/common/eal_private.h | 3 +- lib/librte_eal/include/rte_lcore.h | 68 +++++++++++ lib/librte_eal/rte_eal_version.map | 2 + 5 files changed, 301 insertions(+), 6 deletions(-)
app/test/test_lcores.c +95 -0
@@ -5,6 +5,7 @@#include <pthread.h> #include <string.h> +#include <rte_common.h> #include <rte_lcore.h> #include "test.h"
@@ -113,6 +114,95 @@ test_non_eal_lcores(unsigned int eal_threads_count)return ret; } +struct limit_lcore_context { +unsigned int init; +unsigned int max; +unsigned int uninit; +}; +static int +limit_lcores_init(unsigned int lcore_id __rte_unused, void *arg) +{ +struct limit_lcore_context *l = arg; + + l->init++; +if (l->init > l->max) +return -1 ; +return 0 ; +} +static void +limit_lcores_uninit(unsigned int lcore_id __rte_unused, void *arg) +{ +struct limit_lcore_context *l = arg; + + l->uninit++; +} + +static int +test_lcores_callback (unsigned int eal_threads_count) +{ +struct limit_lcore_context l; +void *handle; + +/* Refuse last lcore => callback register error. */ +memset (&l,0 ,sizeof (l)); + l.max = eal_threads_count -1 ; + handle =rte_lcore_callback_register ("limit" , limit_lcores_init, + limit_lcores_uninit, &l); +if (handle !=NULL ) { +printf ("lcore callback register should have failed\n" ); + goto error; + } +/* Refusal happens at the n th call to the init callback. +* Besides, n - 1 were accepted, so we expect as many uninit calls when +* the rollback happens. +*/ +if (l.init != eal_threads_count) { +printf ("lcore init calls failed: expected %u, got %u\n" , + eal_threads_count, l.init); + goto error; + } +if (l.uninit != eal_threads_count -1 ) { +printf ("lcore uninit calls failed: expected %u, got %u\n" , + eal_threads_count -1 , l.uninit); + goto error; + } + +/* Accept all lcore and unregister. */ +memset (&l,0 ,sizeof (l)); + l.max = eal_threads_count; + handle =rte_lcore_callback_register ("limit" , limit_lcores_init, + limit_lcores_uninit, &l); +if (handle ==NULL ) { +printf ("lcore callback register failed\n" ); + goto error; + } +if (l.uninit !=0 ) { +printf ("lcore uninit got called %u times during register\n" , + l.uninit); + goto error; + } +rte_lcore_callback_unregister (handle); + handle =NULL ; +if (l.init != eal_threads_count) { +printf ("lcore init got called %u times during unregister (expected %u)\n" , + l.init, eal_threads_count); + goto error; + } +if (l.uninit != eal_threads_count) { +printf ("lcore uninit calls failed: expected %u, got %u\n" , + eal_threads_count, l.uninit); + goto error; + } + +return 0 ; + +error: +if (handle !=NULL ) +rte_lcore_callback_unregister (handle); + +return -1 ; +} +static int test_lcores (void ) {
@@ -133,6 +223,11 @@ test_lcores(void)if (test_non_eal_lcores (eal_threads_count) <0 )return TEST_FAILED ; +if (test_lcores_callback (eal_threads_count) <0 ) +return TEST_FAILED ; + +/* FIXME: missing a test on callback + registering non-EAL threads */ +return TEST_SUCCESS ; }
lib/librte_eal/common/eal_common_lcore.c +134 -5
164 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +2 -1
@@ -401,7 +401,8 @@ uint64_t get_tsc_freq_arch(void);* * @return * - the id of a lcore with role ROLE_NON_EAL on success. -* - RTE_MAX_LCORE if none was available. +* - RTE_MAX_LCORE if none was available or initializing was refused (see +* rte_lcore_callback_register). */ unsigned int eal_lcore_non_eal_allocate (void );
lib/librte_eal/include/rte_lcore.h +68 -0
74 lines not on this page · raw message
lib/librte_eal/rte_eal_version.map +2 -0
@@ -395,6 +395,8 @@ EXPERIMENTAL { rte_trace_save; # added in 20.08 + rte_lcore_callback_register; + rte_lcore_callback_unregister; rte_thread_register; rte_thread_unregister; };
Signature · 1 line
2.23.0
PATCH v2 8/9 eal: add lcore iterators
In reply to David MarchandAdd a helper to iterate all lcores.
The iterator callback is read-only wrt the lcores list.
Implement a dump function on top of this for debugging.
---
Changes since v1:
- introduced lcore iterators and implemented rte_lcore_dump, this iterator mechanism can then be used outside of EAL,
--- lib/librte_eal/common/eal_common_lcore.c | 77 ++++++++++++++++++++--- lib/librte_eal/common/eal_common_thread.c | 16 +++-- lib/librte_eal/common/eal_thread.h | 13 +++- lib/librte_eal/freebsd/eal.c | 2 +- lib/librte_eal/freebsd/eal_thread.c | 2 +- lib/librte_eal/include/rte_lcore.h | 47 +++++++++++++- lib/librte_eal/linux/eal.c | 2 +- lib/librte_eal/linux/eal_thread.c | 2 +- lib/librte_eal/rte_eal_version.map | 2 + 9 files changed, 140 insertions(+), 23 deletions(-)
lib/librte_eal/common/eal_common_lcore.c +67 -10
@@ -12,7 +12,7 @@#include <rte_errno.h> #include <rte_lcore.h> #include <rte_log.h> -#include <rte_spinlock.h> +#include <rte_rwlock.h> #include "eal_private.h" #include "eal_thread.h"
@@ -222,7 +222,7 @@ rte_socket_id_by_idx(unsigned int idx)return config->numa_nodes[idx]; } -static rte_spinlock_t lcore_lock =RTE_SPINLOCK_INITIALIZER ; +static rte_rwlock_t lcore_lock =RTE_RWLOCK_INITIALIZER ;struct lcore_callback {TAILQ_ENTRY (lcore_callback) next;char *name;
@@ -271,7 +271,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init, callback->init = init; callback->uninit = uninit; callback->arg = arg; -rte_spinlock_lock (&lcore_lock); +rte_rwlock_write_lock (&lcore_lock);if (callback->init ==NULL ) goto no_init;for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) {
@@ -297,7 +297,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init, callback->name, callback->init ==NULL ?"NO " :"" , callback->uninit == NULL ? "NO " : ""); out: -rte_spinlock_unlock (&lcore_lock); +rte_rwlock_write_unlock (&lcore_lock);return callback; }
@@ -308,7 +308,7 @@ rte_lcore_callback_unregister(void *handle)struct lcore_callback *callback = handle;unsigned int lcore_id; -rte_spinlock_lock (&lcore_lock); +rte_rwlock_write_lock (&lcore_lock);if (callback->uninit ==NULL ) goto no_uninit;for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) {
@@ -318,7 +318,7 @@ rte_lcore_callback_unregister(void *handle) } no_uninit:TAILQ_REMOVE (&lcore_callbacks, callback, next); -rte_spinlock_unlock (&lcore_lock); +rte_rwlock_write_unlock (&lcore_lock);RTE_LOG (DEBUG ,EAL ,"Unregistered lcore callback %s-%p.\n" , callback->name, callback->arg);free (callback->name);
@@ -333,7 +333,7 @@ eal_lcore_non_eal_allocate(void)struct lcore_callback *prev;unsigned int lcore_id; -rte_spinlock_lock (&lcore_lock); +rte_rwlock_write_lock (&lcore_lock);for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) {if (cfg->lcore_role[lcore_id] !=ROLE_OFF )continue ;
@@ -365,7 +365,7 @@ eal_lcore_non_eal_allocate(void) goto out; } out: -rte_spinlock_unlock (&lcore_lock); +rte_rwlock_write_unlock (&lcore_lock);return lcore_id; }
@@ -375,7 +375,7 @@ eal_lcore_non_eal_release(unsigned int lcore_id)struct rte_config *cfg =rte_eal_get_configuration ();struct lcore_callback *callback; -rte_spinlock_lock (&lcore_lock); +rte_rwlock_write_lock (&lcore_lock);if (cfg->lcore_role[lcore_id] !=ROLE_NON_EAL ) goto out;TAILQ_FOREACH (callback, &lcore_callbacks, next)
@@ -383,5 +383,62 @@ eal_lcore_non_eal_release(unsigned int lcore_id) cfg->lcore_role[lcore_id] =ROLE_OFF ; cfg->lcore_count--; out: -rte_spinlock_unlock (&lcore_lock); +rte_rwlock_write_unlock (&lcore_lock); +} + +int +rte_lcore_iterate (rte_lcore_iterate_cb cb,void *arg) +{ +struct rte_config *cfg =rte_eal_get_configuration (); +unsigned int lcore_id; +int ret =0 ; + +rte_rwlock_read_lock (&lcore_lock); +for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +if (cfg->lcore_role[lcore_id] ==ROLE_OFF ) +continue ; + ret =cb (lcore_id, arg); +if (ret !=0 ) +break ; + } +rte_rwlock_read_unlock (&lcore_lock); +return ret; +} + +static int +lcore_dump_cb (unsigned int lcore_id,void *arg) +{ +struct rte_config *cfg =rte_eal_get_configuration (); +char cpuset[RTE_CPU_AFFINITY_STR_LEN ]; +const char *role; +FILE *f = arg; +int ret; + +switch (cfg->lcore_role[lcore_id]) { +case ROLE_RTE : + role ="RTE" ; +break ; +case ROLE_SERVICE : + role ="SERVICE" ; +break ; +case ROLE_NON_EAL : + role ="NON_EAL" ; +break ; +default : + role ="UNKNOWN" ; +break ; + } + + ret =eal_thread_dump_affinity (&lcore_config[lcore_id].cpuset, cpuset, +sizeof (cpuset)); +fprintf (f,"lcore %u, socket %u, role %s, cpuset %s%s\n" , lcore_id, +rte_lcore_to_socket_id (lcore_id), role, cpuset, + ret ==0 ?"" :"..." ); +return 0 ; +} + +void +rte_lcore_dump (FILE *f) +{ +rte_lcore_iterate (lcore_dump_cb, f); }
lib/librte_eal/common/eal_common_thread.c +11 -5
@@ -104,17 +104,14 @@ rte_thread_get_affinity(rte_cpuset_t *cpusetp) }int -eal_thread_dump_affinity (char *str,unsigned size) +eal_thread_dump_affinity (rte_cpuset_t *cpuset,char *str,unsigned int size) { -rte_cpuset_t cpuset;unsigned cpu;int ret;unsigned int out =0 ; -rte_thread_get_affinity (&cpuset); -for (cpu =0 ; cpu <CPU_SETSIZE ; cpu++) { -if (!CPU_ISSET (cpu, &cpuset)) +if (!CPU_ISSET (cpu, cpuset))continue ; ret = snprintf(str + out,
@@ -137,6 +134,15 @@ eal_thread_dump_affinity(char *str, unsigned size)return ret; } +int +eal_thread_dump_current_affinity (char *str,unsigned int size) +{ +rte_cpuset_t cpuset; + +rte_thread_get_affinity (&cpuset); +return eal_thread_dump_affinity (&cpuset, str, size); +} +void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) {
lib/librte_eal/common/eal_thread.h +11 -2
@@ -47,13 +47,15 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);#define RTE_CPU_AFFINITY_STR_LEN 256/** -* Dump the current pthread cpuset. +* Dump the cpuset as a human readable string. * This function is private to EAL. * * Note: * If the dump size is greater than the size of given buffer, * the string will be truncated and with '\0' at the end. * +* @param cpuset +* The CPU affinity object to dump. * @param str * The string buffer the cpuset will dump to. * @param size
@@ -62,6 +64,13 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);* 0 for success, -1 if truncation happens. */ int -eal_thread_dump_affinity (char *str,unsigned size); +eal_thread_dump_affinity (rte_cpuset_t *cpuset,char *str,unsigned int size); + +/** +* Dump the current thread cpuset. +* This is a wrapper on eal_thread_dump_affinity(). +*/ +int +eal_thread_dump_current_affinity (char *str,unsigned int size);#endif /* EAL_THREAD_H */
lib/librte_eal/freebsd/eal.c +1 -1
@@ -886,7 +886,7 @@ rte_eal_init(int argc, char **argv)rte_thread_init (rte_config.master_lcore, &lcore_config[rte_config.master_lcore].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset)); RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n", rte_config.master_lcore, thread_id, cpuset,
lib/librte_eal/freebsd/eal_thread.c +1 -1
@@ -92,7 +92,7 @@ eal_thread_loop(__rte_unused void *arg)rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , lcore_id, thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/include/rte_lcore.h +45 -2
59 lines not on this page · raw message
lib/librte_eal/linux/eal.c +1 -1
@@ -1214,7 +1214,7 @@ rte_eal_init(int argc, char **argv)rte_thread_init (rte_config.master_lcore, &lcore_config[rte_config.master_lcore].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , rte_config.master_lcore, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/linux/eal_thread.c +1 -1
@@ -92,7 +92,7 @@ eal_thread_loop(__rte_unused void *arg)rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/rte_eal_version.map +2 -0
@@ -397,6 +397,8 @@ EXPERIMENTAL { # added in 20.08 rte_lcore_callback_register; rte_lcore_callback_unregister; + rte_lcore_dump; + rte_lcore_iterate; rte_thread_register; rte_thread_unregister; };
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v2 8/9] eal: add lcore iterators
lib/librte_eal/common/eal_common_lcore.c eal_lcore_non_eal_release(unsigned int lcore_id) · line 396
Quoted 1 line · On Fri, 19 Jun 2020 18:22:43 +0200 David Marchand <[email protected]>…
lib/librte_eal/common/eal_common_lcore.c +1
-0+rte_rwlock_read_lock (&lcore_lock);
I see you converted a spin lock to a reader lock.
Are you sure this is a good idea, although conceptually faster, the implementation on most cpu's is slower than a simple spin lock.
https://www.kernel.org/doc/htmldocs/kernel-locking/Efficiency.html
If your code divides neatly along reader/writer lines (as our cache code does), and the lock is held by readers for significant lengths of time, using these locks can help. They are slightly slower than the normal locks though, so in practice rwlock_t is not usually worthwhile.
PATCH v2 9/9 mempool/bucket: handle non-EAL lcores
In reply to David MarchandConvert to new lcore API to support non-EAL lcores.
--- drivers/mempool/bucket/rte_mempool_bucket.c | 131 ++++++++++++-------- 1 file changed, 82 insertions(+), 49 deletions(-)
drivers/mempool/bucket/rte_mempool_bucket.c +82 -49
@@ -55,6 +55,7 @@ struct bucket_data {struct rte_ring *shared_orphan_ring;struct rte_mempool *pool;unsigned int bucket_mem_size; +void *lcore_callback_handle; }; static struct bucket_stack *
@@ -345,6 +346,22 @@ bucket_dequeue_contig_blocks(struct rte_mempool *mp, void **first_obj_table,return 0 ; } +struct bucket_per_lcore_ctx { +const struct bucket_data *bd; +unsigned int count; +}; + +static int +count_per_lcore (unsigned int lcore_id,void *arg) +{ +struct bucket_per_lcore_ctx *ctx = arg; + + ctx->count += ctx->bd->obj_per_bucket * + ctx->bd->buckets[lcore_id]->top; + ctx->count +=rte_ring_count (ctx->bd->adoption_buffer_rings[lcore_id]); +return 0 ; +} + static void count_underfilled_buckets(struct rte_mempool *mp, void *opaque,
@@ -373,23 +390,66 @@ count_underfilled_buckets(struct rte_mempool *mp,static unsigned int bucket_get_count (const struct rte_mempool *mp) { -const struct bucket_data *bd = mp->pool_data; -unsigned int count = - bd->obj_per_bucket *rte_ring_count (bd->shared_bucket_ring) + -rte_ring_count (bd->shared_orphan_ring); -unsigned int i; +struct bucket_per_lcore_ctx ctx; -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (!rte_lcore_is_enabled (i)) -continue ; - count += bd->obj_per_bucket * bd->buckets[i]->top + -rte_ring_count (bd->adoption_buffer_rings[i]); - } + ctx.bd = mp->pool_data; + ctx.count = ctx.bd->obj_per_bucket * +rte_ring_count (ctx.bd->shared_bucket_ring); + ctx.count +=rte_ring_count (ctx.bd->shared_orphan_ring); +rte_lcore_iterate (count_per_lcore, &ctx);rte_mempool_mem_iter ((struct rte_mempool *)(uintptr_t )mp, - count_underfilled_buckets, &count); + count_underfilled_buckets, &ctx.count); + +return ctx.count; +} + +static int +bucket_init_per_lcore (unsigned int lcore_id,void *arg) +{ +char rg_name[RTE_RING_NAMESIZE ]; +struct bucket_data *bd = arg; +struct rte_mempool *mp; +int rg_flags; +int rc; + + mp = bd->pool; + bd->buckets[lcore_id] =bucket_stack_create (mp, + mp->size / bd->obj_per_bucket); +if (bd->buckets[lcore_id] ==NULL ) + goto error; + + rc =snprintf (rg_name,sizeof (rg_name),RTE_MEMPOOL_MZ_FORMAT ".a%u" , + mp->name, lcore_id); +if (rc <0 || rc >= (int )sizeof (rg_name)) + goto error; + + rg_flags =RING_F_SC_DEQ ; +if (mp->flags &MEMPOOL_F_SP_PUT ) + rg_flags |=RING_F_SP_ENQ ; +if (mp->flags &MEMPOOL_F_SC_GET ) + rg_flags |=RING_F_SC_DEQ ; + bd->adoption_buffer_rings[lcore_id] =rte_ring_create (rg_name, +rte_align32pow2 (mp->size +1 ), mp->socket_id, rg_flags); +if (bd->adoption_buffer_rings[lcore_id] ==NULL ) + goto error; -return count; +return 0 ; +error: +rte_free (bd->buckets[lcore_id]); + bd->buckets[lcore_id] =NULL ; +return -1 ; +} + +static void +bucket_uninit_per_lcore (unsigned int lcore_id,void *arg) +{ +struct bucket_data *bd = arg; + +rte_ring_free (bd->adoption_buffer_rings[lcore_id]); + bd->adoption_buffer_rings[lcore_id] =NULL ; +rte_free (bd->buckets[lcore_id]); + bd->buckets[lcore_id] =NULL ; } static int
@@ -399,7 +459,6 @@ bucket_alloc(struct rte_mempool *mp)int rc =0 ;char rg_name[RTE_RING_NAMESIZE ];struct bucket_data *bd; -unsigned int i;unsigned int bucket_header_size;size_t pg_sz;
@@ -429,36 +488,17 @@ bucket_alloc(struct rte_mempool *mp)/* eventually this should be a tunable parameter */ bd->bucket_stack_thresh = (mp->size / bd->obj_per_bucket) *4 /3 ; + bd->lcore_callback_handle =rte_lcore_callback_register ("bucket" , + bucket_init_per_lcore, bucket_uninit_per_lcore, bd); +if (bd->lcore_callback_handle ==NULL ) { + rc = -ENOMEM ; + goto no_mem_for_stacks; + } +if (mp->flags &MEMPOOL_F_SP_PUT ) rg_flags |=RING_F_SP_ENQ ;if (mp->flags &MEMPOOL_F_SC_GET ) rg_flags |=RING_F_SC_DEQ ; - -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (!rte_lcore_is_enabled (i)) -continue ; - bd->buckets[i] = -bucket_stack_create (mp, mp->size / bd->obj_per_bucket); -if (bd->buckets[i] ==NULL ) { - rc = -ENOMEM ; - goto no_mem_for_stacks; - } - rc =snprintf (rg_name,sizeof (rg_name), -RTE_MEMPOOL_MZ_FORMAT ".a%u" , mp->name, i); -if (rc <0 || rc >= (int )sizeof (rg_name)) { - rc = -ENAMETOOLONG ; - goto no_mem_for_stacks; - } - bd->adoption_buffer_rings[i] = -rte_ring_create (rg_name,rte_align32pow2 (mp->size +1 ), - mp->socket_id, - rg_flags |RING_F_SC_DEQ ); -if (bd->adoption_buffer_rings[i] ==NULL ) { - rc = -rte_errno; - goto no_mem_for_stacks; - } - } - rc =snprintf (rg_name,sizeof (rg_name),RTE_MEMPOOL_MZ_FORMAT ".0" , mp->name);if (rc <0 || rc >= (int )sizeof (rg_name)) {
@@ -498,11 +538,8 @@ bucket_alloc(struct rte_mempool *mp)rte_ring_free (bd->shared_orphan_ring); cannot_create_shared_orphan_ring: invalid_shared_orphan_ring: +rte_lcore_callback_unregister (bd->lcore_callback_handle); no_mem_for_stacks: -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -rte_free (bd->buckets[i]); -rte_ring_free (bd->adoption_buffer_rings[i]); - }rte_free (bd); no_mem_for_data: rte_errno = -rc;
@@ -512,16 +549,12 @@ bucket_alloc(struct rte_mempool *mp)static void bucket_free (struct rte_mempool *mp) { -unsigned int i;struct bucket_data *bd = mp->pool_data;if (bd ==NULL )return ; -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -rte_free (bd->buckets[i]); -rte_ring_free (bd->adoption_buffer_rings[i]); - } +rte_lcore_callback_unregister (bd->lcore_callback_handle);rte_ring_free (bd->shared_orphan_ring);rte_ring_free (bd->shared_bucket_ring);
Signature · 1 line
2.23.0
v3 cover Register non-EAL threads as lcore
In reply to David MarchandOVS and some other applications have been hacking into DPDK internals to fake EAL threads and avoid performance penalty of only having non-EAL threads.
This series proposes to add a new type of lcores and maps those threads to such lcores.
non-EAL threads won't run the DPDK eal mainloop.
As a consequence, part of the EAL threads API cannot work.
Having new lcores appearing during the process lifetime is not expected by some DPDK components. This is addressed by introducing init/uninit callacks invoked when hotplugging of such lcore.
There is still some work/discussion:
- refuse new lcore role in incompatible EAL threads API (or document it only as those API were already incompatible?),
- think about deprecation notices for existing RTE_FOREACH_LCORE macros and consorts, it is probably worth discussing on how to iterate over lcores,
For the interested parties, I have a patch [1] against dpdk-latest OVS branch that makes use of this series.
1: https://github.com/david-marchand/ovs/commit/dpdk-latest-external-lcores
Changes since v2:
- fixed windows build error due to missing trace stub,
- fixed bug when rolling back on lcore register,
Changes since v1:
- rebased on master (conflicts on merged Windows series),
- separated lcore role code cleanup in a patch,
- tried to use a single naming, so kept non-EAL threads as the main notion. non-EAL threads are then distinguished between registered and unregistered non-EAL threads,
- added unit tests (still missing some coverage, marked with a FIXME),
- reworked callbacks call under a common rwlock lock which protects lcores allocations and callbacks registration,
- introduced lcore iterators and converted the bucket mempool driver,
Signature · 44 lines
David Marchand David Marchand (9): eal: relocate per thread symbols to common eal: fix multiple definition of per lcore thread id eal: introduce thread init helper eal: introduce thread uninit helper eal: move lcore role code eal: register non-EAL threads as lcores eal: add lcore init callbacks eal: add lcore iterators mempool/bucket: handle non-EAL lcores MAINTAINERS | 1 + app/test/Makefile | 1 + app/test/autotest_data.py | 6 + app/test/meson.build | 2 + app/test/test_lcores.c | 372 ++++++++++++++++++ doc/guides/howto/debug_troubleshoot.rst | 5 +- .../prog_guide/env_abstraction_layer.rst | 22 +- doc/guides/prog_guide/mempool_lib.rst | 2 +- drivers/mempool/bucket/rte_mempool_bucket.c | 131 +++--- lib/librte_eal/common/eal_common_lcore.c | 240 ++++++++++- lib/librte_eal/common/eal_common_thread.c | 126 ++++-- lib/librte_eal/common/eal_common_trace.c | 51 ++- lib/librte_eal/common/eal_private.h | 19 + lib/librte_eal/common/eal_thread.h | 26 +- lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/freebsd/eal.c | 16 +- lib/librte_eal/freebsd/eal_thread.c | 38 +- lib/librte_eal/include/rte_eal.h | 12 +- lib/librte_eal/include/rte_lcore.h | 167 +++++++- lib/librte_eal/include/rte_trace_point.h | 9 + lib/librte_eal/linux/eal.c | 17 +- lib/librte_eal/linux/eal_thread.c | 38 +- lib/librte_eal/rte_eal_version.map | 16 + lib/librte_eal/windows/eal.c | 8 +- lib/librte_eal/windows/eal_thread.c | 14 +- lib/librte_mempool/rte_mempool.h | 11 +- 26 files changed, 1113 insertions(+), 239 deletions(-) create mode 100644 app/test/test_lcores.c -- 2.23.0
PATCH v3 1/9 eal: relocate per thread symbols to common
We have per lcore thread symbols scattered in OS implementations but common code relies on them.
Move all of them in common.
RTE_PER_LCORE(_socket_id) and RTE_PER_LCORE(_cpuset) have public accessors and are not exported through the library map, they can be made static.
--- lib/librte_eal/common/eal_common_thread.c | 5 ++++- lib/librte_eal/freebsd/eal_thread.c | 4 ---- lib/librte_eal/include/rte_lcore.h | 1 - lib/librte_eal/linux/eal_thread.c | 4 ---- lib/librte_eal/windows/eal_thread.c | 4 ---- 5 files changed, 4 insertions(+), 14 deletions(-)
lib/librte_eal/common/eal_common_thread.c +4 -1
@@ -21,7 +21,10 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DECLARE_PER_LCORE (unsigned , _socket_id); +RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = + (unsigned int )SOCKET_ID_ANY ; +static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);unsigned rte_socket_id (void ) {
lib/librte_eal/freebsd/eal_thread.c +0 -4
@@ -25,10 +25,6 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; -RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
lib/librte_eal/include/rte_lcore.h +0 -1
@@ -23,7 +23,6 @@ extern "C" {#define LCORE_ID_ANY UINT32_MAX/**< Any lcore. */ RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ -RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */ /** * Get a lcore's role.
lib/librte_eal/linux/eal_thread.c +0 -4
@@ -25,10 +25,6 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; -RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
lib/librte_eal/windows/eal_thread.c +0 -4
@@ -16,10 +16,6 @@#include "eal_private.h" #include "eal_windows.h" -RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; -RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int)SOCKET_ID_ANY; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
Signature · 1 line
2.23.0
PATCH v3 2/9 eal: fix multiple definition of per lcore thread id
In reply to David MarchandBecause of the inline accessor + static declaration in rte_gettid(), we end up with multiple symbols for RTE_PER_LCORE(_thread_id). Each compilation unit will pay a cost when accessing this information for the first time.
$ nm build/app/dpdk-testpmd | grep per_lcore__thread_id 0000000000000054 d per_lcore__thread_id.5037 0000000000000040 d per_lcore__thread_id.5103 0000000000000048 d per_lcore__thread_id.5259 000000000000004c d per_lcore__thread_id.5259 0000000000000044 d per_lcore__thread_id.5933 0000000000000058 d per_lcore__thread_id.6261 0000000000000050 d per_lcore__thread_id.7378 000000000000005c d per_lcore__thread_id.7496 000000000000000c d per_lcore__thread_id.8016 0000000000000010 d per_lcore__thread_id.8431
Make it global as part of the DPDK_21 stable ABI.
--- lib/librte_eal/common/eal_common_thread.c | 1 + lib/librte_eal/include/rte_eal.h | 3 ++- lib/librte_eal/rte_eal_version.map | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_thread.c +1 -0
@@ -22,6 +22,7 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +RTE_DEFINE_PER_LCORE (int, _thread_id) =-1 ; static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int )SOCKET_ID_ANY ; static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
lib/librte_eal/include/rte_eal.h +2 -1
@@ -447,6 +447,8 @@ enum rte_intr_mode rte_eal_vfio_intr_mode(void);*/ int rte_sys_gettid (void ); +RTE_DECLARE_PER_LCORE (int, _thread_id); +/** * Get system unique thread id. *
@@ -456,7 +458,6 @@ int rte_sys_gettid(void);*/ static inline int rte_gettid (void ) { - static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;if (RTE_PER_LCORE (_thread_id) ==-1 )RTE_PER_LCORE (_thread_id) =rte_sys_gettid ();return RTE_PER_LCORE (_thread_id);
lib/librte_eal/rte_eal_version.map +7 -0
@@ -221,6 +221,13 @@ DPDK_20.0 { local: *; }; +DPDK_21 { + global: + + per_lcore__thread_id; + +} DPDK_20.0; + EXPERIMENTAL { global:
Signature · 1 line
2.23.0
PATCH v3 3/9 eal: introduce thread init helper
In reply to David MarchandIntroduce a helper responsible for initialising the per thread context. We can then have a unified context for EAL and non-EAL threads and remove copy/paste'd OS-specific helpers.
Per EAL thread CPU affinity setting is separated from the thread init. It is to accommodate with Windows EAL where CPU affinity is not set at the moment.
Besides, having affinity set by the master lcore in FreeBSD and Linux will make it possible to detect errors rather than panic in the child thread. But the cleanup when such an event happens is left for later.
---
Changes since v1:
- rebased on master, removed Windows workarounds wrt gettid and traces support,
--- lib/librte_eal/common/eal_common_thread.c | 51 +++++++++++++---------- lib/librte_eal/common/eal_thread.h | 8 ++-- lib/librte_eal/freebsd/eal.c | 14 ++++++- lib/librte_eal/freebsd/eal_thread.c | 32 +------------- lib/librte_eal/linux/eal.c | 15 ++++++- lib/librte_eal/linux/eal_thread.c | 32 +------------- lib/librte_eal/windows/eal.c | 3 +- lib/librte_eal/windows/eal_thread.c | 10 +---- 8 files changed, 66 insertions(+), 99 deletions(-)
lib/librte_eal/common/eal_common_thread.c +30 -21
@@ -71,20 +71,10 @@ eal_cpuset_socket_id(rte_cpuset_t *cpusetp)return socket_id; } -int -rte_thread_set_affinity (rte_cpuset_t *cpusetp) +static void +thread_update_affinity (rte_cpuset_t *cpusetp) { -int s; -unsigned lcore_id; -pthread_t tid; - - tid =pthread_self (); - - s =pthread_setaffinity_np (tid,sizeof (rte_cpuset_t), cpusetp); -if (s !=0 ) { -RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); -return -1 ; - } +unsigned int lcore_id =rte_lcore_id ();/* store socket_id in TLS for quick access */ RTE_PER_LCORE(_socket_id) =
@@ -94,14 +84,24 @@ rte_thread_set_affinity(rte_cpuset_t *cpusetp)memmove (&RTE_PER_LCORE (_cpuset), cpusetp,sizeof (rte_cpuset_t)); - lcore_id =rte_lcore_id ();if (lcore_id != (unsigned )LCORE_ID_ANY ) {/* EAL thread will update lcore_config */ lcore_config[lcore_id].socket_id =RTE_PER_LCORE (_socket_id);memmove (&lcore_config[lcore_id].cpuset, cpusetp,sizeof (rte_cpuset_t)); } +} +int +rte_thread_set_affinity (rte_cpuset_t *cpusetp) +{ +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + cpusetp) !=0 ) { +RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); +return -1 ; + } + +thread_update_affinity (cpusetp);return 0 ; }
@@ -147,6 +147,19 @@ eal_thread_dump_affinity(char *str, unsigned size)return ret; } +void +rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) +{ +/* set the lcore ID in per-lcore memory area */ +RTE_PER_LCORE (_lcore_id) = lcore_id; + +/* acquire system unique id */ +rte_gettid (); + +thread_update_affinity (cpuset); + +__rte_trace_mem_per_thread_alloc (); +}struct rte_thread_ctrl_params {void *(*start_routine)(void *);
@@ -154,16 +167,14 @@ struct rte_thread_ctrl_params {pthread_barrier_t configured; }; -static void *rte_thread_init (void *arg) +static void *ctrl_thread_init (void *arg) {int ret; -rte_cpuset_t *cpuset = &internal_config.ctrl_cpuset;struct rte_thread_ctrl_params *params = arg;void *(*start_routine)(void *) = params->start_routine;void *routine_arg = params->arg; -/* Store cpuset in TLS for quick access */ -memmove (&RTE_PER_LCORE (_cpuset), cpuset,sizeof (rte_cpuset_t)); +rte_thread_init (rte_lcore_id (), &internal_config.ctrl_cpuset); ret =pthread_barrier_wait (¶ms->configured);if (ret ==PTHREAD_BARRIER_SERIAL_THREAD ) {
@@ -171,8 +182,6 @@ static void *rte_thread_init(void *arg)free (params); } -__rte_trace_mem_per_thread_alloc (); -return start_routine (routine_arg); }
@@ -194,7 +203,7 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_barrier_init (¶ms->configured,NULL ,2 ); - ret =pthread_create (thread, attr, rte_thread_init, (void *)params); + ret =pthread_create (thread, attr, ctrl_thread_init, (void *)params);if (ret !=0 ) {free (params);return -ret;
lib/librte_eal/common/eal_thread.h +5 -3
@@ -16,12 +16,14 @@ __rte_noreturn void *eal_thread_loop(void *arg);/** -* Init per-lcore info for master thread +* Init per-lcore info in current thread. * * @param lcore_id -* identifier of master lcore +* identifier of lcore. +* @param cpuset +* CPU affinity for this thread. */ -void eal_thread_init_master (unsigned lcore_id); +void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset);/** * Get the NUMA socket id from cpu id.
lib/librte_eal/freebsd/eal.c +13 -1
@@ -877,7 +877,14 @@ rte_eal_init(int argc, char **argv)eal_check_mem_on_local_socket (); -eal_thread_init_master (rte_config.master_lcore); +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + &lcore_config[rte_config.master_lcore].cpuset) !=0 ) { +rte_eal_init_alert ("Cannot set affinity" ); + rte_errno =EINVAL ; +return -1 ; + } +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset));
@@ -908,6 +915,11 @@ rte_eal_init(int argc, char **argv)snprintf (thread_name,sizeof (thread_name),"lcore-slave-%d" , i);rte_thread_setname (lcore_config[i].thread_id, thread_name); + + ret =pthread_setaffinity_np (lcore_config[i].thread_id, +sizeof (rte_cpuset_t), &lcore_config[i].cpuset); +if (ret !=0 ) +rte_panic ("Cannot set affinity\n" ); }/*
lib/librte_eal/freebsd/eal_thread.c +1 -31
@@ -66,29 +66,6 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)return rc; } -/* set affinity for current thread */ -static int -eal_thread_set_affinity (void ) -{ -unsigned lcore_id =rte_lcore_id (); - -/* acquire system unique id */ -rte_gettid (); - -/* update EAL thread core affinity */ -return rte_thread_set_affinity (&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master (unsigned lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); -} -/* main loop of threads */ __rte_noreturn void * eal_thread_loop(__rte_unused void *arg)
@@ -113,19 +90,12 @@ eal_thread_loop(__rte_unused void *arg) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , lcore_id, thread_id, cpuset, ret ==0 ?"" :"..." ); -__rte_trace_mem_per_thread_alloc ();rte_eal_trace_thread_lcore_ready (lcore_id, cpuset);/* read on our pipe to get commands */
lib/librte_eal/linux/eal.c +13 -2
@@ -1205,10 +1205,16 @@ rte_eal_init(int argc, char **argv)eal_check_mem_on_local_socket (); -eal_thread_init_master (rte_config.master_lcore); +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + &lcore_config[rte_config.master_lcore].cpuset) !=0 ) { +rte_eal_init_alert ("Cannot set affinity" ); + rte_errno =EINVAL ; +return -1 ; + } +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , rte_config.master_lcore, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
@@ -1240,6 +1246,11 @@ rte_eal_init(int argc, char **argv)if (ret !=0 )RTE_LOG (DEBUG ,EAL ,"Cannot set name for lcore thread\n" ); + + ret =pthread_setaffinity_np (lcore_config[i].thread_id, +sizeof (rte_cpuset_t), &lcore_config[i].cpuset); +if (ret !=0 ) +rte_panic ("Cannot set affinity\n" ); }/*
lib/librte_eal/linux/eal_thread.c +1 -31
@@ -66,29 +66,6 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)return rc; } -/* set affinity for current EAL thread */ -static int -eal_thread_set_affinity (void ) -{ -unsigned lcore_id =rte_lcore_id (); - -/* acquire system unique id */ -rte_gettid (); - -/* update EAL thread core affinity */ -return rte_thread_set_affinity (&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master (unsigned lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); -} -/* main loop of threads */ __rte_noreturn void * eal_thread_loop(__rte_unused void *arg)
@@ -113,19 +90,12 @@ eal_thread_loop(__rte_unused void *arg) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." ); -__rte_trace_mem_per_thread_alloc ();rte_eal_trace_thread_lcore_ready (lcore_id, cpuset);/* read on our pipe to get commands */
lib/librte_eal/windows/eal.c +2 -1
@@ -354,7 +354,8 @@ rte_eal_init(int argc, char **argv)return -1 ; } -eal_thread_init_master (rte_config.master_lcore); +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset);RTE_LCORE_FOREACH_SLAVE (i) {
lib/librte_eal/windows/eal_thread.c +1 -9
@@ -53,13 +53,6 @@ rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int slave_id)return 0 ; } -void -eal_thread_init_master (unsigned int lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; -} -/* main loop of threads */ void * eal_thread_loop(void *arg __rte_unused)
@@ -84,8 +77,7 @@ eal_thread_loop(void *arg __rte_unused) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset);RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset);
Signature · 1 line
2.23.0
PATCH v3 4/9 eal: introduce thread uninit helper
In reply to David MarchandThis is a preparation step for dynamically unregistering threads.
Since we explicitly allocate a per thread trace buffer in rte_thread_init, add an internal helper to free this buffer.
---
Note: I preferred renaming the current internal function to free all threads trace buffers (new name trace_mem_free()) and reuse the previous name (trace_mem_per_thread_free()) when freeing this buffer for a given thread.
Changes since v2:
- added missing stub for windows tracing support,
- moved free symbol to exported (experimental) ABI as a counterpart of the alloc symbol we already had,
Changes since v1:
- rebased on master, removed Windows workaround wrt traces support,
--- lib/librte_eal/common/eal_common_thread.c | 9 ++++ lib/librte_eal/common/eal_common_trace.c | 51 +++++++++++++++++++---- lib/librte_eal/common/eal_thread.h | 5 +++ lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/include/rte_trace_point.h | 9 ++++ lib/librte_eal/rte_eal_version.map | 3 ++ lib/librte_eal/windows/eal.c | 5 +++ 7 files changed, 75 insertions(+), 9 deletions(-)
lib/librte_eal/common/eal_common_thread.c +9 -0
@@ -20,6 +20,7 @@#include "eal_internal_cfg.h" #include "eal_private.h" #include "eal_thread.h" +#include "eal_trace.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;RTE_DEFINE_PER_LCORE (int, _thread_id) =-1 ;
@@ -161,6 +162,14 @@ rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset)__rte_trace_mem_per_thread_alloc (); } +void +rte_thread_uninit (void ) +{ +__rte_trace_mem_per_thread_free (); + +RTE_PER_LCORE (_lcore_id) =LCORE_ID_ANY ; +} +struct rte_thread_ctrl_params {void *(*start_routine)(void *);void *arg;
lib/librte_eal/common/eal_common_trace.c +43 -8
74 lines not on this page · raw message
lib/librte_eal/common/eal_thread.h +5 -0
@@ -25,6 +25,11 @@ __rte_noreturn void *eal_thread_loop(void *arg);*/ void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset); +/** +* Uninitialize per-lcore info for current thread. +*/ +void rte_thread_uninit (void ); +/** * Get the NUMA socket id from cpu id. * This function is private to EAL.
lib/librte_eal/common/eal_trace.h +1 -1
@@ -106,7 +106,7 @@ int trace_metadata_create(void);void trace_metadata_destroy (void );int trace_mkdir (void );int trace_epoch_time_save (void ); -void trace_mem_per_thread_free (void ); +void trace_mem_free (void );/* EAL interface */ int eal_trace_init (void );
lib/librte_eal/include/rte_trace_point.h +9 -0
@@ -230,6 +230,15 @@ __rte_trace_point_fp_is_enabled(void)__rte_experimental void __rte_trace_mem_per_thread_alloc(void); +/** +* @internal +* +* Free trace memory buffer per thread. +* +*/ +__rte_experimental +void __rte_trace_mem_per_thread_free(void); +/** * @internal *
lib/librte_eal/rte_eal_version.map +3 -0
@@ -393,6 +393,9 @@ EXPERIMENTAL { rte_trace_point_lookup; rte_trace_regexp; rte_trace_save; + + # added in 20.08 + __rte_trace_mem_per_thread_free; }; INTERNAL {
lib/librte_eal/windows/eal.c +5 -0
@@ -255,6 +255,11 @@ __rte_trace_mem_per_thread_alloc(void) { } +void +__rte_trace_mem_per_thread_free (void ) +{ +} +void __rte_trace_point_emit_field (size_t sz,const char *field,const char *type)
Signature · 1 line
2.23.0
PATCH v3 5/9 eal: move lcore role code
In reply to David MarchandFor consistency sake, move all lcore role code in the dedicated compilation unit / header.
--- lib/librte_eal/common/eal_common_lcore.c | 11 +++++++ lib/librte_eal/common/eal_common_thread.c | 11 ------- lib/librte_eal/include/rte_eal.h | 9 ------ lib/librte_eal/include/rte_lcore.h | 37 ++++++++++++++--------- 4 files changed, 34 insertions(+), 34 deletions(-)
lib/librte_eal/common/eal_common_lcore.c +11 -0
@@ -63,6 +63,17 @@ rte_eal_lcore_role(unsigned int lcore_id)return cfg->lcore_role[lcore_id]; } +int +rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role) +{ +struct rte_config *cfg =rte_eal_get_configuration (); + +if (lcore_id >=RTE_MAX_LCORE ) +return -EINVAL ; + +return cfg->lcore_role[lcore_id] == role; +} +int rte_lcore_is_enabled (unsigned int lcore_id) {struct rte_config *cfg =rte_eal_get_configuration ();
lib/librte_eal/common/eal_common_thread.c +0 -11
@@ -33,17 +33,6 @@ unsigned rte_socket_id(void)return RTE_PER_LCORE (_socket_id); } -int -rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role) -{ -struct rte_config *cfg =rte_eal_get_configuration (); - -if (lcore_id >=RTE_MAX_LCORE ) -return -EINVAL ; - -return cfg->lcore_role[lcore_id] == role; -} -static int eal_cpuset_socket_id (rte_cpuset_t *cpusetp) {
lib/librte_eal/include/rte_eal.h +0 -9
@@ -31,15 +31,6 @@ extern "C" {/* Maximum thread_name length. */ #define RTE_MAX_THREAD_NAME_LEN 16 -/** -* The lcore role (used in RTE or not). -*/ -enum rte_lcore_role_t { -ROLE_RTE , -ROLE_OFF , -ROLE_SERVICE , -}; -/** * The type of process in a linux, multi-process setup */
lib/librte_eal/include/rte_lcore.h +23 -14
@@ -24,6 +24,15 @@ extern "C" {RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ +/** +* The lcore role (used in RTE or not). +*/ +enum rte_lcore_role_t { +ROLE_RTE , +ROLE_OFF , +ROLE_SERVICE , +}; +/** * Get a lcore's role. *
@@ -34,6 +43,20 @@ RTE_DECLARE_PER_LCORE(unsigned, _lcore_id); /**< Per thread "lcore id". */*/ enum rte_lcore_role_t rte_eal_lcore_role (unsigned int lcore_id); +/** +* Test if the core supplied has a specific role +* +* @param lcore_id +* The identifier of the lcore, which MUST be between 0 and +* RTE_MAX_LCORE-1. +* @param role +* The role to be checked against. +* @return +* Boolean value: positive if test is true; otherwise returns 0. +*/ +int +rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role); +/** * Return the Application thread ID of the execution unit. *
@@ -283,20 +306,6 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); -/** -* Test if the core supplied has a specific role -* -* @param lcore_id -* The identifier of the lcore, which MUST be between 0 and -* RTE_MAX_LCORE-1. -* @param role -* The role to be checked against. -* @return -* Boolean value: positive if test is true; otherwise returns 0. -*/ -int -rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role); - #ifdef __cplusplus }#endif
Signature · 1 line
2.23.0
PATCH v3 6/9 eal: register non-EAL threads as lcores
In reply to David MarchandDPDK allows calling some part of its API from a non-EAL thread but this has some limitations.
OVS (and other applications) has its own thread management but still want to avoid such limitations by hacking RTE_PER_LCORE(_lcore_id) and faking EAL threads potentially unknown of some DPDK component.
Introduce a new API to register non-EAL thread and associate them to a free lcore with a new NON_EAL role.
This role denotes lcores that do not run DPDK mainloop and as such prevents use of rte_eal_wait_lcore() and consorts.
---
Changes since v1:
- moved cleanup on lcore role code in patch 5,
- added unit test,
- updated documentation,
- changed naming from "external thread" to "registered non-EAL thread"
--- MAINTAINERS | 1 + app/test/Makefile | 1 + app/test/autotest_data.py | 6 + app/test/meson.build | 2 + app/test/test_lcores.c | 139 ++++++++++++++++++ doc/guides/howto/debug_troubleshoot.rst | 5 +- .../prog_guide/env_abstraction_layer.rst | 22 +-- doc/guides/prog_guide/mempool_lib.rst | 2 +- lib/librte_eal/common/eal_common_lcore.c | 44 +++++- lib/librte_eal/common/eal_common_thread.c | 33 +++++ lib/librte_eal/common/eal_private.h | 18 +++ lib/librte_eal/include/rte_lcore.h | 18 ++- lib/librte_eal/rte_eal_version.map | 2 + lib/librte_mempool/rte_mempool.h | 11 +- 14 files changed, 282 insertions(+), 22 deletions(-) create mode 100644 app/test/test_lcores.c
MAINTAINERS +1 -0
@@ -183,6 +183,7 @@ F: app/test/test_debug.c F: app/test/test_eal* F: app/test/test_errno.c F: app/test/test_interrupts.c +F: app/test/test_lcores.c F: app/test/test_logs.c F: app/test/test_memcpy* F: app/test/test_per_lcore.c
app/test/Makefile +1 -0
@@ -97,6 +97,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_FLOW_CLASSIFY) += test_flow_classify.c endif SRCS-y += test_rwlock.c +SRCS-y += test_lcores.c SRCS-$(CONFIG_RTE_LIBRTE_STACK) += test_stack.c SRCS-$(CONFIG_RTE_LIBRTE_STACK) += test_stack_perf.c
app/test/autotest_data.py +6 -0
@@ -62,6 +62,12 @@ "Func": rwlock_autotest, "Report": None, }, + { + "Name": "Lcores autotest", + "Command": "lcores_autotest", + "Func": default_autotest, + "Report": None, + }, { "Name": "Logs autotest", "Command": "logs_autotest",
app/test/meson.build +2 -0
@@ -67,6 +67,7 @@ test_sources = files('commands.c', 'test_ipsec_perf.c', 'test_kni.c', 'test_kvargs.c', + 'test_lcores.c', 'test_logs.c', 'test_lpm.c', 'test_lpm6.c',
@@ -206,6 +207,7 @@ fast_tests = [ ['hash_autotest', true], ['interrupt_autotest', true], ['ipfrag_autotest', false], + ['lcores_autotest', true], ['logs_autotest', true], ['lpm_autotest', true], ['lpm6_autotest', true],
app/test/test_lcores.c new file +139 -0
139 lines not on this page · raw message
doc/guides/howto/debug_troubleshoot.rst +3 -2
@@ -307,8 +307,9 @@ Custom worker function :numref:`dtg_distributor_worker`. #. Configuration issue isolation - * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF and - SERVICE. Check performance functions are mapped to run on the cores. + * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF, + SERVICE and NON_EAL. Check performance functions are mapped to run on the + cores. * For high-performance execution logic ensure running it on correct NUMA and non-master core.
doc/guides/prog_guide/env_abstraction_layer.rst +13 -9
@@ -564,9 +564,13 @@ It's also compatible with the pattern of corelist('-l') option. non-EAL pthread support ~~~~~~~~~~~~~~~~~~~~~~~ -It is possible to use the DPDK execution context with any user pthread (aka. Non-EAL pthreads). -In a non-EAL pthread, the *_lcore_id* is always LCORE_ID_ANY which identifies that it is not an EAL thread with a valid, unique, *_lcore_id*. -Some libraries will use an alternative unique ID (e.g. TID), some will not be impacted at all, and some will work but with limitations (e.g. timer and mempool libraries). +It is possible to use the DPDK execution context with any user pthread (aka. non-EAL pthreads). +There are two kinds of non-EAL pthreads: + +- a registered non-EAL pthread with a valid *_lcore_id* that was successfully assigned by calling ``rte_thread_register()``, +- a non registered non-EAL pthread with a LCORE_ID_ANY, + +For non registered non-EAL pthread (with a LCORE_ID_ANY *_lcore_id*), some libraries will use an alternative unique ID (e.g. TID), some will not be impacted at all, and some will work but with limitations (e.g. timer and mempool libraries). All these impacts are mentioned in :ref:`known_issue_label` section.
@@ -613,9 +617,9 @@ Known Issues + rte_mempool The rte_mempool uses a per-lcore cache inside the mempool. - For non-EAL pthreads, ``rte_lcore_id()`` will not return a valid number. - So for now, when rte_mempool is used with non-EAL pthreads, the put/get operations will bypass the default mempool cache and there is a performance penalty because of this bypass. - Only user-owned external caches can be used in a non-EAL context in conjunction with ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()`` that accept an explicit cache parameter. + For unregistered non-EAL pthreads, ``rte_lcore_id()`` will not return a valid number. + So for now, when rte_mempool is used with unregistered non-EAL pthreads, the put/get operations will bypass the default mempool cache and there is a performance penalty because of this bypass. + Only user-owned external caches can be used in an unregistered non-EAL context in conjunction with ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()`` that accept an explicit cache parameter. + rte_ring
@@ -660,15 +664,15 @@ Known Issues + rte_timer - Running ``rte_timer_manage()`` on a non-EAL pthread is not allowed. However, resetting/stopping the timer from a non-EAL pthread is allowed. + Running ``rte_timer_manage()`` on an unregistered non-EAL pthread is not allowed. However, resetting/stopping the timer from a non-EAL pthread is allowed. + rte_log - In non-EAL pthreads, there is no per thread loglevel and logtype, global loglevels are used. + In unregistered non-EAL pthreads, there is no per thread loglevel and logtype, global loglevels are used. + misc - The debug statistics of rte_ring, rte_mempool and rte_timer are not supported in a non-EAL pthread. + The debug statistics of rte_ring, rte_mempool and rte_timer are not supported in an unregistered non-EAL pthread. cgroup control ~~~~~~~~~~~~~~
doc/guides/prog_guide/mempool_lib.rst +1 -1
@@ -103,7 +103,7 @@ The maximum size of the cache is static and is defined at compilation time (CONF Alternatively to the internal default per-lcore local cache, an application can create and manage external caches through the ``rte_mempool_cache_create()``, ``rte_mempool_cache_free()`` and ``rte_mempool_cache_flush()`` calls. These user-owned caches can be explicitly passed to ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()``. The ``rte_mempool_default_cache()`` call returns the default internal cache if any. -In contrast to the default caches, user-owned caches can be used by non-EAL threads too. +In contrast to the default caches, user-owned caches can be used by unregistered non-EAL threads too. Mempool Handlers ------------------------
lib/librte_eal/common/eal_common_lcore.c +40 -4
55 lines not on this page · raw message
lib/librte_eal/common/eal_common_thread.c +33 -0
@@ -236,3 +236,36 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_join (*thread,NULL );return -ret; } + +void +rte_thread_register (void ) +{ +unsigned int lcore_id; +rte_cpuset_t cpuset; + +/* EAL init flushes all lcores, we can't register before. */ +assert (internal_config.init_complete ==1 ); +if (pthread_getaffinity_np (pthread_self (),sizeof (cpuset), + &cpuset) !=0 ) +CPU_ZERO (&cpuset); + lcore_id =eal_lcore_non_eal_allocate (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ; +rte_thread_init (lcore_id, &cpuset); +if (lcore_id !=LCORE_ID_ANY ) +RTE_LOG (DEBUG ,EAL ,"Registered non-EAL thread as lcore %u.\n" , + lcore_id); +} + +void +rte_thread_unregister (void ) +{ +unsigned int lcore_id =rte_lcore_id (); + +if (lcore_id !=LCORE_ID_ANY ) +eal_lcore_non_eal_release (lcore_id); +rte_thread_uninit (); +if (lcore_id !=LCORE_ID_ANY ) +RTE_LOG (DEBUG ,EAL ,"Unregistered non-EAL thread (was lcore %u).\n" , + lcore_id); +}
lib/librte_eal/common/eal_private.h +18 -0
@@ -396,6 +396,24 @@ uint64_t get_tsc_freq(void);*/ uint64_t get_tsc_freq_arch (void ); +/** +* Allocate a free lcore to associate to a non-EAL thread. +* +* @return +* - the id of a lcore with role ROLE_NON_EAL on success. +* - RTE_MAX_LCORE if none was available. +*/ +unsigned int eal_lcore_non_eal_allocate (void ); + +/** +* Release the lcore used by a non-EAL thread. +* Counterpart of eal_lcore_non_eal_allocate(). +* +* @param lcore_id +* The lcore with role ROLE_NON_EAL to release. +*/ +void eal_lcore_non_eal_release (unsigned int lcore_id); +/** * Prepare physical memory mapping * i.e. hugepages on Linux and
lib/librte_eal/include/rte_lcore.h +17 -1
@@ -31,6 +31,7 @@ enum rte_lcore_role_t {ROLE_RTE ,ROLE_OFF ,ROLE_SERVICE , + ROLE_NON_EAL, };/**
@@ -67,7 +68,8 @@ rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role);* to run threads with lcore IDs 0, 1, 2 and 3 on physical core 10.. * * @return -* Logical core ID (in EAL thread) or LCORE_ID_ANY (in non-EAL thread) +* Logical core ID (in EAL thread or registered non-EAL thread) or +* LCORE_ID_ANY (in unregistered non-EAL thread) */ static inline unsigned rte_lcore_id (void )
@@ -279,6 +281,20 @@ int rte_thread_setname(pthread_t id, const char *name);__rte_experimental int rte_thread_getname(pthread_t id, char *name, size_t len); +/** +* Register current non-EAL thread as a lcore. +*/ +__rte_experimental +void +rte_thread_register (void ); + +/** +* Unregister current thread and release lcore if one was associated. +*/ +__rte_experimental +void +rte_thread_unregister (void ); +/** * Create a control thread. *
lib/librte_eal/rte_eal_version.map +2 -0
@@ -396,6 +396,8 @@ EXPERIMENTAL { # added in 20.08 __rte_trace_mem_per_thread_free; + rte_thread_register; + rte_thread_unregister; }; INTERNAL {
lib/librte_mempool/rte_mempool.h +6 -5
@@ -28,9 +28,9 @@* rte_mempool_get() or rte_mempool_put() are designed to be called from an EAL * thread due to the internal per-lcore cache. Due to the lack of caching, * rte_mempool_get() or rte_mempool_put() performance will suffer when called -* by non-EAL threads. Instead, non-EAL threads should call -* rte_mempool_generic_get() or rte_mempool_generic_put() with a user cache -* created with rte_mempool_cache_create(). +* by unregistered non-EAL threads. Instead, unregistered non-EAL threads +* should call rte_mempool_generic_get() or rte_mempool_generic_put() with a +* user cache created with rte_mempool_cache_create(). */ #include <stdio.h>
@@ -1233,7 +1233,7 @@ void rte_mempool_dump(FILE *f, struct rte_mempool *mp);/** * Create a user-owned mempool cache. * -* This can be used by non-EAL threads to enable caching when they +* This can be used by unregistered non-EAL threads to enable caching when they * interact with a mempool. * * @param size
@@ -1264,7 +1264,8 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache);* @param lcore_id * The logical core id. * @return -* A pointer to the mempool cache or NULL if disabled or non-EAL thread. +* A pointer to the mempool cache or NULL if disabled or unregistered non-EAL +* thread. */ static __rte_always_inline struct rte_mempool_cache *rte_mempool_default_cache (struct rte_mempool *mp,unsigned lcore_id)
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Hi David,
Quoted 26 lines
lib/librte_eal/common/eal_common_lcore.c +5
-4@@ -6,12 +6,13 @@#include <limits.h> #include <string.h> -#include <rte_errno.h> -#include <rte_log.h> -#include <rte_eal.h> -#include <rte_lcore.h> #include <rte_common.h> #include <rte_debug.h> +#include <rte_eal.h> +#include <rte_errno.h> +#include <rte_lcore.h> +#include <rte_log.h> +#include <rte_spinlock.h> #include "eal_private.h" #include "eal_thread.h" @@ -220,3 +221,38 @@ rte_socket_id_by_idx(unsigned int idx) }return config->numa_nodes[idx]; }
lib/librte_eal/common/eal_common_lcore.c rte_socket_id_by_idx(unsigned int idx) · line 233
Quoted 10 lines
lib/librte_eal/common/eal_common_lcore.c +10
-0+ +static rte_spinlock_t lcore_lock =RTE_SPINLOCK_INITIALIZER ; + +unsigned int +eal_lcore_non_eal_allocate (void ) +{ +struct rte_config *cfg =rte_eal_get_configuration (); +unsigned int lcore_id; + +rte_spinlock_lock (&lcore_lock);
I think it will break current DPDK MP modes.
The problem here - rte_config (and lcore_role[]) is in shared memory, while the lock is local.
Simplest way probably to move lcore_lock to rte_config.
Quoted 39 lines
lib/librte_eal/common/eal_common_lcore.c +25
-0+for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +if (cfg->lcore_role[lcore_id] !=ROLE_OFF ) +continue ; + cfg->lcore_role[lcore_id] =ROLE_NON_EAL ; + cfg->lcore_count++; +break ; + } +if (lcore_id ==RTE_MAX_LCORE ) +RTE_LOG (DEBUG ,EAL ,"No lcore available.\n" ); +rte_spinlock_unlock (&lcore_lock); +return lcore_id; +} + +void +eal_lcore_non_eal_release (unsigned int lcore_id) +{ +struct rte_config *cfg =rte_eal_get_configuration (); + +rte_spinlock_lock (&lcore_lock); +if (cfg->lcore_role[lcore_id] ==ROLE_NON_EAL ) { + cfg->lcore_role[lcore_id] =ROLE_OFF ; + cfg->lcore_count--; + } +rte_spinlock_unlock (&lcore_lock); +}lib/librte_eal/common/eal_common_thread.c +6
-0@@ -236,3 +236,36 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_join (*thread,NULL );return -ret; } + +void +rte_thread_register (void ) +{ +unsigned int lcore_id; +rte_cpuset_t cpuset;
lib/librte_eal/common/eal_common_thread.c rte_ctrl_thread_create(pthread_t *thread, const char *name, · line 254
Quoted 10 lines
lib/librte_eal/common/eal_common_thread.c +10
-0+ +/* EAL init flushes all lcores, we can't register before. */ +assert (internal_config.init_complete ==1 ); +if (pthread_getaffinity_np (pthread_self (),sizeof (cpuset), + &cpuset) !=0 ) +CPU_ZERO (&cpuset); + lcore_id =eal_lcore_non_eal_allocate (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ; +rte_thread_init (lcore_id, &cpuset);
So we just setting affinity to the same value, right?
Not a big deal, but might be easier to allow rte_thread_init() to accept cpuset==NULL (and just don't change thread affinity in that case)
Quoted 140 lines
lib/librte_eal/common/eal_common_thread.c +17
-0+if (lcore_id !=LCORE_ID_ANY ) +RTE_LOG (DEBUG ,EAL ,"Registered non-EAL thread as lcore %u.\n" , + lcore_id); +} + +void +rte_thread_unregister (void ) +{ +unsigned int lcore_id =rte_lcore_id (); + +if (lcore_id !=LCORE_ID_ANY ) +eal_lcore_non_eal_release (lcore_id); +rte_thread_uninit (); +if (lcore_id !=LCORE_ID_ANY ) +RTE_LOG (DEBUG ,EAL ,"Unregistered non-EAL thread (was lcore %u).\n" , + lcore_id); +}lib/librte_eal/common/eal_private.h +18
-0@@ -396,6 +396,24 @@ uint64_t get_tsc_freq(void);*/ uint64_t get_tsc_freq_arch (void ); +/** +* Allocate a free lcore to associate to a non-EAL thread. +* +* @return +* - the id of a lcore with role ROLE_NON_EAL on success. +* - RTE_MAX_LCORE if none was available. +*/ +unsigned int eal_lcore_non_eal_allocate (void ); + +/** +* Release the lcore used by a non-EAL thread. +* Counterpart of eal_lcore_non_eal_allocate(). +* +* @param lcore_id +* The lcore with role ROLE_NON_EAL to release. +*/ +void eal_lcore_non_eal_release (unsigned int lcore_id); +/** * Prepare physical memory mapping * i.e. hugepages on Linux and lib/librte_eal/include/rte_lcore.h +17
-1@@ -31,6 +31,7 @@ enum rte_lcore_role_t {ROLE_RTE ,ROLE_OFF ,ROLE_SERVICE , + ROLE_NON_EAL, };/** @@ -67,7 +68,8 @@ rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role);* to run threads with lcore IDs 0, 1, 2 and 3 on physical core 10.. * * @return -* Logical core ID (in EAL thread) or LCORE_ID_ANY (in non-EAL thread) +* Logical core ID (in EAL thread or registered non-EAL thread) or +* LCORE_ID_ANY (in unregistered non-EAL thread) */ static inline unsigned rte_lcore_id (void )@@ -279,6 +281,20 @@ int rte_thread_setname(pthread_t id, const char *name);__rte_experimental int rte_thread_getname(pthread_t id, char *name, size_t len); +/** +* Register current non-EAL thread as a lcore. +*/ +__rte_experimental +void +rte_thread_register (void ); + +/** +* Unregister current thread and release lcore if one was associated. +*/ +__rte_experimental +void +rte_thread_unregister (void ); +/** * Create a control thread. * lib/librte_eal/rte_eal_version.map +2
-0@@ -396,6 +396,8 @@ EXPERIMENTAL { # added in 20.08 __rte_trace_mem_per_thread_free; + rte_thread_register; + rte_thread_unregister; }; INTERNAL {lib/librte_mempool/rte_mempool.h +6
-6@@ -28,9 +28,9 @@* rte_mempool_get() or rte_mempool_put() are designed to be called from an EAL * thread due to the internal per-lcore cache. Due to the lack of caching, * rte_mempool_get() or rte_mempool_put() performance will suffer when called -* by non-EAL threads. Instead, non-EAL threads should call -* rte_mempool_generic_get() or rte_mempool_generic_put() with a user cache -* created with rte_mempool_cache_create(). +* by unregistered non-EAL threads. Instead, unregistered non-EAL threads +* should call rte_mempool_generic_get() or rte_mempool_generic_put() with a +* user cache created with rte_mempool_cache_create(). */ #include <stdio.h> @@ -1233,7 +1233,7 @@ void rte_mempool_dump(FILE *f, struct rte_mempool *mp);/** * Create a user-owned mempool cache. * -* This can be used by non-EAL threads to enable caching when they +* This can be used by unregistered non-EAL threads to enable caching when they * interact with a mempool. * * @param size @@ -1264,7 +1264,8 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache);* @param lcore_id * The logical core id. * @return -* A pointer to the mempool cache or NULL if disabled or non-EAL thread. +* A pointer to the mempool cache or NULL if disabled or unregistered non-EAL +* thread. */ static __rte_always_inline struct rte_mempool_cache *rte_mempool_default_cache (struct rte_mempool *mp,unsigned lcore_id) --2.23.0
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 37 lines
Hi David,
Quoted 33 lines
lib/librte_eal/common/eal_common_lcore.c +12
-4@@ -6,12 +6,13 @@#include <limits.h> #include <string.h> -#include <rte_errno.h> -#include <rte_log.h> -#include <rte_eal.h> -#include <rte_lcore.h> #include <rte_common.h> #include <rte_debug.h> +#include <rte_eal.h> +#include <rte_errno.h> +#include <rte_lcore.h> +#include <rte_log.h> +#include <rte_spinlock.h> #include "eal_private.h" #include "eal_thread.h" @@ -220,3 +221,38 @@ rte_socket_id_by_idx(unsigned int idx) }return config->numa_nodes[idx]; } + +static rte_spinlock_t lcore_lock =RTE_SPINLOCK_INITIALIZER ; + +unsigned int +eal_lcore_non_eal_allocate (void ) +{ +struct rte_config *cfg =rte_eal_get_configuration ();
Quoted 8 lines
lib/librte_eal/common/eal_common_lcore.c rte_socket_id_by_idx(unsigned int idx) · line 233
Quoted 3 lines
lib/librte_eal/common/eal_common_lcore.c +3
-0+unsigned int lcore_id; + +rte_spinlock_lock (&lcore_lock);I think it will break current DPDK MP modes.
The problem here -rte_config(and lcore_role[]) is in shared memory, while the lock is local.
Simplest way probably to movelcore_locktorte_config.
Actually sorry, I was wrong - rte_config is local.
So having lcore_lock local seems ok here.
Though then, I think another issue arises:
For MP case 2 processes might get the same lcore_id via this function. And, as I remember, rte_mempool cache is by default located in shared memory. So two threads might end-up racing for the same mempool cache slot. Same story probably about some other shared data that uses lcore_id as an index
Quoted 26 lines
Quoted 26 lines
lib/librte_eal/common/eal_common_lcore.c +25
-0+for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +if (cfg->lcore_role[lcore_id] !=ROLE_OFF ) +continue ; + cfg->lcore_role[lcore_id] =ROLE_NON_EAL ; + cfg->lcore_count++; +break ; + } +if (lcore_id ==RTE_MAX_LCORE ) +RTE_LOG (DEBUG ,EAL ,"No lcore available.\n" ); +rte_spinlock_unlock (&lcore_lock); +return lcore_id; +} + +void +eal_lcore_non_eal_release (unsigned int lcore_id) +{ +struct rte_config *cfg =rte_eal_get_configuration (); + +rte_spinlock_lock (&lcore_lock); +if (cfg->lcore_role[lcore_id] ==ROLE_NON_EAL ) { + cfg->lcore_role[lcore_id] =ROLE_OFF ; + cfg->lcore_count--; + } +rte_spinlock_unlock (&lcore_lock); +}
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
In reply to Ananyev, KonstantinHello Konstantin,
Quoted 15 lines · Konstantin
Quoted 15 lines
lib/librte_eal/common/eal_common_lcore.c +7
-0@@ -220,3 +221,38 @@ rte_socket_id_by_idx(unsigned int idx) }return config->numa_nodes[idx]; } + +static rte_spinlock_t lcore_lock =RTE_SPINLOCK_INITIALIZER ; + +unsigned int +eal_lcore_non_eal_allocate (void ) +{ +struct rte_config *cfg =rte_eal_get_configuration ();
Quoted 8 lines
lib/librte_eal/common/eal_common_lcore.c rte_socket_id_by_idx(unsigned int idx) · line 233
Quoted 3 lines
lib/librte_eal/common/eal_common_lcore.c +3
-0+unsigned int lcore_id; + +rte_spinlock_lock (&lcore_lock);I think it will break current DPDK MP modes.
The problem here -rte_config(and lcore_role[]) is in shared memory, while the lock is local.
Simplest way probably to movelcore_locktorte_config.
Even before this series, MP has no protection on lcore placing between primary and secondary processes.
Personally, I have no use for DPDK MP and marking MP as not supporting this new feature is tempting for a first phase.
If this is a strong requirement, I can look at it in a second phase. What do you think?
Quoted 46 lines
Quoted 46 lines
lib/librte_eal/common/eal_common_lcore.c +25
-0+for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +if (cfg->lcore_role[lcore_id] !=ROLE_OFF ) +continue ; + cfg->lcore_role[lcore_id] =ROLE_NON_EAL ; + cfg->lcore_count++; +break ; + } +if (lcore_id ==RTE_MAX_LCORE ) +RTE_LOG (DEBUG ,EAL ,"No lcore available.\n" ); +rte_spinlock_unlock (&lcore_lock); +return lcore_id; +} + +void +eal_lcore_non_eal_release (unsigned int lcore_id) +{ +struct rte_config *cfg =rte_eal_get_configuration (); + +rte_spinlock_lock (&lcore_lock); +if (cfg->lcore_role[lcore_id] ==ROLE_NON_EAL ) { + cfg->lcore_role[lcore_id] =ROLE_OFF ; + cfg->lcore_count--; + } +rte_spinlock_unlock (&lcore_lock); +}lib/librte_eal/common/eal_common_thread.c +12
-0@@ -236,3 +236,36 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_join (*thread,NULL );return -ret; } + +void +rte_thread_register (void ) +{ +unsigned int lcore_id; +rte_cpuset_t cpuset; + +/* EAL init flushes all lcores, we can't register before. */ +assert (internal_config.init_complete ==1 ); +if (pthread_getaffinity_np (pthread_self (),sizeof (cpuset), + &cpuset) !=0 ) +CPU_ZERO (&cpuset);
Quoted 8 lines
lib/librte_eal/common/eal_common_thread.c rte_ctrl_thread_create(pthread_t *thread, const char *name, · line 254
Quoted 4 lines
lib/librte_eal/common/eal_common_thread.c +4
-0+ lcore_id =eal_lcore_non_eal_allocate (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ; +rte_thread_init (lcore_id, &cpuset);So we just setting affinity to the same value, right?
Not a big deal, but might be easier to allowrte_thread_init()to accept cpuset==NULL (and just don't change thread affinity in that case)
rte_thread_init does not change the thread cpu affinity, it handles per thread (TLS included) variables initialization.
So do you mean accepting cpuset == NULL and do the getaffinity in this case? rte_thread_init is EAL private for now.
That saves us some code in this function, but we will call with a != NULL cpuset in all other EAL code.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 28 lines · David Marchand
Hello Konstantin,
Quoted 15 lines · Konstantin
Quoted 15 lines
lib/librte_eal/common/eal_common_lcore.c +7
-0@@ -220,3 +221,38 @@ rte_socket_id_by_idx(unsigned int idx) }return config->numa_nodes[idx]; } + +static rte_spinlock_t lcore_lock =RTE_SPINLOCK_INITIALIZER ; + +unsigned int +eal_lcore_non_eal_allocate (void ) +{ +struct rte_config *cfg =rte_eal_get_configuration ();Quoted 8 lines
lib/librte_eal/common/eal_common_lcore.c rte_socket_id_by_idx(unsigned int idx) · line 233
Quoted 3 lines
lib/librte_eal/common/eal_common_lcore.c +3
-0+unsigned int lcore_id; + +rte_spinlock_lock (&lcore_lock);I think it will break current DPDK MP modes.
The problem here -rte_config(and lcore_role[]) is in shared memory, while the lock is local.
Simplest way probably to movelcore_locktorte_config.
Quoted 7 lines
Even before this series, MP has no protection on lcore placing between primary and secondary processes.
Personally, I have no use for DPDK MP and marking MP as not supporting this new feature is tempting for a first phase.
If this is a strong requirement, I can look at it in a second phase. What do you think?
I think that is reasonable for a new feature. I suspect those wanting to dynamically manage their own threads probably do not care about multi-process mode.
However, this limitation probably needs to be clearly called out in the docs.
/Bruce
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 37 lines · Bruce Richardson
Quoted 28 lines · David Marchand
Hello Konstantin,
Quoted 15 lines · Konstantin
Quoted 15 lines
lib/librte_eal/common/eal_common_lcore.c +7
-0@@ -220,3 +221,38 @@ rte_socket_id_by_idx(unsigned int idx) }return config->numa_nodes[idx]; } + +static rte_spinlock_t lcore_lock =RTE_SPINLOCK_INITIALIZER ; + +unsigned int +eal_lcore_non_eal_allocate (void ) +{ +struct rte_config *cfg =rte_eal_get_configuration ();Quoted 8 lines
lib/librte_eal/common/eal_common_lcore.c rte_socket_id_by_idx(unsigned int idx) · line 233
Quoted 3 lines
lib/librte_eal/common/eal_common_lcore.c +3
-0+unsigned int lcore_id; + +rte_spinlock_lock (&lcore_lock);I think it will break current DPDK MP modes.
The problem here -rte_config(and lcore_role[]) is in shared memory, while the lock is local.
Simplest way probably to movelcore_locktorte_config.Quoted 7 lines
Even before this series, MP has no protection on lcore placing between primary and secondary processes.
Personally, I have no use for DPDK MP and marking MP as not supporting this new feature is tempting for a first phase.
If this is a strong requirement, I can look at it in a second phase. What do you think?
Quoted 6 lines
I think that is reasonable for a new feature. I suspect those wanting to dynamically manage their own threads probably do not care about multi-process mode.
However, this limitation probably needs to be clearly called out in the docs.
Again, *disclaimer* I am not a user of the MP feature. But I suppose users of such a feature are relying on DPDK init and threads management, and I would not expect them to use this new API.
I will add a note in rte_thread_register() doxygen.
But I wonder if adding some check when a secondary attaches would make sense... Like how we have a version check, I could "taint" the dpdk primary
process: a variable in shared memory could do the trick.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
In reply to David MarchandHi David,
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
lib/librte_eal/common/eal_common_lcore.c +7
-0@@ -220,3 +221,38 @@ rte_socket_id_by_idx(unsigned int idx) }return config->numa_nodes[idx]; } + +static rte_spinlock_t lcore_lock =RTE_SPINLOCK_INITIALIZER ; + +unsigned int +eal_lcore_non_eal_allocate (void ) +{ +struct rte_config *cfg =rte_eal_get_configuration ();Quoted 8 lines
lib/librte_eal/common/eal_common_lcore.c rte_socket_id_by_idx(unsigned int idx) · line 233
Quoted 3 lines
lib/librte_eal/common/eal_common_lcore.c +3
-0+unsigned int lcore_id; + +rte_spinlock_lock (&lcore_lock);I think it will break current DPDK MP modes.
The problem here -rte_config(and lcore_role[]) is in shared memory, while the lock is local.
Simplest way probably to movelcore_locktorte_config.
Quoted 2 lines
Even before this series, MP has no protection on lcore placing between primary and secondary processes.
Agree, it is not a new problem, it has been there for a while.
Though making lcore assignment dynamic will make it more noticeable and harder to avoid. With static only lcore distribution it is much easier to control things.
Quoted 4 lines
Personally, I have no use for DPDK MP and marking MP as not supporting this new feature is tempting for a first phase.
If this is a strong requirement, I can look at it in a second phase. What do you think?
In theory it is possible to mark this new API as not supported for MP.
At least for now. Though I think it is sort of temporal solution.
AFAIK, MP is used by customers, so sooner or later someone will hit that problem. Let say, we do have pdump app/library in our mainline.
As I can see - it will be affected when users will start using this new dynamic lcore API inside their apps.
Quoted 56 lines
Quoted 47 lines
Quoted 47 lines
lib/librte_eal/common/eal_common_lcore.c +25
-0+for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +if (cfg->lcore_role[lcore_id] !=ROLE_OFF ) +continue ; + cfg->lcore_role[lcore_id] =ROLE_NON_EAL ; + cfg->lcore_count++; +break ; + } +if (lcore_id ==RTE_MAX_LCORE ) +RTE_LOG (DEBUG ,EAL ,"No lcore available.\n" ); +rte_spinlock_unlock (&lcore_lock); +return lcore_id; +} + +void +eal_lcore_non_eal_release (unsigned int lcore_id) +{ +struct rte_config *cfg =rte_eal_get_configuration (); + +rte_spinlock_lock (&lcore_lock); +if (cfg->lcore_role[lcore_id] ==ROLE_NON_EAL ) { + cfg->lcore_role[lcore_id] =ROLE_OFF ; + cfg->lcore_count--; + } +rte_spinlock_unlock (&lcore_lock); +}lib/librte_eal/common/eal_common_thread.c +12
-0@@ -236,3 +236,36 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_join (*thread,NULL );return -ret; } + +void +rte_thread_register (void ) +{ +unsigned int lcore_id; +rte_cpuset_t cpuset; + +/* EAL init flushes all lcores, we can't register before. */ +assert (internal_config.init_complete ==1 ); +if (pthread_getaffinity_np (pthread_self (),sizeof (cpuset), + &cpuset) !=0 ) +CPU_ZERO (&cpuset);Quoted 8 lines
lib/librte_eal/common/eal_common_thread.c rte_ctrl_thread_create(pthread_t *thread, const char *name, · line 254
Quoted 4 lines
lib/librte_eal/common/eal_common_thread.c +4
-0+ lcore_id =eal_lcore_non_eal_allocate (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ; +rte_thread_init (lcore_id, &cpuset);So we just setting affinity to the same value, right?
Not a big deal, but might be easier to allowrte_thread_init()to accept cpuset==NULL (and just don't change thread affinity in that case)
Quoted 2 lines
rte_thread_initdoes not change the thread cpu affinity, it handles per thread (TLS included) variables initialization.
Right, didn't read the code properly.
Please scratch that comment.
Quoted 5 lines
So do you mean accepting cpuset == NULL and do the getaffinity in this case?
rte_thread_initis EAL private for now.
That saves us some code in this function, but we will call with a != NULL cpuset in all other EAL code.
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 7 lines · Konstantin
Quoted 2 lines
Even before this series, MP has no protection on lcore placing between primary and secondary processes.
Agree, it is not a new problem, it has been there for a while.
Though making lcore assignment dynamic will make it more noticeable and harder to avoid. With static only lcore distribution it is much easier to control things.
Quoted 8 lines
Quoted 4 lines
Personally, I have no use for DPDK MP and marking MP as not supporting this new feature is tempting for a first phase.
If this is a strong requirement, I can look at it in a second phase. What do you think?In theory it is possible to mark this new API as not supported for MP. At least for now. Though I think it is sort of temporal solution. AFAIK, MP is used by customers, so sooner or later someone will hit that problem.
I understand this argument.
But then we don't see those customers giving feedback.
Quoted 3 lines
Let say, we do have pdump app/library in our mainline.
As I can see - it will be affected when users will start using this new dynamic lcore API inside their apps.
Supporting lcore allocation in MP requires exchanges between primary/secondary processes like what we have for memory allocations. It will be quite a beast to get to work fine, while not even knowing if people actually want to use both.
For v4, I added a check to exclude MP and the new API.
I am still willing to help if people do care about using both features together.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 26 lines · David Marchand
Quoted 7 lines · Konstantin
Quoted 2 lines
Even before this series, MP has no protection on lcore placing between primary and secondary processes.
Agree, it is not a new problem, it has been there for a while.
Though making lcore assignment dynamic will make it more noticeable and harder to avoid. With static only lcore distribution it is much easier to control things.Quoted 8 lines
Quoted 4 lines
Personally, I have no use for DPDK MP and marking MP as not supporting this new feature is tempting for a first phase.
If this is a strong requirement, I can look at it in a second phase. What do you think?In theory it is possible to mark this new API as not supported for MP. At least for now. Though I think it is sort of temporal solution. AFAIK, MP is used by customers, so sooner or later someone will hit that problem.
I understand this argument.
But then we don't see those customers giving feedback.Quoted 3 lines
Let say, we do have pdump app/library in our mainline.
As I can see - it will be affected when users will start using this new dynamic lcore API inside their apps.
Quoted 7 lines
Supporting lcore allocation in MP requires exchanges between primary/secondary processes like what we have for memory allocations. It will be quite a beast to get to work fine, while not even knowing if people actually want to use both.
For v4, I added a check to exclude MP and the new API.
I am still willing to help if people do care about using both features together.
I wonder how much we could simplify DPDK generally if we had to enable a specific runtime flag to enable multi-process support and it was off by default. This would break proc_info I think, but maybe we could provide telemetry callbacks to provide the same data, but beyond that it would just allow us to know whether a DPDK app is actually using MP, or just running as a single process.
/Bruce
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
24/06/2020 11:56, Bruce Richardson:
Quoted 35 lines · David Marchand
Quoted 26 lines
Quoted 7 lines · Konstantin
Quoted 2 lines
Even before this series, MP has no protection on lcore placing between primary and secondary processes.
Agree, it is not a new problem, it has been there for a while.
Though making lcore assignment dynamic will make it more noticeable and harder to avoid. With static only lcore distribution it is much easier to control things.Quoted 8 lines
Quoted 4 lines
Personally, I have no use for DPDK MP and marking MP as not supporting this new feature is tempting for a first phase.
If this is a strong requirement, I can look at it in a second phase. What do you think?In theory it is possible to mark this new API as not supported for MP. At least for now. Though I think it is sort of temporal solution. AFAIK, MP is used by customers, so sooner or later someone will hit that problem.
I understand this argument.
But then we don't see those customers giving feedback.Quoted 3 lines
Let say, we do have pdump app/library in our mainline.
As I can see - it will be affected when users will start using this new dynamic lcore API inside their apps.Quoted 7 lines
Supporting lcore allocation in MP requires exchanges between primary/secondary processes like what we have for memory allocations. It will be quite a beast to get to work fine, while not even knowing if people actually want to use both.
For v4, I added a check to exclude MP and the new API.
I am still willing to help if people do care about using both features together.
Quoted 6 lines
I wonder how much we could simplify DPDK generally if we had to enable a specific runtime flag to enable multi-process support and it was off by default. This would break
proc_infoI think, but maybe we could provide telemetry callbacks to provide the same data, but beyond that it would just allow us to know whether a DPDK app is actually using MP, or just running as a single process.
Same thought here.
I like the idea of a "mode flag" when multi-process is in use. Should it be an user explicit flag or an automatic one?
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 44 lines
24/06/2020 11:56, Bruce Richardson:
Quoted 35 lines · David Marchand
Quoted 26 lines
Quoted 7 lines · Konstantin
Quoted 2 lines
Even before this series, MP has no protection on lcore placing between primary and secondary processes.
Agree, it is not a new problem, it has been there for a while.
Though making lcore assignment dynamic will make it more noticeable and harder to avoid. With static only lcore distribution it is much easier to control things.Quoted 8 lines
Quoted 4 lines
Personally, I have no use for DPDK MP and marking MP as not supporting this new feature is tempting for a first phase.
If this is a strong requirement, I can look at it in a second phase. What do you think?In theory it is possible to mark this new API as not supported for MP. At least for now. Though I think it is sort of temporal solution. AFAIK, MP is used by customers, so sooner or later someone will hit that problem.
I understand this argument.
But then we don't see those customers giving feedback.Quoted 3 lines
Let say, we do have pdump app/library in our mainline.
As I can see - it will be affected when users will start using this new dynamic lcore API inside their apps.Quoted 7 lines
Supporting lcore allocation in MP requires exchanges between primary/secondary processes like what we have for memory allocations. It will be quite a beast to get to work fine, while not even knowing if people actually want to use both.
For v4, I added a check to exclude MP and the new API.
I am still willing to help if people do care about using both features together.Quoted 6 lines
I wonder how much we could simplify DPDK generally if we had to enable a specific runtime flag to enable multi-process support and it was off by default. This would break
proc_infoI think, but maybe we could provide telemetry callbacks to provide the same data, but beyond that it would just allow us to know whether a DPDK app is actually using MP, or just running as a single process.
Quoted 3 lines
Same thought here.
I like the idea of a "mode flag" when multi-process is in use. Should it be an user explicit flag or an automatic one?
It is probably possible, but that would mean will need to start splitting core parts of DPDK code into two paths: standalone/MP, right? Wonder how much effort it would require in terms of code rework, testing, maintenance, etc. At first glance seems quite substantial.
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
In reply to David MarchandQuoted 34 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, June 24, 2020 10:24 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; [email protected]; Richardson, Bruce <[email protected]>; [email protected]; [email protected]; Stokes, Ian <[email protected]>; [email protected]; Thomas Monjalon <[email protected]>; Mcnamara, John <[email protected]>; Kovacevic, Marko <[email protected]>; Burakov, Anatoly <[email protected]>; Olivier Matz <[email protected]>; Andrew Rybchenko <[email protected]>; Neil Horman <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcoresQuoted 7 lines · Konstantin
Quoted 2 lines
Even before this series, MP has no protection on lcore placing between primary and secondary processes.
Agree, it is not a new problem, it has been there for a while.
Though making lcore assignment dynamic will make it more noticeable and harder to avoid. With static only lcore distribution it is much easier to control things.Quoted 8 lines
Quoted 4 lines
Personally, I have no use for DPDK MP and marking MP as not supporting this new feature is tempting for a first phase.
If this is a strong requirement, I can look at it in a second phase. What do you think?In theory it is possible to mark this new API as not supported for MP. At least for now. Though I think it is sort of temporal solution. AFAIK, MP is used by customers, so sooner or later someone will hit that problem.
I understand this argument.
But then we don't see those customers giving feedback.
Quoted 8 lines
Quoted 3 lines
Let say, we do have pdump app/library in our mainline.
As I can see - it will be affected when users will start using this new dynamic lcore API inside their apps.Supporting lcore allocation in MP requires exchanges between primary/secondary processes like what we have for memory allocations. It will be quite a beast to get to work fine, while not even knowing if people actually want to use both.
I don't think we need to re-implement RPC as we did for memory subsystem. One relatively simple approach - move lcore_role[] and related lock into shared memory (separate memzone or so).
I think it should help a lot and will solve majority of the problems. One limitation - init/fini callbacks can be static only.
As the drawback, it will introduce change in current behaviour:
secondary process with lcore-mask that intersects with master lcore-mask will fail to start.
Second approach - make lcore_id local process entity:
prohibit indexing by lcore_id in shared data structures.
Let say for mempool - make cache local (per process).
While that approach is probably more elegant and consistent, it would require more work and will cause ABI (maybe API also) breakage.
Quoted 1 line
For v4, I added a check to exclude MP and the new API.
Do you mean - make this new dynamic-lcore API return an error if callied from secondary process?
Quoted 1 line
I am still willing to help if people do care about using both features together.
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 5 lines · Konstantin
Quoted 4 lines
Supporting lcore allocation in MP requires exchanges between primary/secondary processes like what we have for memory allocations. It will be quite a beast to get to work fine, while not even knowing if people actually want to use both.
Quoted 13 lines
I don't think we need to re-implement RPC as we did for memory subsystem. One relatively simple approach - move lcore_role[] and related lock into shared memory (separate memzone or so).
I think it should help a lot and will solve majority of the problems. One limitation - init/fini callbacks can be static only.
As the drawback, it will introduce change in current behaviour:
secondary process with lcore-mask that intersects with master lcore-mask will fail to start.
Second approach - makelcore_idlocal process entity:
prohibit indexing bylcore_idin shared data structures.
Let say for mempool - make cache local (per process).
While that approach is probably more elegant and consistent, it would require more work and will cause ABI (maybe API also) breakage.
In all scenarii, this is quite some work.
Quoted 6 lines
Quoted 2 lines
For v4, I added a check to exclude MP and the new API.
Do you mean - make this new dynamic-lcore API return an error if callied from secondary process?
Yes, and prohibiting from attaching a secondary process if dynamic lcore API has been used in primary.
I intend to squash in patch 6:
https://github.com/david-marchand/dpdk/commit/e5861ee734bfe2e4dc23d9b919b0db2a32a58aee
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 29 lines
Quoted 5 lines · Konstantin
Quoted 4 lines
Supporting lcore allocation in MP requires exchanges between primary/secondary processes like what we have for memory allocations. It will be quite a beast to get to work fine, while not even knowing if people actually want to use both.
Quoted 13 lines
I don't think we need to re-implement RPC as we did for memory subsystem. One relatively simple approach - move lcore_role[] and related lock into shared memory (separate memzone or so).
I think it should help a lot and will solve majority of the problems. One limitation - init/fini callbacks can be static only.
As the drawback, it will introduce change in current behaviour:
secondary process with lcore-mask that intersects with master lcore-mask will fail to start.
Second approach - makelcore_idlocal process entity:
prohibit indexing bylcore_idin shared data structures.
Let say for mempool - make cache local (per process).
While that approach is probably more elegant and consistent, it would require more work and will cause ABI (maybe API also) breakage.In all scenarii, this is quite some work.
Quoted 3 lines
Quoted 2 lines
For v4, I added a check to exclude MP and the new API.
Quoted 8 lines
Quoted 3 lines
Do you mean - make this new dynamic-lcore API return an error if callied from secondary process?
Yes, and prohibiting from attaching a secondary process if dynamic lcore API has been used in primary.
I intend to squash in patch 6:
https://github.com/david-marchand/dpdk/commit/e5861ee734bfe2e4dc23d9b919b0db2a32a58aee
But secondary process can attach before lcore_register, so we'll have some sort of inconsistency in behaviour. If we really want to go ahead with such workaround -
probably better to introduce explicit EAL flag ( --single-process or so).
As Thomas and Bruce suggested, if I understood them properly.
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 10 lines · Konstantin
Quoted 8 lines
Quoted 3 lines
Do you mean - make this new dynamic-lcore API return an error if callied from secondary process?
Yes, and prohibiting from attaching a secondary process if dynamic lcore API has been used in primary.
I intend to squash in patch 6:
https://github.com/david-marchand/dpdk/commit/e5861ee734bfe2e4dc23d9b919b0db2a32a58aeeBut secondary process can attach before
lcore_register, so we'll have some sort of inconsistency in behaviour.
If the developer tries to use both features, he gets an ERROR log in the two init path.
So whatever the order at runtime, we inform the developer (who did not read/understand the rte_thread_register() documentation) that what he is doing is unsupported.
Quoted 3 lines
If we really want to go ahead with such workaround - probably better to introduce explicit EAL flag ( --single-process or so). As Thomas and Bruce suggested, if I understood them properly.
A EAL flag is a stable API from the start, as there is nothing describing how we can remove one.
So a new EAL flag for an experimental API/feature seems contradictory.
Going with a new features status API... I think it is beyond this series.
Thomas seems to suggest an automatic resolution when features conflict happens.. ?
I'll send the v4, let's discuss it there if you want. Thanks.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
26/06/2020 16:43, David Marchand:
Quoted 10 lines
Quoted 8 lines · Konstantin
Quoted 7 lines
Quoted 2 lines
Do you mean - make this new dynamic-lcore API return an error if callied from secondary process?
Yes, and prohibiting from attaching a secondary process if dynamic lcore API has been used in primary.
I intend to squash in patch 6:
https://github.com/david-marchand/dpdk/commit/e5861ee734bfe2e4dc23d9b919b0db2a32a58aee
Quoted 7 lines
Quoted 1 line
But secondary process can attach before
lcore_register, so we'll have some sort of inconsistency in behaviour.If the developer tries to use both features, he gets an ERROR log in the two init path.
So whatever the order at runtime, we inform the developer (who did not read/understand therte_thread_register()documentation) that what he is doing is unsupported.
I agree.
Before this patch, pinning a thread on a random core can trigger some issues.
After this patch, register an external thread will take care of logging errors in case of inconsistencies. So the user will know he is doing something not supported by the app.
It is an nice improvement.
Quoted 1 line
Quoted 1 line
If we really want to go ahead with such workaround -
It is not a workaround.
It is fixing some old issues and making clear what is really impossible.
Quoted 2 lines
Quoted 2 lines
probably better to introduce explicit EAL flag ( --single-process or so). As Thomas and Bruce suggested, if I understood them properly.
No I was thinking to maintain the tri-state information:
- secondary is possible
- secondary is attached
- secondary is forbidden
Asking the user to use an option to forbid attaching a secondary process is the same as telling him it is forbidden.
The error log is enough in my opinion.
Quoted 8 lines
A EAL flag is a stable API from the start, as there is nothing describing how we can remove one.
So a new EAL flag for an experimental API/feature seems contradictory.Going with a new features status API... I think it is beyond this series.
Thomas seems to suggest an automatic resolution when features conflict happens.. ?
I suggest allowing the maximum and raise an error when usage conflicts. It seems this is what you did in v4.
Quoted 1 line
I'll send the v4, let's discuss it there if you want.
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 20 lines
26/06/2020 16:43, David Marchand:
Quoted 10 lines
Quoted 8 lines · Konstantin
Quoted 7 lines
Quoted 2 lines
Do you mean - make this new dynamic-lcore API return an error if callied from secondary process?
Yes, and prohibiting from attaching a secondary process if dynamic lcore API has been used in primary.
I intend to squash in patch 6:
https://github.com/david-marchand/dpdk/commit/e5861ee734bfe2e4dc23d9b919b0db2a32a58aeeQuoted 7 lines
Quoted 1 line
But secondary process can attach before
lcore_register, so we'll have some sort of inconsistency in behaviour.If the developer tries to use both features, he gets an ERROR log in the two init path.
So whatever the order at runtime, we inform the developer (who did not read/understand therte_thread_register()documentation) that what he is doing is unsupported.
Quoted 7 lines
I agree.
Before this patch, pinning a thread on a random core can trigger some issues.
After this patch, register an external thread will take care of logging errors in case of inconsistencies. So the user will know he is doing something not supported by the app.
I understand that, and return a meaningful error is definitely better the silent crash or memory corruption.
The problem with that approach, as I said before, MP group behaviour becomes non-deterministic.
Quoted 7 lines
It is an nice improvement.
Quoted 1 line
Quoted 1 line
If we really want to go ahead with such workaround -
It is not a workaround.
It is fixing some old issues and making clear what is really impossible.
The root cause of the problem is in our MP model design decisions:
from one side we treat lcore_id as process local data, from other side in some shared data-structures we use lcore_id as an index.
I think to fix it properly we need either:
make lcore_id data shared or stop using lcore_id as an index for shared data. So from my perspective this approach is just one of possible workarounds. BTW, there is nothing wrong to have a workaround for the problem we are not ready to fix right now.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
probably better to introduce explicit EAL flag ( --single-process or so). As Thomas and Bruce suggested, if I understood them properly.
No I was thinking to maintain the tri-state information:
- secondary is possible
- secondary is attached
- secondary is forbidden
Ok, then I misunderstood you.
Quoted 2 lines
Asking the user to use an option to forbid attaching a secondary process is the same as telling him it is forbidden.
I don't think it is the same.
On a live and complex system user can't always predict will the primary proc use dynamic lcore and if it will at what particular moment.
Same for secondary process launching - user might never start it, might start it straight after the primary one,
or might be after several hours.
Quoted 1 line
The error log is enough in my opinion.
I think it is better than nothing, but probably not the best one. Apart from possible non-consistent behaviour, it is quite restrictive:
dynamic lcore_id wouldn't be available on any DPDK MP deployment. Which is a pity - I think it is a cool and useful feature.
What do you guys think about different approach:
introduce new optional EAL parameter to restrict lcore_id values available for the process.
#let say to start primary proc that can use lcore_id=[0-99] only:dpdk_primary --lcore-allow=0-99 ... --file-prefix=xz1
#to start secondary one for it with allowed lcore_id=[100-109]:dpdk_secondary --lcore-allow=100-109 ... --file-prefix=xz1 --proc-type=secondary
It is still a workaround, but that way we don't need to
add any new limitations for dynamic lcores and secondary process usage. Now it is up to user to decide would multiple-process use the same shared data and if so - split lcore_id space properly among them
(same as he has to do now with static lcores).
Quoted 14 lines
Quoted 8 lines
A EAL flag is a stable API from the start, as there is nothing describing how we can remove one.
So a new EAL flag for an experimental API/feature seems contradictory.Going with a new features status API... I think it is beyond this series.
Thomas seems to suggest an automatic resolution when features conflict happens.. ?
I suggest allowing the maximum and raise an error when usage conflicts. It seems this is what you did in v4.
Quoted 1 line
I'll send the v4, let's discuss it there if you want.
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 84 lines · Konstantin
Quoted 20 lines
26/06/2020 16:43, David Marchand:
Quoted 10 lines
Quoted 8 lines · Konstantin
Quoted 7 lines
Quoted 2 lines
Do you mean - make this new dynamic-lcore API return an error if callied from secondary process?
Yes, and prohibiting from attaching a secondary process if dynamic lcore API has been used in primary.
I intend to squash in patch 6:
https://github.com/david-marchand/dpdk/commit/e5861ee734bfe2e4dc23d9b919b0db2a32a58aeeQuoted 7 lines
Quoted 1 line
But secondary process can attach before
lcore_register, so we'll have some sort of inconsistency in behaviour.If the developer tries to use both features, he gets an ERROR log in the two init path.
So whatever the order at runtime, we inform the developer (who did not read/understand therte_thread_register()documentation) that what he is doing is unsupported.Quoted 7 lines
I agree.
Before this patch, pinning a thread on a random core can trigger some issues.
After this patch, register an external thread will take care of logging errors in case of inconsistencies. So the user will know he is doing something not supported by the app.I understand that, and return a meaningful error is definitely better the silent crash or memory corruption.
The problem with that approach, as I said before, MP group behaviour becomes non-deterministic.Quoted 7 lines
It is an nice improvement.
Quoted 1 line
Quoted 1 line
If we really want to go ahead with such workaround -
It is not a workaround.
It is fixing some old issues and making clear what is really impossible.The root cause of the problem is in our MP model design decisions:
from one side we treatlcore_idas process local data, from other side in some shared data-structures we uselcore_idas an index.
I think to fix it properly we need either:
makelcore_iddata shared or stop usinglcore_idas an index for shared data. So from my perspective this approach is just one of possible workarounds. BTW, there is nothing wrong to have a workaround for the problem we are not ready to fix right now.Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
probably better to introduce explicit EAL flag ( --single-process or so). As Thomas and Bruce suggested, if I understood them properly.
No I was thinking to maintain the tri-state information:
- secondary is possible
- secondary is attached
- secondary is forbiddenOk, then I misunderstood you.
Quoted 2 lines
Asking the user to use an option to forbid attaching a secondary process is the same as telling him it is forbidden.
I don't think it is the same.
On a live and complex system user can't always predict will the primary proc use dynamic lcore and if it will at what particular moment.
Same for secondary process launching - user might never start it, might start it straight after the primary one,
or might be after several hours.Quoted 1 line
The error log is enough in my opinion.
I think it is better than nothing, but probably not the best one. Apart from possible non-consistent behaviour, it is quite restrictive:
dynamiclcore_idwouldn't be available on any DPDK MP deployment. Which is a pity - I think it is a cool and useful feature.What do you guys think about different approach:
introduce new optional EAL parameter to restrictlcore_idvalues available for the process.#let say to start primary proc that can use lcore_id=[0-99] only:
dpdk_primary--lcore-allow=0-99 ... --file-prefix=xz1
Quoted 8 lines
#to start secondary one for it with allowed lcore_id=[100-109]:
dpdk_secondary--lcore-allow=100-109 ... --file-prefix=xz1 --proc-type=secondaryIt is still a workaround, but that way we don't need to
add any new limitations for dynamic lcores and secondary process usage. Now it is up to user to decide would multiple-process use the same shared data and if so - splitlcore_idspace properly among them
(same as he has to do now with static lcores).
A variant (more simple) of your approach could be to add "--proc-type=standalone" to explicitly disable MP and enable dynamic thread registration.
Quoted 15 lines
Quoted 14 lines
Quoted 8 lines
A EAL flag is a stable API from the start, as there is nothing describing how we can remove one.
So a new EAL flag for an experimental API/feature seems contradictory.Going with a new features status API... I think it is beyond this series.
Thomas seems to suggest an automatic resolution when features conflict happens.. ?
I suggest allowing the maximum and raise an error when usage conflicts. It seems this is what you did in v4.
Quoted 1 line
I'll send the v4, let's discuss it there if you want.
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
30/06/2020 14:44, Olivier Matz:
Quoted 22 lines · Konstantin
Quoted 12 lines
I think it is better than nothing, but probably not the best one. Apart from possible non-consistent behaviour, it is quite restrictive:
dynamiclcore_idwouldn't be available on any DPDK MP deployment. Which is a pity - I think it is a cool and useful feature.What do you guys think about different approach:
introduce new optional EAL parameter to restrictlcore_idvalues available for the process.#let say to start primary proc that can use lcore_id=[0-99] only:
dpdk_primary--lcore-allow=0-99 ... --file-prefix=xz1Quoted 8 lines
#to start secondary one for it with allowed lcore_id=[100-109]:
dpdk_secondary--lcore-allow=100-109 ... --file-prefix=xz1 --proc-type=secondaryIt is still a workaround, but that way we don't need to
add any new limitations for dynamic lcores and secondary process usage. Now it is up to user to decide would multiple-process use the same shared data and if so - splitlcore_idspace properly among them
(same as he has to do now with static lcores).
Quoted 3 lines
A variant (more simple) of your approach could be to add "--proc-type=standalone" to explicitly disable MP and enable dynamic thread registration.
I don't adding a restriction from user input is adding a feature. Konstantin wants to support multi-process with non-EAL threads, which is the opposite of your proposal, Olivier :-)
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
In reply to Olivier MatzQuoted 95 lines · Konstantin
Quoted 84 lines
Quoted 20 lines
26/06/2020 16:43, David Marchand:
Quoted 10 lines
Quoted 8 lines · Konstantin
Quoted 7 lines
Quoted 2 lines
Do you mean - make this new dynamic-lcore API return an error if callied from secondary process?
Yes, and prohibiting from attaching a secondary process if dynamic lcore API has been used in primary.
I intend to squash in patch 6:
https://github.com/david-marchand/dpdk/commit/e5861ee734bfe2e4dc23d9b919b0db2a32a58aeeQuoted 7 lines
Quoted 1 line
But secondary process can attach before
lcore_register, so we'll have some sort of inconsistency in behaviour.If the developer tries to use both features, he gets an ERROR log in the two init path.
So whatever the order at runtime, we inform the developer (who did not read/understand therte_thread_register()documentation) that what he is doing is unsupported.Quoted 7 lines
I agree.
Before this patch, pinning a thread on a random core can trigger some issues.
After this patch, register an external thread will take care of logging errors in case of inconsistencies. So the user will know he is doing something not supported by the app.I understand that, and return a meaningful error is definitely better the silent crash or memory corruption.
The problem with that approach, as I said before, MP group behaviour becomes non-deterministic.Quoted 7 lines
It is an nice improvement.
Quoted 1 line
Quoted 1 line
If we really want to go ahead with such workaround -
It is not a workaround.
It is fixing some old issues and making clear what is really impossible.The root cause of the problem is in our MP model design decisions:
from one side we treatlcore_idas process local data, from other side in some shared data-structures we uselcore_idas an index.
I think to fix it properly we need either:
makelcore_iddata shared or stop usinglcore_idas an index for shared data. So from my perspective this approach is just one of possible workarounds. BTW, there is nothing wrong to have a workaround for the problem we are not ready to fix right now.Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
probably better to introduce explicit EAL flag ( --single-process or so). As Thomas and Bruce suggested, if I understood them properly.
No I was thinking to maintain the tri-state information:
- secondary is possible
- secondary is attached
- secondary is forbiddenOk, then I misunderstood you.
Quoted 2 lines
Asking the user to use an option to forbid attaching a secondary process is the same as telling him it is forbidden.
I don't think it is the same.
On a live and complex system user can't always predict will the primary proc use dynamic lcore and if it will at what particular moment.
Same for secondary process launching - user might never start it, might start it straight after the primary one,
or might be after several hours.Quoted 1 line
The error log is enough in my opinion.
I think it is better than nothing, but probably not the best one. Apart from possible non-consistent behaviour, it is quite restrictive:
dynamiclcore_idwouldn't be available on any DPDK MP deployment. Which is a pity - I think it is a cool and useful feature.What do you guys think about different approach:
introduce new optional EAL parameter to restrictlcore_idvalues available for the process.#let say to start primary proc that can use lcore_id=[0-99] only:
dpdk_primary--lcore-allow=0-99 ... --file-prefix=xz1Quoted 8 lines
#to start secondary one for it with allowed lcore_id=[100-109]:
dpdk_secondary--lcore-allow=100-109 ... --file-prefix=xz1 --proc-type=secondaryIt is still a workaround, but that way we don't need to
add any new limitations for dynamic lcores and secondary process usage. Now it is up to user to decide would multiple-process use the same shared data and if so - splitlcore_idspace properly among them
(same as he has to do now with static lcores).
Quoted 4 lines
A variant (more simple) of your approach could be to add "--proc-type=standalone" to explicitly disable MP and enable dynamic thread registration.
For me it is a bit too restrictive, but yes it is a possible option,
and from my perspective - a better one then disabling secondary proc support on the fly. I tried to summarize different options under discussion in another mail of this thread. Please have a look.
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 9 lines
A EAL flag is a stable API from the start, as there is nothing describing how we can remove one.
So a new EAL flag for an experimental API/feature seems contradictory.Going with a new features status API... I think it is beyond this series.
Thomas seems to suggest an automatic resolution when features conflict happens.. ?
I suggest allowing the maximum and raise an error when usage conflicts. It seems this is what you did in v4.
Quoted 1 line
I'll send the v4, let's discuss it there if you want.
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
In reply to Ananyev, Konstantin30/06/2020 14:07, Ananyev, Konstantin:
Quoted 27 lines
Quoted 19 lines
26/06/2020 16:43, David Marchand:
Quoted 10 lines
Quoted 8 lines · Konstantin
Quoted 7 lines
Quoted 2 lines
Do you mean - make this new dynamic-lcore API return an error if callied from secondary process?
Yes, and prohibiting from attaching a secondary process if dynamic lcore API has been used in primary.
I intend to squash in patch 6:
https://github.com/david-marchand/dpdk/commit/e5861ee734bfe2e4dc23d9b919b0db2a32a58aeeQuoted 7 lines
Quoted 1 line
But secondary process can attach before
lcore_register, so we'll have some sort of inconsistency in behaviour.If the developer tries to use both features, he gets an ERROR log in the two init path.
So whatever the order at runtime, we inform the developer (who did not read/understand therte_thread_register()documentation) that what he is doing is unsupported.Quoted 7 lines
I agree.
Before this patch, pinning a thread on a random core can trigger some issues.
After this patch, register an external thread will take care of logging errors in case of inconsistencies. So the user will know he is doing something not supported by the app.
Quoted 4 lines
I understand that, and return a meaningful error is definitely better the silent crash or memory corruption.
The problem with that approach, as I said before, MP group behaviour becomes non-deterministic.
It was already non-deterministic before these patches.
Quoted 7 lines
Quoted 6 lines
It is an nice improvement.
Quoted 1 line
Quoted 1 line
If we really want to go ahead with such workaround -
It is not a workaround.
It is fixing some old issues and making clear what is really impossible.
Quoted 8 lines
The root cause of the problem is in our MP model design decisions:
from one side we treatlcore_idas process local data, from other side in some shared data-structures we uselcore_idas an index.
I think to fix it properly we need either:
makelcore_iddata shared or stop usinglcore_idas an index for shared data. So from my perspective this approach is just one of possible workarounds. BTW, there is nothing wrong to have a workaround for the problem we are not ready to fix right now.
I think you are trying to fix multi-process handling.
This patch is not about multi-process, it only highlight incompatibilities.
Quoted 13 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
probably better to introduce explicit EAL flag ( --single-process or so). As Thomas and Bruce suggested, if I understood them properly.
No I was thinking to maintain the tri-state information:
- secondary is possible
- secondary is attached
- secondary is forbiddenOk, then I misunderstood you.
Quoted 2 lines
Asking the user to use an option to forbid attaching a secondary process is the same as telling him it is forbidden.
Quoted 6 lines
I don't think it is the same.
On a live and complex system user can't always predict will the primary proc use dynamic lcore and if it will at what particular moment.
Same for secondary process launching - user might never start it, might start it straight after the primary one,
or might be after several hours.
I don't see the difference.
An app which register external threads is not compatible with multi-process. It needs to be clear.
If the user tries to do it anyway, there can be some error, OK.
Quoted 6 lines
Quoted 1 line
The error log is enough in my opinion.
I think it is better than nothing, but probably not the best one. Apart from possible non-consistent behaviour, it is quite restrictive:
dynamiclcore_idwouldn't be available on any DPDK MP deployment. Which is a pity - I think it is a cool and useful feature.
So you are asking to extend the feature.
Honestly, I'm not a fan of multi-process,
so I would not push any feature for it.
If we don't add any new option now, and restrict MP handling to error messages, it would not prevent from extending in future, right?
Quoted 7 lines
What do you guys think about different approach:
introduce new optional EAL parameter to restrictlcore_idvalues available for the process.#let say to start primary proc that can use lcore_id=[0-99] only:
dpdk_primary--lcore-allow=0-99 ... --file-prefix=xz1
Quoted 8 lines
#to start secondary one for it with allowed lcore_id=[100-109]:
dpdk_secondary--lcore-allow=100-109 ... --file-prefix=xz1 --proc-type=secondaryIt is still a workaround, but that way we don't need to
add any new limitations for dynamic lcores and secondary process usage. Now it is up to user to decide would multiple-process use the same shared data and if so - splitlcore_idspace properly among them
(same as he has to do now with static lcores).
Isn't it pushing too much to the user?
Quoted 13 lines
Quoted 13 lines
Quoted 8 lines
A EAL flag is a stable API from the start, as there is nothing describing how we can remove one.
So a new EAL flag for an experimental API/feature seems contradictory.Going with a new features status API... I think it is beyond this series.
Thomas seems to suggest an automatic resolution when features conflict happens.. ?
I suggest allowing the maximum and raise an error when usage conflicts. It seems this is what you did in v4.
Quoted 1 line
I'll send the v4, let's discuss it there if you want.
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 52 lines
30/06/2020 14:07, Ananyev, Konstantin:
Quoted 27 lines
Quoted 19 lines
26/06/2020 16:43, David Marchand:
Quoted 10 lines
Quoted 8 lines · Konstantin
Quoted 7 lines
Quoted 2 lines
Do you mean - make this new dynamic-lcore API return an error if callied from secondary process?
Yes, and prohibiting from attaching a secondary process if dynamic lcore API has been used in primary.
I intend to squash in patch 6:
https://github.com/david-marchand/dpdk/commit/e5861ee734bfe2e4dc23d9b919b0db2a32a58aeeQuoted 7 lines
Quoted 1 line
But secondary process can attach before
lcore_register, so we'll have some sort of inconsistency in behaviour.If the developer tries to use both features, he gets an ERROR log in the two init path.
So whatever the order at runtime, we inform the developer (who did not read/understand therte_thread_register()documentation) that what he is doing is unsupported.Quoted 7 lines
I agree.
Before this patch, pinning a thread on a random core can trigger some issues.
After this patch, register an external thread will take care of logging errors in case of inconsistencies. So the user will know he is doing something not supported by the app.Quoted 4 lines
I understand that, and return a meaningful error is definitely better the silent crash or memory corruption.
The problem with that approach, as I said before, MP group behaviour becomes non-deterministic.It was already non-deterministic before these patches.
Quoted 7 lines
Quoted 6 lines
It is an nice improvement.
Quoted 1 line
Quoted 1 line
If we really want to go ahead with such workaround -
It is not a workaround.
It is fixing some old issues and making clear what is really impossible.Quoted 8 lines
The root cause of the problem is in our MP model design decisions:
from one side we treatlcore_idas process local data, from other side in some shared data-structures we uselcore_idas an index.
I think to fix it properly we need either:
makelcore_iddata shared or stop usinglcore_idas an index for shared data. So from my perspective this approach is just one of possible workarounds. BTW, there is nothing wrong to have a workaround for the problem we are not ready to fix right now.
Quoted 2 lines
I think you are trying to fix multi-process handling.
This patch is not about multi-process, it only highlight incompatibilities.
Yes, the problem has been there for a while. David's patch just made it more visible.
We discussing different workarounds for the problem.
Quoted 20 lines
Quoted 13 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
probably better to introduce explicit EAL flag ( --single-process or so). As Thomas and Bruce suggested, if I understood them properly.
No I was thinking to maintain the tri-state information:
- secondary is possible
- secondary is attached
- secondary is forbiddenOk, then I misunderstood you.
Quoted 2 lines
Asking the user to use an option to forbid attaching a secondary process is the same as telling him it is forbidden.
Quoted 6 lines
I don't think it is the same.
On a live and complex system user can't always predict will the primary proc use dynamic lcore and if it will at what particular moment.
Same for secondary process launching - user might never start it, might start it straight after the primary one,
or might be after several hours.
Quoted 4 lines
I don't see the difference.
An app which register external threads is not compatible with multi-process. It needs to be clear.
If the user tries to do it anyway, there can be some error, OK.
Copying from other mail thread:
Imagine the situation - there is a primary proc (supposed to run forever) that does rte_thread_register/rte_thread_unregister during its lifetime. Plus from time to time user runs some secondary process to collect stats/debug the primary one (proc-info or so).
Now behaviour of such system will be non-deterministic:
In some runs primary proc will do rte_thread_register() first, and then secondary proc will be never able to attach.
In other cases - secondary will win the race, and then for primary eal_lcore_non_eal_allocate() will always fail.
Which means different behaviour between runs, varying performance, etc.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
The error log is enough in my opinion.
I think it is better than nothing, but probably not the best one. Apart from possible non-consistent behaviour, it is quite restrictive:
dynamiclcore_idwouldn't be available on any DPDK MP deployment. Which is a pity - I think it is a cool and useful feature.So you are asking to extend the feature.
I am asking for solution that would guarantee deterministic behaviour to the user. If dynamic lcores and MP support need to be mutually exclusive,
then there should be a clean way for the user to *always* enable
one and disable the other.
"--proc-type=standalone" will at least guarantee such consistent behaviour between runs:
secondary proc will always fail to attach and eal_lcore_non_eal_allocate() will always succeed (as long as there are free lcore_ids off-course).
Though I think even better would be not to make them mutually exclusive,
but instead let user to split lcore_id space accordingly.
Let me list the options currently under discussion:
a) New EAL parameter '--lcore-allow=...'
Explicit EAL parameter to enable dyn-lcore=Y Consistent behaviour between runs=Y DYN-lcores/MP-support are mutually exclusive=N
b) Extend '--proc-type' EAL parameter with new 'standalone' type Explicit EAL parameter to enable dyn-lcore =Y Consistent behaviour between runs=Y
Dyn lcores/MP-support are mutually exclusive=Y
c) dynamic allow/forbid dynamic-lcore/MP support Explicit EAL parameter=N
Consistent behaviour between runs=N Dyn lcores/MP-support are mutually exclusive=Y
My preference list (from top to bottom): a, b, c.
Quoted 2 lines
Honestly, I'm not a fan of multi-process,
so I would not push any feature for it.
Me too, but as we can't drop it, we probably have no choice but to live with it.
Quoted 4 lines
If we don't add any new option now, and restrict MP handling to error messages, it would not prevent from extending in future, right?
It shouldn't I think.
Though what is the urgency to push this feature without having an agreement first?
Quoted 11 lines
Quoted 11 lines
What do you guys think about different approach:
introduce new optional EAL parameter to restrictlcore_idvalues available for the process.#let say to start primary proc that can use lcore_id=[0-99] only:
dpdk_primary--lcore-allow=0-99 ... --file-prefix=xz1#to start secondary one for it with allowed lcore_id=[100-109]:
dpdk_secondary--lcore-allow=100-109 ... --file-prefix=xz1 --proc-type=secondary
Quoted 7 lines
Quoted 5 lines
It is still a workaround, but that way we don't need to
add any new limitations for dynamic lcores and secondary process usage. Now it is up to user to decide would multiple-process use the same shared data and if so - splitlcore_idspace properly among them
(same as he has to do now with static lcores).Isn't it pushing too much to the user?
User has to do the similar thing with static lcores right now.
Quoted 16 lines
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines
A EAL flag is a stable API from the start, as there is nothing describing how we can remove one.
So a new EAL flag for an experimental API/feature seems contradictory.Going with a new features status API... I think it is beyond this series.
Thomas seems to suggest an automatic resolution when features conflict happens.. ?
I suggest allowing the maximum and raise an error when usage conflicts. It seems this is what you did in v4.
Quoted 1 line
I'll send the v4, let's discuss it there if you want.
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 10 lines · Konstantin
Imagine the situation - there is a primary proc (supposed to run forever) that does rte_thread_register/rte_thread_unregister during its lifetime. Plus from time to time user runs some secondary process to collect stats/debug the primary one (proc-info or so).
Now behaviour of such system will be non-deterministic:
In some runs primary proc will dorte_thread_register()first, and then secondary proc will be never able to attach.
In other cases - secondary will win the race, and then for primaryeal_lcore_non_eal_allocate()will always fail.
Which means different behaviour between runs, varying performance, etc.
If the final users finally hit the situation you describe, it means that the multiprocess had been in use so far and was known to be in use (*hopefully*).
So is it not a problem of design/non-regression testing when integrating the new API in the first place?
Quoted 7 lines
Quoted 3 lines
If we don't add any new option now, and restrict MP handling to error messages, it would not prevent from extending in future, right?
It shouldn't I think.
Though what is the urgency to push this feature without having an agreement first?
I waited to see others' opinions (and pinged some OVS-DPDK people). I'd like an agreement too.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 15 lines
Quoted 10 lines · Konstantin
Imagine the situation - there is a primary proc (supposed to run forever) that does rte_thread_register/rte_thread_unregister during its lifetime. Plus from time to time user runs some secondary process to collect stats/debug the primary one (proc-info or so).
Now behaviour of such system will be non-deterministic:
In some runs primary proc will dorte_thread_register()first, and then secondary proc will be never able to attach.
In other cases - secondary will win the race, and then for primaryeal_lcore_non_eal_allocate()will always fail.
Which means different behaviour between runs, varying performance, etc.
Quoted 3 lines
If the final users finally hit the situation you describe, it means that the multiprocess had been in use so far and was known to be in use (*hopefully*).
Yes.
Quoted 2 lines
So is it not a problem of design/non-regression testing when integrating the new API in the first place?
Not sure I understand you here...
If you saying that for SP benchmarking/testing current approach is sufficient, then - yes it is.
Or are you saying it would be hard to create a test-case to reproduce such problematic scenario?
Quoted 15 lines
Quoted 8 lines
Quoted 4 lines
If we don't add any new option now, and restrict MP handling to error messages, it would not prevent from extending in future, right?
It shouldn't I think.
Though what is the urgency to push this feature without having an agreement first?I waited to see others' opinions (and pinged some OVS-DPDK people). I'd like an agreement too.
--
David Marchand
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 6 lines · Konstantin
Quoted 3 lines
If the final users finally hit the situation you describe, it means that the multiprocess had been in use so far and was known to be in use (*hopefully*).
Yes.
Quoted 8 lines
Quoted 2 lines
So is it not a problem of design/non-regression testing when integrating the new API in the first place?
Not sure I understand you here...
If you saying that for SP benchmarking/testing current approach is sufficient, then - yes it is.
Or are you saying it would be hard to create a test-case to reproduce such problematic scenario?
I am saying that getting to a problematic scenario that only the final users get, would be a failure in the development, documentation and validation of the application.
When the developer integrates this new API, the developer will read the API description.
- If the limitation on mp is understood and accepted, the application documentation will be updated to reflect this.
Users can then know mp is not available.
If the users still try to use it, it can be a support issue. The users will then report to support people who should be aware this is not supported (the documentation says so).
- If the application needs mp support because of X, Y reasons, the developer integrating the new API, should complain upstream that the new API requires mp support.
If the developer does not complain but still uses the API.. well too bad (or it falls through to the following point).
- The application needs mp support, the developer did not catch the warning in the API (the kids are home, hard to concentrate)... The new API will be used for datapath processing threads, so non regression perf tests will be run.
On the other hand, the application uses mp for X, Y reasons, so there will be associated test cases.
I can't tell for sure, but I find it hard to believe a validation team would never do tests that combine both.
Signature · 1 line
David Marchand
Thomas Monjalon
Acked-byRe: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
02/07/2020 15:06, David Marchand:
Quoted 37 lines
Quoted 6 lines · Konstantin
Quoted 3 lines
If the final users finally hit the situation you describe, it means that the multiprocess had been in use so far and was known to be in use (*hopefully*).
Yes.
Quoted 8 lines
Quoted 2 lines
So is it not a problem of design/non-regression testing when integrating the new API in the first place?
Not sure I understand you here...
If you saying that for SP benchmarking/testing current approach is sufficient, then - yes it is.
Or are you saying it would be hard to create a test-case to reproduce such problematic scenario?I am saying that getting to a problematic scenario that only the final users get, would be a failure in the development, documentation and validation of the application.
When the developer integrates this new API, the developer will read the API description.
- If the limitation on mp is understood and accepted, the application documentation will be updated to reflect this.
Users can then know mp is not available.
If the users still try to use it, it can be a support issue. The users will then report to support people who should be aware this is not supported (the documentation says so).- If the application needs mp support because of X, Y reasons, the developer integrating the new API, should complain upstream that the new API requires mp support.
If the developer does not complain but still uses the API.. well too bad (or it falls through to the following point).
Quoted 8 lines
- The application needs mp support, the developer did not catch the warning in the API (the kids are home, hard to concentrate)... The new API will be used for datapath processing threads, so non regression perf tests will be run.
On the other hand, the application uses mp for X, Y reasons, so there will be associated test cases.
I can't tell for sure, but I find it hard to believe a validation team would never do tests that combine both.
Please let's conclude.
The proposed API for thread registration does not support multi-process. This limitation is documented and there are some runtime checks. If this API is used in an application design, it should be clear that attaching a secondary process is forbidden.
If a user tries to attach a secondary process before the application registers a thread, then future thread registration will fail. If a user tries to attach a secondary process after a thread registration, then the secondary process will fail.
It means that depending on when the user *wrongly* attach a secondary process (despite the documented limitation of the application), the failure will happen in a different context.
I think it is OK.
The alternative is to introduce a new EAL flag or a new API to make sure the failure will happen when attaching a secondary process, even if no thread is registered yet.
I think adding such addition would be weird from user or API perspective.
Please note that accepting the thread registration API does not prevent from adding an EAL flag or a new API later.
That's why I vote for merging this series.
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
In reply to David MarchandQuoted 37 lines
Quoted 8 lines
Quoted 5 lines
If the final users finally hit the situation you describe, it means that the multiprocess had been in use so far and was known to be in use (*hopefully*).
Yes.
Quoted 8 lines
Quoted 2 lines
So is it not a problem of design/non-regression testing when integrating the new API in the first place?
Not sure I understand you here...
If you saying that for SP benchmarking/testing current approach is sufficient, then - yes it is.
Or are you saying it would be hard to create a test-case to reproduce such problematic scenario?I am saying that getting to a problematic scenario that only the final users get, would be a failure in the development, documentation and validation of the application.
When the developer integrates this new API, the developer will read the API description.
- If the limitation on mp is understood and accepted, the application documentation will be updated to reflect this.
Users can then know mp is not available.
If the users still try to use it, it can be a support issue. The users will then report to support people who should be aware this is not supported (the documentation says so).- If the application needs mp support because of X, Y reasons, the developer integrating the new API, should complain upstream that the new API requires mp support.
If the developer does not complain but still uses the API.. well too bad (or it falls through to the following point).
Quoted 8 lines
- The application needs mp support, the developer did not catch the warning in the API (the kids are home, hard to concentrate)... The new API will be used for datapath processing threads, so non regression perf tests will be run.
On the other hand, the application uses mp for X, Y reasons, so there will be associated test cases.
I can't tell for sure, but I find it hard to believe a validation team would never do tests that combine both.
If there is one team(/organization) doing everything:
development, deployment and support - then yes things
are more or less straightforward.
Though it is not always a case - one app(/lib) can be used in
dozen different deployments by various organizations and
development team might not always be aware about all
possible deployment and usage scenarios.
Let say, right now dpdk app/proc-info can be used with any
primary dpdk proc, even if it was designed as a standalone app.
With this patch, it will not be the case anymore.
It might be ok by itself, but what looks like a problem to me -
there is no a clear and easy way for the user to determine
when he can use proc-info on the given dpdk proc
without causing problems for this app, and when he can't.
Actually, sort of an opposite question -
what are the advantages of current approach (forbid MP support on the fly) over explicit start-up parameters (either --proc-type=single or --lcore-allow=...)? Why do you think it is a better one?
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 3 lines · Konstantin
what are the advantages of current approach (forbid MP support on the fly) over explicit start-up parameters (either --proc-type=single or --lcore-allow=...)? Why do you think it is a better one?
I don't want to perpetuate the "please carefully set your command line" habit. This feature is added through a C API, with documentation and flagged as experimental, it should be enough.
How about moving the mp disable in rte_thread_register() as a separate API? Then a developer must call rte_mp_disable() before attempting rte_thread_register().
That would be equivalent to --proc-type=single.
Why not convert lcore-allow into an API?
This would force us to put something in the init so that external users see how the application has been started and adjust the secondary commandline.
On the other hand, rte_mp_disable() is easy to do with my current v4 + I am running out of time for rc1.
We can still revisit this experimental API.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
Quoted 8 lines
Quoted 3 lines · Konstantin
what are the advantages of current approach (forbid MP support on the fly) over explicit start-up parameters (either --proc-type=single or --lcore-allow=...)? Why do you think it is a better one?
Quoted 8 lines
I don't want to perpetuate the "please carefully set your command line" habit. This feature is added through a C API, with documentation and flagged as experimental, it should be enough.
How about moving the mp disable in
rte_thread_register()as a separate API? Then a developer must callrte_mp_disable()before attemptingrte_thread_register().
That would be equivalent to --proc-type=single.
It wouldn't be exactly the same thing, but yes,
I agree user can call it as first thing after rte_eal_init() and it should help to prevent non-consistency in behaviour. I think it is a good compromise.
Quoted 5 lines
Why not convert lcore-allow into an API?
This would force us to put something in the init so that external users see how the application has been started and adjust the secondary commandline.
Not sure I understand you here...
If we'll make lcore-allow dynamic it is basically the same as moving lcore_role[] (or some similar structure) into shared memory. I am ok with that, but I thought you stated that it would require quite a lot of work.
Quoted 2 lines
On the other hand,
rte_mp_disable()is easy to do with my current v4 + I am running out of time for rc1.
Yes, as I said above such approach seems good enough to me (at least for now).
Konstantin
Re: [dpdk-dev] [PATCH v3 6/9] eal: register non-EAL threads as lcores
In reply to David MarchandQuoted 6 lines · David Marchand
DPDK allows calling some part of its API from a non-EAL thread but this has some limitations.
OVS (and other applications) has its own thread management but still want to avoid such limitations by hackingRTE_PER_LCORE(_lcore_id)and faking EAL threads potentially unknown of some DPDK component.
Quoted 6 lines
Introduce a new API to register non-EAL thread and associate them to a free lcore with a new
NON_EALrole.
This role denotes lcores that do not run DPDK mainloop and as such prevents use ofrte_eal_wait_lcore()and consorts.Signed-off-by David Marchand <[email protected]>
PATCH v3 7/9 eal: add lcore init callbacks
In reply to David MarchandDPDK components and applications can have their say when a new lcore is initialized. For this, they can register a callback for initializing and releasing their private data.
---
Changes since v2:
- added missing test,
- fixed rollback on lcore register,
Changes since v1:
- added unit test (since missing some coverage, for v3),
- preferred callback and removed mention of notification,
--- app/test/test_lcores.c | 230 +++++++++++++++++++++++ lib/librte_eal/common/eal_common_lcore.c | 138 +++++++++++++- lib/librte_eal/common/eal_private.h | 3 +- lib/librte_eal/include/rte_lcore.h | 68 +++++++ lib/librte_eal/rte_eal_version.map | 2 + 5 files changed, 435 insertions(+), 6 deletions(-)
app/test/test_lcores.c +230 -0
@@ -5,6 +5,7 @@#include <pthread.h> #include <string.h> +#include <rte_common.h> #include <rte_lcore.h> #include "test.h"
@@ -113,6 +114,229 @@ test_non_eal_lcores(unsigned int eal_threads_count)return ret; } +struct limit_lcore_context { +unsigned int init; +unsigned int max; +unsigned int uninit; +}; +static int +limit_lcores_init(unsigned int lcore_id __rte_unused, void *arg) +{ +struct limit_lcore_context *l = arg; + + l->init++; +if (l->init > l->max) +return -1 ; +return 0 ; +} +static void +limit_lcores_uninit(unsigned int lcore_id __rte_unused, void *arg) +{ +struct limit_lcore_context *l = arg; + + l->uninit++; +} + +static int +test_lcores_callback (unsigned int eal_threads_count) +{ +struct limit_lcore_context l; +void *handle; + +/* Refuse last lcore => callback register error. */ +memset (&l,0 ,sizeof (l)); + l.max = eal_threads_count -1 ; + handle =rte_lcore_callback_register ("limit" , limit_lcores_init, + limit_lcores_uninit, &l); +if (handle !=NULL ) { +printf ("lcore callback register should have failed\n" ); + goto error; + } +/* Refusal happens at the n th call to the init callback. +* Besides, n - 1 were accepted, so we expect as many uninit calls when +* the rollback happens. +*/ +if (l.init != eal_threads_count) { +printf ("lcore callback register failed but incorrect init calls, expected %u, got %u\n" , + eal_threads_count, l.init); + goto error; + } +if (l.uninit != eal_threads_count -1 ) { +printf ("lcore callback register failed but incorrect uninit calls, expected %u, got %u\n" , + eal_threads_count -1 , l.uninit); + goto error; + } + +/* Accept all lcore and unregister. */ +memset (&l,0 ,sizeof (l)); + l.max = eal_threads_count; + handle =rte_lcore_callback_register ("limit" , limit_lcores_init, + limit_lcores_uninit, &l); +if (handle ==NULL ) { +printf ("lcore callback register failed\n" ); + goto error; + } +if (l.uninit !=0 ) { +printf ("lcore callback register succeeded but incorrect uninit calls, expected 0, got %u\n" , + l.uninit); + goto error; + } +rte_lcore_callback_unregister (handle); + handle =NULL ; +if (l.init != eal_threads_count) { +printf ("lcore callback unregister done but incorrect init calls, expected %u, got %u\n" , + eal_threads_count, l.init); + goto error; + } +if (l.uninit != eal_threads_count) { +printf ("lcore callback unregister done but incorrect uninit calls, expected %u, got %u\n" , + eal_threads_count, l.uninit); + goto error; + } + +return 0 ; + +error: +if (handle !=NULL ) +rte_lcore_callback_unregister (handle); + +return -1 ; +} + +static int +test_non_eal_lcores_callback (unsigned int eal_threads_count) +{ +struct thread_context thread_contexts[2 ]; +unsigned int non_eal_threads_count; +struct limit_lcore_context l[2 ]; +unsigned int registered_count; +struct thread_context *t; +void *handle[2 ]; +unsigned int i; +int ret; + +memset (l,0 ,sizeof (l)); + handle[0 ] = handle[1 ] =NULL ; + non_eal_threads_count =0 ; + registered_count =0 ; + +/* This test requires two empty slots to be sure lcore init refusal is +* because of callback execution. +*/ +if (eal_threads_count +2 >=RTE_MAX_LCORE ) +return 0 ; + +/* Register two callbacks: +* - first one accepts any lcore, +* - second one accepts all EAL lcore + one more for the first non-EAL +* thread, then refuses the next lcore. +*/ + l[0 ].max =UINT_MAX ; + handle[0 ] =rte_lcore_callback_register ("no_limit" , limit_lcores_init, + limit_lcores_uninit, &l[0 ]); +if (handle[0 ] ==NULL ) { +printf ("lcore callback [0] register failed\n" ); + goto error; + } + l[1 ].max = eal_threads_count +1 ; + handle[1 ] =rte_lcore_callback_register ("limit" , limit_lcores_init, + limit_lcores_uninit, &l[1 ]); +if (handle[1 ] ==NULL ) { +printf ("lcore callback [1] register failed\n" ); + goto error; + } +if (l[0 ].init != eal_threads_count || l[1 ].init != eal_threads_count) { +printf ("lcore callbacks register succeeded but incorrect init calls, expected %u, %u, got %u, %u\n" , + eal_threads_count, eal_threads_count, + l[0 ].init, l[1 ].init); + goto error; + } +if (l[0 ].uninit !=0 || l[1 ].uninit !=0 ) { +printf ("lcore callbacks register succeeded but incorrect uninit calls, expected 0, 1, got %u, %u\n" , + l[0 ].uninit, l[1 ].uninit); + goto error; + } +/* First thread that expects a valid lcore id. */ + t = &thread_contexts[0 ]; + t->state =INIT ; + t->registered_count = ®istered_count; + t->lcore_id_any = false; +if (pthread_create (&t->id,NULL , thread_loop, t) !=0 ) + goto cleanup_threads; + non_eal_threads_count++; +while (__atomic_load_n (®istered_count, __ATOMIC_ACQUIRE) != + non_eal_threads_count) + ; +if (l[0 ].init != eal_threads_count +1 || + l[1 ].init != eal_threads_count +1 ) { +printf ("Incorrect init calls, expected %u, %u, got %u, %u\n" , + eal_threads_count +1 , eal_threads_count +1 , + l[0 ].init, l[1 ].init); + goto cleanup_threads; + } +if (l[0 ].uninit !=0 || l[1 ].uninit !=0 ) { +printf ("Incorrect uninit calls, expected 0, 0, got %u, %u\n" , + l[0 ].uninit, l[1 ].uninit); + goto cleanup_threads; + } +/* Second thread, that expects LCORE_ID_ANY because of init refusal. */ + t = &thread_contexts[1 ]; + t->state =INIT ; + t->registered_count = ®istered_count; + t->lcore_id_any = true; +if (pthread_create (&t->id,NULL , thread_loop, t) !=0 ) + goto cleanup_threads; + non_eal_threads_count++; +while (__atomic_load_n (®istered_count, __ATOMIC_ACQUIRE) != + non_eal_threads_count) + ; +if (l[0 ].init != eal_threads_count +2 || + l[1 ].init != eal_threads_count +2 ) { +printf ("Incorrect init calls, expected %u, %u, got %u, %u\n" , + eal_threads_count +2 , eal_threads_count +2 , + l[0 ].init, l[1 ].init); + goto cleanup_threads; + } +if (l[0 ].uninit !=1 || l[1 ].uninit !=0 ) { +printf ("Incorrect uninit calls, expected 1, 0, got %u, %u\n" , + l[0 ].uninit, l[1 ].uninit); + goto cleanup_threads; + } +/* Release all threads, and check their states. */ +__atomic_store_n (®istered_count,0 , __ATOMIC_RELEASE); + ret =0 ; +for (i =0 ; i < non_eal_threads_count; i++) { + t = &thread_contexts[i]; +pthread_join (t->id,NULL ); +if (t->state !=DONE ) + ret =-1 ; + } +if (ret <0 ) + goto error; +if (l[0 ].uninit !=2 || l[1 ].uninit !=1 ) { +printf ("Threads reported having successfully registered and unregistered, but incorrect uninit calls, expected 2, 1, got %u, %u\n" , + l[0 ].uninit, l[1 ].uninit); + goto error; + } +rte_lcore_callback_unregister (handle[0 ]); +rte_lcore_callback_unregister (handle[1 ]); +return 0 ; + +cleanup_threads: +/* Release all threads */ +__atomic_store_n (®istered_count,0 , __ATOMIC_RELEASE); +for (i =0 ; i < non_eal_threads_count; i++) { + t = &thread_contexts[i]; +pthread_join (t->id,NULL ); + } +error: +if (handle[1 ] !=NULL ) +rte_lcore_callback_unregister (handle[1 ]); +if (handle[0 ] !=NULL ) +rte_lcore_callback_unregister (handle[0 ]); +return -1 ; +} +static int test_lcores (void ) {
@@ -133,6 +357,12 @@ test_lcores(void)if (test_non_eal_lcores (eal_threads_count) <0 )return TEST_FAILED ; +if (test_lcores_callback (eal_threads_count) <0 ) +return TEST_FAILED ; + +if (test_non_eal_lcores_callback (eal_threads_count) <0 ) +return TEST_FAILED ; +return TEST_SUCCESS ; }
lib/librte_eal/common/eal_common_lcore.c +133 -5
163 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +2 -1
@@ -401,7 +401,8 @@ uint64_t get_tsc_freq_arch(void);* * @return * - the id of a lcore with role ROLE_NON_EAL on success. -* - RTE_MAX_LCORE if none was available. +* - RTE_MAX_LCORE if none was available or initializing was refused (see +* rte_lcore_callback_register). */ unsigned int eal_lcore_non_eal_allocate (void );
lib/librte_eal/include/rte_lcore.h +68 -0
74 lines not on this page · raw message
lib/librte_eal/rte_eal_version.map +2 -0
@@ -396,6 +396,8 @@ EXPERIMENTAL { # added in 20.08 __rte_trace_mem_per_thread_free; + rte_lcore_callback_register; + rte_lcore_callback_unregister; rte_thread_register; rte_thread_unregister; };
Signature · 1 line
2.23.0
PATCH v3 8/9 eal: add lcore iterators
In reply to David MarchandAdd a helper to iterate all lcores.
The iterator callback is read-only wrt the lcores list.
Implement a dump function on top of this for debugging.
---
Changes since v2:
- added rte_lcore_dump calls in unit test, for basic check,
Changes since v1:
- introduced lcore iterators and implemented rte_lcore_dump, this iterator mechanism can then be used outside of EAL,
--- app/test/test_lcores.c | 3 + lib/librte_eal/common/eal_common_lcore.c | 77 ++++++++++++++++++++--- lib/librte_eal/common/eal_common_thread.c | 16 +++-- lib/librte_eal/common/eal_thread.h | 13 +++- lib/librte_eal/freebsd/eal.c | 2 +- lib/librte_eal/freebsd/eal_thread.c | 2 +- lib/librte_eal/include/rte_lcore.h | 47 +++++++++++++- lib/librte_eal/linux/eal.c | 2 +- lib/librte_eal/linux/eal_thread.c | 2 +- lib/librte_eal/rte_eal_version.map | 2 + 10 files changed, 143 insertions(+), 23 deletions(-)
app/test/test_lcores.c +3 -0
@@ -302,6 +302,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count) l[0].uninit, l[1].uninit); goto cleanup_threads; } +rte_lcore_dump (stdout);/* Release all threads, and check their states. */ __atomic_store_n (®istered_count,0 , __ATOMIC_RELEASE); ret =0 ;
@@ -313,6 +314,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count) }if (ret <0 ) goto error; +rte_lcore_dump (stdout);if (l[0 ].uninit !=2 || l[1 ].uninit !=1 ) {printf ("Threads reported having successfully registered and unregistered, but incorrect uninit calls, expected 2, 1, got %u, %u\n" , l[0 ].uninit, l[1 ].uninit);
@@ -353,6 +355,7 @@ test_lcores(void) }printf ("EAL threads count: %u, RTE_MAX_LCORE=%u\n" , eal_threads_count,RTE_MAX_LCORE ); +rte_lcore_dump (stdout);if (test_non_eal_lcores (eal_threads_count) <0 )return TEST_FAILED ;
lib/librte_eal/common/eal_common_lcore.c +67 -10
135 lines not on this page · raw message
lib/librte_eal/common/eal_common_thread.c +11 -5
@@ -104,17 +104,14 @@ rte_thread_get_affinity(rte_cpuset_t *cpusetp) }int -eal_thread_dump_affinity (char *str,unsigned size) +eal_thread_dump_affinity (rte_cpuset_t *cpuset,char *str,unsigned int size) { -rte_cpuset_t cpuset;unsigned cpu;int ret;unsigned int out =0 ; -rte_thread_get_affinity (&cpuset); -for (cpu =0 ; cpu <CPU_SETSIZE ; cpu++) { -if (!CPU_ISSET (cpu, &cpuset)) +if (!CPU_ISSET (cpu, cpuset))continue ; ret = snprintf(str + out,
@@ -137,6 +134,15 @@ eal_thread_dump_affinity(char *str, unsigned size)return ret; } +int +eal_thread_dump_current_affinity (char *str,unsigned int size) +{ +rte_cpuset_t cpuset; + +rte_thread_get_affinity (&cpuset); +return eal_thread_dump_affinity (&cpuset, str, size); +} +void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) {
lib/librte_eal/common/eal_thread.h +11 -2
@@ -47,13 +47,15 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);#define RTE_CPU_AFFINITY_STR_LEN 256/** -* Dump the current pthread cpuset. +* Dump the cpuset as a human readable string. * This function is private to EAL. * * Note: * If the dump size is greater than the size of given buffer, * the string will be truncated and with '\0' at the end. * +* @param cpuset +* The CPU affinity object to dump. * @param str * The string buffer the cpuset will dump to. * @param size
@@ -62,6 +64,13 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);* 0 for success, -1 if truncation happens. */ int -eal_thread_dump_affinity (char *str,unsigned size); +eal_thread_dump_affinity (rte_cpuset_t *cpuset,char *str,unsigned int size); + +/** +* Dump the current thread cpuset. +* This is a wrapper on eal_thread_dump_affinity(). +*/ +int +eal_thread_dump_current_affinity (char *str,unsigned int size);#endif /* EAL_THREAD_H */
lib/librte_eal/freebsd/eal.c +1 -1
@@ -886,7 +886,7 @@ rte_eal_init(int argc, char **argv)rte_thread_init (rte_config.master_lcore, &lcore_config[rte_config.master_lcore].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset)); RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n", rte_config.master_lcore, thread_id, cpuset,
lib/librte_eal/freebsd/eal_thread.c +1 -1
@@ -92,7 +92,7 @@ eal_thread_loop(__rte_unused void *arg)rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , lcore_id, thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/include/rte_lcore.h +45 -2
59 lines not on this page · raw message
lib/librte_eal/linux/eal.c +1 -1
@@ -1214,7 +1214,7 @@ rte_eal_init(int argc, char **argv)rte_thread_init (rte_config.master_lcore, &lcore_config[rte_config.master_lcore].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , rte_config.master_lcore, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/linux/eal_thread.c +1 -1
@@ -92,7 +92,7 @@ eal_thread_loop(__rte_unused void *arg)rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/rte_eal_version.map +2 -0
@@ -398,6 +398,8 @@ EXPERIMENTAL { __rte_trace_mem_per_thread_free; rte_lcore_callback_register; rte_lcore_callback_unregister; + rte_lcore_dump; + rte_lcore_iterate; rte_thread_register; rte_thread_unregister; };
Signature · 1 line
2.23.0
PATCH v3 9/9 mempool/bucket: handle non-EAL lcores
In reply to David MarchandConvert to new lcore API to support non-EAL lcores.
--- drivers/mempool/bucket/rte_mempool_bucket.c | 131 ++++++++++++-------- 1 file changed, 82 insertions(+), 49 deletions(-)
drivers/mempool/bucket/rte_mempool_bucket.c +82 -49
@@ -55,6 +55,7 @@ struct bucket_data {struct rte_ring *shared_orphan_ring;struct rte_mempool *pool;unsigned int bucket_mem_size; +void *lcore_callback_handle; }; static struct bucket_stack *
@@ -345,6 +346,22 @@ bucket_dequeue_contig_blocks(struct rte_mempool *mp, void **first_obj_table,return 0 ; } +struct bucket_per_lcore_ctx { +const struct bucket_data *bd; +unsigned int count; +}; + +static int +count_per_lcore (unsigned int lcore_id,void *arg) +{ +struct bucket_per_lcore_ctx *ctx = arg; + + ctx->count += ctx->bd->obj_per_bucket * + ctx->bd->buckets[lcore_id]->top; + ctx->count +=rte_ring_count (ctx->bd->adoption_buffer_rings[lcore_id]); +return 0 ; +} + static void count_underfilled_buckets(struct rte_mempool *mp, void *opaque,
@@ -373,23 +390,66 @@ count_underfilled_buckets(struct rte_mempool *mp,static unsigned int bucket_get_count (const struct rte_mempool *mp) { -const struct bucket_data *bd = mp->pool_data; -unsigned int count = - bd->obj_per_bucket *rte_ring_count (bd->shared_bucket_ring) + -rte_ring_count (bd->shared_orphan_ring); -unsigned int i; +struct bucket_per_lcore_ctx ctx; -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (!rte_lcore_is_enabled (i)) -continue ; - count += bd->obj_per_bucket * bd->buckets[i]->top + -rte_ring_count (bd->adoption_buffer_rings[i]); - } + ctx.bd = mp->pool_data; + ctx.count = ctx.bd->obj_per_bucket * +rte_ring_count (ctx.bd->shared_bucket_ring); + ctx.count +=rte_ring_count (ctx.bd->shared_orphan_ring); +rte_lcore_iterate (count_per_lcore, &ctx);rte_mempool_mem_iter ((struct rte_mempool *)(uintptr_t )mp, - count_underfilled_buckets, &count); + count_underfilled_buckets, &ctx.count); + +return ctx.count; +} + +static int +bucket_init_per_lcore (unsigned int lcore_id,void *arg) +{ +char rg_name[RTE_RING_NAMESIZE ]; +struct bucket_data *bd = arg; +struct rte_mempool *mp; +int rg_flags; +int rc; + + mp = bd->pool; + bd->buckets[lcore_id] =bucket_stack_create (mp, + mp->size / bd->obj_per_bucket); +if (bd->buckets[lcore_id] ==NULL ) + goto error; + + rc =snprintf (rg_name,sizeof (rg_name),RTE_MEMPOOL_MZ_FORMAT ".a%u" , + mp->name, lcore_id); +if (rc <0 || rc >= (int )sizeof (rg_name)) + goto error; + + rg_flags =RING_F_SC_DEQ ; +if (mp->flags &MEMPOOL_F_SP_PUT ) + rg_flags |=RING_F_SP_ENQ ; +if (mp->flags &MEMPOOL_F_SC_GET ) + rg_flags |=RING_F_SC_DEQ ; + bd->adoption_buffer_rings[lcore_id] =rte_ring_create (rg_name, +rte_align32pow2 (mp->size +1 ), mp->socket_id, rg_flags); +if (bd->adoption_buffer_rings[lcore_id] ==NULL ) + goto error; -return count; +return 0 ; +error: +rte_free (bd->buckets[lcore_id]); + bd->buckets[lcore_id] =NULL ; +return -1 ; +} + +static void +bucket_uninit_per_lcore (unsigned int lcore_id,void *arg) +{ +struct bucket_data *bd = arg; + +rte_ring_free (bd->adoption_buffer_rings[lcore_id]); + bd->adoption_buffer_rings[lcore_id] =NULL ; +rte_free (bd->buckets[lcore_id]); + bd->buckets[lcore_id] =NULL ; } static int
@@ -399,7 +459,6 @@ bucket_alloc(struct rte_mempool *mp)int rc =0 ;char rg_name[RTE_RING_NAMESIZE ];struct bucket_data *bd; -unsigned int i;unsigned int bucket_header_size;size_t pg_sz;
@@ -429,36 +488,17 @@ bucket_alloc(struct rte_mempool *mp)/* eventually this should be a tunable parameter */ bd->bucket_stack_thresh = (mp->size / bd->obj_per_bucket) *4 /3 ; + bd->lcore_callback_handle =rte_lcore_callback_register ("bucket" , + bucket_init_per_lcore, bucket_uninit_per_lcore, bd); +if (bd->lcore_callback_handle ==NULL ) { + rc = -ENOMEM ; + goto no_mem_for_stacks; + } +if (mp->flags &MEMPOOL_F_SP_PUT ) rg_flags |=RING_F_SP_ENQ ;if (mp->flags &MEMPOOL_F_SC_GET ) rg_flags |=RING_F_SC_DEQ ; - -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (!rte_lcore_is_enabled (i)) -continue ; - bd->buckets[i] = -bucket_stack_create (mp, mp->size / bd->obj_per_bucket); -if (bd->buckets[i] ==NULL ) { - rc = -ENOMEM ; - goto no_mem_for_stacks; - } - rc =snprintf (rg_name,sizeof (rg_name), -RTE_MEMPOOL_MZ_FORMAT ".a%u" , mp->name, i); -if (rc <0 || rc >= (int )sizeof (rg_name)) { - rc = -ENAMETOOLONG ; - goto no_mem_for_stacks; - } - bd->adoption_buffer_rings[i] = -rte_ring_create (rg_name,rte_align32pow2 (mp->size +1 ), - mp->socket_id, - rg_flags |RING_F_SC_DEQ ); -if (bd->adoption_buffer_rings[i] ==NULL ) { - rc = -rte_errno; - goto no_mem_for_stacks; - } - } - rc =snprintf (rg_name,sizeof (rg_name),RTE_MEMPOOL_MZ_FORMAT ".0" , mp->name);if (rc <0 || rc >= (int )sizeof (rg_name)) {
@@ -498,11 +538,8 @@ bucket_alloc(struct rte_mempool *mp)rte_ring_free (bd->shared_orphan_ring); cannot_create_shared_orphan_ring: invalid_shared_orphan_ring: +rte_lcore_callback_unregister (bd->lcore_callback_handle); no_mem_for_stacks: -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -rte_free (bd->buckets[i]); -rte_ring_free (bd->adoption_buffer_rings[i]); - }rte_free (bd); no_mem_for_data: rte_errno = -rc;
@@ -512,16 +549,12 @@ bucket_alloc(struct rte_mempool *mp)static void bucket_free (struct rte_mempool *mp) { -unsigned int i;struct bucket_data *bd = mp->pool_data;if (bd ==NULL )return ; -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -rte_free (bd->buckets[i]); -rte_ring_free (bd->adoption_buffer_rings[i]); - } +rte_lcore_callback_unregister (bd->lcore_callback_handle);rte_ring_free (bd->shared_orphan_ring);rte_ring_free (bd->shared_bucket_ring);
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v3 9/9] mempool/bucket: handle non-EAL lcores
Quoted 20 lines · David Marchand
Convert to new lcore API to support non-EAL lcores.
Signed-off-by David Marchand <[email protected]>--- drivers/mempool/bucket/rte_mempool_bucket.c | 131 ++++++++++++-------- 1 file changed, 82 insertions(+), 49 deletions(-)drivers/mempool/bucket/rte_mempool_bucket.c +1
-0@@ -55,6 +55,7 @@ struct bucket_data {struct rte_ring *shared_orphan_ring;struct rte_mempool *pool;unsigned int bucket_mem_size; +void *lcore_callback_handle; }; static struct bucket_stack *
drivers/mempool/bucket/rte_mempool_bucket.c bucket_dequeue_contig_blocks(struct rte_mempool *mp, void **first_obj_table, · line 349
Quoted 4 lines
drivers/mempool/bucket/rte_mempool_bucket.c +1
-0@@ -345,6 +346,22 @@ bucket_dequeue_contig_blocks(struct rte_mempool *mp, void **first_obj_table,return 0 ; } +struct bucket_per_lcore_ctx {
The structure is not used in per-lcore init and uninit functions. So, it is better to add _count to make it count specified. I.e. bucket_count_per_lcore_ctx.
Quoted 19 lines
drivers/mempool/bucket/rte_mempool_bucket.c +15
-0+const struct bucket_data *bd; +unsigned int count; +}; + +static int +count_per_lcore (unsigned int lcore_id,void *arg) +{ +struct bucket_per_lcore_ctx *ctx = arg; + + ctx->count += ctx->bd->obj_per_bucket * + ctx->bd->buckets[lcore_id]->top; + ctx->count +=rte_ring_count (ctx->bd->adoption_buffer_rings[lcore_id]); +return 0 ; +} + static void count_underfilled_buckets(struct rte_mempool *mp, void *opaque,
drivers/mempool/bucket/rte_mempool_bucket.c count_underfilled_buckets(struct rte_mempool *mp, · line 393
Quoted 9 lines
drivers/mempool/bucket/rte_mempool_bucket.c +1
-5@@ -373,23 +390,66 @@ count_underfilled_buckets(struct rte_mempool *mp,static unsigned int bucket_get_count (const struct rte_mempool *mp) { -const struct bucket_data *bd = mp->pool_data; -unsigned int count = - bd->obj_per_bucket *rte_ring_count (bd->shared_bucket_ring) + -rte_ring_count (bd->shared_orphan_ring); -unsigned int i; +struct bucket_per_lcore_ctx ctx;
Just a nit, but I think that ctx is too generic. (some time ago bucket_data bd was ctx in fact :) ) May be bplc? Up to you.
Quoted 12 lines
drivers/mempool/bucket/rte_mempool_bucket.c +4
-6-for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (!rte_lcore_is_enabled (i)) -continue ; - count += bd->obj_per_bucket * bd->buckets[i]->top + -rte_ring_count (bd->adoption_buffer_rings[i]); - } + ctx.bd = mp->pool_data; + ctx.count = ctx.bd->obj_per_bucket * +rte_ring_count (ctx.bd->shared_bucket_ring); + ctx.count +=rte_ring_count (ctx.bd->shared_orphan_ring);
drivers/mempool/bucket/rte_mempool_bucket.c count_underfilled_buckets(struct rte_mempool *mp, · line 408
Quoted 10 lines
drivers/mempool/bucket/rte_mempool_bucket.c +8
-1+rte_lcore_iterate (count_per_lcore, &ctx);rte_mempool_mem_iter ((struct rte_mempool *)(uintptr_t )mp, - count_underfilled_buckets, &count); + count_underfilled_buckets, &ctx.count); + +return ctx.count; +} + +static int +bucket_init_per_lcore (unsigned int lcore_id,void *arg)
It should be no bucket_ prefix here, or it should be bucket_ prefix above in count_per_lcore.
Quoted 13 lines
drivers/mempool/bucket/rte_mempool_bucket.c +13
-0+{ +char rg_name[RTE_RING_NAMESIZE ]; +struct bucket_data *bd = arg; +struct rte_mempool *mp; +int rg_flags; +int rc; + + mp = bd->pool; + bd->buckets[lcore_id] =bucket_stack_create (mp, + mp->size / bd->obj_per_bucket); +if (bd->buckets[lcore_id] ==NULL ) + goto error; +
drivers/mempool/bucket/rte_mempool_bucket.c count_underfilled_buckets(struct rte_mempool *mp, · line 431
Quoted 10 lines
drivers/mempool/bucket/rte_mempool_bucket.c +10
-0+ rc =snprintf (rg_name,sizeof (rg_name),RTE_MEMPOOL_MZ_FORMAT ".a%u" , + mp->name, lcore_id); +if (rc <0 || rc >= (int )sizeof (rg_name)) + goto error; + + rg_flags =RING_F_SC_DEQ ; +if (mp->flags &MEMPOOL_F_SP_PUT ) + rg_flags |=RING_F_SP_ENQ ; +if (mp->flags &MEMPOOL_F_SC_GET ) + rg_flags |=RING_F_SC_DEQ ;
There is not point to have two above lines here, since RING_F_SC_DEQ is always set.
drivers/mempool/bucket/rte_mempool_bucket.c count_underfilled_buckets(struct rte_mempool *mp, · line 441
Quoted 11 lines
drivers/mempool/bucket/rte_mempool_bucket.c +9
-1+ bd->adoption_buffer_rings[lcore_id] =rte_ring_create (rg_name, +rte_align32pow2 (mp->size +1 ), mp->socket_id, rg_flags); +if (bd->adoption_buffer_rings[lcore_id] ==NULL ) + goto error; -return count; +return 0 ; +error: +rte_free (bd->buckets[lcore_id]); + bd->buckets[lcore_id] =NULL ; +return -1 ;
Why does the API collapse all negative errnos into -1? (I don't think it is critical, just want to know why).
drivers/mempool/bucket/rte_mempool_bucket.c count_underfilled_buckets(struct rte_mempool *mp, · line 445
Quoted 4 lines
drivers/mempool/bucket/rte_mempool_bucket.c +4
-0+} + +static void +bucket_uninit_per_lcore (unsigned int lcore_id,void *arg)
Same note about bucket_ prefix.
Re: [dpdk-dev] [PATCH v3 9/9] mempool/bucket: handle non-EAL lcores
Quoted 25 lines · Andrew Rybchenko
Quoted 23 lines · David Marchand
Convert to new lcore API to support non-EAL lcores.
Signed-off-by David Marchand <[email protected]>--- drivers/mempool/bucket/rte_mempool_bucket.c | 131 ++++++++++++-------- 1 file changed, 82 insertions(+), 49 deletions(-)drivers/mempool/bucket/rte_mempool_bucket.c +1
-0@@ -55,6 +55,7 @@ struct bucket_data {struct rte_ring *shared_orphan_ring;struct rte_mempool *pool;unsigned int bucket_mem_size; +void *lcore_callback_handle; }; static struct bucket_stack *@@ -345,6 +346,22 @@ bucket_dequeue_contig_blocks(struct rte_mempool *mp, void **first_obj_table,return 0 ; }
Quoted 5 lines
drivers/mempool/bucket/rte_mempool_bucket.c bucket_dequeue_contig_blocks(struct rte_mempool *mp, void **first_obj_table, · line 349
Quoted 1 line
drivers/mempool/bucket/rte_mempool_bucket.c +1
-0+struct bucket_per_lcore_ctx {The structure is not used in per-lcore init and uninit functions. So, it is better to add
_countto make it count specified. I.e.bucket_count_per_lcore_ctx.
Yes, and this aligns with its only user being renamed from count_per_lcore to bucket_count_per_lcore.
Quoted 25 lines
Quoted 25 lines
drivers/mempool/bucket/rte_mempool_bucket.c +15
-2+const struct bucket_data *bd; +unsigned int count; +}; + +static int +count_per_lcore (unsigned int lcore_id,void *arg) +{ +struct bucket_per_lcore_ctx *ctx = arg; + + ctx->count += ctx->bd->obj_per_bucket * + ctx->bd->buckets[lcore_id]->top; + ctx->count +=rte_ring_count (ctx->bd->adoption_buffer_rings[lcore_id]); +return 0 ; +} + static void count_underfilled_buckets(struct rte_mempool *mp, void *opaque,@@ -373,23 +390,66 @@ count_underfilled_buckets(struct rte_mempool *mp,static unsigned int bucket_get_count (const struct rte_mempool *mp) { -const struct bucket_data *bd = mp->pool_data; - unsigned int count =
Quoted 8 lines
drivers/mempool/bucket/rte_mempool_bucket.c count_underfilled_buckets(struct rte_mempool *mp, · line 393
Quoted 4 lines
drivers/mempool/bucket/rte_mempool_bucket.c +1
-3- bd->obj_per_bucket *rte_ring_count (bd->shared_bucket_ring) + -rte_ring_count (bd->shared_orphan_ring); -unsigned int i; +struct bucket_per_lcore_ctx ctx;Just a nit, but I think that ctx is too generic. (some time ago
bucket_databd was ctx in fact :) ) May be bplc? Up to you.
Ack.
Quoted 13 lines
Quoted 13 lines
drivers/mempool/bucket/rte_mempool_bucket.c +4
-6-for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (!rte_lcore_is_enabled (i)) -continue ; - count += bd->obj_per_bucket * bd->buckets[i]->top + -rte_ring_count (bd->adoption_buffer_rings[i]); - } + ctx.bd = mp->pool_data; + ctx.count = ctx.bd->obj_per_bucket * +rte_ring_count (ctx.bd->shared_bucket_ring); + ctx.count +=rte_ring_count (ctx.bd->shared_orphan_ring);
Quoted 13 lines
drivers/mempool/bucket/rte_mempool_bucket.c count_underfilled_buckets(struct rte_mempool *mp, · line 408
Quoted 10 lines
drivers/mempool/bucket/rte_mempool_bucket.c +8
-1+rte_lcore_iterate (count_per_lcore, &ctx);rte_mempool_mem_iter ((struct rte_mempool *)(uintptr_t )mp, - count_underfilled_buckets, &count); + count_underfilled_buckets, &ctx.count); + +return ctx.count; +} + +static int +bucket_init_per_lcore (unsigned int lcore_id,void *arg)It should be no
bucket_prefix here, or it should bebucket_prefix above incount_per_lcore.
As mentioned before, ack.
Quoted 19 lines
Quoted 19 lines
drivers/mempool/bucket/rte_mempool_bucket.c +18
-0+{ +char rg_name[RTE_RING_NAMESIZE ]; +struct bucket_data *bd = arg; +struct rte_mempool *mp; +int rg_flags; +int rc; + + mp = bd->pool; + bd->buckets[lcore_id] =bucket_stack_create (mp, + mp->size / bd->obj_per_bucket); +if (bd->buckets[lcore_id] ==NULL ) + goto error; + + rc =snprintf (rg_name,sizeof (rg_name),RTE_MEMPOOL_MZ_FORMAT ".a%u" , + mp->name, lcore_id); +if (rc <0 || rc >= (int )sizeof (rg_name)) + goto error; +
Quoted 8 lines
drivers/mempool/bucket/rte_mempool_bucket.c count_underfilled_buckets(struct rte_mempool *mp, · line 431
Quoted 5 lines
drivers/mempool/bucket/rte_mempool_bucket.c +5
-0+ rg_flags =RING_F_SC_DEQ ; +if (mp->flags &MEMPOOL_F_SP_PUT ) + rg_flags |=RING_F_SP_ENQ ; +if (mp->flags &MEMPOOL_F_SC_GET ) + rg_flags |=RING_F_SC_DEQ ;There is not point to have two above lines here, since
RING_F_SC_DEQis always set.
Ah yes, I did not realise when moving the code.
Quoted 13 lines
drivers/mempool/bucket/rte_mempool_bucket.c count_underfilled_buckets(struct rte_mempool *mp, · line 441
Quoted 12 lines
drivers/mempool/bucket/rte_mempool_bucket.c +9
-1+ bd->adoption_buffer_rings[lcore_id] =rte_ring_create (rg_name, +rte_align32pow2 (mp->size +1 ), mp->socket_id, rg_flags); +if (bd->adoption_buffer_rings[lcore_id] ==NULL ) + goto error; -return count; +return 0 ; +error: +rte_free (bd->buckets[lcore_id]); + bd->buckets[lcore_id] =NULL ; +return -1 ;
Quoted 2 lines
Why does the API collapse all negative errnos into -1? (I don't think it is critical, just want to know why).
I collapsed everything as a single error as we have a partial idea of what went wrong when calling this callback with all lcores at registration.
We could get a specific error reported by this callback, but then we would not know on which lcore (programmatically).
And in the end, all errors will summarize as a lack of resources, I do not expect a need for input validation.
Maybe you have other use cases in mind?
Thanks for the review.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v3 9/9] mempool/bucket: handle non-EAL lcores
Quoted 8 lines · David Marchand
Quoted 6 lines · Andrew Rybchenko
Quoted 4 lines · David Marchand
Convert to new lcore API to support non-EAL lcores.
Signed-off-by David Marchand <[email protected]>---
[snip]
Quoted 15 lines
Quoted 12 lines
drivers/mempool/bucket/rte_mempool_bucket.c count_underfilled_buckets(struct rte_mempool *mp, · line 441
Quoted 11 lines
drivers/mempool/bucket/rte_mempool_bucket.c +9
-1+ bd->adoption_buffer_rings[lcore_id] =rte_ring_create (rg_name, +rte_align32pow2 (mp->size +1 ), mp->socket_id, rg_flags); +if (bd->adoption_buffer_rings[lcore_id] ==NULL ) + goto error; -return count; +return 0 ; +error: +rte_free (bd->buckets[lcore_id]); + bd->buckets[lcore_id] =NULL ; +return -1 ;Quoted 2 lines
Why does the API collapse all negative errnos into -1? (I don't think it is critical, just want to know why).
Quoted 7 lines
I collapsed everything as a single error as we have a partial idea of what went wrong when calling this callback with all lcores at registration.
We could get a specific error reported by this callback, but then we would not know on which lcore (programmatically).
And in the end, all errors will summarize as a lack of resources, I do not expect a need for input validation.
Makes sense. Thanks for explanations.
Quoted 1 line
Maybe you have other use cases in mind?
No.
v4 cover Register non-EAL threads as lcore
In reply to David MarchandOVS and some other applications have been hacking into DPDK internals to fake EAL threads and avoid performance penalty of only having non-EAL threads.
This series proposes to add a new type of lcores and maps those threads to such lcores.
non-EAL threads won't run the DPDK eal mainloop.
As a consequence, part of the EAL threads API cannot work.
Having new lcores appearing during the process lifetime is not expected by some DPDK components. This is addressed by introducing init/uninit callacks invoked when hotplugging of such lcore.
There is still some work/discussion:
- refuse new lcore role in incompatible EAL threads API (or document it only as those API were already incompatible?),
- think about deprecation notices for existing RTE_FOREACH_LCORE macros and consorts, it is probably worth discussing on how to iterate over lcores,
For the interested parties, I have a patch [1] against dpdk-latest OVS branch that makes use of this series.
1: https://patchwork.ozlabs.org/project/openvswitch/patch/[email protected]/
Changes since v3:
- added init failure when trying to use in conjunction with multiprocess,
- addressed Andrew comments,
Changes since v2:
- fixed windows build error due to missing trace stub,
- fixed bug when rolling back on lcore register,
Changes since v1:
- rebased on master (conflicts on merged Windows series),
- separated lcore role code cleanup in a patch,
- tried to use a single naming, so kept non-EAL threads as the main notion. non-EAL threads are then distinguished between registered and unregistered non-EAL threads,
- added unit tests (still missing some coverage, marked with a FIXME),
- reworked callbacks call under a common rwlock lock which protects lcores allocations and callbacks registration,
- introduced lcore iterators and converted the bucket mempool driver,
Signature · 46 lines
David Marchand David Marchand (9): eal: relocate per thread symbols to common eal: fix multiple definition of per lcore thread id eal: introduce thread init helper eal: introduce thread uninit helper eal: move lcore role code eal: register non-EAL threads as lcores eal: add lcore init callbacks eal: add lcore iterators mempool/bucket: handle non-EAL lcores MAINTAINERS | 1 + app/test/Makefile | 1 + app/test/autotest_data.py | 6 + app/test/meson.build | 2 + app/test/test_lcores.c | 372 ++++++++++++++++++ doc/guides/howto/debug_troubleshoot.rst | 5 +- .../prog_guide/env_abstraction_layer.rst | 22 +- doc/guides/prog_guide/mempool_lib.rst | 2 +- drivers/mempool/bucket/rte_mempool_bucket.c | 130 +++--- lib/librte_eal/common/eal_common_lcore.c | 246 +++++++++++- lib/librte_eal/common/eal_common_mcfg.c | 36 ++ lib/librte_eal/common/eal_common_thread.c | 126 ++++-- lib/librte_eal/common/eal_common_trace.c | 51 ++- lib/librte_eal/common/eal_memcfg.h | 10 + lib/librte_eal/common/eal_private.h | 19 + lib/librte_eal/common/eal_thread.h | 26 +- lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/freebsd/eal.c | 20 +- lib/librte_eal/freebsd/eal_thread.c | 38 +- lib/librte_eal/include/rte_eal.h | 12 +- lib/librte_eal/include/rte_lcore.h | 174 +++++++- lib/librte_eal/include/rte_trace_point.h | 9 + lib/librte_eal/linux/eal.c | 21 +- lib/librte_eal/linux/eal_thread.c | 38 +- lib/librte_eal/rte_eal_version.map | 16 + lib/librte_eal/windows/eal.c | 8 +- lib/librte_eal/windows/eal_thread.c | 14 +- lib/librte_mempool/rte_mempool.h | 11 +- 28 files changed, 1179 insertions(+), 239 deletions(-) create mode 100644 app/test/test_lcores.c -- 2.23.0
PATCH v4 1/9 eal: relocate per thread symbols to common
We have per lcore thread symbols scattered in OS implementations but common code relies on them.
Move all of them in common.
RTE_PER_LCORE(_socket_id) and RTE_PER_LCORE(_cpuset) have public accessors and are not exported through the library map, they can be made static.
--- lib/librte_eal/common/eal_common_thread.c | 5 ++++- lib/librte_eal/freebsd/eal_thread.c | 4 ---- lib/librte_eal/include/rte_lcore.h | 1 - lib/librte_eal/linux/eal_thread.c | 4 ---- lib/librte_eal/windows/eal_thread.c | 4 ---- 5 files changed, 4 insertions(+), 14 deletions(-)
lib/librte_eal/common/eal_common_thread.c +4 -1
@@ -21,7 +21,10 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DECLARE_PER_LCORE (unsigned , _socket_id); +RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = + (unsigned int )SOCKET_ID_ANY ; +static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);unsigned rte_socket_id (void ) {
lib/librte_eal/freebsd/eal_thread.c +0 -4
@@ -25,10 +25,6 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; -RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
lib/librte_eal/include/rte_lcore.h +0 -1
@@ -23,7 +23,6 @@ extern "C" {#define LCORE_ID_ANY UINT32_MAX/**< Any lcore. */ RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ -RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */ /** * Get a lcore's role.
lib/librte_eal/linux/eal_thread.c +0 -4
@@ -25,10 +25,6 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; -RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
lib/librte_eal/windows/eal_thread.c +0 -4
@@ -16,10 +16,6 @@#include "eal_private.h" #include "eal_windows.h" -RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; -RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int)SOCKET_ID_ANY; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v4 1/9] eal: relocate per thread symbols to common
Quoted 9 lines · David Marchand
We have per lcore thread symbols scattered in OS implementations but common code relies on them.
Move all of them in common.
RTE_PER_LCORE(_socket_id)andRTE_PER_LCORE(_cpuset)have public accessors and are not exported through the library map, they can be made static.Signed-off-by David Marchand <[email protected]>
PATCH v4 2/9 eal: fix multiple definition of per lcore thread id
In reply to David MarchandBecause of the inline accessor + static declaration in rte_gettid(), we end up with multiple symbols for RTE_PER_LCORE(_thread_id). Each compilation unit will pay a cost when accessing this information for the first time.
$ nm build/app/dpdk-testpmd | grep per_lcore__thread_id 0000000000000054 d per_lcore__thread_id.5037 0000000000000040 d per_lcore__thread_id.5103 0000000000000048 d per_lcore__thread_id.5259 000000000000004c d per_lcore__thread_id.5259 0000000000000044 d per_lcore__thread_id.5933 0000000000000058 d per_lcore__thread_id.6261 0000000000000050 d per_lcore__thread_id.7378 000000000000005c d per_lcore__thread_id.7496 000000000000000c d per_lcore__thread_id.8016 0000000000000010 d per_lcore__thread_id.8431
Make it global as part of the DPDK_21 stable ABI.
--- lib/librte_eal/common/eal_common_thread.c | 1 + lib/librte_eal/include/rte_eal.h | 3 ++- lib/librte_eal/rte_eal_version.map | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_thread.c +1 -0
@@ -22,6 +22,7 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +RTE_DEFINE_PER_LCORE (int, _thread_id) =-1 ; static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int )SOCKET_ID_ANY ; static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
lib/librte_eal/include/rte_eal.h +2 -1
@@ -447,6 +447,8 @@ enum rte_intr_mode rte_eal_vfio_intr_mode(void);*/ int rte_sys_gettid (void ); +RTE_DECLARE_PER_LCORE (int, _thread_id); +/** * Get system unique thread id. *
@@ -456,7 +458,6 @@ int rte_sys_gettid(void);*/ static inline int rte_gettid (void ) { - static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;if (RTE_PER_LCORE (_thread_id) ==-1 )RTE_PER_LCORE (_thread_id) =rte_sys_gettid ();return RTE_PER_LCORE (_thread_id);
lib/librte_eal/rte_eal_version.map +7 -0
@@ -221,6 +221,13 @@ DPDK_20.0 { local: *; }; +DPDK_21 { + global: + + per_lcore__thread_id; + +} DPDK_20.0; + EXPERIMENTAL { global:
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v4 2/9] eal: fix multiple definition of per lcore thread id
Quoted 17 lines · David Marchand
Because of the inline accessor + static declaration in
rte_gettid(), we end up with multiple symbols forRTE_PER_LCORE(_thread_id). Each compilation unit will pay a cost when accessing this information for the first time.$ nm build/app/dpdk-testpmd | grep per_lcore__thread_id 0000000000000054 d per_lcore__thread_id.5037 0000000000000040 d per_lcore__thread_id.5103 0000000000000048 d per_lcore__thread_id.5259 000000000000004c d per_lcore__thread_id.5259 0000000000000044 d per_lcore__thread_id.5933 0000000000000058 d per_lcore__thread_id.6261 0000000000000050 d per_lcore__thread_id.7378 000000000000005c d per_lcore__thread_id.7496 000000000000000c d per_lcore__thread_id.8016 0000000000000010 d per_lcore__thread_id.8431
Quoted 6 lines
Make it global as part of the
DPDK_21stable ABI.Fixes ef76436c6834 ("eal: get unique thread id")Signed-off-by David Marchand <[email protected]>Acked-by Ray Kinsella <[email protected]>
PATCH v4 3/9 eal: introduce thread init helper
In reply to David MarchandIntroduce a helper responsible for initialising the per thread context. We can then have a unified context for EAL and non-EAL threads and remove copy/paste'd OS-specific helpers.
Per EAL thread CPU affinity setting is separated from the thread init. It is to accommodate with Windows EAL where CPU affinity is not set at the moment.
Besides, having affinity set by the master lcore in FreeBSD and Linux will make it possible to detect errors rather than panic in the child thread. But the cleanup when such an event happens is left for later.
---
Changes since v1:
- rebased on master, removed Windows workarounds wrt gettid and traces support,
--- lib/librte_eal/common/eal_common_thread.c | 51 +++++++++++++---------- lib/librte_eal/common/eal_thread.h | 8 ++-- lib/librte_eal/freebsd/eal.c | 14 ++++++- lib/librte_eal/freebsd/eal_thread.c | 32 +------------- lib/librte_eal/linux/eal.c | 15 ++++++- lib/librte_eal/linux/eal_thread.c | 32 +------------- lib/librte_eal/windows/eal.c | 3 +- lib/librte_eal/windows/eal_thread.c | 10 +---- 8 files changed, 66 insertions(+), 99 deletions(-)
lib/librte_eal/common/eal_common_thread.c +30 -21
@@ -71,20 +71,10 @@ eal_cpuset_socket_id(rte_cpuset_t *cpusetp)return socket_id; } -int -rte_thread_set_affinity (rte_cpuset_t *cpusetp) +static void +thread_update_affinity (rte_cpuset_t *cpusetp) { -int s; -unsigned lcore_id; -pthread_t tid; - - tid =pthread_self (); - - s =pthread_setaffinity_np (tid,sizeof (rte_cpuset_t), cpusetp); -if (s !=0 ) { -RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); -return -1 ; - } +unsigned int lcore_id =rte_lcore_id ();/* store socket_id in TLS for quick access */ RTE_PER_LCORE(_socket_id) =
@@ -94,14 +84,24 @@ rte_thread_set_affinity(rte_cpuset_t *cpusetp)memmove (&RTE_PER_LCORE (_cpuset), cpusetp,sizeof (rte_cpuset_t)); - lcore_id =rte_lcore_id ();if (lcore_id != (unsigned )LCORE_ID_ANY ) {/* EAL thread will update lcore_config */ lcore_config[lcore_id].socket_id =RTE_PER_LCORE (_socket_id);memmove (&lcore_config[lcore_id].cpuset, cpusetp,sizeof (rte_cpuset_t)); } +} +int +rte_thread_set_affinity (rte_cpuset_t *cpusetp) +{ +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + cpusetp) !=0 ) { +RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); +return -1 ; + } + +thread_update_affinity (cpusetp);return 0 ; }
@@ -147,6 +147,19 @@ eal_thread_dump_affinity(char *str, unsigned size)return ret; } +void +rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) +{ +/* set the lcore ID in per-lcore memory area */ +RTE_PER_LCORE (_lcore_id) = lcore_id; + +/* acquire system unique id */ +rte_gettid (); + +thread_update_affinity (cpuset); + +__rte_trace_mem_per_thread_alloc (); +}struct rte_thread_ctrl_params {void *(*start_routine)(void *);
@@ -154,16 +167,14 @@ struct rte_thread_ctrl_params {pthread_barrier_t configured; }; -static void *rte_thread_init (void *arg) +static void *ctrl_thread_init (void *arg) {int ret; -rte_cpuset_t *cpuset = &internal_config.ctrl_cpuset;struct rte_thread_ctrl_params *params = arg;void *(*start_routine)(void *) = params->start_routine;void *routine_arg = params->arg; -/* Store cpuset in TLS for quick access */ -memmove (&RTE_PER_LCORE (_cpuset), cpuset,sizeof (rte_cpuset_t)); +rte_thread_init (rte_lcore_id (), &internal_config.ctrl_cpuset); ret =pthread_barrier_wait (¶ms->configured);if (ret ==PTHREAD_BARRIER_SERIAL_THREAD ) {
@@ -171,8 +182,6 @@ static void *rte_thread_init(void *arg)free (params); } -__rte_trace_mem_per_thread_alloc (); -return start_routine (routine_arg); }
@@ -194,7 +203,7 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_barrier_init (¶ms->configured,NULL ,2 ); - ret =pthread_create (thread, attr, rte_thread_init, (void *)params); + ret =pthread_create (thread, attr, ctrl_thread_init, (void *)params);if (ret !=0 ) {free (params);return -ret;
lib/librte_eal/common/eal_thread.h +5 -3
@@ -16,12 +16,14 @@ __rte_noreturn void *eal_thread_loop(void *arg);/** -* Init per-lcore info for master thread +* Init per-lcore info in current thread. * * @param lcore_id -* identifier of master lcore +* identifier of lcore. +* @param cpuset +* CPU affinity for this thread. */ -void eal_thread_init_master (unsigned lcore_id); +void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset);/** * Get the NUMA socket id from cpu id.
lib/librte_eal/freebsd/eal.c +13 -1
@@ -877,7 +877,14 @@ rte_eal_init(int argc, char **argv)eal_check_mem_on_local_socket (); -eal_thread_init_master (rte_config.master_lcore); +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + &lcore_config[rte_config.master_lcore].cpuset) !=0 ) { +rte_eal_init_alert ("Cannot set affinity" ); + rte_errno =EINVAL ; +return -1 ; + } +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset));
@@ -908,6 +915,11 @@ rte_eal_init(int argc, char **argv)snprintf (thread_name,sizeof (thread_name),"lcore-slave-%d" , i);rte_thread_setname (lcore_config[i].thread_id, thread_name); + + ret =pthread_setaffinity_np (lcore_config[i].thread_id, +sizeof (rte_cpuset_t), &lcore_config[i].cpuset); +if (ret !=0 ) +rte_panic ("Cannot set affinity\n" ); }/*
lib/librte_eal/freebsd/eal_thread.c +1 -31
@@ -66,29 +66,6 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)return rc; } -/* set affinity for current thread */ -static int -eal_thread_set_affinity (void ) -{ -unsigned lcore_id =rte_lcore_id (); - -/* acquire system unique id */ -rte_gettid (); - -/* update EAL thread core affinity */ -return rte_thread_set_affinity (&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master (unsigned lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); -} -/* main loop of threads */ __rte_noreturn void * eal_thread_loop(__rte_unused void *arg)
@@ -113,19 +90,12 @@ eal_thread_loop(__rte_unused void *arg) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , lcore_id, thread_id, cpuset, ret ==0 ?"" :"..." ); -__rte_trace_mem_per_thread_alloc ();rte_eal_trace_thread_lcore_ready (lcore_id, cpuset);/* read on our pipe to get commands */
lib/librte_eal/linux/eal.c +13 -2
@@ -1205,10 +1205,16 @@ rte_eal_init(int argc, char **argv)eal_check_mem_on_local_socket (); -eal_thread_init_master (rte_config.master_lcore); +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + &lcore_config[rte_config.master_lcore].cpuset) !=0 ) { +rte_eal_init_alert ("Cannot set affinity" ); + rte_errno =EINVAL ; +return -1 ; + } +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , rte_config.master_lcore, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
@@ -1240,6 +1246,11 @@ rte_eal_init(int argc, char **argv)if (ret !=0 )RTE_LOG (DEBUG ,EAL ,"Cannot set name for lcore thread\n" ); + + ret =pthread_setaffinity_np (lcore_config[i].thread_id, +sizeof (rte_cpuset_t), &lcore_config[i].cpuset); +if (ret !=0 ) +rte_panic ("Cannot set affinity\n" ); }/*
lib/librte_eal/linux/eal_thread.c +1 -31
@@ -66,29 +66,6 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)return rc; } -/* set affinity for current EAL thread */ -static int -eal_thread_set_affinity (void ) -{ -unsigned lcore_id =rte_lcore_id (); - -/* acquire system unique id */ -rte_gettid (); - -/* update EAL thread core affinity */ -return rte_thread_set_affinity (&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master (unsigned lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); -} -/* main loop of threads */ __rte_noreturn void * eal_thread_loop(__rte_unused void *arg)
@@ -113,19 +90,12 @@ eal_thread_loop(__rte_unused void *arg) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." ); -__rte_trace_mem_per_thread_alloc ();rte_eal_trace_thread_lcore_ready (lcore_id, cpuset);/* read on our pipe to get commands */
lib/librte_eal/windows/eal.c +2 -1
@@ -367,7 +367,8 @@ rte_eal_init(int argc, char **argv)return -1 ; } -eal_thread_init_master (rte_config.master_lcore); +rte_thread_init (rte_config.master_lcore, + &lcore_config[rte_config.master_lcore].cpuset);RTE_LCORE_FOREACH_SLAVE (i) {
lib/librte_eal/windows/eal_thread.c +1 -9
@@ -53,13 +53,6 @@ rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int slave_id)return 0 ; } -void -eal_thread_init_master (unsigned int lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; -} -/* main loop of threads */ void * eal_thread_loop(void *arg __rte_unused)
@@ -84,8 +77,7 @@ eal_thread_loop(void *arg __rte_unused) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; +rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset);RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset);
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v4 3/9] eal: introduce thread init helper
Hi David,
one minor comment below
Quoted 84 lines · David Marchand
Introduce a helper responsible for initialising the per thread context. We can then have a unified context for EAL and non-EAL threads and remove copy/paste'd OS-specific helpers.
Per EAL thread CPU affinity setting is separated from the thread init. It is to accommodate with Windows EAL where CPU affinity is not set at the moment.
Besides, having affinity set by the master lcore in FreeBSD and Linux will make it possible to detect errors rather than panic in the child thread. But the cleanup when such an event happens is left for later.Signed-off-by David Marchand <[email protected]>---
Changes since v1:
- rebased on master, removed Windows workarounds wrt gettid and traces support,--- lib/librte_eal/common/eal_common_thread.c | 51 +++++++++++++---------- lib/librte_eal/common/eal_thread.h | 8 ++-- lib/librte_eal/freebsd/eal.c | 14 ++++++- lib/librte_eal/freebsd/eal_thread.c | 32 +------------- lib/librte_eal/linux/eal.c | 15 ++++++- lib/librte_eal/linux/eal_thread.c | 32 +------------- lib/librte_eal/windows/eal.c | 3 +- lib/librte_eal/windows/eal_thread.c | 10 +---- 8 files changed, 66 insertions(+), 99 deletions(-)lib/librte_eal/common/eal_common_thread.c +14
-14@@ -71,20 +71,10 @@ eal_cpuset_socket_id(rte_cpuset_t *cpusetp)return socket_id; } -int -rte_thread_set_affinity (rte_cpuset_t *cpusetp) +static void +thread_update_affinity (rte_cpuset_t *cpusetp) { -int s; -unsigned lcore_id; -pthread_t tid; - - tid =pthread_self (); - - s =pthread_setaffinity_np (tid,sizeof (rte_cpuset_t), cpusetp); -if (s !=0 ) { -RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); -return -1 ; - } +unsigned int lcore_id =rte_lcore_id ();/* store socket_id in TLS for quick access */ RTE_PER_LCORE(_socket_id) =@@ -94,14 +84,24 @@ rte_thread_set_affinity(rte_cpuset_t *cpusetp)memmove (&RTE_PER_LCORE (_cpuset), cpusetp,sizeof (rte_cpuset_t)); - lcore_id =rte_lcore_id ();if (lcore_id != (unsigned )LCORE_ID_ANY ) {/* EAL thread will update lcore_config */ lcore_config[lcore_id].socket_id =RTE_PER_LCORE (_socket_id);memmove (&lcore_config[lcore_id].cpuset, cpusetp,sizeof (rte_cpuset_t)); } +} +int +rte_thread_set_affinity (rte_cpuset_t *cpusetp) +{ +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + cpusetp) !=0 ) { +RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); +return -1 ; + } + +thread_update_affinity (cpusetp);return 0 ; }@@ -147,6 +147,19 @@ eal_thread_dump_affinity(char *str, unsigned size)return ret;
lib/librte_eal/common/eal_common_thread.c eal_thread_dump_affinity(char *str, unsigned size) · line 157
Quoted 10 lines
lib/librte_eal/common/eal_common_thread.c +8
-0} +void +rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) +{ +/* set the lcore ID in per-lcore memory area */ +RTE_PER_LCORE (_lcore_id) = lcore_id; + +/* acquire system unique id */ +rte_gettid ();
If I understand properly, rte_gettid() is now also called for control thread. I don't think this behavior change can break anything, but it may be good to highlight it in the commit log.
also, there are 2 spaces before "*/"
Re: [dpdk-dev] [PATCH v4 3/9] eal: introduce thread init helper
Quoted 13 lines · Olivier Matz
lib/librte_eal/common/eal_common_thread.c eal_thread_dump_affinity(char *str, unsigned size) · line 157
Quoted 9 lines
lib/librte_eal/common/eal_common_thread.c +8
-0+void +rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) +{ +/* set the lcore ID in per-lcore memory area */ +RTE_PER_LCORE (_lcore_id) = lcore_id; + +/* acquire system unique id */ +rte_gettid ();If I understand properly,
rte_gettid()is now also called for control thread. I don't think this behavior change can break anything, but it may be good to highlight it in the commit log.
Control thread could not use recursive locks before, because this rte_gettid() was missing.
Worth mentioning yes.
Signature · 1 line
David Marchand
PATCH v4 4/9 eal: introduce thread uninit helper
In reply to David MarchandThis is a preparation step for dynamically unregistering threads.
Since we explicitly allocate a per thread trace buffer in rte_thread_init, add an internal helper to free this buffer.
---
Note: I preferred renaming the current internal function to free all threads trace buffers (new name trace_mem_free()) and reuse the previous name (trace_mem_per_thread_free()) when freeing this buffer for a given thread.
Changes since v2:
- added missing stub for windows tracing support,
- moved free symbol to exported (experimental) ABI as a counterpart of the alloc symbol we already had,
Changes since v1:
- rebased on master, removed Windows workaround wrt traces support,
--- lib/librte_eal/common/eal_common_thread.c | 9 ++++ lib/librte_eal/common/eal_common_trace.c | 51 +++++++++++++++++++---- lib/librte_eal/common/eal_thread.h | 5 +++ lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/include/rte_trace_point.h | 9 ++++ lib/librte_eal/rte_eal_version.map | 3 ++ lib/librte_eal/windows/eal.c | 5 +++ 7 files changed, 75 insertions(+), 9 deletions(-)
lib/librte_eal/common/eal_common_thread.c +9 -0
@@ -20,6 +20,7 @@#include "eal_internal_cfg.h" #include "eal_private.h" #include "eal_thread.h" +#include "eal_trace.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;RTE_DEFINE_PER_LCORE (int, _thread_id) =-1 ;
@@ -161,6 +162,14 @@ rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset)__rte_trace_mem_per_thread_alloc (); } +void +rte_thread_uninit (void ) +{ +__rte_trace_mem_per_thread_free (); + +RTE_PER_LCORE (_lcore_id) =LCORE_ID_ANY ; +} +struct rte_thread_ctrl_params {void *(*start_routine)(void *);void *arg;
lib/librte_eal/common/eal_common_trace.c +43 -8
74 lines not on this page · raw message
lib/librte_eal/common/eal_thread.h +5 -0
@@ -25,6 +25,11 @@ __rte_noreturn void *eal_thread_loop(void *arg);*/ void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset); +/** +* Uninitialize per-lcore info for current thread. +*/ +void rte_thread_uninit (void ); +/** * Get the NUMA socket id from cpu id. * This function is private to EAL.
lib/librte_eal/common/eal_trace.h +1 -1
@@ -106,7 +106,7 @@ int trace_metadata_create(void);void trace_metadata_destroy (void );int trace_mkdir (void );int trace_epoch_time_save (void ); -void trace_mem_per_thread_free (void ); +void trace_mem_free (void );/* EAL interface */ int eal_trace_init (void );
lib/librte_eal/include/rte_trace_point.h +9 -0
@@ -230,6 +230,15 @@ __rte_trace_point_fp_is_enabled(void)__rte_experimental void __rte_trace_mem_per_thread_alloc(void); +/** +* @internal +* +* Free trace memory buffer per thread. +* +*/ +__rte_experimental +void __rte_trace_mem_per_thread_free(void); +/** * @internal *
lib/librte_eal/rte_eal_version.map +3 -0
@@ -393,6 +393,9 @@ EXPERIMENTAL { rte_trace_point_lookup; rte_trace_regexp; rte_trace_save; + + # added in 20.08 + __rte_trace_mem_per_thread_free; }; INTERNAL {
lib/librte_eal/windows/eal.c +5 -0
@@ -255,6 +255,11 @@ __rte_trace_mem_per_thread_alloc(void) { } +void +__rte_trace_mem_per_thread_free (void ) +{ +} +void __rte_trace_point_emit_field (size_t sz,const char *field,const char *type)
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v4 4/9] eal: introduce thread uninit helper
Quoted 21 lines · David Marchand
This is a preparation step for dynamically unregistering threads.
Since we explicitly allocate a per thread trace buffer in
rte_thread_init, add an internal helper to free this buffer.Signed-off-by David Marchand <[email protected]>---
Note: I preferred renaming the current internal function to free all threads trace buffers (new nametrace_mem_free()) and reuse the previous name (trace_mem_per_thread_free()) when freeing this buffer for a given thread.Changes since v2:
- added missing stub for windows tracing support,
- moved free symbol to exported (experimental) ABI as a counterpart of the alloc symbol we already had,Changes since v1:
- rebased on master, removed Windows workaround wrt traces support,
lib/librte_eal/common/eal_thread.h __rte_noreturn void *eal_thread_loop(void *arg); · line 32
Quoted 5 lines
lib/librte_eal/common/eal_thread.h +5
-0+/** +* Uninitialize per-lcore info for current thread. +*/ +void rte_thread_uninit (void ); +
Is it a public API? I guess not as it not adding in .map file. If it is private API, Is n't it better to change as eal_thread_ like another private API in eal_thread.h?
Re: [dpdk-dev] [PATCH v4 4/9] eal: introduce thread uninit helper
Quoted 24 lines · Jerin Jacob
Quoted 20 lines · David Marchand
This is a preparation step for dynamically unregistering threads.
Since we explicitly allocate a per thread trace buffer in
rte_thread_init, add an internal helper to free this buffer.Signed-off-by David Marchand <[email protected]>---
Note: I preferred renaming the current internal function to free all threads trace buffers (new nametrace_mem_free()) and reuse the previous name (trace_mem_per_thread_free()) when freeing this buffer for a given thread.Changes since v2:
- added missing stub for windows tracing support,
- moved free symbol to exported (experimental) ABI as a counterpart of the alloc symbol we already had,Changes since v1:
- rebased on master, removed Windows workaround wrt traces support,
Quoted 9 lines
lib/librte_eal/common/eal_thread.h __rte_noreturn void *eal_thread_loop(void *arg); · line 32
Quoted 5 lines
lib/librte_eal/common/eal_thread.h +5
-0+/** +* Uninitialize per-lcore info for current thread. +*/ +void rte_thread_uninit (void ); +Is it a public API? I guess not as it not adding in .map file. If it is private API, Is n't it better to change as
eal_thread_like another private API ineal_thread.h?
Before this series, we have:
- rte_thread_ public APIs for both EAL and non-EAL threads (declared in rte_eal_interrupts.h and rte_lcore.h),
- eal_thread_ internal APIs that apply to EAL threads (declared in eal_thread.h),
I guess __rte_thread_ could do the trick and I will move this to eal_private.h.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [EXT] [PATCH v4 4/9] eal: introduce thread uninit helper
In reply to David MarchandQuoted 63 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, June 26, 2020 8:18 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Sunil Kumar Kori <[email protected]>; Neil Horman <[email protected]>; Harini Ramakrishnan <[email protected]>; Omar Cardona <[email protected]>; Pallavi Kadam <[email protected]>; Ranjit Menon <[email protected]>
Subject: [EXT] [PATCH v4 4/9] eal: introduce thread uninit helperExternal Email
----------------------------------------------------------------------
This is a preparation step for dynamically unregistering threads.Since we explicitly allocate a per thread trace buffer in
rte_thread_init, add an internal helper to free this buffer.Signed-off-by David Marchand <[email protected]>---
Note: I preferred renaming the current internal function to free all threads trace buffers (new nametrace_mem_free()) and reuse the previous name (trace_mem_per_thread_free()) when freeing this buffer for a given thread.Changes since v2:
- added missing stub for windows tracing support,
- moved free symbol to exported (experimental) ABI as a counterpart of the alloc symbol we already had,Changes since v1:
- rebased on master, removed Windows workaround wrt traces support,---
lib/librte_eal/common/eal_common_thread.c | 9 ++++ lib/librte_eal/common/eal_common_trace.c | 51 +++++++++++++++++++---- lib/librte_eal/common/eal_thread.h | 5 +++ lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/include/rte_trace_point.h | 9 ++++ lib/librte_eal/rte_eal_version.map | 3 ++ lib/librte_eal/windows/eal.c | 5 +++ 7 files changed, 75 insertions(+), 9 deletions(-)lib/librte_eal/common/eal_common_thread.c +1
-0@@ -20,6 +20,7 @@#include "eal_internal_cfg.h" #include "eal_private.h" #include "eal_thread.h" +#include "eal_trace.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;
RTE_DEFINE_PER_LCORE(int, _thread_id)= -1; @@ -161,6 +162,14 @@rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset)__rte_trace_mem_per_thread_alloc(); }
lib/librte_eal/common/eal_common_thread.c rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset) · line 167
Quoted 3 lines
lib/librte_eal/common/eal_common_thread.c +3
-0+void +rte_thread_uninit (void ) +{
Need to check whether trace is enabled or not similar to trace_mem_free().
Quoted 7 lines
lib/librte_eal/common/eal_common_thread.c +4
-0+__rte_trace_mem_per_thread_free (); + +RTE_PER_LCORE (_lcore_id) =LCORE_ID_ANY ; } +struct rte_thread_ctrl_params { void *(*start_routine)(void *); void *arg;
[snipped]
Quoted 1 line
2.23.0
Re: [dpdk-dev] [EXT] [PATCH v4 4/9] eal: introduce thread uninit helper
Quoted 17 lines · Sunil Kumar Kori
Quoted 17 lines
lib/librte_eal/common/eal_common_thread.c +1
-0@@ -20,6 +20,7 @@#include "eal_internal_cfg.h" #include "eal_private.h" #include "eal_thread.h" +#include "eal_trace.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;
RTE_DEFINE_PER_LCORE(int, _thread_id)= -1; @@ -161,6 +162,14 @@rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset)__rte_trace_mem_per_thread_alloc(); }
Quoted 5 lines
lib/librte_eal/common/eal_common_thread.c rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset) · line 167
Quoted 3 lines
lib/librte_eal/common/eal_common_thread.c +3
-0+void +rte_thread_uninit (void ) +{Need to check whether trace is enabled or not similar to
trace_mem_free().
The internal trace api abstracts this.
It should be in the trace code itself, in the same way it is done for allocating the trace buffer.
But is an additional check needed?
The check on the trace buffer being initialised in __rte_trace_mem_per_thread_free should be enough.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v4 4/9] eal: introduce thread uninit helper
In reply to David MarchandQuoted 29 lines · David Marchand
This is a preparation step for dynamically unregistering threads.
Since we explicitly allocate a per thread trace buffer in
rte_thread_init, add an internal helper to free this buffer.Signed-off-by David Marchand <[email protected]>---
Note: I preferred renaming the current internal function to free all threads trace buffers (new nametrace_mem_free()) and reuse the previous name (trace_mem_per_thread_free()) when freeing this buffer for a given thread.Changes since v2:
- added missing stub for windows tracing support,
- moved free symbol to exported (experimental) ABI as a counterpart of the alloc symbol we already had,Changes since v1:
- rebased on master, removed Windows workaround wrt traces support,--- lib/librte_eal/common/eal_common_thread.c | 9 ++++ lib/librte_eal/common/eal_common_trace.c | 51 +++++++++++++++++++---- lib/librte_eal/common/eal_thread.h | 5 +++ lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/include/rte_trace_point.h | 9 ++++ lib/librte_eal/rte_eal_version.map | 3 ++ lib/librte_eal/windows/eal.c | 5 +++ 7 files changed, 75 insertions(+), 9 deletions(-)
[...]
Quoted 27 lines
lib/librte_eal/common/eal_common_trace.c +11
-1@@ -101,7 +101,7 @@ eal_trace_fini(void) {if (!rte_trace_is_enabled ())return ; -trace_mem_per_thread_free (); +trace_mem_free ();trace_metadata_destroy ();eal_trace_args_free (); }@@ -370,24 +370,59 @@ __rte_trace_mem_per_thread_alloc(void)rte_spinlock_unlock (&trace->lock); } +static void +trace_mem_per_thread_free_unlocked (struct thread_mem_meta *meta) +{ +if (meta->area ==TRACE_AREA_HUGEPAGE ) +eal_free_no_trace (meta->mem); +else if (meta->area ==TRACE_AREA_HEAP ) +free (meta->mem); +} + +void
lib/librte_eal/common/eal_common_trace.c __rte_trace_mem_per_thread_alloc(void) · line 392
Quoted 10 lines
lib/librte_eal/common/eal_common_trace.c +10
-0+__rte_trace_mem_per_thread_free (void) +{ +struct trace *trace =trace_obj_get (); +struct __rte_trace_header *header; +uint32_t count; + +if (RTE_PER_LCORE (trace_mem) ==NULL ) +return ; + + header =RTE_PER_LCORE (trace_mem);
nit:
header = RTE_PER_LCORE(trace_mem); if (header == NULL) return;
[...]
Quoted 6 lines
lib/librte_eal/include/rte_trace_point.h +0
-0@@ -230,6 +230,15 @@ __rte_trace_point_fp_is_enabled(void) __rte_experimental
lib/librte_eal/include/rte_trace_point.h __rte_trace_point_fp_is_enabled(void) · line 240
Quoted 10 lines
lib/librte_eal/include/rte_trace_point.h +8
-0void __rte_trace_mem_per_thread_alloc (void ); +/** +* @internal +* +* Free trace memory buffer per thread. +* +*/ +__rte_experimental +void __rte_trace_mem_per_thread_free(void);
Maybe the doc comment could be reworded a bit
(and the empty line can be removed by the way).
Quoted 9 lines
lib/librte_eal/include/rte_trace_point.h +1
-0+/** * @internal * lib/librte_eal/rte_eal_version.map +0
-0
lib/librte_eal/rte_eal_version.map EXPERIMENTAL { · line 398
Quoted 6 lines
lib/librte_eal/rte_eal_version.map +3
-0@@ -393,6 +393,9 @@ EXPERIMENTAL { rte_trace_point_lookup; rte_trace_regexp; rte_trace_save; + + # added in 20.08 + __rte_trace_mem_per_thread_free;
Is it really needed to export this function?
Re: [dpdk-dev] [PATCH v4 4/9] eal: introduce thread uninit helper
Quoted 8 lines · Olivier Matz
Quoted 8 lines
lib/librte_eal/include/rte_trace_point.h +0
-0@@ -230,6 +230,15 @@ __rte_trace_point_fp_is_enabled(void)__rte_experimental void __rte_trace_mem_per_thread_alloc(void);
Quoted 11 lines
lib/librte_eal/include/rte_trace_point.h __rte_trace_point_fp_is_enabled(void) · line 240
Quoted 8 lines
lib/librte_eal/include/rte_trace_point.h +8
-0+/** +* @internal +* +* Free trace memory buffer per thread. +* +*/ +__rte_experimental +void __rte_trace_mem_per_thread_free(void);Maybe the doc comment could be reworded a bit
(and the empty line can be removed by the way).
Copy/paste.
If we keep this symbol, I'll reword.
Quoted 10 lines
Quoted 10 lines
lib/librte_eal/include/rte_trace_point.h +1
-0+/** * @internal * lib/librte_eal/rte_eal_version.map +0
-0@@ -393,6 +393,9 @@ EXPERIMENTAL {
Quoted 9 lines
lib/librte_eal/rte_eal_version.map EXPERIMENTAL { · line 398
Quoted 6 lines
lib/librte_eal/rte_eal_version.map +3
-0rte_trace_point_lookup; rte_trace_regexp; rte_trace_save; + + # added in 20.08 + __rte_trace_mem_per_thread_free;Is it really needed to export this function?
There is no need for the series.
When an application non-EAL thread (not talking about threads that dpdk is aware of) calls a tracepoint callback, there is an implicit call to _alloc.
We end up with a memory leak and the application has no way to fix this. I left this symbol exported, but this is not documented properly.
Signature · 1 line
David Marchand
PATCH v4 5/9 eal: move lcore role code
In reply to David MarchandFor consistency sake, move all lcore role code in the dedicated compilation unit / header.
--- lib/librte_eal/common/eal_common_lcore.c | 11 +++++++ lib/librte_eal/common/eal_common_thread.c | 11 ------- lib/librte_eal/include/rte_eal.h | 9 ------ lib/librte_eal/include/rte_lcore.h | 37 ++++++++++++++--------- 4 files changed, 34 insertions(+), 34 deletions(-)
lib/librte_eal/common/eal_common_lcore.c +11 -0
@@ -63,6 +63,17 @@ rte_eal_lcore_role(unsigned int lcore_id)return cfg->lcore_role[lcore_id]; } +int +rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role) +{ +struct rte_config *cfg =rte_eal_get_configuration (); + +if (lcore_id >=RTE_MAX_LCORE ) +return -EINVAL ; + +return cfg->lcore_role[lcore_id] == role; +} +int rte_lcore_is_enabled (unsigned int lcore_id) {struct rte_config *cfg =rte_eal_get_configuration ();
lib/librte_eal/common/eal_common_thread.c +0 -11
@@ -33,17 +33,6 @@ unsigned rte_socket_id(void)return RTE_PER_LCORE (_socket_id); } -int -rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role) -{ -struct rte_config *cfg =rte_eal_get_configuration (); - -if (lcore_id >=RTE_MAX_LCORE ) -return -EINVAL ; - -return cfg->lcore_role[lcore_id] == role; -} -static int eal_cpuset_socket_id (rte_cpuset_t *cpusetp) {
lib/librte_eal/include/rte_eal.h +0 -9
@@ -31,15 +31,6 @@ extern "C" {/* Maximum thread_name length. */ #define RTE_MAX_THREAD_NAME_LEN 16 -/** -* The lcore role (used in RTE or not). -*/ -enum rte_lcore_role_t { -ROLE_RTE , -ROLE_OFF , -ROLE_SERVICE , -}; -/** * The type of process in a linux, multi-process setup */
lib/librte_eal/include/rte_lcore.h +23 -14
@@ -24,6 +24,15 @@ extern "C" {RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ +/** +* The lcore role (used in RTE or not). +*/ +enum rte_lcore_role_t { +ROLE_RTE , +ROLE_OFF , +ROLE_SERVICE , +}; +/** * Get a lcore's role. *
@@ -34,6 +43,20 @@ RTE_DECLARE_PER_LCORE(unsigned, _lcore_id); /**< Per thread "lcore id". */*/ enum rte_lcore_role_t rte_eal_lcore_role (unsigned int lcore_id); +/** +* Test if the core supplied has a specific role +* +* @param lcore_id +* The identifier of the lcore, which MUST be between 0 and +* RTE_MAX_LCORE-1. +* @param role +* The role to be checked against. +* @return +* Boolean value: positive if test is true; otherwise returns 0. +*/ +int +rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role); +/** * Return the Application thread ID of the execution unit. *
@@ -283,20 +306,6 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); -/** -* Test if the core supplied has a specific role -* -* @param lcore_id -* The identifier of the lcore, which MUST be between 0 and -* RTE_MAX_LCORE-1. -* @param role -* The role to be checked against. -* @return -* Boolean value: positive if test is true; otherwise returns 0. -*/ -int -rte_lcore_has_role (unsigned int lcore_id,enum rte_lcore_role_t role); - #ifdef __cplusplus }#endif
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v4 5/9] eal: move lcore role code
Quoted 4 lines · David Marchand
For consistency sake, move all lcore role code in the dedicated compilation unit / header.
Signed-off-by David Marchand <[email protected]>
PATCH v4 6/9 eal: register non-EAL threads as lcores
In reply to David MarchandDPDK allows calling some part of its API from a non-EAL thread but this has some limitations.
OVS (and other applications) has its own thread management but still want to avoid such limitations by hacking RTE_PER_LCORE(_lcore_id) and faking EAL threads potentially unknown of some DPDK component.
Introduce a new API to register non-EAL thread and associate them to a free lcore with a new NON_EAL role.
This role denotes lcores that do not run DPDK mainloop and as such prevents use of rte_eal_wait_lcore() and consorts.
Multiprocess is not supported as the need for cohabitation with this new feature is unclear at the moment.
---
Changes since v2:
- refused multiprocess init once rte_thread_register got called, and vice versa,
- added warning on multiprocess in rte_thread_register doxygen,
Changes since v1:
- moved cleanup on lcore role code in patch 5,
- added unit test,
- updated documentation,
- changed naming from "external thread" to "registered non-EAL thread"
--- MAINTAINERS | 1 + app/test/Makefile | 1 + app/test/autotest_data.py | 6 + app/test/meson.build | 2 + app/test/test_lcores.c | 139 ++++++++++++++++++ doc/guides/howto/debug_troubleshoot.rst | 5 +- .../prog_guide/env_abstraction_layer.rst | 22 +-- doc/guides/prog_guide/mempool_lib.rst | 2 +- lib/librte_eal/common/eal_common_lcore.c | 50 ++++++- lib/librte_eal/common/eal_common_mcfg.c | 36 +++++ lib/librte_eal/common/eal_common_thread.c | 33 +++++ lib/librte_eal/common/eal_memcfg.h | 10 ++ lib/librte_eal/common/eal_private.h | 18 +++ lib/librte_eal/freebsd/eal.c | 4 + lib/librte_eal/include/rte_lcore.h | 25 +++- lib/librte_eal/linux/eal.c | 4 + lib/librte_eal/rte_eal_version.map | 2 + lib/librte_mempool/rte_mempool.h | 11 +- 18 files changed, 349 insertions(+), 22 deletions(-) create mode 100644 app/test/test_lcores.c
MAINTAINERS +1 -0
@@ -182,6 +182,7 @@ F: app/test/test_cycles.c F: app/test/test_debug.c F: app/test/test_eal* F: app/test/test_errno.c +F: app/test/test_lcores.c F: app/test/test_logs.c F: app/test/test_memcpy* F: app/test/test_per_lcore.c
app/test/Makefile +1 -0
@@ -97,6 +97,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_FLOW_CLASSIFY) += test_flow_classify.c endif SRCS-y += test_rwlock.c +SRCS-y += test_lcores.c SRCS-$(CONFIG_RTE_LIBRTE_STACK) += test_stack.c SRCS-$(CONFIG_RTE_LIBRTE_STACK) += test_stack_perf.c
app/test/autotest_data.py +6 -0
@@ -62,6 +62,12 @@ "Func": rwlock_autotest, "Report": None, }, + { + "Name": "Lcores autotest", + "Command": "lcores_autotest", + "Func": default_autotest, + "Report": None, + }, { "Name": "Logs autotest", "Command": "logs_autotest",
app/test/meson.build +2 -0
@@ -67,6 +67,7 @@ test_sources = files('commands.c', 'test_ipsec_perf.c', 'test_kni.c', 'test_kvargs.c', + 'test_lcores.c', 'test_logs.c', 'test_lpm.c', 'test_lpm6.c',
@@ -206,6 +207,7 @@ fast_tests = [ ['hash_autotest', true], ['interrupt_autotest', true], ['ipfrag_autotest', false], + ['lcores_autotest', true], ['logs_autotest', true], ['lpm_autotest', true], ['lpm6_autotest', true],
app/test/test_lcores.c new file +139 -0
139 lines not on this page · raw message
doc/guides/howto/debug_troubleshoot.rst +3 -2
@@ -307,8 +307,9 @@ Custom worker function :numref:`dtg_distributor_worker`. #. Configuration issue isolation - * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF and - SERVICE. Check performance functions are mapped to run on the cores. + * Identify core role using ``rte_eal_lcore_role`` to identify RTE, OFF, + SERVICE and NON_EAL. Check performance functions are mapped to run on the + cores. * For high-performance execution logic ensure running it on correct NUMA and non-master core.
doc/guides/prog_guide/env_abstraction_layer.rst +13 -9
@@ -564,9 +564,13 @@ It's also compatible with the pattern of corelist('-l') option. non-EAL pthread support ~~~~~~~~~~~~~~~~~~~~~~~ -It is possible to use the DPDK execution context with any user pthread (aka. Non-EAL pthreads). -In a non-EAL pthread, the *_lcore_id* is always LCORE_ID_ANY which identifies that it is not an EAL thread with a valid, unique, *_lcore_id*. -Some libraries will use an alternative unique ID (e.g. TID), some will not be impacted at all, and some will work but with limitations (e.g. timer and mempool libraries). +It is possible to use the DPDK execution context with any user pthread (aka. non-EAL pthreads). +There are two kinds of non-EAL pthreads: + +- a registered non-EAL pthread with a valid *_lcore_id* that was successfully assigned by calling ``rte_thread_register()``, +- a non registered non-EAL pthread with a LCORE_ID_ANY, + +For non registered non-EAL pthread (with a LCORE_ID_ANY *_lcore_id*), some libraries will use an alternative unique ID (e.g. TID), some will not be impacted at all, and some will work but with limitations (e.g. timer and mempool libraries). All these impacts are mentioned in :ref:`known_issue_label` section.
@@ -613,9 +617,9 @@ Known Issues + rte_mempool The rte_mempool uses a per-lcore cache inside the mempool. - For non-EAL pthreads, ``rte_lcore_id()`` will not return a valid number. - So for now, when rte_mempool is used with non-EAL pthreads, the put/get operations will bypass the default mempool cache and there is a performance penalty because of this bypass. - Only user-owned external caches can be used in a non-EAL context in conjunction with ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()`` that accept an explicit cache parameter. + For unregistered non-EAL pthreads, ``rte_lcore_id()`` will not return a valid number. + So for now, when rte_mempool is used with unregistered non-EAL pthreads, the put/get operations will bypass the default mempool cache and there is a performance penalty because of this bypass. + Only user-owned external caches can be used in an unregistered non-EAL context in conjunction with ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()`` that accept an explicit cache parameter. + rte_ring
@@ -660,15 +664,15 @@ Known Issues + rte_timer - Running ``rte_timer_manage()`` on a non-EAL pthread is not allowed. However, resetting/stopping the timer from a non-EAL pthread is allowed. + Running ``rte_timer_manage()`` on an unregistered non-EAL pthread is not allowed. However, resetting/stopping the timer from a non-EAL pthread is allowed. + rte_log - In non-EAL pthreads, there is no per thread loglevel and logtype, global loglevels are used. + In unregistered non-EAL pthreads, there is no per thread loglevel and logtype, global loglevels are used. + misc - The debug statistics of rte_ring, rte_mempool and rte_timer are not supported in a non-EAL pthread. + The debug statistics of rte_ring, rte_mempool and rte_timer are not supported in an unregistered non-EAL pthread. cgroup control ~~~~~~~~~~~~~~
doc/guides/prog_guide/mempool_lib.rst +1 -1
@@ -103,7 +103,7 @@ The maximum size of the cache is static and is defined at compilation time (CONF Alternatively to the internal default per-lcore local cache, an application can create and manage external caches through the ``rte_mempool_cache_create()``, ``rte_mempool_cache_free()`` and ``rte_mempool_cache_flush()`` calls. These user-owned caches can be explicitly passed to ``rte_mempool_generic_put()`` and ``rte_mempool_generic_get()``. The ``rte_mempool_default_cache()`` call returns the default internal cache if any. -In contrast to the default caches, user-owned caches can be used by non-EAL threads too. +In contrast to the default caches, user-owned caches can be used by unregistered non-EAL threads too. Mempool Handlers ------------------------
lib/librte_eal/common/eal_common_lcore.c +46 -4
62 lines not on this page · raw message
lib/librte_eal/common/eal_common_mcfg.c +36 -0
@@ -44,6 +44,42 @@ eal_mcfg_check_version(void)return 0 ; } +enum mp_status { +MP_UNKNOWN , +MP_FORBIDDEN , +MP_ENABLED , +}; + +static bool +eal_mcfg_set_mp_status (enum mp_status status) +{ +struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; +uint8_t expected; +uint8_t desired; + + expected =MP_UNKNOWN ; + desired = status; +if (__atomic_compare_exchange_n (&mcfg->mp_status, &expected, desired, + false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) +return true; + +return __atomic_load_n (&mcfg->mp_status, __ATOMIC_RELAXED) == desired; +} + +bool +eal_mcfg_forbid_multiprocess (void ) +{ +assert (rte_eal_get_configuration ()->process_type ==RTE_PROC_PRIMARY ); +return eal_mcfg_set_mp_status (MP_FORBIDDEN ); +} + +bool +eal_mcfg_enable_multiprocess (void ) +{ +assert (rte_eal_get_configuration ()->process_type ==RTE_PROC_SECONDARY ); +return eal_mcfg_set_mp_status (MP_ENABLED ); +} +void eal_mcfg_update_internal (void ) {
lib/librte_eal/common/eal_common_thread.c +33 -0
@@ -236,3 +236,36 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_join (*thread,NULL );return -ret; } + +void +rte_thread_register (void ) +{ +unsigned int lcore_id; +rte_cpuset_t cpuset; + +/* EAL init flushes all lcores, we can't register before. */ +assert (internal_config.init_complete ==1 ); +if (pthread_getaffinity_np (pthread_self (),sizeof (cpuset), + &cpuset) !=0 ) +CPU_ZERO (&cpuset); + lcore_id =eal_lcore_non_eal_allocate (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ; +rte_thread_init (lcore_id, &cpuset); +if (lcore_id !=LCORE_ID_ANY ) +RTE_LOG (DEBUG ,EAL ,"Registered non-EAL thread as lcore %u.\n" , + lcore_id); +} + +void +rte_thread_unregister (void ) +{ +unsigned int lcore_id =rte_lcore_id (); + +if (lcore_id !=LCORE_ID_ANY ) +eal_lcore_non_eal_release (lcore_id); +rte_thread_uninit (); +if (lcore_id !=LCORE_ID_ANY ) +RTE_LOG (DEBUG ,EAL ,"Unregistered non-EAL thread (was lcore %u).\n" , + lcore_id); +}
lib/librte_eal/common/eal_memcfg.h +10 -0
@@ -41,6 +41,8 @@ struct rte_mem_config {rte_rwlock_t memory_hotplug_lock;/**< Indicates whether memory hotplug request is in progress. */ +uint8_t mp_status;/**< Indicates whether multiprocess can be used. */ +/* memory segments and zones */ struct rte_fbarray memzones;/**< Memzone descriptors. */
@@ -91,6 +93,14 @@ eal_mcfg_wait_complete(void);int eal_mcfg_check_version (void ); +/* mark primary process as not supporting multi-process. */ +bool +eal_mcfg_forbid_multiprocess (void ); + +/* instruct primary process that a secondary process attached once. */ +bool +eal_mcfg_enable_multiprocess (void ); +/* set mem config as complete */ void eal_mcfg_complete (void );
lib/librte_eal/common/eal_private.h +18 -0
@@ -396,6 +396,24 @@ uint64_t get_tsc_freq(void);*/ uint64_t get_tsc_freq_arch (void ); +/** +* Allocate a free lcore to associate to a non-EAL thread. +* +* @return +* - the id of a lcore with role ROLE_NON_EAL on success. +* - RTE_MAX_LCORE if none was available. +*/ +unsigned int eal_lcore_non_eal_allocate (void ); + +/** +* Release the lcore used by a non-EAL thread. +* Counterpart of eal_lcore_non_eal_allocate(). +* +* @param lcore_id +* The lcore with role ROLE_NON_EAL to release. +*/ +void eal_lcore_non_eal_release (unsigned int lcore_id); +/** * Prepare physical memory mapping * i.e. hugepages on Linux and
lib/librte_eal/freebsd/eal.c +4 -0
@@ -424,6 +424,10 @@ rte_config_init(void) }if (rte_eal_config_reattach () <0 )return -1 ; +if (!eal_mcfg_enable_multiprocess ()) { +RTE_LOG (ERR ,EAL ,"Primary process refused secondary attachment\n" ); +return -1 ; + }eal_mcfg_update_internal ();break ;case RTE_PROC_AUTO :
lib/librte_eal/include/rte_lcore.h +24 -1
@@ -31,6 +31,7 @@ enum rte_lcore_role_t {ROLE_RTE ,ROLE_OFF ,ROLE_SERVICE , + ROLE_NON_EAL, };/**
@@ -67,7 +68,8 @@ rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role);* to run threads with lcore IDs 0, 1, 2 and 3 on physical core 10.. * * @return -* Logical core ID (in EAL thread) or LCORE_ID_ANY (in non-EAL thread) +* Logical core ID (in EAL thread or registered non-EAL thread) or +* LCORE_ID_ANY (in unregistered non-EAL thread) */ static inline unsigned rte_lcore_id (void )
@@ -279,6 +281,27 @@ int rte_thread_setname(pthread_t id, const char *name);__rte_experimental int rte_thread_getname(pthread_t id, char *name, size_t len); +/** +* Register current non-EAL thread as a lcore. +* +* @note This API is not compatible with the multi-process feature: +* - if a primary process registers a non-EAL thread, then no secondary process +* will initialise. +* - if a secondary process initialises successfully, trying to register a +* non-EAL thread from either primary or secondary processes will always end +* up with the thread getting LCORE_ID_ANY as lcore. +*/ +__rte_experimental +void +rte_thread_register (void ); + +/** +* Unregister current thread and release lcore if one was associated. +*/ +__rte_experimental +void +rte_thread_unregister (void ); +/** * Create a control thread. *
lib/librte_eal/linux/eal.c +4 -0
@@ -514,6 +514,10 @@ rte_config_init(void) }if (rte_eal_config_reattach () <0 )return -1 ; +if (!eal_mcfg_enable_multiprocess ()) { +RTE_LOG (ERR ,EAL ,"Primary process refused secondary attachment\n" ); +return -1 ; + }eal_mcfg_update_internal ();break ;case RTE_PROC_AUTO :
lib/librte_eal/rte_eal_version.map +2 -0
@@ -396,6 +396,8 @@ EXPERIMENTAL { # added in 20.08 __rte_trace_mem_per_thread_free; + rte_thread_register; + rte_thread_unregister; }; INTERNAL {
lib/librte_mempool/rte_mempool.h +6 -5
@@ -28,9 +28,9 @@* rte_mempool_get() or rte_mempool_put() are designed to be called from an EAL * thread due to the internal per-lcore cache. Due to the lack of caching, * rte_mempool_get() or rte_mempool_put() performance will suffer when called -* by non-EAL threads. Instead, non-EAL threads should call -* rte_mempool_generic_get() or rte_mempool_generic_put() with a user cache -* created with rte_mempool_cache_create(). +* by unregistered non-EAL threads. Instead, unregistered non-EAL threads +* should call rte_mempool_generic_get() or rte_mempool_generic_put() with a +* user cache created with rte_mempool_cache_create(). */ #include <stdio.h>
@@ -1233,7 +1233,7 @@ void rte_mempool_dump(FILE *f, struct rte_mempool *mp);/** * Create a user-owned mempool cache. * -* This can be used by non-EAL threads to enable caching when they +* This can be used by unregistered non-EAL threads to enable caching when they * interact with a mempool. * * @param size
@@ -1264,7 +1264,8 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache);* @param lcore_id * The logical core id. * @return -* A pointer to the mempool cache or NULL if disabled or non-EAL thread. +* A pointer to the mempool cache or NULL if disabled or unregistered non-EAL +* thread. */ static __rte_always_inline struct rte_mempool_cache *rte_mempool_default_cache (struct rte_mempool *mp,unsigned lcore_id)
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v4 6/9] eal: register non-EAL threads as lcores
Quoted 101 lines
lib/librte_eal/common/eal_common_lcore.c +46
-4@@ -6,13 +6,15 @@#include <limits.h> #include <string.h> -#include <rte_errno.h> -#include <rte_log.h> -#include <rte_eal.h> -#include <rte_lcore.h> #include <rte_common.h> #include <rte_debug.h> +#include <rte_eal.h> +#include <rte_errno.h> +#include <rte_lcore.h> +#include <rte_log.h> +#include <rte_spinlock.h> +#include "eal_memcfg.h" #include "eal_private.h" #include "eal_thread.h" @@ -220,3 +222,43 @@ rte_socket_id_by_idx(unsigned int idx) }return config->numa_nodes[idx]; } + +static rte_spinlock_t lcore_lock =RTE_SPINLOCK_INITIALIZER ; + +unsigned int +eal_lcore_non_eal_allocate (void ) +{ +struct rte_config *cfg =rte_eal_get_configuration (); +unsigned int lcore_id; + +if (cfg->process_type ==RTE_PROC_SECONDARY || + !eal_mcfg_forbid_multiprocess ()) { +RTE_LOG (ERR ,EAL ,"Multiprocess in use, cannot allocate new lcore.\n" ); +return RTE_MAX_LCORE ; + } +rte_spinlock_lock (&lcore_lock); +for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +if (cfg->lcore_role[lcore_id] !=ROLE_OFF ) +continue ; + cfg->lcore_role[lcore_id] =ROLE_NON_EAL ; + cfg->lcore_count++; +break ; + } +if (lcore_id ==RTE_MAX_LCORE ) +RTE_LOG (DEBUG ,EAL ,"No lcore available.\n" ); +rte_spinlock_unlock (&lcore_lock); +return lcore_id; +} + +void +eal_lcore_non_eal_release (unsigned int lcore_id) +{ +struct rte_config *cfg =rte_eal_get_configuration (); + +rte_spinlock_lock (&lcore_lock); +if (cfg->lcore_role[lcore_id] ==ROLE_NON_EAL ) { + cfg->lcore_role[lcore_id] =ROLE_OFF ; + cfg->lcore_count--; + } +rte_spinlock_unlock (&lcore_lock); +}lib/librte_eal/common/eal_common_mcfg.c +25
-0@@ -44,6 +44,42 @@ eal_mcfg_check_version(void)return 0 ; } +enum mp_status { +MP_UNKNOWN , +MP_FORBIDDEN , +MP_ENABLED , +}; + +static bool +eal_mcfg_set_mp_status (enum mp_status status) +{ +struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; +uint8_t expected; +uint8_t desired; + + expected =MP_UNKNOWN ; + desired = status; +if (__atomic_compare_exchange_n (&mcfg->mp_status, &expected, desired, + false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) +return true; + +return __atomic_load_n (&mcfg->mp_status, __ATOMIC_RELAXED) == desired; +} + +bool +eal_mcfg_forbid_multiprocess (void ) +{
lib/librte_eal/common/eal_common_mcfg.c eal_mcfg_check_version(void) · line 81
Quoted 10 lines
lib/librte_eal/common/eal_common_mcfg.c +10
-0+assert (rte_eal_get_configuration ()->process_type ==RTE_PROC_PRIMARY ); +return eal_mcfg_set_mp_status (MP_FORBIDDEN ); +} + +bool +eal_mcfg_enable_multiprocess (void ) +{ +assert (rte_eal_get_configuration ()->process_type ==RTE_PROC_SECONDARY ); +return eal_mcfg_set_mp_status (MP_ENABLED ); +}
I still don't think it is a good idea to allow to change primary proc behaviour (allow/forbid secondary procs to attach) on the fly.
Imagine the situation - there is a primary proc (supposed to run forever) that does rte_thread_register/rte_thread_unregister during its lifetime. Plus from time to time user runs some secondary process to collect stats/debug the primary one (proc-info or so).
Now behaviour of such system will be completely non-deterministic:
In some runs primary proc will do rte_thread_register() first, and then secondary proc will be never able to attach.
In other cases - secondary will win the race, and then for primary eal_lcore_non_eal_allocate() will always fail.
Which means different behaviour, significantly varying performance, etc.
I am not big fun to introduce such workaround at all, but at least startup flag, will guarantee consistent behaviour: secondary proc will always fail to attach and eal_lcore_non_eal_allocate() will always succeed
(as long as there are free lcore_ids off-course).
From your previous mail:
Quoted 3 lines
A EAL flag is a stable API from the start, as there is nothing describing how we can remove one.
So a new EAL flag for an experimental API/feature seems contradictory.
Hm, yes there is a gap, but why eal flag can't also be an experimental one? What will be the difference between flag and API call here?
We can still reserve the right to remove/change it at any time.
As another thought about startup parameters -
would it make sense to have new one: --lcore-allow-list=...? That would limit lcore_ids available for the process. Without this new parameter specified -lcore_allowed_list would be equal to startup lcore list (static ones), and no dynamic lcore allocations will be allowed.
As an example:dpdk_app --lcores=6,7 --lcore-allow=0-100
will reserve lcore_ids 6,7 at startup (same as we do now), and leave [0-5] and [8-100] available for dynamic usage.
Quoted 232 lines
void
eal_mcfg_update_internal(void)
{lib/librte_eal/common/eal_common_thread.c +33
-0@@ -236,3 +236,36 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_join (*thread,NULL );return -ret; } + +void +rte_thread_register (void ) +{ +unsigned int lcore_id; +rte_cpuset_t cpuset; + +/* EAL init flushes all lcores, we can't register before. */ +assert (internal_config.init_complete ==1 ); +if (pthread_getaffinity_np (pthread_self (),sizeof (cpuset), + &cpuset) !=0 ) +CPU_ZERO (&cpuset); + lcore_id =eal_lcore_non_eal_allocate (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ; +rte_thread_init (lcore_id, &cpuset); +if (lcore_id !=LCORE_ID_ANY ) +RTE_LOG (DEBUG ,EAL ,"Registered non-EAL thread as lcore %u.\n" , + lcore_id); +} + +void +rte_thread_unregister (void ) +{ +unsigned int lcore_id =rte_lcore_id (); + +if (lcore_id !=LCORE_ID_ANY ) +eal_lcore_non_eal_release (lcore_id); +rte_thread_uninit (); +if (lcore_id !=LCORE_ID_ANY ) +RTE_LOG (DEBUG ,EAL ,"Unregistered non-EAL thread (was lcore %u).\n" , + lcore_id); +}lib/librte_eal/common/eal_memcfg.h +10
-0@@ -41,6 +41,8 @@ struct rte_mem_config {rte_rwlock_t memory_hotplug_lock;/**< Indicates whether memory hotplug request is in progress. */ +uint8_t mp_status;/**< Indicates whether multiprocess can be used. */ +/* memory segments and zones */ struct rte_fbarray memzones;/**< Memzone descriptors. */ @@ -91,6 +93,14 @@ eal_mcfg_wait_complete(void);int eal_mcfg_check_version (void ); +/* mark primary process as not supporting multi-process. */ +bool +eal_mcfg_forbid_multiprocess (void ); + +/* instruct primary process that a secondary process attached once. */ +bool +eal_mcfg_enable_multiprocess (void ); +/* set mem config as complete */ void eal_mcfg_complete (void );lib/librte_eal/common/eal_private.h +18
-0@@ -396,6 +396,24 @@ uint64_t get_tsc_freq(void);*/ uint64_t get_tsc_freq_arch (void ); +/** +* Allocate a free lcore to associate to a non-EAL thread. +* +* @return +* - the id of a lcore with role ROLE_NON_EAL on success. +* - RTE_MAX_LCORE if none was available. +*/ +unsigned int eal_lcore_non_eal_allocate (void ); + +/** +* Release the lcore used by a non-EAL thread. +* Counterpart of eal_lcore_non_eal_allocate(). +* +* @param lcore_id +* The lcore with role ROLE_NON_EAL to release. +*/ +void eal_lcore_non_eal_release (unsigned int lcore_id); +/** * Prepare physical memory mapping * i.e. hugepages on Linux and lib/librte_eal/freebsd/eal.c +4
-0@@ -424,6 +424,10 @@ rte_config_init(void) }if (rte_eal_config_reattach () <0 )return -1 ; +if (!eal_mcfg_enable_multiprocess ()) { +RTE_LOG (ERR ,EAL ,"Primary process refused secondary attachment\n" ); +return -1 ; + }eal_mcfg_update_internal ();break ;case RTE_PROC_AUTO :lib/librte_eal/include/rte_lcore.h +24
-1@@ -31,6 +31,7 @@ enum rte_lcore_role_t {ROLE_RTE ,ROLE_OFF ,ROLE_SERVICE , + ROLE_NON_EAL, };/** @@ -67,7 +68,8 @@ rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role);* to run threads with lcore IDs 0, 1, 2 and 3 on physical core 10.. * * @return -* Logical core ID (in EAL thread) or LCORE_ID_ANY (in non-EAL thread) +* Logical core ID (in EAL thread or registered non-EAL thread) or +* LCORE_ID_ANY (in unregistered non-EAL thread) */ static inline unsigned rte_lcore_id (void )@@ -279,6 +281,27 @@ int rte_thread_setname(pthread_t id, const char *name);__rte_experimental int rte_thread_getname(pthread_t id, char *name, size_t len); +/** +* Register current non-EAL thread as a lcore. +* +* @note This API is not compatible with the multi-process feature: +* - if a primary process registers a non-EAL thread, then no secondary process +* will initialise. +* - if a secondary process initialises successfully, trying to register a +* non-EAL thread from either primary or secondary processes will always end +* up with the thread getting LCORE_ID_ANY as lcore. +*/ +__rte_experimental +void +rte_thread_register (void ); + +/** +* Unregister current thread and release lcore if one was associated. +*/ +__rte_experimental +void +rte_thread_unregister (void ); +/** * Create a control thread. * lib/librte_eal/linux/eal.c +4
-0@@ -514,6 +514,10 @@ rte_config_init(void) }if (rte_eal_config_reattach () <0 )return -1 ; +if (!eal_mcfg_enable_multiprocess ()) { +RTE_LOG (ERR ,EAL ,"Primary process refused secondary attachment\n" ); +return -1 ; + }eal_mcfg_update_internal ();break ;case RTE_PROC_AUTO :lib/librte_eal/rte_eal_version.map +2
-0@@ -396,6 +396,8 @@ EXPERIMENTAL { # added in 20.08 __rte_trace_mem_per_thread_free; + rte_thread_register; + rte_thread_unregister; }; INTERNAL {lib/librte_mempool/rte_mempool.h +6
-6@@ -28,9 +28,9 @@* rte_mempool_get() or rte_mempool_put() are designed to be called from an EAL * thread due to the internal per-lcore cache. Due to the lack of caching, * rte_mempool_get() or rte_mempool_put() performance will suffer when called -* by non-EAL threads. Instead, non-EAL threads should call -* rte_mempool_generic_get() or rte_mempool_generic_put() with a user cache -* created with rte_mempool_cache_create(). +* by unregistered non-EAL threads. Instead, unregistered non-EAL threads +* should call rte_mempool_generic_get() or rte_mempool_generic_put() with a +* user cache created with rte_mempool_cache_create(). */ #include <stdio.h> @@ -1233,7 +1233,7 @@ void rte_mempool_dump(FILE *f, struct rte_mempool *mp);/** * Create a user-owned mempool cache. * -* This can be used by non-EAL threads to enable caching when they +* This can be used by unregistered non-EAL threads to enable caching when they * interact with a mempool. * * @param size @@ -1264,7 +1264,8 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache);* @param lcore_id * The logical core id. * @return -* A pointer to the mempool cache or NULL if disabled or non-EAL thread. +* A pointer to the mempool cache or NULL if disabled or unregistered non-EAL +* thread. */ static __rte_always_inline struct rte_mempool_cache *rte_mempool_default_cache (struct rte_mempool *mp,unsigned lcore_id) --2.23.0
Re: [dpdk-dev] [PATCH v4 6/9] eal: register non-EAL threads as lcores
In reply to David MarchandQuoted 50 lines · David Marchand
DPDK allows calling some part of its API from a non-EAL thread but this has some limitations.
OVS (and other applications) has its own thread management but still want to avoid such limitations by hackingRTE_PER_LCORE(_lcore_id)and faking EAL threads potentially unknown of some DPDK component.Introduce a new API to register non-EAL thread and associate them to a free lcore with a new
NON_EALrole.
This role denotes lcores that do not run DPDK mainloop and as such prevents use ofrte_eal_wait_lcore()and consorts.Multiprocess is not supported as the need for cohabitation with this new feature is unclear at the moment.
Signed-off-by David Marchand <[email protected]>Acked-by Andrew Rybchenko <[email protected]>---
Changes since v2:
- refused multiprocess init oncerte_thread_registergot called, and vice versa,
- added warning on multiprocess inrte_thread_registerdoxygen,Changes since v1:
- moved cleanup on lcore role code in patch 5,
- added unit test,
- updated documentation,
- changed naming from "external thread" to "registered non-EAL thread"--- MAINTAINERS | 1 + app/test/Makefile | 1 + app/test/autotest_data.py | 6 + app/test/meson.build | 2 + app/test/test_lcores.c | 139 ++++++++++++++++++ doc/guides/howto/debug_troubleshoot.rst | 5 +- .../prog_guide/env_abstraction_layer.rst | 22 +-- doc/guides/prog_guide/mempool_lib.rst | 2 +- lib/librte_eal/common/eal_common_lcore.c | 50 ++++++- lib/librte_eal/common/eal_common_mcfg.c | 36 +++++ lib/librte_eal/common/eal_common_thread.c | 33 +++++ lib/librte_eal/common/eal_memcfg.h | 10 ++ lib/librte_eal/common/eal_private.h | 18 +++ lib/librte_eal/freebsd/eal.c | 4 + lib/librte_eal/include/rte_lcore.h | 25 +++- lib/librte_eal/linux/eal.c | 4 + lib/librte_eal/rte_eal_version.map | 2 + lib/librte_mempool/rte_mempool.h | 11 +- 18 files changed, 349 insertions(+), 22 deletions(-) create mode 100644 app/test/test_lcores.c
[...]
Quoted 15 lines
app/test/test_lcores.c new file +9
-0@@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2020 Red Hat, Inc. +*/ + +#include <pthread.h> +#include <string.h> + +#include <rte_lcore.h> +
app/test/test_lcores.c line 19
Quoted 10 lines
app/test/test_lcores.c new file +10
-0+#include "test.h" + +struct thread_context { +enum {INIT ,ERROR ,DONE } state; +bool lcore_id_any; +pthread_t id; +unsigned int *registered_count; +}; +static void *thread_loop (void *arg) +{
missing an empty line here
Quoted 6 lines
app/test/test_lcores.c new file +6
-0+struct thread_context *t = arg; +unsigned int lcore_id; + + lcore_id =rte_lcore_id (); +if (lcore_id !=LCORE_ID_ANY ) { +printf ("Incorrect lcore id for new thread %u\n" , lcore_id);
app/test/test_lcores.c line 35
Quoted 10 lines
app/test/test_lcores.c new file +10
-0+ t->state =ERROR ; + } +rte_thread_register (); + lcore_id =rte_lcore_id (); +if ((t->lcore_id_any && lcore_id !=LCORE_ID_ANY ) || + (!t->lcore_id_any && lcore_id ==LCORE_ID_ANY )) { +printf ("Could not register new thread, got %u while %sexpecting %u\n" , + lcore_id, t->lcore_id_any ?"" :"not " ,LCORE_ID_ANY ); + t->state =ERROR ; + }
To check if rte_thread_register() succedeed, we need to look at lcore_id. I wonder if rte_thread_register() shouldn't return the lcore id on success, and -1 on error (rte_errno could be set to give some info on the error).
The same could be done for rte_thread_init()
[...]
Quoted 18 lines
lib/librte_eal/common/eal_common_thread.c +10
-0@@ -236,3 +236,36 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_join (*thread,NULL );return -ret; } + +void +rte_thread_register (void ) +{ +unsigned int lcore_id; +rte_cpuset_t cpuset; + +/* EAL init flushes all lcores, we can't register before. */ +assert (internal_config.init_complete ==1 ); + if (pthread_getaffinity_np(pthread_self(), sizeof(cpuset),
lib/librte_eal/common/eal_common_thread.c rte_ctrl_thread_create(pthread_t *thread, const char *name, · line 258
Quoted 10 lines
lib/librte_eal/common/eal_common_thread.c +10
-0+ &cpuset) != 0) +CPU_ZERO (&cpuset); + lcore_id =eal_lcore_non_eal_allocate (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ; +rte_thread_init (lcore_id, &cpuset); +if (lcore_id !=LCORE_ID_ANY ) +RTE_LOG (DEBUG ,EAL ,"Registered non-EAL thread as lcore %u.\n" , + lcore_id); +}
So, in this case, the affinity of the pthread is kept and saved, in other words there is no link between the lcore id and the affinity. It means we are allowing an application to register lcores for dataplane with conflicting affinities.
I wonder if it could be useful to have an API that automatically sets the affinity according to the lcore_id. Or a function that creates a pthread using the specified lcore id, and setting the correct affinity. I could simplify the work for applications that want to create/destroy dataplane threads dynamically.
This could be done later however, just an idea.
[...]
Quoted 20 lines
lib/librte_eal/freebsd/eal.c +4
-0@@ -424,6 +424,10 @@ rte_config_init(void) }if (rte_eal_config_reattach () <0 )return -1 ; +if (!eal_mcfg_enable_multiprocess ()) { +RTE_LOG (ERR ,EAL ,"Primary process refused secondary attachment\n" ); +return -1 ; + }eal_mcfg_update_internal ();break ;case RTE_PROC_AUTO :lib/librte_eal/include/rte_lcore.h +0
-0
lib/librte_eal/include/rte_lcore.h enum rte_lcore_role_t { · line 35
Quoted 5 lines
lib/librte_eal/include/rte_lcore.h +1
-0@@ -31,6 +31,7 @@ enum rte_lcore_role_t {ROLE_RTE ,ROLE_OFF ,ROLE_SERVICE , + ROLE_NON_EAL, };
If find the name ROLE_NON_EAL a bit heavy (this was also my impression when reading the doc part).
I understand that there are several types of threads:
- eal (pthread created by eal): ROLE_RTE and ROLE_SERVICE
- unregistered (pthread not created by eal, and not registered): ROLE_OFF (note that ROLE_OFF also applies for unexistant threads)
- dynamic: pthread not created by eal, but registered
What about using ROLE_DYN ? I'm not sure about this name either, it's just to open the discussion :)
Re: [dpdk-dev] [PATCH v4 6/9] eal: register non-EAL threads as lcores
Quoted 100 lines · Olivier Matz
Quoted 50 lines · David Marchand
DPDK allows calling some part of its API from a non-EAL thread but this has some limitations.
OVS (and other applications) has its own thread management but still want to avoid such limitations by hackingRTE_PER_LCORE(_lcore_id)and faking EAL threads potentially unknown of some DPDK component.Introduce a new API to register non-EAL thread and associate them to a free lcore with a new
NON_EALrole.
This role denotes lcores that do not run DPDK mainloop and as such prevents use ofrte_eal_wait_lcore()and consorts.Multiprocess is not supported as the need for cohabitation with this new feature is unclear at the moment.
Signed-off-by David Marchand <[email protected]>Acked-by Andrew Rybchenko <[email protected]>---
Changes since v2:
- refused multiprocess init oncerte_thread_registergot called, and vice versa,
- added warning on multiprocess inrte_thread_registerdoxygen,Changes since v1:
- moved cleanup on lcore role code in patch 5,
- added unit test,
- updated documentation,
- changed naming from "external thread" to "registered non-EAL thread"--- MAINTAINERS | 1 + app/test/Makefile | 1 + app/test/autotest_data.py | 6 + app/test/meson.build | 2 + app/test/test_lcores.c | 139 ++++++++++++++++++ doc/guides/howto/debug_troubleshoot.rst | 5 +- .../prog_guide/env_abstraction_layer.rst | 22 +-- doc/guides/prog_guide/mempool_lib.rst | 2 +- lib/librte_eal/common/eal_common_lcore.c | 50 ++++++- lib/librte_eal/common/eal_common_mcfg.c | 36 +++++ lib/librte_eal/common/eal_common_thread.c | 33 +++++ lib/librte_eal/common/eal_memcfg.h | 10 ++ lib/librte_eal/common/eal_private.h | 18 +++ lib/librte_eal/freebsd/eal.c | 4 + lib/librte_eal/include/rte_lcore.h | 25 +++- lib/librte_eal/linux/eal.c | 4 + lib/librte_eal/rte_eal_version.map | 2 + lib/librte_mempool/rte_mempool.h | 11 +- 18 files changed, 349 insertions(+), 22 deletions(-) create mode 100644 app/test/test_lcores.c[...]
Quoted 15 lines
app/test/test_lcores.c new file +9
-0@@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2020 Red Hat, Inc. +*/ + +#include <pthread.h> +#include <string.h> + +#include <rte_lcore.h> +app/test/test_lcores.c line 19
Quoted 10 lines
app/test/test_lcores.c new file +10
-0+#include "test.h" + +struct thread_context { +enum {INIT ,ERROR ,DONE } state; +bool lcore_id_any; +pthread_t id; +unsigned int *registered_count; +}; +static void *thread_loop (void *arg) +{missing an empty line here
Quoted 6 lines
app/test/test_lcores.c new file +6
-0+struct thread_context *t = arg; +unsigned int lcore_id; + + lcore_id =rte_lcore_id (); +if (lcore_id !=LCORE_ID_ANY ) { +printf ("Incorrect lcore id for new thread %u\n" , lcore_id);app/test/test_lcores.c line 35
Quoted 10 lines
app/test/test_lcores.c new file +10
-0+ t->state =ERROR ; + } +rte_thread_register (); + lcore_id =rte_lcore_id (); +if ((t->lcore_id_any && lcore_id !=LCORE_ID_ANY ) || + (!t->lcore_id_any && lcore_id ==LCORE_ID_ANY )) { +printf ("Could not register new thread, got %u while %sexpecting %u\n" , + lcore_id, t->lcore_id_any ?"" :"not " ,LCORE_ID_ANY ); + t->state =ERROR ; + }
Quoted 4 lines
To check if
rte_thread_register()succedeed, we need to look atlcore_id. I wonder ifrte_thread_register()shouldn't return the lcore id on success, and -1 on error (rte_errnocould be set to give some info on the error).
lcore_id are unsigned integers with the special value LCORE_ID_ANY mapped to UINT32_MAX (should be UINT_MAX? anyway...).
rte_thread_register could return an error code as there are no ERROR level logs about why a lcore allocation failed.
We could then distinguish a shortage of lcore (or init callback refusal) from an invalid call before rte_eal_init() or when mp is in use.
About returning the lcore_id as part of the return code, this would map to -1 for LCORE_ID_ANY.
This is probably not a problem but still odd.
Quoted 2 lines
The same could be done for
rte_thread_init()
?
Not sure where this one could fail.
Quoted 28 lines
[...]
Quoted 25 lines
lib/librte_eal/common/eal_common_thread.c +17
-0@@ -236,3 +236,36 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_join (*thread,NULL );return -ret; } + +void +rte_thread_register (void ) +{ +unsigned int lcore_id; +rte_cpuset_t cpuset; + +/* EAL init flushes all lcores, we can't register before. */ +assert (internal_config.init_complete ==1 ); +if (pthread_getaffinity_np (pthread_self (),sizeof (cpuset), + &cpuset) !=0 ) +CPU_ZERO (&cpuset); + lcore_id =eal_lcore_non_eal_allocate (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ; +rte_thread_init (lcore_id, &cpuset); +if (lcore_id !=LCORE_ID_ANY )
Quoted 8 lines
lib/librte_eal/common/eal_common_thread.c rte_ctrl_thread_create(pthread_t *thread, const char *name, · line 258
Quoted 3 lines
lib/librte_eal/common/eal_common_thread.c +3
-0+RTE_LOG (DEBUG ,EAL ,"Registered non-EAL thread as lcore %u.\n" , + lcore_id); +}So, in this case, the affinity of the pthread is kept and saved, in other words there is no link between the lcore id and the affinity. It means we are allowing an application to register lcores for dataplane with conflicting affinities.
This is not something new, applications using --lcores option already live with this.
We have warnings in the documentation about non-EAL threads and about the dangers of conflicting affinities.
Hopefully, the users of this API know what they are doing since they chose not to use EAL threads.
Quoted 6 lines
I wonder if it could be useful to have an API that automatically sets the affinity according to the
lcore_id. Or a function that creates a pthread using the specified lcore id, and setting the correct affinity. I could simplify the work for applications that want to create/destroy dataplane threads dynamically.
Do you mean EAL threads dynamic creation/suppression?
Quoted 2 lines
This could be done later however, just an idea.
For now, I don't see the need.
Quoted 31 lines
[...]
Quoted 20 lines
lib/librte_eal/freebsd/eal.c +4
-0@@ -424,6 +424,10 @@ rte_config_init(void) }if (rte_eal_config_reattach () <0 )return -1 ; +if (!eal_mcfg_enable_multiprocess ()) { +RTE_LOG (ERR ,EAL ,"Primary process refused secondary attachment\n" ); +return -1 ; + }eal_mcfg_update_internal ();break ;case RTE_PROC_AUTO :lib/librte_eal/include/rte_lcore.h +0
-0lib/librte_eal/include/rte_lcore.h enum rte_lcore_role_t { · line 35
Quoted 5 lines
lib/librte_eal/include/rte_lcore.h +1
-0@@ -31,6 +31,7 @@ enum rte_lcore_role_t {ROLE_RTE ,ROLE_OFF ,ROLE_SERVICE , + ROLE_NON_EAL, };If find the name
ROLE_NON_EALa bit heavy (this was also my impression when reading the doc part).
Quoted 6 lines
I understand that there are several types of threads:
- eal (pthread created by eal):
ROLE_RTEandROLE_SERVICE
- unregistered (pthread not created by eal, and not registered):ROLE_OFF(note thatROLE_OFFalso applies for unexistant threads)
- dynamic: pthread not created by eal, but registered
Last two cases both are non-EAL threads as described in the doc so far.
Quoted 4 lines
What about using
ROLE_DYN? I'm not sure about this name either, it's just to open the discussion :)
Well, at the moment, all those new lcores are mapped only to non-EAL threads. A dynamic role feels like you want to take dynamic EAL threads into account from the start.
I prefer to stick to non-EAL.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v4 6/9] eal: register non-EAL threads as lcores
Quoted 115 lines · David Marchand
Quoted 100 lines · Olivier Matz
Quoted 50 lines · David Marchand
DPDK allows calling some part of its API from a non-EAL thread but this has some limitations.
OVS (and other applications) has its own thread management but still want to avoid such limitations by hackingRTE_PER_LCORE(_lcore_id)and faking EAL threads potentially unknown of some DPDK component.Introduce a new API to register non-EAL thread and associate them to a free lcore with a new
NON_EALrole.
This role denotes lcores that do not run DPDK mainloop and as such prevents use ofrte_eal_wait_lcore()and consorts.Multiprocess is not supported as the need for cohabitation with this new feature is unclear at the moment.
Signed-off-by David Marchand <[email protected]>Acked-by Andrew Rybchenko <[email protected]>---
Changes since v2:
- refused multiprocess init oncerte_thread_registergot called, and vice versa,
- added warning on multiprocess inrte_thread_registerdoxygen,Changes since v1:
- moved cleanup on lcore role code in patch 5,
- added unit test,
- updated documentation,
- changed naming from "external thread" to "registered non-EAL thread"--- MAINTAINERS | 1 + app/test/Makefile | 1 + app/test/autotest_data.py | 6 + app/test/meson.build | 2 + app/test/test_lcores.c | 139 ++++++++++++++++++ doc/guides/howto/debug_troubleshoot.rst | 5 +- .../prog_guide/env_abstraction_layer.rst | 22 +-- doc/guides/prog_guide/mempool_lib.rst | 2 +- lib/librte_eal/common/eal_common_lcore.c | 50 ++++++- lib/librte_eal/common/eal_common_mcfg.c | 36 +++++ lib/librte_eal/common/eal_common_thread.c | 33 +++++ lib/librte_eal/common/eal_memcfg.h | 10 ++ lib/librte_eal/common/eal_private.h | 18 +++ lib/librte_eal/freebsd/eal.c | 4 + lib/librte_eal/include/rte_lcore.h | 25 +++- lib/librte_eal/linux/eal.c | 4 + lib/librte_eal/rte_eal_version.map | 2 + lib/librte_mempool/rte_mempool.h | 11 +- 18 files changed, 349 insertions(+), 22 deletions(-) create mode 100644 app/test/test_lcores.c[...]
Quoted 15 lines
app/test/test_lcores.c new file +9
-0@@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2020 Red Hat, Inc. +*/ + +#include <pthread.h> +#include <string.h> + +#include <rte_lcore.h> +app/test/test_lcores.c line 19
Quoted 10 lines
app/test/test_lcores.c new file +10
-0+#include "test.h" + +struct thread_context { +enum {INIT ,ERROR ,DONE } state; +bool lcore_id_any; +pthread_t id; +unsigned int *registered_count; +}; +static void *thread_loop (void *arg) +{missing an empty line here
Quoted 6 lines
app/test/test_lcores.c new file +6
-0+struct thread_context *t = arg; +unsigned int lcore_id; + + lcore_id =rte_lcore_id (); +if (lcore_id !=LCORE_ID_ANY ) { +printf ("Incorrect lcore id for new thread %u\n" , lcore_id);app/test/test_lcores.c line 35
Quoted 10 lines
app/test/test_lcores.c new file +10
-0+ t->state =ERROR ; + } +rte_thread_register (); + lcore_id =rte_lcore_id (); +if ((t->lcore_id_any && lcore_id !=LCORE_ID_ANY ) || + (!t->lcore_id_any && lcore_id ==LCORE_ID_ANY )) { +printf ("Could not register new thread, got %u while %sexpecting %u\n" , + lcore_id, t->lcore_id_any ?"" :"not " ,LCORE_ID_ANY ); + t->state =ERROR ; + }Quoted 4 lines
To check if
rte_thread_register()succedeed, we need to look atlcore_id. I wonder ifrte_thread_register()shouldn't return the lcore id on success, and -1 on error (rte_errnocould be set to give some info on the error).
lcore_idare unsigned integers with the special valueLCORE_ID_ANYmapped toUINT32_MAX(should beUINT_MAX? anyway...).
rte_thread_registercould return an error code as there are no ERROR level logs about why a lcore allocation failed.
We could then distinguish a shortage of lcore (or init callback refusal) from an invalid call beforerte_eal_init()or when mp is in use.
Quoted 3 lines
About returning the
lcore_idas part of the return code, this would map to -1 forLCORE_ID_ANY.
This is probably not a problem but still odd.
Yes, it would be a bit odd like this. What about changing the definition of LCORE_ID_ANY to ((unsigned int)-1) ? I think it does not change the effective value on any architecture, but would make the above change clearer.
Quoted 5 lines
Quoted 2 lines
The same could be done for
rte_thread_init()?
Not sure where this one could fail.
I was thinking about __rte_trace_mem_per_thread_alloc(), but maybe it's not needed.
Quoted 92 lines
Quoted 28 lines
[...]
Quoted 25 lines
lib/librte_eal/common/eal_common_thread.c +17
-0@@ -236,3 +236,36 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_join (*thread,NULL );return -ret; } + +void +rte_thread_register (void ) +{ +unsigned int lcore_id; +rte_cpuset_t cpuset; + +/* EAL init flushes all lcores, we can't register before. */ +assert (internal_config.init_complete ==1 ); +if (pthread_getaffinity_np (pthread_self (),sizeof (cpuset), + &cpuset) !=0 ) +CPU_ZERO (&cpuset); + lcore_id =eal_lcore_non_eal_allocate (); +if (lcore_id >=RTE_MAX_LCORE ) + lcore_id =LCORE_ID_ANY ; +rte_thread_init (lcore_id, &cpuset); +if (lcore_id !=LCORE_ID_ANY )Quoted 8 lines
lib/librte_eal/common/eal_common_thread.c rte_ctrl_thread_create(pthread_t *thread, const char *name, · line 258
Quoted 3 lines
lib/librte_eal/common/eal_common_thread.c +3
-0+RTE_LOG (DEBUG ,EAL ,"Registered non-EAL thread as lcore %u.\n" , + lcore_id); +}So, in this case, the affinity of the pthread is kept and saved, in other words there is no link between the lcore id and the affinity. It means we are allowing an application to register lcores for dataplane with conflicting affinities.
This is not something new, applications using --lcores option already live with this.
We have warnings in the documentation about non-EAL threads and about the dangers of conflicting affinities.
Hopefully, the users of this API know what they are doing since they chose not to use EAL threads.Quoted 6 lines
I wonder if it could be useful to have an API that automatically sets the affinity according to the
lcore_id. Or a function that creates a pthread using the specified lcore id, and setting the correct affinity. I could simplify the work for applications that want to create/destroy dataplane threads dynamically.Do you mean EAL threads dynamic creation/suppression?
Quoted 2 lines
This could be done later however, just an idea.
For now, I don't see the need.
Quoted 31 lines
[...]
Quoted 20 lines
lib/librte_eal/freebsd/eal.c +4
-0@@ -424,6 +424,10 @@ rte_config_init(void) }if (rte_eal_config_reattach () <0 )return -1 ; +if (!eal_mcfg_enable_multiprocess ()) { +RTE_LOG (ERR ,EAL ,"Primary process refused secondary attachment\n" ); +return -1 ; + }eal_mcfg_update_internal ();break ;case RTE_PROC_AUTO :lib/librte_eal/include/rte_lcore.h +0
-0lib/librte_eal/include/rte_lcore.h enum rte_lcore_role_t { · line 35
Quoted 5 lines
lib/librte_eal/include/rte_lcore.h +1
-0@@ -31,6 +31,7 @@ enum rte_lcore_role_t {ROLE_RTE ,ROLE_OFF ,ROLE_SERVICE , + ROLE_NON_EAL, };If find the name
ROLE_NON_EALa bit heavy (this was also my impression when reading the doc part).
Quoted 8 lines
Quoted 6 lines
I understand that there are several types of threads:
- eal (pthread created by eal):
ROLE_RTEandROLE_SERVICE
- unregistered (pthread not created by eal, and not registered):ROLE_OFF(note thatROLE_OFFalso applies for unexistant threads)
- dynamic: pthread not created by eal, but registeredLast two cases both are non-EAL threads as described in the doc so far.
Yes, but only the last case has the NON_EAL role.
I feel that currently role != thread_type, so may be a bit confusing to use a pthread_type name in the role enum.
Quoted 16 lines
Quoted 6 lines
What about using
ROLE_DYN? I'm not sure about this name either, it's just to open the discussion :)Well, at the moment, all those new lcores are mapped only to non-EAL threads. A dynamic role feels like you want to take dynamic EAL threads into account from the start.
I prefer to stick to non-EAL.Signature · 1 line
David Marchand
PATCH v4 7/9 eal: add lcore init callbacks
In reply to David MarchandDPDK components and applications can have their say when a new lcore is initialized. For this, they can register a callback for initializing and releasing their private data.
---
Changes since v2:
- added missing test,
- fixed rollback on lcore register,
Changes since v1:
- added unit test (since missing some coverage, for v3),
- preferred callback and removed mention of notification,
--- app/test/test_lcores.c | 230 +++++++++++++++++++++++ lib/librte_eal/common/eal_common_lcore.c | 138 +++++++++++++- lib/librte_eal/common/eal_private.h | 3 +- lib/librte_eal/include/rte_lcore.h | 68 +++++++ lib/librte_eal/rte_eal_version.map | 2 + 5 files changed, 435 insertions(+), 6 deletions(-)
app/test/test_lcores.c +230 -0
@@ -5,6 +5,7 @@#include <pthread.h> #include <string.h> +#include <rte_common.h> #include <rte_lcore.h> #include "test.h"
@@ -113,6 +114,229 @@ test_non_eal_lcores(unsigned int eal_threads_count)return ret; } +struct limit_lcore_context { +unsigned int init; +unsigned int max; +unsigned int uninit; +}; +static int +limit_lcores_init(unsigned int lcore_id __rte_unused, void *arg) +{ +struct limit_lcore_context *l = arg; + + l->init++; +if (l->init > l->max) +return -1 ; +return 0 ; +} +static void +limit_lcores_uninit(unsigned int lcore_id __rte_unused, void *arg) +{ +struct limit_lcore_context *l = arg; + + l->uninit++; +} + +static int +test_lcores_callback (unsigned int eal_threads_count) +{ +struct limit_lcore_context l; +void *handle; + +/* Refuse last lcore => callback register error. */ +memset (&l,0 ,sizeof (l)); + l.max = eal_threads_count -1 ; + handle =rte_lcore_callback_register ("limit" , limit_lcores_init, + limit_lcores_uninit, &l); +if (handle !=NULL ) { +printf ("lcore callback register should have failed\n" ); + goto error; + } +/* Refusal happens at the n th call to the init callback. +* Besides, n - 1 were accepted, so we expect as many uninit calls when +* the rollback happens. +*/ +if (l.init != eal_threads_count) { +printf ("lcore callback register failed but incorrect init calls, expected %u, got %u\n" , + eal_threads_count, l.init); + goto error; + } +if (l.uninit != eal_threads_count -1 ) { +printf ("lcore callback register failed but incorrect uninit calls, expected %u, got %u\n" , + eal_threads_count -1 , l.uninit); + goto error; + } + +/* Accept all lcore and unregister. */ +memset (&l,0 ,sizeof (l)); + l.max = eal_threads_count; + handle =rte_lcore_callback_register ("limit" , limit_lcores_init, + limit_lcores_uninit, &l); +if (handle ==NULL ) { +printf ("lcore callback register failed\n" ); + goto error; + } +if (l.uninit !=0 ) { +printf ("lcore callback register succeeded but incorrect uninit calls, expected 0, got %u\n" , + l.uninit); + goto error; + } +rte_lcore_callback_unregister (handle); + handle =NULL ; +if (l.init != eal_threads_count) { +printf ("lcore callback unregister done but incorrect init calls, expected %u, got %u\n" , + eal_threads_count, l.init); + goto error; + } +if (l.uninit != eal_threads_count) { +printf ("lcore callback unregister done but incorrect uninit calls, expected %u, got %u\n" , + eal_threads_count, l.uninit); + goto error; + } + +return 0 ; + +error: +if (handle !=NULL ) +rte_lcore_callback_unregister (handle); + +return -1 ; +} + +static int +test_non_eal_lcores_callback (unsigned int eal_threads_count) +{ +struct thread_context thread_contexts[2 ]; +unsigned int non_eal_threads_count; +struct limit_lcore_context l[2 ]; +unsigned int registered_count; +struct thread_context *t; +void *handle[2 ]; +unsigned int i; +int ret; + +memset (l,0 ,sizeof (l)); + handle[0 ] = handle[1 ] =NULL ; + non_eal_threads_count =0 ; + registered_count =0 ; + +/* This test requires two empty slots to be sure lcore init refusal is +* because of callback execution. +*/ +if (eal_threads_count +2 >=RTE_MAX_LCORE ) +return 0 ; + +/* Register two callbacks: +* - first one accepts any lcore, +* - second one accepts all EAL lcore + one more for the first non-EAL +* thread, then refuses the next lcore. +*/ + l[0 ].max =UINT_MAX ; + handle[0 ] =rte_lcore_callback_register ("no_limit" , limit_lcores_init, + limit_lcores_uninit, &l[0 ]); +if (handle[0 ] ==NULL ) { +printf ("lcore callback [0] register failed\n" ); + goto error; + } + l[1 ].max = eal_threads_count +1 ; + handle[1 ] =rte_lcore_callback_register ("limit" , limit_lcores_init, + limit_lcores_uninit, &l[1 ]); +if (handle[1 ] ==NULL ) { +printf ("lcore callback [1] register failed\n" ); + goto error; + } +if (l[0 ].init != eal_threads_count || l[1 ].init != eal_threads_count) { +printf ("lcore callbacks register succeeded but incorrect init calls, expected %u, %u, got %u, %u\n" , + eal_threads_count, eal_threads_count, + l[0 ].init, l[1 ].init); + goto error; + } +if (l[0 ].uninit !=0 || l[1 ].uninit !=0 ) { +printf ("lcore callbacks register succeeded but incorrect uninit calls, expected 0, 1, got %u, %u\n" , + l[0 ].uninit, l[1 ].uninit); + goto error; + } +/* First thread that expects a valid lcore id. */ + t = &thread_contexts[0 ]; + t->state =INIT ; + t->registered_count = ®istered_count; + t->lcore_id_any = false; +if (pthread_create (&t->id,NULL , thread_loop, t) !=0 ) + goto cleanup_threads; + non_eal_threads_count++; +while (__atomic_load_n (®istered_count, __ATOMIC_ACQUIRE) != + non_eal_threads_count) + ; +if (l[0 ].init != eal_threads_count +1 || + l[1 ].init != eal_threads_count +1 ) { +printf ("Incorrect init calls, expected %u, %u, got %u, %u\n" , + eal_threads_count +1 , eal_threads_count +1 , + l[0 ].init, l[1 ].init); + goto cleanup_threads; + } +if (l[0 ].uninit !=0 || l[1 ].uninit !=0 ) { +printf ("Incorrect uninit calls, expected 0, 0, got %u, %u\n" , + l[0 ].uninit, l[1 ].uninit); + goto cleanup_threads; + } +/* Second thread, that expects LCORE_ID_ANY because of init refusal. */ + t = &thread_contexts[1 ]; + t->state =INIT ; + t->registered_count = ®istered_count; + t->lcore_id_any = true; +if (pthread_create (&t->id,NULL , thread_loop, t) !=0 ) + goto cleanup_threads; + non_eal_threads_count++; +while (__atomic_load_n (®istered_count, __ATOMIC_ACQUIRE) != + non_eal_threads_count) + ; +if (l[0 ].init != eal_threads_count +2 || + l[1 ].init != eal_threads_count +2 ) { +printf ("Incorrect init calls, expected %u, %u, got %u, %u\n" , + eal_threads_count +2 , eal_threads_count +2 , + l[0 ].init, l[1 ].init); + goto cleanup_threads; + } +if (l[0 ].uninit !=1 || l[1 ].uninit !=0 ) { +printf ("Incorrect uninit calls, expected 1, 0, got %u, %u\n" , + l[0 ].uninit, l[1 ].uninit); + goto cleanup_threads; + } +/* Release all threads, and check their states. */ +__atomic_store_n (®istered_count,0 , __ATOMIC_RELEASE); + ret =0 ; +for (i =0 ; i < non_eal_threads_count; i++) { + t = &thread_contexts[i]; +pthread_join (t->id,NULL ); +if (t->state !=DONE ) + ret =-1 ; + } +if (ret <0 ) + goto error; +if (l[0 ].uninit !=2 || l[1 ].uninit !=1 ) { +printf ("Threads reported having successfully registered and unregistered, but incorrect uninit calls, expected 2, 1, got %u, %u\n" , + l[0 ].uninit, l[1 ].uninit); + goto error; + } +rte_lcore_callback_unregister (handle[0 ]); +rte_lcore_callback_unregister (handle[1 ]); +return 0 ; + +cleanup_threads: +/* Release all threads */ +__atomic_store_n (®istered_count,0 , __ATOMIC_RELEASE); +for (i =0 ; i < non_eal_threads_count; i++) { + t = &thread_contexts[i]; +pthread_join (t->id,NULL ); + } +error: +if (handle[1 ] !=NULL ) +rte_lcore_callback_unregister (handle[1 ]); +if (handle[0 ] !=NULL ) +rte_lcore_callback_unregister (handle[0 ]); +return -1 ; +} +static int test_lcores (void ) {
@@ -133,6 +357,12 @@ test_lcores(void)if (test_non_eal_lcores (eal_threads_count) <0 )return TEST_FAILED ; +if (test_lcores_callback (eal_threads_count) <0 ) +return TEST_FAILED ; + +if (test_non_eal_lcores_callback (eal_threads_count) <0 ) +return TEST_FAILED ; +return TEST_SUCCESS ; }
lib/librte_eal/common/eal_common_lcore.c +133 -5
163 lines not on this page · raw message
lib/librte_eal/common/eal_private.h +2 -1
@@ -401,7 +401,8 @@ uint64_t get_tsc_freq_arch(void);* * @return * - the id of a lcore with role ROLE_NON_EAL on success. -* - RTE_MAX_LCORE if none was available. +* - RTE_MAX_LCORE if none was available or initializing was refused (see +* rte_lcore_callback_register). */ unsigned int eal_lcore_non_eal_allocate (void );
lib/librte_eal/include/rte_lcore.h +68 -0
74 lines not on this page · raw message
lib/librte_eal/rte_eal_version.map +2 -0
@@ -396,6 +396,8 @@ EXPERIMENTAL { # added in 20.08 __rte_trace_mem_per_thread_free; + rte_lcore_callback_register; + rte_lcore_callback_unregister; rte_thread_register; rte_thread_unregister; };
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v4 7/9] eal: add lcore init callbacks
Quoted 42 lines
lib/librte_eal/common/eal_common_lcore.c +32
-0@@ -224,11 +224,114 @@ rte_socket_id_by_idx(unsigned int idx) }static rte_spinlock_t lcore_lock =RTE_SPINLOCK_INITIALIZER ; +struct lcore_callback { +TAILQ_ENTRY (lcore_callback) next; +char *name; +rte_lcore_init_cb init; +rte_lcore_uninit_cb uninit; +void *arg; +}; +static TAILQ_HEAD(lcore_callbacks_head, lcore_callback) lcore_callbacks = +TAILQ_HEAD_INITIALIZER (lcore_callbacks); + +static int +callback_init (struct lcore_callback *callback,unsigned int lcore_id) +{ +if (callback->init ==NULL ) +return 0 ; +RTE_LOG (DEBUG ,EAL ,"Call init for lcore callback %s, lcore_id %u\n" , + callback->name, lcore_id); +return callback->init (lcore_id, callback->arg); +} + +static void +callback_uninit (struct lcore_callback *callback,unsigned int lcore_id) +{ +if (callback->uninit ==NULL ) +return ; +RTE_LOG (DEBUG ,EAL ,"Call uninit for lcore callback %s, lcore_id %u\n" , + callback->name, lcore_id); + callback->uninit (lcore_id, callback->arg); +} + +void * +rte_lcore_callback_register(const char *name, rte_lcore_init_cb init,
lib/librte_eal/common/eal_common_lcore.c rte_socket_id_by_idx(unsigned int idx) · line 268
Quoted 10 lines
lib/librte_eal/common/eal_common_lcore.c +10
-0+ rte_lcore_uninit_cb uninit, void *arg) +{ + struct rte_config *cfg = rte_eal_get_configuration(); +struct lcore_callback *callback; +unsigned int lcore_id; + + callback =calloc (1 ,sizeof (*callback)); +if (callback ==NULL ) +return NULL ; +if (asprintf (&callback->name,"%s-%p" , name, arg) ==-1 ) {
If name is null, I presume asprintf() would segfault, right? As this is a public (and control-plane) API, I think it is worth to add formal checking for input parameters.
Same for other new public functions.
Quoted 12 lines
lib/librte_eal/common/eal_common_lcore.c +12
-0+free (callback); +return NULL ; + } + callback->init = init; + callback->uninit = uninit; + callback->arg = arg; +rte_spinlock_lock (&lcore_lock); +if (callback->init ==NULL ) + goto no_init; +for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +if (cfg->lcore_role[lcore_id] ==ROLE_OFF ) +continue ;
lib/librte_eal/common/eal_common_lcore.c rte_socket_id_by_idx(unsigned int idx) · line 290
Quoted 10 lines
lib/librte_eal/common/eal_common_lcore.c +10
-0+if (callback_init (callback, lcore_id) ==0 ) +continue ; +/* Callback refused init for this lcore, uninitialize all +* previous lcore. +*/ +for (; lcore_id !=0 ; lcore_id--) { +if (cfg->lcore_role[lcore_id -1 ] ==ROLE_OFF ) +continue ; +callback_uninit (callback, lcore_id -1 ); + }
Just as a nit, you can do here instead:
while (lcore_id-- != 0) { if (cfg->lcore_role[lcore_id] == ROLE_OFF) ...} To avoid 'lcore_id -1' inside loop body.
Might look a bit nicer.
lib/librte_eal/common/eal_common_lcore.c rte_socket_id_by_idx(unsigned int idx) · line 291
Quoted 1 line
lib/librte_eal/common/eal_common_lcore.c +1
-0+free (callback);
I think you forgot:free(callback->name);
here.
Might be worth to have a separate helper function around these 2 frees.
Quoted 97 lines
lib/librte_eal/common/eal_common_lcore.c +68
-5+ callback =NULL ; + goto out; + } +no_init: +TAILQ_INSERT_TAIL (&lcore_callbacks, callback, next); +RTE_LOG (DEBUG ,EAL ,"Registered new lcore callback %s (%sinit, %suninit).\n" , + callback->name, callback->init ==NULL ?"NO " :"" , + callback->uninit ==NULL ?"NO " :"" ); +out: +rte_spinlock_unlock (&lcore_lock); +return callback; +} + +void +rte_lcore_callback_unregister (void *handle) +{ +struct rte_config *cfg =rte_eal_get_configuration (); +struct lcore_callback *callback = handle; +unsigned int lcore_id; + +rte_spinlock_lock (&lcore_lock); +if (callback->uninit ==NULL ) + goto no_uninit; +for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) { +if (cfg->lcore_role[lcore_id] ==ROLE_OFF ) +continue ; +callback_uninit (callback, lcore_id); + } +no_uninit: +TAILQ_REMOVE (&lcore_callbacks, callback, next); +rte_spinlock_unlock (&lcore_lock); +RTE_LOG (DEBUG ,EAL ,"Unregistered lcore callback %s-%p.\n" , + callback->name, callback->arg); +free (callback->name); +free (callback); +}unsigned int eal_lcore_non_eal_allocate (void ) {struct rte_config *cfg =rte_eal_get_configuration (); +struct lcore_callback *callback; +struct lcore_callback *prev;unsigned int lcore_id; if (cfg->process_type == RTE_PROC_SECONDARY ||@@ -244,8 +347,29 @@ eal_lcore_non_eal_allocate(void) cfg->lcore_count++;break ; } -if (lcore_id ==RTE_MAX_LCORE ) +if (lcore_id ==RTE_MAX_LCORE ) {RTE_LOG (DEBUG ,EAL ,"No lcore available.\n" ); + goto out; + } + TAILQ_FOREACH(callback, &lcore_callbacks, next) { +if (callback_init (callback, lcore_id) ==0 ) +continue ; +/* Callback refused init for this lcore, call uninit for all +* previous callbacks. +*/ + prev =TAILQ_PREV (callback, lcore_callbacks_head, next); +while (prev !=NULL ) { +callback_uninit (prev, lcore_id); + prev =TAILQ_PREV (prev, lcore_callbacks_head, next); + } +RTE_LOG (DEBUG ,EAL ,"Initialization refused for lcore %u.\n" , + lcore_id); + cfg->lcore_role[lcore_id] =ROLE_OFF ; + cfg->lcore_count--; + lcore_id =RTE_MAX_LCORE ; + goto out; + } +out:rte_spinlock_unlock (&lcore_lock);return lcore_id; }@@ -254,11 +378,15 @@ void eal_lcore_non_eal_release(unsigned int lcore_id) {struct rte_config *cfg =rte_eal_get_configuration (); +struct lcore_callback *callback;rte_spinlock_lock (&lcore_lock); -if (cfg->lcore_role[lcore_id] ==ROLE_NON_EAL ) { - cfg->lcore_role[lcore_id] =ROLE_OFF ; - cfg->lcore_count--; - } +if (cfg->lcore_role[lcore_id] !=ROLE_NON_EAL ) + goto out; + TAILQ_FOREACH(callback, &lcore_callbacks, next) +callback_uninit (callback, lcore_id); + cfg->lcore_role[lcore_id] =ROLE_OFF ; + cfg->lcore_count--; +out:rte_spinlock_unlock (&lcore_lock); }
Re: [dpdk-dev] [PATCH v4 7/9] eal: add lcore init callbacks
In reply to David MarchandQuoted 5 lines · David Marchand
DPDK components and applications can have their say when a new lcore is initialized. For this, they can register a callback for initializing and releasing their private data.
Signed-off-by David Marchand <[email protected]>
[...]
Quoted 10 lines
+/**
+ * Register callbacks invoked when initializing and uninitializing a lcore.
+ *
+ * This function calls the init callback with all initialized lcores.
+ * Any error reported by the init callback triggers a rollback calling the
+ * uninit callback for each lcore.
+ * If this step succeeds, the callbacks are put in the lcore callbacks list
+ * that will get called for each lcore allocation/release.
+ *
+ * Note: callbacks execution is serialised under a lock protecting the lcores
Quoted 8 lines
+ * and callbacks list.
+ *
+ * @param name
+ * A name serving as a small description for this callback.
+ * @param init
+ * The callback invoked when alcore_idis initialized.
+ * @param uninit
+ * The callback invoked when alcore_idis uninitialized.
nit: it could be highlighted that init or uninit can be NULL.
Quoted 12 lines
+ * @param arg
+ * An optional argument that gets passed to the callback when it gets
+ * invoked.
+ * @return+ * On success, returns an opaque pointer for the registered object. + * On failure (either memory allocation issue in the function itself or an + * error is returned by the init callback itself), returns NULL.+ */
lib/librte_eal/include/rte_lcore.h +4
-0+__rte_experimental +void * +rte_lcore_callback_register (const char *name,rte_lcore_init_cb init, +rte_lcore_uninit_cb uninit,void *arg);
Re: [dpdk-dev] [PATCH v4 7/9] eal: add lcore init callbacks
In reply to David MarchandQuoted 5 lines · David Marchand
DPDK components and applications can have their say when a new lcore is initialized. For this, they can register a callback for initializing and releasing their private data.
Signed-off-by David Marchand <[email protected]>
2 more minor comments.
Quoted 28 lines
app/test/test_lcores.c +13
-0@@ -5,6 +5,7 @@#include <pthread.h> #include <string.h> +#include <rte_common.h> #include <rte_lcore.h> #include "test.h" @@ -113,6 +114,229 @@ test_non_eal_lcores(unsigned int eal_threads_count)return ret; } +struct limit_lcore_context { +unsigned int init; +unsigned int max; +unsigned int uninit; +}; +static int +limit_lcores_init(unsigned int lcore_id __rte_unused, void *arg) +{ +struct limit_lcore_context *l = arg; + + l->init++; +if (l->init > l->max)
app/test/test_lcores.c test_non_eal_lcores(unsigned int eal_threads_count) · line 138
Quoted 10 lines
app/test/test_lcores.c +10
-0+return -1 ; +return 0 ; +} +static void +limit_lcores_uninit(unsigned int lcore_id __rte_unused, void *arg) +{ +struct limit_lcore_context *l = arg; + + l->uninit++; +}
missing empty lines
[...]
Quoted 7 lines
app/test/test_lcores.c +7
-0+static int +test_non_eal_lcores_callback (unsigned int eal_threads_count) +{ +struct thread_context thread_contexts[2 ]; +unsigned int non_eal_threads_count; +struct limit_lcore_context l[2 ]; +unsigned int registered_count;
app/test/test_lcores.c test_non_eal_lcores(unsigned int eal_threads_count) · line 222
Quoted 10 lines
app/test/test_lcores.c +10
-0+struct thread_context *t; +void *handle[2 ]; +unsigned int i; +int ret; + +memset (l,0 ,sizeof (l)); + handle[0 ] = handle[1 ] =NULL ; + non_eal_threads_count =0 ; + registered_count =0 ; +
what about initializing it at declaration?
struct thread_context thread_contexts[2] = {};
struct limit_lcore_context l[2] = {};
void *handle[2] = {};PATCH v4 8/9 eal: add lcore iterators
In reply to David MarchandAdd a helper to iterate all lcores.
The iterator callback is read-only wrt the lcores list.
Implement a dump function on top of this for debugging.
---
Changes since v2:
- added rte_lcore_dump calls in unit test, for basic check,
Changes since v1:
- introduced lcore iterators and implemented rte_lcore_dump, this iterator mechanism can then be used outside of EAL,
--- app/test/test_lcores.c | 3 + lib/librte_eal/common/eal_common_lcore.c | 77 ++++++++++++++++++++--- lib/librte_eal/common/eal_common_thread.c | 16 +++-- lib/librte_eal/common/eal_thread.h | 13 +++- lib/librte_eal/freebsd/eal.c | 2 +- lib/librte_eal/freebsd/eal_thread.c | 2 +- lib/librte_eal/include/rte_lcore.h | 47 +++++++++++++- lib/librte_eal/linux/eal.c | 2 +- lib/librte_eal/linux/eal_thread.c | 2 +- lib/librte_eal/rte_eal_version.map | 2 + 10 files changed, 143 insertions(+), 23 deletions(-)
app/test/test_lcores.c +3 -0
@@ -302,6 +302,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count) l[0].uninit, l[1].uninit); goto cleanup_threads; } +rte_lcore_dump (stdout);/* Release all threads, and check their states. */ __atomic_store_n (®istered_count,0 , __ATOMIC_RELEASE); ret =0 ;
@@ -313,6 +314,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count) }if (ret <0 ) goto error; +rte_lcore_dump (stdout);if (l[0 ].uninit !=2 || l[1 ].uninit !=1 ) {printf ("Threads reported having successfully registered and unregistered, but incorrect uninit calls, expected 2, 1, got %u, %u\n" , l[0 ].uninit, l[1 ].uninit);
@@ -353,6 +355,7 @@ test_lcores(void) }printf ("EAL threads count: %u, RTE_MAX_LCORE=%u\n" , eal_threads_count,RTE_MAX_LCORE ); +rte_lcore_dump (stdout);if (test_non_eal_lcores (eal_threads_count) <0 )return TEST_FAILED ;
lib/librte_eal/common/eal_common_lcore.c +67 -10
135 lines not on this page · raw message
lib/librte_eal/common/eal_common_thread.c +11 -5
@@ -104,17 +104,14 @@ rte_thread_get_affinity(rte_cpuset_t *cpusetp) }int -eal_thread_dump_affinity (char *str,unsigned size) +eal_thread_dump_affinity (rte_cpuset_t *cpuset,char *str,unsigned int size) { -rte_cpuset_t cpuset;unsigned cpu;int ret;unsigned int out =0 ; -rte_thread_get_affinity (&cpuset); -for (cpu =0 ; cpu <CPU_SETSIZE ; cpu++) { -if (!CPU_ISSET (cpu, &cpuset)) +if (!CPU_ISSET (cpu, cpuset))continue ; ret = snprintf(str + out,
@@ -137,6 +134,15 @@ eal_thread_dump_affinity(char *str, unsigned size)return ret; } +int +eal_thread_dump_current_affinity (char *str,unsigned int size) +{ +rte_cpuset_t cpuset; + +rte_thread_get_affinity (&cpuset); +return eal_thread_dump_affinity (&cpuset, str, size); +} +void rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) {
lib/librte_eal/common/eal_thread.h +11 -2
@@ -47,13 +47,15 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);#define RTE_CPU_AFFINITY_STR_LEN 256/** -* Dump the current pthread cpuset. +* Dump the cpuset as a human readable string. * This function is private to EAL. * * Note: * If the dump size is greater than the size of given buffer, * the string will be truncated and with '\0' at the end. * +* @param cpuset +* The CPU affinity object to dump. * @param str * The string buffer the cpuset will dump to. * @param size
@@ -62,6 +64,13 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);* 0 for success, -1 if truncation happens. */ int -eal_thread_dump_affinity (char *str,unsigned size); +eal_thread_dump_affinity (rte_cpuset_t *cpuset,char *str,unsigned int size); + +/** +* Dump the current thread cpuset. +* This is a wrapper on eal_thread_dump_affinity(). +*/ +int +eal_thread_dump_current_affinity (char *str,unsigned int size);#endif /* EAL_THREAD_H */
lib/librte_eal/freebsd/eal.c +1 -1
@@ -890,7 +890,7 @@ rte_eal_init(int argc, char **argv)rte_thread_init (rte_config.master_lcore, &lcore_config[rte_config.master_lcore].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset)); RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n", rte_config.master_lcore, thread_id, cpuset,
lib/librte_eal/freebsd/eal_thread.c +1 -1
@@ -92,7 +92,7 @@ eal_thread_loop(__rte_unused void *arg)rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , lcore_id, thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/include/rte_lcore.h +45 -2
59 lines not on this page · raw message
lib/librte_eal/linux/eal.c +1 -1
@@ -1218,7 +1218,7 @@ rte_eal_init(int argc, char **argv)rte_thread_init (rte_config.master_lcore, &lcore_config[rte_config.master_lcore].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , rte_config.master_lcore, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/linux/eal_thread.c +1 -1
@@ -92,7 +92,7 @@ eal_thread_loop(__rte_unused void *arg)rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); - ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); + ret =eal_thread_dump_current_affinity (cpuset,sizeof (cpuset));RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
lib/librte_eal/rte_eal_version.map +2 -0
@@ -398,6 +398,8 @@ EXPERIMENTAL { __rte_trace_mem_per_thread_free; rte_lcore_callback_register; rte_lcore_callback_unregister; + rte_lcore_dump; + rte_lcore_iterate; rte_thread_register; rte_thread_unregister; };
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v4 8/9] eal: add lcore iterators
Quoted 6 lines · David Marchand
Add a helper to iterate all lcores.
The iterator callback is read-only wrt the lcores list.Implement a dump function on top of this for debugging.
Signed-off-by David Marchand <[email protected]>
PATCH v4 9/9 mempool/bucket: handle non-EAL lcores
In reply to David MarchandConvert to new lcore API to support non-EAL lcores.
---
Changes since v3:
- addressed Andrew comments,
--- drivers/mempool/bucket/rte_mempool_bucket.c | 130 ++++++++++++-------- 1 file changed, 81 insertions(+), 49 deletions(-)
drivers/mempool/bucket/rte_mempool_bucket.c +81 -49
@@ -55,6 +55,7 @@ struct bucket_data {struct rte_ring *shared_orphan_ring;struct rte_mempool *pool;unsigned int bucket_mem_size; +void *lcore_callback_handle; }; static struct bucket_stack *
@@ -345,6 +346,23 @@ bucket_dequeue_contig_blocks(struct rte_mempool *mp, void **first_obj_table,return 0 ; } +struct bucket_count_per_lcore_ctx { +const struct bucket_data *bd; +unsigned int count; +}; + +static int +bucket_count_per_lcore (unsigned int lcore_id,void *arg) +{ +struct bucket_count_per_lcore_ctx *bplc = arg; + + bplc->count += bplc->bd->obj_per_bucket * + bplc->bd->buckets[lcore_id]->top; + bplc->count += +rte_ring_count (bplc->bd->adoption_buffer_rings[lcore_id]); +return 0 ; +} + static void count_underfilled_buckets(struct rte_mempool *mp, void *opaque,
@@ -373,23 +391,64 @@ count_underfilled_buckets(struct rte_mempool *mp,static unsigned int bucket_get_count (const struct rte_mempool *mp) { -const struct bucket_data *bd = mp->pool_data; -unsigned int count = - bd->obj_per_bucket *rte_ring_count (bd->shared_bucket_ring) + -rte_ring_count (bd->shared_orphan_ring); -unsigned int i; +struct bucket_count_per_lcore_ctx bplc; -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (!rte_lcore_is_enabled (i)) -continue ; - count += bd->obj_per_bucket * bd->buckets[i]->top + -rte_ring_count (bd->adoption_buffer_rings[i]); - } + bplc.bd = mp->pool_data; + bplc.count = bplc.bd->obj_per_bucket * +rte_ring_count (bplc.bd->shared_bucket_ring); + bplc.count +=rte_ring_count (bplc.bd->shared_orphan_ring); +rte_lcore_iterate (bucket_count_per_lcore, &bplc);rte_mempool_mem_iter ((struct rte_mempool *)(uintptr_t )mp, - count_underfilled_buckets, &count); + count_underfilled_buckets, &bplc.count); + +return bplc.count; +} + +static int +bucket_init_per_lcore (unsigned int lcore_id,void *arg) +{ +char rg_name[RTE_RING_NAMESIZE ]; +struct bucket_data *bd = arg; +struct rte_mempool *mp; +int rg_flags; +int rc; + + mp = bd->pool; + bd->buckets[lcore_id] =bucket_stack_create (mp, + mp->size / bd->obj_per_bucket); +if (bd->buckets[lcore_id] ==NULL ) + goto error; + + rc =snprintf (rg_name,sizeof (rg_name),RTE_MEMPOOL_MZ_FORMAT ".a%u" , + mp->name, lcore_id); +if (rc <0 || rc >= (int )sizeof (rg_name)) + goto error; + + rg_flags =RING_F_SC_DEQ ; +if (mp->flags &MEMPOOL_F_SP_PUT ) + rg_flags |=RING_F_SP_ENQ ; + bd->adoption_buffer_rings[lcore_id] =rte_ring_create (rg_name, +rte_align32pow2 (mp->size +1 ), mp->socket_id, rg_flags); +if (bd->adoption_buffer_rings[lcore_id] ==NULL ) + goto error; -return count; +return 0 ; +error: +rte_free (bd->buckets[lcore_id]); + bd->buckets[lcore_id] =NULL ; +return -1 ; +} + +static void +bucket_uninit_per_lcore (unsigned int lcore_id,void *arg) +{ +struct bucket_data *bd = arg; + +rte_ring_free (bd->adoption_buffer_rings[lcore_id]); + bd->adoption_buffer_rings[lcore_id] =NULL ; +rte_free (bd->buckets[lcore_id]); + bd->buckets[lcore_id] =NULL ; } static int
@@ -399,7 +458,6 @@ bucket_alloc(struct rte_mempool *mp)int rc =0 ;char rg_name[RTE_RING_NAMESIZE ];struct bucket_data *bd; -unsigned int i;unsigned int bucket_header_size;size_t pg_sz;
@@ -429,36 +487,17 @@ bucket_alloc(struct rte_mempool *mp)/* eventually this should be a tunable parameter */ bd->bucket_stack_thresh = (mp->size / bd->obj_per_bucket) *4 /3 ; + bd->lcore_callback_handle =rte_lcore_callback_register ("bucket" , + bucket_init_per_lcore, bucket_uninit_per_lcore, bd); +if (bd->lcore_callback_handle ==NULL ) { + rc = -ENOMEM ; + goto no_mem_for_stacks; + } +if (mp->flags &MEMPOOL_F_SP_PUT ) rg_flags |=RING_F_SP_ENQ ;if (mp->flags &MEMPOOL_F_SC_GET ) rg_flags |=RING_F_SC_DEQ ; - -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -if (!rte_lcore_is_enabled (i)) -continue ; - bd->buckets[i] = -bucket_stack_create (mp, mp->size / bd->obj_per_bucket); -if (bd->buckets[i] ==NULL ) { - rc = -ENOMEM ; - goto no_mem_for_stacks; - } - rc =snprintf (rg_name,sizeof (rg_name), -RTE_MEMPOOL_MZ_FORMAT ".a%u" , mp->name, i); -if (rc <0 || rc >= (int )sizeof (rg_name)) { - rc = -ENAMETOOLONG ; - goto no_mem_for_stacks; - } - bd->adoption_buffer_rings[i] = -rte_ring_create (rg_name,rte_align32pow2 (mp->size +1 ), - mp->socket_id, - rg_flags |RING_F_SC_DEQ ); -if (bd->adoption_buffer_rings[i] ==NULL ) { - rc = -rte_errno; - goto no_mem_for_stacks; - } - } - rc =snprintf (rg_name,sizeof (rg_name),RTE_MEMPOOL_MZ_FORMAT ".0" , mp->name);if (rc <0 || rc >= (int )sizeof (rg_name)) {
@@ -498,11 +537,8 @@ bucket_alloc(struct rte_mempool *mp)rte_ring_free (bd->shared_orphan_ring); cannot_create_shared_orphan_ring: invalid_shared_orphan_ring: +rte_lcore_callback_unregister (bd->lcore_callback_handle); no_mem_for_stacks: -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -rte_free (bd->buckets[i]); -rte_ring_free (bd->adoption_buffer_rings[i]); - }rte_free (bd); no_mem_for_data: rte_errno = -rc;
@@ -512,16 +548,12 @@ bucket_alloc(struct rte_mempool *mp)static void bucket_free (struct rte_mempool *mp) { -unsigned int i;struct bucket_data *bd = mp->pool_data;if (bd ==NULL )return ; -for (i =0 ; i <RTE_MAX_LCORE ; i++) { -rte_free (bd->buckets[i]); -rte_ring_free (bd->adoption_buffer_rings[i]); - } +rte_lcore_callback_unregister (bd->lcore_callback_handle);rte_ring_free (bd->shared_orphan_ring);rte_ring_free (bd->shared_bucket_ring);
Signature · 1 line
2.23.0
Re: [dpdk-dev] [PATCH v4 9/9] mempool/bucket: handle non-EAL lcores
Quoted 3 lines · David Marchand
Convert to new lcore API to support non-EAL lcores.
Signed-off-by David Marchand <[email protected]>
v5 cover Register non-EAL threads as lcore
In reply to David MarchandOVS and some other applications have been hacking into DPDK internals to fake EAL threads and avoid performance penalty of only having non-EAL threads.
This series proposes to add a new type of lcores and maps those threads to such lcores.
non-EAL threads won't run the DPDK eal mainloop.
As a consequence, part of the EAL threads API cannot work.
Having new lcores appearing during the process lifetime is not expected by some DPDK components. This is addressed by introducing init/uninit callacks invoked when hotplugging of such lcore.
There is still some work/discussion:
- refuse new lcore role in incompatible EAL threads API (or document it only as those API were already incompatible?),
- think about deprecation notices for existing RTE_FOREACH_LCORE macros and consorts, it is probably worth discussing on how to iterate over lcores,
For the interested parties, I have a patch [1] against dpdk-latest OVS branch that makes use of this series (this patch probably won't work with v5, it will be rebased once dpdk side is ready).
1: https://patchwork.ozlabs.org/project/openvswitch/patch/[email protected]/
Changes since v4:
- added separate API to control mp feature activation,
- addressed Konstantin and Olivier comments,
Changes since v3:
- added init failure when trying to use in conjunction with multiprocess,
- addressed Andrew comments,
Changes since v2:
- fixed windows build error due to missing trace stub,
- fixed bug when rolling back on lcore register,
Changes since v1:
- rebased on master (conflicts on merged Windows series),
- separated lcore role code cleanup in a patch,
- tried to use a single naming, so kept non-EAL threads as the main notion. non-EAL threads are then distinguished between registered and unregistered non-EAL threads,
- added unit tests (still missing some coverage, marked with a FIXME),
- reworked callbacks call under a common rwlock lock which protects lcores allocations and callbacks registration,
- introduced lcore iterators and converted the bucket mempool driver,
Signature · 46 lines
David Marchand David Marchand (10): eal: relocate per thread symbols to common eal: fix multiple definition of per lcore thread id eal: introduce thread init helper eal: introduce thread uninit helper eal: move lcore role code eal: register non-EAL threads as lcores eal: add lcore init callbacks eal: add lcore iterators mempool/bucket: handle non-EAL lcores eal: add multiprocess disable API MAINTAINERS | 1 + app/test/Makefile | 1 + app/test/autotest_data.py | 6 + app/test/meson.build | 2 + app/test/test_lcores.c | 373 ++++++++++++++++++ app/test/test_mp_secondary.c | 7 + doc/guides/howto/debug_troubleshoot.rst | 5 +- .../prog_guide/env_abstraction_layer.rst | 22 +- doc/guides/prog_guide/mempool_lib.rst | 2 +- drivers/mempool/bucket/rte_mempool_bucket.c | 130 +++--- lib/librte_eal/common/eal_common_lcore.c | 249 +++++++++++- lib/librte_eal/common/eal_common_proc.c | 41 ++ lib/librte_eal/common/eal_common_thread.c | 141 +++++-- lib/librte_eal/common/eal_common_trace.c | 49 ++- lib/librte_eal/common/eal_memcfg.h | 2 + lib/librte_eal/common/eal_private.h | 39 ++ lib/librte_eal/common/eal_thread.h | 21 +- lib/librte_eal/common/eal_trace.h | 1 + lib/librte_eal/freebsd/eal.c | 20 +- lib/librte_eal/freebsd/eal_thread.c | 38 +- lib/librte_eal/include/rte_eal.h | 26 +- lib/librte_eal/include/rte_lcore.h | 179 ++++++++- lib/librte_eal/linux/eal.c | 21 +- lib/librte_eal/linux/eal_thread.c | 38 +- lib/librte_eal/rte_eal_version.map | 16 + lib/librte_eal/windows/eal.c | 8 +- lib/librte_eal/windows/eal_thread.c | 14 +- lib/librte_mempool/rte_mempool.h | 11 +- 28 files changed, 1221 insertions(+), 242 deletions(-) create mode 100644 app/test/test_lcores.c -- 2.23.0
PATCH v5 1/10 eal: relocate per thread symbols to common
We have per lcore thread symbols scattered in OS implementations but common code relies on them.
Move all of them in common.
RTE_PER_LCORE(_socket_id) and RTE_PER_LCORE(_cpuset) have public accessors and are not exported through the library map, they can be made static.
--- lib/librte_eal/common/eal_common_thread.c | 5 ++++- lib/librte_eal/freebsd/eal_thread.c | 4 ---- lib/librte_eal/include/rte_lcore.h | 1 - lib/librte_eal/linux/eal_thread.c | 4 ---- lib/librte_eal/windows/eal_thread.c | 4 ---- 5 files changed, 4 insertions(+), 14 deletions(-)
lib/librte_eal/common/eal_common_thread.c +4 -1
@@ -21,7 +21,10 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DECLARE_PER_LCORE (unsigned , _socket_id); +RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = + (unsigned int )SOCKET_ID_ANY ; +static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);unsigned rte_socket_id (void ) {
lib/librte_eal/freebsd/eal_thread.c +0 -4
@@ -25,10 +25,6 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; -RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
lib/librte_eal/include/rte_lcore.h +0 -1
@@ -23,7 +23,6 @@ extern "C" {#define LCORE_ID_ANY UINT32_MAX/**< Any lcore. */ RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ -RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */ /** * Get a lcore's role.
lib/librte_eal/linux/eal_thread.c +0 -4
@@ -25,10 +25,6 @@#include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE (unsigned, _lcore_id) =LCORE_ID_ANY ; -RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
lib/librte_eal/windows/eal_thread.c +0 -4
@@ -16,10 +16,6 @@#include "eal_private.h" #include "eal_windows.h" -RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; -RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int)SOCKET_ID_ANY; -RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); -/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
Signature · 1 line
2.23.0
PATCH v5 2/10 eal: fix multiple definition of per lcore thread id
In reply to David MarchandBecause of the inline accessor + static declaration in rte_gettid(), we end up with multiple symbols for RTE_PER_LCORE(_thread_id). Each compilation unit will pay a cost when accessing this information for the first time.
$ nm build/app/dpdk-testpmd | grep per_lcore__thread_id 0000000000000054 d per_lcore__thread_id.5037 0000000000000040 d per_lcore__thread_id.5103 0000000000000048 d per_lcore__thread_id.5259 000000000000004c d per_lcore__thread_id.5259 0000000000000044 d per_lcore__thread_id.5933 0000000000000058 d per_lcore__thread_id.6261 0000000000000050 d per_lcore__thread_id.7378 000000000000005c d per_lcore__thread_id.7496 000000000000000c d per_lcore__thread_id.8016 0000000000000010 d per_lcore__thread_id.8431
Make it global as part of the DPDK_21 stable ABI.
--- lib/librte_eal/common/eal_common_thread.c | 1 + lib/librte_eal/include/rte_eal.h | 3 ++- lib/librte_eal/rte_eal_version.map | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_thread.c +1 -0
@@ -22,6 +22,7 @@#include "eal_thread.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +RTE_DEFINE_PER_LCORE (int, _thread_id) =-1 ; static RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int )SOCKET_ID_ANY ; static RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset);
lib/librte_eal/include/rte_eal.h +2 -1
@@ -447,6 +447,8 @@ enum rte_intr_mode rte_eal_vfio_intr_mode(void);*/ int rte_sys_gettid (void ); +RTE_DECLARE_PER_LCORE (int, _thread_id); +/** * Get system unique thread id. *
@@ -456,7 +458,6 @@ int rte_sys_gettid(void);*/ static inline int rte_gettid (void ) { - static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;if (RTE_PER_LCORE (_thread_id) ==-1 )RTE_PER_LCORE (_thread_id) =rte_sys_gettid ();return RTE_PER_LCORE (_thread_id);
lib/librte_eal/rte_eal_version.map +7 -0
@@ -221,6 +221,13 @@ DPDK_20.0 { local: *; }; +DPDK_21 { + global: + + per_lcore__thread_id; + +} DPDK_20.0; + EXPERIMENTAL { global:
Signature · 1 line
2.23.0
PATCH v5 3/10 eal: introduce thread init helper
In reply to David MarchandIntroduce a helper responsible for initialising the per thread context. We can then have a unified context for EAL and non-EAL threads and remove copy/paste'd OS-specific helpers.
Per EAL thread CPU affinity setting is separated from the thread init. It is to accommodate with Windows EAL where CPU affinity is not set at the moment.
Besides, having affinity set by the master lcore in FreeBSD and Linux will make it possible to detect errors rather than panic in the child thread. But the cleanup when such an event happens is left for later.
A side-effect of this patch is that control threads can now use recursive locks (rte_gettid() was not called before).
---
Changes since v4:
- renamed rte_thread_init as __rte_thread_init and moved to eal_private.h,
Changes since v1:
- rebased on master, removed Windows workarounds wrt gettid and traces support,
--- lib/librte_eal/common/eal_common_thread.c | 50 ++++++++++++++--------- lib/librte_eal/common/eal_private.h | 10 +++++ lib/librte_eal/common/eal_thread.h | 8 ---- lib/librte_eal/freebsd/eal.c | 14 ++++++- lib/librte_eal/freebsd/eal_thread.c | 32 +-------------- lib/librte_eal/linux/eal.c | 15 ++++++- lib/librte_eal/linux/eal_thread.c | 32 +-------------- lib/librte_eal/windows/eal.c | 3 +- lib/librte_eal/windows/eal_thread.c | 10 +---- 9 files changed, 71 insertions(+), 103 deletions(-)
lib/librte_eal/common/eal_common_thread.c +30 -20
@@ -71,20 +71,10 @@ eal_cpuset_socket_id(rte_cpuset_t *cpusetp)return socket_id; } -int -rte_thread_set_affinity (rte_cpuset_t *cpusetp) +static void +thread_update_affinity (rte_cpuset_t *cpusetp) { -int s; -unsigned lcore_id; -pthread_t tid; - - tid =pthread_self (); - - s =pthread_setaffinity_np (tid,sizeof (rte_cpuset_t), cpusetp); -if (s !=0 ) { -RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); -return -1 ; - } +unsigned int lcore_id =rte_lcore_id ();/* store socket_id in TLS for quick access */ RTE_PER_LCORE(_socket_id) =
@@ -94,14 +84,24 @@ rte_thread_set_affinity(rte_cpuset_t *cpusetp)memmove (&RTE_PER_LCORE (_cpuset), cpusetp,sizeof (rte_cpuset_t)); - lcore_id =rte_lcore_id ();if (lcore_id != (unsigned )LCORE_ID_ANY ) {/* EAL thread will update lcore_config */ lcore_config[lcore_id].socket_id =RTE_PER_LCORE (_socket_id);memmove (&lcore_config[lcore_id].cpuset, cpusetp,sizeof (rte_cpuset_t)); } +} + +int +rte_thread_set_affinity (rte_cpuset_t *cpusetp) +{ +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + cpusetp) !=0 ) { +RTE_LOG (ERR ,EAL ,"pthread_setaffinity_np failed\n" ); +return -1 ; + } +thread_update_affinity (cpusetp);return 0 ; }
@@ -147,6 +147,19 @@ eal_thread_dump_affinity(char *str, unsigned size)return ret; } +void +__rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset) +{ +/* set the lcore ID in per-lcore memory area */ +RTE_PER_LCORE (_lcore_id) = lcore_id; + +/* acquire system unique id */ +rte_gettid (); + +thread_update_affinity (cpuset); + +__rte_trace_mem_per_thread_alloc (); +}struct rte_thread_ctrl_params {void *(*start_routine)(void *);
@@ -154,7 +167,7 @@ struct rte_thread_ctrl_params {pthread_barrier_t configured; }; -static void *rte_thread_init (void *arg) +static void *ctrl_thread_init (void *arg) {int ret; struct internal_config *internal_conf =
@@ -164,8 +177,7 @@ static void *rte_thread_init(void *arg)void *(*start_routine)(void *) = params->start_routine;void *routine_arg = params->arg; -/* Store cpuset in TLS for quick access */ -memmove (&RTE_PER_LCORE (_cpuset), cpuset,sizeof (rte_cpuset_t)); +__rte_thread_init (rte_lcore_id (), cpuset); ret =pthread_barrier_wait (¶ms->configured);if (ret ==PTHREAD_BARRIER_SERIAL_THREAD ) {
@@ -173,8 +185,6 @@ static void *rte_thread_init(void *arg)free (params); } -__rte_trace_mem_per_thread_alloc (); -return start_routine (routine_arg); }
@@ -198,7 +208,7 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name,pthread_barrier_init (¶ms->configured,NULL ,2 ); - ret =pthread_create (thread, attr, rte_thread_init, (void *)params); + ret =pthread_create (thread, attr, ctrl_thread_init, (void *)params);if (ret !=0 ) {free (params);return -ret;
lib/librte_eal/common/eal_private.h +10 -0
@@ -699,4 +699,14 @@ eal_get_internal_configuration(void);rte_usage_hook_t eal_get_application_usage_hook (void ); +/** +* Init per-lcore info in current thread. +* +* @param lcore_id +* identifier of lcore. +* @param cpuset +* CPU affinity for this thread. +*/ +void __rte_thread_init (unsigned int lcore_id,rte_cpuset_t *cpuset); +#endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/eal_thread.h +0 -8
@@ -15,14 +15,6 @@*/ __rte_noreturn void *eal_thread_loop(void *arg); -/** -* Init per-lcore info for master thread -* -* @param lcore_id -* identifier of master lcore -*/ -void eal_thread_init_master (unsigned lcore_id); -/** * Get the NUMA socket id from cpu id. * This function is private to EAL.
lib/librte_eal/freebsd/eal.c +13 -1
@@ -845,7 +845,14 @@ rte_eal_init(int argc, char **argv)eal_check_mem_on_local_socket (); -eal_thread_init_master (config->master_lcore); +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + &lcore_config[config->master_lcore].cpuset) !=0 ) { +rte_eal_init_alert ("Cannot set affinity" ); + rte_errno =EINVAL ; +return -1 ; + } +__rte_thread_init (config->master_lcore, + &lcore_config[config->master_lcore].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset));
@@ -876,6 +883,11 @@ rte_eal_init(int argc, char **argv)snprintf (thread_name,sizeof (thread_name),"lcore-slave-%d" , i);rte_thread_setname (lcore_config[i].thread_id, thread_name); + + ret =pthread_setaffinity_np (lcore_config[i].thread_id, +sizeof (rte_cpuset_t), &lcore_config[i].cpuset); +if (ret !=0 ) +rte_panic ("Cannot set affinity\n" ); }/*
lib/librte_eal/freebsd/eal_thread.c +1 -31
@@ -66,29 +66,6 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)return rc; } -/* set affinity for current thread */ -static int -eal_thread_set_affinity (void ) -{ -unsigned lcore_id =rte_lcore_id (); - -/* acquire system unique id */ -rte_gettid (); - -/* update EAL thread core affinity */ -return rte_thread_set_affinity (&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master (unsigned lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); -} -/* main loop of threads */ __rte_noreturn void * eal_thread_loop(__rte_unused void *arg)
@@ -113,19 +90,12 @@ eal_thread_loop(__rte_unused void *arg) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); +__rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%p;cpuset=[%s%s])\n" , lcore_id, thread_id, cpuset, ret ==0 ?"" :"..." ); -__rte_trace_mem_per_thread_alloc ();rte_eal_trace_thread_lcore_ready (lcore_id, cpuset);/* read on our pipe to get commands */
lib/librte_eal/linux/eal.c +13 -2
@@ -1184,10 +1184,16 @@ rte_eal_init(int argc, char **argv)eal_check_mem_on_local_socket (); -eal_thread_init_master (config->master_lcore); +if (pthread_setaffinity_np (pthread_self (),sizeof (rte_cpuset_t), + &lcore_config[config->master_lcore].cpuset) !=0 ) { +rte_eal_init_alert ("Cannot set affinity" ); + rte_errno =EINVAL ; +return -1 ; + } +__rte_thread_init (config->master_lcore, + &lcore_config[config->master_lcore].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , config->master_lcore, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." );
@@ -1219,6 +1225,11 @@ rte_eal_init(int argc, char **argv)if (ret !=0 )RTE_LOG (DEBUG ,EAL ,"Cannot set name for lcore thread\n" ); + + ret =pthread_setaffinity_np (lcore_config[i].thread_id, +sizeof (rte_cpuset_t), &lcore_config[i].cpuset); +if (ret !=0 ) +rte_panic ("Cannot set affinity\n" ); }/*
lib/librte_eal/linux/eal_thread.c +1 -31
@@ -66,29 +66,6 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)return rc; } -/* set affinity for current EAL thread */ -static int -eal_thread_set_affinity (void ) -{ -unsigned lcore_id =rte_lcore_id (); - -/* acquire system unique id */ -rte_gettid (); - -/* update EAL thread core affinity */ -return rte_thread_set_affinity (&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master (unsigned lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); -} -/* main loop of threads */ __rte_noreturn void * eal_thread_loop(__rte_unused void *arg)
@@ -113,19 +90,12 @@ eal_thread_loop(__rte_unused void *arg) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; - -/* set CPU affinity */ -if (eal_thread_set_affinity () <0 ) -rte_panic ("cannot set affinity\n" ); +__rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset); ret =eal_thread_dump_affinity (cpuset,sizeof (cpuset)); -RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset, ret ==0 ?"" :"..." ); -__rte_trace_mem_per_thread_alloc ();rte_eal_trace_thread_lcore_ready (lcore_id, cpuset);/* read on our pipe to get commands */
lib/librte_eal/windows/eal.c +2 -1
@@ -333,7 +333,8 @@ rte_eal_init(int argc, char **argv)return -1 ; } -eal_thread_init_master (config->master_lcore); +__rte_thread_init (config->master_lcore, + &lcore_config[config->master_lcore].cpuset); bscan =rte_bus_scan ();if (bscan <0 ) {
lib/librte_eal/windows/eal_thread.c +1 -9
@@ -53,13 +53,6 @@ rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int slave_id)return 0 ; } -void -eal_thread_init_master (unsigned int lcore_id) -{ -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; -} -/* main loop of threads */ void * eal_thread_loop(void *arg __rte_unused)
@@ -84,8 +77,7 @@ eal_thread_loop(void *arg __rte_unused) m2s = lcore_config[lcore_id].pipe_master2slave[0 ]; s2m = lcore_config[lcore_id].pipe_slave2master[1 ]; -/* set the lcore ID in per-lcore memory area */ -RTE_PER_LCORE (_lcore_id) = lcore_id; +__rte_thread_init (lcore_id, &lcore_config[lcore_id].cpuset);RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (tid=%zx;cpuset=[%s])\n" , lcore_id, (uintptr_t )thread_id, cpuset);
Signature · 1 line
2.23.0