From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f178.google.com (mail-pd0-f178.google.com [209.85.192.178]) by dpdk.org (Postfix) with ESMTP id 25E91C390 for ; Sat, 18 Apr 2015 21:33:56 +0200 (CEST) Received: by pdea3 with SMTP id a3so163180968pde.3 for ; Sat, 18 Apr 2015 12:33:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=271XBQKkG0VLCPBKO23sOr75e5KTzvy73fQQq4VN7kI=; b=CoJuhiDriODPB/XtHtjr8nlXW1385ymSzjNF+zKujiUA7hsYf0Cdubzv96uVVu9kD+ Bx+0kDyY6k1P1IkyNiUP0YhdAz/XuJKB37vKfprb0VkExOrGK4wSU9i5tvBgHQ8dcQ4P 3GEgUZkAiuOHJKtICv/fq+sv8/ywW594qsWnj4y1hRvixLHr7kj4bSTtIUQSgXicpmTw kUA98ixGgP1p+wxT7l13OpYqZoO7hOm1cglD45chDeCH2MYKCf/On5HrstSJSkJAtAfZ QLpt4/tnryUZOlWVBhIIowe4I/G6HkKqma1AGhQStU220uI3lsDALWN7SpeCS4nyCw3h qIcg== X-Received: by 10.68.132.233 with SMTP id ox9mr15418925pbb.83.1429385635533; Sat, 18 Apr 2015 12:33:55 -0700 (PDT) Received: from user-PC.hsd1.ca.comcast.net (c-98-234-176-9.hsd1.ca.comcast.net. [98.234.176.9]) by mx.google.com with ESMTPSA id ul8sm13722397pab.36.2015.04.18.12.33.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Apr 2015 12:33:54 -0700 (PDT) From: Ravi Kerur To: dev@dpdk.org Date: Sat, 18 Apr 2015 12:33:46 -0700 Message-Id: <1429385631-12277-1-git-send-email-rkerur@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429385571-12218-1-git-send-email-rkerur@gmail.com> References: <1429385571-12218-1-git-send-email-rkerur@gmail.com> Subject: [dpdk-dev] [PATCH v6 1/9] Move common functions in eal_thread.c X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Apr 2015 19:33:56 -0000 Changes in v6 Remove RTE_EXEC_ENV_BSDAPP from eal_common_thread.c file. Add pthread_setname_np/pthread_set_name_np for Linux/FreeBSD respectively. Plan to use _getname_ in RTE_LOG when available. Use existing rte_get_systid() in RTE_LOG to print thread_id. Changes in v5 Rebase to latest code. Changes in v4 None Changes in v3 Changed subject to be more explicit on file name inclusion. Changes in v2 None Changes in v1 eal_thread.c has minor differences between Linux and BSD, move entire file into common directory. Use RTE_EXEC_ENV_BSDAPP to differentiate on minor differences. Rename eal_thread.c to eal_common_thread.c Makefile changes to reflect file move and name change. Fix checkpatch warnings. Signed-off-by: Ravi Kerur --- examples/vhost/main.c | 18 ++- examples/vhost_xen/main.c | 18 ++- lib/librte_eal/bsdapp/eal/Makefile | 2 +- lib/librte_eal/bsdapp/eal/eal.c | 7 + lib/librte_eal/bsdapp/eal/eal_thread.c | 152 --------------------- lib/librte_eal/common/eal_common_thread.c | 147 +++++++++++++++++++- lib/librte_eal/common/eal_thread.h | 5 + lib/librte_eal/linuxapp/eal/Makefile | 2 + lib/librte_eal/linuxapp/eal/eal.c | 10 ++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 11 ++ lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c | 22 ++- lib/librte_eal/linuxapp/eal/eal_thread.c | 152 +-------------------- lib/librte_eal/linuxapp/eal/eal_timer.c | 15 +- 13 files changed, 250 insertions(+), 311 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index ad10f82..ee36525 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -2891,6 +2891,7 @@ main(int argc, char *argv[]) uint8_t portid; uint16_t queue_id; static pthread_t tid; + char thread_name[RTE_THREAD_NAME_LEN]; /* init EAL */ ret = rte_eal_init(argc, argv); @@ -3017,8 +3018,21 @@ main(int argc, char *argv[]) memset(&dev_statistics, 0, sizeof(dev_statistics)); /* Enable stats if the user option is set. */ - if (enable_stats) - pthread_create(&tid, NULL, (void*)print_stats, NULL ); + if (enable_stats) { + snprintf(thread_name, RTE_THREAD_NAME_LEN, "vhost-stats"); + + ret = pthread_create(&tid, NULL, (void*)print_stats, NULL ); + + if (ret != 0) + rte_exit(EXIT_FAILURE, + "Cannot create print-stats thread\n"); + + ret = pthread_setname_np(tid, thread_name); + + if (ret != 0) + rte_exit(EXIT_FAILURE, + "Cannot set print-stats name\n"); + } /* Launch all data cores. */ if (zero_copy == 0) { diff --git a/examples/vhost_xen/main.c b/examples/vhost_xen/main.c index b4a86e3..530b047 100644 --- a/examples/vhost_xen/main.c +++ b/examples/vhost_xen/main.c @@ -1433,6 +1433,7 @@ main(int argc, char *argv[]) int ret; uint8_t portid; static pthread_t tid; + char thread_name[RTE_THREAD_NAME_LEN]; /* init EAL */ ret = rte_eal_init(argc, argv); @@ -1505,9 +1506,24 @@ main(int argc, char *argv[]) memset(&dev_statistics, 0, sizeof(dev_statistics)); /* Enable stats if the user option is set. */ - if (enable_stats) + if (enable_stats) { + + snprintf(thread_name, RTE_THREAD_NAME_LEN, + "vhost-xen-stats"); + pthread_create(&tid, NULL, (void*)print_stats, NULL ); + if (ret != 0) + rte_exit(EXIT_FAILURE, + "Cannot create print-stats thread\n"); + + ret = pthread_setname_np(tid, thread_name); + + if (ret != 0) + rte_exit(EXIT_FAILURE, + "Cannot set print-stats name\n"); + } + /* Launch all data cores. */ RTE_LCORE_FOREACH_SLAVE(lcore_id) { rte_eal_remote_launch(switch_worker, mbuf_pool, lcore_id); diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile index 2357cfa..55971b9 100644 --- a/lib/librte_eal/bsdapp/eal/Makefile +++ b/lib/librte_eal/bsdapp/eal/Makefile @@ -87,7 +87,7 @@ CFLAGS_eal_common_log.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603 ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y) -CFLAGS_eal_thread.o += -Wno-return-type +CFLAGS_eal_common_thread.o += -Wno-return-type CFLAGS_eal_hpet.o += -Wno-return-type endif diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 871d5f4..6b756d5 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -437,6 +437,7 @@ rte_eal_init(int argc, char **argv) int i, fctret, ret; pthread_t thread_id; static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0); + char thread_name[RTE_THREAD_NAME_LEN]; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; if (!rte_atomic32_test_and_set(&run_once)) @@ -525,6 +526,9 @@ rte_eal_init(int argc, char **argv) RTE_LCORE_FOREACH_SLAVE(i) { + snprintf(thread_name, RTE_THREAD_NAME_LEN, + "lcore-slave-%d", i); + /* * create communication pipes between master thread * and children @@ -541,6 +545,9 @@ rte_eal_init(int argc, char **argv) eal_thread_loop, NULL); if (ret != 0) rte_panic("Cannot create thread\n"); + + pthread_set_name_np( + lcore_config[i].thread_id, (const char *)thread_name); } /* diff --git a/lib/librte_eal/bsdapp/eal/eal_thread.c b/lib/librte_eal/bsdapp/eal/eal_thread.c index 9a03437..5714b8f 100644 --- a/lib/librte_eal/bsdapp/eal/eal_thread.c +++ b/lib/librte_eal/bsdapp/eal/eal_thread.c @@ -35,163 +35,11 @@ #include #include #include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE(unsigned, _lcore_id) = LCORE_ID_ANY; -RTE_DEFINE_PER_LCORE(unsigned, _socket_id) = (unsigned)SOCKET_ID_ANY; -RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset); - -/* - * Send a message to a slave lcore identified by slave_id to call a - * function f with argument arg. Once the execution is done, the - * remote lcore switch in FINISHED state. - */ -int -rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id) -{ - int n; - char c = 0; - int m2s = lcore_config[slave_id].pipe_master2slave[1]; - int s2m = lcore_config[slave_id].pipe_slave2master[0]; - - if (lcore_config[slave_id].state != WAIT) - return -EBUSY; - - lcore_config[slave_id].f = f; - lcore_config[slave_id].arg = arg; - - /* send message */ - n = 0; - while (n == 0 || (n < 0 && errno == EINTR)) - n = write(m2s, &c, 1); - if (n < 0) - rte_panic("cannot write on configuration pipe\n"); - - /* wait ack */ - do { - n = read(s2m, &c, 1); - } while (n < 0 && errno == EINTR); - - if (n <= 0) - rte_panic("cannot read on configuration pipe\n"); - - return 0; -} - -/* set affinity for current thread */ -static int -eal_thread_set_affinity(void) -{ - unsigned lcore_id = rte_lcore_id(); - - /* acquire system unique id */ - rte_gettid(); - - /* update EAL thread core affinity */ - return rte_thread_set_affinity(&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master(unsigned lcore_id) -{ - /* set the lcore ID in per-lcore memory area */ - RTE_PER_LCORE(_lcore_id) = lcore_id; - - /* set CPU affinity */ - if (eal_thread_set_affinity() < 0) - rte_panic("cannot set affinity\n"); -} - -/* main loop of threads */ -__attribute__((noreturn)) void * -eal_thread_loop(__attribute__((unused)) void *arg) -{ - char c; - int n, ret; - unsigned lcore_id; - pthread_t thread_id; - int m2s, s2m; - char cpuset[RTE_CPU_AFFINITY_STR_LEN]; - - thread_id = pthread_self(); - - /* retrieve our lcore_id from the configuration structure */ - RTE_LCORE_FOREACH_SLAVE(lcore_id) { - if (thread_id == lcore_config[lcore_id].thread_id) - break; - } - if (lcore_id == RTE_MAX_LCORE) - rte_panic("cannot retrieve lcore id\n"); - - m2s = lcore_config[lcore_id].pipe_master2slave[0]; - s2m = lcore_config[lcore_id].pipe_slave2master[1]; - - /* set the lcore ID in per-lcore memory area */ - RTE_PER_LCORE(_lcore_id) = lcore_id; - - /* set CPU affinity */ - if (eal_thread_set_affinity() < 0) - rte_panic("cannot set affinity\n"); - - ret = eal_thread_dump_affinity(cpuset, RTE_CPU_AFFINITY_STR_LEN); - - RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%p;cpuset=[%s%s])\n", - lcore_id, thread_id, cpuset, ret == 0 ? "" : "..."); - - /* read on our pipe to get commands */ - while (1) { - void *fct_arg; - - /* wait command */ - do { - n = read(m2s, &c, 1); - } while (n < 0 && errno == EINTR); - - if (n <= 0) - rte_panic("cannot read on configuration pipe\n"); - - lcore_config[lcore_id].state = RUNNING; - - /* send ack */ - n = 0; - while (n == 0 || (n < 0 && errno == EINTR)) - n = write(s2m, &c, 1); - if (n < 0) - rte_panic("cannot write on configuration pipe\n"); - - if (lcore_config[lcore_id].f == NULL) - rte_panic("NULL function pointer\n"); - - /* call the function and store the return value */ - fct_arg = lcore_config[lcore_id].arg; - ret = lcore_config[lcore_id].f(fct_arg); - lcore_config[lcore_id].ret = ret; - rte_wmb(); - lcore_config[lcore_id].state = FINISHED; - } - - /* never reached */ - /* pthread_exit(NULL); */ - /* return NULL; */ -} - /* require calling thread tid by gettid() */ int rte_sys_gettid(void) { diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index 2405e93..48dfd95 100644 --- a/lib/librte_eal/common/eal_common_thread.c +++ b/lib/librte_eal/common/eal_common_thread.c @@ -31,11 +31,12 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include #include -#include +#include #include #include #include @@ -43,10 +44,21 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include "eal_private.h" #include "eal_thread.h" RTE_DECLARE_PER_LCORE(unsigned , _socket_id); +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); unsigned rte_socket_id(void) { @@ -155,3 +167,136 @@ exit: return ret; } + +/* + * 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 + * remote lcore switch in FINISHED state. + */ +int +rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id) +{ + int n; + char c = 0; + int m2s = lcore_config[slave_id].pipe_master2slave[1]; + int s2m = lcore_config[slave_id].pipe_slave2master[0]; + + if (lcore_config[slave_id].state != WAIT) + return -EBUSY; + + lcore_config[slave_id].f = f; + lcore_config[slave_id].arg = arg; + + /* send message */ + n = 0; + while (n == 0 || (n < 0 && errno == EINTR)) + n = write(m2s, &c, 1); + if (n < 0) + rte_panic("cannot write on configuration pipe\n"); + + /* wait ack */ + do { + n = read(s2m, &c, 1); + } while (n < 0 && errno == EINTR); + + if (n <= 0) + rte_panic("cannot read on configuration pipe\n"); + + return 0; +} + +/* set affinity for current EAL thread */ +static int +eal_thread_set_affinity(void) +{ + unsigned lcore_id = rte_lcore_id(); + + /* acquire system unique id */ + rte_gettid(); + + /* update EAL thread core affinity */ + return rte_thread_set_affinity(&lcore_config[lcore_id].cpuset); +} + +void eal_thread_init_master(unsigned lcore_id) +{ + /* set the lcore ID in per-lcore memory area */ + RTE_PER_LCORE(_lcore_id) = lcore_id; + + /* set CPU affinity */ + if (eal_thread_set_affinity() < 0) + rte_panic("cannot set affinity\n"); +} + +/* main loop of threads */ +__attribute__((noreturn)) void * +eal_thread_loop(__attribute__((unused)) void *arg) +{ + char c; + int n, ret; + unsigned lcore_id; + pthread_t thread_id; + int m2s, s2m; + char cpuset[RTE_CPU_AFFINITY_STR_LEN]; + + thread_id = pthread_self(); + + /* retrieve our lcore_id from the configuration structure */ + RTE_LCORE_FOREACH_SLAVE(lcore_id) { + if (thread_id == lcore_config[lcore_id].thread_id) + break; + } + if (lcore_id == RTE_MAX_LCORE) + rte_panic("cannot retrieve lcore id\n"); + + m2s = lcore_config[lcore_id].pipe_master2slave[0]; + s2m = lcore_config[lcore_id].pipe_slave2master[1]; + + /* set the lcore ID in per-lcore memory area */ + RTE_PER_LCORE(_lcore_id) = lcore_id; + + /* set CPU affinity */ + if (eal_thread_set_affinity() < 0) + rte_panic("cannot set affinity\n"); + + ret = eal_thread_dump_affinity(cpuset, RTE_CPU_AFFINITY_STR_LEN); + + RTE_LOG(DEBUG, EAL, "lcore %u is ready (thread=%d;cpuset=[%s%s])\n", + lcore_id, rte_sys_gettid(), cpuset, ret == 0 ? "" : "..."); + + /* read on our pipe to get commands */ + while (1) { + void *fct_arg; + + /* wait command */ + do { + n = read(m2s, &c, 1); + } while (n < 0 && errno == EINTR); + + if (n <= 0) + rte_panic("cannot read on configuration pipe\n"); + + lcore_config[lcore_id].state = RUNNING; + + /* send ack */ + n = 0; + while (n == 0 || (n < 0 && errno == EINTR)) + n = write(s2m, &c, 1); + if (n < 0) + rte_panic("cannot write on configuration pipe\n"); + + if (lcore_config[lcore_id].f == NULL) + rte_panic("NULL function pointer\n"); + + /* call the function and store the return value */ + fct_arg = lcore_config[lcore_id].arg; + ret = lcore_config[lcore_id].f(fct_arg); + lcore_config[lcore_id].ret = ret; + rte_wmb(); + lcore_config[lcore_id].state = FINISHED; + } + + /* never reached */ + /* pthread_exit(NULL); */ + /* return NULL; */ +} diff --git a/lib/librte_eal/common/eal_thread.h b/lib/librte_eal/common/eal_thread.h index e4e76b9..df7dccd 100644 --- a/lib/librte_eal/common/eal_thread.h +++ b/lib/librte_eal/common/eal_thread.h @@ -80,6 +80,11 @@ int eal_cpuset_socket_id(rte_cpuset_t *cpusetp); #define RTE_CPU_AFFINITY_STR_LEN 256 /** + * Default buffer size for thread name + */ +#define RTE_THREAD_NAME_LEN 32 + +/** * Dump the current pthread cpuset. * This function is private to EAL. * diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index 01f7b70..cf2271c 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -93,6 +93,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c CFLAGS_eal.o := -D_GNU_SOURCE CFLAGS_eal_interrupts.o := -D_GNU_SOURCE +CFLAGS_eal_timer.o := -D_GNU_SOURCE CFLAGS_eal_lcore.o := -D_GNU_SOURCE CFLAGS_eal_thread.o := -D_GNU_SOURCE CFLAGS_eal_log.o := -D_GNU_SOURCE @@ -101,6 +102,7 @@ CFLAGS_eal_hugepage_info.o := -D_GNU_SOURCE CFLAGS_eal_pci.o := -D_GNU_SOURCE CFLAGS_eal_pci_uio.o := -D_GNU_SOURCE CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE +CFLAGS_eal_pci_vfio_mp_sync.o := -D_GNU_SOURCE CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE CFLAGS_eal_common_options.o := -D_GNU_SOURCE CFLAGS_eal_common_thread.o := -D_GNU_SOURCE diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index bd770cf..6335a41 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -703,6 +703,7 @@ rte_eal_init(int argc, char **argv) pthread_t thread_id; static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0); struct shared_driver *solib = NULL; + char thread_name[RTE_THREAD_NAME_LEN]; const char *logid; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; @@ -816,6 +817,9 @@ rte_eal_init(int argc, char **argv) RTE_LCORE_FOREACH_SLAVE(i) { + snprintf(thread_name, RTE_THREAD_NAME_LEN, + "lcore-slave-%d", i); + /* * create communication pipes between master thread * and children @@ -832,6 +836,12 @@ rte_eal_init(int argc, char **argv) eal_thread_loop, NULL); if (ret != 0) rte_panic("Cannot create thread\n"); + + ret = pthread_setname_np( + lcore_config[i].thread_id, thread_name); + + if (ret != 0) + rte_panic("Cannot set name for the thread\n"); } /* diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c index 66deda2..5487d58 100644 --- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c +++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c @@ -66,6 +66,7 @@ #include "eal_private.h" #include "eal_vfio.h" +#include "eal_thread.h" #define EAL_INTR_EPOLL_WAIT_FOREVER (-1) @@ -838,6 +839,7 @@ int rte_eal_intr_init(void) { int ret = 0; + char thread_name[RTE_THREAD_NAME_LEN]; /* init the global interrupt source head */ TAILQ_INIT(&intr_sources); @@ -849,6 +851,9 @@ rte_eal_intr_init(void) if (pipe(intr_pipe.pipefd) < 0) return -1; + snprintf(thread_name, RTE_THREAD_NAME_LEN, + "eal-intr-thread"); + /* create the host thread to wait/handle the interrupt */ ret = pthread_create(&intr_thread, NULL, eal_intr_thread_main, NULL); @@ -856,6 +861,12 @@ rte_eal_intr_init(void) RTE_LOG(ERR, EAL, "Failed to create thread for interrupt handling\n"); + ret = pthread_setname_np(intr_thread, thread_name); + + if (ret != 0) + RTE_LOG(ERR, EAL, + "Failed to set thread name for interrupt handling\n"); + return -ret; } diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c index fec7080..c23374d 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c @@ -34,6 +34,7 @@ #include #include #include +#include /* sys/un.h with __USE_MISC uses strlen, which is unsafe */ #ifdef __USE_MISC @@ -54,6 +55,7 @@ #include "eal_filesystem.h" #include "eal_pci_init.h" +#include "eal_thread.h" /** * @file @@ -374,20 +376,36 @@ int pci_vfio_mp_sync_setup(void) { int ret; + char thread_name[RTE_THREAD_NAME_LEN]; if (vfio_mp_sync_socket_setup() < 0) { RTE_LOG(ERR, EAL, "Failed to set up local socket!\n"); return -1; } + snprintf(thread_name, RTE_THREAD_NAME_LEN, + "pci-vfio-mp-sync"); + ret = pthread_create(&socket_thread, NULL, pci_vfio_mp_sync_thread, NULL); if (ret) { - RTE_LOG(ERR, EAL, "Failed to create thread for communication with " - "secondary processes!\n"); + RTE_LOG(ERR, EAL, + "Failed to create thread for communication with " + "secondary processes!\n"); + close(mp_socket_fd); + return -1; + } + + ret = pthread_setname_np(socket_thread, thread_name); + + if (ret) { + RTE_LOG(ERR, EAL, + "Failed to set thread name for " + "secondary processes!\n"); close(mp_socket_fd); return -1; } + return 0; } diff --git a/lib/librte_eal/linuxapp/eal/eal_thread.c b/lib/librte_eal/linuxapp/eal/eal_thread.c index 18bd8e0..51dca37 100644 --- a/lib/librte_eal/linuxapp/eal/eal_thread.c +++ b/lib/librte_eal/linuxapp/eal/eal_thread.c @@ -34,163 +34,13 @@ #include #include #include -#include #include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "eal_private.h" #include "eal_thread.h" -RTE_DEFINE_PER_LCORE(unsigned, _lcore_id) = LCORE_ID_ANY; -RTE_DEFINE_PER_LCORE(unsigned, _socket_id) = (unsigned)SOCKET_ID_ANY; -RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset); - -/* - * Send a message to a slave lcore identified by slave_id to call a - * function f with argument arg. Once the execution is done, the - * remote lcore switch in FINISHED state. - */ -int -rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id) -{ - int n; - char c = 0; - int m2s = lcore_config[slave_id].pipe_master2slave[1]; - int s2m = lcore_config[slave_id].pipe_slave2master[0]; - - if (lcore_config[slave_id].state != WAIT) - return -EBUSY; - - lcore_config[slave_id].f = f; - lcore_config[slave_id].arg = arg; - - /* send message */ - n = 0; - while (n == 0 || (n < 0 && errno == EINTR)) - n = write(m2s, &c, 1); - if (n < 0) - rte_panic("cannot write on configuration pipe\n"); - - /* wait ack */ - do { - n = read(s2m, &c, 1); - } while (n < 0 && errno == EINTR); - - if (n <= 0) - rte_panic("cannot read on configuration pipe\n"); - - return 0; -} - -/* set affinity for current EAL thread */ -static int -eal_thread_set_affinity(void) -{ - unsigned lcore_id = rte_lcore_id(); - - /* acquire system unique id */ - rte_gettid(); - - /* update EAL thread core affinity */ - return rte_thread_set_affinity(&lcore_config[lcore_id].cpuset); -} - -void eal_thread_init_master(unsigned lcore_id) -{ - /* set the lcore ID in per-lcore memory area */ - RTE_PER_LCORE(_lcore_id) = lcore_id; - - /* set CPU affinity */ - if (eal_thread_set_affinity() < 0) - rte_panic("cannot set affinity\n"); -} - -/* main loop of threads */ -__attribute__((noreturn)) void * -eal_thread_loop(__attribute__((unused)) void *arg) -{ - char c; - int n, ret; - unsigned lcore_id; - pthread_t thread_id; - int m2s, s2m; - char cpuset[RTE_CPU_AFFINITY_STR_LEN]; - - thread_id = pthread_self(); - - /* retrieve our lcore_id from the configuration structure */ - RTE_LCORE_FOREACH_SLAVE(lcore_id) { - if (thread_id == lcore_config[lcore_id].thread_id) - break; - } - if (lcore_id == RTE_MAX_LCORE) - rte_panic("cannot retrieve lcore id\n"); - - m2s = lcore_config[lcore_id].pipe_master2slave[0]; - s2m = lcore_config[lcore_id].pipe_slave2master[1]; - - /* set the lcore ID in per-lcore memory area */ - RTE_PER_LCORE(_lcore_id) = lcore_id; - - /* set CPU affinity */ - if (eal_thread_set_affinity() < 0) - rte_panic("cannot set affinity\n"); - - ret = eal_thread_dump_affinity(cpuset, RTE_CPU_AFFINITY_STR_LEN); - - RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%x;cpuset=[%s%s])\n", - lcore_id, (int)thread_id, cpuset, ret == 0 ? "" : "..."); - - /* read on our pipe to get commands */ - while (1) { - void *fct_arg; - - /* wait command */ - do { - n = read(m2s, &c, 1); - } while (n < 0 && errno == EINTR); - - if (n <= 0) - rte_panic("cannot read on configuration pipe\n"); - - lcore_config[lcore_id].state = RUNNING; - - /* send ack */ - n = 0; - while (n == 0 || (n < 0 && errno == EINTR)) - n = write(s2m, &c, 1); - if (n < 0) - rte_panic("cannot write on configuration pipe\n"); - - if (lcore_config[lcore_id].f == NULL) - rte_panic("NULL function pointer\n"); - - /* call the function and store the return value */ - fct_arg = lcore_config[lcore_id].arg; - ret = lcore_config[lcore_id].f(fct_arg); - lcore_config[lcore_id].ret = ret; - rte_wmb(); - lcore_config[lcore_id].state = FINISHED; - } - - /* never reached */ - /* pthread_exit(NULL); */ - /* return NULL; */ -} +#include /* require calling thread tid by gettid() */ int rte_sys_gettid(void) diff --git a/lib/librte_eal/linuxapp/eal/eal_timer.c b/lib/librte_eal/linuxapp/eal/eal_timer.c index 169c6e1..b19b18e 100644 --- a/lib/librte_eal/linuxapp/eal/eal_timer.c +++ b/lib/librte_eal/linuxapp/eal/eal_timer.c @@ -54,6 +54,7 @@ #include "eal_private.h" #include "eal_internal_cfg.h" +#include "eal_thread.h" enum timer_source eal_timer_source = EAL_TIMER_HPET; @@ -186,6 +187,7 @@ int rte_eal_hpet_init(int make_default) { int fd, ret; + char thread_name[RTE_THREAD_NAME_LEN]; if (internal_config.no_hpet) { RTE_LOG(INFO, EAL, "HPET is disabled\n"); @@ -224,16 +226,27 @@ rte_eal_hpet_init(int make_default) eal_hpet_msb = (eal_hpet->counter_l >> 30); + snprintf(thread_name, RTE_THREAD_NAME_LEN, "hpet-msb-inc"); + /* create a thread that will increment a global variable for * msb (hpet is 32 bits by default under linux) */ ret = pthread_create(&msb_inc_thread_id, NULL, (void *(*)(void *))hpet_msb_inc, NULL); - if (ret < 0) { + if (ret != 0) { RTE_LOG(ERR, EAL, "ERROR: Cannot create HPET timer thread!\n"); internal_config.no_hpet = 1; return -1; } + ret = pthread_setname_np(msb_inc_thread_id, thread_name); + + if (ret != 0) { + RTE_LOG(ERR, EAL, + "ERROR: Cannot set HPET timer thread name!\n"); + internal_config.no_hpet = 1; + return -1; + } + if (make_default) eal_timer_source = EAL_TIMER_HPET; return 0; -- 1.9.1