gazelle/0306-fix-a-contention-issue-when-rpc-pools-are-added-to-r.patch
yinbin c2057605b8 sync Connect: execute lwip connect if dst_ip and host_ip are in the same network.
(cherry picked from commit 674a95ff9395859b5b14ede0ed1be07a0fa13ea4)
2024-12-18 19:05:13 +08:00

66 lines
2.1 KiB
Diff

From 6dce1a0ac071e365cb96551b04f555dec3658d85 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Thu, 12 Dec 2024 16:39:48 +0800
Subject: [PATCH] fix a contention issue when rpc pools are added to
rpc_pool_array
---
src/lstack/core/lstack_thread_rpc.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c
index d342af4..050594e 100644
--- a/src/lstack/core/lstack_thread_rpc.c
+++ b/src/lstack/core/lstack_thread_rpc.c
@@ -31,7 +31,9 @@ struct rpc_pool_array {
int cur_count;
};
-static struct rpc_pool_array g_rpc_pool_array;
+static struct rpc_pool_array g_rpc_pool_array = {
+ .lock = PTHREAD_MUTEX_INITIALIZER,
+};
static PER_THREAD struct rpc_msg_pool *g_rpc_pool = NULL;
static struct rpc_stats g_rpc_stats;
@@ -41,13 +43,6 @@ struct rpc_stats *rpc_stats_get(void)
return &g_rpc_stats;
}
-static inline void rpc_pool_array_add(struct rpc_msg_pool *pool)
-{
- pthread_mutex_lock(&g_rpc_pool_array.lock);
- g_rpc_pool_array.array[g_rpc_pool_array.cur_count++] = pool;
- pthread_mutex_unlock(&g_rpc_pool_array.lock);
-}
-
__rte_always_inline
static struct rpc_msg *get_rpc_msg(struct rpc_msg_pool *rpc_pool)
{
@@ -73,7 +68,9 @@ static void rpc_msg_init(struct rpc_msg *msg, rpc_func_t func, struct rpc_msg_po
static struct rpc_msg_pool *rpc_msg_pool_init(void)
{
struct rpc_msg_pool *rpc_pool;
+ pthread_mutex_lock(&g_rpc_pool_array.lock);
if (g_rpc_pool_array.cur_count >= RPC_POOL_MAX_COUNT) {
+ pthread_mutex_unlock(&g_rpc_pool_array.lock);
return g_rpc_pool_array.array[rte_gettid() % RPC_POOL_MAX_COUNT];
}
@@ -90,9 +87,11 @@ static struct rpc_msg_pool *rpc_msg_pool_init(void)
goto END;
}
- rpc_pool_array_add(rpc_pool);
+ g_rpc_pool_array.array[g_rpc_pool_array.cur_count++] = rpc_pool;
+ pthread_mutex_unlock(&g_rpc_pool_array.lock);
return rpc_pool;
END:
+ pthread_mutex_unlock(&g_rpc_pool_array.lock);
g_rpc_stats.call_alloc_fail++;
return NULL;
}
--
2.33.0