sync cfg: notify that it's unsupported, when stack_num > 1

(cherry picked from commit b1760d0d313fd266303f70595be2f6e2f38a5c68)
This commit is contained in:
yinbin6 2024-12-11 16:21:37 +08:00 committed by openeuler-sync-bot
parent 81d04b8e97
commit b0d5ff21f3
8 changed files with 436 additions and 1 deletions

View File

@ -0,0 +1,59 @@
From ac8f22827e961148a8e469e964d58fe248ba03ce Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Wed, 4 Dec 2024 18:00:26 +0800
Subject: [PATCH] openGauss: fix gs_ctl switchover failed
---
src/lstack/api/lstack_unistd.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/lstack/api/lstack_unistd.c b/src/lstack/api/lstack_unistd.c
index 1f78626..e61b0a4 100644
--- a/src/lstack/api/lstack_unistd.c
+++ b/src/lstack/api/lstack_unistd.c
@@ -71,6 +71,24 @@ static void lstack_sig_default_handler(int sig)
(void)kill(getpid(), sig);
}
+static void pthread_block_sig(int sig)
+{
+ sigset_t mask;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, sig);
+ pthread_sigmask(SIG_BLOCK, &mask, NULL);
+}
+
+static void pthread_unblock_sig(int sig)
+{
+ sigset_t mask;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, sig);
+ pthread_sigmask(SIG_UNBLOCK, &mask, NULL);
+}
+
int lstack_signal_init(void)
{
unsigned int i;
@@ -80,6 +98,8 @@ int lstack_signal_init(void)
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
return -1;
}
+ pthread_block_sig(SIGUSR1);
+ pthread_block_sig(SIGUSR2);
sigemptyset(&action.sa_mask);
action.sa_flags = (int)(SA_NODEFER | SA_RESETHAND);
@@ -119,6 +139,8 @@ pid_t lstack_fork(void)
pid = posix_api->fork_fn();
/* child not support lwip */
if (pid == 0) {
+ pthread_unblock_sig(SIGUSR1);
+ pthread_unblock_sig(SIGUSR2);
posix_api->use_kernel = 1;
}
return pid;
--
2.33.0

View File

