From be7a7d55a672a72328f1a6844c610152ea142053 Mon Sep 17 00:00:00 2001 From: jianheng Date: Wed, 14 Dec 2022 09:51:36 +0800 Subject: [PATCH] fix kernel event thread bind numa failed --- src/lstack/core/lstack_cfg.c | 13 +++++------- src/lstack/core/lstack_protocol_stack.c | 28 ++++++++++--------------- src/lstack/include/lstack_cfg.h | 3 ++- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c index 1731c0f..81452e8 100644 --- a/src/lstack/core/lstack_cfg.c +++ b/src/lstack/core/lstack_cfg.c @@ -329,11 +329,10 @@ static int32_t stack_idle_cpuset(struct protocol_stack *stack, cpu_set_t *exclud return 0; } -int32_t init_stack_numa_cpuset(void) +int32_t init_stack_numa_cpuset(struct protocol_stack *stack) { int32_t ret; struct cfg_params *cfg = get_global_cfg_params(); - struct protocol_stack_group *stack_group = get_protocol_stack_group(); cpu_set_t stack_cpuset; CPU_ZERO(&stack_cpuset); @@ -344,12 +343,10 @@ int32_t init_stack_numa_cpuset(void) CPU_SET(cfg->wakeup[idx], &stack_cpuset); } - for (int32_t idx = 0; idx < stack_group->stack_num; ++idx) { - ret = stack_idle_cpuset(stack_group->stacks[idx], &stack_cpuset); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "thread_get_cpuset stack_%d failed\n", idx); - return -1; - } + ret = stack_idle_cpuset(stack, &stack_cpuset); + if (ret < 0) { + LSTACK_LOG(ERR, LSTACK, "thread_get_cpuset stack(%u) failed\n", stack->tid); + return -1; } return 0; diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c index d5830f1..c0925a1 100644 --- a/src/lstack/core/lstack_protocol_stack.c +++ b/src/lstack/core/lstack_protocol_stack.c @@ -352,21 +352,18 @@ static struct protocol_stack *stack_thread_init(uint16_t queue_id) } if (init_stack_value(stack, queue_id) != 0) { - sem_post(&stack_group->thread_phase1); - free(stack); - return NULL; + goto END; } + if (init_stack_numa_cpuset(stack) < 0) { + goto END; + } if (create_affiliate_thread(queue_id, stack_group->wakeup_enable) < 0) { - sem_post(&stack_group->thread_phase1); - free(stack); - return NULL; + goto END; } if (thread_affinity_init(stack->cpu_id) != 0) { - sem_post(&stack_group->thread_phase1); - free(stack); - return NULL; + goto END; } RTE_PER_LCORE(_lcore_id) = stack->cpu_id; @@ -376,9 +373,7 @@ static struct protocol_stack *stack_thread_init(uint16_t queue_id) if (use_ltran()) { if (client_reg_thrd_ring() != 0) { - sem_post(&stack_group->thread_phase1); - free(stack); - return NULL; + goto END; } } @@ -394,6 +389,10 @@ static struct protocol_stack *stack_thread_init(uint16_t queue_id) } return stack; +END: + sem_post(&stack_group->thread_phase1); + free(stack); + return NULL; } static void wakeup_kernel_event(struct protocol_stack *stack) @@ -526,11 +525,6 @@ int32_t init_protocol_stack(void) return -1; } - ret = init_stack_numa_cpuset(); - if (ret < 0) { - return -1; - } - return 0; } diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h index 7075bbc..fe92bc9 100644 --- a/src/lstack/include/lstack_cfg.h +++ b/src/lstack/include/lstack_cfg.h @@ -16,6 +16,7 @@ #include +#include "lstack_protocol_stack.h" #include "gazelle_opt.h" #define BASE_BIN_SCALE 2 @@ -97,6 +98,6 @@ int gazelle_copy_param(const char *param, bool is_double, int *argc, char argv[][PATH_MAX]); int match_host_addr(uint32_t ipv4); -int32_t init_stack_numa_cpuset(void); +int32_t init_stack_numa_cpuset(struct protocol_stack *stack); #endif /* GAZELLE_NET_CFG_H */ -- 2.33.0