From ef60d87b8430ccdf3ba20e0ea5882354e8462238 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Fri, 2 Jun 2017 11:40:23 -0700 Subject: [PATCH] env: Add wrappers to launch and wait for threads Change-Id: Ied778fc41ddc5ff7563408eccafc0e0654287b19 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/363608 Reviewed-by: Daniel Verkamp Tested-by: SPDK Automated Test System --- include/spdk/env.h | 18 ++++++++++++++++++ lib/env_dpdk/threads.c | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/spdk/env.h b/include/spdk/env.h index a9222c8d6..3261717df 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -207,6 +207,24 @@ uint32_t spdk_env_get_next_core(uint32_t prev_core); */ uint32_t spdk_env_get_socket_id(uint32_t core); +typedef int (*thread_start_fn)(void *); + +/** + * \brief Launch a thread pinned to the given core. Only a single pinned thread + * may be launched per core. Subsequent attempts to launch pinned threads on + * that core will fail. + * + * \param core The core to pin the thread to. + * \param fn Entry point on the new thread. + * \param arg Argument apssed to thread_start_fn + */ +int spdk_env_thread_launch_pinned(uint32_t core, thread_start_fn fn, void *arg); + +/** + * \brief Wait for all threads to exit before returning. + */ +void spdk_env_thread_wait_all(void); + /** * Return true if the calling process is primary process */ diff --git a/lib/env_dpdk/threads.c b/lib/env_dpdk/threads.c index d070917a0..3a06d0446 100644 --- a/lib/env_dpdk/threads.c +++ b/lib/env_dpdk/threads.c @@ -71,3 +71,19 @@ spdk_env_get_socket_id(uint32_t core) { return rte_lcore_to_socket_id(core); } + +int +spdk_env_thread_launch_pinned(uint32_t core, thread_start_fn fn, void *arg) +{ + int rc; + + rc = rte_eal_remote_launch(fn, arg, core); + + return rc; +} + +void +spdk_env_thread_wait_all(void) +{ + rte_eal_mp_wait_lcore(); +}