eal: Add new API for threading
PATCH v9 10/10 Enable the new EAL thread API
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Rename pthread_* occurrences with the new rte_thread_* API. Enable the new API in the build system.
--- app/test/process.h | 8 +- app/test/test_lcores.c | 16 +- app/test/test_link_bonding.c | 10 +- app/test/test_lpm_perf.c | 12 +- config/meson.build | 4 + drivers/bus/dpaa/base/qbman/bman_driver.c | 5 +- drivers/bus/dpaa/base/qbman/dpaa_sys.c | 14 +- drivers/bus/dpaa/base/qbman/process.c | 6 +- drivers/bus/dpaa/dpaa_bus.c | 14 +- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 19 +- drivers/compress/mlx5/mlx5_compress.c | 10 +- drivers/event/dlb2/pf/base/dlb2_osdep.h | 4 +- drivers/net/af_xdp/rte_eth_af_xdp.c | 18 +- drivers/net/ark/ark_ethdev.c | 2 +- drivers/net/ark/ark_pktgen.c | 4 +- drivers/net/atlantic/atl_ethdev.c | 4 +- drivers/net/atlantic/atl_types.h | 5 +- .../net/atlantic/hw_atl/hw_atl_utils_fw2x.c | 26 +-- drivers/net/axgbe/axgbe_common.h | 2 +- drivers/net/axgbe/axgbe_dev.c | 8 +- drivers/net/axgbe/axgbe_ethdev.c | 8 +- drivers/net/axgbe/axgbe_ethdev.h | 8 +- drivers/net/axgbe/axgbe_i2c.c | 4 +- drivers/net/axgbe/axgbe_mdio.c | 8 +- drivers/net/axgbe/axgbe_phy_impl.c | 6 +- drivers/net/bnxt/bnxt.h | 16 +- drivers/net/bnxt/bnxt_cpr.c | 4 +- drivers/net/bnxt/bnxt_ethdev.c | 52 ++--- drivers/net/bnxt/bnxt_irq.c | 8 +- drivers/net/bnxt/bnxt_reps.c | 10 +- drivers/net/bnxt/tf_ulp/bnxt_ulp.c | 34 ++-- drivers/net/bnxt/tf_ulp/bnxt_ulp.h | 4 +- drivers/net/bnxt/tf_ulp/ulp_fc_mgr.c | 24 +-- drivers/net/bnxt/tf_ulp/ulp_fc_mgr.h | 2 +- drivers/net/ena/base/ena_plat_dpdk.h | 12 +- drivers/net/enic/enic.h | 2 +- drivers/net/ice/ice_dcf_parent.c | 6 +- drivers/net/ipn3ke/ipn3ke_representor.c | 6 +- drivers/net/ixgbe/ixgbe_ethdev.c | 2 +- drivers/net/ixgbe/ixgbe_ethdev.h | 2 +- drivers/net/kni/rte_eth_kni.c | 8 +- drivers/net/mlx5/linux/mlx5_os.c | 2 +- drivers/net/mlx5/mlx5.c | 20 +- drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_txpp.c | 8 +- drivers/net/mlx5/windows/mlx5_flow_os.c | 10 +- drivers/net/mlx5/windows/mlx5_os.c | 2 +- drivers/net/qede/base/bcm_osal.h | 8 +- drivers/net/vhost/rte_eth_vhost.c | 24 +-- .../net/virtio/virtio_user/virtio_user_dev.c | 30 +-- .../net/virtio/virtio_user/virtio_user_dev.h | 2 +- drivers/raw/ifpga/ifpga_rawdev.c | 6 +- drivers/vdpa/ifc/ifcvf_vdpa.c | 46 ++--- drivers/vdpa/mlx5/mlx5_vdpa.c | 24 +-- drivers/vdpa/mlx5/mlx5_vdpa.h | 4 +- drivers/vdpa/mlx5/mlx5_vdpa_event.c | 46 ++--- examples/kni/main.c | 6 +- .../performance-thread/pthread_shim/main.c | 2 +- examples/vhost/main.c | 2 +- examples/vhost_blk/vhost_blk.c | 12 +- lib/eal/common/eal_common_options.c | 6 +- lib/eal/common/eal_common_proc.c | 48 ++--- lib/eal/common/eal_common_thread.c | 42 ++-- lib/eal/common/eal_common_trace.c | 2 +- lib/eal/common/eal_private.h | 2 +- lib/eal/common/eal_thread.h | 6 + lib/eal/common/malloc_mp.c | 32 +-- lib/eal/common/meson.build | 1 + lib/eal/freebsd/eal.c | 42 +++- lib/eal/freebsd/eal_alarm.c | 12 +- lib/eal/freebsd/eal_interrupts.c | 4 +- lib/eal/freebsd/eal_thread.c | 14 +- lib/eal/include/meson.build | 1 + lib/eal/include/rte_lcore.h | 8 +- lib/eal/include/rte_per_lcore.h | 2 - lib/eal/linux/eal.c | 46 +++-- lib/eal/linux/eal_alarm.c | 10 +- lib/eal/linux/eal_interrupts.c | 4 +- lib/eal/linux/eal_thread.c | 18 +- lib/eal/linux/eal_timer.c | 2 +- lib/eal/unix/meson.build | 1 - lib/eal/unix/rte_thread.c | 92 --------- lib/eal/version.map | 22 ++ lib/eal/windows/eal.c | 43 +++- lib/eal/windows/eal_interrupts.c | 10 +- lib/eal/windows/eal_thread.c | 28 +-- lib/eal/windows/eal_windows.h | 10 - lib/eal/windows/include/meson.build | 1 + lib/eal/windows/include/pthread.h | 192 ------------------ lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/meson.build | 7 +- lib/ethdev/rte_ethdev.c | 4 +- lib/ethdev/rte_ethdev_core.h | 5 +- lib/ethdev/rte_flow.c | 4 +- lib/eventdev/rte_event_eth_rx_adapter.c | 6 +- lib/vhost/fd_man.c | 40 ++-- lib/vhost/fd_man.h | 6 +- lib/vhost/socket.c | 130 ++++++------ lib/vhost/vhost.c | 10 +- meson_options.txt | 2 + 100 files changed, 703 insertions(+), 887 deletions(-) delete mode 100644 lib/eal/unix/rte_thread.c delete mode 100644 lib/eal/windows/include/pthread.h
app/test/process.h +4 -4
@@ -26,7 +26,7 @@#ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING -#include <pthread.h> +#include <rte_thread.h> extern void *send_pkts (void *empty);extern uint16_t flag_for_send_pkts;#endif
@@ -47,7 +47,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value)char path[32 ];#ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING -pthread_t thread; +rte_thread_t thread;int rc;#endif #endif
@@ -128,7 +128,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) #ifdef RTE_LIB_PDUMP #ifdef RTE_NET_RING if ((strcmp(env_value, "run_pdump_server_tests") == 0)) { - rc = pthread_create(&thread, NULL, &send_pkts, NULL); + rc = rte_thread_create(&thread, NULL, &send_pkts, NULL); if (rc != 0) { rte_panic("Cannot start send pkts thread: %s\n", strerror(rc));
@@ -143,7 +143,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value)#ifdef RTE_NET_RING if ((strcmp (env_value,"run_pdump_server_tests" ) ==0 )) { flag_for_send_pkts =0 ; -pthread_join (thread,NULL ); +rte_thread_join (thread,NULL ); }#endif #endif
app/test/test_lcores.c +8 -8
@@ -14,7 +14,7 @@struct thread_context {enum {INIT ,ERROR ,DONE } state;bool lcore_id_any; -pthread_t id; +rte_thread_t id;unsigned int *registered_count; };
@@ -77,7 +77,7 @@ test_non_eal_lcores(unsigned int eal_threads_count) t->state =INIT ; t->registered_count = ®istered_count; t->lcore_id_any = false; -if (pthread_create (&t->id,NULL , thread_loop, t) !=0 ) +if (rte_thread_create (&t->id,NULL , thread_loop, t) !=0 )break ; non_eal_threads_count++; }
@@ -96,7 +96,7 @@ test_non_eal_lcores(unsigned int eal_threads_count) t->state =INIT ; t->registered_count = ®istered_count; t->lcore_id_any = true; -if (pthread_create (&t->id,NULL , thread_loop, t) ==0 ) { +if (rte_thread_create (&t->id,NULL , thread_loop, t) ==0 ) { non_eal_threads_count++;printf ("non-EAL threads count: %u\n" , non_eal_threads_count); while (__atomic_load_n(®istered_count, __ATOMIC_ACQUIRE) !=
@@ -110,7 +110,7 @@ test_non_eal_lcores(unsigned int eal_threads_count) ret =0 ;for (i =0 ; i < non_eal_threads_count; i++) { t = &thread_contexts[i]; -pthread_join (t->id,NULL ); +rte_thread_join (t->id,NULL );if (t->state !=DONE ) ret =-1 ; }
@@ -262,7 +262,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count) t->state =INIT ; t->registered_count = ®istered_count; t->lcore_id_any = false; -if (pthread_create (&t->id,NULL , thread_loop, t) !=0 ) +if (rte_thread_create (&t->id,NULL , thread_loop, t) !=0 ) goto cleanup_threads; non_eal_threads_count++; while (__atomic_load_n(®istered_count, __ATOMIC_ACQUIRE) !=
@@ -285,7 +285,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count) t->state =INIT ; t->registered_count = ®istered_count; t->lcore_id_any = true; -if (pthread_create (&t->id,NULL , thread_loop, t) !=0 ) +if (rte_thread_create (&t->id,NULL , thread_loop, t) !=0 ) goto cleanup_threads; non_eal_threads_count++; while (__atomic_load_n(®istered_count, __ATOMIC_ACQUIRE) !=
@@ -309,7 +309,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count) ret =0 ;for (i =0 ; i < non_eal_threads_count; i++) { t = &thread_contexts[i]; -pthread_join (t->id,NULL ); +rte_thread_join (t->id,NULL );if (t->state !=DONE ) ret =-1 ; }
@@ -330,7 +330,7 @@ test_non_eal_lcores_callback(unsigned int eal_threads_count)__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 ); +rte_thread_join (t->id,NULL ); } error:if (handle[1 ] !=NULL )
app/test/test_link_bonding.c +5 -5
@@ -203,7 +203,7 @@ configure_ethdev(uint16_t port_id, uint8_t start, uint8_t en_isr)static int slaves_initialized;static int mac_slaves_initialized; -static pthread_mutex_t mutex =PTHREAD_MUTEX_INITIALIZER ; +static rte_thread_mutex_t mutex =RTE_THREAD_MUTEX_INITIALIZER ;static pthread_cond_t cvar =PTHREAD_COND_INITIALIZER ;
@@ -1191,11 +1191,11 @@ test_bonding_lsc_event_callback(uint16_t port_id __rte_unused, void *param __rte_unused, void *ret_param __rte_unused) { -pthread_mutex_lock (&mutex); +rte_thread_mutex_lock (&mutex); test_lsc_interrupt_count++;pthread_cond_signal (&cvar); -pthread_mutex_unlock (&mutex); +rte_thread_mutex_unlock (&mutex);return 0 ; }
@@ -1220,11 +1220,11 @@ lsc_timeout(int wait_us) ts.tv_sec +=1 ; } -pthread_mutex_lock (&mutex); +rte_thread_mutex_lock (&mutex);if (test_lsc_interrupt_count <1 ) retval =pthread_cond_timedwait (&cvar, &mutex, &ts); -pthread_mutex_unlock (&mutex); +rte_thread_mutex_unlock (&mutex);if (retval ==0 && test_lsc_interrupt_count <1 )return -1 ;
app/test/test_lpm_perf.c +6 -6
@@ -25,7 +25,7 @@ static volatile uint32_t thr_id;static uint64_t gwrite_cycles;static uint32_t num_writers;/* LPM APIs are not thread safe, use mutex to provide thread safety */ -static pthread_mutex_t lpm_mutex =PTHREAD_MUTEX_INITIALIZER ; +static rte_thread_mutex_t lpm_mutex =RTE_THREAD_MUTEX_INITIALIZER ;/* Report quiescent state interval every 1024 lookups. Larger critical * sections in reader will result in writer polling multiple times.
@@ -443,7 +443,7 @@ test_lpm_rcu_qsbr_writer(void *arg)/* Add all the entries */ for (j = si; j < ei; j++) {if (num_writers >1 ) -pthread_mutex_lock (&lpm_mutex); +rte_thread_mutex_lock (&lpm_mutex);if (rte_lpm_add (lpm, large_ldepth_route_table[j].ip, large_ldepth_route_table[j].depth, next_hop_add) !=0 ) {
@@ -452,13 +452,13 @@ test_lpm_rcu_qsbr_writer(void *arg) goto error; }if (num_writers >1 ) -pthread_mutex_unlock (&lpm_mutex); +rte_thread_mutex_unlock (&lpm_mutex); }/* Delete all the entries */ for (j = si; j < ei; j++) {if (num_writers >1 ) -pthread_mutex_lock (&lpm_mutex); +rte_thread_mutex_lock (&lpm_mutex);if (rte_lpm_delete (lpm, large_ldepth_route_table[j].ip, large_ldepth_route_table[j].depth) !=0 ) { printf("Failed to delete iteration %d, route# %d\n",
@@ -466,7 +466,7 @@ test_lpm_rcu_qsbr_writer(void *arg) goto error; }if (num_writers >1 ) -pthread_mutex_unlock (&lpm_mutex); +rte_thread_mutex_unlock (&lpm_mutex); } }
@@ -478,7 +478,7 @@ test_lpm_rcu_qsbr_writer(void *arg) error:if (num_writers >1 ) -pthread_mutex_unlock (&lpm_mutex); +rte_thread_mutex_unlock (&lpm_mutex);return -1 ; }
config/meson.build +4 -0
@@ -262,6 +262,10 @@ else # for 32-bit we need smaller reserved memory areas dpdk_conf.set('RTE_MAX_MEM_MB', 2048) endif +if is_windows + dpdk_conf.set('RTE_USE_WINDOWS_THREAD_TYPES', not get_option('use_external_thread_lib')) +endif + compile_time_cpuflags = [] subdir(arch_subdir)
drivers/bus/dpaa/base/qbman/bman_driver.c +2 -3
@@ -38,11 +38,10 @@ static int fsl_bman_portal_init(uint32_t idx, int is_shared)struct dpaa_ioctl_irq_map irq_map;/* Verify the thread's cpu-affinity */ - ret =pthread_getaffinity_np (pthread_self (),sizeof (cpu_set_t), - &cpuset); + ret =rte_thread_get_affinity_by_id (rte_thread_self (), &cpuset);if (ret) { errno = ret; -err (0 ,"pthread_getaffinity_np()" ); +err (0 ,"rte_thread_get_affinity_by_id()" );return ret; } pcfg.cpu =-1 ;
drivers/bus/dpaa/base/qbman/dpaa_sys.c +7 -7
@@ -18,16 +18,16 @@ struct process_interrupt { };static COMPAT_LIST_HEAD (process_irq_list); -static pthread_mutex_t process_irq_lock =PTHREAD_MUTEX_INITIALIZER ; +static rte_thread_mutex_t process_irq_lock =RTE_THREAD_MUTEX_INITIALIZER ;static void process_interrupt_install (struct process_interrupt *irq) {int ret;/* Add the irq to the end of the list */ - ret =pthread_mutex_lock (&process_irq_lock); + ret =rte_thread_mutex_lock (&process_irq_lock);assert (!ret);list_add_tail (&irq->node, &process_irq_list); - ret =pthread_mutex_unlock (&process_irq_lock); + ret =rte_thread_mutex_unlock (&process_irq_lock);assert (!ret); }
@@ -35,10 +35,10 @@ static void process_interrupt_remove(struct process_interrupt *irq) {int ret; - ret =pthread_mutex_lock (&process_irq_lock); + ret =rte_thread_mutex_lock (&process_irq_lock);assert (!ret);list_del (&irq->node); - ret =pthread_mutex_unlock (&process_irq_lock); + ret =rte_thread_mutex_unlock (&process_irq_lock);assert (!ret); }
@@ -47,14 +47,14 @@ static struct process_interrupt *process_interrupt_find(int irq_num)int ret;struct process_interrupt *i =NULL ; - ret =pthread_mutex_lock (&process_irq_lock); + ret =rte_thread_mutex_lock (&process_irq_lock);assert (!ret);list_for_each_entry (i, &process_irq_list, node) {if (i->irq == irq_num) goto done; } done: - ret =pthread_mutex_unlock (&process_irq_lock); + ret =rte_thread_mutex_unlock (&process_irq_lock);assert (!ret);return i; }
drivers/bus/dpaa/base/qbman/process.c +3 -3
@@ -21,7 +21,7 @@* what the lock is for. */ static int fd =-1 ; -static pthread_mutex_t fd_init_lock =PTHREAD_MUTEX_INITIALIZER ; +static rte_thread_mutex_t fd_init_lock =RTE_THREAD_MUTEX_INITIALIZER ;static int check_fd (void ) {
@@ -29,12 +29,12 @@ static int check_fd(void)if (fd >=0 )return 0 ; - ret =pthread_mutex_lock (&fd_init_lock); + ret =rte_thread_mutex_lock (&fd_init_lock);assert (!ret);/* check again with the lock held */ if (fd <0 ) fd =open (PROCESS_PATH ,O_RDWR ); - ret =pthread_mutex_unlock (&fd_init_lock); + ret =rte_thread_mutex_unlock (&fd_init_lock);assert (!ret);return (fd >=0 ) ?0 : -ENODEV ; }
drivers/bus/dpaa/dpaa_bus.c +7 -7
@@ -10,7 +10,7 @@#include <limits.h> #include <sched.h> #include <signal.h> -#include <pthread.h> +#include <rte_thread.h> #include <sys/types.h> #include <sys/syscall.h> #include <sys/eventfd.h>
@@ -48,7 +48,7 @@ static struct rte_dpaa_bus rte_dpaa_bus;struct netcfg_info *dpaa_netcfg;/* define a variable to hold the portal_key, once created.*/ -static pthread_key_t dpaa_portal_key; +static rte_thread_key dpaa_portal_key;unsigned int dpaa_svr_family;
@@ -316,10 +316,10 @@ int rte_dpaa_portal_init(void *arg)DPAA_PER_LCORE_PORTAL ->bman_idx =bman_get_portal_index ();DPAA_PER_LCORE_PORTAL ->tid =syscall (SYS_gettid); - ret =pthread_setspecific (dpaa_portal_key, + ret =rte_thread_value_set (dpaa_portal_key, (void *)DPAA_PER_LCORE_PORTAL );if (ret) { -DPAA_BUS_LOG (ERR ,"pthread_setspecific failed on core %u" +DPAA_BUS_LOG (ERR ,"rte_thread_value_set failed on core %u" " (lcore=%u) with ret: %d" , cpu, lcore, ret);dpaa_portal_finish (NULL );
@@ -377,7 +377,7 @@ dpaa_portal_finish(void *arg)bman_thread_finish ();qman_thread_finish (); -pthread_setspecific (dpaa_portal_key,NULL ); +rte_thread_value_set (dpaa_portal_key,NULL );rte_free (dpaa_io_portal); dpaa_io_portal =NULL ;
@@ -453,9 +453,9 @@ rte_dpaa_bus_scan(void)/* create the key, supplying a function that'll be invoked * when a portal affined thread will be deleted. */ - ret =pthread_key_create (&dpaa_portal_key, dpaa_portal_finish); + ret =rte_thread_key_create (&dpaa_portal_key, dpaa_portal_finish);if (ret) { -DPAA_BUS_LOG (DEBUG ,"Unable to create pthread key. (%d)" , ret); +DPAA_BUS_LOG (DEBUG ,"Unable to create thread key. (%d)" , ret);dpaa_clean_device_list ();return ret; }
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +9 -10
@@ -13,7 +13,7 @@#include <stdarg.h> #include <inttypes.h> #include <signal.h> -#include <pthread.h> +#include <rte_thread.h> #include <sys/types.h> #include <sys/queue.h> #include <sys/ioctl.h>
@@ -59,7 +59,7 @@ uint8_t dpaa2_dqrr_size;uint8_t dpaa2_eqcr_size;/* Variable to hold the portal_key, once created.*/ -static pthread_key_t dpaa2_portal_key; +static rte_thread_key dpaa2_portal_key;/*Stashing Macros default for LS208x*/ static int dpaa2_core_cluster_base =0x04 ;
@@ -92,10 +92,9 @@ dpaa2_get_core_id(void)rte_cpuset_t cpuset;int i, ret, cpu_id =-1 ; - ret =pthread_getaffinity_np (pthread_self (),sizeof (cpu_set_t), - &cpuset); + ret =rte_thread_get_affinity_by_id (rte_thread_self (), &cpuset);if (ret) { -DPAA2_BUS_ERR ("pthread_getaffinity_np() failed" ); +DPAA2_BUS_ERR ("rte_thread_get_affinity_by_id() failed" );return ret; }
@@ -296,9 +295,9 @@ static struct dpaa2_dpio_dev *dpaa2_get_qbman_swp(void) } } - ret =pthread_setspecific (dpaa2_portal_key, (void *)dpio_dev); + ret =rte_thread_value_set (dpaa2_portal_key, (void *)dpio_dev);if (ret) { -DPAA2_BUS_ERR ("pthread_setspecific failed with ret: %d" , ret); +DPAA2_BUS_ERR ("rte_thread_value_set failed with ret: %d" , ret);dpaa2_put_qbman_swp (dpio_dev);return NULL ; }
@@ -357,7 +356,7 @@ static void dpaa2_portal_finish(void *arg)dpaa2_put_qbman_swp (RTE_PER_LCORE (_dpaa2_io).dpio_dev);dpaa2_put_qbman_swp (RTE_PER_LCORE (_dpaa2_io).ethrx_dpio_dev); -pthread_setspecific (dpaa2_portal_key,NULL ); +rte_thread_value_set (dpaa2_portal_key,NULL ); } static int
@@ -515,10 +514,10 @@ dpaa2_create_dpio_device(int vdev_fd,/* create the key, supplying a function that'll be invoked * when a portal affined thread will be deleted. */ - ret =pthread_key_create (&dpaa2_portal_key, + ret =rte_thread_key_create (&dpaa2_portal_key, dpaa2_portal_finish);if (ret) { -DPAA2_BUS_DEBUG ("Unable to create pthread key (%d)" , +DPAA2_BUS_DEBUG ("Unable to create thread key (%d)" , ret); goto err; }
drivers/compress/mlx5/mlx5_compress.c +5 -5
@@ -72,7 +72,7 @@ struct mlx5_compress_qp { TAILQ_HEAD(mlx5_compress_privs, mlx5_compress_priv) mlx5_compress_priv_list =TAILQ_HEAD_INITIALIZER (mlx5_compress_priv_list); -static pthread_mutex_t priv_list_lock =PTHREAD_MUTEX_INITIALIZER ; +static rte_thread_mutex_t priv_list_lock =RTE_THREAD_MUTEX_INITIALIZER ;int mlx5_compress_logtype;
@@ -804,9 +804,9 @@ mlx5_compress_pci_probe(struct rte_pci_driver *pci_drv, } priv->mr_scache.reg_mr_cb = mlx5_common_verbs_reg_mr; priv->mr_scache.dereg_mr_cb = mlx5_common_verbs_dereg_mr; -pthread_mutex_lock (&priv_list_lock); +rte_thread_mutex_lock (&priv_list_lock);TAILQ_INSERT_TAIL (&mlx5_compress_priv_list, priv, next); -pthread_mutex_unlock (&priv_list_lock); +rte_thread_mutex_unlock (&priv_list_lock);return 0 ; }
@@ -826,13 +826,13 @@ mlx5_compress_pci_remove(struct rte_pci_device *pdev) {struct mlx5_compress_priv *priv =NULL ; -pthread_mutex_lock (&priv_list_lock); +rte_thread_mutex_lock (&priv_list_lock); TAILQ_FOREACH(priv, &mlx5_compress_priv_list, next)if (rte_pci_addr_cmp (&priv->pci_dev->addr, &pdev->addr) !=0 )break ;if (priv)TAILQ_REMOVE (&mlx5_compress_priv_list, priv, next); -pthread_mutex_unlock (&priv_list_lock); +rte_thread_mutex_unlock (&priv_list_lock);if (priv) {mlx5_mr_release_cache (&priv->mr_scache);mlx5_compress_hw_global_release (priv);
drivers/event/dlb2/pf/base/dlb2_osdep.h +2 -2
@@ -8,7 +8,7 @@#include <string.h> #include <time.h> #include <unistd.h> -#include <pthread.h> +#include <rte_thread.h> #include <rte_string_fns.h> #include <rte_cycles.h>
@@ -194,7 +194,7 @@ static void *dlb2_complete_queue_map_unmap(void *__args)static inline void os_schedule_work (struct dlb2_hw *hw) {struct dlb2_dev *dlb2_dev; -pthread_t complete_queue_map_unmap_thread; +rte_thread_t complete_queue_map_unmap_thread;int ret; dlb2_dev = container_of(hw, struct dlb2_dev, hw);
drivers/net/af_xdp/rte_eth_af_xdp.c +9 -9
@@ -178,7 +178,7 @@ TAILQ_HEAD(internal_list_head, internal_list);static struct internal_list_head internal_list =TAILQ_HEAD_INITIALIZER (internal_list); -static pthread_mutex_t internal_list_lock =PTHREAD_MUTEX_INITIALIZER ; +static rte_thread_mutex_t internal_list_lock =RTE_THREAD_MUTEX_INITIALIZER ;#if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG ) static inline int
@@ -676,7 +676,7 @@ find_internal_resource(struct pmd_internals *port_int)if (port_int ==NULL )return NULL ; -pthread_mutex_lock (&internal_list_lock); +rte_thread_mutex_lock (&internal_list_lock); TAILQ_FOREACH(list, &internal_list, next) { struct pmd_internals *list_int =
@@ -687,7 +687,7 @@ find_internal_resource(struct pmd_internals *port_int) } } -pthread_mutex_unlock (&internal_list_lock); +rte_thread_mutex_unlock (&internal_list_lock);if (!found)return NULL ;
@@ -725,7 +725,7 @@ get_shared_umem(struct pkt_rx_queue *rxq, const char *ifname,if (mb_pool ==NULL )return ret; -pthread_mutex_lock (&internal_list_lock); +rte_thread_mutex_lock (&internal_list_lock); TAILQ_FOREACH(list, &internal_list, next) { internals = list->eth_dev->data->dev_private;
@@ -751,7 +751,7 @@ get_shared_umem(struct pkt_rx_queue *rxq, const char *ifname, } out: -pthread_mutex_unlock (&internal_list_lock); +rte_thread_mutex_unlock (&internal_list_lock);return ret; }
@@ -780,9 +780,9 @@ eth_dev_configure(struct rte_eth_dev *dev)return -1 ; list->eth_dev = dev; -pthread_mutex_lock (&internal_list_lock); +rte_thread_mutex_lock (&internal_list_lock);TAILQ_INSERT_TAIL (&internal_list, list, next); -pthread_mutex_unlock (&internal_list_lock); +rte_thread_mutex_unlock (&internal_list_lock); }return 0 ;
@@ -948,9 +948,9 @@ eth_dev_close(struct rte_eth_dev *dev)/* Remove ethdev from list used to track and share UMEMs */ list =find_internal_resource (internals);if (list) { -pthread_mutex_lock (&internal_list_lock); +rte_thread_mutex_lock (&internal_list_lock);TAILQ_REMOVE (&internal_list, list, next); -pthread_mutex_unlock (&internal_list_lock); +rte_thread_mutex_unlock (&internal_list_lock);rte_free (list); } }
drivers/net/ark/ark_ethdev.c +1 -1
@@ -563,7 +563,7 @@ eth_ark_dev_start(struct rte_eth_dev *dev)ark_pktchkr_run (ark->pc);if (ark->start_pg && (dev->data->port_id ==0 )) { -pthread_t thread; +rte_thread_t thread;/* Delay packet generatpr start allow the hardware to be ready * This is only used for sanity checking with internal generator
drivers/net/ark/ark_pktgen.c +2 -2
@@ -3,7 +3,7 @@*/ #include <unistd.h> -#include <pthread.h> +#include <rte_thread.h> #include <rte_string_fns.h> #include <rte_malloc.h>
@@ -475,7 +475,7 @@ ark_pktgen_delay_start(void *arg)* perform a blind sleep here to ensure that the external test * application has time to setup the test before we generate packets */ -pthread_detach (pthread_self ()); +rte_thread_detach (rte_thread_self ());usleep (100000 );ark_pktgen_run (inst);return NULL ;
drivers/net/atlantic/atl_ethdev.c +2 -2
@@ -405,7 +405,7 @@ eth_atl_dev_init(struct rte_eth_dev *eth_dev) hw->aq_nic_cfg = &adapter->hw_cfg; -pthread_mutex_init (&hw->mbox_mutex,NULL ); +rte_thread_mutex_init (&hw->mbox_mutex);/* disable interrupt */ atl_disable_intr (hw);
@@ -712,7 +712,7 @@ atl_dev_close(struct rte_eth_dev *dev)rte_intr_callback_unregister (intr_handle, atl_dev_interrupt_handler, dev); -pthread_mutex_destroy (&hw->mbox_mutex); +rte_thread_mutex_destroy (&hw->mbox_mutex);return ret; }
drivers/net/atlantic/atl_types.h +3 -2
@@ -10,7 +10,8 @@#include <string.h> #include <stdbool.h> #include <netinet/in.h> -#include <pthread.h> +#include <rte_compat.h> +#include <rte_thread.h> #include <rte_common.h>
@@ -141,7 +142,7 @@ struct aq_hw_s {u32 rpc_tid;struct hw_aq_atl_utils_fw_rpc rpc; -pthread_mutex_t mbox_mutex; +rte_thread_mutex_t mbox_mutex; };struct aq_fw_ops {
drivers/net/atlantic/hw_atl/hw_atl_utils_fw2x.c +13 -13
@@ -6,7 +6,7 @@*/ #include <rte_ether.h> -#include <pthread.h> +#include <rte_thread.h> #include "../atl_hw_regs.h" #include "../atl_types.h"
@@ -218,7 +218,7 @@ int aq_fw2x_get_mac_permanent(struct aq_hw_s *self, u8 *mac)u32 mac_addr[2 ] = {0 };u32 efuse_addr =aq_hw_read_reg (self,HW_ATL_FW2X_MPI_EFUSE_ADDR ); -pthread_mutex_lock (&self->mbox_mutex); +rte_thread_mutex_lock (&self->mbox_mutex);if (efuse_addr !=0 ) { err = hw_atl_utils_fw_downld_dwords(self,
@@ -257,7 +257,7 @@ int aq_fw2x_get_mac_permanent(struct aq_hw_s *self, u8 *mac) } exit: -pthread_mutex_unlock (&self->mbox_mutex); +rte_thread_mutex_unlock (&self->mbox_mutex);return err; }
@@ -269,7 +269,7 @@ static int aq_fw2x_update_stats(struct aq_hw_s *self)u32 orig_stats_val = mpi_opts &BIT (CAPS_HI_STATISTICS ); -pthread_mutex_lock (&self->mbox_mutex); +rte_thread_mutex_lock (&self->mbox_mutex);/* Toggle statistics bit for FW to update */ mpi_opts = mpi_opts ^BIT (CAPS_HI_STATISTICS );
@@ -286,7 +286,7 @@ static int aq_fw2x_update_stats(struct aq_hw_s *self) err =hw_atl_utils_update_stats (self); exit: -pthread_mutex_unlock (&self->mbox_mutex); +rte_thread_mutex_unlock (&self->mbox_mutex);return err;
@@ -299,7 +299,7 @@ static int aq_fw2x_get_temp(struct aq_hw_s *self, int *temp)u32 temp_val = mpi_opts &BIT (CAPS_HI_TEMPERATURE );u32 temp_res; -pthread_mutex_lock (&self->mbox_mutex); +rte_thread_mutex_lock (&self->mbox_mutex);/* Toggle statistics bit for FW to 0x36C.18 (CAPS_HI_TEMPERATURE) */ mpi_opts = mpi_opts ^BIT (CAPS_HI_TEMPERATURE );
@@ -317,7 +317,7 @@ static int aq_fw2x_get_temp(struct aq_hw_s *self, int *temp) sizeof(temp_res) / sizeof(u32)); -pthread_mutex_unlock (&self->mbox_mutex); +rte_thread_mutex_unlock (&self->mbox_mutex);if (err)return err;
@@ -536,7 +536,7 @@ static int aq_fw2x_get_eeprom(struct aq_hw_s *self, int dev_addr,if ((self->caps_lo &BIT (CAPS_LO_SMBUS_READ )) ==0 )return -EOPNOTSUPP ; -pthread_mutex_lock (&self->mbox_mutex); +rte_thread_mutex_lock (&self->mbox_mutex); request.msg_id =0 ; request.device_id = dev_addr;
@@ -605,7 +605,7 @@ static int aq_fw2x_get_eeprom(struct aq_hw_s *self, int dev_addr, } exit: -pthread_mutex_unlock (&self->mbox_mutex); +rte_thread_mutex_unlock (&self->mbox_mutex);return err; }
@@ -626,7 +626,7 @@ static int aq_fw2x_set_eeprom(struct aq_hw_s *self, int dev_addr, request.address = offset; request.length = len; -pthread_mutex_lock (&self->mbox_mutex); +rte_thread_mutex_lock (&self->mbox_mutex);/* Write SMBUS request to cfg memory */ err = hw_atl_utils_fw_upload_dwords(self, self->rpc_addr,
@@ -694,7 +694,7 @@ static int aq_fw2x_set_eeprom(struct aq_hw_s *self, int dev_addr, } exit: -pthread_mutex_unlock (&self->mbox_mutex); +rte_thread_mutex_unlock (&self->mbox_mutex);return err; }
@@ -712,7 +712,7 @@ static int aq_fw2x_send_macsec_request(struct aq_hw_s *self,if ((self->caps_lo &BIT (CAPS_LO_MACSEC )) ==0 )return -EOPNOTSUPP ; -pthread_mutex_lock (&self->mbox_mutex); +rte_thread_mutex_lock (&self->mbox_mutex);/* Write macsec request to cfg memory */ err = hw_atl_utils_fw_upload_dwords(self, self->rpc_addr,
@@ -742,7 +742,7 @@ static int aq_fw2x_send_macsec_request(struct aq_hw_s *self, RTE_ALIGN(sizeof(*response) / sizeof(u32), sizeof(u32))); exit: -pthread_mutex_unlock (&self->mbox_mutex); +rte_thread_mutex_unlock (&self->mbox_mutex);return err; }
drivers/net/axgbe/axgbe_common.h +1 -1
@@ -19,7 +19,7 @@#include <stdarg.h> #include <unistd.h> #include <inttypes.h> -#include <pthread.h> +#include <rte_thread.h> #include <rte_bitops.h> #include <rte_byteorder.h>
drivers/net/axgbe/axgbe_dev.c +4 -4
@@ -167,12 +167,12 @@ static int axgbe_read_mmd_regs_v2(struct axgbe_port *pdata, index = mmd_address & ~pdata->xpcs_window_mask; offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); -pthread_mutex_lock (&pdata->xpcs_mutex); +rte_thread_mutex_lock (&pdata->xpcs_mutex);XPCS32_IOWRITE (pdata, pdata->xpcs_window_sel_reg, index); mmd_data =XPCS16_IOREAD (pdata, offset); -pthread_mutex_unlock (&pdata->xpcs_mutex); +rte_thread_mutex_unlock (&pdata->xpcs_mutex);return mmd_data; }
@@ -201,12 +201,12 @@ static void axgbe_write_mmd_regs_v2(struct axgbe_port *pdata, index = mmd_address & ~pdata->xpcs_window_mask; offset = pdata->xpcs_window + (mmd_address & pdata->xpcs_window_mask); -pthread_mutex_lock (&pdata->xpcs_mutex); +rte_thread_mutex_lock (&pdata->xpcs_mutex);XPCS32_IOWRITE (pdata, pdata->xpcs_window_sel_reg, index);XPCS16_IOWRITE (pdata, offset, mmd_data); -pthread_mutex_unlock (&pdata->xpcs_mutex); +rte_thread_mutex_unlock (&pdata->xpcs_mutex); } static int axgbe_read_mmd_regs(struct axgbe_port *pdata, int prtad,
drivers/net/axgbe/axgbe_ethdev.c +4 -4
@@ -2311,10 +2311,10 @@ eth_axgbe_dev_init(struct rte_eth_dev *eth_dev) pdata->tx_desc_count =AXGBE_MAX_RING_DESC ; pdata->rx_desc_count =AXGBE_MAX_RING_DESC ; -pthread_mutex_init (&pdata->xpcs_mutex,NULL ); -pthread_mutex_init (&pdata->i2c_mutex,NULL ); -pthread_mutex_init (&pdata->an_mutex,NULL ); -pthread_mutex_init (&pdata->phy_mutex,NULL ); +rte_thread_mutex_init (&pdata->xpcs_mutex); +rte_thread_mutex_init (&pdata->i2c_mutex); +rte_thread_mutex_init (&pdata->an_mutex); +rte_thread_mutex_init (&pdata->phy_mutex); ret = pdata->phy_if.phy_init (pdata);if (ret) {
drivers/net/axgbe/axgbe_ethdev.h +4 -4
@@ -602,10 +602,10 @@ struct axgbe_port {int phy_link;int phy_speed; -pthread_mutex_t xpcs_mutex; -pthread_mutex_t i2c_mutex; -pthread_mutex_t an_mutex; -pthread_mutex_t phy_mutex; +rte_thread_mutex_t xpcs_mutex; +rte_thread_mutex_t i2c_mutex; +rte_thread_mutex_t an_mutex; +rte_thread_mutex_t phy_mutex;/* Flow control settings */ unsigned int pause_autoneg;
drivers/net/axgbe/axgbe_i2c.c +2 -2
@@ -229,7 +229,7 @@ static int axgbe_i2c_xfer(struct axgbe_port *pdata, struct axgbe_i2c_op *op)int ret;uint64_t timeout; -pthread_mutex_lock (&pdata->i2c_mutex); +rte_thread_mutex_lock (&pdata->i2c_mutex); ret =axgbe_i2c_disable (pdata);if (ret) {PMD_DRV_LOG (ERR ,"failed to disable i2c master\n" );
@@ -282,7 +282,7 @@ static int axgbe_i2c_xfer(struct axgbe_port *pdata, struct axgbe_i2c_op *op) } unlock: -pthread_mutex_unlock (&pdata->i2c_mutex); +rte_thread_mutex_unlock (&pdata->i2c_mutex);return ret; }
drivers/net/axgbe/axgbe_mdio.c +4 -4
@@ -686,9 +686,9 @@ static void axgbe_an73_isr(struct axgbe_port *pdata)if (pdata->an_int) {/* Clear the interrupt(s) that fired and process them */ XMDIO_WRITE (pdata,MDIO_MMD_AN ,MDIO_AN_INT , ~pdata->an_int); -pthread_mutex_lock (&pdata->an_mutex); +rte_thread_mutex_lock (&pdata->an_mutex);axgbe_an73_state_machine (pdata); -pthread_mutex_unlock (&pdata->an_mutex); +rte_thread_mutex_unlock (&pdata->an_mutex); }else {/* Enable AN interrupts */ axgbe_an73_enable_interrupts (pdata);
@@ -977,7 +977,7 @@ static int axgbe_phy_config_aneg(struct axgbe_port *pdata) {int ret; -pthread_mutex_lock (&pdata->an_mutex); +rte_thread_mutex_lock (&pdata->an_mutex); ret =__axgbe_phy_config_aneg (pdata);if (ret)
@@ -985,7 +985,7 @@ static int axgbe_phy_config_aneg(struct axgbe_port *pdata)else rte_bit_relaxed_clear32 (AXGBE_LINK_ERR , &pdata->dev_state); -pthread_mutex_unlock (&pdata->an_mutex); +rte_thread_mutex_unlock (&pdata->an_mutex);return ret; }
drivers/net/axgbe/axgbe_phy_impl.c +3 -3
@@ -403,7 +403,7 @@ static void axgbe_phy_put_comm_ownership(struct axgbe_port *pdata) phy_data->comm_owned =0 ; -pthread_mutex_unlock (&pdata->phy_mutex); +rte_thread_mutex_unlock (&pdata->phy_mutex); }static int axgbe_phy_get_comm_ownership (struct axgbe_port *pdata)
@@ -416,7 +416,7 @@ static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata)* the driver needs to take the software mutex and then the hardware * mutexes before being able to use the busses. */ -pthread_mutex_lock (&pdata->phy_mutex); +rte_thread_mutex_lock (&pdata->phy_mutex);if (phy_data->comm_owned)return 0 ;
@@ -447,7 +447,7 @@ static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata)return 0 ; } -pthread_mutex_unlock (&pdata->phy_mutex); +rte_thread_mutex_unlock (&pdata->phy_mutex);PMD_DRV_LOG (ERR ,"unable to obtain hardware mutexes\n" );
drivers/net/bnxt/bnxt.h +8 -8
@@ -534,8 +534,8 @@ struct bnxt_mark_info {struct bnxt_rep_info {struct rte_eth_dev *vfr_eth_dev; -pthread_mutex_t vfr_lock; -pthread_mutex_t vfr_start_lock; +rte_thread_mutex_t vfr_lock; +rte_thread_mutex_t vfr_start_lock;bool conduit_valid; };
@@ -687,7 +687,7 @@ struct bnxt {#define BNXT_FW_CAP_ADV_FLOW_COUNTERS BIT(6)#define BNXT_FW_CAP_LINK_ADMIN BIT(7) -pthread_mutex_t flow_lock; +rte_thread_mutex_t flow_lock;uint32_t vnic_cap_flags;#define BNXT_VNIC_CAP_COS_CLASSIFY BIT(0)
@@ -741,18 +741,18 @@ struct bnxt {rte_iova_t hwrm_short_cmd_req_dma_addr;rte_spinlock_t hwrm_lock;/* synchronize between dev_configure_op and int handler */ -pthread_mutex_t def_cp_lock; +rte_thread_mutex_t def_cp_lock;/* synchronize between dev_start_op and async evt handler * Locking sequence in async evt handler will be * def_cp_lock * health_check_lock */ -pthread_mutex_t health_check_lock; +rte_thread_mutex_t health_check_lock;/* synchronize between dev_stop/dev_close_op and * error recovery thread triggered as part of * HWRM_ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY */ -pthread_mutex_t err_recovery_lock; +rte_thread_mutex_t err_recovery_lock;uint16_t max_req_len;uint16_t max_resp_len;uint16_t hwrm_max_ext_req_len;
@@ -944,10 +944,10 @@ uint16_t bnxt_dummy_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,extern const struct rte_flow_ops bnxt_flow_ops;#define bnxt_acquire_flow_lock (bp) \ - pthread_mutex_lock(&(bp)->flow_lock) + rte_thread_mutex_lock(&(bp)->flow_lock)#define bnxt_release_flow_lock (bp) \ - pthread_mutex_unlock(&(bp)->flow_lock) + rte_thread_mutex_unlock(&(bp)->flow_lock)#define BNXT_VALID_VNIC_OR_RET (bp, vnic_id) do { \ if ((vnic_id) >= (bp)->max_vnics) { \
drivers/net/bnxt/bnxt_cpr.c +2 -2
@@ -135,7 +135,7 @@ void bnxt_handle_async_event(struct bnxt *bp,return ; } -pthread_mutex_lock (&bp->err_recovery_lock); +rte_thread_mutex_lock (&bp->err_recovery_lock); event_data =rte_le_to_cpu_32 (async_cmp->event_data1);/* timestamp_lo/hi values are in units of 100ms */ bp->fw_reset_max_msecs = async_cmp->timestamp_hi ?
@@ -157,7 +157,7 @@ void bnxt_handle_async_event(struct bnxt *bp, } bp->flags |=BNXT_FLAG_FW_RESET ; -pthread_mutex_unlock (&bp->err_recovery_lock); +rte_thread_mutex_unlock (&bp->err_recovery_lock);rte_eal_alarm_set (US_PER_MS , bnxt_dev_reset_and_resume, (void *)bp);break ;
drivers/net/bnxt/bnxt_ethdev.c +26 -26
161 lines not on this page · raw message
drivers/net/bnxt/bnxt_irq.c +4 -4
@@ -30,15 +30,15 @@ void bnxt_int_handler(void *param)return ; raw_cons = cpr->cp_raw_cons; -pthread_mutex_lock (&bp->def_cp_lock); +rte_thread_mutex_lock (&bp->def_cp_lock);while (1 ) {if (!cpr || !cpr->cp_ring_struct || !cpr->cp_db.doorbell) { -pthread_mutex_unlock (&bp->def_cp_lock); +rte_thread_mutex_unlock (&bp->def_cp_lock);return ; }if (is_bnxt_in_error (bp)) { -pthread_mutex_unlock (&bp->def_cp_lock); +rte_thread_mutex_unlock (&bp->def_cp_lock);return ; }
@@ -58,7 +58,7 @@ void bnxt_int_handler(void *param)else B_CP_DB_REARM (cpr, cpr->cp_raw_cons); -pthread_mutex_unlock (&bp->def_cp_lock); +rte_thread_mutex_unlock (&bp->def_cp_lock); }int bnxt_free_int (struct bnxt *bp)
drivers/net/bnxt/bnxt_reps.c +5 -5
@@ -120,7 +120,7 @@ bnxt_rep_tx_burst(void *tx_queue, qid = vfr_txq->txq->queue_id; vf_rep_bp = vfr_txq->bp; parent = vf_rep_bp->parent_dev->data->dev_private; -pthread_mutex_lock (&parent->rep_info->vfr_lock); +rte_thread_mutex_lock (&parent->rep_info->vfr_lock); ptxq = parent->tx_queues[qid]; ptxq->vfr_tx_cfa_action = vf_rep_bp->vfr_tx_cfa_action;
@@ -132,7 +132,7 @@ bnxt_rep_tx_burst(void *tx_queue, rc =bnxt_xmit_pkts (ptxq, tx_pkts, nb_pkts); ptxq->vfr_tx_cfa_action =0 ; -pthread_mutex_unlock (&parent->rep_info->vfr_lock); +rte_thread_mutex_unlock (&parent->rep_info->vfr_lock);return rc; }
@@ -407,15 +407,15 @@ int bnxt_rep_dev_start_op(struct rte_eth_dev *eth_dev) rep_info = &parent_bp->rep_info[rep_bp->vf_id];BNXT_TF_DBG (DEBUG ,"BNXT Port:%d VFR start\n" , eth_dev->data->port_id); -pthread_mutex_lock (&rep_info->vfr_start_lock); +rte_thread_mutex_lock (&rep_info->vfr_start_lock);if (!rep_info->conduit_valid) { rc =bnxt_get_dflt_vnic_svif (parent_bp, rep_bp);if (rc || !rep_info->conduit_valid) { -pthread_mutex_unlock (&rep_info->vfr_start_lock); +rte_thread_mutex_unlock (&rep_info->vfr_start_lock);return rc; } } -pthread_mutex_unlock (&rep_info->vfr_start_lock); +rte_thread_mutex_unlock (&rep_info->vfr_start_lock); rc =bnxt_vfr_alloc (eth_dev);if (rc) {
drivers/net/bnxt/tf_ulp/bnxt_ulp.c +17 -17
@@ -28,7 +28,7 @@ STAILQ_HEAD(, bnxt_ulp_session_state) bnxt_ulp_session_list =STAILQ_HEAD_INITIALIZER (bnxt_ulp_session_list);/* Mutex to synchronize bnxt_ulp_session_list operations. */ -static pthread_mutex_t bnxt_ulp_global_mutex =PTHREAD_MUTEX_INITIALIZER ; +static rte_thread_mutex_t bnxt_ulp_global_mutex =RTE_THREAD_MUTEX_INITIALIZER ;/* * Allow the deletion of context only for the bnxt device that
@@ -640,7 +640,7 @@ ulp_ctx_detach(struct bnxt *bp)static void ulp_context_initialized (struct bnxt_ulp_session_state *session,bool *init) { -pthread_mutex_lock (&session->bnxt_ulp_mutex); +rte_thread_mutex_lock (&session->bnxt_ulp_mutex);if (!session->bnxt_ulp_init) { session->bnxt_ulp_init = true;
@@ -649,7 +649,7 @@ ulp_context_initialized(struct bnxt_ulp_session_state *session, bool *init) *init = true; } -pthread_mutex_unlock (&session->bnxt_ulp_mutex); +rte_thread_mutex_unlock (&session->bnxt_ulp_mutex); }/*
@@ -690,7 +690,7 @@ ulp_session_init(struct bnxt *bp, pci_dev =RTE_DEV_TO_PCI (bp->eth_dev->device); pci_addr = &pci_dev->addr; -pthread_mutex_lock (&bnxt_ulp_global_mutex); +rte_thread_mutex_lock (&bnxt_ulp_global_mutex); session =ulp_get_session (pci_addr);if (!session) {
@@ -701,17 +701,17 @@ ulp_session_init(struct bnxt *bp,if (!session) {BNXT_TF_DBG (ERR ,"Allocation failed for bnxt_ulp_session\n" ); -pthread_mutex_unlock (&bnxt_ulp_global_mutex); +rte_thread_mutex_unlock (&bnxt_ulp_global_mutex);return NULL ; }else {/* Add it to the queue */ session->pci_info.domain = pci_addr->domain; session->pci_info.bus = pci_addr->bus; - rc =pthread_mutex_init (&session->bnxt_ulp_mutex,NULL ); + rc =rte_thread_mutex_init (&session->bnxt_ulp_mutex);if (rc) {BNXT_TF_DBG (ERR ,"mutex create failed\n" ); -pthread_mutex_unlock (&bnxt_ulp_global_mutex); +rte_thread_mutex_unlock (&bnxt_ulp_global_mutex);return NULL ; } STAILQ_INSERT_TAIL(&bnxt_ulp_session_list,
@@ -719,7 +719,7 @@ ulp_session_init(struct bnxt *bp, } }ulp_context_initialized (session, init); -pthread_mutex_unlock (&bnxt_ulp_global_mutex); +rte_thread_mutex_unlock (&bnxt_ulp_global_mutex);return session; }
@@ -734,12 +734,12 @@ ulp_session_deinit(struct bnxt_ulp_session_state *session)return ;if (!session->cfg_data) { -pthread_mutex_lock (&bnxt_ulp_global_mutex); +rte_thread_mutex_lock (&bnxt_ulp_global_mutex);STAILQ_REMOVE (&bnxt_ulp_session_list, session, bnxt_ulp_session_state, next); -pthread_mutex_destroy (&session->bnxt_ulp_mutex); +rte_thread_mutex_destroy (&session->bnxt_ulp_mutex);rte_free (session); -pthread_mutex_unlock (&bnxt_ulp_global_mutex); +rte_thread_mutex_unlock (&bnxt_ulp_global_mutex); } }
@@ -892,7 +892,7 @@ bnxt_ulp_deinit(struct bnxt *bp, BNXT_ULP_NAT_OUTER_MOST_FLAGS, 0);/* free the flow db lock */ -pthread_mutex_destroy (&bp->ulp_ctx->cfg_data->flow_db_lock); +rte_thread_mutex_destroy (&bp->ulp_ctx->cfg_data->flow_db_lock);/* Delete the ulp context and tf session and free the ulp context */ ulp_ctx_deinit (bp, session);
@@ -917,7 +917,7 @@ bnxt_ulp_init(struct bnxt *bp, goto jump_to_error; } - rc =pthread_mutex_init (&bp->ulp_ctx->cfg_data->flow_db_lock,NULL ); + rc =rte_thread_mutex_init (&bp->ulp_ctx->cfg_data->flow_db_lock);if (rc) {BNXT_TF_DBG (ERR ,"Unable to initialize flow db lock\n" ); goto jump_to_error;
@@ -1117,9 +1117,9 @@ bnxt_ulp_port_deinit(struct bnxt *bp)/* Get the session details */ pci_dev =RTE_DEV_TO_PCI (bp->eth_dev->device); pci_addr = &pci_dev->addr; -pthread_mutex_lock (&bnxt_ulp_global_mutex); +rte_thread_mutex_lock (&bnxt_ulp_global_mutex); session =ulp_get_session (pci_addr); -pthread_mutex_unlock (&bnxt_ulp_global_mutex); +rte_thread_mutex_unlock (&bnxt_ulp_global_mutex);/* session not found then just exit */ if (!session) {
@@ -1451,7 +1451,7 @@ bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context *ulp_ctx)if (!ulp_ctx || !ulp_ctx->cfg_data)return -1 ; -if (pthread_mutex_lock (&ulp_ctx->cfg_data->flow_db_lock)) { +if (rte_thread_mutex_lock (&ulp_ctx->cfg_data->flow_db_lock)) {BNXT_TF_DBG (ERR ,"unable to acquire fdb lock\n" );return -1 ; }
@@ -1465,5 +1465,5 @@ bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context *ulp_ctx)if (!ulp_ctx || !ulp_ctx->cfg_data)return ; -pthread_mutex_unlock (&ulp_ctx->cfg_data->flow_db_lock); +rte_thread_mutex_unlock (&ulp_ctx->cfg_data->flow_db_lock); }
drivers/net/bnxt/tf_ulp/bnxt_ulp.h +2 -2
@@ -49,7 +49,7 @@ struct bnxt_ulp_data {uint32_t dev_id;/* Hardware device id */ uint32_t ref_cnt;struct bnxt_ulp_flow_db *flow_db; -pthread_mutex_t flow_db_lock; +rte_thread_mutex_t flow_db_lock;void *mapper_data;struct bnxt_ulp_port_db *port_db;struct bnxt_ulp_fc_info *fc_info;
@@ -75,7 +75,7 @@ struct bnxt_ulp_pci_info {struct bnxt_ulp_session_state {STAILQ_ENTRY (bnxt_ulp_session_state) next;bool bnxt_ulp_init; -pthread_mutex_t bnxt_ulp_mutex; +rte_thread_mutex_t bnxt_ulp_mutex;struct bnxt_ulp_pci_info pci_info;struct bnxt_ulp_data *cfg_data;struct tf *g_tfp;
drivers/net/bnxt/tf_ulp/ulp_fc_mgr.c +12 -12
@@ -84,7 +84,7 @@ ulp_fc_mgr_init(struct bnxt_ulp_context *ctxt)if (!ulp_fc_info) goto error; - rc =pthread_mutex_init (&ulp_fc_info->fc_lock,NULL ); + rc =rte_thread_mutex_init (&ulp_fc_info->fc_lock);if (rc) {PMD_DRV_LOG (ERR ,"Failed to initialize fc mutex\n" ); goto error;
@@ -141,7 +141,7 @@ ulp_fc_mgr_deinit(struct bnxt_ulp_context *ctxt)ulp_fc_mgr_thread_cancel (ctxt); -pthread_mutex_destroy (&ulp_fc_info->fc_lock); +rte_thread_mutex_destroy (&ulp_fc_info->fc_lock);for (i =0 ; i <TF_DIR_MAX ; i++)rte_free (ulp_fc_info->sw_acc_tbl[i]);
@@ -383,7 +383,7 @@ ulp_fc_mgr_alarm_cb(void *arg) goto out;if (!ulp_fc_info->num_entries) { -pthread_mutex_unlock (&ulp_fc_info->fc_lock); +rte_thread_mutex_unlock (&ulp_fc_info->fc_lock);ulp_fc_mgr_thread_cancel (ctxt);return ; }
@@ -414,7 +414,7 @@ ulp_fc_mgr_alarm_cb(void *arg) } } -pthread_mutex_unlock (&ulp_fc_info->fc_lock); +rte_thread_mutex_unlock (&ulp_fc_info->fc_lock);/* * If cmd fails once, no need of
@@ -503,12 +503,12 @@ int32_t ulp_fc_mgr_cntr_set(struct bnxt_ulp_context *ctxt, enum tf_dir dir,if (!ulp_fc_info)return -EIO ; -pthread_mutex_lock (&ulp_fc_info->fc_lock); +rte_thread_mutex_lock (&ulp_fc_info->fc_lock); sw_cntr_idx = hw_cntr_id - ulp_fc_info->shadow_hw_tbl[dir].start_idx; ulp_fc_info->sw_acc_tbl[dir][sw_cntr_idx].valid = true; ulp_fc_info->sw_acc_tbl[dir][sw_cntr_idx].hw_cntr_id = hw_cntr_id; ulp_fc_info->num_entries++; -pthread_mutex_unlock (&ulp_fc_info->fc_lock); +rte_thread_mutex_unlock (&ulp_fc_info->fc_lock);return 0 ; }
@@ -535,14 +535,14 @@ int32_t ulp_fc_mgr_cntr_reset(struct bnxt_ulp_context *ctxt, enum tf_dir dir,if (!ulp_fc_info)return -EIO ; -pthread_mutex_lock (&ulp_fc_info->fc_lock); +rte_thread_mutex_lock (&ulp_fc_info->fc_lock); sw_cntr_idx = hw_cntr_id - ulp_fc_info->shadow_hw_tbl[dir].start_idx; ulp_fc_info->sw_acc_tbl[dir][sw_cntr_idx].valid = false; ulp_fc_info->sw_acc_tbl[dir][sw_cntr_idx].hw_cntr_id =0 ; ulp_fc_info->sw_acc_tbl[dir][sw_cntr_idx].pkt_count =0 ; ulp_fc_info->sw_acc_tbl[dir][sw_cntr_idx].byte_count =0 ; ulp_fc_info->num_entries--; -pthread_mutex_unlock (&ulp_fc_info->fc_lock); +rte_thread_mutex_unlock (&ulp_fc_info->fc_lock);return 0 ; }
@@ -607,7 +607,7 @@ int ulp_fc_mgr_query_count_get(struct bnxt_ulp_context *ctxt, hw_cntr_id = params.resource_hndl;if (params.resource_sub_type ==BNXT_ULP_RESOURCE_SUB_TYPE_INDEX_TYPE_INT_COUNT ) { -pthread_mutex_lock (&ulp_fc_info->fc_lock); +rte_thread_mutex_lock (&ulp_fc_info->fc_lock); sw_cntr_idx = hw_cntr_id - ulp_fc_info->shadow_hw_tbl[dir].start_idx; sw_acc_tbl_entry = &ulp_fc_info->sw_acc_tbl[dir][sw_cntr_idx];
@@ -621,7 +621,7 @@ int ulp_fc_mgr_query_count_get(struct bnxt_ulp_context *ctxt, sw_acc_tbl_entry->pkt_count =0 ; sw_acc_tbl_entry->byte_count =0 ; } -pthread_mutex_unlock (&ulp_fc_info->fc_lock); +rte_thread_mutex_unlock (&ulp_fc_info->fc_lock); }else if (params.resource_sub_type ==BNXT_ULP_RESOURCE_SUB_TYPE_INDEX_TYPE_INT_COUNT_ACC ) {/* Get stats from the parent child table */
@@ -663,7 +663,7 @@ int32_t ulp_fc_mgr_cntr_parent_flow_set(struct bnxt_ulp_context *ctxt,if (!ulp_fc_info)return -EIO ; -pthread_mutex_lock (&ulp_fc_info->fc_lock); +rte_thread_mutex_lock (&ulp_fc_info->fc_lock); sw_cntr_idx = hw_cntr_id - ulp_fc_info->shadow_hw_tbl[dir].start_idx;if (ulp_fc_info->sw_acc_tbl[dir][sw_cntr_idx].valid) { ulp_fc_info->sw_acc_tbl[dir][sw_cntr_idx].parent_flow_id = fid;
@@ -672,7 +672,7 @@ int32_t ulp_fc_mgr_cntr_parent_flow_set(struct bnxt_ulp_context *ctxt, hw_cntr_id, fid); rc = -ENOENT ; } -pthread_mutex_unlock (&ulp_fc_info->fc_lock); +rte_thread_mutex_unlock (&ulp_fc_info->fc_lock);return rc; }
drivers/net/bnxt/tf_ulp/ulp_fc_mgr.h +1 -1
@@ -47,7 +47,7 @@ struct bnxt_ulp_fc_info {struct hw_fc_mem_info shadow_hw_tbl[TF_DIR_MAX ];uint32_t flags;uint32_t num_entries; -pthread_mutex_t fc_lock; +rte_thread_mutex_t fc_lock; };int32_t
drivers/net/ena/base/ena_plat_dpdk.h +6 -6
@@ -148,14 +148,14 @@ extern int ena_logtype_com;typedef struct {pthread_cond_t cond; -pthread_mutex_t mutex; +rte_thread_mutex_t mutex;uint8_t flag; }ena_wait_event_t ;#define ENA_WAIT_EVENT_INIT (waitevent) \ do { \ ena_wait_event_t *_we = &(waitevent); \ - pthread_mutex_init(&_we->mutex, NULL); \ + rte_thread_mutex_init(&_we->mutex); \ pthread_cond_init(&_we->cond, NULL); \ _we->flag = 0; \ } while (0)
@@ -172,7 +172,7 @@ typedef struct { wait.tv_sec = now.tv_sec + _tmo /1000000UL ; \ timeout_us = _tmo %1000000UL ; \ wait.tv_nsec = (now.tv_usec + timeout_us) *1000UL ; \ -pthread_mutex_lock (&_we->mutex); \ +rte_thread_mutex_lock (&_we->mutex); \while (ret ==0 && !_we->flag) { \ ret =pthread_cond_timedwait (&_we->cond, \ &_we->mutex, &wait); \
@@ -185,15 +185,15 @@ typedef struct {ena_trc_err (NULL , \ "Timeout waiting for " #waitevent "\n"); \ _we->flag =0 ; \ -pthread_mutex_unlock (&_we->mutex); \ +rte_thread_mutex_unlock (&_we->mutex); \ } while (0)#define ENA_WAIT_EVENT_SIGNAL (waitevent) \ do { \ ena_wait_event_t *_we = &(waitevent); \ - pthread_mutex_lock(&_we->mutex); \ + rte_thread_mutex_lock(&_we->mutex); \ _we->flag = 1; \ pthread_cond_signal(&_we->cond); \ - pthread_mutex_unlock(&_we->mutex); \ + rte_thread_mutex_unlock(&_we->mutex); \ } while (0)/* pthread condition doesn't need to be rearmed after usage */ #define ENA_WAIT_EVENT_CLEAR (...)
drivers/net/enic/enic.h +1 -1
@@ -107,7 +107,7 @@ struct enic {int iommu_groupid;int eventfd;uint8_t mac_addr[RTE_ETHER_ADDR_LEN ]; -pthread_t err_intr_thread; +rte_thread_t err_intr_thread;int promisc;int allmulti;uint8_t ig_vlan_strip_en;
drivers/net/ice/ice_dcf_parent.c +3 -3
@@ -3,7 +3,7 @@*/ #include <sys/types.h> #include <sys/stat.h> -#include <pthread.h> +#include <rte_thread.h> #include <unistd.h> #include <rte_spinlock.h>
@@ -121,7 +121,7 @@ ice_dcf_vsi_update_service_handler(void *param)struct ice_dcf_hw *hw = reset_param->dcf_hw;struct ice_dcf_adapter *adapter; -pthread_detach (pthread_self ()); +rte_thread_detach (rte_thread_self ());rte_delay_us (ICE_DCF_VSI_UPDATE_SERVICE_INTERVAL );
@@ -156,7 +156,7 @@ start_vsi_reset_thread(struct ice_dcf_hw *dcf_hw, bool vfr, uint16_t vf_id)#define THREAD_NAME_LEN 16struct ice_dcf_reset_event_param *param;char name[THREAD_NAME_LEN ]; -pthread_t thread; +rte_thread_t thread;int ret; param =malloc (sizeof (*param));
drivers/net/ipn3ke/ipn3ke_representor.c +3 -3
@@ -27,7 +27,7 @@#include "ipn3ke_ethdev.h" static int ipn3ke_rpst_scan_num; -static pthread_t ipn3ke_rpst_scan_thread; +static rte_thread_t ipn3ke_rpst_scan_thread;/** Double linked list of representor port. */ TAILQ_HEAD (ipn3ke_rpst_list, ipn3ke_rpst);
@@ -2614,11 +2614,11 @@ ipn3ke_rpst_scan_check(void)return -1 ; } }else if (ipn3ke_rpst_scan_num ==0 ) { - ret =pthread_cancel (ipn3ke_rpst_scan_thread); + ret =rte_thread_cancel (ipn3ke_rpst_scan_thread);if (ret)IPN3KE_AFU_PMD_ERR ("Can't cancel the thread" ); - ret =pthread_join (ipn3ke_rpst_scan_thread,NULL ); + ret =rte_thread_join (ipn3ke_rpst_scan_thread,NULL );if (ret)IPN3KE_AFU_PMD_ERR ("Can't join the thread" );
drivers/net/ixgbe/ixgbe_ethdev.c +1 -1
@@ -4156,7 +4156,7 @@ ixgbe_dev_setup_link_thread_handler(void *param)u32 speed;bool autoneg = false; -pthread_detach (pthread_self ()); +rte_thread_detach (rte_thread_self ()); speed = hw->phy.autoneg_advertised;if (!speed)ixgbe_get_link_capabilities (hw, &speed, &autoneg);
drivers/net/ixgbe/ixgbe_ethdev.h +1 -1
@@ -516,7 +516,7 @@ struct ixgbe_adapter {uint8_t pflink_fullchk;uint8_t mac_ctrl_frame_fwd;rte_atomic32_t link_thread_running; -pthread_t link_thread_tid; +rte_thread_t link_thread_tid; };struct ixgbe_vf_representor {
drivers/net/kni/rte_eth_kni.c +4 -4
@@ -3,7 +3,7 @@*/ #include <fcntl.h> -#include <pthread.h> +#include <rte_thread.h> #include <unistd.h> #include <rte_string_fns.h>
@@ -50,7 +50,7 @@ struct pmd_internals {uint16_t port_id;int is_kni_started; -pthread_t thread; +rte_thread_t thread;int stop_thread;int no_request_thread;
@@ -186,11 +186,11 @@ eth_kni_dev_stop(struct rte_eth_dev *dev)if (internals->no_request_thread ==0 && internals->stop_thread ==0 ) { internals->stop_thread =1 ; - ret =pthread_cancel (internals->thread); + ret =rte_thread_cancel (internals->thread);if (ret)PMD_LOG (ERR ,"Can't cancel the thread" ); - ret =pthread_join (internals->thread,NULL ); + ret =rte_thread_join (internals->thread,NULL );if (ret)PMD_LOG (ERR ,"Can't join the thread" ); }
drivers/net/mlx5/linux/mlx5_os.c +1 -1
@@ -2557,7 +2557,7 @@ mlx5_os_open_device(const struct mlx5_dev_spawn_data *spawn,int err =0 ; sh->numa_node = spawn->pci_dev->device.numa_node; -pthread_mutex_init (&sh->txpp.mutex,NULL ); +rte_thread_mutex_init (&sh->txpp.mutex);/* * Configure environment variable "MLX5_BF_SHUT_UP" * before the device creation. The rdma_core library
drivers/net/mlx5/mlx5.c +10 -10
@@ -183,7 +183,7 @@ int mlx5_logtype; static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =LIST_HEAD_INITIALIZER (); -static pthread_mutex_t mlx5_dev_ctx_list_mutex; +static rte_thread_mutex_t mlx5_dev_ctx_list_mutex; static const struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = { #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) [MLX5_IPOOL_DECAP_ENCAP] = {
@@ -1088,7 +1088,7 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,MLX5_ASSERT (spawn);/* Secondary process should not create the shared context. */ MLX5_ASSERT (rte_eal_process_type () ==RTE_PROC_PRIMARY ); -pthread_mutex_lock (&mlx5_dev_ctx_list_mutex); +rte_thread_mutex_lock (&mlx5_dev_ctx_list_mutex);/* Search for IB context by device name. */ LIST_FOREACH(sh, &mlx5_dev_ctx_list, next) { if (!strcmp(sh->ibdev_name,
@@ -1215,11 +1215,11 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,LIST_INSERT_HEAD (&mlx5_dev_ctx_list, sh, next);rte_spinlock_init (&sh->geneve_tlv_opt_sl); exit: -pthread_mutex_unlock (&mlx5_dev_ctx_list_mutex); +rte_thread_mutex_unlock (&mlx5_dev_ctx_list_mutex);return sh; error: -pthread_mutex_destroy (&sh->txpp.mutex); -pthread_mutex_unlock (&mlx5_dev_ctx_list_mutex); +rte_thread_mutex_destroy (&sh->txpp.mutex); +rte_thread_mutex_unlock (&mlx5_dev_ctx_list_mutex);MLX5_ASSERT (sh);if (sh->cnt_id_tbl)mlx5_l3t_destroy (sh->cnt_id_tbl);
@@ -1251,7 +1251,7 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,void mlx5_free_shared_dev_ctx (struct mlx5_dev_ctx_shared *sh) { -pthread_mutex_lock (&mlx5_dev_ctx_list_mutex); +rte_thread_mutex_lock (&mlx5_dev_ctx_list_mutex);#ifdef RTE_LIBRTE_MLX5_DEBUG /* Check the object presence in the list. */ struct mlx5_dev_ctx_shared *lctx;
@@ -1282,7 +1282,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)/* Release flow workspaces objects on the last device. */ if (LIST_EMPTY (&mlx5_dev_ctx_list))mlx5_flow_os_release_workspace (); -pthread_mutex_unlock (&mlx5_dev_ctx_list_mutex); +rte_thread_mutex_unlock (&mlx5_dev_ctx_list_mutex);/* * Ensure there is no async event handler installed. * Only primary process handles async device events.
@@ -1315,11 +1315,11 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)if (sh->ctx)claim_zero (mlx5_glue->close_device (sh->ctx));MLX5_ASSERT (sh->geneve_tlv_option_resource ==NULL ); -pthread_mutex_destroy (&sh->txpp.mutex); +rte_thread_mutex_destroy (&sh->txpp.mutex);mlx5_free (sh);return ; exit: -pthread_mutex_unlock (&mlx5_dev_ctx_list_mutex); +rte_thread_mutex_unlock (&mlx5_dev_ctx_list_mutex); }/**
@@ -2450,7 +2450,7 @@ RTE_LOG_REGISTER_DEFAULT(mlx5_logtype, NOTICE)*/ RTE_INIT (rte_mlx5_pmd_init) { -pthread_mutex_init (&mlx5_dev_ctx_list_mutex,NULL ); +rte_thread_mutex_init (&mlx5_dev_ctx_list_mutex);mlx5_common_init ();/* Build the static tables for Verbs conversion. */ mlx5_set_ptype_table ();
drivers/net/mlx5/mlx5.h +1 -1
@@ -949,7 +949,7 @@ struct mlx5_txpp_ts {/* Tx packet pacing structure. */ struct mlx5_dev_txpp { -pthread_mutex_t mutex;/* Pacing create/destroy mutex. */ +rte_thread_mutex_t mutex;/* Pacing create/destroy mutex. */ uint32_t refcnt;/* Pacing reference counter. */ uint32_t freq;/* Timestamp frequency, Hz. */ uint32_t tick;/* Completion tick duration in nanoseconds. */
drivers/net/mlx5/mlx5_txpp.c +4 -4
@@ -905,7 +905,7 @@ mlx5_txpp_start(struct rte_eth_dev *dev)if (ret <0 )return 0 ; } - ret =pthread_mutex_lock (&sh->txpp.mutex); + ret =rte_thread_mutex_lock (&sh->txpp.mutex);MLX5_ASSERT (!ret);RTE_SET_USED (ret);if (sh->txpp.refcnt) {
@@ -921,7 +921,7 @@ mlx5_txpp_start(struct rte_eth_dev *dev) rte_errno = -err; } } - ret =pthread_mutex_unlock (&sh->txpp.mutex); + ret =rte_thread_mutex_unlock (&sh->txpp.mutex);MLX5_ASSERT (!ret);RTE_SET_USED (ret);return err;
@@ -948,7 +948,7 @@ mlx5_txpp_stop(struct rte_eth_dev *dev)return ; } priv->txpp_en =0 ; - ret =pthread_mutex_lock (&sh->txpp.mutex); + ret =rte_thread_mutex_lock (&sh->txpp.mutex);MLX5_ASSERT (!ret);RTE_SET_USED (ret);MLX5_ASSERT (sh->txpp.refcnt);
@@ -956,7 +956,7 @@ mlx5_txpp_stop(struct rte_eth_dev *dev)return ;/* No references any more, do actual destroy. */ mlx5_txpp_destroy (sh); - ret =pthread_mutex_unlock (&sh->txpp.mutex); + ret =rte_thread_mutex_unlock (&sh->txpp.mutex);MLX5_ASSERT (!ret);RTE_SET_USED (ret); }
drivers/net/mlx5/windows/mlx5_flow_os.c +5 -5
@@ -253,7 +253,7 @@ struct mlx5_workspace_thread {static struct mlx5_workspace_thread *curr;static struct mlx5_workspace_thread *first;rte_thread_key ws_tls_index; -static pthread_mutex_t lock_thread_list; +static rte_thread_mutex_t lock_thread_list;static bool mlx5_is_thread_alive (HANDLE thread_handle)
@@ -330,7 +330,7 @@ mlx5_flow_os_release_workspace(void)free (first); }rte_thread_key_delete (ws_tls_index); -pthread_mutex_destroy (&lock_thread_list); +rte_thread_mutex_destroy (&lock_thread_list); } static int
@@ -352,7 +352,7 @@ mlx5_add_workspace_to_list(struct mlx5_flow_workspace *data) } temp->mlx5_ws = data; temp->thread_handle = curr_thread; -pthread_mutex_lock (&lock_thread_list); +rte_thread_mutex_lock (&lock_thread_list);mlx5_clear_thread_list ();if (!first) { first = temp;
@@ -361,7 +361,7 @@ mlx5_add_workspace_to_list(struct mlx5_flow_workspace *data) curr->next = temp; curr = curr->next; } -pthread_mutex_unlock (&lock_thread_list); +rte_thread_mutex_unlock (&lock_thread_list);return 0 ; }
@@ -374,7 +374,7 @@ mlx5_flow_os_init_workspace_once(void)DRV_LOG (ERR ,"Can't create flow workspace data thread key." );return err; } -pthread_mutex_init (&lock_thread_list,NULL ); +rte_thread_mutex_init (&lock_thread_list);return 0 ; }
drivers/net/mlx5/windows/mlx5_os.c +1 -1
@@ -228,7 +228,7 @@ mlx5_os_open_device(const struct mlx5_dev_spawn_data *spawn,int err =0 ;struct mlx5_context *mlx5_ctx; -pthread_mutex_init (&sh->txpp.mutex,NULL ); +rte_thread_mutex_init (&sh->txpp.mutex);/* Set numa node from pci probe */ sh->numa_node = spawn->pci_dev->device.numa_node;
drivers/net/qede/base/bcm_osal.h +4 -4
@@ -153,10 +153,10 @@ void osal_dma_free_mem(struct ecore_dev *edev, dma_addr_t phys);/* Mutexes */ -typedef pthread_mutex_t osal_mutex_t ; -#define OSAL_MUTEX_RELEASE (lock) pthread_mutex_unlock(lock) -#define OSAL_MUTEX_INIT (lock) pthread_mutex_init(lock, NULL) -#define OSAL_MUTEX_ACQUIRE (lock) pthread_mutex_lock(lock) +typedef rte_thread_mutex_t osal_mutex_t ; +#define OSAL_MUTEX_RELEASE (lock) rte_thread_mutex_unlock(lock) +#define OSAL_MUTEX_INIT (lock) rte_thread_mutex_init(lock) +#define OSAL_MUTEX_ACQUIRE (lock) rte_thread_mutex_lock(lock)#define OSAL_MUTEX_ALLOC (hwfn, lock) nothing#define OSAL_MUTEX_DEALLOC (lock) nothing
drivers/net/vhost/rte_eth_vhost.c +12 -12
@@ -3,7 +3,7 @@* Copyright(c) 2016-2018 Intel Corporation */ #include <unistd.h> -#include <pthread.h> +#include <rte_thread.h> #include <stdbool.h> #include <sys/epoll.h>
@@ -121,7 +121,7 @@ TAILQ_HEAD(internal_list_head, internal_list);static struct internal_list_head internal_list =TAILQ_HEAD_INITIALIZER (internal_list); -static pthread_mutex_t internal_list_lock =PTHREAD_MUTEX_INITIALIZER ; +static rte_thread_mutex_t internal_list_lock =RTE_THREAD_MUTEX_INITIALIZER ;static struct rte_eth_link pmd_link = { .link_speed =10000 ,
@@ -507,7 +507,7 @@ find_internal_resource(char *ifname)if (ifname ==NULL )return NULL ; -pthread_mutex_lock (&internal_list_lock); +rte_thread_mutex_lock (&internal_list_lock); TAILQ_FOREACH(list, &internal_list, next) { internal = list->eth_dev->data->dev_private;
@@ -517,7 +517,7 @@ find_internal_resource(char *ifname) } } -pthread_mutex_unlock (&internal_list_lock); +rte_thread_mutex_unlock (&internal_list_lock);if (!found)return NULL ;
@@ -1001,9 +1001,9 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev) goto free_list; list->eth_dev = eth_dev; -pthread_mutex_lock (&internal_list_lock); +rte_thread_mutex_lock (&internal_list_lock);TAILQ_INSERT_TAIL (&internal_list, list, next); -pthread_mutex_unlock (&internal_list_lock); +rte_thread_mutex_unlock (&internal_list_lock);rte_spinlock_init (&vring_state->lock); vring_states[eth_dev->data->port_id] = vring_state;
@@ -1035,9 +1035,9 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev)rte_vhost_driver_unregister (internal->iface_name); list_remove: vring_states[eth_dev->data->port_id] =NULL ; -pthread_mutex_lock (&internal_list_lock); +rte_thread_mutex_lock (&internal_list_lock);TAILQ_REMOVE (&internal_list, list, next); -pthread_mutex_unlock (&internal_list_lock); +rte_thread_mutex_unlock (&internal_list_lock);rte_free (vring_state); free_list:rte_free (list);
@@ -1093,7 +1093,7 @@ rte_eth_vhost_get_vid_from_port_id(uint16_t port_id)if (!rte_eth_dev_is_valid_port (port_id))return -1 ; -pthread_mutex_lock (&internal_list_lock); +rte_thread_mutex_lock (&internal_list_lock); TAILQ_FOREACH(list, &internal_list, next) { eth_dev = list->eth_dev;
@@ -1106,7 +1106,7 @@ rte_eth_vhost_get_vid_from_port_id(uint16_t port_id) } } -pthread_mutex_unlock (&internal_list_lock); +rte_thread_mutex_unlock (&internal_list_lock);return vid; }
@@ -1184,9 +1184,9 @@ eth_dev_close(struct rte_eth_dev *dev) list =find_internal_resource (internal->iface_name);if (list) {rte_vhost_driver_unregister (internal->iface_name); -pthread_mutex_lock (&internal_list_lock); +rte_thread_mutex_lock (&internal_list_lock);TAILQ_REMOVE (&internal_list, list, next); -pthread_mutex_unlock (&internal_list_lock); +rte_thread_mutex_unlock (&internal_list_lock);rte_free (list); }
drivers/net/virtio/virtio_user/virtio_user_dev.c +15 -15
@@ -143,7 +143,7 @@ virtio_user_dev_set_features(struct virtio_user_dev *dev)uint64_t features;int ret =-1 ; -pthread_mutex_lock (&dev->mutex); +rte_thread_mutex_lock (&dev->mutex);/* Step 0: tell vhost to create queues */ if (virtio_user_queue_setup (dev, virtio_user_create_queue) <0 )
@@ -161,7 +161,7 @@ virtio_user_dev_set_features(struct virtio_user_dev *dev) goto error;PMD_DRV_LOG (INFO ,"(%s) set features: 0x%" PRIx64, dev->path, features); error: -pthread_mutex_unlock (&dev->mutex); +rte_thread_mutex_unlock (&dev->mutex);return ret; }
@@ -185,7 +185,7 @@ virtio_user_start_device(struct virtio_user_dev *dev)* memory subsystem in the future. */ rte_mcfg_mem_read_lock (); -pthread_mutex_lock (&dev->mutex); +rte_thread_mutex_lock (&dev->mutex);/* Step 2: share memory regions */ ret = dev->ops->set_memory_table (dev);
@@ -206,12 +206,12 @@ virtio_user_start_device(struct virtio_user_dev *dev) dev->started = true; -pthread_mutex_unlock (&dev->mutex); +rte_thread_mutex_unlock (&dev->mutex);rte_mcfg_mem_read_unlock ();return 0 ; error: -pthread_mutex_unlock (&dev->mutex); +rte_thread_mutex_unlock (&dev->mutex);rte_mcfg_mem_read_unlock ();PMD_INIT_LOG (ERR ,"(%s) Failed to start device\n" , dev->path);
@@ -226,7 +226,7 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)uint32_t i;int ret; -pthread_mutex_lock (&dev->mutex); +rte_thread_mutex_lock (&dev->mutex);if (!dev->started) goto out;
@@ -249,11 +249,11 @@ int virtio_user_stop_device(struct virtio_user_dev *dev) dev->started = false; out: -pthread_mutex_unlock (&dev->mutex); +rte_thread_mutex_unlock (&dev->mutex);return 0 ; err: -pthread_mutex_unlock (&dev->mutex); +rte_thread_mutex_unlock (&dev->mutex);PMD_INIT_LOG (ERR ,"(%s) Failed to stop device\n" , dev->path);
@@ -380,7 +380,7 @@ virtio_user_mem_event_cb(enum rte_mem_event type __rte_unused,if (msl->external)return ; -pthread_mutex_lock (&dev->mutex); +rte_thread_mutex_lock (&dev->mutex);if (dev->started == false) goto exit;
@@ -405,7 +405,7 @@ virtio_user_mem_event_cb(enum rte_mem_event type __rte_unused, } exit: -pthread_mutex_unlock (&dev->mutex); +rte_thread_mutex_unlock (&dev->mutex);if (ret <0 )PMD_DRV_LOG (ERR ,"(%s) Failed to update memory table\n" , dev->path);
@@ -491,7 +491,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,uint64_t backend_features;int i; -pthread_mutex_init (&dev->mutex,NULL ); +rte_thread_mutex_init (&dev->mutex);strlcpy (dev->path, path,PATH_MAX );for (i =0 ; i <VIRTIO_MAX_VIRTQUEUES ; i++) {
@@ -796,13 +796,13 @@ virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status) {int ret; -pthread_mutex_lock (&dev->mutex); +rte_thread_mutex_lock (&dev->mutex); dev->status = status; ret = dev->ops->set_status (dev, status);if (ret && ret != -ENOTSUP )PMD_INIT_LOG (ERR ,"(%s) Failed to set backend status\n" , dev->path); -pthread_mutex_unlock (&dev->mutex); +rte_thread_mutex_unlock (&dev->mutex);return ret; }
@@ -812,7 +812,7 @@ virtio_user_dev_update_status(struct virtio_user_dev *dev)int ret;uint8_t status; -pthread_mutex_lock (&dev->mutex); +rte_thread_mutex_lock (&dev->mutex); ret = dev->ops->get_status (dev, &status);if (!ret) {
@@ -837,7 +837,7 @@ virtio_user_dev_update_status(struct virtio_user_dev *dev)PMD_INIT_LOG (ERR ,"(%s) Failed to get backend status\n" , dev->path); } -pthread_mutex_unlock (&dev->mutex); +rte_thread_mutex_unlock (&dev->mutex);return ret; }
drivers/net/virtio/virtio_user/virtio_user_dev.h +1 -1
@@ -55,7 +55,7 @@ struct virtio_user_dev {bool qp_enabled[VIRTIO_MAX_VIRTQUEUE_PAIRS ];struct virtio_user_backend_ops *ops; -pthread_mutex_t mutex; +rte_thread_mutex_t mutex;bool started;void *backend_data;
drivers/raw/ifpga/ifpga_rawdev.c +3 -3
@@ -69,7 +69,7 @@ static const struct rte_pci_id pci_ifpga_map[] = {static struct ifpga_rawdev ifpga_rawdevices[IFPGA_RAWDEV_NUM ];static int ifpga_monitor_start; -static pthread_t ifpga_monitor_start_thread; +static rte_thread_t ifpga_monitor_start_thread;#define IFPGA_MAX_IRQ 12/* 0 for FME interrupt, others are reserved for AFU irq */
@@ -545,11 +545,11 @@ ifpga_monitor_stop_func(void)int ret;if (ifpga_monitor_start ==1 ) { - ret =pthread_cancel (ifpga_monitor_start_thread); + ret =rte_thread_cancel (ifpga_monitor_start_thread);if (ret)IFPGA_RAWDEV_PMD_ERR ("Can't cancel the thread" ); - ret =pthread_join (ifpga_monitor_start_thread,NULL ); + ret =rte_thread_join (ifpga_monitor_start_thread,NULL );if (ret)IFPGA_RAWDEV_PMD_ERR ("Can't join the thread" );
drivers/vdpa/ifc/ifcvf_vdpa.c +21 -25
128 lines not on this page · raw message
drivers/vdpa/mlx5/mlx5_vdpa.c +12 -12
@@ -48,7 +48,7 @@ TAILQ_HEAD(mlx5_vdpa_privs, mlx5_vdpa_priv) priv_list =TAILQ_HEAD_INITIALIZER (priv_list); -static pthread_mutex_t priv_list_lock =PTHREAD_MUTEX_INITIALIZER ; +static rte_thread_mutex_t priv_list_lock =RTE_THREAD_MUTEX_INITIALIZER ;static struct mlx5_vdpa_priv *mlx5_vdpa_find_priv_resource_by_vdev (struct rte_vdpa_device *vdev)
@@ -56,14 +56,14 @@ mlx5_vdpa_find_priv_resource_by_vdev(struct rte_vdpa_device *vdev)struct mlx5_vdpa_priv *priv;int found =0 ; -pthread_mutex_lock (&priv_list_lock); +rte_thread_mutex_lock (&priv_list_lock); TAILQ_FOREACH(priv, &priv_list, next) {if (vdev == priv->vdev) { found =1 ;break ; } } -pthread_mutex_unlock (&priv_list_lock); +rte_thread_mutex_unlock (&priv_list_lock);if (!found) {DRV_LOG (ERR ,"Invalid vDPA device: %s." , vdev->device->name); rte_errno =EINVAL ;
@@ -143,9 +143,9 @@ mlx5_vdpa_set_vring_state(int vid, int vring, int state)DRV_LOG (ERR ,"Too big vring id: %d." , vring);return -E2BIG ; } -pthread_mutex_lock (&priv->vq_config_lock); +rte_thread_mutex_lock (&priv->vq_config_lock); ret =mlx5_vdpa_virtq_enable (priv, vring, state); -pthread_mutex_unlock (&priv->vq_config_lock); +rte_thread_mutex_unlock (&priv->vq_config_lock);return ret; }
@@ -296,7 +296,7 @@ mlx5_vdpa_dev_close(int vid) priv->configured =0 ; priv->vid =0 ;/* The mutex may stay locked after event thread cancel - initiate it. */ -pthread_mutex_init (&priv->vq_config_lock,NULL ); +rte_thread_mutex_init (&priv->vq_config_lock);DRV_LOG (INFO ,"vDPA device %d was closed." , vid);return ret; }
@@ -736,10 +736,10 @@ mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, }mlx5_vdpa_config_get (pci_dev->device.devargs, priv);SLIST_INIT (&priv->mr_list); -pthread_mutex_init (&priv->vq_config_lock,NULL ); -pthread_mutex_lock (&priv_list_lock); +rte_thread_mutex_init (&priv->vq_config_lock); +rte_thread_mutex_lock (&priv_list_lock);TAILQ_INSERT_TAIL (&priv_list, priv, next); -pthread_mutex_unlock (&priv_list_lock); +rte_thread_mutex_unlock (&priv_list_lock);return 0 ; error:
@@ -770,7 +770,7 @@ mlx5_vdpa_pci_remove(struct rte_pci_device *pci_dev)struct mlx5_vdpa_priv *priv =NULL ;int found =0 ; -pthread_mutex_lock (&priv_list_lock); +rte_thread_mutex_lock (&priv_list_lock); TAILQ_FOREACH(priv, &priv_list, next) {if (!rte_pci_addr_cmp (&priv->pci_dev->addr, &pci_dev->addr)) { found =1 ;
@@ -779,7 +779,7 @@ mlx5_vdpa_pci_remove(struct rte_pci_device *pci_dev) }if (found)TAILQ_REMOVE (&priv_list, priv, next); -pthread_mutex_unlock (&priv_list_lock); +rte_thread_mutex_unlock (&priv_list_lock);if (found) {if (priv->configured)mlx5_vdpa_dev_close (priv->vid);
@@ -790,7 +790,7 @@ mlx5_vdpa_pci_remove(struct rte_pci_device *pci_dev)if (priv->vdev)rte_vdpa_unregister_device (priv->vdev); mlx5_glue->close_device (priv->ctx); -pthread_mutex_destroy (&priv->vq_config_lock); +rte_thread_mutex_destroy (&priv->vq_config_lock);rte_free (priv); }return 0 ;
drivers/vdpa/mlx5/mlx5_vdpa.h +2 -2
@@ -119,9 +119,9 @@ enum {struct mlx5_vdpa_priv {TAILQ_ENTRY (mlx5_vdpa_priv) next;uint8_t configured; -pthread_mutex_t vq_config_lock; +rte_thread_mutex_t vq_config_lock;uint64_t no_traffic_counter; -pthread_t timer_tid; +rte_thread_t timer_tid;int event_mode;int event_core;/* Event thread cpu affinity core. */ uint32_t event_us;
drivers/vdpa/mlx5/mlx5_vdpa_event.c +21 -25
122 lines not on this page · raw message
examples/kni/main.c +3 -3
@@ -1042,8 +1042,8 @@ main(int argc, char** argv)int ret;uint16_t nb_sys_ports, port;unsigned i; -void *retval; -pthread_t kni_link_tid; +int retval; +rte_thread_t kni_link_tid;int pid;/* Associate signal_hanlder function with USR signals */
@@ -1126,7 +1126,7 @@ main(int argc, char** argv)return -1 ; } monitor_links =0 ; -pthread_join (kni_link_tid, &retval); +rte_thread_join (kni_link_tid, &retval);/* Release resources */ RTE_ETH_FOREACH_DEV (port) {
examples/performance-thread/pthread_shim/main.c +1 -1
@@ -164,7 +164,7 @@ static void *initial_lthread(void *args __rte_unused)rte_exit (EXIT_FAILURE ,"Cannot create helloworld thread\n" );snprintf (name,sizeof (name),"helloworld-%u" , (uint32_t )i); -rte_thread_setname (tid[i], name); +pthread_setname_np (tid[i], name); }/* wait for 1s to allow threads
examples/vhost/main.c +1 -1
@@ -1634,7 +1634,7 @@ main(int argc, char *argv[])unsigned nb_ports, valid_num_ports;int ret, i;uint16_t portid; -static pthread_t tid; +static rte_thread_t tid;uint64_t flags =RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS ;signal (SIGINT , sigint_handler);
examples/vhost_blk/vhost_blk.c +6 -6
@@ -5,7 +5,7 @@#ifndef _GNU_SOURCE#define _GNU_SOURCE#endif -#include <pthread.h> +#include <rte_thread.h> #include <sched.h> #include <stdint.h>
@@ -533,7 +533,7 @@ ctrlr_worker(void *arg) {struct vhost_blk_ctrlr *ctrlr = (struct vhost_blk_ctrlr *)arg;cpu_set_t cpuset; -pthread_t thread; +rte_thread_t thread;int i;fprintf (stdout,"Ctrlr Worker Thread start\n" );
@@ -545,10 +545,10 @@ ctrlr_worker(void *arg)exit (0 ); } - thread =pthread_self (); + thread =rte_thread_self ();CPU_ZERO (&cpuset);CPU_SET (0 , &cpuset); -pthread_setaffinity_np (thread,sizeof (cpu_set_t), &cpuset); +rte_thread_set_affinity_by_id (thread, &cpuset);for (i =0 ; i <NUM_OF_BLK_QUEUES ; i++)submit_inflight_vq (&ctrlr->queues[i]);
@@ -604,7 +604,7 @@ new_device(int vid)struct vhost_blk_queue *vq;char path[PATH_MAX ];uint64_t features, protocol_features; -pthread_t tid; +rte_thread_t tid;int i, ret;bool packed_ring, inflight_shmfd;
@@ -693,7 +693,7 @@ new_device(int vid)/* device has been started */ ctrlr->started =1 ; -pthread_detach (tid); +rte_thread_detach (tid);return 0 ; }
lib/eal/common/eal_common_options.c +2 -4
@@ -1872,8 +1872,7 @@ eal_auto_detect_cores(struct rte_config *cfg)unsigned int removed =0 ;rte_cpuset_t affinity_set; -if (pthread_getaffinity_np (pthread_self (),sizeof (rte_cpuset_t), - &affinity_set)) +if (rte_thread_get_affinity_by_id (rte_thread_self (), &affinity_set))CPU_ZERO (&affinity_set);for (lcore_id =0 ; lcore_id <RTE_MAX_LCORE ; lcore_id++) {
@@ -1901,8 +1900,7 @@ compute_ctrl_threads_cpuset(struct internal_config *internal_cfg) }RTE_CPU_NOT (cpuset, cpuset); -if (pthread_getaffinity_np (pthread_self (),sizeof (rte_cpuset_t), - &default_set)) +if (rte_thread_get_affinity_by_id (rte_thread_self (), &default_set))CPU_ZERO (&default_set);RTE_CPU_AND (cpuset, cpuset, &default_set);
lib/eal/common/eal_common_proc.c +24 -24
162 lines not on this page · raw message
lib/eal/common/eal_common_thread.c +25 -17
114 lines not on this page · raw message
lib/eal/common/eal_common_trace.c +1 -1
@@ -359,7 +359,7 @@ __rte_trace_mem_per_thread_alloc(void)/* Store the thread name */ char *name = header->stream_header.thread_name;memset (name,0 , __RTE_TRACE_EMIT_STRING_LEN_MAX); -rte_thread_getname (pthread_self (), name, +rte_thread_getname (rte_thread_self (), name, __RTE_TRACE_EMIT_STRING_LEN_MAX); trace->lcore_meta[count].mem = header;
lib/eal/common/eal_private.h +1 -1
@@ -19,7 +19,7 @@* Structure storing internal configuration (per-lcore) */ struct lcore_config { -pthread_t thread_id;/**< pthread identifier */ +rte_thread_t thread_id;/**< pthread identifier */ int pipe_main2worker[2 ];/**< communication pipe with main */ int pipe_worker2main[2 ];/**< communication pipe with main */
lib/eal/common/eal_thread.h +6 -0
@@ -58,4 +58,10 @@ eal_thread_dump_affinity(rte_cpuset_t *cpuset, char *str, unsigned int size);int eal_thread_dump_current_affinity (char *str,unsigned int size); +/** +* Set the initial thread priority in the internal configuration +* to the default value of RTE_THREAD_PRIORITY_NORMAL. +*/ +void rte_thread_priority_init (void ); +#endif /* EAL_THREAD_H */
lib/eal/common/malloc_mp.c +16 -16
@@ -75,10 +75,10 @@ struct mp_request {TAILQ_HEAD (mp_request_list, mp_request);static struct {struct mp_request_list list; -pthread_mutex_t lock; +rte_thread_mutex_t lock; } mp_request_list = { .list =TAILQ_HEAD_INITIALIZER (mp_request_list.list), - .lock =PTHREAD_MUTEX_INITIALIZER + .lock =RTE_THREAD_MUTEX_INITIALIZER };/**
@@ -301,7 +301,7 @@ handle_request(const struct rte_mp_msg *msg, const void *peer __rte_unused)int ret;/* lock access to request */ -pthread_mutex_lock (&mp_request_list.lock); +rte_thread_mutex_lock (&mp_request_list.lock);/* make sure it's not a dupe */ entry =find_request_by_id (m->id);
@@ -387,10 +387,10 @@ handle_request(const struct rte_mp_msg *msg, const void *peer __rte_unused)TAILQ_INSERT_TAIL (&mp_request_list.list, entry, next); } -pthread_mutex_unlock (&mp_request_list.lock); +rte_thread_mutex_unlock (&mp_request_list.lock);return 0 ; fail: -pthread_mutex_unlock (&mp_request_list.lock); +rte_thread_mutex_unlock (&mp_request_list.lock);free (entry);return -1 ; }
@@ -409,7 +409,7 @@ handle_sync_response(const struct rte_mp_msg *request,int i;/* lock the request */ -pthread_mutex_lock (&mp_request_list.lock); +rte_thread_mutex_lock (&mp_request_list.lock); entry =find_request_by_id (mpreq->id);if (entry ==NULL ) {
@@ -539,10 +539,10 @@ handle_sync_response(const struct rte_mp_msg *request, goto fail; } -pthread_mutex_unlock (&mp_request_list.lock); +rte_thread_mutex_unlock (&mp_request_list.lock);return 0 ; fail: -pthread_mutex_unlock (&mp_request_list.lock); +rte_thread_mutex_unlock (&mp_request_list.lock);return -1 ; }
@@ -557,7 +557,7 @@ handle_rollback_response(const struct rte_mp_msg *request,struct mp_request *entry;/* lock the request */ -pthread_mutex_lock (&mp_request_list.lock); +rte_thread_mutex_lock (&mp_request_list.lock);memset (&msg,0 ,sizeof (msg));
@@ -588,10 +588,10 @@ handle_rollback_response(const struct rte_mp_msg *request,free (entry->alloc_state.ms);free (entry); -pthread_mutex_unlock (&mp_request_list.lock); +rte_thread_mutex_unlock (&mp_request_list.lock);return 0 ; fail: -pthread_mutex_unlock (&mp_request_list.lock); +rte_thread_mutex_unlock (&mp_request_list.lock);return -1 ; }
@@ -603,7 +603,7 @@ handle_response(const struct rte_mp_msg *msg, const void *peer __rte_unused) (const struct malloc_mp_req *)msg->param;struct mp_request *entry; -pthread_mutex_lock (&mp_request_list.lock); +rte_thread_mutex_lock (&mp_request_list.lock); entry =find_request_by_id (m->id);if (entry !=NULL ) {
@@ -616,7 +616,7 @@ handle_response(const struct rte_mp_msg *msg, const void *peer __rte_unused)pthread_cond_signal (&entry->cond); } -pthread_mutex_unlock (&mp_request_list.lock); +rte_thread_mutex_unlock (&mp_request_list.lock);return 0 ; }
@@ -706,7 +706,7 @@ request_to_primary(struct malloc_mp_req *user_req)memset (&msg,0 ,sizeof (msg));memset (&ts,0 ,sizeof (ts)); -pthread_mutex_lock (&mp_request_list.lock); +rte_thread_mutex_lock (&mp_request_list.lock); entry =malloc (sizeof (*entry));if (entry ==NULL ) {
@@ -767,10 +767,10 @@ request_to_primary(struct malloc_mp_req *user_req)TAILQ_REMOVE (&mp_request_list.list, entry, next);free (entry); -pthread_mutex_unlock (&mp_request_list.lock); +rte_thread_mutex_unlock (&mp_request_list.lock);return ret; fail: -pthread_mutex_unlock (&mp_request_list.lock); +rte_thread_mutex_unlock (&mp_request_list.lock);free (entry);return -1 ; }
lib/eal/common/meson.build +1 -0
@@ -80,6 +80,7 @@ sources += files( 'rte_random.c', 'rte_reciprocal.c', 'rte_service.c', + 'rte_thread.c', 'rte_version.c', )
lib/eal/freebsd/eal.c +32 -10
87 lines not on this page · raw message
lib/eal/freebsd/eal_alarm.c +6 -6
@@ -37,7 +37,7 @@ struct alarm_entry {rte_eal_alarm_callback cb_fn;void *cb_arg;volatile uint8_t executing; -volatile pthread_t executing_id; +volatile rte_thread_t executing_id; }; static LIST_HEAD(alarm_list, alarm_entry) alarm_list = LIST_HEAD_INITIALIZER();
@@ -156,7 +156,7 @@ eal_alarm_callback(void *arg __rte_unused)while (ap !=NULL &×pec_cmp (&now, &ap->time) >=0 ) { ap->executing =1 ; - ap->executing_id =pthread_self (); + ap->executing_id =rte_thread_self ();rte_spinlock_unlock (&alarm_list_lk); ap->cb_fn (ap->cb_arg);
@@ -263,8 +263,8 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)* finish. Otherwise we are trying to cancel * ourselves - mark it by EINPROGRESS. */ -if (pthread_equal (ap->executing_id, -pthread_self ()) ==0 ) +if (rte_thread_equal (ap->executing_id, +rte_thread_self ()) ==0 ) executing++;else err =EINPROGRESS ;
@@ -285,8 +285,8 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)free (ap); count++; ap = ap_prev; - }else if (pthread_equal (ap->executing_id, -pthread_self ()) ==0 ) { + }else if (rte_thread_equal (ap->executing_id, +rte_thread_self ()) ==0 ) { executing++; }else { err =EINPROGRESS ;
lib/eal/freebsd/eal_interrupts.c +2 -2
@@ -52,7 +52,7 @@ static rte_spinlock_t intr_lock = RTE_SPINLOCK_INITIALIZER;static struct rte_intr_source_list intr_sources;/* interrupt handling thread */ -static pthread_t intr_thread; +static rte_thread_t intr_thread;static volatile int kq =-1 ;
@@ -737,5 +737,5 @@ rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle)int rte_thread_is_intr (void ) { -return pthread_equal (intr_thread,pthread_self ()); +return rte_thread_equal (intr_thread,rte_thread_self ()); }
lib/eal/freebsd/eal_thread.c +7 -7
@@ -73,15 +73,15 @@ eal_thread_loop(__rte_unused void *arg)char c;int n, ret;unsigned lcore_id; -pthread_t thread_id; +rte_thread_t thread_id;int m2w, w2m;char cpuset[RTE_CPU_AFFINITY_STR_LEN ]; - thread_id =pthread_self (); + thread_id =rte_thread_self ();/* retrieve our lcore_id from the configuration structure */ RTE_LCORE_FOREACH_WORKER (lcore_id) { -if (thread_id == lcore_config[lcore_id].thread_id) +if (rte_thread_equal (thread_id, lcore_config[lcore_id].thread_id))break ; }if (lcore_id ==RTE_MAX_LCORE )
@@ -93,8 +93,8 @@ eal_thread_loop(__rte_unused void *arg)__rte_thread_init (lcore_id, &lcore_config[lcore_id].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 ?"" :"..." ); +RTE_LOG (DEBUG ,EAL ,"lcore %u is ready (cpuset=[%s%s])\n" , + lcore_id, cpuset, ret ==0 ?"" :"..." );rte_eal_trace_thread_lcore_ready (lcore_id, cpuset);
@@ -143,14 +143,14 @@ int rte_sys_gettid(void)return (int )lwpid; } -int rte_thread_setname (pthread_t id,const char *name) +int rte_thread_setname (rte_thread_t id,const char *name) {/* this BSD function returns no error */ pthread_set_name_np (id, name);return 0 ; } -int rte_thread_getname (pthread_t id,char *name,size_t len) +int rte_thread_getname (rte_thread_t id,char *name,size_t len) {RTE_SET_USED (id);RTE_SET_USED (name);
lib/eal/include/meson.build +1 -0
@@ -40,6 +40,7 @@ headers += files( 'rte_string_fns.h', 'rte_tailq.h', 'rte_thread.h', + 'rte_thread_types.h', 'rte_time.h', 'rte_trace.h', 'rte_trace_point.h',
lib/eal/include/rte_lcore.h +4 -4
@@ -374,7 +374,7 @@ rte_lcore_dump(FILE *f);* @return * On success, return 0; otherwise return a negative value. */ -int rte_thread_setname (pthread_t id,const char *name); +int rte_thread_setname (rte_thread_t id,const char *name);/** * Get thread name.
@@ -391,7 +391,7 @@ int rte_thread_setname(pthread_t id, const char *name);* On success, return 0; otherwise return a negative value. */ __rte_experimental -int rte_thread_getname(pthread_t id, char *name, size_t len); +int rte_thread_getname(rte_thread_t id, char *name, size_t len);/** * Register current non-EAL thread as a lcore.
@@ -440,8 +440,8 @@ rte_thread_unregister(void);* corresponding to the error number. */ int -rte_ctrl_thread_create (pthread_t *thread,const char *name, -const pthread_attr_t *attr, +rte_ctrl_thread_create (rte_thread_t *thread,const char *name, +const rte_thread_attr_t *attr,void *(*start_routine)(void *),void *arg);#ifdef __cplusplus
lib/eal/include/rte_per_lcore.h +0 -2
@@ -22,8 +22,6 @@extern "C" {#endif -#include <pthread.h> -/** * Macro to define a per lcore variable "var" of type "type", don't * use keywords like "static" or "volatile" in type, just prefix the
lib/eal/linux/eal.c +34 -12
82 lines not on this page · raw message
lib/eal/unix/rte_thread.c deleted +0 -92
92 lines not on this page · raw message
lib/eal/windows/eal.c +42 -1
43 lines not on this page · raw message
lib/eal/windows/include/pthread.h deleted +0 -192
192 lines not on this page · raw message
lib/eventdev/rte_event_eth_rx_adapter.c +3 -3
Lines of this file are not shown. View the raw message.
lib/vhost/socket.c +66 -64
130 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.31.0.vfs.0.1
Part of the diff is not shown here. View the raw message.
Re: [dpdk-dev] [PATCH v9 10/10] Enable the new EAL thread API
Quoted 7 lines · Narcisa Ana Maria Vasile
From: Narcisa Vasile <[email protected]>
Rename pthread_* occurrences with the new rte_thread_* API. Enable the new API in the build system.
Signed-off-by Narcisa Vasile <[email protected]>---
I'll send v10.
Can someone please help with an example on how to check for ABI breaks? Thank you!
I've run:
DPDK_ABI_REF_VERSION=v21.05 DPDK_ABI_REF_DIR=~/ref ./devtools/test-meson-builds.sh which doesn't give any warnings about the ABI break.
I've cloned the dpdk repo in "~/ref" and checkout v21.05 tag. "~/dpdk" is on a local branch that contains my changes:
"./devtools/check-abi.sh ~/ref ~/dpdk" - didn't work.
I've then used gen-abi.sh (with a small change to skip the *.symbols, since abidw can't handle them) to generate the *.dump files. Reruning check-abi.sh worked this time, but didn't show the ABI break. This is the entire output:
------
WARNING: could not identify an include directory for /home/administrator/ref, expect false positives...
WARNING: could not identify an include directory for /home/administrator/dpdk, expect false positives... Functions changes summary: 0 Removed, 0 Changed, 0 Added function
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
Variable symbols changes summary: 0 Removed, 0 Added variable symbol not referenced by debug info
------
I've also tried to compare each file:
abidiff --suppr ./devtools/libabigail.abignore --no-added-syms ~/ref/dump/librte_eal.dump ~/dpdk/dump/librte_eal.dump
Re: [dpdk-dev] [PATCH v9 10/10] Enable the new EAL thread API
Quoted 10 lines · Narcisa Ana Maria Vasile
Quoted 7 lines · Narcisa Ana Maria Vasile
From: Narcisa Vasile <[email protected]>
Rename pthread_* occurrences with the new rte_thread_* API. Enable the new API in the build system.
Signed-off-by Narcisa Vasile <[email protected]>---
Quoted 6 lines
I'll send v10.
Can someone please help with an example on how to check for ABI breaks? Thank you!I've run:
DPDK_ABI_REF_VERSION=v21.05 DPDK_ABI_REF_DIR=~/ref./devtools/test-meson-builds.shwhich doesn't give any warnings about the ABI break.
This should work the way you tried if you have working toolchains and libabigail installed.
Something is off in your env.
Side note: ovsrobot is out those days (we have some trouble in one of RH labs and it happens ovsrobot is hosted there), but you could try with a github repo of yours + GHA, and the ABI failure should be caught too.
I just tried on my rhel7 (gcc 4.8.5 + libabigail 1.8.2) with your series applied.
$ DPDK_ABI_REF_VERSION=v21.05 DPDK_ABI_REF_DIR=~/git/pub/dpdk.org/reference ./devtools/test-meson-builds.sh ... Error: ABI issue reported for 'abidiff --suppr /home/dmarchan/git/pub/dpdk.org/devtools/../devtools/libabigail.abignore --no-added-syms --headers-dir1 /home/dmarchan/git/pub/dpdk.org/reference/v21.05/build-gcc-shared/usr/local/include --headers-dir2 /home/dmarchan/git/pub/dpdk.org/build-gcc-shared/install/usr/local/include /home/dmarchan/git/pub/dpdk.org/reference/v21.05/build-gcc-shared/dump/librte_eal.dump /home/dmarchan/git/pub/dpdk.org/build-gcc-shared/install/dump/librte_eal.dump' ABIDIFF_ABI_CHANGE, this change requires a review (abidiff flagged this as a potential issue).
$ abidiff --suppr /home/dmarchan/git/pub/dpdk.org/devtools/../devtools/libabigail.abignore --no-added-syms --headers-dir1 /home/dmarchan/git/pub/dpdk.org/reference/v21.05/build-gcc-shared/usr/local/include --headers-dir2 /home/dmarchan/git/pub/dpdk.org/build-gcc-shared/install/usr/local/include /home/dmarchan/git/pub/dpdk.org/reference/v21.05/build-gcc-shared/dump/librte_eal.dump /home/dmarchan/git/pub/dpdk.org/build-gcc-shared/install/dump/librte_eal.dump Functions changes summary: 0 Removed, 2 Changed (1 filtered out), 0 Added (20 filtered out) functions Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
2 functions with some indirect sub-type change:
[C] 'function int rte_ctrl_thread_create(pthread_t*, const char*,
const pthread_attr_t*, void* (void*)*, void*)' at rte_lcore.h:443:1 has some indirect sub-type changes:
parameter 1 of type 'pthread_t*' changed:
in pointed to type 'typedef pthread_t' at rte_thread.h:42:1:
typedef name changed from pthread_t to rte_thread_t at rte_thread.h:42:1 underlying type 'unsigned long int' changed:
entity changed from 'unsigned long int' to 'structrte_thread_tag' at rte_thread.h:40:1
type size hasn't changed
parameter 3 of type 'const pthread_attr_t*' changed:
in pointed to type 'const pthread_attr_t':
'const pthread_attr_t' changed to 'const rte_thread_attr_t'
[C] 'function int rte_thread_setname(pthread_t, const char*)' at
rte_lcore.h:377:1 has some indirect sub-type changes:
parameter 1 of type 'typedef pthread_t' changed:
typedef name changed from pthread_t to rte_thread_t at rte_thread.h:42:1 underlying type 'unsigned long int' changed:
entity changed from 'unsigned long int' to 'structrte_thread_tag' at rte_thread.h:40:1
type size hasn't changed
Can you check that in your env build-gcc-shared/ and the build directory for references are configured with debug symbols? You should see:
$ meson configure build-gcc-shared | awk '$1=="buildtype" {print $2}'
debugoptimized
$ meson configure reference/v21.05/build | awk '$1=="buildtype" {print $2}'
debugoptimizedQuoted 8 lines
I've cloned the dpdk repo in "~/ref" and checkout v21.05 tag. "~/dpdk" is on a local branch that contains my changes:
"
./devtools/check-abi.sh~/ref ~/dpdk" - didn't work.I've then used
gen-abi.sh(with a small change to skip the *.symbols, since abidw can't handle them) to generate the *.dump files. Reruningcheck-abi.sh
gen-abi.sh is an internal script that works for an installed dpdk, not a build directory.
$ ./devtools/gen-abi.sh Usage: ./devtools/gen-abi.sh installdir
Quoted 5 lines
worked this time, but didn't show the ABI break. This is the entire output:
------
WARNING: could not identify an include directory for/home/administrator/ref, expect false positives...
WARNING: could not identify an include directory for/home/administrator/dpdk, expect false positives...
check-abi.sh tries to find an include/ directory to filter changes on private structures.
But there are multiple include/ dirs in a build directory, so the script gives up on trying to filter and logs a warning. This is not clearly written but, like gen-abi.sh, check-abi.sh works on an installed directory.
Quoted 8 lines
Functions changes summary: 0 Removed, 0 Changed, 0 Added function
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
Variable symbols changes summary: 0 Removed, 0 Added variable symbol not referenced by debug info
------I've also tried to compare each file:
abidiff --suppr ./devtools/libabigail.abignore --no-added-syms ~/ref/dump/librte_eal.dump ~/dpdk/dump/librte_eal.dump
Without debug info, libabigail won't catch/report much but symbol removals, or basic changes in function signatures.
Signature · 1 line
David Marchand
Re: [dpdk-dev] [PATCH v9 10/10] Enable the new EAL thread API
Quoted 84 lines · David Marchand
Quoted 10 lines · Narcisa Ana Maria Vasile
Quoted 7 lines · Narcisa Ana Maria Vasile
From: Narcisa Vasile <[email protected]>
Rename pthread_* occurrences with the new rte_thread_* API. Enable the new API in the build system.
Signed-off-by Narcisa Vasile <[email protected]>---
Quoted 6 lines
I'll send v10.
Can someone please help with an example on how to check for ABI breaks? Thank you!I've run:
DPDK_ABI_REF_VERSION=v21.05 DPDK_ABI_REF_DIR=~/ref./devtools/test-meson-builds.shwhich doesn't give any warnings about the ABI break.This should work the way you tried if you have working toolchains and libabigail installed.
Something is off in your env.Side note: ovsrobot is out those days (we have some trouble in one of RH labs and it happens ovsrobot is hosted there), but you could try with a github repo of yours + GHA, and the ABI failure should be caught too.
I just tried on my rhel7 (gcc 4.8.5 + libabigail 1.8.2) with your series applied.
$ DPDK_ABI_REF_VERSION=v21.05 DPDK_ABI_REF_DIR=~/git/pub/dpdk.org/reference ./devtools/test-meson-builds.sh ... Error: ABI issue reported for 'abidiff --suppr /home/dmarchan/git/pub/dpdk.org/devtools/../devtools/libabigail.abignore --no-added-syms --headers-dir1 /home/dmarchan/git/pub/dpdk.org/reference/v21.05/build-gcc-shared/usr/local/include --headers-dir2 /home/dmarchan/git/pub/dpdk.org/build-gcc-shared/install/usr/local/include /home/dmarchan/git/pub/dpdk.org/reference/v21.05/build-gcc-shared/dump/librte_eal.dump /home/dmarchan/git/pub/dpdk.org/build-gcc-shared/install/dump/librte_eal.dump' ABIDIFF_ABI_CHANGE, this change requires a review (abidiff flagged this as a potential issue).$ abidiff --suppr /home/dmarchan/git/pub/dpdk.org/devtools/../devtools/libabigail.abignore --no-added-syms --headers-dir1 /home/dmarchan/git/pub/dpdk.org/reference/v21.05/build-gcc-shared/usr/local/include --headers-dir2 /home/dmarchan/git/pub/dpdk.org/build-gcc-shared/install/usr/local/include /home/dmarchan/git/pub/dpdk.org/reference/v21.05/build-gcc-shared/dump/librte_eal.dump /home/dmarchan/git/pub/dpdk.org/build-gcc-shared/install/dump/librte_eal.dump Functions changes summary: 0 Removed, 2 Changed (1 filtered out), 0 Added (20 filtered out) functions Variables changes summary: 0 Removed, 0 Changed, 0 Added variable2 functions with some indirect sub-type change:
[C] 'function int rte_ctrl_thread_create(pthread_t*, const char*,
const pthread_attr_t*, void* (void*)*, void*)' at rte_lcore.h:443:1 has some indirect sub-type changes:
parameter 1 of type 'pthread_t*' changed:
in pointed to type 'typedefpthread_t' at rte_thread.h:42:1:
typedef name changed frompthread_ttorte_thread_tat rte_thread.h:42:1 underlying type 'unsigned long int' changed:
entity changed from 'unsigned long int' to 'structrte_thread_tag' at rte_thread.h:40:1
type size hasn't changed
parameter 3 of type 'const pthread_attr_t*' changed:
in pointed to type 'constpthread_attr_t':
'constpthread_attr_t' changed to 'constrte_thread_attr_t'[C] 'function int
rte_thread_setname(pthread_t, const char*)' at
rte_lcore.h:377:1 has some indirect sub-type changes:
parameter 1 of type 'typedefpthread_t' changed:
typedef name changed frompthread_ttorte_thread_tat rte_thread.h:42:1 underlying type 'unsigned long int' changed:
entity changed from 'unsigned long int' to 'structrte_thread_tag' at rte_thread.h:40:1
type size hasn't changed
Quoted 9 lines
Can you check that in your env build-gcc-shared/ and the build directory for references are configured with debug symbols? You should see:
$ meson configure build-gcc-shared | awk '$1=="buildtype" {print $2}' debugoptimized $ meson configure reference/v21.05/build | awk '$1=="buildtype" {print $2}' debugoptimized
Thank you very much David! There was something wrong with my local reference. Using your commands, I am able to run the tools now.
Quoted 1 line
Re: [dpdk-dev] [PATCH v9 10/10] Enable the new EAL thread API
In reply to Narcisa Ana Maria Vasile2021-06-07 22:50 (UTC-0700), Narcisa Ana Maria Vasile:
Quoted 10 lines · Narcisa Ana Maria Vasile
Quoted 7 lines
From: Narcisa Vasile <[email protected]>
Rename pthread_* occurrences with the new rte_thread_* API. Enable the new API in the build system.
Signed-off-by Narcisa Vasile <[email protected]>---
I'll send v10.
Please also run devtools/checkpatches.sh
and fix numerous warnings across the series. Some patches could be acked already if not this issue.
Re: [dpdk-dev] [PATCH v9 10/10] Enable the new EAL thread API
Quoted 7 lines · Dmitry Kozlyuk
2021-06-07 22:50 (UTC-0700), Narcisa Ana Maria Vasile:
Quoted 6 lines · Narcisa Ana Maria Vasile
Quoted 5 lines
From: Narcisa Vasile <[email protected]>
Rename pthread_* occurrences with the new rte_thread_* API. Enable the new API in the build system.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Narcisa Vasile <[email protected]>---
I'll send v10.
Please also run
devtools/checkpatches.sh
and fix numerous warnings across the series. Some patches could be acked already if not this issue.
Thanks, I've fixed the CS errors.
There will be a few warnings that I can't fix (the negative errors for example).
v10 cover eal: Add EAL API for threading
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
EAL thread API
**Problem Statement**
DPDK currently uses the pthread interface to create and manage threads. Windows does not support the POSIX thread programming model, so it currently relies on a header file that hides the Windows calls under pthread matched interfaces.
Given that EAL should isolate the environment specifics from the applications and libraries and mediate all the communication with the operating systems, a new EAL interface
is needed for thread management.
**Goals**
* Introduce a generic EAL API for threading support that will remove the current Windows pthread.h shim.
* Replace references to pthread_* across the DPDK codebase with the new RTE_THREAD_* API.
* Allow users to choose between using the RTE_THREAD_* API or a 3rd party thread library through a configuration option.
**Design plan**
New API main files:
* rte_thread.h (librte_eal/include)
* rte_thread.c (librte_eal/windows)
* rte_thread.c (librte_eal/common)
**A schematic example of the design**
--------------------------------------------------lib/librte_eal/include/rte_thread.h
int rte_thread_create();
lib/librte_eal/common/rte_thread.c
int rte_thread_create()
{
return pthread_create();
}lib/librte_eal/windows/rte_thread.c
int rte_thread_create()
{
return CreateThread();
}-----------------------------------------------------
**Thread attributes**
When or after a thread is created, specific characteristics of the thread can be adjusted. Given that the thread characteristics that are of interest for DPDK applications are affinity and priority, the following structure that represents thread attributes has been defined:
typedef struct
{
enum rte_thread_priority priority;
rte_cpuset_t cpuset;
} rte_thread_attr_t;The *rte_thread_create()* function can optionally receive an rte_thread_attr_t object that will cause the thread to be created with the affinity and priority described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used.
An rte_thread_attr_t object can also be set to the default values by calling *rte_thread_attr_init()*.
*Priority* is represented through an enum that currently advertises two values for priority:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
The enum can be extended to allow for multiple priority levels.rte_thread_set_priority - sets the priority of a threadrte_thread_attr_set_priority - updates an rte_thread_attr_t object
with a new value for priority
The user can choose thread priority through an EAL parameter, when starting an application. If EAL parameter is not used, the per-platform default value for thread priority is used. Otherwise administrator has an option to set one of available options:
--thread-prio normal
--thread-prio realtime
Example:
./dpdk-l2fwd -l 0-3 -n 4 –thread-prio normal -- -q 8 -p ffff
*Affinity* is described by the already known “rte_cpuset_t” type. rte_thread_attr_set/get_affinity - sets/gets the affinity field in a
rte_thread_attr_t object
rte_thread_set/get_affinity – sets/gets the affinity of a thread
**Errors**
A translation function that maps Windows error codes to errno-style error codes is provided.
**Future work**
The long term plan is for EAL to provide full threading support:
* Add support for conditional variables
* Add support for pthread_mutex_trylock
* Additional functionality offered by pthread_*
(such as pthread_setname_np, etc.)
v10:
- Remove patch no. 10. It will be broken down in subpatches and sent as a different patchset that depends on this one. This is done due to the ABI breaks that would be caused by patch 10.
- Replace unix/rte_thread.c with common/rte_thread.c
- Remove initializations that may prevent compiler from issuing useful warnings.
- Remove rte_thread_types.h and rte_windows_thread_types.h
- Remove unneeded priority macros (EAL_THREAD_PRIORITY*)
- Remove functions that retrieves thread handle from process handle
- Remove rte_thread_cancel() until same behavior is obtained on all platforms.
- Fix rte_thread_detach() function description,
return value and remove empty line.
- Reimplement mutex functions. Add compatible representation for mutex identifier. Add macro to replace static mutex initialization instances.
- Fix commit messages (lines too long, remove unicode symbols)
v9:
- Sign patches
v8:
- Rebase
- Add rte_thread_detach() API
- Set default priority, when user did not specify a value
v7:
Based on DmitryK's review:
- Change thread id representation
- Change mutex id representation
- Implement static mutex inititalizer for Windows
- Change barrier identifier representation
- Improve commit messages
- Add missing doxygen comments
- Split error translation function
- Improve name for affinity function
- Remove cpuset_size parameter
- Fix eal_create_cpu_map function
- Map EAL priority values to OS specific values
- Add thread wrapper for start routine
- Do not export rte_thread_cancel() on Windows
- Cleanup, fix comments, fix typos.
v6:
- improve error-translation function
- call the error translation function in rte_thread_value_get()
v5:
- update cover letter with more details on the priority argument
v4:
- fix function description
- rebase
v3:
- rebase
v2:
- revert changes that break ABI
- break up changes into smaller patches
- fix coding style issues
- fix issues with errors
- fix parameter type in examples/kni.c
Narcisa Vasile (9):
eal: add basic threading functions
eal: add thread attributes
eal/windows: translate Windows errors to errno-style errors
eal: implement functions for thread affinity management
eal: implement thread priority management functions
eal: add thread lifetime management
eal: implement functions for mutex management
eal: implement functions for thread barrier management
eal: add EAL argument for setting thread priority
lib/eal/common/eal_common_options.c | 28 +- lib/eal/common/eal_internal_cfg.h | 2 + lib/eal/common/eal_options.h | 2 + lib/eal/common/meson.build | 1 + lib/eal/common/rte_thread.c | 445 +++++++++++++++++++++ lib/eal/include/rte_thread.h | 406 ++++++++++++++++++- lib/eal/unix/meson.build | 1 - lib/eal/unix/rte_thread.c | 92 ----- lib/eal/version.map | 20 + lib/eal/windows/eal_lcore.c | 176 ++++++--- lib/eal/windows/eal_windows.h | 10 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 588 ++++++++++++++++++++++++++-- 13 files changed, 1599 insertions(+), 174 deletions(-) create mode 100644 lib/eal/common/rte_thread.c delete mode 100644 lib/eal/unix/rte_thread.c
Signature · 1 line
2.31.0.vfs.0.1
PATCH v10 1/9 eal: add basic threading functions
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
---
lib/eal/common/meson.build | 1 +
lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
lib/eal/include/rte_thread.h | 48 +++++++++++++++++-----
lib/eal/unix/meson.build | 1 -
lib/eal/version.map | 3 ++
lib/eal/windows/rte_thread.c | 17 ++++++++
6 files changed, 95 insertions(+), 32 deletions(-)
rename lib/eal/{unix => common}/rte_thread.c (66%)lib/eal/common/meson.build +1 -0
@@ -80,6 +80,7 @@ sources += files( 'rte_random.c', 'rte_reciprocal.c', 'rte_service.c', + 'rte_thread.c', 'rte_version.c', )
lib/eal/common/rte_thread.c renamed from lib/eal/unix/rte_thread.c +35 -22
107 lines not on this page · raw message
lib/eal/include/rte_thread.h +39 -9
83 lines not on this page · raw message
lib/eal/unix/meson.build +0 -1
@@ -5,5 +5,4 @@ sources += files( 'eal_file.c', 'eal_unix_memory.c', 'eal_unix_timer.c', - 'rte_thread.c', )
lib/eal/version.map +3 -0
@@ -423,6 +423,9 @@ EXPERIMENTAL { rte_version_release; # WINDOWS_NO_EXPORT rte_version_suffix; # WINDOWS_NO_EXPORT rte_version_year; # WINDOWS_NO_EXPORT + + rte_thread_self; + rte_thread_equal; }; INTERNAL {
lib/eal/windows/rte_thread.c +17 -0
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright 2021 Mellanox Technologies, Ltd +* Copyright(c) 2021 Microsoft Corporation */ #include <rte_common.h>
@@ -11,6 +12,22 @@ struct eal_tls_key {DWORD thread_index; }; +rte_thread_t +rte_thread_self (void ) +{ +rte_thread_t thread_id; + + thread_id.opaque_id =GetCurrentThreadId (); + +return thread_id; +} + +int +rte_thread_equal (rte_thread_t t1,rte_thread_t t2) +{ +return t1.opaque_id == t2.opaque_id; +} +int rte_thread_key_create (rte_thread_key *key, __rte_unused void (*destructor)(void *))
Signature · 1 line
2.31.0.vfs.0.1
PATCH v10 2/9 eal: add thread attributes
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.
Priority is represented through an enum that allows for two levels:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
Affinity is described by the rte_cpuset_t type.
An rte_thread_attr_t object can be set to the default values by calling rte_thread_attr_init().
--- lib/eal/common/rte_thread.c | 46 ++++++++++++++++++ lib/eal/include/rte_thread.h | 93 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 44 +++++++++++++++++ 4 files changed, 187 insertions(+)
lib/eal/common/rte_thread.c +46 -0
@@ -9,6 +9,7 @@#include <string.h> #include <rte_common.h> +#include <rte_debug.h> #include <rte_errno.h> #include <rte_log.h> #include <rte_thread.h>
@@ -33,6 +34,51 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_attr_init (rte_thread_attr_t *attr) +{ +RTE_VERIFY (attr !=NULL ); + +CPU_ZERO (&attr->cpuset); + attr->priority =RTE_THREAD_PRIORITY_NORMAL ; + +return 0 ; +} + +int +rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + thread_attr->cpuset = *cpuset; + +return 0 ; +} + +int +rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + *cpuset = thread_attr->cpuset; + +return 0 ; +} + +int +rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, +enum rte_thread_priority priority) +{ +RTE_VERIFY (thread_attr !=NULL ); + + thread_attr->priority = priority; +return 0 ; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +93 -0
105 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -426,6 +426,10 @@ EXPERIMENTAL { rte_thread_self; rte_thread_equal; + rte_thread_attr_init; + rte_thread_attr_get_affinity; + rte_thread_attr_set_affinity; + rte_thread_attr_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v10 3/9 eal/windows: translate Windows errors to errno-style errors
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function to translate Windows error codes to errno-style error codes. The possible return values are chosen so that we have as much semantical compatibility between platforms as possible.
--- lib/eal/common/rte_thread.c | 6 +-- lib/eal/include/rte_thread.h | 5 +- lib/eal/windows/rte_thread.c | 95 +++++++++++++++++++++++++++--------- 3 files changed, 76 insertions(+), 30 deletions(-)
lib/eal/common/rte_thread.c +3 -3
@@ -47,7 +47,7 @@ rte_thread_attr_init(rte_thread_attr_t *attr)int rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -59,7 +59,7 @@ rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -71,7 +71,7 @@ rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, -enum rte_thread_priority priority) +enum rte_thread_priority priority) {RTE_VERIFY (thread_attr !=NULL );
lib/eal/include/rte_thread.h +2 -3
@@ -235,9 +235,8 @@ int rte_thread_value_set(rte_thread_key key, const void *value);* * @return * On success, value data pointer (can also be NULL). -* On failure, NULL and an error number is set in rte_errno. -* rte_errno can be: EINVAL - Invalid parameter passed. -* ENOEXEC - Specific OS error. +* On failure, NULL and a positive error number is set in rte_errno. +* */ __rte_experimental void *rte_thread_value_get(rte_thread_key key);
lib/eal/windows/rte_thread.c +71 -24
165 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v10 4/9 eal: implement functions for thread affinity management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement functions for getting/setting thread affinity. Threads can be pinned to specific cores by setting their affinity attribute.
--- lib/eal/common/rte_thread.c | 16 ++++ lib/eal/include/rte_thread.h | 36 +++++++ lib/eal/version.map | 2 + lib/eal/windows/eal_lcore.c | 176 +++++++++++++++++++++++++--------- lib/eal/windows/eal_windows.h | 10 ++ lib/eal/windows/rte_thread.c | 125 +++++++++++++++++++++++- 6 files changed, 319 insertions(+), 46 deletions(-)
lib/eal/common/rte_thread.c +16 -0
@@ -34,6 +34,22 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_set_affinity_by_id (rte_thread_t thread_id, +const rte_cpuset_t *cpuset) +{ +return pthread_setaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} + +int +rte_thread_get_affinity_by_id (rte_thread_t thread_id, +rte_cpuset_t *cpuset) +{ +return pthread_getaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +36 -0
@@ -87,6 +87,42 @@ int rte_thread_equal(rte_thread_t t1, rte_thread_t t2);#ifdef RTE_HAS_CPUSET +/** +* Set the affinity of thread 'thread_id' to the cpu set +* specified by 'cpuset'. +* +* @param thread_id +* Id of the thread for which to set the affinity. +* +* @param cpuset +* Pointer to CPU affinity to set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_affinity_by_id(rte_thread_t thread_id, +const rte_cpuset_t *cpuset); + +/** +* Get the affinity of thread 'thread_id' and store it +* in 'cpuset'. +* +* @param thread_id +* Id of the thread for which to get the affinity. +* +* @param cpuset +* Pointer for storing the affinity value. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_get_affinity_by_id(rte_thread_t thread_id, +rte_cpuset_t *cpuset); +/** * Initialize the attributes of a thread. * These attributes can be passed to the rte_thread_create() function
lib/eal/version.map +2 -0
@@ -430,6 +430,8 @@ EXPERIMENTAL { rte_thread_attr_get_affinity; rte_thread_attr_set_affinity; rte_thread_attr_set_priority; + rte_thread_get_affinity_by_id; + rte_thread_set_affinity_by_id; }; INTERNAL {
lib/eal/windows/eal_lcore.c +131 -45
231 lines not on this page · raw message
lib/eal/windows/eal_windows.h +10 -0
@@ -55,6 +55,16 @@ int eal_thread_create(pthread_t *thread);*/ unsigned int eal_socket_numa_node (unsigned int socket_id); +/** +* Get pointer to the group affinity for the cpu. +* +* @param cpu_index +* Index of the cpu, as it comes from rte_cpuset_t. +* @return +* Pointer to the group affinity for the cpu. +*/ +PGROUP_AFFINITY eal_get_cpu_affinity (size_t cpu_index); +/** * Schedule code for execution in the interrupt thread. *
lib/eal/windows/rte_thread.c +124 -1
137 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v10 5/9 eal: implement thread priority management functions
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function for setting the priority for a thread. Priorities on multiple platforms are similarly determined by a priority value and a priority class/policy.
On Linux, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* policy SCHED_OTHER
* priority value: (sched_get_priority_min(SCHED_OTHER) +
sched_get_priority_max(SCHED_OTHER))/2;
RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* policy SCHED_RR
* priority value: sched_get_priority_max(SCHED_RR);
On Windows, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* class NORMAL_PRIORITY_CLASS
* priority THREAD_PRIORITY_NORMAL RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* class REALTIME_PRIORITY_CLASS
* priority THREAD_PRIORITY_TIME_CRITICAL
--- lib/eal/common/rte_thread.c | 49 ++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 17 ++++++++++ lib/eal/version.map | 1 + lib/eal/windows/rte_thread.c | 66 ++++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+)
lib/eal/common/rte_thread.c +49 -0
@@ -50,6 +50,55 @@ rte_thread_get_affinity_by_id(rte_thread_t thread_id, sizeof(*cpuset), cpuset); } +static int +thread_map_priority_to_os_value (enum rte_thread_priority eal_pri, +int *os_pri,int *pol) +{ +/* Clear the output parameters */ + *os_pri =sched_get_priority_min (SCHED_OTHER ) -1 ; + *pol =-1 ; + +switch (eal_pri) { +case RTE_THREAD_PRIORITY_NORMAL : + *pol =SCHED_OTHER ; + +/* +* Choose the middle of the range to represent +* the priority 'normal'. +* On Linux, this should be 0, since both +* sched_get_priority_min/_max return 0 for SCHED_OTHER. +*/ + *os_pri = (sched_get_priority_min (SCHED_OTHER ) + +sched_get_priority_max (SCHED_OTHER ))/2 ; +break ; +case RTE_THREAD_PRIORITY_REALTIME_CRITICAL : + *pol =SCHED_RR ; + *os_pri =sched_get_priority_max (SCHED_RR ); +break ; +default : +RTE_LOG (DEBUG ,EAL ,"The requested priority value is invalid.\n" ); +return EINVAL ; + } +return 0 ; +} + +int +rte_thread_set_priority (rte_thread_t thread_id, +enum rte_thread_priority priority) +{ +int ret; +int policy; +struct sched_param param; + + ret =thread_map_priority_to_os_value (priority, ¶m.sched_priority, + &policy); +if (ret !=0 ) +return ret; + +return pthread_setschedparam ((pthread_t )thread_id.opaque_id, + policy, ¶m); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +17 -0
@@ -215,6 +215,23 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp);#endif /* RTE_HAS_CPUSET */ +/** +* Set the priority of a thread. +* +* @param thread_id +* Id of the thread for which to set priority. +* +* @param priority +* Priority value to be set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_priority(rte_thread_t thread_id, +enum rte_thread_priority priority); +/** * Create a TLS data key visible to all threads in the process. * the created key is later used to get/set a value.
lib/eal/version.map +1 -0
@@ -432,6 +432,7 @@ EXPERIMENTAL { rte_thread_attr_set_priority; rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; + rte_thread_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +66 -0
72 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v10 6/9 eal: add thread lifetime management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for thread creation, joining, detaching.
The *rte_thread_create()* function can optionally receive
an rte_thread_attr_t object that will cause the thread to be created with the affinity and priority described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used.
On Windows, the function executed by a thread when the thread starts is represeneted by a function pointer of type DWORD (*func) (void*). On other platforms, the function pointer is a void* (*func) (void*).
Performing a cast between these two types of function pointers to uniformize the API on all platforms may result in undefined behavior. TO fix this issue, a wrapper that respects the signature required by CreateThread() has been created on Windows.
--- lib/eal/common/rte_thread.c | 107 +++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 55 +++++++++++++ lib/eal/version.map | 3 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 138 ++++++++++++++++++++++++++++++++ 5 files changed, 304 insertions(+), 1 deletion(-)
lib/eal/common/rte_thread.c +107 -0
@@ -144,6 +144,113 @@ rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,return 0 ; } +int +rte_thread_create (rte_thread_t *thread_id, +const rte_thread_attr_t *thread_attr, +rte_thread_func thread_func,void *args) +{ +int ret =0 ; +pthread_attr_t attr; +pthread_attr_t *attrp =NULL ; +struct sched_param param = { + .sched_priority =0 , + }; +int policy =SCHED_OTHER ; + +if (thread_attr !=NULL ) { + ret =pthread_attr_init (&attr); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_init failed\n" ); + goto cleanup; + } + + attrp = &attr; + +if (thread_attr->priority !=RTE_THREAD_PRIORITY_UNDEFINED ) { +/* +* Set the inherit scheduler parameter to explicit, +* otherwise the priority attribute is ignored. +*/ + ret =pthread_attr_setinheritsched (attrp, +PTHREAD_EXPLICIT_SCHED ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setinheritsched failed\n" ); + goto cleanup; + } + + ret =thread_map_priority_to_os_value ( + thread_attr->priority, + ¶m.sched_priority, &policy + ); +if (ret !=0 ) + goto cleanup; + + ret =pthread_attr_setschedpolicy (attrp, policy); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedpolicy failed\n" ); + goto cleanup; + } + + ret =pthread_attr_setschedparam (attrp, ¶m); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedparam failed\n" ); + goto cleanup; + } + } + +if (CPU_COUNT (&thread_attr->cpuset) >0 ) { + ret =pthread_attr_setaffinity_np (attrp, +sizeof (thread_attr->cpuset), + &thread_attr->cpuset); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setaffinity_np failed\n" ); + goto cleanup; + } + } + } + + ret =pthread_create ((pthread_t *)&thread_id->opaque_id, attrp, + thread_func, args); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_create failed\n" ); + goto cleanup; + } + +cleanup: +if (attrp !=NULL ) +pthread_attr_destroy (&attr); + +return ret; +} + +int +rte_thread_join (rte_thread_t thread_id,unsigned long *value_ptr) +{ +int ret =0 ; +void *res =NULL ; +void **pres =NULL ; + +if (value_ptr !=NULL ) + pres = &res; + + ret =pthread_join ((pthread_t )thread_id.opaque_id, pres); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_join failed\n" ); +return ret; + } + +if (pres !=NULL ) + *value_ptr = *(unsigned long *)(*pres); + +return 0 ; +} + +int +rte_thread_detach (rte_thread_t thread_id) +{ +return pthread_detach ((pthread_t )thread_id.opaque_id); +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +55 -0
67 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -433,6 +433,9 @@ EXPERIMENTAL { rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; rte_thread_set_priority; + rte_thread_create; + rte_thread_join; + rte_thread_detach; }; INTERNAL {
lib/eal/windows/include/sched.h +1 -1
@@ -44,7 +44,7 @@ typedef struct _rte_cpuset_s { (1LL << _WHICH_BIT(b))) != 0LL)static inline int -count_cpu (rte_cpuset_t *s) +count_cpu (const rte_cpuset_t *s) {unsigned int _i;int count =0 ;
lib/eal/windows/rte_thread.c +138 -0
150 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v10 7/9 eal: implement functions for mutex management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for mutex init, destroy, lock, unlock.
Add RTE_STATIC_MUTEX macro to replace static initialization of mutexes.
Windows does not have a static initializer. Initialization is only done through InitializeCriticalSection().
The RTE_STATIC_MUTEX calls into the rte_thread_mutex_init() function that performs the actual mutex initialization.
--- lib/eal/common/rte_thread.c | 61 +++++++++++++++++++++++ lib/eal/include/rte_thread.h | 94 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 53 ++++++++++++++++++++ 4 files changed, 212 insertions(+)
lib/eal/common/rte_thread.c +61 -0
@@ -251,6 +251,67 @@ rte_thread_detach(rte_thread_t thread_id)return pthread_detach ((pthread_t )thread_id.opaque_id); } +int +rte_thread_mutex_init (rte_thread_mutex *mutex) +{ +int ret =0 ; +pthread_mutex_t *m =NULL ; + +RTE_VERIFY (mutex !=NULL ); + + m =calloc (1 ,sizeof (*m)); +if (m ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize mutex. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + + ret =pthread_mutex_init (m,NULL ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init mutex. ret = %d\n" , ret); + goto cleanup; + } + + mutex->mutex_id = m; + m =NULL ; + +cleanup: +free (m); +return ret; +} + +int +rte_thread_mutex_lock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_lock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_unlock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_unlock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_destroy (rte_thread_mutex *mutex) +{ +int ret =0 ; +RTE_VERIFY (mutex !=NULL ); + + ret =pthread_mutex_destroy ((pthread_mutex_t *)mutex->mutex_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Unable to destroy mutex, ret = %d\n" , ret); + +free (mutex->mutex_id); + mutex->mutex_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +94 -0
112 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -436,6 +436,10 @@ EXPERIMENTAL { rte_thread_create; rte_thread_join; rte_thread_detach; + rte_thread_mutex_init; + rte_thread_mutex_lock; + rte_thread_mutex_unlock; + rte_thread_mutex_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +53 -0
59 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v10 8/9 eal: implement functions for thread barrier management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for barrier init, destroy, wait.
A portable type is used to represent a barrier identifier. The rte_thread_barrier_wait() function returns the same value on all platforms.
--- lib/eal/common/rte_thread.c | 61 ++++++++++++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 58 ++++++++++++++++++++++++++++++++++ lib/eal/version.map | 3 ++ lib/eal/windows/rte_thread.c | 56 +++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+)
lib/eal/common/rte_thread.c +61 -0
@@ -312,6 +312,67 @@ rte_thread_mutex_destroy(rte_thread_mutex *mutex)return ret; } +int +rte_thread_barrier_init (rte_thread_barrier *barrier,int count) +{ +int ret =0 ; +pthread_barrier_t *pthread_barrier =NULL ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (count >0 ); + + pthread_barrier =calloc (1 ,sizeof (*pthread_barrier)); +if (pthread_barrier ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize barrier. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + ret =pthread_barrier_init (pthread_barrier,NULL , count); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init barrier, ret = %d\n" , ret); + goto cleanup; + } + + barrier->barrier_id = pthread_barrier; + pthread_barrier =NULL ; + +cleanup: +free (pthread_barrier); +return ret; +} + +int +rte_thread_barrier_wait (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (barrier->barrier_id !=NULL ); + + ret =pthread_barrier_wait (barrier->barrier_id); +if (ret ==PTHREAD_BARRIER_SERIAL_THREAD ) + ret =RTE_THREAD_BARRIER_SERIAL_THREAD ; + +return ret; +} + +int +rte_thread_barrier_destroy (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); + + ret =pthread_barrier_destroy (barrier->barrier_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Failed to destroy barrier: %d\n" , ret); + +free (barrier->barrier_id); + barrier->barrier_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +58 -0
70 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -440,6 +440,9 @@ EXPERIMENTAL { rte_thread_mutex_lock; rte_thread_mutex_unlock; rte_thread_mutex_destroy; + rte_thread_barrier_init; + rte_thread_barrier_wait; + rte_thread_barrier_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v10 9/9 eal: add EAL argument for setting thread priority
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Allow the user to choose the thread priority through an EAL command line argument.
The user can choose thread priority through an EAL parameter, when starting an application. If EAL parameter is not used, the per-platform default value for thread priority is used. Otherwise administrator has an option to set one of available options:
--thread-prio normal
--thread-prio realtime
Example:
./dpdk-l2fwd -l 0-3 -n 4 --thread-prio normal -- -q 8 -p ffff
--- lib/eal/common/eal_common_options.c | 28 +++++++++++++++++++++++++++- lib/eal/common/eal_internal_cfg.h | 2 ++ lib/eal/common/eal_options.h | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-)
lib/eal/common/eal_common_options.c +27 -1
@@ -107,6 +107,7 @@ eal_long_options[] = { {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM }, {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM }, {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM}, + {OPT_THREAD_PRIORITY, 1, NULL, OPT_THREAD_PRIORITY_NUM},/* legacy options that will be removed in future */ {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
@@ -1412,6 +1413,24 @@ eal_parse_simd_bitwidth(const char *arg)return 0 ; } +static int +eal_parse_thread_priority (const char *arg) +{ +struct internal_config *internal_conf = +eal_get_internal_configuration (); +enum rte_thread_priority priority; + +if (!strncmp ("normal" , arg,sizeof ("normal" ))) + priority =RTE_THREAD_PRIORITY_NORMAL ; +else if (!strncmp ("realtime" , arg,sizeof ("realtime" ))) + priority =RTE_THREAD_PRIORITY_REALTIME_CRITICAL ; +else +return -1 ; + + internal_conf->thread_priority = priority; +return 0 ; +} +static int eal_parse_base_virtaddr (const char *arg) {
@@ -1825,7 +1844,13 @@ eal_parse_common_option(int opt, const char *optarg,return -1 ; }break ; - +case OPT_THREAD_PRIORITY_NUM : +if (eal_parse_thread_priority (optarg) <0 ) { +RTE_LOG (ERR ,EAL ,"invalid parameter for --" +OPT_THREAD_PRIORITY "\n" ); +return -1 ; + } +break ;/* don't know what to do, leave this to caller */ default :return 1 ;
@@ -2088,6 +2113,7 @@ eal_common_usage(void)" (can be used multiple times)\n" " --" OPT_VMWARE_TSC_MAP " Use VMware TSC map instead of native RDTSC\n" " --" OPT_PROC_TYPE " Type of this process (primary|secondary|auto)\n" +" --" OPT_THREAD_PRIORITY " Set threads priority (normal|realtime)\n" #ifndef RTE_EXEC_ENV_WINDOWS" --" OPT_SYSLOG " Set syslog facility\n" #endif
lib/eal/common/eal_internal_cfg.h +2 -0
@@ -94,6 +94,8 @@ struct internal_config {unsigned int no_telemetry;/**< true to disable Telemetry */ struct simd_bitwidth max_simd_bitwidth;/**< max simd bitwidth path to use */ +enum rte_thread_priority thread_priority; +/**< thread priority to configure */ };void eal_reset_internal_config (struct internal_config *internal_cfg);
lib/eal/common/eal_options.h +2 -0
@@ -93,6 +93,8 @@ enum {OPT_NO_TELEMETRY_NUM , #define OPT_FORCE_MAX_SIMD_BITWIDTH "force-max-simd-bitwidth"OPT_FORCE_MAX_SIMD_BITWIDTH_NUM , +#define OPT_THREAD_PRIORITY "thread-prio" +OPT_THREAD_PRIORITY_NUM ,/* legacy option that will be removed in future */ #define OPT_PCI_BLACKLIST "pci-blacklist"
Signature · 1 line
2.31.0.vfs.0.1
v11 cover eal: Add EAL API for threading
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
EAL thread API
**Problem Statement**
DPDK currently uses the pthread interface to create and manage threads. Windows does not support the POSIX thread programming model, so it currently
relies on a header file that hides the Windows calls under pthread matched interfaces. Given that EAL should isolate the environment specifics from the applications and libraries and mediate
all the communication with the operating systems, a new EAL interface is needed for thread management.
**Goals**
* Introduce a generic EAL API for threading support that will remove the current Windows pthread.h shim.
* Replace references to pthread_* across the DPDK codebase with the new RTE_THREAD_* API.
* Allow users to choose between using the RTE_THREAD_* API or a 3rd party thread library through a configuration option.
**Design plan**
New API main files:
* rte_thread.h (librte_eal/include)
* rte_thread.c (librte_eal/windows)
* rte_thread.c (librte_eal/common)
**A schematic example of the design**
--------------------------------------------------lib/librte_eal/include/rte_thread.h
int rte_thread_create();
lib/librte_eal/common/rte_thread.c
int rte_thread_create()
{
return pthread_create();
}lib/librte_eal/windows/rte_thread.c
int rte_thread_create()
{
return CreateThread();
}-----------------------------------------------------
**Thread attributes**
When or after a thread is created, specific characteristics of the thread can be adjusted. Given that the thread characteristics that are of interest for DPDK applications are affinity and priority, the following structure that represents thread attributes has been defined:
typedef struct
{
enum rte_thread_priority priority;
rte_cpuset_t cpuset;
} rte_thread_attr_t;The *rte_thread_create()* function can optionally receive an rte_thread_attr_t
object that will cause the thread to be created with the affinity and priority
described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used. An rte_thread_attr_t object can also be set to the default values by calling *rte_thread_attr_init()*.
*Priority* is represented through an enum that currently advertises two values for priority:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
The enum can be extended to allow for multiple priority levels.rte_thread_set_priority - sets the priority of a threadrte_thread_attr_set_priority - updates an rte_thread_attr_t object
with a new value for priority
The user can choose thread priority through an EAL parameter, when starting an application. If EAL parameter is not used, the per-platform default value for thread priority is used. Otherwise administrator has an option to set one of available options:
--thread-prio normal
--thread-prio realtime
Example:
./dpdk-l2fwd -l 0-3 -n 4 –thread-prio normal -- -q 8 -p ffff
*Affinity* is described by the already known “rte_cpuset_t” type. rte_thread_attr_set/get_affinity - sets/gets the affinity field in a
rte_thread_attr_t object
rte_thread_set/get_affinity – sets/gets the affinity of a thread
**Errors**
A translation function that maps Windows error codes to errno-style error codes is provided.
**Future work**
The long term plan is for EAL to provide full threading support:
* Add support for conditional variables
* Add support for pthread_mutex_trylock
* Additional functionality offered by pthread_*
(such as pthread_setname_np, etc.)
v11:
- Add unit tests for thread API
- Rebase
v10:
- Remove patch no. 10. It will be broken down in subpatches and sent as a different patchset that depends on this one. This is done due to the ABI breaks that would be caused by patch 10.
- Replace unix/rte_thread.c with common/rte_thread.c
- Remove initializations that may prevent compiler from issuing useful warnings.
- Remove rte_thread_types.h and rte_windows_thread_types.h
- Remove unneeded priority macros (EAL_THREAD_PRIORITY*)
- Remove functions that retrieves thread handle from process handle
- Remove rte_thread_cancel() until same behavior is obtained on all platforms.
- Fix rte_thread_detach() function description,
return value and remove empty line.
- Reimplement mutex functions. Add compatible representation for mutex identifier. Add macro to replace static mutex initialization instances.
- Fix commit messages (lines too long, remove unicode symbols)
v9:
- Sign patches
v8:
- Rebase
- Add rte_thread_detach() API
- Set default priority, when user did not specify a value
v7:
Based on DmitryK's review:
- Change thread id representation
- Change mutex id representation
- Implement static mutex inititalizer for Windows
- Change barrier identifier representation
- Improve commit messages
- Add missing doxygen comments
- Split error translation function
- Improve name for affinity function
- Remove cpuset_size parameter
- Fix eal_create_cpu_map function
- Map EAL priority values to OS specific values
- Add thread wrapper for start routine
- Do not export rte_thread_cancel() on Windows
- Cleanup, fix comments, fix typos.
v6:
- improve error-translation function
- call the error translation function in rte_thread_value_get()
v5:
- update cover letter with more details on the priority argument
v4:
- fix function description
- rebase
v3:
- rebase
v2:
- revert changes that break ABI
- break up changes into smaller patches
- fix coding style issues
- fix issues with errors
- fix parameter type in examples/kni.c
Narcisa Vasile (10):
eal: add basic threading functions
eal: add thread attributes
eal/windows: translate Windows errors to errno-style errors
eal: implement functions for thread affinity management
eal: implement thread priority management functions
eal: add thread lifetime management
eal: implement functions for mutex management
eal: implement functions for thread barrier management
eal: add EAL argument for setting thread priority Add unit tests for thread API
app/test/meson.build | 2 + app/test/test_threads.c | 419 ++++++++++++++++++++ lib/eal/common/eal_common_options.c | 28 +- lib/eal/common/eal_internal_cfg.h | 2 + lib/eal/common/eal_options.h | 2 + lib/eal/common/meson.build | 1 + lib/eal/common/rte_thread.c | 445 +++++++++++++++++++++ lib/eal/include/rte_thread.h | 406 ++++++++++++++++++- lib/eal/unix/meson.build | 1 - lib/eal/unix/rte_thread.c | 92 ----- lib/eal/version.map | 20 + lib/eal/windows/eal_lcore.c | 176 ++++++--- lib/eal/windows/eal_windows.h | 10 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 588 ++++++++++++++++++++++++++-- 15 files changed, 2020 insertions(+), 174 deletions(-) create mode 100644 app/test/test_threads.c create mode 100644 lib/eal/common/rte_thread.c delete mode 100644 lib/eal/unix/rte_thread.c
Signature · 1 line
2.31.0.vfs.0.1
PATCH v11 1/10 eal: add basic threading functions
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
---
lib/eal/common/meson.build | 1 +
lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
lib/eal/include/rte_thread.h | 48 +++++++++++++++++-----
lib/eal/unix/meson.build | 1 -
lib/eal/version.map | 3 ++
lib/eal/windows/rte_thread.c | 17 ++++++++
6 files changed, 95 insertions(+), 32 deletions(-)
rename lib/eal/{unix => common}/rte_thread.c (66%)lib/eal/common/meson.build +1 -0
@@ -80,6 +80,7 @@ sources += files( 'rte_random.c', 'rte_reciprocal.c', 'rte_service.c', + 'rte_thread.c', 'rte_version.c', )
lib/eal/common/rte_thread.c renamed from lib/eal/unix/rte_thread.c +35 -22
107 lines not on this page · raw message
lib/eal/include/rte_thread.h +39 -9
83 lines not on this page · raw message
lib/eal/unix/meson.build +0 -1
@@ -6,5 +6,4 @@ sources += files( 'eal_unix_memory.c', 'eal_unix_timer.c', 'eal_firmware.c', - 'rte_thread.c', )
lib/eal/version.map +3 -0
@@ -426,6 +426,9 @@ EXPERIMENTAL { # added in 21.08 rte_power_monitor_multi; # WINDOWS_NO_EXPORT + + rte_thread_self; + rte_thread_equal; }; INTERNAL {
lib/eal/windows/rte_thread.c +17 -0
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright 2021 Mellanox Technologies, Ltd +* Copyright(c) 2021 Microsoft Corporation */ #include <rte_common.h>
@@ -11,6 +12,22 @@ struct eal_tls_key {DWORD thread_index; }; +rte_thread_t +rte_thread_self (void ) +{ +rte_thread_t thread_id; + + thread_id.opaque_id =GetCurrentThreadId (); + +return thread_id; +} + +int +rte_thread_equal (rte_thread_t t1,rte_thread_t t2) +{ +return t1.opaque_id == t2.opaque_id; +} +int rte_thread_key_create (rte_thread_key *key, __rte_unused void (*destructor)(void *))
Signature · 1 line
2.31.0.vfs.0.1
PATCH v11 2/10 eal: add thread attributes
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.
Priority is represented through an enum that allows for two levels:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
Affinity is described by the rte_cpuset_t type.
An rte_thread_attr_t object can be set to the default values by calling rte_thread_attr_init().
--- lib/eal/common/rte_thread.c | 46 ++++++++++++++++++ lib/eal/include/rte_thread.h | 93 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 44 +++++++++++++++++ 4 files changed, 187 insertions(+)
lib/eal/common/rte_thread.c +46 -0
@@ -9,6 +9,7 @@#include <string.h> #include <rte_common.h> +#include <rte_debug.h> #include <rte_errno.h> #include <rte_log.h> #include <rte_thread.h>
@@ -33,6 +34,51 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_attr_init (rte_thread_attr_t *attr) +{ +RTE_VERIFY (attr !=NULL ); + +CPU_ZERO (&attr->cpuset); + attr->priority =RTE_THREAD_PRIORITY_NORMAL ; + +return 0 ; +} + +int +rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + thread_attr->cpuset = *cpuset; + +return 0 ; +} + +int +rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + *cpuset = thread_attr->cpuset; + +return 0 ; +} + +int +rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, +enum rte_thread_priority priority) +{ +RTE_VERIFY (thread_attr !=NULL ); + + thread_attr->priority = priority; +return 0 ; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +93 -0
105 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -429,6 +429,10 @@ EXPERIMENTAL { rte_thread_self; rte_thread_equal; + rte_thread_attr_init; + rte_thread_attr_get_affinity; + rte_thread_attr_set_affinity; + rte_thread_attr_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v11 3/10 eal/windows: translate Windows errors to errno-style errors
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function to translate Windows error codes to errno-style error codes. The possible return values are chosen so that we have as much semantical compatibility between platforms as possible.
--- lib/eal/common/rte_thread.c | 6 +-- lib/eal/include/rte_thread.h | 5 +- lib/eal/windows/rte_thread.c | 95 +++++++++++++++++++++++++++--------- 3 files changed, 76 insertions(+), 30 deletions(-)
lib/eal/common/rte_thread.c +3 -3
@@ -47,7 +47,7 @@ rte_thread_attr_init(rte_thread_attr_t *attr)int rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -59,7 +59,7 @@ rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -71,7 +71,7 @@ rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, -enum rte_thread_priority priority) +enum rte_thread_priority priority) {RTE_VERIFY (thread_attr !=NULL );
lib/eal/include/rte_thread.h +2 -3
@@ -235,9 +235,8 @@ int rte_thread_value_set(rte_thread_key key, const void *value);* * @return * On success, value data pointer (can also be NULL). -* On failure, NULL and an error number is set in rte_errno. -* rte_errno can be: EINVAL - Invalid parameter passed. -* ENOEXEC - Specific OS error. +* On failure, NULL and a positive error number is set in rte_errno. +* */ __rte_experimental void *rte_thread_value_get(rte_thread_key key);
lib/eal/windows/rte_thread.c +71 -24
165 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v11 4/10 eal: implement functions for thread affinity management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement functions for getting/setting thread affinity. Threads can be pinned to specific cores by setting their affinity attribute.
--- lib/eal/common/rte_thread.c | 16 ++++ lib/eal/include/rte_thread.h | 36 +++++++ lib/eal/version.map | 2 + lib/eal/windows/eal_lcore.c | 176 +++++++++++++++++++++++++--------- lib/eal/windows/eal_windows.h | 10 ++ lib/eal/windows/rte_thread.c | 125 +++++++++++++++++++++++- 6 files changed, 319 insertions(+), 46 deletions(-)
lib/eal/common/rte_thread.c +16 -0
@@ -34,6 +34,22 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_set_affinity_by_id (rte_thread_t thread_id, +const rte_cpuset_t *cpuset) +{ +return pthread_setaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} + +int +rte_thread_get_affinity_by_id (rte_thread_t thread_id, +rte_cpuset_t *cpuset) +{ +return pthread_getaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +36 -0
@@ -87,6 +87,42 @@ int rte_thread_equal(rte_thread_t t1, rte_thread_t t2);#ifdef RTE_HAS_CPUSET +/** +* Set the affinity of thread 'thread_id' to the cpu set +* specified by 'cpuset'. +* +* @param thread_id +* Id of the thread for which to set the affinity. +* +* @param cpuset +* Pointer to CPU affinity to set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_affinity_by_id(rte_thread_t thread_id, +const rte_cpuset_t *cpuset); + +/** +* Get the affinity of thread 'thread_id' and store it +* in 'cpuset'. +* +* @param thread_id +* Id of the thread for which to get the affinity. +* +* @param cpuset +* Pointer for storing the affinity value. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_get_affinity_by_id(rte_thread_t thread_id, +rte_cpuset_t *cpuset); +/** * Initialize the attributes of a thread. * These attributes can be passed to the rte_thread_create() function
lib/eal/version.map +2 -0
@@ -433,6 +433,8 @@ EXPERIMENTAL { rte_thread_attr_get_affinity; rte_thread_attr_set_affinity; rte_thread_attr_set_priority; + rte_thread_get_affinity_by_id; + rte_thread_set_affinity_by_id; }; INTERNAL {
lib/eal/windows/eal_lcore.c +131 -45
231 lines not on this page · raw message
lib/eal/windows/eal_windows.h +10 -0
@@ -55,6 +55,16 @@ int eal_thread_create(pthread_t *thread);*/ unsigned int eal_socket_numa_node (unsigned int socket_id); +/** +* Get pointer to the group affinity for the cpu. +* +* @param cpu_index +* Index of the cpu, as it comes from rte_cpuset_t. +* @return +* Pointer to the group affinity for the cpu. +*/ +PGROUP_AFFINITY eal_get_cpu_affinity (size_t cpu_index); +/** * Schedule code for execution in the interrupt thread. *
lib/eal/windows/rte_thread.c +124 -1
137 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v11 5/10 eal: implement thread priority management functions
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function for setting the priority for a thread. Priorities on multiple platforms are similarly determined by a priority value and a priority class/policy.
On Linux, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* policy SCHED_OTHER
* priority value: (sched_get_priority_min(SCHED_OTHER) +
sched_get_priority_max(SCHED_OTHER))/2;
RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* policy SCHED_RR
* priority value: sched_get_priority_max(SCHED_RR);
On Windows, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* class NORMAL_PRIORITY_CLASS
* priority THREAD_PRIORITY_NORMAL RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* class REALTIME_PRIORITY_CLASS
* priority THREAD_PRIORITY_TIME_CRITICAL
--- lib/eal/common/rte_thread.c | 49 ++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 17 ++++++++++ lib/eal/version.map | 1 + lib/eal/windows/rte_thread.c | 66 ++++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+)
lib/eal/common/rte_thread.c +49 -0
@@ -50,6 +50,55 @@ rte_thread_get_affinity_by_id(rte_thread_t thread_id, sizeof(*cpuset), cpuset); } +static int +thread_map_priority_to_os_value (enum rte_thread_priority eal_pri, +int *os_pri,int *pol) +{ +/* Clear the output parameters */ + *os_pri =sched_get_priority_min (SCHED_OTHER ) -1 ; + *pol =-1 ; + +switch (eal_pri) { +case RTE_THREAD_PRIORITY_NORMAL : + *pol =SCHED_OTHER ; + +/* +* Choose the middle of the range to represent +* the priority 'normal'. +* On Linux, this should be 0, since both +* sched_get_priority_min/_max return 0 for SCHED_OTHER. +*/ + *os_pri = (sched_get_priority_min (SCHED_OTHER ) + +sched_get_priority_max (SCHED_OTHER ))/2 ; +break ; +case RTE_THREAD_PRIORITY_REALTIME_CRITICAL : + *pol =SCHED_RR ; + *os_pri =sched_get_priority_max (SCHED_RR ); +break ; +default : +RTE_LOG (DEBUG ,EAL ,"The requested priority value is invalid.\n" ); +return EINVAL ; + } +return 0 ; +} + +int +rte_thread_set_priority (rte_thread_t thread_id, +enum rte_thread_priority priority) +{ +int ret; +int policy; +struct sched_param param; + + ret =thread_map_priority_to_os_value (priority, ¶m.sched_priority, + &policy); +if (ret !=0 ) +return ret; + +return pthread_setschedparam ((pthread_t )thread_id.opaque_id, + policy, ¶m); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +17 -0
@@ -215,6 +215,23 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp);#endif /* RTE_HAS_CPUSET */ +/** +* Set the priority of a thread. +* +* @param thread_id +* Id of the thread for which to set priority. +* +* @param priority +* Priority value to be set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_priority(rte_thread_t thread_id, +enum rte_thread_priority priority); +/** * Create a TLS data key visible to all threads in the process. * the created key is later used to get/set a value.
lib/eal/version.map +1 -0
@@ -435,6 +435,7 @@ EXPERIMENTAL { rte_thread_attr_set_priority; rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; + rte_thread_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +66 -0
72 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v11 6/10 eal: add thread lifetime management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for thread creation, joining, detaching.
The *rte_thread_create()* function can optionally receive
an rte_thread_attr_t object that will cause the thread to be created with the affinity and priority described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used.
On Windows, the function executed by a thread when the thread starts is represeneted by a function pointer of type DWORD (*func) (void*). On other platforms, the function pointer is a void* (*func) (void*).
Performing a cast between these two types of function pointers to uniformize the API on all platforms may result in undefined behavior. TO fix this issue, a wrapper that respects the signature required by CreateThread() has been created on Windows.
--- lib/eal/common/rte_thread.c | 107 +++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 55 +++++++++++++ lib/eal/version.map | 3 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 138 ++++++++++++++++++++++++++++++++ 5 files changed, 304 insertions(+), 1 deletion(-)
lib/eal/common/rte_thread.c +107 -0
@@ -144,6 +144,113 @@ rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,return 0 ; } +int +rte_thread_create (rte_thread_t *thread_id, +const rte_thread_attr_t *thread_attr, +rte_thread_func thread_func,void *args) +{ +int ret =0 ; +pthread_attr_t attr; +pthread_attr_t *attrp =NULL ; +struct sched_param param = { + .sched_priority =0 , + }; +int policy =SCHED_OTHER ; + +if (thread_attr !=NULL ) { + ret =pthread_attr_init (&attr); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_init failed\n" ); + goto cleanup; + } + + attrp = &attr; + +if (thread_attr->priority !=RTE_THREAD_PRIORITY_UNDEFINED ) { +/* +* Set the inherit scheduler parameter to explicit, +* otherwise the priority attribute is ignored. +*/ + ret =pthread_attr_setinheritsched (attrp, +PTHREAD_EXPLICIT_SCHED ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setinheritsched failed\n" ); + goto cleanup; + } + + ret =thread_map_priority_to_os_value ( + thread_attr->priority, + ¶m.sched_priority, &policy + ); +if (ret !=0 ) + goto cleanup; + + ret =pthread_attr_setschedpolicy (attrp, policy); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedpolicy failed\n" ); + goto cleanup; + } + + ret =pthread_attr_setschedparam (attrp, ¶m); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedparam failed\n" ); + goto cleanup; + } + } + +if (CPU_COUNT (&thread_attr->cpuset) >0 ) { + ret =pthread_attr_setaffinity_np (attrp, +sizeof (thread_attr->cpuset), + &thread_attr->cpuset); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setaffinity_np failed\n" ); + goto cleanup; + } + } + } + + ret =pthread_create ((pthread_t *)&thread_id->opaque_id, attrp, + thread_func, args); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_create failed\n" ); + goto cleanup; + } + +cleanup: +if (attrp !=NULL ) +pthread_attr_destroy (&attr); + +return ret; +} + +int +rte_thread_join (rte_thread_t thread_id,unsigned long *value_ptr) +{ +int ret =0 ; +void *res =NULL ; +void **pres =NULL ; + +if (value_ptr !=NULL ) + pres = &res; + + ret =pthread_join ((pthread_t )thread_id.opaque_id, pres); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_join failed\n" ); +return ret; + } + +if (pres !=NULL ) + *value_ptr = *(unsigned long *)(*pres); + +return 0 ; +} + +int +rte_thread_detach (rte_thread_t thread_id) +{ +return pthread_detach ((pthread_t )thread_id.opaque_id); +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +55 -0
67 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -436,6 +436,9 @@ EXPERIMENTAL { rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; rte_thread_set_priority; + rte_thread_create; + rte_thread_join; + rte_thread_detach; }; INTERNAL {
lib/eal/windows/include/sched.h +1 -1
@@ -44,7 +44,7 @@ typedef struct _rte_cpuset_s { (1LL << _WHICH_BIT(b))) != 0LL)static inline int -count_cpu (rte_cpuset_t *s) +count_cpu (const rte_cpuset_t *s) {unsigned int _i;int count =0 ;
lib/eal/windows/rte_thread.c +138 -0
150 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v11 7/10 eal: implement functions for mutex management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for mutex init, destroy, lock, unlock.
Add RTE_STATIC_MUTEX macro to replace static initialization of mutexes.
Windows does not have a static initializer. Initialization is only done through InitializeCriticalSection().
The RTE_STATIC_MUTEX calls into the rte_thread_mutex_init() function that performs the actual mutex initialization.
--- lib/eal/common/rte_thread.c | 61 +++++++++++++++++++++++ lib/eal/include/rte_thread.h | 94 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 53 ++++++++++++++++++++ 4 files changed, 212 insertions(+)
lib/eal/common/rte_thread.c +61 -0
@@ -251,6 +251,67 @@ rte_thread_detach(rte_thread_t thread_id)return pthread_detach ((pthread_t )thread_id.opaque_id); } +int +rte_thread_mutex_init (rte_thread_mutex *mutex) +{ +int ret =0 ; +pthread_mutex_t *m =NULL ; + +RTE_VERIFY (mutex !=NULL ); + + m =calloc (1 ,sizeof (*m)); +if (m ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize mutex. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + + ret =pthread_mutex_init (m,NULL ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init mutex. ret = %d\n" , ret); + goto cleanup; + } + + mutex->mutex_id = m; + m =NULL ; + +cleanup: +free (m); +return ret; +} + +int +rte_thread_mutex_lock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_lock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_unlock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_unlock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_destroy (rte_thread_mutex *mutex) +{ +int ret =0 ; +RTE_VERIFY (mutex !=NULL ); + + ret =pthread_mutex_destroy ((pthread_mutex_t *)mutex->mutex_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Unable to destroy mutex, ret = %d\n" , ret); + +free (mutex->mutex_id); + mutex->mutex_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +94 -0
112 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -439,6 +439,10 @@ EXPERIMENTAL { rte_thread_create; rte_thread_join; rte_thread_detach; + rte_thread_mutex_init; + rte_thread_mutex_lock; + rte_thread_mutex_unlock; + rte_thread_mutex_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +53 -0
59 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v11 8/10 eal: implement functions for thread barrier management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for barrier init, destroy, wait.
A portable type is used to represent a barrier identifier. The rte_thread_barrier_wait() function returns the same value on all platforms.
--- lib/eal/common/rte_thread.c | 61 ++++++++++++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 58 ++++++++++++++++++++++++++++++++++ lib/eal/version.map | 3 ++ lib/eal/windows/rte_thread.c | 56 +++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+)
lib/eal/common/rte_thread.c +61 -0
@@ -312,6 +312,67 @@ rte_thread_mutex_destroy(rte_thread_mutex *mutex)return ret; } +int +rte_thread_barrier_init (rte_thread_barrier *barrier,int count) +{ +int ret =0 ; +pthread_barrier_t *pthread_barrier =NULL ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (count >0 ); + + pthread_barrier =calloc (1 ,sizeof (*pthread_barrier)); +if (pthread_barrier ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize barrier. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + ret =pthread_barrier_init (pthread_barrier,NULL , count); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init barrier, ret = %d\n" , ret); + goto cleanup; + } + + barrier->barrier_id = pthread_barrier; + pthread_barrier =NULL ; + +cleanup: +free (pthread_barrier); +return ret; +} + +int +rte_thread_barrier_wait (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (barrier->barrier_id !=NULL ); + + ret =pthread_barrier_wait (barrier->barrier_id); +if (ret ==PTHREAD_BARRIER_SERIAL_THREAD ) + ret =RTE_THREAD_BARRIER_SERIAL_THREAD ; + +return ret; +} + +int +rte_thread_barrier_destroy (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); + + ret =pthread_barrier_destroy (barrier->barrier_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Failed to destroy barrier: %d\n" , ret); + +free (barrier->barrier_id); + barrier->barrier_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +58 -0
70 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -443,6 +443,9 @@ EXPERIMENTAL { rte_thread_mutex_lock; rte_thread_mutex_unlock; rte_thread_mutex_destroy; + rte_thread_barrier_init; + rte_thread_barrier_wait; + rte_thread_barrier_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v11 9/10 eal: add EAL argument for setting thread priority
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Allow the user to choose the thread priority through an EAL command line argument.
The user can choose thread priority through an EAL parameter, when starting an application. If EAL parameter is not used, the per-platform default value for thread priority is used. Otherwise administrator has an option to set one of available options:
--thread-prio normal
--thread-prio realtime
Example:
./dpdk-l2fwd -l 0-3 -n 4 --thread-prio normal -- -q 8 -p ffff
--- lib/eal/common/eal_common_options.c | 28 +++++++++++++++++++++++++++- lib/eal/common/eal_internal_cfg.h | 2 ++ lib/eal/common/eal_options.h | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-)
lib/eal/common/eal_common_options.c +27 -1
@@ -107,6 +107,7 @@ eal_long_options[] = { {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM }, {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM }, {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM}, + {OPT_THREAD_PRIORITY, 1, NULL, OPT_THREAD_PRIORITY_NUM},/* legacy options that will be removed in future */ {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
@@ -1412,6 +1413,24 @@ eal_parse_simd_bitwidth(const char *arg)return 0 ; } +static int +eal_parse_thread_priority (const char *arg) +{ +struct internal_config *internal_conf = +eal_get_internal_configuration (); +enum rte_thread_priority priority; + +if (!strncmp ("normal" , arg,sizeof ("normal" ))) + priority =RTE_THREAD_PRIORITY_NORMAL ; +else if (!strncmp ("realtime" , arg,sizeof ("realtime" ))) + priority =RTE_THREAD_PRIORITY_REALTIME_CRITICAL ; +else +return -1 ; + + internal_conf->thread_priority = priority; +return 0 ; +} +static int eal_parse_base_virtaddr (const char *arg) {
@@ -1825,7 +1844,13 @@ eal_parse_common_option(int opt, const char *optarg,return -1 ; }break ; - +case OPT_THREAD_PRIORITY_NUM : +if (eal_parse_thread_priority (optarg) <0 ) { +RTE_LOG (ERR ,EAL ,"invalid parameter for --" +OPT_THREAD_PRIORITY "\n" ); +return -1 ; + } +break ;/* don't know what to do, leave this to caller */ default :return 1 ;
@@ -2088,6 +2113,7 @@ eal_common_usage(void)" (can be used multiple times)\n" " --" OPT_VMWARE_TSC_MAP " Use VMware TSC map instead of native RDTSC\n" " --" OPT_PROC_TYPE " Type of this process (primary|secondary|auto)\n" +" --" OPT_THREAD_PRIORITY " Set threads priority (normal|realtime)\n" #ifndef RTE_EXEC_ENV_WINDOWS" --" OPT_SYSLOG " Set syslog facility\n" #endif
lib/eal/common/eal_internal_cfg.h +2 -0
@@ -94,6 +94,8 @@ struct internal_config {unsigned int no_telemetry;/**< true to disable Telemetry */ struct simd_bitwidth max_simd_bitwidth;/**< max simd bitwidth path to use */ +enum rte_thread_priority thread_priority; +/**< thread priority to configure */ };void eal_reset_internal_config (struct internal_config *internal_cfg);
lib/eal/common/eal_options.h +2 -0
@@ -93,6 +93,8 @@ enum {OPT_NO_TELEMETRY_NUM , #define OPT_FORCE_MAX_SIMD_BITWIDTH "force-max-simd-bitwidth"OPT_FORCE_MAX_SIMD_BITWIDTH_NUM , +#define OPT_THREAD_PRIORITY "thread-prio" +OPT_THREAD_PRIORITY_NUM ,/* legacy option that will be removed in future */ #define OPT_PCI_BLACKLIST "pci-blacklist"
Signature · 1 line
2.31.0.vfs.0.1
PATCH v11 10/10 Add unit tests for thread API
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
As a new API for threading is introduced,
a set of unit tests have been added to test the new interface.
--- app/test/meson.build | 2 + app/test/test_threads.c | 419 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 421 insertions(+) create mode 100644 app/test/test_threads.c
app/test/meson.build +2 -0
@@ -140,6 +140,7 @@ test_sources = files( 'test_table_tables.c', 'test_tailq.c', 'test_thash.c', + 'test_threads.c', 'test_timer.c', 'test_timer_perf.c', 'test_timer_racecond.c',
@@ -276,6 +277,7 @@ fast_tests = [ ['reorder_autotest', true], ['service_autotest', true], ['thash_autotest', true], + ['threads_autotest, true'], ['trace_autotest', true], ]
app/test/test_threads.c new file +419 -0
419 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
v12 cover eal: Add EAL API for threading
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
EAL thread API
**Problem Statement**
DPDK currently uses the pthread interface to create and manage threads. Windows does not support the POSIX thread programming model, so it currently
relies on a header file that hides the Windows calls under pthread matched interfaces. Given that EAL should isolate the environment specifics from the applications and libraries and mediate
all the communication with the operating systems, a new EAL interface is needed for thread management.
**Goals**
* Introduce a generic EAL API for threading support that will remove the current Windows pthread.h shim.
* Replace references to pthread_* across the DPDK codebase with the new RTE_THREAD_* API.
* Allow users to choose between using the RTE_THREAD_* API or a 3rd party thread library through a configuration option.
**Design plan**
New API main files:
* rte_thread.h (librte_eal/include)
* rte_thread.c (librte_eal/windows)
* rte_thread.c (librte_eal/common)
**A schematic example of the design**
--------------------------------------------------lib/librte_eal/include/rte_thread.h
int rte_thread_create();
lib/librte_eal/common/rte_thread.c
int rte_thread_create()
{
return pthread_create();
}lib/librte_eal/windows/rte_thread.c
int rte_thread_create()
{
return CreateThread();
}-----------------------------------------------------
**Thread attributes**
When or after a thread is created, specific characteristics of the thread can be adjusted. Given that the thread characteristics that are of interest for DPDK applications are affinity and priority, the following structure that represents thread attributes has been defined:
typedef struct
{
enum rte_thread_priority priority;
rte_cpuset_t cpuset;
} rte_thread_attr_t;The *rte_thread_create()* function can optionally receive an rte_thread_attr_t
object that will cause the thread to be created with the affinity and priority
described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used. An rte_thread_attr_t object can also be set to the default values by calling *rte_thread_attr_init()*.
*Priority* is represented through an enum that currently advertises two values for priority:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
The enum can be extended to allow for multiple priority levels.rte_thread_set_priority - sets the priority of a threadrte_thread_attr_set_priority - updates an rte_thread_attr_t object
with a new value for priority
The user can choose thread priority through an EAL parameter, when starting an application. If EAL parameter is not used, the per-platform default value for thread priority is used. Otherwise administrator has an option to set one of available options:
--thread-prio normal
--thread-prio realtime
Example:
./dpdk-l2fwd -l 0-3 -n 4 –thread-prio normal -- -q 8 -p ffff
*Affinity* is described by the already known “rte_cpuset_t” type. rte_thread_attr_set/get_affinity - sets/gets the affinity field in a
rte_thread_attr_t object
rte_thread_set/get_affinity – sets/gets the affinity of a thread
**Errors**
A translation function that maps Windows error codes to errno-style error codes is provided.
**Future work**
The long term plan is for EAL to provide full threading support:
* Add support for conditional variables
* Add support for pthread_mutex_trylock
* Additional functionality offered by pthread_*
(such as pthread_setname_np, etc.)
v12:
- Fix freebsd warning about initializer in unit tests
v11:
- Add unit tests for thread API
- Rebase
v10:
- Remove patch no. 10. It will be broken down in subpatches and sent as a different patchset that depends on this one. This is done due to the ABI breaks that would be caused by patch 10.
- Replace unix/rte_thread.c with common/rte_thread.c
- Remove initializations that may prevent compiler from issuing useful warnings.
- Remove rte_thread_types.h and rte_windows_thread_types.h
- Remove unneeded priority macros (EAL_THREAD_PRIORITY*)
- Remove functions that retrieves thread handle from process handle
- Remove rte_thread_cancel() until same behavior is obtained on all platforms.
- Fix rte_thread_detach() function description,
return value and remove empty line.
- Reimplement mutex functions. Add compatible representation for mutex identifier. Add macro to replace static mutex initialization instances.
- Fix commit messages (lines too long, remove unicode symbols)
v9:
- Sign patches
v8:
- Rebase
- Add rte_thread_detach() API
- Set default priority, when user did not specify a value
v7:
Based on DmitryK's review:
- Change thread id representation
- Change mutex id representation
- Implement static mutex inititalizer for Windows
- Change barrier identifier representation
- Improve commit messages
- Add missing doxygen comments
- Split error translation function
- Improve name for affinity function
- Remove cpuset_size parameter
- Fix eal_create_cpu_map function
- Map EAL priority values to OS specific values
- Add thread wrapper for start routine
- Do not export rte_thread_cancel() on Windows
- Cleanup, fix comments, fix typos.
v6:
- improve error-translation function
- call the error translation function in rte_thread_value_get()
v5:
- update cover letter with more details on the priority argument
v4:
- fix function description
- rebase
v3:
- rebase
v2:
- revert changes that break ABI
- break up changes into smaller patches
- fix coding style issues
- fix issues with errors
- fix parameter type in examples/kni.c
Narcisa Vasile (10):
eal: add basic threading functions
eal: add thread attributes
eal/windows: translate Windows errors to errno-style errors
eal: implement functions for thread affinity management
eal: implement thread priority management functions
eal: add thread lifetime management
eal: implement functions for mutex management
eal: implement functions for thread barrier management
eal: add EAL argument for setting thread priority Add unit tests for thread API
app/test/meson.build | 2 + app/test/test_threads.c | 419 ++++++++++++++++++++ lib/eal/common/eal_common_options.c | 28 +- lib/eal/common/eal_internal_cfg.h | 2 + lib/eal/common/eal_options.h | 2 + lib/eal/common/meson.build | 1 + lib/eal/common/rte_thread.c | 445 +++++++++++++++++++++ lib/eal/include/rte_thread.h | 406 ++++++++++++++++++- lib/eal/unix/meson.build | 1 - lib/eal/unix/rte_thread.c | 92 ----- lib/eal/version.map | 20 + lib/eal/windows/eal_lcore.c | 176 ++++++--- lib/eal/windows/eal_windows.h | 10 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 588 ++++++++++++++++++++++++++-- 15 files changed, 2020 insertions(+), 174 deletions(-) create mode 100644 app/test/test_threads.c create mode 100644 lib/eal/common/rte_thread.c delete mode 100644 lib/eal/unix/rte_thread.c
Signature · 1 line
2.31.0.vfs.0.1
PATCH v12 1/10 eal: add basic threading functions
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
---
lib/eal/common/meson.build | 1 +
lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
lib/eal/include/rte_thread.h | 48 +++++++++++++++++-----
lib/eal/unix/meson.build | 1 -
lib/eal/version.map | 3 ++
lib/eal/windows/rte_thread.c | 17 ++++++++
6 files changed, 95 insertions(+), 32 deletions(-)
rename lib/eal/{unix => common}/rte_thread.c (66%)lib/eal/common/meson.build +1 -0
@@ -80,6 +80,7 @@ sources += files( 'rte_random.c', 'rte_reciprocal.c', 'rte_service.c', + 'rte_thread.c', 'rte_version.c', )
lib/eal/common/rte_thread.c renamed from lib/eal/unix/rte_thread.c +35 -22
107 lines not on this page · raw message
lib/eal/include/rte_thread.h +39 -9
83 lines not on this page · raw message
lib/eal/unix/meson.build +0 -1
@@ -6,5 +6,4 @@ sources += files( 'eal_unix_memory.c', 'eal_unix_timer.c', 'eal_firmware.c', - 'rte_thread.c', )
lib/eal/version.map +3 -0
@@ -426,6 +426,9 @@ EXPERIMENTAL { # added in 21.08 rte_power_monitor_multi; # WINDOWS_NO_EXPORT + + rte_thread_self; + rte_thread_equal; }; INTERNAL {
lib/eal/windows/rte_thread.c +17 -0
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright 2021 Mellanox Technologies, Ltd +* Copyright(c) 2021 Microsoft Corporation */ #include <rte_common.h>
@@ -11,6 +12,22 @@ struct eal_tls_key {DWORD thread_index; }; +rte_thread_t +rte_thread_self (void ) +{ +rte_thread_t thread_id; + + thread_id.opaque_id =GetCurrentThreadId (); + +return thread_id; +} + +int +rte_thread_equal (rte_thread_t t1,rte_thread_t t2) +{ +return t1.opaque_id == t2.opaque_id; +} +int rte_thread_key_create (rte_thread_key *key, __rte_unused void (*destructor)(void *))
Signature · 1 line
2.31.0.vfs.0.1
Re: [dpdk-dev] [PATCH v12 01/10] eal: add basic threading functions
lib/eal/common/meson.build
Quoted 18 lines · Narcisa Ana Maria Vasile
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
Signed-off-by Narcisa Vasile <[email protected]>--- lib/eal/common/meson.build | 1 + lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++----------- lib/eal/include/rte_thread.h | 48 +++++++++++++++++----- lib/eal/unix/meson.build | 1 - lib/eal/version.map | 3 ++ lib/eal/windows/rte_thread.c | 17 ++++++++ 6 files changed, 95 insertions(+), 32 deletions(-) rename lib/eal/{unix => common}/rte_thread.c (66%)lib/eal/common/meson.build +0
-0
Hello,
I see the following error on this patch:
ninja: error: loading 'build.ninja': No such file or directory
https://lab.dpdk.org/results/dashboard/patchsets/18090/
Locally, the build succeedes.
How can I see more information about this build error?
Re: [dpdk-dev] [PATCH v12 01/10] eal: add basic threading functions
2021-08-02 14:08 (UTC-0700), Narcisa Ana Maria Vasile:
Quoted 30 lines · Narcisa Ana Maria Vasile
lib/eal/common/meson.build
Quoted 18 lines
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
Signed-off-by Narcisa Vasile <[email protected]>--- lib/eal/common/meson.build | 1 + lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++----------- lib/eal/include/rte_thread.h | 48 +++++++++++++++++----- lib/eal/unix/meson.build | 1 - lib/eal/version.map | 3 ++ lib/eal/windows/rte_thread.c | 17 ++++++++ 6 files changed, 95 insertions(+), 32 deletions(-) rename lib/eal/{unix => common}/rte_thread.c (66%)lib/eal/common/meson.build +0
-0Hello,
I see the following error on this patch:
ninja: error: loading 'build.ninja': No such file or directory
https://lab.dpdk.org/results/dashboard/patchsets/18090/
Locally, the build succeedes.
How can I see more information about this build error?
Re: [dpdk-dev] [dpdk-ci] [PATCH v12 01/10] eal: add basic threading functions
It seems like meson encountered an error when building
app/test/meson.build:472:11: ERROR: Index 1 out of bounds of array of size
Quoted 6 lines
1.
A full log can be found at /home-local/jenkins-local/jenkins-agent/workspace/Apply-Custom-Patch-Set/dpdk/build/meson-logs/meson-log.txt
ninja: error: loading 'build.ninja': No such file or directory
I can also reproduce the issue building locally (Meson version: 0.58.1):
1. Get the DPDK main branch (f12b844b54f4ea7908ecb08ade04c7366ede031d)
2. apply all patches
3. meson $BUILD_DIR
Meson doesn't really give any extra information aside from that, but looking at the build file, it looks like one of the fast_tests has no arguments and at least one is expected.
Quoted 34 lines · Dmitry Kozlyuk
2021-08-02 14:08 (UTC-0700), Narcisa Ana Maria Vasile:
Quoted 30 lines · Narcisa Ana Maria Vasile
lib/eal/common/meson.build
Quoted 18 lines
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
Signed-off-by Narcisa Vasile <[email protected]>--- lib/eal/common/meson.build | 1 + lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++----------- lib/eal/include/rte_thread.h | 48 +++++++++++++++++----- lib/eal/unix/meson.build | 1 - lib/eal/version.map | 3 ++ lib/eal/windows/rte_thread.c | 17 ++++++++ 6 files changed, 95 insertions(+), 32 deletions(-) rename lib/eal/{unix => common}/rte_thread.c (66%)lib/eal/common/meson.build +0
-0Hello,
I see the following error on this patch:
ninja: error: loading 'build.ninja': No such file or directory
https://lab.dpdk.org/results/dashboard/patchsets/18090/
Locally, the build succeedes.
How can I see more information about this build error?
Re: [dpdk-dev] [dpdk-ci] [PATCH v12 01/10] eal: add basic threading functions
2021-08-03 11:11 (UTC-0400), Owen Hilyard:
Quoted 11 lines
It seems like meson encountered an error when building
app/test/meson.build:472:11: ERROR: Index 1 out of bounds of array of size
Quoted 6 lines
1.
A full log can be found at /home-local/jenkins-local/jenkins-agent/workspace/Apply-Custom-Patch-Set/dpdk/build/meson-logs/meson-log.txt
ninja: error: loading 'build.ninja': No such file or directoryI can also reproduce the issue building locally (Meson version: 0.58.1):
Meson 0.58+ has a known issue on Windows:
https://github.com/mesonbuild/meson/issues/8981
The last known good version is 0.57.2.
Quoted 45 lines
1. Get the DPDK main branch (
f12b844b54f4ea7908ecb08ade04c7366ede031d)
2. apply all patches
3. meson $BUILD_DIRMeson doesn't really give any extra information aside from that, but looking at the build file, it looks like one of the
fast_testshas no arguments and at least one is expected.Quoted 34 lines · Dmitry Kozlyuk
2021-08-02 14:08 (UTC-0700), Narcisa Ana Maria Vasile:
Quoted 30 lines · Narcisa Ana Maria Vasile
lib/eal/common/meson.build
Quoted 18 lines
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
Signed-off-by Narcisa Vasile <[email protected]>--- lib/eal/common/meson.build | 1 + lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++----------- lib/eal/include/rte_thread.h | 48 +++++++++++++++++----- lib/eal/unix/meson.build | 1 - lib/eal/version.map | 3 ++ lib/eal/windows/rte_thread.c | 17 ++++++++ 6 files changed, 95 insertions(+), 32 deletions(-) rename lib/eal/{unix => common}/rte_thread.c (66%)lib/eal/common/meson.build +0
-0Hello,
I see the following error on this patch:
ninja: error: loading 'build.ninja': No such file or directory
https://lab.dpdk.org/results/dashboard/patchsets/18090/
Locally, the build succeedes.
How can I see more information about this build error?
Re: [dpdk-dev] [dpdk-ci] [PATCH v12 01/10] eal: add basic threading functions
Our windows servers are both running 0.57.1, but all of the *nix hosts are running 0.58.1. This issue also happens on 0.57.1 and 0.57.2, with the exact same steps to reproduce.
Quoted 69 lines · Dmitry Kozlyuk
2021-08-03 11:11 (UTC-0400), Owen Hilyard:
Quoted 3 lines
It seems like meson encountered an error when building
app/test/meson.build:472:11: ERROR: Index 1 out of bounds of array of
size
Quoted 4 lines
Quoted 4 lines
1.
A full log can be found at
/home-local/jenkins-local/jenkins-agent/workspace/Apply-Custom-Patch-Set/dpdk/build/meson-logs/meson-log.txt
Quoted 4 lines
Quoted 2 lines
ninja: error: loading 'build.ninja': No such file or directory
I can also reproduce the issue building locally (Meson version: 0.58.1):
Meson 0.58+ has a known issue on Windows:
https://github.com/mesonbuild/meson/issues/8981
The last known good version is 0.57.2.Quoted 15 lines
1. Get the DPDK main branch (
f12b844b54f4ea7908ecb08ade04c7366ede031d)
2. apply all patches
3. meson $BUILD_DIRMeson doesn't really give any extra information aside from that, but looking at the build file, it looks like one of the
fast_testshas no arguments and at least one is expected.Quoted 4 lines · Dmitry Kozlyuk
2021-08-02 14:08 (UTC-0700), Narcisa Ana Maria Vasile:
Quoted 1 line
On Mon, Aug 02, 2021 at 10:32:17AM -0700, Narcisa Ana Maria Vasile
Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
Signed-off-by Narcisa Vasile <[email protected]>--- lib/eal/common/meson.build | 1 + lib/eal/{unix => common}/rte_thread.c | 57++++++++++++++++-----------
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 8 lines
lib/eal/include/rte_thread.h | 48 +++++++++++++++++----- lib/eal/unix/meson.build | 1 - lib/eal/version.map | 3 ++ lib/eal/windows/rte_thread.c | 17 ++++++++ 6 files changed, 95 insertions(+), 32 deletions(-) rename lib/eal/{unix => common}/rte_thread.c (66%)(quoted diff) +0
-0b/lib/eal/common/meson.build
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Hello,
I see the following error on this patch:
ninja: error: loading 'build.ninja': No such file or directory
https://lab.dpdk.org/results/dashboard/patchsets/18090/
Locally, the build succeedes.
How can I see more information about this build error?
PATCH v12 2/10 eal: add thread attributes
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.
Priority is represented through an enum that allows for two levels:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
Affinity is described by the rte_cpuset_t type.
An rte_thread_attr_t object can be set to the default values by calling rte_thread_attr_init().
--- lib/eal/common/rte_thread.c | 46 ++++++++++++++++++ lib/eal/include/rte_thread.h | 93 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 44 +++++++++++++++++ 4 files changed, 187 insertions(+)
lib/eal/common/rte_thread.c +46 -0
@@ -9,6 +9,7 @@#include <string.h> #include <rte_common.h> +#include <rte_debug.h> #include <rte_errno.h> #include <rte_log.h> #include <rte_thread.h>
@@ -33,6 +34,51 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_attr_init (rte_thread_attr_t *attr) +{ +RTE_VERIFY (attr !=NULL ); + +CPU_ZERO (&attr->cpuset); + attr->priority =RTE_THREAD_PRIORITY_NORMAL ; + +return 0 ; +} + +int +rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + thread_attr->cpuset = *cpuset; + +return 0 ; +} + +int +rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + *cpuset = thread_attr->cpuset; + +return 0 ; +} + +int +rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, +enum rte_thread_priority priority) +{ +RTE_VERIFY (thread_attr !=NULL ); + + thread_attr->priority = priority; +return 0 ; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +93 -0
105 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -429,6 +429,10 @@ EXPERIMENTAL { rte_thread_self; rte_thread_equal; + rte_thread_attr_init; + rte_thread_attr_get_affinity; + rte_thread_attr_set_affinity; + rte_thread_attr_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v12 3/10 eal/windows: translate Windows errors to errno-style errors
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function to translate Windows error codes to errno-style error codes. The possible return values are chosen so that we have as much semantical compatibility between platforms as possible.
--- lib/eal/common/rte_thread.c | 6 +-- lib/eal/include/rte_thread.h | 5 +- lib/eal/windows/rte_thread.c | 95 +++++++++++++++++++++++++++--------- 3 files changed, 76 insertions(+), 30 deletions(-)
lib/eal/common/rte_thread.c +3 -3
@@ -47,7 +47,7 @@ rte_thread_attr_init(rte_thread_attr_t *attr)int rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -59,7 +59,7 @@ rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -71,7 +71,7 @@ rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, -enum rte_thread_priority priority) +enum rte_thread_priority priority) {RTE_VERIFY (thread_attr !=NULL );
lib/eal/include/rte_thread.h +2 -3
@@ -235,9 +235,8 @@ int rte_thread_value_set(rte_thread_key key, const void *value);* * @return * On success, value data pointer (can also be NULL). -* On failure, NULL and an error number is set in rte_errno. -* rte_errno can be: EINVAL - Invalid parameter passed. -* ENOEXEC - Specific OS error. +* On failure, NULL and a positive error number is set in rte_errno. +* */ __rte_experimental void *rte_thread_value_get(rte_thread_key key);
lib/eal/windows/rte_thread.c +71 -24
165 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v12 4/10 eal: implement functions for thread affinity management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement functions for getting/setting thread affinity. Threads can be pinned to specific cores by setting their affinity attribute.
--- lib/eal/common/rte_thread.c | 16 ++++ lib/eal/include/rte_thread.h | 36 +++++++ lib/eal/version.map | 2 + lib/eal/windows/eal_lcore.c | 176 +++++++++++++++++++++++++--------- lib/eal/windows/eal_windows.h | 10 ++ lib/eal/windows/rte_thread.c | 125 +++++++++++++++++++++++- 6 files changed, 319 insertions(+), 46 deletions(-)
lib/eal/common/rte_thread.c +16 -0
@@ -34,6 +34,22 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_set_affinity_by_id (rte_thread_t thread_id, +const rte_cpuset_t *cpuset) +{ +return pthread_setaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} + +int +rte_thread_get_affinity_by_id (rte_thread_t thread_id, +rte_cpuset_t *cpuset) +{ +return pthread_getaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +36 -0
@@ -87,6 +87,42 @@ int rte_thread_equal(rte_thread_t t1, rte_thread_t t2);#ifdef RTE_HAS_CPUSET +/** +* Set the affinity of thread 'thread_id' to the cpu set +* specified by 'cpuset'. +* +* @param thread_id +* Id of the thread for which to set the affinity. +* +* @param cpuset +* Pointer to CPU affinity to set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_affinity_by_id(rte_thread_t thread_id, +const rte_cpuset_t *cpuset); + +/** +* Get the affinity of thread 'thread_id' and store it +* in 'cpuset'. +* +* @param thread_id +* Id of the thread for which to get the affinity. +* +* @param cpuset +* Pointer for storing the affinity value. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_get_affinity_by_id(rte_thread_t thread_id, +rte_cpuset_t *cpuset); +/** * Initialize the attributes of a thread. * These attributes can be passed to the rte_thread_create() function
lib/eal/version.map +2 -0
@@ -433,6 +433,8 @@ EXPERIMENTAL { rte_thread_attr_get_affinity; rte_thread_attr_set_affinity; rte_thread_attr_set_priority; + rte_thread_get_affinity_by_id; + rte_thread_set_affinity_by_id; }; INTERNAL {
lib/eal/windows/eal_lcore.c +131 -45
231 lines not on this page · raw message
lib/eal/windows/eal_windows.h +10 -0
@@ -55,6 +55,16 @@ int eal_thread_create(pthread_t *thread);*/ unsigned int eal_socket_numa_node (unsigned int socket_id); +/** +* Get pointer to the group affinity for the cpu. +* +* @param cpu_index +* Index of the cpu, as it comes from rte_cpuset_t. +* @return +* Pointer to the group affinity for the cpu. +*/ +PGROUP_AFFINITY eal_get_cpu_affinity (size_t cpu_index); +/** * Schedule code for execution in the interrupt thread. *
lib/eal/windows/rte_thread.c +124 -1
137 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v12 5/10 eal: implement thread priority management functions
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function for setting the priority for a thread. Priorities on multiple platforms are similarly determined by a priority value and a priority class/policy.
On Linux, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* policy SCHED_OTHER
* priority value: (sched_get_priority_min(SCHED_OTHER) +
sched_get_priority_max(SCHED_OTHER))/2;
RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* policy SCHED_RR
* priority value: sched_get_priority_max(SCHED_RR);
On Windows, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* class NORMAL_PRIORITY_CLASS
* priority THREAD_PRIORITY_NORMAL RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* class REALTIME_PRIORITY_CLASS
* priority THREAD_PRIORITY_TIME_CRITICAL
--- lib/eal/common/rte_thread.c | 49 ++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 17 ++++++++++ lib/eal/version.map | 1 + lib/eal/windows/rte_thread.c | 66 ++++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+)
lib/eal/common/rte_thread.c +49 -0
@@ -50,6 +50,55 @@ rte_thread_get_affinity_by_id(rte_thread_t thread_id, sizeof(*cpuset), cpuset); } +static int +thread_map_priority_to_os_value (enum rte_thread_priority eal_pri, +int *os_pri,int *pol) +{ +/* Clear the output parameters */ + *os_pri =sched_get_priority_min (SCHED_OTHER ) -1 ; + *pol =-1 ; + +switch (eal_pri) { +case RTE_THREAD_PRIORITY_NORMAL : + *pol =SCHED_OTHER ; + +/* +* Choose the middle of the range to represent +* the priority 'normal'. +* On Linux, this should be 0, since both +* sched_get_priority_min/_max return 0 for SCHED_OTHER. +*/ + *os_pri = (sched_get_priority_min (SCHED_OTHER ) + +sched_get_priority_max (SCHED_OTHER ))/2 ; +break ; +case RTE_THREAD_PRIORITY_REALTIME_CRITICAL : + *pol =SCHED_RR ; + *os_pri =sched_get_priority_max (SCHED_RR ); +break ; +default : +RTE_LOG (DEBUG ,EAL ,"The requested priority value is invalid.\n" ); +return EINVAL ; + } +return 0 ; +} + +int +rte_thread_set_priority (rte_thread_t thread_id, +enum rte_thread_priority priority) +{ +int ret; +int policy; +struct sched_param param; + + ret =thread_map_priority_to_os_value (priority, ¶m.sched_priority, + &policy); +if (ret !=0 ) +return ret; + +return pthread_setschedparam ((pthread_t )thread_id.opaque_id, + policy, ¶m); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +17 -0
@@ -215,6 +215,23 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp);#endif /* RTE_HAS_CPUSET */ +/** +* Set the priority of a thread. +* +* @param thread_id +* Id of the thread for which to set priority. +* +* @param priority +* Priority value to be set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_priority(rte_thread_t thread_id, +enum rte_thread_priority priority); +/** * Create a TLS data key visible to all threads in the process. * the created key is later used to get/set a value.
lib/eal/version.map +1 -0
@@ -435,6 +435,7 @@ EXPERIMENTAL { rte_thread_attr_set_priority; rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; + rte_thread_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +66 -0
72 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v12 6/10 eal: add thread lifetime management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for thread creation, joining, detaching.
The *rte_thread_create()* function can optionally receive
an rte_thread_attr_t object that will cause the thread to be created with the affinity and priority described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used.
On Windows, the function executed by a thread when the thread starts is represeneted by a function pointer of type DWORD (*func) (void*). On other platforms, the function pointer is a void* (*func) (void*).
Performing a cast between these two types of function pointers to uniformize the API on all platforms may result in undefined behavior. TO fix this issue, a wrapper that respects the signature required by CreateThread() has been created on Windows.
--- lib/eal/common/rte_thread.c | 107 +++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 55 +++++++++++++ lib/eal/version.map | 3 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 138 ++++++++++++++++++++++++++++++++ 5 files changed, 304 insertions(+), 1 deletion(-)
lib/eal/common/rte_thread.c +107 -0
@@ -144,6 +144,113 @@ rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,return 0 ; } +int +rte_thread_create (rte_thread_t *thread_id, +const rte_thread_attr_t *thread_attr, +rte_thread_func thread_func,void *args) +{ +int ret =0 ; +pthread_attr_t attr; +pthread_attr_t *attrp =NULL ; +struct sched_param param = { + .sched_priority =0 , + }; +int policy =SCHED_OTHER ; + +if (thread_attr !=NULL ) { + ret =pthread_attr_init (&attr); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_init failed\n" ); + goto cleanup; + } + + attrp = &attr; + +if (thread_attr->priority !=RTE_THREAD_PRIORITY_UNDEFINED ) { +/* +* Set the inherit scheduler parameter to explicit, +* otherwise the priority attribute is ignored. +*/ + ret =pthread_attr_setinheritsched (attrp, +PTHREAD_EXPLICIT_SCHED ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setinheritsched failed\n" ); + goto cleanup; + } + + ret =thread_map_priority_to_os_value ( + thread_attr->priority, + ¶m.sched_priority, &policy + ); +if (ret !=0 ) + goto cleanup; + + ret =pthread_attr_setschedpolicy (attrp, policy); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedpolicy failed\n" ); + goto cleanup; + } + + ret =pthread_attr_setschedparam (attrp, ¶m); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedparam failed\n" ); + goto cleanup; + } + } + +if (CPU_COUNT (&thread_attr->cpuset) >0 ) { + ret =pthread_attr_setaffinity_np (attrp, +sizeof (thread_attr->cpuset), + &thread_attr->cpuset); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setaffinity_np failed\n" ); + goto cleanup; + } + } + } + + ret =pthread_create ((pthread_t *)&thread_id->opaque_id, attrp, + thread_func, args); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_create failed\n" ); + goto cleanup; + } + +cleanup: +if (attrp !=NULL ) +pthread_attr_destroy (&attr); + +return ret; +} + +int +rte_thread_join (rte_thread_t thread_id,unsigned long *value_ptr) +{ +int ret =0 ; +void *res =NULL ; +void **pres =NULL ; + +if (value_ptr !=NULL ) + pres = &res; + + ret =pthread_join ((pthread_t )thread_id.opaque_id, pres); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_join failed\n" ); +return ret; + } + +if (pres !=NULL ) + *value_ptr = *(unsigned long *)(*pres); + +return 0 ; +} + +int +rte_thread_detach (rte_thread_t thread_id) +{ +return pthread_detach ((pthread_t )thread_id.opaque_id); +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +55 -0
67 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -436,6 +436,9 @@ EXPERIMENTAL { rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; rte_thread_set_priority; + rte_thread_create; + rte_thread_join; + rte_thread_detach; }; INTERNAL {
lib/eal/windows/include/sched.h +1 -1
@@ -44,7 +44,7 @@ typedef struct _rte_cpuset_s { (1LL << _WHICH_BIT(b))) != 0LL)static inline int -count_cpu (rte_cpuset_t *s) +count_cpu (const rte_cpuset_t *s) {unsigned int _i;int count =0 ;
lib/eal/windows/rte_thread.c +138 -0
150 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v12 7/10 eal: implement functions for mutex management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for mutex init, destroy, lock, unlock.
Add RTE_STATIC_MUTEX macro to replace static initialization of mutexes.
Windows does not have a static initializer. Initialization is only done through InitializeCriticalSection().
The RTE_STATIC_MUTEX calls into the rte_thread_mutex_init() function that performs the actual mutex initialization.
--- lib/eal/common/rte_thread.c | 61 +++++++++++++++++++++++ lib/eal/include/rte_thread.h | 94 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 53 ++++++++++++++++++++ 4 files changed, 212 insertions(+)
lib/eal/common/rte_thread.c +61 -0
@@ -251,6 +251,67 @@ rte_thread_detach(rte_thread_t thread_id)return pthread_detach ((pthread_t )thread_id.opaque_id); } +int +rte_thread_mutex_init (rte_thread_mutex *mutex) +{ +int ret =0 ; +pthread_mutex_t *m =NULL ; + +RTE_VERIFY (mutex !=NULL ); + + m =calloc (1 ,sizeof (*m)); +if (m ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize mutex. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + + ret =pthread_mutex_init (m,NULL ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init mutex. ret = %d\n" , ret); + goto cleanup; + } + + mutex->mutex_id = m; + m =NULL ; + +cleanup: +free (m); +return ret; +} + +int +rte_thread_mutex_lock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_lock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_unlock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_unlock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_destroy (rte_thread_mutex *mutex) +{ +int ret =0 ; +RTE_VERIFY (mutex !=NULL ); + + ret =pthread_mutex_destroy ((pthread_mutex_t *)mutex->mutex_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Unable to destroy mutex, ret = %d\n" , ret); + +free (mutex->mutex_id); + mutex->mutex_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +94 -0
112 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -439,6 +439,10 @@ EXPERIMENTAL { rte_thread_create; rte_thread_join; rte_thread_detach; + rte_thread_mutex_init; + rte_thread_mutex_lock; + rte_thread_mutex_unlock; + rte_thread_mutex_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +53 -0
59 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v12 8/10 eal: implement functions for thread barrier management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for barrier init, destroy, wait.
A portable type is used to represent a barrier identifier. The rte_thread_barrier_wait() function returns the same value on all platforms.
--- lib/eal/common/rte_thread.c | 61 ++++++++++++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 58 ++++++++++++++++++++++++++++++++++ lib/eal/version.map | 3 ++ lib/eal/windows/rte_thread.c | 56 +++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+)
lib/eal/common/rte_thread.c +61 -0
@@ -312,6 +312,67 @@ rte_thread_mutex_destroy(rte_thread_mutex *mutex)return ret; } +int +rte_thread_barrier_init (rte_thread_barrier *barrier,int count) +{ +int ret =0 ; +pthread_barrier_t *pthread_barrier =NULL ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (count >0 ); + + pthread_barrier =calloc (1 ,sizeof (*pthread_barrier)); +if (pthread_barrier ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize barrier. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + ret =pthread_barrier_init (pthread_barrier,NULL , count); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init barrier, ret = %d\n" , ret); + goto cleanup; + } + + barrier->barrier_id = pthread_barrier; + pthread_barrier =NULL ; + +cleanup: +free (pthread_barrier); +return ret; +} + +int +rte_thread_barrier_wait (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (barrier->barrier_id !=NULL ); + + ret =pthread_barrier_wait (barrier->barrier_id); +if (ret ==PTHREAD_BARRIER_SERIAL_THREAD ) + ret =RTE_THREAD_BARRIER_SERIAL_THREAD ; + +return ret; +} + +int +rte_thread_barrier_destroy (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); + + ret =pthread_barrier_destroy (barrier->barrier_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Failed to destroy barrier: %d\n" , ret); + +free (barrier->barrier_id); + barrier->barrier_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +58 -0
70 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -443,6 +443,9 @@ EXPERIMENTAL { rte_thread_mutex_lock; rte_thread_mutex_unlock; rte_thread_mutex_destroy; + rte_thread_barrier_init; + rte_thread_barrier_wait; + rte_thread_barrier_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v12 9/10 eal: add EAL argument for setting thread priority
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Allow the user to choose the thread priority through an EAL command line argument.
The user can choose thread priority through an EAL parameter, when starting an application. If EAL parameter is not used, the per-platform default value for thread priority is used. Otherwise administrator has an option to set one of available options:
--thread-prio normal
--thread-prio realtime
Example:
./dpdk-l2fwd -l 0-3 -n 4 --thread-prio normal -- -q 8 -p ffff
--- lib/eal/common/eal_common_options.c | 28 +++++++++++++++++++++++++++- lib/eal/common/eal_internal_cfg.h | 2 ++ lib/eal/common/eal_options.h | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-)
lib/eal/common/eal_common_options.c +27 -1
@@ -107,6 +107,7 @@ eal_long_options[] = { {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM }, {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM }, {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM}, + {OPT_THREAD_PRIORITY, 1, NULL, OPT_THREAD_PRIORITY_NUM},/* legacy options that will be removed in future */ {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
@@ -1412,6 +1413,24 @@ eal_parse_simd_bitwidth(const char *arg)return 0 ; } +static int +eal_parse_thread_priority (const char *arg) +{ +struct internal_config *internal_conf = +eal_get_internal_configuration (); +enum rte_thread_priority priority; + +if (!strncmp ("normal" , arg,sizeof ("normal" ))) + priority =RTE_THREAD_PRIORITY_NORMAL ; +else if (!strncmp ("realtime" , arg,sizeof ("realtime" ))) + priority =RTE_THREAD_PRIORITY_REALTIME_CRITICAL ; +else +return -1 ; + + internal_conf->thread_priority = priority; +return 0 ; +} +static int eal_parse_base_virtaddr (const char *arg) {
@@ -1825,7 +1844,13 @@ eal_parse_common_option(int opt, const char *optarg,return -1 ; }break ; - +case OPT_THREAD_PRIORITY_NUM : +if (eal_parse_thread_priority (optarg) <0 ) { +RTE_LOG (ERR ,EAL ,"invalid parameter for --" +OPT_THREAD_PRIORITY "\n" ); +return -1 ; + } +break ;/* don't know what to do, leave this to caller */ default :return 1 ;
@@ -2088,6 +2113,7 @@ eal_common_usage(void)" (can be used multiple times)\n" " --" OPT_VMWARE_TSC_MAP " Use VMware TSC map instead of native RDTSC\n" " --" OPT_PROC_TYPE " Type of this process (primary|secondary|auto)\n" +" --" OPT_THREAD_PRIORITY " Set threads priority (normal|realtime)\n" #ifndef RTE_EXEC_ENV_WINDOWS" --" OPT_SYSLOG " Set syslog facility\n" #endif
lib/eal/common/eal_internal_cfg.h +2 -0
@@ -94,6 +94,8 @@ struct internal_config {unsigned int no_telemetry;/**< true to disable Telemetry */ struct simd_bitwidth max_simd_bitwidth;/**< max simd bitwidth path to use */ +enum rte_thread_priority thread_priority; +/**< thread priority to configure */ };void eal_reset_internal_config (struct internal_config *internal_cfg);
lib/eal/common/eal_options.h +2 -0
@@ -93,6 +93,8 @@ enum {OPT_NO_TELEMETRY_NUM , #define OPT_FORCE_MAX_SIMD_BITWIDTH "force-max-simd-bitwidth"OPT_FORCE_MAX_SIMD_BITWIDTH_NUM , +#define OPT_THREAD_PRIORITY "thread-prio" +OPT_THREAD_PRIORITY_NUM ,/* legacy option that will be removed in future */ #define OPT_PCI_BLACKLIST "pci-blacklist"
Signature · 1 line
2.31.0.vfs.0.1
PATCH v12 10/10 Add unit tests for thread API
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
As a new API for threading is introduced,
a set of unit tests have been added to test the new interface.
--- app/test/meson.build | 2 + app/test/test_threads.c | 419 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 421 insertions(+) create mode 100644 app/test/test_threads.c
app/test/meson.build +2 -0
@@ -140,6 +140,7 @@ test_sources = files( 'test_table_tables.c', 'test_tailq.c', 'test_thash.c', + 'test_threads.c', 'test_timer.c', 'test_timer_perf.c', 'test_timer_racecond.c',
@@ -276,6 +277,7 @@ fast_tests = [ ['reorder_autotest', true], ['service_autotest', true], ['thash_autotest', true], + ['threads_autotest, true'], ['trace_autotest', true], ]
app/test/test_threads.c new file +419 -0
419 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
v13 cover eal: Add EAL API for threading
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
EAL thread API
**Problem Statement**
DPDK currently uses the pthread interface to create and manage threads. Windows does not support the POSIX thread programming model, so it currently
relies on a header file that hides the Windows calls under pthread matched interfaces. Given that EAL should isolate the environment specifics from the applications and libraries and mediate
all the communication with the operating systems, a new EAL interface is needed for thread management.
**Goals**
* Introduce a generic EAL API for threading support that will remove the current Windows pthread.h shim.
* Replace references to pthread_* across the DPDK codebase with the new RTE_THREAD_* API.
* Allow users to choose between using the RTE_THREAD_* API or a 3rd party thread library through a configuration option.
**Design plan**
New API main files:
* rte_thread.h (librte_eal/include)
* rte_thread.c (librte_eal/windows)
* rte_thread.c (librte_eal/common)
**A schematic example of the design**
--------------------------------------------------lib/librte_eal/include/rte_thread.h
int rte_thread_create();
lib/librte_eal/common/rte_thread.c
int rte_thread_create()
{
return pthread_create();
}lib/librte_eal/windows/rte_thread.c
int rte_thread_create()
{
return CreateThread();
}-----------------------------------------------------
**Thread attributes**
When or after a thread is created, specific characteristics of the thread can be adjusted. Given that the thread characteristics that are of interest for DPDK applications are affinity and priority, the following structure that represents thread attributes has been defined:
typedef struct
{
enum rte_thread_priority priority;
rte_cpuset_t cpuset;
} rte_thread_attr_t;The *rte_thread_create()* function can optionally receive an rte_thread_attr_t
object that will cause the thread to be created with the affinity and priority
described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used. An rte_thread_attr_t object can also be set to the default values by calling *rte_thread_attr_init()*.
*Priority* is represented through an enum that currently advertises two values for priority:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
The enum can be extended to allow for multiple priority levels.rte_thread_set_priority - sets the priority of a threadrte_thread_attr_set_priority - updates an rte_thread_attr_t object
with a new value for priority
The user can choose thread priority through an EAL parameter, when starting an application. If EAL parameter is not used, the per-platform default value for thread priority is used. Otherwise administrator has an option to set one of available options:
--thread-prio normal
--thread-prio realtime
Example:
./dpdk-l2fwd -l 0-3 -n 4 –thread-prio normal -- -q 8 -p ffff
*Affinity* is described by the already known “rte_cpuset_t” type. rte_thread_attr_set/get_affinity - sets/gets the affinity field in a
rte_thread_attr_t object
rte_thread_set/get_affinity – sets/gets the affinity of a thread
**Errors**
A translation function that maps Windows error codes to errno-style error codes is provided.
**Future work**
The long term plan is for EAL to provide full threading support:
* Add support for conditional variables
* Add support for pthread_mutex_trylock
* Additional functionality offered by pthread_*
(such as pthread_setname_np, etc.)
v13:
- Fix syntax error in unit tests
v12:
- Fix freebsd warning about initializer in unit tests
v11:
- Add unit tests for thread API
- Rebase
v10:
- Remove patch no. 10. It will be broken down in subpatches and sent as a different patchset that depends on this one. This is done due to the ABI breaks that would be caused by patch 10.
- Replace unix/rte_thread.c with common/rte_thread.c
- Remove initializations that may prevent compiler from issuing useful warnings.
- Remove rte_thread_types.h and rte_windows_thread_types.h
- Remove unneeded priority macros (EAL_THREAD_PRIORITY*)
- Remove functions that retrieves thread handle from process handle
- Remove rte_thread_cancel() until same behavior is obtained on all platforms.
- Fix rte_thread_detach() function description,
return value and remove empty line.
- Reimplement mutex functions. Add compatible representation for mutex identifier. Add macro to replace static mutex initialization instances.
- Fix commit messages (lines too long, remove unicode symbols)
v9:
- Sign patches
v8:
- Rebase
- Add rte_thread_detach() API
- Set default priority, when user did not specify a value
v7:
Based on DmitryK's review:
- Change thread id representation
- Change mutex id representation
- Implement static mutex inititalizer for Windows
- Change barrier identifier representation
- Improve commit messages
- Add missing doxygen comments
- Split error translation function
- Improve name for affinity function
- Remove cpuset_size parameter
- Fix eal_create_cpu_map function
- Map EAL priority values to OS specific values
- Add thread wrapper for start routine
- Do not export rte_thread_cancel() on Windows
- Cleanup, fix comments, fix typos.
v6:
- improve error-translation function
- call the error translation function in rte_thread_value_get()
v5:
- update cover letter with more details on the priority argument
v4:
- fix function description
- rebase
v3:
- rebase
v2:
- revert changes that break ABI
- break up changes into smaller patches
- fix coding style issues
- fix issues with errors
- fix parameter type in examples/kni.c
Narcisa Vasile (10):
eal: add basic threading functions
eal: add thread attributes
eal/windows: translate Windows errors to errno-style errors
eal: implement functions for thread affinity management
eal: implement thread priority management functions
eal: add thread lifetime management
eal: implement functions for mutex management
eal: implement functions for thread barrier management
eal: add EAL argument for setting thread priority Add unit tests for thread API
app/test/meson.build | 2 + app/test/test_threads.c | 419 ++++++++++++++++++++ lib/eal/common/eal_common_options.c | 28 +- lib/eal/common/eal_internal_cfg.h | 2 + lib/eal/common/eal_options.h | 2 + lib/eal/common/meson.build | 1 + lib/eal/common/rte_thread.c | 445 +++++++++++++++++++++ lib/eal/include/rte_thread.h | 406 ++++++++++++++++++- lib/eal/unix/meson.build | 1 - lib/eal/unix/rte_thread.c | 92 ----- lib/eal/version.map | 20 + lib/eal/windows/eal_lcore.c | 176 ++++++--- lib/eal/windows/eal_windows.h | 10 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 588 ++++++++++++++++++++++++++-- 15 files changed, 2020 insertions(+), 174 deletions(-) create mode 100644 app/test/test_threads.c create mode 100644 lib/eal/common/rte_thread.c delete mode 100644 lib/eal/unix/rte_thread.c
Signature · 1 line
2.31.0.vfs.0.1
PATCH v13 1/10 eal: add basic threading functions
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
---
lib/eal/common/meson.build | 1 +
lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
lib/eal/include/rte_thread.h | 48 +++++++++++++++++-----
lib/eal/unix/meson.build | 1 -
lib/eal/version.map | 3 ++
lib/eal/windows/rte_thread.c | 17 ++++++++
6 files changed, 95 insertions(+), 32 deletions(-)
rename lib/eal/{unix => common}/rte_thread.c (66%)lib/eal/common/meson.build +1 -0
@@ -80,6 +80,7 @@ sources += files( 'rte_random.c', 'rte_reciprocal.c', 'rte_service.c', + 'rte_thread.c', 'rte_version.c', )
lib/eal/common/rte_thread.c renamed from lib/eal/unix/rte_thread.c +35 -22
107 lines not on this page · raw message
lib/eal/include/rte_thread.h +39 -9
83 lines not on this page · raw message
lib/eal/unix/meson.build +0 -1
@@ -6,5 +6,4 @@ sources += files( 'eal_unix_memory.c', 'eal_unix_timer.c', 'eal_firmware.c', - 'rte_thread.c', )
lib/eal/version.map +3 -0
@@ -426,6 +426,9 @@ EXPERIMENTAL { # added in 21.08 rte_power_monitor_multi; # WINDOWS_NO_EXPORT + + rte_thread_self; + rte_thread_equal; }; INTERNAL {
lib/eal/windows/rte_thread.c +17 -0
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright 2021 Mellanox Technologies, Ltd +* Copyright(c) 2021 Microsoft Corporation */ #include <rte_common.h>
@@ -11,6 +12,22 @@ struct eal_tls_key {DWORD thread_index; }; +rte_thread_t +rte_thread_self (void ) +{ +rte_thread_t thread_id; + + thread_id.opaque_id =GetCurrentThreadId (); + +return thread_id; +} + +int +rte_thread_equal (rte_thread_t t1,rte_thread_t t2) +{ +return t1.opaque_id == t2.opaque_id; +} +int rte_thread_key_create (rte_thread_key *key, __rte_unused void (*destructor)(void *))
Signature · 1 line
2.31.0.vfs.0.1
PATCH v13 2/10 eal: add thread attributes
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.
Priority is represented through an enum that allows for two levels:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
Affinity is described by the rte_cpuset_t type.
An rte_thread_attr_t object can be set to the default values by calling rte_thread_attr_init().
--- lib/eal/common/rte_thread.c | 46 ++++++++++++++++++ lib/eal/include/rte_thread.h | 93 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 44 +++++++++++++++++ 4 files changed, 187 insertions(+)
lib/eal/common/rte_thread.c +46 -0
@@ -9,6 +9,7 @@#include <string.h> #include <rte_common.h> +#include <rte_debug.h> #include <rte_errno.h> #include <rte_log.h> #include <rte_thread.h>
@@ -33,6 +34,51 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_attr_init (rte_thread_attr_t *attr) +{ +RTE_VERIFY (attr !=NULL ); + +CPU_ZERO (&attr->cpuset); + attr->priority =RTE_THREAD_PRIORITY_NORMAL ; + +return 0 ; +} + +int +rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + thread_attr->cpuset = *cpuset; + +return 0 ; +} + +int +rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + *cpuset = thread_attr->cpuset; + +return 0 ; +} + +int +rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, +enum rte_thread_priority priority) +{ +RTE_VERIFY (thread_attr !=NULL ); + + thread_attr->priority = priority; +return 0 ; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +93 -0
105 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -429,6 +429,10 @@ EXPERIMENTAL { rte_thread_self; rte_thread_equal; + rte_thread_attr_init; + rte_thread_attr_get_affinity; + rte_thread_attr_set_affinity; + rte_thread_attr_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v13 3/10 eal/windows: translate Windows errors to errno-style errors
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function to translate Windows error codes to errno-style error codes. The possible return values are chosen so that we have as much semantical compatibility between platforms as possible.
--- lib/eal/common/rte_thread.c | 6 +-- lib/eal/include/rte_thread.h | 5 +- lib/eal/windows/rte_thread.c | 95 +++++++++++++++++++++++++++--------- 3 files changed, 76 insertions(+), 30 deletions(-)
lib/eal/common/rte_thread.c +3 -3
@@ -47,7 +47,7 @@ rte_thread_attr_init(rte_thread_attr_t *attr)int rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -59,7 +59,7 @@ rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -71,7 +71,7 @@ rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, -enum rte_thread_priority priority) +enum rte_thread_priority priority) {RTE_VERIFY (thread_attr !=NULL );
lib/eal/include/rte_thread.h +2 -3
@@ -235,9 +235,8 @@ int rte_thread_value_set(rte_thread_key key, const void *value);* * @return * On success, value data pointer (can also be NULL). -* On failure, NULL and an error number is set in rte_errno. -* rte_errno can be: EINVAL - Invalid parameter passed. -* ENOEXEC - Specific OS error. +* On failure, NULL and a positive error number is set in rte_errno. +* */ __rte_experimental void *rte_thread_value_get(rte_thread_key key);
lib/eal/windows/rte_thread.c +71 -24
165 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v13 4/10 eal: implement functions for thread affinity management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement functions for getting/setting thread affinity. Threads can be pinned to specific cores by setting their affinity attribute.
--- lib/eal/common/rte_thread.c | 16 ++++ lib/eal/include/rte_thread.h | 36 +++++++ lib/eal/version.map | 2 + lib/eal/windows/eal_lcore.c | 176 +++++++++++++++++++++++++--------- lib/eal/windows/eal_windows.h | 10 ++ lib/eal/windows/rte_thread.c | 125 +++++++++++++++++++++++- 6 files changed, 319 insertions(+), 46 deletions(-)
lib/eal/common/rte_thread.c +16 -0
@@ -34,6 +34,22 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_set_affinity_by_id (rte_thread_t thread_id, +const rte_cpuset_t *cpuset) +{ +return pthread_setaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} + +int +rte_thread_get_affinity_by_id (rte_thread_t thread_id, +rte_cpuset_t *cpuset) +{ +return pthread_getaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +36 -0
@@ -87,6 +87,42 @@ int rte_thread_equal(rte_thread_t t1, rte_thread_t t2);#ifdef RTE_HAS_CPUSET +/** +* Set the affinity of thread 'thread_id' to the cpu set +* specified by 'cpuset'. +* +* @param thread_id +* Id of the thread for which to set the affinity. +* +* @param cpuset +* Pointer to CPU affinity to set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_affinity_by_id(rte_thread_t thread_id, +const rte_cpuset_t *cpuset); + +/** +* Get the affinity of thread 'thread_id' and store it +* in 'cpuset'. +* +* @param thread_id +* Id of the thread for which to get the affinity. +* +* @param cpuset +* Pointer for storing the affinity value. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_get_affinity_by_id(rte_thread_t thread_id, +rte_cpuset_t *cpuset); +/** * Initialize the attributes of a thread. * These attributes can be passed to the rte_thread_create() function
lib/eal/version.map +2 -0
@@ -433,6 +433,8 @@ EXPERIMENTAL { rte_thread_attr_get_affinity; rte_thread_attr_set_affinity; rte_thread_attr_set_priority; + rte_thread_get_affinity_by_id; + rte_thread_set_affinity_by_id; }; INTERNAL {
lib/eal/windows/eal_lcore.c +131 -45
231 lines not on this page · raw message
lib/eal/windows/eal_windows.h +10 -0
@@ -55,6 +55,16 @@ int eal_thread_create(pthread_t *thread);*/ unsigned int eal_socket_numa_node (unsigned int socket_id); +/** +* Get pointer to the group affinity for the cpu. +* +* @param cpu_index +* Index of the cpu, as it comes from rte_cpuset_t. +* @return +* Pointer to the group affinity for the cpu. +*/ +PGROUP_AFFINITY eal_get_cpu_affinity (size_t cpu_index); +/** * Schedule code for execution in the interrupt thread. *
lib/eal/windows/rte_thread.c +124 -1
137 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v13 5/10 eal: implement thread priority management functions
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function for setting the priority for a thread. Priorities on multiple platforms are similarly determined by a priority value and a priority class/policy.
On Linux, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* policy SCHED_OTHER
* priority value: (sched_get_priority_min(SCHED_OTHER) +
sched_get_priority_max(SCHED_OTHER))/2;
RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* policy SCHED_RR
* priority value: sched_get_priority_max(SCHED_RR);
On Windows, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* class NORMAL_PRIORITY_CLASS
* priority THREAD_PRIORITY_NORMAL RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* class REALTIME_PRIORITY_CLASS
* priority THREAD_PRIORITY_TIME_CRITICAL
--- lib/eal/common/rte_thread.c | 49 ++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 17 ++++++++++ lib/eal/version.map | 1 + lib/eal/windows/rte_thread.c | 66 ++++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+)
lib/eal/common/rte_thread.c +49 -0
@@ -50,6 +50,55 @@ rte_thread_get_affinity_by_id(rte_thread_t thread_id, sizeof(*cpuset), cpuset); } +static int +thread_map_priority_to_os_value (enum rte_thread_priority eal_pri, +int *os_pri,int *pol) +{ +/* Clear the output parameters */ + *os_pri =sched_get_priority_min (SCHED_OTHER ) -1 ; + *pol =-1 ; + +switch (eal_pri) { +case RTE_THREAD_PRIORITY_NORMAL : + *pol =SCHED_OTHER ; + +/* +* Choose the middle of the range to represent +* the priority 'normal'. +* On Linux, this should be 0, since both +* sched_get_priority_min/_max return 0 for SCHED_OTHER. +*/ + *os_pri = (sched_get_priority_min (SCHED_OTHER ) + +sched_get_priority_max (SCHED_OTHER ))/2 ; +break ; +case RTE_THREAD_PRIORITY_REALTIME_CRITICAL : + *pol =SCHED_RR ; + *os_pri =sched_get_priority_max (SCHED_RR ); +break ; +default : +RTE_LOG (DEBUG ,EAL ,"The requested priority value is invalid.\n" ); +return EINVAL ; + } +return 0 ; +} + +int +rte_thread_set_priority (rte_thread_t thread_id, +enum rte_thread_priority priority) +{ +int ret; +int policy; +struct sched_param param; + + ret =thread_map_priority_to_os_value (priority, ¶m.sched_priority, + &policy); +if (ret !=0 ) +return ret; + +return pthread_setschedparam ((pthread_t )thread_id.opaque_id, + policy, ¶m); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +17 -0
@@ -215,6 +215,23 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp);#endif /* RTE_HAS_CPUSET */ +/** +* Set the priority of a thread. +* +* @param thread_id +* Id of the thread for which to set priority. +* +* @param priority +* Priority value to be set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_priority(rte_thread_t thread_id, +enum rte_thread_priority priority); +/** * Create a TLS data key visible to all threads in the process. * the created key is later used to get/set a value.
lib/eal/version.map +1 -0
@@ -435,6 +435,7 @@ EXPERIMENTAL { rte_thread_attr_set_priority; rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; + rte_thread_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +66 -0
72 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v13 6/10 eal: add thread lifetime management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for thread creation, joining, detaching.
The *rte_thread_create()* function can optionally receive
an rte_thread_attr_t object that will cause the thread to be created with the affinity and priority described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used.
On Windows, the function executed by a thread when the thread starts is represeneted by a function pointer of type DWORD (*func) (void*). On other platforms, the function pointer is a void* (*func) (void*).
Performing a cast between these two types of function pointers to uniformize the API on all platforms may result in undefined behavior. TO fix this issue, a wrapper that respects the signature required by CreateThread() has been created on Windows.
--- lib/eal/common/rte_thread.c | 107 +++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 55 +++++++++++++ lib/eal/version.map | 3 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 138 ++++++++++++++++++++++++++++++++ 5 files changed, 304 insertions(+), 1 deletion(-)
lib/eal/common/rte_thread.c +107 -0
@@ -144,6 +144,113 @@ rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,return 0 ; } +int +rte_thread_create (rte_thread_t *thread_id, +const rte_thread_attr_t *thread_attr, +rte_thread_func thread_func,void *args) +{ +int ret =0 ; +pthread_attr_t attr; +pthread_attr_t *attrp =NULL ; +struct sched_param param = { + .sched_priority =0 , + }; +int policy =SCHED_OTHER ; + +if (thread_attr !=NULL ) { + ret =pthread_attr_init (&attr); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_init failed\n" ); + goto cleanup; + } + + attrp = &attr; + +if (thread_attr->priority !=RTE_THREAD_PRIORITY_UNDEFINED ) { +/* +* Set the inherit scheduler parameter to explicit, +* otherwise the priority attribute is ignored. +*/ + ret =pthread_attr_setinheritsched (attrp, +PTHREAD_EXPLICIT_SCHED ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setinheritsched failed\n" ); + goto cleanup; + } + + ret =thread_map_priority_to_os_value ( + thread_attr->priority, + ¶m.sched_priority, &policy + ); +if (ret !=0 ) + goto cleanup; + + ret =pthread_attr_setschedpolicy (attrp, policy); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedpolicy failed\n" ); + goto cleanup; + } + + ret =pthread_attr_setschedparam (attrp, ¶m); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedparam failed\n" ); + goto cleanup; + } + } + +if (CPU_COUNT (&thread_attr->cpuset) >0 ) { + ret =pthread_attr_setaffinity_np (attrp, +sizeof (thread_attr->cpuset), + &thread_attr->cpuset); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setaffinity_np failed\n" ); + goto cleanup; + } + } + } + + ret =pthread_create ((pthread_t *)&thread_id->opaque_id, attrp, + thread_func, args); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_create failed\n" ); + goto cleanup; + } + +cleanup: +if (attrp !=NULL ) +pthread_attr_destroy (&attr); + +return ret; +} + +int +rte_thread_join (rte_thread_t thread_id,unsigned long *value_ptr) +{ +int ret =0 ; +void *res =NULL ; +void **pres =NULL ; + +if (value_ptr !=NULL ) + pres = &res; + + ret =pthread_join ((pthread_t )thread_id.opaque_id, pres); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_join failed\n" ); +return ret; + } + +if (pres !=NULL ) + *value_ptr = *(unsigned long *)(*pres); + +return 0 ; +} + +int +rte_thread_detach (rte_thread_t thread_id) +{ +return pthread_detach ((pthread_t )thread_id.opaque_id); +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +55 -0
67 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -436,6 +436,9 @@ EXPERIMENTAL { rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; rte_thread_set_priority; + rte_thread_create; + rte_thread_join; + rte_thread_detach; }; INTERNAL {
lib/eal/windows/include/sched.h +1 -1
@@ -44,7 +44,7 @@ typedef struct _rte_cpuset_s { (1LL << _WHICH_BIT(b))) != 0LL)static inline int -count_cpu (rte_cpuset_t *s) +count_cpu (const rte_cpuset_t *s) {unsigned int _i;int count =0 ;
lib/eal/windows/rte_thread.c +138 -0
150 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v13 7/10 eal: implement functions for mutex management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for mutex init, destroy, lock, unlock.
Add RTE_STATIC_MUTEX macro to replace static initialization of mutexes.
Windows does not have a static initializer. Initialization is only done through InitializeCriticalSection().
The RTE_STATIC_MUTEX calls into the rte_thread_mutex_init() function that performs the actual mutex initialization.
--- lib/eal/common/rte_thread.c | 61 +++++++++++++++++++++++ lib/eal/include/rte_thread.h | 94 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 53 ++++++++++++++++++++ 4 files changed, 212 insertions(+)
lib/eal/common/rte_thread.c +61 -0
@@ -251,6 +251,67 @@ rte_thread_detach(rte_thread_t thread_id)return pthread_detach ((pthread_t )thread_id.opaque_id); } +int +rte_thread_mutex_init (rte_thread_mutex *mutex) +{ +int ret =0 ; +pthread_mutex_t *m =NULL ; + +RTE_VERIFY (mutex !=NULL ); + + m =calloc (1 ,sizeof (*m)); +if (m ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize mutex. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + + ret =pthread_mutex_init (m,NULL ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init mutex. ret = %d\n" , ret); + goto cleanup; + } + + mutex->mutex_id = m; + m =NULL ; + +cleanup: +free (m); +return ret; +} + +int +rte_thread_mutex_lock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_lock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_unlock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_unlock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_destroy (rte_thread_mutex *mutex) +{ +int ret =0 ; +RTE_VERIFY (mutex !=NULL ); + + ret =pthread_mutex_destroy ((pthread_mutex_t *)mutex->mutex_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Unable to destroy mutex, ret = %d\n" , ret); + +free (mutex->mutex_id); + mutex->mutex_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +94 -0
112 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -439,6 +439,10 @@ EXPERIMENTAL { rte_thread_create; rte_thread_join; rte_thread_detach; + rte_thread_mutex_init; + rte_thread_mutex_lock; + rte_thread_mutex_unlock; + rte_thread_mutex_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +53 -0
59 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v13 8/10 eal: implement functions for thread barrier management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for barrier init, destroy, wait.
A portable type is used to represent a barrier identifier. The rte_thread_barrier_wait() function returns the same value on all platforms.
--- lib/eal/common/rte_thread.c | 61 ++++++++++++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 58 ++++++++++++++++++++++++++++++++++ lib/eal/version.map | 3 ++ lib/eal/windows/rte_thread.c | 56 +++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+)
lib/eal/common/rte_thread.c +61 -0
@@ -312,6 +312,67 @@ rte_thread_mutex_destroy(rte_thread_mutex *mutex)return ret; } +int +rte_thread_barrier_init (rte_thread_barrier *barrier,int count) +{ +int ret =0 ; +pthread_barrier_t *pthread_barrier =NULL ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (count >0 ); + + pthread_barrier =calloc (1 ,sizeof (*pthread_barrier)); +if (pthread_barrier ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize barrier. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + ret =pthread_barrier_init (pthread_barrier,NULL , count); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init barrier, ret = %d\n" , ret); + goto cleanup; + } + + barrier->barrier_id = pthread_barrier; + pthread_barrier =NULL ; + +cleanup: +free (pthread_barrier); +return ret; +} + +int +rte_thread_barrier_wait (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (barrier->barrier_id !=NULL ); + + ret =pthread_barrier_wait (barrier->barrier_id); +if (ret ==PTHREAD_BARRIER_SERIAL_THREAD ) + ret =RTE_THREAD_BARRIER_SERIAL_THREAD ; + +return ret; +} + +int +rte_thread_barrier_destroy (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); + + ret =pthread_barrier_destroy (barrier->barrier_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Failed to destroy barrier: %d\n" , ret); + +free (barrier->barrier_id); + barrier->barrier_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +58 -0
70 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -443,6 +443,9 @@ EXPERIMENTAL { rte_thread_mutex_lock; rte_thread_mutex_unlock; rte_thread_mutex_destroy; + rte_thread_barrier_init; + rte_thread_barrier_wait; + rte_thread_barrier_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v13 9/10 eal: add EAL argument for setting thread priority
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Allow the user to choose the thread priority through an EAL command line argument.
The user can choose thread priority through an EAL parameter, when starting an application. If EAL parameter is not used, the per-platform default value for thread priority is used. Otherwise administrator has an option to set one of available options:
--thread-prio normal
--thread-prio realtime
Example:
./dpdk-l2fwd -l 0-3 -n 4 --thread-prio normal -- -q 8 -p ffff
--- lib/eal/common/eal_common_options.c | 28 +++++++++++++++++++++++++++- lib/eal/common/eal_internal_cfg.h | 2 ++ lib/eal/common/eal_options.h | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-)
lib/eal/common/eal_common_options.c +27 -1
@@ -107,6 +107,7 @@ eal_long_options[] = { {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM }, {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM }, {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM}, + {OPT_THREAD_PRIORITY, 1, NULL, OPT_THREAD_PRIORITY_NUM},/* legacy options that will be removed in future */ {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
@@ -1412,6 +1413,24 @@ eal_parse_simd_bitwidth(const char *arg)return 0 ; } +static int +eal_parse_thread_priority (const char *arg) +{ +struct internal_config *internal_conf = +eal_get_internal_configuration (); +enum rte_thread_priority priority; + +if (!strncmp ("normal" , arg,sizeof ("normal" ))) + priority =RTE_THREAD_PRIORITY_NORMAL ; +else if (!strncmp ("realtime" , arg,sizeof ("realtime" ))) + priority =RTE_THREAD_PRIORITY_REALTIME_CRITICAL ; +else +return -1 ; + + internal_conf->thread_priority = priority; +return 0 ; +} +static int eal_parse_base_virtaddr (const char *arg) {
@@ -1825,7 +1844,13 @@ eal_parse_common_option(int opt, const char *optarg,return -1 ; }break ; - +case OPT_THREAD_PRIORITY_NUM : +if (eal_parse_thread_priority (optarg) <0 ) { +RTE_LOG (ERR ,EAL ,"invalid parameter for --" +OPT_THREAD_PRIORITY "\n" ); +return -1 ; + } +break ;/* don't know what to do, leave this to caller */ default :return 1 ;
@@ -2088,6 +2113,7 @@ eal_common_usage(void)" (can be used multiple times)\n" " --" OPT_VMWARE_TSC_MAP " Use VMware TSC map instead of native RDTSC\n" " --" OPT_PROC_TYPE " Type of this process (primary|secondary|auto)\n" +" --" OPT_THREAD_PRIORITY " Set threads priority (normal|realtime)\n" #ifndef RTE_EXEC_ENV_WINDOWS" --" OPT_SYSLOG " Set syslog facility\n" #endif
lib/eal/common/eal_internal_cfg.h +2 -0
@@ -94,6 +94,8 @@ struct internal_config {unsigned int no_telemetry;/**< true to disable Telemetry */ struct simd_bitwidth max_simd_bitwidth;/**< max simd bitwidth path to use */ +enum rte_thread_priority thread_priority; +/**< thread priority to configure */ };void eal_reset_internal_config (struct internal_config *internal_cfg);
lib/eal/common/eal_options.h +2 -0
@@ -93,6 +93,8 @@ enum {OPT_NO_TELEMETRY_NUM , #define OPT_FORCE_MAX_SIMD_BITWIDTH "force-max-simd-bitwidth"OPT_FORCE_MAX_SIMD_BITWIDTH_NUM , +#define OPT_THREAD_PRIORITY "thread-prio" +OPT_THREAD_PRIORITY_NUM ,/* legacy option that will be removed in future */ #define OPT_PCI_BLACKLIST "pci-blacklist"
Signature · 1 line
2.31.0.vfs.0.1
Re: [dpdk-dev] [PATCH v13 09/10] eal: add EAL argument for setting thread priority
2021-08-03 12:01 (UTC-0700), Narcisa Ana Maria Vasile:
Quoted 4 lines
From: Narcisa Vasile <[email protected]>
Allow the user to choose the thread priority through an EAL command line argument.
EAL options documentation update is needed.
With current wording the user may ask: the priority of which thread?
Quoted 9 lines
The user can choose thread priority through an EAL parameter, when starting an application. If EAL parameter is not used, the per-platform default value for thread priority is used. Otherwise administrator has an option to set one of available options:
--thread-prio normal
--thread-prio realtimeExample:
./dpdk-l2fwd -l 0-3 -n 4 --thread-prio normal -- -q 8 -p ffff
IIUC, with this patch --thread-prio affects nothing, because the value it fills is not used anywhere. Why is it needed in this patchset then?
Quoted 27 lines
Signed-off-by Narcisa Vasile <[email protected]>--- lib/eal/common/eal_common_options.c | 28 +++++++++++++++++++++++++++- lib/eal/common/eal_internal_cfg.h | 2 ++ lib/eal/common/eal_options.h | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-)lib/eal/common/eal_common_options.c +4
-0@@ -107,6 +107,7 @@ eal_long_options[] = { {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM }, {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM }, {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM}, + {OPT_THREAD_PRIORITY, 1, NULL, OPT_THREAD_PRIORITY_NUM},/* legacy options that will be removed in future */ {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },@@ -1412,6 +1413,24 @@ eal_parse_simd_bitwidth(const char *arg)return 0 ; } +static int +eal_parse_thread_priority (const char *arg) +{
lib/eal/common/eal_common_options.c eal_parse_simd_bitwidth(const char *arg) · line 1428
Quoted 10 lines
lib/eal/common/eal_common_options.c +10
-0+struct internal_config *internal_conf = +eal_get_internal_configuration (); +enum rte_thread_priority priority; + +if (!strncmp ("normal" , arg,sizeof ("normal" ))) + priority =RTE_THREAD_PRIORITY_NORMAL ; +else if (!strncmp ("realtime" , arg,sizeof ("realtime" ))) + priority =RTE_THREAD_PRIORITY_REALTIME_CRITICAL ; +else +return -1 ;
Why not just strcmp()?
Quoted 36 lines
lib/eal/common/eal_common_options.c +13
-1+ + internal_conf->thread_priority = priority; +return 0 ; +} +static int eal_parse_base_virtaddr (const char *arg) {@@ -1825,7 +1844,13 @@ eal_parse_common_option(int opt, const char *optarg,return -1 ; }break ; - +case OPT_THREAD_PRIORITY_NUM : +if (eal_parse_thread_priority (optarg) <0 ) { +RTE_LOG (ERR ,EAL ,"invalid parameter for --" +OPT_THREAD_PRIORITY "\n" ); +return -1 ; + } +break ;/* don't know what to do, leave this to caller */ default :return 1 ;@@ -2088,6 +2113,7 @@ eal_common_usage(void)" (can be used multiple times)\n" " --" OPT_VMWARE_TSC_MAP " Use VMware TSC map instead of native RDTSC\n" " --" OPT_PROC_TYPE " Type of this process (primary|secondary|auto)\n" +" --" OPT_THREAD_PRIORITY " Set threads priority (normal|realtime)\n" #ifndef RTE_EXEC_ENV_WINDOWS" --" OPT_SYSLOG " Set syslog facility\n" #endiflib/eal/common/eal_internal_cfg.h +0
-0
lib/eal/common/eal_internal_cfg.h struct internal_config { · line 98
Quoted 5 lines
lib/eal/common/eal_internal_cfg.h +2
-0@@ -94,6 +94,8 @@ struct internal_config {unsigned int no_telemetry;/**< true to disable Telemetry */ struct simd_bitwidth max_simd_bitwidth;/**< max simd bitwidth path to use */ +enum rte_thread_priority thread_priority; +/**< thread priority to configure */
Where is the default set?
If you remove RTE_THREAD_PRIORITY_UNDEFINED in patch 2/10,
it will be RTE_THREAD_PRIORITY_NORMAL in zeroed-out structure, which is OK.
Quoted 16 lines
lib/eal/common/eal_internal_cfg.h +0
-0};void eal_reset_internal_config (struct internal_config *internal_cfg);lib/eal/common/eal_options.h +2
-0@@ -93,6 +93,8 @@ enum {OPT_NO_TELEMETRY_NUM , #define OPT_FORCE_MAX_SIMD_BITWIDTH "force-max-simd-bitwidth"OPT_FORCE_MAX_SIMD_BITWIDTH_NUM , +#define OPT_THREAD_PRIORITY "thread-prio" +OPT_THREAD_PRIORITY_NUM ,/* legacy option that will be removed in future */ #define OPT_PCI_BLACKLIST "pci-blacklist"
Re: [dpdk-dev] [PATCH v13 09/10] eal: add EAL argument for setting thread priority
In reply to Narcisa Ana Maria VasileQuoted 8 lines · On Tue, 3 Aug 2021 12:01:30 -0700 Narcisa Ana Maria Vasile…
lib/eal/common/eal_common_options.c +8
-0+static int +eal_parse_thread_priority (const char *arg) +{ +struct internal_config *internal_conf = +eal_get_internal_configuration (); +enum rte_thread_priority priority; + +if (!strncmp ("normal" , arg,sizeof ("normal" )))
lib/eal/common/eal_common_options.c eal_parse_simd_bitwidth(const char *arg) · line 1433
Quoted 10 lines
lib/eal/common/eal_common_options.c +10
-0+ priority =RTE_THREAD_PRIORITY_NORMAL ; + else if (!strncmp("realtime", arg, sizeof("realtime"))) + priority =RTE_THREAD_PRIORITY_REALTIME_CRITICAL ; + else + return -1; + + internal_conf->thread_priority = priority; +return 0 ; +} +
In my experience using real time priority is dangerous and risks starvation and deadlock. The problem is that DPDK applications are typically 100% CPU poll mode with no system calls; but the kernel has a number of worker threads that can be required on those CPUs.
The typical failure is a disk completion interrupt happens on a CPU that is being used by DPDK lcore thread. With RT priority, the kernel thread to process that I/O completion never runs because the RT user thread has higher priority than the kernel I/O completion thread.
It maybe possible to workaround this with lots of hand crafting through sysfs to reassign threads and irq's. Also, later kernels with full RT might also help.
Before putting this in as part of DPDK in EAL, a full set of testing and documentation of how to configure these kind of applications and systems is needed.
I can't recommend this going in at this time.
Re: [dpdk-dev] [PATCH v13 09/10] eal: add EAL argument for setting thread priority
Quoted 22 lines · Stephen Hemminger
Quoted 8 lines · On Tue, 3 Aug 2021 12:01:30 -0700 Narcisa Ana Maria Vasile…
+static int +eal_parse_thread_priority(const char *arg) +{ + struct
internal_config*internal_conf= +eal_get_internal_configuration(); + enumrte_thread_prioritypriority;
+ + if (!strncmp("normal", arg,sizeof("normal"))) +
priority =RTE_THREAD_PRIORITY_NORMAL; + else if
(!strncmp("realtime", arg,sizeof("realtime"))) + priority =RTE_THREAD_PRIORITY_REALTIME_CRITICAL; + else + return -1;
+ +internal_conf->thread_priority= priority; + return 0; +} +In my experience using real time priority is dangerous and risks starvation and deadlock. The problem is that DPDK applications are typically 100% CPU poll mode with no system calls; but the kernel has a number of worker threads that can be required on those CPUs.
The typical failure is a disk completion interrupt happens on a CPU that is being used by DPDK lcore thread. With RT priority, the kernel thread to process that I/O completion never runs because the RT user thread has higher priority than the kernel I/O completion thread.
Quoted 8 lines
It maybe possible to workaround this with lots of hand crafting through sysfs to reassign threads and irq's. Also, later kernels with full RT might also help.
Before putting this in as part of DPDK in EAL, a full set of testing and documentation of how to configure these kind of applications and systems is needed.
I would tend to agree caution here, based on my experience of having locked up a number of systems in the past when testing running DPDK apps with RT priority!
Re: [dpdk-dev] [PATCH v13 09/10] eal: add EAL argument for setting thread priority
Quoted 27 lines · Bruce Richardson
Quoted 26 lines · Stephen Hemminger
Quoted 8 lines · On Tue, 3 Aug 2021 12:01:30 -0700 Narcisa Ana Maria Vasile…
+static int +eal_parse_thread_priority(const char *arg) +{ + struct
internal_config*internal_conf= +eal_get_internal_configuration(); + enumrte_thread_prioritypriority;
+ + if (!strncmp("normal", arg,sizeof("normal"))) +
priority =RTE_THREAD_PRIORITY_NORMAL; + else if
(!strncmp("realtime", arg,sizeof("realtime"))) + priority =RTE_THREAD_PRIORITY_REALTIME_CRITICAL; + else + return -1;
+ +internal_conf->thread_priority= priority; + return 0; +} +In my experience using real time priority is dangerous and risks starvation and deadlock. The problem is that DPDK applications are typically 100% CPU poll mode with no system calls; but the kernel has a number of worker threads that can be required on those CPUs.
The typical failure is a disk completion interrupt happens on a CPU that is being used by DPDK lcore thread. With RT priority, the kernel thread to process that I/O completion never runs because the RT user thread has higher priority than the kernel I/O completion thread.
It maybe possible to workaround this with lots of hand crafting through sysfs to reassign threads and irq's. Also, later kernels with full RT might also help.
Quoted 7 lines
Quoted 4 lines
Before putting this in as part of DPDK in EAL, a full set of testing and documentation of how to configure these kind of applications and systems is needed.
I would tend to agree caution here, based on my experience of having locked up a number of systems in the past when testing running DPDK apps with RT priority!
Thank you for the comments! I've added this option since it was requested by multiple users. I understand RT priority causes issues on Linux platforms. On Windows we want to be able to use REALTIME priority in certain scenarios.
Would it be acceptable to replace this option with a "HIGH_PRIORITY" one and keep it realtime on Windows and choose a higher (but non-realtime) option on Linux? However, there are 2 issues here:
* We will have different behaviors between the 2 platforms.
* Not sure if I can set a normal but higher priority on Linux. SCHED_OTHER only allows one value and Linux "nice" values don't help. If anyone knows of a way to accomplish this on Linux, please do advise.
Alternatively, we can have this option for Windows only.
In the meantime, I've removed this patch from this patchset in v14 as the cmdline option is not being enabled yet, as DmitryK noted.
Re: [dpdk-dev] [PATCH v13 09/10] eal: add EAL argument for setting thread priority
Quoted 49 lines · On Thu, 19 Aug 2021 14:30:19 -0700 Narcisa Ana Maria Vasile…
Quoted 27 lines · Bruce Richardson
Quoted 26 lines · Stephen Hemminger
Quoted 8 lines · On Tue, 3 Aug 2021 12:01:30 -0700 Narcisa Ana Maria Vasile…
+static int +eal_parse_thread_priority(const char *arg) +{ + struct
internal_config*internal_conf= +eal_get_internal_configuration(); + enumrte_thread_prioritypriority;
+ + if (!strncmp("normal", arg,sizeof("normal"))) +
priority =RTE_THREAD_PRIORITY_NORMAL; + else if
(!strncmp("realtime", arg,sizeof("realtime"))) + priority =RTE_THREAD_PRIORITY_REALTIME_CRITICAL; + else + return -1;
+ +internal_conf->thread_priority= priority; + return 0; +} +In my experience using real time priority is dangerous and risks starvation and deadlock. The problem is that DPDK applications are typically 100% CPU poll mode with no system calls; but the kernel has a number of worker threads that can be required on those CPUs.
The typical failure is a disk completion interrupt happens on a CPU that is being used by DPDK lcore thread. With RT priority, the kernel thread to process that I/O completion never runs because the RT user thread has higher priority than the kernel I/O completion thread.
It maybe possible to workaround this with lots of hand crafting through sysfs to reassign threads and irq's. Also, later kernels with full RT might also help.
Quoted 7 lines
Quoted 4 lines
Before putting this in as part of DPDK in EAL, a full set of testing and documentation of how to configure these kind of applications and systems is needed.
I would tend to agree caution here, based on my experience of having locked up a number of systems in the past when testing running DPDK apps with RT priority!
Thank you for the comments! I've added this option since it was requested by multiple users. I understand RT priority causes issues on Linux platforms. On Windows we want to be able to use REALTIME priority in certain scenarios.
Would it be acceptable to replace this option with a "
HIGH_PRIORITY" one and keep it realtime on Windows and choose a higher (but non-realtime) option on Linux? However, there are 2 issues here:
* We will have different behaviors between the 2 platforms.
* Not sure if I can set a normal but higher priority on Linux.SCHED_OTHERonly allows one value and Linux "nice" values don't help. If anyone knows of a way to accomplish this on Linux, please do advise.
Alternatively, we can have this option for Windows only.
Quoted 4 lines
In the meantime, I've removed this patch from this patchset in v14 as the cmdline option is not being enabled yet, as DmitryK noted.
I think on Linux it should produce a big a*** warning message.
PATCH v13 10/10 Add unit tests for thread API
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
As a new API for threading is introduced,
a set of unit tests have been added to test the new interface.
--- app/test/meson.build | 2 + app/test/test_threads.c | 419 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 421 insertions(+) create mode 100644 app/test/test_threads.c
app/test/meson.build +2 -0
@@ -140,6 +140,7 @@ test_sources = files( 'test_table_tables.c', 'test_tailq.c', 'test_thash.c', + 'test_threads.c', 'test_timer.c', 'test_timer_perf.c', 'test_timer_racecond.c',
@@ -276,6 +277,7 @@ fast_tests = [ ['reorder_autotest', true], ['service_autotest', true], ['thash_autotest', true], + ['threads_autotest', true], ['trace_autotest', true], ]
app/test/test_threads.c new file +419 -0
419 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
v14 cover eal: Add EAL API for threading
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
EAL thread API
**Problem Statement**
DPDK currently uses the pthread interface to create and manage threads. Windows does not support the POSIX thread programming model, so it currently
relies on a header file that hides the Windows calls under pthread matched interfaces. Given that EAL should isolate the environment specifics from the applications and libraries and mediate
all the communication with the operating systems, a new EAL interface is needed for thread management.
**Goals**
* Introduce a generic EAL API for threading support that will remove the current Windows pthread.h shim.
* Replace references to pthread_* across the DPDK codebase with the new RTE_THREAD_* API.
* Allow users to choose between using the RTE_THREAD_* API or a 3rd party thread library through a configuration option.
**Design plan**
New API main files:
* rte_thread.h (librte_eal/include)
* rte_thread.c (librte_eal/windows)
* rte_thread.c (librte_eal/common)
**A schematic example of the design**
--------------------------------------------------lib/librte_eal/include/rte_thread.h
int rte_thread_create();
lib/librte_eal/common/rte_thread.c
int rte_thread_create()
{
return pthread_create();
}lib/librte_eal/windows/rte_thread.c
int rte_thread_create()
{
return CreateThread();
}-----------------------------------------------------
**Thread attributes**
When or after a thread is created, specific characteristics of the thread can be adjusted. Given that the thread characteristics that are of interest for DPDK applications are affinity and priority, the following structure that represents thread attributes has been defined:
typedef struct
{
enum rte_thread_priority priority;
rte_cpuset_t cpuset;
} rte_thread_attr_t;The *rte_thread_create()* function can optionally receive an rte_thread_attr_t
object that will cause the thread to be created with the affinity and priority
described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used. An rte_thread_attr_t object can also be set to the default values by calling *rte_thread_attr_init()*.
*Priority* is represented through an enum that currently advertises two values for priority:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
The enum can be extended to allow for multiple priority levels.rte_thread_set_priority - sets the priority of a threadrte_thread_attr_set_priority - updates an rte_thread_attr_t object
with a new value for priority
*Affinity* is described by the already known “rte_cpuset_t” type. rte_thread_attr_set/get_affinity - sets/gets the affinity field in a
rte_thread_attr_t object
rte_thread_set/get_affinity – sets/gets the affinity of a thread
**Errors**
A translation function that maps Windows error codes to errno-style error codes is provided.
**Future work**
The long term plan is for EAL to provide full threading support:
* Add support for conditional variables
* Add support for pthread_mutex_trylock
* Additional functionality offered by pthread_*
(such as pthread_setname_np, etc.)
v14:
- Remove patch "eal: add EAL argument for setting thread priority" This will be added later when enabling the new threading API.
- Remove priority enum value "_UNDEFINED". NORMAL is used as the default.
- Fix issue with thread return value.
v13:
- Fix syntax error in unit tests
v12:
- Fix freebsd warning about initializer in unit tests
v11:
- Add unit tests for thread API
- Rebase
v10:
- Remove patch no. 10. It will be broken down in subpatches and sent as a different patchset that depends on this one. This is done due to the ABI breaks that would be caused by patch 10.
- Replace unix/rte_thread.c with common/rte_thread.c
- Remove initializations that may prevent compiler from issuing useful warnings.
- Remove rte_thread_types.h and rte_windows_thread_types.h
- Remove unneeded priority macros (EAL_THREAD_PRIORITY*)
- Remove functions that retrieves thread handle from process handle
- Remove rte_thread_cancel() until same behavior is obtained on all platforms.
- Fix rte_thread_detach() function description,
return value and remove empty line.
- Reimplement mutex functions. Add compatible representation for mutex identifier. Add macro to replace static mutex initialization instances.
- Fix commit messages (lines too long, remove unicode symbols)
v9:
- Sign patches
v8:
- Rebase
- Add rte_thread_detach() API
- Set default priority, when user did not specify a value
v7:
Based on DmitryK's review:
- Change thread id representation
- Change mutex id representation
- Implement static mutex inititalizer for Windows
- Change barrier identifier representation
- Improve commit messages
- Add missing doxygen comments
- Split error translation function
- Improve name for affinity function
- Remove cpuset_size parameter
- Fix eal_create_cpu_map function
- Map EAL priority values to OS specific values
- Add thread wrapper for start routine
- Do not export rte_thread_cancel() on Windows
- Cleanup, fix comments, fix typos.
v6:
- improve error-translation function
- call the error translation function in rte_thread_value_get()
v5:
- update cover letter with more details on the priority argument
v4:
- fix function description
- rebase
v3:
- rebase
v2:
- revert changes that break ABI
- break up changes into smaller patches
- fix coding style issues
- fix issues with errors
- fix parameter type in examples/kni.c
Narcisa Vasile (9):
eal: add basic threading functions
eal: add thread attributes
eal/windows: translate Windows errors to errno-style errors
eal: implement functions for thread affinity management
eal: implement thread priority management functions
eal: add thread lifetime management
eal: implement functions for mutex management
eal: implement functions for thread barrier management Add unit tests for thread API
app/test/meson.build | 2 + app/test/test_threads.c | 419 +++++++++++++++++++++++ lib/eal/common/meson.build | 1 + lib/eal/common/rte_thread.c | 441 ++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 404 +++++++++++++++++++++- lib/eal/unix/meson.build | 1 - lib/eal/unix/rte_thread.c | 92 ----- lib/eal/version.map | 20 ++ lib/eal/windows/eal_lcore.c | 176 +++++++--- lib/eal/windows/eal_windows.h | 10 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 584 ++++++++++++++++++++++++++++++-- 12 files changed, 1979 insertions(+), 173 deletions(-) create mode 100644 app/test/test_threads.c create mode 100644 lib/eal/common/rte_thread.c delete mode 100644 lib/eal/unix/rte_thread.c
Signature · 1 line
2.31.0.vfs.0.1
PATCH v14 1/9 eal: add basic threading functions
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
---
lib/eal/common/meson.build | 1 +
lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
lib/eal/include/rte_thread.h | 48 +++++++++++++++++-----
lib/eal/unix/meson.build | 1 -
lib/eal/version.map | 3 ++
lib/eal/windows/rte_thread.c | 17 ++++++++
6 files changed, 95 insertions(+), 32 deletions(-)
rename lib/eal/{unix => common}/rte_thread.c (66%)lib/eal/common/meson.build +1 -0
@@ -80,6 +80,7 @@ sources += files( 'rte_random.c', 'rte_reciprocal.c', 'rte_service.c', + 'rte_thread.c', 'rte_version.c', )
lib/eal/common/rte_thread.c renamed from lib/eal/unix/rte_thread.c +35 -22
107 lines not on this page · raw message
lib/eal/include/rte_thread.h +39 -9
83 lines not on this page · raw message
lib/eal/unix/meson.build +0 -1
@@ -6,5 +6,4 @@ sources += files( 'eal_unix_memory.c', 'eal_unix_timer.c', 'eal_firmware.c', - 'rte_thread.c', )
lib/eal/version.map +3 -0
@@ -426,6 +426,9 @@ EXPERIMENTAL { # added in 21.08 rte_power_monitor_multi; # WINDOWS_NO_EXPORT + + rte_thread_self; + rte_thread_equal; }; INTERNAL {
lib/eal/windows/rte_thread.c +17 -0
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright 2021 Mellanox Technologies, Ltd +* Copyright(c) 2021 Microsoft Corporation */ #include <rte_common.h>
@@ -11,6 +12,22 @@ struct eal_tls_key {DWORD thread_index; }; +rte_thread_t +rte_thread_self (void ) +{ +rte_thread_t thread_id; + + thread_id.opaque_id =GetCurrentThreadId (); + +return thread_id; +} + +int +rte_thread_equal (rte_thread_t t1,rte_thread_t t2) +{ +return t1.opaque_id == t2.opaque_id; +} +int rte_thread_key_create (rte_thread_key *key, __rte_unused void (*destructor)(void *))
Signature · 1 line
2.31.0.vfs.0.1
PATCH v14 2/9 eal: add thread attributes
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.
Priority is represented through an enum that allows for two levels:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
Affinity is described by the rte_cpuset_t type.
An rte_thread_attr_t object can be set to the default values by calling rte_thread_attr_init().
--- lib/eal/common/rte_thread.c | 46 ++++++++++++++++++ lib/eal/include/rte_thread.h | 91 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 44 +++++++++++++++++ 4 files changed, 185 insertions(+)
lib/eal/common/rte_thread.c +46 -0
@@ -9,6 +9,7 @@#include <string.h> #include <rte_common.h> +#include <rte_debug.h> #include <rte_errno.h> #include <rte_log.h> #include <rte_thread.h>
@@ -33,6 +34,51 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_attr_init (rte_thread_attr_t *attr) +{ +RTE_VERIFY (attr !=NULL ); + +CPU_ZERO (&attr->cpuset); + attr->priority =RTE_THREAD_PRIORITY_NORMAL ; + +return 0 ; +} + +int +rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + thread_attr->cpuset = *cpuset; + +return 0 ; +} + +int +rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + *cpuset = thread_attr->cpuset; + +return 0 ; +} + +int +rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, +enum rte_thread_priority priority) +{ +RTE_VERIFY (thread_attr !=NULL ); + + thread_attr->priority = priority; +return 0 ; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +91 -0
103 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -429,6 +429,10 @@ EXPERIMENTAL { rte_thread_self; rte_thread_equal; + rte_thread_attr_init; + rte_thread_attr_get_affinity; + rte_thread_attr_set_affinity; + rte_thread_attr_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v14 3/9 eal/windows: translate Windows errors to errno-style errors
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function to translate Windows error codes to errno-style error codes. The possible return values are chosen so that we have as much semantical compatibility between platforms as possible.
--- lib/eal/common/rte_thread.c | 6 +-- lib/eal/include/rte_thread.h | 5 +- lib/eal/windows/rte_thread.c | 95 +++++++++++++++++++++++++++--------- 3 files changed, 76 insertions(+), 30 deletions(-)
lib/eal/common/rte_thread.c +3 -3
@@ -47,7 +47,7 @@ rte_thread_attr_init(rte_thread_attr_t *attr)int rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -59,7 +59,7 @@ rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -71,7 +71,7 @@ rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, -enum rte_thread_priority priority) +enum rte_thread_priority priority) {RTE_VERIFY (thread_attr !=NULL );
lib/eal/include/rte_thread.h +2 -3
@@ -233,9 +233,8 @@ int rte_thread_value_set(rte_thread_key key, const void *value);* * @return * On success, value data pointer (can also be NULL). -* On failure, NULL and an error number is set in rte_errno. -* rte_errno can be: EINVAL - Invalid parameter passed. -* ENOEXEC - Specific OS error. +* On failure, NULL and a positive error number is set in rte_errno. +* */ __rte_experimental void *rte_thread_value_get(rte_thread_key key);
lib/eal/windows/rte_thread.c +71 -24
165 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v14 4/9 eal: implement functions for thread affinity management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement functions for getting/setting thread affinity. Threads can be pinned to specific cores by setting their affinity attribute.
--- lib/eal/common/rte_thread.c | 16 ++++ lib/eal/include/rte_thread.h | 36 +++++++ lib/eal/version.map | 2 + lib/eal/windows/eal_lcore.c | 176 +++++++++++++++++++++++++--------- lib/eal/windows/eal_windows.h | 10 ++ lib/eal/windows/rte_thread.c | 125 +++++++++++++++++++++++- 6 files changed, 319 insertions(+), 46 deletions(-)
lib/eal/common/rte_thread.c +16 -0
@@ -34,6 +34,22 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_set_affinity_by_id (rte_thread_t thread_id, +const rte_cpuset_t *cpuset) +{ +return pthread_setaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} + +int +rte_thread_get_affinity_by_id (rte_thread_t thread_id, +rte_cpuset_t *cpuset) +{ +return pthread_getaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +36 -0
@@ -85,6 +85,42 @@ int rte_thread_equal(rte_thread_t t1, rte_thread_t t2);#ifdef RTE_HAS_CPUSET +/** +* Set the affinity of thread 'thread_id' to the cpu set +* specified by 'cpuset'. +* +* @param thread_id +* Id of the thread for which to set the affinity. +* +* @param cpuset +* Pointer to CPU affinity to set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_affinity_by_id(rte_thread_t thread_id, +const rte_cpuset_t *cpuset); + +/** +* Get the affinity of thread 'thread_id' and store it +* in 'cpuset'. +* +* @param thread_id +* Id of the thread for which to get the affinity. +* +* @param cpuset +* Pointer for storing the affinity value. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_get_affinity_by_id(rte_thread_t thread_id, +rte_cpuset_t *cpuset); +/** * Initialize the attributes of a thread. * These attributes can be passed to the rte_thread_create() function
lib/eal/version.map +2 -0
@@ -433,6 +433,8 @@ EXPERIMENTAL { rte_thread_attr_get_affinity; rte_thread_attr_set_affinity; rte_thread_attr_set_priority; + rte_thread_get_affinity_by_id; + rte_thread_set_affinity_by_id; }; INTERNAL {
lib/eal/windows/eal_lcore.c +131 -45
231 lines not on this page · raw message
lib/eal/windows/eal_windows.h +10 -0
@@ -55,6 +55,16 @@ int eal_thread_create(pthread_t *thread);*/ unsigned int eal_socket_numa_node (unsigned int socket_id); +/** +* Get pointer to the group affinity for the cpu. +* +* @param cpu_index +* Index of the cpu, as it comes from rte_cpuset_t. +* @return +* Pointer to the group affinity for the cpu. +*/ +PGROUP_AFFINITY eal_get_cpu_affinity (size_t cpu_index); +/** * Schedule code for execution in the interrupt thread. *
lib/eal/windows/rte_thread.c +124 -1
137 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v14 5/9 eal: implement thread priority management functions
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function for setting the priority for a thread. Priorities on multiple platforms are similarly determined by a priority value and a priority class/policy.
On Linux, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* policy SCHED_OTHER
* priority value: (sched_get_priority_min(SCHED_OTHER) +
sched_get_priority_max(SCHED_OTHER))/2;
RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* policy SCHED_RR
* priority value: sched_get_priority_max(SCHED_RR);
On Windows, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* class NORMAL_PRIORITY_CLASS
* priority THREAD_PRIORITY_NORMAL RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* class REALTIME_PRIORITY_CLASS
* priority THREAD_PRIORITY_TIME_CRITICAL
--- lib/eal/common/rte_thread.c | 49 ++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 17 ++++++++++ lib/eal/version.map | 1 + lib/eal/windows/rte_thread.c | 66 ++++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+)
lib/eal/common/rte_thread.c +49 -0
@@ -50,6 +50,55 @@ rte_thread_get_affinity_by_id(rte_thread_t thread_id, sizeof(*cpuset), cpuset); } +static int +thread_map_priority_to_os_value (enum rte_thread_priority eal_pri, +int *os_pri,int *pol) +{ +/* Clear the output parameters */ + *os_pri =sched_get_priority_min (SCHED_OTHER ) -1 ; + *pol =-1 ; + +switch (eal_pri) { +case RTE_THREAD_PRIORITY_NORMAL : + *pol =SCHED_OTHER ; + +/* +* Choose the middle of the range to represent +* the priority 'normal'. +* On Linux, this should be 0, since both +* sched_get_priority_min/_max return 0 for SCHED_OTHER. +*/ + *os_pri = (sched_get_priority_min (SCHED_OTHER ) + +sched_get_priority_max (SCHED_OTHER ))/2 ; +break ; +case RTE_THREAD_PRIORITY_REALTIME_CRITICAL : + *pol =SCHED_RR ; + *os_pri =sched_get_priority_max (SCHED_RR ); +break ; +default : +RTE_LOG (DEBUG ,EAL ,"The requested priority value is invalid.\n" ); +return EINVAL ; + } +return 0 ; +} + +int +rte_thread_set_priority (rte_thread_t thread_id, +enum rte_thread_priority priority) +{ +int ret; +int policy; +struct sched_param param; + + ret =thread_map_priority_to_os_value (priority, ¶m.sched_priority, + &policy); +if (ret !=0 ) +return ret; + +return pthread_setschedparam ((pthread_t )thread_id.opaque_id, + policy, ¶m); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +17 -0
@@ -213,6 +213,23 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp);#endif /* RTE_HAS_CPUSET */ +/** +* Set the priority of a thread. +* +* @param thread_id +* Id of the thread for which to set priority. +* +* @param priority +* Priority value to be set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_priority(rte_thread_t thread_id, +enum rte_thread_priority priority); +/** * Create a TLS data key visible to all threads in the process. * the created key is later used to get/set a value.
lib/eal/version.map +1 -0
@@ -435,6 +435,7 @@ EXPERIMENTAL { rte_thread_attr_set_priority; rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; + rte_thread_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +66 -0
72 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v14 6/9 eal: add thread lifetime management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for thread creation, joining, detaching.
The *rte_thread_create()* function can optionally receive
an rte_thread_attr_t object that will cause the thread to be created with the affinity and priority described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used.
On Windows, the function executed by a thread when the thread starts is represeneted by a function pointer of type DWORD (*func) (void*). On other platforms, the function pointer is a void* (*func) (void*).
Performing a cast between these two types of function pointers to uniformize the API on all platforms may result in undefined behavior. TO fix this issue, a wrapper that respects the signature required by CreateThread() has been created on Windows.
--- lib/eal/common/rte_thread.c | 103 ++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 55 +++++++++++++ lib/eal/version.map | 3 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 134 ++++++++++++++++++++++++++++++++ 5 files changed, 296 insertions(+), 1 deletion(-)
lib/eal/common/rte_thread.c +103 -0
@@ -144,6 +144,109 @@ rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,return 0 ; } +int +rte_thread_create (rte_thread_t *thread_id, +const rte_thread_attr_t *thread_attr, +rte_thread_func thread_func,void *args) +{ +int ret =0 ; +pthread_attr_t attr; +pthread_attr_t *attrp =NULL ; +struct sched_param param = { + .sched_priority =0 , + }; +int policy =SCHED_OTHER ; + +if (thread_attr !=NULL ) { + ret =pthread_attr_init (&attr); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_init failed\n" ); + goto cleanup; + } + + attrp = &attr; + +/* +* Set the inherit scheduler parameter to explicit, +* otherwise the priority attribute is ignored. +*/ + ret =pthread_attr_setinheritsched (attrp, +PTHREAD_EXPLICIT_SCHED ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setinheritsched failed\n" ); + goto cleanup; + } + + ret =thread_map_priority_to_os_value (thread_attr->priority, + ¶m.sched_priority, &policy); +if (ret !=0 ) + goto cleanup; + + ret =pthread_attr_setschedpolicy (attrp, policy); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedpolicy failed\n" ); + goto cleanup; + } + + ret =pthread_attr_setschedparam (attrp, ¶m); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedparam failed\n" ); + goto cleanup; + } + +if (CPU_COUNT (&thread_attr->cpuset) >0 ) { + ret =pthread_attr_setaffinity_np (attrp, +sizeof (thread_attr->cpuset), + &thread_attr->cpuset); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setaffinity_np failed\n" ); + goto cleanup; + } + } + } + + ret =pthread_create ((pthread_t *)&thread_id->opaque_id, attrp, + thread_func, args); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_create failed\n" ); + goto cleanup; + } + +cleanup: +if (attrp !=NULL ) +pthread_attr_destroy (&attr); + +return ret; +} + +int +rte_thread_join (rte_thread_t thread_id,unsigned long *value_ptr) +{ +int ret =0 ; +void *res =NULL ; +void **pres =NULL ; + +if (value_ptr !=NULL ) + pres = &res; + + ret =pthread_join ((pthread_t )thread_id.opaque_id, pres); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_join failed\n" ); +return ret; + } + +if (value_ptr !=NULL && *pres !=NULL ) + *value_ptr = *(unsigned long *)(*pres); + +return 0 ; +} + +int +rte_thread_detach (rte_thread_t thread_id) +{ +return pthread_detach ((pthread_t )thread_id.opaque_id); +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +55 -0
67 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -436,6 +436,9 @@ EXPERIMENTAL { rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; rte_thread_set_priority; + rte_thread_create; + rte_thread_join; + rte_thread_detach; }; INTERNAL {
lib/eal/windows/include/sched.h +1 -1
@@ -44,7 +44,7 @@ typedef struct _rte_cpuset_s { (1LL << _WHICH_BIT(b))) != 0LL)static inline int -count_cpu (rte_cpuset_t *s) +count_cpu (const rte_cpuset_t *s) {unsigned int _i;int count =0 ;
lib/eal/windows/rte_thread.c +134 -0
146 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v14 7/9 eal: implement functions for mutex management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for mutex init, destroy, lock, unlock.
Add RTE_STATIC_MUTEX macro to replace static initialization of mutexes.
Windows does not have a static initializer. Initialization is only done through InitializeCriticalSection().
The RTE_STATIC_MUTEX calls into the rte_thread_mutex_init() function that performs the actual mutex initialization.
--- lib/eal/common/rte_thread.c | 61 +++++++++++++++++++++++ lib/eal/include/rte_thread.h | 94 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 53 ++++++++++++++++++++ 4 files changed, 212 insertions(+)
lib/eal/common/rte_thread.c +61 -0
@@ -247,6 +247,67 @@ rte_thread_detach(rte_thread_t thread_id)return pthread_detach ((pthread_t )thread_id.opaque_id); } +int +rte_thread_mutex_init (rte_thread_mutex *mutex) +{ +int ret =0 ; +pthread_mutex_t *m =NULL ; + +RTE_VERIFY (mutex !=NULL ); + + m =calloc (1 ,sizeof (*m)); +if (m ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize mutex. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + + ret =pthread_mutex_init (m,NULL ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init mutex. ret = %d\n" , ret); + goto cleanup; + } + + mutex->mutex_id = m; + m =NULL ; + +cleanup: +free (m); +return ret; +} + +int +rte_thread_mutex_lock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_lock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_unlock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_unlock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_destroy (rte_thread_mutex *mutex) +{ +int ret =0 ; +RTE_VERIFY (mutex !=NULL ); + + ret =pthread_mutex_destroy ((pthread_mutex_t *)mutex->mutex_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Unable to destroy mutex, ret = %d\n" , ret); + +free (mutex->mutex_id); + mutex->mutex_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +94 -0
112 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -439,6 +439,10 @@ EXPERIMENTAL { rte_thread_create; rte_thread_join; rte_thread_detach; + rte_thread_mutex_init; + rte_thread_mutex_lock; + rte_thread_mutex_unlock; + rte_thread_mutex_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +53 -0
59 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v14 8/9 eal: implement functions for thread barrier management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for barrier init, destroy, wait.
A portable type is used to represent a barrier identifier. The rte_thread_barrier_wait() function returns the same value on all platforms.
--- lib/eal/common/rte_thread.c | 61 ++++++++++++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 58 ++++++++++++++++++++++++++++++++++ lib/eal/version.map | 3 ++ lib/eal/windows/rte_thread.c | 56 +++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+)
lib/eal/common/rte_thread.c +61 -0
@@ -308,6 +308,67 @@ rte_thread_mutex_destroy(rte_thread_mutex *mutex)return ret; } +int +rte_thread_barrier_init (rte_thread_barrier *barrier,int count) +{ +int ret =0 ; +pthread_barrier_t *pthread_barrier =NULL ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (count >0 ); + + pthread_barrier =calloc (1 ,sizeof (*pthread_barrier)); +if (pthread_barrier ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize barrier. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + ret =pthread_barrier_init (pthread_barrier,NULL , count); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init barrier, ret = %d\n" , ret); + goto cleanup; + } + + barrier->barrier_id = pthread_barrier; + pthread_barrier =NULL ; + +cleanup: +free (pthread_barrier); +return ret; +} + +int +rte_thread_barrier_wait (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (barrier->barrier_id !=NULL ); + + ret =pthread_barrier_wait (barrier->barrier_id); +if (ret ==PTHREAD_BARRIER_SERIAL_THREAD ) + ret =RTE_THREAD_BARRIER_SERIAL_THREAD ; + +return ret; +} + +int +rte_thread_barrier_destroy (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); + + ret =pthread_barrier_destroy (barrier->barrier_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Failed to destroy barrier: %d\n" , ret); + +free (barrier->barrier_id); + barrier->barrier_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +58 -0
70 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -443,6 +443,9 @@ EXPERIMENTAL { rte_thread_mutex_lock; rte_thread_mutex_unlock; rte_thread_mutex_destroy; + rte_thread_barrier_init; + rte_thread_barrier_wait; + rte_thread_barrier_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v14 9/9 Add unit tests for thread API
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
As a new API for threading is introduced,
a set of unit tests have been added to test the new interface.
--- app/test/meson.build | 2 + app/test/test_threads.c | 419 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 421 insertions(+) create mode 100644 app/test/test_threads.c
app/test/meson.build +2 -0
@@ -140,6 +140,7 @@ test_sources = files( 'test_table_tables.c', 'test_tailq.c', 'test_thash.c', + 'test_threads.c', 'test_timer.c', 'test_timer_perf.c', 'test_timer_racecond.c',
@@ -276,6 +277,7 @@ fast_tests = [ ['reorder_autotest', true], ['service_autotest', true], ['thash_autotest', true], + ['threads_autotest', true], ['trace_autotest', true], ]
app/test/test_threads.c new file +419 -0
419 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
Re: [dpdk-dev] [PATCH v14 9/9] Add unit tests for thread API
Quoted 5 lines · Narcisa Ana Maria Vasile
From: Narcisa Vasile <[email protected]>
As a new API for threading is introduced,
a set of unit tests have been added to test the new interface.
Quoted 7 lines
Signed-off-by Narcisa Vasile <[email protected]>--- app/test/meson.build | 2 + app/test/test_threads.c | 419 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 421 insertions(+) create mode 100644 app/test/test_threads.c
There's a failure here on Alpine Linux:
"error: implicit declaration of function 'pthread_attr_setaffinity_np'; did you mean 'pthread_setaffinity_np'? [-Werror=implicit-function-declaration]"
It looks like "pthread_attr_setaffinity_np" is not available on Alpine Linux. However, other affinity functions such as "pthread_setaffinity_np" are present. Is there a guard that I can use here to check if the pthread_*_np functions are available, similar to RTE_HAS_CPUSET for cpuset?
Re: [dpdk-dev] [PATCH v14 9/9] Add unit tests for thread API
2021-08-20 09:10 (UTC-0700), Narcisa Ana Maria Vasile:
Quoted 14 lines · Narcisa Ana Maria Vasile
Quoted 5 lines
From: Narcisa Vasile <[email protected]>
As a new API for threading is introduced,
a set of unit tests have been added to test the new interface.Quoted 7 lines
Signed-off-by Narcisa Vasile <[email protected]>--- app/test/meson.build | 2 + app/test/test_threads.c | 419 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 421 insertions(+) create mode 100644 app/test/test_threads.c
Quoted 7 lines
There's a failure here on Alpine Linux:
"error: implicit declaration of function 'pthread_attr_setaffinity_np'; did you mean 'pthread_setaffinity_np'? [-Werror=implicit-function-declaration]"It looks like "
pthread_attr_setaffinity_np" is not available on Alpine Linux. However, other affinity functions such as "pthread_setaffinity_np" are present. Is there a guard that I can use here to check if the pthread_*_np functions are available, similar toRTE_HAS_CPUSETfor cpuset?
Even if there is one, you still need to handle the Alpine case. 41b5a7a8494e ("vdpa/mlx5: replace pthread functions unavailable in musl") is an example how to solve this particular case.
It's also what that rte_ctrl_thread_create() does.
Re: [dpdk-dev] [PATCH v14 9/9] Add unit tests for thread API
In reply to Narcisa Ana Maria Vasile2021-08-19 14:31 (UTC-0700), Narcisa Ana Maria Vasile:
Quoted 4 lines
From: Narcisa Vasile <[email protected]>
As a new API for threading is introduced,
a set of unit tests have been added to test the new interface.
There are three substantial issues with this tests:
1. They use pthread API to verify the results, but the whole point of introducing this new API is to abstract pthread or Win32 interfaces and eventually to remove pthread shim from Windows EAL. Furthermore, new new API actually has functions to do the checks, e.g. rte_thread_get_affinity().
2. They don't really check the contracts:
2.1. Mutex test could pass even if it used no locking at all. 2.2. Barrier test does not verify that threads are blocked/unblocked. 2.3. No test for static initialization.
See also comments inline.
[...]
app/test/test_threads.c line 14
Quoted 2 lines
app/test/test_threads.c new file +2
-0+#define TEST_THREADS_LOG (func) \ + printf("Error at line %d. %s failed!\n", __LINE__, func)
rte_test.h contains some useful macros like this one.
[...]
app/test/test_threads.c line 38
Quoted 13 lines
app/test/test_threads.c new file +13
-0+static int +test_thread_self (void ) +{ +rte_thread_t threads_ids[THREADS_COUNT ]; +rte_thread_t self_ids[THREADS_COUNT ] = {}; +size_t i; +size_t j; +int ret =0 ; + +for (i =0 ; i <THREADS_COUNT ; ++i) { +if (rte_thread_create (&threads_ids[i],NULL , thread_loop_self, + &self_ids[i]) !=0 ) { +printf ("Error, Only %zu threads created.\n" , i);
Typo: "only" (in other copies too).
This test could use RTE_LOG_REGISTER() and log levels if needed.
app/test/test_threads.c line 51
Quoted 13 lines
app/test/test_threads.c new file +13
-0+break ; + } + } + +for (j =0 ; j < i; ++j) { + ret =rte_thread_join (threads_ids[j],NULL ); +if (ret !=0 ) { +TEST_THREADS_LOG ("rte_thread_join()" ); +return -1 ; + } + +if (rte_thread_equal (threads_ids[j], self_ids[j]) ==0 ) + ret =-1 ;
Tests should indicate what exactly went wrong.
Suggesting RTE_TEST_ASSERT_EQUAL() here.
Quoted 4 lines
app/test/test_threads.c new file +4
-0+ } + +return ret; +}
app/test/test_threads.c line 65
Quoted 10 lines
app/test/test_threads.c new file +10
-0+ +struct thread_context { +rte_thread_barrier *barrier; +size_t *thread_count; +}; + +static void * +thread_loop_barrier (void *arg) +{ +
Unnecessary empty line.
Quoted 9 lines
app/test/test_threads.c new file +9
-0+struct thread_context *ctx = arg; + + (void )__atomic_add_fetch (ctx->thread_count,1 , __ATOMIC_RELAXED); + +if (rte_thread_barrier_wait (ctx->barrier) >0 ) +TEST_THREADS_LOG ("rte_thread_barrier_wait()" ); + +return NULL ; +}
[...]
v15 cover eal: Add EAL API for threading
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
EAL thread API
**Problem Statement**
DPDK currently uses the pthread interface to create and manage threads. Windows does not support the POSIX thread programming model, so it currently
relies on a header file that hides the Windows calls under pthread matched interfaces. Given that EAL should isolate the environment specifics from the applications and libraries and mediate
all the communication with the operating systems, a new EAL interface is needed for thread management.
**Goals**
* Introduce a generic EAL API for threading support that will remove the current Windows pthread.h shim.
* Replace references to pthread_* across the DPDK codebase with the new RTE_THREAD_* API.
* Allow users to choose between using the RTE_THREAD_* API or a 3rd party thread library through a configuration option.
**Design plan**
New API main files:
* rte_thread.h (librte_eal/include)
* rte_thread.c (librte_eal/windows)
* rte_thread.c (librte_eal/common)
**A schematic example of the design**
--------------------------------------------------lib/librte_eal/include/rte_thread.h
int rte_thread_create();
lib/librte_eal/common/rte_thread.c
int rte_thread_create()
{
return pthread_create();
}lib/librte_eal/windows/rte_thread.c
int rte_thread_create()
{
return CreateThread();
}-----------------------------------------------------
**Thread attributes**
When or after a thread is created, specific characteristics of the thread can be adjusted. Given that the thread characteristics that are of interest for DPDK applications are affinity and priority, the following structure that represents thread attributes has been defined:
typedef struct
{
enum rte_thread_priority priority;
rte_cpuset_t cpuset;
} rte_thread_attr_t;The *rte_thread_create()* function can optionally receive an rte_thread_attr_t
object that will cause the thread to be created with the affinity and priority
described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used. An rte_thread_attr_t object can also be set to the default values by calling *rte_thread_attr_init()*.
*Priority* is represented through an enum that currently advertises two values for priority:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
The enum can be extended to allow for multiple priority levels.rte_thread_set_priority - sets the priority of a threadrte_thread_get_priority - retrieves the priority of a thread
from the OSrte_thread_attr_set_priority - updates an rte_thread_attr_t object
with a new value for priority
The user can choose thread priority through an EAL parameter, when starting an application. If EAL parameter is not used, the per-platform default value for thread priority is used. Otherwise administrator has an option to set one of available options:
--thread-prio normal
--thread-prio realtime
Example:
./dpdk-l2fwd -l 0-3 -n 4 –thread-prio normal -- -q 8 -p ffff
*Affinity* is described by the already known “rte_cpuset_t” type. rte_thread_attr_set/get_affinity - sets/gets the affinity field in a
rte_thread_attr_t object
rte_thread_set/get_affinity – sets/gets the affinity of a thread
**Errors**
A translation function that maps Windows error codes to errno-style error codes is provided.
**Future work**
The long term plan is for EAL to provide full threading support:
* Add support for conditional variables
* Additional functionality offered by pthread_*
(such as pthread_setname_np, etc.)
v15:
- Add try_lock mutex functionality. If the mutex is already owned by a different thread, the function returns immediately. Otherwise, the mutex will be acquired.
- Add function for getting the priority of a thread.
An auxiliary function that translates the OS priority to the EAL accepted ones is added.
- Fix unit tests logging, add descriptive asserts that mark test failures. Verify mutex locking, verify barrier return values. Add test for statically initialized mutexes.
- Fix Alpine build by removing the use of pthread_attr_set_affinity() and using pthread_set_affinity() after the thread is created.
v14:
- Remove patch "eal: add EAL argument for setting thread priority" This will be added later when enabling the new threading API.
- Remove priority enum value "_UNDEFINED". NORMAL is used as the default.
- Fix issue with thread return value.
v13:
- Fix syntax error in unit tests
v12:
- Fix freebsd warning about initializer in unit tests
v11:
- Add unit tests for thread API
- Rebase
v10:
- Remove patch no. 10. It will be broken down in subpatches and sent as a different patchset that depends on this one. This is done due to the ABI breaks that would be caused by patch 10.
- Replace unix/rte_thread.c with common/rte_thread.c
- Remove initializations that may prevent compiler from issuing useful warnings.
- Remove rte_thread_types.h and rte_windows_thread_types.h
- Remove unneeded priority macros (EAL_THREAD_PRIORITY*)
- Remove functions that retrieves thread handle from process handle
- Remove rte_thread_cancel() until same behavior is obtained on all platforms.
- Fix rte_thread_detach() function description,
return value and remove empty line.
- Reimplement mutex functions. Add compatible representation for mutex identifier. Add macro to replace static mutex initialization instances.
- Fix commit messages (lines too long, remove unicode symbols)
v9:
- Sign patches
v8:
- Rebase
- Add rte_thread_detach() API
- Set default priority, when user did not specify a value
v7:
Based on DmitryK's review:
- Change thread id representation
- Change mutex id representation
- Implement static mutex inititalizer for Windows
- Change barrier identifier representation
- Improve commit messages
- Add missing doxygen comments
- Split error translation function
- Improve name for affinity function
- Remove cpuset_size parameter
- Fix eal_create_cpu_map function
- Map EAL priority values to OS specific values
- Add thread wrapper for start routine
- Do not export rte_thread_cancel() on Windows
- Cleanup, fix comments, fix typos.
v6:
- improve error-translation function
- call the error translation function in rte_thread_value_get()
v5:
- update cover letter with more details on the priority argument
v4:
- fix function description
- rebase
v3:
- rebase
v2:
- revert changes that break ABI
- break up changes into smaller patches
- fix coding style issues
- fix issues with errors
- fix parameter type in examples/kni.c
Narcisa Vasile (9):
eal: add basic threading functions
eal: add thread attributes
eal/windows: translate Windows errors to errno-style errors
eal: implement functions for thread affinity management
eal: implement thread priority management functions
eal: add thread lifetime management
eal: implement functions for mutex management
eal: implement functions for thread barrier management Add unit tests for thread API
app/test/meson.build | 2 + app/test/test_threads.c | 359 +++++++++++++++++ lib/eal/common/meson.build | 1 + lib/eal/common/rte_thread.c | 496 ++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 435 ++++++++++++++++++++- lib/eal/unix/meson.build | 1 - lib/eal/unix/rte_thread.c | 92 ----- lib/eal/version.map | 22 ++ lib/eal/windows/eal_lcore.c | 176 ++++++--- lib/eal/windows/eal_windows.h | 10 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 656 ++++++++++++++++++++++++++++++-- 12 files changed, 2079 insertions(+), 173 deletions(-) create mode 100644 app/test/test_threads.c create mode 100644 lib/eal/common/rte_thread.c delete mode 100644 lib/eal/unix/rte_thread.c
Signature · 1 line
2.31.0.vfs.0.1
PATCH v15 1/9 eal: add basic threading functions
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
---
lib/eal/common/meson.build | 1 +
lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
lib/eal/include/rte_thread.h | 48 +++++++++++++++++-----
lib/eal/unix/meson.build | 1 -
lib/eal/version.map | 3 ++
lib/eal/windows/rte_thread.c | 17 ++++++++
6 files changed, 95 insertions(+), 32 deletions(-)
rename lib/eal/{unix => common}/rte_thread.c (66%)lib/eal/common/meson.build +1 -0
@@ -51,5 +51,6 @@ if not is_windows 'hotplug_mp.c', 'malloc_mp.c', 'rte_keepalive.c', + 'rte_thread.c' ) endif
lib/eal/common/rte_thread.c renamed from lib/eal/unix/rte_thread.c +35 -22
107 lines not on this page · raw message
lib/eal/include/rte_thread.h +39 -9
83 lines not on this page · raw message
lib/eal/unix/meson.build +0 -1
@@ -6,5 +6,4 @@ sources += files( 'eal_unix_memory.c', 'eal_unix_timer.c', 'eal_firmware.c', - 'rte_thread.c', )
lib/eal/version.map +3 -0
@@ -420,6 +420,9 @@ EXPERIMENTAL { # added in 21.08 rte_power_monitor_multi; # WINDOWS_NO_EXPORT + + rte_thread_self; + rte_thread_equal; }; INTERNAL {
lib/eal/windows/rte_thread.c +17 -0
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright 2021 Mellanox Technologies, Ltd +* Copyright(c) 2021 Microsoft Corporation */ #include <rte_common.h>
@@ -11,6 +12,22 @@ struct eal_tls_key {DWORD thread_index; }; +rte_thread_t +rte_thread_self (void ) +{ +rte_thread_t thread_id; + + thread_id.opaque_id =GetCurrentThreadId (); + +return thread_id; +} + +int +rte_thread_equal (rte_thread_t t1,rte_thread_t t2) +{ +return t1.opaque_id == t2.opaque_id; +} +int rte_thread_key_create (rte_thread_key *key, __rte_unused void (*destructor)(void *))
Signature · 1 line
2.31.0.vfs.0.1
PATCH v15 2/9 eal: add thread attributes
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.
Priority is represented through an enum that allows for two levels:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
Affinity is described by the rte_cpuset_t type.
An rte_thread_attr_t object can be set to the default values by calling rte_thread_attr_init().
--- lib/eal/common/rte_thread.c | 46 ++++++++++++++++++ lib/eal/include/rte_thread.h | 91 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 44 +++++++++++++++++ 4 files changed, 185 insertions(+)
lib/eal/common/rte_thread.c +46 -0
@@ -9,6 +9,7 @@#include <string.h> #include <rte_common.h> +#include <rte_debug.h> #include <rte_errno.h> #include <rte_log.h> #include <rte_thread.h>
@@ -33,6 +34,51 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_attr_init (rte_thread_attr_t *attr) +{ +RTE_VERIFY (attr !=NULL ); + +CPU_ZERO (&attr->cpuset); + attr->priority =RTE_THREAD_PRIORITY_NORMAL ; + +return 0 ; +} + +int +rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + thread_attr->cpuset = *cpuset; + +return 0 ; +} + +int +rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + *cpuset = thread_attr->cpuset; + +return 0 ; +} + +int +rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, +enum rte_thread_priority priority) +{ +RTE_VERIFY (thread_attr !=NULL ); + + thread_attr->priority = priority; +return 0 ; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +91 -0
103 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -423,6 +423,10 @@ EXPERIMENTAL { rte_thread_self; rte_thread_equal; + rte_thread_attr_init; + rte_thread_attr_get_affinity; + rte_thread_attr_set_affinity; + rte_thread_attr_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v15 3/9 eal/windows: translate Windows errors to errno-style errors
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function to translate Windows error codes to errno-style error codes. The possible return values are chosen so that we have as much semantical compatibility between platforms as possible.
--- lib/eal/common/rte_thread.c | 6 +-- lib/eal/include/rte_thread.h | 5 +- lib/eal/windows/rte_thread.c | 95 +++++++++++++++++++++++++++--------- 3 files changed, 76 insertions(+), 30 deletions(-)
lib/eal/common/rte_thread.c +3 -3
@@ -47,7 +47,7 @@ rte_thread_attr_init(rte_thread_attr_t *attr)int rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -59,7 +59,7 @@ rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -71,7 +71,7 @@ rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, -enum rte_thread_priority priority) +enum rte_thread_priority priority) {RTE_VERIFY (thread_attr !=NULL );
lib/eal/include/rte_thread.h +2 -3
@@ -233,9 +233,8 @@ int rte_thread_value_set(rte_thread_key key, const void *value);* * @return * On success, value data pointer (can also be NULL). -* On failure, NULL and an error number is set in rte_errno. -* rte_errno can be: EINVAL - Invalid parameter passed. -* ENOEXEC - Specific OS error. +* On failure, NULL and a positive error number is set in rte_errno. +* */ __rte_experimental void *rte_thread_value_get(rte_thread_key key);
lib/eal/windows/rte_thread.c +71 -24
165 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v15 4/9 eal: implement functions for thread affinity management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement functions for getting/setting thread affinity. Threads can be pinned to specific cores by setting their affinity attribute.
--- lib/eal/common/rte_thread.c | 16 ++++ lib/eal/include/rte_thread.h | 36 +++++++ lib/eal/version.map | 2 + lib/eal/windows/eal_lcore.c | 176 +++++++++++++++++++++++++--------- lib/eal/windows/eal_windows.h | 10 ++ lib/eal/windows/rte_thread.c | 125 +++++++++++++++++++++++- 6 files changed, 319 insertions(+), 46 deletions(-)
lib/eal/common/rte_thread.c +16 -0
@@ -34,6 +34,22 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_set_affinity_by_id (rte_thread_t thread_id, +const rte_cpuset_t *cpuset) +{ +return pthread_setaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} + +int +rte_thread_get_affinity_by_id (rte_thread_t thread_id, +rte_cpuset_t *cpuset) +{ +return pthread_getaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +36 -0
@@ -85,6 +85,42 @@ int rte_thread_equal(rte_thread_t t1, rte_thread_t t2);#ifdef RTE_HAS_CPUSET +/** +* Set the affinity of thread 'thread_id' to the cpu set +* specified by 'cpuset'. +* +* @param thread_id +* Id of the thread for which to set the affinity. +* +* @param cpuset +* Pointer to CPU affinity to set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_affinity_by_id(rte_thread_t thread_id, +const rte_cpuset_t *cpuset); + +/** +* Get the affinity of thread 'thread_id' and store it +* in 'cpuset'. +* +* @param thread_id +* Id of the thread for which to get the affinity. +* +* @param cpuset +* Pointer for storing the affinity value. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_get_affinity_by_id(rte_thread_t thread_id, +rte_cpuset_t *cpuset); +/** * Initialize the attributes of a thread. * These attributes can be passed to the rte_thread_create() function
lib/eal/version.map +2 -0
@@ -427,6 +427,8 @@ EXPERIMENTAL { rte_thread_attr_get_affinity; rte_thread_attr_set_affinity; rte_thread_attr_set_priority; + rte_thread_get_affinity_by_id; + rte_thread_set_affinity_by_id; }; INTERNAL {
lib/eal/windows/eal_lcore.c +131 -45
231 lines not on this page · raw message
lib/eal/windows/eal_windows.h +10 -0
@@ -55,6 +55,16 @@ int eal_thread_create(pthread_t *thread);*/ unsigned int eal_socket_numa_node (unsigned int socket_id); +/** +* Get pointer to the group affinity for the cpu. +* +* @param cpu_index +* Index of the cpu, as it comes from rte_cpuset_t. +* @return +* Pointer to the group affinity for the cpu. +*/ +PGROUP_AFFINITY eal_get_cpu_affinity (size_t cpu_index); +/** * Schedule code for execution in the interrupt thread. *
lib/eal/windows/rte_thread.c +124 -1
137 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v15 5/9 eal: implement thread priority management functions
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for setting and getting the priority of a thread. Priorities on multiple platforms are similarly determined by a priority value and a priority class/policy.
On Linux, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* policy SCHED_OTHER
* priority value: (sched_get_priority_min(SCHED_OTHER) +
sched_get_priority_max(SCHED_OTHER))/2;
RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* policy SCHED_RR
* priority value: sched_get_priority_max(SCHED_RR);
On Windows, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* class NORMAL_PRIORITY_CLASS
* priority THREAD_PRIORITY_NORMAL RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* class REALTIME_PRIORITY_CLASS
* priority THREAD_PRIORITY_TIME_CRITICAL
--- lib/eal/common/rte_thread.c | 96 ++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 34 ++++++++++ lib/eal/version.map | 2 + lib/eal/windows/rte_thread.c | 127 +++++++++++++++++++++++++++++++++++ 4 files changed, 259 insertions(+)
lib/eal/common/rte_thread.c +96 -0
@@ -50,6 +50,102 @@ rte_thread_get_affinity_by_id(rte_thread_t thread_id, sizeof(*cpuset), cpuset); } +static int +thread_map_priority_to_os_value (enum rte_thread_priority eal_pri, +int *os_pri,int *pol) +{ +/* Clear the output parameters */ + *os_pri =sched_get_priority_min (SCHED_OTHER ) -1 ; + *pol =-1 ; + +switch (eal_pri) { +case RTE_THREAD_PRIORITY_NORMAL : + *pol =SCHED_OTHER ; + +/* +* Choose the middle of the range to represent +* the priority 'normal'. +* On Linux, this should be 0, since both +* sched_get_priority_min/_max return 0 for SCHED_OTHER. +*/ + *os_pri = (sched_get_priority_min (SCHED_OTHER ) + +sched_get_priority_max (SCHED_OTHER ))/2 ; +break ; +case RTE_THREAD_PRIORITY_REALTIME_CRITICAL : + *pol =SCHED_RR ; + *os_pri =sched_get_priority_max (SCHED_RR ); +break ; +default : +RTE_LOG (DEBUG ,EAL ,"The requested priority value is invalid.\n" ); +return EINVAL ; + } +return 0 ; +} + +static int +thread_map_os_priority_to_eal_priority (int policy,int os_pri, +enum rte_thread_priority *eal_pri) +{ +switch (policy) { +case SCHED_OTHER : +if (os_pri == (sched_get_priority_min (SCHED_OTHER ) + +sched_get_priority_max (SCHED_OTHER ))/2 ) { + *eal_pri =RTE_THREAD_PRIORITY_NORMAL ; +return 0 ; + } +break ; +case SCHED_RR : +if (os_pri ==sched_get_priority_max (SCHED_RR )) { + *eal_pri =RTE_THREAD_PRIORITY_REALTIME_CRITICAL ; +return 0 ; + } +break ; +default : +RTE_LOG (DEBUG ,EAL ,"The OS priority value does not map to an EAL-defined priority.\n" ); +return EINVAL ; + } + +return 0 ; +} + +int +rte_thread_get_priority (rte_thread_t thread_id, +enum rte_thread_priority *priority) +{ +int ret; +int policy; +struct sched_param param; + + ret =pthread_getschedparam (thread_id.opaque_id, &policy, ¶m); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_getschedparam failed\n" ); + goto cleanup; + } + +return thread_map_os_priority_to_eal_priority (policy, + param.sched_priority, priority); + +cleanup: +return ret; +} + +int +rte_thread_set_priority (rte_thread_t thread_id, +enum rte_thread_priority priority) +{ +int ret; +int policy; +struct sched_param param; + + ret =thread_map_priority_to_os_value (priority, ¶m.sched_priority, + &policy); +if (ret !=0 ) +return ret; + +return pthread_setschedparam ((pthread_t )thread_id.opaque_id, + policy, ¶m); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +34 -0
@@ -213,6 +213,40 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp);#endif /* RTE_HAS_CPUSET */ +/** +* Get the priority of a thread. +* +* @param thread_id +* Id of the thread for which to get priority. +* +* @param priority +* Location to store the retrieved priority. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_get_priority(rte_thread_t thread_id, +enum rte_thread_priority *priority); + +/** +* Set the priority of a thread. +* +* @param thread_id +* Id of the thread for which to set priority. +* +* @param priority +* Priority value to be set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_priority(rte_thread_t thread_id, +enum rte_thread_priority priority); +/** * Create a TLS data key visible to all threads in the process. * the created key is later used to get/set a value.
lib/eal/version.map +2 -0
@@ -429,6 +429,8 @@ EXPERIMENTAL { rte_thread_attr_set_priority; rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; + rte_thread_get_priority; + rte_thread_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +127 -0
133 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v15 6/9 eal: add thread lifetime management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for thread creation, joining, detaching.
The *rte_thread_create()* function can optionally receive
an rte_thread_attr_t object that will cause the thread to be created with the affinity and priority described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used.
On Windows, the function executed by a thread when the thread starts is represeneted by a function pointer of type DWORD (*func) (void*). On other platforms, the function pointer is a void* (*func) (void*).
Performing a cast between these two types of function pointers to uniformize the API on all platforms may result in undefined behavior. TO fix this issue, a wrapper that respects the signature required by CreateThread() has been created on Windows.
--- lib/eal/common/rte_thread.c | 103 ++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 55 +++++++++++++ lib/eal/version.map | 3 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 134 ++++++++++++++++++++++++++++++++ 5 files changed, 296 insertions(+), 1 deletion(-)
lib/eal/common/rte_thread.c +103 -0
@@ -191,6 +191,109 @@ rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,return 0 ; } +int +rte_thread_create (rte_thread_t *thread_id, +const rte_thread_attr_t *thread_attr, +rte_thread_func thread_func,void *args) +{ +int ret =0 ; +pthread_attr_t attr; +pthread_attr_t *attrp =NULL ; +struct sched_param param = { + .sched_priority =0 , + }; +int policy =SCHED_OTHER ; + +if (thread_attr !=NULL ) { + ret =pthread_attr_init (&attr); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_init failed\n" ); + goto cleanup; + } + + attrp = &attr; + +/* +* Set the inherit scheduler parameter to explicit, +* otherwise the priority attribute is ignored. +*/ + ret =pthread_attr_setinheritsched (attrp, +PTHREAD_EXPLICIT_SCHED ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setinheritsched failed\n" ); + goto cleanup; + } + + ret =thread_map_priority_to_os_value (thread_attr->priority, + ¶m.sched_priority, &policy); +if (ret !=0 ) + goto cleanup; + + ret =pthread_attr_setschedpolicy (attrp, policy); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedpolicy failed\n" ); + goto cleanup; + } + + ret =pthread_attr_setschedparam (attrp, ¶m); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedparam failed\n" ); + goto cleanup; + } + } + + ret =pthread_create ((pthread_t *)&thread_id->opaque_id, attrp, + thread_func, args); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_create failed\n" ); + goto cleanup; + } + +if (thread_attr !=NULL &&CPU_COUNT (&thread_attr->cpuset) >0 ) { + ret =pthread_setaffinity_np (thread_id->opaque_id, +sizeof (thread_attr->cpuset), + &thread_attr->cpuset); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_setaffinity_np failed\n" ); + goto cleanup; + } + } + +cleanup: +if (attrp !=NULL ) +pthread_attr_destroy (&attr); + +return ret; +} + +int +rte_thread_join (rte_thread_t thread_id,unsigned long *value_ptr) +{ +int ret =0 ; +void *res =NULL ; +void **pres =NULL ; + +if (value_ptr !=NULL ) + pres = &res; + + ret =pthread_join ((pthread_t )thread_id.opaque_id, pres); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_join failed\n" ); +return ret; + } + +if (value_ptr !=NULL && *pres !=NULL ) + *value_ptr = *(unsigned long *)(*pres); + +return 0 ; +} + +int +rte_thread_detach (rte_thread_t thread_id) +{ +return pthread_detach ((pthread_t )thread_id.opaque_id); +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +55 -0
67 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -431,6 +431,9 @@ EXPERIMENTAL { rte_thread_set_affinity_by_id; rte_thread_get_priority; rte_thread_set_priority; + rte_thread_create; + rte_thread_join; + rte_thread_detach; }; INTERNAL {
lib/eal/windows/include/sched.h +1 -1
@@ -44,7 +44,7 @@ typedef struct _rte_cpuset_s { (1LL << _WHICH_BIT(b))) != 0LL)static inline int -count_cpu (rte_cpuset_t *s) +count_cpu (const rte_cpuset_t *s) {unsigned int _i;int count =0 ;
lib/eal/windows/rte_thread.c +134 -0
146 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v15 7/9 eal: implement functions for mutex management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for mutex init, destroy, lock, unlock, trylock.
Add RTE_STATIC_MUTEX macro to replace static initialization of mutexes.
Windows does not have a static initializer. Initialization is only done through InitializeCriticalSection().
The RTE_STATIC_MUTEX calls into the rte_thread_mutex_init() function that performs the actual mutex initialization.
--- lib/eal/common/rte_thread.c | 69 ++++++++++++++++++++++ lib/eal/include/rte_thread.h | 108 +++++++++++++++++++++++++++++++++++ lib/eal/version.map | 5 ++ lib/eal/windows/rte_thread.c | 64 +++++++++++++++++++++ 4 files changed, 246 insertions(+)
lib/eal/common/rte_thread.c +69 -0
@@ -294,6 +294,75 @@ rte_thread_detach(rte_thread_t thread_id)return pthread_detach ((pthread_t )thread_id.opaque_id); } +int +rte_thread_mutex_init (rte_thread_mutex *mutex) +{ +int ret =0 ; +pthread_mutex_t *m =NULL ; + +RTE_VERIFY (mutex !=NULL ); + + m =calloc (1 ,sizeof (*m)); +if (m ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize mutex. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + + ret =pthread_mutex_init (m,NULL ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init mutex. ret = %d\n" , ret); + goto cleanup; + } + + mutex->mutex_id = m; + m =NULL ; + +cleanup: +free (m); +return ret; +} + +int +rte_thread_mutex_lock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_lock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_unlock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_unlock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_try_lock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_trylock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_destroy (rte_thread_mutex *mutex) +{ +int ret =0 ; +RTE_VERIFY (mutex !=NULL ); + + ret =pthread_mutex_destroy ((pthread_mutex_t *)mutex->mutex_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Unable to destroy mutex, ret = %d\n" , ret); + +free (mutex->mutex_id); + mutex->mutex_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +108 -0
126 lines not on this page · raw message
lib/eal/version.map +5 -0
@@ -434,6 +434,11 @@ EXPERIMENTAL { rte_thread_create; rte_thread_join; rte_thread_detach; + rte_thread_mutex_init; + rte_thread_mutex_lock; + rte_thread_mutex_unlock; + rte_thread_mutex_try_lock; + rte_thread_mutex_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +64 -0
70 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v15 8/9 eal: implement functions for thread barrier management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for barrier init, destroy, wait.
A portable type is used to represent a barrier identifier. The rte_thread_barrier_wait() function returns the same value on all platforms.
--- lib/eal/common/rte_thread.c | 61 ++++++++++++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 58 ++++++++++++++++++++++++++++++++++ lib/eal/version.map | 3 ++ lib/eal/windows/rte_thread.c | 56 +++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+)
lib/eal/common/rte_thread.c +61 -0
@@ -363,6 +363,67 @@ rte_thread_mutex_destroy(rte_thread_mutex *mutex)return ret; } +int +rte_thread_barrier_init (rte_thread_barrier *barrier,int count) +{ +int ret =0 ; +pthread_barrier_t *pthread_barrier =NULL ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (count >0 ); + + pthread_barrier =calloc (1 ,sizeof (*pthread_barrier)); +if (pthread_barrier ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize barrier. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + ret =pthread_barrier_init (pthread_barrier,NULL , count); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init barrier, ret = %d\n" , ret); + goto cleanup; + } + + barrier->barrier_id = pthread_barrier; + pthread_barrier =NULL ; + +cleanup: +free (pthread_barrier); +return ret; +} + +int +rte_thread_barrier_wait (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); +RTE_VERIFY (barrier->barrier_id !=NULL ); + + ret =pthread_barrier_wait (barrier->barrier_id); +if (ret ==PTHREAD_BARRIER_SERIAL_THREAD ) + ret =RTE_THREAD_BARRIER_SERIAL_THREAD ; + +return ret; +} + +int +rte_thread_barrier_destroy (rte_thread_barrier *barrier) +{ +int ret =0 ; + +RTE_VERIFY (barrier !=NULL ); + + ret =pthread_barrier_destroy (barrier->barrier_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Failed to destroy barrier: %d\n" , ret); + +free (barrier->barrier_id); + barrier->barrier_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +58 -0
70 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -439,6 +439,9 @@ EXPERIMENTAL { rte_thread_mutex_unlock; rte_thread_mutex_try_lock; rte_thread_mutex_destroy; + rte_thread_barrier_init; + rte_thread_barrier_wait; + rte_thread_barrier_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v15 9/9 Add unit tests for thread API
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
As a new API for threading is introduced,
a set of unit tests have been added to test the new interface. The tests verify that:
* mutexes and barriers behave as expected
* thread properties are applied correctly
* the thread id is retrieved correctly
* thread creation/destruction works properly
--- app/test/meson.build | 2 + app/test/test_threads.c | 359 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 361 insertions(+) create mode 100644 app/test/test_threads.c
app/test/meson.build +2 -0
@@ -141,6 +141,7 @@ test_sources = files( 'test_table_tables.c', 'test_tailq.c', 'test_thash.c', + 'test_threads.c', 'test_timer.c', 'test_timer_perf.c', 'test_timer_racecond.c',
@@ -277,6 +278,7 @@ fast_tests = [ ['reorder_autotest', true], ['service_autotest', true], ['thash_autotest', true], + ['threads_autotest', true], ['trace_autotest', true], ]
app/test/test_threads.c new file +359 -0
359 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
v16 cover eal: Add EAL API for threading
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
EAL thread API
**Problem Statement**
DPDK currently uses the pthread interface to create and manage threads. Windows does not support the POSIX thread programming model, so it currently
relies on a header file that hides the Windows calls under pthread matched interfaces. Given that EAL should isolate the environment specifics from the applications and libraries and mediate
all the communication with the operating systems, a new EAL interface is needed for thread management.
**Goals**
* Introduce a generic EAL API for threading support that will remove the current Windows pthread.h shim.
* Replace references to pthread_* across the DPDK codebase with the new RTE_THREAD_* API.
* Allow users to choose between using the RTE_THREAD_* API or a 3rd party thread library through a configuration option.
**Design plan**
New API main files:
* rte_thread.h (librte_eal/include)
* rte_thread.c (librte_eal/windows)
* rte_thread.c (librte_eal/common)
**A schematic example of the design**
--------------------------------------------------lib/librte_eal/include/rte_thread.h
int rte_thread_create();
lib/librte_eal/common/rte_thread.c
int rte_thread_create()
{
return pthread_create();
}lib/librte_eal/windows/rte_thread.c
int rte_thread_create()
{
return CreateThread();
}-----------------------------------------------------
**Thread attributes**
When or after a thread is created, specific characteristics of the thread can be adjusted. Given that the thread characteristics that are of interest for DPDK applications are affinity and priority, the following structure that represents thread attributes has been defined:
typedef struct
{
enum rte_thread_priority priority;
rte_cpuset_t cpuset;
} rte_thread_attr_t;The *rte_thread_create()* function can optionally receive an rte_thread_attr_t
object that will cause the thread to be created with the affinity and priority
described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used. An rte_thread_attr_t object can also be set to the default values by calling *rte_thread_attr_init()*.
*Priority* is represented through an enum that currently advertises two values for priority:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
The enum can be extended to allow for multiple priority levels.rte_thread_set_priority - sets the priority of a threadrte_thread_get_priority - retrieves the priority of a thread
from the OSrte_thread_attr_set_priority - updates an rte_thread_attr_t object
with a new value for priority
The user can choose thread priority through an EAL parameter, when starting an application. If EAL parameter is not used, the per-platform default value for thread priority is used. Otherwise administrator has an option to set one of available options:
--thread-prio normal
--thread-prio realtime
Example:
./dpdk-l2fwd -l 0-3 -n 4 –thread-prio normal -- -q 8 -p ffff
*Affinity* is described by the already known “rte_cpuset_t” type. rte_thread_attr_set/get_affinity - sets/gets the affinity field in a
rte_thread_attr_t object
rte_thread_set/get_affinity – sets/gets the affinity of a thread
**Errors**
A translation function that maps Windows error codes to errno-style error codes is provided.
**Future work**
The long term plan is for EAL to provide full threading support:
* Add support for conditional variables
* Additional functionality offered by pthread_*
(such as pthread_setname_np, etc.)
v16:
- Fix warning on freebsd by adding cast
- Change affinity unit test to consider ases when the requested CPU are not available on the system.
- Fix priority unit test to avoid termination of thread before the priority is checked.
v15:
- Add try_lock mutex functionality. If the mutex is already owned by a different thread, the function returns immediately. Otherwise, the mutex will be acquired.
- Add function for getting the priority of a thread.
An auxiliary function that translates the OS priority to the EAL accepted ones is added.
- Fix unit tests logging, add descriptive asserts that mark test failures. Verify mutex locking, verify barrier return values. Add test for statically initialized mutexes.
- Fix Alpine build by removing the use of pthread_attr_set_affinity() and using pthread_set_affinity() after the thread is created.
v14:
- Remove patch "eal: add EAL argument for setting thread priority" This will be added later when enabling the new threading API.
- Remove priority enum value "_UNDEFINED". NORMAL is used as the default.
- Fix issue with thread return value.
v13:
- Fix syntax error in unit tests
v12:
- Fix freebsd warning about initializer in unit tests
v11:
- Add unit tests for thread API
- Rebase
v10:
- Remove patch no. 10. It will be broken down in subpatches and sent as a different patchset that depends on this one. This is done due to the ABI breaks that would be caused by patch 10.
- Replace unix/rte_thread.c with common/rte_thread.c
- Remove initializations that may prevent compiler from issuing useful warnings.
- Remove rte_thread_types.h and rte_windows_thread_types.h
- Remove unneeded priority macros (EAL_THREAD_PRIORITY*)
- Remove functions that retrieves thread handle from process handle
- Remove rte_thread_cancel() until same behavior is obtained on all platforms.
- Fix rte_thread_detach() function description,
return value and remove empty line.
- Reimplement mutex functions. Add compatible representation for mutex identifier. Add macro to replace static mutex initialization instances.
- Fix commit messages (lines too long, remove unicode symbols)
v9:
- Sign patches
v8:
- Rebase
- Add rte_thread_detach() API
- Set default priority, when user did not specify a value
v7:
Based on DmitryK's review:
- Change thread id representation
- Change mutex id representation
- Implement static mutex inititalizer for Windows
- Change barrier identifier representation
- Improve commit messages
- Add missing doxygen comments
- Split error translation function
- Improve name for affinity function
- Remove cpuset_size parameter
- Fix eal_create_cpu_map function
- Map EAL priority values to OS specific values
- Add thread wrapper for start routine
- Do not export rte_thread_cancel() on Windows
- Cleanup, fix comments, fix typos.
v6:
- improve error-translation function
- call the error translation function in rte_thread_value_get()
v5:
- update cover letter with more details on the priority argument
v4:
- fix function description
- rebase
v3:
- rebase
v2:
- revert changes that break ABI
- break up changes into smaller patches
- fix coding style issues
- fix issues with errors
- fix parameter type in examples/kni.c
Narcisa Vasile (9):
eal: add basic threading functions
eal: add thread attributes
eal/windows: translate Windows errors to errno-style errors
eal: implement functions for thread affinity management
eal: implement thread priority management functions
eal: add thread lifetime management
eal: implement functions for mutex management
eal: implement functions for thread barrier management Add unit tests for thread API
app/test/meson.build | 2 + app/test/test_threads.c | 372 ++++++++++++++++++ lib/eal/common/meson.build | 1 + lib/eal/common/rte_thread.c | 497 ++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 435 ++++++++++++++++++++- lib/eal/unix/meson.build | 1 - lib/eal/unix/rte_thread.c | 92 ----- lib/eal/version.map | 22 ++ lib/eal/windows/eal_lcore.c | 176 ++++++--- lib/eal/windows/eal_windows.h | 10 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 656 ++++++++++++++++++++++++++++++-- 12 files changed, 2093 insertions(+), 173 deletions(-) create mode 100644 app/test/test_threads.c create mode 100644 lib/eal/common/rte_thread.c delete mode 100644 lib/eal/unix/rte_thread.c
Signature · 1 line
2.31.0.vfs.0.1
PATCH v16 1/9 eal: add basic threading functions
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
---
lib/eal/common/meson.build | 1 +
lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
lib/eal/include/rte_thread.h | 48 +++++++++++++++++-----
lib/eal/unix/meson.build | 1 -
lib/eal/version.map | 3 ++
lib/eal/windows/rte_thread.c | 17 ++++++++
6 files changed, 95 insertions(+), 32 deletions(-)
rename lib/eal/{unix => common}/rte_thread.c (66%)lib/eal/common/meson.build +1 -0
@@ -51,5 +51,6 @@ if not is_windows 'hotplug_mp.c', 'malloc_mp.c', 'rte_keepalive.c', + 'rte_thread.c' ) endif
lib/eal/common/rte_thread.c renamed from lib/eal/unix/rte_thread.c +35 -22
107 lines not on this page · raw message
lib/eal/include/rte_thread.h +39 -9
83 lines not on this page · raw message
lib/eal/unix/meson.build +0 -1
@@ -6,5 +6,4 @@ sources += files( 'eal_unix_memory.c', 'eal_unix_timer.c', 'eal_firmware.c', - 'rte_thread.c', )
lib/eal/version.map +3 -0
@@ -420,6 +420,9 @@ EXPERIMENTAL { # added in 21.08 rte_power_monitor_multi; # WINDOWS_NO_EXPORT + + rte_thread_self; + rte_thread_equal; }; INTERNAL {
lib/eal/windows/rte_thread.c +17 -0
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: BSD-3-Clause * Copyright 2021 Mellanox Technologies, Ltd +* Copyright(c) 2021 Microsoft Corporation */ #include <rte_common.h>
@@ -11,6 +12,22 @@ struct eal_tls_key {DWORD thread_index; }; +rte_thread_t +rte_thread_self (void ) +{ +rte_thread_t thread_id; + + thread_id.opaque_id =GetCurrentThreadId (); + +return thread_id; +} + +int +rte_thread_equal (rte_thread_t t1,rte_thread_t t2) +{ +return t1.opaque_id == t2.opaque_id; +} +int rte_thread_key_create (rte_thread_key *key, __rte_unused void (*destructor)(void *))
Signature · 1 line
2.31.0.vfs.0.1
Re: [dpdk-dev] [PATCH v16 1/9] eal: add basic threading functions
09/10/2021 09:41, Narcisa Ana Maria Vasile:
Quoted 10 lines
From: Narcisa Vasile <[email protected]>
Use a portable, type-safe representation for the thread identifier. Add functions for comparing thread ids and obtaining the thread id for the current thread.
Signed-off-by Narcisa Vasile <[email protected]>--- lib/eal/common/meson.build | 1 + lib/eal/{unix => common}/rte_thread.c | 57 ++++++++++++++++-----------
There is no explanation about this move.
Quoted 6 lines
lib/eal/include/rte_thread.h | 48 +++++++++++++++++-----
lib/eal/unix/meson.build | 1 -
lib/eal/version.map | 3 ++
lib/eal/windows/rte_thread.c | 17 ++++++++
6 files changed, 95 insertions(+), 32 deletions(-)
rename lib/eal/{unix => common}/rte_thread.c (66%)[...]
lib/eal/common/rte_thread.c struct eal_tls_key { · line 48
Quoted 4 lines
lib/eal/common/rte_thread.c renamed from lib/eal/unix/rte_thread.c +2
-2- err =pthread_key_create (&((*key)->thread_index), destructor); -if (err) { + err =pthread_key_create (&(k->thread_index), destructor); +if (err !=0 ) {
It looks wrong to call pthread functions in a "common" file.
PATCH v16 2/9 eal: add thread attributes
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.
Priority is represented through an enum that allows for two levels:
- RTE_THREAD_PRIORITY_NORMAL
- RTE_THREAD_PRIORITY_REALTIME_CRITICAL
Affinity is described by the rte_cpuset_t type.
An rte_thread_attr_t object can be set to the default values by calling rte_thread_attr_init().
--- lib/eal/common/rte_thread.c | 46 ++++++++++++++++++ lib/eal/include/rte_thread.h | 91 ++++++++++++++++++++++++++++++++++++ lib/eal/version.map | 4 ++ lib/eal/windows/rte_thread.c | 44 +++++++++++++++++ 4 files changed, 185 insertions(+)
lib/eal/common/rte_thread.c +46 -0
@@ -9,6 +9,7 @@#include <string.h> #include <rte_common.h> +#include <rte_debug.h> #include <rte_errno.h> #include <rte_log.h> #include <rte_thread.h>
@@ -33,6 +34,51 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_attr_init (rte_thread_attr_t *attr) +{ +RTE_VERIFY (attr !=NULL ); + +CPU_ZERO (&attr->cpuset); + attr->priority =RTE_THREAD_PRIORITY_NORMAL ; + +return 0 ; +} + +int +rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + thread_attr->cpuset = *cpuset; + +return 0 ; +} + +int +rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, +rte_cpuset_t *cpuset) +{ +RTE_VERIFY (thread_attr !=NULL ); +RTE_VERIFY (cpuset !=NULL ); + + *cpuset = thread_attr->cpuset; + +return 0 ; +} + +int +rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, +enum rte_thread_priority priority) +{ +RTE_VERIFY (thread_attr !=NULL ); + + thread_attr->priority = priority; +return 0 ; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +91 -0
103 lines not on this page · raw message
lib/eal/version.map +4 -0
@@ -423,6 +423,10 @@ EXPERIMENTAL { rte_thread_self; rte_thread_equal; + rte_thread_attr_init; + rte_thread_attr_get_affinity; + rte_thread_attr_set_affinity; + rte_thread_attr_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +44 -0
56 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
Re: [dpdk-dev] [PATCH v16 2/9] eal: add thread attributes
09/10/2021 09:41, Narcisa Ana Maria Vasile:
Quoted 10 lines
From: Narcisa Vasile <[email protected]>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.Priority is represented through an enum that allows for two levels:
-RTE_THREAD_PRIORITY_NORMAL
-RTE_THREAD_PRIORITY_REALTIME_CRITICAL
It doesn't say how do you translate these priorites in POSIX and win32.
Quoted 6 lines
Affinity is described by the
rte_cpuset_ttype.An
rte_thread_attr_tobject can be set to the default values by callingrte_thread_attr_init().Signed-off-by Narcisa Vasile <[email protected]>
[...]
Quoted 2 lines
lib/eal/common/rte_thread.c | 46 ++++++++++++++++++ lib/eal/windows/rte_thread.c | 44 +++++++++++++++++
These 2 files look like code duplication.
Re: [dpdk-dev] [PATCH v16 2/9] eal: add thread attributes
Quoted 8 lines · Thomas Monjalon
09/10/2021 09:41, Narcisa Ana Maria Vasile:
Quoted 7 lines
From: Narcisa Vasile <[email protected]>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.
Quoted 5 lines
Quoted 3 lines
Priority is represented through an enum that allows for two levels:
-RTE_THREAD_PRIORITY_NORMAL
-RTE_THREAD_PRIORITY_REALTIME_CRITICALIt doesn't say how do you translate these priorites in POSIX and win32.
I'll send a new version with a better commit message.
Thread priorities on both Linux-based and Windows platforms are similarly constructed from a class/policy + priority value. Currently in DPDK, most threads operate at the OS-default priority level but there are cases when increasing the priority is useful. For example, the Mellanox data path acceleration driver requires realtime thread priority. Similarly, some Windows applications will require elevated priority.
For these reasons, EAL will advertise 2 priority levels which are named suggestively "normal" and "realtime_critical" and are computed as follows:
For Linux and similar platforms:
* EAL "normal" priority corresponds to the (default) SCHED_OTHER policy + a priority value of (sched_get_priority_min(SCHED_OTHER) + sched_get_priority_max(SCHED_OTHER))/2. Note that on Linux the resulting priority value will be 0,
in accordance to the docs guidance that mention the value should be 0 for SCHED_OTHER policy.
* EAL "realtime" priority corresponds to the SCHED_RR policy + a priority value of sched_get_priority_max(SCHED_RR);
For Windows:
* EAL "normal" corresponds to class NORMAL_PRIORITY_CLASS + priority THREAD_PRIORITY_NORMAL
* EAL "realtime_critical" corresponds to class REALTIME_PRIORITY_CLASS + priority THREAD_PRIORITY_TIME_CRITICAL
Quoted 14 lines
Quoted 7 lines
Affinity is described by the
rte_cpuset_ttype.An
rte_thread_attr_tobject can be set to the default values by callingrte_thread_attr_init().Signed-off-by Narcisa Vasile <[email protected]>[...]
Quoted 2 lines
lib/eal/common/rte_thread.c | 46 ++++++++++++++++++ lib/eal/windows/rte_thread.c | 44 +++++++++++++++++These 2 files look like code duplication.
Re: [dpdk-dev] [PATCH v16 2/9] eal: add thread attributes
09/11/2021 02:59, Narcisa Ana Maria Vasile:
Quoted 15 lines · Thomas Monjalon
Quoted 8 lines
09/10/2021 09:41, Narcisa Ana Maria Vasile:
Quoted 7 lines
From: Narcisa Vasile <[email protected]>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.Quoted 5 lines
Quoted 3 lines
Priority is represented through an enum that allows for two levels:
-RTE_THREAD_PRIORITY_NORMAL
-RTE_THREAD_PRIORITY_REALTIME_CRITICALIt doesn't say how do you translate these priorites in POSIX and win32.
Quoted 7 lines
I'll send a new version with a better commit message.
Thread priorities on both Linux-based and Windows platforms are similarly constructed from a class/policy + priority value. Currently in DPDK, most threads operate at the OS-default priority level but there are cases when increasing the priority is useful. For example, the Mellanox data path acceleration driver requires realtime thread priority. Similarly, some Windows applications will require elevated priority.
It should not. We should not use realtime priority.
Quoted 17 lines
For these reasons, EAL will advertise 2 priority levels which are named suggestively "normal" and "
realtime_critical" and are computed as follows:For Linux and similar platforms:
* EAL "normal" priority corresponds to the (default)SCHED_OTHERpolicy + a priority value of (sched_get_priority_min(SCHED_OTHER)+ sched_get_priority_max(SCHED_OTHER))/2. Note that on Linux the resulting priority value will be 0,
in accordance to the docs guidance that mention the value should be 0 forSCHED_OTHERpolicy.* EAL "realtime" priority corresponds to the
SCHED_RRpolicy + a priority value ofsched_get_priority_max(SCHED_RR);For Windows:
* EAL "normal" corresponds to classNORMAL_PRIORITY_CLASS+ priorityTHREAD_PRIORITY_NORMAL
* EAL "realtime_critical" corresponds to classREALTIME_PRIORITY_CLASS+ priorityTHREAD_PRIORITY_TIME_CRITICAL
Re: [dpdk-dev] [PATCH v16 2/9] eal: add thread attributes
Quoted 24 lines · Thomas Monjalon
09/11/2021 02:59, Narcisa Ana Maria Vasile:
Quoted 15 lines · Thomas Monjalon
Quoted 8 lines
09/10/2021 09:41, Narcisa Ana Maria Vasile:
Quoted 7 lines
From: Narcisa Vasile <[email protected]>
Implement thread attributes for:
* thread affinity
* thread priority
Implement functions for managing thread attributes.Quoted 5 lines
Quoted 3 lines
Priority is represented through an enum that allows for two levels:
-RTE_THREAD_PRIORITY_NORMAL
-RTE_THREAD_PRIORITY_REALTIME_CRITICALIt doesn't say how do you translate these priorites in POSIX and win32.
Quoted 7 lines
I'll send a new version with a better commit message.
Thread priorities on both Linux-based and Windows platforms are similarly constructed from a class/policy + priority value. Currently in DPDK, most threads operate at the OS-default priority level but there are cases when increasing the priority is useful. For example, the Mellanox data path acceleration driver requires realtime thread priority. Similarly, some Windows applications will require elevated priority.
Quoted 1 line
It should not. We should not use realtime priority.
Thomas, can you join the community sync tomorrow? I'll bring this up to discuss.
High performance applications benefit from an option to raise the priority of their threads to avoid being preemted by other threads on the system. If there are issues with realtime priority on some of the platforms, maybe we can add a warning for the user to make them aware of possible crashes as Stephen H. suggested some time ago. Note that this patch doesn't change the priority of EAL threads, enabling the higher priority will be done through a command line option when starting the application.
Maybe we can explore raising the priority but not to the realtime level.
Quoted 20 lines
Quoted 18 lines
For these reasons, EAL will advertise 2 priority levels which are named suggestively "normal" and "
realtime_critical" and are computed as follows:For Linux and similar platforms:
* EAL "normal" priority corresponds to the (default)SCHED_OTHERpolicy + a priority value of (sched_get_priority_min(SCHED_OTHER)+ sched_get_priority_max(SCHED_OTHER))/2. Note that on Linux the resulting priority value will be 0,
in accordance to the docs guidance that mention the value should be 0 forSCHED_OTHERpolicy.* EAL "realtime" priority corresponds to the
SCHED_RRpolicy + a priority value ofsched_get_priority_max(SCHED_RR);For Windows:
* EAL "normal" corresponds to classNORMAL_PRIORITY_CLASS+ priorityTHREAD_PRIORITY_NORMAL
* EAL "realtime_critical" corresponds to classREALTIME_PRIORITY_CLASS+ priorityTHREAD_PRIORITY_TIME_CRITICAL
Re: [dpdk-dev] [PATCH v16 2/9] eal: add thread attributes
Quoted 12 lines · On Tue, 9 Nov 2021 19:04:17 -0800 Narcisa Ana Maria Vasile…
Quoted 9 lines
Quoted 7 lines
I'll send a new version with a better commit message.
Thread priorities on both Linux-based and Windows platforms are similarly constructed from a class/policy + priority value. Currently in DPDK, most threads operate at the OS-default priority level but there are cases when increasing the priority is useful. For example, the Mellanox data path acceleration driver requires realtime thread priority. Similarly, some Windows applications will require elevated priority.It should not. We should not use realtime priority.
Thomas, can you join the community sync tomorrow? I'll bring this up to discuss.
Quoted 7 lines
High performance applications benefit from an option to raise the priority of their threads to avoid being preemted by other threads on the system. If there are issues with realtime priority on some of the platforms, maybe we can add a warning for the user to make them aware of possible crashes as Stephen H. suggested some time ago. Note that this patch doesn't change the priority of EAL threads, enabling the higher priority will be done through a command line option when starting the application.
Maybe we can explore raising the priority but not to the realtime level.
Let me put it more succulently.
Almost all DPDK applications have threads that are a 100% CPU doing polling. Putting those thread as real-time thread breaks Linux badly because the kernel can and will try and run work on those CPU's and the system is broken/unstable/dead at that point.
This is a case of different definitions and expectations of real-time in Linux and Windows. Linux definition of real-time priority is for well behaved and time critical applications. It expects RT applications to run, then sleep.
RE: [EXTERNAL] Re: [dpdk-dev] [PATCH v16 2/9] eal: add thread attributes
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, November 9, 2021 8:00 PM
To: Narcisa Ana Maria Vasile <[email protected]>
Cc: thomas <[email protected]>; [email protected]; Dmitry Kozlyuk <[email protected]>; Khoa To <[email protected]>; Dmitry Malloy <[email protected]>; Tyler Retzlaff <[email protected]>; talshn <[email protected]>; Omar Cardona <[email protected]>; [email protected]; [email protected]; Kadam, Pallavi <[email protected]>
Subject: [EXTERNAL] Re: [dpdk-dev] [PATCH v16 2/9] eal: add thread attributes
Quoted 20 lines · On Tue, 9 Nov 2021 19:04:17 -0800 Narcisa Ana Maria Vasile…
Quoted 12 lines
Quoted 9 lines
Quoted 7 lines
I'll send a new version with a better commit message.
Thread priorities on both Linux-based and Windows platforms are similarly constructed from a class/policy + priority value. Currently in DPDK, most threads operate at the OS-default priority level but there are cases when increasing the priority is useful. For example, the Mellanox data path acceleration driver requires realtime thread priority. Similarly, some Windows applications will require elevated priority.It should not. We should not use realtime priority.
Thomas, can you join the community sync tomorrow? I'll bring this up to discuss.
Quoted 7 lines
High performance applications benefit from an option to raise the
priority of their threads to avoid being preemted by other threads on
the system. If there are issues with realtime priority on some of the
platforms, maybe we can add a warning for the user to make them aware
of possible crashes as Stephen H. suggested some time ago. Note that
this patch doesn't change the priority of EAL threads, enabling the higher priority will be done through a command line option when starting the application. Maybe we can explore raising the priority but not to the realtime level.
Quoted 3 lines
Let me put it more succulently.
Almost all DPDK applications have threads that are a 100% CPU doing polling.
Putting those thread as real-time thread breaks Linux badly because the kernel can and will try and run work on those CPU's and the system is broken/unstable/dead at that point.
The suggestion is that when running on Windows it should be possible for the application to be configured to use real-time threads, there is no implication that it will force real-time priority on Linux. If it doesn't make sense for it to be configured on Linux then don't configure it. But saying it shall not be configurable for any platform just because one platform can't make use of the configuration and those platforms have to run compromised makes little sense. Linux administrators are (or should be) knowledgeable enough to know what configuration to use.
Quoted 1 line
Quoted 1 line
This is a case of different definitions and expectations of real-time in Linux and Windows. Linux definition of real-time priority is for well behaved and time critical applications. It expects RT applications to run, then sleep.
Re: [dpdk-dev] [EXTERNAL] Re: [PATCH v16 2/9] eal: add thread attributes
Quoted 9 lines · On Wed, 10 Nov 2021 04:20:52 +0000 Tyler Retzlaff <[email protected]>…
Quoted 8 lines
Quoted 8 lines
High performance applications benefit from an option to raise the
priority of their threads to avoid being preemted by other threads on
the system. If there are issues with realtime priority on some of the
platforms, maybe we can add a warning for the user to make them aware
of possible crashes as Stephen H. suggested some time ago. Note that
this patch doesn't change the priority of EAL threads, enabling the higher priority will be done through a command line option when starting the application. Maybe we can explore raising the priority but not to the realtime level.
Quoted 6 lines
Quoted 3 lines
Let me put it more succulently.
Almost all DPDK applications have threads that are a 100% CPU doing polling.
Putting those thread as real-time thread breaks Linux badly because the kernel can and will try and run work on those CPU's and the system is broken/unstable/dead at that point.The suggestion is that when running on Windows it should be possible for the application to be configured to use real-time threads, there is no implication that it will force real-time priority on Linux. If it doesn't make sense for it to be configured on Linux then don't configure it. But saying it shall not be configurable for any platform just because one platform can't make use of the configuration and those platforms have to run compromised makes little sense. Linux administrators are (or should be) knowledgeable enough to know what configuration to use.
Why not just make it always return an error when real-time is requested on Linux from a DPDK thread.
The experience on the mailing list is that users will find trouble.
Maybe it is just that the sampling is biased. Users that are knowledgeable or figure out problems themselves don't come to the mailing list.
Re: [dpdk-dev] [EXTERNAL] Re: [PATCH v16 2/9] eal: add thread attributes
Quoted 12 lines · Stephen Hemminger
Quoted 9 lines · On Wed, 10 Nov 2021 04:20:52 +0000 Tyler Retzlaff <[email protected]>…
Quoted 8 lines
Quoted 8 lines
High performance applications benefit from an option to raise the
priority of their threads to avoid being preemted by other threads on
the system. If there are issues with realtime priority on some of the
platforms, maybe we can add a warning for the user to make them aware
of possible crashes as Stephen H. suggested some time ago. Note that
this patch doesn't change the priority of EAL threads, enabling the higher priority will be done through a command line option when starting the application. Maybe we can explore raising the priority but not to the realtime level.
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Let me put it more succulently.
Almost all DPDK applications have threads that are a 100% CPU doing polling.
Putting those thread as real-time thread breaks Linux badly because the kernel can and will try and run work on those CPU's and the system is broken/unstable/dead at that point.The suggestion is that when running on Windows it should be possible for the application to be configured to use real-time threads, there is no implication that it will force real-time priority on Linux. If it doesn't make sense for it to be configured on Linux then don't configure it. But saying it shall not be configurable for any platform just because one platform can't make use of the configuration and those platforms have to run compromised makes little sense. Linux administrators are (or should be) knowledgeable enough to know what configuration to use.
Why not just make it always return an error when real-time is requested on Linux from a DPDK thread.
I would tend to agree with this suggestion, that we just return ENOTSUP error code for Linux. It's too easy to lock up a linux system with realtime DPDK threads. If a user really knows what they are doing and they need realtime priority on linux, they can use the linux scheduler APIs directly. However, I am ok with having such a function supported on Windows if it's needed. Unfortunately, I don't know for sure about BSD, but it probably should follow the linux approach initially unless proved safe.
/Bruce
RE: [EXTERNAL] Re: [dpdk-dev] [PATCH v16 2/9] eal: add thread attributes
-----Original Message-----
From: Bruce Richardson <[email protected]>
Sent: Wednesday, November 10, 2021 1:21 AM
To: Stephen Hemminger <[email protected]>
Cc: Tyler Retzlaff <[email protected]>; Narcisa Ana Maria Vasile <[email protected]>; thomas <[email protected]>; [email protected]; Dmitry Kozlyuk <[email protected]>; Khoa To <[email protected]>; Dmitry Malloy <[email protected]>; talshn <[email protected]>; Omar Cardona <[email protected]>; [email protected]; Kadam, Pallavi <[email protected]>
Subject: Re: [EXTERNAL] Re: [dpdk-dev] [PATCH v16 2/9] eal: add thread attributes
Quoted 17 lines · Stephen Hemminger
Quoted 16 lines
Quoted 13 lines · On Wed, 10 Nov 2021 04:20:52 +0000 Tyler Retzlaff <[email protected]>…
Quoted 12 lines
Quoted 8 lines
High performance applications benefit from an option to raise
the priority of their threads to avoid being preemted by other
threads on the system. If there are issues with realtime
priority on some of the platforms, maybe we can add a warning
for the user to make them aware of possible crashes as Stephen
H. suggested some time ago. Note that this patch doesn't change the priority of EAL threads, enabling the higher priority will be done through a command line option when starting the application. Maybe we can explore raising the priority but not to the realtime level.Let me put it more succulently.
Almost all DPDK applications have threads that are a 100% CPU doing polling.
Putting those thread as real-time thread breaks Linux badly because the kernel can and will try and run work on those CPU's and the system is broken/unstable/dead at that point.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
The suggestion is that when running on Windows it should be possible for the application to be configured to use real-time threads, there is no implication that it will force real-time priority on Linux. If it doesn't make sense for it to be configured on Linux then don't configure it. But saying it shall not be configurable for any platform just because one platform can't make use of the configuration and those platforms have to run compromised makes little sense. Linux administrators are (or should be) knowledgeable enough to know what configuration to use.
Why not just make it always return an error when real-time is requested on Linux from a DPDK thread.
I would tend to agree with this suggestion, that we just return ENOTSUP error code for Linux. It's too easy to lock up a linux system with realtime DPDK threads. If a user really knows what they are doing and they need realtime priority on linux, they can use the linux scheduler APIs directly.
This sounds reasonable to me. It doesn't compromise the Linux platform and allows the Windows platform to reach potential.
Quoted 1 line
However, I am ok with having such a function supported on Windows if it's needed. Unfortunately, I don't know for sure about BSD, but it probably should follow the linux approach initially unless proved safe.
Agreed, probably true for all POSIX platforms that support RT extensions.
PATCH v16 3/9 eal/windows: translate Windows errors to errno-style errors
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add function to translate Windows error codes to errno-style error codes. The possible return values are chosen so that we have as much semantical compatibility between platforms as possible.
--- lib/eal/common/rte_thread.c | 6 +-- lib/eal/include/rte_thread.h | 5 +- lib/eal/windows/rte_thread.c | 95 +++++++++++++++++++++++++++--------- 3 files changed, 76 insertions(+), 30 deletions(-)
lib/eal/common/rte_thread.c +3 -3
@@ -47,7 +47,7 @@ rte_thread_attr_init(rte_thread_attr_t *attr)int rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -59,7 +59,7 @@ rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
@@ -71,7 +71,7 @@ rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, -enum rte_thread_priority priority) +enum rte_thread_priority priority) {RTE_VERIFY (thread_attr !=NULL );
lib/eal/include/rte_thread.h +2 -3
@@ -233,9 +233,8 @@ int rte_thread_value_set(rte_thread_key key, const void *value);* * @return * On success, value data pointer (can also be NULL). -* On failure, NULL and an error number is set in rte_errno. -* rte_errno can be: EINVAL - Invalid parameter passed. -* ENOEXEC - Specific OS error. +* On failure, NULL and a positive error number is set in rte_errno. +* */ __rte_experimental void *rte_thread_value_get(rte_thread_key key);
lib/eal/windows/rte_thread.c +71 -24
165 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
Re: [dpdk-dev] [PATCH v16 3/9] eal/windows: translate Windows errors to errno-style errors
09/10/2021 09:41, Narcisa Ana Maria Vasile:
Quoted 37 lines
From: Narcisa Vasile <[email protected]>
Add function to translate Windows error codes to errno-style error codes. The possible return values are chosen so that we have as much semantical compatibility between platforms as possible.
Signed-off-by Narcisa Vasile <[email protected]>--- lib/eal/common/rte_thread.c | 6 +-- lib/eal/include/rte_thread.h | 5 +- lib/eal/windows/rte_thread.c | 95 +++++++++++++++++++++++++++--------- 3 files changed, 76 insertions(+), 30 deletions(-)lib/eal/common/rte_thread.c +2
-2@@ -47,7 +47,7 @@ rte_thread_attr_init(rte_thread_attr_t *attr)int rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );@@ -59,7 +59,7 @@ rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );
lib/eal/common/rte_thread.c rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, · line 74
Quoted 5 lines
lib/eal/common/rte_thread.c +1
-1@@ -71,7 +71,7 @@ rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, -enum rte_thread_priority priority) +enum rte_thread_priority priority)
Above are unrelated changes.
lib/eal/windows/rte_thread.c struct eal_tls_key { · line 18
Quoted 9 lines
lib/eal/windows/rte_thread.c +3
-0@@ -13,6 +13,54 @@ struct eal_tls_key {DWORD thread_index; }; +/* Translates the most common error codes related to threads */ +static int +thread_translate_win32_error (DWORD error)
So you decide to adopt POSIX error codes for the DPDK API. OK
Quoted 35 lines
lib/eal/windows/rte_thread.c +35
-0+{ +switch (error) { +case ERROR_SUCCESS : +return 0 ; + +case ERROR_INVALID_PARAMETER : +return EINVAL ; + +case ERROR_INVALID_HANDLE : +return EFAULT ; + +case ERROR_NOT_ENOUGH_MEMORY : +/* FALLTHROUGH */ +case ERROR_NO_SYSTEM_RESOURCES : +return ENOMEM ; + +case ERROR_PRIVILEGE_NOT_HELD : +/* FALLTHROUGH */ +case ERROR_ACCESS_DENIED : +return EACCES ; + +case ERROR_ALREADY_EXISTS : +return EEXIST ; + +case ERROR_POSSIBLE_DEADLOCK : +return EDEADLK ; + +case ERROR_INVALID_FUNCTION : +/* FALLTHROUGH */ +case ERROR_CALL_NOT_IMPLEMENTED : +return ENOSYS ; + } + +return EINVAL ; +}
[...]
lib/eal/windows/rte_thread.c int · line 133
Quoted 12 lines
rte_thread_key_create(rte_thread_key *key,
lib/eal/windows/rte_thread.c +3
-2__rte_unused void (*destructor)(void *)) { +int ret; + *key =malloc (sizeof (**key));if ((*key) ==NULL ) {RTE_LOG (DEBUG ,EAL ,"Cannot allocate TLS key.\n" ); - rte_errno =ENOMEM ; -return -1 ; +return ENOMEM ; }
Why this change? rte_errno and negative error code are good.
Re: [dpdk-dev] [PATCH v16 3/9] eal/windows: translate Windows errors to errno-style errors
Quoted 39 lines · Thomas Monjalon
09/10/2021 09:41, Narcisa Ana Maria Vasile:
Quoted 38 lines
From: Narcisa Vasile <[email protected]>
Add function to translate Windows error codes to errno-style error codes. The possible return values are chosen so that we have as much semantical compatibility between platforms as possible.
Signed-off-by Narcisa Vasile <[email protected]>--- lib/eal/common/rte_thread.c | 6 +-- lib/eal/include/rte_thread.h | 5 +- lib/eal/windows/rte_thread.c | 95 +++++++++++++++++++++++++++--------- 3 files changed, 76 insertions(+), 30 deletions(-)lib/eal/common/rte_thread.c +2
-2@@ -47,7 +47,7 @@ rte_thread_attr_init(rte_thread_attr_t *attr)int rte_thread_attr_set_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );@@ -59,7 +59,7 @@ rte_thread_attr_set_affinity(rte_thread_attr_t *thread_attr,int rte_thread_attr_get_affinity (rte_thread_attr_t *thread_attr, -rte_cpuset_t *cpuset) +rte_cpuset_t *cpuset) {RTE_VERIFY (thread_attr !=NULL );RTE_VERIFY (cpuset !=NULL );@@ -71,7 +71,7 @@ rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr,
Quoted 7 lines
lib/eal/common/rte_thread.c rte_thread_attr_get_affinity(rte_thread_attr_t *thread_attr, · line 74
Quoted 4 lines
lib/eal/common/rte_thread.c +1
-1int rte_thread_attr_set_priority (rte_thread_attr_t *thread_attr, -enum rte_thread_priority priority) +enum rte_thread_priority priority)Above are unrelated changes.
Thanks, will fix!
Quoted 48 lines
lib/eal/windows/rte_thread.c struct eal_tls_key { · line 18
Quoted 9 lines
lib/eal/windows/rte_thread.c +3
-0@@ -13,6 +13,54 @@ struct eal_tls_key {DWORD thread_index; }; +/* Translates the most common error codes related to threads */ +static int +thread_translate_win32_error (DWORD error)So you decide to adopt POSIX error codes for the DPDK API. OK
Quoted 35 lines
lib/eal/windows/rte_thread.c +35
-0+{ +switch (error) { +case ERROR_SUCCESS : +return 0 ; + +case ERROR_INVALID_PARAMETER : +return EINVAL ; + +case ERROR_INVALID_HANDLE : +return EFAULT ; + +case ERROR_NOT_ENOUGH_MEMORY : +/* FALLTHROUGH */ +case ERROR_NO_SYSTEM_RESOURCES : +return ENOMEM ; + +case ERROR_PRIVILEGE_NOT_HELD : +/* FALLTHROUGH */ +case ERROR_ACCESS_DENIED : +return EACCES ; + +case ERROR_ALREADY_EXISTS : +return EEXIST ; + +case ERROR_POSSIBLE_DEADLOCK : +return EDEADLK ; + +case ERROR_INVALID_FUNCTION : +/* FALLTHROUGH */ +case ERROR_CALL_NOT_IMPLEMENTED : +return ENOSYS ; + } + +return EINVAL ; +}[...]
Quoted 15 lines
lib/eal/windows/rte_thread.c int · line 133
Quoted 12 lines
rte_thread_key_create(rte_thread_key *key,
lib/eal/windows/rte_thread.c +3
-2__rte_unused void (*destructor)(void *)) { +int ret; + *key =malloc (sizeof (**key));if ((*key) ==NULL ) {RTE_LOG (DEBUG ,EAL ,"Cannot allocate TLS key.\n" ); - rte_errno =ENOMEM ; -return -1 ; +return ENOMEM ; }Why this change?
rte_errnoand negative error code are good.
This error could have been handled using rte_errno and negative return, but for consistency, a positive error number is returned. As different platforms have different error codes, the approach here is to translate the Windows error to POSIX-style ones to have uniformity over the values returned. All functions in this thread module return the possible error through the return value.
Quoted 1 line
Re: [dpdk-dev] [PATCH v16 3/9] eal/windows: translate Windows errors to errno-style errors
09/11/2021 03:02, Narcisa Ana Maria Vasile:
Quoted 19 lines · Thomas Monjalon
Quoted 17 lines
09/10/2021 09:41, Narcisa Ana Maria Vasile:
lib/eal/windows/rte_thread.c int · line 133
Quoted 13 lines
From: Narcisa Vasile <[email protected]>
rte_thread_key_create(rte_thread_key *key,lib/eal/windows/rte_thread.c +3
-2__rte_unused void (*destructor)(void *)) { +int ret; + *key =malloc (sizeof (**key));if ((*key) ==NULL ) {RTE_LOG (DEBUG ,EAL ,"Cannot allocate TLS key.\n" ); - rte_errno =ENOMEM ; -return -1 ; +return ENOMEM ; }Why this change?
rte_errnoand negative error code are good.
Quoted 5 lines
This error could have been handled using
rte_errnoand negative return, but for consistency, a positive error number is returned. As different platforms have different error codes, the approach here is to translate the Windows error to POSIX-style ones to have uniformity over the values returned. All functions in this thread module return the possible error through the return value.
We can have the same consistency with rte_errno.
What others think? Should we use rte_errno?
PATCH v16 4/9 eal: implement functions for thread affinity management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Implement functions for getting/setting thread affinity. Threads can be pinned to specific cores by setting their affinity attribute.
--- lib/eal/common/rte_thread.c | 16 ++++ lib/eal/include/rte_thread.h | 36 +++++++ lib/eal/version.map | 2 + lib/eal/windows/eal_lcore.c | 176 +++++++++++++++++++++++++--------- lib/eal/windows/eal_windows.h | 10 ++ lib/eal/windows/rte_thread.c | 125 +++++++++++++++++++++++- 6 files changed, 319 insertions(+), 46 deletions(-)
lib/eal/common/rte_thread.c +16 -0
@@ -34,6 +34,22 @@ rte_thread_equal(rte_thread_t t1, rte_thread_t t2)return pthread_equal ((pthread_t )t1.opaque_id, (pthread_t )t2.opaque_id); } +int +rte_thread_set_affinity_by_id (rte_thread_t thread_id, +const rte_cpuset_t *cpuset) +{ +return pthread_setaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} + +int +rte_thread_get_affinity_by_id (rte_thread_t thread_id, +rte_cpuset_t *cpuset) +{ +return pthread_getaffinity_np ((pthread_t )thread_id.opaque_id, +sizeof (*cpuset), cpuset); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +36 -0
@@ -85,6 +85,42 @@ int rte_thread_equal(rte_thread_t t1, rte_thread_t t2);#ifdef RTE_HAS_CPUSET +/** +* Set the affinity of thread 'thread_id' to the cpu set +* specified by 'cpuset'. +* +* @param thread_id +* Id of the thread for which to set the affinity. +* +* @param cpuset +* Pointer to CPU affinity to set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_affinity_by_id(rte_thread_t thread_id, +const rte_cpuset_t *cpuset); + +/** +* Get the affinity of thread 'thread_id' and store it +* in 'cpuset'. +* +* @param thread_id +* Id of the thread for which to get the affinity. +* +* @param cpuset +* Pointer for storing the affinity value. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_get_affinity_by_id(rte_thread_t thread_id, +rte_cpuset_t *cpuset); +/** * Initialize the attributes of a thread. * These attributes can be passed to the rte_thread_create() function
lib/eal/version.map +2 -0
@@ -427,6 +427,8 @@ EXPERIMENTAL { rte_thread_attr_get_affinity; rte_thread_attr_set_affinity; rte_thread_attr_set_priority; + rte_thread_get_affinity_by_id; + rte_thread_set_affinity_by_id; }; INTERNAL {
lib/eal/windows/eal_lcore.c +131 -45
231 lines not on this page · raw message
lib/eal/windows/eal_windows.h +10 -0
@@ -55,6 +55,16 @@ int eal_thread_create(pthread_t *thread);*/ unsigned int eal_socket_numa_node (unsigned int socket_id); +/** +* Get pointer to the group affinity for the cpu. +* +* @param cpu_index +* Index of the cpu, as it comes from rte_cpuset_t. +* @return +* Pointer to the group affinity for the cpu. +*/ +PGROUP_AFFINITY eal_get_cpu_affinity (size_t cpu_index); +/** * Schedule code for execution in the interrupt thread. *
lib/eal/windows/rte_thread.c +124 -1
137 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
Re: [dpdk-dev] [PATCH v16 4/9] eal: implement functions for thread affinity management
09/10/2021 09:41, Narcisa Ana Maria Vasile:
Quoted 8 lines
From: Narcisa Vasile <[email protected]>
Implement functions for getting/setting thread affinity. Threads can be pinned to specific cores by setting their affinity attribute.
Signed-off-by Narcisa Vasile <[email protected]>Signed-off-by Dmitry Malloy <[email protected]>
[...]
Quoted 5 lines
+/**
+ * Set the affinity of thread 'thread_id' to the cpu set
+ * specified by 'cpuset'.
+ *
+ * @paramthread_id
Quoted 8 lines
+ * Id of the thread for which to set the affinity.
+ *
+ * @param cpuset
+ * Pointer to CPU affinity to set.
+ *
+ * @return
+ * On success, return 0.
+ * On failure, return a positive errno-style error number.
Usually we return negative numbers on error.
PATCH v16 5/9 eal: implement thread priority management functions
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for setting and getting the priority of a thread. Priorities on multiple platforms are similarly determined by a priority value and a priority class/policy.
On Linux, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* policy SCHED_OTHER
* priority value: (sched_get_priority_min(SCHED_OTHER) +
sched_get_priority_max(SCHED_OTHER))/2;
RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* policy SCHED_RR
* priority value: sched_get_priority_max(SCHED_RR);
On Windows, the following mapping is created:RTE_THREAD_PRIORITY_NORMAL corresponds to
* class NORMAL_PRIORITY_CLASS
* priority THREAD_PRIORITY_NORMAL RTE_THREAD_PRIORITY_REALTIME_CRITICAL corresponds to
* class REALTIME_PRIORITY_CLASS
* priority THREAD_PRIORITY_TIME_CRITICAL
--- lib/eal/common/rte_thread.c | 97 ++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 34 ++++++++++ lib/eal/version.map | 2 + lib/eal/windows/rte_thread.c | 127 +++++++++++++++++++++++++++++++++++ 4 files changed, 260 insertions(+)
lib/eal/common/rte_thread.c +97 -0
@@ -50,6 +50,103 @@ rte_thread_get_affinity_by_id(rte_thread_t thread_id, sizeof(*cpuset), cpuset); } +static int +thread_map_priority_to_os_value (enum rte_thread_priority eal_pri, +int *os_pri,int *pol) +{ +/* Clear the output parameters */ + *os_pri =sched_get_priority_min (SCHED_OTHER ) -1 ; + *pol =-1 ; + +switch (eal_pri) { +case RTE_THREAD_PRIORITY_NORMAL : + *pol =SCHED_OTHER ; + +/* +* Choose the middle of the range to represent +* the priority 'normal'. +* On Linux, this should be 0, since both +* sched_get_priority_min/_max return 0 for SCHED_OTHER. +*/ + *os_pri = (sched_get_priority_min (SCHED_OTHER ) + +sched_get_priority_max (SCHED_OTHER ))/2 ; +break ; +case RTE_THREAD_PRIORITY_REALTIME_CRITICAL : + *pol =SCHED_RR ; + *os_pri =sched_get_priority_max (SCHED_RR ); +break ; +default : +RTE_LOG (DEBUG ,EAL ,"The requested priority value is invalid.\n" ); +return EINVAL ; + } +return 0 ; +} + +static int +thread_map_os_priority_to_eal_priority (int policy,int os_pri, +enum rte_thread_priority *eal_pri) +{ +switch (policy) { +case SCHED_OTHER : +if (os_pri == (sched_get_priority_min (SCHED_OTHER ) + +sched_get_priority_max (SCHED_OTHER ))/2 ) { + *eal_pri =RTE_THREAD_PRIORITY_NORMAL ; +return 0 ; + } +break ; +case SCHED_RR : +if (os_pri ==sched_get_priority_max (SCHED_RR )) { + *eal_pri =RTE_THREAD_PRIORITY_REALTIME_CRITICAL ; +return 0 ; + } +break ; +default : +RTE_LOG (DEBUG ,EAL ,"The OS priority value does not map to an EAL-defined priority.\n" ); +return EINVAL ; + } + +return 0 ; +} + +int +rte_thread_get_priority (rte_thread_t thread_id, +enum rte_thread_priority *priority) +{ +int ret; +int policy; +struct sched_param param; + + ret =pthread_getschedparam ((pthread_t )thread_id.opaque_id, &policy, + ¶m); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_getschedparam failed\n" ); + goto cleanup; + } + +return thread_map_os_priority_to_eal_priority (policy, + param.sched_priority, priority); + +cleanup: +return ret; +} + +int +rte_thread_set_priority (rte_thread_t thread_id, +enum rte_thread_priority priority) +{ +int ret; +int policy; +struct sched_param param; + + ret =thread_map_priority_to_os_value (priority, ¶m.sched_priority, + &policy); +if (ret !=0 ) +return ret; + +return pthread_setschedparam ((pthread_t )thread_id.opaque_id, + policy, ¶m); +} +int rte_thread_attr_init (rte_thread_attr_t *attr) {
lib/eal/include/rte_thread.h +34 -0
@@ -213,6 +213,40 @@ void rte_thread_get_affinity(rte_cpuset_t *cpusetp);#endif /* RTE_HAS_CPUSET */ +/** +* Get the priority of a thread. +* +* @param thread_id +* Id of the thread for which to get priority. +* +* @param priority +* Location to store the retrieved priority. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_get_priority(rte_thread_t thread_id, +enum rte_thread_priority *priority); + +/** +* Set the priority of a thread. +* +* @param thread_id +* Id of the thread for which to set priority. +* +* @param priority +* Priority value to be set. +* +* @return +* On success, return 0. +* On failure, return a positive errno-style error number. +*/ +__rte_experimental +int rte_thread_set_priority(rte_thread_t thread_id, +enum rte_thread_priority priority); +/** * Create a TLS data key visible to all threads in the process. * the created key is later used to get/set a value.
lib/eal/version.map +2 -0
@@ -429,6 +429,8 @@ EXPERIMENTAL { rte_thread_attr_set_priority; rte_thread_get_affinity_by_id; rte_thread_set_affinity_by_id; + rte_thread_get_priority; + rte_thread_set_priority; }; INTERNAL {
lib/eal/windows/rte_thread.c +127 -0
133 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v16 6/9 eal: add thread lifetime management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for thread creation, joining, detaching.
The *rte_thread_create()* function can optionally receive
an rte_thread_attr_t object that will cause the thread to be created with the affinity and priority described by the attributes object. If no rte_thread_attr_t is passed (parameter is NULL), the default affinity and priority are used.
On Windows, the function executed by a thread when the thread starts is represeneted by a function pointer of type DWORD (*func) (void*). On other platforms, the function pointer is a void* (*func) (void*).
Performing a cast between these two types of function pointers to uniformize the API on all platforms may result in undefined behavior. TO fix this issue, a wrapper that respects the signature required by CreateThread() has been created on Windows.
--- lib/eal/common/rte_thread.c | 103 ++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 55 +++++++++++++ lib/eal/version.map | 3 + lib/eal/windows/include/sched.h | 2 +- lib/eal/windows/rte_thread.c | 134 ++++++++++++++++++++++++++++++++ 5 files changed, 296 insertions(+), 1 deletion(-)
lib/eal/common/rte_thread.c +103 -0
@@ -192,6 +192,109 @@ rte_thread_attr_set_priority(rte_thread_attr_t *thread_attr,return 0 ; } +int +rte_thread_create (rte_thread_t *thread_id, +const rte_thread_attr_t *thread_attr, +rte_thread_func thread_func,void *args) +{ +int ret =0 ; +pthread_attr_t attr; +pthread_attr_t *attrp =NULL ; +struct sched_param param = { + .sched_priority =0 , + }; +int policy =SCHED_OTHER ; + +if (thread_attr !=NULL ) { + ret =pthread_attr_init (&attr); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_init failed\n" ); + goto cleanup; + } + + attrp = &attr; + +/* +* Set the inherit scheduler parameter to explicit, +* otherwise the priority attribute is ignored. +*/ + ret =pthread_attr_setinheritsched (attrp, +PTHREAD_EXPLICIT_SCHED ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setinheritsched failed\n" ); + goto cleanup; + } + + ret =thread_map_priority_to_os_value (thread_attr->priority, + ¶m.sched_priority, &policy); +if (ret !=0 ) + goto cleanup; + + ret =pthread_attr_setschedpolicy (attrp, policy); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedpolicy failed\n" ); + goto cleanup; + } + + ret =pthread_attr_setschedparam (attrp, ¶m); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_attr_setschedparam failed\n" ); + goto cleanup; + } + } + + ret =pthread_create ((pthread_t *)&thread_id->opaque_id, attrp, + thread_func, args); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_create failed\n" ); + goto cleanup; + } + +if (thread_attr !=NULL &&CPU_COUNT (&thread_attr->cpuset) >0 ) { + ret =pthread_setaffinity_np ((pthread_t )thread_id->opaque_id, +sizeof (thread_attr->cpuset), + &thread_attr->cpuset); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_setaffinity_np failed\n" ); + goto cleanup; + } + } + +cleanup: +if (attrp !=NULL ) +pthread_attr_destroy (&attr); + +return ret; +} + +int +rte_thread_join (rte_thread_t thread_id,unsigned long *value_ptr) +{ +int ret =0 ; +void *res =NULL ; +void **pres =NULL ; + +if (value_ptr !=NULL ) + pres = &res; + + ret =pthread_join ((pthread_t )thread_id.opaque_id, pres); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"pthread_join failed\n" ); +return ret; + } + +if (value_ptr !=NULL && *pres !=NULL ) + *value_ptr = *(unsigned long *)(*pres); + +return 0 ; +} + +int +rte_thread_detach (rte_thread_t thread_id) +{ +return pthread_detach ((pthread_t )thread_id.opaque_id); +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +55 -0
67 lines not on this page · raw message
lib/eal/version.map +3 -0
@@ -431,6 +431,9 @@ EXPERIMENTAL { rte_thread_set_affinity_by_id; rte_thread_get_priority; rte_thread_set_priority; + rte_thread_create; + rte_thread_join; + rte_thread_detach; }; INTERNAL {
lib/eal/windows/include/sched.h +1 -1
@@ -44,7 +44,7 @@ typedef struct _rte_cpuset_s { (1LL << _WHICH_BIT(b))) != 0LL)static inline int -count_cpu (rte_cpuset_t *s) +count_cpu (const rte_cpuset_t *s) {unsigned int _i;int count =0 ;
lib/eal/windows/rte_thread.c +134 -0
146 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
PATCH v16 7/9 eal: implement functions for mutex management
In reply to Narcisa Ana Maria VasileFrom: Narcisa Vasile <[email protected]>
Add functions for mutex init, destroy, lock, unlock, trylock.
Add RTE_STATIC_MUTEX macro to replace static initialization of mutexes.
Windows does not have a static initializer. Initialization is only done through InitializeCriticalSection().
The RTE_STATIC_MUTEX calls into the rte_thread_mutex_init() function that performs the actual mutex initialization.
--- lib/eal/common/rte_thread.c | 69 ++++++++++++++++++++++ lib/eal/include/rte_thread.h | 108 +++++++++++++++++++++++++++++++++++ lib/eal/version.map | 5 ++ lib/eal/windows/rte_thread.c | 64 +++++++++++++++++++++ 4 files changed, 246 insertions(+)
lib/eal/common/rte_thread.c +69 -0
@@ -295,6 +295,75 @@ rte_thread_detach(rte_thread_t thread_id)return pthread_detach ((pthread_t )thread_id.opaque_id); } +int +rte_thread_mutex_init (rte_thread_mutex *mutex) +{ +int ret =0 ; +pthread_mutex_t *m =NULL ; + +RTE_VERIFY (mutex !=NULL ); + + m =calloc (1 ,sizeof (*m)); +if (m ==NULL ) { +RTE_LOG (DEBUG ,EAL ,"Unable to initialize mutex. Insufficient memory!\n" ); + ret =ENOMEM ; + goto cleanup; + } + + ret =pthread_mutex_init (m,NULL ); +if (ret !=0 ) { +RTE_LOG (DEBUG ,EAL ,"Failed to init mutex. ret = %d\n" , ret); + goto cleanup; + } + + mutex->mutex_id = m; + m =NULL ; + +cleanup: +free (m); +return ret; +} + +int +rte_thread_mutex_lock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_lock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_unlock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_unlock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_try_lock (rte_thread_mutex *mutex) +{ +RTE_VERIFY (mutex !=NULL ); + +return pthread_mutex_trylock ((pthread_mutex_t *)mutex->mutex_id); +} + +int +rte_thread_mutex_destroy (rte_thread_mutex *mutex) +{ +int ret =0 ; +RTE_VERIFY (mutex !=NULL ); + + ret =pthread_mutex_destroy ((pthread_mutex_t *)mutex->mutex_id); +if (ret !=0 ) +RTE_LOG (DEBUG ,EAL ,"Unable to destroy mutex, ret = %d\n" , ret); + +free (mutex->mutex_id); + mutex->mutex_id =NULL ; + +return ret; +} +int rte_thread_key_create (rte_thread_key *key,void (*destructor)(void *)) {
lib/eal/include/rte_thread.h +108 -0
126 lines not on this page · raw message
lib/eal/version.map +5 -0
@@ -434,6 +434,11 @@ EXPERIMENTAL { rte_thread_create; rte_thread_join; rte_thread_detach; + rte_thread_mutex_init; + rte_thread_mutex_lock; + rte_thread_mutex_unlock; + rte_thread_mutex_try_lock; + rte_thread_mutex_destroy; }; INTERNAL {
lib/eal/windows/rte_thread.c +64 -0
70 lines not on this page · raw message
Signature · 1 line
2.31.0.vfs.0.1
Re: [dpdk-dev] [PATCH v16 7/9] eal: implement functions for mutex management
09/10/2021 09:41, Narcisa Ana Maria Vasile:
Quoted 11 lines
From: Narcisa Vasile <[email protected]>
Add functions for mutex init, destroy, lock, unlock, trylock.
Add
RTE_STATIC_MUTEXmacro to replace static initialization of mutexes.
Windows does not have a static initializer. Initialization is only done throughInitializeCriticalSection().The
RTE_STATIC_MUTEXcalls into therte_thread_mutex_init()function that performs the actual mutex initialization.
[...]
lib/eal/include/rte_thread.h typedef struct { · line 67
Quoted 13 lines
lib/eal/include/rte_thread.h +11
-0+#define RTE_DECLARE_MUTEX (private_lock) rte_thread_mutex private_lock + +#define RTE_DEFINE_MUTEX (private_lock)\ +RTE_INIT(__rte_ ## private_lock ## _init)\ +{\ + RTE_VERIFY(rte_thread_mutex_init(&private_lock) == 0);\ +} + +#define RTE_STATIC_MUTEX (private_lock)\ +static RTE_DECLARE_MUTEX(private_lock);\ +RTE_DEFINE_MUTEX(private_lock)
This is not truly static.
It is a wrapper to init the mutex in the constructor. Should we rename?