!1122 sync patches of oe2003sp4

From: @yinbin6 
Reviewed-by: @LemmyHuang 
Signed-off-by: @LemmyHuang
This commit is contained in:
openeuler-ci-bot 2024-12-19 07:15:21 +00:00 committed by Gitee
commit f29997d80e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
31 changed files with 3920 additions and 3 deletions

View File

@ -0,0 +1,25 @@
From e35d6ffd66becc2725b38115322307261dd87f07 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Sat, 2 Nov 2024 19:00:31 +0800
Subject: [PATCH] interrupt: fix timeout events cannot be counted
---
src/lstack/core/lstack_interrupt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lstack/core/lstack_interrupt.c b/src/lstack/core/lstack_interrupt.c
index 26823cd..67b763c 100644
--- a/src/lstack/core/lstack_interrupt.c
+++ b/src/lstack/core/lstack_interrupt.c
@@ -317,7 +317,7 @@ static inline void intr_block(uint16_t stack_id, uint32_t timeout)
}
}
- if (event_cnt < 0) {
+ if (event_cnt == 0) {
intr_config->stats.timeout_event_cnt++;
}
}
--
2.33.0

View File

@ -0,0 +1,76 @@
From 84897b16c0a93606817443f792da97b5923fbdf0 Mon Sep 17 00:00:00 2001
From: hankangkang <hankangkang5@huawei.com>
Date: Thu, 31 Oct 2024 16:06:21 +0800
Subject: [PATCH] remove: code about nobolck mode for mysql
---
src/lstack/api/lstack_rtw_api.c | 5 +----
src/lstack/core/lstack_cfg.c | 9 ---------
src/lstack/include/lstack_cfg.h | 1 -
3 files changed, 1 insertion(+), 14 deletions(-)
diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c
index 8765463..eab379c 100644
--- a/src/lstack/api/lstack_rtw_api.c
+++ b/src/lstack/api/lstack_rtw_api.c
@@ -190,10 +190,7 @@ static int stack_broadcast_accept4(int fd, struct sockaddr *addr, socklen_t *add
static int stack_broadcast_accept(int fd, struct sockaddr *addr, socklen_t *addrlen)
{
- if (get_global_cfg_params()->nonblock_mode)
- return stack_broadcast_accept4(fd, addr, addrlen, O_NONBLOCK);
- else
- return stack_broadcast_accept4(fd, addr, addrlen, 0);
+ return stack_broadcast_accept4(fd, addr, addrlen, 0);
}
/* choice one stack listen */
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index f239b60..4c8f066 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -81,7 +81,6 @@ static int32_t parse_nic_rxqueue_size(void);
static int32_t parse_nic_txqueue_size(void);
static int32_t parse_stack_thread_mode(void);
static int32_t parse_nic_vlan_mode(void);
-static int32_t parse_defaule_nonblock_mode(void);
static int32_t parse_rpc_msg_max(void);
static int32_t parse_send_cache_mode(void);
static int32_t parse_flow_bifurcation(void);
@@ -149,7 +148,6 @@ static struct config_vector_t g_config_tbl[] = {
{ "nic_txqueue_size", parse_nic_txqueue_size},
{ "stack_thread_mode", parse_stack_thread_mode },
{ "nic_vlan_mode", parse_nic_vlan_mode },
- { "nonblock_mode", parse_defaule_nonblock_mode },
{ "rpc_msg_max", parse_rpc_msg_max },
{ "send_cache_mode", parse_send_cache_mode },
{ "flow_bifurcation", parse_flow_bifurcation},
@@ -1358,13 +1356,6 @@ static int32_t parse_nic_vlan_mode(void)
return ret;
}
-static int32_t parse_defaule_nonblock_mode(void)
-{
- int32_t ret;
- PARSE_ARG(g_config_params.nonblock_mode, "nonblock_mode", 1, 0, 1, ret);
- return ret;
-}
-
static int32_t parse_rpc_msg_max(void)
{
int32_t ret;
diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h
index 071492d..876423d 100644
--- a/src/lstack/include/lstack_cfg.h
+++ b/src/lstack/include/lstack_cfg.h
@@ -136,7 +136,6 @@ struct cfg_params {
struct { // deprecated
char unix_socket_filename[NAME_MAX];
bool use_ltran; // false:lstack read from nic. true:lstack read form ltran process.
- bool nonblock_mode;
bool udp_enable;
bool kni_switch;
};
--
2.33.0

View File

@ -0,0 +1,40 @@
From c33bfd14030ee84d4da1a5083fe47271f4cb27bb Mon Sep 17 00:00:00 2001
From: yinbin <yinbin8@huawei.com>
Date: Tue, 5 Nov 2024 19:55:52 +0800
Subject: [PATCH] LOG: Optimize some log displays
---
src/lstack/core/lstack_init.c | 2 +-
src/lstack/core/lstack_thread_rpc.c | 3 ---
2 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c
index 8ffc3a1..276cdf8 100644
--- a/src/lstack/core/lstack_init.c
+++ b/src/lstack/core/lstack_init.c
@@ -264,7 +264,7 @@ __attribute__((constructor)) void gazelle_network_init(void)
/* check conflict */
if (check_process_conflict() < 0) {
- LSTACK_PRE_LOG(LSTACK_INFO, "Have another same primary process. WARNING: Posix API will use kernel mode!\n");
+ LSTACK_PRE_LOG(LSTACK_INFO, "Main process has been initialized, this process will use kernel mode!\n");
return;
}
diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c
index aed792d..26bd16a 100644
--- a/src/lstack/core/lstack_thread_rpc.c
+++ b/src/lstack/core/lstack_thread_rpc.c
@@ -470,9 +470,6 @@ int rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, sock
static void callback_getpeername(struct rpc_msg *msg)
{
msg->result = lwip_getpeername(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].p);
- if (msg->result != 0) {
- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d fail %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result);
- }
}
static void callback_getsockname(struct rpc_msg *msg)
--
2.33.0

View File

@ -0,0 +1,967 @@
From 10eb6041c9a3e632b9fc2e769d7e726fbf7c9dd8 Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Sat, 2 Nov 2024 16:03:54 +0800
Subject: [PATCH] xdp: support bind no cpu mode
---
src/common/gazelle_base_func.h | 8 +
src/common/gazelle_reg_msg.h | 21 +-
src/lstack/api/lstack_rtw_api.c | 3 -
src/lstack/api/lstack_wrap.c | 2 +-
src/lstack/core/lstack_cfg.c | 303 +++++++++++----------
src/lstack/core/lstack_dpdk.c | 64 ++++-
src/lstack/core/lstack_protocol_stack.c | 113 +++-----
src/lstack/include/lstack_cfg.h | 10 +-
src/lstack/include/lstack_dpdk.h | 2 +
src/lstack/include/lstack_protocol_stack.h | 3 +-
src/lstack/include/lstack_thread_rpc.h | 2 +
src/lstack/netif/lstack_flow.c | 6 +-
12 files changed, 289 insertions(+), 248 deletions(-)
diff --git a/src/common/gazelle_base_func.h b/src/common/gazelle_base_func.h
index be87ccd..a579cd4 100644
--- a/src/common/gazelle_base_func.h
+++ b/src/common/gazelle_base_func.h
@@ -13,6 +13,8 @@
#ifndef __GAZELLE_BASE_FUNC_H__
#define __GAZELLE_BASE_FUNC_H__
+#include <math.h>
+
#define GAZELLE_FREE(p) do { \
if (p) { \
free(p); \
@@ -28,6 +30,12 @@
#define NODE_ENTRY(node, type, member) \
((type*)((char*)(node) - (size_t)&((type*)0)->member))
+#define MB_IN_BYTES (1024 * 1024)
+static inline int bytes_to_mb(uint32_t bytes)
+{
+ return ceil((double)bytes / MB_IN_BYTES);
+}
+
int32_t separate_str_to_array(char *args, uint32_t *array, int32_t array_size, int32_t max_value);
int32_t check_and_set_run_dir(void);
diff --git a/src/common/gazelle_reg_msg.h b/src/common/gazelle_reg_msg.h
index d849cea..f9de32c 100644
--- a/src/common/gazelle_reg_msg.h
+++ b/src/common/gazelle_reg_msg.h
@@ -17,19 +17,22 @@
#include "gazelle_opt.h"
-#define NULL_CLIENT_IP UINT32_MAX
-#define NULL_CLIENT_PORT UINT16_MAX
+#define NULL_CLIENT_IP UINT32_MAX
+#define NULL_CLIENT_PORT UINT16_MAX
-#define GAZELLE_MAX_REG_ARGS 32
+#define GAZELLE_MAX_REG_ARGS 32
#define ENQUEUE_RING_RETRY_TIMEOUT 10 // ms
-#define OPT_BASE_VIRTADDR "--base-virtaddr"
-#define OPT_FILE_PREFIX "--file-prefix"
-#define OPT_SOCKET_MEM "--socket-mem"
-#define OPT_LEGACY_MEM "--legacy-mem"
-#define OPT_HUGE_DIR "--huge-dir"
-#define OPT_BIND_CORELIST "-l"
+#define OPT_BASE_VIRTADDR "--base-virtaddr"
+#define OPT_FILE_PREFIX "--file-prefix"
+#define OPT_SOCKET_MEM "--socket-mem"
+#define OPT_LEGACY_MEM "--legacy-mem"
+#define OPT_HUGE_DIR "--huge-dir"
+#define OPT_BIND_CORELIST "-l"
+
+#define GAZELLE_MAX_NUMA_NODES 4
+#define SOCKET_MEM_STRLEN (GAZELLE_MAX_NUMA_NODES * 10)
/* types for msg from lstack to ltran */
enum response_type {
diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c
index eab379c..1b02e2a 100644
--- a/src/lstack/api/lstack_rtw_api.c
+++ b/src/lstack/api/lstack_rtw_api.c
@@ -235,9 +235,6 @@ static int stack_broadcast_listen(int fd, int backlog)
#endif
for (int32_t i = 0; i < stack_group->stack_num; ++i) {
stack = stack_group->stacks[i];
- if (get_global_cfg_params()->seperate_send_recv && stack->is_send_thread) {
- continue;
- }
if (stack != cur_stack) {
clone_fd = rpc_call_shadow_fd(&stack->rpc_queue, fd, (struct sockaddr *)&addr, addr_len);
if (clone_fd < 0) {
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index 66cea51..c228cab 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -393,7 +393,7 @@ static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, v
#define SO_NUMA_ID 0x100c
if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP && !unsupport_optname(level, optname)) {
if (level == IPPROTO_IP && optname == SO_NUMA_ID) {
- return lwip_get_socket(s)->stack->socket_id;
+ return lwip_get_socket(s)->stack->numa_id;
}
return g_wrap_api->getsockopt_fn(s, level, optname, optval, optlen);
}
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index 4c8f066..43482af 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -22,14 +22,18 @@
#include <limits.h>
#include <unistd.h>
#include <sched.h>
+#include <numa.h>
#include <rte_eth_bond.h>
+#include <rte_eal.h>
+#include <rte_lcore.h>
#include <lwip/lwipgz_sock.h>
#include <lwip/inet.h>
#include "common/gazelle_reg_msg.h"
#include "common/gazelle_base_func.h"
#include "lstack_log.h"
+#include "lstack_dpdk.h"
#include "lstack_cfg.h"
#define DEFAULT_CONF_FILE "/etc/gazelle/lstack.conf"
@@ -70,7 +74,6 @@ static int32_t parse_recv_ring_size(void);
static int32_t parse_num_process(void);
static int32_t parse_process_numa(void);
static int32_t parse_process_index(void);
-static int32_t parse_seperate_sendrecv_args(void);
static int32_t parse_tuple_filter(void);
static int32_t parse_bond_mode(void);
static int32_t parse_bond_miimon(void);
@@ -85,6 +88,7 @@ static int32_t parse_rpc_msg_max(void);
static int32_t parse_send_cache_mode(void);
static int32_t parse_flow_bifurcation(void);
static int32_t parse_stack_interrupt(void);
+static int32_t parse_stack_num(void);
#define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \
do { \
@@ -118,9 +122,16 @@ static struct config_vector_t g_config_tbl[] = {
{ "mask_addr", parse_mask_addr },
{ "use_ltran", parse_use_ltran },
{ "devices", parse_devices },
- { "dpdk_args", parse_dpdk_args },
- { "seperate_send_recv", parse_seperate_sendrecv_args },
+ { "tcp_conn_count", parse_tcp_conn_count },
+ { "mbuf_count_per_conn", parse_mbuf_count_per_conn },
+ { "nic_rxqueue_size", parse_nic_rxqueue_size},
+ { "nic_txqueue_size", parse_nic_txqueue_size},
+ { "send_ring_size", parse_send_ring_size },
+ { "recv_ring_size", parse_recv_ring_size },
+ { "rpc_msg_max", parse_rpc_msg_max },
+ { "stack_num", parse_stack_num },
{ "num_cpus", parse_stack_cpu_number },
+ { "dpdk_args", parse_dpdk_args },
{ "low_power_mode", parse_low_power_mode },
{ "kni_switch", parse_kni_switch },
{ "listen_shadow", parse_listen_shadow },
@@ -128,13 +139,9 @@ static struct config_vector_t g_config_tbl[] = {
{ "app_exclude_cpus", parse_app_exclude_cpus },
{ "main_thread_affinity", parse_main_thread_affinity },
{ "unix_prefix", parse_unix_prefix },
- { "tcp_conn_count", parse_tcp_conn_count },
- { "mbuf_count_per_conn", parse_mbuf_count_per_conn },
{ "read_connect_number", parse_read_connect_number },
{ "rpc_number", parse_rpc_number },
{ "nic_read_number", parse_nic_read_number },
- { "send_ring_size", parse_send_ring_size },
- { "recv_ring_size", parse_recv_ring_size },
{ "num_process", parse_num_process },
{ "process_numa", parse_process_numa },
{ "process_idx", parse_process_index },
@@ -144,11 +151,8 @@ static struct config_vector_t g_config_tbl[] = {
{ "bond_slave_mac", parse_bond_slave_mac },
{ "use_sockmap", parse_use_sockmap },
{ "udp_enable", parse_udp_enable },
- { "nic_rxqueue_size", parse_nic_rxqueue_size},
- { "nic_txqueue_size", parse_nic_txqueue_size},
{ "stack_thread_mode", parse_stack_thread_mode },
{ "nic_vlan_mode", parse_nic_vlan_mode },
- { "rpc_msg_max", parse_rpc_msg_max },
{ "send_cache_mode", parse_send_cache_mode },
{ "flow_bifurcation", parse_flow_bifurcation},
{ "stack_interrupt", parse_stack_interrupt},
@@ -354,135 +358,80 @@ static int32_t get_param_idx(int32_t argc, char **argv, const char *param)
return -1;
}
-static bool have_corelist_arg(int32_t argc, char **argv)
+static int32_t stack_bind_no_cpu(void)
{
- for (uint32_t i = 0; i < argc; i++) {
- if (strncmp(argv[i], OPT_BIND_CORELIST, strlen(OPT_BIND_CORELIST)) == 0) {
- return true;
- }
+ uint16_t numa_id = 0;
+
+ /* launch a lstack thread when neither num_cpus nor stack_num is specified */
+ if (g_config_params.stack_num == 0) {
+ g_config_params.stack_num = 1;
+ }
- if (strncmp(argv[i], "--lcores", strlen("--lcores")) == 0) {
- return true;
- }
-
- if (strncmp(argv[i], "-c", strlen("-c")) == 0) {
- return true;
- }
+ numa_id = numa_node_of_cpu(sched_getcpu());
+ if (numa_id < 0) {
+ return -EINVAL;
+ }
- if (strncmp(argv[i], "-s", strlen("-s")) == 0) {
- return true;
- }
+ g_config_params.numa_id = numa_id;
+ g_config_params.num_cpu = g_config_params.stack_num;
+ g_config_params.num_queue = g_config_params.num_cpu;
+ g_config_params.tot_queue_num = g_config_params.num_queue;
- if (strncmp(argv[i], "-S", strlen("-S")) == 0) {
- return true;
- }
- }
+ LSTACK_PRE_LOG(LSTACK_INFO, "NUMA node: %d\n", g_config_params.numa_id);
- return false;
+ return 0;
}
-static int32_t parse_stack_cpu_number(void)
+
+static int32_t stack_bind_cpus(void)
{
- const config_setting_t *num_cpus = NULL;
+ int cnt = 0;
+ char *tmp_arg = NULL;
const char *args = NULL;
+ const config_setting_t *num_cpus = NULL;
- if (!g_config_params.seperate_send_recv) {
- num_cpus = config_lookup(&g_config, "num_cpus");
- if (num_cpus == NULL) {
- return -EINVAL;
- }
-
- args = config_setting_get_string(num_cpus);
- if (args == NULL) {
- return -EINVAL;
- }
-
- if (!have_corelist_arg(g_config_params.dpdk_argc, g_config_params.dpdk_argv)) {
- int32_t idx = get_param_idx(g_config_params.dpdk_argc, g_config_params.dpdk_argv, OPT_BIND_CORELIST);
- if (idx < 0) {
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(OPT_BIND_CORELIST);
- g_config_params.dpdk_argc++;
-
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(args);
- g_config_params.dpdk_argc++;
- }
- }
-
- char *tmp_arg = strdup_assert_return(args);
- int32_t cnt = separate_str_to_array(tmp_arg, g_config_params.cpus, CFG_MAX_CPUS, CFG_MAX_CPUS);
- free(tmp_arg);
- if (cnt <= 0 || cnt > CFG_MAX_CPUS) {
- return -EINVAL;
- }
-
- g_config_params.num_cpu = cnt;
- g_config_params.num_queue = (uint16_t)cnt;
- g_config_params.tot_queue_num = g_config_params.num_queue;
- } else {
- // send_num_cpus
- num_cpus = config_lookup(&g_config, "send_num_cpus");
- if (num_cpus == NULL) {
- return -EINVAL;
- }
-
- args = config_setting_get_string(num_cpus);
- if (args == NULL) {
- return -EINVAL;
- }
-
- if (!have_corelist_arg(g_config_params.dpdk_argc, g_config_params.dpdk_argv)) {
- int32_t idx = get_param_idx(g_config_params.dpdk_argc, g_config_params.dpdk_argv, OPT_BIND_CORELIST);
- if (idx < 0) {
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(OPT_BIND_CORELIST);
- g_config_params.dpdk_argc++;
-
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(args);
- g_config_params.dpdk_argc++;
- }
- }
-
- char *tmp_arg_send = strdup_assert_return(args);
- int32_t send_cpu_cnt = separate_str_to_array(tmp_arg_send, g_config_params.send_cpus,
- CFG_MAX_CPUS, CFG_MAX_CPUS);
- free(tmp_arg_send);
-
- // recv_num_cpus
- num_cpus = config_lookup(&g_config, "recv_num_cpus");
- if (num_cpus == NULL) {
- return -EINVAL;
- }
+ num_cpus = config_lookup(&g_config, "num_cpus");
+ if (num_cpus == NULL) {
+ return stack_bind_no_cpu();
+ }
- args = config_setting_get_string(num_cpus);
- if (args == NULL) {
- return -EINVAL;
- }
+ args = config_setting_get_string(num_cpus);
+ if (args == NULL) {
+ return -EINVAL;
+ }
- if (!have_corelist_arg(g_config_params.dpdk_argc, g_config_params.dpdk_argv)) {
- int32_t idx = get_param_idx(g_config_params.dpdk_argc, g_config_params.dpdk_argv, OPT_BIND_CORELIST);
- if (idx < 0) {
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(OPT_BIND_CORELIST);
- g_config_params.dpdk_argc++;
+ strcpy(g_config_params.lcores, args);
- g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(args);
- g_config_params.dpdk_argc++;
- }
- }
+ tmp_arg = strdup_assert_return(args);
+ cnt = separate_str_to_array(tmp_arg, g_config_params.cpus, CFG_MAX_CPUS, CFG_MAX_CPUS);
+ free(tmp_arg);
+ if (cnt <= 0) {
+ return stack_bind_no_cpu();
+ } else if (cnt > CFG_MAX_CPUS) {
+ return -EINVAL;
+ }
- char *tmp_arg_recv = strdup_assert_return(args);
- int32_t recv_cpu_cnt = separate_str_to_array(tmp_arg_recv, g_config_params.recv_cpus,
- CFG_MAX_CPUS, CFG_MAX_CPUS);
- free(tmp_arg_recv);
+ g_config_params.num_cpu = cnt;
+ g_config_params.num_queue = (uint16_t)cnt;
+ g_config_params.tot_queue_num = g_config_params.num_queue;
- if (send_cpu_cnt <= 0 || send_cpu_cnt > CFG_MAX_CPUS / 2 || send_cpu_cnt != recv_cpu_cnt) {
- return -EINVAL;
- }
+ return 0;
+}
- g_config_params.num_cpu = send_cpu_cnt;
- g_config_params.num_queue = (uint16_t)send_cpu_cnt * 2;
- g_config_params.tot_queue_num = g_config_params.num_queue;
+static int32_t parse_stack_cpu_number(void)
+{
+ if (g_config_params.stack_num > 0) {
+ return stack_bind_no_cpu();
}
- return 0;
+ return stack_bind_cpus();
+}
+
+static int32_t parse_stack_num(void)
+{
+ int32_t ret;
+ PARSE_ARG(g_config_params.stack_num, "stack_num", 0, 0, 320, ret);
+ return ret;
}
static int32_t parse_app_bind_numa(void)
@@ -525,12 +474,12 @@ static int32_t parse_app_exclude_cpus(void)
return 0;
}
-static int32_t numa_to_cpusnum(unsigned socket_id, uint32_t *cpulist, int32_t num)
+static int32_t numa_to_cpusnum(unsigned numa_id, uint32_t *cpulist, int32_t num)
{
char path[PATH_MAX] = {0};
char strbuf[PATH_MAX] = {0};
- int32_t ret = snprintf_s(path, sizeof(path), PATH_MAX - 1, NUMA_CPULIST_PATH, socket_id);
+ int32_t ret = snprintf_s(path, sizeof(path), PATH_MAX - 1, NUMA_CPULIST_PATH, numa_id);
if (ret < 0) {
LSTACK_LOG(ERR, LSTACK, "snprintf numa_cpulist failed\n");
return -1;
@@ -557,7 +506,7 @@ static int32_t stack_idle_cpuset(struct protocol_stack *stack, cpu_set_t *exclud
{
uint32_t cpulist[CPUS_MAX_NUM];
- int32_t cpunum = numa_to_cpusnum(stack->socket_id, cpulist, CPUS_MAX_NUM);
+ int32_t cpunum = numa_to_cpusnum(stack->numa_id, cpulist, CPUS_MAX_NUM);
if (cpunum <= 0) {
LSTACK_LOG(ERR, LSTACK, "numa_to_cpusnum failed\n");
return -1;
@@ -584,12 +533,7 @@ int32_t init_stack_numa_cpuset(struct protocol_stack *stack)
cpu_set_t stack_cpuset;
CPU_ZERO(&stack_cpuset);
for (int32_t idx = 0; idx < cfg->num_cpu; ++idx) {
- if (!cfg->seperate_send_recv) {
- CPU_SET(cfg->cpus[idx], &stack_cpuset);
- } else {
- CPU_SET(cfg->send_cpus[idx], &stack_cpuset);
- CPU_SET(cfg->recv_cpus[idx], &stack_cpuset);
- }
+ CPU_SET(cfg->cpus[idx], &stack_cpuset);
}
for (int32_t idx = 0; idx < cfg->app_exclude_num_cpu; ++idx) {
@@ -831,6 +775,94 @@ int32_t gazelle_param_init(int32_t *argc, char **argv)
return 0;
}
+static bool dpdk_have_corelist(int32_t argc, char **argv)
+{
+ for (uint32_t i = 0; i < argc; i++) {
+ if (strncmp(argv[i], OPT_BIND_CORELIST, strlen(OPT_BIND_CORELIST)) == 0) {
+ return true;
+ }
+
+ if (strncmp(argv[i], "--lcores", strlen("--lcores")) == 0) {
+ return true;
+ }
+
+ if (strncmp(argv[i], "-c", strlen("-c")) == 0) {
+ return true;
+ }
+
+ if (strncmp(argv[i], "-s", strlen("-s")) == 0) {
+ return true;
+ }
+
+ if (strncmp(argv[i], "-S", strlen("-S")) == 0) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool dpdk_have_socket_mem(int32_t argc, char **argv)
+{
+ for (uint32_t i = 0; i < argc; i++) {
+ if (strncmp(argv[i], OPT_SOCKET_MEM, strlen(OPT_SOCKET_MEM)) == 0) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static void dpdk_fill_socket_mem(void)
+{
+ uint32_t socket_mem_size = dpdk_total_socket_memory();
+
+ for (uint32_t i = 0; i < GAZELLE_MAX_NUMA_NODES; i++) {
+ if (i == g_config_params.numa_id) {
+ snprintf(g_config_params.socket_mem + strlen(g_config_params.socket_mem),
+ SOCKET_MEM_STRLEN - strlen(g_config_params.socket_mem), "%d", socket_mem_size);
+ } else {
+ snprintf(g_config_params.socket_mem + strlen(g_config_params.socket_mem),
+ SOCKET_MEM_STRLEN - strlen(g_config_params.socket_mem), "%d", 0);
+ }
+ if (i < (GAZELLE_MAX_NUMA_NODES - 1)) {
+ snprintf(g_config_params.socket_mem + strlen(g_config_params.socket_mem),
+ SOCKET_MEM_STRLEN - strlen(g_config_params.socket_mem), "%s", ",");
+ }
+ }
+}
+
+static void dpdk_add_args(void)
+{
+ int idx;
+ uint16_t lcore_id;
+
+ if (!dpdk_have_corelist(g_config_params.dpdk_argc, g_config_params.dpdk_argv)) {
+ if (g_config_params.stack_num > 0) {
+ RTE_LCORE_FOREACH(lcore_id) {
+ if (numa_node_of_cpu(lcore_id) == g_config_params.numa_id && rte_lcore_is_enabled(lcore_id)) {
+ snprintf_s(g_config_params.lcores, sizeof(g_config_params.lcores),
+ sizeof(g_config_params.lcores) - 1, "%d", lcore_id);
+ break;
+ }
+ }
+ }
+ g_config_params.dpdk_argv[g_config_params.dpdk_argc++] = strdup_assert_return(OPT_BIND_CORELIST);
+ g_config_params.dpdk_argv[g_config_params.dpdk_argc++] = strdup_assert_return(g_config_params.lcores);
+ }
+
+ if (g_config_params.stack_num > 0) {
+ dpdk_fill_socket_mem();
+ if (!dpdk_have_socket_mem(g_config_params.dpdk_argc, g_config_params.dpdk_argv)) {
+ g_config_params.dpdk_argv[g_config_params.dpdk_argc++] = strdup_assert_return(OPT_SOCKET_MEM);
+ g_config_params.dpdk_argv[g_config_params.dpdk_argc++] = strdup_assert_return(g_config_params.socket_mem);
+ } else {
+ idx = get_param_idx(g_config_params.dpdk_argc, g_config_params.dpdk_argv, OPT_SOCKET_MEM);
+ strcpy(g_config_params.dpdk_argv[idx + 1], g_config_params.socket_mem);
+ }
+ }
+}
+
static int32_t parse_dpdk_args(void)
{
int32_t i;
@@ -880,8 +912,10 @@ static int32_t parse_dpdk_args(void)
(void)fprintf(stderr, "%s ", g_config_params.dpdk_argv[start_index + i]);
}
(void)fprintf(stderr, "\n");
-
g_config_params.dpdk_argc++;
+
+ dpdk_add_args();
+
if (turn_args_to_config(g_config_params.dpdk_argc, g_config_params.dpdk_argv))
goto free_dpdk_args;
@@ -1106,13 +1140,6 @@ static int32_t parse_unix_prefix(void)
return 0;
}
-static int32_t parse_seperate_sendrecv_args(void)
-{
- int32_t ret;
- PARSE_ARG(g_config_params.seperate_send_recv, "seperate_send_recv", 0, 0, 1, ret);
- return ret;
-}
-
static int32_t parse_num_process(void)
{
if (g_config_params.use_ltran) {
diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c
index 9294c5b..5141c3a 100644
--- a/src/lstack/core/lstack_dpdk.c
+++ b/src/lstack/core/lstack_dpdk.c
@@ -42,6 +42,8 @@
#include "lstack_log.h"
#include "common/dpdk_common.h"
+#include "common/gazelle_base_func.h"
+#include "lstack_thread_rpc.h"
#include "lstack_protocol_stack.h"
#include "lstack_lwip.h"
#include "lstack_cfg.h"
@@ -107,6 +109,10 @@ int32_t thread_affinity_init(int32_t cpu_id)
int32_t ret;
cpu_set_t cpuset;
+ if (get_global_cfg_params()->stack_num > 0) {
+ return 0;
+ }
+
CPU_ZERO(&cpuset);
CPU_SET(cpu_id, &cpuset);
@@ -546,9 +552,6 @@ int32_t dpdk_ethdev_init(int port_id)
int ret;
int32_t rss_enable = 0;
uint16_t nb_queues = get_global_cfg_params()->num_cpu;
- if (get_global_cfg_params()->seperate_send_recv) {
- nb_queues = get_global_cfg_params()->num_cpu * 2;
- }
if (!use_ltran()) {
nb_queues = get_global_cfg_params()->tot_queue_num;
@@ -616,24 +619,23 @@ int32_t dpdk_ethdev_init(int port_id)
static int32_t dpdk_ethdev_setup(const struct eth_params *eth_params, uint16_t idx)
{
int32_t ret;
-
+ uint16_t numa_id = 0;
+ struct cfg_params *cfg = get_global_cfg_params();
struct rte_mempool *rxtx_mbuf_pool = get_protocol_stack_group()->total_rxtx_pktmbuf_pool[idx];
- uint16_t socket_id = 0;
- struct cfg_params *cfg = get_global_cfg_params();
if (!cfg->use_ltran && cfg->num_process == 1) {
- socket_id = numa_node_of_cpu(cfg->cpus[idx]);
+ numa_id = (cfg->stack_num > 0) ? cfg->numa_id : numa_node_of_cpu(cfg->cpus[idx]);
} else {
- socket_id = cfg->process_numa[idx];
+ numa_id = cfg->process_numa[idx];
}
- ret = rte_eth_rx_queue_setup(eth_params->port_id, idx, eth_params->nb_rx_desc, socket_id,
+ ret = rte_eth_rx_queue_setup(eth_params->port_id, idx, eth_params->nb_rx_desc, numa_id,
&eth_params->rx_conf, rxtx_mbuf_pool);
if (ret < 0) {
LSTACK_LOG(ERR, LSTACK, "cannot setup rx_queue %hu: %s\n", idx, rte_strerror(-ret));
return -1;
}
- ret = rte_eth_tx_queue_setup(eth_params->port_id, idx, eth_params->nb_tx_desc, socket_id,
+ ret = rte_eth_tx_queue_setup(eth_params->port_id, idx, eth_params->nb_tx_desc, numa_id,
&eth_params->tx_conf);
if (ret < 0) {
LSTACK_LOG(ERR, LSTACK, "cannot setup tx_queue %hu: %s\n", idx, rte_strerror(-ret));
@@ -1034,3 +1036,45 @@ void dpdk_nic_features_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id)
dfx->data.nic_features.rx_offload = dev_conf.rxmode.offloads;
return;
}
+
+uint32_t dpdk_pktmbuf_mempool_num(void)
+{
+ struct cfg_params *cfg = get_global_cfg_params();
+
+ return (MBUFPOOL_RESERVE_NUM + cfg->rxqueue_size + cfg->txqueue_size +
+ (cfg->tcp_conn_count * cfg->mbuf_count_per_conn) / cfg->num_queue);
+}
+
+uint32_t dpdk_total_socket_memory(void)
+{
+ uint32_t elt_size = 0;
+ uint32_t per_pktmbuf_mempool_size = 0;
+ uint32_t per_rpc_mempool_size = 0;
+ uint32_t per_conn_ring_size = 0;
+ /* the actual fixed memory is about 50M, and 100M is reserved here.
+ * including all hugepages memory used by lwip.
+ */
+ uint32_t fixed_mem = 100;
+ uint32_t total_socket_memory = 0;
+ struct cfg_params *cfg = get_global_cfg_params();
+
+ /* calculate the memory(bytes) of rxtx_mempool */
+ elt_size = sizeof(struct rte_mbuf) + MBUF_SZ + RTE_ALIGN(sizeof(struct mbuf_private), RTE_CACHE_LINE_SIZE);
+ per_pktmbuf_mempool_size = rte_mempool_calc_obj_size(elt_size, 0, NULL);
+
+ /* calculate the memory(bytes) of rpc_mempool, reserved num is (app threads + lstack threads + listen thread) */
+ elt_size = sizeof(struct rpc_msg);
+ per_rpc_mempool_size = rte_mempool_calc_obj_size(elt_size, 0, NULL);
+
+ /* calculate the memory(bytes) of rings, reserved num is GAZELLE_LSTACK_MAX_CONN. */
+ per_conn_ring_size = rte_ring_get_memsize(cfg->send_ring_size) +
+ rte_ring_get_memsize(cfg->recv_ring_size) +
+ rte_ring_get_memsize(DEFAULT_ACCEPTMBOX_SIZE);
+
+ total_socket_memory = fixed_mem + bytes_to_mb(
+ (per_pktmbuf_mempool_size * dpdk_pktmbuf_mempool_num()) * cfg->num_queue +
+ per_rpc_mempool_size * cfg->rpc_msg_max * (RPC_MEMPOOL_THREAD_NUM + cfg->num_queue + 1) +
+ per_conn_ring_size * GAZELLE_LSTACK_MAX_CONN);
+
+ return total_socket_memory;
+}
diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c
index 553dff3..9cfd54f 100644
--- a/src/lstack/core/lstack_protocol_stack.c
+++ b/src/lstack/core/lstack_protocol_stack.c
@@ -126,16 +126,9 @@ struct protocol_stack *get_bind_protocol_stack(void)
pthread_spin_lock(&stack_group->socket_lock);
for (uint16_t i = 0; i < stack_group->stack_num; i++) {
struct protocol_stack* stack = stack_group->stacks[i];
- if (get_global_cfg_params()->seperate_send_recv) {
- if (stack->is_send_thread && stack->conn_num < min_conn_num) {
- index = i;
- min_conn_num = stack->conn_num;
- }
- } else {
- if (stack->conn_num < min_conn_num) {
- index = i;
- min_conn_num = stack->conn_num;
- }
+ if (stack->conn_num < min_conn_num) {
+ index = i;
+ min_conn_num = stack->conn_num;
}
}
}
@@ -154,16 +147,9 @@ int get_min_conn_stack(struct protocol_stack_group *stack_group)
for (int i = 0; i < stack_group->stack_num; i++) {
stack = stack_group->stacks[i];
- if (get_global_cfg_params()->seperate_send_recv) {
- if (!stack->is_send_thread && stack->conn_num < min_conn_num) {
- min_conn_stk_idx = i;
- min_conn_num = stack->conn_num;
- }
- } else {
- if (stack->conn_num < min_conn_num) {
- min_conn_stk_idx = i;
- min_conn_num = stack->conn_num;
- }
+ if (stack->conn_num < min_conn_num) {
+ min_conn_stk_idx = i;
+ min_conn_num = stack->conn_num;
}
}
return min_conn_stk_idx;
@@ -174,6 +160,10 @@ void bind_to_stack_numa(struct protocol_stack *stack)
int32_t ret;
pthread_t tid = pthread_self();
+ if (get_global_cfg_params()->stack_num > 0) {
+ return;
+ }
+
ret = pthread_setaffinity_np(tid, sizeof(stack->idle_cpuset), &stack->idle_cpuset);
if (ret != 0) {
LSTACK_LOG(ERR, LSTACK, "thread %d setaffinity to stack %hu failed\n", rte_gettid(), stack->queue_id);
@@ -268,18 +258,10 @@ static int32_t create_thread(void *arg, char *thread_name, stack_thread_func fun
return -1;
}
- if (get_global_cfg_params()->seperate_send_recv) {
- ret = sprintf_s(name, sizeof(name), "%s", thread_name);
- if (ret < 0) {
- LSTACK_LOG(ERR, LSTACK, "set name failed\n");
- return -1;
- }
- } else {
- ret = sprintf_s(name, sizeof(name), "%s%02hu", thread_name, t_params->queue_id);
- if (ret < 0) {
- LSTACK_LOG(ERR, LSTACK, "set name failed\n");
- return -1;
- }
+ ret = sprintf_s(name, sizeof(name), "%s%02hu", thread_name, t_params->queue_id);
+ if (ret < 0) {
+ LSTACK_LOG(ERR, LSTACK, "set name failed\n");
+ return -1;
}
ret = pthread_create(&tid, NULL, func, arg);
@@ -343,6 +325,7 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg)
{
struct thread_params *t_params = (struct thread_params*) arg;
struct protocol_stack_group *stack_group = get_protocol_stack_group();
+ struct cfg_params *cfg_params = get_global_cfg_params();
stack->tid = rte_gettid();
stack->queue_id = t_params->queue_id;
@@ -363,24 +346,15 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg)
return -1;
}
- int idx = t_params->idx;
- if (get_global_cfg_params()->seperate_send_recv) {
- // 2: idx is even, stack is recv thread, idx is odd, stack is send thread
- if (idx % 2 == 0) {
- stack->cpu_id = get_global_cfg_params()->recv_cpus[idx / 2];
- stack->is_send_thread = 0;
- } else {
- stack->cpu_id = get_global_cfg_params()->send_cpus[idx / 2];
- stack->is_send_thread = 1;
- }
+ if (cfg_params->stack_num > 0) {
+ stack->numa_id = cfg_params->numa_id;
} else {
- stack->cpu_id = get_global_cfg_params()->cpus[idx];
- }
-
- stack->socket_id = numa_node_of_cpu(stack->cpu_id);
- if (stack->socket_id < 0) {
- LSTACK_LOG(ERR, LSTACK, "numa_node_of_cpu failed\n");
- return -1;
+ stack->cpu_id = cfg_params->cpus[t_params->idx];
+ stack->numa_id = numa_node_of_cpu(stack->cpu_id);
+ if (stack->numa_id < 0) {
+ LSTACK_LOG(ERR, LSTACK, "numa_node_of_cpu failed\n");
+ return -1;
+ }
}
if (pktmbuf_pool_init(stack) != 0) {
@@ -441,7 +415,10 @@ static struct protocol_stack *stack_thread_init(void *arg)
if (thread_affinity_init(stack->cpu_id) != 0) {
goto END;
}
- RTE_PER_LCORE(_lcore_id) = stack->cpu_id;
+
+ if (get_global_cfg_params()->stack_num == 0) {
+ RTE_PER_LCORE(_lcore_id) = stack->cpu_id;
+ }
lwip_init();
/* Using errno to return lwip_init() result. */
@@ -591,9 +568,7 @@ static void* gazelle_stack_thread(void *arg)
static int stack_group_init_mempool(void)
{
struct cfg_params *cfg_params = get_global_cfg_params();
- uint32_t total_mbufs = 0;
- uint32_t total_conn_mbufs = cfg_params->mbuf_count_per_conn * cfg_params->tcp_conn_count;
- uint32_t total_nic_mbufs = cfg_params->rxqueue_size + cfg_params->txqueue_size;
+ uint32_t total_mbufs = dpdk_pktmbuf_mempool_num();
struct rte_mempool *rxtx_mbuf = NULL;
uint32_t cpu_id = 0;
unsigned numa_id = 0;
@@ -603,8 +578,12 @@ static int stack_group_init_mempool(void)
"config::num_cpu=%d num_process=%d \n", cfg_params->num_cpu, cfg_params->num_process);
for (int cpu_idx = 0; cpu_idx < cfg_params->num_queue; cpu_idx++) {
- cpu_id = cfg_params->cpus[cpu_idx];
- numa_id = numa_node_of_cpu(cpu_id);
+ if (cfg_params->stack_num > 0) {
+ numa_id = cfg_params->numa_id;
+ } else {
+ cpu_id = cfg_params->cpus[cpu_idx];
+ numa_id = numa_node_of_cpu(cpu_id);
+ }
for (int process_idx = 0; process_idx < cfg_params->num_process; process_idx++) {
queue_id = cpu_idx * cfg_params->num_process + process_idx;
@@ -613,11 +592,9 @@ static int stack_group_init_mempool(void)
return -1;
}
- total_mbufs = (total_conn_mbufs / cfg_params->num_queue) + total_nic_mbufs + MBUFPOOL_RESERVE_NUM;
rxtx_mbuf = create_pktmbuf_mempool("rxtx_mbuf", total_mbufs, RXTX_CACHE_SZ, queue_id, numa_id);
if (rxtx_mbuf == NULL) {
- LSTACK_LOG(ERR, LSTACK, "cpuid=%u, numid=%d , rxtx_mbuf idx= %d create_pktmbuf_mempool fail\n",
- cpu_id, numa_id, queue_id);
+ LSTACK_LOG(ERR, LSTACK, "numid=%d, rxtx_mbuf idx=%d, create_pktmbuf_mempool fail\n", numa_id, queue_id);
return -1;
}
@@ -696,23 +673,9 @@ int stack_setup_thread(void)
}
}
for (i = 0; i < queue_num; i++) {
- if (get_global_cfg_params()->seperate_send_recv) {
- if (i % 2 == 0) {
- ret = sprintf_s(name, sizeof(name), "%s_%d_%d", LSTACK_RECV_THREAD_NAME, process_index, i / 2);
- if (ret < 0) {
- goto OUT1;
- }
- } else {
- ret = sprintf_s(name, sizeof(name), "%s_%d_%d", LSTACK_SEND_THREAD_NAME, process_index, i / 2);
- if (ret < 0) {
- goto OUT1;
- }
- }
- } else {
- ret = sprintf_s(name, sizeof(name), "%s", LSTACK_THREAD_NAME);
- if (ret < 0) {
- goto OUT1;
- }
+ ret = sprintf_s(name, sizeof(name), "%s", LSTACK_THREAD_NAME);
+ if (ret < 0) {
+ goto OUT1;
}
t_params[i]->idx = i;
diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h
index 876423d..073aab6 100644
--- a/src/lstack/include/lstack_cfg.h
+++ b/src/lstack/include/lstack_cfg.h
@@ -20,6 +20,7 @@
#include <rte_bus_pci.h>
#include "lstack_protocol_stack.h"
+#include "common/gazelle_reg_msg.h"
#include "common/gazelle_opt.h"
#define BASE_BIN_SCALE 2
@@ -36,7 +37,6 @@
#define ARP_MAX_ENTRIES 1024
#define LOG_DIR_PATH PATH_MAX
#define LOG_LEVEL_LEN 16
-#define GAZELLE_MAX_NUMA_NODES 8
#define MAX_PROCESS_NUM 32
/* Default value of low power mode parameters */
@@ -77,6 +77,8 @@ struct cfg_params {
uintptr_t base_virtaddr;
char file_prefix[PATH_MAX];
} sec_attach_arg;
+ char socket_mem[SOCKET_MEM_STRLEN];
+ char lcores[RTE_MAX_LCORE];
};
struct { // eth
@@ -109,6 +111,8 @@ struct cfg_params {
struct { // stack
uint16_t num_cpu;
+ uint16_t numa_id;
+ uint16_t stack_num;
uint32_t cpus[CFG_MAX_CPUS];
bool main_thread_affinity;
@@ -147,10 +151,6 @@ struct cfg_params {
uint32_t process_numa[PROTOCOL_STACK_MAX];
bool tuple_filter;
bool use_sockmap;
-
- bool seperate_send_recv;
- uint32_t send_cpus[CFG_MAX_CPUS];
- uint32_t recv_cpus[CFG_MAX_CPUS];
};
};
diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h
index 0210843..87219c2 100644
--- a/src/lstack/include/lstack_dpdk.h
+++ b/src/lstack/include/lstack_dpdk.h
@@ -66,5 +66,7 @@ void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id);
void dpdk_nic_features_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id);
bool dpdk_nic_is_xdp(void);
+uint32_t dpdk_pktmbuf_mempool_num(void);
+uint32_t dpdk_total_socket_memory(void);
#endif /* GAZELLE_DPDK_H */
diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h
index 4d10ac2..068e9d2 100644
--- a/src/lstack/include/lstack_protocol_stack.h
+++ b/src/lstack/include/lstack_protocol_stack.h
@@ -40,7 +40,7 @@ struct protocol_stack {
uint32_t tid;
uint16_t queue_id;
uint16_t port_id;
- uint16_t socket_id;
+ uint16_t numa_id;
uint16_t cpu_id;
uint32_t stack_idx;
cpu_set_t idle_cpuset; /* idle cpu in numa of stack, app thread bind to it */
@@ -56,7 +56,6 @@ struct protocol_stack {
uint32_t reg_head;
volatile bool low_power;
- bool is_send_thread;
char pad1 __rte_cache_aligned;
rpc_queue dfx_rpc_queue;
diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h
index c284d29..c74981f 100644
--- a/src/lstack/include/lstack_thread_rpc.h
+++ b/src/lstack/include/lstack_thread_rpc.h
@@ -26,6 +26,8 @@
#define MSG_ARG_4 (4)
#define RPM_MSG_ARG_SIZE (5)
+#define RPC_MEMPOOL_THREAD_NUM 64
+
typedef struct rpc_queue rpc_queue;
struct rpc_queue {
struct lockless_queue queue;
diff --git a/src/lstack/netif/lstack_flow.c b/src/lstack/netif/lstack_flow.c
index 1ca3314..ec09e45 100644
--- a/src/lstack/netif/lstack_flow.c
+++ b/src/lstack/netif/lstack_flow.c
@@ -639,11 +639,7 @@ int distribute_pakages(struct rte_mbuf *mbuf)
return TRANSFER_KERNEL;
}
- if (get_global_cfg_params()->seperate_send_recv) {
- queue_id = user_process_idx * each_process_queue_num + (index / 2) * 2;
- } else {
- queue_id = user_process_idx * each_process_queue_num + index;
- }
+ queue_id = user_process_idx * each_process_queue_num + index;
if (queue_id != 0) {
if (user_process_idx == 0) {
transfer_tcp_to_thread(mbuf, queue_id);
--
2.33.0

View File

@ -0,0 +1,391 @@
From fa5060a255109d089f98c9c498d7119e96bd39fd Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Mon, 11 Nov 2024 22:45:54 +0800
Subject: [PATCH] support auto set xdp addr
---
src/common/gazelle_reg_msg.h | 2 +
src/lstack/core/lstack_cfg.c | 207 ++++++++++++++++++++++++-------
src/lstack/core/lstack_preload.c | 2 +-
src/lstack/include/lstack_cfg.h | 5 +
4 files changed, 171 insertions(+), 45 deletions(-)
diff --git a/src/common/gazelle_reg_msg.h b/src/common/gazelle_reg_msg.h
index f9de32c..2ba47cc 100644
--- a/src/common/gazelle_reg_msg.h
+++ b/src/common/gazelle_reg_msg.h
@@ -30,6 +30,8 @@
#define OPT_LEGACY_MEM "--legacy-mem"
#define OPT_HUGE_DIR "--huge-dir"
#define OPT_BIND_CORELIST "-l"
+#define OPT_VDEV "--vdev"
+#define VDEV_ARG_IFACE "iface"
#define GAZELLE_MAX_NUMA_NODES 4
#define SOCKET_MEM_STRLEN (GAZELLE_MAX_NUMA_NODES * 10)
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index 43482af..2a3f1af 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -14,7 +14,6 @@
#include <getopt.h>
#include <stdio.h>
#include <fcntl.h>
-#include <sys/socket.h>
#include <inttypes.h>
#include <securec.h>
#include <string.h>
@@ -23,12 +22,15 @@
#include <unistd.h>
#include <sched.h>
#include <numa.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <ifaddrs.h>
+#include <netpacket/packet.h>
#include <rte_eth_bond.h>
#include <rte_eal.h>
#include <rte_lcore.h>
#include <lwip/lwipgz_sock.h>
-#include <lwip/inet.h>
#include "common/gazelle_reg_msg.h"
#include "common/gazelle_base_func.h"
@@ -36,14 +38,14 @@
#include "lstack_dpdk.h"
#include "lstack_cfg.h"
-#define DEFAULT_CONF_FILE "/etc/gazelle/lstack.conf"
-#define LSTACK_CONF_ENV "LSTACK_CONF_PATH"
-#define NUMA_CPULIST_PATH "/sys/devices/system/node/node%u/cpulist"
-#define DEV_MAC_LEN 17
-#define DEV_PCI_ADDR_LEN 12
-#define CPUS_MAX_NUM 256
-#define BOND_MIIMON_MIN 1
-#define BOND_MIIMON_MAX INT_MAX
+#define DEFAULT_CONF_FILE "/etc/gazelle/lstack.conf"
+#define LSTACK_CONF_ENV "LSTACK_CONF_PATH"
+#define NUMA_CPULIST_PATH "/sys/devices/system/node/node%u/cpulist"
+#define DEV_MAC_LEN 17
+#define DEV_PCI_ADDR_LEN 12
+#define CPUS_MAX_NUM 256
+#define BOND_MIIMON_MIN 1
+#define BOND_MIIMON_MAX INT_MAX
static struct cfg_params g_config_params;
@@ -89,6 +91,7 @@ static int32_t parse_send_cache_mode(void);
static int32_t parse_flow_bifurcation(void);
static int32_t parse_stack_interrupt(void);
static int32_t parse_stack_num(void);
+static int32_t parse_xdp_eth_name(void);
#define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \
do { \
@@ -116,12 +119,7 @@ struct config_vector_t {
};
static struct config_vector_t g_config_tbl[] = {
- { "host_addr", parse_host_addr },
- { "host_addr6", parse_host_addr6 },
- { "gateway_addr", parse_gateway_addr },
- { "mask_addr", parse_mask_addr },
{ "use_ltran", parse_use_ltran },
- { "devices", parse_devices },
{ "tcp_conn_count", parse_tcp_conn_count },
{ "mbuf_count_per_conn", parse_mbuf_count_per_conn },
{ "nic_rxqueue_size", parse_nic_rxqueue_size},
@@ -132,6 +130,12 @@ static struct config_vector_t g_config_tbl[] = {
{ "stack_num", parse_stack_num },
{ "num_cpus", parse_stack_cpu_number },
{ "dpdk_args", parse_dpdk_args },
+ { "xdp_eth_name", parse_xdp_eth_name},
+ { "host_addr", parse_host_addr },
+ { "host_addr6", parse_host_addr6 },
+ { "mask_addr", parse_mask_addr },
+ { "gateway_addr", parse_gateway_addr },
+ { "devices", parse_devices },
{ "low_power_mode", parse_low_power_mode },
{ "kni_switch", parse_kni_switch },
{ "listen_shadow", parse_listen_shadow },
@@ -211,18 +215,25 @@ static int32_t str_to_dev_addr(const char *src, struct dev_addr *dst)
static int32_t parse_gateway_addr(void)
{
- char *value;
bool ok;
+ char *value;
+ const char *first_addr = "0.0.0.1";
if (ip4_addr_isany_val(g_config_params.host_addr)) {
return 0;
}
- ok = config_lookup_string(&g_config, "gateway_addr", (const char **)&value);
- if (!ok) {
- return -EINVAL;
+ if (strlen(g_config_params.xdp_eth_name) == 0) {
+ ok = config_lookup_string(&g_config, "gateway_addr", (const char **)&value);
+ if (!ok) {
+ return -EINVAL;
+ }
+ g_config_params.gateway_addr.addr = inet_addr(value);
+ } else {
+ g_config_params.gateway_addr.addr =
+ (g_config_params.host_addr.addr & g_config_params.netmask.addr) | inet_addr(first_addr);
}
- g_config_params.gateway_addr.addr = inet_addr(value);
+
if (g_config_params.gateway_addr.addr == INADDR_NONE) {
return -EINVAL;
}
@@ -231,19 +242,40 @@ static int32_t parse_gateway_addr(void)
static int32_t parse_mask_addr(void)
{
- char *value = NULL;
+ int32_t ret;
uint32_t mask;
- bool ok;
+ char *mask_addr;
+ struct ifaddrs *ifaddr;
+ struct ifaddrs *ifa;
if (ip4_addr_isany_val(g_config_params.host_addr)) {
return 0;
}
- ok = config_lookup_string(&g_config, "mask_addr", (const char **)&value);
- if (!ok) {
- return -EINVAL;
+ if (strlen(g_config_params.xdp_eth_name) == 0) {
+ ret = config_lookup_string(&g_config, "mask_addr", (const char **)&mask_addr);
+ if (!ret) {
+ return -EINVAL;
+ }
+ g_config_params.netmask.addr = inet_addr(mask_addr);
+ } else {
+ if (getifaddrs(&ifaddr) == -1) {
+ LSTACK_PRE_LOG(LSTACK_ERR, "getifaddrs failed\n");
+ return -1;
+ }
+
+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET ||
+ strncmp(ifa->ifa_name, g_config_params.xdp_eth_name, strlen(g_config_params.xdp_eth_name))) {
+ continue;
+ }
+ g_config_params.netmask.addr = ((struct sockaddr_in *)ifa->ifa_netmask)->sin_addr.s_addr;
+ }
+
+ freeifaddrs(ifaddr);
+ freeifaddrs(ifa);
}
- g_config_params.netmask.addr = inet_addr(value);
+
if (g_config_params.netmask.addr == INADDR_NONE) {
return -EINVAL;
}
@@ -257,21 +289,41 @@ static int32_t parse_mask_addr(void)
static int32_t parse_host_addr(void)
{
- char *value = NULL;
- bool ok;
+ int32_t ret;
+ char *host_addr;
+ struct ifaddrs *ifaddr;
+ struct ifaddrs *ifa;
- ok = config_lookup_string(&g_config, "host_addr", (const char **)&value);
- if (!ok) {
- return 0;
+ if (strlen(g_config_params.xdp_eth_name) == 0) {
+ ret = config_lookup_string(&g_config, "host_addr", (const char **)&host_addr);
+ if (!ret) {
+ return 0;
+ }
+ g_config_params.host_addr.addr = inet_addr(host_addr);
+ } else {
+ if (getifaddrs(&ifaddr) == -1) {
+ LSTACK_PRE_LOG(LSTACK_ERR, "getifaddrs failed\n");
+ return -1;
+ }
+
+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET ||
+ strncmp(ifa->ifa_name, g_config_params.xdp_eth_name, strlen(g_config_params.xdp_eth_name))) {
+ continue;
+ }
+ g_config_params.host_addr.addr = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
+ }
+
+ freeifaddrs(ifaddr);
+ freeifaddrs(ifa);
}
- g_config_params.host_addr.addr = inet_addr(value);
if (g_config_params.host_addr.addr == INADDR_NONE) {
return -EINVAL;
}
if (IN_MULTICAST(ntohl(g_config_params.host_addr.addr))) {
- LSTACK_PRE_LOG(LSTACK_ERR, "cfg: host_addr:%s should not be a multicast IP.", value);
+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: host_addr:%s should not be a multicast IP.", host_addr);
return -EINVAL;
}
return 0;
@@ -284,7 +336,7 @@ static int32_t parse_host_addr6(void)
ok = config_lookup_string(&g_config, "host_addr6", (const char **)&value);
if (!ok) {
- if (ip4_addr_isany_val(g_config_params.host_addr)) {
+ if (ip4_addr_isany_val(g_config_params.host_addr) && (strlen(g_config_params.xdp_eth_name) == 0)) {
LSTACK_PRE_LOG(LSTACK_ERR, "cfg: host_addr and host_addr6 must have a valid one.");
return -EINVAL;
} else {
@@ -322,16 +374,37 @@ int32_t match_host_addr(ip_addr_t *addr)
static int32_t parse_devices(void)
{
int32_t ret;
- const char *dev = NULL;
- const config_setting_t *devs = NULL;
+ char *dev = NULL;
+ struct ifaddrs *ifa;
+ struct ifaddrs *ifaddr;
+ char temp_dev[DEV_MAC_LEN + 1] = {0};
+
+ if (strlen(g_config_params.xdp_eth_name) == 0) {
+ ret = config_lookup_string(&g_config, "devices", (const char **)&dev);
+ if (!ret) {
+ return -EINVAL;
+ }
+ } else {
+ if (getifaddrs(&ifaddr) == -1) {
+ LSTACK_PRE_LOG(LSTACK_ERR, "getifaddrs failed\n");
+ return -1;
+ }
- devs = config_lookup(&g_config, "devices");
- if (devs == NULL) {
- return -EINVAL;
- }
- dev = config_setting_get_string(devs);
- if (dev == NULL) {
- return 0;
+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_PACKET ||
+ strncmp(ifa->ifa_name, g_config_params.xdp_eth_name, strlen(g_config_params.xdp_eth_name))) {
+ continue;
+ }
+
+ for (uint32_t i = 0; i < ETHER_ADDR_LEN; i++) {
+ sprintf(temp_dev + strlen(temp_dev), "%02x%s",
+ ((struct sockaddr_ll *)ifa->ifa_addr)->sll_addr[i], i < (ETHER_ADDR_LEN - 1) ? ":" : "");
+ }
+ dev = strdup_assert_return(temp_dev);
+ }
+
+ freeifaddrs(ifaddr);
+ freeifaddrs(ifa);
}
/* add dev */
@@ -1294,7 +1367,7 @@ static int32_t parse_bond_slave_mac(void)
char *bond_slave_mac_tmp = strdup_assert_return(bond_slave_mac);
char *tmp = NULL;
const char *delim = ";";
-
+
char *mac_addr = strtok_s(bond_slave_mac_tmp, delim, &tmp);
while (mac_addr != NULL) {
if (k >= GAZELLE_MAX_BOND_NUM) {
@@ -1426,3 +1499,49 @@ static int32_t parse_stack_interrupt(void)
return ret;
}
+
+static void dpdk_dev_get_iface_name(char *vdev_str)
+{
+ char *token = NULL;
+ char *iface_value = NULL;
+ char *next_token = NULL;
+ char vdev_str_cp[strlen(vdev_str) + 1];
+
+ /* To prevent the original string from being modified, use a copied string. */
+ if (strcpy_s(vdev_str_cp, sizeof(vdev_str_cp), vdev_str) != 0) {
+ LSTACK_PRE_LOG(LSTACK_ERR, "vdev_str strcpy_s fail \n");
+ return;
+ }
+
+ token = strtok_s(vdev_str_cp, ",", &next_token);
+ while (token != NULL) {
+ if (strncmp(token, VDEV_ARG_IFACE, strlen(VDEV_ARG_IFACE)) == 0) {
+ iface_value = token + strlen(VDEV_ARG_IFACE) + 1;
+ break;
+ }
+ token = strtok_s(NULL, ",", &next_token);
+ }
+
+ if (iface_value) {
+ strncpy_s(g_config_params.xdp_eth_name, IFNAMSIZ, iface_value, IFNAMSIZ - 1);
+ }
+}
+
+static int32_t parse_xdp_eth_name(void)
+{
+ int32_t ret;
+
+ ret = memset_s(g_config_params.xdp_eth_name, IFNAMSIZ, 0, IFNAMSIZ);
+ if (ret != 0) {
+ LSTACK_PRE_LOG(LSTACK_ERR, "memset_s failed \n");
+ return ret;
+ }
+
+ for (uint32_t i = 0; i < g_config_params.dpdk_argc; i++) {
+ if (!strncmp(g_config_params.dpdk_argv[i], OPT_VDEV, strlen(OPT_VDEV))) {
+ dpdk_dev_get_iface_name(g_config_params.dpdk_argv[i + 1]);
+ }
+ }
+
+ return 0;
+}
diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c
index 0a1df7d..bdb61e9 100644
--- a/src/lstack/core/lstack_preload.c
+++ b/src/lstack/core/lstack_preload.c
@@ -193,6 +193,6 @@ int preload_info_init(void)
}
g_preload_info.preload_switch = 1;
- LSTACK_PRE_LOG(LSTACK_INFO, "LD_PRELOAD ok\n");
+
return preload_check_bind_proc();
}
diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h
index 073aab6..0fd5323 100644
--- a/src/lstack/include/lstack_cfg.h
+++ b/src/lstack/include/lstack_cfg.h
@@ -14,6 +14,10 @@
#define _GAZELLE_NET_CFG_H_
#include <stdbool.h>
+#ifndef IFNAMSIZ
+#include <net/if.h>
+#endif
+
#include <lwip/ip_addr.h>
#include <rte_ether.h>
#include <rte_pci.h>
@@ -86,6 +90,7 @@ struct cfg_params {
ip6_addr_t host_addr6;
ip4_addr_t netmask;
ip4_addr_t gateway_addr;
+ char xdp_eth_name[IFNAMSIZ];
uint8_t mac_addr[ETHER_ADDR_LEN];
int8_t bond_mode;
int32_t bond_miimon;
--
2.33.0

View File

@ -0,0 +1,82 @@
From be28f36adfebb0e5f7f2340638120a19f5b2eaa6 Mon Sep 17 00:00:00 2001
From: hankangkang <hankangkang5@huawei.com>
Date: Thu, 14 Nov 2024 20:16:14 +0800
Subject: [PATCH] suport kernel accept for openGauss
---
src/lstack/api/lstack_wrap.c | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index 66cea51..6ab31f6 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -14,6 +14,7 @@
#include <ifaddrs.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
+#include <fcntl.h>
#include <linux/if_xdp.h>
#include <lwip/lwipgz_posix_api.h>
@@ -102,14 +103,22 @@ static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *add
return posix_api->accept_fn(s, addr, addrlen);
}
- int32_t fd = g_wrap_api->accept_fn(s, addr, addrlen);
+ int fd = 0;
+ struct lwip_sock *sock = lwip_get_socket(s);
+ if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) {
+ fd = posix_api->accept4_fn(s, addr, addrlen, SOCK_NONBLOCK);
+ if (fd >= 0) {
+ return fd;
+ }
+ }
+
+ fd = g_wrap_api->accept_fn(s, addr, addrlen);
if (fd >= 0) {
- struct lwip_sock *sock = lwip_get_socket(fd);
+ sock = lwip_get_socket(fd);
POSIX_SET_TYPE(sock, POSIX_LWIP);
- return fd;
}
- return posix_api->accept_fn(s, addr, addrlen);
+ return fd;
}
static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, int32_t flags)
@@ -132,6 +141,22 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen,
return posix_api->accept4_fn(s, addr, addrlen, flags);
}
+static inline int sock_set_nonblocking(int fd)
+{
+ int flags = posix_api->fcntl_fn(fd, F_GETFL, 0);
+ if (flags == -1) {
+ LSTACK_LOG(ERR, LSTACK, " get block status faild errno %d.\n", errno);
+ return -1;
+ }
+ // set nonblock
+ flags |= O_NONBLOCK;
+ if (posix_api->fcntl_fn(fd, F_SETFL, flags) == -1) {
+ LSTACK_LOG(ERR, LSTACK, " set non_block status faild errno %d.\n", errno);
+ return -1;
+ }
+ return 0;
+}
+
static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t namelen)
{
struct lwip_sock *sock = lwip_get_socket(s);
@@ -165,6 +190,7 @@ static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t
((struct sockaddr_in *)name)->sin_port = kerneladdr.sin_port;
}
/* not sure POSIX_LWIP or POSIX_KERNEL */
+ sock_set_nonblocking(s);
} else {
POSIX_SET_TYPE(sock, POSIX_LWIP);
LSTACK_LOG(ERR, LSTACK, "kernel bind failed ret %d errno %d sa_family %u times %u\n",
--
2.33.0

View File

@ -0,0 +1,43 @@
From e09613994ea3fee2c5468c48d24d8a6dfb96f8b4 Mon Sep 17 00:00:00 2001
From: hankangkang <hankangkang5@huawei.com>
Date: Mon, 18 Nov 2024 09:18:42 +0800
Subject: [PATCH] openGauss: support kernel accept4
---
src/lstack/api/lstack_wrap.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index 7d32ef1..7e724cd 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -131,14 +131,22 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen,
return posix_api->accept4_fn(s, addr, addrlen, flags);
}
- int32_t fd = g_wrap_api->accept4_fn(s, addr, addrlen, flags);
+ int fd = 0;
+ struct lwip_sock *sock = lwip_get_socket(s);
+ if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) {
+ fd = posix_api->accept4_fn(s, addr, addrlen, flags);
+ if (fd >= 0) {
+ return fd;
+ }
+ }
+
+ fd = g_wrap_api->accept4_fn(s, addr, addrlen, flags);
if (fd >= 0) {
- struct lwip_sock *sock = lwip_get_socket(fd);
+ sock = lwip_get_socket(fd);
POSIX_SET_TYPE(sock, POSIX_LWIP);
- return fd;
}
- return posix_api->accept4_fn(s, addr, addrlen, flags);
+ return fd;
}
static inline int sock_set_nonblocking(int fd)
--
2.33.0

View File

@ -0,0 +1,125 @@
From a735fd09aa59df805865331b3cbda5e0458c9fac Mon Sep 17 00:00:00 2001
From: yinbin <yinbin8@huawei.com>
Date: Tue, 19 Nov 2024 19:36:26 +0800
Subject: [PATCH] socket: init wakeup in blocking socket
---
src/lstack/api/lstack_epoll.c | 16 ++++++++++++----
src/lstack/api/lstack_rtw_api.c | 9 +++++++++
src/lstack/core/lstack_lwip.c | 15 ++++++++++++++-
src/lstack/include/lstack_epoll.h | 2 ++
4 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c
index acbf393..ff9cccf 100644
--- a/src/lstack/api/lstack_epoll.c
+++ b/src/lstack/api/lstack_epoll.c
@@ -872,21 +872,30 @@ static int poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfds
return 0;
}
-int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout)
+struct wakeup_poll* poll_construct_wakeup(void)
{
static PER_THREAD struct wakeup_poll *wakeup = NULL;
if (wakeup == NULL) {
wakeup = calloc(1, sizeof(struct wakeup_poll));
if (wakeup == NULL) {
LSTACK_LOG(ERR, LSTACK, "calloc failed errno=%d\n", errno);
- GAZELLE_RETURN(EINVAL);
+ return NULL;
}
if (init_poll_wakeup_data(wakeup) < 0) {
free(wakeup);
- GAZELLE_RETURN(EINVAL);
+ return NULL;
}
}
+ return wakeup;
+}
+
+int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout)
+{
+ struct wakeup_poll *wakeup = poll_construct_wakeup();
+ if (wakeup == NULL) {
+ GAZELLE_RETURN(EINVAL);
+ }
if (poll_init(wakeup, fds, nfds) < 0) {
free(wakeup);
@@ -1015,4 +1024,3 @@ int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfd
return event_num;
}
-
diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c
index 1b02e2a..6d0bd05 100644
--- a/src/lstack/api/lstack_rtw_api.c
+++ b/src/lstack/api/lstack_rtw_api.c
@@ -136,6 +136,15 @@ static struct lwip_sock *get_min_accept_sock(int fd)
struct lwip_sock *min_sock = NULL;
while (sock) {
+ if (!netconn_is_nonblocking(sock->conn)) {
+ if (sock->wakeup == NULL) {
+ sock->wakeup = poll_construct_wakeup();
+ if (sock->wakeup == NULL) {
+ return NULL;
+ }
+ sock->epoll_events = POLLIN | POLLERR;
+ }
+ }
if (!NETCONN_IS_ACCEPTIN(sock)) {
sock = sock->listen_next;
continue;
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index bb261d2..65acae2 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -993,6 +993,7 @@ static bool recv_break_for_err(struct lwip_sock *sock)
static int recv_ring_get_one(struct lwip_sock *sock, bool noblock, struct pbuf **pbuf)
{
int32_t expect = 1; // only get one pbuf
+ int ret = 0;
uint64_t time_stamp = sys_now_us();
if (sock->recv_lastdata != NULL) {
@@ -1008,8 +1009,20 @@ static int recv_ring_get_one(struct lwip_sock *sock, bool noblock, struct pbuf *
if (recv_break_for_err(sock)) {
return -1;
}
- if (lstack_block_wait(sock->wakeup, sock->conn->recv_timeout) == ETIMEDOUT) {
+ if (unlikely(sock->wakeup == NULL)) {
+ sock->wakeup = poll_construct_wakeup();
+ if (sock->wakeup == NULL) {
+ return -1;
+ }
+ 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 */
+ return ret;
}
}
diff --git a/src/lstack/include/lstack_epoll.h b/src/lstack/include/lstack_epoll.h
index e7ae26b..cad9aed 100644
--- a/src/lstack/include/lstack_epoll.h
+++ b/src/lstack/include/lstack_epoll.h
@@ -76,6 +76,8 @@ int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfd
int32_t lstack_block_wait(struct wakeup_poll *wakeup, int32_t timeout);
+struct wakeup_poll* poll_construct_wakeup(void);
+
static inline void lstack_block_wakeup(struct wakeup_poll *wakeup)
{
if (wakeup && __atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) {
--
2.33.0

View File

@ -0,0 +1,36 @@
From 0f3a61700b17bed0ed39c7c5433952b72dc82b84 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Wed, 20 Nov 2024 11:26:55 +0800
Subject: [PATCH] fix socket of control thread is overwirtten due to another
primary process start
---
src/lstack/core/lstack_init.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c
index 276cdf8..29796ee 100644
--- a/src/lstack/core/lstack_init.c
+++ b/src/lstack/core/lstack_init.c
@@ -166,14 +166,14 @@ static void create_control_thread(void)
LSTACK_EXIT(1, "pthread_create failed ret=%d errno=%d\n", ret, errno);
}
} else {
- ret = pthread_create(&tid, NULL, (void *(*)(void *))control_server_thread, NULL);
- if (ret != 0) {
- LSTACK_EXIT(1, "pthread_create failed ret=%d errno=%d\n", ret, errno);
- }
ret = dpdk_eal_init();
if (ret < 0) {
LSTACK_EXIT(1, "dpdk_eal_init failed ret=%d errno=%d\n", ret, errno);
}
+ ret = pthread_create(&tid, NULL, (void *(*)(void *))control_server_thread, NULL);
+ if (ret != 0) {
+ LSTACK_EXIT(1, "pthread_create failed ret=%d errno=%d\n", ret, errno);
+ }
}
if (pthread_setname_np(tid, CONTROL_THREAD_NAME) != 0) {
--
2.33.0

View File

@ -0,0 +1,29 @@
From 1d4bdf6a14afe7459d2fa9d2da19a36c45ae91f5 Mon Sep 17 00:00:00 2001
From: yinbin <yinbin8@huawei.com>
Date: Wed, 20 Nov 2024 16:32:28 +0800
Subject: [PATCH] LWIP: adjust position of shutdown in callback of connect
---
src/lstack/core/lstack_lwip.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index 65acae2..648da58 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -1273,10 +1273,10 @@ void do_lwip_connected_callback(struct netconn *conn)
posix_api->epoll_ctl_fn(sock->wakeup->epollfd, EPOLL_CTL_DEL, fd, NULL);
}
- posix_api->shutdown_fn(fd, SHUT_RDWR);
-
POSIX_SET_TYPE(sock, POSIX_LWIP);
+ posix_api->shutdown_fn(fd, SHUT_RDWR);
+
add_sock_event(sock, EPOLLOUT);
}
--
2.33.0

View File

@ -0,0 +1,154 @@
From e5aa9e48521b3096ba9acb888d293eefeaf677da Mon Sep 17 00:00:00 2001
From: Caohongtao <caohongtao_yewu@cmss.chinamobile.com>
Date: Wed, 9 Oct 2024 02:55:56 +0000
Subject: [PATCH] Fix the wrong spelling description in the notes and logs
Signed-off-by: Caohongtao <caohongtao_yewu@cmss.chinamobile.com>
---
src/ltran/ltran_forward.c | 6 +++---
src/ltran/main.c | 4 ++--
tools/gazelle_common.sh | 8 ++++----
tools/gazelle_setup.sh | 4 ++--
tools/sync-gazelle-src.sh | 4 ++--
5 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c
index 0de9c1c..aef5e46 100644
--- a/src/ltran/ltran_forward.c
+++ b/src/ltran/ltran_forward.c
@@ -58,7 +58,7 @@ static void calculate_ltran_latency(struct gazelle_stack *stack, const struct rt
uint64_t latency;
lt = &mbuf_to_private(mbuf)->lt;
- // vaild check
+ // valid check
if (lt->stamp != ~(lt->check)) {
return;
}
@@ -221,7 +221,7 @@ static __rte_always_inline void flush_rx_ring(struct gazelle_stack *stack)
}
uint32_t flush_cnt = pkt_bufs_enque_rx_ring(stack);
- /* cant't flush mbuf into backup */
+ /* can't flush mbuf into backup */
if (unlikely(flush_cnt < stack->pkt_cnt)) {
pktbufs_move_to_backup_bufs(stack, &(stack->pkt_buf[flush_cnt]), stack->pkt_cnt - flush_cnt);
}
@@ -475,7 +475,7 @@ static __rte_always_inline void tcp_hash_table_add_conn(struct gazelle_stack *st
tcp_conn->conn_timeout = -1;
return;
} else {
- /* del old invaild conn */
+ /* del old invalid conn */
gazelle_conn_del_by_quintuple(conn_htable, transfer_qtuple);
}
}
diff --git a/src/ltran/main.c b/src/ltran/main.c
index 3d2310b..0320b29 100644
--- a/src/ltran/main.c
+++ b/src/ltran/main.c
@@ -117,7 +117,7 @@ static int32_t ltran_core_init(int32_t argc, char *argv[])
ret = ltran_ethdev_init();
if (ret != GAZELLE_OK) {
- syslog(LOG_ERR, "ltran ethdev init faild. ret=%d.\n", ret);
+ syslog(LOG_ERR, "ltran ethdev init failed. ret=%d.\n", ret);
closelog();
return ret;
}
@@ -211,7 +211,7 @@ int32_t main(int32_t argc, char *argv[])
}
/* create multi thread to receive and send packet for multi bond port */
- LTRAN_INFO("Runing Process forward\n");
+ LTRAN_INFO("Running Process forward\n");
/* main thread is for port 0 receive packet */
index = 0;
upstream_forward((const void *)&index);
diff --git a/tools/gazelle_common.sh b/tools/gazelle_common.sh
index fac0d68..8febd16 100644
--- a/tools/gazelle_common.sh
+++ b/tools/gazelle_common.sh
@@ -25,7 +25,7 @@ g_subnet_len=""
g_gateway=""
g_premask=""
-# globla varibles initialized when run
+# global variables initialized when run
g_netcard_mac=""
g_kni_mac=""
g_default_route="$(sudo ip route | grep default)"
@@ -148,7 +148,7 @@ load_vfio_module() {
msg_show "Loading vfio module"
sudo /sbin/modprobe vfio enable_unsafe_noiommu_mode=1
else
- msg_err "the vfio mudule is not exist"
+ msg_err "the vfio module is not exist"
return 1
fi
sudo modinfo vfio-pci > /dev/null
@@ -156,7 +156,7 @@ load_vfio_module() {
msg_show "Loading vfio-pci module"
sudo /sbin/modprobe vfio-pci
else
- msg_err "the vfio-pci mudule is not exist"
+ msg_err "the vfio-pci module is not exist"
return 1
fi
fi
@@ -393,7 +393,7 @@ configure_nic() {
fi
if [ $1 = "usr" ]; then
- msg_show "use vitual kni card"
+ msg_show "use virtual kni card"
net_card=$g_conn_if_kni
default_route="$(echo $g_default_route | grep $g_conn_if)"
fi
diff --git a/tools/gazelle_setup.sh b/tools/gazelle_setup.sh
index c3ad830..8185e19 100644
--- a/tools/gazelle_setup.sh
+++ b/tools/gazelle_setup.sh
@@ -117,7 +117,7 @@ check_nic_name() {
check_numa_pages() {
numa_num=$(lscpu | grep "NUMA node(s)" | awk '{print $3}')
- # todo : check the maxmum and minmum of the page numbers, make sure the system available mem support
+ # todo : check the maxmum and minimum of the page numbers, make sure the system available mem support
g_hugepages=${g_hugepages:-1024}
msg_show "make sure the huge mem is large enough & not extend the maximum of system mem!"
myPage=(${g_hugepages//\,/ })
@@ -511,7 +511,7 @@ XDG_RUNTIME_DIR=/tmp nohup /usr/bin/ltran --config-file=$CONF_DIR/ltran.conf > /
check_ltran 120
if [ $? -ne 0 ]; then
- msg_err "ltran start faild! Please check ltran's log for the reason of the problem."
+ msg_err "ltran start failed! Please check ltran's log for the reason of the problem."
nic_recover
exit 1
else
diff --git a/tools/sync-gazelle-src.sh b/tools/sync-gazelle-src.sh
index ccfa8eb..326119b 100644
--- a/tools/sync-gazelle-src.sh
+++ b/tools/sync-gazelle-src.sh
@@ -8,7 +8,7 @@
# 2. COMMIT_ID is a committrf hash record from openeuler/gazelle (this repository).
# Multiple committrf hash records should be separated by spaces;
# 3. TARGET_BRANCH is a branch from src-openeuler/gazelle;
-# 4. USER/EMAIL will be autimatically obtailed from the git configuration;
+# 4. USER/EMAIL will be automatically obtailed from the git configuration;
# Example Usage:
# > COMMIT_ID="123456789" TARGET_BRANCH="openEuler-20.03-LTS-SP1" bash tools/sync-gazelle-src.sh
@@ -39,7 +39,7 @@ for commitid in ${COMMIT_ID};do
cd ${workdir}
patchname=$(git format-patch -1 ${commitid} | tail -n1)
if [ $? -ne 0 ];then
- echo "invaild commitid $commitid"
+ echo "invalid commitid $commitid"
exit 1
fi
gitmsg=$(git log --pretty=format:"%s" -1 $commitid | sed -e 's/^![0-9]* //g')
--
2.33.0

View File

@ -0,0 +1,30 @@
From 6da24dc0e77efa68f7b8c7d9986634918ef6097e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=8F=A0=E8=90=9D=E6=9C=89=E7=82=B9=E9=85=B8?=
<yanxiaoqiang_yewu@cmss.chinamobile.com>
Date: Wed, 9 Oct 2024 07:55:56 +0000
Subject: [PATCH] update test/unitest/ltran/ltran_param_test.c.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: 菠萝有点酸 <yanxiaoqiang_yewu@cmss.chinamobile.com>
---
test/unitest/ltran/ltran_param_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/unitest/ltran/ltran_param_test.c b/test/unitest/ltran/ltran_param_test.c
index 3b2a24d..d43d20f 100644
--- a/test/unitest/ltran/ltran_param_test.c
+++ b/test/unitest/ltran/ltran_param_test.c
@@ -74,7 +74,7 @@ void test_ltran_bad_params_clients(void)
CU_ASSERT(ltran_bad_param("s/dispatch_max_clients = 32/dispatch_max_clients = 0/") != 0);
CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
- /* ltran start 999 clinet */
+ /* ltran start 999 client */
CU_ASSERT(ltran_bad_param("s/dispatch_max_clients = 32/dispatch_max_clients = 999/") != 0);
CU_ASSERT(gazelle_get_errno() == GAZELLE_ERANGE);
--
2.33.0

View File

@ -0,0 +1,87 @@
From cd82f46b54e14898087ea1b051bce51eb50adef7 Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Wed, 20 Nov 2024 14:17:09 +0800
Subject: [PATCH] fix free null pointer when no matching device is found
---
src/lstack/core/lstack_cfg.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index 2a3f1af..0ca838d 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -179,7 +179,7 @@ struct cfg_params *get_global_cfg_params(void)
static int32_t str_to_eth_addr(const char *src, unsigned char *dst)
{
- if (strlen(src) > DEV_MAC_LEN) {
+ if (src == NULL || strlen(src) > DEV_MAC_LEN) {
return -EINVAL;
}
@@ -273,7 +273,6 @@ static int32_t parse_mask_addr(void)
}
freeifaddrs(ifaddr);
- freeifaddrs(ifa);
}
if (g_config_params.netmask.addr == INADDR_NONE) {
@@ -315,7 +314,6 @@ static int32_t parse_host_addr(void)
}
freeifaddrs(ifaddr);
- freeifaddrs(ifa);
}
if (g_config_params.host_addr.addr == INADDR_NONE) {
@@ -404,7 +402,6 @@ static int32_t parse_devices(void)
}
freeifaddrs(ifaddr);
- freeifaddrs(ifa);
}
/* add dev */
@@ -1048,7 +1045,7 @@ static int32_t parse_mbuf_count_per_conn(void)
{
int32_t ret;
PARSE_ARG(g_config_params.mbuf_count_per_conn, "mbuf_count_per_conn",
- MBUF_COUNT_PER_CONN, 1, INT32_MAX, ret);
+ MBUF_COUNT_PER_CONN, 1, INT32_MAX, ret);
return ret;
}
@@ -1173,13 +1170,13 @@ static int32_t parse_unix_prefix(void)
int32_t ret = 0;
ret = memset_s(g_config_params.unix_socket_filename, sizeof(g_config_params.unix_socket_filename),
- 0, sizeof(g_config_params.unix_socket_filename));
+ 0, sizeof(g_config_params.unix_socket_filename));
if (ret != EOK) {
return ret;
}
ret = strncpy_s(g_config_params.unix_socket_filename, sizeof(g_config_params.unix_socket_filename),
- GAZELLE_RUN_DIR, strlen(GAZELLE_RUN_DIR) + 1);
+ GAZELLE_RUN_DIR, strlen(GAZELLE_RUN_DIR) + 1);
if (ret != EOK) {
return ret;
}
@@ -1200,10 +1197,10 @@ static int32_t parse_unix_prefix(void)
if (g_config_params.use_ltran) {
ret = strncat_s(g_config_params.unix_socket_filename, sizeof(g_config_params.unix_socket_filename),
- LTRAN_REG_SOCK_FILENAME, strlen(LTRAN_REG_SOCK_FILENAME) + 1);
+ LTRAN_REG_SOCK_FILENAME, strlen(LTRAN_REG_SOCK_FILENAME) + 1);
} else {
ret = strncat_s(g_config_params.unix_socket_filename, sizeof(g_config_params.unix_socket_filename),
- LSTACK_DFX_SOCK_FILENAME, strlen(LSTACK_DFX_SOCK_FILENAME) + 1);
+ LSTACK_DFX_SOCK_FILENAME, strlen(LSTACK_DFX_SOCK_FILENAME) + 1);
}
if (ret != EOK) {
--
2.33.0

View File

@ -0,0 +1,66 @@
From f05ce4c32a5c4121f41a69fa8b78c0a6a69e29d8 Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Wed, 20 Nov 2024 11:42:00 +0800
Subject: [PATCH] cfg: show dpdk args after dpdk_adjust_args
---
src/lstack/core/lstack_cfg.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index 2a3f1af..72dbb18 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -905,7 +905,7 @@ static void dpdk_fill_socket_mem(void)
}
}
-static void dpdk_add_args(void)
+static void dpdk_adjust_args(void)
{
int idx;
uint16_t lcore_id;
@@ -936,6 +936,15 @@ static void dpdk_add_args(void)
}
}
+static void dpdk_show_args(void)
+{
+ (void)fprintf(stderr, "dpdk argv: ");
+ for (uint32_t i = 1; i < g_config_params.dpdk_argc; i++) {
+ (void)fprintf(stderr, "%s ", g_config_params.dpdk_argv[i]);
+ }
+ (void)fprintf(stderr, "\n");
+}
+
static int32_t parse_dpdk_args(void)
{
int32_t i;
@@ -957,8 +966,6 @@ static int32_t parse_dpdk_args(void)
if (!g_config_params.dpdk_argv)
return -EINVAL;
- (void)fprintf(stderr, "dpdk argv: ");
-
g_config_params.dpdk_argv[0] = strdup("lstack");
if (!g_config_params.dpdk_argv[0]) {
goto free_dpdk_args;
@@ -981,13 +988,11 @@ static int32_t parse_dpdk_args(void)
if (strcmp(p, secondary) == 0) {
global_params->is_primary = 0;
}
-
- (void)fprintf(stderr, "%s ", g_config_params.dpdk_argv[start_index + i]);
}
- (void)fprintf(stderr, "\n");
g_config_params.dpdk_argc++;
- dpdk_add_args();
+ dpdk_adjust_args();
+ dpdk_show_args();
if (turn_args_to_config(g_config_params.dpdk_argc, g_config_params.dpdk_argv))
goto free_dpdk_args;
--
2.33.0

View File

@ -0,0 +1,27 @@
From 83b65f8da77f586cc58278944f840016817ba9f7 Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Sat, 23 Nov 2024 16:14:25 +0800
Subject: [PATCH] fix build error in 2003SP4
---
src/lstack/api/lstack_wrap.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index 7e724cd..d22847a 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -31,6 +31,10 @@
#include "lstack_rtw_api.h"
#include "lstack_dummy_api.h"
+#ifndef SOL_XDP
+#define SOL_XDP 283 /* same as define in bits/socket.h */
+#endif
+
static posix_api_t g_wrap_api_value;
static posix_api_t *g_wrap_api;
--
2.33.0

View File

@ -0,0 +1,166 @@
From fb7be13ec41f31261fb32741cab2f9903b05d246 Mon Sep 17 00:00:00 2001
From: yinbin <yinbin8@huawei.com>
Date: Fri, 22 Nov 2024 16:04:14 +0800
Subject: [PATCH] CFG: fix xdp iface check error
---
src/lstack/core/lstack_cfg.c | 47 ++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 13 deletions(-)
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index 0ca838d..45c695e 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -92,6 +92,7 @@ static int32_t parse_flow_bifurcation(void);
static int32_t parse_stack_interrupt(void);
static int32_t parse_stack_num(void);
static int32_t parse_xdp_eth_name(void);
+static bool xdp_eth_enabled(void);
#define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \
do { \
@@ -223,7 +224,7 @@ static int32_t parse_gateway_addr(void)
return 0;
}
- if (strlen(g_config_params.xdp_eth_name) == 0) {
+ if (!xdp_eth_enabled()) {
ok = config_lookup_string(&g_config, "gateway_addr", (const char **)&value);
if (!ok) {
return -EINVAL;
@@ -252,7 +253,7 @@ static int32_t parse_mask_addr(void)
return 0;
}
- if (strlen(g_config_params.xdp_eth_name) == 0) {
+ if (!xdp_eth_enabled()) {
ret = config_lookup_string(&g_config, "mask_addr", (const char **)&mask_addr);
if (!ret) {
return -EINVAL;
@@ -266,7 +267,7 @@ static int32_t parse_mask_addr(void)
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET ||
- strncmp(ifa->ifa_name, g_config_params.xdp_eth_name, strlen(g_config_params.xdp_eth_name))) {
+ strcmp(ifa->ifa_name, g_config_params.xdp_eth_name)) {
continue;
}
g_config_params.netmask.addr = ((struct sockaddr_in *)ifa->ifa_netmask)->sin_addr.s_addr;
@@ -293,7 +294,7 @@ static int32_t parse_host_addr(void)
struct ifaddrs *ifaddr;
struct ifaddrs *ifa;
- if (strlen(g_config_params.xdp_eth_name) == 0) {
+ if (!xdp_eth_enabled()) {
ret = config_lookup_string(&g_config, "host_addr", (const char **)&host_addr);
if (!ret) {
return 0;
@@ -307,7 +308,7 @@ static int32_t parse_host_addr(void)
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET ||
- strncmp(ifa->ifa_name, g_config_params.xdp_eth_name, strlen(g_config_params.xdp_eth_name))) {
+ strcmp(ifa->ifa_name, g_config_params.xdp_eth_name)) {
continue;
}
g_config_params.host_addr.addr = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
@@ -334,7 +335,7 @@ static int32_t parse_host_addr6(void)
ok = config_lookup_string(&g_config, "host_addr6", (const char **)&value);
if (!ok) {
- if (ip4_addr_isany_val(g_config_params.host_addr) && (strlen(g_config_params.xdp_eth_name) == 0)) {
+ if (ip4_addr_isany_val(g_config_params.host_addr) && (!xdp_eth_enabled())) {
LSTACK_PRE_LOG(LSTACK_ERR, "cfg: host_addr and host_addr6 must have a valid one.");
return -EINVAL;
} else {
@@ -377,7 +378,7 @@ static int32_t parse_devices(void)
struct ifaddrs *ifaddr;
char temp_dev[DEV_MAC_LEN + 1] = {0};
- if (strlen(g_config_params.xdp_eth_name) == 0) {
+ if (!xdp_eth_enabled()) {
ret = config_lookup_string(&g_config, "devices", (const char **)&dev);
if (!ret) {
return -EINVAL;
@@ -390,7 +391,7 @@ static int32_t parse_devices(void)
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_PACKET ||
- strncmp(ifa->ifa_name, g_config_params.xdp_eth_name, strlen(g_config_params.xdp_eth_name))) {
+ strcmp(ifa->ifa_name, g_config_params.xdp_eth_name)) {
continue;
}
@@ -399,9 +400,16 @@ static int32_t parse_devices(void)
((struct sockaddr_ll *)ifa->ifa_addr)->sll_addr[i], i < (ETHER_ADDR_LEN - 1) ? ":" : "");
}
dev = strdup_assert_return(temp_dev);
+ break;
}
freeifaddrs(ifaddr);
+
+ if (dev == NULL) {
+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: can not find the iface \"%s\" specified in dpdk_args."
+ " devices parsing exit!\n", g_config_params.xdp_eth_name);
+ return -EINVAL;
+ }
}
/* add dev */
@@ -1497,7 +1505,7 @@ static int32_t parse_stack_interrupt(void)
return ret;
}
-static void dpdk_dev_get_iface_name(char *vdev_str)
+static int dpdk_dev_get_iface_name(char *vdev_str)
{
char *token = NULL;
char *iface_value = NULL;
@@ -1507,7 +1515,7 @@ static void dpdk_dev_get_iface_name(char *vdev_str)
/* To prevent the original string from being modified, use a copied string. */
if (strcpy_s(vdev_str_cp, sizeof(vdev_str_cp), vdev_str) != 0) {
LSTACK_PRE_LOG(LSTACK_ERR, "vdev_str strcpy_s fail \n");
- return;
+ return -1;
}
token = strtok_s(vdev_str_cp, ",", &next_token);
@@ -1519,8 +1527,12 @@ static void dpdk_dev_get_iface_name(char *vdev_str)
token = strtok_s(NULL, ",", &next_token);
}
- if (iface_value) {
+ if (iface_value && strlen(iface_value) > 0) {
strncpy_s(g_config_params.xdp_eth_name, IFNAMSIZ, iface_value, IFNAMSIZ - 1);
+ return 0;
+ } else {
+ LSTACK_PRE_LOG(LSTACK_ERR, "xdp iface name bas not been specified in dpdk_args.\n");
+ return -1;
}
}
@@ -1536,9 +1548,18 @@ static int32_t parse_xdp_eth_name(void)
for (uint32_t i = 0; i < g_config_params.dpdk_argc; i++) {
if (!strncmp(g_config_params.dpdk_argv[i], OPT_VDEV, strlen(OPT_VDEV))) {
- dpdk_dev_get_iface_name(g_config_params.dpdk_argv[i + 1]);
+ ret = dpdk_dev_get_iface_name(g_config_params.dpdk_argv[i + 1]);
+ break;
}
}
- return 0;
+ return ret;
+}
+
+static bool xdp_eth_enabled(void)
+{
+ if (strlen(g_config_params.xdp_eth_name)) {
+ return true;
+ }
+ return false;
}
--
2.33.0

View File

@ -0,0 +1,425 @@
From 4b5ead09ab19b08a46a9ffba7cbc5e42e361dcc1 Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Sat, 23 Nov 2024 18:04:55 +0800
Subject: [PATCH] xdp: support stack bind numa
---
src/common/gazelle_opt.h | 5 +-
src/lstack/core/lstack_cfg.c | 101 ++++++++----------------
src/lstack/core/lstack_dpdk.c | 20 -----
src/lstack/core/lstack_protocol_stack.c | 82 +++++++++++++++++--
src/lstack/include/lstack_cfg.h | 11 +--
src/lstack/include/lstack_dpdk.h | 1 -
6 files changed, 119 insertions(+), 101 deletions(-)
diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h
index 6d787b9..98f1afd 100644
--- a/src/common/gazelle_opt.h
+++ b/src/common/gazelle_opt.h
@@ -105,8 +105,11 @@
#define LSTACK_SEND_THREAD_NAME "lstack_send"
#define LSTACK_RECV_THREAD_NAME "lstack_recv"
-#define LSTACK_THREAD_NAME "gazellelstack"
+#define LSTACK_THREAD_NAME "gazellelstack"
#define SLEEP_US_BEFORE_LINK_UP 10000
+#define CPUS_MAX_NUM 640
+#define GAZELLE_MAX_NUMA_NODES 4
+
#endif /* _GAZELLE_OPT_H_ */
diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c
index 0ca838d..c8ce5c3 100644
--- a/src/lstack/core/lstack_cfg.c
+++ b/src/lstack/core/lstack_cfg.c
@@ -43,7 +43,6 @@
#define NUMA_CPULIST_PATH "/sys/devices/system/node/node%u/cpulist"
#define DEV_MAC_LEN 17
#define DEV_PCI_ADDR_LEN 12
-#define CPUS_MAX_NUM 256
#define BOND_MIIMON_MIN 1
#define BOND_MIIMON_MAX INT_MAX
@@ -127,6 +126,7 @@ static struct config_vector_t g_config_tbl[] = {
{ "send_ring_size", parse_send_ring_size },
{ "recv_ring_size", parse_recv_ring_size },
{ "rpc_msg_max", parse_rpc_msg_max },
+ { "app_bind_numa", parse_app_bind_numa },
{ "stack_num", parse_stack_num },
{ "num_cpus", parse_stack_cpu_number },
{ "dpdk_args", parse_dpdk_args },
@@ -139,7 +139,6 @@ static struct config_vector_t g_config_tbl[] = {
{ "low_power_mode", parse_low_power_mode },
{ "kni_switch", parse_kni_switch },
{ "listen_shadow", parse_listen_shadow },
- { "app_bind_numa", parse_app_bind_numa },
{ "app_exclude_cpus", parse_app_exclude_cpus },
{ "main_thread_affinity", parse_main_thread_affinity },
{ "unix_prefix", parse_unix_prefix },
@@ -446,6 +445,7 @@ static int32_t stack_bind_no_cpu(void)
g_config_params.num_cpu = g_config_params.stack_num;
g_config_params.num_queue = g_config_params.num_cpu;
g_config_params.tot_queue_num = g_config_params.num_queue;
+ g_config_params.app_bind_numa = true;
LSTACK_PRE_LOG(LSTACK_INFO, "NUMA node: %d\n", g_config_params.numa_id);
@@ -473,11 +473,11 @@ static int32_t stack_bind_cpus(void)
strcpy(g_config_params.lcores, args);
tmp_arg = strdup_assert_return(args);
- cnt = separate_str_to_array(tmp_arg, g_config_params.cpus, CFG_MAX_CPUS, CFG_MAX_CPUS);
+ cnt = separate_str_to_array(tmp_arg, g_config_params.cpus, CPUS_MAX_NUM, CPUS_MAX_NUM);
free(tmp_arg);
if (cnt <= 0) {
return stack_bind_no_cpu();
- } else if (cnt > CFG_MAX_CPUS) {
+ } else if (cnt > CPUS_MAX_NUM) {
return -EINVAL;
}
@@ -534,9 +534,9 @@ static int32_t parse_app_exclude_cpus(void)
}
tmp_arg = strdup_assert_return(args);
- cnt = separate_str_to_array(tmp_arg, g_config_params.app_exclude_cpus, CFG_MAX_CPUS, CFG_MAX_CPUS);
+ cnt = separate_str_to_array(tmp_arg, g_config_params.app_exclude_cpus, CPUS_MAX_NUM, CPUS_MAX_NUM);
free(tmp_arg);
- if (cnt <= 0 || cnt > CFG_MAX_CPUS) {
+ if (cnt <= 0 || cnt > CPUS_MAX_NUM) {
return -EINVAL;
}
@@ -544,18 +544,20 @@ static int32_t parse_app_exclude_cpus(void)
return 0;
}
-static int32_t numa_to_cpusnum(unsigned numa_id, uint32_t *cpulist, int32_t num)
+int numa_to_cpusnum(uint16_t numa_id, uint32_t *cpulist, int num)
{
+ int ret;
+ int fd;
char path[PATH_MAX] = {0};
char strbuf[PATH_MAX] = {0};
- int32_t ret = snprintf_s(path, sizeof(path), PATH_MAX - 1, NUMA_CPULIST_PATH, numa_id);
+ ret = snprintf_s(path, sizeof(path), PATH_MAX - 1, NUMA_CPULIST_PATH, numa_id);
if (ret < 0) {
LSTACK_LOG(ERR, LSTACK, "snprintf numa_cpulist failed\n");
return -1;
}
- int32_t fd = open(path, O_RDONLY);
+ fd = open(path, O_RDONLY);
if (fd < 0) {
LSTACK_LOG(ERR, LSTACK, "open %s failed\n", path);
return -1;
@@ -568,55 +570,7 @@ static int32_t numa_to_cpusnum(unsigned numa_id, uint32_t *cpulist, int32_t num)
return -1;
}
- int32_t count = separate_str_to_array(strbuf, cpulist, num, CFG_MAX_CPUS);
- return count;
-}
-
-static int32_t stack_idle_cpuset(struct protocol_stack *stack, cpu_set_t *exclude)
-{
- uint32_t cpulist[CPUS_MAX_NUM];
-
- int32_t cpunum = numa_to_cpusnum(stack->numa_id, cpulist, CPUS_MAX_NUM);
- if (cpunum <= 0) {
- LSTACK_LOG(ERR, LSTACK, "numa_to_cpusnum failed\n");
- return -1;
- }
-
- CPU_ZERO(&stack->idle_cpuset);
- for (int32_t i = 0; i < cpunum; i++) {
- /* skip stack cpu */
- if (CPU_ISSET(cpulist[i], exclude)) {
- continue;
- }
-
- CPU_SET(cpulist[i], &stack->idle_cpuset);
- }
-
- return 0;
-}
-
-int32_t init_stack_numa_cpuset(struct protocol_stack *stack)
-{
- int32_t ret;
- struct cfg_params *cfg = get_global_cfg_params();
-
- cpu_set_t stack_cpuset;
- CPU_ZERO(&stack_cpuset);
- for (int32_t idx = 0; idx < cfg->num_cpu; ++idx) {
- CPU_SET(cfg->cpus[idx], &stack_cpuset);
- }
-
- for (int32_t idx = 0; idx < cfg->app_exclude_num_cpu; ++idx) {
- CPU_SET(cfg->app_exclude_cpus[idx], &stack_cpuset);
- }
-
- 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;
+ return separate_str_to_array(strbuf, cpulist, num, CPUS_MAX_NUM);
}
static int32_t gazelle_parse_base_virtaddr(const char *arg, uintptr_t *base_vaddr)
@@ -883,6 +837,28 @@ static bool dpdk_have_socket_mem(int32_t argc, char **argv)
return false;
}
+static void dpdk_fill_lcore(void)
+{
+ uint16_t lcore_id;
+ cpu_set_t cpuset;
+
+ CPU_ZERO(&cpuset);
+ if (sched_getaffinity(0, sizeof(cpu_set_t), &cpuset) == -1) {
+ LSTACK_LOG(ERR, LSTACK, "sched_getaffinity failed\n");
+ return;
+ }
+
+ for (lcore_id = 0; lcore_id < CPU_SETSIZE; lcore_id++) {
+ if (CPU_ISSET(lcore_id, &cpuset) &&
+ numa_node_of_cpu(lcore_id) == g_config_params.numa_id &&
+ rte_lcore_is_enabled(lcore_id)) {
+ snprintf_s(g_config_params.lcores, sizeof(g_config_params.lcores),
+ sizeof(g_config_params.lcores) - 1, "%d", lcore_id);
+ break;
+ }
+ }
+}
+
static void dpdk_fill_socket_mem(void)
{
uint32_t socket_mem_size = dpdk_total_socket_memory();
@@ -905,17 +881,10 @@ static void dpdk_fill_socket_mem(void)
static void dpdk_adjust_args(void)
{
int idx;
- uint16_t lcore_id;
if (!dpdk_have_corelist(g_config_params.dpdk_argc, g_config_params.dpdk_argv)) {
if (g_config_params.stack_num > 0) {
- RTE_LCORE_FOREACH(lcore_id) {
- if (numa_node_of_cpu(lcore_id) == g_config_params.numa_id && rte_lcore_is_enabled(lcore_id)) {
- snprintf_s(g_config_params.lcores, sizeof(g_config_params.lcores),
- sizeof(g_config_params.lcores) - 1, "%d", lcore_id);
- break;
- }
- }
+ dpdk_fill_lcore();
}
g_config_params.dpdk_argv[g_config_params.dpdk_argc++] = strdup_assert_return(OPT_BIND_CORELIST);
g_config_params.dpdk_argv[g_config_params.dpdk_argc++] = strdup_assert_return(g_config_params.lcores);
diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c
index 5141c3a..3023a6c 100644
--- a/src/lstack/core/lstack_dpdk.c
+++ b/src/lstack/core/lstack_dpdk.c
@@ -104,26 +104,6 @@ int32_t thread_affinity_default(void)
return 0;
}
-int32_t thread_affinity_init(int32_t cpu_id)
-{
- int32_t ret;
- cpu_set_t cpuset;
-
- if (get_global_cfg_params()->stack_num > 0) {
- return 0;
- }
-
- CPU_ZERO(&cpuset);
- CPU_SET(cpu_id, &cpuset);
-
- ret = rte_thread_set_affinity(&cpuset);
- if (ret != 0) {
- LSTACK_LOG(ERR, LSTACK, "thread %d pthread_setaffinity_np failed ret=%d\n", rte_gettid(), ret);
- }
-
- return 0;
-}
-
int32_t dpdk_eal_init(void)
{
int32_t ret;
diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c
index 9cfd54f..2c60a49 100644
--- a/src/lstack/core/lstack_protocol_stack.c
+++ b/src/lstack/core/lstack_protocol_stack.c
@@ -32,9 +32,8 @@
#include "lstack_epoll.h"
#include "lstack_stack_stat.h"
#include "lstack_virtio.h"
-#include "lstack_protocol_stack.h"
-
#include "lstack_interrupt.h"
+#include "lstack_protocol_stack.h"
#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0)
#include <rte_kni.h>
@@ -161,6 +160,7 @@ void bind_to_stack_numa(struct protocol_stack *stack)
pthread_t tid = pthread_self();
if (get_global_cfg_params()->stack_num > 0) {
+ numa_run_on_node(stack->numa_id);
return;
}
@@ -187,6 +187,75 @@ void thread_bind_stack(struct protocol_stack *stack)
}
}
+static int stack_affinity_cpu(int cpu_id)
+{
+ int32_t ret;
+ cpu_set_t cpuset;
+
+ CPU_ZERO(&cpuset);
+ CPU_SET(cpu_id, &cpuset);
+
+ ret = rte_thread_set_affinity(&cpuset);
+ if (ret != 0) {
+ LSTACK_LOG(ERR, LSTACK, "thread %d pthread_setaffinity_np failed ret=%d\n", rte_gettid(), ret);
+ }
+
+ return ret;
+}
+
+static void stack_affinity_numa(int numa_id)
+{
+ numa_run_on_node(numa_id);
+}
+
+static int32_t stack_idle_cpuset(struct protocol_stack *stack, cpu_set_t *exclude)
+{
+ int32_t cpunum;
+ uint32_t cpulist[CPUS_MAX_NUM];
+
+ cpunum = numa_to_cpusnum(stack->numa_id, cpulist, CPUS_MAX_NUM);
+ if (cpunum <= 0) {
+ LSTACK_LOG(ERR, LSTACK, "numa_to_cpusnum failed\n");
+ return -1;
+ }
+
+ CPU_ZERO(&stack->idle_cpuset);
+ for (uint32_t i = 0; i < cpunum; i++) {
+ /* skip stack cpu */
+ if (CPU_ISSET(cpulist[i], exclude)) {
+ continue;
+ }
+
+ CPU_SET(cpulist[i], &stack->idle_cpuset);
+ }
+
+ return 0;
+}
+
+static int32_t init_stack_numa_cpuset(struct protocol_stack *stack)
+{
+ int32_t ret;
+ struct cfg_params *cfg = get_global_cfg_params();
+
+ cpu_set_t stack_cpuset;
+ CPU_ZERO(&stack_cpuset);
+ for (int32_t idx = 0; idx < cfg->num_cpu; ++idx) {
+ CPU_SET(cfg->cpus[idx], &stack_cpuset);
+ }
+
+ for (int32_t idx = 0; idx < cfg->app_exclude_num_cpu; ++idx) {
+ CPU_SET(cfg->app_exclude_cpus[idx], &stack_cpuset);
+ }
+
+ 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;
+}
+
static uint32_t get_protocol_traffic(struct protocol_stack *stack)
{
if (use_ltran()) {
@@ -412,12 +481,13 @@ static struct protocol_stack *stack_thread_init(void *arg)
goto END;
}
- if (thread_affinity_init(stack->cpu_id) != 0) {
- goto END;
- }
-
if (get_global_cfg_params()->stack_num == 0) {
+ if (stack_affinity_cpu(stack->cpu_id) != 0) {
+ goto END;
+ }
RTE_PER_LCORE(_lcore_id) = stack->cpu_id;
+ } else {
+ stack_affinity_numa(stack->numa_id);
}
lwip_init();
diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h
index 0fd5323..07a97cb 100644
--- a/src/lstack/include/lstack_cfg.h
+++ b/src/lstack/include/lstack_cfg.h
@@ -36,7 +36,6 @@
#define RX_RING_NAME 64
#define MBUF_POOL_NAME 64
-#define CFG_MAX_CPUS 512
#define CFG_MAX_PORTS UINT8_MAX
#define ARP_MAX_ENTRIES 1024
#define LOG_DIR_PATH PATH_MAX
@@ -118,12 +117,12 @@ struct cfg_params {
uint16_t num_cpu;
uint16_t numa_id;
uint16_t stack_num;
- uint32_t cpus[CFG_MAX_CPUS];
+ uint32_t cpus[CPUS_MAX_NUM];
bool main_thread_affinity;
bool app_bind_numa;
uint16_t app_exclude_num_cpu;
- uint32_t app_exclude_cpus[CFG_MAX_CPUS];
+ uint32_t app_exclude_cpus[CPUS_MAX_NUM];
bool stack_mode_rtc;
bool listen_shadow; // true:listen in all stack thread. false:listen in one stack thread.
@@ -168,10 +167,8 @@ static inline uint8_t use_ltran(void)
int cfg_init(void);
int gazelle_param_init(int *argc, char **argv);
-int gazelle_copy_param(const char *param, bool is_double,
- int *argc, char argv[][PATH_MAX]);
-
+int gazelle_copy_param(const char *param, bool is_double, int *argc, char argv[][PATH_MAX]);
int match_host_addr(ip_addr_t *addr);
-int32_t init_stack_numa_cpuset(struct protocol_stack *stack);
+int numa_to_cpusnum(uint16_t numa_id, uint32_t *cpulist, int num);
#endif /* GAZELLE_NET_CFG_H */
diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h
index 87219c2..c2142d6 100644
--- a/src/lstack/include/lstack_dpdk.h
+++ b/src/lstack/include/lstack_dpdk.h
@@ -45,7 +45,6 @@ int dpdk_ethdev_start(void);
int init_dpdk_ethdev(void);
int thread_affinity_default(void);
-int thread_affinity_init(int cpu_id);
int32_t create_shared_ring(struct protocol_stack *stack);
int32_t fill_mbuf_to_ring(struct rte_mempool *mempool, struct rte_ring *ring, uint32_t mbuf_num);
--
2.33.0

View File

@ -0,0 +1,125 @@
From b29d2ce72651ac91728278cb9b31029b397c6ea5 Mon Sep 17 00:00:00 2001
From: hankangkang <hankangkang5@huawei.com>
Date: Wed, 27 Nov 2024 09:50:08 +0800
Subject: [PATCH] openGauss: support kernel connnect
Signed-off-by: hankangkang <hankangkang5@huawei.com>
---
src/lstack/api/lstack_wrap.c | 71 ++++++++++++++++++++++++++++--------
1 file changed, 56 insertions(+), 15 deletions(-)
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index d22847a..4416bd8 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -250,7 +250,7 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen
return g_wrap_api->bind_fn(s, name, namelen);
}
-static bool is_dst_ip_localhost(const struct sockaddr *addr)
+static bool kernel_ip_route(const struct sockaddr *addr)
{
struct ifaddrs *ifap;
struct ifaddrs *ifa;
@@ -292,43 +292,84 @@ static bool is_dst_ip_localhost(const struct sockaddr *addr)
freeifaddrs(ifap);
return false;
}
+static bool is_relatived_kernel_ip(const struct sockaddr *dst_addr)
+{
+ struct ifaddrs *ifap;
+ struct ifaddrs *ifa;
+ uint32_t local_ip;
+ uint32_t local_mask;
+ uint32_t dst_ip;
+ bool ret = false;
+
+ if (getifaddrs(&ifap) == -1) {
+ LSTACK_LOG(ERR, LSTACK, "get interface IP address failed\n");
+ return false;
+ }
-static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t namelen)
+ for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr == NULL) {
+ continue;
+ }
+
+ if (ifa->ifa_addr->sa_family == AF_INET) {
+ struct sockaddr_in *if_addr = (struct sockaddr_in *)ifa->ifa_addr;
+ if (get_global_cfg_params()->host_addr.addr == if_addr->sin_addr.s_addr) {
+ continue;
+ }
+ }
+
+ if (ifa->ifa_addr->sa_family == AF_INET && dst_addr->sa_family == AF_INET) {
+ struct sockaddr_in *if_addr = (struct sockaddr_in *)ifa->ifa_addr;
+ struct sockaddr_in *ifa_netmask = (struct sockaddr_in *)ifa->ifa_netmask;
+ local_ip = if_addr->sin_addr.s_addr;
+ local_mask = ifa_netmask->sin_addr.s_addr;
+ dst_ip = ((struct sockaddr_in *)dst_addr) ->sin_addr.s_addr;
+ if ((local_ip & local_mask) == (dst_ip & local_mask)) {
+ ret = true;
+ break;
+ }
+ }
+ }
+ freeifaddrs(ifap);
+ return ret;
+}
+static int32_t do_connect(int32_t s, const struct sockaddr *addr, socklen_t addrlen)
{
- if (name == NULL) {
+ if (addr == NULL) {
GAZELLE_RETURN(EINVAL);
}
struct lwip_sock *sock = lwip_get_socket(s);
if (select_sock_posix_path(sock) == POSIX_KERNEL) {
- return posix_api->connect_fn(s, name, namelen);
+ return posix_api->connect_fn(s, addr, addrlen);
}
int32_t ret = 0;
int32_t remote_port;
- bool is_local = is_dst_ip_localhost(name);
+ bool is_kernel = kernel_ip_route(addr);
+ bool is_to_kernel_connect = is_relatived_kernel_ip(addr);
- remote_port = htons(((struct sockaddr_in *)name)->sin_port);
+ remote_port = htons(((struct sockaddr_in *)addr)->sin_port);
char listen_ring_name[RING_NAME_LEN];
snprintf_s(listen_ring_name, sizeof(listen_ring_name), sizeof(listen_ring_name) - 1,
"listen_rx_ring_%d", remote_port);
- if (is_local && rte_ring_lookup(listen_ring_name) == NULL) {
- ret = posix_api->connect_fn(s, name, namelen);
+
+ if ((is_kernel && rte_ring_lookup(listen_ring_name) == NULL) || is_to_kernel_connect) {
+ ret = posix_api->connect_fn(s, addr, addrlen);
POSIX_SET_TYPE(sock, POSIX_KERNEL);
} else {
/* When the socket is POSIX_LWIP_OR_KERNEL, connect to lwip first and then connect to kernel. */
- ret = g_wrap_api->connect_fn(s, name, namelen);
+ ret = g_wrap_api->connect_fn(s, addr, addrlen);
if (ret == 0 || (ret != 0 && errno == EINPROGRESS)) {
POSIX_SET_TYPE(sock, POSIX_LWIP);
- } else {
- ret = posix_api->connect_fn(s, name, namelen);
+ } else {
+ ret = posix_api->connect_fn(s, addr, addrlen);
if (ret == 0) {
- POSIX_SET_TYPE(sock, POSIX_KERNEL);
- }
- }
+ POSIX_SET_TYPE(sock, POSIX_KERNEL);
+ }
+ }
}
-
return ret;
}
--
2.33.0

View File

@ -0,0 +1,260 @@
From 71fee80519b321b565cdec74d9e7fae25f9bc750 Mon Sep 17 00:00:00 2001
From: yinbin <yinbin8@huawei.com>
Date: Sat, 30 Nov 2024 16:05:02 +0800
Subject: [PATCH] DUMP: gazelle supports dump lstack
---
src/lstack/api/lstack_unistd.c | 36 +++-----
src/lstack/core/lstack_dump.c | 144 +++++++++++++++++++++++++++++++
src/lstack/include/lstack_dump.h | 19 ++++
3 files changed, 176 insertions(+), 23 deletions(-)
create mode 100644 src/lstack/core/lstack_dump.c
create mode 100644 src/lstack/include/lstack_dump.h
diff --git a/src/lstack/api/lstack_unistd.c b/src/lstack/api/lstack_unistd.c
index 1f78626..8fd6490 100644
--- a/src/lstack/api/lstack_unistd.c
+++ b/src/lstack/api/lstack_unistd.c
@@ -11,7 +11,6 @@
*/
#include <sys/types.h>
-#include <execinfo.h>
#include <sys/socket.h>
#include <lwip/lwipgz_sock.h>
@@ -22,28 +21,11 @@
#include "lstack_log.h"
#include "lstack_cfg.h"
#include "lstack_control_plane.h"
+#include "lstack_dump.h"
static int g_hijack_signal[] = { SIGTERM, SIGINT, SIGSEGV, SIGBUS, SIGFPE, SIGILL, SIGKILL};
#define HIJACK_SIGNAL_COUNT (sizeof(g_hijack_signal) / sizeof(g_hijack_signal[0]))
-#define BACKTRACE_SIZE 64
-static void dump_stack(void)
-{
- char **stack_trace = NULL;
- void *stack_array[BACKTRACE_SIZE];
- int stack_num = backtrace(stack_array, BACKTRACE_SIZE);
-
- stack_trace = (char**)backtrace_symbols(stack_array, stack_num);
- if (stack_trace == NULL) {
- perror("backtrace_symbols");
- return;
- }
-
- for (int i = 0; i < stack_num; i++) {
- LSTACK_LOG(ERR, LSTACK, "%s\n", stack_trace[i]);
- }
- free(stack_trace);
-}
static inline bool match_hijack_signal(int sig)
{
unsigned int i;
@@ -58,14 +40,22 @@ static inline bool match_hijack_signal(int sig)
static void lstack_sig_default_handler(int sig)
{
LSTACK_LOG(ERR, LSTACK, "lstack dumped, caught signal: %d\n", sig);
- if (get_global_cfg_params() && get_global_cfg_params()->is_primary) {
- delete_primary_path();
- }
- control_fd_close();
+
/* When operations such as pressing Ctrl+C or Kill, the call stack exit is not displayed. */
if (sig != SIGINT && sig != SIGTERM && sig != SIGKILL) {
+ /* dump stack info */
dump_stack();
+
+ /* dump internal information of lstack */
+ dump_lstack();
}
+
+ if (get_global_cfg_params() && get_global_cfg_params()->is_primary) {
+ delete_primary_path();
+ }
+
+ control_fd_close();
+
lwip_exit();
gazelle_exit();
(void)kill(getpid(), sig);
diff --git a/src/lstack/core/lstack_dump.c b/src/lstack/core/lstack_dump.c
new file mode 100644
index 0000000..d415ddc
--- /dev/null
+++ b/src/lstack/core/lstack_dump.c
@@ -0,0 +1,144 @@
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+* gazelle is licensed under the Mulan PSL v2.
+* You can use this software according to the terms and conditions of the Mulan PSL v2.
+* You may obtain a copy of Mulan PSL v2 at:
+* http://license.coscl.org.cn/MulanPSL2
+* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+* PURPOSE.
+* See the Mulan PSL v2 for more details.
+*/
+
+#include <fcntl.h>
+#include <sys/time.h>
+#include <execinfo.h>
+
+#include "lstack_cfg.h"
+#include "lstack_log.h"
+
+#define DUMP_COMMAND_TIMEOUT_MS 2000
+#define DUMP_COMMAND_INTERVAL_MS 1
+#define DUMP_BUF_SZ 1024
+#define DUMP_BACKTRACE_SIZE 64
+
+static const char *dump_command[] = {
+ "gazellectl lstack show 1",
+ "gazellectl lstack show 1 -s",
+ "gazellectl lstack show 1 -x",
+ "gazellectl lstack show 1 -p UDP",
+ "gazellectl lstack show 1 -p TCP",
+ "gazellectl lstack show 1 -p ICMP",
+ "gazellectl lstack show 1 -p IP",
+ "gazellectl lstack show 1 -p ETHARP",
+ "gazellectl lstack show 1 -c"
+};
+
+static int dump_lstack_check(void)
+{
+ /* In ltran mode, dump commands maybe illegal */
+ if (use_ltran()) {
+ LSTACK_LOG(ERR, LSTACK, "ltran mode doesn't support lstack info dump.\n");
+ return -1;
+ }
+
+ LSTACK_LOG(INFO, LSTACK, "Dump lstack check passed. Dumping information:\n");
+ return 0;
+}
+
+#define US_PER_MS (MS_PER_S)
+static long timeval_diff_ms(struct timeval *end, struct timeval *begin)
+{
+ struct timeval result;
+ long result_ms;
+
+ result.tv_sec = end->tv_sec - begin->tv_sec;
+ result.tv_usec = end->tv_usec - begin->tv_usec;
+
+ result_ms = result.tv_sec * MS_PER_S + result.tv_usec / US_PER_MS;
+ return result_ms;
+}
+
+static int dump_command_excute(const char *command)
+{
+ FILE *fp;
+ int flags, fd;
+ char buffer[DUMP_BUF_SZ];
+ struct timeval start, now;
+ long elapsed;
+
+ if ((fp = popen(command, "r")) == NULL) {
+ LSTACK_LOG(ERR, LSTACK, "popen() failed, command \"%s\" didn't excute.\n", command);
+ return -1;
+ }
+
+ fd = fileno(fp);
+ flags = fcntl(fd, F_GETFL, 0);
+ fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+
+ gettimeofday(&start, NULL);
+
+ /* Loop to print command output while checking for timeout. */
+ while (1) {
+ gettimeofday(&now, NULL);
+ elapsed = timeval_diff_ms(&now, &start);
+
+ /* check timeout */
+ if (elapsed > DUMP_COMMAND_TIMEOUT_MS) {
+ LSTACK_LOG(ERR, LSTACK, "Command timeout: %s\n", command);
+ pclose(fp);
+ return -1;
+ }
+
+ /* get and print command output */
+ if (fgets(buffer, sizeof(buffer), fp) != NULL) {
+ LSTACK_LOG(INFO, LSTACK, "\r %s", buffer);
+ } else if (feof(fp)) {
+ break;
+ } else {
+ usleep(DUMP_COMMAND_INTERVAL_MS * US_PER_MS); // 1ms
+ }
+ }
+
+ pclose(fp);
+ return 0;
+}
+
+void dump_lstack(void)
+{
+ int ret, command_count;
+
+ ret = dump_lstack_check();
+ if (ret < 0) {
+ LSTACK_LOG(ERR, LSTACK, "lstack dump check failed, dump process exited!\n");
+ return;
+ }
+
+ command_count = sizeof(dump_command) / sizeof(dump_command[0]);
+ for (int i = 0; i < command_count; ++i) {
+ LSTACK_LOG(INFO, LSTACK, "Dump command: \"%s\"\n", dump_command[i]);
+
+ ret = dump_command_excute(dump_command[i]);
+ if (ret < 0) {
+ LSTACK_LOG(ERR, LSTACK, "Dump command: \"%s\" excute failed.\n", dump_command[i]);
+ }
+ }
+}
+
+void dump_stack(void)
+{
+ char **stack_trace = NULL;
+ void *stack_array[DUMP_BACKTRACE_SIZE];
+ int stack_num = backtrace(stack_array, DUMP_BACKTRACE_SIZE);
+
+ stack_trace = (char**)backtrace_symbols(stack_array, stack_num);
+ if (stack_trace == NULL) {
+ LSTACK_LOG(ERR, LSTACK, "Error in backtrace_symbols, errno %d\n", errno);
+ return;
+ }
+
+ for (int i = 0; i < stack_num; i++) {
+ LSTACK_LOG(ERR, LSTACK, "%s\n", stack_trace[i]);
+ }
+ free(stack_trace);
+}
diff --git a/src/lstack/include/lstack_dump.h b/src/lstack/include/lstack_dump.h
new file mode 100644
index 0000000..83f2fd9
--- /dev/null
+++ b/src/lstack/include/lstack_dump.h
@@ -0,0 +1,19 @@
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
+* gazelle is licensed under the Mulan PSL v2.
+* You can use this software according to the terms and conditions of the Mulan PSL v2.
+* You may obtain a copy of Mulan PSL v2 at:
+* http://license.coscl.org.cn/MulanPSL2
+* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+* PURPOSE.
+* See the Mulan PSL v2 for more details.
+*/
+
+#ifndef _GAZELLE_DUMP_H_
+#define _GAZELLE_DUMP_H_
+
+void dump_stack(void);
+void dump_lstack(void);
+
+#endif /* _GAZELLE_DUMP_H_ */
--
2.33.0

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

@ -0,0 +1,65 @@
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

View File

@ -0,0 +1,24 @@
From fd8004b7b7e78d08a7ad59a4561a3b539e806f06 Mon Sep 17 00:00:00 2001
From: hankangkang <hankangkang5@huawei.com>
Date: Thu, 12 Dec 2024 09:14:25 +0800
Subject: [PATCH] openGauss unsupport_tcp_optname
---
src/lstack/api/lstack_wrap.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index 4416bd8..95e77b6 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -426,6 +426,7 @@ static bool unsupport_tcp_optname(int32_t optname)
if ((optname == TCP_QUICKACK) ||
(optname == TCP_INFO) ||
(optname == TCP_MAXSEG) ||
+ (optname == TCP_USER_TIMEOUT) ||
(optname == TCP_CONGESTION)) {
return true;
}
--
2.33.0

View File

@ -0,0 +1,48 @@
From bf5bf036eed0f7c15e7441c0c4ddbd5d7e48b3dd Mon Sep 17 00:00:00 2001
From: hankangkang <hankangkang5@huawei.com>
Date: Thu, 12 Dec 2024 11:40:09 +0800
Subject: [PATCH] kernerl bind: add ipv6 add check
---
src/lstack/api/lstack_wrap.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index 4b57e60..05fa6ef 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -174,14 +174,25 @@ 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;
+ bool share_ip = true;
+
+ /* lwip and kernel share IP, and exchange mbuf through virtual-NIC.
+ * 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) {
+ share_ip = false;
+ }
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) {
- LSTACK_LOG(WARNING, LSTACK, "virtio_user addr is tentative, please wait... \n");
- while (ret != 0 && times-- > 0) {
- sleep(1);
- ret = posix_api->bind_fn(s, name, namelen);
+ if (ret < 0 && errno == EADDRNOTAVAIL) {
+ /* ipv6 addr of virtual-NIC maybe is tentative, need to wait a few seconds */
+ if (name->sa_family == AF_INET6 && share_ip) {
+ LSTACK_LOG(WARNING, LSTACK, "virtio_user addr is tentative, please wait... \n");
+ while (ret != 0 && times-- > 0) {
+ sleep(1);
+ ret = posix_api->bind_fn(s, name, namelen);
+ }
}
}
--
2.33.0

View File

@ -0,0 +1,132 @@
From 434a2509c25f265adb5d7b9398cb3bf8e379b387 Mon Sep 17 00:00:00 2001
From: yinbin <yinbin8@huawei.com>
Date: Sat, 14 Dec 2024 16:55:18 +0800
Subject: [PATCH] Connect: execute lwip connect if dst_ip and host_ip are in
the same network.
---
src/lstack/api/lstack_wrap.c | 82 ++++++++++++++++++++++++++----------
1 file changed, 59 insertions(+), 23 deletions(-)
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index 8077753..97e927a 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -256,7 +256,7 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen
return g_wrap_api->bind_fn(s, name, namelen);
}
-static bool kernel_ip_route(const struct sockaddr *addr)
+static bool kernel_ip_match(const struct sockaddr *addr)
{
struct ifaddrs *ifap;
struct ifaddrs *ifa;
@@ -298,7 +298,27 @@ static bool kernel_ip_route(const struct sockaddr *addr)
freeifaddrs(ifap);
return false;
}
-static bool is_relatived_kernel_ip(const struct sockaddr *dst_addr)
+
+static bool lwip_ip_route(const struct sockaddr *dst_addr)
+{
+ uint32_t host_ip;
+ uint32_t host_mask;
+ uint32_t dst_ip;
+
+ host_ip = get_global_cfg_params()->host_addr.addr;
+ host_mask = get_global_cfg_params()->netmask.addr;
+ if (dst_addr->sa_family == AF_INET) {
+ dst_ip = ((struct sockaddr_in *)dst_addr) ->sin_addr.s_addr;
+ /* if dst_addr and host_addr are in the same network, return ture. */
+ if ((host_ip & host_mask) == (dst_ip & host_mask)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool kernel_ip_route(const struct sockaddr *dst_addr)
{
struct ifaddrs *ifap;
struct ifaddrs *ifa;
@@ -339,8 +359,34 @@ static bool is_relatived_kernel_ip(const struct sockaddr *dst_addr)
freeifaddrs(ifap);
return ret;
}
+
+static bool should_enter_kernel_connect(const struct sockaddr *addr)
+{
+ int32_t remote_port;
+ char listen_ring_name[RING_NAME_LEN];
+
+ remote_port = htons(((struct sockaddr_in *)addr)->sin_port);
+ snprintf_s(listen_ring_name, sizeof(listen_ring_name), sizeof(listen_ring_name) - 1,
+ "listen_rx_ring_%d", remote_port);
+ if (kernel_ip_match(addr) && rte_ring_lookup(listen_ring_name) == NULL) {
+ return true;
+ }
+
+ if (lwip_ip_route(addr)) {
+ return false;
+ }
+
+ if (kernel_ip_route(addr)) {
+ return true;
+ }
+
+ return false;
+}
+
static int32_t do_connect(int32_t s, const struct sockaddr *addr, socklen_t addrlen)
{
+ int32_t ret = 0;
+
if (addr == NULL) {
GAZELLE_RETURN(EINVAL);
}
@@ -350,30 +396,20 @@ static int32_t do_connect(int32_t s, const struct sockaddr *addr, socklen_t addr
return posix_api->connect_fn(s, addr, addrlen);
}
- int32_t ret = 0;
- int32_t remote_port;
- bool is_kernel = kernel_ip_route(addr);
- bool is_to_kernel_connect = is_relatived_kernel_ip(addr);
-
- remote_port = htons(((struct sockaddr_in *)addr)->sin_port);
-
- char listen_ring_name[RING_NAME_LEN];
- snprintf_s(listen_ring_name, sizeof(listen_ring_name), sizeof(listen_ring_name) - 1,
- "listen_rx_ring_%d", remote_port);
-
- if ((is_kernel && rte_ring_lookup(listen_ring_name) == NULL) || is_to_kernel_connect) {
+ if (should_enter_kernel_connect(addr)) {
ret = posix_api->connect_fn(s, addr, addrlen);
POSIX_SET_TYPE(sock, POSIX_KERNEL);
+ return ret;
+ }
+
+ /* When the socket is POSIX_LWIP_OR_KERNEL, connect to lwip first and then connect to kernel. */
+ ret = g_wrap_api->connect_fn(s, addr, addrlen);
+ if (ret == 0 || (ret != 0 && errno == EINPROGRESS)) {
+ POSIX_SET_TYPE(sock, POSIX_LWIP);
} else {
- /* When the socket is POSIX_LWIP_OR_KERNEL, connect to lwip first and then connect to kernel. */
- ret = g_wrap_api->connect_fn(s, addr, addrlen);
- if (ret == 0 || (ret != 0 && errno == EINPROGRESS)) {
- POSIX_SET_TYPE(sock, POSIX_LWIP);
- } else {
- ret = posix_api->connect_fn(s, addr, addrlen);
- if (ret == 0) {
- POSIX_SET_TYPE(sock, POSIX_KERNEL);
- }
+ ret = posix_api->connect_fn(s, addr, addrlen);
+ if (ret == 0) {
+ POSIX_SET_TYPE(sock, POSIX_KERNEL);
}
}
return ret;
--
2.33.0

View File

@ -2,14 +2,14 @@
Name: gazelle
Version: 1.0.2
Release: 73
Release: 80
Summary: gazelle is a high performance user-mode stack
License: MulanPSL-2.0
URL: https://gitee.com/openeuler/gazelle
Source0: %{name}-%{version}.tar.gz
BuildRequires: cmake gcc-c++
BuildRequires: lwip >= 2.2.0-51
BuildRequires: lwip >= 2.2.0-63
BuildRequires: dpdk-devel >= 19.11-23
BuildRequires: numactl-devel libpcap-devel libconfig-devel libboundscheck uthash-devel
%ifarch ppc64le
@ -17,7 +17,7 @@ BuildRequires: libarchive libarchive-devel
%endif
Requires: dpdk >= 19.11-23
Requires: numactl libpcap libconfig libboundscheck
Requires: numactl libpcap libconfig libboundscheck iproute
Patch9001: 0001-remove-unused-dpdk-dynamic-libraries.patch
Patch9002: 0002-gazelle_stat_pkts-gazelle_stat_low_power_info.patch
@ -296,6 +296,36 @@ Patch9276: 0276-Fix-annotation-errors.patch
Patch9277: 0277-remove-the-unused-return-variable.patch
Patch9278: 0278-add-SO_NUMA_ID-optname-for-adapting-opneGauss.patch
Patch9279: 0279-xdp-support-XDP_STATISTICS-by-posix_api-getsockopt_f.patch
Patch9280: 0280-interrupt-fix-timeout-events-cannot-be-counted.patch
Patch9281: 0281-remove-code-about-nobolck-mode-for-mysql.patch
Patch9282: 0282-LOG-Optimize-some-log-displays.patch
Patch9283: 0283-xdp-support-bind-no-cpu-mode.patch
Patch9284: 0284-support-auto-set-xdp-addr.patch
Patch9285: 0285-suport-kernel-accept-for-openGauss.patch
Patch9286: 0286-openGauss-support-kernel-accept4.patch
Patch9287: 0287-socket-init-wakeup-in-blocking-socket.patch
Patch9288: 0288-fix-socket-of-control-thread-is-overwirtten-due-to-a.patch
Patch9289: 0289-LWIP-adjust-position-of-shutdown-in-callback-of-conn.patch
Patch9290: 0290-Fix-the-wrong-spelling-description-in-the-notes-and-.patch
Patch9291: 0291-update-test-unitest-ltran-ltran_param_test.c.patch
Patch9292: 0292-fix-free-null-pointer-when-no-matching-device-is-fou.patch
Patch9293: 0293-cfg-show-dpdk-args-after-dpdk_adjust_args.patch
Patch9294: 0294-fix-build-error-in-2003SP4.patch
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
Patch9306: 0306-fix-a-contention-issue-when-rpc-pools-are-added-to-r.patch
Patch9307: 0307-openGauss-unsupport_tcp_optname.patch
Patch9308: 0308-kernerl-bind-add-ipv6-add-check.patch
Patch9309: 0309-Connect-execute-lwip-connect-if-dst_ip-and-host_ip-a.patch
%description
%{name} is a high performance user-mode stack.
@ -337,6 +367,50 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b
%config(noreplace) %{conf_path}/ltran.conf
%changelog
* Wed Dec 18 2024 yinbin6 <yinbin8@huawei.com> - 1.0.2-80
- Connect: execute lwip connect if dst_ip and host_ip are in the same network.
- kernerl bind: add ipv6 add check
- openGauss unsupport_tcp_optname
- fix a contention issue when rpc pools are added to rpc_pool_array
* 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
* Wed Nov 27 2024 yinbin <yinbin8@huawei.com> - 1.0.2-77
- openGauss: support kernel connnect
- xdp: support stack bind numa
- CFG: fix xdp iface check error
- fix build error in 2003SP4
- cfg: show dpdk args after dpdk_adjust_args
- fix free null pointer when no matching device is found
- update test/unitest/ltran/ltran_param_test.c.
- Fix the wrong spelling description in the notes and logs
- LWIP: adjust position of shutdown in callback of connect
- fix socket of control thread is overwirtten due to another primary process start
* Wed Nov 20 2024 yinbin <yinbin8@huawei.com> - 1.0.2-76
- socket: init wakeup in blocking socket
- openGauss: support kernel accept4
* Fri Nov 15 2024 yinbin <chengyechun1@huawei.com> - 1.0.2-75
- suport kernel accept for openGauss
- support auto set xdp addr
- xdp: support bind no cpu mode
* Fri Nov 08 2024 yinbin <jiangheng14@huawei.com> - 1.0.2-74
- LOG: Optimize some log displays
- remove: code about nobolck mode for mysql
- interrupt: fix timeout events cannot be counted
* Fri Nov 01 2024 hantwofish <yinbin8@huawei.com> - 1.0.2-73
- xdp: support XDP_STATISTICS by posix_api->getsockopt_fn
- add SO_NUMA_ID(optname) for adapting opneGauss
@ -486,6 +560,7 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b
- refacotr udp send
* Fri Jun 21 2024 yinbin6 <yinbin8@huawei.com> - 1.0.2-42
- [virtio]: create and init virtio_port
- refactor tx cache module
- cfg: bond_slave_mac support pci addr
- remove legacy-mem