eal: add API that sleeps while waiting for threads
PATCH 1/2 eal: add API that sleeps while waiting for threads
It is common that sample applications call rte_eal_wait_lcore() while waiting for worker threads to be terminated.
Mostly master lcore keeps waiting in this function.
The waiting app for termination is not a time critical task, app can prefer a sleep version of the waiting to consume less cycles.
A sleeping version of the API, rte_eal_wait_lcore_sleep(), has been added which gets sleeping interval as parameter.
Sample applications will be updated later to use this API.
--- lib/librte_eal/common/eal_common_launch.c | 22 ++++++++++++++++++ lib/librte_eal/common/include/rte_launch.h | 27 ++++++++++++++++++++++ lib/librte_eal/rte_eal_version.map | 1 + 3 files changed, 50 insertions(+)
lib/librte_eal/common/eal_common_launch.c +22 -0
@@ -5,6 +5,7 @@#include <errno.h> #include <stdint.h> #include <stdio.h> +#include <unistd.h> #include <sys/queue.h> #include <rte_launch.h>
@@ -35,6 +36,27 @@ rte_eal_wait_lcore(unsigned slave_id)return lcore_config[slave_id].ret; } +/* +* Wait until a lcore finished its job by sleeping. +* Sleep time will be times of 'usec' +*/ +int +rte_eal_wait_lcore_sleep (unsigned slave_id,size_t usec) +{ +if (lcore_config[slave_id].state ==WAIT ) +return 0 ; + +while (lcore_config[slave_id].state !=WAIT && + lcore_config[slave_id].state !=FINISHED ) +usleep (usec); + +rte_rmb (); + +/* we are in finished state, go to wait state */ + lcore_config[slave_id].state =WAIT ; +return lcore_config[slave_id].ret; +} +/* * Check that every SLAVE lcores are in WAIT state, then call * rte_eal_remote_launch() for all of them. If call_master is true
lib/librte_eal/common/include/rte_launch.h +27 -0
@@ -11,6 +11,8 @@* Launch tasks on other lcores */ +#include <rte_compat.h> +#ifdef __cplusplusextern "C" {#endif
@@ -129,6 +131,31 @@ enum rte_lcore_state_t rte_eal_get_lcore_state(unsigned slave_id);*/ int rte_eal_wait_lcore (unsigned slave_id); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Wait until an lcore finishes its job. +* +* To be executed on the MASTER lcore only. +* +* Same as rte_eal_wait_lcore() but sleeps instead of busy wait. +* +* @param slave_id +* The identifier of the lcore. +* @param usec +* The sleep interval in microseconds +* @return +* - 0: If the lcore identified by the slave_id is in a WAIT state. +* - The value that was returned by the previous remote launch +* function call if the lcore identified by the slave_id was in a +* FINISHED or RUNNING state. In this case, it changes the state +* of the lcore to WAIT. +*/ +__rte_experimental int +rte_eal_wait_lcore_sleep (unsigned slave_id,size_t usec); +/** * Wait until all lcores finish their jobs. *
lib/librte_eal/rte_eal_version.map +1 -0
@@ -292,6 +292,7 @@ EXPERIMENTAL { rte_devargs_remove; rte_devargs_type_count; rte_eal_cleanup; + rte_eal_wait_lcore_sleep; rte_fbarray_attach; rte_fbarray_destroy; rte_fbarray_detach;
Signature · 1 line
2.17.1
PATCH 2/2 examples: sleep while waiting worker threads to terminate
This is to prevent sample applications to do busy wait while waiting for worker threads to terminate. Should save cycles on master core. By default a 1ms wait interval used.
--- examples/bbdev_app/main.c | 2 +- examples/distributor/Makefile | 3 +++ examples/distributor/main.c | 2 +- examples/distributor/meson.build | 1 + examples/ethtool/ethtool-app/Makefile | 1 + examples/ethtool/ethtool-app/main.c | 2 +- examples/exception_path/Makefile | 3 +++ examples/exception_path/main.c | 2 +- examples/exception_path/meson.build | 1 + examples/ip_fragmentation/Makefile | 3 +++ examples/ip_fragmentation/main.c | 2 +- examples/ip_fragmentation/meson.build | 1 + examples/ip_reassembly/Makefile | 3 +++ examples/ip_reassembly/main.c | 2 +- examples/ip_reassembly/meson.build | 1 + examples/ipsec-secgw/ipsec-secgw.c | 2 +- examples/ipv4_multicast/Makefile | 3 +++ examples/ipv4_multicast/main.c | 2 +- examples/ipv4_multicast/meson.build | 1 + examples/kni/Makefile | 3 +++ examples/kni/main.c | 2 +- examples/kni/meson.build | 1 + examples/l2fwd-crypto/Makefile | 3 +++ examples/l2fwd-crypto/main.c | 2 +- examples/l2fwd-crypto/meson.build | 1 + examples/l2fwd-jobstats/Makefile | 3 +++ examples/l2fwd-jobstats/main.c | 2 +- examples/l2fwd-jobstats/meson.build | 1 + examples/l2fwd-keepalive/Makefile | 3 +++ examples/l2fwd-keepalive/main.c | 2 +- examples/l2fwd-keepalive/meson.build | 1 + examples/l2fwd/Makefile | 3 +++ examples/l2fwd/main.c | 2 +- examples/l2fwd/meson.build | 1 + examples/l3fwd-acl/Makefile | 3 +++ examples/l3fwd-acl/main.c | 2 +- examples/l3fwd-acl/meson.build | 1 + examples/l3fwd-power/Makefile | 3 +++ examples/l3fwd-power/main.c | 2 +- examples/l3fwd-power/meson.build | 1 + examples/l3fwd-vf/Makefile | 3 +++ examples/l3fwd-vf/main.c | 2 +- examples/l3fwd-vf/meson.build | 1 + examples/l3fwd/Makefile | 3 +++ examples/l3fwd/main.c | 2 +- examples/l3fwd/meson.build | 1 + examples/link_status_interrupt/Makefile | 3 +++ examples/link_status_interrupt/main.c | 2 +- examples/link_status_interrupt/meson.build | 1 + examples/load_balancer/Makefile | 3 +++ examples/load_balancer/main.c | 2 +- examples/load_balancer/meson.build | 1 + examples/packet_ordering/Makefile | 3 +++ examples/packet_ordering/main.c | 2 +- examples/packet_ordering/meson.build | 1 + examples/performance-thread/l3fwd-thread/Makefile | 1 + examples/performance-thread/l3fwd-thread/main.c | 2 +- examples/performance-thread/pthread_shim/Makefile | 1 + examples/performance-thread/pthread_shim/main.c | 2 +- examples/qos_meter/Makefile | 1 + examples/qos_meter/main.c | 2 +- examples/qos_meter/meson.build | 1 + examples/tep_termination/main.c | 2 +- examples/vhost/main.c | 2 +- examples/vhost_crypto/main.c | 2 +- examples/vmdq/Makefile | 3 +++ examples/vmdq/main.c | 2 +- examples/vmdq/meson.build | 1 + 68 files changed, 104 insertions(+), 27 deletions(-)
examples/bbdev_app/main.c +1 -1
@@ -1148,7 +1148,7 @@ main(int argc, char **argv)stats_loop (&stats_lcore);RTE_LCORE_FOREACH_SLAVE (lcore_id) { - ret |=rte_eal_wait_lcore (lcore_id); + ret |=rte_eal_wait_lcore_sleep (lcore_id,1000 ); }return ret;
examples/distributor/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -49,6 +51,7 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/distributor/main.c +1 -1
@@ -801,7 +801,7 @@ main(int argc, char *argv[]) }RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/distributor/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'distributor' +allow_experimental_apis = true sources = files( 'main.c' )
examples/ethtool/ethtool-app/Makefile +1 -0
@@ -18,6 +18,7 @@ SRCS-y := main.c ethapp.c CFLAGS += -O3 -D_GNU_SOURCE -pthread -I$(SRCDIR)/../lib CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDLIBS += -L$(subst ethtool-app,lib,$(RTE_OUTPUT))/lib LDLIBS += -lrte_ethtool
examples/ethtool/ethtool-app/main.c +1 -1
@@ -276,7 +276,7 @@ int main(int argc, char **argv) app_cfg.exit_now =1 ;RTE_LCORE_FOREACH_SLAVE (id_core) { -if (rte_eal_wait_lcore (id_core) <0 ) +if (rte_eal_wait_lcore_sleep (id_core,1000 )<0 )return -1 ; }
examples/exception_path/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk
examples/exception_path/main.c +1 -1
@@ -581,7 +581,7 @@ main(int argc, char** argv)/* Launch per-lcore function on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (i) { -if (rte_eal_wait_lcore (i) <0 ) +if (rte_eal_wait_lcore_sleep (i,1000 ) <0 )return -1 ; }
examples/exception_path/meson.build +1 -0
@@ -6,6 +6,7 @@ # To build this example as a standalone application with an already-installed # DPDK instance, use 'make' +allow_experimental_apis = true sources = files( 'main.c' )
examples/ip_fragmentation/Makefile +3 -0
@@ -24,6 +24,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -51,6 +53,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/ip_fragmentation/main.c +1 -1
@@ -1018,7 +1018,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/ip_fragmentation/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['ip_frag', 'lpm'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/ip_reassembly/Makefile +3 -0
@@ -24,6 +24,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -51,6 +53,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/ip_reassembly/main.c +1 -1
@@ -1175,7 +1175,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/ip_reassembly/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['lpm', 'ip_frag'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/ipsec-secgw/ipsec-secgw.c +1 -1
@@ -1837,7 +1837,7 @@ main(int32_t argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/ipv4_multicast/Makefile +3 -0
@@ -24,6 +24,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -51,6 +53,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/ipv4_multicast/main.c +1 -1
@@ -793,7 +793,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/ipv4_multicast/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'hash' +allow_experimental_apis = true sources = files( 'main.c' )
examples/kni/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -55,6 +57,7 @@ endif CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/kni/main.c +1 -1
@@ -952,7 +952,7 @@ main(int argc, char** argv)/* Launch per-lcore function on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (i) { -if (rte_eal_wait_lcore (i) <0 ) +if (rte_eal_wait_lcore_sleep (i,1000 ) <0 )return -1 ; }
examples/kni/meson.build +1 -0
@@ -9,6 +9,7 @@ # this app can be built if-and-only-if KNI library is buildable build = dpdk_conf.has('RTE_LIBRTE_KNI') deps += ['kni', 'bus_pci'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/l2fwd-crypto/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y) ifeq ($(CONFIG_RTE_LIBRTE_PMD_CRYPTO_SCHEDULER),y)
examples/l2fwd-crypto/main.c +1 -1
@@ -2765,7 +2765,7 @@ main(int argc, char **argv)rte_eal_mp_remote_launch (l2fwd_launch_one_lcore, (void *)&options,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/l2fwd-crypto/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'cryptodev' +allow_experimental_apis = true sources = files( 'main.c' )
examples/l2fwd-jobstats/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -51,6 +53,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/l2fwd-jobstats/main.c +1 -1
@@ -995,7 +995,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (l2fwd_launch_one_lcore,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/l2fwd-jobstats/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['jobstats', 'timer'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/l2fwd-keepalive/Makefile +3 -0
@@ -25,6 +25,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -52,6 +54,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDFLAGS += -lrt include $(RTE_SDK)/mk/rte.extapp.mk
examples/l2fwd-keepalive/main.c +1 -1
@@ -788,7 +788,7 @@ main(int argc, char **argv) }RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/l2fwd-keepalive/meson.build +1 -0
@@ -8,6 +8,7 @@ ext_deps += cc.find_library('rt') deps += 'timer' +allow_experimental_apis = true sources = files( 'main.c', 'shm.c' )
examples/l2fwd/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/l2fwd/main.c +1 -1
@@ -728,7 +728,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (l2fwd_launch_one_lcore,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) { +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 ) { ret =-1 ;break ; }
examples/l2fwd/meson.build +1 -0
@@ -6,6 +6,7 @@ # To build this example as a standalone application with an already-installed # DPDK instance, use 'make' +allow_experimental_apis = true sources = files( 'main.c' )
examples/l3fwd-acl/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/l3fwd-acl/main.c +1 -1
@@ -2078,7 +2078,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/l3fwd-acl/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['acl', 'lpm', 'hash'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/l3fwd-power/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -56,6 +58,7 @@ else CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/l3fwd-power/main.c +1 -1
@@ -1908,7 +1908,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/l3fwd-power/meson.build +1 -0
@@ -10,6 +10,7 @@ if host_machine.system() != 'linux' build = false endif deps += ['power', 'timer', 'lpm', 'hash'] +allow_experimental_apis = true sources = files( 'main.c', 'perf_core.c' )
examples/l3fwd-vf/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 $(USER_FLAGS) CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/l3fwd-vf/main.c +1 -1
@@ -1088,7 +1088,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/l3fwd-vf/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['lpm', 'hash'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/l3fwd/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -51,6 +53,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -I$(SRCDIR) CFLAGS += -O3 $(USER_FLAGS) CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/l3fwd/main.c +1 -1
@@ -1022,7 +1022,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (l3fwd_lkp.main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) { +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 ) { ret =-1 ;break ; }
examples/l3fwd/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['hash', 'lpm'] +allow_experimental_apis = true sources = files( 'l3fwd_em.c', 'l3fwd_lpm.c', 'main.c' )
examples/link_status_interrupt/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/link_status_interrupt/main.c +1 -1
@@ -703,7 +703,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (lsi_launch_one_lcore,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/link_status_interrupt/meson.build +1 -0
@@ -6,6 +6,7 @@ # To build this example as a standalone application with an already-installed # DPDK instance, use 'make' +allow_experimental_apis = true sources = files( 'main.c' )
examples/load_balancer/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 -g CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS_config.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute
examples/load_balancer/main.c +1 -1
@@ -67,7 +67,7 @@ main(int argc, char **argv)/* Launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (app_lcore_main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore) { -if (rte_eal_wait_lcore (lcore) <0 ) { +if (rte_eal_wait_lcore_sleep (lcore,1000 ) <0 ) {return -1 ; } }
examples/load_balancer/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'lpm' +allow_experimental_apis = true sources = files( 'config.c', 'init.c', 'main.c', 'runtime.c' )
examples/packet_ordering/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/packet_ordering/main.c +1 -1
@@ -720,7 +720,7 @@ main(int argc, char **argv)rx_thread (rx_to_workers);RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/packet_ordering/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'reorder' +allow_experimental_apis = true sources = files( 'main.c' )
examples/performance-thread/l3fwd-thread/Makefile +1 -0
@@ -19,6 +19,7 @@ SRCS-y := main.c include $(RTE_SDK)/examples/performance-thread/common/common.mk CFLAGS += -O3 -g $(USER_FLAGS) $(INCLUDES) $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/performance-thread/l3fwd-thread/main.c +1 -1
@@ -3734,7 +3734,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (pthread_run,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; } }
examples/performance-thread/pthread_shim/Makefile +1 -0
@@ -20,6 +20,7 @@ include $(RTE_SDK)/examples/performance-thread/common/common.mk CFLAGS += -g -O3 $(USER_FLAGS) $(INCLUDES) CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDFLAGS += -lpthread
examples/performance-thread/pthread_shim/main.c +1 -1
@@ -257,7 +257,7 @@ int main(int argc, char **argv)/* wait for threads to stop */ RTE_LCORE_FOREACH_SLAVE (lcore_id) { -rte_eal_wait_lcore (lcore_id); +rte_eal_wait_lcore_sleep (lcore_id,1000 ); }return 0 ; }
examples/qos_meter/Makefile +1 -0
@@ -52,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/qos_meter/main.c +1 -1
@@ -438,7 +438,7 @@ main(int argc, char **argv)/* Launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/qos_meter/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'meter' +allow_experimental_apis = true sources = files( 'main.c', 'rte_policer.c' )
examples/tep_termination/main.c +1 -1
@@ -1238,7 +1238,7 @@ main(int argc, char *argv[]) }RTE_LCORE_FOREACH_SLAVE (lcore_id) -rte_eal_wait_lcore (lcore_id); + rte_eal_wait_lcore_sleep(lcore_id, 1000);return 0 ; }
examples/vhost/main.c +1 -1
@@ -1558,7 +1558,7 @@ main(int argc, char *argv[]) }RTE_LCORE_FOREACH_SLAVE (lcore_id) -rte_eal_wait_lcore (lcore_id); + rte_eal_wait_lcore_sleep(lcore_id, 1000);return 0 ;
examples/vhost_crypto/main.c +1 -1
@@ -582,7 +582,7 @@ main(int argc, char *argv[]) }RTE_LCORE_FOREACH (lcore) -rte_eal_wait_lcore (lcore); + rte_eal_wait_lcore_sleep(lcore, 1000);free_resource ();
examples/vmdq/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -49,6 +51,7 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API EXTRA_CFLAGS += -O3
examples/vmdq/main.c +1 -1
@@ -611,7 +611,7 @@ main(int argc, char *argv[])/* call lcore_main() on every lcore */ rte_eal_mp_remote_launch (lcore_main,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id,1000 ) <0 )return -1 ; }
examples/vmdq/meson.build +1 -0
@@ -6,6 +6,7 @@ # To build this example as a standalone application with an already-installed # DPDK instance, use 'make' +allow_experimental_apis = true sources = files( 'main.c' )
Signature · 1 line
2.17.1
Quoted 11 lines · On Thu, 11 Oct 2018 20:57:52 +0100 Ferruh Yigit <[email protected]> wrote:
lib/librte_eal/common/eal_common_launch.c +11
-0+/* +* Wait until a lcore finished its job by sleeping. +* Sleep time will be times of 'usec' +*/ +int +rte_eal_wait_lcore_sleep (unsigned slave_id,size_t usec) +{ +if (lcore_config[slave_id].state ==WAIT ) +return 0 ; + + while (lcore_config[slave_id].state != WAIT &&
lib/librte_eal/common/eal_common_launch.c rte_eal_wait_lcore(unsigned slave_id) · line 59
Quoted 10 lines
lib/librte_eal/common/eal_common_launch.c +10
-0+ lcore_config[slave_id].state != FINISHED) +usleep (usec); + +rte_rmb (); + +/* we are in finished state, go to wait state */ + lcore_config[slave_id].state =WAIT ; +return lcore_config[slave_id].ret; +} +
Since lcore threads are really pthreads you could avoid doing polling by using a pthread condition (ie. pthread_cond_wait and/or pthread_cond_timedwait)
PATCH v2 1/2 eal: add API that sleeps while waiting for threads
In reply to Ferruh YigitIt is common that sample applications call rte_eal_wait_lcore() while waiting for worker threads to be terminated.
Mostly master lcore keeps waiting in this function.
The waiting app for termination is not a time critical task, app can prefer a sleep version of the waiting to consume less cycles.
A sleeping version of the API, rte_eal_wait_lcore_sleep(), has been added which uses pthread conditions.
Sample applications will be updated later to use this API.
---
v2:
* use pthread cond instead of usleep
--- lib/librte_eal/bsdapp/eal/eal.c | 3 +++ lib/librte_eal/bsdapp/eal/eal_thread.c | 7 ++++++ lib/librte_eal/common/eal_common_launch.c | 22 ++++++++++++++++++ lib/librte_eal/common/include/rte_launch.h | 26 ++++++++++++++++++++++ lib/librte_eal/common/include/rte_lcore.h | 3 +++ lib/librte_eal/linuxapp/eal/eal.c | 3 +++ lib/librte_eal/linuxapp/eal/eal_thread.c | 7 ++++++ lib/librte_eal/rte_eal_version.map | 1 + 8 files changed, 72 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +3 -0
@@ -756,6 +756,9 @@ rte_eal_init(int argc, char **argv)snprintf (thread_name,sizeof (thread_name),"lcore-slave-%d" , i);rte_thread_setname (lcore_config[i].thread_id, thread_name); + +pthread_mutex_init (&rte_eal_thread_mutex[i],NULL ); +pthread_cond_init (&rte_eal_thread_cond[i],NULL ); }/*
lib/librte_eal/bsdapp/eal/eal_thread.c +7 -0
@@ -28,6 +28,9 @@ RTE_DEFINE_PER_LCORE(unsigned, _lcore_id) = LCORE_ID_ANY;RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ;RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); +pthread_cond_t rte_eal_thread_cond[RTE_MAX_LCORE ]; +pthread_mutex_t rte_eal_thread_mutex[RTE_MAX_LCORE ]; +/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
@@ -154,6 +157,10 @@ eal_thread_loop(__attribute__((unused)) void *arg) lcore_config[lcore_id].ret = ret;rte_wmb (); lcore_config[lcore_id].state =FINISHED ; + +pthread_mutex_lock (&rte_eal_thread_mutex[lcore_id]); +pthread_cond_signal (&rte_eal_thread_cond[lcore_id]); +pthread_mutex_unlock (&rte_eal_thread_mutex[lcore_id]); }/* never reached */
lib/librte_eal/common/eal_common_launch.c +22 -0
@@ -5,6 +5,7 @@#include <errno.h> #include <stdint.h> #include <stdio.h> +#include <unistd.h> #include <sys/queue.h> #include <rte_launch.h>
@@ -35,6 +36,27 @@ rte_eal_wait_lcore(unsigned slave_id)return lcore_config[slave_id].ret; } +/* +* Wait until a lcore finished its job by pthread condition. +*/ +int +rte_eal_wait_lcore_sleep (unsigned slave_id) +{ +if (lcore_config[slave_id].state ==WAIT ) +return 0 ; + +pthread_mutex_lock (&rte_eal_thread_mutex[slave_id]); +while (lcore_config[slave_id].state !=WAIT && + lcore_config[slave_id].state !=FINISHED ) +pthread_cond_wait (&rte_eal_thread_cond[slave_id], + &rte_eal_thread_mutex[slave_id]); +pthread_mutex_unlock (&rte_eal_thread_mutex[slave_id]); + +/* we are in finished state, go to wait state */ + lcore_config[slave_id].state =WAIT ; +return lcore_config[slave_id].ret; +} +/* * Check that every SLAVE lcores are in WAIT state, then call * rte_eal_remote_launch() for all of them. If call_master is true
lib/librte_eal/common/include/rte_launch.h +26 -0
@@ -11,6 +11,8 @@* Launch tasks on other lcores */ +#include <rte_compat.h> +#ifdef __cplusplusextern "C" {#endif
@@ -129,6 +131,30 @@ enum rte_lcore_state_t rte_eal_get_lcore_state(unsigned slave_id);*/ int rte_eal_wait_lcore (unsigned slave_id); + +/** +* @warning +* @b EXPERIMENTAL: this API may change without prior notice +* +* Wait until an lcore finishes its job. +* +* To be executed on the MASTER lcore only. +* +* Same as rte_eal_wait_lcore() but waits using pthread conditions +* instead of polling in busy loop. +* +* @param slave_id +* The identifier of the lcore. +* @return +* - 0: If the lcore identified by the slave_id is in a WAIT state. +* - The value that was returned by the previous remote launch +* function call if the lcore identified by the slave_id was in a +* FINISHED or RUNNING state. In this case, it changes the state +* of the lcore to WAIT. +*/ +__rte_experimental int +rte_eal_wait_lcore_sleep (unsigned slave_id); +/** * Wait until all lcores finish their jobs. *
lib/librte_eal/common/include/rte_lcore.h +3 -0
@@ -53,6 +53,9 @@ struct lcore_config {*/ extern struct lcore_config lcore_config[RTE_MAX_LCORE ]; +extern pthread_cond_t rte_eal_thread_cond[RTE_MAX_LCORE ]; +extern pthread_mutex_t rte_eal_thread_mutex[RTE_MAX_LCORE ]; +RTE_DECLARE_PER_LCORE (unsigned, _lcore_id);/**< Per thread "lcore id". */ RTE_DECLARE_PER_LCORE (rte_cpuset_t, _cpuset);/**< Per thread "cpuset". */
lib/librte_eal/linuxapp/eal/eal.c +3 -0
@@ -1019,6 +1019,9 @@ rte_eal_init(int argc, char **argv) lcore_config[i].state =WAIT ; +pthread_mutex_init (&rte_eal_thread_mutex[i],NULL ); +pthread_cond_init (&rte_eal_thread_cond[i],NULL ); +/* create a thread for each lcore */ ret =pthread_create (&lcore_config[i].thread_id,NULL , eal_thread_loop,NULL );
lib/librte_eal/linuxapp/eal/eal_thread.c +7 -0
@@ -28,6 +28,9 @@ RTE_DEFINE_PER_LCORE(unsigned, _lcore_id) = LCORE_ID_ANY;RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ;RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); +pthread_cond_t rte_eal_thread_cond[RTE_MAX_LCORE ]; +pthread_mutex_t rte_eal_thread_mutex[RTE_MAX_LCORE ]; +/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the
@@ -161,6 +164,10 @@ eal_thread_loop(__attribute__((unused)) void *arg) lcore_config[lcore_id].state =WAIT ; else lcore_config[lcore_id].state = FINISHED; + +pthread_mutex_lock (&rte_eal_thread_mutex[lcore_id]); +pthread_cond_signal (&rte_eal_thread_cond[lcore_id]); +pthread_mutex_unlock (&rte_eal_thread_mutex[lcore_id]); }/* never reached */
lib/librte_eal/rte_eal_version.map +1 -0
@@ -292,6 +292,7 @@ EXPERIMENTAL { rte_devargs_remove; rte_devargs_type_count; rte_eal_cleanup; + rte_eal_wait_lcore_sleep; rte_fbarray_attach; rte_fbarray_destroy; rte_fbarray_detach;
Signature · 1 line
2.17.2
PATCH v2 2/2 examples: sleep while waiting worker threads to terminate
This is to prevent sample applications to do busy wait while waiting for worker threads to terminate. Should save cycles on master core. By default a 1ms wait interval used.
--- examples/bbdev_app/main.c | 2 +- examples/distributor/Makefile | 3 +++ examples/distributor/main.c | 2 +- examples/distributor/meson.build | 1 + examples/ethtool/ethtool-app/Makefile | 1 + examples/ethtool/ethtool-app/main.c | 2 +- examples/exception_path/Makefile | 3 +++ examples/exception_path/main.c | 2 +- examples/exception_path/meson.build | 1 + examples/ip_fragmentation/Makefile | 3 +++ examples/ip_fragmentation/main.c | 2 +- examples/ip_fragmentation/meson.build | 1 + examples/ip_reassembly/Makefile | 3 +++ examples/ip_reassembly/main.c | 2 +- examples/ip_reassembly/meson.build | 1 + examples/ipsec-secgw/ipsec-secgw.c | 2 +- examples/ipv4_multicast/Makefile | 3 +++ examples/ipv4_multicast/main.c | 2 +- examples/ipv4_multicast/meson.build | 1 + examples/kni/Makefile | 3 +++ examples/kni/main.c | 2 +- examples/kni/meson.build | 1 + examples/l2fwd-crypto/Makefile | 3 +++ examples/l2fwd-crypto/main.c | 2 +- examples/l2fwd-crypto/meson.build | 1 + examples/l2fwd-jobstats/Makefile | 3 +++ examples/l2fwd-jobstats/main.c | 2 +- examples/l2fwd-jobstats/meson.build | 1 + examples/l2fwd-keepalive/Makefile | 3 +++ examples/l2fwd-keepalive/main.c | 2 +- examples/l2fwd-keepalive/meson.build | 1 + examples/l2fwd/Makefile | 3 +++ examples/l2fwd/main.c | 2 +- examples/l2fwd/meson.build | 1 + examples/l3fwd-acl/Makefile | 3 +++ examples/l3fwd-acl/main.c | 2 +- examples/l3fwd-acl/meson.build | 1 + examples/l3fwd-power/Makefile | 3 +++ examples/l3fwd-power/main.c | 2 +- examples/l3fwd-power/meson.build | 1 + examples/l3fwd-vf/Makefile | 3 +++ examples/l3fwd-vf/main.c | 2 +- examples/l3fwd-vf/meson.build | 1 + examples/l3fwd/Makefile | 3 +++ examples/l3fwd/main.c | 2 +- examples/l3fwd/meson.build | 1 + examples/link_status_interrupt/Makefile | 3 +++ examples/link_status_interrupt/main.c | 2 +- examples/link_status_interrupt/meson.build | 1 + examples/load_balancer/Makefile | 3 +++ examples/load_balancer/main.c | 2 +- examples/load_balancer/meson.build | 1 + examples/packet_ordering/Makefile | 3 +++ examples/packet_ordering/main.c | 2 +- examples/packet_ordering/meson.build | 1 + examples/performance-thread/l3fwd-thread/Makefile | 1 + examples/performance-thread/l3fwd-thread/main.c | 2 +- examples/performance-thread/pthread_shim/Makefile | 1 + examples/performance-thread/pthread_shim/main.c | 2 +- examples/qos_meter/Makefile | 1 + examples/qos_meter/main.c | 2 +- examples/qos_meter/meson.build | 1 + examples/tep_termination/main.c | 2 +- examples/vhost/main.c | 2 +- examples/vhost_crypto/main.c | 2 +- examples/vmdq/Makefile | 3 +++ examples/vmdq/main.c | 2 +- examples/vmdq/meson.build | 1 + 68 files changed, 104 insertions(+), 27 deletions(-)
examples/bbdev_app/main.c +1 -1
@@ -1148,7 +1148,7 @@ main(int argc, char **argv)stats_loop (&stats_lcore);RTE_LCORE_FOREACH_SLAVE (lcore_id) { - ret |=rte_eal_wait_lcore (lcore_id); + ret |=rte_eal_wait_lcore_sleep (lcore_id); }return ret;
examples/distributor/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -49,6 +51,7 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/distributor/main.c +1 -1
@@ -801,7 +801,7 @@ main(int argc, char *argv[]) }RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/distributor/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'distributor' +allow_experimental_apis = true sources = files( 'main.c' )
examples/ethtool/ethtool-app/Makefile +1 -0
@@ -18,6 +18,7 @@ SRCS-y := main.c ethapp.c CFLAGS += -O3 -D_GNU_SOURCE -pthread -I$(SRCDIR)/../lib CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDLIBS += -L$(subst ethtool-app,lib,$(RTE_OUTPUT))/lib LDLIBS += -lrte_ethtool
examples/ethtool/ethtool-app/main.c +1 -1
@@ -276,7 +276,7 @@ int main(int argc, char **argv) app_cfg.exit_now =1 ;RTE_LCORE_FOREACH_SLAVE (id_core) { -if (rte_eal_wait_lcore (id_core) <0 ) +if (rte_eal_wait_lcore_sleep (id_core) <0 )return -1 ; }
examples/exception_path/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk
examples/exception_path/main.c +1 -1
@@ -581,7 +581,7 @@ main(int argc, char** argv)/* Launch per-lcore function on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (i) { -if (rte_eal_wait_lcore (i) <0 ) +if (rte_eal_wait_lcore_sleep (i) <0 )return -1 ; }
examples/exception_path/meson.build +1 -0
@@ -6,6 +6,7 @@ # To build this example as a standalone application with an already-installed # DPDK instance, use 'make' +allow_experimental_apis = true sources = files( 'main.c' )
examples/ip_fragmentation/Makefile +3 -0
@@ -24,6 +24,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -51,6 +53,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/ip_fragmentation/main.c +1 -1
@@ -1018,7 +1018,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/ip_fragmentation/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['ip_frag', 'lpm'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/ip_reassembly/Makefile +3 -0
@@ -24,6 +24,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -51,6 +53,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/ip_reassembly/main.c +1 -1
@@ -1175,7 +1175,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/ip_reassembly/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['lpm', 'ip_frag'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/ipsec-secgw/ipsec-secgw.c +1 -1
@@ -1837,7 +1837,7 @@ main(int32_t argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/ipv4_multicast/Makefile +3 -0
@@ -24,6 +24,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -51,6 +53,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/ipv4_multicast/main.c +1 -1
@@ -793,7 +793,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/ipv4_multicast/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'hash' +allow_experimental_apis = true sources = files( 'main.c' )
examples/kni/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -55,6 +57,7 @@ endif CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/kni/main.c +1 -1
@@ -952,7 +952,7 @@ main(int argc, char** argv)/* Launch per-lcore function on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (i) { -if (rte_eal_wait_lcore (i) <0 ) +if (rte_eal_wait_lcore_sleep (i) <0 )return -1 ; }
examples/kni/meson.build +1 -0
@@ -9,6 +9,7 @@ # this app can be built if-and-only-if KNI library is buildable build = dpdk_conf.has('RTE_LIBRTE_KNI') deps += ['kni', 'bus_pci'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/l2fwd-crypto/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y) ifeq ($(CONFIG_RTE_LIBRTE_PMD_CRYPTO_SCHEDULER),y)
examples/l2fwd-crypto/main.c +1 -1
@@ -2765,7 +2765,7 @@ main(int argc, char **argv)rte_eal_mp_remote_launch (l2fwd_launch_one_lcore, (void *)&options,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/l2fwd-crypto/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'cryptodev' +allow_experimental_apis = true sources = files( 'main.c' )
examples/l2fwd-jobstats/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -51,6 +53,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/l2fwd-jobstats/main.c +1 -1
@@ -995,7 +995,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (l2fwd_launch_one_lcore,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/l2fwd-jobstats/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['jobstats', 'timer'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/l2fwd-keepalive/Makefile +3 -0
@@ -25,6 +25,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -52,6 +54,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDFLAGS += -lrt include $(RTE_SDK)/mk/rte.extapp.mk
examples/l2fwd-keepalive/main.c +1 -1
@@ -788,7 +788,7 @@ main(int argc, char **argv) }RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/l2fwd-keepalive/meson.build +1 -0
@@ -8,6 +8,7 @@ ext_deps += cc.find_library('rt') deps += 'timer' +allow_experimental_apis = true sources = files( 'main.c', 'shm.c' )
examples/l2fwd/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/l2fwd/main.c +1 -1
@@ -728,7 +728,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (l2fwd_launch_one_lcore,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) { +if (rte_eal_wait_lcore_sleep (lcore_id) <0 ) { ret =-1 ;break ; }
examples/l2fwd/meson.build +1 -0
@@ -6,6 +6,7 @@ # To build this example as a standalone application with an already-installed # DPDK instance, use 'make' +allow_experimental_apis = true sources = files( 'main.c' )
examples/l3fwd-acl/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/l3fwd-acl/main.c +1 -1
@@ -2078,7 +2078,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/l3fwd-acl/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['acl', 'lpm', 'hash'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/l3fwd-power/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -56,6 +58,7 @@ else CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/l3fwd-power/main.c +1 -1
@@ -1908,7 +1908,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/l3fwd-power/meson.build +1 -0
@@ -10,6 +10,7 @@ if host_machine.system() != 'linux' build = false endif deps += ['power', 'timer', 'lpm', 'hash'] +allow_experimental_apis = true sources = files( 'main.c', 'perf_core.c' )
examples/l3fwd-vf/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 $(USER_FLAGS) CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/l3fwd-vf/main.c +1 -1
@@ -1088,7 +1088,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/l3fwd-vf/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['lpm', 'hash'] +allow_experimental_apis = true sources = files( 'main.c' )
examples/l3fwd/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -51,6 +53,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -I$(SRCDIR) CFLAGS += -O3 $(USER_FLAGS) CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/l3fwd/main.c +1 -1
@@ -1022,7 +1022,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (l3fwd_lkp.main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) { +if (rte_eal_wait_lcore_sleep (lcore_id) <0 ) { ret =-1 ;break ; }
examples/l3fwd/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += ['hash', 'lpm'] +allow_experimental_apis = true sources = files( 'l3fwd_em.c', 'l3fwd_lpm.c', 'main.c' )
examples/link_status_interrupt/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/link_status_interrupt/main.c +1 -1
@@ -703,7 +703,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (lsi_launch_one_lcore,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/link_status_interrupt/meson.build +1 -0
@@ -6,6 +6,7 @@ # To build this example as a standalone application with an already-installed # DPDK instance, use 'make' +allow_experimental_apis = true sources = files( 'main.c' )
examples/load_balancer/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 -g CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS_config.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute
examples/load_balancer/main.c +1 -1
@@ -67,7 +67,7 @@ main(int argc, char **argv)/* Launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (app_lcore_main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore) { -if (rte_eal_wait_lcore (lcore) <0 ) { +if (rte_eal_wait_lcore_sleep (lcore) <0 ) {return -1 ; } }
examples/load_balancer/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'lpm' +allow_experimental_apis = true sources = files( 'config.c', 'init.c', 'main.c', 'runtime.c' )
examples/packet_ordering/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -50,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API include $(RTE_SDK)/mk/rte.extapp.mk endif
examples/packet_ordering/main.c +1 -1
@@ -720,7 +720,7 @@ main(int argc, char **argv)rx_thread (rx_to_workers);RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/packet_ordering/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'reorder' +allow_experimental_apis = true sources = files( 'main.c' )
examples/performance-thread/l3fwd-thread/Makefile +1 -0
@@ -19,6 +19,7 @@ SRCS-y := main.c include $(RTE_SDK)/examples/performance-thread/common/common.mk CFLAGS += -O3 -g $(USER_FLAGS) $(INCLUDES) $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/performance-thread/l3fwd-thread/main.c +1 -1
@@ -3734,7 +3734,7 @@ main(int argc, char **argv)/* launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (pthread_run,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; } }
examples/performance-thread/pthread_shim/Makefile +1 -0
@@ -20,6 +20,7 @@ include $(RTE_SDK)/examples/performance-thread/common/common.mk CFLAGS += -g -O3 $(USER_FLAGS) $(INCLUDES) CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API LDFLAGS += -lpthread
examples/performance-thread/pthread_shim/main.c +1 -1
@@ -257,7 +257,7 @@ int main(int argc, char **argv)/* wait for threads to stop */ RTE_LCORE_FOREACH_SLAVE (lcore_id) { -rte_eal_wait_lcore (lcore_id); +rte_eal_wait_lcore_sleep (lcore_id); }return 0 ; }
examples/qos_meter/Makefile +1 -0
@@ -52,6 +52,7 @@ include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/qos_meter/main.c +1 -1
@@ -438,7 +438,7 @@ main(int argc, char **argv)/* Launch per-lcore init on every lcore */ rte_eal_mp_remote_launch (main_loop,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/qos_meter/meson.build +1 -0
@@ -7,6 +7,7 @@ # DPDK instance, use 'make' deps += 'meter' +allow_experimental_apis = true sources = files( 'main.c', 'rte_policer.c' )
examples/tep_termination/main.c +1 -1
@@ -1238,7 +1238,7 @@ main(int argc, char *argv[]) }RTE_LCORE_FOREACH_SLAVE (lcore_id) -rte_eal_wait_lcore (lcore_id); +rte_eal_wait_lcore_sleep (lcore_id);return 0 ; }
examples/vhost/main.c +1 -1
@@ -1558,7 +1558,7 @@ main(int argc, char *argv[]) }RTE_LCORE_FOREACH_SLAVE (lcore_id) -rte_eal_wait_lcore (lcore_id); +rte_eal_wait_lcore_sleep (lcore_id);return 0 ;
examples/vhost_crypto/main.c +1 -1
@@ -582,7 +582,7 @@ main(int argc, char *argv[]) }RTE_LCORE_FOREACH (lcore) -rte_eal_wait_lcore (lcore); +rte_eal_wait_lcore_sleep (lcore);free_resource ();
examples/vmdq/Makefile +3 -0
@@ -23,6 +23,8 @@ CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk) +CFLAGS += -DALLOW_EXPERIMENTAL_API + build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
@@ -49,6 +51,7 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc include $(RTE_SDK)/mk/rte.vars.mk CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API EXTRA_CFLAGS += -O3
examples/vmdq/main.c +1 -1
@@ -611,7 +611,7 @@ main(int argc, char *argv[])/* call lcore_main() on every lcore */ rte_eal_mp_remote_launch (lcore_main,NULL ,CALL_MASTER );RTE_LCORE_FOREACH_SLAVE (lcore_id) { -if (rte_eal_wait_lcore (lcore_id) <0 ) +if (rte_eal_wait_lcore_sleep (lcore_id) <0 )return -1 ; }
examples/vmdq/meson.build +1 -0
@@ -6,6 +6,7 @@ # To build this example as a standalone application with an already-installed # DPDK instance, use 'make' +allow_experimental_apis = true sources = files( 'main.c' )
Signature · 1 line
2.17.2
HI Ferruh,
Quoted 53 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Ferruh Yigit
Sent: Monday, October 15, 2018 11:21 PM
To: Richardson, Bruce <[email protected]>
Cc: [email protected]; Yigit, Ferruh <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH v2 1/2] eal: add API that sleeps while waiting for threadsIt is common that sample applications call
rte_eal_wait_lcore()while waiting for worker threads to be terminated.
Mostly master lcore keeps waiting in this function.The waiting app for termination is not a time critical task, app can prefer a sleep version of the waiting to consume less cycles.
A sleeping version of the API,
rte_eal_wait_lcore_sleep(), has been added which uses pthread conditions.Sample applications will be updated later to use this API.
Signed-off-by Ferruh Yigit <[email protected]>---
v2:
* use pthread cond instead of usleep--- lib/librte_eal/bsdapp/eal/eal.c | 3 +++ lib/librte_eal/bsdapp/eal/eal_thread.c | 7 ++++++ lib/librte_eal/common/eal_common_launch.c | 22 ++++++++++++++++++ lib/librte_eal/common/include/rte_launch.h | 26 ++++++++++++++++++++++ lib/librte_eal/common/include/rte_lcore.h | 3 +++ lib/librte_eal/linuxapp/eal/eal.c | 3 +++ lib/librte_eal/linuxapp/eal/eal_thread.c | 7 ++++++ lib/librte_eal/rte_eal_version.map | 1 + 8 files changed, 72 insertions(+)lib/librte_eal/bsdapp/eal/eal.c +3
-0@@ -756,6 +756,9 @@ rte_eal_init(int argc, char **argv)snprintf (thread_name,sizeof (thread_name),"lcore-slave-%d" , i);rte_thread_setname (lcore_config[i].thread_id, thread_name); + +pthread_mutex_init (&rte_eal_thread_mutex[i],NULL ); +pthread_cond_init (&rte_eal_thread_cond[i],NULL ); }/* lib/librte_eal/bsdapp/eal/eal_thread.c +0
-0
lib/librte_eal/bsdapp/eal/eal_thread.c RTE_DEFINE_PER_LCORE(unsigned, _lcore_id) = LCORE_ID_ANY; · line 32
Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal_thread.c +2
-0@@ -28,6 +28,9 @@ RTE_DEFINE_PER_LCORE(unsigned, _lcore_id) = LCORE_ID_ANY;RTE_DEFINE_PER_LCORE (unsigned, _socket_id) = (unsigned )SOCKET_ID_ANY ;RTE_DEFINE_PER_LCORE (rte_cpuset_t, _cpuset); +pthread_cond_t rte_eal_thread_cond[RTE_MAX_LCORE ]; +pthread_mutex_t rte_eal_thread_mutex[RTE_MAX_LCORE ];
I think would be better to include cond and mutex into struct lcore_config itself, probably would help to avoid false sharing.
Though yeh, it would mean ABI breakage, I suppose.
lib/librte_eal/bsdapp/eal/eal_thread.c eal_thread_loop(__attribute__((unused)) void *arg) · line 163
Quoted 12 lines
lib/librte_eal/bsdapp/eal/eal_thread.c +5
-0+/* * Send a message to a slave lcore identified by slave_id to call a * function f with argument arg. Once the execution is done, the @@ -154,6 +157,10 @@ eal_thread_loop(__attribute__((unused)) void *arg) lcore_config[lcore_id].ret = ret;rte_wmb (); lcore_config[lcore_id].state =FINISHED ; + +pthread_mutex_lock (&rte_eal_thread_mutex[lcore_id]); +pthread_cond_signal (&rte_eal_thread_cond[lcore_id]); +pthread_mutex_unlock (&rte_eal_thread_mutex[lcore_id]);
I understand it would work that way too, but if you introduce mutex and cond around the state, then it is better to manipulate/access the state after grabbing the mutex. BTW in that case we don't need wmb:
lcore_config[lcore_id].ret = ret;pthread_mutex_lock(...);
lcore_config[lcore_id].state = FINISHED;pthread_cond_signal(..);pthread_mutex_unlock(...);
Konstantin
Quoted 12 lines
lib/librte_eal/common/eal_common_launch.c +11
-0+/* +* Wait until a lcore finished its job by pthread condition. +*/ +int +rte_eal_wait_lcore_sleep (unsigned slave_id) +{ +if (lcore_config[slave_id].state ==WAIT ) +return 0 ; + +pthread_mutex_lock (&rte_eal_thread_mutex[slave_id]); + while (lcore_config[slave_id].state != WAIT &&
lib/librte_eal/common/eal_common_launch.c rte_eal_wait_lcore(unsigned slave_id) · line 59
Quoted 10 lines
lib/librte_eal/common/eal_common_launch.c +10
-0+ lcore_config[slave_id].state != FINISHED) +pthread_cond_wait (&rte_eal_thread_cond[slave_id], + &rte_eal_thread_mutex[slave_id]); +pthread_mutex_unlock (&rte_eal_thread_mutex[slave_id]); + +/* we are in finished state, go to wait state */ + lcore_config[slave_id].state =WAIT ; +return lcore_config[slave_id].ret; +} +
Actually, another question - could that 2 or more threads wait for the same core simultaneously? If yes, then 2-nd thread in that function might stuck forever.
In that case it is better to use cond_timed_wait() here and cond_broadcast() above. Konstantin
Re: [dpdk-dev] [PATCH v2 2/2] examples: sleep while waiting worker threads to terminate
In reply to Ferruh YigitQuoted 5 lines · On Mon, 15 Oct 2018 23:21:10 +0100 Ferruh Yigit <[email protected]> wrote:
This is to prevent sample applications to do busy wait while waiting for worker threads to terminate. Should save cycles on master core. By default a 1ms wait interval used.
Signed-off-by Ferruh Yigit <[email protected]>
This is not a bad idea, and it might make shutdown faster in some cases. But it looks like it never made it farther along in 5 years. Will mark it as rejected, but it would be good to have better lcore/thread shutdown; if someone wants to work more on it, would be a good project.