@ -0,0 +1,30 @@
From 1627afea1cb97f85ffe0877daa3691acb2c67dae Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Wed, 11 Dec 2024 10:04:40 +0800
Subject: [PATCH] openGauss: fix connection attempt failed
---
src/lstack/api/lstack_wrap.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index 4416bd8..4b57e60 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -174,12 +174,7 @@ static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t
struct lwip_sock *sock = lwip_get_socket(s);
int times = 10;
int ret = 0;
- /* lstack not sense if ltran enable kni, so only checks use_ltran. */
- if (!get_global_cfg_params()->use_ltran && !get_global_cfg_params()->kni_switch &&
- !get_global_cfg_params()->flow_bifurcation) {
- POSIX_SET_TYPE(sock, POSIX_LWIP);
- return 0;
- }
+
ret = posix_api->bind_fn(s, name, namelen);
/* maybe kni addr, ipv6 addr maybe is tentative,need to wait a few seconds */
if (name->sa_family == AF_INET6 && ret < 0 && errno == EADDRNOTAVAIL) {
--
2.33.0

View File

@ -0,0 +1,26 @@
From d51c2a23a52d2a2db501abe8cf75c6c2e4fe6bf3 Mon Sep 17 00:00:00 2001
From: compile_success <980965867@qq.com>
Date: Wed, 11 Dec 2024 03:06:17 +0000
Subject: [PATCH] remove app_bind_numa check from exclude_cpus
---
src/lstack/core/lstack_cfg.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index 7545726..6a544b4 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -527,9 +527,6 @@ static int32_t parse_app_exclude_cpus(void)
int32_t cnt;
g_config_params.app_exclude_num_cpu = 0;
- if (!g_config_params.app_bind_numa) {
- return 0;
- }
num_cpus = config_lookup(&g_config, "app_exclude_cpus");
if (num_cpus == NULL) {
--
2.33.0

View File

@ -0,0 +1,99 @@
From f132c0c51e362909081cf0b156ebe093000aa82b Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Tue, 10 Dec 2024 17:12:18 +0800
Subject: [PATCH] fix rpc pool leak, when thread exits
---
src/lstack/core/lstack_thread_rpc.c | 56 +++++++++++++++++++++++------
1 file changed, 45 insertions(+), 11 deletions(-)
diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c
index 26bd16a..d342af4 100644
--- a/src/lstack/core/lstack_thread_rpc.c
+++ b/src/lstack/core/lstack_thread_rpc.c
@@ -24,6 +24,15 @@
#include "lstack_epoll.h"
#include "lstack_lwip.h"
+struct rpc_pool_array {
+#define RPC_POOL_MAX_COUNT 1024
+ struct rpc_msg_pool *array[RPC_POOL_MAX_COUNT];
+ pthread_mutex_t lock;
+ int cur_count;
+};
+
+static struct rpc_pool_array g_rpc_pool_array;
+
static PER_THREAD struct rpc_msg_pool *g_rpc_pool = NULL;
static struct rpc_stats g_rpc_stats;
@@ -32,6 +41,13 @@ 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)
{
@@ -54,23 +70,41 @@ static void rpc_msg_init(struct rpc_msg *msg, rpc_func_t func, struct rpc_msg_po
pthread_spin_init(&msg->lock, PTHREAD_PROCESS_PRIVATE);
}
+static struct rpc_msg_pool *rpc_msg_pool_init(void)
+{
+ struct rpc_msg_pool *rpc_pool;
+ if (g_rpc_pool_array.cur_count >= RPC_POOL_MAX_COUNT) {
+ return g_rpc_pool_array.array[rte_gettid() % RPC_POOL_MAX_COUNT];
+ }
+
+ rpc_pool = calloc(1, sizeof(struct rpc_msg_pool));
+ if (rpc_pool == NULL) {
+ LSTACK_LOG(INFO, LSTACK, "g_rpc_pool calloc failed\n");
+ goto END;
+ }
+ rpc_pool->mempool =
+ create_mempool("rpc_pool", get_global_cfg_params()->rpc_msg_max, sizeof(struct rpc_msg), 0, rte_gettid());
+ if (rpc_pool->mempool == NULL) {
+ LSTACK_LOG(INFO, LSTACK, "rpc_pool create failed, errno is %d\n", errno);
+ free(rpc_pool);
+ goto END;
+ }
+
+ rpc_pool_array_add(rpc_pool);
+ return rpc_pool;
+END:
+ g_rpc_stats.call_alloc_fail++;
+ return NULL;
+}
+
+
static struct rpc_msg *rpc_msg_alloc(rpc_func_t func)
{
struct rpc_msg *msg;
if (unlikely(g_rpc_pool == NULL)) {
- g_rpc_pool = calloc(1, sizeof(struct rpc_msg_pool));
+ g_rpc_pool = rpc_msg_pool_init();
if (g_rpc_pool == NULL) {
- LSTACK_LOG(INFO, LSTACK, "g_rpc_pool calloc failed\n");
- g_rpc_stats.call_alloc_fail++;
- exit(-1);
- }
-
- g_rpc_pool->mempool =
- create_mempool("rpc_pool", get_global_cfg_params()->rpc_msg_max, sizeof(struct rpc_msg), 0, rte_gettid());
- if (g_rpc_pool->mempool == NULL) {
- LSTACK_LOG(INFO, LSTACK, "rpc_pool create failed, errno is %d\n", errno);
- g_rpc_stats.call_alloc_fail++;
exit(-1);
}
}
--
2.33.0

View File

@ -0,0 +1,148 @@
From 2d8ea9ed99116bf034e447307f8360dd24e9449c Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Tue, 10 Dec 2024 16:35:44 +0800
Subject: [PATCH] fix epoll and recv threads blocked on the same semaphore.
data cannot be read in recv thread.
---
src/lstack/api/lstack_epoll.c | 24 +++++++++++++----
src/lstack/core/lstack_lwip.c | 43 ++++++++++++++++++++-----------
src/lstack/include/lstack_epoll.h | 1 +
3 files changed, 48 insertions(+), 20 deletions(-)
diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c
index ff9cccf..644efc0 100644
--- a/src/lstack/api/lstack_epoll.c
+++ b/src/lstack/api/lstack_epoll.c
@@ -73,11 +73,18 @@ void add_sock_event_nolock(struct lwip_sock *sock, uint32_t event)
return;
}
-void add_sock_event(struct lwip_sock *sock, uint32_t event)
+static void _add_sock_event(struct lwip_sock *sock, struct wakeup_poll *wakeup, uint32_t event)
{
- struct wakeup_poll *wakeup = sock->wakeup;
struct protocol_stack *stack = sock->stack;
- if (wakeup == NULL || wakeup->type == WAKEUP_CLOSE || (event & sock->epoll_events) == 0) {
+ if (wakeup == NULL || wakeup->type == WAKEUP_CLOSE) {
+ return;
+ }
+
+ if (wakeup->type == WAKEUP_BLOCK) {
+ if (!(event & (EPOLLIN | EPOLLERR))) {
+ return;
+ }
+ } else if (!(event & sock->epoll_events)) {
return;
}
@@ -91,6 +98,12 @@ void add_sock_event(struct lwip_sock *sock, uint32_t event)
return;
}
+void add_sock_event(struct lwip_sock *sock, uint32_t event)
+{
+ _add_sock_event(sock, sock->wakeup, event);
+ _add_sock_event(sock, sock->recv_block, event);
+}
+
void del_sock_event_nolock(struct lwip_sock *sock, uint32_t event)
{
if (get_global_cfg_params()->stack_mode_rtc) {
@@ -99,7 +112,7 @@ void del_sock_event_nolock(struct lwip_sock *sock, uint32_t event)
if ((event & EPOLLOUT) && !NETCONN_IS_OUTIDLE(sock)) {
sock->events &= ~EPOLLOUT;
}
- if ((event & EPOLLIN) && !NETCONN_IS_DATAIN(sock) && !NETCONN_IS_ACCEPTIN(sock)) {
+ if ((event & EPOLLIN) && !NETCONN_IS_DATAIN(sock) && !NETCONN_IS_ACCEPTIN(sock)) {
sock->events &= ~EPOLLIN;
}
}
@@ -212,7 +225,8 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s
if (wakeup->type == WAKEUP_EPOLL && (sock->events & sock->epoll_events) &&
list_node_null(&sock->event_list)) {
list_add_node(&sock->event_list, &wakeup->event_list);
- sem_post(&wakeup->wait);
+ rte_mb();
+ sem_post(&wakeup->wait);
}
}
pthread_spin_unlock(&wakeup->event_list_lock);
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index 648da58..c1338aa 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -1002,30 +1002,43 @@ static int recv_ring_get_one(struct lwip_sock *sock, bool noblock, struct pbuf *
return 0;
}
- while (gazelle_ring_read(sock->recv_ring, (void **)pbuf, expect) != expect) {
- if (noblock) {
+ if (noblock) {
+ if (gazelle_ring_read(sock->recv_ring, (void **)pbuf, expect) != expect) {
GAZELLE_RETURN(EAGAIN);
}
+ goto END;
+ }
+
+ if (sock->recv_block == NULL) {
+ sock->recv_block = poll_construct_wakeup();
+ if (sock->recv_block == NULL) {
+ GAZELLE_RETURN(ENOMEM);
+ }
+ sock->recv_block->type = WAKEUP_BLOCK;
+ }
+
+ do {
+ __atomic_store_n(&sock->recv_block->in_wait, true, __ATOMIC_RELEASE);
+ if (gazelle_ring_read(sock->recv_ring, (void **)pbuf, expect) == expect) {
+ break;
+ }
if (recv_break_for_err(sock)) {
+ sock->recv_block = NULL;
return -1;
}
- if (unlikely(sock->wakeup == NULL)) {
- sock->wakeup = poll_construct_wakeup();
- if (sock->wakeup == NULL) {
- return -1;
+ ret = lstack_block_wait(sock->recv_block, sock->conn->recv_timeout);
+ if (ret != 0) {
+ if (errno = ETIMEDOUT) {
+ errno = EAGAIN;
}
- sock->epoll_events = POLLIN | POLLERR;
- }
-
- ret = lstack_block_wait(sock->wakeup, sock->conn->recv_timeout);
- if (ret == ETIMEDOUT) {
- noblock = true;
- } else if (ret != 0 && errno == EINTR) {
- /* SIGALRM signal may interrupt blocking */
+ sock->recv_block = NULL;
return ret;
}
- }
+ } while (1);
+ __atomic_store_n(&sock->recv_block->in_wait, false, __ATOMIC_RELEASE);
+ sock->recv_block = NULL;
+END:
if (get_protocol_stack_group()->latency_start) {
calculate_lstack_latency(&sock->stack->latency, *pbuf, GAZELLE_LATENCY_READ_APP_CALL, time_stamp);
}
diff --git a/src/lstack/include/lstack_epoll.h b/src/lstack/include/lstack_epoll.h
index cad9aed..83eace7 100644
--- a/src/lstack/include/lstack_epoll.h
+++ b/src/lstack/include/lstack_epoll.h
@@ -28,6 +28,7 @@ enum wakeup_type {
WAKEUP_EPOLL = 0,
WAKEUP_POLL,
WAKEUP_CLOSE,
+ WAKEUP_BLOCK,
};
struct protocol_stack;
--
2.33.0

View File

@ -0,0 +1,25 @@
From 4de27f4f182bec258313d736d423b3b0ab4ff057 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Wed, 11 Dec 2024 15:31:15 +0800
Subject: [PATCH] fix errno == ETIMEFOUT
---
src/lstack/core/lstack_lwip.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index c1338aa..1bff5ca 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -1028,7 +1028,7 @@ static int recv_ring_get_one(struct lwip_sock *sock, bool noblock, struct pbuf *
}
ret = lstack_block_wait(sock->recv_block, sock->conn->recv_timeout);
if (ret != 0) {
- if (errno = ETIMEDOUT) {
+ if (errno == ETIMEDOUT) {
errno = EAGAIN;
}
sock->recv_block = NULL;
--
2.33.0

View File

@ -0,0 +1,32 @@
From e03be16e5deab1f8cdaf1ec6b6097184c643063d Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Wed, 11 Dec 2024 10:50:39 +0800
Subject: [PATCH] cfg: notify that it's unsupported, when stack_num > 1
---
src/lstack/core/lstack_cfg.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index 7545726..48408d1 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -509,6 +509,15 @@ static int32_t parse_stack_num(void)
{
int32_t ret;
PARSE_ARG(g_config_params.stack_num, "stack_num", 0, 0, 320, ret);
+ if (ret != 0) {
+ return ret;
+ }
+
+ if (g_config_params.stack_num > 1) {
+ LSTACK_LOG(ERR, LSTACK, "Multi stacks bound to numa are not supported currently. Please set stack_num <= 1.\n");
+ return -EINVAL;
+ }
+
return ret;
}
--
2.33.0

View File

@ -2,7 +2,7 @@
Name: gazelle
Version: 1.0.2
Release: 78
Release: 79
Summary: gazelle is a high performance user-mode stack
License: MulanPSL-2.0
URL: https://gitee.com/openeuler/gazelle
@ -315,6 +315,13 @@ Patch9295: 0295-CFG-fix-xdp-iface-check-error.patch
Patch9296: 0296-xdp-support-stack-bind-numa.patch
Patch9297: 0297-openGauss-support-kernel-connnect.patch
Patch9298: 0298-DUMP-gazelle-supports-dump-lstack.patch
Patch9299: 0299-openGauss-fix-gs_ctl-switchover-failed.patch
Patch9300: 0300-openGauss-fix-connection-attempt-failed.patch
Patch9301: 0301-remove-app_bind_numa-check-from-exclude_cpus.patch
Patch9302: 0302-fix-rpc-pool-leak-when-thread-exits.patch
Patch9303: 0303-fix-epoll-and-recv-threads-blocked-on-the-same-semap.patch
Patch9304: 0304-fix-errno-ETIMEFOUT.patch
Patch9305: 0305-cfg-notify-that-it-s-unsupported-when-stack_num-1.patch
%description
%{name} is a high performance user-mode stack.
@ -356,6 +363,15 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b
%config(noreplace) %{conf_path}/ltran.conf
%changelog
* Wed Dec 11 2024 yinbin6 <yinbin8@huawei.com> - 1.0.2-79
- cfg: notify that it's unsupported, when stack_num > 1
- fix errno == ETIMEFOUT
- fix epoll and recv threads blocked on the same semaphore. data cannot be read in recv thread.
- fix rpc pool leak, when thread exits
- remove app_bind_numa check from exclude_cpus
- openGauss: fix connection attempt failed
- openGauss: fix gs_ctl switchover failed
* Wed Dec 04 2024 yinbin6 <yinbin8@huawei.com> - 1.0.2-78
- DUMP: gazelle supports dump lstack