Add support for using hugepages for worker lcore stack memory. The intent is to improve performance by reducing stack memory related TLB misses and also by using memory local to the NUMA node of each lcore.
Platforms desiring to make use of this capability must enable the associated option flag and stack size settings in platform config files. --- lib/eal/linux/eal.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 1ef263434a..4e1e5b6915 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -1143,9 +1143,48 @@ rte_eal_init(int argc, char **argv) lcore_config[i].state = WAIT; +#ifdef RTE_EAL_NUMA_AWARE_LCORE_STACK + /* Allocate NUMA aware stack memory and set pthread attributes */ + pthread_attr_t attr; + void *stack_ptr = + rte_zmalloc_socket("lcore_stack", + RTE_EAL_NUMA_AWARE_LCORE_STACK_SIZE, + RTE_EAL_NUMA_AWARE_LCORE_STACK_SIZE, + rte_lcore_to_socket_id(i)); + + if (stack_ptr == NULL) { + rte_eal_init_alert("Cannot allocate stack memory"); + rte_errno = ENOMEM; + return -1; + } + + if (pthread_attr_init(&attr) != 0) { + rte_eal_init_alert("Cannot init pthread attributes"); + rte_errno = EINVAL; + return -1; + } + if (pthread_attr_setstack(&attr, + stack_ptr, + RTE_EAL_NUMA_AWARE_LCORE_STACK_SIZE) != 0) { + rte_eal_init_alert("Cannot set pthread stack attributes"); + rte_errno = ENOTSUP; + return -1; + } + + /* create a thread for each lcore */ + ret = pthread_create(&lcore_config[i].thread_id, &attr, + eal_thread_loop, (void *)(uintptr_t)i); + + if (pthread_attr_destroy(&attr) != 0) { + rte_eal_init_alert("Cannot destroy pthread attributes"); + rte_errno = EFAULT; + return -1; + } +#else /* create a thread for each lcore */ ret = pthread_create(&lcore_config[i].thread_id, NULL, eal_thread_loop, (void *)(uintptr_t)i); +#endif if (ret != 0) rte_panic("Cannot create thread\n"); -- 2.17.1