diff --git a/0001-remove-unused-dpdk-dynamic-libraries.patch b/0001-remove-unused-dpdk-dynamic-libraries.patch deleted file mode 100644 index ec98466ec4c375a5d8eb50913f486d00a219a50f..0000000000000000000000000000000000000000 --- a/0001-remove-unused-dpdk-dynamic-libraries.patch +++ /dev/null @@ -1,93 +0,0 @@ -From dac81b016b6eccfc9f4061c22c1e78d36ca17f88 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 28 Jun 2023 10:30:48 +0800 -Subject: [PATCH] remove unused dpdk dynamic libraries - ---- - src/lstack/Makefile | 6 +----- - src/ltran/CMakeLists.txt | 42 +++++++++------------------------------- - 2 files changed, 10 insertions(+), 38 deletions(-) - -diff --git a/src/lstack/Makefile b/src/lstack/Makefile -index d9c8396..3550244 100644 ---- a/src/lstack/Makefile -+++ b/src/lstack/Makefile -@@ -98,12 +98,8 @@ else - $(LIB_PATH)/librte_net_i40e.so \ - $(LIB_PATH)/librte_net_ixgbe.so \ - $(LIB_PATH)/librte_net_virtio.so \ -- $(LIB_PATH)/librte_pcapng.so \ -- $(LIB_PATH)/librte_rcu.so \ - $(LIB_PATH)/librte_telemetry.so \ -- $(LIB_PATH)/librte_bpf.so \ -- $(LIB_PATH)/librte_security.so \ -- $(LIB_PATH)/librte_cryptodev.so -+ $(LIB_PATH)/librte_pcapng.so - endif - - DEP_LIBS = $(LWIP_LIB) $(LIBRTE_LIB) -diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt -index 1370dc8..b8d92b7 100644 ---- a/src/ltran/CMakeLists.txt -+++ b/src/ltran/CMakeLists.txt -@@ -30,29 +30,12 @@ endif($ENV{GAZELLE_COVERAGE_ENABLE}) - if($ENV{DPDK_VERSION_1911}) - set(DPDK_DIR /usr/include/dpdk) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDPDK_VERSION_1911=1") -- set(DPDK_LINK_FLAGS "-Wl,-lrte_pmd_af_packet -Wl,-lrte_pmd_ark -Wl,-lrte_pmd_atlantic -Wl,-lrte_pmd_axgbe \ -- -Wl,-lrte_pmd_bnxt -Wl,-lrte_pmd_bond -Wl,-lrte_pmd_cxgbe -Wl,-lrte_pmd_dpaa -Wl,-lrte_pmd_dpaa2 \ -- -Wl,-lrte_pmd_e1000 -Wl,-lrte_pmd_ena -Wl,-lrte_pmd_enetc -Wl,-lrte_pmd_enic -Wl,-lrte_pmd_failsafe \ -- -Wl,-lrte_pmd_i40e -Wl,-lrte_pmd_hinic -Wl,-lrte_pmd_ixgbe -Wl,-lrte_pmd_kni \ -- -Wl,-lrte_pmd_nfp -Wl,-lrte_pmd_null -Wl,-lpcap -Wl,-lrte_pmd_qede -Wl,-lrte_pmd_ring -Wl,-lrte_pmd_softnic \ -- -Wl,-lrte_pmd_pcap -Wl,-lrte_pmd_tap -Wl,-lrte_pmd_vdev_netvsc -Wl,-lrte_pmd_virtio -Wl,-lrte_pmd_vhost \ -- -Wl,-lrte_mempool_octeontx -Wl,-lrte_pmd_octeontx -Wl,-lrte_bus_vmbus -Wl,-lrte_pmd_netvsc \ -- -Wl,-lrte_pmd_vmxnet3_uio -Wl,-lrte_pmd_bbdev_null \ -- -Wl,-lrte_pmd_null_crypto -Wl,-lrte_pmd_octeontx_crypto -Wl,-lrte_pmd_crypto_scheduler \ -- -Wl,-lrte_pmd_dpaa2_sec -Wl,-lrte_pmd_dpaa_sec -Wl,-lrte_pmd_caam_jr -Wl,-lrte_pmd_virtio_crypto \ -- -Wl,-lrte_pmd_octeontx_zip -Wl,-lrte_pmd_qat -Wl,-lrte_pmd_skeleton_event -Wl,-lrte_pmd_sw_event \ -- -Wl,-lrte_pmd_dsw_event -Wl,-lrte_pmd_octeontx_ssovf -Wl,-lrte_pmd_dpaa_event -Wl,-lrte_pmd_dpaa2_event \ -- -Wl,-lrte_pmd_opdl_event -Wl,-lrte_pmd_lio -Wl,-lrte_pmd_thunderx_nicvf -Wl,-lrte_pmd_ifc") -+ set(DPDK_LINK_FLAGS "-Wl,-lrte_pmd_bond -Wl,-lrte_pmd_i40e -Wl,-lrte_pmd_hinic -Wl,-lrte_pmd_ixgbe \ -+ -Wl,-lrte_pmd_pcap -Wl,-lrte_pmd_virtio") - else() - set(DPDK_DIR /usr/local/include/) -- set(DPDK_LINK_FLAGS "-Wl,-lrte_net_af_packet -Wl,-lrte_net_ark -Wl,-lrte_net_atlantic -Wl,-lrte_net_axgbe \ -- -Wl,-lrte_net_bnxt -Wl,-lrte_net_bond -Wl,-lrte_net_cxgbe -Wl,-lrte_net_dpaa -Wl,-lrte_net_dpaa2 \ -- -Wl,-lrte_net_e1000 -Wl,-lrte_net_ena -Wl,-lrte_net_enetc -Wl,-lrte_net_enic -Wl,-lrte_net_failsafe \ -- -Wl,-lrte_net_i40e -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe -Wl,-lrte_net_kni \ -- -Wl,-lrte_net_nfp -Wl,-lrte_net_null -Wl,-lpcap -Wl,-lrte_net_qede -Wl,-lrte_net_ring -Wl,-lrte_net_softnic \ -- -Wl,-lrte_net_pcap -Wl,-lrte_net_tap -Wl,-lrte_net_vdev_netvsc -Wl,-lrte_net_virtio -Wl,-lrte_net_vhost \ -- -Wl,-lrte_mempool_octeontx -Wl,-lrte_net_octeontx -Wl,-lrte_bus_vmbus -Wl,-lrte_net_netvsc \ -- -Wl,-lrte_telemetry") -+ set(DPDK_LINK_FLAGS "-Wl,-lrte_net_bond -Wl,-lrte_net_i40e -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe \ -+ -Wl,-lpcap -Wl,-lrte_net_pcap -Wl,-lrte_net_virtio -Wl,-lrte_pcapng -Wl,-lrte_telemetry") - endif($ENV{DPDK_VERSION_1911}) - - add_executable(ltran main.c ltran_param.c ltran_config.c ltran_ethdev.c ltran_stat.c ltran_errno.c -@@ -69,18 +52,11 @@ target_compile_options(ltran PRIVATE -march=native -fno-strict-aliasing -D__ARM_ - -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough -D_FORTIFY_SOURCE=2) - - target_link_libraries(ltran PRIVATE config boundscheck rte_pdump -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines) --set_target_properties(ltran PROPERTIES LINK_FLAGS "-L$ENV{DPDK_LIB_PATH} -Wl,--whole-archive -Wl,-lrte_pipeline \ -- -Wl,--no-whole-archive -Wl,-lrte_table -Wl,--whole-archive -Wl,--no-whole-archive -Wl,--whole-archive -Wl,-lrte_port -Wl,--no-whole-archive \ -- -Wl,-lrte_distributor -Wl,-lrte_meter -Wl,-lrte_ip_frag -Wl,-lrte_lpm -Wl,--whole-archive -Wl,-lrte_acl -Wl,--no-whole-archive \ -- -Wl,-lrte_jobstats -Wl,-lrte_bitratestats -Wl,-lrte_metrics -Wl,-lrte_latencystats -Wl,-lrte_power -Wl,-lrte_efd -Wl,-lrte_bpf \ -- -Wl,--whole-archive -Wl,-lrte_gro -Wl,-lrte_cfgfile -Wl,-lrte_gso -Wl,-lrte_hash -Wl,-lrte_member -Wl,-lrte_vhost -Wl,-lrte_kvargs \ -- -Wl,-lrte_mbuf -Wl,-lrte_ethdev -Wl,-lrte_net -Wl,-lrte_bbdev -Wl,-lrte_cryptodev -Wl,-lrte_security -Wl,-lrte_compressdev -Wl,-lrte_eventdev \ -- -Wl,-lrte_rawdev -Wl,-lrte_timer -Wl,-lrte_mempool -Wl,-lrte_mempool_ring -Wl,-lrte_ring -Wl,-lrte_pci \ -- -Wl,-Bstatic -lrte_eal -Wl,-Bdynamic -Wl,-lrte_cmdline \ -- -Wl,-lrte_sched -Wl,-lrte_reorder -Wl,-lrte_kni -Wl,-lrte_common_cpt -Wl,-lrte_common_octeontx -Wl,-lrte_common_dpaax -Wl,-lrte_bus_pci \ -- -Wl,-lrte_bus_dpaa -Wl,-lrte_bus_vdev -Wl,-lrte_bus_fslmc -Wl,-lrte_mempool_bucket -Wl,-lrte_mempool_stack -Wl,-lrte_mempool_dpaa \ -- -Wl,-lrte_mempool_dpaa2 -Wl,-lrte_bus_ifpga -Wl,-lrte_stack \ -- ${DPDK_LINK_FLAGS} \ -+set_target_properties(ltran PROPERTIES LINK_FLAGS "-L$ENV{DPDK_LIB_PATH} -Wl,--no-whole-archive \ -+ -Wl,-lrte_meter -Wl,--whole-archive -Wl,-lrte_gro -Wl,-lrte_hash -Wl,-lrte_kvargs -Wl,-lrte_mbuf -Wl,-lrte_ethdev \ -+ -Wl,-lrte_net -Wl,-lrte_timer -Wl,-lrte_mempool -Wl,-lrte_mempool_ring -Wl,-lrte_ring -Wl,-lrte_pci \ -+ -Wl,-Bstatic -lrte_eal -Wl,-Bdynamic -Wl,-lrte_cmdline -Wl,-lrte_kni -Wl,-lrte_bus_pci \ -+ -Wl,-lrte_bus_vdev ${DPDK_LINK_FLAGS} \ - -Wl,--no-whole-archive -Wl,-lm -Wl,-lrt -Wl,-lnuma -Wl,-ldl -Wl,-export-dynamic -Wl,-export-dynamic \ - -Wl,--as-needed -Wl,-export-dynamic -Wl,-Map=ltran.map -Wl,--cref") - --- -2.23.0 - diff --git a/0002-gazelle_stat_pkts-gazelle_stat_low_power_info.patch b/0002-gazelle_stat_pkts-gazelle_stat_low_power_info.patch deleted file mode 100644 index 113b9b1885c404f8c0711eb55131dae260546866..0000000000000000000000000000000000000000 --- a/0002-gazelle_stat_pkts-gazelle_stat_low_power_info.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 8f477abc2530a4defc37d2e443eca19271c1b6b8 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?=E5=AD=99=E8=8B=8F=E7=9A=96?= -Date: Tue, 4 Apr 2023 09:19:48 +0000 -Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9gazelle=5Fstat=5Fpkts?= - =?UTF-8?q?=EF=BC=8Cgazelle=5Fstat=5Flow=5Fpower=5Finfo=E7=BB=93=E6=9E=84?= - =?UTF-8?q?=E4=BD=93=E6=88=90=E5=91=98=E9=A1=BA=E5=BA=8F=EF=BC=8C=E6=9D=A5?= - =?UTF-8?q?=E4=BD=BF=E7=BB=93=E6=9E=84=E4=BD=93=E5=A4=A7=E5=B0=8F=E5=8F=98?= - =?UTF-8?q?=E5=B0=8F?= -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Signed-off-by: 孙苏皖 ---- - src/common/gazelle_dfx_msg.h | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index e4da687..7ce8874 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -79,11 +79,11 @@ struct gazelle_wakeup_stat { - }; - - struct gazelle_stat_pkts { -- uint64_t call_msg_cnt; - uint16_t conn_num; -+ uint32_t mempool_freecnt; -+ uint64_t call_msg_cnt; - uint64_t recv_list_cnt; - uint64_t call_alloc_fail; -- uint32_t mempool_freecnt; - struct gazelle_stack_stat stack_stat; - struct gazelle_wakeup_stat wakeup_stat; - }; -@@ -194,9 +194,9 @@ struct gazelle_stack_latency { - - struct gazelle_stat_low_power_info { - uint16_t low_power_mod; -+ uint16_t lpm_rx_pkts; - uint32_t lpm_pkts_in_detect; - uint32_t lpm_detect_ms; -- uint16_t lpm_rx_pkts; - }; - - #define RTE_ETH_XSTATS_NAME_SIZE 64 --- -2.23.0 - diff --git a/0003-set-localhost-ip-when-bind-ip-is-same-as-ip-in-lstac.patch b/0003-set-localhost-ip-when-bind-ip-is-same-as-ip-in-lstac.patch deleted file mode 100644 index f89791ee17ff80b505a1ffd9b508ed80acc0a0f8..0000000000000000000000000000000000000000 --- a/0003-set-localhost-ip-when-bind-ip-is-same-as-ip-in-lstac.patch +++ /dev/null @@ -1,27 +0,0 @@ -From c13dd0c6ae71dd7547b9c1c6240585ae0f5c7c6b Mon Sep 17 00:00:00 2001 -From: chengyechun -Date: Tue, 11 Jul 2023 10:57:35 +0800 -Subject: [PATCH] set localhost ip when bind ip is same as ip in lstack.conf - ---- - 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 6a1a2c4..956d661 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -245,6 +245,10 @@ bool is_dst_ip_localhost(const struct sockaddr *addr) - char *p; - size_t linel = 0; - int linenum = 0; -+ if (get_global_cfg_params()->host_addr.addr == servaddr->sin_addr.s_addr) { -+ return true; -+ } -+ - FILE *ifh = fopen("/proc/net/dev", "r"); - if (ifh == NULL) { - LSTACK_LOG(ERR, LSTACK, "failed to open /proc/net/dev, errno is %d\n", errno); --- -2.23.0 - diff --git a/0004-refactoring-preload-module.patch b/0004-refactoring-preload-module.patch deleted file mode 100644 index 4f821163a5fb9d22cf33bd3e35c7baeba0334801..0000000000000000000000000000000000000000 --- a/0004-refactoring-preload-module.patch +++ /dev/null @@ -1,158 +0,0 @@ -From c2703d07662909f228e7e93ecec585bc4c826449 Mon Sep 17 00:00:00 2001 -From: yanan-rock -Date: Fri, 21 Jul 2023 08:34:53 +0000 -Subject: [PATCH] refactoring preload module - -Signed-off-by: yanan-rock ---- - src/lstack/core/lstack_init.c | 40 +-------------------- - src/lstack/core/lstack_preload.c | 55 +++++++++++++++++++++++++++++ - src/lstack/include/lstack_preload.h | 16 +++++++++ - 3 files changed, 72 insertions(+), 39 deletions(-) - create mode 100644 src/lstack/core/lstack_preload.c - create mode 100644 src/lstack/include/lstack_preload.h - -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 4fbbc14..53bc541 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -46,11 +46,7 @@ - #include "posix/lstack_unistd.h" - #include "gazelle_base_func.h" - #include "lstack_protocol_stack.h" -- --#define LSTACK_PRELOAD_ENV_SYS "LD_PRELOAD" --#define LSTACK_SO_NAME "liblstack.so" --#define LSTACK_PRELOAD_NAME_LEN PATH_MAX --#define LSTACK_PRELOAD_ENV_PROC "GAZELLE_BIND_PROCNAME" -+#include "lstack_preload.h" - - static volatile bool g_init_fail = false; - -@@ -64,40 +60,6 @@ bool get_init_fail(void) - return g_init_fail; - } - --struct lstack_preload { -- int32_t preload_switch; -- char env_procname[LSTACK_PRELOAD_NAME_LEN]; --}; --static struct lstack_preload g_preload_info = {0}; -- --static int32_t preload_info_init(void) --{ -- char *enval = NULL; -- -- g_preload_info.preload_switch = 0; -- -- enval = getenv(LSTACK_PRELOAD_ENV_SYS); -- if (enval == NULL) { -- return 0; -- } -- -- if (strstr(enval, LSTACK_SO_NAME) == NULL) { -- return 0; -- } -- -- enval = getenv(LSTACK_PRELOAD_ENV_PROC); -- if (enval == NULL) { -- return -1; -- } -- if (strcpy_s(g_preload_info.env_procname, LSTACK_PRELOAD_NAME_LEN, enval) != EOK) { -- return -1; -- } -- -- g_preload_info.preload_switch = 1; -- LSTACK_PRE_LOG(LSTACK_INFO, "LD_PRELOAD ok\n"); -- return 0; --} -- - static void check_process_start(void) - { - if (get_global_cfg_params()->is_primary) { -diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c -new file mode 100644 -index 0000000..9fc5819 ---- /dev/null -+++ b/src/lstack/core/lstack_preload.c -@@ -0,0 +1,55 @@ -+/* -+* 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 -+#include -+#include -+ -+#include "lstack_preload.h" -+ -+#define LSTACK_PRELOAD_ENV_SYS "LD_PRELOAD" -+#define LSTACK_SO_NAME "liblstack.so" -+#define LSTACK_PRELOAD_NAME_LEN PATH_MAX -+#define LSTACK_PRELOAD_ENV_PROC "GAZELLE_BIND_PROCNAME" -+ -+struct lstack_preload { -+ int32_t preload_switch; -+ char env_procname[LSTACK_PRELOAD_NAME_LEN]; -+}; -+static struct lstack_preload g_preload_info = {0}; -+ -+static int32_t preload_info_init(void) -+{ -+ char *enval = NULL; -+ -+ g_preload_info.preload_switch = 0; -+ -+ enval = getenv(LSTACK_PRELOAD_ENV_SYS); -+ if (enval == NULL) { -+ return 0; -+ } -+ -+ if (strstr(enval, LSTACK_SO_NAME) == NULL) { -+ return 0; -+ } -+ -+ enval = getenv(LSTACK_PRELOAD_ENV_PROC); -+ if (enval == NULL) { -+ return -1; -+ } -+ if (strcpy_s(g_preload_info.env_procname, LSTACK_PRELOAD_NAME_LEN, enval) != EOK) { -+ return -1; -+ } -+ -+ g_preload_info.preload_switch = 1; -+ LSTACK_PRE_LOG(LSTACK_INFO, "LD_PRELOAD ok\n"); -+ return 0; -+} -diff --git a/src/lstack/include/lstack_preload.h b/src/lstack/include/lstack_preload.h -new file mode 100644 -index 0000000..4ba6525 ---- /dev/null -+++ b/src/lstack/include/lstack_preload.h -@@ -0,0 +1,16 @@ -+/* -+* 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 __LSTACK_PRELOAD_H__ -+#define __LSTACK_PRELOAD_H__ -+ -+int preload_info_init(void); -+#endif --- -2.23.0 - diff --git a/0005-fix-previous-commit-refactoring-preload-module.patch b/0005-fix-previous-commit-refactoring-preload-module.patch deleted file mode 100644 index 566943575114474415db92fe8d02efa3a565d18a..0000000000000000000000000000000000000000 --- a/0005-fix-previous-commit-refactoring-preload-module.patch +++ /dev/null @@ -1,99 +0,0 @@ -From 6a5bb82feba31762f6c977e618bcee47a5f06d26 Mon Sep 17 00:00:00 2001 -From: yanan-rock -Date: Sun, 14 May 2023 15:02:58 -0400 -Subject: [PATCH] fix previous commit "refactoring preload module" - -Signed-off-by: yanan-rock ---- - src/lstack/core/lstack_init.c | 26 -------------------------- - src/lstack/core/lstack_preload.c | 25 ++++++++++++++++++++++++- - 2 files changed, 24 insertions(+), 27 deletions(-) - -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 53bc541..406a0b8 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -118,29 +118,6 @@ static int32_t check_process_conflict(void) - return 0; - } - --static int32_t check_preload_bind_proc(void) --{ -- char proc_path[PATH_MAX] = {0}; -- -- if (!g_preload_info.preload_switch) { -- return 0; -- } -- -- if (readlink("/proc/self/exe", proc_path, PATH_MAX - 1) <= 0) { -- return -1; -- } -- -- char *proc_name = strrchr(proc_path, '/'); -- if (!proc_name) { -- return -1; -- } -- -- if (strncmp(++proc_name, g_preload_info.env_procname, PATH_MAX) == 0) { -- return 0; -- } -- return -1; --} -- - __attribute__((destructor)) void gazelle_network_exit(void) - { - if (posix_api != NULL && !posix_api->ues_posix) { -@@ -262,9 +239,6 @@ __attribute__((constructor)) void gazelle_network_init(void) - if (preload_info_init() < 0) { - return; - } -- if (check_preload_bind_proc() < 0) { -- return; -- } - - /* Read configure from lstack.cfg */ - if (cfg_init() != 0) { -diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c -index 9fc5819..e04f49b 100644 ---- a/src/lstack/core/lstack_preload.c -+++ b/src/lstack/core/lstack_preload.c -@@ -26,6 +26,29 @@ struct lstack_preload { - }; - static struct lstack_preload g_preload_info = {0}; - -+static int32_t preload_check_bind_proc(void) -+{ -+ char proc_path[PATH_MAX] = {0}; -+ -+ if (!g_preload_info.preload_switch) { -+ return 0; -+ } -+ -+ if (readlink("/proc/self/exe", proc_path, PATH_MAX - 1) <= 0) { -+ return -1; -+ } -+ -+ char *proc_name = strrchr(proc_path, '/'); -+ if (!proc_name) { -+ return -1; -+ } -+ -+ if (strncmp(++proc_name, g_preload_info.env_procname, PATH_MAX) == 0) { -+ return 0; -+ } -+ return -1; -+} -+ - static int32_t preload_info_init(void) - { - char *enval = NULL; -@@ -51,5 +74,5 @@ static int32_t preload_info_init(void) - - g_preload_info.preload_switch = 1; - LSTACK_PRE_LOG(LSTACK_INFO, "LD_PRELOAD ok\n"); -- return 0; -+ return preload_check_bind_proc(); - } --- -2.23.0 - diff --git a/0006-add-lstack_preload.c-to-makefile.patch b/0006-add-lstack_preload.c-to-makefile.patch deleted file mode 100644 index 57887303f5a6761d177918e4115a3cfd3e3eab4a..0000000000000000000000000000000000000000 --- a/0006-add-lstack_preload.c-to-makefile.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 28cf0ab6a58444ee9e1fa36ce6d5b6aa6f37f5ad Mon Sep 17 00:00:00 2001 -From: yanan-rock -Date: Sun, 14 May 2023 21:47:21 -0400 -Subject: [PATCH] add lstack_preload.c to makefile fix compile failure - -Signed-off-by: yanan-rock ---- - src/lstack/core/dir.mk | 2 +- - src/lstack/core/lstack_preload.c | 5 ++++- - 2 files changed, 5 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/dir.mk b/src/lstack/core/dir.mk -index 88c1e08..e2d10a5 100644 ---- a/src/lstack/core/dir.mk -+++ b/src/lstack/core/dir.mk -@@ -8,6 +8,6 @@ - # PURPOSE. - # See the Mulan PSL v2 for more details. - --SRC = lstack_init.c lstack_cfg.c lstack_dpdk.c lstack_control_plane.c lstack_stack_stat.c lstack_lwip.c lstack_protocol_stack.c lstack_thread_rpc.c -+SRC = lstack_preload.c lstack_init.c lstack_cfg.c lstack_dpdk.c lstack_control_plane.c lstack_stack_stat.c lstack_lwip.c lstack_protocol_stack.c lstack_thread_rpc.c - $(eval $(call register_dir, core, $(SRC))) - -diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c -index e04f49b..e3a98fc 100644 ---- a/src/lstack/core/lstack_preload.c -+++ b/src/lstack/core/lstack_preload.c -@@ -13,6 +13,9 @@ - #include - #include - -+#include "securec.h" -+ -+#include "lstack_log.h" - #include "lstack_preload.h" - - #define LSTACK_PRELOAD_ENV_SYS "LD_PRELOAD" -@@ -49,7 +52,7 @@ static int32_t preload_check_bind_proc(void) - return -1; - } - --static int32_t preload_info_init(void) -+int preload_info_init(void) - { - char *enval = NULL; - --- -2.23.0 - diff --git a/0007-cosmetic-changes.patch b/0007-cosmetic-changes.patch deleted file mode 100644 index 7f134fa57504191d5a736026a6f5d93b560b3a28..0000000000000000000000000000000000000000 --- a/0007-cosmetic-changes.patch +++ /dev/null @@ -1,67 +0,0 @@ -From 52e6a745e4b5bf27de66b55283c0e0f474213258 Mon Sep 17 00:00:00 2001 -From: Honggang LI -Date: Mon, 21 Aug 2023 08:48:00 +0800 -Subject: [PATCH] cosmetic changes - -Signed-off-by: Honggang LI ---- - src/lstack/core/lstack_init.c | 2 +- - src/lstack/core/lstack_lwip.c | 1 - - src/lstack/include/lstack_cfg.h | 2 +- - src/ltran/ltran_dfx.c | 2 +- - 4 files changed, 3 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 406a0b8..db203d2 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -256,7 +256,7 @@ __attribute__((constructor)) void gazelle_network_init(void) - return; - } - -- /* check lstack num, and get process idx */ -+ /* check lstack num */ - if (check_params_from_primary() < 0) { - LSTACK_PRE_LOG(LSTACK_ERR, "lstack num error, not same to primary process!\n"); - LSTACK_EXIT(1, "lstack num error, not same to primary process!\n"); -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index c1346f6..bcdbac0 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -1239,7 +1239,6 @@ static inline void clone_lwip_socket_opt(struct lwip_sock *dst_sock, struct lwip - dst_sock->conn->pcb.tcp->netif_idx = src_sock->conn->pcb.tcp->netif_idx; - dst_sock->conn->pcb.tcp->flags = src_sock->conn->pcb.tcp->flags; - dst_sock->conn->pcb.tcp->keep_idle = src_sock->conn->pcb.tcp->keep_idle; -- dst_sock->conn->pcb.tcp->keep_idle = src_sock->conn->pcb.tcp->keep_idle; - dst_sock->conn->pcb.tcp->keep_intvl = src_sock->conn->pcb.tcp->keep_intvl; - dst_sock->conn->pcb.tcp->keep_cnt = src_sock->conn->pcb.tcp->keep_cnt; - } -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 9102fee..52a1abd 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -82,7 +82,7 @@ struct cfg_params { - uint32_t read_connect_number; - uint32_t rpc_number; - uint32_t nic_read_number; -- uint8_t use_ltran; // ture:lstack read from nic false:read form ltran -+ uint8_t use_ltran; // false:lstack read from nic. true:lstack read form ltran process. - - uint16_t num_process; - uint16_t num_listen_port; -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index b8d9c99..e5fd0c8 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -836,7 +836,7 @@ static void gazelle_print_lstack_stat_snmp_core(const struct gazelle_stack_dfx_d - printf("ip_in_deliver: %u\n", snmp->ip_in_deliver); - printf("ip_out_req: %u\n", snmp->ip_out_req); - printf("ip_out_discard: %u\n", snmp->ip_out_discard); -- printf("ip_outnort: %u\n", snmp->ip_out_discard); -+ printf("ip_outnort: %u\n", snmp->ip_outnort); - printf("ip_reasm_ok: %u\n", snmp->ip_reasm_ok); - printf("ip_reasm_fail: %u\n", snmp->ip_reasm_fail); - printf("ip_frag_ok: %u\n", snmp->ip_frag_ok); --- -2.27.0 - diff --git a/0008-add-loongarch64-and-sw64-arch-support.patch b/0008-add-loongarch64-and-sw64-arch-support.patch deleted file mode 100644 index e5703bd94a120eb66f48de61b975c8eb7998149d..0000000000000000000000000000000000000000 --- a/0008-add-loongarch64-and-sw64-arch-support.patch +++ /dev/null @@ -1,120 +0,0 @@ -From 7b2803bfe36e6ca19d4389d28c5d9f15dcbe95e8 Mon Sep 17 00:00:00 2001 -From: herengui -Date: Wed, 30 Aug 2023 15:41:03 +0800 -Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BE=99=E8=8A=AF=E5=92=8C?= - =?UTF-8?q?=E7=94=B3=E5=A8=81=E6=9E=B6=E6=9E=84=E6=94=AF=E6=8C=81?= -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Signed-off-by: herengui ---- - src/lstack/Makefile | 9 +++++++-- - src/ltran/CMakeLists.txt | 17 +++++++++++++---- - test/unitest/ltran/CMakeLists.txt | 5 ++++- - 3 files changed, 24 insertions(+), 7 deletions(-) - -diff --git a/src/lstack/Makefile b/src/lstack/Makefile -index 3550244..8f684ba 100644 ---- a/src/lstack/Makefile -+++ b/src/lstack/Makefile -@@ -26,6 +26,7 @@ CC ?= gcc - OPTIMIZATION = -O2 -g - RM = rm -f - LDFLAGS = -shared -ldl -lm -lpthread -lrt -lnuma -lconfig -lboundscheck -+ARCH := $(shell uname -m) - - ifneq ($(CC),clang) - SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro, -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIFY_SOURCE=2 -@@ -88,18 +89,22 @@ ifeq ($(DPDK_VERSION_1911), 1) - LIBRTE_LIB += $(LIB_PATH)/librte_pmd_pcap.so \ - $(LIB_PATH)/librte_pmd_bond.so \ - $(LIB_PATH)/librte_pmd_hinic.so \ -- $(LIB_PATH)/librte_pmd_i40e.so \ - $(LIB_PATH)/librte_pmd_ixgbe.so \ - $(LIB_PATH)/librte_pmd_virtio.so -+ ifneq ($(ARCH), loongarch64) -+ LIBRTE_LIB += $(LIB_PATH)/librte_pmd_i40e.so -+ endif - else - LIBRTE_LIB += $(LIB_PATH)/librte_net_pcap.so \ - $(LIB_PATH)/librte_net_bond.so \ - $(LIB_PATH)/librte_net_hinic.so \ -- $(LIB_PATH)/librte_net_i40e.so \ - $(LIB_PATH)/librte_net_ixgbe.so \ - $(LIB_PATH)/librte_net_virtio.so \ - $(LIB_PATH)/librte_telemetry.so \ - $(LIB_PATH)/librte_pcapng.so -+ ifneq ($(ARCH), loongarch64) -+ LIBRTE_LIB += $(LIB_PATH)/librte_net_i40e.so -+ endif - endif - - DEP_LIBS = $(LWIP_LIB) $(LIBRTE_LIB) -diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt -index b8d92b7..e098a77 100644 ---- a/src/ltran/CMakeLists.txt -+++ b/src/ltran/CMakeLists.txt -@@ -30,12 +30,18 @@ endif($ENV{GAZELLE_COVERAGE_ENABLE}) - if($ENV{DPDK_VERSION_1911}) - set(DPDK_DIR /usr/include/dpdk) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDPDK_VERSION_1911=1") -- set(DPDK_LINK_FLAGS "-Wl,-lrte_pmd_bond -Wl,-lrte_pmd_i40e -Wl,-lrte_pmd_hinic -Wl,-lrte_pmd_ixgbe \ -+ set(DPDK_LINK_FLAGS "-Wl,-lrte_pmd_bond -Wl,-lrte_pmd_hinic -Wl,-lrte_pmd_ixgbe \ - -Wl,-lrte_pmd_pcap -Wl,-lrte_pmd_virtio") -+ if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "loongarch64") -+ set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-lrte_pmd_i40e") -+ endif() - else() - set(DPDK_DIR /usr/local/include/) -- set(DPDK_LINK_FLAGS "-Wl,-lrte_net_bond -Wl,-lrte_net_i40e -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe \ -+ set(DPDK_LINK_FLAGS "-Wl,-lrte_net_bond -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe \ - -Wl,-lpcap -Wl,-lrte_net_pcap -Wl,-lrte_net_virtio -Wl,-lrte_pcapng -Wl,-lrte_telemetry") -+ if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "loongarch64") -+ set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-lrte_net_i40e") -+ endif() - endif($ENV{DPDK_VERSION_1911}) - - add_executable(ltran main.c ltran_param.c ltran_config.c ltran_ethdev.c ltran_stat.c ltran_errno.c -@@ -44,12 +50,15 @@ add_executable(ltran main.c ltran_param.c ltran_config.c ltran_ethdev.c ltran_st - ${COMMON_DIR}/gazelle_parse_config.c) - - target_include_directories(ltran PRIVATE ${COMMON_DIR} ${PROJECT_SOURCE_DIR} ${LWIP_DIR} ${DPDK_DIR}) --target_compile_options(ltran PRIVATE -march=native -fno-strict-aliasing -D__ARM_FEATURE_CRC32=1 -DRTE_MACHINE_CPUFLAG_NEON -+target_compile_options(ltran PRIVATE -fno-strict-aliasing -D__ARM_FEATURE_CRC32=1 -DRTE_MACHINE_CPUFLAG_NEON - -DRTE_MACHINE_CPUFLAG_CRC32 -DRTE_MACHINE_CPUFLAG_PMULL -DRTE_MACHINE_CPUFLAG_AES - -DRTE_MACHINE_CPUFLAG_SHA1 -DRTE_MACHINE_CPUFLAG_SHA2 -include rte_config.h - -D_GNU_SOURCE -W -Wall -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition -- -Wpointer-arith -Wcast-align -Wcast-qual -Wnested-externs -Wformat-nonliteral -Wformat-security -Wundef -+ -Wpointer-arith -Wcast-qual -Wnested-externs -Wformat-nonliteral -Wformat-security -Wundef - -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough -D_FORTIFY_SOURCE=2) -+if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "sw_64") -+ target_compile_options(ltran PRIVATE -march=native -Wcast-align) -+endif() - - target_link_libraries(ltran PRIVATE config boundscheck rte_pdump -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines) - set_target_properties(ltran PROPERTIES LINK_FLAGS "-L$ENV{DPDK_LIB_PATH} -Wl,--no-whole-archive \ -diff --git a/test/unitest/ltran/CMakeLists.txt b/test/unitest/ltran/CMakeLists.txt -index 9496053..60bda83 100644 ---- a/test/unitest/ltran/CMakeLists.txt -+++ b/test/unitest/ltran/CMakeLists.txt -@@ -47,12 +47,15 @@ set_target_properties(ltran_test PROPERTIES LINK_FLAGS "-L$ENV{DPDK_LIB_PATH} -W - -Wl,-lrte_bus_dpaa -Wl,-lrte_bus_vdev -Wl,-lrte_bus_fslmc -Wl,-lrte_mempool_bucket -Wl,-lrte_mempool_stack -Wl,-lrte_mempool_dpaa \ - -Wl,-lrte_mempool_dpaa2 -Wl,-lrte_net_af_packet -Wl,-lrte_net_ark -Wl,-lrte_net_atlantic -Wl,-lrte_net_axgbe \ - -Wl,-lrte_net_bnxt -Wl,-lrte_net_bond -Wl,-lrte_net_cxgbe -Wl,-lrte_net_dpaa -Wl,-lrte_net_dpaa2 -Wl,-lrte_net_e1000 -Wl,-lrte_net_ena \ -- -Wl,-lrte_net_enetc -Wl,-lrte_net_enic -Wl,-lrte_net_failsafe -Wl,-lrte_net_i40e -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe -Wl,-lrte_net_kni \ -+ -Wl,-lrte_net_enetc -Wl,-lrte_net_enic -Wl,-lrte_net_failsafe -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe -Wl,-lrte_net_kni \ - -Wl,-lrte_net_nfp -Wl,-lrte_net_null -Wl,-lpcap -Wl,-lrte_net_qede -Wl,-lrte_net_ring -Wl,-lrte_net_softnic \ - -Wl,-lrte_net_tap -Wl,-lrte_net_vdev_netvsc -Wl,-lrte_net_virtio -Wl,-lrte_net_vhost \ - -Wl,-lrte_bus_vmbus -Wl,-lrte_net_netvsc -Wl,-lrte_mempool_octeontx -Wl,-lrte_net_octeontx \ - -Wl,-lrte_bus_ifpga -Wl,-lrte_stack -Wl,-lrte_telemetry\ - -Wl,--no-whole-archive -Wl,-lm -Wl,-lrt -Wl,-lnuma -Wl,-ldl -Wl,-export-dynamic -Wl,-export-dynamic \ - -Wl,--as-needed -Wl,-export-dynamic -Wl,-Map=ltran.map -Wl,--cref") -+if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "loongarch64") -+ set_target_properties(ltran_test PROPERTIES LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lrte_net_i40e") -+endif() - target_include_directories(ltran_test PRIVATE ${LIB_PATH}) - target_link_libraries(ltran_test PRIVATE config boundscheck cunit pthread) --- -2.27.0 - diff --git a/0009-CFG-fixed-the-dpdk-primary-default-parameter.patch b/0009-CFG-fixed-the-dpdk-primary-default-parameter.patch deleted file mode 100644 index 66b2a91e8338c2ac1eb2d87760bf89111a844316..0000000000000000000000000000000000000000 --- a/0009-CFG-fixed-the-dpdk-primary-default-parameter.patch +++ /dev/null @@ -1,39 +0,0 @@ -From d8d70edfd8d5fc7ac617671c5ac8fe8364727e29 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Thu, 7 Sep 2023 19:55:58 +0800 -Subject: [PATCH] CFG:fixed the dpdk primary default parameter - ---- - src/lstack/core/lstack_cfg.c | 9 +++++---- - 1 file changed, 5 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 32d63b9..9fc16dd 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -770,6 +770,8 @@ static int32_t parse_dpdk_args(void) - } - start_index = 1; - -+ struct cfg_params *global_params = get_global_cfg_params(); -+ global_params->is_primary = 1; - for (i = 0; i < g_config_params.dpdk_argc; i++) { - arg = config_setting_get_string_elem(args, i); - if (arg == NULL) -@@ -780,10 +782,9 @@ static int32_t parse_dpdk_args(void) - } - g_config_params.dpdk_argv[start_index + i] = p; - -- const char *primary = "primary"; -- if (strcmp(p, primary) == 0) { -- struct cfg_params *global_params = get_global_cfg_params(); -- global_params->is_primary = 1; -+ const char *secondary = "secondary"; -+ if (strcmp(p, secondary) == 0) { -+ global_params->is_primary = 0; - } - - (void)fprintf(stderr, "%s ", g_config_params.dpdk_argv[start_index + i]); --- -2.27.0 - diff --git a/0010-suport-clang-build.patch b/0010-suport-clang-build.patch deleted file mode 100644 index 57d3f17e348056b3da0517528444204febccf517..0000000000000000000000000000000000000000 --- a/0010-suport-clang-build.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 655bcc55ae2045b1a457f7b654569361ea32bfc2 Mon Sep 17 00:00:00 2001 -From: luofeng14 -Date: Tue, 12 Sep 2023 02:05:34 +0000 -Subject: [PATCH] suport clang build - -Signed-off-by: luofeng14 ---- - src/lstack/Makefile | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/Makefile b/src/lstack/Makefile -index 8f684ba..30965f8 100644 ---- a/src/lstack/Makefile -+++ b/src/lstack/Makefile -@@ -40,7 +40,7 @@ INC = -I$(LSTACK_DIR)/include \ - -I$(LWIP_INCLUDE_FILE) \ - -I$(DPDK_INCLUDE_FILE) - --CFLAGS = $(OPTIMIZATION) -fno-strict-aliasing $(INC) -+CFLAGS += $(OPTIMIZATION) -fno-strict-aliasing $(INC) -Wno-error=unused-function - - ifeq ($(GAZELLE_COVERAGE_ENABLE), 1) - LDFLAGS += -fprofile-arcs -ftest-coverage --- -2.27.0 - diff --git a/0011-ethdev-fix-pbuf-chain-tot_len-incorrect.patch b/0011-ethdev-fix-pbuf-chain-tot_len-incorrect.patch deleted file mode 100644 index a98e0a6425e26b484054e49c5d49d32be9778a40..0000000000000000000000000000000000000000 --- a/0011-ethdev-fix-pbuf-chain-tot_len-incorrect.patch +++ /dev/null @@ -1,25 +0,0 @@ -From d98cb71e63fed73197334b373cfb979b6a47e1ea Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Fri, 15 Sep 2023 10:16:19 +0800 -Subject: [PATCH] ethdev: fix pbuf chain tot_len incorrect p->tot_len = p->len - + (p->next ? p->next->tot_len : 0) - ---- - src/lstack/netif/lstack_ethdev.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 3ea8e52..e3e823b 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -96,6 +96,7 @@ void eth_dev_recv(struct rte_mbuf *mbuf, struct protocol_stack *stack) - break; - } - next->tot_len = pkt_len; -+ pkt_len -= len; - #if CHECKSUM_CHECK_IP_HW || CHECKSUM_CHECK_TCP_HW - next->ol_flags = m->ol_flags; - #endif --- -2.27.0 - diff --git a/0012-kernelevent-kernel-event-thread-report-kernel-events.patch b/0012-kernelevent-kernel-event-thread-report-kernel-events.patch deleted file mode 100644 index ccfb33aa5299330f3e5c7140cf809a5584c73b97..0000000000000000000000000000000000000000 --- a/0012-kernelevent-kernel-event-thread-report-kernel-events.patch +++ /dev/null @@ -1,105 +0,0 @@ -From 4267e381b25e42f19b2dd160fbf08efb5d8bd0fb Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 4 Sep 2023 11:16:12 +0800 -Subject: [PATCH] kernelevent: kernel event thread report kernel events to app - thread directly without passing through lstack thread - ---- - src/lstack/core/lstack_protocol_stack.c | 53 +++++++++++++------------ - 1 file changed, 27 insertions(+), 26 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 3a6e792..ca0b046 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -38,7 +38,7 @@ - #include "lstack_stack_stat.h" - #include "lstack_protocol_stack.h" - --#define KERNEL_EVENT_100us 100 -+#define KERNEL_EVENT_10us 10 - - static PER_THREAD struct protocol_stack *g_stack_p = NULL; - static struct protocol_stack_group g_stack_group = {0}; -@@ -258,6 +258,29 @@ static int32_t create_thread(void *arg, char *thread_name, stack_thread_func fun - return 0; - } - -+static void wakeup_kernel_event(struct protocol_stack *stack) -+{ -+ if (stack->kernel_event_num <= 0) { -+ return; -+ } -+ -+ for (int32_t i = 0; i < stack->kernel_event_num; i++) { -+ struct wakeup_poll *wakeup = stack->kernel_events[i].data.ptr; -+ if (wakeup->type == WAKEUP_CLOSE) { -+ continue; -+ } -+ -+ __atomic_store_n(&wakeup->have_kernel_event, true, __ATOMIC_RELEASE); -+ if (__atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { -+ __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -+ rte_mb(); -+ pthread_mutex_unlock(&wakeup->wait); -+ } -+ } -+ -+ return; -+} -+ - static void* gazelle_kernelevent_thread(void *arg) - { - struct thread_params *t_params = (struct thread_params*) arg; -@@ -272,8 +295,9 @@ static void* gazelle_kernelevent_thread(void *arg) - - for (;;) { - stack->kernel_event_num = posix_api->epoll_wait_fn(stack->epollfd, stack->kernel_events, KERNEL_EPOLL_MAX, -1); -- while (stack->kernel_event_num > 0) { -- usleep(KERNEL_EVENT_100us); -+ if (stack->kernel_event_num > 0) { -+ wakeup_kernel_event(stack); -+ usleep(KERNEL_EVENT_10us); - } - } - -@@ -416,28 +440,6 @@ END1: - return NULL; - } - --static void wakeup_kernel_event(struct protocol_stack *stack) --{ -- if (stack->kernel_event_num == 0) { -- return; -- } -- -- for (int32_t i = 0; i < stack->kernel_event_num; i++) { -- struct wakeup_poll *wakeup = stack->kernel_events[i].data.ptr; -- if (wakeup->type == WAKEUP_CLOSE) { -- continue; -- } -- -- __atomic_store_n(&wakeup->have_kernel_event, true, __ATOMIC_RELEASE); -- if (list_is_null(&wakeup->wakeup_list[stack->stack_idx])) { -- list_add_node(&stack->wakeup_list, &wakeup->wakeup_list[stack->stack_idx]); -- } -- } -- -- stack->kernel_event_num = 0; --} -- -- - static void* gazelle_stack_thread(void *arg) - { - struct thread_params *t_params = (struct thread_params*) arg; -@@ -485,7 +487,6 @@ static void* gazelle_stack_thread(void *arg) - read_recv_list(stack, read_connect_number); - - if ((wakeup_tick & 0xf) == 0) { -- wakeup_kernel_event(stack); - wakeup_stack_epoll(stack); - } - --- -2.27.0 - diff --git a/0013-fix-bond-port-reta_size-init.patch b/0013-fix-bond-port-reta_size-init.patch deleted file mode 100644 index 16df1f61f5a10548b1d990563ce3f8350a27fb2b..0000000000000000000000000000000000000000 --- a/0013-fix-bond-port-reta_size-init.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 2151d99ea4b19492543c5c05b3b1cc5ed6db316c Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Tue, 26 Sep 2023 01:29:21 +0000 -Subject: [PATCH] fix bond port reta_size init - ---- - src/lstack/core/lstack_dpdk.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index cd42047..6384439 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -552,6 +552,7 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - } - dev_info.rx_offload_capa = slave_dev_info.rx_offload_capa; - dev_info.tx_offload_capa = slave_dev_info.tx_offload_capa; -+ dev_info.reta_size = slave_dev_info.reta_size; - } - - eth_params_checksum(ð_params->conf, &dev_info); --- -2.27.0 - diff --git a/0014-init-remove-sync-sem-between-lstack-thread-and-main-.patch b/0014-init-remove-sync-sem-between-lstack-thread-and-main-.patch deleted file mode 100644 index d06b3ce979f668f639c17737713cb70ed1dc0990..0000000000000000000000000000000000000000 --- a/0014-init-remove-sync-sem-between-lstack-thread-and-main-.patch +++ /dev/null @@ -1,383 +0,0 @@ -From a0371ba4a351362d7a804d10ed1ee80884da0d85 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sat, 7 Oct 2023 21:35:52 +0800 -Subject: [PATCH] init: remove sync sem between lstack thread and main thread - ---- - src/lstack/core/lstack_dpdk.c | 14 --- - src/lstack/core/lstack_init.c | 26 +--- - src/lstack/core/lstack_protocol_stack.c | 133 +++++++-------------- - src/lstack/include/lstack_protocol_stack.h | 7 +- - 4 files changed, 51 insertions(+), 129 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index cd42047..d848275 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -568,18 +568,6 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - stack_group->nb_queues = nb_queues; - - if (get_global_cfg_params()->is_primary) { -- for (uint32_t i = 0; i < stack_group->stack_num; i++) { -- struct protocol_stack *stack = stack_group->stacks[i]; -- if (likely(stack)) { -- stack->port_id = stack_group->port_id; -- } else { -- LSTACK_LOG(ERR, LSTACK, "empty stack at stack_num %d\n", i); -- stack_group->eth_params = NULL; -- free(eth_params); -- return -EINVAL; -- } -- } -- - ret = rte_eth_dev_configure(port_id, nb_queues, nb_queues, ð_params->conf); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "cannot config eth dev at port %d: %s\n", port_id, rte_strerror(-ret)); -@@ -760,8 +748,6 @@ int32_t init_dpdk_ethdev(void) - } - } - -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- sem_post(&stack_group->ethdev_init); - return 0; - } - -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index db203d2..2183e3a 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -48,18 +48,6 @@ - #include "lstack_protocol_stack.h" - #include "lstack_preload.h" - --static volatile bool g_init_fail = false; -- --void set_init_fail(void) --{ -- g_init_fail = true; --} -- --bool get_init_fail(void) --{ -- return g_init_fail; --} -- - static void check_process_start(void) - { - if (get_global_cfg_params()->is_primary) { -@@ -286,8 +274,8 @@ __attribute__((constructor)) void gazelle_network_init(void) - lstack_log_level_init(); - lstack_prelog_uninit(); - -- if (init_protocol_stack() != 0) { -- LSTACK_EXIT(1, "init_protocol_stack failed\n"); -+ if (stack_group_init() != 0) { -+ LSTACK_EXIT(1, "stack_group_init failed\n"); - } - - if (!use_ltran()) { -@@ -296,15 +284,13 @@ __attribute__((constructor)) void gazelle_network_init(void) - } - } - -+ if (stack_thread_setup() != 0) { -+ LSTACK_EXIT(1, "stack_init_in_setup failed\n"); -+ } -+ - /* lwip initialization */ - lwip_sock_init(); - -- /* wait stack thread and kernel_event thread init finish */ -- wait_sem_value(&get_protocol_stack_group()->all_init, get_protocol_stack_group()->stack_num); -- if (g_init_fail) { -- LSTACK_EXIT(1, "stack thread or kernel_event thread failed\n"); -- } -- - if (get_global_cfg_params()->kni_switch) { - set_kni_ip_mac(); - } -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index ca0b046..8071bda 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -43,8 +43,6 @@ - static PER_THREAD struct protocol_stack *g_stack_p = NULL; - static struct protocol_stack_group g_stack_group = {0}; - --void set_init_fail(void); --bool get_init_fail(void); - typedef void *(*stack_thread_func)(void *arg); - - -@@ -286,12 +284,11 @@ static void* gazelle_kernelevent_thread(void *arg) - struct thread_params *t_params = (struct thread_params*) arg; - uint16_t idx = t_params->idx; - struct protocol_stack *stack = get_protocol_stack_group()->stacks[idx]; -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); - -- sem_post(&stack_group->thread_phase1); - bind_to_stack_numa(stack); - - LSTACK_LOG(INFO, LSTACK, "kernelevent_%02hu start\n", idx); -+ free(arg); - - for (;;) { - stack->kernel_event_num = posix_api->epoll_wait_fn(stack->epollfd, stack->kernel_events, KERNEL_EPOLL_MAX, -1); -@@ -311,6 +308,7 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) - - stack->tid = rte_gettid(); - stack->queue_id = t_params->queue_id; -+ stack->port_id = stack_group->port_id; - stack->stack_idx = t_params->idx; - stack->lwip_stats = &lwip_stats; - -@@ -370,7 +368,12 @@ void wait_sem_value(sem_t *sem, int32_t wait_value) - - static int32_t create_affiliate_thread(void *arg) - { -- if (create_thread(arg, "gazellekernel", gazelle_kernelevent_thread) != 0) { -+ struct thread_params *params = malloc(sizeof(struct thread_params)); -+ if (params == NULL) { -+ return -1; -+ } -+ memcpy_s(params, sizeof(*params), arg, sizeof(struct thread_params)); -+ if (create_thread((void *)params, "gazellekernel", gazelle_kernelevent_thread) != 0) { - LSTACK_LOG(ERR, LSTACK, "gazellekernel errno=%d\n", errno); - return -1; - } -@@ -380,60 +383,49 @@ static int32_t create_affiliate_thread(void *arg) - - static struct protocol_stack *stack_thread_init(void *arg) - { -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); - struct protocol_stack *stack = calloc(1, sizeof(*stack)); - if (stack == NULL) { - LSTACK_LOG(ERR, LSTACK, "malloc stack failed\n"); -- goto END2; -+ goto END; - } - - if (init_stack_value(stack, arg) != 0) { -- goto END2; -+ goto END; - } - - if (init_stack_numa_cpuset(stack) < 0) { -- goto END2; -+ goto END; - } - if (create_affiliate_thread(arg) < 0) { -- goto END2; -+ goto END; - } - - if (thread_affinity_init(stack->cpu_id) != 0) { -- goto END1; -+ goto END; - } - RTE_PER_LCORE(_lcore_id) = stack->cpu_id; - - if (hugepage_init() != 0) { - LSTACK_LOG(ERR, LSTACK, "hugepage init failed\n"); -- goto END1; -+ goto END; - } - - tcpip_init(NULL, NULL); - - if (use_ltran()) { - if (client_reg_thrd_ring() != 0) { -- goto END1; -+ goto END; - } - } - -- sem_post(&stack_group->thread_phase1); -- -- if (!use_ltran()) { -- wait_sem_value(&stack_group->ethdev_init, 1); -- } -- - usleep(SLEEP_US_BEFORE_LINK_UP); - - if (ethdev_init(stack) != 0) { -- goto END1; -+ goto END; - } - - return stack; --/* kernel event thread dont create, stack thread post sem twice */ --END2: -- sem_post(&stack_group->thread_phase1); --END1: -- sem_post(&stack_group->thread_phase1); -+END: - if (stack != NULL) { - free(stack); - } -@@ -453,23 +445,19 @@ static void* gazelle_stack_thread(void *arg) - uint32_t rpc_number = cfg->rpc_number; - uint32_t nic_read_number = cfg->nic_read_number; - uint32_t wakeup_tick = 0; -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); - - struct protocol_stack *stack = stack_thread_init(arg); - -+ free(arg); - if (stack == NULL) { -- /* exit in main thread, avoid create mempool and exit at the same time */ -- set_init_fail(); -- sem_post(&stack_group->all_init); - LSTACK_LOG(ERR, LSTACK, "stack_thread_init failed queue_id=%hu\n", queue_id); -- return NULL; -+ /* exit in signal thread */ -+ raise(SIGTERM); - } - if (!use_ltran() && queue_id == 0) { - init_listen_and_user_ports(); - } - -- sem_post(&stack_group->all_init); -- - LSTACK_LOG(INFO, LSTACK, "stack_%02hu init success\n", queue_id); - - for (;;) { -@@ -517,40 +505,9 @@ static void libnet_listen_thread(void *arg) - recv_pkts_from_other_process(cfg_param->process_idx, arg); - } - --static int32_t init_protocol_sem(void) -+int32_t stack_group_init(void) - { -- int32_t ret; - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- -- if (!use_ltran()) { -- ret = sem_init(&stack_group->ethdev_init, 0, 0); -- if (ret < 0) { -- LSTACK_LOG(ERR, PORT, "sem_init failed ret=%d errno=%d\n", ret, errno); -- return -1; -- } -- } -- -- ret = sem_init(&stack_group->thread_phase1, 0, 0); -- if (ret < 0) { -- LSTACK_LOG(ERR, PORT, "sem_init failed ret=%d errno=%d\n", ret, errno); -- return -1; -- } -- -- ret = sem_init(&stack_group->all_init, 0, 0); -- if (ret < 0) { -- LSTACK_LOG(ERR, PORT, "sem_init failed ret=%d errno=%d\n", ret, errno); -- return -1; -- } -- -- return 0; --} -- --int32_t init_protocol_stack(void) --{ -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- int32_t ret; -- char name[PATH_MAX]; -- - if (!get_global_cfg_params()->seperate_send_recv) { - stack_group->stack_num = get_global_cfg_params()->num_cpu; - } else { -@@ -560,13 +517,6 @@ int32_t init_protocol_stack(void) - init_list_node(&stack_group->poll_list); - pthread_spin_init(&stack_group->poll_list_lock, PTHREAD_PROCESS_PRIVATE); - pthread_spin_init(&stack_group->socket_lock, PTHREAD_PROCESS_PRIVATE); -- -- if (init_protocol_sem() != 0) { -- return -1; -- } -- int queue_num = get_global_cfg_params()->num_queue; -- struct thread_params *t_params[queue_num]; -- int process_index = get_global_cfg_params()->process_idx; - - if (get_global_cfg_params()->is_primary) { - uint32_t total_mbufs = get_global_cfg_params()->mbuf_count_per_conn * get_global_cfg_params()->tcp_conn_count; -@@ -580,6 +530,27 @@ int32_t init_protocol_stack(void) - } - } - -+ if (!use_ltran()) { -+ char name[PATH_MAX]; -+ sem_init(&stack_group->sem_listen_thread, 0, 0); -+ sprintf_s(name, sizeof(name), "%s", "listen_thread"); -+ struct sys_thread *thread = sys_thread_new(name, libnet_listen_thread, -+ (void*)(&stack_group->sem_listen_thread), 0, 0); -+ free(thread); -+ sem_wait(&stack_group->sem_listen_thread); -+ } -+ -+ return 0; -+} -+ -+int32_t stack_thread_setup(void) -+{ -+ int32_t ret; -+ char name[PATH_MAX]; -+ int queue_num = get_global_cfg_params()->num_queue; -+ struct thread_params *t_params[queue_num]; -+ int process_index = get_global_cfg_params()->process_idx; -+ - for (uint32_t i = 0; i < queue_num; i++) { - if (get_global_cfg_params()->seperate_send_recv) { - if (i % 2 == 0) { -@@ -610,26 +581,6 @@ int32_t init_protocol_stack(void) - } - } - -- /* stack_num * 2: stack thread and kernel event thread will post sem */ -- wait_sem_value(&stack_group->thread_phase1, stack_group->stack_num * 2); -- -- for (int idx = 0; idx < queue_num; idx++){ -- free(t_params[idx]); -- } -- -- if (!use_ltran()) { -- ret = sem_init(&stack_group->sem_listen_thread, 0, 0); -- ret = sprintf_s(name, sizeof(name), "%s", "listen_thread"); -- struct sys_thread *thread = sys_thread_new(name, libnet_listen_thread, -- (void*)(&stack_group->sem_listen_thread), 0, 0); -- free(thread); -- sem_wait(&stack_group->sem_listen_thread); -- } -- -- if (get_init_fail()) { -- return -1; -- } -- - return 0; - } - -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index a23ddff..2d723d4 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -85,9 +85,6 @@ struct eth_params; - struct protocol_stack_group { - uint16_t stack_num; - uint16_t port_id; -- sem_t thread_phase1; -- sem_t ethdev_init; -- sem_t all_init; - uint64_t rx_offload; - uint64_t tx_offload; - uint32_t reta_mask; -@@ -112,7 +109,9 @@ struct protocol_stack *get_protocol_stack_by_fd(int32_t fd); - struct protocol_stack *get_bind_protocol_stack(void); - struct protocol_stack_group *get_protocol_stack_group(void); - --int32_t init_protocol_stack(void); -+int32_t stack_group_init(void); -+int32_t stack_thread_setup(void); -+ - void bind_to_stack_numa(struct protocol_stack *stack); - int32_t init_dpdk_ethdev(void); - --- -2.27.0 - diff --git a/0015-lstack_lwip-external-api-start-with-do_lwip_-prefix.patch b/0015-lstack_lwip-external-api-start-with-do_lwip_-prefix.patch deleted file mode 100644 index e0b022650850b7e28624818aa05cdd49cf82f4aa..0000000000000000000000000000000000000000 --- a/0015-lstack_lwip-external-api-start-with-do_lwip_-prefix.patch +++ /dev/null @@ -1,941 +0,0 @@ -From 9ba0b1d9df98b648eecdf5c5ed31611574d25272 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 20 Sep 2023 19:48:22 +0800 -Subject: [PATCH] lstack_lwip: external api start with do_lwip_ prefix - ---- - src/lstack/api/lstack_wrap.c | 22 +-- - src/lstack/core/lstack_dpdk.c | 12 +- - src/lstack/core/lstack_lwip.c | 198 ++++----------------- - src/lstack/core/lstack_protocol_stack.c | 138 +++++++++++++- - src/lstack/core/lstack_thread_rpc.c | 8 +- - src/lstack/include/lstack_dpdk.h | 1 + - src/lstack/include/lstack_lwip.h | 61 ++++--- - src/lstack/include/lstack_protocol_stack.h | 7 + - src/lstack/netif/lstack_ethdev.c | 8 +- - src/lstack/netif/lstack_vdev.c | 2 +- - 10 files changed, 241 insertions(+), 216 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 956d661..236c689 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -438,7 +438,7 @@ static inline ssize_t do_recv(int32_t sockfd, void *buf, size_t len, int32_t fla - - struct lwip_sock *sock = NULL; - if (select_path(sockfd, &sock) == PATH_LWIP) { -- return read_stack_data(sockfd, buf, len, flags, NULL, NULL); -+ return do_lwip_read_from_stack(sockfd, buf, len, flags, NULL, NULL); - } - - return posix_api->recv_fn(sockfd, buf, len, flags); -@@ -456,7 +456,7 @@ static inline ssize_t do_read(int32_t s, void *mem, size_t len) - - struct lwip_sock *sock = NULL; - if (select_path(s, &sock) == PATH_LWIP) { -- return read_stack_data(s, mem, len, 0, NULL, NULL); -+ return do_lwip_read_from_stack(s, mem, len, 0, NULL, NULL); - } - return posix_api->read_fn(s, mem, len); - } -@@ -477,7 +477,7 @@ static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) - msg.msg_control = NULL; - msg.msg_controllen = 0; - msg.msg_flags = 0; -- ssize_t result = recvmsg_from_stack(s, &msg, 0); -+ ssize_t result = do_lwip_recvmsg_from_stack(s, &msg, 0); - if (result == -1 && errno == EAGAIN) { - errno = 0; - return 0; -@@ -492,7 +492,7 @@ static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32 - return posix_api->send_fn(sockfd, buf, len, flags); - } - -- return gazelle_send(sockfd, buf, len, flags, NULL, 0); -+ return do_lwip_send_to_stack(sockfd, buf, len, flags, NULL, 0); - } - - static inline ssize_t do_write(int32_t s, const void *mem, size_t size) -@@ -502,7 +502,7 @@ static inline ssize_t do_write(int32_t s, const void *mem, size_t size) - return posix_api->write_fn(s, mem, size); - } - -- return gazelle_send(s, mem, size, 0, NULL, 0); -+ return do_lwip_send_to_stack(s, mem, size, 0, NULL, 0); - } - - static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) -@@ -521,7 +521,7 @@ static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) - msg.msg_control = NULL; - msg.msg_controllen = 0; - msg.msg_flags = 0; -- return sendmsg_to_stack(sock, s, &msg, 0); -+ return do_lwip_sendmsg_to_stack(sock, s, &msg, 0); - } - - static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flags) -@@ -532,7 +532,7 @@ static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flag - - struct lwip_sock *sock = NULL; - if (select_path(s, &sock) == PATH_LWIP) { -- return recvmsg_from_stack(s, message, flags); -+ return do_lwip_recvmsg_from_stack(s, message, flags); - } - - return posix_api->recv_msg(s, message, flags); -@@ -546,7 +546,7 @@ static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_ - - struct lwip_sock *sock = NULL; - if (select_path(s, &sock) == PATH_LWIP) { -- return sendmsg_to_stack(sock, s, message, flags); -+ return do_lwip_sendmsg_to_stack(sock, s, message, flags); - } - - return posix_api->send_msg(s, message, flags); -@@ -558,7 +558,7 @@ static inline ssize_t udp_recvfrom(struct lwip_sock *sock, int32_t sockfd, void - int32_t ret; - - while (1) { -- ret = read_stack_data(sockfd, buf, len, flags, addr, addrlen); -+ ret = do_lwip_read_from_stack(sockfd, buf, len, flags, addr, addrlen); - if (ret > 0) { - return ret; - } -@@ -581,7 +581,7 @@ static inline ssize_t udp_recvfrom(struct lwip_sock *sock, int32_t sockfd, void - static inline ssize_t tcp_recvfrom(struct lwip_sock *sock, int32_t sockfd, void *buf, size_t len, int32_t flags, - struct sockaddr *addr, socklen_t *addrlen) - { -- return read_stack_data(sockfd, buf, len, flags, addr, addrlen); -+ return do_lwip_read_from_stack(sockfd, buf, len, flags, addr, addrlen); - } - - static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t flags, -@@ -615,7 +615,7 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int - return posix_api->send_to(sockfd, buf, len, flags, addr, addrlen); - } - -- return gazelle_send(sockfd, buf, len, flags, addr, addrlen); -+ return do_lwip_send_to_stack(sockfd, buf, len, flags, addr, addrlen); - } - - static inline int32_t do_close(int32_t s) -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index cd42047..b4e29cb 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -281,6 +281,16 @@ int32_t create_shared_ring(struct protocol_stack *stack) - return 0; - } - -+int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num) -+{ -+ int32_t ret = rte_pktmbuf_alloc_bulk(pool, mbufs, num); -+ if (ret != 0) { -+ return ret; -+ } -+ -+ return 0; -+} -+ - int32_t fill_mbuf_to_ring(struct rte_mempool *mempool, struct rte_ring *ring, uint32_t mbuf_num) - { - int32_t ret; -@@ -291,7 +301,7 @@ int32_t fill_mbuf_to_ring(struct rte_mempool *mempool, struct rte_ring *ring, ui - while (remain > 0) { - batch = LWIP_MIN(remain, RING_SIZE(FREE_RX_QUEUE_SZ)); - -- ret = gazelle_alloc_pktmbuf(mempool, free_buf, batch); -+ ret = dpdk_alloc_pktmbuf(mempool, free_buf, batch); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "cannot alloc mbuf for ring, count: %u ret=%d\n", batch, ret); - return -1; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index bcdbac0..9ab8446 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -167,7 +167,7 @@ static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_so - return false; - } - --void gazelle_init_sock(int32_t fd) -+void do_lwip_init_sock(int32_t fd) - { - static _Atomic uint32_t name_tick = 0; - struct protocol_stack *stack = get_protocol_stack(); -@@ -200,7 +200,7 @@ void gazelle_init_sock(int32_t fd) - init_list_node_null(&sock->event_list); - } - --void gazelle_clean_sock(int32_t fd) -+void do_lwip_clean_sock(int32_t fd) - { - struct lwip_sock *sock = get_socket_by_fd(fd); - if (sock == NULL || sock->stack == NULL) { -@@ -220,7 +220,7 @@ void gazelle_clean_sock(int32_t fd) - list_del_node_null(&sock->recv_list); - } - --void gazelle_free_pbuf(struct pbuf *pbuf) -+void do_lwip_free_pbuf(struct pbuf *pbuf) - { - if (pbuf == NULL) { - return; -@@ -231,17 +231,7 @@ void gazelle_free_pbuf(struct pbuf *pbuf) - rte_pktmbuf_free_seg(mbuf); - } - --int32_t gazelle_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num) --{ -- int32_t ret = rte_pktmbuf_alloc_bulk(pool, mbufs, num); -- if (ret != 0) { -- return ret; -- } -- -- return 0; --} -- --struct pbuf *lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type type) -+struct pbuf *do_lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type type) - { - struct rte_mbuf *mbuf; - struct protocol_stack *stack = get_protocol_stack(); -@@ -254,7 +244,7 @@ struct pbuf *lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type type) - return init_mbuf_to_pbuf(mbuf, layer, length, type); - } - --struct pbuf *write_lwip_data(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags) -+struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags) - { - struct pbuf *pbuf = NULL; - -@@ -321,7 +311,7 @@ struct pbuf *write_lwip_data(struct lwip_sock *sock, uint16_t remain_size, uint8 - return pbuf; - } - --void write_lwip_over(struct lwip_sock *sock) -+void do_lwip_get_from_sendring_over(struct lwip_sock *sock) - { - sock->send_pre_del = NULL; - sock->stack->stats.write_lwip_cnt++; -@@ -549,8 +539,8 @@ int sem_timedwait_nsecs(sem_t *sem) - return sem_timedwait(sem, &ts); - } - --ssize_t write_stack_data(struct lwip_sock *sock, const void *buf, size_t len, -- const struct sockaddr *addr, socklen_t addrlen) -+static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, size_t len, -+ const struct sockaddr *addr, socklen_t addrlen) - { - if (sock->errevent > 0) { - GAZELLE_RETURN(ENOTCONN); -@@ -639,7 +629,7 @@ END: - return send_len; - } - --static inline bool replenish_send_ring(struct protocol_stack *stack, struct lwip_sock *sock) -+bool do_lwip_replenish_sendring(struct protocol_stack *stack, struct lwip_sock *sock) - { - bool replenish_again = false; - -@@ -652,16 +642,8 @@ static inline bool replenish_send_ring(struct protocol_stack *stack, struct lwip - return replenish_again; - } - --void rpc_replenish(struct rpc_msg *msg) --{ -- struct protocol_stack *stack = (struct protocol_stack *)msg->args[MSG_ARG_0].p; -- struct lwip_sock *sock = (struct lwip_sock *)msg->args[MSG_ARG_1].p; -- -- msg->result = replenish_send_ring(stack, sock); --} -- --static inline bool do_lwip_send(struct protocol_stack *stack, int32_t fd, struct lwip_sock *sock, -- size_t len, int32_t flags) -+bool do_lwip_send(struct protocol_stack *stack, int32_t fd, struct lwip_sock *sock, -+ size_t len, int32_t flags) - { - /* send all send_ring, so len set lwip send max. */ - if (NETCONN_IS_UDP(sock)) { -@@ -670,38 +652,7 @@ static inline bool do_lwip_send(struct protocol_stack *stack, int32_t fd, struct - (void)lwip_send(fd, sock, UINT16_MAX, flags); - } - -- return replenish_send_ring(stack, sock); --} -- --void stack_send(struct rpc_msg *msg) --{ -- int32_t fd = msg->args[MSG_ARG_0].i; -- size_t len = msg->args[MSG_ARG_1].size; -- struct protocol_stack *stack = (struct protocol_stack *)msg->args[MSG_ARG_3].p; -- bool replenish_again; -- -- struct lwip_sock *sock = get_socket(fd); -- if (sock == NULL) { -- msg->result = -1; -- LSTACK_LOG(ERR, LSTACK, "stack_send: sock error!\n"); -- rpc_msg_free(msg); -- return; -- } -- -- replenish_again = do_lwip_send(stack, sock->conn->socket, sock, len, 0); -- __sync_fetch_and_sub(&sock->call_num, 1); -- if (!NETCONN_IS_DATAOUT(sock) && !replenish_again) { -- rpc_msg_free(msg); -- return; -- } else { -- if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 0) { -- rpc_call(&stack->rpc_queue, msg); -- __sync_fetch_and_add(&sock->call_num, 1); -- } else { -- rpc_msg_free(msg); -- return; -- } -- } -+ return do_lwip_replenish_sendring(stack, sock); - } - - static inline void free_recv_ring_readover(struct rte_ring *ring) -@@ -721,7 +672,7 @@ static inline struct pbuf *pbuf_last(struct pbuf *pbuf) - return pbuf; - } - --ssize_t read_lwip_data(struct lwip_sock *sock, int32_t flags, u8_t apiflags) -+ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, u8_t apiflags) - { - if (sock->conn->recvmbox == NULL) { - return 0; -@@ -808,7 +759,7 @@ static int32_t check_msg_vaild(const struct msghdr *message) - return 0; - } - --ssize_t recvmsg_from_stack(int32_t s, struct msghdr *message, int32_t flags) -+ssize_t do_lwip_recvmsg_from_stack(int32_t s, struct msghdr *message, int32_t flags) - { - ssize_t buflen = 0; - -@@ -821,8 +772,8 @@ ssize_t recvmsg_from_stack(int32_t s, struct msghdr *message, int32_t flags) - continue; - } - -- ssize_t recvd_local = read_stack_data(s, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len, -- flags, NULL, NULL); -+ ssize_t recvd_local = do_lwip_read_from_stack(s, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len, -+ flags, NULL, NULL); - if (recvd_local > 0) { - buflen += recvd_local; - } -@@ -956,8 +907,8 @@ static inline void thread_bind_stack(struct lwip_sock *sock) - } - } - --ssize_t gazelle_send(int32_t fd, const void *buf, size_t len, int32_t flags, -- const struct sockaddr *addr, socklen_t addrlen) -+ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t flags, -+ const struct sockaddr *addr, socklen_t addrlen) - { - if (buf == NULL) { - GAZELLE_RETURN(EINVAL); -@@ -974,7 +925,7 @@ ssize_t gazelle_send(int32_t fd, const void *buf, size_t len, int32_t flags, - if (sock->same_node_tx_ring != NULL) { - return gazelle_same_node_ring_send(sock, buf, len, flags); - } -- ssize_t send = write_stack_data(sock, buf, len, addr, addrlen); -+ ssize_t send = do_lwip_fill_sendring(sock, buf, len, addr, addrlen); - if (send <= 0) { - return send; - } -@@ -983,7 +934,7 @@ ssize_t gazelle_send(int32_t fd, const void *buf, size_t len, int32_t flags, - return send; - } - --ssize_t sendmsg_to_stack(struct lwip_sock *sock, int32_t s, const struct msghdr *message, int32_t flags) -+ssize_t do_lwip_sendmsg_to_stack(struct lwip_sock *sock, int32_t s, const struct msghdr *message, int32_t flags) - { - int32_t ret; - int32_t i; -@@ -998,7 +949,7 @@ ssize_t sendmsg_to_stack(struct lwip_sock *sock, int32_t s, const struct msghdr - continue; - } - -- ret = write_stack_data(sock, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len, NULL, 0); -+ ret = do_lwip_fill_sendring(sock, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len, NULL, 0); - if (ret <= 0) { - buflen = (buflen == 0) ? ret : buflen; - break; -@@ -1037,7 +988,8 @@ static struct pbuf *pbuf_free_partial(struct pbuf *pbuf, uint16_t free_len) - return pbuf; - } - --ssize_t read_stack_data(int32_t fd, void *buf, size_t len, int32_t flags, struct sockaddr *addr, socklen_t *addrlen) -+ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags, -+ struct sockaddr *addr, socklen_t *addrlen) - { - size_t recv_left = len; - struct pbuf *pbuf = NULL; -@@ -1107,7 +1059,7 @@ ssize_t read_stack_data(int32_t fd, void *buf, size_t len, int32_t flags, struct - return recvd; - } - --void add_recv_list(int32_t fd) -+void do_lwip_add_recvlist(int32_t fd) - { - struct lwip_sock *sock = get_socket_by_fd(fd); - -@@ -1131,7 +1083,7 @@ void read_same_node_recv_list(struct protocol_stack *stack) - } - } - --void read_recv_list(struct protocol_stack *stack, uint32_t max_num) -+void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num) - { - struct list_node *list = &(stack->recv_list); - struct list_node *node, *temp; -@@ -1168,7 +1120,7 @@ void read_recv_list(struct protocol_stack *stack, uint32_t max_num) - } - } - --void gazelle_connected_callback(struct netconn *conn) -+void do_lwip_connected_callback(struct netconn *conn) - { - if (conn == NULL) { - return; -@@ -1225,7 +1177,7 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - } - } - --static inline void clone_lwip_socket_opt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock) -+void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock) - { - dst_sock->conn->pcb.ip->so_options = src_sock->conn->pcb.ip->so_options; - dst_sock->conn->pcb.ip->ttl = src_sock->conn->pcb.ip->ttl; -@@ -1244,19 +1196,19 @@ static inline void clone_lwip_socket_opt(struct lwip_sock *dst_sock, struct lwip - } - } - --int32_t gazelle_socket(int domain, int type, int protocol) -+int32_t do_lwip_socket(int domain, int type, int protocol) - { - int32_t fd = lwip_socket(AF_INET, type, 0); - if (fd < 0) { - return fd; - } - -- gazelle_init_sock(fd); -+ do_lwip_init_sock(fd); - - struct lwip_sock *sock = get_socket(fd); - if (sock == NULL || sock->stack == NULL) { - lwip_close(fd); -- gazelle_clean_sock(fd); -+ do_lwip_clean_sock(fd); - posix_api->close_fn(fd); - return -1; - } -@@ -1264,66 +1216,14 @@ int32_t gazelle_socket(int domain, int type, int protocol) - return fd; - } - --void create_shadow_fd(struct rpc_msg *msg) --{ -- int32_t fd = msg->args[MSG_ARG_0].i; -- struct sockaddr *addr = msg->args[MSG_ARG_1].p; -- socklen_t addr_len = msg->args[MSG_ARG_2].socklen; -- -- int32_t clone_fd = 0; -- struct lwip_sock *sock = get_socket_by_fd(fd); -- if (sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d\n", fd); -- msg->result = -1; -- return; -- } -- -- if (NETCONN_IS_UDP(sock)) { -- clone_fd = gazelle_socket(AF_INET, SOCK_DGRAM, 0); -- } else { -- clone_fd = gazelle_socket(AF_INET, SOCK_STREAM, 0); -- } -- -- if (clone_fd < 0) { -- LSTACK_LOG(ERR, LSTACK, "clone socket failed clone_fd=%d errno=%d\n", clone_fd, errno); -- msg->result = clone_fd; -- return; -- } -- -- struct lwip_sock *clone_sock = get_socket_by_fd(clone_fd); -- if (clone_sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d clone_fd=%d\n", fd, clone_fd); -- msg->result = -1; -- return; -- } -- -- clone_lwip_socket_opt(clone_sock, sock); -- -- while (sock->listen_next) { -- sock = sock->listen_next; -- } -- sock->listen_next = clone_sock; -- -- int32_t ret = lwip_bind(clone_fd, addr, addr_len); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "clone bind failed clone_fd=%d errno=%d\n", clone_fd, errno); -- msg->result = ret; -- return; -- } -- -- msg->result = clone_fd; --} -- --void get_lwip_conntable(struct rpc_msg *msg) -+uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, -+ uint32_t max_num) - { - struct tcp_pcb *pcb = NULL; - uint32_t conn_num = 0; -- struct gazelle_stat_lstack_conn_info *conn = (struct gazelle_stat_lstack_conn_info *)msg->args[MSG_ARG_0].p; -- uint32_t max_num = msg->args[MSG_ARG_1].u; - - if (conn == NULL) { -- msg->result = -1; -- return; -+ return -1; - } - - for (pcb = tcp_active_pcbs; pcb != NULL && conn_num < max_num; pcb = pcb->next) { -@@ -1352,10 +1252,10 @@ void get_lwip_conntable(struct rpc_msg *msg) - conn_num++; - } - -- msg->result = conn_num; -+ return conn_num; - } - --void get_lwip_connnum(struct rpc_msg *msg) -+uint32_t do_lwip_get_connnum(void) - { - struct tcp_pcb *pcb = NULL; - struct tcp_pcb_listen *pcbl = NULL; -@@ -1373,33 +1273,7 @@ void get_lwip_connnum(struct rpc_msg *msg) - conn_num++; - } - -- msg->result = conn_num; --} -- --static uint32_t get_list_count(struct list_node *list) --{ -- struct list_node *node, *temp; -- uint32_t count = 0; -- -- list_for_each_safe(node, temp, list) { -- count++; -- } -- -- return count; --} -- --void stack_mempool_size(struct rpc_msg *msg) --{ -- struct protocol_stack *stack = (struct protocol_stack*)msg->args[MSG_ARG_0].p; -- -- msg->result = rte_mempool_avail_count(stack->rxtx_pktmbuf_pool); --} -- --void stack_recvlist_count(struct rpc_msg *msg) --{ -- struct protocol_stack *stack = (struct protocol_stack*)msg->args[MSG_ARG_0].p; -- -- msg->result = get_list_count(&stack->recv_list); -+ return conn_num; - } - - void netif_poll(struct netif *netif) -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index ca0b046..5695438 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -484,7 +484,7 @@ static void* gazelle_stack_thread(void *arg) - read_same_node_recv_list(stack); - } - } -- read_recv_list(stack, read_connect_number); -+ do_lwip_read_recvlist(stack, read_connect_number); - - if ((wakeup_tick & 0xf) == 0) { - wakeup_stack_epoll(stack); -@@ -643,9 +643,9 @@ void stack_arp(struct rpc_msg *msg) - - void stack_socket(struct rpc_msg *msg) - { -- msg->result = gazelle_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); -+ msg->result = do_lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); - if (msg->result < 0) { -- msg->result = gazelle_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); -+ msg->result = do_lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); - if (msg->result < 0) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, %ld socket failed\n", get_stack_tid(), msg->result); - } -@@ -661,7 +661,7 @@ void stack_close(struct rpc_msg *msg) - LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); - } - -- gazelle_clean_sock(fd); -+ do_lwip_clean_sock(fd); - - posix_api->close_fn(fd); - } -@@ -706,7 +706,7 @@ void stack_accept(struct rpc_msg *msg) - struct lwip_sock *sock = get_socket(accept_fd); - if (sock == NULL || sock->stack == NULL) { - lwip_close(accept_fd); -- gazelle_clean_sock(accept_fd); -+ do_lwip_clean_sock(accept_fd); - posix_api->close_fn(accept_fd); - LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); - return; -@@ -715,7 +715,7 @@ void stack_accept(struct rpc_msg *msg) - msg->result = accept_fd; - sock->stack->conn_num++; - if (rte_ring_count(sock->conn->recvmbox->ring)) { -- add_recv_list(accept_fd); -+ do_lwip_add_recvlist(accept_fd); - } - } - -@@ -783,6 +783,37 @@ void stack_recv(struct rpc_msg *msg) - msg->args[MSG_ARG_3].i); - } - -+void stack_send(struct rpc_msg *msg) -+{ -+ int32_t fd = msg->args[MSG_ARG_0].i; -+ size_t len = msg->args[MSG_ARG_1].size; -+ struct protocol_stack *stack = (struct protocol_stack *)msg->args[MSG_ARG_3].p; -+ bool replenish_again; -+ -+ struct lwip_sock *sock = get_socket(fd); -+ if (sock == NULL) { -+ msg->result = -1; -+ LSTACK_LOG(ERR, LSTACK, "stack_send: sock error!\n"); -+ rpc_msg_free(msg); -+ return; -+ } -+ -+ replenish_again = do_lwip_send(stack, sock->conn->socket, sock, len, 0); -+ __sync_fetch_and_sub(&sock->call_num, 1); -+ if (!NETCONN_IS_DATAOUT(sock) && !replenish_again) { -+ rpc_msg_free(msg); -+ return; -+ } else { -+ if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 0) { -+ rpc_call(&stack->rpc_queue, msg); -+ __sync_fetch_and_add(&sock->call_num, 1); -+ } else { -+ rpc_msg_free(msg); -+ return; -+ } -+ } -+} -+ - /* any protocol stack thread receives arp packet and sync it to other threads so that it can have the arp table */ - void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack) - { -@@ -797,7 +828,7 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - continue; - } - -- ret = gazelle_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); - if (ret != 0) { - stack->stats.rx_allocmbuf_fail++; - return; -@@ -830,6 +861,99 @@ void stack_clean_epoll(struct rpc_msg *msg) - list_del_node_null(&wakeup->wakeup_list[stack->stack_idx]); - } - -+void stack_mempool_size(struct rpc_msg *msg) -+{ -+ struct protocol_stack *stack = (struct protocol_stack*)msg->args[MSG_ARG_0].p; -+ -+ msg->result = rte_mempool_avail_count(stack->rxtx_pktmbuf_pool); -+} -+ -+void stack_create_shadow_fd(struct rpc_msg *msg) -+{ -+ int32_t fd = msg->args[MSG_ARG_0].i; -+ struct sockaddr *addr = msg->args[MSG_ARG_1].p; -+ socklen_t addr_len = msg->args[MSG_ARG_2].socklen; -+ -+ int32_t clone_fd = 0; -+ struct lwip_sock *sock = get_socket_by_fd(fd); -+ if (sock == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d\n", fd); -+ msg->result = -1; -+ return; -+ } -+ -+ if (NETCONN_IS_UDP(sock)) { -+ clone_fd = do_lwip_socket(AF_INET, SOCK_DGRAM, 0); -+ } else { -+ clone_fd = do_lwip_socket(AF_INET, SOCK_STREAM, 0); -+ } -+ -+ if (clone_fd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "clone socket failed clone_fd=%d errno=%d\n", clone_fd, errno); -+ msg->result = clone_fd; -+ return; -+ } -+ -+ struct lwip_sock *clone_sock = get_socket_by_fd(clone_fd); -+ if (clone_sock == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d clone_fd=%d\n", fd, clone_fd); -+ msg->result = -1; -+ return; -+ } -+ -+ do_lwip_clone_sockopt(clone_sock, sock); -+ -+ while (sock->listen_next) { -+ sock = sock->listen_next; -+ } -+ sock->listen_next = clone_sock; -+ -+ int32_t ret = lwip_bind(clone_fd, addr, addr_len); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "clone bind failed clone_fd=%d errno=%d\n", clone_fd, errno); -+ msg->result = ret; -+ return; -+ } -+ -+ msg->result = clone_fd; -+} -+ -+void stack_replenish_sendring(struct rpc_msg *msg) -+{ -+ struct protocol_stack *stack = (struct protocol_stack *)msg->args[MSG_ARG_0].p; -+ struct lwip_sock *sock = (struct lwip_sock *)msg->args[MSG_ARG_1].p; -+ -+ msg->result = do_lwip_replenish_sendring(stack, sock); -+} -+ -+void stack_get_conntable(struct rpc_msg *msg) -+{ -+ struct gazelle_stat_lstack_conn_info *conn = (struct gazelle_stat_lstack_conn_info *)msg->args[MSG_ARG_0].p; -+ uint32_t max_num = msg->args[MSG_ARG_1].u; -+ -+ msg->result = do_lwip_get_conntable(conn, max_num); -+} -+ -+void stack_get_connnum(struct rpc_msg *msg) -+{ -+ msg->result = do_lwip_get_connnum(); -+} -+ -+void stack_recvlist_count(struct rpc_msg *msg) -+{ -+ struct protocol_stack *stack = (struct protocol_stack *)msg->args[MSG_ARG_0].p; -+ struct list_node *list = &stack->recv_list; -+ uint32_t count = 0; -+ struct list_node *node; -+ struct list_node *temp; -+ -+ list_for_each_safe(node, temp, list) { -+ count++; -+ } -+ -+ msg->result = count; -+} -+ - /* when fd is listenfd, listenfd of all protocol stack thread will be closed */ - int32_t stack_broadcast_close(int32_t fd) - { -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 1234bc6..92c58df 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -122,7 +122,7 @@ void poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) - - int32_t rpc_call_conntable(struct protocol_stack *stack, void *conn_table, uint32_t max_conn) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, get_lwip_conntable); -+ struct rpc_msg *msg = rpc_msg_alloc(stack, stack_get_conntable); - if (msg == NULL) { - return -1; - } -@@ -135,7 +135,7 @@ int32_t rpc_call_conntable(struct protocol_stack *stack, void *conn_table, uint3 - - int32_t rpc_call_connnum(struct protocol_stack *stack) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, get_lwip_connnum); -+ struct rpc_msg *msg = rpc_msg_alloc(stack, stack_get_connnum); - if (msg == NULL) { - return -1; - } -@@ -145,7 +145,7 @@ int32_t rpc_call_connnum(struct protocol_stack *stack) - - int32_t rpc_call_shadow_fd(struct protocol_stack *stack, int32_t fd, const struct sockaddr *addr, socklen_t addrlen) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, create_shadow_fd); -+ struct rpc_msg *msg = rpc_msg_alloc(stack, stack_create_shadow_fd); - if (msg == NULL) { - return -1; - } -@@ -434,7 +434,7 @@ int32_t rpc_call_ioctl(int fd, long cmd, void *argp) - - int32_t rpc_call_replenish(struct protocol_stack *stack, struct lwip_sock *sock) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, rpc_replenish); -+ struct rpc_msg *msg = rpc_msg_alloc(stack, stack_replenish_sendring); - if (msg == NULL) { - return -1; - } -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index c233120..6ca4f3b 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -59,4 +59,5 @@ struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, - uint32_t mbuf_cache_size, uint16_t queue_id); - - void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id); -+int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num); - #endif /* GAZELLE_DPDK_H */ -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index 223ff93..55a483e 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -12,6 +12,9 @@ - - #ifndef __GAZELLE_LWIP_H__ - #define __GAZELLE_LWIP_H__ -+#include -+ -+#include "gazelle_dfx_msg.h" - - #define NETCONN_IS_ACCEPTIN(sock) (((sock)->conn->acceptmbox != NULL) && !sys_mbox_empty((sock)->conn->acceptmbox)) - #define NETCONN_IS_DATAIN(sock) ((gazelle_ring_readable_count((sock)->recv_ring) || (sock)->recv_lastdata) || (sock->same_node_rx_ring != NULL && same_node_ring_count(sock))) -@@ -24,32 +27,38 @@ struct rte_mempool; - struct rpc_msg; - struct rte_mbuf; - struct protocol_stack; --void create_shadow_fd(struct rpc_msg *msg); --void gazelle_init_sock(int32_t fd); --int32_t gazelle_socket(int domain, int type, int protocol); --void gazelle_clean_sock(int32_t fd); --struct pbuf *write_lwip_data(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags); --void write_lwip_over(struct lwip_sock *sock); --ssize_t write_stack_data(struct lwip_sock *sock, const void *buf, size_t len, -- const struct sockaddr *addr, socklen_t addrlen); --ssize_t read_stack_data(int32_t fd, void *buf, size_t len, int32_t flags, struct sockaddr *addr, socklen_t *addrlen); --ssize_t read_lwip_data(struct lwip_sock *sock, int32_t flags, uint8_t apiflags); --void read_recv_list(struct protocol_stack *stack, uint32_t max_num); -+ -+int32_t do_lwip_socket(int domain, int type, int protocol); -+void do_lwip_init_sock(int32_t fd); -+void do_lwip_clean_sock(int32_t fd); -+void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock); -+ -+struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags); -+void do_lwip_get_from_sendring_over(struct lwip_sock *sock); -+bool do_lwip_replenish_sendring(struct protocol_stack *stack, struct lwip_sock *sock); -+ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, uint8_t apiflags); -+ -+/* app write/read ring */ -+ssize_t do_lwip_sendmsg_to_stack(struct lwip_sock *sock, int32_t s, -+ const struct msghdr *message, int32_t flags); -+ssize_t do_lwip_recvmsg_from_stack(int32_t s, struct msghdr *message, int32_t flags); -+ -+ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t flags, -+ const struct sockaddr *addr, socklen_t addrlen); -+ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags, -+ struct sockaddr *addr, socklen_t *addrlen); -+ -+void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num); -+void do_lwip_add_recvlist(int32_t fd); -+bool do_lwip_send(struct protocol_stack *stack, int32_t fd, struct lwip_sock *sock, -+ size_t len, int32_t flags); -+ -+uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, uint32_t max_num); -+uint32_t do_lwip_get_connnum(void); -+ -+void do_lwip_free_pbuf(struct pbuf *pbuf); -+struct pbuf *do_lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type type); -+ - void read_same_node_recv_list(struct protocol_stack *stack); --void send_stack_list(struct protocol_stack *stack, uint32_t send_max); --void add_recv_list(int32_t fd); --void get_lwip_conntable(struct rpc_msg *msg); --void get_lwip_connnum(struct rpc_msg *msg); --void stack_recvlist_count(struct rpc_msg *msg); --void stack_send(struct rpc_msg *msg); --void app_rpc_write(struct rpc_msg *msg); --int32_t gazelle_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num); --void gazelle_free_pbuf(struct pbuf *pbuf); --ssize_t sendmsg_to_stack(struct lwip_sock *sock, int32_t s, const struct msghdr *message, int32_t flags); --ssize_t recvmsg_from_stack(int32_t s, struct msghdr *message, int32_t flags); --ssize_t gazelle_send(int32_t fd, const void *buf, size_t len, int32_t flags, -- const struct sockaddr *addr, socklen_t addrlen); --void rpc_replenish(struct rpc_msg *msg); --void stack_mempool_size(struct rpc_msg *msg); - - #endif -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index a23ddff..f8455bd 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -161,5 +161,12 @@ void stack_getsockopt(struct rpc_msg *msg); - void stack_setsockopt(struct rpc_msg *msg); - void stack_fcntl(struct rpc_msg *msg); - void stack_ioctl(struct rpc_msg *msg); -+void stack_send(struct rpc_msg *msg); -+void stack_mempool_size(struct rpc_msg *msg); -+void stack_create_shadow_fd(struct rpc_msg *msg); -+void stack_replenish_sendring(struct rpc_msg *msg); -+void stack_get_conntable(struct rpc_msg *msg); -+void stack_get_connnum(struct rpc_msg *msg); -+void stack_recvlist_count(struct rpc_msg *msg); - void kni_handle_tx(struct rte_mbuf *mbuf); - #endif -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index e3e823b..30c3c9a 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -540,9 +540,9 @@ void parse_arp_and_transefer(char* buf) - int32_t ret; - for (int32_t i = 0; i < stack_group->stack_num; i++) { - stack = stack_group->stacks[i]; -- ret = gazelle_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); - while (ret != 0) { -- ret = gazelle_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); - stack->stats.rx_allocmbuf_fail++; - } - copy_mbuf(mbuf_copy, mbuf); -@@ -569,9 +569,9 @@ void parse_tcp_and_transefer(char* buf) - struct rte_mbuf *mbuf_copy = NULL; - struct protocol_stack *stack = stack_group->stacks[stk_index]; - -- int32_t ret = gazelle_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); - while (ret != 0) { -- ret = gazelle_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); - stack->stats.rx_allocmbuf_fail++; - } - -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 4307f24..81b48dc 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -56,7 +56,7 @@ static uint32_t ltran_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pk - stack->rx_ring_used += rcvd_pkts; - if (unlikely(stack->rx_ring_used >= USED_RX_PKTS_WATERMARK)) { - uint32_t free_cnt = LWIP_MIN(stack->rx_ring_used, RING_SIZE(DPDK_PKT_BURST_SIZE)); -- int32_t ret = gazelle_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, (struct rte_mbuf **)free_buf, free_cnt); -+ int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, (struct rte_mbuf **)free_buf, free_cnt); - if (likely(ret == 0)) { - nr_pkts = gazelle_ring_sp_enqueue(stack->rx_ring, (void **)free_buf, free_cnt); - stack->rx_ring_used -= nr_pkts; --- -2.27.0 - diff --git a/0016-cfg-nic-rx-tx-queue-size-configure.patch b/0016-cfg-nic-rx-tx-queue-size-configure.patch deleted file mode 100644 index 1e6265048ca9f10410430d5ad6393cfac69956f2..0000000000000000000000000000000000000000 --- a/0016-cfg-nic-rx-tx-queue-size-configure.patch +++ /dev/null @@ -1,140 +0,0 @@ -From 4adbb49fe002f097683c3c2155387d6fe7d59952 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 9 Oct 2023 14:21:41 +0800 -Subject: [PATCH] cfg: nic rx/tx queue size configure - ---- - src/common/gazelle_opt.h | 4 ++-- - src/lstack/core/lstack_cfg.c | 20 ++++++++++++++++++++ - src/lstack/core/lstack_dpdk.c | 4 ++-- - src/lstack/include/lstack_cfg.h | 6 ++++++ - src/lstack/include/lstack_protocol_stack.h | 2 +- - src/lstack/lstack.conf | 3 +++ - 6 files changed, 34 insertions(+), 5 deletions(-) - -diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h -index 7b6aa19..7b855f9 100644 ---- a/src/common/gazelle_opt.h -+++ b/src/common/gazelle_opt.h -@@ -42,8 +42,8 @@ - #define VDEV_TX_QUEUE_SZ DEFAULT_RING_SIZE - #define FREE_RX_QUEUE_SZ DPDK_PKT_BURST_SIZE - --#define RTE_TEST_TX_DESC_DEFAULT 2048 --#define RTE_TEST_RX_DESC_DEFAULT 4096 -+#define NIC_QUEUE_SIZE_MAX 8192 -+#define NIC_QUEUE_SIZE_MIN 512 - - #define TCP_CONN_COUNT 1500 - #define MBUF_COUNT_PER_CONN 170 -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 9fc16dd..0eca86e 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -74,6 +74,8 @@ static int32_t parse_use_bond4(void); - static int32_t parse_bond4_slave_mac(void); - static int32_t parse_use_sockmap(void); - static int32_t parse_udp_enable(void); -+static int32_t parse_nic_rxqueue_size(void); -+static int32_t parse_nic_txqueue_size(void); - - #define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \ - do { \ -@@ -131,6 +133,8 @@ static struct config_vector_t g_config_tbl[] = { - { "bond4_slave_mac", parse_bond4_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}, - { NULL, NULL } - }; - -@@ -1163,3 +1167,19 @@ static int32_t parse_use_sockmap(void) - PARSE_ARG(g_config_params.use_sockmap, "use_sockmap", 0, 0, 1, ret); - return ret; - } -+ -+static int32_t parse_nic_rxqueue_size(void) -+{ -+ int32_t ret; -+ PARSE_ARG(g_config_params.nic.rxqueue_size, "nic_rxqueue_size", 4096, -+ NIC_QUEUE_SIZE_MIN, NIC_QUEUE_SIZE_MAX, ret); -+ return ret; -+} -+ -+static int32_t parse_nic_txqueue_size(void) -+{ -+ int32_t ret; -+ PARSE_ARG(g_config_params.nic.txqueue_size, "nic_txqueue_size", 2048, -+ NIC_QUEUE_SIZE_MIN, NIC_QUEUE_SIZE_MAX, ret); -+ return ret; -+} -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 902dadc..a53e85c 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -370,8 +370,8 @@ static struct eth_params *alloc_eth_params(uint16_t port_id, uint16_t nb_queues) - - eth_params->port_id = port_id; - eth_params->nb_queues = nb_queues; -- eth_params->nb_rx_desc = RTE_TEST_RX_DESC_DEFAULT; -- eth_params->nb_tx_desc = RTE_TEST_TX_DESC_DEFAULT; -+ eth_params->nb_rx_desc = get_global_cfg_params()->nic.rxqueue_size; -+ eth_params->nb_tx_desc = get_global_cfg_params()->nic.txqueue_size; - eth_params->conf.link_speeds = ETH_LINK_SPEED_AUTONEG; - eth_params->conf.txmode.mq_mode = ETH_MQ_TX_NONE; - eth_params->conf.rxmode.mq_mode = ETH_MQ_RX_NONE; -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 52a1abd..e48a501 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -59,6 +59,11 @@ struct secondary_attach_arg { - char file_prefix[PATH_MAX]; - }; - -+struct cfg_nic_params { -+ uint32_t rxqueue_size; -+ uint32_t txqueue_size; -+}; -+ - struct cfg_params { - ip4_addr_t host_addr; - ip4_addr_t netmask; -@@ -110,6 +115,7 @@ struct cfg_params { - uint8_t bond4_slave2_mac_addr[ETHER_ADDR_LEN]; - bool use_sockmap; - bool udp_enable; -+ struct cfg_nic_params nic; - }; - - struct cfg_params *get_global_cfg_params(void); -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index b7c18d3..a4f6ac2 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -69,7 +69,7 @@ struct protocol_stack { - uint32_t rx_ring_used; - uint32_t tx_ring_used; - -- struct rte_mbuf *pkts[RTE_TEST_RX_DESC_DEFAULT]; -+ struct rte_mbuf *pkts[NIC_QUEUE_SIZE_MAX]; - struct list_node recv_list; - struct list_node same_node_recv_list; /* used for same node processes communication */ - struct list_node wakeup_list; -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index fa7e284..ad574e1 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -34,6 +34,9 @@ rpc_number = 4 - #read nic pkts number - nic_read_number = 128 - -+nic_rxqueue_size = 4096 -+nic_txqueue_size = 2048 -+ - #each cpu core start a protocol stack thread. - num_cpus="2" - --- -2.27.0 - diff --git a/0017-epoll-distinguish-add-del_sock_event-and-add-del_soc.patch b/0017-epoll-distinguish-add-del_sock_event-and-add-del_soc.patch deleted file mode 100644 index d1ec24f0ab5b1ea57f88d58a21f284077f90f4c7..0000000000000000000000000000000000000000 --- a/0017-epoll-distinguish-add-del_sock_event-and-add-del_soc.patch +++ /dev/null @@ -1,203 +0,0 @@ -From 506a252ff94be857ab89b1c1d4aea0ef66ed9582 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 9 Oct 2023 10:36:50 +0800 -Subject: [PATCH] epoll: distinguish add/del_sock_event and - add/del_sock_event_nolock - ---- - src/lstack/api/lstack_epoll.c | 59 +++++++++++++++++-------- - src/lstack/core/lstack_lwip.c | 47 ++++---------------- - src/lstack/include/posix/lstack_epoll.h | 6 +++ - 3 files changed, 56 insertions(+), 56 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 55ca4fe..7c40792 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -46,37 +46,60 @@ static void update_epoll_max_stack(struct wakeup_poll *wakeup); - static void change_epollfd_kernel_thread(struct wakeup_poll *wakeup, struct protocol_stack *old_stack, - struct protocol_stack *new_stack); - -+static inline void add_wakeup_to_stack_wakeuplist(struct wakeup_poll *wakeup, struct protocol_stack *stack) -+{ -+ if (list_is_null(&wakeup->wakeup_list[stack->stack_idx])) { -+ list_add_node(&stack->wakeup_list, &wakeup->wakeup_list[stack->stack_idx]); -+ } -+} -+ -+void add_sock_event_nolock(struct lwip_sock *sock, uint32_t event) -+{ -+ struct wakeup_poll *wakeup = sock->wakeup; -+ -+ if (wakeup == NULL || wakeup->type == WAKEUP_CLOSE || (event & sock->epoll_events) == 0) { -+ return; -+ } -+ sock->events |= (event == EPOLLERR) ? (EPOLLIN | EPOLLERR) : (event & sock->epoll_events); -+ if (list_is_null(&sock->event_list)) { -+ list_add_node(&wakeup->event_list, &sock->event_list); -+ } -+ return; -+} -+ - void add_sock_event(struct lwip_sock *sock, 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) { - return; - } - - if (wakeup->type == WAKEUP_EPOLL) { - pthread_spin_lock(&wakeup->event_list_lock); -- -- /* app thread have read/write, event is outdated */ -- if (event == EPOLLIN && sock->conn->state != NETCONN_LISTEN && !NETCONN_IS_DATAIN(sock)) { -- pthread_spin_unlock(&wakeup->event_list_lock); -- return; -- } -- if (event == EPOLLOUT && !NETCONN_IS_OUTIDLE(sock)) { -- pthread_spin_unlock(&wakeup->event_list_lock); -- return; -- } -- -- sock->events |= (event == EPOLLERR) ? (EPOLLIN | EPOLLERR) : (event & sock->epoll_events); -- if (list_is_null(&sock->event_list)) { -- list_add_node(&wakeup->event_list, &sock->event_list); -- } -+ add_sock_event_nolock(sock, event); - pthread_spin_unlock(&wakeup->event_list_lock); - } - -- struct protocol_stack *stack = sock->stack; -- if (list_is_null(&wakeup->wakeup_list[stack->stack_idx])) { -- list_add_node(&stack->wakeup_list, &wakeup->wakeup_list[stack->stack_idx]); -+ add_wakeup_to_stack_wakeuplist(wakeup, stack); -+ return; -+} -+ -+void del_sock_event_nolock(struct lwip_sock *sock, uint32_t event) -+{ -+ sock->events &= ~event; -+ -+ if (sock->events == 0) { -+ list_del_node_null(&sock->event_list); - } -+ return; -+} -+ -+void del_sock_event(struct lwip_sock *sock, uint32_t event) -+{ -+ pthread_spin_lock(&sock->wakeup->event_list_lock); -+ del_sock_event_nolock(sock, event); -+ pthread_spin_unlock(&sock->wakeup->event_list_lock); - } - - void wakeup_stack_epoll(struct protocol_stack *stack) -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 9ab8446..a98b1b8 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -317,22 +317,6 @@ void do_lwip_get_from_sendring_over(struct lwip_sock *sock) - sock->stack->stats.write_lwip_cnt++; - } - --static inline void del_data_out_event(struct lwip_sock *sock) --{ -- pthread_spin_lock(&sock->wakeup->event_list_lock); -- -- /* check again avoid cover event add in stack thread */ -- if (!NETCONN_IS_OUTIDLE(sock)) { -- sock->events &= ~EPOLLOUT; -- -- if (sock->events == 0) { -- list_del_node_null(&sock->event_list); -- } -- } -- -- pthread_spin_unlock(&sock->wakeup->event_list_lock); --} -- - static ssize_t do_app_write(struct pbuf *pbufs[], void *buf, size_t len, uint32_t write_num) - { - ssize_t send_len = 0; -@@ -617,8 +601,9 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - wakeup->stat.app_write_cnt += write_num; - } - -- if (wakeup && wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLOUT)) { -- del_data_out_event(sock); -+ if (wakeup && wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLOUT) -+ && !NETCONN_IS_OUTIDLE(sock)) { -+ del_sock_event(sock, EPOLLOUT); - } - - END: -@@ -801,22 +786,6 @@ static inline void notice_stack_send(struct lwip_sock *sock, int32_t fd, int32_t - } - } - --static inline void del_data_in_event(struct lwip_sock *sock) --{ -- pthread_spin_lock(&sock->wakeup->event_list_lock); -- -- /* check again avoid cover event add in stack thread */ -- if (!NETCONN_IS_DATAIN(sock)) { -- sock->events &= ~EPOLLIN; -- -- if (sock->events == 0) { -- list_del_node_null(&sock->event_list); -- } -- } -- -- pthread_spin_unlock(&sock->wakeup->event_list_lock); --} -- - /* process on same node use ring to recv data */ - ssize_t gazelle_same_node_ring_recv(struct lwip_sock *sock, const void *buf, size_t len, int32_t flags) - { -@@ -847,8 +816,9 @@ ssize_t gazelle_same_node_ring_recv(struct lwip_sock *sock, const void *buf, siz - - END: - /* rte_ring_count reduce lock */ -- if (sock->wakeup && sock->wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLIN)) { -- del_data_in_event(sock); -+ if (sock->wakeup && sock->wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLIN) -+ && (!NETCONN_IS_DATAIN(sock))) { -+ del_sock_event(sock, EPOLLIN); - } - return act_len; - } -@@ -1042,8 +1012,9 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - } - - /* rte_ring_count reduce lock */ -- if (sock->wakeup && sock->wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLIN)) { -- del_data_in_event(sock); -+ if (sock->wakeup && sock->wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLIN) -+ && (!NETCONN_IS_DATAIN(sock))) { -+ del_sock_event(sock, EPOLLIN); - } - - if (pbuf && addr && addrlen) { -diff --git a/src/lstack/include/posix/lstack_epoll.h b/src/lstack/include/posix/lstack_epoll.h -index d6c81a7..699a951 100644 ---- a/src/lstack/include/posix/lstack_epoll.h -+++ b/src/lstack/include/posix/lstack_epoll.h -@@ -63,8 +63,14 @@ struct wakeup_poll { - - struct netconn; - struct lwip_sock; -+ - void add_sock_event(struct lwip_sock *sock, uint32_t event); -+void add_sock_event_nolock(struct lwip_sock *sock, uint32_t event); -+void del_sock_event(struct lwip_sock *sock, uint32_t event); -+void del_sock_event_nolock(struct lwip_sock *sock, uint32_t event); -+ - void wakeup_stack_epoll(struct protocol_stack *stack); -+ - int32_t lstack_epoll_create(int32_t size); - int32_t lstack_epoll_create1(int32_t flags); - int32_t lstack_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event *event); --- -2.27.0 - diff --git a/0018-preload-support-thread-hijacking-mode.patch b/0018-preload-support-thread-hijacking-mode.patch deleted file mode 100644 index fe75ba7ea8c71f64817e5c1603a41946a4d4dc75..0000000000000000000000000000000000000000 --- a/0018-preload-support-thread-hijacking-mode.patch +++ /dev/null @@ -1,646 +0,0 @@ -From 7c6d623f4009ec40349504281b9af396d05418ec Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 9 Oct 2023 11:36:34 +0800 -Subject: [PATCH] preload: support thread hijacking mode - ---- - src/lstack/api/lstack_wrap.c | 208 ++++++++++------------------ - src/lstack/core/lstack_cfg.c | 3 +- - src/lstack/core/lstack_init.c | 2 +- - src/lstack/core/lstack_preload.c | 114 ++++++++++++++- - src/lstack/include/lstack_preload.h | 9 ++ - 5 files changed, 202 insertions(+), 134 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 236c689..ab39a68 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -40,73 +40,15 @@ - #include "gazelle_base_func.h" - #include "lstack_thread_rpc.h" - -+#include "lstack_preload.h" -+ - #ifndef SOCK_TYPE_MASK - #define SOCK_TYPE_MASK 0xf - #endif - --enum KERNEL_LWIP_PATH { -- PATH_KERNEL = 0, -- PATH_LWIP, -- PATH_UNKNOW, --}; -- --static inline enum KERNEL_LWIP_PATH select_path(int fd, struct lwip_sock **socket) --{ -- if (unlikely(posix_api == NULL)) { -- /* -- * posix api maybe call before gazelle init -- * So, we must call posix_api_init at the head of select_path -- */ -- if (posix_api_init() != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "posix_api_init failed\n"); -- } -- return PATH_KERNEL; -- } -- -- if (unlikely(posix_api->ues_posix)) { -- return PATH_KERNEL; -- } -- -- struct lwip_sock *sock = get_socket_by_fd(fd); -- -- /* AF_UNIX case */ -- if (!sock || !sock->conn || CONN_TYPE_IS_HOST(sock->conn)) { -- return PATH_KERNEL; -- } -- -- if (socket) { -- *socket = sock; -- } -- -- if (likely(CONN_TYPE_IS_LIBOS(sock->conn))) { -- return PATH_LWIP; -- } -- -- if (NETCONN_IS_UDP(sock)) { -- return PATH_LWIP; -- } else { -- struct tcp_pcb *pcb = sock->conn->pcb.tcp; -- /* after lwip connect, call send immediately, pcb->state is SYN_SENT, need return PATH_LWIP */ -- /* pcb->state default value is CLOSED when call socket, need return PATH_UNKNOW */ -- if (pcb != NULL && pcb->state <= ESTABLISHED && pcb->state >= LISTEN) { -- return PATH_LWIP; -- } -- } -- -- return PATH_UNKNOW; --} -- - static inline int32_t do_epoll_create1(int32_t flags) - { -- if (posix_api == NULL) { -- /* posix api maybe call before gazelle init */ -- if (posix_api_init() != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "posix_api_init failed\n"); -- } -- return posix_api->epoll_create1_fn(flags); -- } -- -- if (unlikely(posix_api->ues_posix)) { -+ if (select_posix_path() == PATH_KERNEL) { - return posix_api->epoll_create1_fn(flags); - } - -@@ -115,15 +57,7 @@ static inline int32_t do_epoll_create1(int32_t flags) - - static inline int32_t do_epoll_create(int32_t size) - { -- if (posix_api == NULL) { -- /* posix api maybe call before gazelle init */ -- if (posix_api_init() != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "posix_api_init failed\n"); -- } -- return posix_api->epoll_create_fn(size); -- } -- -- if (unlikely(posix_api->ues_posix)) { -+ if (select_posix_path() == PATH_KERNEL) { - return posix_api->epoll_create_fn(size); - } - -@@ -132,7 +66,7 @@ static inline int32_t do_epoll_create(int32_t size) - - static inline int32_t do_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event* event) - { -- if (unlikely(posix_api->ues_posix)) { -+ if (select_posix_path() == PATH_KERNEL) { - return posix_api->epoll_ctl_fn(epfd, op, fd, event); - } - -@@ -141,7 +75,7 @@ static inline int32_t do_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct - - static inline int32_t do_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) - { -- if (unlikely(posix_api->ues_posix)) { -+ if (select_posix_path() == PATH_KERNEL) { - return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); - } - -@@ -158,8 +92,7 @@ static inline int32_t do_epoll_wait(int32_t epfd, struct epoll_event* events, in - - static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) - { -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_KERNEL) { -+ if (select_fd_posix_path(s, NULL) == PATH_KERNEL) { - return posix_api->accept_fn(s, addr, addrlen); - } - -@@ -177,8 +110,7 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_KERNEL) { -+ if (select_fd_posix_path(s, NULL) == PATH_KERNEL) { - return posix_api->accept4_fn(s, addr, addrlen, flags); - } - -@@ -219,22 +151,21 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - } - - struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_KERNEL) { -+ if (select_fd_posix_path(s, &sock) == PATH_KERNEL) { - return posix_api->bind_fn(s, name, namelen); - } - -- int32_t ret = posix_api->bind_fn(s, name, namelen); -- if (ret < 0) { -- /* ip is not lstack, just return */ -- if (!match_host_addr(((struct sockaddr_in *)name)->sin_addr.s_addr)) { -- return ret; -+ if (match_host_addr(((struct sockaddr_in *)name)->sin_addr.s_addr)) { -+ /* maybe kni addr */ -+ posix_api->bind_fn(s, name, namelen); -+ if (NETCONN_IS_UDP(sock) && get_global_cfg_params()->listen_shadow) { -+ return stack_broadcast_bind(s, name, namelen); -+ } else { -+ return stack_single_bind(s, name, namelen); - } -- } -- -- if (NETCONN_IS_UDP(sock) && get_global_cfg_params()->listen_shadow) { -- return stack_broadcast_bind(s, name, namelen); - } else { -- return stack_single_bind(s, name, namelen); -+ SET_CONN_TYPE_HOST(sock->conn); -+ return posix_api->bind_fn(s, name, namelen); - } - } - -@@ -299,7 +230,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - } - - struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_KERNEL) { -+ if (select_fd_posix_path(s, &sock) == PATH_KERNEL) { - return posix_api->connect_fn(s, name, namelen); - } - -@@ -309,6 +240,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - } - - if (!netconn_is_nonblocking(sock->conn)) { -+ LSTACK_LOG(ERR, LSTACK, "connect does not support blocking fd currently\n"); - GAZELLE_RETURN(EINVAL); - } - -@@ -330,8 +262,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - - static inline int32_t do_listen(int32_t s, int32_t backlog) - { -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_KERNEL) { -+ if (select_fd_posix_path(s, NULL) == PATH_KERNEL) { - return posix_api->listen_fn(s, backlog); - } - -@@ -355,8 +286,7 @@ static inline int32_t do_getpeername(int32_t s, struct sockaddr *name, socklen_t - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_LWIP) { -+ if (select_fd_posix_path(s, NULL) == PATH_LWIP) { - return rpc_call_getpeername(s, name, namelen); - } - -@@ -369,8 +299,7 @@ static inline int32_t do_getsockname(int32_t s, struct sockaddr *name, socklen_t - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_LWIP) { -+ if (select_fd_posix_path(s, NULL) == PATH_LWIP) { - return rpc_call_getsockname(s, name, namelen); - } - -@@ -391,8 +320,7 @@ static bool unsupport_optname(int32_t optname) - - static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, void *optval, socklen_t *optlen) - { -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_LWIP && !unsupport_optname(optname)) { -+ if (select_fd_posix_path(s, NULL) == PATH_LWIP && !unsupport_optname(optname)) { - return rpc_call_getsockopt(s, level, optname, optval, optlen); - } - -@@ -401,8 +329,7 @@ static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, v - - static inline int32_t do_setsockopt(int32_t s, int32_t level, int32_t optname, const void *optval, socklen_t optlen) - { -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_KERNEL || unsupport_optname(optname)) { -+ if (select_fd_posix_path(s, NULL) == PATH_KERNEL || unsupport_optname(optname)) { - return posix_api->setsockopt_fn(s, level, optname, optval, optlen); - } - -@@ -417,13 +344,27 @@ static inline int32_t do_setsockopt(int32_t s, int32_t level, int32_t optname, c - - static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - { -- if ((domain != AF_INET && domain != AF_UNSPEC) -- || ((type & SOCK_DGRAM) && !get_global_cfg_params()->udp_enable) -- || posix_api->ues_posix) { -+ int32_t ret; -+ /* process not init completed or not hajacking thread */ -+ if (select_posix_path() == PATH_KERNEL) { -+ return posix_api->socket_fn(domain, type, protocol); -+ } -+ -+ if ((domain != AF_INET && domain != AF_UNSPEC) || -+ ((type & SOCK_DGRAM) && !get_global_cfg_params()->udp_enable)) { - return posix_api->socket_fn(domain, type, protocol); - } - -- return rpc_call_socket(domain, type, protocol); -+ ret = rpc_call_socket(domain, type, protocol); -+ /* if udp_enable = 1 in lstack.conf, udp protocol must be in user path currently */ -+ if ((ret >= 0) && (type & SOCK_DGRAM)) { -+ struct lwip_sock *sock = get_socket(ret); -+ if (sock != NULL && sock->conn != NULL) { -+ SET_CONN_TYPE_LIBOS(sock->conn); -+ } -+ } -+ -+ return ret; - } - - static inline ssize_t do_recv(int32_t sockfd, void *buf, size_t len, int32_t flags) -@@ -436,12 +377,12 @@ static inline ssize_t do_recv(int32_t sockfd, void *buf, size_t len, int32_t fla - return 0; - } - -- struct lwip_sock *sock = NULL; -- if (select_path(sockfd, &sock) == PATH_LWIP) { -- return do_lwip_read_from_stack(sockfd, buf, len, flags, NULL, NULL); -+ if (select_posix_path() == PATH_KERNEL || // maybe fd is created by open before posix_api_init called -+ select_fd_posix_path(sockfd, NULL) == PATH_KERNEL) { -+ return posix_api->recv_fn(sockfd, buf, len, flags); - } - -- return posix_api->recv_fn(sockfd, buf, len, flags); -+ return do_lwip_read_from_stack(sockfd, buf, len, flags, NULL, NULL); - } - - static inline ssize_t do_read(int32_t s, void *mem, size_t len) -@@ -454,17 +395,18 @@ static inline ssize_t do_read(int32_t s, void *mem, size_t len) - return 0; - } - -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_LWIP) { -- return do_lwip_read_from_stack(s, mem, len, 0, NULL, NULL); -+ if (select_posix_path() == PATH_KERNEL || -+ select_fd_posix_path(s, NULL) == PATH_KERNEL) { -+ return posix_api->read_fn(s, mem, len); - } -- return posix_api->read_fn(s, mem, len); -+ -+ return do_lwip_read_from_stack(s, mem, len, 0, NULL, NULL); - } - - static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) - { -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) != PATH_LWIP) { -+ if (select_posix_path() == PATH_KERNEL || -+ select_fd_posix_path(s, NULL) == PATH_KERNEL) { - return posix_api->readv_fn(s, iov, iovcnt); - } - -@@ -487,8 +429,8 @@ static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) - - static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32_t flags) - { -- struct lwip_sock *sock = NULL; -- if (select_path(sockfd, &sock) != PATH_LWIP) { -+ if (select_posix_path() == PATH_KERNEL || -+ select_fd_posix_path(sockfd, NULL) == PATH_KERNEL) { - return posix_api->send_fn(sockfd, buf, len, flags); - } - -@@ -497,8 +439,8 @@ static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32 - - static inline ssize_t do_write(int32_t s, const void *mem, size_t size) - { -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) != PATH_LWIP) { -+ if (select_posix_path() == PATH_KERNEL || -+ select_fd_posix_path(s, NULL) == PATH_KERNEL) { - return posix_api->write_fn(s, mem, size); - } - -@@ -507,8 +449,9 @@ static inline ssize_t do_write(int32_t s, const void *mem, size_t size) - - static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) - { -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) != PATH_LWIP) { -+ struct lwip_sock *sock; -+ if (select_posix_path() == PATH_KERNEL || -+ select_fd_posix_path(s, &sock) == PATH_KERNEL) { - return posix_api->writev_fn(s, iov, iovcnt); - } - -@@ -530,12 +473,12 @@ static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flag - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_LWIP) { -- return do_lwip_recvmsg_from_stack(s, message, flags); -+ if (select_posix_path() == PATH_KERNEL || -+ select_fd_posix_path(s, NULL) == PATH_KERNEL) { -+ return posix_api->recv_msg(s, message, flags); - } - -- return posix_api->recv_msg(s, message, flags); -+ return do_lwip_recvmsg_from_stack(s, message, flags); - } - - static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_t flags) -@@ -544,12 +487,13 @@ static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_ - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_LWIP) { -- return do_lwip_sendmsg_to_stack(sock, s, message, flags); -+ struct lwip_sock *sock; -+ if (select_posix_path() == PATH_KERNEL || -+ select_fd_posix_path(s, &sock) == PATH_KERNEL) { -+ return posix_api->send_msg(s, message, flags); - } - -- return posix_api->send_msg(s, message, flags); -+ return do_lwip_sendmsg_to_stack(sock, s, message, flags); - } - - static inline ssize_t udp_recvfrom(struct lwip_sock *sock, int32_t sockfd, void *buf, size_t len, int32_t flags, -@@ -596,7 +540,7 @@ static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t - } - - struct lwip_sock *sock = NULL; -- if (select_path(sockfd, &sock) == PATH_LWIP) { -+ if (select_fd_posix_path(sockfd, &sock) == PATH_LWIP) { - if (NETCONN_IS_UDP(sock)) { - return udp_recvfrom(sock, sockfd, buf, len, flags, addr, addrlen); - } else { -@@ -611,7 +555,7 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int - const struct sockaddr *addr, socklen_t addrlen) - { - struct lwip_sock *sock = NULL; -- if (select_path(sockfd, &sock) != PATH_LWIP) { -+ if (select_fd_posix_path(sockfd, &sock) != PATH_LWIP) { - return posix_api->send_to(sockfd, buf, len, flags, addr, addrlen); - } - -@@ -621,7 +565,8 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int - static inline int32_t do_close(int32_t s) - { - struct lwip_sock *sock = NULL; -- if (select_path(s, &sock) == PATH_KERNEL) { -+ if (select_posix_path() == PATH_KERNEL || -+ select_fd_posix_path(s, &sock) == PATH_KERNEL) { - /* we called lwip_socket, even if kernel fd */ - if (posix_api != NULL && !posix_api->ues_posix && - /* contain posix_api->close_fn if success */ -@@ -639,7 +584,7 @@ static inline int32_t do_close(int32_t s) - - static int32_t do_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - { -- if (unlikely(posix_api->ues_posix) || fds == NULL || nfds == 0) { -+ if ((select_posix_path() == PATH_KERNEL) || fds == NULL || nfds == 0) { - return posix_api->poll_fn(fds, nfds, timeout); - } - -@@ -684,7 +629,8 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct - val = va_arg(ap, typeof(val)); \ - va_end(ap); \ - struct lwip_sock *sock = NULL; \ -- if (select_path(_fd, &sock) == PATH_KERNEL) \ -+ if (select_posix_path() == PATH_KERNEL || \ -+ select_fd_posix_path(_fd, &sock) == PATH_KERNEL) \ - return _fcntl_fn(_fd, _cmd, val); \ - int32_t ret = _fcntl_fn(_fd, _cmd, val); \ - if (ret == -1) \ -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 0eca86e..189459a 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -223,7 +223,8 @@ static int32_t parse_host_addr(void) - int32_t match_host_addr(uint32_t addr) - { - /* network byte order */ -- if (addr == g_config_params.host_addr.addr) { -+ if (addr == g_config_params.host_addr.addr || -+ addr == INADDR_ANY) { - return 1; - } - return 0; -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 2183e3a..b6e9bf1 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -285,7 +285,7 @@ __attribute__((constructor)) void gazelle_network_init(void) - } - - if (stack_thread_setup() != 0) { -- LSTACK_EXIT(1, "stack_init_in_setup failed\n"); -+ LSTACK_EXIT(1, "stack_thread_setup failed\n"); - } - - /* lwip initialization */ -diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c -index e3a98fc..1d68501 100644 ---- a/src/lstack/core/lstack_preload.c -+++ b/src/lstack/core/lstack_preload.c -@@ -12,8 +12,13 @@ - #include - #include - #include -+#define __USE_GNU -+#include -+#include - --#include "securec.h" -+#include -+#include -+#include - - #include "lstack_log.h" - #include "lstack_preload.h" -@@ -22,10 +27,17 @@ - #define LSTACK_SO_NAME "liblstack.so" - #define LSTACK_PRELOAD_NAME_LEN PATH_MAX - #define LSTACK_PRELOAD_ENV_PROC "GAZELLE_BIND_PROCNAME" -+#define LSTACK_PRELOAD_ENV_THRD "GAZELLE_THREAD_NAME" -+ -+#define EXCLUDE_THRD_CNT 1 -+const static char *g_exclude_thread[EXCLUDE_THRD_CNT] = {"eal-intr-thread"}; -+static PER_THREAD enum KERNEL_LWIP_PATH g_preload_thrdpath = PATH_UNKNOW; - - struct lstack_preload { - int32_t preload_switch; - char env_procname[LSTACK_PRELOAD_NAME_LEN]; -+ bool get_thrdname; -+ char env_thrdname[LSTACK_PRELOAD_NAME_LEN]; - }; - static struct lstack_preload g_preload_info = {0}; - -@@ -52,12 +64,104 @@ static int32_t preload_check_bind_proc(void) - return -1; - } - -+static void preload_get_thrdname(void) -+{ -+ g_preload_info.get_thrdname = true; -+ -+ char *enval = NULL; -+ enval = getenv(LSTACK_PRELOAD_ENV_THRD); -+ if (enval == NULL) { -+ return; -+ } -+ if (strcpy_s(g_preload_info.env_thrdname, LSTACK_PRELOAD_NAME_LEN, enval) != EOK) { -+ return; -+ } -+ -+ LSTACK_PRE_LOG(LSTACK_INFO, "thread name=%s ok\n", g_preload_info.env_thrdname); -+} -+ -+enum KERNEL_LWIP_PATH select_fd_posix_path(int32_t fd, struct lwip_sock **socket) -+{ -+ struct lwip_sock *sock = get_socket_by_fd(fd); -+ -+ /* AF_UNIX case */ -+ if (!sock || !sock->conn || CONN_TYPE_IS_HOST(sock->conn)) { -+ return PATH_KERNEL; -+ } -+ -+ if (socket) { -+ *socket = sock; -+ } -+ -+ if (likely(CONN_TYPE_IS_LIBOS(sock->conn))) { -+ return PATH_LWIP; -+ } -+ -+ return PATH_UNKNOW; -+} -+ -+enum KERNEL_LWIP_PATH select_posix_path(void) -+{ -+ if (unlikely(posix_api == NULL)) { -+ /* -+ * posix api maybe call before gazelle init -+ * So, we must call posix_api_init at the head of select_path -+ */ -+ if (posix_api_init() != 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "posix_api_init failed\n"); -+ } -+ return PATH_KERNEL; -+ } -+ -+ if (unlikely(posix_api->ues_posix)) { -+ return PATH_KERNEL; -+ } -+ -+ if (g_preload_thrdpath != PATH_UNKNOW) { -+ return g_preload_thrdpath; -+ } -+ -+ if (!g_preload_info.get_thrdname) { -+ preload_get_thrdname(); -+ } -+ -+ char thread_name[PATH_MAX] = {0}; -+ if (pthread_getname_np(pthread_self(), thread_name, PATH_MAX) != 0) { -+ g_preload_thrdpath = PATH_KERNEL; -+ return PATH_KERNEL; -+ } -+ -+ /* exclude dpdk thread */ -+ for (int i = 0; i < EXCLUDE_THRD_CNT; i++) { -+ if (strstr(thread_name, g_exclude_thread[i]) != NULL) { -+ g_preload_thrdpath = PATH_KERNEL; -+ return PATH_KERNEL; -+ } -+ } -+ -+ /* not set GAZELLE_THREAD_NAME, select all thread */ -+ if (g_preload_info.env_thrdname[0] == '\0') { -+ g_preload_thrdpath = PATH_LWIP; -+ return PATH_LWIP; -+ } -+ -+ if (strstr(thread_name, g_preload_info.env_thrdname) == NULL) { -+ g_preload_thrdpath = PATH_KERNEL; -+ return PATH_KERNEL; -+ } -+ -+ g_preload_thrdpath = PATH_LWIP; -+ return PATH_LWIP; -+} -+ - int preload_info_init(void) - { - char *enval = NULL; - - g_preload_info.preload_switch = 0; - -+ preload_get_thrdname(); -+ - enval = getenv(LSTACK_PRELOAD_ENV_SYS); - if (enval == NULL) { - return 0; -@@ -75,6 +179,14 @@ int preload_info_init(void) - return -1; - } - -+ enval = getenv(LSTACK_PRELOAD_ENV_THRD); -+ if (enval != NULL) { -+ if (strcpy_s(g_preload_info.env_thrdname, LSTACK_PRELOAD_NAME_LEN, enval) != EOK) { -+ return -1; -+ } -+ g_preload_info.get_thrdname = true; -+ } -+ - 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_preload.h b/src/lstack/include/lstack_preload.h -index 4ba6525..0ad7877 100644 ---- a/src/lstack/include/lstack_preload.h -+++ b/src/lstack/include/lstack_preload.h -@@ -11,6 +11,15 @@ - */ - #ifndef __LSTACK_PRELOAD_H__ - #define __LSTACK_PRELOAD_H__ -+#include - -+enum KERNEL_LWIP_PATH { -+ PATH_KERNEL = 0, -+ PATH_LWIP, -+ PATH_UNKNOW, -+}; -+ -+enum KERNEL_LWIP_PATH select_posix_path(void); -+enum KERNEL_LWIP_PATH select_fd_posix_path(int32_t fd, struct lwip_sock **socket); - int preload_info_init(void); - #endif --- -2.23.0 - diff --git a/0019-cfg-add-run-to-completion-mode-configure.patch b/0019-cfg-add-run-to-completion-mode-configure.patch deleted file mode 100644 index b11a79d976a9b5813fde11fd08a6a16ce71c5a72..0000000000000000000000000000000000000000 --- a/0019-cfg-add-run-to-completion-mode-configure.patch +++ /dev/null @@ -1,91 +0,0 @@ -From 3208a2f1ada7c8c388bdea356d38c9edef1e05dd Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sun, 8 Oct 2023 19:48:45 +0800 -Subject: [PATCH] cfg: add run-to-completion mode configure - ---- - src/lstack/core/lstack_cfg.c | 30 ++++++++++++++++++++++++++++++ - src/lstack/include/lstack_cfg.h | 1 + - src/lstack/lstack.conf | 2 ++ - 3 files changed, 33 insertions(+) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 0eca86e..951e6e8 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -76,6 +76,7 @@ static int32_t parse_use_sockmap(void); - static int32_t parse_udp_enable(void); - static int32_t parse_nic_rxqueue_size(void); - static int32_t parse_nic_txqueue_size(void); -+static int32_t parse_stack_thread_mode(void); - - #define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \ - do { \ -@@ -135,6 +136,7 @@ static struct config_vector_t g_config_tbl[] = { - { "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 }, - { NULL, NULL } - }; - -@@ -1183,3 +1185,31 @@ static int32_t parse_nic_txqueue_size(void) - NIC_QUEUE_SIZE_MIN, NIC_QUEUE_SIZE_MAX, ret); - return ret; - } -+ -+static int32_t parse_stack_thread_mode(void) -+{ -+ const config_setting_t *thread_mode = NULL; -+ const char *args = NULL; -+ -+ thread_mode = config_lookup(&g_config, "stack_thread_mode"); -+ if (thread_mode == NULL) { -+ g_config_params.stack_mode_rtc = false; -+ return 0; -+ } -+ -+ args = config_setting_get_string(thread_mode); -+ if (args == NULL) { -+ return -EINVAL; -+ } -+ -+ if (strncmp(args, "run-to-completion", strlen("run-to-completion") + 1) == 0) { -+ g_config_params.stack_mode_rtc = true; -+ } else if (strncmp(args, "run-to-wakeup", strlen("run-to-wakeup") + 1) == 0) { -+ g_config_params.stack_mode_rtc = false; -+ } else { -+ LSTACK_LOG(ERR, LSTACK, "stack_mode_rtc only support run-to-completion or run-to-wakeup\n"); -+ return -EINVAL; -+ } -+ -+ return 0; -+} -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index e48a501..1d895ec 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -116,6 +116,7 @@ struct cfg_params { - bool use_sockmap; - bool udp_enable; - struct cfg_nic_params nic; -+ bool stack_mode_rtc; - }; - - struct cfg_params *get_global_cfg_params(void); -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index ad574e1..48973fe 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -10,6 +10,8 @@ - - dpdk_args=["--socket-mem", "2048,0,0,0", "--huge-dir", "/mnt/hugepages-lstack", "--proc-type", "primary", "--legacy-mem", "--map-perfect"] - -+stack_thread_mode="run-to-wakeup" -+ - use_ltran=1 - kni_switch=0 - --- -2.23.0 - diff --git a/0020-statck-the-for-loop-in-lstack-thread-is-defined-as-s.patch b/0020-statck-the-for-loop-in-lstack-thread-is-defined-as-s.patch deleted file mode 100644 index 0e115925b44f5abaf4362f9680ea8de3e07cfe6e..0000000000000000000000000000000000000000 --- a/0020-statck-the-for-loop-in-lstack-thread-is-defined-as-s.patch +++ /dev/null @@ -1,136 +0,0 @@ -From 71defaec9e10ee23bf9b3e01989dac4feab94d82 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 9 Oct 2023 10:28:30 +0800 -Subject: [PATCH] statck: the for loop in lstack thread is defined as - stack_polling - ---- - src/lstack/core/lstack_protocol_stack.c | 85 ++++++++++++---------- - src/lstack/include/lstack_protocol_stack.h | 1 + - 2 files changed, 49 insertions(+), 37 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 09cba14..ea85bc1 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -432,18 +432,60 @@ END: - return NULL; - } - --static void* gazelle_stack_thread(void *arg) -+void stack_polling(uint32_t wakeup_tick) - { -- struct thread_params *t_params = (struct thread_params*) arg; -- -- uint16_t queue_id = t_params->queue_id; - struct cfg_params *cfg = get_global_cfg_params(); - uint8_t use_ltran_flag = cfg->use_ltran; - bool kni_switch = cfg->kni_switch; - bool use_sockmap = cfg->use_sockmap; -- uint32_t read_connect_number = cfg->read_connect_number; -+ bool stack_mode_rtc = cfg->stack_mode_rtc; - uint32_t rpc_number = cfg->rpc_number; - uint32_t nic_read_number = cfg->nic_read_number; -+ uint32_t read_connect_number = cfg->read_connect_number; -+ struct protocol_stack *stack = get_protocol_stack(); -+ -+ poll_rpc_msg(stack, rpc_number); -+ gazelle_eth_dev_poll(stack, use_ltran_flag, nic_read_number); -+ sys_timer_run(); -+ if (cfg->low_power_mod != 0) { -+ low_power_idling(stack); -+ } -+ -+ if (stack_mode_rtc) { -+ return; -+ } -+ -+ do_lwip_read_recvlist(stack, read_connect_number); -+ if ((wakeup_tick & 0xf) == 0) { -+ wakeup_stack_epoll(stack); -+ } -+ -+ /* run to completion mode currently does not support sockmap */ -+ if (use_sockmap) { -+ netif_poll(&stack->netif); -+ /* reduce traversal times */ -+ if ((wakeup_tick & 0xff) == 0) { -+ read_same_node_recv_list(stack); -+ } -+ } -+ -+ /* run to completion mode currently does not support kni */ -+ /* KNI requests are generally low-rate I/Os, -+ * so processing KNI requests only in the thread with queue_id No.0 is sufficient. */ -+ if (kni_switch && !stack->queue_id && !(wakeup_tick & 0xfff)) { -+ rte_kni_handle_request(get_gazelle_kni()); -+ if (get_kni_started()) { -+ kni_handle_rx(get_port_id()); -+ } -+ } -+ return; -+} -+ -+static void* gazelle_stack_thread(void *arg) -+{ -+ struct thread_params *t_params = (struct thread_params*) arg; -+ -+ uint16_t queue_id = t_params->queue_id; - uint32_t wakeup_tick = 0; - - struct protocol_stack *stack = stack_thread_init(arg); -@@ -461,39 +503,8 @@ static void* gazelle_stack_thread(void *arg) - LSTACK_LOG(INFO, LSTACK, "stack_%02hu init success\n", queue_id); - - for (;;) { -- poll_rpc_msg(stack, rpc_number); -- -- gazelle_eth_dev_poll(stack, use_ltran_flag, nic_read_number); -- -- if (use_sockmap) { -- netif_poll(&stack->netif); -- /* reduce traversal times */ -- if ((wakeup_tick & 0xff) == 0) { -- read_same_node_recv_list(stack); -- } -- } -- do_lwip_read_recvlist(stack, read_connect_number); -- -- if ((wakeup_tick & 0xf) == 0) { -- wakeup_stack_epoll(stack); -- } -- -- /* KNI requests are generally low-rate I/Os, -- * so processing KNI requests only in the thread with queue_id No.0 is sufficient. */ -- if (kni_switch && !queue_id && !(wakeup_tick & 0xfff)) { -- rte_kni_handle_request(get_gazelle_kni()); -- if (get_kni_started()) { -- kni_handle_rx(get_port_id()); -- } -- } -- -+ stack_polling(wakeup_tick); - wakeup_tick++; -- -- sys_timer_run(); -- -- if (cfg->low_power_mod != 0) { -- low_power_idling(stack); -- } - } - - return NULL; -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index a4f6ac2..7cb37bf 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -167,5 +167,6 @@ void stack_replenish_sendring(struct rpc_msg *msg); - void stack_get_conntable(struct rpc_msg *msg); - void stack_get_connnum(struct rpc_msg *msg); - void stack_recvlist_count(struct rpc_msg *msg); -+void stack_polling(uint32_t wakeup_tick); - void kni_handle_tx(struct rte_mbuf *mbuf); - #endif --- -2.27.0 - diff --git a/0021-delete_rule-bug.patch b/0021-delete_rule-bug.patch deleted file mode 100644 index a78f1f028ede5deb8fc1120c207999f7c0fb4d80..0000000000000000000000000000000000000000 --- a/0021-delete_rule-bug.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 09c2b39b22397272668e49060e5f3e3b50fd40b4 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Fri, 20 Oct 2023 09:52:11 +0800 -Subject: [PATCH] delete_rule bug - ---- - src/lstack/netif/lstack_ethdev.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 30c3c9a..6e4c9de 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -189,7 +189,7 @@ void delete_rule(char* rule_key) - { - struct flow_rule *rule = NULL; - HASH_FIND_STR(g_flow_rules, rule_key, rule); -- if (rule == NULL) { -+ if (rule != NULL) { - HASH_DEL(g_flow_rules, rule); - free(rule); - } --- -2.27.0 - diff --git a/0022-tools-gazelle_setup-adapt-non-ltran-mode.patch b/0022-tools-gazelle_setup-adapt-non-ltran-mode.patch deleted file mode 100644 index 539d25da147e4893aa17facec2ad63aff4c31c10..0000000000000000000000000000000000000000 --- a/0022-tools-gazelle_setup-adapt-non-ltran-mode.patch +++ /dev/null @@ -1,198 +0,0 @@ -From 1ebdb7124823835cd29d62c8a81a0b8010c1d754 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Fri, 20 Oct 2023 19:44:52 +0800 -Subject: [PATCH] tools: gazelle_setup adapt non ltran mode - ---- - tools/gazelle_common.sh | 40 ++++++++++++++++++++-------------------- - tools/gazelle_setup.sh | 38 ++++++++++++++++++-------------------- - 2 files changed, 38 insertions(+), 40 deletions(-) - -diff --git a/tools/gazelle_common.sh b/tools/gazelle_common.sh -index b4c011a..fac0d68 100644 ---- a/tools/gazelle_common.sh -+++ b/tools/gazelle_common.sh -@@ -231,18 +231,18 @@ install_nic_mod() { - } - - create_mnt_huge() { -- msg_show "Creating /mnt/hugepages and mounting as hugetlbfs" -- sudo mkdir -p /mnt/hugepages -- sudo mkdir -p /mnt/hugepages-2M -+ msg_show "Creating /mnt/hugepages-ltran and mounting as hugetlbfs" -+ sudo mkdir -p /mnt/hugepages-ltran -+ sudo mkdir -p /mnt/hugepages-lstack - -- grep -s "/mnt/hugepages " /proc/mounts > /dev/null -+ grep -s "/mnt/hugepages-ltran " /proc/mounts > /dev/null - if [ $? -ne 0 ]; then -- sudo mount -t hugetlbfs nodev /mnt/hugepages -+ sudo mount -t hugetlbfs nodev /mnt/hugepages-ltran - fi - -- grep -s "/mnt/hugepages-2M " /proc/mounts > /dev/null -+ grep -s "/mnt/hugepages-lstack " /proc/mounts > /dev/null - if [ $? -ne 0 ]; then -- sudo mount -t hugetlbfs nodev /mnt/hugepages-2M -+ sudo mount -t hugetlbfs nodev /mnt/hugepages-lstack - fi - } - -@@ -285,21 +285,21 @@ set_numa_pages() { - - # Removes all reserved hugepages. - clear_huge_pages() { -- msg_show "Unmounting /mnt/hugepages and removing directory" -- grep -s "/mnt/hugepages " /proc/mounts > /dev/null -+ msg_show "Unmounting /mnt/hugepages-ltran and removing directory" -+ grep -s "/mnt/hugepages-ltran " /proc/mounts > /dev/null - if [ $? -eq 0 ]; then -- sudo umount /mnt/hugepages -+ sudo umount /mnt/hugepages-ltran - if [ $? -ne 0 ]; then -- msg_err "sudo umount /mnt/hugepages failed!" -+ msg_err "sudo umount /mnt/hugepages-ltran failed!" - return 1 - fi - fi - -- grep -s "/mnt/hugepages-2M " /proc/mounts > /dev/null -+ grep -s "/mnt/hugepages-lstack " /proc/mounts > /dev/null - if [ $? -eq 0 ]; then -- sudo umount /mnt/hugepages-2M -+ sudo umount /mnt/hugepages-lstack - if [ $? -ne 0 ]; then -- msg_err "sudo umount /mnt/hugepages-2M failed!" -+ msg_err "sudo umount /mnt/hugepages-lstack failed!" - return 1 - fi - fi -@@ -312,17 +312,17 @@ clear_huge_pages() { - sudo sh .echo_tmp - rm -f .echo_tmp - -- if [ -d /mnt/hugepages ]; then -- sudo rm -R /mnt/hugepages -+ if [ -d /mnt/hugepages-ltran ]; then -+ sudo rm -R /mnt/hugepages-ltran - if [ $? -ne 0 ]; then -- msg_err "sudo rm -R /mnt/hugepages failed!" -+ msg_err "sudo rm -R /mnt/hugepages-ltran failed!" - return 1 - fi - fi -- if [ -d /mnt/hugepages-2M ]; then -- sudo rm -R /mnt/hugepages-2M -+ if [ -d /mnt/hugepages-lstack ]; then -+ sudo rm -R /mnt/hugepages-lstack - if [ $? -ne 0 ]; then -- msg_err "sudo rm -R /mnt/hugepages failed!" -+ msg_err "sudo rm -R /mnt/hugepages-lstack failed!" - return 1 - fi - fi -diff --git a/tools/gazelle_setup.sh b/tools/gazelle_setup.sh -index 014d333..c3ad830 100644 ---- a/tools/gazelle_setup.sh -+++ b/tools/gazelle_setup.sh -@@ -66,8 +66,10 @@ show_usage() { - echo " [-l|--lowpower=]" - echo " [--ltrancore=]" - echo " [--lstackcore=]" -+ echo " [--useltran=]" -+ echo " [--listenshadow=]" - echo "examples:" -- echo " $0 -i eth0 -n 1024,1024 -d 1/0 -k 1/0 -l 1/0 --ltrancore 0,1 --lstackcore 2-3" -+ echo " $0 -i eth0 -n 1024,1024 -d 1/0 -k 1/0 -l 1/0 --ltrancore 0,1 --lstackcore 2-3 --useltran 0/1 --listenshadow 0/1" - } - - check_init() { -@@ -155,14 +157,13 @@ check_args() { - g_low_power=${g_low_power:-0} - check_switch_param $g_low_power - ret=$(($? + ret)) -- g_useltran=${g_useltran:-1} -+ g_useltran=${g_useltran:-0} - check_switch_param $g_useltran -- g_listen_shadow=${g_listen_shadow:-0} -+ g_listen_shadow=${g_listen_shadow:-1} - check_switch_param $g_listen_shadow - ret=$(($? + ret)) - g_ltrancore=${g_ltrancore:-0,1} - g_lstackcore=${g_lstackcore:-2} -- g_wakeupcpus=${g_lstackcore} - if [ $ret -eq 0 ]; then - msg_show "the args is reasonable..." - else -@@ -278,6 +279,12 @@ gen_lstack_conf() { - sed -i "/^gateway_addr/c gateway_addr=\"$g_gateway\"" $CONF_DIR/lstack.conf - sed -i "/^devices/c devices=\"$g_kni_mac\"" $CONF_DIR/lstack.conf - -+ if [ ${g_useltran} -eq 0 ]; then -+ sed -i "/^kni_switch/c kni_switch = $g_kni_switch" $CONF_DIR/lstack.conf -+ else -+ sed -i "/^kni_switch/c kni_switch = 0" $CONF_DIR/lstack.conf -+ fi -+ - shadow_exist=$(grep listen_shadow $CONF_DIR/lstack.conf) - if [ -n "${shadow_exist}" ];then - sed -i "/^listen_shadow/c listen_shadow = $g_listen_shadow" $CONF_DIR/lstack.conf -@@ -289,20 +296,15 @@ gen_lstack_conf() { - local old_lstackcore=$(grep num_cpus $CONF_DIR/lstack.conf | awk -F= '{print $2}' | awk -F "\"" '{print $2}') - sed -i "/^num_cpus/s/${old_lstackcore}/${g_lstackcore}/" $CONF_DIR/lstack.conf - -- # wakeup_cpus -- local old_wakeupcpus=$(grep wakeup_cpus $CONF_DIR/lstack.conf | awk -F= '{print $2}' | awk -F "\"" '{print $2}') -- if [ -n "${g_wakeupcpus}" ]; then -- sed -i "/^wakeup_cpus/s/${old_wakeupcpus}/${g_wakeupcpus}/" $CONF_DIR/lstack.conf -- fi -- - local old_numa=$(grep dpdk_args $CONF_DIR/lstack.conf | awk -F "-socket-mem" '{print $2}' | awk '{print $2}' | awk -F "\"" '{print $2}') - old_numa="\"${old_numa}\"," - sed -i "/^dpdk_args/s/${old_numa}/\"${g_hugepages}\",/" $CONF_DIR/lstack.conf - local cpu_count=$(parse_cpu_count ${g_lstackcore}) -- local mbuf_pool_size=$(expr 200000 \* ${cpu_count} + 8192) -- sed -i "/^mbuf_pool_size/c mbuf_pool_size=${mbuf_pool_size}" $CONF_DIR/lstack.conf -+ tcp_conn_count=1500 -+ mbuf_count_per_conn=$(expr 170 \* ${cpu_count}) - -- # export LSTACK_CONF_PATH=$CONF_DIR/lstack.conf -+ sed -i "/^tcp_conn_count/c tcp_conn_count=${tcp_conn_count}" $CONF_DIR/lstack.conf -+ sed -i "/^mbuf_count_per_conn/c mbuf_count_per_conn=${mbuf_count_per_conn}" $CONF_DIR/lstack.conf - } - - gen_run_param() { -@@ -399,10 +401,6 @@ while true; do - g_lstackcore=$2 - shift 2 - ;; -- --wakeupcpus) -- g_wakeupcpus=$2 -- shift 2 -- ;; - -h | --help) - show_usage - shift 1 -@@ -458,8 +456,8 @@ gen_run_param - msg_show "-----------------" - msg_show "start dpdk" - setup_dpdk --__chown /mnt/hugepages --__chown /mnt/hugepages-2M -+__chown /mnt/hugepages-ltran -+__chown /mnt/hugepages-lstack - - ############################################## - # generate the conf file -@@ -504,7 +502,7 @@ fi - ############################################## - # start ltran - if [ $g_useltran -eq 0 ];then -- msg_show "only gen lstack conf" -+ msg_show "gen lstack conf success" - exit 0 - fi - msg_show "start ltran on $g_conn_if" --- -2.27.0 - diff --git a/0023-wrap-add-run-to-completion-wakeup-mode-api.patch b/0023-wrap-add-run-to-completion-wakeup-mode-api.patch deleted file mode 100644 index cbdb8641cbe5c7a16288b282dab9f8534b147b8a..0000000000000000000000000000000000000000 --- a/0023-wrap-add-run-to-completion-wakeup-mode-api.patch +++ /dev/null @@ -1,993 +0,0 @@ -From 476b225bc50737678223fa29757b0ac08f1a500d Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sun, 8 Oct 2023 20:59:57 +0800 -Subject: [PATCH] wrap: add run-to-completion/wakeup mode api - ---- - src/lstack/api/dir.mk | 2 +- - src/lstack/api/lstack_rtc_api.c | 72 ++++++ - src/lstack/api/lstack_rtw_api.c | 239 ++++++++++++++++++ - src/lstack/api/lstack_wrap.c | 206 +++++++-------- - src/lstack/core/lstack_init.c | 3 + - src/lstack/core/lstack_lwip.c | 2 +- - src/lstack/include/lstack_lwip.h | 2 +- - .../lstack_socket.h => lstack_rtc_api.h} | 59 +++-- - src/lstack/include/lstack_rtw_api.h | 47 ++++ - src/lstack/include/lstack_wrap.h | 19 ++ - 10 files changed, 514 insertions(+), 137 deletions(-) - create mode 100644 src/lstack/api/lstack_rtc_api.c - create mode 100644 src/lstack/api/lstack_rtw_api.c - rename src/lstack/include/{posix/lstack_socket.h => lstack_rtc_api.h} (53%) - create mode 100644 src/lstack/include/lstack_rtw_api.h - create mode 100644 src/lstack/include/lstack_wrap.h - -diff --git a/src/lstack/api/dir.mk b/src/lstack/api/dir.mk -index f5370a2..ffbb137 100644 ---- a/src/lstack/api/dir.mk -+++ b/src/lstack/api/dir.mk -@@ -8,7 +8,7 @@ - # PURPOSE. - # See the Mulan PSL v2 for more details. - --SRC = lstack_epoll.c lstack_signal.c lstack_fork.c lstack_wrap.c -+SRC = lstack_epoll.c lstack_signal.c lstack_fork.c lstack_wrap.c lstack_rtw_api.c lstack_rtc_api.c - - $(eval $(call register_dir, api, $(SRC))) - -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -new file mode 100644 -index 0000000..b7c6380 ---- /dev/null -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -0,0 +1,72 @@ -+/* -+* 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 -+#include -+#include -+#include -+#include -+#include -+#include "posix/lstack_epoll.h" -+#include "lstack_log.h" -+#include "lstack_cfg.h" -+#include "lstack_protocol_stack.h" -+#include "lstack_rtc_api.h" -+ -+int rtc_poll(struct pollfd *fds, nfds_t nfds, int timeout) -+{ -+ return -1; -+} -+ -+int rtc_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) -+{ -+ return -1; -+} -+ -+int rtc_socket(int domain, int type, int protocol) -+{ -+ int ret; -+ -+ /* need call stack thread init function */ -+ ret = lwip_socket(domain, type, protocol); -+ struct lwip_sock *sock = get_socket(ret); -+ if (sock != NULL) { -+ sock->stack = get_protocol_stack(); -+ sock->epoll_events = 0; -+ sock->events = 0; -+ sock->wakeup = NULL; -+ init_list_node_null(&sock->event_list); -+ } -+ return ret; -+} -+ -+int rtc_close(int s) -+{ -+ return lwip_close(s); -+} -+ -+int rtc_epoll_create(int flags) -+{ -+ /* need call stack thread init function */ -+ return lstack_epoll_create(flags); -+} -+ -+int rtc_epoll_create1(int flags) -+{ -+ /* need call stack thread init function */ -+ return lstack_epoll_create1(flags); -+} -+ -+int rtc_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) -+{ -+ return lstack_epoll_ctl(epfd, op, fd, event); -+} -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -new file mode 100644 -index 0000000..9b8678a ---- /dev/null -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -0,0 +1,239 @@ -+/* -+* 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 -+#include -+#include -+#include -+ -+#include -+ -+#include "lstack_thread_rpc.h" -+#include "posix/lstack_epoll.h" -+#include "lstack_protocol_stack.h" -+#include "lstack_cfg.h" -+#include "lstack_lwip.h" -+#include "lstack_rtw_api.h" -+ -+int rtw_socket(int domain, int type, int protocol) -+{ -+ return rpc_call_socket(domain, type, protocol); -+} -+ -+int rtw_accept(int s, struct sockaddr *addr, socklen_t *addrlen) -+{ -+ return stack_broadcast_accept(s, addr, addrlen); -+} -+ -+int rtw_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) -+{ -+ return stack_broadcast_accept4(s, addr, addrlen, flags); -+} -+ -+int rtw_bind(int s, const struct sockaddr *name, socklen_t namelen) -+{ -+ struct lwip_sock *sock = get_socket_by_fd(s); -+ -+ if (NETCONN_IS_UDP(sock) && get_global_cfg_params()->listen_shadow) { -+ return stack_broadcast_bind(s, name, namelen); -+ } else { -+ return stack_single_bind(s, name, namelen); -+ } -+} -+ -+int rtw_listen(int s, int backlog) -+{ -+ if (!get_global_cfg_params()->tuple_filter && -+ !get_global_cfg_params()->listen_shadow) { -+ return stack_single_listen(s, backlog); -+ } else { -+ return stack_broadcast_listen(s, backlog); -+ } -+} -+ -+int rtw_connect(int s, const struct sockaddr *name, socklen_t namelen) -+{ -+ return rpc_call_connect(s, name, namelen); -+} -+ -+int rtw_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) -+{ -+ return rpc_call_setsockopt(s, level, optname, optval, optlen); -+} -+ -+int rtw_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) -+{ -+ return rpc_call_getsockopt(s, level, optname, optval, optlen); -+} -+ -+int rtw_getpeername(int s, struct sockaddr *name, socklen_t *namelen) -+{ -+ return rpc_call_getpeername(s, name, namelen); -+} -+ -+int rtw_getsockname(int s, struct sockaddr *name, socklen_t *namelen) -+{ -+ return rpc_call_getsockname(s, name, namelen); -+} -+ -+ssize_t rtw_read(int s, void *mem, size_t len) -+{ -+ return do_lwip_read_from_stack(s, mem, len, 0, NULL, NULL); -+} -+ -+ssize_t rtw_readv(int s, const struct iovec *iov, int iovcnt) -+{ -+ struct msghdr msg; -+ -+ msg.msg_name = NULL; -+ msg.msg_namelen = 0; -+ msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov); -+ msg.msg_iovlen = iovcnt; -+ msg.msg_control = NULL; -+ msg.msg_controllen = 0; -+ msg.msg_flags = 0; -+ ssize_t result = do_lwip_recvmsg_from_stack(s, &msg, 0); -+ if (result == -1 && errno == EAGAIN) { -+ errno = 0; -+ return 0; -+ } -+ return result; -+} -+ -+ssize_t rtw_write(int s, const void *mem, size_t size) -+{ -+ return do_lwip_send_to_stack(s, mem, size, 0, NULL, 0); -+} -+ -+ssize_t rtw_writev(int s, const struct iovec *iov, int iovcnt) -+{ -+ struct lwip_sock *sock = get_socket_by_fd(s); -+ struct msghdr msg; -+ -+ msg.msg_name = NULL; -+ msg.msg_namelen = 0; -+ msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov); -+ msg.msg_iovlen = iovcnt; -+ msg.msg_control = NULL; -+ msg.msg_controllen = 0; -+ msg.msg_flags = 0; -+ return do_lwip_sendmsg_to_stack(sock, s, &msg, 0); -+} -+ -+ssize_t rtw_recv(int sockfd, void *buf, size_t len, int flags) -+{ -+ return do_lwip_read_from_stack(sockfd, buf, len, flags, NULL, NULL); -+} -+ -+ssize_t rtw_send(int sockfd, const void *buf, size_t len, int flags) -+{ -+ return do_lwip_send_to_stack(sockfd, buf, len, flags, NULL, 0); -+} -+ -+ssize_t rtw_recvmsg(int s, const struct msghdr *message, int flags) -+{ -+ return do_lwip_recvmsg_from_stack(s, message, flags); -+} -+ -+ssize_t rtw_sendmsg(int s, const struct msghdr *message, int flags) -+{ -+ struct lwip_sock *sock = get_socket_by_fd(s); -+ return do_lwip_sendmsg_to_stack(sock, s, message, flags); -+} -+ -+static ssize_t rtw_udp_recvfrom(int sockfd, void *buf, size_t len, int flags, -+ struct sockaddr *addr, socklen_t *addrlen) -+{ -+ struct lwip_sock *sock = get_socket_by_fd(sockfd); -+ int ret; -+ -+ while (1) { -+ ret = do_lwip_read_from_stack(sockfd, buf, len, flags, addr, addrlen); -+ if (ret > 0) { -+ return ret; -+ } -+ if (ret <= 0 && errno != EAGAIN) { -+ return -1; -+ } -+ sock = sock->listen_next; -+ if (sock != NULL && sock->conn != NULL) { -+ sockfd = sock->conn->socket; -+ } else { -+ if (sock == NULL) { -+ errno = EAGAIN; -+ return -1; -+ } else { -+ errno = ENOTCONN; -+ return -1; -+ } -+ } -+ } -+} -+ -+static inline ssize_t rtw_tcp_recvfrom(int sockfd, void *buf, size_t len, int flags, -+ struct sockaddr *addr, socklen_t *addrlen) -+{ -+ return do_lwip_read_from_stack(sockfd, buf, len, flags, addr, addrlen); -+} -+ -+ -+ssize_t rtw_recvfrom(int sockfd, void *buf, size_t len, int flags, -+ struct sockaddr *addr, socklen_t *addrlen) -+{ -+ struct lwip_sock *sock = get_socket_by_fd(sockfd); -+ if (NETCONN_IS_UDP(sock)) { -+ return rtw_udp_recvfrom(sockfd, buf, len, flags, addr, addrlen); -+ } else { -+ return rtw_tcp_recvfrom(sockfd, buf, len, flags, addr, addrlen); -+ } -+} -+ -+ssize_t rtw_sendto(int sockfd, const void *buf, size_t len, int flags, -+ const struct sockaddr *addr, socklen_t addrlen) -+{ -+ return do_lwip_send_to_stack(sockfd, buf, len, flags, addr, addrlen); -+} -+ -+ -+int rtw_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) -+{ -+ return lstack_epoll_wait(epfd, events, maxevents, timeout); -+} -+ -+int rtw_poll(struct pollfd *fds, nfds_t nfds, int timeout) -+{ -+ return lstack_poll(fds, nfds, timeout); -+} -+ -+int rtw_close(int s) -+{ -+ struct lwip_sock *sock = get_socket(s); -+ if (sock && sock->wakeup && sock->wakeup->epollfd == s) { -+ return lstack_epoll_close(s); -+ } -+ return stack_broadcast_close(s); -+} -+ -+int rtw_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) -+{ -+ return lstack_epoll_ctl(epfd, op, fd, event); -+} -+ -+int rtw_epoll_create1(int flags) -+{ -+ return lstack_epoll_create1(flags); -+} -+ -+int rtw_epoll_create(int flags) -+{ -+ return lstack_epoll_create(flags); -+} -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index ab39a68..a808ee8 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -12,17 +12,12 @@ - - #define _GNU_SOURCE - #include --#include - - #include --#include - #include --#include --#include - #include - #include - #include --#include - #include - #include - -@@ -30,29 +25,94 @@ - #include - #include - --#include "posix/lstack_epoll.h" - #include "posix/lstack_unistd.h" --#include "posix/lstack_socket.h" - #include "lstack_log.h" - #include "lstack_cfg.h" - #include "lstack_lwip.h" --#include "lstack_protocol_stack.h" - #include "gazelle_base_func.h" --#include "lstack_thread_rpc.h" -- - #include "lstack_preload.h" - -+#include "lstack_rtc_api.h" -+#include "lstack_rtw_api.h" -+ - #ifndef SOCK_TYPE_MASK - #define SOCK_TYPE_MASK 0xf - #endif - -+posix_api_t g_wrap_api_value; -+posix_api_t *g_wrap_api; -+ -+void wrap_api_init(void) -+{ -+ if (g_wrap_api != NULL) { -+ return; -+ } -+ -+ g_wrap_api = &g_wrap_api_value; -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ g_wrap_api->socket_fn = rtc_socket; -+ g_wrap_api->accept_fn = lwip_accept; -+ g_wrap_api->accept4_fn = lwip_accept4; -+ g_wrap_api->bind_fn = lwip_bind; -+ g_wrap_api->listen_fn = lwip_listen; -+ g_wrap_api->connect_fn = lwip_connect; -+ g_wrap_api->setsockopt_fn = lwip_setsockopt; -+ g_wrap_api->getsockopt_fn = lwip_getsockopt; -+ g_wrap_api->getpeername_fn = lwip_getpeername; -+ g_wrap_api->getsockname_fn = lwip_getsockname; -+ g_wrap_api->read_fn = lwip_read; -+ g_wrap_api->readv_fn = lwip_readv; -+ g_wrap_api->write_fn = lwip_write; -+ g_wrap_api->writev_fn = lwip_writev; -+ g_wrap_api->recv_fn = lwip_recv; -+ g_wrap_api->send_fn = lwip_send; -+ g_wrap_api->recv_msg = lwip_recvmsg; -+ g_wrap_api->send_msg = lwip_sendmsg; -+ g_wrap_api->recv_from = lwip_recvfrom; -+ g_wrap_api->send_to = lwip_sendto; -+ g_wrap_api->epoll_wait_fn = rtc_epoll_wait; -+ g_wrap_api->poll_fn = rtc_poll; -+ g_wrap_api->close_fn = rtc_close; -+ g_wrap_api->epoll_ctl_fn = rtc_epoll_ctl; -+ g_wrap_api->epoll_create1_fn = rtc_epoll_create1; -+ g_wrap_api->epoll_create_fn = rtc_epoll_create; -+ } else { -+ g_wrap_api->socket_fn = rtw_socket; -+ g_wrap_api->accept_fn = rtw_accept; -+ g_wrap_api->accept4_fn = rtw_accept4; -+ g_wrap_api->bind_fn = rtw_bind; -+ g_wrap_api->listen_fn = rtw_listen; -+ g_wrap_api->connect_fn = rtw_connect; -+ g_wrap_api->setsockopt_fn = rtw_setsockopt; -+ g_wrap_api->getsockopt_fn = rtw_getsockopt; -+ g_wrap_api->getpeername_fn = rtw_getpeername; -+ g_wrap_api->getsockname_fn = rtw_getsockname; -+ g_wrap_api->read_fn = rtw_read; -+ g_wrap_api->readv_fn = rtw_readv; -+ g_wrap_api->write_fn = rtw_write; -+ g_wrap_api->writev_fn = rtw_writev; -+ g_wrap_api->recv_fn = rtw_recv; -+ g_wrap_api->send_fn = rtw_send; -+ g_wrap_api->recv_msg = rtw_recvmsg; -+ g_wrap_api->send_msg = rtw_sendmsg; -+ g_wrap_api->recv_from = rtw_recvfrom; -+ g_wrap_api->send_to = rtw_sendto; -+ g_wrap_api->epoll_wait_fn = rtw_epoll_wait; -+ g_wrap_api->poll_fn = rtw_poll; -+ g_wrap_api->close_fn = rtw_close; -+ g_wrap_api->epoll_ctl_fn = rtw_epoll_ctl; -+ g_wrap_api->epoll_create1_fn = rtw_epoll_create1; -+ g_wrap_api->epoll_create_fn = rtw_epoll_create; -+ } -+} -+ - static inline int32_t do_epoll_create1(int32_t flags) - { - if (select_posix_path() == PATH_KERNEL) { - return posix_api->epoll_create1_fn(flags); - } - -- return lstack_epoll_create1(flags); -+ return g_wrap_api->epoll_create1_fn(flags); - } - - static inline int32_t do_epoll_create(int32_t size) -@@ -61,7 +121,7 @@ static inline int32_t do_epoll_create(int32_t size) - return posix_api->epoll_create_fn(size); - } - -- return lstack_epoll_create(size); -+ return g_wrap_api->epoll_create_fn(size); - } - - static inline int32_t do_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event* event) -@@ -70,7 +130,7 @@ static inline int32_t do_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct - return posix_api->epoll_ctl_fn(epfd, op, fd, event); - } - -- return lstack_epoll_ctl(epfd, op, fd, event); -+ return g_wrap_api->epoll_ctl_fn(epfd, op, fd, event); - } - - static inline int32_t do_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) -@@ -87,7 +147,7 @@ static inline int32_t do_epoll_wait(int32_t epfd, struct epoll_event* events, in - GAZELLE_RETURN(EINVAL); - } - -- return lstack_epoll_wait(epfd, events, maxevents, timeout); -+ return g_wrap_api->epoll_wait_fn(epfd, events, maxevents, timeout); - } - - static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) -@@ -96,7 +156,7 @@ 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 = stack_broadcast_accept(s, addr, addrlen); -+ int32_t fd = g_wrap_api->accept_fn(s, addr, addrlen); - if (fd >= 0) { - return fd; - } -@@ -114,7 +174,7 @@ 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 = stack_broadcast_accept4(s, addr, addrlen, flags); -+ int32_t fd = g_wrap_api->accept4_fn(s, addr, addrlen, flags); - if (fd >= 0) { - return fd; - } -@@ -158,11 +218,7 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - if (match_host_addr(((struct sockaddr_in *)name)->sin_addr.s_addr)) { - /* maybe kni addr */ - posix_api->bind_fn(s, name, namelen); -- if (NETCONN_IS_UDP(sock) && get_global_cfg_params()->listen_shadow) { -- return stack_broadcast_bind(s, name, namelen); -- } else { -- return stack_single_bind(s, name, namelen); -- } -+ return g_wrap_api->bind_fn(s, name, namelen); - } else { - SET_CONN_TYPE_HOST(sock->conn); - return posix_api->bind_fn(s, name, namelen); -@@ -253,7 +309,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - ret = posix_api->connect_fn(s, name, namelen); - SET_CONN_TYPE_HOST(sock->conn); - } else { -- ret = rpc_call_connect(s, name, namelen); -+ ret = g_wrap_api->connect_fn(s, name, namelen); - SET_CONN_TYPE_LIBOS(sock->conn); - } - -@@ -266,13 +322,7 @@ static inline int32_t do_listen(int32_t s, int32_t backlog) - return posix_api->listen_fn(s, backlog); - } - -- int32_t ret; -- if (!get_global_cfg_params()->tuple_filter && -- !get_global_cfg_params()->listen_shadow) { -- ret = stack_single_listen(s, backlog); -- } else { -- ret = stack_broadcast_listen(s, backlog); -- } -+ int32_t ret = g_wrap_api->listen_fn(s, backlog); - if (ret != 0) { - return ret; - } -@@ -287,7 +337,7 @@ static inline int32_t do_getpeername(int32_t s, struct sockaddr *name, socklen_t - } - - if (select_fd_posix_path(s, NULL) == PATH_LWIP) { -- return rpc_call_getpeername(s, name, namelen); -+ return g_wrap_api->getpeername_fn(s, name, namelen); - } - - return posix_api->getpeername_fn(s, name, namelen); -@@ -300,7 +350,7 @@ static inline int32_t do_getsockname(int32_t s, struct sockaddr *name, socklen_t - } - - if (select_fd_posix_path(s, NULL) == PATH_LWIP) { -- return rpc_call_getsockname(s, name, namelen); -+ return g_wrap_api->getsockname_fn(s, name, namelen); - } - - return posix_api->getsockname_fn(s, name, namelen); -@@ -321,7 +371,7 @@ static bool unsupport_optname(int32_t optname) - static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, void *optval, socklen_t *optlen) - { - if (select_fd_posix_path(s, NULL) == PATH_LWIP && !unsupport_optname(optname)) { -- return rpc_call_getsockopt(s, level, optname, optval, optlen); -+ return g_wrap_api->getsockopt_fn(s, level, optname, optval, optlen); - } - - return posix_api->getsockopt_fn(s, level, optname, optval, optlen); -@@ -339,7 +389,7 @@ static inline int32_t do_setsockopt(int32_t s, int32_t level, int32_t optname, c - return ret; - } - -- return rpc_call_setsockopt(s, level, optname, optval, optlen); -+ return g_wrap_api->setsockopt_fn(s, level, optname, optval, optlen); - } - - static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) -@@ -355,7 +405,7 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - return posix_api->socket_fn(domain, type, protocol); - } - -- ret = rpc_call_socket(domain, type, protocol); -+ ret = g_wrap_api->socket_fn(domain, type, protocol); - /* if udp_enable = 1 in lstack.conf, udp protocol must be in user path currently */ - if ((ret >= 0) && (type & SOCK_DGRAM)) { - struct lwip_sock *sock = get_socket(ret); -@@ -382,7 +432,7 @@ static inline ssize_t do_recv(int32_t sockfd, void *buf, size_t len, int32_t fla - return posix_api->recv_fn(sockfd, buf, len, flags); - } - -- return do_lwip_read_from_stack(sockfd, buf, len, flags, NULL, NULL); -+ return g_wrap_api->recv_fn(sockfd, buf, len, flags); - } - - static inline ssize_t do_read(int32_t s, void *mem, size_t len) -@@ -400,7 +450,7 @@ static inline ssize_t do_read(int32_t s, void *mem, size_t len) - return posix_api->read_fn(s, mem, len); - } - -- return do_lwip_read_from_stack(s, mem, len, 0, NULL, NULL); -+ return g_wrap_api->read_fn(s, mem, len); - } - - static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) -@@ -410,21 +460,7 @@ static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) - return posix_api->readv_fn(s, iov, iovcnt); - } - -- struct msghdr msg; -- -- msg.msg_name = NULL; -- msg.msg_namelen = 0; -- msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov); -- msg.msg_iovlen = iovcnt; -- msg.msg_control = NULL; -- msg.msg_controllen = 0; -- msg.msg_flags = 0; -- ssize_t result = do_lwip_recvmsg_from_stack(s, &msg, 0); -- if (result == -1 && errno == EAGAIN) { -- errno = 0; -- return 0; -- } -- return result; -+ return g_wrap_api->readv_fn(s, iov, iovcnt); - } - - static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32_t flags) -@@ -434,7 +470,7 @@ static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32 - return posix_api->send_fn(sockfd, buf, len, flags); - } - -- return do_lwip_send_to_stack(sockfd, buf, len, flags, NULL, 0); -+ return g_wrap_api->send_fn(sockfd, buf, len, flags); - } - - static inline ssize_t do_write(int32_t s, const void *mem, size_t size) -@@ -444,7 +480,7 @@ static inline ssize_t do_write(int32_t s, const void *mem, size_t size) - return posix_api->write_fn(s, mem, size); - } - -- return do_lwip_send_to_stack(s, mem, size, 0, NULL, 0); -+ return g_wrap_api->write_fn(s, mem, size); - } - - static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) -@@ -455,16 +491,7 @@ static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) - return posix_api->writev_fn(s, iov, iovcnt); - } - -- struct msghdr msg; -- -- msg.msg_name = NULL; -- msg.msg_namelen = 0; -- msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov); -- msg.msg_iovlen = iovcnt; -- msg.msg_control = NULL; -- msg.msg_controllen = 0; -- msg.msg_flags = 0; -- return do_lwip_sendmsg_to_stack(sock, s, &msg, 0); -+ return g_wrap_api->writev_fn(s, iov, iovcnt); - } - - static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flags) -@@ -478,7 +505,7 @@ static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flag - return posix_api->recv_msg(s, message, flags); - } - -- return do_lwip_recvmsg_from_stack(s, message, flags); -+ return g_wrap_api->recv_msg(s, message, flags); - } - - static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_t flags) -@@ -493,39 +520,7 @@ static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_ - return posix_api->send_msg(s, message, flags); - } - -- return do_lwip_sendmsg_to_stack(sock, s, message, flags); --} -- --static inline ssize_t udp_recvfrom(struct lwip_sock *sock, int32_t sockfd, void *buf, size_t len, int32_t flags, -- struct sockaddr *addr, socklen_t *addrlen) --{ -- int32_t ret; -- -- while (1) { -- ret = do_lwip_read_from_stack(sockfd, buf, len, flags, addr, addrlen); -- if (ret > 0) { -- return ret; -- } -- if (ret <= 0 && errno != EAGAIN) { -- return -1; -- } -- sock = sock->listen_next; -- if (sock != NULL && sock->conn != NULL) { -- sockfd = sock->conn->socket; -- } else { -- if (sock == NULL) { -- GAZELLE_RETURN(EAGAIN); -- } else { -- GAZELLE_RETURN(ENOTCONN); -- } -- } -- } --} -- --static inline ssize_t tcp_recvfrom(struct lwip_sock *sock, int32_t sockfd, void *buf, size_t len, int32_t flags, -- struct sockaddr *addr, socklen_t *addrlen) --{ -- return do_lwip_read_from_stack(sockfd, buf, len, flags, addr, addrlen); -+ return g_wrap_api->send_msg(s, message, flags); - } - - static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t flags, -@@ -541,11 +536,7 @@ static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t - - struct lwip_sock *sock = NULL; - if (select_fd_posix_path(sockfd, &sock) == PATH_LWIP) { -- if (NETCONN_IS_UDP(sock)) { -- return udp_recvfrom(sock, sockfd, buf, len, flags, addr, addrlen); -- } else { -- return tcp_recvfrom(sock, sockfd, buf, len, flags, addr, addrlen); -- } -+ return g_wrap_api->recv_from(sockfd, buf, len, flags, addr, addrlen); - } - - return posix_api->recv_from(sockfd, buf, len, flags, addr, addrlen); -@@ -559,7 +550,7 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int - return posix_api->send_to(sockfd, buf, len, flags, addr, addrlen); - } - -- return do_lwip_send_to_stack(sockfd, buf, len, flags, addr, addrlen); -+ return g_wrap_api->send_to(sockfd, buf, len, flags, addr, addrlen); - } - - static inline int32_t do_close(int32_t s) -@@ -570,16 +561,13 @@ static inline int32_t do_close(int32_t s) - /* we called lwip_socket, even if kernel fd */ - if (posix_api != NULL && !posix_api->ues_posix && - /* contain posix_api->close_fn if success */ -- stack_broadcast_close(s) == 0) { -+ g_wrap_api->close_fn(s) == 0) { - return 0; - } else { - return posix_api->close_fn(s); - } - } -- if (sock && sock->wakeup && sock->wakeup->epollfd == s) { -- return lstack_epoll_close(s); -- } -- return stack_broadcast_close(s); -+ return g_wrap_api->close_fn(s); - } - - static int32_t do_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) -@@ -588,7 +576,7 @@ static int32_t do_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - return posix_api->poll_fn(fds, nfds, timeout); - } - -- return lstack_poll(fds, nfds, timeout); -+ return g_wrap_api->poll_fn(fds, nfds, timeout); - } - - static int32_t do_ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigmask) -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index b6e9bf1..950fa8d 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -47,6 +47,7 @@ - #include "gazelle_base_func.h" - #include "lstack_protocol_stack.h" - #include "lstack_preload.h" -+#include "lstack_wrap.h" - - static void check_process_start(void) - { -@@ -235,6 +236,8 @@ __attribute__((constructor)) void gazelle_network_init(void) - } - LSTACK_PRE_LOG(LSTACK_INFO, "cfg_init success\n"); - -+ wrap_api_init(); -+ - /* check primary process start */ - check_process_start(); - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index a98b1b8..cdb0089 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -744,7 +744,7 @@ static int32_t check_msg_vaild(const struct msghdr *message) - return 0; - } - --ssize_t do_lwip_recvmsg_from_stack(int32_t s, struct msghdr *message, int32_t flags) -+ssize_t do_lwip_recvmsg_from_stack(int32_t s, const struct msghdr *message, int32_t flags) - { - ssize_t buflen = 0; - -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index 55a483e..4a13204 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -41,7 +41,7 @@ ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, uint8_t ap - /* app write/read ring */ - ssize_t do_lwip_sendmsg_to_stack(struct lwip_sock *sock, int32_t s, - const struct msghdr *message, int32_t flags); --ssize_t do_lwip_recvmsg_from_stack(int32_t s, struct msghdr *message, int32_t flags); -+ssize_t do_lwip_recvmsg_from_stack(int32_t s, const struct msghdr *message, int32_t flags); - - ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t flags, - const struct sockaddr *addr, socklen_t addrlen); -diff --git a/src/lstack/include/posix/lstack_socket.h b/src/lstack/include/lstack_rtc_api.h -similarity index 53% -rename from src/lstack/include/posix/lstack_socket.h -rename to src/lstack/include/lstack_rtc_api.h -index a3ce1eb..563cbd8 100644 ---- a/src/lstack/include/posix/lstack_socket.h -+++ b/src/lstack/include/lstack_rtc_api.h -@@ -10,37 +10,46 @@ - * See the Mulan PSL v2 for more details. - */ - --#ifndef _GAZELLE_SOCKET_H_ --#define _GAZELLE_SOCKET_H_ -+#ifndef _LSTACK_RTC_API_H_ -+#define _LSTACK_RTC_API_H_ -+#include -+#include - --#ifdef __cplusplus --extern "C" { --#endif -- --int lwip_socket(int domain, int type, int protocol); --int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); --int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); --int lwip_listen(int s, int backlog); -+/* don't include lwip/sockets.h, conflict with sys/socket.h */ -+/* extern lwip_api here */ -+int lwip_fcntl(int s, int cmd, int val); -+int lwip_ioctl(int s, long cmd, ...); - int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); --int lwip_close(int s); -+int lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags); -+int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); -+int lwip_shutdown(int s, int how); - int lwip_getpeername(int s, struct sockaddr *name, socklen_t *namelen); - int lwip_getsockname(int s, struct sockaddr *name, socklen_t *namelen); - int lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen); - int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen); -- --ssize_t lwip_write(int s, const void *dataptr, size_t size); --ssize_t lwip_send(int s, const void *data, size_t size, int flags); --ssize_t lwip_recvmsg(int s, struct msghdr *message, int flags); --ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags); --ssize_t lwip_read(int s, void *mem, size_t len); --ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, void *from, void *fromlen); -+int lwip_close(int s); -+int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); -+int lwip_listen(int s, int backlog); - ssize_t lwip_recv(int s, void *mem, size_t len, int flags); -+ssize_t lwip_read(int s, void *mem, size_t len); -+ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt); -+ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, -+ struct sockaddr *from, socklen_t *fromlen); -+ssize_t lwip_recvmsg(int s, const struct msghdr *message, int flags); -+ssize_t lwip_send(int s, const void *dataptr, size_t size, int flags); -+ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags); -+ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, -+ const struct sockaddr *to, socklen_t tolen); -+int lwip_socket(int domain, int type, int protocol); -+ssize_t lwip_write(int s, const void *dataptr, size_t size); -+ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt); - --int lwip_fcntl(int s, int cmd, int val); --int lwip_ioctl(int s, int cmd, ...); -- --#ifdef __cplusplus --} --#endif -+int rtc_poll(struct pollfd *fds, nfds_t nfds, int timeout); -+int rtc_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout); -+int rtc_socket(int domain, int type, int protocol); -+int rtc_close(int s); -+int rtc_epoll_create(int flags); -+int rtc_epoll_create1(int flags); -+int rtc_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); - --#endif /* _GAZELLE_SOCKET_H_ */ -+#endif /* __LSTACK_RTC_API_H_ */ -diff --git a/src/lstack/include/lstack_rtw_api.h b/src/lstack/include/lstack_rtw_api.h -new file mode 100644 -index 0000000..facf4c0 ---- /dev/null -+++ b/src/lstack/include/lstack_rtw_api.h -@@ -0,0 +1,47 @@ -+/* -+* 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 _LSTACK_RTW_API_H_ -+#define _LSTACK_RTW_API_H_ -+ -+#include -+#include -+ -+int rtw_socket(int domain, int type, int protocol); -+int rtw_accept(int s, struct sockaddr *addr, socklen_t *addrlen); -+int rtw_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags); -+int rtw_bind(int s, const struct sockaddr *name, socklen_t namelen); -+int rtw_listen(int s, int backlog); -+int rtw_connect(int s, const struct sockaddr *name, socklen_t namelen); -+int rtw_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen); -+int rtw_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen); -+int rtw_getpeername(int s, struct sockaddr *name, socklen_t *namelen); -+int rtw_getsockname(int s, struct sockaddr *name, socklen_t *namelen); -+ssize_t rtw_read(int s, void *mem, size_t len); -+ssize_t rtw_readv(int s, const struct iovec *iov, int iovcnt); -+ssize_t rtw_write(int s, const void *mem, size_t size); -+ssize_t rtw_writev(int s, const struct iovec *iov, int iovcnt); -+ssize_t rtw_recv(int sockfd, void *buf, size_t len, int flags); -+ssize_t rtw_send(int sockfd, const void *buf, size_t len, int flags); -+ssize_t rtw_recvmsg(int s, const struct msghdr *message, int flags); -+ssize_t rtw_sendmsg(int s, const struct msghdr *message, int flags); -+ssize_t rtw_recvfrom(int sockfd, void *buf, size_t len, int flags, -+ struct sockaddr *addr, socklen_t *addrlen); -+ssize_t rtw_sendto(int sockfd, const void *buf, size_t len, int flags, -+ const struct sockaddr *addr, socklen_t addrlen); -+int rtw_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout); -+int rtw_poll(struct pollfd *fds, nfds_t nfds, int timeout); -+int rtw_close(int s); -+int rtw_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); -+int rtw_epoll_create1(int flags); -+int rtw_epoll_create(int flags); -+#endif /* _LSTACK_RTW_API_H_ */ -diff --git a/src/lstack/include/lstack_wrap.h b/src/lstack/include/lstack_wrap.h -new file mode 100644 -index 0000000..80e5f3c ---- /dev/null -+++ b/src/lstack/include/lstack_wrap.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 _LSTACK_WRAP_H_ -+#define _LSTACK_WRAP_H_ -+ -+void wrap_api_init(void); -+ -+#endif -+ --- -2.27.0 - diff --git a/0024-fix-arping-gazelle-return-value-is-1.patch b/0024-fix-arping-gazelle-return-value-is-1.patch deleted file mode 100644 index 8f2d1444665fe11dd969f77cdaa0af44f3873cb8..0000000000000000000000000000000000000000 --- a/0024-fix-arping-gazelle-return-value-is-1.patch +++ /dev/null @@ -1,25 +0,0 @@ -From e7fc6fab09b5687e84467520bf04f84f79de2c03 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Tue, 24 Oct 2023 14:33:00 +0800 -Subject: [PATCH] fix arping gazelle return value is 1 - ---- - src/lstack/core/lstack_protocol_stack.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index ea85bc1..1ef0850 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -786,7 +786,7 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - - for (int32_t i = 0; i < stack_group->stack_num; i++) { - stack = stack_group->stacks[i]; -- if (cur_stack == stack && use_ltran()) { -+ if (cur_stack == stack) { - continue; - } - --- -2.27.0 - diff --git a/0025-init-stack-setup-in-app-thread-when-app-call-socket-.patch b/0025-init-stack-setup-in-app-thread-when-app-call-socket-.patch deleted file mode 100644 index 09482536afde1359de7bb39a631ef865263f6b44..0000000000000000000000000000000000000000 --- a/0025-init-stack-setup-in-app-thread-when-app-call-socket-.patch +++ /dev/null @@ -1,169 +0,0 @@ -From 76dc40bf3d8730e4155c142002bc4a27325672a8 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 9 Oct 2023 10:18:20 +0800 -Subject: [PATCH] init: stack setup in app thread when app call - socket/epoll_create first in rtc mode - ---- - src/lstack/api/lstack_rtc_api.c | 14 ++++++- - src/lstack/core/lstack_init.c | 6 ++- - src/lstack/core/lstack_protocol_stack.c | 43 ++++++++++++++++++++-- - src/lstack/include/lstack_protocol_stack.h | 3 +- - 4 files changed, 57 insertions(+), 9 deletions(-) - -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index b7c6380..276bec0 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -35,6 +35,10 @@ int rtc_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int time - int rtc_socket(int domain, int type, int protocol) - { - int ret; -+ -+ if (stack_setup_app_thread() < 0) { -+ LSTACK_EXIT(1, "stack_setup_app_thread failed!\n"); -+ } - - /* need call stack thread init function */ - ret = lwip_socket(domain, type, protocol); -@@ -56,13 +60,19 @@ int rtc_close(int s) - - int rtc_epoll_create(int flags) - { -- /* need call stack thread init function */ -+ if (stack_setup_app_thread() < 0) { -+ LSTACK_EXIT(1, "stack_setup_app_thread failed!\n"); -+ } -+ - return lstack_epoll_create(flags); - } - - int rtc_epoll_create1(int flags) - { -- /* need call stack thread init function */ -+ if (stack_setup_app_thread() < 0) { -+ LSTACK_EXIT(1, "stack_setup_app_thread failed!\n"); -+ } -+ - return lstack_epoll_create1(flags); - } - -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 950fa8d..a3ca4ff 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -287,8 +287,10 @@ __attribute__((constructor)) void gazelle_network_init(void) - } - } - -- if (stack_thread_setup() != 0) { -- LSTACK_EXIT(1, "stack_thread_setup failed\n"); -+ if (!get_global_cfg_params()->stack_mode_rtc) { -+ if (stack_setup_thread() != 0) { -+ LSTACK_EXIT(1, "stack_setup_thread failed\n"); -+ } - } - - /* lwip initialization */ -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index ea85bc1..69897c7 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -501,6 +501,9 @@ static void* gazelle_stack_thread(void *arg) - } - - LSTACK_LOG(INFO, LSTACK, "stack_%02hu init success\n", queue_id); -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ return NULL; -+ } - - for (;;) { - stack_polling(wakeup_tick); -@@ -510,7 +513,7 @@ static void* gazelle_stack_thread(void *arg) - return NULL; - } - --static void libnet_listen_thread(void *arg) -+static void gazelle_listen_thread(void *arg) - { - struct cfg_params *cfg_param = get_global_cfg_params(); - recv_pkts_from_other_process(cfg_param->process_idx, arg); -@@ -541,11 +544,12 @@ int32_t stack_group_init(void) - } - } - -- if (!use_ltran()) { -+ /* run to completion mode does not currently support multiple process */ -+ if (!use_ltran() && !get_global_cfg_params()->stack_mode_rtc) { - char name[PATH_MAX]; - sem_init(&stack_group->sem_listen_thread, 0, 0); - sprintf_s(name, sizeof(name), "%s", "listen_thread"); -- struct sys_thread *thread = sys_thread_new(name, libnet_listen_thread, -+ struct sys_thread *thread = sys_thread_new(name, gazelle_listen_thread, - (void*)(&stack_group->sem_listen_thread), 0, 0); - free(thread); - sem_wait(&stack_group->sem_listen_thread); -@@ -554,7 +558,33 @@ int32_t stack_group_init(void) - return 0; - } - --int32_t stack_thread_setup(void) -+int32_t stack_setup_app_thread(void) -+{ -+ static PER_THREAD int first_flags = 1; -+ static _Atomic uint32_t queue_id = 0; -+ -+ if (likely(first_flags == 0)) { -+ return 0; -+ } -+ first_flags=0; -+ -+ uint32_t cur_queue_id = atomic_fetch_add(&queue_id, 1); -+ struct thread_params *t_params = malloc(sizeof(struct thread_params)); -+ if (t_params == NULL) { -+ return -1; -+ } -+ t_params->idx = cur_queue_id; -+ t_params->queue_id = cur_queue_id; -+ -+ if (stack_thread_init(t_params) == NULL) { -+ LSTACK_LOG(INFO, LSTACK, "stack setup failed in app thread\n"); -+ return -1; -+ } -+ -+ return 0; -+} -+ -+int32_t stack_setup_thread(void) - { - int32_t ret; - char name[PATH_MAX]; -@@ -790,6 +820,11 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - continue; - } - -+ /* stack maybe not init in app thread yet */ -+ if (stack == NULL || !(netif_is_up(&stack->netif))) { -+ continue; -+ } -+ - ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); - if (ret != 0) { - stack->stats.rx_allocmbuf_fail++; -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 7cb37bf..4f1b127 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -110,7 +110,8 @@ struct protocol_stack *get_bind_protocol_stack(void); - struct protocol_stack_group *get_protocol_stack_group(void); - - int32_t stack_group_init(void); --int32_t stack_thread_setup(void); -+int32_t stack_setup_thread(void); -+int32_t stack_setup_app_thread(void); - - void bind_to_stack_numa(struct protocol_stack *stack); - int32_t init_dpdk_ethdev(void); --- -2.27.0 - diff --git a/0026-epoll-adapt-epoll-interface-for-rtc-mode.patch b/0026-epoll-adapt-epoll-interface-for-rtc-mode.patch deleted file mode 100644 index 9d7dbc411d96903668cd22146d2d231b238f4732..0000000000000000000000000000000000000000 --- a/0026-epoll-adapt-epoll-interface-for-rtc-mode.patch +++ /dev/null @@ -1,365 +0,0 @@ -From 8afdae8f8f41bb62d3e57db638735c29abe132d1 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 9 Oct 2023 11:33:01 +0800 -Subject: [PATCH] epoll: adapt epoll interface for rtc mode - ---- - src/lstack/api/lstack_epoll.c | 158 +++++++++++++++++++++--- - src/lstack/api/lstack_rtc_api.c | 4 +- - src/lstack/api/lstack_rtw_api.c | 4 +- - src/lstack/include/lstack_rtc_api.h | 52 ++++---- - src/lstack/include/posix/lstack_epoll.h | 6 +- - 5 files changed, 178 insertions(+), 46 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 7c40792..d1fb209 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -155,6 +155,34 @@ static uint32_t update_events(struct lwip_sock *sock) - return event; - } - -+static void rtc_raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *sock) -+{ -+ uint32_t event = 0; -+ -+ if (sock->rcvevent) { -+ event |= EPOLLIN; -+ } -+ -+ if (sock->errevent > 0) { -+ event |= EPOLLERR | EPOLLIN; -+ } -+ -+ if (sock->sendevent) { -+ /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ -+ if (sock->conn && CONN_TYPE_IS_LIBOS(sock->conn)) { -+ event |= EPOLLOUT; -+ } -+ } -+ -+ if (event) { -+ sock->events = event; -+ if (wakeup->type == WAKEUP_EPOLL && (sock->events & sock->epoll_events) && -+ list_is_null(&sock->event_list)) { -+ list_add_node(&wakeup->event_list, &sock->event_list); -+ } -+ } -+} -+ - static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *sock) - { - uint32_t event = 0; -@@ -230,11 +258,16 @@ int32_t lstack_do_epoll_create(int32_t fd) - wakeup->epollfd = fd; - sock->wakeup = wakeup; - -- update_epoll_max_stack(wakeup); -- change_epollfd_kernel_thread(wakeup, wakeup->bind_stack, wakeup->max_stack); -- wakeup->bind_stack = wakeup->max_stack; -- if (get_global_cfg_params()->app_bind_numa) { -- bind_to_stack_numa(wakeup->bind_stack); -+ if (!get_global_cfg_params()->stack_mode_rtc) { -+ update_epoll_max_stack(wakeup); -+ change_epollfd_kernel_thread(wakeup, wakeup->bind_stack, wakeup->max_stack); -+ wakeup->bind_stack = wakeup->max_stack; -+ if (get_global_cfg_params()->app_bind_numa) { -+ bind_to_stack_numa(wakeup->bind_stack); -+ } -+ } else { -+ wakeup->bind_stack = wakeup->max_stack = get_protocol_stack(); -+ change_epollfd_kernel_thread(wakeup, NULL, wakeup->max_stack); - } - - return fd; -@@ -329,7 +362,45 @@ static void update_epoll_max_stack(struct wakeup_poll *wakeup) - wakeup->max_stack = stack_group->stacks[bind_id]; - } - --int32_t lstack_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event *event) -+int32_t lstack_rtc_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event *event) -+{ -+ if (epfd < 0 || fd < 0 || epfd == fd || (event == NULL && op != EPOLL_CTL_DEL)) { -+ LSTACK_LOG(ERR, LSTACK, "fd=%d epfd=%d op=%d\n", fd, epfd, op); -+ GAZELLE_RETURN(EINVAL); -+ } -+ -+ struct lwip_sock *epoll_sock = get_socket_by_fd(epfd); -+ if (epoll_sock == NULL || epoll_sock->wakeup == NULL) { -+ return posix_api->epoll_ctl_fn(epfd, op, fd, event); -+ } -+ -+ struct wakeup_poll *wakeup = epoll_sock->wakeup; -+ struct lwip_sock *sock = get_socket(fd); -+ if (sock == NULL) { -+ return posix_api->epoll_ctl_fn(epfd, op, fd, event); -+ } -+ -+ switch (op) { -+ case EPOLL_CTL_ADD: -+ sock->wakeup = wakeup; -+ /* fall through */ -+ case EPOLL_CTL_MOD: -+ sock->epoll_events = event->events | EPOLLERR | EPOLLHUP; -+ sock->ep_data = event->data; -+ rtc_raise_pending_events(wakeup, sock); -+ break; -+ case EPOLL_CTL_DEL: -+ sock->epoll_events = 0; -+ list_del_node_null(&sock->event_list); -+ break; -+ default: -+ GAZELLE_RETURN(EINVAL); -+ } -+ -+ return 0; -+} -+ -+int32_t lstack_rtw_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event *event) - { - LSTACK_LOG(DEBUG, LSTACK, "op=%d events: fd: %d\n", op, fd); - -@@ -384,29 +455,28 @@ int32_t lstack_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_even - return 0; - } - --static int32_t epoll_lwip_event(struct wakeup_poll *wakeup, struct epoll_event *events, uint32_t maxevents) -+int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event *events, uint32_t maxevents) - { - int32_t event_num = 0; - struct list_node *node, *temp; - -- pthread_spin_lock(&wakeup->event_list_lock); -- - list_for_each_safe(node, temp, &wakeup->event_list) { - struct lwip_sock *sock = container_of(node, struct lwip_sock, event_list); - - if ((sock->epoll_events & sock->events) == 0) { -- list_del_node_null(&sock->event_list); -+ list_del_node_null(node); - continue; - } - - if (sock->epoll_events & EPOLLET) { -- list_del_node_null(&sock->event_list); -+ list_del_node_null(node); -+ sock->events = 0; - } - - /* EPOLLONESHOT: generate event after epoll_ctl add/mod event again - epoll_event set 0 avoid generating event util epoll_ctl set epoll_event a valu */ - if (sock->epoll_events & EPOLLONESHOT) { -- list_del_node_null(&sock->event_list); -+ list_del_node_null(node); - sock->epoll_events = 0; - } - -@@ -415,13 +485,25 @@ static int32_t epoll_lwip_event(struct wakeup_poll *wakeup, struct epoll_event * - event_num++; - - if (event_num >= maxevents) { -+ /* move list head after the current node, and start traversing from this node next time */ -+ list_del_node_null(&wakeup->event_list); -+ list_add_node(node, &wakeup->event_list); - break; - } - } - -+ wakeup->stat.app_events += event_num; -+ return event_num; -+} -+ -+static int32_t epoll_lwip_event(struct wakeup_poll *wakeup, struct epoll_event *events, uint32_t maxevents) -+{ -+ int32_t event_num; -+ -+ pthread_spin_lock(&wakeup->event_list_lock); -+ event_num = epoll_lwip_event_nolock(wakeup, events, maxevents); - pthread_spin_unlock(&wakeup->event_list_lock); - -- wakeup->stat.app_events += event_num; - return event_num; - } - -@@ -484,7 +566,55 @@ static void ms_to_timespec(struct timespec *timespec, int32_t timeout) - timespec->tv_nsec = timespec->tv_nsec % SEC_TO_NSEC; - } - --int32_t lstack_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) -+int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) -+{ -+ struct lwip_sock *sock = get_socket_by_fd(epfd); -+ -+ if (sock == NULL || sock->wakeup == NULL) { -+ return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); -+ } -+ -+ struct wakeup_poll *wakeup = sock->wakeup; -+ int32_t lwip_num = 0; -+ /* 16: avoid app process events for a long time */ -+ int32_t tmpmaxevents = 16; -+ /* avoid the starvation of epoll events from both netstack */ -+ int host_maxevents = tmpmaxevents / 2; -+ uint32_t poll_ts = sys_now(); -+ bool loop_flag; -+ int32_t kernel_num = 0; -+ int32_t tmptimeout = timeout; -+ -+ do { -+ stack_polling(0); -+ if (__atomic_load_n(&wakeup->have_kernel_event, __ATOMIC_ACQUIRE)) { -+ kernel_num = posix_api->epoll_wait_fn(epfd, events, host_maxevents, 0); -+ if (!kernel_num) { -+ __atomic_store_n(&wakeup->have_kernel_event, false, __ATOMIC_RELEASE); -+ } -+ } -+ if (tmptimeout > 0) { -+ tmptimeout = update_timeout(tmptimeout, poll_ts); -+ } -+ -+ loop_flag = false; -+ if (!kernel_num && list_is_empty(&wakeup->event_list) && tmptimeout != 0) { -+ loop_flag = true; -+ } -+ } while (loop_flag); -+ -+ if (kernel_num < 0) { -+ LSTACK_LOG(ERR, LSTACK, "lstack_rtc_epoll_wait: kernel event failed\n"); -+ return kernel_num; -+ } -+ -+ lwip_num = epoll_lwip_event_nolock(wakeup, &events[kernel_num], tmpmaxevents - kernel_num); -+ wakeup->stat.app_events += lwip_num; -+ -+ return lwip_num + kernel_num; -+} -+ -+int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) - { - struct lwip_sock *sock = get_socket_by_fd(epfd); - if (sock == NULL || sock->wakeup == NULL) { -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index b7c6380..b9abf0f 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -29,7 +29,7 @@ int rtc_poll(struct pollfd *fds, nfds_t nfds, int timeout) - - int rtc_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) - { -- return -1; -+ return lstack_rtc_epoll_wait(epfd, events, maxevents, timeout); - } - - int rtc_socket(int domain, int type, int protocol) -@@ -68,5 +68,5 @@ int rtc_epoll_create1(int flags) - - int rtc_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) - { -- return lstack_epoll_ctl(epfd, op, fd, event); -+ return lstack_rtc_epoll_ctl(epfd, op, fd, event); - } -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index 9b8678a..7d14ffa 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -206,7 +206,7 @@ ssize_t rtw_sendto(int sockfd, const void *buf, size_t len, int flags, - - int rtw_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) - { -- return lstack_epoll_wait(epfd, events, maxevents, timeout); -+ return lstack_rtw_epoll_wait(epfd, events, maxevents, timeout); - } - - int rtw_poll(struct pollfd *fds, nfds_t nfds, int timeout) -@@ -225,7 +225,7 @@ int rtw_close(int s) - - int rtw_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) - { -- return lstack_epoll_ctl(epfd, op, fd, event); -+ return lstack_rtw_epoll_ctl(epfd, op, fd, event); - } - - int rtw_epoll_create1(int flags) -diff --git a/src/lstack/include/lstack_rtc_api.h b/src/lstack/include/lstack_rtc_api.h -index 563cbd8..0aff928 100644 ---- a/src/lstack/include/lstack_rtc_api.h -+++ b/src/lstack/include/lstack_rtc_api.h -@@ -17,32 +17,32 @@ - - /* don't include lwip/sockets.h, conflict with sys/socket.h */ - /* extern lwip_api here */ --int lwip_fcntl(int s, int cmd, int val); --int lwip_ioctl(int s, long cmd, ...); --int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); --int lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags); --int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); --int lwip_shutdown(int s, int how); --int lwip_getpeername(int s, struct sockaddr *name, socklen_t *namelen); --int lwip_getsockname(int s, struct sockaddr *name, socklen_t *namelen); --int lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen); --int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen); --int lwip_close(int s); --int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); --int lwip_listen(int s, int backlog); --ssize_t lwip_recv(int s, void *mem, size_t len, int flags); --ssize_t lwip_read(int s, void *mem, size_t len); --ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt); --ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, -- struct sockaddr *from, socklen_t *fromlen); --ssize_t lwip_recvmsg(int s, const struct msghdr *message, int flags); --ssize_t lwip_send(int s, const void *dataptr, size_t size, int flags); --ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags); --ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, -- const struct sockaddr *to, socklen_t tolen); --int lwip_socket(int domain, int type, int protocol); --ssize_t lwip_write(int s, const void *dataptr, size_t size); --ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt); -+extern int lwip_fcntl(int s, int cmd, int val); -+extern int lwip_ioctl(int s, long cmd, ...); -+extern int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); -+extern int lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags); -+extern int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); -+extern int lwip_shutdown(int s, int how); -+extern int lwip_getpeername(int s, struct sockaddr *name, socklen_t *namelen); -+extern int lwip_getsockname(int s, struct sockaddr *name, socklen_t *namelen); -+extern int lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen); -+extern int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen); -+extern int lwip_close(int s); -+extern int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); -+extern int lwip_listen(int s, int backlog); -+extern ssize_t lwip_recv(int s, void *mem, size_t len, int flags); -+extern ssize_t lwip_read(int s, void *mem, size_t len); -+extern ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt); -+extern ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, -+ struct sockaddr *from, socklen_t *fromlen); -+extern ssize_t lwip_recvmsg(int s, const struct msghdr *message, int flags); -+extern ssize_t lwip_send(int s, const void *dataptr, size_t size, int flags); -+extern ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags); -+extern ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, -+ const struct sockaddr *to, socklen_t tolen); -+extern int lwip_socket(int domain, int type, int protocol); -+extern ssize_t lwip_write(int s, const void *dataptr, size_t size); -+extern ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt); - - int rtc_poll(struct pollfd *fds, nfds_t nfds, int timeout); - int rtc_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout); -diff --git a/src/lstack/include/posix/lstack_epoll.h b/src/lstack/include/posix/lstack_epoll.h -index 699a951..c42f3a5 100644 ---- a/src/lstack/include/posix/lstack_epoll.h -+++ b/src/lstack/include/posix/lstack_epoll.h -@@ -73,8 +73,10 @@ void wakeup_stack_epoll(struct protocol_stack *stack); - - int32_t lstack_epoll_create(int32_t size); - int32_t lstack_epoll_create1(int32_t flags); --int32_t lstack_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event *event); --int32_t lstack_epoll_wait(int32_t epfd, struct epoll_event *events, int32_t maxevents, int32_t timeout); -+int32_t lstack_rtw_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event *event); -+int32_t lstack_rtc_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event *event); -+int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event *events, int32_t maxevents, int32_t timeout); -+int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout); - int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout); - - #ifdef __cplusplus --- -2.27.0 - diff --git a/0027-clean-useless-code.patch b/0027-clean-useless-code.patch deleted file mode 100644 index 3be5e8af3cbd57b79016e07326802dcb2aa7d724..0000000000000000000000000000000000000000 --- a/0027-clean-useless-code.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 0398acfead1f6c118234559b3473ace2c5676015 Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Thu, 26 Oct 2023 13:20:03 +0000 -Subject: [PATCH] clean useless code - ---- - src/lstack/core/lstack_dpdk.c | 4 ---- - 1 file changed, 4 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index a53e85c..48fa67d 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -740,10 +740,6 @@ int32_t init_dpdk_ethdev(void) - return -1; - } - -- /* 20: sleep for lacp ,this is a temp plan, it will be changed in future */ -- int wait_lacp = 20; -- sleep(wait_lacp); -- - } else { - ret = dpdk_ethdev_init(0, 0); - if (ret != 0) { --- -2.27.0 - diff --git a/0028-ethdev-fix-arp-unicast-packets-cannot-be-transmitted.patch b/0028-ethdev-fix-arp-unicast-packets-cannot-be-transmitted.patch deleted file mode 100644 index 0ed25398bed811a70ca4f1816ac3c406281e566a..0000000000000000000000000000000000000000 --- a/0028-ethdev-fix-arp-unicast-packets-cannot-be-transmitted.patch +++ /dev/null @@ -1,55 +0,0 @@ -From aa2e11540cf897d2b1051ab33245e8c988618aaa Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Thu, 26 Oct 2023 17:45:56 +0800 -Subject: [PATCH] ethdev: fix arp unicast packets cannot be transmitted to - current procotol stack - ---- - src/lstack/core/lstack_protocol_stack.c | 8 ++++++++ - src/lstack/netif/lstack_ethdev.c | 11 ++--------- - 2 files changed, 10 insertions(+), 9 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 0726054..511d2b9 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -837,6 +837,14 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - return; - } - } -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ if (ret != 0) { -+ stack->stats.rx_allocmbuf_fail++; -+ return; -+ } -+ copy_mbuf(mbuf_copy, mbuf); -+ kni_handle_tx(mbuf_copy); -+ return; - } - - void stack_broadcast_clean_epoll(struct wakeup_poll *wakeup) -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 30c3c9a..f2353f8 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -780,15 +780,8 @@ int32_t gazelle_eth_dev_poll(struct protocol_stack *stack, uint8_t use_ltran_fla - struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(stack->pkts[i], struct rte_ether_hdr *); - if (unlikely(RTE_BE16(RTE_ETHER_TYPE_ARP) == ethh->ether_type)) { - stack_broadcast_arp(stack->pkts[i], stack); --#if DPDK_VERSION_1911 -- if (!rte_is_broadcast_ether_addr(ðh->d_addr)) { --#else /* DPDK_VERSION_1911 */ -- if (!rte_is_broadcast_ether_addr(ðh->dst_addr)) { --#endif /* DPDK_VERSION_1911 */ -- // copy arp into other process -- transfer_arp_to_other_process(stack->pkts[i]); -- transfer_type = TRANSFER_KERNEL; -- } -+ /* copy arp into other process */ -+ transfer_arp_to_other_process(stack->pkts[i]); - } else { - if (get_global_cfg_params()->tuple_filter && stack->queue_id == 0) { - transfer_type = distribute_pakages(stack->pkts[i]); --- -2.27.0 - diff --git a/0029-stack-add-semaphore-to-ensure-all-stack-threads-setu.patch b/0029-stack-add-semaphore-to-ensure-all-stack-threads-setu.patch deleted file mode 100644 index 394ce6a49fa4d5bbb4d24bd598cae818317e4b22..0000000000000000000000000000000000000000 --- a/0029-stack-add-semaphore-to-ensure-all-stack-threads-setu.patch +++ /dev/null @@ -1,102 +0,0 @@ -From 24deab28953f33ab4dc1596291289b91b805b4de Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Thu, 26 Oct 2023 19:36:02 +0800 -Subject: [PATCH] stack: add semaphore to ensure all stack threads setup - success in rtw mode before call main() - ---- - src/lstack/core/lstack_protocol_stack.c | 19 +++++++++++++++++-- - src/lstack/include/lstack_protocol_stack.h | 2 ++ - src/lstack/netif/lstack_ethdev.c | 4 ++-- - 3 files changed, 21 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 0726054..27e5005 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -289,6 +289,7 @@ static void* gazelle_kernelevent_thread(void *arg) - - LSTACK_LOG(INFO, LSTACK, "kernelevent_%02hu start\n", idx); - free(arg); -+ sem_post(&g_stack_group.sem_stack_setup); - - for (;;) { - stack->kernel_event_num = posix_api->epoll_wait_fn(stack->epollfd, stack->kernel_events, KERNEL_EPOLL_MAX, -1); -@@ -493,9 +494,12 @@ static void* gazelle_stack_thread(void *arg) - free(arg); - if (stack == NULL) { - LSTACK_LOG(ERR, LSTACK, "stack_thread_init failed queue_id=%hu\n", queue_id); -- /* exit in signal thread */ -- raise(SIGTERM); -+ g_stack_group.stack_setup_fail = 1; -+ sem_post(&g_stack_group.sem_stack_setup); -+ return NULL; - } -+ sem_post(&g_stack_group.sem_stack_setup); -+ - if (!use_ltran() && queue_id == 0) { - init_listen_and_user_ports(); - } -@@ -531,6 +535,11 @@ int32_t stack_group_init(void) - init_list_node(&stack_group->poll_list); - pthread_spin_init(&stack_group->poll_list_lock, PTHREAD_PROCESS_PRIVATE); - pthread_spin_init(&stack_group->socket_lock, PTHREAD_PROCESS_PRIVATE); -+ if (sem_init(&stack_group->sem_stack_setup, 0, 0) < 0) { -+ LSTACK_LOG(ERR, LSTACK, "sem_init failed errno=%d\n", errno); -+ return -1; -+ } -+ stack_group->stack_setup_fail = 0; - - if (get_global_cfg_params()->is_primary) { - uint32_t total_mbufs = get_global_cfg_params()->mbuf_count_per_conn * get_global_cfg_params()->tcp_conn_count; -@@ -622,6 +631,12 @@ int32_t stack_setup_thread(void) - } - } - -+ /* 2: wait stack thread and kernel_event thread init finish */ -+ wait_sem_value(&g_stack_group.sem_stack_setup, g_stack_group.stack_num * 2); -+ if (g_stack_group.stack_setup_fail) { -+ return -1; -+ } -+ - return 0; - } - -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 4f1b127..2c581b3 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -96,6 +96,8 @@ struct protocol_stack_group { - pthread_spinlock_t poll_list_lock; - sem_t sem_listen_thread; - struct rte_mempool *total_rxtx_pktmbuf_pool[PROTOCOL_STACK_MAX]; -+ sem_t sem_stack_setup; -+ bool stack_setup_fail; - - /* dfx stats */ - bool latency_start; -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 30c3c9a..b0dbba4 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -319,7 +319,7 @@ struct rte_flow *create_flow_director(uint16_t port_id, uint16_t queue_id, - if (!res) { - flow = rte_flow_create(port_id, &attr, pattern, action, error); - } else { -- LSTACK_LOG(ERR, PORT, "rte_flow_create.rte_flow_validate error, res %d \n", res); -+ LSTACK_LOG(ERR, LSTACK, "rte_flow_create.rte_flow_validate error, res %d \n", res); - } - - return flow; -@@ -364,7 +364,7 @@ void delete_flow_director(uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) - struct rte_flow_error error; - int ret = rte_flow_destroy(port_id, fl->flow, &error); - if(ret != 0){ -- LSTACK_LOG(ERR, PORT, "Flow can't be delete %d message: %s\n", -+ LSTACK_LOG(ERR, LSTACK, "Flow can't be delete %d message: %s\n", - error.type, error.message ? error.message : "(no stated reason)"); - } - delete_rule(rule_key); --- -2.27.0 - diff --git a/0030-ethdev-register-offload-to-netif.patch b/0030-ethdev-register-offload-to-netif.patch deleted file mode 100644 index a3e86566e687cb42bb3b26e7e2b8e0889903189a..0000000000000000000000000000000000000000 --- a/0030-ethdev-register-offload-to-netif.patch +++ /dev/null @@ -1,29 +0,0 @@ -From f15f4d7c178b35b41bab7c42162517e4142ae77a Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Fri, 27 Oct 2023 20:11:29 +0800 -Subject: [PATCH] ethdev: register offload to netif - ---- - src/lstack/netif/lstack_ethdev.c | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 6e4c9de..80932c8 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -895,6 +895,12 @@ static err_t eth_dev_init(struct netif *netif) - - netif->hwaddr_len = ETHER_ADDR_LEN; - -+ netif_set_rxol_flags(netif, get_protocol_stack_group()->rx_offload); -+ netif_set_txol_flags(netif, get_protocol_stack_group()->tx_offload); -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ netif_set_rtc_mode(netif); -+ } -+ - return ERR_OK; - } - --- -2.27.0 - diff --git a/0031-epoll-fix-epollet-mode-error.patch b/0031-epoll-fix-epollet-mode-error.patch deleted file mode 100644 index a7a674aac022939e3e851e1a83dcebe4383007ef..0000000000000000000000000000000000000000 --- a/0031-epoll-fix-epollet-mode-error.patch +++ /dev/null @@ -1,44 +0,0 @@ -From c6cca5f100c09769a5d260e729f4c149be964ea4 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sat, 28 Oct 2023 20:17:26 +0800 -Subject: [PATCH] epoll: fix epollet mode error - ---- - src/lstack/api/lstack_epoll.c | 10 +++++----- - 1 file changed, 5 insertions(+), 5 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index d1fb209..a711ae3 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -468,22 +468,22 @@ int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event * - continue; - } - -+ events[event_num].events = sock->events & sock->epoll_events; -+ events[event_num].data = sock->ep_data; -+ event_num++; -+ - if (sock->epoll_events & EPOLLET) { - list_del_node_null(node); - sock->events = 0; - } - - /* EPOLLONESHOT: generate event after epoll_ctl add/mod event again -- epoll_event set 0 avoid generating event util epoll_ctl set epoll_event a valu */ -+ epoll_event set 0 avoid generating event util epoll_ctl reset epoll_event */ - if (sock->epoll_events & EPOLLONESHOT) { - list_del_node_null(node); - sock->epoll_events = 0; - } - -- events[event_num].events = sock->events & sock->epoll_events; -- events[event_num].data = sock->ep_data; -- event_num++; -- - if (event_num >= maxevents) { - /* move list head after the current node, and start traversing from this node next time */ - list_del_node_null(&wakeup->event_list); --- -2.27.0 - diff --git a/0032-bond6.patch b/0032-bond6.patch deleted file mode 100644 index 3933e16ad8511b2bcac2d97d52f3d9944d523359..0000000000000000000000000000000000000000 --- a/0032-bond6.patch +++ /dev/null @@ -1,210 +0,0 @@ -From c3cc06b64d2da294001289d7610f186a6af7a8c4 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Mon, 30 Oct 2023 21:52:29 +0800 -Subject: [PATCH] bond6 - ---- - src/lstack/core/lstack_cfg.c | 34 +++++++++++++++++++++------------ - src/lstack/core/lstack_dpdk.c | 33 +++++++++++++++++++------------- - src/lstack/include/lstack_cfg.h | 6 +++--- - 3 files changed, 45 insertions(+), 28 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index ad89bca..c4278b5 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -24,6 +24,7 @@ - #include - #include - -+#include - #include - #include - #include -@@ -70,8 +71,8 @@ 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_use_bond4(void); --static int32_t parse_bond4_slave_mac(void); -+static int32_t parse_bond_mode(void); -+static int32_t parse_bond_slave_mac(void); - static int32_t parse_use_sockmap(void); - static int32_t parse_udp_enable(void); - static int32_t parse_nic_rxqueue_size(void); -@@ -130,8 +131,8 @@ static struct config_vector_t g_config_tbl[] = { - { "process_numa", parse_process_numa }, - { "process_idx", parse_process_index }, - { "tuple_filter", parse_tuple_filter }, -- { "use_bond4", parse_use_bond4 }, -- { "bond4_slave_mac", parse_bond4_slave_mac }, -+ { "bond_mode", parse_bond_mode }, -+ { "bond_slave_mac", parse_bond_slave_mac }, - { "use_sockmap", parse_use_sockmap }, - { "udp_enable", parse_udp_enable }, - { "nic_rxqueue_size", parse_nic_rxqueue_size}, -@@ -1114,16 +1115,25 @@ static int32_t parse_udp_enable(void) - return ret; - } - --static int32_t parse_use_bond4(void) -+static int32_t parse_bond_mode(void) - { -- int32_t ret; -- PARSE_ARG(g_config_params.use_bond4, "use_bond4", 0, 0, 1, ret); -- return ret; -+ const config_setting_t *bond_mode = NULL; -+ bond_mode = config_lookup(&g_config, "bond_mode"); -+ g_config_params.bond_mode = config_setting_get_int(bond_mode); -+ if (g_config_params.bond_mode == -1) { -+ return 0; -+ } -+ if (g_config_params.bond_mode != BONDING_MODE_8023AD && g_config_params.bond_mode != BONDING_MODE_ALB) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid bond mode = %d. only supports bond mode = 4,6.\n", -+ g_config_params.bond_mode); -+ return -EINVAL; -+ } -+ return 0; - } - --static int32_t parse_bond4_slave_mac(void) -+static int32_t parse_bond_slave_mac(void) - { -- if (g_config_params.use_bond4 == 0) { -+ if (g_config_params.bond_mode == -1) { - return 0; - } - -@@ -1151,13 +1161,13 @@ static int32_t parse_bond4_slave_mac(void) - } - - /* add dev */ -- ret = str_to_eth_addr(slave_mac1, g_config_params.bond4_slave1_mac_addr); -+ ret = str_to_eth_addr(slave_mac1, g_config_params.bond_slave1_mac_addr); - if (ret != 0) { - LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid device name %s ret=%d.\n", slave_mac1, ret); - return ret; - } - -- ret = str_to_eth_addr(slave_mac2, g_config_params.bond4_slave2_mac_addr); -+ ret = str_to_eth_addr(slave_mac2, g_config_params.bond_slave2_mac_addr); - if (ret != 0) { - LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid device name %s ret=%d.\n", slave_mac2, ret); - } -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 48fa67d..1a5b568 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -463,7 +463,6 @@ static void rss_setup(const int port_id, const uint16_t nb_queues) - int32_t dpdk_ethdev_init(int port_id, bool bond_port) - { - uint16_t nb_queues = get_global_cfg_params()->num_cpu; -- int32_t use_bond4 = get_global_cfg_params()->use_bond4; - if (get_global_cfg_params()->seperate_send_recv) { - nb_queues = get_global_cfg_params()->num_cpu * 2; - } -@@ -474,7 +473,7 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - - struct protocol_stack_group *stack_group = get_protocol_stack_group(); - -- if (!use_bond4) { -+ if (get_global_cfg_params()->bond_mode < 0) { - port_id = ethdev_port_id(get_global_cfg_params()->mac_addr); - if (port_id < 0) { - return port_id; -@@ -499,13 +498,13 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - if (bond_port) { - int slave_num = 2; - int32_t slave_port_id[2]; -- slave_port_id[0] = ethdev_port_id(get_global_cfg_params()->bond4_slave1_mac_addr); -+ slave_port_id[0] = ethdev_port_id(get_global_cfg_params()->bond_slave1_mac_addr); - if (slave_port_id[0] < 0) { - LSTACK_LOG(ERR, LSTACK, "get slave port id failed port = %d\n", slave_port_id[0]); - return slave_port_id[0]; - } - -- slave_port_id[1] = ethdev_port_id(get_global_cfg_params()->bond4_slave2_mac_addr); -+ slave_port_id[1] = ethdev_port_id(get_global_cfg_params()->bond_slave2_mac_addr); - if (slave_port_id[1] < 0) { - LSTACK_LOG(ERR, LSTACK, "get slave port id failed port = %d\n", slave_port_id[1]); - return slave_port_id[1]; -@@ -648,7 +647,7 @@ int32_t dpdk_ethdev_start(void) - } - } - -- if (get_global_cfg_params()->use_bond4) { -+ if (get_global_cfg_params()->bond_mode >= 0) { - return 0; - } - -@@ -697,15 +696,16 @@ int32_t init_dpdk_ethdev(void) - { - int32_t ret; - -- if (get_global_cfg_params()->use_bond4) { -- int bond_port_id = rte_eth_bond_create("net_bonding0", 4, (uint8_t)rte_socket_id()); -+ if (get_global_cfg_params()->bond_mode >= 0) { -+ uint8_t socket_id = rte_socket_id(); -+ int bond_port_id = rte_eth_bond_create("net_bonding0", get_global_cfg_params()->bond_mode, socket_id); - if (bond_port_id < 0) { - LSTACK_LOG(ERR, LSTACK, "get bond port id failed ret=%d\n", bond_port_id); - return bond_port_id; - } - - ret = dpdk_ethdev_init(bond_port_id, 1); -- if (ret != 0) { -+ if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed ret = %d\n", ret); - return -1; - } -@@ -716,10 +716,17 @@ int32_t init_dpdk_ethdev(void) - return -1; - } - -- ret = rte_eth_bond_8023ad_dedicated_queues_enable(bond_port_id); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk enable 8023 dedicated queues failed ret = %d\n", ret); -- return -1; -+ if (get_global_cfg_params()->bond_mode == BONDING_MODE_8023AD) { -+ ret = rte_eth_bond_8023ad_dedicated_queues_enable(bond_port_id); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk enable 8023 dedicated queues failed ret = %d\n", ret); -+ return -1; -+ } -+ } else { -+ ret = rte_eth_bond_mode_set(bond_port_id, get_global_cfg_params()->bond_mode); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk enable mode set failed ret = %d\n", ret); -+ } - } - - ret = rte_eth_promiscuous_enable(bond_port_id); -@@ -735,7 +742,7 @@ int32_t init_dpdk_ethdev(void) - } - - ret = rte_eth_dev_start(bond_port_id); -- if (ret < 0) { -+ if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk start bond port failed ret = %d\n", ret); - return -1; - } -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 1d895ec..fc627e3 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -110,9 +110,9 @@ struct cfg_params { - uint16_t send_ring_size; - bool expand_send_ring; - bool tuple_filter; -- bool use_bond4; -- uint8_t bond4_slave1_mac_addr[ETHER_ADDR_LEN]; -- uint8_t bond4_slave2_mac_addr[ETHER_ADDR_LEN]; -+ int8_t bond_mode; -+ uint8_t bond_slave1_mac_addr[ETHER_ADDR_LEN]; -+ uint8_t bond_slave2_mac_addr[ETHER_ADDR_LEN]; - bool use_sockmap; - bool udp_enable; - struct cfg_nic_params nic; --- -2.27.0 - diff --git a/0033-cfg-fix-bond_mode-null.patch b/0033-cfg-fix-bond_mode-null.patch deleted file mode 100644 index 6e842b5c878014ba624091c6a60cc96fc5183fc7..0000000000000000000000000000000000000000 --- a/0033-cfg-fix-bond_mode-null.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 845b5afa76205cf1eaffc966257eb62ea64af837 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Sat, 4 Nov 2023 19:18:12 +0800 -Subject: [PATCH] cfg: fix bond_mode null - ---- - src/lstack/core/lstack_cfg.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index c4278b5..8e83c0d 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -1119,6 +1119,11 @@ static int32_t parse_bond_mode(void) - { - const config_setting_t *bond_mode = NULL; - bond_mode = config_lookup(&g_config, "bond_mode"); -+ if (bond_mode == NULL) { -+ g_config_params.bond_mode = -1; -+ return 0; -+ } -+ - g_config_params.bond_mode = config_setting_get_int(bond_mode); - if (g_config_params.bond_mode == -1) { - return 0; --- -2.27.0 - diff --git a/0034-dfx-add-four-snmp-udp-datas.patch b/0034-dfx-add-four-snmp-udp-datas.patch deleted file mode 100644 index 844cbd7532a75de3d9f65bf93cecee09e1e715cc..0000000000000000000000000000000000000000 --- a/0034-dfx-add-four-snmp-udp-datas.patch +++ /dev/null @@ -1,28 +0,0 @@ -From fcab00c220dfd8eaced2e07d4bc3cb9be71b82ff Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Mon, 6 Nov 2023 16:38:32 +0800 -Subject: [PATCH] dfx: add four snmp udp datas - ---- - src/ltran/ltran_dfx.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index e5fd0c8..582a4b7 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -846,6 +846,11 @@ static void gazelle_print_lstack_stat_snmp_core(const struct gazelle_stack_dfx_d - printf("ip_fw_dgm: %u\n", snmp->ip_fw_dgm); - printf("ip_in_recv: %u\n", snmp->ip_in_recv); - -+ printf("udp_in_datagrams: %u\n", snmp->udp_in_datagrams); -+ printf("udp_no_ports: %u\n", snmp->udp_no_ports); -+ printf("udp_in_errors: %u\n", snmp->udp_in_errors); -+ printf("udp_out_datagrams: %u\n", snmp->udp_out_datagrams); -+ - printf("tcp_act_open: %u\n", snmp->tcp_act_open); - printf("tcp_passive_open: %u\n", snmp->tcp_passive_open); - printf("tcp_attempt_fail: %u\n", snmp->tcp_attempt_fail); --- -2.23.0 - diff --git a/0035-cfg-nic-queue-size-only-support-power-of-2.patch b/0035-cfg-nic-queue-size-only-support-power-of-2.patch deleted file mode 100644 index 11d5a646035aba3ad64519ef98e1a0f0cab9c814..0000000000000000000000000000000000000000 --- a/0035-cfg-nic-queue-size-only-support-power-of-2.patch +++ /dev/null @@ -1,38 +0,0 @@ -From cb8d274804ccc9d9c5bb434d1c2e60aaf14e8fd5 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 8 Nov 2023 20:53:22 +0800 -Subject: [PATCH] cfg: nic queue size only support power of 2 - ---- - src/lstack/core/lstack_cfg.c | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 8e83c0d..d2d0fc1 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -1191,6 +1191,10 @@ static int32_t parse_nic_rxqueue_size(void) - int32_t ret; - PARSE_ARG(g_config_params.nic.rxqueue_size, "nic_rxqueue_size", 4096, - NIC_QUEUE_SIZE_MIN, NIC_QUEUE_SIZE_MAX, ret); -+ if (!rte_is_power_of_2(g_config_params.nic.rxqueue_size)) { -+ LSTACK_LOG(ERR, LSTACK, "nic queue size only support power of two\n"); -+ return -1; -+ } - return ret; - } - -@@ -1199,6 +1203,10 @@ static int32_t parse_nic_txqueue_size(void) - int32_t ret; - PARSE_ARG(g_config_params.nic.txqueue_size, "nic_txqueue_size", 2048, - NIC_QUEUE_SIZE_MIN, NIC_QUEUE_SIZE_MAX, ret); -+ if (!rte_is_power_of_2(g_config_params.nic.txqueue_size)) { -+ LSTACK_LOG(ERR, LSTACK, "nic queue size only support power of two\n"); -+ return -1; -+ } - return ret; - } - --- -2.23.0 - diff --git a/0036-stack-fix-possible-coredump-when-arp-packet-broadcas.patch b/0036-stack-fix-possible-coredump-when-arp-packet-broadcas.patch deleted file mode 100644 index adb15f36f752828d08e5c648716dd69c071ad6a5..0000000000000000000000000000000000000000 --- a/0036-stack-fix-possible-coredump-when-arp-packet-broadcas.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 8e5dd5204c57e4443cb79cb01cdc8c16665e6734 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Fri, 10 Nov 2023 18:07:14 +0800 -Subject: [PATCH] stack: fix possible coredump when arp packet broadcast in rtc - mode - ---- - src/lstack/core/lstack_protocol_stack.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 3662948..bafb569 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -852,9 +852,9 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - return; - } - } -- ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); - if (ret != 0) { -- stack->stats.rx_allocmbuf_fail++; -+ cur_stack->stats.rx_allocmbuf_fail++; - return; - } - copy_mbuf(mbuf_copy, mbuf); --- -2.23.0 - diff --git a/0037-Fix-coredump-issue-and-skip-rte_pdump_init-for-secon.patch b/0037-Fix-coredump-issue-and-skip-rte_pdump_init-for-secon.patch deleted file mode 100644 index d90372ec279219917490fb16e81e3bd0ff0f6e59..0000000000000000000000000000000000000000 --- a/0037-Fix-coredump-issue-and-skip-rte_pdump_init-for-secon.patch +++ /dev/null @@ -1,53 +0,0 @@ -From c4e5033d44b4e6ff5a2b35e0087a26539bd9d785 Mon Sep 17 00:00:00 2001 -From: Honggang LI -Date: Mon, 13 Nov 2023 09:35:57 +0800 -Subject: [PATCH] Fix coredump issue and skip rte_pdump_init for secondary - process - -Signed-off-by: Honggang LI ---- - src/lstack/core/lstack_dpdk.c | 14 ++++++++------ - src/lstack/core/lstack_lwip.c | 2 +- - 2 files changed, 9 insertions(+), 7 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 1a5b568..5fc641e 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -125,12 +125,14 @@ int32_t dpdk_eal_init(void) - LSTACK_PRE_LOG(LSTACK_INFO, "dpdk_eal_init success\n"); - } - -- ret = rte_pdump_init(); -- if (ret < 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "rte_pdump_init failed init, rte_errno %d\n", rte_errno); -- /* We do not care whether the pdump is successfully loaded. So, just print an alarm. */ -- } else { -- LSTACK_PRE_LOG(LSTACK_INFO, "rte_pdump_init success\n"); -+ if (get_global_cfg_params()->is_primary) { -+ ret = rte_pdump_init(); -+ if (ret < 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "rte_pdump_init failed init, rte_errno %d\n", rte_errno); -+ /* We do not care whether the pdump is successfully loaded. So, just print an alarm. */ -+ } else { -+ LSTACK_PRE_LOG(LSTACK_INFO, "rte_pdump_init success\n"); -+ } - } - - return ret; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index cdb0089..a2b02df 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -1216,7 +1216,7 @@ uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, - conn[conn_num].l_port = pcbl->local_port; - conn[conn_num].tcp_sub_state = pcbl->state; - struct netconn *netconn = (struct netconn *)pcbl->callback_arg; -- conn[conn_num].fd = netconn->socket; -+ conn[conn_num].fd = netconn != NULL ? netconn->socket : -1; - if (netconn != NULL && netconn->acceptmbox != NULL) { - conn[conn_num].recv_cnt = rte_ring_count(netconn->acceptmbox->ring); - } --- -2.23.0 - diff --git a/0038-solve-problem-that-rte_pktmbuf_poll_creat-in-same-nu.patch b/0038-solve-problem-that-rte_pktmbuf_poll_creat-in-same-nu.patch deleted file mode 100644 index ffa75813c810854b2c0d6ba7038c40b2e71c1211..0000000000000000000000000000000000000000 --- a/0038-solve-problem-that-rte_pktmbuf_poll_creat-in-same-nu.patch +++ /dev/null @@ -1,159 +0,0 @@ -From 2a5891557162fb5743f13cb550dc7ff109476176 Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Wed, 1 Nov 2023 18:34:07 +0800 -Subject: [PATCH] solve problem that rte_pktmbuf_poll_creat in same numa . - ---- - src/lstack/core/lstack_dpdk.c | 11 +++--- - src/lstack/core/lstack_protocol_stack.c | 52 ++++++++++++++++++++----- - src/lstack/include/lstack_dpdk.h | 2 +- - 3 files changed, 50 insertions(+), 15 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 48fa67d..88a6c45 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -110,7 +110,7 @@ int32_t dpdk_eal_init(void) - { - int32_t ret; - struct cfg_params *global_params = get_global_cfg_params(); -- -+ - ret = rte_eal_init(global_params->dpdk_argc, global_params->dpdk_argv); - if (ret < 0) { - if (rte_errno == EALREADY) { -@@ -137,7 +137,7 @@ int32_t dpdk_eal_init(void) - } - - struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, -- uint32_t mbuf_cache_size, uint16_t queue_id) -+ uint32_t mbuf_cache_size, uint16_t queue_id, unsigned numa_id) - { - int32_t ret; - char pool_name[PATH_MAX]; -@@ -145,12 +145,13 @@ struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, - - ret = snprintf_s(pool_name, sizeof(pool_name), PATH_MAX - 1, "%s_%hu", name, queue_id); - if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d \n", ret); - return NULL; - } - - /* time stamp before pbuf_custom as priv_data */ - uint16_t private_size = RTE_ALIGN(sizeof(struct mbuf_private), RTE_CACHE_LINE_SIZE); -- pool = rte_pktmbuf_pool_create(pool_name, nb_mbuf, mbuf_cache_size, private_size, MBUF_SZ, rte_socket_id()); -+ pool = rte_pktmbuf_pool_create(pool_name, nb_mbuf, mbuf_cache_size, private_size, MBUF_SZ, numa_id); - if (pool == NULL) { - LSTACK_LOG(ERR, LSTACK, "cannot create %s pool rte_err=%d\n", pool_name, rte_errno); - } -@@ -611,7 +612,7 @@ static int32_t dpdk_ethdev_setup(const struct eth_params *eth_params, uint16_t i - int32_t ret; - - struct rte_mempool *rxtx_pktmbuf_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) { -@@ -664,7 +665,7 @@ int32_t dpdk_ethdev_start(void) - int32_t dpdk_init_lstack_kni(void) - { - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- stack_group->kni_pktmbuf_pool = create_pktmbuf_mempool("kni_mbuf", KNI_NB_MBUF, 0, 0); -+ stack_group->kni_pktmbuf_pool = create_pktmbuf_mempool("kni_mbuf", KNI_NB_MBUF, 0, 0, rte_socket_id()); - if (stack_group->kni_pktmbuf_pool == NULL) { - return -1; - } -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 3662948..2fd8d0a 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -523,6 +523,46 @@ static void gazelle_listen_thread(void *arg) - recv_pkts_from_other_process(cfg_param->process_idx, arg); - } - -+int32_t stack_group_init_mempool(void) -+{ -+ struct cfg_params *global_cfg_parmas = get_global_cfg_params(); -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ struct rte_mempool *rxtx_mbuf = NULL; -+ uint32_t cpu_id = 0; -+ unsigned numa_id = 0; -+ int queue_id = 0; -+ -+ LSTACK_LOG(INFO, LSTACK, -+ "config::num_cpu=%d num_process=%d \n", global_cfg_parmas->num_cpu, global_cfg_parmas->num_process); -+ -+ uint32_t total_mbufs = get_global_cfg_params()->mbuf_count_per_conn * get_global_cfg_params()->tcp_conn_count; -+ -+ for (int cpu_idx = 0; cpu_idx < global_cfg_parmas->num_cpu; cpu_idx++) { -+ cpu_id = global_cfg_parmas->cpus[cpu_idx]; -+ numa_id = numa_node_of_cpu(cpu_id); -+ -+ for (int process_idx = 0; process_idx < global_cfg_parmas->num_process; process_idx++) { -+ queue_id = cpu_idx * global_cfg_parmas->num_process + process_idx; -+ if (queue_id >= PROTOCOL_STACK_MAX) { -+ LSTACK_LOG(ERR, LSTACK, "index is over\n"); -+ return -1; -+ } -+ -+ rxtx_mbuf = create_pktmbuf_mempool( -+ "rxtx_mbuf", total_mbufs / stack_group->stack_num, 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); -+ return -1; -+ } -+ -+ get_protocol_stack_group()->total_rxtx_pktmbuf_pool[queue_id] = rxtx_mbuf; -+ } -+ } -+ -+ return 0; -+} -+ - int32_t stack_group_init(void) - { - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -@@ -542,14 +582,8 @@ int32_t stack_group_init(void) - stack_group->stack_setup_fail = 0; - - if (get_global_cfg_params()->is_primary) { -- uint32_t total_mbufs = get_global_cfg_params()->mbuf_count_per_conn * get_global_cfg_params()->tcp_conn_count; -- for (uint16_t idx = 0; idx < get_global_cfg_params()->tot_queue_num; idx++) { -- struct rte_mempool* rxtx_mbuf = create_pktmbuf_mempool("rxtx_mbuf", -- total_mbufs / stack_group->stack_num, RXTX_CACHE_SZ, idx); -- if (rxtx_mbuf == NULL) { -- return -1; -- } -- get_protocol_stack_group()->total_rxtx_pktmbuf_pool[idx] = rxtx_mbuf; -+ if (stack_group_init_mempool() != 0) { -+ return -1; - } - } - -@@ -970,7 +1004,7 @@ void stack_recvlist_count(struct rpc_msg *msg) - list_for_each_safe(node, temp, list) { - count++; - } -- -+ - msg->result = count; - } - -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index 6ca4f3b..1a054d6 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -56,7 +56,7 @@ void dpdk_restore_pci(void); - bool port_in_stack_queue(uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); - uint16_t get_port_id(void); - struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, -- uint32_t mbuf_cache_size, uint16_t queue_id); -+ uint32_t mbuf_cache_size, uint16_t queue_id, unsigned numa_id); - - void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id); - int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num); --- -2.23.0 - diff --git a/0040-when-timeout-occurs-process-exits.patch b/0040-when-timeout-occurs-process-exits.patch deleted file mode 100644 index 088226ac2ed79ad1edb56d6a356a054ae9ac1573..0000000000000000000000000000000000000000 --- a/0040-when-timeout-occurs-process-exits.patch +++ /dev/null @@ -1,83 +0,0 @@ -From 3a0bb8c06789288c7152e439b4eed0007a234134 Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Wed, 1 Nov 2023 20:18:07 +0800 -Subject: [PATCH] when timeout occurs,process exits. - ---- - src/common/gazelle_dfx_msg.c | 37 +++++++++++++++++++++++------------- - src/common/gazelle_dfx_msg.h | 2 +- - 2 files changed, 25 insertions(+), 14 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.c b/src/common/gazelle_dfx_msg.c -index 2070d5f..b8472be 100644 ---- a/src/common/gazelle_dfx_msg.c -+++ b/src/common/gazelle_dfx_msg.c -@@ -14,28 +14,39 @@ - #include - #include - #include -+#include -+#include - - #include "gazelle_dfx_msg.h" - - int read_specied_len(int fd, char *buf, size_t target_size) - { -- ssize_t tmp_size; -- char *tmp_pbuf = buf; -- while (target_size > 0) { -- tmp_size = read(fd, tmp_pbuf, target_size); -- if ((tmp_size == -1) && (errno != EINTR)) { -- printf("read msg from fd %d failed, errno %d\n", fd, errno); -+ size_t total_read = 0; -+ struct pollfd fds[1]; -+ fds[0].fd = fd; -+ fds[0].events = POLLIN; -+ -+ while (total_read < target_size) { -+ int ret = poll(fds, 1, GAZELLECTL_TIMEOUT); -+ if (ret < 0) { -+ printf("read_specied_len:: poll ret=%d \n", ret); - return -1; -- } else if (tmp_size == 0) { -- printf("read zero bytes from fd %d, maybe peer is down\n", fd); -+ } else if (ret == 0) { -+ printf("read_specied_len:: time out"); - return -1; - } -- -- tmp_size = (tmp_size < 0) ? 0 : tmp_size; -- target_size -= (size_t)tmp_size; -- tmp_pbuf += tmp_size; -+ if (fds[0].revents & POLLIN) { -+ int n = read(fd, buf + total_read, target_size - total_read); -+ if (n < 0) { -+ printf("read_specied_len:: read ret=%d", ret); -+ return -1; -+ } else if (n == 0) { -+ printf("read_specied_len:: Connection closed"); -+ return -1; -+ } -+ total_read += n; -+ } - } -- - return 0; - } - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 19dddd8..93fe3df 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -18,7 +18,7 @@ - - #define GAZELLE_CLIENT_NUM_MIN 1 - #define GAZELLE_LOG_LEVEL_MAX 10 -- -+#define GAZELLECTL_TIMEOUT 5000 // millisecond - /* maybe it should be consistent with MEMP_NUM_TCP_PCB */ - #define GAZELLE_LSTACK_MAX_CONN (20000 + 2000) // same as MAX_CLIENTS + RESERVED_CLIENTS in lwipopts.h - --- -2.27.0 - diff --git a/0041-wrap-support-select.patch b/0041-wrap-support-select.patch deleted file mode 100644 index 72949d00bc0a8c0bb6f3d1d153b62a012b3072cf..0000000000000000000000000000000000000000 --- a/0041-wrap-support-select.patch +++ /dev/null @@ -1,260 +0,0 @@ -From 21425705a687706faa642e8b99a9c549d7bcaab6 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Thu, 2 Nov 2023 16:10:04 +0800 -Subject: [PATCH] wrap: support select - ---- - src/lstack/api/lstack_epoll.c | 88 +++++++++++++++++++++++++ - src/lstack/api/lstack_rtc_api.c | 7 ++ - src/lstack/api/lstack_rtw_api.c | 5 ++ - src/lstack/api/lstack_wrap.c | 19 ++++++ - src/lstack/include/lstack_rtc_api.h | 2 + - src/lstack/include/lstack_rtw_api.h | 3 + - src/lstack/include/posix/lstack_epoll.h | 1 + - 7 files changed, 125 insertions(+) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index a711ae3..f2c4a8b 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -13,6 +13,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -870,3 +871,90 @@ int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); - return lwip_num + kernel_num; - } -+ -+static void select_set_revent_fdset(struct pollfd *fds, nfds_t nfds, fd_set *eventfds, uint32_t event) -+{ -+ FD_ZERO(eventfds); -+ -+ /* Set the fd_set parameter based on the actual revents. */ -+ for (int i = 0; i < nfds; i++) { -+ if (fds[i].revents & event) { -+ FD_SET(fds[i].fd, eventfds); -+ } -+ } -+} -+ -+static void fds_poll2select(struct pollfd *fds, nfds_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds) -+{ -+ if (fds == NULL || nfds == 0) { -+ return; -+ } -+ -+ if (readfds) { -+ select_set_revent_fdset(fds, nfds, readfds, EPOLLIN); -+ } -+ if (writefds) { -+ select_set_revent_fdset(fds, nfds, writefds, EPOLLOUT); -+ } -+ if (exceptfds) { -+ select_set_revent_fdset(fds, nfds, exceptfds, EPOLLERR); -+ } -+} -+ -+static inline int timeval_to_ms(struct timeval *timeval) -+{ -+ if (timeval == NULL) { -+ return -1; -+ } -+ -+ return (timeval->tv_sec * 1000 + timeval->tv_usec / 1000); -+} -+ -+static nfds_t fds_select2poll(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct pollfd **fds) -+{ -+ struct pollfd pollfds[FD_SETSIZE] = { 0 }; -+ nfds_t nfds = 0; -+ -+ for (int i = 0; i < maxfd; i++) { -+ if (readfds && FD_ISSET(i, readfds)) { -+ pollfds[nfds].events = POLLIN; -+ } -+ if (writefds && FD_ISSET(i, writefds)) { -+ pollfds[nfds].events |= POLLOUT; -+ } -+ if (exceptfds && FD_ISSET(i, exceptfds)) { -+ pollfds[nfds].events |= POLLERR; -+ } -+ if (pollfds[nfds].events > 0) { -+ pollfds[nfds].fd = i; -+ nfds++; -+ } -+ } -+ -+ *fds = pollfds; -+ return nfds; -+} -+ -+int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeval) -+{ -+ if (maxfd == 0) { -+ return 0; -+ } -+ -+ if (maxfd < 0 || maxfd > FD_SETSIZE || (readfds == NULL && writefds == NULL && exceptfds == NULL)) { -+ GAZELLE_RETURN(EINVAL); -+ } -+ -+ /* Convert the select parameter to the poll parameter. */ -+ struct pollfd *fds = NULL; -+ nfds_t nfds = fds_select2poll(maxfd, readfds, writefds, exceptfds, &fds); -+ int timeout = timeval_to_ms(timeval); -+ -+ int event_num = lstack_poll(fds, nfds, timeout); -+ -+ /* After poll, set select fd_set by fds.revents. */ -+ fds_poll2select(fds, nfds, readfds, writefds, exceptfds); -+ -+ return event_num; -+} -+ -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index 059b518..5fad3e8 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -24,6 +24,13 @@ - - int rtc_poll(struct pollfd *fds, nfds_t nfds, int timeout) - { -+ LSTACK_LOG(ERR, LSTACK, "rtc_poll: rtc currently does not support poll\n"); -+ return -1; -+} -+ -+int rtc_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) -+{ -+ LSTACK_LOG(ERR, LSTACK, "rtc_select: rtc currently does not support select\n"); - return -1; - } - -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index 7d14ffa..c524bf9 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -214,6 +214,11 @@ int rtw_poll(struct pollfd *fds, nfds_t nfds, int timeout) - return lstack_poll(fds, nfds, timeout); - } - -+int rtw_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) -+{ -+ return lstack_select(nfds, readfds, writefds, exceptfds, timeout); -+} -+ - int rtw_close(int s) - { - struct lwip_sock *sock = get_socket(s); -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index a808ee8..5bad513 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -76,6 +76,7 @@ void wrap_api_init(void) - g_wrap_api->epoll_ctl_fn = rtc_epoll_ctl; - g_wrap_api->epoll_create1_fn = rtc_epoll_create1; - g_wrap_api->epoll_create_fn = rtc_epoll_create; -+ g_wrap_api->select_fn = rtc_select; - } else { - g_wrap_api->socket_fn = rtw_socket; - g_wrap_api->accept_fn = rtw_accept; -@@ -103,6 +104,7 @@ void wrap_api_init(void) - g_wrap_api->epoll_ctl_fn = rtw_epoll_ctl; - g_wrap_api->epoll_create1_fn = rtw_epoll_create1; - g_wrap_api->epoll_create_fn = rtw_epoll_create; -+ g_wrap_api->select_fn = rtw_select; - } - } - -@@ -609,6 +611,15 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct - return lstack_sigaction(signum, act, oldact); - } - -+static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) -+{ -+ if (select_posix_path() == PATH_KERNEL) { -+ return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); -+ } -+ -+ return g_wrap_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); -+} -+ - #define WRAP_VA_PARAM(_fd, _cmd, _lwip_fcntl, _fcntl_fn) \ - do { \ - unsigned long val; \ -@@ -769,6 +780,10 @@ pid_t fork(void) - { - return lstack_fork(); - } -+int32_t select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) -+{ -+ return do_select(nfds, readfds, writefds, exceptfds, timeout); -+} - - /* -------------------------------------------------------- - * ------- Compile mode replacement interface ----------- -@@ -898,3 +913,7 @@ pid_t __wrap_fork(void) - { - return lstack_fork(); - } -+int32_t __wrap_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) -+{ -+ return do_select(nfds, readfds, writefds, exceptfds, timeout); -+} -diff --git a/src/lstack/include/lstack_rtc_api.h b/src/lstack/include/lstack_rtc_api.h -index 0aff928..dd90e59 100644 ---- a/src/lstack/include/lstack_rtc_api.h -+++ b/src/lstack/include/lstack_rtc_api.h -@@ -13,6 +13,7 @@ - #ifndef _LSTACK_RTC_API_H_ - #define _LSTACK_RTC_API_H_ - #include -+#include - #include - - /* don't include lwip/sockets.h, conflict with sys/socket.h */ -@@ -51,5 +52,6 @@ int rtc_close(int s); - int rtc_epoll_create(int flags); - int rtc_epoll_create1(int flags); - int rtc_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); -+int rtc_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); - - #endif /* __LSTACK_RTC_API_H_ */ -diff --git a/src/lstack/include/lstack_rtw_api.h b/src/lstack/include/lstack_rtw_api.h -index facf4c0..d0f77b7 100644 ---- a/src/lstack/include/lstack_rtw_api.h -+++ b/src/lstack/include/lstack_rtw_api.h -@@ -14,6 +14,7 @@ - #define _LSTACK_RTW_API_H_ - - #include -+#include - #include - - int rtw_socket(int domain, int type, int protocol); -@@ -44,4 +45,6 @@ int rtw_close(int s); - int rtw_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); - int rtw_epoll_create1(int flags); - int rtw_epoll_create(int flags); -+int rtw_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); -+ - #endif /* _LSTACK_RTW_API_H_ */ -diff --git a/src/lstack/include/posix/lstack_epoll.h b/src/lstack/include/posix/lstack_epoll.h -index c42f3a5..9c34eb3 100644 ---- a/src/lstack/include/posix/lstack_epoll.h -+++ b/src/lstack/include/posix/lstack_epoll.h -@@ -78,6 +78,7 @@ int32_t lstack_rtc_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ - int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event *events, int32_t maxevents, int32_t timeout); - int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout); - int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout); -+int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeval); - - #ifdef __cplusplus - } --- -2.27.0 - diff --git a/0042-add-vlan-support.patch b/0042-add-vlan-support.patch deleted file mode 100644 index 02c5138e53edf86f30d222b0b1e35e21a8579920..0000000000000000000000000000000000000000 --- a/0042-add-vlan-support.patch +++ /dev/null @@ -1,152 +0,0 @@ -From 1febf2f274f5bf13004ddde6d20e8744e36fd650 Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Fri, 3 Nov 2023 14:33:20 +0000 -Subject: [PATCH] add vlan support - ---- - src/common/gazelle_opt.h | 4 +++- - src/lstack/core/lstack_cfg.c | 13 +++++++++++++ - src/lstack/core/lstack_lwip.c | 4 ++++ - src/lstack/include/lstack_cfg.h | 1 + - src/lstack/lstack.conf | 3 +++ - src/lstack/netif/lstack_ethdev.c | 8 +++++++- - src/lstack/netif/lstack_vdev.c | 4 +++- - 7 files changed, 34 insertions(+), 3 deletions(-) - -diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h -index 7b855f9..0479051 100644 ---- a/src/common/gazelle_opt.h -+++ b/src/common/gazelle_opt.h -@@ -52,7 +52,9 @@ - #define STACK_THREAD_DEFAULT 4 - #define STACK_NIC_READ_DEFAULT 128 - --#define MBUF_MAX_DATA_LEN 1460 -+#define MTU_DEFAULT_DATA_LEN 1460 -+#define VLAN_HEAD_LEN 4 -+#define MBUF_MAX_DATA_LEN (MTU_DEFAULT_DATA_LEN - VLAN_HEAD_LEN) - - #define DPDK_PKT_BURST_SIZE 512 - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index c4278b5..ac96b1b 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -78,6 +78,7 @@ static int32_t parse_udp_enable(void); - 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); - - #define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \ - do { \ -@@ -138,6 +139,7 @@ static struct config_vector_t g_config_tbl[] = { - { "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 }, - { NULL, NULL } - }; - -@@ -1224,3 +1226,14 @@ static int32_t parse_stack_thread_mode(void) - - return 0; - } -+ -+static int32_t parse_nic_vlan_mode(void) -+{ -+ int32_t ret; -+ PARSE_ARG(g_config_params.nic.vlan_mode, "nic_vlan_mode", 0, 0, 4094, ret); -+ if (ret != 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid vlan mode value %d ret=%d. only support 0~4094\n", \ -+ g_config_params.nic.vlan_mode, ret); -+ } -+ return ret; -+} -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index cdb0089..d5c4896 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -196,6 +196,10 @@ void do_lwip_init_sock(int32_t fd) - (void)replenish_send_idlembuf(stack, sock); - - sock->stack = stack; -+ if (get_global_cfg_params()->nic.vlan_mode > 0 && get_global_cfg_params()->nic.vlan_mode < 4095) { -+ sock->conn->pcb.udp->netif_hints.tci = get_global_cfg_params()->nic.vlan_mode; -+ } -+ - init_list_node_null(&sock->recv_list); - init_list_node_null(&sock->event_list); - } -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index fc627e3..9dea4c1 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -62,6 +62,7 @@ struct secondary_attach_arg { - struct cfg_nic_params { - uint32_t rxqueue_size; - uint32_t txqueue_size; -+ uint16_t vlan_mode; - }; - - struct cfg_params { -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index 48973fe..3eb4685 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -63,3 +63,6 @@ process_idx=0 - - #tuple_filer=0, below cfg valid - listen_shadow=0 -+ -+#vlan mode; only support 0~4094, 0 is disabled -+nic_vlan_mode=0 -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index da16e85..383a56b 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -778,7 +778,13 @@ int32_t gazelle_eth_dev_poll(struct protocol_stack *stack, uint8_t use_ltran_fla - /* copy arp into other stack */ - if (!use_ltran_flag) { - struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(stack->pkts[i], struct rte_ether_hdr *); -- if (unlikely(RTE_BE16(RTE_ETHER_TYPE_ARP) == ethh->ether_type)) { -+ u16_t type; -+ type = ethh->ether_type; -+ if (type == PP_HTONS(ETHTYPE_VLAN)) { -+ struct eth_vlan_hdr *vlan = (struct eth_vlan_hdr *)(((char *)ethh) + SIZEOF_ETH_HDR); -+ type = vlan->tpid; -+ } -+ if (unlikely(RTE_BE16(RTE_ETHER_TYPE_ARP) == type)) { - stack_broadcast_arp(stack->pkts[i], stack); - /* copy arp into other process */ - transfer_arp_to_other_process(stack->pkts[i]); -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 81b48dc..fb295e0 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -20,6 +20,7 @@ - #include - #include - #include -+#include - - #include "lstack_cfg.h" - #include "lstack_dpdk.h" -@@ -83,12 +84,13 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt - } - - /* skip gro when tcp/ip cksum offloads disable */ -- if (get_protocol_stack_group()->rx_offload == 0) { -+ if (get_protocol_stack_group()->rx_offload == 0 || get_global_cfg_params()->nic.vlan_mode > 0) { - return pkt_num; - } - - for (uint32_t i = 0; i < pkt_num; i++) { - struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *); -+ - if (unlikely(RTE_BE16(RTE_ETHER_TYPE_IPV4) != ethh->ether_type)) { - continue; - } --- -2.27.0 - diff --git a/0043-slave-mac-addr.patch b/0043-slave-mac-addr.patch deleted file mode 100644 index f212faab3305161d68330620d39e4396c595524c..0000000000000000000000000000000000000000 --- a/0043-slave-mac-addr.patch +++ /dev/null @@ -1,194 +0,0 @@ -From 5e10c47492fef0eef886fa42651d3acef03f4196 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Wed, 1 Nov 2023 07:50:16 +0800 -Subject: [PATCH] slave mac addr - ---- - src/lstack/core/lstack_cfg.c | 50 ++++++++++++++++----------------- - src/lstack/core/lstack_dpdk.c | 47 ++++++++++++++----------------- - src/lstack/include/lstack_cfg.h | 4 +-- - 3 files changed, 48 insertions(+), 53 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index c4278b5..5ac6aa7 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -1137,40 +1137,40 @@ static int32_t parse_bond_slave_mac(void) - return 0; - } - -- int32_t ret; -- const char *slave_mac1 = NULL; -- const char *slave_mac2 = NULL; -+ int32_t ret = 0; -+ const char *bond_slave_mac = NULL; - const config_setting_t *devs = NULL; - -- devs = config_lookup(&g_config, "slave_mac1"); -- if (devs == NULL) { -- return -EINVAL; -- } -- slave_mac1 = config_setting_get_string(devs); -- if (slave_mac1 == NULL) { -- return 0; -- } -- -- devs = config_lookup(&g_config, "slave_mac2"); -+ devs = config_lookup(&g_config, "bond_slave_mac"); - if (devs == NULL) { - return -EINVAL; - } -- slave_mac2 = config_setting_get_string(devs); -- if (slave_mac2 == NULL) { -+ bond_slave_mac = config_setting_get_string(devs); -+ if (bond_slave_mac == NULL) { - return 0; - } - -- /* add dev */ -- ret = str_to_eth_addr(slave_mac1, g_config_params.bond_slave1_mac_addr); -- if (ret != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid device name %s ret=%d.\n", slave_mac1, ret); -- return ret; -- } -- -- ret = str_to_eth_addr(slave_mac2, g_config_params.bond_slave2_mac_addr); -- if (ret != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid device name %s ret=%d.\n", slave_mac2, ret); -+ int32_t k = 0; -+ char *bond_slave_mac_tmp = strdup(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) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: too many slave mac address. The maximum number of mac address is %d.\n", -+ GAZELLE_MAX_BOND_NUM); -+ return -EINVAL; -+ } -+ ret = str_to_eth_addr(mac_addr, g_config_params.bond_slave_mac_addr[k].addr_bytes); -+ if (ret != 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid device name %s ret=%d.\n", mac_addr, ret); -+ return ret; -+ } -+ mac_addr = strtok_s(NULL, delim, &tmp); -+ k = k + 1; - } -+ free(bond_slave_mac_tmp); - return ret; - } - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 1a5b568..4318096 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -496,46 +496,41 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - } - - if (bond_port) { -- int slave_num = 2; -- int32_t slave_port_id[2]; -- slave_port_id[0] = ethdev_port_id(get_global_cfg_params()->bond_slave1_mac_addr); -- if (slave_port_id[0] < 0) { -- LSTACK_LOG(ERR, LSTACK, "get slave port id failed port = %d\n", slave_port_id[0]); -- return slave_port_id[0]; -- } -- -- slave_port_id[1] = ethdev_port_id(get_global_cfg_params()->bond_slave2_mac_addr); -- if (slave_port_id[1] < 0) { -- LSTACK_LOG(ERR, LSTACK, "get slave port id failed port = %d\n", slave_port_id[1]); -- return slave_port_id[1]; -- } -- -- for (int i = 0; i < slave_num; i++) { -+ int32_t slave_port_id[GAZELLE_MAX_BOND_NUM]; -+ for (int i = 0; i < GAZELLE_MAX_BOND_NUM; i++) { -+ if (rte_is_zero_ether_addr(&get_global_cfg_params()->bond_slave_mac_addr[i])) { -+ break; -+ } -+ slave_port_id[i] = ethdev_port_id(get_global_cfg_params()->bond_slave_mac_addr[i].addr_bytes); -+ if (slave_port_id[i] < 0) { -+ LSTACK_LOG(ERR, LSTACK, "get slave port id failed port = %d\n", slave_port_id[1]); -+ return slave_port_id[i]; -+ } - ret = dpdk_ethdev_init(slave_port_id[i], 0); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed ret = %d\n", ret); - return -1; - } - ret = rte_eth_promiscuous_enable(slave_port_id[i]); -- if (ret != 0) { -+ if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk slave enable promiscuous failed ret = %d\n", ret); - return -1; - } - - ret = rte_eth_allmulticast_enable(slave_port_id[i]); -- if (ret != 0) { -+ if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk slave enable allmulticast failed ret = %d\n", ret); - return -1; - } - - ret = rte_eth_bond_slave_add(port_id, slave_port_id[i]); -- if (ret != 0) { -+ if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk add slave port failed ret = %d\n", ret); - return -1; - } - - ret = rte_eth_dev_start(slave_port_id[i]); -- if (ret != 0) { -+ if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk start slave port failed ret = %d\n", ret); - return -1; - } -@@ -550,15 +545,15 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - if (bond_port) { - struct rte_eth_dev_info slave_dev_info; - int slave_id = rte_eth_bond_primary_get(port_id); -- if (slave_id < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk get bond primary port failed port = %d\n", slave_id); -- return slave_id; -- } -+ if (slave_id < 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk get bond primary port failed port = %d\n", slave_id); -+ return slave_id; -+ } - ret = rte_eth_dev_info_get(slave_id, &slave_dev_info); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk get bond dev info failed ret = %d\n", ret); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk get bond dev info failed ret = %d\n", ret); - return ret; -- } -+ } - dev_info.rx_offload_capa = slave_dev_info.rx_offload_capa; - dev_info.tx_offload_capa = slave_dev_info.tx_offload_capa; - dev_info.reta_size = slave_dev_info.reta_size; -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index fc627e3..c1a6464 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -15,6 +15,7 @@ - #include - - #include -+#include - - #include "lstack_protocol_stack.h" - #include "gazelle_opt.h" -@@ -111,8 +112,7 @@ struct cfg_params { - bool expand_send_ring; - bool tuple_filter; - int8_t bond_mode; -- uint8_t bond_slave1_mac_addr[ETHER_ADDR_LEN]; -- uint8_t bond_slave2_mac_addr[ETHER_ADDR_LEN]; -+ struct rte_ether_addr bond_slave_mac_addr[GAZELLE_MAX_BOND_NUM]; - bool use_sockmap; - bool udp_enable; - struct cfg_nic_params nic; --- -2.27.0 - diff --git a/0044-PRE_LOG-modify-prelog-info-transfer-to-terminal-at-t.patch b/0044-PRE_LOG-modify-prelog-info-transfer-to-terminal-at-t.patch deleted file mode 100644 index 74be8d06116ea57c04b4baa9f7e1e4f6473d0509..0000000000000000000000000000000000000000 --- a/0044-PRE_LOG-modify-prelog-info-transfer-to-terminal-at-t.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 69451fc6a5a7ca0f903c82cf8b44bcdbfa2707b6 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Thu, 16 Nov 2023 17:29:21 +0800 -Subject: [PATCH] PRE_LOG: modify prelog info transfer to terminal at the same - time - ---- - src/lstack/include/lstack_log.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/include/lstack_log.h b/src/lstack/include/lstack_log.h -index 8b4209a..e4bed37 100644 ---- a/src/lstack/include/lstack_log.h -+++ b/src/lstack/include/lstack_log.h -@@ -32,7 +32,7 @@ do { \ - - static inline void lstack_prelog_init(const char *name) - { -- openlog(name, LOG_CONS | LOG_PID, LOG_USER); -+ openlog(name, LOG_PERROR | LOG_PID, LOG_USER); - } - static inline void lstack_prelog_uninit(void) - { --- -2.27.0 - diff --git a/0045-ethdev-mbuf-data-start-pointer-pbuf-payload.patch b/0045-ethdev-mbuf-data-start-pointer-pbuf-payload.patch deleted file mode 100644 index 1efe4b2017c0154c07379685ecaa1e1e30c1af33..0000000000000000000000000000000000000000 --- a/0045-ethdev-mbuf-data-start-pointer-pbuf-payload.patch +++ /dev/null @@ -1,64 +0,0 @@ -From b902a2a2f392ab945bedf7d2d9eb22f6a0aa032c Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 15 Nov 2023 19:15:13 +0800 -Subject: [PATCH] ethdev: mbuf data start pointer pbuf->payload - ---- - src/lstack/netif/lstack_ethdev.c | 26 ++++++++++---------------- - 1 file changed, 10 insertions(+), 16 deletions(-) - -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index da16e85..1d04684 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -809,10 +809,7 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - struct rte_mbuf *pre_mbuf = NULL; - struct rte_mbuf *first_mbuf = NULL; - struct pbuf *first_pbuf = pbuf; -- uint16_t header_len = 0; -- if (likely(first_pbuf != NULL)) { -- header_len = first_pbuf->l2_len + first_pbuf->l3_len + first_pbuf->l4_len; -- } -+ void *buf_addr; - - while (likely(pbuf != NULL)) { - struct rte_mbuf *mbuf = pbuf_to_mbuf(pbuf); -@@ -821,26 +818,23 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - mbuf->pkt_len = pbuf->tot_len; - mbuf->ol_flags = pbuf->ol_flags; - mbuf->next = NULL; -+ buf_addr = rte_pktmbuf_mtod(mbuf, void *); -+ -+ /* -+ * |rte_mbuf | mbuf_private | data_off | data | -+ * ^ ^ -+ * buf_addr payload -+ * m->buf_addr pointer pbuf->payload -+ */ -+ mbuf->data_off += (uint8_t *)pbuf->payload - (uint8_t *)buf_addr; - - if (first_mbuf == NULL) { - first_mbuf = mbuf; - first_pbuf = pbuf; - first_mbuf->nb_segs = 1; -- if (pbuf->header_off > 0) { -- mbuf->data_off -= header_len; -- pbuf->header_off = 0; -- } - } else { - first_mbuf->nb_segs++; - pre_mbuf->next = mbuf; -- if (pbuf->header_off == 0) { -- mbuf->data_off += header_len; -- pbuf->header_off = header_len; -- } -- } -- -- if (first_pbuf->l4_len == 8) { -- mbuf->data_off += 12; - } - - if (likely(first_mbuf->pkt_len > MBUF_MAX_LEN)) { --- -2.27.0 - diff --git a/0047-cfg-fix-lstack-mempool-lookup-failed-in-ltran-mode.patch b/0047-cfg-fix-lstack-mempool-lookup-failed-in-ltran-mode.patch deleted file mode 100644 index 4fc20ce79ec87a7cfa64cb87a863cf8243e45e2a..0000000000000000000000000000000000000000 --- a/0047-cfg-fix-lstack-mempool-lookup-failed-in-ltran-mode.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 31a7c86437dcc5c3ea03694f094fef2236021174 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Fri, 17 Nov 2023 19:52:38 +0800 -Subject: [PATCH] cfg: fix lstack mempool lookup failed in ltran mode - ---- - src/lstack/core/lstack_cfg.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index d2d0fc1..441a2dc 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -1026,6 +1026,7 @@ static int32_t parse_seperate_sendrecv_args(void) - static int32_t parse_num_process(void) - { - if (g_config_params.use_ltran) { -+ g_config_params.num_process = 1; - return 0; - } - --- -2.27.0 - diff --git a/0048-add-tx-package-timeout.patch b/0048-add-tx-package-timeout.patch deleted file mode 100644 index 51acbf08d33d5f6667789a90a77caf87ef5ee560..0000000000000000000000000000000000000000 --- a/0048-add-tx-package-timeout.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 80eccdd1bb639a1ea8c186c8c2b7f451b0b38a7e Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Tue, 31 Oct 2023 11:44:29 +0000 -Subject: [PATCH] add tx package timeout - ---- - src/lstack/netif/lstack_vdev.c | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 81b48dc..62abe80 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -142,10 +142,11 @@ static uint32_t vdev_tx_xmit(struct protocol_stack *stack, struct rte_mbuf **pkt - stack->stats.tx_prepare_fail++; - LSTACK_LOG(INFO, LSTACK, "rte_eth_tx_prepare failed\n"); - } -+ const uint32_t tbegin = sys_now(); - - do { - sent_pkts += rte_eth_tx_burst(stack->port_id, stack->queue_id, &pkts[sent_pkts], nr_pkts - sent_pkts); -- } while (sent_pkts < nr_pkts); -+ } while (sent_pkts < nr_pkts && (ENQUEUE_RING_RETRY_TIMEOUT > sys_now() - tbegin)); - - return sent_pkts; - } --- -2.27.0 - diff --git a/0049-modif-mem.patch b/0049-modif-mem.patch deleted file mode 100644 index 7ace811aedfda721dde615334ca521f3f0c05313..0000000000000000000000000000000000000000 --- a/0049-modif-mem.patch +++ /dev/null @@ -1,48 +0,0 @@ -From e69c39c7c73abd1245c1f7aecde3333fdb45ca2b Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Sat, 18 Nov 2023 17:07:32 +0800 -Subject: [PATCH] modif mem - ---- - src/lstack/api/lstack_epoll.c | 10 ++++------ - 1 file changed, 4 insertions(+), 6 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index f2c4a8b..7572918 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -910,9 +910,9 @@ static inline int timeval_to_ms(struct timeval *timeval) - return (timeval->tv_sec * 1000 + timeval->tv_usec / 1000); - } - --static nfds_t fds_select2poll(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct pollfd **fds) -+static nfds_t fds_select2poll(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct pollfd *fds) - { -- struct pollfd pollfds[FD_SETSIZE] = { 0 }; -+ struct pollfd *pollfds = fds; - nfds_t nfds = 0; - - for (int i = 0; i < maxfd; i++) { -@@ -930,8 +930,6 @@ static nfds_t fds_select2poll(int maxfd, fd_set *readfds, fd_set *writefds, fd_s - nfds++; - } - } -- -- *fds = pollfds; - return nfds; - } - -@@ -946,8 +944,8 @@ int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfd - } - - /* Convert the select parameter to the poll parameter. */ -- struct pollfd *fds = NULL; -- nfds_t nfds = fds_select2poll(maxfd, readfds, writefds, exceptfds, &fds); -+ struct pollfd fds[FD_SETSIZE] = { 0 }; -+ nfds_t nfds = fds_select2poll(maxfd, readfds, writefds, exceptfds, fds); - int timeout = timeval_to_ms(timeval); - - int event_num = lstack_poll(fds, nfds, timeout); --- -2.27.0 - diff --git a/0050-enable-ipv6.patch b/0050-enable-ipv6.patch deleted file mode 100644 index 2337d2ffad47f7286161fe9e07e22226519ec4f8..0000000000000000000000000000000000000000 --- a/0050-enable-ipv6.patch +++ /dev/null @@ -1,734 +0,0 @@ -From 480ef35615b5b0cb21818b117d4bedec42de93e4 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Tue, 31 Oct 2023 04:24:34 +0800 -Subject: [PATCH] enable ipv6 - ---- - src/common/gazelle_opt.h | 3 +- - src/lstack/api/lstack_wrap.c | 93 ++++++---------- - src/lstack/core/lstack_cfg.c | 29 ++++- - src/lstack/core/lstack_control_plane.c | 4 +- - src/lstack/core/lstack_dpdk.c | 29 +++-- - src/lstack/core/lstack_lwip.c | 38 +++++-- - src/lstack/core/lstack_protocol_stack.c | 5 +- - src/lstack/include/lstack_cfg.h | 2 + - src/lstack/include/lstack_dpdk.h | 3 +- - src/lstack/netif/lstack_ethdev.c | 141 ++++++++++++++++-------- - src/lstack/netif/lstack_vdev.c | 36 +++--- - src/ltran/ltran_timer.c | 8 ++ - 12 files changed, 241 insertions(+), 150 deletions(-) - -diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h -index 0479051..7316fc6 100644 ---- a/src/common/gazelle_opt.h -+++ b/src/common/gazelle_opt.h -@@ -54,7 +54,8 @@ - - #define MTU_DEFAULT_DATA_LEN 1460 - #define VLAN_HEAD_LEN 4 --#define MBUF_MAX_DATA_LEN (MTU_DEFAULT_DATA_LEN - VLAN_HEAD_LEN) -+#define IPV6_EXTRA_HEAD_LEN 20 -+#define MBUF_MAX_DATA_LEN (MTU_DEFAULT_DATA_LEN - VLAN_HEAD_LEN - IPV6_EXTRA_HEAD_LEN) - - #define DPDK_PKT_BURST_SIZE 512 - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 5bad513..9468003 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -12,6 +12,8 @@ - - #define _GNU_SOURCE - #include -+#include -+#include - - #include - #include -@@ -184,28 +186,6 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, - return posix_api->accept4_fn(s, addr, addrlen, flags); - } - --#define SIOCGIFADDR 0x8915 --static int get_addr(struct sockaddr_in *sin, char *interface) --{ -- int sockfd = 0; -- struct ifreq ifr; -- -- if ((sockfd = posix_api->socket_fn(AF_INET, SOCK_STREAM, 0)) < 0) return -1; -- -- memset_s(&ifr, sizeof(ifr), 0, sizeof(ifr)); -- snprintf_s(ifr.ifr_name, sizeof(ifr.ifr_name), (sizeof(ifr.ifr_name) - 1), "%s", interface); -- -- if (posix_api->ioctl_fn(sockfd, SIOCGIFADDR, &ifr) < 0) { -- posix_api->close_fn(sockfd); -- return -1; -- } -- posix_api->close_fn(sockfd); -- -- memcpy_s(sin, sizeof(struct sockaddr_in), &ifr.ifr_addr, sizeof(struct sockaddr_in)); -- -- return 0; --} -- - static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen) - { - if (name == NULL) { -@@ -229,55 +209,39 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - - bool is_dst_ip_localhost(const struct sockaddr *addr) - { -- struct sockaddr_in *servaddr = (struct sockaddr_in *) addr; -- char *line = NULL; -- char *p; -- size_t linel = 0; -- int linenum = 0; -- if (get_global_cfg_params()->host_addr.addr == servaddr->sin_addr.s_addr) { -- return true; -- } -+ struct ifaddrs *ifap; -+ struct ifaddrs *ifa; - -- FILE *ifh = fopen("/proc/net/dev", "r"); -- if (ifh == NULL) { -- LSTACK_LOG(ERR, LSTACK, "failed to open /proc/net/dev, errno is %d\n", errno); -- return false; -+ if (addr->sa_family == AF_INET) { -+ if (get_global_cfg_params()->host_addr.addr == ((struct sockaddr_in *)addr)->sin_addr.s_addr) { -+ return true; -+ } - } -- struct sockaddr_in* sin = malloc(sizeof(struct sockaddr_in)); -- if (sin == NULL) { -- LSTACK_LOG(ERR, LSTACK, "sockaddr_in malloc failed\n"); -- fclose(ifh); -+ -+ if (getifaddrs(&ifap) == -1) { -+ LSTACK_LOG(ERR, LSTACK, "get interface IP address failed\n"); - return false; - } - -- while (getdelim(&line, &linel, '\n', ifh) > 0) { -- /* 2: skip the first two lines, which are not nic name */ -- if (linenum++ < 2) { -+ for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { -+ if (ifa->ifa_addr == NULL) { - continue; - } -- -- p = line; -- while (isspace(*p)) { -- ++p; -- } -- int n = strcspn(p, ": \t"); -- -- char interface[20] = {0}; /* 20: nic name len */ -- strncpy_s(interface, sizeof(interface), p, n); -- -- memset_s(sin, sizeof(struct sockaddr_in), 0, sizeof(struct sockaddr_in)); -- int ret = get_addr(sin, interface); -- if (ret == 0) { -- if (sin->sin_addr.s_addr == servaddr->sin_addr.s_addr) { -- free(sin); -- fclose(ifh); -+ if (ifa->ifa_addr->sa_family == AF_INET && addr->sa_family == AF_INET) { -+ struct sockaddr_in *if_addr = (struct sockaddr_in *)ifa->ifa_addr; -+ if (memcmp(&if_addr->sin_addr, &((struct sockaddr_in *)addr)->sin_addr, sizeof(struct in_addr)) == 0) { -+ freeifaddrs(ifap); -+ return true; -+ } -+ } else if (ifa->ifa_addr->sa_family == AF_INET6 && addr->sa_family == AF_INET6) { -+ struct sockaddr_in6 *if_addr = (struct sockaddr_in6 *)ifa->ifa_addr; -+ if (memcmp(&if_addr->sin6_addr, &((struct sockaddr_in6 *)addr)->sin6_addr, sizeof(struct in6_addr)) == 0) { -+ freeifaddrs(ifap); - return true; - } - } - } -- free(sin); -- fclose(ifh); -- -+ freeifaddrs(ifap); - return false; - } - -@@ -303,11 +267,15 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - } - - int32_t ret = 0; -+ int32_t remote_port; -+ bool is_local = is_dst_ip_localhost(name); -+ -+ remote_port = htons(((struct sockaddr_in *)name)->sin_port); -+ - char listen_ring_name[RING_NAME_LEN]; -- int remote_port = htons(((struct sockaddr_in *)name)->sin_port); - snprintf_s(listen_ring_name, sizeof(listen_ring_name), sizeof(listen_ring_name) - 1, - "listen_rx_ring_%d", remote_port); -- if (is_dst_ip_localhost(name) && rte_ring_lookup(listen_ring_name) == NULL) { -+ if (is_local && rte_ring_lookup(listen_ring_name) == NULL) { - ret = posix_api->connect_fn(s, name, namelen); - SET_CONN_TYPE_HOST(sock->conn); - } else { -@@ -403,6 +371,7 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - } - - if ((domain != AF_INET && domain != AF_UNSPEC) || -+ ((domain == AF_INET6) && !get_global_cfg_params()->ipv6_enable) || - ((type & SOCK_DGRAM) && !get_global_cfg_params()->udp_enable)) { - return posix_api->socket_fn(domain, type, protocol); - } -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 729dccb..9f3143f 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -46,6 +46,7 @@ static struct cfg_params g_config_params; - static config_t g_config; - - static int32_t parse_host_addr(void); -+static int32_t parse_host_addr6(void); - static int32_t parse_low_power_mode(void); - static int32_t parse_stack_cpu_number(void); - static int32_t parse_app_bind_numa(void); -@@ -75,6 +76,7 @@ static int32_t parse_bond_mode(void); - static int32_t parse_bond_slave_mac(void); - static int32_t parse_use_sockmap(void); - static int32_t parse_udp_enable(void); -+static int32_t parse_ipv6_enable(void); - static int32_t parse_nic_rxqueue_size(void); - static int32_t parse_nic_txqueue_size(void); - static int32_t parse_stack_thread_mode(void); -@@ -107,6 +109,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 }, -@@ -136,6 +139,7 @@ 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 }, -+ { "ipv6_enable", parse_ipv6_enable }, - { "nic_rxqueue_size", parse_nic_rxqueue_size}, - { "nic_txqueue_size", parse_nic_txqueue_size}, - { "stack_thread_mode", parse_stack_thread_mode }, -@@ -221,15 +225,29 @@ static int32_t parse_host_addr(void) - if (g_config_params.host_addr.addr == INADDR_NONE) { - return -EINVAL; - } -+ return 0; -+} - -+static int32_t parse_host_addr6(void) -+{ -+ char *value = NULL; -+ bool ok; -+ -+ ok = config_lookup_string(&g_config, "host_addr6", (const char **)&value); -+ if (!ok) { -+ return 0; -+ } -+ -+ if (ip6addr_aton(value, &g_config_params.host_addr6) == 0) { -+ return -EINVAL; -+ } - return 0; - } - - int32_t match_host_addr(uint32_t addr) - { - /* network byte order */ -- if (addr == g_config_params.host_addr.addr || -- addr == INADDR_ANY) { -+ if (addr == g_config_params.host_addr.addr || addr == INADDR_ANY) { - return 1; - } - return 0; -@@ -1251,3 +1269,10 @@ static int32_t parse_nic_vlan_mode(void) - } - return ret; - } -+ -+static int32_t parse_ipv6_enable(void) -+{ -+ int32_t ret; -+ PARSE_ARG(g_config_params.ipv6_enable, "ipv6_enable", 0, 0, 1, ret); -+ return ret; -+} -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index be156dc..f5049e9 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -355,15 +355,13 @@ static int32_t reg_conn(enum tcp_list_state table_state, enum reg_ring_type reg_ - if (conn->conn_list[i].state != table_state) { - continue; - } -- - qtuple.protocol = 0; - qtuple.src_ip = conn->conn_list[i].lip; - qtuple.src_port = lwip_htons(conn->conn_list[i].l_port); - qtuple.dst_ip = conn->conn_list[i].rip; - qtuple.dst_port = lwip_htons(conn->conn_list[i].r_port); - -- if ((table_state == LISTEN_LIST) && -- (!match_host_addr(qtuple.src_ip))) { -+ if ((table_state == LISTEN_LIST) && (!match_host_addr(qtuple.src_ip))) { - continue; - } - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 0776e50..6700357 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -763,20 +763,33 @@ int32_t init_dpdk_ethdev(void) - return 0; - } - --bool port_in_stack_queue(uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) -+bool port_in_stack_queue(ip_addr_t src_ip, ip_addr_t dst_ip, uint16_t src_port, uint16_t dst_port) - { - struct protocol_stack_group *stack_group = get_protocol_stack_group(); - if (stack_group->reta_mask == 0 || stack_group->nb_queues <= 1) { - return true; - } - -- struct rte_ipv4_tuple tuple = {0}; -- tuple.src_addr = rte_be_to_cpu_32(src_ip); -- tuple.dst_addr = rte_be_to_cpu_32(dst_ip); -- tuple.sport = src_port; -- tuple.dport = dst_port; -- -- uint32_t hash = rte_softrss((uint32_t *)&tuple, RTE_THASH_V4_L4_LEN, g_default_rss_key); -+ union rte_thash_tuple tuple; -+ uint32_t hash = 0; -+ if (IP_IS_V4_VAL(src_ip)) { -+ tuple.v4.src_addr = rte_be_to_cpu_32(ip_2_ip4(&src_ip)->addr); -+ tuple.v4.dst_addr = rte_be_to_cpu_32(ip_2_ip4(&dst_ip)->addr); -+ tuple.v4.sport = src_port; -+ tuple.v4.dport = dst_port; -+ hash = rte_softrss((uint32_t *)&tuple, RTE_THASH_V4_L4_LEN, g_default_rss_key); -+ } else { -+ int i; -+ for (i = 0; i < 4; i++) { -+ *((uint32_t *)tuple.v6.src_addr + i) = -+ rte_be_to_cpu_32(*((const uint32_t *)src_ip.u_addr.ip6.addr + i)); -+ *((uint32_t *)tuple.v6.dst_addr + i) = -+ rte_be_to_cpu_32(*((const uint32_t *)dst_ip.u_addr.ip6.addr + i)); -+ } -+ tuple.v6.sport = src_port; -+ tuple.v6.dport = dst_port; -+ hash = rte_softrss((uint32_t *)&tuple, RTE_THASH_V6_L4_LEN, g_default_rss_key); -+ } - - uint32_t reta_index = hash & stack_group->reta_mask; - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 3baddec..c8b4e8f 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -123,7 +123,7 @@ static struct pbuf *init_mbuf_to_pbuf(struct rte_mbuf *mbuf, pbuf_layer layer, u - pbuf->allow_in = 1; - pbuf->head = 0; - pbuf->last = pbuf; -- pbuf->addr.addr = 0; -+ pbuf->addr = *IP_ANY_TYPE; - pbuf->port = 0; - pthread_spin_init(&pbuf->pbuf_lock, PTHREAD_PROCESS_SHARED); - } -@@ -441,10 +441,21 @@ static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t l - ssize_t send_len = do_app_write(pbufs, buf, len, write_num); - - if (addr) { -- struct sockaddr_in *saddr = (struct sockaddr_in *)addr; -- for (int i = 0; i < write_num; i++) { -- pbufs[i]->addr.addr = saddr->sin_addr.s_addr; -- pbufs[i]->port = lwip_ntohs((saddr)->sin_port); -+ if (addr->sa_family == AF_INET) { -+ struct sockaddr_in *saddr = (struct sockaddr_in *)addr; -+ for (int i = 0; i < write_num; i++) { -+ pbufs[i]->addr.u_addr.ip4.addr = saddr->sin_addr.s_addr; -+ pbufs[i]->port = lwip_ntohs((saddr)->sin_port); -+ } -+ } else if (addr->sa_family == AF_INET6) { -+ struct sockaddr_in6 *saddr = (struct sockaddr_in6 *)addr; -+ for (int i = 0; i < write_num; i++) { -+ memcpy_s(pbufs[i]->addr.u_addr.ip6.addr, sizeof(pbufs[i]->addr.u_addr.ip6.addr), -+ saddr->sin6_addr.s6_addr, sizeof(saddr->sin6_addr.s6_addr)); -+ pbufs[i]->port = lwip_ntohs((saddr)->sin6_port); -+ } -+ } else { -+ return 0; - } - } - -@@ -573,10 +584,15 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - if (wakeup) { - wakeup->stat.app_write_cnt += write_num; - } -- if (addr) { -+ if (addr->sa_family == AF_INET) { - struct sockaddr_in *saddr = (struct sockaddr_in *)addr; -- last_pbuf->addr.addr = saddr->sin_addr.s_addr; -+ last_pbuf->addr.u_addr.ip4.addr = saddr->sin_addr.s_addr; - last_pbuf->port = lwip_ntohs((saddr)->sin_port); -+ } else if (addr->sa_family == AF_INET6) { -+ struct sockaddr_in6 *saddr = (struct sockaddr_in6 *)addr; -+ memcpy_s(last_pbuf->addr.u_addr.ip6.addr, sizeof(last_pbuf->addr.u_addr.ip6.addr), -+ saddr->sin6_addr.s6_addr, sizeof(saddr->sin6_addr.s6_addr)); -+ last_pbuf->port = lwip_ntohs((saddr)->sin6_port); - } - } else { - (void)rpc_call_replenish(stack, sock); -@@ -1122,8 +1138,8 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - { - struct netconn *netconn = (struct netconn *)pcb->callback_arg; - -- conn->lip = pcb->local_ip.addr; -- conn->rip = pcb->remote_ip.addr; -+ conn->lip = ip_2_ip4(&pcb->local_ip)->addr; -+ conn->rip = ip_2_ip4(&pcb->remote_ip)->addr; - conn->l_port = pcb->local_port; - conn->r_port = pcb->remote_port; - conn->in_send = pcb->snd_queuelen; -@@ -1173,7 +1189,7 @@ void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_soc - - int32_t do_lwip_socket(int domain, int type, int protocol) - { -- int32_t fd = lwip_socket(AF_INET, type, 0); -+ int32_t fd = lwip_socket(domain, type, 0); - if (fd < 0) { - return fd; - } -@@ -1216,7 +1232,7 @@ uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, - for (struct tcp_pcb_listen *pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL && conn_num < max_num; - pcbl = pcbl->next) { - conn[conn_num].state = LISTEN_LIST; -- conn[conn_num].lip = pcbl->local_ip.addr; -+ conn[conn_num].lip = ip_2_ip4(&pcbl->local_ip)->addr; - conn[conn_num].l_port = pcbl->local_port; - conn[conn_num].tcp_sub_state = pcbl->state; - struct netconn *netconn = (struct netconn *)pcbl->callback_arg; -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 74a17d4..54cf9e8 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -936,10 +936,11 @@ void stack_create_shadow_fd(struct rpc_msg *msg) - return; - } - -+ int domain = addr->sa_family; - if (NETCONN_IS_UDP(sock)) { -- clone_fd = do_lwip_socket(AF_INET, SOCK_DGRAM, 0); -+ clone_fd = do_lwip_socket(domain, SOCK_DGRAM, 0); - } else { -- clone_fd = do_lwip_socket(AF_INET, SOCK_STREAM, 0); -+ clone_fd = do_lwip_socket(domain, SOCK_STREAM, 0); - } - - if (clone_fd < 0) { -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index a7b99af..e3edc57 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -68,6 +68,7 @@ struct cfg_nic_params { - - struct cfg_params { - ip4_addr_t host_addr; -+ ip6_addr_t host_addr6; - ip4_addr_t netmask; - ip4_addr_t gateway_addr; - uint8_t mac_addr[ETHER_ADDR_LEN]; -@@ -116,6 +117,7 @@ struct cfg_params { - struct rte_ether_addr bond_slave_mac_addr[GAZELLE_MAX_BOND_NUM]; - bool use_sockmap; - bool udp_enable; -+ bool ipv6_enable; - struct cfg_nic_params nic; - bool stack_mode_rtc; - }; -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index 1a054d6..3a621d0 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -13,6 +13,7 @@ - #ifndef _GAZELLE_DPDK_H_ - #define _GAZELLE_DPDK_H_ - -+#include - #include "gazelle_opt.h" - #include "gazelle_dfx_msg.h" - -@@ -53,7 +54,7 @@ int dpdk_ethdev_start(void); - void dpdk_skip_nic_init(void); - int32_t dpdk_init_lstack_kni(void); - void dpdk_restore_pci(void); --bool port_in_stack_queue(uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); -+bool port_in_stack_queue(ip_addr_t src_ip, ip_addr_t dst_ip, uint16_t src_port, uint16_t dst_port); - uint16_t get_port_id(void); - struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, - uint32_t mbuf_cache_size, uint16_t queue_id, unsigned numa_id); -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 6914cff..02aa611 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -16,9 +16,11 @@ - #include - #include - #include -+#include - - #include - #include -+#include - #include - #include - #include -@@ -664,57 +666,92 @@ void concat_mbuf_and_queue_id(struct rte_mbuf *mbuf, uint16_t queue_id, - sprintf_s(mbuf_and_queue_id, write_len, "%lu%s%u", mbuf, SPLIT_DELIM, queue_id); - } - --int distribute_pakages(struct rte_mbuf *mbuf) --{ -- struct rte_ipv4_hdr *iph = rte_pktmbuf_mtod_offset(mbuf, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr)); -- uint8_t ip_version = (iph->version_ihl & 0xf0) >> IPV4_VERSION_OFFSET; -- if (likely(ip_version == IPV4_VERSION)) { -- if (likely(iph->next_proto_id == IPPROTO_TCP)) { -- int each_process_queue_num = get_global_cfg_params()->num_queue; -- -- struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(mbuf, struct rte_tcp_hdr *, -- sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr)); -- uint16_t dst_port = tcp_hdr->dst_port; -- uint32_t user_process_idx; -- -- if (g_listen_ports[dst_port] != INVAILD_PROCESS_IDX) { -- user_process_idx = g_listen_ports[dst_port]; -- } else { -- user_process_idx = g_user_ports[dst_port]; -+static int mbuf_to_idx(struct rte_mbuf *mbuf, uint16_t *dst_port) -+{ -+ struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr *); -+ u16_t type = rte_be_to_cpu_16(ethh->ether_type); -+ uint32_t index = 0; -+ if (type == RTE_ETHER_TYPE_IPV4) { -+ struct rte_ipv4_hdr *iph = rte_pktmbuf_mtod_offset(mbuf, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr)); -+ uint8_t ip_version = (iph->version_ihl & 0xf0) >> IPV4_VERSION_OFFSET; -+ if (likely(ip_version == IPV4_VERSION)) { -+ if (likely(iph->next_proto_id == IPPROTO_TCP)) { -+ struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(mbuf, struct rte_tcp_hdr *, -+ sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr)); -+ *dst_port = tcp_hdr->dst_port; -+ -+ if (unlikely(tcp_hdr->tcp_flags == TCP_SYN)) { -+ uint32_t src_ip = iph->src_addr; -+ uint16_t src_port = tcp_hdr->src_port; -+ index = rte_jhash_3words(src_ip, src_port | ((*dst_port) << 16), 0, 0); -+ } else { -+ return -1; -+ } - } -+ } -+ } else if (type == RTE_ETHER_TYPE_IPV6) { -+ struct rte_ipv6_hdr *iph = rte_pktmbuf_mtod_offset(mbuf, struct rte_ipv6_hdr *, sizeof(struct rte_ether_hdr)); -+ if (likely(iph->proto == IPPROTO_TCP)) { -+ struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(mbuf, struct rte_tcp_hdr *, -+ sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv6_hdr)); -+ *dst_port = tcp_hdr->dst_port; - -- if (user_process_idx == INVAILD_PROCESS_IDX) { -- return TRANSFER_KERNEL; -- } - if (unlikely(tcp_hdr->tcp_flags == TCP_SYN)) { -- uint32_t src_ip = iph->src_addr; -+ uint32_t *src_ip = (uint32_t *) &iph->src_addr; - uint16_t src_port = tcp_hdr->src_port; -- uint32_t index = rte_jhash_3words(src_ip, src_port | ((dst_port) << 16), 0, 0); -- index = index % each_process_queue_num; -- uint16_t queue_id = 0; -- 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; -- } -- if (queue_id != 0) { -- if (user_process_idx == 0) { -- transfer_tcp_to_thread(mbuf, queue_id); -- } else { -- char mbuf_and_queue_id[TRANSFER_TCP_MUBF_LEN]; -- concat_mbuf_and_queue_id(mbuf, queue_id, mbuf_and_queue_id, TRANSFER_TCP_MUBF_LEN); -- transfer_pkt_to_other_process(mbuf_and_queue_id, user_process_idx, -- TRANSFER_TCP_MUBF_LEN, false); -- } -- return TRANSFER_OTHER_THREAD; -- } else { -- return TRANSFER_CURRENT_THREAD; -- } -+ uint32_t v = rte_jhash_3words(src_ip[0], src_ip[1], src_ip[2], 0); -+ index = rte_jhash_3words(src_ip[3], src_port | ((*dst_port) << 16), v, 0); - } else { -- return TRANSFER_CURRENT_THREAD; -+ return -1; - } - } -+ } else { -+ return -1; -+ } -+ return index; -+} -+ -+int distribute_pakages(struct rte_mbuf *mbuf) -+{ -+ uint16_t dst_port = 0; -+ uint32_t index = mbuf_to_idx(mbuf, &dst_port); -+ if (index == -1) { -+ return TRANSFER_CURRENT_THREAD; -+ } -+ -+ uint16_t queue_id = 0; -+ uint32_t user_process_idx = 0; -+ int each_process_queue_num = get_global_cfg_params()->num_queue; -+ index = index % each_process_queue_num; -+ if (g_listen_ports[dst_port] != INVAILD_PROCESS_IDX) { -+ user_process_idx = g_listen_ports[dst_port]; -+ } else { -+ user_process_idx = g_user_ports[dst_port]; -+ } -+ -+ if (user_process_idx == INVAILD_PROCESS_IDX) { -+ 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; -+ } -+ if (queue_id != 0) { -+ if (user_process_idx == 0) { -+ transfer_tcp_to_thread(mbuf, queue_id); -+ } else { -+ char mbuf_and_queue_id[TRANSFER_TCP_MUBF_LEN]; -+ concat_mbuf_and_queue_id(mbuf, queue_id, mbuf_and_queue_id, TRANSFER_TCP_MUBF_LEN); -+ transfer_pkt_to_other_process(mbuf_and_queue_id, user_process_idx, -+ TRANSFER_TCP_MUBF_LEN, false); -+ } -+ return TRANSFER_OTHER_THREAD; -+ } else { -+ return TRANSFER_CURRENT_THREAD; - } -+ - return TRANSFER_KERNEL; - } - -@@ -874,10 +911,11 @@ static err_t eth_dev_init(struct netif *netif) - - netif->name[0] = 'e'; - netif->name[1] = 't'; -- netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP; -+ netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP | NETIF_FLAG_MLD6; - netif->mtu = FRAME_MTU; - netif->output = etharp_output; - netif->linkoutput = eth_dev_output; -+ netif->output_ip6 = ethip6_output; - - int32_t ret; - ret = memcpy_s(netif->hwaddr, sizeof(netif->hwaddr), cfg->mac_addr, ETHER_ADDR_LEN); -@@ -914,11 +952,20 @@ int32_t ethdev_init(struct protocol_stack *stack) - - netif_set_default(&stack->netif); - -- struct netif *netif = netif_add(&stack->netif, &cfg->host_addr, &cfg->netmask, &cfg->gateway_addr, NULL, -- eth_dev_init, ethernet_input); -+ struct netif *netif; -+ if (!ip4_addr_isany(&cfg->host_addr)) { -+ netif = netif_add(&stack->netif, &cfg->host_addr, &cfg->netmask, -+ &cfg->gateway_addr, NULL, eth_dev_init, ethernet_input); -+ } else { -+ netif = netif_add(&stack->netif, NULL, NULL, NULL, NULL, eth_dev_init, ethernet_input); -+ } - if (netif == NULL) { - LSTACK_LOG(ERR, LSTACK, "netif_add failed\n"); -- return ERR_IF; -+ return ERR_IF; -+ } -+ if (!ip6_addr_isany(&cfg->host_addr6)) { -+ netif_ip6_addr_set(&stack->netif, 0, &cfg->host_addr6); -+ netif_ip6_addr_set_state(&stack->netif, 0, IP6_ADDR_VALID); - } - - netif_set_link_up(&stack->netif); -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 4a93f87..d57ce59 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -90,24 +90,34 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt - - for (uint32_t i = 0; i < pkt_num; i++) { - struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *); -+ u16_t type = ethh->ether_type; - -- if (unlikely(RTE_BE16(RTE_ETHER_TYPE_IPV4) != ethh->ether_type)) { -- continue; -- } - pkts[i]->l2_len = sizeof(struct rte_ether_hdr); - -- struct rte_ipv4_hdr *iph = rte_pktmbuf_mtod_offset(pkts[i], struct rte_ipv4_hdr *, -- sizeof(struct rte_ether_hdr)); -- if (unlikely((iph->version_ihl & IPV4_MASK) != IPV4_VERION)) { -- continue; -- } -- pkts[i]->l3_len = sizeof(struct rte_ipv4_hdr); -+ if (type == RTE_BE16(RTE_ETHER_TYPE_IPV4)) { -+ struct rte_ipv4_hdr *iph = rte_pktmbuf_mtod_offset(pkts[i], struct rte_ipv4_hdr *, -+ sizeof(struct rte_ether_hdr)); -+ if (unlikely((iph->version_ihl & IPV4_MASK) != IPV4_VERION)) { -+ continue; -+ } -+ pkts[i]->l3_len = sizeof(struct rte_ipv4_hdr); - -- struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(pkts[i], struct rte_tcp_hdr *, -- sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr)); -- pkts[i]->l4_len = TCP_HDR_LEN(tcp_hdr); -+ struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(pkts[i], struct rte_tcp_hdr *, -+ sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr)); -+ pkts[i]->l4_len = TCP_HDR_LEN(tcp_hdr); - -- pkts[i]->packet_type = RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP; -+ pkts[i]->packet_type = RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP; -+ } else if (type == RTE_BE16(RTE_ETHER_TYPE_IPV6)) { -+ pkts[i]->l3_len = sizeof(struct rte_ipv6_hdr); -+ -+ struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(pkts[i], struct rte_tcp_hdr *, -+ sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv6_hdr)); -+ pkts[i]->l4_len = TCP_HDR_LEN(tcp_hdr); -+ -+ pkts[i]->packet_type = RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP; -+ } else { -+ continue; -+ } - } - pkt_num = rte_gro_reassemble_burst(pkts, pkt_num, &gro_param); - -diff --git a/src/ltran/ltran_timer.c b/src/ltran/ltran_timer.c -index 85ea324..749b8e0 100644 ---- a/src/ltran/ltran_timer.c -+++ b/src/ltran/ltran_timer.c -@@ -24,6 +24,14 @@ - #include "ltran_tcp_conn.h" - #include "ltran_instance.h" - #include "ltran_timer.h" -+/* undefine lwip_ntohs in lwip/def.h */ -+#ifdef ntohs -+#undef ntohs -+#endif -+#ifdef htons -+#undef htons -+#endif -+ - - static uint64_t g_cycles_per_us = 0; - --- -2.27.0 - diff --git a/0051-wrap-dont-hijack-select-temporarily.patch b/0051-wrap-dont-hijack-select-temporarily.patch deleted file mode 100644 index ff7231506001a5d2b8a0bfa9900d14c9f7637b4b..0000000000000000000000000000000000000000 --- a/0051-wrap-dont-hijack-select-temporarily.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 801aafea1889a5c54ca884f62b0a24c5d6b6d8ce Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Sat, 18 Nov 2023 19:09:34 +0800 -Subject: [PATCH] wrap: dont hijack select temporarily - ---- - src/lstack/api/lstack_wrap.c | 6 +----- - 1 file changed, 1 insertion(+), 5 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 9468003..1e67b76 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -582,11 +582,7 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct - - static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) - { -- if (select_posix_path() == PATH_KERNEL) { -- return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); -- } -- -- return g_wrap_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); -+ return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); - } - - #define WRAP_VA_PARAM(_fd, _cmd, _lwip_fcntl, _fcntl_fn) \ --- -2.27.0 - diff --git a/0052-ipv6.patch b/0052-ipv6.patch deleted file mode 100644 index c587389d50d27aa1bd08410b160efa59027e7114..0000000000000000000000000000000000000000 --- a/0052-ipv6.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 894c59a8e2351f0c0b34e3582054a696a913f114 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Sat, 18 Nov 2023 00:44:43 +0800 -Subject: [PATCH] ipv6 - ---- - src/lstack/api/lstack_wrap.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 1e67b76..b6ac1bd 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -370,7 +370,7 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - return posix_api->socket_fn(domain, type, protocol); - } - -- if ((domain != AF_INET && domain != AF_UNSPEC) || -+ if ((domain != AF_INET && domain != AF_UNSPEC && domain != AF_INET6) || - ((domain == AF_INET6) && !get_global_cfg_params()->ipv6_enable) || - ((type & SOCK_DGRAM) && !get_global_cfg_params()->udp_enable)) { - return posix_api->socket_fn(domain, type, protocol); --- -2.27.0 - diff --git a/0053-add-gazelle-log.patch b/0053-add-gazelle-log.patch deleted file mode 100644 index ec5036a308888b7f53d06b046efdc19af986d73d..0000000000000000000000000000000000000000 --- a/0053-add-gazelle-log.patch +++ /dev/null @@ -1,258 +0,0 @@ -From 9980175dfd8e33ed17bbe928c5adaeee10907e4b Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Sat, 18 Nov 2023 10:28:59 +0800 -Subject: [PATCH] add gazelle log - ---- - src/common/gazelle_dfx_msg.c | 6 ++--- - src/lstack/core/lstack_control_plane.c | 9 ++++++++ - src/lstack/core/lstack_dpdk.c | 31 ++++++++++++++++++++------ - 3 files changed, 36 insertions(+), 10 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.c b/src/common/gazelle_dfx_msg.c -index b8472be..5fe4e06 100644 ---- a/src/common/gazelle_dfx_msg.c -+++ b/src/common/gazelle_dfx_msg.c -@@ -32,16 +32,16 @@ int read_specied_len(int fd, char *buf, size_t target_size) - printf("read_specied_len:: poll ret=%d \n", ret); - return -1; - } else if (ret == 0) { -- printf("read_specied_len:: time out"); -+ printf("read_specied_len:: time out \n"); - return -1; - } - if (fds[0].revents & POLLIN) { - int n = read(fd, buf + total_read, target_size - total_read); - if (n < 0) { -- printf("read_specied_len:: read ret=%d", ret); -+ printf("read_specied_len:: read ret=%d \n", ret); - return -1; - } else if (n == 0) { -- printf("read_specied_len:: Connection closed"); -+ printf("read_specied_len:: Connection closed \n"); - return -1; - } - total_read += n; -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index be156dc..746c209 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -134,11 +134,13 @@ static int32_t msg_proc_init(enum request_type rqt_type, struct reg_request_msg - - ret = strncpy_s(conf->file_prefix, PATH_MAX, global_params->sec_attach_arg.file_prefix, PATH_MAX - 1); - if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "strncpy_s fail ret=%d \n", ret); - return ret; - } - - ret = memcpy_s(conf->mac_addr, ETHER_ADDR_LEN, global_params->mac_addr, ETHER_ADDR_LEN); - if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "memcpy_s fail ret=%d \n", ret); - return ret; - } - switch (rqt_type) { -@@ -153,14 +155,17 @@ static int32_t msg_proc_init(enum request_type rqt_type, struct reg_request_msg - conf->argc = 0; - ret = gazelle_copy_param(OPT_SOCKET_MEM, true, (int32_t *)&conf->argc, conf->argv); - if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "gazelle_copy_param OPT_SOCKET_MEM fail ret=%d \n", ret); - return ret; - } - ret = gazelle_copy_param(OPT_FILE_PREFIX, true, (int32_t *)&conf->argc, conf->argv); - if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "gazelle_copy_param OPT_FILE_PREFIX fail ret=%d \n", ret); - return ret; - } - ret = gazelle_copy_param(OPT_LEGACY_MEM, false, (int32_t *)&conf->argc, conf->argv); - if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "gazelle_copy_param OPT_LEGACY_MEM fail ret=%d \n", ret); - return ret; - } - -@@ -494,6 +499,7 @@ int32_t control_init_client(bool is_reconnect) - - ret = client_reg_proc_memory(is_reconnect); - if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "client_reg_proc_memory ret=%d \n", ret); - posix_api->close_fn(g_data_fd); - g_data_fd = -1; - return -1; -@@ -501,6 +507,7 @@ int32_t control_init_client(bool is_reconnect) - - ret = client_reg_proc_attach(is_reconnect); - if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "client_reg_proc_memory ret=%d \n", ret); - posix_api->close_fn(g_data_fd); - g_data_fd = -1; - return -1; -@@ -636,12 +643,14 @@ static int32_t client_reg_proc_reconnect(int32_t epfd) - /* longterm connect g_data_fd; init process info */ - ret = control_init_client(true); - if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "control_init_client fail ret=%d\n", ret); - return -1; - } - sockfd = g_data_fd; - - ret = thread_register(); - if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "thread_register fail ret=%d\n", ret); - posix_api->close_fn(sockfd); - g_data_fd = -1; - return -1; -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index da6eda0..966507f 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -75,15 +75,20 @@ int32_t thread_affinity_default(void) - { - static cpu_set_t cpuset; - static bool first_flags = true; -+ int ret = 0; - if (first_flags) { - CPU_ZERO(&cpuset); -- if (pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset) != 0) { -+ ret = pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "pthread_getaffinity_np fail ret=%d\n", ret); - return -1; - } - first_flags = false; - } else { - /* cancel the core binding from DPDK initialization */ -- if (pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset) != 0) { -+ ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "pthread_setaffinity_np fail ret=%d\n", ret); - return -1; - } - } -@@ -167,6 +172,7 @@ static struct rte_mempool* get_pktmbuf_mempool(const char *name, uint16_t queue_ - - ret = snprintf_s(pool_name, sizeof(pool_name), PATH_MAX - 1, "%s_%hu", name, queue_id); - if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d\n", ret); - return NULL; - } - pool = rte_mempool_lookup(pool_name); -@@ -185,6 +191,7 @@ static struct reg_ring_msg *create_reg_mempool(const char *name, uint16_t queue_ - - ret = snprintf_s(pool_name, sizeof(pool_name), PATH_MAX - 1, "%s_%hu", name, queue_id); - if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d\n", ret); - return NULL; - } - -@@ -205,12 +212,14 @@ int32_t pktmbuf_pool_init(struct protocol_stack *stack, uint16_t stack_num) - - stack->rxtx_pktmbuf_pool = get_pktmbuf_mempool("rxtx_mbuf", stack->queue_id); - if (stack->rxtx_pktmbuf_pool == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "rxtx_pktmbuf_pool is NULL\n"); - return -1; - } - - if (use_ltran()) { - stack->reg_buf = create_reg_mempool("reg_ring_msg", stack->queue_id); - if (stack->reg_buf == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "rxtx_pktmbuf_pool is NULL\n"); - return -1; - } - } -@@ -226,6 +235,7 @@ struct rte_mempool *create_mempool(const char *name, uint32_t count, uint32_t si - int32_t ret = snprintf_s(pool_name, sizeof(pool_name), RTE_MEMPOOL_NAMESIZE - 1, - "%s_%d", name, idx); - if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d\n", ret); - return NULL; - } - -@@ -246,6 +256,7 @@ struct rte_ring *create_ring(const char *name, uint32_t count, uint32_t flags, i - int32_t ret = snprintf_s(ring_name, sizeof(ring_name), RTE_RING_NAMESIZE - 1, - "%s_%d_%d", name, get_global_cfg_params()->process_idx, queue_id); - if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d\n", ret); - return NULL; - } - -@@ -286,6 +297,8 @@ int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, ui - { - int32_t ret = rte_pktmbuf_alloc_bulk(pool, mbufs, num); - if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_pktmbuf_alloc_bulk fail allocNum=%d, ret=%d, info:=%s \n", -+ num, ret, rte_strerror(-ret)); - return ret; - } - -@@ -477,6 +490,7 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - if (get_global_cfg_params()->bond_mode < 0) { - port_id = ethdev_port_id(get_global_cfg_params()->mac_addr); - if (port_id < 0) { -+ LSTACK_LOG(ERR, LSTACK, "ethdev_port_id FAIL port_id=%d\n", port_id); - return port_id; - } - } -@@ -589,7 +603,7 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - - ret = dpdk_ethdev_start(); - if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_start failed\n"); -+ LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_start failed ret=%d\n", ret); - stack_group->eth_params = NULL; - free(eth_params); - return ret; -@@ -644,6 +658,7 @@ int32_t dpdk_ethdev_start(void) - for (int32_t i = 0; i < get_global_cfg_params()->tot_queue_num; i++) { - ret = dpdk_ethdev_setup(stack_group->eth_params, i); - if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_setup fail queueid=%d, ret=%d\n", i, ret); - return ret; - } - } -@@ -666,11 +681,13 @@ int32_t dpdk_init_lstack_kni(void) - struct protocol_stack_group *stack_group = get_protocol_stack_group(); - stack_group->kni_pktmbuf_pool = create_pktmbuf_mempool("kni_mbuf", KNI_NB_MBUF, 0, 0, rte_socket_id()); - if (stack_group->kni_pktmbuf_pool == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "kni_mbuf is NULL\n"); - return -1; - } - - int32_t ret = dpdk_kni_init(stack_group->port_id, stack_group->kni_pktmbuf_pool); - if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk_kni_init fail ret=%d\n", ret); - return -1; - } - -@@ -706,18 +723,18 @@ int32_t init_dpdk_ethdev(void) - } - - ret = dpdk_ethdev_init(bond_port_id, 1); -- if (ret != 0) { -+ if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed ret = %d\n", ret); - return -1; - } - - ret = rte_eth_bond_xmit_policy_set(bond_port_id, BALANCE_XMIT_POLICY_LAYER34); - if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk set bond xmit policy failed ret = %d\n", ret); -+ LSTACK_LOG(ERR, LSTACK, "dpdk set bond xmit policy failed ret = %d\n", ret); - return -1; - } - -- if (get_global_cfg_params()->bond_mode == BONDING_MODE_8023AD) { -+ if (get_global_cfg_params()->bond_mode == BONDING_MODE_8023AD) { - ret = rte_eth_bond_8023ad_dedicated_queues_enable(bond_port_id); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk enable 8023 dedicated queues failed ret = %d\n", ret); -@@ -743,7 +760,7 @@ int32_t init_dpdk_ethdev(void) - } - - ret = rte_eth_dev_start(bond_port_id); -- if (ret < 0) { -+ if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk start bond port failed ret = %d\n", ret); - return -1; - } --- -2.27.0 - diff --git a/0054-PRE_LOG-modify-log-info-while-there-are-repeated-ite.patch b/0054-PRE_LOG-modify-log-info-while-there-are-repeated-ite.patch deleted file mode 100644 index 5345a88080bb372315b98e80eb43deb69256757f..0000000000000000000000000000000000000000 --- a/0054-PRE_LOG-modify-log-info-while-there-are-repeated-ite.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 38ce070bc6922470a92b925e030ba61586a6e92a Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Mon, 20 Nov 2023 11:08:10 +0800 -Subject: [PATCH] PRE_LOG: modify log info while there are repeated items in - conf file - ---- - src/lstack/core/lstack_cfg.c | 5 +++-- - 1 file changed, 3 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 9f3143f..7a4504f 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -946,6 +946,7 @@ static int32_t parse_conf_file(const char *path) - int32_t ret; - - if (realpath(path, real_path) == NULL) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "Config path error. Errno: %d. Please check conf file path: %s\n", errno, path); - return -1; - } - -@@ -953,7 +954,7 @@ static int32_t parse_conf_file(const char *path) - - ret = config_read_file(&g_config, real_path); - if (ret == 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "Config file path error, Please check conf file path.\n"); -+ LSTACK_PRE_LOG(LSTACK_ERR, "Read config file \"%s\" error: %s\n", real_path, config_error_text(&g_config)); - config_destroy(&g_config); - return -EINVAL; - } -@@ -961,7 +962,7 @@ static int32_t parse_conf_file(const char *path) - for (int32_t i = 0; g_config_tbl[i].name && g_config_tbl[i].f; ++i) { - ret = g_config_tbl[i].f(); - if (ret != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "error parsing parameter '%s' ret=%d\n.", g_config_tbl[i].name, ret); -+ LSTACK_PRE_LOG(LSTACK_ERR, "error parsing parameter '%s' ret=%d.\n", g_config_tbl[i].name, ret); - config_destroy(&g_config); - return ret; - } --- -2.27.0 - diff --git a/0055-add-gazelle-log.patch b/0055-add-gazelle-log.patch deleted file mode 100644 index bd4827c924d2c39047eac40e5383512244e073a0..0000000000000000000000000000000000000000 --- a/0055-add-gazelle-log.patch +++ /dev/null @@ -1,100 +0,0 @@ -From c136185db539fe2a7de58a4677b293f0c24f0e2a Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Mon, 20 Nov 2023 09:56:50 +0800 -Subject: [PATCH] add gazelle log - ---- - src/lstack/api/lstack_epoll.c | 3 +++ - src/lstack/core/lstack_protocol_stack.c | 12 +++++++++--- - 2 files changed, 12 insertions(+), 3 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index f2c4a8b..eacbe33 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -821,6 +821,7 @@ int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - 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); - } - -@@ -938,10 +939,12 @@ static nfds_t fds_select2poll(int maxfd, fd_set *readfds, fd_set *writefds, fd_s - int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeval) - { - if (maxfd == 0) { -+ LSTACK_LOG(ERR, LSTACK, "select maxfd is zero\n"); - return 0; - } - - if (maxfd < 0 || maxfd > FD_SETSIZE || (readfds == NULL && writefds == NULL && exceptfds == NULL)) { -+ LSTACK_LOG(ERR, LSTACK, "select input param error, fd num=%d\n", maxfd); - GAZELLE_RETURN(EINVAL); - } - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 74a17d4..aedf9c5 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -325,6 +325,7 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) - - stack->epollfd = posix_api->epoll_create_fn(GAZELLE_LSTACK_MAX_CONN); - if (stack->epollfd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "kernel epoll_create failed\n"); - return -1; - } - -@@ -349,10 +350,12 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) - } - - if (pktmbuf_pool_init(stack, stack_group->stack_num) != 0) { -+ LSTACK_LOG(ERR, LSTACK, "pktmbuf_pool_init failed\n"); - return -1; - } - - if (create_shared_ring(stack) != 0) { -+ LSTACK_LOG(ERR, LSTACK, "create_shared_ring failed\n"); - return -1; - } - -@@ -583,6 +586,7 @@ int32_t stack_group_init(void) - - if (get_global_cfg_params()->is_primary) { - if (stack_group_init_mempool() != 0) { -+ LSTACK_LOG(ERR, LSTACK, "stack group init mempool failed\n"); - return -1; - } - } -@@ -789,7 +793,8 @@ void stack_getsockopt(struct rpc_msg *msg) - msg->result = lwip_getsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, - msg->args[MSG_ARG_3].p, msg->args[MSG_ARG_4].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); -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d, level %d, optname %d, fail %ld\n", get_stack_tid(), -+ msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); - } - } - -@@ -798,7 +803,8 @@ void stack_setsockopt(struct rpc_msg *msg) - msg->result = lwip_setsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, - msg->args[MSG_ARG_3].cp, msg->args[MSG_ARG_4].socklen); - 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); -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d, level %d, optname %d, fail %ld\n", get_stack_tid(), -+ msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); - } - } - -@@ -834,7 +840,7 @@ void stack_send(struct rpc_msg *msg) - struct lwip_sock *sock = get_socket(fd); - if (sock == NULL) { - msg->result = -1; -- LSTACK_LOG(ERR, LSTACK, "stack_send: sock error!\n"); -+ LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); - rpc_msg_free(msg); - return; - } --- -2.27.0 - diff --git a/0056-wrap-fix-connect-wrong-port-after-addr-bind-two-port.patch b/0056-wrap-fix-connect-wrong-port-after-addr-bind-two-port.patch deleted file mode 100644 index 5e42a15fafa61684b0bd36277e062e28b0c97f89..0000000000000000000000000000000000000000 --- a/0056-wrap-fix-connect-wrong-port-after-addr-bind-two-port.patch +++ /dev/null @@ -1,38 +0,0 @@ -From c7a9c71456844b164477f329f79f5e10de7898a4 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Wed, 15 Nov 2023 11:23:04 +0800 -Subject: [PATCH] wrap: fix connect wrong port after addr bind two ports - ---- - src/lstack/api/lstack_wrap.c | 15 ++++++++++++++- - 1 file changed, 14 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 5bad513..f427d33 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -219,7 +219,20 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - - if (match_host_addr(((struct sockaddr_in *)name)->sin_addr.s_addr)) { - /* maybe kni addr */ -- posix_api->bind_fn(s, name, namelen); -+ if (posix_api->bind_fn(s, name, namelen) != 0) { -+ SET_CONN_TYPE_LIBOS(sock->conn); -+ } else { -+ /* reuse the port allocated by kernel when port == 0 */ -+ if (((struct sockaddr_in *)name)->sin_port == 0) { -+ struct sockaddr_in kerneladdr; -+ socklen_t len = sizeof(kerneladdr); -+ if (posix_api->getsockname_fn(s, (struct sockaddr *)&kerneladdr, &len) < 0) { -+ LSTACK_LOG(ERR, LSTACK, "kernel getsockname failed, fd=%d, errno=%d\n", s, errno); -+ return -1; -+ } -+ ((struct sockaddr_in *)name)->sin_port = kerneladdr.sin_port; -+ } -+ } - return g_wrap_api->bind_fn(s, name, namelen); - } else { - SET_CONN_TYPE_HOST(sock->conn); --- -2.27.0 - diff --git a/0057-cfg-rm-ipv6_enable.patch b/0057-cfg-rm-ipv6_enable.patch deleted file mode 100644 index 799a8c45e43b74b8eb60a701843ca063fc1c1225..0000000000000000000000000000000000000000 --- a/0057-cfg-rm-ipv6_enable.patch +++ /dev/null @@ -1,88 +0,0 @@ -From d0c8c259add3b170e413d4c3a9e248ba3e550680 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Thu, 23 Nov 2023 11:19:01 +0800 -Subject: [PATCH] cfg: rm ipv6_enable - ---- - src/lstack/api/lstack_wrap.c | 2 +- - src/lstack/core/lstack_cfg.c | 8 -------- - src/lstack/include/lstack_cfg.h | 1 - - src/lstack/netif/lstack_ethdev.c | 4 ++-- - 4 files changed, 3 insertions(+), 12 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 43b9dad..abbf8a1 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -384,7 +384,7 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - } - - if ((domain != AF_INET && domain != AF_UNSPEC && domain != AF_INET6) || -- ((domain == AF_INET6) && !get_global_cfg_params()->ipv6_enable) || -+ ((domain == AF_INET6) && ip6_addr_isany(&get_global_cfg_params()->host_addr6)) || - ((type & SOCK_DGRAM) && !get_global_cfg_params()->udp_enable)) { - return posix_api->socket_fn(domain, type, protocol); - } -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 7a4504f..d1cbd1d 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -76,7 +76,6 @@ static int32_t parse_bond_mode(void); - static int32_t parse_bond_slave_mac(void); - static int32_t parse_use_sockmap(void); - static int32_t parse_udp_enable(void); --static int32_t parse_ipv6_enable(void); - static int32_t parse_nic_rxqueue_size(void); - static int32_t parse_nic_txqueue_size(void); - static int32_t parse_stack_thread_mode(void); -@@ -139,7 +138,6 @@ 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 }, -- { "ipv6_enable", parse_ipv6_enable }, - { "nic_rxqueue_size", parse_nic_rxqueue_size}, - { "nic_txqueue_size", parse_nic_txqueue_size}, - { "stack_thread_mode", parse_stack_thread_mode }, -@@ -1271,9 +1269,3 @@ static int32_t parse_nic_vlan_mode(void) - return ret; - } - --static int32_t parse_ipv6_enable(void) --{ -- int32_t ret; -- PARSE_ARG(g_config_params.ipv6_enable, "ipv6_enable", 0, 0, 1, ret); -- return ret; --} -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index e3edc57..26da357 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -117,7 +117,6 @@ struct cfg_params { - struct rte_ether_addr bond_slave_mac_addr[GAZELLE_MAX_BOND_NUM]; - bool use_sockmap; - bool udp_enable; -- bool ipv6_enable; - struct cfg_nic_params nic; - bool stack_mode_rtc; - }; -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 02aa611..9912858 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -961,11 +961,11 @@ int32_t ethdev_init(struct protocol_stack *stack) - } - if (netif == NULL) { - LSTACK_LOG(ERR, LSTACK, "netif_add failed\n"); -- return ERR_IF; -+ return ERR_IF; - } - if (!ip6_addr_isany(&cfg->host_addr6)) { - netif_ip6_addr_set(&stack->netif, 0, &cfg->host_addr6); -- netif_ip6_addr_set_state(&stack->netif, 0, IP6_ADDR_VALID); -+ netif_ip6_addr_set_state(&stack->netif, 0, IP6_ADDR_VALID); - } - - netif_set_link_up(&stack->netif); --- -2.27.0 - diff --git a/0058-ltran-support-vlan.patch b/0058-ltran-support-vlan.patch deleted file mode 100644 index f3d93706ea0b8060de16c55dc0b36d0d121379a9..0000000000000000000000000000000000000000 --- a/0058-ltran-support-vlan.patch +++ /dev/null @@ -1,102 +0,0 @@ -From 0b7daa128d4b6dc231814537594158f8d928ef6c Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Thu, 23 Nov 2023 16:20:50 +0800 -Subject: [PATCH] ltran support vlan - ---- - src/ltran/ltran_forward.c | 35 ++++++++++++++++++++++++++++------- - 1 file changed, 28 insertions(+), 7 deletions(-) - -diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c -index b41e1e2..a6f2d71 100644 ---- a/src/ltran/ltran_forward.c -+++ b/src/ltran/ltran_forward.c -@@ -281,14 +281,26 @@ static __rte_always_inline int32_t tcp_handle(struct rte_mbuf *m, const struct r - return GAZELLE_OK; - } - -+static uint32_t get_vlan_offset(const struct rte_mbuf *m) -+{ -+ uint32_t offset = 0; -+ struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); -+ u16_t type = ethh->ether_type; -+ if (type == PP_HTONS(RTE_ETHER_TYPE_VLAN)) { -+ offset += sizeof(struct rte_vlan_hdr); -+ } -+ return offset; -+} -+ - static struct gazelle_stack* get_icmp_handle_stack(const struct rte_mbuf *m) - { - int32_t i; - struct gazelle_stack** stack_array = NULL; - struct rte_ipv4_hdr *ipv4_hdr = NULL; - struct gazelle_instance *instance = NULL; -+ uint32_t offset = get_vlan_offset(m); - -- ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr)); -+ ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr) + offset); - instance = gazelle_instance_get_by_ip(get_instance_mgr(), ipv4_hdr->dst_addr); - if (instance == NULL) { - return NULL; -@@ -321,10 +333,11 @@ static __rte_always_inline int32_t ipv4_handle(struct rte_mbuf *m, struct rte_ip - { - struct rte_tcp_hdr *tcp_hdr = NULL; - int32_t ret = -1; -+ uint32_t offset = get_vlan_offset(m); - - if (likely(ipv4_hdr->next_proto_id == IPPROTO_TCP)) { - tcp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_tcp_hdr *, sizeof(struct rte_ether_hdr) + -- sizeof(struct rte_ipv4_hdr)); -+ sizeof(struct rte_ipv4_hdr) + offset); - get_statistics()->port_stats[g_port_index].tcp_pkt++; - ret = tcp_handle(m, ipv4_hdr, tcp_hdr); - } else if (ipv4_hdr->next_proto_id == IPPROTO_ICMP) { -@@ -336,7 +349,8 @@ static __rte_always_inline int32_t ipv4_handle(struct rte_mbuf *m, struct rte_ip - - static __rte_always_inline void arp_handle(struct rte_mbuf *m) - { -- struct rte_arp_hdr *arph = rte_pktmbuf_mtod_offset(m, struct rte_arp_hdr *, sizeof(struct rte_ether_hdr)); -+ uint32_t offset = get_vlan_offset(m); -+ struct rte_arp_hdr *arph = rte_pktmbuf_mtod_offset(m, struct rte_arp_hdr *, sizeof(struct rte_ether_hdr) + offset); - - get_statistics()->port_stats[g_port_index].arp_pkt++; - -@@ -367,14 +381,14 @@ static __rte_always_inline void arp_handle(struct rte_mbuf *m) - static __rte_always_inline void upstream_forward_one(struct rte_mbuf *m) - { - struct rte_ipv4_hdr *iph = NULL; -- struct rte_ether_hdr *ethh = NULL; - uint8_t ip_version; - const int32_t ipv4_version_offset = 4; - const int32_t ipv4_version = 4; -+ uint32_t offset = get_vlan_offset(m); - - get_statistics()->port_stats[g_port_index].rx_bytes += m->data_len; - -- iph = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr)); -+ iph = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr) + offset); - ip_version = (iph->version_ihl & 0xf0) >> ipv4_version_offset; - if (likely(ip_version == ipv4_version)) { - int32_t ret = ipv4_handle(m, iph); -@@ -385,8 +399,15 @@ static __rte_always_inline void upstream_forward_one(struct rte_mbuf *m) - goto forward_to_kni; - } - -- ethh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); -- if (unlikely(RTE_BE16(RTE_ETHER_TYPE_ARP) == ethh->ether_type)) { -+ uint16_t type = 0; -+ if (offset > 0) { -+ struct rte_vlan_hdr *vlan_hdr = rte_pktmbuf_mtod_offset(m, struct rte_vlan_hdr *, sizeof(struct rte_ether_hdr)); -+ type = vlan_hdr->eth_proto; -+ } else { -+ struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); -+ type = ethh->ether_type; -+ } -+ if (unlikely(RTE_BE16(RTE_ETHER_TYPE_ARP) == type)) { - arp_handle(m); - // arp packets are sent to kni by default - goto forward_to_kni; --- -2.27.0 - diff --git a/0059-update-src-ltran-ltran_param.c.patch b/0059-update-src-ltran-ltran_param.c.patch deleted file mode 100644 index 1498d4f2c39124970a79fa21d95e205ee321628f..0000000000000000000000000000000000000000 --- a/0059-update-src-ltran-ltran_param.c.patch +++ /dev/null @@ -1,33 +0,0 @@ -From a82c372c3dc55167b2a83a2f3b5632bd0771d306 Mon Sep 17 00:00:00 2001 -From: gaojiazhen -Date: Thu, 23 Nov 2023 17:43:11 +0000 -Subject: [PATCH] =?UTF-8?q?update=20src/ltran/ltran=5Fparam.c.=20=E8=A7=84?= - =?UTF-8?q?=E8=8C=83679=E8=A1=8C=E7=9A=84=E6=8A=A5=E9=94=99=E6=97=A5?= - =?UTF-8?q?=E5=BF=97=E4=BF=A1=E6=81=AF=EF=BC=8C=E5=B0=86=E2=80=9C,?= - =?UTF-8?q?=E2=80=9D=E4=B9=8B=E5=90=8E=E7=9A=84=E2=80=9CPlease=E2=80=9D?= - =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=BA=E2=80=9Cplease=E2=80=9D?= -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Signed-off-by: gaojiazhen ---- - src/ltran/ltran_param.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/ltran/ltran_param.c b/src/ltran/ltran_param.c -index e16e648..11a4bc8 100644 ---- a/src/ltran/ltran_param.c -+++ b/src/ltran/ltran_param.c -@@ -676,7 +676,7 @@ int32_t parse_config_file_args(const char *conf_file_path, struct ltran_config * - ret = config_read_file(&config, conf_file_path); - if (ret == 0) { - config_destroy(&config); -- syslog(LOG_ERR, "Err: Config file path %s error, Please check conf file path.\n", conf_file_path); -+ syslog(LOG_ERR, "Err: Config file path %s error, please check conf file path.\n", conf_file_path); - return -GAZELLE_EPATH; - } - --- -2.27.0 - diff --git a/0060-dfx-support-bond-get-dpdk-xstats.patch b/0060-dfx-support-bond-get-dpdk-xstats.patch deleted file mode 100644 index 2f5b1e4e09802ee55bfc4d2286196754f23949f4..0000000000000000000000000000000000000000 --- a/0060-dfx-support-bond-get-dpdk-xstats.patch +++ /dev/null @@ -1,262 +0,0 @@ -From 75e11463d7bd67732d3c7f0e7ed3a9dece8c4982 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sat, 25 Nov 2023 09:26:23 +0800 -Subject: [PATCH] dfx: support bond get dpdk xstats - ---- - src/lstack/core/lstack_control_plane.c | 2 + - src/lstack/core/lstack_dpdk.c | 93 +++++++++++++++++++------ - src/lstack/core/lstack_protocol_stack.c | 2 +- - src/lstack/core/lstack_stack_stat.c | 14 ++-- - src/lstack/include/lstack_cfg.h | 1 - - src/lstack/include/lstack_dpdk.h | 1 - - src/lstack/include/lstack_stack_stat.h | 3 +- - src/lstack/netif/lstack_ethdev.c | 4 +- - 8 files changed, 89 insertions(+), 31 deletions(-) - -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index b97ee7f..4633834 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -586,6 +586,8 @@ static int32_t handle_stat_request(int32_t sockfd) - if (msg.stat_mode == GAZELLE_STAT_LSTACK_LOG_LEVEL_SET || - msg.stat_mode == GAZELLE_STAT_LSTACK_LOW_POWER_MDF) { - return handle_proc_cmd(sockfd, &msg); -+ } else if (msg.stat_mode == GAZELLE_STAT_LSTACK_SHOW_XSTATS) { -+ return handle_dpdk_cmd(sockfd, msg.stat_mode); - } else { - ret = handle_stack_cmd(sockfd, msg.stat_mode); - if (ret != 0) { -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 703fd0d..19a7bf4 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -346,13 +346,6 @@ void lstack_log_level_init(void) - } - } - --// get port id --inline uint16_t get_port_id(void) --{ -- uint16_t port_id = get_global_cfg_params()->port_id; -- return port_id; --} -- - static int32_t ethdev_port_id(uint8_t *mac) - { - int32_t port_id; -@@ -497,8 +490,6 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - } - } - -- get_global_cfg_params()->port_id = port_id; -- - struct rte_eth_dev_info dev_info; - int32_t ret = rte_eth_dev_info_get(port_id, &dev_info); - if (ret != 0) { -@@ -814,23 +805,83 @@ bool port_in_stack_queue(ip_addr_t src_ip, ip_addr_t dst_ip, uint16_t src_port, - return (reta_index % stack_group->nb_queues) == stack->queue_id; - } - --void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id) -+static int dpdk_nic_xstats_value_get(uint64_t *values, unsigned int len, uint16_t *ports, unsigned int count) - { -- int32_t ret; -- int32_t len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL); -- dfx->data.nic_xstats.len = len; -- dfx->data.nic_xstats.port_id = port_id; -+ uint64_t tmp_values[RTE_ETH_XSTATS_MAX_LEN]; -+ int p_idx; -+ int v_idx; -+ int ret; -+ -+ for (p_idx = 0; p_idx < count; p_idx++) { -+ ret = rte_eth_xstats_get_by_id(ports[p_idx], NULL, tmp_values, len); -+ if (ret < 0 || ret > len) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_xstats_get_by_id failed.\n"); -+ return -1; -+ } -+ -+ for (v_idx = 0; v_idx < len; v_idx++) { -+ values[v_idx] += tmp_values[v_idx]; -+ } -+ } -+ return 0; -+} -+ -+static int dpdk_nic_xstats_name_get(struct nic_eth_xstats_name *names, uint16_t port_id) -+{ -+ int len; -+ -+ len = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL); - if (len < 0) { -- return; -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_xstats_get_names_by_id failed.\n"); -+ return -1; -+ } -+ -+ if (len != rte_eth_xstats_get_names_by_id(port_id, (struct rte_eth_xstat_name *)names, len, NULL)) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_xstats_get_names_by_id failed.\n"); -+ return -1; - } -- if (len != rte_eth_xstats_get_names_by_id(port_id, -- (struct rte_eth_xstat_name *)dfx->data.nic_xstats.xstats_name, len, NULL)) { -- dfx->data.nic_xstats.len = -1; -+ -+ return len; -+} -+ -+void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id) -+{ -+ struct rte_eth_dev_info dev_info; -+ int len; -+ int ret; -+ -+ dfx->data.nic_xstats.len = -1; -+ dfx->data.nic_xstats.port_id = port_id; -+ ret = rte_eth_dev_info_get(port_id, &dev_info); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_dev_info_get failed.\n"); - return; - } - -- ret = rte_eth_xstats_get_by_id(port_id, NULL, dfx->data.nic_xstats.values, len); -- if (ret < 0 || ret > len) { -- dfx->data.nic_xstats.len = -1; -+ /* bond not support get xstats, we get xstats from slave device of bond */ -+ if (strcmp(dev_info.driver_name, "net_bonding") == 0) { -+ uint16_t slaves[RTE_MAX_ETHPORTS]; -+ int slave_count; -+ slave_count = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS); -+ if (slave_count <= 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_bond_slaves_get failed.\n"); -+ return; -+ } -+ len = dpdk_nic_xstats_name_get(dfx->data.nic_xstats.xstats_name, slaves[0]); -+ if (len <= 0) { -+ return; -+ } -+ if (dpdk_nic_xstats_value_get(dfx->data.nic_xstats.values, len, slaves, slave_count) != 0) { -+ return; -+ } -+ } else { -+ len = dpdk_nic_xstats_name_get(dfx->data.nic_xstats.xstats_name, port_id); -+ if (len <= 0) { -+ return; -+ } -+ if (dpdk_nic_xstats_value_get(dfx->data.nic_xstats.values, len, &port_id, 1) != 0) { -+ return; -+ } - } -+ dfx->data.nic_xstats.len = len; - } -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index cbc8b8f..dfebfcc 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -479,7 +479,7 @@ void stack_polling(uint32_t wakeup_tick) - if (kni_switch && !stack->queue_id && !(wakeup_tick & 0xfff)) { - rte_kni_handle_request(get_gazelle_kni()); - if (get_kni_started()) { -- kni_handle_rx(get_port_id()); -+ kni_handle_rx(stack->port_id); - } - } - return; -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 60832b4..18548ab 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -256,19 +256,25 @@ static int32_t send_control_cmd_data(int32_t fd, struct gazelle_stack_dfx_data * - return 0; - } - --int32_t handle_stack_cmd(int32_t fd, enum GAZELLE_STAT_MODE stat_mode) -+int handle_dpdk_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode) - { - struct gazelle_stack_dfx_data dfx; -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); - - if (stat_mode == GAZELLE_STAT_LSTACK_SHOW_XSTATS) { -- dpdk_nic_xstats_get(&dfx, get_port_id()); -+ dpdk_nic_xstats_get(&dfx, get_protocol_stack_group()->port_id); - dfx.tid = 0; - dfx.eof = 1; - send_control_cmd_data(fd, &dfx); -- return 0; - } - -+ return 0; -+} -+ -+int handle_stack_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode) -+{ -+ struct gazelle_stack_dfx_data dfx; -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ - for (uint32_t i = 0; i < stack_group->stack_num; i++) { - struct protocol_stack *stack = stack_group->stacks[i]; - -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 26da357..e33f4fe 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -94,7 +94,6 @@ struct cfg_params { - - uint16_t num_process; - uint16_t num_listen_port; -- uint16_t port_id; - uint16_t is_primary; - uint16_t num_queue; - uint16_t tot_queue_num; -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index 3a621d0..e3daefa 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -55,7 +55,6 @@ void dpdk_skip_nic_init(void); - int32_t dpdk_init_lstack_kni(void); - void dpdk_restore_pci(void); - bool port_in_stack_queue(ip_addr_t src_ip, ip_addr_t dst_ip, uint16_t src_port, uint16_t dst_port); --uint16_t get_port_id(void); - struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, - uint32_t mbuf_cache_size, uint16_t queue_id, unsigned numa_id); - -diff --git a/src/lstack/include/lstack_stack_stat.h b/src/lstack/include/lstack_stack_stat.h -index 5737bae..d5a4ec7 100644 ---- a/src/lstack/include/lstack_stack_stat.h -+++ b/src/lstack/include/lstack_stack_stat.h -@@ -24,7 +24,8 @@ enum GAZELLE_STAT_MODE; - void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, - enum GAZELLE_LATENCY_TYPE type); - void stack_stat_init(void); --int32_t handle_stack_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode); -+int handle_stack_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode); -+int handle_dpdk_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode); - uint64_t get_current_time(void); - void lstack_get_low_power_info(struct gazelle_stat_low_power_info *low_power_info); - void unregister_wakeup(struct protocol_stack *stack, struct wakeup_poll *wakeup); -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 9912858..29bef21 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -330,7 +330,7 @@ struct rte_flow *create_flow_director(uint16_t port_id, uint16_t queue_id, - void config_flow_director(uint16_t queue_id, uint32_t src_ip, - uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) - { -- uint16_t port_id = get_port_id(); -+ uint16_t port_id = get_protocol_stack_group()->port_id; - char rule_key[RULE_KEY_LEN] = {0}; - sprintf_s(rule_key, sizeof(rule_key), "%u_%u_%u", src_ip, src_port, dst_port); - struct flow_rule *fl_exist = find_rule(rule_key); -@@ -357,7 +357,7 @@ void config_flow_director(uint16_t queue_id, uint32_t src_ip, - - void delete_flow_director(uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) - { -- uint16_t port_id = get_port_id(); -+ uint16_t port_id = get_protocol_stack_group()->port_id; - char rule_key[RULE_KEY_LEN] = {0}; - sprintf_s(rule_key, RULE_KEY_LEN, "%u_%u_%u",dst_ip, dst_port, src_port); - struct flow_rule *fl = find_rule(rule_key); --- -2.27.0 - diff --git a/0061-add-tcp-faste-timer-cnt.patch b/0061-add-tcp-faste-timer-cnt.patch deleted file mode 100644 index 7052525176ae14145f1e18e0da477de3271db20f..0000000000000000000000000000000000000000 --- a/0061-add-tcp-faste-timer-cnt.patch +++ /dev/null @@ -1,73 +0,0 @@ -From 4098ba1fbc9f382d0f9d6b6b071d7ed9a2682cfc Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Fri, 24 Nov 2023 14:19:16 +0800 -Subject: [PATCH] add tcp faste timer cnt - ---- - src/common/gazelle_dfx_msg.h | 3 +++ - src/ltran/ltran_dfx.c | 28 ++++++++++++++++++---------- - 2 files changed, 21 insertions(+), 10 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 93fe3df..8071108 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -117,6 +117,9 @@ struct gazelle_stat_lstack_snmp { - uint32_t tcp_in_seg; - uint32_t tcp_in_err; - uint32_t tcp_out_rst; -+ uint32_t tcp_fin_ack_cnt; -+ uint32_t tcp_delay_ack_cnt; -+ uint32_t tcp_refused_cnt; - - /* UDP */ - uint32_t udp_in_datagrams; -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 582a4b7..98e23dc 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -825,6 +825,22 @@ static void gazelle_print_lstack_stat_rate(void *buf, const struct gazelle_stat_ - } while (true); - } - -+static void gazelle_print_lstack_tcp_stat(const struct gazelle_stat_lstack_snmp *snmp) -+{ -+ printf("tcp_act_open: %u\n", snmp->tcp_act_open); -+ printf("tcp_passive_open: %u\n", snmp->tcp_passive_open); -+ printf("tcp_attempt_fail: %u\n", snmp->tcp_attempt_fail); -+ printf("tcp_estab_rst: %u\n", snmp->tcp_estab_rst); -+ printf("tcp_out_seg: %u\n", snmp->tcp_out_seg); -+ printf("tcp_retran_seg: %u\n", snmp->tcp_retran_seg); -+ printf("tcp_in_seg: %u\n", snmp->tcp_in_seg); -+ printf("tcp_in_err: %u\n", snmp->tcp_in_err); -+ printf("tcp_out_rst: %u\n", snmp->tcp_out_rst); -+ printf("tcp_fin_ack_cnt: %u\n", snmp->tcp_fin_ack_cnt); -+ printf("tcp_delay_ack_cnt: %u\n", snmp->tcp_delay_ack_cnt); -+ printf("tcp_refused_cnt: %u\n", snmp->tcp_refused_cnt); -+} -+ - static void gazelle_print_lstack_stat_snmp_core(const struct gazelle_stack_dfx_data *stat, - const struct gazelle_stat_lstack_snmp *snmp) - { -@@ -850,16 +866,8 @@ static void gazelle_print_lstack_stat_snmp_core(const struct gazelle_stack_dfx_d - printf("udp_no_ports: %u\n", snmp->udp_no_ports); - printf("udp_in_errors: %u\n", snmp->udp_in_errors); - printf("udp_out_datagrams: %u\n", snmp->udp_out_datagrams); -- -- printf("tcp_act_open: %u\n", snmp->tcp_act_open); -- printf("tcp_passive_open: %u\n", snmp->tcp_passive_open); -- printf("tcp_attempt_fail: %u\n", snmp->tcp_attempt_fail); -- printf("tcp_estab_rst: %u\n", snmp->tcp_estab_rst); -- printf("tcp_out_seg: %u\n", snmp->tcp_out_seg); -- printf("tcp_retran_seg: %u\n", snmp->tcp_retran_seg); -- printf("tcp_in_seg: %u\n", snmp->tcp_in_seg); -- printf("tcp_in_err: %u\n", snmp->tcp_in_err); -- printf("tcp_out_rst: %u\n", snmp->tcp_out_rst); -+ -+ gazelle_print_lstack_tcp_stat(snmp); - - printf("icmp_in_msgs: %u\n", snmp->icmp_in_msgs); - printf("icmp_in_errors: %u\n", snmp->icmp_in_errors); --- -2.27.0 - diff --git a/0062-stack-fix-coredump-caused-by-gazelleclt-in-rtc-mode.patch b/0062-stack-fix-coredump-caused-by-gazelleclt-in-rtc-mode.patch deleted file mode 100644 index 4f5a6983ba643098909374693d529d99f9e0519a..0000000000000000000000000000000000000000 --- a/0062-stack-fix-coredump-caused-by-gazelleclt-in-rtc-mode.patch +++ /dev/null @@ -1,124 +0,0 @@ -From 94e60e452e11fcc785fe44a66358608b5e2d90a7 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 27 Nov 2023 21:41:13 +0800 -Subject: [PATCH] stack: fix coredump caused by gazelleclt in rtc mode when - stack num defined is greater than the hijacked thread num - ---- - src/lstack/core/lstack_dpdk.c | 7 +------ - src/lstack/core/lstack_protocol_stack.c | 20 ++++++++------------ - src/lstack/include/lstack_dpdk.h | 2 +- - 3 files changed, 10 insertions(+), 19 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 19a7bf4..839516e 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -205,13 +205,8 @@ static struct reg_ring_msg *create_reg_mempool(const char *name, uint16_t queue_ - return reg_buf; - } - --int32_t pktmbuf_pool_init(struct protocol_stack *stack, uint16_t stack_num) -+int32_t pktmbuf_pool_init(struct protocol_stack *stack) - { -- if (stack_num == 0) { -- LSTACK_LOG(ERR, LSTACK, "stack_num=0.\n"); -- return -1; -- } -- - stack->rxtx_pktmbuf_pool = get_pktmbuf_mempool("rxtx_mbuf", stack->queue_id); - if (stack->rxtx_pktmbuf_pool == NULL) { - LSTACK_LOG(ERR, LSTACK, "rxtx_pktmbuf_pool is NULL\n"); -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index dfebfcc..baacaa9 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -349,7 +349,7 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) - return -1; - } - -- if (pktmbuf_pool_init(stack, stack_group->stack_num) != 0) { -+ if (pktmbuf_pool_init(stack) != 0) { - LSTACK_LOG(ERR, LSTACK, "pktmbuf_pool_init failed\n"); - return -1; - } -@@ -529,7 +529,7 @@ static void gazelle_listen_thread(void *arg) - int32_t stack_group_init_mempool(void) - { - struct cfg_params *global_cfg_parmas = get_global_cfg_params(); -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ uint32_t total_mbufs = get_global_cfg_params()->mbuf_count_per_conn * get_global_cfg_params()->tcp_conn_count; - struct rte_mempool *rxtx_mbuf = NULL; - uint32_t cpu_id = 0; - unsigned numa_id = 0; -@@ -537,10 +537,8 @@ int32_t stack_group_init_mempool(void) - - LSTACK_LOG(INFO, LSTACK, - "config::num_cpu=%d num_process=%d \n", global_cfg_parmas->num_cpu, global_cfg_parmas->num_process); -- -- uint32_t total_mbufs = get_global_cfg_params()->mbuf_count_per_conn * get_global_cfg_params()->tcp_conn_count; - -- for (int cpu_idx = 0; cpu_idx < global_cfg_parmas->num_cpu; cpu_idx++) { -+ for (int cpu_idx = 0; cpu_idx < get_global_cfg_params()->num_queue; cpu_idx++) { - cpu_id = global_cfg_parmas->cpus[cpu_idx]; - numa_id = numa_node_of_cpu(cpu_id); - -@@ -552,7 +550,7 @@ int32_t stack_group_init_mempool(void) - } - - rxtx_mbuf = create_pktmbuf_mempool( -- "rxtx_mbuf", total_mbufs / stack_group->stack_num, RXTX_CACHE_SZ, queue_id, numa_id); -+ "rxtx_mbuf", total_mbufs / get_global_cfg_params()->num_queue, 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); -@@ -569,11 +567,7 @@ int32_t stack_group_init_mempool(void) - int32_t stack_group_init(void) - { - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- if (!get_global_cfg_params()->seperate_send_recv) { -- stack_group->stack_num = get_global_cfg_params()->num_cpu; -- } else { -- stack_group->stack_num = get_global_cfg_params()->num_cpu * 2; -- } -+ stack_group->stack_num = 0; - - init_list_node(&stack_group->poll_list); - pthread_spin_init(&stack_group->poll_list_lock, PTHREAD_PROCESS_PRIVATE); -@@ -627,6 +621,7 @@ int32_t stack_setup_app_thread(void) - LSTACK_LOG(INFO, LSTACK, "stack setup failed in app thread\n"); - return -1; - } -+ atomic_fetch_add(&g_stack_group.stack_num, 1); - - return 0; - } -@@ -670,10 +665,11 @@ int32_t stack_setup_thread(void) - } - - /* 2: wait stack thread and kernel_event thread init finish */ -- wait_sem_value(&g_stack_group.sem_stack_setup, g_stack_group.stack_num * 2); -+ wait_sem_value(&g_stack_group.sem_stack_setup, queue_num * 2); - if (g_stack_group.stack_setup_fail) { - return -1; - } -+ g_stack_group.stack_num = queue_num; - - return 0; - } -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index e3daefa..6554a7e 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -43,7 +43,7 @@ struct rte_ring; - struct rte_mbuf; - int32_t fill_mbuf_to_ring(struct rte_mempool *mempool, struct rte_ring *ring, uint32_t mbuf_num); - int32_t dpdk_eal_init(void); --int32_t pktmbuf_pool_init(struct protocol_stack *stack, uint16_t stack_num); -+int32_t pktmbuf_pool_init(struct protocol_stack *stack); - struct rte_ring *create_ring(const char *name, uint32_t count, uint32_t flags, int32_t queue_id); - struct rte_mempool *create_mempool(const char *name, uint32_t count, uint32_t size, - uint32_t flags, int32_t idx); --- -2.27.0 - diff --git a/0063-dfx-add-tcp-exception-and-kernel-event-statistics.patch b/0063-dfx-add-tcp-exception-and-kernel-event-statistics.patch deleted file mode 100644 index c1a91198b3be7ab06f6af19bf1ea43d98cd167a8..0000000000000000000000000000000000000000 --- a/0063-dfx-add-tcp-exception-and-kernel-event-statistics.patch +++ /dev/null @@ -1,109 +0,0 @@ -From 66f2015f6710d86966b8abcf028f69a3165c10aa Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Tue, 28 Nov 2023 18:43:42 +0800 -Subject: [PATCH] dfx: add tcp exception and kernel event statistics - ---- - src/common/gazelle_dfx_msg.h | 4 ++++ - src/lstack/api/lstack_epoll.c | 9 +++++++-- - src/ltran/ltran_dfx.c | 7 ++++++- - 3 files changed, 17 insertions(+), 3 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 8071108..bfc4992 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -75,6 +75,7 @@ struct gazelle_wakeup_stat { - uint64_t app_write_cnt; - uint64_t app_read_cnt; - uint64_t read_null; -+ uint64_t kernel_events; - }; - - struct gazelle_stat_pkts { -@@ -120,6 +121,9 @@ struct gazelle_stat_lstack_snmp { - uint32_t tcp_fin_ack_cnt; - uint32_t tcp_delay_ack_cnt; - uint32_t tcp_refused_cnt; -+ uint32_t tcp_out_of_seq; -+ uint32_t tcp_acceptmbox_full; -+ uint32_t tcp_listen_drops; - - /* UDP */ - uint32_t udp_in_datagrams; -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 2cb459e..a2d2a9b 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -493,7 +493,6 @@ int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event * - } - } - -- wakeup->stat.app_events += event_num; - return event_num; - } - -@@ -611,6 +610,7 @@ int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t - - lwip_num = epoll_lwip_event_nolock(wakeup, &events[kernel_num], tmpmaxevents - kernel_num); - wakeup->stat.app_events += lwip_num; -+ wakeup->stat.kernel_events += kernel_num; - - return lwip_num + kernel_num; - } -@@ -634,7 +634,6 @@ int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t - do { - __atomic_store_n(&wakeup->in_wait, true, __ATOMIC_RELEASE); - lwip_num = epoll_lwip_event(wakeup, events, maxevents); -- wakeup->stat.app_events += lwip_num; - - if (__atomic_load_n(&wakeup->have_kernel_event, __ATOMIC_ACQUIRE)) { - kernel_num = posix_api->epoll_wait_fn(epfd, &events[lwip_num], maxevents - lwip_num, 0); -@@ -661,6 +660,9 @@ int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t - } while (ret == 0); - - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -+ wakeup->stat.app_events += lwip_num; -+ wakeup->stat.kernel_events += kernel_num; -+ - return lwip_num + kernel_num; - } - -@@ -870,6 +872,9 @@ int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - } while (ret == 0); - - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -+ wakeup->stat.app_events += lwip_num; -+ wakeup->stat.kernel_events += kernel_num; -+ - return lwip_num + kernel_num; - } - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 98e23dc..3bd120c 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -604,7 +604,9 @@ static void show_lstack_stats(struct gazelle_stack_dfx_data *lstack_stat) - printf("write_lwip: %-17"PRIu64" ", lstack_stat->data.pkts.stack_stat.write_lwip_cnt); - printf("app_write_rpc: %-14"PRIu64" \n", lstack_stat->data.pkts.wakeup_stat.app_write_rpc); - printf("recv_list: %-18"PRIu64" ", lstack_stat->data.pkts.recv_list_cnt); -- printf("conn_num: %-19hu \n", lstack_stat->data.pkts.conn_num); -+ printf("conn_num: %-19hu ", lstack_stat->data.pkts.conn_num); -+ -+ printf("kernel_events: %-14"PRIu64"\n", lstack_stat->data.pkts.wakeup_stat.kernel_events); - printf("wakeup_events: %-14"PRIu64" ", lstack_stat->data.pkts.stack_stat.wakeup_events); - printf("app_events: %-17"PRIu64" ", lstack_stat->data.pkts.wakeup_stat.app_events); - printf("read_null: %-18"PRIu64" \n", lstack_stat->data.pkts.wakeup_stat.read_null); -@@ -839,6 +841,9 @@ static void gazelle_print_lstack_tcp_stat(const struct gazelle_stat_lstack_snmp - printf("tcp_fin_ack_cnt: %u\n", snmp->tcp_fin_ack_cnt); - printf("tcp_delay_ack_cnt: %u\n", snmp->tcp_delay_ack_cnt); - printf("tcp_refused_cnt: %u\n", snmp->tcp_refused_cnt); -+ printf("tcp_out_of_seq: %u\n", snmp->tcp_out_of_seq); -+ printf("tcp_acceptmbox_full: %u\n", snmp->tcp_acceptmbox_full); -+ printf("tcp_listen_drops: %u\n", snmp->tcp_listen_drops); - } - - static void gazelle_print_lstack_stat_snmp_core(const struct gazelle_stack_dfx_data *stat, --- -2.27.0 - diff --git a/0064-add-vlan_id-in-netif.patch b/0064-add-vlan_id-in-netif.patch deleted file mode 100644 index c35d11e8224b56dab33af365fd299129e472c6d8..0000000000000000000000000000000000000000 --- a/0064-add-vlan_id-in-netif.patch +++ /dev/null @@ -1,88 +0,0 @@ -From fcdf8a09859cc0ba148a5c0a410997931fb4fa20 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Wed, 22 Nov 2023 16:08:22 +0800 -Subject: [PATCH] add vlan_id in netif - ---- - src/lstack/core/lstack_cfg.c | 4 ++-- - src/lstack/core/lstack_lwip.c | 3 --- - src/lstack/include/lstack_cfg.h | 2 +- - src/lstack/netif/lstack_ethdev.c | 5 +++++ - src/lstack/netif/lstack_vdev.c | 2 +- - 5 files changed, 9 insertions(+), 7 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index d1cbd1d..6324c97 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -1261,9 +1261,9 @@ static int32_t parse_stack_thread_mode(void) - static int32_t parse_nic_vlan_mode(void) - { - int32_t ret; -- PARSE_ARG(g_config_params.nic.vlan_mode, "nic_vlan_mode", 0, 0, 4094, ret); -+ PARSE_ARG(g_config_params.nic.vlan_mode, "nic_vlan_mode", -1, -1, 4094, ret); - if (ret != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid vlan mode value %d ret=%d. only support 0~4094\n", \ -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid vlan mode value %d ret=%d. only support -1~4094\n", \ - g_config_params.nic.vlan_mode, ret); - } - return ret; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index c8b4e8f..af9bf73 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -196,9 +196,6 @@ void do_lwip_init_sock(int32_t fd) - (void)replenish_send_idlembuf(stack, sock); - - sock->stack = stack; -- if (get_global_cfg_params()->nic.vlan_mode > 0 && get_global_cfg_params()->nic.vlan_mode < 4095) { -- sock->conn->pcb.udp->netif_hints.tci = get_global_cfg_params()->nic.vlan_mode; -- } - - init_list_node_null(&sock->recv_list); - init_list_node_null(&sock->event_list); -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index e33f4fe..a6bdfd5 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -63,7 +63,7 @@ struct secondary_attach_arg { - struct cfg_nic_params { - uint32_t rxqueue_size; - uint32_t txqueue_size; -- uint16_t vlan_mode; -+ int32_t vlan_mode; - }; - - struct cfg_params { -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 29bef21..cce2fcf 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -967,6 +967,11 @@ int32_t ethdev_init(struct protocol_stack *stack) - netif_ip6_addr_set(&stack->netif, 0, &cfg->host_addr6); - netif_ip6_addr_set_state(&stack->netif, 0, IP6_ADDR_VALID); - } -+ -+ /* 0-4094: The vlaue range for VLAN IDs is 0 to 4094. */ -+ if (get_global_cfg_params()->nic.vlan_mode >= 0 && get_global_cfg_params()->nic.vlan_mode <= 4094) { -+ netif_set_vlan_tci(&stack->netif, (u16_t)get_global_cfg_params()->nic.vlan_mode); -+ } - - netif_set_link_up(&stack->netif); - -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index d57ce59..18322a6 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -84,7 +84,7 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt - } - - /* skip gro when tcp/ip cksum offloads disable */ -- if (get_protocol_stack_group()->rx_offload == 0 || get_global_cfg_params()->nic.vlan_mode > 0) { -+ if (get_protocol_stack_group()->rx_offload == 0 || get_global_cfg_params()->nic.vlan_mode >= 0) { - return pkt_num; - } - --- -2.27.0 - diff --git a/0065-support-vlan-offload.patch b/0065-support-vlan-offload.patch deleted file mode 100644 index 2d5beb1247e32a85ec8acdd9478b12cdf493c380..0000000000000000000000000000000000000000 --- a/0065-support-vlan-offload.patch +++ /dev/null @@ -1,89 +0,0 @@ -From a449111fed8c0c4cd7b8021ff20b3ea12f334479 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Tue, 28 Nov 2023 14:14:15 +0800 -Subject: [PATCH] support vlan offload - ---- - src/common/dpdk_common.c | 12 ++++++++++++ - src/lstack/netif/lstack_ethdev.c | 13 +++++++------ - src/lstack/netif/lstack_vdev.c | 3 ++- - 3 files changed, 21 insertions(+), 7 deletions(-) - -diff --git a/src/common/dpdk_common.c b/src/common/dpdk_common.c -index 52a163f..50f0bf0 100644 ---- a/src/common/dpdk_common.c -+++ b/src/common/dpdk_common.c -@@ -104,6 +104,12 @@ void eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev - COMMON_INFO("DEV_RX_OFFLOAD_UDP_CKSUM\n"); - } - -+ // rx vlan -+ if (rx_ol_capa & DEV_RX_OFFLOAD_VLAN_STRIP) { -+ rx_ol |= DEV_RX_OFFLOAD_VLAN_STRIP; -+ COMMON_INFO("DEV_RX_OFFLOAD_VLAN_STRIP\n"); -+ } -+ - // tx ip - if (tx_ol_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) { - tx_ol |= DEV_TX_OFFLOAD_IPV4_CKSUM; -@@ -128,6 +134,12 @@ void eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev - COMMON_INFO("DEV_TX_OFFLOAD_TCP_TSO\n"); - } - -+ // tx vlan -+ if (tx_ol_capa & DEV_TX_OFFLOAD_VLAN_INSERT) { -+ tx_ol |= DEV_TX_OFFLOAD_VLAN_INSERT; -+ COMMON_INFO("DEV_TX_OFFLOAD_VLAN_INSERT\n"); -+ } -+ - if (!(rx_ol & DEV_RX_OFFLOAD_UDP_CKSUM) || - !(rx_ol & DEV_RX_OFFLOAD_TCP_CKSUM) || - !(rx_ol & DEV_RX_OFFLOAD_IPV4_CKSUM)) { -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index cce2fcf..31856f2 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -815,12 +815,12 @@ int32_t gazelle_eth_dev_poll(struct protocol_stack *stack, uint8_t use_ltran_fla - /* copy arp into other stack */ - if (!use_ltran_flag) { - struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(stack->pkts[i], struct rte_ether_hdr *); -- u16_t type; -- type = ethh->ether_type; -- if (type == PP_HTONS(ETHTYPE_VLAN)) { -- struct eth_vlan_hdr *vlan = (struct eth_vlan_hdr *)(((char *)ethh) + SIZEOF_ETH_HDR); -- type = vlan->tpid; -- } -+ u16_t type; -+ type = ethh->ether_type; -+ if (type == PP_HTONS(ETHTYPE_VLAN)) { -+ struct eth_vlan_hdr *vlan = (struct eth_vlan_hdr *)(((char *)ethh) + SIZEOF_ETH_HDR); -+ type = vlan->tpid; -+ } - if (unlikely(RTE_BE16(RTE_ETHER_TYPE_ARP) == type)) { - stack_broadcast_arp(stack->pkts[i], stack); - /* copy arp into other process */ -@@ -860,6 +860,7 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - mbuf->data_len = pbuf->len; - mbuf->pkt_len = pbuf->tot_len; - mbuf->ol_flags = pbuf->ol_flags; -+ mbuf->vlan_tci = pbuf->vlan_tci; - mbuf->next = NULL; - buf_addr = rte_pktmbuf_mtod(mbuf, void *); - -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 18322a6..e1438da 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -84,7 +84,8 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt - } - - /* skip gro when tcp/ip cksum offloads disable */ -- if (get_protocol_stack_group()->rx_offload == 0 || get_global_cfg_params()->nic.vlan_mode >= 0) { -+ if (get_protocol_stack_group()->rx_offload == 0 || (get_global_cfg_params()->nic.vlan_mode >= 0 -+ && !(get_protocol_stack_group()->rx_offload & DEV_RX_OFFLOAD_VLAN_STRIP))) { - return pkt_num; - } - --- -2.27.0 - diff --git a/0066-gazellectl-fix-gazellectl-lstack-show-1-r-error.patch b/0066-gazellectl-fix-gazellectl-lstack-show-1-r-error.patch deleted file mode 100644 index 9d7711d6391a3187752db8b72c6eab0c8a08d23e..0000000000000000000000000000000000000000 --- a/0066-gazellectl-fix-gazellectl-lstack-show-1-r-error.patch +++ /dev/null @@ -1,487 +0,0 @@ -From 1a43d75144d7fc4f052758aceadf47535ef3262e Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Mon, 20 Nov 2023 21:15:51 +0800 -Subject: [PATCH] gazellectl: fix gazellectl lstack show 1 -r error - ---- - src/common/gazelle_dfx_msg.h | 28 +++-- - src/lstack/core/lstack_stack_stat.c | 15 +-- - src/ltran/ltran_dfx.c | 188 ++++++++++++++++------------ - src/ltran/ltran_monitor.c | 5 +- - 4 files changed, 131 insertions(+), 105 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index bfc4992..ac6ea5e 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -25,6 +25,7 @@ - enum GAZELLE_STAT_MODE { - GAZELLE_STAT_LTRAN_SHOW = 0, - GAZELLE_STAT_LTRAN_SHOW_RATE, -+ GAZELLE_STAT_LTRAN_SHOW_LB_RATE, - GAZELLE_STAT_LTRAN_SHOW_INSTANCE, - GAZELLE_STAT_LTRAN_SHOW_BURST, - GAZELLE_STAT_LTRAN_SHOW_LATENCY, -@@ -78,6 +79,18 @@ struct gazelle_wakeup_stat { - uint64_t kernel_events; - }; - -+struct gazelle_stack_aggregate_stats { -+ /* 0: RX, 1: TX, 2: APP_TX */ -+ uint32_t size_1_64[3]; -+ uint32_t size_65_512[3]; -+ uint32_t size_513_1460[3]; -+ uint32_t size_1461_8192[3]; -+ uint32_t size_8193_max[3]; -+ -+ uint64_t rx_bytes; -+ uint64_t tx_bytes; -+}; -+ - struct gazelle_stat_pkts { - uint16_t conn_num; - uint32_t mempool_freecnt; -@@ -86,6 +99,7 @@ struct gazelle_stat_pkts { - uint64_t call_alloc_fail; - struct gazelle_stack_stat stack_stat; - struct gazelle_wakeup_stat wakeup_stat; -+ struct gazelle_stack_aggregate_stats aggregate_stats; - }; - - /* same as define in lwip/stats.h - struct stats_mib2 */ -@@ -218,23 +232,12 @@ struct nic_eth_xstats { - uint16_t port_id; - }; - --struct gazelle_stack_aggregate_stats { -- /* 0: RX, 1: TX, 2: APP_TX */ -- uint32_t size_1_64[3]; -- uint32_t size_65_512[3]; -- uint32_t size_513_1460[3]; -- uint32_t size_1461_8192[3]; -- uint32_t size_8193_max[3]; -- -- uint64_t rx_bytes; -- uint64_t tx_bytes; --}; -- - struct gazelle_stack_dfx_data { - /* indicates whether the current message is the last */ - uint32_t eof; - uint32_t tid; - int32_t loglevel; -+ uint32_t stack_id; - struct gazelle_stat_low_power_info low_power_info; - - union lstack_msg { -@@ -243,7 +246,6 @@ struct gazelle_stack_dfx_data { - struct gazelle_stat_lstack_conn conn; - struct gazelle_stat_lstack_snmp snmp; - struct nic_eth_xstats nic_xstats; -- struct gazelle_stack_aggregate_stats aggregate_stats; - } data; - }; - -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 18548ab..3fd5903 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -198,6 +198,13 @@ static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protoc - case GAZELLE_STAT_LSTACK_SHOW: - case GAZELLE_STAT_LSTACK_SHOW_RATE: - get_stack_stats(dfx, stack); -+ /* fall through */ -+ case GAZELLE_STAT_LSTACK_SHOW_AGGREGATE: -+ ret = memcpy_s(&dfx->data.pkts.aggregate_stats, sizeof(dfx->data.pkts.aggregate_stats), -+ &stack->aggregate_stats, sizeof(stack->aggregate_stats)); -+ if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "memcpy_s err ret=%d \n", ret); -+ } - break; - case GAZELLE_STAT_LSTACK_SHOW_SNMP: - ret = memcpy_s(&dfx->data.snmp, sizeof(dfx->data.snmp), &stack->lwip_stats->mib2, -@@ -218,13 +225,6 @@ static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protoc - LSTACK_LOG(ERR, LSTACK, "memcpy_s err ret=%d \n", ret); - } - break; -- case GAZELLE_STAT_LSTACK_SHOW_AGGREGATE: -- ret = memcpy_s(&dfx->data.aggregate_stats, sizeof(dfx->data.aggregate_stats), -- &stack->aggregate_stats, sizeof(stack->aggregate_stats)); -- if (ret != EOK) { -- LSTACK_LOG(ERR, LSTACK, "memcpy_s err ret=%d \n", ret); -- } -- break; - case GAZELLE_STAT_LTRAN_START_LATENCY: - set_latency_start_flag(true); - break; -@@ -287,6 +287,7 @@ int handle_stack_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode) - } - - dfx.tid = stack->tid; -+ dfx.stack_id = i; - if (i == stack_group->stack_num - 1) { - dfx.eof = 1; - } -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 3bd120c..d3ff527 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -45,6 +45,7 @@ - #define GAZELLE_LSTACK_SET_MINNUM 6 - - #define GAZELLE_CMD_MAX 5 -+#define CMD_WAIT_TIME 1 // sec - - #define GAZELLE_RESULT_LEN 8291 - #define GAZELLE_MAX_LATENCY_TIME 1800 // max latency time 30mins -@@ -55,6 +56,7 @@ static int32_t g_unix_fd = -1; - static int32_t g_ltran_rate_show_flag = GAZELLE_OFF; // not show when first get total statistics - static struct gazelle_stat_ltran_total g_last_ltran_total; - static struct gazelle_stat_lstack_total g_last_lstack_total[GAZELLE_MAX_STACK_ARRAY_SIZE]; -+static struct gazelle_stack_dfx_data g_last_lstack_data[GAZELLE_MAX_STACK_ARRAY_SIZE]; - - static bool g_use_ltran = false; - -@@ -73,6 +75,7 @@ struct gazelle_dfx_list { - - static void gazelle_print_ltran_stat_total(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_ltran_stat_rate(void *buf, const struct gazelle_stat_msg_request *req_msg); -+static void gazelle_print_ltran_stat_lb_rate(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_ltran_stat_client(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_ltran_stat_burst(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_ltran_stat_latency(void *buf, const struct gazelle_stat_msg_request *req_msg); -@@ -92,6 +95,7 @@ static void gazelle_print_lstack_aggregate(void *buf, const struct gazelle_stat_ - static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = { - {GAZELLE_STAT_LTRAN_SHOW, sizeof(struct gazelle_stat_ltran_total), gazelle_print_ltran_stat_total}, - {GAZELLE_STAT_LTRAN_SHOW_RATE, sizeof(struct gazelle_stat_ltran_total), gazelle_print_ltran_stat_rate}, -+ {GAZELLE_STAT_LTRAN_SHOW_LB_RATE, sizeof(struct gazelle_stat_ltran_total), gazelle_print_ltran_stat_lb_rate}, - {GAZELLE_STAT_LTRAN_SHOW_INSTANCE, sizeof(struct gazelle_stat_ltran_client), gazelle_print_ltran_stat_client}, - {GAZELLE_STAT_LTRAN_SHOW_BURST, sizeof(struct gazelle_stat_ltran_total), gazelle_print_ltran_stat_burst}, - {GAZELLE_STAT_LTRAN_SHOW_LATENCY, sizeof(struct in_addr), gazelle_print_ltran_stat_latency}, -@@ -103,7 +107,7 @@ static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = { - {GAZELLE_STAT_LTRAN_SHOW_CONNTABLE, sizeof(struct gazelle_stat_forward_table), gazelle_print_ltran_conn}, - {GAZELLE_STAT_LSTACK_LOG_LEVEL_SET, 0, gazelle_print_ltran_wait}, - {GAZELLE_STAT_LSTACK_SHOW, sizeof(struct gazelle_stat_lstack_total), gazelle_print_lstack_stat_total}, -- {GAZELLE_STAT_LSTACK_SHOW_RATE, sizeof(struct gazelle_stat_lstack_total), gazelle_print_lstack_stat_rate}, -+ {GAZELLE_STAT_LSTACK_SHOW_RATE, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_rate}, - {GAZELLE_STAT_LSTACK_SHOW_SNMP, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_snmp}, - {GAZELLE_STAT_LSTACK_SHOW_CONN, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_conn}, - {GAZELLE_STAT_LSTACK_SHOW_LATENCY, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_latency}, -@@ -422,7 +426,7 @@ static void gazelle_print_ltran_wait(void *buf, const struct gazelle_stat_msg_re - { - (void)buf; - (void)req_msg; -- sleep(1); // give ltran time to read cmd -+ sleep(CMD_WAIT_TIME); // give ltran time to read cmd - } - - static void gazelle_print_ltran_start_latency(void *buf, const struct gazelle_stat_msg_request *req_msg) -@@ -774,44 +778,39 @@ static void gazelle_print_lstack_stat_rate(void *buf, const struct gazelle_stat_ - { - int32_t ret; - double rate; -- uint32_t stack_index; -+ uint32_t index; - char *rate_type = NULL; -- struct gazelle_stat_lstack_total *stats = (struct gazelle_stat_lstack_total *)buf; -+ uint32_t total_wait_time = g_wait_reply + CMD_WAIT_TIME; /* STOP_LATENCY would sleep */ -+ struct gazelle_stack_dfx_data *stats = (struct gazelle_stack_dfx_data *)buf; - /* not show when first get total statistics */ - static int32_t g_lstack_rate_show_flag[GAZELLE_MAX_STACK_ARRAY_SIZE] = {0}; - - do { -- stack_index = stats->index; -- if (stack_index >= GAZELLE_MAX_STACK_ARRAY_SIZE) { -+ index = stats->stack_id; -+ if (index >= GAZELLE_MAX_STACK_ARRAY_SIZE) { - break; - } - -- if (g_lstack_rate_show_flag[stack_index] == GAZELLE_ON) { -+ if (g_lstack_rate_show_flag[index] == GAZELLE_ON) { - printf("------ Statistics of lstack rate stack tid: %6u ------\n", stats->tid); -- printf("rx_pkts: %-15"PRIu64" ", (stats->rx - g_last_lstack_total[stack_index].rx) / -- GAZELLE_DFX_REQ_INTERVAL_S); -- rate = rate_convert_type((stats->rx_bytes - g_last_lstack_total[stack_index].rx_bytes) / -- GAZELLE_DFX_REQ_INTERVAL_S, &rate_type); -+ printf("rx_pkts: %-15"PRIu64" ", (stats->data.pkts.stack_stat.rx - -+ g_last_lstack_data[index].data.pkts.stack_stat.rx) / total_wait_time); -+ rate = rate_convert_type((stats->data.pkts.aggregate_stats.rx_bytes / g_wait_reply), &rate_type); - printf("rx_bytes: %7.2lf%s ", rate, rate_type); -- printf("rx_err: %-15"PRIu64" ", (stats->rx_err - g_last_lstack_total[stack_index].rx_err) / -- GAZELLE_DFX_REQ_INTERVAL_S); -- printf("rx_drop: %-15"PRIu64"\n", (stats->rx_drop - g_last_lstack_total[stack_index].rx_drop) / -- GAZELLE_DFX_REQ_INTERVAL_S); -- printf("tx_pkts: %-15"PRIu64" ", (stats->tx - g_last_lstack_total[stack_index].tx) / -- GAZELLE_DFX_REQ_INTERVAL_S); -- rate = rate_convert_type((stats->tx_bytes - g_last_lstack_total[stack_index].tx_bytes) / -- GAZELLE_DFX_REQ_INTERVAL_S, &rate_type); -+ printf("rx_drop: %-15"PRIu64"\n", (stats->data.pkts.stack_stat.rx_drop - -+ g_last_lstack_data[index].data.pkts.stack_stat.rx_drop) /total_wait_time); -+ printf("tx_pkts: %-15"PRIu64" ", (stats->data.pkts.stack_stat.tx - -+ g_last_lstack_data[index].data.pkts.stack_stat.tx) / total_wait_time); -+ rate = rate_convert_type((stats->data.pkts.aggregate_stats.tx_bytes / g_wait_reply), &rate_type); - printf("tx_bytes: %7.2lf%s ", rate, rate_type); -- printf("tx_err: %-15"PRIu64" ", (stats->tx_err - g_last_lstack_total[stack_index].tx_err) / -- GAZELLE_DFX_REQ_INTERVAL_S); -- printf("tx_drop: %-15"PRIu64"\n\n", (stats->tx_drop - g_last_lstack_total[stack_index].tx_drop) / -- GAZELLE_DFX_REQ_INTERVAL_S); -+ printf("tx_drop: %-15"PRIu64"\n\n", (stats->data.pkts.stack_stat.tx_drop - -+ g_last_lstack_data[index].data.pkts.stack_stat.tx_drop) / total_wait_time); - } else { -- g_lstack_rate_show_flag[stack_index] = GAZELLE_ON; -+ g_lstack_rate_show_flag[index] = GAZELLE_ON; - } - -- ret = memcpy_s(&g_last_lstack_total[stack_index], sizeof(*stats), stats, -- sizeof(struct gazelle_stat_lstack_total)); -+ ret = memcpy_s(&g_last_lstack_data[index], sizeof(*stats), stats, -+ sizeof(struct gazelle_stack_dfx_data)); - if (ret != EOK) { - printf("%s:%d memcpy_s fail ret=%d\n", __FUNCTION__, __LINE__, ret); - } -@@ -820,7 +819,7 @@ static void gazelle_print_lstack_stat_rate(void *buf, const struct gazelle_stat_ - break; - } - -- ret = dfx_stat_read_from_ltran(buf, sizeof(struct gazelle_stat_lstack_total), req_msg->stat_mode); -+ ret = dfx_stat_read_from_ltran(buf, sizeof(struct gazelle_stack_dfx_data), req_msg->stat_mode); - if (ret != GAZELLE_OK) { - return; - } -@@ -846,6 +845,63 @@ static void gazelle_print_lstack_tcp_stat(const struct gazelle_stat_lstack_snmp - printf("tcp_listen_drops: %u\n", snmp->tcp_listen_drops); - } - -+static void gazelle_print_ltran_stat_lb_rate(void *buf, const struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t ret; -+ double rate; -+ uint32_t stack_index; -+ char *rate_type = NULL; -+ struct gazelle_stat_lstack_total *stats = (struct gazelle_stat_lstack_total *)buf; -+ /* not show when first get total statistics */ -+ static int32_t g_ltran_lb_rate_show_flag[GAZELLE_MAX_STACK_ARRAY_SIZE] = {0}; -+ -+ do { -+ stack_index = stats->index; -+ if (stack_index >= GAZELLE_MAX_STACK_ARRAY_SIZE) { -+ break; -+ } -+ -+ if (g_ltran_lb_rate_show_flag[stack_index] == GAZELLE_ON) { -+ printf("------ Statistics of lstack rate stack tid: %6u ------\n", stats->tid); -+ printf("rx_pkts: %-15"PRIu64" ", (stats->rx - g_last_lstack_total[stack_index].rx) / -+ GAZELLE_DFX_REQ_INTERVAL_S); -+ rate = rate_convert_type((stats->rx_bytes - g_last_lstack_total[stack_index].rx_bytes) / -+ GAZELLE_DFX_REQ_INTERVAL_S, &rate_type); -+ printf("rx_bytes: %7.2lf%s ", rate, rate_type); -+ printf("rx_err: %-15"PRIu64" ", (stats->rx_err - g_last_lstack_total[stack_index].rx_err) / -+ GAZELLE_DFX_REQ_INTERVAL_S); -+ printf("rx_drop: %-15"PRIu64"\n", (stats->rx_drop - g_last_lstack_total[stack_index].rx_drop) / -+ GAZELLE_DFX_REQ_INTERVAL_S); -+ printf("tx_pkts: %-15"PRIu64" ", (stats->tx - g_last_lstack_total[stack_index].tx) / -+ GAZELLE_DFX_REQ_INTERVAL_S); -+ rate = rate_convert_type((stats->tx_bytes - g_last_lstack_total[stack_index].tx_bytes) / -+ GAZELLE_DFX_REQ_INTERVAL_S, &rate_type); -+ printf("tx_bytes: %7.2lf%s ", rate, rate_type); -+ printf("tx_err: %-15"PRIu64" ", (stats->tx_err - g_last_lstack_total[stack_index].tx_err) / -+ GAZELLE_DFX_REQ_INTERVAL_S); -+ printf("tx_drop: %-15"PRIu64"\n\n", (stats->tx_drop - g_last_lstack_total[stack_index].tx_drop) / -+ GAZELLE_DFX_REQ_INTERVAL_S); -+ } else { -+ g_ltran_lb_rate_show_flag[stack_index] = GAZELLE_ON; -+ } -+ -+ ret = memcpy_s(&g_last_lstack_total[stack_index], sizeof(*stats), stats, -+ sizeof(struct gazelle_stat_lstack_total)); -+ if (ret != EOK) { -+ printf("%s:%d memcpy_s fail ret=%d\n", __FUNCTION__, __LINE__, ret); -+ } -+ -+ if (stats->eof != 0) { -+ break; -+ } -+ -+ ret = dfx_stat_read_from_ltran(buf, sizeof(struct gazelle_stat_lstack_total), req_msg->stat_mode); -+ if (ret != GAZELLE_OK) { -+ return; -+ } -+ } while (true); -+} -+ - static void gazelle_print_lstack_stat_snmp_core(const struct gazelle_stack_dfx_data *stat, - const struct gazelle_stat_lstack_snmp *snmp) - { -@@ -1048,15 +1104,12 @@ static int32_t parse_dfx_ltran_show_args(int32_t argc, char *argv[], struct gaze - if (strcmp(param, "rate") == 0 || strcmp(param, "-r") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_RATE; - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_MODE_MAX; -- } -- if (strcmp(param, "instance") == 0 || strcmp(param, "-i") == 0) { -+ } else if (strcmp(param, "instance") == 0 || strcmp(param, "-i") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_INSTANCE; -- } -- if (strcmp(param, "burst") == 0 || strcmp(param, "-b") == 0) { -+ } else if (strcmp(param, "burst") == 0 || strcmp(param, "-b") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_BURST; - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_MODE_MAX; -- } -- if (strcmp(param, "table") == 0 || strcmp(param, "-t") == 0) { -+ } else if (strcmp(param, "table") == 0 || strcmp(param, "-t") == 0) { - if (argc < GAZELLE_OPT_LPM_ARG_IDX1) { - return cmd_index; - } -@@ -1067,8 +1120,7 @@ static int32_t parse_dfx_ltran_show_args(int32_t argc, char *argv[], struct gaze - if (strcmp(param, "conntable") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_CONNTABLE; - } -- } -- if (strcmp(param, "latency") == 0 || strcmp(param, "-l") == 0) { -+ } else if (strcmp(param, "latency") == 0 || strcmp(param, "-l") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_START_LATENCY; - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_STOP_LATENCY; - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_LATENCY; -@@ -1092,7 +1144,7 @@ static int32_t parse_dfx_ltran_show_args(int32_t argc, char *argv[], struct gaze - static void gazelle_print_lstack_aggregate(void *buf, const struct gazelle_stat_msg_request *req_msg) - { - struct gazelle_stack_dfx_data *dfx = (struct gazelle_stack_dfx_data *)buf; -- struct gazelle_stack_aggregate_stats *stats = &dfx->data.aggregate_stats; -+ struct gazelle_stack_aggregate_stats *stats = &dfx->data.pkts.aggregate_stats; - char *rate_type = NULL; - double rate; - int32_t ret = 0; -@@ -1219,19 +1271,21 @@ static int32_t parse_dfx_lstack_show_args(int32_t argc, char *argv[], struct gaz - - char *param = argv[GAZELLE_OPTIONS1_ARG_IDX]; - if (strcmp(param, "rate") == 0 || strcmp(param, "-r") == 0) { -- req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_RATE; -+ if (g_use_ltran) { -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_LB_RATE; -+ } else { -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_START_LATENCY; -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_STOP_LATENCY; -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_RATE; -+ } - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_MODE_MAX; -- } -- if (strcmp(param, "snmp") == 0 || strcmp(param, "-s") == 0) { -+ } else if (strcmp(param, "snmp") == 0 || strcmp(param, "-s") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_SNMP; -- } -- if (strcmp(param, "connect") == 0 || strcmp(param, "-c") == 0) { -+ } else if (strcmp(param, "connect") == 0 || strcmp(param, "-c") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_CONN; -- } -- if (strcmp(param, "xstats") == 0 || strcmp(param, "-x") == 0) { -+ } else if (strcmp(param, "xstats") == 0 || strcmp(param, "-x") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_XSTATS; -- } -- if (strcmp(param, "latency") == 0 || strcmp(param, "-l") == 0) { -+ } else if (strcmp(param, "latency") == 0 || strcmp(param, "-l") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_START_LATENCY; - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_STOP_LATENCY; - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_LATENCY; -@@ -1242,8 +1296,7 @@ static int32_t parse_dfx_lstack_show_args(int32_t argc, char *argv[], struct gaz - if (parse_delay_arg(argc, argv, delay) != 0) { - return 0; - } -- } -- if (strcmp(param, "aggragate") == 0 || strcmp(param, "-a") == 0) { -+ } else if (strcmp(param, "aggragate") == 0 || strcmp(param, "-a") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_START_LATENCY; - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_STOP_LATENCY; - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_AGGREGATE; -@@ -1314,31 +1367,6 @@ static int32_t parse_dfx_cmd_args(int32_t argc, char *argv[], struct gazelle_sta - return num_cmd; - } - --static int32_t check_cmd_support(struct gazelle_stat_msg_request *req_msg, int32_t req_msg_num) --{ -- switch (req_msg[0].stat_mode) { -- case GAZELLE_STAT_LSTACK_LOG_LEVEL_SET: -- case GAZELLE_STAT_LSTACK_SHOW: -- case GAZELLE_STAT_LSTACK_SHOW_SNMP: -- case GAZELLE_STAT_LSTACK_SHOW_CONN: -- case GAZELLE_STAT_LSTACK_SHOW_LATENCY: -- case GAZELLE_STAT_LSTACK_LOW_POWER_MDF: -- case GAZELLE_STAT_LSTACK_SHOW_XSTATS: -- case GAZELLE_STAT_LSTACK_SHOW_AGGREGATE: -- return 0; -- default: -- if (req_msg[0].stat_mode == GAZELLE_STAT_LTRAN_START_LATENCY && -- (req_msg[req_msg_num - 1].stat_mode == GAZELLE_STAT_LSTACK_SHOW_LATENCY || -- req_msg[req_msg_num - 1].stat_mode == GAZELLE_STAT_LSTACK_SHOW_AGGREGATE)) { -- return 0; -- } -- /* keep output consistency */ -- printf("connect ltran failed. errno: 111 ret=-1\n"); -- printf("You may need to use the -u parameter to specify the UNIX_PREFIX that matches the configuration.\n"); -- return -1; -- } --} -- - int32_t dfx_loop(struct gazelle_stat_msg_request *req_msg, int32_t req_msg_num) - { - int32_t ret; -@@ -1377,8 +1405,10 @@ int32_t dfx_loop(struct gazelle_stat_msg_request *req_msg, int32_t req_msg_num) - - // stat_mode = GAZELLE_STAT_MODE_MAX need repeat command - if (req_msg[msg_index].stat_mode == GAZELLE_STAT_MODE_MAX) { -- msg_index--; -- sleep(GAZELLE_DFX_REQ_INTERVAL_S); -+ if (req_msg[msg_index - 1].stat_mode != GAZELLE_STAT_LSTACK_SHOW_RATE) { -+ sleep(GAZELLE_DFX_REQ_INTERVAL_S); -+ } -+ msg_index = 0; - } - } - -@@ -1388,7 +1418,7 @@ int32_t dfx_loop(struct gazelle_stat_msg_request *req_msg, int32_t req_msg_num) - int32_t main(int32_t argc, char *argv[]) - { - struct gazelle_stat_msg_request req_msg[GAZELLE_CMD_MAX] = {0}; -- int32_t req_msg_num, ret; -+ int32_t req_msg_num; - - int unix_arg = 0; - for (int32_t i = 1; i < argc; i++) { -@@ -1418,13 +1448,5 @@ int32_t main(int32_t argc, char *argv[]) - return 0; - } - -- if (!g_use_ltran) { -- g_gazelle_dfx_tbl[GAZELLE_STAT_LSTACK_SHOW].recv_size = sizeof(struct gazelle_stack_dfx_data); -- ret = check_cmd_support(req_msg, req_msg_num); -- if (ret < 0) { -- return -1; -- } -- } -- - return dfx_loop(req_msg, req_msg_num); - } -diff --git a/src/ltran/ltran_monitor.c b/src/ltran/ltran_monitor.c -index d163a47..792db89 100644 ---- a/src/ltran/ltran_monitor.c -+++ b/src/ltran/ltran_monitor.c -@@ -335,14 +335,15 @@ static int32_t lstack_req_mode_process(int32_t fd, const struct gazelle_stat_msg - case GAZELLE_STAT_LSTACK_LOG_LEVEL_SET: - handle_resp_lstack_transfer(req_msg, -1); - break; -- case GAZELLE_STAT_LSTACK_SHOW_RATE: -+ case GAZELLE_STAT_LTRAN_SHOW_LB_RATE: - handle_resp_lstack_total(req_msg, fd); - break; - case GAZELLE_STAT_LSTACK_SHOW: - handle_resp_lstack_total(req_msg, fd); - handle_resp_lstack_transfer(req_msg, fd); - break; -- case GAZELLE_STAT_LSTACK_SHOW_SNMP: // fall through -+ case GAZELLE_STAT_LSTACK_SHOW_RATE: // fall through -+ case GAZELLE_STAT_LSTACK_SHOW_SNMP: - case GAZELLE_STAT_LSTACK_SHOW_CONN: - case GAZELLE_STAT_LSTACK_SHOW_LATENCY: - case GAZELLE_STAT_LSTACK_LOW_POWER_MDF: --- -2.27.0 - diff --git a/0067-fix-coredump-because-sock-closed-before-send-data-fu.patch b/0067-fix-coredump-because-sock-closed-before-send-data-fu.patch deleted file mode 100644 index 0bd8a486001c217752104aedafa48f53cd11e759..0000000000000000000000000000000000000000 --- a/0067-fix-coredump-because-sock-closed-before-send-data-fu.patch +++ /dev/null @@ -1,129 +0,0 @@ -From 1a6c2c86c51997d541c6243a80580c9f54f99bb2 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Tue, 28 Nov 2023 11:30:49 +0800 -Subject: [PATCH] fix coredump because sock closed before send data fully - ---- - src/lstack/core/lstack_protocol_stack.c | 15 ++++++++++----- - src/lstack/core/lstack_thread_rpc.c | 20 +++++++++++--------- - src/lstack/include/lstack_thread_rpc.h | 3 ++- - 3 files changed, 23 insertions(+), 15 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 54cf9e8..71e7bcc 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -696,7 +696,15 @@ void stack_socket(struct rpc_msg *msg) - void stack_close(struct rpc_msg *msg) - { - int32_t fd = msg->args[MSG_ARG_0].i; -- -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -+ struct lwip_sock *sock = get_socket(fd); -+ -+ if (NETCONN_IS_DATAOUT(sock)) { -+ msg->recall_flag = 1; -+ rpc_call(&stack->rpc_queue, msg); /* until stack_send recall finish */ -+ return; -+ } -+ - msg->result = lwip_close(fd); - if (msg->result != 0) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); -@@ -842,15 +850,12 @@ void stack_send(struct rpc_msg *msg) - replenish_again = do_lwip_send(stack, sock->conn->socket, sock, len, 0); - __sync_fetch_and_sub(&sock->call_num, 1); - if (!NETCONN_IS_DATAOUT(sock) && !replenish_again) { -- rpc_msg_free(msg); - return; - } else { - if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 0) { -+ msg->recall_flag = 1; - rpc_call(&stack->rpc_queue, msg); - __sync_fetch_and_add(&sock->call_num, 1); -- } else { -- rpc_msg_free(msg); -- return; - } - } - } -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 92c58df..03e014d 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -71,8 +71,8 @@ static struct rpc_msg *rpc_msg_alloc(struct protocol_stack *stack, rpc_msg_func - - pthread_spin_init(&msg->lock, PTHREAD_PROCESS_PRIVATE); - msg->func = func; -- msg->self_release = 1; -- -+ msg->sync_flag = 1; -+ msg->recall_flag = 0; - return msg; - } - -@@ -94,6 +94,7 @@ static inline __attribute__((always_inline)) int32_t rpc_sync_call(lockless_queu - void poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) - { - struct rpc_msg *msg = NULL; -+ struct lwip_sock *sock = NULL; - - while (max_num--) { - lockless_queue_node *node = lockless_queue_mpsc_pop(&stack->rpc_queue); -@@ -109,14 +110,15 @@ void poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) - stack->stats.call_null++; - } - -- /* stack_send free msg in stack_send */ -- if (msg->func != stack_send) { -- if (msg->self_release) { -+ if (!msg->recall_flag) { -+ if (msg->sync_flag) { - pthread_spin_unlock(&msg->lock); - } else { - rpc_msg_free(msg); - } -- } -+ } else { -+ msg->recall_flag = 0; -+ } - } - } - -@@ -224,7 +226,7 @@ int32_t rpc_call_arp(struct protocol_stack *stack, struct rte_mbuf *mbuf) - return -1; - } - -- msg->self_release = 0; -+ msg->sync_flag = 0; - msg->args[MSG_ARG_0].p = mbuf; - msg->args[MSG_ARG_1].p = stack; - -@@ -458,8 +460,8 @@ int32_t rpc_call_send(int fd, const void *buf, size_t len, int flags) - msg->args[MSG_ARG_1].size = len; - msg->args[MSG_ARG_2].i = flags; - msg->args[MSG_ARG_3].p = stack; -- msg->self_release = 0; -- -+ msg->sync_flag = 0; -+ - rpc_call(&stack->rpc_queue, msg); - - return 0; -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index bcb40dd..80e254f 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -44,7 +44,8 @@ union rpc_msg_arg { - struct rpc_msg_pool; - struct rpc_msg { - pthread_spinlock_t lock; /* msg handler unlock notice sender msg process done */ -- int32_t self_release; /* 0:msg handler release msg 1:msg sender release msg */ -+ int8_t sync_flag : 1; -+ int8_t recall_flag : 1; - int64_t result; /* func return val */ - lockless_queue_node queue_node; - struct rpc_msg_pool *pool; --- -2.27.0 - diff --git a/0068-fix-compilation-error.patch b/0068-fix-compilation-error.patch deleted file mode 100644 index 398c566dbb91e18519fbfe25665b8047a19c4abd..0000000000000000000000000000000000000000 --- a/0068-fix-compilation-error.patch +++ /dev/null @@ -1,39 +0,0 @@ -From 876393a2263c2d5de441d357a22db0db0e80a81f Mon Sep 17 00:00:00 2001 -From: wuchangye -Date: Sat, 2 Dec 2023 13:46:03 +0800 -Subject: [PATCH] fix compilation error - ---- - src/lstack/core/lstack_thread_rpc.c | 1 - - src/lstack/include/lstack_thread_rpc.h | 3 --- - 2 files changed, 4 deletions(-) - -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 03e014d..f23d935 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -94,7 +94,6 @@ static inline __attribute__((always_inline)) int32_t rpc_sync_call(lockless_queu - void poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) - { - struct rpc_msg *msg = NULL; -- struct lwip_sock *sock = NULL; - - while (max_num--) { - lockless_queue_node *node = lockless_queue_mpsc_pop(&stack->rpc_queue); -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 80e254f..aa8c451 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -96,9 +96,6 @@ static inline __attribute__((always_inline)) void rpc_call(lockless_queue *queue - static inline __attribute__((always_inline)) void rpc_msg_free(struct rpc_msg *msg) - { - pthread_spin_destroy(&msg->lock); -- -- msg->self_release = 0; -- - rte_mempool_put(msg->pool->rpc_pool, (void *)msg); - } - --- -2.27.0 - diff --git a/0069-fix-coredump-because-of-addr-null-in-lwip_fill_sendr.patch b/0069-fix-coredump-because-of-addr-null-in-lwip_fill_sendr.patch deleted file mode 100644 index f719c93691fc1c4c74dafc9b30a86ca99853c76f..0000000000000000000000000000000000000000 --- a/0069-fix-coredump-because-of-addr-null-in-lwip_fill_sendr.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 7ad97d182db49ae91e9044f4d50e52f8633b2b1c Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Fri, 1 Dec 2023 15:58:09 +0800 -Subject: [PATCH] fix coredump because of addr null in lwip_fill_sendring - ---- - src/lstack/core/lstack_protocol_stack.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index c087098..27eeafb 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -699,7 +699,7 @@ void stack_close(struct rpc_msg *msg) - struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - struct lwip_sock *sock = get_socket(fd); - -- if (NETCONN_IS_DATAOUT(sock)) { -+ if (sock && NETCONN_IS_DATAOUT(sock)) { - msg->recall_flag = 1; - rpc_call(&stack->rpc_queue, msg); /* until stack_send recall finish */ - return; --- -2.27.0 - diff --git a/0070-add-struct-gz_addr_t.patch b/0070-add-struct-gz_addr_t.patch deleted file mode 100644 index 9d74e672e054e49de59a032f0fe592996d0e94ae..0000000000000000000000000000000000000000 --- a/0070-add-struct-gz_addr_t.patch +++ /dev/null @@ -1,97 +0,0 @@ -From 7d721f7c7e5b1ac5265a8a7a30158e81f0e45b9b Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Mon, 4 Dec 2023 20:28:41 +0800 -Subject: [PATCH] add struct gz_addr_t -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -日期: Tue Dec 5 9:30:41 2023 +0800 ---- - src/lstack/core/lstack_dpdk.c | 14 ++++++-------- - src/lstack/include/lstack_dpdk.h | 4 ++-- - src/ltran/ltran_timer.c | 8 -------- - 3 files changed, 8 insertions(+), 18 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 839516e..a742335 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -766,7 +766,7 @@ int32_t init_dpdk_ethdev(void) - return 0; - } - --bool port_in_stack_queue(ip_addr_t src_ip, ip_addr_t dst_ip, uint16_t src_port, uint16_t dst_port) -+bool port_in_stack_queue(gz_addr_t *src_ip, gz_addr_t *dst_ip, uint16_t src_port, uint16_t dst_port) - { - struct protocol_stack_group *stack_group = get_protocol_stack_group(); - if (stack_group->reta_mask == 0 || stack_group->nb_queues <= 1) { -@@ -775,19 +775,17 @@ bool port_in_stack_queue(ip_addr_t src_ip, ip_addr_t dst_ip, uint16_t src_port, - - union rte_thash_tuple tuple; - uint32_t hash = 0; -- if (IP_IS_V4_VAL(src_ip)) { -- tuple.v4.src_addr = rte_be_to_cpu_32(ip_2_ip4(&src_ip)->addr); -- tuple.v4.dst_addr = rte_be_to_cpu_32(ip_2_ip4(&dst_ip)->addr); -+ if (IP_IS_V4_VAL(*src_ip)) { -+ tuple.v4.src_addr = rte_be_to_cpu_32(src_ip->u_addr.ip4.addr); -+ tuple.v4.dst_addr = rte_be_to_cpu_32(dst_ip->u_addr.ip4.addr); - tuple.v4.sport = src_port; - tuple.v4.dport = dst_port; - hash = rte_softrss((uint32_t *)&tuple, RTE_THASH_V4_L4_LEN, g_default_rss_key); - } else { - int i; - for (i = 0; i < 4; i++) { -- *((uint32_t *)tuple.v6.src_addr + i) = -- rte_be_to_cpu_32(*((const uint32_t *)src_ip.u_addr.ip6.addr + i)); -- *((uint32_t *)tuple.v6.dst_addr + i) = -- rte_be_to_cpu_32(*((const uint32_t *)dst_ip.u_addr.ip6.addr + i)); -+ *((uint32_t *)tuple.v6.src_addr + i) = rte_be_to_cpu_32(*(src_ip->u_addr.ip6.addr + i)); -+ *((uint32_t *)tuple.v6.dst_addr + i) = rte_be_to_cpu_32(*(dst_ip->u_addr.ip6.addr + i)); - } - tuple.v6.sport = src_port; - tuple.v6.dport = dst_port; -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index 6554a7e..724ab24 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -13,7 +13,7 @@ - #ifndef _GAZELLE_DPDK_H_ - #define _GAZELLE_DPDK_H_ - --#include -+#include - #include "gazelle_opt.h" - #include "gazelle_dfx_msg.h" - -@@ -54,7 +54,7 @@ int dpdk_ethdev_start(void); - void dpdk_skip_nic_init(void); - int32_t dpdk_init_lstack_kni(void); - void dpdk_restore_pci(void); --bool port_in_stack_queue(ip_addr_t src_ip, ip_addr_t dst_ip, uint16_t src_port, uint16_t dst_port); -+bool port_in_stack_queue(gz_addr_t *src_ip, gz_addr_t *dst_ip, uint16_t src_port, uint16_t dst_port); - struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, - uint32_t mbuf_cache_size, uint16_t queue_id, unsigned numa_id); - -diff --git a/src/ltran/ltran_timer.c b/src/ltran/ltran_timer.c -index 749b8e0..85ea324 100644 ---- a/src/ltran/ltran_timer.c -+++ b/src/ltran/ltran_timer.c -@@ -24,14 +24,6 @@ - #include "ltran_tcp_conn.h" - #include "ltran_instance.h" - #include "ltran_timer.h" --/* undefine lwip_ntohs in lwip/def.h */ --#ifdef ntohs --#undef ntohs --#endif --#ifdef htons --#undef htons --#endif -- - - static uint64_t g_cycles_per_us = 0; - --- -2.27.0 - diff --git a/0071-wrap-support-shutdown.patch b/0071-wrap-support-shutdown.patch deleted file mode 100644 index b2bafed1e56a7d1a3a0c2c032bca44bb01851682..0000000000000000000000000000000000000000 --- a/0071-wrap-support-shutdown.patch +++ /dev/null @@ -1,305 +0,0 @@ -From e1bdd31e6f4ec0aa426cdc2e24b2c78fb7903cfe Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Wed, 6 Dec 2023 09:26:45 +0800 -Subject: [PATCH] wrap: support shutdown - ---- - src/lstack/api/lstack_rtc_api.c | 5 +++ - src/lstack/api/lstack_rtw_api.c | 13 +++++++ - src/lstack/api/lstack_wrap.c | 24 ++++++++++++ - src/lstack/core/lstack_dpdk.c | 2 +- - src/lstack/core/lstack_protocol_stack.c | 45 ++++++++++++++++++++++ - src/lstack/core/lstack_thread_rpc.c | 16 ++++++++ - src/lstack/include/lstack_protocol_stack.h | 3 ++ - src/lstack/include/lstack_rtc_api.h | 1 + - src/lstack/include/lstack_rtw_api.h | 1 + - src/lstack/include/lstack_thread_rpc.h | 1 + - 10 files changed, 110 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index 5fad3e8..50d72bc 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -65,6 +65,11 @@ int rtc_close(int s) - return lwip_close(s); - } - -+int rtc_shutdown(int fd, int how) -+{ -+ return lwip_shutdown(fd, how); -+} -+ - int rtc_epoll_create(int flags) - { - if (stack_setup_app_thread() < 0) { -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index c524bf9..04944d5 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -22,8 +22,10 @@ - #include "lstack_protocol_stack.h" - #include "lstack_cfg.h" - #include "lstack_lwip.h" -+#include "gazelle_base_func.h" - #include "lstack_rtw_api.h" - -+ - int rtw_socket(int domain, int type, int protocol) - { - return rpc_call_socket(domain, type, protocol); -@@ -228,6 +230,16 @@ int rtw_close(int s) - return stack_broadcast_close(s); - } - -+int rtw_shutdown(int fd, int how) -+{ -+ struct lwip_sock *sock = get_socket_by_fd(fd); -+ if (sock && sock->wakeup && sock->wakeup->epollfd == fd) { -+ GAZELLE_RETURN(ENOTSOCK); -+ } -+ -+ return stack_broadcast_shutdown(fd, how); -+} -+ - int rtw_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) - { - return lstack_rtw_epoll_ctl(epfd, op, fd, event); -@@ -242,3 +254,4 @@ int rtw_epoll_create(int flags) - { - return lstack_epoll_create(flags); - } -+ -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index abbf8a1..07d5f27 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -75,6 +75,7 @@ void wrap_api_init(void) - g_wrap_api->epoll_wait_fn = rtc_epoll_wait; - g_wrap_api->poll_fn = rtc_poll; - g_wrap_api->close_fn = rtc_close; -+ g_wrap_api->shutdown_fn = rtc_shutdown; - g_wrap_api->epoll_ctl_fn = rtc_epoll_ctl; - g_wrap_api->epoll_create1_fn = rtc_epoll_create1; - g_wrap_api->epoll_create_fn = rtc_epoll_create; -@@ -103,6 +104,7 @@ void wrap_api_init(void) - g_wrap_api->epoll_wait_fn = rtw_epoll_wait; - g_wrap_api->poll_fn = rtw_poll; - g_wrap_api->close_fn = rtw_close; -+ g_wrap_api->shutdown_fn = rtw_shutdown; - g_wrap_api->epoll_ctl_fn = rtw_epoll_ctl; - g_wrap_api->epoll_create1_fn = rtw_epoll_create1; - g_wrap_api->epoll_create_fn = rtw_epoll_create; -@@ -554,6 +556,20 @@ static inline int32_t do_close(int32_t s) - return g_wrap_api->close_fn(s); - } - -+static int32_t do_shutdown(int fd, int how) -+{ -+ struct lwip_sock *sock = NULL; -+ if (select_posix_path() == PATH_KERNEL || select_fd_posix_path(fd, &sock) == PATH_KERNEL) { -+ if (posix_api != NULL && !posix_api->ues_posix && g_wrap_api->shutdown_fn(fd, how) == 0) { -+ return 0; -+ } else { -+ return posix_api->shutdown_fn(fd, how); -+ } -+ } -+ -+ return g_wrap_api->shutdown_fn(fd, how); -+} -+ - static int32_t do_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - { - if ((select_posix_path() == PATH_KERNEL) || fds == NULL || nfds == 0) { -@@ -742,6 +758,10 @@ int32_t close(int32_t s) - { - return do_close(s); - } -+int32_t shutdown(int fd, int how) -+{ -+ return do_shutdown(fd, how); -+} - int32_t poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - { - return do_poll(fds, nfds, timeout); -@@ -875,6 +895,10 @@ int32_t __wrap_close(int32_t s) - { - return do_close(s); - } -+int32_t __wrap_shutdown(int fd, int how) -+{ -+ return do_shutdown(fd, how); -+} - int32_t __wrap_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - { - return do_poll(fds, nfds, timeout); -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index a742335..1811a9d 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -294,7 +294,7 @@ int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, ui - { - int32_t ret = rte_pktmbuf_alloc_bulk(pool, mbufs, num); - if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "rte_pktmbuf_alloc_bulk fail allocNum=%d, ret=%d, info:=%s \n", -+ LSTACK_LOG(ERR, LSTACK, "rte_pktmbuf_alloc_bulk fail allocNum=%d, ret=%d, info:%s \n", - num, ret, rte_strerror(-ret)); - return ret; - } -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 27eeafb..dc8f143 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -715,6 +715,27 @@ void stack_close(struct rpc_msg *msg) - posix_api->close_fn(fd); - } - -+void stack_shutdown(struct rpc_msg *msg) -+{ -+ int fd = msg->args[MSG_ARG_0].i; -+ int how = msg->args[MSG_ARG_1].i; -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -+ struct lwip_sock *sock = get_socket(fd); -+ -+ if (sock && NETCONN_IS_DATAOUT(sock)) { -+ msg->recall_flag = 1; -+ rpc_call(&stack->rpc_queue, msg); -+ return; -+ } -+ -+ msg->result = lwip_shutdown(fd, how); -+ if (msg->result != 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d fail %ld\n", get_stack_tid(), fd, msg->result); -+ } -+ -+ posix_api->shutdown_fn(fd, how); -+} -+ - void stack_bind(struct rpc_msg *msg) - { - msg->result = lwip_bind(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].cp, msg->args[MSG_ARG_2].socklen); -@@ -1041,6 +1062,29 @@ int32_t stack_broadcast_close(int32_t fd) - return ret; - } - -+int stack_broadcast_shutdown(int fd, int how) -+{ -+ int32_t ret = 0; -+ struct lwip_sock *sock = get_socket(fd); -+ if (sock == NULL) { -+ return -1; -+ } -+ -+ do { -+ sock = sock->listen_next; -+ if (rpc_call_shutdown(fd, how)) { -+ ret = -1; -+ } -+ -+ if (sock == NULL || sock->conn == NULL) { -+ break; -+ } -+ fd = sock->conn->socket; -+ } while (sock); -+ -+ return ret; -+} -+ - /* choice one stack listen */ - int32_t stack_single_listen(int32_t fd, int32_t backlog) - { -@@ -1204,3 +1248,4 @@ int32_t stack_broadcast_accept(int32_t fd, struct sockaddr *addr, socklen_t *add - { - return stack_broadcast_accept4(fd, addr, addrlen, 0); - } -+ -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index f23d935..4dc3da3 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -262,6 +262,21 @@ int32_t rpc_call_close(int fd) - return rpc_sync_call(&stack->rpc_queue, msg); - } - -+int32_t rpc_call_shutdown(int fd, int how) -+{ -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -+ -+ struct rpc_msg *msg = rpc_msg_alloc(stack, stack_shutdown); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].i = how; -+ -+ return rpc_sync_call(&stack->rpc_queue, msg); -+} -+ - void rpc_call_clean_epoll(struct protocol_stack *stack, struct wakeup_poll *wakeup) - { - struct rpc_msg *msg = rpc_msg_alloc(stack, stack_clean_epoll); -@@ -465,3 +480,4 @@ int32_t rpc_call_send(int fd, const void *buf, size_t len, int flags) - - return 0; - } -+ -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 2c581b3..e339b8d 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -126,6 +126,8 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - /* when fd is listenfd, listenfd of all protocol stack thread will be closed */ - int32_t stack_broadcast_close(int32_t fd); - -+int stack_broadcast_shutdown(int fd, int how); -+ - /* listen sync to all protocol stack thread, so that any protocol stack thread can build connect */ - int32_t stack_broadcast_listen(int32_t fd, int backlog); - int32_t stack_single_listen(int32_t fd, int32_t backlog); -@@ -152,6 +154,7 @@ void stack_clean_epoll(struct rpc_msg *msg); - void stack_arp(struct rpc_msg *msg); - void stack_socket(struct rpc_msg *msg); - void stack_close(struct rpc_msg *msg); -+void stack_shutdown(struct rpc_msg *msg); - void stack_bind(struct rpc_msg *msg); - void stack_listen(struct rpc_msg *msg); - void stack_accept(struct rpc_msg *msg); -diff --git a/src/lstack/include/lstack_rtc_api.h b/src/lstack/include/lstack_rtc_api.h -index dd90e59..3a41e6f 100644 ---- a/src/lstack/include/lstack_rtc_api.h -+++ b/src/lstack/include/lstack_rtc_api.h -@@ -49,6 +49,7 @@ int rtc_poll(struct pollfd *fds, nfds_t nfds, int timeout); - int rtc_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout); - int rtc_socket(int domain, int type, int protocol); - int rtc_close(int s); -+int rtc_shutdown(int fd, int how); - int rtc_epoll_create(int flags); - int rtc_epoll_create1(int flags); - int rtc_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); -diff --git a/src/lstack/include/lstack_rtw_api.h b/src/lstack/include/lstack_rtw_api.h -index d0f77b7..a38b656 100644 ---- a/src/lstack/include/lstack_rtw_api.h -+++ b/src/lstack/include/lstack_rtw_api.h -@@ -42,6 +42,7 @@ ssize_t rtw_sendto(int sockfd, const void *buf, size_t len, int flags, - int rtw_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout); - int rtw_poll(struct pollfd *fds, nfds_t nfds, int timeout); - int rtw_close(int s); -+int rtw_shutdown(int fd, int how); - int rtw_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); - int rtw_epoll_create1(int flags); - int rtw_epoll_create(int flags); -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index aa8c451..13f5ec2 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -74,6 +74,7 @@ int32_t rpc_call_connnum(struct protocol_stack *stack); - int32_t rpc_call_arp(struct protocol_stack *stack, struct rte_mbuf *mbuf); - int32_t rpc_call_socket(int32_t domain, int32_t type, int32_t protocol); - int32_t rpc_call_close(int32_t fd); -+int32_t rpc_call_shutdown(int fd, int how); - int32_t rpc_call_bind(int32_t fd, const struct sockaddr *addr, socklen_t addrlen); - int32_t rpc_call_listen(int s, int backlog); - int32_t rpc_call_accept(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags); --- -2.27.0 - diff --git a/0072-1.solve-the-problem-of-1w-connection-not-being-able-.patch b/0072-1.solve-the-problem-of-1w-connection-not-being-able-.patch deleted file mode 100644 index 9512287273a0e9a95b4bd507e770f013c3fcfbb6..0000000000000000000000000000000000000000 --- a/0072-1.solve-the-problem-of-1w-connection-not-being-able-.patch +++ /dev/null @@ -1,395 +0,0 @@ -From 17d320fa7a978de0d76ae13d0afb1744cf456250 Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Mon, 4 Dec 2023 15:45:09 +0800 -Subject: [PATCH] 1.solve the problem of 1w connection not being able to ping - 2.add debug info : rpc_mempool availd size - -3.mod struct member name -3.1 rxtx_pktmbuf_pool -> rxtx_mbufpool -3.2 pool -> rpcpool; rpc_pool -> mempool ---- - src/common/gazelle_dfx_msg.h | 3 ++- - src/lstack/core/lstack_dpdk.c | 15 +++++++++------ - src/lstack/core/lstack_lwip.c | 8 ++++---- - src/lstack/core/lstack_protocol_stack.c | 12 +++++++++--- - src/lstack/core/lstack_stack_stat.c | 7 +++++-- - src/lstack/core/lstack_thread_rpc.c | 20 +++++++++++++++----- - src/lstack/include/lstack_protocol_stack.h | 5 ++++- - src/lstack/include/lstack_thread_rpc.h | 11 ++++++----- - src/lstack/netif/lstack_ethdev.c | 10 +++++----- - src/lstack/netif/lstack_vdev.c | 2 +- - src/ltran/ltran_dfx.c | 3 ++- - 11 files changed, 62 insertions(+), 34 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index ac6ea5e..81d3426 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -93,7 +93,8 @@ struct gazelle_stack_aggregate_stats { - - struct gazelle_stat_pkts { - uint16_t conn_num; -- uint32_t mempool_freecnt; -+ uint32_t mbufpool_avail_cnt; -+ uint32_t rpcpool_avail_cnt; - uint64_t call_msg_cnt; - uint64_t recv_list_cnt; - uint64_t call_alloc_fail; -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 1811a9d..5107f1a 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -207,16 +207,16 @@ static struct reg_ring_msg *create_reg_mempool(const char *name, uint16_t queue_ - - int32_t pktmbuf_pool_init(struct protocol_stack *stack) - { -- stack->rxtx_pktmbuf_pool = get_pktmbuf_mempool("rxtx_mbuf", stack->queue_id); -- if (stack->rxtx_pktmbuf_pool == NULL) { -- LSTACK_LOG(ERR, LSTACK, "rxtx_pktmbuf_pool is NULL\n"); -+ stack->rxtx_mbuf_pool = get_pktmbuf_mempool("rxtx_mbuf", stack->queue_id); -+ if (stack->rxtx_mbuf_pool == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "rxtx_mbuf_pool is NULL\n"); - return -1; - } - - if (use_ltran()) { - stack->reg_buf = create_reg_mempool("reg_ring_msg", stack->queue_id); - if (stack->reg_buf == NULL) { -- LSTACK_LOG(ERR, LSTACK, "rxtx_pktmbuf_pool is NULL\n"); -+ LSTACK_LOG(ERR, LSTACK, "rxtx_mbuf_pool is NULL\n"); - return -1; - } - } -@@ -292,6 +292,9 @@ int32_t create_shared_ring(struct protocol_stack *stack) - - int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num) - { -+ if (rte_mempool_avail_count(pool) < MBUFPOOL_RESERVE_NUM + num) { -+ return -ENOMEM; -+ } - int32_t ret = rte_pktmbuf_alloc_bulk(pool, mbufs, num); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "rte_pktmbuf_alloc_bulk fail allocNum=%d, ret=%d, info:%s \n", -@@ -607,7 +610,7 @@ static int32_t dpdk_ethdev_setup(const struct eth_params *eth_params, uint16_t i - { - int32_t ret; - -- struct rte_mempool *rxtx_pktmbuf_pool = get_protocol_stack_group()->total_rxtx_pktmbuf_pool[idx]; -+ 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(); -@@ -617,7 +620,7 @@ static int32_t dpdk_ethdev_setup(const struct eth_params *eth_params, uint16_t i - socket_id = cfg->process_numa[idx]; - } - ret = rte_eth_rx_queue_setup(eth_params->port_id, idx, eth_params->nb_rx_desc, socket_id, -- ð_params->rx_conf, rxtx_pktmbuf_pool); -+ ð_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; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index af9bf73..5d5ad73 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -143,7 +143,7 @@ static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_so - return false; - } - -- if (rte_pktmbuf_alloc_bulk(stack->rxtx_pktmbuf_pool, (struct rte_mbuf **)pbuf, replenish_cnt) != 0) { -+ if (dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)pbuf, replenish_cnt) != 0) { - stack->stats.tx_allocmbuf_fail++; - return true; - } -@@ -237,7 +237,7 @@ struct pbuf *do_lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type typ - struct rte_mbuf *mbuf; - struct protocol_stack *stack = get_protocol_stack(); - -- if (rte_pktmbuf_alloc_bulk(stack->rxtx_pktmbuf_pool, &mbuf, 1) != 0) { -+ if (dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf, 1) != 0) { - stack->stats.tx_allocmbuf_fail++; - return NULL; - } -@@ -362,7 +362,7 @@ static inline ssize_t app_direct_write(struct protocol_stack *stack, struct lwip - } - - /* first pbuf get from send_ring. and malloc pbufs attach to first pbuf */ -- if (rte_pktmbuf_alloc_bulk(stack->rxtx_pktmbuf_pool, (struct rte_mbuf **)&pbufs[1], write_num - 1) != 0) { -+ if (dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)&pbufs[1], write_num - 1) != 0) { - stack->stats.tx_allocmbuf_fail++; - free(pbufs); - return 0; -@@ -401,7 +401,7 @@ static inline ssize_t app_direct_attach(struct protocol_stack *stack, struct pbu - } - - /* first pbuf get from send_ring. and malloc pbufs attach to first pbuf */ -- if (rte_pktmbuf_alloc_bulk(stack->rxtx_pktmbuf_pool, (struct rte_mbuf **)pbufs, write_num) != 0) { -+ if (dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)pbufs, write_num) != 0) { - stack->stats.tx_allocmbuf_fail++; - free(pbufs); - return 0; -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index dc8f143..f61e7a8 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -902,7 +902,7 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - continue; - } - -- ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1); - if (ret != 0) { - stack->stats.rx_allocmbuf_fail++; - return; -@@ -914,7 +914,7 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - return; - } - } -- ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1); - if (ret != 0) { - cur_stack->stats.rx_allocmbuf_fail++; - return; -@@ -947,7 +947,13 @@ void stack_mempool_size(struct rpc_msg *msg) - { - struct protocol_stack *stack = (struct protocol_stack*)msg->args[MSG_ARG_0].p; - -- msg->result = rte_mempool_avail_count(stack->rxtx_pktmbuf_pool); -+ msg->result = rte_mempool_avail_count(stack->rxtx_mbuf_pool); -+} -+ -+void stack_rpcpool_size(struct rpc_msg *msg) -+{ -+ struct rpc_msg_pool *rpc_mem_pool = (struct rpc_msg_pool*)msg->args[MSG_ARG_0].p; -+ msg->result = rte_mempool_avail_count(rpc_mem_pool->mempool); - } - - void stack_create_shadow_fd(struct rpc_msg *msg) -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 3fd5903..45237b0 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -179,12 +179,15 @@ static void get_stack_stats(struct gazelle_stack_dfx_data *dfx, struct protocol_ - int32_t rpc_call_result = rpc_call_msgcnt(stack); - dfx->data.pkts.call_msg_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; - -- rpc_call_result = rpc_call_mempoolsize(stack); -- dfx->data.pkts.mempool_freecnt = (rpc_call_result < 0) ? 0 : rpc_call_result; -+ rpc_call_result = rpc_call_mbufpoolsize(stack); -+ dfx->data.pkts.mbufpool_avail_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; - - rpc_call_result = rpc_call_recvlistcnt(stack); - dfx->data.pkts.recv_list_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; - -+ rpc_call_result = rpc_call_rpcpool_size(stack); -+ dfx->data.pkts.rpcpool_avail_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; -+ - dfx->data.pkts.conn_num = stack->conn_num; - } - -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 4dc3da3..473e908 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -29,7 +29,7 @@ static inline __attribute__((always_inline)) struct rpc_msg *get_rpc_msg(struct - { - int ret; - struct rpc_msg *msg = NULL; -- ret = rte_mempool_get(rpc_pool->rpc_pool, (void **)&msg); -+ ret = rte_mempool_get(rpc_pool->mempool, (void **)&msg); - if (ret < 0) { - LSTACK_LOG(INFO, LSTACK, "rpc pool empty!\n"); - errno = ENOMEM; -@@ -54,9 +54,9 @@ static struct rpc_msg *rpc_msg_alloc(struct protocol_stack *stack, rpc_msg_func - return NULL; - } - -- g_rpc_pool->rpc_pool = create_mempool("rpc_pool", RPC_MSG_MAX, sizeof(struct rpc_msg), -+ g_rpc_pool->mempool = create_mempool("rpc_pool", RPC_MSG_MAX, sizeof(struct rpc_msg), - 0, rte_gettid()); -- if (g_rpc_pool->rpc_pool == NULL) { -+ if (g_rpc_pool->mempool == NULL) { - get_protocol_stack_group()->call_alloc_fail++; - return NULL; - } -@@ -67,7 +67,7 @@ static struct rpc_msg *rpc_msg_alloc(struct protocol_stack *stack, rpc_msg_func - get_protocol_stack_group()->call_alloc_fail++; - return NULL; - } -- msg->pool = g_rpc_pool; -+ msg->rpcpool = g_rpc_pool; - - pthread_spin_init(&msg->lock, PTHREAD_PROCESS_PRIVATE); - msg->func = func; -@@ -194,7 +194,7 @@ int32_t rpc_call_thread_regphase2(struct protocol_stack *stack, void *conn) - return rpc_sync_call(&stack->rpc_queue, msg); - } - --int32_t rpc_call_mempoolsize(struct protocol_stack *stack) -+int32_t rpc_call_mbufpoolsize(struct protocol_stack *stack) - { - struct rpc_msg *msg = rpc_msg_alloc(stack, stack_mempool_size); - if (msg == NULL) { -@@ -206,6 +206,16 @@ int32_t rpc_call_mempoolsize(struct protocol_stack *stack) - return rpc_sync_call(&stack->rpc_queue, msg); - } - -+int32_t rpc_call_rpcpool_size(struct protocol_stack *stack) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(stack, stack_rpcpool_size); -+ if (msg == NULL) { -+ return -1; -+ } -+ msg->args[MSG_ARG_0].p = g_rpc_pool; -+ return rpc_sync_call(&stack->rpc_queue, msg); -+} -+ - int32_t rpc_call_recvlistcnt(struct protocol_stack *stack) - { - struct rpc_msg *msg = rpc_msg_alloc(stack, stack_recvlist_count); -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index e339b8d..6638984 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -31,6 +31,8 @@ - #define SOCK_SEND_REPLENISH_THRES (16) - #define WAKEUP_MAX_NUM (32) - -+#define MBUFPOOL_RESERVE_NUM 5000 -+ - struct rte_mempool; - struct rte_ring; - struct rte_mbuf; -@@ -45,7 +47,7 @@ struct protocol_stack { - cpu_set_t idle_cpuset; /* idle cpu in numa of stack, app thread bind to it */ - int32_t epollfd; /* kernel event thread epoll fd */ - -- struct rte_mempool *rxtx_pktmbuf_pool; -+ struct rte_mempool *rxtx_mbuf_pool; - struct rte_ring *rx_ring; - struct rte_ring *tx_ring; - struct rte_ring *reg_ring; -@@ -168,6 +170,7 @@ void stack_fcntl(struct rpc_msg *msg); - void stack_ioctl(struct rpc_msg *msg); - void stack_send(struct rpc_msg *msg); - void stack_mempool_size(struct rpc_msg *msg); -+void stack_rpcpool_size(struct rpc_msg *msg); - void stack_create_shadow_fd(struct rpc_msg *msg); - void stack_replenish_sendring(struct rpc_msg *msg); - void stack_get_conntable(struct rpc_msg *msg); -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 13f5ec2..ca8a510 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -26,7 +26,7 @@ - #define MSG_ARG_4 (4) - #define RPM_MSG_ARG_SIZE (5) - --#define RPC_MSG_MAX 2048 -+#define RPC_MSG_MAX 4096 - #define RPC_MSG_MASK (RPC_MSG_MAX - 1) - - struct rpc_msg; -@@ -48,14 +48,14 @@ struct rpc_msg { - int8_t recall_flag : 1; - int64_t result; /* func return val */ - lockless_queue_node queue_node; -- struct rpc_msg_pool *pool; -+ struct rpc_msg_pool *rpcpool; - - rpc_msg_func func; /* msg handle func hook */ - union rpc_msg_arg args[RPM_MSG_ARG_SIZE]; /* resolve by type */ - }; - - struct rpc_msg_pool { -- struct rte_mempool *rpc_pool; -+ struct rte_mempool *mempool; - }; - - struct protocol_stack; -@@ -87,7 +87,8 @@ int32_t rpc_call_setsockopt(int fd, int level, int optname, const void *optval, - int32_t rpc_call_fcntl(int fd, int cmd, long val); - int32_t rpc_call_ioctl(int fd, long cmd, void *argp); - int32_t rpc_call_replenish(struct protocol_stack *stack, struct lwip_sock *sock); --int32_t rpc_call_mempoolsize(struct protocol_stack *stack); -+int32_t rpc_call_mbufpoolsize(struct protocol_stack *stack); -+int32_t rpc_call_rpcpool_size(struct protocol_stack *stack); - - static inline __attribute__((always_inline)) void rpc_call(lockless_queue *queue, struct rpc_msg *msg) - { -@@ -97,7 +98,7 @@ static inline __attribute__((always_inline)) void rpc_call(lockless_queue *queue - static inline __attribute__((always_inline)) void rpc_msg_free(struct rpc_msg *msg) - { - pthread_spin_destroy(&msg->lock); -- rte_mempool_put(msg->pool->rpc_pool, (void *)msg); -+ rte_mempool_put(msg->rpcpool->mempool, (void *)msg); - } - - #endif -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 31856f2..2e11670 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -542,9 +542,9 @@ void parse_arp_and_transefer(char* buf) - int32_t ret; - for (int32_t i = 0; i < stack_group->stack_num; i++) { - stack = stack_group->stacks[i]; -- ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1); - while (ret != 0) { -- ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1); - stack->stats.rx_allocmbuf_fail++; - } - copy_mbuf(mbuf_copy, mbuf); -@@ -571,9 +571,9 @@ void parse_tcp_and_transefer(char* buf) - struct rte_mbuf *mbuf_copy = NULL; - struct protocol_stack *stack = stack_group->stacks[stk_index]; - -- int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1); - while (ret != 0) { -- ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1); - stack->stats.rx_allocmbuf_fail++; - } - -@@ -944,7 +944,7 @@ int32_t ethdev_init(struct protocol_stack *stack) - - if (use_ltran()) { - stack->rx_ring_used = 0; -- int32_t ret = fill_mbuf_to_ring(stack->rxtx_pktmbuf_pool, stack->rx_ring, RING_SIZE(VDEV_RX_QUEUE_SZ)); -+ int32_t ret = fill_mbuf_to_ring(stack->rxtx_mbuf_pool, stack->rx_ring, RING_SIZE(VDEV_RX_QUEUE_SZ)); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "fill mbuf to rx_ring failed ret=%d\n", ret); - return ret; -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index e1438da..ccf664a 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -57,7 +57,7 @@ static uint32_t ltran_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pk - stack->rx_ring_used += rcvd_pkts; - if (unlikely(stack->rx_ring_used >= USED_RX_PKTS_WATERMARK)) { - uint32_t free_cnt = LWIP_MIN(stack->rx_ring_used, RING_SIZE(DPDK_PKT_BURST_SIZE)); -- int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_pktmbuf_pool, (struct rte_mbuf **)free_buf, free_cnt); -+ int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)free_buf, free_cnt); - if (likely(ret == 0)) { - nr_pkts = gazelle_ring_sp_enqueue(stack->rx_ring, (void **)free_buf, free_cnt); - stack->rx_ring_used -= nr_pkts; -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index d3ff527..58ab14c 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -618,7 +618,8 @@ static void show_lstack_stats(struct gazelle_stack_dfx_data *lstack_stat) - printf("call_alloc_fail: %-12"PRIu64" ", lstack_stat->data.pkts.call_alloc_fail); - printf("call_null: %-18"PRIu64" \n", lstack_stat->data.pkts.stack_stat.call_null); - printf("send_pkts_fail: %-13"PRIu64" ", lstack_stat->data.pkts.stack_stat.send_pkts_fail); -- printf("mempool_freecnt: %-12"PRIu32" \n", lstack_stat->data.pkts.mempool_freecnt); -+ printf("mbuf_pool_freecnt: %-10"PRIu32" ", lstack_stat->data.pkts.mbufpool_avail_cnt); -+ printf("rpc_pool_freecnt: %-12"PRIu32" \n", lstack_stat->data.pkts.rpcpool_avail_cnt); - } - - static void gazelle_print_lstack_stat_detail(struct gazelle_stack_dfx_data *lstack_stat, --- -2.27.0 - diff --git a/0073-dfx-gazellectl-c-support-ipv6.patch b/0073-dfx-gazellectl-c-support-ipv6.patch deleted file mode 100644 index 3f2a9d61bf414c39be43226ff72449498c2903f1..0000000000000000000000000000000000000000 --- a/0073-dfx-gazellectl-c-support-ipv6.patch +++ /dev/null @@ -1,181 +0,0 @@ -From 61bf27272a56a426909a809a8a20dcf4220a3273 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Wed, 29 Nov 2023 11:10:51 +0800 -Subject: [PATCH] dfx: gazellectl -c support ipv6 -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - - 日期: Thu Dec 7 14:28:51 2023 +0800 ---- - src/common/gazelle_dfx_msg.h | 6 ++-- - src/common/gazelle_opt.h | 4 +++ - src/lstack/core/lstack_control_plane.c | 4 +-- - src/lstack/core/lstack_lwip.c | 8 +++--- - src/ltran/ltran_dfx.c | 39 ++++++++++++++++---------- - 5 files changed, 38 insertions(+), 23 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index ac6ea5e..698846f 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -16,6 +16,8 @@ - #include - #include - -+#include -+ - #define GAZELLE_CLIENT_NUM_MIN 1 - #define GAZELLE_LOG_LEVEL_MAX 10 - #define GAZELLECTL_TIMEOUT 5000 // millisecond -@@ -170,8 +172,8 @@ struct gazelle_stat_lstack_snmp { - /* same as define in lwip/tcp.h - struct tcp_pcb_dp */ - struct gazelle_stat_lstack_conn_info { - uint32_t state; -- uint32_t rip; -- uint32_t lip; -+ gz_addr_t rip; -+ gz_addr_t lip; - uint16_t r_port; - uint16_t l_port; - uint32_t in_send; -diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h -index 7316fc6..bb540f4 100644 ---- a/src/common/gazelle_opt.h -+++ b/src/common/gazelle_opt.h -@@ -52,6 +52,10 @@ - #define STACK_THREAD_DEFAULT 4 - #define STACK_NIC_READ_DEFAULT 128 - -+/* same as define in lwip/ip_addr.h */ -+#define GZ_ADDR_TYPE_V4 0 -+#define GZ_ADDR_TYPE_V6 6 -+ - #define MTU_DEFAULT_DATA_LEN 1460 - #define VLAN_HEAD_LEN 4 - #define IPV6_EXTRA_HEAD_LEN 20 -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 4633834..e7fcd26 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -361,9 +361,9 @@ static int32_t reg_conn(enum tcp_list_state table_state, enum reg_ring_type reg_ - continue; - } - qtuple.protocol = 0; -- qtuple.src_ip = conn->conn_list[i].lip; -+ qtuple.src_ip = conn->conn_list[i].lip.u_addr.ip4.addr; - qtuple.src_port = lwip_htons(conn->conn_list[i].l_port); -- qtuple.dst_ip = conn->conn_list[i].rip; -+ qtuple.dst_ip = conn->conn_list[i].rip.u_addr.ip4.addr; - qtuple.dst_port = lwip_htons(conn->conn_list[i].r_port); - - if ((table_state == LISTEN_LIST) && (!match_host_addr(qtuple.src_ip))) { -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index af9bf73..5a3b703 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -1135,8 +1135,8 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - { - struct netconn *netconn = (struct netconn *)pcb->callback_arg; - -- conn->lip = ip_2_ip4(&pcb->local_ip)->addr; -- conn->rip = ip_2_ip4(&pcb->remote_ip)->addr; -+ conn->lip = *((gz_addr_t *)&pcb->local_ip); -+ conn->rip = *((gz_addr_t *)&pcb->remote_ip); - conn->l_port = pcb->local_port; - conn->r_port = pcb->remote_port; - conn->in_send = pcb->snd_queuelen; -@@ -1229,11 +1229,11 @@ uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, - for (struct tcp_pcb_listen *pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL && conn_num < max_num; - pcbl = pcbl->next) { - conn[conn_num].state = LISTEN_LIST; -- conn[conn_num].lip = ip_2_ip4(&pcbl->local_ip)->addr; -+ conn[conn_num].lip = *((gz_addr_t *)&pcbl->local_ip); - conn[conn_num].l_port = pcbl->local_port; - conn[conn_num].tcp_sub_state = pcbl->state; - struct netconn *netconn = (struct netconn *)pcbl->callback_arg; -- conn[conn_num].fd = netconn != NULL ? netconn->socket : -1; -+ conn[conn_num].fd = netconn != NULL ? netconn->socket : -1; - if (netconn != NULL && netconn->acceptmbox != NULL) { - conn[conn_num].recv_cnt = rte_ring_count(netconn->acceptmbox->ring); - } -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index d3ff527..273eeaa 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -233,6 +233,7 @@ static int32_t dfx_connect_ltran(bool use_ltran, bool probe) - strlen(GAZELLE_DFX_SOCK_FILENAME) + 1); - if (ret != EOK) { - printf("%s:%d strncat_s fail ret=%d\n", __FUNCTION__, __LINE__, ret); -+ goto END; - } - } else { - ret = strncat_s(addr.sun_path, sizeof(addr.sun_path), GAZELLE_REG_SOCK_FILENAME, -@@ -973,10 +974,11 @@ static void gazelle_print_lstack_stat_snmp(void *buf, const struct gazelle_stat_ - static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_msg_request *req_msg) - { - uint32_t i; -- struct in_addr rip; -- struct in_addr lip; -- char str_ip[GAZELLE_SUBNET_LENGTH_MAX] = {0}; -- char str_rip[GAZELLE_SUBNET_LENGTH_MAX] = {0}; -+ char str_ip[INET6_ADDRSTRLEN] = {0}; -+ char str_rip[INET6_ADDRSTRLEN] = {0}; -+ /* ip:port, 6 is the length reserved for port */ -+ char str_laddr[INET6_ADDRSTRLEN + 6] = {0}; -+ char str_raddr[INET6_ADDRSTRLEN + 6] = {0}; - struct gazelle_stack_dfx_data *stat = (struct gazelle_stack_dfx_data *)buf; - struct gazelle_stat_lstack_conn *conn = &stat->data.conn; - struct timeval time = {0}; -@@ -986,30 +988,37 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - do { - printf("\n------ stack tid: %6u ------time=%lu\n", stat->tid, time.tv_sec * 1000000 + time.tv_usec); - printf("No. Proto lwip_recv recv_ring in_send send_ring cwn rcv_wnd snd_wnd snd_buf snd_nxt" -- " lastack rcv_nxt events epoll_ev evlist fd Local Address " -- "Foreign Address State\n"); -+ " lastack rcv_nxt events epoll_ev evlist fd Local Address" -+ " Foreign Address State\n"); - uint32_t unread_pkts = 0; - uint32_t unsend_pkts = 0; - for (i = 0; i < conn->conn_num && i < GAZELLE_LSTACK_MAX_CONN; i++) { - struct gazelle_stat_lstack_conn_info *conn_info = &conn->conn_list[i]; - -- rip.s_addr = conn_info->rip; -- lip.s_addr = conn_info->lip; -+ uint32_t domain = conn_info->lip.type == GZ_ADDR_TYPE_V4 ? AF_INET : AF_INET6; -+ void *lip = (void *)&conn_info->lip; -+ void *rip = (void *)&conn_info->rip; -+ - if ((conn_info->state == GAZELLE_ACTIVE_LIST) || (conn_info->state == GAZELLE_TIME_WAIT_LIST)) { -+ inet_ntop(domain, lip, str_ip, sizeof(str_ip)); -+ inet_ntop(domain, rip, str_rip, sizeof(str_rip)); -+ sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port); -+ sprintf_s(str_raddr, sizeof(str_raddr), "%s:%hu", str_rip, conn_info->r_port); - printf("%-6utcp %-10u%-10u%-8u%-10u%-9d%-9d%-10d%-10d%-15u%-15u%-15u%-10x%-10x%-7d%-7d" -- "%s:%hu %s:%hu %s\n", i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send, -+ "%-52s %-52s %s\n", i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send, - conn_info->send_ring_cnt, conn_info->cwn, conn_info->rcv_wnd, conn_info->snd_wnd, - conn_info->snd_buf, conn_info->snd_nxt, conn_info->lastack, conn_info->rcv_nxt, conn_info->events, - conn_info->epoll_events, conn_info->eventlist, conn_info->fd, -- inet_ntop(AF_INET, &lip, str_ip, sizeof(str_ip)), conn_info->l_port, -- inet_ntop(AF_INET, &rip, str_rip, sizeof(str_rip)), conn_info->r_port, -- tcp_state_to_str(conn_info->tcp_sub_state)); -+ str_laddr, str_raddr, tcp_state_to_str(conn_info->tcp_sub_state)); - } else if (conn_info->state == GAZELLE_LISTEN_LIST) { -- printf("%-6utcp %-147u%-7d%s:%hu 0.0.0.0:* LISTEN\n", i, conn_info->recv_cnt, -- conn_info->fd, inet_ntop(AF_INET, &lip, str_ip, sizeof(str_ip)), conn_info->l_port); -+ inet_ntop(domain, lip, str_ip, sizeof(str_ip)); -+ sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port); -+ sprintf_s(str_raddr, sizeof(str_raddr), "%s:*", domain == AF_INET ? "0.0.0.0" : "::0"); -+ printf("%-6utcp %-147u%-7d%-52s %-52s LISTEN\n", i, conn_info->recv_cnt, -+ conn_info->fd, str_laddr, str_raddr); - } else { - printf("Got unknow tcp conn::%s:%5hu, state:%u\n", -- inet_ntop(AF_INET, &lip, str_ip, sizeof(str_ip)), conn_info->l_port, conn_info->state); -+ inet_ntop(domain, lip, str_ip, sizeof(str_ip)), conn_info->l_port, conn_info->state); - } - unread_pkts += conn_info->recv_ring_cnt + conn_info->recv_cnt; - unsend_pkts += conn_info->send_ring_cnt + conn_info->in_send; --- -2.27.0 - diff --git a/0074-The-call-stack-is-not-printed-in-the-proactive-exit-.patch b/0074-The-call-stack-is-not-printed-in-the-proactive-exit-.patch deleted file mode 100644 index 1f823ee4f0dc79ec6e192a42da38921f3df83452..0000000000000000000000000000000000000000 --- a/0074-The-call-stack-is-not-printed-in-the-proactive-exit-.patch +++ /dev/null @@ -1,28 +0,0 @@ -From ef311f5a6c9d9c3578db836d68a3ad15727bdc15 Mon Sep 17 00:00:00 2001 -From: wuchangye -Date: Thu, 7 Dec 2023 14:17:49 +0800 -Subject: [PATCH] The call stack is not printed in the proactive exit scenario. - ---- - src/lstack/api/lstack_signal.c | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/api/lstack_signal.c b/src/lstack/api/lstack_signal.c -index 03118f5..285aaf3 100644 ---- a/src/lstack/api/lstack_signal.c -+++ b/src/lstack/api/lstack_signal.c -@@ -64,7 +64,10 @@ static void lstack_sig_default_handler(int sig) - dpdk_kni_release(); - } - control_fd_close(); -- dump_stack(); -+ /* 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(); -+ } - lwip_exit(); - (void)kill(getpid(), sig); - } --- -2.27.0 - diff --git a/0075-dfx-fix-gazellectl-lstack-show-ip-failed.patch b/0075-dfx-fix-gazellectl-lstack-show-ip-failed.patch deleted file mode 100644 index 4aac242476ca121028ce687477dc53d6e5651062..0000000000000000000000000000000000000000 --- a/0075-dfx-fix-gazellectl-lstack-show-ip-failed.patch +++ /dev/null @@ -1,69 +0,0 @@ -From f2080c02b864d6ce7f07b874e489bb5ea98b837a Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 6 Dec 2023 20:33:13 +0800 -Subject: [PATCH] dfx: fix 'gazellectl lstack show ip' failed - ---- - src/common/gazelle_dfx_msg.h | 3 ++- - src/ltran/ltran_dfx.c | 7 +++++-- - src/ltran/ltran_monitor.c | 2 +- - 3 files changed, 8 insertions(+), 4 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index ac6ea5e..d2c6ef9 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -35,9 +35,10 @@ enum GAZELLE_STAT_MODE { - GAZELLE_STAT_LTRAN_LOG_LEVEL_SET, - GAZELLE_STAT_LTRAN_SHOW_SOCKTABLE, - GAZELLE_STAT_LTRAN_SHOW_CONNTABLE, -+ GAZELLE_STAT_LTRAN_SHOW_LSTACK, - -- GAZELLE_STAT_LSTACK_LOG_LEVEL_SET, - GAZELLE_STAT_LSTACK_SHOW, -+ GAZELLE_STAT_LSTACK_LOG_LEVEL_SET, - GAZELLE_STAT_LSTACK_SHOW_RATE, - GAZELLE_STAT_LSTACK_SHOW_SNMP, - GAZELLE_STAT_LSTACK_SHOW_CONN, -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index d3ff527..c200b1d 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -105,8 +105,11 @@ static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = { - {GAZELLE_STAT_LTRAN_LOG_LEVEL_SET, 0, gazelle_print_ltran_wait}, - {GAZELLE_STAT_LTRAN_SHOW_SOCKTABLE, sizeof(struct gazelle_stat_forward_table), gazelle_print_ltran_sock}, - {GAZELLE_STAT_LTRAN_SHOW_CONNTABLE, sizeof(struct gazelle_stat_forward_table), gazelle_print_ltran_conn}, -+ -+ {GAZELLE_STAT_LTRAN_SHOW_LSTACK, sizeof(struct gazelle_stat_lstack_total), gazelle_print_lstack_stat_total}, -+ {GAZELLE_STAT_LSTACK_SHOW, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_total}, -+ - {GAZELLE_STAT_LSTACK_LOG_LEVEL_SET, 0, gazelle_print_ltran_wait}, -- {GAZELLE_STAT_LSTACK_SHOW, sizeof(struct gazelle_stat_lstack_total), gazelle_print_lstack_stat_total}, - {GAZELLE_STAT_LSTACK_SHOW_RATE, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_rate}, - {GAZELLE_STAT_LSTACK_SHOW_SNMP, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_snmp}, - {GAZELLE_STAT_LSTACK_SHOW_CONN, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_conn}, -@@ -1265,7 +1268,7 @@ static int32_t parse_dfx_lstack_show_args(int32_t argc, char *argv[], struct gaz - long int delay = 1; - - if (argc == GAZELLE_LSTACK_PARAM_NUM) { -- req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW; -+ req_msg[cmd_index++].stat_mode = g_use_ltran ? GAZELLE_STAT_LTRAN_SHOW_LSTACK : GAZELLE_STAT_LSTACK_SHOW; - return cmd_index; - } - -diff --git a/src/ltran/ltran_monitor.c b/src/ltran/ltran_monitor.c -index 792db89..b2bcc07 100644 ---- a/src/ltran/ltran_monitor.c -+++ b/src/ltran/ltran_monitor.c -@@ -338,7 +338,7 @@ static int32_t lstack_req_mode_process(int32_t fd, const struct gazelle_stat_msg - case GAZELLE_STAT_LTRAN_SHOW_LB_RATE: - handle_resp_lstack_total(req_msg, fd); - break; -- case GAZELLE_STAT_LSTACK_SHOW: -+ case GAZELLE_STAT_LTRAN_SHOW_LSTACK: - handle_resp_lstack_total(req_msg, fd); - handle_resp_lstack_transfer(req_msg, fd); - break; --- -2.27.0 - diff --git a/0076-gazellectl-add-connect-para.patch b/0076-gazellectl-add-connect-para.patch deleted file mode 100644 index 9e64bbfdaee35fcf6e14e6a73224a126c8e6e1b8..0000000000000000000000000000000000000000 --- a/0076-gazellectl-add-connect-para.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 175f3818dc8ea64b37c4aa804375ef1216601813 Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Thu, 7 Dec 2023 00:38:00 +0800 -Subject: [PATCH] gazellectl add connect para - ---- - src/common/gazelle_dfx_msg.h | 2 ++ - src/lstack/core/lstack_lwip.c | 2 ++ - src/ltran/ltran_dfx.c | 8 +++++--- - 3 files changed, 9 insertions(+), 3 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index e2485ef..f91a661 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -194,6 +194,8 @@ struct gazelle_stat_lstack_conn_info { - uint32_t events; - uint32_t epoll_events; - uint32_t eventlist; -+ uint32_t keepalive; -+ uint32_t keep_idle; - }; - - struct gazelle_stat_lstack_conn { -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 7fb164c..5a719ea 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -1148,6 +1148,8 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - conn->lastack = pcb->lastack; - conn->snd_nxt = pcb->snd_nxt; - conn->rcv_nxt = pcb->rcv_nxt; -+ conn->keepalive = (ip_get_option(pcb, SOF_KEEPALIVE) != 0); -+ conn->keep_idle = pcb->keep_idle; - - if (netconn != NULL && netconn->recvmbox != NULL) { - conn->recv_cnt = rte_ring_count(netconn->recvmbox->ring); -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index b999d20..fcbe857 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -993,7 +993,8 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - printf("\n------ stack tid: %6u ------time=%lu\n", stat->tid, time.tv_sec * 1000000 + time.tv_usec); - printf("No. Proto lwip_recv recv_ring in_send send_ring cwn rcv_wnd snd_wnd snd_buf snd_nxt" - " lastack rcv_nxt events epoll_ev evlist fd Local Address" -- " Foreign Address State\n"); -+ " Foreign Address State" -+ " keep-alive keep-idle\n"); - uint32_t unread_pkts = 0; - uint32_t unsend_pkts = 0; - for (i = 0; i < conn->conn_num && i < GAZELLE_LSTACK_MAX_CONN; i++) { -@@ -1009,11 +1010,12 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port); - sprintf_s(str_raddr, sizeof(str_raddr), "%s:%hu", str_rip, conn_info->r_port); - printf("%-6utcp %-10u%-10u%-8u%-10u%-9d%-9d%-10d%-10d%-15u%-15u%-15u%-10x%-10x%-7d%-7d" -- "%-52s %-52s %s\n", i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send, -+ "%-52s %-52s %s %-5d %-9u\n", i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send, - conn_info->send_ring_cnt, conn_info->cwn, conn_info->rcv_wnd, conn_info->snd_wnd, - conn_info->snd_buf, conn_info->snd_nxt, conn_info->lastack, conn_info->rcv_nxt, conn_info->events, - conn_info->epoll_events, conn_info->eventlist, conn_info->fd, -- str_laddr, str_raddr, tcp_state_to_str(conn_info->tcp_sub_state)); -+ str_laddr, str_raddr, tcp_state_to_str(conn_info->tcp_sub_state), -+ conn_info->keepalive, conn_info->keep_idle); - } else if (conn_info->state == GAZELLE_LISTEN_LIST) { - inet_ntop(domain, lip, str_ip, sizeof(str_ip)); - sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port); --- -2.27.0 - diff --git a/0077-log-optimize-lstack-log.patch b/0077-log-optimize-lstack-log.patch deleted file mode 100644 index 6c2c0b3748bf204be799147093bc8fd84c783c8b..0000000000000000000000000000000000000000 --- a/0077-log-optimize-lstack-log.patch +++ /dev/null @@ -1,51 +0,0 @@ -From 10db670bcca6be723361e710625452c42249002a Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Sat, 9 Dec 2023 22:31:02 +0800 -Subject: [PATCH] add - ---- - src/common/gazelle_reg_msg.h | 2 +- - src/lstack/core/lstack_lwip.c | 1 - - src/lstack/core/lstack_thread_rpc.c | 1 - - 3 files changed, 1 insertion(+), 3 deletions(-) - -diff --git a/src/common/gazelle_reg_msg.h b/src/common/gazelle_reg_msg.h -index a944d80..d849cea 100644 ---- a/src/common/gazelle_reg_msg.h -+++ b/src/common/gazelle_reg_msg.h -@@ -22,7 +22,7 @@ - - #define GAZELLE_MAX_REG_ARGS 32 - --#define ENQUEUE_RING_RETRY_TIMEOUT 500 // ms -+#define ENQUEUE_RING_RETRY_TIMEOUT 10 // ms - - #define OPT_BASE_VIRTADDR "--base-virtaddr" - #define OPT_FILE_PREFIX "--file-prefix" -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 5a719ea..026c870 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -797,7 +797,6 @@ static inline void notice_stack_send(struct lwip_sock *sock, int32_t fd, int32_t - if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) < 2) { - while (rpc_call_send(fd, NULL, len, flags) < 0) { - usleep(1000); // 1000: wait 1ms to exec again -- LSTACK_LOG(INFO, LSTACK, "rpc_call_send failed, try again\n"); - } - __sync_fetch_and_add(&sock->call_num, 1); - } -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 473e908..4aceee6 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -31,7 +31,6 @@ static inline __attribute__((always_inline)) struct rpc_msg *get_rpc_msg(struct - struct rpc_msg *msg = NULL; - ret = rte_mempool_get(rpc_pool->mempool, (void **)&msg); - if (ret < 0) { -- LSTACK_LOG(INFO, LSTACK, "rpc pool empty!\n"); - errno = ENOMEM; - return NULL; - } --- -2.27.0 - diff --git a/0078-support-show-nic-offload-and-features.patch b/0078-support-show-nic-offload-and-features.patch deleted file mode 100644 index 462b652f2df52b58ea80072ee43e12565501caca..0000000000000000000000000000000000000000 --- a/0078-support-show-nic-offload-and-features.patch +++ /dev/null @@ -1,209 +0,0 @@ -From e38f829d0c2f0e46b4c026044ed69ebbb4d2821d Mon Sep 17 00:00:00 2001 -From: wuchangye -Date: Fri, 8 Dec 2023 01:23:14 +0800 -Subject: [PATCH] support show nic offload and features - ---- - src/common/gazelle_dfx_msg.h | 8 ++++++++ - src/lstack/Makefile | 4 ++-- - src/lstack/core/lstack_control_plane.c | 3 ++- - src/lstack/core/lstack_dpdk.c | 17 +++++++++++++++++ - src/lstack/core/lstack_stack_stat.c | 10 +++++++--- - src/lstack/include/lstack_dpdk.h | 1 + - src/ltran/ltran_dfx.c | 23 +++++++++++++++++++++++ - 8 files changed, 61 insertions(+), 6 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index e2485ef..04fe996 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -48,6 +48,7 @@ enum GAZELLE_STAT_MODE { - GAZELLE_STAT_LSTACK_LOW_POWER_MDF, - GAZELLE_STAT_LSTACK_SHOW_XSTATS, - GAZELLE_STAT_LSTACK_SHOW_AGGREGATE, -+ GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES, - - GAZELLE_STAT_MODE_MAX, - }; -@@ -236,6 +237,12 @@ struct nic_eth_xstats { - uint16_t port_id; - }; - -+struct nic_eth_features { -+ uint16_t port_id; -+ uint64_t rx_offload; -+ uint64_t tx_offload; -+}; -+ - struct gazelle_stack_dfx_data { - /* indicates whether the current message is the last */ - uint32_t eof; -@@ -250,6 +257,7 @@ struct gazelle_stack_dfx_data { - struct gazelle_stat_lstack_conn conn; - struct gazelle_stat_lstack_snmp snmp; - struct nic_eth_xstats nic_xstats; -+ struct nic_eth_features nic_features; - } data; - }; - -diff --git a/src/lstack/Makefile b/src/lstack/Makefile -index 30965f8..d585040 100644 ---- a/src/lstack/Makefile -+++ b/src/lstack/Makefile -@@ -29,9 +29,9 @@ LDFLAGS = -shared -ldl -lm -lpthread -lrt -lnuma -lconfig -lboundscheck - ARCH := $(shell uname -m) - - ifneq ($(CC),clang) -- SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro, -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIFY_SOURCE=2 -+ SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wno-deprecated-declarations -Wl,-z,relro, -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIFY_SOURCE=2 - else -- SEC_FLAGS = -fstack-protector-strong -Werror -Wall -fPIC -+ SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wno-deprecated-declarations -fPIC - endif - $(info $(CC):$(SEC_FLAGS)) - -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index e7fcd26..668ff80 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -586,7 +586,8 @@ static int32_t handle_stat_request(int32_t sockfd) - if (msg.stat_mode == GAZELLE_STAT_LSTACK_LOG_LEVEL_SET || - msg.stat_mode == GAZELLE_STAT_LSTACK_LOW_POWER_MDF) { - return handle_proc_cmd(sockfd, &msg); -- } else if (msg.stat_mode == GAZELLE_STAT_LSTACK_SHOW_XSTATS) { -+ } else if (msg.stat_mode == GAZELLE_STAT_LSTACK_SHOW_XSTATS || -+ msg.stat_mode == GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES) { - return handle_dpdk_cmd(sockfd, msg.stat_mode); - } else { - ret = handle_stack_cmd(sockfd, msg.stat_mode); -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 5eff915..936fd89 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -881,3 +881,20 @@ void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id) - } - dfx->data.nic_xstats.len = len; - } -+ -+void dpdk_nic_features_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id) -+{ -+ int ret; -+ struct rte_eth_conf dev_conf; -+ -+ ret = rte_eth_dev_conf_get(port_id, &dev_conf); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_dev_conf_get failed:%d.\n", ret); -+ return; -+ } -+ -+ dfx->data.nic_features.port_id = port_id; -+ dfx->data.nic_features.tx_offload = dev_conf.txmode.offloads; -+ dfx->data.nic_features.rx_offload = dev_conf.rxmode.offloads; -+ return; -+} -\ No newline at end of file -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 45237b0..2d85efa 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -265,11 +265,15 @@ int handle_dpdk_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode) - - if (stat_mode == GAZELLE_STAT_LSTACK_SHOW_XSTATS) { - dpdk_nic_xstats_get(&dfx, get_protocol_stack_group()->port_id); -- dfx.tid = 0; -- dfx.eof = 1; -- send_control_cmd_data(fd, &dfx); -+ } else if (stat_mode == GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES) { -+ dpdk_nic_features_get(&dfx, get_protocol_stack_group()->port_id); -+ } else { -+ return 0; - } - -+ dfx.tid = 0; -+ dfx.eof = 1; -+ send_control_cmd_data(fd, &dfx); - return 0; - } - -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index 724ab24..05f5bc6 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -60,4 +60,5 @@ struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, - - void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id); - int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num); -+void dpdk_nic_features_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id); - #endif /* GAZELLE_DPDK_H */ -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index b999d20..dfcdc0c 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -24,6 +24,7 @@ - #include - #include - #include -+#include - - #include "ltran_stat.h" - #include "ltran_base.h" -@@ -91,6 +92,7 @@ static void gazelle_print_ltran_sock(void *buf, const struct gazelle_stat_msg_re - static void gazelle_print_ltran_conn(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_xstats(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_aggregate(void *buf, const struct gazelle_stat_msg_request *req_msg); -+static void gazelle_print_lstack_nic_features(void *buf, const struct gazelle_stat_msg_request *req_msg); - - static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = { - {GAZELLE_STAT_LTRAN_SHOW, sizeof(struct gazelle_stat_ltran_total), gazelle_print_ltran_stat_total}, -@@ -117,6 +119,7 @@ static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = { - {GAZELLE_STAT_LSTACK_LOW_POWER_MDF, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_lpm}, - {GAZELLE_STAT_LSTACK_SHOW_XSTATS, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_xstats}, - {GAZELLE_STAT_LSTACK_SHOW_AGGREGATE, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_aggregate}, -+ {GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_nic_features}, - }; - - static int32_t g_wait_reply = 1; -@@ -158,6 +161,23 @@ static void gazelle_print_lstack_xstats(void *buf, const struct gazelle_stat_msg - printf("%s############################\n", nic_stats_border); - } - -+static void gazelle_print_lstack_nic_features(void *buf, const struct gazelle_stat_msg_request *req_msg) -+{ -+ struct nic_eth_features *f = &(((struct gazelle_stack_dfx_data *)buf)->data.nic_features); -+ printf("###### NIC offload and other features for port %-2d #########\n", f->port_id); -+ -+ printf("tx-ipv4-checksum: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "on" : "off"); -+ printf("tx-tcp_checksum: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_TCP_CKSUM) ? "on" : "off"); -+ printf("tx-tcp-tso: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_TCP_TSO) ? "on" : "off"); -+ printf("tx-udp-checksum: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_UDP_CKSUM) ? "on" : "off"); -+ printf("tx-vlan-insert: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_VLAN_INSERT) ? "on" : "off"); -+ -+ printf("rx-ipv4-checksum: %s\n", (f->rx_offload & DEV_RX_OFFLOAD_IPV4_CKSUM) ? "on" : "off"); -+ printf("rx-tcp-checksum: %s\n", (f->rx_offload & DEV_RX_OFFLOAD_TCP_CKSUM) ? "on" : "off"); -+ printf("rx-udp-checksum: %s\n", (f->rx_offload & DEV_RX_OFFLOAD_UDP_CKSUM) ? "on" : "off"); -+ printf("rx-vlan-strip: %s\n", (f->rx_offload & DEV_RX_OFFLOAD_VLAN_STRIP) ? "on" : "off"); -+} -+ - static void gazelle_print_ltran_conn(void *buf, const struct gazelle_stat_msg_request *req_msg) - { - struct gazelle_stat_forward_table *table = (struct gazelle_stat_forward_table *)buf; -@@ -1069,6 +1089,7 @@ static void show_usage(void) - " -c, connect show lstack connect \n" - " -l, latency [time] show lstack latency \n" - " -x, xstats show lstack xstats \n" -+ " -k, nic-features show state of protocol offload and other features \n" - " -a, aggregatin [time] show lstack send/recv aggregation \n" - " set: \n" - " loglevel {error | info | debug} set lstack loglevel \n" -@@ -1316,6 +1337,8 @@ static int32_t parse_dfx_lstack_show_args(int32_t argc, char *argv[], struct gaz - if (parse_delay_arg(argc, argv, delay) != 0) { - return 0; - } -+ } else if (strcmp(param, "-k") == 0 || strcmp(param, "nic-features") == 0) { -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES; - } - - return cmd_index; --- -2.27.0 - diff --git a/0079-Fixed-an-issue-where-no-packet-is-sent-or-received-w.patch b/0079-Fixed-an-issue-where-no-packet-is-sent-or-received-w.patch deleted file mode 100644 index 3ccd97368731c3494aebc95c21eefe22a07051fc..0000000000000000000000000000000000000000 --- a/0079-Fixed-an-issue-where-no-packet-is-sent-or-received-w.patch +++ /dev/null @@ -1,33 +0,0 @@ -From b8f23521a5454ba0b7b1d262dfad8aa59eb328ed Mon Sep 17 00:00:00 2001 -From: wuchangye -Date: Fri, 8 Dec 2023 09:43:43 +0800 -Subject: [PATCH] Fixed an issue where no packet is sent or received when UDP - traffic is sent - ---- - src/lstack/core/lstack_lwip.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 026c870..c4b1ebc 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -443,6 +443,7 @@ static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t l - for (int i = 0; i < write_num; i++) { - pbufs[i]->addr.u_addr.ip4.addr = saddr->sin_addr.s_addr; - pbufs[i]->port = lwip_ntohs((saddr)->sin_port); -+ IP_SET_TYPE(&pbufs[i]->addr, IPADDR_TYPE_V4); - } - } else if (addr->sa_family == AF_INET6) { - struct sockaddr_in6 *saddr = (struct sockaddr_in6 *)addr; -@@ -450,6 +451,7 @@ static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t l - memcpy_s(pbufs[i]->addr.u_addr.ip6.addr, sizeof(pbufs[i]->addr.u_addr.ip6.addr), - saddr->sin6_addr.s6_addr, sizeof(saddr->sin6_addr.s6_addr)); - pbufs[i]->port = lwip_ntohs((saddr)->sin6_port); -+ IP_SET_TYPE(&pbufs[i]->addr, IPADDR_TYPE_V6); - } - } else { - return 0; --- -2.27.0 - diff --git a/0080-fix-example-print-error.patch b/0080-fix-example-print-error.patch deleted file mode 100644 index e19870a28a821621813deb76cf7a6a2440ddf39c..0000000000000000000000000000000000000000 --- a/0080-fix-example-print-error.patch +++ /dev/null @@ -1,46 +0,0 @@ -From 881bf800f35c79f778b1cdb401ad7ff780b010e9 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Wed, 6 Dec 2023 12:23:51 +0800 -Subject: [PATCH] fix example print error - ---- - src/lstack/api/lstack_epoll.c | 7 +------ - src/lstack/api/lstack_wrap.c | 4 ++++ - 2 files changed, 5 insertions(+), 6 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index a2d2a9b..7825bed 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -941,12 +941,7 @@ static nfds_t fds_select2poll(int maxfd, fd_set *readfds, fd_set *writefds, fd_s - - int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeval) - { -- if (maxfd == 0) { -- LSTACK_LOG(ERR, LSTACK, "select maxfd is zero\n"); -- return 0; -- } -- -- if (maxfd < 0 || maxfd > FD_SETSIZE || (readfds == NULL && writefds == NULL && exceptfds == NULL)) { -+ if (maxfd < 0 || maxfd > FD_SETSIZE) { - LSTACK_LOG(ERR, LSTACK, "select input param error, fd num=%d\n", maxfd); - GAZELLE_RETURN(EINVAL); - } -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index abbf8a1..69a1409 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -595,6 +595,10 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct - - static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) - { -+ if ((select_posix_path() == PATH_KERNEL) || !(readfds || writefds || exceptfds) || nfds == 0) { -+ return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); -+ } -+ - return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); - } - --- -2.27.0 - diff --git a/0081-dfx-fix-kernel_events-stat.patch b/0081-dfx-fix-kernel_events-stat.patch deleted file mode 100644 index b924ae3857fba4e5fd31c9c0973c22e8c23d14c7..0000000000000000000000000000000000000000 --- a/0081-dfx-fix-kernel_events-stat.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 3f93ac98b09a3bdb0dc557f9b93a008d809cd5c3 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Sun, 10 Dec 2023 14:55:16 +0800 -Subject: [PATCH] dfx: fix kernel_events stat - ---- - src/lstack/core/lstack_stack_stat.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 2d85efa..e4ccc41 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -136,6 +136,7 @@ static void get_wakeup_stat(struct protocol_stack_group *stack_group, struct pro - struct wakeup_poll *wakeup = container_of(node, struct wakeup_poll, poll_list); - - if (wakeup->bind_stack == stack) { -+ stat->kernel_events += wakeup->stat.kernel_events; - stat->app_events += wakeup->stat.app_events; - stat->read_null += wakeup->stat.read_null; - stat->app_write_cnt += wakeup->stat.app_write_cnt; --- -2.27.0 - diff --git a/0082-add-keep-alive-info.patch b/0082-add-keep-alive-info.patch deleted file mode 100644 index c9cdf07b9bc6fc1408584d2db45269248a090724..0000000000000000000000000000000000000000 --- a/0082-add-keep-alive-info.patch +++ /dev/null @@ -1,111 +0,0 @@ -From 5e6a73b66e0b231237ea3a3bbedfe4dd4d974f45 Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Mon, 11 Dec 2023 05:03:04 +0800 -Subject: [PATCH] add keep-alive info - ---- - src/common/gazelle_dfx_msg.h | 2 ++ - src/lstack/core/lstack_lwip.c | 2 ++ - src/ltran/ltran_dfx.c | 25 ++++++++++++++++++++++--- - 3 files changed, 26 insertions(+), 3 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 3d559c3..478c440 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -197,6 +197,8 @@ struct gazelle_stat_lstack_conn_info { - uint32_t eventlist; - uint32_t keepalive; - uint32_t keep_idle; -+ uint32_t keep_intvl; -+ uint32_t keep_cnt; - }; - - struct gazelle_stat_lstack_conn { -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index c4b1ebc..cbb771f 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -1151,6 +1151,8 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - conn->rcv_nxt = pcb->rcv_nxt; - conn->keepalive = (ip_get_option(pcb, SOF_KEEPALIVE) != 0); - conn->keep_idle = pcb->keep_idle; -+ conn->keep_intvl = pcb->keep_intvl; -+ conn->keep_cnt = pcb->keep_cnt; - - if (netconn != NULL && netconn->recvmbox != NULL) { - conn->recv_cnt = rte_ring_count(netconn->recvmbox->ring); -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index ebe1323..2a84cb8 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -52,6 +52,7 @@ - #define GAZELLE_MAX_LATENCY_TIME 1800 // max latency time 30mins - - #define GAZELLE_DECIMAL 10 -+#define GAZELLE_KEEPALIVE_STR_LEN 35 - - static int32_t g_unix_fd = -1; - static int32_t g_ltran_rate_show_flag = GAZELLE_OFF; // not show when first get total statistics -@@ -995,6 +996,20 @@ static void gazelle_print_lstack_stat_snmp(void *buf, const struct gazelle_stat_ - } while (true); - } - -+static void gazelle_keepalive_string(char* str, int buff_len, struct gazelle_stat_lstack_conn_info *conn_info) -+{ -+ if (conn_info->keepalive == 0) { -+ return; -+ } -+ int ret = sprintf_s(str, buff_len - 1, "(%u,%u,%u)", conn_info->keep_idle, conn_info->keep_intvl, -+ conn_info->keep_cnt); -+ if (ret < 0) { -+ printf("gazelle_keepalive_string sprintf_s fail ret=%d\n", ret); -+ return; -+ } -+ str[strlen(str)] = '\0'; -+} -+ - static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_msg_request *req_msg) - { - uint32_t i; -@@ -1007,6 +1022,7 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - struct gazelle_stat_lstack_conn *conn = &stat->data.conn; - struct timeval time = {0}; - gettimeofday(&time, NULL); -+ char keepalive_info_str[GAZELLE_KEEPALIVE_STR_LEN] = {0}; - - printf("Active Internet connections (servers and established)\n"); - do { -@@ -1014,7 +1030,7 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - printf("No. Proto lwip_recv recv_ring in_send send_ring cwn rcv_wnd snd_wnd snd_buf snd_nxt" - " lastack rcv_nxt events epoll_ev evlist fd Local Address" - " Foreign Address State" -- " keep-alive keep-idle\n"); -+ " keep-alive keep-alive(idle,intvl,cnt)\n"); - uint32_t unread_pkts = 0; - uint32_t unsend_pkts = 0; - for (i = 0; i < conn->conn_num && i < GAZELLE_LSTACK_MAX_CONN; i++) { -@@ -1027,15 +1043,18 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - if ((conn_info->state == GAZELLE_ACTIVE_LIST) || (conn_info->state == GAZELLE_TIME_WAIT_LIST)) { - inet_ntop(domain, lip, str_ip, sizeof(str_ip)); - inet_ntop(domain, rip, str_rip, sizeof(str_rip)); -+ -+ gazelle_keepalive_string(keepalive_info_str, sizeof(keepalive_info_str)/sizeof(char), conn_info); -+ - sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port); - sprintf_s(str_raddr, sizeof(str_raddr), "%s:%hu", str_rip, conn_info->r_port); - printf("%-6utcp %-10u%-10u%-8u%-10u%-9d%-9d%-10d%-10d%-15u%-15u%-15u%-10x%-10x%-7d%-7d" -- "%-52s %-52s %s %-5d %-9u\n", i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send, -+ "%-52s %-52s %s %-5d %s\n", i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send, - conn_info->send_ring_cnt, conn_info->cwn, conn_info->rcv_wnd, conn_info->snd_wnd, - conn_info->snd_buf, conn_info->snd_nxt, conn_info->lastack, conn_info->rcv_nxt, conn_info->events, - conn_info->epoll_events, conn_info->eventlist, conn_info->fd, - str_laddr, str_raddr, tcp_state_to_str(conn_info->tcp_sub_state), -- conn_info->keepalive, conn_info->keep_idle); -+ conn_info->keepalive, keepalive_info_str); - } else if (conn_info->state == GAZELLE_LISTEN_LIST) { - inet_ntop(domain, lip, str_ip, sizeof(str_ip)); - sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port); --- -2.27.0 - diff --git a/0083-fix-close-can-t-exit.patch b/0083-fix-close-can-t-exit.patch deleted file mode 100644 index 9bf3399c88b536e7cb3af050eb99b37d404df666..0000000000000000000000000000000000000000 --- a/0083-fix-close-can-t-exit.patch +++ /dev/null @@ -1,137 +0,0 @@ -From f4abd3b3fd5004405cb186981b93f5d40e4648db Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sun, 10 Dec 2023 17:47:56 +0800 -Subject: [PATCH] fix close can't exit - ---- - src/lstack/core/lstack_lwip.c | 12 ++++++++---- - src/lstack/core/lstack_protocol_stack.c | 25 +++++++++++++++---------- - src/lstack/core/lstack_thread_rpc.c | 6 +++--- - src/lstack/include/lstack_lwip.h | 4 ++-- - 4 files changed, 28 insertions(+), 19 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index c4b1ebc..73a6f12 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -646,14 +646,18 @@ bool do_lwip_replenish_sendring(struct protocol_stack *stack, struct lwip_sock * - return replenish_again; - } - --bool do_lwip_send(struct protocol_stack *stack, int32_t fd, struct lwip_sock *sock, -- size_t len, int32_t flags) -+int do_lwip_send(struct protocol_stack *stack, int32_t fd, struct lwip_sock *sock, -+ size_t len, int32_t flags) - { -+ ssize_t ret; - /* send all send_ring, so len set lwip send max. */ - if (NETCONN_IS_UDP(sock)) { -- (void)lwip_send(fd, sock, len, flags); -+ ret = lwip_send(fd, sock, len, flags); - } else { -- (void)lwip_send(fd, sock, UINT16_MAX, flags); -+ ret = lwip_send(fd, sock, UINT16_MAX, flags); -+ } -+ if (ret < 0 && (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED)) { -+ return -1; - } - - return do_lwip_replenish_sendring(stack, sock); -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index f61e7a8..8dbd9ad 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -699,10 +699,10 @@ void stack_close(struct rpc_msg *msg) - struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - struct lwip_sock *sock = get_socket(fd); - -- if (sock && NETCONN_IS_DATAOUT(sock)) { -+ if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { - msg->recall_flag = 1; - rpc_call(&stack->rpc_queue, msg); /* until stack_send recall finish */ -- return; -+ return; - } - - msg->result = lwip_close(fd); -@@ -860,27 +860,32 @@ void stack_send(struct rpc_msg *msg) - int32_t fd = msg->args[MSG_ARG_0].i; - size_t len = msg->args[MSG_ARG_1].size; - struct protocol_stack *stack = (struct protocol_stack *)msg->args[MSG_ARG_3].p; -- bool replenish_again; -+ int replenish_again; - - struct lwip_sock *sock = get_socket(fd); - if (sock == NULL) { - msg->result = -1; - LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); -- rpc_msg_free(msg); -+ __sync_fetch_and_sub(&sock->call_num, 1); - return; - } - - replenish_again = do_lwip_send(stack, sock->conn->socket, sock, len, 0); -- __sync_fetch_and_sub(&sock->call_num, 1); -- if (!NETCONN_IS_DATAOUT(sock) && !replenish_again) { -+ if (replenish_again < 0) { -+ __sync_fetch_and_sub(&sock->call_num, 1); - return; -- } else { -- if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 0) { -- msg->recall_flag = 1; -+ } -+ -+ if (NETCONN_IS_DATAOUT(sock) || replenish_again > 0) { -+ if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1) { -+ msg->recall_flag = 1; - rpc_call(&stack->rpc_queue, msg); -- __sync_fetch_and_add(&sock->call_num, 1); -+ return; - } - } -+ -+ __sync_fetch_and_sub(&sock->call_num, 1); -+ return; - } - - /* any protocol stack thread receives arp packet and sync it to other threads so that it can have the arp table */ -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 4aceee6..0b2a62a 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -109,14 +109,14 @@ void poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) - } - - if (!msg->recall_flag) { -- if (msg->sync_flag) { -+ if (msg->sync_flag) { - pthread_spin_unlock(&msg->lock); - } else { - rpc_msg_free(msg); - } - } else { -- msg->recall_flag = 0; -- } -+ msg->recall_flag = 0; -+ } - } - } - -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index 4a13204..a11489c 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -50,8 +50,8 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - - void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num); - void do_lwip_add_recvlist(int32_t fd); --bool do_lwip_send(struct protocol_stack *stack, int32_t fd, struct lwip_sock *sock, -- size_t len, int32_t flags); -+int do_lwip_send(struct protocol_stack *stack, int32_t fd, struct lwip_sock *sock, -+ size_t len, int32_t flags); - - uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, uint32_t max_num); - uint32_t do_lwip_get_connnum(void); --- -2.27.0 - diff --git a/0084-mod-unix-time-stamp-to-local-time.patch b/0084-mod-unix-time-stamp-to-local-time.patch deleted file mode 100644 index fda79e95dce4f4349ae7548ca74a190a93152391..0000000000000000000000000000000000000000 --- a/0084-mod-unix-time-stamp-to-local-time.patch +++ /dev/null @@ -1,72 +0,0 @@ -From 95784bb047ae30ebff9d224ef178430fda91027e Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Fri, 15 Dec 2023 03:34:46 +0800 -Subject: [PATCH] mod unix time stamp to local time - ---- - src/ltran/ltran_dfx.c | 26 +++++++++++++++++++++----- - 1 file changed, 21 insertions(+), 5 deletions(-) - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 2a84cb8..25d4f35 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -53,6 +53,7 @@ - - #define GAZELLE_DECIMAL 10 - #define GAZELLE_KEEPALIVE_STR_LEN 35 -+#define GAZELLE_TIME_STR_LEN 25 - - static int32_t g_unix_fd = -1; - static int32_t g_ltran_rate_show_flag = GAZELLE_OFF; // not show when first get total statistics -@@ -1001,13 +1002,27 @@ static void gazelle_keepalive_string(char* str, int buff_len, struct gazelle_sta - if (conn_info->keepalive == 0) { - return; - } -- int ret = sprintf_s(str, buff_len - 1, "(%u,%u,%u)", conn_info->keep_idle, conn_info->keep_intvl, -+ int ret = sprintf_s(str, buff_len, "(%u,%u,%u)", conn_info->keep_idle, conn_info->keep_intvl, - conn_info->keep_cnt); - if (ret < 0) { - printf("gazelle_keepalive_string sprintf_s fail ret=%d\n", ret); - return; - } -- str[strlen(str)] = '\0'; -+} -+ -+static void gazelle_localtime_string(char* str, int buff_len) -+{ -+ struct timeval time = {0}; -+ gettimeofday(&time, NULL); -+ struct tm* tm; -+ time_t t = time.tv_sec; -+ tm = localtime(&t); -+ int ret = sprintf_s(str, buff_len, "%d-%d-%d %d:%d:%d", -+ tm->tm_yday + 1900, tm->tm_mon + 1, tm->tm_yday, tm->tm_hour, tm->tm_min, tm->tm_sec); -+ if (ret < 0) { -+ printf("gazelle_localtime_string sprintf_s fail ret=%d\n", ret); -+ return; -+ } - } - - static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_msg_request *req_msg) -@@ -1020,13 +1035,14 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - char str_raddr[INET6_ADDRSTRLEN + 6] = {0}; - struct gazelle_stack_dfx_data *stat = (struct gazelle_stack_dfx_data *)buf; - struct gazelle_stat_lstack_conn *conn = &stat->data.conn; -- struct timeval time = {0}; -- gettimeofday(&time, NULL); -+ - char keepalive_info_str[GAZELLE_KEEPALIVE_STR_LEN] = {0}; -+ char sys_local_time_str[GAZELLE_TIME_STR_LEN] = {0}; -+ gazelle_localtime_string(sys_local_time_str, GAZELLE_TIME_STR_LEN); - - printf("Active Internet connections (servers and established)\n"); - do { -- printf("\n------ stack tid: %6u ------time=%lu\n", stat->tid, time.tv_sec * 1000000 + time.tv_usec); -+ printf("\n------ stack tid: %6u ------time=%s\n", stat->tid, sys_local_time_str); - printf("No. Proto lwip_recv recv_ring in_send send_ring cwn rcv_wnd snd_wnd snd_buf snd_nxt" - " lastack rcv_nxt events epoll_ev evlist fd Local Address" - " Foreign Address State" --- -2.27.0 - diff --git a/0085-optimize-gazelle-exit-process.patch b/0085-optimize-gazelle-exit-process.patch deleted file mode 100644 index a8a68b515e80ca5358186a442da4d8d6156a2918..0000000000000000000000000000000000000000 --- a/0085-optimize-gazelle-exit-process.patch +++ /dev/null @@ -1,671 +0,0 @@ -From 95c0a884ff26b42a75ee35639d789b40af131fd3 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Tue, 12 Dec 2023 19:24:14 +0800 -Subject: [PATCH] optimize gazelle exit process 1. close all fds 2. lstack - thread exits, then gazelle process exits - ---- - src/common/gazelle_base_func.h | 2 + - src/common/gazelle_dfx_msg.c | 8 +- - src/lstack/api/dir.mk | 2 +- - src/lstack/api/lstack_dummy_api.c | 55 +++++++++++++ - src/lstack/api/lstack_rtc_api.c | 1 + - src/lstack/api/lstack_signal.c | 5 +- - src/lstack/api/lstack_wrap.c | 12 +++ - src/lstack/core/lstack_dpdk.c | 2 +- - src/lstack/core/lstack_init.c | 18 ++++- - src/lstack/core/lstack_lwip.c | 16 ++-- - src/lstack/core/lstack_protocol_stack.c | 93 ++++++++++++++++++---- - src/lstack/core/lstack_thread_rpc.c | 22 ++++- - src/lstack/include/lstack_dummy_api.h | 23 ++++++ - src/lstack/include/lstack_lwip.h | 4 +- - src/lstack/include/lstack_protocol_stack.h | 6 +- - src/lstack/include/lstack_thread_rpc.h | 3 +- - src/lstack/include/lstack_wrap.h | 1 + - 17 files changed, 237 insertions(+), 36 deletions(-) - create mode 100644 src/lstack/api/lstack_dummy_api.c - create mode 100644 src/lstack/include/lstack_dummy_api.h - -diff --git a/src/common/gazelle_base_func.h b/src/common/gazelle_base_func.h -index d21ef5f..2d629c1 100644 ---- a/src/common/gazelle_base_func.h -+++ b/src/common/gazelle_base_func.h -@@ -34,6 +34,8 @@ int32_t check_and_set_run_dir(void); - - int32_t filename_check(const char* args); - -+void gazelle_exit(void); -+ - #undef container_of - #define container_of(ptr, type, field) ((type *)(void*)(((char *)(ptr)) - offsetof(type, field))) - -diff --git a/src/common/gazelle_dfx_msg.c b/src/common/gazelle_dfx_msg.c -index 5fe4e06..ec23401 100644 ---- a/src/common/gazelle_dfx_msg.c -+++ b/src/common/gazelle_dfx_msg.c -@@ -29,19 +29,19 @@ int read_specied_len(int fd, char *buf, size_t target_size) - while (total_read < target_size) { - int ret = poll(fds, 1, GAZELLECTL_TIMEOUT); - if (ret < 0) { -- printf("read_specied_len:: poll ret=%d \n", ret); -+ printf("read_specied_len: poll ret=%d \n", ret); - return -1; - } else if (ret == 0) { -- printf("read_specied_len:: time out \n"); -+ printf("read_specied_len: time out \n"); - return -1; - } - if (fds[0].revents & POLLIN) { - int n = read(fd, buf + total_read, target_size - total_read); - if (n < 0) { -- printf("read_specied_len:: read ret=%d \n", ret); -+ printf("read_specied_len: read ret=%d \n", ret); - return -1; - } else if (n == 0) { -- printf("read_specied_len:: Connection closed \n"); -+ printf("read_specied_len: Connection closed \n"); - return -1; - } - total_read += n; -diff --git a/src/lstack/api/dir.mk b/src/lstack/api/dir.mk -index ffbb137..729690d 100644 ---- a/src/lstack/api/dir.mk -+++ b/src/lstack/api/dir.mk -@@ -8,7 +8,7 @@ - # PURPOSE. - # See the Mulan PSL v2 for more details. - --SRC = lstack_epoll.c lstack_signal.c lstack_fork.c lstack_wrap.c lstack_rtw_api.c lstack_rtc_api.c -+SRC = lstack_epoll.c lstack_signal.c lstack_fork.c lstack_wrap.c lstack_rtw_api.c lstack_rtc_api.c lstack_dummy_api.c - - $(eval $(call register_dir, api, $(SRC))) - -diff --git a/src/lstack/api/lstack_dummy_api.c b/src/lstack/api/lstack_dummy_api.c -new file mode 100644 -index 0000000..f327916 ---- /dev/null -+++ b/src/lstack/api/lstack_dummy_api.c -@@ -0,0 +1,55 @@ -+/* -+* 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 -+#include -+#include -+ -+#define DUMMY_SLEEP_S 5 -+ -+static inline ssize_t dummy_exit(void) -+{ -+ sleep(DUMMY_SLEEP_S); -+ errno = ENOTCONN; -+ return -1; -+} -+ -+int dummy_socket(int domain, int type, int protocol) -+{ -+ sleep(DUMMY_SLEEP_S); -+ return -1; -+} -+ -+ssize_t dummy_write(int s, const void *mem, size_t size) -+{ -+ return dummy_exit(); -+} -+ -+ssize_t dummy_writev(int s, const struct iovec *iov, int iovcnt) -+{ -+ return dummy_exit(); -+} -+ -+ssize_t dummy_send(int sockfd, const void *buf, size_t len, int flags) -+{ -+ return dummy_exit(); -+} -+ -+ssize_t dummy_sendmsg(int s, const struct msghdr *message, int flags) -+{ -+ return dummy_exit(); -+} -+ -+ssize_t dummy_sendto(int sockfd, const void *buf, size_t len, int flags, -+ const struct sockaddr *addr, socklen_t addrlen) -+{ -+ return dummy_exit(); -+} -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index 50d72bc..d29e51e 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -20,6 +20,7 @@ - #include "lstack_log.h" - #include "lstack_cfg.h" - #include "lstack_protocol_stack.h" -+#include "lstack_thread_rpc.h" - #include "lstack_rtc_api.h" - - int rtc_poll(struct pollfd *fds, nfds_t nfds, int timeout) -diff --git a/src/lstack/api/lstack_signal.c b/src/lstack/api/lstack_signal.c -index 285aaf3..6da6eb4 100644 ---- a/src/lstack/api/lstack_signal.c -+++ b/src/lstack/api/lstack_signal.c -@@ -18,6 +18,7 @@ - #include - #include - -+#include "gazelle_base_func.h" - #include "lstack_cfg.h" - #include "dpdk_common.h" - #include "lstack_log.h" -@@ -60,15 +61,13 @@ static void lstack_sig_default_handler(int sig) - if (get_global_cfg_params() && get_global_cfg_params()->is_primary) { - delete_primary_path(); - } -- if (!use_ltran()) { -- dpdk_kni_release(); -- } - 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(); - } - lwip_exit(); -+ gazelle_exit(); - (void)kill(getpid(), sig); - } - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 65a0a5a..89f54f8 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -36,6 +36,7 @@ - - #include "lstack_rtc_api.h" - #include "lstack_rtw_api.h" -+#include "lstack_dummy_api.h" - - #ifndef SOCK_TYPE_MASK - #define SOCK_TYPE_MASK 0xf -@@ -112,6 +113,17 @@ void wrap_api_init(void) - } - } - -+void wrap_api_set_dummy(void) -+{ -+ g_wrap_api->socket_fn = dummy_socket; -+ g_wrap_api->send_fn = dummy_send; -+ g_wrap_api->write_fn = dummy_write; -+ g_wrap_api->writev_fn = dummy_writev; -+ g_wrap_api->send_msg = dummy_sendmsg; -+ g_wrap_api->send_to = dummy_sendto; -+ rte_wmb(); -+} -+ - static inline int32_t do_epoll_create1(int32_t flags) - { - if (select_posix_path() == PATH_KERNEL) { -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 8950591..e20dea8 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -897,4 +897,4 @@ void dpdk_nic_features_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id) - dfx->data.nic_features.tx_offload = dev_conf.txmode.offloads; - dfx->data.nic_features.rx_offload = dev_conf.rxmode.offloads; - return; --} -\ No newline at end of file -+} -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index a3ca4ff..fef2942 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -107,10 +107,24 @@ static int32_t check_process_conflict(void) - return 0; - } - -+void gazelle_exit(void) -+{ -+ if (!get_global_cfg_params()->stack_mode_rtc) { -+ wrap_api_set_dummy(); -+ /* 1: wait until app thread call send functio complete */ -+ sleep(1); -+ stack_group_exit(); -+ } -+ if (!use_ltran()) { -+ dpdk_kni_release(); -+ } -+} -+ - __attribute__((destructor)) void gazelle_network_exit(void) - { - if (posix_api != NULL && !posix_api->ues_posix) { - lwip_exit(); -+ gazelle_exit(); - } - - if (!use_ltran()) { -@@ -118,8 +132,6 @@ __attribute__((destructor)) void gazelle_network_exit(void) - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "rte_pdump_uninit failed\n"); - } -- -- dpdk_kni_release(); - } - } - -@@ -289,6 +301,7 @@ __attribute__((constructor)) void gazelle_network_init(void) - - if (!get_global_cfg_params()->stack_mode_rtc) { - if (stack_setup_thread() != 0) { -+ gazelle_exit(); - LSTACK_EXIT(1, "stack_setup_thread failed\n"); - } - } -@@ -301,6 +314,7 @@ __attribute__((constructor)) void gazelle_network_init(void) - } - - if (set_process_start_flag() != 0) { -+ gazelle_exit(); - LSTACK_EXIT(1, "set_process_start_flag failed\n"); - } - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index fb286d6..15f99f9 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -201,7 +201,7 @@ void do_lwip_init_sock(int32_t fd) - init_list_node_null(&sock->event_list); - } - --void do_lwip_clean_sock(int32_t fd) -+void do_lwip_clean_sock(int fd) - { - struct lwip_sock *sock = get_socket_by_fd(fd); - if (sock == NULL || sock->stack == NULL) { -@@ -1193,7 +1193,15 @@ void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_soc - } - } - --int32_t do_lwip_socket(int domain, int type, int protocol) -+int do_lwip_close(int fd) -+{ -+ int ret = lwip_close(fd); -+ do_lwip_clean_sock(fd); -+ posix_api->close_fn(fd); -+ return ret; -+} -+ -+int do_lwip_socket(int domain, int type, int protocol) - { - int32_t fd = lwip_socket(domain, type, 0); - if (fd < 0) { -@@ -1204,9 +1212,7 @@ int32_t do_lwip_socket(int domain, int type, int protocol) - - struct lwip_sock *sock = get_socket(fd); - if (sock == NULL || sock->stack == NULL) { -- lwip_close(fd); -- do_lwip_clean_sock(fd); -- posix_api->close_fn(fd); -+ do_lwip_close(fd); - return -1; - } - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 8dbd9ad..3123ca3 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -45,6 +45,22 @@ static struct protocol_stack_group g_stack_group = {0}; - - typedef void *(*stack_thread_func)(void *arg); - -+static void stack_set_state(struct protocol_stack *stack, enum rte_lcore_state_t state) -+{ -+ __atomic_store_n(&stack->state, state, __ATOMIC_RELEASE); -+} -+ -+static enum rte_lcore_state_t stack_get_state(struct protocol_stack *stack) -+{ -+ return __atomic_load_n(&stack->state, __ATOMIC_ACQUIRE); -+} -+ -+static void stack_wait_quit(struct protocol_stack *stack) -+{ -+ while (__atomic_load_n(&stack->state, __ATOMIC_ACQUIRE) != WAIT) { -+ rte_pause(); -+ } -+} - - void bind_to_stack_numa(struct protocol_stack *stack) - { -@@ -436,8 +452,9 @@ END: - return NULL; - } - --void stack_polling(uint32_t wakeup_tick) -+int stack_polling(uint32_t wakeup_tick) - { -+ int force_quit; - struct cfg_params *cfg = get_global_cfg_params(); - uint8_t use_ltran_flag = cfg->use_ltran; - bool kni_switch = cfg->kni_switch; -@@ -448,7 +465,7 @@ void stack_polling(uint32_t wakeup_tick) - uint32_t read_connect_number = cfg->read_connect_number; - struct protocol_stack *stack = get_protocol_stack(); - -- poll_rpc_msg(stack, rpc_number); -+ force_quit = poll_rpc_msg(stack, rpc_number); - gazelle_eth_dev_poll(stack, use_ltran_flag, nic_read_number); - sys_timer_run(); - if (cfg->low_power_mod != 0) { -@@ -456,7 +473,7 @@ void stack_polling(uint32_t wakeup_tick) - } - - if (stack_mode_rtc) { -- return; -+ return force_quit; - } - - do_lwip_read_recvlist(stack, read_connect_number); -@@ -482,7 +499,7 @@ void stack_polling(uint32_t wakeup_tick) - kni_handle_rx(stack->port_id); - } - } -- return; -+ return force_quit; - } - - static void* gazelle_stack_thread(void *arg) -@@ -512,11 +529,14 @@ static void* gazelle_stack_thread(void *arg) - return NULL; - } - -- for (;;) { -- stack_polling(wakeup_tick); -+ stack_set_state(stack, RUNNING); -+ -+ while (stack_polling(wakeup_tick) == 0) { - wakeup_tick++; - } - -+ stack_set_state(stack, WAIT); -+ - return NULL; - } - -@@ -576,6 +596,7 @@ int32_t stack_group_init(void) - LSTACK_LOG(ERR, LSTACK, "sem_init failed errno=%d\n", errno); - return -1; - } -+ - stack_group->stack_setup_fail = 0; - - if (get_global_cfg_params()->is_primary) { -@@ -705,14 +726,10 @@ void stack_close(struct rpc_msg *msg) - return; - } - -- msg->result = lwip_close(fd); -+ msg->result = do_lwip_close(fd); - if (msg->result != 0) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); - } -- -- do_lwip_clean_sock(fd); -- -- posix_api->close_fn(fd); - } - - void stack_shutdown(struct rpc_msg *msg) -@@ -775,9 +792,7 @@ void stack_accept(struct rpc_msg *msg) - - struct lwip_sock *sock = get_socket(accept_fd); - if (sock == NULL || sock->stack == NULL) { -- lwip_close(accept_fd); -- do_lwip_clean_sock(accept_fd); -- posix_api->close_fn(accept_fd); -+ do_lwip_close(accept_fd); - LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); - return; - } -@@ -866,7 +881,6 @@ void stack_send(struct rpc_msg *msg) - if (sock == NULL) { - msg->result = -1; - LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); -- __sync_fetch_and_sub(&sock->call_num, 1); - return; - } - -@@ -1260,3 +1274,52 @@ int32_t stack_broadcast_accept(int32_t fd, struct sockaddr *addr, socklen_t *add - return stack_broadcast_accept4(fd, addr, addrlen, 0); - } - -+static void stack_all_fds_close(void) -+{ -+ for (int i = 3; i < GAZELLE_MAX_CLIENTS + GAZELLE_RESERVED_CLIENTS; i++) { -+ struct lwip_sock *sock = get_socket(i); -+ if (sock && sock->stack == get_protocol_stack()) { -+ do_lwip_close(i); -+ } -+ } -+} -+ -+static void stack_exit(void) -+{ -+ stack_all_fds_close(); -+} -+ -+void stack_exit_by_rpc(struct rpc_msg *msg) -+{ -+ stack_exit(); -+} -+ -+void stack_group_exit(void) -+{ -+ int i; -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ struct protocol_stack *stack = get_protocol_stack(); -+ -+ for (i = 0; i < stack_group->stack_num; i++) { -+ if ((stack_group->stacks[i] == NULL) || -+ stack_get_state(stack_group->stacks[i]) != RUNNING) { -+ continue; -+ } -+ -+ if (stack != stack_group->stacks[i]) { -+ rpc_call_stack_exit(stack_group->stacks[i]); -+ } -+ } -+ -+ if (stack != NULL) { -+ stack_exit(); -+ } -+ -+ for (i = 0; i < stack_group->stack_num; i++) { -+ if (stack_group->stacks[i] == NULL || stack == stack_group->stacks[i]) { -+ continue; -+ } -+ /* wait stack thread quit */ -+ stack_wait_quit(stack_group->stacks[i]); -+ } -+} -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 0b2a62a..2af30d7 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -90,8 +90,9 @@ static inline __attribute__((always_inline)) int32_t rpc_sync_call(lockless_queu - return ret; - } - --void poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) -+int poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) - { -+ int force_quit = 0; - struct rpc_msg *msg = NULL; - - while (max_num--) { -@@ -108,6 +109,10 @@ void poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) - stack->stats.call_null++; - } - -+ if (msg->func == stack_exit_by_rpc) { -+ force_quit = 1; -+ } -+ - if (!msg->recall_flag) { - if (msg->sync_flag) { - pthread_spin_unlock(&msg->lock); -@@ -118,6 +123,8 @@ void poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) - msg->recall_flag = 0; - } - } -+ -+ return force_quit; - } - - int32_t rpc_call_conntable(struct protocol_stack *stack, void *conn_table, uint32_t max_conn) -@@ -246,6 +253,7 @@ int32_t rpc_call_arp(struct protocol_stack *stack, struct rte_mbuf *mbuf) - int32_t rpc_call_socket(int32_t domain, int32_t type, int32_t protocol) - { - struct protocol_stack *stack = get_bind_protocol_stack(); -+ - struct rpc_msg *msg = rpc_msg_alloc(stack, stack_socket); - if (msg == NULL) { - return -1; -@@ -271,6 +279,18 @@ int32_t rpc_call_close(int fd) - return rpc_sync_call(&stack->rpc_queue, msg); - } - -+int32_t rpc_call_stack_exit(struct protocol_stack *stack) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(stack, stack_exit_by_rpc); -+ if (msg == NULL) { -+ LSTACK_LOG(INFO, LSTACK, "rpc msg alloc failed\n"); -+ return -1; -+ } -+ -+ rpc_call(&stack->rpc_queue, msg); -+ return 0; -+} -+ - int32_t rpc_call_shutdown(int fd, int how) - { - struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -diff --git a/src/lstack/include/lstack_dummy_api.h b/src/lstack/include/lstack_dummy_api.h -new file mode 100644 -index 0000000..48bce31 ---- /dev/null -+++ b/src/lstack/include/lstack_dummy_api.h -@@ -0,0 +1,23 @@ -+/* -+* 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 _LSTACK_DUMMY_API_H_ -+#define _LSTACK_DUMMY_API_H_ -+ -+int dummy_socket(int domain, int type, int protocol); -+ssize_t dummy_write(int s, const void *mem, size_t size); -+ssize_t dummy_writev(int s, const struct iovec *iov, int iovcnt); -+ssize_t dummy_sendmsg(int s, const struct msghdr *message, int flags); -+ssize_t dummy_send(int sockfd, const void *buf, size_t len, int flags); -+ssize_t dummy_sendto(int sockfd, const void *buf, size_t len, int flags, -+ const struct sockaddr *addr, socklen_t addrlen); -+#endif /* __LSTACK_DUMMY_API_H_ */ -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index a11489c..0a82781 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -28,9 +28,9 @@ struct rpc_msg; - struct rte_mbuf; - struct protocol_stack; - --int32_t do_lwip_socket(int domain, int type, int protocol); -+int do_lwip_socket(int domain, int type, int protocol); -+int do_lwip_close(int32_t fd); - void do_lwip_init_sock(int32_t fd); --void do_lwip_clean_sock(int32_t fd); - void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock); - - struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags); -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 6638984..8e2e807 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -46,6 +46,7 @@ struct protocol_stack { - uint32_t stack_idx; - cpu_set_t idle_cpuset; /* idle cpu in numa of stack, app thread bind to it */ - int32_t epollfd; /* kernel event thread epoll fd */ -+ volatile enum rte_lcore_state_t state; - - struct rte_mempool *rxtx_mbuf_pool; - struct rte_ring *rx_ring; -@@ -114,6 +115,7 @@ struct protocol_stack *get_bind_protocol_stack(void); - struct protocol_stack_group *get_protocol_stack_group(void); - - int32_t stack_group_init(void); -+void stack_group_exit(void); - int32_t stack_setup_thread(void); - int32_t stack_setup_app_thread(void); - -@@ -176,6 +178,8 @@ void stack_replenish_sendring(struct rpc_msg *msg); - void stack_get_conntable(struct rpc_msg *msg); - void stack_get_connnum(struct rpc_msg *msg); - void stack_recvlist_count(struct rpc_msg *msg); --void stack_polling(uint32_t wakeup_tick); -+void stack_exit_by_rpc(struct rpc_msg *msg); -+ -+int stack_polling(uint32_t wakeup_tick); - void kni_handle_tx(struct rte_mbuf *mbuf); - #endif -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index ca8a510..633ef93 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -62,7 +62,7 @@ struct protocol_stack; - struct rte_mbuf; - struct wakeup_poll; - struct lwip_sock; --void poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num); -+int poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num); - void rpc_call_clean_epoll(struct protocol_stack *stack, struct wakeup_poll *wakeup); - int32_t rpc_call_msgcnt(struct protocol_stack *stack); - int32_t rpc_call_shadow_fd(struct protocol_stack *stack, int32_t fd, const struct sockaddr *addr, socklen_t addrlen); -@@ -89,6 +89,7 @@ int32_t rpc_call_ioctl(int fd, long cmd, void *argp); - int32_t rpc_call_replenish(struct protocol_stack *stack, struct lwip_sock *sock); - int32_t rpc_call_mbufpoolsize(struct protocol_stack *stack); - int32_t rpc_call_rpcpool_size(struct protocol_stack *stack); -+int32_t rpc_call_stack_exit(struct protocol_stack *stack); - - static inline __attribute__((always_inline)) void rpc_call(lockless_queue *queue, struct rpc_msg *msg) - { -diff --git a/src/lstack/include/lstack_wrap.h b/src/lstack/include/lstack_wrap.h -index 80e5f3c..dab5222 100644 ---- a/src/lstack/include/lstack_wrap.h -+++ b/src/lstack/include/lstack_wrap.h -@@ -14,6 +14,7 @@ - #define _LSTACK_WRAP_H_ - - void wrap_api_init(void); -+void wrap_api_set_dummy(void); - - #endif - --- -2.27.0 - diff --git a/0086-fix-EPOLLIN-event-error.patch b/0086-fix-EPOLLIN-event-error.patch deleted file mode 100644 index c534f3e6557116d6081b8951bf9c58824fdf5391..0000000000000000000000000000000000000000 --- a/0086-fix-EPOLLIN-event-error.patch +++ /dev/null @@ -1,52 +0,0 @@ -From a72ed2effc718023316452866632f52058ae8218 Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Mon, 11 Dec 2023 13:24:33 +0000 -Subject: [PATCH] fix EPOLLIN event error - ---- - src/lstack/api/lstack_epoll.c | 22 +++++++++++++++++++++- - 1 file changed, 21 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 7825bed..7dbef9d 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -61,6 +61,17 @@ void add_sock_event_nolock(struct lwip_sock *sock, uint32_t event) - if (wakeup == NULL || wakeup->type == WAKEUP_CLOSE || (event & sock->epoll_events) == 0) { - return; - } -+ -+ if (!get_global_cfg_params()->stack_mode_rtc) { -+ if (event == EPOLLIN && !NETCONN_IS_DATAIN(sock) && !NETCONN_IS_ACCEPTIN(sock)) { -+ return; -+ } -+ -+ if (event == EPOLLOUT && !NETCONN_IS_OUTIDLE(sock)) { -+ return; -+ } -+ } -+ - sock->events |= (event == EPOLLERR) ? (EPOLLIN | EPOLLERR) : (event & sock->epoll_events); - if (list_is_null(&sock->event_list)) { - list_add_node(&wakeup->event_list, &sock->event_list); -@@ -88,7 +99,16 @@ void add_sock_event(struct lwip_sock *sock, uint32_t event) - - void del_sock_event_nolock(struct lwip_sock *sock, uint32_t event) - { -- sock->events &= ~event; -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ sock->events &= ~event; -+ } else { -+ if ((event & EPOLLOUT) && !NETCONN_IS_OUTIDLE(sock)) { -+ sock->events &= ~EPOLLOUT; -+ } -+ if ((event & EPOLLIN) && !NETCONN_IS_DATAIN(sock) && !NETCONN_IS_ACCEPTIN(sock)) { -+ sock->events &= ~EPOLLIN; -+ } -+ } - - if (sock->events == 0) { - list_del_node_null(&sock->event_list); --- -2.27.0 - diff --git a/0087-mod-time-err.patch b/0087-mod-time-err.patch deleted file mode 100644 index 9893b9af19ad8ae081dd50f28962dcffb6f932ec..0000000000000000000000000000000000000000 --- a/0087-mod-time-err.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 1d578011ed2ee7e508af119d963e7283b1d0dc6f Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Mon, 18 Dec 2023 09:52:21 +0800 -Subject: [PATCH] mod time err - ---- - src/ltran/ltran_dfx.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 25d4f35..c8dc562 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -1018,7 +1018,7 @@ static void gazelle_localtime_string(char* str, int buff_len) - time_t t = time.tv_sec; - tm = localtime(&t); - int ret = sprintf_s(str, buff_len, "%d-%d-%d %d:%d:%d", -- tm->tm_yday + 1900, tm->tm_mon + 1, tm->tm_yday, tm->tm_hour, tm->tm_min, tm->tm_sec); -+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); - if (ret < 0) { - printf("gazelle_localtime_string sprintf_s fail ret=%d\n", ret); - return; --- -2.27.0 - diff --git a/0088-fix-gazellectl-lstack-show-ip-r-with-ltran-error-log.patch b/0088-fix-gazellectl-lstack-show-ip-r-with-ltran-error-log.patch deleted file mode 100644 index a9076d1b57679c1e3b7225d80aa11c8ad72b41ae..0000000000000000000000000000000000000000 --- a/0088-fix-gazellectl-lstack-show-ip-r-with-ltran-error-log.patch +++ /dev/null @@ -1,39 +0,0 @@ -From 24b45463b653cf2aa204ca3ff303f8fe848d416f Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Sat, 16 Dec 2023 20:21:21 +0800 -Subject: [PATCH] fix gazellectl lstack show ip -r with ltran error && log info - display unknow error - ---- - src/lstack/core/lstack_stack_stat.c | 1 + - src/ltran/ltran_dfx.c | 2 +- - 2 files changed, 2 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index e4ccc41..23571b4 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -201,6 +201,7 @@ static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protoc - switch (stat_mode) { - case GAZELLE_STAT_LSTACK_SHOW: - case GAZELLE_STAT_LSTACK_SHOW_RATE: -+ case GAZELLE_STAT_LTRAN_SHOW_LSTACK: - get_stack_stats(dfx, stack); - /* fall through */ - case GAZELLE_STAT_LSTACK_SHOW_AGGREGATE: -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 25d4f35..5291fe0 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -99,7 +99,7 @@ static void gazelle_print_lstack_nic_features(void *buf, const struct gazelle_st - static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = { - {GAZELLE_STAT_LTRAN_SHOW, sizeof(struct gazelle_stat_ltran_total), gazelle_print_ltran_stat_total}, - {GAZELLE_STAT_LTRAN_SHOW_RATE, sizeof(struct gazelle_stat_ltran_total), gazelle_print_ltran_stat_rate}, -- {GAZELLE_STAT_LTRAN_SHOW_LB_RATE, sizeof(struct gazelle_stat_ltran_total), gazelle_print_ltran_stat_lb_rate}, -+ {GAZELLE_STAT_LTRAN_SHOW_LB_RATE, sizeof(struct gazelle_stat_lstack_total), gazelle_print_ltran_stat_lb_rate}, - {GAZELLE_STAT_LTRAN_SHOW_INSTANCE, sizeof(struct gazelle_stat_ltran_client), gazelle_print_ltran_stat_client}, - {GAZELLE_STAT_LTRAN_SHOW_BURST, sizeof(struct gazelle_stat_ltran_total), gazelle_print_ltran_stat_burst}, - {GAZELLE_STAT_LTRAN_SHOW_LATENCY, sizeof(struct in_addr), gazelle_print_ltran_stat_latency}, --- -2.27.0 - diff --git a/0089-fix-udp-multicast-bind-error.patch b/0089-fix-udp-multicast-bind-error.patch deleted file mode 100644 index 37184ea7c066ce6650a7ff8a88f227cd814b5e18..0000000000000000000000000000000000000000 --- a/0089-fix-udp-multicast-bind-error.patch +++ /dev/null @@ -1,29 +0,0 @@ -From d14e214a9cd32f05f097b023baa7c4a6d8629fce Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 18 Dec 2023 21:30:32 +0800 -Subject: [PATCH] fix udp multicast bind error - ---- - src/lstack/api/lstack_wrap.c | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 89f54f8..5feadc3 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -211,6 +211,12 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - return posix_api->bind_fn(s, name, namelen); - } - -+ /* select user path when udp enable and ip addr is multicast */ -+ if (IN_MULTICAST(ntohl(((struct sockaddr_in *)name)->sin_addr.s_addr))) { -+ SET_CONN_TYPE_LIBOS(sock->conn); -+ return g_wrap_api->bind_fn(s, name, namelen); -+ } -+ - if (match_host_addr(((struct sockaddr_in *)name)->sin_addr.s_addr)) { - /* maybe kni addr */ - if (posix_api->bind_fn(s, name, namelen) != 0) { --- -2.27.0 - diff --git a/0090-support-netperf.patch b/0090-support-netperf.patch deleted file mode 100644 index d0f70dc600497907dc514c21a5c9b2c75efd3df3..0000000000000000000000000000000000000000 --- a/0090-support-netperf.patch +++ /dev/null @@ -1,179 +0,0 @@ -From 8dfa19585b0e5b23e7855e1d544c41dd7a6a1dd9 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Fri, 15 Dec 2023 17:56:30 +0800 -Subject: [PATCH] support netperf - ---- - src/lstack/api/lstack_wrap.c | 13 ++++++------- - src/lstack/core/lstack_lwip.c | 21 +++++++++++++++++++-- - src/lstack/core/lstack_protocol_stack.c | 19 +++++++++++-------- - src/lstack/include/posix/lstack_epoll.h | 19 +++++++++++++++++++ - src/ltran/ltran_dfx.c | 2 +- - 5 files changed, 56 insertions(+), 18 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 65a0a5a..a226dc4 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -276,11 +276,6 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - return posix_api->connect_fn(s, name, namelen); - } - -- if (!netconn_is_nonblocking(sock->conn)) { -- LSTACK_LOG(ERR, LSTACK, "connect does not support blocking fd currently\n"); -- GAZELLE_RETURN(EINVAL); -- } -- - int32_t ret = 0; - int32_t remote_port; - bool is_local = is_dst_ip_localhost(name); -@@ -347,7 +342,11 @@ static bool unsupport_optname(int32_t optname) - optname == SO_PROTOCOL || - optname == TCP_QUICKACK || - optname == SO_SNDTIMEO || -- optname == SO_RCVTIMEO) { -+ optname == SO_RCVTIMEO || -+ optname == SO_SNDBUF || -+ optname == TCP_INFO || -+ optname == TCP_MAXSEG || -+ optname == TCP_CONGESTION) { - return true; - } - return false; -@@ -615,7 +614,7 @@ static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set - return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); - } - -- return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); -+ return g_wrap_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); - } - - #define WRAP_VA_PARAM(_fd, _cmd, _lwip_fcntl, _fcntl_fn) \ -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index fb286d6..a944f7a 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -564,6 +564,12 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - uint32_t write_avail = gazelle_ring_readable_count(sock->send_ring); - struct wakeup_poll *wakeup = sock->wakeup; - -+ if (!netconn_is_nonblocking(sock->conn)) { -+ while (write_avail < write_num) { -+ write_avail = gazelle_ring_readable_count(sock->send_ring); -+ } -+ } -+ - /* send_ring is full, data attach last pbuf */ - if (write_avail == 0) { - if (!get_global_cfg_params()->expand_send_ring) { -@@ -1005,8 +1011,19 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - pbuf = sock->recv_lastdata; - sock->recv_lastdata = NULL; - } else { -- if (gazelle_ring_read(sock->recv_ring, (void **)&pbuf, 1) != 1) { -- break; -+ if (netconn_is_nonblocking(sock->conn)) { -+ if (gazelle_ring_read(sock->recv_ring, (void **)&pbuf, 1) != 1) { -+ break; -+ } -+ } else { -+ while (gazelle_ring_read(sock->recv_ring, (void **)&pbuf, 1) != 1 && recvd == 0) { -+ /* if the connection is disconnected, recv return 0 */ -+ if ((sock->errevent > 0 || (sock->conn->pcb.tcp->flags & TF_FIN)) && !NETCONN_IS_DATAIN(sock)) { -+ return 0; -+ } -+ -+ lstack_block_wait(sock->wakeup); -+ } - } - } - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 8dbd9ad..414b5f8 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -268,12 +268,8 @@ static void wakeup_kernel_event(struct protocol_stack *stack) - continue; - } - -- __atomic_store_n(&wakeup->have_kernel_event, true, __ATOMIC_RELEASE); -- if (__atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { -- __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -- rte_mb(); -- pthread_mutex_unlock(&wakeup->wait); -- } -+ __atomic_store_n(&wakeup->have_kernel_event, true, __ATOMIC_RELEASE); -+ lstack_block_wakeup(wakeup); - } - - return; -@@ -1233,14 +1229,21 @@ int32_t stack_broadcast_bind(int32_t fd, const struct sockaddr *name, socklen_t - int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *addrlen, int flags) - { - int32_t ret = -1; -- -+ struct lwip_sock *min_sock = NULL; - struct lwip_sock *sock = get_socket(fd); - if (sock == NULL) { - errno = EINVAL; - return -1; - } - -- struct lwip_sock *min_sock = get_min_accept_sock(fd); -+ if (netconn_is_nonblocking(sock->conn)) { -+ min_sock = get_min_accept_sock(fd); -+ } else { -+ while ((min_sock = get_min_accept_sock(fd)) == NULL) { -+ lstack_block_wait(sock->wakeup); -+ } -+ } -+ - if (min_sock && min_sock->conn) { - ret = rpc_call_accept(min_sock->conn->socket, addr, addrlen, flags); - } -diff --git a/src/lstack/include/posix/lstack_epoll.h b/src/lstack/include/posix/lstack_epoll.h -index 9c34eb3..7591f0f 100644 ---- a/src/lstack/include/posix/lstack_epoll.h -+++ b/src/lstack/include/posix/lstack_epoll.h -@@ -80,6 +80,25 @@ int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t - int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout); - int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeval); - -+static inline void lstack_block_wait(struct wakeup_poll *wakeup) -+{ -+ if (wakeup == NULL) { -+ return; -+ } -+ -+ __atomic_store_n(&wakeup->in_wait, true, __ATOMIC_RELEASE); -+ pthread_mutex_lock(&wakeup->wait); -+} -+ -+static inline void lstack_block_wakeup(struct wakeup_poll *wakeup) -+{ -+ if (wakeup && __atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { -+ __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -+ rte_mb(); -+ pthread_mutex_unlock(&wakeup->wait); -+ } -+} -+ - #ifdef __cplusplus - } - #endif -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 2a84cb8..ee80359 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -168,7 +168,7 @@ static void gazelle_print_lstack_nic_features(void *buf, const struct gazelle_st - printf("###### NIC offload and other features for port %-2d #########\n", f->port_id); - - printf("tx-ipv4-checksum: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "on" : "off"); -- printf("tx-tcp_checksum: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_TCP_CKSUM) ? "on" : "off"); -+ printf("tx-tcp-checksum: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_TCP_CKSUM) ? "on" : "off"); - printf("tx-tcp-tso: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_TCP_TSO) ? "on" : "off"); - printf("tx-udp-checksum: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_UDP_CKSUM) ? "on" : "off"); - printf("tx-vlan-insert: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_VLAN_INSERT) ? "on" : "off"); --- -2.27.0 - diff --git a/0091-fix-alloc-not-free.patch b/0091-fix-alloc-not-free.patch deleted file mode 100644 index 33c3c55efa3d446ac704f0e7ccff3a2bc019d8cf..0000000000000000000000000000000000000000 --- a/0091-fix-alloc-not-free.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 053024d4cbedc106276e25a7ace5d833f8a62dea Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Wed, 20 Dec 2023 01:37:12 +0000 -Subject: [PATCH] fix alloc not free - ---- - src/lstack/core/lstack_cfg.c | 2 ++ - src/lstack/core/lstack_dpdk.c | 2 ++ - 2 files changed, 4 insertions(+) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 6324c97..f639473 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -1185,11 +1185,13 @@ static int32_t parse_bond_slave_mac(void) - if (k >= GAZELLE_MAX_BOND_NUM) { - LSTACK_PRE_LOG(LSTACK_ERR, "cfg: too many slave mac address. The maximum number of mac address is %d.\n", - GAZELLE_MAX_BOND_NUM); -+ free(bond_slave_mac_tmp); - return -EINVAL; - } - ret = str_to_eth_addr(mac_addr, g_config_params.bond_slave_mac_addr[k].addr_bytes); - if (ret != 0) { - LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid device name %s ret=%d.\n", mac_addr, ret); -+ free(bond_slave_mac_tmp); - return ret; - } - mac_addr = strtok_s(NULL, delim, &tmp); -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index e20dea8..6933ecd 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -553,11 +553,13 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - int slave_id = rte_eth_bond_primary_get(port_id); - if (slave_id < 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk get bond primary port failed port = %d\n", slave_id); -+ free(eth_params); - return slave_id; - } - ret = rte_eth_dev_info_get(slave_id, &slave_dev_info); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk get bond dev info failed ret = %d\n", ret); -+ free(eth_params); - return ret; - } - dev_info.rx_offload_capa = slave_dev_info.rx_offload_capa; --- -2.27.0 - diff --git a/0092-sigaction-fix-deprecated-signal-flags.patch b/0092-sigaction-fix-deprecated-signal-flags.patch deleted file mode 100644 index 899febb0019ac5ea918a5807db2412193122aa37..0000000000000000000000000000000000000000 --- a/0092-sigaction-fix-deprecated-signal-flags.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 3af406243bb2a4a6c8ac5b3f1d98a9cd7e0af295 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Wed, 20 Dec 2023 11:37:13 +0800 -Subject: [PATCH] sigaction: fix deprecated signal flags - ---- - src/lstack/api/lstack_signal.c | 10 +++++++++- - src/lstack/core/lstack_lwip.c | 7 ++++--- - 2 files changed, 13 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/api/lstack_signal.c b/src/lstack/api/lstack_signal.c -index 6da6eb4..314c14c 100644 ---- a/src/lstack/api/lstack_signal.c -+++ b/src/lstack/api/lstack_signal.c -@@ -57,7 +57,7 @@ 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); -+ 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(); - } -@@ -94,5 +94,13 @@ int lstack_sigaction(int sig_num, const struct sigaction *action, struct sigacti - new_action.sa_handler = lstack_sig_default_handler; - return posix_api->sigaction_fn(sig_num, &new_action, old_action); - } -+ -+ /* SA_INTERRUPT is deprecated, use SA_RESETHAND instead. */ -+ if ((match_hijack_signal(sig_num) != 0) && (action && action->sa_flags == SA_INTERRUPT)) { -+ new_action = *action; -+ new_action.sa_flags |= SA_RESETHAND; -+ return posix_api->sigaction_fn(sig_num, &new_action, old_action); -+ } -+ - return posix_api->sigaction_fn(sig_num, action, old_action); - } -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 34ec1bd..100f075 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -564,10 +564,11 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - uint32_t write_avail = gazelle_ring_readable_count(sock->send_ring); - struct wakeup_poll *wakeup = sock->wakeup; - -- if (!netconn_is_nonblocking(sock->conn)) { -- while (write_avail < write_num) { -- write_avail = gazelle_ring_readable_count(sock->send_ring); -+ while (!netconn_is_nonblocking(sock->conn) && (write_avail < write_num)) { -+ if (sock->errevent > 0) { -+ GAZELLE_RETURN(ENOTCONN); - } -+ write_avail = gazelle_ring_readable_count(sock->send_ring); - } - - /* send_ring is full, data attach last pbuf */ --- -2.27.0 - diff --git a/0093-fix-gazellectl-c-msg-error.patch b/0093-fix-gazellectl-c-msg-error.patch deleted file mode 100644 index 26cc6c0b41d25157cadef4d9bb71ac2254d162cb..0000000000000000000000000000000000000000 --- a/0093-fix-gazellectl-c-msg-error.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 887130c90c7875b4c0860ed0667224418e690752 Mon Sep 17 00:00:00 2001 -From: jinag12 -Date: Thu, 21 Dec 2023 09:03:02 +0000 -Subject: [PATCH] fix gazellectl -c msg error - -Signed-off-by: jinag12 ---- - src/lstack/core/lstack_lwip.c | 11 +++++------ - 1 file changed, 5 insertions(+), 6 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 15f99f9..1913d03 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -1158,15 +1158,14 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - conn->keep_intvl = pcb->keep_intvl; - conn->keep_cnt = pcb->keep_cnt; - -- if (netconn != NULL && netconn->recvmbox != NULL) { -- conn->recv_cnt = rte_ring_count(netconn->recvmbox->ring); -+ if (netconn != NULL) { - conn->fd = netconn->socket; -- -+ conn->recv_cnt = (netconn->recvmbox == NULL) ? 0 : rte_ring_count(netconn->recvmbox->ring); - struct lwip_sock *sock = get_socket(netconn->socket); -- if (netconn->socket > 0 && sock != NULL && sock->recv_ring != NULL && sock->send_ring != NULL) { -- conn->recv_ring_cnt = gazelle_ring_readable_count(sock->recv_ring); -+ if (sock != NULL) { -+ conn->recv_ring_cnt = (sock->recv_ring == NULL) ? 0 : gazelle_ring_readable_count(sock->recv_ring); - conn->recv_ring_cnt += (sock->recv_lastdata) ? 1 : 0; -- conn->send_ring_cnt = gazelle_ring_readover_count(sock->send_ring); -+ conn->send_ring_cnt = (sock->send_ring == NULL) ? 0 : gazelle_ring_readover_count(sock->send_ring); - conn->events = sock->events; - conn->epoll_events = sock->epoll_events; - conn->eventlist = !list_is_null(&sock->event_list); --- -2.27.0 - diff --git a/0094-CFG-fix-check-func-strdup-return-value-is-NULL.patch b/0094-CFG-fix-check-func-strdup-return-value-is-NULL.patch deleted file mode 100644 index ddd4df6607244c38bd3bc3eb000b7460b01c046f..0000000000000000000000000000000000000000 --- a/0094-CFG-fix-check-func-strdup-return-value-is-NULL.patch +++ /dev/null @@ -1,107 +0,0 @@ -From 43985056c5446c0ad45acb2309165543bd8e15e1 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Fri, 22 Dec 2023 15:42:40 +0800 -Subject: [PATCH] CFG:fix check func strdup return value is NULL - ---- - src/lstack/core/lstack_cfg.c | 31 ++++++++++++++++++++----------- - 1 file changed, 20 insertions(+), 11 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 6324c97..6e97c96 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -145,6 +145,15 @@ static struct config_vector_t g_config_tbl[] = { - { NULL, NULL } - }; - -+static char* strdup_assert_return(const char* str) -+{ -+ char* result = strdup(str); -+ if (result == NULL) { -+ LSTACK_EXIT(1, "strdup_assert_return failed, func strdup return NULL!\n"); -+ } -+ return result; -+} -+ - struct cfg_params *get_global_cfg_params(void) - { - return &g_config_params; -@@ -336,15 +345,15 @@ static int32_t parse_stack_cpu_number(void) - 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(OPT_BIND_CORELIST); -+ 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(args); -+ g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(args); - g_config_params.dpdk_argc++; - } - } - -- char *tmp_arg = strdup(args); -+ 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) { -@@ -369,15 +378,15 @@ static int32_t parse_stack_cpu_number(void) - 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(OPT_BIND_CORELIST); -+ 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(args); -+ g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(args); - g_config_params.dpdk_argc++; - } - } - -- char *tmp_arg_send = strdup(args); -+ 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); -@@ -396,15 +405,15 @@ static int32_t parse_stack_cpu_number(void) - 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(OPT_BIND_CORELIST); -+ 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(args); -+ g_config_params.dpdk_argv[g_config_params.dpdk_argc] = strdup_assert_return(args); - g_config_params.dpdk_argc++; - } - } - -- char *tmp_arg_recv = strdup(args); -+ 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); -@@ -450,7 +459,7 @@ static int32_t parse_app_exclude_cpus(void) - return -EINVAL; - } - -- tmp_arg = strdup(args); -+ 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); - free(tmp_arg); - if (cnt <= 0 || cnt > CFG_MAX_CPUS) { -@@ -1176,7 +1185,7 @@ static int32_t parse_bond_slave_mac(void) - } - - int32_t k = 0; -- char *bond_slave_mac_tmp = strdup(bond_slave_mac); -+ char *bond_slave_mac_tmp = strdup_assert_return(bond_slave_mac); - char *tmp = NULL; - const char *delim = ";"; - --- -2.27.0 - diff --git a/0095-fix-func-separate_str_to_array-overflow-problem.patch b/0095-fix-func-separate_str_to_array-overflow-problem.patch deleted file mode 100644 index 1cfbaf7e2c083cccf50eb142e85bbd5fc4bbd9a8..0000000000000000000000000000000000000000 --- a/0095-fix-func-separate_str_to_array-overflow-problem.patch +++ /dev/null @@ -1,26 +0,0 @@ -From f6a7a9585bfb82680519034869b4141c514d9214 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Mon, 25 Dec 2023 00:34:55 +0800 -Subject: [PATCH] fix func separate_str_to_array overflow problem - ---- - src/common/gazelle_parse_config.c | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/src/common/gazelle_parse_config.c b/src/common/gazelle_parse_config.c -index 42e12b5..77d0b82 100644 ---- a/src/common/gazelle_parse_config.c -+++ b/src/common/gazelle_parse_config.c -@@ -80,6 +80,9 @@ int32_t separate_str_to_array(char *args, uint32_t *array, int32_t array_size, i - for (idx = min; idx <= max; idx++) { - array[count] = idx; - count++; -+ if (count > array_size) { -+ return -1; -+ } - } - min = array_size; - } else { --- -2.27.0 - diff --git a/0096-use-default-nonblock-mode.patch b/0096-use-default-nonblock-mode.patch deleted file mode 100644 index e9e1bb809ad1856b5a95d5294e3895a447c08934..0000000000000000000000000000000000000000 --- a/0096-use-default-nonblock-mode.patch +++ /dev/null @@ -1,76 +0,0 @@ -From 47ab261c2b533975a59b34f06da0ccf83692bb78 Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Tue, 26 Dec 2023 16:53:58 +0000 -Subject: [PATCH] use default nonblock mode - ---- - src/lstack/core/lstack_cfg.c | 12 ++++++++++++ - src/lstack/core/lstack_protocol_stack.c | 5 ++++- - src/lstack/include/lstack_cfg.h | 1 + - 3 files changed, 17 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index a292070..d9c23fb 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -80,6 +80,7 @@ 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); - - #define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \ - do { \ -@@ -142,6 +143,7 @@ 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 }, - { NULL, NULL } - }; - -@@ -1280,3 +1282,13 @@ 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); -+ if (ret != 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid nonblock mode value %d. only support 0 or 1\n", \ -+ g_config_params.nonblock_mode); -+ } -+ return ret; -+} -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 9158d20..a000224 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -1287,7 +1287,10 @@ int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *ad - - int32_t stack_broadcast_accept(int32_t fd, struct sockaddr *addr, socklen_t *addrlen) - { -- return stack_broadcast_accept4(fd, addr, addrlen, 0); -+ 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); - } - - static void stack_all_fds_close(void) -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index a6bdfd5..82e96d8 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -118,6 +118,7 @@ struct cfg_params { - bool udp_enable; - struct cfg_nic_params nic; - bool stack_mode_rtc; -+ bool nonblock_mode; - }; - - struct cfg_params *get_global_cfg_params(void); --- -2.27.0 - diff --git a/0097-fix-rte_ring_create-free-time-consuming.patch b/0097-fix-rte_ring_create-free-time-consuming.patch deleted file mode 100644 index 55b45a4c272aad0119e0c7bd0f64bf29a472d71f..0000000000000000000000000000000000000000 --- a/0097-fix-rte_ring_create-free-time-consuming.patch +++ /dev/null @@ -1,128 +0,0 @@ -From 66b0ba4be7a5c3b79482eafdc28fd75e8f44e761 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 27 Dec 2023 10:26:07 +0800 -Subject: [PATCH] fix rte_ring_create/free time consuming - ---- - src/lstack/core/lstack_dpdk.c | 27 +++------------------------ - src/lstack/core/lstack_lwip.c | 14 ++++++-------- - src/lstack/include/lstack_dpdk.h | 1 - - 3 files changed, 9 insertions(+), 33 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 6933ecd..729a84c 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -245,43 +245,22 @@ struct rte_mempool *create_mempool(const char *name, uint32_t count, uint32_t si - return mempool; - } - --struct rte_ring *create_ring(const char *name, uint32_t count, uint32_t flags, int32_t queue_id) --{ -- char ring_name[RTE_RING_NAMESIZE] = {0}; -- struct rte_ring *ring; -- -- int32_t ret = snprintf_s(ring_name, sizeof(ring_name), RTE_RING_NAMESIZE - 1, -- "%s_%d_%d", name, get_global_cfg_params()->process_idx, queue_id); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d\n", ret); -- return NULL; -- } -- -- ring = rte_ring_create(ring_name, count, rte_socket_id(), flags); -- if (ring == NULL) { -- LSTACK_LOG(ERR, LSTACK, "%s create failed. errno: %d.\n", name, rte_errno); -- } -- -- return ring; --} -- - int32_t create_shared_ring(struct protocol_stack *stack) - { - lockless_queue_init(&stack->rpc_queue); - - if (use_ltran()) { -- stack->rx_ring = create_ring("RING_RX", VDEV_RX_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ, stack->queue_id); -+ stack->rx_ring = gazelle_ring_create_fast("RING_RX", VDEV_RX_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ); - if (stack->rx_ring == NULL) { - return -1; - } - -- stack->tx_ring = create_ring("RING_TX", VDEV_TX_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ, stack->queue_id); -+ stack->tx_ring = gazelle_ring_create_fast("RING_TX", VDEV_TX_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ); - if (stack->tx_ring == NULL) { - return -1; - } - -- stack->reg_ring = create_ring("SHARED_REG_RING", VDEV_REG_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ, -- stack->queue_id); -+ stack->reg_ring = gazelle_ring_create_fast("SHARED_REG_RING", VDEV_REG_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ); - if (stack->reg_ring == NULL) { - return -1; - } -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index c167ba4..4953f3d 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -72,13 +72,13 @@ static void reset_sock_data(struct lwip_sock *sock) - /* check null pointer in ring_free func */ - if (sock->recv_ring) { - free_ring_pbuf(sock->recv_ring); -- rte_ring_free(sock->recv_ring); -+ gazelle_ring_free_fast(sock->recv_ring); - sock->recv_ring = NULL; - } - - if (sock->send_ring) { - free_ring_pbuf(sock->send_ring); -- rte_ring_free(sock->send_ring); -+ gazelle_ring_free_fast(sock->send_ring); - sock->send_ring = NULL; - } - -@@ -169,7 +169,6 @@ static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_so - - void do_lwip_init_sock(int32_t fd) - { -- static _Atomic uint32_t name_tick = 0; - struct protocol_stack *stack = get_protocol_stack(); - struct lwip_sock *sock = get_socket(fd); - if (sock == NULL) { -@@ -178,18 +177,17 @@ void do_lwip_init_sock(int32_t fd) - - reset_sock_data(sock); - -- sock->recv_ring = create_ring("sock_recv", SOCK_RECV_RING_SIZE, RING_F_SP_ENQ | RING_F_SC_DEQ, -- atomic_fetch_add(&name_tick, 1)); -+ sock->recv_ring = gazelle_ring_create_fast("sock_recv", SOCK_RECV_RING_SIZE, RING_F_SP_ENQ | RING_F_SC_DEQ); - if (sock->recv_ring == NULL) { - LSTACK_LOG(ERR, LSTACK, "sock_recv create failed. errno: %d.\n", rte_errno); - return; - } - -- sock->send_ring = create_ring("sock_send", -+ sock->send_ring = gazelle_ring_create_fast("sock_send", - get_global_cfg_params()->send_ring_size, -- RING_F_SP_ENQ | RING_F_SC_DEQ, -- atomic_fetch_add(&name_tick, 1)); -+ RING_F_SP_ENQ | RING_F_SC_DEQ); - if (sock->send_ring == NULL) { -+ gazelle_ring_free_fast(sock->recv_ring); - LSTACK_LOG(ERR, LSTACK, "sock_send create failed. errno: %d.\n", rte_errno); - return; - } -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index 05f5bc6..4a160e0 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -44,7 +44,6 @@ struct rte_mbuf; - int32_t fill_mbuf_to_ring(struct rte_mempool *mempool, struct rte_ring *ring, uint32_t mbuf_num); - int32_t dpdk_eal_init(void); - int32_t pktmbuf_pool_init(struct protocol_stack *stack); --struct rte_ring *create_ring(const char *name, uint32_t count, uint32_t flags, int32_t queue_id); - struct rte_mempool *create_mempool(const char *name, uint32_t count, uint32_t size, - uint32_t flags, int32_t idx); - int32_t create_shared_ring(struct protocol_stack *stack); --- -2.27.0 - diff --git a/0098-optimize-shutdown-exit-process.patch b/0098-optimize-shutdown-exit-process.patch deleted file mode 100644 index e444784f35e3a76149b17985dd632d5dbf189653..0000000000000000000000000000000000000000 --- a/0098-optimize-shutdown-exit-process.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 5ca16b89699250a52d11ee5a181fef227fd399b6 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Mon, 18 Dec 2023 10:50:53 +0800 -Subject: [PATCH] optimize shutdown exit process - ---- - src/lstack/core/lstack_protocol_stack.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 8dbd9ad..564f055 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -722,7 +722,7 @@ void stack_shutdown(struct rpc_msg *msg) - struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - struct lwip_sock *sock = get_socket(fd); - -- if (sock && NETCONN_IS_DATAOUT(sock)) { -+ if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { - msg->recall_flag = 1; - rpc_call(&stack->rpc_queue, msg); - return; --- -2.27.0 - diff --git a/0099-fix-func-separate_str_to_array-overflow-problem.patch b/0099-fix-func-separate_str_to_array-overflow-problem.patch deleted file mode 100644 index a4d790ffb006233b40837e525550190d4ad3a25d..0000000000000000000000000000000000000000 --- a/0099-fix-func-separate_str_to_array-overflow-problem.patch +++ /dev/null @@ -1,32 +0,0 @@ -From e4eeed95dcbb47b3413e51df6c82e85a735aa31c Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Mon, 25 Dec 2023 09:31:44 +0000 -Subject: [PATCH] fix func separate_str_to_array overflow problem - -Signed-off-by: yinbin6 ---- - src/common/gazelle_parse_config.c | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/src/common/gazelle_parse_config.c b/src/common/gazelle_parse_config.c -index 77d0b82..82be52c 100644 ---- a/src/common/gazelle_parse_config.c -+++ b/src/common/gazelle_parse_config.c -@@ -78,11 +78,11 @@ int32_t separate_str_to_array(char *args, uint32_t *array, int32_t array_size, i - min = idx; - } - for (idx = min; idx <= max; idx++) { -+ if (count > array_size) { -+ return -1; -+ } - array[count] = idx; - count++; -- if (count > array_size) { -- return -1; -- } - } - min = array_size; - } else { --- -2.27.0 - diff --git a/0100-fix-func-separate_str_to_array-overflow-problem.patch b/0100-fix-func-separate_str_to_array-overflow-problem.patch deleted file mode 100644 index 8f3b2a5db55aee8a3706081cdc389722488deb12..0000000000000000000000000000000000000000 --- a/0100-fix-func-separate_str_to_array-overflow-problem.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 89abb6f4e231cf378b1e7f7415cfa196fdf7b3da Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Mon, 25 Dec 2023 10:25:42 +0000 -Subject: [PATCH] fix func separate_str_to_array overflow problem - -Signed-off-by: yinbin6 ---- - src/common/gazelle_parse_config.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/common/gazelle_parse_config.c b/src/common/gazelle_parse_config.c -index 82be52c..9772af9 100644 ---- a/src/common/gazelle_parse_config.c -+++ b/src/common/gazelle_parse_config.c -@@ -79,8 +79,8 @@ int32_t separate_str_to_array(char *args, uint32_t *array, int32_t array_size, i - } - for (idx = min; idx <= max; idx++) { - if (count > array_size) { -- return -1; -- } -+ return -1; -+ } - array[count] = idx; - count++; - } --- -2.27.0 - diff --git a/0101-fix-func-separate_str_to_array-overflow-problem.patch b/0101-fix-func-separate_str_to_array-overflow-problem.patch deleted file mode 100644 index c0e7eb43dd331a52c379c5175f6b5bbb16c27b88..0000000000000000000000000000000000000000 --- a/0101-fix-func-separate_str_to_array-overflow-problem.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 58248cb2bae3d2c50f65b3ade360fc14716a0ce7 Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Mon, 25 Dec 2023 11:06:18 +0000 -Subject: [PATCH] fix func separate_str_to_array overflow problem - -Signed-off-by: yinbin6 ---- - src/common/gazelle_parse_config.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/common/gazelle_parse_config.c b/src/common/gazelle_parse_config.c -index 9772af9..16efdc8 100644 ---- a/src/common/gazelle_parse_config.c -+++ b/src/common/gazelle_parse_config.c -@@ -78,7 +78,7 @@ int32_t separate_str_to_array(char *args, uint32_t *array, int32_t array_size, i - min = idx; - } - for (idx = min; idx <= max; idx++) { -- if (count > array_size) { -+ if (count >= array_size) { - return -1; - } - array[count] = idx; --- -2.27.0 - diff --git a/0102-fix-func-separate_str_to_array-overflow-problem.patch b/0102-fix-func-separate_str_to_array-overflow-problem.patch deleted file mode 100644 index 4266ac5d657f8e23066e4472ed0ff6607470b090..0000000000000000000000000000000000000000 --- a/0102-fix-func-separate_str_to_array-overflow-problem.patch +++ /dev/null @@ -1,26 +0,0 @@ -From fafd5c387910da2f81f38c320b3da01ffd97c6c2 Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Mon, 25 Dec 2023 13:01:39 +0000 -Subject: [PATCH] fix func separate_str_to_array overflow problem - -Signed-off-by: yinbin6 ---- - src/common/gazelle_parse_config.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/common/gazelle_parse_config.c b/src/common/gazelle_parse_config.c -index 16efdc8..1adce78 100644 ---- a/src/common/gazelle_parse_config.c -+++ b/src/common/gazelle_parse_config.c -@@ -33,7 +33,7 @@ - - int32_t separate_str_to_array(char *args, uint32_t *array, int32_t array_size, int32_t max_value) - { -- uint32_t count = 0; -+ int32_t count = 0; - char *end = NULL; - int32_t min, max; - int32_t idx; --- -2.27.0 - diff --git a/0103-fix-func-stack_setup_thread-array-doesn-t-init.patch b/0103-fix-func-stack_setup_thread-array-doesn-t-init.patch deleted file mode 100644 index 5015c7a71cfb510814558c697abe4583854c7611..0000000000000000000000000000000000000000 --- a/0103-fix-func-stack_setup_thread-array-doesn-t-init.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 9ed5bee888ab4936372a81919d894d8fd291e7c1 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Tue, 26 Dec 2023 22:49:03 +0800 -Subject: [PATCH] fix func stack_setup_thread array doesn't init - ---- - src/lstack/core/lstack_protocol_stack.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 829313f..0aff1b4 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -648,7 +648,7 @@ int32_t stack_setup_thread(void) - int32_t ret; - char name[PATH_MAX]; - int queue_num = get_global_cfg_params()->num_queue; -- struct thread_params *t_params[queue_num]; -+ struct thread_params *t_params[queue_num] = {0}; - int process_index = get_global_cfg_params()->process_idx; - - for (uint32_t i = 0; i < queue_num; i++) { --- -2.27.0 - diff --git a/0104-fix-stack_setup_thread-array-range.patch b/0104-fix-stack_setup_thread-array-range.patch deleted file mode 100644 index 57b54edc8535682ac9e27b8cb91c885b67bcbf7d..0000000000000000000000000000000000000000 --- a/0104-fix-stack_setup_thread-array-range.patch +++ /dev/null @@ -1,21 +0,0 @@ -From f6df059cf18aa0019c5bdea8947a5b4a53c02bde Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Wed, 27 Dec 2023 09:58:30 +0800 -Subject: [PATCH] fix stack_setup_thread array range - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 0aff1b4..b5d4ea3 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -648,7 +648,7 @@ int32_t stack_setup_thread(void) - int32_t ret; - char name[PATH_MAX]; - int queue_num = get_global_cfg_params()->num_queue; -- struct thread_params *t_params[queue_num] = {0}; -+ struct thread_params *t_params[PROTOCOL_STACK_MAX] = {NULL}; - int process_index = get_global_cfg_params()->process_idx; - - for (uint32_t i = 0; i < queue_num; i++) { --- -2.27.0 - diff --git a/0105-fix-func-separate_str_to_array-overflow-problem.patch b/0105-fix-func-separate_str_to_array-overflow-problem.patch deleted file mode 100644 index 69a3de42bed7157492d4862115a1cbd658753208..0000000000000000000000000000000000000000 --- a/0105-fix-func-separate_str_to_array-overflow-problem.patch +++ /dev/null @@ -1,80 +0,0 @@ -From c6de43f7e7cb866f8d5ddd453c73783d5daafca0 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Wed, 27 Dec 2023 12:22:06 +0800 -Subject: [PATCH] fix func separate_str_to_array overflow problem - ---- - src/lstack/core/lstack_protocol_stack.c | 25 +++++++++++++++++++------ - 1 file changed, 19 insertions(+), 6 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index b5d4ea3..f3d2452 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -651,44 +651,57 @@ int32_t stack_setup_thread(void) - struct thread_params *t_params[PROTOCOL_STACK_MAX] = {NULL}; - int process_index = get_global_cfg_params()->process_idx; - -+ for (uint32_t i = 0; i < queue_num; ++i) { -+ t_params[i] = malloc(sizeof(struct thread_params)); -+ if (t_params[i] == NULL) { -+ goto OUT; -+ } -+ } -+ - for (uint32_t 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) { -- return -1; -+ goto OUT; - } - } else { - ret = sprintf_s(name, sizeof(name), "%s_%d_%d", LSTACK_SEND_THREAD_NAME, process_index, i / 2); - if (ret < 0) { -- return -1; -+ goto OUT; - } - } - } else { - ret = sprintf_s(name, sizeof(name), "%s", LSTACK_THREAD_NAME); - if (ret < 0) { -- return -1; -+ goto OUT; - } - } - -- t_params[i] = malloc(sizeof(struct thread_params)); - t_params[i]->idx = i; - t_params[i]->queue_id = process_index * queue_num + i; - - ret = create_thread((void *)t_params[i], name, gazelle_stack_thread); - if (ret != 0) { -- return ret; -+ goto OUT; - } - } - - /* 2: wait stack thread and kernel_event thread init finish */ - wait_sem_value(&g_stack_group.sem_stack_setup, queue_num * 2); - if (g_stack_group.stack_setup_fail) { -- return -1; -+ goto OUT; - } - g_stack_group.stack_num = queue_num; - - return 0; -+OUT: -+ for (int32_t i = 0; i < queue_num; ++i) { -+ if (t_params[i] != NULL) { -+ free(t_params[i]); -+ } -+ } -+ return -1; - } - - void stack_arp(struct rpc_msg *msg) --- -2.27.0 - diff --git a/0106-fix-dpdk_alloc_pktmbuf-time-consuming.patch b/0106-fix-dpdk_alloc_pktmbuf-time-consuming.patch deleted file mode 100644 index cc41030d4a935085228c7f5f064a73674adbeb84..0000000000000000000000000000000000000000 --- a/0106-fix-dpdk_alloc_pktmbuf-time-consuming.patch +++ /dev/null @@ -1,32 +0,0 @@ -From d40a2e46403547fc8d12ee1dacc6484eca1fbbeb Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Fri, 5 Jan 2024 10:15:22 +0800 -Subject: [PATCH] fix dpdk_alloc_pktmbuf time-consuming - ---- - src/lstack/core/lstack_dpdk.c | 7 ++++++- - 1 file changed, 6 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 729a84c..3182bb5 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -271,9 +271,14 @@ int32_t create_shared_ring(struct protocol_stack *stack) - - int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num) - { -- if (rte_mempool_avail_count(pool) < MBUFPOOL_RESERVE_NUM + num) { -+ /* -+ * don't use rte_mempool_avail_count, it traverse cpu local cache, -+ * when RTE_MAX_LCORE is too large, it's time-consuming -+ */ -+ if (rte_ring_count(pool->pool_data) < MBUFPOOL_RESERVE_NUM + num) { - return -ENOMEM; - } -+ - int32_t ret = rte_pktmbuf_alloc_bulk(pool, mbufs, num); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "rte_pktmbuf_alloc_bulk fail allocNum=%d, ret=%d, info:%s \n", --- -2.33.0 - diff --git a/0107-ltran-optimize-config-file-error-message.patch b/0107-ltran-optimize-config-file-error-message.patch deleted file mode 100644 index bc1572b66c45f5b0f946a972ced7c564fa7f2317..0000000000000000000000000000000000000000 --- a/0107-ltran-optimize-config-file-error-message.patch +++ /dev/null @@ -1,46 +0,0 @@ -From e46c71fda9678df02d7373a1bb987cbc3979f1f6 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Fri, 5 Jan 2024 18:07:42 +0800 -Subject: [PATCH] ltran: optimize config file error message - ---- - src/ltran/ltran_param.c | 13 ++++++++++--- - 1 file changed, 10 insertions(+), 3 deletions(-) - -diff --git a/src/ltran/ltran_param.c b/src/ltran/ltran_param.c -index 11a4bc8..1eaace4 100644 ---- a/src/ltran/ltran_param.c -+++ b/src/ltran/ltran_param.c -@@ -664,8 +664,15 @@ struct param_parser g_param_parse_tbl[] = { - int32_t parse_config_file_args(const char *conf_file_path, struct ltran_config *ltran_config) - { - config_t config; -- config_init(&config); - int32_t ret; -+ char real_path[PATH_MAX]; -+ -+ if (realpath(conf_file_path, real_path) == NULL) { -+ syslog(LOG_ERR, "Err: Config file path %s error, please check conf file path.\n", conf_file_path); -+ return -1; -+ } -+ -+ config_init(&config); - - ret = memset_s(ltran_config, sizeof(struct ltran_config), 0, sizeof(struct ltran_config)); - if (ret != 0) { -@@ -673,10 +680,10 @@ int32_t parse_config_file_args(const char *conf_file_path, struct ltran_config * - syslog(LOG_ERR, "memset_s failed\n"); - return ret; - } -- ret = config_read_file(&config, conf_file_path); -+ ret = config_read_file(&config, real_path); - if (ret == 0) { -+ syslog(LOG_ERR, "Err: Read config file \"%s\" error: %s\n", real_path, config_error_text(&config)); - config_destroy(&config); -- syslog(LOG_ERR, "Err: Config file path %s error, please check conf file path.\n", conf_file_path); - return -GAZELLE_EPATH; - } - --- -2.33.0 - diff --git a/0108-replace-with-gz_addr_t.patch b/0108-replace-with-gz_addr_t.patch deleted file mode 100644 index b72791fc0f5df3d9cbf1b9e2b81bede17612ccab..0000000000000000000000000000000000000000 --- a/0108-replace-with-gz_addr_t.patch +++ /dev/null @@ -1,224 +0,0 @@ -From fa28c2bf790466ab3a4cfc8fa39ed14764797e87 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Tue, 2 Jan 2024 17:10:44 +0800 -Subject: [PATCH] replace with gz_addr_t - ---- - src/common/gazelle_opt.h | 5 +---- - src/lstack/core/lstack_control_plane.c | 6 +++--- - src/lstack/core/lstack_lwip.c | 3 +-- - src/lstack/netif/lstack_vdev.c | 16 +++++++++------- - src/ltran/ltran_forward.c | 10 +++++----- - src/ltran/ltran_stat.c | 4 ++-- - src/ltran/ltran_tcp_conn.c | 4 ++-- - src/ltran/ltran_tcp_sock.c | 4 ++-- - src/ltran/ltran_timer.c | 4 ++-- - 9 files changed, 27 insertions(+), 29 deletions(-) - -diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h -index bb540f4..36915c6 100644 ---- a/src/common/gazelle_opt.h -+++ b/src/common/gazelle_opt.h -@@ -27,6 +27,7 @@ - #define KERNEL_EPOLL_MAX 512 - - #define ETHER_ADDR_LEN 6 -+#define IPV6_ADDR_LEN 16 - - #define DEFAULT_RING_SIZE (512) - #define DEFAULT_RING_MASK (511) -@@ -52,10 +53,6 @@ - #define STACK_THREAD_DEFAULT 4 - #define STACK_NIC_READ_DEFAULT 128 - --/* same as define in lwip/ip_addr.h */ --#define GZ_ADDR_TYPE_V4 0 --#define GZ_ADDR_TYPE_V6 6 -- - #define MTU_DEFAULT_DATA_LEN 1460 - #define VLAN_HEAD_LEN 4 - #define IPV6_EXTRA_HEAD_LEN 20 -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 668ff80..2d629c8 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -361,12 +361,12 @@ static int32_t reg_conn(enum tcp_list_state table_state, enum reg_ring_type reg_ - continue; - } - qtuple.protocol = 0; -- qtuple.src_ip = conn->conn_list[i].lip.u_addr.ip4.addr; -+ qtuple.src_ip = conn->conn_list[i].lip; - qtuple.src_port = lwip_htons(conn->conn_list[i].l_port); -- qtuple.dst_ip = conn->conn_list[i].rip.u_addr.ip4.addr; -+ qtuple.dst_ip = conn->conn_list[i].rip; - qtuple.dst_port = lwip_htons(conn->conn_list[i].r_port); - -- if ((table_state == LISTEN_LIST) && (!match_host_addr(qtuple.src_ip))) { -+ if ((table_state == LISTEN_LIST) && (!match_host_addr(qtuple.src_ip.u_addr.ip4.addr))) { - continue; - } - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 4953f3d..87ec1f5 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -446,8 +446,7 @@ static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t l - } else if (addr->sa_family == AF_INET6) { - struct sockaddr_in6 *saddr = (struct sockaddr_in6 *)addr; - for (int i = 0; i < write_num; i++) { -- memcpy_s(pbufs[i]->addr.u_addr.ip6.addr, sizeof(pbufs[i]->addr.u_addr.ip6.addr), -- saddr->sin6_addr.s6_addr, sizeof(saddr->sin6_addr.s6_addr)); -+ memcpy_s(pbufs[i]->addr.u_addr.ip6.addr, IPV6_ADDR_LEN, saddr->sin6_addr.s6_addr, IPV6_ADDR_LEN); - pbufs[i]->port = lwip_ntohs((saddr)->sin6_port); - IP_SET_TYPE(&pbufs[i]->addr, IPADDR_TYPE_V6); - } -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index ccf664a..9a79dc3 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -185,10 +185,12 @@ int32_t vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple) - delete_user_process_port(qtuple->src_port, PORT_CONNECT); - uint16_t queue_id = get_protocol_stack()->queue_id; - if (queue_id != 0) { -- transfer_delete_rule_info_to_process0(qtuple->dst_ip, qtuple->src_port, qtuple->dst_port); -+ transfer_delete_rule_info_to_process0(qtuple->dst_ip.u_addr.ip4.addr, -+ qtuple->src_port, qtuple->dst_port); - } - } else { -- transfer_delete_rule_info_to_process0(qtuple->dst_ip, qtuple->src_port, qtuple->dst_port); -+ transfer_delete_rule_info_to_process0(qtuple->dst_ip.u_addr.ip4.addr, -+ qtuple->src_port, qtuple->dst_port); - } - } - -@@ -197,12 +199,12 @@ int32_t vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple) - if (get_global_cfg_params()->is_primary) { - add_user_process_port(qtuple->src_port, get_global_cfg_params()->process_idx, PORT_CONNECT); - if (queue_id != 0) { -- transfer_create_rule_info_to_process0(queue_id, qtuple->src_ip, qtuple->dst_ip, -- qtuple->src_port, qtuple->dst_port); -+ transfer_create_rule_info_to_process0(queue_id, qtuple->src_ip.u_addr.ip4.addr, -+ qtuple->dst_ip.u_addr.ip4.addr, qtuple->src_port, qtuple->dst_port); - } - } else { -- transfer_create_rule_info_to_process0(queue_id, qtuple->src_ip, qtuple->dst_ip, -- qtuple->src_port, qtuple->dst_port); -+ transfer_create_rule_info_to_process0(queue_id, qtuple->src_ip.u_addr.ip4.addr, -+ qtuple->dst_ip.u_addr.ip4.addr, qtuple->src_port, qtuple->dst_port); - } - } - -@@ -228,7 +230,7 @@ int32_t vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple) - struct protocol_stack *stack = get_protocol_stack(); - - if (type == REG_RING_TCP_LISTEN || type == REG_RING_TCP_LISTEN_CLOSE) { -- if (!match_host_addr(qtuple->src_ip)) { -+ if (!match_host_addr(qtuple->src_ip.u_addr.ip4.addr)) { - LSTACK_LOG(INFO, LSTACK, "lstack ip not match in conf.\n"); - return 0; - } -diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c -index a6f2d71..ee379b5 100644 ---- a/src/ltran/ltran_forward.c -+++ b/src/ltran/ltran_forward.c -@@ -246,8 +246,8 @@ static __rte_always_inline int32_t tcp_handle(struct rte_mbuf *m, const struct r - struct gazelle_tcp_sock *tcp_sock = NULL; - struct gazelle_quintuple quintuple; - -- quintuple.dst_ip = ipv4_hdr->dst_addr; -- quintuple.src_ip = ipv4_hdr->src_addr; -+ quintuple.dst_ip.u_addr.ip4.addr = ipv4_hdr->dst_addr; -+ quintuple.src_ip.u_addr.ip4.addr = ipv4_hdr->src_addr; - quintuple.dst_port = tcp_hdr->dst_port; - quintuple.src_port = tcp_hdr->src_port; - quintuple.protocol = 0; -@@ -260,7 +260,7 @@ static __rte_always_inline int32_t tcp_handle(struct rte_mbuf *m, const struct r - } - - tcp_sock = gazelle_sock_get_by_min_conn(gazelle_get_tcp_sock_htable(), -- quintuple.dst_ip, quintuple.dst_port); -+ quintuple.dst_ip.u_addr.ip4.addr, quintuple.dst_port); - if (unlikely(tcp_sock == NULL)) { - return GAZELLE_ERR; - } -@@ -494,7 +494,7 @@ static void tcp_hash_table_modify(struct gazelle_stack *stack, const struct reg_ - case REG_RING_TCP_LISTEN: - /* add sock htable */ - tcp_sock = gazelle_sock_add_by_ipporttid(gazelle_get_tcp_sock_htable(), -- transfer_qtuple.dst_ip, transfer_qtuple.dst_port, msg->tid); -+ transfer_qtuple.dst_ip.u_addr.ip4.addr, transfer_qtuple.dst_port, msg->tid); - if (tcp_sock == NULL) { - LTRAN_ERR("add tcp sock htable failed\n"); - break; -@@ -506,7 +506,7 @@ static void tcp_hash_table_modify(struct gazelle_stack *stack, const struct reg_ - case REG_RING_TCP_LISTEN_CLOSE: - /* del sock htable */ - gazelle_sock_del_by_ipporttid(gazelle_get_tcp_sock_htable(), -- transfer_qtuple.dst_ip, transfer_qtuple.dst_port, msg->tid); -+ transfer_qtuple.dst_ip.u_addr.ip4.addr, transfer_qtuple.dst_port, msg->tid); - break; - case REG_RING_TCP_CONNECT: - /* add conn htable */ -diff --git a/src/ltran/ltran_stat.c b/src/ltran/ltran_stat.c -index 2a0c03a..dfd5fc9 100644 ---- a/src/ltran/ltran_stat.c -+++ b/src/ltran/ltran_stat.c -@@ -267,8 +267,8 @@ void handle_resp_ltran_conn(int32_t fd) - if (index < GAZELLE_LSTACK_MAX_CONN) { - forward_table.conn_list[index].protocol = conn->quintuple.protocol; - forward_table.conn_list[index].tid = conn->tid; -- forward_table.conn_list[index].dst_ip = conn->quintuple.dst_ip; -- forward_table.conn_list[index].src_ip = conn->quintuple.src_ip; -+ forward_table.conn_list[index].dst_ip = conn->quintuple.dst_ip.u_addr.ip4.addr; -+ forward_table.conn_list[index].src_ip = conn->quintuple.src_ip.u_addr.ip4.addr; - forward_table.conn_list[index].dst_port = ntohs(conn->quintuple.dst_port); - forward_table.conn_list[index].src_port = ntohs(conn->quintuple.src_port); - } -diff --git a/src/ltran/ltran_tcp_conn.c b/src/ltran/ltran_tcp_conn.c -index e0ad562..026d22a 100644 ---- a/src/ltran/ltran_tcp_conn.c -+++ b/src/ltran/ltran_tcp_conn.c -@@ -78,8 +78,8 @@ struct gazelle_tcp_conn_hbucket *gazelle_conn_hbucket_get(struct gazelle_tcp_con - const struct gazelle_quintuple *quintuple) - { - uint32_t index; -- index = tuple_hash_fn(quintuple->src_ip, quintuple->src_port, quintuple->dst_ip, quintuple->dst_port) % -- GAZELLE_MAX_CONN_HTABLE_SIZE; -+ index = tuple_hash_fn(quintuple->src_ip.u_addr.ip4.addr, quintuple->src_port, quintuple->dst_ip.u_addr.ip4.addr, -+ quintuple->dst_port) % GAZELLE_MAX_CONN_HTABLE_SIZE; - return &conn_htable->array[index]; - } - -diff --git a/src/ltran/ltran_tcp_sock.c b/src/ltran/ltran_tcp_sock.c -index d6a0d17..940ded8 100644 ---- a/src/ltran/ltran_tcp_sock.c -+++ b/src/ltran/ltran_tcp_sock.c -@@ -104,8 +104,8 @@ static void recover_sock_info_from_conn(struct gazelle_tcp_sock *tcp_sock) - head = &conn_htable->array[i].chain; - - hlist_for_each_entry(conn, node, head, conn_node) { -- if ((conn->quintuple.dst_ip != tcp_sock->ip) || (conn->quintuple.dst_port != tcp_sock->port) || -- (conn->tid != tcp_sock->tid)) { -+ if ((conn->quintuple.dst_ip.u_addr.ip4.addr != tcp_sock->ip) || -+ (conn->quintuple.dst_port != tcp_sock->port) || (conn->tid != tcp_sock->tid)) { - continue; - } - count++; -diff --git a/src/ltran/ltran_timer.c b/src/ltran/ltran_timer.c -index 85ea324..96c622e 100644 ---- a/src/ltran/ltran_timer.c -+++ b/src/ltran/ltran_timer.c -@@ -103,8 +103,8 @@ void gazelle_detect_conn_logout(struct gazelle_tcp_conn_htable *conn_htable) - conn_htable->array[i].chain_size--; - LTRAN_DEBUG("delete the tcp conn htable: tid %u quintuple[%u %u %u %u %u]\n", - conn->tid, conn->quintuple.protocol, -- conn->quintuple.src_ip, (uint32_t)ntohs(conn->quintuple.src_port), -- conn->quintuple.dst_ip, (uint32_t)ntohs(conn->quintuple.dst_port)); -+ conn->quintuple.src_ip.u_addr.ip4.addr, (uint32_t)ntohs(conn->quintuple.src_port), -+ conn->quintuple.dst_ip.u_addr.ip4.addr, (uint32_t)ntohs(conn->quintuple.dst_port)); - rte_free(conn); - } - } --- -2.33.0 - diff --git a/0109-match_host_addr-func-support-ipv6.patch b/0109-match_host_addr-func-support-ipv6.patch deleted file mode 100644 index 0e55ed22b388ad507d87b4ba8297066f2691aa45..0000000000000000000000000000000000000000 --- a/0109-match_host_addr-func-support-ipv6.patch +++ /dev/null @@ -1,103 +0,0 @@ -From 2489b4b21632c9016f87c6fe963d27ef3e20951b Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Fri, 5 Jan 2024 14:32:48 +0800 -Subject: [PATCH] match_host_addr func support ipv6 - ---- - src/lstack/api/lstack_wrap.c | 12 +++++++++++- - src/lstack/core/lstack_cfg.c | 12 +++++++++--- - src/lstack/core/lstack_control_plane.c | 2 +- - src/lstack/include/lstack_cfg.h | 2 +- - src/lstack/netif/lstack_vdev.c | 2 +- - 5 files changed, 23 insertions(+), 7 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 56f89b2..3db62c7 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -217,7 +217,17 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - return g_wrap_api->bind_fn(s, name, namelen); - } - -- if (match_host_addr(((struct sockaddr_in *)name)->sin_addr.s_addr)) { -+ ip_addr_t sock_addr = IPADDR_ANY_TYPE_INIT; -+ if (name->sa_family == AF_INET) { -+ sock_addr.type = IPADDR_TYPE_V4; -+ sock_addr.u_addr.ip4.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr; -+ } else if (name->sa_family == AF_INET6) { -+ sock_addr.type = IPADDR_TYPE_V6; -+ memcpy_s(sock_addr.u_addr.ip6.addr, IPV6_ADDR_LEN, -+ ((struct sockaddr_in6 *)name)->sin6_addr.s6_addr, IPV6_ADDR_LEN); -+ } -+ -+ if (match_host_addr(&sock_addr)) { - /* maybe kni addr */ - if (posix_api->bind_fn(s, name, namelen) != 0) { - SET_CONN_TYPE_LIBOS(sock->conn); -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index d9c23fb..c1f5680 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -253,11 +253,17 @@ static int32_t parse_host_addr6(void) - return 0; - } - --int32_t match_host_addr(uint32_t addr) -+int32_t match_host_addr(ip_addr_t *addr) - { - /* network byte order */ -- if (addr == g_config_params.host_addr.addr || addr == INADDR_ANY) { -- return 1; -+ if (IP_IS_V4_VAL(*addr)) { -+ if (ip4_addr_cmp(&addr->u_addr.ip4, &g_config_params.host_addr) || ip4_addr_isany_val(addr->u_addr.ip4)) { -+ return 1; -+ } -+ } else if (IP_IS_V6_VAL(*addr)) { -+ if (ip6_addr_cmp(&addr->u_addr.ip6, &g_config_params.host_addr6) || ip6_addr_isany_val(addr->u_addr.ip6)) { -+ return 1; -+ } - } - return 0; - } -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 2d629c8..a9a3814 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -366,7 +366,7 @@ static int32_t reg_conn(enum tcp_list_state table_state, enum reg_ring_type reg_ - qtuple.dst_ip = conn->conn_list[i].rip; - qtuple.dst_port = lwip_htons(conn->conn_list[i].r_port); - -- if ((table_state == LISTEN_LIST) && (!match_host_addr(qtuple.src_ip.u_addr.ip4.addr))) { -+ if ((table_state == LISTEN_LIST) && (!match_host_addr((ip_addr_t *)&qtuple.src_ip))) { - continue; - } - -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 82e96d8..c1074f8 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -133,7 +133,7 @@ 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 match_host_addr(uint32_t ipv4); -+int match_host_addr(ip_addr_t *addr); - int32_t init_stack_numa_cpuset(struct protocol_stack *stack); - - #endif /* GAZELLE_NET_CFG_H */ -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 9a79dc3..c845f7a 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -230,7 +230,7 @@ int32_t vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple) - struct protocol_stack *stack = get_protocol_stack(); - - if (type == REG_RING_TCP_LISTEN || type == REG_RING_TCP_LISTEN_CLOSE) { -- if (!match_host_addr(qtuple->src_ip.u_addr.ip4.addr)) { -+ if (!match_host_addr((ip_addr_t *)&qtuple->src_ip)) { - LSTACK_LOG(INFO, LSTACK, "lstack ip not match in conf.\n"); - return 0; - } --- -2.33.0 - diff --git a/0110-add-example-keep-alive-interval-para.patch b/0110-add-example-keep-alive-interval-para.patch deleted file mode 100644 index c97ee421271dfb5387cb6a2773729c7a283534c4..0000000000000000000000000000000000000000 --- a/0110-add-example-keep-alive-interval-para.patch +++ /dev/null @@ -1,27 +0,0 @@ -From f2770a0dd75007d152bdb346e16009227a6d55fa Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Thu, 4 Jan 2024 16:08:02 +0800 -Subject: [PATCH] add example keep-alive interval para - ---- - src/ltran/ltran_dfx.c | 4 ++-- - 8 files changed, 47 insertions(+), 8 deletions(-) - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 08c9da3..5e22e20 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -1002,8 +1002,8 @@ static void gazelle_keepalive_string(char* str, int buff_len, struct gazelle_sta - if (conn_info->keepalive == 0) { - return; - } -- int ret = sprintf_s(str, buff_len, "(%u,%u,%u)", conn_info->keep_idle, conn_info->keep_intvl, -- conn_info->keep_cnt); -+ int ret = sprintf_s(str, buff_len, "(%u,%u,%u)", (conn_info->keep_idle) / 1000, -+ (conn_info->keep_intvl) / 1000, conn_info->keep_cnt); - if (ret < 0) { - printf("gazelle_keepalive_string sprintf_s fail ret=%d\n", ret); - return; --- -2.33.0 - diff --git a/0111-update-src-common-dpdk_common.c.patch b/0111-update-src-common-dpdk_common.c.patch deleted file mode 100644 index a7aa72cce3efa5f2ee94b4b0309b558f37401a0c..0000000000000000000000000000000000000000 --- a/0111-update-src-common-dpdk_common.c.patch +++ /dev/null @@ -1,68 +0,0 @@ -From c6a7e8224dd9faff9120be8814638fe939570908 Mon Sep 17 00:00:00 2001 -From: Caohongtao -Date: Thu, 4 Jan 2024 09:34:04 +0000 -Subject: [PATCH] update src/common/dpdk_common.c. - -Signed-off-by: Caohongtao ---- - src/common/dpdk_common.c | 12 ++++++------ - 1 file changed, 6 insertions(+), 6 deletions(-) - -diff --git a/src/common/dpdk_common.c b/src/common/dpdk_common.c -index 50f0bf0..62278c2 100644 ---- a/src/common/dpdk_common.c -+++ b/src/common/dpdk_common.c -@@ -65,13 +65,13 @@ static int32_t kni_config_network_interface(uint16_t port_id, uint8_t if_up) - g_bond_dev_started = true; - } - } else { -- COMMON_INFO("trying to start a started dev. \n"); -+ COMMON_INFO("Trying to start a started dev. \n"); - } - } else { /* Configure network interface down */ - if (g_kni_started) { - g_kni_started = false; - } else { -- COMMON_INFO("trying to stop a stopped dev. \n"); -+ COMMON_INFO("Trying to stop a stopped dev. \n"); - } - } - -@@ -154,7 +154,7 @@ void eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev - conf->rxmode.offloads = rx_ol; - conf->txmode.offloads = tx_ol; - -- COMMON_INFO("set checksum offloads\n"); -+ COMMON_INFO("Set checksum offloads\n"); - } - - int32_t dpdk_kni_init(uint16_t port, struct rte_mempool *pool) -@@ -179,14 +179,14 @@ int32_t dpdk_kni_init(uint16_t port, struct rte_mempool *pool) - - ret = snprintf_s(conf.name, RTE_KNI_NAMESIZE, RTE_KNI_NAMESIZE - 1, "%s", GAZELLE_KNI_NAME); - if (ret < 0) { -- COMMON_ERR("snprintf_s failed. ret=%d\n", ret); -+ COMMON_ERR("Snprintf_s failed. ret=%d\n", ret); - return -1; - } - conf.mbuf_size = GAZELLE_MAX_PKT_SZ; - conf.group_id = port; - - if (rte_eth_dev_info_get(port, &dev_info) != 0) { -- COMMON_ERR("Fail rte_eth_dev_info_get\n"); -+ COMMON_ERR("Failed rte_eth_dev_info_get\n"); - return -1; - } - -@@ -204,7 +204,7 @@ int32_t dpdk_kni_init(uint16_t port, struct rte_mempool *pool) - ops.port_id = port; - g_pkni = rte_kni_alloc(pool, &conf, &ops); - if (g_pkni == NULL) { -- COMMON_ERR("Fail to create kni for port: %hu \n", port); -+ COMMON_ERR("Failed to create kni for port: %hu \n", port); - return -1; - } - return 0; --- -2.33.0 - diff --git a/0112-listen_shadow-support-ipv6.patch b/0112-listen_shadow-support-ipv6.patch deleted file mode 100644 index 35949ab2bff178b297efe32765387179d686f3d7..0000000000000000000000000000000000000000 --- a/0112-listen_shadow-support-ipv6.patch +++ /dev/null @@ -1,51 +0,0 @@ -From 0fddaa74aa71ec25ee9cb1db141dd8a778e6e76d Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Mon, 8 Jan 2024 15:08:24 +0800 -Subject: [PATCH] listen_shadow support ipv6 - ---- - src/lstack/core/lstack_protocol_stack.c | 12 +++++++++--- - 1 file changed, 9 insertions(+), 3 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index f849bcd..e7b541e 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -1128,9 +1128,15 @@ int32_t stack_single_listen(int32_t fd, int32_t backlog) - /* listen sync to all protocol stack thread, so that any protocol stack thread can build connect */ - int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) - { -+ typedef union sockaddr_union { -+ struct sockaddr sa; -+ struct sockaddr_in in; -+ struct sockaddr_in6 in6; -+ } sockaddr_t; -+ - struct protocol_stack *cur_stack = get_protocol_stack_by_fd(fd); - struct protocol_stack *stack = NULL; -- struct sockaddr addr; -+ sockaddr_t addr; - socklen_t addr_len = sizeof(addr); - int32_t ret, clone_fd; - -@@ -1140,7 +1146,7 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) - GAZELLE_RETURN(EINVAL); - } - -- ret = rpc_call_getsockname(fd, &addr, &addr_len); -+ ret = rpc_call_getsockname(fd, (struct sockaddr *)&addr, &addr_len); - if (ret != 0) { - return ret; - } -@@ -1154,7 +1160,7 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) - continue; - } - if (stack != cur_stack) { -- clone_fd = rpc_call_shadow_fd(stack, fd, &addr, sizeof(addr)); -+ clone_fd = rpc_call_shadow_fd(stack, fd, (struct sockaddr *)&addr, addr_len); - if (clone_fd < 0) { - stack_broadcast_close(fd); - return clone_fd; --- -2.33.0 - diff --git a/0113-lstack_dpdk-limit-mbuf-max-num.patch b/0113-lstack_dpdk-limit-mbuf-max-num.patch deleted file mode 100644 index 6ced2f7001e6e64bd91935f8c30dc15aec47485d..0000000000000000000000000000000000000000 --- a/0113-lstack_dpdk-limit-mbuf-max-num.patch +++ /dev/null @@ -1,78 +0,0 @@ -From aa0bd688a6dae115e136771fda747c9428e65561 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Tue, 2 Jan 2024 09:32:00 +0800 -Subject: [PATCH] lstack_dpdk: limit mbuf max num - ---- - src/lstack/core/lstack_dpdk.c | 5 +++++ - src/lstack/include/lstack_dpdk.h | 18 ++++++++---------- - src/ltran/main.c | 2 +- - 3 files changed, 14 insertions(+), 11 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 729a84c..580dd1d 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -155,6 +155,11 @@ struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, - LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d \n", ret); - return NULL; - } -+ /* limit mbuf max num based on the dpdk capability */ -+ if (nb_mbuf > MBUF_MAX_NUM) { -+ LSTACK_LOG(ERR, LSTACK, "out of the dpdk mbuf quantity range\n"); -+ return NULL; -+ } - - /* time stamp before pbuf_custom as priv_data */ - uint16_t private_size = RTE_ALIGN(sizeof(struct mbuf_private), RTE_CACHE_LINE_SIZE); -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index 4a160e0..2a44c6e 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -17,22 +17,20 @@ - #include "gazelle_opt.h" - #include "gazelle_dfx_msg.h" - --#define RXTX_CACHE_SZ (VDEV_RX_QUEUE_SZ) --#define KNI_NB_MBUF (DEFAULT_RING_SIZE << 4) -+#define RXTX_CACHE_SZ (VDEV_RX_QUEUE_SZ) - --#define RESERVE_NIC_RECV (1024) -+#define KNI_NB_MBUF (DEFAULT_RING_SIZE << 4) - --#define MBUF_HEADER_LEN 64 -- --#define MAX_PACKET_SZ 2048 -+#define MAX_PACKET_SZ 2048 - - #define RING_SIZE(x) ((x) - 1) - --#define MBUF_SZ (MAX_PACKET_SZ + RTE_PKTMBUF_HEADROOM) -+#define MBUF_SZ (MAX_PACKET_SZ + RTE_PKTMBUF_HEADROOM) - --#define MAX_CORE_NUM 256 --#define CALL_MSG_RING_SIZE (unsigned long long)32 --#define CALL_CACHE_SZ 0 -+/* DPDK limit ring head-tail distance in rte_ring_init. -+ * Max value is RTE_RING_SZ_MASK / HTD_MAX_DEF, RTE_RING_SZ_MASK is 0x7fffffff, HTD_MAX_DEF is 8. -+ */ -+#define MBUF_MAX_NUM 0xfffffff - - int thread_affinity_default(void); - int thread_affinity_init(int cpu_id); -diff --git a/src/ltran/main.c b/src/ltran/main.c -index 87f1e14..c2598a7 100644 ---- a/src/ltran/main.c -+++ b/src/ltran/main.c -@@ -55,7 +55,7 @@ static void print_stack(void) - - static void sig_default_handler(int32_t sig) - { -- LTRAN_ERR("ltran dumped,caught signal:%d.\n", sig); -+ LTRAN_ERR("ltran dumped, caught signal: %d.\n", sig); - print_stack(); - dpdk_kni_release(); - int ret = 0; --- -2.33.0 - diff --git a/0114-gazellectl-add-tcp_input-empty-ack-cnt.patch b/0114-gazellectl-add-tcp_input-empty-ack-cnt.patch deleted file mode 100644 index 8485e0261c975086c312300eb8e704c8e5406e04..0000000000000000000000000000000000000000 --- a/0114-gazellectl-add-tcp_input-empty-ack-cnt.patch +++ /dev/null @@ -1,66 +0,0 @@ -From 295ad7d27233404457488089453a51d39e4d8038 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Mon, 8 Jan 2024 09:12:59 +0800 -Subject: [PATCH] gazellectl: add tcp_input empty ack cnt - ---- - src/common/gazelle_dfx_msg.h | 1 + - src/ltran/ltran_dfx.c | 29 +++++++++++++++-------------- - 2 files changed, 16 insertions(+), 14 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 478c440..d58a072 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -143,6 +143,7 @@ struct gazelle_stat_lstack_snmp { - uint32_t tcp_out_of_seq; - uint32_t tcp_acceptmbox_full; - uint32_t tcp_listen_drops; -+ uint32_t tcp_in_empty_acks; - - /* UDP */ - uint32_t udp_in_datagrams; -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 08c9da3..5d4e74c 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -855,21 +855,22 @@ static void gazelle_print_lstack_stat_rate(void *buf, const struct gazelle_stat_ - - static void gazelle_print_lstack_tcp_stat(const struct gazelle_stat_lstack_snmp *snmp) - { -- printf("tcp_act_open: %u\n", snmp->tcp_act_open); -- printf("tcp_passive_open: %u\n", snmp->tcp_passive_open); -- printf("tcp_attempt_fail: %u\n", snmp->tcp_attempt_fail); -- printf("tcp_estab_rst: %u\n", snmp->tcp_estab_rst); -- printf("tcp_out_seg: %u\n", snmp->tcp_out_seg); -- printf("tcp_retran_seg: %u\n", snmp->tcp_retran_seg); -- printf("tcp_in_seg: %u\n", snmp->tcp_in_seg); -- printf("tcp_in_err: %u\n", snmp->tcp_in_err); -- printf("tcp_out_rst: %u\n", snmp->tcp_out_rst); -- printf("tcp_fin_ack_cnt: %u\n", snmp->tcp_fin_ack_cnt); -- printf("tcp_delay_ack_cnt: %u\n", snmp->tcp_delay_ack_cnt); -- printf("tcp_refused_cnt: %u\n", snmp->tcp_refused_cnt); -- printf("tcp_out_of_seq: %u\n", snmp->tcp_out_of_seq); -+ printf("tcp_act_open: %u\n", snmp->tcp_act_open); -+ printf("tcp_passive_open: %u\n", snmp->tcp_passive_open); -+ printf("tcp_attempt_fail: %u\n", snmp->tcp_attempt_fail); -+ printf("tcp_estab_rst: %u\n", snmp->tcp_estab_rst); -+ printf("tcp_out_seg: %u\n", snmp->tcp_out_seg); -+ printf("tcp_retran_seg: %u\n", snmp->tcp_retran_seg); -+ printf("tcp_in_seg: %u\n", snmp->tcp_in_seg); -+ printf("tcp_in_err: %u\n", snmp->tcp_in_err); -+ printf("tcp_out_rst: %u\n", snmp->tcp_out_rst); -+ printf("tcp_fin_ack_cnt: %u\n", snmp->tcp_fin_ack_cnt); -+ printf("tcp_delay_ack_cnt: %u\n", snmp->tcp_delay_ack_cnt); -+ printf("tcp_refused_cnt: %u\n", snmp->tcp_refused_cnt); -+ printf("tcp_out_of_seq: %u\n", snmp->tcp_out_of_seq); - printf("tcp_acceptmbox_full: %u\n", snmp->tcp_acceptmbox_full); -- printf("tcp_listen_drops: %u\n", snmp->tcp_listen_drops); -+ printf("tcp_listen_drops: %u\n", snmp->tcp_listen_drops); -+ printf("tcp_in_empty_acks: %u\n", snmp->tcp_in_empty_acks); - } - - static void gazelle_print_ltran_stat_lb_rate(void *buf, const struct gazelle_stat_msg_request *req_msg) --- -2.33.0 - diff --git a/0115-add-socket-accept-fail-cnt.patch b/0115-add-socket-accept-fail-cnt.patch deleted file mode 100644 index 4be8bde79e0e28f81cd5b4d7e859537a62f1161f..0000000000000000000000000000000000000000 --- a/0115-add-socket-accept-fail-cnt.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 53457e3ab329eb944579ffe55ddc4435e0bca0a1 Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Wed, 10 Jan 2024 09:12:34 +0800 -Subject: [PATCH] add socket accept fail cnt - ---- - src/common/gazelle_dfx_msg.h | 1 + - src/lstack/core/lstack_protocol_stack.c | 2 ++ - src/ltran/ltran_dfx.c | 1 + - 3 files changed, 4 insertions(+) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 478c440..1d3249d 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -72,6 +72,7 @@ struct gazelle_stack_stat { - uint64_t tx_drop; - uint64_t tx; - uint64_t tx_prepare_fail; -+ uint64_t accept_fail; - }; - - struct gazelle_wakeup_stat { -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index f849bcd..0d845dd 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -792,9 +792,11 @@ void stack_accept(struct rpc_msg *msg) - { - int32_t fd = msg->args[MSG_ARG_0].i; - msg->result = -1; -+ struct protocol_stack *stack = get_protocol_stack(); - - int32_t accept_fd = lwip_accept4(fd, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].p, msg->args[MSG_ARG_3].i); - if (accept_fd < 0) { -+ stack->stats.accept_fail++; - LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); - return; - } -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 5e22e20..461912f 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -646,6 +646,7 @@ static void show_lstack_stats(struct gazelle_stack_dfx_data *lstack_stat) - printf("send_pkts_fail: %-13"PRIu64" ", lstack_stat->data.pkts.stack_stat.send_pkts_fail); - printf("mbuf_pool_freecnt: %-10"PRIu32" ", lstack_stat->data.pkts.mbufpool_avail_cnt); - printf("rpc_pool_freecnt: %-12"PRIu32" \n", lstack_stat->data.pkts.rpcpool_avail_cnt); -+ printf("accpet_fail: %-12"PRIu64" \n", lstack_stat->data.pkts.stack_stat.accept_fail); - } - - static void gazelle_print_lstack_stat_detail(struct gazelle_stack_dfx_data *lstack_stat, --- -2.33.0 - diff --git a/0116-diff-lstack-and-ltran-dfx-sock.patch b/0116-diff-lstack-and-ltran-dfx-sock.patch deleted file mode 100644 index 5a7adaa5186fb46aab8eedc70007ebd9671fcfed..0000000000000000000000000000000000000000 --- a/0116-diff-lstack-and-ltran-dfx-sock.patch +++ /dev/null @@ -1,137 +0,0 @@ -From db89062f34f8bcccf80a82d6589e5f3b5bc63cfe Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Sat, 13 Jan 2024 17:03:07 +0800 -Subject: [PATCH] diff lstack and ltran dfx sock - ---- - src/common/gazelle_opt.h | 9 +++++++-- - src/lstack/core/lstack_cfg.c | 10 ++++++++-- - src/ltran/ltran_base.h | 3 --- - src/ltran/ltran_dfx.c | 8 ++++---- - src/ltran/ltran_monitor.c | 8 ++++---- - src/ltran/ltran_param.c | 4 ++-- - 6 files changed, 25 insertions(+), 17 deletions(-) - -diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h -index 36915c6..1d1c5f5 100644 ---- a/src/common/gazelle_opt.h -+++ b/src/common/gazelle_opt.h -@@ -85,8 +85,13 @@ - - #define GAZELLE_MAX_STACK_ARRAY_SIZE GAZELLE_CLIENT_NUM - --#define GAZELLE_REG_SOCK_PATHNAME "/var/run/gazelle/gazelle_client.sock" --#define GAZELLE_REG_SOCK_FILENAME "gazelle_client.sock" -+#define LTRAN_REG_SOCK_PATHNAME "/var/run/gazelle/ltran_client.sock" -+#define LTRAN_REG_SOCK_FILENAME "ltran_client.sock" -+#define LTRAN_DFX_SOCK_PATHNAME "/var/run/gazelle/ltran_cmd.sock" -+#define LTRAN_DFX_SOCK_FILENAME "ltran_cmd.sock" -+#define LSTACK_DFX_SOCK_PATHNAME "/var/run/gazelle/lstack_cmd.sock" -+#define LSTACK_DFX_SOCK_FILENAME "lstack_cmd.sock" -+ - #define GAZELLE_SOCK_FILENAME_MAXLEN 128 - - #define GAZELLE_RUN_DIR "/var/run/gazelle/" -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index c1f5680..87df790 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -1043,8 +1043,14 @@ static int32_t parse_unix_prefix(void) - } - } - -- ret = strncat_s(g_config_params.unix_socket_filename, sizeof(g_config_params.unix_socket_filename), -- GAZELLE_REG_SOCK_FILENAME, strlen(GAZELLE_REG_SOCK_FILENAME) + 1); -+ 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); -+ } 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); -+ } -+ - if (ret != EOK) { - return ret; - } -diff --git a/src/ltran/ltran_base.h b/src/ltran/ltran_base.h -index 6be9152..f174a40 100644 ---- a/src/ltran/ltran_base.h -+++ b/src/ltran/ltran_base.h -@@ -98,7 +98,4 @@ - - #define GAZELLE_INET_ADDRSTRLEN 16 - --#define GAZELLE_DFX_SOCK_PATHNAME "/var/run/gazelle/gazelle_cmd.sock" --#define GAZELLE_DFX_SOCK_FILENAME "gazelle_cmd.sock" -- - #endif /* ifndef __GAZELLE_BASE_H__ */ -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index a64c1d5..05234de 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -254,15 +254,15 @@ static int32_t dfx_connect_ltran(bool use_ltran, bool probe) - - addr.sun_family = AF_UNIX; - if (use_ltran) { -- ret = strncat_s(addr.sun_path, sizeof(addr.sun_path), GAZELLE_DFX_SOCK_FILENAME, -- strlen(GAZELLE_DFX_SOCK_FILENAME) + 1); -+ ret = strncat_s(addr.sun_path, sizeof(addr.sun_path), LTRAN_DFX_SOCK_FILENAME, -+ strlen(LTRAN_DFX_SOCK_FILENAME) + 1); - if (ret != EOK) { - printf("%s:%d strncat_s fail ret=%d\n", __FUNCTION__, __LINE__, ret); - goto END; - } - } else { -- ret = strncat_s(addr.sun_path, sizeof(addr.sun_path), GAZELLE_REG_SOCK_FILENAME, -- strlen(GAZELLE_REG_SOCK_FILENAME) + 1); -+ ret = strncat_s(addr.sun_path, sizeof(addr.sun_path), LSTACK_DFX_SOCK_FILENAME, -+ strlen(LSTACK_DFX_SOCK_FILENAME) + 1); - if (ret != EOK) { - printf("%s:%d strncat_s fail ret=%d\n", __FUNCTION__, __LINE__, ret); - goto END; -diff --git a/src/ltran/ltran_monitor.c b/src/ltran/ltran_monitor.c -index b2bcc07..ea31e84 100644 ---- a/src/ltran/ltran_monitor.c -+++ b/src/ltran/ltran_monitor.c -@@ -238,13 +238,13 @@ static void gazelle_ctl_destroy(void) - close(g_epoll_fd); - g_epoll_fd = -1; - -- ret = unlink(GAZELLE_DFX_SOCK_PATHNAME); -+ ret = unlink(LTRAN_DFX_SOCK_PATHNAME); - if (ret != 0) { -- LTRAN_WARN("unlink %s ERROR. errno: %d. ret=%d\n", GAZELLE_DFX_SOCK_PATHNAME, errno, ret); -+ LTRAN_WARN("unlink %s ERROR. errno: %d. ret=%d\n", LTRAN_DFX_SOCK_PATHNAME, errno, ret); - } -- ret = unlink(GAZELLE_REG_SOCK_PATHNAME); -+ ret = unlink(LTRAN_REG_SOCK_PATHNAME); - if (ret != 0) { -- LTRAN_WARN("unlink %s ERROR. errno: %d. ret=%d\n", GAZELLE_REG_SOCK_PATHNAME, errno, ret); -+ LTRAN_WARN("unlink %s ERROR. errno: %d. ret=%d\n", LTRAN_REG_SOCK_PATHNAME, errno, ret); - } - } - -diff --git a/src/ltran/ltran_param.c b/src/ltran/ltran_param.c -index 1eaace4..bd5a8e1 100644 ---- a/src/ltran/ltran_param.c -+++ b/src/ltran/ltran_param.c -@@ -598,14 +598,14 @@ static int32_t parse_unix_prefix(const config_t *config, const char *key, struct - } - - ret = strncat_s(ltran_config->unix_socket_filename, sizeof(ltran_config->unix_socket_filename), -- GAZELLE_REG_SOCK_FILENAME, strlen(GAZELLE_REG_SOCK_FILENAME) + 1); -+ LTRAN_REG_SOCK_FILENAME, strlen(LTRAN_REG_SOCK_FILENAME) + 1); - if (ret != EOK) { - gazelle_set_errno(GAZELLE_EINETATON); - return GAZELLE_ERR; - } - - ret = strncat_s(ltran_config->dfx_socket_filename, sizeof(ltran_config->dfx_socket_filename), -- GAZELLE_DFX_SOCK_FILENAME, strlen(GAZELLE_DFX_SOCK_FILENAME) + 1); -+ LTRAN_DFX_SOCK_FILENAME, strlen(LTRAN_DFX_SOCK_FILENAME) + 1); - if (ret != EOK) { - gazelle_set_errno(GAZELLE_EINETATON); - return GAZELLE_ERR; --- -2.33.0 - diff --git a/0117-fix-host_addr6-can-be-assigned-a-multicast-address.patch b/0117-fix-host_addr6-can-be-assigned-a-multicast-address.patch deleted file mode 100644 index a99e7c174a00e0b25e0ff6119e9c0be4f48ba0bb..0000000000000000000000000000000000000000 --- a/0117-fix-host_addr6-can-be-assigned-a-multicast-address.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 7c8d80e76f93029437f9a52f04c9d02b0d55dd78 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Tue, 16 Jan 2024 23:52:23 +0800 -Subject: [PATCH] fix host_addr6 can be assigned a multicast address - ---- - src/lstack/core/lstack_cfg.c | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 87df790..5e30e89 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -250,6 +250,12 @@ static int32_t parse_host_addr6(void) - if (ip6addr_aton(value, &g_config_params.host_addr6) == 0) { - return -EINVAL; - } -+ -+ if (ip6_addr_ismulticast(&g_config_params.host_addr6)) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: host_addr6 cannot be a multicast address."); -+ return -EINVAL; -+ } -+ - return 0; - } - --- -2.33.0 - diff --git a/0118-udp-do-not-merge-data-into-last-pbuf.patch b/0118-udp-do-not-merge-data-into-last-pbuf.patch deleted file mode 100644 index a3f557a493484c79f2da1b451f6c59762c489653..0000000000000000000000000000000000000000 --- a/0118-udp-do-not-merge-data-into-last-pbuf.patch +++ /dev/null @@ -1,45 +0,0 @@ -From b90801a943f140a62761158a058d1076212dccf3 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Thu, 18 Jan 2024 10:01:52 +0800 -Subject: [PATCH] udp: do not merge data into last pbuf - ---- - src/lstack/core/lstack_lwip.c | 9 +++++++-- - 1 file changed, 7 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 87ec1f5..6ebe589 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -542,14 +542,14 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - } - - struct protocol_stack *stack = sock->stack; -- if (!stack|| len == 0) { -+ if (!stack || len == 0) { - return 0; - } - - ssize_t send_len = 0; - - /* merge data into last pbuf */ -- if (sock->remain_len) { -+ if (!NETCONN_IS_UDP(sock) && sock->remain_len) { - send_len = merge_data_lastpbuf(sock, (char *)buf, len); - if (send_len >= len) { - send_len = len; -@@ -1045,6 +1045,11 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_READ); - } - gazelle_ring_read_over(sock->recv_ring); -+ -+ /* in udp, if pbuf remaining len less than copy_len, discard these packets */ -+ if (recvd > 0 && NETCONN_IS_UDP(sock)) { -+ break; -+ } - } - } - --- -2.33.0 - diff --git a/0119-adpat-dpdk-23.11.patch b/0119-adpat-dpdk-23.11.patch deleted file mode 100644 index 07b81bd964b7c0621e989c90a4b46bcbb27d05b7..0000000000000000000000000000000000000000 --- a/0119-adpat-dpdk-23.11.patch +++ /dev/null @@ -1,969 +0,0 @@ -From bbb97803a36a5de0bb6ca6ce0518a6ef0666a22b Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 15 Jan 2024 09:37:20 +0800 -Subject: [PATCH] adpat dpdk 23.11 - ---- - src/common/dpdk_common.c | 171 +++++++++++---------- - src/common/gazelle_parse_config.c | 1 + - src/lstack/Makefile | 50 +++--- - src/lstack/core/lstack_dpdk.c | 34 ++-- - src/lstack/core/lstack_init.c | 2 + - src/lstack/core/lstack_protocol_stack.c | 12 +- - src/lstack/include/lstack_ethdev.h | 8 + - src/lstack/include/lstack_protocol_stack.h | 1 - - src/lstack/netif/lstack_ethdev.c | 8 + - src/lstack/netif/lstack_vdev.c | 4 +- - src/ltran/CMakeLists.txt | 33 +++- - src/ltran/ltran_dfx.c | 20 +-- - src/ltran/ltran_ethdev.c | 29 +++- - src/ltran/ltran_forward.c | 14 ++ - src/ltran/ltran_stack.c | 1 + - src/ltran/ltran_timer.c | 1 + - src/ltran/main.c | 6 + - 17 files changed, 254 insertions(+), 141 deletions(-) - -diff --git a/src/common/dpdk_common.c b/src/common/dpdk_common.c -index 62278c2..c0c4f63 100644 ---- a/src/common/dpdk_common.c -+++ b/src/common/dpdk_common.c -@@ -10,18 +10,21 @@ - * See the Mulan PSL v2 for more details. - */ - --#include -+#include - #include - #include - #include - #include - #include --#include -+#include -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) -+#include -+#endif -+ -+#include - - #include "dpdk_common.h" - --#define GAZELLE_KNI_IFACES_NUM 1 --#define GAZELLE_KNI_READ_SIZE 32 - #define GAZELLE_MAX_PKT_SZ 2048 - - #ifdef LTRAN_COMPILE -@@ -34,6 +37,9 @@ - #define COMMON_INFO(fmt, ...) LSTACK_LOG(INFO, LSTACK, fmt, ##__VA_ARGS__) - #endif - -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) -+#define GAZELLE_KNI_IFACES_NUM 1 -+#define GAZELLE_KNI_READ_SIZE 32 - struct rte_kni *g_pkni = NULL; - static volatile bool g_kni_started = false; - -@@ -79,84 +85,6 @@ static int32_t kni_config_network_interface(uint16_t port_id, uint8_t if_up) - return ret; - } - --void eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev_info) --{ -- uint64_t rx_ol = 0; -- uint64_t tx_ol = 0; -- uint64_t rx_ol_capa = dev_info->rx_offload_capa; -- uint64_t tx_ol_capa = dev_info->tx_offload_capa; -- -- // rx ip -- if (rx_ol_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) { -- rx_ol |= DEV_RX_OFFLOAD_IPV4_CKSUM; -- COMMON_INFO("DEV_RX_OFFLOAD_IPV4_CKSUM\n"); -- } -- -- // rx tcp -- if (rx_ol_capa & DEV_RX_OFFLOAD_TCP_CKSUM) { -- rx_ol |= DEV_RX_OFFLOAD_TCP_CKSUM; -- COMMON_INFO("DEV_RX_OFFLOAD_TCP_CKSUM\n"); -- } -- -- // rx udp -- if (rx_ol_capa & DEV_RX_OFFLOAD_UDP_CKSUM) { -- rx_ol |= DEV_RX_OFFLOAD_UDP_CKSUM; -- COMMON_INFO("DEV_RX_OFFLOAD_UDP_CKSUM\n"); -- } -- -- // rx vlan -- if (rx_ol_capa & DEV_RX_OFFLOAD_VLAN_STRIP) { -- rx_ol |= DEV_RX_OFFLOAD_VLAN_STRIP; -- COMMON_INFO("DEV_RX_OFFLOAD_VLAN_STRIP\n"); -- } -- -- // tx ip -- if (tx_ol_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) { -- tx_ol |= DEV_TX_OFFLOAD_IPV4_CKSUM; -- COMMON_INFO("DEV_TX_OFFLOAD_IPV4_CKSUM\n"); -- } -- -- // tx tcp -- if (tx_ol_capa & DEV_TX_OFFLOAD_TCP_CKSUM) { -- tx_ol |= DEV_TX_OFFLOAD_TCP_CKSUM; -- COMMON_INFO("DEV_TX_OFFLOAD_TCP_CKSUM\n"); -- } -- -- // tx udp -- if (tx_ol_capa & DEV_TX_OFFLOAD_UDP_CKSUM) { -- tx_ol |= DEV_TX_OFFLOAD_UDP_CKSUM; -- COMMON_INFO("DEV_TX_OFFLOAD_UDP_CKSUM\n"); -- } -- -- // tx tso -- if (tx_ol_capa & DEV_TX_OFFLOAD_TCP_TSO) { -- tx_ol |= (DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_MULTI_SEGS); -- COMMON_INFO("DEV_TX_OFFLOAD_TCP_TSO\n"); -- } -- -- // tx vlan -- if (tx_ol_capa & DEV_TX_OFFLOAD_VLAN_INSERT) { -- tx_ol |= DEV_TX_OFFLOAD_VLAN_INSERT; -- COMMON_INFO("DEV_TX_OFFLOAD_VLAN_INSERT\n"); -- } -- -- if (!(rx_ol & DEV_RX_OFFLOAD_UDP_CKSUM) || -- !(rx_ol & DEV_RX_OFFLOAD_TCP_CKSUM) || -- !(rx_ol & DEV_RX_OFFLOAD_IPV4_CKSUM)) { -- rx_ol = 0; -- } -- if (!(tx_ol & DEV_TX_OFFLOAD_UDP_CKSUM) || -- !(tx_ol & DEV_TX_OFFLOAD_TCP_CKSUM) || -- !(tx_ol & DEV_TX_OFFLOAD_IPV4_CKSUM)) { -- tx_ol = 0; -- } -- -- conf->rxmode.offloads = rx_ol; -- conf->txmode.offloads = tx_ol; -- -- COMMON_INFO("Set checksum offloads\n"); --} -- - int32_t dpdk_kni_init(uint16_t port, struct rte_mempool *pool) - { - int32_t ret; -@@ -262,3 +190,82 @@ void kni_process_rx(uint16_t port) - } - } - } -+#endif -+ -+void eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev_info) -+{ -+ uint64_t rx_ol = 0; -+ uint64_t tx_ol = 0; -+ uint64_t rx_ol_capa = dev_info->rx_offload_capa; -+ uint64_t tx_ol_capa = dev_info->tx_offload_capa; -+ -+ // rx ip -+ if (rx_ol_capa & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM) { -+ rx_ol |= RTE_ETH_RX_OFFLOAD_IPV4_CKSUM; -+ COMMON_INFO("RTE_ETH_RX_OFFLOAD_IPV4_CKSUM\n"); -+ } -+ -+ // rx tcp -+ if (rx_ol_capa & RTE_ETH_RX_OFFLOAD_TCP_CKSUM) { -+ rx_ol |= RTE_ETH_RX_OFFLOAD_TCP_CKSUM; -+ COMMON_INFO("RTE_ETH_RX_OFFLOAD_TCP_CKSUM\n"); -+ } -+ -+ // rx udp -+ if (rx_ol_capa & RTE_ETH_RX_OFFLOAD_UDP_CKSUM) { -+ rx_ol |= RTE_ETH_RX_OFFLOAD_UDP_CKSUM; -+ COMMON_INFO("RTE_ETH_RX_OFFLOAD_UDP_CKSUM\n"); -+ } -+ -+ // rx vlan -+ if (rx_ol_capa & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) { -+ rx_ol |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP; -+ COMMON_INFO("RTE_ETH_RX_OFFLOAD_VLAN_STRIP\n"); -+ } -+ -+ // tx ip -+ if (tx_ol_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) { -+ tx_ol |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM; -+ COMMON_INFO("RTE_ETH_TX_OFFLOAD_IPV4_CKSUM\n"); -+ } -+ -+ // tx tcp -+ if (tx_ol_capa & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) { -+ tx_ol |= RTE_ETH_TX_OFFLOAD_TCP_CKSUM; -+ COMMON_INFO("RTE_ETH_TX_OFFLOAD_TCP_CKSUM\n"); -+ } -+ -+ // tx udp -+ if (tx_ol_capa & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) { -+ tx_ol |= RTE_ETH_TX_OFFLOAD_UDP_CKSUM; -+ COMMON_INFO("RTE_ETH_TX_OFFLOAD_UDP_CKSUM\n"); -+ } -+ -+ // tx tso -+ if (tx_ol_capa & RTE_ETH_TX_OFFLOAD_TCP_TSO) { -+ tx_ol |= (RTE_ETH_TX_OFFLOAD_TCP_TSO | RTE_ETH_TX_OFFLOAD_MULTI_SEGS); -+ COMMON_INFO("RTE_ETH_TX_OFFLOAD_TCP_TSO\n"); -+ } -+ -+ // tx vlan -+ if (tx_ol_capa & RTE_ETH_TX_OFFLOAD_VLAN_INSERT) { -+ tx_ol |= RTE_ETH_TX_OFFLOAD_VLAN_INSERT; -+ COMMON_INFO("RTE_ETH_TX_OFFLOAD_VLAN_INSERT\n"); -+ } -+ -+ if (!(rx_ol & RTE_ETH_RX_OFFLOAD_UDP_CKSUM) || -+ !(rx_ol & RTE_ETH_RX_OFFLOAD_TCP_CKSUM) || -+ !(rx_ol & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM)) { -+ rx_ol = 0; -+ } -+ if (!(tx_ol & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) || -+ !(tx_ol & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) || -+ !(tx_ol & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) { -+ tx_ol = 0; -+ } -+ -+ conf->rxmode.offloads = rx_ol; -+ conf->txmode.offloads = tx_ol; -+ -+ COMMON_INFO("Set checksum offloads\n"); -+} -diff --git a/src/common/gazelle_parse_config.c b/src/common/gazelle_parse_config.c -index 1adce78..0553f0d 100644 ---- a/src/common/gazelle_parse_config.c -+++ b/src/common/gazelle_parse_config.c -@@ -15,6 +15,7 @@ - #include - #include - #include -+#include - #include - #include - -diff --git a/src/lstack/Makefile b/src/lstack/Makefile -index d585040..df1ddaa 100644 ---- a/src/lstack/Makefile -+++ b/src/lstack/Makefile -@@ -7,17 +7,17 @@ - # IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - # PURPOSE. - # See the Mulan PSL v2 for more details. -- - LSTACK_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) - ROOT_DIR := $(dir $(abspath $(LSTACK_DIR))) - - LWIP_INCLUDE_FILE ?= /usr/include/lwip - LIB_PATH ?= /usr/lib64 - --ifeq ($(DPDK_VERSION_1911), 1) -- DPDK_INCLUDE_FILE ?= /usr/include/dpdk -+DPDK_VERSION := $(shell rpm -q --queryformat '%{VERSION}' dpdk) -+ifeq ($(DPDK_VERSION),21.11) -+ DPDK_INCLUDE_FILE := /usr/local/include - else -- DPDK_INCLUDE_FILE ?= /usr/local/include/ -+ DPDK_INCLUDE_FILE := /usr/include/dpdk - endif - - AR = ar -@@ -77,34 +77,36 @@ LIBRTE_LIB = $(LIB_PATH)/librte_pci.so \ - $(LIB_PATH)/librte_gro.so \ - $(LIB_PATH)/librte_ring.so \ - $(LIB_PATH)/librte_mbuf.so \ -- $(LIB_PATH)/librte_kni.so \ - $(LIB_PATH)/librte_kvargs.so \ - $(LIB_PATH)/librte_bus_vdev.so \ - $(LIB_PATH)/librte_net.so \ - $(LIB_PATH)/librte_ethdev.so \ -- $(LIB_PATH)/librte_pdump.so \ -+ $(LIB_PATH)/librte_pdump.so -+ -+ifeq ($(shell expr $(DPDK_VERSION) \< 23.11), 1) -+ LIBRTE_LIB += $(LIB_PATH)/librte_kni.so -+endif - --ifeq ($(DPDK_VERSION_1911), 1) -- CFLAGS += -DDPDK_VERSION_1911=1 -+ifeq ($(DPDK_VERSION), 19.11) - LIBRTE_LIB += $(LIB_PATH)/librte_pmd_pcap.so \ -- $(LIB_PATH)/librte_pmd_bond.so \ -- $(LIB_PATH)/librte_pmd_hinic.so \ -- $(LIB_PATH)/librte_pmd_ixgbe.so \ -- $(LIB_PATH)/librte_pmd_virtio.so -- ifneq ($(ARCH), loongarch64) -- LIBRTE_LIB += $(LIB_PATH)/librte_pmd_i40e.so -- endif -+ $(LIB_PATH)/librte_pmd_bond.so \ -+ $(LIB_PATH)/librte_pmd_hinic.so \ -+ $(LIB_PATH)/librte_pmd_ixgbe.so \ -+ $(LIB_PATH)/librte_pmd_virtio.so -+ ifneq ($(ARCH), loongarch64) -+ LIBRTE_LIB += $(LIB_PATH)/librte_pmd_i40e.so -+ endif - else - LIBRTE_LIB += $(LIB_PATH)/librte_net_pcap.so \ -- $(LIB_PATH)/librte_net_bond.so \ -- $(LIB_PATH)/librte_net_hinic.so \ -- $(LIB_PATH)/librte_net_ixgbe.so \ -- $(LIB_PATH)/librte_net_virtio.so \ -- $(LIB_PATH)/librte_telemetry.so \ -- $(LIB_PATH)/librte_pcapng.so -- ifneq ($(ARCH), loongarch64) -- LIBRTE_LIB += $(LIB_PATH)/librte_net_i40e.so -- endif -+ $(LIB_PATH)/librte_net_bond.so \ -+ $(LIB_PATH)/librte_net_hinic.so \ -+ $(LIB_PATH)/librte_net_ixgbe.so \ -+ $(LIB_PATH)/librte_net_virtio.so \ -+ $(LIB_PATH)/librte_telemetry.so \ -+ $(LIB_PATH)/librte_pcapng.so -+ ifneq ($(ARCH), loongarch64) -+ LIBRTE_LIB += $(LIB_PATH)/librte_net_i40e.so -+ endif - endif - - DEP_LIBS = $(LWIP_LIB) $(LIBRTE_LIB) -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 630b043..7f1ceb8 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -27,7 +27,10 @@ - #include - #include - #include -+#include -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - #include -+#endif - #include - #include - #include -@@ -35,6 +38,7 @@ - #include - #include - #include -+ - #include - #include - #include -@@ -59,8 +63,10 @@ struct eth_params { - struct rte_eth_rxconf rx_conf; - struct rte_eth_txconf tx_conf; - }; -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - struct rte_kni; - static struct rte_bus *g_pci_bus = NULL; -+#endif - - #define RSS_HASH_KEY_LEN 40 - static uint8_t g_default_rss_key[] = { -@@ -368,9 +374,9 @@ static struct eth_params *alloc_eth_params(uint16_t port_id, uint16_t nb_queues) - eth_params->nb_queues = nb_queues; - eth_params->nb_rx_desc = get_global_cfg_params()->nic.rxqueue_size; - eth_params->nb_tx_desc = get_global_cfg_params()->nic.txqueue_size; -- eth_params->conf.link_speeds = ETH_LINK_SPEED_AUTONEG; -- eth_params->conf.txmode.mq_mode = ETH_MQ_TX_NONE; -- eth_params->conf.rxmode.mq_mode = ETH_MQ_RX_NONE; -+ eth_params->conf.link_speeds = RTE_ETH_LINK_SPEED_AUTONEG; -+ eth_params->conf.txmode.mq_mode = RTE_ETH_MQ_TX_NONE; -+ eth_params->conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE; - - return eth_params; - } -@@ -388,7 +394,7 @@ uint64_t get_eth_params_tx_ol(void) - static int eth_params_rss(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev_info) - { - int rss_enable = 0; -- uint64_t def_rss_hf = ETH_RSS_TCP | ETH_RSS_UDP | ETH_RSS_IP; -+ uint64_t def_rss_hf = RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_IP; - struct rte_eth_rss_conf rss_conf = { - g_default_rss_key, - RSS_HASH_KEY_LEN, -@@ -404,7 +410,7 @@ static int eth_params_rss(struct rte_eth_conf *conf, struct rte_eth_dev_info *de - if (rss_conf.rss_hf) { - rss_enable = 1; - conf->rx_adv_conf.rss_conf = rss_conf; -- conf->rxmode.mq_mode = ETH_MQ_RX_RSS; -+ conf->rxmode.mq_mode = RTE_ETH_MQ_RX_RSS; - - LSTACK_LOG(INFO, LSTACK, "set rss_hf: %lx\n", rss_conf.rss_hf); - } -@@ -427,8 +433,8 @@ static void rss_setup(const int port_id, const uint16_t nb_queues) - return; - } - -- reta_conf_size = dev_info.reta_size / RTE_RETA_GROUP_SIZE; -- if (dev_info.reta_size % RTE_RETA_GROUP_SIZE) { -+ reta_conf_size = dev_info.reta_size / RTE_ETH_RETA_GROUP_SIZE; -+ if (dev_info.reta_size % RTE_ETH_RETA_GROUP_SIZE) { - reta_conf_size += 1; - } - -@@ -438,8 +444,8 @@ static void rss_setup(const int port_id, const uint16_t nb_queues) - } - for (i = 0; i < dev_info.reta_size; i++) { - struct rte_eth_rss_reta_entry64 *one_reta_conf = -- &reta_conf[i / RTE_RETA_GROUP_SIZE]; -- one_reta_conf->reta[i % RTE_RETA_GROUP_SIZE] = i % nb_queues; -+ &reta_conf[i / RTE_ETH_RETA_GROUP_SIZE]; -+ one_reta_conf->reta[i % RTE_ETH_RETA_GROUP_SIZE] = i % nb_queues; - } - - for (i = 0; i < reta_conf_size; i++) { -@@ -518,7 +524,11 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - return -1; - } - -+#if RTE_VERSION >= RTE_VERSION_NUM(23, 11, 0, 0) -+ ret = rte_eth_bond_member_add(port_id, slave_port_id[i]); -+#else - ret = rte_eth_bond_slave_add(port_id, slave_port_id[i]); -+#endif - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk add slave port failed ret = %d\n", ret); - return -1; -@@ -671,6 +681,7 @@ int32_t dpdk_init_lstack_kni(void) - return 0; - } - -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - void dpdk_skip_nic_init(void) - { - /* when lstack init nic again, ltran can't read pkts from nic. unregister pci_bus to avoid init nic in lstack */ -@@ -686,6 +697,7 @@ void dpdk_restore_pci(void) - rte_bus_register(g_pci_bus); - } - } -+#endif - - int32_t init_dpdk_ethdev(void) - { -@@ -849,7 +861,11 @@ void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id) - if (strcmp(dev_info.driver_name, "net_bonding") == 0) { - uint16_t slaves[RTE_MAX_ETHPORTS]; - int slave_count; -+#if RTE_VERSION >= RTE_VERSION_NUM(23, 11, 0, 0) -+ slave_count = rte_eth_bond_members_get(port_id, slaves, RTE_MAX_ETHPORTS); -+#else - slave_count = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS); -+#endif - if (slave_count <= 0) { - LSTACK_LOG(ERR, LSTACK, "rte_eth_bond_slaves_get failed.\n"); - return; -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index fef2942..31fd91d 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -116,7 +116,9 @@ void gazelle_exit(void) - stack_group_exit(); - } - if (!use_ltran()) { -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - dpdk_kni_release(); -+#endif - } - } - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 1fa7373..a24fc4c 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -13,8 +13,6 @@ - #include - #include - --#include -- - #include - #include - #include -@@ -38,6 +36,10 @@ - #include "lstack_stack_stat.h" - #include "lstack_protocol_stack.h" - -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) -+#include -+#endif -+ - #define KERNEL_EVENT_10us 10 - - static PER_THREAD struct protocol_stack *g_stack_p = NULL; -@@ -453,7 +455,9 @@ int stack_polling(uint32_t wakeup_tick) - int force_quit; - struct cfg_params *cfg = get_global_cfg_params(); - uint8_t use_ltran_flag = cfg->use_ltran; -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - bool kni_switch = cfg->kni_switch; -+#endif - bool use_sockmap = cfg->use_sockmap; - bool stack_mode_rtc = cfg->stack_mode_rtc; - uint32_t rpc_number = cfg->rpc_number; -@@ -486,6 +490,7 @@ int stack_polling(uint32_t wakeup_tick) - } - } - -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - /* run to completion mode currently does not support kni */ - /* KNI requests are generally low-rate I/Os, - * so processing KNI requests only in the thread with queue_id No.0 is sufficient. */ -@@ -495,6 +500,7 @@ int stack_polling(uint32_t wakeup_tick) - kni_handle_rx(stack->port_id); - } - } -+#endif - return force_quit; - } - -@@ -950,7 +956,9 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - return; - } - copy_mbuf(mbuf_copy, mbuf); -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - kni_handle_tx(mbuf_copy); -+#endif - return; - } - -diff --git a/src/lstack/include/lstack_ethdev.h b/src/lstack/include/lstack_ethdev.h -index 326bd1b..3252906 100644 ---- a/src/lstack/include/lstack_ethdev.h -+++ b/src/lstack/include/lstack_ethdev.h -@@ -13,6 +13,9 @@ - #ifndef __GAZELLE_ETHDEV_H__ - #define __GAZELLE_ETHDEV_H__ - -+#include -+#include -+ - #define INVAILD_PROCESS_IDX 255 - - enum port_type { -@@ -46,7 +49,12 @@ void eth_dev_recv(struct rte_mbuf *mbuf, struct protocol_stack *stack); - - int recv_pkts_from_other_process(int process_index, void* arg); - int32_t check_params_from_primary(void); -+ -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - void kni_handle_rx(uint16_t port_id); -+void kni_handle_tx(struct rte_mbuf *mbuf); -+#endif -+ - void delete_user_process_port(uint16_t dst_port, enum port_type type); - void add_user_process_port(uint16_t dst_port, uint8_t process_idx, enum port_type type); - void delete_flow_director(uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 8e2e807..c681547 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -181,5 +181,4 @@ void stack_recvlist_count(struct rpc_msg *msg); - void stack_exit_by_rpc(struct rpc_msg *msg); - - int stack_polling(uint32_t wakeup_tick); --void kni_handle_tx(struct rte_mbuf *mbuf); - #endif -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 2e11670..5b0f83e 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -13,7 +13,11 @@ - #include - #include - -+#include -+#include -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - #include -+#endif - #include - #include - #include -@@ -755,6 +759,7 @@ int distribute_pakages(struct rte_mbuf *mbuf) - return TRANSFER_KERNEL; - } - -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - void kni_handle_rx(uint16_t port_id) - { - struct rte_mbuf *pkts_burst[PACKET_READ_SIZE]; -@@ -793,6 +798,7 @@ void kni_handle_tx(struct rte_mbuf *mbuf) - rte_pktmbuf_free(mbuf); - } - } -+#endif - - /* optimized eth_dev_poll() in lstack */ - int32_t gazelle_eth_dev_poll(struct protocol_stack *stack, uint8_t use_ltran_flag, uint32_t nic_read_number) -@@ -835,7 +841,9 @@ int32_t gazelle_eth_dev_poll(struct protocol_stack *stack, uint8_t use_ltran_fla - if (likely(transfer_type == TRANSFER_CURRENT_THREAD)) { - eth_dev_recv(stack->pkts[i], stack); - } else if (transfer_type == TRANSFER_KERNEL) { -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - kni_handle_tx(stack->pkts[i]); -+#endif - } else { - /* transfer to other thread */ - } -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index c845f7a..fe17f59 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -22,6 +22,8 @@ - #include - #include - -+#include -+ - #include "lstack_cfg.h" - #include "lstack_dpdk.h" - #include "lstack_ethdev.h" -@@ -85,7 +87,7 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt - - /* skip gro when tcp/ip cksum offloads disable */ - if (get_protocol_stack_group()->rx_offload == 0 || (get_global_cfg_params()->nic.vlan_mode >= 0 -- && !(get_protocol_stack_group()->rx_offload & DEV_RX_OFFLOAD_VLAN_STRIP))) { -+ && !(get_protocol_stack_group()->rx_offload & RTE_ETH_RX_OFFLOAD_VLAN_STRIP))) { - return pkt_num; - } - -diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt -index e098a77..f739ceb 100644 ---- a/src/ltran/CMakeLists.txt -+++ b/src/ltran/CMakeLists.txt -@@ -27,22 +27,38 @@ if($ENV{GAZELLE_COVERAGE_ENABLE}) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs") - endif($ENV{GAZELLE_COVERAGE_ENABLE}) - --if($ENV{DPDK_VERSION_1911}) -+execute_process( -+ COMMAND rpm -qa dpdk -+ OUTPUT_VARIABLE DPDK_VERSION_FULL -+ OUTPUT_STRIP_TRAILING_WHITESPACE -+) -+string(REGEX MATCH "[0-9]+\\.[0-9]+" DPDK_VERSION ${DPDK_VERSION_FULL}) -+ -+if (DPDK_VERSION STREQUAL "21.11") -+ set(DPDK_DIR /usr/local/include/) -+else() - set(DPDK_DIR /usr/include/dpdk) -- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDPDK_VERSION_1911=1") -+endif() -+ -+if (DPDK_VERSION STREQUAL "19.11") - set(DPDK_LINK_FLAGS "-Wl,-lrte_pmd_bond -Wl,-lrte_pmd_hinic -Wl,-lrte_pmd_ixgbe \ - -Wl,-lrte_pmd_pcap -Wl,-lrte_pmd_virtio") - if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "loongarch64") - set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-lrte_pmd_i40e") - endif() - else() -- set(DPDK_DIR /usr/local/include/) - set(DPDK_LINK_FLAGS "-Wl,-lrte_net_bond -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe \ - -Wl,-lpcap -Wl,-lrte_net_pcap -Wl,-lrte_net_virtio -Wl,-lrte_pcapng -Wl,-lrte_telemetry") - if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "loongarch64") - set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-lrte_net_i40e") - endif() --endif($ENV{DPDK_VERSION_1911}) -+endif() -+ -+if (DPDK_VERSION GREATER_EQUAL 23.11) -+ set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -lrte_log -larchive -Wl,-lrte_eal") -+else() -+ set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -lrte_kni -Wl,-Bstatic -lrte_eal -Wl,-Bdynamic") -+endif() - - add_executable(ltran main.c ltran_param.c ltran_config.c ltran_ethdev.c ltran_stat.c ltran_errno.c - ltran_monitor.c ltran_instance.c ltran_stack.c ltran_tcp_conn.c ltran_tcp_sock.c -@@ -55,16 +71,19 @@ target_compile_options(ltran PRIVATE -fno-strict-aliasing -D__ARM_FEATURE_CRC32= - -DRTE_MACHINE_CPUFLAG_SHA1 -DRTE_MACHINE_CPUFLAG_SHA2 -include rte_config.h - -D_GNU_SOURCE -W -Wall -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition - -Wpointer-arith -Wcast-qual -Wnested-externs -Wformat-nonliteral -Wformat-security -Wundef -- -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough -D_FORTIFY_SOURCE=2) --if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "sw_64") -+ -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough -D_FORTIFY_SOURCE=2 -Wno-error=deprecated-declarations) -+ -+# gcc coredump in openEuler-20.03-LTS-XX aarch64 when add -march=native -+if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "sw_64|aarch64" ) - target_compile_options(ltran PRIVATE -march=native -Wcast-align) - endif() - - target_link_libraries(ltran PRIVATE config boundscheck rte_pdump -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines) -+ - set_target_properties(ltran PROPERTIES LINK_FLAGS "-L$ENV{DPDK_LIB_PATH} -Wl,--no-whole-archive \ - -Wl,-lrte_meter -Wl,--whole-archive -Wl,-lrte_gro -Wl,-lrte_hash -Wl,-lrte_kvargs -Wl,-lrte_mbuf -Wl,-lrte_ethdev \ - -Wl,-lrte_net -Wl,-lrte_timer -Wl,-lrte_mempool -Wl,-lrte_mempool_ring -Wl,-lrte_ring -Wl,-lrte_pci \ -- -Wl,-Bstatic -lrte_eal -Wl,-Bdynamic -Wl,-lrte_cmdline -Wl,-lrte_kni -Wl,-lrte_bus_pci \ -+ -Wl,-lrte_cmdline -Wl,-lrte_bus_pci\ - -Wl,-lrte_bus_vdev ${DPDK_LINK_FLAGS} \ - -Wl,--no-whole-archive -Wl,-lm -Wl,-lrt -Wl,-lnuma -Wl,-ldl -Wl,-export-dynamic -Wl,-export-dynamic \ - -Wl,--as-needed -Wl,-export-dynamic -Wl,-Map=ltran.map -Wl,--cref") -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 0d7ea7b..4b246a1 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -26,6 +26,8 @@ - #include - #include - -+#include -+ - #include "ltran_stat.h" - #include "ltran_base.h" - #include "gazelle_dfx_msg.h" -@@ -168,16 +170,16 @@ static void gazelle_print_lstack_nic_features(void *buf, const struct gazelle_st - struct nic_eth_features *f = &(((struct gazelle_stack_dfx_data *)buf)->data.nic_features); - printf("###### NIC offload and other features for port %-2d #########\n", f->port_id); - -- printf("tx-ipv4-checksum: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_IPV4_CKSUM) ? "on" : "off"); -- printf("tx-tcp-checksum: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_TCP_CKSUM) ? "on" : "off"); -- printf("tx-tcp-tso: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_TCP_TSO) ? "on" : "off"); -- printf("tx-udp-checksum: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_UDP_CKSUM) ? "on" : "off"); -- printf("tx-vlan-insert: %s\n", (f->tx_offload & DEV_TX_OFFLOAD_VLAN_INSERT) ? "on" : "off"); -+ printf("tx-ipv4-checksum: %s\n", (f->tx_offload & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) ? "on" : "off"); -+ printf("tx-tcp-checksum: %s\n", (f->tx_offload & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ? "on" : "off"); -+ printf("tx-tcp-tso: %s\n", (f->tx_offload & RTE_ETH_TX_OFFLOAD_TCP_TSO) ? "on" : "off"); -+ printf("tx-udp-checksum: %s\n", (f->tx_offload & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ? "on" : "off"); -+ printf("tx-vlan-insert: %s\n", (f->tx_offload & RTE_ETH_TX_OFFLOAD_VLAN_INSERT) ? "on" : "off"); - -- printf("rx-ipv4-checksum: %s\n", (f->rx_offload & DEV_RX_OFFLOAD_IPV4_CKSUM) ? "on" : "off"); -- printf("rx-tcp-checksum: %s\n", (f->rx_offload & DEV_RX_OFFLOAD_TCP_CKSUM) ? "on" : "off"); -- printf("rx-udp-checksum: %s\n", (f->rx_offload & DEV_RX_OFFLOAD_UDP_CKSUM) ? "on" : "off"); -- printf("rx-vlan-strip: %s\n", (f->rx_offload & DEV_RX_OFFLOAD_VLAN_STRIP) ? "on" : "off"); -+ printf("rx-ipv4-checksum: %s\n", (f->rx_offload & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM) ? "on" : "off"); -+ printf("rx-tcp-checksum: %s\n", (f->rx_offload & RTE_ETH_RX_OFFLOAD_TCP_CKSUM) ? "on" : "off"); -+ printf("rx-udp-checksum: %s\n", (f->rx_offload & RTE_ETH_RX_OFFLOAD_UDP_CKSUM) ? "on" : "off"); -+ printf("rx-vlan-strip: %s\n", (f->rx_offload & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) ? "on" : "off"); - } - - static void gazelle_print_ltran_conn(void *buf, const struct gazelle_stat_msg_request *req_msg) -diff --git a/src/ltran/ltran_ethdev.c b/src/ltran/ltran_ethdev.c -index e2eb4a8..2fb7fab 100644 ---- a/src/ltran/ltran_ethdev.c -+++ b/src/ltran/ltran_ethdev.c -@@ -21,10 +21,15 @@ - #include - #include - #include -+#include -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - #include -+#endif - #include - #include - -+#include -+ - #include "dpdk_common.h" - #include "ltran_param.h" - #include "ltran_log.h" -@@ -85,7 +90,11 @@ static int32_t ltran_mbuf_pool_init(void); - static int32_t ltran_single_slave_port_init(uint16_t port_num, struct rte_mempool *pktmbuf_rxpool); - static int32_t ltran_single_bond_port_init(uint16_t port_num, struct rte_mempool *pktmbuf_rxpool); - static int32_t ltran_slave_port_init(void); -+ -+ -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - static int32_t ltran_kni_init(void); -+#endif - static int32_t ltran_bond_port_init(void); - - static int32_t ltran_eal_init(void) -@@ -248,10 +257,10 @@ static int32_t ltran_single_slave_port_init(uint16_t port_num, struct rte_mempoo - } - - struct rte_eth_conf port_conf = {0}; -- port_conf.txmode.mq_mode = ETH_MQ_TX_NONE; -- port_conf.link_speeds = ETH_LINK_SPEED_AUTONEG; -+ port_conf.txmode.mq_mode = RTE_ETH_MQ_TX_NONE; -+ port_conf.link_speeds = RTE_ETH_LINK_SPEED_AUTONEG; - eth_params_checksum(&port_conf, &dev_info); -- port_conf.rxmode.mq_mode = ETH_MQ_RX_NONE; -+ port_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE; - - struct ltran_config *ltran_config = get_ltran_config(); - ltran_config->dpdk.rx_offload = port_conf.rxmode.offloads; -@@ -311,7 +320,11 @@ static int32_t ltran_slave_port_init(void) - static int32_t ltran_eth_bond_slave(const struct port_info *port_info, uint16_t port_num, uint16_t bond_port_id) - { - for (uint32_t i = 0; i < port_info[port_num].num_ports; i++) { -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - int32_t ret = rte_eth_bond_slave_add(bond_port_id, port_info[port_num].id[i]); -+#else -+ int32_t ret = rte_eth_bond_member_add(bond_port_id, port_info[port_num].id[i]); -+#endif - if (ret < 0) { - return ret; - } -@@ -370,9 +383,9 @@ static int32_t ltran_bond_port_attr_set(uint16_t port_num, uint16_t bond_port_id - } - - struct rte_eth_conf port_conf = {0}; -- port_conf.rxmode.mq_mode = ETH_MQ_RX_NONE; -- port_conf.txmode.mq_mode = ETH_MQ_TX_NONE; -- port_conf.link_speeds = ETH_LINK_SPEED_AUTONEG; -+ port_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE; -+ port_conf.txmode.mq_mode = RTE_ETH_MQ_TX_NONE; -+ port_conf.link_speeds = RTE_ETH_LINK_SPEED_AUTONEG; - eth_params_checksum(&port_conf, &dev_info); - - ret = rte_eth_dev_configure(bond_port_id, rx_queue_num, tx_queue_num, &port_conf); -@@ -469,6 +482,7 @@ static int32_t ltran_bond_port_init(void) - return GAZELLE_OK; - } - -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - static int32_t ltran_kni_init(void) - { - // if not use kni. skip kni init and return -@@ -481,6 +495,7 @@ static int32_t ltran_kni_init(void) - - return dpdk_kni_init(bond_port[0], txpool[0]); - } -+#endif - - typedef int32_t (*ethdev_init_func)(void); - -@@ -492,7 +507,9 @@ static ethdev_init_func g_ltran_ethdev_init_tbl[] = { - ltran_mbuf_pool_init, - ltran_slave_port_init, - ltran_bond_port_init, -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - ltran_kni_init, -+#endif - }; - - int32_t ltran_ethdev_init(void) -diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c -index ee379b5..a5756d7 100644 ---- a/src/ltran/ltran_forward.c -+++ b/src/ltran/ltran_forward.c -@@ -13,7 +13,12 @@ - #include - #include - #include -+#include -+ -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - #include -+#endif -+ - #include - #include - #include -@@ -195,6 +200,7 @@ static __rte_always_inline uint32_t pkt_bufs_enque_rx_ring(struct gazelle_stack - - static __rte_always_inline void flush_rx_ring(struct gazelle_stack *stack) - { -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - if (unlikely(stack == get_kni_stack())) { - // if fail, free mbuf inside - kni_process_tx(stack->pkt_buf, stack->pkt_cnt); -@@ -202,6 +208,7 @@ static __rte_always_inline void flush_rx_ring(struct gazelle_stack *stack) - stack->pkt_cnt = 0; - return; - } -+#endif - - /* first flush backup mbuf pointer avoid packet disorder */ - if (unlikely(stack->backup_pkt_cnt > 0)) { -@@ -414,9 +421,12 @@ static __rte_always_inline void upstream_forward_one(struct rte_mbuf *m) - } - - forward_to_kni: -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - if (get_ltran_config()->dpdk.kni_switch == GAZELLE_ON) { - enqueue_rx_packet(get_kni_stack(), m); - } -+#endif -+ return; - } - - static __rte_always_inline void msg_to_quintuple(struct gazelle_quintuple *transfer_qtuple, -@@ -653,10 +663,12 @@ void upstream_forward(const uint16_t *port) - upstream_forward_loop(port_id, queue_id); - } - -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - if (get_ltran_config()->dpdk.kni_switch == GAZELLE_ON) { - flush_rx_ring(get_kni_stack()); - rte_kni_handle_request(get_gazelle_kni()); - } -+#endif - - now_time = get_current_time(); - if (now_time - aging_conn_last_time > GAZELLE_CONN_INTERVAL) { -@@ -755,11 +767,13 @@ int32_t downstream_forward(uint16_t *port) - uint32_t queue_num = get_ltran_config()->bond.tx_queue_num; - - while (get_ltran_stop_flag() != GAZELLE_TRUE) { -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - /* kni rx means read from kni and send to nic */ - if (get_ltran_config()->dpdk.kni_switch == GAZELLE_ON && - get_kni_started()) { - kni_process_rx(g_port_index); - } -+#endif - - for (uint32_t queue_id = 0; queue_id < queue_num; queue_id++) { - downstream_forward_loop(port_id, queue_id); -diff --git a/src/ltran/ltran_stack.c b/src/ltran/ltran_stack.c -index d4e935e..2aed6c9 100644 ---- a/src/ltran/ltran_stack.c -+++ b/src/ltran/ltran_stack.c -@@ -10,6 +10,7 @@ - * See the Mulan PSL v2 for more details. - */ - -+#include - #include - - #include "ltran_instance.h" -diff --git a/src/ltran/ltran_timer.c b/src/ltran/ltran_timer.c -index 96c622e..0832c5f 100644 ---- a/src/ltran/ltran_timer.c -+++ b/src/ltran/ltran_timer.c -@@ -10,6 +10,7 @@ - * See the Mulan PSL v2 for more details. - */ - -+#include - #include - #include - -diff --git a/src/ltran/main.c b/src/ltran/main.c -index c2598a7..6cc8bc9 100644 ---- a/src/ltran/main.c -+++ b/src/ltran/main.c -@@ -17,6 +17,8 @@ - #include - #include - #include -+#include -+#include - - #include "dpdk_common.h" - #include "ltran_log.h" -@@ -57,7 +59,9 @@ static void sig_default_handler(int32_t sig) - { - LTRAN_ERR("ltran dumped, caught signal: %d.\n", sig); - print_stack(); -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - dpdk_kni_release(); -+#endif - int ret = 0; - ret = unlink(get_ltran_config()->unix_socket_filename); - if (ret) { -@@ -143,7 +147,9 @@ static void ltran_core_destroy(void) - gazelle_stack_htable_destroy(); - gazelle_tcp_conn_htable_destroy(); - gazelle_tcp_sock_htable_destroy(); -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - dpdk_kni_release(); -+#endif - } - - static void wait_thread_finish(pthread_t ctrl_thread, uint32_t next_core) --- -2.33.0 - diff --git a/0120-modify-conf-vlan-default-vlaue.patch b/0120-modify-conf-vlan-default-vlaue.patch deleted file mode 100644 index a679ded40d541c66a7b217d1ca884d7c4e423a4b..0000000000000000000000000000000000000000 --- a/0120-modify-conf-vlan-default-vlaue.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 560eb7939415f3cd8b10bbc829fd57141b757727 Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Fri, 19 Jan 2024 01:47:26 +0000 -Subject: [PATCH] modify conf vlan default vlaue - ---- - src/lstack/lstack.conf | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index 3eb4685..ce86ec4 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -64,5 +64,5 @@ process_idx=0 - #tuple_filer=0, below cfg valid - listen_shadow=0 - --#vlan mode; only support 0~4094, 0 is disabled --nic_vlan_mode=0 -+#vlan mode; only support -1~4094, -1 is disabled -+nic_vlan_mode=-1 --- -2.33.0 - diff --git a/0121-remove-unused-variables-in-pbuf-and-reduce-mbuf-size.patch b/0121-remove-unused-variables-in-pbuf-and-reduce-mbuf-size.patch deleted file mode 100644 index 911f70c58b76e08afbad2759ea6a4a9e797c7f86..0000000000000000000000000000000000000000 --- a/0121-remove-unused-variables-in-pbuf-and-reduce-mbuf-size.patch +++ /dev/null @@ -1,123 +0,0 @@ -From 2bfb7f1dcaab4436db7345d6f9fcb6f4a1d27681 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sun, 21 Jan 2024 16:42:46 +0800 -Subject: [PATCH] remove unused variables in pbuf and reduce mbuf size - ---- - src/lstack/core/lstack_lwip.c | 10 ---------- - src/lstack/include/lstack_dpdk.h | 2 +- - src/lstack/netif/lstack_ethdev.c | 11 ----------- - 3 files changed, 1 insertion(+), 22 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 6ebe589..63044c2 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -114,14 +114,7 @@ static struct pbuf *init_mbuf_to_pbuf(struct rte_mbuf *mbuf, pbuf_layer layer, u - void *data = rte_pktmbuf_mtod(mbuf, void *); - struct pbuf *pbuf = pbuf_alloced_custom(layer, length, type, pbuf_custom, data, MAX_PACKET_SZ); - if (pbuf) { -- pbuf->ol_flags = 0; -- pbuf->l2_len = 0; -- pbuf->l3_len = 0; -- pbuf->l4_len = 0; -- pbuf->header_off = 0; -- pbuf->rexmit = 0; - pbuf->allow_in = 1; -- pbuf->head = 0; - pbuf->last = pbuf; - pbuf->addr = *IP_ANY_TYPE; - pbuf->port = 0; -@@ -290,7 +283,6 @@ struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_s - if (pbuf->tot_len > remain_size) { - pthread_spin_unlock(&pbuf->pbuf_lock); - *apiflags &= ~TCP_WRITE_FLAG_MORE; -- pbuf->head = 1; - return NULL; - } - if (pbuf->allow_in == 1) { -@@ -300,7 +292,6 @@ struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_s - } else { - if (pbuf->tot_len > remain_size) { - *apiflags &= ~TCP_WRITE_FLAG_MORE; -- pbuf->head = 1; - return NULL; - } - } -@@ -1354,7 +1345,6 @@ err_t netif_loop_output(struct netif *netif, struct pbuf *p) - LSTACK_LOG(ERR, LSTACK, "netif_loop_output: pbuf_alloc failed\n"); - return ERR_MEM; - } -- head->ol_flags = p->ol_flags; - memcpy_s(head->payload, head->len, p->payload, p->len); - - if ((flags & TCP_SYN) && !(flags & TCP_ACK)) { -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index 2a44c6e..b39d199 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -21,7 +21,7 @@ - - #define KNI_NB_MBUF (DEFAULT_RING_SIZE << 4) - --#define MAX_PACKET_SZ 2048 -+#define MAX_PACKET_SZ 1530 - - #define RING_SIZE(x) ((x) - 1) - -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 5b0f83e..4d6f620 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -103,9 +103,6 @@ void eth_dev_recv(struct rte_mbuf *mbuf, struct protocol_stack *stack) - } - next->tot_len = pkt_len; - pkt_len -= len; --#if CHECKSUM_CHECK_IP_HW || CHECKSUM_CHECK_TCP_HW -- next->ol_flags = m->ol_flags; --#endif - - if (head == NULL) { - head = next; -@@ -859,7 +856,6 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - struct protocol_stack *stack = get_protocol_stack(); - struct rte_mbuf *pre_mbuf = NULL; - struct rte_mbuf *first_mbuf = NULL; -- struct pbuf *first_pbuf = pbuf; - void *buf_addr; - - while (likely(pbuf != NULL)) { -@@ -867,8 +863,6 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - - mbuf->data_len = pbuf->len; - mbuf->pkt_len = pbuf->tot_len; -- mbuf->ol_flags = pbuf->ol_flags; -- mbuf->vlan_tci = pbuf->vlan_tci; - mbuf->next = NULL; - buf_addr = rte_pktmbuf_mtod(mbuf, void *); - -@@ -882,7 +876,6 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - - if (first_mbuf == NULL) { - first_mbuf = mbuf; -- first_pbuf = pbuf; - first_mbuf->nb_segs = 1; - } else { - first_mbuf->nb_segs++; -@@ -893,13 +886,9 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - mbuf->ol_flags |= RTE_MBUF_F_TX_TCP_SEG; - mbuf->tso_segsz = MBUF_MAX_DATA_LEN; - } -- mbuf->l2_len = first_pbuf->l2_len; -- mbuf->l3_len = first_pbuf->l3_len; -- mbuf->l4_len = first_pbuf->l4_len; - - pre_mbuf = mbuf; - rte_mbuf_refcnt_update(mbuf, 1); -- pbuf->rexmit = 1; - pbuf = pbuf->next; - } - --- -2.33.0 - diff --git a/0122-optimize-recv-exit-process-for-FIN-and-unsupport-SO_.patch b/0122-optimize-recv-exit-process-for-FIN-and-unsupport-SO_.patch deleted file mode 100644 index 03af1628e6a78120b00702f62d0ca914d960877e..0000000000000000000000000000000000000000 --- a/0122-optimize-recv-exit-process-for-FIN-and-unsupport-SO_.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 7499d04834da6c3774923972d927229b10189e62 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Mon, 22 Jan 2024 12:52:09 +0800 -Subject: [PATCH] optimize recv exit process for FIN and unsupport SO_RCVBUF - ---- - src/lstack/api/lstack_wrap.c | 1 + - src/lstack/core/lstack_lwip.c | 2 +- - 2 files changed, 2 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 3db62c7..372e102 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -372,6 +372,7 @@ static bool unsupport_optname(int32_t optname) - optname == SO_SNDTIMEO || - optname == SO_RCVTIMEO || - optname == SO_SNDBUF || -+ optname == SO_RCVBUF || - optname == TCP_INFO || - optname == TCP_MAXSEG || - optname == TCP_CONGESTION) { -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 6ebe589..ce218f5 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -1016,7 +1016,7 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - } else { - while (gazelle_ring_read(sock->recv_ring, (void **)&pbuf, 1) != 1 && recvd == 0) { - /* if the connection is disconnected, recv return 0 */ -- if ((sock->errevent > 0 || (sock->conn->pcb.tcp->flags & TF_FIN)) && !NETCONN_IS_DATAIN(sock)) { -+ if (sock->errevent > 0 && !NETCONN_IS_DATAIN(sock)) { - return 0; - } - --- -2.33.0 - diff --git a/0123-remove-expand_send_ring.patch b/0123-remove-expand_send_ring.patch deleted file mode 100644 index 260061fbdb2b9c81642ed2bc8880c6917fb78231..0000000000000000000000000000000000000000 --- a/0123-remove-expand_send_ring.patch +++ /dev/null @@ -1,371 +0,0 @@ -From 744be87c712b7166eb921b2e7d537bea71005966 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 22 Jan 2024 17:08:42 +0800 -Subject: [PATCH] remove expand_send_ring - ---- - src/lstack/core/lstack_cfg.c | 9 -- - src/lstack/core/lstack_lwip.c | 191 ++----------------------------- - src/lstack/include/lstack_cfg.h | 1 - - src/lstack/include/lstack_lwip.h | 2 +- - src/lstack/lstack.conf | 4 - - 5 files changed, 12 insertions(+), 195 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 5e30e89..028ea26 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -66,7 +66,6 @@ static int32_t parse_nic_read_number(void); - static int32_t parse_tcp_conn_count(void); - static int32_t parse_mbuf_count_per_conn(void); - static int32_t parse_send_ring_size(void); --static int32_t parse_expand_send_ring(void); - static int32_t parse_num_process(void); - static int32_t parse_process_numa(void); - static int32_t parse_process_index(void); -@@ -130,7 +129,6 @@ static struct config_vector_t g_config_tbl[] = { - { "rpc_number", parse_rpc_number }, - { "nic_read_number", parse_nic_read_number }, - { "send_ring_size", parse_send_ring_size }, -- { "expand_send_ring", parse_expand_send_ring }, - { "num_process", parse_num_process }, - { "process_numa", parse_process_numa }, - { "process_idx", parse_process_index }, -@@ -888,13 +886,6 @@ static int32_t parse_send_ring_size(void) - return ret; - } - --static int32_t parse_expand_send_ring(void) --{ -- int32_t ret; -- PARSE_ARG(g_config_params.expand_send_ring, "expand_send_ring", 0, 0, 1, ret); -- return ret; --} -- - static int32_t parse_mbuf_count_per_conn(void) - { - int32_t ret; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 6ebe589..33b6abd 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -56,17 +56,6 @@ static void free_ring_pbuf(struct rte_ring *ring) - } while (gazelle_ring_readover_count(ring)); - } - --static void free_list_pbuf(struct pbuf *pbuf) --{ -- while (pbuf) { -- struct pbuf *del_pbuf = pbuf; -- pbuf = pbuf->next; -- -- del_pbuf->next = NULL; -- pbuf_free(del_pbuf); -- } --} -- - static void reset_sock_data(struct lwip_sock *sock) - { - /* check null pointer in ring_free func */ -@@ -82,11 +71,6 @@ static void reset_sock_data(struct lwip_sock *sock) - sock->send_ring = NULL; - } - -- if (sock->send_lastdata) { -- free_list_pbuf(sock->send_lastdata); -- sock->send_lastdata = NULL; -- } -- - if (sock->send_pre_del) { - pbuf_free(sock->send_pre_del); - sock->send_pre_del = NULL; -@@ -160,9 +144,7 @@ static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_so - pbuf_free(pbuf[i]); - } - -- if (!get_global_cfg_params()->expand_send_ring) { -- sem_post(&sock->snd_ring_sem); -- } -+ sem_post(&sock->snd_ring_sem); - - return false; - } -@@ -260,22 +242,6 @@ struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_s - } - pthread_spin_unlock(&pbuf->pbuf_lock); - -- if (pbuf->next) { -- sock->send_lastdata = pbuf->next; -- pbuf->next = NULL; -- } -- return pbuf; -- } -- -- if (sock->send_lastdata) { -- pbuf = sock->send_lastdata; -- if (pbuf->tot_len > remain_size) { -- *apiflags &= ~TCP_WRITE_FLAG_MORE; -- return NULL; -- } -- sock->send_pre_del = pbuf; -- sock->send_lastdata = pbuf->next; -- pbuf->next = NULL; - return pbuf; - } - -@@ -305,8 +271,6 @@ struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_s - } - } - -- sock->send_lastdata = pbuf->next; -- pbuf->next = NULL; - return pbuf; - } - -@@ -320,112 +284,25 @@ static ssize_t do_app_write(struct pbuf *pbufs[], void *buf, size_t len, uint32_ - { - ssize_t send_len = 0; - uint32_t i = 0; -- uint32_t expand_send_ring = get_global_cfg_params()->expand_send_ring; - - for (i = 0; i < write_num - 1; i++) { - rte_prefetch0(pbufs[i + 1]); - rte_prefetch0(pbufs[i + 1]->payload); - rte_prefetch0((char *)buf + send_len + MBUF_MAX_DATA_LEN); -- if (expand_send_ring) { -- pbuf_take(pbufs[i], (char *)buf + send_len, MBUF_MAX_DATA_LEN); -- } else { -- rte_memcpy((char *)pbufs[i]->payload, (char *)buf + send_len, MBUF_MAX_DATA_LEN); -- } -+ rte_memcpy((char *)pbufs[i]->payload, (char *)buf + send_len, MBUF_MAX_DATA_LEN); - pbufs[i]->tot_len = pbufs[i]->len = MBUF_MAX_DATA_LEN; - send_len += MBUF_MAX_DATA_LEN; - } - - /* reduce the branch in loop */ - uint16_t copy_len = len - send_len; -- if (expand_send_ring) { -- pbuf_take(pbufs[i], (char *)buf + send_len, copy_len); -- } else { -- rte_memcpy((char *)pbufs[i]->payload, (char *)buf + send_len, copy_len); -- } -+ rte_memcpy((char *)pbufs[i]->payload, (char *)buf + send_len, copy_len); - pbufs[i]->tot_len = pbufs[i]->len = copy_len; - send_len += copy_len; - - return send_len; - } - --static inline ssize_t app_direct_write(struct protocol_stack *stack, struct lwip_sock *sock, void *buf, -- size_t len, uint32_t write_num) --{ -- if (write_num == 0) { -- return 0; -- } -- struct pbuf **pbufs = (struct pbuf **)malloc(write_num * sizeof(struct pbuf *)); -- if (pbufs == NULL) { -- return 0; -- } -- -- /* first pbuf get from send_ring. and malloc pbufs attach to first pbuf */ -- if (dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)&pbufs[1], write_num - 1) != 0) { -- stack->stats.tx_allocmbuf_fail++; -- free(pbufs); -- return 0; -- } -- -- (void)gazelle_ring_read(sock->send_ring, (void **)&pbufs[0], 1); -- -- uint32_t i = 1; -- for (; i < write_num - 1; i++) { -- rte_prefetch0(mbuf_to_pbuf((void *)pbufs[i + 1])); -- pbufs[i] = init_mbuf_to_pbuf((struct rte_mbuf *)pbufs[i], PBUF_TRANSPORT, MBUF_MAX_DATA_LEN, PBUF_RAM); -- pbufs[i - 1]->next = pbufs[i]; -- } -- pbufs[i] = init_mbuf_to_pbuf((struct rte_mbuf *)pbufs[i], PBUF_TRANSPORT, MBUF_MAX_DATA_LEN, PBUF_RAM); -- pbufs[i - 1]->next = pbufs[i]; -- -- ssize_t send_len = do_app_write(pbufs, buf, len, write_num); -- -- gazelle_ring_read_over(sock->send_ring); -- -- pbufs[0]->last = pbufs[write_num - 1]; -- sock->remain_len = 0; -- free(pbufs); -- return send_len; --} -- --static inline ssize_t app_direct_attach(struct protocol_stack *stack, struct pbuf *attach_pbuf, void *buf, -- size_t len, uint32_t write_num) --{ -- if (write_num == 0) { -- return 0; -- } -- struct pbuf **pbufs = (struct pbuf **)malloc(write_num * sizeof(struct pbuf *)); -- if (pbufs == NULL) { -- return 0; -- } -- -- /* first pbuf get from send_ring. and malloc pbufs attach to first pbuf */ -- if (dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)pbufs, write_num) != 0) { -- stack->stats.tx_allocmbuf_fail++; -- free(pbufs); -- return 0; -- } -- -- pbufs[0] = init_mbuf_to_pbuf((struct rte_mbuf *)pbufs[0], PBUF_TRANSPORT, MBUF_MAX_DATA_LEN, PBUF_RAM); -- uint32_t i = 1; -- for (; i < write_num - 1; i++) { -- rte_prefetch0(mbuf_to_pbuf((void *)pbufs[i + 1])); -- pbufs[i] = init_mbuf_to_pbuf((struct rte_mbuf *)pbufs[i], PBUF_TRANSPORT, MBUF_MAX_DATA_LEN, PBUF_RAM); -- pbufs[i - 1]->next = pbufs[i]; -- } -- if (write_num > 1) { -- pbufs[i] = init_mbuf_to_pbuf((struct rte_mbuf *)pbufs[i], PBUF_TRANSPORT, MBUF_MAX_DATA_LEN, PBUF_RAM); -- pbufs[i - 1]->next = pbufs[i]; -- } -- -- ssize_t send_len = do_app_write(pbufs, buf, len, write_num); -- -- attach_pbuf->last->next = pbufs[0]; -- attach_pbuf->last = pbufs[write_num - 1]; -- -- free(pbufs); -- return send_len; --} -- - static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t len, uint32_t write_num, - const struct sockaddr *addr, socklen_t addrlen) - { -@@ -496,12 +373,6 @@ static inline size_t merge_data_lastpbuf(struct lwip_sock *sock, void *buf, size - return 0; - } - -- if (last_pbuf->next || last_pbuf->len >= MBUF_MAX_DATA_LEN) { -- sock->remain_len = 0; -- gazelle_ring_lastover(last_pbuf); -- return 0; -- } -- - size_t send_len = MBUF_MAX_DATA_LEN - last_pbuf->len; - if (send_len >= len) { - sock->remain_len = send_len - len; -@@ -512,11 +383,7 @@ static inline size_t merge_data_lastpbuf(struct lwip_sock *sock, void *buf, size - - uint16_t offset = last_pbuf->len; - last_pbuf->tot_len = last_pbuf->len = offset + send_len; -- if (get_global_cfg_params()->expand_send_ring) { -- pbuf_take_at(last_pbuf, buf, send_len, offset); -- } else { -- rte_memcpy((char *)last_pbuf->payload + offset, buf, send_len); -- } -+ rte_memcpy((char *)last_pbuf->payload + offset, buf, send_len); - - gazelle_ring_lastover(last_pbuf); - -@@ -570,55 +437,19 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - - /* send_ring is full, data attach last pbuf */ - if (write_avail == 0) { -- if (!get_global_cfg_params()->expand_send_ring) { -- sem_timedwait_nsecs(&sock->snd_ring_sem); -- if (likely(sock->send_ring != NULL)) { -- write_avail = gazelle_ring_readable_count(sock->send_ring); -- } -- goto END; -+ sem_timedwait_nsecs(&sock->snd_ring_sem); -+ if (likely(sock->send_ring != NULL)) { -+ write_avail = gazelle_ring_readable_count(sock->send_ring); - } -- if (unlikely(sock->send_ring == NULL)) { -- goto END; -- } -- struct pbuf *last_pbuf = gazelle_ring_readlast(sock->send_ring); -- if (last_pbuf) { -- send_len += app_direct_attach(stack, last_pbuf, (char *)buf + send_len, len - send_len, write_num); -- gazelle_ring_lastover(last_pbuf); -- if (wakeup) { -- wakeup->stat.app_write_cnt += write_num; -- } -- if (addr->sa_family == AF_INET) { -- struct sockaddr_in *saddr = (struct sockaddr_in *)addr; -- last_pbuf->addr.u_addr.ip4.addr = saddr->sin_addr.s_addr; -- last_pbuf->port = lwip_ntohs((saddr)->sin_port); -- } else if (addr->sa_family == AF_INET6) { -- struct sockaddr_in6 *saddr = (struct sockaddr_in6 *)addr; -- memcpy_s(last_pbuf->addr.u_addr.ip6.addr, sizeof(last_pbuf->addr.u_addr.ip6.addr), -- saddr->sin6_addr.s6_addr, sizeof(saddr->sin6_addr.s6_addr)); -- last_pbuf->port = lwip_ntohs((saddr)->sin6_port); -- } -- } else { -- (void)rpc_call_replenish(stack, sock); -- if (wakeup) { -- wakeup->stat.app_write_rpc++; -- } -- } -- sock->remain_len = 0; - goto END; - } - - /* send_ring have idle */ -- if (get_global_cfg_params()->expand_send_ring) { -- send_len += (write_num <= write_avail) ? -- app_buff_write(sock, (char *)buf + send_len, len - send_len, write_num, addr, addrlen) : -- app_direct_write(stack, sock, (char *)buf + send_len, len - send_len, write_num); -- } else { -- if (write_num > write_avail) { -- write_num = write_avail; -- len = write_num * MBUF_MAX_DATA_LEN; -- } -- send_len += app_buff_write(sock, (char *)buf + send_len, len - send_len, write_num, addr, addrlen); -+ if (write_num > write_avail) { -+ write_num = write_avail; -+ len = write_num * MBUF_MAX_DATA_LEN; - } -+ send_len += app_buff_write(sock, (char *)buf + send_len, len - send_len, write_num, addr, addrlen); - - if (wakeup) { - wakeup->stat.app_write_cnt += write_num; -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index c1074f8..01d70fb 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -110,7 +110,6 @@ struct cfg_params { - struct secondary_attach_arg sec_attach_arg; - char unix_socket_filename[NAME_MAX]; - uint16_t send_ring_size; -- bool expand_send_ring; - bool tuple_filter; - int8_t bond_mode; - struct rte_ether_addr bond_slave_mac_addr[GAZELLE_MAX_BOND_NUM]; -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index 0a82781..fa10e3f 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -18,7 +18,7 @@ - - #define NETCONN_IS_ACCEPTIN(sock) (((sock)->conn->acceptmbox != NULL) && !sys_mbox_empty((sock)->conn->acceptmbox)) - #define NETCONN_IS_DATAIN(sock) ((gazelle_ring_readable_count((sock)->recv_ring) || (sock)->recv_lastdata) || (sock->same_node_rx_ring != NULL && same_node_ring_count(sock))) --#define NETCONN_IS_DATAOUT(sock) (gazelle_ring_readover_count((sock)->send_ring) || (sock)->send_lastdata || (sock)->send_pre_del) -+#define NETCONN_IS_DATAOUT(sock) (gazelle_ring_readover_count((sock)->send_ring) || (sock)->send_pre_del) - #define NETCONN_IS_OUTIDLE(sock) gazelle_ring_readable_count((sock)->send_ring) - #define NETCONN_IS_UDP(sock) (NETCONNTYPE_GROUP(netconn_type((sock)->conn)) == NETCONN_UDP) - -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index 3eb4685..7baa38d 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -24,10 +24,6 @@ mbuf_count_per_conn = 170 - # send ring size, default is 32, max is 2048 - send_ring_size = 32 - --# 0: when send ring full, send return --# 1: when send ring full, alloc mbuf from mempool to send data --expand_send_ring = 0 -- - #protocol stack thread per loop params - #read data form protocol stack into recv_ring - read_connect_number = 4 --- -2.33.0 - diff --git a/0124-set-ltran.patch b/0124-set-ltran.patch deleted file mode 100644 index c477d3501ad182a40b2a54c7f0a3e9e18ad58ffc..0000000000000000000000000000000000000000 --- a/0124-set-ltran.patch +++ /dev/null @@ -1,25 +0,0 @@ -From c565ac1ced3eba745f22cdca849c3d38aaf386f1 Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Sat, 27 Jan 2024 02:22:11 +0000 -Subject: [PATCH] set ltran - ---- - src/lstack/lstack.conf | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index fc49944..60f3ee5 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -12,7 +12,7 @@ dpdk_args=["--socket-mem", "2048,0,0,0", "--huge-dir", "/mnt/hugepages-lstack", - - stack_thread_mode="run-to-wakeup" - --use_ltran=1 -+use_ltran=0 - kni_switch=0 - - low_power_mode=0 --- -2.33.0 - diff --git a/0125-add-bond-doc.patch b/0125-add-bond-doc.patch deleted file mode 100644 index 6f713275d38661cc1987687ea21f47cbfbbb68c3..0000000000000000000000000000000000000000 --- a/0125-add-bond-doc.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 44f8b983df75103b1bd3befbabeebe3ef406dbb1 Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Sat, 27 Jan 2024 09:16:46 +0000 -Subject: [PATCH] add bond doc - ---- - src/lstack/lstack.conf | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index 60f3ee5..a7f4e75 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -62,3 +62,8 @@ listen_shadow=0 - - #vlan mode; only support -1~4094, -1 is disabled - nic_vlan_mode=-1 -+ -+#bond mode; only support bond 4 or 6 mode ,-1 is disabled -+bond_mode=-1 -+#bond slave mac, separated by ; , only support 2 slave mac -+#bond_slave_mac="aa:bb:cc:dd:ee:ff;gg:hh:ii:jj:kk:ll" --- -2.33.0 - diff --git a/0126-cfg-host_addr-is-not-mandatory.patch b/0126-cfg-host_addr-is-not-mandatory.patch deleted file mode 100644 index 27a2f7127a6200aa59c253fdbdcd6fb25417e088..0000000000000000000000000000000000000000 --- a/0126-cfg-host_addr-is-not-mandatory.patch +++ /dev/null @@ -1,61 +0,0 @@ -From 1ad9802429cc2d2cf8eb90ec84cfed7d3c3d4feb Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Mon, 29 Jan 2024 15:01:05 +0800 -Subject: [PATCH] cfg: host_addr is not mandatory - ---- - src/lstack/core/lstack_cfg.c | 17 +++++++++++++++-- - 1 file changed, 15 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 028ea26..7e4482f 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -185,6 +185,10 @@ static int32_t parse_gateway_addr(void) - char *value; - bool ok; - -+ 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; -@@ -202,6 +206,10 @@ static int32_t parse_mask_addr(void) - uint32_t mask; - bool ok; - -+ 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; -@@ -225,7 +233,7 @@ static int32_t parse_host_addr(void) - - ok = config_lookup_string(&g_config, "host_addr", (const char **)&value); - if (!ok) { -- return -EINVAL; -+ return 0; - } - - g_config_params.host_addr.addr = inet_addr(value); -@@ -242,7 +250,12 @@ static int32_t parse_host_addr6(void) - - ok = config_lookup_string(&g_config, "host_addr6", (const char **)&value); - if (!ok) { -- return 0; -+ if (ip4_addr_isany_val(g_config_params.host_addr)) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: host_addr and host_addr6 must have a valid one."); -+ return -EINVAL; -+ } else { -+ return 0; -+ } - } - - if (ip6addr_aton(value, &g_config_params.host_addr6) == 0) { --- -2.33.0 - diff --git a/0127-add-bond1-support.patch b/0127-add-bond1-support.patch deleted file mode 100644 index e609d708e9ad9121558b568d3fe01186f6b9b3a0..0000000000000000000000000000000000000000 --- a/0127-add-bond1-support.patch +++ /dev/null @@ -1,139 +0,0 @@ -From cfe5641d29e425c9da54b270b7945d17ab5d594b Mon Sep 17 00:00:00 2001 -From: zhangmengxuan -Date: Mon, 22 Jan 2024 13:52:50 +0800 -Subject: [PATCH] add bond1 support - ---- - src/lstack/core/lstack_cfg.c | 28 ++++++++++++++++++++++++---- - src/lstack/core/lstack_dpdk.c | 24 ++++++++++++++++++++++++ - src/lstack/include/lstack_cfg.h | 1 + - 3 files changed, 49 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 7e4482f..b533a33 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -40,6 +40,8 @@ - #define NUMA_CPULIST_PATH "/sys/devices/system/node/node%u/cpulist" - #define DEV_MAC_LEN 17 - #define CPUS_MAX_NUM 256 -+#define BOND_MIIMON_MIN 1 -+#define BOND_MIIMON_MAX INT_MAX - - static struct cfg_params g_config_params; - -@@ -72,6 +74,7 @@ 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); - static int32_t parse_bond_slave_mac(void); - static int32_t parse_use_sockmap(void); - static int32_t parse_udp_enable(void); -@@ -134,6 +137,7 @@ static struct config_vector_t g_config_tbl[] = { - { "process_idx", parse_process_index }, - { "tuple_filter", parse_tuple_filter }, - { "bond_mode", parse_bond_mode }, -+ { "bond_miimon", parse_bond_miimon}, - { "bond_slave_mac", parse_bond_slave_mac }, - { "use_sockmap", parse_use_sockmap }, - { "udp_enable", parse_udp_enable }, -@@ -1181,14 +1185,30 @@ static int32_t parse_bond_mode(void) - if (g_config_params.bond_mode == -1) { - return 0; - } -- if (g_config_params.bond_mode != BONDING_MODE_8023AD && g_config_params.bond_mode != BONDING_MODE_ALB) { -- LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid bond mode = %d. only supports bond mode = 4,6.\n", -- g_config_params.bond_mode); -- return -EINVAL; -+ -+ switch (g_config_params.bond_mode) { -+ case BONDING_MODE_ACTIVE_BACKUP: -+ case BONDING_MODE_8023AD: -+ case BONDING_MODE_ALB: -+ break; -+ default: -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid bond mode = %d. only supports bond mode = 1,4,6.\n", -+ g_config_params.bond_mode); -+ return -EINVAL; // Invalid bond mode - } - return 0; - } - -+static int32_t parse_bond_miimon(void) -+{ -+ int32_t ret; -+ if (g_config_params.bond_mode == -1) { -+ return 0; -+ } -+ PARSE_ARG(g_config_params.bond_miimon, "bond_miimon", 10, BOND_MIIMON_MIN, BOND_MIIMON_MAX, ret); -+ return ret; -+} -+ - static int32_t parse_bond_slave_mac(void) - { - if (g_config_params.bond_mode == -1) { -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 7f1ceb8..e352850 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -462,6 +462,20 @@ static void rss_setup(const int port_id, const uint16_t nb_queues) - free(reta_conf); - } - -+int32_t dpdk_bond_primary_set(int port_id, int slave_port_id) -+{ -+ int32_t primary_port_id = ethdev_port_id(get_global_cfg_params()->mac_addr); -+ if (slave_port_id == primary_port_id) { -+ int32_t ret = rte_eth_bond_primary_set(port_id, primary_port_id); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk set bond primary port failed ret = %d\n", ret); -+ return -1; -+ } -+ return ret; -+ } -+ return 0; -+} -+ - int32_t dpdk_ethdev_init(int port_id, bool bond_port) - { - uint16_t nb_queues = get_global_cfg_params()->num_cpu; -@@ -533,6 +547,10 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - LSTACK_LOG(ERR, LSTACK, "dpdk add slave port failed ret = %d\n", ret); - return -1; - } -+ -+ if (get_global_cfg_params()->bond_mode == BONDING_MODE_ACTIVE_BACKUP) { -+ dpdk_bond_primary_set(port_id, slave_port_id[i]); -+ } - - ret = rte_eth_dev_start(slave_port_id[i]); - if (ret != 0) { -@@ -736,6 +754,12 @@ int32_t init_dpdk_ethdev(void) - } - } - -+ ret = rte_eth_bond_link_monitoring_set(bond_port_id, get_global_cfg_params()->bond_miimon); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk set bond link monitoring failed ret = %d\n", ret); -+ return -1; -+ } -+ - ret = rte_eth_promiscuous_enable(bond_port_id); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk enable promiscuous failed ret = %d\n", ret); -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 01d70fb..a00e47a 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -112,6 +112,7 @@ struct cfg_params { - uint16_t send_ring_size; - bool tuple_filter; - int8_t bond_mode; -+ int32_t bond_miimon; - struct rte_ether_addr bond_slave_mac_addr[GAZELLE_MAX_BOND_NUM]; - bool use_sockmap; - bool udp_enable; --- -2.33.0 - diff --git a/0128-fix-t_params-double-free.patch b/0128-fix-t_params-double-free.patch deleted file mode 100644 index 6335292a4f8b014ff5baa23fc0fc9356a874076c..0000000000000000000000000000000000000000 --- a/0128-fix-t_params-double-free.patch +++ /dev/null @@ -1,77 +0,0 @@ -From 8905d508d754a6d75516bbf26839848f4dfef282 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 29 Jan 2024 19:11:45 +0800 -Subject: [PATCH] fix t_params double free - ---- - src/lstack/core/lstack_protocol_stack.c | 16 +++++++++------- - 1 file changed, 9 insertions(+), 7 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 800872b..bb7ec17 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -660,7 +660,7 @@ int32_t stack_setup_thread(void) - for (uint32_t i = 0; i < queue_num; ++i) { - t_params[i] = malloc(sizeof(struct thread_params)); - if (t_params[i] == NULL) { -- goto OUT; -+ goto OUT1; - } - } - -@@ -669,18 +669,18 @@ int32_t stack_setup_thread(void) - 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 OUT; -+ goto OUT1; - } - } else { - ret = sprintf_s(name, sizeof(name), "%s_%d_%d", LSTACK_SEND_THREAD_NAME, process_index, i / 2); - if (ret < 0) { -- goto OUT; -+ goto OUT1; - } - } - } else { - ret = sprintf_s(name, sizeof(name), "%s", LSTACK_THREAD_NAME); - if (ret < 0) { -- goto OUT; -+ goto OUT1; - } - } - -@@ -689,24 +689,26 @@ int32_t stack_setup_thread(void) - - ret = create_thread((void *)t_params[i], name, gazelle_stack_thread); - if (ret != 0) { -- goto OUT; -+ goto OUT1; - } - } - - /* 2: wait stack thread and kernel_event thread init finish */ - wait_sem_value(&g_stack_group.sem_stack_setup, queue_num * 2); - if (g_stack_group.stack_setup_fail) { -- goto OUT; -+ /* t_params free by stack thread */ -+ goto OUT2; - } - g_stack_group.stack_num = queue_num; - - return 0; --OUT: -+OUT1: - for (int32_t i = 0; i < queue_num; ++i) { - if (t_params[i] != NULL) { - free(t_params[i]); - } - } -+OUT2: - return -1; - } - --- -2.33.0 - diff --git a/0129-fix-receive-fin-packet-process-error.patch b/0129-fix-receive-fin-packet-process-error.patch deleted file mode 100644 index 4c8ec0e69e839c84f21819d999d715f644c7d71b..0000000000000000000000000000000000000000 --- a/0129-fix-receive-fin-packet-process-error.patch +++ /dev/null @@ -1,155 +0,0 @@ -From 517d32ae3467596ca8173ff5f9300aa7d84d2b7f Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 22 Jan 2024 17:30:30 +0800 -Subject: [PATCH] fix receive fin packet process error - ---- - src/lstack/core/lstack_lwip.c | 67 +++++++++++++++++++++++------------ - 1 file changed, 45 insertions(+), 22 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index fe30edf..a7201aa 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -38,6 +38,8 @@ - #include "lstack_cfg.h" - #include "lstack_lwip.h" - -+static const uint8_t fin_packet = 0; -+ - static void free_ring_pbuf(struct rte_ring *ring) - { - void *pbufs[SOCK_RECV_RING_SIZE]; -@@ -509,13 +511,15 @@ static inline struct pbuf *pbuf_last(struct pbuf *pbuf) - ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, u8_t apiflags) - { - if (sock->conn->recvmbox == NULL) { -- return 0; -+ sock->conn->pending_err = ERR_CONN; -+ GAZELLE_RETURN(ENOTCONN); - } - - free_recv_ring_readover(sock->recv_ring); - - uint32_t free_count = gazelle_ring_free_count(sock->recv_ring); - if (free_count == 0) { -+ sock->conn->pending_err = ERR_WOULDBLOCK; - GAZELLE_RETURN(EAGAIN); - } - -@@ -534,12 +538,19 @@ ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, u8_t apifl - err = netconn_recv_tcp_pbuf_flags(sock->conn, &pbufs[i], apiflags); - } - if (err != ERR_OK) { -- if (recv_len > 0) { -- /* already received data, return that (this trusts in getting the same error from -- netconn layer again next time netconn_recv is called) */ -+ /* fin has been read from recvmbox, put it to recv_ring */ -+ if (!NETCONN_IS_UDP(sock) && -+ (netconn_is_flag_set(sock->conn, NETCONN_FIN_RX_PENDING) || err == ERR_CLSD)) { -+ /* fin has been read, lwip don't need to process fin packet */ -+ netconn_clear_flags(sock->conn, NETCONN_FIN_RX_PENDING); -+ pbufs[i] = NULL; -+ read_count++; - break; - } -- return (err == ERR_CLSD) ? 0 : -1; -+ -+ /* store err to pending_err again, clear it after app read */ -+ sock->conn->pending_err = err; -+ GAZELLE_RETURN(err_to_errno(err)); - } - - recv_len += pbufs[i]->tot_len; -@@ -551,25 +562,17 @@ ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, u8_t apifl - } - - uint32_t enqueue_num = gazelle_ring_sp_enqueue(sock->recv_ring, (void **)pbufs, read_count); -- for (uint32_t i = enqueue_num; i < read_count; i++) { -- if (NETCONN_IS_UDP(sock)) { -- pbuf_free(pbufs[i]); -- } else { -- /* update receive window */ -- tcp_recved(sock->conn->pcb.tcp, pbufs[i]->tot_len); -- pbuf_free(pbufs[i]); -- } -- sock->stack->stats.read_lwip_drop++; -+ if (enqueue_num != read_count) { -+ LSTACK_LOG(ERR, LSTACK, "Code shouldn't get here!\n"); - } - - for (uint32_t i = 0; get_protocol_stack_group()->latency_start && i < read_count; i++) { -- calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_LWIP); -+ if (pbufs[i] != NULL) { -+ calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_LWIP); -+ } - } - - sock->stack->stats.read_lwip_cnt += read_count; -- if (recv_len == 0) { -- GAZELLE_RETURN(EAGAIN); -- } - return recv_len; - } - -@@ -817,7 +820,8 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - bool latency_enable = get_protocol_stack_group()->latency_start; - - if (sock->errevent > 0 && !NETCONN_IS_DATAIN(sock)) { -- return 0; -+ errno = err_to_errno(netconn_err(sock->conn)); -+ return -1; - } - - thread_bind_stack(sock); -@@ -839,7 +843,8 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - while (gazelle_ring_read(sock->recv_ring, (void **)&pbuf, 1) != 1 && recvd == 0) { - /* if the connection is disconnected, recv return 0 */ - if (sock->errevent > 0 && !NETCONN_IS_DATAIN(sock)) { -- return 0; -+ errno = err_to_errno(netconn_err(sock->conn)); -+ return -1; - } - - lstack_block_wait(sock->wakeup); -@@ -847,6 +852,23 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - } - } - -+ /* fin */ -+ if (unlikely(pbuf == NULL)) { -+ if (recvd > 0) { -+ /* read data first, then read fin */ -+ sock->recv_lastdata = (void *)&fin_packet; -+ gazelle_ring_read_over(sock->recv_ring); -+ break; -+ } -+ gazelle_ring_read_over(sock->recv_ring); -+ return 0; -+ } -+ -+ /* pending fin */ -+ if (unlikely(pbuf == (void *)&fin_packet)) { -+ return 0; -+ } -+ - copy_len = (recv_left > pbuf->tot_len) ? pbuf->tot_len : recv_left; - if (copy_len > UINT16_MAX) { - copy_len = UINT16_MAX; -@@ -946,10 +968,11 @@ void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num) - } else { - len = lwip_recv(sock->conn->socket, NULL, 0, 0); - } -- if (len == 0) { -+ if (len < 0 && errno != EAGAIN) { - sock->errevent = 1; - add_sock_event(sock, EPOLLERR); -- } else if (len > 0) { -+ /* = 0: fin */ -+ } else if (len >= 0) { - add_sock_event(sock, EPOLLIN); - } - } --- -2.33.0 - diff --git a/0130-support-netperf-UDP_STREAM-and-UDP_RR.patch b/0130-support-netperf-UDP_STREAM-and-UDP_RR.patch deleted file mode 100644 index 0d75020aacdccdfa9e606ebed793bf18882b4da8..0000000000000000000000000000000000000000 --- a/0130-support-netperf-UDP_STREAM-and-UDP_RR.patch +++ /dev/null @@ -1,129 +0,0 @@ -From abbd69fdbc7b43229093a1ec57ea6d0dd952db8d Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Fri, 26 Jan 2024 17:21:38 +0800 -Subject: [PATCH] support netperf UDP_STREAM and UDP_RR - ---- - src/lstack/api/lstack_rtw_api.c | 7 +++---- - src/lstack/api/lstack_wrap.c | 1 + - src/lstack/core/lstack_lwip.c | 21 +++++++++++++++------ - 3 files changed, 19 insertions(+), 10 deletions(-) - -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index 04944d5..839d320 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -160,10 +160,10 @@ static ssize_t rtw_udp_recvfrom(int sockfd, void *buf, size_t len, int flags, - - while (1) { - ret = do_lwip_read_from_stack(sockfd, buf, len, flags, addr, addrlen); -- if (ret > 0) { -+ if (ret >= 0) { - return ret; - } -- if (ret <= 0 && errno != EAGAIN) { -+ if (ret < 0 && errno != EAGAIN) { - return -1; - } - sock = sock->listen_next; -@@ -205,7 +205,6 @@ ssize_t rtw_sendto(int sockfd, const void *buf, size_t len, int flags, - return do_lwip_send_to_stack(sockfd, buf, len, flags, addr, addrlen); - } - -- - int rtw_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) - { - return lstack_rtw_epoll_wait(epfd, events, maxevents, timeout); -@@ -234,7 +233,7 @@ int rtw_shutdown(int fd, int how) - { - struct lwip_sock *sock = get_socket_by_fd(fd); - if (sock && sock->wakeup && sock->wakeup->epollfd == fd) { -- GAZELLE_RETURN(ENOTSOCK); -+ GAZELLE_RETURN(ENOTSOCK); - } - - return stack_broadcast_shutdown(fd, how); -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 372e102..8992e39 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -375,6 +375,7 @@ static bool unsupport_optname(int32_t optname) - optname == SO_RCVBUF || - optname == TCP_INFO || - optname == TCP_MAXSEG || -+ optname == SO_DONTROUTE || - optname == TCP_CONGESTION) { - return true; - } -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index a7201aa..22605dd 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -402,7 +402,7 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - } - - struct protocol_stack *stack = sock->stack; -- if (!stack || len == 0) { -+ if (!stack) { - return 0; - } - -@@ -421,6 +421,11 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - uint32_t write_avail = gazelle_ring_readable_count(sock->send_ring); - struct wakeup_poll *wakeup = sock->wakeup; - -+ /* if udp send 0 packet, set write_num to at least 1 */ -+ if (NETCONN_IS_UDP(sock) && write_num == 0) { -+ write_num = 1; -+ } -+ - while (!netconn_is_nonblocking(sock->conn) && (write_avail < write_num)) { - if (sock->errevent > 0) { - GAZELLE_RETURN(ENOTCONN); -@@ -454,7 +459,7 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - } - - END: -- if (send_len == 0) { -+ if (send_len == 0 && !NETCONN_IS_UDP(sock)) { - errno = EAGAIN; - return -1; - } -@@ -735,19 +740,18 @@ ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t f - GAZELLE_RETURN(EINVAL); - } - -- if (len == 0) { -+ struct lwip_sock *sock = get_socket_by_fd(fd); -+ if (len == 0 && !NETCONN_IS_UDP(sock)) { - return 0; - } - -- struct lwip_sock *sock = get_socket_by_fd(fd); -- - thread_bind_stack(sock); - - if (sock->same_node_tx_ring != NULL) { - return gazelle_same_node_ring_send(sock, buf, len, flags); - } - ssize_t send = do_lwip_fill_sendring(sock, buf, len, addr, addrlen); -- if (send <= 0) { -+ if (send < 0 || (send == 0 && !NETCONN_IS_UDP(sock))) { - return send; - } - -@@ -852,6 +856,11 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - } - } - -+ /* if udp recv a packet whose len is 0, return 0 */ -+ if (NETCONN_IS_UDP(sock) && pbuf->tot_len == 0) { -+ return 0; -+ } -+ - /* fin */ - if (unlikely(pbuf == NULL)) { - if (recvd > 0) { --- -2.33.0 - diff --git a/0131-adapt-lwip-2.2.0.patch b/0131-adapt-lwip-2.2.0.patch deleted file mode 100644 index dbbe0eafa34d8c457c8780236748f284147a9fe8..0000000000000000000000000000000000000000 --- a/0131-adapt-lwip-2.2.0.patch +++ /dev/null @@ -1,131 +0,0 @@ -From feaa11fb77f6134639885c378d87903fc2301331 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Tue, 6 Feb 2024 09:55:23 +0800 -Subject: [PATCH] adapt lwip-2.2.0 - ---- - src/lstack/api/lstack_rtw_api.c | 2 +- - src/lstack/core/lstack_lwip.c | 16 ++++++++-------- - src/lstack/core/lstack_protocol_stack.c | 8 ++++---- - 3 files changed, 13 insertions(+), 13 deletions(-) - -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index 839d320..10bc613 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -168,7 +168,7 @@ static ssize_t rtw_udp_recvfrom(int sockfd, void *buf, size_t len, int flags, - } - sock = sock->listen_next; - if (sock != NULL && sock->conn != NULL) { -- sockfd = sock->conn->socket; -+ sockfd = sock->conn->callback_arg.socket; - } else { - if (sock == NULL) { - errno = EAGAIN; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 22605dd..2ba18e2 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -973,9 +973,9 @@ void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num) - - ssize_t len = 0; - if (NETCONN_IS_UDP(sock)) { -- len = lwip_recv(sock->conn->socket, NULL, SSIZE_MAX, 0); -+ len = lwip_recv(sock->conn->callback_arg.socket, NULL, SSIZE_MAX, 0); - } else { -- len = lwip_recv(sock->conn->socket, NULL, 0, 0); -+ len = lwip_recv(sock->conn->callback_arg.socket, NULL, 0, 0); - } - if (len < 0 && errno != EAGAIN) { - sock->errevent = 1; -@@ -993,7 +993,7 @@ void do_lwip_connected_callback(struct netconn *conn) - return; - } - -- int32_t fd = conn->socket; -+ int32_t fd = conn->callback_arg.socket; - struct lwip_sock *sock = get_socket_by_fd(fd); - if (sock == NULL || sock->conn == NULL) { - return; -@@ -1033,9 +1033,9 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - conn->keep_cnt = pcb->keep_cnt; - - if (netconn != NULL) { -- conn->fd = netconn->socket; -+ conn->fd = netconn->callback_arg.socket; - conn->recv_cnt = (netconn->recvmbox == NULL) ? 0 : rte_ring_count(netconn->recvmbox->ring); -- struct lwip_sock *sock = get_socket(netconn->socket); -+ struct lwip_sock *sock = get_socket(netconn->callback_arg.socket); - if (sock != NULL) { - conn->recv_ring_cnt = (sock->recv_ring == NULL) ? 0 : gazelle_ring_readable_count(sock->recv_ring); - conn->recv_ring_cnt += (sock->recv_lastdata) ? 1 : 0; -@@ -1121,7 +1121,7 @@ uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, - conn[conn_num].l_port = pcbl->local_port; - conn[conn_num].tcp_sub_state = pcbl->state; - struct netconn *netconn = (struct netconn *)pcbl->callback_arg; -- conn[conn_num].fd = netconn != NULL ? netconn->socket : -1; -+ conn[conn_num].fd = netconn != NULL ? netconn->callback_arg.socket : -1; - if (netconn != NULL && netconn->acceptmbox != NULL) { - conn[conn_num].recv_cnt = rte_ring_count(netconn->acceptmbox->ring); - } -@@ -1319,7 +1319,7 @@ err_t same_node_ring_create(struct rte_ring **ring, int size, int port, char *na - static void init_same_node_ring(struct tcp_pcb *pcb) - { - struct netconn *netconn = (struct netconn *)pcb->callback_arg; -- struct lwip_sock *sock = get_socket(netconn->socket); -+ struct lwip_sock *sock = get_socket(netconn->callback_arg.socket); - - pcb->client_rx_ring = NULL; - pcb->client_tx_ring = NULL; -@@ -1334,7 +1334,7 @@ static void init_same_node_ring(struct tcp_pcb *pcb) - err_t create_same_node_ring(struct tcp_pcb *pcb) - { - struct netconn *netconn = (struct netconn *)pcb->callback_arg; -- struct lwip_sock *sock = get_socket(netconn->socket); -+ struct lwip_sock *sock = get_socket(netconn->callback_arg.socket); - - if (same_node_ring_create(&pcb->client_rx_ring, CLIENT_RING_SIZE, pcb->local_port, "client", "rx") != 0) { - goto END; -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 9e2197c..8b99e82 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -903,7 +903,7 @@ void stack_send(struct rpc_msg *msg) - return; - } - -- replenish_again = do_lwip_send(stack, sock->conn->socket, sock, len, 0); -+ replenish_again = do_lwip_send(stack, sock->conn->callback_arg.socket, sock, len, 0); - if (replenish_again < 0) { - __sync_fetch_and_sub(&sock->call_num, 1); - return; -@@ -1102,7 +1102,7 @@ int32_t stack_broadcast_close(int32_t fd) - if (sock == NULL || sock->conn == NULL) { - break; - } -- fd = sock->conn->socket; -+ fd = sock->conn->callback_arg.socket; - } while (sock); - - return ret; -@@ -1125,7 +1125,7 @@ int stack_broadcast_shutdown(int fd, int how) - if (sock == NULL || sock->conn == NULL) { - break; - } -- fd = sock->conn->socket; -+ fd = sock->conn->callback_arg.socket; - } while (sock); - - return ret; -@@ -1290,7 +1290,7 @@ int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *ad - } - - if (min_sock && min_sock->conn) { -- ret = rpc_call_accept(min_sock->conn->socket, addr, addrlen, flags); -+ ret = rpc_call_accept(min_sock->conn->callback_arg.socket, addr, addrlen, flags); - } - - if (min_sock && min_sock->wakeup && min_sock->wakeup->type == WAKEUP_EPOLL) { --- -2.33.0 - diff --git a/0132-add-observable-method-of-data-aggregation.patch b/0132-add-observable-method-of-data-aggregation.patch deleted file mode 100644 index b46fc91f0c2886679eee6c99bb0097847ef2ee7b..0000000000000000000000000000000000000000 --- a/0132-add-observable-method-of-data-aggregation.patch +++ /dev/null @@ -1,62 +0,0 @@ -From 36d2ddc58cd0f467d6d7682689cc10947a8a1973 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Tue, 6 Feb 2024 11:29:26 +0800 -Subject: [PATCH] add observable method of data aggregation - ---- - src/common/gazelle_dfx_msg.h | 2 ++ - src/lstack/core/lstack_lwip.c | 2 ++ - src/ltran/ltran_dfx.c | 4 +++- - 3 files changed, 7 insertions(+), 1 deletion(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index d465efa..1ca210b 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -73,6 +73,8 @@ struct gazelle_stack_stat { - uint64_t tx; - uint64_t tx_prepare_fail; - uint64_t accept_fail; -+ uint64_t sock_rx_drop; -+ uint64_t sock_tx_merge; - }; - - struct gazelle_wakeup_stat { -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 63044c2..4523907 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -541,6 +541,7 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - - /* merge data into last pbuf */ - if (!NETCONN_IS_UDP(sock) && sock->remain_len) { -+ sock->stack->stats.sock_tx_merge++; - send_len = merge_data_lastpbuf(sock, (char *)buf, len); - if (send_len >= len) { - send_len = len; -@@ -1039,6 +1040,7 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - - /* in udp, if pbuf remaining len less than copy_len, discard these packets */ - if (recvd > 0 && NETCONN_IS_UDP(sock)) { -+ sock->stack->stats.sock_rx_drop++; - break; - } - } -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 4b246a1..9f12096 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -648,7 +648,9 @@ static void show_lstack_stats(struct gazelle_stack_dfx_data *lstack_stat) - printf("send_pkts_fail: %-13"PRIu64" ", lstack_stat->data.pkts.stack_stat.send_pkts_fail); - printf("mbuf_pool_freecnt: %-10"PRIu32" ", lstack_stat->data.pkts.mbufpool_avail_cnt); - printf("rpc_pool_freecnt: %-12"PRIu32" \n", lstack_stat->data.pkts.rpcpool_avail_cnt); -- printf("accpet_fail: %-12"PRIu64" \n", lstack_stat->data.pkts.stack_stat.accept_fail); -+ printf("accpet_fail: %-16"PRIu64" ", lstack_stat->data.pkts.stack_stat.accept_fail); -+ printf("sock_rx_drop: %-15"PRIu64" ", lstack_stat->data.pkts.stack_stat.sock_rx_drop); -+ printf("sock_tx_merge: %-16"PRIu64" \n", lstack_stat->data.pkts.stack_stat.sock_tx_merge); - } - - static void gazelle_print_lstack_stat_detail(struct gazelle_stack_dfx_data *lstack_stat, --- -2.27.0 - diff --git a/0133-try-to-ensure-arp-packet-can-be-sent.patch b/0133-try-to-ensure-arp-packet-can-be-sent.patch deleted file mode 100644 index ef48dd53ea69dc60b93b15816107ce91208d5f0b..0000000000000000000000000000000000000000 --- a/0133-try-to-ensure-arp-packet-can-be-sent.patch +++ /dev/null @@ -1,191 +0,0 @@ -From 1a7bb2f60a459c2cca6646ccbe04a52fcd8272f6 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 31 Jan 2024 14:49:40 +0800 -Subject: [PATCH] try to ensure arp packet can be sent - ---- - src/lstack/core/lstack_dpdk.c | 18 ++++++++++-------- - src/lstack/core/lstack_lwip.c | 13 ++++++++++--- - src/lstack/core/lstack_protocol_stack.c | 4 ++-- - src/lstack/include/lstack_dpdk.h | 2 +- - src/lstack/include/lstack_protocol_stack.h | 2 +- - src/lstack/netif/lstack_ethdev.c | 8 ++++---- - src/lstack/netif/lstack_vdev.c | 2 +- - 7 files changed, 29 insertions(+), 20 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index e352850..74e033b 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -280,14 +280,16 @@ int32_t create_shared_ring(struct protocol_stack *stack) - return 0; - } - --int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num) -+int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num, bool reserve) - { -- /* -- * don't use rte_mempool_avail_count, it traverse cpu local cache, -- * when RTE_MAX_LCORE is too large, it's time-consuming -- */ -- if (rte_ring_count(pool->pool_data) < MBUFPOOL_RESERVE_NUM + num) { -- return -ENOMEM; -+ if (reserve) { -+ /* -+ * don't use rte_mempool_avail_count, it traverse cpu local cache, -+ * when RTE_MAX_LCORE is too large, it's time-consuming -+ */ -+ if (rte_ring_count(pool->pool_data) < MBUFPOOL_RESERVE_NUM + num) { -+ return -ENOMEM; -+ } - } - - int32_t ret = rte_pktmbuf_alloc_bulk(pool, mbufs, num); -@@ -310,7 +312,7 @@ int32_t fill_mbuf_to_ring(struct rte_mempool *mempool, struct rte_ring *ring, ui - while (remain > 0) { - batch = LWIP_MIN(remain, RING_SIZE(FREE_RX_QUEUE_SZ)); - -- ret = dpdk_alloc_pktmbuf(mempool, free_buf, batch); -+ ret = dpdk_alloc_pktmbuf(mempool, free_buf, batch, true); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "cannot alloc mbuf for ring, count: %u ret=%d\n", batch, ret); - return -1; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 3f76424..da50fec 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -22,6 +22,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -101,7 +102,6 @@ static struct pbuf *init_mbuf_to_pbuf(struct rte_mbuf *mbuf, pbuf_layer layer, u - struct pbuf *pbuf = pbuf_alloced_custom(layer, length, type, pbuf_custom, data, MAX_PACKET_SZ); - if (pbuf) { - pbuf->allow_in = 1; -- pbuf->last = pbuf; - pbuf->addr = *IP_ANY_TYPE; - pbuf->port = 0; - pthread_spin_init(&pbuf->pbuf_lock, PTHREAD_PROCESS_SHARED); -@@ -122,7 +122,7 @@ static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_so - return false; - } - -- if (dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)pbuf, replenish_cnt) != 0) { -+ if (dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)pbuf, replenish_cnt, true) != 0) { - stack->stats.tx_allocmbuf_fail++; - return true; - } -@@ -209,10 +209,17 @@ void do_lwip_free_pbuf(struct pbuf *pbuf) - - struct pbuf *do_lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type type) - { -+ int ret; - struct rte_mbuf *mbuf; - struct protocol_stack *stack = get_protocol_stack(); - -- if (dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf, 1) != 0) { -+ /* ensure arp packet can be sent */ -+ if (layer == PBUF_LINK && length == SIZEOF_ETHARP_HDR) { -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf, 1, false); -+ } else { -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf, 1, true); -+ } -+ if (ret != 0) { - stack->stats.tx_allocmbuf_fail++; - return NULL; - } -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 8b99e82..cb39928 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -940,7 +940,7 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - continue; - } - -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); - if (ret != 0) { - stack->stats.rx_allocmbuf_fail++; - return; -@@ -952,7 +952,7 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - return; - } - } -- ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); - if (ret != 0) { - cur_stack->stats.rx_allocmbuf_fail++; - return; -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index b39d199..c40f3c0 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -56,6 +56,6 @@ struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, - uint32_t mbuf_cache_size, uint16_t queue_id, unsigned numa_id); - - void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id); --int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num); -+int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num, bool reserve); - void dpdk_nic_features_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id); - #endif /* GAZELLE_DPDK_H */ -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index c681547..0a523b7 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -31,7 +31,7 @@ - #define SOCK_SEND_REPLENISH_THRES (16) - #define WAKEUP_MAX_NUM (32) - --#define MBUFPOOL_RESERVE_NUM 5000 -+#define MBUFPOOL_RESERVE_NUM (get_global_cfg_params()->nic.rxqueue_size + 1024) - - struct rte_mempool; - struct rte_ring; -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 4d6f620..acf3c10 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -543,9 +543,9 @@ void parse_arp_and_transefer(char* buf) - int32_t ret; - for (int32_t i = 0; i < stack_group->stack_num; i++) { - stack = stack_group->stacks[i]; -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); - while (ret != 0) { -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); - stack->stats.rx_allocmbuf_fail++; - } - copy_mbuf(mbuf_copy, mbuf); -@@ -572,9 +572,9 @@ void parse_tcp_and_transefer(char* buf) - struct rte_mbuf *mbuf_copy = NULL; - struct protocol_stack *stack = stack_group->stacks[stk_index]; - -- int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1); -+ int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); - while (ret != 0) { -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1); -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); - stack->stats.rx_allocmbuf_fail++; - } - -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index fe17f59..f78e48a 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -59,7 +59,7 @@ static uint32_t ltran_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pk - stack->rx_ring_used += rcvd_pkts; - if (unlikely(stack->rx_ring_used >= USED_RX_PKTS_WATERMARK)) { - uint32_t free_cnt = LWIP_MIN(stack->rx_ring_used, RING_SIZE(DPDK_PKT_BURST_SIZE)); -- int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)free_buf, free_cnt); -+ int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)free_buf, free_cnt, true); - if (likely(ret == 0)) { - nr_pkts = gazelle_ring_sp_enqueue(stack->rx_ring, (void **)free_buf, free_cnt); - stack->rx_ring_used -= nr_pkts; --- -2.27.0 - diff --git a/0134-gazellectl-support-send-latency-show.patch b/0134-gazellectl-support-send-latency-show.patch deleted file mode 100644 index 5950ca75ce63d4141dcde6f33a9ac9b7d1adb7fc..0000000000000000000000000000000000000000 --- a/0134-gazellectl-support-send-latency-show.patch +++ /dev/null @@ -1,345 +0,0 @@ -From 03eabf12b7d486278598ad44d2b7d8e310ff0abf Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Sun, 4 Feb 2024 13:29:15 +0800 -Subject: [PATCH] gazellectl: support send latency show - ---- - src/common/dpdk_common.h | 10 +++ - src/common/gazelle_dfx_msg.h | 20 ++++- - src/lstack/core/lstack_lwip.c | 14 +++- - src/lstack/core/lstack_stack_stat.c | 15 ++-- - src/lstack/netif/lstack_ethdev.c | 4 + - src/ltran/ltran_dfx.c | 110 +++++++++++++++------------- - 6 files changed, 111 insertions(+), 62 deletions(-) - -diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h -index 38f09ae..a79a0f2 100644 ---- a/src/common/dpdk_common.h -+++ b/src/common/dpdk_common.h -@@ -95,6 +95,16 @@ static __rte_always_inline void time_stamp_into_mbuf(uint32_t rx_count, struct r - } - } - -+static __rte_always_inline void time_stamp_into_pbuf(uint32_t tx_count, struct pbuf *buf[], uint64_t time_stamp) -+{ -+ struct latency_timestamp *lt; -+ for (uint32_t i = 0; i < tx_count; i++) { -+ lt = &pbuf_to_private(buf[i])->lt; -+ lt->stamp = time_stamp; -+ lt->check = ~(time_stamp); -+ } -+} -+ - bool get_kni_started(void); - struct rte_kni* get_gazelle_kni(void); - int32_t dpdk_kni_init(uint16_t port, struct rte_mempool *pool); -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index d465efa..d47ed9a 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -24,6 +24,10 @@ - /* maybe it should be consistent with MEMP_NUM_TCP_PCB */ - #define GAZELLE_LSTACK_MAX_CONN (20000 + 2000) // same as MAX_CLIENTS + RESERVED_CLIENTS in lwipopts.h - -+#define GAZELLE_RESULT_LEN 4096 -+#define GAZELLE_MAX_LATENCY_TIME 1800 // max latency time 30mins -+#define GAZELLE_RESULT_LINE_LEN 80 // for a single row, the max len of result is 80 -+ - enum GAZELLE_STAT_MODE { - GAZELLE_STAT_LTRAN_SHOW = 0, - GAZELLE_STAT_LTRAN_SHOW_RATE, -@@ -54,8 +58,11 @@ enum GAZELLE_STAT_MODE { - }; - - enum GAZELLE_LATENCY_TYPE { -- GAZELLE_LATENCY_LWIP, -- GAZELLE_LATENCY_READ, -+ GAZELLE_LATENCY_READ_LWIP, -+ GAZELLE_LATENCY_READ_LSTACK, -+ GAZELLE_LATENCY_WRITE_LWIP, -+ GAZELLE_LATENCY_WRITE_LSTACK, -+ GAZELLE_LATENCY_MAX, - }; - - struct gazelle_stack_stat { -@@ -216,9 +223,14 @@ struct stack_latency { - uint64_t latency_total; - }; - -+struct gazelle_latency_result { -+ int latency_stat_index; -+ struct stack_latency latency_stat_record; -+ char latency_stat_result[GAZELLE_RESULT_LEN]; -+}; -+ - struct gazelle_stack_latency { -- struct stack_latency read_latency; -- struct stack_latency lwip_latency; -+ struct stack_latency latency[GAZELLE_LATENCY_MAX]; - uint64_t start_time; - uint64_t g_cycles_per_us; - }; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 22605dd..be2c6de 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -244,6 +244,11 @@ struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_s - if (pbuf == NULL) { - return NULL; - } -+ -+ if (get_protocol_stack_group()->latency_start) { -+ calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LWIP); -+ } -+ - sock->send_pre_del = pbuf; - - if (!gazelle_ring_readover_count(sock->send_ring)) { -@@ -303,6 +308,11 @@ static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t l - - (void)gazelle_ring_read(sock->send_ring, (void **)pbufs, write_num); - -+ if (get_protocol_stack_group()->latency_start) { -+ uint64_t time_stamp = get_current_time(); -+ time_stamp_into_pbuf(write_num, pbufs, time_stamp); -+ } -+ - ssize_t send_len = do_app_write(pbufs, buf, len, write_num); - - if (addr) { -@@ -573,7 +583,7 @@ ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, u8_t apifl - - for (uint32_t i = 0; get_protocol_stack_group()->latency_start && i < read_count; i++) { - if (pbufs[i] != NULL) { -- calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_LWIP); -+ calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_READ_LWIP); - } - } - -@@ -895,7 +905,7 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - sock->wakeup->stat.app_read_cnt += 1; - } - if (latency_enable) { -- calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_READ); -+ calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK); - } - gazelle_ring_read_over(sock->recv_ring); - -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 23571b4..cb11dc3 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -53,8 +53,9 @@ void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const - { - uint64_t latency; - const struct latency_timestamp *lt; -+ struct stack_latency *latency_stat; - -- if (pbuf == NULL) { -+ if (pbuf == NULL || type >= GAZELLE_LATENCY_MAX) { - return; - } - -@@ -62,10 +63,9 @@ void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const - if (lt->stamp != ~(lt->check) || lt->stamp < stack_latency->start_time) { - return; - } -- latency = get_current_time() - lt->stamp; - -- struct stack_latency *latency_stat = (type == GAZELLE_LATENCY_LWIP) ? -- &stack_latency->lwip_latency : &stack_latency->read_latency; -+ latency = get_current_time() - lt->stamp; -+ latency_stat = &stack_latency->latency[type]; - - latency_stat->latency_total += latency; - latency_stat->latency_max = (latency_stat->latency_max > latency) ? latency_stat->latency_max : latency; -@@ -118,8 +118,11 @@ static void set_latency_start_flag(bool start) - LSTACK_LOG(ERR, LSTACK, "memset_s faile\n"); - } - stack->latency.start_time = get_current_time(); -- stack->latency.lwip_latency.latency_min = ~((uint64_t)0); -- stack->latency.read_latency.latency_min = ~((uint64_t)0); -+ -+ for (uint32_t j = 0; j < GAZELLE_LATENCY_MAX; j++) { -+ stack->latency.latency[j].latency_min = ~((uint64_t)0); -+ } -+ - memset_s(&stack->aggregate_stats, sizeof(struct gazelle_stack_aggregate_stats), - 0, sizeof(stack->aggregate_stats)); - } -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 4d6f620..94ecffc 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -889,6 +889,10 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - - pre_mbuf = mbuf; - rte_mbuf_refcnt_update(mbuf, 1); -+ -+ if (get_protocol_stack_group()->latency_start) { -+ calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LSTACK); -+ } - pbuf = pbuf->next; - } - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 4b246a1..ecdb5f9 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -50,9 +50,6 @@ - #define GAZELLE_CMD_MAX 5 - #define CMD_WAIT_TIME 1 // sec - --#define GAZELLE_RESULT_LEN 8291 --#define GAZELLE_MAX_LATENCY_TIME 1800 // max latency time 30mins -- - #define GAZELLE_DECIMAL 10 - #define GAZELLE_KEEPALIVE_STR_LEN 35 - #define GAZELLE_TIME_STR_LEN 25 -@@ -702,8 +699,8 @@ static void parse_thread_latency_result(const struct stack_latency *latency, cha - { - if (latency->latency_pkts > 0) { - *pos += sprintf_s(result + *pos, max_len, "%-8"PRIu64" ", latency->latency_pkts); -- *pos += sprintf_s(result + *pos, max_len, "%-6"PRIu64" ", latency->latency_min); -- *pos += sprintf_s(result + *pos, max_len, "%-6"PRIu64" ", latency->latency_max); -+ *pos += sprintf_s(result + *pos, max_len, "%-8"PRIu64" ", latency->latency_min); -+ *pos += sprintf_s(result + *pos, max_len, "%-8"PRIu64" ", latency->latency_max); - *pos += sprintf_s(result + *pos, max_len, "%-6.2f \n", - (double)latency->latency_total / latency->latency_pkts); - } else { -@@ -719,52 +716,53 @@ static void parse_thread_latency_result(const struct stack_latency *latency, cha - static void parse_latency_total_result(char *result, size_t max_len, int32_t *pos, - const struct stack_latency *record) - { -+ if (max_len < GAZELLE_RESULT_LINE_LEN) { -+ printf("total latency result show failed, out of memory bounds\n"); -+ return; -+ } -+ - if (record->latency_pkts > 0) { -- *pos += sprintf_s(result + *pos, max_len, " total: "); -+ *pos += sprintf_s(result + *pos, max_len, " total: "); - *pos += sprintf_s(result + *pos, max_len, "%-8"PRIu64" ", record->latency_pkts); -- *pos += sprintf_s(result + *pos, max_len, "%-6"PRIu64" ", record->latency_min); -- *pos += sprintf_s(result + *pos, max_len, "%-6"PRIu64" ", record->latency_max); -- *pos += sprintf_s(result + *pos, max_len, "%-6.2f \n\n\n", -+ *pos += sprintf_s(result + *pos, max_len, "%-8"PRIu64" ", record->latency_min); -+ *pos += sprintf_s(result + *pos, max_len, "%-8"PRIu64" ", record->latency_max); -+ *pos += sprintf_s(result + *pos, max_len, "%-6.2f \n\n", - (double)record->latency_total / record->latency_pkts); - } else { -- *pos += sprintf_s(result + *pos, max_len, " total: 0\n\n\n"); -+ *pos += sprintf_s(result + *pos, max_len, " total: 0\n\n"); - } - } - --static void gazelle_print_lstack_stat_latency(void *buf, const struct gazelle_stat_msg_request *req_msg) -+static void gazelle_show_latency_result(const struct gazelle_stat_msg_request *req_msg, -+ struct gazelle_stack_dfx_data *stat, struct stack_latency *latency, -+ struct gazelle_latency_result *res) - { -- struct gazelle_stack_dfx_data *stat = (struct gazelle_stack_dfx_data *)buf; -- struct gazelle_stack_latency *latency = &stat->data.latency; -- int32_t ret = GAZELLE_OK; -- int32_t lwip_index = 0; -- int32_t read_index = 0; -- struct stack_latency lwip_record = {0}; -- struct stack_latency read_record = {0}; -- char str_ip[GAZELLE_SUBNET_LENGTH_MAX] = {0}; -+ char str_ip[GAZELLE_SUBNET_LENGTH_MAX] = { 0 }; - -- read_record.latency_min = ~((uint64_t)0); -- lwip_record.latency_min = ~((uint64_t)0); -- -- char *lwip_result = calloc(GAZELLE_RESULT_LEN, sizeof(char)); -- if (lwip_result == NULL) { -- return; -- } -- char *read_result = calloc(GAZELLE_RESULT_LEN, sizeof(char)); -- if (read_result == NULL) { -- free(lwip_result); -+ if (GAZELLE_RESULT_LEN - res->latency_stat_index < GAZELLE_RESULT_LINE_LEN) { -+ printf("too many threads show latency result, out of memory bounds\n"); - return; - } - -- do { -- lwip_index += sprintf_s(lwip_result + lwip_index, (size_t)(GAZELLE_RESULT_LEN - lwip_index), -- "ip: %-15s tid: %-8u ", inet_ntop(AF_INET, &req_msg->ip, str_ip, sizeof(str_ip)), stat->tid); -- parse_thread_latency_result(&latency->lwip_latency, lwip_result, (size_t)(GAZELLE_RESULT_LEN - lwip_index), -- &lwip_index, &lwip_record); -+ res->latency_stat_index += sprintf_s(res->latency_stat_result + res->latency_stat_index, -+ (size_t)(GAZELLE_RESULT_LEN - res->latency_stat_index), "ip: %-15s tid: %-8u ", -+ inet_ntop(AF_INET, &req_msg->ip, str_ip, sizeof(str_ip)), stat->tid); - -- read_index += sprintf_s(read_result + read_index, (size_t)(GAZELLE_RESULT_LEN - read_index), -- "ip: %-15s tid: %-8u ", inet_ntop(AF_INET, &req_msg->ip, str_ip, sizeof(str_ip)), stat->tid); -- parse_thread_latency_result(&latency->read_latency, read_result, (size_t)(GAZELLE_RESULT_LEN - read_index), -- &read_index, &read_record); -+ parse_thread_latency_result(latency, res->latency_stat_result, -+ (size_t)(GAZELLE_RESULT_LEN - res->latency_stat_index), &res->latency_stat_index, &res->latency_stat_record); -+} -+ -+static void gazelle_show_latency_result_total(void *buf, const struct gazelle_stat_msg_request *req_msg, -+ struct gazelle_latency_result *res) -+{ -+ int ret = GAZELLE_OK; -+ struct gazelle_stack_dfx_data *stat = (struct gazelle_stack_dfx_data *)buf; -+ struct gazelle_stack_latency *latency = &stat->data.latency; -+ -+ do { -+ for (int i = 0; i < GAZELLE_LATENCY_MAX; i++) { -+ gazelle_show_latency_result(req_msg, stat, &latency->latency[i], &res[i]); -+ } - - if ((stat->eof != 0) || (ret != GAZELLE_OK)) { - break; -@@ -772,21 +770,33 @@ static void gazelle_print_lstack_stat_latency(void *buf, const struct gazelle_st - ret = dfx_stat_read_from_ltran(buf, sizeof(struct gazelle_stack_dfx_data), req_msg->stat_mode); - } while (true); - -- parse_latency_total_result(lwip_result, (size_t)(GAZELLE_RESULT_LEN - lwip_index), &lwip_index, &lwip_record); -- parse_latency_total_result(read_result, (size_t)(GAZELLE_RESULT_LEN - read_index), &read_index, &read_record); -+ for (int i = 0; i < GAZELLE_LATENCY_MAX; i++) { -+ parse_latency_total_result(res[i].latency_stat_result, (size_t)(GAZELLE_RESULT_LEN - res[i].latency_stat_index), -+ &res[i].latency_stat_index, &res[i].latency_stat_record); -+ } -+} -+ -+static void gazelle_print_lstack_stat_latency(void *buf, const struct gazelle_stat_msg_request *req_msg) -+{ -+ struct gazelle_latency_result *res = calloc(GAZELLE_LATENCY_MAX, sizeof(struct gazelle_latency_result)); -+ if (res == NULL) { -+ return; -+ } -+ -+ for (int i = 0; i < GAZELLE_LATENCY_MAX; i++) { -+ res[i].latency_stat_record.latency_min = ~((uint64_t)0); -+ } - -- printf("Statistics of lstack latency: t0--->t3 \ -- (t0:read form nic t1:into lstask queue t2:into app queue t3:app read)\n"); -- printf(" pkts min(us) max(us) average(us)\n%s", -- read_result); -+ gazelle_show_latency_result_total(buf, req_msg, res); - -- printf("Statistics of lstack latency: t0--->t2 \ -- (t0:read form nic t1:into lstask queue t2:into app queue t3:app read)\n"); -- printf(" pkts min(us) max(us) average(us)\n%s", -- lwip_result); -+ printf("Statistics of lstack latency pkts min(us) max(us) average(us)\n"); -+ printf("range: t0--->t3\n%s", res[GAZELLE_LATENCY_READ_LSTACK].latency_stat_result); -+ printf("range: t0--->t2\n%s", res[GAZELLE_LATENCY_READ_LWIP].latency_stat_result); -+ printf("range: t3--->t0\n%s", res[GAZELLE_LATENCY_WRITE_LSTACK].latency_stat_result); -+ printf("range: t2--->t0\n%s", res[GAZELLE_LATENCY_WRITE_LWIP].latency_stat_result); -+ printf("t0:read form/send to nic t1:into/out of lstask queue t2:into/out of app queue t3:app read/send\n"); - -- free(read_result); -- free(lwip_result); -+ free(res); - } - - static void gazelle_print_lstack_stat_lpm(void *buf, const struct gazelle_stat_msg_request *req_msg) --- -2.27.0 - diff --git a/0135-rpc-function-does-not-depend-on-protocol-stack.patch b/0135-rpc-function-does-not-depend-on-protocol-stack.patch deleted file mode 100644 index 1ca8ca53c3ffd9cb05e52183abb04f655bac54eb..0000000000000000000000000000000000000000 --- a/0135-rpc-function-does-not-depend-on-protocol-stack.patch +++ /dev/null @@ -1,1336 +0,0 @@ -From fe39b43f897be7d29f9b51e79d51395e43b83e23 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sun, 4 Feb 2024 19:46:17 +0800 -Subject: [PATCH] rpc function does not depend on protocol stack diff rpc queue - and dfx rpc queue - ---- - src/common/gazelle_dfx_msg.h | 1 - - src/lstack/api/lstack_rtw_api.c | 36 ++- - src/lstack/core/lstack_control_plane.c | 10 +- - src/lstack/core/lstack_dpdk.c | 4 +- - src/lstack/core/lstack_lwip.c | 2 +- - src/lstack/core/lstack_protocol_stack.c | 92 ++++---- - src/lstack/core/lstack_stack_stat.c | 18 +- - src/lstack/core/lstack_thread_rpc.c | 241 ++++++++------------- - src/lstack/include/lstack_control_plane.h | 3 - - src/lstack/include/lstack_protocol_stack.h | 36 +-- - src/lstack/include/lstack_rpc_proc.h | 46 ++++ - src/lstack/include/lstack_thread_rpc.h | 79 +++---- - src/lstack/netif/lstack_ethdev.c | 6 +- - src/ltran/ltran_dfx.c | 3 +- - 14 files changed, 292 insertions(+), 285 deletions(-) - create mode 100644 src/lstack/include/lstack_rpc_proc.h - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 1ca210b..a91a30f 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -101,7 +101,6 @@ struct gazelle_stack_aggregate_stats { - struct gazelle_stat_pkts { - uint16_t conn_num; - uint32_t mbufpool_avail_cnt; -- uint32_t rpcpool_avail_cnt; - uint64_t call_msg_cnt; - uint64_t recv_list_cnt; - uint64_t call_alloc_fail; -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index 10bc613..8498b8e 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -28,7 +28,11 @@ - - int rtw_socket(int domain, int type, int protocol) - { -- return rpc_call_socket(domain, type, protocol); -+ struct protocol_stack *stack = get_bind_protocol_stack(); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EINVAL); -+ } -+ return rpc_call_socket(&stack->rpc_queue, domain, type, protocol); - } - - int rtw_accept(int s, struct sockaddr *addr, socklen_t *addrlen) -@@ -64,27 +68,47 @@ int rtw_listen(int s, int backlog) - - int rtw_connect(int s, const struct sockaddr *name, socklen_t namelen) - { -- return rpc_call_connect(s, name, namelen); -+ struct protocol_stack *stack = get_protocol_stack_by_fd(s); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_connect(&stack->rpc_queue, s, name, namelen); - } - - int rtw_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) - { -- return rpc_call_setsockopt(s, level, optname, optval, optlen); -+ struct protocol_stack *stack = get_protocol_stack_by_fd(s); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_setsockopt(&stack->rpc_queue, s, level, optname, optval, optlen); - } - - int rtw_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) - { -- return rpc_call_getsockopt(s, level, optname, optval, optlen); -+ struct protocol_stack *stack = get_protocol_stack_by_fd(s); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_getsockopt(&stack->rpc_queue, s, level, optname, optval, optlen); - } - - int rtw_getpeername(int s, struct sockaddr *name, socklen_t *namelen) - { -- return rpc_call_getpeername(s, name, namelen); -+ struct protocol_stack *stack = get_protocol_stack_by_fd(s); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_getpeername(&stack->rpc_queue, s, name, namelen); - } - - int rtw_getsockname(int s, struct sockaddr *name, socklen_t *namelen) - { -- return rpc_call_getsockname(s, name, namelen); -+ struct protocol_stack *stack = get_protocol_stack_by_fd(s); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_getsockname(&stack->rpc_queue, s, name, namelen); - } - - ssize_t rtw_read(int s, void *mem, size_t len) -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index a9a3814..025291d 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -611,9 +611,10 @@ static int32_t thread_register(void) - /* register all connected conn before listen conn, avoid creating new conn */ - struct protocol_stack_group *stack_group = get_protocol_stack_group(); - for (int32_t i = 0; i < stack_group->stack_num; i++) { -- conn->conn_num = rpc_call_conntable(stack_group->stacks[i], conn->conn_list, GAZELLE_LSTACK_MAX_CONN); -+ conn->conn_num = rpc_call_conntable(&stack_group->stacks[i]->rpc_queue, -+ conn->conn_list, GAZELLE_LSTACK_MAX_CONN); - -- ret = rpc_call_thread_regphase1(stack_group->stacks[i], conn); -+ ret = rpc_call_thread_regphase1(&stack_group->stacks[i]->rpc_queue, conn); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "thread_register_phase1 failed ret=%d!\n", ret); - free(conn); -@@ -622,9 +623,10 @@ static int32_t thread_register(void) - } - - for (int32_t i = 0; i < stack_group->stack_num; i++) { -- conn->conn_num = rpc_call_conntable(stack_group->stacks[i], conn->conn_list, GAZELLE_LSTACK_MAX_CONN); -+ conn->conn_num = rpc_call_conntable(&stack_group->stacks[i]->rpc_queue, -+ conn->conn_list, GAZELLE_LSTACK_MAX_CONN); - -- ret = rpc_call_thread_regphase2(stack_group->stacks[i], conn); -+ ret = rpc_call_thread_regphase2(&stack_group->stacks[i]->rpc_queue, conn); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "thread_register_phase2 failed ret=%d!\n", ret); - free(conn); -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index e352850..985f1a5 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -45,7 +45,6 @@ - - #include "lstack_log.h" - #include "dpdk_common.h" --#include "lstack_lockless_queue.h" - #include "lstack_protocol_stack.h" - #include "lstack_thread_rpc.h" - #include "lstack_lwip.h" -@@ -258,7 +257,8 @@ struct rte_mempool *create_mempool(const char *name, uint32_t count, uint32_t si - - int32_t create_shared_ring(struct protocol_stack *stack) - { -- lockless_queue_init(&stack->rpc_queue); -+ rpc_queue_init(&stack->rpc_queue); -+ rpc_queue_init(&stack->dfx_rpc_queue); - - if (use_ltran()) { - stack->rx_ring = gazelle_ring_create_fast("RING_RX", VDEV_RX_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ); -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 3f76424..b79cdef 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -636,7 +636,7 @@ static inline void notice_stack_send(struct lwip_sock *sock, int32_t fd, int32_t - { - // 2: call_num >= 2, don't need add new rpc send - if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) < 2) { -- while (rpc_call_send(fd, NULL, len, flags) < 0) { -+ while (rpc_call_send(&sock->stack->rpc_queue, fd, NULL, len, flags) < 0) { - usleep(1000); // 1000: wait 1ms to exec again - } - __sync_fetch_and_add(&sock->call_num, 1); -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 8b99e82..f63fcb0 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -465,7 +465,10 @@ int stack_polling(uint32_t wakeup_tick) - uint32_t read_connect_number = cfg->read_connect_number; - struct protocol_stack *stack = get_protocol_stack(); - -- force_quit = poll_rpc_msg(stack, rpc_number); -+ /* 2: one dfx consumes two rpc */ -+ rpc_poll_msg(&stack->dfx_rpc_queue, 2); -+ force_quit = rpc_poll_msg(&stack->rpc_queue, rpc_number); -+ - gazelle_eth_dev_poll(stack, use_ltran_flag, nic_read_number); - sys_timer_run(); - if (cfg->low_power_mod != 0) { -@@ -715,7 +718,7 @@ OUT2: - void stack_arp(struct rpc_msg *msg) - { - struct rte_mbuf *mbuf = (struct rte_mbuf *)msg->args[MSG_ARG_0].p; -- struct protocol_stack *stack = (struct protocol_stack*)msg->args[MSG_ARG_1].p; -+ struct protocol_stack *stack = get_protocol_stack(); - - eth_dev_recv(mbuf, stack); - } -@@ -893,7 +896,7 @@ void stack_send(struct rpc_msg *msg) - { - int32_t fd = msg->args[MSG_ARG_0].i; - size_t len = msg->args[MSG_ARG_1].size; -- struct protocol_stack *stack = (struct protocol_stack *)msg->args[MSG_ARG_3].p; -+ struct protocol_stack *stack = get_protocol_stack(); - int replenish_again; - - struct lwip_sock *sock = get_socket(fd); -@@ -947,7 +950,7 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - } - copy_mbuf(mbuf_copy, mbuf); - -- ret = rpc_call_arp(stack, mbuf_copy); -+ ret = rpc_call_arp(&stack->rpc_queue, mbuf_copy); - if (ret != 0) { - return; - } -@@ -971,7 +974,7 @@ void stack_broadcast_clean_epoll(struct wakeup_poll *wakeup) - - for (int32_t i = 0; i < stack_group->stack_num; i++) { - stack = stack_group->stacks[i]; -- rpc_call_clean_epoll(stack, wakeup); -+ rpc_call_clean_epoll(&stack->rpc_queue, wakeup); - } - } - -@@ -985,17 +988,11 @@ void stack_clean_epoll(struct rpc_msg *msg) - - void stack_mempool_size(struct rpc_msg *msg) - { -- struct protocol_stack *stack = (struct protocol_stack*)msg->args[MSG_ARG_0].p; -+ struct protocol_stack *stack = get_protocol_stack(); - - msg->result = rte_mempool_avail_count(stack->rxtx_mbuf_pool); - } - --void stack_rpcpool_size(struct rpc_msg *msg) --{ -- struct rpc_msg_pool *rpc_mem_pool = (struct rpc_msg_pool*)msg->args[MSG_ARG_0].p; -- msg->result = rte_mempool_avail_count(rpc_mem_pool->mempool); --} -- - void stack_create_shadow_fd(struct rpc_msg *msg) - { - int32_t fd = msg->args[MSG_ARG_0].i; -@@ -1049,8 +1046,8 @@ void stack_create_shadow_fd(struct rpc_msg *msg) - - void stack_replenish_sendring(struct rpc_msg *msg) - { -- struct protocol_stack *stack = (struct protocol_stack *)msg->args[MSG_ARG_0].p; -- struct lwip_sock *sock = (struct lwip_sock *)msg->args[MSG_ARG_1].p; -+ struct protocol_stack *stack = get_protocol_stack(); -+ struct lwip_sock *sock = (struct lwip_sock *)msg->args[MSG_ARG_0].p; - - msg->result = do_lwip_replenish_sendring(stack, sock); - } -@@ -1070,7 +1067,7 @@ void stack_get_connnum(struct rpc_msg *msg) - - void stack_recvlist_count(struct rpc_msg *msg) - { -- struct protocol_stack *stack = (struct protocol_stack *)msg->args[MSG_ARG_0].p; -+ struct protocol_stack *stack = get_protocol_stack(); - struct list_node *list = &stack->recv_list; - uint32_t count = 0; - struct list_node *node; -@@ -1086,16 +1083,16 @@ void stack_recvlist_count(struct rpc_msg *msg) - /* when fd is listenfd, listenfd of all protocol stack thread will be closed */ - int32_t stack_broadcast_close(int32_t fd) - { -- struct lwip_sock *sock = get_socket(fd); - int32_t ret = 0; -- -+ struct lwip_sock *sock = get_socket(fd); -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - if (sock == NULL) { -- return -1; -+ GAZELLE_RETURN(EBADF); - } - - do { - sock = sock->listen_next; -- if (rpc_call_close(fd)) { -+ if (stack == NULL || rpc_call_close(&stack->rpc_queue, fd)) { - ret = -1; - } - -@@ -1103,7 +1100,8 @@ int32_t stack_broadcast_close(int32_t fd) - break; - } - fd = sock->conn->callback_arg.socket; -- } while (sock); -+ stack = get_protocol_stack_by_fd(fd); -+ } while (1); - - return ret; - } -@@ -1112,13 +1110,14 @@ int stack_broadcast_shutdown(int fd, int how) - { - int32_t ret = 0; - struct lwip_sock *sock = get_socket(fd); -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - if (sock == NULL) { -- return -1; -+ GAZELLE_RETURN(EBADF); - } - - do { - sock = sock->listen_next; -- if (rpc_call_shutdown(fd, how)) { -+ if (stack == NULL || rpc_call_shutdown(&stack->rpc_queue, fd, how)) { - ret = -1; - } - -@@ -1126,7 +1125,8 @@ int stack_broadcast_shutdown(int fd, int how) - break; - } - fd = sock->conn->callback_arg.socket; -- } while (sock); -+ stack = get_protocol_stack_by_fd(fd); -+ } while (1); - - return ret; - } -@@ -1134,7 +1134,11 @@ int stack_broadcast_shutdown(int fd, int how) - /* choice one stack listen */ - int32_t stack_single_listen(int32_t fd, int32_t backlog) - { -- return rpc_call_listen(fd, backlog); -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_listen(&stack->rpc_queue, fd, backlog); - } - - /* listen sync to all protocol stack thread, so that any protocol stack thread can build connect */ -@@ -1153,12 +1157,12 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) - int32_t ret, clone_fd; - - struct lwip_sock *sock = get_socket(fd); -- if (sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null\n", get_stack_tid(), fd); -- GAZELLE_RETURN(EINVAL); -+ if (sock == NULL || cur_stack == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); -+ GAZELLE_RETURN(EBADF); - } - -- ret = rpc_call_getsockname(fd, (struct sockaddr *)&addr, &addr_len); -+ ret = rpc_call_getsockname(&cur_stack->rpc_queue, fd, (struct sockaddr *)&addr, &addr_len); - if (ret != 0) { - return ret; - } -@@ -1172,7 +1176,7 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) - continue; - } - if (stack != cur_stack) { -- clone_fd = rpc_call_shadow_fd(stack, fd, (struct sockaddr *)&addr, addr_len); -+ clone_fd = rpc_call_shadow_fd(&stack->rpc_queue, fd, (struct sockaddr *)&addr, addr_len); - if (clone_fd < 0) { - stack_broadcast_close(fd); - return clone_fd; -@@ -1187,7 +1191,7 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) - get_socket_by_fd(clone_fd)->conn->is_master_fd = 0; - } - -- ret = rpc_call_listen(clone_fd, backlog); -+ ret = rpc_call_listen(&stack->rpc_queue, clone_fd, backlog); - if (ret < 0) { - stack_broadcast_close(fd); - return ret; -@@ -1234,7 +1238,11 @@ static void inline del_accept_in_event(struct lwip_sock *sock) - /* choice one stack bind */ - int32_t stack_single_bind(int32_t fd, const struct sockaddr *name, socklen_t namelen) - { -- return rpc_call_bind(fd, name, namelen); -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_bind(&stack->rpc_queue, fd, name, namelen); - } - - /* bind sync to all protocol stack thread, so that any protocol stack thread can build connect */ -@@ -1245,12 +1253,12 @@ int32_t stack_broadcast_bind(int32_t fd, const struct sockaddr *name, socklen_t - int32_t ret, clone_fd; - - struct lwip_sock *sock = get_socket(fd); -- if (sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null\n", get_stack_tid(), fd); -- GAZELLE_RETURN(EINVAL); -+ if (sock == NULL || cur_stack == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); -+ GAZELLE_RETURN(EBADF); - } - -- ret = rpc_call_bind(fd, name, namelen); -+ ret = rpc_call_bind(&cur_stack->rpc_queue, fd, name, namelen); - if (ret < 0) { - close(fd); - return ret; -@@ -1260,7 +1268,7 @@ int32_t stack_broadcast_bind(int32_t fd, const struct sockaddr *name, socklen_t - for (int32_t i = 0; i < stack_group->stack_num; ++i) { - stack = stack_group->stacks[i]; - if (stack != cur_stack) { -- clone_fd = rpc_call_shadow_fd(stack, fd, name, namelen); -+ clone_fd = rpc_call_shadow_fd(&stack->rpc_queue, fd, name, namelen); - if (clone_fd < 0) { - stack_broadcast_close(fd); - return clone_fd; -@@ -1276,9 +1284,9 @@ int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *ad - int32_t ret = -1; - struct lwip_sock *min_sock = NULL; - struct lwip_sock *sock = get_socket(fd); -+ struct protocol_stack *stack = NULL; - if (sock == NULL) { -- errno = EINVAL; -- return -1; -+ GAZELLE_RETURN(EBADF); - } - - if (netconn_is_nonblocking(sock->conn)) { -@@ -1290,7 +1298,11 @@ int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *ad - } - - if (min_sock && min_sock->conn) { -- ret = rpc_call_accept(min_sock->conn->callback_arg.socket, addr, addrlen, flags); -+ stack = get_protocol_stack_by_fd(min_sock->conn->callback_arg.socket); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ ret = rpc_call_accept(&stack->rpc_queue, min_sock->conn->callback_arg.socket, addr, addrlen, flags); - } - - if (min_sock && min_sock->wakeup && min_sock->wakeup->type == WAKEUP_EPOLL) { -@@ -1344,7 +1356,7 @@ void stack_group_exit(void) - } - - if (stack != stack_group->stacks[i]) { -- rpc_call_stack_exit(stack_group->stacks[i]); -+ rpc_call_stack_exit(&stack_group->stacks[i]->rpc_queue); - } - } - -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 23571b4..01ac6fb 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -175,20 +175,17 @@ static void get_stack_stats(struct gazelle_stack_dfx_data *dfx, struct protocol_ - - get_wakeup_stat(stack_group, stack, &dfx->data.pkts.wakeup_stat); - -- dfx->data.pkts.call_alloc_fail = stack_group->call_alloc_fail; -+ dfx->data.pkts.call_alloc_fail = rpc_stats_get()->call_alloc_fail; - -- int32_t rpc_call_result = rpc_call_msgcnt(stack); -+ int32_t rpc_call_result = rpc_msgcnt(&stack->rpc_queue); - dfx->data.pkts.call_msg_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; - -- rpc_call_result = rpc_call_mbufpoolsize(stack); -+ rpc_call_result = rpc_call_mbufpoolsize(&stack->dfx_rpc_queue); - dfx->data.pkts.mbufpool_avail_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; - -- rpc_call_result = rpc_call_recvlistcnt(stack); -+ rpc_call_result = rpc_call_recvlistcnt(&stack->dfx_rpc_queue); - dfx->data.pkts.recv_list_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; - -- rpc_call_result = rpc_call_rpcpool_size(stack); -- dfx->data.pkts.rpcpool_avail_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; -- - dfx->data.pkts.conn_num = stack->conn_num; - } - -@@ -219,9 +216,10 @@ static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protoc - } - break; - case GAZELLE_STAT_LSTACK_SHOW_CONN: -- rpc_call_result = rpc_call_conntable(stack, dfx->data.conn.conn_list, GAZELLE_LSTACK_MAX_CONN); -+ rpc_call_result = rpc_call_conntable(&stack->dfx_rpc_queue, dfx->data.conn.conn_list, -+ GAZELLE_LSTACK_MAX_CONN); - dfx->data.conn.conn_num = (rpc_call_result < 0) ? 0 : rpc_call_result; -- rpc_call_result = rpc_call_connnum(stack); -+ rpc_call_result = rpc_call_connnum(&stack->dfx_rpc_queue); - dfx->data.conn.total_conn_num = (rpc_call_result < 0) ? 0 : rpc_call_result; - break; - case GAZELLE_STAT_LSTACK_SHOW_LATENCY: -@@ -296,7 +294,7 @@ int handle_stack_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode) - } - - dfx.tid = stack->tid; -- dfx.stack_id = i; -+ dfx.stack_id = i; - if (i == stack_group->stack_num - 1) { - dfx.eof = 1; - } -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 2af30d7..1fdb037 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -9,21 +9,20 @@ - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ --#include --#include - #include --#include - #include - - #include "lstack_log.h" --#include "lstack_lwip.h" --#include "lstack_protocol_stack.h" --#include "lstack_control_plane.h" --#include "gazelle_base_func.h" - #include "lstack_dpdk.h" -+#include "lstack_rpc_proc.h" - #include "lstack_thread_rpc.h" - - static PER_THREAD struct rpc_msg_pool *g_rpc_pool = NULL; -+static struct rpc_stats g_rpc_stats; -+struct rpc_stats *rpc_stats_get(void) -+{ -+ return &g_rpc_stats; -+} - - static inline __attribute__((always_inline)) struct rpc_msg *get_rpc_msg(struct rpc_msg_pool *rpc_pool) - { -@@ -37,33 +36,29 @@ static inline __attribute__((always_inline)) struct rpc_msg *get_rpc_msg(struct - return msg; - } - --static struct rpc_msg *rpc_msg_alloc(struct protocol_stack *stack, rpc_msg_func func) -+static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func) - { - struct rpc_msg *msg = NULL; - -- if (stack == NULL) { -- return NULL; -- } -- - if (g_rpc_pool == NULL) { - g_rpc_pool = calloc(1, sizeof(struct rpc_msg_pool)); - if (g_rpc_pool == NULL) { - LSTACK_LOG(INFO, LSTACK, "g_rpc_pool calloc failed\n"); -- get_protocol_stack_group()->call_alloc_fail++; -+ g_rpc_stats.call_alloc_fail++; - return NULL; - } - - g_rpc_pool->mempool = create_mempool("rpc_pool", RPC_MSG_MAX, sizeof(struct rpc_msg), - 0, rte_gettid()); - if (g_rpc_pool->mempool == NULL) { -- get_protocol_stack_group()->call_alloc_fail++; -+ g_rpc_stats.call_alloc_fail++; - return NULL; - } - } - - msg = get_rpc_msg(g_rpc_pool); - if (msg == NULL) { -- get_protocol_stack_group()->call_alloc_fail++; -+ g_rpc_stats.call_alloc_fail++; - return NULL; - } - msg->rpcpool = g_rpc_pool; -@@ -75,7 +70,7 @@ static struct rpc_msg *rpc_msg_alloc(struct protocol_stack *stack, rpc_msg_func - return msg; - } - --static inline __attribute__((always_inline)) int32_t rpc_sync_call(lockless_queue *queue, struct rpc_msg *msg) -+static inline __attribute__((always_inline)) int32_t rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg) - { - int32_t ret; - -@@ -90,13 +85,18 @@ static inline __attribute__((always_inline)) int32_t rpc_sync_call(lockless_queu - return ret; - } - --int poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) -+int32_t rpc_msgcnt(rpc_queue *queue) -+{ -+ return lockless_queue_count(queue); -+} -+ -+int rpc_poll_msg(rpc_queue *queue, uint32_t max_num) - { - int force_quit = 0; - struct rpc_msg *msg = NULL; - - while (max_num--) { -- lockless_queue_node *node = lockless_queue_mpsc_pop(&stack->rpc_queue); -+ lockless_queue_node *node = lockless_queue_mpsc_pop(queue); - if (node == NULL) { - break; - } -@@ -106,7 +106,7 @@ int poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) - if (msg->func) { - msg->func(msg); - } else { -- stack->stats.call_null++; -+ g_rpc_stats.call_null++; - } - - if (msg->func == stack_exit_by_rpc) { -@@ -127,9 +127,9 @@ int poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num) - return force_quit; - } - --int32_t rpc_call_conntable(struct protocol_stack *stack, void *conn_table, uint32_t max_conn) -+int32_t rpc_call_conntable(rpc_queue *queue, void *conn_table, uint32_t max_conn) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_get_conntable); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_get_conntable); - if (msg == NULL) { - return -1; - } -@@ -137,22 +137,22 @@ int32_t rpc_call_conntable(struct protocol_stack *stack, void *conn_table, uint3 - msg->args[MSG_ARG_0].p = conn_table; - msg->args[MSG_ARG_1].u = max_conn; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_connnum(struct protocol_stack *stack) -+int32_t rpc_call_connnum(rpc_queue *queue) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_get_connnum); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_get_connnum); - if (msg == NULL) { - return -1; - } - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_shadow_fd(struct protocol_stack *stack, int32_t fd, const struct sockaddr *addr, socklen_t addrlen) -+int32_t rpc_call_shadow_fd(rpc_queue *queue, int32_t fd, const struct sockaddr *addr, socklen_t addrlen) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_create_shadow_fd); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_create_shadow_fd); - if (msg == NULL) { - return -1; - } -@@ -161,100 +161,67 @@ int32_t rpc_call_shadow_fd(struct protocol_stack *stack, int32_t fd, const struc - msg->args[MSG_ARG_1].cp = addr; - msg->args[MSG_ARG_2].socklen = addrlen; - -- return rpc_sync_call(&stack->rpc_queue, msg); --} -- --static void rpc_msgcnt(struct rpc_msg *msg) --{ -- struct protocol_stack *stack = get_protocol_stack(); -- msg->result = lockless_queue_count(&stack->rpc_queue); --} -- --int32_t rpc_call_msgcnt(struct protocol_stack *stack) --{ -- struct rpc_msg *msg = rpc_msg_alloc(stack, rpc_msgcnt); -- if (msg == NULL) { -- return -1; -- } -- -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_thread_regphase1(struct protocol_stack *stack, void *conn) -+int32_t rpc_call_thread_regphase1(rpc_queue *queue, void *conn) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, thread_register_phase1); -+ struct rpc_msg *msg = rpc_msg_alloc(thread_register_phase1); - if (msg == NULL) { - return -1; - } - msg->args[MSG_ARG_0].p = conn; -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_thread_regphase2(struct protocol_stack *stack, void *conn) -+int32_t rpc_call_thread_regphase2(rpc_queue *queue, void *conn) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, thread_register_phase2); -+ struct rpc_msg *msg = rpc_msg_alloc(thread_register_phase2); - if (msg == NULL) { - return -1; - } - msg->args[MSG_ARG_0].p = conn; -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_mbufpoolsize(struct protocol_stack *stack) -+int32_t rpc_call_mbufpoolsize(rpc_queue *queue) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_mempool_size); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_mempool_size); - if (msg == NULL) { - return -1; - } - -- msg->args[MSG_ARG_0].p = stack; -- -- return rpc_sync_call(&stack->rpc_queue, msg); --} -- --int32_t rpc_call_rpcpool_size(struct protocol_stack *stack) --{ -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_rpcpool_size); -- if (msg == NULL) { -- return -1; -- } -- msg->args[MSG_ARG_0].p = g_rpc_pool; -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_recvlistcnt(struct protocol_stack *stack) -+int32_t rpc_call_recvlistcnt(rpc_queue *queue) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_recvlist_count); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_recvlist_count); - if (msg == NULL) { - return -1; - } - -- msg->args[MSG_ARG_0].p = stack; -- -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_arp(struct protocol_stack *stack, struct rte_mbuf *mbuf) -+int32_t rpc_call_arp(rpc_queue *queue, void *mbuf) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_arp); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_arp); - if (msg == NULL) { - return -1; - } - - msg->sync_flag = 0; - msg->args[MSG_ARG_0].p = mbuf; -- msg->args[MSG_ARG_1].p = stack; - -- rpc_call(&stack->rpc_queue, msg); -+ rpc_call(queue, msg); - - return 0; - } - --int32_t rpc_call_socket(int32_t domain, int32_t type, int32_t protocol) -+int32_t rpc_call_socket(rpc_queue *queue, int32_t domain, int32_t type, int32_t protocol) - { -- struct protocol_stack *stack = get_bind_protocol_stack(); -- -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_socket); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_socket); - if (msg == NULL) { - return -1; - } -@@ -263,39 +230,35 @@ int32_t rpc_call_socket(int32_t domain, int32_t type, int32_t protocol) - msg->args[MSG_ARG_1].i = type; - msg->args[MSG_ARG_2].i = protocol; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_close(int fd) -+int32_t rpc_call_close(rpc_queue *queue, int fd) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_close); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_close); - if (msg == NULL) { - return -1; - } - - msg->args[MSG_ARG_0].i = fd; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_stack_exit(struct protocol_stack *stack) -+int32_t rpc_call_stack_exit(rpc_queue *queue) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_exit_by_rpc); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_exit_by_rpc); - if (msg == NULL) { -- LSTACK_LOG(INFO, LSTACK, "rpc msg alloc failed\n"); - return -1; - } - -- rpc_call(&stack->rpc_queue, msg); -+ rpc_call(queue, msg); - return 0; - } - --int32_t rpc_call_shutdown(int fd, int how) -+int32_t rpc_call_shutdown(rpc_queue *queue, int fd, int how) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_shutdown); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_shutdown); - if (msg == NULL) { - return -1; - } -@@ -303,25 +266,24 @@ int32_t rpc_call_shutdown(int fd, int how) - msg->args[MSG_ARG_0].i = fd; - msg->args[MSG_ARG_1].i = how; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --void rpc_call_clean_epoll(struct protocol_stack *stack, struct wakeup_poll *wakeup) -+void rpc_call_clean_epoll(rpc_queue *queue, void *wakeup) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_clean_epoll); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_clean_epoll); - if (msg == NULL) { - return; - } - - msg->args[MSG_ARG_0].p = wakeup; - -- rpc_sync_call(&stack->rpc_queue, msg); -+ rpc_sync_call(queue, msg); - } - --int32_t rpc_call_bind(int32_t fd, const struct sockaddr *addr, socklen_t addrlen) -+int32_t rpc_call_bind(rpc_queue *queue, int32_t fd, const struct sockaddr *addr, socklen_t addrlen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_bind); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_bind); - if (msg == NULL) { - return -1; - } -@@ -330,13 +292,12 @@ int32_t rpc_call_bind(int32_t fd, const struct sockaddr *addr, socklen_t addrlen - msg->args[MSG_ARG_1].cp = addr; - msg->args[MSG_ARG_2].socklen = addrlen; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_listen(int s, int backlog) -+int32_t rpc_call_listen(rpc_queue *queue, int s, int backlog) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(s); -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_listen); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_listen); - if (msg == NULL) { - return -1; - } -@@ -344,13 +305,12 @@ int32_t rpc_call_listen(int s, int backlog) - msg->args[MSG_ARG_0].i = s; - msg->args[MSG_ARG_1].i = backlog; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_accept(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags) -+int32_t rpc_call_accept(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen, int flags) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_accept); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_accept); - if (msg == NULL) { - return -1; - } -@@ -360,13 +320,12 @@ int32_t rpc_call_accept(int fd, struct sockaddr *addr, socklen_t *addrlen, int f - msg->args[MSG_ARG_2].p = addrlen; - msg->args[MSG_ARG_3].i = flags; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_connect(int fd, const struct sockaddr *addr, socklen_t addrlen) -+int32_t rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_connect); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_connect); - if (msg == NULL) { - return -1; - } -@@ -375,7 +334,7 @@ int32_t rpc_call_connect(int fd, const struct sockaddr *addr, socklen_t addrlen) - msg->args[MSG_ARG_1].cp = addr; - msg->args[MSG_ARG_2].socklen = addrlen; - -- int32_t ret = rpc_sync_call(&stack->rpc_queue, msg); -+ int32_t ret = rpc_sync_call(queue, msg); - if (ret < 0) { - errno = -ret; - return -1; -@@ -383,10 +342,9 @@ int32_t rpc_call_connect(int fd, const struct sockaddr *addr, socklen_t addrlen) - return ret; - } - --int32_t rpc_call_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen) -+int32_t rpc_call_getpeername(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_getpeername); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_getpeername); - if (msg == NULL) { - return -1; - } -@@ -395,13 +353,12 @@ int32_t rpc_call_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen) - msg->args[MSG_ARG_1].p = addr; - msg->args[MSG_ARG_2].p = addrlen; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen) -+int32_t rpc_call_getsockname(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_getsockname); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_getsockname); - if (msg == NULL) { - return -1; - } -@@ -410,13 +367,12 @@ int32_t rpc_call_getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen) - msg->args[MSG_ARG_1].p = addr; - msg->args[MSG_ARG_2].p = addrlen; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen) -+int32_t rpc_call_getsockopt(rpc_queue *queue, int fd, int level, int optname, void *optval, socklen_t *optlen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_getsockopt); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_getsockopt); - if (msg == NULL) { - return -1; - } -@@ -427,13 +383,12 @@ int32_t rpc_call_getsockopt(int fd, int level, int optname, void *optval, sockle - msg->args[MSG_ARG_3].p = optval; - msg->args[MSG_ARG_4].p = optlen; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen) -+int32_t rpc_call_setsockopt(rpc_queue *queue, int fd, int level, int optname, const void *optval, socklen_t optlen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_setsockopt); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_setsockopt); - if (msg == NULL) { - return -1; - } -@@ -444,13 +399,12 @@ int32_t rpc_call_setsockopt(int fd, int level, int optname, const void *optval, - msg->args[MSG_ARG_3].cp = optval; - msg->args[MSG_ARG_4].socklen = optlen; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_fcntl(int fd, int cmd, long val) -+int32_t rpc_call_fcntl(rpc_queue *queue, int fd, int cmd, long val) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_fcntl); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_fcntl); - if (msg == NULL) { - return -1; - } -@@ -459,13 +413,12 @@ int32_t rpc_call_fcntl(int fd, int cmd, long val) - msg->args[MSG_ARG_1].i = cmd; - msg->args[MSG_ARG_2].l = val; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_ioctl(int fd, long cmd, void *argp) -+int32_t rpc_call_ioctl(rpc_queue *queue, int fd, long cmd, void *argp) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_ioctl); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_ioctl); - if (msg == NULL) { - return -1; - } -@@ -474,27 +427,24 @@ int32_t rpc_call_ioctl(int fd, long cmd, void *argp) - msg->args[MSG_ARG_1].l = cmd; - msg->args[MSG_ARG_2].p = argp; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_replenish(struct protocol_stack *stack, struct lwip_sock *sock) -+int32_t rpc_call_replenish(rpc_queue *queue, void *sock) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_replenish_sendring); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_replenish_sendring); - if (msg == NULL) { - return -1; - } - -- msg->args[MSG_ARG_0].p = stack; -- msg->args[MSG_ARG_1].p = sock; -+ msg->args[MSG_ARG_0].p = sock; - -- return rpc_sync_call(&stack->rpc_queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_send(int fd, const void *buf, size_t len, int flags) -+int32_t rpc_call_send(rpc_queue *queue, int fd, const void *buf, size_t len, int flags) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- -- struct rpc_msg *msg = rpc_msg_alloc(stack, stack_send); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_send); - if (msg == NULL) { - return -1; - } -@@ -502,10 +452,9 @@ int32_t rpc_call_send(int fd, const void *buf, size_t len, int flags) - msg->args[MSG_ARG_0].i = fd; - msg->args[MSG_ARG_1].size = len; - msg->args[MSG_ARG_2].i = flags; -- msg->args[MSG_ARG_3].p = stack; - msg->sync_flag = 0; - -- rpc_call(&stack->rpc_queue, msg); -+ rpc_call(queue, msg); - - return 0; - } -diff --git a/src/lstack/include/lstack_control_plane.h b/src/lstack/include/lstack_control_plane.h -index aed5443..548d725 100644 ---- a/src/lstack/include/lstack_control_plane.h -+++ b/src/lstack/include/lstack_control_plane.h -@@ -23,14 +23,11 @@ enum vdev_request { - VDEV_NONE, - }; - --struct rpc_msg; - int client_reg_thrd_ring(void); - int32_t control_init_client(bool is_reconnect); - void control_client_thread(void *arg); - void control_server_thread(void *arg); - bool get_register_state(void); --void thread_register_phase1(struct rpc_msg *msg); --void thread_register_phase2(struct rpc_msg *msg); - void control_fd_close(void); - void delete_primary_path(void); - -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index c681547..7489f2a 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -21,7 +21,7 @@ - #include - - #include "gazelle_dfx_msg.h" --#include "lstack_lockless_queue.h" -+#include "lstack_thread_rpc.h" - #include "lstack_ethdev.h" - #include "gazelle_opt.h" - -@@ -59,13 +59,15 @@ struct protocol_stack { - volatile bool low_power; - bool is_send_thread; - -- lockless_queue rpc_queue __rte_cache_aligned; -- char pad __rte_cache_aligned; -+ char pad1 __rte_cache_aligned; -+ rpc_queue dfx_rpc_queue; -+ rpc_queue rpc_queue; -+ char pad2 __rte_cache_aligned; - - /* kernel event thread read/write frequently */ - struct epoll_event kernel_events[KERNEL_EPOLL_MAX]; - int32_t kernel_event_num; -- char pad1 __rte_cache_aligned; -+ char pad3 __rte_cache_aligned; - - struct netif netif; - struct lstack_dev_ops dev_ops; -@@ -149,36 +151,10 @@ void stack_broadcast_clean_epoll(struct wakeup_poll *wakeup); - - void stack_send_pkts(struct protocol_stack *stack); - --struct rpc_msg; - struct thread_params { - uint16_t queue_id; - uint16_t idx; - }; --void stack_clean_epoll(struct rpc_msg *msg); --void stack_arp(struct rpc_msg *msg); --void stack_socket(struct rpc_msg *msg); --void stack_close(struct rpc_msg *msg); --void stack_shutdown(struct rpc_msg *msg); --void stack_bind(struct rpc_msg *msg); --void stack_listen(struct rpc_msg *msg); --void stack_accept(struct rpc_msg *msg); --void stack_connect(struct rpc_msg *msg); --void stack_recv(struct rpc_msg *msg); --void stack_getpeername(struct rpc_msg *msg); --void stack_getsockname(struct rpc_msg *msg); --void stack_getsockopt(struct rpc_msg *msg); --void stack_setsockopt(struct rpc_msg *msg); --void stack_fcntl(struct rpc_msg *msg); --void stack_ioctl(struct rpc_msg *msg); --void stack_send(struct rpc_msg *msg); --void stack_mempool_size(struct rpc_msg *msg); --void stack_rpcpool_size(struct rpc_msg *msg); --void stack_create_shadow_fd(struct rpc_msg *msg); --void stack_replenish_sendring(struct rpc_msg *msg); --void stack_get_conntable(struct rpc_msg *msg); --void stack_get_connnum(struct rpc_msg *msg); --void stack_recvlist_count(struct rpc_msg *msg); --void stack_exit_by_rpc(struct rpc_msg *msg); - - int stack_polling(uint32_t wakeup_tick); - #endif -diff --git a/src/lstack/include/lstack_rpc_proc.h b/src/lstack/include/lstack_rpc_proc.h -new file mode 100644 -index 0000000..71f0c58 ---- /dev/null -+++ b/src/lstack/include/lstack_rpc_proc.h -@@ -0,0 +1,46 @@ -+/* -+* 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_RPC_PROC_H__ -+#define __GAZELLE_RPC_PROC_H__ -+#include "lstack_thread_rpc.h" -+ -+void stack_clean_epoll(struct rpc_msg *msg); -+void stack_arp(struct rpc_msg *msg); -+void stack_socket(struct rpc_msg *msg); -+void stack_close(struct rpc_msg *msg); -+void stack_shutdown(struct rpc_msg *msg); -+void stack_bind(struct rpc_msg *msg); -+void stack_listen(struct rpc_msg *msg); -+void stack_accept(struct rpc_msg *msg); -+void stack_connect(struct rpc_msg *msg); -+void stack_recv(struct rpc_msg *msg); -+void stack_getpeername(struct rpc_msg *msg); -+void stack_getsockname(struct rpc_msg *msg); -+void stack_getsockopt(struct rpc_msg *msg); -+void stack_setsockopt(struct rpc_msg *msg); -+void stack_fcntl(struct rpc_msg *msg); -+void stack_ioctl(struct rpc_msg *msg); -+void stack_send(struct rpc_msg *msg); -+void stack_mempool_size(struct rpc_msg *msg); -+void stack_rpcpool_size(struct rpc_msg *msg); -+void stack_create_shadow_fd(struct rpc_msg *msg); -+void stack_replenish_sendring(struct rpc_msg *msg); -+void stack_get_conntable(struct rpc_msg *msg); -+void stack_get_connnum(struct rpc_msg *msg); -+void stack_recvlist_count(struct rpc_msg *msg); -+void stack_exit_by_rpc(struct rpc_msg *msg); -+ -+void thread_register_phase1(struct rpc_msg *msg); -+void thread_register_phase2(struct rpc_msg *msg); -+ -+#endif -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 633ef93..30caa66 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -28,6 +28,12 @@ - - #define RPC_MSG_MAX 4096 - #define RPC_MSG_MASK (RPC_MSG_MAX - 1) -+typedef struct lockless_queue rpc_queue; -+ -+struct rpc_stats { -+ uint16_t call_null; -+ uint64_t call_alloc_fail; -+}; - - struct rpc_msg; - typedef void (*rpc_msg_func)(struct rpc_msg *msg); -@@ -41,7 +47,9 @@ union rpc_msg_arg { - socklen_t socklen; - size_t size; - }; --struct rpc_msg_pool; -+struct rpc_msg_pool { -+ struct rte_mempool *mempool; -+}; - struct rpc_msg { - pthread_spinlock_t lock; /* msg handler unlock notice sender msg process done */ - int8_t sync_flag : 1; -@@ -54,44 +62,41 @@ struct rpc_msg { - union rpc_msg_arg args[RPM_MSG_ARG_SIZE]; /* resolve by type */ - }; - --struct rpc_msg_pool { -- struct rte_mempool *mempool; --}; -+static inline void rpc_queue_init(rpc_queue *queue) -+{ -+ lockless_queue_init(queue); -+} - --struct protocol_stack; --struct rte_mbuf; --struct wakeup_poll; --struct lwip_sock; --int poll_rpc_msg(struct protocol_stack *stack, uint32_t max_num); --void rpc_call_clean_epoll(struct protocol_stack *stack, struct wakeup_poll *wakeup); --int32_t rpc_call_msgcnt(struct protocol_stack *stack); --int32_t rpc_call_shadow_fd(struct protocol_stack *stack, int32_t fd, const struct sockaddr *addr, socklen_t addrlen); --int32_t rpc_call_recvlistcnt(struct protocol_stack *stack); --int32_t rpc_call_thread_regphase1(struct protocol_stack *stack, void *conn); --int32_t rpc_call_thread_regphase2(struct protocol_stack *stack, void *conn); --int32_t rpc_call_conntable(struct protocol_stack *stack, void *conn_table, uint32_t max_conn); --int32_t rpc_call_connnum(struct protocol_stack *stack); --int32_t rpc_call_arp(struct protocol_stack *stack, struct rte_mbuf *mbuf); --int32_t rpc_call_socket(int32_t domain, int32_t type, int32_t protocol); --int32_t rpc_call_close(int32_t fd); --int32_t rpc_call_shutdown(int fd, int how); --int32_t rpc_call_bind(int32_t fd, const struct sockaddr *addr, socklen_t addrlen); --int32_t rpc_call_listen(int s, int backlog); --int32_t rpc_call_accept(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags); --int32_t rpc_call_connect(int fd, const struct sockaddr *addr, socklen_t addrlen); --int32_t rpc_call_send(int fd, const void *buf, size_t len, int flags); --int32_t rpc_call_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen); --int32_t rpc_call_getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen); --int32_t rpc_call_getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen); --int32_t rpc_call_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen); --int32_t rpc_call_fcntl(int fd, int cmd, long val); --int32_t rpc_call_ioctl(int fd, long cmd, void *argp); --int32_t rpc_call_replenish(struct protocol_stack *stack, struct lwip_sock *sock); --int32_t rpc_call_mbufpoolsize(struct protocol_stack *stack); --int32_t rpc_call_rpcpool_size(struct protocol_stack *stack); --int32_t rpc_call_stack_exit(struct protocol_stack *stack); -+struct rpc_stats *rpc_stats_get(void); -+int32_t rpc_msgcnt(rpc_queue *queue); -+int rpc_poll_msg(rpc_queue *queue, uint32_t max_num); -+void rpc_call_clean_epoll(rpc_queue *queue, void *wakeup); -+int32_t rpc_call_shadow_fd(rpc_queue *queue, int32_t fd, const struct sockaddr *addr, socklen_t addrlen); -+int32_t rpc_call_recvlistcnt(rpc_queue *queue); -+int32_t rpc_call_thread_regphase1(rpc_queue *queue, void *conn); -+int32_t rpc_call_thread_regphase2(rpc_queue *queue, void *conn); -+int32_t rpc_call_conntable(rpc_queue *queue, void *conn_table, uint32_t max_conn); -+int32_t rpc_call_connnum(rpc_queue *queue); -+int32_t rpc_call_arp(rpc_queue *queue, void *mbuf); -+int32_t rpc_call_socket(rpc_queue *queue, int32_t domain, int32_t type, int32_t protocol); -+int32_t rpc_call_close(rpc_queue *queue, int32_t fd); -+int32_t rpc_call_shutdown(rpc_queue *queue, int fd, int how); -+int32_t rpc_call_bind(rpc_queue *queue, int32_t fd, const struct sockaddr *addr, socklen_t addrlen); -+int32_t rpc_call_listen(rpc_queue *queue, int s, int backlog); -+int32_t rpc_call_accept(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen, int flags); -+int32_t rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen); -+int32_t rpc_call_send(rpc_queue *queue, int fd, const void *buf, size_t len, int flags); -+int32_t rpc_call_getpeername(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen); -+int32_t rpc_call_getsockname(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen); -+int32_t rpc_call_getsockopt(rpc_queue *queue, int fd, int level, int optname, void *optval, socklen_t *optlen); -+int32_t rpc_call_setsockopt(rpc_queue *queue, int fd, int level, int optname, const void *optval, socklen_t optlen); -+int32_t rpc_call_fcntl(rpc_queue *queue, int fd, int cmd, long val); -+int32_t rpc_call_ioctl(rpc_queue *queue, int fd, long cmd, void *argp); -+int32_t rpc_call_replenish(rpc_queue *queue, void *sock); -+int32_t rpc_call_mbufpoolsize(rpc_queue *queue); -+int32_t rpc_call_stack_exit(rpc_queue *queue); - --static inline __attribute__((always_inline)) void rpc_call(lockless_queue *queue, struct rpc_msg *msg) -+static inline __attribute__((always_inline)) void rpc_call(rpc_queue *queue, struct rpc_msg *msg) - { - lockless_queue_mpsc_push(queue, &msg->queue_node); - } -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 4d6f620..965de58 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -529,7 +529,7 @@ void transfer_tcp_to_thread(struct rte_mbuf *mbuf, uint16_t stk_idx) - struct protocol_stack *stack = get_protocol_stack_group()->stacks[stk_idx]; - int ret = -1; - while(ret != 0) { -- ret = rpc_call_arp(stack, mbuf); -+ ret = rpc_call_arp(&stack->rpc_queue, mbuf); - printf("transfer_tcp_to_thread, ret : %d \n", ret); - } - } -@@ -550,10 +550,10 @@ void parse_arp_and_transefer(char* buf) - } - copy_mbuf(mbuf_copy, mbuf); - -- ret = rpc_call_arp(stack, mbuf_copy); -+ ret = rpc_call_arp(&stack->rpc_queue, mbuf_copy); - - while (ret != 0) { -- rpc_call_arp(stack, mbuf_copy);; -+ rpc_call_arp(&stack->rpc_queue, mbuf_copy); - } - } - } -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 9f12096..bea0dc7 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -646,8 +646,7 @@ static void show_lstack_stats(struct gazelle_stack_dfx_data *lstack_stat) - printf("call_alloc_fail: %-12"PRIu64" ", lstack_stat->data.pkts.call_alloc_fail); - printf("call_null: %-18"PRIu64" \n", lstack_stat->data.pkts.stack_stat.call_null); - printf("send_pkts_fail: %-13"PRIu64" ", lstack_stat->data.pkts.stack_stat.send_pkts_fail); -- printf("mbuf_pool_freecnt: %-10"PRIu32" ", lstack_stat->data.pkts.mbufpool_avail_cnt); -- printf("rpc_pool_freecnt: %-12"PRIu32" \n", lstack_stat->data.pkts.rpcpool_avail_cnt); -+ printf("mbuf_pool_freecnt: %-10"PRIu32" \n", lstack_stat->data.pkts.mbufpool_avail_cnt); - printf("accpet_fail: %-16"PRIu64" ", lstack_stat->data.pkts.stack_stat.accept_fail); - printf("sock_rx_drop: %-15"PRIu64" ", lstack_stat->data.pkts.stack_stat.sock_rx_drop); - printf("sock_tx_merge: %-16"PRIu64" \n", lstack_stat->data.pkts.stack_stat.sock_tx_merge); --- -2.27.0 - diff --git a/0136-readv-return-1-errno-is-EAGAIN-when-recvring-no-data.patch b/0136-readv-return-1-errno-is-EAGAIN-when-recvring-no-data.patch deleted file mode 100644 index 0d311c836ad6ec668d5335c65ea1075e379580db..0000000000000000000000000000000000000000 --- a/0136-readv-return-1-errno-is-EAGAIN-when-recvring-no-data.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 61888e1e0d4810d3f0dbe5aa1d43a2dbcf2ad0f5 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 21 Feb 2024 07:44:59 +0800 -Subject: [PATCH] readv return -1, errno is EAGAIN when recvring no data - ---- - src/lstack/api/lstack_rtw_api.c | 7 +------ - 1 file changed, 1 insertion(+), 6 deletions(-) - -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index 8498b8e..e50fe37 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -127,12 +127,7 @@ ssize_t rtw_readv(int s, const struct iovec *iov, int iovcnt) - msg.msg_control = NULL; - msg.msg_controllen = 0; - msg.msg_flags = 0; -- ssize_t result = do_lwip_recvmsg_from_stack(s, &msg, 0); -- if (result == -1 && errno == EAGAIN) { -- errno = 0; -- return 0; -- } -- return result; -+ return do_lwip_recvmsg_from_stack(s, &msg, 0); - } - - ssize_t rtw_write(int s, const void *mem, size_t size) --- -2.27.0 - diff --git a/0137-split-the-flow-fules-related-functions-into-separate.patch b/0137-split-the-flow-fules-related-functions-into-separate.patch deleted file mode 100644 index 1bf499d096f9cac2f3078eae0b31fe991104f4d9..0000000000000000000000000000000000000000 --- a/0137-split-the-flow-fules-related-functions-into-separate.patch +++ /dev/null @@ -1,1707 +0,0 @@ -From 409b6155a1ec9324bd68aae97a07e33560c19028 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 21 Feb 2024 08:05:03 +0800 -Subject: [PATCH] split the flow fules related functions into separate file - ---- - src/lstack/core/lstack_init.c | 1 + - src/lstack/core/lstack_protocol_stack.c | 25 +- - src/lstack/include/lstack_ethdev.h | 27 - - src/lstack/include/lstack_flow.h | 51 ++ - src/lstack/include/lstack_vdev.h | 9 - - src/lstack/netif/dir.mk | 2 +- - src/lstack/netif/lstack_ethdev.c | 687 +----------------------- - src/lstack/netif/lstack_flow.c | 680 +++++++++++++++++++++++ - src/lstack/netif/lstack_vdev.c | 1 + - 9 files changed, 747 insertions(+), 736 deletions(-) - create mode 100644 src/lstack/include/lstack_flow.h - create mode 100644 src/lstack/netif/lstack_flow.c - -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 31fd91d..d22a295 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -48,6 +48,7 @@ - #include "lstack_protocol_stack.h" - #include "lstack_preload.h" - #include "lstack_wrap.h" -+#include "lstack_flow.h" - - static void check_process_start(void) - { -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 18e5df7..a545b73 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -454,14 +454,12 @@ int stack_polling(uint32_t wakeup_tick) - { - int force_quit; - struct cfg_params *cfg = get_global_cfg_params(); -- uint8_t use_ltran_flag = cfg->use_ltran; - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - bool kni_switch = cfg->kni_switch; - #endif - bool use_sockmap = cfg->use_sockmap; - bool stack_mode_rtc = cfg->stack_mode_rtc; - uint32_t rpc_number = cfg->rpc_number; -- uint32_t nic_read_number = cfg->nic_read_number; - uint32_t read_connect_number = cfg->read_connect_number; - struct protocol_stack *stack = get_protocol_stack(); - -@@ -469,7 +467,7 @@ int stack_polling(uint32_t wakeup_tick) - rpc_poll_msg(&stack->dfx_rpc_queue, 2); - force_quit = rpc_poll_msg(&stack->rpc_queue, rpc_number); - -- gazelle_eth_dev_poll(stack, use_ltran_flag, nic_read_number); -+ eth_dev_poll(); - sys_timer_run(); - if (cfg->low_power_mod != 0) { - low_power_idling(stack); -@@ -525,10 +523,6 @@ static void* gazelle_stack_thread(void *arg) - } - sem_post(&g_stack_group.sem_stack_setup); - -- if (!use_ltran() && queue_id == 0) { -- init_listen_and_user_ports(); -- } -- - LSTACK_LOG(INFO, LSTACK, "stack_%02hu init success\n", queue_id); - if (get_global_cfg_params()->stack_mode_rtc) { - return NULL; -@@ -545,12 +539,6 @@ static void* gazelle_stack_thread(void *arg) - return NULL; - } - --static void gazelle_listen_thread(void *arg) --{ -- struct cfg_params *cfg_param = get_global_cfg_params(); -- recv_pkts_from_other_process(cfg_param->process_idx, arg); --} -- - int32_t stack_group_init_mempool(void) - { - struct cfg_params *global_cfg_parmas = get_global_cfg_params(); -@@ -611,17 +599,6 @@ int32_t stack_group_init(void) - } - } - -- /* run to completion mode does not currently support multiple process */ -- if (!use_ltran() && !get_global_cfg_params()->stack_mode_rtc) { -- char name[PATH_MAX]; -- sem_init(&stack_group->sem_listen_thread, 0, 0); -- sprintf_s(name, sizeof(name), "%s", "listen_thread"); -- struct sys_thread *thread = sys_thread_new(name, gazelle_listen_thread, -- (void*)(&stack_group->sem_listen_thread), 0, 0); -- free(thread); -- sem_wait(&stack_group->sem_listen_thread); -- } -- - return 0; - } - -diff --git a/src/lstack/include/lstack_ethdev.h b/src/lstack/include/lstack_ethdev.h -index 3252906..0c3d906 100644 ---- a/src/lstack/include/lstack_ethdev.h -+++ b/src/lstack/include/lstack_ethdev.h -@@ -16,25 +16,6 @@ - #include - #include - --#define INVAILD_PROCESS_IDX 255 -- --enum port_type { -- PORT_LISTEN, -- PORT_CONNECT, --}; -- --enum PACKET_TRANSFER_TYPE { -- TRANSFER_KERNEL = -1, -- TRANSFER_OTHER_THREAD, -- TRANSFER_CURRENT_THREAD, --}; -- --enum TRANSFER_MESSAGE_RESULT { -- CONNECT_ERROR = -2, -- REPLY_ERROR = -1, -- TRANSFER_SUCESS = 0, --}; -- - struct protocol_stack; - struct rte_mbuf; - struct lstack_dev_ops { -@@ -44,21 +25,13 @@ struct lstack_dev_ops { - - int32_t ethdev_init(struct protocol_stack *stack); - int32_t eth_dev_poll(void); --int32_t gazelle_eth_dev_poll(struct protocol_stack *stack, uint8_t use_ltran_flag, uint32_t nic_read_number); - void eth_dev_recv(struct rte_mbuf *mbuf, struct protocol_stack *stack); - --int recv_pkts_from_other_process(int process_index, void* arg); --int32_t check_params_from_primary(void); -- - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - void kni_handle_rx(uint16_t port_id); - void kni_handle_tx(struct rte_mbuf *mbuf); - #endif - --void delete_user_process_port(uint16_t dst_port, enum port_type type); --void add_user_process_port(uint16_t dst_port, uint8_t process_idx, enum port_type type); --void delete_flow_director(uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); --void config_flow_director(uint16_t queue_id, uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); - void netif_poll(struct netif *netif); - - #endif /* __GAZELLE_ETHDEV_H__ */ -diff --git a/src/lstack/include/lstack_flow.h b/src/lstack/include/lstack_flow.h -new file mode 100644 -index 0000000..ad35cdf ---- /dev/null -+++ b/src/lstack/include/lstack_flow.h -@@ -0,0 +1,51 @@ -+/* -+* 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 __LSTACK_FLOW_H__ -+#define __LSTACK_FLOW_H__ -+ -+#include -+ -+enum port_type { -+ PORT_LISTEN, -+ PORT_CONNECT, -+}; -+ -+enum PACKET_TRANSFER_TYPE { -+ TRANSFER_KERNEL = -1, -+ TRANSFER_OTHER_THREAD, -+ TRANSFER_CURRENT_THREAD, -+}; -+ -+enum TRANSFER_MESSAGE_RESULT { -+ CONNECT_ERROR = -2, -+ REPLY_ERROR = -1, -+ TRANSFER_SUCESS = 0, -+}; -+ -+int distribute_pakages(struct rte_mbuf *mbuf); -+void flow_init(void); -+int32_t check_params_from_primary(void); -+ -+int recv_pkts_from_other_process(int process_index, void* arg); -+void transfer_delete_rule_info_to_process0(uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); -+void transfer_create_rule_info_to_process0(uint16_t queue_id, uint32_t src_ip, -+ uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); -+void transfer_add_or_delete_listen_port_to_process0(uint16_t listen_port, uint8_t process_idx, uint8_t is_add); -+void transfer_arp_to_other_process(struct rte_mbuf *mbuf); -+ -+void add_user_process_port(uint16_t dst_port, uint8_t process_idx, enum port_type type); -+void delete_user_process_port(uint16_t dst_port, enum port_type type); -+ -+void gazelle_listen_thread(void *arg); -+ -+#endif -diff --git a/src/lstack/include/lstack_vdev.h b/src/lstack/include/lstack_vdev.h -index 007eec7..4e5d191 100644 ---- a/src/lstack/include/lstack_vdev.h -+++ b/src/lstack/include/lstack_vdev.h -@@ -13,19 +13,10 @@ - #ifndef _GAZELLE_VDEV_H_ - #define _GAZELLE_VDEV_H_ - --#include -- - struct lstack_dev_ops; - struct gazelle_quintuple; - enum reg_ring_type; - void vdev_dev_ops_init(struct lstack_dev_ops *dev_ops); - int vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple); - --int recv_pkts_from_other_process(int process_index, void* arg); --void transfer_delete_rule_info_to_process0(uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); --void transfer_create_rule_info_to_process0(uint16_t queue_id, uint32_t src_ip, -- uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); --void transfer_add_or_delete_listen_port_to_process0(uint16_t listen_port, uint8_t process_idx, uint8_t is_add); --void init_listen_and_user_ports(); -- - #endif /* _GAZELLE_VDEV_H_ */ -diff --git a/src/lstack/netif/dir.mk b/src/lstack/netif/dir.mk -index ec7c4ad..20fb5d6 100644 ---- a/src/lstack/netif/dir.mk -+++ b/src/lstack/netif/dir.mk -@@ -8,5 +8,5 @@ - # PURPOSE. - # See the Mulan PSL v2 for more details. - --SRC = lstack_ethdev.c lstack_vdev.c -+SRC = lstack_ethdev.c lstack_vdev.c lstack_flow.c - $(eval $(call register_dir, netif, $(SRC))) -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 25c94eb..2e938b0 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -10,74 +10,36 @@ - * See the Mulan PSL v2 for more details. - */ - --#include --#include -- - #include - #include - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - #include - #endif - #include --#include --#include - --#include - #include - #include - #include - #include --#include --#include - - #include --#include --#include - -+#include "dpdk_common.h" - #include "lstack_cfg.h" - #include "lstack_vdev.h" - #include "lstack_stack_stat.h" - #include "lstack_log.h" - #include "lstack_dpdk.h" - #include "lstack_lwip.h" --#include "dpdk_common.h" - #include "lstack_protocol_stack.h" - #include "lstack_thread_rpc.h" -+#include "lstack_flow.h" - #include "lstack_ethdev.h" - - /* FRAME_MTU + 14byte header */ - #define MBUF_MAX_LEN 1514 --#define MAX_PATTERN_NUM 4 --#define MAX_ACTION_NUM 2 --#define FULL_MASK 0xffffffff /* full mask */ --#define EMPTY_MASK 0x0 /* empty mask */ --#define LSTACK_MBUF_LEN 64 --#define TRANSFER_TCP_MUBF_LEN (LSTACK_MBUF_LEN + 3) --#define DELETE_FLOWS_PARAMS_NUM 3 --#define DELETE_FLOWS_PARAMS_LENGTH 30 --#define CREATE_FLOWS_PARAMS_NUM 6 --#define CREATE_FLOWS_PARAMS_LENGTH 60 --#define ADD_OR_DELETE_LISTEN_PORT_PARAMS_LENGTH 25 --#define ADD_OR_DELETE_LISTEN_PORT_PARAMS_NUM 3 --#define REPLY_LEN 10 --#define SUCCESS_REPLY "success" --#define ERROR_REPLY "error" - #define PACKET_READ_SIZE 32 - --#define GET_LSTACK_NUM 14 --#define GET_LSTACK_NUM_STRING "get_lstack_num" -- --#define SERVER_PATH "/var/run/gazelle/server.socket" --#define SPLIT_DELIM "," -- --#define UNIX_TCP_PORT_MAX 65535 -- --#define IPV4_VERSION_OFFSET 4 --#define IPV4_VERSION 4 -- --static uint8_t g_user_ports[UNIX_TCP_PORT_MAX] = {INVAILD_PROCESS_IDX, }; --static uint8_t g_listen_ports[UNIX_TCP_PORT_MAX] = {INVAILD_PROCESS_IDX, }; -- - void eth_dev_recv(struct rte_mbuf *mbuf, struct protocol_stack *stack) - { - int32_t ret; -@@ -126,636 +88,6 @@ void eth_dev_recv(struct rte_mbuf *mbuf, struct protocol_stack *stack) - } - } - --int32_t eth_dev_poll(void) --{ -- uint32_t nr_pkts; -- struct cfg_params *cfg = get_global_cfg_params(); -- struct protocol_stack *stack = get_protocol_stack(); -- -- nr_pkts = stack->dev_ops.rx_poll(stack, stack->pkts, cfg->nic_read_number); -- if (nr_pkts == 0) { -- return 0; -- } -- -- if (!cfg->use_ltran && get_protocol_stack_group()->latency_start) { -- uint64_t time_stamp = get_current_time(); -- time_stamp_into_mbuf(nr_pkts, stack->pkts, time_stamp); -- } -- -- for (uint32_t i = 0; i < nr_pkts; i++) { -- /* copy arp into other stack */ -- if (!cfg->use_ltran) { -- struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(stack->pkts[i], struct rte_ether_hdr *); -- if (unlikely(RTE_BE16(RTE_ETHER_TYPE_ARP) == ethh->ether_type)) { -- stack_broadcast_arp(stack->pkts[i], stack); -- } -- } -- -- eth_dev_recv(stack->pkts[i], stack); -- } -- -- stack->stats.rx += nr_pkts; -- -- return nr_pkts; --} -- --/* flow rule map */ --#define RULE_KEY_LEN 23 --struct flow_rule { -- char rule_key[RULE_KEY_LEN]; -- struct rte_flow *flow; -- UT_hash_handle hh; --}; -- --static uint16_t g_flow_num = 0; --struct flow_rule *g_flow_rules = NULL; --struct flow_rule *find_rule(char *rule_key) --{ -- struct flow_rule *fl; -- HASH_FIND_STR(g_flow_rules, rule_key, fl); -- return fl; --} -- --void add_rule(char* rule_key, struct rte_flow *flow) --{ -- struct flow_rule *rule; -- HASH_FIND_STR(g_flow_rules, rule_key, rule); -- if (rule == NULL) { -- rule = (struct flow_rule*)malloc(sizeof(struct flow_rule)); -- strcpy_s(rule->rule_key, RULE_KEY_LEN, rule_key); -- HASH_ADD_STR(g_flow_rules, rule_key, rule); -- } -- rule->flow = flow; --} -- --void delete_rule(char* rule_key) --{ -- struct flow_rule *rule = NULL; -- HASH_FIND_STR(g_flow_rules, rule_key, rule); -- if (rule != NULL) { -- HASH_DEL(g_flow_rules, rule); -- free(rule); -- } --} -- --void init_listen_and_user_ports(void) --{ -- memset_s(g_user_ports, sizeof(g_user_ports), INVAILD_PROCESS_IDX, sizeof(g_user_ports)); -- memset_s(g_listen_ports, sizeof(g_listen_ports), INVAILD_PROCESS_IDX, sizeof(g_listen_ports)); --} -- --int transfer_pkt_to_other_process(char *buf, int process_index, int write_len, bool need_reply) --{ -- /* other process queue_id */ -- struct sockaddr_un serun; -- int sockfd; -- int ret = 0; -- -- sockfd = posix_api->socket_fn(AF_UNIX, SOCK_STREAM, 0); -- memset_s(&serun, sizeof(serun), 0, sizeof(serun)); -- serun.sun_family = AF_UNIX; -- sprintf_s(serun.sun_path, PATH_MAX, "%s%d", SERVER_PATH, process_index); -- int32_t len = offsetof(struct sockaddr_un, sun_path) + strlen(serun.sun_path); -- if (posix_api->connect_fn(sockfd, (struct sockaddr *)&serun, len) < 0) { -- return CONNECT_ERROR; -- } -- posix_api->write_fn(sockfd, buf, write_len); -- if (need_reply) { -- char reply_message[REPLY_LEN]; -- int32_t read_result = posix_api->read_fn(sockfd, reply_message, REPLY_LEN); -- if (read_result > 0) { -- if (strcmp(reply_message, SUCCESS_REPLY) == 0) { -- ret = TRANSFER_SUCESS; -- } else if (strcmp(reply_message, ERROR_REPLY) == 0) { -- ret = REPLY_ERROR; -- } else { -- ret = atoi(reply_message); -- } -- } else { -- ret = REPLY_ERROR; -- } -- } -- posix_api->close_fn(sockfd); -- -- return ret; --} -- --int32_t check_params_from_primary(void) --{ -- struct cfg_params *cfg = get_global_cfg_params(); -- if (cfg->is_primary) { -- return 0; -- } -- // check lstack num -- char get_lstack_num[GET_LSTACK_NUM]; -- sprintf_s(get_lstack_num, GET_LSTACK_NUM, "%s", GET_LSTACK_NUM_STRING); -- int32_t ret = transfer_pkt_to_other_process(get_lstack_num, 0, GET_LSTACK_NUM, true); -- if (ret != cfg->num_cpu) { -- return -1; -- } -- return 0; --} -- --struct rte_flow *create_flow_director(uint16_t port_id, uint16_t queue_id, -- uint32_t src_ip, uint32_t dst_ip, -- uint16_t src_port, uint16_t dst_port, -- struct rte_flow_error *error) --{ -- struct rte_flow_attr attr; -- struct rte_flow_item pattern[MAX_PATTERN_NUM]; -- struct rte_flow_action action[MAX_ACTION_NUM]; -- struct rte_flow *flow = NULL; -- struct rte_flow_action_queue queue = { .index = queue_id }; -- struct rte_flow_item_ipv4 ip_spec; -- struct rte_flow_item_ipv4 ip_mask; -- -- struct rte_flow_item_tcp tcp_spec; -- struct rte_flow_item_tcp tcp_mask; -- int res; -- -- memset_s(pattern, sizeof(pattern), 0, sizeof(pattern)); -- memset_s(action, sizeof(action), 0, sizeof(action)); -- -- /* -- * set the rule attribute. -- * in this case only ingress packets will be checked. -- */ -- memset_s(&attr, sizeof(struct rte_flow_attr), 0, sizeof(struct rte_flow_attr)); -- attr.ingress = 1; -- -- /* -- * create the action sequence. -- * one action only, move packet to queue -- */ -- action[0].type = RTE_FLOW_ACTION_TYPE_QUEUE; -- action[0].conf = &queue; -- action[1].type = RTE_FLOW_ACTION_TYPE_END; -- -- // not limit eth header -- pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; -- -- // ip header -- memset_s(&ip_spec, sizeof(struct rte_flow_item_ipv4), 0, sizeof(struct rte_flow_item_ipv4)); -- memset_s(&ip_mask, sizeof(struct rte_flow_item_ipv4), 0, sizeof(struct rte_flow_item_ipv4)); -- ip_spec.hdr.dst_addr = dst_ip; -- ip_mask.hdr.dst_addr = FULL_MASK; -- ip_spec.hdr.src_addr = src_ip; -- ip_mask.hdr.src_addr = FULL_MASK; -- pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4; -- pattern[1].spec = &ip_spec; -- pattern[1].mask = &ip_mask; -- -- // tcp header, full mask 0xffff -- memset_s(&tcp_spec, sizeof(struct rte_flow_item_tcp), 0, sizeof(struct rte_flow_item_tcp)); -- memset_s(&tcp_mask, sizeof(struct rte_flow_item_tcp), 0, sizeof(struct rte_flow_item_tcp)); -- pattern[2].type = RTE_FLOW_ITEM_TYPE_TCP; // 2: pattern 2 is tcp header -- tcp_spec.hdr.src_port = src_port; -- tcp_spec.hdr.dst_port = dst_port; -- tcp_mask.hdr.src_port = rte_flow_item_tcp_mask.hdr.src_port; -- tcp_mask.hdr.dst_port = rte_flow_item_tcp_mask.hdr.dst_port; -- pattern[2].spec = &tcp_spec; -- pattern[2].mask = &tcp_mask; -- -- /* the final level must be always type end */ -- pattern[3].type = RTE_FLOW_ITEM_TYPE_END; -- res = rte_flow_validate(port_id, &attr, pattern, action, error); -- if (!res) { -- flow = rte_flow_create(port_id, &attr, pattern, action, error); -- } else { -- LSTACK_LOG(ERR, LSTACK, "rte_flow_create.rte_flow_validate error, res %d \n", res); -- } -- -- return flow; --} -- --void config_flow_director(uint16_t queue_id, uint32_t src_ip, -- uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) --{ -- uint16_t port_id = get_protocol_stack_group()->port_id; -- char rule_key[RULE_KEY_LEN] = {0}; -- sprintf_s(rule_key, sizeof(rule_key), "%u_%u_%u", src_ip, src_port, dst_port); -- struct flow_rule *fl_exist = find_rule(rule_key); -- if (fl_exist != NULL) { -- return; -- } -- -- LSTACK_LOG(INFO, LSTACK, -- "config_flow_director, flow queue_id %u, src_ip %u,src_port_ntohs:%u, dst_port_ntohs:%u\n", -- queue_id, src_ip, ntohs(src_port), ntohs(dst_port)); -- -- struct rte_flow_error error; -- struct rte_flow *flow = create_flow_director(port_id, queue_id, src_ip, dst_ip, src_port, dst_port, &error); -- if (!flow) { -- LSTACK_LOG(ERR, LSTACK,"flow can not be created. queue_id %u, src_ip %u, src_port %u," -- "dst_port %u, dst_port_ntohs :%u, type %d. message: %s\n", -- queue_id, src_ip, src_port, dst_port, ntohs(dst_port), -- error.type, error.message ? error.message : "(no stated reason)"); -- return; -- } -- __sync_fetch_and_add(&g_flow_num, 1); -- add_rule(rule_key, flow); --} -- --void delete_flow_director(uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) --{ -- uint16_t port_id = get_protocol_stack_group()->port_id; -- char rule_key[RULE_KEY_LEN] = {0}; -- sprintf_s(rule_key, RULE_KEY_LEN, "%u_%u_%u",dst_ip, dst_port, src_port); -- struct flow_rule *fl = find_rule(rule_key); -- -- if(fl != NULL){ -- struct rte_flow_error error; -- int ret = rte_flow_destroy(port_id, fl->flow, &error); -- if(ret != 0){ -- LSTACK_LOG(ERR, LSTACK, "Flow can't be delete %d message: %s\n", -- error.type, error.message ? error.message : "(no stated reason)"); -- } -- delete_rule(rule_key); -- __sync_fetch_and_sub(&g_flow_num, 1); -- } --} -- --/* if process 0, delete directly, else transfer 'dst_ip,src_port,dst_port' to process 0. */ --void transfer_delete_rule_info_to_process0(uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) --{ -- if (get_global_cfg_params()->is_primary) { -- delete_flow_director(dst_ip, src_port, dst_port); -- } else { -- char process_server_path[DELETE_FLOWS_PARAMS_LENGTH]; -- sprintf_s(process_server_path, DELETE_FLOWS_PARAMS_LENGTH, "%u%s%u%s%u", -- dst_ip, SPLIT_DELIM, src_port, SPLIT_DELIM, dst_port); -- int ret = transfer_pkt_to_other_process(process_server_path, 0, DELETE_FLOWS_PARAMS_LENGTH, false); -- if(ret != TRANSFER_SUCESS){ -- LSTACK_LOG(ERR, LSTACK, "error. tid %d. dst_ip %u, src_port: %u, dst_port %u\n", -- rte_gettid(), dst_ip, src_port, dst_port); -- } -- } --} -- --// if process 0, add directly, else transfer 'src_ip,dst_ip,src_port,dst_port,queue_id' to process 0. --void transfer_create_rule_info_to_process0(uint16_t queue_id, uint32_t src_ip, -- uint32_t dst_ip, uint16_t src_port, -- uint16_t dst_port) --{ -- char process_server_path[CREATE_FLOWS_PARAMS_LENGTH]; -- /* exchage src_ip and dst_ip, src_port and dst_port */ -- uint8_t process_idx = get_global_cfg_params()->process_idx; -- sprintf_s(process_server_path, CREATE_FLOWS_PARAMS_LENGTH, "%u%s%u%s%u%s%u%s%u%s%u", -- dst_ip, SPLIT_DELIM, src_ip, SPLIT_DELIM, -- dst_port, SPLIT_DELIM, src_port, SPLIT_DELIM, -- queue_id, SPLIT_DELIM, process_idx); -- int ret = transfer_pkt_to_other_process(process_server_path, 0, CREATE_FLOWS_PARAMS_LENGTH, true); -- if (ret != TRANSFER_SUCESS) { -- LSTACK_LOG(ERR, LSTACK, "error. tid %d. src_ip %u, dst_ip %u, src_port: %u, dst_port %u," -- "queue_id %u, process_idx %u\n", -- rte_gettid(), src_ip, dst_ip, src_port, dst_port, queue_id, process_idx); -- } --} -- --void transfer_add_or_delete_listen_port_to_process0(uint16_t listen_port, uint8_t process_idx, uint8_t is_add) --{ -- char process_server_path[ADD_OR_DELETE_LISTEN_PORT_PARAMS_LENGTH]; -- sprintf_s(process_server_path, ADD_OR_DELETE_LISTEN_PORT_PARAMS_LENGTH, -- "%u%s%u%s%u", listen_port, SPLIT_DELIM, process_idx, SPLIT_DELIM, is_add); -- int ret = transfer_pkt_to_other_process(process_server_path, 0, ADD_OR_DELETE_LISTEN_PORT_PARAMS_LENGTH, true); -- if(ret != TRANSFER_SUCESS) { -- LSTACK_LOG(ERR, LSTACK, "error. tid %d. listen_port %u, process_idx %u\n", -- rte_gettid(), listen_port, process_idx); -- } --} -- --static int str_to_array(char *args, uint32_t *array, int size) --{ -- int val; -- uint16_t cnt = 0; -- char *elem = NULL; -- char *next_token = NULL; -- -- memset_s(array, sizeof(*array) * size, 0, sizeof(*array) * size); -- elem = strtok_s((char *)args, SPLIT_DELIM, &next_token); -- while (elem != NULL) { -- if (cnt >= size) { -- return -1; -- } -- val = atoi(elem); -- if (val < 0) { -- return -1; -- } -- array[cnt] = (uint32_t)val; -- cnt++; -- -- elem = strtok_s(NULL, SPLIT_DELIM, &next_token); -- } -- -- return cnt; --} -- --void parse_and_delete_rule(char* buf) --{ -- uint32_t array[DELETE_FLOWS_PARAMS_NUM]; -- str_to_array(buf, array, DELETE_FLOWS_PARAMS_NUM); -- uint32_t dst_ip = array[0]; -- uint16_t src_port = array[1]; -- uint16_t dst_port = array[2]; -- delete_flow_director(dst_ip, src_port, dst_port); --} -- --void add_user_process_port(uint16_t dst_port, uint8_t process_idx, enum port_type type) --{ -- if (type == PORT_LISTEN) { -- g_listen_ports[dst_port] = process_idx; -- } else { -- g_user_ports[dst_port] = process_idx; -- } --} -- --void delete_user_process_port(uint16_t dst_port, enum port_type type) --{ -- if (type == PORT_LISTEN) { -- g_listen_ports[dst_port] = INVAILD_PROCESS_IDX; -- } else { -- g_user_ports[dst_port] = INVAILD_PROCESS_IDX; -- } --} -- --void parse_and_create_rule(char* buf) --{ -- uint32_t array[CREATE_FLOWS_PARAMS_NUM]; -- str_to_array(buf, array, CREATE_FLOWS_PARAMS_NUM); -- uint32_t src_ip = array[0]; -- uint32_t dst_ip = array[1]; -- uint16_t src_port = array[2]; -- uint16_t dst_port = array[3]; -- uint16_t queue_id = array[4]; -- uint8_t process_idx = array[5]; -- config_flow_director(queue_id, src_ip, dst_ip, src_port, dst_port); -- add_user_process_port(dst_port, process_idx, PORT_CONNECT); --} -- --void parse_and_add_or_delete_listen_port(char* buf) --{ -- uint32_t array[ADD_OR_DELETE_LISTEN_PORT_PARAMS_NUM]; -- str_to_array(buf, array, ADD_OR_DELETE_LISTEN_PORT_PARAMS_NUM); -- uint16_t listen_port = array[0]; -- uint8_t process_idx = array[1]; -- uint8_t is_add = array[2]; -- if (is_add == 1) { -- add_user_process_port(listen_port, process_idx, PORT_LISTEN); -- } else { -- delete_user_process_port(listen_port, PORT_LISTEN); -- } -- --} -- --void transfer_arp_to_other_process(struct rte_mbuf *mbuf) --{ -- struct cfg_params *cfgs = get_global_cfg_params(); -- -- for(int i = 1; i < cfgs->num_process; i++){ -- char arp_mbuf[LSTACK_MBUF_LEN] = {0}; -- sprintf_s(arp_mbuf, sizeof(arp_mbuf), "%lu", mbuf); -- int result = transfer_pkt_to_other_process(arp_mbuf, i, LSTACK_MBUF_LEN, false); -- if (result == CONNECT_ERROR) { -- LSTACK_LOG(INFO, LSTACK,"connect process %d failed, ensure the process is started.\n", i); -- } else if (result == REPLY_ERROR) { -- LSTACK_LOG(ERR, LSTACK,"transfer arp pakages to process %d error. %m\n", i); -- } -- } --} -- --void transfer_tcp_to_thread(struct rte_mbuf *mbuf, uint16_t stk_idx) --{ -- /* current process queue_id */ -- struct protocol_stack *stack = get_protocol_stack_group()->stacks[stk_idx]; -- int ret = -1; -- while(ret != 0) { -- ret = rpc_call_arp(&stack->rpc_queue, mbuf); -- printf("transfer_tcp_to_thread, ret : %d \n", ret); -- } --} -- --void parse_arp_and_transefer(char* buf) --{ -- struct rte_mbuf *mbuf = (struct rte_mbuf *)atoll(buf); -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- struct rte_mbuf *mbuf_copy = NULL; -- struct protocol_stack *stack = NULL; -- int32_t ret; -- for (int32_t i = 0; i < stack_group->stack_num; i++) { -- stack = stack_group->stacks[i]; -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -- while (ret != 0) { -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -- stack->stats.rx_allocmbuf_fail++; -- } -- copy_mbuf(mbuf_copy, mbuf); -- -- ret = rpc_call_arp(&stack->rpc_queue, mbuf_copy); -- -- while (ret != 0) { -- rpc_call_arp(&stack->rpc_queue, mbuf_copy); -- } -- } --} -- --void parse_tcp_and_transefer(char* buf) --{ -- char *next_token = NULL; -- char *elem = strtok_s(buf, SPLIT_DELIM, &next_token); -- struct rte_mbuf *mbuf = (struct rte_mbuf *) atoll(elem); -- elem = strtok_s(NULL, SPLIT_DELIM, &next_token); -- uint16_t queue_id = atoll(elem); -- -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- uint16_t num_queue = get_global_cfg_params()->num_queue; -- uint16_t stk_index = queue_id % num_queue; -- struct rte_mbuf *mbuf_copy = NULL; -- struct protocol_stack *stack = stack_group->stacks[stk_index]; -- -- int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -- while (ret != 0) { -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -- stack->stats.rx_allocmbuf_fail++; -- } -- -- copy_mbuf(mbuf_copy,mbuf); -- -- transfer_tcp_to_thread(mbuf_copy, stk_index); --} -- --int recv_pkts_from_other_process(int process_index, void* arg) --{ -- struct sockaddr_un serun, cliun; -- socklen_t cliun_len; -- int listenfd, connfd, size; -- char buf[132]; -- /* socket */ -- if ((listenfd = posix_api->socket_fn(AF_UNIX, SOCK_STREAM, 0)) < 0) { -- perror("socket error"); -- return -1; -- } -- /* bind */ -- memset_s(&serun, sizeof(serun), 0, sizeof(serun)); -- serun.sun_family = AF_UNIX; -- char process_server_path[PATH_MAX]; -- sprintf_s(process_server_path, sizeof(process_server_path), "%s%d", SERVER_PATH, process_index); -- strcpy_s(serun.sun_path, sizeof(serun.sun_path), process_server_path); -- size = offsetof(struct sockaddr_un, sun_path) + strlen(serun.sun_path); -- unlink(process_server_path); -- if (posix_api->bind_fn(listenfd, (struct sockaddr *)&serun, size) < 0) { -- perror("bind error"); -- return -1; -- } -- if (posix_api->listen_fn(listenfd, 20) < 0) { /* 20: max backlog */ -- perror("listen error"); -- return -1; -- } -- sem_post((sem_t *)arg); -- /* block */ -- while(1) { -- cliun_len = sizeof(cliun); -- if ((connfd = posix_api->accept_fn(listenfd, (struct sockaddr *)&cliun, &cliun_len)) < 0) { -- perror("accept error"); -- continue; -- } -- while(1) { -- int n = posix_api->read_fn(connfd, buf, sizeof(buf)); -- if (n < 0) { -- perror("read error"); -- break; -- } else if (n == 0) { -- break; -- } -- -- if(n == LSTACK_MBUF_LEN) { -- /* arp */ -- parse_arp_and_transefer(buf); -- } else if (n == TRANSFER_TCP_MUBF_LEN) { -- /* tcp. lstack_mbuf_queue_id */ -- parse_tcp_and_transefer(buf); -- } else if (n == DELETE_FLOWS_PARAMS_LENGTH) { -- /* delete rule */ -- parse_and_delete_rule(buf); -- } else if(n == CREATE_FLOWS_PARAMS_LENGTH) { -- /* add rule */ -- parse_and_create_rule(buf); -- char reply_buf[REPLY_LEN]; -- sprintf_s(reply_buf, sizeof(reply_buf), "%s", SUCCESS_REPLY); -- posix_api->write_fn(connfd, reply_buf, REPLY_LEN); -- } else if (n == GET_LSTACK_NUM) { -- char reply_buf[REPLY_LEN]; -- sprintf_s(reply_buf, sizeof(reply_buf), "%d", get_global_cfg_params()->num_cpu); -- posix_api->write_fn(connfd, reply_buf, REPLY_LEN); -- } else { -- /* add port */ -- parse_and_add_or_delete_listen_port(buf); -- char reply_buf[REPLY_LEN]; -- sprintf_s(reply_buf, sizeof(reply_buf), "%s", SUCCESS_REPLY); -- posix_api->write_fn(connfd, reply_buf, REPLY_LEN); -- } -- -- } -- posix_api->close_fn(connfd); -- } -- posix_api->close_fn(listenfd); -- return 0; --} -- --void concat_mbuf_and_queue_id(struct rte_mbuf *mbuf, uint16_t queue_id, -- char* mbuf_and_queue_id, int write_len) --{ -- sprintf_s(mbuf_and_queue_id, write_len, "%lu%s%u", mbuf, SPLIT_DELIM, queue_id); --} -- --static int mbuf_to_idx(struct rte_mbuf *mbuf, uint16_t *dst_port) --{ -- struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr *); -- u16_t type = rte_be_to_cpu_16(ethh->ether_type); -- uint32_t index = 0; -- if (type == RTE_ETHER_TYPE_IPV4) { -- struct rte_ipv4_hdr *iph = rte_pktmbuf_mtod_offset(mbuf, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr)); -- uint8_t ip_version = (iph->version_ihl & 0xf0) >> IPV4_VERSION_OFFSET; -- if (likely(ip_version == IPV4_VERSION)) { -- if (likely(iph->next_proto_id == IPPROTO_TCP)) { -- struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(mbuf, struct rte_tcp_hdr *, -- sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr)); -- *dst_port = tcp_hdr->dst_port; -- -- if (unlikely(tcp_hdr->tcp_flags == TCP_SYN)) { -- uint32_t src_ip = iph->src_addr; -- uint16_t src_port = tcp_hdr->src_port; -- index = rte_jhash_3words(src_ip, src_port | ((*dst_port) << 16), 0, 0); -- } else { -- return -1; -- } -- } -- } -- } else if (type == RTE_ETHER_TYPE_IPV6) { -- struct rte_ipv6_hdr *iph = rte_pktmbuf_mtod_offset(mbuf, struct rte_ipv6_hdr *, sizeof(struct rte_ether_hdr)); -- if (likely(iph->proto == IPPROTO_TCP)) { -- struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(mbuf, struct rte_tcp_hdr *, -- sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv6_hdr)); -- *dst_port = tcp_hdr->dst_port; -- -- if (unlikely(tcp_hdr->tcp_flags == TCP_SYN)) { -- uint32_t *src_ip = (uint32_t *) &iph->src_addr; -- uint16_t src_port = tcp_hdr->src_port; -- uint32_t v = rte_jhash_3words(src_ip[0], src_ip[1], src_ip[2], 0); -- index = rte_jhash_3words(src_ip[3], src_port | ((*dst_port) << 16), v, 0); -- } else { -- return -1; -- } -- } -- } else { -- return -1; -- } -- return index; --} -- --int distribute_pakages(struct rte_mbuf *mbuf) --{ -- uint16_t dst_port = 0; -- uint32_t index = mbuf_to_idx(mbuf, &dst_port); -- if (index == -1) { -- return TRANSFER_CURRENT_THREAD; -- } -- -- uint16_t queue_id = 0; -- uint32_t user_process_idx = 0; -- int each_process_queue_num = get_global_cfg_params()->num_queue; -- index = index % each_process_queue_num; -- if (g_listen_ports[dst_port] != INVAILD_PROCESS_IDX) { -- user_process_idx = g_listen_ports[dst_port]; -- } else { -- user_process_idx = g_user_ports[dst_port]; -- } -- -- if (user_process_idx == INVAILD_PROCESS_IDX) { -- 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; -- } -- if (queue_id != 0) { -- if (user_process_idx == 0) { -- transfer_tcp_to_thread(mbuf, queue_id); -- } else { -- char mbuf_and_queue_id[TRANSFER_TCP_MUBF_LEN]; -- concat_mbuf_and_queue_id(mbuf, queue_id, mbuf_and_queue_id, TRANSFER_TCP_MUBF_LEN); -- transfer_pkt_to_other_process(mbuf_and_queue_id, user_process_idx, -- TRANSFER_TCP_MUBF_LEN, false); -- } -- return TRANSFER_OTHER_THREAD; -- } else { -- return TRANSFER_CURRENT_THREAD; -- } -- -- return TRANSFER_KERNEL; --} -- - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - void kni_handle_rx(uint16_t port_id) - { -@@ -797,17 +129,18 @@ void kni_handle_tx(struct rte_mbuf *mbuf) - } - #endif - --/* optimized eth_dev_poll() in lstack */ --int32_t gazelle_eth_dev_poll(struct protocol_stack *stack, uint8_t use_ltran_flag, uint32_t nic_read_number) -+int32_t eth_dev_poll(void) - { - uint32_t nr_pkts; -+ struct cfg_params *cfg = get_global_cfg_params(); -+ struct protocol_stack *stack = get_protocol_stack(); - -- nr_pkts = stack->dev_ops.rx_poll(stack, stack->pkts, nic_read_number); -+ nr_pkts = stack->dev_ops.rx_poll(stack, stack->pkts, cfg->nic_read_number); - if (nr_pkts == 0) { - return 0; - } - -- if (!use_ltran_flag && get_protocol_stack_group()->latency_start) { -+ if (!use_ltran() && get_protocol_stack_group()->latency_start) { - uint64_t time_stamp = get_current_time(); - time_stamp_into_mbuf(nr_pkts, stack->pkts, time_stamp); - } -@@ -816,7 +149,7 @@ int32_t gazelle_eth_dev_poll(struct protocol_stack *stack, uint8_t use_ltran_fla - /* 1 current thread recv; 0 other thread recv; -1 kni recv; */ - int transfer_type = TRANSFER_CURRENT_THREAD; - /* copy arp into other stack */ -- if (!use_ltran_flag) { -+ if (!use_ltran()) { - struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(stack->pkts[i], struct rte_ether_hdr *); - u16_t type; - type = ethh->ether_type; -@@ -946,6 +279,10 @@ int32_t ethdev_init(struct protocol_stack *stack) - LSTACK_LOG(ERR, LSTACK, "fill mbuf to rx_ring failed ret=%d\n", ret); - return ret; - } -+ } else { -+ if (cfg->tuple_filter && stack->queue_id == 0) { -+ flow_init(); -+ } - } - - netif_set_default(&stack->netif); -diff --git a/src/lstack/netif/lstack_flow.c b/src/lstack/netif/lstack_flow.c -new file mode 100644 -index 0000000..4e04209 ---- /dev/null -+++ b/src/lstack/netif/lstack_flow.c -@@ -0,0 +1,680 @@ -+/* -+* 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 -+#include -+#include -+ -+#include -+#include -+#include -+#include -+ -+#include -+#include -+#include -+ -+#include "dpdk_common.h" -+#include "lstack_log.h" -+#include "lstack_dpdk.h" -+#include "lstack_cfg.h" -+#include "lstack_protocol_stack.h" -+#include "lstack_flow.h" -+ -+#define MAX_PATTERN_NUM 4 -+#define MAX_ACTION_NUM 2 -+#define FULL_MASK 0xffffffff /* full mask */ -+#define EMPTY_MASK 0x0 /* empty mask */ -+#define LSTACK_MBUF_LEN 64 -+#define TRANSFER_TCP_MUBF_LEN (LSTACK_MBUF_LEN + 3) -+#define DELETE_FLOWS_PARAMS_NUM 3 -+#define DELETE_FLOWS_PARAMS_LENGTH 30 -+#define CREATE_FLOWS_PARAMS_NUM 6 -+#define CREATE_FLOWS_PARAMS_LENGTH 60 -+#define ADD_OR_DELETE_LISTEN_PORT_PARAMS_LENGTH 25 -+#define ADD_OR_DELETE_LISTEN_PORT_PARAMS_NUM 3 -+#define REPLY_LEN 10 -+#define SUCCESS_REPLY "success" -+#define ERROR_REPLY "error" -+ -+#define GET_LSTACK_NUM 14 -+#define GET_LSTACK_NUM_STRING "get_lstack_num" -+ -+#define SERVER_PATH "/var/run/gazelle/server.socket" -+#define SPLIT_DELIM "," -+ -+#define UNIX_TCP_PORT_MAX 65535 -+ -+#define INVAILD_PROCESS_IDX 255 -+ -+#define IPV4_VERSION_OFFSET 4 -+#define IPV4_VERSION 4 -+ -+static uint8_t g_user_ports[UNIX_TCP_PORT_MAX] = {INVAILD_PROCESS_IDX, }; -+static uint8_t g_listen_ports[UNIX_TCP_PORT_MAX] = {INVAILD_PROCESS_IDX, }; -+ -+/* flow rule map */ -+#define RULE_KEY_LEN 23 -+struct flow_rule { -+ char rule_key[RULE_KEY_LEN]; -+ struct rte_flow *flow; -+ UT_hash_handle hh; -+}; -+ -+static uint16_t g_flow_num = 0; -+static struct flow_rule *g_flow_rules = NULL; -+static struct flow_rule *find_rule(char *rule_key) -+{ -+ struct flow_rule *fl; -+ HASH_FIND_STR(g_flow_rules, rule_key, fl); -+ return fl; -+} -+ -+static void add_rule(char* rule_key, struct rte_flow *flow) -+{ -+ struct flow_rule *rule; -+ HASH_FIND_STR(g_flow_rules, rule_key, rule); -+ if (rule == NULL) { -+ rule = (struct flow_rule*)malloc(sizeof(struct flow_rule)); -+ strcpy_s(rule->rule_key, RULE_KEY_LEN, rule_key); -+ HASH_ADD_STR(g_flow_rules, rule_key, rule); -+ } -+ rule->flow = flow; -+} -+ -+static void delete_rule(char* rule_key) -+{ -+ struct flow_rule *rule = NULL; -+ HASH_FIND_STR(g_flow_rules, rule_key, rule); -+ if (rule != NULL) { -+ HASH_DEL(g_flow_rules, rule); -+ free(rule); -+ } -+} -+ -+static void init_listen_and_user_ports(void) -+{ -+ memset_s(g_user_ports, sizeof(g_user_ports), INVAILD_PROCESS_IDX, sizeof(g_user_ports)); -+ memset_s(g_listen_ports, sizeof(g_listen_ports), INVAILD_PROCESS_IDX, sizeof(g_listen_ports)); -+} -+ -+static int transfer_pkt_to_other_process(char *buf, int process_index, int write_len, bool need_reply) -+{ -+ /* other process queue_id */ -+ struct sockaddr_un serun; -+ int sockfd; -+ int ret = 0; -+ -+ sockfd = posix_api->socket_fn(AF_UNIX, SOCK_STREAM, 0); -+ memset_s(&serun, sizeof(serun), 0, sizeof(serun)); -+ serun.sun_family = AF_UNIX; -+ sprintf_s(serun.sun_path, PATH_MAX, "%s%d", SERVER_PATH, process_index); -+ int32_t len = offsetof(struct sockaddr_un, sun_path) + strlen(serun.sun_path); -+ if (posix_api->connect_fn(sockfd, (struct sockaddr *)&serun, len) < 0) { -+ return CONNECT_ERROR; -+ } -+ posix_api->write_fn(sockfd, buf, write_len); -+ if (need_reply) { -+ char reply_message[REPLY_LEN]; -+ int32_t read_result = posix_api->read_fn(sockfd, reply_message, REPLY_LEN); -+ if (read_result > 0) { -+ if (strcmp(reply_message, SUCCESS_REPLY) == 0) { -+ ret = TRANSFER_SUCESS; -+ } else if (strcmp(reply_message, ERROR_REPLY) == 0) { -+ ret = REPLY_ERROR; -+ } else { -+ ret = atoi(reply_message); -+ } -+ } else { -+ ret = REPLY_ERROR; -+ } -+ } -+ posix_api->close_fn(sockfd); -+ -+ return ret; -+} -+ -+int32_t check_params_from_primary(void) -+{ -+ struct cfg_params *cfg = get_global_cfg_params(); -+ if (cfg->is_primary) { -+ return 0; -+ } -+ // check lstack num -+ char get_lstack_num[GET_LSTACK_NUM]; -+ sprintf_s(get_lstack_num, GET_LSTACK_NUM, "%s", GET_LSTACK_NUM_STRING); -+ int32_t ret = transfer_pkt_to_other_process(get_lstack_num, 0, GET_LSTACK_NUM, true); -+ if (ret != cfg->num_cpu) { -+ return -1; -+ } -+ return 0; -+} -+ -+static struct rte_flow *create_flow_director(uint16_t port_id, uint16_t queue_id, -+ uint32_t src_ip, uint32_t dst_ip, -+ uint16_t src_port, uint16_t dst_port, -+ struct rte_flow_error *error) -+{ -+ struct rte_flow_attr attr; -+ struct rte_flow_item pattern[MAX_PATTERN_NUM]; -+ struct rte_flow_action action[MAX_ACTION_NUM]; -+ struct rte_flow *flow = NULL; -+ struct rte_flow_action_queue queue = { .index = queue_id }; -+ struct rte_flow_item_ipv4 ip_spec; -+ struct rte_flow_item_ipv4 ip_mask; -+ -+ struct rte_flow_item_tcp tcp_spec; -+ struct rte_flow_item_tcp tcp_mask; -+ int res; -+ -+ memset_s(pattern, sizeof(pattern), 0, sizeof(pattern)); -+ memset_s(action, sizeof(action), 0, sizeof(action)); -+ -+ /* -+ * set the rule attribute. -+ * in this case only ingress packets will be checked. -+ */ -+ memset_s(&attr, sizeof(struct rte_flow_attr), 0, sizeof(struct rte_flow_attr)); -+ attr.ingress = 1; -+ -+ /* -+ * create the action sequence. -+ * one action only, move packet to queue -+ */ -+ action[0].type = RTE_FLOW_ACTION_TYPE_QUEUE; -+ action[0].conf = &queue; -+ action[1].type = RTE_FLOW_ACTION_TYPE_END; -+ -+ // not limit eth header -+ pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; -+ -+ // ip header -+ memset_s(&ip_spec, sizeof(struct rte_flow_item_ipv4), 0, sizeof(struct rte_flow_item_ipv4)); -+ memset_s(&ip_mask, sizeof(struct rte_flow_item_ipv4), 0, sizeof(struct rte_flow_item_ipv4)); -+ ip_spec.hdr.dst_addr = dst_ip; -+ ip_mask.hdr.dst_addr = FULL_MASK; -+ ip_spec.hdr.src_addr = src_ip; -+ ip_mask.hdr.src_addr = FULL_MASK; -+ pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4; -+ pattern[1].spec = &ip_spec; -+ pattern[1].mask = &ip_mask; -+ -+ // tcp header, full mask 0xffff -+ memset_s(&tcp_spec, sizeof(struct rte_flow_item_tcp), 0, sizeof(struct rte_flow_item_tcp)); -+ memset_s(&tcp_mask, sizeof(struct rte_flow_item_tcp), 0, sizeof(struct rte_flow_item_tcp)); -+ pattern[2].type = RTE_FLOW_ITEM_TYPE_TCP; // 2: pattern 2 is tcp header -+ tcp_spec.hdr.src_port = src_port; -+ tcp_spec.hdr.dst_port = dst_port; -+ tcp_mask.hdr.src_port = rte_flow_item_tcp_mask.hdr.src_port; -+ tcp_mask.hdr.dst_port = rte_flow_item_tcp_mask.hdr.dst_port; -+ pattern[2].spec = &tcp_spec; -+ pattern[2].mask = &tcp_mask; -+ -+ /* the final level must be always type end */ -+ pattern[3].type = RTE_FLOW_ITEM_TYPE_END; -+ res = rte_flow_validate(port_id, &attr, pattern, action, error); -+ if (!res) { -+ flow = rte_flow_create(port_id, &attr, pattern, action, error); -+ } else { -+ LSTACK_LOG(ERR, LSTACK, "rte_flow_create.rte_flow_validate error, res %d \n", res); -+ } -+ -+ return flow; -+} -+ -+static void config_flow_director(uint16_t queue_id, uint32_t src_ip, -+ uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) -+{ -+ uint16_t port_id = get_protocol_stack_group()->port_id; -+ char rule_key[RULE_KEY_LEN] = {0}; -+ sprintf_s(rule_key, sizeof(rule_key), "%u_%u_%u", src_ip, src_port, dst_port); -+ struct flow_rule *fl_exist = find_rule(rule_key); -+ if (fl_exist != NULL) { -+ return; -+ } -+ -+ LSTACK_LOG(INFO, LSTACK, -+ "config_flow_director, flow queue_id %u, src_ip %u,src_port_ntohs:%u, dst_port_ntohs:%u\n", -+ queue_id, src_ip, ntohs(src_port), ntohs(dst_port)); -+ -+ struct rte_flow_error error; -+ struct rte_flow *flow = create_flow_director(port_id, queue_id, src_ip, dst_ip, src_port, dst_port, &error); -+ if (!flow) { -+ LSTACK_LOG(ERR, LSTACK,"flow can not be created. queue_id %u, src_ip %u, src_port %u," -+ "dst_port %u, dst_port_ntohs :%u, type %d. message: %s\n", -+ queue_id, src_ip, src_port, dst_port, ntohs(dst_port), -+ error.type, error.message ? error.message : "(no stated reason)"); -+ return; -+ } -+ __sync_fetch_and_add(&g_flow_num, 1); -+ add_rule(rule_key, flow); -+} -+ -+static void delete_flow_director(uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) -+{ -+ uint16_t port_id = get_protocol_stack_group()->port_id; -+ char rule_key[RULE_KEY_LEN] = {0}; -+ sprintf_s(rule_key, RULE_KEY_LEN, "%u_%u_%u",dst_ip, dst_port, src_port); -+ struct flow_rule *fl = find_rule(rule_key); -+ -+ if(fl != NULL) { -+ struct rte_flow_error error; -+ int ret = rte_flow_destroy(port_id, fl->flow, &error); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "Flow can't be delete %d message: %s\n", -+ error.type, error.message ? error.message : "(no stated reason)"); -+ } -+ delete_rule(rule_key); -+ __sync_fetch_and_sub(&g_flow_num, 1); -+ } -+} -+ -+/* if process 0, delete directly, else transfer 'dst_ip,src_port,dst_port' to process 0. */ -+void transfer_delete_rule_info_to_process0(uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) -+{ -+ if (get_global_cfg_params()->is_primary) { -+ delete_flow_director(dst_ip, src_port, dst_port); -+ } else { -+ char process_server_path[DELETE_FLOWS_PARAMS_LENGTH]; -+ sprintf_s(process_server_path, DELETE_FLOWS_PARAMS_LENGTH, "%u%s%u%s%u", -+ dst_ip, SPLIT_DELIM, src_port, SPLIT_DELIM, dst_port); -+ int ret = transfer_pkt_to_other_process(process_server_path, 0, DELETE_FLOWS_PARAMS_LENGTH, false); -+ if (ret != TRANSFER_SUCESS) { -+ LSTACK_LOG(ERR, LSTACK, "error. tid %d. dst_ip %u, src_port: %u, dst_port %u\n", -+ rte_gettid(), dst_ip, src_port, dst_port); -+ } -+ } -+} -+ -+// if process 0, add directly, else transfer 'src_ip,dst_ip,src_port,dst_port,queue_id' to process 0. -+void transfer_create_rule_info_to_process0(uint16_t queue_id, uint32_t src_ip, -+ uint32_t dst_ip, uint16_t src_port, -+ uint16_t dst_port) -+{ -+ char process_server_path[CREATE_FLOWS_PARAMS_LENGTH]; -+ /* exchage src_ip and dst_ip, src_port and dst_port */ -+ uint8_t process_idx = get_global_cfg_params()->process_idx; -+ sprintf_s(process_server_path, CREATE_FLOWS_PARAMS_LENGTH, "%u%s%u%s%u%s%u%s%u%s%u", -+ dst_ip, SPLIT_DELIM, src_ip, SPLIT_DELIM, -+ dst_port, SPLIT_DELIM, src_port, SPLIT_DELIM, -+ queue_id, SPLIT_DELIM, process_idx); -+ int ret = transfer_pkt_to_other_process(process_server_path, 0, CREATE_FLOWS_PARAMS_LENGTH, true); -+ if (ret != TRANSFER_SUCESS) { -+ LSTACK_LOG(ERR, LSTACK, "error. tid %d. src_ip %u, dst_ip %u, src_port: %u, dst_port %u," -+ "queue_id %u, process_idx %u\n", -+ rte_gettid(), src_ip, dst_ip, src_port, dst_port, queue_id, process_idx); -+ } -+} -+ -+void transfer_add_or_delete_listen_port_to_process0(uint16_t listen_port, uint8_t process_idx, uint8_t is_add) -+{ -+ char process_server_path[ADD_OR_DELETE_LISTEN_PORT_PARAMS_LENGTH]; -+ sprintf_s(process_server_path, ADD_OR_DELETE_LISTEN_PORT_PARAMS_LENGTH, -+ "%u%s%u%s%u", listen_port, SPLIT_DELIM, process_idx, SPLIT_DELIM, is_add); -+ int ret = transfer_pkt_to_other_process(process_server_path, 0, ADD_OR_DELETE_LISTEN_PORT_PARAMS_LENGTH, true); -+ if (ret != TRANSFER_SUCESS) { -+ LSTACK_LOG(ERR, LSTACK, "error. tid %d. listen_port %u, process_idx %u\n", -+ rte_gettid(), listen_port, process_idx); -+ } -+} -+ -+static int str_to_array(char *args, uint32_t *array, int size) -+{ -+ int val; -+ uint16_t cnt = 0; -+ char *elem = NULL; -+ char *next_token = NULL; -+ -+ memset_s(array, sizeof(*array) * size, 0, sizeof(*array) * size); -+ elem = strtok_s((char *)args, SPLIT_DELIM, &next_token); -+ while (elem != NULL) { -+ if (cnt >= size) { -+ return -1; -+ } -+ val = atoi(elem); -+ if (val < 0) { -+ return -1; -+ } -+ array[cnt] = (uint32_t)val; -+ cnt++; -+ -+ elem = strtok_s(NULL, SPLIT_DELIM, &next_token); -+ } -+ -+ return cnt; -+} -+ -+static void parse_and_delete_rule(char* buf) -+{ -+ uint32_t array[DELETE_FLOWS_PARAMS_NUM]; -+ str_to_array(buf, array, DELETE_FLOWS_PARAMS_NUM); -+ uint32_t dst_ip = array[0]; -+ uint16_t src_port = array[1]; -+ uint16_t dst_port = array[2]; -+ delete_flow_director(dst_ip, src_port, dst_port); -+} -+ -+void add_user_process_port(uint16_t dst_port, uint8_t process_idx, enum port_type type) -+{ -+ if (type == PORT_LISTEN) { -+ g_listen_ports[dst_port] = process_idx; -+ } else { -+ g_user_ports[dst_port] = process_idx; -+ } -+} -+ -+void delete_user_process_port(uint16_t dst_port, enum port_type type) -+{ -+ if (type == PORT_LISTEN) { -+ g_listen_ports[dst_port] = INVAILD_PROCESS_IDX; -+ } else { -+ g_user_ports[dst_port] = INVAILD_PROCESS_IDX; -+ } -+} -+ -+static void parse_and_create_rule(char* buf) -+{ -+ uint32_t array[CREATE_FLOWS_PARAMS_NUM]; -+ str_to_array(buf, array, CREATE_FLOWS_PARAMS_NUM); -+ uint32_t src_ip = array[0]; -+ uint32_t dst_ip = array[1]; -+ uint16_t src_port = array[2]; -+ uint16_t dst_port = array[3]; -+ uint16_t queue_id = array[4]; -+ uint8_t process_idx = array[5]; -+ config_flow_director(queue_id, src_ip, dst_ip, src_port, dst_port); -+ add_user_process_port(dst_port, process_idx, PORT_CONNECT); -+} -+ -+static void parse_and_add_or_delete_listen_port(char* buf) -+{ -+ uint32_t array[ADD_OR_DELETE_LISTEN_PORT_PARAMS_NUM]; -+ str_to_array(buf, array, ADD_OR_DELETE_LISTEN_PORT_PARAMS_NUM); -+ uint16_t listen_port = array[0]; -+ uint8_t process_idx = array[1]; -+ uint8_t is_add = array[2]; -+ if (is_add == 1) { -+ add_user_process_port(listen_port, process_idx, PORT_LISTEN); -+ } else { -+ delete_user_process_port(listen_port, PORT_LISTEN); -+ } -+} -+ -+void transfer_arp_to_other_process(struct rte_mbuf *mbuf) -+{ -+ struct cfg_params *cfgs = get_global_cfg_params(); -+ -+ for (int i = 1; i < cfgs->num_process; i++) { -+ char arp_mbuf[LSTACK_MBUF_LEN] = {0}; -+ sprintf_s(arp_mbuf, sizeof(arp_mbuf), "%lu", mbuf); -+ int result = transfer_pkt_to_other_process(arp_mbuf, i, LSTACK_MBUF_LEN, false); -+ if (result == CONNECT_ERROR) { -+ LSTACK_LOG(INFO, LSTACK,"connect process %d failed, ensure the process is started.\n", i); -+ } else if (result == REPLY_ERROR) { -+ LSTACK_LOG(ERR, LSTACK,"transfer arp pakages to process %d error. %m\n", i); -+ } -+ } -+} -+ -+static void transfer_tcp_to_thread(struct rte_mbuf *mbuf, uint16_t stk_idx) -+{ -+ /* current process queue_id */ -+ struct protocol_stack *stack = get_protocol_stack_group()->stacks[stk_idx]; -+ int ret = -1; -+ while (ret != 0) { -+ ret = rpc_call_arp(&stack->rpc_queue, mbuf); -+ printf("transfer_tcp_to_thread, ret : %d \n", ret); -+ } -+} -+ -+static void parse_arp_and_transefer(char* buf) -+{ -+ struct rte_mbuf *mbuf = (struct rte_mbuf *)atoll(buf); -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ struct rte_mbuf *mbuf_copy = NULL; -+ struct protocol_stack *stack = NULL; -+ int32_t ret; -+ for (int32_t i = 0; i < stack_group->stack_num; i++) { -+ stack = stack_group->stacks[i]; -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, false); -+ while (ret != 0) { -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, false); -+ stack->stats.rx_allocmbuf_fail++; -+ } -+ copy_mbuf(mbuf_copy, mbuf); -+ -+ ret = rpc_call_arp(&stack->rpc_queue, mbuf_copy); -+ -+ while (ret != 0) { -+ rpc_call_arp(&stack->rpc_queue, mbuf_copy); -+ } -+ } -+} -+ -+static void parse_tcp_and_transefer(char* buf) -+{ -+ char *next_token = NULL; -+ char *elem = strtok_s(buf, SPLIT_DELIM, &next_token); -+ struct rte_mbuf *mbuf = (struct rte_mbuf *) atoll(elem); -+ elem = strtok_s(NULL, SPLIT_DELIM, &next_token); -+ uint16_t queue_id = atoll(elem); -+ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ uint16_t num_queue = get_global_cfg_params()->num_queue; -+ uint16_t stk_index = queue_id % num_queue; -+ struct rte_mbuf *mbuf_copy = NULL; -+ struct protocol_stack *stack = stack_group->stacks[stk_index]; -+ -+ int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, false); -+ while (ret != 0) { -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, false); -+ stack->stats.rx_allocmbuf_fail++; -+ } -+ -+ copy_mbuf(mbuf_copy,mbuf); -+ transfer_tcp_to_thread(mbuf_copy, stk_index); -+} -+ -+int recv_pkts_from_other_process(int process_index, void* arg) -+{ -+ struct sockaddr_un serun, cliun; -+ socklen_t cliun_len; -+ int listenfd, connfd, size; -+ char buf[132]; -+ /* socket */ -+ if ((listenfd = posix_api->socket_fn(AF_UNIX, SOCK_STREAM, 0)) < 0) { -+ perror("socket error"); -+ return -1; -+ } -+ /* bind */ -+ memset_s(&serun, sizeof(serun), 0, sizeof(serun)); -+ serun.sun_family = AF_UNIX; -+ char process_server_path[PATH_MAX]; -+ sprintf_s(process_server_path, sizeof(process_server_path), "%s%d", SERVER_PATH, process_index); -+ strcpy_s(serun.sun_path, sizeof(serun.sun_path), process_server_path); -+ size = offsetof(struct sockaddr_un, sun_path) + strlen(serun.sun_path); -+ unlink(process_server_path); -+ if (posix_api->bind_fn(listenfd, (struct sockaddr *)&serun, size) < 0) { -+ perror("bind error"); -+ return -1; -+ } -+ if (posix_api->listen_fn(listenfd, 20) < 0) { /* 20: max backlog */ -+ perror("listen error"); -+ return -1; -+ } -+ sem_post((sem_t *)arg); -+ /* block */ -+ while (1) { -+ cliun_len = sizeof(cliun); -+ if ((connfd = posix_api->accept_fn(listenfd, (struct sockaddr *)&cliun, &cliun_len)) < 0) { -+ perror("accept error"); -+ continue; -+ } -+ while (1) { -+ int n = posix_api->read_fn(connfd, buf, sizeof(buf)); -+ if (n < 0) { -+ perror("read error"); -+ break; -+ } else if (n == 0) { -+ break; -+ } -+ -+ if (n == LSTACK_MBUF_LEN) { -+ /* arp */ -+ parse_arp_and_transefer(buf); -+ } else if (n == TRANSFER_TCP_MUBF_LEN) { -+ /* tcp. lstack_mbuf_queue_id */ -+ parse_tcp_and_transefer(buf); -+ } else if (n == DELETE_FLOWS_PARAMS_LENGTH) { -+ /* delete rule */ -+ parse_and_delete_rule(buf); -+ } else if (n == CREATE_FLOWS_PARAMS_LENGTH) { -+ /* add rule */ -+ parse_and_create_rule(buf); -+ char reply_buf[REPLY_LEN]; -+ sprintf_s(reply_buf, sizeof(reply_buf), "%s", SUCCESS_REPLY); -+ posix_api->write_fn(connfd, reply_buf, REPLY_LEN); -+ } else if (n == GET_LSTACK_NUM) { -+ char reply_buf[REPLY_LEN]; -+ sprintf_s(reply_buf, sizeof(reply_buf), "%d", get_global_cfg_params()->num_cpu); -+ posix_api->write_fn(connfd, reply_buf, REPLY_LEN); -+ } else { -+ /* add port */ -+ parse_and_add_or_delete_listen_port(buf); -+ char reply_buf[REPLY_LEN]; -+ sprintf_s(reply_buf, sizeof(reply_buf), "%s", SUCCESS_REPLY); -+ posix_api->write_fn(connfd, reply_buf, REPLY_LEN); -+ } -+ -+ } -+ posix_api->close_fn(connfd); -+ } -+ posix_api->close_fn(listenfd); -+ return 0; -+} -+ -+void concat_mbuf_and_queue_id(struct rte_mbuf *mbuf, uint16_t queue_id, -+ char* mbuf_and_queue_id, int write_len) -+{ -+ sprintf_s(mbuf_and_queue_id, write_len, "%lu%s%u", mbuf, SPLIT_DELIM, queue_id); -+} -+ -+static int mbuf_to_idx(struct rte_mbuf *mbuf, uint16_t *dst_port) -+{ -+ struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr *); -+ u16_t type = rte_be_to_cpu_16(ethh->ether_type); -+ uint32_t index = 0; -+ if (type == RTE_ETHER_TYPE_IPV4) { -+ struct rte_ipv4_hdr *iph = rte_pktmbuf_mtod_offset(mbuf, struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr)); -+ uint8_t ip_version = (iph->version_ihl & 0xf0) >> IPV4_VERSION_OFFSET; -+ if (likely(ip_version == IPV4_VERSION)) { -+ if (likely(iph->next_proto_id == IPPROTO_TCP)) { -+ struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(mbuf, struct rte_tcp_hdr *, -+ sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr)); -+ *dst_port = tcp_hdr->dst_port; -+ -+ if (unlikely(tcp_hdr->tcp_flags == TCP_SYN)) { -+ uint32_t src_ip = iph->src_addr; -+ uint16_t src_port = tcp_hdr->src_port; -+ index = rte_jhash_3words(src_ip, src_port | ((*dst_port) << 16), 0, 0); -+ } else { -+ return -1; -+ } -+ } -+ } -+ } else if (type == RTE_ETHER_TYPE_IPV6) { -+ struct rte_ipv6_hdr *iph = rte_pktmbuf_mtod_offset(mbuf, struct rte_ipv6_hdr *, sizeof(struct rte_ether_hdr)); -+ if (likely(iph->proto == IPPROTO_TCP)) { -+ struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(mbuf, struct rte_tcp_hdr *, -+ sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv6_hdr)); -+ *dst_port = tcp_hdr->dst_port; -+ -+ if (unlikely(tcp_hdr->tcp_flags == TCP_SYN)) { -+ uint32_t *src_ip = (uint32_t *) &iph->src_addr; -+ uint16_t src_port = tcp_hdr->src_port; -+ uint32_t v = rte_jhash_3words(src_ip[0], src_ip[1], src_ip[2], 0); -+ index = rte_jhash_3words(src_ip[3], src_port | ((*dst_port) << 16), v, 0); -+ } else { -+ return -1; -+ } -+ } -+ } else { -+ return -1; -+ } -+ return index; -+} -+ -+int distribute_pakages(struct rte_mbuf *mbuf) -+{ -+ uint16_t dst_port = 0; -+ uint32_t index = mbuf_to_idx(mbuf, &dst_port); -+ if (index == -1) { -+ return TRANSFER_CURRENT_THREAD; -+ } -+ -+ uint16_t queue_id = 0; -+ uint32_t user_process_idx = 0; -+ int each_process_queue_num = get_global_cfg_params()->num_queue; -+ index = index % each_process_queue_num; -+ if (g_listen_ports[dst_port] != INVAILD_PROCESS_IDX) { -+ user_process_idx = g_listen_ports[dst_port]; -+ } else { -+ user_process_idx = g_user_ports[dst_port]; -+ } -+ -+ if (user_process_idx == INVAILD_PROCESS_IDX) { -+ 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; -+ } -+ if (queue_id != 0) { -+ if (user_process_idx == 0) { -+ transfer_tcp_to_thread(mbuf, queue_id); -+ } else { -+ char mbuf_and_queue_id[TRANSFER_TCP_MUBF_LEN]; -+ concat_mbuf_and_queue_id(mbuf, queue_id, mbuf_and_queue_id, TRANSFER_TCP_MUBF_LEN); -+ transfer_pkt_to_other_process(mbuf_and_queue_id, user_process_idx, -+ TRANSFER_TCP_MUBF_LEN, false); -+ } -+ return TRANSFER_OTHER_THREAD; -+ } else { -+ return TRANSFER_CURRENT_THREAD; -+ } -+ -+ return TRANSFER_KERNEL; -+} -+ -+void gazelle_listen_thread(void *arg) -+{ -+ struct cfg_params *cfg_param = get_global_cfg_params(); -+ recv_pkts_from_other_process(cfg_param->process_idx, arg); -+} -+ -+void flow_init(void) -+{ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ init_listen_and_user_ports(); -+ -+ /* run to completion mode does not currently support multiple process */ -+ if (!use_ltran() && !get_global_cfg_params()->stack_mode_rtc) { -+ char name[PATH_MAX]; -+ sem_init(&stack_group->sem_listen_thread, 0, 0); -+ sprintf_s(name, sizeof(name), "%s", "listen_thread"); -+ struct sys_thread *thread = sys_thread_new(name, gazelle_listen_thread, -+ (void*)(&stack_group->sem_listen_thread), 0, 0); -+ free(thread); -+ sem_wait(&stack_group->sem_listen_thread); -+ } -+} -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index f78e48a..3703092 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -33,6 +33,7 @@ - #include "lstack_protocol_stack.h" - #include "gazelle_reg_msg.h" - #include "lstack_lwip.h" -+#include "lstack_flow.h" - #include "lstack_vdev.h" - - /* INUSE_TX_PKTS_WATERMARK < VDEV_RX_QUEUE_SZ; --- -2.27.0 - diff --git a/0138-fix-coreddump-when-stack-setup-failed-in-rtc-mode.patch b/0138-fix-coreddump-when-stack-setup-failed-in-rtc-mode.patch deleted file mode 100644 index 1e4c1929b0018ee419d00d56c88257c76657b5e2..0000000000000000000000000000000000000000 --- a/0138-fix-coreddump-when-stack-setup-failed-in-rtc-mode.patch +++ /dev/null @@ -1,66 +0,0 @@ -From 52fafeafd51ed5363081064076dff4ed276a99c1 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Thu, 22 Feb 2024 21:22:44 +0800 -Subject: [PATCH] fix coreddump when stack setup failed in rtc mode - ---- - src/lstack/api/lstack_rtc_api.c | 6 +++--- - src/lstack/core/lstack_init.c | 11 +++++------ - 2 files changed, 8 insertions(+), 9 deletions(-) - -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index d29e51e..2e10e30 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -45,7 +45,7 @@ int rtc_socket(int domain, int type, int protocol) - int ret; - - if (stack_setup_app_thread() < 0) { -- LSTACK_EXIT(1, "stack_setup_app_thread failed!\n"); -+ exit(1); - } - - /* need call stack thread init function */ -@@ -74,7 +74,7 @@ int rtc_shutdown(int fd, int how) - int rtc_epoll_create(int flags) - { - if (stack_setup_app_thread() < 0) { -- LSTACK_EXIT(1, "stack_setup_app_thread failed!\n"); -+ exit(1); - } - - return lstack_epoll_create(flags); -@@ -83,7 +83,7 @@ int rtc_epoll_create(int flags) - int rtc_epoll_create1(int flags) - { - if (stack_setup_app_thread() < 0) { -- LSTACK_EXIT(1, "stack_setup_app_thread failed!\n"); -+ exit(1); - } - - return lstack_epoll_create1(flags); -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 31fd91d..bd9ba8a 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -109,12 +109,11 @@ static int32_t check_process_conflict(void) - - void gazelle_exit(void) - { -- if (!get_global_cfg_params()->stack_mode_rtc) { -- wrap_api_set_dummy(); -- /* 1: wait until app thread call send functio complete */ -- sleep(1); -- stack_group_exit(); -- } -+ wrap_api_set_dummy(); -+ /* 1: wait until app thread call send functio complete */ -+ sleep(1); -+ stack_group_exit(); -+ - if (!use_ltran()) { - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - dpdk_kni_release(); --- -2.27.0 - diff --git a/0139-diff-udp-and-tcp-read-from-stack.patch b/0139-diff-udp-and-tcp-read-from-stack.patch deleted file mode 100644 index ff642fe9660eb7ce24a02b108ba2c2d82f06cdb3..0000000000000000000000000000000000000000 --- a/0139-diff-udp-and-tcp-read-from-stack.patch +++ /dev/null @@ -1,277 +0,0 @@ -From 472e2f00b3fda7dad4396704fd94715d91be4642 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 21 Feb 2024 04:25:43 +0800 -Subject: [PATCH] diff udp and tcp read from stack - ---- - src/lstack/core/lstack_lwip.c | 211 +++++++++++++++++++++++----------- - 1 file changed, 146 insertions(+), 65 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 50a3389..0b339fe 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -831,74 +831,96 @@ static struct pbuf *pbuf_free_partial(struct pbuf *pbuf, uint16_t free_len) - return pbuf; - } - --ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags, -- struct sockaddr *addr, socklen_t *addrlen) -+static bool recv_break_for_err(struct lwip_sock *sock) - { -- size_t recv_left = len; -- struct pbuf *pbuf = NULL; -- ssize_t recvd = 0; -- uint32_t copy_len; -- struct lwip_sock *sock = get_socket_by_fd(fd); -- bool latency_enable = get_protocol_stack_group()->latency_start; -- -- if (sock->errevent > 0 && !NETCONN_IS_DATAIN(sock)) { -- errno = err_to_errno(netconn_err(sock->conn)); -- return -1; -- } -+ bool break_wait = (sock->errevent > 0) && (!NETCONN_IS_DATAIN(sock)); -+ errno = err_to_errno(netconn_err(sock->conn)); -+ return break_wait; -+} - -- thread_bind_stack(sock); -+static void recv_block_wait(struct lwip_sock *sock) -+{ -+ lstack_block_wait(sock->wakeup); -+} - -- if (sock->same_node_rx_ring != NULL) { -- return gazelle_same_node_ring_recv(sock, buf, len, flags); -+/* -+ * return 0 on success, -1 on error -+ * pbuf maybe NULL(tcp fin packet) -+ */ -+static int recv_ring_get_one(struct lwip_sock *sock, bool noblock, struct pbuf **pbuf) -+{ -+ if (sock->recv_lastdata != NULL) { -+ *pbuf = sock->recv_lastdata; -+ sock->recv_lastdata = NULL; -+ return 0; - } - -- while (recv_left > 0) { -- if (sock->recv_lastdata) { -- pbuf = sock->recv_lastdata; -- sock->recv_lastdata = NULL; -+ if (noblock) { -+ if (gazelle_ring_read(sock->recv_ring, (void **)pbuf, 1) != 1) { -+ errno = EAGAIN; -+ return -1; - } else { -- if (netconn_is_nonblocking(sock->conn)) { -- if (gazelle_ring_read(sock->recv_ring, (void **)&pbuf, 1) != 1) { -- break; -- } -- } else { -- while (gazelle_ring_read(sock->recv_ring, (void **)&pbuf, 1) != 1 && recvd == 0) { -- /* if the connection is disconnected, recv return 0 */ -- if (sock->errevent > 0 && !NETCONN_IS_DATAIN(sock)) { -- errno = err_to_errno(netconn_err(sock->conn)); -- return -1; -- } -- -- lstack_block_wait(sock->wakeup); -- } -+ return 0; -+ } -+ } else { -+ while (gazelle_ring_read(sock->recv_ring, (void **)pbuf, 1) != 1) { -+ if (recv_break_for_err(sock)) { -+ return -1; - } -+ recv_block_wait(sock); - } -+ return 0; -+ } -+} - -- /* if udp recv a packet whose len is 0, return 0 */ -- if (NETCONN_IS_UDP(sock) && pbuf->tot_len == 0) { -- return 0; -+/* return true: fin is read to user, false: pend fin */ -+static bool recv_ring_handle_fin(struct lwip_sock *sock, struct pbuf *pbuf, ssize_t recvd) -+{ -+ if (pbuf == NULL) { -+ if (recvd > 0) { -+ /* handle data first, then handle fin */ -+ sock->recv_lastdata = (void *)&fin_packet; -+ gazelle_ring_read_over(sock->recv_ring); -+ return false; - } -+ gazelle_ring_read_over(sock->recv_ring); -+ return true; -+ } -+ /* pending fin */ -+ if (pbuf == (void *)&fin_packet) { -+ return true; -+ } - -- /* fin */ -- if (unlikely(pbuf == NULL)) { -- if (recvd > 0) { -- /* read data first, then read fin */ -- sock->recv_lastdata = (void *)&fin_packet; -- gazelle_ring_read_over(sock->recv_ring); -- break; -- } -- gazelle_ring_read_over(sock->recv_ring); -- return 0; -+ return false; -+} -+ -+static ssize_t recv_ring_tcp_read(struct lwip_sock *sock, void *buf, size_t len, bool noblock) -+{ -+ ssize_t recvd = 0; -+ size_t recv_left = len; -+ uint32_t copy_len; -+ struct pbuf *pbuf = NULL; -+ -+ if (len == 0) { -+ return 0; -+ } -+ -+ while (recv_left > 0) { -+ if (recv_ring_get_one(sock, noblock, &pbuf) != 0) { -+ break; - } - -- /* pending fin */ -- if (unlikely(pbuf == (void *)&fin_packet)) { -- return 0; -+ if (unlikely((pbuf == NULL) || (pbuf == (void *)&fin_packet))) { -+ if (recv_ring_handle_fin(sock, pbuf, recvd)) { -+ return 0; -+ } else { -+ break; /* recvd > 0, pending fin, handle data */ -+ } - } - - copy_len = (recv_left > pbuf->tot_len) ? pbuf->tot_len : recv_left; - if (copy_len > UINT16_MAX) { -- copy_len = UINT16_MAX; -+ copy_len = UINT16_MAX; /* it's impossible to get here */ - } - pbuf_copy_partial(pbuf, (char *)buf + recvd, copy_len, 0); - -@@ -907,39 +929,98 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - - if (pbuf->tot_len > copy_len) { - sock->recv_lastdata = pbuf_free_partial(pbuf, copy_len); -- break; - } else { - if (sock->wakeup) { - sock->wakeup->stat.app_read_cnt += 1; - } -- if (latency_enable) { -+ -+ if (get_protocol_stack_group()->latency_start) { - calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK); - } -- gazelle_ring_read_over(sock->recv_ring); - -- /* in udp, if pbuf remaining len less than copy_len, discard these packets */ -- if (recvd > 0 && NETCONN_IS_UDP(sock)) { -- sock->stack->stats.sock_rx_drop++; -- break; -- } -+ gazelle_ring_read_over(sock->recv_ring); - } - } - -- /* rte_ring_count reduce lock */ -- if (sock->wakeup && sock->wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLIN) -- && (!NETCONN_IS_DATAIN(sock))) { -- del_sock_event(sock, EPOLLIN); -+ if (recvd > 0) { -+ errno = 0; -+ } else { -+ recvd = -1; - } - -+ return recvd; -+} -+ -+static ssize_t recv_ring_udp_read(struct lwip_sock *sock, void *buf, size_t len, bool noblock, -+ struct sockaddr *addr, socklen_t *addrlen) -+{ -+ size_t recv_left = len; -+ struct pbuf *pbuf = NULL; -+ uint32_t copy_len; -+ -+ sock->recv_lastdata = NULL; -+ -+ if (recv_ring_get_one(sock, noblock, &pbuf) != 0) { -+ /* errno have set */ -+ return -1; -+ } -+ -+ copy_len = (recv_left > pbuf->tot_len) ? pbuf->tot_len : recv_left; -+ pbuf_copy_partial(pbuf, (char *)buf, copy_len, 0); -+ /* drop remaining data if have */ -+ gazelle_ring_read_over(sock->recv_ring); -+ - if (pbuf && addr && addrlen) { - lwip_sock_make_addr(sock->conn, &(pbuf->addr), pbuf->port, addr, addrlen); - } - -- if (recvd == 0) { -+ if (copy_len < pbuf->tot_len) { -+ sock->stack->stats.sock_rx_drop++; -+ } -+ -+ if (sock->wakeup) { -+ sock->wakeup->stat.app_read_cnt++; -+ } -+ if (get_protocol_stack_group()->latency_start) { -+ calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK); -+ } -+ -+ return copy_len; -+} -+ -+ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags, -+ struct sockaddr *addr, socklen_t *addrlen) -+{ -+ ssize_t recvd = 0; -+ struct lwip_sock *sock = get_socket_by_fd(fd); -+ -+ if (recv_break_for_err(sock)) { -+ return -1; -+ } -+ -+ thread_bind_stack(sock); -+ -+ if (sock->same_node_rx_ring != NULL) { -+ return gazelle_same_node_ring_recv(sock, buf, len, flags); -+ } -+ -+ if (NETCONN_IS_UDP(sock)) { -+ recvd = recv_ring_udp_read(sock, buf, len, netconn_is_nonblocking(sock->conn), addr, addrlen); -+ } else { -+ recvd = recv_ring_tcp_read(sock, buf, len, netconn_is_nonblocking(sock->conn)); -+ } -+ -+ /* rte_ring_count reduce lock */ -+ if (sock->wakeup && sock->wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLIN) -+ && (!NETCONN_IS_DATAIN(sock))) { -+ del_sock_event(sock, EPOLLIN); -+ } -+ -+ if (recvd < 0) { - if (sock->wakeup) { - sock->wakeup->stat.read_null++; - } -- GAZELLE_RETURN(EAGAIN); -+ return -1; - } - return recvd; - } --- -2.27.0 - diff --git a/0140-FAULT-INJECT-gazelle-add-packet-delay-and-packet-dro.patch b/0140-FAULT-INJECT-gazelle-add-packet-delay-and-packet-dro.patch deleted file mode 100644 index cb42a610d7b4b4d17ef04c1d21a499d7e5ac974b..0000000000000000000000000000000000000000 --- a/0140-FAULT-INJECT-gazelle-add-packet-delay-and-packet-dro.patch +++ /dev/null @@ -1,798 +0,0 @@ -From f28b880f3be68377003c60005011a835eb18e105 Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Sun, 18 Feb 2024 17:11:05 +0800 -Subject: [PATCH] FAULT INJECT: gazelle add packet delay and packet drop - ---- - src/common/gazelle_dfx_msg.h | 15 ++ - src/common/gazelle_fault_inject_common.h | 75 +++++++ - src/lstack/Makefile | 5 + - src/lstack/core/lstack_control_plane.c | 13 +- - src/lstack/include/lstack_fault_inject.h | 20 ++ - src/lstack/include/lstack_vdev.h | 1 + - src/lstack/netif/dir.mk | 3 + - src/lstack/netif/lstack_fault_inject.c | 187 ++++++++++++++++ - src/lstack/netif/lstack_vdev.c | 2 +- - src/ltran/CMakeLists.txt | 5 + - src/ltran/ltran_dfx.c | 274 ++++++++++++++++++++++- - 11 files changed, 595 insertions(+), 5 deletions(-) - create mode 100644 src/common/gazelle_fault_inject_common.h - create mode 100644 src/lstack/include/lstack_fault_inject.h - create mode 100644 src/lstack/netif/lstack_fault_inject.c - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 7f8422a..8d528d6 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -18,6 +18,10 @@ - - #include - -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+#include "gazelle_fault_inject_common.h" -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ -+ - #define GAZELLE_CLIENT_NUM_MIN 1 - #define GAZELLE_LOG_LEVEL_MAX 10 - #define GAZELLECTL_TIMEOUT 5000 // millisecond -@@ -54,6 +58,11 @@ enum GAZELLE_STAT_MODE { - GAZELLE_STAT_LSTACK_SHOW_AGGREGATE, - GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES, - -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+ GAZELLE_STAT_FAULT_INJECT_SET, -+ GAZELLE_STAT_FAULT_INJECT_UNSET, -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ -+ - GAZELLE_STAT_MODE_MAX, - }; - -@@ -277,6 +286,9 @@ struct gazelle_stack_dfx_data { - struct gazelle_stat_lstack_snmp snmp; - struct nic_eth_xstats nic_xstats; - struct nic_eth_features nic_features; -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+ struct gazelle_fault_inject_data inject; -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ - } data; - }; - -@@ -307,6 +319,9 @@ struct gazelle_stat_msg_request { - union stat_param { - char log_level[GAZELLE_LOG_LEVEL_MAX]; - uint16_t low_power_mod; -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+ struct gazelle_fault_inject_data inject; -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ - } data; - }; - -diff --git a/src/common/gazelle_fault_inject_common.h b/src/common/gazelle_fault_inject_common.h -new file mode 100644 -index 0000000..3a77f39 ---- /dev/null -+++ b/src/common/gazelle_fault_inject_common.h -@@ -0,0 +1,75 @@ -+/* -+* 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_INJECT_COMMON_H__ -+#define __GAZELLE_INJECT_COMMON_H__ -+ -+#include -+ -+enum GAZELLE_FAULT_INJECT_TYPE { -+ GAZELLE_FAULT_INJECT_TYPE_ERR = 0, -+ GAZELLE_FAULT_INJECT_PACKET_DELAY, -+ GAZELLE_FAULT_INJECT_PACKET_LOSS, -+ GAZELLE_FAULT_INJECT_PACKAET_DUPLICATE, -+ GAZELLE_FAULT_INJECT_PACKET_REORDER, -+ GAZELLE_FAULT_INJECT_TYPE_MAX, -+}; -+ -+enum GAZELLE_FAULT_INJECT_RULE { -+ INJECT_RULE_ERR = 0, -+ /* packet delay rule */ -+ INJECT_DELAY_RANDOM, -+ /* packet loss rule */ -+ INJECT_LOSS_RANDOM, -+ /* packet duplicate */ -+ INJECT_DUPLICATE_RANDOM, -+ /* packet reorder */ -+ INJECT_REORDER_RANDOM, -+}; -+ -+/* fault inject delay: packet delay's time and range, time unit is "ms" */ -+struct delay_data { -+ uint32_t delay_time; -+ uint32_t delay_range; -+}; -+ -+/* fault inject loss: packet loss rate */ -+struct loss_data { -+ double loss_rate; -+ uint32_t loss_sigle_count; -+}; -+ -+/* fault inject duplicate: packet duplicate rate and duplicate count */ -+struct duplicate_data { -+ double duplicate_rate; -+ uint32_t duplicate_sigle_count; -+}; -+ -+/* fault inject reorder: packet reorder rate and reorder count */ -+struct reorder_data { -+ double reorder_rate; -+ uint32_t reorder_sigle_count; -+}; -+ -+struct gazelle_fault_inject_data { -+ int32_t fault_inject_on; -+ enum GAZELLE_FAULT_INJECT_TYPE inject_type; -+ enum GAZELLE_FAULT_INJECT_RULE inject_rule; -+ union { -+ struct delay_data delay; -+ struct loss_data loss; -+ struct duplicate_data duplicate; -+ struct reorder_data reorder; -+ } inject_data; -+}; -+ -+#endif /* __GAZELLE_INJECT_COMMON_H__ */ -diff --git a/src/lstack/Makefile b/src/lstack/Makefile -index df1ddaa..d2c039d 100644 ---- a/src/lstack/Makefile -+++ b/src/lstack/Makefile -@@ -47,6 +47,11 @@ ifeq ($(GAZELLE_COVERAGE_ENABLE), 1) - CFLAGS += -fprofile-arcs -ftest-coverage - endif - -+ifeq ($(GAZELLE_FAULT_INJECT_ENABLE), 1) -+ LDFLAGS += -DGAZELLE_FAULT_INJECT_ENABLE -+ CFLAGS += -DGAZELLE_FAULT_INJECT_ENABLE -+endif -+ - ifeq ($(shell $(CC) -dumpmachine | cut -d"-" -f1), x86_64) - CFLAGS += -mssse3 - endif -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 025291d..783f21c 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -34,6 +34,10 @@ - #include "lstack_protocol_stack.h" - #include "lstack_control_plane.h" - -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+#include "lstack_fault_inject.h" -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ -+ - /* intervals between two connection attempts and two registration attempts, in second */ - #define CONNECT_TO_LTRAN_INFINITE (-1) - #define CONNECT_TO_LTRAN_RETRY_INTERVAL 1 -@@ -582,7 +586,14 @@ static int32_t handle_stat_request(int32_t sockfd) - LSTACK_LOG(ERR, LSTACK, "recv wrong stat mode %d\n", (int32_t)msg.stat_mode); - return 0; - } -- -+ -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+ if (msg.stat_mode == GAZELLE_STAT_FAULT_INJECT_SET || -+ msg.stat_mode == GAZELLE_STAT_FAULT_INJECT_UNSET) { -+ return handle_fault_inject_cmd(sockfd, &msg); -+ } -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ -+ - if (msg.stat_mode == GAZELLE_STAT_LSTACK_LOG_LEVEL_SET || - msg.stat_mode == GAZELLE_STAT_LSTACK_LOW_POWER_MDF) { - return handle_proc_cmd(sockfd, &msg); -diff --git a/src/lstack/include/lstack_fault_inject.h b/src/lstack/include/lstack_fault_inject.h -new file mode 100644 -index 0000000..d54f1f2 ---- /dev/null -+++ b/src/lstack/include/lstack_fault_inject.h -@@ -0,0 +1,20 @@ -+/* -+* 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_INJECT_H__ -+#define __GAZELLE_INJECT_H__ -+ -+#include -+ -+int32_t handle_fault_inject_cmd(int32_t sockfd, struct gazelle_stat_msg_request *msg); -+ -+#endif /* __GAZELLE_INJECT_H__ */ -diff --git a/src/lstack/include/lstack_vdev.h b/src/lstack/include/lstack_vdev.h -index 4e5d191..1a8342a 100644 ---- a/src/lstack/include/lstack_vdev.h -+++ b/src/lstack/include/lstack_vdev.h -@@ -18,5 +18,6 @@ struct gazelle_quintuple; - enum reg_ring_type; - void vdev_dev_ops_init(struct lstack_dev_ops *dev_ops); - int vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple); -+uint32_t vdev_tx_xmit(struct protocol_stack *stack, struct rte_mbuf **pkts, uint32_t nr_pkts); - - #endif /* _GAZELLE_VDEV_H_ */ -diff --git a/src/lstack/netif/dir.mk b/src/lstack/netif/dir.mk -index 20fb5d6..1e67734 100644 ---- a/src/lstack/netif/dir.mk -+++ b/src/lstack/netif/dir.mk -@@ -9,4 +9,7 @@ - # See the Mulan PSL v2 for more details. - - SRC = lstack_ethdev.c lstack_vdev.c lstack_flow.c -+ifeq ($(GAZELLE_FAULT_INJECT_ENABLE), 1) -+ SRC += lstack_fault_inject.c -+endif - $(eval $(call register_dir, netif, $(SRC))) -diff --git a/src/lstack/netif/lstack_fault_inject.c b/src/lstack/netif/lstack_fault_inject.c -new file mode 100644 -index 0000000..4daad10 ---- /dev/null -+++ b/src/lstack/netif/lstack_fault_inject.c -@@ -0,0 +1,187 @@ -+/* -+* 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 -+#include -+#include -+ -+#include -+ -+#include "lstack_cfg.h" -+#include "lstack_log.h" -+#include "lstack_vdev.h" -+ -+#define INJECT_MODULO 1000 /* used in modulus operator */ -+#define INJECT_US_TO_MS 1000 /* transefer time unit us to ms */ -+ -+typedef int32_t (*inject_xmit_func)(struct protocol_stack *stack, struct rte_mbuf **pkts, -+ uint32_t nr_pkts, struct gazelle_fault_inject_data data); -+struct inject_tbl { -+ struct gazelle_fault_inject_data inject_data; -+ inject_xmit_func inject_func; -+}; -+static struct inject_tbl g_inject_tbl[GAZELLE_FAULT_INJECT_TYPE_MAX]; -+ -+struct inject_func_tbl { -+ enum GAZELLE_FAULT_INJECT_TYPE type; -+ enum GAZELLE_FAULT_INJECT_RULE rule; -+ inject_xmit_func inject_func; -+}; -+ -+static int32_t inject_packet_delay_random(struct protocol_stack *stack, struct rte_mbuf **pkts, -+ uint32_t nr_pkts, struct gazelle_fault_inject_data data); -+static int32_t inject_packet_loss_random(struct protocol_stack *stack, struct rte_mbuf **pkts, -+ uint32_t nr_pkts, struct gazelle_fault_inject_data data); -+ -+static struct inject_func_tbl g_inject_func_tbl[] = { -+ {GAZELLE_FAULT_INJECT_PACKET_LOSS, INJECT_LOSS_RANDOM, inject_packet_loss_random}, -+ {GAZELLE_FAULT_INJECT_PACKET_DELAY, INJECT_DELAY_RANDOM, inject_packet_delay_random}, -+}; -+ -+static int32_t inject_func_tbl_update() -+{ -+ int32_t func_count = sizeof(g_inject_func_tbl) / sizeof(g_inject_func_tbl[0]); -+ -+ for (int32_t i = 0; i < GAZELLE_FAULT_INJECT_TYPE_MAX; ++i) { -+ if (!g_inject_tbl[i].inject_data.fault_inject_on) { -+ continue; -+ } -+ for (int32_t j = 0; j < func_count; ++j) { -+ if (g_inject_func_tbl[j].type == g_inject_tbl[i].inject_data.inject_type && -+ g_inject_func_tbl[j].rule == g_inject_tbl[i].inject_data.inject_rule) { -+ g_inject_tbl[i].inject_func = g_inject_func_tbl[j].inject_func; -+ } -+ } -+ } -+ return 0; -+} -+ -+static uint32_t inject_tx_xmit(struct protocol_stack *stack, struct rte_mbuf **pkts, uint32_t nr_pkts) -+{ -+ for (int32_t i = 0; i < GAZELLE_FAULT_INJECT_TYPE_MAX; ++i) { -+ if (g_inject_tbl[i].inject_data.fault_inject_on) { -+ int32_t xmit_pkts = 0; -+ xmit_pkts = g_inject_tbl[i].inject_func(stack, pkts, nr_pkts, -+ g_inject_tbl[i].inject_data); -+ if (xmit_pkts == nr_pkts) { -+ continue; -+ } -+ return xmit_pkts; -+ } -+ } -+ if (rte_mbuf_refcnt_read(*pkts) == 1) { -+ return nr_pkts; -+ } -+ return vdev_tx_xmit(stack, pkts, nr_pkts); -+} -+ -+static int32_t inject_strategy_update() -+{ -+ inject_func_tbl_update(); -+ -+ int32_t inject_on = 0; -+ for (int32_t i = 0; i < GAZELLE_FAULT_INJECT_TYPE_MAX; ++i) { -+ if (g_inject_tbl[i].inject_data.fault_inject_on) { -+ inject_on = 1; -+ break; -+ } -+ } -+ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ -+ if (inject_on) { -+ for (uint32_t i = 0; i < stack_group->stack_num; ++i) { -+ struct protocol_stack *stack = stack_group->stacks[i]; -+ stack->dev_ops.tx_xmit = inject_tx_xmit; -+ } -+ return 0; -+ } -+ -+ for (uint32_t i = 0; i < stack_group->stack_num; ++i) { -+ struct protocol_stack *stack = stack_group->stacks[i]; -+ vdev_dev_ops_init(&stack->dev_ops); -+ } -+ -+ return 0; -+} -+ -+static int32_t inject_packet_delay_random(struct protocol_stack *stack, struct rte_mbuf **pkts, -+ uint32_t nr_pkts, struct gazelle_fault_inject_data data) -+{ -+ /* while *pkts->refcnt == 1, other inject type is on, and the packets have been loss. */ -+ if (rte_mbuf_refcnt_read(*pkts) == 1) { -+ return nr_pkts; -+ } -+ int32_t delay_time = data.inject_data.delay.delay_time; -+ int32_t delay_range = data.inject_data.delay.delay_range; -+ int32_t rand_num = rte_rand(); -+ rand_num %= INJECT_MODULO; -+ delay_time += delay_range * rand_num / INJECT_MODULO; -+ rte_delay_us(delay_time * INJECT_US_TO_MS); -+ -+ return nr_pkts; -+} -+ -+static int32_t inject_packet_loss_random(struct protocol_stack *stack, struct rte_mbuf **pkts, -+ uint32_t nr_pkts, struct gazelle_fault_inject_data data) -+{ -+ double loss_rate = data.inject_data.loss.loss_rate; -+ int32_t boundary = (int32_t) (loss_rate * INJECT_MODULO); -+ -+ uint32_t rand_num = rte_rand(); -+ rand_num %= INJECT_MODULO; -+ -+ if (rand_num > boundary) { -+ return nr_pkts; -+ } -+ -+ for (int32_t i = 0; i < nr_pkts; ++i) { -+ rte_pktmbuf_free(pkts[i]); -+ } -+ return nr_pkts; -+} -+ -+int32_t handle_fault_inject_cmd(int32_t sockfd, struct gazelle_stat_msg_request *msg) -+{ -+ struct gazelle_stack_dfx_data rsp = {0}; -+ int32_t ret = 0; -+ -+ ret = memcpy_s(&g_inject_tbl[msg->data.inject.inject_type].inject_data, -+ sizeof(struct gazelle_fault_inject_data), -+ &msg->data.inject, sizeof(struct gazelle_fault_inject_data)); -+ if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "fault inject memcpy_s error, ret = %d", ret); -+ return -1; -+ } -+ -+ inject_strategy_update(); -+ -+ for (int32_t i = 0; i < GAZELLE_FAULT_INJECT_TYPE_MAX; ++i) { -+ ret = memcpy_s(&rsp.data.inject, sizeof(struct gazelle_fault_inject_data), -+ &g_inject_tbl[i].inject_data, sizeof(struct gazelle_fault_inject_data)); -+ if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "fault inject memcpy_s error, ret = %d", ret); -+ return -1; -+ } -+ if (i == GAZELLE_FAULT_INJECT_TYPE_MAX -1) { -+ rsp.eof = 1; -+ } -+ ret = (int32_t) posix_api->write_fn(sockfd, (void *)&rsp, sizeof(rsp)); -+ if (ret <= 0) { -+ LSTACK_LOG(ERR, LSTACK, "write msg from peer failed, errno %d. ret=%d\n", errno, ret); -+ return -1; -+ } -+ } -+ -+ return 0; -+} -+ -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 3703092..107ee8c 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -150,7 +150,7 @@ static uint32_t ltran_tx_xmit(struct protocol_stack *stack, struct rte_mbuf **pk - return sent_pkts; - } - --static uint32_t vdev_tx_xmit(struct protocol_stack *stack, struct rte_mbuf **pkts, uint32_t nr_pkts) -+uint32_t vdev_tx_xmit(struct protocol_stack *stack, struct rte_mbuf **pkts, uint32_t nr_pkts) - { - uint32_t sent_pkts = 0; - -diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt -index f739ceb..a484ae3 100644 ---- a/src/ltran/CMakeLists.txt -+++ b/src/ltran/CMakeLists.txt -@@ -27,6 +27,11 @@ if($ENV{GAZELLE_COVERAGE_ENABLE}) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs") - endif($ENV{GAZELLE_COVERAGE_ENABLE}) - -+if($ENV{GAZELLE_FAULT_INJECT_ENABLE}) -+ message("Enable Fault inject option") -+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGAZELLE_FAULT_INJECT_ENABLE") -+endif($ENV{GAZELLE_FAULT_INJECT_ENABLE}) -+ - execute_process( - COMMAND rpm -qa dpdk - OUTPUT_VARIABLE DPDK_VERSION_FULL -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 344afb2..413bf89 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -60,6 +60,46 @@ static struct gazelle_stat_ltran_total g_last_ltran_total; - static struct gazelle_stat_lstack_total g_last_lstack_total[GAZELLE_MAX_STACK_ARRAY_SIZE]; - static struct gazelle_stack_dfx_data g_last_lstack_data[GAZELLE_MAX_STACK_ARRAY_SIZE]; - -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+#define INJECT_NAME_SIZE 32 -+#define INJECT_RULE_SIZE 32 -+ -+typedef int32_t (*inject_parse_digit_fun)(char*, char*, struct gazelle_stat_msg_request *req_msg); -+static int32_t parse_inject_packet_delay_digit(char *time, char *range, struct gazelle_stat_msg_request *req_msg); -+static int32_t parse_inject_packet_loss_digit(char *rate, char *count, struct gazelle_stat_msg_request *req_msg); -+static int32_t parse_inject_packet_duplicate_digit(char *rate, char *count, struct gazelle_stat_msg_request *req_msg); -+static int32_t parse_inject_packet_reorder_digit(char *rate, char *count, struct gazelle_stat_msg_request *req_msg); -+ -+struct gazelle_fault_inject_type_list { -+ char inject_type_item[INJECT_NAME_SIZE]; -+ enum GAZELLE_FAULT_INJECT_TYPE inject_type_parsed; -+ inject_parse_digit_fun parse_digit_func; -+}; -+ -+static struct gazelle_fault_inject_type_list inject_type_list[] = { -+ {"delay", GAZELLE_FAULT_INJECT_PACKET_DELAY, parse_inject_packet_delay_digit}, -+ {"loss", GAZELLE_FAULT_INJECT_PACKET_LOSS, parse_inject_packet_loss_digit}, -+ {"duplicate", GAZELLE_FAULT_INJECT_PACKAET_DUPLICATE, parse_inject_packet_duplicate_digit}, -+ {"reorder", GAZELLE_FAULT_INJECT_PACKET_REORDER, parse_inject_packet_reorder_digit}, -+}; -+ -+struct gazelle_fault_inject_rule_list { -+ char inject_rule_item[INJECT_RULE_SIZE]; -+ enum GAZELLE_FAULT_INJECT_RULE inject_rule_parsed; -+ enum GAZELLE_FAULT_INJECT_TYPE rule_parse_assit; -+}; -+ -+static struct gazelle_fault_inject_rule_list g_gazelle_fault_inject_rule_list[] = { -+ {"random", INJECT_DELAY_RANDOM, GAZELLE_FAULT_INJECT_PACKET_DELAY}, -+ {"random", INJECT_LOSS_RANDOM, GAZELLE_FAULT_INJECT_PACKET_LOSS}, -+ {"random", INJECT_DUPLICATE_RANDOM, GAZELLE_FAULT_INJECT_PACKAET_DUPLICATE}, -+ {"random", INJECT_REORDER_RANDOM, GAZELLE_FAULT_INJECT_PACKET_REORDER}, -+}; -+ -+static void gazelle_print_fault_inject_set_status(void *buf, const struct gazelle_stat_msg_request *req_msg); -+ -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ -+ - static bool g_use_ltran = false; - - static char* g_unix_prefix; -@@ -95,6 +135,11 @@ static void gazelle_print_lstack_xstats(void *buf, const struct gazelle_stat_msg - static void gazelle_print_lstack_aggregate(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_nic_features(void *buf, const struct gazelle_stat_msg_request *req_msg); - -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+static void gazelle_print_fault_inject_set_status(void *buf, const struct gazelle_stat_msg_request *req_msg); -+static void gazelle_print_fault_inject_unset_status(void *buf, const struct gazelle_stat_msg_request *req_msg); -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ -+ - static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = { - {GAZELLE_STAT_LTRAN_SHOW, sizeof(struct gazelle_stat_ltran_total), gazelle_print_ltran_stat_total}, - {GAZELLE_STAT_LTRAN_SHOW_RATE, sizeof(struct gazelle_stat_ltran_total), gazelle_print_ltran_stat_rate}, -@@ -121,6 +166,11 @@ static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = { - {GAZELLE_STAT_LSTACK_SHOW_XSTATS, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_xstats}, - {GAZELLE_STAT_LSTACK_SHOW_AGGREGATE, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_aggregate}, - {GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_nic_features}, -+ -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+ {GAZELLE_STAT_FAULT_INJECT_SET, sizeof(struct gazelle_stack_dfx_data), gazelle_print_fault_inject_set_status}, -+ {GAZELLE_STAT_FAULT_INJECT_UNSET, sizeof(struct gazelle_stack_dfx_data), gazelle_print_fault_inject_unset_status}, -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ - }; - - static int32_t g_wait_reply = 1; -@@ -1121,7 +1171,10 @@ static void show_usage(void) - { - printf("Usage: gazellectl [-h | help] \n" - " or: gazellectl ltran {quit | show | set} [LTRAN_OPTIONS] [-u UNIX_PREFIX]\n" -- " or: gazellectl lstack {show | set} ip [LSTACK_OPTIONS] [-u UNIX_PREFIX]\n \n" -+ " or: gazellectl lstack {show | set} ip [LSTACK_OPTIONS] [-u UNIX_PREFIX]\n\n" -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+ " or: gazellectl inject [inject_type] [digit_param_1] [digit_param_2] [inject_rule]\n\n" -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ - " quit ltran process exit \n \n" - " where LTRAN_OPTIONS := \n" - " show: \n" -@@ -1146,7 +1199,13 @@ static void show_usage(void) - " set: \n" - " loglevel {error | info | debug} set lstack loglevel \n" - " lowpower {0 | 1} set lowpower enable \n" -- " [time] measure latency time default 1S, maximum 30mins \n"); -+ " [time] measure latency time default 1S, maximum 30mins \n\n" -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+ " *inject params*\n" -+ " |inject_type | digit_param_1 | digit_param_2 | inject_rule |\n" -+ " | delay | delay_time(unit: ms) | delay_range(unit: ms) | random |\n" -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ -+ ); - } - - static int32_t parse_dfx_ltran_set_args(int32_t argc, char *argv[], struct gazelle_stat_msg_request *req_msg) -@@ -1436,6 +1495,211 @@ static int32_t parse_dfx_lstack_args(int32_t argc, char *argv[], struct gazelle_ - return num_cmd; - } - -+ -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+ -+#define GAZELLE_SET_FAULT_INJECT_PARAM_COUNT 6 -+#define GAZELLE_UNSET_FAULT_INJECT_PARAM_COUNT 4 -+#define INJECT_TYPE_INDEX 2 -+#define INJECT_DIGITAL_FIRST_INDEX 3 -+#define INJECT_DIGITAL_SECOND_INDEX 4 -+#define INJECT_RULE_INDEX 5 -+ -+ -+static void gazelle_print_fault_inject_type_info(struct gazelle_fault_inject_data *inject) -+{ -+ if (!inject->fault_inject_on) { -+ return; -+ } -+ -+ if (inject->inject_type == GAZELLE_FAULT_INJECT_PACKET_DELAY) { -+ printf("\t| inject_type: delay | delay_time: %-7d | delay_range: %-3d | " -+ "inject_rule: random |\n", inject->inject_data.delay.delay_time, -+ inject->inject_data.delay.delay_range); -+ } -+ -+#define INJECT_PERCENT 100 -+ -+ if (inject->inject_type == GAZELLE_FAULT_INJECT_PACKET_LOSS) { -+ printf("\t| inject_type: loss | loss_rate: %-3.1f%% | loss_single_count: %-3d | " -+ "inject_rule: random |\n", inject->inject_data.loss.loss_rate * INJECT_PERCENT, -+ inject->inject_data.loss.loss_sigle_count); -+ } -+ printf("\n"); -+} -+ -+static void gazelle_print_fault_inject_set_status(void *buf, const struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t ret; -+ struct gazelle_stack_dfx_data *stat = (struct gazelle_stack_dfx_data *)buf; -+ struct gazelle_fault_inject_data *inject = &stat->data.inject; -+ -+ printf("\n\n\t\t\t\t\t **** FAULT INJECT INFO **** \n\n"); -+ do { -+ gazelle_print_fault_inject_type_info(inject); -+ if (stat->eof != 0) { -+ break; -+ } -+ ret = dfx_stat_read_from_ltran(buf, sizeof(struct gazelle_stack_dfx_data), req_msg->stat_mode); -+ if (ret != GAZELLE_OK) { -+ return; -+ } -+ } while (true); -+} -+ -+static void gazelle_print_fault_inject_unset_status(void *buf, const struct gazelle_stat_msg_request *req_msg) -+{ -+ return; -+} -+ -+static int32_t parse_inject_packet_delay_digit(char* time, char* range, struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t parse_success = 0; -+ int32_t delay_time = atoi(time); -+ if (delay_time <= 0) { -+ printf("FAULT INJECT error: delay time error -- %d, need positive integer.\n", delay_time); -+ return parse_success; -+ } -+ req_msg->data.inject.inject_data.delay.delay_time = (uint32_t) delay_time; -+ -+ int32_t delay_range = atoi(range); -+ if (delay_range < 0) { -+ printf("FAULT INJECT error: delay range error -- %d, need positive integer.\n", delay_range); -+ return parse_success; -+ } -+ if (delay_time - delay_range <= 0) { -+ printf("FAULT INJECT error: delay range should lower than delay time.\n"); -+ return parse_success; -+ } -+ req_msg->data.inject.inject_data.delay.delay_range = delay_range; -+ -+ return ++parse_success; -+} -+ -+#define INJECT_RATE_LOWER 0.001 -+ -+static int32_t parse_inject_packet_loss_digit(char *rate, char *count, struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t parse_success = 0; -+ double loss_rate = atof(rate); -+ if (loss_rate < INJECT_RATE_LOWER || loss_rate >= 1) { -+ printf("FAULT INJECT error: loss rate error, range in [0.001, 1), now is %f\n", loss_rate); -+ return parse_success; -+ } -+ req_msg->data.inject.inject_data.loss.loss_rate = loss_rate; -+ -+ int32_t loss_counts = atoi(count); -+ if (loss_counts <= 0) { -+ printf("FAULT INJECT error: single loss counts wrong --%d, need positive integer.", loss_counts); -+ return parse_success; -+ } -+ req_msg->data.inject.inject_data.loss.loss_sigle_count = loss_counts; -+ -+ return ++parse_success; -+} -+ -+static int32_t parse_inject_packet_duplicate_digit(char *rate, char *count, struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t parse_success = 0; -+ double duplicate_rate = atof(rate); -+ if (duplicate_rate < INJECT_RATE_LOWER || duplicate_rate >= 1) { -+ printf("FAULT INJECT error: duplicate rate error, range in [0.001, 1), now is %f\n", duplicate_rate); -+ return parse_success; -+ } -+ req_msg->data.inject.inject_data.duplicate.duplicate_rate = duplicate_rate; -+ -+ int32_t duplicate_counts = atoi(count); -+ if (duplicate_counts <= 0) { -+ printf("FAULT INJECT error: single duplicate counts wrong --%d, need positive integer.", duplicate_counts); -+ return parse_success; -+ } -+ req_msg->data.inject.inject_data.duplicate.duplicate_sigle_count = duplicate_counts; -+ -+ return ++parse_success; -+} -+ -+static int32_t parse_inject_packet_reorder_digit(char *rate, char *count, struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t parse_success = 0; -+ double reorder_rate = atof(rate); -+ if (reorder_rate < INJECT_RATE_LOWER || reorder_rate >= 1) { -+ printf("FAULT INJECT error: reorder rate error, range in [0.001, 1), now is %f\n", reorder_rate); -+ return parse_success; -+ } -+ req_msg->data.inject.inject_data.reorder.reorder_rate = reorder_rate; -+ -+ int32_t reorder_counts = atoi(count); -+ if (reorder_counts <= 0) { -+ printf("FAULT INJECT error: single duplicate counts wrong --%d, need positive integer.", reorder_counts); -+ return parse_success; -+ } -+ req_msg->data.inject.inject_data.reorder.reorder_sigle_count = reorder_counts; -+ -+ return ++parse_success; -+} -+ -+static int32_t parse_fault_inject_digital_data(char *argv[], struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t parse_success = 0; -+ int32_t func_count = sizeof(inject_type_list) / sizeof(inject_type_list[0]); -+ for (int32_t i = 0; i < func_count; ++i) { -+ if (inject_type_list[i].inject_type_parsed == req_msg->data.inject.inject_type) { -+ parse_success = inject_type_list[i].parse_digit_func(argv[INJECT_DIGITAL_FIRST_INDEX], -+ argv[INJECT_DIGITAL_SECOND_INDEX], req_msg); -+ break; -+ } -+ } -+ -+ return parse_success; -+} -+ -+static int32_t parse_dfx_fault_inject_args(int32_t argc, char *argv[], struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t num_cmd = 0; /* while parse error, num_cmd will return as 0, or num_cmd should be returned as 1. */ -+ -+ req_msg->data.inject.fault_inject_on = 1; /* set fault inject on */ -+ -+ if (argc == GAZELLE_SET_FAULT_INJECT_PARAM_COUNT) { -+ req_msg->stat_mode = GAZELLE_STAT_FAULT_INJECT_SET; -+ } else if (argc == GAZELLE_UNSET_FAULT_INJECT_PARAM_COUNT) { -+ req_msg->stat_mode = GAZELLE_STAT_FAULT_INJECT_UNSET; -+ } else { -+ printf("FAULT_INJECT error: Count of params wrong , correct count is 6 or 4, now is %d\n", argc); -+ return num_cmd; -+ } -+ -+ int32_t inject_type_count = sizeof(inject_type_list) / sizeof(inject_type_list[0]); -+ for (int32_t i = 0; i < inject_type_count; ++i) { -+ if (strcmp(inject_type_list[i].inject_type_item, argv[INJECT_TYPE_INDEX]) == 0) { -+ req_msg->data.inject.inject_type = inject_type_list[i].inject_type_parsed; -+ break; -+ } -+ } -+ if (req_msg->data.inject.inject_type == GAZELLE_FAULT_INJECT_TYPE_ERR) { -+ printf("FAULT_INJECT error: input inject type is wrong -- %s\n", argv[INJECT_TYPE_INDEX]); -+ return num_cmd; -+ } -+ -+ int32_t inject_rule_count = sizeof(g_gazelle_fault_inject_rule_list) / sizeof(g_gazelle_fault_inject_rule_list[0]); -+ for (int32_t i = 0; i < inject_rule_count; ++i) { -+ if (strcmp(g_gazelle_fault_inject_rule_list[i].inject_rule_item, argv[INJECT_RULE_INDEX]) == 0 && -+ g_gazelle_fault_inject_rule_list[i].rule_parse_assit == req_msg->data.inject.inject_type) { -+ req_msg->data.inject.inject_rule = g_gazelle_fault_inject_rule_list[i].inject_rule_parsed; -+ break; -+ } -+ } -+ if (req_msg->data.inject.inject_rule == INJECT_RULE_ERR) { -+ printf("FAULT_INJECT error: input inject rule is wrong -- %s\n", argv[INJECT_RULE_INDEX]); -+ return num_cmd; -+ } -+ -+ num_cmd = parse_fault_inject_digital_data(argv, req_msg); -+ -+ return num_cmd; -+} -+ -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ -+ - static int32_t parse_dfx_cmd_args(int32_t argc, char *argv[], struct gazelle_stat_msg_request *req_msg) - { - int32_t num_cmd = 0; -@@ -1451,7 +1715,11 @@ static int32_t parse_dfx_cmd_args(int32_t argc, char *argv[], struct gazelle_sta - if (strcmp(param, "lstack") == 0) { - num_cmd = parse_dfx_lstack_args(argc, argv, req_msg); - } -- -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+ if (strcmp(param, "inject") == 0) { -+ num_cmd = parse_dfx_fault_inject_args(argc, argv, req_msg); -+ } -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ - return num_cmd; - } - --- -2.27.0 - diff --git a/0141-recv-support-MSG_DONTWAIT.patch b/0141-recv-support-MSG_DONTWAIT.patch deleted file mode 100644 index 403b96ba845177f8eba52b96ad1ef8b9a93b91ac..0000000000000000000000000000000000000000 --- a/0141-recv-support-MSG_DONTWAIT.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 34c272bf7f0484a1371033c187719adc72f061d5 Mon Sep 17 00:00:00 2001 -From: li_yunqing -Date: Tue, 27 Feb 2024 16:58:59 +0800 -Subject: [PATCH] recv support MSG_DONTWAIT - ---- - src/lstack/core/lstack_lwip.c | 5 +++-- - 1 file changed, 3 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 0b339fe..7715cf3 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -993,6 +993,7 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - { - ssize_t recvd = 0; - struct lwip_sock *sock = get_socket_by_fd(fd); -+ bool noblock = (flags & MSG_DONTWAIT) || netconn_is_nonblocking(sock->conn); - - if (recv_break_for_err(sock)) { - return -1; -@@ -1005,9 +1006,9 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - } - - if (NETCONN_IS_UDP(sock)) { -- recvd = recv_ring_udp_read(sock, buf, len, netconn_is_nonblocking(sock->conn), addr, addrlen); -+ recvd = recv_ring_udp_read(sock, buf, len, noblock, addr, addrlen); - } else { -- recvd = recv_ring_tcp_read(sock, buf, len, netconn_is_nonblocking(sock->conn)); -+ recvd = recv_ring_tcp_read(sock, buf, len, noblock); - } - - /* rte_ring_count reduce lock */ --- -2.27.0 - diff --git a/0142-do_setsockopt-function-no-longer-checks-the-results-.patch b/0142-do_setsockopt-function-no-longer-checks-the-results-.patch deleted file mode 100644 index 8a873509da8cbb26596f1028df500774cea334bd..0000000000000000000000000000000000000000 --- a/0142-do_setsockopt-function-no-longer-checks-the-results-.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 712a3c23451ed79449cea9322586d958c27c679f Mon Sep 17 00:00:00 2001 -From: jiangjixiang -Date: Fri, 1 Mar 2024 10:10:01 +0800 -Subject: [PATCH] do_setsockopt function no longer checks the results of the - kernel. - ---- - src/lstack/api/lstack_wrap.c | 5 +---- - 1 file changed, 1 insertion(+), 4 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 8992e39..1e36d3d 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -398,10 +398,7 @@ static inline int32_t do_setsockopt(int32_t s, int32_t level, int32_t optname, c - } - - /* we both set kernel and lwip */ -- int32_t ret = posix_api->setsockopt_fn(s, level, optname, optval, optlen); -- if (ret != 0) { -- return ret; -- } -+ posix_api->setsockopt_fn(s, level, optname, optval, optlen); - - return g_wrap_api->setsockopt_fn(s, level, optname, optval, optlen); - } --- -2.27.0 - diff --git a/0143-FAUT-INJECT-add-fault-inject-unset-method.patch b/0143-FAUT-INJECT-add-fault-inject-unset-method.patch deleted file mode 100644 index 31a8c4b30c9d5b4a66f9fa057bf632c5dd148783..0000000000000000000000000000000000000000 --- a/0143-FAUT-INJECT-add-fault-inject-unset-method.patch +++ /dev/null @@ -1,254 +0,0 @@ -From c2cf2ef0cc9f28a8322e17870d209f546ad6711d Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Mon, 4 Mar 2024 11:15:34 +0800 -Subject: [PATCH] FAUT INJECT: add fault inject unset method - ---- - src/lstack/core/lstack_control_plane.c | 2 +- - src/lstack/include/lstack_fault_inject.h | 2 +- - src/lstack/netif/lstack_fault_inject.c | 60 ++++++++++++---- - src/ltran/ltran_dfx.c | 92 +++++++++++++++++++++--- - 4 files changed, 131 insertions(+), 25 deletions(-) - -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 783f21c..9f0c313 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -590,7 +590,7 @@ static int32_t handle_stat_request(int32_t sockfd) - #ifdef GAZELLE_FAULT_INJECT_ENABLE - if (msg.stat_mode == GAZELLE_STAT_FAULT_INJECT_SET || - msg.stat_mode == GAZELLE_STAT_FAULT_INJECT_UNSET) { -- return handle_fault_inject_cmd(sockfd, &msg); -+ return handle_fault_inject_cmd(sockfd, msg.data.inject, msg.stat_mode); - } - #endif /* GAZELLE_FAULT_INJECT_ENABLE */ - -diff --git a/src/lstack/include/lstack_fault_inject.h b/src/lstack/include/lstack_fault_inject.h -index d54f1f2..afd8faf 100644 ---- a/src/lstack/include/lstack_fault_inject.h -+++ b/src/lstack/include/lstack_fault_inject.h -@@ -15,6 +15,6 @@ - - #include - --int32_t handle_fault_inject_cmd(int32_t sockfd, struct gazelle_stat_msg_request *msg); -+int32_t handle_fault_inject_cmd(int32_t sockfd, struct gazelle_fault_inject_data inject, enum GAZELLE_STAT_MODE stat_mode); - - #endif /* __GAZELLE_INJECT_H__ */ -diff --git a/src/lstack/netif/lstack_fault_inject.c b/src/lstack/netif/lstack_fault_inject.c -index 4daad10..41e7d95 100644 ---- a/src/lstack/netif/lstack_fault_inject.c -+++ b/src/lstack/netif/lstack_fault_inject.c -@@ -150,21 +150,10 @@ static int32_t inject_packet_loss_random(struct protocol_stack *stack, struct rt - return nr_pkts; - } - --int32_t handle_fault_inject_cmd(int32_t sockfd, struct gazelle_stat_msg_request *msg) -+static int32_t inject_respond_msg(int32_t sockfd) - { - struct gazelle_stack_dfx_data rsp = {0}; - int32_t ret = 0; -- -- ret = memcpy_s(&g_inject_tbl[msg->data.inject.inject_type].inject_data, -- sizeof(struct gazelle_fault_inject_data), -- &msg->data.inject, sizeof(struct gazelle_fault_inject_data)); -- if (ret != EOK) { -- LSTACK_LOG(ERR, LSTACK, "fault inject memcpy_s error, ret = %d", ret); -- return -1; -- } -- -- inject_strategy_update(); -- - for (int32_t i = 0; i < GAZELLE_FAULT_INJECT_TYPE_MAX; ++i) { - ret = memcpy_s(&rsp.data.inject, sizeof(struct gazelle_fault_inject_data), - &g_inject_tbl[i].inject_data, sizeof(struct gazelle_fault_inject_data)); -@@ -185,3 +174,50 @@ int32_t handle_fault_inject_cmd(int32_t sockfd, struct gazelle_stat_msg_request - return 0; - } - -+static int32_t inject_unset_cmd(int32_t sockfd, struct gazelle_fault_inject_data inject) -+{ -+ if (inject.inject_type == GAZELLE_FAULT_INJECT_TYPE_MAX) { -+ /* means unset all kinds of fault inject type */ -+ for (int32_t i = 0; i < GAZELLE_FAULT_INJECT_TYPE_MAX; ++i) { -+ g_inject_tbl[i].inject_data.fault_inject_on = 0; -+ } -+ } else { -+ int32_t ret = 0; -+ ret = memcpy_s(&g_inject_tbl[inject.inject_type].inject_data, -+ sizeof(struct gazelle_fault_inject_data), -+ &inject, sizeof(struct gazelle_fault_inject_data)); -+ if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "fault inject memcpy_s error, ret = %d", ret); -+ return -1; -+ } -+ } -+ -+ inject_strategy_update(); -+ -+ return inject_respond_msg(sockfd); -+} -+ -+static int32_t inject_set_cmd(int32_t sockfd, struct gazelle_fault_inject_data inject) -+{ -+ int32_t ret = 0; -+ ret = memcpy_s(&g_inject_tbl[inject.inject_type].inject_data, -+ sizeof(struct gazelle_fault_inject_data), -+ &inject, sizeof(struct gazelle_fault_inject_data)); -+ if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "fault inject memcpy_s error, ret = %d", ret); -+ return -1; -+ } -+ -+ inject_strategy_update(); -+ -+ return inject_respond_msg(sockfd); -+} -+ -+int32_t handle_fault_inject_cmd(int32_t sockfd, struct gazelle_fault_inject_data inject, enum GAZELLE_STAT_MODE stat_mode) -+{ -+ if (stat_mode == GAZELLE_STAT_FAULT_INJECT_UNSET) { -+ return inject_unset_cmd(sockfd, inject); -+ } -+ return inject_set_cmd(sockfd, inject); -+} -+ -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 413bf89..96509e5 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -97,7 +97,7 @@ static struct gazelle_fault_inject_rule_list g_gazelle_fault_inject_rule_list[] - }; - - static void gazelle_print_fault_inject_set_status(void *buf, const struct gazelle_stat_msg_request *req_msg); -- -+static void gazelle_print_fault_inject_unset_status(void *buf, const struct gazelle_stat_msg_request *req_msg); - #endif /* GAZELLE_FAULT_INJECT_ENABLE */ - - static bool g_use_ltran = false; -@@ -1504,6 +1504,7 @@ static int32_t parse_dfx_lstack_args(int32_t argc, char *argv[], struct gazelle_ - #define INJECT_DIGITAL_FIRST_INDEX 3 - #define INJECT_DIGITAL_SECOND_INDEX 4 - #define INJECT_RULE_INDEX 5 -+#define INJECT_UNSET_TYPE_INDEX 3 - - - static void gazelle_print_fault_inject_type_info(struct gazelle_fault_inject_data *inject) -@@ -1549,6 +1550,33 @@ static void gazelle_print_fault_inject_set_status(void *buf, const struct gazell - - static void gazelle_print_fault_inject_unset_status(void *buf, const struct gazelle_stat_msg_request *req_msg) - { -+ int32_t ret; -+ static int32_t inject_enable[GAZELLE_FAULT_INJECT_TYPE_MAX]; -+ struct gazelle_stack_dfx_data *stat = (struct gazelle_stack_dfx_data *)buf; -+ struct gazelle_fault_inject_data *inject = &stat->data.inject; -+ -+ printf("\n\t\t\t\t\t **** INJECT ENABLE ITEM **** \n\n"); -+ do { -+ inject_enable[inject->inject_type] = inject->fault_inject_on; -+ gazelle_print_fault_inject_type_info(inject); -+ if (stat->eof != 0) { -+ break; -+ } -+ ret = dfx_stat_read_from_ltran(buf, sizeof(struct gazelle_stack_dfx_data), req_msg->stat_mode); -+ if (ret != GAZELLE_OK) { -+ return; -+ } -+ } while (true); -+ -+ printf("\n\n\t\t\t\t\t **** INJECT DISABLE ITEM **** \n\n"); -+ printf("\tThe currently closed inject types are: "); -+ for (int32_t i = 1; i < GAZELLE_FAULT_INJECT_TYPE_MAX; ++i) { -+ if (!inject_enable[i]) { -+ /* i - 1 means fault inject type mapping inject_type_item name */ -+ printf("\"%s\" ", inject_type_list[i - 1].inject_type_item); -+ } -+ } -+ printf("\n"); - return; - } - -@@ -1653,21 +1681,45 @@ static int32_t parse_fault_inject_digital_data(char *argv[], struct gazelle_stat - return parse_success; - } - --static int32_t parse_dfx_fault_inject_args(int32_t argc, char *argv[], struct gazelle_stat_msg_request *req_msg) -+static int32_t parse_fault_inject_unset_type(char *argv[], struct gazelle_stat_msg_request *req_msg) - { -- int32_t num_cmd = 0; /* while parse error, num_cmd will return as 0, or num_cmd should be returned as 1. */ -- -- req_msg->data.inject.fault_inject_on = 1; /* set fault inject on */ -+ int32_t num_cmd = 0; -+ -+ if (strcmp(argv[INJECT_TYPE_INDEX], "unset") != 0) { -+ printf("FAULT_INJECT error: unrecognized input -- %s, should be \"unset\"\n", argv[INJECT_TYPE_INDEX]); -+ return num_cmd; -+ } -+ -+ req_msg->data.inject.fault_inject_on = 0; /* unset fault inject */ -+ req_msg->stat_mode = GAZELLE_STAT_FAULT_INJECT_UNSET; -+ -+ if (strcmp(argv[INJECT_UNSET_TYPE_INDEX], "all") == 0) { -+ req_msg->data.inject.inject_type = GAZELLE_FAULT_INJECT_TYPE_MAX; -+ return ++num_cmd; -+ } - -- if (argc == GAZELLE_SET_FAULT_INJECT_PARAM_COUNT) { -- req_msg->stat_mode = GAZELLE_STAT_FAULT_INJECT_SET; -- } else if (argc == GAZELLE_UNSET_FAULT_INJECT_PARAM_COUNT) { -- req_msg->stat_mode = GAZELLE_STAT_FAULT_INJECT_UNSET; -- } else { -- printf("FAULT_INJECT error: Count of params wrong , correct count is 6 or 4, now is %d\n", argc); -+ int32_t inject_type_count = sizeof(inject_type_list) / sizeof(inject_type_list[0]); -+ for (int32_t i = 0; i < inject_type_count; ++i) { -+ if (strcmp(inject_type_list[i].inject_type_item, argv[INJECT_UNSET_TYPE_INDEX]) == 0) { -+ req_msg->data.inject.inject_type = inject_type_list[i].inject_type_parsed; -+ break; -+ } -+ } -+ if (req_msg->data.inject.inject_type == GAZELLE_FAULT_INJECT_TYPE_ERR) { -+ printf("FAULT_INJECT error: input inject type is wrong -- %s\n", argv[INJECT_TYPE_INDEX]); - return num_cmd; - } - -+ return ++num_cmd; -+} -+ -+static int32_t parse_fault_inject_set_type(char *argv[], struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t num_cmd = 0; -+ -+ req_msg->data.inject.fault_inject_on = 1; /* set fault inject on */ -+ req_msg->stat_mode = GAZELLE_STAT_FAULT_INJECT_SET; -+ - int32_t inject_type_count = sizeof(inject_type_list) / sizeof(inject_type_list[0]); - for (int32_t i = 0; i < inject_type_count; ++i) { - if (strcmp(inject_type_list[i].inject_type_item, argv[INJECT_TYPE_INDEX]) == 0) { -@@ -1698,6 +1750,24 @@ static int32_t parse_dfx_fault_inject_args(int32_t argc, char *argv[], struct ga - return num_cmd; - } - -+static int32_t parse_dfx_fault_inject_args(int32_t argc, char *argv[], struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t num_cmd = 0; /* while parse error, num_cmd will return as 0, or num_cmd should be returned as 1. */ -+ -+ if (argc == GAZELLE_UNSET_FAULT_INJECT_PARAM_COUNT) { -+ num_cmd = parse_fault_inject_unset_type(argv, req_msg); -+ return num_cmd; -+ } -+ -+ if (argc == GAZELLE_SET_FAULT_INJECT_PARAM_COUNT) { -+ num_cmd = parse_fault_inject_set_type(argv, req_msg); -+ return num_cmd; -+ } -+ -+ printf("FAULT_INJECT error: Count of params wrong , correct count is 6 or 4, now is %d\n", argc); -+ return num_cmd; -+} -+ - #endif /* GAZELLE_FAULT_INJECT_ENABLE */ - - static int32_t parse_dfx_cmd_args(int32_t argc, char *argv[], struct gazelle_stat_msg_request *req_msg) --- -2.27.0 - diff --git a/0144-support-udp-pkglen-mtu.patch b/0144-support-udp-pkglen-mtu.patch deleted file mode 100644 index c03fd04a95ee4af970265afebdde9992bd5bc25b..0000000000000000000000000000000000000000 --- a/0144-support-udp-pkglen-mtu.patch +++ /dev/null @@ -1,85 +0,0 @@ -From 5ba19529acaf76a681313245a9a278356b615687 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Mon, 4 Mar 2024 14:10:43 +0800 -Subject: [PATCH] support udp pkglen > mtu - ---- - src/lstack/core/lstack_lwip.c | 20 ++++++++++++++++++-- - src/lstack/include/lstack_dpdk.h | 2 +- - 2 files changed, 19 insertions(+), 3 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 7715cf3..f4199f8 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -252,6 +252,13 @@ struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_s - return NULL; - } - -+ /* udp send a pbuf chain, dequeue all pbufs except head pbuf */ -+ if (NETCONN_IS_UDP(sock) && remain_size > MBUF_MAX_DATA_LEN) { -+ int size = (remain_size + MBUF_MAX_DATA_LEN - 1) / MBUF_MAX_DATA_LEN - 1; -+ struct pbuf *pbuf_used[size]; -+ gazelle_ring_sc_dequeue(sock->send_ring, (void **)&pbuf_used, size); -+ } -+ - if (get_protocol_stack_group()->latency_start) { - calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LWIP); - } -@@ -285,7 +292,7 @@ void do_lwip_get_from_sendring_over(struct lwip_sock *sock) - sock->stack->stats.write_lwip_cnt++; - } - --static ssize_t do_app_write(struct pbuf *pbufs[], void *buf, size_t len, uint32_t write_num) -+static ssize_t do_app_write(struct lwip_sock *sock, struct pbuf *pbufs[], void *buf, size_t len, uint32_t write_num) - { - ssize_t send_len = 0; - uint32_t i = 0; -@@ -297,6 +304,11 @@ static ssize_t do_app_write(struct pbuf *pbufs[], void *buf, size_t len, uint32_ - rte_memcpy((char *)pbufs[i]->payload, (char *)buf + send_len, MBUF_MAX_DATA_LEN); - pbufs[i]->tot_len = pbufs[i]->len = MBUF_MAX_DATA_LEN; - send_len += MBUF_MAX_DATA_LEN; -+ -+ /* if udp pkg len > mtu, use pbuf chain to send it */ -+ if (NETCONN_IS_UDP(sock) && i > 0) { -+ pbuf_cat(pbufs[0], pbufs[i]); -+ } - } - - /* reduce the branch in loop */ -@@ -305,6 +317,10 @@ static ssize_t do_app_write(struct pbuf *pbufs[], void *buf, size_t len, uint32_ - pbufs[i]->tot_len = pbufs[i]->len = copy_len; - send_len += copy_len; - -+ if (NETCONN_IS_UDP(sock) && i > 0) { -+ pbuf_cat(pbufs[0], pbufs[i]); -+ } -+ - return send_len; - } - -@@ -320,7 +336,7 @@ static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t l - time_stamp_into_pbuf(write_num, pbufs, time_stamp); - } - -- ssize_t send_len = do_app_write(pbufs, buf, len, write_num); -+ ssize_t send_len = do_app_write(sock, pbufs, buf, len, write_num); - - if (addr) { - if (addr->sa_family == AF_INET) { -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index c40f3c0..c7cfbdf 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -21,7 +21,7 @@ - - #define KNI_NB_MBUF (DEFAULT_RING_SIZE << 4) - --#define MAX_PACKET_SZ 1530 -+#define MAX_PACKET_SZ 1538 - - #define RING_SIZE(x) ((x) - 1) - --- -2.27.0 - diff --git a/0145-add-limit-with-level-for-sockopt.patch b/0145-add-limit-with-level-for-sockopt.patch deleted file mode 100644 index c58bbc723a6aeb2f1bc1c74b62777ade637ac0fd..0000000000000000000000000000000000000000 --- a/0145-add-limit-with-level-for-sockopt.patch +++ /dev/null @@ -1,86 +0,0 @@ -From 5e4b2366417b5f951ffd5ee45c0917ae67bd502e Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Sun, 3 Mar 2024 21:40:23 +0800 -Subject: [PATCH] add limit with level for sockopt - ---- - src/lstack/api/lstack_wrap.c | 49 +++++++++++++++++++++++++----------- - 2 files changed, 35 insertions(+), 16 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 1e36d3d..49bbf91 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -364,27 +364,46 @@ static inline int32_t do_getsockname(int32_t s, struct sockaddr *name, socklen_t - return posix_api->getsockname_fn(s, name, namelen); - } - --static bool unsupport_optname(int32_t optname) --{ -- if (optname == SO_BROADCAST || -- optname == SO_PROTOCOL || -- optname == TCP_QUICKACK || -- optname == SO_SNDTIMEO || -- optname == SO_RCVTIMEO || -- optname == SO_SNDBUF || -- optname == SO_RCVBUF || -- optname == TCP_INFO || -- optname == TCP_MAXSEG || -- optname == SO_DONTROUTE || -- optname == TCP_CONGESTION) { -+static bool unsupport_tcp_optname(int32_t optname) -+{ -+ if ((optname == TCP_QUICKACK) || -+ (optname == TCP_INFO) || -+ (optname == TCP_MAXSEG) || -+ (optname == TCP_CONGESTION)) { -+ return true; -+ } -+ return false; -+} -+ -+static bool unsupport_socket_optname(int32_t optname) -+{ -+ if ((optname == SO_BROADCAST) || -+ (optname == SO_PROTOCOL) || -+ (optname == SO_SNDTIMEO) || -+ (optname == SO_RCVTIMEO) || -+ (optname == SO_SNDBUF) || -+ (optname == SO_RCVBUF) || -+ (optname == SO_DONTROUTE)) { - return true; - } - return false; - } - -+static bool unsupport_optname(int32_t level, int32_t optname) -+{ -+ if (level == SOL_TCP) { -+ return unsupport_tcp_optname(optname); -+ } -+ -+ if (level == SOL_SOCKET) { -+ return unsupport_socket_optname(optname); -+ } -+ return false; -+} -+ - static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, void *optval, socklen_t *optlen) - { -- if (select_fd_posix_path(s, NULL) == PATH_LWIP && !unsupport_optname(optname)) { -+ if (select_fd_posix_path(s, NULL) == PATH_LWIP && !unsupport_optname(level, optname)) { - return g_wrap_api->getsockopt_fn(s, level, optname, optval, optlen); - } - -@@ -393,7 +412,7 @@ static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, v - - static inline int32_t do_setsockopt(int32_t s, int32_t level, int32_t optname, const void *optval, socklen_t optlen) - { -- if (select_fd_posix_path(s, NULL) == PATH_KERNEL || unsupport_optname(optname)) { -+ if (select_fd_posix_path(s, NULL) == PATH_KERNEL || unsupport_optname(level, optname)) { - return posix_api->setsockopt_fn(s, level, optname, optval, optlen); - } - --- -2.27.0 - diff --git a/0146-udp-add-restriction-message-too-long.patch b/0146-udp-add-restriction-message-too-long.patch deleted file mode 100644 index a74c49ca73d90ae94e37e479a32df927967f89c8..0000000000000000000000000000000000000000 --- a/0146-udp-add-restriction-message-too-long.patch +++ /dev/null @@ -1,42 +0,0 @@ -From a37c451e63bed06a70e887aba6364183d71f414f Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Mon, 11 Mar 2024 11:18:54 +0800 -Subject: [PATCH] udp add restriction: message too long - ---- - src/common/gazelle_opt.h | 2 ++ - src/lstack/core/lstack_lwip.c | 5 +++++ - 2 files changed, 7 insertions(+) - -diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h -index 1d1c5f5..6d787b9 100644 ---- a/src/common/gazelle_opt.h -+++ b/src/common/gazelle_opt.h -@@ -60,6 +60,8 @@ - - #define DPDK_PKT_BURST_SIZE 512 - -+#define GAZELLE_UDP_PKGLEN_MAX (65535 - IP_HLEN - UDP_HLEN) -+ - /* total:33 client, index 32 is invaild client */ - #define GAZELLE_CLIENT_NUM_ALL 33 - #define GAZELLE_NULL_CLIENT (GAZELLE_CLIENT_NUM_ALL - 1) -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index f4199f8..8aae433 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -779,6 +779,11 @@ ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t f - return 0; - } - -+ if (NETCONN_IS_UDP(sock) && (len > GAZELLE_UDP_PKGLEN_MAX)) { -+ LSTACK_LOG(ERR, LSTACK, "Message too long\n"); -+ GAZELLE_RETURN(EMSGSIZE); -+ } -+ - thread_bind_stack(sock); - - if (sock->same_node_tx_ring != NULL) { --- -2.27.0 - diff --git a/0147-dfx-improve-log-readability-when-connect-ltran-lstac.patch b/0147-dfx-improve-log-readability-when-connect-ltran-lstac.patch deleted file mode 100644 index f21edae90691f4c057e313c04ff7acd9284ce1b0..0000000000000000000000000000000000000000 --- a/0147-dfx-improve-log-readability-when-connect-ltran-lstac.patch +++ /dev/null @@ -1,269 +0,0 @@ -From 9d68f6bca1adfba6802e85aa213dbba5002cb289 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Tue, 27 Feb 2024 22:48:19 +0800 -Subject: [PATCH] dfx: improve log readability when connect ltran/lstack failed - ---- - src/ltran/ltran_dfx.c | 152 +++++++++++++++++++++++++++--------------- - 1 file changed, 99 insertions(+), 53 deletions(-) - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 96509e5..a429866 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -101,6 +101,8 @@ static void gazelle_print_fault_inject_unset_status(void *buf, const struct gaze - #endif /* GAZELLE_FAULT_INJECT_ENABLE */ - - static bool g_use_ltran = false; -+static char g_ltran_unix_path[PATH_MAX]; -+static char g_lstack_unix_path[PATH_MAX]; - - static char* g_unix_prefix; - -@@ -268,24 +270,16 @@ static void gazelle_print_ltran_sock(void *buf, const struct gazelle_stat_msg_re - printf("ltran sock table num: %u\n", table->conn_num); - } - --static int32_t dfx_connect_ltran(bool use_ltran, bool probe) -+static int dfx_make_unix_addr(struct sockaddr_un *addr, bool use_ltran) - { -- int32_t ret, fd; -- struct sockaddr_un addr; -- -- fd = socket(AF_UNIX, SOCK_STREAM, 0); -- if (fd == -1) { -- printf("create socket failed. errno: %d\n", errno); -- return GAZELLE_ERR; -- } -- -- ret = memset_s(&addr, sizeof(addr), 0, sizeof(struct sockaddr_un)); -+ int ret; -+ ret = memset_s(addr, sizeof(*addr), 0, sizeof(struct sockaddr_un)); - if (ret != EOK) { - printf("%s:%d memset_s fail ret=%d\n", __FUNCTION__, __LINE__, ret); - goto END; - } - -- ret = strncpy_s(addr.sun_path, sizeof(addr.sun_path), GAZELLE_RUN_DIR, -+ ret = strncpy_s(addr->sun_path, sizeof(addr->sun_path), GAZELLE_RUN_DIR, - strlen(GAZELLE_RUN_DIR) + 1); - if (ret != EOK) { - printf("%s:%d strncpy_s fail ret=%d\n", __FUNCTION__, __LINE__, ret); -@@ -293,7 +287,7 @@ static int32_t dfx_connect_ltran(bool use_ltran, bool probe) - } - - if (g_unix_prefix) { -- ret = strncat_s(addr.sun_path, sizeof(addr.sun_path), g_unix_prefix, -+ ret = strncat_s(addr->sun_path, sizeof(addr->sun_path), g_unix_prefix, - strlen(g_unix_prefix) + 1); - if (ret != EOK) { - printf("%s:%d strncat_s fail ret=%d\n", __FUNCTION__, __LINE__, ret); -@@ -301,43 +295,89 @@ static int32_t dfx_connect_ltran(bool use_ltran, bool probe) - } - } - -- addr.sun_family = AF_UNIX; -+ addr->sun_family = AF_UNIX; - if (use_ltran) { -- ret = strncat_s(addr.sun_path, sizeof(addr.sun_path), LTRAN_DFX_SOCK_FILENAME, -+ ret = strncat_s(addr->sun_path, sizeof(addr->sun_path), LTRAN_DFX_SOCK_FILENAME, - strlen(LTRAN_DFX_SOCK_FILENAME) + 1); - if (ret != EOK) { - printf("%s:%d strncat_s fail ret=%d\n", __FUNCTION__, __LINE__, ret); - goto END; - } -+ memcpy_s(g_ltran_unix_path, PATH_MAX, addr->sun_path, sizeof(addr->sun_path)); - } else { -- ret = strncat_s(addr.sun_path, sizeof(addr.sun_path), LSTACK_DFX_SOCK_FILENAME, -+ ret = strncat_s(addr->sun_path, sizeof(addr->sun_path), LSTACK_DFX_SOCK_FILENAME, - strlen(LSTACK_DFX_SOCK_FILENAME) + 1); - if (ret != EOK) { - printf("%s:%d strncat_s fail ret=%d\n", __FUNCTION__, __LINE__, ret); - goto END; - } -+ memcpy_s(g_lstack_unix_path, PATH_MAX, addr->sun_path, sizeof(addr->sun_path)); - } -+ return 0; -+END: -+ return -1; -+} -+ -+static int32_t dfx_connect_server(bool use_ltran) -+{ -+ int32_t ret, fd; -+ struct sockaddr_un addr; -+ -+ fd = socket(AF_UNIX, SOCK_STREAM, 0); -+ if (fd == -1) { -+ printf("create socket failed. errno: %d\n", errno); -+ return GAZELLE_ERR; -+ } -+ -+ ret = dfx_make_unix_addr(&addr, use_ltran); -+ if (ret != 0) { -+ goto END; -+ } - - ret = connect(fd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)); -- if (ret == -1) { -- if (!probe) { -- printf("connect ltran failed. errno: %d ret=%d\n", errno, ret); -- printf("You may need to use the -u parameter to specify the UNIX_PREFIX that matches the configuration.\n"); -- } -+ if (ret != 0) { - goto END; - } - - return fd; - END: -+ ret = errno; - close(fd); -- return GAZELLE_ERR; -+ return -ret; -+} -+ -+static int dfx_connect_probe(void) -+{ -+ int32_t ret1; -+ int32_t ret2; -+ ret1 = dfx_connect_server(true); -+ if (ret1 > 0) { -+ close(ret1); -+ return 1; -+ } -+ ret2 = dfx_connect_server(false); -+ if (ret2 > 0) { -+ close(ret2); -+ return 0; -+ } -+ -+ printf("Connect lstack(path:%s), errno: %d; Connect ltran(path:%s) failed, errno: %d\n", -+ g_lstack_unix_path, -ret2, g_ltran_unix_path, -ret1); -+ printf("Please ensure the process is started; If use ltran mode, \ -+ set use_ltran=1 in lstack.conf, otherwise set use_ltran=0\n"); -+ return -1; - } - - static int32_t dfx_stat_conn_to_ltran(struct gazelle_stat_msg_request *req_msg) - { -- int32_t fd = dfx_connect_ltran(g_use_ltran, false); -+ int32_t fd = dfx_connect_server(g_use_ltran); - if (fd < 0) { -- return fd; -+ if (g_use_ltran) { -+ printf("Connect ltran(path:%s) failed. errno: %d\n", g_ltran_unix_path, -fd); -+ } else { -+ printf("Connect lstack(path:%s) failed. errno: %d\n", g_lstack_unix_path, -fd); -+ } -+ return GAZELLE_ERR; - } - - int32_t ret = write_specied_len(fd, (char *)req_msg, sizeof(*req_msg)); -@@ -1417,12 +1457,12 @@ static int32_t parse_dfx_lstack_show_args(int32_t argc, char *argv[], struct gaz - char *param = argv[GAZELLE_OPTIONS1_ARG_IDX]; - if (strcmp(param, "rate") == 0 || strcmp(param, "-r") == 0) { - if (g_use_ltran) { -- req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_LB_RATE; -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_SHOW_LB_RATE; - } else { -- req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_START_LATENCY; -- req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_STOP_LATENCY; -- req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_RATE; -- } -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_START_LATENCY; -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LTRAN_STOP_LATENCY; -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_RATE; -+ } - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_MODE_MAX; - } else if (strcmp(param, "snmp") == 0 || strcmp(param, "-s") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_SNMP; -@@ -1495,7 +1535,6 @@ static int32_t parse_dfx_lstack_args(int32_t argc, char *argv[], struct gazelle_ - return num_cmd; - } - -- - #ifdef GAZELLE_FAULT_INJECT_ENABLE - - #define GAZELLE_SET_FAULT_INJECT_PARAM_COUNT 6 -@@ -1770,19 +1809,48 @@ static int32_t parse_dfx_fault_inject_args(int32_t argc, char *argv[], struct ga - - #endif /* GAZELLE_FAULT_INJECT_ENABLE */ - -+static void parse_unix_arg(int32_t *argc, char *argv[]) -+{ -+ int unix_arg = 0; -+ for (int i = 1; i < *argc; i++) { -+ if (unix_arg == 0) { -+ if (!strcmp(argv[i], "-u")) { -+ unix_arg++; -+ } -+ } else if (unix_arg == 1) { -+ g_unix_prefix = argv[i]; -+ unix_arg++; -+ } else { -+ argv[i - unix_arg] = argv[i]; -+ } -+ } -+ -+ argv[*argc - unix_arg] = argv[*argc]; -+ *argc -= unix_arg; -+} -+ - static int32_t parse_dfx_cmd_args(int32_t argc, char *argv[], struct gazelle_stat_msg_request *req_msg) - { -- int32_t num_cmd = 0; -+ int num_cmd = 0; -+ int ret; - - if (argc < GAZELLE_PARAM_MINNUM) { - return num_cmd; - } - -+ parse_unix_arg(&argc, argv); -+ - char *param = argv[GAZELLE_TARGET_ARG_IDX]; - if (strcmp(param, "ltran") == 0) { -+ g_use_ltran = true; - num_cmd = parse_dfx_ltran_args(argc, argv, req_msg); - } - if (strcmp(param, "lstack") == 0) { -+ ret = dfx_connect_probe(); -+ if (ret < 0) { -+ exit(0); -+ } -+ g_use_ltran = ret; - num_cmd = parse_dfx_lstack_args(argc, argv, req_msg); - } - #ifdef GAZELLE_FAULT_INJECT_ENABLE -@@ -1846,28 +1914,6 @@ int32_t main(int32_t argc, char *argv[]) - struct gazelle_stat_msg_request req_msg[GAZELLE_CMD_MAX] = {0}; - int32_t req_msg_num; - -- int unix_arg = 0; -- for (int32_t i = 1; i < argc; i++) { -- if (unix_arg == 0) { -- if (!strcmp(argv[i], "-u")) { -- unix_arg++; -- } -- } else if (unix_arg == 1) { -- g_unix_prefix = argv[i]; -- unix_arg++; -- } else { -- argv[i - unix_arg] = argv[i]; -- } -- } -- -- argv[argc - unix_arg] = argv[argc]; -- argc -= unix_arg; -- -- int32_t fd = dfx_connect_ltran(true, true); -- if (fd > 0) { -- g_use_ltran = true; -- close(fd); -- } - req_msg_num = parse_dfx_cmd_args(argc, argv, req_msg); - if (req_msg_num <= 0 || req_msg_num > GAZELLE_CMD_MAX) { - show_usage(); --- -2.27.0 - diff --git a/0148-fix-rpc_pool-create-failed-coredump.patch b/0148-fix-rpc_pool-create-failed-coredump.patch deleted file mode 100644 index b52c0895459b8121c104db714d39388e42311954..0000000000000000000000000000000000000000 --- a/0148-fix-rpc_pool-create-failed-coredump.patch +++ /dev/null @@ -1,103 +0,0 @@ -From 98b8e8cea061d65ece3865ce8e772f5b4226199e Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Tue, 27 Feb 2024 22:37:47 +0800 -Subject: [PATCH] fix rpc_pool create failed coredump - ---- - src/lstack/core/lstack_thread_rpc.c | 34 ++++++++++++++++++++------ - src/lstack/include/lstack_thread_rpc.h | 6 ++++- - 2 files changed, 31 insertions(+), 9 deletions(-) - -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 1fdb037..20c5a43 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -36,6 +36,27 @@ static inline __attribute__((always_inline)) struct rpc_msg *get_rpc_msg(struct - return msg; - } - -+static void rpc_msg_init(struct rpc_msg *msg, rpc_msg_func func, struct rpc_msg_pool *pool) -+{ -+ msg->rpcpool = pool; -+ pthread_spin_init(&msg->lock, PTHREAD_PROCESS_PRIVATE); -+ msg->func = func; -+ msg->sync_flag = 1; -+ msg->recall_flag = 0; -+} -+ -+static struct rpc_msg *rpc_msg_alloc_except(rpc_msg_func func) -+{ -+ struct rpc_msg *msg = calloc(1, sizeof(struct rpc_msg)); -+ if (msg == NULL) { -+ return NULL; -+ } -+ -+ rpc_msg_init(msg, func, NULL); -+ -+ return msg; -+} -+ - static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func) - { - struct rpc_msg *msg = NULL; -@@ -45,14 +66,15 @@ static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func) - if (g_rpc_pool == NULL) { - LSTACK_LOG(INFO, LSTACK, "g_rpc_pool calloc failed\n"); - g_rpc_stats.call_alloc_fail++; -- return NULL; -+ exit(-1); - } - - g_rpc_pool->mempool = create_mempool("rpc_pool", 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++; -- return NULL; -+ exit(-1); - } - } - -@@ -61,12 +83,8 @@ static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func) - g_rpc_stats.call_alloc_fail++; - return NULL; - } -- msg->rpcpool = g_rpc_pool; -+ rpc_msg_init(msg, func, g_rpc_pool); - -- pthread_spin_init(&msg->lock, PTHREAD_PROCESS_PRIVATE); -- msg->func = func; -- msg->sync_flag = 1; -- msg->recall_flag = 0; - return msg; - } - -@@ -247,7 +265,7 @@ int32_t rpc_call_close(rpc_queue *queue, int fd) - - int32_t rpc_call_stack_exit(rpc_queue *queue) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_exit_by_rpc); -+ struct rpc_msg *msg = rpc_msg_alloc_except(stack_exit_by_rpc); - if (msg == NULL) { - return -1; - } -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 30caa66..4d89604 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -104,7 +104,11 @@ static inline __attribute__((always_inline)) void rpc_call(rpc_queue *queue, str - static inline __attribute__((always_inline)) void rpc_msg_free(struct rpc_msg *msg) - { - pthread_spin_destroy(&msg->lock); -- rte_mempool_put(msg->rpcpool->mempool, (void *)msg); -+ if (msg->rpcpool != NULL && msg->rpcpool->mempool != NULL) { -+ rte_mempool_put(msg->rpcpool->mempool, (void *)msg); -+ } else { -+ free(msg); -+ } - } - - #endif --- -2.27.0 - diff --git a/0149-ensure-the-bond-interface-flow_type_rss_offloads-mat.patch b/0149-ensure-the-bond-interface-flow_type_rss_offloads-mat.patch deleted file mode 100644 index 7585389444f1d114171de425e02194f338ef80f7..0000000000000000000000000000000000000000 --- a/0149-ensure-the-bond-interface-flow_type_rss_offloads-mat.patch +++ /dev/null @@ -1,24 +0,0 @@ -From f8321fa815ca33267bd5b829fd8c06b75ab215d1 Mon Sep 17 00:00:00 2001 -From: zhangmengxuan -Date: Tue, 12 Mar 2024 19:51:57 +0800 -Subject: [PATCH] ensure the bond interface flow_type_rss_offloads match slave - ---- - src/lstack/core/lstack_dpdk.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 5811918..a774d45 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -584,6 +584,7 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - dev_info.rx_offload_capa = slave_dev_info.rx_offload_capa; - dev_info.tx_offload_capa = slave_dev_info.tx_offload_capa; - dev_info.reta_size = slave_dev_info.reta_size; -+ dev_info.flow_type_rss_offloads = slave_dev_info.flow_type_rss_offloads; - } - - eth_params_checksum(ð_params->conf, &dev_info); --- -2.33.0 - diff --git a/0150-FAULT-INJECT-add-duplicate-and-reorder-methods.patch b/0150-FAULT-INJECT-add-duplicate-and-reorder-methods.patch deleted file mode 100644 index 17a181812f666669a8285544422ee38d7c1945bf..0000000000000000000000000000000000000000 --- a/0150-FAULT-INJECT-add-duplicate-and-reorder-methods.patch +++ /dev/null @@ -1,315 +0,0 @@ -From 1929cc2a07a8e6d6a81b13a8338d816d7f09e709 Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Wed, 6 Mar 2024 10:51:42 +0800 -Subject: [PATCH] FAULT INJECT: add duplicate and reorder methods - ---- - src/common/gazelle_fault_inject_common.h | 4 +- - src/lstack/netif/lstack_fault_inject.c | 162 ++++++++++++++++++++++- - src/ltran/ltran_dfx.c | 20 ++- - 3 files changed, 174 insertions(+), 12 deletions(-) - -diff --git a/src/common/gazelle_fault_inject_common.h b/src/common/gazelle_fault_inject_common.h -index 3a77f39..72d778c 100644 ---- a/src/common/gazelle_fault_inject_common.h -+++ b/src/common/gazelle_fault_inject_common.h -@@ -17,10 +17,10 @@ - - enum GAZELLE_FAULT_INJECT_TYPE { - GAZELLE_FAULT_INJECT_TYPE_ERR = 0, -- GAZELLE_FAULT_INJECT_PACKET_DELAY, - GAZELLE_FAULT_INJECT_PACKET_LOSS, -- GAZELLE_FAULT_INJECT_PACKAET_DUPLICATE, - GAZELLE_FAULT_INJECT_PACKET_REORDER, -+ GAZELLE_FAULT_INJECT_PACKET_DELAY, -+ GAZELLE_FAULT_INJECT_PACKAET_DUPLICATE, - GAZELLE_FAULT_INJECT_TYPE_MAX, - }; - -diff --git a/src/lstack/netif/lstack_fault_inject.c b/src/lstack/netif/lstack_fault_inject.c -index 41e7d95..4edc6cc 100644 ---- a/src/lstack/netif/lstack_fault_inject.c -+++ b/src/lstack/netif/lstack_fault_inject.c -@@ -9,7 +9,7 @@ - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ -- -+#include - #include - #include - #include -@@ -31,6 +31,15 @@ struct inject_tbl { - }; - static struct inject_tbl g_inject_tbl[GAZELLE_FAULT_INJECT_TYPE_MAX]; - -+struct reorder_stat { -+ int32_t enable; -+ int32_t arr_size; -+ int32_t cur_cnt; -+ struct rte_mbuf **array; -+}; -+ -+static struct reorder_stat g_reorder[PROTOCOL_STACK_MAX]; -+ - struct inject_func_tbl { - enum GAZELLE_FAULT_INJECT_TYPE type; - enum GAZELLE_FAULT_INJECT_RULE rule; -@@ -41,10 +50,16 @@ static int32_t inject_packet_delay_random(struct protocol_stack *stack, struct r - uint32_t nr_pkts, struct gazelle_fault_inject_data data); - static int32_t inject_packet_loss_random(struct protocol_stack *stack, struct rte_mbuf **pkts, - uint32_t nr_pkts, struct gazelle_fault_inject_data data); -+static int32_t inject_packet_duplicate_random(struct protocol_stack *stack, struct rte_mbuf **pkts, -+ uint32_t nr_pkts, struct gazelle_fault_inject_data data); -+static int32_t inject_packet_reorder_random(struct protocol_stack *stack, struct rte_mbuf **pkts, -+ uint32_t nr_pkts, struct gazelle_fault_inject_data data); - - static struct inject_func_tbl g_inject_func_tbl[] = { - {GAZELLE_FAULT_INJECT_PACKET_LOSS, INJECT_LOSS_RANDOM, inject_packet_loss_random}, - {GAZELLE_FAULT_INJECT_PACKET_DELAY, INJECT_DELAY_RANDOM, inject_packet_delay_random}, -+ {GAZELLE_FAULT_INJECT_PACKAET_DUPLICATE, INJECT_DUPLICATE_RANDOM, inject_packet_duplicate_random}, -+ {GAZELLE_FAULT_INJECT_PACKET_REORDER, INJECT_REORDER_RANDOM, inject_packet_reorder_random}, - }; - - static int32_t inject_func_tbl_update() -@@ -68,16 +83,16 @@ static int32_t inject_func_tbl_update() - static uint32_t inject_tx_xmit(struct protocol_stack *stack, struct rte_mbuf **pkts, uint32_t nr_pkts) - { - for (int32_t i = 0; i < GAZELLE_FAULT_INJECT_TYPE_MAX; ++i) { -- if (g_inject_tbl[i].inject_data.fault_inject_on) { -+ if (g_inject_tbl[i].inject_data.fault_inject_on && g_inject_tbl[i].inject_func) { - int32_t xmit_pkts = 0; -- xmit_pkts = g_inject_tbl[i].inject_func(stack, pkts, nr_pkts, -- g_inject_tbl[i].inject_data); -+ xmit_pkts = g_inject_tbl[i].inject_func(stack, pkts, nr_pkts, g_inject_tbl[i].inject_data); - if (xmit_pkts == nr_pkts) { - continue; - } - return xmit_pkts; - } - } -+ - if (rte_mbuf_refcnt_read(*pkts) == 1) { - return nr_pkts; - } -@@ -105,7 +120,7 @@ static int32_t inject_strategy_update() - } - return 0; - } -- -+ - for (uint32_t i = 0; i < stack_group->stack_num; ++i) { - struct protocol_stack *stack = stack_group->stacks[i]; - vdev_dev_ops_init(&stack->dev_ops); -@@ -150,6 +165,132 @@ static int32_t inject_packet_loss_random(struct protocol_stack *stack, struct rt - return nr_pkts; - } - -+static int32_t inject_packet_duplicate_random(struct protocol_stack *stack, struct rte_mbuf **pkts, -+ uint32_t nr_pkts, struct gazelle_fault_inject_data data) -+{ -+ if (rte_mbuf_refcnt_read(*pkts) == 1) { -+ return nr_pkts; -+ } -+ -+ double duplicate_rate = data.inject_data.duplicate.duplicate_rate; -+ int32_t boundary = (int32_t) (duplicate_rate * INJECT_MODULO); -+ int32_t count_max = data.inject_data.duplicate.duplicate_sigle_count; -+ -+ uint32_t rand_num = rte_rand() % INJECT_MODULO; -+ if (rand_num > boundary) { -+ return nr_pkts; -+ } -+ -+ struct rte_mempool *mp = stack->rxtx_mbuf_pool; -+ struct rte_mbuf *mbuf_clone = NULL; -+ int32_t ret = 0; -+ -+ for (int32_t i = 0; i < nr_pkts; ++i) { -+ int32_t count = count_max; -+ while (count--) { -+ mbuf_clone = rte_pktmbuf_clone(pkts[i], mp); -+ rte_pktmbuf_free(pkts[i]); -+ if (mbuf_clone == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "fault inject mbuf_clone fail.\n"); -+ return 0; -+ } -+ ret = vdev_tx_xmit(stack, &mbuf_clone, 1); -+ if (ret < 1) { -+ rte_pktmbuf_free(mbuf_clone); -+ return ret; -+ } -+ } -+ } -+ return nr_pkts; -+} -+ -+static int32_t send_reorder_array(struct protocol_stack *stack) -+{ -+ int32_t idx = stack->stack_idx; -+ int32_t ret = 0; -+ -+ for (int32_t i = 0; i < g_reorder[idx].cur_cnt; ++i) { -+ ret = vdev_tx_xmit(stack, g_reorder[idx].array + i, 1); -+ if (ret < 1) { -+ rte_pktmbuf_free(*(g_reorder[idx].array + i)); -+ } -+ } -+ g_reorder[idx].cur_cnt = 0; -+ -+ return 0; -+} -+ -+static int32_t inject_packet_reorder_random(struct protocol_stack *stack, struct rte_mbuf **pkts, -+ uint32_t nr_pkts, struct gazelle_fault_inject_data data) -+{ -+ if (rte_mbuf_refcnt_read(*pkts) == 1) { -+ return nr_pkts; -+ } -+ -+ double reorder_rate = data.inject_data.reorder.reorder_rate; -+ int32_t boundary = (int32_t) (reorder_rate * INJECT_MODULO); -+ int32_t count_max = data.inject_data.reorder.reorder_sigle_count; -+ -+ uint32_t rand_num = rte_rand() % INJECT_MODULO; -+ if (rand_num > boundary) { -+ return nr_pkts; -+ } -+ -+ struct rte_mempool *mp = stack->rxtx_mbuf_pool; -+ struct rte_mbuf *mbuf_clone = NULL; -+ int32_t idx = stack->stack_idx; -+ for (int32_t i = 0; i < nr_pkts; ++i) { -+ if (g_reorder[idx].cur_cnt < count_max) { -+ mbuf_clone = rte_pktmbuf_clone(pkts[i], mp); -+ if (mbuf_clone == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "fault inject mbuf_clone fail.\n"); -+ return 0; -+ } -+ *(g_reorder[idx].array + g_reorder[idx].cur_cnt++) = mbuf_clone; -+ /* func rte_pktmbuf_clone will add refcnt of mbuf, so following operation will free mbuf double */ -+ rte_pktmbuf_free(pkts[i]); -+ rte_pktmbuf_free(pkts[i]); -+ } else { -+ send_reorder_array(stack); -+ } -+ } -+ -+ return nr_pkts; -+} -+ -+static int32_t inject_reorder_mem_release() -+{ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ -+ for (uint32_t i = 0; i < stack_group->stack_num; ++i) { -+ struct protocol_stack *stack = stack_group->stacks[i]; -+ if (!g_reorder[i].enable) { -+ return 0; -+ } -+ send_reorder_array(stack); -+ free(g_reorder[i].array); -+ g_reorder[i].enable = 0; -+ } -+ -+ return 0; -+} -+ -+static int32_t inject_reorder_mem_alloc() -+{ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ -+ for (uint32_t i = 0; i < stack_group->stack_num; ++i) { -+ g_reorder[i].enable = 1; -+ -+ g_reorder[i].arr_size = -+ g_inject_tbl[GAZELLE_FAULT_INJECT_PACKET_REORDER].inject_data.inject_data.reorder.reorder_sigle_count; -+ g_reorder[i].cur_cnt = 0; -+ g_reorder[i].array = -+ (struct rte_mbuf**) malloc(sizeof(struct rte_mbuf**) * (g_reorder[i].arr_size)); -+ } -+ return 0; -+} -+ - static int32_t inject_respond_msg(int32_t sockfd) - { - struct gazelle_stack_dfx_data rsp = {0}; -@@ -192,6 +333,10 @@ static int32_t inject_unset_cmd(int32_t sockfd, struct gazelle_fault_inject_data - } - } - -+ if (!g_inject_tbl[GAZELLE_FAULT_INJECT_PACKET_REORDER].inject_data.fault_inject_on) { -+ inject_reorder_mem_release(); -+ } -+ - inject_strategy_update(); - - return inject_respond_msg(sockfd); -@@ -208,8 +353,13 @@ static int32_t inject_set_cmd(int32_t sockfd, struct gazelle_fault_inject_data i - return -1; - } - -+ if (inject.inject_type == GAZELLE_FAULT_INJECT_PACKET_REORDER) { -+ inject_reorder_mem_release(); -+ inject_reorder_mem_alloc(); -+ } -+ - inject_strategy_update(); -- -+ - return inject_respond_msg(sockfd); - } - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 96509e5..2cc3504 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -77,10 +77,10 @@ struct gazelle_fault_inject_type_list { - }; - - static struct gazelle_fault_inject_type_list inject_type_list[] = { -- {"delay", GAZELLE_FAULT_INJECT_PACKET_DELAY, parse_inject_packet_delay_digit}, - {"loss", GAZELLE_FAULT_INJECT_PACKET_LOSS, parse_inject_packet_loss_digit}, -- {"duplicate", GAZELLE_FAULT_INJECT_PACKAET_DUPLICATE, parse_inject_packet_duplicate_digit}, - {"reorder", GAZELLE_FAULT_INJECT_PACKET_REORDER, parse_inject_packet_reorder_digit}, -+ {"delay", GAZELLE_FAULT_INJECT_PACKET_DELAY, parse_inject_packet_delay_digit}, -+ {"duplicate", GAZELLE_FAULT_INJECT_PACKAET_DUPLICATE, parse_inject_packet_duplicate_digit}, - }; - - struct gazelle_fault_inject_rule_list { -@@ -1514,7 +1514,7 @@ static void gazelle_print_fault_inject_type_info(struct gazelle_fault_inject_dat - } - - if (inject->inject_type == GAZELLE_FAULT_INJECT_PACKET_DELAY) { -- printf("\t| inject_type: delay | delay_time: %-7d | delay_range: %-3d | " -+ printf("\t| inject_type: delay | delay_time: %-7d | delay_range: %-3d | " - "inject_rule: random |\n", inject->inject_data.delay.delay_time, - inject->inject_data.delay.delay_range); - } -@@ -1522,10 +1522,22 @@ static void gazelle_print_fault_inject_type_info(struct gazelle_fault_inject_dat - #define INJECT_PERCENT 100 - - if (inject->inject_type == GAZELLE_FAULT_INJECT_PACKET_LOSS) { -- printf("\t| inject_type: loss | loss_rate: %-3.1f%% | loss_single_count: %-3d | " -+ printf("\t| inject_type: loss | loss_rate: %-4.1f%% | loss_single_count: %-3d | " - "inject_rule: random |\n", inject->inject_data.loss.loss_rate * INJECT_PERCENT, - inject->inject_data.loss.loss_sigle_count); - } -+ -+ if (inject->inject_type == GAZELLE_FAULT_INJECT_PACKAET_DUPLICATE) { -+ printf("\t| inject_type: duplicate | duplicate_rate: %-4.1f%% | duplicate_single_count: %-3d | " -+ "inject_rule: random |\n", inject->inject_data.duplicate.duplicate_rate * INJECT_PERCENT, -+ inject->inject_data.duplicate.duplicate_sigle_count); -+ } -+ -+ if (inject->inject_type == GAZELLE_FAULT_INJECT_PACKET_REORDER) { -+ printf("\t| inject_type: reorder | reorder_rate: %-4.1f%% | reorder_sigle_count: %-3d | " -+ "inject_rule: random |\n", inject->inject_data.reorder.reorder_rate * INJECT_PERCENT, -+ inject->inject_data.reorder.reorder_sigle_count); -+ } - printf("\n"); - } - --- -2.33.0 - diff --git a/0151-select-timeout-arguments-check.patch b/0151-select-timeout-arguments-check.patch deleted file mode 100644 index 61daec9522a6591bc74d85433b76f86a1de66e4b..0000000000000000000000000000000000000000 --- a/0151-select-timeout-arguments-check.patch +++ /dev/null @@ -1,51 +0,0 @@ -From fbd169eb504f5edc905f07f33785ba3df5812b4c Mon Sep 17 00:00:00 2001 -From: li_yunqing -Date: Thu, 14 Mar 2024 16:37:27 +0800 -Subject: [PATCH] select timeout arguments check - ---- - src/lstack/api/lstack_epoll.c | 18 +++++++++++++----- - 1 file changed, 13 insertions(+), 5 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 7dbef9d..c9d1f0c 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -927,13 +927,17 @@ static void fds_poll2select(struct pollfd *fds, nfds_t nfds, fd_set *readfds, fd - } - } - --static inline int timeval_to_ms(struct timeval *timeval) -+static inline int timeval_to_ms(struct timeval *timeval, int32_t *timeout) - { -- if (timeval == NULL) { -+ if (!timeval) { -+ *timeout = -1; -+ return 0; -+ } -+ if (unlikely((timeval->tv_sec < 0 || timeval->tv_usec < 0 || timeval->tv_usec >= 1000000))) { - return -1; - } -- -- return (timeval->tv_sec * 1000 + timeval->tv_usec / 1000); -+ *timeout = timeval->tv_sec * 1000 + timeval->tv_usec / 1000; -+ return 0; - } - - static nfds_t fds_select2poll(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct pollfd *fds) -@@ -969,7 +973,11 @@ int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfd - /* Convert the select parameter to the poll parameter. */ - struct pollfd fds[FD_SETSIZE] = { 0 }; - nfds_t nfds = fds_select2poll(maxfd, readfds, writefds, exceptfds, fds); -- int timeout = timeval_to_ms(timeval); -+ int timeout = 0; -+ if (timeval_to_ms(timeval, &timeout)) { -+ LSTACK_LOG(ERR, LSTACK, "select input param timeout error.\n"); -+ GAZELLE_RETURN(EINVAL); -+ } - - int event_num = lstack_poll(fds, nfds, timeout); - --- -2.33.0 - diff --git a/0152-recvfrom-support-timeout.patch b/0152-recvfrom-support-timeout.patch deleted file mode 100644 index fa91ff799f04508a7704bba21441be03901e92a2..0000000000000000000000000000000000000000 --- a/0152-recvfrom-support-timeout.patch +++ /dev/null @@ -1,213 +0,0 @@ -From e19bb18fad80ed95fb68318fc6ec7f2f892942dd Mon Sep 17 00:00:00 2001 -From: li_yunqing -Date: Tue, 19 Mar 2024 21:06:07 +0800 -Subject: [PATCH] recvfrom support timeout - ---- - src/lstack/api/lstack_epoll.c | 57 ++++++++++++++++--------- - src/lstack/api/lstack_wrap.c | 1 - - src/lstack/core/lstack_lwip.c | 28 +++++------- - src/lstack/core/lstack_protocol_stack.c | 2 +- - src/lstack/include/posix/lstack_epoll.h | 10 +---- - 5 files changed, 50 insertions(+), 48 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 7dbef9d..1b68c36 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -586,6 +586,41 @@ static void ms_to_timespec(struct timespec *timespec, int32_t timeout) - timespec->tv_nsec = timespec->tv_nsec % SEC_TO_NSEC; - } - -+/** -+ * Block lstack thread -+ * -+ * @param wakeup -+ * The pointer to the wakeup_poll. -+ * @param timeout -+ * The time to wait, if 'timeout <= 0' will block until unlock -+ * -+ * @return -+ * - return '0' on unlock -+ * - return 'ETIMEDOUT' on timeout -+ */ -+int32_t lstack_block_wait(struct wakeup_poll *wakeup, int32_t timeout) -+{ -+ int ret = 0; -+ if (wakeup == NULL) { -+ return ret; -+ } -+ -+ __atomic_store_n(&wakeup->in_wait, true, __ATOMIC_RELEASE); -+ if (timeout > 0) { -+ struct timespec timespec; -+ ms_to_timespec(×pec, timeout); -+ ret = pthread_mutex_timedlock(&wakeup->wait, ×pec); -+ } else { -+ ret = pthread_mutex_lock(&wakeup->wait); -+ } -+ -+ if (__atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { -+ __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -+ } -+ -+ return ret; -+} -+ - int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) - { - struct lwip_sock *sock = get_socket_by_fd(epfd); -@@ -645,7 +680,6 @@ int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t - struct wakeup_poll *wakeup = sock->wakeup; - int32_t kernel_num = 0; - int32_t lwip_num = 0; -- int32_t ret = 0; - - if (get_global_cfg_params()->app_bind_numa) { - epoll_bind_statck(sock->wakeup); -@@ -669,15 +703,7 @@ int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t - if (timeout == 0) { - break; - } -- -- if (timeout < 0) { -- ret = pthread_mutex_lock(&wakeup->wait); -- } else { -- struct timespec epoll_time; -- ms_to_timespec(&epoll_time, timeout); -- ret = pthread_mutex_timedlock(&wakeup->wait, &epoll_time); -- } -- } while (ret == 0); -+ } while (lstack_block_wait(wakeup, timeout) == 0); - - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); - wakeup->stat.app_events += lwip_num; -@@ -857,7 +883,6 @@ int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - - int32_t kernel_num = 0; - int32_t lwip_num = 0; -- int32_t ret; - - do { - __atomic_store_n(&wakeup->in_wait, true, __ATOMIC_RELEASE); -@@ -881,15 +906,7 @@ int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - if (timeout == 0) { - break; - } -- -- if (timeout < 0) { -- ret = pthread_mutex_lock(&wakeup->wait); -- } else { -- struct timespec epoll_time; -- ms_to_timespec(&epoll_time, timeout); -- ret = pthread_mutex_timedlock(&wakeup->wait, &epoll_time); -- } -- } while (ret == 0); -+ } while (lstack_block_wait(wakeup, timeout) == 0); - - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); - wakeup->stat.app_events += lwip_num; -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 49bbf91..0dac82e 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -380,7 +380,6 @@ static bool unsupport_socket_optname(int32_t optname) - if ((optname == SO_BROADCAST) || - (optname == SO_PROTOCOL) || - (optname == SO_SNDTIMEO) || -- (optname == SO_RCVTIMEO) || - (optname == SO_SNDBUF) || - (optname == SO_RCVBUF) || - (optname == SO_DONTROUTE)) { -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 8aae433..d0dea80 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -859,39 +859,33 @@ static bool recv_break_for_err(struct lwip_sock *sock) - return break_wait; - } - --static void recv_block_wait(struct lwip_sock *sock) --{ -- lstack_block_wait(sock->wakeup); --} -- - /* - * return 0 on success, -1 on error - * pbuf maybe NULL(tcp fin packet) - */ - static int recv_ring_get_one(struct lwip_sock *sock, bool noblock, struct pbuf **pbuf) - { -+ int32_t expect = 1; // only get one pbuf -+ - if (sock->recv_lastdata != NULL) { - *pbuf = sock->recv_lastdata; - sock->recv_lastdata = NULL; - return 0; - } - -- if (noblock) { -- if (gazelle_ring_read(sock->recv_ring, (void **)pbuf, 1) != 1) { -- errno = EAGAIN; -+ while (gazelle_ring_read(sock->recv_ring, (void **)pbuf, expect) != expect) { -+ if (noblock) { -+ GAZELLE_RETURN(EAGAIN); -+ } -+ if (recv_break_for_err(sock)) { - return -1; -- } else { -- return 0; - } -- } else { -- while (gazelle_ring_read(sock->recv_ring, (void **)pbuf, 1) != 1) { -- if (recv_break_for_err(sock)) { -- return -1; -- } -- recv_block_wait(sock); -+ if (lstack_block_wait(sock->wakeup, sock->conn->recv_timeout) == ETIMEDOUT) { -+ noblock = true; - } -- return 0; - } -+ -+ return 0; - } - - /* return true: fin is read to user, false: pend fin */ -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index a545b73..7c4af64 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -1270,7 +1270,7 @@ int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *ad - min_sock = get_min_accept_sock(fd); - } else { - while ((min_sock = get_min_accept_sock(fd)) == NULL) { -- lstack_block_wait(sock->wakeup); -+ lstack_block_wait(sock->wakeup, 0); - } - } - -diff --git a/src/lstack/include/posix/lstack_epoll.h b/src/lstack/include/posix/lstack_epoll.h -index 7591f0f..59b5ef7 100644 ---- a/src/lstack/include/posix/lstack_epoll.h -+++ b/src/lstack/include/posix/lstack_epoll.h -@@ -80,15 +80,7 @@ int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t - int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout); - int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeval); - --static inline void lstack_block_wait(struct wakeup_poll *wakeup) --{ -- if (wakeup == NULL) { -- return; -- } -- -- __atomic_store_n(&wakeup->in_wait, true, __ATOMIC_RELEASE); -- pthread_mutex_lock(&wakeup->wait); --} -+int32_t lstack_block_wait(struct wakeup_poll *wakeup, int32_t timeout); - - static inline void lstack_block_wakeup(struct wakeup_poll *wakeup) - { --- -2.33.0 - diff --git a/0153-fix-netperf-setsockopt-fail.patch b/0153-fix-netperf-setsockopt-fail.patch deleted file mode 100644 index 5fcfe8204f2f0109f8b934a8823ba3771e034fdc..0000000000000000000000000000000000000000 --- a/0153-fix-netperf-setsockopt-fail.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 33efdf6e98d223f44a0168ae2e17e95cb7f27402 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Thu, 14 Mar 2024 13:16:58 +0800 -Subject: [PATCH] fix netperf setsockopt fail - ---- - src/lstack/api/lstack_wrap.c | 12 ++++++++++++ - 1 file changed, 12 insertions(+) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 49bbf91..1bec08b 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -364,6 +364,14 @@ static inline int32_t do_getsockname(int32_t s, struct sockaddr *name, socklen_t - return posix_api->getsockname_fn(s, name, namelen); - } - -+static bool unsupport_ip_optname(int32_t optname) -+{ -+ if (optname == IP_RECVERR) { -+ return true; -+ } -+ return false; -+} -+ - static bool unsupport_tcp_optname(int32_t optname) - { - if ((optname == TCP_QUICKACK) || -@@ -391,6 +399,10 @@ static bool unsupport_socket_optname(int32_t optname) - - static bool unsupport_optname(int32_t level, int32_t optname) - { -+ if (level == SOL_IP) { -+ return unsupport_ip_optname(optname); -+ } -+ - if (level == SOL_TCP) { - return unsupport_tcp_optname(optname); - } --- -2.33.0 - diff --git a/0154-fix-LATENCY_WRITE-increase-in-recv-process.patch b/0154-fix-LATENCY_WRITE-increase-in-recv-process.patch deleted file mode 100644 index 3a0efb674a96838ade6c2f32eb7b44f66318c95b..0000000000000000000000000000000000000000 --- a/0154-fix-LATENCY_WRITE-increase-in-recv-process.patch +++ /dev/null @@ -1,134 +0,0 @@ -From c3d84d821fcdc15245f7cc9838cf97b4947a48e2 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Wed, 13 Mar 2024 13:01:38 +0800 -Subject: [PATCH] fix LATENCY_WRITE increase in recv process - ---- - src/common/dpdk_common.h | 5 +++++ - src/common/gazelle_dfx_msg.h | 2 ++ - src/lstack/core/lstack_lwip.c | 4 ++++ - src/lstack/core/lstack_stack_stat.c | 20 +++++++++++++++++++- - src/lstack/include/lstack_stack_stat.h | 1 + - 5 files changed, 31 insertions(+), 1 deletion(-) - -diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h -index a79a0f2..cb41747 100644 ---- a/src/common/dpdk_common.h -+++ b/src/common/dpdk_common.h -@@ -23,6 +23,8 @@ - - #define GAZELLE_KNI_NAME "kni" // will be removed during dpdk update - -+#define GAZELLE_LATENCY_RD 0 -+#define GAZELLE_LATENCY_WR 1 - - /* Layout: - * | rte_mbuf | mbuf_private | payload | -@@ -31,6 +33,7 @@ - struct latency_timestamp { - uint64_t stamp; // time stamp - uint64_t check; // just for later vaild check -+ uint16_t type; // latency type - }; - struct mbuf_private { - /* struct pbuf_custom must at first */ -@@ -92,6 +95,7 @@ static __rte_always_inline void time_stamp_into_mbuf(uint32_t rx_count, struct r - lt = &mbuf_to_private(buf[i])->lt; - lt->stamp = time_stamp; - lt->check = ~(time_stamp); -+ lt->type = GAZELLE_LATENCY_RD; - } - } - -@@ -102,6 +106,7 @@ static __rte_always_inline void time_stamp_into_pbuf(uint32_t tx_count, struct p - lt = &pbuf_to_private(buf[i])->lt; - lt->stamp = time_stamp; - lt->check = ~(time_stamp); -+ lt->type = GAZELLE_LATENCY_WR; - } - } - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 8d528d6..d7ba80f 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -69,6 +69,8 @@ enum GAZELLE_STAT_MODE { - enum GAZELLE_LATENCY_TYPE { - GAZELLE_LATENCY_READ_LWIP, - GAZELLE_LATENCY_READ_LSTACK, -+ GAZELLE_LATENCY_READ_MAX, -+ - GAZELLE_LATENCY_WRITE_LWIP, - GAZELLE_LATENCY_WRITE_LSTACK, - GAZELLE_LATENCY_MAX, -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 8aae433..f9b83c7 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -257,6 +257,10 @@ struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_s - int size = (remain_size + MBUF_MAX_DATA_LEN - 1) / MBUF_MAX_DATA_LEN - 1; - struct pbuf *pbuf_used[size]; - gazelle_ring_sc_dequeue(sock->send_ring, (void **)&pbuf_used, size); -+ -+ for (uint32_t i = 0; get_protocol_stack_group()->latency_start && i < size; i++) { -+ calculate_lstack_latency(&sock->stack->latency, pbuf_used[i], GAZELLE_LATENCY_WRITE_LWIP); -+ } - } - - if (get_protocol_stack_group()->latency_start) { -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 25b5557..3e016b7 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -48,10 +48,27 @@ uint64_t get_current_time(void) - return (rte_rdtsc() / g_cycles_per_us); - } - -+void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new) -+{ -+ if (!get_protocol_stack_group()->latency_start) { -+ return; -+ } -+ struct latency_timestamp *lt_old; -+ struct latency_timestamp *lt_new; -+ -+ lt_old = &pbuf_to_private(pbuf_old)->lt; -+ lt_new = &pbuf_to_private(pbuf_new)->lt; -+ -+ lt_new->stamp = lt_old->stamp; -+ lt_new->check = lt_old->check; -+ lt_new->type = lt_old->type; -+} -+ - void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, - enum GAZELLE_LATENCY_TYPE type) - { - uint64_t latency; -+ uint16_t lt_type; - const struct latency_timestamp *lt; - struct stack_latency *latency_stat; - -@@ -60,7 +77,8 @@ void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const - } - - lt = &pbuf_to_private(pbuf)->lt; -- if (lt->stamp != ~(lt->check) || lt->stamp < stack_latency->start_time) { -+ lt_type = (type / GAZELLE_LATENCY_READ_MAX) ? GAZELLE_LATENCY_WR : GAZELLE_LATENCY_RD; -+ if (lt->stamp != ~(lt->check) || lt->stamp < stack_latency->start_time || lt_type != lt->type) { - return; - } - -diff --git a/src/lstack/include/lstack_stack_stat.h b/src/lstack/include/lstack_stack_stat.h -index d5a4ec7..87951aa 100644 ---- a/src/lstack/include/lstack_stack_stat.h -+++ b/src/lstack/include/lstack_stack_stat.h -@@ -30,5 +30,6 @@ uint64_t get_current_time(void); - void lstack_get_low_power_info(struct gazelle_stat_low_power_info *low_power_info); - void unregister_wakeup(struct protocol_stack *stack, struct wakeup_poll *wakeup); - void lstack_calculate_aggregate(int type, uint32_t len); -+void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new); - - #endif /* GAZELLE_STACK_STAT_H */ --- -2.33.0 - diff --git a/0155-dpdk-add-vlan-filter.patch b/0155-dpdk-add-vlan-filter.patch deleted file mode 100644 index 05c98d7804b6e4679ca9a9e790f5db5ec1fedd10..0000000000000000000000000000000000000000 --- a/0155-dpdk-add-vlan-filter.patch +++ /dev/null @@ -1,95 +0,0 @@ -From 3d8a848dde959ef95796e8215cdb1882a3496ce4 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Thu, 21 Mar 2024 11:24:26 +0800 -Subject: [PATCH] dpdk add vlan filter - ---- - src/common/dpdk_common.c | 6 ++++++ - src/lstack/core/lstack_dpdk.c | 19 +++++++++++++------ - 2 files changed, 19 insertions(+), 6 deletions(-) - -diff --git a/src/common/dpdk_common.c b/src/common/dpdk_common.c -index c0c4f63..c03b2ec 100644 ---- a/src/common/dpdk_common.c -+++ b/src/common/dpdk_common.c -@@ -223,6 +223,12 @@ void eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev - COMMON_INFO("RTE_ETH_RX_OFFLOAD_VLAN_STRIP\n"); - } - -+ // rx vlan filter -+ if (rx_ol_capa & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) { -+ rx_ol |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER; -+ COMMON_INFO("RTE_ETH_RX_OFFLOAD_VLAN_STRIP\n"); -+ } -+ - // tx ip - if (tx_ol_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) { - tx_ol |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM; -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index a774d45..42981f4 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -572,13 +572,13 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - int slave_id = rte_eth_bond_primary_get(port_id); - if (slave_id < 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk get bond primary port failed port = %d\n", slave_id); -- free(eth_params); -+ free(eth_params); - return slave_id; - } - ret = rte_eth_dev_info_get(slave_id, &slave_dev_info); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk get bond dev info failed ret = %d\n", ret); -- free(eth_params); -+ free(eth_params); - return ret; - } - dev_info.rx_offload_capa = slave_dev_info.rx_offload_capa; -@@ -623,6 +623,13 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - } - } - -+ /* after rte_eth_dev_configure */ -+ ret = rte_eth_dev_vlan_filter(port_id, get_global_cfg_params()->nic.vlan_mode, 1); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk add vlan filter failed ret = %d\n", ret); -+ return -1; -+ } -+ - rte_eth_allmulticast_enable(port_id); - - return 0; -@@ -733,7 +740,7 @@ int32_t init_dpdk_ethdev(void) - } - - ret = dpdk_ethdev_init(bond_port_id, 1); -- if (ret != 0) { -+ if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed ret = %d\n", ret); - return -1; - } -@@ -765,18 +772,18 @@ int32_t init_dpdk_ethdev(void) - - ret = rte_eth_promiscuous_enable(bond_port_id); - if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk enable promiscuous failed ret = %d\n", ret); -+ LSTACK_LOG(ERR, LSTACK, "dpdk enable promiscuous failed ret = %d\n", ret); - return -1; - } - - ret = rte_eth_allmulticast_enable(bond_port_id); - if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk enable allmulticast failed ret = %d\n", ret); -+ LSTACK_LOG(ERR, LSTACK, "dpdk enable allmulticast failed ret = %d\n", ret); - return -1; - } - - ret = rte_eth_dev_start(bond_port_id); -- if (ret < 0) { -+ if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk start bond port failed ret = %d\n", ret); - return -1; - } --- -2.33.0 - diff --git a/0156-Correcting-spelling-errors.patch b/0156-Correcting-spelling-errors.patch deleted file mode 100644 index ab52f9240c1840198b5d350044250798cfb8495d..0000000000000000000000000000000000000000 --- a/0156-Correcting-spelling-errors.patch +++ /dev/null @@ -1,25 +0,0 @@ -From b766b84a25e9099e67ebacffed7ff96024af2268 Mon Sep 17 00:00:00 2001 -From: gaojiazhen -Date: Fri, 22 Mar 2024 17:33:59 +0800 -Subject: [PATCH] Correcting spelling errors - ---- - src/ltran/ltran_ethdev.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/ltran/ltran_ethdev.c b/src/ltran/ltran_ethdev.c -index 2fb7fab..2f08d4a 100644 ---- a/src/ltran/ltran_ethdev.c -+++ b/src/ltran/ltran_ethdev.c -@@ -378,7 +378,7 @@ static int32_t ltran_bond_port_attr_set(uint16_t port_num, uint16_t bond_port_id - - struct rte_eth_dev_info dev_info; - if (rte_eth_dev_info_get(bond_port_id, &dev_info) != 0) { -- LTRAN_ERR("faile rte_eth_dev_info_get\n"); -+ LTRAN_ERR("rte_eth_dev_info_get failed\n"); - return GAZELLE_ERR; - } - --- -2.33.0 - diff --git a/0157-perftool-add-lhist-statstic-tool.patch b/0157-perftool-add-lhist-statstic-tool.patch deleted file mode 100644 index ed74fd8fa3dcbeccfdc43dd07d33c837658fb4cc..0000000000000000000000000000000000000000 --- a/0157-perftool-add-lhist-statstic-tool.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 34c2f6cc1e1059ffe3e5edd7cebeb758e4ba9f36 Mon Sep 17 00:00:00 2001 -From: wuchangye -Date: Sun, 24 Mar 2024 00:10:08 +0800 -Subject: [PATCH] perftool: add lhist statstic tool - ---- - tools/perf/glhist.bt | 21 +++++++++++++++++++++ - 1 file changed, 21 insertions(+) - create mode 100644 tools/perf/glhist.bt - -diff --git a/tools/perf/glhist.bt b/tools/perf/glhist.bt -new file mode 100644 -index 0000000..757f6e9 ---- /dev/null -+++ b/tools/perf/glhist.bt -@@ -0,0 +1,21 @@ -+#!/usr/bin/env bpftrace -+/* -+reference: https://github.com/bpftrace/bpftrace/blob/master/man/adoc/bpftrace.adoc -+prepare: yum install bpftrace -+example: ./glhist.bt rpc_poll_msg -+*/ -+ -+uprobe:/usr/lib64/liblstack.so:$1 -+{ -+ @t_start[tid] = nsecs; -+} -+ -+uretprobe:/usr/lib64/liblstack.so:$1 -+{ -+ @t_dur[tid] = nsecs - @t_start[tid]; -+ @t_count[tid] = count(); -+ if (@t_dur[tid] < 1000000000) { -+ // lhist(int64 n, int64 min, int64 max, int64 step) -+ @t_hist[tid] = lhist(@t_dur[tid], 0, 4000, 100); -+ } -+} -\ No newline at end of file --- -2.33.0 - diff --git a/0158-add-udp-poll.patch b/0158-add-udp-poll.patch deleted file mode 100644 index 4b7380a87293479ff191ffe736ae5c6b2a752040..0000000000000000000000000000000000000000 --- a/0158-add-udp-poll.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 776ff89196c1fb5bc0193ea746119e40f80fed46 Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Fri, 22 Mar 2024 08:31:28 +0000 -Subject: [PATCH] add udp poll - ---- - src/lstack/core/lstack_lwip.c | 8 ++++++++ - src/lstack/core/lstack_protocol_stack.c | 4 ++++ - 2 files changed, 12 insertions(+) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index a604a62..c5161b4 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -1307,6 +1307,14 @@ void netif_poll(struct netif *netif) - /* processes on same node handshake packet use this function */ - err_t netif_loop_output(struct netif *netif, struct pbuf *p) - { -+ if (p != NULL) { -+ const struct ip_hdr *iphdr; -+ iphdr = (const struct ip_hdr *)p->payload; -+ if (IPH_PROTO(iphdr) == IP_PROTO_UDP) { -+ return udp_netif_loop_output(netif, p); -+ } -+ } -+ - struct tcp_pcb *pcb = p->pcb; - struct pbuf *head = NULL; - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 7c4af64..138ac2b 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -491,6 +491,10 @@ int stack_polling(uint32_t wakeup_tick) - } - } - -+ if (cfg->udp_enable) { -+ udp_netif_poll(&stack->netif); -+ } -+ - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - /* run to completion mode currently does not support kni */ - /* KNI requests are generally low-rate I/Os, --- -2.33.0 - diff --git a/0159-DFX-adapt-testcase-for-gazellectl-connect-failed.patch b/0159-DFX-adapt-testcase-for-gazellectl-connect-failed.patch deleted file mode 100644 index b9d73f5c422204b12715b574da2259c8dc611b98..0000000000000000000000000000000000000000 --- a/0159-DFX-adapt-testcase-for-gazellectl-connect-failed.patch +++ /dev/null @@ -1,39 +0,0 @@ -From f082b20ee9bab301fb21f2a40c32ca031f6177af Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Tue, 26 Mar 2024 10:40:00 +0800 -Subject: [PATCH] DFX: adapt testcase for gazellectl connect failed - ---- - src/ltran/ltran_dfx.c | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 91c6063..073dfa7 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -361,10 +361,10 @@ static int dfx_connect_probe(void) - return 0; - } - -- printf("Connect lstack(path:%s), errno: %d; Connect ltran(path:%s) failed, errno: %d\n", -+ printf("Connect lstack(path:%s) failed, errno: %d; Connect ltran(path:%s) failed, errno: %d\n", - g_lstack_unix_path, -ret2, g_ltran_unix_path, -ret1); -- printf("Please ensure the process is started; If use ltran mode, \ -- set use_ltran=1 in lstack.conf, otherwise set use_ltran=0\n"); -+ printf("Please ensure the process is started; If use ltran mode, " -+ "set use_ltran=1 in lstack.conf, otherwise set use_ltran=0\n"); - return -1; - } - -@@ -1860,7 +1860,7 @@ static int32_t parse_dfx_cmd_args(int32_t argc, char *argv[], struct gazelle_sta - if (strcmp(param, "lstack") == 0) { - ret = dfx_connect_probe(); - if (ret < 0) { -- exit(0); -+ exit(-1); - } - g_use_ltran = ret; - num_cmd = parse_dfx_lstack_args(argc, argv, req_msg); --- -2.33.0 - diff --git a/0160-warp-add-configuration-check-with-host_addr-and-serv.patch b/0160-warp-add-configuration-check-with-host_addr-and-serv.patch deleted file mode 100644 index fdafe9e57a0b091024528ca2e612bd12fbb5446d..0000000000000000000000000000000000000000 --- a/0160-warp-add-configuration-check-with-host_addr-and-serv.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 7604fb6e3917bd2b745f9dd5591de5a3b244c51e Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Mon, 25 Mar 2024 16:07:09 +0800 -Subject: [PATCH] warp: add configuration check with host_addr and server_ip - for ipv6 - ---- - src/lstack/api/lstack_wrap.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 49bbf91..2d5ef83 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -259,6 +259,11 @@ bool is_dst_ip_localhost(const struct sockaddr *addr) - if (get_global_cfg_params()->host_addr.addr == ((struct sockaddr_in *)addr)->sin_addr.s_addr) { - return true; - } -+ } else if (addr->sa_family == AF_INET6) { -+ if (memcmp(get_global_cfg_params()->host_addr6.addr, &((struct sockaddr_in6 *)addr)->sin6_addr, -+ sizeof(struct in6_addr)) == 0) { -+ return true; -+ } - } - - if (getifaddrs(&ifap) == -1) { --- -2.33.0 - diff --git a/0161-add-latency-nodes-READ_APP_CALL-WRITE_RPC_MSG.patch b/0161-add-latency-nodes-READ_APP_CALL-WRITE_RPC_MSG.patch deleted file mode 100644 index b30688ec5da670cd2d38650217a416454683b14b..0000000000000000000000000000000000000000 --- a/0161-add-latency-nodes-READ_APP_CALL-WRITE_RPC_MSG.patch +++ /dev/null @@ -1,380 +0,0 @@ -From 286e9a267e2d106d05c5fec80a932ed605d4b006 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Mon, 1 Apr 2024 09:15:56 +0800 -Subject: [PATCH] add latency nodes: READ_APP_CALL & WRITE_RPC_MSG - ---- - src/common/dpdk_common.h | 2 + - src/common/gazelle_dfx_msg.h | 18 ++++--- - src/lstack/core/lstack_lwip.c | 23 ++++++--- - src/lstack/core/lstack_protocol_stack.c | 4 ++ - src/lstack/core/lstack_stack_stat.c | 68 +++++++++++++++++++++---- - src/lstack/core/lstack_thread_rpc.c | 8 ++- - src/lstack/include/lstack_stack_stat.h | 4 ++ - src/lstack/include/lstack_thread_rpc.h | 2 + - src/lstack/netif/lstack_ethdev.c | 2 +- - src/ltran/ltran_dfx.c | 21 ++++++-- - 10 files changed, 124 insertions(+), 28 deletions(-) - -diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h -index cb41747..7a05342 100644 ---- a/src/common/dpdk_common.h -+++ b/src/common/dpdk_common.h -@@ -19,6 +19,7 @@ - #include - #include - -+#include "gazelle_dfx_msg.h" - #include "gazelle_opt.h" - - #define GAZELLE_KNI_NAME "kni" // will be removed during dpdk update -@@ -33,6 +34,7 @@ - struct latency_timestamp { - uint64_t stamp; // time stamp - uint64_t check; // just for later vaild check -+ uint16_t stamp_seg[GAZELLE_LATENCY_MAX]; // time stamp segment - uint16_t type; // latency type - }; - struct mbuf_private { -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index d7ba80f..c2ff760 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -62,17 +62,23 @@ enum GAZELLE_STAT_MODE { - GAZELLE_STAT_FAULT_INJECT_SET, - GAZELLE_STAT_FAULT_INJECT_UNSET, - #endif /* GAZELLE_FAULT_INJECT_ENABLE */ -- -+ - GAZELLE_STAT_MODE_MAX, - }; - - enum GAZELLE_LATENCY_TYPE { -- GAZELLE_LATENCY_READ_LWIP, -- GAZELLE_LATENCY_READ_LSTACK, -- GAZELLE_LATENCY_READ_MAX, -+ GAZELLE_LATENCY_READ_LWIP, // t0 -> t1 -+ GAZELLE_LATENCY_READ_APP_CALL, // t1 -> t2 -+ GAZELLE_LATENCY_READ_LSTACK, // t2 -> t3 -+ GAZELLE_LATENCY_READ_MAX, // t0 -> t3 -+ -+ GAZELLE_LATENCY_WRITE_INTO_RING, // t0 -> t1 -+ GAZELLE_LATENCY_WRITE_LWIP, // t1 -> t2 -+ GAZELLE_LATENCY_WRITE_LSTACK, // t2 -> t3 -+ GAZELLE_LATENCY_WRITE_MAX, // t0 -> t3 -+ -+ GAZELLE_LATENCY_WRITE_RPC_MSG, // rpc_call_send - -- GAZELLE_LATENCY_WRITE_LWIP, -- GAZELLE_LATENCY_WRITE_LSTACK, - GAZELLE_LATENCY_MAX, - }; - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index a604a62..1d27938 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -259,12 +259,12 @@ struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_s - gazelle_ring_sc_dequeue(sock->send_ring, (void **)&pbuf_used, size); - - for (uint32_t i = 0; get_protocol_stack_group()->latency_start && i < size; i++) { -- calculate_lstack_latency(&sock->stack->latency, pbuf_used[i], GAZELLE_LATENCY_WRITE_LWIP); -+ calculate_lstack_latency(&sock->stack->latency, pbuf_used[i], GAZELLE_LATENCY_WRITE_LWIP, 0); - } - } - - if (get_protocol_stack_group()->latency_start) { -- calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LWIP); -+ calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LWIP, 0); - } - - sock->send_pre_del = pbuf; -@@ -362,6 +362,12 @@ static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t l - } - } - -+ for (int i = 0; get_protocol_stack_group()->latency_start && i < write_num; i++) { -+ if (pbufs[i] != NULL) { -+ calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_WRITE_INTO_RING, 0); -+ } -+ } -+ - gazelle_ring_read_over(sock->send_ring); - - sock->remain_len = MBUF_MAX_DATA_LEN - pbufs[write_num - 1]->len; -@@ -611,7 +617,7 @@ ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, u8_t apifl - - for (uint32_t i = 0; get_protocol_stack_group()->latency_start && i < read_count; i++) { - if (pbufs[i] != NULL) { -- calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_READ_LWIP); -+ calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_READ_LWIP, 0); - } - } - -@@ -870,6 +876,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 -+ uint64_t time_stamp = get_current_time(); - - if (sock->recv_lastdata != NULL) { - *pbuf = sock->recv_lastdata; -@@ -888,7 +895,11 @@ static int recv_ring_get_one(struct lwip_sock *sock, bool noblock, struct pbuf * - noblock = true; - } - } -- -+ -+ if (get_protocol_stack_group()->latency_start) { -+ calculate_lstack_latency(&sock->stack->latency, *pbuf, GAZELLE_LATENCY_READ_APP_CALL, time_stamp); -+ } -+ - return 0; - } - -@@ -954,7 +965,7 @@ static ssize_t recv_ring_tcp_read(struct lwip_sock *sock, void *buf, size_t len, - } - - if (get_protocol_stack_group()->latency_start) { -- calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK); -+ calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK, 0); - } - - gazelle_ring_read_over(sock->recv_ring); -@@ -1001,7 +1012,7 @@ static ssize_t recv_ring_udp_read(struct lwip_sock *sock, void *buf, size_t len, - sock->wakeup->stat.app_read_cnt++; - } - if (get_protocol_stack_group()->latency_start) { -- calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK); -+ calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK, 0); - } - - return copy_len; -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 7c4af64..079bba0 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -876,6 +876,10 @@ void stack_send(struct rpc_msg *msg) - struct protocol_stack *stack = get_protocol_stack(); - int replenish_again; - -+ if (get_protocol_stack_group()->latency_start) { -+ calculate_rpcmsg_latency(&stack->latency, msg, GAZELLE_LATENCY_WRITE_RPC_MSG); -+ } -+ - struct lwip_sock *sock = get_socket(fd); - if (sock == NULL) { - msg->result = -1; -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 3e016b7..80d4998 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -62,16 +62,53 @@ void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new) - lt_new->stamp = lt_old->stamp; - lt_new->check = lt_old->check; - lt_new->type = lt_old->type; -+ for (int i = 0; i < GAZELLE_LATENCY_MAX; i++) { -+ lt_new->stamp_seg[i] = lt_old->stamp_seg[i]; -+ } - } - --void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, -+void time_stamp_into_rpcmsg(struct rpc_msg *msg) -+{ -+ msg->time_stamp = get_current_time(); -+} -+ -+void calculate_rpcmsg_latency(struct gazelle_stack_latency *stack_latency, struct rpc_msg *msg, - enum GAZELLE_LATENCY_TYPE type) - { - uint64_t latency; -- uint16_t lt_type; -- const struct latency_timestamp *lt; -+ struct stack_latency *latency_stat; -+ if (msg == NULL || msg->time_stamp < stack_latency->start_time || type >= GAZELLE_LATENCY_MAX) { -+ return; -+ } -+ -+ latency = get_current_time() - msg->time_stamp; -+ latency_stat = &stack_latency->latency[type]; -+ -+ latency_stat->latency_total += latency; -+ latency_stat->latency_max = (latency_stat->latency_max > latency) ? latency_stat->latency_max : latency; -+ latency_stat->latency_min = (latency_stat->latency_min < latency) ? latency_stat->latency_min : latency; -+ latency_stat->latency_pkts++; -+} -+ -+void calculate_latency_stat(struct gazelle_stack_latency *stack_latency, uint64_t latency, -+ enum GAZELLE_LATENCY_TYPE type) -+{ - struct stack_latency *latency_stat; - -+ latency_stat = &stack_latency->latency[type]; -+ latency_stat->latency_total += latency; -+ latency_stat->latency_max = (latency_stat->latency_max > latency) ? latency_stat->latency_max : latency; -+ latency_stat->latency_min = (latency_stat->latency_min < latency) ? latency_stat->latency_min : latency; -+ latency_stat->latency_pkts++; -+} -+ -+void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, -+ enum GAZELLE_LATENCY_TYPE type, uint64_t time_record) -+{ -+ uint64_t latency; -+ uint16_t lt_type; -+ struct latency_timestamp *lt; -+ - if (pbuf == NULL || type >= GAZELLE_LATENCY_MAX) { - return; - } -@@ -82,13 +119,26 @@ void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const - return; - } - -- latency = get_current_time() - lt->stamp; -- latency_stat = &stack_latency->latency[type]; -+ if (time_record == 0) { -+ lt->stamp_seg[type] = get_current_time() - lt->stamp; -+ } else { -+ lt->stamp_seg[type] = time_record > (lt->stamp_seg[type - 1] + lt->stamp) ? -+ (time_record - lt->stamp) : lt->stamp_seg[type - 1]; -+ } - -- latency_stat->latency_total += latency; -- latency_stat->latency_max = (latency_stat->latency_max > latency) ? latency_stat->latency_max : latency; -- latency_stat->latency_min = (latency_stat->latency_min < latency) ? latency_stat->latency_min : latency; -- latency_stat->latency_pkts++; -+ latency = lt->stamp_seg[type]; -+ if (((lt_type == GAZELLE_LATENCY_RD && type > GAZELLE_LATENCY_READ_LWIP) || -+ (lt_type == GAZELLE_LATENCY_WR && type > GAZELLE_LATENCY_WRITE_INTO_RING)) && -+ latency >= lt->stamp_seg[type - 1]) { -+ latency -= lt->stamp_seg[type - 1]; -+ } -+ -+ /* calculate the time of the entire read/write process */ -+ if (type == GAZELLE_LATENCY_READ_MAX - 1 || type == GAZELLE_LATENCY_WRITE_MAX - 1) { -+ calculate_latency_stat(stack_latency, lt->stamp_seg[type], type + 1); -+ } -+ -+ calculate_latency_stat(stack_latency, latency, type); - } - - void lstack_calculate_aggregate(int type, uint32_t len) -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 20c5a43..30bd827 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -15,6 +15,8 @@ - #include "lstack_log.h" - #include "lstack_dpdk.h" - #include "lstack_rpc_proc.h" -+#include "lstack_stack_stat.h" -+#include "lstack_protocol_stack.h" - #include "lstack_thread_rpc.h" - - static PER_THREAD struct rpc_msg_pool *g_rpc_pool = NULL; -@@ -467,11 +469,15 @@ int32_t rpc_call_send(rpc_queue *queue, int fd, const void *buf, size_t len, int - return -1; - } - -+ if (get_protocol_stack_group()->latency_start) { -+ time_stamp_into_rpcmsg(msg); -+ } -+ - msg->args[MSG_ARG_0].i = fd; - msg->args[MSG_ARG_1].size = len; - msg->args[MSG_ARG_2].i = flags; - msg->sync_flag = 0; -- -+ - rpc_call(queue, msg); - - return 0; -diff --git a/src/lstack/include/lstack_stack_stat.h b/src/lstack/include/lstack_stack_stat.h -index 87951aa..f901982 100644 ---- a/src/lstack/include/lstack_stack_stat.h -+++ b/src/lstack/include/lstack_stack_stat.h -@@ -15,6 +15,7 @@ - - struct gazelle_stack_latency; - struct pbuf; -+struct rpc_msg; - struct gazelle_stat_low_power_info; - struct wakeup_poll; - struct protocol_stack; -@@ -22,6 +23,8 @@ enum GAZELLE_LATENCY_TYPE; - enum GAZELLE_STAT_MODE; - - void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, -+ enum GAZELLE_LATENCY_TYPE type, uint64_t time_record); -+void calculate_rpcmsg_latency(struct gazelle_stack_latency *stack_latency, struct rpc_msg *msg, - enum GAZELLE_LATENCY_TYPE type); - void stack_stat_init(void); - int handle_stack_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode); -@@ -31,5 +34,6 @@ void lstack_get_low_power_info(struct gazelle_stat_low_power_info *low_power_inf - void unregister_wakeup(struct protocol_stack *stack, struct wakeup_poll *wakeup); - void lstack_calculate_aggregate(int type, uint32_t len); - void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new); -+void time_stamp_into_rpcmsg(struct rpc_msg *msg); - - #endif /* GAZELLE_STACK_STAT_H */ -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 4d89604..8e97c11 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -60,6 +60,8 @@ struct rpc_msg { - - rpc_msg_func func; /* msg handle func hook */ - union rpc_msg_arg args[RPM_MSG_ARG_SIZE]; /* resolve by type */ -+ -+ uint64_t time_stamp; /* rpc_call_* start time */ - }; - - static inline void rpc_queue_init(rpc_queue *queue) -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 8fe11c4..23edc19 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -224,7 +224,7 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - rte_mbuf_refcnt_update(mbuf, 1); - - if (get_protocol_stack_group()->latency_start) { -- calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LSTACK); -+ calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LSTACK, 0); - } - pbuf = pbuf->next; - } -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 91c6063..79c172b 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -881,11 +881,22 @@ static void gazelle_print_lstack_stat_latency(void *buf, const struct gazelle_st - gazelle_show_latency_result_total(buf, req_msg, res); - - printf("Statistics of lstack latency pkts min(us) max(us) average(us)\n"); -- printf("range: t0--->t3\n%s", res[GAZELLE_LATENCY_READ_LSTACK].latency_stat_result); -- printf("range: t0--->t2\n%s", res[GAZELLE_LATENCY_READ_LWIP].latency_stat_result); -- printf("range: t3--->t0\n%s", res[GAZELLE_LATENCY_WRITE_LSTACK].latency_stat_result); -- printf("range: t2--->t0\n%s", res[GAZELLE_LATENCY_WRITE_LWIP].latency_stat_result); -- printf("t0:read form/send to nic t1:into/out of lstask queue t2:into/out of app queue t3:app read/send\n"); -+ printf("Recv:\n"); -+ printf("range: t0--->t1\n%s", res[GAZELLE_LATENCY_READ_LWIP].latency_stat_result); -+ printf("range: t1--->t2\n%s", res[GAZELLE_LATENCY_READ_APP_CALL].latency_stat_result); -+ printf("range: t2--->t3\n%s", res[GAZELLE_LATENCY_READ_LSTACK].latency_stat_result); -+ printf("range: t0--->t3\n%s", res[GAZELLE_LATENCY_READ_MAX].latency_stat_result); -+ printf("t0: read from nic t1: into recv ring t2: app read start t3: app read end\n"); -+ -+ printf("Send:\n"); -+ printf("range: t0--->t1\n%s", res[GAZELLE_LATENCY_WRITE_INTO_RING].latency_stat_result); -+ printf("range: t1--->t2\n%s", res[GAZELLE_LATENCY_WRITE_LWIP].latency_stat_result); -+ printf("range: t2--->t3\n%s", res[GAZELLE_LATENCY_WRITE_LSTACK].latency_stat_result); -+ printf("range: t0--->t3\n%s", res[GAZELLE_LATENCY_WRITE_MAX].latency_stat_result); -+ printf("t0: app send t1: into send ring t2: out of send ring t3: send to nic\n"); -+ -+ printf("Rpc:\n"); -+ printf("rpc_call_send \n%s", res[GAZELLE_LATENCY_WRITE_RPC_MSG].latency_stat_result); - - free(res); - } --- -2.33.0 - diff --git a/0162-fix-vlan-filter-can-be-added-when-vlan_mode-1.patch b/0162-fix-vlan-filter-can-be-added-when-vlan_mode-1.patch deleted file mode 100644 index 05a56815af9c6b5e72be9aca84aa5939dfe12539..0000000000000000000000000000000000000000 --- a/0162-fix-vlan-filter-can-be-added-when-vlan_mode-1.patch +++ /dev/null @@ -1,33 +0,0 @@ -From c392e263cb5f5392713600174d3b8955f2d26759 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Wed, 3 Apr 2024 14:33:57 +0800 -Subject: [PATCH] fix vlan filter can be added when vlan_mode=-1 - ---- - src/lstack/core/lstack_dpdk.c | 10 ++++++---- - 1 file changed, 6 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 42981f4..b972c00 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -624,10 +624,12 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - } - - /* after rte_eth_dev_configure */ -- ret = rte_eth_dev_vlan_filter(port_id, get_global_cfg_params()->nic.vlan_mode, 1); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk add vlan filter failed ret = %d\n", ret); -- return -1; -+ if (get_global_cfg_params()->nic.vlan_mode != -1) { -+ ret = rte_eth_dev_vlan_filter(port_id, get_global_cfg_params()->nic.vlan_mode, 1); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk add vlan filter failed ret = %d\n", ret); -+ return -1; -+ } - } - - rte_eth_allmulticast_enable(port_id); --- -2.33.0 - diff --git a/0163-Add-support-for-arch-ppc64le.patch b/0163-Add-support-for-arch-ppc64le.patch deleted file mode 100644 index 7d42df30536876fe685028aa7e1f2d9819271b10..0000000000000000000000000000000000000000 --- a/0163-Add-support-for-arch-ppc64le.patch +++ /dev/null @@ -1,36 +0,0 @@ -From e89442aa3aebae9896a5d5dac0e397e5da16f8de Mon Sep 17 00:00:00 2001 -From: Ren Zhijie -Date: Mon, 25 Mar 2024 16:46:08 +0800 -Subject: [PATCH] Add support for arch ppc64le - -Signed-off-by: Ren Zhijie ---- - src/ltran/CMakeLists.txt | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt -index a484ae3..2eb7d70 100644 ---- a/src/ltran/CMakeLists.txt -+++ b/src/ltran/CMakeLists.txt -@@ -63,6 +63,9 @@ if (DPDK_VERSION GREATER_EQUAL 23.11) - set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -lrte_log -larchive -Wl,-lrte_eal") - else() - set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -lrte_kni -Wl,-Bstatic -lrte_eal -Wl,-Bdynamic") -+ if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "ppc64le") -+ set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-larchive") -+ endif() - endif() - - add_executable(ltran main.c ltran_param.c ltran_config.c ltran_ethdev.c ltran_stat.c ltran_errno.c -@@ -79,7 +82,7 @@ target_compile_options(ltran PRIVATE -fno-strict-aliasing -D__ARM_FEATURE_CRC32= - -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough -D_FORTIFY_SOURCE=2 -Wno-error=deprecated-declarations) - - # gcc coredump in openEuler-20.03-LTS-XX aarch64 when add -march=native --if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "sw_64|aarch64" ) -+if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "sw_64|aarch64|ppc64le" ) - target_compile_options(ltran PRIVATE -march=native -Wcast-align) - endif() - --- -2.33.0 - diff --git a/0164-dfx-support-get-nic-bond-status.patch b/0164-dfx-support-get-nic-bond-status.patch deleted file mode 100644 index af4f21a98f24c424572b981fda6e6229b0bf814e..0000000000000000000000000000000000000000 --- a/0164-dfx-support-get-nic-bond-status.patch +++ /dev/null @@ -1,120 +0,0 @@ -From 819f74f014592b8af93eb45fd13681caa2cb662a Mon Sep 17 00:00:00 2001 -From: zhangmengxuan -Date: Thu, 28 Mar 2024 21:24:05 +0800 -Subject: [PATCH] dfx: support get nic bond status - ---- - src/common/gazelle_dfx_msg.h | 9 +++++++++ - src/lstack/core/lstack_dpdk.c | 27 +++++++++++++++++++++++++++ - src/ltran/ltran_dfx.c | 14 ++++++++++++++ - 3 files changed, 50 insertions(+) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index d7ba80f..4929ae7 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -256,15 +256,24 @@ struct gazelle_stat_low_power_info { - - #define RTE_ETH_XSTATS_NAME_SIZE 64 - #define RTE_ETH_XSTATS_MAX_LEN 256 -+#define RTE_MAX_ETHPORTS 32 - struct nic_eth_xstats_name { - char name[RTE_ETH_XSTATS_NAME_SIZE]; - }; - -+struct bonding { -+ int8_t mode; -+ int32_t miimon; -+ uint16_t primary_port_id; -+ uint16_t slaves[RTE_MAX_ETHPORTS]; -+}; -+ - struct nic_eth_xstats { - struct nic_eth_xstats_name xstats_name[RTE_ETH_XSTATS_MAX_LEN]; - uint64_t values[RTE_ETH_XSTATS_MAX_LEN]; - uint32_t len; - uint16_t port_id; -+ struct bonding bonding; - }; - - struct nic_eth_features { -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index a774d45..cd87026 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -870,6 +870,31 @@ static int dpdk_nic_xstats_name_get(struct nic_eth_xstats_name *names, uint16_t - return len; - } - -+void dpdk_nic_bond_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id, uint16_t *slaves, int count) -+{ -+ dfx->data.nic_xstats.bonding.mode = rte_eth_bond_mode_get(port_id); -+ if (dfx->data.nic_xstats.bonding.mode < 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_bond_mode_get failed.\n"); -+ return; -+ } -+ -+ dfx->data.nic_xstats.bonding.primary_port_id = rte_eth_bond_primary_get(port_id); -+ if (dfx->data.nic_xstats.bonding.primary_port_id < 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_bond_primary_get failed.\n"); -+ return; -+ } -+ -+ dfx->data.nic_xstats.bonding.miimon = rte_eth_bond_link_monitoring_get(port_id); -+ if (dfx->data.nic_xstats.bonding.miimon <= 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_bond_link_monitoring_get failed.\n"); -+ return; -+ } -+ -+ for (int i = 0; i < count; i++) { -+ dfx->data.nic_xstats.bonding.slaves[i] = slaves[i]; -+ } -+} -+ - void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id) - { - struct rte_eth_dev_info dev_info; -@@ -878,6 +903,7 @@ void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id) - - dfx->data.nic_xstats.len = -1; - dfx->data.nic_xstats.port_id = port_id; -+ dfx->data.nic_xstats.bonding.mode = -1; - ret = rte_eth_dev_info_get(port_id, &dev_info); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "rte_eth_dev_info_get failed.\n"); -@@ -904,6 +930,7 @@ void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id) - if (dpdk_nic_xstats_value_get(dfx->data.nic_xstats.values, len, slaves, slave_count) != 0) { - return; - } -+ dpdk_nic_bond_xstats_get(dfx, port_id, slaves, slave_count); - } else { - len = dpdk_nic_xstats_name_get(dfx->data.nic_xstats.xstats_name, port_id); - if (len <= 0) { -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 073dfa7..88d11bd 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -200,6 +200,20 @@ static void gazelle_print_lstack_xstats(void *buf, const struct gazelle_stat_msg - struct nic_eth_xstats *xstats = &stat->data.nic_xstats; - static const char *nic_stats_border = "########################"; - -+ if (xstats->bonding.mode >= 0) { -+ printf("############# NIC bonding mode display #############\n"); -+ printf("%s############################\n", nic_stats_border); -+ printf("Bonding mode: [%d]\n", xstats->bonding.mode); -+ printf("Bonding miimon: [%d]\n", xstats->bonding.miimon); -+ printf("Slaves(%d): [", xstats->port_id); -+ for (int i = 0; i < xstats->port_id - 1; i++) { -+ printf("%d ", xstats->bonding.slaves[i]); -+ } -+ printf("%d]\n", xstats->bonding.slaves[xstats->port_id - 1]); -+ printf("Primary: [%d]\n", xstats->bonding.primary_port_id); -+ printf("%s############################\n", nic_stats_border); -+ } -+ - printf("###### NIC extended statistics for port %-2d #########\n", xstats->port_id); - printf("%s############################\n", nic_stats_border); - if (xstats->len <= 0 || xstats->len > RTE_ETH_XSTATS_MAX_LEN) { --- -2.33.0 - diff --git a/0165-remove-dpdk_skip_nic_init-for-dpdk-23.11.patch b/0165-remove-dpdk_skip_nic_init-for-dpdk-23.11.patch deleted file mode 100644 index c97b59f34b6474cfb5379050c75486c8245e14f6..0000000000000000000000000000000000000000 --- a/0165-remove-dpdk_skip_nic_init-for-dpdk-23.11.patch +++ /dev/null @@ -1,54 +0,0 @@ -From aae704235da3299fb2d6920aef46afd560ab2c01 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Tue, 9 Apr 2024 17:50:46 +0800 -Subject: [PATCH] remove dpdk_skip_nic_init for dpdk-23.11 - ---- - src/lstack/core/lstack_init.c | 4 ++++ - src/lstack/include/lstack_dpdk.h | 4 +++- - 2 files changed, 7 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index f1ef134..79b4060 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -144,7 +144,9 @@ static void create_control_thread(void) - pthread_t tid; - if (use_ltran()) { - /* The function call here should be in strict order. */ -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - dpdk_skip_nic_init(); -+#endif - if (control_init_client(false) != 0) { - LSTACK_EXIT(1, "control_init_client failed\n"); - } -@@ -279,7 +281,9 @@ __attribute__((constructor)) void gazelle_network_init(void) - - /* Init control plane and dpdk init */ - create_control_thread(); -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - dpdk_restore_pci(); -+#endif - - /* cancel the core binding from DPDK initialization */ - if (!get_global_cfg_params()->main_thread_affinity) { -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index c7cfbdf..fe3d07b 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -48,9 +48,11 @@ int32_t create_shared_ring(struct protocol_stack *stack); - void lstack_log_level_init(void); - int dpdk_ethdev_init(int port_id, bool bond_port); - int dpdk_ethdev_start(void); -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - void dpdk_skip_nic_init(void); --int32_t dpdk_init_lstack_kni(void); - void dpdk_restore_pci(void); -+#endif -+int32_t dpdk_init_lstack_kni(void); - bool port_in_stack_queue(gz_addr_t *src_ip, gz_addr_t *dst_ip, uint16_t src_port, uint16_t dst_port); - struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, - uint32_t mbuf_cache_size, uint16_t queue_id, unsigned numa_id); --- -2.33.0 - diff --git a/0166-gazellectl-add-lwip-stats_proto-print.patch b/0166-gazellectl-add-lwip-stats_proto-print.patch deleted file mode 100644 index bb4c27ff5d9a8dd9d7ff8de9f74fb0da6563eab9..0000000000000000000000000000000000000000 --- a/0166-gazellectl-add-lwip-stats_proto-print.patch +++ /dev/null @@ -1,317 +0,0 @@ -From 3beb273528f360c7d6863990a5d0cdcb5ebcb407 Mon Sep 17 00:00:00 2001 -From: ningjin -Date: Thu, 28 Mar 2024 16:05:01 +0800 -Subject: [PATCH] gazellectl add lwip stats_proto print - ---- - src/common/gazelle_dfx_msg.h | 23 ++++++++++ - src/lstack/core/lstack_control_plane.c | 2 +- - src/lstack/core/lstack_stack_stat.c | 41 +++++++++++++++-- - src/lstack/include/lstack_stack_stat.h | 3 +- - src/ltran/ltran_dfx.c | 61 +++++++++++++++++++++++++- - src/ltran/ltran_monitor.c | 1 + - 6 files changed, 124 insertions(+), 7 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index d7ba80f..6cd90b1 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -24,6 +24,7 @@ - - #define GAZELLE_CLIENT_NUM_MIN 1 - #define GAZELLE_LOG_LEVEL_MAX 10 -+#define MAX_PROTOCOL_LENGTH 20 - #define GAZELLECTL_TIMEOUT 5000 // millisecond - /* maybe it should be consistent with MEMP_NUM_TCP_PCB */ - #define GAZELLE_LSTACK_MAX_CONN (20000 + 2000) // same as MAX_CLIENTS + RESERVED_CLIENTS in lwipopts.h -@@ -46,6 +47,7 @@ enum GAZELLE_STAT_MODE { - GAZELLE_STAT_LTRAN_SHOW_SOCKTABLE, - GAZELLE_STAT_LTRAN_SHOW_CONNTABLE, - GAZELLE_STAT_LTRAN_SHOW_LSTACK, -+ GAZELLE_STAT_LSTACK_SHOW_PROTOCOL, - - GAZELLE_STAT_LSTACK_SHOW, - GAZELLE_STAT_LSTACK_LOG_LEVEL_SET, -@@ -193,6 +195,24 @@ struct gazelle_stat_lstack_snmp { - uint32_t icmp_out_echo_reps; - }; - -+/* same as define in lwip/stats.h - struct stats_proto */ -+struct gazelle_stat_lstack_proto { -+ /* data */ -+ uint16_t xmit; /* Transmitted packets. */ -+ uint16_t recv; /* Received packets. */ -+ uint16_t fw; /* Forwarded packets. */ -+ uint16_t drop; /* Dropped packets. */ -+ uint16_t chkerr; /* Checksum error. */ -+ uint16_t lenerr; /* Invalid length error. */ -+ uint16_t memerr; /* Out of memory error. */ -+ uint16_t rterr; /* Routing error. */ -+ uint16_t proterr; /* Protocol error. */ -+ uint16_t opterr; /* Error in options. */ -+ uint16_t err; /* Misc error. */ -+ uint16_t cachehit; -+}; -+ -+ - /* same as define in lwip/tcp.h - struct tcp_pcb_dp */ - struct gazelle_stat_lstack_conn_info { - uint32_t state; -@@ -288,6 +308,8 @@ struct gazelle_stack_dfx_data { - struct gazelle_stat_lstack_snmp snmp; - struct nic_eth_xstats nic_xstats; - struct nic_eth_features nic_features; -+ struct gazelle_stat_lstack_proto proto_data; -+ - #ifdef GAZELLE_FAULT_INJECT_ENABLE - struct gazelle_fault_inject_data inject; - #endif /* GAZELLE_FAULT_INJECT_ENABLE */ -@@ -321,6 +343,7 @@ struct gazelle_stat_msg_request { - union stat_param { - char log_level[GAZELLE_LOG_LEVEL_MAX]; - uint16_t low_power_mod; -+ char protocol[MAX_PROTOCOL_LENGTH]; - #ifdef GAZELLE_FAULT_INJECT_ENABLE - struct gazelle_fault_inject_data inject; - #endif /* GAZELLE_FAULT_INJECT_ENABLE */ -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 9f0c313..04858c7 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -601,7 +601,7 @@ static int32_t handle_stat_request(int32_t sockfd) - msg.stat_mode == GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES) { - return handle_dpdk_cmd(sockfd, msg.stat_mode); - } else { -- ret = handle_stack_cmd(sockfd, msg.stat_mode); -+ ret = handle_stack_cmd(sockfd, &msg); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "get_stats failed ret=%d\n", ret); - } -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 3e016b7..d439357 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -210,11 +210,42 @@ static void get_stack_stats(struct gazelle_stack_dfx_data *dfx, struct protocol_ - dfx->data.pkts.conn_num = stack->conn_num; - } - -+static void get_stack_dfx_data_proto(struct gazelle_stack_dfx_data *dfx, struct protocol_stack *stack, -+ struct gazelle_stat_msg_request *msg) -+{ -+ int32_t ret = 0; -+ msg->data.protocol[MAX_PROTOCOL_LENGTH - 1] = '\0'; -+ const char* proto_mode = msg->data.protocol; -+ -+ if (strcmp(proto_mode, "UDP") == 0) { -+ ret = memcpy_s(&dfx->data.proto_data, sizeof(dfx->data.proto_data), -+ &stack->lwip_stats->udp, sizeof(stack->lwip_stats->udp)); -+ } else if (strcmp(proto_mode, "TCP") == 0) { -+ ret = memcpy_s(&dfx->data.proto_data, sizeof(dfx->data.proto_data), -+ &stack->lwip_stats->tcp, sizeof(stack->lwip_stats->tcp)); -+ } else if (strcmp(proto_mode, "IP") == 0) { -+ ret = memcpy_s(&dfx->data.proto_data, sizeof(dfx->data.proto_data), -+ &stack->lwip_stats->ip, sizeof(stack->lwip_stats->ip)); -+ } else if (strcmp(proto_mode, "ICMP") == 0) { -+ ret = memcpy_s(&dfx->data.proto_data, sizeof(dfx->data.proto_data), -+ &stack->lwip_stats->icmp, sizeof(stack->lwip_stats->icmp)); -+ } else if (strcmp(proto_mode, "ETHARP") == 0) { -+ ret = memcpy_s(&dfx->data.proto_data, sizeof(dfx->data.proto_data), -+ &stack->lwip_stats->etharp, sizeof(stack->lwip_stats->etharp)); -+ } else { -+ printf("Error: Invalid protocol\n"); -+ } -+ if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "memcpy_s err ret=%d \n", ret); -+ } -+} -+ - static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protocol_stack *stack, -- enum GAZELLE_STAT_MODE stat_mode) -+ struct gazelle_stat_msg_request *msg) - { - int32_t rpc_call_result; - int32_t ret; -+ enum GAZELLE_STAT_MODE stat_mode = msg->stat_mode; - - switch (stat_mode) { - case GAZELLE_STAT_LSTACK_SHOW: -@@ -255,6 +286,9 @@ static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protoc - case GAZELLE_STAT_LTRAN_STOP_LATENCY: - set_latency_start_flag(false); - break; -+ case GAZELLE_STAT_LSTACK_SHOW_PROTOCOL: -+ get_stack_dfx_data_proto(dfx, stack, msg); -+ break; - default: - break; - } -@@ -298,16 +332,17 @@ int handle_dpdk_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode) - return 0; - } - --int handle_stack_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode) -+int handle_stack_cmd(int fd, struct gazelle_stat_msg_request *msg) - { - struct gazelle_stack_dfx_data dfx; - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ enum GAZELLE_STAT_MODE stat_mode = msg->stat_mode; - - for (uint32_t i = 0; i < stack_group->stack_num; i++) { - struct protocol_stack *stack = stack_group->stacks[i]; - - memset_s(&dfx, sizeof(dfx), 0, sizeof(dfx)); -- get_stack_dfx_data(&dfx, stack, stat_mode); -+ get_stack_dfx_data(&dfx, stack, msg); - - if (!use_ltran() && - (stat_mode == GAZELLE_STAT_LTRAN_START_LATENCY || stat_mode == GAZELLE_STAT_LTRAN_STOP_LATENCY)) { -diff --git a/src/lstack/include/lstack_stack_stat.h b/src/lstack/include/lstack_stack_stat.h -index 87951aa..867f35b 100644 ---- a/src/lstack/include/lstack_stack_stat.h -+++ b/src/lstack/include/lstack_stack_stat.handle -@@ -21,13 +21,14 @@ struct wakeup_poll; - struct protocol_stack; - enum GAZELLE_LATENCY_TYPE; - enum GAZELLE_STAT_MODE; -+struct gazelle_stat_msg_request; - - void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, - enum GAZELLE_LATENCY_TYPE type, uint64_t time_record); - void calculate_rpcmsg_latency(struct gazelle_stack_latency *stack_latency, struct rpc_msg *msg, - enum GAZELLE_LATENCY_TYPE type); - void stack_stat_init(void); --int handle_stack_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode); -+int handle_stack_cmd(int fd, struct gazelle_stat_msg_request *msg); - int handle_dpdk_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode); - uint64_t get_current_time(void); - void lstack_get_low_power_info(struct gazelle_stat_low_power_info *low_power_info); -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 073dfa7..717744a 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -136,6 +136,7 @@ static void gazelle_print_ltran_conn(void *buf, const struct gazelle_stat_msg_re - static void gazelle_print_lstack_xstats(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_aggregate(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_nic_features(void *buf, const struct gazelle_stat_msg_request *req_msg); -+static void gazelle_print_lstack_stat_proto(void *buf, const struct gazelle_stat_msg_request *req_msg); - - #ifdef GAZELLE_FAULT_INJECT_ENABLE - static void gazelle_print_fault_inject_set_status(void *buf, const struct gazelle_stat_msg_request *req_msg); -@@ -168,7 +169,8 @@ static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = { - {GAZELLE_STAT_LSTACK_SHOW_XSTATS, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_xstats}, - {GAZELLE_STAT_LSTACK_SHOW_AGGREGATE, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_aggregate}, - {GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_nic_features}, -- -+ {GAZELLE_STAT_LSTACK_SHOW_PROTOCOL, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_proto}, -+ - #ifdef GAZELLE_FAULT_INJECT_ENABLE - {GAZELLE_STAT_FAULT_INJECT_SET, sizeof(struct gazelle_stack_dfx_data), gazelle_print_fault_inject_set_status}, - {GAZELLE_STAT_FAULT_INJECT_UNSET, sizeof(struct gazelle_stack_dfx_data), gazelle_print_fault_inject_unset_status}, -@@ -1083,6 +1085,20 @@ static void gazelle_print_lstack_stat_snmp_core(const struct gazelle_stack_dfx_d - printf("icmp_out_echo_reps: %u\n", snmp->icmp_out_echo_reps); - } - -+static void gazelle_print_lstack_stat_proto_core(const struct gazelle_stack_dfx_data *stat, -+ const struct gazelle_stat_lstack_proto *proto) -+{ -+ printf("\n------ stack tid: %6u ------\n", stat->tid); -+ printf("xmit: %u\n", proto->xmit); -+ printf("recv: %u\n", proto->recv); -+ printf("fw: %u\n", proto->fw); -+ printf("drop: %u\n", proto->drop); -+ printf("chkerr: %u\n", proto->chkerr); -+ printf("lenerr: %u\n", proto->lenerr); -+ printf("memerr: %u\n", proto->memerr); -+ printf("rterr: %u\n", proto->rterr); -+} -+ - static void gazelle_print_lstack_stat_snmp(void *buf, const struct gazelle_stat_msg_request *req_msg) - { - int32_t ret; -@@ -1102,6 +1118,26 @@ static void gazelle_print_lstack_stat_snmp(void *buf, const struct gazelle_stat_ - } while (true); - } - -+static void gazelle_print_lstack_stat_proto(void *buf, const struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t ret; -+ struct gazelle_stack_dfx_data *stat = (struct gazelle_stack_dfx_data *)buf; -+ struct gazelle_stat_lstack_proto *proto = NULL; -+ -+ proto = &stat->data.proto_data; -+ printf("Statistics of lstack proto:\n"); -+ do { -+ gazelle_print_lstack_stat_proto_core(stat, proto); -+ if (stat->eof != 0) { -+ break; -+ } -+ ret = dfx_stat_read_from_ltran(buf, sizeof(struct gazelle_stack_dfx_data), req_msg->stat_mode); -+ if (ret != GAZELLE_OK) { -+ return; -+ } -+ } while (true); -+} -+ - static void gazelle_keepalive_string(char* str, int buff_len, struct gazelle_stat_lstack_conn_info *conn_info) - { - if (conn_info->keepalive == 0) { -@@ -1240,6 +1276,7 @@ static void show_usage(void) - " loglevel {error | info | debug} set lstack loglevel \n" - " lowpower {0 | 1} set lowpower enable \n" - " [time] measure latency time default 1S, maximum 30mins \n\n" -+ " -p, protocol {UDP | TCP | ICMP | IP | ETHARP | IP_FRAG} show lstack protocol statistics \n" - #ifdef GAZELLE_FAULT_INJECT_ENABLE - " *inject params*\n" - " |inject_type | digit_param_1 | digit_param_2 | inject_rule |\n" -@@ -1444,6 +1481,25 @@ static int parse_delay_arg(int32_t argc, char *argv[], long int delay) - return 0; - } - -+static int32_t parse_dfx_lstack_show_proto_args(int32_t argc, char *argv[], struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t cmd_index = 0; -+ int32_t ret; -+ -+ char *param = argv[GAZELLE_OPTIONS2_ARG_IDX]; -+ if (strcmp(param, "UDP") != 0 && strcmp(param, "TCP") != 0 && strcmp(param, "IP") && -+ strcmp(param, "ICMP") && strcmp(param, "ETHARP") != 0) { -+ return cmd_index; -+ } -+ ret = strncpy_s(req_msg[cmd_index].data.protocol, MAX_PROTOCOL_LENGTH, argv[GAZELLE_OPTIONS2_ARG_IDX], -+ MAX_PROTOCOL_LENGTH - 1); -+ if (ret != EOK) { -+ return -1; -+ } -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_PROTOCOL; -+ return cmd_index; -+} -+ - static int32_t parse_dfx_lstack_show_args(int32_t argc, char *argv[], struct gazelle_stat_msg_request *req_msg) - { - int32_t cmd_index = 0; -@@ -1490,8 +1546,9 @@ static int32_t parse_dfx_lstack_show_args(int32_t argc, char *argv[], struct gaz - } - } else if (strcmp(param, "-k") == 0 || strcmp(param, "nic-features") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES; -+ } else if (strcmp(param, "protocol") == 0 || strcmp(param, "-p") == 0) { -+ cmd_index = parse_dfx_lstack_show_proto_args(argc, argv, req_msg); - } -- - return cmd_index; - } - -diff --git a/src/ltran/ltran_monitor.c b/src/ltran/ltran_monitor.c -index ea31e84..457e8c8 100644 ---- a/src/ltran/ltran_monitor.c -+++ b/src/ltran/ltran_monitor.c -@@ -347,6 +347,7 @@ static int32_t lstack_req_mode_process(int32_t fd, const struct gazelle_stat_msg - case GAZELLE_STAT_LSTACK_SHOW_CONN: - case GAZELLE_STAT_LSTACK_SHOW_LATENCY: - case GAZELLE_STAT_LSTACK_LOW_POWER_MDF: -+ case GAZELLE_STAT_LSTACK_SHOW_PROTOCOL: - handle_resp_lstack_transfer(req_msg, fd); - break; - default: --- -2.33.0 - diff --git a/0167-fix-port-not-support-vlan-filter.patch b/0167-fix-port-not-support-vlan-filter.patch deleted file mode 100644 index 3083078e8667d9905b8315d09b7bbf7909367d77..0000000000000000000000000000000000000000 --- a/0167-fix-port-not-support-vlan-filter.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 3171100d06146791ab9d22523805b8ed580daf3f Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Fri, 12 Apr 2024 15:09:12 +0800 -Subject: [PATCH] fix port not support vlan filter - ---- - src/lstack/core/lstack_dpdk.c | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index a6a8a01..5d90408 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -624,7 +624,8 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - } - - /* after rte_eth_dev_configure */ -- if (get_global_cfg_params()->nic.vlan_mode != -1) { -+ if ((get_global_cfg_params()->nic.vlan_mode != -1) && -+ ((stack_group->rx_offload & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) == RTE_ETH_RX_OFFLOAD_VLAN_FILTER)) { - ret = rte_eth_dev_vlan_filter(port_id, get_global_cfg_params()->nic.vlan_mode, 1); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk add vlan filter failed ret = %d\n", ret); --- -2.33.0 - diff --git a/0168-fix-tcp-recv-does-not-return-pkg-when-ring-buffer-is.patch b/0168-fix-tcp-recv-does-not-return-pkg-when-ring-buffer-is.patch deleted file mode 100644 index 01ded107f0facf828c078bdeef3e9d6059bcd4d2..0000000000000000000000000000000000000000 --- a/0168-fix-tcp-recv-does-not-return-pkg-when-ring-buffer-is.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 5fff605ff68741482d7fff992343eaccb383115f Mon Sep 17 00:00:00 2001 -From: li_yunqing -Date: Fri, 22 Mar 2024 15:47:19 +0800 -Subject: [PATCH] fix tcp recv does not return pkg when ring buffer is empty - ---- - src/lstack/core/lstack_lwip.c | 4 +++- - 1 file changed, 3 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index a604a62..51238ba 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -925,7 +925,9 @@ static ssize_t recv_ring_tcp_read(struct lwip_sock *sock, void *buf, size_t len, - } - - while (recv_left > 0) { -- if (recv_ring_get_one(sock, noblock, &pbuf) != 0) { -+ if (recv_ring_get_one(sock, noblock | recvd, &pbuf) != 0) { -+ /* When the buffer is empty, it will be returned directly -+ if in non-blocking mode or if data has already been received */ - break; - } - --- -2.33.0 - diff --git a/0169-add-tuple_fileter-error-info.patch b/0169-add-tuple_fileter-error-info.patch deleted file mode 100644 index e15770e7a616f2c799068e7298aeb788241efbcd..0000000000000000000000000000000000000000 --- a/0169-add-tuple_fileter-error-info.patch +++ /dev/null @@ -1,24 +0,0 @@ -From e4d3f17fbb3efce9e29c86838a09fa1f9e224fd3 Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Tue, 16 Apr 2024 03:46:12 +0000 -Subject: [PATCH] add tuple_fileter error info - ---- - src/lstack/core/lstack_cfg.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index b533a33..533eb6c 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -1159,6 +1159,7 @@ static int parse_tuple_filter(void) - return 0; - } - if (g_config_params.use_ltran || g_config_params.listen_shadow) { -+ LSTACK_LOG(ERR, LSTACK, "tuple filter and (ltran or listen_shadow) cannot be enabled at the same time\n"); - return -EINVAL; - } - --- -2.33.0 - diff --git a/0170-adapt-dpdk-23.11-remove-kni.patch b/0170-adapt-dpdk-23.11-remove-kni.patch deleted file mode 100644 index f264f5de609cdf21fcbea9567efb100a9e5e1340..0000000000000000000000000000000000000000 --- a/0170-adapt-dpdk-23.11-remove-kni.patch +++ /dev/null @@ -1,80 +0,0 @@ -From 201e8d1e2fad0d83ea1544fd14b35492d8dd72bc Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 17 Apr 2024 15:43:07 +0800 -Subject: [PATCH] adapt dpdk-23.11 remove kni - ---- - src/lstack/core/lstack_dpdk.c | 4 +++- - src/lstack/core/lstack_init.c | 4 ++++ - 2 files changed, 7 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 5d90408..016276a 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -694,6 +694,7 @@ int32_t dpdk_ethdev_start(void) - return 0; - } - -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - int32_t dpdk_init_lstack_kni(void) - { - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -@@ -712,7 +713,6 @@ int32_t dpdk_init_lstack_kni(void) - return 0; - } - --#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - void dpdk_skip_nic_init(void) - { - /* when lstack init nic again, ltran can't read pkts from nic. unregister pci_bus to avoid init nic in lstack */ -@@ -799,12 +799,14 @@ int32_t init_dpdk_ethdev(void) - } - } - -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - if (get_global_cfg_params()->kni_switch && get_global_cfg_params()->is_primary) { - ret = dpdk_init_lstack_kni(); - if (ret < 0) { - return -1; - } - } -+#endif - - return 0; - } -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 79b4060..c2499d7 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -183,6 +183,7 @@ static void gazelle_signal_init(void) - lstack_signal_init(); - } - -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - static void set_kni_ip_mac() - { - struct cfg_params *cfg = get_global_cfg_params(); -@@ -230,6 +231,7 @@ static void set_kni_ip_mac() - - posix_api->close_fn(fd); - } -+#endif - - __attribute__((constructor)) void gazelle_network_init(void) - { -@@ -315,9 +317,11 @@ __attribute__((constructor)) void gazelle_network_init(void) - /* lwip initialization */ - lwip_sock_init(); - -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - if (get_global_cfg_params()->kni_switch) { - set_kni_ip_mac(); - } -+#endif - - if (set_process_start_flag() != 0) { - gazelle_exit(); --- -2.33.0 - diff --git a/0171-fix-ioctl-set-failed.patch b/0171-fix-ioctl-set-failed.patch deleted file mode 100644 index e1cfefcd06ce86086bce3654d753dbea2a66f49e..0000000000000000000000000000000000000000 --- a/0171-fix-ioctl-set-failed.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 5924fd2879acbb52b12a61380b939cce30a133a9 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sun, 28 Apr 2024 10:44:15 +0800 -Subject: [PATCH] fix ioctl set failed - ---- - src/lstack/api/lstack_wrap.c | 24 +++++++++++++++++++----- - 1 file changed, 19 insertions(+), 5 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index c90aa04..7101d98 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -690,13 +690,27 @@ static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set - if (select_posix_path() == PATH_KERNEL || \ - select_fd_posix_path(_fd, &sock) == PATH_KERNEL) \ - return _fcntl_fn(_fd, _cmd, val); \ -- int32_t ret = _fcntl_fn(_fd, _cmd, val); \ -- if (ret == -1) \ -- return ret; \ -- return _lwip_fcntl(_fd, _cmd, val); \ -+ int32_t ret1 = _fcntl_fn(_fd, _cmd, val); \ -+ if (ret1 == -1) { \ -+ LSTACK_LOG(ERR, LSTACK, "fd(%d) kernel path call failed, errno is %d, maybe not error\n", \ -+ _fd, errno); \ -+ return ret1; \ -+ } \ -+ int32_t ret2 = _lwip_fcntl(_fd, _cmd, val); \ -+ /* -+ * if function not implemented, fcntl get/set context will not be modifyed by user path, -+ * return kernel path result -+ */ \ -+ if (ret2 == -1) { \ -+ if (errno == ENOSYS) { \ -+ return ret1; \ -+ } \ -+ LSTACK_LOG(ERR, LSTACK, "fd(%d) user path call failed, errno is %d, maybe not error\n", \ -+ _fd, errno); \ -+ } \ -+ return ret2; \ - } while (0) - -- - /* -------------------------------------------------------- - * ------- LD_PRELOAD mode replacement interface -------- - * -------------------------------------------------------- --- -2.33.0 - diff --git a/0172-ltran-memset-quintuple.patch b/0172-ltran-memset-quintuple.patch deleted file mode 100644 index 94a2d369d469f664ffd456ebeff8ffd44364d456..0000000000000000000000000000000000000000 --- a/0172-ltran-memset-quintuple.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 3e10c7661d412082990d88d479c02d77c14fbd8c Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Tue, 30 Apr 2024 09:56:59 +0800 -Subject: [PATCH] ltran: memset quintuple - ---- - src/ltran/ltran_forward.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c -index a5756d7..0658b11 100644 ---- a/src/ltran/ltran_forward.c -+++ b/src/ltran/ltran_forward.c -@@ -251,7 +251,7 @@ static __rte_always_inline int32_t tcp_handle(struct rte_mbuf *m, const struct r - { - struct gazelle_tcp_conn *tcp_conn = NULL; - struct gazelle_tcp_sock *tcp_sock = NULL; -- struct gazelle_quintuple quintuple; -+ struct gazelle_quintuple quintuple = {0}; - - quintuple.dst_ip.u_addr.ip4.addr = ipv4_hdr->dst_addr; - quintuple.src_ip.u_addr.ip4.addr = ipv4_hdr->src_addr; --- -2.33.0 - diff --git a/0173-gazellectl-add-lwip-stats_proto-print.patch b/0173-gazellectl-add-lwip-stats_proto-print.patch deleted file mode 100644 index 82ec1dd1f9d19cc741e983dc4bfc00e5b0080d2a..0000000000000000000000000000000000000000 --- a/0173-gazellectl-add-lwip-stats_proto-print.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 62297e7fb9299a75bc582b1abb4343e88e5c7c05 Mon Sep 17 00:00:00 2001 -From: ningjin -Date: Thu, 28 Mar 2024 16:05:01 +0800 -Subject: [PATCH] gazellectl add lwip stats_proto print - ---- - src/common/gazelle_dfx_msg.h | 4 ++++ - src/ltran/ltran_dfx.c | 12 +++++++----- - 2 files changed, 11 insertions(+), 5 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 5d626a2..17e1662 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -206,6 +206,10 @@ struct gazelle_stat_lstack_proto { - /* data */ - uint16_t xmit; /* Transmitted packets. */ - uint16_t recv; /* Received packets. */ -+ uint16_t tx_in; /* Transmitted in packets. */ -+ uint16_t tx_out; /* Transmitted out packets. */ -+ uint16_t rx_in; /* Received in packets. */ -+ uint16_t rx_out; /* Received out packets. */ - uint16_t fw; /* Forwarded packets. */ - uint16_t drop; /* Dropped packets. */ - uint16_t chkerr; /* Checksum error. */ -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index c81cce2..f4e55e3 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -1114,8 +1114,10 @@ static void gazelle_print_lstack_stat_proto_core(const struct gazelle_stack_dfx_ - const struct gazelle_stat_lstack_proto *proto) - { - printf("\n------ stack tid: %6u ------\n", stat->tid); -- printf("xmit: %u\n", proto->xmit); -- printf("recv: %u\n", proto->recv); -+ printf("tx_in: %u\n", proto->tx_in); -+ printf("tx_out: %u\n", proto->tx_out); -+ printf("rx_in: %u\n", proto->rx_in); -+ printf("rx_out: %u\n", proto->rx_out); - printf("fw: %u\n", proto->fw); - printf("drop: %u\n", proto->drop); - printf("chkerr: %u\n", proto->chkerr); -@@ -1297,11 +1299,11 @@ static void show_usage(void) - " -x, xstats show lstack xstats \n" - " -k, nic-features show state of protocol offload and other features \n" - " -a, aggregatin [time] show lstack send/recv aggregation \n" -+ " -p, protocol {UDP | TCP | ICMP | IP | ETHARP} show lstack protocol statistics \n" - " set: \n" - " loglevel {error | info | debug} set lstack loglevel \n" - " lowpower {0 | 1} set lowpower enable \n" - " [time] measure latency time default 1S, maximum 30mins \n\n" -- " -p, protocol {UDP | TCP | ICMP | IP | ETHARP | IP_FRAG} show lstack protocol statistics \n" - #ifdef GAZELLE_FAULT_INJECT_ENABLE - " *inject params*\n" - " |inject_type | digit_param_1 | digit_param_2 | inject_rule |\n" -@@ -1512,8 +1514,8 @@ static int32_t parse_dfx_lstack_show_proto_args(int32_t argc, char *argv[], stru - int32_t ret; - - char *param = argv[GAZELLE_OPTIONS2_ARG_IDX]; -- if (strcmp(param, "UDP") != 0 && strcmp(param, "TCP") != 0 && strcmp(param, "IP") && -- strcmp(param, "ICMP") && strcmp(param, "ETHARP") != 0) { -+ if ((param == NULL) || (strcmp(param, "UDP") != 0 && strcmp(param, "TCP") != 0 && strcmp(param, "IP") && -+ strcmp(param, "ICMP") && strcmp(param, "ETHARP") != 0)) { - return cmd_index; - } - ret = strncpy_s(req_msg[cmd_index].data.protocol, MAX_PROTOCOL_LENGTH, argv[GAZELLE_OPTIONS2_ARG_IDX], --- -2.33.0 - diff --git a/0174-CFG-set-multicast-IP-assert.patch b/0174-CFG-set-multicast-IP-assert.patch deleted file mode 100644 index 0bdb20e0cf394cf498c371dde1d0662ea3b90ceb..0000000000000000000000000000000000000000 --- a/0174-CFG-set-multicast-IP-assert.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 38f5dbd34dfede9fc4a22c89903132fafc01fc6d Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Mon, 29 Apr 2024 17:07:15 +0800 -Subject: [PATCH] CFG:set multicast IP assert - ---- - src/lstack/core/lstack_cfg.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 533eb6c..319a720 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -244,6 +244,11 @@ static int32_t parse_host_addr(void) - if (g_config_params.host_addr.addr == INADDR_NONE) { - return -EINVAL; - } -+ -+ if (IN_MULTICAST(g_config_params.host_addr.addr)) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: host_addr:%s should not be a multicast IP.", value); -+ return -EINVAL; -+ } - return 0; - } - --- -2.33.0 - diff --git a/0175-cfg-devices-must-be-in-bond_slave_mac-for-BONDING_MO.patch b/0175-cfg-devices-must-be-in-bond_slave_mac-for-BONDING_MO.patch deleted file mode 100644 index fef0c395e35b77bc0937d1444a655571d9cdc310..0000000000000000000000000000000000000000 --- a/0175-cfg-devices-must-be-in-bond_slave_mac-for-BONDING_MO.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 82ad5f93a2bd11411fec78ec7bcb26d6055fdfda Mon Sep 17 00:00:00 2001 -From: zhangmengxuan -Date: Mon, 29 Apr 2024 10:43:37 +0800 -Subject: [PATCH] cfg: devices must be in bond_slave_mac for - BONDING_MODE_ACTIVE - ---- - src/lstack/core/lstack_cfg.c | 16 ++++++++++++++++ - 1 file changed, 16 insertions(+) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 533eb6c..8073dd4 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -1210,6 +1210,16 @@ static int32_t parse_bond_miimon(void) - return ret; - } - -+static bool validate_bond_mac(uint8_t *mac_addr, struct rte_ether_addr *bond_slave_mac, int num_slaves) -+{ -+ for (int i = 0; i < num_slaves; i++) { -+ if (memcmp(mac_addr, bond_slave_mac[i].addr_bytes, ETHER_ADDR_LEN) == 0) { -+ return true; -+ } -+ } -+ return false; -+} -+ - static int32_t parse_bond_slave_mac(void) - { - if (g_config_params.bond_mode == -1) { -@@ -1252,6 +1262,12 @@ static int32_t parse_bond_slave_mac(void) - k = k + 1; - } - free(bond_slave_mac_tmp); -+ if (g_config_params.bond_mode == BONDING_MODE_ACTIVE_BACKUP) { -+ if (!validate_bond_mac(g_config_params.mac_addr, g_config_params.bond_slave_mac_addr, GAZELLE_MAX_BOND_NUM)) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: devices must be in bond_slave_mac for BONDING_MODE_ACTIVE_BACKUP.\n"); -+ return -EINVAL; -+ } -+ } - return ret; - } - --- -2.33.0 - diff --git a/0176-CFG-fix-multicast-IP-assert-error.patch b/0176-CFG-fix-multicast-IP-assert-error.patch deleted file mode 100644 index ec26a4b9c54030ed165055cbeb78420dc2584161..0000000000000000000000000000000000000000 --- a/0176-CFG-fix-multicast-IP-assert-error.patch +++ /dev/null @@ -1,25 +0,0 @@ -From f9407c8871223cef6dfbc66afb89a3b1b13b811a Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Wed, 8 May 2024 16:32:44 +0800 -Subject: [PATCH] CFG:fix multicast IP assert error - ---- - src/lstack/core/lstack_cfg.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 7967bb7..9efdbaa 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -245,7 +245,7 @@ static int32_t parse_host_addr(void) - return -EINVAL; - } - -- if (IN_MULTICAST(g_config_params.host_addr.addr)) { -+ 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); - return -EINVAL; - } --- -2.33.0 - diff --git a/0177-fix-mbuf-leak-in-dpdk-23.11-due-to-kni-removed.patch b/0177-fix-mbuf-leak-in-dpdk-23.11-due-to-kni-removed.patch deleted file mode 100644 index 042fd0404c404a74f0da4b2a8f23577081e4a2f6..0000000000000000000000000000000000000000 --- a/0177-fix-mbuf-leak-in-dpdk-23.11-due-to-kni-removed.patch +++ /dev/null @@ -1,82 +0,0 @@ -From 27af442164cce5ccb7df65435f76262ebb2d810e Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Thu, 9 May 2024 15:27:48 +0800 -Subject: [PATCH] fix mbuf leak in dpdk-23.11 due to kni removed - ---- - src/lstack/core/lstack_dpdk.c | 3 +++ - src/lstack/core/lstack_protocol_stack.c | 3 ++- - src/lstack/netif/lstack_ethdev.c | 2 ++ - src/ltran/ltran_forward.c | 5 ++++- - 4 files changed, 11 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 016276a..ec35f9c 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -321,6 +321,9 @@ int32_t fill_mbuf_to_ring(struct rte_mempool *mempool, struct rte_ring *ring, ui - ret = gazelle_ring_sp_enqueue(ring, (void **)free_buf, batch); - if (ret == 0) { - LSTACK_LOG(ERR, LSTACK, "cannot enqueue to ring, count: %u\n", batch); -+ for (int i = 0; i < batch; i++) { -+ rte_pktmbuf_free(free_buf[i]); -+ } - return -1; - } - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 04d54c5..892c16d 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -937,16 +937,17 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - - ret = rpc_call_arp(&stack->rpc_queue, mbuf_copy); - if (ret != 0) { -+ rte_pktmbuf_free(mbuf_copy); - return; - } - } -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); - if (ret != 0) { - cur_stack->stats.rx_allocmbuf_fail++; - return; - } - copy_mbuf(mbuf_copy, mbuf); --#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - kni_handle_tx(mbuf_copy); - #endif - return; -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 23edc19..048ea92 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -173,6 +173,8 @@ int32_t eth_dev_poll(void) - } else if (transfer_type == TRANSFER_KERNEL) { - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - kni_handle_tx(stack->pkts[i]); -+#else -+ rte_pktmbuf_free(stack->pkts[i]); - #endif - } else { - /* transfer to other thread */ -diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c -index a5756d7..d27f073 100644 ---- a/src/ltran/ltran_forward.c -+++ b/src/ltran/ltran_forward.c -@@ -424,8 +424,11 @@ forward_to_kni: - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - if (get_ltran_config()->dpdk.kni_switch == GAZELLE_ON) { - enqueue_rx_packet(get_kni_stack(), m); -- } -+ } else - #endif -+ { -+ rte_pktmbuf_free(m); -+ } - return; - } - --- -2.33.0 - diff --git a/0178-add-riscv64-support.patch b/0178-add-riscv64-support.patch deleted file mode 100644 index a1cbcb72e5d098db10ca977cc211f1c3d00ee7c2..0000000000000000000000000000000000000000 --- a/0178-add-riscv64-support.patch +++ /dev/null @@ -1,48 +0,0 @@ -From c17a61a4e7872af8eabdf213f71ff8aad84687ad Mon Sep 17 00:00:00 2001 -From: laokz -Date: Thu, 9 May 2024 18:44:28 +0800 -Subject: [PATCH] add riscv64 support - ---- - src/lstack/Makefile | 2 +- - src/ltran/CMakeLists.txt | 4 ++-- - 2 files changed, 3 insertions(+), 3 deletions(-) - -diff --git a/src/lstack/Makefile b/src/lstack/Makefile -index d2c039d..ace33bd 100644 ---- a/src/lstack/Makefile -+++ b/src/lstack/Makefile -@@ -109,7 +109,7 @@ else - $(LIB_PATH)/librte_net_virtio.so \ - $(LIB_PATH)/librte_telemetry.so \ - $(LIB_PATH)/librte_pcapng.so -- ifneq ($(ARCH), loongarch64) -+ ifeq ($(filter loongarch64 riscv64, $(ARCH)),) - LIBRTE_LIB += $(LIB_PATH)/librte_net_i40e.so - endif - endif -diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt -index 2eb7d70..fee3a94 100644 ---- a/src/ltran/CMakeLists.txt -+++ b/src/ltran/CMakeLists.txt -@@ -54,7 +54,7 @@ if (DPDK_VERSION STREQUAL "19.11") - else() - set(DPDK_LINK_FLAGS "-Wl,-lrte_net_bond -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe \ - -Wl,-lpcap -Wl,-lrte_net_pcap -Wl,-lrte_net_virtio -Wl,-lrte_pcapng -Wl,-lrte_telemetry") -- if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "loongarch64") -+ if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "loongarch64|riscv64") - set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-lrte_net_i40e") - endif() - endif() -@@ -82,7 +82,7 @@ target_compile_options(ltran PRIVATE -fno-strict-aliasing -D__ARM_FEATURE_CRC32= - -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough -D_FORTIFY_SOURCE=2 -Wno-error=deprecated-declarations) - - # gcc coredump in openEuler-20.03-LTS-XX aarch64 when add -march=native --if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "sw_64|aarch64|ppc64le" ) -+if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "sw_64|aarch64|ppc64le|riscv64" ) - target_compile_options(ltran PRIVATE -march=native -Wcast-align) - endif() - --- -2.33.0 - diff --git a/0179-dfx-fix-gazellectl-x-for-bond.patch b/0179-dfx-fix-gazellectl-x-for-bond.patch deleted file mode 100644 index f9c46fe0f673620cc684fe307e3a94b08139f881..0000000000000000000000000000000000000000 --- a/0179-dfx-fix-gazellectl-x-for-bond.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 3c3f69c0ca77b3d05df27aeda2fb7daa9757f50c Mon Sep 17 00:00:00 2001 -From: zhangmengxuan -Date: Mon, 13 May 2024 14:51:18 +0800 -Subject: [PATCH] dfx: fix gazellectl -x for bond - ---- - src/common/gazelle_dfx_msg.h | 1 + - src/lstack/core/lstack_dpdk.c | 2 ++ - src/ltran/ltran_dfx.c | 7 ++++--- - 3 files changed, 7 insertions(+), 3 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 17e1662..9f88203 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -296,6 +296,7 @@ struct bonding { - int32_t miimon; - uint16_t primary_port_id; - uint16_t slaves[RTE_MAX_ETHPORTS]; -+ uint16_t slave_count; - }; - - struct nic_eth_xstats { -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index ec35f9c..f1a22ea 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -905,6 +905,8 @@ void dpdk_nic_bond_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_ - return; - } - -+ dfx->data.nic_xstats.bonding.slave_count = count; -+ - for (int i = 0; i < count; i++) { - dfx->data.nic_xstats.bonding.slaves[i] = slaves[i]; - } -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index f4e55e3..aa08f25 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -207,11 +207,12 @@ static void gazelle_print_lstack_xstats(void *buf, const struct gazelle_stat_msg - printf("%s############################\n", nic_stats_border); - printf("Bonding mode: [%d]\n", xstats->bonding.mode); - printf("Bonding miimon: [%d]\n", xstats->bonding.miimon); -- printf("Slaves(%d): [", xstats->port_id); -- for (int i = 0; i < xstats->port_id - 1; i++) { -+ printf("Port range: 0->%d; Bonding port is %d\n", xstats->port_id, xstats->port_id); -+ printf("Slaves(%d): [", xstats->bonding.slave_count); -+ for (int i = 0; i < xstats->bonding.slave_count - 1; i++) { - printf("%d ", xstats->bonding.slaves[i]); - } -- printf("%d]\n", xstats->bonding.slaves[xstats->port_id - 1]); -+ printf("%d]\n", xstats->bonding.slaves[xstats->bonding.slave_count - 1]); - printf("Primary: [%d]\n", xstats->bonding.primary_port_id); - printf("%s############################\n", nic_stats_border); - } --- -2.33.0 - diff --git a/0180-change-gazelle_stat_lstack_proto-from-u16-to-u64.patch b/0180-change-gazelle_stat_lstack_proto-from-u16-to-u64.patch deleted file mode 100644 index bac10b515de40c51c107353074b899c22a88cb38..0000000000000000000000000000000000000000 --- a/0180-change-gazelle_stat_lstack_proto-from-u16-to-u64.patch +++ /dev/null @@ -1,87 +0,0 @@ -From f9872991239cc4ddcd9b3c706cf135cdbea28a48 Mon Sep 17 00:00:00 2001 -From: ningjin -Date: Tue, 21 May 2024 10:23:49 +0800 -Subject: [PATCH] change gazelle_stat_lstack_proto from u16 to u64 - ---- - src/common/gazelle_dfx_msg.h | 32 ++++++++++++++++---------------- - src/ltran/ltran_dfx.c | 20 ++++++++++---------- - 2 files changed, 26 insertions(+), 26 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 9f88203..cad7978 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -204,22 +204,22 @@ struct gazelle_stat_lstack_snmp { - /* same as define in lwip/stats.h - struct stats_proto */ - struct gazelle_stat_lstack_proto { - /* data */ -- uint16_t xmit; /* Transmitted packets. */ -- uint16_t recv; /* Received packets. */ -- uint16_t tx_in; /* Transmitted in packets. */ -- uint16_t tx_out; /* Transmitted out packets. */ -- uint16_t rx_in; /* Received in packets. */ -- uint16_t rx_out; /* Received out packets. */ -- uint16_t fw; /* Forwarded packets. */ -- uint16_t drop; /* Dropped packets. */ -- uint16_t chkerr; /* Checksum error. */ -- uint16_t lenerr; /* Invalid length error. */ -- uint16_t memerr; /* Out of memory error. */ -- uint16_t rterr; /* Routing error. */ -- uint16_t proterr; /* Protocol error. */ -- uint16_t opterr; /* Error in options. */ -- uint16_t err; /* Misc error. */ -- uint16_t cachehit; -+ uint64_t xmit; /* Transmitted packets. */ -+ uint64_t recv; /* Received packets. */ -+ uint64_t tx_in; /* Transmitted in packets. */ -+ uint64_t tx_out; /* Transmitted out packets. */ -+ uint64_t rx_in; /* Received in packets. */ -+ uint64_t rx_out; /* Received out packets. */ -+ uint64_t fw; /* Forwarded packets. */ -+ uint64_t drop; /* Dropped packets. */ -+ uint64_t chkerr; /* Checksum error. */ -+ uint64_t lenerr; /* Invalid length error. */ -+ uint64_t memerr; /* Out of memory error. */ -+ uint64_t rterr; /* Routing error. */ -+ uint64_t proterr; /* Protocol error. */ -+ uint64_t opterr; /* Error in options. */ -+ uint64_t err; /* Misc error. */ -+ uint64_t cachehit; - }; - - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index aa08f25..319f7cd 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -1115,16 +1115,16 @@ static void gazelle_print_lstack_stat_proto_core(const struct gazelle_stack_dfx_ - const struct gazelle_stat_lstack_proto *proto) - { - printf("\n------ stack tid: %6u ------\n", stat->tid); -- printf("tx_in: %u\n", proto->tx_in); -- printf("tx_out: %u\n", proto->tx_out); -- printf("rx_in: %u\n", proto->rx_in); -- printf("rx_out: %u\n", proto->rx_out); -- printf("fw: %u\n", proto->fw); -- printf("drop: %u\n", proto->drop); -- printf("chkerr: %u\n", proto->chkerr); -- printf("lenerr: %u\n", proto->lenerr); -- printf("memerr: %u\n", proto->memerr); -- printf("rterr: %u\n", proto->rterr); -+ printf("tx_in: %lu\n", proto->tx_in); -+ printf("tx_out: %lu\n", proto->tx_out); -+ printf("rx_in: %lu\n", proto->rx_in); -+ printf("rx_out: %lu\n", proto->rx_out); -+ printf("fw: %lu\n", proto->fw); -+ printf("drop: %lu\n", proto->drop); -+ printf("chkerr: %lu\n", proto->chkerr); -+ printf("lenerr: %lu\n", proto->lenerr); -+ printf("memerr: %lu\n", proto->memerr); -+ printf("rterr: %lu\n", proto->rterr); - } - - static void gazelle_print_lstack_stat_snmp(void *buf, const struct gazelle_stat_msg_request *req_msg) --- -2.33.0 - diff --git a/0181-memary-error-fix-some-memary-error.patch b/0181-memary-error-fix-some-memary-error.patch deleted file mode 100644 index 8c602ffb99f3ad95ae0c59041f02e0887a21b359..0000000000000000000000000000000000000000 --- a/0181-memary-error-fix-some-memary-error.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 7b859a1e3dbb8ed719035942040a581982d71508 Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Sat, 18 May 2024 17:27:35 +0800 -Subject: [PATCH] memary error: fix some memary error - ---- - src/lstack/core/lstack_protocol_stack.c | 3 ++- - src/lstack/netif/lstack_flow.c | 4 ++++ - 2 files changed, 6 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 892c16d..c5a265e 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -626,10 +626,11 @@ int32_t stack_setup_app_thread(void) - - if (stack_thread_init(t_params) == NULL) { - LSTACK_LOG(INFO, LSTACK, "stack setup failed in app thread\n"); -+ free(t_params); - return -1; - } - atomic_fetch_add(&g_stack_group.stack_num, 1); -- -+ free(t_params); - return 0; - } - -diff --git a/src/lstack/netif/lstack_flow.c b/src/lstack/netif/lstack_flow.c -index 4e04209..9e8792c 100644 ---- a/src/lstack/netif/lstack_flow.c -+++ b/src/lstack/netif/lstack_flow.c -@@ -84,6 +84,10 @@ static void add_rule(char* rule_key, struct rte_flow *flow) - HASH_FIND_STR(g_flow_rules, rule_key, rule); - if (rule == NULL) { - rule = (struct flow_rule*)malloc(sizeof(struct flow_rule)); -+ if (rule == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "flow rule add failed. \n"); -+ return; -+ } - strcpy_s(rule->rule_key, RULE_KEY_LEN, rule_key); - HASH_ADD_STR(g_flow_rules, rule_key, rule); - } --- -2.33.0 - diff --git a/0182-bond-remove-bond-initialization-code-in-dpdk_ethdev_.patch b/0182-bond-remove-bond-initialization-code-in-dpdk_ethdev_.patch deleted file mode 100644 index c6723289eb9396bf4b7caaf503190f2ce0a068ca..0000000000000000000000000000000000000000 --- a/0182-bond-remove-bond-initialization-code-in-dpdk_ethdev_.patch +++ /dev/null @@ -1,545 +0,0 @@ -From 369b298752a84df677300792174f1957fa52cd52 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Tue, 21 May 2024 22:24:39 +0800 -Subject: [PATCH] bond:remove bond initialization code in dpdk_ethdev_init - ---- - src/common/dpdk_common.c | 2 +- - src/lstack/core/lstack_dpdk.c | 364 ++++++++++----------- - src/lstack/include/lstack_dpdk.h | 2 +- - src/lstack/include/lstack_protocol_stack.h | 2 - - 4 files changed, 173 insertions(+), 197 deletions(-) - -diff --git a/src/common/dpdk_common.c b/src/common/dpdk_common.c -index c03b2ec..66ad529 100644 ---- a/src/common/dpdk_common.c -+++ b/src/common/dpdk_common.c -@@ -226,7 +226,7 @@ void eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev - // rx vlan filter - if (rx_ol_capa & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) { - rx_ol |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER; -- COMMON_INFO("RTE_ETH_RX_OFFLOAD_VLAN_STRIP\n"); -+ COMMON_INFO("RTE_ETH_RX_OFFLOAD_VLAN_FILTER\n"); - } - - // tx ip -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index f1a22ea..07fffe9 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -58,10 +58,14 @@ struct eth_params { - uint16_t nb_rx_desc; - uint16_t nb_tx_desc; - -+ uint32_t reta_mask; -+ - struct rte_eth_conf conf; - struct rte_eth_rxconf rx_conf; - struct rte_eth_txconf tx_conf; - }; -+ -+static struct eth_params g_eth_params; - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - struct rte_kni; - static struct rte_bus *g_pci_bus = NULL; -@@ -368,34 +372,6 @@ static int32_t ethdev_port_id(uint8_t *mac) - return port_id; - } - --static struct eth_params *alloc_eth_params(uint16_t port_id, uint16_t nb_queues) --{ -- struct eth_params *eth_params = calloc(1, sizeof(struct eth_params)); -- if (eth_params == NULL) { -- return NULL; -- } -- -- eth_params->port_id = port_id; -- eth_params->nb_queues = nb_queues; -- eth_params->nb_rx_desc = get_global_cfg_params()->nic.rxqueue_size; -- eth_params->nb_tx_desc = get_global_cfg_params()->nic.txqueue_size; -- eth_params->conf.link_speeds = RTE_ETH_LINK_SPEED_AUTONEG; -- eth_params->conf.txmode.mq_mode = RTE_ETH_MQ_TX_NONE; -- eth_params->conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE; -- -- return eth_params; --} -- --uint64_t get_eth_params_rx_ol(void) --{ -- return get_protocol_stack_group()->rx_offload; --} -- --uint64_t get_eth_params_tx_ol(void) --{ -- return get_protocol_stack_group()->tx_offload; --} -- - static int eth_params_rss(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev_info) - { - int rss_enable = 0; -@@ -423,6 +399,54 @@ static int eth_params_rss(struct rte_eth_conf *conf, struct rte_eth_dev_info *de - return rss_enable; - } - -+static int eth_params_init(struct eth_params *eth_params, uint16_t port_id, uint16_t nb_queues, int *rss_enable) -+{ -+ struct rte_eth_dev_info dev_info; -+ int ret = rte_eth_dev_info_get(port_id, &dev_info); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "get dev info ret=%d\n", ret); -+ return ret; -+ } -+ -+ int32_t max_queues = LWIP_MIN(dev_info.max_rx_queues, dev_info.max_tx_queues); -+ if (max_queues < nb_queues) { -+ LSTACK_LOG(ERR, LSTACK, "port_id %d max_queues=%d\n", port_id, max_queues); -+ return -EINVAL; -+ } -+ -+ memset_s(eth_params, sizeof(struct eth_params), 0, sizeof(struct eth_params)); -+ -+ eth_params->port_id = port_id; -+ eth_params->nb_queues = nb_queues; -+ eth_params->nb_rx_desc = get_global_cfg_params()->nic.rxqueue_size; -+ eth_params->nb_tx_desc = get_global_cfg_params()->nic.txqueue_size; -+ eth_params->conf.link_speeds = RTE_ETH_LINK_SPEED_AUTONEG; -+ eth_params->conf.txmode.mq_mode = RTE_ETH_MQ_TX_NONE; -+ eth_params->conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE; -+ /* used for tcp port alloc */ -+ eth_params->reta_mask = dev_info.reta_size - 1; -+ -+ eth_params_checksum(ð_params->conf, &dev_info); -+ -+ if (!get_global_cfg_params()->tuple_filter) { -+ *rss_enable = eth_params_rss(ð_params->conf, &dev_info); -+ } else { -+ *rss_enable = 0; -+ } -+ -+ return 0; -+} -+ -+uint64_t get_eth_params_rx_ol(void) -+{ -+ return get_protocol_stack_group()->rx_offload; -+} -+ -+uint64_t get_eth_params_tx_ol(void) -+{ -+ return get_protocol_stack_group()->tx_offload; -+} -+ - static void rss_setup(const int port_id, const uint16_t nb_queues) - { - int ret; -@@ -481,8 +505,10 @@ int32_t dpdk_bond_primary_set(int port_id, int slave_port_id) - return 0; - } - --int32_t dpdk_ethdev_init(int port_id, bool bond_port) -+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; -@@ -494,145 +520,55 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port) - - struct protocol_stack_group *stack_group = get_protocol_stack_group(); - -- if (get_global_cfg_params()->bond_mode < 0) { -- port_id = ethdev_port_id(get_global_cfg_params()->mac_addr); -- if (port_id < 0) { -- LSTACK_LOG(ERR, LSTACK, "ethdev_port_id FAIL port_id=%d\n", port_id); -- return port_id; -- } -- } -- -- struct rte_eth_dev_info dev_info; -- int32_t ret = rte_eth_dev_info_get(port_id, &dev_info); -+ ret = eth_params_init(&g_eth_params, port_id, nb_queues, &rss_enable); - if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "get dev info ret=%d\n", ret); -+ LSTACK_LOG(ERR, LSTACK, "eth_params_init failed ret=%d\n", ret); - return ret; - } - -- int32_t max_queues = LWIP_MIN(dev_info.max_rx_queues, dev_info.max_tx_queues); -- if (max_queues < nb_queues) { -- LSTACK_LOG(ERR, LSTACK, "port_id %d max_queues=%d\n", port_id, max_queues); -- return -EINVAL; -- } -- -- if (bond_port) { -- int32_t slave_port_id[GAZELLE_MAX_BOND_NUM]; -- for (int i = 0; i < GAZELLE_MAX_BOND_NUM; i++) { -- if (rte_is_zero_ether_addr(&get_global_cfg_params()->bond_slave_mac_addr[i])) { -- break; -- } -- slave_port_id[i] = ethdev_port_id(get_global_cfg_params()->bond_slave_mac_addr[i].addr_bytes); -- if (slave_port_id[i] < 0) { -- LSTACK_LOG(ERR, LSTACK, "get slave port id failed port = %d\n", slave_port_id[1]); -- return slave_port_id[i]; -- } -- ret = dpdk_ethdev_init(slave_port_id[i], 0); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed ret = %d\n", ret); -- return -1; -- } -- ret = rte_eth_promiscuous_enable(slave_port_id[i]); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk slave enable promiscuous failed ret = %d\n", ret); -- return -1; -- } -- -- ret = rte_eth_allmulticast_enable(slave_port_id[i]); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk slave enable allmulticast failed ret = %d\n", ret); -- return -1; -- } -- --#if RTE_VERSION >= RTE_VERSION_NUM(23, 11, 0, 0) -- ret = rte_eth_bond_member_add(port_id, slave_port_id[i]); --#else -- ret = rte_eth_bond_slave_add(port_id, slave_port_id[i]); --#endif -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk add slave port failed ret = %d\n", ret); -- return -1; -- } -- -- if (get_global_cfg_params()->bond_mode == BONDING_MODE_ACTIVE_BACKUP) { -- dpdk_bond_primary_set(port_id, slave_port_id[i]); -- } -- -- ret = rte_eth_dev_start(slave_port_id[i]); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk start slave port failed ret = %d\n", ret); -- return -1; -- } -- } -- } -- -- struct eth_params *eth_params = alloc_eth_params(port_id, nb_queues); -- if (eth_params == NULL) { -- return -ENOMEM; -- } -- -- if (bond_port) { -- struct rte_eth_dev_info slave_dev_info; -- int slave_id = rte_eth_bond_primary_get(port_id); -- if (slave_id < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk get bond primary port failed port = %d\n", slave_id); -- free(eth_params); -- return slave_id; -- } -- ret = rte_eth_dev_info_get(slave_id, &slave_dev_info); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk get bond dev info failed ret = %d\n", ret); -- free(eth_params); -- return ret; -- } -- dev_info.rx_offload_capa = slave_dev_info.rx_offload_capa; -- dev_info.tx_offload_capa = slave_dev_info.tx_offload_capa; -- dev_info.reta_size = slave_dev_info.reta_size; -- dev_info.flow_type_rss_offloads = slave_dev_info.flow_type_rss_offloads; -- } -- -- eth_params_checksum(ð_params->conf, &dev_info); -- int32_t rss_enable = 0; -- if (!get_global_cfg_params()->tuple_filter) { -- rss_enable = eth_params_rss(ð_params->conf, &dev_info); -- } -- stack_group->eth_params = eth_params; -- stack_group->port_id = eth_params->port_id; -- stack_group->rx_offload = eth_params->conf.rxmode.offloads; -- stack_group->tx_offload = eth_params->conf.txmode.offloads; -- /* used for tcp port alloc */ -- stack_group->reta_mask = dev_info.reta_size - 1; -- stack_group->nb_queues = nb_queues; -+ stack_group->eth_params = &g_eth_params; -+ stack_group->rx_offload = g_eth_params.conf.rxmode.offloads; -+ stack_group->tx_offload = g_eth_params.conf.txmode.offloads; -+ stack_group->port_id = port_id; - - if (get_global_cfg_params()->is_primary) { -- ret = rte_eth_dev_configure(port_id, nb_queues, nb_queues, ð_params->conf); -+ ret = rte_eth_dev_configure(port_id, nb_queues, nb_queues, &stack_group->eth_params->conf); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "cannot config eth dev at port %d: %s\n", port_id, rte_strerror(-ret)); -- stack_group->eth_params = NULL; -- free(eth_params); - return ret; - } - - ret = dpdk_ethdev_start(); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_start failed ret=%d\n", ret); -- stack_group->eth_params = NULL; -- free(eth_params); - return ret; - } - - if (rss_enable && !get_global_cfg_params()->tuple_filter) { - rss_setup(port_id, nb_queues); -- stack_group->reta_mask = dev_info.reta_size - 1; - } - } - - /* after rte_eth_dev_configure */ - if ((get_global_cfg_params()->nic.vlan_mode != -1) && - ((stack_group->rx_offload & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) == RTE_ETH_RX_OFFLOAD_VLAN_FILTER)) { -- ret = rte_eth_dev_vlan_filter(port_id, get_global_cfg_params()->nic.vlan_mode, 1); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk add vlan filter failed ret = %d\n", ret); -- return -1; -+ /* -+ * vlan filter can be configured for switch,nic and software. -+ * bond4/6 mode need enable promiscuous mode, it conflicts with nic vlan filter. -+ * therefore, we can't use nic vlan filter in bond4/6 mode. -+ * 1. use software: need disable vlan strip in nic, the corresponding GRO becomes invalid -+ * GRO does not support vlan pakckets, which affects performance. -+ * 2. use switch: it's a good config -+ */ -+ if ((get_global_cfg_params()->bond_mode != BONDING_MODE_8023AD) && -+ (get_global_cfg_params()->bond_mode != BONDING_MODE_ALB)) { -+ ret = rte_eth_dev_vlan_filter(port_id, get_global_cfg_params()->nic.vlan_mode, 1); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk add vlan filter failed ret = %d\n", ret); -+ return -1; -+ } -+ } else { -+ LSTACK_LOG(ERR, LSTACK, "bond4 and bond6 not support set vlan filter in nic\n"); - } - } - -@@ -684,10 +620,6 @@ int32_t dpdk_ethdev_start(void) - } - } - -- if (get_global_cfg_params()->bond_mode >= 0) { -- return 0; -- } -- - ret = rte_eth_dev_start(stack_group->eth_params->port_id); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "cannot start ethdev: %d\n", (-ret)); -@@ -733,77 +665,117 @@ void dpdk_restore_pci(void) - } - #endif - --int32_t init_dpdk_ethdev(void) -+static int dpdk_bond_create(uint8_t mode, int *slave_port_id, int count) - { -- int32_t ret; -+ int port_id = rte_eth_bond_create("net_bonding0", mode, rte_socket_id()); -+ struct cfg_params *cfg = get_global_cfg_params(); -+ int ret; - -- if (get_global_cfg_params()->bond_mode >= 0) { -- uint8_t socket_id = rte_socket_id(); -- int bond_port_id = rte_eth_bond_create("net_bonding0", get_global_cfg_params()->bond_mode, socket_id); -- if (bond_port_id < 0) { -- LSTACK_LOG(ERR, LSTACK, "get bond port id failed ret=%d\n", bond_port_id); -- return bond_port_id; -- } -+ if (port_id < 0) { -+ LSTACK_LOG(ERR, LSTACK, "get bond port id failed ret=%d\n", port_id); -+ return -1; -+ } - -- ret = dpdk_ethdev_init(bond_port_id, 1); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed ret = %d\n", ret); -+ for (int i = 0; i < count; i++) { -+ /* rte_dev_info_get can get correct devinfo after call bond_member_add */ -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) -+ ret = rte_eth_bond_slave_add(port_id, slave_port_id[i]); -+#else -+ ret = rte_eth_bond_member_add(port_id, slave_port_id[i]); -+#endif -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "bond add slave devices failed, ret=%d\n", ret); - return -1; - } -+ if (cfg->bond_mode == BONDING_MODE_ACTIVE_BACKUP) { -+ dpdk_bond_primary_set(port_id, slave_port_id[i]); -+ } -+ } - -- ret = rte_eth_bond_xmit_policy_set(bond_port_id, BALANCE_XMIT_POLICY_LAYER34); -+ if (get_global_cfg_params()->bond_mode == BONDING_MODE_8023AD) { -+ ret = rte_eth_bond_8023ad_dedicated_queues_enable(port_id); - if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk set bond xmit policy failed ret = %d\n", ret); -+ LSTACK_LOG(ERR, LSTACK, "dpdk enable 8023 dedicated queues failed ret = %d\n", ret); - return -1; - } -+ } - -- if (get_global_cfg_params()->bond_mode == BONDING_MODE_8023AD) { -- ret = rte_eth_bond_8023ad_dedicated_queues_enable(bond_port_id); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk enable 8023 dedicated queues failed ret = %d\n", ret); -+ if (dpdk_ethdev_init(port_id) < 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed for bond port\n"); -+ return -1; -+ } -+ -+ ret = rte_eth_bond_xmit_policy_set(port_id, BALANCE_XMIT_POLICY_LAYER34); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk set bond xmit policy failed ret = %d\n", ret); -+ return -1; -+ } -+ -+ ret = rte_eth_bond_link_monitoring_set(port_id, get_global_cfg_params()->bond_miimon); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk set bond link monitoring failed ret = %d\n", ret); -+ return -1; -+ } -+ -+ if ((get_global_cfg_params()->bond_mode == BONDING_MODE_8023AD) || -+ (get_global_cfg_params()->bond_mode == BONDING_MODE_ALB)) { -+ for (int i = 0; i < count; i++) { -+ /* bond port promiscuous only enable primary port */ -+ /* we enable all ports */ -+ ret = rte_eth_promiscuous_enable(slave_port_id[i]); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk slave enable promiscuous failed ret = %d\n", ret); - return -1; - } -- } else { -- ret = rte_eth_bond_mode_set(bond_port_id, get_global_cfg_params()->bond_mode); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk enable mode set failed ret = %d\n", ret); -- } - } -+ } - -- ret = rte_eth_bond_link_monitoring_set(bond_port_id, get_global_cfg_params()->bond_miimon); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk set bond link monitoring failed ret = %d\n", ret); -- return -1; -- } -+ ret = rte_eth_dev_start(port_id); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk start bond port failed ret = %d\n", ret); -+ return -1; -+ } - -- ret = rte_eth_promiscuous_enable(bond_port_id); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk enable promiscuous failed ret = %d\n", ret); -- return -1; -- } -+ return 0; -+} - -- ret = rte_eth_allmulticast_enable(bond_port_id); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk enable allmulticast failed ret = %d\n", ret); -- return -1; -+int32_t init_dpdk_ethdev(void) -+{ -+ int32_t ret; -+ int slave_port_id[GAZELLE_MAX_BOND_NUM]; -+ int port_id; -+ struct cfg_params *cfg = get_global_cfg_params(); -+ int i; -+ -+ if (cfg->bond_mode >= 0) { -+ for (i = 0; i < GAZELLE_MAX_BOND_NUM; i++) { -+ if (rte_is_zero_ether_addr(&cfg->bond_slave_mac_addr[i])) { -+ break; -+ } -+ slave_port_id[i] = ethdev_port_id(cfg->bond_slave_mac_addr[i].addr_bytes); -+ ret = dpdk_ethdev_init(slave_port_id[i]); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "slave port(%d) init failed, ret=%d\n", slave_port_id[i], ret); -+ return -1; -+ } - } - -- ret = rte_eth_dev_start(bond_port_id); -+ ret = dpdk_bond_create(cfg->bond_mode, slave_port_id, i); - if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk start bond port failed ret = %d\n", ret); -+ LSTACK_LOG(ERR, LSTACK, "bond device create failed, ret=%d\n", ret); - return -1; - } -- - } else { -- ret = dpdk_ethdev_init(0, 0); -+ port_id = ethdev_port_id(cfg->mac_addr); -+ ret = dpdk_ethdev_init(port_id); - if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed\n"); -+ LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed, port id=%d\n", port_id); - return -1; - } - } - - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) -- if (get_global_cfg_params()->kni_switch && get_global_cfg_params()->is_primary) { -+ if (cfg->kni_switch && cfg->is_primary) { - ret = dpdk_init_lstack_kni(); - if (ret < 0) { - return -1; -@@ -817,7 +789,13 @@ int32_t init_dpdk_ethdev(void) - bool port_in_stack_queue(gz_addr_t *src_ip, gz_addr_t *dst_ip, uint16_t src_port, uint16_t dst_port) - { - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- if (stack_group->reta_mask == 0 || stack_group->nb_queues <= 1) { -+ -+ /* ltran mode */ -+ if (stack_group->eth_params == NULL) { -+ return true; -+ } -+ -+ if (stack_group->eth_params->reta_mask == 0 || stack_group->eth_params->nb_queues <= 1) { - return true; - } - -@@ -840,10 +818,10 @@ bool port_in_stack_queue(gz_addr_t *src_ip, gz_addr_t *dst_ip, uint16_t src_port - hash = rte_softrss((uint32_t *)&tuple, RTE_THASH_V6_L4_LEN, g_default_rss_key); - } - -- uint32_t reta_index = hash & stack_group->reta_mask; -+ uint32_t reta_index = hash & stack_group->eth_params->reta_mask; - - struct protocol_stack *stack = get_protocol_stack(); -- return (reta_index % stack_group->nb_queues) == stack->queue_id; -+ return (reta_index % stack_group->eth_params->nb_queues) == stack->queue_id; - } - - static int dpdk_nic_xstats_value_get(uint64_t *values, unsigned int len, uint16_t *ports, unsigned int count) -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index fe3d07b..dff1e44 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -46,7 +46,7 @@ struct rte_mempool *create_mempool(const char *name, uint32_t count, uint32_t si - uint32_t flags, int32_t idx); - int32_t create_shared_ring(struct protocol_stack *stack); - void lstack_log_level_init(void); --int dpdk_ethdev_init(int port_id, bool bond_port); -+int dpdk_ethdev_init(int port_id); - int dpdk_ethdev_start(void); - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - void dpdk_skip_nic_init(void); -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index df0902d..93fa40c 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -92,8 +92,6 @@ struct protocol_stack_group { - uint16_t port_id; - uint64_t rx_offload; - uint64_t tx_offload; -- uint32_t reta_mask; -- uint16_t nb_queues; - struct rte_mempool *kni_pktmbuf_pool; - struct eth_params *eth_params; - struct protocol_stack *stacks[PROTOCOL_STACK_MAX]; --- -2.33.0 - diff --git a/0183-make-rpc_msg_max-recv_ring_size-configurable.patch b/0183-make-rpc_msg_max-recv_ring_size-configurable.patch deleted file mode 100644 index ae786ca44971cfec771a8a95fa6616dbe3a83928..0000000000000000000000000000000000000000 --- a/0183-make-rpc_msg_max-recv_ring_size-configurable.patch +++ /dev/null @@ -1,169 +0,0 @@ -From 55ed3c6aaccf320a7d3240753a5aabe400ac4bd3 Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Fri, 7 Jun 2024 17:06:50 +0800 -Subject: [PATCH] make rpc_msg_max recv_ring_size-configurable - - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 9efdbaa..0e5fbf3 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -68,6 +68,7 @@ static int32_t parse_nic_read_number(void); - static int32_t parse_tcp_conn_count(void); - static int32_t parse_mbuf_count_per_conn(void); - static int32_t parse_send_ring_size(void); -+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); -@@ -83,6 +84,7 @@ 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); - - #define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \ - do { \ -@@ -132,6 +134,7 @@ static struct config_vector_t g_config_tbl[] = { - { "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 }, -@@ -146,6 +149,7 @@ static struct config_vector_t g_config_tbl[] = { - { "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 }, - { NULL, NULL } - }; - -@@ -908,6 +912,14 @@ static int32_t parse_send_ring_size(void) - return ret; - } - -+static int32_t parse_recv_ring_size(void) -+{ -+ int32_t ret; -+ /* recv ring size default value is 128 */ -+ PARSE_ARG(g_config_params.recv_ring_size, "recv_ring_size", 128, 1, SOCK_RECV_RING_SIZE_MAX, ret); -+ return ret; -+} -+ - static int32_t parse_mbuf_count_per_conn(void) - { - int32_t ret; -@@ -1356,3 +1368,15 @@ static int32_t parse_defaule_nonblock_mode(void) - } - return ret; - } -+ -+static int32_t parse_rpc_msg_max(void) -+{ -+ int32_t ret; -+ PARSE_ARG(g_config_params.rpc_msg_max, "rpc_msg_max", 4096, 1, 8192, ret); -+ if (ret != 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid rpc msg max value %d ret=%d. only support 1~8192\n", -+ g_config_params.rpc_msg_max, ret); -+ } -+ return ret; -+} -+ -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 30bd827..b98ba84 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -13,6 +13,7 @@ - #include - - #include "lstack_log.h" -+#include "lstack_cfg.h" - #include "lstack_dpdk.h" - #include "lstack_rpc_proc.h" - #include "lstack_stack_stat.h" -@@ -71,7 +72,7 @@ static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func) - exit(-1); - } - -- g_rpc_pool->mempool = create_mempool("rpc_pool", RPC_MSG_MAX, sizeof(struct rpc_msg), -+ 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); -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index a00e47a..94878de 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -110,6 +110,7 @@ struct cfg_params { - struct secondary_attach_arg sec_attach_arg; - char unix_socket_filename[NAME_MAX]; - uint16_t send_ring_size; -+ uint16_t recv_ring_size; - bool tuple_filter; - int8_t bond_mode; - int32_t bond_miimon; -@@ -119,6 +120,7 @@ struct cfg_params { - struct cfg_nic_params nic; - bool stack_mode_rtc; - bool nonblock_mode; -+ uint32_t rpc_msg_max; - }; - - struct cfg_params *get_global_cfg_params(void); -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 93fa40c..c210ab9 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -25,8 +25,9 @@ - #include "lstack_ethdev.h" - #include "gazelle_opt.h" - --#define SOCK_RECV_RING_SIZE (128) -+#define SOCK_RECV_RING_SIZE (get_global_cfg_params()->recv_ring_size) - #define SOCK_RECV_FREE_THRES (32) -+#define SOCK_RECV_RING_SIZE_MAX (2048) - #define SOCK_SEND_RING_SIZE_MAX (2048) - #define SOCK_SEND_REPLENISH_THRES (16) - #define WAKEUP_MAX_NUM (32) -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 8e97c11..0c51848 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -26,8 +26,6 @@ - #define MSG_ARG_4 (4) - #define RPM_MSG_ARG_SIZE (5) - --#define RPC_MSG_MAX 4096 --#define RPC_MSG_MASK (RPC_MSG_MAX - 1) - typedef struct lockless_queue rpc_queue; - - struct rpc_stats { -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index a7f4e75..4c3784f 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -22,8 +22,12 @@ tcp_conn_count = 1500 - mbuf_count_per_conn = 170 - - # send ring size, default is 32, max is 2048 -+# if udp pktlen exceeds 45952(32 * 1436)B, send_ring_size must be at least 64. - send_ring_size = 32 - -+#recv ring size, default is 128, max is 2048 -+recv_ring_size = 128 -+ - #protocol stack thread per loop params - #read data form protocol stack into recv_ring - read_connect_number = 4 -@@ -67,3 +71,6 @@ nic_vlan_mode=-1 - bond_mode=-1 - #bond slave mac, separated by ; , only support 2 slave mac - #bond_slave_mac="aa:bb:cc:dd:ee:ff;gg:hh:ii:jj:kk:ll" -+ -+#maximum number of rpc memory pools -+rpc_msg_max=4096 --- -2.33.0 - diff --git a/0184-EPOLL-fix-coredump-while-event-count-exceed-maxevent.patch b/0184-EPOLL-fix-coredump-while-event-count-exceed-maxevent.patch deleted file mode 100644 index b80b2730fc42353407bf50f967f04a7c30903131..0000000000000000000000000000000000000000 --- a/0184-EPOLL-fix-coredump-while-event-count-exceed-maxevent.patch +++ /dev/null @@ -1,46 +0,0 @@ -From e3c12e9d73678b3c5445f770c929e035ef1c4997 Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Fri, 7 Jun 2024 11:13:08 +0800 -Subject: [PATCH] EPOLL: fix coredump while event count exceed maxevents - ---- - src/lstack/api/lstack_epoll.c | 16 ++++++++-------- - 1 file changed, 8 insertions(+), 8 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index c8a2e43..28a3dd9 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -488,7 +488,14 @@ int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event * - list_del_node_null(node); - continue; - } -- -+ -+ if (event_num >= maxevents) { -+ /* move list head after the current node, and start traversing from this node next time */ -+ list_del_node_null(&wakeup->event_list); -+ list_add_node(node, &wakeup->event_list); -+ break; -+ } -+ - events[event_num].events = sock->events & sock->epoll_events; - events[event_num].data = sock->ep_data; - event_num++; -@@ -504,13 +511,6 @@ int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event * - list_del_node_null(node); - sock->epoll_events = 0; - } -- -- if (event_num >= maxevents) { -- /* move list head after the current node, and start traversing from this node next time */ -- list_del_node_null(&wakeup->event_list); -- list_add_node(node, &wakeup->event_list); -- break; -- } - } - - return event_num; --- -2.33.0 - diff --git a/0185-fix-fin-pack-free-coredump.patch b/0185-fix-fin-pack-free-coredump.patch deleted file mode 100644 index 22aa7d1e5932724af874d39920489176942176e2..0000000000000000000000000000000000000000 --- a/0185-fix-fin-pack-free-coredump.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 8bcbc7ef61b9193da5d3deb519211a2406564298 Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Fri, 7 Jun 2024 01:51:34 +0000 -Subject: [PATCH] fix fin pack free coredump - ---- - 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 667ffd7..628319c 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -88,7 +88,7 @@ static void reset_sock_data(struct lwip_sock *sock) - sock->remain_len = 0; - sock->already_bind_numa = 0; - -- if (sock->recv_lastdata) { -+ if (sock->recv_lastdata && sock->recv_lastdata != (void *)&fin_packet) { - pbuf_free(sock->recv_lastdata); - } - sock->recv_lastdata = NULL; --- -2.33.0 - diff --git a/0186-fix-MySQL-shutdown-cmd.patch b/0186-fix-MySQL-shutdown-cmd.patch deleted file mode 100644 index fa2d7ee8c2ca97f0a4dcc700de9f6146e3e08e9c..0000000000000000000000000000000000000000 --- a/0186-fix-MySQL-shutdown-cmd.patch +++ /dev/null @@ -1,95 +0,0 @@ -From 1431fd828005acb2aa7df1844cdec62e21f50769 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Wed, 5 Jun 2024 12:56:52 +0800 -Subject: [PATCH] fix MySQL shutdown cmd - ---- - src/lstack/api/lstack_epoll.c | 14 ++++++-------- - src/lstack/include/posix/lstack_epoll.h | 4 ++-- - 2 files changed, 8 insertions(+), 10 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index c8a2e43..1d6ae52 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -144,7 +144,7 @@ void wakeup_stack_epoll(struct protocol_stack *stack) - if (__atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); - rte_mb(); -- pthread_mutex_unlock(&wakeup->wait); -+ sem_post(&wakeup->wait); - stack->stats.wakeup_events++; - } - -@@ -258,12 +258,11 @@ int32_t lstack_do_epoll_create(int32_t fd) - init_list_node_null(&wakeup->wakeup_list[i]); - } - -- if (pthread_mutex_init(&wakeup->wait, NULL) != 0) { -+ if (sem_init(&wakeup->wait, 0, 0) != 0) { - posix_api->close_fn(fd); - free(wakeup); - GAZELLE_RETURN(EINVAL); - } -- pthread_mutex_trylock(&wakeup->wait); - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); - - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -@@ -337,7 +336,7 @@ int32_t lstack_epoll_close(int32_t fd) - list_del_node_null(&wakeup->poll_list); - pthread_spin_unlock(&stack_group->poll_list_lock); - -- pthread_mutex_destroy(&wakeup->wait); -+ sem_destroy(&wakeup->wait); - - free(wakeup); - sock->wakeup = NULL; -@@ -609,9 +608,9 @@ int32_t lstack_block_wait(struct wakeup_poll *wakeup, int32_t timeout) - if (timeout > 0) { - struct timespec timespec; - ms_to_timespec(×pec, timeout); -- ret = pthread_mutex_timedlock(&wakeup->wait, ×pec); -+ ret = sem_timedwait(&wakeup->wait, ×pec); - } else { -- ret = pthread_mutex_lock(&wakeup->wait); -+ ret = sem_wait(&wakeup->wait); - } - - if (__atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { -@@ -714,10 +713,9 @@ int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t - - static int32_t init_poll_wakeup_data(struct wakeup_poll *wakeup) - { -- if (pthread_mutex_init(&wakeup->wait, NULL) != 0) { -+ if (sem_init(&wakeup->wait, 0, 0) != 0) { - GAZELLE_RETURN(EINVAL); - } -- pthread_mutex_trylock(&wakeup->wait); - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); - - for (uint32_t i = 0; i < PROTOCOL_STACK_MAX; i++) { -diff --git a/src/lstack/include/posix/lstack_epoll.h b/src/lstack/include/posix/lstack_epoll.h -index 59b5ef7..a7164f4 100644 ---- a/src/lstack/include/posix/lstack_epoll.h -+++ b/src/lstack/include/posix/lstack_epoll.h -@@ -37,7 +37,7 @@ struct protocol_stack; - struct wakeup_poll { - /* stack thread read frequently */ - enum wakeup_type type; -- pthread_mutex_t wait __rte_cache_aligned; -+ sem_t wait; - bool in_wait; - struct list_node wakeup_list[PROTOCOL_STACK_MAX]; - bool have_kernel_event; -@@ -87,7 +87,7 @@ static inline void lstack_block_wakeup(struct wakeup_poll *wakeup) - if (wakeup && __atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); - rte_mb(); -- pthread_mutex_unlock(&wakeup->wait); -+ sem_post(&wakeup->wait); - } - } - --- -2.33.0 - diff --git a/0187-cfg-remove-map-perfect-flag-in-lstack.conf.patch b/0187-cfg-remove-map-perfect-flag-in-lstack.conf.patch deleted file mode 100644 index 40d63bee1c3d760da853b24e56b1fd29c2cb0ec9..0000000000000000000000000000000000000000 --- a/0187-cfg-remove-map-perfect-flag-in-lstack.conf.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 9cd0a7ebb73b882ef3ac968795fb22ca78fb33cc Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 29 May 2024 16:20:59 +0800 -Subject: [PATCH] cfg: remove map-perfect flag in lstack.conf - -This parameter is used in ltran mode. -By defualt, ltran mode is not used, so remove it. ---- - src/lstack/lstack.conf | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index 07a6092..0b7dbc9 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -8,10 +8,11 @@ - # PURPOSE. - # See the Mulan PSL v2 for more details. - --dpdk_args=["--socket-mem", "2048,0,0,0", "--huge-dir", "/mnt/hugepages-lstack", "--proc-type", "primary", "--legacy-mem", "--map-perfect"] -+dpdk_args=["--socket-mem", "2048,0,0,0", "--huge-dir", "/mnt/hugepages-lstack", "--proc-type", "primary", "--legacy-mem"] - - stack_thread_mode="run-to-wakeup" - -+#ltran mode need add "--map-perfect" in dpdk_args - use_ltran=0 - kni_switch=0 - --- -2.33.0 - diff --git a/0188-redis-perf-add-tx-driver-cache.patch b/0188-redis-perf-add-tx-driver-cache.patch deleted file mode 100644 index af3dfffd565f5dd2c1e8ea83f2551e6be23a2929..0000000000000000000000000000000000000000 --- a/0188-redis-perf-add-tx-driver-cache.patch +++ /dev/null @@ -1,255 +0,0 @@ -From 9e6197b3d39a244ed7900bfc2df9d0f2290fcfb2 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Mon, 17 Jun 2024 10:41:54 +0800 -Subject: [PATCH] redis perf: add tx driver cache - ---- - src/lstack/api/dir.mk | 2 +- - src/lstack/api/lstack_tx_cache.c | 47 ++++++++++++++++++++++ - src/lstack/core/lstack_cfg.c | 13 ++++++ - src/lstack/core/lstack_protocol_stack.c | 1 + - src/lstack/include/lstack_cfg.h | 1 + - src/lstack/include/lstack_protocol_stack.h | 2 + - src/lstack/include/lstack_tx_cache.h | 28 +++++++++++++ - src/lstack/netif/lstack_ethdev.c | 30 +++++++++++--- - 8 files changed, 117 insertions(+), 7 deletions(-) - create mode 100644 src/lstack/api/lstack_tx_cache.c - create mode 100644 src/lstack/include/lstack_tx_cache.h - -diff --git a/src/lstack/api/dir.mk b/src/lstack/api/dir.mk -index 729690d..70bc59d 100644 ---- a/src/lstack/api/dir.mk -+++ b/src/lstack/api/dir.mk -@@ -8,7 +8,7 @@ - # PURPOSE. - # See the Mulan PSL v2 for more details. - --SRC = lstack_epoll.c lstack_signal.c lstack_fork.c lstack_wrap.c lstack_rtw_api.c lstack_rtc_api.c lstack_dummy_api.c -+SRC = lstack_epoll.c lstack_signal.c lstack_fork.c lstack_wrap.c lstack_rtw_api.c lstack_rtc_api.c lstack_dummy_api.c lstack_tx_cache.c - - $(eval $(call register_dir, api, $(SRC))) - -diff --git a/src/lstack/api/lstack_tx_cache.c b/src/lstack/api/lstack_tx_cache.c -new file mode 100644 -index 0000000..42aef57 ---- /dev/null -+++ b/src/lstack/api/lstack_tx_cache.c -@@ -0,0 +1,47 @@ -+/* -+* 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 "lwip/sockets.h" -+#include "lstack_cfg.h" -+#include "lstack_protocol_stack.h" -+#include "lstack_tx_cache.h" -+ -+void stack_send_pkts(struct protocol_stack *stack) -+{ -+ if (!get_global_cfg_params()->send_cache_mode) { -+ return; -+ } -+ -+ uint32_t send_num = stack->tx_cache.send_end - stack->tx_cache.send_start; -+ -+ if (send_num == 0) { -+ return; -+ } -+ -+ uint32_t start = stack->tx_cache.send_start & STACK_SEND_MASK; -+ uint32_t end = stack->tx_cache.send_end & STACK_SEND_MASK; -+ uint32_t sent_pkts = 0; -+ -+ if (start < end) { -+ sent_pkts = stack->dev_ops.tx_xmit(stack, &stack->tx_cache.send_pkts[start], send_num); -+ } else { -+ send_num = STACK_SEND_MAX - start; -+ sent_pkts = stack->dev_ops.tx_xmit(stack, &stack->tx_cache.send_pkts[start], send_num); -+ if (sent_pkts == send_num) { -+ sent_pkts += stack->dev_ops.tx_xmit(stack, stack->tx_cache.send_pkts, end); -+ } -+ } -+ -+ stack->tx_cache.send_start += sent_pkts; -+ stack->stats.tx += sent_pkts; -+} -+ -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 0e5fbf3..56f290e 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -85,6 +85,7 @@ 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); - - #define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \ - do { \ -@@ -150,6 +151,7 @@ static struct config_vector_t g_config_tbl[] = { - { "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 }, - { NULL, NULL } - }; - -@@ -1380,3 +1382,14 @@ static int32_t parse_rpc_msg_max(void) - return ret; - } - -+static int32_t parse_send_cache_mode(void) -+{ -+ int32_t ret; -+ PARSE_ARG(g_config_params.send_cache_mode, "send_cache_mode", 0, 0, 1, ret); -+ if (ret != 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid send cache mode value %d. only support 0 or 1\n", -+ g_config_params.send_cache_mode); -+ } -+ return ret; -+} -+ -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index c5a265e..98d6549 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -480,6 +480,7 @@ int stack_polling(uint32_t wakeup_tick) - do_lwip_read_recvlist(stack, read_connect_number); - if ((wakeup_tick & 0xf) == 0) { - wakeup_stack_epoll(stack); -+ stack_send_pkts(stack); - } - - /* run to completion mode currently does not support sockmap */ -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 94878de..b9721ff 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -121,6 +121,7 @@ struct cfg_params { - bool stack_mode_rtc; - bool nonblock_mode; - uint32_t rpc_msg_max; -+ bool send_cache_mode; - }; - - struct cfg_params *get_global_cfg_params(void); -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index c210ab9..ab27dfa 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -23,6 +23,7 @@ - #include "gazelle_dfx_msg.h" - #include "lstack_thread_rpc.h" - #include "lstack_ethdev.h" -+#include "lstack_tx_cache.h" - #include "gazelle_opt.h" - - #define SOCK_RECV_RING_SIZE (get_global_cfg_params()->recv_ring_size) -@@ -76,6 +77,7 @@ struct protocol_stack { - uint32_t tx_ring_used; - - struct rte_mbuf *pkts[NIC_QUEUE_SIZE_MAX]; -+ struct lstack_tx_cache tx_cache; - struct list_node recv_list; - struct list_node same_node_recv_list; /* used for same node processes communication */ - struct list_node wakeup_list; -diff --git a/src/lstack/include/lstack_tx_cache.h b/src/lstack/include/lstack_tx_cache.h -new file mode 100644 -index 0000000..3991b16 ---- /dev/null -+++ b/src/lstack/include/lstack_tx_cache.h -@@ -0,0 +1,28 @@ -+/* -+* 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 _LSTACK_TX_CACHE_H_ -+#define _LSTACK_TX_CACHE_H_ -+ -+#define STACK_SEND_MAX (2048) -+#define STACK_SEND_MASK (STACK_SEND_MAX - 1) -+#define STACK_SEND_INDEX(index) ((index) & STACK_SEND_MASK) -+ -+struct lstack_tx_cache { -+ uint32_t send_start; -+ uint32_t send_end; -+ struct rte_mbuf *send_pkts[STACK_SEND_MAX]; -+}; -+ -+void stack_send_pkts(struct protocol_stack *stack); -+ -+#endif /* _LSTACK_TX_CACHE_H_ */ -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 048ea92..77172f8 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -34,6 +34,7 @@ - #include "lstack_protocol_stack.h" - #include "lstack_thread_rpc.h" - #include "lstack_flow.h" -+#include "lstack_tx_cache.h" - #include "lstack_ethdev.h" - - /* FRAME_MTU + 14byte header */ -@@ -186,6 +187,19 @@ int32_t eth_dev_poll(void) - return nr_pkts; - } - -+static void eth_dev_send_pkt(struct protocol_stack *stack, struct rte_mbuf *mbuf) -+{ -+ do { -+ if (STACK_SEND_INDEX(stack->tx_cache.send_end + 1) != STACK_SEND_INDEX(stack->tx_cache.send_start)) { -+ stack->tx_cache.send_pkts[STACK_SEND_INDEX(stack->tx_cache.send_end)] = mbuf; -+ stack->tx_cache.send_end++; -+ return; -+ } -+ stack_send_pkts(stack); -+ stack->stats.send_pkts_fail++; -+ } while (1); -+} -+ - static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - { - struct protocol_stack *stack = get_protocol_stack(); -@@ -231,12 +245,16 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - pbuf = pbuf->next; - } - -- uint32_t sent_pkts = stack->dev_ops.tx_xmit(stack, &first_mbuf, 1); -- stack->stats.tx += sent_pkts; -- if (sent_pkts < 1) { -- stack->stats.tx_drop++; -- rte_pktmbuf_free(first_mbuf); -- return ERR_MEM; -+ if (!get_global_cfg_params()->send_cache_mode) { -+ uint32_t sent_pkts = stack->dev_ops.tx_xmit(stack, &first_mbuf, 1); -+ stack->stats.tx += sent_pkts; -+ if (sent_pkts < 1) { -+ stack->stats.tx_drop++; -+ rte_pktmbuf_free(first_mbuf); -+ return ERR_MEM; -+ } -+ } else { -+ eth_dev_send_pkt(stack, first_mbuf); - } - - return ERR_OK; --- -2.33.0 - diff --git a/0189-optimized-latency-distribution-dotting.patch b/0189-optimized-latency-distribution-dotting.patch deleted file mode 100644 index fee0346c82280b77a7f4ac768e4ba83f98a8b3b4..0000000000000000000000000000000000000000 --- a/0189-optimized-latency-distribution-dotting.patch +++ /dev/null @@ -1,250 +0,0 @@ -From 8fd1a2bfacf928d86fe1b76fc1cd80b3a21cb2cc Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Thu, 13 Jun 2024 18:31:42 +0800 -Subject: [PATCH] optimized latency distribution dotting - ---- - src/common/gazelle_dfx_msg.h | 10 ++++--- - src/lstack/core/lstack_lwip.c | 4 +++ - src/lstack/core/lstack_protocol_stack.c | 8 +++--- - src/lstack/core/lstack_stack_stat.c | 36 +++++++++++++++++++++---- - src/lstack/core/lstack_thread_rpc.c | 3 ++- - src/lstack/include/lstack_stack_stat.h | 7 ++++- - src/lstack/include/lstack_thread_rpc.h | 2 -- - src/ltran/ltran_dfx.c | 17 +++++++----- - 8 files changed, 63 insertions(+), 24 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index cad7978..696daf2 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -69,10 +69,11 @@ enum GAZELLE_STAT_MODE { - }; - - enum GAZELLE_LATENCY_TYPE { -- GAZELLE_LATENCY_READ_LWIP, // t0 -> t1 -- GAZELLE_LATENCY_READ_APP_CALL, // t1 -> t2 -- GAZELLE_LATENCY_READ_LSTACK, // t2 -> t3 -- GAZELLE_LATENCY_READ_MAX, // t0 -> t3 -+ GAZELLE_LATENCY_INTO_MBOX, // t0 -> t1 -+ GAZELLE_LATENCY_READ_LWIP, // t1 -> t2 -+ GAZELLE_LATENCY_READ_APP_CALL, // t2 -> t3 -+ GAZELLE_LATENCY_READ_LSTACK, // t3 -> t4 -+ GAZELLE_LATENCY_READ_MAX, // t0 -> t4 - - GAZELLE_LATENCY_WRITE_INTO_RING, // t0 -> t1 - GAZELLE_LATENCY_WRITE_LWIP, // t1 -> t2 -@@ -80,6 +81,7 @@ enum GAZELLE_LATENCY_TYPE { - GAZELLE_LATENCY_WRITE_MAX, // t0 -> t3 - - GAZELLE_LATENCY_WRITE_RPC_MSG, // rpc_call_send -+ GAZELLE_LATENCY_RECVMBOX_READY, // ready to read from recvmbox - - GAZELLE_LATENCY_MAX, - }; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 628319c..153c5cc 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -1104,6 +1104,10 @@ void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num) - continue; - } - -+ if (get_protocol_stack_group()->latency_start) { -+ calculate_sock_latency(&sock->stack->latency, sock, GAZELLE_LATENCY_RECVMBOX_READY); -+ } -+ - ssize_t len = 0; - if (NETCONN_IS_UDP(sock)) { - len = lwip_recv(sock->conn->callback_arg.socket, NULL, SSIZE_MAX, 0); -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 98d6549..74e543d 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -882,10 +882,6 @@ void stack_send(struct rpc_msg *msg) - struct protocol_stack *stack = get_protocol_stack(); - int replenish_again; - -- if (get_protocol_stack_group()->latency_start) { -- calculate_rpcmsg_latency(&stack->latency, msg, GAZELLE_LATENCY_WRITE_RPC_MSG); -- } -- - struct lwip_sock *sock = get_socket(fd); - if (sock == NULL) { - msg->result = -1; -@@ -893,6 +889,10 @@ void stack_send(struct rpc_msg *msg) - return; - } - -+ if (get_protocol_stack_group()->latency_start) { -+ calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_WRITE_RPC_MSG); -+ } -+ - replenish_again = do_lwip_send(stack, sock->conn->callback_arg.socket, sock, len, 0); - if (replenish_again < 0) { - __sync_fetch_and_sub(&sock->call_num, 1); -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index e430195..a1bd44d 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -15,6 +15,7 @@ - #include - #include - #include -+#include - - #include "lstack_cfg.h" - #include "lstack_ethdev.h" -@@ -67,21 +68,46 @@ void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new) - } - } - --void time_stamp_into_rpcmsg(struct rpc_msg *msg) -+void time_stamp_into_rpcmsg(struct lwip_sock *sock) - { -- msg->time_stamp = get_current_time(); -+ sock->stamp.rpc_time_stamp = get_current_time(); - } - --void calculate_rpcmsg_latency(struct gazelle_stack_latency *stack_latency, struct rpc_msg *msg, -+void time_stamp_into_recvmbox(struct lwip_sock *sock) -+{ -+ sock->stamp.mbox_time_stamp = get_current_time(); -+} -+ -+void time_stamp_record(int fd, struct pbuf *pbuf) -+{ -+ struct lwip_sock *sock = get_socket_by_fd(fd); -+ -+ if (get_protocol_stack_group()->latency_start && pbuf != NULL) { -+ calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_INTO_MBOX, 0); -+ time_stamp_into_recvmbox(sock); -+ } -+} -+ -+void calculate_sock_latency(struct gazelle_stack_latency *stack_latency, struct lwip_sock *sock, - enum GAZELLE_LATENCY_TYPE type) - { - uint64_t latency; -+ uint64_t stamp; - struct stack_latency *latency_stat; -- if (msg == NULL || msg->time_stamp < stack_latency->start_time || type >= GAZELLE_LATENCY_MAX) { -+ -+ if (type == GAZELLE_LATENCY_WRITE_RPC_MSG) { -+ stamp = sock->stamp.rpc_time_stamp; -+ } else if (type == GAZELLE_LATENCY_RECVMBOX_READY) { -+ stamp = sock->stamp.mbox_time_stamp; -+ } else { -+ return; -+ } -+ -+ if (stamp < stack_latency->start_time) { - return; - } - -- latency = get_current_time() - msg->time_stamp; -+ latency = get_current_time() - stamp; - latency_stat = &stack_latency->latency[type]; - - latency_stat->latency_total += latency; -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index b98ba84..04bdc3a 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -10,6 +10,7 @@ - * See the Mulan PSL v2 for more details. - */ - #include -+#include - #include - - #include "lstack_log.h" -@@ -471,7 +472,7 @@ int32_t rpc_call_send(rpc_queue *queue, int fd, const void *buf, size_t len, int - } - - if (get_protocol_stack_group()->latency_start) { -- time_stamp_into_rpcmsg(msg); -+ time_stamp_into_rpcmsg(get_socket_by_fd(fd)); - } - - msg->args[MSG_ARG_0].i = fd; -diff --git a/src/lstack/include/lstack_stack_stat.h b/src/lstack/include/lstack_stack_stat.h -index 939189e..f0d3d5d 100644 ---- a/src/lstack/include/lstack_stack_stat.h -+++ b/src/lstack/include/lstack_stack_stat.h -@@ -22,11 +22,14 @@ struct protocol_stack; - enum GAZELLE_LATENCY_TYPE; - enum GAZELLE_STAT_MODE; - struct gazelle_stat_msg_request; -+struct lwip_sock; - - void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, - enum GAZELLE_LATENCY_TYPE type, uint64_t time_record); - void calculate_rpcmsg_latency(struct gazelle_stack_latency *stack_latency, struct rpc_msg *msg, - enum GAZELLE_LATENCY_TYPE type); -+void calculate_sock_latency(struct gazelle_stack_latency *stack_latency, struct lwip_sock *sock, -+ enum GAZELLE_LATENCY_TYPE type); - void stack_stat_init(void); - int handle_stack_cmd(int fd, struct gazelle_stat_msg_request *msg); - int handle_dpdk_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode); -@@ -35,6 +38,8 @@ void lstack_get_low_power_info(struct gazelle_stat_low_power_info *low_power_inf - void unregister_wakeup(struct protocol_stack *stack, struct wakeup_poll *wakeup); - void lstack_calculate_aggregate(int type, uint32_t len); - void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new); --void time_stamp_into_rpcmsg(struct rpc_msg *msg); -+void time_stamp_into_rpcmsg(struct lwip_sock *sock); -+void time_stamp_into_recvmbox(struct lwip_sock *sock); -+void time_stamp_record(int fd, struct pbuf *pbuf); - - #endif /* GAZELLE_STACK_STAT_H */ -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 0c51848..276ebb2 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -58,8 +58,6 @@ struct rpc_msg { - - rpc_msg_func func; /* msg handle func hook */ - union rpc_msg_arg args[RPM_MSG_ARG_SIZE]; /* resolve by type */ -- -- uint64_t time_stamp; /* rpc_call_* start time */ - }; - - static inline void rpc_queue_init(rpc_queue *queue) -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 319f7cd..4351891 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -899,11 +899,13 @@ static void gazelle_print_lstack_stat_latency(void *buf, const struct gazelle_st - - printf("Statistics of lstack latency pkts min(us) max(us) average(us)\n"); - printf("Recv:\n"); -- printf("range: t0--->t1\n%s", res[GAZELLE_LATENCY_READ_LWIP].latency_stat_result); -- printf("range: t1--->t2\n%s", res[GAZELLE_LATENCY_READ_APP_CALL].latency_stat_result); -- printf("range: t2--->t3\n%s", res[GAZELLE_LATENCY_READ_LSTACK].latency_stat_result); -- printf("range: t0--->t3\n%s", res[GAZELLE_LATENCY_READ_MAX].latency_stat_result); -- printf("t0: read from nic t1: into recv ring t2: app read start t3: app read end\n"); -+ -+ printf("range: t0--->t1\n%s", res[GAZELLE_LATENCY_INTO_MBOX].latency_stat_result); -+ printf("range: t1--->t2\n%s", res[GAZELLE_LATENCY_READ_LWIP].latency_stat_result); -+ printf("range: t2--->t3\n%s", res[GAZELLE_LATENCY_READ_APP_CALL].latency_stat_result); -+ printf("range: t3--->t4\n%s", res[GAZELLE_LATENCY_READ_LSTACK].latency_stat_result); -+ printf("range: t0--->t4\n%s", res[GAZELLE_LATENCY_READ_MAX].latency_stat_result); -+ printf("t0: read from nic t1: into recvmbox t2: into recvring t3: app read start t4: app read end\n"); - - printf("Send:\n"); - printf("range: t0--->t1\n%s", res[GAZELLE_LATENCY_WRITE_INTO_RING].latency_stat_result); -@@ -912,8 +914,9 @@ static void gazelle_print_lstack_stat_latency(void *buf, const struct gazelle_st - printf("range: t0--->t3\n%s", res[GAZELLE_LATENCY_WRITE_MAX].latency_stat_result); - printf("t0: app send t1: into send ring t2: out of send ring t3: send to nic\n"); - -- printf("Rpc:\n"); -- printf("rpc_call_send \n%s", res[GAZELLE_LATENCY_WRITE_RPC_MSG].latency_stat_result); -+ printf("Others:\n"); -+ printf("rpc_call_send\n%s", res[GAZELLE_LATENCY_WRITE_RPC_MSG].latency_stat_result); -+ printf("ready to read from recvmbox\n%s", res[GAZELLE_LATENCY_RECVMBOX_READY].latency_stat_result); - - free(res); - } --- -2.33.0 - diff --git a/0190-rtc-adapt-rtc_close.patch b/0190-rtc-adapt-rtc_close.patch deleted file mode 100644 index 11f66ddec882541e054d5488eadbdcb0bc09ba18..0000000000000000000000000000000000000000 --- a/0190-rtc-adapt-rtc_close.patch +++ /dev/null @@ -1,51 +0,0 @@ -From cba42b0ca25bed62c946a4d902deb82ce0ca74e9 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sat, 2 Mar 2024 13:44:20 +0800 -Subject: [PATCH] rtc: adapt rtc_close - ---- - src/lstack/api/lstack_epoll.c | 4 +++- - src/lstack/api/lstack_rtc_api.c | 12 +++++++++++- - 2 files changed, 14 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 7dbef9d..6ae0eec 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -322,7 +322,9 @@ int32_t lstack_epoll_close(int32_t fd) - - wakeup->type = WAKEUP_CLOSE; - -- stack_broadcast_clean_epoll(wakeup); -+ if (!get_global_cfg_params()->stack_mode_rtc) { -+ stack_broadcast_clean_epoll(wakeup); -+ } - - struct list_node *node, *temp; - pthread_spin_lock(&wakeup->event_list_lock); -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index 2e10e30..18664ca 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -63,7 +63,17 @@ int rtc_socket(int domain, int type, int protocol) - - int rtc_close(int s) - { -- return lwip_close(s); -+ struct lwip_sock *sock = get_socket(s); -+ if (sock != NULL && sock->wakeup != NULL && sock->wakeup->epollfd == s) { -+ return lstack_epoll_close(s); -+ } -+ -+ lwip_close(s); -+ if (sock != NULL) { -+ list_del_node_null(&sock->event_list); -+ } -+ -+ return posix_api->close_fn(s); - } - - int rtc_shutdown(int fd, int how) --- -2.33.0 - diff --git a/0191-virtio-flow_bifurcation-switch.patch b/0191-virtio-flow_bifurcation-switch.patch deleted file mode 100644 index a6c62410be21baefeda3b9067c1cec81713994cc..0000000000000000000000000000000000000000 --- a/0191-virtio-flow_bifurcation-switch.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 259092f39041968a07b395c43ed9cd26250215d9 Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Tue, 18 Jun 2024 11:29:58 +0800 -Subject: [PATCH] [virtio]: flow_bifurcation switch - ---- - src/lstack/core/lstack_cfg.c | 12 ++++++++++++ - src/lstack/include/lstack_cfg.h | 1 + - 2 files changed, 13 insertions(+) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 56f290e..f0c5f4f 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -86,6 +86,7 @@ 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); - - #define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \ - do { \ -@@ -152,6 +153,7 @@ static struct config_vector_t g_config_tbl[] = { - { "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}, - { NULL, NULL } - }; - -@@ -1393,3 +1395,13 @@ static int32_t parse_send_cache_mode(void) - return ret; - } - -+static int32_t parse_flow_bifurcation(void) -+{ -+ int32_t ret; -+ PARSE_ARG(g_config_params.flow_bifurcation, "flow_bifurcation", 0, 0, 1, ret); -+ if (ret != 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid flow_bifurcation value %d. only support 0 or 1\n", -+ g_config_params.flow_bifurcation); -+ } -+ return ret; -+} -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index b9721ff..9649d73 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -122,6 +122,7 @@ struct cfg_params { - bool nonblock_mode; - uint32_t rpc_msg_max; - bool send_cache_mode; -+ bool flow_bifurcation; - }; - - struct cfg_params *get_global_cfg_params(void); --- -2.33.0 - diff --git a/0192-remove-legacy-mem.patch b/0192-remove-legacy-mem.patch deleted file mode 100644 index 411da6afd628b1dfc3a0bfcbed2842f19ff14e22..0000000000000000000000000000000000000000 --- a/0192-remove-legacy-mem.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 9fc2f5d7e298c3f549ad7abccc01ee1b971068e2 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sun, 16 Jun 2024 14:29:43 +0800 -Subject: [PATCH] remove legacy-mem - ---- - src/lstack/lstack.conf | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index 9cf967a..c65a25d 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -8,11 +8,11 @@ - # PURPOSE. - # See the Mulan PSL v2 for more details. - --dpdk_args=["--socket-mem", "2048,0,0,0", "--huge-dir", "/mnt/hugepages-lstack", "--proc-type", "primary", "--legacy-mem"] -+dpdk_args=["--socket-mem", "2048,0,0,0", "--huge-dir", "/mnt/hugepages-lstack", "--proc-type", "primary"] - - stack_thread_mode="run-to-wakeup" - --#ltran mode need add "--map-perfect" in dpdk_args -+#ltran mode need add "--map-perfect" and "--legacy-mem" in dpdk_args - use_ltran=0 - kni_switch=0 - --- -2.33.0 - diff --git a/0193-cfg-bond_slave_mac-support-pci-addr.patch b/0193-cfg-bond_slave_mac-support-pci-addr.patch deleted file mode 100644 index 4721ce67f47c5af0287d2f3d5bd7f448ca4b526e..0000000000000000000000000000000000000000 --- a/0193-cfg-bond_slave_mac-support-pci-addr.patch +++ /dev/null @@ -1,246 +0,0 @@ -From 61366e0a54935684ca3e17477c6367907285a5ff Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Mon, 17 Jun 2024 18:35:12 +0800 -Subject: [PATCH] cfg: bond_slave_mac support pci addr - ---- - src/lstack/core/lstack_cfg.c | 35 +++++++++--------- - src/lstack/core/lstack_dpdk.c | 63 ++++++++++++++++++++++++--------- - src/lstack/include/lstack_cfg.h | 16 ++++++++- - 3 files changed, 80 insertions(+), 34 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 0e5fbf3..6ce862b 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -39,6 +39,7 @@ - #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 -@@ -188,6 +189,21 @@ static int32_t str_to_eth_addr(const char *src, unsigned char *dst) - return 0; - } - -+static int32_t str_to_dev_addr(const char *src, struct dev_addr *dst) -+{ -+ int32_t ret = 0; -+ if (strlen(src) == DEV_PCI_ADDR_LEN) { -+ /* str to pci addr */ -+ ret = rte_pci_addr_parse(src, &dst->addr.pci_addr); -+ dst->addr_type = DEV_ADDR_TYPE_PCI; -+ } else { -+ /* str to mac addr */ -+ ret = str_to_eth_addr(src, dst->addr.mac_addr.addr_bytes); -+ dst->addr_type = DEV_ADDR_TYPE_MAC; -+ } -+ return ret; -+} -+ - static int32_t parse_gateway_addr(void) - { - char *value; -@@ -1227,16 +1243,6 @@ static int32_t parse_bond_miimon(void) - return ret; - } - --static bool validate_bond_mac(uint8_t *mac_addr, struct rte_ether_addr *bond_slave_mac, int num_slaves) --{ -- for (int i = 0; i < num_slaves; i++) { -- if (memcmp(mac_addr, bond_slave_mac[i].addr_bytes, ETHER_ADDR_LEN) == 0) { -- return true; -- } -- } -- return false; --} -- - static int32_t parse_bond_slave_mac(void) - { - if (g_config_params.bond_mode == -1) { -@@ -1269,7 +1275,8 @@ static int32_t parse_bond_slave_mac(void) - free(bond_slave_mac_tmp); - return -EINVAL; - } -- ret = str_to_eth_addr(mac_addr, g_config_params.bond_slave_mac_addr[k].addr_bytes); -+ -+ ret = str_to_dev_addr(mac_addr, &g_config_params.bond_slave_addr[k]); - if (ret != 0) { - LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid device name %s ret=%d.\n", mac_addr, ret); - free(bond_slave_mac_tmp); -@@ -1279,12 +1286,6 @@ static int32_t parse_bond_slave_mac(void) - k = k + 1; - } - free(bond_slave_mac_tmp); -- if (g_config_params.bond_mode == BONDING_MODE_ACTIVE_BACKUP) { -- if (!validate_bond_mac(g_config_params.mac_addr, g_config_params.bond_slave_mac_addr, GAZELLE_MAX_BOND_NUM)) { -- LSTACK_PRE_LOG(LSTACK_ERR, "cfg: devices must be in bond_slave_mac for BONDING_MODE_ACTIVE_BACKUP.\n"); -- return -EINVAL; -- } -- } - return ret; - } - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 07fffe9..785431f 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -372,6 +372,23 @@ static int32_t ethdev_port_id(uint8_t *mac) - return port_id; - } - -+static int32_t pci_to_port_id(struct rte_pci_addr *pci_addr) -+{ -+ uint16_t port_id; -+ char device_name[RTE_DEV_NAME_MAX_LEN] = ""; -+ -+ rte_pci_device_name(pci_addr, device_name, RTE_DEV_NAME_MAX_LEN); -+ -+ int ret = rte_eth_dev_get_port_by_name(device_name, &port_id); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "match failed: no NIC matches cfg:%04x:%02x:%02x.%x\n", -+ pci_addr->domain, pci_addr->bus, pci_addr->devid, pci_addr->function); -+ return -EINVAL; -+ } -+ -+ return port_id; -+} -+ - static int eth_params_rss(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev_info) - { - int rss_enable = 0; -@@ -491,18 +508,25 @@ static void rss_setup(const int port_id, const uint16_t nb_queues) - free(reta_conf); - } - --int32_t dpdk_bond_primary_set(int port_id, int slave_port_id) -+int32_t dpdk_bond_primary_set(int port_id, int *slave_port_id) - { - int32_t primary_port_id = ethdev_port_id(get_global_cfg_params()->mac_addr); -- if (slave_port_id == primary_port_id) { -- int32_t ret = rte_eth_bond_primary_set(port_id, primary_port_id); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "dpdk set bond primary port failed ret = %d\n", ret); -- return -1; -+ if (primary_port_id < 0) { -+ LSTACK_LOG(ERR, LSTACK, "cannot get the port id of the cfg\n"); -+ return -1; -+ } -+ for (int i = 0; i < GAZELLE_MAX_BOND_NUM; i++) { -+ if (slave_port_id[i] == primary_port_id) { -+ int32_t ret = rte_eth_bond_primary_set(port_id, primary_port_id); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk set bond primary port failed ret = %d\n", ret); -+ return -1; -+ } -+ return ret; - } -- return ret; - } -- return 0; -+ LSTACK_LOG(ERR, LSTACK, "cfg: devices must be in bond_slave_mac for BONDING_MODE_ACTIVE_BACKUP.\n"); -+ return -1; - } - - int32_t dpdk_ethdev_init(int port_id) -@@ -687,12 +711,17 @@ static int dpdk_bond_create(uint8_t mode, int *slave_port_id, int count) - LSTACK_LOG(ERR, LSTACK, "bond add slave devices failed, ret=%d\n", ret); - return -1; - } -- if (cfg->bond_mode == BONDING_MODE_ACTIVE_BACKUP) { -- dpdk_bond_primary_set(port_id, slave_port_id[i]); -+ } -+ -+ if (cfg->bond_mode == BONDING_MODE_ACTIVE_BACKUP) { -+ ret = dpdk_bond_primary_set(port_id, slave_port_id); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "dpdk set bond primary port failed ret = %d\n", ret); -+ return -1; - } - } - -- if (get_global_cfg_params()->bond_mode == BONDING_MODE_8023AD) { -+ if (cfg->bond_mode == BONDING_MODE_8023AD) { - ret = rte_eth_bond_8023ad_dedicated_queues_enable(port_id); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk enable 8023 dedicated queues failed ret = %d\n", ret); -@@ -717,8 +746,7 @@ static int dpdk_bond_create(uint8_t mode, int *slave_port_id, int count) - return -1; - } - -- if ((get_global_cfg_params()->bond_mode == BONDING_MODE_8023AD) || -- (get_global_cfg_params()->bond_mode == BONDING_MODE_ALB)) { -+ if ((cfg->bond_mode == BONDING_MODE_8023AD) || (cfg->bond_mode == BONDING_MODE_ALB)) { - for (int i = 0; i < count; i++) { - /* bond port promiscuous only enable primary port */ - /* we enable all ports */ -@@ -742,17 +770,20 @@ static int dpdk_bond_create(uint8_t mode, int *slave_port_id, int count) - int32_t init_dpdk_ethdev(void) - { - int32_t ret; -- int slave_port_id[GAZELLE_MAX_BOND_NUM]; -+ int slave_port_id[GAZELLE_MAX_BOND_NUM] = {-1}; - int port_id; - struct cfg_params *cfg = get_global_cfg_params(); - int i; - - if (cfg->bond_mode >= 0) { - for (i = 0; i < GAZELLE_MAX_BOND_NUM; i++) { -- if (rte_is_zero_ether_addr(&cfg->bond_slave_mac_addr[i])) { -+ if (cfg->bond_slave_addr[i].addr_type == DEV_ADDR_TYPE_EMPTY) { - break; -+ } else if (cfg->bond_slave_addr[i].addr_type == DEV_ADDR_TYPE_MAC) { -+ slave_port_id[i] = ethdev_port_id(cfg->bond_slave_addr[i].addr.mac_addr.addr_bytes); -+ } else { -+ slave_port_id[i] = pci_to_port_id(&cfg->bond_slave_addr[i].addr.pci_addr); - } -- slave_port_id[i] = ethdev_port_id(cfg->bond_slave_mac_addr[i].addr_bytes); - ret = dpdk_ethdev_init(slave_port_id[i]); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "slave port(%d) init failed, ret=%d\n", slave_port_id[i], ret); -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 94878de..21d9d83 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -16,6 +16,8 @@ - - #include - #include -+#include -+#include - - #include "lstack_protocol_stack.h" - #include "gazelle_opt.h" -@@ -52,6 +54,18 @@ - #define LSTACK_LPM_PKTS_IN_DETECT_MIN 5 - #define LSTACK_LPM_PKTS_IN_DETECT_MAX 65535 - -+#define DEV_ADDR_TYPE_EMPTY 0 -+#define DEV_ADDR_TYPE_MAC 1 -+#define DEV_ADDR_TYPE_PCI 2 -+ -+struct dev_addr { -+ uint8_t addr_type; // 0:empty, 1:mac, 2:pci -+ union addr_union { -+ struct rte_ether_addr mac_addr; -+ struct rte_pci_addr pci_addr; -+ } addr; -+}; -+ - struct secondary_attach_arg { - uint8_t socket_num; - uint64_t socket_size; -@@ -114,7 +128,7 @@ struct cfg_params { - bool tuple_filter; - int8_t bond_mode; - int32_t bond_miimon; -- struct rte_ether_addr bond_slave_mac_addr[GAZELLE_MAX_BOND_NUM]; -+ struct dev_addr bond_slave_addr[GAZELLE_MAX_BOND_NUM]; - bool use_sockmap; - bool udp_enable; - struct cfg_nic_params nic; --- -2.33.0 - diff --git a/0194-refactor-tx-cache-module.patch b/0194-refactor-tx-cache-module.patch deleted file mode 100644 index 3516aaaf602500ad6a4ada779c032770cc42de68..0000000000000000000000000000000000000000 --- a/0194-refactor-tx-cache-module.patch +++ /dev/null @@ -1,340 +0,0 @@ -From dae1c41eea8dba45344f49c2fc00eeb31a24f925 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 17 Jun 2024 19:09:13 +0800 -Subject: [PATCH] refactor tx cache module - ---- - src/lstack/api/dir.mk | 2 +- - src/lstack/api/lstack_tx_cache.c | 47 --------- - src/lstack/core/lstack_cfg.c | 1 - - src/lstack/core/lstack_protocol_stack.c | 4 +- - src/lstack/include/lstack_protocol_stack.h | 1 - - src/lstack/include/lstack_tx_cache.h | 13 +-- - src/lstack/netif/dir.mk | 2 +- - src/lstack/netif/lstack_ethdev.c | 32 ++---- - src/lstack/netif/lstack_tx_cache.c | 114 +++++++++++++++++++++ - 9 files changed, 130 insertions(+), 86 deletions(-) - delete mode 100644 src/lstack/api/lstack_tx_cache.c - create mode 100644 src/lstack/netif/lstack_tx_cache.c - -diff --git a/src/lstack/api/dir.mk b/src/lstack/api/dir.mk -index 70bc59d..729690d 100644 ---- a/src/lstack/api/dir.mk -+++ b/src/lstack/api/dir.mk -@@ -8,7 +8,7 @@ - # PURPOSE. - # See the Mulan PSL v2 for more details. - --SRC = lstack_epoll.c lstack_signal.c lstack_fork.c lstack_wrap.c lstack_rtw_api.c lstack_rtc_api.c lstack_dummy_api.c lstack_tx_cache.c -+SRC = lstack_epoll.c lstack_signal.c lstack_fork.c lstack_wrap.c lstack_rtw_api.c lstack_rtc_api.c lstack_dummy_api.c - - $(eval $(call register_dir, api, $(SRC))) - -diff --git a/src/lstack/api/lstack_tx_cache.c b/src/lstack/api/lstack_tx_cache.c -deleted file mode 100644 -index 42aef57..0000000 ---- a/src/lstack/api/lstack_tx_cache.c -+++ /dev/null -@@ -1,47 +0,0 @@ --/* --* 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 "lwip/sockets.h" --#include "lstack_cfg.h" --#include "lstack_protocol_stack.h" --#include "lstack_tx_cache.h" -- --void stack_send_pkts(struct protocol_stack *stack) --{ -- if (!get_global_cfg_params()->send_cache_mode) { -- return; -- } -- -- uint32_t send_num = stack->tx_cache.send_end - stack->tx_cache.send_start; -- -- if (send_num == 0) { -- return; -- } -- -- uint32_t start = stack->tx_cache.send_start & STACK_SEND_MASK; -- uint32_t end = stack->tx_cache.send_end & STACK_SEND_MASK; -- uint32_t sent_pkts = 0; -- -- if (start < end) { -- sent_pkts = stack->dev_ops.tx_xmit(stack, &stack->tx_cache.send_pkts[start], send_num); -- } else { -- send_num = STACK_SEND_MAX - start; -- sent_pkts = stack->dev_ops.tx_xmit(stack, &stack->tx_cache.send_pkts[start], send_num); -- if (sent_pkts == send_num) { -- sent_pkts += stack->dev_ops.tx_xmit(stack, stack->tx_cache.send_pkts, end); -- } -- } -- -- stack->tx_cache.send_start += sent_pkts; -- stack->stats.tx += sent_pkts; --} -- -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index f0c5f4f..5521898 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -32,7 +32,6 @@ - #include "gazelle_reg_msg.h" - #include "lstack_log.h" - #include "gazelle_base_func.h" --#include "lstack_protocol_stack.h" - #include "lstack_cfg.h" - - #define DEFAULT_CONF_FILE "/etc/gazelle/lstack.conf" -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 74e543d..f6d381e 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -480,7 +480,9 @@ int stack_polling(uint32_t wakeup_tick) - do_lwip_read_recvlist(stack, read_connect_number); - if ((wakeup_tick & 0xf) == 0) { - wakeup_stack_epoll(stack); -- stack_send_pkts(stack); -+ if (get_global_cfg_params()->send_cache_mode) { -+ tx_cache_send(stack->queue_id); -+ } - } - - /* run to completion mode currently does not support sockmap */ -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index ab27dfa..6ca4f14 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -77,7 +77,6 @@ struct protocol_stack { - uint32_t tx_ring_used; - - struct rte_mbuf *pkts[NIC_QUEUE_SIZE_MAX]; -- struct lstack_tx_cache tx_cache; - struct list_node recv_list; - struct list_node same_node_recv_list; /* used for same node processes communication */ - struct list_node wakeup_list; -diff --git a/src/lstack/include/lstack_tx_cache.h b/src/lstack/include/lstack_tx_cache.h -index 3991b16..04e9e35 100644 ---- a/src/lstack/include/lstack_tx_cache.h -+++ b/src/lstack/include/lstack_tx_cache.h -@@ -13,16 +13,7 @@ - #ifndef _LSTACK_TX_CACHE_H_ - #define _LSTACK_TX_CACHE_H_ - --#define STACK_SEND_MAX (2048) --#define STACK_SEND_MASK (STACK_SEND_MAX - 1) --#define STACK_SEND_INDEX(index) ((index) & STACK_SEND_MASK) -- --struct lstack_tx_cache { -- uint32_t send_start; -- uint32_t send_end; -- struct rte_mbuf *send_pkts[STACK_SEND_MAX]; --}; -- --void stack_send_pkts(struct protocol_stack *stack); -+int tx_cache_init(uint16_t queue_id, void *priv, struct lstack_dev_ops *dev_ops); -+int tx_cache_send(uint16_t queue_id); - - #endif /* _LSTACK_TX_CACHE_H_ */ -diff --git a/src/lstack/netif/dir.mk b/src/lstack/netif/dir.mk -index 1e67734..b551041 100644 ---- a/src/lstack/netif/dir.mk -+++ b/src/lstack/netif/dir.mk -@@ -8,7 +8,7 @@ - # PURPOSE. - # See the Mulan PSL v2 for more details. - --SRC = lstack_ethdev.c lstack_vdev.c lstack_flow.c -+SRC = lstack_ethdev.c lstack_vdev.c lstack_flow.c lstack_tx_cache.c - ifeq ($(GAZELLE_FAULT_INJECT_ENABLE), 1) - SRC += lstack_fault_inject.c - endif -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 77172f8..45c5f9e 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -187,19 +187,6 @@ int32_t eth_dev_poll(void) - return nr_pkts; - } - --static void eth_dev_send_pkt(struct protocol_stack *stack, struct rte_mbuf *mbuf) --{ -- do { -- if (STACK_SEND_INDEX(stack->tx_cache.send_end + 1) != STACK_SEND_INDEX(stack->tx_cache.send_start)) { -- stack->tx_cache.send_pkts[STACK_SEND_INDEX(stack->tx_cache.send_end)] = mbuf; -- stack->tx_cache.send_end++; -- return; -- } -- stack_send_pkts(stack); -- stack->stats.send_pkts_fail++; -- } while (1); --} -- - static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - { - struct protocol_stack *stack = get_protocol_stack(); -@@ -245,16 +232,12 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - pbuf = pbuf->next; - } - -- if (!get_global_cfg_params()->send_cache_mode) { -- uint32_t sent_pkts = stack->dev_ops.tx_xmit(stack, &first_mbuf, 1); -- stack->stats.tx += sent_pkts; -- if (sent_pkts < 1) { -- stack->stats.tx_drop++; -- rte_pktmbuf_free(first_mbuf); -- return ERR_MEM; -- } -- } else { -- eth_dev_send_pkt(stack, first_mbuf); -+ uint32_t sent_pkts = stack->dev_ops.tx_xmit(stack, &first_mbuf, 1); -+ stack->stats.tx += sent_pkts; -+ if (sent_pkts < 1) { -+ stack->stats.tx_drop++; -+ rte_pktmbuf_free(first_mbuf); -+ return ERR_MEM; - } - - return ERR_OK; -@@ -295,6 +278,9 @@ int32_t ethdev_init(struct protocol_stack *stack) - struct cfg_params *cfg = get_global_cfg_params(); - - vdev_dev_ops_init(&stack->dev_ops); -+ if (cfg->send_cache_mode) { -+ tx_cache_init(stack->queue_id, stack, &stack->dev_ops); -+ } - - if (use_ltran()) { - stack->rx_ring_used = 0; -diff --git a/src/lstack/netif/lstack_tx_cache.c b/src/lstack/netif/lstack_tx_cache.c -new file mode 100644 -index 0000000..ac5a9db ---- /dev/null -+++ b/src/lstack/netif/lstack_tx_cache.c -@@ -0,0 +1,114 @@ -+/* -+* 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 -+ -+#include "lwip/sockets.h" -+#include "lstack_ethdev.h" -+#include "lstack_log.h" -+#include "gazelle_opt.h" -+#include "lstack_protocol_stack.h" -+#include "lstack_tx_cache.h" -+ -+#define TX_CACHE_MAX 128 -+#define TX_CACHE_MASK (TX_CACHE_MAX - 1) -+#define TX_CACHE_INDEX(index) ((index) & TX_CACHE_MASK) -+ -+struct tx_cache { -+ uint16_t port_id; -+ uint16_t queue_id; -+ -+ uint32_t send_start; -+ uint32_t send_end; -+ struct rte_mbuf *send_pkts[TX_CACHE_MAX]; -+ -+ uint64_t send_pkts_fail; -+ void *priv; -+}; -+struct lstack_dev_ops g_tx_cache_dev_ops; -+ -+static uint32_t tx_cache_recv(struct protocol_stack *stack, struct rte_mbuf **pkts, uint32_t nr_pkts); -+ -+struct tx_cache *g_tx_cache[PROTOCOL_STACK_MAX]; -+ -+int tx_cache_init(uint16_t queue_id, void *priv, struct lstack_dev_ops *dev_ops) -+{ -+ struct tx_cache *tx_cache = calloc(1, sizeof(struct tx_cache)); -+ if (tx_cache == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "queue(%d) tx cache init failed\n", queue_id); -+ } -+ -+ tx_cache->queue_id = queue_id; -+ tx_cache->priv = priv; -+ g_tx_cache[queue_id] = tx_cache; -+ -+ g_tx_cache_dev_ops.tx_xmit = dev_ops->tx_xmit; -+ dev_ops->tx_xmit = tx_cache_recv; -+ -+ return 0; -+} -+ -+int tx_cache_send(uint16_t queue_id) -+{ -+ struct tx_cache *tx_cache = g_tx_cache[queue_id]; -+ if (tx_cache == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "queue(%d) tx cache get failed\n", queue_id); -+ return 0; -+ } -+ -+ uint32_t send_num = tx_cache->send_end - tx_cache->send_start; -+ if (send_num == 0) { -+ return 0; -+ } -+ -+ uint32_t start = tx_cache->send_start & TX_CACHE_MASK; -+ uint32_t end = tx_cache->send_end & TX_CACHE_MASK; -+ uint32_t sent_pkts = 0; -+ if (start < end) { -+ sent_pkts = g_tx_cache_dev_ops.tx_xmit(tx_cache->priv, &tx_cache->send_pkts[start], send_num); -+ } else { -+ send_num = TX_CACHE_MAX - start; -+ sent_pkts = g_tx_cache_dev_ops.tx_xmit(tx_cache->priv, &tx_cache->send_pkts[start], send_num); -+ if (sent_pkts == send_num) { -+ sent_pkts += g_tx_cache_dev_ops.tx_xmit(tx_cache->priv, tx_cache->send_pkts, end); -+ } -+ } -+ -+ tx_cache->send_start += sent_pkts; -+ return sent_pkts; -+} -+ -+static uint32_t tx_cache_recv(struct protocol_stack *stack, struct rte_mbuf **pkts, uint32_t nr_pkts) -+{ -+ if (nr_pkts != 1) { -+ LSTACK_LOG(ERR, LSTACK, "arg not support, nr_pkts is %d\n", nr_pkts); -+ return 0; -+ } -+ uint16_t queue_id = stack->queue_id; -+ struct tx_cache *tx_cache = g_tx_cache[queue_id]; -+ if (tx_cache == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "queue(%d) tx cache get failed\n", queue_id); -+ return 0; -+ } -+ -+ do { -+ if (TX_CACHE_INDEX(tx_cache->send_end + 1) != TX_CACHE_INDEX(tx_cache->send_start)) { -+ tx_cache->send_pkts[TX_CACHE_INDEX(tx_cache->send_end)] = pkts[0]; -+ tx_cache->send_end++; -+ return nr_pkts; -+ } -+ -+ tx_cache_send(queue_id); -+ } while (1); -+ -+ return 0; -+} --- -2.33.0 - diff --git a/0195-virtio-create-and-init-virtio_port.patch b/0195-virtio-create-and-init-virtio_port.patch deleted file mode 100644 index 0c7706a7c57a8b7fe6fd809973626243b9a3282f..0000000000000000000000000000000000000000 --- a/0195-virtio-create-and-init-virtio_port.patch +++ /dev/null @@ -1,392 +0,0 @@ -From 696cd69752032e55ef301f3eb4f7ad42693137ab Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Mon, 17 Jun 2024 14:33:50 +0800 -Subject: [PATCH] [virtio]: create and init virtio_port - ---- - src/lstack/core/dir.mk | 2 +- - src/lstack/core/lstack_dpdk.c | 6 +- - src/lstack/core/lstack_port_map.c | 43 ++++++ - src/lstack/core/lstack_virtio.c | 201 +++++++++++++++++++++++++++ - src/lstack/include/lstack_port_map.h | 20 +++ - src/lstack/include/lstack_virtio.h | 36 +++++ - 6 files changed, 306 insertions(+), 2 deletions(-) - create mode 100644 src/lstack/core/lstack_port_map.c - create mode 100644 src/lstack/core/lstack_virtio.c - create mode 100644 src/lstack/include/lstack_port_map.h - create mode 100644 src/lstack/include/lstack_virtio.h - -diff --git a/src/lstack/core/dir.mk b/src/lstack/core/dir.mk -index e2d10a5..21b0d22 100644 ---- a/src/lstack/core/dir.mk -+++ b/src/lstack/core/dir.mk -@@ -8,6 +8,6 @@ - # PURPOSE. - # See the Mulan PSL v2 for more details. - --SRC = lstack_preload.c lstack_init.c lstack_cfg.c lstack_dpdk.c lstack_control_plane.c lstack_stack_stat.c lstack_lwip.c lstack_protocol_stack.c lstack_thread_rpc.c -+SRC = lstack_preload.c lstack_init.c lstack_cfg.c lstack_dpdk.c lstack_control_plane.c lstack_stack_stat.c lstack_lwip.c lstack_protocol_stack.c lstack_thread_rpc.c lstack_virtio.c lstack_port_map.c - $(eval $(call register_dir, core, $(SRC))) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 785431f..b0d76bf 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -49,6 +49,7 @@ - #include "lstack_thread_rpc.h" - #include "lstack_lwip.h" - #include "lstack_cfg.h" -+#include "lstack_virtio.h" - #include "lstack_dpdk.h" - - struct eth_params { -@@ -771,7 +772,7 @@ int32_t init_dpdk_ethdev(void) - { - int32_t ret; - int slave_port_id[GAZELLE_MAX_BOND_NUM] = {-1}; -- int port_id; -+ int port_id = 0; - struct cfg_params *cfg = get_global_cfg_params(); - int i; - -@@ -813,6 +814,9 @@ int32_t init_dpdk_ethdev(void) - } - } - #endif -+ if (get_global_cfg_params()->flow_bifurcation && virtio_port_create(port_id) != 0) { -+ return -1; -+ } - - return 0; - } -diff --git a/src/lstack/core/lstack_port_map.c b/src/lstack/core/lstack_port_map.c -new file mode 100644 -index 0000000..e5008b3 ---- /dev/null -+++ b/src/lstack/core/lstack_port_map.c -@@ -0,0 +1,43 @@ -+/* -+ * 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 -+#include -+#include "lstack_port_map.h" -+ -+#define PORT_MAP_UNIX_TCP_PORT_MAX 65535 -+#define PORT_MAP_EIGHT_BIT 8 -+ -+static uint8_t g_rule_port[(PORT_MAP_UNIX_TCP_PORT_MAX + 1) / PORT_MAP_EIGHT_BIT]; // 8k byte -+static pthread_mutex_t g_rule_map_mutex = PTHREAD_MUTEX_INITIALIZER; -+ -+void port_map_set(uint32_t modBit, int setVal) -+{ -+ pthread_mutex_lock(&g_rule_map_mutex); -+ g_rule_port[modBit / PORT_MAP_EIGHT_BIT] &= ~(1 << (modBit % PORT_MAP_EIGHT_BIT)); -+ g_rule_port[modBit / PORT_MAP_EIGHT_BIT] |= (setVal << (modBit % PORT_MAP_EIGHT_BIT)); -+ pthread_mutex_unlock(&g_rule_map_mutex); -+} -+ -+int port_map_get(int bit_index) -+{ -+ int bit_val = 0; -+ int byte_index = bit_index / PORT_MAP_EIGHT_BIT; -+ int bit_offset = bit_index % PORT_MAP_EIGHT_BIT; -+ uint8_t mask = 1 << bit_offset; -+ pthread_mutex_lock(&g_rule_map_mutex); -+ if ((g_rule_port[byte_index] & mask) != 0) { -+ bit_val = 1; -+ } -+ pthread_mutex_unlock(&g_rule_map_mutex); -+ return bit_val; -+} -\ No newline at end of file -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -new file mode 100644 -index 0000000..810e343 ---- /dev/null -+++ b/src/lstack/core/lstack_virtio.c -@@ -0,0 +1,201 @@ -+/* -+ * 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 -+#include "lstack_cfg.h" -+#include "lstack_log.h" -+#include "lstack_port_map.h" -+#include "lstack_virtio.h" -+ -+#define VIRTIO_USER_NAME "virtio_user0" -+#define VIRTIO_DPDK_PARA_LEN 256 -+#define VIRTIO_TX_RX_RING_SIZE 1024 -+ -+static struct virtio_instance g_virtio_instance = {0}; -+ -+struct virtio_instance* virtio_instance_get(void) -+{ -+ return &g_virtio_instance; -+} -+ -+static int virtio_set_ipv6_addr(void) -+{ -+ return 0; -+} -+ -+static int virtio_cfg_ip(void) -+{ -+ // set ipv4 adr() -+ -+ // set ipv6 addr -+ virtio_set_ipv6_addr(); -+ return 0; -+} -+ -+void virtio_tap_process_rx(uint16_t port, uint32_t queue_id) -+{ -+ struct rte_mbuf *pkts_burst[VIRTIO_TX_RX_RING_SIZE]; -+ uint16_t lstack_net_port = port; -+ uint32_t pkg_num; -+ -+ pkg_num = rte_eth_rx_burst(g_virtio_instance.virtio_port_id, queue_id, pkts_burst, VIRTIO_TX_RX_RING_SIZE); -+ if (pkg_num > 0) { -+ g_virtio_instance.rx_pkg[queue_id] += pkg_num; -+ uint16_t nb_rx = rte_eth_tx_burst(lstack_net_port, queue_id, pkts_burst, pkg_num); -+ for (uint16_t i = nb_rx; i < pkg_num; ++i) { -+ rte_pktmbuf_free(pkts_burst[i]); -+ g_virtio_instance.rx_drop[queue_id]++; -+ } -+ } -+} -+ -+void virtio_tap_process_tx(uint16_t queue_id, struct rte_mbuf *mbuf_copy) -+{ -+ int tx_num = rte_eth_tx_burst(g_virtio_instance.virtio_port_id, queue_id, &(mbuf_copy), 1); -+ if (tx_num < 0) { -+ rte_pktmbuf_free(mbuf_copy); -+ g_virtio_instance.tx_drop[queue_id]++; -+ LSTACK_LOG(ERR, LSTACK, "virtio_tap_process_tx failed %d, %d\n", queue_id, tx_num); -+ } -+ g_virtio_instance.tx_pkg[queue_id]++; -+} -+ -+static int virtio_port_init(uint16_t port) -+{ -+ int retval; -+ uint16_t rx_queue_num = g_virtio_instance.rx_queue_num; -+ uint16_t tx_queue_num = g_virtio_instance.tx_queue_num; -+ -+ LSTACK_LOG(INFO, LSTACK, "virtio_port_init port= %u rx_queue_num=%u tx_queue_num=%u \n", -+ port, rx_queue_num, tx_queue_num); -+ -+ struct rte_eth_conf port_conf; -+ memset(&port_conf, 0, sizeof(struct rte_eth_conf)); -+ -+ struct rte_eth_dev_info dev_info; -+ retval = rte_eth_dev_info_get(port, &dev_info); -+ if (retval != 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_dev_info_get failed(port %u) info: %d\n", port, retval); -+ return retval; -+ } -+ -+ retval = rte_eth_dev_configure(port, rx_queue_num, tx_queue_num, &port_conf); -+ if (retval != 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_dev_configure failed retval=%d\n", retval); -+ return retval; -+ } -+ -+ for (uint16_t q = 0; q < tx_queue_num; q++) { -+ retval = rte_eth_tx_queue_setup(port, q, VIRTIO_TX_RX_RING_SIZE, rte_eth_dev_socket_id(port), NULL); -+ if (retval < 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_tx_queue_setup failed (queue %u) retval=%d \n", q, retval); -+ return retval; -+ } -+ } -+ -+ for (uint16_t q = 0; q < rx_queue_num; q++) { -+ struct rte_mempool *rxtx_mbuf_pool = get_protocol_stack_group()->total_rxtx_pktmbuf_pool[q]; -+ retval = rte_eth_rx_queue_setup(port, q, VIRTIO_TX_RX_RING_SIZE, rte_eth_dev_socket_id(port), -+ NULL, rxtx_mbuf_pool); -+ if (retval < 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_rx_queue_setup failed (queue %u) retval=%d \n", q, retval); -+ return retval; -+ } -+ } -+ return 0; -+} -+ -+static int32_t virtio_port_start(uint16_t virtio_port) -+{ -+ int retval = 0; -+ if (virtio_port_init(virtio_port) < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_port_init failed \n"); -+ return -1; -+ } -+ -+ retval = rte_eth_dev_start(virtio_port); -+ if (retval < 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_dev_start failed retval=%d\n", retval); -+ return retval; -+ } -+ -+ if (virtio_cfg_ip() != 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_cfg_ip_mac failed\n"); -+ return -1; -+ } -+ LSTACK_LOG(INFO, LSTACK, "virtio_user lstack_net_port=%u virtio_port=%u rx_queue_num = %u tx_queue_num = %u\n", -+ g_virtio_instance.lstack_port_id, g_virtio_instance.virtio_port_id, -+ g_virtio_instance.rx_queue_num, g_virtio_instance.tx_queue_num); -+ return 0; -+} -+int virtio_port_create(int lstack_net_port) -+{ -+ char portargs[VIRTIO_DPDK_PARA_LEN] = {0}; -+ -+ struct rte_ether_addr addr; -+ uint16_t virtio_port_id = 0xffff; // invalid val -+ -+ struct rte_eth_dev_info dev_info; -+ int ret = rte_eth_dev_info_get(lstack_net_port, &dev_info); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "get dev info ret=%d\n", ret); -+ return ret; -+ } -+ -+ g_virtio_instance.rx_queue_num = dev_info.nb_rx_queues; -+ g_virtio_instance.tx_queue_num = dev_info.nb_tx_queues; -+ -+ if (g_virtio_instance.rx_queue_num > VIRTIO_MAX_QUEUE_NUM || -+ g_virtio_instance.tx_queue_num > VIRTIO_MAX_QUEUE_NUM) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_port_create failed queue_num (%u %u) is bigger than %u\n", -+ g_virtio_instance.rx_queue_num, g_virtio_instance.tx_queue_num, VIRTIO_MAX_QUEUE_NUM); -+ return -1; -+ } -+ -+ int retval = rte_eth_macaddr_get(lstack_net_port, &addr); // virtio_user0'mac is same with lstack.conf MAC addr -+ if (retval != 0) { -+ LSTACK_LOG(ERR, LSTACK, " rte_eth_macaddr_get failed ret = %d\n", retval); -+ return retval; -+ } -+ -+ retval = snprintf(portargs, sizeof(portargs), -+ "path=/dev/vhost-net,queues=%u,queue_size=%u,iface=%s,mac=" RTE_ETHER_ADDR_PRT_FMT, -+ VIRTIO_MAX_QUEUE_NUM, VIRTIO_TX_RX_RING_SIZE, VIRTIO_USER_NAME, RTE_ETHER_ADDR_BYTES(&addr)); -+ if (retval < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio portargs snprintf failed ret=%d \n", retval); -+ return retval; -+ } -+ LSTACK_LOG(INFO, LSTACK, "virtio portargs=%s \n", portargs); -+ -+ retval = rte_eal_hotplug_add("vdev", VIRTIO_USER_NAME, portargs); -+ if (retval < 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eal_hotplug_add failed retval=%d : %s\n", retval, strerror(-retval)); -+ return retval; -+ } -+ -+ retval = rte_eth_dev_get_port_by_name(VIRTIO_USER_NAME, &virtio_port_id); -+ if (retval != 0) { -+ rte_eal_hotplug_remove("vdev", VIRTIO_USER_NAME); -+ LSTACK_LOG(ERR, LSTACK, "virtio_user0 not found\n"); -+ return -1; -+ } -+ -+ g_virtio_instance.virtio_port_id = virtio_port_id; -+ g_virtio_instance.lstack_port_id = lstack_net_port; -+ -+ retval = virtio_port_start(virtio_port_id); -+ if (retval != 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_port_start failed ret=%d\n", retval); -+ rte_eal_hotplug_remove("vdev", VIRTIO_USER_NAME); -+ return retval; -+ } -+ return 0; -+} -\ No newline at end of file -diff --git a/src/lstack/include/lstack_port_map.h b/src/lstack/include/lstack_port_map.h -new file mode 100644 -index 0000000..24ef53a ---- /dev/null -+++ b/src/lstack/include/lstack_port_map.h -@@ -0,0 +1,20 @@ -+/* -+ * 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 __LSTACK_PORT_MAP_H__ -+#define __LSTACK_PORT_MAP_H__ -+ -+#include -+ -+void port_map_set(uint32_t modBit, int setVal); -+int port_map_get(int bit_index); -+ -+#endif -\ No newline at end of file -diff --git a/src/lstack/include/lstack_virtio.h b/src/lstack/include/lstack_virtio.h -new file mode 100644 -index 0000000..5e001ca ---- /dev/null -+++ b/src/lstack/include/lstack_virtio.h -@@ -0,0 +1,36 @@ -+/* -+ * 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 __LSTACK_VIRTIO_H__ -+#define __LSTACK_VIRTIO_H__ -+ -+#include -+ -+#define VIRTIO_MAX_QUEUE_NUM 8 -+struct virtio_instance { -+ uint16_t lstack_port_id; -+ uint16_t virtio_port_id; -+ uint16_t rx_queue_num; -+ uint16_t tx_queue_num; -+ -+ uint64_t rx_pkg[VIRTIO_MAX_QUEUE_NUM]; -+ uint64_t rx_drop[VIRTIO_MAX_QUEUE_NUM]; -+ uint64_t tx_pkg[VIRTIO_MAX_QUEUE_NUM]; -+ uint64_t tx_drop[VIRTIO_MAX_QUEUE_NUM]; -+}; -+ -+void virtio_tap_process_rx(uint16_t port, uint32_t queue_id); -+void virtio_tap_process_tx(uint16_t queue_id, struct rte_mbuf *mbuf_copy); -+ -+int virtio_port_create(int lstack_net_port); -+ -+struct virtio_instance* virtio_instance_get(void); -+#endif -\ No newline at end of file --- -2.33.0 - diff --git a/0196-refactor-udp-send.patch b/0196-refactor-udp-send.patch deleted file mode 100644 index a6221436cc64c3f7d7a868fbdd237177f7d5e9c4..0000000000000000000000000000000000000000 --- a/0196-refactor-udp-send.patch +++ /dev/null @@ -1,341 +0,0 @@ -From c109336bcf860c9dd16ba8becd9de72ecdce4d8f Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Tue, 11 Jun 2024 14:15:49 +0800 -Subject: [PATCH] refactor udp send distinguish tcp/udp get_from_sendring - cancel the restrictioin that maximum of 2 rpc msg can be send over the same - udp sock - ---- - src/lstack/core/lstack_lwip.c | 107 ++++++++++++++++-------- - src/lstack/core/lstack_protocol_stack.c | 39 ++++++++- - src/lstack/core/lstack_thread_rpc.c | 29 ++++++- - src/lstack/include/lstack_lwip.h | 3 +- - src/lstack/include/lstack_rpc_proc.h | 3 +- - src/lstack/include/lstack_thread_rpc.h | 3 +- - 6 files changed, 141 insertions(+), 43 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 153c5cc..db948b0 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -101,7 +101,7 @@ static struct pbuf *init_mbuf_to_pbuf(struct rte_mbuf *mbuf, pbuf_layer layer, u - void *data = rte_pktmbuf_mtod(mbuf, void *); - struct pbuf *pbuf = pbuf_alloced_custom(layer, length, type, pbuf_custom, data, MAX_PACKET_SZ); - if (pbuf) { -- pbuf->allow_in = 1; -+ pbuf->allow_append = 1; - pbuf->addr = *IP_ANY_TYPE; - pbuf->port = 0; - pthread_spin_init(&pbuf->pbuf_lock, PTHREAD_PROCESS_SHARED); -@@ -227,24 +227,61 @@ struct pbuf *do_lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type typ - return init_mbuf_to_pbuf(mbuf, layer, length, type); - } - --struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags) -+static inline bool pbuf_allow_append(struct pbuf *pbuf, uint16_t remain_size) -+{ -+ pthread_spin_lock(&pbuf->pbuf_lock); -+ if (pbuf->tot_len > remain_size) { -+ pthread_spin_unlock(&pbuf->pbuf_lock); -+ return false; -+ } -+ if (pbuf->allow_append == 1) { -+ __sync_fetch_and_sub(&pbuf->allow_append, 1); -+ } -+ -+ pthread_spin_unlock(&pbuf->pbuf_lock); -+ return true; -+} -+ -+struct pbuf *do_lwip_udp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size) -+{ -+ int count; -+ /* when remain_size is 0, fill_sendring write one pbuf to sendring */ -+ if (remain_size == 0) { -+ count = 1; -+ } else { -+ count = (remain_size + MBUF_MAX_DATA_LEN - 1) / MBUF_MAX_DATA_LEN; -+ } -+ -+ struct pbuf *pbufs[count]; -+ -+ int actual_count = gazelle_ring_sc_dequeue(sock->send_ring, (void **)&pbufs, count); -+ if (unlikely(actual_count != count)) { -+ LSTACK_LOG(ERR, LSTACK, "udp get pbuf from sendring error, expected: %d, actual: %d\n", -+ count, actual_count); -+ } -+ -+ if (unlikely(pbufs[0]->tot_len != remain_size)) { -+ LSTACK_LOG(ERR, LSTACK, "udp get pbuf size error, expected: %d, actual: %d\n", -+ remain_size, pbufs[0]->tot_len); -+ } -+ -+ for (int i = 0; get_protocol_stack_group()->latency_start && i < count; i++) { -+ calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_WRITE_LWIP, 0); -+ } -+ -+ return pbufs[0]; -+} -+ -+struct pbuf *do_lwip_tcp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size) - { - struct pbuf *pbuf = NULL; - - if (unlikely(sock->send_pre_del)) { -- pbuf = sock->send_pre_del; -- pthread_spin_lock(&pbuf->pbuf_lock); -- if (pbuf->tot_len > remain_size) { -- pthread_spin_unlock(&pbuf->pbuf_lock); -- *apiflags &= ~TCP_WRITE_FLAG_MORE; -+ if (pbuf_allow_append(sock->send_pre_del, remain_size)) { -+ return sock->send_pre_del; -+ } else { - return NULL; - } -- if (pbuf->allow_in == 1) { -- __sync_fetch_and_sub(&pbuf->allow_in, 1); -- } -- pthread_spin_unlock(&pbuf->pbuf_lock); -- -- return pbuf; - } - - gazelle_ring_sc_dequeue(sock->send_ring, (void **)&pbuf, 1); -@@ -252,17 +289,6 @@ struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_s - return NULL; - } - -- /* udp send a pbuf chain, dequeue all pbufs except head pbuf */ -- if (NETCONN_IS_UDP(sock) && remain_size > MBUF_MAX_DATA_LEN) { -- int size = (remain_size + MBUF_MAX_DATA_LEN - 1) / MBUF_MAX_DATA_LEN - 1; -- struct pbuf *pbuf_used[size]; -- gazelle_ring_sc_dequeue(sock->send_ring, (void **)&pbuf_used, size); -- -- for (uint32_t i = 0; get_protocol_stack_group()->latency_start && i < size; i++) { -- calculate_lstack_latency(&sock->stack->latency, pbuf_used[i], GAZELLE_LATENCY_WRITE_LWIP, 0); -- } -- } -- - if (get_protocol_stack_group()->latency_start) { - calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LWIP, 0); - } -@@ -270,19 +296,11 @@ struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_s - sock->send_pre_del = pbuf; - - if (!gazelle_ring_readover_count(sock->send_ring)) { -- pthread_spin_lock(&pbuf->pbuf_lock); -- if (pbuf->tot_len > remain_size) { -- pthread_spin_unlock(&pbuf->pbuf_lock); -- *apiflags &= ~TCP_WRITE_FLAG_MORE; -+ if (!pbuf_allow_append(pbuf, remain_size)) { - return NULL; - } -- if (pbuf->allow_in == 1) { -- __sync_fetch_and_sub(&pbuf->allow_in, 1); -- } -- pthread_spin_unlock(&pbuf->pbuf_lock); - } else { - if (pbuf->tot_len > remain_size) { -- *apiflags &= ~TCP_WRITE_FLAG_MORE; - return NULL; - } - } -@@ -388,7 +406,7 @@ static inline struct pbuf *gazelle_ring_readlast(struct rte_ring *r) - if (pthread_spin_trylock(&last_pbuf->pbuf_lock) != 0) { - return NULL; - } -- if (last_pbuf->allow_in != 1) { -+ if (last_pbuf->allow_append != 1) { - pthread_spin_unlock(&last_pbuf->pbuf_lock); - return NULL; - } -@@ -675,17 +693,34 @@ ssize_t do_lwip_recvmsg_from_stack(int32_t s, const struct msghdr *message, int3 - return buflen; - } - --static inline void notice_stack_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags) -+static inline void notice_stack_tcp_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags) - { - // 2: call_num >= 2, don't need add new rpc send - if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) < 2) { -- while (rpc_call_send(&sock->stack->rpc_queue, fd, NULL, len, flags) < 0) { -+ while (rpc_call_tcp_send(&sock->stack->rpc_queue, fd, len, flags) < 0) { - usleep(1000); // 1000: wait 1ms to exec again - } - __sync_fetch_and_add(&sock->call_num, 1); - } - } - -+static inline void notice_stack_udp_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags) -+{ -+ __sync_fetch_and_add(&sock->call_num, 1); -+ while (rpc_call_udp_send(&sock->stack->rpc_queue, fd, len, flags) < 0) { -+ usleep(1000); // 1000: wait 1ms to exec again -+ } -+} -+ -+static inline void notice_stack_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags) -+{ -+ if (NETCONN_IS_UDP(sock)) { -+ notice_stack_udp_send(sock, fd, len, flags); -+ } else { -+ notice_stack_tcp_send(sock, fd, len, flags); -+ } -+} -+ - /* process on same node use ring to recv data */ - ssize_t gazelle_same_node_ring_recv(struct lwip_sock *sock, const void *buf, size_t len, int32_t flags) - { -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index f6d381e..d130c91 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -877,7 +877,7 @@ void stack_recv(struct rpc_msg *msg) - msg->args[MSG_ARG_3].i); - } - --void stack_send(struct rpc_msg *msg) -+void stack_tcp_send(struct rpc_msg *msg) - { - int32_t fd = msg->args[MSG_ARG_0].i; - size_t len = msg->args[MSG_ARG_1].size; -@@ -913,6 +913,39 @@ void stack_send(struct rpc_msg *msg) - return; - } - -+void stack_udp_send(struct rpc_msg *msg) -+{ -+ int32_t fd = msg->args[MSG_ARG_0].i; -+ size_t len = msg->args[MSG_ARG_1].size; -+ struct protocol_stack *stack = get_protocol_stack(); -+ int replenish_again; -+ uint32_t call_num; -+ -+ if (get_protocol_stack_group()->latency_start) { -+ calculate_rpcmsg_latency(&stack->latency, msg, GAZELLE_LATENCY_WRITE_RPC_MSG); -+ } -+ -+ struct lwip_sock *sock = get_socket(fd); -+ if (sock == NULL) { -+ msg->result = -1; -+ LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); -+ return; -+ } -+ -+ replenish_again = do_lwip_send(stack, sock->conn->callback_arg.socket, sock, len, 0); -+ call_num = __sync_fetch_and_sub(&sock->call_num, 1); -+ if (replenish_again < 0) { -+ return; -+ } -+ -+ if ((call_num == 1) && (replenish_again > 0)) { -+ rpc_call_replenish(&stack->rpc_queue, sock); -+ return; -+ } -+ -+ return; -+} -+ - /* any protocol stack thread receives arp packet and sync it to other threads so that it can have the arp table */ - void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack) - { -@@ -1040,6 +1073,10 @@ void stack_replenish_sendring(struct rpc_msg *msg) - struct lwip_sock *sock = (struct lwip_sock *)msg->args[MSG_ARG_0].p; - - msg->result = do_lwip_replenish_sendring(stack, sock); -+ if (msg->result == true) { -+ msg->recall_flag = 1; -+ rpc_call(&stack->rpc_queue, msg); -+ } - } - - void stack_get_conntable(struct rpc_msg *msg) -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 04bdc3a..e438c37 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -460,13 +460,36 @@ int32_t rpc_call_replenish(rpc_queue *queue, void *sock) - } - - msg->args[MSG_ARG_0].p = sock; -+ msg->sync_flag = 0; - -- return rpc_sync_call(queue, msg); -+ rpc_call(queue, msg); -+ return 0; -+} -+ -+int32_t rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(stack_tcp_send); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ if (get_protocol_stack_group()->latency_start) { -+ time_stamp_into_rpcmsg(get_socket_by_fd(fd)); -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].size = len; -+ msg->args[MSG_ARG_2].i = flags; -+ msg->sync_flag = 0; -+ -+ rpc_call(queue, msg); -+ -+ return 0; - } - --int32_t rpc_call_send(rpc_queue *queue, int fd, const void *buf, size_t len, int flags) -+int32_t rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_send); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_udp_send); - if (msg == NULL) { - return -1; - } -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index fa10e3f..85c9c20 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -33,7 +33,8 @@ int do_lwip_close(int32_t fd); - void do_lwip_init_sock(int32_t fd); - void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock); - --struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags); -+struct pbuf *do_lwip_tcp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size); -+struct pbuf *do_lwip_udp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size); - void do_lwip_get_from_sendring_over(struct lwip_sock *sock); - bool do_lwip_replenish_sendring(struct protocol_stack *stack, struct lwip_sock *sock); - ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, uint8_t apiflags); -diff --git a/src/lstack/include/lstack_rpc_proc.h b/src/lstack/include/lstack_rpc_proc.h -index 71f0c58..77b18bd 100644 ---- a/src/lstack/include/lstack_rpc_proc.h -+++ b/src/lstack/include/lstack_rpc_proc.h -@@ -30,7 +30,8 @@ void stack_getsockopt(struct rpc_msg *msg); - void stack_setsockopt(struct rpc_msg *msg); - void stack_fcntl(struct rpc_msg *msg); - void stack_ioctl(struct rpc_msg *msg); --void stack_send(struct rpc_msg *msg); -+void stack_tcp_send(struct rpc_msg *msg); -+void stack_udp_send(struct rpc_msg *msg); - void stack_mempool_size(struct rpc_msg *msg); - void stack_rpcpool_size(struct rpc_msg *msg); - void stack_create_shadow_fd(struct rpc_msg *msg); -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 276ebb2..fa98b0c 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -83,7 +83,8 @@ int32_t rpc_call_bind(rpc_queue *queue, int32_t fd, const struct sockaddr *addr, - int32_t rpc_call_listen(rpc_queue *queue, int s, int backlog); - int32_t rpc_call_accept(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen, int flags); - int32_t rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen); --int32_t rpc_call_send(rpc_queue *queue, int fd, const void *buf, size_t len, int flags); -+int32_t rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags); -+int32_t rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags); - int32_t rpc_call_getpeername(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen); - int32_t rpc_call_getsockname(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen); - int32_t rpc_call_getsockopt(rpc_queue *queue, int fd, int level, int optname, void *optval, socklen_t *optlen); --- -2.33.0 - diff --git a/0197-solve-compile-err-in-20.03.patch b/0197-solve-compile-err-in-20.03.patch deleted file mode 100644 index 1f5ccefd2bec492636a9f6de484fee50433c68e1..0000000000000000000000000000000000000000 --- a/0197-solve-compile-err-in-20.03.patch +++ /dev/null @@ -1,39 +0,0 @@ -From 7755b72b475fdb5fbd75f51cfb8dfd4a49b70852 Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Mon, 24 Jun 2024 15:26:31 +0800 -Subject: [PATCH] solve complie err in 20.03 RTE_ETHER_ADDR_PRT_FMT - RTE_ETHER_ADDR_BYTES are defined in dpdk 21.11 - ---- - src/lstack/include/lstack_virtio.h | 15 +++++++++++++++ - 1 file changed, 15 insertions(+) - -diff --git a/src/lstack/include/lstack_virtio.h b/src/lstack/include/lstack_virtio.h -index 5e001ca..d40c754 100644 ---- a/src/lstack/include/lstack_virtio.h -+++ b/src/lstack/include/lstack_virtio.h -@@ -15,6 +15,21 @@ - #include - - #define VIRTIO_MAX_QUEUE_NUM 8 -+ -+// RTE_ETHER_ADDR_PRT_FMT RTE_ETHER_ADDR_BYTES are defined in dpdk 21.11 -+#ifndef RTE_ETHER_ADDR_PRT_FMT -+#define RTE_ETHER_ADDR_PRT_FMT "%02X:%02X:%02X:%02X:%02X:%02X" -+#endif -+ -+#ifndef RTE_ETHER_ADDR_BYTES -+#define RTE_ETHER_ADDR_BYTES(mac_addrs) ((mac_addrs)->addr_bytes[0]), \ -+ ((mac_addrs)->addr_bytes[1]), \ -+ ((mac_addrs)->addr_bytes[2]), \ -+ ((mac_addrs)->addr_bytes[3]), \ -+ ((mac_addrs)->addr_bytes[4]), \ -+ ((mac_addrs)->addr_bytes[5]) -+#endif -+ - struct virtio_instance { - uint16_t lstack_port_id; - uint16_t virtio_port_id; --- -2.33.0 - diff --git a/0198-fix-function-call-error.patch b/0198-fix-function-call-error.patch deleted file mode 100644 index b6353afb25328682594e2f6ab76f0574a082274e..0000000000000000000000000000000000000000 --- a/0198-fix-function-call-error.patch +++ /dev/null @@ -1,66 +0,0 @@ -From bcf0dff302a8416cb7528ee44c2f0fb3138ff13e Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Tue, 25 Jun 2024 17:53:36 +0800 -Subject: [PATCH] fix function call error - ---- - src/lstack/core/lstack_protocol_stack.c | 8 ++++---- - src/lstack/core/lstack_stack_stat.c | 2 +- - src/lstack/include/lstack_stack_stat.h | 2 -- - 3 files changed, 5 insertions(+), 7 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index d130c91..d6e3c86 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -921,10 +921,6 @@ void stack_udp_send(struct rpc_msg *msg) - int replenish_again; - uint32_t call_num; - -- if (get_protocol_stack_group()->latency_start) { -- calculate_rpcmsg_latency(&stack->latency, msg, GAZELLE_LATENCY_WRITE_RPC_MSG); -- } -- - struct lwip_sock *sock = get_socket(fd); - if (sock == NULL) { - msg->result = -1; -@@ -932,6 +928,10 @@ void stack_udp_send(struct rpc_msg *msg) - return; - } - -+ if (get_protocol_stack_group()->latency_start) { -+ calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_WRITE_RPC_MSG); -+ } -+ - replenish_again = do_lwip_send(stack, sock->conn->callback_arg.socket, sock, len, 0); - call_num = __sync_fetch_and_sub(&sock->call_num, 1); - if (replenish_again < 0) { -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index a1bd44d..0f1f693 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -82,7 +82,7 @@ void time_stamp_record(int fd, struct pbuf *pbuf) - { - struct lwip_sock *sock = get_socket_by_fd(fd); - -- if (get_protocol_stack_group()->latency_start && pbuf != NULL) { -+ if (get_protocol_stack_group()->latency_start && sock && pbuf) { - calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_INTO_MBOX, 0); - time_stamp_into_recvmbox(sock); - } -diff --git a/src/lstack/include/lstack_stack_stat.h b/src/lstack/include/lstack_stack_stat.h -index f0d3d5d..9fca04a 100644 ---- a/src/lstack/include/lstack_stack_stat.h -+++ b/src/lstack/include/lstack_stack_stat.h -@@ -26,8 +26,6 @@ struct lwip_sock; - - void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, - enum GAZELLE_LATENCY_TYPE type, uint64_t time_record); --void calculate_rpcmsg_latency(struct gazelle_stack_latency *stack_latency, struct rpc_msg *msg, -- enum GAZELLE_LATENCY_TYPE type); - void calculate_sock_latency(struct gazelle_stack_latency *stack_latency, struct lwip_sock *sock, - enum GAZELLE_LATENCY_TYPE type); - void stack_stat_init(void); --- -2.33.0 - diff --git a/0199-perftool-add-latency-tool.patch b/0199-perftool-add-latency-tool.patch deleted file mode 100644 index 7bf1e21a2ca1b109e029d2cf5c856b57d9814798..0000000000000000000000000000000000000000 --- a/0199-perftool-add-latency-tool.patch +++ /dev/null @@ -1,57 +0,0 @@ -From a037f2d9d92ea4a5e659297c5c9839557040f1ce Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Fri, 21 Jun 2024 16:48:20 +0800 -Subject: [PATCH] perftool: add latency tool - ---- - tools/perf/latency.bt | 38 ++++++++++++++++++++++++++++++++++++++ - 1 file changed, 38 insertions(+) - create mode 100755 tools/perf/latency.bt - -diff --git a/tools/perf/latency.bt b/tools/perf/latency.bt -new file mode 100755 -index 0000000..bfe18ae ---- /dev/null -+++ b/tools/perf/latency.bt -@@ -0,0 +1,38 @@ -+#!/usr/bin/env bpftrace -+/* -+reference: https://github.com/bpftrace/bpftrace/blob/master/man/adoc/bpftrace.adoc -+prepare: yum install bpftrace -+example: ./latency.bt xxx.so func1 func2 -+supported functions: bpftrace -l 'uprobe:xxx.so' -+*/ -+ -+BEGIN -+{ -+} -+ -+uprobe:$1:$2 -+{ -+ @t_start[tid] = nsecs; -+} -+ -+uretprobe:$1:$3 -+/@t_start[tid]/ -+{ -+ $t_dur = nsecs - @t_start[tid]; -+ @t_avg = avg($t_dur); -+ -+ //@t_hist = lhist($t_dur, 0, 4000, 100); -+ @t_hist = hist($t_dur); -+ -+ delete(@t_start[tid]); -+} -+ -+END -+{ -+ printf("\n\n%s -> %s \n", str($2), str($3)); -+ printf("average time(nsec):"); -+ print(@t_avg); -+ -+ clear(@t_avg); -+ clear(@t_start); -+} --- -2.33.0 - diff --git a/0200-cfg-del-unnecessary-logs.patch b/0200-cfg-del-unnecessary-logs.patch deleted file mode 100644 index b1f8f23212c9a9e5d558f1115a72c4de54368ef7..0000000000000000000000000000000000000000 --- a/0200-cfg-del-unnecessary-logs.patch +++ /dev/null @@ -1,88 +0,0 @@ -From b83a8ba5bb2f7f689cbdb404d3352bd039def160 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Thu, 20 Jun 2024 16:58:38 +0800 -Subject: [PATCH] cfg: del unnecessary logs - ---- - src/lstack/core/lstack_cfg.c | 24 ++---------------------- - 1 file changed, 2 insertions(+), 22 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index a1afe70..a5918f1 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -100,7 +100,7 @@ static int32_t parse_flow_bifurcation(void); - } \ - int32_t _val = config_setting_get_int(_config_arg); \ - if (_val < (_min_val) || _val > (_max_val)) { \ -- LSTACK_PRE_LOG(LSTACK_ERR, "cfg %s %d invaild, range is [%d, %d].\n", \ -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg %s %d invalid, range is [%d, %d].\n", \ - (_arg_string), _val, (_min_val), (_max_val)); \ - (_ret) = -EINVAL; \ - break; \ -@@ -1196,7 +1196,7 @@ static int parse_tuple_filter(void) - return 0; - } - if (g_config_params.use_ltran || g_config_params.listen_shadow) { -- LSTACK_LOG(ERR, LSTACK, "tuple filter and (ltran or listen_shadow) cannot be enabled at the same time\n"); -+ LSTACK_LOG(ERR, LSTACK, "tuple filter and (ltran or listen_shadow) cannot be enabled at the same time\n"); - return -EINVAL; - } - -@@ -1356,10 +1356,6 @@ static int32_t parse_nic_vlan_mode(void) - { - int32_t ret; - PARSE_ARG(g_config_params.nic.vlan_mode, "nic_vlan_mode", -1, -1, 4094, ret); -- if (ret != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid vlan mode value %d ret=%d. only support -1~4094\n", \ -- g_config_params.nic.vlan_mode, ret); -- } - return ret; - } - -@@ -1367,10 +1363,6 @@ static int32_t parse_defaule_nonblock_mode(void) - { - int32_t ret; - PARSE_ARG(g_config_params.nonblock_mode, "nonblock_mode", 1, 0, 1, ret); -- if (ret != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid nonblock mode value %d. only support 0 or 1\n", \ -- g_config_params.nonblock_mode); -- } - return ret; - } - -@@ -1378,10 +1370,6 @@ static int32_t parse_rpc_msg_max(void) - { - int32_t ret; - PARSE_ARG(g_config_params.rpc_msg_max, "rpc_msg_max", 4096, 1, 8192, ret); -- if (ret != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid rpc msg max value %d ret=%d. only support 1~8192\n", -- g_config_params.rpc_msg_max, ret); -- } - return ret; - } - -@@ -1389,10 +1377,6 @@ static int32_t parse_send_cache_mode(void) - { - int32_t ret; - PARSE_ARG(g_config_params.send_cache_mode, "send_cache_mode", 0, 0, 1, ret); -- if (ret != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid send cache mode value %d. only support 0 or 1\n", -- g_config_params.send_cache_mode); -- } - return ret; - } - -@@ -1400,9 +1384,5 @@ static int32_t parse_flow_bifurcation(void) - { - int32_t ret; - PARSE_ARG(g_config_params.flow_bifurcation, "flow_bifurcation", 0, 0, 1, ret); -- if (ret != 0) { -- LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid flow_bifurcation value %d. only support 0 or 1\n", -- g_config_params.flow_bifurcation); -- } - return ret; - } --- -2.33.0 - diff --git a/0201-fix-dpdk_bond_primary_set-bug.patch b/0201-fix-dpdk_bond_primary_set-bug.patch deleted file mode 100644 index 9a7f813d7f8fa50af5a97e111cd5499e335fe4e5..0000000000000000000000000000000000000000 --- a/0201-fix-dpdk_bond_primary_set-bug.patch +++ /dev/null @@ -1,72 +0,0 @@ -From c65b58b68bf51cc09d1c2438e55d1dcb92ffd4ca Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Mon, 24 Jun 2024 10:43:50 +0800 -Subject: [PATCH] fix dpdk_bond_primary_set bug - ---- - src/lstack/core/lstack_dpdk.c | 15 +++++++++++---- - 1 file changed, 11 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index b0d76bf..6e52187 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -509,14 +509,14 @@ static void rss_setup(const int port_id, const uint16_t nb_queues) - free(reta_conf); - } - --int32_t dpdk_bond_primary_set(int port_id, int *slave_port_id) -+int32_t dpdk_bond_primary_set(int port_id, int *slave_port_id, int count) - { - int32_t primary_port_id = ethdev_port_id(get_global_cfg_params()->mac_addr); - if (primary_port_id < 0) { - LSTACK_LOG(ERR, LSTACK, "cannot get the port id of the cfg\n"); - return -1; - } -- for (int i = 0; i < GAZELLE_MAX_BOND_NUM; i++) { -+ for (int i = 0; i < count; i++) { - if (slave_port_id[i] == primary_port_id) { - int32_t ret = rte_eth_bond_primary_set(port_id, primary_port_id); - if (ret != 0) { -@@ -715,7 +715,7 @@ static int dpdk_bond_create(uint8_t mode, int *slave_port_id, int count) - } - - if (cfg->bond_mode == BONDING_MODE_ACTIVE_BACKUP) { -- ret = dpdk_bond_primary_set(port_id, slave_port_id); -+ ret = dpdk_bond_primary_set(port_id, slave_port_id, count); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk set bond primary port failed ret = %d\n", ret); - return -1; -@@ -771,7 +771,7 @@ static int dpdk_bond_create(uint8_t mode, int *slave_port_id, int count) - int32_t init_dpdk_ethdev(void) - { - int32_t ret; -- int slave_port_id[GAZELLE_MAX_BOND_NUM] = {-1}; -+ int slave_port_id[GAZELLE_MAX_BOND_NUM]; - int port_id = 0; - struct cfg_params *cfg = get_global_cfg_params(); - int i; -@@ -785,6 +785,10 @@ int32_t init_dpdk_ethdev(void) - } else { - slave_port_id[i] = pci_to_port_id(&cfg->bond_slave_addr[i].addr.pci_addr); - } -+ if (slave_port_id[i] < 0) { -+ LSTACK_LOG(ERR, LSTACK, "cfg->bond_slave_addr[%d] parsing failed, ret=%d\n", i, ret); -+ return -1; -+ } - ret = dpdk_ethdev_init(slave_port_id[i]); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "slave port(%d) init failed, ret=%d\n", slave_port_id[i], ret); -@@ -799,6 +803,9 @@ int32_t init_dpdk_ethdev(void) - } - } else { - port_id = ethdev_port_id(cfg->mac_addr); -+ if (port_id < 0) { -+ return -1; -+ } - ret = dpdk_ethdev_init(port_id); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed, port id=%d\n", port_id); --- -2.33.0 - diff --git a/0202-fix-build-failed-in-2003sp4.patch b/0202-fix-build-failed-in-2003sp4.patch deleted file mode 100644 index d0e38cf5886b061260330a3a79d6c7809a9f8a4d..0000000000000000000000000000000000000000 --- a/0202-fix-build-failed-in-2003sp4.patch +++ /dev/null @@ -1,25 +0,0 @@ -From a287036099c050f91bceaeb7bd1a3b5c1b0b6af6 Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Mon, 24 Jun 2024 20:01:58 +0800 -Subject: [PATCH] fix build failed in 2003sp4 - ---- - src/lstack/core/lstack_dpdk.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 6e52187..2de41e3 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -786,7 +786,7 @@ int32_t init_dpdk_ethdev(void) - slave_port_id[i] = pci_to_port_id(&cfg->bond_slave_addr[i].addr.pci_addr); - } - if (slave_port_id[i] < 0) { -- LSTACK_LOG(ERR, LSTACK, "cfg->bond_slave_addr[%d] parsing failed, ret=%d\n", i, ret); -+ LSTACK_LOG(ERR, LSTACK, "cfg->bond_slave_addr[%d] parsing failed.\n", i); - return -1; - } - ret = dpdk_ethdev_init(slave_port_id[i]); --- -2.33.0 - diff --git a/0203-virtio-cfg-ipv4-and-ipv6-addr.patch b/0203-virtio-cfg-ipv4-and-ipv6-addr.patch deleted file mode 100644 index a2df27caf00b6b024817eada1de1c60c36c08c11..0000000000000000000000000000000000000000 --- a/0203-virtio-cfg-ipv4-and-ipv6-addr.patch +++ /dev/null @@ -1,190 +0,0 @@ -From e2bdddb748e891312aa6e2c67a44ba265ca16edf Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Fri, 21 Jun 2024 09:20:03 +0800 -Subject: [PATCH] [virtio]: cfg ipv4 and ipv6 addr - ---- - src/lstack/core/lstack_virtio.c | 140 +++++++++++++++++++++++++++++++- - 1 file changed, 136 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index 810e343..c3b3511 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -10,15 +10,23 @@ - * See the Mulan PSL v2 for more details. - */ - #include -+#include -+#include -+#include -+#include -+#include - #include "lstack_cfg.h" - #include "lstack_log.h" - #include "lstack_port_map.h" - #include "lstack_virtio.h" -+#include "securec.h" - - #define VIRTIO_USER_NAME "virtio_user0" - #define VIRTIO_DPDK_PARA_LEN 256 - #define VIRTIO_TX_RX_RING_SIZE 1024 - -+#define VIRTIO_MASK_BITS(mask) (32 - __builtin_clz(mask)) -+ - static struct virtio_instance g_virtio_instance = {0}; - - struct virtio_instance* virtio_instance_get(void) -@@ -28,15 +36,139 @@ struct virtio_instance* virtio_instance_get(void) - - static int virtio_set_ipv6_addr(void) - { -+ struct cfg_params *cfg = get_global_cfg_params(); -+ struct ifreq ifr; -+ memset_s(&ifr, sizeof(ifr), 0, sizeof(ifr)); -+ -+ int sockfd = posix_api->socket_fn(AF_INET6, SOCK_DGRAM, 0); -+ if (sockfd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv6_addr failed ret =%d errno=%d \n", sockfd, errno); -+ return -1; -+ } -+ -+ int ret = strncpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), VIRTIO_USER_NAME, sizeof(VIRTIO_USER_NAME)); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv6_addr strncpy failed ret =%d errno=%d \n", ret, errno); -+ posix_api->close_fn(sockfd); -+ return -1; -+ } -+ -+ ret = posix_api->ioctl_fn(sockfd, SIOGIFINDEX, &ifr); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv6_addr failed ret =%d errno=%d \n", ret, errno); -+ posix_api->close_fn(sockfd); -+ return -1; -+ } -+ -+ struct in6_ifreq ifr6; -+ memset_s(&ifr6, sizeof(ifr6), 0, sizeof(ifr6)); -+ ret = memcpy_s(&ifr6.ifr6_addr, sizeof(ifr6.ifr6_addr), &(cfg->host_addr6), sizeof((cfg->host_addr6.addr))); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv6_addr memcpy_s failed ret =%d errno=%d \n", ret, errno); -+ posix_api->close_fn(sockfd); -+ return -1; -+ } -+ -+ ifr6.ifr6_ifindex = ifr.ifr_ifindex; -+ ifr6.ifr6_prefixlen = VIRTIO_MASK_BITS(cfg->netmask.addr); -+ -+ ret = posix_api->ioctl_fn(sockfd, SIOCSIFADDR, &ifr6); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv6_addr failed err= %d errno %d \n", ret, errno); -+ posix_api->close_fn(sockfd); -+ return -1; -+ } -+ posix_api->close_fn(sockfd); -+ return 0; -+} -+ -+static int virtio_set_ipv4_addr(void) -+{ -+ int ret = 0; -+ int sockfd = posix_api->socket_fn(AF_INET, SOCK_DGRAM, 0); -+ if (sockfd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv6_addr failed ret= %d errno %d \n", sockfd, errno); -+ return -1; -+ } -+ -+ struct cfg_params *cfg = get_global_cfg_params(); -+ struct ifreq ifr; -+ memset_s(&ifr, sizeof(ifr), 0, sizeof(ifr)); -+ -+ ret = strcpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), VIRTIO_USER_NAME); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv4_addr strcpy_s failed ret=%d errno %d \n", ret, errno); -+ posix_api->close_fn(sockfd); -+ return -1; -+ } -+ -+ struct sockaddr_in *addr = (struct sockaddr_in *)&ifr.ifr_addr; -+ addr->sin_family = AF_INET; -+ addr->sin_addr.s_addr = cfg->host_addr.addr; -+ -+ if (posix_api->ioctl_fn(sockfd, SIOCSIFADDR, &ifr) < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_cfg_ip failed errno %d \n", errno); -+ posix_api->close_fn(sockfd); -+ return -1; -+ } -+ -+ addr->sin_addr.s_addr = cfg->netmask.addr; -+ if (posix_api->ioctl_fn(sockfd, SIOCSIFNETMASK, &ifr) < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_cfg_ip netmask=%u fail\n", cfg->netmask.addr); -+ posix_api->close_fn(sockfd); -+ return -1; -+ } -+ posix_api->close_fn(sockfd); -+ return 0; -+} -+ -+static int virtio_netif_up(void) -+{ -+ int sockfd = posix_api->socket_fn(AF_INET, SOCK_DGRAM, 0); -+ if (sockfd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_netif_up socket_fn failed ret= %d errno %d \n", sockfd, errno); -+ return -1; -+ } -+ -+ struct ifreq ifr; -+ memset_s(&ifr, sizeof(ifr), 0, sizeof(ifr)); -+ int ret = strcpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), VIRTIO_USER_NAME); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_netif_up strcpy_s failed ret=%d errno %d \n", ret, errno); -+ posix_api->close_fn(sockfd); -+ return -1; -+ } -+ -+ ifr.ifr_flags |= IFF_UP; -+ if (posix_api->ioctl_fn(sockfd, SIOCSIFFLAGS, &ifr) < 0) { -+ posix_api->close_fn(sockfd); -+ LSTACK_LOG(ERR, LSTACK, " virtio_netif_up ioctl_fn failed errno= %d \n", errno); -+ return -1; -+ } -+ -+ posix_api->close_fn(sockfd); - return 0; - } - - static int virtio_cfg_ip(void) - { -- // set ipv4 adr() -+ struct cfg_params *cfg = get_global_cfg_params(); - -- // set ipv6 addr -- virtio_set_ipv6_addr(); -+ if (virtio_set_ipv4_addr() < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv4_addr failed \n"); -+ return -1; -+ } -+ -+ if (!ip6_addr_isany(&cfg->host_addr6) && virtio_set_ipv6_addr() < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv6_addr failed \n"); -+ return -1; -+ } -+ -+ // start virtio_user -+ if (virtio_netif_up() < 0) { -+ LSTACK_LOG(ERR, LSTACK, "virtio_netif_up failed \n"); -+ return -1; -+ } - return 0; - } - -@@ -198,4 +330,4 @@ int virtio_port_create(int lstack_net_port) - return retval; - } - return 0; --} -\ No newline at end of file -+} --- -2.33.0 - diff --git a/0204-parse-packages-type-in-rx_poll.patch b/0204-parse-packages-type-in-rx_poll.patch deleted file mode 100644 index 35a7d0f3a41b326198f745441c9398015dddf24e..0000000000000000000000000000000000000000 --- a/0204-parse-packages-type-in-rx_poll.patch +++ /dev/null @@ -1,168 +0,0 @@ -From c7fff9e6eb2ba6f9d71389dc43c606b55f9379ce Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Tue, 18 Jun 2024 15:33:14 +0800 -Subject: [PATCH] parse packages type in rx_poll - ---- - src/lstack/netif/lstack_ethdev.c | 28 ++++++++--- - src/lstack/netif/lstack_vdev.c | 84 ++++++++++++++++++++------------ - 2 files changed, 73 insertions(+), 39 deletions(-) - -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 45c5f9e..3bfa8af 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -130,6 +130,25 @@ void kni_handle_tx(struct rte_mbuf *mbuf) - } - #endif - -+#define IS_ARP_PKT(ptype) ((ptype & RTE_PTYPE_L2_ETHER_ARP) == RTE_PTYPE_L2_ETHER_ARP) -+#define IS_IPV4_TCP_PKT(ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ -+ ((ptype & RTE_PTYPE_L4_TCP) == RTE_PTYPE_L4_TCP) && \ -+ ((ptype & RTE_PTYPE_L4_FRAG) != RTE_PTYPE_L4_FRAG) && \ -+ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0)) -+ -+#define IS_IPV6_TCP_PKT(ptype) (RTE_ETH_IS_IPV6_HDR(ptype) && \ -+ ((ptype & RTE_PTYPE_L4_TCP) == RTE_PTYPE_L4_TCP) && \ -+ ((ptype & RTE_PTYPE_L4_FRAG) != RTE_PTYPE_L4_FRAG) && \ -+ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0)) -+ -+#define IS_IPV4_UDP_PKT(ptype) (RTE_ETH_IS_IPV4_HDR(ptype) && \ -+ ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \ -+ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0)) -+ -+#define IS_IPV6_UDP_PKT(ptype) (RTE_ETH_IS_IPV6_HDR(ptype) && \ -+ ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \ -+ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0)) -+ - int32_t eth_dev_poll(void) - { - uint32_t nr_pkts; -@@ -151,14 +170,7 @@ int32_t eth_dev_poll(void) - int transfer_type = TRANSFER_CURRENT_THREAD; - /* copy arp into other stack */ - if (!use_ltran()) { -- struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(stack->pkts[i], struct rte_ether_hdr *); -- u16_t type; -- type = ethh->ether_type; -- if (type == PP_HTONS(ETHTYPE_VLAN)) { -- struct eth_vlan_hdr *vlan = (struct eth_vlan_hdr *)(((char *)ethh) + SIZEOF_ETH_HDR); -- type = vlan->tpid; -- } -- if (unlikely(RTE_BE16(RTE_ETHER_TYPE_ARP) == type)) { -+ if (unlikely(IS_ARP_PKT(stack->pkts[i]->packet_type))) { - stack_broadcast_arp(stack->pkts[i], stack); - /* copy arp into other process */ - transfer_arp_to_other_process(stack->pkts[i]); -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 107ee8c..5ce69a9 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -72,6 +72,58 @@ static uint32_t ltran_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pk - return rcvd_pkts; - } - -+static inline void vdev_pkts_parse(struct rte_mbuf **pkts, int pkt_num) -+{ -+ for (int i = 0; i < pkt_num; i++) { -+ struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *); -+ u16_t type = ethh->ether_type; -+ if (type == RTE_BE16(RTE_ETHER_TYPE_VLAN)) { -+ struct rte_vlan_hdr *vlan = (struct rte_vlan_hdr *)(ethh + 1); -+ type = vlan->eth_proto; -+ pkts[i]->l2_len = sizeof(struct rte_ether_hdr) + sizeof(struct rte_vlan_hdr); -+ } else { -+ pkts[i]->l2_len = sizeof(struct rte_ether_hdr); -+ } -+ -+ if (type == RTE_BE16(RTE_ETHER_TYPE_IPV4)) { -+ struct rte_ipv4_hdr *iph = rte_pktmbuf_mtod_offset(pkts[i], struct rte_ipv4_hdr *, -+ pkts[i]->l2_len); -+ if (unlikely((iph->version_ihl & IPV4_MASK) != IPV4_VERION)) { -+ continue; -+ } -+ pkts[i]->l3_len = sizeof(struct rte_ipv4_hdr); -+ if (iph->next_proto_id == IPPROTO_TCP) { -+ struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(pkts[i], struct rte_tcp_hdr *, -+ pkts[i]->l2_len + pkts[i]->l3_len); -+ pkts[i]->l4_len = TCP_HDR_LEN(tcp_hdr); -+ -+ pkts[i]->packet_type = RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP; -+ } else if (iph->next_proto_id == IPPROTO_UDP) { -+ pkts[i]->l4_len = sizeof(struct rte_udp_hdr); -+ pkts[i]->packet_type = RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP; -+ } -+ -+ } else if (type == RTE_BE16(RTE_ETHER_TYPE_IPV6)) { -+ struct rte_ipv6_hdr *iph6 = rte_pktmbuf_mtod_offset(pkts[i], struct rte_ipv6_hdr *, -+ pkts[i]->l2_len); -+ pkts[i]->l3_len = sizeof(struct rte_ipv6_hdr); -+ if (iph6->proto == IPPROTO_TCP) { -+ struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(pkts[i], struct rte_tcp_hdr *, -+ pkts[i]->l2_len + pkts[i]->l3_len); -+ pkts[i]->l4_len = TCP_HDR_LEN(tcp_hdr); -+ pkts[i]->packet_type = RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP; -+ } else if (iph6->proto == IPPROTO_UDP) { -+ pkts[i]->l4_len = sizeof(struct rte_udp_hdr); -+ pkts[i]->packet_type = RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP; -+ } -+ } else if (type == RTE_BE16(RTE_ETHER_TYPE_ARP)) { -+ pkts[i]->packet_type = RTE_PTYPE_L2_ETHER_ARP; -+ } else { -+ continue; -+ } -+ } -+} -+ - static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkts, uint32_t max_mbuf) - { - struct rte_gro_param gro_param = { -@@ -82,6 +134,7 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt - }; - - uint32_t pkt_num = rte_eth_rx_burst(stack->port_id, stack->queue_id, pkts, max_mbuf); -+ vdev_pkts_parse(pkts, pkt_num); - if (pkt_num <= 1) { - return pkt_num; - } -@@ -92,37 +145,6 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt - return pkt_num; - } - -- for (uint32_t i = 0; i < pkt_num; i++) { -- struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(pkts[i], struct rte_ether_hdr *); -- u16_t type = ethh->ether_type; -- -- pkts[i]->l2_len = sizeof(struct rte_ether_hdr); -- -- if (type == RTE_BE16(RTE_ETHER_TYPE_IPV4)) { -- struct rte_ipv4_hdr *iph = rte_pktmbuf_mtod_offset(pkts[i], struct rte_ipv4_hdr *, -- sizeof(struct rte_ether_hdr)); -- if (unlikely((iph->version_ihl & IPV4_MASK) != IPV4_VERION)) { -- continue; -- } -- pkts[i]->l3_len = sizeof(struct rte_ipv4_hdr); -- -- struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(pkts[i], struct rte_tcp_hdr *, -- sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr)); -- pkts[i]->l4_len = TCP_HDR_LEN(tcp_hdr); -- -- pkts[i]->packet_type = RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP; -- } else if (type == RTE_BE16(RTE_ETHER_TYPE_IPV6)) { -- pkts[i]->l3_len = sizeof(struct rte_ipv6_hdr); -- -- struct rte_tcp_hdr *tcp_hdr = rte_pktmbuf_mtod_offset(pkts[i], struct rte_tcp_hdr *, -- sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv6_hdr)); -- pkts[i]->l4_len = TCP_HDR_LEN(tcp_hdr); -- -- pkts[i]->packet_type = RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP; -- } else { -- continue; -- } -- } - pkt_num = rte_gro_reassemble_burst(pkts, pkt_num, &gro_param); - - return pkt_num; --- -2.33.0 - diff --git a/0205-virtio-distribute-pkg-by-dst_port.patch b/0205-virtio-distribute-pkg-by-dst_port.patch deleted file mode 100644 index 77e8204d3085b3d6a1849407db67e19362994682..0000000000000000000000000000000000000000 --- a/0205-virtio-distribute-pkg-by-dst_port.patch +++ /dev/null @@ -1,198 +0,0 @@ -From a86ef865f47b99b41e426e621cb3b5e3416a70ff Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Thu, 27 Jun 2024 19:53:07 +0800 -Subject: [PATCH] [virtio]: distribute pkg by dst_port - ---- - src/lstack/core/lstack_protocol_stack.c | 27 ++++++++++++++---- - src/lstack/core/lstack_virtio.c | 9 ++++++ - src/lstack/include/lstack_virtio.h | 2 ++ - src/lstack/netif/lstack_ethdev.c | 37 +++++++++++++++++++++++-- - src/lstack/netif/lstack_vdev.c | 2 ++ - 5 files changed, 68 insertions(+), 9 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index d6e3c86..e272a04 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -34,6 +34,7 @@ - #include "lstack_control_plane.h" - #include "posix/lstack_epoll.h" - #include "lstack_stack_stat.h" -+#include "lstack_virtio.h" - #include "lstack_protocol_stack.h" - - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) -@@ -509,6 +510,9 @@ int stack_polling(uint32_t wakeup_tick) - } - } - #endif -+ if (get_global_cfg_params()->flow_bifurcation) { -+ virtio_tap_process_rx(stack->port_id, stack->queue_id); -+ } - return force_quit; - } - -@@ -979,14 +983,25 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - } - } - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) -- ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -- if (ret != 0) { -- cur_stack->stats.rx_allocmbuf_fail++; -- return; -+ if (get_global_cfg_params()->kni_switch) { -+ ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -+ if (ret != 0) { -+ cur_stack->stats.rx_allocmbuf_fail++; -+ return; -+ } -+ copy_mbuf(mbuf_copy, mbuf); -+ kni_handle_tx(mbuf_copy); - } -- copy_mbuf(mbuf_copy, mbuf); -- kni_handle_tx(mbuf_copy); - #endif -+ if (get_global_cfg_params()->flow_bifurcation) { -+ ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -+ if (ret != 0) { -+ cur_stack->stats.rx_allocmbuf_fail++; -+ return; -+ } -+ copy_mbuf(mbuf_copy, mbuf); -+ virtio_tap_process_tx(stack->queue_id, mbuf_copy); -+ } - return; - } - -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index c3b3511..ad3088d 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -331,3 +331,12 @@ int virtio_port_create(int lstack_net_port) - } - return 0; - } -+ -+bool virtio_distribute_pkg_to_kernel(uint16_t dst_port) -+{ -+ if (dst_port == VIRTIO_PORT_INVALID) { -+ return false; -+ } -+ -+ return (port_map_get(dst_port) == 0); -+} -\ No newline at end of file -diff --git a/src/lstack/include/lstack_virtio.h b/src/lstack/include/lstack_virtio.h -index d40c754..615d9c9 100644 ---- a/src/lstack/include/lstack_virtio.h -+++ b/src/lstack/include/lstack_virtio.h -@@ -14,6 +14,7 @@ - - #include - -+#define VIRTIO_PORT_INVALID 0xffff - #define VIRTIO_MAX_QUEUE_NUM 8 - - // RTE_ETHER_ADDR_PRT_FMT RTE_ETHER_ADDR_BYTES are defined in dpdk 21.11 -@@ -48,4 +49,5 @@ void virtio_tap_process_tx(uint16_t queue_id, struct rte_mbuf *mbuf_copy); - int virtio_port_create(int lstack_net_port); - - struct virtio_instance* virtio_instance_get(void); -+bool virtio_distribute_pkg_to_kernel(uint16_t dst_port); - #endif -\ No newline at end of file -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 3bfa8af..933c3e8 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -35,6 +35,7 @@ - #include "lstack_thread_rpc.h" - #include "lstack_flow.h" - #include "lstack_tx_cache.h" -+#include "lstack_virtio.h" - #include "lstack_ethdev.h" - - /* FRAME_MTU + 14byte header */ -@@ -149,6 +150,25 @@ void kni_handle_tx(struct rte_mbuf *mbuf) - ((ptype & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) && \ - (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0)) - -+#define IS_ICMPV6_PKT(ptype) (RTE_ETH_IS_IPV6_HDR(ptype) && \ -+ ((ptype & RTE_PTYPE_L4_ICMP) == RTE_PTYPE_L4_ICMP) && \ -+ (RTE_ETH_IS_TUNNEL_PKT(ptype) == 0)) -+ -+static uint16_t eth_dev_get_dst_port(struct rte_mbuf *pkt) -+{ -+ uint16_t dst_port = VIRTIO_PORT_INVALID; -+ uint32_t packet_type = pkt->packet_type; -+ -+ void *l4_hdr = rte_pktmbuf_mtod_offset(pkt, void *, pkt->l2_len + pkt->l3_len); -+ -+ if (IS_IPV4_TCP_PKT(packet_type) || IS_IPV6_TCP_PKT(packet_type)) { -+ dst_port = rte_be_to_cpu_16(((struct rte_tcp_hdr *)l4_hdr)->dst_port); -+ } else if (IS_IPV4_UDP_PKT(packet_type) || IS_IPV6_UDP_PKT(packet_type)) { -+ dst_port = rte_be_to_cpu_16(((struct rte_udp_hdr *)l4_hdr)->dst_port); -+ } -+ return dst_port; -+} -+ - int32_t eth_dev_poll(void) - { - uint32_t nr_pkts; -@@ -170,7 +190,8 @@ int32_t eth_dev_poll(void) - int transfer_type = TRANSFER_CURRENT_THREAD; - /* copy arp into other stack */ - if (!use_ltran()) { -- if (unlikely(IS_ARP_PKT(stack->pkts[i]->packet_type))) { -+ if (unlikely(IS_ARP_PKT(stack->pkts[i]->packet_type)) || -+ unlikely(IS_ICMPV6_PKT(stack->pkts[i]->packet_type))) { - stack_broadcast_arp(stack->pkts[i], stack); - /* copy arp into other process */ - transfer_arp_to_other_process(stack->pkts[i]); -@@ -178,17 +199,27 @@ int32_t eth_dev_poll(void) - if (get_global_cfg_params()->tuple_filter && stack->queue_id == 0) { - transfer_type = distribute_pakages(stack->pkts[i]); - } -+ if (get_global_cfg_params()->flow_bifurcation) { -+ uint16_t dst_port = eth_dev_get_dst_port(stack->pkts[i]); -+ if (virtio_distribute_pkg_to_kernel(dst_port)) { -+ transfer_type = TRANSFER_KERNEL; -+ } -+ } - } - } - - if (likely(transfer_type == TRANSFER_CURRENT_THREAD)) { - eth_dev_recv(stack->pkts[i], stack); - } else if (transfer_type == TRANSFER_KERNEL) { -+ if (get_global_cfg_params()->flow_bifurcation) { -+ virtio_tap_process_tx(stack->queue_id, stack->pkts[i]); -+ } else { - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) -- kni_handle_tx(stack->pkts[i]); -+ kni_handle_tx(stack->pkts[i]); - #else -- rte_pktmbuf_free(stack->pkts[i]); -+ rte_pktmbuf_free(stack->pkts[i]); - #endif -+ } - } else { - /* transfer to other thread */ - } -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 5ce69a9..cb3953e 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -115,6 +115,8 @@ static inline void vdev_pkts_parse(struct rte_mbuf **pkts, int pkt_num) - } else if (iph6->proto == IPPROTO_UDP) { - pkts[i]->l4_len = sizeof(struct rte_udp_hdr); - pkts[i]->packet_type = RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP; -+ } else if (iph6->proto == IPPROTO_ICMPV6) { -+ pkts[i]->packet_type = RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_ICMP; - } - } else if (type == RTE_BE16(RTE_ETHER_TYPE_ARP)) { - pkts[i]->packet_type = RTE_PTYPE_L2_ETHER_ARP; --- -2.33.0 - diff --git a/0206-fix-coredump-when-get-empty-from-udp-sendring.patch b/0206-fix-coredump-when-get-empty-from-udp-sendring.patch deleted file mode 100644 index c4bb923c342c83084c53474264e2b572c76c422a..0000000000000000000000000000000000000000 --- a/0206-fix-coredump-when-get-empty-from-udp-sendring.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 8cd5427107511b6daed9905590c2812346a3a57d Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Thu, 27 Jun 2024 19:52:02 +0800 -Subject: [PATCH] fix coredump when get empty from udp sendring - ---- - src/lstack/core/lstack_lwip.c | 13 ++++++------- - 1 file changed, 6 insertions(+), 7 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index db948b0..3728100 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -255,17 +255,16 @@ struct pbuf *do_lwip_udp_get_from_sendring(struct lwip_sock *sock, uint16_t rema - struct pbuf *pbufs[count]; - - int actual_count = gazelle_ring_sc_dequeue(sock->send_ring, (void **)&pbufs, count); -- if (unlikely(actual_count != count)) { -+ /* it's impossible to enter this branch theoretically */ -+ if (unlikely((actual_count != count) || -+ ((actual_count != 0) && pbufs[0]->tot_len != remain_size))) { - LSTACK_LOG(ERR, LSTACK, "udp get pbuf from sendring error, expected: %d, actual: %d\n", - count, actual_count); -+ LSTACK_LOG(ERR, LSTACK, "udp get pbuf size error, expected: %d, actual: %d\n", -+ remain_size, actual_count == 0 ? 0 : pbufs[0]->tot_len); - } - -- if (unlikely(pbufs[0]->tot_len != remain_size)) { -- LSTACK_LOG(ERR, LSTACK, "udp get pbuf size error, expected: %d, actual: %d\n", -- remain_size, pbufs[0]->tot_len); -- } -- -- for (int i = 0; get_protocol_stack_group()->latency_start && i < count; i++) { -+ for (int i = 0; get_protocol_stack_group()->latency_start && i < actual_count; i++) { - calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_WRITE_LWIP, 0); - } - --- -2.33.0 - diff --git a/0207-fix-poll-init-not-clear-old-fd.patch b/0207-fix-poll-init-not-clear-old-fd.patch deleted file mode 100644 index f2b4d3f8ed6013c5eadda232ed3e90ad3a8ae3a3..0000000000000000000000000000000000000000 --- a/0207-fix-poll-init-not-clear-old-fd.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 5dbdb572406e168205cb9e54b2c247e97a57c22c Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Sat, 29 Jun 2024 07:17:27 +0000 -Subject: [PATCH] fix poll init not clear old fd - ---- - src/lstack/api/lstack_epoll.c | 7 ++++--- - 1 file changed, 4 insertions(+), 3 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 2791dd7..2ac7150 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -837,14 +837,15 @@ static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfd - continue; - } - } -- wakeup->last_fds[i].fd = fd; -- wakeup->last_fds[i].events = fds[i].events; -- poll_change = 1; - - if (sock == NULL || sock->conn == NULL || CONN_TYPE_HAS_HOST(sock->conn)) { - update_kernel_poll(wakeup, i, fds + i); - } - -+ wakeup->last_fds[i].fd = fd; -+ wakeup->last_fds[i].events = fds[i].events; -+ poll_change = 1; -+ - while (sock && sock->conn) { - sock->epoll_events = fds[i].events | POLLERR; - sock->wakeup = wakeup; --- -2.33.0 - diff --git a/0208-virtio-mode-actual_queue_num.patch b/0208-virtio-mode-actual_queue_num.patch deleted file mode 100644 index fd53200c9d12c19c7137e928eec2ef4d51a44e21..0000000000000000000000000000000000000000 --- a/0208-virtio-mode-actual_queue_num.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 0613a7275ed2ed0aefc2f8419adeaadd8fd87de9 Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Sat, 29 Jun 2024 17:35:37 +0800 -Subject: [PATCH] virtio: mode actual_queue_num - ---- - src/lstack/core/lstack_virtio.c | 4 +++- - 1 file changed, 3 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index ad3088d..bc42bb9 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -298,9 +298,11 @@ int virtio_port_create(int lstack_net_port) - return retval; - } - -+ uint16_t actual_queue_num = (g_virtio_instance.rx_queue_num < g_virtio_instance.tx_queue_num) ? -+ g_virtio_instance.rx_queue_num : g_virtio_instance.tx_queue_num; - retval = snprintf(portargs, sizeof(portargs), - "path=/dev/vhost-net,queues=%u,queue_size=%u,iface=%s,mac=" RTE_ETHER_ADDR_PRT_FMT, -- VIRTIO_MAX_QUEUE_NUM, VIRTIO_TX_RX_RING_SIZE, VIRTIO_USER_NAME, RTE_ETHER_ADDR_BYTES(&addr)); -+ actual_queue_num, VIRTIO_TX_RX_RING_SIZE, VIRTIO_USER_NAME, RTE_ETHER_ADDR_BYTES(&addr)); - if (retval < 0) { - LSTACK_LOG(ERR, LSTACK, "virtio portargs snprintf failed ret=%d \n", retval); - return retval; --- -2.33.0 - diff --git a/0209-virtio-update-g_rule_port-by-reg_ring_type-enum.patch b/0209-virtio-update-g_rule_port-by-reg_ring_type-enum.patch deleted file mode 100644 index 9833f1eb4aeebe49e7d5344ad9e1ba318d0505f2..0000000000000000000000000000000000000000 --- a/0209-virtio-update-g_rule_port-by-reg_ring_type-enum.patch +++ /dev/null @@ -1,109 +0,0 @@ -From cb0c86801bc4c221ae79a284619879dc98a5464d Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Sat, 29 Jun 2024 14:46:32 +0800 -Subject: [PATCH] virtio: update g_rule_port by reg_ring_type enum - ---- - src/lstack/core/lstack_port_map.c | 25 ++++++++++++------------- - src/lstack/include/lstack_port_map.h | 4 ++-- - src/lstack/netif/lstack_vdev.c | 15 +++++++++++++++ - 3 files changed, 29 insertions(+), 15 deletions(-) - -diff --git a/src/lstack/core/lstack_port_map.c b/src/lstack/core/lstack_port_map.c -index e5008b3..5439394 100644 ---- a/src/lstack/core/lstack_port_map.c -+++ b/src/lstack/core/lstack_port_map.c -@@ -15,29 +15,28 @@ - #include "lstack_port_map.h" - - #define PORT_MAP_UNIX_TCP_PORT_MAX 65535 --#define PORT_MAP_EIGHT_BIT 8 - --static uint8_t g_rule_port[(PORT_MAP_UNIX_TCP_PORT_MAX + 1) / PORT_MAP_EIGHT_BIT]; // 8k byte -+static uint32_t g_rule_port[PORT_MAP_UNIX_TCP_PORT_MAX] = {0}; - static pthread_mutex_t g_rule_map_mutex = PTHREAD_MUTEX_INITIALIZER; - --void port_map_set(uint32_t modBit, int setVal) -+void port_map_mod(uint16_t port, uint16_t flag) - { - pthread_mutex_lock(&g_rule_map_mutex); -- g_rule_port[modBit / PORT_MAP_EIGHT_BIT] &= ~(1 << (modBit % PORT_MAP_EIGHT_BIT)); -- g_rule_port[modBit / PORT_MAP_EIGHT_BIT] |= (setVal << (modBit % PORT_MAP_EIGHT_BIT)); -+ if (flag == 0) { -+ g_rule_port[port]--; -+ } else { -+ g_rule_port[port]++; -+ } - pthread_mutex_unlock(&g_rule_map_mutex); - } - --int port_map_get(int bit_index) -+uint16_t port_map_get(uint16_t port) - { -- int bit_val = 0; -- int byte_index = bit_index / PORT_MAP_EIGHT_BIT; -- int bit_offset = bit_index % PORT_MAP_EIGHT_BIT; -- uint8_t mask = 1 << bit_offset; -+ uint16_t val = 0; - pthread_mutex_lock(&g_rule_map_mutex); -- if ((g_rule_port[byte_index] & mask) != 0) { -- bit_val = 1; -+ if (g_rule_port[port] > 0) { -+ val = 1; - } - pthread_mutex_unlock(&g_rule_map_mutex); -- return bit_val; -+ return val; - } -\ No newline at end of file -diff --git a/src/lstack/include/lstack_port_map.h b/src/lstack/include/lstack_port_map.h -index 24ef53a..80955dc 100644 ---- a/src/lstack/include/lstack_port_map.h -+++ b/src/lstack/include/lstack_port_map.h -@@ -14,7 +14,7 @@ - - #include - --void port_map_set(uint32_t modBit, int setVal); --int port_map_get(int bit_index); -+void port_map_mod(uint16_t port, uint16_t flag); -+uint16_t port_map_get(uint16_t port); - - #endif -\ No newline at end of file -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index cb3953e..75e4acc 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -35,6 +35,8 @@ - #include "lstack_lwip.h" - #include "lstack_flow.h" - #include "lstack_vdev.h" -+#include "lstack_port_map.h" -+#include "lstack_virtio.h" - - /* INUSE_TX_PKTS_WATERMARK < VDEV_RX_QUEUE_SZ; - * USE_RX_PKTS_WATERMARK < FREE_RX_QUEUE_SZ. -@@ -197,6 +199,19 @@ int32_t vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple) - return -1; - } - -+ uint16_t local_port = ntohs(qtuple->src_port); -+ if (get_global_cfg_params()->flow_bifurcation && get_global_cfg_params()->is_primary) { -+ if (type == REG_RING_TCP_LISTEN_CLOSE || type == REG_RING_UDP_BIND_CLOSE) { // add enum type in reg_sock.h -+ port_map_mod(local_port, 0); -+ } else if (type == REG_RING_TCP_LISTEN || type == REG_RING_UDP_BIND) { -+ port_map_mod(local_port, 1); -+ } else if (type == REG_RING_TCP_CONNECT_CLOSE) { -+ port_map_mod(local_port, 0); -+ } else if (type == REG_RING_TCP_CONNECT) { -+ port_map_mod(local_port, 1); -+ } -+ } -+ - if (!use_ltran() && get_global_cfg_params()->tuple_filter) { - if (type == REG_RING_TCP_LISTEN_CLOSE) { - if (get_global_cfg_params()->is_primary) { --- -2.33.0 - diff --git a/0210-virtio-dfx-data-of-virtio.patch b/0210-virtio-dfx-data-of-virtio.patch deleted file mode 100644 index 2769715f9d3dbe27b59da4c89110652c32d9802b..0000000000000000000000000000000000000000 --- a/0210-virtio-dfx-data-of-virtio.patch +++ /dev/null @@ -1,157 +0,0 @@ -From 0c6cf045fb0eea38cc7e53ee1984459ae90792bf Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Sat, 29 Jun 2024 15:16:54 +0800 -Subject: [PATCH] virtio: dfx data of virtio - ---- - src/common/gazelle_dfx_msg.h | 16 ++++++++++++++++ - src/lstack/core/lstack_stack_stat.c | 8 ++++++++ - src/lstack/include/lstack_virtio.h | 2 +- - src/ltran/ltran_dfx.c | 23 +++++++++++++++++++++++ - 4 files changed, 48 insertions(+), 1 deletion(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 696daf2..57bf631 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -53,6 +53,7 @@ enum GAZELLE_STAT_MODE { - GAZELLE_STAT_LSTACK_LOG_LEVEL_SET, - GAZELLE_STAT_LSTACK_SHOW_RATE, - GAZELLE_STAT_LSTACK_SHOW_SNMP, -+ GAZELLE_STAT_LSTACK_SHOW_VIRTIO, - GAZELLE_STAT_LSTACK_SHOW_CONN, - GAZELLE_STAT_LSTACK_SHOW_LATENCY, - GAZELLE_STAT_LSTACK_LOW_POWER_MDF, -@@ -137,6 +138,20 @@ struct gazelle_stat_pkts { - struct gazelle_stack_aggregate_stats aggregate_stats; - }; - -+// same with lstack_virtio.h struct virtio_instance -+struct gazelle_stat_lstack_virtio { -+#define VIRTIO_MAX_QUEUE_NUM 8 -+ uint16_t lstack_port_id; -+ uint16_t virtio_port_id; -+ uint16_t rx_queue_num; -+ uint16_t tx_queue_num; -+ -+ uint64_t rx_pkg[VIRTIO_MAX_QUEUE_NUM]; -+ uint64_t rx_drop[VIRTIO_MAX_QUEUE_NUM]; -+ uint64_t tx_pkg[VIRTIO_MAX_QUEUE_NUM]; -+ uint64_t tx_drop[VIRTIO_MAX_QUEUE_NUM]; -+}; -+ - /* same as define in lwip/stats.h - struct stats_mib2 */ - struct gazelle_stat_lstack_snmp { - /* IP */ -@@ -328,6 +343,7 @@ struct gazelle_stack_dfx_data { - struct gazelle_stack_latency latency; - struct gazelle_stat_lstack_conn conn; - struct gazelle_stat_lstack_snmp snmp; -+ struct gazelle_stat_lstack_virtio virtio; - struct nic_eth_xstats nic_xstats; - struct nic_eth_features nic_features; - struct gazelle_stat_lstack_proto proto_data; -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 0f1f693..1e32c45 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -29,6 +29,7 @@ - #include "posix/lstack_epoll.h" - #include "lstack_dpdk.h" - #include "lstack_stack_stat.h" -+#include "lstack_virtio.h" - - #define US_PER_SEC 1000000 - -@@ -343,6 +344,13 @@ static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protoc - LSTACK_LOG(ERR, LSTACK, "memcpy_s err ret=%d \n", ret); - } - break; -+ case GAZELLE_STAT_LSTACK_SHOW_VIRTIO: -+ ret = memcpy_s(&dfx->data.virtio, sizeof(dfx->data.virtio), virtio_instance_get(), -+ sizeof(*(virtio_instance_get()))); -+ if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "memcpy_s err ret=%d \n", ret); -+ } -+ break; - case GAZELLE_STAT_LSTACK_SHOW_CONN: - rpc_call_result = rpc_call_conntable(&stack->dfx_rpc_queue, dfx->data.conn.conn_list, - GAZELLE_LSTACK_MAX_CONN); -diff --git a/src/lstack/include/lstack_virtio.h b/src/lstack/include/lstack_virtio.h -index 615d9c9..5298dbe 100644 ---- a/src/lstack/include/lstack_virtio.h -+++ b/src/lstack/include/lstack_virtio.h -@@ -30,7 +30,7 @@ - ((mac_addrs)->addr_bytes[4]), \ - ((mac_addrs)->addr_bytes[5]) - #endif -- -+// When modifying virtio_instance, gazelle_stat_lstack_virtio also needs to be modified together. - struct virtio_instance { - uint16_t lstack_port_id; - uint16_t virtio_port_id; -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 4351891..cdcd7b3 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -128,6 +128,7 @@ static void gazelle_print_ltran_start_latency(void *buf, const struct gazelle_st - static void gazelle_print_lstack_stat_total(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_stat_rate(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_stat_snmp(void *buf, const struct gazelle_stat_msg_request *req_msg); -+static void gazelle_print_lstack_stat_virtio(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_stat_latency(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_stat_lpm(void *buf, const struct gazelle_stat_msg_request *req_msg); -@@ -163,6 +164,7 @@ static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = { - {GAZELLE_STAT_LSTACK_LOG_LEVEL_SET, 0, gazelle_print_ltran_wait}, - {GAZELLE_STAT_LSTACK_SHOW_RATE, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_rate}, - {GAZELLE_STAT_LSTACK_SHOW_SNMP, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_snmp}, -+ {GAZELLE_STAT_LSTACK_SHOW_VIRTIO, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_virtio}, - {GAZELLE_STAT_LSTACK_SHOW_CONN, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_conn}, - {GAZELLE_STAT_LSTACK_SHOW_LATENCY, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_latency}, - {GAZELLE_STAT_LSTACK_LOW_POWER_MDF, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_lpm}, -@@ -1169,6 +1171,24 @@ static void gazelle_print_lstack_stat_proto(void *buf, const struct gazelle_stat - } while (true); - } - -+static void gazelle_print_lstack_stat_virtio(void *buf, const struct gazelle_stat_msg_request *req_msg) -+{ -+ struct gazelle_stack_dfx_data *stat = (struct gazelle_stack_dfx_data *)buf; -+ struct gazelle_stat_lstack_virtio *virtio = &stat->data.virtio; -+ printf("\nStatistics of lstack virtio:\n"); -+ -+ printf("\nlstack_port_id =%u virtio_port_id =%u rx_queue_num =%u tx_queue_num =%u \n", -+ virtio->lstack_port_id, virtio->virtio_port_id, virtio->rx_queue_num, -+ virtio->tx_queue_num); -+ -+ printf("\n%-8s %-8s %-8s %-8s %-8s\n", "queue_id", "rx_pkg", "rx_drop", "tx_pkg", "tx_drop"); -+ for (int i = 0; i < virtio->rx_queue_num; i++) { -+ printf("%-8d %-8lu %-8lu %-8lu %-8lu\n", i, -+ virtio->rx_pkg[i], virtio->rx_drop[i], virtio->tx_pkg[i], virtio->tx_drop[i]); -+ } -+ printf("\n"); -+} -+ - static void gazelle_keepalive_string(char* str, int buff_len, struct gazelle_stat_lstack_conn_info *conn_info) - { - if (conn_info->keepalive == 0) { -@@ -1298,6 +1318,7 @@ static void show_usage(void) - " show lstack all statistics \n" - " -r, rate show lstack statistics per second \n" - " -s, snmp show lstack snmp \n" -+ " -v, virtio show rx_pkg/rx_drop/tx_pkg/tx_drop num of virtio \n" - " -c, connect show lstack connect \n" - " -l, latency [time] show lstack latency \n" - " -x, xstats show lstack xstats \n" -@@ -1553,6 +1574,8 @@ static int32_t parse_dfx_lstack_show_args(int32_t argc, char *argv[], struct gaz - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_MODE_MAX; - } else if (strcmp(param, "snmp") == 0 || strcmp(param, "-s") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_SNMP; -+ } else if (strcmp(param, "virtio") == 0 || strcmp(param, "-v") == 0) { -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_VIRTIO; - } else if (strcmp(param, "connect") == 0 || strcmp(param, "-c") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_CONN; - } else if (strcmp(param, "xstats") == 0 || strcmp(param, "-x") == 0) { --- -2.33.0 - diff --git a/0211-add-flow_bifurcation-switch-in-lstack_cfg-file.patch b/0211-add-flow_bifurcation-switch-in-lstack_cfg-file.patch deleted file mode 100644 index ecd20311785d31f806b28fc71f55601f8ca0f989..0000000000000000000000000000000000000000 --- a/0211-add-flow_bifurcation-switch-in-lstack_cfg-file.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 4af8c587a4f5b861012cb2d1ca954af8e6872162 Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Tue, 2 Jul 2024 15:26:48 +0800 -Subject: [PATCH] add flow_bifurcation switch in lstack_cfg file - ---- - src/lstack/lstack.conf | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index c65a25d..490bdfc 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -15,6 +15,7 @@ stack_thread_mode="run-to-wakeup" - #ltran mode need add "--map-perfect" and "--legacy-mem" in dpdk_args - use_ltran=0 - kni_switch=0 -+flow_bifurcation=0 - - low_power_mode=0 - --- -2.33.0 - diff --git a/0212-example-sync-example-update.patch b/0212-example-sync-example-update.patch deleted file mode 100644 index 28e40283d98855f6f2c74ee8604497d4ba2d0905..0000000000000000000000000000000000000000 --- a/0212-example-sync-example-update.patch +++ /dev/null @@ -1,3751 +0,0 @@ -From f599cc99be29c47a7765e3fae602f3474b30926a Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Thu, 11 Jul 2024 10:30:31 +0800 -Subject: [PATCH] example: sync example update - ---- - build/build.sh | 8 + - examples/FAULT_INJECT.md | 33 ++ - examples/README.md | 79 +++- - examples/inc/bussiness.h | 16 +- - examples/inc/client.h | 44 +- - examples/inc/parameter.h | 80 +++- - examples/inc/server.h | 25 +- - examples/inc/utilities.h | 88 +++- - examples/main.c | 7 +- - examples/src/bussiness.c | 212 ++++++--- - examples/src/client.c | 562 ++++++++++++++++++------ - examples/src/parameter.c | 484 +++++++++++++++++--- - examples/src/server.c | 512 ++++++++++++++++----- - examples/src/utilities.c | 386 +++++++++++----- - src/lstack/core/lstack_protocol_stack.c | 2 +- - 15 files changed, 2006 insertions(+), 532 deletions(-) - create mode 100644 examples/FAULT_INJECT.md - -diff --git a/build/build.sh b/build/build.sh -index 4464f8c..622e1cc 100755 ---- a/build/build.sh -+++ b/build/build.sh -@@ -31,3 +31,11 @@ if [ $? -ne 0 ]; then - fi - - cd - -+cd ../examples -+cmake . -+make -+if [ $? -ne 0 ]; then -+ echo "build examples failed" -+ exit 1 -+fi -+cd - -diff --git a/examples/FAULT_INJECT.md b/examples/FAULT_INJECT.md -new file mode 100644 -index 0000000..ff551a9 ---- /dev/null -+++ b/examples/FAULT_INJECT.md -@@ -0,0 +1,33 @@ -+# Gazelle 故障注入 说明 -+ -+## 需求 -+1. example:构造黑盒故障 -+ * 延迟类:accept|read: -+ * accept: 构造tcp_acceptmbox_full的情景. -+ * read: 构造tcp_refuse_count、recvmbox满 -+ * 跳过类:跳过 read/write并close: -+ * read: 构造链接关闭时时4次挥手的情景,验证TCP状态机。 -+2. gazelle/lwip: 构造白盒故障,支持注入故障报文、协议栈状态、事件设置、资源异常等 -+ * 编译宏支持 -+ * 提供接口:配置文件、env -+ * 故障报文注入: -+ * 类似内核tc工具: -+ * 内核TC工具qdisc指令原理:报文分组被添加到网卡队列(qdisc),该队列决定发包顺序。
-+ qdisc指令可以在队列层面实现延时、丢包、重复等故障。 -+ * dpdk性能检测工具testpmd可以模拟实现类似的故障模拟,testpmd与gazelle不兼容,需要参考其中调用的dpdk接口来改gazelle代码。
-+ * 延时故障 -+ * 丢包故障 -+ - 思路:调整网卡队列,随机丢弃百分比的包,然后发送。 -+ - 函数调用:rte_rand(),rte_eth_tx_burst()。 -+ * 包重复故障 -+ * 随机故障 -+ * 乱序故障 -+ * 协议栈状态故障 -+ * ... -+ * 事件设置 -+ * ... -+ * 资源异常 -+ * 资源耗尽,无法申请。 -+ * ... -+ -+ -diff --git a/examples/README.md b/examples/README.md -index 5a73ce0..77a0f85 100644 ---- a/examples/README.md -+++ b/examples/README.md -@@ -7,6 +7,7 @@ - * 支持多线程网络非对称模型,一个 listen 线程,若干个读写线程。listen 线程和读写线程使用 `poll` / `epoll` 监听事件。 - * 支持 `recvmsg` 、`sendmsg` 、`recv` 、`send` 、`recvfrom`、`sendto`、`getpeername` 、`getsockopt` 、`epoll_ctl` 等 posix 接口。 - * 网络通讯报文采用问答方式,丢包或者内容错误则报错并停止通讯。报文内容有变化,长度可配。 -+* 支持网络故障注入,延迟进行(delay)、跳过(skip)read、write、accept等逻辑。 - - ## 网络模型 - -@@ -103,15 +104,15 @@ - * `-a, --as [server | client]`:作为服务端还是客户端。 - * `server`:作为服务端。 - * `client`:作为客户端。 --* `-i, --ip [xxx.xxx.xxx.xxx]`:IP地址。 --* `-g, --groupip [xxx.xxx.xxx.xxx]`:UDP组播地址。 -+* `-i, --ip [xxx.xxx.xxx.xxx]`:server端IP地址。当v4与v6地址同时存在时,以","分隔。例如:`-i 192.168.1.88,aa22:bb11:1122:cdef:1234:aa99:7654:7410` -+* `-g, --groupip [xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx]`:配置UDP组播地址与interface地址,以','分隔,其中interface地址为可选项。例如:`-g 224.0.0.24,192.168.1.202`或`-g 224.0.0.24` - * `-p, --port [xxxx]`:端口。 - * `-m, --model [mum | mud]`:采用的网络模型类型。 - * `mum (multi thread, unblock, multiplexing IO)`:多线程非阻塞IO复用。 - * `mud (multi thread, unblock, dissymmetric)`:多线程非阻塞非对称。 - * `-t, --threadnum`:线程数设置。 - * `-c, --connectnum`:连接数设置。当 `domain` 设置为 `udp` 时,`connectnum` 会被设置为1。 --* `-D, --domain [unix | tcp | udp]`:通信协议。 -+* `-D, --domain [unix | tcp | udp]`:通信协议。当支持多个通信协议时以","分隔。例如:`-D tcp,udp` - * `unix`:基于 unix 协议实现。 - * `tcp`:基于 tcp 协议实现。 - * `udp`:基于 udp 协议实现。 -@@ -132,6 +133,19 @@ - * `-C, --accept`:accept的方式。 - * `ac`:使用accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)通过套接口接受连接。 - * `ac4`:使用accept4(int sockfd, struct sockaddr *addr,socklen_t *addrlen, int flags)通过套接口接受连接,flags=SOCK_CLOEXEC。 -+* `-k, --keep_alive`:配置TCP keep_alive idle , keep_alive interval时间(second)。 -+* `-I, --inject`: 配置故障注入类型。 -+ * `delay`: -+ * `"delay 20 before_accept"`: 延迟20秒进行accept,时间可自定义,需大于0。可用于构造tcp_acceptmbox_full的情景 -+ * `"delay 20 before_read"`: 延迟20秒进行read,时间可自定义,需大于0。 -+ * `"delay 20 before_write"`: 延迟20秒进行write,时间可自定义,需大于0。 -+ * `"delay 20 before_read_and_write"`: 延迟20秒进行read和write,时间可自定义,需大于0。 -+ * `skip`: -+ * `"skip write"`: 跳过写过程,并关闭链接。 -+ * `"skip read"`: 跳过读过程,并关闭链接。 -+ * `"skip read_and_write"`: 跳过读写写过程,并关闭链接。 -+ -+ - ## 使用 - - * **环境配置** -@@ -235,12 +249,12 @@ make - * 创建udp组播服务端 - - ``` --./example -A server -D udp -i 192.168.0.1 -g 225.0.0.1 -A recvfromsendto -+./example -A server -D udp -g 225.0.0.1,192.168.0.1 -A recvfromsendto - - [program parameters]: - --> [as]: server ----> [server ip]: 192.168.0.1 - --> [server group ip]: 225.0.0.1 -+--> [server groupip_interface]: 192.168.0.1 - --> [server port]: 5050 - --> [model]: mum - --> [thread number]: 1 -@@ -260,12 +274,12 @@ make - * 创建udp组播客户端 - - ``` --./example -A client -D udp -i 192.168.0.1 -g 225.0.0.1 -A recvfromsendto -+./example -A client -D udp -g 225.0.0.1,192.168.0.1 -A recvfromsendto - - [program parameters]: ----> [as]: server ----> [server ip]: 225.0.0.1 ----> [client send ip]: 192.168.0.1 -+--> [as]: client -+--> [client group ip]: 225.0.0.1 -+--> [client groupip_interface]: 192.168.0.1 - --> [server port]: 5050 - --> [thread number]: 1 - --> [connection number]: 1 -@@ -280,3 +294,50 @@ make - [program informations]: - --> : [connect num]: 0, [send]: 0.000 B/s - ``` -+ -+* 混杂模式下server 与 client 配置 -+``` -+./example -a server -D tcp,udp -i 192.168.1.88 -p 33333 -g 224.0.0.24,192.168.1.188 -+[program parameters]: -+--> [as]: server -+--> [server group ip]: 224.0.0.24 -+--> [server groupip_interface]: 192.168.1.188 -+--> [server ip]: 192.168.1.888 -+--> [server port]: 33333 -+--> [model]: mum -+--> [thread number]: 1 -+--> [domain]: tcp,udp -+--> [api]: read & write -+--> [packet length]: 1024 -+--> [verify]: off -+--> [ringpmd]: off -+--> [debug]: off -+--> [epoll create]: ec -+--> [accept]: ac -+--> [inject]: none -+ -+[program informations]: -+``` -+``` -+./example -a client -D tcp,udp -i 192.168.1.188 -p 33333 -g 192.168.1.202,224.0.0.24 -+[program parameters]: -+--> [as]: client -+--> [client group ip]: 224.0.0.24 -+--> [client groupip_interface]: 192.168.1.202 -+--> [server ip]: 192.168.1.188 -+--> [server port]: 33333 -+--> [thread number]: 1 -+--> [connection number]: 1 -+--> [domain]: tcp,udp -+--> [api]: read & write -+--> [packet length]: 1024 -+--> [verify]: off -+--> [ringpmd]: off -+--> [debug]: off -+--> [epoll create]: ec -+--> [accept]: ac -+--> [inject]: none -+ -+[program informations]: -+ -+``` -\ No newline at end of file -diff --git a/examples/inc/bussiness.h b/examples/inc/bussiness.h -index 83645ef..3a78b1f 100644 ---- a/examples/inc/bussiness.h -+++ b/examples/inc/bussiness.h -@@ -28,7 +28,9 @@ - */ - struct ServerHandler - { -+ int32_t listen_fd_array[PROTOCOL_MODE_MAX]; - int32_t fd; ///< socket file descriptor -+ int32_t is_v6; - }; - - /** -@@ -39,6 +41,7 @@ struct ClientHandler - { - int32_t fd; ///< socket file descriptor - uint32_t msg_idx; ///< the start charactors index of message -+ int32_t sendtime_interverl; ///< udp send packet interverl - }; - - -@@ -90,24 +93,21 @@ int32_t client_bussiness(char *out, const char *in, uint32_t size, bool verify, - /** - * @brief server checks the information and answers - * This function checks the information and answers. -- * @param server_handler server handler -+ * @param fd socket_fd - * @param pktlen the length of package - * @param api the api - * @return the result - */ --int32_t server_ans(struct ServerHandler *server_handler, uint32_t pktlen, const char* api, const char* domain); -+int32_t server_ans(int32_t fd, uint32_t pktlen, const char* api, const char* domain); - - /** - * @brief client asks server - * This function asks server. - * @param client_handler client handler -- * @param pktlen the length of package -- * @param api the api -- * @param domain the domain -+ * @param client_unit ClientUnit - * @return the result - */ --int32_t client_ask(struct ClientHandler *client_handler, uint32_t pktlen, const char* api, const char* domain, in_addr_t ip, uint16_t port); -- -+int32_t client_ask(struct ClientHandler *client_handler, struct ClientUnit *client_unit); - /** - * @brief client checks the information and answers - * This function checks the information and answers. -@@ -119,7 +119,7 @@ int32_t client_ask(struct ClientHandler *client_handler, uint32_t pktlen, const - * @param ip the ip address of peer, maybe group ip - * @return the result - */ --int32_t client_chkans(struct ClientHandler *client_handler, uint32_t pktlen, bool verify, const char* api, const char* domain, in_addr_t ip); -+int32_t client_chkans(struct ClientHandler *client_handler, uint32_t pktlen, bool verify, const char* api, const char* domain, ip_addr_t* ip); - - - #endif // __EXAMPLES_BUSSINESS_H__ -diff --git a/examples/inc/client.h b/examples/inc/client.h -index 97af33f..0fe07aa 100644 ---- a/examples/inc/client.h -+++ b/examples/inc/client.h -@@ -19,31 +19,8 @@ - #include "parameter.h" - #include "bussiness.h" - -- --/** -- * @brief client unit -- * The information of each thread of client. -- */ --struct ClientUnit --{ -- struct ClientHandler *handlers; ///< the handlers -- int32_t epfd; ///< the connect epoll file descriptor -- struct epoll_event *epevs; ///< the epoll events -- uint32_t curr_connect; ///< current connection number -- uint64_t send_bytes; ///< total send bytes -- in_addr_t ip; ///< server ip -- in_addr_t groupip; ///< server groupip -- uint16_t port; ///< server port -- uint16_t sport; ///< client sport -- uint32_t connect_num; ///< total connection number -- uint32_t pktlen; ///< the length of peckage -- bool verify; ///< if we verify or not -- char* domain; ///< the communication domain -- char* api; ///< the type of api -- bool debug; ///< if we print the debug information -- char* epollcreate; ///< epoll_create method -- struct ClientUnit *next; ///< next pointer --}; -+#define TIME_SCAN_INTERVAL 1 -+#define TIME_SEND_INTERVAL 1 - - /** - * @brief client -@@ -53,8 +30,14 @@ struct Client - { - struct ClientUnit *uints; ///< the server mum unit - bool debug; ///< if we print the debug information -+ uint32_t threadNum; -+ bool loop; ///< judge client info print while loop is open - }; - -+struct Client_domain_ip { -+ char *domain; -+ uint8_t ip_family; -+}; - - /** - * @brief the single thread, client prints informations -@@ -66,7 +49,7 @@ struct Client - * @param debug if debug or not - * @return the result pointer - */ --void client_debug_print(const char *ch_str, const char *act_str, in_addr_t ip, uint16_t port, bool debug); -+void client_debug_print(const char *ch_str, const char *act_str, ip_addr_t *ip, uint16_t port, bool debug); - - /** - * @brief the client prints informations -@@ -86,7 +69,7 @@ void client_info_print(struct Client *client); - * @param domain domain - * @return the result pointer - */ --int32_t client_thread_try_connect(struct ClientHandler *client_handler, int32_t epoll_fd, in_addr_t ip, in_addr_t groupip, uint16_t port, uint16_t sport, const char *domain, const char *api); -+int32_t client_thread_try_connect(struct ClientHandler *client_handler, struct ClientUnit *client_unit); - - /** - * @brief the single thread, client retry to connect to server, register to epoll -@@ -122,4 +105,11 @@ void *client_s_create_and_run(void *arg); - int32_t client_create_and_run(struct ProgramParams *params); - - -+/** -+ * @brief loop server info -+ * This function print loop mode server info. -+ */ -+void loop_info_print(); -+ -+ - #endif // __EXAMPLES_CLIENT_H__ -diff --git a/examples/inc/parameter.h b/examples/inc/parameter.h -index 93e3672..ff2f114 100644 ---- a/examples/inc/parameter.h -+++ b/examples/inc/parameter.h -@@ -20,6 +20,8 @@ - - #define PARAM_DEFAULT_AS ("server") ///< default type - #define PARAM_DEFAULT_IP ("127.0.0.1") ///< default IP -+#define PARAM_DEFAULT_IP_V6 ("0.0.0.0.0.0.0.0") ///< default IP -+#define PARAM_DEFAULT_ADDR_FAMILY (AF_INET) ///< default address family - #define PARAM_DEFAULT_PORT (5050) ///< default port - #define PARAM_DEFAULT_SPORT (0) ///< default sport - #define PARAM_DEFAULT_MODEL ("mum") ///< default model type -@@ -34,6 +36,9 @@ - #define PARAM_DEFAULT_EPOLLCREATE ("ec") ///< default method of epoll_create - #define PARAM_DEFAULT_ACCEPT ("ac") ///< default method of accept method - #define PARAM_DEFAULT_GROUPIP ("0.0.0.0") ///< default group IP> -+#define PARAM_DEFAULT_KEEPALIVEIDLE (0) ///< default TCP_KEEPALIVE_IDLE_TIME> -+ -+#define TCP_KEEPALIVE_IDLE_MAX (3600) // time: second - - - enum { -@@ -43,7 +48,7 @@ enum { - PARAM_NUM_IP = 'i', - #define PARAM_NAME_PORT ("port") ///< name of parameter port - PARAM_NUM_PORT = 'p', --#define PARAM_NAME_SPORT ("sport") ///< name of parameter sport -+#define PARAM_NAME_SPORT ("sport") ///< name of parameter sport - PARAM_NUM_SPORT = 's', - #define PARAM_NAME_MODEL ("model") ///< name of parameter model type - PARAM_NUM_MODEL = 'm', -@@ -71,12 +76,27 @@ enum { - PARAM_NUM_ACCEPT = 'C', - #define PARAM_NAME_GROUPIP ("groupip") ///< name of parameter group ip - PARAM_NUM_GROUPIP = 'g', -+#define PARAM_NAME_KEEPALIVE ("keep_alive") ///< name of parameter keep_alive -+ PARAM_NUM_KEEPALIVE = 'k', -+#define PARAM_NAME_INJECT ("inject") ///< name of parameter fault inject -+ PARAM_NUM_INJECT = 'I', - }; - - #define NO_ARGUMENT 0 ///< options takes no arguments - #define REQUIRED_ARGUMETN 1 ///< options requires arguments - #define OPTIONAL_ARGUMETN 2 ///< options arguments are optional - -+uint8_t getbit_num(uint8_t mode, uint8_t index); -+uint8_t setbitnum_on(uint8_t mode, uint8_t index); -+uint8_t setbitnum_off(uint8_t mode, uint8_t index); -+ -+uint8_t program_get_protocol_mode_by_domain_ip(char* domain, char* ipv4, char* ipv6, char* group_ip); -+ -+struct ServerBaseCfgInfo { -+ const char *domain; -+ const char *api; -+ uint32_t pktlen; -+}; - - /** - * @brief program option description -@@ -96,12 +116,13 @@ struct ProgramOption { - struct ProgramParams { - char* as; ///< as server or client - char* ip; ///< IP address -- uint32_t port; ///< port -- uint32_t sport; ///< sport -+ char* ipv6; -+ bool port[UNIX_TCP_PORT_MAX]; ///< index:port list; value:port is set or not -+ bool sport[UNIX_TCP_PORT_MAX]; ///< index:sport list; value:sport is set or not - char* model; ///< model type - uint32_t thread_num; ///< the number of threads - uint32_t connect_num; ///< the connection number -- char* domain; ///< the communication dimain -+ char* domain; ///< the communication domain - char* api; ///< the type of api - uint32_t pktlen; ///< the packet length - bool verify; ///< if we verify the message or not -@@ -110,8 +131,58 @@ struct ProgramParams { - char* accept; ///< accept connections method - bool ringpmd; ///< if we use ring PMD or not - char* groupip; ///< group IP address> -+ char* groupip_interface; ///< udp multicast interface address> -+ uint32_t addr_family; ///< IP address family -+ int32_t tcp_keepalive_idle; ///< tcp keepalive idle time -+ int32_t tcp_keepalive_interval; ///< tcp keepalive interval time -+#define INJECT_TYPE_IDX (0) ///< the index of inject type -+#define INJECT_TIME_IDX (1) ///< the index of delay time -+#define INJECT_SKIP_IDX (1) ///< the index of skip location -+#define INJECT_LOCATION_IDX (2) ///< the index of delay location -+#define FAULT_INJECT_PARA_COUNT (3) ///< the count of fault injection parameters -+ char* inject[FAULT_INJECT_PARA_COUNT]; /// < fault inject - }; - -+typedef enum { -+ INJECT_DELAY_ACCEPT = 0, -+ INJECT_DELAY_READ, -+ INJECT_DELAY_WRITE, -+ INJECT_DELAY_MAX, -+}delay_type; -+ -+typedef enum { -+ INJECT_SKIP_READ = 0, -+ INJECT_SKIP_WRITE, -+ INJECT_SKIP_MAX, -+} skip_type; -+ -+typedef enum { -+ V4_TCP, -+ V6_TCP, -+ V4_UDP, -+ V6_UDP, -+ UDP_MULTICAST, -+ UNIX, -+ PROTOCOL_MODE_MAX -+} PROTOCOL_MODE_ENUM_TYPE; -+ -+#define FAULT_INJECT_SKIP_BEGIN(skip_type) \ -+ if (get_g_inject_skip((skip_type))) {} \ -+ else { -+#define FAULT_INJECT_SKIP_END } -+ -+/** -+ * @brief return g_inject_skip value -+ * This function return g_inject_skip value to deside if excute skip -+ */ -+int32_t get_g_inject_skip(skip_type type); -+ -+/** -+ * @brief function execute delay inject -+ * This function delay execute following program. -+ */ -+void fault_inject_delay(delay_type type); -+ - /** - * @brief initialize the parameters - * This function initializes the parameters of main function. -@@ -142,5 +213,6 @@ int32_t program_params_parse(struct ProgramParams *params, uint32_t argc, char * - */ - void program_params_print(struct ProgramParams *params); - -+bool ip_is_v6(const char *ip); - - #endif // __EXAMPLES_PARAMETER_H__ -diff --git a/examples/inc/server.h b/examples/inc/server.h -index a3affef..4631a28 100644 ---- a/examples/inc/server.h -+++ b/examples/inc/server.h -@@ -31,8 +31,7 @@ struct ServerMumUnit - struct epoll_event *epevs; ///< the epoll events - uint32_t curr_connect; ///< current connection number - uint64_t recv_bytes; ///< total receive bytes -- in_addr_t ip; ///< server ip -- in_addr_t groupip; ///< server group ip -+ struct ServerIpInfo server_ip_info; - uint16_t port; ///< server port - uint32_t pktlen; ///< the length of peckage - char* domain; ///< communication domain -@@ -40,6 +39,9 @@ struct ServerMumUnit - bool debug; ///< if we print the debug information - char* epollcreate; ///< epoll_create method - char* accept; ///< accept connections method -+ int32_t tcp_keepalive_idle; ///< tcp keepalive idle time -+ int32_t tcp_keepalive_interval; ///< tcp keepalive interval time -+ uint8_t protocol_type_mode; ///< tcp/udp ipv4/ipv6 protocol mode - struct ServerMumUnit *next; ///< next pointer - }; - -@@ -64,11 +66,13 @@ struct ServerMudWorker - struct epoll_event *epevs; ///< the epoll events - uint64_t recv_bytes; ///< total receive bytes - uint32_t pktlen; ///< the length of peckage -- in_addr_t ip; ///< client ip -+ ip_addr_t ip; ///< client ip - uint16_t port; ///< client port - char* api; ///< the type of api - bool debug; ///< if we print the debug information - char* epollcreate; ///< epoll_create method -+ char* domain; -+ uint32_t curr_connect; - struct ServerMudWorker *next; ///< next pointer - }; - -@@ -82,16 +86,17 @@ struct ServerMud - struct ServerMudWorker *workers; ///< the workers - int32_t epfd; ///< the listen epoll file descriptor - struct epoll_event *epevs; ///< the epoll events -- uint32_t curr_connect; ///< current connection number -- in_addr_t ip; ///< server ip -- in_addr_t groupip; ///< server group ip -- uint16_t port; ///< server port -+ struct ServerIpInfo server_ip_info; -+ bool* port; ///< server port point to parameter's port - uint32_t pktlen; ///< the length of peckage - char* domain; ///< communication domain - char* api; ///< the type of api - bool debug; ///< if we print the debug information - char* accept; ///< accept connections method - char* epollcreate; ///< epoll_create method -+ int32_t tcp_keepalive_idle; ///< tcp keepalive idle time -+ int32_t tcp_keepalive_interval; ///< tcp keepalive interval time -+ uint8_t protocol_type_mode; ///< tcp/udp ipv4/ipv6 protocol mode - }; - - -@@ -105,7 +110,7 @@ struct ServerMud - * @param debug if debug or not - * @return the result pointer - */ --void server_debug_print(const char *ch_str, const char *act_str, in_addr_t ip, uint16_t port, bool debug); -+void server_debug_print(const char *ch_str, const char *act_str, ip_addr_t *ip, uint16_t port, bool debug); - - /** - * @brief the multi thread, unblock, dissymmetric server prints informations -@@ -136,7 +141,7 @@ int32_t sermud_listener_create_epfd_and_reg(struct ServerMud *server_mud); - * @param server_mud the server unit - * @return the result pointer - */ --int32_t sermud_listener_accept_connects(struct ServerMud *server_mud); -+int32_t sermud_listener_accept_connects(struct epoll_event *curr_epev, struct ServerMud *server_mud); - - /** - * @brief the worker thread, unblock, dissymmetric server processes the events -@@ -200,7 +205,7 @@ int32_t sersum_create_epfd_and_reg(struct ServerMumUnit *server_unit); - * @param server_handler the server handler - * @return the result pointer - */ --int32_t sersum_accept_connects(struct ServerMumUnit *server_unit, struct ServerHandler *server_handler); -+int32_t sersum_accept_connects(struct epoll_event *cur_epev, struct ServerMumUnit *server_unit); - - /** - * @brief the single thread, unblock, mutliplexing IO server processes the events -diff --git a/examples/inc/utilities.h b/examples/inc/utilities.h -index 0f9db4e..262481a 100644 ---- a/examples/inc/utilities.h -+++ b/examples/inc/utilities.h -@@ -27,6 +27,7 @@ - #include - #include - #include -+#include - - #include - #include -@@ -36,6 +37,7 @@ - #include - - #include -+#include - #include - - #include "securec.h" -@@ -47,7 +49,7 @@ - { \ - printf("\n[error]: "); \ - printf(format, ##__VA_ARGS__); \ -- printf("\n"); \ -+ printf("\n\n"); \ - } while (0) - #define PRINT_WARNNING(format, ...) do \ - { \ -@@ -76,7 +78,7 @@ - } while(0) - #define PRINT_CLIENT_DATAFLOW(format, ...) do \ - { \ -- printf("\033[?25l\033[A\033[K"); \ -+ printf(" "); \ - printf("--> : "); \ - printf(format, ##__VA_ARGS__); \ - printf("\033[?25h\n"); \ -@@ -90,24 +92,94 @@ - #define PROGRAM_INPROGRESS (-2) ///< program in progress flag - - #define UNIX_TCP_PORT_MIN (1024) ///< TCP minimum port number in unix --#define UNIX_TCP_PORT_MAX (65535) ///< TCP minimum port number in unix -+#define UNIX_TCP_PORT_MAX (65535) ///< TCP maximum port number in unix - #define THREAD_NUM_MIN (1) ///< minimum number of thead - #define THREAD_NUM_MAX (1000) ///< maximum number of thead - #define MESSAGE_PKTLEN_MIN (2) ///< minimum length of message (1 byte) - #define MESSAGE_PKTLEN_MAX (1024 * 1024 * 10) ///< maximum length of message (10 Mb) -+#define UDP_PKTLEN_MAX (65507) ///< maximum length of udp message - --#define SERVER_SOCKET_LISTEN_BACKLOG (128) ///< the queue of socket -+#define SERVER_SOCKET_LISTEN_BACKLOG (4096) ///< the queue of socket - #define SERVER_EPOLL_SIZE_MAX (10000) ///< the max wait event of epoll - #define SERVER_EPOLL_WAIT_TIMEOUT (-1) ///< the timeout value of epoll - - #define CLIENT_EPOLL_SIZE_MAX (10000) ///< the max wait event of epoll - #define CLIENT_EPOLL_WAIT_TIMEOUT (-1) ///< the timeout value of epoll - --#define TERMINAL_REFRESH_MS (100) ///< the time cut off between of terminal refresh -+#define TERMINAL_REFRESH_MS (500) ///< the time cut off between of terminal refresh - - #define SOCKET_UNIX_DOMAIN_FILE "unix_domain_file" ///< socket unix domain file - -+#define IPV4_STR "V4" -+#define IPV6_STR "V6" -+#define IPV4_MULTICAST "Multicast" -+#define INVAILD_STR "STR_NULL" -+ -+#define TIMES_CONVERSION_RATE (1000) -+#define KB (1024) -+#define MB (KB * KB) -+#define GB (MB * MB) -+ -+struct ThreadUintInfo { -+ uint64_t send_bytes; ///< total send bytes -+ uint32_t cur_connect_num; ///< total connection number -+ char* domain; -+ char* ip_type_info; -+ pthread_t thread_id; -+}; -+ -+typedef struct ip_addr { -+ struct { -+ struct in_addr ip4; -+ struct in6_addr ip6; -+ } u_addr; -+ uint32_t addr_family; -+} ip_addr_t; -+ -+typedef union sockaddr_union { -+ struct sockaddr sa; -+ struct sockaddr_in in; -+ struct sockaddr_in6 in6; -+} sockaddr_t; - -+/** -+ * @brief client unit -+ * The information of each thread of client. -+ */ -+struct ClientUnit { -+ struct ClientHandler *handlers; ///< the handlers -+ int32_t epfd; ///< the connect epoll file descriptor -+ struct epoll_event *epevs; ///< the epoll events -+ uint32_t curr_connect; ///< current connection number -+ ip_addr_t ip; ///< server ip -+ ip_addr_t groupip; ///< server groupip -+ uint32_t port; ///< server port -+ ip_addr_t groupip_interface; ///< udp multicast interface address> -+ uint32_t sport; ///< client sport -+ uint32_t connect_num; ///< total connection number -+ uint32_t pktlen; ///< the length of peckage -+ uint32_t loop; ///< the packet send to loop -+ bool verify; ///< if we verify or not -+ char* domain; ///< the communication domain -+ char* api; ///< the type of api -+ bool debug; ///< if we print the debug information -+ char* epollcreate; ///< epoll_create method -+ uint8_t protocol_type_mode; ///< tcp/udp ipv4/ipv6 protocol mode -+ struct ThreadUintInfo threadVolume; -+ struct ClientUnit *next; ///< next pointer -+}; -+struct ServerIpInfo { -+ ip_addr_t ip; ///< server ip -+ ip_addr_t groupip; ///< server group ip -+ ip_addr_t groupip_interface; ///< server group interface ip -+}; -+ -+struct LoopInfo { -+ char* model; -+ struct ServerMud *server_mud_info; -+ struct ServerMum *server_mum_info; -+}; -+extern struct LoopInfo loopmod; - /** - * @brief create the socket and listen - * Thi function creates the socket and listen. -@@ -118,7 +190,8 @@ - * @param domain domain - * @return the result - */ --int32_t create_socket_and_listen(int32_t *socket_fd, in_addr_t ip, in_addr_t groupip, uint16_t port, const char *domain); -+int32_t create_socket_and_listen(int32_t *listen_fd_array, struct ServerIpInfo *server_ip_info, uint16_t port, -+ uint8_t protocol_mode); - - /** - * @brief create the socket and connect -@@ -131,7 +204,7 @@ int32_t create_socket_and_listen(int32_t *socket_fd, in_addr_t ip, in_addr_t gro - * @param api api - * @return the result - */ --int32_t create_socket_and_connect(int32_t *socket_fd, in_addr_t ip, in_addr_t groupip, uint16_t port, uint16_t sport, const char *domain, const char *api); -+int32_t create_socket_and_connect(int32_t *socket_fd, struct ClientUnit *client_unit); - - /** - * @brief set the socket to unblock -@@ -140,6 +213,7 @@ int32_t create_socket_and_connect(int32_t *socket_fd, in_addr_t ip, in_addr_t gr - * @return the result - */ - int32_t set_socket_unblock(int32_t socket_fd); -+int32_t set_tcp_keep_alive_info(int32_t sockfd, int32_t tcp_keepalive_idle, int32_t tcp_keepalive_interval); - - - #endif // __EXAMPLES_UTILITIES_H__ -diff --git a/examples/main.c b/examples/main.c -index 5338572..dfee2db 100644 ---- a/examples/main.c -+++ b/examples/main.c -@@ -31,7 +31,12 @@ int32_t main(int argc, char *argv[]) - - if (strcmp(prog_params.as, "server") == 0) { - server_create_and_run(&prog_params); -- } else { -+ } else if (strcmp(prog_params.as, "client") == 0) { -+ client_create_and_run(&prog_params); -+ } else if (strcmp(prog_params.as, "loop") == 0) { -+ server_create_and_run(&prog_params); -+ /* sleep to wait server creating */ -+ sleep(1); - client_create_and_run(&prog_params); - } - -diff --git a/examples/src/bussiness.c b/examples/src/bussiness.c -index 7263371..46c99fe 100644 ---- a/examples/src/bussiness.c -+++ b/examples/src/bussiness.c -@@ -11,8 +11,9 @@ - */ - - --#include "bussiness.h" -+#include "parameter.h" - #include "client.h" -+#include "bussiness.h" - - - static const char bussiness_messages_low[] = "abcdefghijklmnopqrstuvwxyz"; // the lower charactors of business message -@@ -135,41 +136,41 @@ int32_t client_bussiness(char *out, const char *in, uint32_t size, bool verify, - return PROGRAM_OK; - } - --// server answers --int32_t server_ans(struct ServerHandler *server_handler, uint32_t pktlen, const char* api, const char* domain) -+static void server_ans_free_buff(char *buff_in, char *buff_out) - { -- const uint32_t length = pktlen; -- char *buffer_in = (char *)malloc(length * sizeof(char)); -- char *buffer_out = (char *)malloc(length * sizeof(char)); -+ if (buff_in) { -+ free(buff_in); -+ } -+ if (buff_out) { -+ free(buff_out); -+ } -+} -+ -+// server_ans_read -+static int32_t server_ans_read(int32_t socket_fd, struct ServerBaseCfgInfo *server_base_info, char *buffer_in, -+ struct sockaddr *client_addr) -+{ -+ const uint32_t length = server_base_info->pktlen; -+ const char *api = server_base_info->api; -+ const char *domain = server_base_info->domain; - - int32_t cread = 0; - int32_t sread = length; - int32_t nread = 0; -- struct sockaddr_in client_addr; -- socklen_t len = sizeof(client_addr); - -- if (strcmp(domain, "udp") == 0 && strncmp(api, "recvfrom", strlen("recvfrom")) != 0) { -- if (getpeername(server_handler->fd, (struct sockaddr *)&client_addr, &len) < 0) { -- if (recvfrom(server_handler->fd, buffer_in, length, MSG_PEEK, (struct sockaddr *)&client_addr, &len) < 0) { -- return PROGRAM_FAULT; -- } -- if (connect(server_handler->fd, (struct sockaddr *)&client_addr, sizeof(struct sockaddr_in)) < 0) { -- return PROGRAM_FAULT; -- } -- } -- } -+ socklen_t len = sizeof(sockaddr_t); - - while (cread < sread) { - if (strcmp(domain, "udp") == 0 && strcmp(api, "recvfromsendto") == 0) { -- nread = recvfrom(server_handler->fd, buffer_in, length, 0, (struct sockaddr *)&client_addr, &len); -+ nread = recvfrom(socket_fd, buffer_in, length, 0, client_addr, &len); - } else { -- nread = read_api(server_handler->fd, buffer_in, length, api); -+ nread = read_api(socket_fd, buffer_in, length, api); - } -- - if (nread == 0) { - return PROGRAM_ABORT; - } else if (nread < 0) { - if (errno != EINTR && errno != EWOULDBLOCK && errno != EAGAIN) { -+ PRINT_ERROR("nread =%d, errno=%d", nread, errno); - return PROGRAM_FAULT; - } - } else { -@@ -177,66 +178,152 @@ int32_t server_ans(struct ServerHandler *server_handler, uint32_t pktlen, const - continue; - } - } -+ return PROGRAM_OK; -+} - -- if (strcmp(api, "recvfrom") == 0) { -- free(buffer_in); -- free(buffer_out); -- return PROGRAM_OK; -- } -- -- server_bussiness(buffer_out, buffer_in, length); -+static int32_t server_ans_write(int32_t socket_fd, struct ServerBaseCfgInfo *server_base_info, char *buffer_out, -+ struct sockaddr *client_addr) -+{ -+ const uint32_t length = server_base_info->pktlen; -+ const char *api = server_base_info->api; -+ const char *domain = server_base_info->domain; - - int32_t cwrite = 0; - int32_t swrite = length; - int32_t nwrite = 0; -+ socklen_t len = sizeof(sockaddr_t); -+ - while (cwrite < swrite) { - if (strcmp(domain, "udp") == 0 && strcmp(api, "recvfromsendto") == 0) { -- nwrite = sendto(server_handler->fd, buffer_out, length, 0, (struct sockaddr *)&client_addr, len); -+ nwrite = sendto(socket_fd, buffer_out, swrite - cwrite, 0, client_addr, len); - } else { -- nwrite = write_api(server_handler->fd, buffer_out, length, api); -+ nwrite = write_api(socket_fd, buffer_out, swrite - cwrite, api); - } - - if (nwrite == 0) { - return PROGRAM_ABORT; - } else if (nwrite < 0) { -- if (errno != EINTR && errno != EWOULDBLOCK && errno != EAGAIN) { -+ if (errno != EINTR && errno != EWOULDBLOCK && errno != EAGAIN) { -+ PRINT_ERROR("nwrite =%d, errno=%d", nwrite, errno); - return PROGRAM_FAULT; -- } -+ } - } else { - cwrite += nwrite; - continue; - } - } -+ return PROGRAM_OK; -+} - -- free(buffer_in); -- free(buffer_out); -+// server answers -+int32_t server_ans(int32_t fd, uint32_t pktlen, const char* api, const char* domain) -+{ -+ const uint32_t length = pktlen; -+ char *buffer_in = (char *)calloc(length, sizeof(char)); -+ char *buffer_out = (char *)calloc(length, sizeof(char)); -+ if (buffer_in == NULL || buffer_out == NULL) { -+ return PROGRAM_FAULT; -+ } -+ -+ struct ServerBaseCfgInfo server_base_info; -+ server_base_info.domain = domain; -+ server_base_info.api = api; -+ server_base_info.pktlen = pktlen; -+ -+ sockaddr_t client_addr; -+ socklen_t len = sizeof(sockaddr_t); -+ -+ if (strcmp(domain, "udp") == 0 && strncmp(api, "recvfrom", strlen("recvfrom")) != 0) { -+ if (getpeername(fd, (struct sockaddr *)&client_addr, &len) < 0) { -+ if (recvfrom(fd, buffer_in, length, MSG_PEEK, (struct sockaddr *)&client_addr, &len) < 0) { -+ server_ans_free_buff(buffer_in, buffer_out); -+ return PROGRAM_FAULT; -+ } -+ if (connect(fd, (struct sockaddr *)&client_addr, len) < 0) { -+ server_ans_free_buff(buffer_in, buffer_out); -+ return PROGRAM_FAULT; -+ } -+ } -+ } -+ -+ fault_inject_delay(INJECT_DELAY_READ); -+ FAULT_INJECT_SKIP_BEGIN(INJECT_SKIP_READ) -+ -+ if (server_ans_read(fd, &server_base_info, buffer_in, (struct sockaddr *)&client_addr) != PROGRAM_OK) { -+ server_ans_free_buff(buffer_in, buffer_out); -+ return PROGRAM_FAULT; -+ } -+ -+ FAULT_INJECT_SKIP_END -+ -+ if (strcmp(api, "recvfrom") == 0) { -+ server_ans_free_buff(buffer_in, buffer_out); -+ return PROGRAM_OK; -+ } -+ -+ server_bussiness(buffer_out, buffer_in, length); -+ -+ fault_inject_delay(INJECT_DELAY_WRITE); -+ FAULT_INJECT_SKIP_BEGIN(INJECT_SKIP_WRITE) -+ -+ if (server_ans_write(fd, &server_base_info, buffer_out, (struct sockaddr *)&client_addr) != PROGRAM_OK) { -+ server_ans_free_buff(buffer_in, buffer_out); -+ return PROGRAM_FAULT; -+ } -+ -+ FAULT_INJECT_SKIP_END -+ -+ server_ans_free_buff(buffer_in, buffer_out); - - return PROGRAM_OK; - } - - // client asks --int32_t client_ask(struct ClientHandler *client_handler, uint32_t pktlen, const char* api, const char* domain, in_addr_t ip, uint16_t port) -+int32_t client_ask(struct ClientHandler *client_handler, struct ClientUnit *client_unit) - { -- const uint32_t length = pktlen; -- char *buffer_in = (char *)malloc(length * sizeof(char)); -- char *buffer_out = (char *)malloc(length * sizeof(char)); -- struct sockaddr_in server_addr; -- socklen_t len = sizeof(server_addr); -- memset_s(&server_addr, sizeof(server_addr), 0, sizeof(server_addr)); -- server_addr.sin_family = AF_INET; -- server_addr.sin_addr.s_addr = ip; -- server_addr.sin_port = port; -+ const char *api = client_unit->api; -+ const char *domain = client_unit->domain; -+ -+ ip_addr_t *ip = client_unit->protocol_type_mode == UDP_MULTICAST ? &client_unit->groupip : &client_unit->ip; -+ uint16_t port = client_unit->port; -+ -+ const uint32_t length = client_unit->pktlen; -+ char *buffer_in = (char *)calloc(length, sizeof(char)); -+ char *buffer_out = (char *)calloc(length, sizeof(char)); -+ if (buffer_in == NULL || buffer_out == NULL) { -+ return PROGRAM_FAULT; -+ } -+ sockaddr_t server_addr; -+ socklen_t len = 0; -+ -+ if (ip->addr_family == AF_INET6) { -+ memset_s(&server_addr, sizeof(struct sockaddr_in6), 0, sizeof(struct sockaddr_in6)); -+ ((struct sockaddr_in6 *)&server_addr)->sin6_family = AF_INET6; -+ ((struct sockaddr_in6 *)&server_addr)->sin6_addr = ip->u_addr.ip6; -+ ((struct sockaddr_in6 *)&server_addr)->sin6_port = port; -+ len = sizeof(struct sockaddr_in6); -+ } else if (ip->addr_family == AF_INET) { -+ memset_s(&server_addr, sizeof(struct sockaddr_in), 0, sizeof(struct sockaddr_in)); -+ ((struct sockaddr_in *)&server_addr)->sin_family = AF_INET; -+ ((struct sockaddr_in *)&server_addr)->sin_addr = ip->u_addr.ip4; -+ ((struct sockaddr_in *)&server_addr)->sin_port = port; -+ len = sizeof(struct sockaddr_in); -+ } - - client_bussiness(buffer_out, buffer_in, length, false, &(client_handler->msg_idx)); - - int32_t cwrite = 0; - int32_t swrite = length; - int32_t nwrite = 0; -+ -+ fault_inject_delay(INJECT_DELAY_WRITE); -+ FAULT_INJECT_SKIP_BEGIN(INJECT_SKIP_WRITE) -+ - while (cwrite < swrite) { - if (strcmp(domain, "udp") == 0 && strcmp(api, "recvfromsendto") == 0) { -- nwrite = sendto(client_handler->fd, buffer_out, length, 0, (struct sockaddr *)&server_addr, len); -+ nwrite = sendto(client_handler->fd, buffer_out, swrite - cwrite, 0, (struct sockaddr *)&server_addr, len); - } else { -- nwrite = write_api(client_handler->fd, buffer_out, length, api); -+ nwrite = write_api(client_handler->fd, buffer_out, swrite - cwrite, api); - } - if (nwrite == 0) { - return PROGRAM_ABORT; -@@ -250,6 +337,8 @@ int32_t client_ask(struct ClientHandler *client_handler, uint32_t pktlen, const - } - } - -+ FAULT_INJECT_SKIP_END -+ - free(buffer_in); - free(buffer_out); - -@@ -257,18 +346,24 @@ int32_t client_ask(struct ClientHandler *client_handler, uint32_t pktlen, const - } - - // client checks --int32_t client_chkans(struct ClientHandler *client_handler, uint32_t pktlen, bool verify, const char* api, const char* domain, in_addr_t ip) -+int32_t client_chkans(struct ClientHandler *client_handler, uint32_t pktlen, bool verify, const char* api, const char* domain, ip_addr_t* ip) - { - const uint32_t length = pktlen; -- char *buffer_in = (char *)malloc(length * sizeof(char)); -- char *buffer_out = (char *)malloc(length * sizeof(char)); -+ char *buffer_in = (char *)calloc(length, sizeof(char)); -+ char *buffer_out = (char *)calloc(length, sizeof(char)); -+ if (buffer_in == NULL || buffer_out == NULL) { -+ return PROGRAM_FAULT; -+ } - - int32_t cread = 0; - int32_t sread = length; - int32_t nread = 0; -- struct sockaddr_in server_addr; -- socklen_t len = sizeof(server_addr); -+ sockaddr_t server_addr; -+ socklen_t len = ip->addr_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); - -+ fault_inject_delay(INJECT_DELAY_READ); -+ FAULT_INJECT_SKIP_BEGIN(INJECT_SKIP_READ) -+ - while (cread < sread) { - if (strcmp(domain, "udp") == 0 && strcmp(api, "recvfromsendto") == 0) { - nread = recvfrom(client_handler->fd, buffer_in, length, 0, (struct sockaddr *)&server_addr, &len); -@@ -287,6 +382,8 @@ int32_t client_chkans(struct ClientHandler *client_handler, uint32_t pktlen, boo - } - } - -+ FAULT_INJECT_SKIP_END -+ - if (client_bussiness(buffer_out, buffer_in, length, verify, &(client_handler->msg_idx)) < 0) { - PRINT_ERROR("message verify fault! "); - getchar(); -@@ -295,15 +392,18 @@ int32_t client_chkans(struct ClientHandler *client_handler, uint32_t pktlen, boo - int32_t cwrite = 0; - int32_t swrite = length; - int32_t nwrite = 0; -- if (ip >= inet_addr("224.0.0.0") && ip <= inet_addr("239.255.255.255")) { -- server_addr.sin_addr.s_addr = ip; -+ if (ip->addr_family == AF_INET && ip->u_addr.ip4.s_addr >= inet_addr("224.0.0.0") && ip->u_addr.ip4.s_addr <= inet_addr("239.255.255.255")) { -+ ((struct sockaddr_in*)&server_addr)->sin_addr = ip->u_addr.ip4; - } - -+ fault_inject_delay(INJECT_DELAY_WRITE); -+ FAULT_INJECT_SKIP_BEGIN(INJECT_SKIP_WRITE) -+ - while (cwrite < swrite) { - if (strcmp(domain, "udp") == 0 && strcmp(api, "recvfromsendto") == 0) { -- nwrite = sendto(client_handler->fd, buffer_out, length, 0, (struct sockaddr *)&server_addr, len); -+ nwrite = sendto(client_handler->fd, buffer_out, swrite - cwrite, 0, (struct sockaddr *)&server_addr, len); - } else { -- nwrite = write_api(client_handler->fd, buffer_out, length, api); -+ nwrite = write_api(client_handler->fd, buffer_out, swrite - cwrite, api); - } - if (nwrite == 0) { - return PROGRAM_ABORT; -@@ -317,6 +417,8 @@ int32_t client_chkans(struct ClientHandler *client_handler, uint32_t pktlen, boo - } - } - -+ FAULT_INJECT_SKIP_END -+ - free(buffer_in); - free(buffer_out); - -diff --git a/examples/src/client.c b/examples/src/client.c -index 1366924..43fbd0e 100644 ---- a/examples/src/client.c -+++ b/examples/src/client.c -@@ -12,24 +12,61 @@ - - - #include "client.h" -- -+#include "server.h" - - static pthread_mutex_t client_debug_mutex; // the client mutex for printf -+struct Client *g_client_begin = NULL; -+ -+static int32_t client_process_ask(struct ClientHandler *client_handler, struct ClientUnit *client_unit); -+static void client_get_domain_ipversion(uint8_t protocol_type, struct ClientUnit *client_unit); - -+static void timer_handle(int signum) -+{ -+ if (g_client_begin == NULL) { -+ return; -+ } -+ -+ struct ClientUnit *begin_client_unit = g_client_begin->uints; -+ while (begin_client_unit != NULL) { -+ if (begin_client_unit->domain != NULL && strcmp(begin_client_unit->domain, "udp") != 0) { -+ begin_client_unit = begin_client_unit->next; -+ continue; -+ } -+ for (int32_t i = 0; i < begin_client_unit->connect_num; i++) { -+ struct ClientHandler *handle = begin_client_unit->handlers + i; -+ if (handle->sendtime_interverl == TIME_SEND_INTERVAL) { -+ client_process_ask(handle, begin_client_unit); -+ } else { -+ handle->sendtime_interverl++; -+ } -+ } -+ -+ begin_client_unit = begin_client_unit->next; -+ } -+ alarm(TIME_SCAN_INTERVAL); -+} -+ -+static struct Client_domain_ip g_cfgmode_map[PROTOCOL_MODE_MAX] = { -+ [V4_TCP] = {"tcp", AF_INET}, -+ [V6_TCP] = {"tcp", AF_INET6}, -+ [V4_UDP] = {"udp", AF_INET}, -+ [V6_UDP] = {"udp", AF_INET6}, -+ [UDP_MULTICAST] = {"udp", AF_INET}}; - - // the single thread, client prints informations --void client_debug_print(const char *ch_str, const char *act_str, in_addr_t ip, uint16_t port, bool debug) -+void client_debug_print(const char *ch_str, const char *act_str, ip_addr_t *ip, uint16_t port, bool debug) - { - if (debug == true) { - pthread_mutex_lock(&client_debug_mutex); -- struct in_addr sin_addr; -- sin_addr.s_addr = ip; -+ uint8_t str_len = ip->addr_family == AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN; -+ char str_ip[str_len]; -+ inet_ntop(ip->addr_family, &ip->u_addr, str_ip, str_len); - PRINT_CLIENT("[%s] [pid: %d] [tid: %ld] [%s <- %s:%d]. ", \ - ch_str, \ - getpid(), \ - pthread_self(), \ - act_str, \ -- inet_ntoa(sin_addr), \ -+ str_ip, \ - ntohs(port)); - pthread_mutex_unlock(&client_debug_mutex); - } -@@ -41,7 +78,8 @@ void client_info_print(struct Client *client) - if (client->debug == false) { - struct timeval begin; - gettimeofday(&begin, NULL); -- uint64_t begin_time = (uint64_t)begin.tv_sec * 1000 + (uint64_t)begin.tv_usec / 1000; -+ uint64_t begin_time = (uint64_t)begin.tv_sec * TIMES_CONVERSION_RATE + -+ (uint64_t)begin.tv_usec / TIMES_CONVERSION_RATE; - - uint32_t curr_connect = 0; - double bytes_ps = 0; -@@ -49,45 +87,164 @@ void client_info_print(struct Client *client) - struct ClientUnit *begin_uint = client->uints; - while (begin_uint != NULL) { - curr_connect += begin_uint->curr_connect; -- begin_send_bytes += begin_uint->send_bytes; -+ begin_send_bytes += begin_uint->threadVolume.send_bytes; - begin_uint = begin_uint->next; - } - - struct timeval delay; - delay.tv_sec = 0; -- delay.tv_usec = TERMINAL_REFRESH_MS * 1000; -+ delay.tv_usec = TERMINAL_REFRESH_MS * TIMES_CONVERSION_RATE; - select(0, NULL, NULL, NULL, &delay); - - uint64_t end_send_bytes = 0; - struct ClientUnit *end_uint = client->uints; - while (end_uint != NULL) { -- end_send_bytes += end_uint->send_bytes; -+ end_send_bytes += end_uint->threadVolume.send_bytes; - end_uint = end_uint->next; - } - - struct timeval end; - gettimeofday(&end, NULL); -- uint64_t end_time = (uint64_t)end.tv_sec * 1000 + (uint64_t)end.tv_usec / 1000; -- -+ uint64_t end_time = (uint64_t)end.tv_sec * TIMES_CONVERSION_RATE + -+ (uint64_t)end.tv_usec / TIMES_CONVERSION_RATE; -+ - double bytes_sub = end_send_bytes > begin_send_bytes ? (double)(end_send_bytes - begin_send_bytes) : 0; -- double time_sub = end_time > begin_time ? (double)(end_time - begin_time) / 1000 : 0; -+ double time_sub = end_time > begin_time ? (double)(end_time - begin_time) / TIMES_CONVERSION_RATE : 0; - - bytes_ps = bytes_sub / time_sub; - -- if (bytes_ps < 1024) { -+ if (bytes_ps < KB) { - PRINT_CLIENT_DATAFLOW("[connect num]: %d, [send]: %.3f B/s", curr_connect, bytes_ps); -- } else if (bytes_ps < (1024 * 1024)) { -- PRINT_CLIENT_DATAFLOW("[connect num]: %d, [send]: %.3f KB/s", curr_connect, bytes_ps / 1024); -+ } else if (bytes_ps < MB) { -+ PRINT_CLIENT_DATAFLOW("[connect num]: %d, [send]: %.3f KB/s", curr_connect, bytes_ps / KB); - } else { -- PRINT_CLIENT_DATAFLOW("[connect num]: %d, [send]: %.3f MB/s", curr_connect, bytes_ps / (1024 * 1024)); -+ PRINT_CLIENT_DATAFLOW("[connect num]: %d, [send]: %.3f MB/s", curr_connect, bytes_ps / MB); -+ } -+ -+ if (client->loop) { -+ printf("\033[2A\033[120C\033[K\n"); -+ return; -+ } -+ printf("\033[A\033[K"); -+ } -+} -+ -+static int32_t client_process_ask(struct ClientHandler *client_handler, struct ClientUnit *client_unit) -+{ -+ // not support udp+v6 currently -+ if (strcmp(client_unit->domain, "udp") == 0 && client_unit->ip.addr_family == AF_INET6) { -+ return PROGRAM_OK; -+ } -+ -+ int32_t client_ask_ret = client_ask(client_handler, client_unit); -+ if (client_ask_ret == PROGRAM_FAULT) { -+ --client_unit->curr_connect; -+ struct epoll_event ep_ev; -+ if (client_handler->fd > 0 && epoll_ctl(client_unit->epfd, EPOLL_CTL_DEL, (client_handler)->fd, &ep_ev) < 0) { -+ PRINT_ERROR("client can't delete socket '%d' to control epoll %d! ", (client_handler)->fd, errno); -+ return PROGRAM_FAULT; - } -+ } else if (client_ask_ret == PROGRAM_ABORT) { -+ --client_unit->curr_connect; -+ if (close((client_handler)->fd) < 0) { -+ PRINT_ERROR("client can't close the socket! "); -+ return PROGRAM_FAULT; -+ } -+ client_debug_print("client unit", "close", &client_unit->ip, client_unit->port, client_unit->debug); -+ } else { -+ client_unit->threadVolume.send_bytes += client_unit->pktlen; -+ client_handler->sendtime_interverl = 0; -+ client_debug_print("client unit", "send", &client_unit->ip, client_unit->port, client_unit->debug); -+ } -+ return PROGRAM_OK; -+} -+ -+static void client_get_thread_volume(struct Client *client, struct ThreadUintInfo *threadVolume) -+{ -+ int index = 0; -+ struct ClientUnit *curUint = client->uints; -+ while (curUint != NULL && index < client->threadNum) { -+ threadVolume[index].send_bytes = curUint->threadVolume.send_bytes; -+ -+ threadVolume[index].cur_connect_num = curUint->curr_connect; -+ threadVolume[index].thread_id = curUint->threadVolume.thread_id; -+ threadVolume[index].domain = curUint->threadVolume.domain; -+ threadVolume[index].ip_type_info = curUint->threadVolume.ip_type_info; -+ curUint = curUint->next; -+ index++; -+ } -+} -+ -+void client_info_print_mixed(struct Client *client, struct ThreadUintInfo *threadVolume, -+ struct ThreadUintInfo *endThreadVolume) -+{ -+ if (client->debug == true) { -+ return; -+ } -+ int32_t pthread_num = client->threadNum; -+ int32_t not_support_thread = 0; -+ struct timeval cur = {0}; -+ -+ gettimeofday(&cur, NULL); -+ uint64_t begin_time = (uint64_t)cur.tv_sec * TIMES_CONVERSION_RATE + (uint64_t)cur.tv_usec / TIMES_CONVERSION_RATE; -+ -+ client_get_thread_volume(client, threadVolume); -+ -+ struct timeval delay; -+ delay.tv_sec = 0; -+ delay.tv_usec = TERMINAL_REFRESH_MS * TIMES_CONVERSION_RATE; -+ select(0, NULL, NULL, NULL, &delay); -+ -+ client_get_thread_volume(client, endThreadVolume); -+ -+ gettimeofday(&cur, NULL); -+ uint64_t end_time = (uint64_t)cur.tv_sec * TIMES_CONVERSION_RATE + (uint64_t)cur.tv_usec / TIMES_CONVERSION_RATE; -+ -+ for (int i = 0; i < pthread_num; i++) { -+ uint64_t begin_send_bytes = threadVolume[i].send_bytes; -+ uint64_t end_send_bytes = endThreadVolume[i].send_bytes; -+ pthread_t thread_id = endThreadVolume[i].thread_id; -+ uint32_t connect_num = endThreadVolume[i].cur_connect_num; -+ char *domain = endThreadVolume[i].domain; -+ char *ip_ver = endThreadVolume[i].ip_type_info; -+ -+ if (thread_id == 0) { -+ not_support_thread++; -+ continue; -+ } -+ -+ double bytes_sub = end_send_bytes > begin_send_bytes ? (double)(end_send_bytes - begin_send_bytes) : 0; -+ double time_sub = end_time > begin_time ? (double)(end_time - begin_time) / TIMES_CONVERSION_RATE : 0; -+ double bytes_ps = bytes_sub / time_sub; -+ -+ if (bytes_ps < KB) { -+ PRINT_CLIENT_DATAFLOW("threadID=%-15lu, %s_%-9s [connect num]: %u, [send]: %.3f B/s", -+ thread_id, domain, ip_ver, connect_num, bytes_ps); -+ } else if (bytes_ps < MB) { -+ PRINT_CLIENT_DATAFLOW("threadID=%-15lu, %s_%-9s [connect num]: %u, [send]: %.3f kB/s", -+ thread_id, domain, ip_ver, connect_num, bytes_ps / KB); -+ } else { -+ PRINT_CLIENT_DATAFLOW("threadID=%-15lu, %s_%-9s [connect num]: %u, [send]: %.3f MB/s", -+ thread_id, domain, ip_ver, connect_num, bytes_ps / MB); -+ } -+ } -+ printf("\033[%dA\033[K", pthread_num - not_support_thread); -+} -+ -+void loop_info_print() -+{ -+ printf(" "); -+ if (strcmp(loopmod.model, "mum") == 0) { -+ sermum_info_print(loopmod.server_mum_info); -+ } else { -+ sermud_info_print(loopmod.server_mud_info); - } - } - - // the single thread, client try to connect to server, register to epoll --int32_t client_thread_try_connect(struct ClientHandler *client_handler, int32_t epoll_fd, in_addr_t ip, in_addr_t groupip, uint16_t port, uint16_t sport, const char *domain, const char *api) -+int32_t client_thread_try_connect(struct ClientHandler *client_handler, struct ClientUnit *client_unit) - { -- int32_t create_socket_and_connect_ret = create_socket_and_connect(&(client_handler->fd), ip, groupip, port, sport, domain, api); -+ int32_t create_socket_and_connect_ret = create_socket_and_connect(&(client_handler->fd), client_unit); - if (create_socket_and_connect_ret == PROGRAM_INPROGRESS) { - return PROGRAM_OK; - } -@@ -97,7 +254,7 @@ int32_t client_thread_try_connect(struct ClientHandler *client_handler, int32_t - // the single thread, client retry to connect to server, register to epoll - int32_t client_thread_retry_connect(struct ClientUnit *client_unit, struct ClientHandler *client_handler) - { -- int32_t clithd_try_cnntask_ret = client_thread_try_connect(client_handler, client_unit->epfd, client_unit->ip, client_unit->groupip, client_unit->port, client_unit->sport, client_unit->domain, client_unit->api); -+ int32_t clithd_try_cnntask_ret = client_thread_try_connect(client_handler, client_unit); - if (clithd_try_cnntask_ret < 0) { - if (clithd_try_cnntask_ret == PROGRAM_INPROGRESS) { - return PROGRAM_OK; -@@ -114,35 +271,27 @@ int32_t client_thread_retry_connect(struct ClientUnit *client_unit, struct Clien - - ++(client_unit->curr_connect); - -- struct sockaddr_in server_addr; -- socklen_t server_addr_len = sizeof(server_addr); -+ sockaddr_t server_addr; -+ socklen_t server_addr_len = client_unit->ip.addr_family ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); - if (getpeername(client_handler->fd, (struct sockaddr *)&server_addr, &server_addr_len) < 0) { - PRINT_ERROR("client can't socket peername %d! ", errno); - return PROGRAM_FAULT; - } -- client_debug_print("client unit", "connect", server_addr.sin_addr.s_addr, server_addr.sin_port, client_unit->debug); - -- int32_t client_ask_ret = client_ask(client_handler, client_unit->pktlen, client_unit->api, client_unit->domain, client_unit->groupip ? client_unit->groupip:client_unit->ip, client_unit->port); -- if (client_ask_ret == PROGRAM_FAULT) { -- --client_unit->curr_connect; -- struct epoll_event ep_ev; -- if (epoll_ctl(client_unit->epfd, EPOLL_CTL_DEL, client_handler->fd, &ep_ev) < 0) { -- PRINT_ERROR("client can't delete socket '%d' to control epoll %d! ", client_handler->fd, errno); -- return PROGRAM_FAULT; -- } -- } else if (client_ask_ret == PROGRAM_ABORT) { -- --client_unit->curr_connect; -- if (close(client_handler->fd) < 0) { -- PRINT_ERROR("client can't close the socket %d! ", errno); -- return PROGRAM_FAULT; -- } -- client_debug_print("client unit", "close", server_addr.sin_addr.s_addr, server_addr.sin_port, client_unit->debug); -- } else { -- client_unit->send_bytes += client_unit->pktlen; -- client_debug_print("client unit", "send", server_addr.sin_addr.s_addr, server_addr.sin_port, client_unit->debug); -+ // sockaddr to ip, port -+ ip_addr_t remote_ip; -+ uint16_t remote_port = ((struct sockaddr_in*)&server_addr)->sin_port; -+ if (((struct sockaddr *)&server_addr)->sa_family == AF_INET) { -+ remote_ip.addr_family = AF_INET; -+ remote_ip.u_addr.ip4 = ((struct sockaddr_in *)&server_addr)->sin_addr; -+ } else if (((struct sockaddr *)&server_addr)->sa_family == AF_INET6) { -+ remote_ip.addr_family = AF_INET6; -+ remote_ip.u_addr.ip6 = ((struct sockaddr_in6 *)&server_addr)->sin6_addr; - } - -- return PROGRAM_OK; -+ client_debug_print("client unit", "connect", &remote_ip, remote_port, client_unit->debug); -+ -+ return client_process_ask(client_handler, client_unit); - } - - // the single thread, client connects and gets epoll feature descriptors -@@ -162,7 +311,7 @@ int32_t client_thread_create_epfd_and_reg(struct ClientUnit *client_unit) - } - - for (uint32_t i = 0; i < connect_num; ++i) { -- int32_t clithd_try_cnntask_ret = client_thread_try_connect(client_unit->handlers + i, client_unit->epfd, client_unit->ip, client_unit->groupip, client_unit->port, client_unit->sport, client_unit->domain, client_unit->api); -+ int32_t clithd_try_cnntask_ret = client_thread_try_connect(client_unit->handlers + i, client_unit); - if (clithd_try_cnntask_ret < 0) { - if (clithd_try_cnntask_ret == PROGRAM_INPROGRESS) { - continue; -@@ -179,26 +328,11 @@ int32_t client_thread_create_epfd_and_reg(struct ClientUnit *client_unit) - - ++(client_unit->curr_connect); - -- client_debug_print("client unit", "connect", client_unit->ip, client_unit->port, client_unit->debug); -- -- int32_t client_ask_ret = client_ask(client_unit->handlers + i, client_unit->pktlen, client_unit->api, client_unit->domain, client_unit->groupip ? client_unit->groupip:client_unit->ip, client_unit->port); -- if (client_ask_ret == PROGRAM_FAULT) { -- --client_unit->curr_connect; -- struct epoll_event ep_ev; -- if (epoll_ctl(client_unit->epfd, EPOLL_CTL_DEL, (client_unit->handlers + i)->fd, &ep_ev) < 0) { -- PRINT_ERROR("client can't delete socket '%d' to control epoll %d! ", client_unit->epevs[i].data.fd, errno); -- return PROGRAM_FAULT; -- } -- } else if (client_ask_ret == PROGRAM_ABORT) { -- --client_unit->curr_connect; -- if (close((client_unit->handlers + i)->fd) < 0) { -- PRINT_ERROR("client can't close the socket! "); -- return PROGRAM_FAULT; -- } -- client_debug_print("client unit", "close", client_unit->ip, client_unit->port, client_unit->debug); -- } else { -- client_unit->send_bytes += client_unit->pktlen; -- client_debug_print("client unit", "send", client_unit->ip, client_unit->port, client_unit->debug); -+ client_debug_print("client unit", "connect", &client_unit->ip, client_unit->port, client_unit->debug); -+ -+ int32_t client_ask_ret = client_process_ask(client_unit->handlers + i, client_unit); -+ if (client_ask_ret != PROGRAM_OK) { -+ return client_ask_ret; - } - } - } -@@ -206,15 +340,97 @@ int32_t client_thread_create_epfd_and_reg(struct ClientUnit *client_unit) - return PROGRAM_OK; - } - -+ -+static int32_t clithd_proc_epevs_epollout(struct epoll_event *curr_epev, struct ClientUnit *client_unit) -+{ -+ int32_t connect_error = 0; -+ socklen_t connect_error_len = sizeof(connect_error); -+ struct ClientHandler *client_handler = (struct ClientHandler *)curr_epev->data.ptr; -+ if (getsockopt(client_handler->fd, SOL_SOCKET, SO_ERROR, (void *)(&connect_error), &connect_error_len) < 0) { -+ PRINT_ERROR("client can't get socket option %d! ", errno); -+ return PROGRAM_FAULT; -+ } -+ if (connect_error < 0) { -+ if (connect_error == ETIMEDOUT) { -+ if (client_thread_retry_connect(client_unit, client_handler) < 0) { -+ return PROGRAM_FAULT; -+ } -+ return PROGRAM_OK; -+ } -+ PRINT_ERROR("client connect error %d! ", connect_error); -+ return PROGRAM_FAULT; -+ } else { -+ ++(client_unit->curr_connect); -+ -+ sockaddr_t server_addr; -+ socklen_t server_addr_len = -+ client_unit->ip.addr_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); -+ if (getpeername(client_handler->fd, (struct sockaddr *)&server_addr, &server_addr_len) < 0) { -+ PRINT_ERROR("client can't socket peername %d! ", errno); -+ return PROGRAM_FAULT; -+ } -+ -+ // sockaddr to ip, port -+ ip_addr_t remote_ip; -+ uint16_t remote_port = ((struct sockaddr_in *)&server_addr)->sin_port; -+ if (((struct sockaddr *)&server_addr)->sa_family == AF_INET) { -+ remote_ip.addr_family = AF_INET; -+ remote_ip.u_addr.ip4 = ((struct sockaddr_in *)&server_addr)->sin_addr; -+ } else if (((struct sockaddr *)&server_addr)->sa_family == AF_INET6) { -+ remote_ip.addr_family = AF_INET6; -+ remote_ip.u_addr.ip6 = ((struct sockaddr_in6 *)&server_addr)->sin6_addr; -+ } -+ -+ client_debug_print("client unit", "connect", &remote_ip, remote_port, client_unit->debug); -+ -+ int32_t client_ask_ret = client_process_ask(client_handler, client_unit); -+ if (client_ask_ret != PROGRAM_OK) { -+ return client_ask_ret; -+ } -+ } -+ return PROGRAM_OK; -+} -+ -+static int32_t clithd_proc_epevs_epollin(struct epoll_event *curr_epev, struct ClientUnit *client_unit) -+{ -+ ip_addr_t *chkans_ip = client_unit->protocol_type_mode == UDP_MULTICAST ? &client_unit->groupip : &client_unit->ip; -+ int32_t client_chkans_ret = client_chkans((struct ClientHandler *)curr_epev->data.ptr, client_unit->pktlen, -+ client_unit->verify, client_unit->api, client_unit->domain, chkans_ip); -+ struct ClientHandler *client_handler = (struct ClientHandler *)curr_epev->data.ptr; -+ int32_t fd = client_handler->fd; -+ if (client_chkans_ret == PROGRAM_FAULT) { -+ --client_unit->curr_connect; -+ struct epoll_event ep_ev; -+ if (epoll_ctl(client_unit->epfd, EPOLL_CTL_DEL, fd, &ep_ev) < 0) { -+ PRINT_ERROR("client can't delete socket '%d' to control epoll %d! ", fd, errno); -+ return PROGRAM_FAULT; -+ } -+ } else if (client_chkans_ret == PROGRAM_ABORT) { -+ --client_unit->curr_connect; -+ if (close(fd) < 0) { -+ PRINT_ERROR("client can't close the socket %d! ", errno); -+ return PROGRAM_FAULT; -+ } -+ client_debug_print("client unit", "close", &client_unit->ip, client_unit->port, client_unit->debug); -+ } else { -+ client_unit->threadVolume.send_bytes += client_unit->pktlen; -+ client_handler->sendtime_interverl = 0; -+ client_debug_print("client unit", "receive", &client_unit->ip, client_unit->port, client_unit->debug); -+ } -+ return PROGRAM_OK; -+} -+ - // the single thread, client processes epoll events - int32_t clithd_proc_epevs(struct ClientUnit *client_unit) - { - int32_t epoll_nfds = epoll_wait(client_unit->epfd, client_unit->epevs, CLIENT_EPOLL_SIZE_MAX, CLIENT_EPOLL_WAIT_TIMEOUT); -+ int ret = 0; - if (epoll_nfds < 0) { - PRINT_ERROR("client epoll wait error %d! ", errno); - return PROGRAM_FAULT; - } - -+ - for (int32_t i = 0; i < epoll_nfds; ++i) { - struct epoll_event *curr_epev = client_unit->epevs + i; - -@@ -222,76 +438,17 @@ int32_t clithd_proc_epevs(struct ClientUnit *client_unit) - PRINT_ERROR("client epoll wait error! %d", curr_epev->events); - return PROGRAM_FAULT; - } else if (curr_epev->events == EPOLLOUT) { -- int32_t connect_error = 0; -- socklen_t connect_error_len = sizeof(connect_error); -- struct ClientHandler *client_handler = (struct ClientHandler *)curr_epev->data.ptr; -- if (getsockopt(client_handler->fd, SOL_SOCKET, SO_ERROR, (void *)(&connect_error), &connect_error_len) < 0) { -- PRINT_ERROR("client can't get socket option %d! ", errno); -- return PROGRAM_FAULT; -- } -- if (connect_error < 0) { -- if (connect_error == ETIMEDOUT) { -- if (client_thread_retry_connect(client_unit, client_handler) < 0) { -- return PROGRAM_FAULT; -- } -- continue; -- } -- PRINT_ERROR("client connect error %d! ", connect_error); -- return PROGRAM_FAULT; -- } else { -- ++(client_unit->curr_connect); -- -- struct sockaddr_in server_addr; -- socklen_t server_addr_len = sizeof(server_addr); -- if (getpeername(client_handler->fd, (struct sockaddr *)&server_addr, &server_addr_len) < 0) { -- PRINT_ERROR("client can't socket peername %d! ", errno); -- return PROGRAM_FAULT; -- } -- client_debug_print("client unit", "connect", server_addr.sin_addr.s_addr, server_addr.sin_port, client_unit->debug); -- -- int32_t client_ask_ret = client_ask(client_handler, client_unit->pktlen, client_unit->api, client_unit->domain, client_unit->groupip ? client_unit->groupip:client_unit->ip, client_unit->port); -- if (client_ask_ret == PROGRAM_FAULT) { -- --client_unit->curr_connect; -- struct epoll_event ep_ev; -- if (epoll_ctl(client_unit->epfd, EPOLL_CTL_DEL, curr_epev->data.fd, &ep_ev) < 0) { -- PRINT_ERROR("client can't delete socket '%d' to control epoll %d! ", curr_epev->data.fd, errno); -- return PROGRAM_FAULT; -- } -- } else if (client_ask_ret == PROGRAM_ABORT) { -- --client_unit->curr_connect; -- if (close(curr_epev->data.fd) < 0) { -- PRINT_ERROR("client can't close the socket! "); -- return PROGRAM_FAULT; -- } -- client_debug_print("client unit", "close", server_addr.sin_addr.s_addr, server_addr.sin_port, client_unit->debug); -- } else { -- client_unit->send_bytes += client_unit->pktlen; -- client_debug_print("client unit", "send", server_addr.sin_addr.s_addr, server_addr.sin_port, client_unit->debug); -- } -+ ret = clithd_proc_epevs_epollout(curr_epev, client_unit); -+ if (ret != PROGRAM_OK) { -+ return ret; - } - } else if (curr_epev->events == EPOLLIN) { -- int32_t client_chkans_ret = client_chkans((struct ClientHandler *)curr_epev->data.ptr, client_unit->pktlen, client_unit->verify, client_unit->api, client_unit->domain, client_unit->groupip ? client_unit->groupip:client_unit->ip); -- if (client_chkans_ret == PROGRAM_FAULT) { -- --client_unit->curr_connect; -- struct epoll_event ep_ev; -- if (epoll_ctl(client_unit->epfd, EPOLL_CTL_DEL, curr_epev->data.fd, &ep_ev) < 0) { -- PRINT_ERROR("client can't delete socket '%d' to control epoll %d! ", curr_epev->data.fd, errno); -- return PROGRAM_FAULT; -- } -- } else if (client_chkans_ret == PROGRAM_ABORT) { -- --client_unit->curr_connect; -- if (close(curr_epev->data.fd) < 0) { -- PRINT_ERROR("client can't close the socket %d! ", errno); -- return PROGRAM_FAULT; -- } -- client_debug_print("client unit", "close", client_unit->ip, client_unit->port, client_unit->debug); -- } else { -- client_unit->send_bytes += client_unit->pktlen; -- client_debug_print("client unit", "receive", client_unit->ip, client_unit->port, client_unit->debug); -+ ret = clithd_proc_epevs_epollin(curr_epev, client_unit); -+ if (ret != PROGRAM_OK) { -+ return ret; - } - } - } -- - return PROGRAM_OK; - } - -@@ -299,6 +456,17 @@ int32_t clithd_proc_epevs(struct ClientUnit *client_unit) - void *client_s_create_and_run(void *arg) - { - struct ClientUnit *client_unit = (struct ClientUnit *)arg; -+ // update domain ip info. -+ client_get_domain_ipversion(client_unit->protocol_type_mode, client_unit); -+ -+ if (client_unit->protocol_type_mode == UDP_MULTICAST) { -+ client_unit->threadVolume.ip_type_info = IPV4_MULTICAST; -+ } else { -+ client_unit->threadVolume.ip_type_info = (client_unit->ip.addr_family == AF_INET ? IPV4_STR : IPV6_STR); -+ } -+ client_unit->threadVolume.thread_id = pthread_self(); -+ -+ client_unit->threadVolume.domain = client_unit->domain; - - if (client_thread_create_epfd_and_reg(client_unit) < 0) { - exit(PROGRAM_FAULT); -@@ -316,6 +484,42 @@ void *client_s_create_and_run(void *arg) - return (void *)PROGRAM_OK; - } - -+// prase the specific supported TCP IP types by cfg_mode. -+static void client_get_protocol_type_by_cfgmode(uint8_t mode, int32_t *support_type_array, int32_t buff_len, -+ int32_t *actual_len) -+{ -+ int32_t index = 0; -+ for (uint8_t i = V4_TCP; i < PROTOCOL_MODE_MAX; i++) { -+ if (i == V6_UDP) { -+ continue; -+ } -+ if (getbit_num(mode, i) == 1) { -+ if (index >= buff_len) { -+ PRINT_ERROR("index is over, index =%d", index); -+ return; -+ } -+ support_type_array[index] = i; -+ index++; -+ } -+ } -+ *actual_len = index; -+} -+ -+static void client_get_domain_ipversion(uint8_t protocol_type, struct ClientUnit *client_unit) -+{ -+ client_unit->domain = g_cfgmode_map[protocol_type].domain; -+ client_unit->ip.addr_family = g_cfgmode_map[protocol_type].ip_family; -+} -+ -+static void alarm_init() -+{ -+ struct sigaction sa; -+ memset(&sa, 0, sizeof(sa)); -+ sa.sa_handler = &timer_handle; -+ sigaction(SIGALRM, &sa, NULL); -+ alarm(TIME_SCAN_INTERVAL); -+} -+ - // create client and run - int32_t client_create_and_run(struct ProgramParams *params) - { -@@ -323,16 +527,44 @@ int32_t client_create_and_run(struct ProgramParams *params) - const uint32_t thread_num = params->thread_num; - pthread_t *tids = (pthread_t *)malloc(thread_num * sizeof(pthread_t)); - struct Client *client = (struct Client *)malloc(sizeof(struct Client)); -+ g_client_begin = client; -+ client->threadNum = thread_num; -+ - struct ClientUnit *client_unit = (struct ClientUnit *)malloc(sizeof(struct ClientUnit)); -+ memset_s(client_unit, sizeof(struct ClientUnit), 0, sizeof(struct ClientUnit)); -+ int32_t protocol_support_array[PROTOCOL_MODE_MAX] = {0}; -+ int32_t number_of_support_type = 1; - - if (pthread_mutex_init(&client_debug_mutex, NULL) < 0) { - PRINT_ERROR("client can't init posix mutex %d! ", errno); - return PROGRAM_FAULT; - } - -+ bool v4_cfg_flag = (strcmp(params->ip, PARAM_DEFAULT_IP) != 0); -+ bool v6_cfg_flag = (strcmp(params->ipv6, PARAM_DEFAULT_IP_V6) != 0); -+ bool multcact_cfg_flag = (strcmp(params->groupip, PARAM_DEFAULT_GROUPIP) != 0); -+ -+ bool mixed_mode_flag = false; -+ if ((strchr(params->domain, ',') != NULL) || (v4_cfg_flag && v6_cfg_flag) || -+ (multcact_cfg_flag && (v4_cfg_flag || v6_cfg_flag))) { -+ mixed_mode_flag = true; -+ } -+ - client->uints = client_unit; - client->debug = params->debug; - -+ uint8_t protocol_type_mode = program_get_protocol_mode_by_domain_ip(params->domain, params->ip, params->ipv6, -+ params->groupip); -+ -+ client_get_protocol_type_by_cfgmode(protocol_type_mode, protocol_support_array, PROTOCOL_MODE_MAX, -+ &number_of_support_type); -+ -+ uint32_t port = UNIX_TCP_PORT_MIN; -+ uint32_t sport = 0; -+ uint32_t sp = 0; -+ -+ alarm_init(); -+ - for (uint32_t i = 0; i < thread_num; ++i) { - client_unit->handlers = (struct ClientHandler *)malloc(connect_num * sizeof(struct ClientHandler)); - for (uint32_t j = 0; j < connect_num; ++j) { -@@ -342,13 +574,42 @@ int32_t client_create_and_run(struct ProgramParams *params) - client_unit->epfd = -1; - client_unit->epevs = (struct epoll_event *)malloc(CLIENT_EPOLL_SIZE_MAX * sizeof(struct epoll_event)); - client_unit->curr_connect = 0; -- client_unit->send_bytes = 0; -- client_unit->ip = inet_addr(params->ip); -- client_unit->groupip = inet_addr(params->groupip); -- client_unit->port = htons(params->port); -- client_unit->sport = htons(params->sport); -+ -+ client_unit->threadVolume.cur_connect_num = 0; -+ client_unit->threadVolume.thread_id = 0; -+ client_unit->threadVolume.send_bytes = 0; -+ client_unit->threadVolume.ip_type_info = INVAILD_STR; -+ client_unit->threadVolume.domain = INVAILD_STR; -+ -+ client_unit->ip.addr_family = params->addr_family; -+ inet_pton(AF_INET, params->ip, &client_unit->ip.u_addr.ip4); -+ inet_pton(AF_INET6, params->ipv6, &client_unit->ip.u_addr.ip6); -+ client_unit->groupip.addr_family = AF_INET; -+ inet_pton(AF_INET, params->groupip, &client_unit->groupip.u_addr); -+ client_unit->groupip_interface.addr_family = params->addr_family; -+ inet_pton(AF_INET, params->groupip_interface, &client_unit->groupip_interface.u_addr); -+ -+ /* loop to set ports to each client_units */ -+ while (!((params->port)[port])) { -+ port = (port + 1) % UNIX_TCP_PORT_MAX; -+ } -+ client_unit->port = htons(port++); -+ -+ sp = sport; -+ sport++; -+ while (!((params->sport)[sport]) && (sport != sp)) { -+ sport = (sport + 1) % UNIX_TCP_PORT_MAX; -+ } -+ -+ client_unit->sport = htons(sport); - client_unit->connect_num = params->connect_num; - client_unit->pktlen = params->pktlen; -+ if (strcmp(params->as, "loop") == 0) { -+ client_unit->loop = 1; -+ } else { -+ client_unit->loop = 0; -+ } -+ - client_unit->verify = params->verify; - client_unit->domain = params->domain; - client_unit->api = params->api; -@@ -357,6 +618,16 @@ int32_t client_create_and_run(struct ProgramParams *params) - client_unit->next = (struct ClientUnit *)malloc(sizeof(struct ClientUnit)); - memset_s(client_unit->next, sizeof(struct ClientUnit), 0, sizeof(struct ClientUnit)); - -+ if (number_of_support_type > 0) { -+ int32_t index = i % number_of_support_type; -+ client_unit->protocol_type_mode = protocol_support_array[index]; -+ } -+ if (client_unit->protocol_type_mode == V4_UDP || client_unit->protocol_type_mode == V6_UDP || -+ client_unit->protocol_type_mode == UDP_MULTICAST) { -+ client_unit->pktlen = params->pktlen > UDP_PKTLEN_MAX ? UDP_PKTLEN_MAX : params->pktlen; -+ } else { -+ client_unit->pktlen = params->pktlen; -+ } - if (pthread_create((tids + i), NULL, client_s_create_and_run, client_unit) < 0) { - PRINT_ERROR("client can't create thread of poisx %d! ", errno); - return PROGRAM_FAULT; -@@ -367,9 +638,34 @@ int32_t client_create_and_run(struct ProgramParams *params) - if (client->debug == false) { - printf("[program informations]: \n\n"); - } -+ -+ struct ThreadUintInfo *beginVolume = (struct ThreadUintInfo *)malloc(thread_num * sizeof(struct ThreadUintInfo)); -+ if (beginVolume == NULL) { -+ return PROGRAM_FAULT; -+ } -+ memset_s(beginVolume, thread_num * sizeof(struct ThreadUintInfo), 0, thread_num * sizeof(struct ThreadUintInfo)); -+ struct ThreadUintInfo *endVolume = (struct ThreadUintInfo *)malloc(thread_num * sizeof(struct ThreadUintInfo)); -+ if (endVolume == NULL) { -+ return PROGRAM_FAULT; -+ } -+ memset_s(endVolume, thread_num * sizeof(struct ThreadUintInfo), 0, thread_num * sizeof(struct ThreadUintInfo)); -+ -+ if (strcmp(params->as, "loop") == 0) { -+ client->loop = true; -+ } -+ - while (true) { -- client_info_print(client); -+ if (strcmp(params->as, "loop") == 0) { -+ loop_info_print(); -+ } -+ if (mixed_mode_flag == true) { -+ client_info_print_mixed(client, beginVolume, endVolume); -+ } else { -+ client_info_print(client); -+ } - } -+ free(beginVolume); -+ free(endVolume); - - pthread_mutex_destroy(&client_debug_mutex); - -diff --git a/examples/src/parameter.c b/examples/src/parameter.c -index 1bb6858..7f519e7 100644 ---- a/examples/src/parameter.c -+++ b/examples/src/parameter.c -@@ -13,6 +13,8 @@ - - #include "parameter.h" - -+static int32_t g_inject_delay[INJECT_DELAY_MAX] = {0}; -+static int32_t g_inject_skip[INJECT_SKIP_MAX]; - - // program short options - const char prog_short_opts[] = \ -@@ -30,9 +32,11 @@ const char prog_short_opts[] = \ - "r" // ringpmd - "d" // debug - "h" // help -- "E" // epollcreate -- "C" // accept -+ "E:" // epollcreate -+ "C:" // accept - "g:" // group address -+ "k:" // tcp keep_alive -+ "I:" // fault inject - ; - - // program long options -@@ -55,17 +59,72 @@ const struct ProgramOption prog_long_opts[] = \ - {PARAM_NAME_EPOLLCREATE, REQUIRED_ARGUMETN, NULL, PARAM_NUM_EPOLLCREATE}, - {PARAM_NAME_ACCEPT, REQUIRED_ARGUMETN, NULL, PARAM_NUM_ACCEPT}, - {PARAM_NAME_GROUPIP, REQUIRED_ARGUMETN, NULL, PARAM_NUM_GROUPIP}, -+ {PARAM_NAME_KEEPALIVE, REQUIRED_ARGUMETN, NULL, PARAM_NUM_KEEPALIVE}, -+ {PARAM_NAME_INJECT, REQUIRED_ARGUMETN, NULL, PARAM_NUM_INJECT}, - }; - - - // get long options - int getopt_long(int argc, char * const argv[], const char *optstring, const struct ProgramOption *long_opts, int *long_idx); -+// index [0,7) -+uint8_t getbit_num(uint8_t mode, uint8_t index) -+{ -+ return (mode & ((uint8_t)1 << index)) != 0; -+} -+ -+uint8_t setbitnum_on(uint8_t mode, uint8_t index) -+{ -+ mode |= ((uint8_t)1 << index); -+ return mode; -+} -+ -+uint8_t setbitnum_off(uint8_t mode, uint8_t index) -+{ -+ mode &= ~((uint8_t)1 << index); -+ return mode; -+} -+ -+static uint8_t program_set_protocol_mode(uint8_t protocol_mode, char *ipv4, char *ipv6, uint8_t index_v4, -+ uint8_t index_v6) -+{ -+ uint8_t protocol_mode_temp = protocol_mode; -+ if (strcmp(ipv4, PARAM_DEFAULT_IP) != 0) { -+ protocol_mode_temp = setbitnum_on(protocol_mode_temp, index_v4); -+ } -+ if (strcmp(ipv6, PARAM_DEFAULT_IP_V6) != 0) { -+ protocol_mode_temp = setbitnum_on(protocol_mode_temp, index_v6); -+ } -+ return protocol_mode_temp; -+} -+ -+uint8_t program_get_protocol_mode_by_domain_ip(char* domain, char* ipv4, char* ipv6, char* groupip) -+{ -+ uint8_t protocol_mode = 0; -+ char *cur_ptr = NULL; -+ char *next_Ptr = NULL; -+ cur_ptr = strtok_s(domain, ",", &next_Ptr); -+ while (cur_ptr) { -+ if (strcmp(cur_ptr, "tcp") == 0) { -+ protocol_mode = program_set_protocol_mode(protocol_mode, ipv4, ipv6, V4_TCP, V6_TCP); -+ } else if (strcmp(cur_ptr, "udp") == 0) { -+ protocol_mode = program_set_protocol_mode(protocol_mode, ipv4, ipv6, V4_UDP, V6_UDP); -+ } else if (strcmp(cur_ptr, "unix") == 0) { -+ protocol_mode = setbitnum_on(protocol_mode, UNIX); -+ } -+ cur_ptr = strtok_s(NULL, ",", &next_Ptr); -+ } -+ -+ if (strcmp(groupip, PARAM_DEFAULT_GROUPIP) != 0) { -+ protocol_mode = setbitnum_on(protocol_mode, UDP_MULTICAST); -+ } - -+ return protocol_mode; -+} - - // set `as` parameter - void program_param_parse_as(struct ProgramParams *params) - { -- if (strcmp(optarg, "server") == 0 || strcmp(optarg, "client") == 0) { -+ if (strcmp(optarg, "server") == 0 || strcmp(optarg, "client") == 0 || strcmp(optarg, "loop") == 0) { - params->as = optarg; - } else { - PRINT_ERROR("illigal argument -- %s \n", optarg); -@@ -73,40 +132,113 @@ void program_param_parse_as(struct ProgramParams *params) - } - } - --// set `ip` parameter --void program_param_parse_ip(struct ProgramParams *params) -+bool ip_is_v6(const char *cp) -+{ -+ if (cp != NULL) { -+ const char *c; -+ for (c = cp; *c != 0; c++) { -+ if (*c == ':') { -+ return 1; -+ } -+ } -+ } -+ return 0; -+} -+ -+ -+static bool program_ipv4_check(char *ipv4) - { -- if (inet_addr(optarg) != INADDR_NONE) { -- params->ip = optarg; -+ in_addr_t ip = ntohl(inet_addr(ipv4)); -+ if (ip == INADDR_NONE) { -+ PRINT_ERROR("illigal argument -- %s \n", ipv4); -+ return false; -+ } -+ if ((ip >= ntohl(inet_addr("1.0.0.1")) && ip <= ntohl(inet_addr("126.255.255.254"))) || -+ (ip >= ntohl(inet_addr("127.0.0.1")) && ip <= ntohl(inet_addr("127.255.255.254"))) || -+ (ip >= ntohl(inet_addr("128.0.0.1")) && ip <= ntohl(inet_addr("191.255.255.254"))) || -+ (ip >= ntohl(inet_addr("192.0.0.1")) && ip <= ntohl(inet_addr("223.255.255.254"))) || -+ (ip >= ntohl(inet_addr("224.0.0.1")) && ip <= ntohl(inet_addr("224.255.255.255"))) ) { // Broadcast IP -+ return true; -+ } -+ -+ PRINT_ERROR("illigal argument -- %s \n", ipv4); -+ return false; -+} -+ -+static void program_param_parse_ipv4_addr(char* v4ip_addr, struct ProgramParams *params) -+{ -+ struct in6_addr ip_tmp; -+ params->addr_family = AF_INET; -+ if (inet_pton(params->addr_family, v4ip_addr, &ip_tmp) > 0 && program_ipv4_check(v4ip_addr) == true) { -+ params->ip = v4ip_addr; - } else { -- PRINT_ERROR("illigal argument -- %s \n", optarg); -+ PRINT_ERROR("illegal ipv4 addr -- %s \n", v4ip_addr); - exit(PROGRAM_ABORT); - } - } - --// set `port` parameter --void program_param_parse_port(struct ProgramParams *params) -+static void program_param_parse_ipv6_addr(char* v6ip_add, struct ProgramParams *params) - { -- int32_t port_arg = strtol(optarg, NULL, 0); -- printf("%d\n", port_arg); -- if (CHECK_VAL_RANGE(port_arg, UNIX_TCP_PORT_MIN, UNIX_TCP_PORT_MAX) == true) { -- params->port = (uint32_t)port_arg; -+ struct in6_addr ip_tmp; -+ params->addr_family = AF_INET6; -+ if (inet_pton(AF_INET6, v6ip_add, &ip_tmp) > 0) { -+ params->ipv6 = v6ip_add; - } else { -- PRINT_ERROR("illigal argument -- %s \n", optarg); -+ PRINT_ERROR("illegal ipv6 addr -- %s \n", v6ip_add); - exit(PROGRAM_ABORT); - } - } -+// set `ip` parameter,支持同时配置 ipv4 和 ipv6 地址,格式为 ipv4,ipv6 -+void program_param_parse_ip(struct ProgramParams *params) -+{ -+ char *cur_ptr = NULL; -+ char *next_ptr = NULL; -+ -+ cur_ptr = strtok_s(optarg, ",", &next_ptr); -+ while (cur_ptr) { -+ if (ip_is_v6(cur_ptr)) { -+ program_param_parse_ipv6_addr(cur_ptr, params); -+ } else { -+ program_param_parse_ipv4_addr(cur_ptr, params); -+ } -+ cur_ptr = strtok_s(NULL, ",", &next_ptr); -+ } -+} -+ -+// set `port` parameter -+void program_param_parse_port(struct ProgramParams *params) -+{ -+ char* port_list = optarg; -+ char* token = NULL; -+ int32_t port_arg = 0; -+ params->port[PARAM_DEFAULT_PORT] = 0; -+ -+ while ((token = strtok_r(port_list, ",", &port_list))) { -+ port_arg = strtol(token, NULL, 0); -+ if (CHECK_VAL_RANGE(port_arg, UNIX_TCP_PORT_MIN, UNIX_TCP_PORT_MAX) == true) { -+ params->port[port_arg] = 1; -+ } else { -+ PRINT_ERROR("illigal argument -- %s \n", optarg); -+ exit(PROGRAM_ABORT); -+ } -+ } -+} - - // set `sport` parameter - void program_param_parse_sport(struct ProgramParams *params) - { -- int32_t sport_arg = strtol(optarg, NULL, 0); -- printf("%d\n", sport_arg); -- if (CHECK_VAL_RANGE(sport_arg, UNIX_TCP_PORT_MIN, UNIX_TCP_PORT_MAX) == true) { -- params->sport = (uint32_t)sport_arg; -- } else { -- PRINT_ERROR("illigal argument -- %s \n", optarg); -- exit(PROGRAM_ABORT); -+ char* port_list = optarg; -+ char* token = NULL; -+ int32_t port_arg = 0; -+ -+ while ((token = strtok_r(port_list, ",", &port_list))) { -+ port_arg = strtol(token, NULL, 0); -+ if (CHECK_VAL_RANGE(port_arg, UNIX_TCP_PORT_MIN, UNIX_TCP_PORT_MAX) == true) { -+ params->sport[port_arg] = 1; -+ } else { -+ PRINT_ERROR("illigal argument -- %s \n", optarg); -+ exit(PROGRAM_ABORT); -+ } - } - } - -@@ -148,12 +280,23 @@ void program_param_parse_threadnum(struct ProgramParams *params) - // set `domain` parameter - void program_param_parse_domain(struct ProgramParams *params) - { -- if (strcmp(optarg, "unix") == 0 || strcmp(optarg, "tcp") == 0 || strcmp(optarg, "udp") == 0) { -- params->domain = optarg; -- } else { -- PRINT_ERROR("illigal argument -- %s \n", optarg); -+ char temp[100] = {0}; -+ int32_t ret = strcpy_s(temp, sizeof(temp) / sizeof(char), optarg); -+ if (ret != 0) { -+ PRINT_ERROR("strcpy_s fail ret=%d \n", ret); - exit(PROGRAM_ABORT); - } -+ char *cur_ptr = temp; -+ char *next_ptr = NULL; -+ cur_ptr = strtok_s(cur_ptr, ",", &next_ptr); -+ while (cur_ptr) { -+ if (strcmp(cur_ptr, "tcp") != 0 && strcmp(cur_ptr, "udp") != 0 && strcmp(cur_ptr, "unix") != 0) { -+ PRINT_ERROR("illigal argument -- %s \n", cur_ptr); -+ exit(PROGRAM_ABORT); -+ } -+ cur_ptr = strtok_s(NULL, ",", &next_ptr); -+ } -+ params->domain = optarg; - } - - // set `api` parameter -@@ -174,6 +317,9 @@ void program_param_parse_pktlen(struct ProgramParams *params) - int32_t pktlen_arg = strtol(optarg, NULL, 0); - if (CHECK_VAL_RANGE(pktlen_arg, MESSAGE_PKTLEN_MIN, MESSAGE_PKTLEN_MAX) == true) { - params->pktlen = (uint32_t)pktlen_arg; -+ if (strstr(params->domain, "udp") && params->pktlen > UDP_PKTLEN_MAX) { -+ PRINT_WARNNING("udp message too long, change it to %d \n", UDP_PKTLEN_MAX); -+ } - } else { - PRINT_ERROR("illigal argument -- %s \n", optarg); - exit(PROGRAM_ABORT); -@@ -202,16 +348,196 @@ void program_param_parse_accept(struct ProgramParams *params) - } - } - -+// set `tcp_keepalive_idle` parameter -+void program_param_parse_keepalive(struct ProgramParams *params) -+{ -+ char *token = NULL; -+ char *next_token = NULL; -+ token = strtok_s(optarg, ",", &next_token); -+ if (token == NULL) { -+ PRINT_ERROR("parse keep_alive idle null, illigal argument(%s) \n", optarg); -+ exit(PROGRAM_ABORT); -+ } -+ -+ int32_t keep_alive_idle = strtol(optarg, NULL, 0); -+ if (keep_alive_idle > 0 && keep_alive_idle <= TCP_KEEPALIVE_IDLE_MAX) { -+ params->tcp_keepalive_idle = keep_alive_idle; -+ } else { -+ PRINT_ERROR("keep_alive_idle=%d,illigal argument -- %s \n", keep_alive_idle, optarg); -+ exit(PROGRAM_ABORT); -+ } -+ -+ token = strtok_s(NULL, ",", &next_token); -+ if (token == NULL) { -+ PRINT_ERROR("parse keep_alive interval null, illigal argument(%s) \n", optarg); -+ exit(PROGRAM_ABORT); -+ } -+ int32_t keep_alive_interval = strtol(token, NULL, 0); -+ if (keep_alive_interval > 0 && keep_alive_interval <= TCP_KEEPALIVE_IDLE_MAX) { -+ params->tcp_keepalive_interval = keep_alive_interval; -+ } else { -+ PRINT_ERROR("keep_alive_interval=%d,illigal argument -- %s \n", keep_alive_interval, optarg); -+ exit(PROGRAM_ABORT); -+ } -+} -+ - // set `group ip` parameter - void program_param_parse_groupip(struct ProgramParams *params) - { -- in_addr_t ip = inet_addr(optarg); -- if (ip != INADDR_NONE && ip >= inet_addr("224.0.0.0") && ip <= inet_addr("239.255.255.255")) { -- params->groupip = optarg; -+ char *cur_ptr = NULL; -+ char *next_ptr = NULL; -+ -+ cur_ptr = strtok_s(optarg, ",", &next_ptr); -+ if (program_ipv4_check(cur_ptr) == false) { -+ PRINT_ERROR("illigal argument -- %s \n", cur_ptr); -+ exit(PROGRAM_ABORT); -+ } -+ -+ in_addr_t ip = ntohl(inet_addr(cur_ptr)); -+ if (ip != INADDR_NONE && ip >= ntohl(inet_addr("224.0.0.0")) && ip <= ntohl(inet_addr("239.255.255.255"))) { -+ params->groupip = cur_ptr; - } else { -- PRINT_ERROR("illigal argument -- %s \n", optarg); -+ PRINT_ERROR("illigal argument -- %s \n", cur_ptr); -+ exit(PROGRAM_ABORT); -+ } -+ -+ if (*next_ptr) { -+ if (program_ipv4_check(next_ptr)) { -+ params->groupip_interface = next_ptr; -+ } else { -+ PRINT_ERROR("illigal argument -- %s \n", next_ptr); -+ exit(PROGRAM_ABORT); -+ } -+ } -+} -+ -+void fault_inject_delay(delay_type type) -+{ -+ if (g_inject_delay[type]) { -+ printf("FAULT INJECT: Delay begin, sleep %d seconds.\n", g_inject_delay[type]); -+ sleep(g_inject_delay[type]); -+ g_inject_delay[type] = 0; -+ printf("FAULT INJECT: Delay finished.\n"); -+ } -+} -+ -+ -+// apply fault inject type of delay -+static void delay_param_parse(struct ProgramParams *params) -+{ -+ int32_t time = 0; -+ if (params->inject[INJECT_TIME_IDX] != NULL) { -+ time = atoi(params->inject[INJECT_TIME_IDX]); -+ } -+ if (time <= 0) { -+ PRINT_ERROR("FAULT INJECT: delay time input error! receive: \"%s\"\n", params->inject[INJECT_TIME_IDX]); -+ exit(PROGRAM_ABORT); -+ } -+ -+ char *location = params->inject[INJECT_LOCATION_IDX]; -+ if (location == NULL) { -+ PRINT_ERROR("FAULT INJECT: Lack param for delay fault inject, The location is not appointed.\n"); - exit(PROGRAM_ABORT); - } -+ -+ if (strcmp("before_accept", location) == 0) { -+ g_inject_delay[INJECT_DELAY_ACCEPT] = time; -+ return; -+ } -+ if (strcmp("before_read", location) == 0) { -+ g_inject_delay[INJECT_DELAY_READ] = time; -+ return; -+ } -+ if (strcmp("before_write", location) == 0) { -+ g_inject_delay[INJECT_DELAY_WRITE] = time; -+ return; -+ } -+ if (strcmp("before_read_and_write", location) == 0) { -+ g_inject_delay[INJECT_DELAY_READ] = time; -+ g_inject_delay[INJECT_DELAY_WRITE] = time; -+ return; -+ } -+ -+ PRINT_ERROR("FAULT INJECT: Unidentified fault inject location -- %s \n", location); -+ exit(PROGRAM_ABORT); -+} -+ -+// apply fault inject type of skip -+static void skip_param_parse(struct ProgramParams *params) -+{ -+ char* location = params->inject[INJECT_SKIP_IDX]; -+ if (location == NULL) { -+ PRINT_ERROR("FAULT INJECT: Lack param for skip fault inject, location is not appointed.\n"); -+ exit(PROGRAM_ABORT); -+ } -+ -+ if (strcmp("read", location) == 0) { -+ g_inject_skip[INJECT_SKIP_READ] = 1; -+ return; -+ } -+ if (strcmp("write", location) == 0) { -+ g_inject_skip[INJECT_SKIP_WRITE] = 1; -+ return; -+ } -+ if (strcmp("read_and_write", location) == 0) { -+ g_inject_skip[INJECT_SKIP_READ] = 1; -+ g_inject_skip[INJECT_SKIP_WRITE] = 1; -+ return; -+ } -+ -+ PRINT_ERROR("FAULT INJECT: Unidentified fault inject location -- %s \n", location); -+ exit(PROGRAM_ABORT); -+} -+ -+// judge if need skip fault inject -+int32_t get_g_inject_skip(skip_type type) -+{ -+ return g_inject_skip[type]; -+} -+ -+// check legitimacy of fault injection and apply it. -+static void apply_fault_inject(struct ProgramParams *params) -+{ -+ char *inject_type = params->inject[INJECT_TYPE_IDX]; -+ if (strcmp("delay", inject_type) == 0) { -+ delay_param_parse(params); -+ return; -+ } -+ if (strcmp("skip", inject_type) == 0) { -+ skip_param_parse(params); -+ return; -+ } -+ -+ PRINT_ERROR("FAULT INJCET: Unidentified fault inject -- %s \n", inject_type); -+ exit(PROGRAM_ABORT); -+} -+ -+// set `fault injection` parameter -+static void program_param_parse_inject(struct ProgramParams *params) -+{ -+ int32_t inject_idx = 0; -+ char *inject_input = strdup(optarg); -+ if (inject_input == NULL) { -+ PRINT_ERROR("FAULT INJCET: Insufficient memory, strdup failed.\n"); -+ exit(PROGRAM_ABORT); -+ } -+ -+ char *context = NULL; -+ char *elem = strtok_s(inject_input, " ", &context); -+ if (elem == NULL) { -+ PRINT_ERROR("FAULT INJECT: Input error. -- %s \n", inject_input); -+ exit(PROGRAM_ABORT); -+ } -+ while (elem != NULL) { -+ if (inject_idx == FAULT_INJECT_PARA_COUNT) { -+ PRINT_ERROR("FAULT INJECT: Exceed the max count (3) of fault inject params. -- %s\n", optarg); -+ exit(PROGRAM_ABORT); -+ } -+ params->inject[inject_idx++] = elem; -+ elem = strtok_s(NULL, " ", &context); -+ } -+ -+ apply_fault_inject(params); - } - - // initialize the parameters -@@ -219,8 +545,11 @@ void program_params_init(struct ProgramParams *params) - { - params->as = PARAM_DEFAULT_AS; - params->ip = PARAM_DEFAULT_IP; -- params->port = PARAM_DEFAULT_PORT; -- params->sport = PARAM_DEFAULT_SPORT; -+ params->ipv6 = PARAM_DEFAULT_IP_V6; -+ params->addr_family = PARAM_DEFAULT_ADDR_FAMILY; -+ memset_s(params->port, sizeof(bool)*UNIX_TCP_PORT_MAX, 0, sizeof(bool)*UNIX_TCP_PORT_MAX); -+ memset_s(params->sport, sizeof(bool)*UNIX_TCP_PORT_MAX, 0, sizeof(bool)*UNIX_TCP_PORT_MAX); -+ (params->port)[PARAM_DEFAULT_PORT] = 1; - params->model = PARAM_DEFAULT_MODEL; - params->thread_num = PARAM_DEFAULT_THREAD_NUM; - params->connect_num = PARAM_DEFAULT_CONNECT_NUM; -@@ -233,15 +562,19 @@ void program_params_init(struct ProgramParams *params) - params->epollcreate = PARAM_DEFAULT_EPOLLCREATE; - params->accept = PARAM_DEFAULT_ACCEPT; - params->groupip = PARAM_DEFAULT_GROUPIP; -+ params->groupip_interface = PARAM_DEFAULT_GROUPIP; -+ params->tcp_keepalive_idle = PARAM_DEFAULT_KEEPALIVEIDLE; -+ params->tcp_keepalive_interval = PARAM_DEFAULT_KEEPALIVEIDLE; - } - - // print program helps - void program_params_help(void) - { - printf("\n"); -- printf("-a, --as [server | client]: set programas server or client. \n"); -+ printf("-a, --as [server | client | loop]: set programas server, client or loop. \n"); - printf(" server: as server. \n"); - printf(" client: as client. \n"); -+ printf(" loop: as server and client. \n"); - printf("-i, --ip [???.???.???.???]: set ip address. \n"); - printf("-g, --groupip [???.???.???.???]: set group ip address. \n"); - printf("-p, --port [????]: set port number in range of %d - %d. \n", UNIX_TCP_PORT_MIN, UNIX_TCP_PORT_MAX); -@@ -268,6 +601,16 @@ void program_params_help(void) - printf("-h, --help: see helps. \n"); - printf("-E, --epollcreate [ec | ec1]: epoll_create method. \n"); - printf("-C, --accept [ac | ac4]: accept method. \n"); -+ printf("-k, --keep_alive [keep_alive_idle:keep_alive_interval]: set tcp-alive info in range of %d-%d. \n", -+ PARAM_DEFAULT_KEEPALIVEIDLE, TCP_KEEPALIVE_IDLE_MAX); -+ printf("-I, --inject [\"fault_inject_param0 fault_inject_param1 fault_inject_param2\"]: fault inject\n"); -+ printf(" for example: \"delay 20 before_accept\"\n"); -+ printf(" \"delay 20 before_read\"\n"); -+ printf(" \"delay 20 before_write\"\n"); -+ printf(" \"delay 20 before_read_and_write\"\n"); -+ printf(" \"skip read\"\n"); -+ printf(" \"skip write\"\n"); -+ printf(" \"skip read_and_write\"\n"); - printf("\n"); - } - -@@ -295,7 +638,7 @@ int32_t program_params_parse(struct ProgramParams *params, uint32_t argc, char * - case (PARAM_NUM_PORT): - program_param_parse_port(params); - break; -- case (PARAM_NUM_SPORT): -+ case (PARAM_NUM_SPORT): - program_param_parse_sport(params); - break; - case (PARAM_NUM_MODEL): -@@ -331,9 +674,15 @@ int32_t program_params_parse(struct ProgramParams *params, uint32_t argc, char * - case (PARAM_NUM_ACCEPT): - program_param_parse_accept(params); - break; -- case (PARAM_NUM_GROUPIP): -- program_param_parse_groupip(params); -- break; -+ case (PARAM_NUM_GROUPIP): -+ program_param_parse_groupip(params); -+ break; -+ case (PARAM_NUM_KEEPALIVE): -+ program_param_parse_keepalive(params); -+ break; -+ case (PARAM_NUM_INJECT): -+ program_param_parse_inject(params); -+ break; - case (PARAM_NUM_HELP): - program_params_help(); - return PROGRAM_ABORT; -@@ -345,11 +694,6 @@ int32_t program_params_parse(struct ProgramParams *params, uint32_t argc, char * - } - } - -- if (strcmp(params->domain, "tcp") != 0) { -- params->thread_num = 1; -- params->connect_num = 1; -- } -- - return PROGRAM_OK; - } - -@@ -361,22 +705,47 @@ void program_params_print(struct ProgramParams *params) - printf("--> [as]: %s \n", params->as); - if (strcmp(params->groupip, PARAM_DEFAULT_GROUPIP) != 0) { - if (strcmp(params->as, "server") == 0) { -- printf("--> [server ip]: %s \n", params->ip); - printf("--> [server group ip]: %s \n", params->groupip); -+ printf("--> [server groupip_interface]: %s \n", params->groupip_interface); - } else { -- printf("--> [server ip]: %s \n", params->groupip); -- printf("--> [client send ip]: %s \n", params->ip); -+ printf("--> [client group ip]: %s \n", params->groupip); -+ printf("--> [client groupip_interface]: %s \n", params->groupip_interface); - } -- } else { -- printf("--> [server ip]: %s \n", params->ip); - } -- if ((strcmp(params->as, "server") == 0 && strcmp(params->groupip, PARAM_DEFAULT_GROUPIP)) != 0) { -- printf("--> [server group ip]: %s \n", params->groupip); -+ printf("--> [server ip]: %s \n", params->ip); -+ if (strcmp(params->ipv6, PARAM_DEFAULT_IP_V6) != 0) { -+ printf("--> [server ipv6]: %s \n", params->ipv6); -+ } -+ -+ printf("--> [server port]: "); -+ uint32_t comma = 0; -+ uint32_t sport = 0; -+ -+ /* use comma to print port list */ -+ for (uint32_t i = UNIX_TCP_PORT_MIN; i < UNIX_TCP_PORT_MAX; i++) { -+ if ((params->port)[i]) { -+ printf("%s%u", comma?",":"", i); -+ comma = 1; -+ } -+ if ((params->sport)[i]) { -+ sport = i; -+ } - } -- printf("--> [server port]: %u \n", params->port); -- if (params->sport && strcmp(params->as, "client") == 0) { -- printf("--> [client sport]: %u \n", params->sport); -+ printf(" \n"); -+ -+ /* use comma to print sport list */ -+ if (sport && strcmp(params->as, "client") == 0) { -+ printf("--> [client sport]: "); -+ comma = 0; -+ for (uint32_t i = UNIX_TCP_PORT_MIN; i < sport + 1; i++) { -+ if ((params->sport)[i]) { -+ printf("%s%u", comma?",":"", i); -+ comma = 1; -+ } -+ } -+ printf(" \n"); - } -+ - if (strcmp(params->as, "server") == 0) { - printf("--> [model]: %s \n", params->model); - } -@@ -404,5 +773,16 @@ void program_params_print(struct ProgramParams *params) - printf("--> [debug]: %s \n", (params->debug == true) ? "on" : "off"); - printf("--> [epoll create]: %s \n", params->epollcreate); - printf("--> [accept]: %s \n", params->accept); -+ printf("--> [inject]: "); -+ if (params->inject[INJECT_TYPE_IDX] == NULL) { -+ printf("none \n"); -+ } else { -+ for (int32_t i = 0; i < FAULT_INJECT_PARA_COUNT; ++i) { -+ if (params->inject[i] != NULL) { -+ printf("%s ", params->inject[i]); -+ } -+ } -+ printf("\n"); -+ } - printf("\n"); - } -diff --git a/examples/src/server.c b/examples/src/server.c -index 8634dde..7bc7d9e 100644 ---- a/examples/src/server.c -+++ b/examples/src/server.c -@@ -14,20 +14,22 @@ - #include "server.h" - - static pthread_mutex_t server_debug_mutex; // the server mutex for debug -+struct LoopInfo loopmod; - - // server debug information print --void server_debug_print(const char *ch_str, const char *act_str, in_addr_t ip, uint16_t port, bool debug) -+void server_debug_print(const char *ch_str, const char *act_str, ip_addr_t *ip, uint16_t port, bool debug) - { - if (debug == true) { - pthread_mutex_lock(&server_debug_mutex); -- struct in_addr sin_addr; -- sin_addr.s_addr = ip; -+ uint8_t str_len = ip->addr_family == AF_INET ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN; -+ char str_ip[str_len]; -+ inet_ntop(ip->addr_family, &ip->u_addr, str_ip, str_len); - PRINT_SERVER("[%s] [pid: %d] [tid: %ld] [%s <- %s:%d]. ", \ - ch_str, \ - getpid(), \ - pthread_self(), \ - act_str, \ -- inet_ntoa(sin_addr), \ -+ str_ip, \ - ntohs(port)); - pthread_mutex_unlock(&server_debug_mutex); - } -@@ -37,7 +39,7 @@ void server_debug_print(const char *ch_str, const char *act_str, in_addr_t ip, u - void sermud_info_print(struct ServerMud *server_mud) - { - if (server_mud->debug == false) { -- uint32_t curr_connect = server_mud->curr_connect; -+ uint32_t curr_connect = 0; - - struct timeval begin; - gettimeofday(&begin, NULL); -@@ -48,6 +50,7 @@ void sermud_info_print(struct ServerMud *server_mud) - struct ServerMudWorker *begin_uint = server_mud->workers; - while (begin_uint != NULL) { - begin_recv_bytes += begin_uint->recv_bytes; -+ curr_connect += begin_uint->curr_connect; - begin_uint = begin_uint->next; - } - -@@ -122,45 +125,82 @@ int32_t sermud_listener_create_epfd_and_reg(struct ServerMud *server_mud) - } - - struct epoll_event ep_ev; -- ep_ev.data.ptr = (void *)&(server_mud->listener); - ep_ev.events = EPOLLIN | EPOLLET; -- if (epoll_ctl(server_mud->epfd, EPOLL_CTL_ADD, server_mud->listener.fd, &ep_ev) < 0) { -- PRINT_ERROR("server can't control epoll %d! ", errno); -- return PROGRAM_FAULT; -+ for (int i = 0; i < PROTOCOL_MODE_MAX; i++) { -+ if (server_mud->listener.listen_fd_array[i] != -1) { -+ struct ServerHandler *server_handler = (struct ServerHandler *)malloc(sizeof(struct ServerHandler)); -+ memset_s(server_handler, sizeof(struct ServerHandler), 0, sizeof(struct ServerHandler)); -+ server_handler->fd = server_mud->listener.listen_fd_array[i]; -+ ep_ev.data.ptr = (void *)server_handler; -+ if (epoll_ctl(server_mud->epfd, EPOLL_CTL_ADD, server_mud->listener.listen_fd_array[i], &ep_ev) < 0) { -+ PRINT_ERROR("epoll_ctl failed %d! listen_fd=%d ", errno, server_mud->listener.listen_fd_array[i]); -+ return PROGRAM_FAULT; -+ } -+ } -+ } -+ -+ return PROGRAM_OK; -+} -+ -+static void sermud_accept_get_remote_ip(sockaddr_t *accept_addr, ip_addr_t *remote_ip, bool is_tcp_v6_flag) -+{ -+ remote_ip->addr_family = is_tcp_v6_flag ? AF_INET6 : AF_INET; -+ if (is_tcp_v6_flag == false) { -+ remote_ip->u_addr.ip4 = ((struct sockaddr_in *)accept_addr)->sin_addr; -+ } else { -+ remote_ip->u_addr.ip6 = ((struct sockaddr_in6 *)accept_addr)->sin6_addr; - } -+} - -- server_debug_print("server mud listener", "waiting", server_mud->ip, server_mud->port, server_mud->debug); -+int32_t sermud_set_socket_opt(int32_t accept_fd, struct ServerMud *server_mud) -+{ -+ if (set_tcp_keep_alive_info(accept_fd, server_mud->tcp_keepalive_idle, server_mud->tcp_keepalive_interval) < 0) { -+ PRINT_ERROR("cant't set_tcp_keep_alive_info! "); -+ return PROGRAM_FAULT; -+ } - -+ if (set_socket_unblock(accept_fd) < 0) { -+ PRINT_ERROR("server can't set the connect socket to unblock! "); -+ return PROGRAM_FAULT; -+ } - return PROGRAM_OK; - } - - // the listener thread, unblock, dissymmetric server accepts the connections --int32_t sermud_listener_accept_connects(struct ServerMud *server_mud) -+int32_t sermud_listener_accept_connects(struct epoll_event *curr_epev, struct ServerMud *server_mud) - { -+ int32_t fd = ((struct ServerHandler*)(curr_epev->data.ptr))->fd; -+ fault_inject_delay(INJECT_DELAY_ACCEPT); -+ - while (true) { -- struct sockaddr_in accept_addr; -- uint32_t sockaddr_in_len = sizeof(struct sockaddr_in); -+ sockaddr_t accept_addr; -+ bool is_tcp_v6_flag = (fd == server_mud->listener.listen_fd_array[V6_TCP]) ? true : false; -+ -+ uint32_t sockaddr_in_len = is_tcp_v6_flag ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in); -+ - int32_t accept_fd; -- if (strcmp(server_mud->domain, "udp") == 0) { -- break; -- } -+ -+ int32_t listen_fd_index = is_tcp_v6_flag ? V6_TCP : V4_TCP; -+ int32_t listen_fd = server_mud->listener.listen_fd_array[listen_fd_index]; - - if (strcmp(server_mud->accept, "ac4") == 0) { -- accept_fd = accept4(server_mud->listener.fd, (struct sockaddr *)&accept_addr, &sockaddr_in_len, SOCK_CLOEXEC); -+ accept_fd = accept4(listen_fd, (struct sockaddr *)&accept_addr, &sockaddr_in_len, SOCK_CLOEXEC); - } else { -- accept_fd = accept(server_mud->listener.fd, (struct sockaddr *)&accept_addr, &sockaddr_in_len); -+ accept_fd = accept(listen_fd, (struct sockaddr *)&accept_addr, &sockaddr_in_len); - } -- -+ - if (accept_fd < 0) { - break; - } - -- if (set_socket_unblock(accept_fd) < 0) { -- PRINT_ERROR("server can't set the connect socket to unblock! "); -+ if (sermud_set_socket_opt(accept_fd, server_mud) < 0) { - return PROGRAM_FAULT; - } - -- ++(server_mud->curr_connect); -+ // sockaddr to ip, port -+ ip_addr_t remote_ip; -+ uint16_t remote_port = ((struct sockaddr_in *)&accept_addr)->sin_port; -+ sermud_accept_get_remote_ip(&accept_addr, &remote_ip, is_tcp_v6_flag); - - pthread_t *tid = (pthread_t *)malloc(sizeof(pthread_t)); - struct ServerMudWorker *worker = (struct ServerMudWorker *)malloc(sizeof(struct ServerMudWorker)); -@@ -169,26 +209,50 @@ int32_t sermud_listener_accept_connects(struct ServerMud *server_mud) - worker->epevs = (struct epoll_event *)malloc(sizeof(struct epoll_event)); - worker->recv_bytes = 0; - worker->pktlen = server_mud->pktlen; -- worker->ip = accept_addr.sin_addr.s_addr; -- worker->port = accept_addr.sin_port; -+ worker->ip = remote_ip; -+ worker->port = remote_port; - worker->api = server_mud->api; - worker->debug = server_mud->debug; - worker->next = server_mud->workers; - worker->epollcreate = server_mud->epollcreate; -+ worker->worker.is_v6 = is_tcp_v6_flag ? 1 : 0; -+ worker->domain = server_mud->domain; -+ worker->curr_connect = 1; - - server_mud->workers = worker; - -- if (pthread_create(tid, NULL, sermud_worker_create_and_run, server_mud) < 0) { -+ if (pthread_create(tid, NULL, sermud_worker_create_and_run, worker) < 0) { - PRINT_ERROR("server can't create poisx thread %d! ", errno); - return PROGRAM_FAULT; - } - -- server_debug_print("server mud listener", "accept", accept_addr.sin_addr.s_addr, accept_addr.sin_port, server_mud->debug); -+ server_debug_print("server mud listener", "accept", &remote_ip, remote_port, server_mud->debug); - } - - return PROGRAM_OK; - } - -+static int32_t server_handler_close(int32_t epfd, struct ServerHandler *server_handler) -+{ -+ int32_t fd = server_handler->fd; -+ struct epoll_event ep_ev; -+ if (server_handler) { -+ free(server_handler); -+ } -+ -+ if (epoll_ctl(epfd, EPOLL_CTL_DEL, fd, &ep_ev) < 0) { -+ PRINT_ERROR("server can't delete socket '%d' to control epoll %d! ", fd, errno); -+ return PROGRAM_FAULT; -+ } -+ -+ if (close(fd) < 0) { -+ PRINT_ERROR("server can't close the socket %d! ", errno); -+ return PROGRAM_FAULT; -+ } -+ -+ return 0; -+} -+ - // the worker thread, unblock, dissymmetric server processes the events - int32_t sermud_worker_proc_epevs(struct ServerMudWorker *worker_unit, const char* domain) - { -@@ -201,32 +265,60 @@ int32_t sermud_worker_proc_epevs(struct ServerMudWorker *worker_unit, const char - for (int32_t i = 0; i < epoll_nfds; ++i) { - struct epoll_event *curr_epev = worker_unit->epevs + i; - -- if (curr_epev->events == EPOLLERR || curr_epev->events == EPOLLHUP || curr_epev->events == EPOLLRDHUP) { -+ if (curr_epev->events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) { -+ worker_unit->curr_connect--; - PRINT_ERROR("server epoll wait error %d! ", curr_epev->events); -- return PROGRAM_FAULT; -+ if (server_handler_close(worker_unit->epfd, (struct ServerHandler *)curr_epev->data.ptr) != 0) { -+ return PROGRAM_FAULT; -+ } - } - - if (curr_epev->events == EPOLLIN) { - struct ServerHandler *server_handler = (struct ServerHandler *)curr_epev->data.ptr; - -- int32_t server_ans_ret = server_ans(server_handler, worker_unit->pktlen, worker_unit->api, domain); -+ int32_t server_ans_ret = server_ans(server_handler->fd, worker_unit->pktlen, worker_unit->api, "tcp"); - if (server_ans_ret == PROGRAM_FAULT) { -- struct epoll_event ep_ev; -- if (epoll_ctl(worker_unit->epfd, EPOLL_CTL_DEL, server_handler->fd, &ep_ev) < 0) { -- PRINT_ERROR("server can't delete socket '%d' to control epoll %d! ", server_handler->fd, errno); -+ worker_unit->curr_connect--; -+ if (server_handler_close(worker_unit->epfd, server_handler) != 0) { - return PROGRAM_FAULT; - } - } else if (server_ans_ret == PROGRAM_ABORT) { -- if (close(server_handler->fd) < 0) { -- PRINT_ERROR("server can't close the socket %d! ", errno); -+ worker_unit->curr_connect--; -+ server_debug_print("server mud worker", "close", &worker_unit->ip, worker_unit->port, worker_unit->debug); -+ if (server_handler_close(worker_unit->epfd, server_handler) != 0) { - return PROGRAM_FAULT; - } -- server_debug_print("server mud worker", "close", worker_unit->ip, worker_unit->port, worker_unit->debug); - } else { - worker_unit->recv_bytes += worker_unit->pktlen; -- server_debug_print("server mud worker", "receive", worker_unit->ip, worker_unit->port, worker_unit->debug); -+ server_debug_print("server mud worker", "receive", &worker_unit->ip, worker_unit->port, worker_unit->debug); -+ } -+ } -+ } -+ -+ return PROGRAM_OK; -+} -+ -+static int32_t sermud_process_epollin_event(struct epoll_event *curr_epev, struct ServerMud *server_mud) -+{ -+ struct ServerHandler *server_handler = (struct ServerHandler *)curr_epev->data.ptr; -+ -+ if (server_handler->fd == server_mud->listener.listen_fd_array[V4_UDP] || -+ server_handler->fd == server_mud->listener.listen_fd_array[UDP_MULTICAST]) { -+ uint32_t pktlen = server_mud->pktlen > UDP_PKTLEN_MAX ? UDP_PKTLEN_MAX : server_mud->pktlen; -+ int32_t server_ans_ret = server_ans(server_handler->fd, pktlen, server_mud->api, "udp"); -+ if (server_ans_ret != PROGRAM_OK) { -+ if (server_handler_close(server_mud->epfd, server_handler) != 0) { -+ PRINT_ERROR("server_handler_close server_ans_ret %d! \n", server_ans_ret); -+ return PROGRAM_FAULT; - } - } -+ server_mud->workers->recv_bytes += pktlen; -+ } else { -+ int32_t sermud_listener_accept_connects_ret = sermud_listener_accept_connects(curr_epev, server_mud); -+ if (sermud_listener_accept_connects_ret < 0) { -+ PRINT_ERROR("server try accept error %d! ", sermud_listener_accept_connects_ret); -+ return PROGRAM_FAULT; -+ } - } - - return PROGRAM_OK; -@@ -244,15 +336,14 @@ int32_t sermud_listener_proc_epevs(struct ServerMud *server_mud) - for (int32_t i = 0; i < epoll_nfds; ++i) { - struct epoll_event *curr_epev = server_mud->epevs + i; - -- if (curr_epev->events == EPOLLERR || curr_epev->events == EPOLLHUP || curr_epev->events == EPOLLRDHUP) { -+ if (curr_epev->events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) { - PRINT_ERROR("server epoll wait error %d! ", curr_epev->events); -- return PROGRAM_FAULT; -+ server_handler_close(server_mud->epfd, (struct ServerHandler *)curr_epev->data.ptr); -+ return PROGRAM_OK; - } - - if (curr_epev->events == EPOLLIN) { -- int32_t sermud_listener_accept_connects_ret = sermud_listener_accept_connects(server_mud); -- if (sermud_listener_accept_connects_ret < 0) { -- PRINT_ERROR("server try accept error %d! ", sermud_listener_accept_connects_ret); -+ if (sermud_process_epollin_event(curr_epev, server_mud) < 0) { - return PROGRAM_FAULT; - } - } -@@ -266,15 +357,15 @@ void *sermud_worker_create_and_run(void *arg) - { - pthread_detach(pthread_self()); - -- struct ServerMudWorker *worker_unit = ((struct ServerMud *)arg)->workers; -- char* domain = ((struct ServerMud *)arg)->domain; -+ struct ServerMudWorker *worker_unit = (struct ServerMudWorker *)arg; -+ char *domain = worker_unit->domain; - - if (sermud_worker_create_epfd_and_reg(worker_unit) < 0) { -- exit(PROGRAM_FAULT); -+ return (void *)PROGRAM_OK; - } - while (true) { - if (sermud_worker_proc_epevs(worker_unit, domain) < 0) { -- exit(PROGRAM_FAULT); -+ return (void *)PROGRAM_OK; - } - } - -@@ -284,26 +375,60 @@ void *sermud_worker_create_and_run(void *arg) - return (void *)PROGRAM_OK; - } - -+void sermud_memory_recycle(struct ServerMud *server_mud) -+{ -+ // recycle mem of epevs -+ if (server_mud->epevs) { -+ free(server_mud->epevs); -+ } -+ struct ServerMudWorker *head = server_mud->workers; -+ while (head) { -+ if (head->epevs) { -+ free(head->epevs); -+ } -+ struct ServerMudWorker *next = head->next; -+ free(head); -+ head = next; -+ } -+} -+ - // create the listener thread, unblock, dissymmetric server and run - void *sermud_listener_create_and_run(void *arg) - { - struct ServerMud *server_mud = (struct ServerMud *)arg; - -- if (create_socket_and_listen(&(server_mud->listener.fd), server_mud->ip, server_mud->groupip, server_mud->port, server_mud->domain) < 0) { -- exit(PROGRAM_FAULT); -+ uint32_t port = 0; -+ for (; port < UNIX_TCP_PORT_MAX; port++) { -+ if ((server_mud->port)[port]) { -+ if (create_socket_and_listen(server_mud->listener.listen_fd_array, &(server_mud->server_ip_info), -+ htons(port), server_mud->protocol_type_mode) < 0) { -+ PRINT_ERROR("create_socket_and_listen err"); -+ sermud_memory_recycle(server_mud); -+ exit(PROGRAM_FAULT); -+ } -+ } - } -+ - if (sermud_listener_create_epfd_and_reg(server_mud) < 0) { -- exit(PROGRAM_FAULT); -+ sermud_memory_recycle(server_mud); -+ exit(PROGRAM_FAULT); - } - while (true) { - if (sermud_listener_proc_epevs(server_mud) < 0) { -+ sermud_memory_recycle(server_mud); - exit(PROGRAM_FAULT); - } - } -- if (close(server_mud->listener.fd) < 0 || close(server_mud->epfd) < 0) { -- exit(PROGRAM_FAULT); -- } - -+ for (int i = 0; i < PROTOCOL_MODE_MAX; i++) { -+ if (server_mud->listener.listen_fd_array[i] == -1) -+ continue; -+ if (close(server_mud->listener.listen_fd_array[i]) < 0) { -+ sermud_memory_recycle(server_mud); -+ exit(PROGRAM_FAULT); -+ } -+ } -+ sermud_memory_recycle(server_mud); - return (void *)PROGRAM_OK; - } - -@@ -319,19 +444,44 @@ int32_t sermud_create_and_run(struct ProgramParams *params) - } - - server_mud->listener.fd = -1; -- server_mud->workers = NULL; -+ for (int32_t i = 0; i < PROTOCOL_MODE_MAX; i++) { -+ server_mud->listener.listen_fd_array[i] = -1; -+ } -+ -+ struct ServerMudWorker *workers = (struct ServerMudWorker *)malloc(sizeof(struct ServerMudWorker)); -+ if (workers == NULL) { -+ PRINT_ERROR("malloc truct ServerMudWorker failed "); -+ return PROGRAM_FAULT; -+ } -+ memset_s(workers, sizeof(struct ServerMudWorker), 0, sizeof(struct ServerMudWorker)); -+ workers->next = NULL; -+ server_mud->workers = workers; -+ - server_mud->epfd = -1; - server_mud->epevs = (struct epoll_event *)malloc(SERVER_EPOLL_SIZE_MAX * sizeof(struct epoll_event)); -- server_mud->curr_connect = 0; -- server_mud->ip = inet_addr(params->ip); -- server_mud->groupip = inet_addr(params->groupip); -- server_mud->port = htons(params->port); -+ server_mud->server_ip_info.ip.addr_family = params->addr_family; -+ -+ inet_pton(AF_INET, params->ip, &server_mud->server_ip_info.ip.u_addr.ip4); -+ inet_pton(AF_INET6, params->ipv6, &server_mud->server_ip_info.ip.u_addr.ip6); -+ -+ server_mud->server_ip_info.groupip.addr_family = params->addr_family; -+ inet_pton(AF_INET, params->groupip, &server_mud->server_ip_info.groupip.u_addr); -+ -+ server_mud->server_ip_info.groupip_interface.addr_family = params->addr_family; -+ inet_pton(AF_INET, params->groupip_interface, &server_mud->server_ip_info.groupip_interface.u_addr); -+ -+ server_mud->port = params->port; - server_mud->pktlen = params->pktlen; -- server_mud->domain = params->domain; -+ -+ server_mud->protocol_type_mode = program_get_protocol_mode_by_domain_ip(params->domain, params->ip, params->ipv6, -+ params->groupip); -+ - server_mud->api = params->api; - server_mud->debug = params->debug; - server_mud->epollcreate = params->epollcreate; - server_mud->accept = params->accept; -+ server_mud->tcp_keepalive_idle = params->tcp_keepalive_idle; -+ server_mud->tcp_keepalive_interval = params->tcp_keepalive_interval; - - if (pthread_create(tid, NULL, sermud_listener_create_and_run, server_mud) < 0) { - PRINT_ERROR("server can't create poisx thread %d! ", errno); -@@ -341,10 +491,17 @@ int32_t sermud_create_and_run(struct ProgramParams *params) - if (server_mud->debug == false) { - printf("[program informations]: \n\n"); - } -- while (true) { -- sermud_info_print(server_mud); -+ -+ if (strcmp(params->as, "server") == 0) { -+ while (true) { -+ sermud_info_print(server_mud); -+ } -+ } else if (strcmp(params->as, "loop") == 0) { -+ loopmod.model = params->model; -+ loopmod.server_mud_info = server_mud; - } - -+ - pthread_mutex_destroy(&server_debug_mutex); - - return PROGRAM_OK; -@@ -413,39 +570,62 @@ int32_t sersum_create_epfd_and_reg(struct ServerMumUnit *server_unit) - return PROGRAM_FAULT; - } - -- struct epoll_event ep_ev; -- ep_ev.data.ptr = (void *)&(server_unit->listener); -+ struct epoll_event ep_ev = {0}; - ep_ev.events = EPOLLIN | EPOLLET; -- if (epoll_ctl(server_unit->epfd, EPOLL_CTL_ADD, server_unit->listener.fd, &ep_ev) < 0) { -- PRINT_ERROR("server can't control epoll %d! ", errno); -- return PROGRAM_FAULT; -+ -+ for (int32_t i = 0; i < PROTOCOL_MODE_MAX; i++) { -+ if (server_unit->listener.listen_fd_array[i] != -1) { -+ struct ServerHandler *server_handler = (struct ServerHandler *)malloc(sizeof(struct ServerHandler)); -+ memset_s(server_handler, sizeof(struct ServerHandler), 0, sizeof(struct ServerHandler)); -+ server_handler->fd = server_unit->listener.listen_fd_array[i]; -+ -+ ep_ev.data.ptr = (void *)server_handler; -+ if (epoll_ctl(server_unit->epfd, EPOLL_CTL_ADD, server_unit->listener.listen_fd_array[i], &ep_ev) < 0) { -+ PRINT_ERROR("epoll_ctl failed %d! listen_fd=%d ", errno, server_unit->listener.listen_fd_array[i]); -+ return PROGRAM_FAULT; -+ } -+ } - } - -- server_debug_print("server mum unit", "waiting", server_unit->ip, server_unit->port, server_unit->debug); -+ server_debug_print("server mum unit", "waiting", &server_unit->server_ip_info.ip, server_unit->port, -+ server_unit->debug); - - return PROGRAM_OK; - } - - // the single thread, unblock, mutliplexing IO server accepts the connections --int32_t sersum_accept_connects(struct ServerMumUnit *server_unit, struct ServerHandler *server_handler) -+int32_t sersum_accept_connects(struct epoll_event *cur_epev, struct ServerMumUnit *server_unit) - { -+ fault_inject_delay(INJECT_DELAY_ACCEPT); -+ int32_t fd = ((struct ServerHandler*)(cur_epev->data.ptr))->fd; - while (true) { -- struct sockaddr_in accept_addr; -- uint32_t sockaddr_in_len = sizeof(struct sockaddr_in); -+ sockaddr_t accept_addr; -+ bool is_tcp_v6 = (fd == (server_unit->listener.listen_fd_array[V6_TCP])) ? true : false; -+ -+ socklen_t sockaddr_in_len = is_tcp_v6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in); - int32_t accept_fd; -- if (strcmp(server_unit->domain, "udp") == 0) { -- break; -- } -+ int32_t ret = 0; -+ -+ int32_t listen_index = (is_tcp_v6) ? V6_TCP : V4_TCP; -+ int32_t listen_fd = server_unit->listener.listen_fd_array[listen_index]; - - if (strcmp(server_unit->accept, "ac4") == 0) { -- accept_fd = accept4(server_unit->listener.fd, (struct sockaddr *)&accept_addr, &sockaddr_in_len, SOCK_CLOEXEC); -+ accept_fd = accept4(listen_fd, (struct sockaddr *)&accept_addr, &sockaddr_in_len, SOCK_CLOEXEC); - } else { -- accept_fd = accept(server_unit->listener.fd, (struct sockaddr *)&accept_addr, &sockaddr_in_len); -+ accept_fd = accept(listen_fd, (struct sockaddr *)&accept_addr, &sockaddr_in_len); - } -- -+ - if (accept_fd < 0) { -+ if (errno != EWOULDBLOCK && errno != EAGAIN){ -+ PRINT_ERROR("accept_fd=%d , errno=%d ", accept_fd, errno); -+ } - break; - } -+ ret = set_tcp_keep_alive_info(accept_fd, server_unit->tcp_keepalive_idle, server_unit->tcp_keepalive_interval); -+ if (ret < 0) { -+ PRINT_ERROR("set_tcp_keep_alive_info ret=%d \n", ret); -+ return PROGRAM_FAULT; -+ } - - if (set_socket_unblock(accept_fd) < 0) { - PRINT_ERROR("server can't set the connect socket to unblock! "); -@@ -454,6 +634,8 @@ int32_t sersum_accept_connects(struct ServerMumUnit *server_unit, struct ServerH - - struct ServerHandler *server_handler = (struct ServerHandler *)malloc(sizeof(struct ServerHandler)); - server_handler->fd = accept_fd; -+ server_handler->is_v6 = (is_tcp_v6) ? 1 : 0; -+ - struct epoll_event ep_ev; - ep_ev.data.ptr = (void *)server_handler; - ep_ev.events = EPOLLIN | EPOLLET; -@@ -463,13 +645,98 @@ int32_t sersum_accept_connects(struct ServerMumUnit *server_unit, struct ServerH - } - - ++server_unit->curr_connect; -- -- server_debug_print("server mum unit", "accept", accept_addr.sin_addr.s_addr, accept_addr.sin_port, server_unit->debug); -+ -+ // sockaddr tp ip, port -+ ip_addr_t remote_ip; -+ uint16_t remote_port = ((struct sockaddr_in*)&accept_addr)->sin_port; -+ remote_ip.addr_family = (is_tcp_v6) ? AF_INET6 : AF_INET; -+ if (is_tcp_v6 == false) { -+ remote_ip.u_addr.ip4 = ((struct sockaddr_in *)&accept_addr)->sin_addr; -+ } else { -+ remote_ip.u_addr.ip6 = ((struct sockaddr_in6 *)&accept_addr)->sin6_addr; -+ } -+ -+ server_debug_print("server mum unit", "accept", &remote_ip, remote_port, server_unit->debug); - } - - return PROGRAM_OK; - } - -+static int sersum_get_remote_ip(struct ServerHandler *server_handler, ip_addr_t *remote_ip, uint16_t *remote_port) -+{ -+ sockaddr_t connect_addr; -+ socklen_t connect_addr_len = server_handler->is_v6 == 0 ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); -+ if (getpeername(server_handler->fd, (struct sockaddr *)&connect_addr, &connect_addr_len) < 0) { -+ PRINT_ERROR("server can't socket peername %d! ", errno); -+ return PROGRAM_ABORT; -+ } -+ -+ *remote_port = ((struct sockaddr_in *)&connect_addr)->sin_port; -+ if (((struct sockaddr *)&connect_addr)->sa_family == AF_INET) { -+ remote_ip->addr_family = AF_INET; -+ remote_ip->u_addr.ip4 = ((struct sockaddr_in *)&connect_addr)->sin_addr; -+ } else if (((struct sockaddr *)&connect_addr)->sa_family == AF_INET6) { -+ remote_ip->addr_family = AF_INET6; -+ remote_ip->u_addr.ip6 = ((struct sockaddr_in6 *)&connect_addr)->sin6_addr; -+ } -+ return PROGRAM_OK; -+} -+ -+static int sersum_process_tcp_accept_event(struct ServerMumUnit *server_unit, struct epoll_event *curr_epev) -+{ -+ struct ServerHandler *server_handler = (struct ServerHandler *)curr_epev->data.ptr; -+ ip_addr_t remote_ip; -+ uint16_t remote_port; -+ -+ if (sersum_get_remote_ip(server_handler, &remote_ip, &remote_port) != PROGRAM_OK) { -+ return PROGRAM_ABORT; -+ } -+ -+ int32_t server_ans_ret = server_ans(server_handler->fd, server_unit->pktlen, server_unit->api, "tcp"); -+ if (server_ans_ret == PROGRAM_FAULT) { -+ --server_unit->curr_connect; -+ server_handler_close(server_unit->epfd, server_handler); -+ } else if (server_ans_ret == PROGRAM_ABORT) { -+ --server_unit->curr_connect; -+ server_debug_print("server mum unit", "close", &remote_ip, remote_port, server_unit->debug); -+ server_handler_close(server_unit->epfd, server_handler); -+ } else { -+ server_unit->recv_bytes += server_unit->pktlen; -+ server_debug_print("server mum unit", "receive", &remote_ip, remote_port, server_unit->debug); -+ } -+ return PROGRAM_OK; -+} -+ -+static int sersum_process_epollin_event(struct ServerMumUnit *server_unit, struct epoll_event *curr_epev) -+{ -+ struct ServerHandler *server_handler = (struct ServerHandler *)curr_epev->data.ptr; -+ int32_t fd = server_handler->fd; -+ if (fd == (server_unit->listener.listen_fd_array[V4_TCP]) || -+ fd == (server_unit->listener.listen_fd_array[V6_TCP])) { -+ int32_t sersum_accept_connects_ret = sersum_accept_connects(curr_epev, server_unit); -+ if (sersum_accept_connects_ret < 0) { -+ PRINT_ERROR("server try accept error %d! ", sersum_accept_connects_ret); -+ return PROGRAM_ABORT; -+ } -+ } else if (fd == (server_unit->listener.listen_fd_array[V4_UDP]) || -+ fd == (server_unit->listener.listen_fd_array[UDP_MULTICAST])) { -+ uint32_t pktlen = server_unit->pktlen > UDP_PKTLEN_MAX ? UDP_PKTLEN_MAX : server_unit->pktlen; -+ int32_t server_ans_ret = server_ans(fd, pktlen, server_unit->api, "udp"); -+ if (server_ans_ret != PROGRAM_OK) { -+ if (server_handler_close(server_unit->epfd, server_handler) != 0) { -+ PRINT_ERROR("server_handler_close ret %d! \n", server_ans_ret); -+ return PROGRAM_ABORT; -+ } -+ } -+ server_unit->recv_bytes += pktlen; -+ } else { -+ if (sersum_process_tcp_accept_event(server_unit, curr_epev) != PROGRAM_OK) { -+ return PROGRAM_ABORT; -+ } -+ } -+ return PROGRAM_OK; -+} -+ - // the single thread, unblock, mutliplexing IO server processes the events - int32_t sersum_proc_epevs(struct ServerMumUnit *server_unit) - { -@@ -482,47 +749,16 @@ int32_t sersum_proc_epevs(struct ServerMumUnit *server_unit) - for (int32_t i = 0; i < epoll_nfds; ++i) { - struct epoll_event *curr_epev = server_unit->epevs + i; - -- if (curr_epev->events == EPOLLERR || curr_epev->events == EPOLLHUP || curr_epev->events == EPOLLRDHUP) { -- PRINT_ERROR("server epoll wait error %d! ", curr_epev->events); -- return PROGRAM_FAULT; -+ if (curr_epev->events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) { -+ server_unit->curr_connect--; -+ if (server_handler_close(server_unit->epfd, (struct ServerHandler *)curr_epev->data.ptr) != 0) { -+ return PROGRAM_OK; -+ } - } - - if (curr_epev->events == EPOLLIN) { -- if (curr_epev->data.ptr == (void *)&(server_unit->listener) && strcmp(server_unit->domain, "udp") != 0) { -- int32_t sersum_accept_connects_ret = sersum_accept_connects(server_unit, &(server_unit->listener)); -- if (sersum_accept_connects_ret < 0) { -- PRINT_ERROR("server try accept error %d! ", sersum_accept_connects_ret); -- return PROGRAM_FAULT; -- } -- continue; -- } else { -- struct ServerHandler *server_handler = (struct ServerHandler *)curr_epev->data.ptr; -- struct sockaddr_in connect_addr; -- socklen_t connect_addr_len = sizeof(connect_addr); -- if (strcmp(server_unit->domain, "udp") != 0 && getpeername(server_handler->fd, (struct sockaddr *)&connect_addr, &connect_addr_len) < 0) { -- PRINT_ERROR("server can't socket peername %d! ", errno); -- return PROGRAM_FAULT; -- } -- -- int32_t server_ans_ret = server_ans(server_handler, server_unit->pktlen, server_unit->api, server_unit->domain); -- if (server_ans_ret == PROGRAM_FAULT) { -- --server_unit->curr_connect; -- struct epoll_event ep_ev; -- if (epoll_ctl(server_unit->epfd, EPOLL_CTL_DEL, server_handler->fd, &ep_ev) < 0) { -- PRINT_ERROR("server can't delete socket '%d' to control epoll %d! ", server_handler->fd, errno); -- return PROGRAM_FAULT; -- } -- } else if (server_ans_ret == PROGRAM_ABORT) { -- --server_unit->curr_connect; -- if (close(server_handler->fd) < 0) { -- PRINT_ERROR("server can't close the socket %d! ", errno); -- return PROGRAM_FAULT; -- } -- server_debug_print("server mum unit", "close", connect_addr.sin_addr.s_addr, connect_addr.sin_port, server_unit->debug); -- } else { -- server_unit->recv_bytes += server_unit->pktlen; -- server_debug_print("server mum unit", "receive", connect_addr.sin_addr.s_addr, connect_addr.sin_port, server_unit->debug); -- } -+ if (sersum_process_epollin_event(server_unit, curr_epev) != PROGRAM_OK) { -+ return PROGRAM_ABORT; - } - } - } -@@ -535,7 +771,9 @@ void *sersum_create_and_run(void *arg) - { - struct ServerMumUnit *server_unit = (struct ServerMumUnit *)arg; - -- if (create_socket_and_listen(&(server_unit->listener.fd), server_unit->ip, server_unit->groupip, server_unit->port, server_unit->domain) < 0) { -+ if (create_socket_and_listen(server_unit->listener.listen_fd_array, &(server_unit->server_ip_info), -+ server_unit->port, server_unit->protocol_type_mode) < 0) { -+ PRINT_ERROR("create_socket_and_listen err! \n"); - exit(PROGRAM_FAULT); - } - if (sersum_create_epfd_and_reg(server_unit) < 0) { -@@ -560,6 +798,7 @@ int32_t sermum_create_and_run(struct ProgramParams *params) - pthread_t *tids = (pthread_t *)malloc(thread_num * sizeof(pthread_t)); - struct ServerMum *server_mum = (struct ServerMum *)malloc(sizeof(struct ServerMum)); - struct ServerMumUnit *server_unit = (struct ServerMumUnit *)malloc(sizeof(struct ServerMumUnit)); -+ memset_s(server_unit, sizeof(struct ServerMumUnit), 0, sizeof(struct ServerMumUnit)); - - if (pthread_mutex_init(&server_debug_mutex, NULL) < 0) { - PRINT_ERROR("server can't init posix mutex %d! ", errno); -@@ -568,22 +807,47 @@ int32_t sermum_create_and_run(struct ProgramParams *params) - - server_mum->uints = server_unit; - server_mum->debug = params->debug; -+ uint32_t port = UNIX_TCP_PORT_MIN; - - for (uint32_t i = 0; i < thread_num; ++i) { - server_unit->listener.fd = -1; -+ for (int32_t i = 0; i < PROTOCOL_MODE_MAX; i++) { -+ server_unit->listener.listen_fd_array[i] = -1; -+ } - server_unit->epfd = -1; - server_unit->epevs = (struct epoll_event *)malloc(SERVER_EPOLL_SIZE_MAX * sizeof(struct epoll_event)); - server_unit->curr_connect = 0; - server_unit->recv_bytes = 0; -- server_unit->ip = inet_addr(params->ip); -- server_unit->groupip = inet_addr(params->groupip); -- server_unit->port = htons(params->port); -+ server_unit->server_ip_info.ip.addr_family = params->addr_family; -+ inet_pton(AF_INET, params->ip, &server_unit->server_ip_info.ip.u_addr.ip4); -+ inet_pton(AF_INET6, params->ipv6, &server_unit->server_ip_info.ip.u_addr.ip6); -+ -+ server_unit->server_ip_info.groupip.addr_family = AF_INET; -+ inet_pton(AF_INET, params->groupip, &server_unit->server_ip_info.groupip.u_addr); -+ -+ server_unit->server_ip_info.groupip_interface.addr_family = AF_INET; -+ inet_pton(AF_INET, params->groupip_interface, &server_unit->server_ip_info.groupip_interface.u_addr); -+ -+ /* loop to set ports to each server_mums */ -+ while (!((params->port)[port])) { -+ port = (port + 1) % UNIX_TCP_PORT_MAX; -+ } -+ server_unit->port = htons(port++); - server_unit->pktlen = params->pktlen; -- server_unit->domain = params->domain; -+ -+ server_unit->protocol_type_mode = program_get_protocol_mode_by_domain_ip(params->domain, params->ip, -+ params->ipv6, params->groupip); -+ -+ // Create multicast sockets only on the first thread -+ if (i != 0) { -+ server_unit->protocol_type_mode = setbitnum_off(server_unit->protocol_type_mode, UDP_MULTICAST); -+ } - server_unit->api = params->api; - server_unit->debug = params->debug; - server_unit->epollcreate = params->epollcreate; - server_unit->accept = params->accept; -+ server_unit->tcp_keepalive_idle = params->tcp_keepalive_idle; -+ server_unit->tcp_keepalive_interval = params->tcp_keepalive_interval; - server_unit->next = (struct ServerMumUnit *)malloc(sizeof(struct ServerMumUnit)); - if (server_unit->next) { - memset_s(server_unit->next, sizeof(struct ServerMumUnit), 0, sizeof(struct ServerMumUnit)); -@@ -599,8 +863,14 @@ int32_t sermum_create_and_run(struct ProgramParams *params) - if (server_mum->debug == false) { - printf("[program informations]: \n\n"); - } -- while (true) { -- sermum_info_print(server_mum); -+ -+ if (strcmp(params->as, "server") == 0) { -+ while (true) { -+ sermum_info_print(server_mum); -+ } -+ } else if (strcmp(params->as, "loop") == 0) { -+ loopmod.model = params->model; -+ loopmod.server_mum_info = server_mum; - } - - pthread_mutex_destroy(&server_debug_mutex); -diff --git a/examples/src/utilities.c b/examples/src/utilities.c -index 7247b44..59d8bea 100644 ---- a/examples/src/utilities.c -+++ b/examples/src/utilities.c -@@ -11,35 +11,215 @@ - */ - - --#include "utilities.h" -+#include "parameter.h" - -+int32_t set_tcp_keep_alive_info(int32_t sockfd, int32_t tcp_keepalive_idle, int32_t tcp_keepalive_interval) -+{ -+ int32_t ret = 0; -+ int32_t keep_alive = 1; -+ int32_t keep_idle = 1; -+ int32_t keep_interval = 1; -+ -+ if ((tcp_keepalive_idle == PARAM_DEFAULT_KEEPALIVEIDLE) || -+ (tcp_keepalive_interval == PARAM_DEFAULT_KEEPALIVEIDLE)) { -+ return 0; -+ } -+ -+ keep_idle = tcp_keepalive_idle; -+ ret = setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (void *)&keep_alive, sizeof(keep_alive)); -+ if (ret != 0) { -+ PRINT_ERROR("setsockopt keep_alive err ret=%d \n", ret); -+ return ret; -+ } -+ -+ ret = setsockopt(sockfd, SOL_TCP, TCP_KEEPIDLE, (void *)&keep_idle, sizeof(keep_idle)); -+ if (ret != 0) { -+ PRINT_ERROR("setsockopt keep_idle err ret=%d \n", ret); -+ return ret; -+ } -+ -+ keep_interval = tcp_keepalive_interval; -+ ret = setsockopt(sockfd, SOL_TCP, TCP_KEEPINTVL, (void *)&keep_interval, sizeof(keep_interval)); -+ if (ret != 0) { -+ PRINT_ERROR("setsockopt keep_interval err ret=%d \n", ret); -+ return ret; -+ } -+ return ret; -+} -+ -+static int32_t process_unix_fd(int32_t *socket_fd, int32_t *listen_fd_array) -+{ -+ struct sockaddr_un socket_addr; -+ int32_t fd = socket(AF_UNIX, SOCK_STREAM, 0); -+ if (fd < 0) { -+ PRINT_ERROR("can't create socket %d! ", errno); -+ return PROGRAM_FAULT; -+ } -+ *socket_fd = fd; -+ -+ unlink(SOCKET_UNIX_DOMAIN_FILE); -+ socket_addr.sun_family = AF_UNIX; -+ strcpy_s(socket_addr.sun_path, sizeof(socket_addr.sun_path), SOCKET_UNIX_DOMAIN_FILE); -+ if (bind(*socket_fd, (struct sockaddr *)&socket_addr, sizeof(struct sockaddr_un)) < 0) { -+ PRINT_ERROR("can't bind the address to socket %d! ", errno); -+ return PROGRAM_FAULT; -+ } -+ -+ if (listen(*socket_fd, SERVER_SOCKET_LISTEN_BACKLOG) < 0) { -+ PRINT_ERROR("server socket can't lisiten %d! ", errno); -+ return PROGRAM_FAULT; -+ } -+ return PROGRAM_OK; -+} -+ -+static int32_t process_udp_groupip(int32_t fd, ip_addr_t *ip, ip_addr_t *groupip, sockaddr_t *socker_add_info, -+ ip_addr_t *groupip_interface) -+{ -+ struct ip_mreq mreq; -+ if (groupip->u_addr.ip4.s_addr) { -+ mreq.imr_multiaddr = groupip->u_addr.ip4; -+ if (groupip_interface->u_addr.ip4.s_addr) { -+ mreq.imr_interface = groupip_interface->u_addr.ip4; -+ } else { -+ mreq.imr_interface = ip->u_addr.ip4; -+ } -+ -+ if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(struct ip_mreq)) == -1) { -+ PRINT_ERROR("can't set the address to group %d! ", errno); -+ return PROGRAM_FAULT; -+ } -+ ((struct sockaddr_in *)socker_add_info)->sin_addr = groupip->u_addr.ip4; -+ return PROGRAM_OK; -+ } -+ return PROGRAM_OK; -+} -+ -+static int32_t server_create_sock(uint8_t protocol_mode, int32_t* fd_arry) -+{ -+ bool ret = true; -+ for (int32_t i = 0; i < PROTOCOL_MODE_MAX; i++) { -+ if (getbit_num(protocol_mode, i) == 0) -+ continue; -+ if (i == V4_TCP) { -+ fd_arry[i] = socket(AF_INET, SOCK_STREAM, 0); -+ } else if (i == V6_TCP) { -+ fd_arry[i] = socket(AF_INET6, SOCK_STREAM, 0); -+ } else if (i == V4_UDP) { -+ fd_arry[i] = socket(AF_INET, SOCK_DGRAM, 0); -+ } else if (i == UDP_MULTICAST) { -+ fd_arry[i] = socket(AF_INET, SOCK_DGRAM, 0); -+ } else { -+ continue; -+ } -+ if (fd_arry[i] < 0) { -+ PRINT_ERROR("can't create socket type=%d errno=%d! ", i, errno); -+ ret = false; -+ break; -+ } -+ } -+ -+ if (ret == false) { -+ for (int32_t i = 0; i< PROTOCOL_MODE_MAX; i++) { -+ if (fd_arry[i] > 0) { -+ close(fd_arry[i]); -+ } -+ } -+ return PROGRAM_FAULT; -+ } -+ return PROGRAM_OK; -+} -+ -+static int32_t socket_add_info_init(int32_t idx, uint16_t port, struct ServerIpInfo *server_ip_info, -+ sockaddr_t *socker_add_info, int32_t *listen_fd_array) -+{ -+ ip_addr_t *ip = &(server_ip_info->ip); -+ ip_addr_t *groupip = &(server_ip_info->groupip); -+ ip_addr_t *groupip_interface = &(server_ip_info->groupip_interface); -+ -+ uint32_t len = ((idx == V4_TCP || idx == V4_UDP || idx == UDP_MULTICAST) ? -+ sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)); -+ memset_s(socker_add_info, len, 0, len); -+ -+ if (idx == V4_TCP || idx == V4_UDP) { -+ ((struct sockaddr_in *)socker_add_info)->sin_addr = ip->u_addr.ip4; -+ } else if (idx == V6_TCP) { -+ ((struct sockaddr_in6 *)socker_add_info)->sin6_addr = ip->u_addr.ip6; -+ } else if (idx == UDP_MULTICAST) { -+ if (process_udp_groupip(listen_fd_array[idx], ip, groupip, socker_add_info, groupip_interface) != PROGRAM_OK) { -+ return PROGRAM_FAULT; -+ } -+ } -+ -+ ((struct sockaddr *)socker_add_info)->sa_family = ((idx == V4_TCP || idx == V4_UDP || idx == UDP_MULTICAST) ? -+ AF_INET : AF_INET6); -+ ((struct sockaddr_in *)socker_add_info)->sin_port = port; -+ return PROGRAM_OK; -+} - - // create the socket and listen --int32_t create_socket_and_listen(int32_t *socket_fd, in_addr_t ip, in_addr_t groupip, uint16_t port, const char *domain) -+int32_t create_socket_and_listen(int32_t *listen_fd_array, struct ServerIpInfo *server_ip_info, -+ uint16_t port, uint8_t protocol_mode) - { -- if (strcmp(domain, "tcp") == 0) { -- *socket_fd = socket(AF_INET, SOCK_STREAM, 0); -- if (*socket_fd < 0) { -- PRINT_ERROR("can't create socket %d! ", errno); -+ int32_t port_multi = 1; -+ uint32_t len = 0; -+ sockaddr_t socker_add_info; -+ -+ if (getbit_num(protocol_mode, UNIX) == 1) { -+ if (process_unix_fd(&listen_fd_array[UNIX], listen_fd_array) != PROGRAM_OK) { - return PROGRAM_FAULT; - } -- } else if (strcmp(domain, "unix") == 0) { -- *socket_fd = socket(AF_UNIX, SOCK_STREAM, 0); -- if (*socket_fd < 0) { -- PRINT_ERROR("can't create socket %d! ", errno); -+ return PROGRAM_OK; -+ } -+ -+ if (server_create_sock(protocol_mode, listen_fd_array) != PROGRAM_OK) { -+ return PROGRAM_FAULT; -+ } -+ -+ for (int32_t i = 0;i< PROTOCOL_MODE_MAX; i++) { -+ if (listen_fd_array[i] <= 0) -+ continue; -+ if (setsockopt(listen_fd_array[i], SOL_SOCKET, SO_REUSEPORT, (void *)&port_multi, sizeof(int32_t)) < 0) { -+ PRINT_ERROR("can't set the option of socket %d! ", errno); - return PROGRAM_FAULT; - } -- } else if (strcmp(domain, "udp") == 0) { -- *socket_fd = socket(AF_INET, SOCK_DGRAM, 0); -- if (*socket_fd < 0) { -- PRINT_ERROR("can't create socket %d! ", errno); -+ if (set_socket_unblock(listen_fd_array[i]) < 0) { -+ PRINT_ERROR("can't set the socket to unblock! "); -+ return PROGRAM_FAULT; -+ } -+ if (socket_add_info_init(i, port, server_ip_info, &socker_add_info, listen_fd_array) != PROGRAM_OK) { -+ return PROGRAM_FAULT; -+ } -+ -+ len = ((i == V4_TCP || i == V4_UDP || i == UDP_MULTICAST) ? -+ sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)); -+ -+ if (bind(listen_fd_array[i], (struct sockaddr *)&socker_add_info, len) < 0) { -+ PRINT_ERROR("can't bind the address %d!, i=%d, listen_fd_array[i]=%d ", errno, i, listen_fd_array[i]); - return PROGRAM_FAULT; - } -+ -+ if (i == V4_TCP || i == V6_TCP) { -+ if (listen(listen_fd_array[i], SERVER_SOCKET_LISTEN_BACKLOG) < 0) { -+ PRINT_ERROR("server socket can't lisiten %d! ", errno); -+ return PROGRAM_FAULT; -+ } -+ } - } -+ return PROGRAM_OK; -+} - -- int32_t port_multi = 1; -- if (setsockopt(*socket_fd, SOL_SOCKET, SO_REUSEPORT, (void *)&port_multi, sizeof(int32_t)) < 0) { -- PRINT_ERROR("can't set the option of socket %d! ", errno); -+static int32_t creat_socket_init(int32_t *socket_fd, struct ClientUnit *client_unit, sockaddr_t *server_addr) -+{ -+ ip_addr_t *ip = &client_unit->ip; -+ const char *domain = client_unit->domain; -+ -+ if (strcmp(domain, "tcp") == 0) { -+ *socket_fd = socket(ip->addr_family, SOCK_STREAM, 0); -+ } else { -+ *socket_fd = socket(AF_INET, SOCK_DGRAM, 0); -+ } -+ if (*socket_fd < 0) { -+ PRINT_ERROR("client can't create socket %d! ", errno); - return PROGRAM_FAULT; - } - -@@ -48,106 +228,118 @@ int32_t create_socket_and_listen(int32_t *socket_fd, in_addr_t ip, in_addr_t gro - return PROGRAM_FAULT; - } - -- if (strcmp(domain, "tcp") == 0) { -- struct sockaddr_in socket_addr; -- memset_s(&socket_addr, sizeof(socket_addr), 0, sizeof(socket_addr)); -- socket_addr.sin_family = AF_INET; -- socket_addr.sin_addr.s_addr = ip; -- socket_addr.sin_port = port; -- if (bind(*socket_fd, (struct sockaddr *)&socket_addr, sizeof(struct sockaddr_in)) < 0) { -- PRINT_ERROR("can't bind the address to socket %d! ", errno); -- return PROGRAM_FAULT; -- } -+ ((struct sockaddr *)server_addr)->sa_family = ip->addr_family; - -- if (listen(*socket_fd, SERVER_SOCKET_LISTEN_BACKLOG) < 0) { -- PRINT_ERROR("server socket can't lisiten %d! ", errno); -- return PROGRAM_FAULT; -+ return PROGRAM_OK; -+} -+ -+static int32_t pocess_connect_sport(int32_t *socket_fd, struct ClientUnit *client_unit, sockaddr_t *server_addr) -+{ -+ uint16_t sport = client_unit->sport; -+ ip_addr_t *ip = &client_unit->ip; -+ uint32_t addr_len = ip->addr_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); -+ -+ if (sport) { -+ if (ip->addr_family == AF_INET) { -+ ((struct sockaddr_in *)server_addr)->sin_addr.s_addr = htonl(INADDR_ANY); -+ } else if (ip->addr_family == AF_INET6) { -+ ((struct sockaddr_in6 *)server_addr)->sin6_addr = in6addr_any; - } -- } else if (strcmp(domain, "unix") == 0) { -- struct sockaddr_un socket_addr; -- unlink(SOCKET_UNIX_DOMAIN_FILE); -- socket_addr.sun_family = AF_UNIX; -- strcpy_s(socket_addr.sun_path, sizeof(socket_addr.sun_path), SOCKET_UNIX_DOMAIN_FILE); -- if (bind(*socket_fd, (struct sockaddr *)&socket_addr, sizeof(struct sockaddr_un)) < 0) { -+ ((struct sockaddr_in *)server_addr)->sin_port = sport; -+ if (bind(*socket_fd, (struct sockaddr *)server_addr, addr_len) < 0) { - PRINT_ERROR("can't bind the address to socket %d! ", errno); - return PROGRAM_FAULT; - } -+ } -+ return PROGRAM_OK; -+} - -- if (listen(*socket_fd, SERVER_SOCKET_LISTEN_BACKLOG) < 0) { -- PRINT_ERROR("server socket can't lisiten %d! ", errno); -+static int32_t pocess_unix_create_connect(int32_t *socket_fd) -+{ -+ *socket_fd = socket(AF_UNIX, SOCK_STREAM, 0); -+ if (*socket_fd < 0) { -+ PRINT_ERROR("client can't create socket %d! ", errno); -+ return PROGRAM_FAULT; -+ } -+ -+ struct sockaddr_un server_addr; -+ server_addr.sun_family = AF_UNIX; -+ strcpy_s(server_addr.sun_path, sizeof(server_addr.sun_path), SOCKET_UNIX_DOMAIN_FILE); -+ if (connect(*socket_fd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr_un)) < 0) { -+ if (errno == EINPROGRESS) { -+ return PROGRAM_INPROGRESS; -+ } else { -+ PRINT_ERROR("client can't connect to the server %d! ", errno); - return PROGRAM_FAULT; - } -- } else if (strcmp(domain, "udp") == 0) { -- struct sockaddr_in socket_addr; -- memset_s(&socket_addr, sizeof(socket_addr), 0, sizeof(socket_addr)); -- socket_addr.sin_family = AF_INET; -- socket_addr.sin_port = port; -- -- if (groupip) { -- struct ip_mreq mreq; -- mreq.imr_multiaddr.s_addr = groupip; -- mreq.imr_interface.s_addr = ip; -- if (setsockopt(*socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(struct ip_mreq)) == -1) { -- PRINT_ERROR("can't set the address to group %d! ", errno); -- return PROGRAM_FAULT;; -+ } -+ return PROGRAM_OK; -+} -+ -+static int32_t pocess_udp_multicast(int32_t *socket_fd, struct ClientUnit *client_unit, sockaddr_t *server_addr) -+{ -+ const uint32_t loop = client_unit->loop; -+ ip_addr_t *groupip = &client_unit->groupip; -+ if (client_unit->protocol_type_mode == UDP_MULTICAST) { -+ /* set the local device for a multicast socket */ -+ ((struct sockaddr_in *)server_addr)->sin_addr = groupip->u_addr.ip4; -+ -+ struct in_addr localInterface; -+ localInterface.s_addr = client_unit->groupip_interface.u_addr.ip4.s_addr; -+ if (localInterface.s_addr) { -+ if (setsockopt(*socket_fd, IPPROTO_IP, IP_MULTICAST_IF, (char *)&localInterface, -+ sizeof(localInterface)) < 0) { -+ PRINT_ERROR("can't set the multicast interface %d! ", errno); -+ return PROGRAM_FAULT; - } -- socket_addr.sin_addr.s_addr = groupip; -- } else { -- socket_addr.sin_addr.s_addr = ip; - } - -- if (bind(*socket_fd, (struct sockaddr *)&socket_addr, sizeof(struct sockaddr_in)) < 0) { -- PRINT_ERROR("can't bind the address to socket %d! ", errno); -+ /* sent multicast packets should be looped back to the local socket */ -+ if (setsockopt(*socket_fd, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) == -1) { -+ PRINT_ERROR("can't set the multicast loop %d! ", errno); - return PROGRAM_FAULT; -- } -+ } - } -- - return PROGRAM_OK; - } - - // create the socket and connect --int32_t create_socket_and_connect(int32_t *socket_fd, in_addr_t ip, in_addr_t groupip, uint16_t port, uint16_t sport, const char *domain, const char *api) -+int32_t create_socket_and_connect(int32_t *socket_fd, struct ClientUnit *client_unit) - { -+ ip_addr_t *ip = &client_unit->ip; -+ const char *domain = client_unit->domain; -+ const char *api = client_unit->api; -+ -+ sockaddr_t server_addr; -+ - if (strcmp(domain, "tcp") == 0 || strcmp(domain, "udp") == 0) { -- if (strcmp(domain, "tcp") == 0) { -- *socket_fd = socket(AF_INET, SOCK_STREAM, 0); -- } else { -- *socket_fd = socket(AF_INET, SOCK_DGRAM, 0); -- } -- if (*socket_fd < 0) { -- PRINT_ERROR("client can't create socket %d! ", errno); -+ uint32_t addr_len = ip->addr_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); -+ memset_s(&server_addr, addr_len, 0, addr_len); -+ -+ if (creat_socket_init(socket_fd, client_unit, &server_addr) != PROGRAM_OK) { - return PROGRAM_FAULT; - } - -- if (set_socket_unblock(*socket_fd) < 0) { -- PRINT_ERROR("can't set the socket to unblock! "); -+ if (pocess_connect_sport(socket_fd, client_unit, &server_addr) < 0) { - return PROGRAM_FAULT; - } - -- struct sockaddr_in server_addr; -- memset_s(&server_addr, sizeof(server_addr), 0, sizeof(server_addr)); -- server_addr.sin_family = AF_INET; -- if (sport) { -- server_addr.sin_addr.s_addr = htonl(INADDR_ANY); -- server_addr.sin_port = sport; -- if (bind(*socket_fd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr_in)) < 0) { -- PRINT_ERROR("can't bind the address to socket %d! ", errno); -- return PROGRAM_FAULT; -- } -+ if (ip->addr_family == AF_INET) { -+ ((struct sockaddr_in *)&server_addr)->sin_addr = ip->u_addr.ip4; -+ } else if (ip->addr_family == AF_INET6) { -+ ((struct sockaddr_in6 *)&server_addr)->sin6_addr = ip->u_addr.ip6; - } -- server_addr.sin_addr.s_addr = ip; -- server_addr.sin_port = port; -+ ((struct sockaddr_in *)&server_addr)->sin_port = client_unit->port; -+ - if (strcmp(domain, "udp") == 0) { -- if (groupip) { -- server_addr.sin_addr.s_addr = groupip; -- if (setsockopt(*socket_fd, IPPROTO_IP, IP_MULTICAST_IF, &ip, sizeof(ip)) != 0) { -- PRINT_ERROR("can't set the multicast interface %d! ", errno); -- return PROGRAM_FAULT; -- } -+ int32_t ret = pocess_udp_multicast(socket_fd, client_unit, &server_addr); -+ if (ret != PROGRAM_OK) { -+ return ret; - } - } -+ - if (strcmp(domain, "udp") != 0 || strcmp(api, "recvfromsendto") != 0) { -- if (connect(*socket_fd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr_in)) < 0) { -+ if (connect(*socket_fd, (struct sockaddr *)&server_addr, addr_len) < 0) { - if (errno == EINPROGRESS) { - return PROGRAM_INPROGRESS; - } else { -@@ -157,25 +349,11 @@ int32_t create_socket_and_connect(int32_t *socket_fd, in_addr_t ip, in_addr_t gr - } - } - } else if (strcmp(domain, "unix") == 0) { -- *socket_fd = socket(AF_UNIX, SOCK_STREAM, 0); -- if (*socket_fd < 0) { -- PRINT_ERROR("client can't create socket %d! ", errno); -- return PROGRAM_FAULT; -- } -- -- struct sockaddr_un server_addr; -- server_addr.sun_family = AF_UNIX; -- strcpy_s(server_addr.sun_path, sizeof(server_addr.sun_path), SOCKET_UNIX_DOMAIN_FILE); -- if (connect(*socket_fd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr_un)) < 0) { -- if (errno == EINPROGRESS) { -- return PROGRAM_INPROGRESS; -- } else { -- PRINT_ERROR("client can't connect to the server %d! ", errno); -- return PROGRAM_FAULT; -- } -+ int32_t ret = pocess_unix_create_connect(socket_fd); -+ if (ret != PROGRAM_OK) { -+ return ret; - } - } -- - return PROGRAM_OK; - } - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 3e6eeef..e272a04 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -655,7 +655,6 @@ int32_t stack_setup_thread(void) - goto OUT1; - } - } -- - for (uint32_t i = 0; i < queue_num; i++) { - if (get_global_cfg_params()->seperate_send_recv) { - if (i % 2 == 0) { -@@ -694,6 +693,7 @@ int32_t stack_setup_thread(void) - g_stack_group.stack_num = queue_num; - - return 0; -+ - OUT1: - for (int32_t i = 0; i < queue_num; ++i) { - if (t_params[i] != NULL) { --- -2.33.0 - diff --git a/0213-cleancode-improving-makefile-readability.patch b/0213-cleancode-improving-makefile-readability.patch deleted file mode 100644 index 448293448c7cef5d11479f10c184e69e8a6af34b..0000000000000000000000000000000000000000 --- a/0213-cleancode-improving-makefile-readability.patch +++ /dev/null @@ -1,1154 +0,0 @@ -From 871a94d0abdf14efb9dfe42b711acc37d842ce6d Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 8 Jul 2024 20:35:10 +0800 -Subject: [PATCH] cleancode: improving makefile readability - -Signed-off-by: Lemmy Huang ---- - build/build.sh | 8 +- - src/common/dir.mk | 13 --- - src/lstack/Makefile | 92 +++++++-------- - src/lstack/Printlog.mk | 14 +++ - src/lstack/api/dir.mk | 14 --- - src/lstack/api/lstack_epoll.c | 4 +- - src/lstack/api/lstack_rtw_api.c | 2 +- - src/lstack/api/lstack_signal.c | 4 +- - src/lstack/api/lstack_wrap.c | 3 +- - src/lstack/core/dir.mk | 13 --- - src/lstack/core/lstack_cfg.c | 5 +- - src/lstack/core/lstack_control_plane.c | 4 +- - src/lstack/core/lstack_dpdk.c | 3 +- - src/lstack/core/lstack_init.c | 5 +- - src/lstack/core/lstack_lwip.c | 4 +- - src/lstack/core/lstack_preload.c | 1 - - src/lstack/core/lstack_protocol_stack.c | 6 +- - src/lstack/core/lstack_stack_stat.c | 4 +- - src/lstack/include/lstack_cfg.h | 2 +- - src/lstack/include/lstack_dpdk.h | 4 +- - src/lstack/include/lstack_fault_inject.h | 2 + - src/lstack/include/lstack_lwip.h | 2 +- - src/lstack/include/lstack_protocol_stack.h | 4 +- - src/lstack/include/posix/lstack_epoll.h | 4 +- - src/lstack/netif/dir.mk | 15 --- - src/lstack/netif/lstack_ethdev.c | 2 +- - src/lstack/netif/lstack_fault_inject.c | 4 + - src/lstack/netif/lstack_flow.c | 2 +- - src/lstack/netif/lstack_tx_cache.c | 2 +- - src/lstack/netif/lstack_vdev.c | 4 +- - src/ltran/CMakeLists.txt | 127 ++++++++++++--------- - src/ltran/ltran_base.h | 2 +- - src/ltran/ltran_dfx.c | 2 +- - src/ltran/ltran_ethdev.c | 6 +- - src/ltran/ltran_ethdev.h | 2 +- - src/ltran/ltran_forward.c | 2 +- - src/ltran/ltran_instance.c | 6 +- - src/ltran/ltran_instance.h | 4 +- - src/ltran/ltran_monitor.c | 4 +- - src/ltran/ltran_param.c | 4 +- - src/ltran/ltran_param.h | 2 +- - src/ltran/ltran_stack.c | 2 +- - src/ltran/ltran_stat.c | 4 +- - src/ltran/ltran_stat.h | 2 +- - src/ltran/ltran_tcp_conn.h | 2 +- - src/ltran/ltran_tcp_sock.c | 2 +- - src/ltran/ltran_tcp_sock.h | 2 +- - src/ltran/main.c | 2 +- - 48 files changed, 200 insertions(+), 223 deletions(-) - delete mode 100644 src/common/dir.mk - create mode 100644 src/lstack/Printlog.mk - delete mode 100644 src/lstack/api/dir.mk - delete mode 100644 src/lstack/core/dir.mk - delete mode 100644 src/lstack/netif/dir.mk - -diff --git a/build/build.sh b/build/build.sh -index 622e1cc..ed6d444 100755 ---- a/build/build.sh -+++ b/build/build.sh -@@ -12,8 +12,10 @@ - export CURRENT_PATH=$(dirname $(readlink -f ${BASH_SOURCE[0]})) - cd $CURRENT_PATH - -+cpu_num=8 -+ - make -C ../src/lstack clean --make -C ../src/lstack -+make -C ../src/lstack -j${cpu_num} - if [ $? -ne 0 ]; then - echo "build lstack failed" - exit 1 -@@ -24,7 +26,7 @@ rm -f CMakeCache.txt - rm -f ltran gazellectl - rm -rf CMakeFiles - cmake . --make -+make -j${cpu_num} - if [ $? -ne 0 ]; then - echo "build ltran failed" - exit 1 -@@ -33,7 +35,7 @@ fi - cd - - cd ../examples - cmake . --make -+make -j${cpu_num} - if [ $? -ne 0 ]; then - echo "build examples failed" - exit 1 -diff --git a/src/common/dir.mk b/src/common/dir.mk -deleted file mode 100644 -index 68a2b72..0000000 ---- a/src/common/dir.mk -+++ /dev/null -@@ -1,13 +0,0 @@ --# 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. -- --SRC = dpdk_common.c gazelle_parse_config.c --$(eval $(call register_dir, ../common, $(SRC))) -- -diff --git a/src/lstack/Makefile b/src/lstack/Makefile -index ace33bd..dd4e2c4 100644 ---- a/src/lstack/Makefile -+++ b/src/lstack/Makefile -@@ -7,40 +7,28 @@ - # IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - # PURPOSE. - # See the Mulan PSL v2 for more details. --LSTACK_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) --ROOT_DIR := $(dir $(abspath $(LSTACK_DIR))) -+ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) -+ -+include $(ROOT_DIR)/Printlog.mk - --LWIP_INCLUDE_FILE ?= /usr/include/lwip - LIB_PATH ?= /usr/lib64 -+LWIP_INCLUDE_DIR ?= /usr/include/lwip - - DPDK_VERSION := $(shell rpm -q --queryformat '%{VERSION}' dpdk) - ifeq ($(DPDK_VERSION),21.11) -- DPDK_INCLUDE_FILE := /usr/local/include -+ DPDK_INCLUDE_DIR := /usr/local/include - else -- DPDK_INCLUDE_FILE := /usr/include/dpdk -+ DPDK_INCLUDE_DIR := /usr/include/dpdk - endif - - AR = ar - ARFLAGS = crDP - CC ?= gcc --OPTIMIZATION = -O2 -g - RM = rm -f --LDFLAGS = -shared -ldl -lm -lpthread -lrt -lnuma -lconfig -lboundscheck - ARCH := $(shell uname -m) - --ifneq ($(CC),clang) -- SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wno-deprecated-declarations -Wl,-z,relro, -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIFY_SOURCE=2 --else -- SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wno-deprecated-declarations -fPIC --endif --$(info $(CC):$(SEC_FLAGS)) -- --INC = -I$(LSTACK_DIR)/include \ -- -I$(LSTACK_DIR)/../common \ -- -I$(LWIP_INCLUDE_FILE) \ -- -I$(DPDK_INCLUDE_FILE) -- --CFLAGS += $(OPTIMIZATION) -fno-strict-aliasing $(INC) -Wno-error=unused-function -+CFLAGS = -O2 -g -+LDFLAGS = -shared -ldl -lm -lpthread -lrt -lnuma -lconfig -lboundscheck - - ifeq ($(GAZELLE_COVERAGE_ENABLE), 1) - LDFLAGS += -fprofile-arcs -ftest-coverage -@@ -48,7 +36,6 @@ ifeq ($(GAZELLE_COVERAGE_ENABLE), 1) - endif - - ifeq ($(GAZELLE_FAULT_INJECT_ENABLE), 1) -- LDFLAGS += -DGAZELLE_FAULT_INJECT_ENABLE - CFLAGS += -DGAZELLE_FAULT_INJECT_ENABLE - endif - -@@ -56,19 +43,21 @@ ifeq ($(shell $(CC) -dumpmachine | cut -d"-" -f1), x86_64) - CFLAGS += -mssse3 - endif - --CFLAGS += $(SEC_FLAGS) -- --SRCS = --DIRS = core netif api ../common -+SEC_FLAGS = -Wall -Werror -fstack-protector-strong -Wno-deprecated-declarations -fPIC -+ifneq ($(CC),clang) -+ SEC_FLAGS += -Wl,-z,relro, -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -D_FORTIFY_SOURCE=2 -+endif - --define register_dir --SRCS += $(patsubst %, $(1)/%, $(2)) --endef -+INC = -I$(ROOT_DIR)/include \ -+ -I$(ROOT_DIR)/../ \ -+ -I$(LWIP_INCLUDE_DIR) \ -+ -I$(DPDK_INCLUDE_DIR) - --include $(patsubst %, %/dir.mk, $(DIRS)) -+CFLAGS += -fno-strict-aliasing -Wno-error=unused-function -+CFLAGS += -D__USE_GNU=1 -D_GNU_SOURCE=1 -+CFLAGS += $(SEC_FLAGS) -+CFLAGS += $(INC) - --# Linking object and library --OBJS = $(subst .c,.o,$(SRCS)) - - LWIP_LIB = $(LIB_PATH)/liblwip.a - LIBRTE_LIB = $(LIB_PATH)/librte_pci.so \ -@@ -98,9 +87,9 @@ ifeq ($(DPDK_VERSION), 19.11) - $(LIB_PATH)/librte_pmd_hinic.so \ - $(LIB_PATH)/librte_pmd_ixgbe.so \ - $(LIB_PATH)/librte_pmd_virtio.so -- ifneq ($(ARCH), loongarch64) -- LIBRTE_LIB += $(LIB_PATH)/librte_pmd_i40e.so -- endif -+ ifneq ($(ARCH), loongarch64) -+ LIBRTE_LIB += $(LIB_PATH)/librte_pmd_i40e.so -+ endif - else - LIBRTE_LIB += $(LIB_PATH)/librte_net_pcap.so \ - $(LIB_PATH)/librte_net_bond.so \ -@@ -109,31 +98,38 @@ else - $(LIB_PATH)/librte_net_virtio.so \ - $(LIB_PATH)/librte_telemetry.so \ - $(LIB_PATH)/librte_pcapng.so -- ifeq ($(filter loongarch64 riscv64, $(ARCH)),) -- LIBRTE_LIB += $(LIB_PATH)/librte_net_i40e.so -- endif -+ ifeq ($(filter loongarch64 riscv64, $(ARCH)),) -+ LIBRTE_LIB += $(LIB_PATH)/librte_net_i40e.so -+ endif - endif - - DEP_LIBS = $(LWIP_LIB) $(LIBRTE_LIB) -+$(info $(CC):$(DEP_LIBS)) -+ -+SRCS = $(wildcard ./api/*.c ./core/*.c ./netif/*.c ../common/*.c) -+# Linking object and library -+OBJS = $(subst .c,.o,$(SRCS)) -+ - LDFLAGS += -Wl,--whole-archive $(DEP_LIBS) $(OBJS) -Wl,--no-whole-archive - -+$(info [CFLAGS] $(CFLAGS)) -+$(info [LDFLAGS] $(LDFLAGS)) -+ - # Target - LSTACK_SHARED_LIB = liblstack.so - LSTACK_STATIC_LIB = liblstack.a - --.PHONY: all -+.PHONY: all clean - all: $(LSTACK_SHARED_LIB) - --depend: .depend -- --.depend: $(SRCS) -- rm -f ./.depend -- $(foreach SRC,$(SRCS),$(CC) $(CFLAGS) -MM -MT $(SRC:.c=.o) $(SRC) >> .depend;) -- ---include .depend -- - $(LSTACK_SHARED_LIB): $(OBJS) -- $(CC) $(LDFLAGS) -Wl,--whole-archive -Wl,--no-whole-archive -o $@ -+ $(call printlog, BUILD, $@) -+ $(QUIET) $(CC) $(LDFLAGS) -o $@ -+ -+%.o: %.c -+ $(call printlog, BUILD, $@) -+ $(QUIET) $(CC) $(CFLAGS) -c $(filter %.c,$^) -o $@ - - clean: -- $(RM) $(LSTACK_SHARED_LIB) $(OBJS) .depend -+ $(call printlog, CLEAN, $(LSTACK_SHARED_LIB)) -+ $(QUIET) $(RM) $(LSTACK_SHARED_LIB) $(OBJS) -diff --git a/src/lstack/Printlog.mk b/src/lstack/Printlog.mk -new file mode 100644 -index 0000000..7604851 ---- /dev/null -+++ b/src/lstack/Printlog.mk -@@ -0,0 +1,14 @@ -+ -+ROOT_DIR ?= $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) -+ -+ifeq ($(V),1) -+ QUIET = -+ printlog = -+else -+ QUIET = @ -+ printlog = @printf ' %-8s %s%s\n' \ -+ "$(1)" \ -+ "$(patsubst $(ROOT_DIR)/%,%,$(2))" \ -+ "$(if $(3), $(3))"; -+ MAKEFLAGS += --no-print-directory -+endif -diff --git a/src/lstack/api/dir.mk b/src/lstack/api/dir.mk -deleted file mode 100644 -index 729690d..0000000 ---- a/src/lstack/api/dir.mk -+++ /dev/null -@@ -1,14 +0,0 @@ --# 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. -- --SRC = lstack_epoll.c lstack_signal.c lstack_fork.c lstack_wrap.c lstack_rtw_api.c lstack_rtc_api.c lstack_dummy_api.c -- --$(eval $(call register_dir, api, $(SRC))) -- -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 2ac7150..9c0aef7 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -31,8 +31,8 @@ - #include "lstack_stack_stat.h" - #include "lstack_cfg.h" - #include "lstack_log.h" --#include "dpdk_common.h" --#include "gazelle_base_func.h" -+#include "common/dpdk_common.h" -+#include "common/gazelle_base_func.h" - #include "lstack_lwip.h" - #include "lstack_protocol_stack.h" - #include "posix/lstack_epoll.h" -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index e50fe37..e43be59 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -22,7 +22,7 @@ - #include "lstack_protocol_stack.h" - #include "lstack_cfg.h" - #include "lstack_lwip.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_base_func.h" - #include "lstack_rtw_api.h" - - -diff --git a/src/lstack/api/lstack_signal.c b/src/lstack/api/lstack_signal.c -index 314c14c..3dd5d03 100644 ---- a/src/lstack/api/lstack_signal.c -+++ b/src/lstack/api/lstack_signal.c -@@ -18,9 +18,9 @@ - #include - #include - --#include "gazelle_base_func.h" -+#include "common/gazelle_base_func.h" - #include "lstack_cfg.h" --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "lstack_log.h" - #include "lstack_control_plane.h" - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 7101d98..3a60cbb 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -10,7 +10,6 @@ - * See the Mulan PSL v2 for more details. - */ - --#define _GNU_SOURCE - #include - #include - #include -@@ -31,7 +30,7 @@ - #include "lstack_log.h" - #include "lstack_cfg.h" - #include "lstack_lwip.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_base_func.h" - #include "lstack_preload.h" - - #include "lstack_rtc_api.h" -diff --git a/src/lstack/core/dir.mk b/src/lstack/core/dir.mk -deleted file mode 100644 -index 21b0d22..0000000 ---- a/src/lstack/core/dir.mk -+++ /dev/null -@@ -1,13 +0,0 @@ --# 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. -- --SRC = lstack_preload.c lstack_init.c lstack_cfg.c lstack_dpdk.c lstack_control_plane.c lstack_stack_stat.c lstack_lwip.c lstack_protocol_stack.c lstack_thread_rpc.c lstack_virtio.c lstack_port_map.c --$(eval $(call register_dir, core, $(SRC))) -- -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index a165cdb..4bc4217 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -10,7 +10,6 @@ - * See the Mulan PSL v2 for more details. - */ - --#define _GNU_SOURCE - #include - #include - #include -@@ -29,9 +28,9 @@ - #include - #include - --#include "gazelle_reg_msg.h" -+#include "common/gazelle_reg_msg.h" -+#include "common/gazelle_base_func.h" - #include "lstack_log.h" --#include "gazelle_base_func.h" - #include "lstack_cfg.h" - - #define DEFAULT_CONF_FILE "/etc/gazelle/lstack.conf" -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 04858c7..4ab12f6 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -26,8 +26,8 @@ - - #include "lstack_cfg.h" - #include "lstack_dpdk.h" --#include "gazelle_reg_msg.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_reg_msg.h" -+#include "common/gazelle_base_func.h" - #include "lstack_stack_stat.h" - #include "lstack_log.h" - #include "lstack_thread_rpc.h" -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 2de41e3..583bb09 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -10,7 +10,6 @@ - * See the Mulan PSL v2 for more details. - */ - --#define _GNU_SOURCE - #include - #include - #include -@@ -44,7 +43,7 @@ - #include - - #include "lstack_log.h" --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "lstack_protocol_stack.h" - #include "lstack_thread_rpc.h" - #include "lstack_lwip.h" -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index c2499d7..d97b218 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -10,7 +10,6 @@ - * See the Mulan PSL v2 for more details. - */ - --#define _GNU_SOURCE - #include - #include - #include -@@ -41,10 +40,10 @@ - #include "lstack_dpdk.h" - #include "lstack_stack_stat.h" - #include "lstack_log.h" --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "posix/lstack_epoll.h" - #include "posix/lstack_unistd.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_base_func.h" - #include "lstack_protocol_stack.h" - #include "lstack_preload.h" - #include "lstack_wrap.h" -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 3728100..6e50e4d 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -27,7 +27,7 @@ - #include - #include - --#include "gazelle_base_func.h" -+#include "common/gazelle_base_func.h" - #include "lstack_ethdev.h" - #include "lstack_protocol_stack.h" - #include "lstack_log.h" -@@ -35,7 +35,7 @@ - #include "lstack_stack_stat.h" - #include "posix/lstack_epoll.h" - #include "lstack_thread_rpc.h" --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "lstack_cfg.h" - #include "lstack_lwip.h" - -diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c -index 1d68501..f7caef5 100644 ---- a/src/lstack/core/lstack_preload.c -+++ b/src/lstack/core/lstack_preload.c -@@ -12,7 +12,6 @@ - #include - #include - #include --#define __USE_GNU - #include - #include - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index e272a04..1983c0b 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -9,7 +9,7 @@ - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ --#define _GNU_SOURCE -+ - #include - #include - -@@ -22,9 +22,9 @@ - #include - #include - --#include "gazelle_base_func.h" -+#include "common/gazelle_base_func.h" - #include "lstack_thread_rpc.h" --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "lstack_log.h" - #include "lstack_dpdk.h" - #include "lstack_ethdev.h" -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 1e32c45..423be81 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -22,8 +22,8 @@ - #include "posix_api.h" - #include "lstack_control_plane.h" - #include "lstack_log.h" --#include "dpdk_common.h" --#include "gazelle_dfx_msg.h" -+#include "common/dpdk_common.h" -+#include "common/gazelle_dfx_msg.h" - #include "lstack_thread_rpc.h" - #include "lstack_protocol_stack.h" - #include "posix/lstack_epoll.h" -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index a15088a..4fc99f3 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -20,7 +20,7 @@ - #include - - #include "lstack_protocol_stack.h" --#include "gazelle_opt.h" -+#include "common/gazelle_opt.h" - - #define BASE_BIN_SCALE 2 - #define BASE_OCT_SCALE 8 -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index dff1e44..91af3c5 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -14,8 +14,8 @@ - #define _GAZELLE_DPDK_H_ - - #include --#include "gazelle_opt.h" --#include "gazelle_dfx_msg.h" -+#include "common/gazelle_opt.h" -+#include "common/gazelle_dfx_msg.h" - - #define RXTX_CACHE_SZ (VDEV_RX_QUEUE_SZ) - -diff --git a/src/lstack/include/lstack_fault_inject.h b/src/lstack/include/lstack_fault_inject.h -index afd8faf..a65c61f 100644 ---- a/src/lstack/include/lstack_fault_inject.h -+++ b/src/lstack/include/lstack_fault_inject.h -@@ -15,6 +15,8 @@ - - #include - -+#include "common/gazelle_dfx_msg.h" -+ - int32_t handle_fault_inject_cmd(int32_t sockfd, struct gazelle_fault_inject_data inject, enum GAZELLE_STAT_MODE stat_mode); - - #endif /* __GAZELLE_INJECT_H__ */ -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index 85c9c20..0b952ec 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -14,7 +14,7 @@ - #define __GAZELLE_LWIP_H__ - #include - --#include "gazelle_dfx_msg.h" -+#include "common/gazelle_dfx_msg.h" - - #define NETCONN_IS_ACCEPTIN(sock) (((sock)->conn->acceptmbox != NULL) && !sys_mbox_empty((sock)->conn->acceptmbox)) - #define NETCONN_IS_DATAIN(sock) ((gazelle_ring_readable_count((sock)->recv_ring) || (sock)->recv_lastdata) || (sock->same_node_rx_ring != NULL && same_node_ring_count(sock))) -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 6ca4f14..5b04c6d 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -20,11 +20,11 @@ - #include - #include - --#include "gazelle_dfx_msg.h" -+#include "common/gazelle_opt.h" -+#include "common/gazelle_dfx_msg.h" - #include "lstack_thread_rpc.h" - #include "lstack_ethdev.h" - #include "lstack_tx_cache.h" --#include "gazelle_opt.h" - - #define SOCK_RECV_RING_SIZE (get_global_cfg_params()->recv_ring_size) - #define SOCK_RECV_FREE_THRES (32) -diff --git a/src/lstack/include/posix/lstack_epoll.h b/src/lstack/include/posix/lstack_epoll.h -index a7164f4..77b6ebb 100644 ---- a/src/lstack/include/posix/lstack_epoll.h -+++ b/src/lstack/include/posix/lstack_epoll.h -@@ -20,8 +20,8 @@ - - #include - --#include "gazelle_dfx_msg.h" --#include "gazelle_opt.h" -+#include "common/gazelle_dfx_msg.h" -+#include "common/gazelle_opt.h" - - #ifdef __cplusplus - extern "C" { -diff --git a/src/lstack/netif/dir.mk b/src/lstack/netif/dir.mk -deleted file mode 100644 -index b551041..0000000 ---- a/src/lstack/netif/dir.mk -+++ /dev/null -@@ -1,15 +0,0 @@ --# 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. -- --SRC = lstack_ethdev.c lstack_vdev.c lstack_flow.c lstack_tx_cache.c --ifeq ($(GAZELLE_FAULT_INJECT_ENABLE), 1) -- SRC += lstack_fault_inject.c --endif --$(eval $(call register_dir, netif, $(SRC))) -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 933c3e8..e23d313 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -24,7 +24,7 @@ - - #include - --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "lstack_cfg.h" - #include "lstack_vdev.h" - #include "lstack_stack_stat.h" -diff --git a/src/lstack/netif/lstack_fault_inject.c b/src/lstack/netif/lstack_fault_inject.c -index 4edc6cc..4736e29 100644 ---- a/src/lstack/netif/lstack_fault_inject.c -+++ b/src/lstack/netif/lstack_fault_inject.c -@@ -20,6 +20,9 @@ - #include "lstack_log.h" - #include "lstack_vdev.h" - -+#ifdef GAZELLE_FAULT_INJECT_ENABLE -+#include "lstack_fault_inject.h" -+ - #define INJECT_MODULO 1000 /* used in modulus operator */ - #define INJECT_US_TO_MS 1000 /* transefer time unit us to ms */ - -@@ -371,3 +374,4 @@ int32_t handle_fault_inject_cmd(int32_t sockfd, struct gazelle_fault_inject_data - return inject_set_cmd(sockfd, inject); - } - -+#endif /* GAZELLE_FAULT_INJECT_ENABLE */ -diff --git a/src/lstack/netif/lstack_flow.c b/src/lstack/netif/lstack_flow.c -index 9e8792c..84497dc 100644 ---- a/src/lstack/netif/lstack_flow.c -+++ b/src/lstack/netif/lstack_flow.c -@@ -22,7 +22,7 @@ - #include - #include - --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "lstack_log.h" - #include "lstack_dpdk.h" - #include "lstack_cfg.h" -diff --git a/src/lstack/netif/lstack_tx_cache.c b/src/lstack/netif/lstack_tx_cache.c -index ac5a9db..cda0003 100644 ---- a/src/lstack/netif/lstack_tx_cache.c -+++ b/src/lstack/netif/lstack_tx_cache.c -@@ -15,7 +15,7 @@ - #include "lwip/sockets.h" - #include "lstack_ethdev.h" - #include "lstack_log.h" --#include "gazelle_opt.h" -+#include "common/gazelle_opt.h" - #include "lstack_protocol_stack.h" - #include "lstack_tx_cache.h" - -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 75e4acc..63f9e40 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -29,9 +29,9 @@ - #include "lstack_ethdev.h" - #include "lstack_control_plane.h" - #include "lstack_log.h" --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "lstack_protocol_stack.h" --#include "gazelle_reg_msg.h" -+#include "common/gazelle_reg_msg.h" - #include "lstack_lwip.h" - #include "lstack_flow.h" - #include "lstack_vdev.h" -diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt -index fee3a94..8e9b1ea 100644 ---- a/src/ltran/CMakeLists.txt -+++ b/src/ltran/CMakeLists.txt -@@ -12,25 +12,7 @@ cmake_minimum_required(VERSION 3.12.1) - project(ltran) - - set(COMMON_DIR ${PROJECT_SOURCE_DIR}/../common) --set(LWIP_DIR /usr/include/lwip) -- --set(CMAKE_VERBOSE_MAKEFILE ON) --if (CMAKE_C_COMPILER_ID STREQUAL "GNU") -- set(CMAKE_C_FLAGS "-g -fstack-protector-strong -Wall -Werror -fPIE -pie -pthread -D_FORTIFY_SOURCE=2 -O2 -fPIC") --elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") -- set(CMAKE_C_FLAGS "-O2 -g -fstack-protector-strong -Wall -Werror -fPIE -pthread") --endif() --set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D LTRAN_COMPILE") -- --if($ENV{GAZELLE_COVERAGE_ENABLE}) -- message("Enable Coverage compile option") -- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs") --endif($ENV{GAZELLE_COVERAGE_ENABLE}) -- --if($ENV{GAZELLE_FAULT_INJECT_ENABLE}) -- message("Enable Fault inject option") -- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGAZELLE_FAULT_INJECT_ENABLE") --endif($ENV{GAZELLE_FAULT_INJECT_ENABLE}) -+set(LWIP_INCLUDE_DIR /usr/include/lwip) - - execute_process( - COMMAND rpm -qa dpdk -@@ -40,62 +22,99 @@ execute_process( - string(REGEX MATCH "[0-9]+\\.[0-9]+" DPDK_VERSION ${DPDK_VERSION_FULL}) - - if (DPDK_VERSION STREQUAL "21.11") -- set(DPDK_DIR /usr/local/include/) -+ set(DPDK_INCLUDE_DIR /usr/local/include/) - else() -- set(DPDK_DIR /usr/include/dpdk) -+ set(DPDK_INCLUDE_DIR /usr/include/dpdk) -+endif() -+ -+ -+set(CMAKE_C_FLAGS "-O2 -g") -+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLTRAN_COMPILE -D_GNU_SOURCE -fno-strict-aliasing") -+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -fstack-protector-strong -fPIE") -+if (CMAKE_C_COMPILER_ID STREQUAL "GNU") -+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -D_FORTIFY_SOURCE=2 -fPIC") -+endif() -+ -+# gcc coredump in openEuler-20.03-LTS-XX aarch64 when add -march=native -+if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "sw_64|aarch64|ppc64le|riscv64" ) -+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -Wcast-align") - endif() - -+if($ENV{GAZELLE_COVERAGE_ENABLE}) -+ message("Enable Coverage compile option") -+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs") -+endif($ENV{GAZELLE_COVERAGE_ENABLE}) -+ -+if($ENV{GAZELLE_FAULT_INJECT_ENABLE}) -+ message("Enable Fault inject option") -+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGAZELLE_FAULT_INJECT_ENABLE") -+endif($ENV{GAZELLE_FAULT_INJECT_ENABLE}) -+ -+set(LTRAN_C_FLAGS -D__ARM_FEATURE_CRC32=1 -+ -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition -+ -Wpointer-arith -Wcast-qual -Wnested-externs -Wformat-nonliteral -Wformat-security -Wundef -+ -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough -Wno-error=deprecated-declarations) -+ -+set(DPDK_C_FLAGS -DRTE_MACHINE_CPUFLAG_NEON -DRTE_MACHINE_CPUFLAG_CRC32 -+ -DRTE_MACHINE_CPUFLAG_PMULL -DRTE_MACHINE_CPUFLAG_AES -+ -DRTE_MACHINE_CPUFLAG_SHA1 -DRTE_MACHINE_CPUFLAG_SHA2 -+ -include rte_config.h) -+ -+set(DPDK_LINK_FLAGS -Wl,-lrte_meter -Wl,-lrte_gro -Wl,-lrte_hash -Wl,-lrte_kvargs -+ -Wl,-lrte_mbuf -Wl,-lrte_ethdev -Wl,-lrte_net -Wl,-lrte_timer -Wl,-lrte_mempool -+ -Wl,-lrte_mempool_ring -Wl,-lrte_ring -Wl,-lrte_pci -Wl,-lrte_cmdline -+ -Wl,-lrte_bus_pci -Wl,-lrte_bus_vdev -Wl,-lrte_pdump) -+ - if (DPDK_VERSION STREQUAL "19.11") -- set(DPDK_LINK_FLAGS "-Wl,-lrte_pmd_bond -Wl,-lrte_pmd_hinic -Wl,-lrte_pmd_ixgbe \ -- -Wl,-lrte_pmd_pcap -Wl,-lrte_pmd_virtio") -+ set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -Wl,-lrte_pmd_bond -Wl,-lrte_pmd_hinic -Wl,-lrte_pmd_ixgbe -+ -Wl,-lrte_pmd_pcap -Wl,-lrte_pmd_virtio) - if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "loongarch64") -- set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-lrte_pmd_i40e") -+ set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -Wl,-lrte_pmd_i40e) - endif() - else() -- set(DPDK_LINK_FLAGS "-Wl,-lrte_net_bond -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe \ -- -Wl,-lpcap -Wl,-lrte_net_pcap -Wl,-lrte_net_virtio -Wl,-lrte_pcapng -Wl,-lrte_telemetry") -+ set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -Wl,-lrte_net_bond -Wl,-lrte_net_hinic -Wl,-lrte_net_ixgbe -+ -Wl,-lpcap -Wl,-lrte_net_pcap -Wl,-lrte_net_virtio -Wl,-lrte_pcapng -Wl,-lrte_telemetry) - if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "loongarch64|riscv64") -- set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-lrte_net_i40e") -+ set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -Wl,-lrte_net_i40e) - endif() - endif() - - if (DPDK_VERSION GREATER_EQUAL 23.11) -- set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -lrte_log -larchive -Wl,-lrte_eal") -+ set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -lrte_log -larchive -Wl,-lrte_eal) - else() -- set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -lrte_kni -Wl,-Bstatic -lrte_eal -Wl,-Bdynamic") -+ set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -lrte_kni -Wl,-Bstatic -Wl,-lrte_eal -Wl,-Bdynamic) - if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "ppc64le") -- set(DPDK_LINK_FLAGS "${DPDK_LINK_FLAGS} -Wl,-larchive") -+ set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -Wl,-larchive) - endif() - endif() - -+# compile info -+# set(CMAKE_VERBOSE_MAKEFILE ON) -+message("[CMAKE_C_FLAGS] ${CMAKE_C_FLAGS}") -+message("[LTRAN_C_FLAGS] ${LTRAN_C_FLAGS}") -+message("[DPDK_C_FLAGS ] ${DPDK_C_FLAGS}") -+message("[DPDK_LINK_FLAGS] ${DPDK_LINK_FLAGS}") -+ - add_executable(ltran main.c ltran_param.c ltran_config.c ltran_ethdev.c ltran_stat.c ltran_errno.c -- ltran_monitor.c ltran_instance.c ltran_stack.c ltran_tcp_conn.c ltran_tcp_sock.c -- ltran_forward.c ltran_timer.c ${COMMON_DIR}/gazelle_dfx_msg.c ${COMMON_DIR}/dpdk_common.c -- ${COMMON_DIR}/gazelle_parse_config.c) -- --target_include_directories(ltran PRIVATE ${COMMON_DIR} ${PROJECT_SOURCE_DIR} ${LWIP_DIR} ${DPDK_DIR}) --target_compile_options(ltran PRIVATE -fno-strict-aliasing -D__ARM_FEATURE_CRC32=1 -DRTE_MACHINE_CPUFLAG_NEON -- -DRTE_MACHINE_CPUFLAG_CRC32 -DRTE_MACHINE_CPUFLAG_PMULL -DRTE_MACHINE_CPUFLAG_AES -- -DRTE_MACHINE_CPUFLAG_SHA1 -DRTE_MACHINE_CPUFLAG_SHA2 -include rte_config.h -- -D_GNU_SOURCE -W -Wall -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition -- -Wpointer-arith -Wcast-qual -Wnested-externs -Wformat-nonliteral -Wformat-security -Wundef -- -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough -D_FORTIFY_SOURCE=2 -Wno-error=deprecated-declarations) -+ ltran_monitor.c ltran_instance.c ltran_stack.c ltran_tcp_conn.c ltran_tcp_sock.c -+ ltran_forward.c ltran_timer.c -+ ${COMMON_DIR}/gazelle_dfx_msg.c -+ ${COMMON_DIR}/dpdk_common.c -+ ${COMMON_DIR}/gazelle_parse_config.c) - --# gcc coredump in openEuler-20.03-LTS-XX aarch64 when add -march=native --if(NOT CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "sw_64|aarch64|ppc64le|riscv64" ) -- target_compile_options(ltran PRIVATE -march=native -Wcast-align) --endif() -+target_include_directories(ltran PRIVATE ${COMMON_DIR}/../ ${PROJECT_SOURCE_DIR} ${LWIP_INCLUDE_DIR} ${DPDK_INCLUDE_DIR}) - --target_link_libraries(ltran PRIVATE config boundscheck rte_pdump -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines) -+# COMPILE_FLAGS and LINK_FLAGS are deprecated. -+target_compile_options(ltran PRIVATE ${LTRAN_C_FLAGS} ${DPDK_C_FLAGS}) -+target_link_options(ltran PRIVATE -+ -Wl,--whole-archive ${DPDK_LINK_FLAGS} -Wl,--no-whole-archive -+ -Wl,--as-needed -Wl,-export-dynamic -+ -Wl,-Map=ltran.map -Wl,--cref) -+target_link_libraries(ltran PRIVATE pthread config boundscheck -+ -Wl,-lm -Wl,-lrt -Wl,-lnuma -Wl,-ldl -+ -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines) - --set_target_properties(ltran PROPERTIES LINK_FLAGS "-L$ENV{DPDK_LIB_PATH} -Wl,--no-whole-archive \ -- -Wl,-lrte_meter -Wl,--whole-archive -Wl,-lrte_gro -Wl,-lrte_hash -Wl,-lrte_kvargs -Wl,-lrte_mbuf -Wl,-lrte_ethdev \ -- -Wl,-lrte_net -Wl,-lrte_timer -Wl,-lrte_mempool -Wl,-lrte_mempool_ring -Wl,-lrte_ring -Wl,-lrte_pci \ -- -Wl,-lrte_cmdline -Wl,-lrte_bus_pci\ -- -Wl,-lrte_bus_vdev ${DPDK_LINK_FLAGS} \ -- -Wl,--no-whole-archive -Wl,-lm -Wl,-lrt -Wl,-lnuma -Wl,-ldl -Wl,-export-dynamic -Wl,-export-dynamic \ -- -Wl,--as-needed -Wl,-export-dynamic -Wl,-Map=ltran.map -Wl,--cref") - - add_executable(gazellectl ltran_dfx.c ${COMMON_DIR}/gazelle_dfx_msg.c) --target_include_directories(gazellectl PRIVATE $ENV{DPDK_INCLUDE_FILE} ${COMMON_DIR} ${DPDK_DIR}) -+target_include_directories(gazellectl PRIVATE ${COMMON_DIR}/../ ${DPDK_INCLUDE_DIR}) - target_link_libraries(gazellectl PRIVATE boundscheck -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack) -diff --git a/src/ltran/ltran_base.h b/src/ltran/ltran_base.h -index f174a40..9462fe5 100644 ---- a/src/ltran/ltran_base.h -+++ b/src/ltran/ltran_base.h -@@ -15,7 +15,7 @@ - - #include - --#include "gazelle_opt.h" -+#include "common/gazelle_opt.h" - - #define GAZELLE_CMD_BUFFER_SIZE _POSIX_ARG_MAX - #define GAZELLE_PATH_BUFFER_SIZE PATH_MAX -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index cdcd7b3..005b09c 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -30,7 +30,7 @@ - - #include "ltran_stat.h" - #include "ltran_base.h" --#include "gazelle_dfx_msg.h" -+#include "common/gazelle_dfx_msg.h" - - /* seeing show_usage() */ - #define GAZELLE_TARGET_ARG_IDX 1 -diff --git a/src/ltran/ltran_ethdev.c b/src/ltran/ltran_ethdev.c -index 2f08d4a..68dc786 100644 ---- a/src/ltran/ltran_ethdev.c -+++ b/src/ltran/ltran_ethdev.c -@@ -30,13 +30,13 @@ - - #include - --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "ltran_param.h" - #include "ltran_log.h" - #include "ltran_base.h" --#include "gazelle_opt.h" -+#include "common/gazelle_opt.h" - #include "ltran_errno.h" --#include "gazelle_reg_msg.h" -+#include "common/gazelle_reg_msg.h" - - uint32_t g_bond_num = 0; - FILE* g_log_file = NULL; -diff --git a/src/ltran/ltran_ethdev.h b/src/ltran/ltran_ethdev.h -index f720c55..b84baae 100644 ---- a/src/ltran/ltran_ethdev.h -+++ b/src/ltran/ltran_ethdev.h -@@ -15,7 +15,7 @@ - - #include - --#include "gazelle_opt.h" -+#include "common/gazelle_opt.h" - - struct port_info { - uint16_t num_ports; -diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c -index c49da89..c2f53d6 100644 ---- a/src/ltran/ltran_forward.c -+++ b/src/ltran/ltran_forward.c -@@ -28,7 +28,7 @@ - #include - #include - --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "ltran_instance.h" - #include "ltran_tcp_conn.h" - #include "ltran_tcp_sock.h" -diff --git a/src/ltran/ltran_instance.c b/src/ltran/ltran_instance.c -index fc5b0fb..428c1aa 100644 ---- a/src/ltran/ltran_instance.c -+++ b/src/ltran/ltran_instance.c -@@ -25,10 +25,10 @@ - #include "ltran_stat.h" - #include "ltran_log.h" - #include "ltran_base.h" --#include "gazelle_opt.h" -+#include "common/gazelle_opt.h" - #include "ltran_errno.h" --#include "gazelle_dfx_msg.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_dfx_msg.h" -+#include "common/gazelle_base_func.h" - #include "ltran_instance.h" - - volatile unsigned long g_tx_loop_count __rte_cache_aligned; -diff --git a/src/ltran/ltran_instance.h b/src/ltran/ltran_instance.h -index 2b888ec..f0fe580 100644 ---- a/src/ltran/ltran_instance.h -+++ b/src/ltran/ltran_instance.h -@@ -17,8 +17,8 @@ - #include - #include - --#include "gazelle_opt.h" --#include "gazelle_reg_msg.h" -+#include "common/gazelle_opt.h" -+#include "common/gazelle_reg_msg.h" - - struct gazelle_stack; - struct gazelle_instance { -diff --git a/src/ltran/ltran_monitor.c b/src/ltran/ltran_monitor.c -index 457e8c8..93ab2d5 100644 ---- a/src/ltran/ltran_monitor.c -+++ b/src/ltran/ltran_monitor.c -@@ -29,8 +29,8 @@ - #include "ltran_log.h" - #include "ltran_stat.h" - #include "ltran_instance.h" --#include "gazelle_dfx_msg.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_dfx_msg.h" -+#include "common/gazelle_base_func.h" - #include "ltran_param.h" - #include "ltran_monitor.h" - -diff --git a/src/ltran/ltran_param.c b/src/ltran/ltran_param.c -index bd5a8e1..ad689f6 100644 ---- a/src/ltran/ltran_param.c -+++ b/src/ltran/ltran_param.c -@@ -23,8 +23,8 @@ - #include "ltran_errno.h" - #include "ltran_base.h" - #include "ltran_log.h" --#include "gazelle_dfx_msg.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_dfx_msg.h" -+#include "common/gazelle_base_func.h" - #include "ltran_param.h" - - #define HEX_BASE 16 -diff --git a/src/ltran/ltran_param.h b/src/ltran/ltran_param.h -index 75addcd..e48b781 100644 ---- a/src/ltran/ltran_param.h -+++ b/src/ltran/ltran_param.h -@@ -17,7 +17,7 @@ - #include - #include - --#include "gazelle_opt.h" -+#include "common/gazelle_opt.h" - - struct ltran_config { - struct { -diff --git a/src/ltran/ltran_stack.c b/src/ltran/ltran_stack.c -index 2aed6c9..299fb7a 100644 ---- a/src/ltran/ltran_stack.c -+++ b/src/ltran/ltran_stack.c -@@ -16,7 +16,7 @@ - #include "ltran_instance.h" - #include "ltran_log.h" - #include "ltran_jhash.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_base_func.h" - #include "ltran_stack.h" - - struct gazelle_stack_htable *g_stack_htable = NULL; -diff --git a/src/ltran/ltran_stat.c b/src/ltran/ltran_stat.c -index dfd5fc9..0a8d75c 100644 ---- a/src/ltran/ltran_stat.c -+++ b/src/ltran/ltran_stat.c -@@ -21,12 +21,12 @@ - #include "ltran_tcp_conn.h" - #include "ltran_instance.h" - #include "ltran_log.h" --#include "gazelle_dfx_msg.h" -+#include "common/gazelle_dfx_msg.h" - #include "ltran_timer.h" - #include "ltran_ethdev.h" - #include "ltran_base.h" - #include "ltran_stack.h" --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "ltran_forward.h" - - /* undefine lwip_ntohs in lwip/def.h */ -diff --git a/src/ltran/ltran_stat.h b/src/ltran/ltran_stat.h -index 16d03a1..75cb353 100644 ---- a/src/ltran/ltran_stat.h -+++ b/src/ltran/ltran_stat.h -@@ -17,7 +17,7 @@ - - #include - --#include "gazelle_opt.h" -+#include "common/gazelle_opt.h" - - /* - * When doing reads from the NIC or the client queues, -diff --git a/src/ltran/ltran_tcp_conn.h b/src/ltran/ltran_tcp_conn.h -index fa508bc..82c5faf 100644 ---- a/src/ltran/ltran_tcp_conn.h -+++ b/src/ltran/ltran_tcp_conn.h -@@ -18,7 +18,7 @@ - #include - #include - --#include "gazelle_opt.h" -+#include "common/gazelle_opt.h" - - struct gazelle_tcp_conn { - uint32_t tid; -diff --git a/src/ltran/ltran_tcp_sock.c b/src/ltran/ltran_tcp_sock.c -index 940ded8..4044fc0 100644 ---- a/src/ltran/ltran_tcp_sock.c -+++ b/src/ltran/ltran_tcp_sock.c -@@ -18,7 +18,7 @@ - #include "ltran_instance.h" - #include "ltran_base.h" - #include "ltran_jhash.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_base_func.h" - #include "ltran_tcp_sock.h" - - struct gazelle_tcp_sock_htable *g_tcp_sock_htable = NULL; -diff --git a/src/ltran/ltran_tcp_sock.h b/src/ltran/ltran_tcp_sock.h -index a6e9571..e40891d 100644 ---- a/src/ltran/ltran_tcp_sock.h -+++ b/src/ltran/ltran_tcp_sock.h -@@ -17,7 +17,7 @@ - #include - #include - --#include "gazelle_opt.h" -+#include "common/gazelle_opt.h" - - struct gazelle_stack; - struct gazelle_tcp_sock { -diff --git a/src/ltran/main.c b/src/ltran/main.c -index 6cc8bc9..3d2310b 100644 ---- a/src/ltran/main.c -+++ b/src/ltran/main.c -@@ -20,7 +20,7 @@ - #include - #include - --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "ltran_log.h" - #include "ltran_param.h" - #include "ltran_stat.h" --- -2.33.0 - diff --git a/0214-add-.gitignore.patch b/0214-add-.gitignore.patch deleted file mode 100644 index 9217a9d7e0f36ab826daca4abde7fecbab9d7be9..0000000000000000000000000000000000000000 --- a/0214-add-.gitignore.patch +++ /dev/null @@ -1,50 +0,0 @@ -From da27acd950124efefb237b4cce69e42b9a769fa9 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 9 Jul 2024 15:37:30 +0800 -Subject: [PATCH] add .gitignore - -Signed-off-by: Lemmy Huang ---- - .gitignore | 17 +++++++++++++++++ - src/lstack/Makefile | 1 - - 2 files changed, 17 insertions(+), 1 deletion(-) - create mode 100644 .gitignore - -diff --git a/.gitignore b/.gitignore -new file mode 100644 -index 0000000..ec51d25 ---- /dev/null -+++ b/.gitignore -@@ -0,0 +1,17 @@ -+.vscode -+ -+**/*.so -+**/*.a -+**/*.o -+ -+**/CMakeCache.txt -+**/CMakeFiles -+examples/Makefile -+examples/cmake_install.cmake -+examples/example -+src/ltran/Makefile -+src/ltran/cmake_install.cmake -+src/ltran/ltran.map -+src/ltran/gazellectl -+src/ltran/ltran -+ -diff --git a/src/lstack/Makefile b/src/lstack/Makefile -index dd4e2c4..8a659c2 100644 ---- a/src/lstack/Makefile -+++ b/src/lstack/Makefile -@@ -104,7 +104,6 @@ else - endif - - DEP_LIBS = $(LWIP_LIB) $(LIBRTE_LIB) --$(info $(CC):$(DEP_LIBS)) - - SRCS = $(wildcard ./api/*.c ./core/*.c ./netif/*.c ../common/*.c) - # Linking object and library --- -2.33.0 - diff --git a/0215-cleancode-rename-gazelle-files-in-lwip.patch b/0215-cleancode-rename-gazelle-files-in-lwip.patch deleted file mode 100644 index daffb57c798bf15216aedea701060b0dcd0988f0..0000000000000000000000000000000000000000 --- a/0215-cleancode-rename-gazelle-files-in-lwip.patch +++ /dev/null @@ -1,489 +0,0 @@ -From 8ce0711285aaa897b08cf894e2908fef9fffe112 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 9 Jul 2024 21:52:51 +0800 -Subject: [PATCH] cleancode: rename gazelle files in lwip - -Signed-off-by: Lemmy Huang ---- - src/common/gazelle_dfx_msg.h | 2 +- - src/lstack/api/lstack_epoll.c | 6 +++--- - src/lstack/api/lstack_fork.c | 2 +- - src/lstack/api/lstack_rtc_api.c | 4 ++-- - src/lstack/api/lstack_rtw_api.c | 2 +- - src/lstack/api/lstack_signal.c | 4 ++-- - src/lstack/api/lstack_wrap.c | 4 ++-- - src/lstack/core/lstack_cfg.c | 4 ++-- - src/lstack/core/lstack_control_plane.c | 4 ++-- - src/lstack/core/lstack_dpdk.c | 4 ++-- - src/lstack/core/lstack_init.c | 6 +++--- - src/lstack/core/lstack_lwip.c | 4 ++-- - src/lstack/core/lstack_preload.c | 4 ++-- - src/lstack/core/lstack_protocol_stack.c | 6 +++--- - src/lstack/core/lstack_stack_stat.c | 4 ++-- - src/lstack/core/lstack_thread_rpc.c | 2 +- - src/lstack/core/lstack_virtio.c | 2 +- - src/lstack/include/lstack_dpdk.h | 2 +- - src/lstack/include/lstack_protocol_stack.h | 2 +- - src/lstack/include/posix/lstack_epoll.h | 2 +- - src/lstack/netif/lstack_ethdev.c | 2 +- - src/lstack/netif/lstack_fault_inject.c | 2 +- - src/lstack/netif/lstack_flow.c | 2 +- - src/lstack/netif/lstack_vdev.c | 4 ++-- - src/ltran/ltran_instance.h | 2 +- - src/ltran/ltran_stack.h | 2 +- - src/ltran/ltran_tcp_conn.h | 4 ++-- - src/ltran/ltran_tcp_sock.c | 2 +- - src/ltran/ltran_tcp_sock.h | 2 +- - src/ltran/ltran_timer.c | 2 +- - 30 files changed, 47 insertions(+), 47 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 57bf631..a2ec07b 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -16,7 +16,7 @@ - #include - #include - --#include -+#include - - #ifdef GAZELLE_FAULT_INJECT_ENABLE - #include "gazelle_fault_inject_common.h" -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 9c0aef7..7d00de7 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -19,13 +19,13 @@ - #include - #include - --#include -+#include - #include --#include -+#include - #include - #include - #include --#include -+#include - - #include "lstack_ethdev.h" - #include "lstack_stack_stat.h" -diff --git a/src/lstack/api/lstack_fork.c b/src/lstack/api/lstack_fork.c -index 43c212b..5cddee2 100644 ---- a/src/lstack/api/lstack_fork.c -+++ b/src/lstack/api/lstack_fork.c -@@ -13,7 +13,7 @@ - #include - #include - --#include -+#include - - pid_t lstack_fork(void) - { -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index 18664ca..e77edec 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -14,8 +14,8 @@ - #include - #include - #include --#include --#include -+#include -+#include - #include "posix/lstack_epoll.h" - #include "lstack_log.h" - #include "lstack_cfg.h" -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index e43be59..0f23ffd 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -15,7 +15,7 @@ - #include - #include - --#include -+#include - - #include "lstack_thread_rpc.h" - #include "posix/lstack_epoll.h" -diff --git a/src/lstack/api/lstack_signal.c b/src/lstack/api/lstack_signal.c -index 3dd5d03..9d0431b 100644 ---- a/src/lstack/api/lstack_signal.c -+++ b/src/lstack/api/lstack_signal.c -@@ -15,8 +15,8 @@ - #include - #include - #include --#include --#include -+#include -+#include - - #include "common/gazelle_base_func.h" - #include "lstack_cfg.h" -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 3a60cbb..cf0d302 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -22,8 +22,8 @@ - #include - #include - --#include --#include -+#include -+#include - #include - - #include "posix/lstack_unistd.h" -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 4bc4217..a1f6c2f 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -24,8 +24,8 @@ - #include - - #include --#include --#include -+#include -+#include - #include - - #include "common/gazelle_reg_msg.h" -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 4ab12f6..5545b9f 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -21,8 +21,8 @@ - #include - #include - #include --#include --#include -+#include -+#include - - #include "lstack_cfg.h" - #include "lstack_dpdk.h" -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 583bb09..a095cbd 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -32,10 +32,10 @@ - #endif - #include - #include --#include -+#include - #include - #include --#include -+#include - #include - - #include -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index d97b218..a5a4a4e 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -28,11 +28,11 @@ - - #include - #include --#include -+#include - #include --#include -+#include - #include --#include -+#include - - #include "lstack_cfg.h" - #include "lstack_control_plane.h" -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 6e50e4d..75ef5f6 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -15,11 +15,11 @@ - #include - #include - #include --#include -+#include - #include - #include - #include --#include -+#include - #include - #include - #include -diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c -index f7caef5..0974e9e 100644 ---- a/src/lstack/core/lstack_preload.c -+++ b/src/lstack/core/lstack_preload.c -@@ -15,8 +15,8 @@ - #include - #include - --#include --#include -+#include -+#include - #include - - #include "lstack_log.h" -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 1983c0b..d8bdd3c 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -16,9 +16,9 @@ - #include - #include - #include --#include --#include --#include -+#include -+#include -+#include - #include - #include - -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 423be81..e77f21a 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -15,11 +15,11 @@ - #include - #include - #include --#include -+#include -+#include - - #include "lstack_cfg.h" - #include "lstack_ethdev.h" --#include "posix_api.h" - #include "lstack_control_plane.h" - #include "lstack_log.h" - #include "common/dpdk_common.h" -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index e438c37..a6d2dbf 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -10,7 +10,7 @@ - * See the Mulan PSL v2 for more details. - */ - #include --#include -+#include - #include - - #include "lstack_log.h" -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index bc42bb9..36159c9 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -13,7 +13,7 @@ - #include - #include - #include --#include -+#include - #include - #include "lstack_cfg.h" - #include "lstack_log.h" -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index 91af3c5..d058409 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -13,7 +13,7 @@ - #ifndef _GAZELLE_DPDK_H_ - #define _GAZELLE_DPDK_H_ - --#include -+#include - #include "common/gazelle_opt.h" - #include "common/gazelle_dfx_msg.h" - -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 5b04c6d..7dce757 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -17,7 +17,7 @@ - #include - #include - --#include -+#include - #include - - #include "common/gazelle_opt.h" -diff --git a/src/lstack/include/posix/lstack_epoll.h b/src/lstack/include/posix/lstack_epoll.h -index 77b6ebb..6e02615 100644 ---- a/src/lstack/include/posix/lstack_epoll.h -+++ b/src/lstack/include/posix/lstack_epoll.h -@@ -18,7 +18,7 @@ - #include - #include - --#include -+#include - - #include "common/gazelle_dfx_msg.h" - #include "common/gazelle_opt.h" -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index e23d313..5685d11 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -19,7 +19,7 @@ - - #include - #include --#include -+#include - #include - - #include -diff --git a/src/lstack/netif/lstack_fault_inject.c b/src/lstack/netif/lstack_fault_inject.c -index 4736e29..9fae745 100644 ---- a/src/lstack/netif/lstack_fault_inject.c -+++ b/src/lstack/netif/lstack_fault_inject.c -@@ -14,7 +14,7 @@ - #include - #include - --#include -+#include - - #include "lstack_cfg.h" - #include "lstack_log.h" -diff --git a/src/lstack/netif/lstack_flow.c b/src/lstack/netif/lstack_flow.c -index 84497dc..84c5c61 100644 ---- a/src/lstack/netif/lstack_flow.c -+++ b/src/lstack/netif/lstack_flow.c -@@ -18,7 +18,7 @@ - #include - #include - --#include -+#include - #include - #include - -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 63f9e40..a590b30 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -14,7 +14,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include -@@ -201,7 +201,7 @@ int32_t vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple) - - uint16_t local_port = ntohs(qtuple->src_port); - if (get_global_cfg_params()->flow_bifurcation && get_global_cfg_params()->is_primary) { -- if (type == REG_RING_TCP_LISTEN_CLOSE || type == REG_RING_UDP_BIND_CLOSE) { // add enum type in reg_sock.h -+ if (type == REG_RING_TCP_LISTEN_CLOSE || type == REG_RING_UDP_BIND_CLOSE) { // add enum type in lwipgz_flow.h - port_map_mod(local_port, 0); - } else if (type == REG_RING_TCP_LISTEN || type == REG_RING_UDP_BIND) { - port_map_mod(local_port, 1); -diff --git a/src/ltran/ltran_instance.h b/src/ltran/ltran_instance.h -index f0fe580..9cb6d31 100644 ---- a/src/ltran/ltran_instance.h -+++ b/src/ltran/ltran_instance.h -@@ -13,7 +13,7 @@ - #ifndef __GAZELLE_INSTANCE_H__ - #define __GAZELLE_INSTANCE_H__ - --#include -+#include - #include - #include - -diff --git a/src/ltran/ltran_stack.h b/src/ltran/ltran_stack.h -index 693bb33..7dd1cb1 100644 ---- a/src/ltran/ltran_stack.h -+++ b/src/ltran/ltran_stack.h -@@ -13,7 +13,7 @@ - #ifndef __GAZELLE_STACK_H__ - #define __GAZELLE_STACK_H__ - --#include -+#include - - #include "ltran_stat.h" - -diff --git a/src/ltran/ltran_tcp_conn.h b/src/ltran/ltran_tcp_conn.h -index 82c5faf..87491de 100644 ---- a/src/ltran/ltran_tcp_conn.h -+++ b/src/ltran/ltran_tcp_conn.h -@@ -13,10 +13,10 @@ - #ifndef __GAZELLE_TCP_CONN_H__ - #define __GAZELLE_TCP_CONN_H__ - --#include -+#include - #include - #include --#include -+#include - - #include "common/gazelle_opt.h" - -diff --git a/src/ltran/ltran_tcp_sock.c b/src/ltran/ltran_tcp_sock.c -index 4044fc0..eef2821 100644 ---- a/src/ltran/ltran_tcp_sock.c -+++ b/src/ltran/ltran_tcp_sock.c -@@ -12,7 +12,7 @@ - - #include - --#include -+#include - - #include "ltran_tcp_conn.h" - #include "ltran_instance.h" -diff --git a/src/ltran/ltran_tcp_sock.h b/src/ltran/ltran_tcp_sock.h -index e40891d..6ca97ec 100644 ---- a/src/ltran/ltran_tcp_sock.h -+++ b/src/ltran/ltran_tcp_sock.h -@@ -13,7 +13,7 @@ - #ifndef __GAZELLE_TCP_SOCK_H__ - #define __GAZELLE_TCP_SOCK_H__ - --#include -+#include - #include - #include - -diff --git a/src/ltran/ltran_timer.c b/src/ltran/ltran_timer.c -index 0832c5f..87046cb 100644 ---- a/src/ltran/ltran_timer.c -+++ b/src/ltran/ltran_timer.c -@@ -17,7 +17,7 @@ - #include - #include - #include --#include -+#include - - #include "ltran_param.h" - #include "ltran_log.h" --- -2.33.0 - diff --git a/0216-cleancode-refactor-lwipsock.h.patch b/0216-cleancode-refactor-lwipsock.h.patch deleted file mode 100644 index 1726808c26bb0975a2924d0dbdef7738450ec3ec..0000000000000000000000000000000000000000 --- a/0216-cleancode-refactor-lwipsock.h.patch +++ /dev/null @@ -1,280 +0,0 @@ -From 2f7ca29c8b7a93079a5579062fc6751a6be6fd0c Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Wed, 10 Jul 2024 11:08:07 +0800 -Subject: [PATCH] cleancode: refactor lwipsock.h - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_rtc_api.c | 7 +--- - src/lstack/api/lstack_wrap.c | 11 ++++-- - src/lstack/core/lstack_init.c | 3 -- - src/lstack/core/lstack_lwip.c | 45 ++++++++----------------- - src/lstack/core/lstack_protocol_stack.c | 26 ++++---------- - src/lstack/include/lstack_lwip.h | 7 ++-- - 6 files changed, 33 insertions(+), 66 deletions(-) - -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index e77edec..57ff89f 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -68,12 +68,7 @@ int rtc_close(int s) - return lstack_epoll_close(s); - } - -- lwip_close(s); -- if (sock != NULL) { -- list_del_node_null(&sock->event_list); -- } -- -- return posix_api->close_fn(s); -+ return lwip_close(s); - } - - int rtc_shutdown(int fd, int how) -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index cf0d302..16fc876 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -175,6 +175,8 @@ static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *add - - int32_t fd = g_wrap_api->accept_fn(s, addr, addrlen); - if (fd >= 0) { -+ struct lwip_sock *sock = get_socket(fd); -+ SET_CONN_TYPE_LIBOS(sock->conn); - return fd; - } - -@@ -193,6 +195,8 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, - - int32_t fd = g_wrap_api->accept4_fn(s, addr, addrlen, flags); - if (fd >= 0) { -+ struct lwip_sock *sock = get_socket(fd); -+ SET_CONN_TYPE_LIBOS(sock->conn); - return fd; - } - -@@ -452,10 +456,11 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - } - - ret = g_wrap_api->socket_fn(domain, type, protocol); -- /* if udp_enable = 1 in lstack.conf, udp protocol must be in user path currently */ -- if ((ret >= 0) && (type & SOCK_DGRAM)) { -+ if (ret >= 0) { - struct lwip_sock *sock = get_socket(ret); -- if (sock != NULL && sock->conn != NULL) { -+ SET_CONN_TYPE_LIBOS_OR_HOST(sock->conn); -+ /* if udp_enable = 1 in lstack.conf, udp protocol must be in user path currently */ -+ if (type & SOCK_DGRAM) { - SET_CONN_TYPE_LIBOS(sock->conn); - } - } -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index a5a4a4e..1b3882e 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -313,9 +313,6 @@ __attribute__((constructor)) void gazelle_network_init(void) - } - } - -- /* lwip initialization */ -- lwip_sock_init(); -- - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - if (get_global_cfg_params()->kni_switch) { - set_kni_ip_mac(); -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 75ef5f6..6fe4055 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -144,12 +144,12 @@ static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_so - return false; - } - --void do_lwip_init_sock(int32_t fd) -+int do_lwip_init_sock(int32_t fd) - { - struct protocol_stack *stack = get_protocol_stack(); -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = get_socket_by_fd(fd); - if (sock == NULL) { -- return; -+ return -1; - } - - reset_sock_data(sock); -@@ -157,7 +157,7 @@ void do_lwip_init_sock(int32_t fd) - sock->recv_ring = gazelle_ring_create_fast("sock_recv", SOCK_RECV_RING_SIZE, RING_F_SP_ENQ | RING_F_SC_DEQ); - if (sock->recv_ring == NULL) { - LSTACK_LOG(ERR, LSTACK, "sock_recv create failed. errno: %d.\n", rte_errno); -- return; -+ return -1; - } - - sock->send_ring = gazelle_ring_create_fast("sock_send", -@@ -166,7 +166,7 @@ void do_lwip_init_sock(int32_t fd) - if (sock->send_ring == NULL) { - gazelle_ring_free_fast(sock->recv_ring); - LSTACK_LOG(ERR, LSTACK, "sock_send create failed. errno: %d.\n", rte_errno); -- return; -+ return -1; - } - (void)replenish_send_idlembuf(stack, sock); - -@@ -174,6 +174,7 @@ void do_lwip_init_sock(int32_t fd) - - init_list_node_null(&sock->recv_list); - init_list_node_null(&sock->event_list); -+ return 0; - } - - void do_lwip_clean_sock(int fd) -@@ -1237,32 +1238,6 @@ void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_soc - } - } - --int do_lwip_close(int fd) --{ -- int ret = lwip_close(fd); -- do_lwip_clean_sock(fd); -- posix_api->close_fn(fd); -- return ret; --} -- --int do_lwip_socket(int domain, int type, int protocol) --{ -- int32_t fd = lwip_socket(domain, type, 0); -- if (fd < 0) { -- return fd; -- } -- -- do_lwip_init_sock(fd); -- -- struct lwip_sock *sock = get_socket(fd); -- if (sock == NULL || sock->stack == NULL) { -- do_lwip_close(fd); -- return -1; -- } -- -- return fd; --} -- - uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, - uint32_t max_num) - { -@@ -1583,3 +1558,11 @@ err_t find_same_node_ring(struct tcp_pcb *npcb) - } - return 0; - } -+ -+unsigned same_node_ring_count(struct lwip_sock *sock) -+{ -+ const unsigned long long cur_begin = __atomic_load_n(&sock->same_node_rx_ring->sndbegin, __ATOMIC_RELAXED); -+ const unsigned long long cur_end = __atomic_load_n(&sock->same_node_rx_ring->sndend, __ATOMIC_RELAXED); -+ -+ return cur_end - cur_begin; -+} -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index d8bdd3c..c6075d5 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -424,11 +424,6 @@ static struct protocol_stack *stack_thread_init(void *arg) - } - RTE_PER_LCORE(_lcore_id) = stack->cpu_id; - -- if (hugepage_init() != 0) { -- LSTACK_LOG(ERR, LSTACK, "hugepage init failed\n"); -- goto END; -- } -- - tcpip_init(NULL, NULL); - - if (use_ltran()) { -@@ -714,12 +709,9 @@ void stack_arp(struct rpc_msg *msg) - - void stack_socket(struct rpc_msg *msg) - { -- msg->result = do_lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); -+ msg->result = lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); - if (msg->result < 0) { -- msg->result = do_lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); -- if (msg->result < 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, %ld socket failed\n", get_stack_tid(), msg->result); -- } -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, %ld socket failed\n", get_stack_tid(), msg->result); - } - } - -@@ -735,7 +727,7 @@ void stack_close(struct rpc_msg *msg) - return; - } - -- msg->result = do_lwip_close(fd); -+ msg->result = lwip_close(fd); - if (msg->result != 0) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); - } -@@ -803,7 +795,7 @@ void stack_accept(struct rpc_msg *msg) - - struct lwip_sock *sock = get_socket(accept_fd); - if (sock == NULL || sock->stack == NULL) { -- do_lwip_close(accept_fd); -+ lwip_close(accept_fd); - LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); - return; - } -@@ -1046,12 +1038,8 @@ void stack_create_shadow_fd(struct rpc_msg *msg) - } - - int domain = addr->sa_family; -- if (NETCONN_IS_UDP(sock)) { -- clone_fd = do_lwip_socket(domain, SOCK_DGRAM, 0); -- } else { -- clone_fd = do_lwip_socket(domain, SOCK_STREAM, 0); -- } -- -+ int type = NETCONN_IS_UDP(sock) ? SOCK_DGRAM : SOCK_STREAM; -+ clone_fd = lwip_socket(domain, type, 0); - if (clone_fd < 0) { - LSTACK_LOG(ERR, LSTACK, "clone socket failed clone_fd=%d errno=%d\n", clone_fd, errno); - msg->result = clone_fd; -@@ -1370,7 +1358,7 @@ static void stack_all_fds_close(void) - for (int i = 3; i < GAZELLE_MAX_CLIENTS + GAZELLE_RESERVED_CLIENTS; i++) { - struct lwip_sock *sock = get_socket(i); - if (sock && sock->stack == get_protocol_stack()) { -- do_lwip_close(i); -+ lwip_close(i); - } - } - } -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index 0b952ec..b972f11 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -16,21 +16,20 @@ - - #include "common/gazelle_dfx_msg.h" - -+struct lwip_sock; -+unsigned same_node_ring_count(struct lwip_sock *sock); -+ - #define NETCONN_IS_ACCEPTIN(sock) (((sock)->conn->acceptmbox != NULL) && !sys_mbox_empty((sock)->conn->acceptmbox)) - #define NETCONN_IS_DATAIN(sock) ((gazelle_ring_readable_count((sock)->recv_ring) || (sock)->recv_lastdata) || (sock->same_node_rx_ring != NULL && same_node_ring_count(sock))) - #define NETCONN_IS_DATAOUT(sock) (gazelle_ring_readover_count((sock)->send_ring) || (sock)->send_pre_del) - #define NETCONN_IS_OUTIDLE(sock) gazelle_ring_readable_count((sock)->send_ring) - #define NETCONN_IS_UDP(sock) (NETCONNTYPE_GROUP(netconn_type((sock)->conn)) == NETCONN_UDP) - --struct lwip_sock; - struct rte_mempool; - struct rpc_msg; - struct rte_mbuf; - struct protocol_stack; - --int do_lwip_socket(int domain, int type, int protocol); --int do_lwip_close(int32_t fd); --void do_lwip_init_sock(int32_t fd); - void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock); - - struct pbuf *do_lwip_tcp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size); --- -2.33.0 - diff --git a/0217-cleancode-refactor-posix-type-and-get_socket.patch b/0217-cleancode-refactor-posix-type-and-get_socket.patch deleted file mode 100644 index cbf98e2019607d37c577cecc289e523dd6e95ff4..0000000000000000000000000000000000000000 --- a/0217-cleancode-refactor-posix-type-and-get_socket.patch +++ /dev/null @@ -1,1047 +0,0 @@ -From dcfb07a30a3e4f8eece68d1ad8c17cb8c2a58945 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Wed, 10 Jul 2024 16:37:01 +0800 -Subject: [PATCH] cleancode: refactor posix type and get_socket - - Changed: - get_socket_by_fd -> lwip_get_socket - get_socket - - SET_CONN_TYPE_LIBOS_OR_HOST -> POSIX_SET_TYPE - SET_CONN_TYPE_LIBOS - SET_CONN_TYPE_HOST - - CONN_TYPE_IS_LIBOS -> POSIX_IS_TYPE - CONN_TYPE_IS_HOST - - CONN_TYPE_HAS_LIBOS_AND_HOST -> POSIX_HAS_TYPE - CONN_TYPE_HAS_LIBOS - CONN_TYPE_HAS_HOST - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 34 ++++---- - src/lstack/api/lstack_rtc_api.c | 6 +- - src/lstack/api/lstack_rtw_api.c | 14 ++-- - src/lstack/api/lstack_wrap.c | 104 ++++++++++++------------ - src/lstack/core/lstack_lwip.c | 22 ++--- - src/lstack/core/lstack_preload.c | 44 +++++----- - src/lstack/core/lstack_protocol_stack.c | 40 ++++----- - src/lstack/core/lstack_stack_stat.c | 2 +- - src/lstack/core/lstack_thread_rpc.c | 4 +- - src/lstack/include/lstack_preload.h | 10 +-- - 10 files changed, 137 insertions(+), 143 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 7d00de7..8146b4f 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -164,7 +164,7 @@ static uint32_t update_events(struct lwip_sock *sock) - - if ((sock->epoll_events & EPOLLOUT) && NETCONN_IS_OUTIDLE(sock)) { - /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ -- if (sock->conn && CONN_TYPE_IS_LIBOS(sock->conn)) { -+ if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { - event |= EPOLLOUT; - } - } -@@ -190,7 +190,7 @@ static void rtc_raise_pending_events(struct wakeup_poll *wakeup, struct lwip_soc - - if (sock->sendevent) { - /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ -- if (sock->conn && CONN_TYPE_IS_LIBOS(sock->conn)) { -+ if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { - event |= EPOLLOUT; - } - } -@@ -219,7 +219,7 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s - pthread_spin_lock(&wakeup->event_list_lock); - if (NETCONN_IS_OUTIDLE(sock)) { - /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ -- if (sock->conn && CONN_TYPE_IS_LIBOS(sock->conn)) { -+ if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { - event |= EPOLLOUT; - } - } -@@ -240,7 +240,7 @@ int32_t lstack_do_epoll_create(int32_t fd) - return fd; - } - -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL) { - LSTACK_LOG(ERR, LSTACK, "fd=%d sock is NULL errno=%d\n", fd, errno); - posix_api->close_fn(fd); -@@ -307,7 +307,7 @@ int32_t lstack_epoll_create(int32_t flags) - - int32_t lstack_epoll_close(int32_t fd) - { -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL) { - LSTACK_LOG(ERR, LSTACK, "fd=%d sock is NULL errno=%d\n", fd, errno); - GAZELLE_RETURN(EINVAL); -@@ -391,14 +391,14 @@ int32_t lstack_rtc_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *epoll_sock = get_socket_by_fd(epfd); -+ struct lwip_sock *epoll_sock = lwip_get_socket(epfd); - if (epoll_sock == NULL || epoll_sock->wakeup == NULL) { - return posix_api->epoll_ctl_fn(epfd, op, fd, event); - } - - struct wakeup_poll *wakeup = epoll_sock->wakeup; -- struct lwip_sock *sock = get_socket(fd); -- if (sock == NULL) { -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL || sock->conn == NULL) { - return posix_api->epoll_ctl_fn(epfd, op, fd, event); - } - -@@ -431,18 +431,18 @@ int32_t lstack_rtw_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *epoll_sock = get_socket_by_fd(epfd); -+ struct lwip_sock *epoll_sock = lwip_get_socket(epfd); - if (epoll_sock == NULL || epoll_sock->wakeup == NULL) { - return posix_api->epoll_ctl_fn(epfd, op, fd, event); - } - - struct wakeup_poll *wakeup = epoll_sock->wakeup; -- struct lwip_sock *sock = get_socket(fd); -- if (sock == NULL) { -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL || sock->conn == NULL) { - return posix_api->epoll_ctl_fn(epfd, op, fd, event); - } - -- if (CONN_TYPE_HAS_HOST(sock->conn)) { -+ if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { - int32_t ret = posix_api->epoll_ctl_fn(epfd, op, fd, event); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "fd=%d epfd=%d op=%d errno=%d\n", fd, epfd, op, errno); -@@ -535,7 +535,7 @@ static int32_t poll_lwip_event(struct pollfd *fds, nfds_t nfds) - for (uint32_t i = 0; i < nfds; i++) { - /* sock->listen_next pointerto next stack listen */ - int32_t fd = fds[i].fd; -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - while (sock && sock->conn) { - uint32_t events = update_events(sock); - if (events) { -@@ -624,7 +624,7 @@ int32_t lstack_block_wait(struct wakeup_poll *wakeup, int32_t timeout) - - int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) - { -- struct lwip_sock *sock = get_socket_by_fd(epfd); -+ struct lwip_sock *sock = lwip_get_socket(epfd); - - if (sock == NULL || sock->wakeup == NULL) { - return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); -@@ -673,7 +673,7 @@ int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t - - int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) - { -- struct lwip_sock *sock = get_socket_by_fd(epfd); -+ struct lwip_sock *sock = lwip_get_socket(epfd); - if (sock == NULL || sock->wakeup == NULL) { - return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); - } -@@ -829,7 +829,7 @@ static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfd - for (uint32_t i = 0; i < nfds; i++) { - int32_t fd = fds[i].fd; - fds[i].revents = 0; -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - - if (fd == wakeup->last_fds[i].fd && fds[i].events == wakeup->last_fds[i].events) { - /* fd close then socket may get same fd. */ -@@ -838,7 +838,7 @@ static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfd - } - } - -- if (sock == NULL || sock->conn == NULL || CONN_TYPE_HAS_HOST(sock->conn)) { -+ if (sock == NULL || sock->conn == NULL || POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { - update_kernel_poll(wakeup, i, fds + i); - } - -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index 57ff89f..97623b3 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -50,8 +50,8 @@ int rtc_socket(int domain, int type, int protocol) - - /* need call stack thread init function */ - ret = lwip_socket(domain, type, protocol); -- struct lwip_sock *sock = get_socket(ret); -- if (sock != NULL) { -+ if (ret >= 0) { -+ struct lwip_sock *sock = lwip_get_socket(ret); - sock->stack = get_protocol_stack(); - sock->epoll_events = 0; - sock->events = 0; -@@ -63,7 +63,7 @@ int rtc_socket(int domain, int type, int protocol) - - int rtc_close(int s) - { -- struct lwip_sock *sock = get_socket(s); -+ struct lwip_sock *sock = lwip_get_socket(s); - if (sock != NULL && sock->wakeup != NULL && sock->wakeup->epollfd == s) { - return lstack_epoll_close(s); - } -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index 0f23ffd..f59b0cd 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -47,7 +47,7 @@ int rtw_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) - - int rtw_bind(int s, const struct sockaddr *name, socklen_t namelen) - { -- struct lwip_sock *sock = get_socket_by_fd(s); -+ struct lwip_sock *sock = lwip_get_socket(s); - - if (NETCONN_IS_UDP(sock) && get_global_cfg_params()->listen_shadow) { - return stack_broadcast_bind(s, name, namelen); -@@ -137,7 +137,7 @@ ssize_t rtw_write(int s, const void *mem, size_t size) - - ssize_t rtw_writev(int s, const struct iovec *iov, int iovcnt) - { -- struct lwip_sock *sock = get_socket_by_fd(s); -+ struct lwip_sock *sock = lwip_get_socket(s); - struct msghdr msg; - - msg.msg_name = NULL; -@@ -167,14 +167,14 @@ ssize_t rtw_recvmsg(int s, const struct msghdr *message, int flags) - - ssize_t rtw_sendmsg(int s, const struct msghdr *message, int flags) - { -- struct lwip_sock *sock = get_socket_by_fd(s); -+ struct lwip_sock *sock = lwip_get_socket(s); - return do_lwip_sendmsg_to_stack(sock, s, message, flags); - } - - static ssize_t rtw_udp_recvfrom(int sockfd, void *buf, size_t len, int flags, - struct sockaddr *addr, socklen_t *addrlen) - { -- struct lwip_sock *sock = get_socket_by_fd(sockfd); -+ struct lwip_sock *sock = lwip_get_socket(sockfd); - int ret; - - while (1) { -@@ -210,7 +210,7 @@ static inline ssize_t rtw_tcp_recvfrom(int sockfd, void *buf, size_t len, int fl - ssize_t rtw_recvfrom(int sockfd, void *buf, size_t len, int flags, - struct sockaddr *addr, socklen_t *addrlen) - { -- struct lwip_sock *sock = get_socket_by_fd(sockfd); -+ struct lwip_sock *sock = lwip_get_socket(sockfd); - if (NETCONN_IS_UDP(sock)) { - return rtw_udp_recvfrom(sockfd, buf, len, flags, addr, addrlen); - } else { -@@ -241,7 +241,7 @@ int rtw_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, s - - int rtw_close(int s) - { -- struct lwip_sock *sock = get_socket(s); -+ struct lwip_sock *sock = lwip_get_socket(s); - if (sock && sock->wakeup && sock->wakeup->epollfd == s) { - return lstack_epoll_close(s); - } -@@ -250,7 +250,7 @@ int rtw_close(int s) - - int rtw_shutdown(int fd, int how) - { -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock && sock->wakeup && sock->wakeup->epollfd == fd) { - GAZELLE_RETURN(ENOTSOCK); - } -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 16fc876..d3e1027 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -125,7 +125,7 @@ void wrap_api_set_dummy(void) - - static inline int32_t do_epoll_create1(int32_t flags) - { -- if (select_posix_path() == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL) { - return posix_api->epoll_create1_fn(flags); - } - -@@ -134,7 +134,7 @@ static inline int32_t do_epoll_create1(int32_t flags) - - static inline int32_t do_epoll_create(int32_t size) - { -- if (select_posix_path() == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL) { - return posix_api->epoll_create_fn(size); - } - -@@ -143,7 +143,7 @@ static inline int32_t do_epoll_create(int32_t size) - - static inline int32_t do_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event* event) - { -- if (select_posix_path() == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL) { - return posix_api->epoll_ctl_fn(epfd, op, fd, event); - } - -@@ -152,7 +152,7 @@ static inline int32_t do_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct - - static inline int32_t do_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) - { -- if (select_posix_path() == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL) { - return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); - } - -@@ -169,14 +169,14 @@ static inline int32_t do_epoll_wait(int32_t epfd, struct epoll_event* events, in - - static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) - { -- if (select_fd_posix_path(s, NULL) == PATH_KERNEL) { -+ if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { - return posix_api->accept_fn(s, addr, addrlen); - } - - int32_t fd = g_wrap_api->accept_fn(s, addr, addrlen); - if (fd >= 0) { -- struct lwip_sock *sock = get_socket(fd); -- SET_CONN_TYPE_LIBOS(sock->conn); -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); - return fd; - } - -@@ -189,14 +189,14 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, - GAZELLE_RETURN(EINVAL); - } - -- if (select_fd_posix_path(s, NULL) == PATH_KERNEL) { -+ if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { - return posix_api->accept4_fn(s, addr, addrlen, flags); - } - - int32_t fd = g_wrap_api->accept4_fn(s, addr, addrlen, flags); - if (fd >= 0) { -- struct lwip_sock *sock = get_socket(fd); -- SET_CONN_TYPE_LIBOS(sock->conn); -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); - return fd; - } - -@@ -210,13 +210,13 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - } - - struct lwip_sock *sock = NULL; -- if (select_fd_posix_path(s, &sock) == PATH_KERNEL) { -+ if (select_fd_posix_path(s, &sock) == POSIX_KERNEL) { - return posix_api->bind_fn(s, name, namelen); - } - - /* select user path when udp enable and ip addr is multicast */ - if (IN_MULTICAST(ntohl(((struct sockaddr_in *)name)->sin_addr.s_addr))) { -- SET_CONN_TYPE_LIBOS(sock->conn); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); - return g_wrap_api->bind_fn(s, name, namelen); - } - -@@ -233,7 +233,7 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - if (match_host_addr(&sock_addr)) { - /* maybe kni addr */ - if (posix_api->bind_fn(s, name, namelen) != 0) { -- SET_CONN_TYPE_LIBOS(sock->conn); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); - } else { - /* reuse the port allocated by kernel when port == 0 */ - if (((struct sockaddr_in *)name)->sin_port == 0) { -@@ -248,7 +248,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); - } else { -- SET_CONN_TYPE_HOST(sock->conn); -+ POSIX_SET_TYPE(sock, POSIX_KERNEL); - return posix_api->bind_fn(s, name, namelen); - } - } -@@ -303,11 +303,11 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - } - - struct lwip_sock *sock = NULL; -- if (select_fd_posix_path(s, &sock) == PATH_KERNEL) { -+ if (select_fd_posix_path(s, &sock) == POSIX_KERNEL) { - return posix_api->connect_fn(s, name, namelen); - } - -- sock = get_socket(s); -+ sock = lwip_get_socket(s); - if (sock == NULL) { - return posix_api->connect_fn(s, name, namelen); - } -@@ -323,10 +323,10 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - "listen_rx_ring_%d", remote_port); - if (is_local && rte_ring_lookup(listen_ring_name) == NULL) { - ret = posix_api->connect_fn(s, name, namelen); -- SET_CONN_TYPE_HOST(sock->conn); -+ POSIX_SET_TYPE(sock, POSIX_KERNEL); - } else { - ret = g_wrap_api->connect_fn(s, name, namelen); -- SET_CONN_TYPE_LIBOS(sock->conn); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); - } - - return ret; -@@ -334,7 +334,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - - static inline int32_t do_listen(int32_t s, int32_t backlog) - { -- if (select_fd_posix_path(s, NULL) == PATH_KERNEL) { -+ if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { - return posix_api->listen_fn(s, backlog); - } - -@@ -352,7 +352,7 @@ static inline int32_t do_getpeername(int32_t s, struct sockaddr *name, socklen_t - GAZELLE_RETURN(EINVAL); - } - -- if (select_fd_posix_path(s, NULL) == PATH_LWIP) { -+ if (select_fd_posix_path(s, NULL) == POSIX_LWIP) { - return g_wrap_api->getpeername_fn(s, name, namelen); - } - -@@ -365,7 +365,7 @@ static inline int32_t do_getsockname(int32_t s, struct sockaddr *name, socklen_t - GAZELLE_RETURN(EINVAL); - } - -- if (select_fd_posix_path(s, NULL) == PATH_LWIP) { -+ if (select_fd_posix_path(s, NULL) == POSIX_LWIP) { - return g_wrap_api->getsockname_fn(s, name, namelen); - } - -@@ -422,7 +422,7 @@ static bool unsupport_optname(int32_t level, int32_t optname) - - static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, void *optval, socklen_t *optlen) - { -- if (select_fd_posix_path(s, NULL) == PATH_LWIP && !unsupport_optname(level, optname)) { -+ if (select_fd_posix_path(s, NULL) == POSIX_LWIP && !unsupport_optname(level, optname)) { - return g_wrap_api->getsockopt_fn(s, level, optname, optval, optlen); - } - -@@ -431,7 +431,7 @@ static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, v - - static inline int32_t do_setsockopt(int32_t s, int32_t level, int32_t optname, const void *optval, socklen_t optlen) - { -- if (select_fd_posix_path(s, NULL) == PATH_KERNEL || unsupport_optname(level, optname)) { -+ if (select_fd_posix_path(s, NULL) == POSIX_KERNEL || unsupport_optname(level, optname)) { - return posix_api->setsockopt_fn(s, level, optname, optval, optlen); - } - -@@ -445,7 +445,7 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - { - int32_t ret; - /* process not init completed or not hajacking thread */ -- if (select_posix_path() == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL) { - return posix_api->socket_fn(domain, type, protocol); - } - -@@ -457,11 +457,11 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - - ret = g_wrap_api->socket_fn(domain, type, protocol); - if (ret >= 0) { -- struct lwip_sock *sock = get_socket(ret); -- SET_CONN_TYPE_LIBOS_OR_HOST(sock->conn); -+ struct lwip_sock *sock = lwip_get_socket(ret); -+ POSIX_SET_TYPE(sock, POSIX_LWIP | POSIX_KERNEL); - /* if udp_enable = 1 in lstack.conf, udp protocol must be in user path currently */ - if (type & SOCK_DGRAM) { -- SET_CONN_TYPE_LIBOS(sock->conn); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); - } - } - -@@ -478,8 +478,8 @@ static inline ssize_t do_recv(int32_t sockfd, void *buf, size_t len, int32_t fla - return 0; - } - -- if (select_posix_path() == PATH_KERNEL || // maybe fd is created by open before posix_api_init called -- select_fd_posix_path(sockfd, NULL) == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL || // maybe fd is created by open before posix_api_init called -+ select_fd_posix_path(sockfd, NULL) == POSIX_KERNEL) { - return posix_api->recv_fn(sockfd, buf, len, flags); - } - -@@ -496,8 +496,8 @@ static inline ssize_t do_read(int32_t s, void *mem, size_t len) - return 0; - } - -- if (select_posix_path() == PATH_KERNEL || -- select_fd_posix_path(s, NULL) == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL || -+ select_fd_posix_path(s, NULL) == POSIX_KERNEL) { - return posix_api->read_fn(s, mem, len); - } - -@@ -506,8 +506,8 @@ static inline ssize_t do_read(int32_t s, void *mem, size_t len) - - static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) - { -- if (select_posix_path() == PATH_KERNEL || -- select_fd_posix_path(s, NULL) == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL || -+ select_fd_posix_path(s, NULL) == POSIX_KERNEL) { - return posix_api->readv_fn(s, iov, iovcnt); - } - -@@ -516,8 +516,8 @@ static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) - - static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32_t flags) - { -- if (select_posix_path() == PATH_KERNEL || -- select_fd_posix_path(sockfd, NULL) == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL || -+ select_fd_posix_path(sockfd, NULL) == POSIX_KERNEL) { - return posix_api->send_fn(sockfd, buf, len, flags); - } - -@@ -526,8 +526,8 @@ static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32 - - static inline ssize_t do_write(int32_t s, const void *mem, size_t size) - { -- if (select_posix_path() == PATH_KERNEL || -- select_fd_posix_path(s, NULL) == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL || -+ select_fd_posix_path(s, NULL) == POSIX_KERNEL) { - return posix_api->write_fn(s, mem, size); - } - -@@ -537,8 +537,8 @@ static inline ssize_t do_write(int32_t s, const void *mem, size_t size) - static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) - { - struct lwip_sock *sock; -- if (select_posix_path() == PATH_KERNEL || -- select_fd_posix_path(s, &sock) == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL || -+ select_fd_posix_path(s, &sock) == POSIX_KERNEL) { - return posix_api->writev_fn(s, iov, iovcnt); - } - -@@ -551,8 +551,8 @@ static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flag - GAZELLE_RETURN(EINVAL); - } - -- if (select_posix_path() == PATH_KERNEL || -- select_fd_posix_path(s, NULL) == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL || -+ select_fd_posix_path(s, NULL) == POSIX_KERNEL) { - return posix_api->recv_msg(s, message, flags); - } - -@@ -566,8 +566,8 @@ static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_ - } - - struct lwip_sock *sock; -- if (select_posix_path() == PATH_KERNEL || -- select_fd_posix_path(s, &sock) == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL || -+ select_fd_posix_path(s, &sock) == POSIX_KERNEL) { - return posix_api->send_msg(s, message, flags); - } - -@@ -586,7 +586,7 @@ static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t - } - - struct lwip_sock *sock = NULL; -- if (select_fd_posix_path(sockfd, &sock) == PATH_LWIP) { -+ if (select_fd_posix_path(sockfd, &sock) == POSIX_LWIP) { - return g_wrap_api->recv_from(sockfd, buf, len, flags, addr, addrlen); - } - -@@ -597,7 +597,7 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int - const struct sockaddr *addr, socklen_t addrlen) - { - struct lwip_sock *sock = NULL; -- if (select_fd_posix_path(sockfd, &sock) != PATH_LWIP) { -+ if (select_fd_posix_path(sockfd, &sock) != POSIX_LWIP) { - return posix_api->send_to(sockfd, buf, len, flags, addr, addrlen); - } - -@@ -607,8 +607,8 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int - static inline int32_t do_close(int32_t s) - { - struct lwip_sock *sock = NULL; -- if (select_posix_path() == PATH_KERNEL || -- select_fd_posix_path(s, &sock) == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL || -+ select_fd_posix_path(s, &sock) == POSIX_KERNEL) { - /* we called lwip_socket, even if kernel fd */ - if (posix_api != NULL && !posix_api->ues_posix && - /* contain posix_api->close_fn if success */ -@@ -624,7 +624,7 @@ static inline int32_t do_close(int32_t s) - static int32_t do_shutdown(int fd, int how) - { - struct lwip_sock *sock = NULL; -- if (select_posix_path() == PATH_KERNEL || select_fd_posix_path(fd, &sock) == PATH_KERNEL) { -+ if (select_posix_path() == POSIX_KERNEL || select_fd_posix_path(fd, &sock) == POSIX_KERNEL) { - if (posix_api != NULL && !posix_api->ues_posix && g_wrap_api->shutdown_fn(fd, how) == 0) { - return 0; - } else { -@@ -637,7 +637,7 @@ static int32_t do_shutdown(int fd, int how) - - static int32_t do_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - { -- if ((select_posix_path() == PATH_KERNEL) || fds == NULL || nfds == 0) { -+ if ((select_posix_path() == POSIX_KERNEL) || fds == NULL || nfds == 0) { - return posix_api->poll_fn(fds, nfds, timeout); - } - -@@ -676,7 +676,7 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct - - static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) - { -- if ((select_posix_path() == PATH_KERNEL) || !(readfds || writefds || exceptfds) || nfds == 0) { -+ if ((select_posix_path() == POSIX_KERNEL) || !(readfds || writefds || exceptfds) || nfds == 0) { - return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); - } - -@@ -691,8 +691,8 @@ static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set - val = va_arg(ap, typeof(val)); \ - va_end(ap); \ - struct lwip_sock *sock = NULL; \ -- if (select_posix_path() == PATH_KERNEL || \ -- select_fd_posix_path(_fd, &sock) == PATH_KERNEL) \ -+ if (select_posix_path() == POSIX_KERNEL || \ -+ select_fd_posix_path(_fd, &sock) == POSIX_KERNEL) \ - return _fcntl_fn(_fd, _cmd, val); \ - int32_t ret1 = _fcntl_fn(_fd, _cmd, val); \ - if (ret1 == -1) { \ -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 6fe4055..84ef782 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -147,7 +147,7 @@ static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_so - int do_lwip_init_sock(int32_t fd) - { - struct protocol_stack *stack = get_protocol_stack(); -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL) { - return -1; - } -@@ -179,7 +179,7 @@ int do_lwip_init_sock(int32_t fd) - - void do_lwip_clean_sock(int fd) - { -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL || sock->stack == NULL) { - return; - } -@@ -819,7 +819,7 @@ ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t f - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (len == 0 && !NETCONN_IS_UDP(sock)) { - return 0; - } -@@ -1059,7 +1059,7 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - struct sockaddr *addr, socklen_t *addrlen) - { - ssize_t recvd = 0; -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - bool noblock = (flags & MSG_DONTWAIT) || netconn_is_nonblocking(sock->conn); - - if (recv_break_for_err(sock)) { -@@ -1095,7 +1095,7 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - - void do_lwip_add_recvlist(int32_t fd) - { -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - - if (sock && sock->stack && list_is_null(&sock->recv_list)) { - list_add_node(&sock->stack->recv_list, &sock->recv_list); -@@ -1166,7 +1166,7 @@ void do_lwip_connected_callback(struct netconn *conn) - } - - int32_t fd = conn->callback_arg.socket; -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL || sock->conn == NULL) { - return; - } -@@ -1177,7 +1177,7 @@ void do_lwip_connected_callback(struct netconn *conn) - - posix_api->shutdown_fn(fd, SHUT_RDWR); - -- SET_CONN_TYPE_LIBOS(conn); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); - - add_sock_event(sock, EPOLLOUT); - } -@@ -1207,8 +1207,8 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - if (netconn != NULL) { - conn->fd = netconn->callback_arg.socket; - conn->recv_cnt = (netconn->recvmbox == NULL) ? 0 : rte_ring_count(netconn->recvmbox->ring); -- struct lwip_sock *sock = get_socket(netconn->callback_arg.socket); -- if (sock != NULL) { -+ struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); -+ if (sock != NULL && sock->conn != NULL) { - conn->recv_ring_cnt = (sock->recv_ring == NULL) ? 0 : gazelle_ring_readable_count(sock->recv_ring); - conn->recv_ring_cnt += (sock->recv_lastdata) ? 1 : 0; - conn->send_ring_cnt = (sock->send_ring == NULL) ? 0 : gazelle_ring_readover_count(sock->send_ring); -@@ -1473,7 +1473,7 @@ err_t same_node_ring_create(struct rte_ring **ring, int size, int port, char *na - static void init_same_node_ring(struct tcp_pcb *pcb) - { - struct netconn *netconn = (struct netconn *)pcb->callback_arg; -- struct lwip_sock *sock = get_socket(netconn->callback_arg.socket); -+ struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); - - pcb->client_rx_ring = NULL; - pcb->client_tx_ring = NULL; -@@ -1488,7 +1488,7 @@ static void init_same_node_ring(struct tcp_pcb *pcb) - err_t create_same_node_ring(struct tcp_pcb *pcb) - { - struct netconn *netconn = (struct netconn *)pcb->callback_arg; -- struct lwip_sock *sock = get_socket(netconn->callback_arg.socket); -+ struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); - - if (same_node_ring_create(&pcb->client_rx_ring, CLIENT_RING_SIZE, pcb->local_port, "client", "rx") != 0) { - goto END; -diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c -index 0974e9e..8cf4657 100644 ---- a/src/lstack/core/lstack_preload.c -+++ b/src/lstack/core/lstack_preload.c -@@ -30,7 +30,7 @@ - - #define EXCLUDE_THRD_CNT 1 - const static char *g_exclude_thread[EXCLUDE_THRD_CNT] = {"eal-intr-thread"}; --static PER_THREAD enum KERNEL_LWIP_PATH g_preload_thrdpath = PATH_UNKNOW; -+static PER_THREAD enum posix_type g_preload_thrdpath = POSIX_ALL; - - struct lstack_preload { - int32_t preload_switch; -@@ -79,27 +79,27 @@ static void preload_get_thrdname(void) - LSTACK_PRE_LOG(LSTACK_INFO, "thread name=%s ok\n", g_preload_info.env_thrdname); - } - --enum KERNEL_LWIP_PATH select_fd_posix_path(int32_t fd, struct lwip_sock **socket) -+enum posix_type select_fd_posix_path(int32_t fd, struct lwip_sock **socket) - { -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - - /* AF_UNIX case */ -- if (!sock || !sock->conn || CONN_TYPE_IS_HOST(sock->conn)) { -- return PATH_KERNEL; -+ if (!sock || !sock->conn || POSIX_IS_TYPE(sock, POSIX_KERNEL)) { -+ return POSIX_KERNEL; - } - - if (socket) { - *socket = sock; - } - -- if (likely(CONN_TYPE_IS_LIBOS(sock->conn))) { -- return PATH_LWIP; -+ if (likely(POSIX_IS_TYPE(sock, POSIX_LWIP))) { -+ return POSIX_LWIP; - } - -- return PATH_UNKNOW; -+ return POSIX_ALL; - } - --enum KERNEL_LWIP_PATH select_posix_path(void) -+enum posix_type select_posix_path(void) - { - if (unlikely(posix_api == NULL)) { - /* -@@ -109,14 +109,14 @@ enum KERNEL_LWIP_PATH select_posix_path(void) - if (posix_api_init() != 0) { - LSTACK_PRE_LOG(LSTACK_ERR, "posix_api_init failed\n"); - } -- return PATH_KERNEL; -+ return POSIX_KERNEL; - } - - if (unlikely(posix_api->ues_posix)) { -- return PATH_KERNEL; -+ return POSIX_KERNEL; - } - -- if (g_preload_thrdpath != PATH_UNKNOW) { -+ if (g_preload_thrdpath != POSIX_ALL) { - return g_preload_thrdpath; - } - -@@ -126,31 +126,31 @@ enum KERNEL_LWIP_PATH select_posix_path(void) - - char thread_name[PATH_MAX] = {0}; - if (pthread_getname_np(pthread_self(), thread_name, PATH_MAX) != 0) { -- g_preload_thrdpath = PATH_KERNEL; -- return PATH_KERNEL; -+ g_preload_thrdpath = POSIX_KERNEL; -+ return POSIX_KERNEL; - } - - /* exclude dpdk thread */ - for (int i = 0; i < EXCLUDE_THRD_CNT; i++) { - if (strstr(thread_name, g_exclude_thread[i]) != NULL) { -- g_preload_thrdpath = PATH_KERNEL; -- return PATH_KERNEL; -+ g_preload_thrdpath = POSIX_KERNEL; -+ return POSIX_KERNEL; - } - } - - /* not set GAZELLE_THREAD_NAME, select all thread */ - if (g_preload_info.env_thrdname[0] == '\0') { -- g_preload_thrdpath = PATH_LWIP; -- return PATH_LWIP; -+ g_preload_thrdpath = POSIX_LWIP; -+ return POSIX_LWIP; - } - - if (strstr(thread_name, g_preload_info.env_thrdname) == NULL) { -- g_preload_thrdpath = PATH_KERNEL; -- return PATH_KERNEL; -+ g_preload_thrdpath = POSIX_KERNEL; -+ return POSIX_KERNEL; - } - -- g_preload_thrdpath = PATH_LWIP; -- return PATH_LWIP; -+ g_preload_thrdpath = POSIX_LWIP; -+ return POSIX_LWIP; - } - - int preload_info_init(void) -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index c6075d5..d17cb67 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -126,8 +126,8 @@ struct protocol_stack *get_protocol_stack(void) - - struct protocol_stack *get_protocol_stack_by_fd(int32_t fd) - { -- struct lwip_sock *sock = get_socket(fd); -- if (sock == NULL) { -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL || sock->conn == NULL) { - return NULL; - } - -@@ -719,7 +719,7 @@ void stack_close(struct rpc_msg *msg) - { - int32_t fd = msg->args[MSG_ARG_0].i; - struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - - if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { - msg->recall_flag = 1; -@@ -738,7 +738,7 @@ void stack_shutdown(struct rpc_msg *msg) - int fd = msg->args[MSG_ARG_0].i; - int how = msg->args[MSG_ARG_1].i; - struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - - if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { - msg->recall_flag = 1; -@@ -767,7 +767,7 @@ void stack_listen(struct rpc_msg *msg) - int32_t fd = msg->args[MSG_ARG_0].i; - int32_t backlog = msg->args[MSG_ARG_1].i; - -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL) { - msg->result = -1; - return; -@@ -793,7 +793,7 @@ void stack_accept(struct rpc_msg *msg) - return; - } - -- struct lwip_sock *sock = get_socket(accept_fd); -+ struct lwip_sock *sock = lwip_get_socket(accept_fd); - if (sock == NULL || sock->stack == NULL) { - lwip_close(accept_fd); - LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); -@@ -880,7 +880,7 @@ void stack_tcp_send(struct rpc_msg *msg) - struct protocol_stack *stack = get_protocol_stack(); - int replenish_again; - -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL) { - msg->result = -1; - LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); -@@ -917,7 +917,7 @@ void stack_udp_send(struct rpc_msg *msg) - int replenish_again; - uint32_t call_num; - -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL) { - msg->result = -1; - LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); -@@ -1030,7 +1030,7 @@ void stack_create_shadow_fd(struct rpc_msg *msg) - socklen_t addr_len = msg->args[MSG_ARG_2].socklen; - - int32_t clone_fd = 0; -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL) { - LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d\n", fd); - msg->result = -1; -@@ -1046,7 +1046,7 @@ void stack_create_shadow_fd(struct rpc_msg *msg) - return; - } - -- struct lwip_sock *clone_sock = get_socket_by_fd(clone_fd); -+ struct lwip_sock *clone_sock = lwip_get_socket(clone_fd); - if (clone_sock == NULL) { - LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d clone_fd=%d\n", fd, clone_fd); - msg->result = -1; -@@ -1114,7 +1114,7 @@ void stack_recvlist_count(struct rpc_msg *msg) - int32_t stack_broadcast_close(int32_t fd) - { - int32_t ret = 0; -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - if (sock == NULL) { - GAZELLE_RETURN(EBADF); -@@ -1139,7 +1139,7 @@ int32_t stack_broadcast_close(int32_t fd) - int stack_broadcast_shutdown(int fd, int how) - { - int32_t ret = 0; -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - if (sock == NULL) { - GAZELLE_RETURN(EBADF); -@@ -1186,7 +1186,7 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) - socklen_t addr_len = sizeof(addr); - int32_t ret, clone_fd; - -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL || cur_stack == NULL) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); - GAZELLE_RETURN(EBADF); -@@ -1216,9 +1216,9 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) - } - - if (min_conn_stk_idx == i) { -- get_socket_by_fd(clone_fd)->conn->is_master_fd = 1; -+ lwip_get_socket(clone_fd)->conn->is_master_fd = 1; - } else { -- get_socket_by_fd(clone_fd)->conn->is_master_fd = 0; -+ lwip_get_socket(clone_fd)->conn->is_master_fd = 0; - } - - ret = rpc_call_listen(&stack->rpc_queue, clone_fd, backlog); -@@ -1232,7 +1232,7 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) - - static struct lwip_sock *get_min_accept_sock(int32_t fd) - { -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - struct lwip_sock *min_sock = NULL; - - while (sock) { -@@ -1282,7 +1282,7 @@ int32_t stack_broadcast_bind(int32_t fd, const struct sockaddr *name, socklen_t - struct protocol_stack *stack = NULL; - int32_t ret, clone_fd; - -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL || cur_stack == NULL) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); - GAZELLE_RETURN(EBADF); -@@ -1313,7 +1313,7 @@ int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *ad - { - int32_t ret = -1; - struct lwip_sock *min_sock = NULL; -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - struct protocol_stack *stack = NULL; - if (sock == NULL) { - GAZELLE_RETURN(EBADF); -@@ -1356,8 +1356,8 @@ int32_t stack_broadcast_accept(int32_t fd, struct sockaddr *addr, socklen_t *add - static void stack_all_fds_close(void) - { - for (int i = 3; i < GAZELLE_MAX_CLIENTS + GAZELLE_RESERVED_CLIENTS; i++) { -- struct lwip_sock *sock = get_socket(i); -- if (sock && sock->stack == get_protocol_stack()) { -+ struct lwip_sock *sock = lwip_get_socket(i); -+ if (sock && sock->conn && sock->stack == get_protocol_stack()) { - lwip_close(i); - } - } -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index e77f21a..e42efde 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -81,7 +81,7 @@ void time_stamp_into_recvmbox(struct lwip_sock *sock) - - void time_stamp_record(int fd, struct pbuf *pbuf) - { -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); - - if (get_protocol_stack_group()->latency_start && sock && pbuf) { - calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_INTO_MBOX, 0); -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index a6d2dbf..8ac06cb 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -474,7 +474,7 @@ int32_t rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags) - } - - if (get_protocol_stack_group()->latency_start) { -- time_stamp_into_rpcmsg(get_socket_by_fd(fd)); -+ time_stamp_into_rpcmsg(lwip_get_socket(fd)); - } - - msg->args[MSG_ARG_0].i = fd; -@@ -495,7 +495,7 @@ int32_t rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags) - } - - if (get_protocol_stack_group()->latency_start) { -- time_stamp_into_rpcmsg(get_socket_by_fd(fd)); -+ time_stamp_into_rpcmsg(lwip_get_socket(fd)); - } - - msg->args[MSG_ARG_0].i = fd; -diff --git a/src/lstack/include/lstack_preload.h b/src/lstack/include/lstack_preload.h -index 0ad7877..c30736a 100644 ---- a/src/lstack/include/lstack_preload.h -+++ b/src/lstack/include/lstack_preload.h -@@ -13,13 +13,7 @@ - #define __LSTACK_PRELOAD_H__ - #include - --enum KERNEL_LWIP_PATH { -- PATH_KERNEL = 0, -- PATH_LWIP, -- PATH_UNKNOW, --}; -- --enum KERNEL_LWIP_PATH select_posix_path(void); --enum KERNEL_LWIP_PATH select_fd_posix_path(int32_t fd, struct lwip_sock **socket); -+enum posix_type select_posix_path(void); -+enum posix_type select_fd_posix_path(int32_t fd, struct lwip_sock **socket); - int preload_info_init(void); - #endif --- -2.33.0 - diff --git a/0218-fix-some-error-of-NULL-pointer.patch b/0218-fix-some-error-of-NULL-pointer.patch deleted file mode 100644 index a49c79232e58f39dae3cacd365b7077353d1eece..0000000000000000000000000000000000000000 --- a/0218-fix-some-error-of-NULL-pointer.patch +++ /dev/null @@ -1,198 +0,0 @@ -From da10c78f9fa9b865ccc1a780a77f405dc093d04a Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Mon, 15 Jul 2024 15:27:53 +0800 -Subject: [PATCH] fix some error of NULL pointer - ---- - src/lstack/api/lstack_epoll.c | 23 ++++++++++++++++++----- - src/lstack/core/lstack_lwip.c | 15 ++++++++------- - src/lstack/core/lstack_port_map.c | 2 +- - src/lstack/core/lstack_protocol_stack.c | 2 +- - src/lstack/netif/lstack_ethdev.c | 8 ++++++-- - src/lstack/netif/lstack_tx_cache.c | 1 + - 6 files changed, 35 insertions(+), 16 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 7d00de7..566443e 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -740,6 +740,7 @@ static int32_t init_poll_wakeup_data(struct wakeup_poll *wakeup) - wakeup->events = calloc(POLL_KERNEL_EVENTS, sizeof(struct epoll_event)); - if (wakeup->events == NULL) { - free(wakeup->last_fds); -+ wakeup->last_fds = NULL; - GAZELLE_RETURN(EINVAL); - } - -@@ -760,7 +761,7 @@ static int32_t init_poll_wakeup_data(struct wakeup_poll *wakeup) - return 0; - } - --static void resize_kernel_poll(struct wakeup_poll *wakeup, nfds_t nfds) -+static int resize_kernel_poll(struct wakeup_poll *wakeup, nfds_t nfds) - { - if (wakeup->last_fds) { - free(wakeup->last_fds); -@@ -768,6 +769,7 @@ static void resize_kernel_poll(struct wakeup_poll *wakeup, nfds_t nfds) - wakeup->last_fds = calloc(nfds, sizeof(struct pollfd)); - if (wakeup->last_fds == NULL) { - LSTACK_LOG(ERR, LSTACK, "calloc failed errno=%d\n", errno); -+ return -1; - } - - if (wakeup->events) { -@@ -776,9 +778,12 @@ static void resize_kernel_poll(struct wakeup_poll *wakeup, nfds_t nfds) - wakeup->events = calloc(nfds, sizeof(struct epoll_event)); - if (wakeup->events == NULL) { - LSTACK_LOG(ERR, LSTACK, "calloc failed errno=%d\n", errno); -+ free(wakeup->last_fds); -+ return -1; - } - - wakeup->last_max_nfds = nfds; -+ return 0; - } - - static void poll_bind_statck(struct wakeup_poll *wakeup, int32_t *stack_count) -@@ -811,14 +816,18 @@ static void update_kernel_poll(struct wakeup_poll *wakeup, uint32_t index, struc - } - } - --static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfds) -+static int poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfds) - { - int32_t stack_count[PROTOCOL_STACK_MAX] = {0}; - int32_t poll_change = 0; -+ int ret = 0; - - /* poll fds num more, recalloc fds size */ - if (nfds > wakeup->last_max_nfds) { -- resize_kernel_poll(wakeup, nfds); -+ ret = resize_kernel_poll(wakeup, nfds); -+ if (ret < 0) { -+ return -1; -+ } - poll_change = 1; - } - -@@ -855,13 +864,14 @@ static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfd - } - - if (poll_change == 0) { -- return; -+ return 0; - } - wakeup->last_nfds = nfds; - - if (get_global_cfg_params()->app_bind_numa) { - poll_bind_statck(wakeup, stack_count); - } -+ return 0; - } - - int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) -@@ -880,7 +890,10 @@ int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - } - } - -- poll_init(wakeup, fds, nfds); -+ if (poll_init(wakeup, fds, nfds) < 0) { -+ free(wakeup); -+ GAZELLE_RETURN(EINVAL); -+ } - - int32_t kernel_num = 0; - int32_t lwip_num = 0; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 75ef5f6..4d73d44 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -333,7 +333,7 @@ static ssize_t do_app_write(struct lwip_sock *sock, struct pbuf *pbufs[], void * - } - - /* reduce the branch in loop */ -- uint16_t copy_len = len - send_len; -+ size_t copy_len = len - send_len; - rte_memcpy((char *)pbufs[i]->payload, (char *)buf + send_len, copy_len); - pbufs[i]->tot_len = pbufs[i]->len = copy_len; - send_len += copy_len; -@@ -1358,12 +1358,13 @@ void netif_poll(struct netif *netif) - /* processes on same node handshake packet use this function */ - err_t netif_loop_output(struct netif *netif, struct pbuf *p) - { -- if (p != NULL) { -- const struct ip_hdr *iphdr; -- iphdr = (const struct ip_hdr *)p->payload; -- if (IPH_PROTO(iphdr) == IP_PROTO_UDP) { -- return udp_netif_loop_output(netif, p); -- } -+ if (!p) { -+ return ERR_ARG; -+ } -+ const struct ip_hdr *iphdr; -+ iphdr = (const struct ip_hdr *)p->payload; -+ if (IPH_PROTO(iphdr) == IP_PROTO_UDP) { -+ return udp_netif_loop_output(netif, p); - } - - struct tcp_pcb *pcb = p->pcb; -diff --git a/src/lstack/core/lstack_port_map.c b/src/lstack/core/lstack_port_map.c -index 5439394..ce9d8df 100644 ---- a/src/lstack/core/lstack_port_map.c -+++ b/src/lstack/core/lstack_port_map.c -@@ -39,4 +39,4 @@ uint16_t port_map_get(uint16_t port) - } - pthread_mutex_unlock(&g_rule_map_mutex); - return val; --} -\ No newline at end of file -+} -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index d8bdd3c..d1bbf9b 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -1000,7 +1000,7 @@ void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack - return; - } - copy_mbuf(mbuf_copy, mbuf); -- virtio_tap_process_tx(stack->queue_id, mbuf_copy); -+ virtio_tap_process_tx(cur_stack->queue_id, mbuf_copy); - } - return; - } -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 5685d11..d4d0878 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -319,10 +319,14 @@ static err_t eth_dev_init(struct netif *netif) - int32_t ethdev_init(struct protocol_stack *stack) - { - struct cfg_params *cfg = get_global_cfg_params(); -- -+ int ret = 0; -+ - vdev_dev_ops_init(&stack->dev_ops); - if (cfg->send_cache_mode) { -- tx_cache_init(stack->queue_id, stack, &stack->dev_ops); -+ ret = tx_cache_init(stack->queue_id, stack, &stack->dev_ops); -+ if (ret < 0) { -+ return ret; -+ } - } - - if (use_ltran()) { -diff --git a/src/lstack/netif/lstack_tx_cache.c b/src/lstack/netif/lstack_tx_cache.c -index cda0003..9a48307 100644 ---- a/src/lstack/netif/lstack_tx_cache.c -+++ b/src/lstack/netif/lstack_tx_cache.c -@@ -45,6 +45,7 @@ int tx_cache_init(uint16_t queue_id, void *priv, struct lstack_dev_ops *dev_ops) - struct tx_cache *tx_cache = calloc(1, sizeof(struct tx_cache)); - if (tx_cache == NULL) { - LSTACK_LOG(ERR, LSTACK, "queue(%d) tx cache init failed\n", queue_id); -+ return -1; - } - - tx_cache->queue_id = queue_id; --- -2.33.0 - diff --git a/0219-cleancode-refactor-posix_api.patch b/0219-cleancode-refactor-posix_api.patch deleted file mode 100644 index 776865fa405a9545614bc7d839bc41c361e44ecf..0000000000000000000000000000000000000000 --- a/0219-cleancode-refactor-posix_api.patch +++ /dev/null @@ -1,775 +0,0 @@ -From a1523d108581cfc8aaf89b1116dde071ca5656d8 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Wed, 10 Jul 2024 17:40:43 +0800 -Subject: [PATCH] cleancode: refactor posix_api - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 16 +- - src/lstack/api/lstack_fork.c | 3 +- - src/lstack/api/lstack_rtw_api.c | 2 +- - src/lstack/api/lstack_wrap.c | 234 ++++++++++-------------- - src/lstack/core/lstack_control_plane.c | 4 +- - src/lstack/core/lstack_init.c | 4 +- - src/lstack/core/lstack_lwip.c | 5 +- - src/lstack/core/lstack_preload.c | 23 ++- - src/lstack/core/lstack_protocol_stack.c | 8 +- - src/lstack/include/lstack_preload.h | 6 +- - src/lstack/netif/lstack_flow.c | 1 + - 11 files changed, 139 insertions(+), 167 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 8146b4f..f8fd6d4 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -164,7 +164,7 @@ static uint32_t update_events(struct lwip_sock *sock) - - if ((sock->epoll_events & EPOLLOUT) && NETCONN_IS_OUTIDLE(sock)) { - /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ -- if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { -+ if (!POSIX_IS_CLOSED(sock) && POSIX_IS_TYPE(sock, POSIX_LWIP)) { - event |= EPOLLOUT; - } - } -@@ -190,7 +190,7 @@ static void rtc_raise_pending_events(struct wakeup_poll *wakeup, struct lwip_soc - - if (sock->sendevent) { - /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ -- if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { -+ if (!POSIX_IS_CLOSED(sock) && POSIX_IS_TYPE(sock, POSIX_LWIP)) { - event |= EPOLLOUT; - } - } -@@ -219,7 +219,7 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s - pthread_spin_lock(&wakeup->event_list_lock); - if (NETCONN_IS_OUTIDLE(sock)) { - /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ -- if (sock->conn && POSIX_IS_TYPE(sock, POSIX_LWIP)) { -+ if (!POSIX_IS_CLOSED(sock) && POSIX_IS_TYPE(sock, POSIX_LWIP)) { - event |= EPOLLOUT; - } - } -@@ -398,7 +398,7 @@ int32_t lstack_rtc_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ - - struct wakeup_poll *wakeup = epoll_sock->wakeup; - struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL || sock->conn == NULL) { -+ if (POSIX_IS_CLOSED(sock)) { - return posix_api->epoll_ctl_fn(epfd, op, fd, event); - } - -@@ -438,7 +438,7 @@ int32_t lstack_rtw_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ - - struct wakeup_poll *wakeup = epoll_sock->wakeup; - struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL || sock->conn == NULL) { -+ if (POSIX_IS_CLOSED(sock)) { - return posix_api->epoll_ctl_fn(epfd, op, fd, event); - } - -@@ -536,7 +536,7 @@ static int32_t poll_lwip_event(struct pollfd *fds, nfds_t nfds) - /* sock->listen_next pointerto next stack listen */ - int32_t fd = fds[i].fd; - struct lwip_sock *sock = lwip_get_socket(fd); -- while (sock && sock->conn) { -+ while (!POSIX_IS_CLOSED(sock)) { - uint32_t events = update_events(sock); - if (events) { - fds[i].revents = events; -@@ -838,7 +838,7 @@ static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfd - } - } - -- if (sock == NULL || sock->conn == NULL || POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { -+ if (POSIX_IS_CLOSED(sock) || POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { - update_kernel_poll(wakeup, i, fds + i); - } - -@@ -846,7 +846,7 @@ static void poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfd - wakeup->last_fds[i].events = fds[i].events; - poll_change = 1; - -- while (sock && sock->conn) { -+ while (!POSIX_IS_CLOSED(sock)) { - sock->epoll_events = fds[i].events | POLLERR; - sock->wakeup = wakeup; - stack_count[sock->stack->stack_idx]++; -diff --git a/src/lstack/api/lstack_fork.c b/src/lstack/api/lstack_fork.c -index 5cddee2..f5d0e95 100644 ---- a/src/lstack/api/lstack_fork.c -+++ b/src/lstack/api/lstack_fork.c -@@ -20,8 +20,9 @@ pid_t lstack_fork(void) - pid_t pid; - - pid = posix_api->fork_fn(); -+ /* child not support lwip */ - if (pid == 0) { -- posix_api_fork(); -+ posix_api->use_kernel = 1; - } - return pid; - } -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index f59b0cd..09c4e11 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -186,7 +186,7 @@ static ssize_t rtw_udp_recvfrom(int sockfd, void *buf, size_t len, int flags, - return -1; - } - sock = sock->listen_next; -- if (sock != NULL && sock->conn != NULL) { -+ if (!POSIX_IS_CLOSED(sock)) { - sockfd = sock->conn->callback_arg.socket; - } else { - if (sock == NULL) { -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index d3e1027..b19990e 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -37,12 +37,8 @@ - #include "lstack_rtw_api.h" - #include "lstack_dummy_api.h" - --#ifndef SOCK_TYPE_MASK --#define SOCK_TYPE_MASK 0xf --#endif -- --posix_api_t g_wrap_api_value; --posix_api_t *g_wrap_api; -+static posix_api_t g_wrap_api_value; -+static posix_api_t *g_wrap_api; - - void wrap_api_init(void) - { -@@ -68,10 +64,10 @@ void wrap_api_init(void) - g_wrap_api->writev_fn = lwip_writev; - g_wrap_api->recv_fn = lwip_recv; - g_wrap_api->send_fn = lwip_send; -- g_wrap_api->recv_msg = lwip_recvmsg; -- g_wrap_api->send_msg = lwip_sendmsg; -- g_wrap_api->recv_from = lwip_recvfrom; -- g_wrap_api->send_to = lwip_sendto; -+ g_wrap_api->recvmsg_fn = lwip_recvmsg; -+ g_wrap_api->sendmsg_fn = lwip_sendmsg; -+ g_wrap_api->recvfrom_fn = lwip_recvfrom; -+ g_wrap_api->sendto_fn = lwip_sendto; - g_wrap_api->epoll_wait_fn = rtc_epoll_wait; - g_wrap_api->poll_fn = rtc_poll; - g_wrap_api->close_fn = rtc_close; -@@ -97,10 +93,10 @@ void wrap_api_init(void) - g_wrap_api->writev_fn = rtw_writev; - g_wrap_api->recv_fn = rtw_recv; - g_wrap_api->send_fn = rtw_send; -- g_wrap_api->recv_msg = rtw_recvmsg; -- g_wrap_api->send_msg = rtw_sendmsg; -- g_wrap_api->recv_from = rtw_recvfrom; -- g_wrap_api->send_to = rtw_sendto; -+ g_wrap_api->recvmsg_fn = rtw_recvmsg; -+ g_wrap_api->sendmsg_fn = rtw_sendmsg; -+ g_wrap_api->recvfrom_fn = rtw_recvfrom; -+ g_wrap_api->sendto_fn = rtw_sendto; - g_wrap_api->epoll_wait_fn = rtw_epoll_wait; - g_wrap_api->poll_fn = rtw_poll; - g_wrap_api->close_fn = rtw_close; -@@ -118,8 +114,8 @@ void wrap_api_set_dummy(void) - g_wrap_api->send_fn = dummy_send; - g_wrap_api->write_fn = dummy_write; - g_wrap_api->writev_fn = dummy_writev; -- g_wrap_api->send_msg = dummy_sendmsg; -- g_wrap_api->send_to = dummy_sendto; -+ g_wrap_api->sendmsg_fn = dummy_sendmsg; -+ g_wrap_api->sendto_fn = dummy_sendto; - rte_wmb(); - } - -@@ -169,7 +165,7 @@ static inline int32_t do_epoll_wait(int32_t epfd, struct epoll_event* events, in - - static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) - { -- if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_KERNEL) { - return posix_api->accept_fn(s, addr, addrlen); - } - -@@ -189,7 +185,7 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, - GAZELLE_RETURN(EINVAL); - } - -- if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_KERNEL) { - return posix_api->accept4_fn(s, addr, addrlen, flags); - } - -@@ -209,8 +205,8 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *sock = NULL; -- if (select_fd_posix_path(s, &sock) == POSIX_KERNEL) { -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (select_sock_posix_path(sock) == POSIX_KERNEL) { - return posix_api->bind_fn(s, name, namelen); - } - -@@ -230,30 +226,31 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - ((struct sockaddr_in6 *)name)->sin6_addr.s6_addr, IPV6_ADDR_LEN); - } - -- if (match_host_addr(&sock_addr)) { -- /* maybe kni addr */ -- if (posix_api->bind_fn(s, name, namelen) != 0) { -- POSIX_SET_TYPE(sock, POSIX_LWIP); -- } else { -- /* reuse the port allocated by kernel when port == 0 */ -- if (((struct sockaddr_in *)name)->sin_port == 0) { -- struct sockaddr_in kerneladdr; -- socklen_t len = sizeof(kerneladdr); -- if (posix_api->getsockname_fn(s, (struct sockaddr *)&kerneladdr, &len) < 0) { -- LSTACK_LOG(ERR, LSTACK, "kernel getsockname failed, fd=%d, errno=%d\n", s, errno); -- return -1; -- } -- ((struct sockaddr_in *)name)->sin_port = kerneladdr.sin_port; -+ if (!match_host_addr(&sock_addr)) { -+ POSIX_SET_TYPE(sock, POSIX_KERNEL); -+ return posix_api->bind_fn(s, name, namelen); -+ } -+ -+ /* maybe kni addr */ -+ if (posix_api->bind_fn(s, name, namelen) == 0) { -+ /* reuse the port allocated by kernel when port == 0 */ -+ if (((struct sockaddr_in *)name)->sin_port == 0) { -+ struct sockaddr_in kerneladdr; -+ socklen_t len = sizeof(kerneladdr); -+ if (posix_api->getsockname_fn(s, (struct sockaddr *)&kerneladdr, &len) < 0) { -+ LSTACK_LOG(ERR, LSTACK, "kernel getsockname failed, fd=%d, errno=%d\n", s, errno); -+ return -1; - } -+ ((struct sockaddr_in *)name)->sin_port = kerneladdr.sin_port; - } -- return g_wrap_api->bind_fn(s, name, namelen); -+ /* not sure POSIX_LWIP or POSIX_KERNEL */ - } else { -- POSIX_SET_TYPE(sock, POSIX_KERNEL); -- return posix_api->bind_fn(s, name, namelen); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); - } -+ return g_wrap_api->bind_fn(s, name, namelen); - } - --bool is_dst_ip_localhost(const struct sockaddr *addr) -+static bool is_dst_ip_localhost(const struct sockaddr *addr) - { - struct ifaddrs *ifap; - struct ifaddrs *ifa; -@@ -302,13 +299,8 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *sock = NULL; -- if (select_fd_posix_path(s, &sock) == POSIX_KERNEL) { -- return posix_api->connect_fn(s, name, namelen); -- } -- -- sock = lwip_get_socket(s); -- if (sock == NULL) { -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (select_sock_posix_path(sock) == POSIX_KERNEL) { - return posix_api->connect_fn(s, name, namelen); - } - -@@ -334,7 +326,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - - static inline int32_t do_listen(int32_t s, int32_t backlog) - { -- if (select_fd_posix_path(s, NULL) == POSIX_KERNEL) { -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_KERNEL) { - return posix_api->listen_fn(s, backlog); - } - -@@ -352,7 +344,7 @@ static inline int32_t do_getpeername(int32_t s, struct sockaddr *name, socklen_t - GAZELLE_RETURN(EINVAL); - } - -- if (select_fd_posix_path(s, NULL) == POSIX_LWIP) { -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { - return g_wrap_api->getpeername_fn(s, name, namelen); - } - -@@ -365,7 +357,7 @@ static inline int32_t do_getsockname(int32_t s, struct sockaddr *name, socklen_t - GAZELLE_RETURN(EINVAL); - } - -- if (select_fd_posix_path(s, NULL) == POSIX_LWIP) { -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { - return g_wrap_api->getsockname_fn(s, name, namelen); - } - -@@ -422,7 +414,7 @@ static bool unsupport_optname(int32_t level, int32_t optname) - - static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, void *optval, socklen_t *optlen) - { -- if (select_fd_posix_path(s, NULL) == POSIX_LWIP && !unsupport_optname(level, optname)) { -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP && !unsupport_optname(level, optname)) { - return g_wrap_api->getsockopt_fn(s, level, optname, optval, optlen); - } - -@@ -431,7 +423,7 @@ static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, v - - static inline int32_t do_setsockopt(int32_t s, int32_t level, int32_t optname, const void *optval, socklen_t optlen) - { -- if (select_fd_posix_path(s, NULL) == POSIX_KERNEL || unsupport_optname(level, optname)) { -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_KERNEL || unsupport_optname(level, optname)) { - return posix_api->setsockopt_fn(s, level, optname, optval, optlen); - } - -@@ -473,17 +465,14 @@ static inline ssize_t do_recv(int32_t sockfd, void *buf, size_t len, int32_t fla - if (buf == NULL) { - GAZELLE_RETURN(EINVAL); - } -- - if (len == 0) { - return 0; - } - -- if (select_posix_path() == POSIX_KERNEL || // maybe fd is created by open before posix_api_init called -- select_fd_posix_path(sockfd, NULL) == POSIX_KERNEL) { -- return posix_api->recv_fn(sockfd, buf, len, flags); -+ if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -+ return g_wrap_api->recv_fn(sockfd, buf, len, flags); - } -- -- return g_wrap_api->recv_fn(sockfd, buf, len, flags); -+ return posix_api->recv_fn(sockfd, buf, len, flags); - } - - static inline ssize_t do_read(int32_t s, void *mem, size_t len) -@@ -491,58 +480,46 @@ static inline ssize_t do_read(int32_t s, void *mem, size_t len) - if (mem == NULL) { - GAZELLE_RETURN(EINVAL); - } -- - if (len == 0) { - return 0; - } - -- if (select_posix_path() == POSIX_KERNEL || -- select_fd_posix_path(s, NULL) == POSIX_KERNEL) { -- return posix_api->read_fn(s, mem, len); -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -+ return g_wrap_api->read_fn(s, mem, len); - } -- -- return g_wrap_api->read_fn(s, mem, len); -+ return posix_api->read_fn(s, mem, len); - } - - static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) - { -- if (select_posix_path() == POSIX_KERNEL || -- select_fd_posix_path(s, NULL) == POSIX_KERNEL) { -- return posix_api->readv_fn(s, iov, iovcnt); -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -+ return g_wrap_api->readv_fn(s, iov, iovcnt); - } -- -- return g_wrap_api->readv_fn(s, iov, iovcnt); -+ return posix_api->readv_fn(s, iov, iovcnt); - } - - static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32_t flags) - { -- if (select_posix_path() == POSIX_KERNEL || -- select_fd_posix_path(sockfd, NULL) == POSIX_KERNEL) { -- return posix_api->send_fn(sockfd, buf, len, flags); -+ if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -+ return g_wrap_api->send_fn(sockfd, buf, len, flags); - } -- -- return g_wrap_api->send_fn(sockfd, buf, len, flags); -+ return posix_api->send_fn(sockfd, buf, len, flags); - } - - static inline ssize_t do_write(int32_t s, const void *mem, size_t size) - { -- if (select_posix_path() == POSIX_KERNEL || -- select_fd_posix_path(s, NULL) == POSIX_KERNEL) { -- return posix_api->write_fn(s, mem, size); -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -+ return g_wrap_api->write_fn(s, mem, size); - } -- -- return g_wrap_api->write_fn(s, mem, size); -+ return posix_api->write_fn(s, mem, size); - } - - static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) - { -- struct lwip_sock *sock; -- if (select_posix_path() == POSIX_KERNEL || -- select_fd_posix_path(s, &sock) == POSIX_KERNEL) { -- return posix_api->writev_fn(s, iov, iovcnt); -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -+ return g_wrap_api->writev_fn(s, iov, iovcnt); - } -- -- return g_wrap_api->writev_fn(s, iov, iovcnt); -+ return posix_api->writev_fn(s, iov, iovcnt); - } - - static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flags) -@@ -551,12 +528,10 @@ static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flag - GAZELLE_RETURN(EINVAL); - } - -- if (select_posix_path() == POSIX_KERNEL || -- select_fd_posix_path(s, NULL) == POSIX_KERNEL) { -- return posix_api->recv_msg(s, message, flags); -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -+ return g_wrap_api->recvmsg_fn(s, message, flags); - } -- -- return g_wrap_api->recv_msg(s, message, flags); -+ return posix_api->recvmsg_fn(s, message, flags); - } - - static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_t flags) -@@ -565,13 +540,10 @@ static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_ - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *sock; -- if (select_posix_path() == POSIX_KERNEL || -- select_fd_posix_path(s, &sock) == POSIX_KERNEL) { -- return posix_api->send_msg(s, message, flags); -+ if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -+ return g_wrap_api->sendmsg_fn(s, message, flags); - } -- -- return g_wrap_api->send_msg(s, message, flags); -+ return posix_api->sendmsg_fn(s, message, flags); - } - - static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t flags, -@@ -580,58 +552,48 @@ static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t - if (buf == NULL) { - GAZELLE_RETURN(EINVAL); - } -- - if (len == 0) { - return 0; - } - -- struct lwip_sock *sock = NULL; -- if (select_fd_posix_path(sockfd, &sock) == POSIX_LWIP) { -- return g_wrap_api->recv_from(sockfd, buf, len, flags, addr, addrlen); -+ if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -+ return g_wrap_api->recvfrom_fn(sockfd, buf, len, flags, addr, addrlen); - } -- -- return posix_api->recv_from(sockfd, buf, len, flags, addr, addrlen); -+ return posix_api->recvfrom_fn(sockfd, buf, len, flags, addr, addrlen); - } - - static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int32_t flags, - const struct sockaddr *addr, socklen_t addrlen) - { -- struct lwip_sock *sock = NULL; -- if (select_fd_posix_path(sockfd, &sock) != POSIX_LWIP) { -- return posix_api->send_to(sockfd, buf, len, flags, addr, addrlen); -+ if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -+ return g_wrap_api->sendto_fn(sockfd, buf, len, flags, addr, addrlen); - } -- -- return g_wrap_api->send_to(sockfd, buf, len, flags, addr, addrlen); -+ return posix_api->sendto_fn(sockfd, buf, len, flags, addr, addrlen); - } - --static inline int32_t do_close(int32_t s) -+static inline int32_t do_close(int fd) - { -- struct lwip_sock *sock = NULL; -+ /* Can not use select_sock_posix_path() ! -+ * When fd created by lwip_stocket() set as POSIX_KERNEL, -+ * lwip_close() is still required. -+ */ - if (select_posix_path() == POSIX_KERNEL || -- select_fd_posix_path(s, &sock) == POSIX_KERNEL) { -- /* we called lwip_socket, even if kernel fd */ -- if (posix_api != NULL && !posix_api->ues_posix && -- /* contain posix_api->close_fn if success */ -- g_wrap_api->close_fn(s) == 0) { -- return 0; -- } else { -- return posix_api->close_fn(s); -- } -+ POSIX_IS_CLOSED(lwip_get_socket(fd))) { -+ return posix_api->close_fn(fd); - } -- return g_wrap_api->close_fn(s); -+ return g_wrap_api->close_fn(fd); - } - - static int32_t do_shutdown(int fd, int how) - { -- struct lwip_sock *sock = NULL; -- if (select_posix_path() == POSIX_KERNEL || select_fd_posix_path(fd, &sock) == POSIX_KERNEL) { -- if (posix_api != NULL && !posix_api->ues_posix && g_wrap_api->shutdown_fn(fd, how) == 0) { -- return 0; -- } else { -- return posix_api->shutdown_fn(fd, how); -- } -+ /* Can not use select_sock_posix_path() ! -+ * When fd created by lwip_stocket() set as POSIX_KERNEL, -+ * lwip_close() is still required. -+ */ -+ if (select_posix_path() == POSIX_KERNEL || -+ POSIX_IS_CLOSED(lwip_get_socket(fd))) { -+ return posix_api->shutdown_fn(fd, how); - } -- - return g_wrap_api->shutdown_fn(fd, how); - } - -@@ -660,15 +622,13 @@ static int32_t do_ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec * - return ready; - } - --typedef int32_t (*sigaction_fn)(int32_t signum, const struct sigaction *act, struct sigaction *oldact); - static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct sigaction *oldact) - { -- if (posix_api == NULL) { -- sigaction_fn sf = (sigaction_fn)dlsym(RTLD_NEXT, "sigaction"); -- if (sf == NULL) { -- return -1; -+ if (unlikely(posix_api == NULL)) { -+ if (posix_api_init() != 0) { -+ GAZELLE_RETURN(EAGAIN); - } -- return sf(signum, act, oldact); -+ return posix_api->sigaction_fn(signum, act, oldact); - } - - return lstack_sigaction(signum, act, oldact); -@@ -676,10 +636,14 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct - - static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) - { -- if ((select_posix_path() == POSIX_KERNEL) || !(readfds || writefds || exceptfds) || nfds == 0) { -+ if (nfds <= 0 || !(readfds || writefds || exceptfds)) { -+ GAZELLE_RETURN(EINVAL); -+ } -+ -+ if (select_posix_path() == POSIX_KERNEL) { - return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); - } -- -+ - return g_wrap_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); - } - -@@ -690,9 +654,9 @@ static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set - va_start(ap, _cmd); \ - val = va_arg(ap, typeof(val)); \ - va_end(ap); \ -- struct lwip_sock *sock = NULL; \ -+ struct lwip_sock *sock = lwip_get_socket(_fd); \ - if (select_posix_path() == POSIX_KERNEL || \ -- select_fd_posix_path(_fd, &sock) == POSIX_KERNEL) \ -+ select_sock_posix_path(sock) == POSIX_KERNEL) \ - return _fcntl_fn(_fd, _cmd, val); \ - int32_t ret1 = _fcntl_fn(_fd, _cmd, val); \ - if (ret1 == -1) { \ -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 5545b9f..f1e3064 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -764,7 +764,7 @@ void control_server_thread(void *arg) - struct epoll_event evt_array; - while (1) { - /* wait init finish */ -- if (posix_api->ues_posix) { -+ if (posix_api->use_kernel) { - usleep(GAZELLE_10MS); - continue; - } -@@ -813,7 +813,7 @@ void control_client_thread(void *arg) - - while (1) { - /* wait init finish */ -- if (posix_api->ues_posix) { -+ if (posix_api->use_kernel) { - usleep(GAZELLE_10MS); - continue; - } -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 1b3882e..54ee97e 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -123,7 +123,7 @@ void gazelle_exit(void) - - __attribute__((destructor)) void gazelle_network_exit(void) - { -- if (posix_api != NULL && !posix_api->ues_posix) { -+ if (posix_api != NULL && !posix_api->use_kernel) { - lwip_exit(); - gazelle_exit(); - } -@@ -324,7 +324,7 @@ __attribute__((constructor)) void gazelle_network_init(void) - LSTACK_EXIT(1, "set_process_start_flag failed\n"); - } - -- posix_api->ues_posix = 0; -+ posix_api->use_kernel = 0; - LSTACK_LOG(INFO, LSTACK, "gazelle_network_init success\n"); - rte_smp_mb(); - } -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 84ef782..2b39d05 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -79,6 +79,7 @@ static void reset_sock_data(struct lwip_sock *sock) - sock->send_pre_del = NULL; - } - -+ sock->type = 0; - sock->stack = NULL; - sock->wakeup = NULL; - sock->listen_next = NULL; -@@ -1167,7 +1168,7 @@ void do_lwip_connected_callback(struct netconn *conn) - - int32_t fd = conn->callback_arg.socket; - struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL || sock->conn == NULL) { -+ if (POSIX_IS_CLOSED(sock)) { - return; - } - -@@ -1208,7 +1209,7 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - conn->fd = netconn->callback_arg.socket; - conn->recv_cnt = (netconn->recvmbox == NULL) ? 0 : rte_ring_count(netconn->recvmbox->ring); - struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); -- if (sock != NULL && sock->conn != NULL) { -+ if (!POSIX_IS_CLOSED(sock)) { - conn->recv_ring_cnt = (sock->recv_ring == NULL) ? 0 : gazelle_ring_readable_count(sock->recv_ring); - conn->recv_ring_cnt += (sock->recv_lastdata) ? 1 : 0; - conn->send_ring_cnt = (sock->send_ring == NULL) ? 0 : gazelle_ring_readover_count(sock->send_ring); -diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c -index 8cf4657..689d2bf 100644 ---- a/src/lstack/core/lstack_preload.c -+++ b/src/lstack/core/lstack_preload.c -@@ -79,17 +79,22 @@ static void preload_get_thrdname(void) - LSTACK_PRE_LOG(LSTACK_INFO, "thread name=%s ok\n", g_preload_info.env_thrdname); - } - --enum posix_type select_fd_posix_path(int32_t fd, struct lwip_sock **socket) -+enum posix_type select_sock_posix_path(struct lwip_sock *sock) - { -- struct lwip_sock *sock = lwip_get_socket(fd); -- -- /* AF_UNIX case */ -- if (!sock || !sock->conn || POSIX_IS_TYPE(sock, POSIX_KERNEL)) { -+ if (unlikely(posix_api == NULL)) { -+ /* -+ * read/write/readv/writev may not be sockfd, -+ * posix api maybe not init. -+ */ -+ if (posix_api_init() != 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "posix_api_init failed\n"); -+ } - return POSIX_KERNEL; - } - -- if (socket) { -- *socket = sock; -+ /* CLOSED means not sockfd, such as file fd or unix fd */ -+ if (POSIX_IS_CLOSED(sock) || POSIX_IS_TYPE(sock, POSIX_KERNEL)) { -+ return POSIX_KERNEL; - } - - if (likely(POSIX_IS_TYPE(sock, POSIX_LWIP))) { -@@ -112,11 +117,11 @@ enum posix_type select_posix_path(void) - return POSIX_KERNEL; - } - -- if (unlikely(posix_api->ues_posix)) { -+ if (unlikely(posix_api->use_kernel)) { - return POSIX_KERNEL; - } - -- if (g_preload_thrdpath != POSIX_ALL) { -+ if (likely(g_preload_thrdpath != POSIX_ALL)) { - return g_preload_thrdpath; - } - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index d17cb67..a809d8c 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -127,7 +127,7 @@ struct protocol_stack *get_protocol_stack(void) - struct protocol_stack *get_protocol_stack_by_fd(int32_t fd) - { - struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL || sock->conn == NULL) { -+ if (POSIX_IS_CLOSED(sock)) { - return NULL; - } - -@@ -1126,7 +1126,7 @@ int32_t stack_broadcast_close(int32_t fd) - ret = -1; - } - -- if (sock == NULL || sock->conn == NULL) { -+ if (POSIX_IS_CLOSED(sock)) { - break; - } - fd = sock->conn->callback_arg.socket; -@@ -1151,7 +1151,7 @@ int stack_broadcast_shutdown(int fd, int how) - ret = -1; - } - -- if (sock == NULL || sock->conn == NULL) { -+ if (POSIX_IS_CLOSED(sock)) { - break; - } - fd = sock->conn->callback_arg.socket; -@@ -1357,7 +1357,7 @@ static void stack_all_fds_close(void) - { - for (int i = 3; i < GAZELLE_MAX_CLIENTS + GAZELLE_RESERVED_CLIENTS; i++) { - struct lwip_sock *sock = lwip_get_socket(i); -- if (sock && sock->conn && sock->stack == get_protocol_stack()) { -+ if (!POSIX_IS_CLOSED(sock) && sock->stack == get_protocol_stack()) { - lwip_close(i); - } - } -diff --git a/src/lstack/include/lstack_preload.h b/src/lstack/include/lstack_preload.h -index c30736a..d4ad385 100644 ---- a/src/lstack/include/lstack_preload.h -+++ b/src/lstack/include/lstack_preload.h -@@ -11,9 +11,9 @@ - */ - #ifndef __LSTACK_PRELOAD_H__ - #define __LSTACK_PRELOAD_H__ --#include - - enum posix_type select_posix_path(void); --enum posix_type select_fd_posix_path(int32_t fd, struct lwip_sock **socket); -+enum posix_type select_sock_posix_path(struct lwip_sock *sock); - int preload_info_init(void); --#endif -+ -+#endif /* __LSTACK_PRELOAD_H__ */ -diff --git a/src/lstack/netif/lstack_flow.c b/src/lstack/netif/lstack_flow.c -index 84c5c61..1ca3314 100644 ---- a/src/lstack/netif/lstack_flow.c -+++ b/src/lstack/netif/lstack_flow.c -@@ -19,6 +19,7 @@ - #include - - #include -+#include - #include - #include - --- -2.33.0 - diff --git a/0220-cleancode-refactor-lwipgz_list.h.patch b/0220-cleancode-refactor-lwipgz_list.h.patch deleted file mode 100644 index 64d79c410145a1f047347d1aabc19208d4609807..0000000000000000000000000000000000000000 --- a/0220-cleancode-refactor-lwipgz_list.h.patch +++ /dev/null @@ -1,445 +0,0 @@ -From daacb87180fa9c98c53c001bb37929b9aaef46d9 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 15 Jul 2024 11:27:19 +0800 -Subject: [PATCH] cleancode: refactor lwipgz_list.h - - Changed: - list_is_empty -> list_head_empty - list_is_null -> list_node_null - - init_list_node -> list_init_head - init_list_node_null -> list_init_node - - list_add_node -> list_add_node - list_del_node_null -> list_del_node - list_del_node -> __list_del_node - list_for_each_safe -> list_for_each_node - Deprecated: - list_del_node_init - Added: - list_get_node_count - list_entry - -Signed-off-by: Lemmy Huang ---- - src/common/gazelle_base_func.h | 5 +- - src/lstack/api/lstack_epoll.c | 66 ++++++++++++------------- - src/lstack/api/lstack_rtc_api.c | 2 +- - src/lstack/core/lstack_lwip.c | 28 +++++------ - src/lstack/core/lstack_protocol_stack.c | 14 +++--- - src/lstack/core/lstack_stack_stat.c | 4 +- - 6 files changed, 60 insertions(+), 59 deletions(-) - -diff --git a/src/common/gazelle_base_func.h b/src/common/gazelle_base_func.h -index 2d629c1..be87ccd 100644 ---- a/src/common/gazelle_base_func.h -+++ b/src/common/gazelle_base_func.h -@@ -36,7 +36,8 @@ int32_t filename_check(const char* args); - - void gazelle_exit(void); - --#undef container_of --#define container_of(ptr, type, field) ((type *)(void*)(((char *)(ptr)) - offsetof(type, field))) -+/* Do not check if the type of ptr and type->member are the same */ -+#define container_of_uncheck_ptr(ptr, type, member) \ -+ ((type *)(void*)(((char *)(ptr)) - offsetof(type, member))) - - #endif /* ifndef __GAZELLE_BASE_FUNC_H__ */ -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 06c708b..2f48606 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -49,8 +49,8 @@ static void change_epollfd_kernel_thread(struct wakeup_poll *wakeup, struct prot - - static inline void add_wakeup_to_stack_wakeuplist(struct wakeup_poll *wakeup, struct protocol_stack *stack) - { -- if (list_is_null(&wakeup->wakeup_list[stack->stack_idx])) { -- list_add_node(&stack->wakeup_list, &wakeup->wakeup_list[stack->stack_idx]); -+ if (list_node_null(&wakeup->wakeup_list[stack->stack_idx])) { -+ list_add_node(&wakeup->wakeup_list[stack->stack_idx], &stack->wakeup_list); - } - } - -@@ -73,8 +73,8 @@ void add_sock_event_nolock(struct lwip_sock *sock, uint32_t event) - } - - sock->events |= (event == EPOLLERR) ? (EPOLLIN | EPOLLERR) : (event & sock->epoll_events); -- if (list_is_null(&sock->event_list)) { -- list_add_node(&wakeup->event_list, &sock->event_list); -+ if (list_node_null(&sock->event_list)) { -+ list_add_node(&sock->event_list, &wakeup->event_list); - } - return; - } -@@ -111,7 +111,7 @@ void del_sock_event_nolock(struct lwip_sock *sock, uint32_t event) - } - - if (sock->events == 0) { -- list_del_node_null(&sock->event_list); -+ list_del_node(&sock->event_list); - } - return; - } -@@ -127,7 +127,7 @@ void wakeup_stack_epoll(struct protocol_stack *stack) - { - struct list_node *node, *temp; - -- list_for_each_safe(node, temp, &stack->wakeup_list) { -+ list_for_each_node(node, temp, &stack->wakeup_list) { - /* When temp is NULL, find the tail node in the wekeup_list and connect it to the back of the node */ - if (unlikely(temp == NULL)) { - struct list_node *nod = &stack->wakeup_list; -@@ -139,7 +139,7 @@ void wakeup_stack_epoll(struct protocol_stack *stack) - temp = nod; - } - -- struct wakeup_poll *wakeup = container_of((node - stack->stack_idx), struct wakeup_poll, wakeup_list); -+ struct wakeup_poll *wakeup = container_of_uncheck_ptr((node - stack->stack_idx), struct wakeup_poll, wakeup_list); - - if (__atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -@@ -148,7 +148,7 @@ void wakeup_stack_epoll(struct protocol_stack *stack) - stack->stats.wakeup_events++; - } - -- list_del_node_null(&wakeup->wakeup_list[stack->stack_idx]); -+ list_del_node(&wakeup->wakeup_list[stack->stack_idx]); - } - } - -@@ -198,8 +198,8 @@ static void rtc_raise_pending_events(struct wakeup_poll *wakeup, struct lwip_soc - if (event) { - sock->events = event; - if (wakeup->type == WAKEUP_EPOLL && (sock->events & sock->epoll_events) && -- list_is_null(&sock->event_list)) { -- list_add_node(&wakeup->event_list, &sock->event_list); -+ list_node_null(&sock->event_list)) { -+ list_add_node(&sock->event_list, &wakeup->event_list); - } - } - } -@@ -227,8 +227,8 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s - if (event) { - sock->events = event; - if (wakeup->type == WAKEUP_EPOLL && (sock->events & sock->epoll_events) && -- list_is_null(&sock->event_list)) { -- list_add_node(&wakeup->event_list, &sock->event_list); -+ list_node_null(&sock->event_list)) { -+ list_add_node(&sock->event_list, &wakeup->event_list); - } - } - pthread_spin_unlock(&wakeup->event_list_lock); -@@ -255,7 +255,7 @@ int32_t lstack_do_epoll_create(int32_t fd) - } - - for (uint32_t i = 0; i < PROTOCOL_STACK_MAX; i++) { -- init_list_node_null(&wakeup->wakeup_list[i]); -+ list_init_node(&wakeup->wakeup_list[i]); - } - - if (sem_init(&wakeup->wait, 0, 0) != 0) { -@@ -266,12 +266,12 @@ int32_t lstack_do_epoll_create(int32_t fd) - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); - - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- init_list_node_null(&wakeup->poll_list); -+ list_init_node(&wakeup->poll_list); - pthread_spin_lock(&stack_group->poll_list_lock); -- list_add_node(&stack_group->poll_list, &wakeup->poll_list); -+ list_add_node(&wakeup->poll_list, &stack_group->poll_list); - pthread_spin_unlock(&stack_group->poll_list_lock); - -- init_list_node(&wakeup->event_list); -+ list_init_head(&wakeup->event_list); - pthread_spin_init(&wakeup->event_list_lock, PTHREAD_PROCESS_PRIVATE); - - wakeup->type = WAKEUP_EPOLL; -@@ -327,15 +327,15 @@ int32_t lstack_epoll_close(int32_t fd) - - struct list_node *node, *temp; - pthread_spin_lock(&wakeup->event_list_lock); -- list_for_each_safe(node, temp, &wakeup->event_list) { -- struct lwip_sock *sock = container_of(node, struct lwip_sock, event_list); -- list_del_node_null(&sock->event_list); -+ list_for_each_node(node, temp, &wakeup->event_list) { -+ struct lwip_sock *sock = list_entry(node, struct lwip_sock, event_list); -+ list_del_node(&sock->event_list); - } - pthread_spin_unlock(&wakeup->event_list_lock); - pthread_spin_destroy(&wakeup->event_list_lock); - - pthread_spin_lock(&stack_group->poll_list_lock); -- list_del_node_null(&wakeup->poll_list); -+ list_del_node(&wakeup->poll_list); - pthread_spin_unlock(&stack_group->poll_list_lock); - - sem_destroy(&wakeup->wait); -@@ -413,7 +413,7 @@ int32_t lstack_rtc_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ - break; - case EPOLL_CTL_DEL: - sock->epoll_events = 0; -- list_del_node_null(&sock->event_list); -+ list_del_node(&sock->event_list); - break; - default: - GAZELLE_RETURN(EINVAL); -@@ -464,7 +464,7 @@ int32_t lstack_rtw_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ - sock->epoll_events = 0; - wakeup->stack_fd_cnt[sock->stack->stack_idx]--; - pthread_spin_lock(&wakeup->event_list_lock); -- list_del_node_null(&sock->event_list); -+ list_del_node(&sock->event_list); - pthread_spin_unlock(&wakeup->event_list_lock); - break; - default: -@@ -482,18 +482,18 @@ int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event * - int32_t event_num = 0; - struct list_node *node, *temp; - -- list_for_each_safe(node, temp, &wakeup->event_list) { -- struct lwip_sock *sock = container_of(node, struct lwip_sock, event_list); -+ list_for_each_node(node, temp, &wakeup->event_list) { -+ struct lwip_sock *sock = list_entry(node, struct lwip_sock, event_list); - - if ((sock->epoll_events & sock->events) == 0) { -- list_del_node_null(node); -+ list_del_node(node); - continue; - } - - if (event_num >= maxevents) { - /* move list head after the current node, and start traversing from this node next time */ -- list_del_node_null(&wakeup->event_list); -- list_add_node(node, &wakeup->event_list); -+ list_del_node(&wakeup->event_list); -+ list_add_node(&wakeup->event_list, node); - break; - } - -@@ -502,14 +502,14 @@ int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event * - event_num++; - - if (sock->epoll_events & EPOLLET) { -- list_del_node_null(node); -+ list_del_node(node); - sock->events = 0; - } - - /* EPOLLONESHOT: generate event after epoll_ctl add/mod event again - epoll_event set 0 avoid generating event util epoll_ctl reset epoll_event */ - if (sock->epoll_events & EPOLLONESHOT) { -- list_del_node_null(node); -+ list_del_node(node); - sock->epoll_events = 0; - } - } -@@ -654,7 +654,7 @@ int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t - } - - loop_flag = false; -- if (!kernel_num && list_is_empty(&wakeup->event_list) && tmptimeout != 0) { -+ if (!kernel_num && list_head_empty(&wakeup->event_list) && tmptimeout != 0) { - loop_flag = true; - } - } while (loop_flag); -@@ -721,7 +721,7 @@ static int32_t init_poll_wakeup_data(struct wakeup_poll *wakeup) - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); - - for (uint32_t i = 0; i < PROTOCOL_STACK_MAX; i++) { -- init_list_node_null(&wakeup->wakeup_list[i]); -+ list_init_node(&wakeup->wakeup_list[i]); - } - - wakeup->epollfd = posix_api->epoll_create_fn(POLL_KERNEL_EVENTS); -@@ -745,9 +745,9 @@ static int32_t init_poll_wakeup_data(struct wakeup_poll *wakeup) - } - - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- init_list_node_null(&wakeup->poll_list); -+ list_init_node(&wakeup->poll_list); - pthread_spin_lock(&stack_group->poll_list_lock); -- list_add_node(&stack_group->poll_list, &wakeup->poll_list); -+ list_add_node(&wakeup->poll_list, &stack_group->poll_list); - pthread_spin_unlock(&stack_group->poll_list_lock); - - int32_t stack_count[PROTOCOL_STACK_MAX] = {0}; -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index 97623b3..ca0e7ec 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -56,7 +56,7 @@ int rtc_socket(int domain, int type, int protocol) - sock->epoll_events = 0; - sock->events = 0; - sock->wakeup = NULL; -- init_list_node_null(&sock->event_list); -+ list_init_node(&sock->event_list); - } - return ret; - } -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index f52f39f..c05a763 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -173,8 +173,8 @@ int do_lwip_init_sock(int32_t fd) - - sock->stack = stack; - -- init_list_node_null(&sock->recv_list); -- init_list_node_null(&sock->event_list); -+ list_init_node(&sock->recv_list); -+ list_init_node(&sock->event_list); - return 0; - } - -@@ -187,7 +187,7 @@ void do_lwip_clean_sock(int fd) - - if (sock->wakeup && sock->wakeup->type == WAKEUP_EPOLL) { - pthread_spin_lock(&sock->wakeup->event_list_lock); -- list_del_node_null(&sock->event_list); -+ list_del_node(&sock->event_list); - pthread_spin_unlock(&sock->wakeup->event_list_lock); - } - -@@ -195,7 +195,7 @@ void do_lwip_clean_sock(int fd) - - reset_sock_data(sock); - -- list_del_node_null(&sock->recv_list); -+ list_del_node(&sock->recv_list); - } - - void do_lwip_free_pbuf(struct pbuf *pbuf) -@@ -1098,8 +1098,8 @@ void do_lwip_add_recvlist(int32_t fd) - { - struct lwip_sock *sock = lwip_get_socket(fd); - -- if (sock && sock->stack && list_is_null(&sock->recv_list)) { -- list_add_node(&sock->stack->recv_list, &sock->recv_list); -+ if (sock && sock->stack && list_node_null(&sock->recv_list)) { -+ list_add_node(&sock->recv_list, &sock->stack->recv_list); - } - } - -@@ -1109,8 +1109,8 @@ void read_same_node_recv_list(struct protocol_stack *stack) - struct list_node *node, *temp; - struct lwip_sock *sock; - -- list_for_each_safe(node, temp, list) { -- sock = container_of(node, struct lwip_sock, recv_list); -+ list_for_each_node(node, temp, list) { -+ sock = list_entry(node, struct lwip_sock, recv_list); - - if (sock->same_node_rx_ring != NULL && same_node_ring_count(sock)) { - add_sock_event(sock, EPOLLIN); -@@ -1125,18 +1125,18 @@ void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num) - struct lwip_sock *sock; - uint32_t read_num = 0; - -- list_for_each_safe(node, temp, list) { -- sock = container_of(node, struct lwip_sock, recv_list); -+ list_for_each_node(node, temp, list) { -+ sock = list_entry(node, struct lwip_sock, recv_list); - - if (++read_num > max_num) { - /* list head move to next send */ - list_del_node(&stack->recv_list); -- list_add_node(&sock->recv_list, &stack->recv_list); -+ list_add_node(&stack->recv_list, &sock->recv_list); - break; - } - - if (sock->conn == NULL || sock->conn->recvmbox == NULL || rte_ring_count(sock->conn->recvmbox->ring) == 0) { -- list_del_node_null(&sock->recv_list); -+ list_del_node(&sock->recv_list); - continue; - } - -@@ -1215,7 +1215,7 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - conn->send_ring_cnt = (sock->send_ring == NULL) ? 0 : gazelle_ring_readover_count(sock->send_ring); - conn->events = sock->events; - conn->epoll_events = sock->epoll_events; -- conn->eventlist = !list_is_null(&sock->event_list); -+ conn->eventlist = !list_node_null(&sock->event_list); - } - } - } -@@ -1426,7 +1426,7 @@ err_t find_same_node_memzone(struct tcp_pcb *pcb, struct lwip_sock *nsock) - - /* rcvlink init in alloc_socket() */ - /* remove from g_rcv_process_list in free_socket */ -- list_add_node(&nsock->stack->same_node_recv_list, &nsock->recv_list); -+ list_add_node(&nsock->recv_list, &nsock->stack->same_node_recv_list); - return 0; - } - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 4f5cfae..9bb1b6a 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -328,9 +328,9 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) - stack->stack_idx = t_params->idx; - stack->lwip_stats = &lwip_stats; - -- init_list_node(&stack->recv_list); -- init_list_node(&stack->same_node_recv_list); -- init_list_node(&stack->wakeup_list); -+ list_init_head(&stack->recv_list); -+ list_init_head(&stack->same_node_recv_list); -+ list_init_head(&stack->wakeup_list); - - sys_calibrate_tsc(); - stack_stat_init(); -@@ -588,7 +588,7 @@ int32_t stack_group_init(void) - struct protocol_stack_group *stack_group = get_protocol_stack_group(); - stack_group->stack_num = 0; - -- init_list_node(&stack_group->poll_list); -+ list_init_head(&stack_group->poll_list); - pthread_spin_init(&stack_group->poll_list_lock, PTHREAD_PROCESS_PRIVATE); - pthread_spin_init(&stack_group->socket_lock, PTHREAD_PROCESS_PRIVATE); - if (sem_init(&stack_group->sem_stack_setup, 0, 0) < 0) { -@@ -1013,7 +1013,7 @@ void stack_clean_epoll(struct rpc_msg *msg) - struct protocol_stack *stack = get_protocol_stack(); - struct wakeup_poll *wakeup = (struct wakeup_poll *)msg->args[MSG_ARG_0].p; - -- list_del_node_null(&wakeup->wakeup_list[stack->stack_idx]); -+ list_del_node(&wakeup->wakeup_list[stack->stack_idx]); - } - - void stack_mempool_size(struct rpc_msg *msg) -@@ -1103,7 +1103,7 @@ void stack_recvlist_count(struct rpc_msg *msg) - struct list_node *node; - struct list_node *temp; - -- list_for_each_safe(node, temp, list) { -+ list_for_each_node(node, temp, list) { - count++; - } - -@@ -1258,7 +1258,7 @@ static void inline del_accept_in_event(struct lwip_sock *sock) - if (!NETCONN_IS_ACCEPTIN(sock)) { - sock->events &= ~EPOLLIN; - if (sock->events == 0) { -- list_del_node_null(&sock->event_list); -+ list_del_node(&sock->event_list); - } - } - -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index e42efde..0411d9e 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -230,8 +230,8 @@ static void get_wakeup_stat(struct protocol_stack_group *stack_group, struct pro - - pthread_spin_lock(&stack_group->poll_list_lock); - -- list_for_each_safe(node, temp, &stack_group->poll_list) { -- struct wakeup_poll *wakeup = container_of(node, struct wakeup_poll, poll_list); -+ list_for_each_node(node, temp, &stack_group->poll_list) { -+ struct wakeup_poll *wakeup = list_entry(node, struct wakeup_poll, poll_list); - - if (wakeup->bind_stack == stack) { - stat->kernel_events += wakeup->stat.kernel_events; --- -2.33.0 - diff --git a/0221-fix-EPOLLIN-event-dropd.patch b/0221-fix-EPOLLIN-event-dropd.patch deleted file mode 100644 index 87d1a34ed19f0826bcd9fb520289f26ce71380c9..0000000000000000000000000000000000000000 --- a/0221-fix-EPOLLIN-event-dropd.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 065b0fe7ac355ba741f7a2be96738c4792e13cfe Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Thu, 18 Jul 2024 11:59:52 +0000 -Subject: [PATCH] fix EPOLLIN event dropd - ---- - src/lstack/api/lstack_epoll.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 06c708b..ff80003 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -208,6 +208,7 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s - { - uint32_t event = 0; - -+ pthread_spin_lock(&wakeup->event_list_lock); - if (NETCONN_IS_DATAIN(sock) || NETCONN_IS_ACCEPTIN(sock)) { - event |= EPOLLIN; - } -@@ -216,7 +217,6 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s - event |= EPOLLERR | EPOLLIN; - } - -- pthread_spin_lock(&wakeup->event_list_lock); - if (NETCONN_IS_OUTIDLE(sock)) { - /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ - if (!POSIX_IS_CLOSED(sock) && POSIX_IS_TYPE(sock, POSIX_LWIP)) { --- -2.33.0 - diff --git a/0222-cleancode-refactor-lwipgz_hlist.h.patch b/0222-cleancode-refactor-lwipgz_hlist.h.patch deleted file mode 100644 index 9bd4e81918da9f692146dd14e5a687d42d181c2c..0000000000000000000000000000000000000000 --- a/0222-cleancode-refactor-lwipgz_hlist.h.patch +++ /dev/null @@ -1,160 +0,0 @@ -From 288f7301ecafb2c53ab4671361109803af118668 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Thu, 11 Jul 2024 16:04:00 +0800 -Subject: [PATCH] cleancode: refactor lwipgz_hlist.h - - Changed: - INIT_HLIST_HEAD -> hlist_init_head - INIT_HLIST_NODE -> hlist_init_node - hlist_empty -> hlist_head_empty - hlist_unhashed -> hlist_node_null - hlist_del_init -> hlist_del_node - Not changed: - hlist_add_head - hlist_add_before - hlist_add_after - Deprecated: - INIT_HLIST_CTRL - hlist_ctl_del - hlist_pop_tail - hlist_pop_head - hlist_ctl_add_tail - hlist_ctl_add_head - hlist_ctl_add_after - hlist_ctl_add_before - -Signed-off-by: Lemmy Huang ---- - src/ltran/ltran_stack.c | 6 +++--- - src/ltran/ltran_tcp_conn.c | 6 +++--- - src/ltran/ltran_tcp_sock.c | 6 +++--- - src/ltran/ltran_timer.c | 6 +++--- - 4 files changed, 12 insertions(+), 12 deletions(-) - -diff --git a/src/ltran/ltran_stack.c b/src/ltran/ltran_stack.c -index 299fb7a..737d883 100644 ---- a/src/ltran/ltran_stack.c -+++ b/src/ltran/ltran_stack.c -@@ -43,7 +43,7 @@ struct gazelle_stack_htable *gazelle_stack_htable_create(uint32_t max_stack_num) - } - - for (i = 0; i < GAZELLE_MAX_STACK_HTABLE_SIZE; i++) { -- INIT_HLIST_HEAD(&stack_htable->array[i].chain); -+ hlist_init_head(&stack_htable->array[i].chain); - stack_htable->array[i].chain_size = 0; - } - stack_htable->cur_stack_num = 0; -@@ -68,7 +68,7 @@ void gazelle_stack_htable_destroy(void) - while (node != NULL) { - stack = hlist_entry(node, typeof(*stack), stack_node); - node = node->next; -- hlist_del_init(&stack->stack_node); -+ hlist_del_node(&stack->stack_node); - free(stack); - } - } -@@ -181,7 +181,7 @@ void gazelle_stack_del_by_tid(struct gazelle_stack_htable *stack_htable, uint32_ - } - } - -- hlist_del_init(&stack->stack_node); -+ hlist_del_node(&stack->stack_node); - stack_htable->cur_stack_num--; - stack_hbucket->chain_size--; - -diff --git a/src/ltran/ltran_tcp_conn.c b/src/ltran/ltran_tcp_conn.c -index 026d22a..2c8f8ef 100644 ---- a/src/ltran/ltran_tcp_conn.c -+++ b/src/ltran/ltran_tcp_conn.c -@@ -40,7 +40,7 @@ struct gazelle_tcp_conn_htable *gazelle_tcp_conn_htable_create(uint32_t max_conn - } - - for (i = 0; i < GAZELLE_MAX_CONN_HTABLE_SIZE; i++) { -- INIT_HLIST_HEAD(&conn_htable->array[i].chain); -+ hlist_init_head(&conn_htable->array[i].chain); - conn_htable->array[i].chain_size = 0; - } - conn_htable->cur_conn_num = 0; -@@ -65,7 +65,7 @@ void gazelle_tcp_conn_htable_destroy(void) - while (node != NULL) { - conn = hlist_entry(node, typeof(*conn), conn_node); - node = node->next; -- hlist_del_init(&conn->conn_node); -+ hlist_del_node(&conn->conn_node); - rte_free(conn); - } - } -@@ -175,7 +175,7 @@ void gazelle_conn_del_by_quintuple(struct gazelle_tcp_conn_htable *conn_htable, - return; - } - -- hlist_del_init(&conn->conn_node); -+ hlist_del_node(&conn->conn_node); - rte_free(conn); - conn_htable->cur_conn_num--; - conn_hbucket->chain_size--; -diff --git a/src/ltran/ltran_tcp_sock.c b/src/ltran/ltran_tcp_sock.c -index eef2821..1e06bd7 100644 ---- a/src/ltran/ltran_tcp_sock.c -+++ b/src/ltran/ltran_tcp_sock.c -@@ -51,7 +51,7 @@ struct gazelle_tcp_sock_htable *gazelle_tcp_sock_htable_create(uint32_t max_tcp_ - } - - for (i = 0; i < GAZELLE_MAX_TCP_SOCK_HTABLE_SIZE; i++) { -- INIT_HLIST_HEAD(&tcp_sock_htable->array[i].chain); -+ hlist_init_head(&tcp_sock_htable->array[i].chain); - tcp_sock_htable->array[i].chain_size = 0; - } - tcp_sock_htable->cur_tcp_sock_num = 0; -@@ -77,7 +77,7 @@ void gazelle_tcp_sock_htable_destroy(void) - while (node != NULL) { - tcp_sock = hlist_entry(node, typeof(*tcp_sock), tcp_sock_node); - node = node->next; -- hlist_del_init(&tcp_sock->tcp_sock_node); -+ hlist_del_node(&tcp_sock->tcp_sock_node); - free(tcp_sock); - } - } -@@ -186,7 +186,7 @@ void gazelle_sock_del_by_ipporttid(struct gazelle_tcp_sock_htable *tcp_sock_htab - return; - } - -- hlist_del_init(&tcp_sock->tcp_sock_node); -+ hlist_del_node(&tcp_sock->tcp_sock_node); - free(tcp_sock); - tcp_sock_htable->cur_tcp_sock_num--; - tcp_sock_hbucket->chain_size--; -diff --git a/src/ltran/ltran_timer.c b/src/ltran/ltran_timer.c -index 87046cb..51d6544 100644 ---- a/src/ltran/ltran_timer.c -+++ b/src/ltran/ltran_timer.c -@@ -63,7 +63,7 @@ void gazelle_detect_sock_logout(struct gazelle_tcp_sock_htable *tcp_sock_htable) - tcp_sock = hlist_entry(node, typeof(*tcp_sock), tcp_sock_node); - node = node->next; - if (!INSTANCE_IS_ON(tcp_sock)) { -- hlist_del_init(&tcp_sock->tcp_sock_node); -+ hlist_del_node(&tcp_sock->tcp_sock_node); - tcp_sock_htable->cur_tcp_sock_num--; - tcp_sock_htable->array[i].chain_size--; - LTRAN_DEBUG("delete the tcp sock htable: tid %u ip %u port %u\n", -@@ -99,7 +99,7 @@ void gazelle_detect_conn_logout(struct gazelle_tcp_conn_htable *conn_htable) - conn = hlist_entry(node, typeof(*conn), conn_node); - node = node->next; - if (!INSTANCE_IS_ON(conn)) { -- hlist_del_init(&conn->conn_node); -+ hlist_del_node(&conn->conn_node); - conn_htable->cur_conn_num--; - conn_htable->array[i].chain_size--; - LTRAN_DEBUG("delete the tcp conn htable: tid %u quintuple[%u %u %u %u %u]\n", -@@ -146,7 +146,7 @@ void gazelle_delete_aging_conn(struct gazelle_tcp_conn_htable *conn_htable) - continue; - } - -- hlist_del_init(&conn->conn_node); -+ hlist_del_node(&conn->conn_node); - conn_htable->cur_conn_num--; - conn_htable->array[i].chain_size--; - if (conn->sock) { --- -2.33.0 - diff --git a/0223-add-sem-post-when-update-event.patch b/0223-add-sem-post-when-update-event.patch deleted file mode 100644 index 45a1a1c465c85218739e86a6eee55b1999814734..0000000000000000000000000000000000000000 --- a/0223-add-sem-post-when-update-event.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 2ad0be3590c8ac380c2b0e87f28653b994916c65 Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Thu, 18 Jul 2024 13:40:15 +0000 -Subject: [PATCH] add sem post when update event - ---- - src/lstack/api/lstack_epoll.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index e92faac..417499b 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -229,6 +229,7 @@ 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); - } - } - pthread_spin_unlock(&wakeup->event_list_lock); --- -2.33.0 - diff --git a/0224-cleancode-refactor-sys_now-and-lwip_ioctl.patch b/0224-cleancode-refactor-sys_now-and-lwip_ioctl.patch deleted file mode 100644 index 369aba087669a53c42210690cec170de260261a5..0000000000000000000000000000000000000000 --- a/0224-cleancode-refactor-sys_now-and-lwip_ioctl.patch +++ /dev/null @@ -1,673 +0,0 @@ -From 107e0eda4e255dc93aa94a9ffa31427f912341f5 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 12 Jul 2024 11:02:59 +0800 -Subject: [PATCH] cleancode: refactor sys_now and lwip_ioctl - -Signed-off-by: Lemmy Huang ---- - src/common/gazelle_dfx_msg.h | 8 ++++- - src/lstack/api/lstack_epoll.c | 4 ++- - src/lstack/api/lstack_wrap.c | 47 +++++++++++-------------- - src/lstack/core/lstack_cfg.c | 1 - - src/lstack/core/lstack_control_plane.c | 21 ++++++----- - src/lstack/core/lstack_dpdk.c | 10 +++--- - src/lstack/core/lstack_init.c | 2 -- - src/lstack/core/lstack_lwip.c | 19 +++++----- - src/lstack/core/lstack_protocol_stack.c | 12 +++---- - src/lstack/core/lstack_stack_stat.c | 29 +++------------ - src/lstack/include/lstack_stack_stat.h | 1 - - src/lstack/include/lstack_thread_rpc.h | 1 - - src/lstack/netif/lstack_ethdev.c | 3 +- - src/ltran/ltran_forward.c | 10 +++--- - src/ltran/ltran_stat.c | 2 +- - src/ltran/ltran_stat.h | 6 ---- - src/ltran/ltran_timer.c | 14 +++----- - src/ltran/ltran_timer.h | 4 +-- - test/unitest/stub.c | 6 ---- - 19 files changed, 79 insertions(+), 121 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index a2ec07b..8eb54ff 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -87,6 +87,12 @@ enum GAZELLE_LATENCY_TYPE { - GAZELLE_LATENCY_MAX, - }; - -+enum GAZELLE_TCP_LIST_STATE { -+ GAZELLE_ACTIVE_LIST, -+ GAZELLE_LISTEN_LIST, -+ GAZELLE_TIME_WAIT_LIST, -+}; -+ - struct gazelle_stack_stat { - uint64_t wakeup_events; - uint64_t write_lwip_cnt; -@@ -240,7 +246,6 @@ struct gazelle_stat_lstack_proto { - }; - - --/* same as define in lwip/tcp.h - struct tcp_pcb_dp */ - struct gazelle_stat_lstack_conn_info { - uint32_t state; - gz_addr_t rip; -@@ -252,6 +257,7 @@ struct gazelle_stat_lstack_conn_info { - uint32_t send_ring_cnt; - uint32_t recv_ring_cnt; - uint32_t tcp_sub_state; -+ - uint32_t cwn; - uint32_t rcv_wnd; - uint32_t snd_wnd; -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 2f48606..3ad22b9 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -650,7 +650,9 @@ int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t - } - } - if (tmptimeout > 0) { -- tmptimeout = update_timeout(tmptimeout, poll_ts); -+ if (tmptimeout <= sys_now() - poll_ts) { -+ tmptimeout = 0; -+ } - } - - loop_flag = false; -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index b19990e..976a3f3 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -647,36 +647,31 @@ static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set - return g_wrap_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); - } - --#define WRAP_VA_PARAM(_fd, _cmd, _lwip_fcntl, _fcntl_fn) \ -+#define POSIX_VA_PARAM(fd, cmd, type, lwip_fn, kernel_fn) \ - do { \ -- unsigned long val; \ -- va_list ap; \ -- va_start(ap, _cmd); \ -- val = va_arg(ap, typeof(val)); \ -- va_end(ap); \ -- struct lwip_sock *sock = lwip_get_socket(_fd); \ -- if (select_posix_path() == POSIX_KERNEL || \ -- select_sock_posix_path(sock) == POSIX_KERNEL) \ -- return _fcntl_fn(_fd, _cmd, val); \ -- int32_t ret1 = _fcntl_fn(_fd, _cmd, val); \ -- if (ret1 == -1) { \ -- LSTACK_LOG(ERR, LSTACK, "fd(%d) kernel path call failed, errno is %d, maybe not error\n", \ -- _fd, errno); \ -- return ret1; \ -+ unsigned long __val; \ -+ va_list __ap; \ -+ va_start(__ap, cmd); \ -+ __val = va_arg(__ap, typeof(__val)); \ -+ va_end(__ap); \ -+ /* always try kernel */ \ -+ int __ret1 = kernel_fn(fd, cmd, __val); \ -+ if (__ret1 == -1 || select_sock_posix_path(lwip_get_socket(fd)) == POSIX_KERNEL) { \ -+ return __ret1; \ - } \ -- int32_t ret2 = _lwip_fcntl(_fd, _cmd, val); \ -+ int __ret2 = lwip_fn(fd, cmd, (type)__val); \ - /* - * if function not implemented, fcntl get/set context will not be modifyed by user path, - * return kernel path result - */ \ -- if (ret2 == -1) { \ -+ if (__ret2 == -1) { \ - if (errno == ENOSYS) { \ -- return ret1; \ -+ return __ret1; \ - } \ - LSTACK_LOG(ERR, LSTACK, "fd(%d) user path call failed, errno is %d, maybe not error\n", \ -- _fd, errno); \ -+ fd, errno); \ - } \ -- return ret2; \ -+ return __ret2; \ - } while (0) - - /* -------------------------------------------------------- -@@ -701,15 +696,15 @@ int32_t epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, - } - int32_t fcntl64(int32_t s, int32_t cmd, ...) - { -- WRAP_VA_PARAM(s, cmd, lwip_fcntl, posix_api->fcntl64_fn); -+ POSIX_VA_PARAM(s, cmd, int, lwip_fcntl, posix_api->fcntl64_fn); - } - int32_t fcntl(int32_t s, int32_t cmd, ...) - { -- WRAP_VA_PARAM(s, cmd, lwip_fcntl, posix_api->fcntl_fn); -+ POSIX_VA_PARAM(s, cmd, int, lwip_fcntl, posix_api->fcntl_fn); - } - int32_t ioctl(int32_t s, int32_t cmd, ...) - { -- WRAP_VA_PARAM(s, cmd, lwip_ioctl, posix_api->ioctl_fn); -+ POSIX_VA_PARAM(s, cmd, void*, lwip_ioctl, posix_api->ioctl_fn); - } - int32_t accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) - { -@@ -853,15 +848,15 @@ int32_t __wrap_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxe - } - int32_t __wrap_fcntl64(int32_t s, int32_t cmd, ...) - { -- WRAP_VA_PARAM(s, cmd, lwip_fcntl, posix_api->fcntl64_fn); -+ POSIX_VA_PARAM(s, cmd, int, lwip_fcntl, posix_api->fcntl64_fn); - } - int32_t __wrap_fcntl(int32_t s, int32_t cmd, ...) - { -- WRAP_VA_PARAM(s, cmd, lwip_fcntl, posix_api->fcntl_fn); -+ POSIX_VA_PARAM(s, cmd, int, lwip_fcntl, posix_api->fcntl_fn); - } - int32_t __wrap_ioctl(int32_t s, int32_t cmd, ...) - { -- WRAP_VA_PARAM(s, cmd, lwip_ioctl, posix_api->ioctl_fn); -+ POSIX_VA_PARAM(s, cmd, void*, lwip_ioctl, posix_api->ioctl_fn); - } - - int32_t __wrap_accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index a1f6c2f..cd81edb 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -25,7 +25,6 @@ - - #include - #include --#include - #include - - #include "common/gazelle_reg_msg.h" -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index f1e3064..11f5129 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -18,11 +18,14 @@ - #include - #include - --#include - #include - #include -+#include -+ -+#include - #include - #include -+#include - - #include "lstack_cfg.h" - #include "lstack_dpdk.h" -@@ -353,7 +356,7 @@ static int32_t client_reg_proc_attach(__attribute__((__unused__)) bool is_reconn - return 0; - } - --static int32_t reg_conn(enum tcp_list_state table_state, enum reg_ring_type reg_type, -+static int32_t reg_conn(enum GAZELLE_TCP_LIST_STATE table_state, enum reg_ring_type reg_type, - const struct gazelle_stat_lstack_conn *conn) - { - struct gazelle_quintuple qtuple; -@@ -370,7 +373,7 @@ static int32_t reg_conn(enum tcp_list_state table_state, enum reg_ring_type reg_ - qtuple.dst_ip = conn->conn_list[i].rip; - qtuple.dst_port = lwip_htons(conn->conn_list[i].r_port); - -- if ((table_state == LISTEN_LIST) && (!match_host_addr((ip_addr_t *)&qtuple.src_ip))) { -+ if ((table_state == GAZELLE_LISTEN_LIST) && (!match_host_addr((ip_addr_t *)&qtuple.src_ip))) { - continue; - } - -@@ -398,16 +401,16 @@ void thread_register_phase1(struct rpc_msg *msg) - } - - struct gazelle_stat_lstack_conn *conn = (struct gazelle_stat_lstack_conn *)msg->args[MSG_ARG_0].p; -- ret = reg_conn(ACTIVE_LIST, REG_RING_TCP_CONNECT, conn); -+ ret = reg_conn(GAZELLE_ACTIVE_LIST, REG_RING_TCP_CONNECT, conn); - if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "ACTIVE_LIST rereg conn fail ret=%d\n", ret); -+ LSTACK_LOG(ERR, LSTACK, "GAZELLE_ACTIVE_LIST rereg conn fail ret=%d\n", ret); - msg->result = ret; - return; - } - -- ret = reg_conn(TIME_WAIT_LIST, REG_RING_TCP_CONNECT, conn); -+ ret = reg_conn(GAZELLE_TIME_WAIT_LIST, REG_RING_TCP_CONNECT, conn); - if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "TIME_WAIT_LIST rereg conn fail ret=%d\n", ret); -+ LSTACK_LOG(ERR, LSTACK, "GAZELLE_TIME_WAIT_LIST rereg conn fail ret=%d\n", ret); - } - msg->result = ret; - } -@@ -416,9 +419,9 @@ void thread_register_phase2(struct rpc_msg *msg) - { - struct gazelle_stat_lstack_conn *conn = (struct gazelle_stat_lstack_conn *)msg->args[MSG_ARG_0].p; - -- int32_t ret = reg_conn(LISTEN_LIST, REG_RING_TCP_LISTEN, conn); -+ int32_t ret = reg_conn(GAZELLE_LISTEN_LIST, REG_RING_TCP_LISTEN, conn); - if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "LISTEN_LIST rereg conn fail ret=%d\n", ret); -+ LSTACK_LOG(ERR, LSTACK, "GAZELLE_LISTEN_LIST rereg conn fail ret=%d\n", ret); - } - - msg->result = ret; -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index a095cbd..e17242c 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -32,16 +32,14 @@ - #endif - #include - #include --#include --#include --#include --#include --#include -- - #include - #include - #include - -+#include -+#include -+#include -+ - #include "lstack_log.h" - #include "common/dpdk_common.h" - #include "lstack_protocol_stack.h" -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 54ee97e..e89e19c 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -29,8 +29,6 @@ - #include - #include - #include --#include --#include - #include - #include - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index c05a763..271e94f 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -12,20 +12,21 @@ - - #include - #include -+#include -+ -+#include -+#include -+ - #include - #include - #include - #include --#include - #include - #include - #include - #include - #include - #include --#include --#include --#include - - #include "common/gazelle_base_func.h" - #include "lstack_ethdev.h" -@@ -355,7 +356,7 @@ static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t l - (void)gazelle_ring_read(sock->send_ring, (void **)pbufs, write_num); - - if (get_protocol_stack_group()->latency_start) { -- uint64_t time_stamp = get_current_time(); -+ uint64_t time_stamp = sys_now_us(); - time_stamp_into_pbuf(write_num, pbufs, time_stamp); - } - -@@ -912,7 +913,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 -- uint64_t time_stamp = get_current_time(); -+ uint64_t time_stamp = sys_now_us(); - - if (sock->recv_lastdata != NULL) { - *pbuf = sock->recv_lastdata; -@@ -1250,20 +1251,20 @@ uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, - } - - for (pcb = tcp_active_pcbs; pcb != NULL && conn_num < max_num; pcb = pcb->next) { -- conn[conn_num].state = ACTIVE_LIST; -+ conn[conn_num].state = GAZELLE_ACTIVE_LIST; - copy_pcb_to_conn(conn + conn_num, pcb); - conn_num++; - } - - for (pcb = tcp_tw_pcbs; pcb != NULL && conn_num < max_num; pcb = pcb->next) { -- conn[conn_num].state = TIME_WAIT_LIST; -+ conn[conn_num].state = GAZELLE_TIME_WAIT_LIST; - copy_pcb_to_conn(conn + conn_num, pcb); - conn_num++; - } - - for (struct tcp_pcb_listen *pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL && conn_num < max_num; - pcbl = pcbl->next) { -- conn[conn_num].state = LISTEN_LIST; -+ conn[conn_num].state = GAZELLE_LISTEN_LIST; - conn[conn_num].lip = *((gz_addr_t *)&pcbl->local_ip); - conn[conn_num].l_port = pcbl->local_port; - conn[conn_num].tcp_sub_state = pcbl->state; -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 9bb1b6a..6f2e84e 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -12,15 +12,14 @@ - - #include - #include -+#include -+#include - - #include --#include -+#include - #include --#include - #include - #include --#include --#include - - #include "common/gazelle_base_func.h" - #include "lstack_thread_rpc.h" -@@ -332,9 +331,6 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) - list_init_head(&stack->same_node_recv_list); - list_init_head(&stack->wakeup_list); - -- sys_calibrate_tsc(); -- stack_stat_init(); -- - stack_group->stacks[t_params->idx] = stack; - set_stack_idx(t_params->idx); - -@@ -424,7 +420,7 @@ static struct protocol_stack *stack_thread_init(void *arg) - } - RTE_PER_LCORE(_lcore_id) = stack->cpu_id; - -- tcpip_init(NULL, NULL); -+ lwip_init(); - - if (use_ltran()) { - if (client_reg_thrd_ring() != 0) { -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 0411d9e..91ca49a 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -31,25 +31,6 @@ - #include "lstack_stack_stat.h" - #include "lstack_virtio.h" - --#define US_PER_SEC 1000000 -- --static uint64_t g_cycles_per_us; -- --void stack_stat_init(void) --{ -- uint64_t freq = rte_get_tsc_hz(); -- g_cycles_per_us = (freq + US_PER_SEC - 1) / US_PER_SEC; --} -- --uint64_t get_current_time(void) --{ -- if (g_cycles_per_us == 0) { -- return 0; -- } -- -- return (rte_rdtsc() / g_cycles_per_us); --} -- - void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new) - { - if (!get_protocol_stack_group()->latency_start) { -@@ -71,12 +52,12 @@ void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new) - - void time_stamp_into_rpcmsg(struct lwip_sock *sock) - { -- sock->stamp.rpc_time_stamp = get_current_time(); -+ sock->stamp.rpc_time_stamp = sys_now_us(); - } - - void time_stamp_into_recvmbox(struct lwip_sock *sock) - { -- sock->stamp.mbox_time_stamp = get_current_time(); -+ sock->stamp.mbox_time_stamp = sys_now_us(); - } - - void time_stamp_record(int fd, struct pbuf *pbuf) -@@ -108,7 +89,7 @@ void calculate_sock_latency(struct gazelle_stack_latency *stack_latency, struct - return; - } - -- latency = get_current_time() - stamp; -+ latency = sys_now_us() - stamp; - latency_stat = &stack_latency->latency[type]; - - latency_stat->latency_total += latency; -@@ -147,7 +128,7 @@ void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const - } - - if (time_record == 0) { -- lt->stamp_seg[type] = get_current_time() - lt->stamp; -+ lt->stamp_seg[type] = sys_now_us() - lt->stamp; - } else { - lt->stamp_seg[type] = time_record > (lt->stamp_seg[type - 1] + lt->stamp) ? - (time_record - lt->stamp) : lt->stamp_seg[type - 1]; -@@ -212,7 +193,7 @@ static void set_latency_start_flag(bool start) - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "memset_s faile\n"); - } -- stack->latency.start_time = get_current_time(); -+ stack->latency.start_time = sys_now_us(); - - for (uint32_t j = 0; j < GAZELLE_LATENCY_MAX; j++) { - stack->latency.latency[j].latency_min = ~((uint64_t)0); -diff --git a/src/lstack/include/lstack_stack_stat.h b/src/lstack/include/lstack_stack_stat.h -index 9fca04a..ef33365 100644 ---- a/src/lstack/include/lstack_stack_stat.h -+++ b/src/lstack/include/lstack_stack_stat.h -@@ -31,7 +31,6 @@ void calculate_sock_latency(struct gazelle_stack_latency *stack_latency, struct - void stack_stat_init(void); - int handle_stack_cmd(int fd, struct gazelle_stat_msg_request *msg); - int handle_dpdk_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode); --uint64_t get_current_time(void); - void lstack_get_low_power_info(struct gazelle_stat_low_power_info *low_power_info); - void unregister_wakeup(struct protocol_stack *stack, struct wakeup_poll *wakeup); - void lstack_calculate_aggregate(int type, uint32_t len); -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index fa98b0c..d268366 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -14,7 +14,6 @@ - #define __GAZELLE_THREAD_RPC_H__ - - #include --#include - #include - - #include "lstack_lockless_queue.h" -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index d4d0878..cf66e15 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -21,6 +21,7 @@ - #include - #include - #include -+#include - - #include - -@@ -181,7 +182,7 @@ int32_t eth_dev_poll(void) - } - - if (!use_ltran() && get_protocol_stack_group()->latency_start) { -- uint64_t time_stamp = get_current_time(); -+ uint64_t time_stamp = sys_now_us(); - time_stamp_into_mbuf(nr_pkts, stack->pkts, time_stamp); - } - -diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c -index c2f53d6..0de9c1c 100644 ---- a/src/ltran/ltran_forward.c -+++ b/src/ltran/ltran_forward.c -@@ -24,7 +24,6 @@ - #include - #include - #include --#include - #include - #include - -@@ -70,7 +69,7 @@ static void calculate_ltran_latency(struct gazelle_stack *stack, const struct rt - return; - } - -- latency = get_current_time() - lt->stamp; -+ latency = gazelle_now_us() - lt->stamp; - - stack->stack_stats.latency_total += latency; - stack->stack_stats.latency_pkts++; -@@ -595,7 +594,7 @@ static __rte_always_inline void upstream_forward_loop(uint32_t port_id, uint32_t - struct rte_mbuf *buf[GAZELLE_PACKET_READ_SIZE] __rte_cache_aligned; - for (loop_cnt = 0; loop_cnt < UPSTREAM_LOOP_TIMES; loop_cnt++) { - if (get_start_latency_flag() == GAZELLE_ON) { -- time_stamp = get_current_time(); -+ time_stamp = gazelle_now_us(); - } - - rx_count = rte_eth_rx_burst(port_id, queue_id, buf, GAZELLE_PACKET_READ_SIZE); -@@ -657,9 +656,8 @@ void upstream_forward(const uint16_t *port) - uint32_t queue_num = get_ltran_config()->bond.rx_queue_num; - uint32_t port_id = get_bond_port()[g_port_index]; - unsigned long now_time; -- unsigned long last_time = get_current_time(); -+ unsigned long last_time = gazelle_now_us(); - unsigned long aging_conn_last_time = last_time; -- calibrate_time(); - - while (get_ltran_stop_flag() != GAZELLE_TRUE) { - for (queue_id = 0; queue_id < queue_num; queue_id++) { -@@ -673,7 +671,7 @@ void upstream_forward(const uint16_t *port) - } - #endif - -- now_time = get_current_time(); -+ now_time = gazelle_now_us(); - if (now_time - aging_conn_last_time > GAZELLE_CONN_INTERVAL) { - gazelle_delete_aging_conn(gazelle_get_tcp_conn_htable()); - aging_conn_last_time = now_time; -diff --git a/src/ltran/ltran_stat.c b/src/ltran/ltran_stat.c -index 0a8d75c..72de448 100644 ---- a/src/ltran/ltran_stat.c -+++ b/src/ltran/ltran_stat.c -@@ -75,7 +75,7 @@ void set_start_latency_flag(int32_t flag) - } - - g_start_latency = flag; -- g_start_time_stamp = get_current_time(); -+ g_start_time_stamp = gazelle_now_us(); - } - - int32_t get_start_latency_flag(void) -diff --git a/src/ltran/ltran_stat.h b/src/ltran/ltran_stat.h -index 75cb353..7945d67 100644 ---- a/src/ltran/ltran_stat.h -+++ b/src/ltran/ltran_stat.h -@@ -36,12 +36,6 @@ enum GAZELLE_CLIENT_STATE { - GAZELLE_CLIENT_STATE_MAX - }; - --enum GAZELLE_TCP_LIST_STATE { -- GAZELLE_ACTIVE_LIST, -- GAZELLE_LISTEN_LIST, -- GAZELLE_TIME_WAIT_LIST, --}; -- - enum GAZELLE_TCP_STATE { - GAZELLE_TCP_STATE_CLS, - GAZELLE_TCP_STATE_LSN, -diff --git a/src/ltran/ltran_timer.c b/src/ltran/ltran_timer.c -index 51d6544..f1c0e6e 100644 ---- a/src/ltran/ltran_timer.c -+++ b/src/ltran/ltran_timer.c -@@ -26,22 +26,16 @@ - #include "ltran_instance.h" - #include "ltran_timer.h" - --static uint64_t g_cycles_per_us = 0; -- --uint64_t get_current_time(void) -+uint64_t gazelle_now_us(void) - { -- if (g_cycles_per_us == 0) { -- return 0; -+ static uint64_t g_cycles_per_us = 0; -+ if (unlikely(g_cycles_per_us == 0)) { -+ g_cycles_per_us = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S; - } - - return (rte_rdtsc() / g_cycles_per_us); - } - --void calibrate_time(void) --{ -- g_cycles_per_us = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S; --} -- - void gazelle_detect_sock_logout(struct gazelle_tcp_sock_htable *tcp_sock_htable) - { - uint32_t i; -diff --git a/src/ltran/ltran_timer.h b/src/ltran/ltran_timer.h -index abc08b9..6c7aeef 100644 ---- a/src/ltran/ltran_timer.h -+++ b/src/ltran/ltran_timer.h -@@ -13,11 +13,11 @@ - #ifndef __GAZELLE_TIMER_H__ - #define __GAZELLE_TIMER_H__ - -+uint64_t gazelle_now_us(void); -+ - struct gazelle_tcp_conn_htable; - struct gazelle_tcp_sock_htable; - --unsigned long get_current_time(void); --void calibrate_time(void); - void gazelle_detect_conn_logout(struct gazelle_tcp_conn_htable *conn_htable); - void gazelle_detect_sock_logout(struct gazelle_tcp_sock_htable *tcp_sock_htable); - void gazelle_delete_aging_conn(struct gazelle_tcp_conn_htable *conn_htable); -diff --git a/test/unitest/stub.c b/test/unitest/stub.c -index 8f37c90..8478b50 100644 ---- a/test/unitest/stub.c -+++ b/test/unitest/stub.c -@@ -10,14 +10,8 @@ - * See the Mulan PSL v2 for more details. - */ - --#include - #include - --uint64_t get_current_time(void) --{ -- return 0; --} -- - int rte_pdump_init(void) - { - return 0; --- -2.33.0 - diff --git a/0225-POSIX-fix-select-timeout-disable-and-build-failed-in.patch b/0225-POSIX-fix-select-timeout-disable-and-build-failed-in.patch deleted file mode 100644 index dc2d007615d0c592768ecb5dfeb464c22b6c8078..0000000000000000000000000000000000000000 --- a/0225-POSIX-fix-select-timeout-disable-and-build-failed-in.patch +++ /dev/null @@ -1,41 +0,0 @@ -From a1d1d5a6d24748883cfe6bb7018681bc3af00f87 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Mon, 22 Jul 2024 15:13:22 +0800 -Subject: [PATCH] POSIX: fix select timeout disable and build failed in - openEuler 2003 - ---- - src/lstack/api/lstack_wrap.c | 3 ++- - src/lstack/core/lstack_preload.c | 1 + - 2 files changed, 3 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 976a3f3..397870e 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -636,8 +636,9 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct - - static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) - { -+ /* while input args are invalid, param timeout will steal be executed in kernel */ - if (nfds <= 0 || !(readfds || writefds || exceptfds)) { -- GAZELLE_RETURN(EINVAL); -+ return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); - } - - if (select_posix_path() == POSIX_KERNEL) { -diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c -index 689d2bf..0a1df7d 100644 ---- a/src/lstack/core/lstack_preload.c -+++ b/src/lstack/core/lstack_preload.c -@@ -14,6 +14,7 @@ - #include - #include - #include -+#include - - #include - #include --- -2.33.0 - diff --git a/0226-support-kernel-connect.patch b/0226-support-kernel-connect.patch deleted file mode 100644 index 3568380e911e058382eaba8457a7b5db9c59e4f0..0000000000000000000000000000000000000000 --- a/0226-support-kernel-connect.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 34a090b2cfb88cb2e711d02c0f3eddf3a3656fac Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Fri, 19 Jul 2024 07:34:47 +0000 -Subject: [PATCH] support kernel connect - ---- - src/lstack/api/lstack_epoll.c | 2 +- - src/lstack/api/lstack_wrap.c | 10 +++++++++- - 2 files changed, 10 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 417499b..6426de4 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -439,7 +439,7 @@ int32_t lstack_rtw_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_ - - struct wakeup_poll *wakeup = epoll_sock->wakeup; - struct lwip_sock *sock = lwip_get_socket(fd); -- if (POSIX_IS_CLOSED(sock)) { -+ if (POSIX_IS_CLOSED(sock) || POSIX_IS_TYPE(sock, POSIX_KERNEL)) { - return posix_api->epoll_ctl_fn(epfd, op, fd, event); - } - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index b19990e..a6ea485 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -317,8 +317,16 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - ret = posix_api->connect_fn(s, name, namelen); - 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); -- POSIX_SET_TYPE(sock, POSIX_LWIP); -+ if (ret == 0) { -+ POSIX_SET_TYPE(sock, POSIX_LWIP); -+ } else { -+ ret = posix_api->connect_fn(s, name, namelen); -+ if (ret == 0) { -+ POSIX_SET_TYPE(sock, POSIX_KERNEL); -+ } -+ } - } - - return ret; --- -2.33.0 - diff --git a/0227-Check-the-return-of-lwip_init.patch b/0227-Check-the-return-of-lwip_init.patch deleted file mode 100644 index 5056f8aee4e0a06796f94b85412248dc749a9167..0000000000000000000000000000000000000000 --- a/0227-Check-the-return-of-lwip_init.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 7cb4456d14405d1d9dbeb890642a339ef13165da Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 22 Jul 2024 15:09:33 +0800 -Subject: [PATCH] Check the return of lwip_init - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_protocol_stack.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 6f2e84e..2867711 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -421,6 +421,11 @@ static struct protocol_stack *stack_thread_init(void *arg) - RTE_PER_LCORE(_lcore_id) = stack->cpu_id; - - lwip_init(); -+ /* Using errno to return lwip_init() result. */ -+ if (errno != 0) { -+ LSTACK_LOG(ERR, LSTACK, "lwip_init failed, errno %d\n", errno); -+ goto END; -+ } - - if (use_ltran()) { - if (client_reg_thrd_ring() != 0) { --- -2.33.0 - diff --git a/0228-vitio_user-modify-mbuf-index-for-bond4.patch b/0228-vitio_user-modify-mbuf-index-for-bond4.patch deleted file mode 100644 index a9833c49a42c5fda69fdabc225ed8ddadb030f2c..0000000000000000000000000000000000000000 --- a/0228-vitio_user-modify-mbuf-index-for-bond4.patch +++ /dev/null @@ -1,60 +0,0 @@ -From 0f841d29ed2f17f54bc4c13ef01f364ef4c633ac Mon Sep 17 00:00:00 2001 -From: hkk -Date: Sat, 20 Jul 2024 16:52:52 +0800 -Subject: [PATCH] vitio_user: modify mbuf index for bond4 - ---- - src/lstack/core/lstack_virtio.c | 6 ++++-- - src/ltran/ltran_dfx.c | 4 ++-- - 2 files changed, 6 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index 36159c9..f907a99 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -205,6 +205,7 @@ static int virtio_port_init(uint16_t port) - int retval; - uint16_t rx_queue_num = g_virtio_instance.rx_queue_num; - uint16_t tx_queue_num = g_virtio_instance.tx_queue_num; -+ int mbuf_total_num = get_global_cfg_params()->num_cpu * get_global_cfg_params()->num_process; - - LSTACK_LOG(INFO, LSTACK, "virtio_port_init port= %u rx_queue_num=%u tx_queue_num=%u \n", - port, rx_queue_num, tx_queue_num); -@@ -226,7 +227,8 @@ static int virtio_port_init(uint16_t port) - } - - for (uint16_t q = 0; q < tx_queue_num; q++) { -- retval = rte_eth_tx_queue_setup(port, q, VIRTIO_TX_RX_RING_SIZE, rte_eth_dev_socket_id(port), NULL); -+ retval = rte_eth_tx_queue_setup(port, q % mbuf_total_num, VIRTIO_TX_RX_RING_SIZE, -+ rte_eth_dev_socket_id(port), NULL); - if (retval < 0) { - LSTACK_LOG(ERR, LSTACK, "rte_eth_tx_queue_setup failed (queue %u) retval=%d \n", q, retval); - return retval; -@@ -341,4 +343,4 @@ bool virtio_distribute_pkg_to_kernel(uint16_t dst_port) - } - - return (port_map_get(dst_port) == 0); --} -\ No newline at end of file -+} -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 005b09c..1bf5451 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -1177,11 +1177,11 @@ static void gazelle_print_lstack_stat_virtio(void *buf, const struct gazelle_sta - struct gazelle_stat_lstack_virtio *virtio = &stat->data.virtio; - printf("\nStatistics of lstack virtio:\n"); - -- printf("\nlstack_port_id =%u virtio_port_id =%u rx_queue_num =%u tx_queue_num =%u \n", -+ printf("\nlstack_port_id: %u virtio_port_id: %u rx_queue_num: %u tx_queue_num: %u \n", - virtio->lstack_port_id, virtio->virtio_port_id, virtio->rx_queue_num, - virtio->tx_queue_num); - -- printf("\n%-8s %-8s %-8s %-8s %-8s\n", "queue_id", "rx_pkg", "rx_drop", "tx_pkg", "tx_drop"); -+ printf("\n%-8s %-8s %-8s %-8s %-8s\n", "queue_id", "rx_pkg", "rx_drop", "tx_pkg", "tx_drop"); - for (int i = 0; i < virtio->rx_queue_num; i++) { - printf("%-8d %-8lu %-8lu %-8lu %-8lu\n", i, - virtio->rx_pkg[i], virtio->rx_drop[i], virtio->tx_pkg[i], virtio->tx_drop[i]); --- -2.33.0 - diff --git a/0229-fix-redis-coredump-when-hugetlbs-pagesize-is-1024M.patch b/0229-fix-redis-coredump-when-hugetlbs-pagesize-is-1024M.patch deleted file mode 100644 index 3a201290b9f65b7e50f05d1e97fb8dce094e23ec..0000000000000000000000000000000000000000 --- a/0229-fix-redis-coredump-when-hugetlbs-pagesize-is-1024M.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 5dff08d02b2561ca39d7e569b9870f7a315080f0 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Tue, 16 Jul 2024 22:24:04 +0800 -Subject: [PATCH] fix redis coredump when hugetlbs pagesize is 1024M - ---- - src/lstack/core/lstack_init.c | 16 +++++++++------- - 1 file changed, 9 insertions(+), 7 deletions(-) - -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index a5a4a4e..629c790 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -113,8 +113,16 @@ void gazelle_exit(void) - /* 1: wait until app thread call send functio complete */ - sleep(1); - stack_group_exit(); -+} - -+void dpdk_exit(void) -+{ - if (!use_ltran()) { -+ int ret = rte_pdump_uninit(); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_pdump_uninit failed\n"); -+ } -+ - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - dpdk_kni_release(); - #endif -@@ -126,13 +134,7 @@ __attribute__((destructor)) void gazelle_network_exit(void) - if (posix_api != NULL && !posix_api->use_kernel) { - lwip_exit(); - gazelle_exit(); -- } -- -- if (!use_ltran()) { -- int32_t ret = rte_pdump_uninit(); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "rte_pdump_uninit failed\n"); -- } -+ dpdk_exit(); - } - } - --- -2.33.0 - diff --git a/0230-dfx-optimize-gazellectl-x-for-bond.patch b/0230-dfx-optimize-gazellectl-x-for-bond.patch deleted file mode 100644 index f2891a7dcaceb09c2f048793b06462a403ee1b42..0000000000000000000000000000000000000000 --- a/0230-dfx-optimize-gazellectl-x-for-bond.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 99b72b69ea7ce93077d890829e3db812fa34e2cb Mon Sep 17 00:00:00 2001 -From: zhangmengxuan -Date: Wed, 10 Jul 2024 17:23:21 +0800 -Subject: [PATCH] dfx: optimize gazellectl -x for bond - ---- - src/ltran/ltran_dfx.c | 7 ++----- - 1 file changed, 2 insertions(+), 5 deletions(-) - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 005b09c..5bda330 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -204,22 +204,19 @@ static void gazelle_print_lstack_xstats(void *buf, const struct gazelle_stat_msg - struct nic_eth_xstats *xstats = &stat->data.nic_xstats; - static const char *nic_stats_border = "########################"; - -+ printf("###### NIC extended statistics for port %-2d #########\n", xstats->port_id); - if (xstats->bonding.mode >= 0) { - printf("############# NIC bonding mode display #############\n"); - printf("%s############################\n", nic_stats_border); -- printf("Bonding mode: [%d]\n", xstats->bonding.mode); -+ printf("Bonding mode: [%d]\n", xstats->bonding.mode); - printf("Bonding miimon: [%d]\n", xstats->bonding.miimon); -- printf("Port range: 0->%d; Bonding port is %d\n", xstats->port_id, xstats->port_id); - printf("Slaves(%d): [", xstats->bonding.slave_count); - for (int i = 0; i < xstats->bonding.slave_count - 1; i++) { - printf("%d ", xstats->bonding.slaves[i]); - } - printf("%d]\n", xstats->bonding.slaves[xstats->bonding.slave_count - 1]); - printf("Primary: [%d]\n", xstats->bonding.primary_port_id); -- printf("%s############################\n", nic_stats_border); - } -- -- printf("###### NIC extended statistics for port %-2d #########\n", xstats->port_id); - printf("%s############################\n", nic_stats_border); - if (xstats->len <= 0 || xstats->len > RTE_ETH_XSTATS_MAX_LEN) { - printf("xstats item(%d) num error!\n", xstats->len); --- -2.33.0 - diff --git a/0231-virtio-fix-dfx-error-with-multiple-cpus.patch b/0231-virtio-fix-dfx-error-with-multiple-cpus.patch deleted file mode 100644 index 3ab08783a01ca20624230ba097825f14a9256560..0000000000000000000000000000000000000000 --- a/0231-virtio-fix-dfx-error-with-multiple-cpus.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 61b535e5956122e8e07426218b718a05f9ff81b3 Mon Sep 17 00:00:00 2001 -From: hkk -Date: Thu, 25 Jul 2024 20:20:50 +0800 -Subject: [PATCH] virtio: fix dfx error with multiple cpus - ---- - src/lstack/core/lstack_stack_stat.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 91ca49a..406e27c 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -413,6 +413,10 @@ int handle_stack_cmd(int fd, struct gazelle_stat_msg_request *msg) - (stat_mode == GAZELLE_STAT_LTRAN_START_LATENCY || stat_mode == GAZELLE_STAT_LTRAN_STOP_LATENCY)) { - continue; - } -+ -+ if (i > 0 && stat_mode == GAZELLE_STAT_LSTACK_SHOW_VIRTIO) { -+ break; -+ } - - dfx.tid = stack->tid; - dfx.stack_id = i; --- -2.33.0 - diff --git a/0232-fix-issue-create-virtio_user-based-on-bond4-main-net.patch b/0232-fix-issue-create-virtio_user-based-on-bond4-main-net.patch deleted file mode 100644 index 55d1b9f5635b6b0567e31de3f2c473923bfb87ea..0000000000000000000000000000000000000000 --- a/0232-fix-issue-create-virtio_user-based-on-bond4-main-net.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 81b3494fbb9a6b346560220bf4b4dc10ae8f9881 Mon Sep 17 00:00:00 2001 -From: hkk -Date: Wed, 24 Jul 2024 15:30:48 +0800 -Subject: [PATCH] fix issue: create virtio_user based on bond4 main network - card - ---- - src/lstack/core/lstack_dpdk.c | 11 +++++++++-- - 1 file changed, 9 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index e17242c..50fbdf6 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -798,6 +798,7 @@ int32_t init_dpdk_ethdev(void) - LSTACK_LOG(ERR, LSTACK, "bond device create failed, ret=%d\n", ret); - return -1; - } -+ port_id = rte_eth_bond_primary_get(get_protocol_stack_group()->port_id); - } else { - port_id = ethdev_port_id(cfg->mac_addr); - if (port_id < 0) { -@@ -818,8 +819,14 @@ int32_t init_dpdk_ethdev(void) - } - } - #endif -- if (get_global_cfg_params()->flow_bifurcation && virtio_port_create(port_id) != 0) { -- return -1; -+ if (cfg->flow_bifurcation) { -+ if (cfg->kni_switch) { -+ LSTACK_LOG(ERR, LSTACK, "flow_bifurcation and kni_switch cannot both be enabled, please check them\n"); -+ return -1; -+ } -+ if (virtio_port_create(port_id) != 0) { -+ return -1; -+ } - } - - return 0; --- -2.33.0 - diff --git a/0233-virtio_user-modify-mbuf-index-for-bond4.patch b/0233-virtio_user-modify-mbuf-index-for-bond4.patch deleted file mode 100644 index efc84b28bb1445bdac7cb07a8f384e4518451d5a..0000000000000000000000000000000000000000 --- a/0233-virtio_user-modify-mbuf-index-for-bond4.patch +++ /dev/null @@ -1,34 +0,0 @@ -From c7cb61ee76b78908b5a4a544cd04ea15e497cfe9 Mon Sep 17 00:00:00 2001 -From: hkk -Date: Tue, 30 Jul 2024 21:11:52 +0800 -Subject: [PATCH] virtio_user: modify mbuf index for bond4 - ---- - src/lstack/core/lstack_virtio.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index f907a99..70b025c 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -227,7 +227,7 @@ static int virtio_port_init(uint16_t port) - } - - for (uint16_t q = 0; q < tx_queue_num; q++) { -- retval = rte_eth_tx_queue_setup(port, q % mbuf_total_num, VIRTIO_TX_RX_RING_SIZE, -+ retval = rte_eth_tx_queue_setup(port, q, VIRTIO_TX_RX_RING_SIZE, - rte_eth_dev_socket_id(port), NULL); - if (retval < 0) { - LSTACK_LOG(ERR, LSTACK, "rte_eth_tx_queue_setup failed (queue %u) retval=%d \n", q, retval); -@@ -236,7 +236,7 @@ static int virtio_port_init(uint16_t port) - } - - for (uint16_t q = 0; q < rx_queue_num; q++) { -- struct rte_mempool *rxtx_mbuf_pool = get_protocol_stack_group()->total_rxtx_pktmbuf_pool[q]; -+ struct rte_mempool *rxtx_mbuf_pool = get_protocol_stack_group()->total_rxtx_pktmbuf_pool[q % mbuf_total_num]; - retval = rte_eth_rx_queue_setup(port, q, VIRTIO_TX_RX_RING_SIZE, rte_eth_dev_socket_id(port), - NULL, rxtx_mbuf_pool); - if (retval < 0) { --- -2.33.0 - diff --git a/0234-WRAP-fix-double-connect-lead-posix-api-disable.patch b/0234-WRAP-fix-double-connect-lead-posix-api-disable.patch deleted file mode 100644 index dbb7acecd478a44818c811d131c5c9245170caa9..0000000000000000000000000000000000000000 --- a/0234-WRAP-fix-double-connect-lead-posix-api-disable.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 4ab3c2ccc73f6a935e05b914adcdafdf416a0f2f Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Fri, 2 Aug 2024 17:09:02 +0800 -Subject: [PATCH] WRAP:fix double connect lead posix api disable - ---- - src/lstack/api/lstack_wrap.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 947b273..5e60c36 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -319,7 +319,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - } 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); -- if (ret == 0) { -+ if (ret == 0 || (ret != 0 && errno == EINPROGRESS)) { - POSIX_SET_TYPE(sock, POSIX_LWIP); - } else { - ret = posix_api->connect_fn(s, name, namelen); --- -2.33.0 - diff --git a/0235-virtio_user-add-vlan-info-for-kernerl-packets-when-v.patch b/0235-virtio_user-add-vlan-info-for-kernerl-packets-when-v.patch deleted file mode 100644 index 70dde64c487fbad89771295804c8f593b6c62042..0000000000000000000000000000000000000000 --- a/0235-virtio_user-add-vlan-info-for-kernerl-packets-when-v.patch +++ /dev/null @@ -1,51 +0,0 @@ -From a547e495321969074b72331c0ae6b65a39975f6a Mon Sep 17 00:00:00 2001 -From: hkk -Date: Mon, 5 Aug 2024 21:58:46 +0800 -Subject: [PATCH] virtio_user: add vlan info for kernerl packets when vlan - switch is on - ---- - src/lstack/core/lstack_virtio.c | 14 ++++++++++++++ - src/lstack/netif/lstack_vdev.c | 1 + - 2 files changed, 15 insertions(+) - -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index 70b025c..f95b289 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -179,6 +179,20 @@ void virtio_tap_process_rx(uint16_t port, uint32_t queue_id) - uint32_t pkg_num; - - pkg_num = rte_eth_rx_burst(g_virtio_instance.virtio_port_id, queue_id, pkts_burst, VIRTIO_TX_RX_RING_SIZE); -+ /* -+ * For VLAN, the tap device defaults to tx-vlan-ofload as enabled and will not be modified by default, -+ * so the judgment is skipped. -+ * For checksum, tap devices are turned off by default, and it is assumed that they will not be modified, -+ * so no action will be taken. -+ * For TSO, tap devices do not support it, so no action will be taken. -+ */ -+ if (get_global_cfg_params()->nic.vlan_mode != -1) { -+ for (int i = 0; i< pkg_num; i++) { -+ pkts_burst[i]->ol_flags |= RTE_MBUF_F_TX_VLAN; -+ pkts_burst[i]->vlan_tci = (u16_t)get_global_cfg_params()->nic.vlan_mode; -+ } -+ } -+ - if (pkg_num > 0) { - g_virtio_instance.rx_pkg[queue_id] += pkg_num; - uint16_t nb_rx = rte_eth_tx_burst(lstack_net_port, queue_id, pkts_burst, pkg_num); -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index a590b30..9ca77ba 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -87,6 +87,7 @@ static inline void vdev_pkts_parse(struct rte_mbuf **pkts, int pkt_num) - pkts[i]->l2_len = sizeof(struct rte_ether_hdr); - } - -+ pkts[i]->packet_type = 0; - if (type == RTE_BE16(RTE_ETHER_TYPE_IPV4)) { - struct rte_ipv4_hdr *iph = rte_pktmbuf_mtod_offset(pkts[i], struct rte_ipv4_hdr *, - pkts[i]->l2_len); --- -2.33.0 - diff --git a/0236-virtio_user-solve-the-issue-that-failed-to-bind-virt.patch b/0236-virtio_user-solve-the-issue-that-failed-to-bind-virt.patch deleted file mode 100644 index b9445e2410be5333bf021c32c736736ca3673e1d..0000000000000000000000000000000000000000 --- a/0236-virtio_user-solve-the-issue-that-failed-to-bind-virt.patch +++ /dev/null @@ -1,88 +0,0 @@ -From b193256f4e3e5967ec2fc85600ec0883edc4bcc1 Mon Sep 17 00:00:00 2001 -From: hkk -Date: Thu, 8 Aug 2024 10:54:40 +0800 -Subject: [PATCH] virtio_user: solve the issue that failed to bind - virtio_user's IPv6 address - ---- - src/lstack/api/lstack_wrap.c | 57 ++++++++++++++++++++++++++---------- - 1 file changed, 42 insertions(+), 15 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 5e60c36..afcd227 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -199,6 +199,46 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, - return posix_api->accept4_fn(s, addr, addrlen, flags); - } - -+static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t namelen) -+{ -+ struct lwip_sock *sock = NULL; -+ int times = 10; -+ int ret = 0; -+ -+ if (get_global_cfg_params()->kni_switch == 0 && get_global_cfg_params()->flow_bifurcation == 0) { -+ 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) { -+ 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) { -+ /* reuse the port allocated by kernel when port == 0 */ -+ if (((struct sockaddr_in *)name)->sin_port == 0) { -+ struct sockaddr_in kerneladdr; -+ socklen_t len = sizeof(kerneladdr); -+ if (posix_api->getsockname_fn(s, (struct sockaddr *)&kerneladdr, &len) < 0) { -+ LSTACK_LOG(ERR, LSTACK, "kernel getsockname failed, fd=%d, errno=%d\n", s, errno); -+ return -1; -+ } -+ ((struct sockaddr_in *)name)->sin_port = kerneladdr.sin_port; -+ } -+ /* not sure POSIX_LWIP or POSIX_KERNEL */ -+ } else { -+ sock = lwip_get_socket(s); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); -+ LSTACK_LOG(ERR, LSTACK, "kernel bind failed ret %d errno %d sa_family %u times %u\n", -+ ret, errno, name->sa_family, times); -+ } -+ return 0; -+} -+ - static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen) - { - if (name == NULL) { -@@ -231,21 +271,8 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - return posix_api->bind_fn(s, name, namelen); - } - -- /* maybe kni addr */ -- if (posix_api->bind_fn(s, name, namelen) == 0) { -- /* reuse the port allocated by kernel when port == 0 */ -- if (((struct sockaddr_in *)name)->sin_port == 0) { -- struct sockaddr_in kerneladdr; -- socklen_t len = sizeof(kerneladdr); -- if (posix_api->getsockname_fn(s, (struct sockaddr *)&kerneladdr, &len) < 0) { -- LSTACK_LOG(ERR, LSTACK, "kernel getsockname failed, fd=%d, errno=%d\n", s, errno); -- return -1; -- } -- ((struct sockaddr_in *)name)->sin_port = kerneladdr.sin_port; -- } -- /* not sure POSIX_LWIP or POSIX_KERNEL */ -- } else { -- POSIX_SET_TYPE(sock, POSIX_LWIP); -+ if (kernel_bind_process(s, name, namelen) < 0) { -+ return -1; - } - return g_wrap_api->bind_fn(s, name, namelen); - } --- -2.33.0 - diff --git a/0237-refector-fill-udp-sendring.patch b/0237-refector-fill-udp-sendring.patch deleted file mode 100644 index 29d6f3f796b65874fc2d77b07a7167320e1ae3c0..0000000000000000000000000000000000000000 --- a/0237-refector-fill-udp-sendring.patch +++ /dev/null @@ -1,223 +0,0 @@ -From eedeee26cb113f550339d54238ca41eb012697e3 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Wed, 31 Jul 2024 20:31:57 +0800 -Subject: [PATCH] refector fill udp sendring - ---- - src/lstack/core/lstack_lwip.c | 109 ++++++++++++++++++------ - src/lstack/core/lstack_protocol_stack.c | 11 +-- - 2 files changed, 84 insertions(+), 36 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 271e94f..19ff22d 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -457,22 +457,67 @@ int sem_timedwait_nsecs(sem_t *sem) - return sem_timedwait(sem, &ts); - } - --static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, size_t len, -- const struct sockaddr *addr, socklen_t addrlen) -+static ssize_t do_lwip_udp_fill_sendring(struct lwip_sock *sock, const void *buf, size_t len, -+ const struct sockaddr *addr, socklen_t addrlen) - { -- if (sock->errevent > 0) { -- GAZELLE_RETURN(ENOTCONN); -+ if (len > GAZELLE_UDP_PKGLEN_MAX) { -+ LSTACK_LOG(ERR, LSTACK, "Message too long\n"); -+ GAZELLE_RETURN(EMSGSIZE); -+ } -+ -+ ssize_t send_len = 0; -+ uint32_t write_num = (len + MBUF_MAX_DATA_LEN - 1) / MBUF_MAX_DATA_LEN; -+ uint32_t write_avail = gazelle_ring_readable_count(sock->send_ring); -+ struct wakeup_poll *wakeup = sock->wakeup; -+ -+ if (write_num > rte_ring_get_capacity(sock->send_ring)) { -+ LSTACK_LOG(ERR, LSTACK, "sock send_ring size is not enough\n"); -+ GAZELLE_RETURN(ENOMEM); -+ } -+ -+ /* if udp send 0 packet, set write_num to at least 1 */ -+ if (write_num == 0) { -+ write_num = 1; -+ } -+ -+ while (!netconn_is_nonblocking(sock->conn) && (write_avail < write_num)) { -+ if (sock->errevent > 0) { -+ GAZELLE_RETURN(ENOTCONN); -+ } -+ write_avail = gazelle_ring_readable_count(sock->send_ring); -+ } -+ -+ if (write_avail < write_num) { -+ sem_timedwait_nsecs(&sock->snd_ring_sem); -+ GAZELLE_RETURN(ENOMEM); -+ } -+ -+ send_len = app_buff_write(sock, (char *)buf, len, write_num, addr, addrlen); -+ -+ if (wakeup && wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLOUT) -+ && !NETCONN_IS_OUTIDLE(sock)) { -+ del_sock_event(sock, EPOLLOUT); -+ } -+ -+ if (wakeup) { -+ wakeup->stat.app_write_cnt += write_num; - } - -- struct protocol_stack *stack = sock->stack; -- if (!stack) { -+ return send_len; -+} -+ -+static ssize_t do_lwip_tcp_fill_sendring(struct lwip_sock *sock, const void *buf, size_t len, -+ const struct sockaddr *addr, socklen_t addrlen) -+{ -+ /* refer to the lwip implementation. */ -+ if (len == 0) { - return 0; - } - - ssize_t send_len = 0; - - /* merge data into last pbuf */ -- if (!NETCONN_IS_UDP(sock) && sock->remain_len) { -+ if (sock->remain_len) { - sock->stack->stats.sock_tx_merge++; - send_len = merge_data_lastpbuf(sock, (char *)buf, len); - if (send_len >= len) { -@@ -485,11 +530,6 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - uint32_t write_avail = gazelle_ring_readable_count(sock->send_ring); - struct wakeup_poll *wakeup = sock->wakeup; - -- /* if udp send 0 packet, set write_num to at least 1 */ -- if (NETCONN_IS_UDP(sock) && write_num == 0) { -- write_num = 1; -- } -- - while (!netconn_is_nonblocking(sock->conn) && (write_avail < write_num)) { - if (sock->errevent > 0) { - GAZELLE_RETURN(ENOTCONN); -@@ -500,9 +540,6 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - /* send_ring is full, data attach last pbuf */ - if (write_avail == 0) { - sem_timedwait_nsecs(&sock->snd_ring_sem); -- if (likely(sock->send_ring != NULL)) { -- write_avail = gazelle_ring_readable_count(sock->send_ring); -- } - goto END; - } - -@@ -523,10 +560,11 @@ static ssize_t do_lwip_fill_sendring(struct lwip_sock *sock, const void *buf, si - } - - END: -- if (send_len == 0 && !NETCONN_IS_UDP(sock)) { -+ if (send_len == 0) { - errno = EAGAIN; - return -1; - } -+ - return send_len; - } - -@@ -817,28 +855,39 @@ static inline void thread_bind_stack(struct lwip_sock *sock) - ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t flags, - const struct sockaddr *addr, socklen_t addrlen) - { -+ ssize_t send = 0; -+ - if (buf == NULL) { - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (len == 0 && !NETCONN_IS_UDP(sock)) { -- return 0; -- } -- -- if (NETCONN_IS_UDP(sock) && (len > GAZELLE_UDP_PKGLEN_MAX)) { -- LSTACK_LOG(ERR, LSTACK, "Message too long\n"); -- GAZELLE_RETURN(EMSGSIZE); -+ if (addr && addr->sa_family != AF_INET && addr->sa_family != AF_INET6) { -+ GAZELLE_RETURN(EINVAL); - } -+ -+ struct lwip_sock *sock = lwip_get_socket(fd); - - thread_bind_stack(sock); - - if (sock->same_node_tx_ring != NULL) { - return gazelle_same_node_ring_send(sock, buf, len, flags); - } -- ssize_t send = do_lwip_fill_sendring(sock, buf, len, addr, addrlen); -- if (send < 0 || (send == 0 && !NETCONN_IS_UDP(sock))) { -- return send; -+ if (sock->errevent > 0 || sock->stack == NULL) { -+ GAZELLE_RETURN(ENOTCONN); -+ } -+ -+ if (NETCONN_IS_UDP(sock)) { -+ send = do_lwip_udp_fill_sendring(sock, buf, len, addr, addrlen); -+ /* send = 0: udp send a empty package */ -+ if (send < 0) { -+ return send; -+ } -+ } else { -+ send = do_lwip_tcp_fill_sendring(sock, buf, len, addr, addrlen); -+ // send = 0 : tcp peer close connection ? -+ if (send <= 0) { -+ return send; -+ } - } - - notice_stack_send(sock, fd, send, flags); -@@ -860,7 +909,11 @@ ssize_t do_lwip_sendmsg_to_stack(struct lwip_sock *sock, int32_t s, const struct - continue; - } - -- ret = do_lwip_fill_sendring(sock, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len, NULL, 0); -+ if (NETCONN_IS_UDP(sock)) { -+ ret = do_lwip_udp_fill_sendring(sock, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len, NULL, 0); -+ } else { -+ ret = do_lwip_tcp_fill_sendring(sock, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len, NULL, 0); -+ } - if (ret <= 0) { - buflen = (buflen == 0) ? ret : buflen; - break; -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 2867711..f433d0d 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -916,7 +916,6 @@ void stack_udp_send(struct rpc_msg *msg) - size_t len = msg->args[MSG_ARG_1].size; - struct protocol_stack *stack = get_protocol_stack(); - int replenish_again; -- uint32_t call_num; - - struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL) { -@@ -930,16 +929,12 @@ void stack_udp_send(struct rpc_msg *msg) - } - - replenish_again = do_lwip_send(stack, sock->conn->callback_arg.socket, sock, len, 0); -- call_num = __sync_fetch_and_sub(&sock->call_num, 1); -- if (replenish_again < 0) { -- return; -- } -- -- if ((call_num == 1) && (replenish_again > 0)) { -+ if ((replenish_again > 0) && (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1)) { - rpc_call_replenish(&stack->rpc_queue, sock); - return; - } -- -+ -+ __sync_fetch_and_sub(&sock->call_num, 1); - return; - } - --- -2.33.0 - diff --git a/0238-virtio_user-The-program-establishes-a-network-connec.patch b/0238-virtio_user-The-program-establishes-a-network-connec.patch deleted file mode 100644 index ccabe82d40c9c36a0013deefe88dd5d6a7eb521c..0000000000000000000000000000000000000000 --- a/0238-virtio_user-The-program-establishes-a-network-connec.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 5d0f8bead56a19862ac1e5a9dbd30797e24be6b4 Mon Sep 17 00:00:00 2001 -From: hkk -Date: Sat, 10 Aug 2024 17:11:55 +0800 -Subject: [PATCH] virtio_user: The program establishes a network connection - when network card status is up - ---- - src/lstack/core/lstack_virtio.c | 7 +++++++ - 1 file changed, 7 insertions(+) - -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index f95b289..b8114e8 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -147,6 +147,13 @@ static int virtio_netif_up(void) - } - - posix_api->close_fn(sockfd); -+ /* -+ * For virtio_user IPv6 addresses, the kernel will check if they are valid, -+ * so wait a few seconds for the address status to change from scope global tentative to scope global. -+ * 3:systerm check ipv6 addr -+ */ -+ sleep(3); -+ - return 0; - } - --- -2.33.0 - diff --git a/0239-WRAP-fix-ltran-mode-did-not-bind-kernel-while-open-k.patch b/0239-WRAP-fix-ltran-mode-did-not-bind-kernel-while-open-k.patch deleted file mode 100644 index caaa59bf1017914e1b7d6ec835fe93545df29d9e..0000000000000000000000000000000000000000 --- a/0239-WRAP-fix-ltran-mode-did-not-bind-kernel-while-open-k.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 19ba97492e3e658301e801d1866a68ac17d87f2f Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Sat, 10 Aug 2024 15:34:42 +0800 -Subject: [PATCH] WRAP:fix ltran mode did not bind kernel while open kni - ---- - src/lstack/api/lstack_wrap.c | 5 +++-- - 1 file changed, 3 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index afcd227..73281e9 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -204,8 +204,9 @@ static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t - struct lwip_sock *sock = NULL; - int times = 10; - int ret = 0; -- -- if (get_global_cfg_params()->kni_switch == 0 && get_global_cfg_params()->flow_bifurcation == 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) { - return 0; - } - ret = posix_api->bind_fn(s, name, namelen); --- -2.33.0 - diff --git a/0240-WRAP-fix-bind-log-error.patch b/0240-WRAP-fix-bind-log-error.patch deleted file mode 100644 index d47cf47005fc7f395217cd51979e59ce9df578dd..0000000000000000000000000000000000000000 --- a/0240-WRAP-fix-bind-log-error.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 7601cb5b7f384750bb08c15179c43b8e4417d9c6 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Mon, 12 Aug 2024 14:32:08 +0800 -Subject: [PATCH] WRAP: fix bind log error - ---- - src/lstack/api/lstack_wrap.c | 7 ++++--- - 1 file changed, 4 insertions(+), 3 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 73281e9..8c3c731 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -201,12 +201,13 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, - - static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t namelen) - { -- struct lwip_sock *sock = NULL; -+ 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); -@@ -232,7 +233,6 @@ static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t - } - /* not sure POSIX_LWIP or POSIX_KERNEL */ - } else { -- sock = lwip_get_socket(s); - POSIX_SET_TYPE(sock, POSIX_LWIP); - LSTACK_LOG(ERR, LSTACK, "kernel bind failed ret %d errno %d sa_family %u times %u\n", - ret, errno, name->sa_family, times); -@@ -266,7 +266,8 @@ static int32_t do_bind(int32_t s, const struct sockaddr *name, socklen_t namelen - memcpy_s(sock_addr.u_addr.ip6.addr, IPV6_ADDR_LEN, - ((struct sockaddr_in6 *)name)->sin6_addr.s6_addr, IPV6_ADDR_LEN); - } -- -+ -+ /* TODO: if addr == 127.0.0.1, try kernel and lwip */ - if (!match_host_addr(&sock_addr)) { - POSIX_SET_TYPE(sock, POSIX_KERNEL); - return posix_api->bind_fn(s, name, namelen); --- -2.33.0 - diff --git a/0241-virtio-mod-virtio_user_name-when-multi-process-is-on.patch b/0241-virtio-mod-virtio_user_name-when-multi-process-is-on.patch deleted file mode 100644 index 266f5dfe8c6c52036f183530010a6a51bbc432ca..0000000000000000000000000000000000000000 --- a/0241-virtio-mod-virtio_user_name-when-multi-process-is-on.patch +++ /dev/null @@ -1,154 +0,0 @@ -From d6fab15b942ec7452c1a485741ecec7bb876390f Mon Sep 17 00:00:00 2001 -From: hkk -Date: Tue, 13 Aug 2024 10:09:50 +0800 -Subject: [PATCH] virtio: mod virtio_user_name when multi process is on - ---- - src/lstack/core/lstack_virtio.c | 57 ++++++++++++++++++++++++++------- - 1 file changed, 45 insertions(+), 12 deletions(-) - -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index b8114e8..9862b48 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -13,6 +13,7 @@ - #include - #include - #include -+#include - #include - #include - #include "lstack_cfg.h" -@@ -21,14 +22,14 @@ - #include "lstack_virtio.h" - #include "securec.h" - --#define VIRTIO_USER_NAME "virtio_user0" -+#define VIRTIO_USER_NAME "virtio_user" - #define VIRTIO_DPDK_PARA_LEN 256 - #define VIRTIO_TX_RX_RING_SIZE 1024 - - #define VIRTIO_MASK_BITS(mask) (32 - __builtin_clz(mask)) - - static struct virtio_instance g_virtio_instance = {0}; -- -+static char g_virtio_user_name[IFNAMSIZ] = {0}; - struct virtio_instance* virtio_instance_get(void) - { - return &g_virtio_instance; -@@ -46,7 +47,7 @@ static int virtio_set_ipv6_addr(void) - return -1; - } - -- int ret = strncpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), VIRTIO_USER_NAME, sizeof(VIRTIO_USER_NAME)); -+ int ret = strncpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), g_virtio_user_name, strlen(g_virtio_user_name)); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv6_addr strncpy failed ret =%d errno=%d \n", ret, errno); - posix_api->close_fn(sockfd); -@@ -95,7 +96,7 @@ static int virtio_set_ipv4_addr(void) - struct ifreq ifr; - memset_s(&ifr, sizeof(ifr), 0, sizeof(ifr)); - -- ret = strcpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), VIRTIO_USER_NAME); -+ ret = strcpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), g_virtio_user_name); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "virtio_set_ipv4_addr strcpy_s failed ret=%d errno %d \n", ret, errno); - posix_api->close_fn(sockfd); -@@ -132,7 +133,7 @@ static int virtio_netif_up(void) - - struct ifreq ifr; - memset_s(&ifr, sizeof(ifr), 0, sizeof(ifr)); -- int ret = strcpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), VIRTIO_USER_NAME); -+ int ret = strcpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), g_virtio_user_name); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "virtio_netif_up strcpy_s failed ret=%d errno %d \n", ret, errno); - posix_api->close_fn(sockfd); -@@ -291,15 +292,47 @@ static int32_t virtio_port_start(uint16_t virtio_port) - g_virtio_instance.rx_queue_num, g_virtio_instance.tx_queue_num); - return 0; - } -+ -+static int virtio_get_netif_num(void) -+{ -+ int netif_num = 0; -+ struct ifaddrs *ifaddr, *ifa; -+ -+ if (getifaddrs(&ifaddr) == -1) { -+ LSTACK_LOG(ERR, LSTACK, "getifaddrs failed \n"); -+ return -1; -+ } -+ -+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { -+ if (strncmp(ifa->ifa_name, VIRTIO_USER_NAME, sizeof(VIRTIO_USER_NAME) - 1) == 0) { -+ netif_num++; -+ } -+ } -+ -+ freeifaddrs(ifaddr); -+ return netif_num; -+} -+ - int virtio_port_create(int lstack_net_port) - { - char portargs[VIRTIO_DPDK_PARA_LEN] = {0}; - - struct rte_ether_addr addr; - uint16_t virtio_port_id = 0xffff; // invalid val -- - struct rte_eth_dev_info dev_info; -- int ret = rte_eth_dev_info_get(lstack_net_port, &dev_info); -+ -+ int ret = virtio_get_netif_num(); -+ if (ret < 0) { -+ return -1; -+ } -+ -+ ret = sprintf_s(g_virtio_user_name, sizeof(g_virtio_user_name), VIRTIO_USER_NAME "%d", ret); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "sprintf_s failed ret=%d \n", ret); -+ return -1; -+ } -+ -+ ret = rte_eth_dev_info_get(lstack_net_port, &dev_info); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "get dev info ret=%d\n", ret); - return ret; -@@ -325,22 +358,22 @@ int virtio_port_create(int lstack_net_port) - g_virtio_instance.rx_queue_num : g_virtio_instance.tx_queue_num; - retval = snprintf(portargs, sizeof(portargs), - "path=/dev/vhost-net,queues=%u,queue_size=%u,iface=%s,mac=" RTE_ETHER_ADDR_PRT_FMT, -- actual_queue_num, VIRTIO_TX_RX_RING_SIZE, VIRTIO_USER_NAME, RTE_ETHER_ADDR_BYTES(&addr)); -+ actual_queue_num, VIRTIO_TX_RX_RING_SIZE, g_virtio_user_name, RTE_ETHER_ADDR_BYTES(&addr)); - if (retval < 0) { - LSTACK_LOG(ERR, LSTACK, "virtio portargs snprintf failed ret=%d \n", retval); - return retval; - } - LSTACK_LOG(INFO, LSTACK, "virtio portargs=%s \n", portargs); - -- retval = rte_eal_hotplug_add("vdev", VIRTIO_USER_NAME, portargs); -+ retval = rte_eal_hotplug_add("vdev", g_virtio_user_name, portargs); - if (retval < 0) { - LSTACK_LOG(ERR, LSTACK, "rte_eal_hotplug_add failed retval=%d : %s\n", retval, strerror(-retval)); - return retval; - } - -- retval = rte_eth_dev_get_port_by_name(VIRTIO_USER_NAME, &virtio_port_id); -+ retval = rte_eth_dev_get_port_by_name(g_virtio_user_name, &virtio_port_id); - if (retval != 0) { -- rte_eal_hotplug_remove("vdev", VIRTIO_USER_NAME); -+ rte_eal_hotplug_remove("vdev", g_virtio_user_name); - LSTACK_LOG(ERR, LSTACK, "virtio_user0 not found\n"); - return -1; - } -@@ -351,7 +384,7 @@ int virtio_port_create(int lstack_net_port) - retval = virtio_port_start(virtio_port_id); - if (retval != 0) { - LSTACK_LOG(ERR, LSTACK, "virtio_port_start failed ret=%d\n", retval); -- rte_eal_hotplug_remove("vdev", VIRTIO_USER_NAME); -+ rte_eal_hotplug_remove("vdev", g_virtio_user_name); - return retval; - } - return 0; --- -2.33.0 - diff --git a/0242-fix-redis-coredump-ctrl-c-during-the-pressure-test.patch b/0242-fix-redis-coredump-ctrl-c-during-the-pressure-test.patch deleted file mode 100644 index b755200aaf2636093ea588f8b126d304723271e7..0000000000000000000000000000000000000000 --- a/0242-fix-redis-coredump-ctrl-c-during-the-pressure-test.patch +++ /dev/null @@ -1,33 +0,0 @@ -From c080e30b41f47848de441e96232d255e541a7c1a Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Thu, 1 Aug 2024 15:55:50 +0800 -Subject: [PATCH] fix redis coredump: ctrl+c during the pressure test - ---- - src/lstack/core/lstack_protocol_stack.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 2867711..f0f2735 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -882,7 +882,7 @@ void stack_tcp_send(struct rpc_msg *msg) - int replenish_again; - - struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -+ if (POSIX_IS_CLOSED(sock)) { - msg->result = -1; - LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); - return; -@@ -919,6 +919,6 @@ void stack_udp_send(struct rpc_msg *msg) - - struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -+ if (POSIX_IS_CLOSED(sock)) { - msg->result = -1; - LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); - return; --- -2.33.0 - diff --git a/0243-virtio_user-check-netif-status.patch b/0243-virtio_user-check-netif-status.patch deleted file mode 100644 index 8d2273dcaae5f4a788aa964bcaeaf62631fddf8c..0000000000000000000000000000000000000000 --- a/0243-virtio_user-check-netif-status.patch +++ /dev/null @@ -1,73 +0,0 @@ -From 1b994a0e9cd2dfa59076b35e3e4c82b1a18c9e1d Mon Sep 17 00:00:00 2001 -From: hkk -Date: Mon, 19 Aug 2024 16:34:54 +0800 -Subject: [PATCH] virtio_user: check netif status - ---- - src/lstack/core/lstack_virtio.c | 35 +++++++++++++++++++++++++++++++-- - 1 file changed, 33 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index 9862b48..4a91ed7 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -26,6 +26,9 @@ - #define VIRTIO_DPDK_PARA_LEN 256 - #define VIRTIO_TX_RX_RING_SIZE 1024 - -+#define VIRTIO_NETIF_CHECK_MAX_TIMES 10 -+#define VIRTIO_NETIF_CMD_OUTPUT 4096 -+ - #define VIRTIO_MASK_BITS(mask) (32 - __builtin_clz(mask)) - - static struct virtio_instance g_virtio_instance = {0}; -@@ -123,6 +126,27 @@ static int virtio_set_ipv4_addr(void) - return 0; - } - -+static int virtio_ipv6_is_tentative(void) -+{ -+ FILE *fp; -+ char output[VIRTIO_NETIF_CMD_OUTPUT] = {0}; -+ int not_ready = 0; -+ /* ipv6 tentative state means not ready */ -+ const char *cmd = "ip a |grep tentative"; -+ -+ fp = popen(cmd, "r"); -+ if (fp == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "%s execution failed \n", cmd); -+ return -1; -+ } -+ -+ if (fgets(output, sizeof(output), fp) != NULL) { -+ not_ready = 1; -+ } -+ pclose(fp); -+ return not_ready; -+} -+ - static int virtio_netif_up(void) - { - int sockfd = posix_api->socket_fn(AF_INET, SOCK_DGRAM, 0); -@@ -151,9 +175,16 @@ static int virtio_netif_up(void) - /* - * For virtio_user IPv6 addresses, the kernel will check if they are valid, - * so wait a few seconds for the address status to change from scope global tentative to scope global. -- * 3:systerm check ipv6 addr - */ -- sleep(3); -+ for (int i = 0; i < VIRTIO_NETIF_CHECK_MAX_TIMES; i++) { -+ ret = virtio_ipv6_is_tentative(); -+ if (ret == 0) { -+ break; -+ } else if (ret < 0) { -+ return -1; -+ } -+ sleep(1); -+ } - - return 0; - } --- -2.33.0 - diff --git a/0244-virtio-solve-compilation-error-in-2003sp3.patch b/0244-virtio-solve-compilation-error-in-2003sp3.patch deleted file mode 100644 index 9112e3719a14d34bafc64062fa27db2b0058ca05..0000000000000000000000000000000000000000 --- a/0244-virtio-solve-compilation-error-in-2003sp3.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 4a30424a4ce6135cbd118bc36f00b35955255f41 Mon Sep 17 00:00:00 2001 -From: hantwofish -Date: Tue, 20 Aug 2024 17:28:37 +0800 -Subject: [PATCH] virtio: solve compilation error in 2003sp3 - ---- - src/lstack/core/lstack_virtio.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index 4a91ed7..7a8d947 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -15,6 +15,7 @@ - #include - #include - #include -+#include - #include - #include "lstack_cfg.h" - #include "lstack_log.h" --- -2.33.0 - diff --git a/0245-CMAKE-fix-ltran-build-error-in-2403.patch b/0245-CMAKE-fix-ltran-build-error-in-2403.patch deleted file mode 100644 index ffe9a369d35a244087279db16e6faebd91ce456b..0000000000000000000000000000000000000000 --- a/0245-CMAKE-fix-ltran-build-error-in-2403.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 0e6641552d16987b7e0706e1edb4992e7bd5e7d9 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Mon, 26 Aug 2024 17:21:44 +0800 -Subject: [PATCH] CMAKE: fix ltran build error in 2403 - ---- - src/ltran/CMakeLists.txt | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt -index 8e9b1ea..f94ed83 100644 ---- a/src/ltran/CMakeLists.txt -+++ b/src/ltran/CMakeLists.txt -@@ -80,12 +80,12 @@ else() - endif() - - if (DPDK_VERSION GREATER_EQUAL 23.11) -- set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -lrte_log -larchive -Wl,-lrte_eal) -+ set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -lrte_log -Wl,-lrte_eal) - else() - set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -lrte_kni -Wl,-Bstatic -Wl,-lrte_eal -Wl,-Bdynamic) -- if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "ppc64le") -- set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -Wl,-larchive) -- endif() -+endif() -+if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "ppc64le") -+ set(DPDK_LINK_FLAGS ${DPDK_LINK_FLAGS} -Wl,-larchive) - endif() - - # compile info --- -2.34.1 - diff --git a/0246-fix-mbuf_total-calculation-error.patch b/0246-fix-mbuf_total-calculation-error.patch deleted file mode 100644 index e428785524e7726122ed101d59289dff8124703a..0000000000000000000000000000000000000000 --- a/0246-fix-mbuf_total-calculation-error.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 783ea4a8f8949cb943a94cb6fdb1690852f7faa3 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Fri, 16 Aug 2024 05:55:40 +0800 -Subject: [PATCH] fix mbuf_total calculation error - ---- - src/lstack/core/lstack_protocol_stack.c | 20 +++++++++++--------- - 1 file changed, 11 insertions(+), 9 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 6e980a8..ba90d86 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -548,29 +548,31 @@ static void* gazelle_stack_thread(void *arg) - - int32_t stack_group_init_mempool(void) - { -- struct cfg_params *global_cfg_parmas = get_global_cfg_params(); -- uint32_t total_mbufs = get_global_cfg_params()->mbuf_count_per_conn * get_global_cfg_params()->tcp_conn_count; -+ 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->nic.rxqueue_size + cfg_params->nic.txqueue_size; - struct rte_mempool *rxtx_mbuf = NULL; - uint32_t cpu_id = 0; - unsigned numa_id = 0; - int queue_id = 0; - - LSTACK_LOG(INFO, LSTACK, -- "config::num_cpu=%d num_process=%d \n", global_cfg_parmas->num_cpu, global_cfg_parmas->num_process); -+ "config::num_cpu=%d num_process=%d \n", cfg_params->num_cpu, cfg_params->num_process); - -- for (int cpu_idx = 0; cpu_idx < get_global_cfg_params()->num_queue; cpu_idx++) { -- cpu_id = global_cfg_parmas->cpus[cpu_idx]; -+ 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); - -- for (int process_idx = 0; process_idx < global_cfg_parmas->num_process; process_idx++) { -- queue_id = cpu_idx * global_cfg_parmas->num_process + process_idx; -+ for (int process_idx = 0; process_idx < cfg_params->num_process; process_idx++) { -+ queue_id = cpu_idx * cfg_params->num_process + process_idx; - if (queue_id >= PROTOCOL_STACK_MAX) { - LSTACK_LOG(ERR, LSTACK, "index is over\n"); - return -1; - } - -- rxtx_mbuf = create_pktmbuf_mempool( -- "rxtx_mbuf", total_mbufs / get_global_cfg_params()->num_queue, RXTX_CACHE_SZ, queue_id, numa_id); -+ 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); --- -2.33.0 - diff --git a/0247-cfg-modify-maximum-tcp_conn_count-to-2w.patch b/0247-cfg-modify-maximum-tcp_conn_count-to-2w.patch deleted file mode 100644 index 999bb59aa72eea8ca170ae9d295a9839161b8b7a..0000000000000000000000000000000000000000 --- a/0247-cfg-modify-maximum-tcp_conn_count-to-2w.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 5c0ece87e2ce183119f29f5d6a2c53465a622ac9 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Sat, 17 Aug 2024 05:15:57 +0800 -Subject: [PATCH] cfg: modify maximum tcp_conn_count to 2w - ---- - src/lstack/core/lstack_cfg.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index cd81edb..882e60a 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -917,7 +917,7 @@ static int32_t parse_use_ltran(void) - static int32_t parse_tcp_conn_count(void) - { - int32_t ret; -- PARSE_ARG(g_config_params.tcp_conn_count, "tcp_conn_count", TCP_CONN_COUNT, 1, TCP_CONN_COUNT, ret); -+ PARSE_ARG(g_config_params.tcp_conn_count, "tcp_conn_count", TCP_CONN_COUNT, 1, GAZELLE_MAX_CLIENTS, ret); - return ret; - } - --- -2.33.0 - diff --git a/0248-tools-fix-sync-patch-script-date-wrong-and-update-th.patch b/0248-tools-fix-sync-patch-script-date-wrong-and-update-th.patch deleted file mode 100644 index eb264d4aff655e1a36e2920d4c5d2b5dd62a6194..0000000000000000000000000000000000000000 --- a/0248-tools-fix-sync-patch-script-date-wrong-and-update-th.patch +++ /dev/null @@ -1,47 +0,0 @@ -From ccab3a40054a7d95e144bca8f9e0fd0c376cbaf6 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Mon, 26 Aug 2024 21:12:17 +0800 -Subject: [PATCH] tools: fix sync patch script date wrong and update the way - get patchnum - ---- - tools/sync-gazelle-src.sh | 16 +++++++++++----- - 1 file changed, 11 insertions(+), 5 deletions(-) - -diff --git a/tools/sync-gazelle-src.sh b/tools/sync-gazelle-src.sh -index 8d44ca2..142e770 100644 ---- a/tools/sync-gazelle-src.sh -+++ b/tools/sync-gazelle-src.sh -@@ -63,10 +63,16 @@ for commitid in ${COMMIT_ID};do - git checkout -b $TARGET_BRANCH origin/$TARGET_BRANCH - git pull https://gitee.com/src-openeuler/gazelle.git $TARGET_BRANCH - fi -- patchnum=$(ls ./*.patch | wc -l) -- let patchnum+=1 -- let Patchnum=9000+$patchnum -- patchnum=$(printf "%04d\n" $patchnum) -+ -+ #get patchnum from spec file. -+ patchnum=$(grep -o "Patch[0-9]\+" *.spec | tail -n 1 | awk -Fh '{print $2}') -+ if [ -z $patchnum ];then -+ #there is no patch in spec file. get patch by conunt patches in dir. -+ patchnum=$(ls ./*.patch | wc -l) -+ let Patchnum=9000+$patchnum -+ patchnum=$(printf "%04d\n" $patchnum) -+ fi -+ let patchnum+=1 - new_patchname=$(echo $patchname | sed -e "s/^0001-/${patchnum}-/g") - - echo $new_patchname -@@ -82,7 +88,7 @@ for commitid in ${COMMIT_ID};do - - #add changelog in spec file - changelog_line=$(grep -n '^%changelog' gazelle.spec | cut -f1 -d':') -- changelog_data=$(date | awk '{print $1,$2,$3,$6}') -+ changelog_data=$(date +"%a %b %d %Y") - changelog_version=$(grep '^Version' gazelle.spec | awk '{print $2}') - - if [ -z "$done_once" ];then --- -2.33.0 - diff --git a/0249-epoll-fix-wild-pointer-detected-by-cooddy.patch b/0249-epoll-fix-wild-pointer-detected-by-cooddy.patch deleted file mode 100644 index bd3952c7824f8df5cc1882267e8b88468949a838..0000000000000000000000000000000000000000 --- a/0249-epoll-fix-wild-pointer-detected-by-cooddy.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 2adb9415c567037a44f6adf7df3b91ced624cb51 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Tue, 27 Aug 2024 16:23:03 +0800 -Subject: [PATCH] epoll: fix wild pointer detected by cooddy - ---- - src/lstack/api/lstack_epoll.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index b83da70..5b0bee4 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -782,6 +782,7 @@ static int resize_kernel_poll(struct wakeup_poll *wakeup, nfds_t nfds) - if (wakeup->events == NULL) { - LSTACK_LOG(ERR, LSTACK, "calloc failed errno=%d\n", errno); - free(wakeup->last_fds); -+ wakeup->last_fds = NULL; - return -1; - } - --- -2.33.0 - diff --git a/0250-tools-fix-script-generate-patchname-wrong.patch b/0250-tools-fix-script-generate-patchname-wrong.patch deleted file mode 100644 index 813e176cb27491d2e5afac3fb321908d2e0f3954..0000000000000000000000000000000000000000 --- a/0250-tools-fix-script-generate-patchname-wrong.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 878bd892608e312276945a57430c86909cefb459 Mon Sep 17 00:00:00 2001 -From: yinbin6 -Date: Fri, 30 Aug 2024 16:15:03 +0800 -Subject: [PATCH] tools: fix script generate patchname wrong - ---- - tools/sync-gazelle-src.sh | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/tools/sync-gazelle-src.sh b/tools/sync-gazelle-src.sh -index 142e770..ccfa8eb 100644 ---- a/tools/sync-gazelle-src.sh -+++ b/tools/sync-gazelle-src.sh -@@ -65,14 +65,14 @@ for commitid in ${COMMIT_ID};do - fi - - #get patchnum from spec file. -- patchnum=$(grep -o "Patch[0-9]\+" *.spec | tail -n 1 | awk -Fh '{print $2}') -+ patchnum=$(grep -o "Patch[0-9]\+" *.spec | tail -n 1 | awk -Fh '{print $2}' | awk '{print $1 - 9000}') - if [ -z $patchnum ];then - #there is no patch in spec file. get patch by conunt patches in dir. - patchnum=$(ls ./*.patch | wc -l) -- let Patchnum=9000+$patchnum -- patchnum=$(printf "%04d\n" $patchnum) - fi - let patchnum+=1 -+ let Patchnum=9000+$patchnum -+ patchnum=$(printf "%04d\n" $patchnum) - new_patchname=$(echo $patchname | sed -e "s/^0001-/${patchnum}-/g") - - echo $new_patchname --- -2.33.0 - diff --git a/0251-fix-when-errno-is-ENOTCONN-ignore-it.patch b/0251-fix-when-errno-is-ENOTCONN-ignore-it.patch deleted file mode 100644 index 6d8577089f07e7b0f7206136d198e1be00e8f0d8..0000000000000000000000000000000000000000 --- a/0251-fix-when-errno-is-ENOTCONN-ignore-it.patch +++ /dev/null @@ -1,81 +0,0 @@ -From 015eea5899cfea961247686d711a67917cb7a7b9 Mon Sep 17 00:00:00 2001 -From: hkk -Date: Thu, 5 Sep 2024 14:37:07 +0800 -Subject: [PATCH] fix: when errno is ENOTCONN, ignore it - ---- - src/lstack/core/lstack_protocol_stack.c | 16 ++++++++-------- - 1 file changed, 8 insertions(+), 8 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index ba90d86..49b3ec8 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -559,18 +559,18 @@ int32_t stack_group_init_mempool(void) - - LSTACK_LOG(INFO, LSTACK, - "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); -- -+ - for (int process_idx = 0; process_idx < cfg_params->num_process; process_idx++) { - queue_id = cpu_idx * cfg_params->num_process + process_idx; - if (queue_id >= PROTOCOL_STACK_MAX) { - LSTACK_LOG(ERR, LSTACK, "index is over\n"); - 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) { -@@ -578,7 +578,7 @@ int32_t stack_group_init_mempool(void) - cpu_id, numa_id, queue_id); - return -1; - } -- -+ - get_protocol_stack_group()->total_rxtx_pktmbuf_pool[queue_id] = rxtx_mbuf; - } - } -@@ -723,13 +723,13 @@ void stack_close(struct rpc_msg *msg) - int32_t fd = msg->args[MSG_ARG_0].i; - struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - struct lwip_sock *sock = lwip_get_socket(fd); -- -+ - if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { - msg->recall_flag = 1; - rpc_call(&stack->rpc_queue, msg); /* until stack_send recall finish */ - return; - } -- -+ - msg->result = lwip_close(fd); - if (msg->result != 0) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); -@@ -750,7 +750,7 @@ void stack_shutdown(struct rpc_msg *msg) - } - - msg->result = lwip_shutdown(fd, how); -- if (msg->result != 0) { -+ if (msg->result != 0 && errno != ENOTCONN) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d fail %ld\n", get_stack_tid(), fd, msg->result); - } - -@@ -935,7 +935,7 @@ void stack_udp_send(struct rpc_msg *msg) - rpc_call_replenish(&stack->rpc_queue, sock); - return; - } -- -+ - __sync_fetch_and_sub(&sock->call_num, 1); - return; - } --- -2.33.0 - diff --git a/0252-rtc-do_lwip_init_sock-no-need-to-create-ring-in-rtc-.patch b/0252-rtc-do_lwip_init_sock-no-need-to-create-ring-in-rtc-.patch deleted file mode 100644 index c8cc8bc9c32e49894363eef97a33125c7a866655..0000000000000000000000000000000000000000 --- a/0252-rtc-do_lwip_init_sock-no-need-to-create-ring-in-rtc-.patch +++ /dev/null @@ -1,52 +0,0 @@ -From 6b097278f9d70f3cc976d7a7078447975de6a4b7 Mon Sep 17 00:00:00 2001 -From: zhengjiebing -Date: Mon, 29 Jul 2024 14:07:21 +0800 -Subject: [PATCH] rtc: do_lwip_init_sock no need to create ring in rtc mode - ---- - src/lstack/api/lstack_rtc_api.c | 8 -------- - src/lstack/core/lstack_lwip.c | 9 +++++++++ - 2 files changed, 9 insertions(+), 8 deletions(-) - -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index ca0e7ec..e30718c 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -50,14 +50,6 @@ int rtc_socket(int domain, int type, int protocol) - - /* need call stack thread init function */ - ret = lwip_socket(domain, type, protocol); -- if (ret >= 0) { -- struct lwip_sock *sock = lwip_get_socket(ret); -- sock->stack = get_protocol_stack(); -- sock->epoll_events = 0; -- sock->events = 0; -- sock->wakeup = NULL; -- list_init_node(&sock->event_list); -- } - return ret; - } - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 271e94f..4ea13ad 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -154,6 +154,15 @@ int do_lwip_init_sock(int32_t fd) - return -1; - } - -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ sock->stack = stack; -+ sock->epoll_events = 0; -+ sock->events = 0; -+ sock->wakeup = NULL; -+ list_init_node(&sock->event_list); -+ return 0; -+ } -+ - reset_sock_data(sock); - - sock->recv_ring = gazelle_ring_create_fast("sock_recv", SOCK_RECV_RING_SIZE, RING_F_SP_ENQ | RING_F_SC_DEQ); --- -2.33.0 - diff --git a/0253-example-solve-double-free.patch b/0253-example-solve-double-free.patch deleted file mode 100644 index 51d8bd5f6cb7eada403951cad82c33498bcc5bab..0000000000000000000000000000000000000000 --- a/0253-example-solve-double-free.patch +++ /dev/null @@ -1,99 +0,0 @@ -From c49e92c7fc0a76fbc605c2b67fd46deba7953e1a Mon Sep 17 00:00:00 2001 -From: hkk -Date: Thu, 5 Sep 2024 09:55:36 +0800 -Subject: [PATCH] example: solve double free - ---- - examples/src/server.c | 21 +++++++++++---------- - 1 file changed, 11 insertions(+), 10 deletions(-) - -diff --git a/examples/src/server.c b/examples/src/server.c -index 7bc7d9e..b53e005 100644 ---- a/examples/src/server.c -+++ b/examples/src/server.c -@@ -69,7 +69,7 @@ void sermud_info_print(struct ServerMud *server_mud) - struct timeval end; - gettimeofday(&end, NULL); - uint64_t end_time = (uint64_t)end.tv_sec * 1000 + (uint64_t)end.tv_usec / 1000; -- -+ - double bytes_sub = end_recv_bytes > begin_recv_bytes ? (double)(end_recv_bytes - begin_recv_bytes) : 0; - double time_sub = end_time > begin_time ? (double)(end_time - begin_time) / 1000 : 0; - -@@ -93,7 +93,7 @@ int32_t sermud_worker_create_epfd_and_reg(struct ServerMudWorker *worker_unit) - } else { - worker_unit->epfd = epoll_create(SERVER_EPOLL_SIZE_MAX); - } -- -+ - if (worker_unit->epfd < 0) { - PRINT_ERROR("server can't create epoll %d! ", worker_unit->epfd); - return PROGRAM_FAULT; -@@ -118,7 +118,7 @@ int32_t sermud_listener_create_epfd_and_reg(struct ServerMud *server_mud) - } else { - server_mud->epfd = epoll_create(SERVER_EPOLL_SIZE_MAX); - } -- -+ - if (server_mud->epfd < 0) { - PRINT_ERROR("server can't create epoll %d! ", server_mud->epfd); - return PROGRAM_FAULT; -@@ -236,15 +236,16 @@ static int32_t server_handler_close(int32_t epfd, struct ServerHandler *server_h - { - int32_t fd = server_handler->fd; - struct epoll_event ep_ev; -- if (server_handler) { -- free(server_handler); -- } - - if (epoll_ctl(epfd, EPOLL_CTL_DEL, fd, &ep_ev) < 0) { - PRINT_ERROR("server can't delete socket '%d' to control epoll %d! ", fd, errno); - return PROGRAM_FAULT; - } - -+ if (server_handler) { -+ free(server_handler); -+ } -+ - if (close(fd) < 0) { - PRINT_ERROR("server can't close the socket %d! ", errno); - return PROGRAM_FAULT; -@@ -335,7 +336,7 @@ int32_t sermud_listener_proc_epevs(struct ServerMud *server_mud) - - for (int32_t i = 0; i < epoll_nfds; ++i) { - struct epoll_event *curr_epev = server_mud->epevs + i; -- -+ - if (curr_epev->events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) { - PRINT_ERROR("server epoll wait error %d! ", curr_epev->events); - server_handler_close(server_mud->epfd, (struct ServerHandler *)curr_epev->data.ptr); -@@ -540,7 +541,7 @@ void sermum_info_print(struct ServerMum *server_mum) - struct timeval end; - gettimeofday(&end, NULL); - uint64_t end_time = (uint64_t)end.tv_sec * 1000 + (uint64_t)end.tv_usec / 1000; -- -+ - double bytes_sub = end_recv_bytes > begin_recv_bytes ? (double)(end_recv_bytes - begin_recv_bytes) : 0; - double time_sub = end_time > begin_time ? (double)(end_time - begin_time) / 1000 : 0; - -@@ -564,7 +565,7 @@ int32_t sersum_create_epfd_and_reg(struct ServerMumUnit *server_unit) - } else { - server_unit->epfd = epoll_create(SERVER_EPOLL_SIZE_MAX); - } -- -+ - if (server_unit->epfd < 0) { - PRINT_ERROR("server can't create epoll %d! ", server_unit->epfd); - return PROGRAM_FAULT; -@@ -784,7 +785,7 @@ void *sersum_create_and_run(void *arg) - exit(PROGRAM_FAULT); - } - } -- -+ - close(server_unit->listener.fd); - close(server_unit->epfd); - --- -2.33.0 - diff --git a/0254-WRAP-support-setsockopt-SO_SNDTIMEO-SO_SNBUF.patch b/0254-WRAP-support-setsockopt-SO_SNDTIMEO-SO_SNBUF.patch deleted file mode 100644 index 36c72d189284f9fc631627ac1eac9f5f177405b1..0000000000000000000000000000000000000000 --- a/0254-WRAP-support-setsockopt-SO_SNDTIMEO-SO_SNBUF.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 34d3415bab0de76e2d704cda1c786c06e110e2e7 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Wed, 11 Sep 2024 16:50:17 +0800 -Subject: [PATCH] WRAP: support setsockopt SO_SNDTIMEO SO_SNBUF - ---- - src/lstack/api/lstack_wrap.c | 2 -- - 1 file changed, 2 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 8c3c731..92ce73b 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -424,8 +424,6 @@ static bool unsupport_socket_optname(int32_t optname) - { - if ((optname == SO_BROADCAST) || - (optname == SO_PROTOCOL) || -- (optname == SO_SNDTIMEO) || -- (optname == SO_SNDBUF) || - (optname == SO_RCVBUF) || - (optname == SO_DONTROUTE)) { - return true; --- -2.33.0 - diff --git a/0255-DFX-adapt-log-optimization.patch b/0255-DFX-adapt-log-optimization.patch deleted file mode 100644 index fa8028e7a82e2e252ea8f3f98f7b8c2a4a9f6bb0..0000000000000000000000000000000000000000 --- a/0255-DFX-adapt-log-optimization.patch +++ /dev/null @@ -1,71 +0,0 @@ -From 0093be5afee0264c669111a0137a580b2c314b6c Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Wed, 18 Sep 2024 15:24:17 +0800 -Subject: [PATCH] DFX: adapt log optimization - ---- - src/common/gazelle_dfx_msg.h | 8 ++++++++ - src/lstack/core/lstack_protocol_stack.c | 2 -- - src/ltran/ltran_dfx.c | 7 +++++++ - 3 files changed, 15 insertions(+), 2 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 8eb54ff..08f9df1 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -195,6 +195,14 @@ struct gazelle_stat_lstack_snmp { - uint32_t tcp_acceptmbox_full; - uint32_t tcp_listen_drops; - uint32_t tcp_in_empty_acks; -+ /* GAZELLE TCP */ -+ uint32_t tcp_rst_in_keepalive_timeout; -+ uint32_t tcp_rst_wrong_syn_in_timewait; -+ uint32_t tcp_rst_wrong_ack_in_syn_rcvd; -+ uint32_t tcp_ooseq_data_drop; -+ uint32_t tcp_free_pcb_in_syn_maxrtx; -+ uint32_t tcp_free_pcb_in_maxrtx; -+ uint32_t tcp_alloc_pcb_fails; - - /* UDP */ - uint32_t udp_in_datagrams; -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 49b3ec8..00900e7 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -886,7 +886,6 @@ void stack_tcp_send(struct rpc_msg *msg) - struct lwip_sock *sock = lwip_get_socket(fd); - if (POSIX_IS_CLOSED(sock)) { - msg->result = -1; -- LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); - return; - } - -@@ -922,7 +921,6 @@ void stack_udp_send(struct rpc_msg *msg) - struct lwip_sock *sock = lwip_get_socket(fd); - if (POSIX_IS_CLOSED(sock)) { - msg->result = -1; -- LSTACK_LOG(ERR, LSTACK, "get sock error! fd=%d, len=%ld\n", fd, len); - return; - } - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 9815009..fc30054 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -1005,6 +1005,13 @@ static void gazelle_print_lstack_tcp_stat(const struct gazelle_stat_lstack_snmp - printf("tcp_acceptmbox_full: %u\n", snmp->tcp_acceptmbox_full); - printf("tcp_listen_drops: %u\n", snmp->tcp_listen_drops); - printf("tcp_in_empty_acks: %u\n", snmp->tcp_in_empty_acks); -+ printf("tcp_rst_in_keepalive_timeout: %u\n", snmp->tcp_rst_in_keepalive_timeout); -+ printf("tcp_rst_wrong_syn_in_timewait: %u\n", snmp->tcp_rst_wrong_syn_in_timewait); -+ printf("tcp_rst_wrong_ack_in_syn_rcvd: %u\n", snmp->tcp_rst_wrong_ack_in_syn_rcvd); -+ printf("tcp_ooseq_data_drop: %u\n", snmp->tcp_ooseq_data_drop); -+ printf("tcp_free_pcb_in_syn_maxrtx: %u\n", snmp->tcp_free_pcb_in_syn_maxrtx); -+ printf("tcp_free_pcb_in_maxrtx: %u\n", snmp->tcp_free_pcb_in_maxrtx); -+ printf("tcp_alloc_pcb_fails: %u\n", snmp->tcp_alloc_pcb_fails); - } - - static void gazelle_print_ltran_stat_lb_rate(void *buf, const struct gazelle_stat_msg_request *req_msg) --- -2.33.0 - diff --git a/0256-LOG-add-log-when-udp-send_ring-is-exhausted.patch b/0256-LOG-add-log-when-udp-send_ring-is-exhausted.patch deleted file mode 100644 index 85446e22a9b69afb4156aea458dc57c4df4f2d1e..0000000000000000000000000000000000000000 --- a/0256-LOG-add-log-when-udp-send_ring-is-exhausted.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 66b11c7916740615be6012938e82abd821a1b06e Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Mon, 23 Sep 2024 20:17:10 +0800 -Subject: [PATCH] LOG:add log when udp send_ring is exhausted - ---- - src/lstack/core/lstack_lwip.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 636bbc7..a7b7202 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -497,6 +497,7 @@ static ssize_t do_lwip_udp_fill_sendring(struct lwip_sock *sock, const void *buf - } - - if (write_avail < write_num) { -+ LSTACK_LOG(WARNING, LSTACK, "sock send_ring is already exhausted.\n"); - sem_timedwait_nsecs(&sock->snd_ring_sem); - GAZELLE_RETURN(ENOMEM); - } --- -2.33.0 - diff --git a/0257-cleancode-refactor-rtc_api-rtw_api-and-dummy_api.patch b/0257-cleancode-refactor-rtc_api-rtw_api-and-dummy_api.patch deleted file mode 100644 index 13b6996384af29ef2c60123b0fe523d3331e7e1c..0000000000000000000000000000000000000000 --- a/0257-cleancode-refactor-rtc_api-rtw_api-and-dummy_api.patch +++ /dev/null @@ -1,1035 +0,0 @@ -From 85e907b495391a89096bfb7e5c9cb901d0f9f56b Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sat, 31 Aug 2024 11:31:13 +0800 -Subject: [PATCH] cleancode: refactor rtc_api rtw_api and dummy_api - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_dummy_api.c | 32 ++++-- - src/lstack/api/lstack_epoll.c | 2 +- - src/lstack/api/lstack_fork.c | 28 ----- - src/lstack/api/lstack_rtc_api.c | 92 +++++++++++----- - src/lstack/api/lstack_rtw_api.c | 104 +++++++++++------- - .../api/{lstack_signal.c => lstack_unistd.c} | 31 +++++- - src/lstack/api/lstack_wrap.c | 91 ++------------- - src/lstack/core/lstack_init.c | 31 ++---- - src/lstack/core/lstack_lwip.c | 2 +- - src/lstack/core/lstack_protocol_stack.c | 2 +- - src/lstack/core/lstack_stack_stat.c | 2 +- - src/lstack/include/{posix => }/lstack_epoll.h | 0 - src/lstack/include/lstack_rtc_api.h | 43 +------- - src/lstack/include/lstack_rtw_api.h | 35 +----- - .../include/{posix => }/lstack_unistd.h | 13 +-- - src/lstack/include/lstack_wrap.h | 2 +- - 16 files changed, 217 insertions(+), 293 deletions(-) - delete mode 100644 src/lstack/api/lstack_fork.c - rename src/lstack/api/{lstack_signal.c => lstack_unistd.c} (89%) - rename src/lstack/include/{posix => }/lstack_epoll.h (100%) - rename src/lstack/include/{posix => }/lstack_unistd.h (78%) - -diff --git a/src/lstack/api/lstack_dummy_api.c b/src/lstack/api/lstack_dummy_api.c -index f327916..3a867b3 100644 ---- a/src/lstack/api/lstack_dummy_api.c -+++ b/src/lstack/api/lstack_dummy_api.c -@@ -13,6 +13,10 @@ - #include - #include - -+#include -+#include -+#include -+ - #define DUMMY_SLEEP_S 5 - - static inline ssize_t dummy_exit(void) -@@ -22,34 +26,48 @@ static inline ssize_t dummy_exit(void) - return -1; - } - --int dummy_socket(int domain, int type, int protocol) -+static int dummy_socket(int domain, int type, int protocol) - { - sleep(DUMMY_SLEEP_S); - return -1; - } - --ssize_t dummy_write(int s, const void *mem, size_t size) -+static ssize_t dummy_write(int s, const void *mem, size_t size) - { - return dummy_exit(); - } - --ssize_t dummy_writev(int s, const struct iovec *iov, int iovcnt) -+static ssize_t dummy_writev(int s, const struct iovec *iov, int iovcnt) - { - return dummy_exit(); - } - --ssize_t dummy_send(int sockfd, const void *buf, size_t len, int flags) -+static ssize_t dummy_send(int sockfd, const void *buf, size_t len, int flags) - { - return dummy_exit(); - } - --ssize_t dummy_sendmsg(int s, const struct msghdr *message, int flags) -+static ssize_t dummy_sendmsg(int s, const struct msghdr *message, int flags) - { - return dummy_exit(); - } - --ssize_t dummy_sendto(int sockfd, const void *buf, size_t len, int flags, -- const struct sockaddr *addr, socklen_t addrlen) -+static ssize_t dummy_sendto(int sockfd, const void *buf, size_t len, int flags, -+ const struct sockaddr *addr, socklen_t addrlen) - { - return dummy_exit(); - } -+ -+void dummy_api_init(posix_api_t *api) -+{ -+ api->socket_fn = dummy_socket; -+ api->send_fn = dummy_send; -+ api->write_fn = dummy_write; -+ api->writev_fn = dummy_writev; -+ api->sendmsg_fn = dummy_sendmsg; -+ api->sendto_fn = dummy_sendto; -+ -+ rte_wmb(); -+ /* 1: wait until app thread call send functio complete */ -+ sleep(1); -+} -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 5b0bee4..1c13076 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -35,7 +35,7 @@ - #include "common/gazelle_base_func.h" - #include "lstack_lwip.h" - #include "lstack_protocol_stack.h" --#include "posix/lstack_epoll.h" -+#include "lstack_epoll.h" - - #define EPOLL_KERNEL_INTERVAL 10 /* ms */ - #define SEC_TO_NSEC 1000000000 -diff --git a/src/lstack/api/lstack_fork.c b/src/lstack/api/lstack_fork.c -deleted file mode 100644 -index f5d0e95..0000000 ---- a/src/lstack/api/lstack_fork.c -+++ /dev/null -@@ -1,28 +0,0 @@ --/* --* 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 --#include -- --#include -- --pid_t lstack_fork(void) --{ -- pid_t pid; -- -- pid = posix_api->fork_fn(); -- /* child not support lwip */ -- if (pid == 0) { -- posix_api->use_kernel = 1; -- } -- return pid; --} -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index e30718c..7689c83 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -10,37 +10,16 @@ - * See the Mulan PSL v2 for more details. - */ - --#include --#include --#include --#include --#include - #include --#include "posix/lstack_epoll.h" -+#include -+ -+#include "lstack_epoll.h" - #include "lstack_log.h" - #include "lstack_cfg.h" - #include "lstack_protocol_stack.h" --#include "lstack_thread_rpc.h" - #include "lstack_rtc_api.h" - --int rtc_poll(struct pollfd *fds, nfds_t nfds, int timeout) --{ -- LSTACK_LOG(ERR, LSTACK, "rtc_poll: rtc currently does not support poll\n"); -- return -1; --} -- --int rtc_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) --{ -- LSTACK_LOG(ERR, LSTACK, "rtc_select: rtc currently does not support select\n"); -- return -1; --} -- --int rtc_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) --{ -- return lstack_rtc_epoll_wait(epfd, events, maxevents, timeout); --} -- --int rtc_socket(int domain, int type, int protocol) -+static int rtc_socket(int domain, int type, int protocol) - { - int ret; - -@@ -53,7 +32,7 @@ int rtc_socket(int domain, int type, int protocol) - return ret; - } - --int rtc_close(int s) -+static int rtc_close(int s) - { - struct lwip_sock *sock = lwip_get_socket(s); - if (sock != NULL && sock->wakeup != NULL && sock->wakeup->epollfd == s) { -@@ -63,12 +42,12 @@ int rtc_close(int s) - return lwip_close(s); - } - --int rtc_shutdown(int fd, int how) -+static int rtc_shutdown(int fd, int how) - { - return lwip_shutdown(fd, how); - } - --int rtc_epoll_create(int flags) -+static int rtc_epoll_create(int flags) - { - if (stack_setup_app_thread() < 0) { - exit(1); -@@ -77,7 +56,7 @@ int rtc_epoll_create(int flags) - return lstack_epoll_create(flags); - } - --int rtc_epoll_create1(int flags) -+static int rtc_epoll_create1(int flags) - { - if (stack_setup_app_thread() < 0) { - exit(1); -@@ -86,7 +65,60 @@ int rtc_epoll_create1(int flags) - return lstack_epoll_create1(flags); - } - --int rtc_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) -+static int rtc_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) - { - return lstack_rtc_epoll_ctl(epfd, op, fd, event); - } -+ -+static int rtc_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) -+{ -+ return lstack_rtc_epoll_wait(epfd, events, maxevents, timeout); -+} -+ -+static int rtc_poll(struct pollfd *fds, nfds_t nfds, int timeout) -+{ -+ LSTACK_LOG(ERR, LSTACK, "rtc_poll: rtc currently does not support poll\n"); -+ return -1; -+} -+ -+static int rtc_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) -+{ -+ LSTACK_LOG(ERR, LSTACK, "rtc_select: rtc currently does not support select\n"); -+ return -1; -+} -+ -+void rtc_api_init(posix_api_t *api) -+{ -+ api->close_fn = rtc_close; -+ api->shutdown_fn = rtc_shutdown; -+ api->socket_fn = rtc_socket; -+ api->accept_fn = lwip_accept; -+ api->accept4_fn = lwip_accept4; -+ api->bind_fn = lwip_bind; -+ api->listen_fn = lwip_listen; -+ api->connect_fn = lwip_connect; -+ -+ api->setsockopt_fn = lwip_setsockopt; -+ api->getsockopt_fn = lwip_getsockopt; -+ api->getpeername_fn = lwip_getpeername; -+ api->getsockname_fn = lwip_getsockname; -+ -+ api->read_fn = lwip_read; -+ api->readv_fn = lwip_readv; -+ api->write_fn = lwip_write; -+ api->writev_fn = lwip_writev; -+ api->recv_fn = lwip_recv; -+ api->send_fn = lwip_send; -+ api->recvmsg_fn = (ssize_t (*)(int, const struct msghdr *, int))lwip_recvmsg; // TODO: fix unnecessary 'const' in lwipgz_posix_api.h -+ api->sendmsg_fn = lwip_sendmsg; -+ api->recvfrom_fn = lwip_recvfrom; -+ api->sendto_fn = lwip_sendto; -+ -+ api->epoll_ctl_fn = rtc_epoll_ctl; -+ api->epoll_create1_fn = rtc_epoll_create1; -+ api->epoll_create_fn = rtc_epoll_create; -+ api->epoll_wait_fn = rtc_epoll_wait; -+ -+ api->poll_fn = rtc_poll; -+ api->select_fn = rtc_select; -+} -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index 09c4e11..d8634cc 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -10,23 +10,18 @@ - * See the Mulan PSL v2 for more details. - */ - --#include --#include --#include --#include -- - #include -+#include - - #include "lstack_thread_rpc.h" --#include "posix/lstack_epoll.h" -+#include "lstack_epoll.h" - #include "lstack_protocol_stack.h" - #include "lstack_cfg.h" - #include "lstack_lwip.h" - #include "common/gazelle_base_func.h" - #include "lstack_rtw_api.h" - -- --int rtw_socket(int domain, int type, int protocol) -+static int rtw_socket(int domain, int type, int protocol) - { - struct protocol_stack *stack = get_bind_protocol_stack(); - if (stack == NULL) { -@@ -35,17 +30,17 @@ int rtw_socket(int domain, int type, int protocol) - return rpc_call_socket(&stack->rpc_queue, domain, type, protocol); - } - --int rtw_accept(int s, struct sockaddr *addr, socklen_t *addrlen) -+static int rtw_accept(int s, struct sockaddr *addr, socklen_t *addrlen) - { - return stack_broadcast_accept(s, addr, addrlen); - } - --int rtw_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) -+static int rtw_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) - { - return stack_broadcast_accept4(s, addr, addrlen, flags); - } - --int rtw_bind(int s, const struct sockaddr *name, socklen_t namelen) -+static int rtw_bind(int s, const struct sockaddr *name, socklen_t namelen) - { - struct lwip_sock *sock = lwip_get_socket(s); - -@@ -56,7 +51,7 @@ int rtw_bind(int s, const struct sockaddr *name, socklen_t namelen) - } - } - --int rtw_listen(int s, int backlog) -+static int rtw_listen(int s, int backlog) - { - if (!get_global_cfg_params()->tuple_filter && - !get_global_cfg_params()->listen_shadow) { -@@ -66,7 +61,7 @@ int rtw_listen(int s, int backlog) - } - } - --int rtw_connect(int s, const struct sockaddr *name, socklen_t namelen) -+static int rtw_connect(int s, const struct sockaddr *name, socklen_t namelen) - { - struct protocol_stack *stack = get_protocol_stack_by_fd(s); - if (stack == NULL) { -@@ -75,7 +70,7 @@ int rtw_connect(int s, const struct sockaddr *name, socklen_t namelen) - return rpc_call_connect(&stack->rpc_queue, s, name, namelen); - } - --int rtw_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) -+static int rtw_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) - { - struct protocol_stack *stack = get_protocol_stack_by_fd(s); - if (stack == NULL) { -@@ -84,7 +79,7 @@ int rtw_setsockopt(int s, int level, int optname, const void *optval, socklen_t - return rpc_call_setsockopt(&stack->rpc_queue, s, level, optname, optval, optlen); - } - --int rtw_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) -+static int rtw_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) - { - struct protocol_stack *stack = get_protocol_stack_by_fd(s); - if (stack == NULL) { -@@ -93,7 +88,7 @@ int rtw_getsockopt(int s, int level, int optname, void *optval, socklen_t *optle - return rpc_call_getsockopt(&stack->rpc_queue, s, level, optname, optval, optlen); - } - --int rtw_getpeername(int s, struct sockaddr *name, socklen_t *namelen) -+static int rtw_getpeername(int s, struct sockaddr *name, socklen_t *namelen) - { - struct protocol_stack *stack = get_protocol_stack_by_fd(s); - if (stack == NULL) { -@@ -102,7 +97,7 @@ int rtw_getpeername(int s, struct sockaddr *name, socklen_t *namelen) - return rpc_call_getpeername(&stack->rpc_queue, s, name, namelen); - } - --int rtw_getsockname(int s, struct sockaddr *name, socklen_t *namelen) -+static int rtw_getsockname(int s, struct sockaddr *name, socklen_t *namelen) - { - struct protocol_stack *stack = get_protocol_stack_by_fd(s); - if (stack == NULL) { -@@ -111,12 +106,12 @@ int rtw_getsockname(int s, struct sockaddr *name, socklen_t *namelen) - return rpc_call_getsockname(&stack->rpc_queue, s, name, namelen); - } - --ssize_t rtw_read(int s, void *mem, size_t len) -+static ssize_t rtw_read(int s, void *mem, size_t len) - { - return do_lwip_read_from_stack(s, mem, len, 0, NULL, NULL); - } - --ssize_t rtw_readv(int s, const struct iovec *iov, int iovcnt) -+static ssize_t rtw_readv(int s, const struct iovec *iov, int iovcnt) - { - struct msghdr msg; - -@@ -130,12 +125,12 @@ ssize_t rtw_readv(int s, const struct iovec *iov, int iovcnt) - return do_lwip_recvmsg_from_stack(s, &msg, 0); - } - --ssize_t rtw_write(int s, const void *mem, size_t size) -+static ssize_t rtw_write(int s, const void *mem, size_t size) - { - return do_lwip_send_to_stack(s, mem, size, 0, NULL, 0); - } - --ssize_t rtw_writev(int s, const struct iovec *iov, int iovcnt) -+static ssize_t rtw_writev(int s, const struct iovec *iov, int iovcnt) - { - struct lwip_sock *sock = lwip_get_socket(s); - struct msghdr msg; -@@ -150,22 +145,22 @@ ssize_t rtw_writev(int s, const struct iovec *iov, int iovcnt) - return do_lwip_sendmsg_to_stack(sock, s, &msg, 0); - } - --ssize_t rtw_recv(int sockfd, void *buf, size_t len, int flags) -+static ssize_t rtw_recv(int sockfd, void *buf, size_t len, int flags) - { - return do_lwip_read_from_stack(sockfd, buf, len, flags, NULL, NULL); - } - --ssize_t rtw_send(int sockfd, const void *buf, size_t len, int flags) -+static ssize_t rtw_send(int sockfd, const void *buf, size_t len, int flags) - { - return do_lwip_send_to_stack(sockfd, buf, len, flags, NULL, 0); - } - --ssize_t rtw_recvmsg(int s, const struct msghdr *message, int flags) -+static ssize_t rtw_recvmsg(int s, struct msghdr *message, int flags) - { - return do_lwip_recvmsg_from_stack(s, message, flags); - } - --ssize_t rtw_sendmsg(int s, const struct msghdr *message, int flags) -+static ssize_t rtw_sendmsg(int s, const struct msghdr *message, int flags) - { - struct lwip_sock *sock = lwip_get_socket(s); - return do_lwip_sendmsg_to_stack(sock, s, message, flags); -@@ -207,8 +202,8 @@ static inline ssize_t rtw_tcp_recvfrom(int sockfd, void *buf, size_t len, int fl - } - - --ssize_t rtw_recvfrom(int sockfd, void *buf, size_t len, int flags, -- struct sockaddr *addr, socklen_t *addrlen) -+static ssize_t rtw_recvfrom(int sockfd, void *buf, size_t len, int flags, -+ struct sockaddr *addr, socklen_t *addrlen) - { - struct lwip_sock *sock = lwip_get_socket(sockfd); - if (NETCONN_IS_UDP(sock)) { -@@ -218,28 +213,28 @@ ssize_t rtw_recvfrom(int sockfd, void *buf, size_t len, int flags, - } - } - --ssize_t rtw_sendto(int sockfd, const void *buf, size_t len, int flags, -- const struct sockaddr *addr, socklen_t addrlen) -+static ssize_t rtw_sendto(int sockfd, const void *buf, size_t len, int flags, -+ const struct sockaddr *addr, socklen_t addrlen) - { - return do_lwip_send_to_stack(sockfd, buf, len, flags, addr, addrlen); - } - --int rtw_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) -+static int rtw_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) - { - return lstack_rtw_epoll_wait(epfd, events, maxevents, timeout); - } - --int rtw_poll(struct pollfd *fds, nfds_t nfds, int timeout) -+static int rtw_poll(struct pollfd *fds, nfds_t nfds, int timeout) - { - return lstack_poll(fds, nfds, timeout); - } - --int rtw_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) -+static int rtw_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) - { - return lstack_select(nfds, readfds, writefds, exceptfds, timeout); - } - --int rtw_close(int s) -+static int rtw_close(int s) - { - struct lwip_sock *sock = lwip_get_socket(s); - if (sock && sock->wakeup && sock->wakeup->epollfd == s) { -@@ -248,7 +243,7 @@ int rtw_close(int s) - return stack_broadcast_close(s); - } - --int rtw_shutdown(int fd, int how) -+static int rtw_shutdown(int fd, int how) - { - struct lwip_sock *sock = lwip_get_socket(fd); - if (sock && sock->wakeup && sock->wakeup->epollfd == fd) { -@@ -258,18 +253,53 @@ int rtw_shutdown(int fd, int how) - return stack_broadcast_shutdown(fd, how); - } - --int rtw_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) -+static int rtw_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) - { - return lstack_rtw_epoll_ctl(epfd, op, fd, event); - } - --int rtw_epoll_create1(int flags) -+static int rtw_epoll_create1(int flags) - { - return lstack_epoll_create1(flags); - } - --int rtw_epoll_create(int flags) -+static int rtw_epoll_create(int flags) - { - return lstack_epoll_create(flags); - } - -+void rtw_api_init(posix_api_t *api) -+{ -+ api->close_fn = rtw_close; -+ api->shutdown_fn = rtw_shutdown; -+ api->socket_fn = rtw_socket; -+ api->accept_fn = rtw_accept; -+ api->accept4_fn = rtw_accept4; -+ api->bind_fn = rtw_bind; -+ api->listen_fn = rtw_listen; -+ api->connect_fn = rtw_connect; -+ -+ api->setsockopt_fn = rtw_setsockopt; -+ api->getsockopt_fn = rtw_getsockopt; -+ api->getpeername_fn = rtw_getpeername; -+ api->getsockname_fn = rtw_getsockname; -+ -+ api->read_fn = rtw_read; -+ api->readv_fn = rtw_readv; -+ api->write_fn = rtw_write; -+ api->writev_fn = rtw_writev; -+ api->recv_fn = rtw_recv; -+ api->send_fn = rtw_send; -+ api->recvmsg_fn = (ssize_t (*)(int, const struct msghdr *, int))rtw_recvmsg; // TODO: fix unnecessary 'const' in lwipgz_posix_api.h -+ api->sendmsg_fn = rtw_sendmsg; -+ api->recvfrom_fn = rtw_recvfrom; -+ api->sendto_fn = rtw_sendto; -+ -+ api->epoll_ctl_fn = rtw_epoll_ctl; -+ api->epoll_create1_fn = rtw_epoll_create1; -+ api->epoll_create_fn = rtw_epoll_create; -+ api->epoll_wait_fn = rtw_epoll_wait; -+ -+ api->poll_fn = rtw_poll; -+ api->select_fn = rtw_select; -+} -\ No newline at end of file -diff --git a/src/lstack/api/lstack_signal.c b/src/lstack/api/lstack_unistd.c -similarity index 89% -rename from src/lstack/api/lstack_signal.c -rename to src/lstack/api/lstack_unistd.c -index 9d0431b..1f78626 100644 ---- a/src/lstack/api/lstack_signal.c -+++ b/src/lstack/api/lstack_unistd.c -@@ -11,22 +11,22 @@ - */ - - #include --#include --#include - #include --#include -+#include -+ - #include - #include - -+#include "lstack_unistd.h" - #include "common/gazelle_base_func.h" --#include "lstack_cfg.h" --#include "common/dpdk_common.h" - #include "lstack_log.h" -+#include "lstack_cfg.h" - #include "lstack_control_plane.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; -@@ -71,17 +71,24 @@ static void lstack_sig_default_handler(int sig) - (void)kill(getpid(), sig); - } - --void lstack_signal_init(void) -+int lstack_signal_init(void) - { - unsigned int i; - struct sigaction action; - -+ /* to prevent crash, just ignore SIGPIPE when socket is closed */ -+ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { -+ return -1; -+ } -+ - sigemptyset(&action.sa_mask); - action.sa_flags = (int)(SA_NODEFER | SA_RESETHAND); - action.sa_handler = lstack_sig_default_handler; - for (i = 0; i < HIJACK_SIGNAL_COUNT; i++) { - posix_api->sigaction_fn(g_hijack_signal[i], &action, NULL); - } -+ -+ return 0; - } - - int lstack_sigaction(int sig_num, const struct sigaction *action, struct sigaction *old_action) -@@ -104,3 +111,15 @@ int lstack_sigaction(int sig_num, const struct sigaction *action, struct sigacti - - return posix_api->sigaction_fn(sig_num, action, old_action); - } -+ -+pid_t lstack_fork(void) -+{ -+ pid_t pid; -+ -+ pid = posix_api->fork_fn(); -+ /* child not support lwip */ -+ if (pid == 0) { -+ posix_api->use_kernel = 1; -+ } -+ return pid; -+} -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 92ce73b..1d5529d 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -10,29 +10,22 @@ - * See the Mulan PSL v2 for more details. - */ - --#include --#include -+#include - #include -- --#include --#include - #include - #include --#include - #include --#include - - #include - #include - #include - --#include "posix/lstack_unistd.h" -+#include "common/gazelle_base_func.h" - #include "lstack_log.h" - #include "lstack_cfg.h" - #include "lstack_lwip.h" --#include "common/gazelle_base_func.h" - #include "lstack_preload.h" -- -+#include "lstack_unistd.h" - #include "lstack_rtc_api.h" - #include "lstack_rtw_api.h" - #include "lstack_dummy_api.h" -@@ -45,78 +38,18 @@ void wrap_api_init(void) - if (g_wrap_api != NULL) { - return; - } -- - g_wrap_api = &g_wrap_api_value; -+ - if (get_global_cfg_params()->stack_mode_rtc) { -- g_wrap_api->socket_fn = rtc_socket; -- g_wrap_api->accept_fn = lwip_accept; -- g_wrap_api->accept4_fn = lwip_accept4; -- g_wrap_api->bind_fn = lwip_bind; -- g_wrap_api->listen_fn = lwip_listen; -- g_wrap_api->connect_fn = lwip_connect; -- g_wrap_api->setsockopt_fn = lwip_setsockopt; -- g_wrap_api->getsockopt_fn = lwip_getsockopt; -- g_wrap_api->getpeername_fn = lwip_getpeername; -- g_wrap_api->getsockname_fn = lwip_getsockname; -- g_wrap_api->read_fn = lwip_read; -- g_wrap_api->readv_fn = lwip_readv; -- g_wrap_api->write_fn = lwip_write; -- g_wrap_api->writev_fn = lwip_writev; -- g_wrap_api->recv_fn = lwip_recv; -- g_wrap_api->send_fn = lwip_send; -- g_wrap_api->recvmsg_fn = lwip_recvmsg; -- g_wrap_api->sendmsg_fn = lwip_sendmsg; -- g_wrap_api->recvfrom_fn = lwip_recvfrom; -- g_wrap_api->sendto_fn = lwip_sendto; -- g_wrap_api->epoll_wait_fn = rtc_epoll_wait; -- g_wrap_api->poll_fn = rtc_poll; -- g_wrap_api->close_fn = rtc_close; -- g_wrap_api->shutdown_fn = rtc_shutdown; -- g_wrap_api->epoll_ctl_fn = rtc_epoll_ctl; -- g_wrap_api->epoll_create1_fn = rtc_epoll_create1; -- g_wrap_api->epoll_create_fn = rtc_epoll_create; -- g_wrap_api->select_fn = rtc_select; -+ rtc_api_init(g_wrap_api); - } else { -- g_wrap_api->socket_fn = rtw_socket; -- g_wrap_api->accept_fn = rtw_accept; -- g_wrap_api->accept4_fn = rtw_accept4; -- g_wrap_api->bind_fn = rtw_bind; -- g_wrap_api->listen_fn = rtw_listen; -- g_wrap_api->connect_fn = rtw_connect; -- g_wrap_api->setsockopt_fn = rtw_setsockopt; -- g_wrap_api->getsockopt_fn = rtw_getsockopt; -- g_wrap_api->getpeername_fn = rtw_getpeername; -- g_wrap_api->getsockname_fn = rtw_getsockname; -- g_wrap_api->read_fn = rtw_read; -- g_wrap_api->readv_fn = rtw_readv; -- g_wrap_api->write_fn = rtw_write; -- g_wrap_api->writev_fn = rtw_writev; -- g_wrap_api->recv_fn = rtw_recv; -- g_wrap_api->send_fn = rtw_send; -- g_wrap_api->recvmsg_fn = rtw_recvmsg; -- g_wrap_api->sendmsg_fn = rtw_sendmsg; -- g_wrap_api->recvfrom_fn = rtw_recvfrom; -- g_wrap_api->sendto_fn = rtw_sendto; -- g_wrap_api->epoll_wait_fn = rtw_epoll_wait; -- g_wrap_api->poll_fn = rtw_poll; -- g_wrap_api->close_fn = rtw_close; -- g_wrap_api->shutdown_fn = rtw_shutdown; -- g_wrap_api->epoll_ctl_fn = rtw_epoll_ctl; -- g_wrap_api->epoll_create1_fn = rtw_epoll_create1; -- g_wrap_api->epoll_create_fn = rtw_epoll_create; -- g_wrap_api->select_fn = rtw_select; -- } --} -- --void wrap_api_set_dummy(void) --{ -- g_wrap_api->socket_fn = dummy_socket; -- g_wrap_api->send_fn = dummy_send; -- g_wrap_api->write_fn = dummy_write; -- g_wrap_api->writev_fn = dummy_writev; -- g_wrap_api->sendmsg_fn = dummy_sendmsg; -- g_wrap_api->sendto_fn = dummy_sendto; -- rte_wmb(); -+ rtw_api_init(g_wrap_api); -+ } -+} -+ -+void wrap_api_exit(void) -+{ -+ dummy_api_init(g_wrap_api); - } - - static inline int32_t do_epoll_create1(int32_t flags) -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index e0f7bd7..37264a1 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -20,27 +20,26 @@ - #include - #include - #include --#include - #include - #include - #include - #include - --#include -+#include -+ - #include - #include - #include - #include - -+#include "lstack_log.h" - #include "lstack_cfg.h" - #include "lstack_control_plane.h" - #include "lstack_ethdev.h" - #include "lstack_dpdk.h" - #include "lstack_stack_stat.h" --#include "lstack_log.h" - #include "common/dpdk_common.h" --#include "posix/lstack_epoll.h" --#include "posix/lstack_unistd.h" -+#include "lstack_unistd.h" - #include "common/gazelle_base_func.h" - #include "lstack_protocol_stack.h" - #include "lstack_preload.h" -@@ -107,9 +106,7 @@ static int32_t check_process_conflict(void) - - void gazelle_exit(void) - { -- wrap_api_set_dummy(); -- /* 1: wait until app thread call send functio complete */ -- sleep(1); -+ wrap_api_exit(); - stack_group_exit(); - } - -@@ -170,18 +167,6 @@ static void create_control_thread(void) - LSTACK_LOG(INFO, LSTACK, "create control_easy_thread success\n"); - } - --static void gazelle_signal_init(void) --{ -- /* to prevent crash , just ignore SIGPIPE when socket is closed */ -- if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { -- LSTACK_PRE_LOG(LSTACK_ERR, "signal error, errno:%d.", errno); -- LSTACK_EXIT(1, "signal SIGPIPE SIG_IGN\n"); -- } -- -- /* register core sig handler func to dumped stack */ -- lstack_signal_init(); --} -- - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - static void set_kni_ip_mac() - { -@@ -278,7 +263,11 @@ __attribute__((constructor)) void gazelle_network_init(void) - } - } - -- gazelle_signal_init(); -+ /* register core sig handler func to dumped stack */ -+ if (lstack_signal_init() != 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "signal init failed, errno %d\n", errno); -+ LSTACK_EXIT(1, "signal init failed, errno %d\n", errno); -+ } - - /* Init control plane and dpdk init */ - create_control_thread(); -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index a7b7202..89142a4 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -34,7 +34,7 @@ - #include "lstack_log.h" - #include "lstack_dpdk.h" - #include "lstack_stack_stat.h" --#include "posix/lstack_epoll.h" -+#include "lstack_epoll.h" - #include "lstack_thread_rpc.h" - #include "common/dpdk_common.h" - #include "lstack_cfg.h" -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 00900e7..f56e911 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -31,7 +31,7 @@ - #include "lstack_lwip.h" - #include "lstack_cfg.h" - #include "lstack_control_plane.h" --#include "posix/lstack_epoll.h" -+#include "lstack_epoll.h" - #include "lstack_stack_stat.h" - #include "lstack_virtio.h" - #include "lstack_protocol_stack.h" -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 406e27c..b6619f6 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -26,7 +26,7 @@ - #include "common/gazelle_dfx_msg.h" - #include "lstack_thread_rpc.h" - #include "lstack_protocol_stack.h" --#include "posix/lstack_epoll.h" -+#include "lstack_epoll.h" - #include "lstack_dpdk.h" - #include "lstack_stack_stat.h" - #include "lstack_virtio.h" -diff --git a/src/lstack/include/posix/lstack_epoll.h b/src/lstack/include/lstack_epoll.h -similarity index 100% -rename from src/lstack/include/posix/lstack_epoll.h -rename to src/lstack/include/lstack_epoll.h -diff --git a/src/lstack/include/lstack_rtc_api.h b/src/lstack/include/lstack_rtc_api.h -index 3a41e6f..b4b7e1c 100644 ---- a/src/lstack/include/lstack_rtc_api.h -+++ b/src/lstack/include/lstack_rtc_api.h -@@ -12,47 +12,14 @@ - - #ifndef _LSTACK_RTC_API_H_ - #define _LSTACK_RTC_API_H_ --#include --#include --#include -+ -+#include - - /* don't include lwip/sockets.h, conflict with sys/socket.h */ --/* extern lwip_api here */ - extern int lwip_fcntl(int s, int cmd, int val); --extern int lwip_ioctl(int s, long cmd, ...); --extern int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); --extern int lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags); --extern int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); --extern int lwip_shutdown(int s, int how); --extern int lwip_getpeername(int s, struct sockaddr *name, socklen_t *namelen); --extern int lwip_getsockname(int s, struct sockaddr *name, socklen_t *namelen); --extern int lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen); --extern int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen); --extern int lwip_close(int s); --extern int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); --extern int lwip_listen(int s, int backlog); --extern ssize_t lwip_recv(int s, void *mem, size_t len, int flags); --extern ssize_t lwip_read(int s, void *mem, size_t len); --extern ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt); --extern ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, -- struct sockaddr *from, socklen_t *fromlen); --extern ssize_t lwip_recvmsg(int s, const struct msghdr *message, int flags); --extern ssize_t lwip_send(int s, const void *dataptr, size_t size, int flags); --extern ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags); --extern ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, -- const struct sockaddr *to, socklen_t tolen); --extern int lwip_socket(int domain, int type, int protocol); --extern ssize_t lwip_write(int s, const void *dataptr, size_t size); --extern ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt); -+extern int lwip_ioctl(int s, long cmd, void *argp); - --int rtc_poll(struct pollfd *fds, nfds_t nfds, int timeout); --int rtc_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout); --int rtc_socket(int domain, int type, int protocol); --int rtc_close(int s); --int rtc_shutdown(int fd, int how); --int rtc_epoll_create(int flags); --int rtc_epoll_create1(int flags); --int rtc_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); --int rtc_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); -+void dummy_api_init(posix_api_t *api); -+void rtc_api_init(posix_api_t *api); - - #endif /* __LSTACK_RTC_API_H_ */ -diff --git a/src/lstack/include/lstack_rtw_api.h b/src/lstack/include/lstack_rtw_api.h -index a38b656..437901a 100644 ---- a/src/lstack/include/lstack_rtw_api.h -+++ b/src/lstack/include/lstack_rtw_api.h -@@ -13,39 +13,8 @@ - #ifndef _LSTACK_RTW_API_H_ - #define _LSTACK_RTW_API_H_ - --#include --#include --#include -+#include - --int rtw_socket(int domain, int type, int protocol); --int rtw_accept(int s, struct sockaddr *addr, socklen_t *addrlen); --int rtw_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags); --int rtw_bind(int s, const struct sockaddr *name, socklen_t namelen); --int rtw_listen(int s, int backlog); --int rtw_connect(int s, const struct sockaddr *name, socklen_t namelen); --int rtw_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen); --int rtw_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen); --int rtw_getpeername(int s, struct sockaddr *name, socklen_t *namelen); --int rtw_getsockname(int s, struct sockaddr *name, socklen_t *namelen); --ssize_t rtw_read(int s, void *mem, size_t len); --ssize_t rtw_readv(int s, const struct iovec *iov, int iovcnt); --ssize_t rtw_write(int s, const void *mem, size_t size); --ssize_t rtw_writev(int s, const struct iovec *iov, int iovcnt); --ssize_t rtw_recv(int sockfd, void *buf, size_t len, int flags); --ssize_t rtw_send(int sockfd, const void *buf, size_t len, int flags); --ssize_t rtw_recvmsg(int s, const struct msghdr *message, int flags); --ssize_t rtw_sendmsg(int s, const struct msghdr *message, int flags); --ssize_t rtw_recvfrom(int sockfd, void *buf, size_t len, int flags, -- struct sockaddr *addr, socklen_t *addrlen); --ssize_t rtw_sendto(int sockfd, const void *buf, size_t len, int flags, -- const struct sockaddr *addr, socklen_t addrlen); --int rtw_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout); --int rtw_poll(struct pollfd *fds, nfds_t nfds, int timeout); --int rtw_close(int s); --int rtw_shutdown(int fd, int how); --int rtw_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); --int rtw_epoll_create1(int flags); --int rtw_epoll_create(int flags); --int rtw_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); -+void rtw_api_init(posix_api_t *api); - - #endif /* _LSTACK_RTW_API_H_ */ -diff --git a/src/lstack/include/posix/lstack_unistd.h b/src/lstack/include/lstack_unistd.h -similarity index 78% -rename from src/lstack/include/posix/lstack_unistd.h -rename to src/lstack/include/lstack_unistd.h -index 484a792..3bcee5a 100644 ---- a/src/lstack/include/posix/lstack_unistd.h -+++ b/src/lstack/include/lstack_unistd.h -@@ -13,16 +13,11 @@ - #ifndef _GAZELLE_UNISTD_H_ - #define _GAZELLE_UNISTD_H_ - --#ifdef __cplusplus --extern "C" { --#endif -+#include -+#include - -+int lstack_signal_init(void); -+int lstack_sigaction(int sig_num, const struct sigaction *action, struct sigaction *old_action); - pid_t lstack_fork(void); --void lstack_signal_init(void); --int lstack_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); -- --#ifdef __cplusplus --} --#endif - - #endif /* _GAZELLE_UNISTD_H_ */ -diff --git a/src/lstack/include/lstack_wrap.h b/src/lstack/include/lstack_wrap.h -index dab5222..a45b0d5 100644 ---- a/src/lstack/include/lstack_wrap.h -+++ b/src/lstack/include/lstack_wrap.h -@@ -14,7 +14,7 @@ - #define _LSTACK_WRAP_H_ - - void wrap_api_init(void); --void wrap_api_set_dummy(void); -+void wrap_api_exit(void); - - #endif - --- -2.33.0 - diff --git a/0258-cleancode-move-some-API-from-stack-to-rpc-and-rtw.patch b/0258-cleancode-move-some-API-from-stack-to-rpc-and-rtw.patch deleted file mode 100644 index 3cce58f22e31096e723236d19403fec9f7f8cd90..0000000000000000000000000000000000000000 --- a/0258-cleancode-move-some-API-from-stack-to-rpc-and-rtw.patch +++ /dev/null @@ -1,2604 +0,0 @@ -From 7e4d7c638681df4f32c0d719c62b4e38ef69c1eb Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sat, 31 Aug 2024 14:51:41 +0800 -Subject: [PATCH] cleancode: move some API from stack to rpc and rtw - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 17 +- - src/lstack/api/lstack_rtc_api.c | 7 +- - src/lstack/api/lstack_rtw_api.c | 250 ++++++- - src/lstack/api/lstack_wrap.c | 1 - - src/lstack/core/lstack_dpdk.c | 5 +- - src/lstack/core/lstack_lwip.c | 47 +- - src/lstack/core/lstack_protocol_stack.c | 757 ++------------------- - src/lstack/core/lstack_thread_rpc.c | 610 +++++++++++++---- - src/lstack/include/lstack_dpdk.h | 33 +- - src/lstack/include/lstack_epoll.h | 12 +- - src/lstack/include/lstack_lwip.h | 9 +- - src/lstack/include/lstack_protocol_stack.h | 51 +- - src/lstack/include/lstack_rpc_proc.h | 47 -- - src/lstack/include/lstack_thread_rpc.h | 81 +-- - src/lstack/netif/lstack_ethdev.c | 56 ++ - 15 files changed, 927 insertions(+), 1056 deletions(-) - delete mode 100644 src/lstack/include/lstack_rpc_proc.h - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 1c13076..ce3d267 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -19,15 +19,9 @@ - #include - #include - --#include - #include --#include --#include --#include --#include - #include - --#include "lstack_ethdev.h" - #include "lstack_stack_stat.h" - #include "lstack_cfg.h" - #include "lstack_log.h" -@@ -306,6 +300,17 @@ int32_t lstack_epoll_create(int32_t flags) - return lstack_do_epoll_create(fd); - } - -+static void stack_broadcast_clean_epoll(struct wakeup_poll *wakeup) -+{ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ struct protocol_stack *stack = NULL; -+ -+ for (int32_t i = 0; i < stack_group->stack_num; i++) { -+ stack = stack_group->stacks[i]; -+ rpc_call_clean_epoll(&stack->rpc_queue, wakeup); -+ } -+} -+ - int32_t lstack_epoll_close(int32_t fd) - { - struct lwip_sock *sock = lwip_get_socket(fd); -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index 7689c83..60d3b23 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -42,11 +42,6 @@ static int rtc_close(int s) - return lwip_close(s); - } - --static int rtc_shutdown(int fd, int how) --{ -- return lwip_shutdown(fd, how); --} -- - static int rtc_epoll_create(int flags) - { - if (stack_setup_app_thread() < 0) { -@@ -90,7 +85,7 @@ static int rtc_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *excep - void rtc_api_init(posix_api_t *api) - { - api->close_fn = rtc_close; -- api->shutdown_fn = rtc_shutdown; -+ api->shutdown_fn = lwip_shutdown; - api->socket_fn = rtc_socket; - api->accept_fn = lwip_accept; - api->accept4_fn = lwip_accept4; -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index d8634cc..7ceff20 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -13,14 +13,258 @@ - #include - #include - -+#include "common/gazelle_base_func.h" -+#include "lstack_log.h" -+#include "lstack_cfg.h" - #include "lstack_thread_rpc.h" --#include "lstack_epoll.h" - #include "lstack_protocol_stack.h" --#include "lstack_cfg.h" - #include "lstack_lwip.h" --#include "common/gazelle_base_func.h" -+#include "lstack_epoll.h" - #include "lstack_rtw_api.h" - -+/* when fd is listenfd, listenfd of all protocol stack thread will be closed */ -+static int stack_broadcast_close(int fd) -+{ -+ int ret = 0; -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -+ if (sock == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ -+ do { -+ sock = sock->listen_next; -+ if (stack == NULL || rpc_call_close(&stack->rpc_queue, fd)) { -+ ret = -1; -+ } -+ -+ if (POSIX_IS_CLOSED(sock)) { -+ break; -+ } -+ fd = sock->conn->callback_arg.socket; -+ stack = get_protocol_stack_by_fd(fd); -+ } while (1); -+ -+ return ret; -+} -+ -+static int stack_broadcast_shutdown(int fd, int how) -+{ -+ int32_t ret = 0; -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -+ if (sock == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ -+ do { -+ sock = sock->listen_next; -+ if (stack == NULL || rpc_call_shutdown(&stack->rpc_queue, fd, how)) { -+ ret = -1; -+ } -+ -+ if (POSIX_IS_CLOSED(sock)) { -+ break; -+ } -+ fd = sock->conn->callback_arg.socket; -+ stack = get_protocol_stack_by_fd(fd); -+ } while (1); -+ -+ return ret; -+} -+ -+/* choice one stack bind */ -+static int stack_single_bind(int fd, const struct sockaddr *name, socklen_t namelen) -+{ -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_bind(&stack->rpc_queue, fd, name, namelen); -+} -+ -+/* bind sync to all protocol stack thread, so that any protocol stack thread can build connect */ -+static int stack_broadcast_bind(int fd, const struct sockaddr *name, socklen_t namelen) -+{ -+ struct protocol_stack *cur_stack = get_protocol_stack_by_fd(fd); -+ struct protocol_stack *stack = NULL; -+ int ret, clone_fd; -+ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL || cur_stack == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); -+ GAZELLE_RETURN(EBADF); -+ } -+ -+ ret = rpc_call_bind(&cur_stack->rpc_queue, fd, name, namelen); -+ if (ret < 0) { -+ close(fd); -+ return ret; -+ } -+ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ for (int i = 0; i < stack_group->stack_num; ++i) { -+ stack = stack_group->stacks[i]; -+ if (stack != cur_stack) { -+ clone_fd = rpc_call_shadow_fd(&stack->rpc_queue, fd, name, namelen); -+ if (clone_fd < 0) { -+ stack_broadcast_close(fd); -+ return clone_fd; -+ } -+ } -+ } -+ return 0; -+} -+ -+static void inline del_accept_in_event(struct lwip_sock *sock) -+{ -+ pthread_spin_lock(&sock->wakeup->event_list_lock); -+ -+ if (!NETCONN_IS_ACCEPTIN(sock)) { -+ sock->events &= ~EPOLLIN; -+ if (sock->events == 0) { -+ list_del_node(&sock->event_list); -+ } -+ } -+ -+ pthread_spin_unlock(&sock->wakeup->event_list_lock); -+} -+ -+static struct lwip_sock *get_min_accept_sock(int fd) -+{ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ struct lwip_sock *min_sock = NULL; -+ -+ while (sock) { -+ if (!NETCONN_IS_ACCEPTIN(sock)) { -+ sock = sock->listen_next; -+ continue; -+ } -+ -+ if (min_sock == NULL || min_sock->stack->conn_num > sock->stack->conn_num) { -+ min_sock = sock; -+ } -+ -+ sock = sock->listen_next; -+ } -+ -+ return min_sock; -+} -+ -+/* ergodic the protocol stack thread to find the connection, because all threads are listening */ -+static int stack_broadcast_accept4(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags) -+{ -+ int ret = -1; -+ struct lwip_sock *min_sock = NULL; -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ struct protocol_stack *stack = NULL; -+ if (sock == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ -+ if (netconn_is_nonblocking(sock->conn)) { -+ min_sock = get_min_accept_sock(fd); -+ } else { -+ while ((min_sock = get_min_accept_sock(fd)) == NULL) { -+ lstack_block_wait(sock->wakeup, 0); -+ } -+ } -+ -+ if (min_sock && min_sock->conn) { -+ stack = get_protocol_stack_by_fd(min_sock->conn->callback_arg.socket); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ ret = rpc_call_accept(&stack->rpc_queue, min_sock->conn->callback_arg.socket, addr, addrlen, flags); -+ } -+ -+ if (min_sock && min_sock->wakeup && min_sock->wakeup->type == WAKEUP_EPOLL) { -+ del_accept_in_event(min_sock); -+ } -+ -+ if (ret < 0) { -+ errno = EAGAIN; -+ } -+ return ret; -+} -+ -+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); -+} -+ -+/* choice one stack listen */ -+static int stack_single_listen(int fd, int backlog) -+{ -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_listen(&stack->rpc_queue, fd, backlog); -+} -+ -+/* listen sync to all protocol stack thread, so that any protocol stack thread can build connect */ -+static int stack_broadcast_listen(int fd, int backlog) -+{ -+ typedef union sockaddr_union { -+ struct sockaddr sa; -+ struct sockaddr_in in; -+ struct sockaddr_in6 in6; -+ } sockaddr_t; -+ -+ struct protocol_stack *cur_stack = get_protocol_stack_by_fd(fd); -+ struct protocol_stack *stack = NULL; -+ sockaddr_t addr; -+ socklen_t addr_len = sizeof(addr); -+ int ret, clone_fd; -+ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL || cur_stack == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); -+ GAZELLE_RETURN(EBADF); -+ } -+ -+ ret = rpc_call_getsockname(&cur_stack->rpc_queue, fd, (struct sockaddr *)&addr, &addr_len); -+ if (ret != 0) { -+ return ret; -+ } -+ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ int min_conn_stk_idx = get_min_conn_stack(stack_group); -+ -+ 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) { -+ stack_broadcast_close(fd); -+ return clone_fd; -+ } -+ } else { -+ clone_fd = fd; -+ } -+ -+ if (min_conn_stk_idx == i) { -+ lwip_get_socket(clone_fd)->conn->is_master_fd = 1; -+ } else { -+ lwip_get_socket(clone_fd)->conn->is_master_fd = 0; -+ } -+ -+ ret = rpc_call_listen(&stack->rpc_queue, clone_fd, backlog); -+ if (ret < 0) { -+ stack_broadcast_close(fd); -+ return ret; -+ } -+ } -+ return 0; -+} -+ - static int rtw_socket(int domain, int type, int protocol) - { - struct protocol_stack *stack = get_bind_protocol_stack(); -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 1d5529d..8f80f98 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -14,7 +14,6 @@ - #include - #include - #include --#include - - #include - #include -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 50fbdf6..f87e362 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -43,7 +43,6 @@ - #include "lstack_log.h" - #include "common/dpdk_common.h" - #include "lstack_protocol_stack.h" --#include "lstack_thread_rpc.h" - #include "lstack_lwip.h" - #include "lstack_cfg.h" - #include "lstack_virtio.h" -@@ -765,9 +764,9 @@ static int dpdk_bond_create(uint8_t mode, int *slave_port_id, int count) - return 0; - } - --int32_t init_dpdk_ethdev(void) -+int init_dpdk_ethdev(void) - { -- int32_t ret; -+ int ret; - int slave_port_id[GAZELLE_MAX_BOND_NUM]; - int port_id = 0; - struct cfg_params *cfg = get_global_cfg_params(); -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 89142a4..3454961 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -29,15 +29,12 @@ - #include - - #include "common/gazelle_base_func.h" --#include "lstack_ethdev.h" --#include "lstack_protocol_stack.h" - #include "lstack_log.h" --#include "lstack_dpdk.h" -+#include "lstack_cfg.h" -+#include "lstack_protocol_stack.h" - #include "lstack_stack_stat.h" - #include "lstack_epoll.h" --#include "lstack_thread_rpc.h" --#include "common/dpdk_common.h" --#include "lstack_cfg.h" -+#include "lstack_dpdk.h" - #include "lstack_lwip.h" - - static const uint8_t fin_packet = 0; -@@ -841,43 +838,24 @@ ssize_t gazelle_same_node_ring_send(struct lwip_sock *sock, const void *buf, siz - return act_len; - } - --PER_THREAD uint16_t stack_sock_num[GAZELLE_MAX_STACK_NUM] = {0}; --PER_THREAD uint16_t max_sock_stack = 0; -- --static inline void thread_bind_stack(struct lwip_sock *sock) --{ -- if (likely(sock->already_bind_numa || !sock->stack)) { -- return; -- } -- sock->already_bind_numa = 1; -- -- if (get_global_cfg_params()->app_bind_numa == 0) { -- return; -- } -- -- stack_sock_num[sock->stack->stack_idx]++; -- if (stack_sock_num[sock->stack->stack_idx] > max_sock_stack) { -- max_sock_stack = stack_sock_num[sock->stack->stack_idx]; -- bind_to_stack_numa(sock->stack); -- } --} -- - ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t flags, - const struct sockaddr *addr, socklen_t addrlen) - { -+ struct lwip_sock *sock; - ssize_t send = 0; -- -+ - if (buf == NULL) { - GAZELLE_RETURN(EINVAL); - } -- - if (addr && addr->sa_family != AF_INET && addr->sa_family != AF_INET6) { - GAZELLE_RETURN(EINVAL); - } -- -- struct lwip_sock *sock = lwip_get_socket(fd); - -- thread_bind_stack(sock); -+ sock = lwip_get_socket(fd); -+ if (unlikely(sock->already_bind_numa == 0 && sock->stack)) { -+ thread_bind_stack(sock->stack); -+ sock->already_bind_numa = 1; -+ } - - if (sock->same_node_tx_ring != NULL) { - return gazelle_same_node_ring_send(sock, buf, len, flags); -@@ -1131,7 +1109,10 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - return -1; - } - -- thread_bind_stack(sock); -+ if (unlikely(sock->already_bind_numa == 0 && sock->stack)) { -+ thread_bind_stack(sock->stack); -+ sock->already_bind_numa = 1; -+ } - - if (sock->same_node_rx_ring != NULL) { - return gazelle_same_node_ring_recv(sock, buf, len, flags); -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index f56e911..bcca1a7 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -22,14 +22,12 @@ - #include - - #include "common/gazelle_base_func.h" --#include "lstack_thread_rpc.h" - #include "common/dpdk_common.h" - #include "lstack_log.h" -+#include "lstack_cfg.h" - #include "lstack_dpdk.h" - #include "lstack_ethdev.h" --#include "lstack_vdev.h" - #include "lstack_lwip.h" --#include "lstack_cfg.h" - #include "lstack_control_plane.h" - #include "lstack_epoll.h" - #include "lstack_stack_stat.h" -@@ -64,18 +62,6 @@ static void stack_wait_quit(struct protocol_stack *stack) - } - } - --void bind_to_stack_numa(struct protocol_stack *stack) --{ -- int32_t ret; -- pthread_t tid = pthread_self(); -- -- 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); -- return; -- } --} -- - static inline void set_stack_idx(uint16_t idx) - { - g_stack_p = g_stack_group.stacks[idx]; -@@ -97,27 +83,6 @@ struct protocol_stack_group *get_protocol_stack_group(void) - return &g_stack_group; - } - --int get_min_conn_stack(struct protocol_stack_group *stack_group) --{ -- int min_conn_stk_idx = 0; -- int min_conn_num = GAZELLE_MAX_CLIENTS; -- for (int 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) { -- 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; -- } -- } -- } -- return min_conn_stk_idx; --} -- - struct protocol_stack *get_protocol_stack(void) - { - return g_stack_p; -@@ -179,6 +144,57 @@ struct protocol_stack *get_bind_protocol_stack(void) - return stack_group->stacks[index]; - } - -+int get_min_conn_stack(struct protocol_stack_group *stack_group) -+{ -+ struct protocol_stack* stack; -+ int min_conn_stk_idx = 0; -+ int min_conn_num = GAZELLE_MAX_CLIENTS; -+ -+ 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; -+ } -+ } -+ } -+ return min_conn_stk_idx; -+} -+ -+void bind_to_stack_numa(struct protocol_stack *stack) -+{ -+ int32_t ret; -+ pthread_t tid = pthread_self(); -+ -+ 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); -+ return; -+ } -+} -+ -+void thread_bind_stack(struct protocol_stack *stack) -+{ -+ static PER_THREAD uint16_t stack_sock_num[GAZELLE_MAX_STACK_NUM] = {0}; -+ static PER_THREAD uint16_t max_sock_stack = 0; -+ -+ if (get_global_cfg_params()->app_bind_numa == 0) { -+ return; -+ } -+ -+ stack_sock_num[stack->stack_idx]++; -+ if (stack_sock_num[stack->stack_idx] > max_sock_stack) { -+ max_sock_stack = stack_sock_num[stack->stack_idx]; -+ bind_to_stack_numa(stack); -+ } -+} -+ - static uint32_t get_protocol_traffic(struct protocol_stack *stack) - { - if (use_ltran()) { -@@ -232,6 +248,11 @@ void low_power_idling(struct protocol_stack *stack) - } - } - -+struct thread_params { -+ uint16_t queue_id; -+ uint16_t idx; -+}; -+ - static int32_t create_thread(void *arg, char *thread_name, stack_thread_func func) - { - /* thread may run slow, if arg is temp var maybe have relese */ -@@ -373,7 +394,7 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) - return 0; - } - --void wait_sem_value(sem_t *sem, int32_t wait_value) -+static void wait_sem_value(sem_t *sem, int32_t wait_value) - { - int32_t sem_val; - do { -@@ -546,7 +567,7 @@ static void* gazelle_stack_thread(void *arg) - return NULL; - } - --int32_t stack_group_init_mempool(void) -+static int stack_group_init_mempool(void) - { - struct cfg_params *cfg_params = get_global_cfg_params(); - uint32_t total_mbufs = 0; -@@ -702,655 +723,9 @@ OUT2: - return -1; - } - --void stack_arp(struct rpc_msg *msg) --{ -- struct rte_mbuf *mbuf = (struct rte_mbuf *)msg->args[MSG_ARG_0].p; -- struct protocol_stack *stack = get_protocol_stack(); -- -- eth_dev_recv(mbuf, stack); --} -- --void stack_socket(struct rpc_msg *msg) --{ -- msg->result = lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); -- if (msg->result < 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, %ld socket failed\n", get_stack_tid(), msg->result); -- } --} -- --void stack_close(struct rpc_msg *msg) --{ -- int32_t fd = msg->args[MSG_ARG_0].i; -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct lwip_sock *sock = lwip_get_socket(fd); -- -- if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { -- msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); /* until stack_send recall finish */ -- return; -- } -- -- msg->result = lwip_close(fd); -- if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); -- } --} -- --void stack_shutdown(struct rpc_msg *msg) --{ -- int fd = msg->args[MSG_ARG_0].i; -- int how = msg->args[MSG_ARG_1].i; -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- struct lwip_sock *sock = lwip_get_socket(fd); -- -- if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { -- msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); -- return; -- } -- -- msg->result = lwip_shutdown(fd, how); -- if (msg->result != 0 && errno != ENOTCONN) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d fail %ld\n", get_stack_tid(), fd, msg->result); -- } -- -- posix_api->shutdown_fn(fd, how); --} -- --void stack_bind(struct rpc_msg *msg) --{ -- msg->result = lwip_bind(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].cp, msg->args[MSG_ARG_2].socklen); -- if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); -- } --} -- --void stack_listen(struct rpc_msg *msg) --{ -- int32_t fd = msg->args[MSG_ARG_0].i; -- int32_t backlog = msg->args[MSG_ARG_1].i; -- -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- msg->result = -1; -- return; -- } -- -- /* new listen add to stack listen list */ -- msg->result = lwip_listen(fd, backlog); -- if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); -- } --} -- --void stack_accept(struct rpc_msg *msg) --{ -- int32_t fd = msg->args[MSG_ARG_0].i; -- msg->result = -1; -- struct protocol_stack *stack = get_protocol_stack(); -- -- int32_t accept_fd = lwip_accept4(fd, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].p, msg->args[MSG_ARG_3].i); -- if (accept_fd < 0) { -- stack->stats.accept_fail++; -- LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); -- return; -- } -- -- struct lwip_sock *sock = lwip_get_socket(accept_fd); -- if (sock == NULL || sock->stack == NULL) { -- lwip_close(accept_fd); -- LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); -- return; -- } -- -- msg->result = accept_fd; -- sock->stack->conn_num++; -- if (rte_ring_count(sock->conn->recvmbox->ring)) { -- do_lwip_add_recvlist(accept_fd); -- } --} -- --void stack_connect(struct rpc_msg *msg) --{ -- msg->result = lwip_connect(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].socklen); -- if (msg->result < 0) { -- msg->result = -errno; -- } --} -- --void stack_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); -- } --} -- --void stack_getsockname(struct rpc_msg *msg) --{ -- msg->result = lwip_getsockname(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); -- } --} -- --void stack_getsockopt(struct rpc_msg *msg) --{ -- msg->result = lwip_getsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, -- msg->args[MSG_ARG_3].p, msg->args[MSG_ARG_4].p); -- if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d, level %d, optname %d, fail %ld\n", get_stack_tid(), -- msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); -- } --} -- --void stack_setsockopt(struct rpc_msg *msg) --{ -- msg->result = lwip_setsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, -- msg->args[MSG_ARG_3].cp, msg->args[MSG_ARG_4].socklen); -- if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d, level %d, optname %d, fail %ld\n", get_stack_tid(), -- msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); -- } --} -- --void stack_fcntl(struct rpc_msg *msg) --{ -- msg->result = lwip_fcntl(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].l); -- 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); -- } --} -- --void stack_ioctl(struct rpc_msg *msg) --{ -- msg->result = lwip_ioctl(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].l, 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); -- } --} -- --void stack_recv(struct rpc_msg *msg) --{ -- msg->result = lwip_recv(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].size, -- msg->args[MSG_ARG_3].i); --} -- --void stack_tcp_send(struct rpc_msg *msg) --{ -- int32_t fd = msg->args[MSG_ARG_0].i; -- size_t len = msg->args[MSG_ARG_1].size; -- struct protocol_stack *stack = get_protocol_stack(); -- int replenish_again; -- -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (POSIX_IS_CLOSED(sock)) { -- msg->result = -1; -- return; -- } -- -- if (get_protocol_stack_group()->latency_start) { -- calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_WRITE_RPC_MSG); -- } -- -- replenish_again = do_lwip_send(stack, sock->conn->callback_arg.socket, sock, len, 0); -- if (replenish_again < 0) { -- __sync_fetch_and_sub(&sock->call_num, 1); -- return; -- } -- -- if (NETCONN_IS_DATAOUT(sock) || replenish_again > 0) { -- if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1) { -- msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); -- return; -- } -- } -- -- __sync_fetch_and_sub(&sock->call_num, 1); -- return; --} -- --void stack_udp_send(struct rpc_msg *msg) --{ -- int32_t fd = msg->args[MSG_ARG_0].i; -- size_t len = msg->args[MSG_ARG_1].size; -- struct protocol_stack *stack = get_protocol_stack(); -- int replenish_again; -- -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (POSIX_IS_CLOSED(sock)) { -- msg->result = -1; -- return; -- } -- -- if (get_protocol_stack_group()->latency_start) { -- calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_WRITE_RPC_MSG); -- } -- -- replenish_again = do_lwip_send(stack, sock->conn->callback_arg.socket, sock, len, 0); -- if ((replenish_again > 0) && (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1)) { -- rpc_call_replenish(&stack->rpc_queue, sock); -- return; -- } -- -- __sync_fetch_and_sub(&sock->call_num, 1); -- return; --} -- --/* any protocol stack thread receives arp packet and sync it to other threads so that it can have the arp table */ --void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack) --{ -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- struct rte_mbuf *mbuf_copy = NULL; -- struct protocol_stack *stack = NULL; -- int32_t ret; -- -- for (int32_t i = 0; i < stack_group->stack_num; i++) { -- stack = stack_group->stacks[i]; -- if (cur_stack == stack) { -- continue; -- } -- -- /* stack maybe not init in app thread yet */ -- if (stack == NULL || !(netif_is_up(&stack->netif))) { -- continue; -- } -- -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -- if (ret != 0) { -- stack->stats.rx_allocmbuf_fail++; -- return; -- } -- copy_mbuf(mbuf_copy, mbuf); -- -- ret = rpc_call_arp(&stack->rpc_queue, mbuf_copy); -- if (ret != 0) { -- rte_pktmbuf_free(mbuf_copy); -- return; -- } -- } --#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) -- if (get_global_cfg_params()->kni_switch) { -- ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -- if (ret != 0) { -- cur_stack->stats.rx_allocmbuf_fail++; -- return; -- } -- copy_mbuf(mbuf_copy, mbuf); -- kni_handle_tx(mbuf_copy); -- } --#endif -- if (get_global_cfg_params()->flow_bifurcation) { -- ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -- if (ret != 0) { -- cur_stack->stats.rx_allocmbuf_fail++; -- return; -- } -- copy_mbuf(mbuf_copy, mbuf); -- virtio_tap_process_tx(cur_stack->queue_id, mbuf_copy); -- } -- return; --} -- --void stack_broadcast_clean_epoll(struct wakeup_poll *wakeup) --{ -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- struct protocol_stack *stack = NULL; -- -- for (int32_t i = 0; i < stack_group->stack_num; i++) { -- stack = stack_group->stacks[i]; -- rpc_call_clean_epoll(&stack->rpc_queue, wakeup); -- } --} -- --void stack_clean_epoll(struct rpc_msg *msg) --{ -- struct protocol_stack *stack = get_protocol_stack(); -- struct wakeup_poll *wakeup = (struct wakeup_poll *)msg->args[MSG_ARG_0].p; -- -- list_del_node(&wakeup->wakeup_list[stack->stack_idx]); --} -- --void stack_mempool_size(struct rpc_msg *msg) --{ -- struct protocol_stack *stack = get_protocol_stack(); -- -- msg->result = rte_mempool_avail_count(stack->rxtx_mbuf_pool); --} -- --void stack_create_shadow_fd(struct rpc_msg *msg) --{ -- int32_t fd = msg->args[MSG_ARG_0].i; -- struct sockaddr *addr = msg->args[MSG_ARG_1].p; -- socklen_t addr_len = msg->args[MSG_ARG_2].socklen; -- -- int32_t clone_fd = 0; -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d\n", fd); -- msg->result = -1; -- return; -- } -- -- int domain = addr->sa_family; -- int type = NETCONN_IS_UDP(sock) ? SOCK_DGRAM : SOCK_STREAM; -- clone_fd = lwip_socket(domain, type, 0); -- if (clone_fd < 0) { -- LSTACK_LOG(ERR, LSTACK, "clone socket failed clone_fd=%d errno=%d\n", clone_fd, errno); -- msg->result = clone_fd; -- return; -- } -- -- struct lwip_sock *clone_sock = lwip_get_socket(clone_fd); -- if (clone_sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d clone_fd=%d\n", fd, clone_fd); -- msg->result = -1; -- return; -- } -- -- do_lwip_clone_sockopt(clone_sock, sock); -- -- while (sock->listen_next) { -- sock = sock->listen_next; -- } -- sock->listen_next = clone_sock; -- -- int32_t ret = lwip_bind(clone_fd, addr, addr_len); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "clone bind failed clone_fd=%d errno=%d\n", clone_fd, errno); -- msg->result = ret; -- return; -- } -- -- msg->result = clone_fd; --} -- --void stack_replenish_sendring(struct rpc_msg *msg) --{ -- struct protocol_stack *stack = get_protocol_stack(); -- struct lwip_sock *sock = (struct lwip_sock *)msg->args[MSG_ARG_0].p; -- -- msg->result = do_lwip_replenish_sendring(stack, sock); -- if (msg->result == true) { -- msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); -- } --} -- --void stack_get_conntable(struct rpc_msg *msg) --{ -- struct gazelle_stat_lstack_conn_info *conn = (struct gazelle_stat_lstack_conn_info *)msg->args[MSG_ARG_0].p; -- uint32_t max_num = msg->args[MSG_ARG_1].u; -- -- msg->result = do_lwip_get_conntable(conn, max_num); --} -- --void stack_get_connnum(struct rpc_msg *msg) --{ -- msg->result = do_lwip_get_connnum(); --} -- --void stack_recvlist_count(struct rpc_msg *msg) --{ -- struct protocol_stack *stack = get_protocol_stack(); -- struct list_node *list = &stack->recv_list; -- uint32_t count = 0; -- struct list_node *node; -- struct list_node *temp; -- -- list_for_each_node(node, temp, list) { -- count++; -- } -- -- msg->result = count; --} -- --/* when fd is listenfd, listenfd of all protocol stack thread will be closed */ --int32_t stack_broadcast_close(int32_t fd) --{ -- int32_t ret = 0; -- struct lwip_sock *sock = lwip_get_socket(fd); -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- -- do { -- sock = sock->listen_next; -- if (stack == NULL || rpc_call_close(&stack->rpc_queue, fd)) { -- ret = -1; -- } -- -- if (POSIX_IS_CLOSED(sock)) { -- break; -- } -- fd = sock->conn->callback_arg.socket; -- stack = get_protocol_stack_by_fd(fd); -- } while (1); -- -- return ret; --} -- --int stack_broadcast_shutdown(int fd, int how) --{ -- int32_t ret = 0; -- struct lwip_sock *sock = lwip_get_socket(fd); -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- -- do { -- sock = sock->listen_next; -- if (stack == NULL || rpc_call_shutdown(&stack->rpc_queue, fd, how)) { -- ret = -1; -- } -- -- if (POSIX_IS_CLOSED(sock)) { -- break; -- } -- fd = sock->conn->callback_arg.socket; -- stack = get_protocol_stack_by_fd(fd); -- } while (1); -- -- return ret; --} -- --/* choice one stack listen */ --int32_t stack_single_listen(int32_t fd, int32_t backlog) --{ -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- if (stack == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- return rpc_call_listen(&stack->rpc_queue, fd, backlog); --} -- --/* listen sync to all protocol stack thread, so that any protocol stack thread can build connect */ --int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) --{ -- typedef union sockaddr_union { -- struct sockaddr sa; -- struct sockaddr_in in; -- struct sockaddr_in6 in6; -- } sockaddr_t; -- -- struct protocol_stack *cur_stack = get_protocol_stack_by_fd(fd); -- struct protocol_stack *stack = NULL; -- sockaddr_t addr; -- socklen_t addr_len = sizeof(addr); -- int32_t ret, clone_fd; -- -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL || cur_stack == NULL) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); -- GAZELLE_RETURN(EBADF); -- } -- -- ret = rpc_call_getsockname(&cur_stack->rpc_queue, fd, (struct sockaddr *)&addr, &addr_len); -- if (ret != 0) { -- return ret; -- } -- -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- int min_conn_stk_idx = get_min_conn_stack(stack_group); -- -- 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) { -- stack_broadcast_close(fd); -- return clone_fd; -- } -- } else { -- clone_fd = fd; -- } -- -- if (min_conn_stk_idx == i) { -- lwip_get_socket(clone_fd)->conn->is_master_fd = 1; -- } else { -- lwip_get_socket(clone_fd)->conn->is_master_fd = 0; -- } -- -- ret = rpc_call_listen(&stack->rpc_queue, clone_fd, backlog); -- if (ret < 0) { -- stack_broadcast_close(fd); -- return ret; -- } -- } -- return 0; --} -- --static struct lwip_sock *get_min_accept_sock(int32_t fd) --{ -- struct lwip_sock *sock = lwip_get_socket(fd); -- struct lwip_sock *min_sock = NULL; -- -- while (sock) { -- if (!NETCONN_IS_ACCEPTIN(sock)) { -- sock = sock->listen_next; -- continue; -- } -- -- if (min_sock == NULL || min_sock->stack->conn_num > sock->stack->conn_num) { -- min_sock = sock; -- } -- -- sock = sock->listen_next; -- } -- -- return min_sock; --} -- --static void inline del_accept_in_event(struct lwip_sock *sock) --{ -- pthread_spin_lock(&sock->wakeup->event_list_lock); -- -- if (!NETCONN_IS_ACCEPTIN(sock)) { -- sock->events &= ~EPOLLIN; -- if (sock->events == 0) { -- list_del_node(&sock->event_list); -- } -- } -- -- pthread_spin_unlock(&sock->wakeup->event_list_lock); --} -- --/* choice one stack bind */ --int32_t stack_single_bind(int32_t fd, const struct sockaddr *name, socklen_t namelen) --{ -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- if (stack == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- return rpc_call_bind(&stack->rpc_queue, fd, name, namelen); --} -- --/* bind sync to all protocol stack thread, so that any protocol stack thread can build connect */ --int32_t stack_broadcast_bind(int32_t fd, const struct sockaddr *name, socklen_t namelen) --{ -- struct protocol_stack *cur_stack = get_protocol_stack_by_fd(fd); -- struct protocol_stack *stack = NULL; -- int32_t ret, clone_fd; -- -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL || cur_stack == NULL) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); -- GAZELLE_RETURN(EBADF); -- } -- -- ret = rpc_call_bind(&cur_stack->rpc_queue, fd, name, namelen); -- if (ret < 0) { -- close(fd); -- return ret; -- } -- -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- for (int32_t i = 0; i < stack_group->stack_num; ++i) { -- stack = stack_group->stacks[i]; -- if (stack != cur_stack) { -- clone_fd = rpc_call_shadow_fd(&stack->rpc_queue, fd, name, namelen); -- if (clone_fd < 0) { -- stack_broadcast_close(fd); -- return clone_fd; -- } -- } -- } -- return 0; --} -- --/* ergodic the protocol stack thread to find the connection, because all threads are listening */ --int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *addrlen, int flags) --{ -- int32_t ret = -1; -- struct lwip_sock *min_sock = NULL; -- struct lwip_sock *sock = lwip_get_socket(fd); -- struct protocol_stack *stack = NULL; -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- -- if (netconn_is_nonblocking(sock->conn)) { -- min_sock = get_min_accept_sock(fd); -- } else { -- while ((min_sock = get_min_accept_sock(fd)) == NULL) { -- lstack_block_wait(sock->wakeup, 0); -- } -- } -- -- if (min_sock && min_sock->conn) { -- stack = get_protocol_stack_by_fd(min_sock->conn->callback_arg.socket); -- if (stack == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- ret = rpc_call_accept(&stack->rpc_queue, min_sock->conn->callback_arg.socket, addr, addrlen, flags); -- } -- -- if (min_sock && min_sock->wakeup && min_sock->wakeup->type == WAKEUP_EPOLL) { -- del_accept_in_event(min_sock); -- } -- -- if (ret < 0) { -- errno = EAGAIN; -- } -- return ret; --} -- --int32_t stack_broadcast_accept(int32_t 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); --} -- --static void stack_all_fds_close(void) -+void stack_exit(void) - { -+ /* close all fd */ - for (int i = 3; i < GAZELLE_MAX_CLIENTS + GAZELLE_RESERVED_CLIENTS; i++) { - struct lwip_sock *sock = lwip_get_socket(i); - if (!POSIX_IS_CLOSED(sock) && sock->stack == get_protocol_stack()) { -@@ -1359,16 +734,6 @@ static void stack_all_fds_close(void) - } - } - --static void stack_exit(void) --{ -- stack_all_fds_close(); --} -- --void stack_exit_by_rpc(struct rpc_msg *msg) --{ -- stack_exit(); --} -- - void stack_group_exit(void) - { - int i; -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 8ac06cb..3e9889a 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -13,22 +13,27 @@ - #include - #include - -+#include "lwip/lwipgz_posix_api.h" -+ - #include "lstack_log.h" - #include "lstack_cfg.h" - #include "lstack_dpdk.h" --#include "lstack_rpc_proc.h" - #include "lstack_stack_stat.h" - #include "lstack_protocol_stack.h" - #include "lstack_thread_rpc.h" -+#include "lstack_epoll.h" -+#include "lstack_lwip.h" - - static PER_THREAD struct rpc_msg_pool *g_rpc_pool = NULL; - static struct rpc_stats g_rpc_stats; -+ - struct rpc_stats *rpc_stats_get(void) - { - return &g_rpc_stats; - } - --static inline __attribute__((always_inline)) struct rpc_msg *get_rpc_msg(struct rpc_msg_pool *rpc_pool) -+__rte_always_inline -+static struct rpc_msg *get_rpc_msg(struct rpc_msg_pool *rpc_pool) - { - int ret; - struct rpc_msg *msg = NULL; -@@ -42,23 +47,11 @@ static inline __attribute__((always_inline)) struct rpc_msg *get_rpc_msg(struct - - static void rpc_msg_init(struct rpc_msg *msg, rpc_msg_func func, struct rpc_msg_pool *pool) - { -- msg->rpcpool = pool; -- pthread_spin_init(&msg->lock, PTHREAD_PROCESS_PRIVATE); -- msg->func = func; -- msg->sync_flag = 1; -+ msg->func = func; -+ msg->rpcpool = pool; -+ msg->sync_flag = 1; - msg->recall_flag = 0; --} -- --static struct rpc_msg *rpc_msg_alloc_except(rpc_msg_func func) --{ -- struct rpc_msg *msg = calloc(1, sizeof(struct rpc_msg)); -- if (msg == NULL) { -- return NULL; -- } -- -- rpc_msg_init(msg, func, NULL); -- -- return msg; -+ pthread_spin_init(&msg->lock, PTHREAD_PROCESS_PRIVATE); - } - - static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func) -@@ -92,9 +85,27 @@ static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func) - return msg; - } - --static inline __attribute__((always_inline)) int32_t rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg) -+__rte_always_inline -+static void rpc_msg_free(struct rpc_msg *msg) -+{ -+ pthread_spin_destroy(&msg->lock); -+ if (msg->rpcpool != NULL && msg->rpcpool->mempool != NULL) { -+ rte_mempool_put(msg->rpcpool->mempool, (void *)msg); -+ } else { -+ free(msg); -+ } -+} -+ -+__rte_always_inline -+static void rpc_call(rpc_queue *queue, struct rpc_msg *msg) - { -- int32_t ret; -+ lockless_queue_mpsc_push(queue, &msg->queue_node); -+} -+ -+__rte_always_inline -+static int rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg) -+{ -+ int ret; - - pthread_spin_trylock(&msg->lock); - rpc_call(queue, msg); -@@ -107,12 +118,39 @@ static inline __attribute__((always_inline)) int32_t rpc_sync_call(rpc_queue *qu - return ret; - } - --int32_t rpc_msgcnt(rpc_queue *queue) -+int rpc_msgcnt(rpc_queue *queue) - { - return lockless_queue_count(queue); - } - --int rpc_poll_msg(rpc_queue *queue, uint32_t max_num) -+static struct rpc_msg *rpc_msg_alloc_except(rpc_msg_func func) -+{ -+ struct rpc_msg *msg = calloc(1, sizeof(struct rpc_msg)); -+ if (msg == NULL) { -+ return NULL; -+ } -+ -+ rpc_msg_init(msg, func, NULL); -+ return msg; -+} -+ -+static void stack_exit_by_rpc(struct rpc_msg *msg) -+{ -+ stack_exit(); -+} -+ -+int rpc_call_stack_exit(rpc_queue *queue) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc_except(stack_exit_by_rpc); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ rpc_call(queue, msg); -+ return 0; -+} -+ -+int rpc_poll_msg(rpc_queue *queue, int max_num) - { - int force_quit = 0; - struct rpc_msg *msg = NULL; -@@ -149,101 +187,165 @@ int rpc_poll_msg(rpc_queue *queue, uint32_t max_num) - return force_quit; - } - --int32_t rpc_call_conntable(rpc_queue *queue, void *conn_table, uint32_t max_conn) -+ -+static void callback_socket(struct rpc_msg *msg) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_get_conntable); -- if (msg == NULL) { -- return -1; -+ msg->result = lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); -+ if (msg->result < 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, %ld socket failed\n", get_stack_tid(), msg->result); - } -- -- msg->args[MSG_ARG_0].p = conn_table; -- msg->args[MSG_ARG_1].u = max_conn; -- -- return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_connnum(rpc_queue *queue) -+static void callback_close(struct rpc_msg *msg) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_get_connnum); -- if (msg == NULL) { -- return -1; -+ int fd = msg->args[MSG_ARG_0].i; -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ -+ if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { -+ msg->recall_flag = 1; -+ rpc_call(&stack->rpc_queue, msg); /* until stack_send recall finish */ -+ return; - } - -- return rpc_sync_call(queue, msg); -+ msg->result = lwip_close(fd); -+ if (msg->result != 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); -+ } - } - --int32_t rpc_call_shadow_fd(rpc_queue *queue, int32_t fd, const struct sockaddr *addr, socklen_t addrlen) -+static void callback_shutdown(struct rpc_msg *msg) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_create_shadow_fd); -- if (msg == NULL) { -- return -1; -+ int fd = msg->args[MSG_ARG_0].i; -+ int how = msg->args[MSG_ARG_1].i; -+ struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ -+ if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { -+ msg->recall_flag = 1; -+ rpc_call(&stack->rpc_queue, msg); -+ return; - } - -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].cp = addr; -- msg->args[MSG_ARG_2].socklen = addrlen; -+ msg->result = lwip_shutdown(fd, how); -+ if (msg->result != 0 && errno != ENOTCONN) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d fail %ld\n", get_stack_tid(), fd, msg->result); -+ } - -- return rpc_sync_call(queue, msg); -+ posix_api->shutdown_fn(fd, how); - } - --int32_t rpc_call_thread_regphase1(rpc_queue *queue, void *conn) -+static void callback_bind(struct rpc_msg *msg) - { -- struct rpc_msg *msg = rpc_msg_alloc(thread_register_phase1); -- if (msg == NULL) { -- return -1; -+ msg->result = lwip_bind(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].cp, msg->args[MSG_ARG_2].socklen); -+ if (msg->result != 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); - } -- msg->args[MSG_ARG_0].p = conn; -- return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_thread_regphase2(rpc_queue *queue, void *conn) -+static void callback_listen(struct rpc_msg *msg) - { -- struct rpc_msg *msg = rpc_msg_alloc(thread_register_phase2); -- if (msg == NULL) { -- return -1; -+ int fd = msg->args[MSG_ARG_0].i; -+ int backlog = msg->args[MSG_ARG_1].i; -+ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL) { -+ msg->result = -1; -+ return; -+ } -+ -+ /* new listen add to stack listen list */ -+ msg->result = lwip_listen(fd, backlog); -+ if (msg->result != 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); - } -- msg->args[MSG_ARG_0].p = conn; -- return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_mbufpoolsize(rpc_queue *queue) -+static void callback_create_shadow_fd(struct rpc_msg *msg) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_mempool_size); -- if (msg == NULL) { -- return -1; -+ int fd = msg->args[MSG_ARG_0].i; -+ struct sockaddr *addr = msg->args[MSG_ARG_1].p; -+ socklen_t addr_len = msg->args[MSG_ARG_2].socklen; -+ -+ int clone_fd = 0; -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d\n", fd); -+ msg->result = -1; -+ return; - } - -- return rpc_sync_call(queue, msg); --} -+ int domain = addr->sa_family; -+ int type = NETCONN_IS_UDP(sock) ? SOCK_DGRAM : SOCK_STREAM; -+ clone_fd = lwip_socket(domain, type, 0); -+ if (clone_fd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "clone socket failed clone_fd=%d errno=%d\n", clone_fd, errno); -+ msg->result = clone_fd; -+ return; -+ } - --int32_t rpc_call_recvlistcnt(rpc_queue *queue) --{ -- struct rpc_msg *msg = rpc_msg_alloc(stack_recvlist_count); -- if (msg == NULL) { -- return -1; -+ struct lwip_sock *clone_sock = lwip_get_socket(clone_fd); -+ if (clone_sock == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d clone_fd=%d\n", fd, clone_fd); -+ msg->result = -1; -+ return; - } - -- return rpc_sync_call(queue, msg); -+ do_lwip_clone_sockopt(clone_sock, sock); -+ -+ while (sock->listen_next) { -+ sock = sock->listen_next; -+ } -+ sock->listen_next = clone_sock; -+ -+ int ret = lwip_bind(clone_fd, addr, addr_len); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "clone bind failed clone_fd=%d errno=%d\n", clone_fd, errno); -+ msg->result = ret; -+ return; -+ } -+ -+ msg->result = clone_fd; - } - --int32_t rpc_call_arp(rpc_queue *queue, void *mbuf) -+static void callback_accept(struct rpc_msg *msg) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_arp); -- if (msg == NULL) { -- return -1; -+ int fd = msg->args[MSG_ARG_0].i; -+ msg->result = -1; -+ struct protocol_stack *stack = get_protocol_stack(); -+ -+ int accept_fd = lwip_accept4(fd, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].p, msg->args[MSG_ARG_3].i); -+ if (accept_fd < 0) { -+ stack->stats.accept_fail++; -+ LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); -+ return; - } - -- msg->sync_flag = 0; -- msg->args[MSG_ARG_0].p = mbuf; -+ struct lwip_sock *sock = lwip_get_socket(accept_fd); -+ if (sock == NULL || sock->stack == NULL) { -+ lwip_close(accept_fd); -+ LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); -+ return; -+ } - -- rpc_call(queue, msg); -+ msg->result = accept_fd; -+ sock->stack->conn_num++; -+ if (rte_ring_count(sock->conn->recvmbox->ring)) { -+ do_lwip_add_recvlist(accept_fd); -+ } -+} - -- return 0; -+static void callback_connect(struct rpc_msg *msg) -+{ -+ msg->result = lwip_connect(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].socklen); -+ if (msg->result < 0) { -+ msg->result = -errno; -+ } - } - --int32_t rpc_call_socket(rpc_queue *queue, int32_t domain, int32_t type, int32_t protocol) -+int rpc_call_socket(rpc_queue *queue, int domain, int type, int protocol) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_socket); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_socket); - if (msg == NULL) { - return -1; - } -@@ -255,9 +357,9 @@ int32_t rpc_call_socket(rpc_queue *queue, int32_t domain, int32_t type, int32_t - return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_close(rpc_queue *queue, int fd) -+int rpc_call_close(rpc_queue *queue, int fd) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_close); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_close); - if (msg == NULL) { - return -1; - } -@@ -267,20 +369,9 @@ int32_t rpc_call_close(rpc_queue *queue, int fd) - return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_stack_exit(rpc_queue *queue) -+int rpc_call_shutdown(rpc_queue *queue, int fd, int how) - { -- struct rpc_msg *msg = rpc_msg_alloc_except(stack_exit_by_rpc); -- if (msg == NULL) { -- return -1; -- } -- -- rpc_call(queue, msg); -- return 0; --} -- --int32_t rpc_call_shutdown(rpc_queue *queue, int fd, int how) --{ -- struct rpc_msg *msg = rpc_msg_alloc(stack_shutdown); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_shutdown); - if (msg == NULL) { - return -1; - } -@@ -291,48 +382,50 @@ int32_t rpc_call_shutdown(rpc_queue *queue, int fd, int how) - return rpc_sync_call(queue, msg); - } - --void rpc_call_clean_epoll(rpc_queue *queue, void *wakeup) -+int rpc_call_bind(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_clean_epoll); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_bind); - if (msg == NULL) { -- return; -+ return -1; - } - -- msg->args[MSG_ARG_0].p = wakeup; -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].cp = addr; -+ msg->args[MSG_ARG_2].socklen = addrlen; - -- rpc_sync_call(queue, msg); -+ return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_bind(rpc_queue *queue, int32_t fd, const struct sockaddr *addr, socklen_t addrlen) -+int rpc_call_listen(rpc_queue *queue, int s, int backlog) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_bind); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_listen); - if (msg == NULL) { - return -1; - } - -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].cp = addr; -- msg->args[MSG_ARG_2].socklen = addrlen; -+ msg->args[MSG_ARG_0].i = s; -+ msg->args[MSG_ARG_1].i = backlog; - - return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_listen(rpc_queue *queue, int s, int backlog) -+int rpc_call_shadow_fd(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_listen); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_create_shadow_fd); - if (msg == NULL) { - return -1; - } - -- msg->args[MSG_ARG_0].i = s; -- msg->args[MSG_ARG_1].i = backlog; -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].cp = addr; -+ msg->args[MSG_ARG_2].socklen = addrlen; - - return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_accept(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen, int flags) -+int rpc_call_accept(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen, int flags) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_accept); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_accept); - if (msg == NULL) { - return -1; - } -@@ -345,9 +438,9 @@ int32_t rpc_call_accept(rpc_queue *queue, int fd, struct sockaddr *addr, socklen - return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen) -+int rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_connect); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_connect); - if (msg == NULL) { - return -1; - } -@@ -356,7 +449,7 @@ int32_t rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, - msg->args[MSG_ARG_1].cp = addr; - msg->args[MSG_ARG_2].socklen = addrlen; - -- int32_t ret = rpc_sync_call(queue, msg); -+ int ret = rpc_sync_call(queue, msg); - if (ret < 0) { - errno = -ret; - return -1; -@@ -364,9 +457,45 @@ int32_t rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, - return ret; - } - --int32_t rpc_call_getpeername(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen) -+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) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_getpeername); -+ msg->result = lwip_getsockname(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_getsockopt(struct rpc_msg *msg) -+{ -+ msg->result = lwip_getsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, -+ msg->args[MSG_ARG_3].p, msg->args[MSG_ARG_4].p); -+ if (msg->result != 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d, level %d, optname %d, fail %ld\n", get_stack_tid(), -+ msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); -+ } -+} -+ -+static void callback_setsockopt(struct rpc_msg *msg) -+{ -+ msg->result = lwip_setsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, -+ msg->args[MSG_ARG_3].cp, msg->args[MSG_ARG_4].socklen); -+ if (msg->result != 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d, level %d, optname %d, fail %ld\n", get_stack_tid(), -+ msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); -+ } -+} -+ -+int rpc_call_getpeername(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(callback_getpeername); - if (msg == NULL) { - return -1; - } -@@ -378,9 +507,9 @@ int32_t rpc_call_getpeername(rpc_queue *queue, int fd, struct sockaddr *addr, so - return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_getsockname(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen) -+int rpc_call_getsockname(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_getsockname); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_getsockname); - if (msg == NULL) { - return -1; - } -@@ -392,9 +521,9 @@ int32_t rpc_call_getsockname(rpc_queue *queue, int fd, struct sockaddr *addr, so - return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_getsockopt(rpc_queue *queue, int fd, int level, int optname, void *optval, socklen_t *optlen) -+int rpc_call_getsockopt(rpc_queue *queue, int fd, int level, int optname, void *optval, socklen_t *optlen) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_getsockopt); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_getsockopt); - if (msg == NULL) { - return -1; - } -@@ -408,9 +537,9 @@ int32_t rpc_call_getsockopt(rpc_queue *queue, int fd, int level, int optname, vo - return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_setsockopt(rpc_queue *queue, int fd, int level, int optname, const void *optval, socklen_t optlen) -+int rpc_call_setsockopt(rpc_queue *queue, int fd, int level, int optname, const void *optval, socklen_t optlen) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_setsockopt); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_setsockopt); - if (msg == NULL) { - return -1; - } -@@ -424,51 +553,91 @@ int32_t rpc_call_setsockopt(rpc_queue *queue, int fd, int level, int optname, co - return rpc_sync_call(queue, msg); - } - --int32_t rpc_call_fcntl(rpc_queue *queue, int fd, int cmd, long val) -+static void callback_tcp_send(struct rpc_msg *msg) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_fcntl); -- if (msg == NULL) { -- return -1; -+ int fd = msg->args[MSG_ARG_0].i; -+ size_t len = msg->args[MSG_ARG_1].size; -+ struct protocol_stack *stack = get_protocol_stack(); -+ int replenish_again; -+ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (POSIX_IS_CLOSED(sock)) { -+ msg->result = -1; -+ return; - } - -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].i = cmd; -- msg->args[MSG_ARG_2].l = val; -+ if (get_protocol_stack_group()->latency_start) { -+ calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_WRITE_RPC_MSG); -+ } - -- return rpc_sync_call(queue, msg); -+ replenish_again = do_lwip_send(stack, sock->conn->callback_arg.socket, sock, len, 0); -+ if (replenish_again < 0) { -+ __sync_fetch_and_sub(&sock->call_num, 1); -+ return; -+ } -+ -+ if (NETCONN_IS_DATAOUT(sock) || replenish_again > 0) { -+ if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1) { -+ msg->recall_flag = 1; -+ rpc_call(&stack->rpc_queue, msg); -+ return; -+ } -+ } -+ -+ __sync_fetch_and_sub(&sock->call_num, 1); -+ return; - } - --int32_t rpc_call_ioctl(rpc_queue *queue, int fd, long cmd, void *argp) -+static void callback_udp_send(struct rpc_msg *msg) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_ioctl); -- if (msg == NULL) { -- return -1; -+ int fd = msg->args[MSG_ARG_0].i; -+ size_t len = msg->args[MSG_ARG_1].size; -+ struct protocol_stack *stack = get_protocol_stack(); -+ int replenish_again; -+ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (POSIX_IS_CLOSED(sock)) { -+ msg->result = -1; -+ return; - } - -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].l = cmd; -- msg->args[MSG_ARG_2].p = argp; -+ if (get_protocol_stack_group()->latency_start) { -+ calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_WRITE_RPC_MSG); -+ } - -- return rpc_sync_call(queue, msg); -+ replenish_again = do_lwip_send(stack, sock->conn->callback_arg.socket, sock, len, 0); -+ if ((replenish_again > 0) && (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1)) { -+ rpc_call_replenish(&stack->rpc_queue, sock); -+ return; -+ } -+ -+ __sync_fetch_and_sub(&sock->call_num, 1); -+ return; - } - --int32_t rpc_call_replenish(rpc_queue *queue, void *sock) -+int rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_replenish_sendring); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_udp_send); - if (msg == NULL) { - return -1; - } - -- msg->args[MSG_ARG_0].p = sock; -+ if (get_protocol_stack_group()->latency_start) { -+ time_stamp_into_rpcmsg(lwip_get_socket(fd)); -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].size = len; -+ msg->args[MSG_ARG_2].i = flags; - msg->sync_flag = 0; - - rpc_call(queue, msg); - return 0; - } - --int32_t rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags) -+int rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_tcp_send); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_tcp_send); - if (msg == NULL) { - return -1; - } -@@ -483,28 +652,173 @@ int32_t rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags) - msg->sync_flag = 0; - - rpc_call(queue, msg); -+ return 0; -+} -+ -+static void callback_replenish_sendring(struct rpc_msg *msg) -+{ -+ struct protocol_stack *stack = get_protocol_stack(); -+ struct lwip_sock *sock = (struct lwip_sock *)msg->args[MSG_ARG_0].p; -+ -+ msg->result = do_lwip_replenish_sendring(stack, sock); -+ if (msg->result == true) { -+ msg->recall_flag = 1; -+ rpc_call(&stack->rpc_queue, msg); -+ } -+} -+ -+int rpc_call_replenish(rpc_queue *queue, void *sock) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(callback_replenish_sendring); -+ if (msg == NULL) { -+ return -1; -+ } - -+ msg->args[MSG_ARG_0].p = sock; -+ msg->sync_flag = 0; -+ -+ rpc_call(queue, msg); - return 0; - } - --int32_t rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags) -+static void callback_recvlist_count(struct rpc_msg *msg) -+{ -+ struct protocol_stack *stack = get_protocol_stack(); -+ struct list_node *list = &stack->recv_list; -+ int count = 0; -+ struct list_node *node; -+ struct list_node *temp; -+ -+ list_for_each_node(node, temp, list) { -+ count++; -+ } -+ msg->result = count; -+} -+ -+int rpc_call_recvlistcnt(rpc_queue *queue) - { -- struct rpc_msg *msg = rpc_msg_alloc(stack_udp_send); -+ struct rpc_msg *msg = rpc_msg_alloc(callback_recvlist_count); - if (msg == NULL) { - return -1; - } - -- if (get_protocol_stack_group()->latency_start) { -- time_stamp_into_rpcmsg(lwip_get_socket(fd)); -+ return rpc_sync_call(queue, msg); -+} -+ -+static void callback_clean_epoll(struct rpc_msg *msg) -+{ -+ struct protocol_stack *stack = get_protocol_stack(); -+ struct wakeup_poll *wakeup = (struct wakeup_poll *)msg->args[MSG_ARG_0].p; -+ -+ list_del_node(&wakeup->wakeup_list[stack->stack_idx]); -+} -+ -+void rpc_call_clean_epoll(rpc_queue *queue, void *wakeup) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(callback_clean_epoll); -+ if (msg == NULL) { -+ return; -+ } -+ -+ msg->args[MSG_ARG_0].p = wakeup; -+ -+ rpc_sync_call(queue, msg); -+} -+ -+static void callback_arp(struct rpc_msg *msg) -+{ -+ struct rte_mbuf *mbuf = (struct rte_mbuf *)msg->args[MSG_ARG_0].p; -+ struct protocol_stack *stack = get_protocol_stack(); -+ -+ eth_dev_recv(mbuf, stack); -+} -+ -+int rpc_call_arp(rpc_queue *queue, void *mbuf) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(callback_arp); -+ if (msg == NULL) { -+ return -1; - } - -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].size = len; -- msg->args[MSG_ARG_2].i = flags; - msg->sync_flag = 0; -+ msg->args[MSG_ARG_0].p = mbuf; - - rpc_call(queue, msg); - - return 0; - } - -+static void callback_mempool_size(struct rpc_msg *msg) -+{ -+ struct protocol_stack *stack = get_protocol_stack(); -+ -+ msg->result = rte_mempool_avail_count(stack->rxtx_mbuf_pool); -+} -+ -+static void callback_get_conntable(struct rpc_msg *msg) -+{ -+ struct gazelle_stat_lstack_conn_info *conn = (struct gazelle_stat_lstack_conn_info *)msg->args[MSG_ARG_0].p; -+ unsigned max_num = msg->args[MSG_ARG_1].u; -+ -+ msg->result = do_lwip_get_conntable(conn, max_num); -+} -+ -+static void callback_get_connnum(struct rpc_msg *msg) -+{ -+ msg->result = do_lwip_get_connnum(); -+} -+ -+int rpc_call_conntable(rpc_queue *queue, void *conn_table, unsigned max_conn) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(callback_get_conntable); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].p = conn_table; -+ msg->args[MSG_ARG_1].u = max_conn; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+int rpc_call_connnum(rpc_queue *queue) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(callback_get_connnum); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+int rpc_call_mbufpoolsize(rpc_queue *queue) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(callback_mempool_size); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+extern void thread_register_phase1(struct rpc_msg *msg); -+int rpc_call_thread_regphase1(rpc_queue *queue, void *conn) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(thread_register_phase1); -+ if (msg == NULL) { -+ return -1; -+ } -+ msg->args[MSG_ARG_0].p = conn; -+ return rpc_sync_call(queue, msg); -+} -+ -+extern void thread_register_phase2(struct rpc_msg *msg); -+int rpc_call_thread_regphase2(rpc_queue *queue, void *conn) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(thread_register_phase2); -+ if (msg == NULL) { -+ return -1; -+ } -+ msg->args[MSG_ARG_0].p = conn; -+ return rpc_sync_call(queue, msg); -+} -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index d058409..965a0cb 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -13,7 +13,10 @@ - #ifndef _GAZELLE_DPDK_H_ - #define _GAZELLE_DPDK_H_ - --#include -+#include -+#include -+#include -+ - #include "common/gazelle_opt.h" - #include "common/gazelle_dfx_msg.h" - -@@ -32,32 +35,34 @@ - */ - #define MBUF_MAX_NUM 0xfffffff - -+struct protocol_stack; -+ -+int32_t dpdk_eal_init(void); -+void lstack_log_level_init(void); -+ -+int dpdk_ethdev_init(int port_id); -+int dpdk_ethdev_start(void); -+int init_dpdk_ethdev(void); -+ - int thread_affinity_default(void); - int thread_affinity_init(int cpu_id); - --struct protocol_stack; --struct rte_mempool; --struct rte_ring; --struct rte_mbuf; -+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); --int32_t dpdk_eal_init(void); - int32_t pktmbuf_pool_init(struct protocol_stack *stack); - struct rte_mempool *create_mempool(const char *name, uint32_t count, uint32_t size, - uint32_t flags, int32_t idx); --int32_t create_shared_ring(struct protocol_stack *stack); --void lstack_log_level_init(void); --int dpdk_ethdev_init(int port_id); --int dpdk_ethdev_start(void); -+struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, -+ uint32_t mbuf_cache_size, uint16_t queue_id, unsigned numa_id); -+int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num, bool reserve); -+ - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - void dpdk_skip_nic_init(void); - void dpdk_restore_pci(void); - #endif - int32_t dpdk_init_lstack_kni(void); --bool port_in_stack_queue(gz_addr_t *src_ip, gz_addr_t *dst_ip, uint16_t src_port, uint16_t dst_port); --struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, -- uint32_t mbuf_cache_size, uint16_t queue_id, unsigned numa_id); - - void dpdk_nic_xstats_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id); --int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num, bool reserve); - void dpdk_nic_features_get(struct gazelle_stack_dfx_data *dfx, uint16_t port_id); -+ - #endif /* GAZELLE_DPDK_H */ -diff --git a/src/lstack/include/lstack_epoll.h b/src/lstack/include/lstack_epoll.h -index 6e02615..e7ae26b 100644 ---- a/src/lstack/include/lstack_epoll.h -+++ b/src/lstack/include/lstack_epoll.h -@@ -19,14 +19,11 @@ - #include - - #include -+#include - - #include "common/gazelle_dfx_msg.h" - #include "common/gazelle_opt.h" - --#ifdef __cplusplus --extern "C" { --#endif -- - enum wakeup_type { - WAKEUP_EPOLL = 0, - WAKEUP_POLL, -@@ -61,9 +58,6 @@ struct wakeup_poll { - pthread_spinlock_t event_list_lock; - }; - --struct netconn; --struct lwip_sock; -- - void add_sock_event(struct lwip_sock *sock, uint32_t event); - void add_sock_event_nolock(struct lwip_sock *sock, uint32_t event); - void del_sock_event(struct lwip_sock *sock, uint32_t event); -@@ -91,8 +85,4 @@ static inline void lstack_block_wakeup(struct wakeup_poll *wakeup) - } - } - --#ifdef __cplusplus --} --#endif -- - #endif /* _GAZELLE_EPOLL_H_ */ -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index b972f11..0c7bb62 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -15,8 +15,12 @@ - #include - - #include "common/gazelle_dfx_msg.h" -+#include "common/dpdk_common.h" - - struct lwip_sock; -+struct rpc_msg; -+struct protocol_stack; -+ - unsigned same_node_ring_count(struct lwip_sock *sock); - - #define NETCONN_IS_ACCEPTIN(sock) (((sock)->conn->acceptmbox != NULL) && !sys_mbox_empty((sock)->conn->acceptmbox)) -@@ -25,11 +29,6 @@ unsigned same_node_ring_count(struct lwip_sock *sock); - #define NETCONN_IS_OUTIDLE(sock) gazelle_ring_readable_count((sock)->send_ring) - #define NETCONN_IS_UDP(sock) (NETCONNTYPE_GROUP(netconn_type((sock)->conn)) == NETCONN_UDP) - --struct rte_mempool; --struct rpc_msg; --struct rte_mbuf; --struct protocol_stack; -- - void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock); - - struct pbuf *do_lwip_tcp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size); -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 7dce757..fdd5388 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -17,6 +17,10 @@ - #include - #include - -+#include -+#include -+#include -+ - #include - #include - -@@ -35,10 +39,6 @@ - - #define MBUFPOOL_RESERVE_NUM (get_global_cfg_params()->nic.rxqueue_size + 1024) - --struct rte_mempool; --struct rte_ring; --struct rte_mbuf; -- - struct protocol_stack { - uint32_t tid; - uint16_t queue_id; -@@ -111,50 +111,23 @@ struct protocol_stack_group { - }; - - long get_stack_tid(void); -+ - struct protocol_stack *get_protocol_stack(void); - struct protocol_stack *get_protocol_stack_by_fd(int32_t fd); - struct protocol_stack *get_bind_protocol_stack(void); - struct protocol_stack_group *get_protocol_stack_group(void); - -+int get_min_conn_stack(struct protocol_stack_group *stack_group); -+void bind_to_stack_numa(struct protocol_stack *stack); -+void thread_bind_stack(struct protocol_stack *stack); -+ - int32_t stack_group_init(void); - void stack_group_exit(void); -+void stack_exit(void); -+ - int32_t stack_setup_thread(void); - int32_t stack_setup_app_thread(void); - --void bind_to_stack_numa(struct protocol_stack *stack); --int32_t init_dpdk_ethdev(void); -- --void wait_sem_value(sem_t *sem, int32_t wait_value); -- --/* any protocol stack thread receives arp packet and sync it to other threads so that it can have the arp table */ --void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack); -- --/* when fd is listenfd, listenfd of all protocol stack thread will be closed */ --int32_t stack_broadcast_close(int32_t fd); -- --int stack_broadcast_shutdown(int fd, int how); -- --/* listen sync to all protocol stack thread, so that any protocol stack thread can build connect */ --int32_t stack_broadcast_listen(int32_t fd, int backlog); --int32_t stack_single_listen(int32_t fd, int32_t backlog); -- --/* bind sync to all protocol stack thread, only for udp protocol */ --int32_t stack_broadcast_bind(int32_t fd, const struct sockaddr *name, socklen_t namelen); --int32_t stack_single_bind(int32_t fd, const struct sockaddr *name, socklen_t namelen); -- --/* ergodic the protocol stack thread to find the connection, because all threads are listening */ --int32_t stack_broadcast_accept(int32_t fd, struct sockaddr *addr, socklen_t *addrlen); --int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *addrlen, int32_t flags); -- --struct wakeup_poll; --void stack_broadcast_clean_epoll(struct wakeup_poll *wakeup); -- --void stack_send_pkts(struct protocol_stack *stack); -- --struct thread_params { -- uint16_t queue_id; -- uint16_t idx; --}; -- - int stack_polling(uint32_t wakeup_tick); -+ - #endif -diff --git a/src/lstack/include/lstack_rpc_proc.h b/src/lstack/include/lstack_rpc_proc.h -deleted file mode 100644 -index 77b18bd..0000000 ---- a/src/lstack/include/lstack_rpc_proc.h -+++ /dev/null -@@ -1,47 +0,0 @@ --/* --* 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_RPC_PROC_H__ --#define __GAZELLE_RPC_PROC_H__ --#include "lstack_thread_rpc.h" -- --void stack_clean_epoll(struct rpc_msg *msg); --void stack_arp(struct rpc_msg *msg); --void stack_socket(struct rpc_msg *msg); --void stack_close(struct rpc_msg *msg); --void stack_shutdown(struct rpc_msg *msg); --void stack_bind(struct rpc_msg *msg); --void stack_listen(struct rpc_msg *msg); --void stack_accept(struct rpc_msg *msg); --void stack_connect(struct rpc_msg *msg); --void stack_recv(struct rpc_msg *msg); --void stack_getpeername(struct rpc_msg *msg); --void stack_getsockname(struct rpc_msg *msg); --void stack_getsockopt(struct rpc_msg *msg); --void stack_setsockopt(struct rpc_msg *msg); --void stack_fcntl(struct rpc_msg *msg); --void stack_ioctl(struct rpc_msg *msg); --void stack_tcp_send(struct rpc_msg *msg); --void stack_udp_send(struct rpc_msg *msg); --void stack_mempool_size(struct rpc_msg *msg); --void stack_rpcpool_size(struct rpc_msg *msg); --void stack_create_shadow_fd(struct rpc_msg *msg); --void stack_replenish_sendring(struct rpc_msg *msg); --void stack_get_conntable(struct rpc_msg *msg); --void stack_get_connnum(struct rpc_msg *msg); --void stack_recvlist_count(struct rpc_msg *msg); --void stack_exit_by_rpc(struct rpc_msg *msg); -- --void thread_register_phase1(struct rpc_msg *msg); --void thread_register_phase2(struct rpc_msg *msg); -- --#endif -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index d268366..c2654bb 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -35,8 +35,8 @@ struct rpc_stats { - struct rpc_msg; - typedef void (*rpc_msg_func)(struct rpc_msg *msg); - union rpc_msg_arg { -- int32_t i; -- uint32_t u; -+ int i; -+ unsigned int u; - long l; - unsigned long ul; - void *p; -@@ -63,50 +63,43 @@ static inline void rpc_queue_init(rpc_queue *queue) - { - lockless_queue_init(queue); - } -- - struct rpc_stats *rpc_stats_get(void); --int32_t rpc_msgcnt(rpc_queue *queue); --int rpc_poll_msg(rpc_queue *queue, uint32_t max_num); -+int rpc_msgcnt(rpc_queue *queue); -+int rpc_poll_msg(rpc_queue *queue, int max_num); -+ -+int rpc_call_stack_exit(rpc_queue *queue); -+ -+/* #include will conflict with lwip/sockets.h */ -+struct sockaddr; -+ -+int rpc_call_close(rpc_queue *queue, int fd); -+int rpc_call_shutdown(rpc_queue *queue, int fd, int how); -+int rpc_call_socket(rpc_queue *queue, int domain, int type, int protocol); -+int rpc_call_bind(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen); -+int rpc_call_listen(rpc_queue *queue, int s, int backlog); -+int rpc_call_shadow_fd(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen); -+int rpc_call_accept(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen, int flags); -+int rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen); -+ -+int rpc_call_getpeername(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen); -+int rpc_call_getsockname(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen); -+int rpc_call_getsockopt(rpc_queue *queue, int fd, int level, int optname, void *optval, socklen_t *optlen); -+int rpc_call_setsockopt(rpc_queue *queue, int fd, int level, int optname, const void *optval, socklen_t optlen); -+ -+int rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags); -+int rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags); -+ -+int rpc_call_replenish(rpc_queue *queue, void *sock); -+int rpc_call_recvlistcnt(rpc_queue *queue); -+ - void rpc_call_clean_epoll(rpc_queue *queue, void *wakeup); --int32_t rpc_call_shadow_fd(rpc_queue *queue, int32_t fd, const struct sockaddr *addr, socklen_t addrlen); --int32_t rpc_call_recvlistcnt(rpc_queue *queue); --int32_t rpc_call_thread_regphase1(rpc_queue *queue, void *conn); --int32_t rpc_call_thread_regphase2(rpc_queue *queue, void *conn); --int32_t rpc_call_conntable(rpc_queue *queue, void *conn_table, uint32_t max_conn); --int32_t rpc_call_connnum(rpc_queue *queue); --int32_t rpc_call_arp(rpc_queue *queue, void *mbuf); --int32_t rpc_call_socket(rpc_queue *queue, int32_t domain, int32_t type, int32_t protocol); --int32_t rpc_call_close(rpc_queue *queue, int32_t fd); --int32_t rpc_call_shutdown(rpc_queue *queue, int fd, int how); --int32_t rpc_call_bind(rpc_queue *queue, int32_t fd, const struct sockaddr *addr, socklen_t addrlen); --int32_t rpc_call_listen(rpc_queue *queue, int s, int backlog); --int32_t rpc_call_accept(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen, int flags); --int32_t rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen); --int32_t rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags); --int32_t rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags); --int32_t rpc_call_getpeername(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen); --int32_t rpc_call_getsockname(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen); --int32_t rpc_call_getsockopt(rpc_queue *queue, int fd, int level, int optname, void *optval, socklen_t *optlen); --int32_t rpc_call_setsockopt(rpc_queue *queue, int fd, int level, int optname, const void *optval, socklen_t optlen); --int32_t rpc_call_fcntl(rpc_queue *queue, int fd, int cmd, long val); --int32_t rpc_call_ioctl(rpc_queue *queue, int fd, long cmd, void *argp); --int32_t rpc_call_replenish(rpc_queue *queue, void *sock); --int32_t rpc_call_mbufpoolsize(rpc_queue *queue); --int32_t rpc_call_stack_exit(rpc_queue *queue); -- --static inline __attribute__((always_inline)) void rpc_call(rpc_queue *queue, struct rpc_msg *msg) --{ -- lockless_queue_mpsc_push(queue, &msg->queue_node); --} -+int rpc_call_arp(rpc_queue *queue, void *mbuf); - --static inline __attribute__((always_inline)) void rpc_msg_free(struct rpc_msg *msg) --{ -- pthread_spin_destroy(&msg->lock); -- if (msg->rpcpool != NULL && msg->rpcpool->mempool != NULL) { -- rte_mempool_put(msg->rpcpool->mempool, (void *)msg); -- } else { -- free(msg); -- } --} -+int rpc_call_conntable(rpc_queue *queue, void *conn_table, unsigned max_conn); -+int rpc_call_connnum(rpc_queue *queue); -+int rpc_call_mbufpoolsize(rpc_queue *queue); -+ -+int rpc_call_thread_regphase1(rpc_queue *queue, void *conn); -+int rpc_call_thread_regphase2(rpc_queue *queue, void *conn); - - #endif -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index cf66e15..4f3cbc1 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -43,6 +43,62 @@ - #define MBUF_MAX_LEN 1514 - #define PACKET_READ_SIZE 32 - -+/* any protocol stack thread receives arp packet and sync it to other threads, -+ * so that it can have the arp table */ -+static void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cur_stack) -+{ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ struct rte_mbuf *mbuf_copy = NULL; -+ struct protocol_stack *stack = NULL; -+ int32_t ret; -+ -+ for (int32_t i = 0; i < stack_group->stack_num; i++) { -+ stack = stack_group->stacks[i]; -+ if (cur_stack == stack) { -+ continue; -+ } -+ -+ /* stack maybe not init in app thread yet */ -+ if (stack == NULL || !(netif_is_up(&stack->netif))) { -+ continue; -+ } -+ -+ ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -+ if (ret != 0) { -+ stack->stats.rx_allocmbuf_fail++; -+ return; -+ } -+ copy_mbuf(mbuf_copy, mbuf); -+ -+ ret = rpc_call_arp(&stack->rpc_queue, mbuf_copy); -+ if (ret != 0) { -+ rte_pktmbuf_free(mbuf_copy); -+ return; -+ } -+ } -+#if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) -+ if (get_global_cfg_params()->kni_switch) { -+ ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -+ if (ret != 0) { -+ cur_stack->stats.rx_allocmbuf_fail++; -+ return; -+ } -+ copy_mbuf(mbuf_copy, mbuf); -+ kni_handle_tx(mbuf_copy); -+ } -+#endif -+ if (get_global_cfg_params()->flow_bifurcation) { -+ ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -+ if (ret != 0) { -+ cur_stack->stats.rx_allocmbuf_fail++; -+ return; -+ } -+ copy_mbuf(mbuf_copy, mbuf); -+ virtio_tap_process_tx(cur_stack->queue_id, mbuf_copy); -+ } -+ return; -+} -+ - void eth_dev_recv(struct rte_mbuf *mbuf, struct protocol_stack *stack) - { - int32_t ret; --- -2.33.0 - diff --git a/0259-cleancode-add-rpc_async_call-remove-rpc_msg_arg.sock.patch b/0259-cleancode-add-rpc_async_call-remove-rpc_msg_arg.sock.patch deleted file mode 100644 index 1d2c323fdb838b7c87a361fac3ddc36c90c18257..0000000000000000000000000000000000000000 --- a/0259-cleancode-add-rpc_async_call-remove-rpc_msg_arg.sock.patch +++ /dev/null @@ -1,693 +0,0 @@ -From 710bb34f1b46e0df4d82fe46fc36e729160ea1d7 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sun, 1 Sep 2024 00:21:52 +0800 -Subject: [PATCH] cleancode: add rpc_async_call, remove rpc_msg_arg.socklen, - fix some format - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_lwip.c | 27 +---- - src/lstack/core/lstack_protocol_stack.c | 25 ++--- - src/lstack/core/lstack_thread_rpc.c | 124 +++++++++++---------- - src/lstack/include/lstack_lwip.h | 27 +++-- - src/lstack/include/lstack_protocol_stack.h | 13 +-- - src/lstack/include/lstack_thread_rpc.h | 25 +++-- - 6 files changed, 117 insertions(+), 124 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 3454961..91f4838 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -588,23 +588,6 @@ bool do_lwip_replenish_sendring(struct protocol_stack *stack, struct lwip_sock * - return replenish_again; - } - --int do_lwip_send(struct protocol_stack *stack, int32_t fd, struct lwip_sock *sock, -- size_t len, int32_t flags) --{ -- ssize_t ret; -- /* send all send_ring, so len set lwip send max. */ -- if (NETCONN_IS_UDP(sock)) { -- ret = lwip_send(fd, sock, len, flags); -- } else { -- ret = lwip_send(fd, sock, UINT16_MAX, flags); -- } -- if (ret < 0 && (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED)) { -- return -1; -- } -- -- return do_lwip_replenish_sendring(stack, sock); --} -- - static inline void free_recv_ring_readover(struct rte_ring *ring) - { - void *pbufs[SOCK_RECV_RING_SIZE]; -@@ -753,10 +736,10 @@ static inline void notice_stack_tcp_send(struct lwip_sock *sock, int32_t fd, int - - static inline void notice_stack_udp_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags) - { -- __sync_fetch_and_add(&sock->call_num, 1); -- while (rpc_call_udp_send(&sock->stack->rpc_queue, fd, len, flags) < 0) { -- usleep(1000); // 1000: wait 1ms to exec again -- } -+ __sync_fetch_and_add(&sock->call_num, 1); -+ while (rpc_call_udp_send(&sock->stack->rpc_queue, fd, len, flags) < 0) { -+ usleep(1000); // 1000: wait 1ms to exec again -+ } - } - - static inline void notice_stack_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags) -@@ -875,7 +858,7 @@ ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t f - // send = 0 : tcp peer close connection ? - if (send <= 0) { - return send; -- } -+ } - } - - notice_stack_send(sock, fd, send, flags); -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index bcca1a7..f1eeba1 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -88,7 +88,7 @@ struct protocol_stack *get_protocol_stack(void) - return g_stack_p; - } - --struct protocol_stack *get_protocol_stack_by_fd(int32_t fd) -+struct protocol_stack *get_protocol_stack_by_fd(int fd) - { - struct lwip_sock *sock = lwip_get_socket(fd); - if (POSIX_IS_CLOSED(sock)) { -@@ -468,7 +468,7 @@ END: - return NULL; - } - --int stack_polling(uint32_t wakeup_tick) -+int stack_polling(unsigned wakeup_tick) - { - int force_quit; - struct cfg_params *cfg = get_global_cfg_params(); -@@ -536,12 +536,11 @@ int stack_polling(uint32_t wakeup_tick) - static void* gazelle_stack_thread(void *arg) - { - struct thread_params *t_params = (struct thread_params*) arg; -- - uint16_t queue_id = t_params->queue_id; -- uint32_t wakeup_tick = 0; -- -- struct protocol_stack *stack = stack_thread_init(arg); -+ struct protocol_stack *stack; -+ unsigned wakeup_tick = 0; - -+ stack = stack_thread_init(arg); - free(arg); - if (stack == NULL) { - LSTACK_LOG(ERR, LSTACK, "stack_thread_init failed queue_id=%hu\n", queue_id); -@@ -607,7 +606,7 @@ static int stack_group_init_mempool(void) - return 0; - } - --int32_t stack_group_init(void) -+int stack_group_init(void) - { - struct protocol_stack_group *stack_group = get_protocol_stack_group(); - stack_group->stack_num = 0; -@@ -632,7 +631,7 @@ int32_t stack_group_init(void) - return 0; - } - --int32_t stack_setup_app_thread(void) -+int stack_setup_app_thread(void) - { - static PER_THREAD int first_flags = 1; - static _Atomic uint32_t queue_id = 0; -@@ -660,21 +659,21 @@ int32_t stack_setup_app_thread(void) - return 0; - } - --int32_t stack_setup_thread(void) -+int stack_setup_thread(void) - { -- int32_t ret; -+ int ret, i; - char name[PATH_MAX]; - int queue_num = get_global_cfg_params()->num_queue; - struct thread_params *t_params[PROTOCOL_STACK_MAX] = {NULL}; - int process_index = get_global_cfg_params()->process_idx; - -- for (uint32_t i = 0; i < queue_num; ++i) { -+ for (i = 0; i < queue_num; ++i) { - t_params[i] = malloc(sizeof(struct thread_params)); - if (t_params[i] == NULL) { - goto OUT1; - } - } -- for (uint32_t i = 0; i < queue_num; i++) { -+ 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); -@@ -714,7 +713,7 @@ int32_t stack_setup_thread(void) - return 0; - - OUT1: -- for (int32_t i = 0; i < queue_num; ++i) { -+ for (i = 0; i < queue_num; ++i) { - if (t_params[i] != NULL) { - free(t_params[i]); - } -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 3e9889a..b4a5953 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -45,20 +45,20 @@ static struct rpc_msg *get_rpc_msg(struct rpc_msg_pool *rpc_pool) - return msg; - } - --static void rpc_msg_init(struct rpc_msg *msg, rpc_msg_func func, struct rpc_msg_pool *pool) -+__rte_always_inline -+static void rpc_msg_init(struct rpc_msg *msg, rpc_func_t func, struct rpc_msg_pool *pool) - { - msg->func = func; - msg->rpcpool = pool; -- msg->sync_flag = 1; - msg->recall_flag = 0; - pthread_spin_init(&msg->lock, PTHREAD_PROCESS_PRIVATE); - } - --static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func) -+static struct rpc_msg *rpc_msg_alloc(rpc_func_t func) - { -- struct rpc_msg *msg = NULL; -+ struct rpc_msg *msg; - -- if (g_rpc_pool == NULL) { -+ if (unlikely(g_rpc_pool == NULL)) { - g_rpc_pool = calloc(1, sizeof(struct rpc_msg_pool)); - if (g_rpc_pool == NULL) { - LSTACK_LOG(INFO, LSTACK, "g_rpc_pool calloc failed\n"); -@@ -66,8 +66,8 @@ static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func) - exit(-1); - } - -- g_rpc_pool->mempool = create_mempool("rpc_pool", get_global_cfg_params()->rpc_msg_max, sizeof(struct rpc_msg), -- 0, rte_gettid()); -+ 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++; -@@ -76,12 +76,12 @@ static struct rpc_msg *rpc_msg_alloc(rpc_msg_func func) - } - - msg = get_rpc_msg(g_rpc_pool); -- if (msg == NULL) { -+ if (unlikely(msg == NULL)) { - g_rpc_stats.call_alloc_fail++; - return NULL; - } -- rpc_msg_init(msg, func, g_rpc_pool); - -+ rpc_msg_init(msg, func, g_rpc_pool); - return msg; - } - -@@ -97,8 +97,9 @@ static void rpc_msg_free(struct rpc_msg *msg) - } - - __rte_always_inline --static void rpc_call(rpc_queue *queue, struct rpc_msg *msg) -+static void rpc_async_call(rpc_queue *queue, struct rpc_msg *msg) - { -+ msg->sync_flag = 0; - lockless_queue_mpsc_push(queue, &msg->queue_node); - } - -@@ -108,7 +109,9 @@ static int rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg) - int ret; - - pthread_spin_trylock(&msg->lock); -- rpc_call(queue, msg); -+ -+ msg->sync_flag = 1; -+ lockless_queue_mpsc_push(queue, &msg->queue_node); - - // waiting stack unlock - pthread_spin_lock(&msg->lock); -@@ -123,7 +126,7 @@ int rpc_msgcnt(rpc_queue *queue) - return lockless_queue_count(queue); - } - --static struct rpc_msg *rpc_msg_alloc_except(rpc_msg_func func) -+static struct rpc_msg *rpc_msg_alloc_except(rpc_func_t func) - { - struct rpc_msg *msg = calloc(1, sizeof(struct rpc_msg)); - if (msg == NULL) { -@@ -146,14 +149,14 @@ int rpc_call_stack_exit(rpc_queue *queue) - return -1; - } - -- rpc_call(queue, msg); -+ rpc_async_call(queue, msg); - return 0; - } - - int rpc_poll_msg(rpc_queue *queue, int max_num) - { - int force_quit = 0; -- struct rpc_msg *msg = NULL; -+ struct rpc_msg *msg; - - while (max_num--) { - lockless_queue_node *node = lockless_queue_mpsc_pop(queue); -@@ -163,24 +166,24 @@ int rpc_poll_msg(rpc_queue *queue, int max_num) - - msg = container_of(node, struct rpc_msg, queue_node); - -- if (msg->func) { -+ if (likely(msg->func)) { - msg->func(msg); - } else { - g_rpc_stats.call_null++; - } - -- if (msg->func == stack_exit_by_rpc) { -+ if (unlikely(msg->func == stack_exit_by_rpc)) { - force_quit = 1; - } -+ if (msg->recall_flag) { -+ msg->recall_flag = 0; -+ continue; -+ } - -- if (!msg->recall_flag) { -- if (msg->sync_flag) { -- pthread_spin_unlock(&msg->lock); -- } else { -- rpc_msg_free(msg); -- } -+ if (msg->sync_flag) { -+ pthread_spin_unlock(&msg->lock); - } else { -- msg->recall_flag = 0; -+ rpc_msg_free(msg); - } - } - -@@ -204,7 +207,7 @@ static void callback_close(struct rpc_msg *msg) - - if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { - msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); /* until stack_send recall finish */ -+ rpc_async_call(&stack->rpc_queue, msg); /* until stack_send recall finish */ - return; - } - -@@ -223,7 +226,7 @@ static void callback_shutdown(struct rpc_msg *msg) - - if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { - msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); -+ rpc_async_call(&stack->rpc_queue, msg); - return; - } - -@@ -237,7 +240,7 @@ static void callback_shutdown(struct rpc_msg *msg) - - static void callback_bind(struct rpc_msg *msg) - { -- msg->result = lwip_bind(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].cp, msg->args[MSG_ARG_2].socklen); -+ msg->result = lwip_bind(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].cp, msg->args[MSG_ARG_2].u); - if (msg->result != 0) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); - } -@@ -265,7 +268,7 @@ static void callback_create_shadow_fd(struct rpc_msg *msg) - { - int fd = msg->args[MSG_ARG_0].i; - struct sockaddr *addr = msg->args[MSG_ARG_1].p; -- socklen_t addr_len = msg->args[MSG_ARG_2].socklen; -+ socklen_t addr_len = msg->args[MSG_ARG_2].u; - - int clone_fd = 0; - struct lwip_sock *sock = lwip_get_socket(fd); -@@ -337,7 +340,7 @@ static void callback_accept(struct rpc_msg *msg) - - static void callback_connect(struct rpc_msg *msg) - { -- msg->result = lwip_connect(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].socklen); -+ msg->result = lwip_connect(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].u); - if (msg->result < 0) { - msg->result = -errno; - } -@@ -391,7 +394,7 @@ int rpc_call_bind(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen - - msg->args[MSG_ARG_0].i = fd; - msg->args[MSG_ARG_1].cp = addr; -- msg->args[MSG_ARG_2].socklen = addrlen; -+ msg->args[MSG_ARG_2].u = addrlen; - - return rpc_sync_call(queue, msg); - } -@@ -418,7 +421,7 @@ int rpc_call_shadow_fd(rpc_queue *queue, int fd, const struct sockaddr *addr, so - - msg->args[MSG_ARG_0].i = fd; - msg->args[MSG_ARG_1].cp = addr; -- msg->args[MSG_ARG_2].socklen = addrlen; -+ msg->args[MSG_ARG_2].u = addrlen; - - return rpc_sync_call(queue, msg); - } -@@ -447,7 +450,7 @@ int rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, sock - - msg->args[MSG_ARG_0].i = fd; - msg->args[MSG_ARG_1].cp = addr; -- msg->args[MSG_ARG_2].socklen = addrlen; -+ msg->args[MSG_ARG_2].u = addrlen; - - int ret = rpc_sync_call(queue, msg); - if (ret < 0) { -@@ -486,7 +489,7 @@ static void callback_getsockopt(struct rpc_msg *msg) - static void callback_setsockopt(struct rpc_msg *msg) - { - msg->result = lwip_setsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, -- msg->args[MSG_ARG_3].cp, msg->args[MSG_ARG_4].socklen); -+ msg->args[MSG_ARG_3].cp, msg->args[MSG_ARG_4].u); - if (msg->result != 0) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d, level %d, optname %d, fail %ld\n", get_stack_tid(), - msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); -@@ -548,7 +551,7 @@ int rpc_call_setsockopt(rpc_queue *queue, int fd, int level, int optname, const - msg->args[MSG_ARG_1].i = level; - msg->args[MSG_ARG_2].i = optname; - msg->args[MSG_ARG_3].cp = optval; -- msg->args[MSG_ARG_4].socklen = optlen; -+ msg->args[MSG_ARG_4].u = optlen; - - return rpc_sync_call(queue, msg); - } -@@ -556,13 +559,13 @@ int rpc_call_setsockopt(rpc_queue *queue, int fd, int level, int optname, const - static void callback_tcp_send(struct rpc_msg *msg) - { - int fd = msg->args[MSG_ARG_0].i; -- size_t len = msg->args[MSG_ARG_1].size; -+ size_t len = UINT16_MAX; /* ignore msg->args[MSG_ARG_1].size; */ - struct protocol_stack *stack = get_protocol_stack(); -- int replenish_again; -+ int ret; -+ msg->result = -1; - - struct lwip_sock *sock = lwip_get_socket(fd); -- if (POSIX_IS_CLOSED(sock)) { -- msg->result = -1; -+ if (unlikely(POSIX_IS_CLOSED(sock))) { - return; - } - -@@ -570,16 +573,18 @@ static void callback_tcp_send(struct rpc_msg *msg) - calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_WRITE_RPC_MSG); - } - -- replenish_again = do_lwip_send(stack, sock->conn->callback_arg.socket, sock, len, 0); -- if (replenish_again < 0) { -+ ret = lwip_send(fd, sock, len, 0); -+ if (unlikely(ret < 0) && (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED)) { - __sync_fetch_and_sub(&sock->call_num, 1); - return; - } -+ msg->result = 0; - -- if (NETCONN_IS_DATAOUT(sock) || replenish_again > 0) { -+ ret = do_lwip_replenish_sendring(stack, sock); -+ if (ret > 0 || NETCONN_IS_DATAOUT(sock)) { - if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1) { - msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); -+ rpc_async_call(&stack->rpc_queue, msg); - return; - } - } -@@ -593,11 +598,11 @@ static void callback_udp_send(struct rpc_msg *msg) - int fd = msg->args[MSG_ARG_0].i; - size_t len = msg->args[MSG_ARG_1].size; - struct protocol_stack *stack = get_protocol_stack(); -- int replenish_again; -+ int ret; -+ msg->result = -1; - - struct lwip_sock *sock = lwip_get_socket(fd); -- if (POSIX_IS_CLOSED(sock)) { -- msg->result = -1; -+ if (unlikely(POSIX_IS_CLOSED(sock))) { - return; - } - -@@ -605,8 +610,15 @@ static void callback_udp_send(struct rpc_msg *msg) - calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_WRITE_RPC_MSG); - } - -- replenish_again = do_lwip_send(stack, sock->conn->callback_arg.socket, sock, len, 0); -- if ((replenish_again > 0) && (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1)) { -+ ret = lwip_send(fd, sock, len, 0); -+ if (unlikely(ret < 0) && (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED)) { -+ __sync_fetch_and_sub(&sock->call_num, 1); -+ return; -+ } -+ msg->result = 0; -+ -+ ret = do_lwip_replenish_sendring(stack, sock); -+ if (ret > 0 && (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1)) { - rpc_call_replenish(&stack->rpc_queue, sock); - return; - } -@@ -629,9 +641,8 @@ int rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags) - msg->args[MSG_ARG_0].i = fd; - msg->args[MSG_ARG_1].size = len; - msg->args[MSG_ARG_2].i = flags; -- msg->sync_flag = 0; - -- rpc_call(queue, msg); -+ rpc_async_call(queue, msg); - return 0; - } - -@@ -649,9 +660,8 @@ int rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags) - msg->args[MSG_ARG_0].i = fd; - msg->args[MSG_ARG_1].size = len; - msg->args[MSG_ARG_2].i = flags; -- msg->sync_flag = 0; - -- rpc_call(queue, msg); -+ rpc_async_call(queue, msg); - return 0; - } - -@@ -663,7 +673,7 @@ static void callback_replenish_sendring(struct rpc_msg *msg) - msg->result = do_lwip_replenish_sendring(stack, sock); - if (msg->result == true) { - msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); -+ rpc_async_call(&stack->rpc_queue, msg); - } - } - -@@ -675,9 +685,8 @@ int rpc_call_replenish(rpc_queue *queue, void *sock) - } - - msg->args[MSG_ARG_0].p = sock; -- msg->sync_flag = 0; - -- rpc_call(queue, msg); -+ rpc_async_call(queue, msg); - return 0; - } - -@@ -713,16 +722,17 @@ static void callback_clean_epoll(struct rpc_msg *msg) - list_del_node(&wakeup->wakeup_list[stack->stack_idx]); - } - --void rpc_call_clean_epoll(rpc_queue *queue, void *wakeup) -+int rpc_call_clean_epoll(rpc_queue *queue, void *wakeup) - { - struct rpc_msg *msg = rpc_msg_alloc(callback_clean_epoll); - if (msg == NULL) { -- return; -+ return -1; - } - - msg->args[MSG_ARG_0].p = wakeup; - - rpc_sync_call(queue, msg); -+ return 0; - } - - static void callback_arp(struct rpc_msg *msg) -@@ -740,11 +750,9 @@ int rpc_call_arp(rpc_queue *queue, void *mbuf) - return -1; - } - -- msg->sync_flag = 0; - msg->args[MSG_ARG_0].p = mbuf; - -- rpc_call(queue, msg); -- -+ rpc_async_call(queue, msg); - return 0; - } - -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index 0c7bb62..dcb7dac 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -29,15 +29,23 @@ unsigned same_node_ring_count(struct lwip_sock *sock); - #define NETCONN_IS_OUTIDLE(sock) gazelle_ring_readable_count((sock)->send_ring) - #define NETCONN_IS_UDP(sock) (NETCONNTYPE_GROUP(netconn_type((sock)->conn)) == NETCONN_UDP) - --void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock); -- -+/* lwip api */ - struct pbuf *do_lwip_tcp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size); - struct pbuf *do_lwip_udp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size); - void do_lwip_get_from_sendring_over(struct lwip_sock *sock); --bool do_lwip_replenish_sendring(struct protocol_stack *stack, struct lwip_sock *sock); - ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, uint8_t apiflags); - --/* app write/read ring */ -+/* lwip api */ -+void do_lwip_free_pbuf(struct pbuf *pbuf); -+struct pbuf *do_lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type type); -+ -+/* lwip api */ -+void do_lwip_add_recvlist(int32_t fd); -+/* stack api */ -+void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num); -+ -+ -+/* app api */ - ssize_t do_lwip_sendmsg_to_stack(struct lwip_sock *sock, int32_t s, - const struct msghdr *message, int32_t flags); - ssize_t do_lwip_recvmsg_from_stack(int32_t s, const struct msghdr *message, int32_t flags); -@@ -47,17 +55,14 @@ ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t f - ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags, - struct sockaddr *addr, socklen_t *addrlen); - --void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num); --void do_lwip_add_recvlist(int32_t fd); --int do_lwip_send(struct protocol_stack *stack, int32_t fd, struct lwip_sock *sock, -- size_t len, int32_t flags); -+/* stack api */ -+bool do_lwip_replenish_sendring(struct protocol_stack *stack, struct lwip_sock *sock); -+ -+void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock); - - uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, uint32_t max_num); - uint32_t do_lwip_get_connnum(void); - --void do_lwip_free_pbuf(struct pbuf *pbuf); --struct pbuf *do_lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type type); -- - void read_same_node_recv_list(struct protocol_stack *stack); - - #endif -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index fdd5388..08a3901 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -31,11 +31,8 @@ - #include "lstack_tx_cache.h" - - #define SOCK_RECV_RING_SIZE (get_global_cfg_params()->recv_ring_size) --#define SOCK_RECV_FREE_THRES (32) - #define SOCK_RECV_RING_SIZE_MAX (2048) - #define SOCK_SEND_RING_SIZE_MAX (2048) --#define SOCK_SEND_REPLENISH_THRES (16) --#define WAKEUP_MAX_NUM (32) - - #define MBUFPOOL_RESERVE_NUM (get_global_cfg_params()->nic.rxqueue_size + 1024) - -@@ -113,7 +110,7 @@ struct protocol_stack_group { - long get_stack_tid(void); - - struct protocol_stack *get_protocol_stack(void); --struct protocol_stack *get_protocol_stack_by_fd(int32_t fd); -+struct protocol_stack *get_protocol_stack_by_fd(int fd); - struct protocol_stack *get_bind_protocol_stack(void); - struct protocol_stack_group *get_protocol_stack_group(void); - -@@ -121,13 +118,13 @@ int get_min_conn_stack(struct protocol_stack_group *stack_group); - void bind_to_stack_numa(struct protocol_stack *stack); - void thread_bind_stack(struct protocol_stack *stack); - --int32_t stack_group_init(void); -+int stack_group_init(void); - void stack_group_exit(void); - void stack_exit(void); - --int32_t stack_setup_thread(void); --int32_t stack_setup_app_thread(void); -+int stack_setup_thread(void); -+int stack_setup_app_thread(void); - --int stack_polling(uint32_t wakeup_tick); -+int stack_polling(unsigned wakeup_tick); - - #endif -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index c2654bb..6f8e03e 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -32,8 +32,6 @@ struct rpc_stats { - uint64_t call_alloc_fail; - }; - --struct rpc_msg; --typedef void (*rpc_msg_func)(struct rpc_msg *msg); - union rpc_msg_arg { - int i; - unsigned int u; -@@ -41,22 +39,25 @@ union rpc_msg_arg { - unsigned long ul; - void *p; - const void *cp; -- socklen_t socklen; - size_t size; - }; --struct rpc_msg_pool { -- struct rte_mempool *mempool; --}; -+ -+struct rpc_msg; -+typedef void (*rpc_func_t)(struct rpc_msg *msg); - struct rpc_msg { -- pthread_spinlock_t lock; /* msg handler unlock notice sender msg process done */ - int8_t sync_flag : 1; - int8_t recall_flag : 1; -- int64_t result; /* func return val */ -- lockless_queue_node queue_node; -- struct rpc_msg_pool *rpcpool; - -- rpc_msg_func func; /* msg handle func hook */ -+ long result; /* func return val */ -+ rpc_func_t func; /* msg handle func hook */ - union rpc_msg_arg args[RPM_MSG_ARG_SIZE]; /* resolve by type */ -+ -+ struct rpc_msg_pool { -+ struct rte_mempool *mempool; -+ } *rpcpool; -+ -+ pthread_spinlock_t lock; /* msg handler unlock notice sender msg process done */ -+ lockless_queue_node queue_node; - }; - - static inline void rpc_queue_init(rpc_queue *queue) -@@ -92,7 +93,7 @@ int rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags); - int rpc_call_replenish(rpc_queue *queue, void *sock); - int rpc_call_recvlistcnt(rpc_queue *queue); - --void rpc_call_clean_epoll(rpc_queue *queue, void *wakeup); -+int rpc_call_clean_epoll(rpc_queue *queue, void *wakeup); - int rpc_call_arp(rpc_queue *queue, void *mbuf); - - int rpc_call_conntable(rpc_queue *queue, void *conn_table, unsigned max_conn); --- -2.33.0 - diff --git a/0260-cleancode-declare-different-cfg_params-types.patch b/0260-cleancode-declare-different-cfg_params-types.patch deleted file mode 100644 index fb2c1a97db5a635fa5b244041244e63036c0c897..0000000000000000000000000000000000000000 --- a/0260-cleancode-declare-different-cfg_params-types.patch +++ /dev/null @@ -1,347 +0,0 @@ -From 3313619bd53f1bafc5e48eb4642213fd5208c0e2 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sun, 1 Sep 2024 11:33:12 +0800 -Subject: [PATCH] cleancode: declare different cfg_params types - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_cfg.c | 10 +- - src/lstack/core/lstack_dpdk.c | 8 +- - src/lstack/core/lstack_protocol_stack.c | 2 +- - src/lstack/core/lstack_virtio.c | 4 +- - src/lstack/include/lstack_cfg.h | 161 +++++++++++---------- - src/lstack/include/lstack_protocol_stack.h | 2 +- - src/lstack/netif/lstack_ethdev.c | 4 +- - src/lstack/netif/lstack_vdev.c | 2 +- - 8 files changed, 104 insertions(+), 89 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 882e60a..659a2a7 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -1300,9 +1300,9 @@ static int32_t parse_use_sockmap(void) - static int32_t parse_nic_rxqueue_size(void) - { - int32_t ret; -- PARSE_ARG(g_config_params.nic.rxqueue_size, "nic_rxqueue_size", 4096, -+ PARSE_ARG(g_config_params.rxqueue_size, "nic_rxqueue_size", 4096, - NIC_QUEUE_SIZE_MIN, NIC_QUEUE_SIZE_MAX, ret); -- if (!rte_is_power_of_2(g_config_params.nic.rxqueue_size)) { -+ if (!rte_is_power_of_2(g_config_params.rxqueue_size)) { - LSTACK_LOG(ERR, LSTACK, "nic queue size only support power of two\n"); - return -1; - } -@@ -1312,9 +1312,9 @@ static int32_t parse_nic_rxqueue_size(void) - static int32_t parse_nic_txqueue_size(void) - { - int32_t ret; -- PARSE_ARG(g_config_params.nic.txqueue_size, "nic_txqueue_size", 2048, -+ PARSE_ARG(g_config_params.txqueue_size, "nic_txqueue_size", 2048, - NIC_QUEUE_SIZE_MIN, NIC_QUEUE_SIZE_MAX, ret); -- if (!rte_is_power_of_2(g_config_params.nic.txqueue_size)) { -+ if (!rte_is_power_of_2(g_config_params.txqueue_size)) { - LSTACK_LOG(ERR, LSTACK, "nic queue size only support power of two\n"); - return -1; - } -@@ -1352,7 +1352,7 @@ static int32_t parse_stack_thread_mode(void) - static int32_t parse_nic_vlan_mode(void) - { - int32_t ret; -- PARSE_ARG(g_config_params.nic.vlan_mode, "nic_vlan_mode", -1, -1, 4094, ret); -+ PARSE_ARG(g_config_params.vlan_mode, "nic_vlan_mode", -1, -1, 4094, ret); - return ret; - } - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index f87e362..1fe0f0a 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -432,8 +432,8 @@ static int eth_params_init(struct eth_params *eth_params, uint16_t port_id, uint - - eth_params->port_id = port_id; - eth_params->nb_queues = nb_queues; -- eth_params->nb_rx_desc = get_global_cfg_params()->nic.rxqueue_size; -- eth_params->nb_tx_desc = get_global_cfg_params()->nic.txqueue_size; -+ eth_params->nb_rx_desc = get_global_cfg_params()->rxqueue_size; -+ eth_params->nb_tx_desc = get_global_cfg_params()->txqueue_size; - eth_params->conf.link_speeds = RTE_ETH_LINK_SPEED_AUTONEG; - eth_params->conf.txmode.mq_mode = RTE_ETH_MQ_TX_NONE; - eth_params->conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE; -@@ -571,7 +571,7 @@ int32_t dpdk_ethdev_init(int port_id) - } - - /* after rte_eth_dev_configure */ -- if ((get_global_cfg_params()->nic.vlan_mode != -1) && -+ if ((get_global_cfg_params()->vlan_mode != -1) && - ((stack_group->rx_offload & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) == RTE_ETH_RX_OFFLOAD_VLAN_FILTER)) { - /* - * vlan filter can be configured for switch,nic and software. -@@ -583,7 +583,7 @@ int32_t dpdk_ethdev_init(int port_id) - */ - if ((get_global_cfg_params()->bond_mode != BONDING_MODE_8023AD) && - (get_global_cfg_params()->bond_mode != BONDING_MODE_ALB)) { -- ret = rte_eth_dev_vlan_filter(port_id, get_global_cfg_params()->nic.vlan_mode, 1); -+ ret = rte_eth_dev_vlan_filter(port_id, get_global_cfg_params()->vlan_mode, 1); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk add vlan filter failed ret = %d\n", ret); - return -1; -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index f1eeba1..d03b744 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -571,7 +571,7 @@ 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->nic.rxqueue_size + cfg_params->nic.txqueue_size; -+ uint32_t total_nic_mbufs = cfg_params->rxqueue_size + cfg_params->txqueue_size; - struct rte_mempool *rxtx_mbuf = NULL; - uint32_t cpu_id = 0; - unsigned numa_id = 0; -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index 7a8d947..fefb06d 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -226,10 +226,10 @@ void virtio_tap_process_rx(uint16_t port, uint32_t queue_id) - * so no action will be taken. - * For TSO, tap devices do not support it, so no action will be taken. - */ -- if (get_global_cfg_params()->nic.vlan_mode != -1) { -+ if (get_global_cfg_params()->vlan_mode != -1) { - for (int i = 0; i< pkg_num; i++) { - pkts_burst[i]->ol_flags |= RTE_MBUF_F_TX_VLAN; -- pkts_burst[i]->vlan_tci = (u16_t)get_global_cfg_params()->nic.vlan_mode; -+ pkts_burst[i]->vlan_tci = (u16_t)get_global_cfg_params()->vlan_mode; - } - } - -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 4fc99f3..5e2d6fc 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -50,93 +50,108 @@ - #define LSTACK_LPM_PKTS_IN_DETECT 1000 - #define LSTACK_LPM_RX_PKTS 20 - -- - #define LSTACK_LPM_PKTS_IN_DETECT_MIN 5 - #define LSTACK_LPM_PKTS_IN_DETECT_MAX 65535 - -+struct dev_addr { - #define DEV_ADDR_TYPE_EMPTY 0 - #define DEV_ADDR_TYPE_MAC 1 - #define DEV_ADDR_TYPE_PCI 2 -- --struct dev_addr { -- uint8_t addr_type; // 0:empty, 1:mac, 2:pci -+ uint8_t addr_type; - union addr_union { - struct rte_ether_addr mac_addr; - struct rte_pci_addr pci_addr; - } addr; - }; - --struct secondary_attach_arg { -- uint8_t socket_num; -- uint64_t socket_size; -- uint32_t socket_per_size[GAZELLE_MAX_NUMA_NODES]; -- uintptr_t base_virtaddr; -- char file_prefix[PATH_MAX]; --}; -- --struct cfg_nic_params { -- uint32_t rxqueue_size; -- uint32_t txqueue_size; -- int32_t vlan_mode; --}; -- - struct cfg_params { -- ip4_addr_t host_addr; -- ip6_addr_t host_addr6; -- ip4_addr_t netmask; -- ip4_addr_t gateway_addr; -- uint8_t mac_addr[ETHER_ADDR_LEN]; -- uint16_t num_cpu; -- uint32_t cpus[CFG_MAX_CPUS]; -- uint32_t send_cpus[CFG_MAX_CPUS]; -- uint32_t recv_cpus[CFG_MAX_CPUS]; -- uint16_t app_exclude_num_cpu; -- uint32_t app_exclude_cpus[CFG_MAX_CPUS]; -- uint8_t num_ports; -- uint16_t ports[CFG_MAX_PORTS]; - char log_file[PATH_MAX]; -- uint16_t low_power_mod; -- uint16_t lpm_rx_pkts; -- uint32_t lpm_detect_ms; -- uint32_t lpm_pkts_in_detect; -- uint32_t tcp_conn_count; -- uint32_t mbuf_count_per_conn; -- uint32_t read_connect_number; -- uint32_t rpc_number; -- uint32_t nic_read_number; -- uint8_t use_ltran; // false:lstack read from nic. true:lstack read form ltran process. -- -- uint16_t num_process; -- uint16_t num_listen_port; -- uint16_t is_primary; -- uint16_t num_queue; -- uint16_t tot_queue_num; -- uint8_t process_idx; -- uint32_t process_numa[PROTOCOL_STACK_MAX]; -- -- bool kni_switch; -- bool listen_shadow; // true:listen in all stack thread. false:listen in one stack thread. -- bool app_bind_numa; -- bool main_thread_affinity; -- bool seperate_send_recv; -- int dpdk_argc; -- char **dpdk_argv; -- struct secondary_attach_arg sec_attach_arg; -- char unix_socket_filename[NAME_MAX]; -- uint16_t send_ring_size; -- uint16_t recv_ring_size; -- bool tuple_filter; -- int8_t bond_mode; -- int32_t bond_miimon; -- struct dev_addr bond_slave_addr[GAZELLE_MAX_BOND_NUM]; -- bool use_sockmap; -- bool udp_enable; -- struct cfg_nic_params nic; -- bool stack_mode_rtc; -- bool nonblock_mode; -- uint32_t rpc_msg_max; -- bool send_cache_mode; -- bool flow_bifurcation; -+ -+ struct { // dpdk -+ char **dpdk_argv; -+ uint8_t dpdk_argc; -+ struct secondary_attach_arg { -+ uint8_t socket_num; -+ uint64_t socket_size; -+ uint32_t socket_per_size[GAZELLE_MAX_NUMA_NODES]; -+ uintptr_t base_virtaddr; -+ char file_prefix[PATH_MAX]; -+ } sec_attach_arg; -+ }; -+ -+ struct { // eth -+ ip4_addr_t host_addr; -+ ip6_addr_t host_addr6; -+ ip4_addr_t netmask; -+ ip4_addr_t gateway_addr; -+ uint8_t mac_addr[ETHER_ADDR_LEN]; -+ int8_t bond_mode; -+ int32_t bond_miimon; -+ struct dev_addr bond_slave_addr[GAZELLE_MAX_BOND_NUM]; -+ }; -+ -+ struct { // low_power -+ uint16_t low_power_mod; -+ uint16_t lpm_rx_pkts; -+ uint32_t lpm_detect_ms; -+ uint32_t lpm_pkts_in_detect; -+ }; -+ -+ struct { // eth_rxtx -+ uint32_t rxqueue_size; -+ uint32_t txqueue_size; -+ uint16_t num_queue; -+ uint16_t tot_queue_num; -+ bool send_cache_mode; -+ bool flow_bifurcation; -+ int32_t vlan_mode; -+ }; -+ -+ struct { // stack -+ uint16_t num_cpu; -+ uint32_t cpus[CFG_MAX_CPUS]; -+ -+ bool main_thread_affinity; -+ bool app_bind_numa; -+ uint16_t app_exclude_num_cpu; -+ uint32_t app_exclude_cpus[CFG_MAX_CPUS]; -+ -+ bool stack_mode_rtc; -+ bool listen_shadow; // true:listen in all stack thread. false:listen in one stack thread. -+ -+ uint32_t read_connect_number; -+ uint32_t nic_read_number; -+ uint32_t rpc_number; -+ uint32_t rpc_msg_max; -+ }; -+ -+ struct { // socket -+ uint16_t send_ring_size; -+ uint16_t recv_ring_size; -+ uint32_t tcp_conn_count; -+ uint32_t mbuf_count_per_conn; -+ }; -+ -+ 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; -+ }; -+ -+ struct { // experiment -+ uint16_t num_process; -+ uint16_t is_primary; -+ uint8_t process_idx; -+ 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]; -+ }; - }; - - struct cfg_params *get_global_cfg_params(void); -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 08a3901..8cb0020 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -34,7 +34,7 @@ - #define SOCK_RECV_RING_SIZE_MAX (2048) - #define SOCK_SEND_RING_SIZE_MAX (2048) - --#define MBUFPOOL_RESERVE_NUM (get_global_cfg_params()->nic.rxqueue_size + 1024) -+#define MBUFPOOL_RESERVE_NUM (get_global_cfg_params()->rxqueue_size + 1024) - - struct protocol_stack { - uint32_t tid; -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 4f3cbc1..1a721f6 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -418,8 +418,8 @@ int32_t ethdev_init(struct protocol_stack *stack) - } - - /* 0-4094: The vlaue range for VLAN IDs is 0 to 4094. */ -- if (get_global_cfg_params()->nic.vlan_mode >= 0 && get_global_cfg_params()->nic.vlan_mode <= 4094) { -- netif_set_vlan_tci(&stack->netif, (u16_t)get_global_cfg_params()->nic.vlan_mode); -+ if (get_global_cfg_params()->vlan_mode >= 0 && get_global_cfg_params()->vlan_mode <= 4094) { -+ netif_set_vlan_tci(&stack->netif, (u16_t)get_global_cfg_params()->vlan_mode); - } - - netif_set_link_up(&stack->netif); -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 9ca77ba..e1a63a7 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -145,7 +145,7 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt - } - - /* skip gro when tcp/ip cksum offloads disable */ -- if (get_protocol_stack_group()->rx_offload == 0 || (get_global_cfg_params()->nic.vlan_mode >= 0 -+ if (get_protocol_stack_group()->rx_offload == 0 || (get_global_cfg_params()->vlan_mode >= 0 - && !(get_protocol_stack_group()->rx_offload & RTE_ETH_RX_OFFLOAD_VLAN_STRIP))) { - return pkt_num; - } --- -2.33.0 - diff --git a/0261-Fill-in-a-portion-of-mbuf-to-send_ring-when-mbuf-is-.patch b/0261-Fill-in-a-portion-of-mbuf-to-send_ring-when-mbuf-is-.patch deleted file mode 100644 index 1290f60b9950e08047569151171aef6d50089813..0000000000000000000000000000000000000000 --- a/0261-Fill-in-a-portion-of-mbuf-to-send_ring-when-mbuf-is-.patch +++ /dev/null @@ -1,78 +0,0 @@ -From 7718bd104226b2444e1a3a7405e4daed9ac046f9 Mon Sep 17 00:00:00 2001 -From: hkk -Date: Wed, 25 Sep 2024 15:01:02 +0800 -Subject: [PATCH] Fill in a portion of mbuf to send_ring, when mbuf is - insufficient. - ---- - src/lstack/core/lstack_lwip.c | 31 +++++++++++++++++++--- - src/lstack/include/lstack_protocol_stack.h | 2 +- - 2 files changed, 29 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 91f4838..7677e46 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -109,18 +109,43 @@ static struct pbuf *init_mbuf_to_pbuf(struct rte_mbuf *mbuf, pbuf_layer layer, u - return pbuf; - } - -+static uint32_t update_replenish_mbuf_cnt(struct protocol_stack *stack, struct lwip_sock *sock) -+{ -+ const uint32_t min_alloc_mbuf_num = 4; -+ struct rte_ring *ring = sock->send_ring; -+ -+ uint32_t replenish_cnt = gazelle_ring_free_count(ring); -+ if (replenish_cnt <= min_alloc_mbuf_num) { -+ return replenish_cnt; -+ } -+ -+ uint32_t resu = replenish_cnt; -+ uint32_t tcp_conn_count = get_global_cfg_params()->tcp_conn_count; -+ uint16_t send_ring_size = get_global_cfg_params()->send_ring_size; -+ uint16_t proportion = stack->conn_num / tcp_conn_count; -+ uint32_t replenish_mbuf_cnt_cal = (send_ring_size >> proportion); -+ -+ if (replenish_mbuf_cnt_cal <= min_alloc_mbuf_num) { -+ resu = min_alloc_mbuf_num; -+ } else if (replenish_mbuf_cnt_cal < replenish_cnt) { -+ resu = replenish_mbuf_cnt_cal; -+ } else { -+ resu = replenish_cnt + 1; -+ } -+ -+ return resu - 1; -+} -+ - /* true: need replenish again */ - static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_sock *sock) - { - void *pbuf[SOCK_SEND_RING_SIZE_MAX]; -- - struct rte_ring *ring = sock->send_ring; - -- uint32_t replenish_cnt = gazelle_ring_free_count(ring); -+ uint32_t replenish_cnt = update_replenish_mbuf_cnt(stack, sock); - if (replenish_cnt == 0) { - return false; - } -- - if (dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)pbuf, replenish_cnt, true) != 0) { - stack->stats.tx_allocmbuf_fail++; - return true; -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 8cb0020..4d10ac2 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -34,7 +34,7 @@ - #define SOCK_RECV_RING_SIZE_MAX (2048) - #define SOCK_SEND_RING_SIZE_MAX (2048) - --#define MBUFPOOL_RESERVE_NUM (get_global_cfg_params()->rxqueue_size + 1024) -+#define MBUFPOOL_RESERVE_NUM (2 * get_global_cfg_params()->rxqueue_size + 1024) - - struct protocol_stack { - uint32_t tid; --- -2.33.0 - diff --git a/0262-add-pingpong-dfx-support.patch b/0262-add-pingpong-dfx-support.patch deleted file mode 100644 index f23a349c8661393e29a850fa2ebe18251a3f668b..0000000000000000000000000000000000000000 --- a/0262-add-pingpong-dfx-support.patch +++ /dev/null @@ -1,67 +0,0 @@ -From 8de32dd108ac0666aabf01aa68b017389a390b26 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Fri, 27 Sep 2024 15:41:42 +0800 -Subject: [PATCH] add pingpong dfx support - ---- - src/common/gazelle_dfx_msg.h | 1 + - src/lstack/core/lstack_lwip.c | 1 + - src/ltran/ltran_dfx.c | 7 ++++--- - 3 files changed, 6 insertions(+), 3 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 08f9df1..266c239 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -281,6 +281,7 @@ struct gazelle_stat_lstack_conn_info { - uint32_t keep_idle; - uint32_t keep_intvl; - uint32_t keep_cnt; -+ uint8_t pingpong; - }; - - struct gazelle_stat_lstack_conn { -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 7677e46..2eb872c 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -1257,6 +1257,7 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - conn->keep_idle = pcb->keep_idle; - conn->keep_intvl = pcb->keep_intvl; - conn->keep_cnt = pcb->keep_cnt; -+ conn->pingpong = tcp_in_pingpong(pcb); - - if (netconn != NULL) { - conn->fd = netconn->callback_arg.socket; -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index fc30054..7fa117a 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -1242,7 +1242,7 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - printf("No. Proto lwip_recv recv_ring in_send send_ring cwn rcv_wnd snd_wnd snd_buf snd_nxt" - " lastack rcv_nxt events epoll_ev evlist fd Local Address" - " Foreign Address State" -- " keep-alive keep-alive(idle,intvl,cnt)\n"); -+ " keep-alive keep-alive(idle,intvl,cnt) pingpong\n"); - uint32_t unread_pkts = 0; - uint32_t unsend_pkts = 0; - for (i = 0; i < conn->conn_num && i < GAZELLE_LSTACK_MAX_CONN; i++) { -@@ -1261,12 +1261,13 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port); - sprintf_s(str_raddr, sizeof(str_raddr), "%s:%hu", str_rip, conn_info->r_port); - printf("%-6utcp %-10u%-10u%-8u%-10u%-9d%-9d%-10d%-10d%-15u%-15u%-15u%-10x%-10x%-7d%-7d" -- "%-52s %-52s %s %-5d %s\n", i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send, -+ "%-52s %-52s %s %-5d %s %d\n", -+ i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send, - conn_info->send_ring_cnt, conn_info->cwn, conn_info->rcv_wnd, conn_info->snd_wnd, - conn_info->snd_buf, conn_info->snd_nxt, conn_info->lastack, conn_info->rcv_nxt, conn_info->events, - conn_info->epoll_events, conn_info->eventlist, conn_info->fd, - str_laddr, str_raddr, tcp_state_to_str(conn_info->tcp_sub_state), -- conn_info->keepalive, keepalive_info_str); -+ conn_info->keepalive, keepalive_info_str, conn_info->pingpong); - } else if (conn_info->state == GAZELLE_LISTEN_LIST) { - inet_ntop(domain, lip, str_ip, sizeof(str_ip)); - sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port); --- -2.33.0 - diff --git a/0263-add-interrupt-mode-support.patch b/0263-add-interrupt-mode-support.patch deleted file mode 100644 index ce489342ca791600688fcb5ef26624e469a758bb..0000000000000000000000000000000000000000 --- a/0263-add-interrupt-mode-support.patch +++ /dev/null @@ -1,977 +0,0 @@ -From 2cfaac4ec2a653af30d7368fbc1c2bdec4fa8bdf Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sun, 29 Sep 2024 14:41:19 +0800 -Subject: [PATCH] add interrupt mode support - ---- - src/common/gazelle_dfx_msg.h | 10 + - src/lstack/core/lstack_cfg.c | 25 ++ - src/lstack/core/lstack_dpdk.c | 27 +- - src/lstack/core/lstack_init.c | 5 + - src/lstack/core/lstack_interrupt.c | 346 ++++++++++++++++++++++++ - src/lstack/core/lstack_protocol_stack.c | 24 +- - src/lstack/core/lstack_stack_stat.c | 6 + - src/lstack/core/lstack_thread_rpc.c | 10 +- - src/lstack/core/lstack_virtio.c | 9 + - src/lstack/include/lstack_cfg.h | 1 + - src/lstack/include/lstack_interrupt.h | 34 +++ - src/lstack/include/lstack_thread_rpc.h | 12 +- - src/lstack/include/lstack_tx_cache.h | 1 + - src/lstack/include/lstack_virtio.h | 2 +- - src/lstack/netif/lstack_tx_cache.c | 27 +- - src/lstack/netif/lstack_vdev.c | 2 + - src/ltran/ltran_dfx.c | 34 +++ - 17 files changed, 559 insertions(+), 16 deletions(-) - create mode 100644 src/lstack/core/lstack_interrupt.c - create mode 100644 src/lstack/include/lstack_interrupt.h - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 266c239..1a89e65 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -60,6 +60,7 @@ enum GAZELLE_STAT_MODE { - GAZELLE_STAT_LSTACK_SHOW_XSTATS, - GAZELLE_STAT_LSTACK_SHOW_AGGREGATE, - GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES, -+ GAZELLE_STAT_LSTACK_SHOW_INTR, - - #ifdef GAZELLE_FAULT_INJECT_ENABLE - GAZELLE_STAT_FAULT_INJECT_SET, -@@ -345,6 +346,14 @@ struct nic_eth_features { - uint64_t tx_offload; - }; - -+struct interrupt_stats { -+ uint64_t virtio_user_event_cnt; -+ uint64_t nic_event_cnt; -+ uint64_t remote_event_cnt; -+ uint64_t local_event_cnt; -+ uint64_t timeout_event_cnt; -+}; -+ - struct gazelle_stack_dfx_data { - /* indicates whether the current message is the last */ - uint32_t eof; -@@ -362,6 +371,7 @@ struct gazelle_stack_dfx_data { - struct nic_eth_xstats nic_xstats; - struct nic_eth_features nic_features; - struct gazelle_stat_lstack_proto proto_data; -+ struct interrupt_stats intr_stats; - - #ifdef GAZELLE_FAULT_INJECT_ENABLE - struct gazelle_fault_inject_data inject; -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 659a2a7..f239b60 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -85,6 +85,7 @@ 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); -+static int32_t parse_stack_interrupt(void); - - #define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \ - do { \ -@@ -152,6 +153,7 @@ static struct config_vector_t g_config_tbl[] = { - { "rpc_msg_max", parse_rpc_msg_max }, - { "send_cache_mode", parse_send_cache_mode }, - { "flow_bifurcation", parse_flow_bifurcation}, -+ { "stack_interrupt", parse_stack_interrupt}, - { NULL, NULL } - }; - -@@ -1383,3 +1385,26 @@ static int32_t parse_flow_bifurcation(void) - PARSE_ARG(g_config_params.flow_bifurcation, "flow_bifurcation", 0, 0, 1, ret); - return ret; - } -+ -+static int32_t parse_stack_interrupt(void) -+{ -+ int32_t ret; -+ PARSE_ARG(g_config_params.stack_interrupt, "stack_interrupt", false, false, true, ret); -+ if (ret != 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "cfg: invalid enable intr value %d. only support 0 or 1\n", \ -+ g_config_params.stack_interrupt); -+ } -+ -+ if (g_config_params.stack_interrupt == true) { -+ if (g_config_params.stack_mode_rtc == true) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "rtc mode not support interrupt mode now.\n"); -+ return -1; -+ } -+ if (g_config_params.bond_mode >= 0) { -+ LSTACK_PRE_LOG(LSTACK_ERR, "bond mode not support interrupt mode.\n"); -+ return -1; -+ } -+ } -+ -+ return ret; -+} -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 1fe0f0a..530332b 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -258,8 +258,8 @@ struct rte_mempool *create_mempool(const char *name, uint32_t count, uint32_t si - - int32_t create_shared_ring(struct protocol_stack *stack) - { -- rpc_queue_init(&stack->rpc_queue); -- rpc_queue_init(&stack->dfx_rpc_queue); -+ rpc_queue_init(&stack->rpc_queue, stack->queue_id); -+ rpc_queue_init(&stack->dfx_rpc_queue, stack->queue_id); - - if (use_ltran()) { - stack->rx_ring = gazelle_ring_create_fast("RING_RX", VDEV_RX_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ); -@@ -439,6 +439,7 @@ static int eth_params_init(struct eth_params *eth_params, uint16_t port_id, uint - eth_params->conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE; - /* used for tcp port alloc */ - eth_params->reta_mask = dev_info.reta_size - 1; -+ eth_params->conf.intr_conf.rxq = get_global_cfg_params()->stack_interrupt; - - eth_params_checksum(ð_params->conf, &dev_info); - -@@ -630,10 +631,11 @@ static int32_t dpdk_ethdev_setup(const struct eth_params *eth_params, uint16_t i - - int32_t dpdk_ethdev_start(void) - { -+ int i; - int32_t ret; - const struct protocol_stack_group *stack_group = get_protocol_stack_group(); - -- for (int32_t i = 0; i < get_global_cfg_params()->tot_queue_num; i++) { -+ for (i = 0; i < get_global_cfg_params()->tot_queue_num; i++) { - ret = dpdk_ethdev_setup(stack_group->eth_params, i); - if (ret < 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_setup fail queueid=%d, ret=%d\n", i, ret); -@@ -647,6 +649,14 @@ int32_t dpdk_ethdev_start(void) - return ret; - } - -+ /* after rte_eth_dev_start */ -+ for (i = 0; i < get_global_cfg_params()->tot_queue_num; i++) { -+ struct intr_dpdk_event_args intr_arg; -+ intr_arg.port_id = stack_group->eth_params->port_id; -+ intr_arg.queue_id = i; -+ intr_register(i, INTR_DPDK_EVENT, &intr_arg); -+ } -+ - return 0; - } - -@@ -799,10 +809,21 @@ int init_dpdk_ethdev(void) - } - port_id = rte_eth_bond_primary_get(get_protocol_stack_group()->port_id); - } else { -+ struct rte_eth_dev_info dev_info; - port_id = ethdev_port_id(cfg->mac_addr); - if (port_id < 0) { - return -1; - } -+ -+ if (rte_eth_dev_info_get(port_id, &dev_info) < 0) { -+ return -1; -+ } -+ if (strcmp(dev_info.driver_name, "net_hinic") == 0 && -+ get_global_cfg_params()->stack_interrupt == true) { -+ LSTACK_LOG(ERR, LSTACK, "hinic not support interrupt mode\n"); -+ return -1; -+ } -+ - ret = dpdk_ethdev_init(port_id); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed, port id=%d\n", port_id); -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 37264a1..5e405ee 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -45,6 +45,7 @@ - #include "lstack_preload.h" - #include "lstack_wrap.h" - #include "lstack_flow.h" -+#include "lstack_interrupt.h" - - static void check_process_start(void) - { -@@ -289,6 +290,10 @@ __attribute__((constructor)) void gazelle_network_init(void) - LSTACK_EXIT(1, "stack_group_init failed\n"); - } - -+ if (intr_init() < 0) { -+ LSTACK_EXIT(1, "intr init failed\n"); -+ } -+ - if (!use_ltran()) { - if (init_dpdk_ethdev() != 0) { - LSTACK_EXIT(1, "init_dpdk_ethdev failed\n"); -diff --git a/src/lstack/core/lstack_interrupt.c b/src/lstack/core/lstack_interrupt.c -new file mode 100644 -index 0000000..26823cd ---- /dev/null -+++ b/src/lstack/core/lstack_interrupt.c -@@ -0,0 +1,346 @@ -+/* -+* 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 -+#include -+#include -+#include -+#include -+ -+#include -+#include -+ -+#include -+#include -+#include -+ -+#include "common/dpdk_common.h" -+#include "common/gazelle_opt.h" -+#include "common/gazelle_dfx_msg.h" -+#include "lstack_log.h" -+#include "lstack_cfg.h" -+#include "lstack_interrupt.h" -+ -+#define INTR_MAX_EVENT_NUM 8 -+ -+struct intr_dpdk_event { -+ int rte_epfd; -+#define INTR_PORT_NUM 2 -+#define INTR_INVALID_PORT 65535 -+ uint16_t port_id[INTR_PORT_NUM]; /* 0: nic port id, 1: virtio_user port id */ -+ uint16_t queue_id[INTR_PORT_NUM]; -+}; -+ -+struct intr_local_event { -+ bool (*get_event) (uint16_t stack_id); -+}; -+ -+struct intr_remote_event { -+ int event_fd; -+}; -+ -+struct intr_policy { -+#define INTR_LOOP_TIMES 5 -+ uint8_t no_event_cnt; -+}; -+ -+struct intr_config { -+ int epoll_fd; /* used for epoll */ -+ uint16_t stack_id; -+ bool in_wait; -+ -+ struct intr_dpdk_event dpdk_event; -+ struct intr_local_event local_event; -+ struct intr_remote_event remote_event; -+ -+ struct intr_policy policy; -+ struct interrupt_stats stats; -+}; -+ -+static struct intr_config g_intr_configs[PROTOCOL_STACK_MAX] = {0}; -+ -+static inline struct intr_config *intr_config_get(uint16_t stack_id) -+{ -+ return &g_intr_configs[stack_id]; -+} -+ -+int intr_init(void) -+{ -+ int stack_id; -+ struct cfg_params *cfg = get_global_cfg_params(); -+ if (!cfg->stack_interrupt) { -+ return 0; -+ } -+ -+ for (stack_id = 0; stack_id < cfg->num_queue; stack_id++) { -+ struct intr_config *intr_config = intr_config_get(stack_id); -+ intr_config->epoll_fd = posix_api->epoll_create_fn(1); -+ if (intr_config->epoll_fd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "epoll create fd fialed, errno is %d\n", errno); -+ return -1; -+ } -+ -+ for (int i = 0; i < INTR_PORT_NUM; i++) { -+ intr_config->dpdk_event.port_id[i] = INTR_INVALID_PORT; -+ } -+ -+ if (intr_register(stack_id, INTR_REMOTE_EVENT, NULL) < 0) { -+ LSTACK_LOG(ERR, LSTACK, "register intr failed\n"); -+ return -1; -+ } -+ } -+ -+ return 0; -+} -+ -+static inline int add_fd_to_epoll(int fd, int epoll_fd) -+{ -+ struct epoll_event event ; -+ event.data.fd = fd ; -+ event.events = EPOLLIN | EPOLLPRI | EPOLLRDHUP | EPOLLHUP ; -+ int ret = posix_api->epoll_ctl_fn(epoll_fd, EPOLL_CTL_ADD, fd, &event); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "add fd %d to epoll fd %d failed errno:%d ret=%d.\n", -+ fd, epoll_fd, errno, ret); -+ return ret; -+ } -+ -+ return ret ; -+} -+ -+static inline int intr_local_event_register(struct intr_config *config, void *priv) -+{ -+ config->local_event.get_event = priv; -+ return 0; -+} -+ -+static int intr_dpdk_event_register(struct intr_config *config, void *priv) -+{ -+ struct intr_dpdk_event_args *arg = priv; -+ int i; -+ -+ if (arg == NULL) { -+ return -1; -+ } -+ -+ if (config->dpdk_event.rte_epfd <= 0) { -+ config->dpdk_event.rte_epfd = posix_api->epoll_create_fn(1); -+ if (config->dpdk_event.rte_epfd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "epoll create fd fialed, errno is %d\n", errno); -+ return -1; -+ } -+ if (add_fd_to_epoll(config->dpdk_event.rte_epfd, config->epoll_fd) < 0) { -+ return -1; -+ } -+ } -+ -+ for (i = 0; i < INTR_PORT_NUM; i++) { -+ if (config->dpdk_event.port_id[i] == INTR_INVALID_PORT) { -+ config->dpdk_event.port_id[i] = arg->port_id; -+ break; -+ } -+ } -+ config->dpdk_event.queue_id[i] = arg->queue_id; -+ -+ int data = ((arg->port_id) << CHAR_BIT) | arg->queue_id; -+ if (rte_eth_dev_rx_intr_ctl_q(arg->port_id, arg->queue_id, config->dpdk_event.rte_epfd, -+ RTE_INTR_EVENT_ADD, (void *)((uintptr_t)data)) < 0) { -+ LSTACK_LOG(ERR, LSTACK, "rte_eth_dev_rx_intr_ctl_q failed, port(%d), queue(%d)\n", -+ arg->port_id, arg->queue_id); -+ return -1; -+ } -+ return 0; -+} -+ -+static int intr_remote_event_register(struct intr_config *config, void *priv) -+{ -+ struct intr_remote_event *remote_event = &config->remote_event; -+ if (remote_event->event_fd > 0) { -+ return 0; -+ } -+ -+ remote_event->event_fd = posix_api->eventfd_fn(0, 0); -+ if (remote_event->event_fd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "event fd create failed\n"); -+ return -1; -+ } -+ return add_fd_to_epoll(remote_event->event_fd, config->epoll_fd); -+} -+ -+int intr_register(uint16_t stack_id, enum intr_type type, void *priv) -+{ -+ struct cfg_params *cfg = get_global_cfg_params(); -+ if (!cfg->stack_interrupt) { -+ return 0; -+ } -+ -+ struct intr_config *config = intr_config_get(stack_id); -+ switch (type) { -+ case INTR_DPDK_EVENT: -+ return intr_dpdk_event_register(config, priv); -+ case INTR_REMOTE_EVENT: -+ return intr_remote_event_register(config, priv); -+ case INTR_LOCAL_EVENT: -+ return intr_local_event_register(config, priv); -+ default: -+ return -1; -+ } -+ return 0; -+} -+ -+static inline void intr_remote_event_enable(struct intr_config *config) -+{ -+ eventfd_t eventfd_num = 1; -+ if (__atomic_load_n(&config->in_wait, __ATOMIC_ACQUIRE)) { -+ posix_api->write_fn(config->remote_event.event_fd, &eventfd_num, sizeof(eventfd_t)); -+ } -+} -+ -+static inline void intr_remote_event_disable(struct intr_config *config) -+{ -+ eventfd_t read_num; -+ posix_api->read_fn(config->remote_event.event_fd, &read_num, sizeof(eventfd_t)); -+} -+ -+static inline bool intr_local_event(struct intr_config *config) -+{ -+ return config->local_event.get_event(config->stack_id); -+} -+ -+void intr_wakeup(uint16_t stack_id, enum intr_type type) -+{ -+ if (!get_global_cfg_params()->stack_interrupt) { -+ return; -+ } -+ -+ struct intr_config *config = intr_config_get(stack_id); -+ switch (type) { -+ case INTR_REMOTE_EVENT: -+ intr_remote_event_enable(config); -+ break; -+ default: -+ break; -+ } -+} -+ -+static inline void intr_dpdk_event_enable(struct intr_config *config) -+{ -+ int i; -+ int ret = 0; -+ struct intr_dpdk_event *dpdk_event = &config->dpdk_event; -+ -+ for (i = 0; i < INTR_PORT_NUM; i++) { -+ if (dpdk_event->port_id[i] != INTR_INVALID_PORT) { -+ ret = rte_eth_dev_rx_intr_enable(dpdk_event->port_id[i], dpdk_event->queue_id[i]); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "port(%d) queue(%d) enable interrupt failed\n", -+ dpdk_event->port_id[i], dpdk_event->queue_id[i]); -+ return; -+ } -+ } -+ } -+} -+ -+static inline void intr_dpdk_event_disable(struct intr_config *config) -+{ -+ int i, n; -+ void *data; -+ uint16_t port_id; -+ uint16_t queue_id; -+ struct intr_dpdk_event *dpdk_event = &config->dpdk_event; -+ struct rte_epoll_event event[INTR_MAX_EVENT_NUM]; -+ -+ n = rte_epoll_wait(dpdk_event->rte_epfd, event, INTR_MAX_EVENT_NUM, 1); -+ for (i = 0; i < n; i++) { -+ data = event[i].epdata.data; -+ port_id = ((uintptr_t)data) >> CHAR_BIT; -+ queue_id = ((uintptr_t)data) & RTE_LEN2MASK(CHAR_BIT, uint8_t); -+ -+ rte_eth_dev_rx_intr_disable(port_id, queue_id); -+ -+ if (port_id == dpdk_event->port_id[0]) { -+ config->stats.nic_event_cnt++; -+ } else { -+ config->stats.virtio_user_event_cnt++; -+ } -+ } -+} -+ -+static inline void intr_policy_clear(struct intr_config *config) -+{ -+ config->policy.no_event_cnt = 0; -+} -+ -+static inline bool intr_policy(struct intr_config *config) -+{ -+ if (config->policy.no_event_cnt++ < INTR_LOOP_TIMES) { -+ return true; -+ } -+ config->policy.no_event_cnt = 0; -+ return false; -+} -+ -+static inline void intr_block(uint16_t stack_id, uint32_t timeout) -+{ -+ struct epoll_event events[INTR_MAX_EVENT_NUM]; -+ struct intr_config *intr_config = intr_config_get(stack_id); -+ -+ /* in_wait need in here to avoid competion problem with remote event */ -+ __atomic_store_n(&intr_config->in_wait, true, __ATOMIC_RELEASE); -+ if (intr_local_event(intr_config)) { -+ intr_config->stats.local_event_cnt++; -+ __atomic_store_n(&intr_config->in_wait, false, __ATOMIC_RELEASE); -+ return; -+ } -+ -+ intr_dpdk_event_enable(intr_config); -+ -+ int32_t event_cnt = posix_api->epoll_wait_fn(intr_config->epoll_fd, events, INTR_MAX_EVENT_NUM, timeout); -+ __atomic_store_n(&intr_config->in_wait, false, __ATOMIC_RELEASE); -+ for (int i = 0; i < event_cnt; i++) { -+ if (events[i].data.fd == intr_config->dpdk_event.rte_epfd) { -+ intr_dpdk_event_disable(intr_config); -+ } else if (events[i].data.fd == intr_config->remote_event.event_fd) { -+ intr_remote_event_disable(intr_config); -+ intr_config->stats.remote_event_cnt++; -+ } else { -+ LSTACK_LOG(ERR, LSTACK, "unknow fd have event.\n"); -+ } -+ } -+ -+ if (event_cnt < 0) { -+ intr_config->stats.timeout_event_cnt++; -+ } -+} -+ -+void intr_wait(uint16_t stack_id, uint32_t timeout) -+{ -+ struct intr_config *intr_config = intr_config_get(stack_id); -+ -+ if (intr_policy(intr_config)) { -+ return; -+ } -+ -+ intr_block(stack_id, timeout); -+ -+ intr_policy_clear(intr_config); -+} -+ -+int intr_stats_get(uint16_t stack_id, void *ptr, int len) -+{ -+ struct intr_config *config = intr_config_get(stack_id); -+ if (len < sizeof(struct interrupt_stats)) { -+ return -1; -+ } -+ -+ return memcpy_s(ptr, len, &config->stats, sizeof(struct interrupt_stats)); -+} -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index d03b744..e412c3b 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -34,6 +34,8 @@ - #include "lstack_virtio.h" - #include "lstack_protocol_stack.h" - -+#include "lstack_interrupt.h" -+ - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - #include - #endif -@@ -480,13 +482,18 @@ int stack_polling(unsigned wakeup_tick) - uint32_t rpc_number = cfg->rpc_number; - uint32_t read_connect_number = cfg->read_connect_number; - struct protocol_stack *stack = get_protocol_stack(); -+ uint32_t timeout; - - /* 2: one dfx consumes two rpc */ - rpc_poll_msg(&stack->dfx_rpc_queue, 2); - force_quit = rpc_poll_msg(&stack->rpc_queue, rpc_number); - - eth_dev_poll(); -- sys_timer_run(); -+ timeout = sys_timer_run(); -+ if (cfg->stack_interrupt) { -+ intr_wait(stack->stack_idx, timeout); -+ } -+ - if (cfg->low_power_mod != 0) { - low_power_idling(stack); - } -@@ -496,6 +503,7 @@ int stack_polling(unsigned wakeup_tick) - } - - do_lwip_read_recvlist(stack, read_connect_number); -+ - if ((wakeup_tick & 0xf) == 0) { - wakeup_stack_epoll(stack); - if (get_global_cfg_params()->send_cache_mode) { -@@ -533,6 +541,19 @@ int stack_polling(unsigned wakeup_tick) - return force_quit; - } - -+static bool stack_local_event_get(uint16_t stack_id) -+{ -+ struct protocol_stack *stack = g_stack_group.stacks[stack_id]; -+ if (!lockless_queue_empty(&stack->dfx_rpc_queue.queue) || -+ !lockless_queue_empty(&stack->rpc_queue.queue) || -+ !list_head_empty(&stack->recv_list) || -+ !list_head_empty(&stack->wakeup_list) || -+ tx_cache_count(stack->queue_id)) { -+ return true; -+ } -+ return false; -+} -+ - static void* gazelle_stack_thread(void *arg) - { - struct thread_params *t_params = (struct thread_params*) arg; -@@ -541,6 +562,7 @@ static void* gazelle_stack_thread(void *arg) - unsigned wakeup_tick = 0; - - stack = stack_thread_init(arg); -+ intr_register(stack->stack_idx, INTR_LOCAL_EVENT, stack_local_event_get); - free(arg); - if (stack == NULL) { - LSTACK_LOG(ERR, LSTACK, "stack_thread_init failed queue_id=%hu\n", queue_id); -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index b6619f6..8efa5ab 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -325,6 +325,12 @@ static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protoc - LSTACK_LOG(ERR, LSTACK, "memcpy_s err ret=%d \n", ret); - } - break; -+ case GAZELLE_STAT_LSTACK_SHOW_INTR: -+ ret = intr_stats_get(stack->stack_idx, &dfx->data.intr_stats, sizeof(dfx->data.intr_stats)); -+ if (ret != EOK) { -+ LSTACK_LOG(ERR, LSTACK, "memcpy_s err ret=%d \n", ret); -+ } -+ break; - case GAZELLE_STAT_LSTACK_SHOW_VIRTIO: - ret = memcpy_s(&dfx->data.virtio, sizeof(dfx->data.virtio), virtio_instance_get(), - sizeof(*(virtio_instance_get()))); -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index b4a5953..7f77c12 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -100,7 +100,8 @@ __rte_always_inline - static void rpc_async_call(rpc_queue *queue, struct rpc_msg *msg) - { - msg->sync_flag = 0; -- lockless_queue_mpsc_push(queue, &msg->queue_node); -+ lockless_queue_mpsc_push(&queue->queue, &msg->queue_node); -+ intr_wakeup(queue->queue_id, INTR_REMOTE_EVENT); - } - - __rte_always_inline -@@ -111,7 +112,8 @@ static int rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg) - pthread_spin_trylock(&msg->lock); - - msg->sync_flag = 1; -- lockless_queue_mpsc_push(queue, &msg->queue_node); -+ lockless_queue_mpsc_push(&queue->queue, &msg->queue_node); -+ intr_wakeup(queue->queue_id, INTR_REMOTE_EVENT); - - // waiting stack unlock - pthread_spin_lock(&msg->lock); -@@ -123,7 +125,7 @@ static int rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg) - - int rpc_msgcnt(rpc_queue *queue) - { -- return lockless_queue_count(queue); -+ return lockless_queue_count(&queue->queue); - } - - static struct rpc_msg *rpc_msg_alloc_except(rpc_func_t func) -@@ -159,7 +161,7 @@ int rpc_poll_msg(rpc_queue *queue, int max_num) - struct rpc_msg *msg; - - while (max_num--) { -- lockless_queue_node *node = lockless_queue_mpsc_pop(queue); -+ lockless_queue_node *node = lockless_queue_mpsc_pop(&queue->queue); - if (node == NULL) { - break; - } -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index fefb06d..75a23f2 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -20,6 +20,7 @@ - #include "lstack_cfg.h" - #include "lstack_log.h" - #include "lstack_port_map.h" -+#include "lstack_interrupt.h" - #include "lstack_virtio.h" - #include "securec.h" - -@@ -274,6 +275,7 @@ static int virtio_port_init(uint16_t port) - return retval; - } - -+ port_conf.intr_conf.rxq = get_global_cfg_params()->stack_interrupt; - retval = rte_eth_dev_configure(port, rx_queue_num, tx_queue_num, &port_conf); - if (retval != 0) { - LSTACK_LOG(ERR, LSTACK, "rte_eth_dev_configure failed retval=%d\n", retval); -@@ -297,6 +299,13 @@ static int virtio_port_init(uint16_t port) - LSTACK_LOG(ERR, LSTACK, "rte_eth_rx_queue_setup failed (queue %u) retval=%d \n", q, retval); - return retval; - } -+ -+ if (port_conf.intr_conf.rxq) { -+ struct intr_dpdk_event_args intr_arg; -+ intr_arg.port_id = port; -+ intr_arg.queue_id = q; -+ intr_register(q, INTR_DPDK_EVENT, &intr_arg); -+ } - } - return 0; - } -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 5e2d6fc..071492d 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -118,6 +118,7 @@ struct cfg_params { - - bool stack_mode_rtc; - bool listen_shadow; // true:listen in all stack thread. false:listen in one stack thread. -+ bool stack_interrupt; - - uint32_t read_connect_number; - uint32_t nic_read_number; -diff --git a/src/lstack/include/lstack_interrupt.h b/src/lstack/include/lstack_interrupt.h -new file mode 100644 -index 0000000..1be7d07 ---- /dev/null -+++ b/src/lstack/include/lstack_interrupt.h -@@ -0,0 +1,34 @@ -+/* -+* 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 __LSTACK_INTERRUPT_H__ -+#define __LSTACK_INTERRUPT_H__ -+ -+enum intr_type { -+ INTR_DPDK_EVENT = 0, -+ INTR_LOCAL_EVENT, -+ INTR_REMOTE_EVENT, -+}; -+ -+struct intr_dpdk_event_args { -+ uint16_t port_id; -+ uint16_t queue_id; -+}; -+ -+int intr_init(void); -+int intr_register(uint16_t stack_id, enum intr_type type, void *priv); -+void intr_wakeup(uint16_t stack_id, enum intr_type type); -+void intr_wait(uint16_t stack_id, uint32_t timeout); -+int intr_stats_get(uint16_t stack_id, void *ptr, int len); -+ -+#endif -+ -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 6f8e03e..c284d29 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -17,6 +17,7 @@ - #include - - #include "lstack_lockless_queue.h" -+#include "lstack_interrupt.h" - - #define MSG_ARG_0 (0) - #define MSG_ARG_1 (1) -@@ -25,7 +26,11 @@ - #define MSG_ARG_4 (4) - #define RPM_MSG_ARG_SIZE (5) - --typedef struct lockless_queue rpc_queue; -+typedef struct rpc_queue rpc_queue; -+struct rpc_queue { -+ struct lockless_queue queue; -+ uint16_t queue_id; -+}; - - struct rpc_stats { - uint16_t call_null; -@@ -60,9 +65,10 @@ struct rpc_msg { - lockless_queue_node queue_node; - }; - --static inline void rpc_queue_init(rpc_queue *queue) -+static inline void rpc_queue_init(rpc_queue *queue, uint16_t queue_id) - { -- lockless_queue_init(queue); -+ lockless_queue_init(&queue->queue); -+ queue->queue_id = queue_id; - } - struct rpc_stats *rpc_stats_get(void); - int rpc_msgcnt(rpc_queue *queue); -diff --git a/src/lstack/include/lstack_tx_cache.h b/src/lstack/include/lstack_tx_cache.h -index 04e9e35..ccd9c17 100644 ---- a/src/lstack/include/lstack_tx_cache.h -+++ b/src/lstack/include/lstack_tx_cache.h -@@ -15,5 +15,6 @@ - - int tx_cache_init(uint16_t queue_id, void *priv, struct lstack_dev_ops *dev_ops); - int tx_cache_send(uint16_t queue_id); -+int tx_cache_count(uint16_t queue_id); - - #endif /* _LSTACK_TX_CACHE_H_ */ -diff --git a/src/lstack/include/lstack_virtio.h b/src/lstack/include/lstack_virtio.h -index 5298dbe..745c86b 100644 ---- a/src/lstack/include/lstack_virtio.h -+++ b/src/lstack/include/lstack_virtio.h -@@ -50,4 +50,4 @@ int virtio_port_create(int lstack_net_port); - - struct virtio_instance* virtio_instance_get(void); - bool virtio_distribute_pkg_to_kernel(uint16_t dst_port); --#endif -\ No newline at end of file -+#endif -diff --git a/src/lstack/netif/lstack_tx_cache.c b/src/lstack/netif/lstack_tx_cache.c -index 9a48307..17d3c3b 100644 ---- a/src/lstack/netif/lstack_tx_cache.c -+++ b/src/lstack/netif/lstack_tx_cache.c -@@ -58,22 +58,40 @@ int tx_cache_init(uint16_t queue_id, void *priv, struct lstack_dev_ops *dev_ops) - return 0; - } - -+int tx_cache_count(uint16_t queue_id) -+{ -+ struct tx_cache *tx_cache = g_tx_cache[queue_id]; -+ if (tx_cache == NULL) { -+ return 0; -+ } -+ uint32_t start = tx_cache->send_start; -+ uint32_t end = tx_cache->send_end; -+ uint32_t count = (end - start) & TX_CACHE_MASK; -+ uint32_t capacity = TX_CACHE_MAX - 1; -+ -+ return (count > capacity) ? capacity : count; -+} -+ - int tx_cache_send(uint16_t queue_id) - { -+ uint32_t send_num; -+ uint32_t sent_pkts = 0; -+ uint32_t start; -+ uint32_t end; -+ - struct tx_cache *tx_cache = g_tx_cache[queue_id]; - if (tx_cache == NULL) { - LSTACK_LOG(ERR, LSTACK, "queue(%d) tx cache get failed\n", queue_id); - return 0; - } - -- uint32_t send_num = tx_cache->send_end - tx_cache->send_start; -+ send_num = tx_cache_count(queue_id); - if (send_num == 0) { - return 0; - } - -- uint32_t start = tx_cache->send_start & TX_CACHE_MASK; -- uint32_t end = tx_cache->send_end & TX_CACHE_MASK; -- uint32_t sent_pkts = 0; -+ start = tx_cache->send_start & TX_CACHE_MASK; -+ end = tx_cache->send_end & TX_CACHE_MASK; - if (start < end) { - sent_pkts = g_tx_cache_dev_ops.tx_xmit(tx_cache->priv, &tx_cache->send_pkts[start], send_num); - } else { -@@ -85,6 +103,7 @@ int tx_cache_send(uint16_t queue_id) - } - - tx_cache->send_start += sent_pkts; -+ - return sent_pkts; - } - -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index e1a63a7..290046e 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -38,6 +38,8 @@ - #include "lstack_port_map.h" - #include "lstack_virtio.h" - -+#include "lstack_interrupt.h" -+ - /* INUSE_TX_PKTS_WATERMARK < VDEV_RX_QUEUE_SZ; - * USE_RX_PKTS_WATERMARK < FREE_RX_QUEUE_SZ. - * less, means more available mbuf. -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 7fa117a..f6d1148 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -138,6 +138,7 @@ static void gazelle_print_lstack_xstats(void *buf, const struct gazelle_stat_msg - static void gazelle_print_lstack_aggregate(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_nic_features(void *buf, const struct gazelle_stat_msg_request *req_msg); - static void gazelle_print_lstack_stat_proto(void *buf, const struct gazelle_stat_msg_request *req_msg); -+static void gazelle_print_lstack_stat_intr(void *buf, const struct gazelle_stat_msg_request *req_msg); - - #ifdef GAZELLE_FAULT_INJECT_ENABLE - static void gazelle_print_fault_inject_set_status(void *buf, const struct gazelle_stat_msg_request *req_msg); -@@ -172,6 +173,7 @@ static struct gazelle_dfx_list g_gazelle_dfx_tbl[] = { - {GAZELLE_STAT_LSTACK_SHOW_AGGREGATE, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_aggregate}, - {GAZELLE_STAT_LSTACK_SHOW_NIC_FEATURES, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_nic_features}, - {GAZELLE_STAT_LSTACK_SHOW_PROTOCOL, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_proto}, -+ {GAZELLE_STAT_LSTACK_SHOW_INTR, sizeof(struct gazelle_stack_dfx_data), gazelle_print_lstack_stat_intr}, - - #ifdef GAZELLE_FAULT_INJECT_ENABLE - {GAZELLE_STAT_FAULT_INJECT_SET, sizeof(struct gazelle_stack_dfx_data), gazelle_print_fault_inject_set_status}, -@@ -1136,6 +1138,17 @@ static void gazelle_print_lstack_stat_proto_core(const struct gazelle_stack_dfx_ - printf("rterr: %lu\n", proto->rterr); - } - -+static void gazelle_print_lstack_stat_intr_core(const struct gazelle_stack_dfx_data *stat, -+ const struct interrupt_stats *intr_stats) -+{ -+ printf("\n------ stack tid: %6u ------\n", stat->tid); -+ printf("nic_event_cnt: %lu\n", intr_stats->nic_event_cnt); -+ printf("virtio_user_event_cnt: %lu\n", intr_stats->virtio_user_event_cnt); -+ printf("local_event_cnt: %lu\n", intr_stats->local_event_cnt); -+ printf("remote_event_cnt: %lu\n", intr_stats->remote_event_cnt); -+ printf("timeout_event_cnt: %lu\n", intr_stats->timeout_event_cnt); -+} -+ - static void gazelle_print_lstack_stat_snmp(void *buf, const struct gazelle_stat_msg_request *req_msg) - { - int32_t ret; -@@ -1155,6 +1168,25 @@ static void gazelle_print_lstack_stat_snmp(void *buf, const struct gazelle_stat_ - } while (true); - } - -+static void gazelle_print_lstack_stat_intr(void *buf, const struct gazelle_stat_msg_request *req_msg) -+{ -+ int32_t ret; -+ struct gazelle_stack_dfx_data *stat = (struct gazelle_stack_dfx_data *)buf; -+ struct interrupt_stats *intr_stats = &stat->data.intr_stats; -+ -+ printf("Statistics of lstack interrupt:\n"); -+ do { -+ gazelle_print_lstack_stat_intr_core(stat, intr_stats); -+ if (stat->eof != 0) { -+ break; -+ } -+ ret = dfx_stat_read_from_ltran(buf, sizeof(struct gazelle_stack_dfx_data), req_msg->stat_mode); -+ if (ret != GAZELLE_OK) { -+ return; -+ } -+ } while (true); -+} -+ - static void gazelle_print_lstack_stat_proto(void *buf, const struct gazelle_stat_msg_request *req_msg) - { - int32_t ret; -@@ -1579,6 +1611,8 @@ static int32_t parse_dfx_lstack_show_args(int32_t argc, char *argv[], struct gaz - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_MODE_MAX; - } else if (strcmp(param, "snmp") == 0 || strcmp(param, "-s") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_SNMP; -+ } else if (strcmp(param, "intr") == 0 || strcmp(param, "-I") == 0) { -+ req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_INTR; - } else if (strcmp(param, "virtio") == 0 || strcmp(param, "-v") == 0) { - req_msg[cmd_index++].stat_mode = GAZELLE_STAT_LSTACK_SHOW_VIRTIO; - } else if (strcmp(param, "connect") == 0 || strcmp(param, "-c") == 0) { --- -2.33.0 - diff --git a/0264-af_xdp-set-rlimit-unlimit-when-gazelle-init.patch b/0264-af_xdp-set-rlimit-unlimit-when-gazelle-init.patch deleted file mode 100644 index 79553f4f6bda8e706152d7bc745453de01b46870..0000000000000000000000000000000000000000 --- a/0264-af_xdp-set-rlimit-unlimit-when-gazelle-init.patch +++ /dev/null @@ -1,57 +0,0 @@ -From 7e6a5d97430f0d178c5e2b211c0c194fdea0c00a Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Fri, 27 Sep 2024 06:32:41 +0800 -Subject: [PATCH] af_xdp: set rlimit unlimit when gazelle init - ---- - src/lstack/core/lstack_init.c | 20 ++++++++++++++++++++ - 1 file changed, 20 insertions(+) - -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 37264a1..1d27f68 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -17,6 +17,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -104,6 +105,20 @@ static int32_t check_process_conflict(void) - return 0; - } - -+/* Remove the memory resource limit of the current process. -+ * if the number of locked memory resources is exceeded, xdp_umem_create fails. -+ */ -+static int set_rlimit_unlimited(void) -+{ -+ struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; -+ -+ if (setrlimit(RLIMIT_MEMLOCK, &r) != 0) { -+ return -1; -+ } -+ -+ return 0; -+} -+ - void gazelle_exit(void) - { - wrap_api_exit(); -@@ -240,6 +255,11 @@ __attribute__((constructor)) void gazelle_network_init(void) - - wrap_api_init(); - -+ if (set_rlimit_unlimited() != 0) { -+ LSTACK_PRE_LOG(LSTACK_INFO, "set rlimit unlimited failed\n"); -+ LSTACK_EXIT(1, "set rlimit unlimited failed\n"); -+ } -+ - /* check primary process start */ - check_process_start(); - --- -2.33.0 - diff --git a/0265-fix-stack-null-when-register-interrupt.patch b/0265-fix-stack-null-when-register-interrupt.patch deleted file mode 100644 index 3e35ac7aa2511aba963140fb8e089c06e2701640..0000000000000000000000000000000000000000 --- a/0265-fix-stack-null-when-register-interrupt.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 14faa8f3a28490367c41c32ccb714ca4e743775d Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Mon, 30 Sep 2024 14:46:55 +0800 -Subject: [PATCH] fix stack null when register interrupt - ---- - src/lstack/core/lstack_protocol_stack.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index e412c3b..553dff3 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -562,7 +562,6 @@ static void* gazelle_stack_thread(void *arg) - unsigned wakeup_tick = 0; - - stack = stack_thread_init(arg); -- intr_register(stack->stack_idx, INTR_LOCAL_EVENT, stack_local_event_get); - free(arg); - if (stack == NULL) { - LSTACK_LOG(ERR, LSTACK, "stack_thread_init failed queue_id=%hu\n", queue_id); -@@ -577,6 +576,7 @@ static void* gazelle_stack_thread(void *arg) - return NULL; - } - -+ intr_register(stack->stack_idx, INTR_LOCAL_EVENT, stack_local_event_get); - stack_set_state(stack, RUNNING); - - while (stack_polling(wakeup_tick) == 0) { --- -2.33.0 - diff --git a/0266-rtw-fix-send-length-exceeding-send_ring_size.patch b/0266-rtw-fix-send-length-exceeding-send_ring_size.patch deleted file mode 100644 index 6f53ca85bb15ea484d0366059f92f2963f514ebd..0000000000000000000000000000000000000000 --- a/0266-rtw-fix-send-length-exceeding-send_ring_size.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 26550111abb490691a8b774f8bcc5a11a5a1cd9a Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 30 Sep 2024 11:33:05 +0800 -Subject: [PATCH] rtw: fix send length exceeding send_ring_size - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_lwip.c | 31 +++++++++++++++++++++++++++++-- - 1 file changed, 29 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 2eb872c..cb0964b 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -538,8 +538,8 @@ static ssize_t do_lwip_udp_fill_sendring(struct lwip_sock *sock, const void *buf - return send_len; - } - --static ssize_t do_lwip_tcp_fill_sendring(struct lwip_sock *sock, const void *buf, size_t len, -- const struct sockaddr *addr, socklen_t addrlen) -+static ssize_t __do_lwip_tcp_fill_sendring(struct lwip_sock *sock, const void *buf, size_t len, -+ const struct sockaddr *addr, socklen_t addrlen) - { - /* refer to the lwip implementation. */ - if (len == 0) { -@@ -566,6 +566,10 @@ static ssize_t do_lwip_tcp_fill_sendring(struct lwip_sock *sock, const void *buf - if (sock->errevent > 0) { - GAZELLE_RETURN(ENOTCONN); - } -+ /* wait until (send_ring_size / 4) */ -+ if (write_avail > (rte_ring_get_capacity(sock->send_ring) >> 2)) { -+ break; -+ } - write_avail = gazelle_ring_readable_count(sock->send_ring); - } - -@@ -600,6 +604,29 @@ END: - return send_len; - } - -+static inline void notice_stack_tcp_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags); -+static ssize_t do_lwip_tcp_fill_sendring(struct lwip_sock *sock, const void *buf, size_t len, -+ const struct sockaddr *addr, socklen_t addrlen) -+{ -+ ssize_t ret, send_len = 0; -+ -+ while (true) { -+ ret = __do_lwip_tcp_fill_sendring(sock, (char *)buf + send_len, len - send_len, addr, addrlen); -+ // send = 0 : tcp peer close connection ? -+ if (unlikely(ret <= 0)) { -+ break; -+ } -+ send_len += ret; -+ if (send_len == len || netconn_is_nonblocking(sock->conn)) { -+ break; -+ } -+ -+ notice_stack_tcp_send(sock, sock->conn->callback_arg.socket, ret, 0); -+ } -+ -+ return send_len == 0 ? ret : send_len; -+} -+ - bool do_lwip_replenish_sendring(struct protocol_stack *stack, struct lwip_sock *sock) - { - bool replenish_again = false; --- -2.33.0 - diff --git a/0267-rpc-fix-rpc_sync_call-spinlock-block-when-msg-be-rec.patch b/0267-rpc-fix-rpc_sync_call-spinlock-block-when-msg-be-rec.patch deleted file mode 100644 index b32c87c245aaf87f4a9bf68d6a04f3d156aefc13..0000000000000000000000000000000000000000 --- a/0267-rpc-fix-rpc_sync_call-spinlock-block-when-msg-be-rec.patch +++ /dev/null @@ -1,84 +0,0 @@ -From 870caa8931a9f6a068172e56d7e401cd4b9b4086 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Tue, 8 Oct 2024 20:39:37 +0800 -Subject: [PATCH] rpc: fix rpc_sync_call spinlock block when msg be recalled - ---- - src/lstack/core/lstack_thread_rpc.c | 21 +++++++++++++-------- - 1 file changed, 13 insertions(+), 8 deletions(-) - -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 7f77c12..aed792d 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -97,13 +97,19 @@ static void rpc_msg_free(struct rpc_msg *msg) - } - - __rte_always_inline --static void rpc_async_call(rpc_queue *queue, struct rpc_msg *msg) -+static void rpc_call(rpc_queue *queue, struct rpc_msg *msg) - { -- msg->sync_flag = 0; - lockless_queue_mpsc_push(&queue->queue, &msg->queue_node); - intr_wakeup(queue->queue_id, INTR_REMOTE_EVENT); - } - -+__rte_always_inline -+static void rpc_async_call(rpc_queue *queue, struct rpc_msg *msg) -+{ -+ msg->sync_flag = 0; -+ rpc_call(queue, msg); -+} -+ - __rte_always_inline - static int rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg) - { -@@ -112,8 +118,7 @@ static int rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg) - pthread_spin_trylock(&msg->lock); - - msg->sync_flag = 1; -- lockless_queue_mpsc_push(&queue->queue, &msg->queue_node); -- intr_wakeup(queue->queue_id, INTR_REMOTE_EVENT); -+ rpc_call(queue, msg); - - // waiting stack unlock - pthread_spin_lock(&msg->lock); -@@ -209,7 +214,7 @@ static void callback_close(struct rpc_msg *msg) - - if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { - msg->recall_flag = 1; -- rpc_async_call(&stack->rpc_queue, msg); /* until stack_send recall finish */ -+ rpc_call(&stack->rpc_queue, msg); /* until stack_send recall finish */ - return; - } - -@@ -228,7 +233,7 @@ static void callback_shutdown(struct rpc_msg *msg) - - if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { - msg->recall_flag = 1; -- rpc_async_call(&stack->rpc_queue, msg); -+ rpc_call(&stack->rpc_queue, msg); - return; - } - -@@ -586,7 +591,7 @@ static void callback_tcp_send(struct rpc_msg *msg) - if (ret > 0 || NETCONN_IS_DATAOUT(sock)) { - if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1) { - msg->recall_flag = 1; -- rpc_async_call(&stack->rpc_queue, msg); -+ rpc_call(&stack->rpc_queue, msg); - return; - } - } -@@ -675,7 +680,7 @@ static void callback_replenish_sendring(struct rpc_msg *msg) - msg->result = do_lwip_replenish_sendring(stack, sock); - if (msg->result == true) { - msg->recall_flag = 1; -- rpc_async_call(&stack->rpc_queue, msg); -+ rpc_call(&stack->rpc_queue, msg); - } - } - --- -2.33.0 - diff --git a/0268-bugfix-fix-gazelle-init-failed-while-setup-by-non-ro.patch b/0268-bugfix-fix-gazelle-init-failed-while-setup-by-non-ro.patch deleted file mode 100644 index b4019c178d9f93684465a6b13169bd868bea8969..0000000000000000000000000000000000000000 --- a/0268-bugfix-fix-gazelle-init-failed-while-setup-by-non-ro.patch +++ /dev/null @@ -1,39 +0,0 @@ -From 6b489d5555a2d28c37bb64f995962239f4e91624 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Tue, 8 Oct 2024 20:25:34 +0800 -Subject: [PATCH] bugfix: fix gazelle init failed while setup by non-root user - ---- - src/lstack/core/lstack_init.c | 3 +-- - src/lstack/include/lstack_log.h | 1 + - 2 files changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 53e25b4..a72af84 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -257,8 +257,7 @@ __attribute__((constructor)) void gazelle_network_init(void) - wrap_api_init(); - - if (set_rlimit_unlimited() != 0) { -- LSTACK_PRE_LOG(LSTACK_INFO, "set rlimit unlimited failed\n"); -- LSTACK_EXIT(1, "set rlimit unlimited failed\n"); -+ LSTACK_PRE_LOG(LSTACK_WARNING, "set rlimit unlimited failed. errno=%d\n", errno); - } - - /* check primary process start */ -diff --git a/src/lstack/include/lstack_log.h b/src/lstack/include/lstack_log.h -index e4bed37..a48e02f 100644 ---- a/src/lstack/include/lstack_log.h -+++ b/src/lstack/include/lstack_log.h -@@ -23,6 +23,7 @@ - - #define LSTACK_INFO LOG_INFO - #define LSTACK_ERR LOG_ERR -+#define LSTACK_WARNING LOG_WARNING - - /* before rte_eal_init */ - #define LSTACK_PRE_LOG(level, fmt, ...) \ --- -2.33.0 - diff --git a/0269-xdp-skip-checksum-temporarily-due-to-kernel-cannot-t.patch b/0269-xdp-skip-checksum-temporarily-due-to-kernel-cannot-t.patch deleted file mode 100644 index 243d7be5080b4e57b5c39169bd38ed933c997ffd..0000000000000000000000000000000000000000 --- a/0269-xdp-skip-checksum-temporarily-due-to-kernel-cannot-t.patch +++ /dev/null @@ -1,97 +0,0 @@ -From 77f34bd4406093dd47ec1fd60332ac5fd0f685a3 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Wed, 9 Oct 2024 21:05:34 +0800 -Subject: [PATCH] xdp: skip checksum temporarily due to kernel cannot transfer - offloads - ---- - src/lstack/core/lstack_dpdk.c | 10 ++++++++++ - src/lstack/include/lstack_dpdk.h | 2 ++ - src/lstack/netif/lstack_ethdev.c | 8 +++++++- - src/lstack/netif/lstack_vdev.c | 5 +++-- - 4 files changed, 22 insertions(+), 3 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 530332b..33605b3 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -50,6 +50,7 @@ - - struct eth_params { - uint16_t port_id; -+ bool is_xdp; - - uint16_t nb_queues; - uint16_t nb_rx_desc; -@@ -413,6 +414,12 @@ static int eth_params_rss(struct rte_eth_conf *conf, struct rte_eth_dev_info *de - return rss_enable; - } - -+bool dpdk_nic_is_xdp(void) -+{ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ return stack_group->eth_params->is_xdp; -+} -+ - static int eth_params_init(struct eth_params *eth_params, uint16_t port_id, uint16_t nb_queues, int *rss_enable) - { - struct rte_eth_dev_info dev_info; -@@ -442,6 +449,9 @@ static int eth_params_init(struct eth_params *eth_params, uint16_t port_id, uint - eth_params->conf.intr_conf.rxq = get_global_cfg_params()->stack_interrupt; - - eth_params_checksum(ð_params->conf, &dev_info); -+ if (strcmp(dev_info.driver_name, "net_af_xdp") == 0) { -+ eth_params->is_xdp = true; -+ } - - if (!get_global_cfg_params()->tuple_filter) { - *rss_enable = eth_params_rss(ð_params->conf, &dev_info); -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index 965a0cb..0210843 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -65,4 +65,6 @@ int32_t dpdk_init_lstack_kni(void); - 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); -+ - #endif /* GAZELLE_DPDK_H */ -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 1a721f6..315cced 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -364,7 +364,13 @@ static err_t eth_dev_init(struct netif *netif) - - netif->hwaddr_len = ETHER_ADDR_LEN; - -- netif_set_rxol_flags(netif, get_protocol_stack_group()->rx_offload); -+ if (dpdk_nic_is_xdp()) { -+ netif_set_rxol_flags(netif, RTE_ETH_RX_OFFLOAD_TCP_CKSUM | -+ RTE_ETH_RX_OFFLOAD_UDP_CKSUM | -+ RTE_ETH_RX_OFFLOAD_IPV4_CKSUM); -+ } else { -+ netif_set_rxol_flags(netif, get_protocol_stack_group()->rx_offload); -+ } - netif_set_txol_flags(netif, get_protocol_stack_group()->tx_offload); - if (get_global_cfg_params()->stack_mode_rtc) { - netif_set_rtc_mode(netif); -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 290046e..b1d1a1b 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -146,8 +146,9 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt - return pkt_num; - } - -- /* skip gro when tcp/ip cksum offloads disable */ -- if (get_protocol_stack_group()->rx_offload == 0 || (get_global_cfg_params()->vlan_mode >= 0 -+ if (get_protocol_stack_group()->rx_offload == 0 || /* skip gro when tcp/ip cksum offloads disable */ -+ dpdk_nic_is_xdp() || /* kernel has done GRO */ -+ (get_global_cfg_params()->vlan_mode >= 0 - && !(get_protocol_stack_group()->rx_offload & RTE_ETH_RX_OFFLOAD_VLAN_STRIP))) { - return pkt_num; - } --- -2.33.0 - diff --git a/0270-fix-dpdk_nic_is_xdp-coredump-in-ltran-mode.patch b/0270-fix-dpdk_nic_is_xdp-coredump-in-ltran-mode.patch deleted file mode 100644 index 1cea7d6c24722fcc83105c8db46161cff8c1842f..0000000000000000000000000000000000000000 --- a/0270-fix-dpdk_nic_is_xdp-coredump-in-ltran-mode.patch +++ /dev/null @@ -1,27 +0,0 @@ -From ba4115c3e56f32fb5186cd178b36974367723df9 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Thu, 10 Oct 2024 17:55:53 +0800 -Subject: [PATCH] fix dpdk_nic_is_xdp coredump in ltran mode - ---- - src/lstack/core/lstack_dpdk.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 33605b3..9294c5b 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -417,6 +417,10 @@ static int eth_params_rss(struct rte_eth_conf *conf, struct rte_eth_dev_info *de - bool dpdk_nic_is_xdp(void) - { - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ /* eth_params is null in ltran mode */ -+ if (stack_group->eth_params == NULL) { -+ return false; -+ } - return stack_group->eth_params->is_xdp; - } - --- -2.33.0 - diff --git a/0271-fix-the-coredump-when-gazellectl-l.patch b/0271-fix-the-coredump-when-gazellectl-l.patch deleted file mode 100644 index d42795864f60eeeede4b68547127a12853ec12a6..0000000000000000000000000000000000000000 --- a/0271-fix-the-coredump-when-gazellectl-l.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 577698e8a9a44d5689a7608e7bfbe27ed6529a54 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Fri, 11 Oct 2024 10:48:03 +0800 -Subject: [PATCH] fix the coredump when gazellectl -l - ---- - src/lstack/core/lstack_stack_stat.c | 6 +++++- - 1 file changed, 5 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 8efa5ab..c88da8f 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -64,7 +64,7 @@ void time_stamp_record(int fd, struct pbuf *pbuf) - { - struct lwip_sock *sock = lwip_get_socket(fd); - -- if (get_protocol_stack_group()->latency_start && sock && pbuf) { -+ if (get_protocol_stack_group()->latency_start && sock && sock->stack && pbuf) { - calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_INTO_MBOX, 0); - time_stamp_into_recvmbox(sock); - } -@@ -122,6 +122,10 @@ void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const - } - - lt = &pbuf_to_private(pbuf)->lt; -+ if (lt == NULL) { -+ return; -+ } -+ - lt_type = (type / GAZELLE_LATENCY_READ_MAX) ? GAZELLE_LATENCY_WR : GAZELLE_LATENCY_RD; - if (lt->stamp != ~(lt->check) || lt->stamp < stack_latency->start_time || lt_type != lt->type) { - return; --- -2.33.0 - diff --git a/0272-control-call-epoll_ctl-delete-fd-when-fd-close.patch b/0272-control-call-epoll_ctl-delete-fd-when-fd-close.patch deleted file mode 100644 index 2361cfe2d151948401c0d9bbb310fe6b38eb23e7..0000000000000000000000000000000000000000 --- a/0272-control-call-epoll_ctl-delete-fd-when-fd-close.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 2c8bf41f4adf425afc668b77c2a792abcdd98c5b Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Thu, 17 Oct 2024 19:16:55 +0800 -Subject: [PATCH] control: call epoll_ctl delete fd when fd close - ---- - src/lstack/core/lstack_control_plane.c | 8 ++++++++ - src/lstack/core/lstack_lwip.c | 4 ++++ - 2 files changed, 12 insertions(+) - -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 11f5129..bf34693 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -778,6 +778,12 @@ void control_server_thread(void *arg) - } - - if ((evt_array.events & EPOLLERR) || (evt_array.events & EPOLLHUP)) { -+ /* -+ * if app call fork and child process inherits the fd, -+ * close fd cannot ensure that fd is removed from the epoll, -+ * so epoll_ctl_del need to be called. -+ */ -+ posix_api->epoll_ctl_fn(epfd, EPOLL_CTL_DEL, evt_array.data.fd, NULL); - posix_api->close_fn(evt_array.data.fd); - continue; - } -@@ -795,6 +801,8 @@ void control_server_thread(void *arg) - } - } else { - if (handle_stat_request(evt_array.data.fd) < 0) { -+ /* same as the comment above */ -+ posix_api->epoll_ctl_fn(epfd, EPOLL_CTL_DEL, evt_array.data.fd, NULL); - posix_api->close_fn(evt_array.data.fd); - } - } -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index cb0964b..bb261d2 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -185,6 +185,10 @@ int do_lwip_init_sock(int32_t fd) - return 0; - } - -+ if (sock->recv_ring != NULL || sock->send_ring != NULL) { -+ LSTACK_LOG(ERR, LSTACK, "socket(%d) not close but open again?\n", fd); -+ } -+ - reset_sock_data(sock); - - sock->recv_ring = gazelle_ring_create_fast("sock_recv", SOCK_RECV_RING_SIZE, RING_F_SP_ENQ | RING_F_SC_DEQ); --- -2.33.0 - diff --git a/0273-epoll-remove-unnecessary-judgment-code.patch b/0273-epoll-remove-unnecessary-judgment-code.patch deleted file mode 100644 index 25bede0c6078c604d59ac9f4b325eededfd53dc8..0000000000000000000000000000000000000000 --- a/0273-epoll-remove-unnecessary-judgment-code.patch +++ /dev/null @@ -1,34 +0,0 @@ -From 0cecec15dad5d4baecceb343e1803eaa9c66de26 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Tue, 22 Oct 2024 10:14:58 +0800 -Subject: [PATCH] epoll: remove unnecessary judgment code - ---- - src/lstack/api/lstack_epoll.c | 11 ----------- - 1 file changed, 11 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index ce3d267..acbf393 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -122,17 +122,6 @@ void wakeup_stack_epoll(struct protocol_stack *stack) - struct list_node *node, *temp; - - list_for_each_node(node, temp, &stack->wakeup_list) { -- /* When temp is NULL, find the tail node in the wekeup_list and connect it to the back of the node */ -- if (unlikely(temp == NULL)) { -- struct list_node *nod = &stack->wakeup_list; -- while (nod->prev && nod->prev != node) { -- nod = nod->prev; -- } -- nod->prev = node; -- node->next = nod; -- temp = nod; -- } -- - struct wakeup_poll *wakeup = container_of_uncheck_ptr((node - stack->stack_idx), struct wakeup_poll, wakeup_list); - - if (__atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { --- -2.33.0 - diff --git a/0274-slove-compile-err-when-GAZELLE_TCP_REUSE_IPPORT-is-o.patch b/0274-slove-compile-err-when-GAZELLE_TCP_REUSE_IPPORT-is-o.patch deleted file mode 100644 index f665305c97aff30cfc0e14627818769c1b83f343..0000000000000000000000000000000000000000 --- a/0274-slove-compile-err-when-GAZELLE_TCP_REUSE_IPPORT-is-o.patch +++ /dev/null @@ -1,50 +0,0 @@ -From d64a161fb935b8fbfd69781a5cf891d2cebed2df Mon Sep 17 00:00:00 2001 -From: hkk -Date: Fri, 25 Oct 2024 16:55:23 +0800 -Subject: [PATCH] slove compile err when GAZELLE_TCP_REUSE_IPPORT is off - ---- - src/lstack/api/lstack_rtw_api.c | 9 +++++---- - 1 file changed, 5 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index 7ceff20..8765463 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -233,8 +233,9 @@ static int stack_broadcast_listen(int fd, int backlog) - } - - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+#if GAZELLE_TCP_REUSE_IPPORT - int min_conn_stk_idx = get_min_conn_stack(stack_group); -- -+#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) { -@@ -249,13 +250,13 @@ static int stack_broadcast_listen(int fd, int backlog) - } else { - clone_fd = fd; - } -- -+#if GAZELLE_TCP_REUSE_IPPORT - if (min_conn_stk_idx == i) { - lwip_get_socket(clone_fd)->conn->is_master_fd = 1; - } else { - lwip_get_socket(clone_fd)->conn->is_master_fd = 0; - } -- -+#endif - ret = rpc_call_listen(&stack->rpc_queue, clone_fd, backlog); - if (ret < 0) { - stack_broadcast_close(fd); -@@ -546,4 +547,4 @@ void rtw_api_init(posix_api_t *api) - - api->poll_fn = rtw_poll; - api->select_fn = rtw_select; --} -\ No newline at end of file -+} --- -2.33.0 - diff --git a/0275-bugfix-start-fail-when-executing-the-popen-command-f.patch b/0275-bugfix-start-fail-when-executing-the-popen-command-f.patch deleted file mode 100644 index 61c061f718df80442e40247e68fecd5a6441feac..0000000000000000000000000000000000000000 --- a/0275-bugfix-start-fail-when-executing-the-popen-command-f.patch +++ /dev/null @@ -1,25 +0,0 @@ -From e2ab6a041aa5587c6e6d021c32da2ce4d98522b2 Mon Sep 17 00:00:00 2001 -From: hankangkang -Date: Wed, 30 Oct 2024 11:15:55 +0800 -Subject: [PATCH] bugfix: start fail when executing the popen command for the - second time in openGauss - ---- - src/lstack/core/lstack_init.c | 1 - - 1 file changed, 1 deletion(-) - -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index a72af84..8ffc3a1 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -98,7 +98,6 @@ static int32_t check_process_conflict(void) - } - - ret = flock((fileno(fp)), LOCK_EX | LOCK_NB); -- (void)fclose(fp); - if (ret < 0) { - return -1; - } --- -2.33.0 - diff --git a/0276-Fix-annotation-errors.patch b/0276-Fix-annotation-errors.patch deleted file mode 100644 index 967c847be08d9e2a4f2804d781a4f21c280b8026..0000000000000000000000000000000000000000 --- a/0276-Fix-annotation-errors.patch +++ /dev/null @@ -1,73 +0,0 @@ -From 1005ad274d1a59d8a2d60fc280eae38f43c90dbe Mon Sep 17 00:00:00 2001 -From: lixiang -Date: Fri, 11 Oct 2024 09:58:44 +0800 -Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BF=AE=E6=94=B9?= -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - ---- - examples/inc/server.h | 12 ++++++------ - 1 file changed, 6 insertions(+), 6 deletions(-) - -diff --git a/examples/inc/server.h b/examples/inc/server.h -index 4631a28..35773e1 100644 ---- a/examples/inc/server.h -+++ b/examples/inc/server.h -@@ -33,7 +33,7 @@ struct ServerMumUnit - uint64_t recv_bytes; ///< total receive bytes - struct ServerIpInfo server_ip_info; - uint16_t port; ///< server port -- uint32_t pktlen; ///< the length of peckage -+ uint32_t pktlen; ///< the length of package - char* domain; ///< communication domain - char* api; ///< the type of api - bool debug; ///< if we print the debug information -@@ -65,7 +65,7 @@ struct ServerMudWorker - int32_t epfd; ///< the worker epoll file descriptor - struct epoll_event *epevs; ///< the epoll events - uint64_t recv_bytes; ///< total receive bytes -- uint32_t pktlen; ///< the length of peckage -+ uint32_t pktlen; ///< the length of package - ip_addr_t ip; ///< client ip - uint16_t port; ///< client port - char* api; ///< the type of api -@@ -88,7 +88,7 @@ struct ServerMud - struct epoll_event *epevs; ///< the epoll events - struct ServerIpInfo server_ip_info; - bool* port; ///< server port point to parameter's port -- uint32_t pktlen; ///< the length of peckage -+ uint32_t pktlen; ///< the length of package - char* domain; ///< communication domain - char* api; ///< the type of api - bool debug; ///< if we print the debug information -@@ -184,7 +184,7 @@ void *sermud_listener_create_and_run(void *arg); - int32_t sermud_create_and_run(struct ProgramParams *params); - - /** -- * @brief the multi thread, unblock, mutliplexing IO server prints informations -+ * @brief the multi thread, unblock, multiplexing IO server prints informations - * The multi thread, unblock, mutliplexing IO server prints informations. - * @param server_mum the server information - */ -@@ -199,7 +199,7 @@ void sermum_info_print(struct ServerMum *server_mum); - int32_t sersum_create_epfd_and_reg(struct ServerMumUnit *server_unit); - - /** -- * @brief the single thread, unblock, mutliplexing IO server accepts the connections -+ * @brief the single thread, unblock, multiplexing IO server accepts the connections - * The single thread, unblock, mutliplexing IO server accepts the connections. - * @param server_unit the server unit - * @param server_handler the server handler -@@ -208,7 +208,7 @@ int32_t sersum_create_epfd_and_reg(struct ServerMumUnit *server_unit); - int32_t sersum_accept_connects(struct epoll_event *cur_epev, struct ServerMumUnit *server_unit); - - /** -- * @brief the single thread, unblock, mutliplexing IO server processes the events -+ * @brief the single thread, unblock, multiplexing IO server processes the events - * The single thread, unblock, mutliplexing IO server processes the events. - * @param server_unit the server unit - * @return the result pointer --- -2.33.0 - diff --git a/0277-remove-the-unused-return-variable.patch b/0277-remove-the-unused-return-variable.patch deleted file mode 100644 index d860cec9e5e801807dc5643744b48fa7d592842c..0000000000000000000000000000000000000000 --- a/0277-remove-the-unused-return-variable.patch +++ /dev/null @@ -1,40 +0,0 @@ -From 1494a9e8d7b461301476be05a6b9cbc170b4d51d Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?=E5=BC=A0=E6=A5=9A=E5=90=9B?= - -Date: Fri, 11 Oct 2024 14:56:06 +0800 -Subject: [PATCH] remove the unused return variable. -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -因为kni_config_network_interface函数始终返回0,此提交移除了‘ret’变量,化简了函数的返回逻辑 - -Signed-off-by:zhangchujun ---- - src/common/dpdk_common.c | 3 +-- - 1 file changed, 1 insertion(+), 2 deletions(-) - -diff --git a/src/common/dpdk_common.c b/src/common/dpdk_common.c -index 66ad529..fafd266 100644 ---- a/src/common/dpdk_common.c -+++ b/src/common/dpdk_common.c -@@ -55,7 +55,6 @@ struct rte_kni* get_gazelle_kni(void) - - static int32_t kni_config_network_interface(uint16_t port_id, uint8_t if_up) - { -- int32_t ret = 0; - static bool g_bond_dev_started = false; - - if (port_id >= rte_eth_dev_count_avail() || port_id >= GAZELLE_MAX_ETHPORTS) { -@@ -82,7 +81,7 @@ static int32_t kni_config_network_interface(uint16_t port_id, uint8_t if_up) - } - - COMMON_INFO("Configure network interface of %hu %s \n", port_id, if_up ? "up" : "down"); -- return ret; -+ return 0; - } - - int32_t dpdk_kni_init(uint16_t port, struct rte_mempool *pool) --- -2.33.0 - diff --git a/0278-add-SO_NUMA_ID-optname-for-adapting-opneGauss.patch b/0278-add-SO_NUMA_ID-optname-for-adapting-opneGauss.patch deleted file mode 100644 index ca4903b8a4bd6b26278b11ee18e25e7089062f73..0000000000000000000000000000000000000000 --- a/0278-add-SO_NUMA_ID-optname-for-adapting-opneGauss.patch +++ /dev/null @@ -1,28 +0,0 @@ -From f62692f99e2d10803a667202694b5e38fa335edb Mon Sep 17 00:00:00 2001 -From: hankangkang -Date: Thu, 31 Oct 2024 10:37:06 +0800 -Subject: [PATCH] add SO_NUMA_ID(optname) for adapting opneGauss - ---- - 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 8f80f98..e0e8244 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -381,7 +381,11 @@ static bool unsupport_optname(int32_t level, int32_t optname) - - static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, void *optval, socklen_t *optlen) - { -+#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 g_wrap_api->getsockopt_fn(s, level, optname, optval, optlen); - } - --- -2.33.0 - diff --git a/0279-xdp-support-XDP_STATISTICS-by-posix_api-getsockopt_f.patch b/0279-xdp-support-XDP_STATISTICS-by-posix_api-getsockopt_f.patch deleted file mode 100644 index 37258a57c203d724c8c3ff36a6c3ac020d742900..0000000000000000000000000000000000000000 --- a/0279-xdp-support-XDP_STATISTICS-by-posix_api-getsockopt_f.patch +++ /dev/null @@ -1,63 +0,0 @@ -From e1cd2f3205eb6ebcf63ee931c48c54dc49417708 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Fri, 1 Nov 2024 09:12:52 +0800 -Subject: [PATCH] xdp: support XDP_STATISTICS by posix_api->getsockopt_fn - ---- - src/lstack/api/lstack_wrap.c | 29 +++++++++++++++++++---------- - 1 file changed, 19 insertions(+), 10 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 8f80f98..98bb8a1 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -14,6 +14,7 @@ - #include - #include - #include -+#include - - #include - #include -@@ -363,20 +364,28 @@ static bool unsupport_socket_optname(int32_t optname) - return false; - } - --static bool unsupport_optname(int32_t level, int32_t optname) -+static bool unsupport_xdp_optname(int32_t optname) - { -- if (level == SOL_IP) { -- return unsupport_ip_optname(optname); -- } -- -- if (level == SOL_TCP) { -- return unsupport_tcp_optname(optname); -+ if (optname == XDP_STATISTICS) { -+ return true; - } -+ return false; -+} - -- if (level == SOL_SOCKET) { -- return unsupport_socket_optname(optname); -+static bool unsupport_optname(int32_t level, int32_t optname) -+{ -+ switch (level) { -+ case SOL_IP: -+ return unsupport_ip_optname(optname); -+ case SOL_TCP: -+ return unsupport_tcp_optname(optname); -+ case SOL_SOCKET: -+ return unsupport_socket_optname(optname); -+ case SOL_XDP: -+ return unsupport_xdp_optname(optname); -+ default: -+ return false; - } -- return false; - } - - static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, void *optval, socklen_t *optlen) --- -2.33.0 - diff --git a/0280-interrupt-fix-timeout-events-cannot-be-counted.patch b/0280-interrupt-fix-timeout-events-cannot-be-counted.patch deleted file mode 100644 index d8f6976770e283aa2a6041145421086ddfd46d9e..0000000000000000000000000000000000000000 --- a/0280-interrupt-fix-timeout-events-cannot-be-counted.patch +++ /dev/null @@ -1,25 +0,0 @@ -From e35d6ffd66becc2725b38115322307261dd87f07 Mon Sep 17 00:00:00 2001 -From: jiangheng -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 - diff --git a/0281-remove-code-about-nobolck-mode-for-mysql.patch b/0281-remove-code-about-nobolck-mode-for-mysql.patch deleted file mode 100644 index 5d1282859d81954e0bf3f57eccf77db41d4d2095..0000000000000000000000000000000000000000 --- a/0281-remove-code-about-nobolck-mode-for-mysql.patch +++ /dev/null @@ -1,76 +0,0 @@ -From 84897b16c0a93606817443f792da97b5923fbdf0 Mon Sep 17 00:00:00 2001 -From: hankangkang -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 - diff --git a/0282-LOG-Optimize-some-log-displays.patch b/0282-LOG-Optimize-some-log-displays.patch deleted file mode 100644 index b0d408d22a5529080d34f8a7ec6fa15a77e7cc43..0000000000000000000000000000000000000000 --- a/0282-LOG-Optimize-some-log-displays.patch +++ /dev/null @@ -1,40 +0,0 @@ -From c33bfd14030ee84d4da1a5083fe47271f4cb27bb Mon Sep 17 00:00:00 2001 -From: yinbin -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 - diff --git a/0283-xdp-support-bind-no-cpu-mode.patch b/0283-xdp-support-bind-no-cpu-mode.patch deleted file mode 100644 index 708f4f8f81fd45c265d96b934421b2b9d7158a58..0000000000000000000000000000000000000000 --- a/0283-xdp-support-bind-no-cpu-mode.patch +++ /dev/null @@ -1,967 +0,0 @@ -From 10eb6041c9a3e632b9fc2e769d7e726fbf7c9dd8 Mon Sep 17 00:00:00 2001 -From: yangchen -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 -+ - #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 - #include - #include -+#include - - #include -+#include -+#include - #include - #include - - #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, - ð_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, - ð_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 - - #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 - diff --git a/0284-support-auto-set-xdp-addr.patch b/0284-support-auto-set-xdp-addr.patch deleted file mode 100644 index f5f00813233001b76ea86bc3806a16f6fef529c7..0000000000000000000000000000000000000000 --- a/0284-support-auto-set-xdp-addr.patch +++ /dev/null @@ -1,391 +0,0 @@ -From fa5060a255109d089f98c9c498d7119e96bd39fd Mon Sep 17 00:00:00 2001 -From: yangchen -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 - #include - #include --#include - #include - #include - #include -@@ -23,12 +22,15 @@ - #include - #include - #include -+#include -+#include -+#include -+#include - - #include - #include - #include - #include --#include - - #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 - -+#ifndef IFNAMSIZ -+#include -+#endif -+ - #include - #include - #include -@@ -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 - diff --git a/0285-suport-kernel-accept-for-openGauss.patch b/0285-suport-kernel-accept-for-openGauss.patch deleted file mode 100644 index 80b80ed1283d502f631dd5f9d30607a71d984b56..0000000000000000000000000000000000000000 --- a/0285-suport-kernel-accept-for-openGauss.patch +++ /dev/null @@ -1,82 +0,0 @@ -From be28f36adfebb0e5f7f2340638120a19f5b2eaa6 Mon Sep 17 00:00:00 2001 -From: hankangkang -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 - #include - #include -+#include - #include - - #include -@@ -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 - diff --git a/0286-openGauss-support-kernel-accept4.patch b/0286-openGauss-support-kernel-accept4.patch deleted file mode 100644 index 2db330e2450b9884226319814166603f4f1c0a4f..0000000000000000000000000000000000000000 --- a/0286-openGauss-support-kernel-accept4.patch +++ /dev/null @@ -1,43 +0,0 @@ -From e09613994ea3fee2c5468c48d24d8a6dfb96f8b4 Mon Sep 17 00:00:00 2001 -From: hankangkang -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 - diff --git a/0287-socket-init-wakeup-in-blocking-socket.patch b/0287-socket-init-wakeup-in-blocking-socket.patch deleted file mode 100644 index 9e98a0190ba641b06d8c546fe378a74475161d8b..0000000000000000000000000000000000000000 --- a/0287-socket-init-wakeup-in-blocking-socket.patch +++ /dev/null @@ -1,125 +0,0 @@ -From a735fd09aa59df805865331b3cbda5e0458c9fac Mon Sep 17 00:00:00 2001 -From: yinbin -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 - diff --git a/0288-fix-socket-of-control-thread-is-overwirtten-due-to-a.patch b/0288-fix-socket-of-control-thread-is-overwirtten-due-to-a.patch deleted file mode 100644 index 17443d3f548cb4a4ed9cdd50f9bd0740b169c0f5..0000000000000000000000000000000000000000 --- a/0288-fix-socket-of-control-thread-is-overwirtten-due-to-a.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 0f3a61700b17bed0ed39c7c5433952b72dc82b84 Mon Sep 17 00:00:00 2001 -From: jiangheng -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 - diff --git a/0289-LWIP-adjust-position-of-shutdown-in-callback-of-conn.patch b/0289-LWIP-adjust-position-of-shutdown-in-callback-of-conn.patch deleted file mode 100644 index b067e0ee8318a6f24a518d0a7bdf977544bb98c2..0000000000000000000000000000000000000000 --- a/0289-LWIP-adjust-position-of-shutdown-in-callback-of-conn.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 1d4bdf6a14afe7459d2fa9d2da19a36c45ae91f5 Mon Sep 17 00:00:00 2001 -From: yinbin -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 - diff --git a/0290-Fix-the-wrong-spelling-description-in-the-notes-and-.patch b/0290-Fix-the-wrong-spelling-description-in-the-notes-and-.patch deleted file mode 100644 index f25cb9d4dccf11eafde7871ed2802ad6203d01ba..0000000000000000000000000000000000000000 --- a/0290-Fix-the-wrong-spelling-description-in-the-notes-and-.patch +++ /dev/null @@ -1,154 +0,0 @@ -From e5aa9e48521b3096ba9acb888d293eefeaf677da Mon Sep 17 00:00:00 2001 -From: Caohongtao -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 ---- - 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 - diff --git a/0291-update-test-unitest-ltran-ltran_param_test.c.patch b/0291-update-test-unitest-ltran-ltran_param_test.c.patch deleted file mode 100644 index d9b636762da2a334a77f17c8fd44ccae70fe88d5..0000000000000000000000000000000000000000 --- a/0291-update-test-unitest-ltran-ltran_param_test.c.patch +++ /dev/null @@ -1,30 +0,0 @@ -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?= - -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: 菠萝有点酸 ---- - 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 - diff --git a/0292-fix-free-null-pointer-when-no-matching-device-is-fou.patch b/0292-fix-free-null-pointer-when-no-matching-device-is-fou.patch deleted file mode 100644 index 3b2e6fda801b334de5db83d6d2b34fdf436b7f7a..0000000000000000000000000000000000000000 --- a/0292-fix-free-null-pointer-when-no-matching-device-is-fou.patch +++ /dev/null @@ -1,87 +0,0 @@ -From cd82f46b54e14898087ea1b051bce51eb50adef7 Mon Sep 17 00:00:00 2001 -From: yangchen -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 - diff --git a/0293-cfg-show-dpdk-args-after-dpdk_adjust_args.patch b/0293-cfg-show-dpdk-args-after-dpdk_adjust_args.patch deleted file mode 100644 index 732509aaca8f241267f53aeae0502506a031a024..0000000000000000000000000000000000000000 --- a/0293-cfg-show-dpdk-args-after-dpdk_adjust_args.patch +++ /dev/null @@ -1,66 +0,0 @@ -From f05ce4c32a5c4121f41a69fa8b78c0a6a69e29d8 Mon Sep 17 00:00:00 2001 -From: yangchen -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 - diff --git a/0294-fix-build-error-in-2003SP4.patch b/0294-fix-build-error-in-2003SP4.patch deleted file mode 100644 index fa6a0042d9518ae28324f0b8da4964ae06409111..0000000000000000000000000000000000000000 --- a/0294-fix-build-error-in-2003SP4.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 83b65f8da77f586cc58278944f840016817ba9f7 Mon Sep 17 00:00:00 2001 -From: yangchen -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 - diff --git a/0295-CFG-fix-xdp-iface-check-error.patch b/0295-CFG-fix-xdp-iface-check-error.patch deleted file mode 100644 index adfb22daa06346eeacc4ccd389cdc905aeefda9b..0000000000000000000000000000000000000000 --- a/0295-CFG-fix-xdp-iface-check-error.patch +++ /dev/null @@ -1,166 +0,0 @@ -From fb7be13ec41f31261fb32741cab2f9903b05d246 Mon Sep 17 00:00:00 2001 -From: yinbin -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 - diff --git a/0296-xdp-support-stack-bind-numa.patch b/0296-xdp-support-stack-bind-numa.patch deleted file mode 100644 index 6af3c82f4bd3bd6498da74c84a0807c0225254f8..0000000000000000000000000000000000000000 --- a/0296-xdp-support-stack-bind-numa.patch +++ /dev/null @@ -1,425 +0,0 @@ -From 4b5ead09ab19b08a46a9ffba7cbc5e42e361dcc1 Mon Sep 17 00:00:00 2001 -From: yangchen -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 -@@ -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 - diff --git a/0297-openGauss-support-kernel-connnect.patch b/0297-openGauss-support-kernel-connnect.patch deleted file mode 100644 index 0acbe9178e528b7617da79baae48151e603b79e9..0000000000000000000000000000000000000000 --- a/0297-openGauss-support-kernel-connnect.patch +++ /dev/null @@ -1,125 +0,0 @@ -From b29d2ce72651ac91728278cb9b31029b397c6ea5 Mon Sep 17 00:00:00 2001 -From: hankangkang -Date: Wed, 27 Nov 2024 09:50:08 +0800 -Subject: [PATCH] openGauss: support kernel connnect - -Signed-off-by: hankangkang ---- - 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 - diff --git a/0298-DUMP-gazelle-supports-dump-lstack.patch b/0298-DUMP-gazelle-supports-dump-lstack.patch deleted file mode 100644 index db6afc6bdfcf223ba931d1828ba24fa3a12649b5..0000000000000000000000000000000000000000 --- a/0298-DUMP-gazelle-supports-dump-lstack.patch +++ /dev/null @@ -1,260 +0,0 @@ -From 71fee80519b321b565cdec74d9e7fae25f9bc750 Mon Sep 17 00:00:00 2001 -From: yinbin -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 --#include - #include - - #include -@@ -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 -+#include -+#include -+ -+#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 - diff --git a/0299-openGauss-fix-gs_ctl-switchover-failed.patch b/0299-openGauss-fix-gs_ctl-switchover-failed.patch deleted file mode 100644 index 89cb302ea7667a1392f4f9e81a8c9eafed371175..0000000000000000000000000000000000000000 --- a/0299-openGauss-fix-gs_ctl-switchover-failed.patch +++ /dev/null @@ -1,59 +0,0 @@ -From ac8f22827e961148a8e469e964d58fe248ba03ce Mon Sep 17 00:00:00 2001 -From: yangchen -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 - diff --git a/0300-openGauss-fix-connection-attempt-failed.patch b/0300-openGauss-fix-connection-attempt-failed.patch deleted file mode 100644 index c86518d72167ada8fcdaf5bfeeb442c84441601c..0000000000000000000000000000000000000000 --- a/0300-openGauss-fix-connection-attempt-failed.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 1627afea1cb97f85ffe0877daa3691acb2c67dae Mon Sep 17 00:00:00 2001 -From: yangchen -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 - diff --git a/0301-remove-app_bind_numa-check-from-exclude_cpus.patch b/0301-remove-app_bind_numa-check-from-exclude_cpus.patch deleted file mode 100644 index c9dff59e1ae0eaae5fe8c2f5a769588356440f98..0000000000000000000000000000000000000000 --- a/0301-remove-app_bind_numa-check-from-exclude_cpus.patch +++ /dev/null @@ -1,26 +0,0 @@ -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 - diff --git a/0302-fix-rpc-pool-leak-when-thread-exits.patch b/0302-fix-rpc-pool-leak-when-thread-exits.patch deleted file mode 100644 index 55517df0438970bc162429bd75533516659cbca1..0000000000000000000000000000000000000000 --- a/0302-fix-rpc-pool-leak-when-thread-exits.patch +++ /dev/null @@ -1,99 +0,0 @@ -From f132c0c51e362909081cf0b156ebe093000aa82b Mon Sep 17 00:00:00 2001 -From: jiangheng -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 - diff --git a/0303-fix-epoll-and-recv-threads-blocked-on-the-same-semap.patch b/0303-fix-epoll-and-recv-threads-blocked-on-the-same-semap.patch deleted file mode 100644 index 2decded8342bcd653b33ae1f7ba655fb2dce119a..0000000000000000000000000000000000000000 --- a/0303-fix-epoll-and-recv-threads-blocked-on-the-same-semap.patch +++ /dev/null @@ -1,148 +0,0 @@ -From 2d8ea9ed99116bf034e447307f8360dd24e9449c Mon Sep 17 00:00:00 2001 -From: jiangheng -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 - diff --git a/0304-fix-errno-ETIMEFOUT.patch b/0304-fix-errno-ETIMEFOUT.patch deleted file mode 100644 index 7908aeeebf4fdb804fc0ff073248678df2dcee8c..0000000000000000000000000000000000000000 --- a/0304-fix-errno-ETIMEFOUT.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 4de27f4f182bec258313d736d423b3b0ab4ff057 Mon Sep 17 00:00:00 2001 -From: jiangheng -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 - diff --git a/0305-cfg-notify-that-it-s-unsupported-when-stack_num-1.patch b/0305-cfg-notify-that-it-s-unsupported-when-stack_num-1.patch deleted file mode 100644 index 4d2e20378784e182e97b408dbbeb1f50d3164fa2..0000000000000000000000000000000000000000 --- a/0305-cfg-notify-that-it-s-unsupported-when-stack_num-1.patch +++ /dev/null @@ -1,32 +0,0 @@ -From e03be16e5deab1f8cdaf1ec6b6097184c643063d Mon Sep 17 00:00:00 2001 -From: yangchen -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 - diff --git a/0306-fix-a-contention-issue-when-rpc-pools-are-added-to-r.patch b/0306-fix-a-contention-issue-when-rpc-pools-are-added-to-r.patch deleted file mode 100644 index 9738bcf7bcf14bda16ee05ab519e4b5f48d77931..0000000000000000000000000000000000000000 --- a/0306-fix-a-contention-issue-when-rpc-pools-are-added-to-r.patch +++ /dev/null @@ -1,65 +0,0 @@ -From 6dce1a0ac071e365cb96551b04f555dec3658d85 Mon Sep 17 00:00:00 2001 -From: jiangheng -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 - diff --git a/0307-openGauss-unsupport_tcp_optname.patch b/0307-openGauss-unsupport_tcp_optname.patch deleted file mode 100644 index de3546f17cc96b9ab9e545e9ae0078f989b93419..0000000000000000000000000000000000000000 --- a/0307-openGauss-unsupport_tcp_optname.patch +++ /dev/null @@ -1,24 +0,0 @@ -From fd8004b7b7e78d08a7ad59a4561a3b539e806f06 Mon Sep 17 00:00:00 2001 -From: hankangkang -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 - diff --git a/0308-kernerl-bind-add-ipv6-add-check.patch b/0308-kernerl-bind-add-ipv6-add-check.patch deleted file mode 100644 index 29f7a4817c2e25f69469b03e33858156b29fc092..0000000000000000000000000000000000000000 --- a/0308-kernerl-bind-add-ipv6-add-check.patch +++ /dev/null @@ -1,48 +0,0 @@ -From bf5bf036eed0f7c15e7441c0c4ddbd5d7e48b3dd Mon Sep 17 00:00:00 2001 -From: hankangkang -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 - diff --git a/0309-Connect-execute-lwip-connect-if-dst_ip-and-host_ip-a.patch b/0309-Connect-execute-lwip-connect-if-dst_ip-and-host_ip-a.patch deleted file mode 100644 index 885171be8a2036f7a9202819f99a89dd6e188869..0000000000000000000000000000000000000000 --- a/0309-Connect-execute-lwip-connect-if-dst_ip-and-host_ip-a.patch +++ /dev/null @@ -1,132 +0,0 @@ -From 434a2509c25f265adb5d7b9398cb3bf8e379b387 Mon Sep 17 00:00:00 2001 -From: yinbin -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 - diff --git a/0310-DUMP-fix-build-error-of-oe2003-because-of-micro-is-n.patch b/0310-DUMP-fix-build-error-of-oe2003-because-of-micro-is-n.patch deleted file mode 100644 index f78853cd699cdb33e6fa7452fd428ad8ff12494c..0000000000000000000000000000000000000000 --- a/0310-DUMP-fix-build-error-of-oe2003-because-of-micro-is-n.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 2def683d0139084f48dc15d118af1d78e687e1f0 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Wed, 18 Dec 2024 19:54:29 +0800 -Subject: [PATCH] DUMP: fix build error of oe2003 because of micro is not - defined. - ---- - src/lstack/core/lstack_dump.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/src/lstack/core/lstack_dump.c b/src/lstack/core/lstack_dump.c -index d415ddc..969ca2b 100644 ---- a/src/lstack/core/lstack_dump.c -+++ b/src/lstack/core/lstack_dump.c -@@ -14,6 +14,8 @@ - #include - #include - -+#include -+ - #include "lstack_cfg.h" - #include "lstack_log.h" - --- -2.33.0 - diff --git a/0311-SIGNAL-Adjust-sigaction-function-to-keep-lstack-sign.patch b/0311-SIGNAL-Adjust-sigaction-function-to-keep-lstack-sign.patch deleted file mode 100644 index 098403b743d5314ff5ab5ca0d8386d1393b313b7..0000000000000000000000000000000000000000 --- a/0311-SIGNAL-Adjust-sigaction-function-to-keep-lstack-sign.patch +++ /dev/null @@ -1,310 +0,0 @@ -From bfc5d283ad9558d169bdb70e6b43876f5aa0062c Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Tue, 31 Dec 2024 14:45:58 +0800 -Subject: [PATCH] SIGNAL: Adjust sigaction function to keep lstack signal - function executed successfully. - ---- - src/lstack/api/lstack_unistd.c | 91 ++++++++++++++++++---- - src/lstack/core/lstack_dump.c | 4 +- - src/lstack/core/lstack_protocol_stack.c | 23 +++++- - src/lstack/core/lstack_stack_stat.c | 24 +++--- - src/lstack/core/lstack_thread_rpc.c | 1 + - src/lstack/include/lstack_protocol_stack.h | 3 + - 6 files changed, 117 insertions(+), 29 deletions(-) - -diff --git a/src/lstack/api/lstack_unistd.c b/src/lstack/api/lstack_unistd.c -index 47d80ec..90e603e 100644 ---- a/src/lstack/api/lstack_unistd.c -+++ b/src/lstack/api/lstack_unistd.c -@@ -26,23 +26,54 @@ - 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])) - -+static struct sigaction g_register_sigactions[NSIG]; // NSIG is the signal counts of system, normally equal 65 in Linux. -+static void lstack_sig_default_handler(int sig); -+ -+static bool sig_is_registered(int sig) -+{ -+ if (g_register_sigactions[sig].sa_handler != NULL && -+ g_register_sigactions[sig].sa_handler != (void *) lstack_sig_default_handler) { -+ return true; -+ } -+ return false; -+} -+ - static inline bool match_hijack_signal(int sig) - { - unsigned int i; - for (i = 0; i < HIJACK_SIGNAL_COUNT; i++) { - if (sig == g_hijack_signal[i]) { -- return 1; -+ return true; - } - } -- return 0; -+ return false; - } - --static void lstack_sig_default_handler(int sig) -+/* When operations such as pressing Ctrl+C or Kill are executed, we don't need to dump the stack. */ -+bool sig_need_dump(int sig) - { -+ if (sig == SIGINT || sig == SIGTERM || sig == SIGKILL) { -+ return false; -+ } -+ return true; -+} -+ -+static void lstack_sigaction_default_handler(int sig, siginfo_t *info, void *context) -+{ -+ static bool skip_process_exit = false; -+ -+ /* avoiding sig function being executed twice. */ -+ if (!skip_process_exit) { -+ skip_process_exit = true; -+ } else { -+ return; -+ } -+ - LSTACK_LOG(ERR, LSTACK, "lstack dumped, caught signal: %d\n", sig); - -- /* When operations such as pressing Ctrl+C or Kill, the call stack exit is not displayed. */ -- if (sig != SIGINT && sig != SIGTERM && sig != SIGKILL) { -+ stack_stop(); -+ -+ if (sig_need_dump(sig)) { - /* dump stack info */ - dump_stack(); - -@@ -50,17 +81,31 @@ static void lstack_sig_default_handler(int sig) - dump_lstack(); - } - -+ if (sig_is_registered(sig)) { -+ if (g_register_sigactions[sig].sa_flags & SA_SIGINFO) { -+ g_register_sigactions[sig].sa_sigaction(sig, info, context); -+ } else { -+ g_register_sigactions[sig].sa_handler(sig); -+ } -+ } -+ - if (get_global_cfg_params() && get_global_cfg_params()->is_primary) { - delete_primary_path(); - } - - control_fd_close(); - -+ stack_exit(); - lwip_exit(); - gazelle_exit(); - (void)kill(getpid(), sig); - } - -+static void lstack_sig_default_handler(int sig) -+{ -+ lstack_sigaction_default_handler(sig, NULL, NULL); -+} -+ - static void pthread_block_sig(int sig) - { - sigset_t mask; -@@ -105,18 +150,34 @@ int lstack_sigaction(int sig_num, const struct sigaction *action, struct sigacti - { - struct sigaction new_action; - -- if ((match_hijack_signal(sig_num) != 0) && (action && action->sa_handler == SIG_DFL)) { -+ if (match_hijack_signal(sig_num) && action != NULL) { - new_action = *action; -- new_action.sa_flags |= SA_RESETHAND; -- new_action.sa_handler = lstack_sig_default_handler; -- return posix_api->sigaction_fn(sig_num, &new_action, old_action); -- } - -- /* SA_INTERRUPT is deprecated, use SA_RESETHAND instead. */ -- if ((match_hijack_signal(sig_num) != 0) && (action && action->sa_flags == SA_INTERRUPT)) { -- new_action = *action; -- new_action.sa_flags |= SA_RESETHAND; -- return posix_api->sigaction_fn(sig_num, &new_action, old_action); -+ if (action->sa_handler == SIG_DFL) { -+ new_action = *action; -+ new_action.sa_flags |= SA_RESETHAND; -+ new_action.sa_handler = lstack_sig_default_handler; -+ return posix_api->sigaction_fn(sig_num, &new_action, old_action); -+ } -+ -+ /* SA_INTERRUPT is deprecated, use SA_RESETHAND instead. */ -+ if (action->sa_flags == SA_INTERRUPT) { -+ new_action = *action; -+ new_action.sa_flags |= SA_RESETHAND; -+ return posix_api->sigaction_fn(sig_num, &new_action, old_action); -+ } -+ -+ if (sig_need_dump(sig_num)) { -+ g_register_sigactions[sig_num] = new_action; -+ -+ /* If SA_SIGINFO is setted, we use sa_sigaction. */ -+ if (action->sa_flags & SA_SIGINFO) { -+ new_action.sa_sigaction = lstack_sigaction_default_handler; -+ } else { -+ new_action.sa_handler = lstack_sig_default_handler; -+ } -+ return posix_api->sigaction_fn(sig_num, &new_action, old_action); -+ } - } - - return posix_api->sigaction_fn(sig_num, action, old_action); -diff --git a/src/lstack/core/lstack_dump.c b/src/lstack/core/lstack_dump.c -index d415ddc..2a4477d 100644 ---- a/src/lstack/core/lstack_dump.c -+++ b/src/lstack/core/lstack_dump.c -@@ -23,14 +23,16 @@ - #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 -v", -+ "gazellectl lstack show 1 -I", - "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", - "gazellectl lstack show 1 -c" - }; - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 2c60a49..1eebac4 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -51,7 +51,7 @@ static void stack_set_state(struct protocol_stack *stack, enum rte_lcore_state_t - __atomic_store_n(&stack->state, state, __ATOMIC_RELEASE); - } - --static enum rte_lcore_state_t stack_get_state(struct protocol_stack *stack) -+enum rte_lcore_state_t stack_get_state(struct protocol_stack *stack) - { - return __atomic_load_n(&stack->state, __ATOMIC_ACQUIRE); - } -@@ -777,17 +777,32 @@ OUT2: - return -1; - } - --void stack_exit(void) -+static void stack_all_fds_close(struct protocol_stack *stack) - { -- /* close all fd */ - for (int i = 3; i < GAZELLE_MAX_CLIENTS + GAZELLE_RESERVED_CLIENTS; i++) { - struct lwip_sock *sock = lwip_get_socket(i); -- if (!POSIX_IS_CLOSED(sock) && sock->stack == get_protocol_stack()) { -+ if (!POSIX_IS_CLOSED(sock) && sock->stack == stack) { - lwip_close(i); - } - } - } - -+void stack_exit(void) -+{ -+ struct protocol_stack *stack = get_protocol_stack(); -+ if (stack != NULL) { -+ stack_all_fds_close(stack); -+ } -+} -+ -+void stack_stop(void) -+{ -+ struct protocol_stack *stack = get_protocol_stack(); -+ if (stack != NULL) { -+ stack_set_state(stack, WAIT); -+ } -+} -+ - void stack_group_exit(void) - { - int i; -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index c88da8f..b1eb60e 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -30,6 +30,7 @@ - #include "lstack_dpdk.h" - #include "lstack_stack_stat.h" - #include "lstack_virtio.h" -+#include "lstack_dump.h" - - void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new) - { -@@ -263,11 +264,13 @@ static void get_stack_stats(struct gazelle_stack_dfx_data *dfx, struct protocol_ - int32_t rpc_call_result = rpc_msgcnt(&stack->rpc_queue); - dfx->data.pkts.call_msg_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; - -- rpc_call_result = rpc_call_mbufpoolsize(&stack->dfx_rpc_queue); -- dfx->data.pkts.mbufpool_avail_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; -+ if (stack_get_state(stack) == RUNNING) { -+ rpc_call_result = rpc_call_mbufpoolsize(&stack->dfx_rpc_queue); -+ dfx->data.pkts.mbufpool_avail_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; - -- rpc_call_result = rpc_call_recvlistcnt(&stack->dfx_rpc_queue); -- dfx->data.pkts.recv_list_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; -+ rpc_call_result = rpc_call_recvlistcnt(&stack->dfx_rpc_queue); -+ dfx->data.pkts.recv_list_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; -+ } - - dfx->data.pkts.conn_num = stack->conn_num; - } -@@ -343,11 +346,14 @@ static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protoc - } - break; - case GAZELLE_STAT_LSTACK_SHOW_CONN: -- rpc_call_result = rpc_call_conntable(&stack->dfx_rpc_queue, dfx->data.conn.conn_list, -- GAZELLE_LSTACK_MAX_CONN); -- dfx->data.conn.conn_num = (rpc_call_result < 0) ? 0 : rpc_call_result; -- rpc_call_result = rpc_call_connnum(&stack->dfx_rpc_queue); -- dfx->data.conn.total_conn_num = (rpc_call_result < 0) ? 0 : rpc_call_result; -+ if (stack_get_state(stack) == RUNNING) { -+ rpc_call_result = rpc_call_conntable(&stack->dfx_rpc_queue, dfx->data.conn.conn_list, -+ GAZELLE_LSTACK_MAX_CONN); -+ dfx->data.conn.conn_num = (rpc_call_result < 0) ? 0 : rpc_call_result; -+ rpc_call_result = rpc_call_connnum(&stack->dfx_rpc_queue); -+ dfx->data.conn.total_conn_num = (rpc_call_result < 0) ? 0 : rpc_call_result; -+ } -+ - break; - case GAZELLE_STAT_LSTACK_SHOW_LATENCY: - ret = memcpy_s(&dfx->data.latency, sizeof(dfx->data.latency), &stack->latency, sizeof(stack->latency)); -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 26bd16a..9f871af 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -146,6 +146,7 @@ static struct rpc_msg *rpc_msg_alloc_except(rpc_func_t func) - - static void stack_exit_by_rpc(struct rpc_msg *msg) - { -+ stack_stop(); - stack_exit(); - } - -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 068e9d2..c7c7efe 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -120,10 +120,13 @@ void thread_bind_stack(struct protocol_stack *stack); - int stack_group_init(void); - void stack_group_exit(void); - void stack_exit(void); -+void stack_stop(void); - - int stack_setup_thread(void); - int stack_setup_app_thread(void); - - int stack_polling(unsigned wakeup_tick); - -+enum rte_lcore_state_t stack_get_state(struct protocol_stack *stack); -+ - #endif --- -2.33.0 - diff --git a/0312-SIGNAL-Adjust-hijack-sigal-table-to-hijack-SIGABRT-S.patch b/0312-SIGNAL-Adjust-hijack-sigal-table-to-hijack-SIGABRT-S.patch deleted file mode 100644 index 1489236c8844e435d91cd01aa53084116bd35ceb..0000000000000000000000000000000000000000 --- a/0312-SIGNAL-Adjust-hijack-sigal-table-to-hijack-SIGABRT-S.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 036485b74b382574f1b88b10b5cfed5a0efb2562 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Thu, 2 Jan 2025 17:47:13 +0800 -Subject: [PATCH] SIGNAL: Adjust hijack sigal table to hijack SIGABRT SIGQUIT - and delet SIGKILL - ---- - src/lstack/api/lstack_unistd.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/api/lstack_unistd.c b/src/lstack/api/lstack_unistd.c -index 90e603e..0837a6b 100644 ---- a/src/lstack/api/lstack_unistd.c -+++ b/src/lstack/api/lstack_unistd.c -@@ -23,7 +23,7 @@ - #include "lstack_control_plane.h" - #include "lstack_dump.h" - --static int g_hijack_signal[] = { SIGTERM, SIGINT, SIGSEGV, SIGBUS, SIGFPE, SIGILL, SIGKILL}; -+static int g_hijack_signal[] = { SIGTERM, SIGINT, SIGSEGV, SIGBUS, SIGFPE, SIGILL, SIGABRT, SIGQUIT}; - #define HIJACK_SIGNAL_COUNT (sizeof(g_hijack_signal) / sizeof(g_hijack_signal[0])) - - static struct sigaction g_register_sigactions[NSIG]; // NSIG is the signal counts of system, normally equal 65 in Linux. -@@ -52,7 +52,7 @@ static inline bool match_hijack_signal(int sig) - /* When operations such as pressing Ctrl+C or Kill are executed, we don't need to dump the stack. */ - bool sig_need_dump(int sig) - { -- if (sig == SIGINT || sig == SIGTERM || sig == SIGKILL) { -+ if (sig == SIGINT || sig == SIGTERM || sig == SIGQUIT) { - return false; - } - return true; --- -2.33.0 - diff --git a/0313-DUMP-fix-abnomal-printing-in-the-dump-process.patch b/0313-DUMP-fix-abnomal-printing-in-the-dump-process.patch deleted file mode 100644 index 4c0fa4c198e7995adf2052cf60e32c72327b479c..0000000000000000000000000000000000000000 --- a/0313-DUMP-fix-abnomal-printing-in-the-dump-process.patch +++ /dev/null @@ -1,25 +0,0 @@ -From b514eab8bb012067d6f40f3d6a7ec925e9b2093e Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Fri, 10 Jan 2025 14:04:44 +0800 -Subject: [PATCH] DUMP: fix abnomal printing in the dump process. - ---- - src/lstack/core/lstack_dump.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_dump.c b/src/lstack/core/lstack_dump.c -index 2a4477d..56eb305 100644 ---- a/src/lstack/core/lstack_dump.c -+++ b/src/lstack/core/lstack_dump.c -@@ -94,7 +94,7 @@ static int dump_command_excute(const char *command) - - /* get and print command output */ - if (fgets(buffer, sizeof(buffer), fp) != NULL) { -- LSTACK_LOG(INFO, LSTACK, "\r %s", buffer); -+ LSTACK_LOG(INFO, LSTACK, "\r\033[K %s", buffer); - } else if (feof(fp)) { - break; - } else { --- -2.33.0 - diff --git a/0314-fix-the-memory-leak-when-using-strdup.patch b/0314-fix-the-memory-leak-when-using-strdup.patch deleted file mode 100644 index d3141810d28fab27069fc428cd7ad7a4c5853a1b..0000000000000000000000000000000000000000 --- a/0314-fix-the-memory-leak-when-using-strdup.patch +++ /dev/null @@ -1,25 +0,0 @@ -From ff847f26a675fe7a1eca24cda2aad5904435ea74 Mon Sep 17 00:00:00 2001 -From: yangchen -Date: Mon, 13 Jan 2025 14:19:47 +0800 -Subject: [PATCH] fix the memory leak when using strdup - ---- - src/lstack/core/lstack_cfg.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 9a935f1..3d49cc3 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -398,7 +398,7 @@ static int32_t parse_devices(void) - 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); -+ dev = temp_dev; - break; - } - --- -2.33.0 - diff --git a/0315-Stack-unset-stack_stop-while-stacks-exit-by-rpc-mess.patch b/0315-Stack-unset-stack_stop-while-stacks-exit-by-rpc-mess.patch deleted file mode 100644 index 9daafedf8fd7c348f56cfc7f58b53270e2fc897d..0000000000000000000000000000000000000000 --- a/0315-Stack-unset-stack_stop-while-stacks-exit-by-rpc-mess.patch +++ /dev/null @@ -1,74 +0,0 @@ -From 51e3c4f57dfcd6400df17bbebe18f544b90e134f Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Tue, 14 Jan 2025 10:19:27 +0800 -Subject: [PATCH] Stack: unset stack_stop, while stacks exit by rpc message. - ---- - src/lstack/api/lstack_unistd.c | 2 +- - src/lstack/core/lstack_protocol_stack.c | 3 ++- - src/lstack/core/lstack_thread_rpc.c | 1 - - src/lstack/include/lstack_protocol_stack.h | 2 +- - 4 files changed, 4 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/api/lstack_unistd.c b/src/lstack/api/lstack_unistd.c -index 0837a6b..d8b5d8e 100644 ---- a/src/lstack/api/lstack_unistd.c -+++ b/src/lstack/api/lstack_unistd.c -@@ -71,7 +71,7 @@ static void lstack_sigaction_default_handler(int sig, siginfo_t *info, void *con - - LSTACK_LOG(ERR, LSTACK, "lstack dumped, caught signal: %d\n", sig); - -- stack_stop(); -+ stack_wait(); - - if (sig_need_dump(sig)) { - /* dump stack info */ -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 1eebac4..fcc0ad7 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -795,7 +795,7 @@ void stack_exit(void) - } - } - --void stack_stop(void) -+void stack_wait(void) - { - struct protocol_stack *stack = get_protocol_stack(); - if (stack != NULL) { -@@ -824,6 +824,7 @@ void stack_group_exit(void) - stack_exit(); - } - -+ /* Waiting all stacks' status transfer to WAIT, which means stacks are ready to exit. */ - for (i = 0; i < stack_group->stack_num; i++) { - if (stack_group->stacks[i] == NULL || stack == stack_group->stacks[i]) { - continue; -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 9f871af..26bd16a 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -146,7 +146,6 @@ static struct rpc_msg *rpc_msg_alloc_except(rpc_func_t func) - - static void stack_exit_by_rpc(struct rpc_msg *msg) - { -- stack_stop(); - stack_exit(); - } - -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index c7c7efe..c9c50c9 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -120,7 +120,7 @@ void thread_bind_stack(struct protocol_stack *stack); - int stack_group_init(void); - void stack_group_exit(void); - void stack_exit(void); --void stack_stop(void); -+void stack_wait(void); - - int stack_setup_thread(void); - int stack_setup_app_thread(void); --- -2.33.0 - diff --git a/0316-SIGNAL-block-SIGSEGV-during-exit-process.patch b/0316-SIGNAL-block-SIGSEGV-during-exit-process.patch deleted file mode 100644 index a339ff5a4b71dccbaad309cc8d39e7ea91a96425..0000000000000000000000000000000000000000 --- a/0316-SIGNAL-block-SIGSEGV-during-exit-process.patch +++ /dev/null @@ -1,58 +0,0 @@ -From 5d7e406a138567a9959c994af4fb574f7f075bed Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Wed, 15 Jan 2025 11:16:43 +0800 -Subject: [PATCH] SIGNAL: block SIGSEGV during exit process - ---- - src/lstack/api/lstack_unistd.c | 21 ++++++++++++--------- - 1 file changed, 12 insertions(+), 9 deletions(-) - -diff --git a/src/lstack/api/lstack_unistd.c b/src/lstack/api/lstack_unistd.c -index d8b5d8e..e3b9b1f 100644 ---- a/src/lstack/api/lstack_unistd.c -+++ b/src/lstack/api/lstack_unistd.c -@@ -58,6 +58,15 @@ bool sig_need_dump(int sig) - return true; - } - -+static void pthread_block_sig(int sig) -+{ -+ sigset_t mask; -+ -+ sigemptyset(&mask); -+ sigaddset(&mask, sig); -+ pthread_sigmask(SIG_BLOCK, &mask, NULL); -+} -+ - static void lstack_sigaction_default_handler(int sig, siginfo_t *info, void *context) - { - static bool skip_process_exit = false; -@@ -81,6 +90,9 @@ static void lstack_sigaction_default_handler(int sig, siginfo_t *info, void *con - dump_lstack(); - } - -+ /* App sig_handler may access invalid memory address in gazelle threads, -+ * so we block this signal avoiding getting stuck during exit. */ -+ pthread_block_sig(SIGSEGV); - if (sig_is_registered(sig)) { - if (g_register_sigactions[sig].sa_flags & SA_SIGINFO) { - g_register_sigactions[sig].sa_sigaction(sig, info, context); -@@ -106,15 +118,6 @@ static void lstack_sig_default_handler(int sig) - lstack_sigaction_default_handler(sig, NULL, NULL); - } - --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; --- -2.33.0 - diff --git a/0317-add-xdp-tx-checksum-tso-offload.patch b/0317-add-xdp-tx-checksum-tso-offload.patch deleted file mode 100644 index 8edb75d10d9aa54210418d23ff6845159da5ab45..0000000000000000000000000000000000000000 --- a/0317-add-xdp-tx-checksum-tso-offload.patch +++ /dev/null @@ -1,191 +0,0 @@ -From a237d1d8515d602e152546f182b1769fd31fa8b7 Mon Sep 17 00:00:00 2001 -From: jiangheng -Date: Sat, 18 Jan 2025 21:32:23 +0800 -Subject: [PATCH] add xdp tx checksum/tso offload - ---- - src/lstack/core/lstack_cfg.c | 20 ++++++++++---------- - src/lstack/core/lstack_dpdk.c | 21 ++++++--------------- - src/lstack/include/lstack_cfg.h | 8 ++++++++ - src/lstack/include/lstack_dpdk.h | 1 - - src/lstack/netif/lstack_ethdev.c | 11 +++++++++-- - src/lstack/netif/lstack_vdev.c | 2 +- - 6 files changed, 34 insertions(+), 29 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 3d49cc3..04ceb89 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -91,7 +91,6 @@ 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 { \ -@@ -1491,6 +1490,7 @@ static int dpdk_dev_get_iface_name(char *vdev_str) - char *iface_value = NULL; - char *next_token = NULL; - char vdev_str_cp[strlen(vdev_str) + 1]; -+ int idx = 0; - - /* 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) { -@@ -1498,7 +1498,15 @@ static int dpdk_dev_get_iface_name(char *vdev_str) - return -1; - } - -- token = strtok_s(vdev_str_cp, ",", &next_token); -+ while (vdev_str_cp[idx] == ' ') { -+ idx++; -+ } -+ -+ if (strncmp(&vdev_str_cp[idx], "net_af_xdp", strlen("net_af_xdp")) != 0) { -+ return 0; -+ } -+ -+ token = strtok_s(&vdev_str_cp[idx], ",", &next_token); - while (token != NULL) { - if (strncmp(token, VDEV_ARG_IFACE, strlen(VDEV_ARG_IFACE)) == 0) { - iface_value = token + strlen(VDEV_ARG_IFACE) + 1; -@@ -1535,11 +1543,3 @@ static int32_t parse_xdp_eth_name(void) - - return ret; - } -- --static bool xdp_eth_enabled(void) --{ -- if (strlen(g_config_params.xdp_eth_name)) { -- return true; -- } -- return false; --} -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 3023a6c..fcb78ca 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -52,7 +52,6 @@ - - struct eth_params { - uint16_t port_id; -- bool is_xdp; - - uint16_t nb_queues; - uint16_t nb_rx_desc; -@@ -155,7 +154,12 @@ struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, - } - - /* time stamp before pbuf_custom as priv_data */ -- uint16_t private_size = RTE_ALIGN(sizeof(struct mbuf_private), RTE_CACHE_LINE_SIZE); -+ uint16_t private_size = sizeof(struct mbuf_private); -+ if (xdp_eth_enabled()) { -+ /* reserved for xdp metadata, see struct xsk_tx_metadata in /usr/include/linux/if_xdp.h */ -+ private_size += 24; -+ } -+ private_size = RTE_ALIGN(private_size, RTE_CACHE_LINE_SIZE); - pool = rte_pktmbuf_pool_create(pool_name, nb_mbuf, mbuf_cache_size, private_size, MBUF_SZ, numa_id); - if (pool == NULL) { - LSTACK_LOG(ERR, LSTACK, "cannot create %s pool rte_err=%d\n", pool_name, rte_errno); -@@ -400,16 +404,6 @@ static int eth_params_rss(struct rte_eth_conf *conf, struct rte_eth_dev_info *de - return rss_enable; - } - --bool dpdk_nic_is_xdp(void) --{ -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- /* eth_params is null in ltran mode */ -- if (stack_group->eth_params == NULL) { -- return false; -- } -- return stack_group->eth_params->is_xdp; --} -- - static int eth_params_init(struct eth_params *eth_params, uint16_t port_id, uint16_t nb_queues, int *rss_enable) - { - struct rte_eth_dev_info dev_info; -@@ -439,9 +433,6 @@ static int eth_params_init(struct eth_params *eth_params, uint16_t port_id, uint - eth_params->conf.intr_conf.rxq = get_global_cfg_params()->stack_interrupt; - - eth_params_checksum(ð_params->conf, &dev_info); -- if (strcmp(dev_info.driver_name, "net_af_xdp") == 0) { -- eth_params->is_xdp = true; -- } - - if (!get_global_cfg_params()->tuple_filter) { - *rss_enable = eth_params_rss(ð_params->conf, &dev_info); -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 07a97cb..d59407b 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -165,6 +165,14 @@ static inline uint8_t use_ltran(void) - return get_global_cfg_params()->use_ltran; - } - -+static inline bool xdp_eth_enabled(void) -+{ -+ if (strlen(get_global_cfg_params()->xdp_eth_name)) { -+ return true; -+ } -+ return false; -+} -+ - 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]); -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index c2142d6..6251be7 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -64,7 +64,6 @@ int32_t dpdk_init_lstack_kni(void); - 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); - -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 315cced..3b859d2 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -364,14 +364,21 @@ static err_t eth_dev_init(struct netif *netif) - - netif->hwaddr_len = ETHER_ADDR_LEN; - -- if (dpdk_nic_is_xdp()) { -+ if (xdp_eth_enabled()) { - netif_set_rxol_flags(netif, RTE_ETH_RX_OFFLOAD_TCP_CKSUM | - RTE_ETH_RX_OFFLOAD_UDP_CKSUM | - RTE_ETH_RX_OFFLOAD_IPV4_CKSUM); -+ netif_set_txol_flags(netif, RTE_ETH_TX_OFFLOAD_TCP_CKSUM | RTE_ETH_TX_OFFLOAD_TCP_TSO); -+ /* 16: see kernel MAX_SKB_FRAGS define in skbuff.h */ -+ netif_set_max_pbuf_frags(netif, 16); - } else { - netif_set_rxol_flags(netif, get_protocol_stack_group()->rx_offload); -+ netif_set_txol_flags(netif, get_protocol_stack_group()->tx_offload); -+ /* 40: dpdk pmd support 40 max segs */ -+ netif_set_max_pbuf_frags(netif, 40); - } -- netif_set_txol_flags(netif, get_protocol_stack_group()->tx_offload); -+ netif_set_min_tso_seglen(netif, 256); -+ - if (get_global_cfg_params()->stack_mode_rtc) { - netif_set_rtc_mode(netif); - } -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index b1d1a1b..2eaeb1f 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -147,7 +147,7 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt - } - - if (get_protocol_stack_group()->rx_offload == 0 || /* skip gro when tcp/ip cksum offloads disable */ -- dpdk_nic_is_xdp() || /* kernel has done GRO */ -+ xdp_eth_enabled() || /* kernel has done GRO */ - (get_global_cfg_params()->vlan_mode >= 0 - && !(get_protocol_stack_group()->rx_offload & RTE_ETH_RX_OFFLOAD_VLAN_STRIP))) { - return pkt_num; --- -2.33.0 - diff --git a/0318-RTC-mode-fix-gazellectl-can-t-print-connenct-info.patch b/0318-RTC-mode-fix-gazellectl-can-t-print-connenct-info.patch deleted file mode 100644 index 2b57b57f9156b99129c3877215b7626cb9347d4e..0000000000000000000000000000000000000000 --- a/0318-RTC-mode-fix-gazellectl-can-t-print-connenct-info.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 4ad01c9c13f3f0837d19194463d6493ee5f1c243 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Tue, 21 Jan 2025 11:43:02 +0800 -Subject: [PATCH] RTC-mode: fix gazellectl can't print connenct info - ---- - src/lstack/core/lstack_protocol_stack.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index fcc0ad7..cb1b2b8 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -704,6 +704,7 @@ int stack_setup_app_thread(void) - { - static PER_THREAD int first_flags = 1; - static _Atomic uint32_t queue_id = 0; -+ struct protocol_stack *stack; - - if (likely(first_flags == 0)) { - return 0; -@@ -723,6 +724,10 @@ int stack_setup_app_thread(void) - free(t_params); - return -1; - } -+ -+ stack = get_protocol_stack(); -+ stack_set_state(stack, RUNNING); -+ - atomic_fetch_add(&g_stack_group.stack_num, 1); - free(t_params); - return 0; --- -2.33.0 - diff --git a/0319-Connect-fix-benchmark_dws-connect-failed.patch b/0319-Connect-fix-benchmark_dws-connect-failed.patch deleted file mode 100644 index 8b88bb69b7ad55e7ea409dd95e07d8a4810d0b72..0000000000000000000000000000000000000000 --- a/0319-Connect-fix-benchmark_dws-connect-failed.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 76c84f12bbcaf36f367252adc0a6da1bfee05de1 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Sat, 15 Feb 2025 16:41:13 +0800 -Subject: [PATCH] Connect: fix benchmark_dws connect failed - ---- - src/lstack/api/lstack_wrap.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 97e927a..e90c523 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -404,7 +404,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *addr, socklen_t addr - - /* 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)) { -+ if (ret == 0 || (ret != 0 && (errno == EINPROGRESS || errno == EISCONN))) { - POSIX_SET_TYPE(sock, POSIX_LWIP); - } else { - ret = posix_api->connect_fn(s, addr, addrlen); --- -2.33.0 - diff --git a/0320-Protocal-fixing-deathlock-between-protocol-threads-a.patch b/0320-Protocal-fixing-deathlock-between-protocol-threads-a.patch deleted file mode 100644 index c9ae9b98cade4907bfcc424c6d00ac969793b8eb..0000000000000000000000000000000000000000 --- a/0320-Protocal-fixing-deathlock-between-protocol-threads-a.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 3619605574d0c624513a10ecd543cc2bc1608f7b Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Fri, 24 Jan 2025 14:18:26 +0800 -Subject: [PATCH] Protocal: fixing deathlock between protocol threads and app - thread - ---- - src/lstack/core/lstack_lwip.c | 9 ++++++++- - 1 file changed, 8 insertions(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 648da58..3bb943f 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -267,7 +267,14 @@ struct pbuf *do_lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type typ - - static inline bool pbuf_allow_append(struct pbuf *pbuf, uint16_t remain_size) - { -- pthread_spin_lock(&pbuf->pbuf_lock); -+ int ret; -+ -+ /* Using pthread_spin_trylock to avoid deadlock between app thread and lstack threads */ -+ ret = pthread_spin_trylock(&pbuf->pbuf_lock); -+ if (ret != 0) { -+ return false; -+ } -+ - if (pbuf->tot_len > remain_size) { - pthread_spin_unlock(&pbuf->pbuf_lock); - return false; --- -2.33.0 - diff --git a/0321-update-gazelle-max-numa-nodes-8.patch b/0321-update-gazelle-max-numa-nodes-8.patch deleted file mode 100644 index 0552c4bb41230e98c51b0636a79f452a33d3fd63..0000000000000000000000000000000000000000 --- a/0321-update-gazelle-max-numa-nodes-8.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 9e8c4da250bb57f0ba6d59a98d0f601a853d4f7e Mon Sep 17 00:00:00 2001 -From: compile_success <980965867@qq.com> -Date: Tue, 4 Mar 2025 08:14:18 +0000 -Subject: [PATCH] update gazelle max numa nodes 8 - ---- - src/common/gazelle_opt.h | 2 +- - src/common/gazelle_reg_msg.h | 2 +- - 2 files changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h -index 98f1afd..d6b1c44 100644 ---- a/src/common/gazelle_opt.h -+++ b/src/common/gazelle_opt.h -@@ -110,6 +110,6 @@ - #define SLEEP_US_BEFORE_LINK_UP 10000 - - #define CPUS_MAX_NUM 640 --#define GAZELLE_MAX_NUMA_NODES 4 -+#define GAZELLE_MAX_NUMA_NODES 8 - - #endif /* _GAZELLE_OPT_H_ */ -diff --git a/src/common/gazelle_reg_msg.h b/src/common/gazelle_reg_msg.h -index 2ba47cc..ecd1e35 100644 ---- a/src/common/gazelle_reg_msg.h -+++ b/src/common/gazelle_reg_msg.h -@@ -33,7 +33,7 @@ - #define OPT_VDEV "--vdev" - #define VDEV_ARG_IFACE "iface" - --#define GAZELLE_MAX_NUMA_NODES 4 -+#define GAZELLE_MAX_NUMA_NODES 8 - #define SOCKET_MEM_STRLEN (GAZELLE_MAX_NUMA_NODES * 10) - - /* types for msg from lstack to ltran */ --- -2.33.0 - diff --git a/0322-RTC-fixing-program-stuck-while-gazelle-exit-in-multi.patch b/0322-RTC-fixing-program-stuck-while-gazelle-exit-in-multi.patch deleted file mode 100644 index 1706f31c82605d07a062fa82bbedf9808db99998..0000000000000000000000000000000000000000 --- a/0322-RTC-fixing-program-stuck-while-gazelle-exit-in-multi.patch +++ /dev/null @@ -1,134 +0,0 @@ -From e09eda4fb531f63836f0b2c2ed4bfd4f769a67e3 Mon Sep 17 00:00:00 2001 -From: yinbin -Date: Tue, 3 Jun 2025 21:05:13 +0800 -Subject: [PATCH] RTC: fixing program stuck while gazelle exit in multi-threads - envirement - ---- - src/common/gazelle_base_func.h | 2 ++ - src/lstack/api/lstack_dummy_api.c | 35 +++++++++++++++++++++---- - src/lstack/core/lstack_dump.c | 2 +- - src/lstack/core/lstack_protocol_stack.c | 12 +++++++-- - 4 files changed, 43 insertions(+), 8 deletions(-) - -diff --git a/src/common/gazelle_base_func.h b/src/common/gazelle_base_func.h -index a579cd4..0ccb34b 100644 ---- a/src/common/gazelle_base_func.h -+++ b/src/common/gazelle_base_func.h -@@ -15,6 +15,8 @@ - - #include - -+#define US_PER_MS 1000 -+ - #define GAZELLE_FREE(p) do { \ - if (p) { \ - free(p); \ -diff --git a/src/lstack/api/lstack_dummy_api.c b/src/lstack/api/lstack_dummy_api.c -index 3a867b3..004a3aa 100644 ---- a/src/lstack/api/lstack_dummy_api.c -+++ b/src/lstack/api/lstack_dummy_api.c -@@ -17,18 +17,45 @@ - #include - #include - --#define DUMMY_SLEEP_S 5 -+#include "lstack_log.h" -+#include "lstack_protocol_stack.h" -+#include "common/gazelle_base_func.h" -+ -+#define DUMMY_WAIT_TIMEOUT_MS 5000 -+static void waiting_exit_msg(void) -+{ -+ int time = 0; -+ int sleep_interval = 10; -+ -+ while (time < DUMMY_WAIT_TIMEOUT_MS) { -+ time += sleep_interval; -+ usleep(sleep_interval * US_PER_MS); -+ /* Must be in a secure context before close sockets */ -+ if (get_protocol_stack() && stack_polling(0) != 0) { -+ /* Means stack has closed all fds */ -+ stack_wait(); -+ break; -+ } -+ } -+ -+ if (time >= DUMMY_WAIT_TIMEOUT_MS) { -+ LSTACK_LOG(ERR, LSTACK, "APP thread doesn't recv 'stack_exit' message, will force quit within 5 seconds.\n"); -+ stack_wait(); -+ } -+ -+ usleep(DUMMY_WAIT_TIMEOUT_MS * US_PER_MS); -+} - - static inline ssize_t dummy_exit(void) - { -- sleep(DUMMY_SLEEP_S); -+ waiting_exit_msg(); - errno = ENOTCONN; - return -1; - } - - static int dummy_socket(int domain, int type, int protocol) - { -- sleep(DUMMY_SLEEP_S); -+ waiting_exit_msg(); - return -1; - } - -@@ -68,6 +95,4 @@ void dummy_api_init(posix_api_t *api) - api->sendto_fn = dummy_sendto; - - rte_wmb(); -- /* 1: wait until app thread call send functio complete */ -- sleep(1); - } -diff --git a/src/lstack/core/lstack_dump.c b/src/lstack/core/lstack_dump.c -index da9da28..7092871 100644 ---- a/src/lstack/core/lstack_dump.c -+++ b/src/lstack/core/lstack_dump.c -@@ -18,6 +18,7 @@ - - #include "lstack_cfg.h" - #include "lstack_log.h" -+#include "common/gazelle_base_func.h" - - #define DUMP_COMMAND_TIMEOUT_MS 2000 - #define DUMP_COMMAND_INTERVAL_MS 1 -@@ -50,7 +51,6 @@ static int dump_lstack_check(void) - return 0; - } - --#define US_PER_MS (MS_PER_S) - static long timeval_diff_ms(struct timeval *end, struct timeval *begin) - { - struct timeval result; -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index cb1b2b8..ed36890 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -56,10 +56,18 @@ enum rte_lcore_state_t stack_get_state(struct protocol_stack *stack) - return __atomic_load_n(&stack->state, __ATOMIC_ACQUIRE); - } - -+#define STACK_WAIT_TIMEOUT_MS 5000 - static void stack_wait_quit(struct protocol_stack *stack) - { -- while (__atomic_load_n(&stack->state, __ATOMIC_ACQUIRE) != WAIT) { -- rte_pause(); -+ int timeout = 0; -+ int sleep_interval = 10; -+ while (stack_get_state(stack) != WAIT && timeout < STACK_WAIT_TIMEOUT_MS) { -+ timeout += sleep_interval; -+ usleep(sleep_interval * US_PER_MS); -+ } -+ -+ if (timeout >= STACK_WAIT_TIMEOUT_MS) { -+ LSTACK_LOG(ERR, LSTACK, "stack %p exits time out!\n", stack); - } - } - --- -2.33.0 - diff --git a/0323-cleancode-add-GAZELLE_SAME_NODE.patch b/0323-cleancode-add-GAZELLE_SAME_NODE.patch deleted file mode 100644 index 650b5e55aaa270db5c82c873f8a77669d77d75bb..0000000000000000000000000000000000000000 --- a/0323-cleancode-add-GAZELLE_SAME_NODE.patch +++ /dev/null @@ -1,958 +0,0 @@ -From ff922a7e3085c37ed70add038a306ef519983a06 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 11 Mar 2025 14:30:02 +0800 -Subject: [PATCH] cleancode: add GAZELLE_SAME_NODE - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_wrap.c | 2 + - src/lstack/core/lstack_lwip.c | 363 +------------------- - src/lstack/core/lstack_protocol_stack.c | 4 + - src/lstack/core/same_node.c | 376 +++++++++++++++++++++ - src/lstack/include/lstack_ethdev.h | 2 - - src/lstack/include/lstack_lwip.h | 6 +- - src/lstack/include/lstack_protocol_stack.h | 2 + - src/lstack/include/same_node.h | 35 ++ - 8 files changed, 427 insertions(+), 363 deletions(-) - create mode 100644 src/lstack/core/same_node.c - create mode 100644 src/lstack/include/same_node.h - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index e90c523..8a88c47 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -362,6 +362,7 @@ static bool kernel_ip_route(const struct sockaddr *dst_addr) - - static bool should_enter_kernel_connect(const struct sockaddr *addr) - { -+#if GAZELLE_SAME_NODE - int32_t remote_port; - char listen_ring_name[RING_NAME_LEN]; - -@@ -371,6 +372,7 @@ static bool should_enter_kernel_connect(const struct sockaddr *addr) - if (kernel_ip_match(addr) && rte_ring_lookup(listen_ring_name) == NULL) { - return true; - } -+#endif /* GAZELLE_SAME_NODE */ - - if (lwip_ip_route(addr)) { - return false; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 4f5c4cc..d0e51b2 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -814,76 +814,6 @@ static inline void notice_stack_send(struct lwip_sock *sock, int32_t fd, int32_t - } - } - --/* process on same node use ring to recv data */ --ssize_t gazelle_same_node_ring_recv(struct lwip_sock *sock, const void *buf, size_t len, int32_t flags) --{ -- unsigned long long cur_begin = sock->same_node_rx_ring->sndbegin; -- unsigned long long cur_end; -- unsigned long long index = cur_begin + 1; -- size_t act_len = 0; -- -- cur_end = __atomic_load_n(&sock->same_node_rx_ring->sndend, __ATOMIC_ACQUIRE); -- if (cur_begin == cur_end) { -- errno = EAGAIN; -- act_len = -1; -- goto END; -- } -- act_len = cur_end - index + 1; -- act_len = RTE_MIN(act_len, len); -- if ((index & SAME_NODE_RING_MASK) + act_len > SAME_NODE_RING_LEN) { -- size_t act_len1 = SAME_NODE_RING_LEN - (index & SAME_NODE_RING_MASK); -- size_t act_len2 = act_len - act_len1; -- rte_memcpy((char *)buf, (char *)sock->same_node_rx_ring->mz->addr + (index & SAME_NODE_RING_MASK), act_len1); -- rte_memcpy((char *)buf + act_len1, (char *)sock->same_node_rx_ring->mz->addr, act_len2); -- } else { -- rte_memcpy((char *)buf, (char *)sock->same_node_rx_ring->mz->addr + (index & SAME_NODE_RING_MASK), act_len); -- } -- -- index += act_len; -- __atomic_store_n(&sock->same_node_rx_ring->sndbegin, index - 1, __ATOMIC_RELEASE); -- --END: -- /* rte_ring_count reduce lock */ -- if (sock->wakeup && sock->wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLIN) -- && (!NETCONN_IS_DATAIN(sock))) { -- del_sock_event(sock, EPOLLIN); -- } -- return act_len; --} -- --/* processes on same node use ring to send data */ --ssize_t gazelle_same_node_ring_send(struct lwip_sock *sock, const void *buf, size_t len, int32_t flags) --{ -- unsigned long long cur_begin = __atomic_load_n(&sock->same_node_tx_ring->sndbegin, __ATOMIC_ACQUIRE); -- unsigned long long cur_end = sock->same_node_tx_ring->sndend; -- if (cur_end >= cur_begin + SAME_NODE_RING_LEN) { -- errno = EAGAIN; -- return -1; -- } -- -- unsigned long long index = cur_end + 1; -- size_t act_len = SAME_NODE_RING_LEN - (cur_end - cur_begin); -- act_len = RTE_MIN(act_len, len); -- -- if ((index & SAME_NODE_RING_MASK) + act_len > SAME_NODE_RING_LEN) { -- size_t act_len1 = SAME_NODE_RING_LEN - (index & SAME_NODE_RING_MASK); -- size_t act_len2 = act_len - act_len1; -- rte_memcpy((char *)sock->same_node_tx_ring->mz->addr + (index & SAME_NODE_RING_MASK), buf, act_len1); -- rte_memcpy((char *)sock->same_node_tx_ring->mz->addr, (char *)buf + act_len1, act_len2); -- } else { -- rte_memcpy((char *)sock->same_node_tx_ring->mz->addr + (index & SAME_NODE_RING_MASK), buf, act_len); -- } -- -- index += act_len; -- __atomic_store_n(&sock->same_node_tx_ring->sndend, index - 1, __ATOMIC_RELEASE); -- if (act_len == 0) { -- errno = EAGAIN; -- return -1; -- } -- -- return act_len; --} -- - ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t flags, - const struct sockaddr *addr, socklen_t addrlen) - { -@@ -903,9 +833,11 @@ ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t f - sock->already_bind_numa = 1; - } - -+#if GAZELLE_SAME_NODE - if (sock->same_node_tx_ring != NULL) { - return gazelle_same_node_ring_send(sock, buf, len, flags); - } -+#endif /* GAZELLE_SAME_NODE */ - if (sock->errevent > 0 || sock->stack == NULL) { - GAZELLE_RETURN(ENOTCONN); - } -@@ -1186,10 +1118,11 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - sock->already_bind_numa = 1; - } - -+#if GAZELLE_SAME_NODE - if (sock->same_node_rx_ring != NULL) { -- return gazelle_same_node_ring_recv(sock, buf, len, flags); -- } -- -+ recvd = gazelle_same_node_ring_recv(sock, buf, len, flags); -+ } else -+#endif /* GAZELLE_SAME_NODE */ - if (NETCONN_IS_UDP(sock)) { - recvd = recv_ring_udp_read(sock, buf, len, noblock, addr, addrlen); - } else { -@@ -1220,21 +1153,6 @@ void do_lwip_add_recvlist(int32_t fd) - } - } - --void read_same_node_recv_list(struct protocol_stack *stack) --{ -- struct list_node *list = &(stack->same_node_recv_list); -- struct list_node *node, *temp; -- struct lwip_sock *sock; -- -- list_for_each_node(node, temp, list) { -- sock = list_entry(node, struct lwip_sock, recv_list); -- -- if (sock->same_node_rx_ring != NULL && same_node_ring_count(sock)) { -- add_sock_event(sock, EPOLLIN); -- } -- } --} -- - void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num) - { - struct list_node *list = &(stack->recv_list); -@@ -1417,272 +1335,3 @@ uint32_t do_lwip_get_connnum(void) - return conn_num; - } - --void netif_poll(struct netif *netif) --{ -- struct tcp_pcb *pcb = NULL; -- struct tcp_pcb_listen *pcbl = NULL; -- -- for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { --#define NETIF_POLL_READ_COUNT 32 -- struct pbuf *pbufs[NETIF_POLL_READ_COUNT]; -- int ret; -- -- if (pcb->client_rx_ring != NULL) { -- ret = rte_ring_sc_dequeue_burst(pcb->client_rx_ring, (void **)pbufs, NETIF_POLL_READ_COUNT, NULL); -- for (int i = 0; i < ret; i++) { -- if (ip_input(pbufs[i], netif) != 0) { -- LSTACK_LOG(INFO, LSTACK, "ip_input return err\n"); -- pbuf_free(pbufs[i]); -- } -- } -- } -- } -- for (pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL; pcbl = pcbl->next) { -- if (pcbl->listen_rx_ring != NULL) { -- struct pbuf *pbuf; -- if (rte_ring_sc_dequeue(pcbl->listen_rx_ring, (void **)&pbuf) == 0) { -- if (ip_input(pbuf, netif) != ERR_OK) { -- pbuf_free(pbuf); -- } -- } -- } -- } --} -- --/* processes on same node handshake packet use this function */ --err_t netif_loop_output(struct netif *netif, struct pbuf *p) --{ -- if (!p) { -- return ERR_ARG; -- } -- const struct ip_hdr *iphdr; -- iphdr = (const struct ip_hdr *)p->payload; -- if (IPH_PROTO(iphdr) == IP_PROTO_UDP) { -- return udp_netif_loop_output(netif, p); -- } -- -- struct tcp_pcb *pcb = p->pcb; -- struct pbuf *head = NULL; -- -- if (pcb == NULL || pcb->client_tx_ring == NULL) { -- LSTACK_LOG(ERR, LSTACK, "pcb is null\n"); -- return ERR_ARG; -- } -- -- if (p->next != NULL) { -- LSTACK_LOG(ERR, LSTACK, "netif_loop_output: not support chained pbuf\n"); -- return ERR_ARG; -- } -- -- struct tcp_hdr *tcp_hdr = (struct tcp_hdr *)((char *)p->payload + sizeof(struct ip_hdr)); -- uint8_t flags = TCPH_FLAGS(tcp_hdr); -- -- head = pbuf_alloc(0, p->len, PBUF_RAM); -- if (head == NULL) { -- LSTACK_LOG(ERR, LSTACK, "netif_loop_output: pbuf_alloc failed\n"); -- return ERR_MEM; -- } -- memcpy_s(head->payload, head->len, p->payload, p->len); -- -- if ((flags & TCP_SYN) && !(flags & TCP_ACK)) { -- /* SYN packet, send to listen_ring */ -- char ring_name[RING_NAME_LEN] = {0}; -- snprintf_s(ring_name, sizeof(ring_name), sizeof(ring_name) - 1, "listen_rx_ring_%d", pcb->remote_port); -- struct rte_ring *ring = rte_ring_lookup(ring_name); -- if (ring == NULL) { -- LSTACK_LOG(INFO, LSTACK, "netif_loop_output: cant find listen_rx_ring %d\n", pcb->remote_port); -- pbuf_free(head); -- } else { -- if (rte_ring_mp_enqueue(ring, head) != 0) { -- LSTACK_LOG(INFO, LSTACK, "enqueue sync packet failed\n"); -- pbuf_free(head); -- } -- } -- } else { -- /* send other type packet to tx_ring */ -- if (rte_ring_sp_enqueue(pcb->client_tx_ring, head) != 0) { -- LSTACK_LOG(INFO, LSTACK, "client tx ring full\n"); -- pbuf_free(head); -- } -- } -- -- return ERR_OK; --} -- --err_t find_same_node_memzone(struct tcp_pcb *pcb, struct lwip_sock *nsock) --{ -- char name[RING_NAME_LEN]; -- snprintf_s(name, sizeof(name), sizeof(name) - 1, "rte_mz_rx_%u", pcb->remote_port); -- if ((nsock->same_node_tx_ring_mz = rte_memzone_lookup(name)) == NULL) { -- LSTACK_LOG(INFO, LSTACK, "lwip_accept: can't find %s\n",name); -- return -1; -- } else { -- LSTACK_LOG(INFO, LSTACK, "lookup %s success\n", name); -- } -- nsock->same_node_tx_ring = (struct same_node_ring *)nsock->same_node_tx_ring_mz->addr; -- -- snprintf_s(name, sizeof(name), sizeof(name) - 1, "rte_mz_buf_rx_%u", pcb->remote_port); -- if ((nsock->same_node_tx_ring->mz = rte_memzone_lookup(name)) == NULL) { -- LSTACK_LOG(INFO, LSTACK, "lwip_accept: can't find %s\n",name); -- return -1; -- } -- -- snprintf_s(name, sizeof(name), sizeof(name) - 1, "rte_mz_tx_%u", pcb->remote_port); -- if ((nsock->same_node_rx_ring_mz = rte_memzone_lookup(name)) == NULL) { -- LSTACK_LOG(INFO, LSTACK, "lwip_accept: can't find %s\n",name); -- return -1; -- } else { -- LSTACK_LOG(INFO, LSTACK, "lookup %s success\n", name); -- } -- nsock->same_node_rx_ring = (struct same_node_ring *)nsock->same_node_rx_ring_mz->addr; -- -- snprintf_s(name, sizeof(name), sizeof(name) - 1,"rte_mz_buf_tx_%u", pcb->remote_port); -- if ((nsock->same_node_rx_ring->mz = rte_memzone_lookup(name)) == NULL) { -- LSTACK_LOG(INFO, LSTACK, "lwip_accept: can't find %s\n",name); -- return -1; -- } -- -- /* rcvlink init in alloc_socket() */ -- /* remove from g_rcv_process_list in free_socket */ -- list_add_node(&nsock->recv_list, &nsock->stack->same_node_recv_list); -- return 0; --} -- --err_t same_node_memzone_create(const struct rte_memzone **zone, int size, int port, char *name, char *rx) --{ -- char mem_name[RING_NAME_LEN] = {0}; -- snprintf_s(mem_name, sizeof(mem_name), sizeof(mem_name) - 1, "%s_%s_%d", name, rx, port); -- -- *zone = rte_memzone_reserve_aligned(mem_name, size, rte_socket_id(), 0, RTE_CACHE_LINE_SIZE); -- if (*zone == NULL) { -- LSTACK_LOG(ERR, LSTACK, "cannot reserve memzone:%s, errno is %d\n", mem_name, rte_errno); -- return ERR_MEM; -- } -- -- LSTACK_LOG(INFO, LSTACK, "lstack id %d, reserve %s(%p) success, addr is %p, size is %u\n", -- rte_socket_id(), mem_name, *zone, (*zone)->addr, size); -- -- return ERR_OK; --} -- --err_t same_node_ring_create(struct rte_ring **ring, int size, int port, char *name, char *rx) --{ -- if (!get_global_cfg_params()->use_sockmap) { -- *ring = NULL; -- return -1; -- } -- -- unsigned flags; -- char ring_name[RING_NAME_LEN] = {0}; -- if (strcmp(name, "listen") == 0) { -- flags = RING_F_SC_DEQ; -- } else { -- flags = RING_F_SP_ENQ | RING_F_SC_DEQ; -- } -- -- snprintf_s(ring_name, sizeof(ring_name), sizeof(ring_name) - 1, "%s_%s_ring_%d", name, rx, port); -- *ring = rte_ring_create(ring_name, size, rte_socket_id(), flags); -- if (*ring == NULL) { -- LSTACK_LOG(ERR, LSTACK, "cannot create rte_ring %s, errno is %d\n", ring_name, rte_errno); -- return ERR_MEM; -- } -- LSTACK_LOG(INFO, LSTACK, "lstack socket id:%d, create %s(%p) success\n", rte_socket_id(), ring_name, *ring); -- return ERR_OK; --} -- --static void init_same_node_ring(struct tcp_pcb *pcb) --{ -- struct netconn *netconn = (struct netconn *)pcb->callback_arg; -- struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); -- -- pcb->client_rx_ring = NULL; -- pcb->client_tx_ring = NULL; -- pcb->free_ring = 0; -- sock->same_node_rx_ring = NULL; -- sock->same_node_rx_ring_mz = NULL; -- sock->same_node_tx_ring = NULL; -- sock->same_node_tx_ring_mz = NULL; --} -- --#define CLIENT_RING_SIZE 512 --err_t create_same_node_ring(struct tcp_pcb *pcb) --{ -- struct netconn *netconn = (struct netconn *)pcb->callback_arg; -- struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); -- -- if (same_node_ring_create(&pcb->client_rx_ring, CLIENT_RING_SIZE, pcb->local_port, "client", "rx") != 0) { -- goto END; -- } -- if (same_node_ring_create(&pcb->client_tx_ring, CLIENT_RING_SIZE, pcb->local_port, "client", "tx") != 0) { -- goto END; -- } -- pcb->free_ring = 1; -- -- if (same_node_memzone_create(&sock->same_node_rx_ring_mz, sizeof(struct same_node_ring), -- pcb->local_port, "rte_mz", "rx") != 0) { -- goto END; -- } -- sock->same_node_rx_ring = (struct same_node_ring*)sock->same_node_rx_ring_mz->addr; -- -- if (same_node_memzone_create(&sock->same_node_rx_ring->mz, SAME_NODE_RING_LEN, -- pcb->local_port, "rte_mz_buf", "rx") != 0) { -- goto END; -- } -- -- sock->same_node_rx_ring->sndbegin = 0; -- sock->same_node_rx_ring->sndend = 0; -- -- if (same_node_memzone_create(&sock->same_node_tx_ring_mz, sizeof(struct same_node_ring), -- pcb->local_port, "rte_mz", "tx") != 0) { -- goto END; -- } -- sock->same_node_tx_ring = (struct same_node_ring*)sock->same_node_tx_ring_mz->addr; -- -- if (same_node_memzone_create(&sock->same_node_tx_ring->mz, SAME_NODE_RING_LEN, -- pcb->local_port, "rte_mz_buf", "tx") != 0) { -- goto END; -- } -- -- sock->same_node_tx_ring->sndbegin = 0; -- sock->same_node_tx_ring->sndend = 0; -- -- return 0; --END: -- rte_ring_free(pcb->client_rx_ring); -- rte_ring_free(pcb->client_tx_ring); -- rte_memzone_free(sock->same_node_rx_ring->mz); -- rte_memzone_free(sock->same_node_rx_ring_mz); -- rte_memzone_free(sock->same_node_tx_ring->mz); -- rte_memzone_free(sock->same_node_tx_ring_mz); -- init_same_node_ring(pcb); -- return ERR_BUF; --} -- --err_t find_same_node_ring(struct tcp_pcb *npcb) --{ -- char name[RING_NAME_LEN] = {0}; -- snprintf_s(name, sizeof(name), sizeof(name) - 1, "client_tx_ring_%u", npcb->remote_port); -- npcb->client_rx_ring = rte_ring_lookup(name); -- memset_s(name, sizeof(name), 0, sizeof(name)); -- snprintf_s(name, sizeof(name), sizeof(name) - 1, "client_rx_ring_%u", npcb->remote_port); -- npcb->client_tx_ring = rte_ring_lookup(name); -- npcb->free_ring = 0; -- if (npcb->client_tx_ring == NULL || -- npcb->client_rx_ring == NULL) { -- LSTACK_LOG(INFO, LSTACK, "lookup client rxtx ring failed, port is %d\n", npcb->remote_port); -- tcp_abandon(npcb, 0); -- return ERR_CONN; -- } else { -- LSTACK_LOG(INFO, LSTACK, "find client_tx_ring_%u and client_rx_ring_%u\n", -- npcb->remote_port, npcb->remote_port); -- } -- return 0; --} -- --unsigned same_node_ring_count(struct lwip_sock *sock) --{ -- const unsigned long long cur_begin = __atomic_load_n(&sock->same_node_rx_ring->sndbegin, __ATOMIC_RELAXED); -- const unsigned long long cur_end = __atomic_load_n(&sock->same_node_rx_ring->sndend, __ATOMIC_RELAXED); -- -- return cur_end - cur_begin; --} -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index ed36890..b4fb2fd 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -146,6 +146,7 @@ struct protocol_stack *get_bind_protocol_stack(void) - return stack_group->stacks[index]; - } - -+#if GAZELLE_TCP_REUSE_IPPORT - int get_min_conn_stack(struct protocol_stack_group *stack_group) - { - struct protocol_stack* stack; -@@ -161,6 +162,7 @@ int get_min_conn_stack(struct protocol_stack_group *stack_group) - } - return min_conn_stk_idx; - } -+#endif /* GAZELLE_TCP_REUSE_IPPORT */ - - void bind_to_stack_numa(struct protocol_stack *stack) - { -@@ -566,6 +568,7 @@ int stack_polling(unsigned wakeup_tick) - } - } - -+#if GAZELLE_SAME_NODE - /* run to completion mode currently does not support sockmap */ - if (use_sockmap) { - netif_poll(&stack->netif); -@@ -574,6 +577,7 @@ int stack_polling(unsigned wakeup_tick) - read_same_node_recv_list(stack); - } - } -+#endif /* GAZELLE_SAME_NODE */ - - if (cfg->udp_enable) { - udp_netif_poll(&stack->netif); -diff --git a/src/lstack/core/same_node.c b/src/lstack/core/same_node.c -new file mode 100644 -index 0000000..0fe0fa8 ---- /dev/null -+++ b/src/lstack/core/same_node.c -@@ -0,0 +1,376 @@ -+/* -+* 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 -+#include -+ -+#include -+ -+#include "lstack_log.h" -+#include "lstack_cfg.h" -+#include "lstack_protocol_stack.h" -+#include "lstack_stack_stat.h" -+#include "same_node.h" -+#include "lstack_epoll.h" -+#include "lstack_lwip.h" -+ -+#if GAZELLE_SAME_NODE -+void read_same_node_recv_list(struct protocol_stack *stack) -+{ -+ struct list_node *list = &(stack->same_node_recv_list); -+ struct list_node *node, *temp; -+ struct lwip_sock *sock; -+ -+ list_for_each_node(node, temp, list) { -+ sock = list_entry(node, struct lwip_sock, recv_list); -+ -+ if (sock->same_node_rx_ring != NULL && same_node_ring_count(sock)) { -+ add_sock_event(sock, EPOLLIN); -+ } -+ } -+} -+ -+/* process on same node use ring to recv data */ -+ssize_t gazelle_same_node_ring_recv(struct lwip_sock *sock, const void *buf, size_t len, int32_t flags) -+{ -+ unsigned long long cur_begin = sock->same_node_rx_ring->sndbegin; -+ unsigned long long cur_end; -+ unsigned long long index = cur_begin + 1; -+ size_t act_len = 0; -+ -+ cur_end = __atomic_load_n(&sock->same_node_rx_ring->sndend, __ATOMIC_ACQUIRE); -+ if (cur_begin == cur_end) { -+ errno = EAGAIN; -+ act_len = -1; -+ goto END; -+ } -+ act_len = cur_end - index + 1; -+ act_len = RTE_MIN(act_len, len); -+ if ((index & SAME_NODE_RING_MASK) + act_len > SAME_NODE_RING_LEN) { -+ size_t act_len1 = SAME_NODE_RING_LEN - (index & SAME_NODE_RING_MASK); -+ size_t act_len2 = act_len - act_len1; -+ rte_memcpy((char *)buf, (char *)sock->same_node_rx_ring->mz->addr + (index & SAME_NODE_RING_MASK), act_len1); -+ rte_memcpy((char *)buf + act_len1, (char *)sock->same_node_rx_ring->mz->addr, act_len2); -+ } else { -+ rte_memcpy((char *)buf, (char *)sock->same_node_rx_ring->mz->addr + (index & SAME_NODE_RING_MASK), act_len); -+ } -+ -+ index += act_len; -+ __atomic_store_n(&sock->same_node_rx_ring->sndbegin, index - 1, __ATOMIC_RELEASE); -+ -+END: -+ return act_len; -+} -+ -+/* processes on same node use ring to send data */ -+ssize_t gazelle_same_node_ring_send(struct lwip_sock *sock, const void *buf, size_t len, int32_t flags) -+{ -+ unsigned long long cur_begin = __atomic_load_n(&sock->same_node_tx_ring->sndbegin, __ATOMIC_ACQUIRE); -+ unsigned long long cur_end = sock->same_node_tx_ring->sndend; -+ if (cur_end >= cur_begin + SAME_NODE_RING_LEN) { -+ errno = EAGAIN; -+ return -1; -+ } -+ -+ unsigned long long index = cur_end + 1; -+ size_t act_len = SAME_NODE_RING_LEN - (cur_end - cur_begin); -+ act_len = RTE_MIN(act_len, len); -+ -+ if ((index & SAME_NODE_RING_MASK) + act_len > SAME_NODE_RING_LEN) { -+ size_t act_len1 = SAME_NODE_RING_LEN - (index & SAME_NODE_RING_MASK); -+ size_t act_len2 = act_len - act_len1; -+ rte_memcpy((char *)sock->same_node_tx_ring->mz->addr + (index & SAME_NODE_RING_MASK), buf, act_len1); -+ rte_memcpy((char *)sock->same_node_tx_ring->mz->addr, (char *)buf + act_len1, act_len2); -+ } else { -+ rte_memcpy((char *)sock->same_node_tx_ring->mz->addr + (index & SAME_NODE_RING_MASK), buf, act_len); -+ } -+ -+ index += act_len; -+ __atomic_store_n(&sock->same_node_tx_ring->sndend, index - 1, __ATOMIC_RELEASE); -+ if (act_len == 0) { -+ errno = EAGAIN; -+ return -1; -+ } -+ -+ return act_len; -+} -+ -+void netif_poll(struct netif *netif) -+{ -+ struct tcp_pcb *pcb = NULL; -+ struct tcp_pcb_listen *pcbl = NULL; -+ -+ for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { -+#define NETIF_POLL_READ_COUNT 32 -+ struct pbuf *pbufs[NETIF_POLL_READ_COUNT]; -+ int ret; -+ -+ if (pcb->client_rx_ring != NULL) { -+ ret = rte_ring_sc_dequeue_burst(pcb->client_rx_ring, (void **)pbufs, NETIF_POLL_READ_COUNT, NULL); -+ for (int i = 0; i < ret; i++) { -+ if (ip_input(pbufs[i], netif) != 0) { -+ LSTACK_LOG(INFO, LSTACK, "ip_input return err\n"); -+ pbuf_free(pbufs[i]); -+ } -+ } -+ } -+ } -+ for (pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL; pcbl = pcbl->next) { -+ if (pcbl->listen_rx_ring != NULL) { -+ struct pbuf *pbuf; -+ if (rte_ring_sc_dequeue(pcbl->listen_rx_ring, (void **)&pbuf) == 0) { -+ if (ip_input(pbuf, netif) != ERR_OK) { -+ pbuf_free(pbuf); -+ } -+ } -+ } -+ } -+} -+ -+/* processes on same node handshake packet use this function */ -+err_t netif_loop_output(struct netif *netif, struct pbuf *p) -+{ -+ if (!p) { -+ return ERR_ARG; -+ } -+ const struct ip_hdr *iphdr; -+ iphdr = (const struct ip_hdr *)p->payload; -+ if (IPH_PROTO(iphdr) == IP_PROTO_UDP) { -+ return udp_netif_loop_output(netif, p); -+ } -+ -+ struct tcp_pcb *pcb = p->pcb; -+ struct pbuf *head = NULL; -+ -+ if (pcb == NULL || pcb->client_tx_ring == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "pcb is null\n"); -+ return ERR_ARG; -+ } -+ -+ if (p->next != NULL) { -+ LSTACK_LOG(ERR, LSTACK, "netif_loop_output: not support chained pbuf\n"); -+ return ERR_ARG; -+ } -+ -+ struct tcp_hdr *tcp_hdr = (struct tcp_hdr *)((char *)p->payload + sizeof(struct ip_hdr)); -+ uint8_t flags = TCPH_FLAGS(tcp_hdr); -+ -+ head = pbuf_alloc(0, p->len, PBUF_RAM); -+ if (head == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "netif_loop_output: pbuf_alloc failed\n"); -+ return ERR_MEM; -+ } -+ memcpy_s(head->payload, head->len, p->payload, p->len); -+ -+ if ((flags & TCP_SYN) && !(flags & TCP_ACK)) { -+ /* SYN packet, send to listen_ring */ -+ char ring_name[RING_NAME_LEN] = {0}; -+ snprintf_s(ring_name, sizeof(ring_name), sizeof(ring_name) - 1, "listen_rx_ring_%d", pcb->remote_port); -+ struct rte_ring *ring = rte_ring_lookup(ring_name); -+ if (ring == NULL) { -+ LSTACK_LOG(INFO, LSTACK, "netif_loop_output: cant find listen_rx_ring %d\n", pcb->remote_port); -+ pbuf_free(head); -+ } else { -+ if (rte_ring_mp_enqueue(ring, head) != 0) { -+ LSTACK_LOG(INFO, LSTACK, "enqueue sync packet failed\n"); -+ pbuf_free(head); -+ } -+ } -+ } else { -+ /* send other type packet to tx_ring */ -+ if (rte_ring_sp_enqueue(pcb->client_tx_ring, head) != 0) { -+ LSTACK_LOG(INFO, LSTACK, "client tx ring full\n"); -+ pbuf_free(head); -+ } -+ } -+ -+ return ERR_OK; -+} -+ -+err_t find_same_node_memzone(struct tcp_pcb *pcb, struct lwip_sock *nsock) -+{ -+ char name[RING_NAME_LEN]; -+ snprintf_s(name, sizeof(name), sizeof(name) - 1, "rte_mz_rx_%u", pcb->remote_port); -+ if ((nsock->same_node_tx_ring_mz = rte_memzone_lookup(name)) == NULL) { -+ LSTACK_LOG(INFO, LSTACK, "lwip_accept: can't find %s\n",name); -+ return -1; -+ } else { -+ LSTACK_LOG(INFO, LSTACK, "lookup %s success\n", name); -+ } -+ nsock->same_node_tx_ring = (struct same_node_ring *)nsock->same_node_tx_ring_mz->addr; -+ -+ snprintf_s(name, sizeof(name), sizeof(name) - 1, "rte_mz_buf_rx_%u", pcb->remote_port); -+ if ((nsock->same_node_tx_ring->mz = rte_memzone_lookup(name)) == NULL) { -+ LSTACK_LOG(INFO, LSTACK, "lwip_accept: can't find %s\n",name); -+ return -1; -+ } -+ -+ snprintf_s(name, sizeof(name), sizeof(name) - 1, "rte_mz_tx_%u", pcb->remote_port); -+ if ((nsock->same_node_rx_ring_mz = rte_memzone_lookup(name)) == NULL) { -+ LSTACK_LOG(INFO, LSTACK, "lwip_accept: can't find %s\n",name); -+ return -1; -+ } else { -+ LSTACK_LOG(INFO, LSTACK, "lookup %s success\n", name); -+ } -+ nsock->same_node_rx_ring = (struct same_node_ring *)nsock->same_node_rx_ring_mz->addr; -+ -+ snprintf_s(name, sizeof(name), sizeof(name) - 1,"rte_mz_buf_tx_%u", pcb->remote_port); -+ if ((nsock->same_node_rx_ring->mz = rte_memzone_lookup(name)) == NULL) { -+ LSTACK_LOG(INFO, LSTACK, "lwip_accept: can't find %s\n",name); -+ return -1; -+ } -+ -+ /* rcvlink init in alloc_socket() */ -+ /* remove from g_rcv_process_list in free_socket */ -+ list_add_node(&nsock->recv_list, &nsock->stack->same_node_recv_list); -+ return 0; -+} -+ -+err_t same_node_memzone_create(const struct rte_memzone **zone, int size, int port, char *name, char *rx) -+{ -+ char mem_name[RING_NAME_LEN] = {0}; -+ snprintf_s(mem_name, sizeof(mem_name), sizeof(mem_name) - 1, "%s_%s_%d", name, rx, port); -+ -+ *zone = rte_memzone_reserve_aligned(mem_name, size, rte_socket_id(), 0, RTE_CACHE_LINE_SIZE); -+ if (*zone == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "cannot reserve memzone:%s, errno is %d\n", mem_name, rte_errno); -+ return ERR_MEM; -+ } -+ -+ LSTACK_LOG(INFO, LSTACK, "lstack id %d, reserve %s(%p) success, addr is %p, size is %u\n", -+ rte_socket_id(), mem_name, *zone, (*zone)->addr, size); -+ -+ return ERR_OK; -+} -+ -+err_t same_node_ring_create(struct rte_ring **ring, int size, int port, char *name, char *rx) -+{ -+ if (!get_global_cfg_params()->use_sockmap) { -+ *ring = NULL; -+ return -1; -+ } -+ -+ unsigned flags; -+ char ring_name[RING_NAME_LEN] = {0}; -+ if (strcmp(name, "listen") == 0) { -+ flags = RING_F_SC_DEQ; -+ } else { -+ flags = RING_F_SP_ENQ | RING_F_SC_DEQ; -+ } -+ -+ snprintf_s(ring_name, sizeof(ring_name), sizeof(ring_name) - 1, "%s_%s_ring_%d", name, rx, port); -+ *ring = rte_ring_create(ring_name, size, rte_socket_id(), flags); -+ if (*ring == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "cannot create rte_ring %s, errno is %d\n", ring_name, rte_errno); -+ return ERR_MEM; -+ } -+ LSTACK_LOG(INFO, LSTACK, "lstack socket id:%d, create %s(%p) success\n", rte_socket_id(), ring_name, *ring); -+ return ERR_OK; -+} -+ -+static void init_same_node_ring(struct tcp_pcb *pcb) -+{ -+ struct netconn *netconn = (struct netconn *)pcb->callback_arg; -+ struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); -+ -+ pcb->client_rx_ring = NULL; -+ pcb->client_tx_ring = NULL; -+ pcb->free_ring = 0; -+ sock->same_node_rx_ring = NULL; -+ sock->same_node_rx_ring_mz = NULL; -+ sock->same_node_tx_ring = NULL; -+ sock->same_node_tx_ring_mz = NULL; -+} -+ -+#define CLIENT_RING_SIZE 512 -+err_t create_same_node_ring(struct tcp_pcb *pcb) -+{ -+ struct netconn *netconn = (struct netconn *)pcb->callback_arg; -+ struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); -+ -+ if (same_node_ring_create(&pcb->client_rx_ring, CLIENT_RING_SIZE, pcb->local_port, "client", "rx") != 0) { -+ goto END; -+ } -+ if (same_node_ring_create(&pcb->client_tx_ring, CLIENT_RING_SIZE, pcb->local_port, "client", "tx") != 0) { -+ goto END; -+ } -+ pcb->free_ring = 1; -+ -+ if (same_node_memzone_create(&sock->same_node_rx_ring_mz, sizeof(struct same_node_ring), -+ pcb->local_port, "rte_mz", "rx") != 0) { -+ goto END; -+ } -+ sock->same_node_rx_ring = (struct same_node_ring*)sock->same_node_rx_ring_mz->addr; -+ -+ if (same_node_memzone_create(&sock->same_node_rx_ring->mz, SAME_NODE_RING_LEN, -+ pcb->local_port, "rte_mz_buf", "rx") != 0) { -+ goto END; -+ } -+ -+ sock->same_node_rx_ring->sndbegin = 0; -+ sock->same_node_rx_ring->sndend = 0; -+ -+ if (same_node_memzone_create(&sock->same_node_tx_ring_mz, sizeof(struct same_node_ring), -+ pcb->local_port, "rte_mz", "tx") != 0) { -+ goto END; -+ } -+ sock->same_node_tx_ring = (struct same_node_ring*)sock->same_node_tx_ring_mz->addr; -+ -+ if (same_node_memzone_create(&sock->same_node_tx_ring->mz, SAME_NODE_RING_LEN, -+ pcb->local_port, "rte_mz_buf", "tx") != 0) { -+ goto END; -+ } -+ -+ sock->same_node_tx_ring->sndbegin = 0; -+ sock->same_node_tx_ring->sndend = 0; -+ -+ return 0; -+END: -+ rte_ring_free(pcb->client_rx_ring); -+ rte_ring_free(pcb->client_tx_ring); -+ rte_memzone_free(sock->same_node_rx_ring->mz); -+ rte_memzone_free(sock->same_node_rx_ring_mz); -+ rte_memzone_free(sock->same_node_tx_ring->mz); -+ rte_memzone_free(sock->same_node_tx_ring_mz); -+ init_same_node_ring(pcb); -+ return ERR_BUF; -+} -+ -+err_t find_same_node_ring(struct tcp_pcb *npcb) -+{ -+ char name[RING_NAME_LEN] = {0}; -+ snprintf_s(name, sizeof(name), sizeof(name) - 1, "client_tx_ring_%u", npcb->remote_port); -+ npcb->client_rx_ring = rte_ring_lookup(name); -+ memset_s(name, sizeof(name), 0, sizeof(name)); -+ snprintf_s(name, sizeof(name), sizeof(name) - 1, "client_rx_ring_%u", npcb->remote_port); -+ npcb->client_tx_ring = rte_ring_lookup(name); -+ npcb->free_ring = 0; -+ if (npcb->client_tx_ring == NULL || -+ npcb->client_rx_ring == NULL) { -+ LSTACK_LOG(INFO, LSTACK, "lookup client rxtx ring failed, port is %d\n", npcb->remote_port); -+ tcp_abandon(npcb, 0); -+ return ERR_CONN; -+ } else { -+ LSTACK_LOG(INFO, LSTACK, "find client_tx_ring_%u and client_rx_ring_%u\n", -+ npcb->remote_port, npcb->remote_port); -+ } -+ return 0; -+} -+ -+unsigned same_node_ring_count(const struct lwip_sock *sock) -+{ -+ const unsigned long long cur_begin = __atomic_load_n(&sock->same_node_rx_ring->sndbegin, __ATOMIC_RELAXED); -+ const unsigned long long cur_end = __atomic_load_n(&sock->same_node_rx_ring->sndend, __ATOMIC_RELAXED); -+ -+ return cur_end - cur_begin; -+} -+#endif /* GAZELLE_SAME_NODE */ -diff --git a/src/lstack/include/lstack_ethdev.h b/src/lstack/include/lstack_ethdev.h -index 0c3d906..5aeb80d 100644 ---- a/src/lstack/include/lstack_ethdev.h -+++ b/src/lstack/include/lstack_ethdev.h -@@ -32,6 +32,4 @@ void kni_handle_rx(uint16_t port_id); - void kni_handle_tx(struct rte_mbuf *mbuf); - #endif - --void netif_poll(struct netif *netif); -- - #endif /* __GAZELLE_ETHDEV_H__ */ -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index dcb7dac..f2524e4 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -16,15 +16,15 @@ - - #include "common/gazelle_dfx_msg.h" - #include "common/dpdk_common.h" -+#include "same_node.h" - - struct lwip_sock; - struct rpc_msg; - struct protocol_stack; - --unsigned same_node_ring_count(struct lwip_sock *sock); - - #define NETCONN_IS_ACCEPTIN(sock) (((sock)->conn->acceptmbox != NULL) && !sys_mbox_empty((sock)->conn->acceptmbox)) --#define NETCONN_IS_DATAIN(sock) ((gazelle_ring_readable_count((sock)->recv_ring) || (sock)->recv_lastdata) || (sock->same_node_rx_ring != NULL && same_node_ring_count(sock))) -+#define NETCONN_IS_DATAIN(sock) ((gazelle_ring_readable_count((sock)->recv_ring) || (sock)->recv_lastdata) || NETCONN_NEED_SAME_NODE(sock)) - #define NETCONN_IS_DATAOUT(sock) (gazelle_ring_readover_count((sock)->send_ring) || (sock)->send_pre_del) - #define NETCONN_IS_OUTIDLE(sock) gazelle_ring_readable_count((sock)->send_ring) - #define NETCONN_IS_UDP(sock) (NETCONNTYPE_GROUP(netconn_type((sock)->conn)) == NETCONN_UDP) -@@ -63,6 +63,4 @@ void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_soc - uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, uint32_t max_num); - uint32_t do_lwip_get_connnum(void); - --void read_same_node_recv_list(struct protocol_stack *stack); -- - #endif -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index c9c50c9..a278d7a 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -113,7 +113,9 @@ struct protocol_stack *get_protocol_stack_by_fd(int fd); - struct protocol_stack *get_bind_protocol_stack(void); - struct protocol_stack_group *get_protocol_stack_group(void); - -+#if GAZELLE_TCP_REUSE_IPPORT - int get_min_conn_stack(struct protocol_stack_group *stack_group); -+#endif /* GAZELLE_TCP_REUSE_IPPORT */ - void bind_to_stack_numa(struct protocol_stack *stack); - void thread_bind_stack(struct protocol_stack *stack); - -diff --git a/src/lstack/include/same_node.h b/src/lstack/include/same_node.h -new file mode 100644 -index 0000000..90a5b76 ---- /dev/null -+++ b/src/lstack/include/same_node.h -@@ -0,0 +1,35 @@ -+/* -+* 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_SAME_NODE_H__ -+#define __GAZELLE_SAME_NODE_H__ -+ -+#include -+ -+#if GAZELLE_SAME_NODE -+ -+unsigned same_node_ring_count(const struct lwip_sock *sock); -+ -+void read_same_node_recv_list(struct protocol_stack *stack); -+ssize_t gazelle_same_node_ring_recv(struct lwip_sock *sock, const void *buf, size_t len, int32_t flags); -+ssize_t gazelle_same_node_ring_send(struct lwip_sock *sock, const void *buf, size_t len, int32_t flags); -+ -+#define NETCONN_NEED_SAME_NODE(sock) \ -+ ( (sock->same_node_rx_ring && same_node_ring_count(sock)) ) -+ -+#else /* GAZELLE_SAME_NODE */ -+ -+#define NETCONN_NEED_SAME_NODE(sock) false -+ -+#endif /* GAZELLE_SAME_NODE */ -+ -+#endif /* __GAZELLE_SAME_NODE_H__ */ --- -2.33.0 - diff --git a/0324-cleancode-remove-gazelle_light_ring.patch b/0324-cleancode-remove-gazelle_light_ring.patch deleted file mode 100644 index abaa10d5d48c621413166e89237715c8d3dd0173..0000000000000000000000000000000000000000 --- a/0324-cleancode-remove-gazelle_light_ring.patch +++ /dev/null @@ -1,104 +0,0 @@ -From 791872dcb02eacc2bc0e43deb97ecb9cf3cd9711 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 11 Mar 2025 15:06:10 +0800 -Subject: [PATCH] cleancode: remove gazelle_light_ring - -Signed-off-by: Lemmy Huang ---- - src/common/dpdk_common.h | 60 ++++++---------------------------------- - 1 file changed, 8 insertions(+), 52 deletions(-) - -diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h -index 7a05342..8609216 100644 ---- a/src/common/dpdk_common.h -+++ b/src/common/dpdk_common.h -@@ -123,49 +123,6 @@ struct rte_eth_conf; - struct rte_eth_dev_info; - void eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev_info); - --/* -- gazelle custom rte ring interface -- lightweight ring reduce atomic and smp_mb. -- only surpport single-consumers or the single-consumer. -- */ --static __rte_always_inline uint32_t gazelle_light_ring_enqueue_busrt(struct rte_ring *r, void **obj_table, uint32_t n) --{ -- uint32_t cons = __atomic_load_n(&r->cons.tail, __ATOMIC_ACQUIRE); -- uint32_t prod = r->prod.tail; -- uint32_t free_entries = r->capacity + cons - prod; -- -- if (n > free_entries) { -- return 0; -- } -- -- __rte_ring_enqueue_elems(r, prod, obj_table, sizeof(void *), n); -- -- __atomic_store_n(&r->prod.tail, prod + n, __ATOMIC_RELEASE); -- -- return n; --} -- --static __rte_always_inline uint32_t gazelle_light_ring_dequeue_burst(struct rte_ring *r, void **obj_table, uint32_t n) --{ -- uint32_t prod = __atomic_load_n(&r->prod.tail, __ATOMIC_ACQUIRE); -- uint32_t cons = r->cons.tail; -- uint32_t entries = prod - cons; -- -- if (n > entries) { -- n = entries; -- } -- -- if (n == 0) { -- return 0; -- } -- -- __rte_ring_dequeue_elems(r, cons, obj_table, sizeof(void *), n); -- -- __atomic_store_n(&r->cons.tail, cons + n, __ATOMIC_RELEASE); -- -- return n; --} -- - /* - gazelle custom rte ring interface - one thread enqueue and dequeue, other thread read object use and object still in queue. -@@ -177,15 +134,16 @@ static __rte_always_inline uint32_t gazelle_light_ring_dequeue_burst(struct rte_ - gazelle_ring_read: prod.head-->> cons.head, read object, prod.head = prod.tail + N - gazelle_ring_read_over: prod.tail = prod.head, update prod.tail - */ --static __rte_always_inline uint32_t gazelle_ring_sp_enqueue(struct rte_ring *r, void **obj_table, uint32_t n) -+static __rte_always_inline uint32_t gazelle_ring_sp_enqueue(struct rte_ring *r, void *const *obj_table, uint32_t n) - { - uint32_t head = __atomic_load_n(&r->cons.head, __ATOMIC_ACQUIRE); - uint32_t tail = r->cons.tail; - -- uint32_t entries = r->capacity + tail - head; -- if (n > entries) { -+ uint32_t free_entries = r->capacity + tail - head; -+ if (unlikely(free_entries == 0)) - return 0; -- } -+ if (n > free_entries) -+ n = free_entries; - - __rte_ring_enqueue_elems(r, head, obj_table, sizeof(void *), n); - -@@ -200,12 +158,10 @@ static __rte_always_inline uint32_t gazelle_ring_sc_dequeue(struct rte_ring *r, - uint32_t cons = r->cons.tail; - - uint32_t entries = prod - cons; -- if (n > entries) { -- n = entries; -- } -- if (unlikely(n == 0)) { -+ if (unlikely(entries == 0)) - return 0; -- } -+ if (n > entries) -+ n = entries; - - __rte_ring_dequeue_elems(r, cons, obj_table, sizeof(void *), n); - --- -2.33.0 - diff --git a/0325-cleancode-remove-get_stack_tid-DPDK_PKT_BURST_SIZE-P.patch b/0325-cleancode-remove-get_stack_tid-DPDK_PKT_BURST_SIZE-P.patch deleted file mode 100644 index 29914c609bf1a7f7c6bca8e13ae9dd2946d129ab..0000000000000000000000000000000000000000 --- a/0325-cleancode-remove-get_stack_tid-DPDK_PKT_BURST_SIZE-P.patch +++ /dev/null @@ -1,292 +0,0 @@ -From 33b786bd43e769351f89e9500f78819c3550949b Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 11 Mar 2025 15:09:56 +0800 -Subject: [PATCH] cleancode: remove get_stack_tid DPDK_PKT_BURST_SIZE - PACKET_READ_SIZE - -Signed-off-by: Lemmy Huang ---- - src/common/gazelle_base_func.h | 3 --- - src/common/gazelle_opt.h | 10 ++++------ - src/lstack/api/lstack_rtw_api.c | 4 ++-- - src/lstack/core/lstack_protocol_stack.c | 11 ----------- - src/lstack/core/lstack_thread_rpc.c | 16 ++++++++-------- - src/lstack/core/lstack_virtio.c | 3 ++- - src/lstack/include/lstack_protocol_stack.h | 2 -- - src/lstack/netif/lstack_ethdev.c | 5 ++--- - src/lstack/netif/lstack_vdev.c | 8 ++++---- - 9 files changed, 22 insertions(+), 40 deletions(-) - -diff --git a/src/common/gazelle_base_func.h b/src/common/gazelle_base_func.h -index 0ccb34b..29534a7 100644 ---- a/src/common/gazelle_base_func.h -+++ b/src/common/gazelle_base_func.h -@@ -29,9 +29,6 @@ - return -1; \ - } while (0) - --#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) - { -diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h -index d6b1c44..4406831 100644 ---- a/src/common/gazelle_opt.h -+++ b/src/common/gazelle_opt.h -@@ -23,6 +23,9 @@ - #define GAZELLE_TRUE 1 - #define GAZELLE_FALSE 0 - -+#define CPUS_MAX_NUM 640 -+#define GAZELLE_MAX_NUMA_NODES 8 -+ - #define PROTOCOL_STACK_MAX 32 - #define KERNEL_EPOLL_MAX 512 - -@@ -41,7 +44,7 @@ - #define VDEV_IDLE_QUEUE_SZ DEFAULT_RING_SIZE - - #define VDEV_TX_QUEUE_SZ DEFAULT_RING_SIZE --#define FREE_RX_QUEUE_SZ DPDK_PKT_BURST_SIZE -+#define FREE_RX_QUEUE_SZ DEFAULT_RING_SIZE - - #define NIC_QUEUE_SIZE_MAX 8192 - #define NIC_QUEUE_SIZE_MIN 512 -@@ -58,8 +61,6 @@ - #define IPV6_EXTRA_HEAD_LEN 20 - #define MBUF_MAX_DATA_LEN (MTU_DEFAULT_DATA_LEN - VLAN_HEAD_LEN - IPV6_EXTRA_HEAD_LEN) - --#define DPDK_PKT_BURST_SIZE 512 -- - #define GAZELLE_UDP_PKGLEN_MAX (65535 - IP_HLEN - UDP_HLEN) - - /* total:33 client, index 32 is invaild client */ -@@ -109,7 +110,4 @@ - - #define SLEEP_US_BEFORE_LINK_UP 10000 - --#define CPUS_MAX_NUM 640 --#define GAZELLE_MAX_NUMA_NODES 8 -- - #endif /* _GAZELLE_OPT_H_ */ -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index 6d0bd05..35439bc 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -92,7 +92,7 @@ static int stack_broadcast_bind(int fd, const struct sockaddr *name, socklen_t n - - struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL || cur_stack == NULL) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); -+ LSTACK_LOG(ERR, LSTACK, "tid %d, %d get sock null or stack null\n", rte_gettid(), fd); - GAZELLE_RETURN(EBADF); - } - -@@ -229,7 +229,7 @@ static int stack_broadcast_listen(int fd, int backlog) - - struct lwip_sock *sock = lwip_get_socket(fd); - if (sock == NULL || cur_stack == NULL) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null or stack null\n", get_stack_tid(), fd); -+ LSTACK_LOG(ERR, LSTACK, "tid %d, %d get sock null or stack null\n", rte_gettid(), fd); - GAZELLE_RETURN(EBADF); - } - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index b4fb2fd..3bb1eeb 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -76,17 +76,6 @@ static inline void set_stack_idx(uint16_t idx) - g_stack_p = g_stack_group.stacks[idx]; - } - --long get_stack_tid(void) --{ -- static PER_THREAD int32_t g_stack_tid = 0; -- -- if (g_stack_tid == 0) { -- g_stack_tid = rte_gettid(); -- } -- -- return g_stack_tid; --} -- - struct protocol_stack_group *get_protocol_stack_group(void) - { - return &g_stack_group; -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 050594e..26ae501 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -235,7 +235,7 @@ static void callback_socket(struct rpc_msg *msg) - { - msg->result = lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); - if (msg->result < 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, %ld socket failed\n", get_stack_tid(), msg->result); -+ LSTACK_LOG(ERR, LSTACK, "tid %d, %ld socket failed\n", rte_gettid(), msg->result); - } - } - -@@ -253,7 +253,7 @@ static void callback_close(struct rpc_msg *msg) - - msg->result = lwip_close(fd); - if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d failed %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); - } - } - -@@ -272,7 +272,7 @@ static void callback_shutdown(struct rpc_msg *msg) - - msg->result = lwip_shutdown(fd, how); - if (msg->result != 0 && errno != ENOTCONN) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d fail %ld\n", get_stack_tid(), fd, msg->result); -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d fail %ld\n", rte_gettid(), fd, msg->result); - } - - posix_api->shutdown_fn(fd, how); -@@ -282,7 +282,7 @@ static void callback_bind(struct rpc_msg *msg) - { - msg->result = lwip_bind(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].cp, msg->args[MSG_ARG_2].u); - if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d failed %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); - } - } - -@@ -300,7 +300,7 @@ static void callback_listen(struct rpc_msg *msg) - /* new listen add to stack listen list */ - msg->result = lwip_listen(fd, backlog); - if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d failed %ld\n", get_stack_tid(), msg->args[MSG_ARG_0].i, msg->result); -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d failed %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); - } - } - -@@ -509,7 +509,7 @@ static void callback_getsockname(struct rpc_msg *msg) - { - msg->result = lwip_getsockname(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); -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d fail %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); - } - } - -@@ -518,7 +518,7 @@ static void callback_getsockopt(struct rpc_msg *msg) - msg->result = lwip_getsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, - msg->args[MSG_ARG_3].p, msg->args[MSG_ARG_4].p); - if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d, level %d, optname %d, fail %ld\n", get_stack_tid(), -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d, level %d, optname %d, fail %ld\n", rte_gettid(), - msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); - } - } -@@ -528,7 +528,7 @@ static void callback_setsockopt(struct rpc_msg *msg) - msg->result = lwip_setsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, - msg->args[MSG_ARG_3].cp, msg->args[MSG_ARG_4].u); - if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %ld, fd %d, level %d, optname %d, fail %ld\n", get_stack_tid(), -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d, level %d, optname %d, fail %ld\n", rte_gettid(), - msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); - } - } -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index 75a23f2..f6855d1 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -17,12 +17,13 @@ - #include - #include - #include -+#include -+ - #include "lstack_cfg.h" - #include "lstack_log.h" - #include "lstack_port_map.h" - #include "lstack_interrupt.h" - #include "lstack_virtio.h" --#include "securec.h" - - #define VIRTIO_USER_NAME "virtio_user" - #define VIRTIO_DPDK_PARA_LEN 256 -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index a278d7a..3f6e3d3e 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -106,8 +106,6 @@ struct protocol_stack_group { - pthread_spinlock_t socket_lock; - }; - --long get_stack_tid(void); -- - struct protocol_stack *get_protocol_stack(void); - struct protocol_stack *get_protocol_stack_by_fd(int fd); - struct protocol_stack *get_bind_protocol_stack(void); -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 3b859d2..a370714 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -41,7 +41,6 @@ - - /* FRAME_MTU + 14byte header */ - #define MBUF_MAX_LEN 1514 --#define PACKET_READ_SIZE 32 - - /* any protocol stack thread receives arp packet and sync it to other threads, - * so that it can have the arp table */ -@@ -150,11 +149,11 @@ void eth_dev_recv(struct rte_mbuf *mbuf, struct protocol_stack *stack) - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - void kni_handle_rx(uint16_t port_id) - { -- struct rte_mbuf *pkts_burst[PACKET_READ_SIZE]; -+ struct rte_mbuf *pkts_burst[GAZELLE_PACKET_READ_SIZE]; - struct rte_kni* kni = get_gazelle_kni(); - uint32_t nb_kni_rx = 0; - if (kni) { -- nb_kni_rx = rte_kni_rx_burst(kni, pkts_burst, PACKET_READ_SIZE); -+ nb_kni_rx = rte_kni_rx_burst(kni, pkts_burst, GAZELLE_PACKET_READ_SIZE); - } - if (nb_kni_rx > 0) { - uint16_t nb_rx = rte_eth_tx_burst(port_id, 0, pkts_burst, nb_kni_rx); -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 2eaeb1f..14d8cc6 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -57,13 +57,13 @@ static uint32_t ltran_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pk - { - uint32_t rcvd_pkts; - uint32_t nr_pkts; -- struct rte_mbuf *free_buf[DPDK_PKT_BURST_SIZE]; -+ struct rte_mbuf *free_buf[VDEV_RX_QUEUE_SZ]; - - rcvd_pkts = gazelle_ring_sc_dequeue(stack->rx_ring, (void **)pkts, max_mbuf); - - stack->rx_ring_used += rcvd_pkts; - if (unlikely(stack->rx_ring_used >= USED_RX_PKTS_WATERMARK)) { -- uint32_t free_cnt = LWIP_MIN(stack->rx_ring_used, RING_SIZE(DPDK_PKT_BURST_SIZE)); -+ uint32_t free_cnt = LWIP_MIN(stack->rx_ring_used, RING_SIZE(VDEV_RX_QUEUE_SZ)); - int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)free_buf, free_cnt, true); - if (likely(ret == 0)) { - nr_pkts = gazelle_ring_sp_enqueue(stack->rx_ring, (void **)free_buf, free_cnt); -@@ -161,7 +161,7 @@ static uint32_t vdev_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pkt - static uint32_t ltran_tx_xmit(struct protocol_stack *stack, struct rte_mbuf **pkts, uint32_t nr_pkts) - { - uint32_t sent_pkts = 0; -- struct rte_mbuf *free_buf[DPDK_PKT_BURST_SIZE]; -+ struct rte_mbuf *free_buf[VDEV_TX_QUEUE_SZ]; - const uint32_t tbegin = sys_now(); - - do { -@@ -292,7 +292,7 @@ int32_t vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple) - - tmp_buf = &stack->reg_buf[reg_index]; - tmp_buf->type = type; -- tmp_buf->tid = get_stack_tid(); -+ tmp_buf->tid = rte_gettid(); - ret = memcpy_s(&tmp_buf->qtuple, sizeof(*qtuple), qtuple, sizeof(struct gazelle_quintuple)); - if (ret != EOK) { - LSTACK_LOG(ERR, LSTACK, "memcpy_s failed ret=%d.\n", ret); --- -2.33.0 - diff --git a/0326-socket-refactor-sock_event.patch b/0326-socket-refactor-sock_event.patch deleted file mode 100644 index 007cbc96eb5a636495851c924d906a4d5b891e96..0000000000000000000000000000000000000000 --- a/0326-socket-refactor-sock_event.patch +++ /dev/null @@ -1,1613 +0,0 @@ -From 2168db467896885c571dafb98ed03a90101c98d2 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 21 Mar 2025 16:42:43 +0800 -Subject: [PATCH] socket: refactor sock_event - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 846 ++++++++++++++++++++++++++++++ - src/lstack/core/lstack_wait.c | 550 +++++++++++++++++++ - src/lstack/include/lstack_epoll.h | 18 + - src/lstack/include/lstack_wait.h | 138 +++++ - 4 files changed, 1552 insertions(+) - create mode 100644 src/lstack/core/lstack_wait.c - create mode 100644 src/lstack/include/lstack_wait.h - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 644efc0..a110aa1 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -10,6 +10,8 @@ - * See the Mulan PSL v2 for more details. - */ - -+#if !SOCK_EVENT_V2 -+ - #include - #include - #include -@@ -1038,3 +1040,847 @@ int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfd - - return event_num; - } -+ -+#else /* SOCK_EVENT_V2 */ -+ -+#include -+#include -+#include -+#include -+ -+#include -+ -+#include -+#include -+#include -+ -+#include "lstack_epoll.h" -+#include "common/dpdk_common.h" -+#include "common/gazelle_base_func.h" -+#include "lstack_preload.h" -+#include "lstack_cfg.h" -+#include "lstack_log.h" -+#include "lstack_protocol_stack.h" -+ -+#define POLL_MAX_EVENTS 32 -+ -+static PER_THREAD struct sock_wait *g_sk_wait = NULL; -+ -+ -+static int rtc_sock_wait_timedwait(struct sock_wait *sk_wait, int timeout, uint32_t start) -+{ -+ stack_polling(0); -+ -+ if (timeout > 0 && timeout <= (int)(sys_now() - start)) { -+ timeout = 0; -+ } -+ return timeout; -+} -+ -+static int rtw_sock_wait_timedwait(struct sock_wait *sk_wait, int timeout, uint32_t start) -+{ -+ return sys_mutex_timedlock_internal(&sk_wait->mutex, timeout); -+} -+ -+static void rtc_epoll_notify_event(struct sock_wait *sk_wait, struct sock_event *sk_event, -+ unsigned pending, int stack_id) -+{ -+ sk_event->pending |= pending; -+ if (list_node_null(&sk_event->event_node)) { -+ list_add_node(&sk_event->event_node, &sk_wait->epcb.event_list); -+ } -+} -+ -+static void rtc_epoll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending) -+{ -+ sk_event->pending &= ~pending; -+ if (sk_event->pending == 0) { -+ list_del_node(&sk_event->event_node); -+ } -+} -+ -+static void rtw_epoll_notify_event(struct sock_wait *sk_wait, struct sock_event *sk_event, -+ unsigned pending, int stack_id) -+{ -+#if SOCK_WAIT_BATCH_NOTIFY -+ if (likely(stack_id >= 0)) { -+ lwip_wait_add_notify(sk_wait, sk_event, pending, stack_id); -+ return; -+ } -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ -+ -+ rte_spinlock_lock(&sk_wait->epcb.lock); -+ sk_event->pending |= pending; -+ if (list_node_null(&sk_event->event_node)) { -+ list_add_node(&sk_event->event_node, &sk_wait->epcb.event_list); -+ } -+ rte_spinlock_unlock(&sk_wait->epcb.lock); -+ -+ sys_mutex_unlock_internal(&sk_wait->mutex); -+} -+ -+static void rtw_epoll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending) -+{ -+ rte_spinlock_lock(&sk_wait->epcb.lock); -+ sk_event->pending &= ~pending; -+ if (sk_event->pending == 0) { -+ list_del_node(&sk_event->event_node); -+ } -+ rte_spinlock_unlock(&sk_wait->epcb.lock); -+} -+ -+static void rtc_poll_notify_event(struct sock_wait *sk_wait, struct sock_event *sk_event, -+ unsigned pending, int stack_id) -+{ -+} -+static void rtc_poll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending) -+{ -+} -+static void rtw_poll_notify_event(struct sock_wait *sk_wait, struct sock_event *sk_event, -+ unsigned pending, int stack_id) -+{ -+#if SOCK_WAIT_BATCH_NOTIFY -+ if (likely(stack_id >= 0)) { -+ lwip_wait_add_notify(sk_wait, NULL, 0, stack_id); -+ return; -+ } -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ -+ sys_mutex_unlock_internal(&sk_wait->mutex); -+} -+static void rtw_poll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending) -+{ -+} -+ -+/* Cannot support the same sock being waited by both epoll/poll/select or multiple epollfd. */ -+static void sock_wait_check_change(struct sock_wait *new_sk_wait, struct sock_wait *old_sk_wait) -+{ -+ if (old_sk_wait == NULL || new_sk_wait == old_sk_wait || -+ old_sk_wait->type == WAIT_CLOSE) { -+ return; -+ } -+ -+ if (new_sk_wait->type & WAIT_EPOLL) { -+ if (old_sk_wait->type & WAIT_EPOLL) { -+ LSTACK_LOG(ERR, LSTACK, "Cannot support the same sock being waited by multiple epollfd! \n"); -+ } else { -+ LSTACK_LOG(ERR, LSTACK, "Cannot support the same sock being waited by both epoll/poll/select! \n"); -+ } -+ } -+} -+ -+ -+static int epoll_cb_init(struct epoll_cb *epcb) -+{ -+ list_init_head(&epcb->event_list); -+ rte_spinlock_init(&epcb->lock); -+ return 0; -+} -+ -+static void epoll_cb_free(struct epoll_cb *epcb) -+{ -+ struct list_node *node, *temp; -+ struct sock_event *sk_event; -+ -+ rte_spinlock_lock(&epcb->lock); -+ -+ list_for_each_node(node, temp, &epcb->event_list) { -+ sk_event = list_entry(node, struct sock_event, event_node); -+ list_del_node(&sk_event->event_node); -+ } -+ -+ rte_spinlock_unlock(&epcb->lock); -+} -+ -+static int epoll_create_internal(int epfd) -+{ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ bool rtc_mode = get_global_cfg_params()->stack_mode_rtc; -+ struct sock_wait *sk_wait; -+ struct lwip_sock *epsock; -+ -+ epsock = lwip_get_socket(epfd); -+ if (epsock == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "epfd=%d sock is NULL errno=%d\n", epfd, errno); -+ GAZELLE_RETURN(EINVAL); -+ } -+ -+ /* calloc will memset to zero */ -+ sk_wait = calloc(1, sizeof(struct sock_wait)); -+ if (sk_wait == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "calloc null\n"); -+ GAZELLE_RETURN(EINVAL); -+ } -+ -+ sk_wait->type = WAIT_EPOLL; -+ sock_wait_common_init(sk_wait); -+ sock_wait_kernel_init(sk_wait, epfd, stack_group->stack_num); -+ epoll_cb_init(&sk_wait->epcb); -+ -+ if (rtc_mode) { -+ sk_wait->timedwait_fn = rtc_sock_wait_timedwait; -+ sk_wait->notify_fn = rtc_epoll_notify_event; -+ sk_wait->remove_fn = rtc_epoll_remove_event; -+ } else { -+ sk_wait->timedwait_fn = rtw_sock_wait_timedwait; -+ sk_wait->notify_fn = rtw_epoll_notify_event; -+ sk_wait->remove_fn = rtw_epoll_remove_event; -+ } -+ -+ epsock->sk_wait = sk_wait; -+ return 0; -+} -+ -+static int epoll_close_internal(int epfd) -+{ -+ struct sock_wait *sk_wait; -+ struct lwip_sock *epsock; -+ -+ epsock = lwip_get_socket(epfd); -+ if (epsock == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "epfd=%d sock is NULL errno=%d\n", epfd, errno); -+ GAZELLE_RETURN(EINVAL); -+ } -+ -+ sk_wait = epsock->sk_wait; -+ if (sk_wait == NULL) { -+ return 0; -+ } -+ -+ sk_wait->type = WAIT_CLOSE; -+ epoll_cb_free(&sk_wait->epcb); -+ -+ posix_api->close_fn(sk_wait->epfd); -+ sock_wait_kernel_free(sk_wait); -+ sock_wait_common_free(sk_wait); -+ -+ sk_wait->timedwait_fn = NULL; -+ sk_wait->notify_fn = NULL; -+ sk_wait->remove_fn = NULL; -+ -+ /* FIXME: set all 'sock->sk_wait = NULL' before free. */ -+ free(sk_wait); -+ epsock->sk_wait = NULL; -+ -+ return 0; -+} -+ -+int lstack_epoll_create1(int flags) -+{ -+ int epfd = posix_api->epoll_create1_fn(flags); -+ if (epfd != -1) { -+ if (epoll_create_internal(epfd) != 0) { -+ posix_api->close_fn(epfd); -+ epfd = -1; -+ } -+ } -+ return epfd; -+} -+ -+int lstack_epoll_create(int size) -+{ -+ /* Since Linux 2.6.8, the size argument is ignored, -+ * but must be greater than zero. */ -+ return size <= 0 ? -1 : lstack_epoll_create1(0); -+} -+ -+int lstack_epoll_close(int epfd) -+{ -+ epoll_close_internal(epfd); -+ return posix_api->close_fn(epfd); -+} -+ -+int lstack_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) -+{ -+ int ret; -+ struct lwip_sock *epsock = lwip_get_socket(epfd); -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ struct sock_wait *sk_wait = epsock->sk_wait; -+ struct sock_event *sk_event; -+ unsigned pending; -+ -+ if (epfd < 0 || fd < 0 || epfd == fd || \ -+ (event == NULL && op != EPOLL_CTL_DEL)) { -+ LSTACK_LOG(ERR, LSTACK, "fd=%d epfd=%d op=%d\n", fd, epfd, op); -+ GAZELLE_RETURN(EINVAL); -+ } -+ -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(epfd=%d, op=%d, fd=%d, event=%p)\n", -+ __FUNCTION__, epfd, op, fd, event)); -+ -+ enum posix_type sk_type = select_sock_posix_path(sock); -+ /* has POSIX_LWIP */ -+ if (sk_type != POSIX_LWIP) { -+ ret = posix_api->epoll_ctl_fn(epfd, op, fd, event); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "epoll_ctl_fn failed, fd=%d epfd=%d op=%d\n", fd, epfd, op); -+ return ret; -+ } -+ if (op == EPOLL_CTL_ADD) { -+ sk_wait->kernel_nfds++; -+ } else if (op == EPOLL_CTL_DEL) { -+ sk_wait->kernel_nfds--; -+ } -+ } -+ /* is POSIX_KERNEL */ -+ if (sk_type == POSIX_KERNEL) -+ return ret; -+ -+ for (; sock != NULL; sock = sock->listen_next) { -+ sk_event = &sock->sk_event; -+ -+ switch (op) { -+ case EPOLL_CTL_ADD: -+ sock_wait_check_change(sk_wait, sock->sk_wait); -+ sock->sk_wait = sk_wait; -+ /* fall through */ -+ case EPOLL_CTL_MOD: -+ sk_event->events = event->events | EPOLLERR | EPOLLHUP; -+ sk_event->ep_data = event->data; -+ -+ pending = sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_RCVPLUS, 0) | -+ sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_SENDPLUS, 0) | -+ sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_ERROR, 0); -+ sk_wait->notify_fn(sk_wait, sk_event, pending, -1); -+ -+ sk_wait->lwip_nfds++; -+ sk_wait->affinity.stack_nfds[sock->stack_id]++; -+ break; -+ case EPOLL_CTL_DEL: -+ sk_event->events = 0; -+ -+ pending = sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_RCVMINUS, 0) | -+ sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_SENDMINUS, 0) | -+ sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_ERROR, 0); -+ sk_wait->remove_fn(sk_wait, sk_event, pending); -+ -+ sk_wait->lwip_nfds--; -+ sk_wait->affinity.stack_nfds[sock->stack_id]--; -+ break; -+ default: -+ GAZELLE_RETURN(EINVAL); -+ } -+ } -+ -+ if (get_global_cfg_params()->app_bind_numa) { -+ affinity_update_max_stack(&sk_wait->affinity); -+ } -+ return 0; -+} -+ -+static int epoll_scan_lwip_event(struct epoll_cb *epcb, struct epoll_event *events, int maxevents) -+{ -+ bool rtc_mode = get_global_cfg_params()->stack_mode_rtc; -+ struct list_node *node, *temp; -+ struct sock_event *sk_event; -+ int num = 0; -+ -+ if (!rtc_mode) -+ rte_spinlock_lock(&epcb->lock); -+ -+ list_for_each_node(node, temp, &epcb->event_list) { -+ sk_event = list_entry(node, struct sock_event, event_node); -+ if (num >= maxevents) { -+ /* move list head after the current node, -+ * and start traversing from this node next time */ -+ list_del_node(&epcb->event_list); -+ list_add_node(&epcb->event_list, node); -+ break; -+ } -+ -+ if ((sk_event->events & sk_event->pending) == 0) { -+ // LSTACK_LOG(WARNING, LSTACK, "get empty event\n"); -+ list_del_node(node); -+ continue; -+ } -+ -+ events[num].events = sk_event->pending; -+ events[num].data = sk_event->ep_data; -+ num++; -+ -+ if (sk_event->events & EPOLLET) { -+ sk_event->pending = 0; -+ list_del_node(node); -+ } -+ -+ /* EPOLLONESHOT: generate event after epoll_ctl add/mod event again, -+ * epoll_event set 0 avoid generating event util epoll_ctl reset epoll_event */ -+ if (sk_event->events & EPOLLONESHOT) { -+ sk_event->events = 0; -+ list_del_node(node); -+ } -+ } -+ -+ if (!rtc_mode) -+ rte_spinlock_unlock(&epcb->lock); -+ -+ return num; -+} -+ -+int lstack_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) -+{ -+ bool rtc_mode = get_global_cfg_params()->stack_mode_rtc; -+ struct lwip_sock *epsock = lwip_get_socket(epfd); -+ struct sock_wait *sk_wait = epsock->sk_wait; -+ int kernel_num = 0; -+ int lwip_num = 0; -+ int lwip_maxevents; -+ uint32_t start; -+ -+ if (unlikely(epfd < 0)) { -+ GAZELLE_RETURN(EBADF); -+ } -+ if (unlikely(events == NULL || maxevents <= 0 || timeout < -1)) { -+ GAZELLE_RETURN(EINVAL); -+ } -+ -+ if (get_global_cfg_params()->app_bind_numa) { -+ affinity_bind_stack(sk_wait, &sk_wait->affinity); -+ } -+ -+ /* avoid RTC app process events for a long time */ -+ if (rtc_mode && maxevents > POLL_MAX_EVENTS) { -+ maxevents = POLL_MAX_EVENTS; -+ } -+ /* avoid the starvation of poll events from both kernel and lwip */ -+ lwip_maxevents = (maxevents >> 1) + 1; -+ -+ start = sys_now(); -+ -+ /* RTC try to recv polling. */ -+ sk_wait->timedwait_fn(sk_wait, 0, start); -+ do { -+ if (likely(sk_wait->lwip_nfds > 0)) { -+ lwip_num = epoll_scan_lwip_event(&sk_wait->epcb, events, lwip_maxevents); -+ } -+ -+ if (sk_wait->kernel_nfds > 0 && rte_atomic16_read(&sk_wait->kernel_pending)) { -+ kernel_num = posix_api->epoll_wait_fn( -+ sk_wait->epfd, &events[lwip_num], maxevents - lwip_num, 0); -+ if (unlikely(kernel_num == 0) && errno != EINTR && errno != EAGAIN) { -+ rte_atomic16_set(&sk_wait->kernel_pending, false); -+ } -+ } -+ -+ if (lwip_num + kernel_num > 0) { -+ break; -+ } -+ -+ timeout = sk_wait->timedwait_fn(sk_wait, timeout, start); -+ } while (timeout != 0); -+ -+ sk_wait->stat.app_events += lwip_num; -+ sk_wait->stat.kernel_events += kernel_num; -+ -+ return lwip_num + kernel_num; -+} -+ -+static void poll_cb_free(struct poll_cb *pcb) -+{ -+ if (pcb->lwip_p_fds != NULL) { -+ free(pcb->lwip_p_fds); -+ pcb->lwip_p_fds = NULL; -+ } -+ if (pcb->kernel_fds != NULL) { -+ free(pcb->kernel_fds); -+ pcb->kernel_fds = NULL; -+ } -+} -+ -+static int poll_cb_init(struct poll_cb *pcb, int nfds) -+{ -+ if (nfds <= 0) -+ return 0; -+ -+ pcb->lwip_p_fds = calloc(1, sizeof(*pcb->lwip_p_fds) * nfds); -+ pcb->kernel_fds = calloc(1, sizeof(*pcb->kernel_fds) * nfds); -+ -+ if (pcb->lwip_p_fds == NULL || pcb->kernel_fds == NULL) { -+ poll_cb_free(pcb); -+ return -1; -+ } -+ -+ pcb->max_nfds = nfds; -+ return 0; -+} -+ -+static int poll_init_wait(struct sock_wait *sk_wait, int nfds) -+{ -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ bool rtc_mode = get_global_cfg_params()->stack_mode_rtc; -+ int epfd; -+ -+ epfd = posix_api->epoll_create_fn(POLL_MAX_EVENTS); -+ if (epfd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "epoll_create failed, errno %d\n", errno); -+ return -1; -+ } -+ -+ sk_wait->type = WAIT_POLL; -+ sock_wait_common_init(sk_wait); -+ sock_wait_kernel_init(sk_wait, epfd, stack_group->stack_num); -+ -+ if (rtc_mode) { -+ sk_wait->timedwait_fn = rtc_sock_wait_timedwait; -+ sk_wait->notify_fn = rtc_poll_notify_event; -+ sk_wait->remove_fn = rtc_poll_remove_event; -+ } else { -+ sk_wait->timedwait_fn = rtw_sock_wait_timedwait; -+ sk_wait->notify_fn = rtw_poll_notify_event; -+ sk_wait->remove_fn = rtw_poll_remove_event; -+ } -+ -+ return poll_cb_init(&sk_wait->pcb, nfds); -+} -+ -+static void poll_free_wait(struct sock_wait *sk_wait) -+{ -+ sk_wait->type = WAIT_CLOSE; -+ poll_cb_free(&sk_wait->pcb); -+ -+ posix_api->close_fn(sk_wait->epfd); -+ sock_wait_kernel_free(sk_wait); -+ sock_wait_common_free(sk_wait); -+ -+ sk_wait->timedwait_fn = NULL; -+ sk_wait->notify_fn = NULL; -+ sk_wait->remove_fn = NULL; -+} -+ -+void poll_destruct_wait(void) -+{ -+ if (unlikely(g_sk_wait == NULL)) { -+ return; -+ } -+ -+ poll_free_wait(g_sk_wait); -+ -+ /* FIXME: set all 'sock->sk_wait = NULL' before free. */ -+ free(g_sk_wait); -+ g_sk_wait = NULL; -+} -+ -+struct sock_wait *poll_construct_wait(int nfds) -+{ -+ if (unlikely(g_sk_wait == NULL)) { -+ g_sk_wait = calloc(1, sizeof(struct sock_wait)); -+ if (g_sk_wait == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "calloc failed errno=%d\n", errno); -+ return NULL; -+ } -+ -+ if (poll_init_wait(g_sk_wait, nfds) < 0) { -+ free(g_sk_wait); -+ return NULL; -+ } -+ } -+ -+ /* resize poll_cb */ -+ if (g_sk_wait->pcb.max_nfds < nfds) { -+ poll_cb_free(&g_sk_wait->pcb); -+ if (poll_cb_init(&g_sk_wait->pcb, nfds) != 0) { -+ return NULL; -+ } -+ } -+ -+ return g_sk_wait; -+} -+ -+static bool poll_ctl_kernel_event(int epfd, int fds_id, -+ const struct pollfd *new_fds, const struct pollfd *old_fds) -+{ -+ int ret; -+ struct epoll_event epevent; -+ -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(epfd=%d, old_fd=%d, new_fd=%d)\n", -+ __FUNCTION__, epfd, old_fds->fd, new_fds->fd)); -+ -+ epevent.data.fd = fds_id; -+ epevent.events = new_fds->events; -+ -+ /* EPOLL_CTL_MOD may not be any events, but why? */ -+ if (old_fds->fd == 0) { -+ ret = posix_api->epoll_ctl_fn(epfd, EPOLL_CTL_ADD, new_fds->fd, &epevent); -+ } else { -+ ret = posix_api->epoll_ctl_fn(epfd, EPOLL_CTL_DEL, old_fds->fd, NULL); -+ ret |= posix_api->epoll_ctl_fn(epfd, EPOLL_CTL_ADD, new_fds->fd, &epevent); -+ } -+ -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "epoll_ctl failed, errno %d, new_fd %d, old_fd %d\n", -+ errno, new_fds->fd, old_fds->fd); -+ } -+ return true; -+} -+ -+static int poll_wait_kernel_event(int epfd, struct pollfd *fds, int maxevents) -+{ -+ struct epoll_event epevents[POLL_MAX_EVENTS]; -+ int num = 0; -+ int i, fds_id; -+ -+ num = posix_api->epoll_wait_fn(epfd, epevents, maxevents, 0); -+ for (i = 0; i < num; ++i) { -+ fds_id = epevents[i].data.fd; -+ fds[fds_id].revents = epevents[i].events; -+ } -+ -+ return num; -+} -+ -+static void poll_prepare_wait(struct sock_wait *sk_wait, struct pollfd *fds, nfds_t nfds) -+{ -+ struct poll_cb *pcb = &sk_wait->pcb; -+ struct lwip_sock *sock; -+ enum posix_type sk_type; -+ int fd, i; -+ -+ sk_wait->lwip_nfds = 0; -+ sk_wait->kernel_nfds = 0; -+ memset_s(&sk_wait->affinity.stack_nfds, sizeof(sk_wait->affinity.stack_nfds), -+ 0, sizeof(sk_wait->affinity.stack_nfds)); -+ -+ for (i = 0; i < nfds; ++i) { -+ fd = fds[i].fd; -+ sock = lwip_get_socket(fd); -+ sk_type = select_sock_posix_path(sock); -+ -+ if (sk_type & POSIX_KERNEL) { -+ poll_ctl_kernel_event(sk_wait->epfd, i, &fds[i], -+ &pcb->kernel_fds[sk_wait->kernel_nfds]); -+ pcb->kernel_fds[sk_wait->kernel_nfds] = fds[i]; -+ sk_wait->kernel_nfds++; -+ } -+ -+ if (sk_type & POSIX_LWIP) { -+ pcb->lwip_p_fds[sk_wait->lwip_nfds] = &fds[i]; -+ sk_wait->lwip_nfds++; -+ -+ for (; sock != NULL; sock = sock->listen_next) { -+ sock->sk_event.events = fds[i].events | POLLERR; -+ sock_wait_check_change(sk_wait, sock->sk_wait); -+ sock->sk_wait = sk_wait; -+ sk_wait->affinity.stack_nfds[sock->stack_id]++; -+ } -+ } -+ } -+ -+ if (get_global_cfg_params()->app_bind_numa) { -+ affinity_update_max_stack(&sk_wait->affinity); -+ affinity_bind_stack(sk_wait, &sk_wait->affinity); -+ } -+ -+ return; -+} -+ -+static int poll_scan_lwip_event(struct poll_cb *pcb, int nfds, int maxevents) -+{ -+ struct lwip_sock *sock; -+ struct pollfd *fds; -+ int num = 0; -+ int i; -+ -+ for (i = 0; i < nfds && num < maxevents; ++i) { -+ fds = pcb->lwip_p_fds[i]; -+ sock = lwip_get_socket(fds->fd); -+ -+ for (; !POSIX_IS_CLOSED(sock); sock = sock->listen_next) { -+ fds->revents = sock_event_hold_pending(sock, WAIT_POLL, NETCONN_EVT_RCVPLUS, 0) | -+ sock_event_hold_pending(sock, WAIT_POLL, NETCONN_EVT_SENDPLUS, 0) | -+ sock_event_hold_pending(sock, WAIT_POLL, NETCONN_EVT_ERROR, 0); -+ if (fds->revents != 0) { -+ num++; -+ break; -+ } -+ } -+ } -+ -+ return num; -+} -+ -+int lstack_poll(struct pollfd *fds, nfds_t nfds, int timeout) -+{ -+ struct sock_wait *sk_wait; -+ int kernel_num = 0; -+ int lwip_num = 0; -+ uint32_t start; -+ -+ if (unlikely(fds == NULL || nfds == 0 || timeout < -1)) { -+ GAZELLE_RETURN(EINVAL); -+ } -+ -+ sk_wait = poll_construct_wait(nfds); -+ if (unlikely(sk_wait == NULL)) { -+ return -1; -+ } -+ poll_prepare_wait(sk_wait, fds, nfds); -+ -+ if (sk_wait->lwip_nfds == 0 && sk_wait->kernel_nfds > 0) { -+ return posix_api->poll_fn(fds, nfds, timeout); -+ } -+ -+ start = sys_now(); -+ -+ /* RTC try to recv polling. */ -+ sk_wait->timedwait_fn(sk_wait, 0, start); -+ do { -+ if (sk_wait->lwip_nfds > 0) { -+ lwip_num = poll_scan_lwip_event(&sk_wait->pcb, sk_wait->lwip_nfds, nfds); -+ } -+ -+ if (sk_wait->kernel_nfds > 0 && rte_atomic16_read(&sk_wait->kernel_pending)) { -+ kernel_num = poll_wait_kernel_event(sk_wait->epfd, fds, sk_wait->kernel_nfds); -+ if (kernel_num == 0 && errno != EINTR && errno != EAGAIN) { -+ rte_atomic16_set(&sk_wait->kernel_pending, false); -+ } -+ } -+ -+ if (lwip_num + kernel_num > 0) { -+ break; -+ } -+ -+ timeout = sk_wait->timedwait_fn(sk_wait, timeout, start); -+ } while (timeout != 0); -+ -+ sk_wait->stat.app_events += lwip_num; -+ sk_wait->stat.kernel_events += kernel_num; -+ -+ return lwip_num + kernel_num; -+} -+ -+/* refer to linux kernel */ -+#define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN | EPOLLHUP | EPOLLERR) -+#define POLLOUT_SET (EPOLLWRBAND | EPOLLWRNORM | EPOLLOUT | EPOLLERR) -+#define POLLEX_SET (EPOLLPRI) -+ -+static int fds_select2poll(struct pollfd *fds, int maxfd, -+ fd_set *readfds, fd_set *writefds, fd_set *exceptfds) -+{ -+ int nfds = 0; -+ -+ for (int i = 0; i < maxfd; i++) { -+ if (readfds && FD_ISSET(i, readfds)) { -+ fds[nfds].events = POLLIN_SET; -+ } -+ if (writefds && FD_ISSET(i, writefds)) { -+ fds[nfds].events |= POLLOUT_SET; -+ } -+ if (exceptfds && FD_ISSET(i, exceptfds)) { -+ fds[nfds].events |= POLLEX_SET; -+ } -+ if (fds[nfds].events > 0) { -+ fds[nfds].fd = i; -+ nfds++; -+ } -+ } -+ -+ return nfds; -+} -+ -+static void fds_poll2select(const struct pollfd *fds, int nfds, -+ fd_set *readfds, fd_set *writefds, fd_set *exceptfds) -+{ -+ if (readfds) -+ FD_ZERO(readfds); -+ if (writefds) -+ FD_ZERO(writefds); -+ if (exceptfds) -+ FD_ZERO(exceptfds); -+ -+ for (int i = 0; i < nfds; ++i) { -+ if (readfds && fds[i].revents & POLLIN_SET) { -+ FD_SET(fds[i].fd, readfds); -+ } -+ if (writefds && fds[i].revents & POLLOUT_SET) { -+ FD_SET(fds[i].fd, writefds); -+ } -+ if (exceptfds && fds[i].revents & POLLEX_SET) { -+ FD_SET(fds[i].fd, exceptfds); -+ } -+ } -+} -+ -+static inline int timeval2ms(struct timeval *timeval) -+{ -+ if (timeval == NULL) { -+ return -1; -+ } -+ return timeval->tv_sec * MS_PER_S + timeval->tv_usec / (US_PER_S / MS_PER_S); -+} -+ -+int lstack_select(int nfds, fd_set *readfds, fd_set *writefds, -+ fd_set *exceptfds, struct timeval *timeout) -+{ -+ struct pollfd poll_fds[FD_SETSIZE] = {0}; -+ int poll_nfds, num; -+ int time_ms; -+ -+ if (unlikely(nfds < 0 || nfds > FD_SETSIZE)) { -+ LSTACK_LOG(ERR, LSTACK, "select invalid args, nfds=%d\n", nfds); -+ GAZELLE_RETURN(EINVAL); -+ } -+ if (timeout != NULL && unlikely(timeout->tv_sec < 0 || timeout->tv_usec < 0)) { -+ LSTACK_LOG(ERR, LSTACK, "select invalid args, timeout\n"); -+ GAZELLE_RETURN(EINVAL); -+ } -+ /* empty fds, just timeout */ -+ if (!readfds && !writefds && !exceptfds) { -+ return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); -+ } -+ -+ time_ms = timeval2ms(timeout); -+ -+ poll_nfds = fds_select2poll(poll_fds, nfds, readfds, writefds, exceptfds); -+ num = lstack_poll(poll_fds, poll_nfds, time_ms); -+ fds_poll2select(poll_fds, poll_nfds, readfds, writefds, exceptfds); -+ -+ return num; -+} -+ -+void epoll_api_init(posix_api_t *api) -+{ -+ api->epoll_create1_fn = lstack_epoll_create1; -+ api->epoll_create_fn = lstack_epoll_create; -+ api->epoll_ctl_fn = lstack_epoll_ctl; -+ api->epoll_wait_fn = lstack_epoll_wait; -+ -+ api->poll_fn = lstack_poll; -+ api->select_fn = lstack_select; -+} -+ -+bool sock_event_wait(struct lwip_sock *sock, bool noblocking) -+{ -+ bool rtc_mode = get_global_cfg_params()->stack_mode_rtc; -+ uint32_t start; -+ int timeout; -+ unsigned pending; -+ -+ if (!rtc_mode && noblocking) -+ return false; -+ -+ if (unlikely(sock->sk_wait == NULL) || sock->sk_wait->type == WAIT_CLOSE) { -+ sock->sk_wait = poll_construct_wait(0); -+ } -+ if (!(sock->sk_wait->type & WAIT_BLOCK)) { -+ sock->sk_wait->type |= WAIT_BLOCK; -+ } -+ -+ if (rtc_mode) { -+ /* RTC try to recv polling. */ -+ sock->sk_wait->timedwait_fn(sock->sk_wait, 0, 0); -+ return true; -+ } -+ -+ timeout = sock->conn->recv_timeout == 0 ? -1 : sock->conn->recv_timeout; -+ start = sys_now(); -+ do { -+ pending = sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_RCVPLUS, 0) | -+ sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0); -+ if (pending) { -+ return true; -+ } -+ timeout = sock->sk_wait->timedwait_fn(sock->sk_wait, timeout, start); -+ } while (timeout != 0); -+ -+ return false; -+} -+#endif /* SOCK_EVENT_V2 */ -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -new file mode 100644 -index 0000000..c67df93 ---- /dev/null -+++ b/src/lstack/core/lstack_wait.c -@@ -0,0 +1,550 @@ -+/* -+* 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 -+#include -+ -+#include -+#include -+ -+#include -+#include -+#include -+#include -+ -+#include "common/gazelle_base_func.h" -+#include "lstack_wait.h" -+#include "lstack_log.h" -+#include "lstack_cfg.h" -+#include "same_node.h" -+#include "mbox_ring.h" -+ -+#define KERNEL_EVENT_WAIT_US 10 -+#define LWIP_EVENT_WAIT_US 10 -+ -+struct kernel_wait { -+ int epfd; -+}; -+ -+struct lwip_wait { -+#if SOCK_WAIT_BATCH_NOTIFY -+ struct list_node stk_notify_list; -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ -+} __rte_cache_aligned; -+ -+struct sock_wait_group { -+ struct kernel_wait kwaits[PROTOCOL_STACK_MAX]; -+ struct lwip_wait lwaits[PROTOCOL_STACK_MAX]; -+ -+ _Atomic uint16_t affinity_tick; -+ -+ /* new cache line */ -+ char pad0 __rte_cache_aligned; -+ -+ /* dfx stat */ -+ struct list_node group_list; -+ rte_spinlock_t group_list_lock; -+}; -+static struct sock_wait_group g_wait_group = {0}; -+ -+static inline struct kernel_wait *kernel_wait_get(int stack_id) -+{ -+ if (unlikely(stack_id < 0 || stack_id >= PROTOCOL_STACK_MAX)) { -+ return NULL; -+ } -+ return &g_wait_group.kwaits[stack_id]; -+} -+ -+static inline struct lwip_wait *lwip_wait_get(int stack_id) -+{ -+ if (unlikely(stack_id < 0 || stack_id >= PROTOCOL_STACK_MAX)) { -+ return NULL; -+ } -+ return &g_wait_group.lwaits[stack_id]; -+} -+ -+static int lwip_wait_init(int stack_id) -+{ -+ struct lwip_wait *lwait = lwip_wait_get(stack_id); -+ LWIP_UNUSED_ARG(lwait); -+ -+#if SOCK_WAIT_BATCH_NOTIFY -+ list_init_head(&lwait->stk_notify_list); -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ -+ return 0; -+} -+ -+static int kernel_wait_init(int stack_id) -+{ -+ struct kernel_wait *kwait = kernel_wait_get(stack_id); -+ -+ kwait->epfd = posix_api->epoll_create_fn(GAZELLE_LSTACK_MAX_CONN); -+ if (kwait->epfd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "epoll_create failed, errno %d\n", errno); -+ return -1; -+ } -+ -+ return 0; -+} -+ -+int sock_wait_group_init(void) -+{ -+ list_init_head(&g_wait_group.group_list); -+ rte_spinlock_init(&g_wait_group.group_list_lock); -+ return 0; -+} -+ -+static inline void sock_wait_group_add(struct sock_wait *sk_wait) -+{ -+ list_init_node(&sk_wait->group_node); -+ -+ rte_spinlock_lock(&g_wait_group.group_list_lock); -+ list_add_node(&sk_wait->group_node, &g_wait_group.group_list); -+ rte_spinlock_unlock(&g_wait_group.group_list_lock); -+} -+ -+static inline void sock_wait_group_del(struct sock_wait *sk_wait) -+{ -+ rte_spinlock_lock(&g_wait_group.group_list_lock); -+ list_del_node(&sk_wait->group_node); -+ rte_spinlock_unlock(&g_wait_group.group_list_lock); -+} -+ -+void sock_wait_group_stat(int stack_id, struct gazelle_wakeup_stat *stat) -+{ -+ struct sock_wait *sk_wait; -+ struct list_node *node, *next; -+ -+ rte_spinlock_lock(&g_wait_group.group_list_lock); -+ -+ list_for_each_node(node, next, &g_wait_group.group_list) { -+ sk_wait = list_entry(node, struct sock_wait, group_node); -+ -+ if (sk_wait->affinity.bind_stack_id == stack_id) { -+ memcpy_s(stat, sizeof(struct gazelle_wakeup_stat), -+ &sk_wait->stat, sizeof(struct gazelle_wakeup_stat)); -+ } -+ } -+ -+ rte_spinlock_unlock(&g_wait_group.group_list_lock); -+} -+ -+int kernel_wait_ctl(struct sock_wait *sk_wait, int new_stack_id, int old_stack_id) -+{ -+ int ret; -+ struct kernel_wait *old_kwait = kernel_wait_get(old_stack_id); -+ struct kernel_wait *new_kwait = kernel_wait_get(new_stack_id); -+ struct epoll_event epevent; -+ -+ /* not change */ -+ if (old_kwait != NULL && old_kwait == new_kwait) { -+ return 0; -+ } -+ -+ if (old_kwait) { -+ ret = posix_api->epoll_ctl_fn(old_kwait->epfd, EPOLL_CTL_DEL, sk_wait->epfd, NULL); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "epoll_ctl failed, errno %d\n", errno); -+ return -1; -+ } -+ } -+ -+ if (new_kwait) { -+ epevent.events = EPOLLIN | EPOLLOUT | EPOLLERR | EPOLLHUP | EPOLLET; -+ epevent.data.ptr = sk_wait; -+ ret = posix_api->epoll_ctl_fn(new_kwait->epfd, EPOLL_CTL_ADD, sk_wait->epfd, &epevent); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "epoll_ctl failed, errno %d\n", errno); -+ return -1; -+ } -+ } -+ -+ return 0; -+} -+ -+void* kernel_wait_thread(void *arg) -+{ -+ struct thread_params *t_params = (struct thread_params*) arg; -+ unsigned stack_id = t_params->idx; -+ struct epoll_event kernel_events[KERNEL_EPOLL_MAX]; -+ int num, i; -+ struct kernel_wait *kwait; -+ struct sock_wait *sk_wait; -+ -+ bind_to_stack_numa(stack_id); -+ free(arg); -+ sem_post(&get_protocol_stack_group()->sem_stack_setup); -+ -+ lwip_wait_init(stack_id); -+ kernel_wait_init(stack_id); -+ kwait = kernel_wait_get(stack_id); -+ -+ LSTACK_LOG(INFO, LSTACK, "kernelevent_%02hu start\n", stack_id); -+ -+ for (;;) { -+ num = posix_api->epoll_wait_fn(kwait->epfd, kernel_events, KERNEL_EPOLL_MAX, -1); -+ if (num < 0 && errno != EINTR && errno != EAGAIN) { -+ LSTACK_LOG(ERR, LSTACK, "epoll_wait faild, errno %d\n", errno); -+ } -+ -+ for (i = 0; i < num; ++i) { -+ sk_wait = kernel_events[i].data.ptr; -+ if (sk_wait->type == WAIT_CLOSE) -+ continue; -+ rte_atomic16_set(&sk_wait->kernel_pending, true); -+ sys_mutex_unlock_internal(&sk_wait->mutex); -+ } -+ usleep(KERNEL_EVENT_WAIT_US); -+ } -+ -+ return NULL; -+} -+ -+static unsigned affinity_choice_stack(int stack_num) -+{ -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ return get_protocol_stack()->stack_idx; -+ } -+ return atomic_fetch_add(&g_wait_group.affinity_tick, 1) % stack_num; -+} -+ -+static void affinity_find_max_stack(struct wait_affinity *affinity, int stack_num) -+{ -+ int max_stack_id = affinity->max_stack_id; -+ -+ for (int i = 0; i < stack_num; i++) { -+ if (affinity->stack_nfds[i] > affinity->stack_nfds[max_stack_id]) { -+ max_stack_id = i; -+ } -+ } -+ affinity->max_stack_id = max_stack_id; -+} -+ -+void affinity_update_max_stack(struct wait_affinity *affinity) -+{ -+ struct protocol_stack_group *stack_group; -+ -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ affinity->max_stack_id = get_protocol_stack()->stack_idx; -+ } else { -+ stack_group = get_protocol_stack_group(); -+ affinity_find_max_stack(affinity, stack_group->stack_num); -+ } -+} -+ -+void affinity_bind_stack(struct sock_wait *sk_wait, struct wait_affinity *affinity) -+{ -+ if (affinity->max_stack_id != affinity->bind_stack_id) { -+ bind_to_stack_numa(affinity->max_stack_id); -+ kernel_wait_ctl(sk_wait, affinity->max_stack_id, affinity->bind_stack_id); -+ affinity->bind_stack_id = affinity->max_stack_id; -+ } -+} -+ -+int sock_event_init(struct sock_event *sk_event) -+{ -+ memset_s(sk_event, sizeof(struct sock_event), 0, sizeof(struct sock_event)); -+ -+ list_init_node(&sk_event->event_node); -+#if SOCK_WAIT_BATCH_NOTIFY -+ list_init_node(&sk_event->stk_event_node); -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ -+ return 0; -+} -+ -+void sock_event_free(struct sock_event *sk_event, struct sock_wait *sk_wait) -+{ -+ if (sk_wait && sk_wait->type & WAIT_EPOLL) { -+ rte_spinlock_lock(&sk_wait->epcb.lock); -+ list_del_node(&sk_event->event_node); -+ rte_spinlock_unlock(&sk_wait->epcb.lock); -+ -+#if SOCK_WAIT_BATCH_NOTIFY -+ list_del_node(&sk_event->stk_event_node); -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ -+ } -+} -+ -+int sock_wait_common_init(struct sock_wait *sk_wait) -+{ -+ sk_wait->lwip_nfds = 0; -+ sk_wait->kernel_nfds = 0; -+ sys_mutex_new_internal(&sk_wait->mutex); -+ -+#if SOCK_WAIT_BATCH_NOTIFY -+ for (int i = 0; i < PROTOCOL_STACK_MAX; ++i) { -+ list_init_node(&sk_wait->stk_notify_node[i]); -+ list_init_head(&sk_wait->stk_event_list[i]); -+ } -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ -+ sock_wait_group_add(sk_wait); -+ -+ return 0; -+} -+ -+void sock_wait_common_free(struct sock_wait *sk_wait) -+{ -+#if SOCK_WAIT_BATCH_NOTIFY -+ bool wait_stack; -+ -+ /* wait lwip_wait_foreach_notify() finish. */ -+ do { -+ wait_stack = false; -+ for (int i = 0; i < PROTOCOL_STACK_MAX; ++i) { -+ rte_mb(); -+ if (!list_node_null(&sk_wait->stk_notify_node[i])) { -+ wait_stack = true; -+ usleep(LWIP_EVENT_WAIT_US); -+ break; -+ } -+ } -+ } while (wait_stack); -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ -+ -+ sock_wait_group_del(sk_wait); -+ sys_mutex_free_internal(&sk_wait->mutex); -+} -+ -+int sock_wait_kernel_init(struct sock_wait *sk_wait, int epfd, int stack_num) -+{ -+ sk_wait->epfd = epfd; -+ sk_wait->affinity.max_stack_id = affinity_choice_stack(stack_num); -+ kernel_wait_ctl(sk_wait, sk_wait->affinity.max_stack_id, -1); -+ sk_wait->affinity.bind_stack_id = sk_wait->affinity.max_stack_id; -+ -+ rte_atomic16_init(&sk_wait->kernel_pending); -+ rte_atomic16_set(&sk_wait->kernel_pending, true); -+ return 0; -+} -+ -+void sock_wait_kernel_free(struct sock_wait *sk_wait) -+{ -+ kernel_wait_ctl(sk_wait, -1, sk_wait->affinity.bind_stack_id); -+ sk_wait->epfd = -1; -+ sk_wait->affinity.bind_stack_id = -1; -+ sk_wait->affinity.max_stack_id = -1; -+ -+ rte_atomic16_clear(&sk_wait->kernel_pending); -+} -+ -+ -+static inline bool NETCONN_NEED_ACCEPT(const struct lwip_sock *sock) -+{ -+ if (sys_mbox_valid(&sock->conn->acceptmbox)) { -+ const struct mbox_ring *mr = &sock->conn->acceptmbox->mring; -+ return mr->ops->count(mr) > 0; -+ } -+ return false; -+} -+ -+static inline bool NETCONN_NEED_RECV(const struct lwip_sock *sock) -+{ -+ if (sock->lastdata.pbuf != NULL) -+ return true; -+ if (sys_mbox_valid(&sock->conn->recvmbox)) { -+ const struct mbox_ring *mr = &sock->conn->recvmbox->mring; -+ return mr->ops->recv_count(mr) > 0; -+ } -+ return false; -+} -+ -+static inline bool NETCONN_ALLOW_SEND(const struct lwip_sock *sock) -+{ -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ if (NETCONN_TYPE(sock->conn) == NETCONN_TCP) -+ return lwip_tcp_allow_send(sock->conn->pcb.tcp); -+ return false; -+ } -+ if (sys_mbox_valid(&sock->conn->sendmbox)) { -+ const struct mbox_ring *mr = &sock->conn->sendmbox->mring; -+ return mr->ops->free_count(mr) > 0; -+ } -+ return false; -+} -+ -+static unsigned sock_event_lose_pending(const struct lwip_sock *sock, enum netconn_evt evt, unsigned len) -+{ -+ unsigned event = 0; -+ -+ switch (evt) { -+ case NETCONN_EVT_RCVMINUS: -+ if (sock->sk_event.events & EPOLLIN) { -+ if (!NETCONN_NEED_RECV(sock) && -+ !NETCONN_NEED_ACCEPT(sock)) { -+ event = EPOLLIN; -+ } -+ } -+ break; -+ case NETCONN_EVT_SENDMINUS: -+ if (sock->sk_event.events & EPOLLOUT) { -+ if (!NETCONN_ALLOW_SEND(sock)) { -+ event = EPOLLOUT; -+ } -+ } -+ break; -+ default: -+ break; -+ } -+ -+ return event; -+} -+ -+unsigned sock_event_hold_pending(const struct lwip_sock *sock, -+ enum sock_wait_type type, enum netconn_evt evt, unsigned len) -+{ -+ unsigned event = 0; -+ -+ switch (evt) { -+ case NETCONN_EVT_RCVPLUS: -+ if (sock->sk_event.events & EPOLLIN || type & WAIT_BLOCK) { -+ if (len > 0 || -+ NETCONN_NEED_RECV(sock) || -+ NETCONN_NEED_ACCEPT(sock)) { -+ event = EPOLLIN; -+ } -+ } -+ break; -+ case NETCONN_EVT_SENDPLUS: -+ if (sock->sk_event.events & EPOLLOUT) { -+ if (len > 0 || -+ NETCONN_ALLOW_SEND(sock)) { -+ event = EPOLLOUT; -+ } -+ } -+ break; -+ case NETCONN_EVT_ERROR: -+ if (sock->errevent) { -+ event = EPOLLERR | EPOLLHUP | EPOLLIN; -+ } -+ break; -+ default: -+ break; -+ } -+ -+ return event; -+} -+ -+void sock_event_remove_pending(struct lwip_sock *sock, enum netconn_evt evt, unsigned len) -+{ -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(sock=%p, sk_wait=%p, evt=%d, len=%u)\n", -+ __FUNCTION__, sock, sock->sk_wait, evt, len)); -+ -+ if (sock->sk_wait == NULL) { -+ return; -+ } -+ if (unlikely(sock->sk_wait->type == WAIT_CLOSE)) { -+ sock->sk_wait = NULL; -+ return; -+ } -+ -+ unsigned pending = sock_event_lose_pending(sock, evt, 0); -+ if (pending) { -+ sock->sk_wait->remove_fn(sock->sk_wait, &sock->sk_event, pending); -+ } -+} -+ -+void sock_event_notify_pending(struct lwip_sock *sock, enum netconn_evt evt, unsigned len) -+{ -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(sock=%p, sk_wait=%p, evt=%d, len=%u)\n", -+ __FUNCTION__, sock, sock->sk_wait, evt, len)); -+ -+ if (sock->sk_wait == NULL) { -+ return; -+ } -+ if (unlikely(sock->sk_wait->type == WAIT_CLOSE)) { -+ sock->sk_wait = NULL; -+ return; -+ } -+ -+ unsigned pending = sock_event_hold_pending(sock, sock->sk_wait->type, evt, len); -+ if (pending) { -+ sock->sk_wait->notify_fn(sock->sk_wait, &sock->sk_event, pending, sock->stack_id); -+ } -+} -+ -+#if SOCK_WAIT_BATCH_NOTIFY -+/* Only allow stack call */ -+void lwip_wait_add_notify(struct sock_wait *sk_wait, struct sock_event *sk_event, -+ unsigned pending, int stack_id) -+{ -+ struct lwip_wait *lwait = lwip_wait_get(stack_id); -+ -+ if (sk_event != NULL) { -+ sk_event->stk_pending |= pending; -+ if (list_node_null(&sk_event->stk_event_node)) { -+ list_add_node(&sk_event->stk_event_node, &sk_wait->stk_event_list[stack_id]); -+ } -+ } -+ -+ if (list_node_null(&sk_wait->stk_notify_node[stack_id])) { -+ list_add_node(&sk_wait->stk_notify_node[stack_id], &lwait->stk_notify_list); -+ } -+} -+ -+static inline -+unsigned sock_wait_foreach_event(struct sock_wait *sk_wait, int stack_id) -+{ -+ struct list_node *node, *next; -+ struct sock_event *sk_event; -+ unsigned count = 0; -+ -+ /* only rtw epoll need */ -+ if (list_head_empty(&sk_wait->stk_event_list[stack_id])) -+ return 0; -+ -+ rte_spinlock_lock(&sk_wait->epcb.lock); -+ -+ list_for_each_node(node, next, &sk_wait->stk_event_list[stack_id]) { -+ list_del_node(node); -+ sk_event = container_of(node, struct sock_event, stk_event_node); -+ -+ /* see rtw_epoll_notify_event() */ -+ sk_event->pending |= sk_event->stk_pending; -+ if (list_node_null(&sk_event->event_node)) { -+ list_add_node(&sk_event->event_node, &sk_wait->epcb.event_list); -+ } -+ -+ sk_event->stk_pending = 0; -+ count++; -+ } -+ -+ rte_spinlock_unlock(&sk_wait->epcb.lock); -+ -+ return count; -+} -+ -+/* Only allow stack call */ -+unsigned lwip_wait_foreach_notify(int stack_id) -+{ -+ struct lwip_wait *lwait = lwip_wait_get(stack_id); -+ struct sock_wait *sk_wait; -+ struct list_node *node, *next; -+ unsigned count = 0; -+ -+ list_for_each_node(node, next, &lwait->stk_notify_list) { -+ list_del_node(node); -+ sk_wait = container_of_uncheck_ptr((node - stack_id), struct sock_wait, stk_notify_node); -+ -+ sock_wait_foreach_event(sk_wait, stack_id); -+ -+ sys_mutex_unlock_internal(&sk_wait->mutex); -+ count++; -+ } -+ return count; -+} -+ -+bool lwip_wait_notify_empty(int stack_id) -+{ -+ struct lwip_wait *lwait = lwip_wait_get(stack_id); -+ return list_head_empty(&lwait->stk_notify_list); -+} -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ -diff --git a/src/lstack/include/lstack_epoll.h b/src/lstack/include/lstack_epoll.h -index 83eace7..9a5d15a 100644 ---- a/src/lstack/include/lstack_epoll.h -+++ b/src/lstack/include/lstack_epoll.h -@@ -13,6 +13,8 @@ - #ifndef _GAZELLE_EPOLL_H_ - #define _GAZELLE_EPOLL_H_ - -+#if /* SOCK_EVENT_V2 */ -+ - #include - #include - #include -@@ -88,4 +90,20 @@ static inline void lstack_block_wakeup(struct wakeup_poll *wakeup) - } - } - -+#else /* SOCK_EVENT_V2 */ -+ -+#include -+#include -+ -+#include "lstack_wait.h" -+ -+struct sock_wait *poll_construct_wait(int nfds); -+void poll_destruct_wait(void); -+ -+int lstack_epoll_close(int epfd); -+void epoll_api_init(posix_api_t *api); -+bool sock_event_wait(struct lwip_sock *sock, bool noblocking); -+ -+#endif /* SOCK_EVENT_V2 */ -+ - #endif /* _GAZELLE_EPOLL_H_ */ -diff --git a/src/lstack/include/lstack_wait.h b/src/lstack/include/lstack_wait.h -new file mode 100644 -index 0000000..ed154b4 ---- /dev/null -+++ b/src/lstack/include/lstack_wait.h -@@ -0,0 +1,138 @@ -+/* -+* 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 _LSTACK_WAIT_H_ -+#define _LSTACK_WAIT_H_ -+ -+#include -+#include -+#include -+#include -+ -+#include -+#include -+ -+#include -+#include -+#include -+#include -+ -+#include "common/gazelle_dfx_msg.h" -+#include "lstack_protocol_stack.h" -+#include "lstack_cfg.h" -+ -+ -+#define NETCONN_TYPE(conn) NETCONNTYPE_GROUP(netconn_type((conn))) -+ -+enum sock_wait_type { -+ WAIT_CLOSE = 0x00, -+ WAIT_POLL = 0x01, -+ WAIT_EPOLL = 0x02, -+ WAIT_BLOCK = 0x04, -+ WAIT_MAX = 0x08, -+}; -+ -+struct wait_affinity { -+ int bind_stack_id; -+ int max_stack_id; -+ unsigned stack_nfds[PROTOCOL_STACK_MAX]; -+}; -+ -+/* epoll control block */ -+struct epoll_cb { -+ struct list_node event_list; -+ rte_spinlock_t lock; -+}; -+ -+/* poll control block */ -+struct poll_cb { -+ int max_nfds; -+ struct pollfd **lwip_p_fds; -+ struct pollfd *kernel_fds; -+}; -+ -+struct sock_wait { -+ enum sock_wait_type type; -+ -+ /* blocking and return 0 on timeout */ -+ int (*timedwait_fn)(struct sock_wait *sk_wait, int timeout, uint32_t start); -+ /* trigger event */ -+ void (*notify_fn)(struct sock_wait *sk_wait, struct sock_event *sk_event, -+ unsigned pending, int stack_id); -+ /* remove event */ -+ void (*remove_fn)(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending); -+ -+ /* dfx stat */ -+ struct list_node group_node; -+ struct gazelle_wakeup_stat stat; -+ -+ /* epoll kernel fd */ -+ int epfd; -+ -+ /* socket count */ -+ unsigned lwip_nfds; -+ unsigned kernel_nfds; -+ struct wait_affinity affinity; -+ -+ char pad0 __rte_cache_aligned; /* new cache line */ -+ -+#if SOCK_WAIT_BATCH_NOTIFY -+ /* lwip event foreach notify list */ -+ struct list_node __rte_cache_aligned stk_notify_node[PROTOCOL_STACK_MAX]; -+ struct list_node __rte_cache_aligned stk_event_list[PROTOCOL_STACK_MAX]; -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ -+ -+ char pad1 __rte_cache_aligned; /* new cache line */ -+ -+ /* kernel event flag */ -+ rte_atomic16_t kernel_pending; -+ /* run-to-wakeup blocking lock */ -+ struct sys_mutex mutex; -+ -+ union { -+ struct epoll_cb epcb; -+ struct poll_cb pcb; -+ }; -+}; -+ -+ -+int sock_wait_group_init(void); -+void sock_wait_group_stat(int stack_id, struct gazelle_wakeup_stat *stat); -+ -+void* kernel_wait_thread(void *arg); -+int kernel_wait_ctl(struct sock_wait *sk_wait, int new_stack_id, int old_stack_id); -+ -+#if SOCK_WAIT_BATCH_NOTIFY -+void lwip_wait_add_notify(struct sock_wait *sk_wait, struct sock_event *sk_event, -+ unsigned pending, int stack_id); -+unsigned lwip_wait_foreach_notify(int stack_id); -+bool lwip_wait_notify_empty(int stack_id); -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ -+ -+unsigned sock_event_hold_pending(const struct lwip_sock *sock, -+ enum sock_wait_type type, enum netconn_evt evt, unsigned len); -+void sock_event_notify_pending(struct lwip_sock *sock, enum netconn_evt evt, unsigned len); -+void sock_event_remove_pending(struct lwip_sock *sock, enum netconn_evt evt, unsigned len); -+ -+int sock_event_init(struct sock_event *sk_event); -+void sock_event_free(struct sock_event *sk_event, struct sock_wait *sk_wait); -+ -+int sock_wait_common_init(struct sock_wait *sk_wait); -+void sock_wait_common_free(struct sock_wait *sk_wait); -+ -+int sock_wait_kernel_init(struct sock_wait *sk_wait, int epfd, int stack_num); -+void sock_wait_kernel_free(struct sock_wait *sk_wait); -+ -+void affinity_update_max_stack(struct wait_affinity *affinity); -+void affinity_bind_stack(struct sock_wait *sk_wait, struct wait_affinity *affinity); -+ -+#endif /* _LSTACK_WAIT_H_ */ --- -2.33.0 - diff --git a/0327-socket-adapt-to-sock_event.patch b/0327-socket-adapt-to-sock_event.patch deleted file mode 100644 index c0255396d975eb7747dddb5886d0d0f303306c49..0000000000000000000000000000000000000000 --- a/0327-socket-adapt-to-sock_event.patch +++ /dev/null @@ -1,2955 +0,0 @@ -From 9098cb36f9a28fcc64b90168c71dfa4910c607ec Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 21 Mar 2025 16:53:37 +0800 -Subject: [PATCH] socket: adapt to sock_event - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 1034 -------------------- - src/lstack/api/lstack_rtc_api.c | 79 +- - src/lstack/api/lstack_rtw_api.c | 189 ++-- - src/lstack/api/lstack_wrap.c | 153 +-- - src/lstack/core/lstack_lwip.c | 217 ++-- - src/lstack/core/lstack_protocol_stack.c | 116 +-- - src/lstack/core/lstack_stack_stat.c | 32 +- - src/lstack/core/lstack_thread_rpc.c | 29 +- - src/lstack/core/lstack_wait.c | 26 +- - src/lstack/core/same_node.c | 5 +- - src/lstack/include/lstack_epoll.h | 81 -- - src/lstack/include/lstack_lwip.h | 4 - - src/lstack/include/lstack_protocol_stack.h | 52 +- - src/lstack/include/lstack_thread_rpc.h | 1 - - 14 files changed, 312 insertions(+), 1706 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index a110aa1..3940f43 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -10,1039 +10,6 @@ - * See the Mulan PSL v2 for more details. - */ - --#if !SOCK_EVENT_V2 -- --#include --#include --#include --#include --#include --#include --#include --#include -- --#include --#include -- --#include "lstack_stack_stat.h" --#include "lstack_cfg.h" --#include "lstack_log.h" --#include "common/dpdk_common.h" --#include "common/gazelle_base_func.h" --#include "lstack_lwip.h" --#include "lstack_protocol_stack.h" --#include "lstack_epoll.h" -- --#define EPOLL_KERNEL_INTERVAL 10 /* ms */ --#define SEC_TO_NSEC 1000000000 --#define SEC_TO_MSEC 1000 --#define MSEC_TO_NSEC 1000000 --#define POLL_KERNEL_EVENTS 32 -- --static void update_epoll_max_stack(struct wakeup_poll *wakeup); --static void change_epollfd_kernel_thread(struct wakeup_poll *wakeup, struct protocol_stack *old_stack, -- struct protocol_stack *new_stack); -- --static inline void add_wakeup_to_stack_wakeuplist(struct wakeup_poll *wakeup, struct protocol_stack *stack) --{ -- if (list_node_null(&wakeup->wakeup_list[stack->stack_idx])) { -- list_add_node(&wakeup->wakeup_list[stack->stack_idx], &stack->wakeup_list); -- } --} -- --void add_sock_event_nolock(struct lwip_sock *sock, uint32_t event) --{ -- struct wakeup_poll *wakeup = sock->wakeup; -- -- if (wakeup == NULL || wakeup->type == WAKEUP_CLOSE || (event & sock->epoll_events) == 0) { -- return; -- } -- -- if (!get_global_cfg_params()->stack_mode_rtc) { -- if (event == EPOLLIN && !NETCONN_IS_DATAIN(sock) && !NETCONN_IS_ACCEPTIN(sock)) { -- return; -- } -- -- if (event == EPOLLOUT && !NETCONN_IS_OUTIDLE(sock)) { -- return; -- } -- } -- -- sock->events |= (event == EPOLLERR) ? (EPOLLIN | EPOLLERR) : (event & sock->epoll_events); -- if (list_node_null(&sock->event_list)) { -- list_add_node(&sock->event_list, &wakeup->event_list); -- } -- return; --} -- --static void _add_sock_event(struct lwip_sock *sock, struct wakeup_poll *wakeup, uint32_t event) --{ -- struct protocol_stack *stack = sock->stack; -- 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; -- } -- -- if (wakeup->type == WAKEUP_EPOLL) { -- pthread_spin_lock(&wakeup->event_list_lock); -- add_sock_event_nolock(sock, event); -- pthread_spin_unlock(&wakeup->event_list_lock); -- } -- -- add_wakeup_to_stack_wakeuplist(wakeup, stack); -- 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) { -- sock->events &= ~event; -- } else { -- if ((event & EPOLLOUT) && !NETCONN_IS_OUTIDLE(sock)) { -- sock->events &= ~EPOLLOUT; -- } -- if ((event & EPOLLIN) && !NETCONN_IS_DATAIN(sock) && !NETCONN_IS_ACCEPTIN(sock)) { -- sock->events &= ~EPOLLIN; -- } -- } -- -- if (sock->events == 0) { -- list_del_node(&sock->event_list); -- } -- return; --} -- --void del_sock_event(struct lwip_sock *sock, uint32_t event) --{ -- pthread_spin_lock(&sock->wakeup->event_list_lock); -- del_sock_event_nolock(sock, event); -- pthread_spin_unlock(&sock->wakeup->event_list_lock); --} -- --void wakeup_stack_epoll(struct protocol_stack *stack) --{ -- struct list_node *node, *temp; -- -- list_for_each_node(node, temp, &stack->wakeup_list) { -- struct wakeup_poll *wakeup = container_of_uncheck_ptr((node - stack->stack_idx), struct wakeup_poll, wakeup_list); -- -- if (__atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { -- __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -- rte_mb(); -- sem_post(&wakeup->wait); -- stack->stats.wakeup_events++; -- } -- -- list_del_node(&wakeup->wakeup_list[stack->stack_idx]); -- } --} -- --static uint32_t update_events(struct lwip_sock *sock) --{ -- uint32_t event = 0; -- -- if (sock->epoll_events & EPOLLIN) { -- if (NETCONN_IS_DATAIN(sock) || NETCONN_IS_ACCEPTIN(sock)) { -- event |= EPOLLIN; -- } -- } -- -- if ((sock->epoll_events & EPOLLOUT) && NETCONN_IS_OUTIDLE(sock)) { -- /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ -- if (!POSIX_IS_CLOSED(sock) && POSIX_IS_TYPE(sock, POSIX_LWIP)) { -- event |= EPOLLOUT; -- } -- } -- -- if (sock->errevent > 0) { -- event |= EPOLLERR | EPOLLIN; -- } -- -- return event; --} -- --static void rtc_raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *sock) --{ -- uint32_t event = 0; -- -- if (sock->rcvevent) { -- event |= EPOLLIN; -- } -- -- if (sock->errevent > 0) { -- event |= EPOLLERR | EPOLLIN; -- } -- -- if (sock->sendevent) { -- /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ -- if (!POSIX_IS_CLOSED(sock) && POSIX_IS_TYPE(sock, POSIX_LWIP)) { -- event |= EPOLLOUT; -- } -- } -- -- if (event) { -- sock->events = event; -- 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); -- } -- } --} -- --static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *sock) --{ -- uint32_t event = 0; -- -- pthread_spin_lock(&wakeup->event_list_lock); -- if (NETCONN_IS_DATAIN(sock) || NETCONN_IS_ACCEPTIN(sock)) { -- event |= EPOLLIN; -- } -- -- if (sock->errevent > 0) { -- event |= EPOLLERR | EPOLLIN; -- } -- -- if (NETCONN_IS_OUTIDLE(sock)) { -- /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ -- if (!POSIX_IS_CLOSED(sock) && POSIX_IS_TYPE(sock, POSIX_LWIP)) { -- event |= EPOLLOUT; -- } -- } -- -- if (event) { -- sock->events = event; -- 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); -- rte_mb(); -- sem_post(&wakeup->wait); -- } -- } -- pthread_spin_unlock(&wakeup->event_list_lock); --} -- --int32_t lstack_do_epoll_create(int32_t fd) --{ -- if (fd < 0) { -- return fd; -- } -- -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "fd=%d sock is NULL errno=%d\n", fd, errno); -- posix_api->close_fn(fd); -- GAZELLE_RETURN(EINVAL); -- } -- -- struct wakeup_poll *wakeup = calloc(1, sizeof(struct wakeup_poll)); -- if (wakeup == NULL) { -- LSTACK_LOG(ERR, LSTACK, "calloc null\n"); -- posix_api->close_fn(fd); -- GAZELLE_RETURN(EINVAL); -- } -- -- for (uint32_t i = 0; i < PROTOCOL_STACK_MAX; i++) { -- list_init_node(&wakeup->wakeup_list[i]); -- } -- -- if (sem_init(&wakeup->wait, 0, 0) != 0) { -- posix_api->close_fn(fd); -- free(wakeup); -- GAZELLE_RETURN(EINVAL); -- } -- __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -- -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- list_init_node(&wakeup->poll_list); -- pthread_spin_lock(&stack_group->poll_list_lock); -- list_add_node(&wakeup->poll_list, &stack_group->poll_list); -- pthread_spin_unlock(&stack_group->poll_list_lock); -- -- list_init_head(&wakeup->event_list); -- pthread_spin_init(&wakeup->event_list_lock, PTHREAD_PROCESS_PRIVATE); -- -- wakeup->type = WAKEUP_EPOLL; -- wakeup->epollfd = fd; -- sock->wakeup = wakeup; -- -- if (!get_global_cfg_params()->stack_mode_rtc) { -- update_epoll_max_stack(wakeup); -- change_epollfd_kernel_thread(wakeup, wakeup->bind_stack, wakeup->max_stack); -- wakeup->bind_stack = wakeup->max_stack; -- if (get_global_cfg_params()->app_bind_numa) { -- bind_to_stack_numa(wakeup->bind_stack); -- } -- } else { -- wakeup->bind_stack = wakeup->max_stack = get_protocol_stack(); -- change_epollfd_kernel_thread(wakeup, NULL, wakeup->max_stack); -- } -- -- return fd; --} -- --int32_t lstack_epoll_create1(int32_t flags) --{ -- int32_t fd = posix_api->epoll_create1_fn(flags); -- return lstack_do_epoll_create(fd); --} -- --int32_t lstack_epoll_create(int32_t flags) --{ -- int32_t fd = posix_api->epoll_create_fn(flags); -- return lstack_do_epoll_create(fd); --} -- --static void stack_broadcast_clean_epoll(struct wakeup_poll *wakeup) --{ -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- struct protocol_stack *stack = NULL; -- -- for (int32_t i = 0; i < stack_group->stack_num; i++) { -- stack = stack_group->stacks[i]; -- rpc_call_clean_epoll(&stack->rpc_queue, wakeup); -- } --} -- --int32_t lstack_epoll_close(int32_t fd) --{ -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "fd=%d sock is NULL errno=%d\n", fd, errno); -- GAZELLE_RETURN(EINVAL); -- } -- -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- struct wakeup_poll *wakeup = sock->wakeup; -- if (wakeup == NULL) { -- return 0; -- } -- -- wakeup->type = WAKEUP_CLOSE; -- -- if (!get_global_cfg_params()->stack_mode_rtc) { -- stack_broadcast_clean_epoll(wakeup); -- } -- -- struct list_node *node, *temp; -- pthread_spin_lock(&wakeup->event_list_lock); -- list_for_each_node(node, temp, &wakeup->event_list) { -- struct lwip_sock *sock = list_entry(node, struct lwip_sock, event_list); -- list_del_node(&sock->event_list); -- } -- pthread_spin_unlock(&wakeup->event_list_lock); -- pthread_spin_destroy(&wakeup->event_list_lock); -- -- pthread_spin_lock(&stack_group->poll_list_lock); -- list_del_node(&wakeup->poll_list); -- pthread_spin_unlock(&stack_group->poll_list_lock); -- -- sem_destroy(&wakeup->wait); -- -- free(wakeup); -- sock->wakeup = NULL; -- -- posix_api->close_fn(fd); -- return 0; --} -- --static uint16_t find_max_cnt_stack(int32_t *stack_count, uint16_t stack_num, struct protocol_stack *last_stack) --{ -- uint16_t max_index = 0; -- bool all_same_cnt = true; -- -- for (uint16_t i = 1; i < stack_num; i++) { -- if (stack_count[i] != stack_count[0]) { -- all_same_cnt = false; -- } -- -- if (stack_count[i] > stack_count[max_index]) { -- max_index = i; -- } -- } -- -- /* all stack same, don't change */ -- if (all_same_cnt && last_stack) { -- return last_stack->stack_idx; -- } -- -- /* first bind and all stack same. choice tick as queue_id, avoid all bind to statck_0. */ -- static _Atomic uint16_t tick = 0; -- if (all_same_cnt && stack_num) { -- max_index = atomic_fetch_add(&tick, 1) % stack_num; -- } -- -- return max_index; --} -- --static void update_epoll_max_stack(struct wakeup_poll *wakeup) --{ -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- uint16_t bind_id = find_max_cnt_stack(wakeup->stack_fd_cnt, stack_group->stack_num, wakeup->max_stack); -- -- wakeup->max_stack = stack_group->stacks[bind_id]; --} -- --int32_t lstack_rtc_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event *event) --{ -- if (epfd < 0 || fd < 0 || epfd == fd || (event == NULL && op != EPOLL_CTL_DEL)) { -- LSTACK_LOG(ERR, LSTACK, "fd=%d epfd=%d op=%d\n", fd, epfd, op); -- GAZELLE_RETURN(EINVAL); -- } -- -- struct lwip_sock *epoll_sock = lwip_get_socket(epfd); -- if (epoll_sock == NULL || epoll_sock->wakeup == NULL) { -- return posix_api->epoll_ctl_fn(epfd, op, fd, event); -- } -- -- struct wakeup_poll *wakeup = epoll_sock->wakeup; -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (POSIX_IS_CLOSED(sock)) { -- return posix_api->epoll_ctl_fn(epfd, op, fd, event); -- } -- -- switch (op) { -- case EPOLL_CTL_ADD: -- sock->wakeup = wakeup; -- /* fall through */ -- case EPOLL_CTL_MOD: -- sock->epoll_events = event->events | EPOLLERR | EPOLLHUP; -- sock->ep_data = event->data; -- rtc_raise_pending_events(wakeup, sock); -- break; -- case EPOLL_CTL_DEL: -- sock->epoll_events = 0; -- list_del_node(&sock->event_list); -- break; -- default: -- GAZELLE_RETURN(EINVAL); -- } -- -- return 0; --} -- --int32_t lstack_rtw_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event *event) --{ -- LSTACK_LOG(DEBUG, LSTACK, "op=%d events: fd: %d\n", op, fd); -- -- if (epfd < 0 || fd < 0 || epfd == fd || (event == NULL && op != EPOLL_CTL_DEL)) { -- LSTACK_LOG(ERR, LSTACK, "fd=%d epfd=%d op=%d\n", fd, epfd, op); -- GAZELLE_RETURN(EINVAL); -- } -- -- struct lwip_sock *epoll_sock = lwip_get_socket(epfd); -- if (epoll_sock == NULL || epoll_sock->wakeup == NULL) { -- return posix_api->epoll_ctl_fn(epfd, op, fd, event); -- } -- -- struct wakeup_poll *wakeup = epoll_sock->wakeup; -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (POSIX_IS_CLOSED(sock) || POSIX_IS_TYPE(sock, POSIX_KERNEL)) { -- return posix_api->epoll_ctl_fn(epfd, op, fd, event); -- } -- -- if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { -- int32_t ret = posix_api->epoll_ctl_fn(epfd, op, fd, event); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "fd=%d epfd=%d op=%d errno=%d\n", fd, epfd, op, errno); -- } -- } -- -- do { -- switch (op) { -- case EPOLL_CTL_ADD: -- sock->wakeup = wakeup; -- wakeup->stack_fd_cnt[sock->stack->stack_idx]++; -- /* fall through */ -- case EPOLL_CTL_MOD: -- sock->epoll_events = event->events | EPOLLERR | EPOLLHUP; -- sock->ep_data = event->data; -- raise_pending_events(wakeup, sock); -- break; -- case EPOLL_CTL_DEL: -- sock->epoll_events = 0; -- wakeup->stack_fd_cnt[sock->stack->stack_idx]--; -- pthread_spin_lock(&wakeup->event_list_lock); -- list_del_node(&sock->event_list); -- pthread_spin_unlock(&wakeup->event_list_lock); -- break; -- default: -- GAZELLE_RETURN(EINVAL); -- } -- sock = sock->listen_next; -- } while (sock != NULL); -- -- update_epoll_max_stack(wakeup); -- return 0; --} -- --int32_t epoll_lwip_event_nolock(struct wakeup_poll *wakeup, struct epoll_event *events, uint32_t maxevents) --{ -- int32_t event_num = 0; -- struct list_node *node, *temp; -- -- list_for_each_node(node, temp, &wakeup->event_list) { -- struct lwip_sock *sock = list_entry(node, struct lwip_sock, event_list); -- -- if ((sock->epoll_events & sock->events) == 0) { -- list_del_node(node); -- continue; -- } -- -- if (event_num >= maxevents) { -- /* move list head after the current node, and start traversing from this node next time */ -- list_del_node(&wakeup->event_list); -- list_add_node(&wakeup->event_list, node); -- break; -- } -- -- events[event_num].events = sock->events & sock->epoll_events; -- events[event_num].data = sock->ep_data; -- event_num++; -- -- if (sock->epoll_events & EPOLLET) { -- list_del_node(node); -- sock->events = 0; -- } -- -- /* EPOLLONESHOT: generate event after epoll_ctl add/mod event again -- epoll_event set 0 avoid generating event util epoll_ctl reset epoll_event */ -- if (sock->epoll_events & EPOLLONESHOT) { -- list_del_node(node); -- sock->epoll_events = 0; -- } -- } -- -- return event_num; --} -- --static int32_t epoll_lwip_event(struct wakeup_poll *wakeup, struct epoll_event *events, uint32_t maxevents) --{ -- int32_t event_num; -- -- pthread_spin_lock(&wakeup->event_list_lock); -- event_num = epoll_lwip_event_nolock(wakeup, events, maxevents); -- pthread_spin_unlock(&wakeup->event_list_lock); -- -- return event_num; --} -- --static int32_t poll_lwip_event(struct pollfd *fds, nfds_t nfds) --{ -- int32_t event_num = 0; -- -- for (uint32_t i = 0; i < nfds; i++) { -- /* sock->listen_next pointerto next stack listen */ -- int32_t fd = fds[i].fd; -- struct lwip_sock *sock = lwip_get_socket(fd); -- while (!POSIX_IS_CLOSED(sock)) { -- uint32_t events = update_events(sock); -- if (events) { -- fds[i].revents = events; -- event_num++; -- break; -- } -- -- sock = sock->listen_next; -- } -- } -- -- return event_num; --} -- --static void change_epollfd_kernel_thread(struct wakeup_poll *wakeup, struct protocol_stack *old_stack, -- struct protocol_stack *new_stack) --{ -- if (old_stack) { -- if (posix_api->epoll_ctl_fn(old_stack->epollfd, EPOLL_CTL_DEL, wakeup->epollfd, NULL) != 0) { -- LSTACK_LOG(ERR, LSTACK, "epoll_ctl_fn errno=%d\n", errno); -- } -- } -- -- /* avoid kernel thread post too much, use EPOLLET */ -- struct epoll_event event; -- event.data.ptr = wakeup; -- event.events = EPOLLIN | EPOLLOUT | EPOLLERR | EPOLLHUP | EPOLLET; -- if (posix_api->epoll_ctl_fn(new_stack->epollfd, EPOLL_CTL_ADD, wakeup->epollfd, &event) != 0) { -- LSTACK_LOG(ERR, LSTACK, "epoll_ctl_fn errno=%d\n", errno); -- } --} -- --static void epoll_bind_statck(struct wakeup_poll *wakeup) --{ -- if (wakeup->bind_stack != wakeup->max_stack && wakeup->max_stack) { -- bind_to_stack_numa(wakeup->max_stack); -- change_epollfd_kernel_thread(wakeup, wakeup->bind_stack, wakeup->max_stack); -- wakeup->bind_stack = wakeup->max_stack; -- } --} -- --static void ms_to_timespec(struct timespec *timespec, int32_t timeout) --{ -- clock_gettime(CLOCK_REALTIME, timespec); -- timespec->tv_sec += timeout / SEC_TO_MSEC; -- timespec->tv_nsec += (timeout % SEC_TO_MSEC) * MSEC_TO_NSEC; -- timespec->tv_sec += timespec->tv_nsec / SEC_TO_NSEC; -- timespec->tv_nsec = timespec->tv_nsec % SEC_TO_NSEC; --} -- --/** -- * Block lstack thread -- * -- * @param wakeup -- * The pointer to the wakeup_poll. -- * @param timeout -- * The time to wait, if 'timeout <= 0' will block until unlock -- * -- * @return -- * - return '0' on unlock -- * - return 'ETIMEDOUT' on timeout -- */ --int32_t lstack_block_wait(struct wakeup_poll *wakeup, int32_t timeout) --{ -- int ret = 0; -- if (wakeup == NULL) { -- return ret; -- } -- -- __atomic_store_n(&wakeup->in_wait, true, __ATOMIC_RELEASE); -- if (timeout > 0) { -- struct timespec timespec; -- ms_to_timespec(×pec, timeout); -- ret = sem_timedwait(&wakeup->wait, ×pec); -- } else { -- ret = sem_wait(&wakeup->wait); -- } -- -- if (__atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { -- __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -- } -- -- return ret; --} -- --int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) --{ -- struct lwip_sock *sock = lwip_get_socket(epfd); -- -- if (sock == NULL || sock->wakeup == NULL) { -- return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); -- } -- -- struct wakeup_poll *wakeup = sock->wakeup; -- int32_t lwip_num = 0; -- /* 16: avoid app process events for a long time */ -- int32_t tmpmaxevents = 16; -- /* avoid the starvation of epoll events from both netstack */ -- int host_maxevents = tmpmaxevents / 2; -- uint32_t poll_ts = sys_now(); -- bool loop_flag; -- int32_t kernel_num = 0; -- int32_t tmptimeout = timeout; -- -- do { -- stack_polling(0); -- if (__atomic_load_n(&wakeup->have_kernel_event, __ATOMIC_ACQUIRE)) { -- kernel_num = posix_api->epoll_wait_fn(epfd, events, host_maxevents, 0); -- if (!kernel_num) { -- __atomic_store_n(&wakeup->have_kernel_event, false, __ATOMIC_RELEASE); -- } -- } -- if (tmptimeout > 0) { -- if (tmptimeout <= sys_now() - poll_ts) { -- tmptimeout = 0; -- } -- } -- -- loop_flag = false; -- if (!kernel_num && list_head_empty(&wakeup->event_list) && tmptimeout != 0) { -- loop_flag = true; -- } -- } while (loop_flag); -- -- if (kernel_num < 0) { -- LSTACK_LOG(ERR, LSTACK, "lstack_rtc_epoll_wait: kernel event failed\n"); -- return kernel_num; -- } -- -- lwip_num = epoll_lwip_event_nolock(wakeup, &events[kernel_num], tmpmaxevents - kernel_num); -- wakeup->stat.app_events += lwip_num; -- wakeup->stat.kernel_events += kernel_num; -- -- return lwip_num + kernel_num; --} -- --int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) --{ -- struct lwip_sock *sock = lwip_get_socket(epfd); -- if (sock == NULL || sock->wakeup == NULL) { -- return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); -- } -- -- struct wakeup_poll *wakeup = sock->wakeup; -- int32_t kernel_num = 0; -- int32_t lwip_num = 0; -- -- if (get_global_cfg_params()->app_bind_numa) { -- epoll_bind_statck(sock->wakeup); -- } -- -- do { -- __atomic_store_n(&wakeup->in_wait, true, __ATOMIC_RELEASE); -- lwip_num = epoll_lwip_event(wakeup, events, maxevents); -- -- if (__atomic_load_n(&wakeup->have_kernel_event, __ATOMIC_ACQUIRE)) { -- kernel_num = posix_api->epoll_wait_fn(epfd, &events[lwip_num], maxevents - lwip_num, 0); -- if (!kernel_num) { -- __atomic_store_n(&wakeup->have_kernel_event, false, __ATOMIC_RELEASE); -- } -- } -- -- if (lwip_num + kernel_num > 0) { -- break; -- } -- -- if (timeout == 0) { -- break; -- } -- } while (lstack_block_wait(wakeup, timeout) == 0); -- -- __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -- wakeup->stat.app_events += lwip_num; -- wakeup->stat.kernel_events += kernel_num; -- -- return lwip_num + kernel_num; --} -- --static int32_t init_poll_wakeup_data(struct wakeup_poll *wakeup) --{ -- if (sem_init(&wakeup->wait, 0, 0) != 0) { -- GAZELLE_RETURN(EINVAL); -- } -- __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -- -- for (uint32_t i = 0; i < PROTOCOL_STACK_MAX; i++) { -- list_init_node(&wakeup->wakeup_list[i]); -- } -- -- wakeup->epollfd = posix_api->epoll_create_fn(POLL_KERNEL_EVENTS); -- if (wakeup->epollfd < 0) { -- GAZELLE_RETURN(EINVAL); -- } -- -- wakeup->type = WAKEUP_POLL; -- -- wakeup->last_fds = calloc(POLL_KERNEL_EVENTS, sizeof(struct pollfd)); -- if (wakeup->last_fds == NULL) { -- GAZELLE_RETURN(EINVAL); -- } -- wakeup->last_max_nfds = POLL_KERNEL_EVENTS; -- -- wakeup->events = calloc(POLL_KERNEL_EVENTS, sizeof(struct epoll_event)); -- if (wakeup->events == NULL) { -- free(wakeup->last_fds); -- wakeup->last_fds = NULL; -- GAZELLE_RETURN(EINVAL); -- } -- -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- list_init_node(&wakeup->poll_list); -- pthread_spin_lock(&stack_group->poll_list_lock); -- list_add_node(&wakeup->poll_list, &stack_group->poll_list); -- pthread_spin_unlock(&stack_group->poll_list_lock); -- -- int32_t stack_count[PROTOCOL_STACK_MAX] = {0}; -- uint16_t bind_id = find_max_cnt_stack(stack_count, stack_group->stack_num, wakeup->bind_stack); -- change_epollfd_kernel_thread(wakeup, wakeup->bind_stack, stack_group->stacks[bind_id]); -- wakeup->bind_stack = stack_group->stacks[bind_id]; -- if (get_global_cfg_params()->app_bind_numa) { -- bind_to_stack_numa(wakeup->bind_stack); -- } -- -- return 0; --} -- --static int resize_kernel_poll(struct wakeup_poll *wakeup, nfds_t nfds) --{ -- if (wakeup->last_fds) { -- free(wakeup->last_fds); -- } -- wakeup->last_fds = calloc(nfds, sizeof(struct pollfd)); -- if (wakeup->last_fds == NULL) { -- LSTACK_LOG(ERR, LSTACK, "calloc failed errno=%d\n", errno); -- return -1; -- } -- -- if (wakeup->events) { -- free(wakeup->events); -- } -- wakeup->events = calloc(nfds, sizeof(struct epoll_event)); -- if (wakeup->events == NULL) { -- LSTACK_LOG(ERR, LSTACK, "calloc failed errno=%d\n", errno); -- free(wakeup->last_fds); -- wakeup->last_fds = NULL; -- return -1; -- } -- -- wakeup->last_max_nfds = nfds; -- return 0; --} -- --static void poll_bind_statck(struct wakeup_poll *wakeup, int32_t *stack_count) --{ -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- -- uint16_t bind_id = find_max_cnt_stack(stack_count, stack_group->stack_num, wakeup->bind_stack); -- if (wakeup->bind_stack && wakeup->bind_stack->queue_id == bind_id) { -- return; -- } -- -- change_epollfd_kernel_thread(wakeup, wakeup->bind_stack, stack_group->stacks[bind_id]); -- bind_to_stack_numa(stack_group->stacks[bind_id]); -- wakeup->bind_stack = stack_group->stacks[bind_id]; --} -- --static void update_kernel_poll(struct wakeup_poll *wakeup, uint32_t index, struct pollfd *new_fd) --{ -- posix_api->epoll_ctl_fn(wakeup->epollfd, EPOLL_CTL_DEL, wakeup->last_fds[index].fd, NULL); -- -- if (new_fd == NULL) { -- return; -- } -- -- struct epoll_event event; -- event.data.u32 = index; -- event.events = new_fd->events; -- if (posix_api->epoll_ctl_fn(wakeup->epollfd, EPOLL_CTL_ADD, new_fd->fd, &event) != 0) { -- LSTACK_LOG(ERR, LSTACK, "epoll_ctl_fn errno=%d\n", errno); -- } --} -- --static int poll_init(struct wakeup_poll *wakeup, struct pollfd *fds, nfds_t nfds) --{ -- int32_t stack_count[PROTOCOL_STACK_MAX] = {0}; -- int32_t poll_change = 0; -- int ret = 0; -- -- /* poll fds num more, recalloc fds size */ -- if (nfds > wakeup->last_max_nfds) { -- ret = resize_kernel_poll(wakeup, nfds); -- if (ret < 0) { -- return -1; -- } -- poll_change = 1; -- } -- -- if (nfds < wakeup->last_nfds) { -- poll_change = 1; -- } -- -- for (uint32_t i = 0; i < nfds; i++) { -- int32_t fd = fds[i].fd; -- fds[i].revents = 0; -- struct lwip_sock *sock = lwip_get_socket(fd); -- -- if (fd == wakeup->last_fds[i].fd && fds[i].events == wakeup->last_fds[i].events) { -- /* fd close then socket may get same fd. */ -- if (sock == NULL || sock->wakeup != NULL) { -- continue; -- } -- } -- -- if (POSIX_IS_CLOSED(sock) || POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { -- update_kernel_poll(wakeup, i, fds + i); -- } -- -- wakeup->last_fds[i].fd = fd; -- wakeup->last_fds[i].events = fds[i].events; -- poll_change = 1; -- -- while (!POSIX_IS_CLOSED(sock)) { -- sock->epoll_events = fds[i].events | POLLERR; -- sock->wakeup = wakeup; -- stack_count[sock->stack->stack_idx]++; -- sock = sock->listen_next; -- } -- } -- -- if (poll_change == 0) { -- return 0; -- } -- wakeup->last_nfds = nfds; -- -- if (get_global_cfg_params()->app_bind_numa) { -- poll_bind_statck(wakeup, stack_count); -- } -- return 0; --} -- --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); -- return NULL; -- } -- -- if (init_poll_wakeup_data(wakeup) < 0) { -- free(wakeup); -- 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); -- GAZELLE_RETURN(EINVAL); -- } -- -- int32_t kernel_num = 0; -- int32_t lwip_num = 0; -- -- do { -- __atomic_store_n(&wakeup->in_wait, true, __ATOMIC_RELEASE); -- lwip_num = poll_lwip_event(fds, nfds); -- -- if (__atomic_load_n(&wakeup->have_kernel_event, __ATOMIC_ACQUIRE)) { -- kernel_num = posix_api->epoll_wait_fn(wakeup->epollfd, wakeup->events, nfds, 0); -- for (int32_t i = 0; i < kernel_num; i++) { -- uint32_t index = wakeup->events[i].data.u32; -- fds[index].revents = wakeup->events[i].events; -- } -- if (!kernel_num) { -- __atomic_store_n(&wakeup->have_kernel_event, false, __ATOMIC_RELEASE); -- } -- } -- -- if (lwip_num + kernel_num > 0) { -- break; -- } -- -- if (timeout == 0) { -- break; -- } -- } while (lstack_block_wait(wakeup, timeout) == 0); -- -- __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -- wakeup->stat.app_events += lwip_num; -- wakeup->stat.kernel_events += kernel_num; -- -- return lwip_num + kernel_num; --} -- --static void select_set_revent_fdset(struct pollfd *fds, nfds_t nfds, fd_set *eventfds, uint32_t event) --{ -- FD_ZERO(eventfds); -- -- /* Set the fd_set parameter based on the actual revents. */ -- for (int i = 0; i < nfds; i++) { -- if (fds[i].revents & event) { -- FD_SET(fds[i].fd, eventfds); -- } -- } --} -- --static void fds_poll2select(struct pollfd *fds, nfds_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds) --{ -- if (fds == NULL || nfds == 0) { -- return; -- } -- -- if (readfds) { -- select_set_revent_fdset(fds, nfds, readfds, EPOLLIN); -- } -- if (writefds) { -- select_set_revent_fdset(fds, nfds, writefds, EPOLLOUT); -- } -- if (exceptfds) { -- select_set_revent_fdset(fds, nfds, exceptfds, EPOLLERR); -- } --} -- --static inline int timeval_to_ms(struct timeval *timeval, int32_t *timeout) --{ -- if (!timeval) { -- *timeout = -1; -- return 0; -- } -- if (unlikely((timeval->tv_sec < 0 || timeval->tv_usec < 0 || timeval->tv_usec >= 1000000))) { -- return -1; -- } -- *timeout = timeval->tv_sec * 1000 + timeval->tv_usec / 1000; -- return 0; --} -- --static nfds_t fds_select2poll(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct pollfd *fds) --{ -- struct pollfd *pollfds = fds; -- nfds_t nfds = 0; -- -- for (int i = 0; i < maxfd; i++) { -- if (readfds && FD_ISSET(i, readfds)) { -- pollfds[nfds].events = POLLIN; -- } -- if (writefds && FD_ISSET(i, writefds)) { -- pollfds[nfds].events |= POLLOUT; -- } -- if (exceptfds && FD_ISSET(i, exceptfds)) { -- pollfds[nfds].events |= POLLERR; -- } -- if (pollfds[nfds].events > 0) { -- pollfds[nfds].fd = i; -- nfds++; -- } -- } -- return nfds; --} -- --int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeval) --{ -- if (maxfd < 0 || maxfd > FD_SETSIZE) { -- LSTACK_LOG(ERR, LSTACK, "select input param error, fd num=%d\n", maxfd); -- GAZELLE_RETURN(EINVAL); -- } -- -- /* Convert the select parameter to the poll parameter. */ -- struct pollfd fds[FD_SETSIZE] = { 0 }; -- nfds_t nfds = fds_select2poll(maxfd, readfds, writefds, exceptfds, fds); -- int timeout = 0; -- if (timeval_to_ms(timeval, &timeout)) { -- LSTACK_LOG(ERR, LSTACK, "select input param timeout error.\n"); -- GAZELLE_RETURN(EINVAL); -- } -- -- int event_num = lstack_poll(fds, nfds, timeout); -- -- /* After poll, set select fd_set by fds.revents. */ -- fds_poll2select(fds, nfds, readfds, writefds, exceptfds); -- -- return event_num; --} -- --#else /* SOCK_EVENT_V2 */ -- - #include - #include - #include -@@ -1883,4 +850,3 @@ bool sock_event_wait(struct lwip_sock *sock, bool noblocking) - - return false; - } --#endif /* SOCK_EVENT_V2 */ -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -index 60d3b23..4a962e1 100644 ---- a/src/lstack/api/lstack_rtc_api.c -+++ b/src/lstack/api/lstack_rtc_api.c -@@ -13,80 +13,15 @@ - #include - #include - --#include "lstack_epoll.h" - #include "lstack_log.h" --#include "lstack_cfg.h" --#include "lstack_protocol_stack.h" - #include "lstack_rtc_api.h" - --static int rtc_socket(int domain, int type, int protocol) --{ -- int ret; -- -- if (stack_setup_app_thread() < 0) { -- exit(1); -- } -- -- /* need call stack thread init function */ -- ret = lwip_socket(domain, type, protocol); -- return ret; --} -- --static int rtc_close(int s) --{ -- struct lwip_sock *sock = lwip_get_socket(s); -- if (sock != NULL && sock->wakeup != NULL && sock->wakeup->epollfd == s) { -- return lstack_epoll_close(s); -- } -- -- return lwip_close(s); --} -- --static int rtc_epoll_create(int flags) --{ -- if (stack_setup_app_thread() < 0) { -- exit(1); -- } -- -- return lstack_epoll_create(flags); --} -- --static int rtc_epoll_create1(int flags) --{ -- if (stack_setup_app_thread() < 0) { -- exit(1); -- } -- -- return lstack_epoll_create1(flags); --} -- --static int rtc_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) --{ -- return lstack_rtc_epoll_ctl(epfd, op, fd, event); --} -- --static int rtc_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) --{ -- return lstack_rtc_epoll_wait(epfd, events, maxevents, timeout); --} -- --static int rtc_poll(struct pollfd *fds, nfds_t nfds, int timeout) --{ -- LSTACK_LOG(ERR, LSTACK, "rtc_poll: rtc currently does not support poll\n"); -- return -1; --} -- --static int rtc_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) --{ -- LSTACK_LOG(ERR, LSTACK, "rtc_select: rtc currently does not support select\n"); -- return -1; --} - - void rtc_api_init(posix_api_t *api) - { -- api->close_fn = rtc_close; -+ api->close_fn = lwip_close; - api->shutdown_fn = lwip_shutdown; -- api->socket_fn = rtc_socket; -+ api->socket_fn = lwip_socket; - api->accept_fn = lwip_accept; - api->accept4_fn = lwip_accept4; - api->bind_fn = lwip_bind; -@@ -104,16 +39,8 @@ void rtc_api_init(posix_api_t *api) - api->writev_fn = lwip_writev; - api->recv_fn = lwip_recv; - api->send_fn = lwip_send; -- api->recvmsg_fn = (ssize_t (*)(int, const struct msghdr *, int))lwip_recvmsg; // TODO: fix unnecessary 'const' in lwipgz_posix_api.h -+ api->recvmsg_fn = lwip_recvmsg; - api->sendmsg_fn = lwip_sendmsg; - api->recvfrom_fn = lwip_recvfrom; - api->sendto_fn = lwip_sendto; -- -- api->epoll_ctl_fn = rtc_epoll_ctl; -- api->epoll_create1_fn = rtc_epoll_create1; -- api->epoll_create_fn = rtc_epoll_create; -- api->epoll_wait_fn = rtc_epoll_wait; -- -- api->poll_fn = rtc_poll; -- api->select_fn = rtc_select; - } -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -index 35439bc..7b8dec2 100644 ---- a/src/lstack/api/lstack_rtw_api.c -+++ b/src/lstack/api/lstack_rtw_api.c -@@ -19,30 +19,31 @@ - #include "lstack_thread_rpc.h" - #include "lstack_protocol_stack.h" - #include "lstack_lwip.h" --#include "lstack_epoll.h" - #include "lstack_rtw_api.h" -+#include "lstack_epoll.h" -+#include "lstack_wait.h" - - /* when fd is listenfd, listenfd of all protocol stack thread will be closed */ - static int stack_broadcast_close(int fd) - { - int ret = 0; -+ struct protocol_stack *stack; - struct lwip_sock *sock = lwip_get_socket(fd); -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - if (sock == NULL) { - GAZELLE_RETURN(EBADF); - } - - do { -- sock = sock->listen_next; -+ if (POSIX_IS_CLOSED(sock)) { -+ break; -+ } -+ stack = get_protocol_stack_by_id(sock->stack_id); - if (stack == NULL || rpc_call_close(&stack->rpc_queue, fd)) { - ret = -1; - } - -- if (POSIX_IS_CLOSED(sock)) { -- break; -- } -+ sock = sock->listen_next; - fd = sock->conn->callback_arg.socket; -- stack = get_protocol_stack_by_fd(fd); - } while (1); - - return ret; -@@ -51,23 +52,23 @@ static int stack_broadcast_close(int fd) - static int stack_broadcast_shutdown(int fd, int how) - { - int32_t ret = 0; -+ struct protocol_stack *stack; - struct lwip_sock *sock = lwip_get_socket(fd); -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - if (sock == NULL) { - GAZELLE_RETURN(EBADF); - } - - do { -- sock = sock->listen_next; -+ if (POSIX_IS_CLOSED(sock)) { -+ break; -+ } -+ stack = get_protocol_stack_by_id(sock->stack_id); - if (stack == NULL || rpc_call_shutdown(&stack->rpc_queue, fd, how)) { - ret = -1; - } - -- if (POSIX_IS_CLOSED(sock)) { -- break; -- } -+ sock = sock->listen_next; - fd = sock->conn->callback_arg.socket; -- stack = get_protocol_stack_by_fd(fd); - } while (1); - - return ret; -@@ -76,26 +77,29 @@ static int stack_broadcast_shutdown(int fd, int how) - /* choice one stack bind */ - static int stack_single_bind(int fd, const struct sockaddr *name, socklen_t namelen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- if (stack == NULL) { -+ struct protocol_stack *stack; -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL) { - GAZELLE_RETURN(EBADF); - } -+ stack = get_protocol_stack_by_id(sock->stack_id); - return rpc_call_bind(&stack->rpc_queue, fd, name, namelen); - } - - /* bind sync to all protocol stack thread, so that any protocol stack thread can build connect */ - static int stack_broadcast_bind(int fd, const struct sockaddr *name, socklen_t namelen) - { -- struct protocol_stack *cur_stack = get_protocol_stack_by_fd(fd); -+ struct protocol_stack *cur_stack; - struct protocol_stack *stack = NULL; - int ret, clone_fd; - - struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL || cur_stack == NULL) { -+ if (sock == NULL) { - LSTACK_LOG(ERR, LSTACK, "tid %d, %d get sock null or stack null\n", rte_gettid(), fd); - GAZELLE_RETURN(EBADF); - } - -+ cur_stack = get_protocol_stack_by_id(sock->stack_id); - ret = rpc_call_bind(&cur_stack->rpc_queue, fd, name, namelen); - if (ret < 0) { - close(fd); -@@ -116,45 +120,30 @@ static int stack_broadcast_bind(int fd, const struct sockaddr *name, socklen_t n - return 0; - } - --static void inline del_accept_in_event(struct lwip_sock *sock) --{ -- pthread_spin_lock(&sock->wakeup->event_list_lock); -- -- if (!NETCONN_IS_ACCEPTIN(sock)) { -- sock->events &= ~EPOLLIN; -- if (sock->events == 0) { -- list_del_node(&sock->event_list); -- } -- } -- -- pthread_spin_unlock(&sock->wakeup->event_list_lock); --} -- - static struct lwip_sock *get_min_accept_sock(int fd) - { -- struct lwip_sock *sock = lwip_get_socket(fd); -+ struct lwip_sock *sock; - struct lwip_sock *min_sock = NULL; - -- while (sock) { -+ for (sock = lwip_get_socket(fd); sock != NULL; sock = sock->listen_next) { - 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; -+ /* init all sock sk_wait */ -+ if (unlikely(sock->sk_wait == NULL) || sock->sk_wait->type == WAIT_CLOSE) { -+ sock->sk_wait = poll_construct_wait(0); -+ } -+ if (!(sock->sk_wait->type & WAIT_BLOCK)) { -+ sock->sk_wait->type |= WAIT_BLOCK; - } - } -- if (!NETCONN_IS_ACCEPTIN(sock)) { -- sock = sock->listen_next; -+ -+ if (!sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_RCVPLUS, 0)) { - continue; - } - -- if (min_sock == NULL || min_sock->stack->conn_num > sock->stack->conn_num) { -+ if (min_sock == NULL || -+ get_protocol_stack_by_id(min_sock->stack_id)->conn_num > get_protocol_stack_by_id(sock->stack_id)->conn_num) { - min_sock = sock; - } -- -- sock = sock->listen_next; - } - - return min_sock; -@@ -171,24 +160,16 @@ static int stack_broadcast_accept4(int fd, struct sockaddr *addr, socklen_t *add - GAZELLE_RETURN(EBADF); - } - -- if (netconn_is_nonblocking(sock->conn)) { -- min_sock = get_min_accept_sock(fd); -- } else { -- while ((min_sock = get_min_accept_sock(fd)) == NULL) { -- lstack_block_wait(sock->wakeup, 0); -- } -- } -- -- if (min_sock && min_sock->conn) { -- stack = get_protocol_stack_by_fd(min_sock->conn->callback_arg.socket); -- if (stack == NULL) { -- GAZELLE_RETURN(EBADF); -+ min_sock = get_min_accept_sock(fd); -+ if (min_sock == NULL) { -+ if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & SOCK_NONBLOCK))) { -+ min_sock = get_min_accept_sock(fd); - } -- ret = rpc_call_accept(&stack->rpc_queue, min_sock->conn->callback_arg.socket, addr, addrlen, flags); - } - -- if (min_sock && min_sock->wakeup && min_sock->wakeup->type == WAKEUP_EPOLL) { -- del_accept_in_event(min_sock); -+ if (!POSIX_IS_CLOSED(min_sock)) { -+ stack = get_protocol_stack_by_id(min_sock->stack_id); -+ ret = rpc_call_accept(&stack->rpc_queue, min_sock->conn->callback_arg.socket, addr, addrlen, flags); - } - - if (ret < 0) { -@@ -205,10 +186,12 @@ static int stack_broadcast_accept(int fd, struct sockaddr *addr, socklen_t *addr - /* choice one stack listen */ - static int stack_single_listen(int fd, int backlog) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); -- if (stack == NULL) { -+ struct protocol_stack *stack; -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL) { - GAZELLE_RETURN(EBADF); - } -+ stack = get_protocol_stack_by_id(sock->stack_id); - return rpc_call_listen(&stack->rpc_queue, fd, backlog); - } - -@@ -221,18 +204,19 @@ static int stack_broadcast_listen(int fd, int backlog) - struct sockaddr_in6 in6; - } sockaddr_t; - -- struct protocol_stack *cur_stack = get_protocol_stack_by_fd(fd); -+ struct protocol_stack *cur_stack; - struct protocol_stack *stack = NULL; - sockaddr_t addr; - socklen_t addr_len = sizeof(addr); - int ret, clone_fd; - - struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL || cur_stack == NULL) { -+ if (sock == NULL) { - LSTACK_LOG(ERR, LSTACK, "tid %d, %d get sock null or stack null\n", rte_gettid(), fd); - GAZELLE_RETURN(EBADF); - } - -+ cur_stack = get_protocol_stack_by_id(sock->stack_id); - ret = rpc_call_getsockname(&cur_stack->rpc_queue, fd, (struct sockaddr *)&addr, &addr_len); - if (ret != 0) { - return ret; -@@ -311,46 +295,56 @@ static int rtw_listen(int s, int backlog) - - static int rtw_connect(int s, const struct sockaddr *name, socklen_t namelen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(s); -- if (stack == NULL) { -+ struct protocol_stack *stack; -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (sock == NULL) { - GAZELLE_RETURN(EBADF); - } -+ stack = get_protocol_stack_by_id(sock->stack_id); - return rpc_call_connect(&stack->rpc_queue, s, name, namelen); - } - - static int rtw_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(s); -- if (stack == NULL) { -+ struct protocol_stack *stack; -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (sock == NULL) { - GAZELLE_RETURN(EBADF); - } -+ stack = get_protocol_stack_by_id(sock->stack_id); - return rpc_call_setsockopt(&stack->rpc_queue, s, level, optname, optval, optlen); - } - - static int rtw_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(s); -- if (stack == NULL) { -+ struct protocol_stack *stack; -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (sock == NULL) { - GAZELLE_RETURN(EBADF); - } -+ stack = get_protocol_stack_by_id(sock->stack_id); - return rpc_call_getsockopt(&stack->rpc_queue, s, level, optname, optval, optlen); - } - - static int rtw_getpeername(int s, struct sockaddr *name, socklen_t *namelen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(s); -- if (stack == NULL) { -+ struct protocol_stack *stack; -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (sock == NULL) { - GAZELLE_RETURN(EBADF); - } -+ stack = get_protocol_stack_by_id(sock->stack_id); - return rpc_call_getpeername(&stack->rpc_queue, s, name, namelen); - } - - static int rtw_getsockname(int s, struct sockaddr *name, socklen_t *namelen) - { -- struct protocol_stack *stack = get_protocol_stack_by_fd(s); -- if (stack == NULL) { -+ struct protocol_stack *stack; -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (sock == NULL) { - GAZELLE_RETURN(EBADF); - } -+ stack = get_protocol_stack_by_id(sock->stack_id); - return rpc_call_getsockname(&stack->rpc_queue, s, name, namelen); - } - -@@ -467,55 +461,16 @@ static ssize_t rtw_sendto(int sockfd, const void *buf, size_t len, int flags, - return do_lwip_send_to_stack(sockfd, buf, len, flags, addr, addrlen); - } - --static int rtw_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) --{ -- return lstack_rtw_epoll_wait(epfd, events, maxevents, timeout); --} -- --static int rtw_poll(struct pollfd *fds, nfds_t nfds, int timeout) --{ -- return lstack_poll(fds, nfds, timeout); --} -- --static int rtw_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) --{ -- return lstack_select(nfds, readfds, writefds, exceptfds, timeout); --} -- - static int rtw_close(int s) - { -- struct lwip_sock *sock = lwip_get_socket(s); -- if (sock && sock->wakeup && sock->wakeup->epollfd == s) { -- return lstack_epoll_close(s); -- } - return stack_broadcast_close(s); - } - - static int rtw_shutdown(int fd, int how) - { -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock && sock->wakeup && sock->wakeup->epollfd == fd) { -- GAZELLE_RETURN(ENOTSOCK); -- } -- - return stack_broadcast_shutdown(fd, how); - } - --static int rtw_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) --{ -- return lstack_rtw_epoll_ctl(epfd, op, fd, event); --} -- --static int rtw_epoll_create1(int flags) --{ -- return lstack_epoll_create1(flags); --} -- --static int rtw_epoll_create(int flags) --{ -- return lstack_epoll_create(flags); --} -- - void rtw_api_init(posix_api_t *api) - { - api->close_fn = rtw_close; -@@ -538,16 +493,8 @@ void rtw_api_init(posix_api_t *api) - api->writev_fn = rtw_writev; - api->recv_fn = rtw_recv; - api->send_fn = rtw_send; -- api->recvmsg_fn = (ssize_t (*)(int, const struct msghdr *, int))rtw_recvmsg; // TODO: fix unnecessary 'const' in lwipgz_posix_api.h -+ api->recvmsg_fn = rtw_recvmsg; - api->sendmsg_fn = rtw_sendmsg; - api->recvfrom_fn = rtw_recvfrom; - api->sendto_fn = rtw_sendto; -- -- api->epoll_ctl_fn = rtw_epoll_ctl; -- api->epoll_create1_fn = rtw_epoll_create1; -- api->epoll_create_fn = rtw_epoll_create; -- api->epoll_wait_fn = rtw_epoll_wait; -- -- api->poll_fn = rtw_poll; -- api->select_fn = rtw_select; - } -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 8a88c47..5869d6b 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -27,6 +27,7 @@ - #include "lstack_lwip.h" - #include "lstack_preload.h" - #include "lstack_unistd.h" -+#include "lstack_epoll.h" - #include "lstack_rtc_api.h" - #include "lstack_rtw_api.h" - #include "lstack_dummy_api.h" -@@ -35,8 +36,8 @@ - #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; -+static posix_api_t g_wrap_api_value = {0}; -+static posix_api_t *g_wrap_api = NULL; - - void wrap_api_init(void) - { -@@ -50,6 +51,8 @@ void wrap_api_init(void) - } else { - rtw_api_init(g_wrap_api); - } -+ -+ epoll_api_init(g_wrap_api); - } - - void wrap_api_exit(void) -@@ -57,50 +60,6 @@ void wrap_api_exit(void) - dummy_api_init(g_wrap_api); - } - --static inline int32_t do_epoll_create1(int32_t flags) --{ -- if (select_posix_path() == POSIX_KERNEL) { -- return posix_api->epoll_create1_fn(flags); -- } -- -- return g_wrap_api->epoll_create1_fn(flags); --} -- --static inline int32_t do_epoll_create(int32_t size) --{ -- if (select_posix_path() == POSIX_KERNEL) { -- return posix_api->epoll_create_fn(size); -- } -- -- return g_wrap_api->epoll_create_fn(size); --} -- --static inline int32_t do_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event* event) --{ -- if (select_posix_path() == POSIX_KERNEL) { -- return posix_api->epoll_ctl_fn(epfd, op, fd, event); -- } -- -- return g_wrap_api->epoll_ctl_fn(epfd, op, fd, event); --} -- --static inline int32_t do_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout) --{ -- if (select_posix_path() == POSIX_KERNEL) { -- return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); -- } -- -- if (epfd < 0) { -- GAZELLE_RETURN(EBADF); -- } -- -- if ((events == NULL) || (timeout < -1) || (maxevents <= 0)) { -- GAZELLE_RETURN(EINVAL); -- } -- -- return g_wrap_api->epoll_wait_fn(epfd, events, maxevents, timeout); --} -- - static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) - { - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_KERNEL) { -@@ -515,9 +474,14 @@ static bool unsupport_optname(int32_t level, int32_t optname) - static inline int32_t do_getsockopt(int32_t s, int32_t level, int32_t optname, void *optval, socklen_t *optlen) - { - #define SO_NUMA_ID 0x100c -- if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP && !unsupport_optname(level, optname)) { -+ const struct protocol_stack *stack; -+ struct lwip_sock *sock; -+ -+ sock = lwip_get_socket(s); -+ if (select_sock_posix_path(sock) == POSIX_LWIP && !unsupport_optname(level, optname)) { - if (level == IPPROTO_IP && optname == SO_NUMA_ID) { -- return lwip_get_socket(s)->stack->numa_id; -+ stack = get_protocol_stack_by_id(sock->stack_id); -+ return stack->numa_id; - } - return g_wrap_api->getsockopt_fn(s, level, optname, optval, optlen); - } -@@ -551,6 +515,12 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - return posix_api->socket_fn(domain, type, protocol); - } - -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ if (stack_setup_app_thread() != 0) { -+ LSTACK_EXIT(1, "stack_setup_app_thread failed\n"); -+ } -+ } -+ - ret = g_wrap_api->socket_fn(domain, type, protocol); - if (ret >= 0) { - struct lwip_sock *sock = lwip_get_socket(ret); -@@ -677,14 +647,20 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int - - static inline int32_t do_close(int fd) - { -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ - /* Can not use select_sock_posix_path() ! - * When fd created by lwip_stocket() set as POSIX_KERNEL, - * lwip_close() is still required. - */ - if (select_posix_path() == POSIX_KERNEL || -- POSIX_IS_CLOSED(lwip_get_socket(fd))) { -+ POSIX_IS_CLOSED(sock)) { - return posix_api->close_fn(fd); - } -+ -+ if (select_sock_posix_path(sock) == POSIX_EPOLL) { -+ return lstack_epoll_close(fd); -+ } - return g_wrap_api->close_fn(fd); - } - -@@ -701,9 +677,56 @@ static int32_t do_shutdown(int fd, int how) - return g_wrap_api->shutdown_fn(fd, how); - } - -+ -+static inline int do_epoll_create1(int flags) -+{ -+ int epfd; -+ -+ if (select_posix_path() == POSIX_KERNEL) { -+ return posix_api->epoll_create1_fn(flags); -+ } -+ -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ if (stack_setup_app_thread() != 0) { -+ LSTACK_EXIT(1, "stack_setup_app_thread failed\n"); -+ } -+ } -+ -+ epfd = g_wrap_api->epoll_create1_fn(flags); -+ if (epfd > 0) { -+ POSIX_SET_TYPE(lwip_get_socket(epfd), POSIX_EPOLL); -+ } -+ return epfd; -+} -+ -+static inline int do_epoll_create(int size) -+{ -+ /* Since Linux 2.6.8, the size argument is ignored, -+ * but must be greater than zero. */ -+ return size <= 0 ? -1 : do_epoll_create1(0); -+} -+ -+static inline int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event* event) -+{ -+ if (select_sock_posix_path(lwip_get_socket(epfd)) == POSIX_KERNEL) { -+ return posix_api->epoll_ctl_fn(epfd, op, fd, event); -+ } -+ -+ return g_wrap_api->epoll_ctl_fn(epfd, op, fd, event); -+} -+ -+static inline int do_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) -+{ -+ if (select_sock_posix_path(lwip_get_socket(epfd)) == POSIX_KERNEL) { -+ return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); -+ } -+ -+ return g_wrap_api->epoll_wait_fn(epfd, events, maxevents, timeout); -+} -+ - static int32_t do_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - { -- if ((select_posix_path() == POSIX_KERNEL) || fds == NULL || nfds == 0) { -+ if ((select_posix_path() == POSIX_KERNEL)) { - return posix_api->poll_fn(fds, nfds, timeout); - } - -@@ -712,18 +735,21 @@ static int32_t do_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout) - - static int32_t do_ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigmask) - { -- int32_t ready; - int32_t timeout; - -- if (fds == NULL || tmo_p == NULL) { -- GAZELLE_RETURN(EINVAL); -- } -- - // s * 1000 and ns / 1000000 -> ms - timeout = (tmo_p == NULL) ? -1 : (tmo_p->tv_sec * 1000 + tmo_p->tv_nsec / 1000000); -- ready = do_poll(fds, nfds, timeout); - -- return ready; -+ return do_poll(fds, nfds, timeout); -+} -+ -+static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) -+{ -+ if (select_posix_path() == POSIX_KERNEL) { -+ return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); -+ } -+ -+ return g_wrap_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); - } - - static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct sigaction *oldact) -@@ -738,19 +764,6 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct - return lstack_sigaction(signum, act, oldact); - } - --static int32_t do_select(int32_t nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) --{ -- /* while input args are invalid, param timeout will steal be executed in kernel */ -- if (nfds <= 0 || !(readfds || writefds || exceptfds)) { -- return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); -- } -- -- if (select_posix_path() == POSIX_KERNEL) { -- return posix_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); -- } -- -- return g_wrap_api->select_fn(nfds, readfds, writefds, exceptfds, timeout); --} - - #define POSIX_VA_PARAM(fd, cmd, type, lwip_fn, kernel_fn) \ - do { \ -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index d0e51b2..047dfdf 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -78,14 +78,12 @@ static void reset_sock_data(struct lwip_sock *sock) - } - - sock->type = 0; -- sock->stack = NULL; -- sock->wakeup = NULL; -+ sock->stack_id = 0; -+ sock->affinity_numa = 0; -+ sock->sk_wait = NULL; - sock->listen_next = NULL; -- sock->epoll_events = 0; -- sock->events = 0; - sock->call_num = 0; - sock->remain_len = 0; -- sock->already_bind_numa = 0; - - if (sock->recv_lastdata && sock->recv_lastdata != (void *)&fin_packet) { - pbuf_free(sock->recv_lastdata); -@@ -176,12 +174,14 @@ int do_lwip_init_sock(int32_t fd) - return -1; - } - -+ sock->stack_id = stack->stack_idx; -+ sock->sk_wait = NULL; -+ if (sock_event_init(&sock->sk_event) != 0) { -+ LSTACK_LOG(ERR, LSTACK, "sock_event_init failed\n"); -+ return -1; -+ } -+ - if (get_global_cfg_params()->stack_mode_rtc) { -- sock->stack = stack; -- sock->epoll_events = 0; -- sock->events = 0; -- sock->wakeup = NULL; -- list_init_node(&sock->event_list); - return 0; - } - -@@ -207,31 +207,25 @@ int do_lwip_init_sock(int32_t fd) - } - (void)replenish_send_idlembuf(stack, sock); - -- sock->stack = stack; -- - list_init_node(&sock->recv_list); -- list_init_node(&sock->event_list); - return 0; - } - - void do_lwip_clean_sock(int fd) - { - struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL || sock->stack == NULL) { -+ if (POSIX_IS_CLOSED(sock)) { - return; - } - -- if (sock->wakeup && sock->wakeup->type == WAKEUP_EPOLL) { -- pthread_spin_lock(&sock->wakeup->event_list_lock); -- list_del_node(&sock->event_list); -- pthread_spin_unlock(&sock->wakeup->event_list_lock); -- } -- -- sock->stack->conn_num--; -+ sock_event_free(&sock->sk_event, sock->sk_wait); -+ sock->sk_wait = NULL; - - reset_sock_data(sock); - - list_del_node(&sock->recv_list); -+ -+ get_protocol_stack_by_id(sock->stack_id)->conn_num--; - } - - void do_lwip_free_pbuf(struct pbuf *pbuf) -@@ -310,7 +304,8 @@ struct pbuf *do_lwip_udp_get_from_sendring(struct lwip_sock *sock, uint16_t rema - } - - for (int i = 0; get_protocol_stack_group()->latency_start && i < actual_count; i++) { -- calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_WRITE_LWIP, 0); -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ calculate_lstack_latency(&stack->latency, pbufs[i], GAZELLE_LATENCY_WRITE_LWIP, 0); - } - - return pbufs[0]; -@@ -334,7 +329,8 @@ struct pbuf *do_lwip_tcp_get_from_sendring(struct lwip_sock *sock, uint16_t rema - } - - if (get_protocol_stack_group()->latency_start) { -- calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LWIP, 0); -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LWIP, 0); - } - - sock->send_pre_del = pbuf; -@@ -354,8 +350,9 @@ struct pbuf *do_lwip_tcp_get_from_sendring(struct lwip_sock *sock, uint16_t rema - - void do_lwip_get_from_sendring_over(struct lwip_sock *sock) - { -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ stack->stats.write_lwip_cnt++; - sock->send_pre_del = NULL; -- sock->stack->stats.write_lwip_cnt++; - } - - static ssize_t do_app_write(struct lwip_sock *sock, struct pbuf *pbufs[], void *buf, size_t len, uint32_t write_num) -@@ -425,8 +422,9 @@ static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t l - } - - for (int i = 0; get_protocol_stack_group()->latency_start && i < write_num; i++) { -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); - if (pbufs[i] != NULL) { -- calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_WRITE_INTO_RING, 0); -+ calculate_lstack_latency(&stack->latency, pbufs[i], GAZELLE_LATENCY_WRITE_INTO_RING, 0); - } - } - -@@ -510,7 +508,6 @@ static ssize_t do_lwip_udp_fill_sendring(struct lwip_sock *sock, const void *buf - ssize_t send_len = 0; - uint32_t write_num = (len + MBUF_MAX_DATA_LEN - 1) / MBUF_MAX_DATA_LEN; - uint32_t write_avail = gazelle_ring_readable_count(sock->send_ring); -- struct wakeup_poll *wakeup = sock->wakeup; - - if (write_num > rte_ring_get_capacity(sock->send_ring)) { - LSTACK_LOG(ERR, LSTACK, "sock send_ring size is not enough\n"); -@@ -537,14 +534,7 @@ static ssize_t do_lwip_udp_fill_sendring(struct lwip_sock *sock, const void *buf - - send_len = app_buff_write(sock, (char *)buf, len, write_num, addr, addrlen); - -- if (wakeup && wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLOUT) -- && !NETCONN_IS_OUTIDLE(sock)) { -- del_sock_event(sock, EPOLLOUT); -- } -- -- if (wakeup) { -- wakeup->stat.app_write_cnt += write_num; -- } -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); - - return send_len; - } -@@ -561,7 +551,8 @@ static ssize_t __do_lwip_tcp_fill_sendring(struct lwip_sock *sock, const void *b - - /* merge data into last pbuf */ - if (sock->remain_len) { -- sock->stack->stats.sock_tx_merge++; -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ stack->stats.sock_tx_merge++; - send_len = merge_data_lastpbuf(sock, (char *)buf, len); - if (send_len >= len) { - send_len = len; -@@ -571,7 +562,6 @@ static ssize_t __do_lwip_tcp_fill_sendring(struct lwip_sock *sock, const void *b - - uint32_t write_num = (len - send_len + MBUF_MAX_DATA_LEN - 1) / MBUF_MAX_DATA_LEN; - uint32_t write_avail = gazelle_ring_readable_count(sock->send_ring); -- struct wakeup_poll *wakeup = sock->wakeup; - - while (!netconn_is_nonblocking(sock->conn) && (write_avail < write_num)) { - if (sock->errevent > 0) { -@@ -597,14 +587,7 @@ static ssize_t __do_lwip_tcp_fill_sendring(struct lwip_sock *sock, const void *b - } - send_len += app_buff_write(sock, (char *)buf + send_len, len - send_len, write_num, addr, addrlen); - -- if (wakeup) { -- wakeup->stat.app_write_cnt += write_num; -- } -- -- if (wakeup && wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLOUT) -- && !NETCONN_IS_OUTIDLE(sock)) { -- del_sock_event(sock, EPOLLOUT); -- } -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); - - END: - if (send_len == 0) { -@@ -644,9 +627,7 @@ bool do_lwip_replenish_sendring(struct protocol_stack *stack, struct lwip_sock * - - replenish_again = replenish_send_idlembuf(stack, sock); - -- if (NETCONN_IS_OUTIDLE(sock)) { -- add_sock_event(sock, EPOLLOUT); -- } -+ API_EVENT(sock->conn, NETCONN_EVT_SENDPLUS, 0); - - return replenish_again; - } -@@ -726,13 +707,14 @@ ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, u8_t apifl - LSTACK_LOG(ERR, LSTACK, "Code shouldn't get here!\n"); - } - -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); - for (uint32_t i = 0; get_protocol_stack_group()->latency_start && i < read_count; i++) { - if (pbufs[i] != NULL) { -- calculate_lstack_latency(&sock->stack->latency, pbufs[i], GAZELLE_LATENCY_READ_LWIP, 0); -+ calculate_lstack_latency(&stack->latency, pbufs[i], GAZELLE_LATENCY_READ_LWIP, 0); - } - } -+ stack->stats.read_lwip_cnt += read_count; - -- sock->stack->stats.read_lwip_cnt += read_count; - return recv_len; - } - -@@ -790,7 +772,8 @@ static inline void notice_stack_tcp_send(struct lwip_sock *sock, int32_t fd, int - { - // 2: call_num >= 2, don't need add new rpc send - if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) < 2) { -- while (rpc_call_tcp_send(&sock->stack->rpc_queue, fd, len, flags) < 0) { -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ while (rpc_call_tcp_send(&stack->rpc_queue, fd, len, flags) < 0) { - usleep(1000); // 1000: wait 1ms to exec again - } - __sync_fetch_and_add(&sock->call_num, 1); -@@ -800,7 +783,8 @@ static inline void notice_stack_tcp_send(struct lwip_sock *sock, int32_t fd, int - static inline void notice_stack_udp_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags) - { - __sync_fetch_and_add(&sock->call_num, 1); -- while (rpc_call_udp_send(&sock->stack->rpc_queue, fd, len, flags) < 0) { -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ while (rpc_call_udp_send(&stack->rpc_queue, fd, len, flags) < 0) { - usleep(1000); // 1000: wait 1ms to exec again - } - } -@@ -828,9 +812,9 @@ ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t f - } - - sock = lwip_get_socket(fd); -- if (unlikely(sock->already_bind_numa == 0 && sock->stack)) { -- thread_bind_stack(sock->stack); -- sock->already_bind_numa = 1; -+ if (unlikely(sock->affinity_numa == 0)) { -+ thread_bind_stack(sock->stack_id); -+ sock->affinity_numa = 1; - } - - #if GAZELLE_SAME_NODE -@@ -838,7 +822,7 @@ ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t f - return gazelle_same_node_ring_send(sock, buf, len, flags); - } - #endif /* GAZELLE_SAME_NODE */ -- if (sock->errevent > 0 || sock->stack == NULL) { -+ if (sock->errevent > 0) { - GAZELLE_RETURN(ENOTCONN); - } - -@@ -920,9 +904,10 @@ static struct pbuf *pbuf_free_partial(struct pbuf *pbuf, uint16_t free_len) - - static bool recv_break_for_err(struct lwip_sock *sock) - { -- bool break_wait = (sock->errevent > 0) && (!NETCONN_IS_DATAIN(sock)); - errno = err_to_errno(netconn_err(sock->conn)); -- return break_wait; -+ unsigned pending = sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_RCVPLUS, 0) | -+ sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0); -+ return pending; - } - - /* -@@ -931,8 +916,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; -+ int32_t expect; - uint64_t time_stamp = sys_now_us(); - - if (sock->recv_lastdata != NULL) { -@@ -941,45 +925,24 @@ static int recv_ring_get_one(struct lwip_sock *sock, bool noblock, struct pbuf * - return 0; - } - -- if (noblock) { -- if (gazelle_ring_read(sock->recv_ring, (void **)pbuf, expect) != expect) { -+ expect = gazelle_ring_read(sock->recv_ring, (void **)pbuf, 1); -+ if (expect == 0) { -+ if (netconn_is_nonblocking(sock->conn)) { - 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; -- } -- ret = lstack_block_wait(sock->recv_block, sock->conn->recv_timeout); -- if (ret != 0) { -- if (errno == ETIMEDOUT) { -- errno = EAGAIN; -+ sock_event_wait(sock, true); -+ expect = gazelle_ring_read(sock->recv_ring, (void **)pbuf, 1); -+ if (expect == 0) { -+ if (recv_break_for_err(sock)) { -+ return -1; - } -- sock->recv_block = NULL; -- return ret; -+ GAZELLE_RETURN(EAGAIN); - } -- } 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); -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ calculate_lstack_latency(&stack->latency, *pbuf, GAZELLE_LATENCY_READ_APP_CALL, time_stamp); - } - - return 0; -@@ -1044,12 +1007,9 @@ static ssize_t recv_ring_tcp_read(struct lwip_sock *sock, void *buf, size_t len, - if (pbuf->tot_len > copy_len) { - sock->recv_lastdata = pbuf_free_partial(pbuf, copy_len); - } else { -- if (sock->wakeup) { -- sock->wakeup->stat.app_read_cnt += 1; -- } -- - if (get_protocol_stack_group()->latency_start) { -- calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK, 0); -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK, 0); - } - - gazelle_ring_read_over(sock->recv_ring); -@@ -1088,15 +1048,12 @@ static ssize_t recv_ring_udp_read(struct lwip_sock *sock, void *buf, size_t len, - lwip_sock_make_addr(sock->conn, &(pbuf->addr), pbuf->port, addr, addrlen); - } - -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); - if (copy_len < pbuf->tot_len) { -- sock->stack->stats.sock_rx_drop++; -- } -- -- if (sock->wakeup) { -- sock->wakeup->stat.app_read_cnt++; -+ stack->stats.sock_rx_drop++; - } - if (get_protocol_stack_group()->latency_start) { -- calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK, 0); -+ calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK, 0); - } - - return copy_len; -@@ -1113,9 +1070,9 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - return -1; - } - -- if (unlikely(sock->already_bind_numa == 0 && sock->stack)) { -- thread_bind_stack(sock->stack); -- sock->already_bind_numa = 1; -+ if (unlikely(sock->affinity_numa == 0)) { -+ thread_bind_stack(sock->stack_id); -+ sock->affinity_numa = 1; - } - - #if GAZELLE_SAME_NODE -@@ -1129,16 +1086,9 @@ ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags - recvd = recv_ring_tcp_read(sock, buf, len, noblock); - } - -- /* rte_ring_count reduce lock */ -- if (sock->wakeup && sock->wakeup->type == WAKEUP_EPOLL && (sock->events & EPOLLIN) -- && (!NETCONN_IS_DATAIN(sock))) { -- del_sock_event(sock, EPOLLIN); -- } -+ API_EVENT(sock->conn, NETCONN_EVT_RCVMINUS, recvd); - - if (recvd < 0) { -- if (sock->wakeup) { -- sock->wakeup->stat.read_null++; -- } - return -1; - } - return recvd; -@@ -1148,8 +1098,9 @@ void do_lwip_add_recvlist(int32_t fd) - { - struct lwip_sock *sock = lwip_get_socket(fd); - -- if (sock && sock->stack && list_node_null(&sock->recv_list)) { -- list_add_node(&sock->recv_list, &sock->stack->recv_list); -+ if (sock && list_node_null(&sock->recv_list)) { -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ list_add_node(&sock->recv_list, &stack->recv_list); - } - } - -@@ -1176,7 +1127,8 @@ void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num) - } - - if (get_protocol_stack_group()->latency_start) { -- calculate_sock_latency(&sock->stack->latency, sock, GAZELLE_LATENCY_RECVMBOX_READY); -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_RECVMBOX_READY); - } - - ssize_t len = 0; -@@ -1186,36 +1138,33 @@ void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num) - len = lwip_recv(sock->conn->callback_arg.socket, NULL, 0, 0); - } - if (len < 0 && errno != EAGAIN) { -- sock->errevent = 1; -- add_sock_event(sock, EPOLLERR); -+ API_EVENT(sock->conn, NETCONN_EVT_ERROR, 0); - /* = 0: fin */ - } else if (len >= 0) { -- add_sock_event(sock, EPOLLIN); -+ API_EVENT(sock->conn, NETCONN_EVT_RCVPLUS, 0); - } - } - } - --void do_lwip_connected_callback(struct netconn *conn) -+void do_lwip_connected_callback(int fd) - { -- if (conn == NULL) { -- return; -- } -- -- int32_t fd = conn->callback_arg.socket; - struct lwip_sock *sock = lwip_get_socket(fd); - if (POSIX_IS_CLOSED(sock)) { - return; - } - -- if (sock->wakeup != NULL && sock->wakeup->epollfd > 0) { -- posix_api->epoll_ctl_fn(sock->wakeup->epollfd, EPOLL_CTL_DEL, fd, NULL); -+ if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { -+ /* delete kernel event */ -+ if (sock->sk_wait != NULL) { -+ posix_api->epoll_ctl_fn(sock->sk_wait->epfd, EPOLL_CTL_DEL, fd, NULL); -+ } -+ /* shutdown kernel connect, do_connect() has tried both kernel and lwip. */ -+ 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); -+ API_EVENT(sock->conn, NETCONN_EVT_RCVPLUS, 0); - } - - static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const struct tcp_pcb *pcb) -@@ -1249,9 +1198,9 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - conn->recv_ring_cnt = (sock->recv_ring == NULL) ? 0 : gazelle_ring_readable_count(sock->recv_ring); - conn->recv_ring_cnt += (sock->recv_lastdata) ? 1 : 0; - conn->send_ring_cnt = (sock->send_ring == NULL) ? 0 : gazelle_ring_readover_count(sock->send_ring); -- conn->events = sock->events; -- conn->epoll_events = sock->epoll_events; -- conn->eventlist = !list_node_null(&sock->event_list); -+ conn->events = sock->sk_event.pending; -+ conn->epoll_events = sock->sk_event.events; -+ conn->eventlist = !list_node_null(&sock->sk_event.event_node); - } - } - } -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 3bb1eeb..1e7df33 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -29,7 +29,7 @@ - #include "lstack_ethdev.h" - #include "lstack_lwip.h" - #include "lstack_control_plane.h" --#include "lstack_epoll.h" -+#include "lstack_wait.h" - #include "lstack_stack_stat.h" - #include "lstack_virtio.h" - #include "lstack_interrupt.h" -@@ -39,9 +39,7 @@ - #include - #endif - --#define KERNEL_EVENT_10us 10 -- --static PER_THREAD struct protocol_stack *g_stack_p = NULL; -+PER_THREAD struct protocol_stack *g_stack_p = NULL; - static struct protocol_stack_group g_stack_group = {0}; - - typedef void *(*stack_thread_func)(void *arg); -@@ -81,19 +79,15 @@ struct protocol_stack_group *get_protocol_stack_group(void) - return &g_stack_group; - } - --struct protocol_stack *get_protocol_stack(void) -+struct protocol_stack *get_protocol_stack_by_id(int stack_id) - { -- return g_stack_p; --} -+ struct protocol_stack_group *stack_group; - --struct protocol_stack *get_protocol_stack_by_fd(int fd) --{ -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (POSIX_IS_CLOSED(sock)) { -+ if (stack_id < 0) { - return NULL; - } -- -- return sock->stack; -+ stack_group = get_protocol_stack_group(); -+ return stack_group->stacks[stack_id]; - } - - struct protocol_stack *get_bind_protocol_stack(void) -@@ -153,10 +147,11 @@ int get_min_conn_stack(struct protocol_stack_group *stack_group) - } - #endif /* GAZELLE_TCP_REUSE_IPPORT */ - --void bind_to_stack_numa(struct protocol_stack *stack) -+void bind_to_stack_numa(int stack_id) - { -- int32_t ret; -+ int ret; - pthread_t tid = pthread_self(); -+ struct protocol_stack *stack = get_protocol_stack_by_id(stack_id); - - if (get_global_cfg_params()->stack_num > 0) { - numa_run_on_node(stack->numa_id); -@@ -170,7 +165,7 @@ void bind_to_stack_numa(struct protocol_stack *stack) - } - } - --void thread_bind_stack(struct protocol_stack *stack) -+void thread_bind_stack(int stack_id) - { - static PER_THREAD uint16_t stack_sock_num[GAZELLE_MAX_STACK_NUM] = {0}; - static PER_THREAD uint16_t max_sock_stack = 0; -@@ -179,10 +174,10 @@ void thread_bind_stack(struct protocol_stack *stack) - return; - } - -- stack_sock_num[stack->stack_idx]++; -- if (stack_sock_num[stack->stack_idx] > max_sock_stack) { -- max_sock_stack = stack_sock_num[stack->stack_idx]; -- bind_to_stack_numa(stack); -+ stack_sock_num[stack_id]++; -+ if (stack_sock_num[stack_id] > max_sock_stack) { -+ max_sock_stack = stack_sock_num[stack_id]; -+ bind_to_stack_numa(stack_id); - } - } - -@@ -308,11 +303,6 @@ void low_power_idling(struct protocol_stack *stack) - } - } - --struct thread_params { -- uint16_t queue_id; -- uint16_t idx; --}; -- - static int32_t create_thread(void *arg, char *thread_name, stack_thread_func func) - { - /* thread may run slow, if arg is temp var maybe have relese */ -@@ -347,48 +337,6 @@ static int32_t create_thread(void *arg, char *thread_name, stack_thread_func fun - return 0; - } - --static void wakeup_kernel_event(struct protocol_stack *stack) --{ -- if (stack->kernel_event_num <= 0) { -- return; -- } -- -- for (int32_t i = 0; i < stack->kernel_event_num; i++) { -- struct wakeup_poll *wakeup = stack->kernel_events[i].data.ptr; -- if (wakeup->type == WAKEUP_CLOSE) { -- continue; -- } -- -- __atomic_store_n(&wakeup->have_kernel_event, true, __ATOMIC_RELEASE); -- lstack_block_wakeup(wakeup); -- } -- -- return; --} -- --static void* gazelle_kernelevent_thread(void *arg) --{ -- struct thread_params *t_params = (struct thread_params*) arg; -- uint16_t idx = t_params->idx; -- struct protocol_stack *stack = get_protocol_stack_group()->stacks[idx]; -- -- bind_to_stack_numa(stack); -- -- LSTACK_LOG(INFO, LSTACK, "kernelevent_%02hu start\n", idx); -- free(arg); -- sem_post(&g_stack_group.sem_stack_setup); -- -- for (;;) { -- stack->kernel_event_num = posix_api->epoll_wait_fn(stack->epollfd, stack->kernel_events, KERNEL_EPOLL_MAX, -1); -- if (stack->kernel_event_num > 0) { -- wakeup_kernel_event(stack); -- usleep(KERNEL_EVENT_10us); -- } -- } -- -- return NULL; --} -- - static int32_t init_stack_value(struct protocol_stack *stack, void *arg) - { - struct thread_params *t_params = (struct thread_params*) arg; -@@ -403,16 +351,10 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) - - list_init_head(&stack->recv_list); - list_init_head(&stack->same_node_recv_list); -- list_init_head(&stack->wakeup_list); - - stack_group->stacks[t_params->idx] = stack; - set_stack_idx(t_params->idx); - -- stack->epollfd = posix_api->epoll_create_fn(GAZELLE_LSTACK_MAX_CONN); -- if (stack->epollfd < 0) { -- LSTACK_LOG(ERR, LSTACK, "kernel epoll_create failed\n"); -- return -1; -- } - - if (cfg_params->stack_num > 0) { - stack->numa_id = cfg_params->numa_id; -@@ -453,7 +395,7 @@ static int32_t create_affiliate_thread(void *arg) - return -1; - } - memcpy_s(params, sizeof(*params), arg, sizeof(struct thread_params)); -- if (create_thread((void *)params, "gazellekernel", gazelle_kernelevent_thread) != 0) { -+ if (create_thread((void *)params, "gazellekernel", kernel_wait_thread) != 0) { - LSTACK_LOG(ERR, LSTACK, "gazellekernel errno=%d\n", errno); - return -1; - } -@@ -551,7 +493,9 @@ int stack_polling(unsigned wakeup_tick) - do_lwip_read_recvlist(stack, read_connect_number); - - if ((wakeup_tick & 0xf) == 0) { -- wakeup_stack_epoll(stack); -+#if SOCK_WAIT_BATCH_NOTIFY -+ stack->stats.wakeup_events += lwip_wait_foreach_notify(stack->stack_idx); -+#endif /* SOCK_WAIT_BATCH_NOTIFY */ - if (get_global_cfg_params()->send_cache_mode) { - tx_cache_send(stack->queue_id); - } -@@ -595,7 +539,7 @@ static bool stack_local_event_get(uint16_t stack_id) - if (!lockless_queue_empty(&stack->dfx_rpc_queue.queue) || - !lockless_queue_empty(&stack->rpc_queue.queue) || - !list_head_empty(&stack->recv_list) || -- !list_head_empty(&stack->wakeup_list) || -+ !lwip_wait_notify_empty(stack_id) || - tx_cache_count(stack->queue_id)) { - return true; - } -@@ -681,8 +625,6 @@ int stack_group_init(void) - struct protocol_stack_group *stack_group = get_protocol_stack_group(); - stack_group->stack_num = 0; - -- list_init_head(&stack_group->poll_list); -- pthread_spin_init(&stack_group->poll_list_lock, PTHREAD_PROCESS_PRIVATE); - pthread_spin_init(&stack_group->socket_lock, PTHREAD_PROCESS_PRIVATE); - if (sem_init(&stack_group->sem_stack_setup, 0, 0) < 0) { - LSTACK_LOG(ERR, LSTACK, "sem_init failed errno=%d\n", errno); -@@ -783,24 +725,22 @@ OUT2: - return -1; - } - --static void stack_all_fds_close(struct protocol_stack *stack) -+ -+void stack_exit(void) - { -+ struct protocol_stack *stack = get_protocol_stack(); -+ if (stack == NULL) -+ return; -+ -+ /* close all fd */ - for (int i = 3; i < GAZELLE_MAX_CLIENTS + GAZELLE_RESERVED_CLIENTS; i++) { - struct lwip_sock *sock = lwip_get_socket(i); -- if (!POSIX_IS_CLOSED(sock) && sock->stack == stack) { -+ if (!POSIX_IS_CLOSED(sock) && sock->stack_id == stack->stack_idx) { - lwip_close(i); - } - } - } - --void stack_exit(void) --{ -- struct protocol_stack *stack = get_protocol_stack(); -- if (stack != NULL) { -- stack_all_fds_close(stack); -- } --} -- - void stack_wait(void) - { - struct protocol_stack *stack = get_protocol_stack(); -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index b1eb60e..dc9c931 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -65,8 +65,9 @@ void time_stamp_record(int fd, struct pbuf *pbuf) - { - struct lwip_sock *sock = lwip_get_socket(fd); - -- if (get_protocol_stack_group()->latency_start && sock && sock->stack && pbuf) { -- calculate_lstack_latency(&sock->stack->latency, pbuf, GAZELLE_LATENCY_INTO_MBOX, 0); -+ if (get_protocol_stack_group()->latency_start && sock && pbuf) { -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_INTO_MBOX, 0); - time_stamp_into_recvmbox(sock); - } - } -@@ -209,29 +210,6 @@ static void set_latency_start_flag(bool start) - } - } - --static void get_wakeup_stat(struct protocol_stack_group *stack_group, struct protocol_stack *stack, -- struct gazelle_wakeup_stat *stat) --{ -- struct list_node *node, *temp; -- -- pthread_spin_lock(&stack_group->poll_list_lock); -- -- list_for_each_node(node, temp, &stack_group->poll_list) { -- struct wakeup_poll *wakeup = list_entry(node, struct wakeup_poll, poll_list); -- -- if (wakeup->bind_stack == stack) { -- stat->kernel_events += wakeup->stat.kernel_events; -- stat->app_events += wakeup->stat.app_events; -- stat->read_null += wakeup->stat.read_null; -- stat->app_write_cnt += wakeup->stat.app_write_cnt; -- stat->app_write_rpc += wakeup->stat.app_write_rpc; -- stat->app_read_cnt += wakeup->stat.app_read_cnt; -- } -- } -- -- pthread_spin_unlock(&stack_group->poll_list_lock); --} -- - void lstack_get_low_power_info(struct gazelle_stat_low_power_info *low_power_info) - { - struct cfg_params *cfg = get_global_cfg_params(); -@@ -244,8 +222,6 @@ void lstack_get_low_power_info(struct gazelle_stat_low_power_info *low_power_inf - - static void get_stack_stats(struct gazelle_stack_dfx_data *dfx, struct protocol_stack *stack) - { -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- - dfx->loglevel = rte_log_get_level(RTE_LOGTYPE_LSTACK); - - lstack_get_low_power_info(&dfx->low_power_info); -@@ -257,7 +233,7 @@ static void get_stack_stats(struct gazelle_stack_dfx_data *dfx, struct protocol_ - return; - } - -- get_wakeup_stat(stack_group, stack, &dfx->data.pkts.wakeup_stat); -+ sock_wait_group_stat(stack->stack_idx, &dfx->data.pkts.wakeup_stat); - - dfx->data.pkts.call_alloc_fail = rpc_stats_get()->call_alloc_fail; - -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 26ae501..a831d3b 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -242,8 +242,8 @@ static void callback_socket(struct rpc_msg *msg) - static void callback_close(struct rpc_msg *msg) - { - int fd = msg->args[MSG_ARG_0].i; -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - struct lwip_sock *sock = lwip_get_socket(fd); -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); - - if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { - msg->recall_flag = 1; -@@ -261,8 +261,8 @@ static void callback_shutdown(struct rpc_msg *msg) - { - int fd = msg->args[MSG_ARG_0].i; - int how = msg->args[MSG_ARG_1].i; -- struct protocol_stack *stack = get_protocol_stack_by_fd(fd); - struct lwip_sock *sock = lwip_get_socket(fd); -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); - - if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { - msg->recall_flag = 1; -@@ -365,14 +365,14 @@ static void callback_accept(struct rpc_msg *msg) - } - - struct lwip_sock *sock = lwip_get_socket(accept_fd); -- if (sock == NULL || sock->stack == NULL) { -+ if (sock == NULL) { - lwip_close(accept_fd); - LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); - return; - } - - msg->result = accept_fd; -- sock->stack->conn_num++; -+ stack->conn_num++; - if (rte_ring_count(sock->conn->recvmbox->ring)) { - do_lwip_add_recvlist(accept_fd); - } -@@ -751,27 +751,6 @@ int rpc_call_recvlistcnt(rpc_queue *queue) - return rpc_sync_call(queue, msg); - } - --static void callback_clean_epoll(struct rpc_msg *msg) --{ -- struct protocol_stack *stack = get_protocol_stack(); -- struct wakeup_poll *wakeup = (struct wakeup_poll *)msg->args[MSG_ARG_0].p; -- -- list_del_node(&wakeup->wakeup_list[stack->stack_idx]); --} -- --int rpc_call_clean_epoll(rpc_queue *queue, void *wakeup) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_clean_epoll); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].p = wakeup; -- -- rpc_sync_call(queue, msg); -- return 0; --} -- - static void callback_arp(struct rpc_msg *msg) - { - struct rte_mbuf *mbuf = (struct rte_mbuf *)msg->args[MSG_ARG_0].p; -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -index c67df93..6334f5e 100644 ---- a/src/lstack/core/lstack_wait.c -+++ b/src/lstack/core/lstack_wait.c -@@ -26,7 +26,7 @@ - #include "lstack_log.h" - #include "lstack_cfg.h" - #include "same_node.h" --#include "mbox_ring.h" -+#include "lstack_lwip.h" - - #define KERNEL_EVENT_WAIT_US 10 - #define LWIP_EVENT_WAIT_US 10 -@@ -340,34 +340,26 @@ void sock_wait_kernel_free(struct sock_wait *sk_wait) - static inline bool NETCONN_NEED_ACCEPT(const struct lwip_sock *sock) - { - if (sys_mbox_valid(&sock->conn->acceptmbox)) { -- const struct mbox_ring *mr = &sock->conn->acceptmbox->mring; -- return mr->ops->count(mr) > 0; -+ return !sys_mbox_empty(sock->conn->acceptmbox); - } - return false; - } - - static inline bool NETCONN_NEED_RECV(const struct lwip_sock *sock) - { -- if (sock->lastdata.pbuf != NULL) -+ if (sock->recv_lastdata != NULL) -+ return true; -+ if (gazelle_ring_readable_count(sock->recv_ring) > 0) -+ return true; -+ if (NETCONN_NEED_SAME_NODE(sock)) - return true; -- if (sys_mbox_valid(&sock->conn->recvmbox)) { -- const struct mbox_ring *mr = &sock->conn->recvmbox->mring; -- return mr->ops->recv_count(mr) > 0; -- } - return false; - } - - static inline bool NETCONN_ALLOW_SEND(const struct lwip_sock *sock) - { -- if (get_global_cfg_params()->stack_mode_rtc) { -- if (NETCONN_TYPE(sock->conn) == NETCONN_TCP) -- return lwip_tcp_allow_send(sock->conn->pcb.tcp); -- return false; -- } -- if (sys_mbox_valid(&sock->conn->sendmbox)) { -- const struct mbox_ring *mr = &sock->conn->sendmbox->mring; -- return mr->ops->free_count(mr) > 0; -- } -+ if (gazelle_ring_readable_count(sock->send_ring) > 0) -+ return true; - return false; - } - -diff --git a/src/lstack/core/same_node.c b/src/lstack/core/same_node.c -index 0fe0fa8..660fefd 100644 ---- a/src/lstack/core/same_node.c -+++ b/src/lstack/core/same_node.c -@@ -34,7 +34,7 @@ void read_same_node_recv_list(struct protocol_stack *stack) - sock = list_entry(node, struct lwip_sock, recv_list); - - if (sock->same_node_rx_ring != NULL && same_node_ring_count(sock)) { -- add_sock_event(sock, EPOLLIN); -+ API_EVENT(sock->conn, NETCONN_EVT_RCVPLUS, 0); - } - } - } -@@ -231,7 +231,8 @@ err_t find_same_node_memzone(struct tcp_pcb *pcb, struct lwip_sock *nsock) - - /* rcvlink init in alloc_socket() */ - /* remove from g_rcv_process_list in free_socket */ -- list_add_node(&nsock->recv_list, &nsock->stack->same_node_recv_list); -+ struct protocol_stack *stack = get_protocol_stack_by_id(nsock->stack_id); -+ list_add_node(&nsock->recv_list, &stack->same_node_recv_list); - return 0; - } - -diff --git a/src/lstack/include/lstack_epoll.h b/src/lstack/include/lstack_epoll.h -index 9a5d15a..655e178 100644 ---- a/src/lstack/include/lstack_epoll.h -+++ b/src/lstack/include/lstack_epoll.h -@@ -13,85 +13,6 @@ - #ifndef _GAZELLE_EPOLL_H_ - #define _GAZELLE_EPOLL_H_ - --#if /* SOCK_EVENT_V2 */ -- --#include --#include --#include --#include -- --#include --#include -- --#include "common/gazelle_dfx_msg.h" --#include "common/gazelle_opt.h" -- --enum wakeup_type { -- WAKEUP_EPOLL = 0, -- WAKEUP_POLL, -- WAKEUP_CLOSE, -- WAKEUP_BLOCK, --}; -- --struct protocol_stack; --struct wakeup_poll { -- /* stack thread read frequently */ -- enum wakeup_type type; -- sem_t wait; -- bool in_wait; -- struct list_node wakeup_list[PROTOCOL_STACK_MAX]; -- bool have_kernel_event; -- char pad __rte_cache_aligned; -- -- struct gazelle_wakeup_stat stat; -- struct protocol_stack *bind_stack; -- struct list_node poll_list; -- -- /* poll */ -- struct pollfd *last_fds; -- nfds_t last_nfds; -- nfds_t last_max_nfds; -- struct epoll_event *events; -- -- /* epoll */ -- int32_t epollfd; /* epoll kernel fd */ -- int32_t stack_fd_cnt[PROTOCOL_STACK_MAX]; -- struct protocol_stack *max_stack; -- struct list_node event_list; -- pthread_spinlock_t event_list_lock; --}; -- --void add_sock_event(struct lwip_sock *sock, uint32_t event); --void add_sock_event_nolock(struct lwip_sock *sock, uint32_t event); --void del_sock_event(struct lwip_sock *sock, uint32_t event); --void del_sock_event_nolock(struct lwip_sock *sock, uint32_t event); -- --void wakeup_stack_epoll(struct protocol_stack *stack); -- --int32_t lstack_epoll_create(int32_t size); --int32_t lstack_epoll_create1(int32_t flags); --int32_t lstack_rtw_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event *event); --int32_t lstack_rtc_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_event *event); --int32_t lstack_rtw_epoll_wait(int32_t epfd, struct epoll_event *events, int32_t maxevents, int32_t timeout); --int32_t lstack_rtc_epoll_wait(int32_t epfd, struct epoll_event* events, int32_t maxevents, int32_t timeout); --int32_t lstack_poll(struct pollfd *fds, nfds_t nfds, int32_t timeout); --int lstack_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeval); -- --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)) { -- __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -- rte_mb(); -- sem_post(&wakeup->wait); -- } --} -- --#else /* SOCK_EVENT_V2 */ -- - #include - #include - -@@ -104,6 +25,4 @@ int lstack_epoll_close(int epfd); - void epoll_api_init(posix_api_t *api); - bool sock_event_wait(struct lwip_sock *sock, bool noblocking); - --#endif /* SOCK_EVENT_V2 */ -- - #endif /* _GAZELLE_EPOLL_H_ */ -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index f2524e4..4cc9db1 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -22,11 +22,7 @@ struct lwip_sock; - struct rpc_msg; - struct protocol_stack; - -- --#define NETCONN_IS_ACCEPTIN(sock) (((sock)->conn->acceptmbox != NULL) && !sys_mbox_empty((sock)->conn->acceptmbox)) --#define NETCONN_IS_DATAIN(sock) ((gazelle_ring_readable_count((sock)->recv_ring) || (sock)->recv_lastdata) || NETCONN_NEED_SAME_NODE(sock)) - #define NETCONN_IS_DATAOUT(sock) (gazelle_ring_readover_count((sock)->send_ring) || (sock)->send_pre_del) --#define NETCONN_IS_OUTIDLE(sock) gazelle_ring_readable_count((sock)->send_ring) - #define NETCONN_IS_UDP(sock) (NETCONNTYPE_GROUP(netconn_type((sock)->conn)) == NETCONN_UDP) - - /* lwip api */ -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 3f6e3d3e..b77d5da 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -14,7 +14,6 @@ - #define __GAZELLE_PROTOCOL_STACK_H__ - - #include --#include - #include - - #include -@@ -43,41 +42,35 @@ struct protocol_stack { - uint16_t numa_id; - uint16_t cpu_id; - uint32_t stack_idx; -+ -+ struct netif netif; -+ struct lstack_dev_ops dev_ops; -+ - cpu_set_t idle_cpuset; /* idle cpu in numa of stack, app thread bind to it */ -- int32_t epollfd; /* kernel event thread epoll fd */ -+ - volatile enum rte_lcore_state_t state; -+ volatile bool low_power; -+ volatile uint16_t conn_num; - - struct rte_mempool *rxtx_mbuf_pool; -- struct rte_ring *rx_ring; -+ struct rte_ring *rx_ring; - struct rte_ring *tx_ring; - struct rte_ring *reg_ring; -- struct rte_ring *wakeup_ring; - struct reg_ring_msg *reg_buf; - uint32_t reg_head; - -- volatile bool low_power; -+ uint32_t rx_ring_used; -+ uint32_t tx_ring_used; -+ struct rte_mbuf *pkts[NIC_QUEUE_SIZE_MAX]; - - char pad1 __rte_cache_aligned; - rpc_queue dfx_rpc_queue; - rpc_queue rpc_queue; - char pad2 __rte_cache_aligned; - -- /* kernel event thread read/write frequently */ -- struct epoll_event kernel_events[KERNEL_EPOLL_MAX]; -- int32_t kernel_event_num; -- char pad3 __rte_cache_aligned; -- -- struct netif netif; -- struct lstack_dev_ops dev_ops; -- uint32_t rx_ring_used; -- uint32_t tx_ring_used; -- -- struct rte_mbuf *pkts[NIC_QUEUE_SIZE_MAX]; - struct list_node recv_list; - struct list_node same_node_recv_list; /* used for same node processes communication */ -- struct list_node wakeup_list; - -- volatile uint16_t conn_num; - struct stats_ *lwip_stats; - struct gazelle_stack_latency latency; - struct gazelle_stack_stat stats; -@@ -93,8 +86,7 @@ struct protocol_stack_group { - struct rte_mempool *kni_pktmbuf_pool; - struct eth_params *eth_params; - struct protocol_stack *stacks[PROTOCOL_STACK_MAX]; -- struct list_node poll_list; -- pthread_spinlock_t poll_list_lock; -+ - sem_t sem_listen_thread; - struct rte_mempool *total_rxtx_pktmbuf_pool[PROTOCOL_STACK_MAX]; - sem_t sem_stack_setup; -@@ -106,16 +98,26 @@ struct protocol_stack_group { - pthread_spinlock_t socket_lock; - }; - --struct protocol_stack *get_protocol_stack(void); --struct protocol_stack *get_protocol_stack_by_fd(int fd); --struct protocol_stack *get_bind_protocol_stack(void); -+struct thread_params { -+ uint16_t queue_id; -+ uint16_t idx; -+}; -+ - struct protocol_stack_group *get_protocol_stack_group(void); - -+extern PER_THREAD struct protocol_stack *g_stack_p; -+static inline struct protocol_stack *get_protocol_stack(void) -+{ -+ return g_stack_p; -+} -+struct protocol_stack *get_protocol_stack_by_id(int stack_id); -+struct protocol_stack *get_bind_protocol_stack(void); -+ - #if GAZELLE_TCP_REUSE_IPPORT - int get_min_conn_stack(struct protocol_stack_group *stack_group); - #endif /* GAZELLE_TCP_REUSE_IPPORT */ --void bind_to_stack_numa(struct protocol_stack *stack); --void thread_bind_stack(struct protocol_stack *stack); -+void bind_to_stack_numa(int stack_id); -+void thread_bind_stack(int stack_id); - - int stack_group_init(void); - void stack_group_exit(void); -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index c74981f..427a519 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -101,7 +101,6 @@ int rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags); - int rpc_call_replenish(rpc_queue *queue, void *sock); - int rpc_call_recvlistcnt(rpc_queue *queue); - --int rpc_call_clean_epoll(rpc_queue *queue, void *wakeup); - int rpc_call_arp(rpc_queue *queue, void *mbuf); - - int rpc_call_conntable(rpc_queue *queue, void *conn_table, unsigned max_conn); --- -2.33.0 - diff --git a/0328-socket-refactor-tcp-and-udp.patch b/0328-socket-refactor-tcp-and-udp.patch deleted file mode 100644 index 58114af8341b6058988e627f6086056266e4b81b..0000000000000000000000000000000000000000 --- a/0328-socket-refactor-tcp-and-udp.patch +++ /dev/null @@ -1,4524 +0,0 @@ -From 52c4cd904e90bc506ae1323465d99007e0e1a4ba Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 21 Mar 2025 17:02:04 +0800 -Subject: [PATCH] socket: refactor tcp and udp - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockctl.c | 840 +++++++++++ - src/lstack/api/lstack_sockio.c | 1488 ++++++++++++++++++++ - src/lstack/core/lstack_mempool.c | 1014 +++++++++++++ - src/lstack/include/lstack_lockless_queue.h | 81 +- - src/lstack/include/lstack_mempool.h | 325 +++++ - src/lstack/include/lstack_sockctl.h | 25 + - src/lstack/include/lstack_sockio.h | 41 + - src/lstack/include/mbox_ring.h | 583 ++++++++ - 8 files changed, 4394 insertions(+), 3 deletions(-) - create mode 100644 src/lstack/api/lstack_sockctl.c - create mode 100644 src/lstack/api/lstack_sockio.c - create mode 100644 src/lstack/core/lstack_mempool.c - create mode 100644 src/lstack/include/lstack_mempool.h - create mode 100644 src/lstack/include/lstack_sockctl.h - create mode 100644 src/lstack/include/lstack_sockio.h - create mode 100644 src/lstack/include/mbox_ring.h - -diff --git a/src/lstack/api/lstack_sockctl.c b/src/lstack/api/lstack_sockctl.c -new file mode 100644 -index 0000000..71310b7 ---- /dev/null -+++ b/src/lstack/api/lstack_sockctl.c -@@ -0,0 +1,840 @@ -+/* -+* 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 -+#include -+#include -+ -+#include "common/gazelle_base_func.h" -+#include "lstack_log.h" -+#include "lstack_cfg.h" -+#include "lstack_thread_rpc.h" -+#include "lstack_protocol_stack.h" -+#include "lstack_epoll.h" -+#include "lstack_sockctl.h" -+#include "lstack_sockio.h" -+ -+ -+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 %d, fd %d fail %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); -+ } -+} -+ -+static void callback_getsockname(struct rpc_msg *msg) -+{ -+ msg->result = lwip_getsockname(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 %d, fd %d fail %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); -+ } -+} -+ -+static void callback_getsockopt(struct rpc_msg *msg) -+{ -+ msg->result = lwip_getsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, -+ msg->args[MSG_ARG_3].p, msg->args[MSG_ARG_4].p); -+ if (msg->result != 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d, level %d, optname %d, fail %ld\n", rte_gettid(), -+ msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); -+ } -+} -+ -+static void callback_setsockopt(struct rpc_msg *msg) -+{ -+ msg->result = lwip_setsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, -+ msg->args[MSG_ARG_3].cp, msg->args[MSG_ARG_4].u); -+ if (msg->result != 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d, level %d, optname %d, fail %ld\n", rte_gettid(), -+ msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); -+ } -+} -+ -+static int rpc_call_getpeername(int stack_id, int fd, struct sockaddr *addr, socklen_t *addrlen) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_getpeername); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].p = addr; -+ msg->args[MSG_ARG_2].p = addrlen; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+static int rpc_call_getsockname(int stack_id, int fd, struct sockaddr *addr, socklen_t *addrlen) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_getsockname); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].p = addr; -+ msg->args[MSG_ARG_2].p = addrlen; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+static int rpc_call_getsockopt(int stack_id, int fd, int level, int optname, void *optval, socklen_t *optlen) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_getsockopt); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].i = level; -+ msg->args[MSG_ARG_2].i = optname; -+ msg->args[MSG_ARG_3].p = optval; -+ msg->args[MSG_ARG_4].p = optlen; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+static int rpc_call_setsockopt(int stack_id, int fd, int level, int optname, const void *optval, socklen_t optlen) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_setsockopt); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].i = level; -+ msg->args[MSG_ARG_2].i = optname; -+ msg->args[MSG_ARG_3].cp = optval; -+ msg->args[MSG_ARG_4].u = optlen; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+static int rtw_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) -+{ -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (POSIX_IS_CLOSED(sock)) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_setsockopt(sock->stack_id, s, level, optname, optval, optlen); -+} -+ -+static int rtw_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) -+{ -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (POSIX_IS_CLOSED(sock)) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_getsockopt(sock->stack_id, s, level, optname, optval, optlen); -+} -+ -+static int rtw_getpeername(int s, struct sockaddr *name, socklen_t *namelen) -+{ -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (POSIX_IS_CLOSED(sock)) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_getpeername(sock->stack_id, s, name, namelen); -+} -+ -+static int rtw_getsockname(int s, struct sockaddr *name, socklen_t *namelen) -+{ -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (POSIX_IS_CLOSED(sock)) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_getsockname(sock->stack_id, s, name, namelen); -+} -+ -+ -+static void callback_socket(struct rpc_msg *msg) -+{ -+ msg->result = lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); -+ if (msg->result < 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %d, %ld socket failed\n", rte_gettid(), msg->result); -+ } -+} -+ -+static int rpc_call_socket(int stack_id, int domain, int type, int protocol) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_socket); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = domain; -+ msg->args[MSG_ARG_1].i = type; -+ msg->args[MSG_ARG_2].i = protocol; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+static void callback_close(struct rpc_msg *msg) -+{ -+ int fd = msg->args[MSG_ARG_0].i; -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ -+ if (sockio_mbox_pending(sock)) { -+ rpc_queue *queue = &get_protocol_stack_by_id(sock->stack_id)->rpc_queue; -+ rpc_async_call(queue, msg, RPC_MSG_FREE | RPC_MSG_RECALL); /* until stack_send recall finish */ -+ return; -+ } -+ -+ msg->result = lwip_close(fd); -+ if (msg->result != 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d failed %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); -+ } -+} -+ -+static void callback_shutdown(struct rpc_msg *msg) -+{ -+ int fd = msg->args[MSG_ARG_0].i; -+ int how = msg->args[MSG_ARG_1].i; -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ -+ if (sockio_mbox_pending(sock)) { -+ rpc_queue *queue = &get_protocol_stack_by_id(sock->stack_id)->rpc_queue; -+ rpc_async_call(queue, msg, RPC_MSG_FREE | RPC_MSG_RECALL); -+ return; -+ } -+ -+ msg->result = lwip_shutdown(fd, how); -+ if (msg->result != 0 && errno != ENOTCONN) { -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d fail %ld\n", rte_gettid(), fd, msg->result); -+ } -+ -+ posix_api->shutdown_fn(fd, how); -+} -+ -+static int rpc_call_close(int stack_id, int fd) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_close); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+static int rpc_call_shutdown(int stack_id, int fd, int how) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_shutdown); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].i = how; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+static void callback_bind(struct rpc_msg *msg) -+{ -+ msg->result = lwip_bind(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].cp, msg->args[MSG_ARG_2].u); -+ if (msg->result != 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d failed %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); -+ } -+} -+ -+static int rpc_call_bind(int stack_id, int fd, const struct sockaddr *addr, socklen_t addrlen) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_bind); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].cp = addr; -+ msg->args[MSG_ARG_2].u = addrlen; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+static void callback_listen(struct rpc_msg *msg) -+{ -+ int fd = msg->args[MSG_ARG_0].i; -+ int backlog = msg->args[MSG_ARG_1].i; -+ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL) { -+ msg->result = -1; -+ return; -+ } -+ -+ /* new listen add to stack listen list */ -+ msg->result = lwip_listen(fd, backlog); -+ if (msg->result != 0) { -+ LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d failed %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); -+ } -+} -+ -+static int rpc_call_listen(int stack_id, int s, int backlog) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_listen); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = s; -+ msg->args[MSG_ARG_1].i = backlog; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+static void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock) -+{ -+ dst_sock->conn->pcb.ip->so_options = src_sock->conn->pcb.ip->so_options; -+ dst_sock->conn->pcb.ip->ttl = src_sock->conn->pcb.ip->ttl; -+ dst_sock->conn->pcb.ip->tos = src_sock->conn->pcb.ip->tos; -+ dst_sock->conn->flags = src_sock->conn->flags; -+ -+ switch (NETCONN_TYPE(src_sock->conn)) { -+ case NETCONN_TCP: -+ dst_sock->conn->pcb.tcp->netif_idx = src_sock->conn->pcb.tcp->netif_idx; -+ dst_sock->conn->pcb.tcp->flags = src_sock->conn->pcb.tcp->flags; -+ dst_sock->conn->pcb.tcp->keep_idle = src_sock->conn->pcb.tcp->keep_idle; -+ dst_sock->conn->pcb.tcp->keep_intvl = src_sock->conn->pcb.tcp->keep_intvl; -+ dst_sock->conn->pcb.tcp->keep_cnt = src_sock->conn->pcb.tcp->keep_cnt; -+ break; -+ case NETCONN_UDP: -+ dst_sock->conn->pcb.udp->flags = src_sock->conn->pcb.udp->flags; -+ dst_sock->conn->pcb.udp->mcast_ifindex = src_sock->conn->pcb.udp->mcast_ifindex; -+ dst_sock->conn->pcb.udp->mcast_ttl = src_sock->conn->pcb.udp->mcast_ttl; -+ break; -+ default: -+ break; -+ } -+} -+static void callback_create_shadow_fd(struct rpc_msg *msg) -+{ -+ int fd = msg->args[MSG_ARG_0].i; -+ struct sockaddr *addr = msg->args[MSG_ARG_1].p; -+ socklen_t addr_len = msg->args[MSG_ARG_2].u; -+ -+ int clone_fd = 0; -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d\n", fd); -+ msg->result = -1; -+ return; -+ } -+ -+ int domain = addr->sa_family; -+ int type = NETCONN_TYPE(sock->conn) == NETCONN_UDP ? SOCK_DGRAM : SOCK_STREAM; -+ clone_fd = lwip_socket(domain, type, 0); -+ if (clone_fd < 0) { -+ LSTACK_LOG(ERR, LSTACK, "clone socket failed clone_fd=%d errno=%d\n", clone_fd, errno); -+ msg->result = clone_fd; -+ return; -+ } -+ -+ struct lwip_sock *clone_sock = lwip_get_socket(clone_fd); -+ if (clone_sock == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d clone_fd=%d\n", fd, clone_fd); -+ msg->result = -1; -+ return; -+ } -+ -+ do_lwip_clone_sockopt(clone_sock, sock); -+ -+ while (sock->listen_next) { -+ sock = sock->listen_next; -+ } -+ sock->listen_next = clone_sock; -+ -+ int ret = lwip_bind(clone_fd, addr, addr_len); -+ if (ret < 0) { -+ LSTACK_LOG(ERR, LSTACK, "clone bind failed clone_fd=%d errno=%d\n", clone_fd, errno); -+ msg->result = ret; -+ return; -+ } -+ -+ msg->result = clone_fd; -+} -+ -+static int rpc_call_shadow_fd(int stack_id, int fd, const struct sockaddr *addr, socklen_t addrlen) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_create_shadow_fd); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].cp = addr; -+ msg->args[MSG_ARG_2].u = addrlen; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+static void callback_accept(struct rpc_msg *msg) -+{ -+ int fd = msg->args[MSG_ARG_0].i; -+ msg->result = -1; -+ struct protocol_stack *stack = get_protocol_stack(); -+ -+ int accept_fd = lwip_accept4(fd, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].p, msg->args[MSG_ARG_3].i); -+ if (accept_fd < 0) { -+ stack->stats.accept_fail++; -+ LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); -+ return; -+ } -+ msg->result = accept_fd; -+} -+ -+static int rpc_call_accept(int stack_id, int fd, struct sockaddr *addr, socklen_t *addrlen, int flags) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_accept); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].p = addr; -+ msg->args[MSG_ARG_2].p = addrlen; -+ msg->args[MSG_ARG_3].i = flags; -+ -+ return rpc_sync_call(queue, msg); -+} -+ -+static void callback_connect(struct rpc_msg *msg) -+{ -+ msg->result = lwip_connect(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].u); -+ if (msg->result < 0) { -+ msg->result = -errno; -+ } -+} -+ -+static int rpc_call_connect(int stack_id, int fd, const struct sockaddr *addr, socklen_t addrlen) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_connect); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->args[MSG_ARG_0].i = fd; -+ msg->args[MSG_ARG_1].cp = addr; -+ msg->args[MSG_ARG_2].u = addrlen; -+ -+ int ret = rpc_sync_call(queue, msg); -+ if (ret < 0) { -+ errno = -ret; -+ ret = -1; -+ } -+ -+ if (ret < 0 && errno == EINPROGRESS) { -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn))) { -+ ret = 0; -+ } -+ } -+ return ret; -+} -+ -+/* for lwip nonblock connected callback */ -+void do_lwip_connected_callback(int fd) -+{ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (POSIX_IS_CLOSED(sock)) { -+ return; -+ } -+ -+ if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { -+ /* delete kernel event */ -+ if (sock->sk_wait != NULL) { -+ posix_api->epoll_ctl_fn(sock->sk_wait->epfd, EPOLL_CTL_DEL, fd, NULL); -+ } -+ /* shutdown kernel connect, do_connect() has tried both kernel and lwip. */ -+ posix_api->shutdown_fn(fd, SHUT_RDWR); -+ } -+ -+ POSIX_SET_TYPE(sock, POSIX_LWIP); -+ -+ API_EVENT(sock->conn, NETCONN_EVT_RCVPLUS, 0); -+} -+ -+/* when fd is listenfd, listenfd of all protocol stack thread will be closed */ -+static int stack_broadcast_close(int fd) -+{ -+ int ret = 0; -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ -+ while (sock != NULL) { -+ if (POSIX_IS_CLOSED(sock)) { -+ ret = -1; -+ break; -+ } -+ fd = sock->conn->callback_arg.socket; -+ ret |= rpc_call_close(sock->stack_id, fd); -+ sock = sock->listen_next; -+ } -+ -+ if (ret != 0) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return ret; -+} -+ -+static int stack_broadcast_shutdown(int fd, int how) -+{ -+ int ret = 0; -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ -+ while (true) { -+ if (POSIX_IS_CLOSED(sock)) { -+ ret = -1; -+ break; -+ } -+ fd = sock->conn->callback_arg.socket; -+ ret |= rpc_call_shutdown(sock->stack_id, fd, how); -+ sock = sock->listen_next; -+ } -+ -+ if (ret != 0) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return ret; -+} -+ -+/* choice one stack bind */ -+static int stack_single_bind(int fd, const struct sockaddr *name, socklen_t namelen) -+{ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (POSIX_IS_CLOSED(sock)) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_bind(sock->stack_id, fd, name, namelen); -+} -+ -+/* bind sync to all protocol stack thread, so that any protocol stack thread can build connect */ -+static int stack_broadcast_bind(int fd, const struct sockaddr *name, socklen_t namelen) -+{ -+ struct protocol_stack *cur_stack; -+ struct protocol_stack *stack = NULL; -+ int ret, clone_fd; -+ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "tid %d, %d get sock null or stack null\n", rte_gettid(), fd); -+ GAZELLE_RETURN(EBADF); -+ } -+ -+ ret = rpc_call_bind(sock->stack_id, fd, name, namelen); -+ if (ret < 0) { -+ close(fd); -+ return ret; -+ } -+ -+ cur_stack = get_protocol_stack_by_id(sock->stack_id); -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+ for (int i = 0; i < stack_group->stack_num; ++i) { -+ stack = stack_group->stacks[i]; -+ if (stack != cur_stack) { -+ clone_fd = rpc_call_shadow_fd(stack->stack_idx, fd, name, namelen); -+ if (clone_fd < 0) { -+ stack_broadcast_close(fd); -+ return clone_fd; -+ } -+ } -+ } -+ return 0; -+} -+ -+static struct lwip_sock *get_min_accept_sock(int fd) -+{ -+ struct lwip_sock *sock; -+ struct lwip_sock *min_sock = NULL; -+ -+ for (sock = lwip_get_socket(fd); sock != NULL; sock = sock->listen_next) { -+ if (!netconn_is_nonblocking(sock->conn)) { -+ /* init all sock sk_wait */ -+ if (unlikely(sock->sk_wait == NULL) || sock->sk_wait->type == WAIT_CLOSE) { -+ sock->sk_wait = poll_construct_wait(0); -+ } -+ if (!(sock->sk_wait->type & WAIT_BLOCK)) { -+ sock->sk_wait->type |= WAIT_BLOCK; -+ } -+ } -+ -+ if (!sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_RCVPLUS, 0)) { -+ continue; -+ } -+ -+ if (min_sock == NULL || -+ get_protocol_stack_by_id(min_sock->stack_id)->conn_num > get_protocol_stack_by_id(sock->stack_id)->conn_num) { -+ min_sock = sock; -+ } -+ } -+ -+ return min_sock; -+} -+ -+/* ergodic the protocol stack thread to find the connection, because all threads are listening */ -+static int stack_broadcast_accept4(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags) -+{ -+ int ret = -1; -+ struct protocol_stack *stack; -+ struct lwip_sock *min_sock; -+ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL) { -+ GAZELLE_RETURN(EBADF); -+ } -+ -+ min_sock = get_min_accept_sock(fd); -+ if (min_sock == NULL) { -+ if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & SOCK_NONBLOCK))) { -+ min_sock = get_min_accept_sock(fd); -+ } -+ } -+ -+ if (!POSIX_IS_CLOSED(min_sock)) { -+ stack = get_protocol_stack_by_id(min_sock->stack_id); -+ ret = rpc_call_accept(stack->stack_idx, min_sock->conn->callback_arg.socket, addr, addrlen, flags); -+ } -+ -+ if (ret < 0) { -+ errno = EAGAIN; -+ } -+ return ret; -+} -+ -+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, SOCK_NONBLOCK); -+ else -+ return stack_broadcast_accept4(fd, addr, addrlen, 0); -+} -+ -+/* choice one stack listen */ -+static int stack_single_listen(int fd, int backlog) -+{ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (POSIX_IS_CLOSED(sock)) { -+ GAZELLE_RETURN(EBADF); -+ } -+ return rpc_call_listen(sock->stack_id, fd, backlog); -+} -+ -+/* listen sync to all protocol stack thread, so that any protocol stack thread can build connect */ -+static int stack_broadcast_listen(int fd, int backlog) -+{ -+ typedef union sockaddr_union { -+ struct sockaddr sa; -+ struct sockaddr_in in; -+ struct sockaddr_in6 in6; -+ } sockaddr_t; -+ -+ struct protocol_stack *cur_stack; -+ struct protocol_stack *stack = NULL; -+ sockaddr_t addr; -+ socklen_t addr_len = sizeof(addr); -+ int ret, clone_fd; -+ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "tid %d, %d get sock null or stack null\n", rte_gettid(), fd); -+ GAZELLE_RETURN(EBADF); -+ } -+ -+ ret = rpc_call_getsockname(sock->stack_id, fd, (struct sockaddr *)&addr, &addr_len); -+ if (ret != 0) { -+ return ret; -+ } -+ -+ cur_stack = get_protocol_stack_by_id(sock->stack_id); -+ struct protocol_stack_group *stack_group = get_protocol_stack_group(); -+#if GAZELLE_TCP_REUSE_IPPORT -+ int min_conn_stk_idx = get_min_conn_stack(stack_group); -+#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->stack_idx, fd, (struct sockaddr *)&addr, addr_len); -+ if (clone_fd < 0) { -+ stack_broadcast_close(fd); -+ return clone_fd; -+ } -+ } else { -+ clone_fd = fd; -+ } -+ -+#if GAZELLE_TCP_REUSE_IPPORT -+ if (min_conn_stk_idx == i) { -+ lwip_get_socket(clone_fd)->conn->is_master_fd = 1; -+ } else { -+ lwip_get_socket(clone_fd)->conn->is_master_fd = 0; -+ } -+#endif /* GAZELLE_TCP_REUSE_IPPORT */ -+ -+ ret = rpc_call_listen(stack->stack_idx, clone_fd, backlog); -+ if (ret < 0) { -+ stack_broadcast_close(fd); -+ return ret; -+ } -+ } -+ return 0; -+} -+ -+ -+static int rtw_socket(int domain, int type, int protocol) -+{ -+ struct protocol_stack *stack = get_bind_protocol_stack(); -+ if (stack == NULL) { -+ GAZELLE_RETURN(EINVAL); -+ } -+ return rpc_call_socket(stack->stack_idx, domain, type, protocol); -+} -+ -+static int rtw_accept(int s, struct sockaddr *addr, socklen_t *addrlen) -+{ -+ return stack_broadcast_accept(s, addr, addrlen); -+} -+ -+static int rtw_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) -+{ -+ return stack_broadcast_accept4(s, addr, addrlen, flags); -+} -+ -+static int rtw_bind(int s, const struct sockaddr *name, socklen_t namelen) -+{ -+ struct lwip_sock *sock = lwip_get_socket(s); -+ -+ if (NETCONN_TYPE(sock->conn) == NETCONN_UDP && -+ get_global_cfg_params()->listen_shadow) { -+ return stack_broadcast_bind(s, name, namelen); -+ } else { -+ return stack_single_bind(s, name, namelen); -+ } -+} -+ -+static int rtw_listen(int s, int backlog) -+{ -+ if (!get_global_cfg_params()->tuple_filter && -+ !get_global_cfg_params()->listen_shadow) { -+ return stack_single_listen(s, backlog); -+ } else { -+ return stack_broadcast_listen(s, backlog); -+ } -+} -+ -+static int rtw_connect(int s, const struct sockaddr *name, socklen_t namelen) -+{ -+ struct lwip_sock *sock = lwip_get_socket(s); -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ if (stack == NULL || POSIX_IS_CLOSED(sock)) { -+ GAZELLE_RETURN(EBADF); -+ } -+ -+ return rpc_call_connect(stack->stack_idx, s, name, namelen); -+} -+ -+static int rtw_close(int s) -+{ -+ return stack_broadcast_close(s); -+} -+ -+static int rtw_shutdown(int fd, int how) -+{ -+ return stack_broadcast_shutdown(fd, how); -+} -+ -+void sockctl_rtw_api_init(posix_api_t *api) -+{ -+ api->close_fn = rtw_close; -+ api->shutdown_fn = rtw_shutdown; -+ api->socket_fn = rtw_socket; -+ api->bind_fn = rtw_bind; -+ api->listen_fn = rtw_listen; -+ api->accept_fn = rtw_accept; -+ api->accept4_fn = rtw_accept4; -+ api->connect_fn = rtw_connect; -+ -+ api->setsockopt_fn = rtw_setsockopt; -+ api->getsockopt_fn = rtw_getsockopt; -+ api->getpeername_fn = rtw_getpeername; -+ api->getsockname_fn = rtw_getsockname; -+} -+ -+static int rtc_connect(int s, const struct sockaddr *name, socklen_t namelen) -+{ -+ int ret; -+ -+ ret = lwip_connect(s, name, namelen); -+ if (ret < 0 && errno == EINPROGRESS) { -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn))) { -+ ret = 0; -+ } -+ } -+ -+ return ret; -+} -+ -+static int rtc_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) -+{ -+ int ret; -+ struct lwip_sock *sock = lwip_get_socket(s); -+ if (POSIX_IS_CLOSED(sock)) { -+ GAZELLE_RETURN(EBADF); -+ } -+ -+ ret = lwip_accept4(s, addr, addrlen, flags); -+ if (ret < 0 && errno == EWOULDBLOCK) { -+ if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & SOCK_NONBLOCK))) { -+ ret = lwip_accept4(s, addr, addrlen, flags); -+ } -+ } -+ return ret; -+} -+ -+static int rtc_accept(int s, struct sockaddr *addr, socklen_t *addrlen) -+{ -+ return rtc_accept4(s, addr, addrlen, 0); -+} -+ -+void sockctl_rtc_api_init(posix_api_t *api) -+{ -+ api->close_fn = lwip_close; -+ api->shutdown_fn = lwip_shutdown; -+ api->socket_fn = lwip_socket; -+ api->bind_fn = lwip_bind; -+ api->listen_fn = lwip_listen; -+ api->accept_fn = rtc_accept; -+ api->accept4_fn = rtc_accept4; -+ api->connect_fn = rtc_connect; -+ -+ api->setsockopt_fn = lwip_setsockopt; -+ api->getsockopt_fn = lwip_getsockopt; -+ api->getpeername_fn = lwip_getpeername; -+ api->getsockname_fn = lwip_getsockname; -+} -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -new file mode 100644 -index 0000000..060b3b3 ---- /dev/null -+++ b/src/lstack/api/lstack_sockio.c -@@ -0,0 +1,1488 @@ -+/* -+* 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 -+ -+#include -+#include -+#include -+ -+#include "lstack_thread_rpc.h" -+#include "lstack_log.h" -+#include "lstack_sockio.h" -+#include "lstack_wait.h" -+#include "mbox_ring.h" -+#include "lstack_epoll.h" -+#include "lstack_stack_stat.h" -+ -+ -+/* see lwip ip4_frag() and ip6_frag(), nfb must be a multiple of 8 */ -+#define IP_FRAG_NFB ((GAZELLE_ETH_MTU - PBUF_IP) / 8) -+#define UDP_MSS (IP_FRAG_NFB * 8 - UDP_HLEN) -+ -+#define IP4_UDP_SND_SIZE_MAX (0xFFFF - IP_HLEN - UDP_HLEN) -+#define IP6_UDP_SND_SIZE_MAX (0xFFFF - IP6_HLEN - UDP_HLEN) -+#define UDP_SND_SIZE_MAX(conn) (NETCONNTYPE_ISIPV6(netconn_type(conn)) ? IP6_UDP_SND_SIZE_MAX : IP4_UDP_SND_SIZE_MAX) -+#define UDP_SND_QUEUELEN_MAX ((IP6_UDP_SND_SIZE_MAX + UDP_MSS - 1) / UDP_MSS) -+#define UDP_SND_OUTPUT_NUM (16) -+ -+#define TCP_SND_OUTPUT_NUM OFFLOAD_TX_TSO_MTU_FRAGS -+#define TCP_SND_QUEUELEN_MAX OFFLOAD_TX_TSO_MTU_FRAGS -+#define TCP_SND_SIZE_MAX (TCP_SND_QUEUELEN_MAX * TCP_MSS) -+ -+#define TCP_SND_APPEND_LEN (TCP_MSS >> 1) -+ -+#define RECV_EXTEND_CACHE_MAX 8 -+#define RECV_EXTEND_CACHE_LEN (4 * TCP_MSS) -+ -+struct sockio_ops { -+ ssize_t (*stack_udp_write)(struct lwip_sock *sock, const void *data, size_t len, int flags, -+ const struct sockaddr *to, socklen_t tolen); -+ void (*stack_udp_send)(struct lwip_sock *sock); -+ -+ ssize_t (*stack_udp_readmsg)(struct lwip_sock *sock, struct msghdr *msg, int flags); -+ -+ ssize_t (*stack_tcp_write)(struct lwip_sock *sock, const char *data, size_t len, int flags); -+ void (*stack_tcp_send)(struct lwip_sock *sock); -+ -+ ssize_t (*stack_tcp_read)(struct lwip_sock *sock, char *data, size_t len, int flags, -+ struct sockaddr *from, socklen_t *fromlen); -+ void (*stack_tcp_recvd)(struct lwip_sock *sock, ssize_t recvd, int flags); -+}; -+static struct sockio_ops ioops = {0}; -+ -+ -+static unsigned pbuf_list_count(const struct mbox_ring *mr) -+{ -+ struct pbuf *p = mr->ops->read_tail(mr); -+ return pbuf_clen(p); -+} -+ -+static unsigned netbuf_list_count(const struct mbox_ring *mr) -+{ -+ struct netbuf *nbuf = mr->ops->read_tail(mr); -+ return pbuf_clen(nbuf->p); -+} -+ -+static void netbuf_obj_free(struct mbox_ring *mr, void *obj, bool is_tail) -+{ -+ err_t err; -+ if (unlikely(lwip_netconn_is_err_msg(obj, &err))) -+ return; -+ -+ if (is_tail && (mr->flags & MBOX_FLAG_RECV)) { -+ pbuf_free((struct pbuf *)obj); -+ } else { -+ netbuf_free((struct netbuf *)obj); -+ } -+} -+ -+static void pbuf_obj_free(struct mbox_ring *mr, void *obj, bool is_tail) -+{ -+ err_t err; -+ if (unlikely(lwip_netconn_is_err_msg(obj, &err))) -+ return; -+ pbuf_free((struct pbuf *)obj); -+} -+ -+void sockio_mbox_set_func(struct mbox_ring *mr) -+{ -+ mr->tail_count = pbuf_list_count; -+ if (mr->flags & MBOX_FLAG_TCP) { -+ /* only tcp sendmbox & recvmbox, lwip would free all acceptmbox newconn objs. */ -+ mr->obj_free_fn = pbuf_obj_free; -+ } else if (mr->flags & MBOX_FLAG_UDP) { -+ /* udp sendmbox & recvmbox */ -+ mr->obj_free_fn = netbuf_obj_free; -+ if (mr->flags & MBOX_FLAG_SEND) -+ mr->tail_count = netbuf_list_count; -+ } -+} -+ -+void sockio_peek_recv_free(struct mbox_ring *mr, unsigned n) -+{ -+ void *buf_pkts[RECV_EXTEND_CACHE_MAX]; -+ unsigned num, i; -+ -+ mr->stk_queued_num += n; -+ if (mr->stk_queued_num < (RECV_EXTEND_CACHE_MAX >> 1)) { -+ return; -+ } -+ -+ while (true) { -+ num = mr->ops->dequeue_burst(mr, buf_pkts, RECV_EXTEND_CACHE_MAX); -+ if (num == 0) -+ break; -+ if (mr->flags & MBOX_FLAG_UDP) { -+ for (i = 0; i < num; ++i) { -+ buf_pkts[i] = ((struct netbuf *)buf_pkts[i])->p; -+ } -+ } -+ mem_put_pbuf_list_bulk((struct pbuf **)buf_pkts, num); -+ mr->stk_queued_num -= num; -+ } -+} -+ -+static void sock_mbox_private_free(struct mbox_ring *mr) -+{ -+ struct rpc_msg *msg = (struct rpc_msg *)mr->private_data; -+ if (msg != NULL) { -+ rpc_msg_free(msg); -+ mr->private_data = NULL; -+ } -+} -+ -+static int sock_mbox_private_init(sys_mbox_t mb, rpc_func_t func) -+{ -+ struct rpc_msg *msg = rpc_msg_alloc(get_protocol_stack()->stack_idx, func); -+ if (msg == NULL) -+ return -1; -+ -+ memset_s(msg->args, sizeof(msg->args), 0, sizeof(msg->args)); -+ -+ mb->mring.private_data = msg; -+ mb->mring.private_data_free_fn = sock_mbox_private_free; -+ return 0; -+} -+ -+static inline struct rpc_msg *sock_mbox_private_get(sys_mbox_t mb) -+{ -+ return (struct rpc_msg *)mb->mring.private_data; -+} -+ -+ -+static inline uint16_t write_pbuf(struct pbuf *p, const char *data, uint16_t len, uint8_t optlen) -+{ -+ mem_init_pbuf(p, PBUF_TRANSPORT, len, len, PBUF_POOL); -+ if (optlen > 0) { -+ /* see pbuf_remove_header() */ -+ p->payload = (uint8_t *)p->payload + optlen; -+ } -+ -+ if (get_protocol_stack_group()->latency_start) -+ time_stamp_into_write(&p, 1); -+ -+ pbuf_take(p, data, len); -+ return len; -+} -+ -+static inline void write_pbuf_bulk(struct pbuf *pbuf_pkts[], unsigned n, uint16_t payload_size, -+ const char *data, uint16_t len, uint8_t optlen) -+{ -+ unsigned i; -+ uint16_t copied_total = 0; -+ -+ for (i = 0; i < (n & ~0x3); i += 4) { -+ rte_prefetch0(pbuf_pkts[i + 1]); -+ rte_prefetch0(data + copied_total + payload_size); -+ copied_total += write_pbuf(pbuf_pkts[i], data + copied_total, payload_size, optlen); -+ -+ rte_prefetch0(pbuf_pkts[i + 2]); -+ rte_prefetch0(data + copied_total + payload_size); -+ copied_total += write_pbuf(pbuf_pkts[i + 1], data + copied_total, payload_size, optlen); -+ -+ rte_prefetch0(pbuf_pkts[i + 3]); -+ rte_prefetch0(data + copied_total + payload_size); -+ copied_total += write_pbuf(pbuf_pkts[i + 2], data + copied_total, payload_size, optlen); -+ -+ if (payload_size > len - copied_total) -+ payload_size = len - copied_total; -+ copied_total += write_pbuf(pbuf_pkts[i + 3], data + copied_total, payload_size, optlen); -+ } -+ switch (n & 0x3) { -+ case 3: -+ rte_prefetch0(pbuf_pkts[i + 1]); -+ copied_total += write_pbuf(pbuf_pkts[i], data + copied_total, payload_size, optlen); -+ ++i; /* fallthrough */ -+ case 2: -+ rte_prefetch0(pbuf_pkts[i + 1]); -+ copied_total += write_pbuf(pbuf_pkts[i], data + copied_total, payload_size, optlen); -+ ++i; /* fallthrough */ -+ case 1: -+ payload_size = len - copied_total; -+ write_pbuf(pbuf_pkts[i], data + copied_total, payload_size, optlen); -+ /* fallthrough */ -+ } -+} -+ -+static inline void write_pbuf_list(struct pbuf *pbuf_pkts[], unsigned n, uint16_t payload_size, -+ const char *data, uint16_t len, uint8_t optlen) -+{ -+ unsigned i; -+ uint16_t copied_total = 0; -+ -+ for (i = 0; i < n - 1; ++i) { -+ rte_prefetch0(pbuf_pkts[i + 1]); -+ rte_prefetch0(data + copied_total + payload_size); -+ write_pbuf(pbuf_pkts[i], data + copied_total, payload_size, optlen); -+ pbuf_pkts[i]->next = pbuf_pkts[i + 1]; -+ pbuf_pkts[i]->tot_len = len - copied_total; -+ copied_total += payload_size; -+ } -+ -+ payload_size = len - copied_total; -+ write_pbuf(pbuf_pkts[i], data + copied_total, payload_size, optlen); -+ pbuf_pkts[i]->next = NULL; -+} -+ -+static uint16_t stack_udp_write_one(const struct lwip_sock *sock, struct mbox_ring *mr, -+ const char *data, uint16_t len, int flags, -+ const struct sockaddr *to, socklen_t tolen) -+{ -+ struct pbuf **extcache_list = (struct pbuf **)&sock->conn->recvmbox->mring.st_obj; -+ struct pbuf *p; -+ struct netbuf *nbuf; -+ -+ p = mem_extcache_get_pbuf(sock->stack_id, true, extcache_list); -+ if (p == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "mem_extcache_get_pbuf failed\n"); -+ set_errno(ENOMEM); -+ return 0; -+ } -+ -+ write_pbuf(p, data, len, 0); -+ -+ nbuf = netbuf_create(p); -+ lwip_sendto_netbuf(sock->conn, nbuf, to, tolen); -+ -+ if (get_protocol_stack_group()->latency_start) -+ calculate_lstack_latency(sock->stack_id, &nbuf->p, 1, GAZELLE_LATENCY_WRITE_INTO_RING, 0); -+ -+ mr->ops->enqueue_burst(mr, (void **)&nbuf, 1); -+ mr->app_free_count -= 1; -+ -+ return len; -+} -+ -+static uint16_t stack_udp_write_bulk(const struct lwip_sock *sock, struct mbox_ring *mr, -+ const char *data, uint16_t len, int flags, -+ const struct sockaddr *to, socklen_t tolen) -+{ -+ struct pbuf *pbuf_pkts[UDP_SND_QUEUELEN_MAX]; -+ unsigned pbuf_num; -+ struct netbuf *nbuf; -+ uint16_t payload_size; -+ uint8_t optlen; -+ uint16_t copied_total = 0; -+ -+ if (NETCONNTYPE_ISIPV6(netconn_type(sock->conn))) { -+ optlen = IP6_FRAG_HLEN; -+ payload_size = UDP_MSS - IP6_FRAG_HLEN; -+ } else { -+ optlen = 0; -+ payload_size = UDP_MSS; -+ } -+ -+ /* step1. udp append data */ -+ nbuf = (struct netbuf *)mr->ops->pop_tail(mr, NULL); -+ if (nbuf != NULL) { -+ copied_total = LWIP_MIN(len, payload_size - nbuf->tail->len); -+ pbuf_append_take(nbuf->p, nbuf->tail, data, copied_total, NULL); -+ len -= copied_total; -+ } -+ -+ /* step2. alloc a batch of pbufs */ -+ if (len > 0) { -+ struct pbuf **extcache_list = (struct pbuf **)&sock->conn->recvmbox->mring.st_obj; -+ pbuf_num = (len + payload_size - 1) / payload_size; -+ pbuf_num = mem_extcache_get_pbuf_bulk(sock->stack_id, pbuf_pkts, pbuf_num, true, extcache_list); -+ if (pbuf_num == 0) { -+ /* drop netbuf */ -+ if (nbuf != NULL) { -+ netbuf_free(nbuf); -+ } -+ LSTACK_LOG(ERR, LSTACK, "mem_extcache_get_pbuf_bulk failed, pbuf_num %u\n", pbuf_num); -+ set_errno(ENOMEM); -+ return 0; -+ } -+ -+ write_pbuf_list(pbuf_pkts, pbuf_num, payload_size, data + copied_total, len, optlen); -+ copied_total += len; -+ -+ if (nbuf == NULL) { -+ nbuf = netbuf_create(pbuf_pkts[0]); -+ lwip_sendto_netbuf(sock->conn, nbuf, to, tolen); -+ } else { -+ pbuf_cat(nbuf->p, pbuf_pkts[0]); -+ } -+ nbuf->tail = pbuf_pkts[pbuf_num - 1]; -+ } -+ -+ /* step3. enqueue the new netbuf */ -+ if ((flags & MSG_MORE) == 0) { -+ if (get_protocol_stack_group()->latency_start) -+ calculate_lstack_latency(sock->stack_id, &nbuf->p, 1, GAZELLE_LATENCY_WRITE_INTO_RING, 0); -+ -+ mr->ops->enqueue_burst(mr, (void **)&nbuf, 1); -+ mr->app_free_count -= 1; -+ } else { -+ mr->ops->push_tail(mr, nbuf); -+ } -+ -+ return copied_total; -+} -+ -+static ssize_t stack_udp_write(struct lwip_sock *sock, const void *data, size_t len, int flags, -+ const struct sockaddr *to, socklen_t tolen) -+{ -+ struct mbox_ring *mr = &sock->conn->sendmbox->mring; -+ uint16_t copied_total; -+ -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(sock=%p, data=%p, size=%"SZT_F", flags=0x%x)\n", -+ __FUNCTION__, sock, data, len, flags)); -+ -+ if (unlikely(sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0))) { -+ set_errno(ENOTCONN); -+ return -1; -+ } -+ -+ if (unlikely(len > UDP_SND_SIZE_MAX(sock->conn))) { -+ LSTACK_LOG(ERR, LSTACK, "Message too long\n"); -+ set_errno(EMSGSIZE); -+ return -1; -+ } -+ -+ if (unlikely(mr->app_free_count < 1)) { -+ mr->app_free_count = mr->ops->free_count(mr); -+ if (unlikely(mr->app_free_count < 1)) { -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -+ set_errno(EWOULDBLOCK); -+ return -1; -+ } -+ } -+ -+ if (len <= UDP_MSS && (flags & MSG_MORE) == 0) { -+ copied_total = stack_udp_write_one(sock, mr, data, len, flags, to, tolen); -+ } else { -+ copied_total = stack_udp_write_bulk(sock, mr, data, len, flags, to, tolen); -+ } -+ -+ return copied_total > 0 ? copied_total : -1; -+} -+ -+static ssize_t stack_udp_output(struct netconn *conn, bool *output_again, struct mem_thread *mt) -+{ -+ struct mbox_ring *mr = &conn->sendmbox->mring; -+ err_t err; -+ struct netbuf *nbuf_pkts[UDP_SND_OUTPUT_NUM]; -+ unsigned nbuf_num = 0; -+ unsigned pbuf_num = 0; -+ size_t send_total = 0; -+ size_t send_len; -+ -+ *output_again = false; -+ -+ nbuf_num = mr->ops->dequeue_burst(mr, (void **)nbuf_pkts, UDP_SND_OUTPUT_NUM); -+ if (unlikely(nbuf_num == 0)) { -+ return 0; -+ } -+ if (unlikely(nbuf_num == UDP_SND_OUTPUT_NUM) && -+ mr->ops->count(mr) > 0) { -+ *output_again = true; -+ } -+ -+ for (unsigned i = 0; i < nbuf_num; ++i) { -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(conn=%p, fd=%d, nbuf_pkts[%d]=%p {.p=%p, .tot_len=%u})\n", -+ __FUNCTION__, conn, conn->callback_arg.socket, -+ i, nbuf_pkts[i], nbuf_pkts[i]->p, nbuf_pkts[i]->p->tot_len)); -+ -+ if (get_protocol_stack_group()->latency_start) -+ calculate_lstack_latency(get_protocol_stack()->stack_idx, &(nbuf_pkts[i]->p), 1, GAZELLE_LATENCY_WRITE_LWIP, 0); -+ -+ if (mt != NULL) { -+ pbuf_num += pbuf_clen(nbuf_pkts[i]->p); -+ } -+ -+ /* ip4_frag/ip6_frag would: -+ * 1. split pbuf list and modify tot_len. -+ * 2. free node of pbuf list, except for the pbuf head. -+ */ -+ send_len = nbuf_pkts[i]->p->tot_len; -+ /* This would add header 'UDP_HLEN' ! */ -+ err = netconn_send(conn, nbuf_pkts[i]); -+ if (err != ERR_OK) { -+ LSTACK_LOG(ERR, LSTACK, "netconn_send failed, err %d\n", err); -+ break; -+ } -+ send_total += send_len; -+ } -+ for (unsigned i = 0; i < nbuf_num; ++i) { -+ netbuf_free(nbuf_pkts[i]); -+ } -+ -+ if (mt != NULL) { -+ mem_mbuf_migrate_enqueue(mt, pbuf_num); -+ } -+ -+ return (err == ERR_OK ? send_total : -1); -+} -+ -+static void callback_udp_send(struct rpc_msg *msg) -+{ -+ struct protocol_stack *stack = get_protocol_stack(); -+ struct lwip_sock *sock = msg->args[MSG_ARG_0].p; -+ struct mem_thread *mt = msg->args[MSG_ARG_1].p; -+ bool output_again; -+ -+ if (get_protocol_stack_group()->latency_start) -+ calculate_sock_latency(sock, GAZELLE_LATENCY_WRITE_RPC_MSG); -+ -+ msg->result = stack_udp_output(sock->conn, &output_again, mt); -+ if (output_again) { -+ rpc_async_call(&stack->rpc_queue, msg, RPC_MSG_REUSE | RPC_MSG_RECALL); -+ } -+ -+ return; -+} -+ -+static inline int rpc_call_udp_send(rpc_queue *queue, struct lwip_sock *sock) -+{ -+ struct rpc_msg *msg; -+ -+ if (get_protocol_stack_group()->latency_start) -+ time_stamp_into_rpcmsg(sock); -+ -+ msg = sock_mbox_private_get(sock->conn->sendmbox); -+ msg->args[MSG_ARG_0].p = sock; -+ msg->args[MSG_ARG_1].p = mem_thread_migrate_get(sock->stack_id); -+ -+ rpc_async_call(queue, msg, RPC_MSG_REUSE); -+ return 0; -+} -+ -+static void rtw_stack_udp_send(struct lwip_sock *sock) -+{ -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ rpc_call_udp_send(&stack->rpc_queue, sock); -+} -+ -+static void rtc_stack_udp_send(struct lwip_sock *sock) -+{ -+ bool output_again; -+ do { -+ stack_udp_output(sock->conn, &output_again, NULL); -+ } while (output_again); -+} -+ -+static ssize_t stack_udp_readmsg(struct lwip_sock *sock, struct msghdr *msg, int flags) -+{ -+ struct mbox_ring *mr = &sock->conn->recvmbox->mring; -+ struct pbuf **extcache_list; -+ struct netbuf *nbuf; -+ err_t err = ERR_OK; -+ uint16_t copied_total = 0; -+ -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(sock=%p, msg=%p, size=%"SZT_F", flags=0x%x)\n", -+ __FUNCTION__, sock, msg, len, flags)); -+ -+ if (mr->ops->recv_start_burst(mr, (void **)&nbuf, 1) == 0) { -+ if (unlikely(sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0))) { -+ err = ERR_CONN; -+ } else { -+ err = ERR_WOULDBLOCK; -+ } -+ goto out; -+ } -+ if (unlikely(lwip_netconn_is_err_msg(nbuf, &err))) { -+ API_EVENT(sock->conn, NETCONN_EVT_RCVMINUS, 0); -+ goto out; -+ } -+ -+ if (get_protocol_stack_group()->latency_start) -+ calculate_lstack_latency(sock->stack_id, &nbuf->p, 1, GAZELLE_LATENCY_READ_APP_CALL, sys_now_us()); -+ -+ /* let not free inside by MSG_PEEK */ -+ sock->lastdata.netbuf = nbuf; -+ err = lwip_recvfrom_udp_raw(sock, flags | MSG_PEEK, msg, &copied_total, 0); -+ sock->lastdata.netbuf = NULL; -+ -+ if (get_protocol_stack_group()->latency_start) -+ calculate_lstack_latency(sock->stack_id, &nbuf->p, 1, GAZELLE_LATENCY_READ_LSTACK, 0); -+ -+ if (mr->flags & MBOX_FLAG_PEEK) { -+ extcache_list = NULL; -+ } else { -+ extcache_list = (struct pbuf **)&mr->st_obj; -+ mem_extcache_put_pbuf(nbuf->p, NULL, extcache_list); -+ } -+ -+ mr->app_recvd_len += copied_total; -+ mr->app_queued_num++; -+ if (mr->app_queued_num >= RECV_EXTEND_CACHE_MAX || -+ mr->app_recvd_len >= RECV_EXTEND_CACHE_LEN) { -+ if (extcache_list != NULL) { -+ mem_extcache_flush_pbuf(extcache_list); -+ } -+ mr->ops->recv_finish_burst(mr); -+ mr->app_queued_num = 0; -+ mr->app_recvd_len = 0; -+ } -+ -+ if (err == ERR_OK) { -+ API_EVENT(sock->conn, NETCONN_EVT_RCVMINUS, copied_total); -+ return copied_total; -+ } -+out: -+ set_errno(err_to_errno(err)); -+ return -1; -+} -+ -+ -+static uint16_t rtw_stack_tcp_write_one(const struct lwip_sock *sock, struct mbox_ring *mr, -+ const char *data, uint16_t len, int flags) -+{ -+ struct pbuf **extcache_list = (struct pbuf **)&sock->conn->recvmbox->mring.st_obj; -+ struct pbuf *p; -+ -+ p = mem_extcache_get_pbuf(sock->stack_id, true, extcache_list); -+ if (p == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "mem_extcache_get_pbuf failed\n"); -+ set_errno(ENOMEM); -+ return 0; -+ } -+ -+ write_pbuf(p, data, len, 0); -+ if ((flags & MSG_MORE) == 0) { -+ p->tcp_psh = 1; -+ } -+ -+ if (get_protocol_stack_group()->latency_start) -+ calculate_lstack_latency(sock->stack_id, &p, 1, GAZELLE_LATENCY_WRITE_INTO_RING, 0); -+ -+ mr->ops->enqueue_burst(mr, (void **)&p, 1); -+ mr->app_free_count -= 1; -+ -+ return len; -+} -+ -+static uint16_t rtw_stack_tcp_write_bulk(const struct lwip_sock *sock, struct mbox_ring *mr, -+ const char *data, uint16_t len, int flags) -+{ -+ struct pbuf **extcache_list = (struct pbuf **)&sock->conn->recvmbox->mring.st_obj; -+ unsigned pbuf_num; -+ struct pbuf *pbuf_pkts[TCP_SND_QUEUELEN_MAX]; -+ struct pbuf *tail; -+ -+ pbuf_num = (len + TCP_MSS - 1) / TCP_MSS; -+ pbuf_num = mem_extcache_get_pbuf_bulk(sock->stack_id, pbuf_pkts, pbuf_num, true, extcache_list); -+ if (unlikely(pbuf_num == 0)) { -+ LSTACK_LOG(ERR, LSTACK, "mem_extcache_get_pbuf_bulk failed, pbuf_num %u\n", pbuf_num); -+ set_errno(ENOMEM); -+ return 0; -+ } -+ -+ write_pbuf_bulk(pbuf_pkts, pbuf_num, TCP_MSS, data, len, 0); -+ -+ if (get_protocol_stack_group()->latency_start) -+ calculate_lstack_latency(sock->stack_id, pbuf_pkts, pbuf_num, GAZELLE_LATENCY_WRITE_INTO_RING, 0); -+ -+ tail = pbuf_pkts[pbuf_num - 1]; -+ if ((flags & MSG_MORE) == 0) { -+ tail->tcp_psh = 1; -+ } -+ -+ mr->app_tail_left = TCP_MSS - tail->tot_len; -+ if (mr->app_tail_left > TCP_SND_APPEND_LEN) { -+ pbuf_num--; -+ } else { -+ mr->app_tail_left = 0; -+ tail = NULL; -+ } -+ -+ /* must first enqueue before push_tail !!! */ -+ mr->app_free_count -= pbuf_num; -+ mr->ops->enqueue_burst(mr, (void **)pbuf_pkts, pbuf_num); -+ if (tail != NULL) { -+ mr->ops->push_tail(mr, tail); -+ } -+ -+ return len; -+} -+ -+static inline bool tcp_seg_need_append(uint16_t oversize_left, uint16_t payload_size, uint16_t data_len, int flags) -+{ -+ if (flags & MSG_MORE) { -+ return true; -+ } -+ /* Avoid splitting once write len into 3 segs. */ -+ if ((data_len % payload_size) <= oversize_left) -+ return true; -+ return false; -+} -+static uint16_t rtw_stack_tcp_append(struct mbox_ring *mr, const char *data, uint16_t len, int flags) -+{ -+ struct pbuf *p; -+ bool need_append; -+ uint16_t buf_copy_len; -+ -+ if (mr->app_tail_left == 0) { -+ return 0; -+ } -+ -+ buf_copy_len = 0; -+ p = (struct pbuf *)mr->ops->pop_tail(mr, NULL); -+ if (p != NULL) { -+ need_append = tcp_seg_need_append(mr->app_tail_left, TCP_MSS, len, flags); -+ if (need_append) { -+ buf_copy_len = LWIP_MIN(len, mr->app_tail_left); -+ pbuf_append_take(p, p, data, buf_copy_len, NULL); -+ } -+ mr->ops->enqueue_burst(mr, (void **)&p, 1); -+ mr->app_free_count -= 1; -+ } -+ -+ mr->app_tail_left = 0; -+ -+ return buf_copy_len; -+} -+ -+static ssize_t rtw_stack_tcp_write(struct lwip_sock *sock, const char *data, size_t len, int flags) -+{ -+ struct mbox_ring *mr = &sock->conn->sendmbox->mring; -+ uint16_t buf_copy_len; -+ uint32_t total_copy_len = (uint32_t)len; -+ uint32_t copied_total = 0; -+ -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(sock=%p, data=%p, size=%"SZT_F", flags=0x%x)\n", -+ __FUNCTION__, sock, data, len, flags)); -+ -+ if (unlikely(sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0))) { -+ set_errno(ENOTCONN); -+ return -1; -+ } -+ -+ if (unlikely(mr->app_free_count < 2)) { -+ mr->app_free_count = mr->ops->free_count(mr); -+ if (unlikely(mr->app_free_count < 2)) { -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -+ set_errno(EWOULDBLOCK); -+ return -1; -+ } -+ } -+ -+ copied_total = rtw_stack_tcp_append(mr, data, LWIP_MIN(TCP_MSS, total_copy_len), flags); -+ if (copied_total == total_copy_len) { -+ return copied_total; -+ } -+ -+ if (total_copy_len <= TCP_MSS) { -+ /* write one pbuf */ -+ copied_total += rtw_stack_tcp_write_one(sock, mr, data + copied_total, total_copy_len, flags); -+ } else { -+ if (total_copy_len > mr->app_free_count * TCP_MSS) { -+ mr->app_free_count = mr->ops->free_count(mr); -+ if (unlikely(mr->app_free_count < 2)) { -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -+ set_errno(EWOULDBLOCK); -+ goto out; -+ } -+ if (total_copy_len > mr->app_free_count * TCP_MSS) { -+ total_copy_len = mr->app_free_count * TCP_MSS; -+ } -+ } -+ /* write bulk pbuf */ -+ while (total_copy_len > 0) { -+ buf_copy_len = LWIP_MIN(total_copy_len, TCP_SND_SIZE_MAX); -+ buf_copy_len = rtw_stack_tcp_write_bulk(sock, mr, data + copied_total, buf_copy_len, flags); -+ if (unlikely(buf_copy_len == 0)) { -+ goto out; -+ } -+ copied_total += buf_copy_len; -+ total_copy_len -= buf_copy_len; -+ } -+ } -+ -+out: -+ return copied_total > 0 ? copied_total : -1; -+} -+ -+static struct pbuf *rtw_tcp_output_pop_tail(struct mbox_ring *mr) -+{ -+ void *tail; -+ -+ tail = mr->ops->read_tail(mr); -+ if (tail == NULL) -+ return NULL; -+ -+ if (mr->ops->count(mr) > 0) -+ return NULL; -+ return mr->ops->pop_tail(mr, tail); -+} -+ -+static uint16_t rtw_stack_tcp_output(struct netconn *conn, bool *output_again, struct mem_thread *mt) -+{ -+ struct mbox_ring *mr = &conn->sendmbox->mring; -+ struct pbuf *pbuf_pkts[TCP_SND_OUTPUT_NUM]; -+ uint16_t pbuf_num; -+ -+ *output_again = false; -+ -+ /* must first dequeue before pop_tail !!! */ -+ pbuf_num = mr->ops->dequeue_burst(mr, (void **)pbuf_pkts, TCP_SND_OUTPUT_NUM); -+ -+ if (pbuf_num < TCP_SND_OUTPUT_NUM) { -+ if (pbuf_num == 0 || pbuf_pkts[pbuf_num - 1]->len == TCP_MSS) { -+ pbuf_pkts[pbuf_num] = rtw_tcp_output_pop_tail(mr); -+ if (pbuf_pkts[pbuf_num] != NULL) { -+ pbuf_num++; -+ } -+ } -+ -+ if (unlikely(pbuf_num == 0)) { -+ return 0; -+ } -+ } else { -+ if (mr->ops->count(mr) > 0 || mr->ops->read_tail(mr) != NULL) { -+ *output_again = true; -+ } -+ } -+ -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(conn=%p, fd=%d, pbuf_num=%u)\n", -+ __FUNCTION__, conn, conn->callback_arg.socket, pbuf_num)); -+ -+ if (get_protocol_stack_group()->latency_start) -+ calculate_lstack_latency(get_protocol_stack()->stack_idx, pbuf_pkts, pbuf_num, GAZELLE_LATENCY_WRITE_LWIP, 0); -+ -+ if (mt != NULL) { -+ mem_mbuf_migrate_enqueue(mt, pbuf_num); -+ } -+ -+ if (pbuf_num > 1) { -+ lwip_tcp_tso_merge_seg(conn->pcb.tcp, pbuf_pkts, &pbuf_num); -+ } -+ return lwip_tcp_prepare_seg(conn->pcb.tcp, pbuf_pkts, pbuf_num); -+} -+ -+ -+static uint32_t pbuf_copy_and_free(struct pbuf **left_pbuf, struct pbuf **extcache_list, char *data, uint32_t len) -+{ -+ struct pbuf *q, *t; -+ uint16_t buf_copy_len; -+ uint32_t copied_total = 0; -+ -+ q = *left_pbuf; -+ t = NULL; -+ while (copied_total < len && q != NULL) { -+ buf_copy_len = LWIP_MIN(q->len, len - copied_total); -+ -+ if (buf_copy_len > 0) { -+ MEMCPY(data + copied_total, q->payload, buf_copy_len); -+ copied_total += buf_copy_len; -+ -+ if (buf_copy_len < q->len) { -+ pbuf_remove_header(q, buf_copy_len); -+ break; -+ } else { -+ q->tot_len = q->len = 0; -+ } -+ } -+ -+ t = q; -+ q = q->next; -+ } -+ -+ if (t != NULL && extcache_list != NULL) { -+ t->next = NULL; -+ mem_extcache_put_pbuf(*left_pbuf, t, extcache_list); -+ } -+ *left_pbuf = q; -+ -+ return copied_total; -+} -+ -+static ssize_t stack_tcp_read(struct lwip_sock *sock, char *data, size_t len, int flags, -+ struct sockaddr *from, socklen_t *fromlen) -+{ -+ struct mbox_ring *mr = &sock->conn->recvmbox->mring; -+ struct pbuf **extcache_list; -+ err_t err = ERR_OK; -+ struct pbuf *p; -+ -+ uint32_t buf_copy_len; -+ uint32_t total_copy_len = len; -+ uint32_t copied_total = 0; -+ -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(sock=%p, data=%p, size=%"SZT_F", flags=0x%x)\n", -+ __FUNCTION__, sock, data, len, flags)); -+ -+ if (mr->flags & MBOX_FLAG_PEEK) { -+ extcache_list = NULL; -+ } else { -+ extcache_list = (struct pbuf **)&mr->st_obj; -+ } -+ -+ if (sock->lastdata.pbuf != NULL) { -+ // TODO: support MSG_PEEK -+ buf_copy_len = pbuf_copy_and_free(&sock->lastdata.pbuf, extcache_list, data, total_copy_len); -+ copied_total += buf_copy_len; -+ total_copy_len -= buf_copy_len; -+ mr->app_recvd_len += buf_copy_len; -+ } -+ -+ while (total_copy_len > 0) { -+ if (mr->ops->recv_start_burst(mr, (void **)&p, 1) == 0) { -+ if (unlikely(sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0))) { -+ err = ERR_CONN; -+ } else { -+ err = ERR_WOULDBLOCK; -+ } -+ break; -+ } -+ mr->app_queued_num++; -+ if (unlikely(lwip_netconn_is_err_msg(p, &err))) { -+ API_EVENT(sock->conn, NETCONN_EVT_RCVMINUS, copied_total); -+ break; -+ } -+ -+ if (get_protocol_stack_group()->latency_start) -+ calculate_lstack_latency(sock->stack_id, &p, 1, GAZELLE_LATENCY_READ_APP_CALL, sys_now_us()); -+ -+ sock->lastdata.pbuf = p; -+ // TODO: support MSG_PEEK -+ buf_copy_len = pbuf_copy_and_free(&sock->lastdata.pbuf, extcache_list, data + copied_total, total_copy_len); -+ copied_total += buf_copy_len; -+ total_copy_len -= buf_copy_len; -+ mr->app_recvd_len += buf_copy_len; -+ -+ if (get_protocol_stack_group()->latency_start) -+ calculate_lstack_latency(sock->stack_id, &p, 1, GAZELLE_LATENCY_READ_LSTACK, 0); -+ -+ if (mr->app_queued_num >= RECV_EXTEND_CACHE_MAX || -+ mr->app_recvd_len >= RECV_EXTEND_CACHE_LEN) { -+ if (sock->lastdata.pbuf == NULL) { -+ mr->ops->recv_finish_burst(mr); -+ mr->app_queued_num = 0; -+ } -+ } -+ } -+ -+ if (mr->app_recvd_len >= RECV_EXTEND_CACHE_LEN) { -+ if (extcache_list != NULL) { -+ mem_extcache_flush_pbuf(extcache_list); -+ } -+ mr->app_recvd_len = 0; -+ } -+ -+ lwip_tcp_recv_from(sock->conn, from, fromlen, copied_total); -+ -+ if (copied_total > 0) { -+ API_EVENT(sock->conn, NETCONN_EVT_RCVMINUS, copied_total); -+ return copied_total; -+ } -+ -+ set_errno(err_to_errno(err)); -+ if (err == ERR_CLSD) { -+ return 0; -+ } -+ return -1; -+} -+ -+ -+#define RECVD_UNCOMMITTED(msg) ((msg)->args[MSG_ARG_2].ul) -+#define RECVD_CURR_SEQ(msg) ((msg)->args[MSG_ARG_3].ul) -+#define RECVD_LAST_SEQ(msg) ((msg)->args[MSG_ARG_4].ul) -+ -+static inline bool rpc_commit_tcp_recvd(struct rpc_msg *recvmsg, unsigned long threshold) -+{ -+ if (RECVD_UNCOMMITTED(recvmsg) >= threshold) { -+ __atomic_add_fetch(&RECVD_CURR_SEQ(recvmsg), RECVD_UNCOMMITTED(recvmsg), __ATOMIC_RELEASE); -+ RECVD_UNCOMMITTED(recvmsg) = 0; -+ return true; -+ } -+ return false; -+} -+ -+#if TCP_RECV_AND_UPDATE -+static inline unsigned long rpc_read_tcp_recvd(struct rpc_msg *recvmsg) -+{ -+ unsigned long curr_recvd_seq; -+ unsigned long recvd; -+ -+ curr_recvd_seq = __atomic_load_n(&RECVD_CURR_SEQ(recvmsg), __ATOMIC_ACQUIRE); -+ recvd = curr_recvd_seq - RECVD_LAST_SEQ(recvmsg); -+ if (recvd > 0) { -+ /* update last recvd seq */ -+ RECVD_LAST_SEQ(recvmsg) = curr_recvd_seq; -+ } -+ return recvd; -+} -+ -+static void callback_tcp_recvd(struct rpc_msg *recvmsg) -+{ -+ struct lwip_sock *sock = recvmsg->args[MSG_ARG_0].p; -+ unsigned long recvd; -+ -+ recvd = rpc_read_tcp_recvd(recvmsg); -+ lwip_tcp_recvd(sock->conn, recvd, 0); -+ -+ recvmsg->result = recvd; -+ return; -+} -+#endif /* TCP_RECV_AND_UPDATE */ -+ -+static inline int rpc_call_tcp_recvd(rpc_queue *queue, struct lwip_sock *sock, size_t recvd, int flags) -+{ -+ struct rpc_msg *recvmsg; -+ -+ recvmsg = sock_mbox_private_get(sock->conn->recvmbox); -+ recvmsg->args[MSG_ARG_0].p = sock; -+ recvmsg->result = 0; -+ -+ RECVD_UNCOMMITTED(recvmsg) += recvd; -+ if (rpc_commit_tcp_recvd(recvmsg, TCP_WND_UPDATE_THRESHOLD << 1)) { -+ rpc_async_call(queue, recvmsg, RPC_MSG_REUSE); -+ } -+ -+ return 0; -+} -+ -+static void rtw_stack_tcp_recvd(struct lwip_sock *sock, ssize_t recvd, int flags) -+{ -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ -+ if (recvd <= 0 || flags & MSG_PEEK) { -+ return; -+ } -+ rpc_call_tcp_recvd(&stack->rpc_queue, sock, recvd, flags); -+} -+ -+static void rtc_stack_tcp_recvd(struct lwip_sock *sock, ssize_t recvd, int flags) -+{ -+ if (recvd <= 0 || flags & MSG_PEEK) { -+ return; -+ } -+ lwip_tcp_recvd(sock->conn, recvd, flags); -+} -+ -+static void callback_tcp_send(struct rpc_msg *sendmsg) -+{ -+ struct protocol_stack *stack = get_protocol_stack(); -+ struct lwip_sock *sock = sendmsg->args[MSG_ARG_0].p; -+ struct mem_thread *mt = sendmsg->args[MSG_ARG_1].p; -+ bool output_again; -+ err_t err; -+ -+ if (unlikely(sock->conn->pcb.tcp == NULL)) -+ return; -+ -+ if (get_protocol_stack_group()->latency_start) -+ calculate_sock_latency(sock, GAZELLE_LATENCY_WRITE_RPC_MSG); -+ -+ do { -+ if (!lwip_tcp_allow_send(sock->conn->pcb.tcp)) { -+ rpc_async_call(&stack->rpc_queue, sendmsg, RPC_MSG_REUSE | RPC_MSG_RECALL); -+ break; -+ } -+ sendmsg->result += rtw_stack_tcp_output(sock->conn, &output_again, mt); -+ } while (output_again); -+ err = tcp_output(sock->conn->pcb.tcp); -+ if (unlikely(err != ERR_OK)) { -+ LSTACK_LOG(ERR, LSTACK, "tcp_output failed, sock %p, err %u\n", sock, err); -+ } -+ -+#if TCP_RECV_AND_UPDATE -+ struct rpc_msg *recvmsg; -+ if (RECVD_UNCOMMITTED(sendmsg)) { -+ RECVD_UNCOMMITTED(sendmsg) = 0; -+ recvmsg = sock_mbox_private_get(sock->conn->recvmbox); -+ callback_tcp_recvd(recvmsg); -+ } -+#endif /* TCP_RECV_AND_UPDATE */ -+ -+ return; -+} -+ -+static inline int rpc_call_tcp_send(rpc_queue *queue, struct lwip_sock *sock) -+{ -+ struct rpc_msg *sendmsg; -+ -+ if (get_protocol_stack_group()->latency_start) -+ time_stamp_into_rpcmsg(sock); -+ -+ sendmsg = sock_mbox_private_get(sock->conn->sendmbox); -+ sendmsg->result = 0; -+ sendmsg->args[MSG_ARG_0].p = sock; -+ sendmsg->args[MSG_ARG_1].p = mem_thread_migrate_get(sock->stack_id); -+ -+#if TCP_RECV_AND_UPDATE -+ struct rpc_msg *recvmsg; -+ recvmsg = sock_mbox_private_get(sock->conn->recvmbox); -+ RECVD_UNCOMMITTED(sendmsg) = rpc_commit_tcp_recvd(recvmsg, TCP_WND_UPDATE_THRESHOLD); -+#endif /* TCP_RECV_AND_UPDATE */ -+ -+ rpc_async_call(queue, sendmsg, RPC_MSG_REUSE); -+ return 0; -+} -+ -+static void rtw_stack_tcp_send(struct lwip_sock *sock) -+{ -+ struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -+ rpc_call_tcp_send(&stack->rpc_queue, sock); -+} -+ -+ -+static ssize_t rtc_stack_tcp_write(struct lwip_sock *sock, const char *data, size_t len, int flags) -+{ -+ struct tcp_pcb *pcb = sock->conn->pcb.tcp; -+ err_t err = ERR_OK; -+ int write_flags, write_more; -+ -+ uint16_t buf_copy_len; -+ uint32_t total_copy_len; -+ uint32_t copied_total = 0; -+ -+ write_more = TCP_WRITE_FLAG_MORE; -+ write_flags = NETCONN_COPY | -+ ((flags & MSG_MORE) ? NETCONN_MORE : 0) | -+ ((flags & MSG_DONTWAIT) ? NETCONN_DONTBLOCK : 0); -+ -+ if (unlikely(sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0))) { -+ set_errno(ENOTCONN); -+ return -1; -+ } -+ -+ total_copy_len = LWIP_MIN((uint32_t)len, (uint32_t)pcb->snd_buf); -+ if (unlikely(total_copy_len == 0)) { -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -+ set_errno(EWOULDBLOCK); -+ return -1; -+ } -+ -+ while (total_copy_len > 0) { -+ if (total_copy_len <= TCP_SND_SIZE_MAX) { -+ buf_copy_len = total_copy_len; -+ write_more = 0; -+ } else { -+ buf_copy_len = TCP_SND_SIZE_MAX; -+ } -+ -+ err = tcp_write(pcb, data + copied_total, buf_copy_len, write_flags | write_more); -+ if (err != ERR_OK) { -+ LSTACK_LOG(ERR, LSTACK, "tcp_write failed, errno %d\n", err_to_errno(err)); -+ break; -+ } -+ total_copy_len -= buf_copy_len; -+ copied_total += buf_copy_len; -+ } -+ -+ if (copied_total > 0) { -+ return copied_total; -+ } -+ set_errno(err_to_errno(err)); -+ return -1; -+} -+ -+static void rtc_stack_tcp_send(struct lwip_sock *sock) -+{ -+ tcp_output(sock->conn->pcb.tcp); -+} -+ -+ -+ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, -+ struct sockaddr *from, socklen_t *fromlen) -+{ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ ssize_t recvd; -+ struct iovec vec; -+ struct msghdr msg; -+ -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(%d, mem=%p, size=%"SZT_F", flags=0x%x)\n", -+ __FUNCTION__, fd, mem, len, flags)); -+ -+ if (unlikely(mem == NULL || len <= 0)) { -+ set_errno(EINVAL); -+ return -1; -+ } -+ -+ if (unlikely(!sock->affinity_numa)) { -+ thread_bind_stack(sock->stack_id); -+ sock->affinity_numa = true; -+ } -+ -+ switch (NETCONN_TYPE(sock->conn)) { -+ case NETCONN_TCP: -+ /* TODO: support MSG_WAITALL */ -+ recvd = ioops.stack_tcp_read(sock, mem, len, flags, from, fromlen); -+ if (recvd < 0 && errno == EWOULDBLOCK) { -+ if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { -+ recvd = ioops.stack_tcp_read(sock, mem, len, flags, from, fromlen); -+ } -+ } -+#if TCP_RECV_AND_UPDATE -+ if (recvd > 0) { -+ ioops.stack_tcp_recvd(sock, recvd, flags); -+ } -+#endif /* TCP_RECV_AND_UPDATE */ -+ break; -+ case NETCONN_UDP: -+ vec.iov_base = mem; -+ vec.iov_len = len; -+ msg.msg_control = NULL; -+ msg.msg_controllen = 0; -+ msg.msg_flags = 0; -+ msg.msg_iov = &vec; -+ msg.msg_iovlen = 1; -+ msg.msg_name = from; -+ msg.msg_namelen = (fromlen ? *fromlen : 0); -+ recvd = ioops.stack_udp_readmsg(sock, &msg, flags); -+ if (recvd < 0 && errno == EWOULDBLOCK) { -+ if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { -+ recvd = ioops.stack_udp_readmsg(sock, &msg, flags); -+ } -+ } -+ if (recvd > 0 && fromlen != NULL) { -+ *fromlen = msg.msg_namelen; -+ } -+ break; -+ default: -+ recvd = -1; -+ break; -+ } -+ -+ return recvd; -+} -+ -+ssize_t sockio_recvmsg(int fd, struct msghdr *msg, int flags) -+{ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ ssize_t ret, recvd = 0; -+ -+ ret = lwip_recvmsg_check(NULL, msg, flags); -+ if (unlikely(ret <= 0)) { -+ return ret; -+ } -+ -+ if (unlikely(!sock->affinity_numa)) { -+ thread_bind_stack(sock->stack_id); -+ sock->affinity_numa = true; -+ } -+ -+ switch (NETCONN_TYPE(sock->conn)) { -+ case NETCONN_TCP: -+ for (int i = 0; i < msg->msg_iovlen; ++i) { -+ ret = sockio_recvfrom(fd, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags, NULL, NULL); -+ if (ret <= 0) { -+ if (recvd == 0) -+ recvd = ret; -+ break; -+ } -+ recvd += ret; -+ } -+ break; -+ case NETCONN_UDP: -+ recvd = ioops.stack_udp_readmsg(sock, msg, flags); -+ if (recvd < 0 && errno == EWOULDBLOCK) { -+ if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { -+ recvd = ioops.stack_udp_readmsg(sock, msg, flags); -+ } -+ } -+ break; -+ default: -+ recvd = -1; -+ break; -+ } -+ -+ return recvd; -+} -+ -+ssize_t sockio_sendto(int fd, const void *mem, size_t len, int flags, -+ const struct sockaddr *to, socklen_t tolen) -+{ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ ssize_t ret; -+ -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(%d, mem=%p, size=%"SZT_F", flags=0x%x)\n", -+ __FUNCTION__, fd, mem, len, flags)); -+ -+ if (unlikely(mem == NULL || len <= 0)) { -+ set_errno(EINVAL); -+ return -1; -+ } -+ -+ if (unlikely(!sock->affinity_numa)) { -+ thread_bind_stack(sock->stack_id); -+ sock->affinity_numa = true; -+ } -+ -+ switch (NETCONN_TYPE(sock->conn)) { -+ case NETCONN_TCP: -+ ret = ioops.stack_tcp_write(sock, mem, len, flags); -+ if (ret < 0) { -+ if (errno == EWOULDBLOCK) { -+ sock_event_wait(sock, true); -+ } -+ } else { -+ ioops.stack_tcp_send(sock); -+ } -+ break; -+ case NETCONN_UDP: -+ ret = ioops.stack_udp_write(sock, mem, len, flags, to, tolen); -+ if (ret < 0) { -+ if (errno == EWOULDBLOCK) { -+ sock_event_wait(sock, true); -+ } -+ } else { -+ ioops.stack_udp_send(sock); -+ } -+ break; -+ default: -+ ret = -1; -+ break; -+ } -+ -+ return ret; -+} -+ -+ssize_t sockio_sendmsg(int fd, const struct msghdr *msg, int flags) -+{ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ ssize_t ret = -1; -+ size_t written = 0; -+ int write_more = MSG_MORE; -+ int i; -+ -+ ret = lwip_sendmsg_check(sock, msg, flags); -+ if (unlikely(ret <= 0)) { -+ return ret; -+ } -+ -+ if (unlikely(!sock->affinity_numa)) { -+ thread_bind_stack(sock->stack_id); -+ sock->affinity_numa = true; -+ } -+ -+ switch (NETCONN_TYPE(sock->conn)) { -+ case NETCONN_TCP: -+ for (i = 0; i < msg->msg_iovlen; ++i) { -+ if (i == msg->msg_iovlen - 1) { -+ write_more = 0; -+ } -+ ret = ioops.stack_tcp_write(sock, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags | write_more); -+ if (ret < 0) { -+ if (errno == EWOULDBLOCK) { -+ sock_event_wait(sock, true); -+ } -+ break; -+ } -+ written += ret; -+ } -+ if (written > 0) { -+ ioops.stack_tcp_send(sock); -+ } -+ break; -+ case NETCONN_UDP: -+ for (i = 0; i < msg->msg_iovlen; ++i) { -+ if (i == msg->msg_iovlen - 1) { -+ write_more = 0; -+ } -+ ret = ioops.stack_udp_write(sock, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags | write_more, NULL, 0); -+ if (ret < 0) { -+ if (errno == EWOULDBLOCK) { -+ sock_event_wait(sock, true); -+ } -+ break; -+ } -+ written += ret; -+ } -+ if (written > 0) { -+ ioops.stack_udp_send(sock); -+ } -+ break; -+ default: -+ written = -1; -+ break; -+ } -+ -+ return written > 0 ? written : ret; -+} -+ -+ssize_t sockio_read(int fd, void *mem, size_t len) -+{ -+ return sockio_recvfrom(fd, mem, len, 0, NULL, NULL); -+} -+ -+ssize_t sockio_write(int fd, const void *mem, size_t len) -+{ -+ return sockio_sendto(fd, mem, len, 0, NULL, 0); -+} -+ -+ssize_t sockio_recv(int fd, void *mem, size_t len, int flags) -+{ -+ return sockio_recvfrom(fd, mem, len, flags, NULL, NULL); -+} -+ -+ssize_t sockio_send(int fd, const void *mem, size_t len, int flags) -+{ -+ return sockio_sendto(fd, mem, len, flags, NULL, 0); -+} -+ -+ssize_t sockio_readv(int fd, const struct iovec *iov, int iovcnt) -+{ -+ struct msghdr msg; -+ -+ msg.msg_name = NULL; -+ msg.msg_namelen = 0; -+ msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov); -+ msg.msg_iovlen = iovcnt; -+ msg.msg_control = NULL; -+ msg.msg_controllen = 0; -+ msg.msg_flags = 0; -+ -+ return sockio_recvmsg(fd, &msg, 0); -+} -+ -+ssize_t sockio_writev(int fd, const struct iovec *iov, int iovcnt) -+{ -+ struct msghdr msg; -+ -+ msg.msg_name = NULL; -+ msg.msg_namelen = 0; -+ msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov); -+ msg.msg_iovlen = iovcnt; -+ msg.msg_control = NULL; -+ msg.msg_controllen = 0; -+ msg.msg_flags = 0; -+ -+ return sockio_sendmsg(fd, &msg, 0); -+} -+ -+void sockio_ops_init(void) -+{ -+ struct sockio_ops *ops = &ioops; -+ -+ ops->stack_udp_write = stack_udp_write; -+ ops->stack_udp_readmsg = stack_udp_readmsg; -+ ops->stack_tcp_read = stack_tcp_read; -+ -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ ops->stack_udp_send = rtc_stack_udp_send; -+ ops->stack_tcp_write = rtc_stack_tcp_write; -+ ops->stack_tcp_send = rtc_stack_tcp_send; -+ ops->stack_tcp_recvd = rtc_stack_tcp_recvd; -+ } else { -+ ops->stack_udp_send = rtw_stack_udp_send; -+ ops->stack_tcp_write = rtw_stack_tcp_write; -+ ops->stack_tcp_send = rtw_stack_tcp_send; -+ ops->stack_tcp_recvd = rtw_stack_tcp_recvd; -+ } -+} -+ -+static int sockio_mbox_init(struct lwip_sock *sock) -+{ -+ int ret; -+ sys_mbox_t sendmbox = sock->conn->sendmbox; -+ sys_mbox_t recvmbox = sock->conn->recvmbox; -+ -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ return 0; -+ } -+ -+ switch (NETCONN_TYPE(sock->conn)) { -+ case NETCONN_TCP: -+ ret = sock_mbox_private_init(sendmbox, callback_tcp_send); -+#if TCP_RECV_AND_UPDATE -+ if (sys_mbox_valid(&recvmbox)) { -+ ret |= sock_mbox_private_init(recvmbox, callback_tcp_recvd); -+ } -+#endif /* TCP_RECV_AND_UPDATE */ -+ break; -+ case NETCONN_UDP: -+ ret = sock_mbox_private_init(sendmbox, callback_udp_send); -+ break; -+ default: -+ ret = 0; -+ } -+ -+ if (ret != 0) { -+ sock_mbox_private_free(&sendmbox->mring); -+ if (sys_mbox_valid(&recvmbox)) { -+ sock_mbox_private_free(&recvmbox->mring); -+ } -+ } -+ return ret; -+} -+ -+bool sockio_mbox_pending(const struct lwip_sock *sock) -+{ -+ struct rpc_msg *msg; -+ -+ if (POSIX_IS_CLOSED(sock)) -+ return false; -+ -+ if (sys_mbox_valid(&sock->conn->sendmbox)) { -+ msg = sock_mbox_private_get(sock->conn->sendmbox); -+ if (msg != NULL && !lockless_queue_node_is_poped(&msg->queue_node)) { -+ return true; -+ } -+ } -+ if (sys_mbox_valid(&sock->conn->recvmbox)) { -+ msg = sock_mbox_private_get(sock->conn->recvmbox); -+ if (msg != NULL && !lockless_queue_node_is_poped(&msg->queue_node)) { -+ return true; -+ } -+ } -+ -+ return false; -+} -+ -+int do_lwip_init_sock(int fd) -+{ -+ int ret; -+ struct protocol_stack *stack = get_protocol_stack(); -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock == NULL) { -+ return -1; -+ } -+ -+ sock->type = 0; -+ sock->listen_next = NULL; -+ sock->stack_id = stack->stack_idx; -+ -+ /* RTC affinity by stack_setup_app_thread() */ -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ sock->affinity_numa = true; -+ } else { -+ sock->affinity_numa = false; -+ } -+ -+ sock->sk_wait = NULL; -+ ret = sock_event_init(&sock->sk_event); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "sock_event_init failed\n"); -+ return -1; -+ } -+ -+ ret = sockio_mbox_init(sock); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "sockio_mbox_init failed\n"); -+ return -1; -+ } -+ -+ get_protocol_stack_by_id(sock->stack_id)->conn_num++; -+ return 0; -+} -+ -+void do_lwip_clean_sock(int fd) -+{ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (POSIX_IS_CLOSED(sock)) { -+ return; -+ } -+ -+ sock_event_free(&sock->sk_event, sock->sk_wait); -+ sock->sk_wait = NULL; -+ -+ sock->listen_next = NULL; -+ -+ get_protocol_stack_by_id(sock->stack_id)->conn_num--; -+ sock->stack_id = -1; -+} -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -new file mode 100644 -index 0000000..8f01f31 ---- /dev/null -+++ b/src/lstack/core/lstack_mempool.c -@@ -0,0 +1,1014 @@ -+/* -+* 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 -+ -+#include -+#include -+ -+#include "lstack_mempool.h" -+#include "lstack_log.h" -+#include "lstack_cfg.h" -+#include "common/dpdk_common.h" -+#include "lstack_dpdk.h" -+#include "lstack_protocol_stack.h" -+ -+#define MEM_THREAD_MANAGER_TIMEOUT 1 -+#define MEM_THREAD_MANAGER_MAX 64 -+ -+struct mem_thread_manager { -+ struct list_node mt_work_list; -+ struct list_node mt_free_list; -+ rte_spinlock_t list_lock; -+}; -+ -+struct mem_thread_group { -+ int tid; -+ pthread_t thread; -+ struct list_node mt_node; -+ struct mem_thread mt_array[PROTOCOL_STACK_MAX]; -+}; -+ -+static struct mem_stack g_mem_stack_group[PROTOCOL_STACK_MAX] = {0}; -+static PER_THREAD struct mem_thread_group *g_mem_thread_group = NULL; -+static struct mem_thread_manager g_mem_thread_manager = {0}; -+ -+static __rte_always_inline -+struct mem_stack *mem_stack_get(int stack_id) -+{ -+ return &g_mem_stack_group[stack_id]; -+} -+ -+struct rte_mempool *mem_get_mbuf_pool(int stack_id) -+{ -+ return g_mem_stack_group[stack_id].mbuf_pool; -+} -+ -+struct rte_mempool *mem_get_rpc_pool(int stack_id) -+{ -+ return g_mem_stack_group[stack_id].rpc_pool; -+} -+ -+static void mem_thread_manager_add_work(struct mem_thread_group *mt_group) -+{ -+ rte_spinlock_lock(&g_mem_thread_manager.list_lock); -+ list_add_node(&mt_group->mt_node, &g_mem_thread_manager.mt_work_list); -+ rte_spinlock_unlock(&g_mem_thread_manager.list_lock); -+} -+ -+static inline bool mem_thread_group_exist(const struct mem_thread_group *mt_group) -+{ -+ if (pthread_tryjoin_np(mt_group->thread, NULL) == 0) -+ return false; -+ return true; -+} -+ -+static void mem_thread_group_free(struct mem_thread_group *mt_group) -+{ -+ struct mem_thread *mt; -+ int stack_id; -+ -+ for (stack_id = 0; stack_id < PROTOCOL_STACK_MAX; stack_id++) { -+ mt = &mt_group->mt_array[stack_id]; -+ mem_thread_cache_free(mt); -+ } -+ free(mt_group); -+ return; -+} -+ -+static int mem_thread_group_init(int stack_id) -+{ -+ struct mem_thread *mt; -+ -+ if (rte_lcore_id() < RTE_MAX_LCORE) { -+ LSTACK_LOG(ERR, LSTACK, "tid %d, lcore_id %u is invalid\n", rte_gettid(), rte_lcore_id()); -+ return -1; -+ } -+ -+ if (g_mem_thread_group == NULL) { -+ g_mem_thread_group = (struct mem_thread_group *)calloc(1, sizeof(struct mem_thread_group)); -+ if (g_mem_thread_group == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "alloc mem_thread_group failed, stack_id %d\n", stack_id); -+ return -1; -+ } -+ g_mem_thread_group->tid = rte_gettid(); -+ g_mem_thread_group->thread = pthread_self(); -+ list_init_node(&g_mem_thread_group->mt_node); -+ mem_thread_manager_add_work(g_mem_thread_group); -+ } -+ -+ mt = &g_mem_thread_group->mt_array[stack_id]; -+ if (mem_thread_cache_init(mt) != 0) { -+ LSTACK_LOG(ERR, LSTACK, "mem_thread_cache_init failed, stack_id %d\n", stack_id); -+ return -1; -+ } -+ -+ return 0; -+} -+ -+static inline struct mem_thread *mem_thread_group_get(int stack_id) -+{ -+ struct mem_thread *mt; -+ -+ if (likely(g_mem_thread_group != NULL)) { -+ mt = &g_mem_thread_group->mt_array[stack_id]; -+ if (likely(mt->mbuf_cache != NULL)) -+ return mt; -+ } -+ -+ if (mem_thread_group_init(stack_id) != 0) { -+ LSTACK_LOG(ERR, LSTACK, "mem_thread_group_init failed, stack_id %d\n", stack_id); -+ return NULL; -+ } -+ mt = &g_mem_thread_group->mt_array[stack_id]; -+ return mt; -+} -+ -+static void *mem_thread_manager_thread(void *arg) -+{ -+ struct list_node *node, *next; -+ struct mem_thread_group *mt_group; -+ unsigned count = 0; -+ -+ rte_spinlock_init(&g_mem_thread_manager.list_lock); -+ list_init_head(&g_mem_thread_manager.mt_work_list); -+ list_init_head(&g_mem_thread_manager.mt_free_list); -+ -+ while(true) { -+ sleep(MEM_THREAD_MANAGER_TIMEOUT); -+ -+ rte_spinlock_lock(&g_mem_thread_manager.list_lock); -+ -+ list_for_each_node(node, next, &g_mem_thread_manager.mt_free_list) { -+ mt_group = container_of(node, struct mem_thread_group, mt_node); -+ list_del_node(node); -+ mem_thread_group_free(mt_group); -+ } -+ -+ list_for_each_node(node, next, &g_mem_thread_manager.mt_work_list) { -+ count++; -+ if (count > MEM_THREAD_MANAGER_MAX) { -+ /* move list head after the current node, -+ * and start traversing from this node next time */ -+ list_del_node(&g_mem_thread_manager.mt_work_list); -+ list_add_node(&g_mem_thread_manager.mt_work_list, node); -+ break; -+ } -+ -+ mt_group = container_of(node, struct mem_thread_group, mt_node); -+ if (mem_thread_group_exist(mt_group)) { -+ continue; -+ } -+ list_del_node(node); -+ list_add_node(node, &g_mem_thread_manager.mt_free_list); -+ } -+ -+ rte_spinlock_unlock(&g_mem_thread_manager.list_lock); -+ } -+ -+ return NULL; -+} -+ -+int mem_thread_manager_init(void) -+{ -+ return thread_create("gzmempool", 0, mem_thread_manager_thread, NULL); -+} -+ -+static __rte_always_inline -+struct mem_thread *mem_thread_get(int stack_id) -+{ -+ /* stack thread uses mbufpool_cache instead of buf_cache */ -+ if (get_protocol_stack() != NULL) -+ return NULL; -+ -+#if MEMP_DEBUG -+ if (RTE_PER_LCORE(_lcore_id) < RTE_MAX_LCORE) { -+ LWIP_DEBUGF(MEMP_DEBUG | LWIPGZ_LOG_FATAL, ("tid %d has invalid rte_lcore_id %u !\n", -+ rte_gettid(), RTE_PER_LCORE(_lcore_id))); -+ return NULL; -+ } -+#endif /* MEMP_DEBUG */ -+ -+ return mem_thread_group_get(stack_id); -+} -+ -+struct mem_obj_ops { -+ void (*init)(struct rte_mempool *mp, void *arg, void *obj, unsigned obj_idx); -+ unsigned (*get_stack_id)(const void *obj); -+ struct rte_mempool * (*get_pool)(const void *obj); -+}; -+ -+static __rte_always_inline -+void rpc_obj_init(struct rte_mempool *mp, void *arg, void *obj, unsigned obj_idx) -+{ -+ int stack_id = *(int *)arg; -+ struct rpc_msg *msg = obj; -+ msg->stack_id = stack_id; -+} -+ -+static __rte_always_inline -+unsigned rpc_obj_get_stack_id(const void *obj) -+{ -+ return ((const struct rpc_msg *)obj)->stack_id; -+} -+ -+static __rte_always_inline -+struct rte_mempool *rpc_obj_get_pool(const void *obj) -+{ -+ int stack_id = rpc_obj_get_stack_id(obj); -+ return mem_get_rpc_pool(stack_id); -+} -+ -+static __rte_always_inline -+void mbuf_obj_init(struct rte_mempool *mp, void *arg, void *obj, unsigned obj_idx) -+{ -+ int stack_id = *(int *)arg; -+ struct rte_mbuf *mbuf = obj; -+ struct mbuf_private *priv = mbuf_to_private(mbuf); -+ priv->stack_id = stack_id; -+} -+ -+static __rte_always_inline -+unsigned mbuf_obj_get_stack_id(const void *obj) -+{ -+ return mbuf_to_private((const struct rte_mbuf *)obj)->stack_id; -+} -+ -+static __rte_always_inline -+struct rte_mempool *mbuf_obj_get_pool(const void *obj) -+{ -+ int stack_id = mbuf_obj_get_stack_id(obj); -+ return mem_get_mbuf_pool(stack_id); -+} -+ -+static const struct mem_obj_ops rpc_obj_ops = { -+ .init = rpc_obj_init, -+ .get_stack_id = rpc_obj_get_stack_id, -+ .get_pool = rpc_obj_get_pool, -+}; -+ -+static const struct mem_obj_ops mbuf_obj_ops = { -+ .init = mbuf_obj_init, -+ .get_stack_id = mbuf_obj_get_stack_id, -+ .get_pool = mbuf_obj_get_pool, -+}; -+ -+struct mempool_ops { -+ struct rte_mempool *(*create)(const char *name, unsigned n, -+ unsigned cache_size, unsigned priv_size, unsigned data_room_size, int socket_id); -+ void (*put_bulk)(struct rte_mempool *pool, void *const *obj_table, unsigned n); -+ unsigned (*get_bulk)(struct rte_mempool *pool, void **obj_table, unsigned n); -+}; -+ -+static __rte_always_inline -+struct rte_mempool *mempool_create(const char *name, unsigned n, -+ unsigned cache_size, unsigned priv_size, unsigned data_room_size, int socket_id) -+{ -+ struct rte_mempool *pool; -+ -+ LSTACK_LOG(INFO, LSTACK, "name %s, n %u, cache_size %u, priv_size %u, data_room_size %u, socket_id %d, ops_name %s\n", -+ name, n, cache_size, priv_size, data_room_size, socket_id, MEMPOOL_OPS_NAME); -+ -+ pool = rte_mempool_create(name, n, data_room_size, cache_size, priv_size, NULL, NULL, NULL, NULL, socket_id, 0); -+ if (pool != NULL) -+ rte_mempool_set_ops_byname(pool, MEMPOOL_OPS_NAME, NULL); -+ return pool; -+} -+ -+static __rte_always_inline -+void mempool_put_bulk(struct rte_mempool *pool, void *const *obj_table, unsigned n) -+{ -+ rte_mempool_put_bulk(pool, obj_table, n); -+} -+ -+static __rte_always_inline -+unsigned mempool_get_bulk(struct rte_mempool *pool, void **obj_table, unsigned n) -+{ -+ return rte_mempool_get_bulk(pool, obj_table, n) != 0 ? 0 : n; -+} -+ -+static __rte_always_inline -+struct rte_mempool *pkgmbuf_create(const char *name, unsigned n, -+ unsigned cache_size, unsigned priv_size, unsigned data_room_size, int socket_id) -+{ -+ LSTACK_LOG(INFO, LSTACK, "name %s, n %u, cache_size %u, priv_size %u, data_room_size %u, socket_id %d, ops_name %s\n", -+ name, n, cache_size, priv_size, data_room_size, socket_id, MEMPOOL_OPS_NAME); -+ -+ return rte_pktmbuf_pool_create_by_ops(name, n, cache_size, priv_size, data_room_size, socket_id, MEMPOOL_OPS_NAME); -+} -+ -+static __rte_always_inline -+void pkgmbuf_put_bulk(struct rte_mempool *pool, void *const *obj_table, unsigned n) -+{ -+ // rte_pktmbuf_free_bulk((struct rte_mbuf **)obj_table, n); -+ rte_mempool_put_bulk(pool, obj_table, n); -+} -+ -+static __rte_always_inline -+unsigned pkgmbuf_get_bulk(struct rte_mempool *pool, void **obj_table, unsigned n) -+{ -+ return rte_pktmbuf_alloc_bulk(pool, (struct rte_mbuf **)obj_table, n) != 0 ? 0 : n; -+} -+ -+static const struct mempool_ops mem_mp_ops = { -+ .create = mempool_create, -+ .put_bulk = mempool_put_bulk, -+ .get_bulk = mempool_get_bulk, -+}; -+ -+static const struct mempool_ops mbuf_mp_ops = { -+ .create = pkgmbuf_create, -+ .put_bulk = pkgmbuf_put_bulk, -+ .get_bulk = pkgmbuf_get_bulk, -+}; -+ -+ -+static struct rte_mempool *mbuf_pool_create(int stack_id) -+{ -+ struct cfg_params *cfg_params = get_global_cfg_params(); -+ char name[RTE_MEMPOOL_NAMESIZE]; -+ struct rte_mempool *pool; -+ uint32_t total_conn_mbufs, total_nic_mbufs, total_mbufs; -+ uint16_t private_size; -+ -+ total_conn_mbufs = cfg_params->mbuf_count_per_conn * cfg_params->tcp_conn_count; -+ total_nic_mbufs = cfg_params->rxqueue_size + cfg_params->txqueue_size; -+ -+ total_mbufs = (total_conn_mbufs / cfg_params->num_queue) + total_nic_mbufs + MBUFPOOL_RESERVE_NUM; -+ /* limit mbuf max num based on the dpdk capability */ -+ if (total_mbufs > MBUFPOOL_MAX_NUM) { -+ LSTACK_LOG(ERR, LSTACK, "total_mbufs %u out of the dpdk mbuf_pool range\n", total_mbufs); -+ return NULL; -+ } -+ -+ SYS_FORMAT_NAME(name, RTE_MEMPOOL_NAMESIZE, "%s_%hu", "mbuf_pool", stack_id); -+ private_size = RTE_ALIGN(sizeof(struct mbuf_private) + 24, RTE_CACHE_LINE_SIZE); -+ -+ pool = mbuf_mp_ops.create(name, total_mbufs, MBUFPOOL_CACHE_NUM, private_size, MBUF_DATA_SIZE, rte_socket_id()); -+ if (pool == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "rte_pktmbuf_pool_create %s failed, rte_errno %d\n", name, rte_errno); -+ return NULL; -+ } -+ -+ return pool; -+} -+ -+static struct rte_mempool *rpc_pool_create(int stack_id) -+{ -+ char name [RTE_MEMPOOL_NAMESIZE]; -+ struct rte_mempool *pool; -+ uint32_t total_bufs = get_global_cfg_params()->rpc_msg_max; -+ -+ SYS_FORMAT_NAME(name, RTE_MEMPOOL_NAMESIZE, "%s_%hu", "rpc_pool", stack_id); -+ -+ pool = mem_mp_ops.create(name, total_bufs, MEMPOOL_CACHE_NUM, 0, sizeof(struct rpc_msg), rte_socket_id()); -+ if (pool == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "rte_mempool_create %s failed, rte_errno %d\n", name, rte_errno); -+ } -+ -+ return pool; -+} -+ -+void mem_stack_pool_free(int stack_id) -+{ -+ struct mem_stack *ms = mem_stack_get(stack_id); -+ -+ if (ms->mbuf_pool != NULL) { -+ rte_mempool_free(ms->mbuf_pool); -+ ms->mbuf_pool = NULL; -+ } -+ if (ms->rpc_pool != NULL) { -+ rte_mempool_free(ms->rpc_pool); -+ ms->rpc_pool = NULL; -+ } -+} -+ -+int mem_stack_pool_init(int stack_id) -+{ -+ struct mem_stack *ms = mem_stack_get(stack_id); -+ -+ ms->mbuf_pool = mbuf_pool_create(stack_id); -+ if (ms->mbuf_pool == NULL) { -+ return -1; -+ } -+ -+ ms->rpc_pool = rpc_pool_create(stack_id); -+ if (ms->rpc_pool == NULL) { -+ mem_stack_pool_free(stack_id); -+ return -1; -+ } -+ -+ rte_mempool_obj_iter(ms->mbuf_pool, mbuf_obj_ops.init, &stack_id); -+ rte_mempool_obj_iter(ms->rpc_pool, rpc_obj_ops.init, &stack_id); -+ -+ return 0; -+} -+ -+int mem_stack_mpcache_init(int stack_id, unsigned cpu_id) -+{ -+ struct mem_stack *ms = mem_stack_get(stack_id); -+ -+ if (ms->mbuf_pool == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "mem_stack_get stack_id %d failed\n", stack_id); -+ return -1; -+ } -+ -+ RTE_PER_LCORE(_lcore_id) = cpu_id; -+ ms->mbuf_mpcache = rte_mempool_default_cache(ms->mbuf_pool, rte_lcore_id()); -+ ms->migrate_watermark = ms->mbuf_mpcache->size / 8; -+ -+ LSTACK_LOG(INFO, LSTACK, "tid %d, stack_id %d, lcore_id %u, migrate_watermark %u\n", -+ rte_gettid(), stack_id, rte_lcore_id(), ms->migrate_watermark); -+ -+ return 0; -+} -+ -+unsigned mem_stack_mbuf_pool_count(int stack_id) -+{ -+ struct mem_stack *ms = mem_stack_get(stack_id); -+ return rte_mempool_avail_count(ms->mbuf_pool); -+} -+ -+void mem_thread_cache_free(struct mem_thread *mt) -+{ -+ void *obj; -+ -+ if (mt->mbuf_migrate_ring != NULL) { -+ while (rte_ring_sc_dequeue(mt->mbuf_migrate_ring, &obj) == 0) { -+ mem_put_mbuf_bulk((struct rte_mbuf **)&obj, 1); -+ } -+ rte_ring_free(mt->mbuf_migrate_ring); -+ mt->mbuf_migrate_ring = NULL; -+ } -+ -+ if (mt->mbuf_cache != NULL) { -+ while (buf_cache_pop_bulk(mt->mbuf_cache, &obj, 1, NULL) > 0) { -+ mem_put_mbuf_bulk((struct rte_mbuf **)&obj, 1); -+ } -+ buf_cache_free(mt->mbuf_cache); -+ mt->mbuf_cache = NULL; -+ } -+ -+ if (mt->rpc_cache != NULL) { -+ while (buf_cache_pop_bulk(mt->rpc_cache, &obj, 1, NULL) > 0) { -+ mem_put_rpc(obj); -+ } -+ buf_cache_free(mt->rpc_cache); -+ mt->rpc_cache = NULL; -+ } -+} -+ -+int mem_thread_cache_init(struct mem_thread *mt) -+{ -+ if (!get_global_cfg_params()->stack_mode_rtc && !dpdk_nic_is_xdp()) { -+ char name [RTE_MEMPOOL_NAMESIZE]; -+ SYS_FORMAT_NAME(name, RTE_MEMPOOL_NAMESIZE, "%s_%p", "migrate_ring", mt); -+ -+ mt->mbuf_migrate_ring = rte_ring_create(name, BUF_CACHE_DEFAULT_NUM, -+ rte_socket_id(), RING_F_SP_ENQ | RING_F_SC_DEQ); -+ if (mt->mbuf_migrate_ring == NULL) { -+ return -1; -+ } -+ } -+ -+ mt->mbuf_cache = buf_cache_create(BUF_CACHE_DEFAULT_NUM); -+ if (mt->mbuf_cache == NULL) { -+ mem_thread_cache_free(mt); -+ return -1; -+ } -+ -+ mt->rpc_cache = buf_cache_create(BUF_CACHE_MIN_NUM); -+ if (mt->rpc_cache == NULL) { -+ mem_thread_cache_free(mt); -+ return -1; -+ } -+ -+ return 0; -+} -+ -+struct mem_thread *mem_thread_migrate_get(int stack_id) -+{ -+ struct mem_thread *mt = mem_thread_get(stack_id); -+ if (mt == NULL || mt->mbuf_migrate_ring == NULL) -+ return NULL; -+ return mt; -+} -+ -+static inline void mem_preinit_pbuf(struct pbuf *p); -+void mem_mbuf_migrate_enqueue(struct mem_thread *mt, unsigned n) -+{ -+ struct mem_stack *ms; -+ struct rte_mempool_cache *mpcache; -+ int stack_id; -+ unsigned num, i; -+ void **obj_table; -+ -+ stack_id = get_protocol_stack()->stack_idx; -+ ms = mem_stack_get(stack_id); -+ mpcache = ms->mbuf_mpcache; -+ -+ mt->stk_migrate_count += n; -+ -+ if (mpcache->len <= ms->migrate_watermark) -+ return; -+ -+ num = LWIP_MIN(mpcache->len - ms->migrate_watermark, -+ mt->stk_migrate_count); -+ obj_table = &mpcache->objs[mpcache->len - num]; -+ -+ for (i = 0; i < num; i++) { -+ rte_pktmbuf_reset(obj_table[i]); -+ mem_preinit_pbuf(mbuf_to_pbuf(obj_table[i])); -+ } -+ num = rte_ring_sp_enqueue_bulk(mt->mbuf_migrate_ring, obj_table, num, NULL); -+ if (num > 0) { -+ mpcache->len -= num; -+ mt->stk_migrate_count -= num; -+ } else { -+ mt->stk_migrate_count = 0; -+ } -+} -+ -+void mem_mbuf_migrate_dequeue(struct mem_thread *mt) -+{ -+ struct buf_cache *cache; -+ unsigned num; -+ void **obj_table; -+ -+ if (mt->mbuf_migrate_ring == NULL) -+ return; -+ -+ cache = mt->mbuf_cache; -+ if (cache->head > (cache->watermark >> 1)) -+ return; -+ -+ num = cache->capacity - cache->head; -+ obj_table = &cache->objs[cache->head]; -+ -+ num = rte_ring_sc_dequeue_burst(mt->mbuf_migrate_ring, obj_table, num, NULL); -+ cache->head += num; -+} -+ -+/* see rte_mempool_cache_flush() */ -+static inline -+void pool_put_with_mpcache(struct rte_mempool *pool, struct rte_mempool_cache* mpcache, void *obj) -+{ -+ if (mpcache->len >= mpcache->flushthresh) { -+ rte_mempool_ops_enqueue_bulk(pool, &mpcache->objs[mpcache->size], -+ mpcache->len - mpcache->size); -+ mpcache->len = mpcache->size; -+ } -+ mpcache->objs[mpcache->len] = obj; -+ mpcache->len++; -+} -+ -+static inline -+void pool_put_with_bufcache(struct rte_mempool *pool, struct buf_cache* cache, void *obj) -+{ -+ if (cache->head >= cache->flushthresh) { -+ buf_cache_sub_watermark(cache); -+ rte_mempool_ops_enqueue_bulk(pool, &cache->objs[cache->watermark], -+ cache->head - cache->watermark); -+ cache->head = cache->watermark; -+ } -+ cache->objs[cache->head] = obj; -+ cache->head++; -+} -+ -+static unsigned pool_get_bulk_with_cache(const struct mempool_ops *pool_ops, -+ struct rte_mempool *pool, struct buf_cache *cache, -+ void **obj_table, unsigned n) -+{ -+ unsigned ret; -+ unsigned count = 0; -+ unsigned get_count; -+ -+ ret = buf_cache_pop_bulk(cache, obj_table, n, &count); -+ if (ret > 0) { -+ return n; -+ } -+ -+ /* get from the pool */ -+ ret = pool_ops->get_bulk(pool, obj_table, n); -+ if (unlikely(ret == 0)) { -+ LSTACK_LOG(ERR, LSTACK, "pool %s get_bulk failed, n %u\n", pool->name, n); -+ return 0; -+ } -+ -+ buf_cache_add_watermark(cache); -+ if (count >= cache->watermark) { -+ return n; -+ } -+ -+ /* get from the pool, then enqueue to cache */ -+ get_count = cache->watermark - count; -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(cache=%p, watermark=%u, get_count=%u)\n", -+ __FUNCTION__, cache, cache->watermark, get_count)); -+ -+ ret = pool_ops->get_bulk(pool, &cache->objs[cache->head], get_count); -+ if (unlikely(ret == 0)) { -+ LSTACK_LOG(ERR, LSTACK, "pool %s get_bulk failed, n %u\n", pool->name, get_count); -+ } else { -+ cache->head += get_count; -+ } -+ -+ return n; -+} -+ -+static void pool_put_bulk_with_cache(const struct mempool_ops *pool_ops, -+ struct rte_mempool *pool, struct buf_cache *cache, -+ void *const *obj_table, unsigned n) -+{ -+ unsigned ret; -+ unsigned count; -+ unsigned free_count = 0; -+ unsigned put_count; -+ -+ ret = buf_cache_push_bulk(cache, obj_table, n, &free_count); -+ if (ret > 0) { -+ return; -+ } -+ -+ /* put to the pool */ -+ pool_ops->put_bulk(pool, obj_table, n); -+ -+ buf_cache_sub_watermark(cache); -+ count = buf_cache_get_capacity(cache) - free_count; -+ if (count <= cache->watermark) { -+ return; -+ } -+ -+ /* dequeue from cache, then put to the pool */ -+ put_count = count - cache->watermark; -+ LWIP_DEBUGF(MEMP_DEBUG, ("pool_put_bulk_with_cache(cache=%p, watermark=%u, put_count=%u)\n", -+ cache, cache->watermark, put_count)); -+ -+ pool_ops->put_bulk(pool, &cache->objs[cache->head - put_count], put_count); -+ cache->head -= put_count; -+ -+ return; -+} -+ -+ -+void *mem_get_rpc(int stack_id) -+{ -+ struct mem_stack *ms = mem_stack_get(stack_id); -+ struct mem_thread *mt = mem_thread_get(stack_id); -+ unsigned ret; -+ void *obj; -+ -+ if (mt == NULL) { -+ ret = mem_mp_ops.get_bulk(ms->rpc_pool, &obj, 1); -+ } else { -+ ret = pool_get_bulk_with_cache(&mem_mp_ops, ms->rpc_pool, mt->rpc_cache, &obj, 1); -+ } -+ -+ LWIP_DEBUGF(MEMP_DEBUG, ("mem_get_rpc(stack_id=%d, obj=%p)\n", stack_id, obj)); -+ -+ return ret == 0 ? NULL : obj; -+} -+ -+void mem_put_rpc(void *obj) -+{ -+ unsigned stack_id = rpc_obj_ops.get_stack_id(obj); -+ struct mem_stack *ms = mem_stack_get(stack_id); -+ struct mem_thread *mt = mem_thread_get(stack_id); -+ -+ LWIP_DEBUGF(MEMP_DEBUG, ("mem_put_rpc(stack_id=%d, obj=%p)\n", stack_id, obj)); -+ -+ if (mt == NULL) { -+ mem_mp_ops.put_bulk(ms->rpc_pool, &obj, 1); -+ } else { -+ pool_put_bulk_with_cache(&mem_mp_ops, ms->rpc_pool, mt->rpc_cache, &obj, 1); -+ } -+} -+ -+unsigned mem_get_mbuf_bulk(int stack_id, struct rte_mbuf **mbuf_table, unsigned n, bool reserve) -+{ -+ struct mem_stack *ms = mem_stack_get(stack_id); -+ struct mem_thread *mt = mem_thread_get(stack_id); -+ unsigned ret; -+ -+ if (unlikely(n == 0)) { -+ return 0; -+ } -+ -+ if (reserve) { -+ /* don't use rte_mempool_avail_count, it traverse cpu local cache, -+ * when RTE_MAX_LCORE is too large, it's time-consuming -+ */ -+ if (rte_ring_count(ms->mbuf_pool->pool_data) < MBUFPOOL_RESERVE_NUM + n) { -+ return 0; -+ } -+ } -+ -+ if (mt == NULL) { -+ ret = mbuf_mp_ops.get_bulk(ms->mbuf_pool, (void **)mbuf_table, n); -+ } else { -+ mem_mbuf_migrate_dequeue(mt); -+ ret = pool_get_bulk_with_cache(&mbuf_mp_ops, ms->mbuf_pool, mt->mbuf_cache, (void **)mbuf_table, n); -+ } -+ -+#if MEMP_DEBUG -+ for (unsigned i = 0; i < ret; ++i) { -+ LWIP_DEBUGF(MEMP_DEBUG, ("mem_get_mbuf_bulk(stack_id=%d, n=%u, mbuf_table[%u]=%p, pbuf=%p)\n", -+ stack_id, n, i, mbuf_table[i], mbuf_to_pbuf(mbuf_table[i]))); -+ } -+#endif /* MEMP_DEBUG */ -+ -+ return ret; -+} -+ -+static void mem_put_mbuf_bulk_by_pbuf(struct rte_mbuf *const *mbuf_table, unsigned n) -+{ -+ unsigned stack_id = mbuf_obj_ops.get_stack_id(mbuf_table[0]); -+ struct mem_stack *ms = mem_stack_get(stack_id); -+ struct mem_thread *mt = mem_thread_get(stack_id); -+ -+ if (unlikely(n == 0)) { -+ return; -+ } -+ -+#if MEMP_DEBUG -+ for (unsigned i = 0; i < n; ++i) { -+ LWIP_DEBUGF(MEMP_DEBUG, ("mem_put_mbuf_bulk(stack_id=%d, n=%u, mbuf_table[%u]=%p, pbuf=%p)\n", -+ stack_id, n, i, mbuf_table[i], mbuf_to_pbuf(mbuf_table[i]))); -+ } -+#endif /* MEMP_DEBUG */ -+ -+ if (mt == NULL) { -+ mbuf_mp_ops.put_bulk(ms->mbuf_pool, (void *const *)mbuf_table, n); -+ } else { -+ pool_put_bulk_with_cache(&mbuf_mp_ops, ms->mbuf_pool, mt->mbuf_cache, (void *const *)mbuf_table, n); -+ } -+ -+} -+ -+void mem_put_mbuf_bulk(struct rte_mbuf *const *mbuf_table, unsigned n) -+{ -+ unsigned i; -+ for (i = 0; i < n; ++i) { -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(stack_id=%d, n=%u, mbuf_table[%u]=%p, pbuf=%p)\n", -+ __FUNCTION__, mbuf_obj_ops.get_stack_id(mbuf_table[i]), -+ n, i, mbuf_table[i], mbuf_to_pbuf(mbuf_table[i]))); -+ -+ rte_pktmbuf_free(mbuf_table[i]); -+ } -+} -+ -+ -+unsigned mem_get_pbuf_bulk(int stack_id, struct pbuf **pbuf_table, unsigned n, bool reserve) -+{ -+ struct rte_mbuf **mbuf_table = (struct rte_mbuf **)pbuf_table; -+ unsigned ret, i; -+ -+ ret = mem_get_mbuf_bulk(stack_id, mbuf_table, n, reserve); -+ if (unlikely(ret == 0)) { -+ struct protocol_stack *stack = get_protocol_stack_by_id(stack_id); -+ stack->stats.tx_allocmbuf_fail++; -+ return 0; -+ } -+ -+ for (i = 0; i < (n & ~0x3); i += 4) { -+ pbuf_table[i] = mbuf_to_pbuf(mbuf_table[i]); -+ pbuf_table[i + 1] = mbuf_to_pbuf(mbuf_table[i + 1]); -+ pbuf_table[i + 2] = mbuf_to_pbuf(mbuf_table[i + 2]); -+ pbuf_table[i + 3] = mbuf_to_pbuf(mbuf_table[i + 3]); -+ } -+ switch (n & 0x3) { -+ case 3: -+ pbuf_table[i] = mbuf_to_pbuf(mbuf_table[i]); /* fallthrough */ -+ ++i; -+ case 2: -+ pbuf_table[i] = mbuf_to_pbuf(mbuf_table[i]); /* fallthrough */ -+ ++i; -+ case 1: -+ pbuf_table[i] = mbuf_to_pbuf(mbuf_table[i]); /* fallthrough */ -+ ++i; -+ } -+ -+ return n; -+} -+ -+void mem_preput_pbuf(struct pbuf *p) -+{ -+ struct rte_mbuf *m = pbuf_to_mbuf(p); -+ p->mbuf_refcnt = rte_mbuf_refcnt_read(m); -+ if (p->mbuf_refcnt == 1) { -+ rte_pktmbuf_reset(m); -+ } -+} -+ -+/* ignore buf->ref, and reset to 1 */ -+static __rte_always_inline -+struct rte_mbuf *pbuf_to_mbuf_prefree(struct pbuf *p) -+{ -+ if (unlikely(p == NULL)) -+ return NULL; -+ -+ if (p->next != NULL) -+ p->next = NULL; -+ -+ struct rte_mbuf *m = pbuf_to_mbuf(p); -+#if MEMP_DEBUG -+ if (rte_mbuf_refcnt_read(m) > 1) { -+ LWIP_DEBUGF(MEMP_DEBUG, ("pbuf_to_mbuf_prefree(mbuf=%p, pbuf=%p, refcnt=%u)\n", -+ m, p, rte_mbuf_refcnt_read(m))); -+ } -+#endif /* MEMP_DEBUG */ -+ if (p->mbuf_refcnt != 1) { -+ m = rte_pktmbuf_prefree_seg(m); -+ if (m != NULL) { -+ rte_pktmbuf_reset(m); -+ } -+ } -+ -+ return m; -+} -+ -+void mem_put_pbuf_bulk(struct pbuf *const *pbuf_table, unsigned n) -+{ -+ struct rte_mbuf *mbuf_table[BUF_BULK_MAX_NUM]; -+ unsigned i, copied, batch, bulk_num; -+ -+ copied = 0; -+ while (copied < n) { -+ batch = LWIP_MIN(n - copied, BUF_BULK_MAX_NUM); -+ bulk_num = 0; -+ for (i = 0; i < batch; ++i, ++copied) { -+ mbuf_table[bulk_num] = pbuf_to_mbuf_prefree(pbuf_table[copied]); -+ if (mbuf_table[bulk_num] != NULL) { -+ ++bulk_num; -+ } -+ } -+ mem_put_mbuf_bulk_by_pbuf(mbuf_table, bulk_num); -+ } -+} -+ -+void mem_put_pbuf_list_bulk(struct pbuf *const *pbuf_table, unsigned n) -+{ -+ unsigned stack_id = mbuf_obj_ops.get_stack_id(pbuf_to_mbuf(pbuf_table[0])); -+ struct mem_stack *ms = mem_stack_get(stack_id); -+ struct mem_thread *mt = mem_thread_get(stack_id); -+ -+ struct pbuf *q, *next; -+ struct rte_mbuf *mbuf; -+ -+ for (unsigned i = 0; i < n; ++i) { -+ q = pbuf_table[i]; -+ while (q != NULL) { -+ next = q->next; -+ q->next = NULL; -+ -+ q->ref--; -+ if (q->ref > 0) -+ break; -+ mbuf = pbuf_to_mbuf_prefree(q); -+ if (mbuf == NULL) -+ break; -+ -+ q = next; -+ -+ if (mt == NULL) { -+ pool_put_with_mpcache(ms->mbuf_pool, ms->mbuf_mpcache, mbuf); -+ } else { -+ pool_put_with_bufcache(ms->mbuf_pool, mt->mbuf_cache, mbuf); -+ } -+ -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(stack_id=%d, n=%u, mbuf_table[%u]=%p, pbuf=%p)\n", -+ __FUNCTION__, stack_id, n, i, mbuf, q)); -+ } -+ } -+} -+ -+struct pbuf *mem_get_pbuf(int stack_id, bool reserve) -+{ -+ int ret; -+ struct rte_mbuf *mbuf; -+ -+ if (stack_id < 0 || stack_id >= PROTOCOL_STACK_MAX) -+ stack_id = get_protocol_stack()->stack_idx; -+ -+ ret = mem_get_mbuf_bulk(stack_id, &mbuf, 1, reserve); -+ if (unlikely(ret == 0)) { -+ struct protocol_stack *stack = get_protocol_stack_by_id(stack_id); -+ stack->stats.tx_allocmbuf_fail++; -+ return NULL; -+ } -+ -+ return mbuf_to_pbuf(mbuf); -+} -+ -+void mem_put_pbuf(struct pbuf *p) -+{ -+ struct rte_mbuf *mbuf = pbuf_to_mbuf_prefree(p); -+ if (mbuf != NULL) { -+ mem_put_mbuf_bulk_by_pbuf(&mbuf, 1); -+ } -+} -+ -+unsigned mem_extcache_get_pbuf_bulk(int stack_id, struct pbuf **pbuf_table, unsigned n, bool reserve, struct pbuf **extcache_list) -+{ -+ unsigned ret; -+ struct pbuf *p; -+ -+ for (int i = 0; i < n; ++i) { -+ p = *extcache_list; -+ if (p != NULL) { -+ *extcache_list = p->next; -+ p->next = NULL; -+ pbuf_table[i] = p; -+ } else { -+ ret = mem_get_pbuf_bulk(stack_id, &pbuf_table[i], n - i, reserve); -+ if (unlikely(ret == 0)) { -+ mem_put_pbuf_bulk(pbuf_table, i); -+ return 0; -+ } -+ break; -+ } -+ } -+ -+ return n; -+} -+ -+struct pbuf *mem_extcache_get_pbuf(int stack_id, bool reserve, struct pbuf **extcache_list) -+{ -+ struct pbuf *p; -+ -+ p = *extcache_list; -+ if (p != NULL) { -+ *extcache_list = p->next; -+ p->next = NULL; -+ } else { -+ p = mem_get_pbuf(stack_id, reserve); -+ } -+ -+ return p; -+} -+ -+void mem_extcache_put_pbuf(struct pbuf *h, struct pbuf *t, struct pbuf **extcache_list) -+{ -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ pbuf_free(h); -+ return; -+ } -+ -+ if (*extcache_list == NULL) { -+ *extcache_list = h; -+ } else { -+ if (t == NULL) -+ t = pbuf_list_tail(h); -+ t->next = *extcache_list; -+ *extcache_list = h; -+ } -+} -+ -+void mem_extcache_flush_pbuf(struct pbuf **extcache_list) -+{ -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ return; -+ } -+ -+ struct pbuf *p = *extcache_list; -+ if (p != NULL) { -+ mem_put_pbuf_list_bulk(&p, 1); -+ *extcache_list = NULL; -+ } -+} -+ -+static inline void mem_preinit_pbuf(struct pbuf *p) -+{ -+ mem_init_pbuf(p, 0, 0, 0, PBUF_POOL_PREINIT); -+} -+ -+void mem_init_pbuf(struct pbuf *p, pbuf_layer layer, uint16_t tot_len, uint16_t len, pbuf_type type) -+{ -+ struct pbuf_custom *pc; -+ struct rte_mbuf *mbuf; -+ void *data; -+ -+ if (p->type_internal == PBUF_POOL_PREINIT) { -+ p->payload = (uint8_t *)p->payload + LWIP_MEM_ALIGN_SIZE((uint16_t)layer); -+ p->type_internal = type; -+ p->len = len; -+ p->tot_len = tot_len; -+ return; -+ } -+ -+ pc = (struct pbuf_custom *)p; -+ mbuf = pbuf_to_mbuf(p); -+ data = rte_pktmbuf_mtod(mbuf, void *); -+ -+ pbuf_alloced_custom(layer, len, type, pc, data, MBUF_PAYLOAD_SIZE); -+ p->tot_len = tot_len; -+ pc->custom_free_function = mem_put_pbuf; -+} -diff --git a/src/lstack/include/lstack_lockless_queue.h b/src/lstack/include/lstack_lockless_queue.h -index b0fc31f..bec2564 100644 ---- a/src/lstack/include/lstack_lockless_queue.h -+++ b/src/lstack/include/lstack_lockless_queue.h -@@ -15,6 +15,8 @@ - - #include - -+/* multi-producers single-consumer queue */ -+ - typedef struct lockless_queue_node { - struct lockless_queue_node *volatile next; - } lockless_queue_node; -@@ -25,6 +27,32 @@ typedef struct lockless_queue { - lockless_queue_node stub __attribute__((__aligned__(64))); - } lockless_queue; - -+ -+static inline void lockless_queue_node_set_poped(lockless_queue_node *node) -+{ -+ node->next = node; -+} -+ -+static inline bool lockless_queue_node_is_poped(lockless_queue_node *node) -+{ -+ return node->next == node; -+} -+ -+static inline bool lockless_queue_node_test_poped(lockless_queue_node *node) -+{ -+ /* -+ * if (node->next == node) { -+ * node->next = NULL; -+ * return 1; -+ * } else { -+ * return 0; -+ * } -+ */ -+ return !!__atomic_compare_exchange_n( -+ (volatile uint64_t *)&node->next, (uint64_t *)&node, (uint64_t)NULL, -+ false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); -+} -+ - static inline void lockless_queue_init(lockless_queue *queue) - { - queue->head = &queue->stub; -@@ -57,11 +85,35 @@ static inline int32_t lockless_queue_count(lockless_queue *queue) - return count; - } - -+/* -+ * tail head -+ * \_ stub _/ -+ * -+ * tail old_head head -+ * \_ stub _/ node _/ -+ * -+ * tail head -+ * \_ stub -> node _/ -+ */ - static inline void lockless_queue_mpsc_push(lockless_queue *queue, lockless_queue_node *node) - { -+ lockless_queue_node *old_head; -+ - node->next = NULL; -- lockless_queue_node *old_head = -- (lockless_queue_node *)__atomic_exchange_n((void **)&queue->head, (void*)node, __ATOMIC_ACQ_REL); -+ -+ old_head = (lockless_queue_node *)__atomic_exchange_n((void **)&queue->head, (void*)node, __ATOMIC_ACQ_REL); -+ -+ __atomic_store_n(&old_head->next, node, __ATOMIC_RELEASE); -+} -+ -+static inline void lockless_queue_mpsc_test_push(lockless_queue *queue, lockless_queue_node *node) -+{ -+ lockless_queue_node *old_head; -+ -+ if (!lockless_queue_node_test_poped(node)) -+ return; -+ -+ old_head = (lockless_queue_node *)__atomic_exchange_n((void **)&queue->head, (void*)node, __ATOMIC_ACQ_REL); - - __atomic_store_n(&old_head->next, node, __ATOMIC_RELEASE); - } -@@ -70,7 +122,13 @@ static inline lockless_queue_node* lockless_queue_mpsc_pop(lockless_queue* queue - { - lockless_queue_node *tail = queue->tail; - lockless_queue_node *next = tail->next; -+ lockless_queue_node *head; - -+ /* -+ * step1. dequeue stub. -+ * tail head -+ * \_ stub -> node -> node _/ -+ */ - if (tail == &queue->stub) { - if (next == NULL) { - return NULL; -@@ -80,21 +138,38 @@ static inline lockless_queue_node* lockless_queue_mpsc_pop(lockless_queue* queue - next = next->next; - } - -+ /* -+ * step2. dequeue tail. -+ * tail next-\ head -+ * \_ node -> node _/ -+ */ - if (next) { - queue->tail = next; -+ lockless_queue_node_set_poped(tail); - return tail; - } - -- lockless_queue_node *head = queue->head; -+ /* -+ * step3. enqueue ing. -+ * tail old_head head -+ * \_ node _/ node _/ -+ */ -+ head = queue->head; - if (tail != head) { - return NULL; - } - -+ /* -+ * step4. only one node, enqueue stub and dequeue node. -+ * tail head -+ * \_ node _/ -+ */ - lockless_queue_mpsc_push(queue, &queue->stub); - - next = tail->next; - if (next) { - queue->tail = next; -+ lockless_queue_node_set_poped(tail); - return tail; - } - -diff --git a/src/lstack/include/lstack_mempool.h b/src/lstack/include/lstack_mempool.h -new file mode 100644 -index 0000000..c6adff0 ---- /dev/null -+++ b/src/lstack/include/lstack_mempool.h -@@ -0,0 +1,325 @@ -+/* -+* 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_MEM_H__ -+#define __GAZELLE_MEM_H__ -+ -+#include -+ -+#include -+#include -+#include -+ -+#include -+#include -+ -+#include "common/dpdk_common.h" -+ -+/* fix virtio PMD error: Rx scatter is disabled and RxQ mbuf pool object is too small. */ -+#define DEV_VIRTIO_RX_MBUF_SIZE 1530 -+/* see hinic_convert_rx_buf_size() */ -+#define DEV_HINIC_RX_MBUF_SIZE 0x600 -+ -+/* IP6_HLEN - IP_HLEN: reserve 20 byte to overflow, -+ * if distinguish between IP4_MSS and IP6_MSS. */ -+#define MBUF_PAYLOAD_SIZE LWIP_MAX(PBUF_POOL_BUFSIZE, DEV_HINIC_RX_MBUF_SIZE) -+#define MBUF_DATA_SIZE (MBUF_PAYLOAD_SIZE + RTE_PKTMBUF_HEADROOM) -+/* DPDK limit ring head-tail distance in rte_ring_init. -+ * Max value is RTE_RING_SZ_MASK / HTD_MAX_DEF, RTE_RING_SZ_MASK is 0x7fffffff, HTD_MAX_DEF is 8. -+ */ -+#define MBUFPOOL_MAX_NUM 0xfffffff -+ -+#define MBUFPOOL_CACHE_NUM LWIP_MIN(NIC_QUEUE_SIZE_MAX >> 1, RTE_MEMPOOL_CACHE_MAX_SIZE) -+#define MBUFPOOL_RESERVE_NUM (NIC_QUEUE_SIZE_MAX + MBUFPOOL_CACHE_NUM) -+ -+#define MEMPOOL_OPS_NAME "ring_mt_rts" -+#define MEMPOOL_CACHE_NUM 32 -+ -+#define BUF_CACHE_MIN_NUM 32 -+#define BUF_CACHE_DEFAULT_NUM 1024 -+#define BUF_CACHE_WATERSTEP_SHIFT 4 /* 1/16 */ -+ -+#define BUF_BULK_MAX_NUM 32 -+ -+struct buf_cache { -+ unsigned size; /* Size of cache. */ -+ unsigned mask; /* Mask (size-1) of cache. */ -+ unsigned capacity; /* Usable size of cache */ -+ -+ unsigned watermark; -+ unsigned waterstep; -+ unsigned flushthresh; -+ -+ unsigned head; -+ unsigned tail; -+ -+ /* new cache line */ -+ char pad0 __rte_cache_aligned; -+ void *objs[0]; -+}; -+ -+static __rte_always_inline -+struct buf_cache *buf_cache_create(unsigned count) -+{ -+ struct buf_cache *cache; -+ unsigned size; -+ -+ size = rte_align32pow2(count); -+ if (size < BUF_CACHE_MIN_NUM) -+ return NULL; -+ -+ cache = (struct buf_cache *)calloc(1, sizeof(struct buf_cache) + sizeof(void *) * size); -+ if (cache == NULL) -+ return NULL; -+ -+ cache->size = size; -+ cache->mask = size - 1; -+ cache->capacity = size - 1; -+ if (cache->capacity > count) -+ cache->capacity = count; -+ -+ cache->head = 0; -+ cache->tail = 0; -+ -+ cache->waterstep = cache->size >> BUF_CACHE_WATERSTEP_SHIFT; -+ if (cache->waterstep < BUF_CACHE_WATERSTEP_SHIFT) -+ cache->waterstep = BUF_CACHE_WATERSTEP_SHIFT; -+ cache->watermark = cache->waterstep; -+ cache->flushthresh = cache->size - cache->waterstep; -+ -+ return cache; -+} -+ -+static __rte_always_inline -+void buf_cache_free(struct buf_cache *cache) -+{ -+ if (cache != NULL) { -+ free(cache); -+ } -+} -+ -+static __rte_always_inline -+unsigned buf_cache_count(const struct buf_cache *cache) -+{ -+ unsigned count = (cache->head - cache->tail) & cache->mask; -+ return (count > cache->capacity) ? cache->capacity : count; -+} -+ -+static __rte_always_inline -+unsigned buf_cache_free_count(const struct buf_cache *cache) -+{ -+ return cache->capacity - buf_cache_count(cache); -+} -+ -+static __rte_always_inline -+unsigned buf_cache_get_capacity(const struct buf_cache *cache) -+{ -+ return cache->capacity; -+} -+ -+static __rte_always_inline -+void buf_cache_add_watermark(struct buf_cache *cache) -+{ -+ if (cache->watermark < cache->flushthresh) { -+ cache->watermark += cache->waterstep; -+ } -+} -+ -+static __rte_always_inline -+void buf_cache_sub_watermark(struct buf_cache *cache) -+{ -+ if (cache->watermark > cache->waterstep) { -+ cache->watermark -= cache->waterstep; -+ } -+} -+ -+static __rte_always_inline -+void __buf_cache_copy_objs(void ** dst_table, void *const *src_table, unsigned n) -+{ -+ unsigned i; -+ -+ for (i = 0; i < (n & ~0x3); i += 4) { -+ dst_table[i] = src_table[i]; -+ dst_table[i + 1] = src_table[i + 1]; -+ dst_table[i + 2] = src_table[i + 2]; -+ dst_table[i + 3] = src_table[i + 3]; -+ } -+ switch (n & 0x3) { -+ case 3: -+ dst_table[i] = src_table[i]; /* fallthrough */ -+ ++i; -+ case 2: -+ dst_table[i] = src_table[i]; /* fallthrough */ -+ ++i; -+ case 1: -+ dst_table[i] = src_table[i]; /* fallthrough */ -+ } -+} -+ -+static __rte_always_inline -+unsigned buf_cache_enqueue_bulk(struct buf_cache *cache, void *const *obj_table, unsigned n, unsigned *free_space) -+{ -+ unsigned free_count = buf_cache_free_count(cache); -+ unsigned i, idx; -+ -+ if (unlikely(n > free_count)) { -+ if (free_space != NULL) { -+ *free_space = free_count; -+ } -+ return 0; -+ } -+ -+ /* refence to __rte_ring_enqueue_elems_64() */ -+ idx = cache->head & cache->mask; -+ if (likely(idx + n < cache->size)) { -+ __buf_cache_copy_objs(&cache->objs[idx], obj_table, n); -+ } else { -+ for (i = 0; idx < cache->size; i++, idx++) -+ cache->objs[idx] = obj_table[i]; -+ /* Start at the beginning */ -+ for (idx = 0; i < n; i++, idx++) -+ cache->objs[idx] = obj_table[i]; -+ } -+ -+ cache->head += n; -+ return n; -+} -+ -+static __rte_always_inline -+unsigned buf_cache_dequeue_bulk(struct buf_cache *cache, void **obj_table, unsigned n, unsigned *available) -+{ -+ unsigned count = buf_cache_count(cache); -+ unsigned i, idx; -+ -+ if (unlikely(n > count)) { -+ if (available != NULL) { -+ *available = count; -+ } -+ return 0; -+ } -+ -+ /* refence to __rte_ring_dequeue_elems_64() */ -+ idx = cache->tail & cache->mask; -+ if (likely(idx + n < cache->size)) { -+ __buf_cache_copy_objs(obj_table, &cache->objs[idx], n); -+ } else { -+ for (i = 0; idx < cache->size; i++, idx++) -+ obj_table[i] = cache->objs[idx]; -+ /* Start at the beginning */ -+ for (idx = 0; i < n; i++, idx++) -+ obj_table[i] = cache->objs[idx]; -+ } -+ -+ cache->tail += n; -+ return n; -+} -+ -+static __rte_always_inline -+unsigned buf_cache_push_bulk(struct buf_cache *cache, void *const *obj_table, unsigned n, unsigned *free_space) -+{ -+ unsigned free_count = buf_cache_free_count(cache); -+ unsigned top; -+ -+ if (unlikely(n > free_count)) { -+ if (free_space != NULL) { -+ *free_space = free_count; -+ } -+ return 0; -+ } -+ -+ top = cache->head; -+ __buf_cache_copy_objs(&cache->objs[top], obj_table, n); -+ -+ cache->head += n; -+ return n; -+} -+ -+static __rte_always_inline -+unsigned buf_cache_pop_bulk(struct buf_cache *cache, void **obj_table, unsigned n, unsigned *available) -+{ -+ unsigned count = buf_cache_count(cache); -+ unsigned top; -+ -+ if (unlikely(n > count)) { -+ if (available != NULL) { -+ *available = count; -+ } -+ return 0; -+ } -+ -+ top = cache->head; -+ __buf_cache_copy_objs(obj_table, &cache->objs[top - n], n); -+ -+ cache->head -= n; -+ return n; -+} -+ -+ -+struct mem_stack { -+ struct rte_mempool *rpc_pool; -+ -+ struct rte_mempool *mbuf_pool; -+ struct rte_mempool_cache *mbuf_mpcache; -+ unsigned migrate_watermark; -+}; -+ -+struct mem_thread { -+ struct buf_cache *rpc_cache; -+ -+ struct buf_cache *mbuf_cache; -+ struct rte_ring *mbuf_migrate_ring; -+ -+ char pad0 __rte_cache_aligned; /* new cache line */ -+ -+ unsigned stk_migrate_count; -+} __rte_cache_aligned; -+ -+void mem_stack_pool_free(int stack_id); -+int mem_stack_pool_init(int stack_id); -+int mem_stack_mpcache_init(int stack_id, unsigned cpu_id); -+ -+int mem_thread_manager_init(void); -+void mem_thread_cache_free(struct mem_thread *mt); -+int mem_thread_cache_init(struct mem_thread *mt); -+ -+unsigned mem_stack_mbuf_pool_count(int stack_id); -+struct rte_mempool *mem_get_mbuf_pool(int stack_id); -+struct rte_mempool *mem_get_rpc_pool(int stack_id); -+ -+void *mem_get_rpc(int stack_id); -+void mem_put_rpc(void *obj); -+ -+struct mem_thread *mem_thread_migrate_get(int stack_id); -+void mem_mbuf_migrate_enqueue(struct mem_thread *mt, unsigned n); -+void mem_mbuf_migrate_dequeue(struct mem_thread *mt); -+ -+unsigned mem_get_mbuf_bulk(int stack_id, struct rte_mbuf **mbuf_table, unsigned n, bool reserve); -+void mem_put_mbuf_bulk(struct rte_mbuf *const *mbuf_table, unsigned n); -+ -+unsigned mem_get_pbuf_bulk(int stack_id, struct pbuf **pbuf_table, unsigned n, bool reserve); -+void mem_preput_pbuf(struct pbuf *p); -+void mem_put_pbuf_bulk(struct pbuf *const *pbuf_table, unsigned n); -+void mem_put_pbuf_list_bulk(struct pbuf *const *pbuf_table, unsigned n); -+ -+struct pbuf *mem_get_pbuf(int stack_id, bool reserve); -+void mem_put_pbuf(struct pbuf *p); -+ -+unsigned mem_extcache_get_pbuf_bulk(int stack_id, struct pbuf **pbuf_table, unsigned n, bool reserve, -+ struct pbuf **extcache_list); -+struct pbuf *mem_extcache_get_pbuf(int stack_id, bool reserve, struct pbuf **extcache_list); -+void mem_extcache_put_pbuf(struct pbuf *h, struct pbuf *t, struct pbuf **extcache_list); -+void mem_extcache_flush_pbuf(struct pbuf **extcache_list); -+ -+void mem_init_pbuf(struct pbuf *p, pbuf_layer layer, uint16_t tot_len, uint16_t len, pbuf_type type); -+ -+ -+#endif /* __GAZELLE_MEM_H__ */ -\ No newline at end of file -diff --git a/src/lstack/include/lstack_sockctl.h b/src/lstack/include/lstack_sockctl.h -new file mode 100644 -index 0000000..91445ad ---- /dev/null -+++ b/src/lstack/include/lstack_sockctl.h -@@ -0,0 +1,25 @@ -+/* -+* 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 _LSTACK_RTC_API_H_ -+#define _LSTACK_RTC_API_H_ -+ -+#include -+ -+/* don't include lwip/sockets.h, conflict with sys/socket.h */ -+extern int lwip_fcntl(int s, int cmd, int val); -+extern int lwip_ioctl(int s, long cmd, void *argp); -+ -+void sockctl_rtw_api_init(posix_api_t *api); -+void sockctl_rtc_api_init(posix_api_t *api); -+ -+#endif /* __LSTACK_RTC_API_H_ */ -diff --git a/src/lstack/include/lstack_sockio.h b/src/lstack/include/lstack_sockio.h -new file mode 100644 -index 0000000..f4e5e99 ---- /dev/null -+++ b/src/lstack/include/lstack_sockio.h -@@ -0,0 +1,41 @@ -+/* -+* 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 _LSTACK_SOCKIO_H_ -+#define _LSTACK_SOCKIO_H_ -+ -+#include -+#include -+ -+ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); -+ssize_t sockio_recvmsg(int fd, struct msghdr *msg, int flags); -+ssize_t sockio_sendto(int fd, const void *mem, size_t len, int flags, const struct sockaddr *to, socklen_t tolen); -+ssize_t sockio_sendmsg(int fd, const struct msghdr *msg, int flags); -+ -+ssize_t sockio_read(int fd, void *mem, size_t len); -+ssize_t sockio_write(int fd, const void *mem, size_t len); -+ -+ssize_t sockio_recv(int fd, void *mem, size_t len, int flags); -+ssize_t sockio_send(int fd, const void *mem, size_t len, int flags); -+ -+ssize_t sockio_readv(int fd, const struct iovec *iov, int iovcnt); -+ssize_t sockio_writev(int fd, const struct iovec *iov, int iovcnt); -+ -+ -+void sockio_ops_init(void); -+bool sockio_mbox_pending(const struct lwip_sock *sock); -+ -+/* just for lwip */ -+int do_lwip_init_sock(int fd); -+void do_lwip_clean_sock(int fd); -+ -+#endif /* _LSTACK_SOCKIO_H_ */ -diff --git a/src/lstack/include/mbox_ring.h b/src/lstack/include/mbox_ring.h -new file mode 100644 -index 0000000..c48a47b ---- /dev/null -+++ b/src/lstack/include/mbox_ring.h -@@ -0,0 +1,583 @@ -+/* -+* 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 __MBOX_RING_H__ -+#define __MBOX_RING_H__ -+ -+#include -+#include -+ -+#include -+#include -+ -+#include "common/dpdk_common.h" -+#include "lstack_dpdk.h" -+#include "lstack_mempool.h" -+#include "lstack_cfg.h" -+ -+/* Optimize performance of creating ring. */ -+static inline -+struct rte_ring *rte_ring_create_fast(const char *name, unsigned size, unsigned flags) -+{ -+ ssize_t ring_size; -+ char ring_name[RTE_MEMZONE_NAMESIZE] = {0}; -+ struct rte_ring *ring; -+ -+ ring_size = rte_ring_get_memsize(size); -+ if (ring_size < 0) { -+ RTE_LOG(ERR, EAL, "rte_ring_get_memszie failed\n"); -+ return NULL; -+ } -+ -+ /* -+ * rte_ring_create is not used because it calls memzone_lookup_thread_unsafe function -+ * time consuming when there are many rings -+ */ -+ ring = rte_malloc_socket(NULL, ring_size, RTE_CACHE_LINE_SIZE, rte_socket_id()); -+ if (ring == NULL) { -+ RTE_LOG(ERR, EAL, "cannot create rte_ring for mbox\n"); -+ return NULL; -+ } -+ -+ if (snprintf(ring_name, sizeof(ring_name), "%s""%"PRIXPTR, name, (uintptr_t)ring) < 0) { -+ rte_free(ring); -+ RTE_LOG(ERR, EAL, "snprintf failed\n"); -+ return NULL; -+ } -+ -+ if (rte_ring_init(ring, ring_name, size, flags) != 0) { -+ rte_free(ring); -+ RTE_LOG(ERR, EAL, "cannot init rte_ring for mbox\n"); -+ return NULL; -+ } -+ -+ return ring; -+} -+ -+static inline -+void rte_ring_free_fast(struct rte_ring *ring) -+{ -+ rte_free(ring); -+} -+ -+ -+static inline -+void mbox_ring_common_free(struct mbox_ring *mr) -+{ -+ void *obj; -+ -+ if (mr->private_data_free_fn != NULL && mr->private_data != NULL) { -+ mr->private_data_free_fn(mr); -+ mr->private_data_free_fn = NULL; -+ mr->private_data = NULL; -+ } -+ -+ obj = mr->ops->pop_tail(mr, NULL); -+ if (obj != NULL) -+ mr->obj_free_fn(mr, obj, true); -+ while (true) { -+ if (mr->ops->dequeue_burst(mr, &obj, 1) == 0) -+ break; -+ mr->obj_free_fn(mr, obj, false); -+ } -+} -+ -+extern void sockio_mbox_set_func(struct mbox_ring *mr); -+static inline -+void mbox_ring_common_init(struct mbox_ring *mr) -+{ -+ mr->stk_queued_num = 0; -+ -+ mr->app_free_count = 0; -+ mr->app_queued_num = 0; -+ mr->app_tail_left = 0; -+ mr->app_recvd_len = 0; -+ -+ sockio_mbox_set_func(mr); -+} -+ -+/* single thread */ -+static inline -+int st_ring_create(struct mbox_ring *mr, const char *name, unsigned count) -+{ -+ mbox_ring_common_init(mr); -+ -+ mr->ops = &g_mbox_rtc_default_ops; -+ mr->st_obj = NULL; -+ -+ mr->ring = rte_ring_create_fast(name, count, RING_F_SP_ENQ | RING_F_SC_DEQ); -+ if (mr->ring == NULL) { -+ return -ENOMEM; -+ } -+ return 0; -+} -+ -+static inline -+void st_ring_destroy(struct mbox_ring *mr) -+{ -+ mbox_ring_common_free(mr); -+ -+ mr->ops = NULL; -+ mr->st_obj = NULL; -+ if (mr->ring != NULL) { -+ rte_ring_free_fast(mr->ring); -+ mr->ring = NULL; -+ } -+} -+ -+static inline -+unsigned st_ring_get_capacity(const struct mbox_ring *mr) -+{ -+ return mr->ring->capacity; -+} -+ -+static inline -+unsigned st_ring_count(const struct mbox_ring *mr) -+{ -+ // return rte_ring_count(mr->ring); -+ struct rte_ring *r = mr->ring; -+ uint32_t prod_tail = r->prod.tail; -+ uint32_t cons_head = r->cons.head; -+ uint32_t count = (prod_tail - cons_head) & r->mask; -+ return (count > r->capacity) ? r->capacity : count; -+} -+ -+static inline -+unsigned st_ring_free_count(const struct mbox_ring *mr) -+{ -+ return st_ring_get_capacity(mr) - st_ring_count(mr); -+} -+ -+static inline -+unsigned st_ring_enqueue_burst_start(struct mbox_ring *mr, void *const *obj_table, unsigned n) -+{ -+ struct rte_ring *r = mr->ring; -+ uint32_t prod_head, cons_tail; -+ uint32_t free_entries; -+ -+ prod_head = r->prod.head; -+ cons_tail = r->cons.tail; -+ -+ free_entries = r->capacity + cons_tail - prod_head; -+ if (unlikely(free_entries == 0)) -+ return 0; -+ if (n > free_entries) -+ n = free_entries; -+ -+ r->prod.head = prod_head + n; -+ -+ __rte_ring_enqueue_elems(r, prod_head, obj_table, sizeof(void *), n); -+ return n; -+} -+ -+static inline -+void st_ring_enqueue_burst_finish(struct mbox_ring *mr) -+{ -+ mr->ring->prod.tail = mr->ring->prod.head; -+} -+ -+static inline -+unsigned st_ring_dequeue_burst_start(struct mbox_ring *mr, void **obj_table, unsigned n) -+{ -+ struct rte_ring *r = mr->ring; -+ uint32_t cons_head, prod_tail; -+ uint32_t entries; -+ -+ cons_head = r->cons.head; -+ prod_tail = r->prod.tail; -+ -+ entries = prod_tail - cons_head; -+ if (unlikely(entries == 0)) -+ return 0; -+ if (n > entries) -+ n = entries; -+ -+ r->cons.head = cons_head + n; -+ -+ __rte_ring_dequeue_elems(r, cons_head, obj_table, sizeof(void *), n); -+ return n; -+} -+ -+static inline -+void st_ring_dequeue_burst_finish(struct mbox_ring *mr) -+{ -+ mr->ring->cons.tail = mr->ring->cons.head; -+} -+ -+static inline -+unsigned st_ring_enqueue_burst(struct mbox_ring *mr, void *const *obj_table, unsigned n) -+{ -+ n = st_ring_enqueue_burst_start(mr, obj_table, n); -+ st_ring_enqueue_burst_finish(mr); -+ return n; -+} -+ -+static inline -+unsigned st_ring_dequeue_burst(struct mbox_ring *mr, void **obj_table, unsigned n) -+{ -+ n = st_ring_dequeue_burst_start(mr, obj_table, n); -+ st_ring_dequeue_burst_finish(mr); -+ return n; -+} -+ -+static inline -+void *st_ring_read_tail(const struct mbox_ring *mr) -+{ -+ return mr->st_obj; -+} -+ -+static inline -+void st_ring_push_tail(struct mbox_ring *mr, void *obj) -+{ -+ mr->st_obj = obj; -+} -+ -+static inline -+void *st_ring_pop_tail(struct mbox_ring *mr, void *expect) -+{ -+ expect = mr->st_obj; -+ mr->st_obj = NULL; -+ return expect; -+} -+ -+static inline -+void st_ring_ops_init(struct mbox_ring_ops *ops) -+{ -+ ops->create = st_ring_create; -+ ops->destroy = st_ring_destroy; -+ -+ ops->get_capacity = st_ring_get_capacity; -+ ops->count = st_ring_count; -+ ops->free_count = st_ring_free_count; -+ -+ ops->enqueue_burst = st_ring_enqueue_burst; -+ ops->dequeue_burst = st_ring_dequeue_burst; -+ -+ ops->recv_count = st_ring_count; -+ ops->recv_start_burst = st_ring_dequeue_burst_start; -+ ops->recv_finish_burst = st_ring_dequeue_burst_finish; -+ -+ ops->read_tail = st_ring_read_tail; -+ ops->push_tail = st_ring_push_tail; -+ ops->pop_tail = st_ring_pop_tail; -+} -+ -+ -+/* multi thread */ -+static inline -+int mt_ring_create(struct mbox_ring *mr, const char *name, unsigned count) -+{ -+ mbox_ring_common_init(mr); -+ -+ if ((mr->flags & MBOX_FLAG_TCP) && (mr->flags & MBOX_FLAG_SEND)) { -+ mr->ops = &g_mbox_rtw_append_ops; -+ rte_atomic64_init(&mr->mt_obj); -+ } else { -+ mr->ops = &g_mbox_rtw_default_ops; -+ mr->st_obj = NULL; -+ } -+ if ((mr->flags & MBOX_FLAG_RECV) && !dpdk_nic_is_xdp()) { -+ mr->flags |= MBOX_FLAG_PEEK; -+ mr->ops = &g_mbox_rtw_peek_ops; -+ mr->ops->create(mr, name, count); -+ } -+ -+ mr->ring = rte_ring_create_fast(name, count, RING_F_SP_ENQ | RING_F_SC_DEQ); -+ if (mr->ring == NULL) { -+ return -ENOMEM; -+ } -+ return 0; -+} -+ -+static inline -+void mt_ring_destroy(struct mbox_ring *mr) -+{ -+ if (mr->flags & MBOX_FLAG_PEEK) { -+ mr->ops->destroy(mr); -+ } -+ mbox_ring_common_free(mr); -+ -+ mr->ops = NULL; -+ if ((mr->flags & MBOX_FLAG_TCP) && (mr->flags & MBOX_FLAG_SEND)) { -+ rte_atomic64_clear(&mr->mt_obj); -+ } else { -+ mr->st_obj = NULL; -+ } -+ -+ if (mr->ring != NULL) { -+ rte_ring_free_fast(mr->ring); -+ mr->ring = NULL; -+ } -+} -+ -+static inline -+unsigned mt_ring_get_capacity(const struct mbox_ring *mr) -+{ -+ return mr->ring->capacity; -+} -+ -+static inline -+unsigned mt_ring_count(const struct mbox_ring *mr) -+{ -+ // return rte_ring_count(mr->ring); -+ struct rte_ring *r = mr->ring; -+ uint32_t prod_tail = r->prod.tail; -+ uint32_t cons_head = r->cons.head; -+ uint32_t count = (prod_tail - cons_head) & r->mask; -+ return (count > r->capacity) ? r->capacity : count; -+} -+ -+static inline -+unsigned mt_ring_free_count(const struct mbox_ring *mr) -+{ -+ return mt_ring_get_capacity(mr) - mt_ring_count(mr); -+} -+ -+static inline -+unsigned mt_ring_enqueue_burst_start(struct mbox_ring *mr, void *const *obj_table, unsigned n) -+{ -+ struct rte_ring *r = mr->ring; -+ uint32_t prod_head, cons_tail; -+ uint32_t free_entries; -+ -+ prod_head = r->prod.head; -+ cons_tail = __atomic_load_n(&r->cons.tail, __ATOMIC_ACQUIRE); -+ -+ free_entries = r->capacity + cons_tail - prod_head; -+ if (unlikely(free_entries == 0)) -+ return 0; -+ if (n > free_entries) -+ n = free_entries; -+ -+ r->prod.head = prod_head + n; -+ -+ __rte_ring_enqueue_elems(r, prod_head, obj_table, sizeof(void *), n); -+ return n; -+} -+ -+static inline -+void mt_ring_enqueue_burst_finish(struct mbox_ring *mr) -+{ -+ __atomic_store_n(&mr->ring->prod.tail, mr->ring->prod.head, __ATOMIC_RELEASE); -+} -+ -+static inline -+unsigned mt_ring_dequeue_burst_start(struct mbox_ring *mr, void ** obj_table, unsigned n) -+{ -+ struct rte_ring *r = mr->ring; -+ uint32_t cons_head, prod_tail; -+ uint32_t entries; -+ -+ cons_head = r->cons.head; -+ prod_tail = __atomic_load_n(&r->prod.tail, __ATOMIC_ACQUIRE); -+ -+ entries = prod_tail - cons_head; -+ if (unlikely(entries == 0)) -+ return 0; -+ if (n > entries) -+ n = entries; -+ -+ r->cons.head = cons_head + n; -+ -+ __rte_ring_dequeue_elems(r, cons_head, obj_table, sizeof(void *), n); -+ return n; -+} -+ -+static inline -+void mt_ring_dequeue_burst_finish(struct mbox_ring *mr) -+{ -+ __atomic_store_n(&mr->ring->cons.tail, mr->ring->cons.head, __ATOMIC_RELEASE); -+} -+ -+static inline -+unsigned mt_ring_enqueue_burst(struct mbox_ring *mr, void *const *obj_table, unsigned n) -+{ -+ // return rte_ring_sp_enqueue_burst(mr->ring, obj_table, n, NULL); -+ n = mt_ring_enqueue_burst_start(mr, obj_table, n); -+ mt_ring_enqueue_burst_finish(mr); -+ return n; -+} -+ -+static inline -+unsigned mt_ring_dequeue_burst(struct mbox_ring *mr, void **obj_table, unsigned n) -+{ -+ // return rte_ring_sc_dequeue_burst(mr->ring, obj_table, n, NULL); -+ n = mt_ring_dequeue_burst_start(mr, obj_table, n); -+ mt_ring_dequeue_burst_finish(mr); -+ return n; -+} -+ -+static inline -+void *mt_ring_read_tail(const struct mbox_ring *mr) -+{ -+ return (void *)rte_atomic64_read((rte_atomic64_t *)&mr->mt_obj); -+} -+ -+static inline -+void mt_ring_push_tail(struct mbox_ring *mr, void *obj) -+{ -+ rte_atomic64_set(&mr->mt_obj, (uint64_t )obj); -+} -+ -+static inline -+void *mt_ring_pop_tail(struct mbox_ring *mr, void *expect) -+{ -+ if (expect == NULL) { -+ expect = (void *)rte_atomic64_exchange((volatile uint64_t *)&mr->mt_obj.cnt, -+ (uint64_t)NULL); -+ return expect; -+ } -+ -+ int ret = rte_atomic64_cmpset((volatile uint64_t *)&mr->mt_obj.cnt, -+ (uint64_t)expect, (uint64_t)NULL); -+ if (ret == 0) /* mt_obj != expect, cmpset failed */ -+ return NULL; -+ return expect; -+} -+ -+static inline -+void mt_ring_ops_init(struct mbox_ring_ops *ops) -+{ -+ ops->create = mt_ring_create; -+ ops->destroy = mt_ring_destroy; -+ -+ ops->get_capacity = mt_ring_get_capacity; -+ ops->count = mt_ring_count; -+ ops->free_count = mt_ring_free_count; -+ -+ ops->enqueue_burst = mt_ring_enqueue_burst; -+ ops->dequeue_burst = mt_ring_dequeue_burst; -+ -+ ops->recv_count = mt_ring_count; -+ ops->recv_start_burst = mt_ring_dequeue_burst_start; -+ ops->recv_finish_burst = mt_ring_dequeue_burst_finish; -+ -+ ops->read_tail = mt_ring_read_tail; -+ ops->push_tail = mt_ring_push_tail; -+ ops->pop_tail = mt_ring_pop_tail; -+} -+ -+/* multi thread & peek */ -+static inline -+int pk_ring_create(struct mbox_ring *mr, const char *name, unsigned count) -+{ -+ return 0; -+} -+ -+static inline -+void pk_ring_destroy(struct mbox_ring *mr) -+{ -+ void *obj; -+ while (mr->ops->recv_start_burst(mr, &obj, 1) > 0) { -+ mr->ops->recv_finish_burst(mr); -+ } -+ return; -+} -+ -+extern void sockio_peek_recv_free(struct mbox_ring *mr, unsigned n); -+static inline -+unsigned pk_ring_enqueue_burst(struct mbox_ring *mr, void *const *obj_table, unsigned n) -+{ -+ n = gazelle_ring_sp_enqueue(mr->ring, obj_table, n); -+ if (mr->flags & MBOX_FLAG_RECV) -+ sockio_peek_recv_free(mr, n); -+ return n; -+} -+ -+static inline -+unsigned pk_ring_dequeue_burst(struct mbox_ring *mr, void **obj_table, unsigned n) -+{ -+ return gazelle_ring_sc_dequeue(mr->ring, obj_table, n); -+} -+ -+static inline -+unsigned pk_ring_peek_start_burst(struct mbox_ring *mr, void **obj_table, unsigned n) -+{ -+ return gazelle_ring_read(mr->ring, obj_table, n); -+} -+static inline -+void pk_ring_peek_finish_burst(struct mbox_ring *mr) -+{ -+ gazelle_ring_read_over(mr->ring); -+} -+ -+static inline -+unsigned pk_ring_get_capacity(const struct mbox_ring *mr) -+{ -+ return mr->ring->capacity; -+} -+static inline -+unsigned pk_ring_count(const struct mbox_ring *mr) -+{ -+ return gazelle_ring_count(mr->ring); -+} -+static inline -+unsigned pk_ring_free_count(const struct mbox_ring *mr) -+{ -+ return gazelle_ring_free_count(mr->ring); -+} -+ -+static inline -+unsigned pk_ring_peek_start_count(const struct mbox_ring *mr) -+{ -+ return gazelle_ring_readable_count(mr->ring); -+} -+static inline -+unsigned pk_ring_peek_finish_count(const struct mbox_ring *mr) -+{ -+ return gazelle_ring_readover_count(mr->ring); -+} -+ -+static inline -+void pk_ring_ops_init(struct mbox_ring_ops *ops) -+{ -+ ops->create = pk_ring_create; -+ ops->destroy = pk_ring_destroy; -+ -+ ops->get_capacity = pk_ring_get_capacity; -+ ops->count = pk_ring_count; -+ ops->free_count = pk_ring_free_count; -+ -+ ops->enqueue_burst = pk_ring_enqueue_burst; -+ ops->dequeue_burst = pk_ring_dequeue_burst; -+ -+ ops->recv_count = pk_ring_peek_start_count; -+ ops->recv_start_burst = pk_ring_peek_start_burst; -+ ops->recv_finish_burst = pk_ring_peek_finish_burst; -+ -+ ops->read_tail = st_ring_read_tail; -+ ops->push_tail = st_ring_push_tail; -+ ops->pop_tail = st_ring_pop_tail; -+} -+ -+static inline -+void mbox_ring_ops_init(void) -+{ -+ st_ring_ops_init(&g_mbox_rtc_default_ops); -+ -+ mt_ring_ops_init(&g_mbox_rtw_append_ops); -+ mt_ring_ops_init(&g_mbox_rtw_default_ops); -+ /* rtw udp don't need to append data.*/ -+ g_mbox_rtw_default_ops.read_tail = st_ring_read_tail; -+ g_mbox_rtw_default_ops.pop_tail = st_ring_pop_tail; -+ g_mbox_rtw_default_ops.push_tail = st_ring_push_tail; -+ -+ pk_ring_ops_init(&g_mbox_rtw_peek_ops); -+ -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ g_mbox_default_ops = &g_mbox_rtc_default_ops; -+ } else { -+ g_mbox_default_ops = &g_mbox_rtw_default_ops; -+ } -+} -+ -+#endif /* __MBOX_RING_H__ */ --- -2.33.0 - diff --git a/0329-socket-adapt-to-tcp-and-udp.patch b/0329-socket-adapt-to-tcp-and-udp.patch deleted file mode 100644 index cc1d8e718bed1ccc9d9ddf5021f7ffc2b3584218..0000000000000000000000000000000000000000 --- a/0329-socket-adapt-to-tcp-and-udp.patch +++ /dev/null @@ -1,5305 +0,0 @@ -From 3413b74afd91914682fc494defe17d057db8e2d2 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 21 Mar 2025 17:05:48 +0800 -Subject: [PATCH] socket: adapt to tcp and udp - -Signed-off-by: Lemmy Huang ---- - src/common/dpdk_common.h | 11 +- - src/common/gazelle_dfx_msg.h | 30 +- - src/common/gazelle_opt.h | 6 - - src/common/gazelle_reg_msg.h | 1 - - src/lstack/api/lstack_rtc_api.c | 46 - - src/lstack/api/lstack_rtw_api.c | 500 ------- - ...lstack_dummy_api.c => lstack_sock_dummy.c} | 2 +- - src/lstack/api/lstack_sockctl.c | 25 +- - src/lstack/api/lstack_wrap.c | 69 +- - src/lstack/core/lstack_cfg.c | 47 +- - src/lstack/core/lstack_control_plane.c | 38 +- - src/lstack/core/lstack_dpdk.c | 174 +-- - src/lstack/core/lstack_lwip.c | 1286 ----------------- - src/lstack/core/lstack_mempool.c | 23 +- - src/lstack/core/lstack_preload.c | 11 +- - src/lstack/core/lstack_protocol_stack.c | 63 +- - src/lstack/core/lstack_stack_stat.c | 122 +- - src/lstack/core/lstack_thread_rpc.c | 821 ++--------- - src/lstack/core/lstack_virtio.c | 3 +- - src/lstack/core/lstack_wait.c | 26 +- - src/lstack/core/same_node.c | 22 +- - src/lstack/include/lstack_cfg.h | 6 +- - src/lstack/include/lstack_dpdk.h | 20 +- - src/lstack/include/lstack_dummy_api.h | 23 - - src/lstack/include/lstack_lwip.h | 62 - - src/lstack/include/lstack_mempool.h | 2 +- - src/lstack/include/lstack_protocol_stack.h | 11 - - src/lstack/include/lstack_rtc_api.h | 25 - - .../{lstack_rtw_api.h => lstack_sock_dummy.h} | 10 +- - src/lstack/include/lstack_stack_stat.h | 16 +- - src/lstack/include/lstack_thread_rpc.h | 63 +- - src/lstack/include/mbox_ring.h | 2 +- - src/lstack/include/same_node.h | 1 - - src/lstack/netif/lstack_ethdev.c | 76 +- - src/lstack/netif/lstack_fault_inject.c | 20 +- - src/lstack/netif/lstack_flow.c | 15 +- - src/lstack/netif/lstack_vdev.c | 11 +- - src/ltran/ltran_dfx.c | 34 +- - src/ltran/ltran_forward.c | 2 +- - 39 files changed, 492 insertions(+), 3233 deletions(-) - delete mode 100644 src/lstack/api/lstack_rtc_api.c - delete mode 100644 src/lstack/api/lstack_rtw_api.c - rename src/lstack/api/{lstack_dummy_api.c => lstack_sock_dummy.c} (98%) - delete mode 100644 src/lstack/core/lstack_lwip.c - delete mode 100644 src/lstack/include/lstack_dummy_api.h - delete mode 100644 src/lstack/include/lstack_lwip.h - delete mode 100644 src/lstack/include/lstack_rtc_api.h - rename src/lstack/include/{lstack_rtw_api.h => lstack_sock_dummy.h} (77%) - -diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h -index 8609216..cff193c 100644 ---- a/src/common/dpdk_common.h -+++ b/src/common/dpdk_common.h -@@ -40,8 +40,7 @@ struct latency_timestamp { - struct mbuf_private { - /* struct pbuf_custom must at first */ - struct pbuf_custom pc; -- /* don't use `struct tcp_seg` directly to avoid conflicts by include lwip tcp header */ -- char ts[32]; // 32 > sizeof(struct tcp_seg) -+ int stack_id; /* the stack to which buf belongs */ - struct latency_timestamp lt; - }; - -@@ -49,13 +48,9 @@ static __rte_always_inline struct mbuf_private *mbuf_to_private(const struct rte - { - return (struct mbuf_private *)RTE_PTR_ADD(m, sizeof(struct rte_mbuf)); - } --static __rte_always_inline struct pbuf_custom *mbuf_to_pbuf(const struct rte_mbuf *m) -+static __rte_always_inline struct pbuf *mbuf_to_pbuf(const struct rte_mbuf *m) - { -- return &mbuf_to_private(m)->pc; --} --static __rte_always_inline struct rte_mbuf *pbuf_to_mbuf(const struct pbuf *p) --{ -- return (struct rte_mbuf *)RTE_PTR_SUB(p, sizeof(struct rte_mbuf)); -+ return &mbuf_to_private(m)->pc.pbuf; - } - static __rte_always_inline struct mbuf_private *pbuf_to_private(const struct pbuf *p) - { -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 1a89e65..2c6462d 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -72,10 +72,9 @@ enum GAZELLE_STAT_MODE { - - enum GAZELLE_LATENCY_TYPE { - GAZELLE_LATENCY_INTO_MBOX, // t0 -> t1 -- GAZELLE_LATENCY_READ_LWIP, // t1 -> t2 -- GAZELLE_LATENCY_READ_APP_CALL, // t2 -> t3 -- GAZELLE_LATENCY_READ_LSTACK, // t3 -> t4 -- GAZELLE_LATENCY_READ_MAX, // t0 -> t4 -+ GAZELLE_LATENCY_READ_APP_CALL, // t1 -> t2 -+ GAZELLE_LATENCY_READ_LSTACK, // t2 -> t3 -+ GAZELLE_LATENCY_READ_MAX, // t0 -> t3 - - GAZELLE_LATENCY_WRITE_INTO_RING, // t0 -> t1 - GAZELLE_LATENCY_WRITE_LWIP, // t1 -> t2 -@@ -123,12 +122,12 @@ struct gazelle_wakeup_stat { - }; - - struct gazelle_stack_aggregate_stats { -- /* 0: RX, 1: TX, 2: APP_TX */ -- uint32_t size_1_64[3]; -- uint32_t size_65_512[3]; -- uint32_t size_513_1460[3]; -- uint32_t size_1461_8192[3]; -- uint32_t size_8193_max[3]; -+ /* 0: RX, 1: TX */ -+ uint32_t size_1_64[2]; -+ uint32_t size_65_512[2]; -+ uint32_t size_513_1460[2]; -+ uint32_t size_1461_8192[2]; -+ uint32_t size_8193_max[2]; - - uint64_t rx_bytes; - uint64_t tx_bytes; -@@ -138,7 +137,6 @@ struct gazelle_stat_pkts { - uint16_t conn_num; - uint32_t mbufpool_avail_cnt; - uint64_t call_msg_cnt; -- uint64_t recv_list_cnt; - uint64_t call_alloc_fail; - struct gazelle_stack_stat stack_stat; - struct gazelle_wakeup_stat wakeup_stat; -@@ -257,15 +255,17 @@ struct gazelle_stat_lstack_proto { - - struct gazelle_stat_lstack_conn_info { - uint32_t state; -+ uint32_t tcp_sub_state; -+ - gz_addr_t rip; - gz_addr_t lip; - uint16_t r_port; - uint16_t l_port; - uint32_t in_send; -- uint32_t recv_cnt; -- uint32_t send_ring_cnt; -- uint32_t recv_ring_cnt; -- uint32_t tcp_sub_state; -+ uint32_t recvmbox_cnt; -+ uint16_t recvmbox_tail; -+ uint32_t sendmbox_cnt; -+ uint16_t sendmbox_tail; - - uint32_t cwn; - uint32_t rcv_wnd; -diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h -index 4406831..86eb874 100644 ---- a/src/common/gazelle_opt.h -+++ b/src/common/gazelle_opt.h -@@ -56,12 +56,6 @@ - #define STACK_THREAD_DEFAULT 4 - #define STACK_NIC_READ_DEFAULT 128 - --#define MTU_DEFAULT_DATA_LEN 1460 --#define VLAN_HEAD_LEN 4 --#define IPV6_EXTRA_HEAD_LEN 20 --#define MBUF_MAX_DATA_LEN (MTU_DEFAULT_DATA_LEN - VLAN_HEAD_LEN - IPV6_EXTRA_HEAD_LEN) -- --#define GAZELLE_UDP_PKGLEN_MAX (65535 - IP_HLEN - UDP_HLEN) - - /* total:33 client, index 32 is invaild client */ - #define GAZELLE_CLIENT_NUM_ALL 33 -diff --git a/src/common/gazelle_reg_msg.h b/src/common/gazelle_reg_msg.h -index ecd1e35..f573390 100644 ---- a/src/common/gazelle_reg_msg.h -+++ b/src/common/gazelle_reg_msg.h -@@ -33,7 +33,6 @@ - #define OPT_VDEV "--vdev" - #define VDEV_ARG_IFACE "iface" - --#define GAZELLE_MAX_NUMA_NODES 8 - #define SOCKET_MEM_STRLEN (GAZELLE_MAX_NUMA_NODES * 10) - - /* types for msg from lstack to ltran */ -diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c -deleted file mode 100644 -index 4a962e1..0000000 ---- a/src/lstack/api/lstack_rtc_api.c -+++ /dev/null -@@ -1,46 +0,0 @@ --/* --* 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 --#include -- --#include "lstack_log.h" --#include "lstack_rtc_api.h" -- -- --void rtc_api_init(posix_api_t *api) --{ -- api->close_fn = lwip_close; -- api->shutdown_fn = lwip_shutdown; -- api->socket_fn = lwip_socket; -- api->accept_fn = lwip_accept; -- api->accept4_fn = lwip_accept4; -- api->bind_fn = lwip_bind; -- api->listen_fn = lwip_listen; -- api->connect_fn = lwip_connect; -- -- api->setsockopt_fn = lwip_setsockopt; -- api->getsockopt_fn = lwip_getsockopt; -- api->getpeername_fn = lwip_getpeername; -- api->getsockname_fn = lwip_getsockname; -- -- api->read_fn = lwip_read; -- api->readv_fn = lwip_readv; -- api->write_fn = lwip_write; -- api->writev_fn = lwip_writev; -- api->recv_fn = lwip_recv; -- api->send_fn = lwip_send; -- api->recvmsg_fn = lwip_recvmsg; -- api->sendmsg_fn = lwip_sendmsg; -- api->recvfrom_fn = lwip_recvfrom; -- api->sendto_fn = lwip_sendto; --} -diff --git a/src/lstack/api/lstack_rtw_api.c b/src/lstack/api/lstack_rtw_api.c -deleted file mode 100644 -index 7b8dec2..0000000 ---- a/src/lstack/api/lstack_rtw_api.c -+++ /dev/null -@@ -1,500 +0,0 @@ --/* --* 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 --#include -- --#include "common/gazelle_base_func.h" --#include "lstack_log.h" --#include "lstack_cfg.h" --#include "lstack_thread_rpc.h" --#include "lstack_protocol_stack.h" --#include "lstack_lwip.h" --#include "lstack_rtw_api.h" --#include "lstack_epoll.h" --#include "lstack_wait.h" -- --/* when fd is listenfd, listenfd of all protocol stack thread will be closed */ --static int stack_broadcast_close(int fd) --{ -- int ret = 0; -- struct protocol_stack *stack; -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- -- do { -- if (POSIX_IS_CLOSED(sock)) { -- break; -- } -- stack = get_protocol_stack_by_id(sock->stack_id); -- if (stack == NULL || rpc_call_close(&stack->rpc_queue, fd)) { -- ret = -1; -- } -- -- sock = sock->listen_next; -- fd = sock->conn->callback_arg.socket; -- } while (1); -- -- return ret; --} -- --static int stack_broadcast_shutdown(int fd, int how) --{ -- int32_t ret = 0; -- struct protocol_stack *stack; -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- -- do { -- if (POSIX_IS_CLOSED(sock)) { -- break; -- } -- stack = get_protocol_stack_by_id(sock->stack_id); -- if (stack == NULL || rpc_call_shutdown(&stack->rpc_queue, fd, how)) { -- ret = -1; -- } -- -- sock = sock->listen_next; -- fd = sock->conn->callback_arg.socket; -- } while (1); -- -- return ret; --} -- --/* choice one stack bind */ --static int stack_single_bind(int fd, const struct sockaddr *name, socklen_t namelen) --{ -- struct protocol_stack *stack; -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- stack = get_protocol_stack_by_id(sock->stack_id); -- return rpc_call_bind(&stack->rpc_queue, fd, name, namelen); --} -- --/* bind sync to all protocol stack thread, so that any protocol stack thread can build connect */ --static int stack_broadcast_bind(int fd, const struct sockaddr *name, socklen_t namelen) --{ -- struct protocol_stack *cur_stack; -- struct protocol_stack *stack = NULL; -- int ret, clone_fd; -- -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "tid %d, %d get sock null or stack null\n", rte_gettid(), fd); -- GAZELLE_RETURN(EBADF); -- } -- -- cur_stack = get_protocol_stack_by_id(sock->stack_id); -- ret = rpc_call_bind(&cur_stack->rpc_queue, fd, name, namelen); -- if (ret < 0) { -- close(fd); -- return ret; -- } -- -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- for (int i = 0; i < stack_group->stack_num; ++i) { -- stack = stack_group->stacks[i]; -- if (stack != cur_stack) { -- clone_fd = rpc_call_shadow_fd(&stack->rpc_queue, fd, name, namelen); -- if (clone_fd < 0) { -- stack_broadcast_close(fd); -- return clone_fd; -- } -- } -- } -- return 0; --} -- --static struct lwip_sock *get_min_accept_sock(int fd) --{ -- struct lwip_sock *sock; -- struct lwip_sock *min_sock = NULL; -- -- for (sock = lwip_get_socket(fd); sock != NULL; sock = sock->listen_next) { -- if (!netconn_is_nonblocking(sock->conn)) { -- /* init all sock sk_wait */ -- if (unlikely(sock->sk_wait == NULL) || sock->sk_wait->type == WAIT_CLOSE) { -- sock->sk_wait = poll_construct_wait(0); -- } -- if (!(sock->sk_wait->type & WAIT_BLOCK)) { -- sock->sk_wait->type |= WAIT_BLOCK; -- } -- } -- -- if (!sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_RCVPLUS, 0)) { -- continue; -- } -- -- if (min_sock == NULL || -- get_protocol_stack_by_id(min_sock->stack_id)->conn_num > get_protocol_stack_by_id(sock->stack_id)->conn_num) { -- min_sock = sock; -- } -- } -- -- return min_sock; --} -- --/* ergodic the protocol stack thread to find the connection, because all threads are listening */ --static int stack_broadcast_accept4(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags) --{ -- int ret = -1; -- struct lwip_sock *min_sock = NULL; -- struct lwip_sock *sock = lwip_get_socket(fd); -- struct protocol_stack *stack = NULL; -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- -- min_sock = get_min_accept_sock(fd); -- if (min_sock == NULL) { -- if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & SOCK_NONBLOCK))) { -- min_sock = get_min_accept_sock(fd); -- } -- } -- -- if (!POSIX_IS_CLOSED(min_sock)) { -- stack = get_protocol_stack_by_id(min_sock->stack_id); -- ret = rpc_call_accept(&stack->rpc_queue, min_sock->conn->callback_arg.socket, addr, addrlen, flags); -- } -- -- if (ret < 0) { -- errno = EAGAIN; -- } -- return ret; --} -- --static int stack_broadcast_accept(int fd, struct sockaddr *addr, socklen_t *addrlen) --{ -- return stack_broadcast_accept4(fd, addr, addrlen, 0); --} -- --/* choice one stack listen */ --static int stack_single_listen(int fd, int backlog) --{ -- struct protocol_stack *stack; -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- stack = get_protocol_stack_by_id(sock->stack_id); -- return rpc_call_listen(&stack->rpc_queue, fd, backlog); --} -- --/* listen sync to all protocol stack thread, so that any protocol stack thread can build connect */ --static int stack_broadcast_listen(int fd, int backlog) --{ -- typedef union sockaddr_union { -- struct sockaddr sa; -- struct sockaddr_in in; -- struct sockaddr_in6 in6; -- } sockaddr_t; -- -- struct protocol_stack *cur_stack; -- struct protocol_stack *stack = NULL; -- sockaddr_t addr; -- socklen_t addr_len = sizeof(addr); -- int ret, clone_fd; -- -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "tid %d, %d get sock null or stack null\n", rte_gettid(), fd); -- GAZELLE_RETURN(EBADF); -- } -- -- cur_stack = get_protocol_stack_by_id(sock->stack_id); -- ret = rpc_call_getsockname(&cur_stack->rpc_queue, fd, (struct sockaddr *)&addr, &addr_len); -- if (ret != 0) { -- return ret; -- } -- -- struct protocol_stack_group *stack_group = get_protocol_stack_group(); --#if GAZELLE_TCP_REUSE_IPPORT -- int min_conn_stk_idx = get_min_conn_stack(stack_group); --#endif -- for (int32_t i = 0; i < stack_group->stack_num; ++i) { -- stack = stack_group->stacks[i]; -- if (stack != cur_stack) { -- clone_fd = rpc_call_shadow_fd(&stack->rpc_queue, fd, (struct sockaddr *)&addr, addr_len); -- if (clone_fd < 0) { -- stack_broadcast_close(fd); -- return clone_fd; -- } -- } else { -- clone_fd = fd; -- } --#if GAZELLE_TCP_REUSE_IPPORT -- if (min_conn_stk_idx == i) { -- lwip_get_socket(clone_fd)->conn->is_master_fd = 1; -- } else { -- lwip_get_socket(clone_fd)->conn->is_master_fd = 0; -- } --#endif -- ret = rpc_call_listen(&stack->rpc_queue, clone_fd, backlog); -- if (ret < 0) { -- stack_broadcast_close(fd); -- return ret; -- } -- } -- return 0; --} -- --static int rtw_socket(int domain, int type, int protocol) --{ -- struct protocol_stack *stack = get_bind_protocol_stack(); -- if (stack == NULL) { -- GAZELLE_RETURN(EINVAL); -- } -- return rpc_call_socket(&stack->rpc_queue, domain, type, protocol); --} -- --static int rtw_accept(int s, struct sockaddr *addr, socklen_t *addrlen) --{ -- return stack_broadcast_accept(s, addr, addrlen); --} -- --static int rtw_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) --{ -- return stack_broadcast_accept4(s, addr, addrlen, flags); --} -- --static int rtw_bind(int s, const struct sockaddr *name, socklen_t namelen) --{ -- struct lwip_sock *sock = lwip_get_socket(s); -- -- if (NETCONN_IS_UDP(sock) && get_global_cfg_params()->listen_shadow) { -- return stack_broadcast_bind(s, name, namelen); -- } else { -- return stack_single_bind(s, name, namelen); -- } --} -- --static int rtw_listen(int s, int backlog) --{ -- if (!get_global_cfg_params()->tuple_filter && -- !get_global_cfg_params()->listen_shadow) { -- return stack_single_listen(s, backlog); -- } else { -- return stack_broadcast_listen(s, backlog); -- } --} -- --static int rtw_connect(int s, const struct sockaddr *name, socklen_t namelen) --{ -- struct protocol_stack *stack; -- struct lwip_sock *sock = lwip_get_socket(s); -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- stack = get_protocol_stack_by_id(sock->stack_id); -- return rpc_call_connect(&stack->rpc_queue, s, name, namelen); --} -- --static int rtw_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) --{ -- struct protocol_stack *stack; -- struct lwip_sock *sock = lwip_get_socket(s); -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- stack = get_protocol_stack_by_id(sock->stack_id); -- return rpc_call_setsockopt(&stack->rpc_queue, s, level, optname, optval, optlen); --} -- --static int rtw_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) --{ -- struct protocol_stack *stack; -- struct lwip_sock *sock = lwip_get_socket(s); -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- stack = get_protocol_stack_by_id(sock->stack_id); -- return rpc_call_getsockopt(&stack->rpc_queue, s, level, optname, optval, optlen); --} -- --static int rtw_getpeername(int s, struct sockaddr *name, socklen_t *namelen) --{ -- struct protocol_stack *stack; -- struct lwip_sock *sock = lwip_get_socket(s); -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- stack = get_protocol_stack_by_id(sock->stack_id); -- return rpc_call_getpeername(&stack->rpc_queue, s, name, namelen); --} -- --static int rtw_getsockname(int s, struct sockaddr *name, socklen_t *namelen) --{ -- struct protocol_stack *stack; -- struct lwip_sock *sock = lwip_get_socket(s); -- if (sock == NULL) { -- GAZELLE_RETURN(EBADF); -- } -- stack = get_protocol_stack_by_id(sock->stack_id); -- return rpc_call_getsockname(&stack->rpc_queue, s, name, namelen); --} -- --static ssize_t rtw_read(int s, void *mem, size_t len) --{ -- return do_lwip_read_from_stack(s, mem, len, 0, NULL, NULL); --} -- --static ssize_t rtw_readv(int s, const struct iovec *iov, int iovcnt) --{ -- struct msghdr msg; -- -- msg.msg_name = NULL; -- msg.msg_namelen = 0; -- msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov); -- msg.msg_iovlen = iovcnt; -- msg.msg_control = NULL; -- msg.msg_controllen = 0; -- msg.msg_flags = 0; -- return do_lwip_recvmsg_from_stack(s, &msg, 0); --} -- --static ssize_t rtw_write(int s, const void *mem, size_t size) --{ -- return do_lwip_send_to_stack(s, mem, size, 0, NULL, 0); --} -- --static ssize_t rtw_writev(int s, const struct iovec *iov, int iovcnt) --{ -- struct lwip_sock *sock = lwip_get_socket(s); -- struct msghdr msg; -- -- msg.msg_name = NULL; -- msg.msg_namelen = 0; -- msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov); -- msg.msg_iovlen = iovcnt; -- msg.msg_control = NULL; -- msg.msg_controllen = 0; -- msg.msg_flags = 0; -- return do_lwip_sendmsg_to_stack(sock, s, &msg, 0); --} -- --static ssize_t rtw_recv(int sockfd, void *buf, size_t len, int flags) --{ -- return do_lwip_read_from_stack(sockfd, buf, len, flags, NULL, NULL); --} -- --static ssize_t rtw_send(int sockfd, const void *buf, size_t len, int flags) --{ -- return do_lwip_send_to_stack(sockfd, buf, len, flags, NULL, 0); --} -- --static ssize_t rtw_recvmsg(int s, struct msghdr *message, int flags) --{ -- return do_lwip_recvmsg_from_stack(s, message, flags); --} -- --static ssize_t rtw_sendmsg(int s, const struct msghdr *message, int flags) --{ -- struct lwip_sock *sock = lwip_get_socket(s); -- return do_lwip_sendmsg_to_stack(sock, s, message, flags); --} -- --static ssize_t rtw_udp_recvfrom(int sockfd, void *buf, size_t len, int flags, -- struct sockaddr *addr, socklen_t *addrlen) --{ -- struct lwip_sock *sock = lwip_get_socket(sockfd); -- int ret; -- -- while (1) { -- ret = do_lwip_read_from_stack(sockfd, buf, len, flags, addr, addrlen); -- if (ret >= 0) { -- return ret; -- } -- if (ret < 0 && errno != EAGAIN) { -- return -1; -- } -- sock = sock->listen_next; -- if (!POSIX_IS_CLOSED(sock)) { -- sockfd = sock->conn->callback_arg.socket; -- } else { -- if (sock == NULL) { -- errno = EAGAIN; -- return -1; -- } else { -- errno = ENOTCONN; -- return -1; -- } -- } -- } --} -- --static inline ssize_t rtw_tcp_recvfrom(int sockfd, void *buf, size_t len, int flags, -- struct sockaddr *addr, socklen_t *addrlen) --{ -- return do_lwip_read_from_stack(sockfd, buf, len, flags, addr, addrlen); --} -- -- --static ssize_t rtw_recvfrom(int sockfd, void *buf, size_t len, int flags, -- struct sockaddr *addr, socklen_t *addrlen) --{ -- struct lwip_sock *sock = lwip_get_socket(sockfd); -- if (NETCONN_IS_UDP(sock)) { -- return rtw_udp_recvfrom(sockfd, buf, len, flags, addr, addrlen); -- } else { -- return rtw_tcp_recvfrom(sockfd, buf, len, flags, addr, addrlen); -- } --} -- --static ssize_t rtw_sendto(int sockfd, const void *buf, size_t len, int flags, -- const struct sockaddr *addr, socklen_t addrlen) --{ -- return do_lwip_send_to_stack(sockfd, buf, len, flags, addr, addrlen); --} -- --static int rtw_close(int s) --{ -- return stack_broadcast_close(s); --} -- --static int rtw_shutdown(int fd, int how) --{ -- return stack_broadcast_shutdown(fd, how); --} -- --void rtw_api_init(posix_api_t *api) --{ -- api->close_fn = rtw_close; -- api->shutdown_fn = rtw_shutdown; -- api->socket_fn = rtw_socket; -- api->accept_fn = rtw_accept; -- api->accept4_fn = rtw_accept4; -- api->bind_fn = rtw_bind; -- api->listen_fn = rtw_listen; -- api->connect_fn = rtw_connect; -- -- api->setsockopt_fn = rtw_setsockopt; -- api->getsockopt_fn = rtw_getsockopt; -- api->getpeername_fn = rtw_getpeername; -- api->getsockname_fn = rtw_getsockname; -- -- api->read_fn = rtw_read; -- api->readv_fn = rtw_readv; -- api->write_fn = rtw_write; -- api->writev_fn = rtw_writev; -- api->recv_fn = rtw_recv; -- api->send_fn = rtw_send; -- api->recvmsg_fn = rtw_recvmsg; -- api->sendmsg_fn = rtw_sendmsg; -- api->recvfrom_fn = rtw_recvfrom; -- api->sendto_fn = rtw_sendto; --} -diff --git a/src/lstack/api/lstack_dummy_api.c b/src/lstack/api/lstack_sock_dummy.c -similarity index 98% -rename from src/lstack/api/lstack_dummy_api.c -rename to src/lstack/api/lstack_sock_dummy.c -index 004a3aa..ce046e3 100644 ---- a/src/lstack/api/lstack_dummy_api.c -+++ b/src/lstack/api/lstack_sock_dummy.c -@@ -85,7 +85,7 @@ static ssize_t dummy_sendto(int sockfd, const void *buf, size_t len, int flags, - return dummy_exit(); - } - --void dummy_api_init(posix_api_t *api) -+void sock_dummy_api_init(posix_api_t *api) - { - api->socket_fn = dummy_socket; - api->send_fn = dummy_send; -diff --git a/src/lstack/api/lstack_sockctl.c b/src/lstack/api/lstack_sockctl.c -index 71310b7..7da7473 100644 ---- a/src/lstack/api/lstack_sockctl.c -+++ b/src/lstack/api/lstack_sockctl.c -@@ -27,9 +27,6 @@ - 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 %d, fd %d fail %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); -- } - } - - static void callback_getsockname(struct rpc_msg *msg) -@@ -191,7 +188,7 @@ static void callback_close(struct rpc_msg *msg) - - if (sockio_mbox_pending(sock)) { - rpc_queue *queue = &get_protocol_stack_by_id(sock->stack_id)->rpc_queue; -- rpc_async_call(queue, msg, RPC_MSG_FREE | RPC_MSG_RECALL); /* until stack_send recall finish */ -+ rpc_async_call(queue, msg, RPC_MSG_RECALL); /* until stack_send recall finish */ - return; - } - -@@ -209,7 +206,7 @@ static void callback_shutdown(struct rpc_msg *msg) - - if (sockio_mbox_pending(sock)) { - rpc_queue *queue = &get_protocol_stack_by_id(sock->stack_id)->rpc_queue; -- rpc_async_call(queue, msg, RPC_MSG_FREE | RPC_MSG_RECALL); -+ rpc_async_call(queue, msg, RPC_MSG_RECALL); - return; - } - -@@ -458,12 +455,15 @@ static int rpc_call_connect(int stack_id, int fd, const struct sockaddr *addr, s - /* for lwip nonblock connected callback */ - void do_lwip_connected_callback(int fd) - { -+ bool has_kernel; - struct lwip_sock *sock = lwip_get_socket(fd); - if (POSIX_IS_CLOSED(sock)) { - return; - } - -- if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { -+ has_kernel = POSIX_HAS_TYPE(sock, POSIX_KERNEL); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); -+ if (has_kernel) { - /* delete kernel event */ - if (sock->sk_wait != NULL) { - posix_api->epoll_ctl_fn(sock->sk_wait->epfd, EPOLL_CTL_DEL, fd, NULL); -@@ -471,10 +471,7 @@ void do_lwip_connected_callback(int fd) - /* shutdown kernel connect, do_connect() has tried both kernel and lwip. */ - posix_api->shutdown_fn(fd, SHUT_RDWR); - } -- -- POSIX_SET_TYPE(sock, POSIX_LWIP); -- -- API_EVENT(sock->conn, NETCONN_EVT_RCVPLUS, 0); -+ return; - } - - /* when fd is listenfd, listenfd of all protocol stack thread will be closed */ -@@ -625,10 +622,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, SOCK_NONBLOCK); -- else -- return stack_broadcast_accept4(fd, addr, addrlen, 0); -+ return stack_broadcast_accept4(fd, addr, addrlen, 0); - } - - /* choice one stack listen */ -@@ -675,9 +669,6 @@ static int stack_broadcast_listen(int fd, int backlog) - - 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->stack_idx, 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 5869d6b..e22937f 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -24,13 +24,13 @@ - #include "common/gazelle_base_func.h" - #include "lstack_log.h" - #include "lstack_cfg.h" --#include "lstack_lwip.h" - #include "lstack_preload.h" - #include "lstack_unistd.h" - #include "lstack_epoll.h" --#include "lstack_rtc_api.h" --#include "lstack_rtw_api.h" --#include "lstack_dummy_api.h" -+#include "lstack_sockctl.h" -+#include "lstack_sockio.h" -+#include "lstack_sock_dummy.h" -+#include "mbox_ring.h" - - #ifndef SOL_XDP - #define SOL_XDP 283 /* same as define in bits/socket.h */ -@@ -47,17 +47,19 @@ void wrap_api_init(void) - g_wrap_api = &g_wrap_api_value; - - if (get_global_cfg_params()->stack_mode_rtc) { -- rtc_api_init(g_wrap_api); -+ sockctl_rtc_api_init(g_wrap_api); - } else { -- rtw_api_init(g_wrap_api); -+ sockctl_rtw_api_init(g_wrap_api); - } - - epoll_api_init(g_wrap_api); -+ sockio_ops_init(); -+ mbox_ring_ops_init(); - } - - void wrap_api_exit(void) - { -- dummy_api_init(g_wrap_api); -+ sock_dummy_api_init(g_wrap_api); - } - - static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *addrlen) -@@ -517,7 +519,7 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - - if (get_global_cfg_params()->stack_mode_rtc) { - if (stack_setup_app_thread() != 0) { -- LSTACK_EXIT(1, "stack_setup_app_thread failed\n"); -+ exit(1); - } - } - -@@ -536,30 +538,16 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - - static inline ssize_t do_recv(int32_t sockfd, void *buf, size_t len, int32_t flags) - { -- if (buf == NULL) { -- GAZELLE_RETURN(EINVAL); -- } -- if (len == 0) { -- return 0; -- } -- - if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -- return g_wrap_api->recv_fn(sockfd, buf, len, flags); -+ return sockio_recv(sockfd, buf, len, flags); - } - return posix_api->recv_fn(sockfd, buf, len, flags); - } - - static inline ssize_t do_read(int32_t s, void *mem, size_t len) - { -- if (mem == NULL) { -- GAZELLE_RETURN(EINVAL); -- } -- if (len == 0) { -- return 0; -- } -- - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return g_wrap_api->read_fn(s, mem, len); -+ return sockio_read(s, mem, len); - } - return posix_api->read_fn(s, mem, len); - } -@@ -567,7 +555,7 @@ static inline ssize_t do_read(int32_t s, void *mem, size_t len) - static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) - { - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return g_wrap_api->readv_fn(s, iov, iovcnt); -+ return sockio_readv(s, iov, iovcnt); - } - return posix_api->readv_fn(s, iov, iovcnt); - } -@@ -575,7 +563,7 @@ static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) - static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32_t flags) - { - if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -- return g_wrap_api->send_fn(sockfd, buf, len, flags); -+ return sockio_send(sockfd, buf, len, flags); - } - return posix_api->send_fn(sockfd, buf, len, flags); - } -@@ -583,7 +571,7 @@ static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32 - static inline ssize_t do_write(int32_t s, const void *mem, size_t size) - { - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return g_wrap_api->write_fn(s, mem, size); -+ return sockio_write(s, mem, size); - } - return posix_api->write_fn(s, mem, size); - } -@@ -591,31 +579,23 @@ static inline ssize_t do_write(int32_t s, const void *mem, size_t size) - static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) - { - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return g_wrap_api->writev_fn(s, iov, iovcnt); -+ return sockio_writev(s, iov, iovcnt); - } - return posix_api->writev_fn(s, iov, iovcnt); - } - - static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flags) - { -- if (message == NULL) { -- GAZELLE_RETURN(EINVAL); -- } -- - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return g_wrap_api->recvmsg_fn(s, message, flags); -+ return sockio_recvmsg(s, message, flags); - } - return posix_api->recvmsg_fn(s, message, flags); - } - - static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_t flags) - { -- if (message == NULL) { -- GAZELLE_RETURN(EINVAL); -- } -- - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return g_wrap_api->sendmsg_fn(s, message, flags); -+ return sockio_sendmsg(s, message, flags); - } - return posix_api->sendmsg_fn(s, message, flags); - } -@@ -623,15 +603,8 @@ static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_ - static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t flags, - struct sockaddr *addr, socklen_t *addrlen) - { -- if (buf == NULL) { -- GAZELLE_RETURN(EINVAL); -- } -- if (len == 0) { -- return 0; -- } -- - if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -- return g_wrap_api->recvfrom_fn(sockfd, buf, len, flags, addr, addrlen); -+ return sockio_recvfrom(sockfd, buf, len, flags, addr, addrlen); - } - return posix_api->recvfrom_fn(sockfd, buf, len, flags, addr, addrlen); - } -@@ -640,7 +613,7 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int - const struct sockaddr *addr, socklen_t addrlen) - { - if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -- return g_wrap_api->sendto_fn(sockfd, buf, len, flags, addr, addrlen); -+ return sockio_sendto(sockfd, buf, len, flags, addr, addrlen); - } - return posix_api->sendto_fn(sockfd, buf, len, flags, addr, addrlen); - } -@@ -688,7 +661,7 @@ static inline int do_epoll_create1(int flags) - - if (get_global_cfg_params()->stack_mode_rtc) { - if (stack_setup_app_thread() != 0) { -- LSTACK_EXIT(1, "stack_setup_app_thread failed\n"); -+ exit(1); - } - } - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 04ceb89..432e4db 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -14,6 +14,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -28,9 +29,7 @@ - #include - - #include --#include --#include --#include -+#include - - #include "common/gazelle_reg_msg.h" - #include "common/gazelle_base_func.h" -@@ -65,13 +64,10 @@ static int32_t parse_kni_switch(void); - static int32_t parse_listen_shadow(void); - static int32_t parse_main_thread_affinity(void); - static int32_t parse_unix_prefix(void); --static int32_t parse_read_connect_number(void); - static int32_t parse_rpc_number(void); - static int32_t parse_nic_read_number(void); - static int32_t parse_tcp_conn_count(void); - static int32_t parse_mbuf_count_per_conn(void); --static int32_t parse_send_ring_size(void); --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); -@@ -123,8 +119,6 @@ static struct config_vector_t g_config_tbl[] = { - { "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 }, - { "app_bind_numa", parse_app_bind_numa }, - { "stack_num", parse_stack_num }, -@@ -142,7 +136,6 @@ 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 }, -- { "read_connect_number", parse_read_connect_number }, - { "rpc_number", parse_rpc_number }, - { "nic_read_number", parse_nic_read_number }, - { "num_process", parse_num_process }, -@@ -1012,22 +1005,6 @@ static int32_t parse_tcp_conn_count(void) - return ret; - } - --static int32_t parse_send_ring_size(void) --{ -- int32_t ret; -- /* send ring size default value is 32 */ -- PARSE_ARG(g_config_params.send_ring_size, "send_ring_size", 32, 1, SOCK_SEND_RING_SIZE_MAX, ret); -- return ret; --} -- --static int32_t parse_recv_ring_size(void) --{ -- int32_t ret; -- /* recv ring size default value is 128 */ -- PARSE_ARG(g_config_params.recv_ring_size, "recv_ring_size", 128, 1, SOCK_RECV_RING_SIZE_MAX, ret); -- return ret; --} -- - static int32_t parse_mbuf_count_per_conn(void) - { - int32_t ret; -@@ -1036,13 +1013,6 @@ static int32_t parse_mbuf_count_per_conn(void) - return ret; - } - --static int32_t parse_read_connect_number(void) --{ -- int32_t ret; -- PARSE_ARG(g_config_params.read_connect_number, "read_connect_number", -- STACK_THREAD_DEFAULT, 1, INT32_MAX, ret); -- return ret; --} - - static int32_t parse_rpc_number(void) - { -@@ -1126,6 +1096,16 @@ static int32_t parse_conf_file(const char *path) - return 0; - } - -+static void lwip_conf_init(void) -+{ -+ const struct cfg_params *cfg = get_global_cfg_params(); -+ -+ struct sys_config sys_conf = { -+ .rtc_mode = cfg->stack_mode_rtc, -+ }; -+ sys_config_init(&sys_conf); -+} -+ - int32_t cfg_init(void) - { - int32_t ret; -@@ -1145,8 +1125,9 @@ int32_t cfg_init(void) - } - - ret = parse_conf_file(config_file); -- - free(config_file); -+ -+ lwip_conf_init(); - return ret; - } - -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index bf34693..9d9e012 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -278,6 +278,8 @@ static int32_t proc_memory_init(const struct reg_response_msg *rsp_msg) - } - - ret = rte_eal_init(lc_argc, lc_argv); -+ /* rte_eal_init() would call __rte_thread_init(), and set _lcore_id. */ -+ RTE_PER_LCORE(_lcore_id) = LCORE_ID_ANY; - if (ret < 0) { - if (rte_errno == EALREADY) - LSTACK_PRE_LOG(LSTACK_INFO, "rte_eal_init aleady init ret=%d\n", ret); -@@ -389,7 +391,7 @@ static int32_t reg_conn(enum GAZELLE_TCP_LIST_STATE table_state, enum reg_ring_t - return 0; - } - --void thread_register_phase1(struct rpc_msg *msg) -+static void thread_register_phase1(struct rpc_msg *msg) - { - int32_t ret; - -@@ -415,7 +417,7 @@ void thread_register_phase1(struct rpc_msg *msg) - msg->result = ret; - } - --void thread_register_phase2(struct rpc_msg *msg) -+static void thread_register_phase2(struct rpc_msg *msg) - { - struct gazelle_stat_lstack_conn *conn = (struct gazelle_stat_lstack_conn *)msg->args[MSG_ARG_0].p; - -@@ -427,6 +429,28 @@ void thread_register_phase2(struct rpc_msg *msg) - msg->result = ret; - } - -+static int rpc_call_thread_regphase1(int stack_id, void *conn) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, thread_register_phase1); -+ if (msg == NULL) { -+ return -1; -+ } -+ msg->args[MSG_ARG_0].p = conn; -+ return rpc_sync_call(queue, msg); -+} -+ -+static int rpc_call_thread_regphase2(int stack_id, void *conn) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, thread_register_phase2); -+ if (msg == NULL) { -+ return -1; -+ } -+ msg->args[MSG_ARG_0].p = conn; -+ return rpc_sync_call(queue, msg); -+} -+ - int32_t client_reg_thrd_ring(void) - { - int32_t ret; -@@ -625,10 +649,9 @@ static int32_t thread_register(void) - /* register all connected conn before listen conn, avoid creating new conn */ - struct protocol_stack_group *stack_group = get_protocol_stack_group(); - for (int32_t i = 0; i < stack_group->stack_num; i++) { -- conn->conn_num = rpc_call_conntable(&stack_group->stacks[i]->rpc_queue, -- conn->conn_list, GAZELLE_LSTACK_MAX_CONN); -+ conn->conn_num = rpc_call_conntable(i, conn->conn_list, GAZELLE_LSTACK_MAX_CONN); - -- ret = rpc_call_thread_regphase1(&stack_group->stacks[i]->rpc_queue, conn); -+ ret = rpc_call_thread_regphase1(i, conn); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "thread_register_phase1 failed ret=%d!\n", ret); - free(conn); -@@ -637,10 +660,9 @@ static int32_t thread_register(void) - } - - for (int32_t i = 0; i < stack_group->stack_num; i++) { -- conn->conn_num = rpc_call_conntable(&stack_group->stacks[i]->rpc_queue, -- conn->conn_list, GAZELLE_LSTACK_MAX_CONN); -+ conn->conn_num = rpc_call_conntable(i, conn->conn_list, GAZELLE_LSTACK_MAX_CONN); - -- ret = rpc_call_thread_regphase2(&stack_group->stacks[i]->rpc_queue, conn); -+ ret = rpc_call_thread_regphase2(i, conn); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "thread_register_phase2 failed ret=%d!\n", ret); - free(conn); -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index fcb78ca..8f896c9 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -38,17 +38,15 @@ - - #include - #include --#include - - #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" - #include "lstack_virtio.h" - #include "lstack_dpdk.h" -+#include "mbox_ring.h" - - struct eth_params { - uint16_t port_id; -@@ -109,6 +107,8 @@ int32_t dpdk_eal_init(void) - struct cfg_params *global_params = get_global_cfg_params(); - - ret = rte_eal_init(global_params->dpdk_argc, global_params->dpdk_argv); -+ /* rte_eal_init() would call __rte_thread_init(), and set _lcore_id. */ -+ RTE_PER_LCORE(_lcore_id) = LCORE_ID_ANY; - if (ret < 0) { - if (rte_errno == EALREADY) { - LSTACK_PRE_LOG(LSTACK_INFO, "rte_eal_init aleady init\n"); -@@ -135,58 +135,6 @@ int32_t dpdk_eal_init(void) - return ret; - } - --struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, -- uint32_t mbuf_cache_size, uint16_t queue_id, unsigned numa_id) --{ -- int32_t ret; -- char pool_name[PATH_MAX]; -- struct rte_mempool *pool; -- -- ret = snprintf_s(pool_name, sizeof(pool_name), PATH_MAX - 1, "%s_%hu", name, queue_id); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d \n", ret); -- return NULL; -- } -- /* limit mbuf max num based on the dpdk capability */ -- if (nb_mbuf > MBUF_MAX_NUM) { -- LSTACK_LOG(ERR, LSTACK, "out of the dpdk mbuf quantity range\n"); -- return NULL; -- } -- -- /* time stamp before pbuf_custom as priv_data */ -- uint16_t private_size = sizeof(struct mbuf_private); -- if (xdp_eth_enabled()) { -- /* reserved for xdp metadata, see struct xsk_tx_metadata in /usr/include/linux/if_xdp.h */ -- private_size += 24; -- } -- private_size = RTE_ALIGN(private_size, RTE_CACHE_LINE_SIZE); -- pool = rte_pktmbuf_pool_create(pool_name, nb_mbuf, mbuf_cache_size, private_size, MBUF_SZ, numa_id); -- if (pool == NULL) { -- LSTACK_LOG(ERR, LSTACK, "cannot create %s pool rte_err=%d\n", pool_name, rte_errno); -- } -- -- return pool; --} -- --static struct rte_mempool* get_pktmbuf_mempool(const char *name, uint16_t queue_id) --{ -- int32_t ret; -- char pool_name[PATH_MAX]; -- struct rte_mempool *pool; -- -- ret = snprintf_s(pool_name, sizeof(pool_name), PATH_MAX - 1, "%s_%hu", name, queue_id); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d\n", ret); -- return NULL; -- } -- pool = rte_mempool_lookup(pool_name); -- if (pool == NULL) { -- LSTACK_LOG(ERR, LSTACK, "look up %s pool rte_err=%d\n", pool_name, rte_errno); -- } -- -- return pool; --} -- - static struct reg_ring_msg *create_reg_mempool(const char *name, uint16_t queue_id) - { - int ret; -@@ -207,115 +155,56 @@ static struct reg_ring_msg *create_reg_mempool(const char *name, uint16_t queue_ - return reg_buf; - } - --int32_t pktmbuf_pool_init(struct protocol_stack *stack) --{ -- stack->rxtx_mbuf_pool = get_pktmbuf_mempool("rxtx_mbuf", stack->queue_id); -- if (stack->rxtx_mbuf_pool == NULL) { -- LSTACK_LOG(ERR, LSTACK, "rxtx_mbuf_pool is NULL\n"); -- return -1; -- } -- -- if (use_ltran()) { -- stack->reg_buf = create_reg_mempool("reg_ring_msg", stack->queue_id); -- if (stack->reg_buf == NULL) { -- LSTACK_LOG(ERR, LSTACK, "rxtx_mbuf_pool is NULL\n"); -- return -1; -- } -- } -- -- return 0; --} -- --struct rte_mempool *create_mempool(const char *name, uint32_t count, uint32_t size, -- uint32_t flags, int32_t idx) -+int32_t create_shared_ring(struct protocol_stack *stack) - { -- char pool_name [RTE_MEMPOOL_NAMESIZE]; -- struct rte_mempool *mempool; -- int32_t ret = snprintf_s(pool_name, sizeof(pool_name), RTE_MEMPOOL_NAMESIZE - 1, -- "%s_%d", name, idx); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d\n", ret); -- return NULL; -+ if (!use_ltran()) { -+ return 0; - } - -- mempool = rte_mempool_create(pool_name, count, size, -- 0, 0, NULL, NULL, NULL, NULL, rte_socket_id(), flags); -- if (mempool == NULL) { -- LSTACK_LOG(ERR, LSTACK, "%s create failed. errno: %d.\n", name, rte_errno); -+ stack->rx_ring = rte_ring_create_fast("RING_RX", VDEV_RX_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ); -+ if (stack->rx_ring == NULL) { -+ return -1; - } - -- return mempool; --} -- --int32_t create_shared_ring(struct protocol_stack *stack) --{ -- rpc_queue_init(&stack->rpc_queue, stack->queue_id); -- rpc_queue_init(&stack->dfx_rpc_queue, stack->queue_id); -- -- if (use_ltran()) { -- stack->rx_ring = gazelle_ring_create_fast("RING_RX", VDEV_RX_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ); -- if (stack->rx_ring == NULL) { -- return -1; -- } -- -- stack->tx_ring = gazelle_ring_create_fast("RING_TX", VDEV_TX_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ); -- if (stack->tx_ring == NULL) { -- return -1; -- } -- -- stack->reg_ring = gazelle_ring_create_fast("SHARED_REG_RING", VDEV_REG_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ); -- if (stack->reg_ring == NULL) { -- return -1; -- } -+ stack->tx_ring = rte_ring_create_fast("RING_TX", VDEV_TX_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ); -+ if (stack->tx_ring == NULL) { -+ return -1; - } - -- return 0; --} -- --int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num, bool reserve) --{ -- if (reserve) { -- /* -- * don't use rte_mempool_avail_count, it traverse cpu local cache, -- * when RTE_MAX_LCORE is too large, it's time-consuming -- */ -- if (rte_ring_count(pool->pool_data) < MBUFPOOL_RESERVE_NUM + num) { -- return -ENOMEM; -- } -+ stack->reg_ring = rte_ring_create_fast("SHARED_REG_RING", VDEV_REG_QUEUE_SZ, RING_F_SP_ENQ | RING_F_SC_DEQ); -+ if (stack->reg_ring == NULL) { -+ return -1; - } - -- int32_t ret = rte_pktmbuf_alloc_bulk(pool, mbufs, num); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "rte_pktmbuf_alloc_bulk fail allocNum=%d, ret=%d, info:%s \n", -- num, ret, rte_strerror(-ret)); -- return ret; -+ stack->reg_buf = create_reg_mempool("reg_ring_msg", stack->queue_id); -+ if (stack->reg_buf == NULL) { -+ LSTACK_LOG(ERR, LSTACK, "reg_buf is NULL\n"); -+ return -1; - } - - return 0; - } - --int32_t fill_mbuf_to_ring(struct rte_mempool *mempool, struct rte_ring *ring, uint32_t mbuf_num) -+int32_t fill_mbuf_to_ring(int stack_id, struct rte_ring *ring, uint32_t mbuf_num) - { - int32_t ret; - uint32_t batch; - uint32_t remain = mbuf_num; -- struct rte_mbuf *free_buf[FREE_RX_QUEUE_SZ]; -+ struct rte_mbuf *free_buf[VDEV_RX_QUEUE_SZ]; - - while (remain > 0) { -- batch = LWIP_MIN(remain, RING_SIZE(FREE_RX_QUEUE_SZ)); -+ batch = LWIP_MIN(remain, RING_SIZE(VDEV_RX_QUEUE_SZ)); - -- ret = dpdk_alloc_pktmbuf(mempool, free_buf, batch, true); -+ ret = mem_get_mbuf_bulk(stack_id, free_buf, batch, true); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "cannot alloc mbuf for ring, count: %u ret=%d\n", batch, ret); - return -1; - } - - ret = gazelle_ring_sp_enqueue(ring, (void **)free_buf, batch); -- if (ret == 0) { -+ if (ret < batch) { -+ mem_put_mbuf_bulk(&free_buf[ret], batch - ret); - LSTACK_LOG(ERR, LSTACK, "cannot enqueue to ring, count: %u\n", batch); -- for (int i = 0; i < batch; i++) { -- rte_pktmbuf_free(free_buf[i]); -- } - return -1; - } - -@@ -592,7 +481,7 @@ static int32_t dpdk_ethdev_setup(const struct eth_params *eth_params, uint16_t i - 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]; -+ struct rte_mempool *rxtx_mbuf_pool = mem_get_mbuf_pool(idx); - - if (!cfg->use_ltran && cfg->num_process == 1) { - numa_id = (cfg->stack_num > 0) ? cfg->numa_id : numa_node_of_cpu(cfg->cpus[idx]); -@@ -651,7 +540,7 @@ int32_t dpdk_ethdev_start(void) - int32_t dpdk_init_lstack_kni(void) - { - struct protocol_stack_group *stack_group = get_protocol_stack_group(); -- stack_group->kni_pktmbuf_pool = create_pktmbuf_mempool("kni_mbuf", KNI_NB_MBUF, 0, 0, rte_socket_id()); -+ stack_group->kni_pktmbuf_pool = rte_pktmbuf_pool_create("kni_mbuf", KNI_NB_MBUF, 0, 0, MBUF_DATA_SIZE, rte_socket_id()); - if (stack_group->kni_pktmbuf_pool == NULL) { - LSTACK_LOG(ERR, LSTACK, "kni_mbuf is NULL\n"); - return -1; -@@ -1030,7 +919,7 @@ uint32_t dpdk_total_socket_memory(void) - 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); -+ elt_size = sizeof(struct rte_mbuf) + MBUF_DATA_SIZE + 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) */ -@@ -1038,13 +927,12 @@ uint32_t dpdk_total_socket_memory(void) - 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); -+ per_conn_ring_size = rte_ring_get_memsize(DEFAULT_SENDMBOX_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_rpc_mempool_size * cfg->rpc_msg_max + - per_conn_ring_size * GAZELLE_LSTACK_MAX_CONN); - - return total_socket_memory; -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -deleted file mode 100644 -index 047dfdf..0000000 ---- a/src/lstack/core/lstack_lwip.c -+++ /dev/null -@@ -1,1286 +0,0 @@ --/* --* 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 --#include --#include -- --#include --#include -- --#include --#include --#include --#include --#include --#include --#include --#include --#include --#include -- --#include "common/gazelle_base_func.h" --#include "lstack_log.h" --#include "lstack_cfg.h" --#include "lstack_protocol_stack.h" --#include "lstack_stack_stat.h" --#include "lstack_epoll.h" --#include "lstack_dpdk.h" --#include "lstack_lwip.h" -- --static const uint8_t fin_packet = 0; -- --static void free_ring_pbuf(struct rte_ring *ring) --{ -- void *pbufs[SOCK_RECV_RING_SIZE]; -- -- do { -- gazelle_ring_read(ring, pbufs, RING_SIZE(SOCK_RECV_RING_SIZE)); -- gazelle_ring_read_over(ring); -- } while (gazelle_ring_readable_count(ring)); -- -- do { -- uint32_t num = gazelle_ring_sc_dequeue(ring, pbufs, RING_SIZE(SOCK_RECV_RING_SIZE)); -- -- for (uint32_t i = 0; i < num; i++) { -- pbuf_free(pbufs[i]); -- } -- } while (gazelle_ring_readover_count(ring)); --} -- --static void reset_sock_data(struct lwip_sock *sock) --{ -- /* check null pointer in ring_free func */ -- if (sock->recv_ring) { -- free_ring_pbuf(sock->recv_ring); -- gazelle_ring_free_fast(sock->recv_ring); -- sock->recv_ring = NULL; -- } -- -- if (sock->send_ring) { -- free_ring_pbuf(sock->send_ring); -- gazelle_ring_free_fast(sock->send_ring); -- sock->send_ring = NULL; -- } -- -- if (sock->send_pre_del) { -- pbuf_free(sock->send_pre_del); -- sock->send_pre_del = NULL; -- } -- -- sock->type = 0; -- sock->stack_id = 0; -- sock->affinity_numa = 0; -- sock->sk_wait = NULL; -- sock->listen_next = NULL; -- sock->call_num = 0; -- sock->remain_len = 0; -- -- if (sock->recv_lastdata && sock->recv_lastdata != (void *)&fin_packet) { -- pbuf_free(sock->recv_lastdata); -- } -- sock->recv_lastdata = NULL; --} -- --static struct pbuf *init_mbuf_to_pbuf(struct rte_mbuf *mbuf, pbuf_layer layer, uint16_t length, pbuf_type type) --{ -- struct pbuf_custom *pbuf_custom = mbuf_to_pbuf(mbuf); -- -- void *data = rte_pktmbuf_mtod(mbuf, void *); -- struct pbuf *pbuf = pbuf_alloced_custom(layer, length, type, pbuf_custom, data, MAX_PACKET_SZ); -- if (pbuf) { -- pbuf->allow_append = 1; -- pbuf->addr = *IP_ANY_TYPE; -- pbuf->port = 0; -- pthread_spin_init(&pbuf->pbuf_lock, PTHREAD_PROCESS_SHARED); -- } -- -- return pbuf; --} -- --static uint32_t update_replenish_mbuf_cnt(struct protocol_stack *stack, struct lwip_sock *sock) --{ -- const uint32_t min_alloc_mbuf_num = 4; -- struct rte_ring *ring = sock->send_ring; -- -- uint32_t replenish_cnt = gazelle_ring_free_count(ring); -- if (replenish_cnt <= min_alloc_mbuf_num) { -- return replenish_cnt; -- } -- -- uint32_t resu = replenish_cnt; -- uint32_t tcp_conn_count = get_global_cfg_params()->tcp_conn_count; -- uint16_t send_ring_size = get_global_cfg_params()->send_ring_size; -- uint16_t proportion = stack->conn_num / tcp_conn_count; -- uint32_t replenish_mbuf_cnt_cal = (send_ring_size >> proportion); -- -- if (replenish_mbuf_cnt_cal <= min_alloc_mbuf_num) { -- resu = min_alloc_mbuf_num; -- } else if (replenish_mbuf_cnt_cal < replenish_cnt) { -- resu = replenish_mbuf_cnt_cal; -- } else { -- resu = replenish_cnt + 1; -- } -- -- return resu - 1; --} -- --/* true: need replenish again */ --static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_sock *sock) --{ -- void *pbuf[SOCK_SEND_RING_SIZE_MAX]; -- struct rte_ring *ring = sock->send_ring; -- -- uint32_t replenish_cnt = update_replenish_mbuf_cnt(stack, sock); -- if (replenish_cnt == 0) { -- return false; -- } -- if (dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)pbuf, replenish_cnt, true) != 0) { -- stack->stats.tx_allocmbuf_fail++; -- return true; -- } -- -- uint32_t i = 0; -- for (; i < replenish_cnt - 1; i++) { -- rte_prefetch0(mbuf_to_pbuf((void *)pbuf[i + 1])); -- pbuf[i] = init_mbuf_to_pbuf(pbuf[i], PBUF_TRANSPORT, MBUF_MAX_DATA_LEN, PBUF_RAM); -- } -- pbuf[i] = init_mbuf_to_pbuf((struct rte_mbuf *)pbuf[i], PBUF_TRANSPORT, MBUF_MAX_DATA_LEN, PBUF_RAM); -- -- uint32_t num = gazelle_ring_sp_enqueue(ring, pbuf, replenish_cnt); -- for (uint32_t i = num; i < replenish_cnt; i++) { -- pbuf_free(pbuf[i]); -- } -- -- sem_post(&sock->snd_ring_sem); -- -- return false; --} -- --int do_lwip_init_sock(int32_t fd) --{ -- struct protocol_stack *stack = get_protocol_stack(); -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- return -1; -- } -- -- sock->stack_id = stack->stack_idx; -- sock->sk_wait = NULL; -- if (sock_event_init(&sock->sk_event) != 0) { -- LSTACK_LOG(ERR, LSTACK, "sock_event_init failed\n"); -- return -1; -- } -- -- if (get_global_cfg_params()->stack_mode_rtc) { -- return 0; -- } -- -- if (sock->recv_ring != NULL || sock->send_ring != NULL) { -- LSTACK_LOG(ERR, LSTACK, "socket(%d) not close but open again?\n", fd); -- } -- -- reset_sock_data(sock); -- -- sock->recv_ring = gazelle_ring_create_fast("sock_recv", SOCK_RECV_RING_SIZE, RING_F_SP_ENQ | RING_F_SC_DEQ); -- if (sock->recv_ring == NULL) { -- LSTACK_LOG(ERR, LSTACK, "sock_recv create failed. errno: %d.\n", rte_errno); -- return -1; -- } -- -- sock->send_ring = gazelle_ring_create_fast("sock_send", -- get_global_cfg_params()->send_ring_size, -- RING_F_SP_ENQ | RING_F_SC_DEQ); -- if (sock->send_ring == NULL) { -- gazelle_ring_free_fast(sock->recv_ring); -- LSTACK_LOG(ERR, LSTACK, "sock_send create failed. errno: %d.\n", rte_errno); -- return -1; -- } -- (void)replenish_send_idlembuf(stack, sock); -- -- list_init_node(&sock->recv_list); -- return 0; --} -- --void do_lwip_clean_sock(int fd) --{ -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (POSIX_IS_CLOSED(sock)) { -- return; -- } -- -- sock_event_free(&sock->sk_event, sock->sk_wait); -- sock->sk_wait = NULL; -- -- reset_sock_data(sock); -- -- list_del_node(&sock->recv_list); -- -- get_protocol_stack_by_id(sock->stack_id)->conn_num--; --} -- --void do_lwip_free_pbuf(struct pbuf *pbuf) --{ -- if (pbuf == NULL) { -- return; -- } -- -- struct rte_mbuf *mbuf = pbuf_to_mbuf(pbuf); -- -- rte_pktmbuf_free_seg(mbuf); --} -- --struct pbuf *do_lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type type) --{ -- int ret; -- struct rte_mbuf *mbuf; -- struct protocol_stack *stack = get_protocol_stack(); -- -- /* ensure arp packet can be sent */ -- if (layer == PBUF_LINK && length == SIZEOF_ETHARP_HDR) { -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf, 1, false); -- } else { -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf, 1, true); -- } -- if (ret != 0) { -- stack->stats.tx_allocmbuf_fail++; -- return NULL; -- } -- -- return init_mbuf_to_pbuf(mbuf, layer, length, type); --} -- --static inline bool pbuf_allow_append(struct pbuf *pbuf, uint16_t remain_size) --{ -- int ret; -- -- /* Using pthread_spin_trylock to avoid deadlock between app thread and lstack threads */ -- ret = pthread_spin_trylock(&pbuf->pbuf_lock); -- if (ret != 0) { -- return false; -- } -- -- if (pbuf->tot_len > remain_size) { -- pthread_spin_unlock(&pbuf->pbuf_lock); -- return false; -- } -- if (pbuf->allow_append == 1) { -- __sync_fetch_and_sub(&pbuf->allow_append, 1); -- } -- -- pthread_spin_unlock(&pbuf->pbuf_lock); -- return true; --} -- --struct pbuf *do_lwip_udp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size) --{ -- int count; -- /* when remain_size is 0, fill_sendring write one pbuf to sendring */ -- if (remain_size == 0) { -- count = 1; -- } else { -- count = (remain_size + MBUF_MAX_DATA_LEN - 1) / MBUF_MAX_DATA_LEN; -- } -- -- struct pbuf *pbufs[count]; -- -- int actual_count = gazelle_ring_sc_dequeue(sock->send_ring, (void **)&pbufs, count); -- /* it's impossible to enter this branch theoretically */ -- if (unlikely((actual_count != count) || -- ((actual_count != 0) && pbufs[0]->tot_len != remain_size))) { -- LSTACK_LOG(ERR, LSTACK, "udp get pbuf from sendring error, expected: %d, actual: %d\n", -- count, actual_count); -- LSTACK_LOG(ERR, LSTACK, "udp get pbuf size error, expected: %d, actual: %d\n", -- remain_size, actual_count == 0 ? 0 : pbufs[0]->tot_len); -- } -- -- for (int i = 0; get_protocol_stack_group()->latency_start && i < actual_count; i++) { -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- calculate_lstack_latency(&stack->latency, pbufs[i], GAZELLE_LATENCY_WRITE_LWIP, 0); -- } -- -- return pbufs[0]; --} -- --struct pbuf *do_lwip_tcp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size) --{ -- struct pbuf *pbuf = NULL; -- -- if (unlikely(sock->send_pre_del)) { -- if (pbuf_allow_append(sock->send_pre_del, remain_size)) { -- return sock->send_pre_del; -- } else { -- return NULL; -- } -- } -- -- gazelle_ring_sc_dequeue(sock->send_ring, (void **)&pbuf, 1); -- if (pbuf == NULL) { -- return NULL; -- } -- -- if (get_protocol_stack_group()->latency_start) { -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LWIP, 0); -- } -- -- sock->send_pre_del = pbuf; -- -- if (!gazelle_ring_readover_count(sock->send_ring)) { -- if (!pbuf_allow_append(pbuf, remain_size)) { -- return NULL; -- } -- } else { -- if (pbuf->tot_len > remain_size) { -- return NULL; -- } -- } -- -- return pbuf; --} -- --void do_lwip_get_from_sendring_over(struct lwip_sock *sock) --{ -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- stack->stats.write_lwip_cnt++; -- sock->send_pre_del = NULL; --} -- --static ssize_t do_app_write(struct lwip_sock *sock, struct pbuf *pbufs[], void *buf, size_t len, uint32_t write_num) --{ -- ssize_t send_len = 0; -- uint32_t i = 0; -- -- for (i = 0; i < write_num - 1; i++) { -- rte_prefetch0(pbufs[i + 1]); -- rte_prefetch0(pbufs[i + 1]->payload); -- rte_prefetch0((char *)buf + send_len + MBUF_MAX_DATA_LEN); -- rte_memcpy((char *)pbufs[i]->payload, (char *)buf + send_len, MBUF_MAX_DATA_LEN); -- pbufs[i]->tot_len = pbufs[i]->len = MBUF_MAX_DATA_LEN; -- send_len += MBUF_MAX_DATA_LEN; -- -- /* if udp pkg len > mtu, use pbuf chain to send it */ -- if (NETCONN_IS_UDP(sock) && i > 0) { -- pbuf_cat(pbufs[0], pbufs[i]); -- } -- } -- -- /* reduce the branch in loop */ -- size_t copy_len = len - send_len; -- rte_memcpy((char *)pbufs[i]->payload, (char *)buf + send_len, copy_len); -- pbufs[i]->tot_len = pbufs[i]->len = copy_len; -- send_len += copy_len; -- -- if (NETCONN_IS_UDP(sock) && i > 0) { -- pbuf_cat(pbufs[0], pbufs[i]); -- } -- -- return send_len; --} -- --static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t len, uint32_t write_num, -- const struct sockaddr *addr, socklen_t addrlen) --{ -- struct pbuf *pbufs[SOCK_SEND_RING_SIZE_MAX]; -- -- (void)gazelle_ring_read(sock->send_ring, (void **)pbufs, write_num); -- -- if (get_protocol_stack_group()->latency_start) { -- uint64_t time_stamp = sys_now_us(); -- time_stamp_into_pbuf(write_num, pbufs, time_stamp); -- } -- -- ssize_t send_len = do_app_write(sock, pbufs, buf, len, write_num); -- -- if (addr) { -- if (addr->sa_family == AF_INET) { -- struct sockaddr_in *saddr = (struct sockaddr_in *)addr; -- for (int i = 0; i < write_num; i++) { -- pbufs[i]->addr.u_addr.ip4.addr = saddr->sin_addr.s_addr; -- pbufs[i]->port = lwip_ntohs((saddr)->sin_port); -- IP_SET_TYPE(&pbufs[i]->addr, IPADDR_TYPE_V4); -- } -- } else if (addr->sa_family == AF_INET6) { -- struct sockaddr_in6 *saddr = (struct sockaddr_in6 *)addr; -- for (int i = 0; i < write_num; i++) { -- memcpy_s(pbufs[i]->addr.u_addr.ip6.addr, IPV6_ADDR_LEN, saddr->sin6_addr.s6_addr, IPV6_ADDR_LEN); -- pbufs[i]->port = lwip_ntohs((saddr)->sin6_port); -- IP_SET_TYPE(&pbufs[i]->addr, IPADDR_TYPE_V6); -- } -- } else { -- return 0; -- } -- } -- -- for (int i = 0; get_protocol_stack_group()->latency_start && i < write_num; i++) { -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- if (pbufs[i] != NULL) { -- calculate_lstack_latency(&stack->latency, pbufs[i], GAZELLE_LATENCY_WRITE_INTO_RING, 0); -- } -- } -- -- gazelle_ring_read_over(sock->send_ring); -- -- sock->remain_len = MBUF_MAX_DATA_LEN - pbufs[write_num - 1]->len; -- return send_len; --} -- --static inline struct pbuf *gazelle_ring_readlast(struct rte_ring *r) --{ -- struct pbuf *last_pbuf = NULL; -- volatile uint32_t tail = __atomic_load_n(&r->cons.tail, __ATOMIC_ACQUIRE); -- uint32_t last = r->prod.tail - 1; -- if (last + 1 == tail || last + 1 - tail > r->capacity) { -- return NULL; -- } -- -- __rte_ring_dequeue_elems(r, last, (void **)&last_pbuf, sizeof(void *), 1); -- -- if (pthread_spin_trylock(&last_pbuf->pbuf_lock) != 0) { -- return NULL; -- } -- if (last_pbuf->allow_append != 1) { -- pthread_spin_unlock(&last_pbuf->pbuf_lock); -- return NULL; -- } -- -- return last_pbuf; --} -- --static inline void gazelle_ring_lastover(struct pbuf *last_pbuf) --{ -- pthread_spin_unlock(&last_pbuf->pbuf_lock); --} -- --static inline size_t merge_data_lastpbuf(struct lwip_sock *sock, void *buf, size_t len) --{ -- struct pbuf *last_pbuf = gazelle_ring_readlast(sock->send_ring); -- if (last_pbuf == NULL) { -- sock->remain_len = 0; -- return 0; -- } -- -- size_t send_len = MBUF_MAX_DATA_LEN - last_pbuf->len; -- if (send_len >= len) { -- sock->remain_len = send_len - len; -- send_len = len; -- } else { -- sock->remain_len = 0; -- } -- -- uint16_t offset = last_pbuf->len; -- last_pbuf->tot_len = last_pbuf->len = offset + send_len; -- rte_memcpy((char *)last_pbuf->payload + offset, buf, send_len); -- -- gazelle_ring_lastover(last_pbuf); -- -- return send_len; --} -- --int sem_timedwait_nsecs(sem_t *sem) --{ -- struct timespec ts; -- clock_gettime(CLOCK_REALTIME, &ts); -- long long wait_nsec = ts.tv_nsec + SEND_TIME_WAIT_NS; -- ts.tv_nsec = wait_nsec % SECOND_NSECOND; -- long add = wait_nsec / SECOND_NSECOND; -- ts.tv_sec += add; -- return sem_timedwait(sem, &ts); --} -- --static ssize_t do_lwip_udp_fill_sendring(struct lwip_sock *sock, const void *buf, size_t len, -- const struct sockaddr *addr, socklen_t addrlen) --{ -- if (len > GAZELLE_UDP_PKGLEN_MAX) { -- LSTACK_LOG(ERR, LSTACK, "Message too long\n"); -- GAZELLE_RETURN(EMSGSIZE); -- } -- -- ssize_t send_len = 0; -- uint32_t write_num = (len + MBUF_MAX_DATA_LEN - 1) / MBUF_MAX_DATA_LEN; -- uint32_t write_avail = gazelle_ring_readable_count(sock->send_ring); -- -- if (write_num > rte_ring_get_capacity(sock->send_ring)) { -- LSTACK_LOG(ERR, LSTACK, "sock send_ring size is not enough\n"); -- GAZELLE_RETURN(ENOMEM); -- } -- -- /* if udp send 0 packet, set write_num to at least 1 */ -- if (write_num == 0) { -- write_num = 1; -- } -- -- while (!netconn_is_nonblocking(sock->conn) && (write_avail < write_num)) { -- if (sock->errevent > 0) { -- GAZELLE_RETURN(ENOTCONN); -- } -- write_avail = gazelle_ring_readable_count(sock->send_ring); -- } -- -- if (write_avail < write_num) { -- LSTACK_LOG(WARNING, LSTACK, "sock send_ring is already exhausted.\n"); -- sem_timedwait_nsecs(&sock->snd_ring_sem); -- GAZELLE_RETURN(ENOMEM); -- } -- -- send_len = app_buff_write(sock, (char *)buf, len, write_num, addr, addrlen); -- -- API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -- -- return send_len; --} -- --static ssize_t __do_lwip_tcp_fill_sendring(struct lwip_sock *sock, const void *buf, size_t len, -- const struct sockaddr *addr, socklen_t addrlen) --{ -- /* refer to the lwip implementation. */ -- if (len == 0) { -- return 0; -- } -- -- ssize_t send_len = 0; -- -- /* merge data into last pbuf */ -- if (sock->remain_len) { -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- stack->stats.sock_tx_merge++; -- send_len = merge_data_lastpbuf(sock, (char *)buf, len); -- if (send_len >= len) { -- send_len = len; -- goto END; -- } -- } -- -- uint32_t write_num = (len - send_len + MBUF_MAX_DATA_LEN - 1) / MBUF_MAX_DATA_LEN; -- uint32_t write_avail = gazelle_ring_readable_count(sock->send_ring); -- -- while (!netconn_is_nonblocking(sock->conn) && (write_avail < write_num)) { -- if (sock->errevent > 0) { -- GAZELLE_RETURN(ENOTCONN); -- } -- /* wait until (send_ring_size / 4) */ -- if (write_avail > (rte_ring_get_capacity(sock->send_ring) >> 2)) { -- break; -- } -- write_avail = gazelle_ring_readable_count(sock->send_ring); -- } -- -- /* send_ring is full, data attach last pbuf */ -- if (write_avail == 0) { -- sem_timedwait_nsecs(&sock->snd_ring_sem); -- goto END; -- } -- -- /* send_ring have idle */ -- if (write_num > write_avail) { -- write_num = write_avail; -- len = write_num * MBUF_MAX_DATA_LEN; -- } -- send_len += app_buff_write(sock, (char *)buf + send_len, len - send_len, write_num, addr, addrlen); -- -- API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -- --END: -- if (send_len == 0) { -- errno = EAGAIN; -- return -1; -- } -- -- return send_len; --} -- --static inline void notice_stack_tcp_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags); --static ssize_t do_lwip_tcp_fill_sendring(struct lwip_sock *sock, const void *buf, size_t len, -- const struct sockaddr *addr, socklen_t addrlen) --{ -- ssize_t ret, send_len = 0; -- -- while (true) { -- ret = __do_lwip_tcp_fill_sendring(sock, (char *)buf + send_len, len - send_len, addr, addrlen); -- // send = 0 : tcp peer close connection ? -- if (unlikely(ret <= 0)) { -- break; -- } -- send_len += ret; -- if (send_len == len || netconn_is_nonblocking(sock->conn)) { -- break; -- } -- -- notice_stack_tcp_send(sock, sock->conn->callback_arg.socket, ret, 0); -- } -- -- return send_len == 0 ? ret : send_len; --} -- --bool do_lwip_replenish_sendring(struct protocol_stack *stack, struct lwip_sock *sock) --{ -- bool replenish_again = false; -- -- replenish_again = replenish_send_idlembuf(stack, sock); -- -- API_EVENT(sock->conn, NETCONN_EVT_SENDPLUS, 0); -- -- return replenish_again; --} -- --static inline void free_recv_ring_readover(struct rte_ring *ring) --{ -- void *pbufs[SOCK_RECV_RING_SIZE]; -- uint32_t num = gazelle_ring_sc_dequeue(ring, pbufs, RING_SIZE(SOCK_RECV_RING_SIZE)); -- for (uint32_t i = 0; i < num; i++) { -- pbuf_free(pbufs[i]); -- } --} -- --static inline struct pbuf *pbuf_last(struct pbuf *pbuf) --{ -- while (pbuf->next) { -- pbuf = pbuf->next; -- } -- return pbuf; --} -- --ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, u8_t apiflags) --{ -- if (sock->conn->recvmbox == NULL) { -- sock->conn->pending_err = ERR_CONN; -- GAZELLE_RETURN(ENOTCONN); -- } -- -- free_recv_ring_readover(sock->recv_ring); -- -- uint32_t free_count = gazelle_ring_free_count(sock->recv_ring); -- if (free_count == 0) { -- sock->conn->pending_err = ERR_WOULDBLOCK; -- GAZELLE_RETURN(EAGAIN); -- } -- -- uint32_t data_count = rte_ring_count(sock->conn->recvmbox->ring); -- uint32_t read_num = LWIP_MIN(free_count, data_count); -- struct pbuf *pbufs[SOCK_RECV_RING_SIZE]; -- uint32_t read_count = 0; -- ssize_t recv_len = 0; -- -- for (uint32_t i = 0; i < read_num; i++) { -- -- err_t err = ERR_OK; -- if (NETCONN_IS_UDP(sock)) { -- err = netconn_recv_udp_raw_pbuf_flags(sock->conn, &pbufs[i], apiflags); -- } else { -- err = netconn_recv_tcp_pbuf_flags(sock->conn, &pbufs[i], apiflags); -- } -- if (err != ERR_OK) { -- /* fin has been read from recvmbox, put it to recv_ring */ -- if (!NETCONN_IS_UDP(sock) && -- (netconn_is_flag_set(sock->conn, NETCONN_FIN_RX_PENDING) || err == ERR_CLSD)) { -- /* fin has been read, lwip don't need to process fin packet */ -- netconn_clear_flags(sock->conn, NETCONN_FIN_RX_PENDING); -- pbufs[i] = NULL; -- read_count++; -- break; -- } -- -- /* store err to pending_err again, clear it after app read */ -- sock->conn->pending_err = err; -- GAZELLE_RETURN(err_to_errno(err)); -- } -- -- recv_len += pbufs[i]->tot_len; -- lstack_calculate_aggregate(0, pbufs[i]->tot_len); -- read_count++; -- -- /* once we have some data to return, only add more if we don't need to wait */ -- apiflags |= NETCONN_DONTBLOCK | NETCONN_NOFIN; -- } -- -- uint32_t enqueue_num = gazelle_ring_sp_enqueue(sock->recv_ring, (void **)pbufs, read_count); -- if (enqueue_num != read_count) { -- LSTACK_LOG(ERR, LSTACK, "Code shouldn't get here!\n"); -- } -- -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- for (uint32_t i = 0; get_protocol_stack_group()->latency_start && i < read_count; i++) { -- if (pbufs[i] != NULL) { -- calculate_lstack_latency(&stack->latency, pbufs[i], GAZELLE_LATENCY_READ_LWIP, 0); -- } -- } -- stack->stats.read_lwip_cnt += read_count; -- -- return recv_len; --} -- --static int32_t check_msg_vaild(const struct msghdr *message) --{ -- ssize_t buflen = 0; -- -- if (message == NULL || message->msg_iovlen <= 0 || message->msg_iovlen > IOV_MAX) { -- GAZELLE_RETURN(EINVAL); -- } -- -- for (int32_t i = 0; i < message->msg_iovlen; i++) { -- if ((message->msg_iov[i].iov_base == NULL) || ((ssize_t)message->msg_iov[i].iov_len < 0) || -- ((size_t)(ssize_t)message->msg_iov[i].iov_len != message->msg_iov[i].iov_len) || -- ((ssize_t)(buflen + (ssize_t)message->msg_iov[i].iov_len) < 0)) { -- GAZELLE_RETURN(EINVAL); -- } -- buflen = (ssize_t)(buflen + (ssize_t)message->msg_iov[i].iov_len); -- } -- -- return 0; --} -- --ssize_t do_lwip_recvmsg_from_stack(int32_t s, const struct msghdr *message, int32_t flags) --{ -- ssize_t buflen = 0; -- -- if (check_msg_vaild(message)) { -- GAZELLE_RETURN(EINVAL); -- } -- -- for (int32_t i = 0; i < message->msg_iovlen; i++) { -- if (message->msg_iov[i].iov_len == 0) { -- continue; -- } -- -- ssize_t recvd_local = do_lwip_read_from_stack(s, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len, -- flags, NULL, NULL); -- if (recvd_local > 0) { -- buflen += recvd_local; -- } -- if (recvd_local < 0 || (recvd_local < (int)message->msg_iov[i].iov_len) || (flags & MSG_PEEK)) { -- if (buflen <= 0) { -- buflen = recvd_local; -- } -- break; -- } -- flags |= MSG_DONTWAIT; -- } -- -- return buflen; --} -- --static inline void notice_stack_tcp_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags) --{ -- // 2: call_num >= 2, don't need add new rpc send -- if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) < 2) { -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- while (rpc_call_tcp_send(&stack->rpc_queue, fd, len, flags) < 0) { -- usleep(1000); // 1000: wait 1ms to exec again -- } -- __sync_fetch_and_add(&sock->call_num, 1); -- } --} -- --static inline void notice_stack_udp_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags) --{ -- __sync_fetch_and_add(&sock->call_num, 1); -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- while (rpc_call_udp_send(&stack->rpc_queue, fd, len, flags) < 0) { -- usleep(1000); // 1000: wait 1ms to exec again -- } --} -- --static inline void notice_stack_send(struct lwip_sock *sock, int32_t fd, int32_t len, int32_t flags) --{ -- if (NETCONN_IS_UDP(sock)) { -- notice_stack_udp_send(sock, fd, len, flags); -- } else { -- notice_stack_tcp_send(sock, fd, len, flags); -- } --} -- --ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t flags, -- const struct sockaddr *addr, socklen_t addrlen) --{ -- struct lwip_sock *sock; -- ssize_t send = 0; -- -- if (buf == NULL) { -- GAZELLE_RETURN(EINVAL); -- } -- if (addr && addr->sa_family != AF_INET && addr->sa_family != AF_INET6) { -- GAZELLE_RETURN(EINVAL); -- } -- -- sock = lwip_get_socket(fd); -- if (unlikely(sock->affinity_numa == 0)) { -- thread_bind_stack(sock->stack_id); -- sock->affinity_numa = 1; -- } -- --#if GAZELLE_SAME_NODE -- if (sock->same_node_tx_ring != NULL) { -- return gazelle_same_node_ring_send(sock, buf, len, flags); -- } --#endif /* GAZELLE_SAME_NODE */ -- if (sock->errevent > 0) { -- GAZELLE_RETURN(ENOTCONN); -- } -- -- if (NETCONN_IS_UDP(sock)) { -- send = do_lwip_udp_fill_sendring(sock, buf, len, addr, addrlen); -- /* send = 0: udp send a empty package */ -- if (send < 0) { -- return send; -- } -- } else { -- send = do_lwip_tcp_fill_sendring(sock, buf, len, addr, addrlen); -- // send = 0 : tcp peer close connection ? -- if (send <= 0) { -- return send; -- } -- } -- -- notice_stack_send(sock, fd, send, flags); -- return send; --} -- --ssize_t do_lwip_sendmsg_to_stack(struct lwip_sock *sock, int32_t s, const struct msghdr *message, int32_t flags) --{ -- int32_t ret; -- int32_t i; -- ssize_t buflen = 0; -- -- if (check_msg_vaild(message)) { -- GAZELLE_RETURN(EINVAL); -- } -- -- for (i = 0; i < message->msg_iovlen; i++) { -- if (message->msg_iov[i].iov_len == 0) { -- continue; -- } -- -- if (NETCONN_IS_UDP(sock)) { -- ret = do_lwip_udp_fill_sendring(sock, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len, NULL, 0); -- } else { -- ret = do_lwip_tcp_fill_sendring(sock, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len, NULL, 0); -- } -- if (ret <= 0) { -- buflen = (buflen == 0) ? ret : buflen; -- break; -- } -- -- buflen += ret; -- -- if (ret < message->msg_iov[i].iov_len) { -- break; -- } -- } -- -- if (buflen > 0) { -- notice_stack_send(sock, s, buflen, flags); -- } -- return buflen; --} -- --static struct pbuf *pbuf_free_partial(struct pbuf *pbuf, uint16_t free_len) --{ -- uint32_t tot_len = pbuf->tot_len - free_len; -- -- while (free_len && pbuf) { -- if (free_len >= pbuf->len) { -- free_len = free_len - pbuf->len; -- pbuf = pbuf->next; -- } else { -- pbuf_remove_header(pbuf, free_len); -- break; -- } -- } -- -- if (pbuf) { -- pbuf->tot_len = tot_len; -- } -- return pbuf; --} -- --static bool recv_break_for_err(struct lwip_sock *sock) --{ -- errno = err_to_errno(netconn_err(sock->conn)); -- unsigned pending = sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_RCVPLUS, 0) | -- sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0); -- return pending; --} -- --/* -- * return 0 on success, -1 on error -- * pbuf maybe NULL(tcp fin packet) -- */ --static int recv_ring_get_one(struct lwip_sock *sock, bool noblock, struct pbuf **pbuf) --{ -- int32_t expect; -- uint64_t time_stamp = sys_now_us(); -- -- if (sock->recv_lastdata != NULL) { -- *pbuf = sock->recv_lastdata; -- sock->recv_lastdata = NULL; -- return 0; -- } -- -- expect = gazelle_ring_read(sock->recv_ring, (void **)pbuf, 1); -- if (expect == 0) { -- if (netconn_is_nonblocking(sock->conn)) { -- GAZELLE_RETURN(EAGAIN); -- } -- sock_event_wait(sock, true); -- expect = gazelle_ring_read(sock->recv_ring, (void **)pbuf, 1); -- if (expect == 0) { -- if (recv_break_for_err(sock)) { -- return -1; -- } -- GAZELLE_RETURN(EAGAIN); -- } -- } -- -- if (get_protocol_stack_group()->latency_start) { -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- calculate_lstack_latency(&stack->latency, *pbuf, GAZELLE_LATENCY_READ_APP_CALL, time_stamp); -- } -- -- return 0; --} -- --/* return true: fin is read to user, false: pend fin */ --static bool recv_ring_handle_fin(struct lwip_sock *sock, struct pbuf *pbuf, ssize_t recvd) --{ -- if (pbuf == NULL) { -- if (recvd > 0) { -- /* handle data first, then handle fin */ -- sock->recv_lastdata = (void *)&fin_packet; -- gazelle_ring_read_over(sock->recv_ring); -- return false; -- } -- gazelle_ring_read_over(sock->recv_ring); -- return true; -- } -- /* pending fin */ -- if (pbuf == (void *)&fin_packet) { -- return true; -- } -- -- return false; --} -- --static ssize_t recv_ring_tcp_read(struct lwip_sock *sock, void *buf, size_t len, bool noblock) --{ -- ssize_t recvd = 0; -- size_t recv_left = len; -- uint32_t copy_len; -- struct pbuf *pbuf = NULL; -- -- if (len == 0) { -- return 0; -- } -- -- while (recv_left > 0) { -- if (recv_ring_get_one(sock, noblock | recvd, &pbuf) != 0) { -- /* When the buffer is empty, it will be returned directly -- if in non-blocking mode or if data has already been received */ -- break; -- } -- -- if (unlikely((pbuf == NULL) || (pbuf == (void *)&fin_packet))) { -- if (recv_ring_handle_fin(sock, pbuf, recvd)) { -- return 0; -- } else { -- break; /* recvd > 0, pending fin, handle data */ -- } -- } -- -- copy_len = (recv_left > pbuf->tot_len) ? pbuf->tot_len : recv_left; -- if (copy_len > UINT16_MAX) { -- copy_len = UINT16_MAX; /* it's impossible to get here */ -- } -- pbuf_copy_partial(pbuf, (char *)buf + recvd, copy_len, 0); -- -- recvd += copy_len; -- recv_left -= copy_len; -- -- if (pbuf->tot_len > copy_len) { -- sock->recv_lastdata = pbuf_free_partial(pbuf, copy_len); -- } else { -- if (get_protocol_stack_group()->latency_start) { -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK, 0); -- } -- -- gazelle_ring_read_over(sock->recv_ring); -- } -- } -- -- if (recvd > 0) { -- errno = 0; -- } else { -- recvd = -1; -- } -- -- return recvd; --} -- --static ssize_t recv_ring_udp_read(struct lwip_sock *sock, void *buf, size_t len, bool noblock, -- struct sockaddr *addr, socklen_t *addrlen) --{ -- size_t recv_left = len; -- struct pbuf *pbuf = NULL; -- uint32_t copy_len; -- -- sock->recv_lastdata = NULL; -- -- if (recv_ring_get_one(sock, noblock, &pbuf) != 0) { -- /* errno have set */ -- return -1; -- } -- -- copy_len = (recv_left > pbuf->tot_len) ? pbuf->tot_len : recv_left; -- pbuf_copy_partial(pbuf, (char *)buf, copy_len, 0); -- /* drop remaining data if have */ -- gazelle_ring_read_over(sock->recv_ring); -- -- if (pbuf && addr && addrlen) { -- lwip_sock_make_addr(sock->conn, &(pbuf->addr), pbuf->port, addr, addrlen); -- } -- -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- if (copy_len < pbuf->tot_len) { -- stack->stats.sock_rx_drop++; -- } -- if (get_protocol_stack_group()->latency_start) { -- calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_READ_LSTACK, 0); -- } -- -- return copy_len; --} -- --ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags, -- struct sockaddr *addr, socklen_t *addrlen) --{ -- ssize_t recvd = 0; -- struct lwip_sock *sock = lwip_get_socket(fd); -- bool noblock = (flags & MSG_DONTWAIT) || netconn_is_nonblocking(sock->conn); -- -- if (recv_break_for_err(sock)) { -- return -1; -- } -- -- if (unlikely(sock->affinity_numa == 0)) { -- thread_bind_stack(sock->stack_id); -- sock->affinity_numa = 1; -- } -- --#if GAZELLE_SAME_NODE -- if (sock->same_node_rx_ring != NULL) { -- recvd = gazelle_same_node_ring_recv(sock, buf, len, flags); -- } else --#endif /* GAZELLE_SAME_NODE */ -- if (NETCONN_IS_UDP(sock)) { -- recvd = recv_ring_udp_read(sock, buf, len, noblock, addr, addrlen); -- } else { -- recvd = recv_ring_tcp_read(sock, buf, len, noblock); -- } -- -- API_EVENT(sock->conn, NETCONN_EVT_RCVMINUS, recvd); -- -- if (recvd < 0) { -- return -1; -- } -- return recvd; --} -- --void do_lwip_add_recvlist(int32_t fd) --{ -- struct lwip_sock *sock = lwip_get_socket(fd); -- -- if (sock && list_node_null(&sock->recv_list)) { -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- list_add_node(&sock->recv_list, &stack->recv_list); -- } --} -- --void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num) --{ -- struct list_node *list = &(stack->recv_list); -- struct list_node *node, *temp; -- struct lwip_sock *sock; -- uint32_t read_num = 0; -- -- list_for_each_node(node, temp, list) { -- sock = list_entry(node, struct lwip_sock, recv_list); -- -- if (++read_num > max_num) { -- /* list head move to next send */ -- list_del_node(&stack->recv_list); -- list_add_node(&stack->recv_list, &sock->recv_list); -- break; -- } -- -- if (sock->conn == NULL || sock->conn->recvmbox == NULL || rte_ring_count(sock->conn->recvmbox->ring) == 0) { -- list_del_node(&sock->recv_list); -- continue; -- } -- -- if (get_protocol_stack_group()->latency_start) { -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_RECVMBOX_READY); -- } -- -- ssize_t len = 0; -- if (NETCONN_IS_UDP(sock)) { -- len = lwip_recv(sock->conn->callback_arg.socket, NULL, SSIZE_MAX, 0); -- } else { -- len = lwip_recv(sock->conn->callback_arg.socket, NULL, 0, 0); -- } -- if (len < 0 && errno != EAGAIN) { -- API_EVENT(sock->conn, NETCONN_EVT_ERROR, 0); -- /* = 0: fin */ -- } else if (len >= 0) { -- API_EVENT(sock->conn, NETCONN_EVT_RCVPLUS, 0); -- } -- } --} -- --void do_lwip_connected_callback(int fd) --{ -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (POSIX_IS_CLOSED(sock)) { -- return; -- } -- -- if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { -- /* delete kernel event */ -- if (sock->sk_wait != NULL) { -- posix_api->epoll_ctl_fn(sock->sk_wait->epfd, EPOLL_CTL_DEL, fd, NULL); -- } -- /* shutdown kernel connect, do_connect() has tried both kernel and lwip. */ -- posix_api->shutdown_fn(fd, SHUT_RDWR); -- } -- -- POSIX_SET_TYPE(sock, POSIX_LWIP); -- -- API_EVENT(sock->conn, NETCONN_EVT_RCVPLUS, 0); --} -- --static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const struct tcp_pcb *pcb) --{ -- struct netconn *netconn = (struct netconn *)pcb->callback_arg; -- -- conn->lip = *((gz_addr_t *)&pcb->local_ip); -- conn->rip = *((gz_addr_t *)&pcb->remote_ip); -- conn->l_port = pcb->local_port; -- conn->r_port = pcb->remote_port; -- conn->in_send = pcb->snd_queuelen; -- conn->tcp_sub_state = pcb->state; -- conn->cwn = pcb->cwnd; -- conn->rcv_wnd = pcb->rcv_wnd; -- conn->snd_wnd = pcb->snd_wnd; -- conn->snd_buf = pcb->snd_buf; -- conn->lastack = pcb->lastack; -- conn->snd_nxt = pcb->snd_nxt; -- conn->rcv_nxt = pcb->rcv_nxt; -- conn->keepalive = (ip_get_option(pcb, SOF_KEEPALIVE) != 0); -- conn->keep_idle = pcb->keep_idle; -- conn->keep_intvl = pcb->keep_intvl; -- conn->keep_cnt = pcb->keep_cnt; -- conn->pingpong = tcp_in_pingpong(pcb); -- -- if (netconn != NULL) { -- conn->fd = netconn->callback_arg.socket; -- conn->recv_cnt = (netconn->recvmbox == NULL) ? 0 : rte_ring_count(netconn->recvmbox->ring); -- struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); -- if (!POSIX_IS_CLOSED(sock)) { -- conn->recv_ring_cnt = (sock->recv_ring == NULL) ? 0 : gazelle_ring_readable_count(sock->recv_ring); -- conn->recv_ring_cnt += (sock->recv_lastdata) ? 1 : 0; -- conn->send_ring_cnt = (sock->send_ring == NULL) ? 0 : gazelle_ring_readover_count(sock->send_ring); -- conn->events = sock->sk_event.pending; -- conn->epoll_events = sock->sk_event.events; -- conn->eventlist = !list_node_null(&sock->sk_event.event_node); -- } -- } --} -- --void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock) --{ -- dst_sock->conn->pcb.ip->so_options = src_sock->conn->pcb.ip->so_options; -- dst_sock->conn->pcb.ip->ttl = src_sock->conn->pcb.ip->ttl; -- dst_sock->conn->pcb.ip->tos = src_sock->conn->pcb.ip->tos; -- dst_sock->conn->flags = src_sock->conn->flags; -- if (NETCONN_IS_UDP(src_sock)) { -- dst_sock->conn->pcb.udp->flags = src_sock->conn->pcb.udp->flags; -- dst_sock->conn->pcb.udp->mcast_ifindex = src_sock->conn->pcb.udp->mcast_ifindex; -- dst_sock->conn->pcb.udp->mcast_ttl = src_sock->conn->pcb.udp->mcast_ttl; -- } else { -- dst_sock->conn->pcb.tcp->netif_idx = src_sock->conn->pcb.tcp->netif_idx; -- dst_sock->conn->pcb.tcp->flags = src_sock->conn->pcb.tcp->flags; -- dst_sock->conn->pcb.tcp->keep_idle = src_sock->conn->pcb.tcp->keep_idle; -- dst_sock->conn->pcb.tcp->keep_intvl = src_sock->conn->pcb.tcp->keep_intvl; -- dst_sock->conn->pcb.tcp->keep_cnt = src_sock->conn->pcb.tcp->keep_cnt; -- } --} -- --uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, -- uint32_t max_num) --{ -- struct tcp_pcb *pcb = NULL; -- uint32_t conn_num = 0; -- -- if (conn == NULL) { -- return -1; -- } -- -- for (pcb = tcp_active_pcbs; pcb != NULL && conn_num < max_num; pcb = pcb->next) { -- conn[conn_num].state = GAZELLE_ACTIVE_LIST; -- copy_pcb_to_conn(conn + conn_num, pcb); -- conn_num++; -- } -- -- for (pcb = tcp_tw_pcbs; pcb != NULL && conn_num < max_num; pcb = pcb->next) { -- conn[conn_num].state = GAZELLE_TIME_WAIT_LIST; -- copy_pcb_to_conn(conn + conn_num, pcb); -- conn_num++; -- } -- -- for (struct tcp_pcb_listen *pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL && conn_num < max_num; -- pcbl = pcbl->next) { -- conn[conn_num].state = GAZELLE_LISTEN_LIST; -- conn[conn_num].lip = *((gz_addr_t *)&pcbl->local_ip); -- conn[conn_num].l_port = pcbl->local_port; -- conn[conn_num].tcp_sub_state = pcbl->state; -- struct netconn *netconn = (struct netconn *)pcbl->callback_arg; -- conn[conn_num].fd = netconn != NULL ? netconn->callback_arg.socket : -1; -- if (netconn != NULL && netconn->acceptmbox != NULL) { -- conn[conn_num].recv_cnt = rte_ring_count(netconn->acceptmbox->ring); -- } -- conn_num++; -- } -- -- return conn_num; --} -- --uint32_t do_lwip_get_connnum(void) --{ -- struct tcp_pcb *pcb = NULL; -- struct tcp_pcb_listen *pcbl = NULL; -- uint32_t conn_num = 0; -- -- for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { -- conn_num++; -- } -- -- for (pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL; pcbl = pcbl->next) { -- conn_num++; -- } -- -- for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) { -- conn_num++; -- } -- -- return conn_num; --} -- -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index 8f01f31..983f2f0 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -332,13 +332,14 @@ static const struct mempool_ops mbuf_mp_ops = { - }; - - --static struct rte_mempool *mbuf_pool_create(int stack_id) -+static struct rte_mempool *mbuf_pool_create(int stack_id, uint16_t numa_id) - { - struct cfg_params *cfg_params = get_global_cfg_params(); - char name[RTE_MEMPOOL_NAMESIZE]; - struct rte_mempool *pool; - uint32_t total_conn_mbufs, total_nic_mbufs, total_mbufs; - uint16_t private_size; -+ uint16_t xdp_metadata = 0; - - total_conn_mbufs = cfg_params->mbuf_count_per_conn * cfg_params->tcp_conn_count; - total_nic_mbufs = cfg_params->rxqueue_size + cfg_params->txqueue_size; -@@ -351,9 +352,13 @@ static struct rte_mempool *mbuf_pool_create(int stack_id) - } - - SYS_FORMAT_NAME(name, RTE_MEMPOOL_NAMESIZE, "%s_%hu", "mbuf_pool", stack_id); -- private_size = RTE_ALIGN(sizeof(struct mbuf_private) + 24, RTE_CACHE_LINE_SIZE); -+ /* reserved for xdp metadata, see struct xsk_tx_metadata in /usr/include/linux/if_xdp.h */ -+ if (xdp_eth_enabled()) { -+ xdp_metadata = 24; -+ } -+ private_size = RTE_ALIGN(sizeof(struct mbuf_private) + xdp_metadata, RTE_CACHE_LINE_SIZE); - -- pool = mbuf_mp_ops.create(name, total_mbufs, MBUFPOOL_CACHE_NUM, private_size, MBUF_DATA_SIZE, rte_socket_id()); -+ pool = mbuf_mp_ops.create(name, total_mbufs, MBUFPOOL_CACHE_NUM, private_size, MBUF_DATA_SIZE, numa_id); - if (pool == NULL) { - LSTACK_LOG(ERR, LSTACK, "rte_pktmbuf_pool_create %s failed, rte_errno %d\n", name, rte_errno); - return NULL; -@@ -362,7 +367,7 @@ static struct rte_mempool *mbuf_pool_create(int stack_id) - return pool; - } - --static struct rte_mempool *rpc_pool_create(int stack_id) -+static struct rte_mempool *rpc_pool_create(int stack_id, uint16_t numa_id) - { - char name [RTE_MEMPOOL_NAMESIZE]; - struct rte_mempool *pool; -@@ -370,7 +375,7 @@ static struct rte_mempool *rpc_pool_create(int stack_id) - - SYS_FORMAT_NAME(name, RTE_MEMPOOL_NAMESIZE, "%s_%hu", "rpc_pool", stack_id); - -- pool = mem_mp_ops.create(name, total_bufs, MEMPOOL_CACHE_NUM, 0, sizeof(struct rpc_msg), rte_socket_id()); -+ pool = mem_mp_ops.create(name, total_bufs, MEMPOOL_CACHE_NUM, 0, sizeof(struct rpc_msg), numa_id); - if (pool == NULL) { - LSTACK_LOG(ERR, LSTACK, "rte_mempool_create %s failed, rte_errno %d\n", name, rte_errno); - } -@@ -392,16 +397,16 @@ void mem_stack_pool_free(int stack_id) - } - } - --int mem_stack_pool_init(int stack_id) -+int mem_stack_pool_init(int stack_id, unsigned numa_id) - { - struct mem_stack *ms = mem_stack_get(stack_id); - -- ms->mbuf_pool = mbuf_pool_create(stack_id); -+ ms->mbuf_pool = mbuf_pool_create(stack_id, numa_id); - if (ms->mbuf_pool == NULL) { - return -1; - } - -- ms->rpc_pool = rpc_pool_create(stack_id); -+ ms->rpc_pool = rpc_pool_create(stack_id, numa_id); - if (ms->rpc_pool == NULL) { - mem_stack_pool_free(stack_id); - return -1; -@@ -469,7 +474,7 @@ void mem_thread_cache_free(struct mem_thread *mt) - - int mem_thread_cache_init(struct mem_thread *mt) - { -- if (!get_global_cfg_params()->stack_mode_rtc && !dpdk_nic_is_xdp()) { -+ if (!get_global_cfg_params()->stack_mode_rtc && !xdp_eth_enabled()) { - char name [RTE_MEMPOOL_NAMESIZE]; - SYS_FORMAT_NAME(name, RTE_MEMPOOL_NAMESIZE, "%s_%p", "migrate_ring", mt); - -diff --git a/src/lstack/core/lstack_preload.c b/src/lstack/core/lstack_preload.c -index bdb61e9..2de25f9 100644 ---- a/src/lstack/core/lstack_preload.c -+++ b/src/lstack/core/lstack_preload.c -@@ -94,15 +94,10 @@ enum posix_type select_sock_posix_path(struct lwip_sock *sock) - } - - /* CLOSED means not sockfd, such as file fd or unix fd */ -- if (POSIX_IS_CLOSED(sock) || POSIX_IS_TYPE(sock, POSIX_KERNEL)) { -+ if (POSIX_IS_CLOSED(sock)) { - return POSIX_KERNEL; - } -- -- if (likely(POSIX_IS_TYPE(sock, POSIX_LWIP))) { -- return POSIX_LWIP; -- } -- -- return POSIX_ALL; -+ return sock->type; - } - - enum posix_type select_posix_path(void) -@@ -193,6 +188,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/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 1e7df33..c07d8e7 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -27,13 +27,13 @@ - #include "lstack_cfg.h" - #include "lstack_dpdk.h" - #include "lstack_ethdev.h" --#include "lstack_lwip.h" - #include "lstack_control_plane.h" - #include "lstack_wait.h" - #include "lstack_stack_stat.h" - #include "lstack_virtio.h" - #include "lstack_interrupt.h" - #include "lstack_protocol_stack.h" -+#include "lstack_mempool.h" - - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - #include -@@ -349,8 +349,8 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) - stack->stack_idx = t_params->idx; - stack->lwip_stats = &lwip_stats; - -- list_init_head(&stack->recv_list); -- list_init_head(&stack->same_node_recv_list); -+ rpc_queue_init(&stack->rpc_queue, stack->queue_id); -+ rpc_queue_init(&stack->dfx_rpc_queue, stack->queue_id); - - stack_group->stacks[t_params->idx] = stack; - set_stack_idx(t_params->idx); -@@ -367,11 +367,6 @@ static int32_t init_stack_value(struct protocol_stack *stack, void *arg) - } - } - -- if (pktmbuf_pool_init(stack) != 0) { -- LSTACK_LOG(ERR, LSTACK, "pktmbuf_pool_init failed\n"); -- return -1; -- } -- - if (create_shared_ring(stack) != 0) { - LSTACK_LOG(ERR, LSTACK, "create_shared_ring failed\n"); - return -1; -@@ -426,11 +421,14 @@ static struct protocol_stack *stack_thread_init(void *arg) - 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); - } - -+ if (mem_stack_mpcache_init(stack->stack_idx, stack->cpu_id) < 0) { -+ goto END; -+ } -+ - lwip_init(); - /* Using errno to return lwip_init() result. */ - if (errno != 0) { -@@ -468,7 +466,6 @@ int stack_polling(unsigned wakeup_tick) - bool use_sockmap = cfg->use_sockmap; - bool stack_mode_rtc = cfg->stack_mode_rtc; - uint32_t rpc_number = cfg->rpc_number; -- uint32_t read_connect_number = cfg->read_connect_number; - struct protocol_stack *stack = get_protocol_stack(); - uint32_t timeout; - -@@ -490,8 +487,6 @@ int stack_polling(unsigned wakeup_tick) - return force_quit; - } - -- do_lwip_read_recvlist(stack, read_connect_number); -- - if ((wakeup_tick & 0xf) == 0) { - #if SOCK_WAIT_BATCH_NOTIFY - stack->stats.wakeup_events += lwip_wait_foreach_notify(stack->stack_idx); -@@ -505,10 +500,6 @@ int stack_polling(unsigned wakeup_tick) - /* run to completion mode currently does not support sockmap */ - if (use_sockmap) { - netif_poll(&stack->netif); -- /* reduce traversal times */ -- if ((wakeup_tick & 0xff) == 0) { -- read_same_node_recv_list(stack); -- } - } - #endif /* GAZELLE_SAME_NODE */ - -@@ -538,7 +529,6 @@ static bool stack_local_event_get(uint16_t stack_id) - struct protocol_stack *stack = g_stack_group.stacks[stack_id]; - if (!lockless_queue_empty(&stack->dfx_rpc_queue.queue) || - !lockless_queue_empty(&stack->rpc_queue.queue) || -- !list_head_empty(&stack->recv_list) || - !lwip_wait_notify_empty(stack_id) || - tx_cache_count(stack->queue_id)) { - return true; -@@ -582,9 +572,8 @@ static void* gazelle_stack_thread(void *arg) - - static int stack_group_init_mempool(void) - { -+ int ret; - struct cfg_params *cfg_params = get_global_cfg_params(); -- uint32_t total_mbufs = dpdk_pktmbuf_mempool_num(); -- struct rte_mempool *rxtx_mbuf = NULL; - uint32_t cpu_id = 0; - unsigned numa_id = 0; - int queue_id = 0; -@@ -607,13 +596,12 @@ static int stack_group_init_mempool(void) - return -1; - } - -- rxtx_mbuf = create_pktmbuf_mempool("rxtx_mbuf", total_mbufs, RXTX_CACHE_SZ, queue_id, numa_id); -- if (rxtx_mbuf == NULL) { -- LSTACK_LOG(ERR, LSTACK, "numid=%d, rxtx_mbuf idx=%d, create_pktmbuf_mempool fail\n", numa_id, queue_id); -+ ret = mem_stack_pool_init(queue_id, numa_id); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "mem_stack_pool_init failed, cpuid=%u, numid=%d, queue_id=%d\n", -+ cpu_id, numa_id, queue_id); - return -1; - } -- -- get_protocol_stack_group()->total_rxtx_pktmbuf_pool[queue_id] = rxtx_mbuf; - } - } - -@@ -633,6 +621,11 @@ int stack_group_init(void) - - stack_group->stack_setup_fail = 0; - -+ if (mem_thread_manager_init() != 0) { -+ LSTACK_LOG(ERR, LSTACK, "mem_thread_manager_init failed\n"); -+ return -1; -+ } -+ - if (get_global_cfg_params()->is_primary) { - if (stack_group_init_mempool() != 0) { - LSTACK_LOG(ERR, LSTACK, "stack group init mempool failed\n"); -@@ -640,7 +633,7 @@ int stack_group_init(void) - } - } - -- return 0; -+ return sock_wait_group_init(); - } - - int stack_setup_app_thread(void) -@@ -749,6 +742,24 @@ void stack_wait(void) - } - } - -+static void stack_exit_by_rpc(struct rpc_msg *msg) -+{ -+ stack_exit(); -+} -+ -+static int rpc_call_stack_exit(int stack_id) -+{ -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, stack_exit_by_rpc); -+ if (msg == NULL) { -+ return -1; -+ } -+ -+ msg->flags |= RPC_MSG_EXIT; -+ rpc_async_call(queue, msg, RPC_MSG_FREE | RPC_MSG_EXIT); -+ return 0; -+} -+ - void stack_group_exit(void) - { - int i; -@@ -762,7 +773,7 @@ void stack_group_exit(void) - } - - if (stack != stack_group->stacks[i]) { -- rpc_call_stack_exit(&stack_group->stacks[i]->rpc_queue); -+ rpc_call_stack_exit(i); - } - } - -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index dc9c931..3b3bd75 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -26,29 +26,15 @@ - #include "common/gazelle_dfx_msg.h" - #include "lstack_thread_rpc.h" - #include "lstack_protocol_stack.h" --#include "lstack_epoll.h" - #include "lstack_dpdk.h" - #include "lstack_stack_stat.h" - #include "lstack_virtio.h" --#include "lstack_dump.h" -+#include "lstack_wait.h" -+#include "lstack_mempool.h" - --void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new) -+void time_stamp_into_write(struct pbuf *pbufs[], uint32_t num) - { -- if (!get_protocol_stack_group()->latency_start) { -- return; -- } -- struct latency_timestamp *lt_old; -- struct latency_timestamp *lt_new; -- -- lt_old = &pbuf_to_private(pbuf_old)->lt; -- lt_new = &pbuf_to_private(pbuf_new)->lt; -- -- lt_new->stamp = lt_old->stamp; -- lt_new->check = lt_old->check; -- lt_new->type = lt_old->type; -- for (int i = 0; i < GAZELLE_LATENCY_MAX; i++) { -- lt_new->stamp_seg[i] = lt_old->stamp_seg[i]; -- } -+ time_stamp_into_pbuf(num, pbufs, sys_now_us()); - } - - void time_stamp_into_rpcmsg(struct lwip_sock *sock) -@@ -56,28 +42,29 @@ void time_stamp_into_rpcmsg(struct lwip_sock *sock) - sock->stamp.rpc_time_stamp = sys_now_us(); - } - --void time_stamp_into_recvmbox(struct lwip_sock *sock) -+static void time_stamp_into_recvmbox(struct lwip_sock *sock) - { - sock->stamp.mbox_time_stamp = sys_now_us(); - } - - void time_stamp_record(int fd, struct pbuf *pbuf) - { -- struct lwip_sock *sock = lwip_get_socket(fd); -- -- if (get_protocol_stack_group()->latency_start && sock && pbuf) { -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_INTO_MBOX, 0); -- time_stamp_into_recvmbox(sock); -+ if (get_protocol_stack_group()->latency_start && pbuf) { -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (sock != NULL) { -+ calculate_sock_latency(sock, GAZELLE_LATENCY_RECVMBOX_READY); -+ calculate_lstack_latency(sock->stack_id, &pbuf, 1, GAZELLE_LATENCY_INTO_MBOX, 0); -+ time_stamp_into_recvmbox(sock); -+ } - } - } - --void calculate_sock_latency(struct gazelle_stack_latency *stack_latency, struct lwip_sock *sock, -- enum GAZELLE_LATENCY_TYPE type) -+void calculate_sock_latency(struct lwip_sock *sock, enum GAZELLE_LATENCY_TYPE type) - { - uint64_t latency; - uint64_t stamp; - struct stack_latency *latency_stat; -+ struct protocol_stack *stack; - - if (type == GAZELLE_LATENCY_WRITE_RPC_MSG) { - stamp = sock->stamp.rpc_time_stamp; -@@ -87,12 +74,13 @@ void calculate_sock_latency(struct gazelle_stack_latency *stack_latency, struct - return; - } - -- if (stamp < stack_latency->start_time) { -+ stack = get_protocol_stack(); -+ if (stamp < stack->latency.start_time) { - return; - } - - latency = sys_now_us() - stamp; -- latency_stat = &stack_latency->latency[type]; -+ latency_stat = &stack->latency.latency[type]; - - latency_stat->latency_total += latency; - latency_stat->latency_max = (latency_stat->latency_max > latency) ? latency_stat->latency_max : latency; -@@ -112,47 +100,54 @@ void calculate_latency_stat(struct gazelle_stack_latency *stack_latency, uint64_ - latency_stat->latency_pkts++; - } - --void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, -+void calculate_lstack_latency(int stack_id, struct pbuf *const *pbufs, uint32_t num, - enum GAZELLE_LATENCY_TYPE type, uint64_t time_record) - { - uint64_t latency; - uint16_t lt_type; - struct latency_timestamp *lt; -+ struct gazelle_stack_latency *stack_latency; -+ struct protocol_stack *stack; - -- if (pbuf == NULL || type >= GAZELLE_LATENCY_MAX) { -+ stack = get_protocol_stack_by_id(stack_id); -+ if (stack == NULL) - return; -- } -+ stack_latency = &stack->latency; -+ lt_type = (type / GAZELLE_LATENCY_READ_MAX) ? GAZELLE_LATENCY_WR : GAZELLE_LATENCY_RD; - -- lt = &pbuf_to_private(pbuf)->lt; -- if (lt == NULL) { -- return; -- } -+ for (uint32_t i = 0; i < num; ++i) { -+ if (pbufs[i] == NULL) { -+ continue; -+ } -+ lt = &pbuf_to_private(pbufs[i])->lt; - -- lt_type = (type / GAZELLE_LATENCY_READ_MAX) ? GAZELLE_LATENCY_WR : GAZELLE_LATENCY_RD; -- if (lt->stamp != ~(lt->check) || lt->stamp < stack_latency->start_time || lt_type != lt->type) { -- return; -- } -+ if (lt->stamp != ~(lt->check) || -+ lt->stamp < stack_latency->start_time || -+ lt_type != lt->type) { -+ continue; -+ } - -- if (time_record == 0) { -- lt->stamp_seg[type] = sys_now_us() - lt->stamp; -- } else { -- lt->stamp_seg[type] = time_record > (lt->stamp_seg[type - 1] + lt->stamp) ? -- (time_record - lt->stamp) : lt->stamp_seg[type - 1]; -- } -+ if (time_record == 0) { -+ lt->stamp_seg[type] = sys_now_us() - lt->stamp; -+ } else { -+ lt->stamp_seg[type] = time_record > (lt->stamp_seg[type - 1] + lt->stamp) ? -+ (time_record - lt->stamp) : lt->stamp_seg[type - 1]; -+ } - -- latency = lt->stamp_seg[type]; -- if (((lt_type == GAZELLE_LATENCY_RD && type > GAZELLE_LATENCY_READ_LWIP) || -- (lt_type == GAZELLE_LATENCY_WR && type > GAZELLE_LATENCY_WRITE_INTO_RING)) && -- latency >= lt->stamp_seg[type - 1]) { -- latency -= lt->stamp_seg[type - 1]; -- } -+ latency = lt->stamp_seg[type]; -+ if (((lt_type == GAZELLE_LATENCY_RD && type > GAZELLE_LATENCY_INTO_MBOX) || -+ (lt_type == GAZELLE_LATENCY_WR && type > GAZELLE_LATENCY_WRITE_INTO_RING)) && -+ latency >= lt->stamp_seg[type - 1]) { -+ latency -= lt->stamp_seg[type - 1]; -+ } - -- /* calculate the time of the entire read/write process */ -- if (type == GAZELLE_LATENCY_READ_MAX - 1 || type == GAZELLE_LATENCY_WRITE_MAX - 1) { -- calculate_latency_stat(stack_latency, lt->stamp_seg[type], type + 1); -- } -+ /* calculate the time of the entire read/write process */ -+ if (type == GAZELLE_LATENCY_READ_MAX - 1 || type == GAZELLE_LATENCY_WRITE_MAX - 1) { -+ calculate_latency_stat(stack_latency, lt->stamp_seg[type], type + 1); -+ } - -- calculate_latency_stat(stack_latency, latency, type); -+ calculate_latency_stat(stack_latency, latency, type); -+ } - } - - void lstack_calculate_aggregate(int type, uint32_t len) -@@ -240,13 +235,7 @@ static void get_stack_stats(struct gazelle_stack_dfx_data *dfx, struct protocol_ - int32_t rpc_call_result = rpc_msgcnt(&stack->rpc_queue); - dfx->data.pkts.call_msg_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; - -- if (stack_get_state(stack) == RUNNING) { -- rpc_call_result = rpc_call_mbufpoolsize(&stack->dfx_rpc_queue); -- dfx->data.pkts.mbufpool_avail_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; -- -- rpc_call_result = rpc_call_recvlistcnt(&stack->dfx_rpc_queue); -- dfx->data.pkts.recv_list_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; -- } -+ dfx->data.pkts.mbufpool_avail_cnt = mem_stack_mbuf_pool_count(stack->stack_idx); - - dfx->data.pkts.conn_num = stack->conn_num; - } -@@ -323,13 +312,12 @@ static void get_stack_dfx_data(struct gazelle_stack_dfx_data *dfx, struct protoc - break; - case GAZELLE_STAT_LSTACK_SHOW_CONN: - if (stack_get_state(stack) == RUNNING) { -- rpc_call_result = rpc_call_conntable(&stack->dfx_rpc_queue, dfx->data.conn.conn_list, -+ rpc_call_result = rpc_call_conntable(stack->stack_idx, dfx->data.conn.conn_list, - GAZELLE_LSTACK_MAX_CONN); - dfx->data.conn.conn_num = (rpc_call_result < 0) ? 0 : rpc_call_result; -- rpc_call_result = rpc_call_connnum(&stack->dfx_rpc_queue); -+ rpc_call_result = rpc_call_connnum(stack->stack_idx); - dfx->data.conn.total_conn_num = (rpc_call_result < 0) ? 0 : rpc_call_result; - } -- - break; - case GAZELLE_STAT_LSTACK_SHOW_LATENCY: - ret = memcpy_s(&dfx->data.latency, sizeof(dfx->data.latency), &stack->latency, sizeof(stack->latency)); -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index a831d3b..7b3e432 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -9,33 +9,17 @@ - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ --#include --#include --#include - --#include "lwip/lwipgz_posix_api.h" -+#include -+#include - - #include "lstack_log.h" - #include "lstack_cfg.h" --#include "lstack_dpdk.h" - #include "lstack_stack_stat.h" - #include "lstack_protocol_stack.h" - #include "lstack_thread_rpc.h" --#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; --}; -+#include "lstack_mempool.h" - --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; - - struct rpc_stats *rpc_stats_get(void) -@@ -44,114 +28,60 @@ struct rpc_stats *rpc_stats_get(void) - } - - __rte_always_inline --static struct rpc_msg *get_rpc_msg(struct rpc_msg_pool *rpc_pool) --{ -- int ret; -- struct rpc_msg *msg = NULL; -- ret = rte_mempool_get(rpc_pool->mempool, (void **)&msg); -- if (ret < 0) { -- errno = ENOMEM; -- return NULL; -- } -- return msg; --} -- --__rte_always_inline --static void rpc_msg_init(struct rpc_msg *msg, rpc_func_t func, struct rpc_msg_pool *pool) -+static void rpc_msg_init(struct rpc_msg *msg, rpc_func_t func) - { - msg->func = func; -- msg->rpcpool = pool; -- msg->recall_flag = 0; -+ msg->flags = 0; - pthread_spin_init(&msg->lock, PTHREAD_PROCESS_PRIVATE); --} -- --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]; -- } - -- 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; -- } -- -- 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; -+ lockless_queue_node_set_poped(&msg->queue_node); - } - -- --static struct rpc_msg *rpc_msg_alloc(rpc_func_t func) -+struct rpc_msg *rpc_msg_alloc(int stack_id, rpc_func_t func) - { - struct rpc_msg *msg; - -- if (unlikely(g_rpc_pool == NULL)) { -- g_rpc_pool = rpc_msg_pool_init(); -- if (g_rpc_pool == NULL) { -- exit(-1); -- } -- } -- -- msg = get_rpc_msg(g_rpc_pool); -+ msg = mem_get_rpc(stack_id); - if (unlikely(msg == NULL)) { - g_rpc_stats.call_alloc_fail++; - return NULL; - } - -- rpc_msg_init(msg, func, g_rpc_pool); -+ rpc_msg_init(msg, func); - return msg; - } - --__rte_always_inline --static void rpc_msg_free(struct rpc_msg *msg) -+void rpc_msg_free(struct rpc_msg *msg) - { - pthread_spin_destroy(&msg->lock); -- if (msg->rpcpool != NULL && msg->rpcpool->mempool != NULL) { -- rte_mempool_put(msg->rpcpool->mempool, (void *)msg); -- } else { -- free(msg); -- } -+ mem_put_rpc(msg); - } - --__rte_always_inline --static void rpc_call(rpc_queue *queue, struct rpc_msg *msg) -+void rpc_async_call(rpc_queue *queue, struct rpc_msg *msg, int flags) - { -- lockless_queue_mpsc_push(&queue->queue, &msg->queue_node); -- intr_wakeup(queue->queue_id, INTR_REMOTE_EVENT); --} -+ if (flags & RPC_MSG_RECALL) -+ msg->flags |= flags; /* if RECALL, keep the previous flags. */ -+ else -+ msg->flags = flags & (~RPC_MSG_SYNC); - --__rte_always_inline --static void rpc_async_call(rpc_queue *queue, struct rpc_msg *msg) --{ -- msg->sync_flag = 0; -- rpc_call(queue, msg); -+ if (msg->flags & RPC_MSG_REUSE) -+ lockless_queue_mpsc_test_push(&queue->queue, &msg->queue_node); -+ else -+ lockless_queue_mpsc_push(&queue->queue, &msg->queue_node); -+ -+ intr_wakeup(queue->queue_id, INTR_REMOTE_EVENT); - } - --__rte_always_inline --static int rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg) -+int rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg) - { - int ret; - - pthread_spin_trylock(&msg->lock); - -- msg->sync_flag = 1; -- rpc_call(queue, msg); -+ msg->flags = RPC_MSG_SYNC; -+ lockless_queue_mpsc_push(&queue->queue, &msg->queue_node); -+ -+ intr_wakeup(queue->queue_id, INTR_REMOTE_EVENT); - - // waiting stack unlock - pthread_spin_lock(&msg->lock); -@@ -161,36 +91,15 @@ static int rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg) - return ret; - } - --int rpc_msgcnt(rpc_queue *queue) -+void rpc_queue_init(rpc_queue *queue, uint16_t queue_id) - { -- return lockless_queue_count(&queue->queue); -+ lockless_queue_init(&queue->queue); -+ queue->queue_id = queue_id; - } - --static struct rpc_msg *rpc_msg_alloc_except(rpc_func_t func) --{ -- struct rpc_msg *msg = calloc(1, sizeof(struct rpc_msg)); -- if (msg == NULL) { -- return NULL; -- } -- -- rpc_msg_init(msg, func, NULL); -- return msg; --} -- --static void stack_exit_by_rpc(struct rpc_msg *msg) --{ -- stack_exit(); --} -- --int rpc_call_stack_exit(rpc_queue *queue) -+int rpc_msgcnt(rpc_queue *queue) - { -- struct rpc_msg *msg = rpc_msg_alloc_except(stack_exit_by_rpc); -- if (msg == NULL) { -- return -1; -- } -- -- rpc_async_call(queue, msg); -- return 0; -+ return lockless_queue_count(&queue->queue); - } - - int rpc_poll_msg(rpc_queue *queue, int max_num) -@@ -203,7 +112,6 @@ int rpc_poll_msg(rpc_queue *queue, int max_num) - if (node == NULL) { - break; - } -- - msg = container_of(node, struct rpc_msg, queue_node); - - if (likely(msg->func)) { -@@ -212,17 +120,19 @@ int rpc_poll_msg(rpc_queue *queue, int max_num) - g_rpc_stats.call_null++; - } - -- if (unlikely(msg->func == stack_exit_by_rpc)) { -- force_quit = 1; -- } -- if (msg->recall_flag) { -- msg->recall_flag = 0; -+ if (msg->flags & RPC_MSG_RECALL) { -+ msg->flags &= ~RPC_MSG_RECALL; - continue; - } - -- if (msg->sync_flag) { -+ if (unlikely(msg->flags & RPC_MSG_EXIT)) { -+ force_quit = 1; -+ } -+ -+ if (msg->flags & RPC_MSG_SYNC) { - pthread_spin_unlock(&msg->lock); -- } else { -+ } -+ if (msg->flags & RPC_MSG_FREE) { - rpc_msg_free(msg); - } - } -@@ -231,560 +141,145 @@ int rpc_poll_msg(rpc_queue *queue, int max_num) - } - - --static void callback_socket(struct rpc_msg *msg) --{ -- msg->result = lwip_socket(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i); -- if (msg->result < 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %d, %ld socket failed\n", rte_gettid(), msg->result); -- } --} -- --static void callback_close(struct rpc_msg *msg) --{ -- int fd = msg->args[MSG_ARG_0].i; -- struct lwip_sock *sock = lwip_get_socket(fd); -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- -- if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { -- msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); /* until stack_send recall finish */ -- return; -- } -- -- msg->result = lwip_close(fd); -- if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d failed %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); -- } --} -- --static void callback_shutdown(struct rpc_msg *msg) --{ -- int fd = msg->args[MSG_ARG_0].i; -- int how = msg->args[MSG_ARG_1].i; -- struct lwip_sock *sock = lwip_get_socket(fd); -- struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); -- -- if (sock && __atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) > 0) { -- msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); -- return; -- } -- -- msg->result = lwip_shutdown(fd, how); -- if (msg->result != 0 && errno != ENOTCONN) { -- LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d fail %ld\n", rte_gettid(), fd, msg->result); -- } -- -- posix_api->shutdown_fn(fd, how); --} -- --static void callback_bind(struct rpc_msg *msg) --{ -- msg->result = lwip_bind(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].cp, msg->args[MSG_ARG_2].u); -- if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d failed %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); -- } --} -- --static void callback_listen(struct rpc_msg *msg) --{ -- int fd = msg->args[MSG_ARG_0].i; -- int backlog = msg->args[MSG_ARG_1].i; -- -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- msg->result = -1; -- return; -- } -- -- /* new listen add to stack listen list */ -- msg->result = lwip_listen(fd, backlog); -- if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d failed %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); -- } --} -- --static void callback_create_shadow_fd(struct rpc_msg *msg) --{ -- int fd = msg->args[MSG_ARG_0].i; -- struct sockaddr *addr = msg->args[MSG_ARG_1].p; -- socklen_t addr_len = msg->args[MSG_ARG_2].u; -- -- int clone_fd = 0; -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d\n", fd); -- msg->result = -1; -- return; -- } -- -- int domain = addr->sa_family; -- int type = NETCONN_IS_UDP(sock) ? SOCK_DGRAM : SOCK_STREAM; -- clone_fd = lwip_socket(domain, type, 0); -- if (clone_fd < 0) { -- LSTACK_LOG(ERR, LSTACK, "clone socket failed clone_fd=%d errno=%d\n", clone_fd, errno); -- msg->result = clone_fd; -- return; -- } -- -- struct lwip_sock *clone_sock = lwip_get_socket(clone_fd); -- if (clone_sock == NULL) { -- LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d clone_fd=%d\n", fd, clone_fd); -- msg->result = -1; -- return; -- } -- -- do_lwip_clone_sockopt(clone_sock, sock); -- -- while (sock->listen_next) { -- sock = sock->listen_next; -- } -- sock->listen_next = clone_sock; -- -- int ret = lwip_bind(clone_fd, addr, addr_len); -- if (ret < 0) { -- LSTACK_LOG(ERR, LSTACK, "clone bind failed clone_fd=%d errno=%d\n", clone_fd, errno); -- msg->result = ret; -- return; -- } -- -- msg->result = clone_fd; --} -- --static void callback_accept(struct rpc_msg *msg) -+static void callback_arp(struct rpc_msg *msg) - { -- int fd = msg->args[MSG_ARG_0].i; -- msg->result = -1; -+ struct rte_mbuf *mbuf = (struct rte_mbuf *)msg->args[MSG_ARG_0].p; - struct protocol_stack *stack = get_protocol_stack(); - -- int accept_fd = lwip_accept4(fd, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].p, msg->args[MSG_ARG_3].i); -- if (accept_fd < 0) { -- stack->stats.accept_fail++; -- LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); -- return; -- } -- -- struct lwip_sock *sock = lwip_get_socket(accept_fd); -- if (sock == NULL) { -- lwip_close(accept_fd); -- LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); -- return; -- } -- -- msg->result = accept_fd; -- stack->conn_num++; -- if (rte_ring_count(sock->conn->recvmbox->ring)) { -- do_lwip_add_recvlist(accept_fd); -- } --} -- --static void callback_connect(struct rpc_msg *msg) --{ -- msg->result = lwip_connect(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].u); -- if (msg->result < 0) { -- msg->result = -errno; -- } --} -- --int rpc_call_socket(rpc_queue *queue, int domain, int type, int protocol) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_socket); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].i = domain; -- msg->args[MSG_ARG_1].i = type; -- msg->args[MSG_ARG_2].i = protocol; -- -- return rpc_sync_call(queue, msg); --} -- --int rpc_call_close(rpc_queue *queue, int fd) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_close); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].i = fd; -- -- return rpc_sync_call(queue, msg); --} -- --int rpc_call_shutdown(rpc_queue *queue, int fd, int how) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_shutdown); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].i = how; -- -- return rpc_sync_call(queue, msg); --} -- --int rpc_call_bind(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_bind); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].cp = addr; -- msg->args[MSG_ARG_2].u = addrlen; -- -- return rpc_sync_call(queue, msg); --} -- --int rpc_call_listen(rpc_queue *queue, int s, int backlog) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_listen); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].i = s; -- msg->args[MSG_ARG_1].i = backlog; -- -- return rpc_sync_call(queue, msg); --} -- --int rpc_call_shadow_fd(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_create_shadow_fd); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].cp = addr; -- msg->args[MSG_ARG_2].u = addrlen; -- -- return rpc_sync_call(queue, msg); --} -- --int rpc_call_accept(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen, int flags) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_accept); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].p = addr; -- msg->args[MSG_ARG_2].p = addrlen; -- msg->args[MSG_ARG_3].i = flags; -- -- return rpc_sync_call(queue, msg); --} -- --int rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_connect); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].cp = addr; -- msg->args[MSG_ARG_2].u = addrlen; -- -- int ret = rpc_sync_call(queue, msg); -- if (ret < 0) { -- errno = -ret; -- return -1; -- } -- return ret; --} -- --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); --} -- --static void callback_getsockname(struct rpc_msg *msg) --{ -- msg->result = lwip_getsockname(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 %d, fd %d fail %ld\n", rte_gettid(), msg->args[MSG_ARG_0].i, msg->result); -- } --} -- --static void callback_getsockopt(struct rpc_msg *msg) --{ -- msg->result = lwip_getsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, -- msg->args[MSG_ARG_3].p, msg->args[MSG_ARG_4].p); -- if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d, level %d, optname %d, fail %ld\n", rte_gettid(), -- msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); -- } --} -- --static void callback_setsockopt(struct rpc_msg *msg) --{ -- msg->result = lwip_setsockopt(msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, -- msg->args[MSG_ARG_3].cp, msg->args[MSG_ARG_4].u); -- if (msg->result != 0) { -- LSTACK_LOG(ERR, LSTACK, "tid %d, fd %d, level %d, optname %d, fail %ld\n", rte_gettid(), -- msg->args[MSG_ARG_0].i, msg->args[MSG_ARG_1].i, msg->args[MSG_ARG_2].i, msg->result); -- } --} -- --int rpc_call_getpeername(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_getpeername); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].p = addr; -- msg->args[MSG_ARG_2].p = addrlen; -- -- return rpc_sync_call(queue, msg); --} -- --int rpc_call_getsockname(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_getsockname); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].p = addr; -- msg->args[MSG_ARG_2].p = addrlen; -- -- return rpc_sync_call(queue, msg); --} -- --int rpc_call_getsockopt(rpc_queue *queue, int fd, int level, int optname, void *optval, socklen_t *optlen) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_getsockopt); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].i = level; -- msg->args[MSG_ARG_2].i = optname; -- msg->args[MSG_ARG_3].p = optval; -- msg->args[MSG_ARG_4].p = optlen; -- -- return rpc_sync_call(queue, msg); -+ eth_dev_recv(mbuf, stack); - } - --int rpc_call_setsockopt(rpc_queue *queue, int fd, int level, int optname, const void *optval, socklen_t optlen) -+int rpc_call_arp(int stack_id, void *mbuf) - { -- struct rpc_msg *msg = rpc_msg_alloc(callback_setsockopt); -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_arp); - if (msg == NULL) { - return -1; - } - -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].i = level; -- msg->args[MSG_ARG_2].i = optname; -- msg->args[MSG_ARG_3].cp = optval; -- msg->args[MSG_ARG_4].u = optlen; -+ msg->args[MSG_ARG_0].p = mbuf; - -- return rpc_sync_call(queue, msg); -+ rpc_async_call(queue, msg, RPC_MSG_FREE); -+ return 0; - } - --static void callback_tcp_send(struct rpc_msg *msg) --{ -- int fd = msg->args[MSG_ARG_0].i; -- size_t len = UINT16_MAX; /* ignore msg->args[MSG_ARG_1].size; */ -- struct protocol_stack *stack = get_protocol_stack(); -- int ret; -- msg->result = -1; -- -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (unlikely(POSIX_IS_CLOSED(sock))) { -- return; -- } -- -- if (get_protocol_stack_group()->latency_start) { -- calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_WRITE_RPC_MSG); -- } -+static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const struct tcp_pcb *pcb) -+{ -+ struct netconn *netconn = (struct netconn *)pcb->callback_arg; -+ const struct mbox_ring *mr; -+ -+ conn->lip = *((gz_addr_t *)&pcb->local_ip); -+ conn->rip = *((gz_addr_t *)&pcb->remote_ip); -+ conn->l_port = pcb->local_port; -+ conn->r_port = pcb->remote_port; -+ conn->in_send = pcb->snd_queuelen; -+ conn->tcp_sub_state = pcb->state; -+ conn->cwn = pcb->cwnd; -+ conn->rcv_wnd = pcb->rcv_wnd; -+ conn->snd_wnd = pcb->snd_wnd; -+ conn->snd_buf = pcb->snd_buf; -+ conn->lastack = pcb->lastack; -+ conn->snd_nxt = pcb->snd_nxt; -+ conn->rcv_nxt = pcb->rcv_nxt; -+ conn->keepalive = (ip_get_option(pcb, SOF_KEEPALIVE) != 0); -+ conn->keep_idle = pcb->keep_idle; -+ conn->keep_intvl = pcb->keep_intvl; -+ conn->keep_cnt = pcb->keep_cnt; -+ conn->pingpong = tcp_in_pingpong(pcb); -+ -+ if (netconn != NULL) { -+ if (sys_mbox_valid(&netconn->recvmbox)) { -+ mr = &netconn->recvmbox->mring; -+ conn->recvmbox_cnt = mr->ops->recv_count(mr); -+ conn->recvmbox_tail = mr->tail_count(mr); -+ } -+ if (sys_mbox_valid(&netconn->sendmbox)) { -+ mr = &netconn->sendmbox->mring; -+ conn->sendmbox_cnt = mr->ops->count(mr); -+ conn->sendmbox_tail = mr->tail_count(mr); -+ } - -- ret = lwip_send(fd, sock, len, 0); -- if (unlikely(ret < 0) && (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED)) { -- __sync_fetch_and_sub(&sock->call_num, 1); -- return; -- } -- msg->result = 0; -- -- ret = do_lwip_replenish_sendring(stack, sock); -- if (ret > 0 || NETCONN_IS_DATAOUT(sock)) { -- if (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1) { -- msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); -- return; -+ conn->fd = netconn->callback_arg.socket; -+ struct lwip_sock *sock = lwip_get_socket(netconn->callback_arg.socket); -+ if (!POSIX_IS_CLOSED(sock)) { -+ struct sock_event *sk_event = &sock->sk_event; -+ conn->events = sk_event->pending; -+ conn->epoll_events = sk_event->events; -+ conn->eventlist = !list_node_null(&sk_event->event_node); - } - } -- -- __sync_fetch_and_sub(&sock->call_num, 1); -- return; - } - --static void callback_udp_send(struct rpc_msg *msg) -+static uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, -+ uint32_t max_num) - { -- int fd = msg->args[MSG_ARG_0].i; -- size_t len = msg->args[MSG_ARG_1].size; -- struct protocol_stack *stack = get_protocol_stack(); -- int ret; -- msg->result = -1; -- -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (unlikely(POSIX_IS_CLOSED(sock))) { -- return; -- } -- -- if (get_protocol_stack_group()->latency_start) { -- calculate_sock_latency(&stack->latency, sock, GAZELLE_LATENCY_WRITE_RPC_MSG); -- } -- -- ret = lwip_send(fd, sock, len, 0); -- if (unlikely(ret < 0) && (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED)) { -- __sync_fetch_and_sub(&sock->call_num, 1); -- return; -- } -- msg->result = 0; -- -- ret = do_lwip_replenish_sendring(stack, sock); -- if (ret > 0 && (__atomic_load_n(&sock->call_num, __ATOMIC_ACQUIRE) == 1)) { -- rpc_call_replenish(&stack->rpc_queue, sock); -- return; -- } -+ struct tcp_pcb *pcb = NULL; -+ uint32_t conn_num = 0; -+ const struct mbox_ring *mr; - -- __sync_fetch_and_sub(&sock->call_num, 1); -- return; --} -- --int rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_udp_send); -- if (msg == NULL) { -+ if (conn == NULL) { - return -1; - } - -- if (get_protocol_stack_group()->latency_start) { -- time_stamp_into_rpcmsg(lwip_get_socket(fd)); -+ for (pcb = tcp_active_pcbs; pcb != NULL && conn_num < max_num; pcb = pcb->next) { -+ conn[conn_num].state = GAZELLE_ACTIVE_LIST; -+ copy_pcb_to_conn(conn + conn_num, pcb); -+ conn_num++; - } - -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].size = len; -- msg->args[MSG_ARG_2].i = flags; -- -- rpc_async_call(queue, msg); -- return 0; --} -- --int rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_tcp_send); -- if (msg == NULL) { -- return -1; -+ for (pcb = tcp_tw_pcbs; pcb != NULL && conn_num < max_num; pcb = pcb->next) { -+ conn[conn_num].state = GAZELLE_TIME_WAIT_LIST; -+ copy_pcb_to_conn(conn + conn_num, pcb); -+ conn_num++; - } - -- if (get_protocol_stack_group()->latency_start) { -- time_stamp_into_rpcmsg(lwip_get_socket(fd)); -+ for (struct tcp_pcb_listen *pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL && conn_num < max_num; -+ pcbl = pcbl->next) { -+ conn[conn_num].state = GAZELLE_LISTEN_LIST; -+ conn[conn_num].lip = *((gz_addr_t *)&pcbl->local_ip); -+ conn[conn_num].l_port = pcbl->local_port; -+ conn[conn_num].tcp_sub_state = pcbl->state; -+ struct netconn *netconn = (struct netconn *)pcbl->callback_arg; -+ conn[conn_num].fd = netconn != NULL ? netconn->callback_arg.socket : -1; -+ if (netconn != NULL) { -+ if (sys_mbox_valid(&netconn->acceptmbox)) { -+ mr = &netconn->acceptmbox->mring; -+ conn[conn_num].recvmbox_cnt = mr->ops->count(mr); -+ } -+ } -+ conn_num++; - } - -- msg->args[MSG_ARG_0].i = fd; -- msg->args[MSG_ARG_1].size = len; -- msg->args[MSG_ARG_2].i = flags; -- -- rpc_async_call(queue, msg); -- return 0; -+ return conn_num; - } - --static void callback_replenish_sendring(struct rpc_msg *msg) --{ -- struct protocol_stack *stack = get_protocol_stack(); -- struct lwip_sock *sock = (struct lwip_sock *)msg->args[MSG_ARG_0].p; -- -- msg->result = do_lwip_replenish_sendring(stack, sock); -- if (msg->result == true) { -- msg->recall_flag = 1; -- rpc_call(&stack->rpc_queue, msg); -- } --} -- --int rpc_call_replenish(rpc_queue *queue, void *sock) -+static void callback_get_conntable(struct rpc_msg *msg) - { -- struct rpc_msg *msg = rpc_msg_alloc(callback_replenish_sendring); -- if (msg == NULL) { -- return -1; -- } -- -- msg->args[MSG_ARG_0].p = sock; -+ struct gazelle_stat_lstack_conn_info *conn = (struct gazelle_stat_lstack_conn_info *)msg->args[MSG_ARG_0].p; -+ unsigned max_num = msg->args[MSG_ARG_1].u; - -- rpc_async_call(queue, msg); -- return 0; -+ msg->result = do_lwip_get_conntable(conn, max_num); - } - --static void callback_recvlist_count(struct rpc_msg *msg) -+static uint32_t do_lwip_get_connnum(void) - { -- struct protocol_stack *stack = get_protocol_stack(); -- struct list_node *list = &stack->recv_list; -- int count = 0; -- struct list_node *node; -- struct list_node *temp; -+ struct tcp_pcb *pcb = NULL; -+ struct tcp_pcb_listen *pcbl = NULL; -+ uint32_t conn_num = 0; - -- list_for_each_node(node, temp, list) { -- count++; -+ for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) { -+ conn_num++; - } -- msg->result = count; --} - --int rpc_call_recvlistcnt(rpc_queue *queue) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_recvlist_count); -- if (msg == NULL) { -- return -1; -+ for (pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL; pcbl = pcbl->next) { -+ conn_num++; - } - -- return rpc_sync_call(queue, msg); --} -- --static void callback_arp(struct rpc_msg *msg) --{ -- struct rte_mbuf *mbuf = (struct rte_mbuf *)msg->args[MSG_ARG_0].p; -- struct protocol_stack *stack = get_protocol_stack(); -- -- eth_dev_recv(mbuf, stack); --} -- --int rpc_call_arp(rpc_queue *queue, void *mbuf) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_arp); -- if (msg == NULL) { -- return -1; -+ for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) { -+ conn_num++; - } - -- msg->args[MSG_ARG_0].p = mbuf; -- -- rpc_async_call(queue, msg); -- return 0; --} -- --static void callback_mempool_size(struct rpc_msg *msg) --{ -- struct protocol_stack *stack = get_protocol_stack(); -- -- msg->result = rte_mempool_avail_count(stack->rxtx_mbuf_pool); --} -- --static void callback_get_conntable(struct rpc_msg *msg) --{ -- struct gazelle_stat_lstack_conn_info *conn = (struct gazelle_stat_lstack_conn_info *)msg->args[MSG_ARG_0].p; -- unsigned max_num = msg->args[MSG_ARG_1].u; -- -- msg->result = do_lwip_get_conntable(conn, max_num); -+ return conn_num; - } - - static void callback_get_connnum(struct rpc_msg *msg) -@@ -792,9 +287,10 @@ static void callback_get_connnum(struct rpc_msg *msg) - msg->result = do_lwip_get_connnum(); - } - --int rpc_call_conntable(rpc_queue *queue, void *conn_table, unsigned max_conn) -+int rpc_call_conntable(int stack_id, void *conn_table, unsigned max_conn) - { -- struct rpc_msg *msg = rpc_msg_alloc(callback_get_conntable); -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->dfx_rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_get_conntable); - if (msg == NULL) { - return -1; - } -@@ -805,44 +301,13 @@ int rpc_call_conntable(rpc_queue *queue, void *conn_table, unsigned max_conn) - return rpc_sync_call(queue, msg); - } - --int rpc_call_connnum(rpc_queue *queue) -+int rpc_call_connnum(int stack_id) - { -- struct rpc_msg *msg = rpc_msg_alloc(callback_get_connnum); -+ rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->dfx_rpc_queue; -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_get_connnum); - if (msg == NULL) { - return -1; - } - - return rpc_sync_call(queue, msg); - } -- --int rpc_call_mbufpoolsize(rpc_queue *queue) --{ -- struct rpc_msg *msg = rpc_msg_alloc(callback_mempool_size); -- if (msg == NULL) { -- return -1; -- } -- -- return rpc_sync_call(queue, msg); --} -- --extern void thread_register_phase1(struct rpc_msg *msg); --int rpc_call_thread_regphase1(rpc_queue *queue, void *conn) --{ -- struct rpc_msg *msg = rpc_msg_alloc(thread_register_phase1); -- if (msg == NULL) { -- return -1; -- } -- msg->args[MSG_ARG_0].p = conn; -- return rpc_sync_call(queue, msg); --} -- --extern void thread_register_phase2(struct rpc_msg *msg); --int rpc_call_thread_regphase2(rpc_queue *queue, void *conn) --{ -- struct rpc_msg *msg = rpc_msg_alloc(thread_register_phase2); -- if (msg == NULL) { -- return -1; -- } -- msg->args[MSG_ARG_0].p = conn; -- return rpc_sync_call(queue, msg); --} -diff --git a/src/lstack/core/lstack_virtio.c b/src/lstack/core/lstack_virtio.c -index f6855d1..2c2d74e 100644 ---- a/src/lstack/core/lstack_virtio.c -+++ b/src/lstack/core/lstack_virtio.c -@@ -24,6 +24,7 @@ - #include "lstack_port_map.h" - #include "lstack_interrupt.h" - #include "lstack_virtio.h" -+#include "mbox_ring.h" - - #define VIRTIO_USER_NAME "virtio_user" - #define VIRTIO_DPDK_PARA_LEN 256 -@@ -293,7 +294,7 @@ static int virtio_port_init(uint16_t port) - } - - for (uint16_t q = 0; q < rx_queue_num; q++) { -- struct rte_mempool *rxtx_mbuf_pool = get_protocol_stack_group()->total_rxtx_pktmbuf_pool[q % mbuf_total_num]; -+ struct rte_mempool *rxtx_mbuf_pool = mem_get_mbuf_pool(q % mbuf_total_num); - retval = rte_eth_rx_queue_setup(port, q, VIRTIO_TX_RX_RING_SIZE, rte_eth_dev_socket_id(port), - NULL, rxtx_mbuf_pool); - if (retval < 0) { -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -index 6334f5e..c67df93 100644 ---- a/src/lstack/core/lstack_wait.c -+++ b/src/lstack/core/lstack_wait.c -@@ -26,7 +26,7 @@ - #include "lstack_log.h" - #include "lstack_cfg.h" - #include "same_node.h" --#include "lstack_lwip.h" -+#include "mbox_ring.h" - - #define KERNEL_EVENT_WAIT_US 10 - #define LWIP_EVENT_WAIT_US 10 -@@ -340,26 +340,34 @@ void sock_wait_kernel_free(struct sock_wait *sk_wait) - static inline bool NETCONN_NEED_ACCEPT(const struct lwip_sock *sock) - { - if (sys_mbox_valid(&sock->conn->acceptmbox)) { -- return !sys_mbox_empty(sock->conn->acceptmbox); -+ const struct mbox_ring *mr = &sock->conn->acceptmbox->mring; -+ return mr->ops->count(mr) > 0; - } - return false; - } - - static inline bool NETCONN_NEED_RECV(const struct lwip_sock *sock) - { -- if (sock->recv_lastdata != NULL) -- return true; -- if (gazelle_ring_readable_count(sock->recv_ring) > 0) -- return true; -- if (NETCONN_NEED_SAME_NODE(sock)) -+ if (sock->lastdata.pbuf != NULL) - return true; -+ if (sys_mbox_valid(&sock->conn->recvmbox)) { -+ const struct mbox_ring *mr = &sock->conn->recvmbox->mring; -+ return mr->ops->recv_count(mr) > 0; -+ } - return false; - } - - static inline bool NETCONN_ALLOW_SEND(const struct lwip_sock *sock) - { -- if (gazelle_ring_readable_count(sock->send_ring) > 0) -- return true; -+ if (get_global_cfg_params()->stack_mode_rtc) { -+ if (NETCONN_TYPE(sock->conn) == NETCONN_TCP) -+ return lwip_tcp_allow_send(sock->conn->pcb.tcp); -+ return false; -+ } -+ if (sys_mbox_valid(&sock->conn->sendmbox)) { -+ const struct mbox_ring *mr = &sock->conn->sendmbox->mring; -+ return mr->ops->free_count(mr) > 0; -+ } - return false; - } - -diff --git a/src/lstack/core/same_node.c b/src/lstack/core/same_node.c -index 660fefd..eb3610e 100644 ---- a/src/lstack/core/same_node.c -+++ b/src/lstack/core/same_node.c -@@ -20,25 +20,10 @@ - #include "lstack_protocol_stack.h" - #include "lstack_stack_stat.h" - #include "same_node.h" --#include "lstack_epoll.h" --#include "lstack_lwip.h" -+#include "lstack_wait.h" - --#if GAZELLE_SAME_NODE --void read_same_node_recv_list(struct protocol_stack *stack) --{ -- struct list_node *list = &(stack->same_node_recv_list); -- struct list_node *node, *temp; -- struct lwip_sock *sock; -- -- list_for_each_node(node, temp, list) { -- sock = list_entry(node, struct lwip_sock, recv_list); -- -- if (sock->same_node_rx_ring != NULL && same_node_ring_count(sock)) { -- API_EVENT(sock->conn, NETCONN_EVT_RCVPLUS, 0); -- } -- } --} - -+#if GAZELLE_SAME_NODE - /* process on same node use ring to recv data */ - ssize_t gazelle_same_node_ring_recv(struct lwip_sock *sock, const void *buf, size_t len, int32_t flags) - { -@@ -231,8 +216,7 @@ err_t find_same_node_memzone(struct tcp_pcb *pcb, struct lwip_sock *nsock) - - /* rcvlink init in alloc_socket() */ - /* remove from g_rcv_process_list in free_socket */ -- struct protocol_stack *stack = get_protocol_stack_by_id(nsock->stack_id); -- list_add_node(&nsock->recv_list, &stack->same_node_recv_list); -+ API_EVENT(nsock->conn, NETCONN_EVT_RCVPLUS, 0); - return 0; - } - -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index d59407b..3e671b5 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -128,15 +128,12 @@ struct cfg_params { - bool listen_shadow; // true:listen in all stack thread. false:listen in one stack thread. - bool stack_interrupt; - -- uint32_t read_connect_number; - uint32_t nic_read_number; - uint32_t rpc_number; - uint32_t rpc_msg_max; - }; - - struct { // socket -- uint16_t send_ring_size; -- uint16_t recv_ring_size; - uint32_t tcp_conn_count; - uint32_t mbuf_count_per_conn; - }; -@@ -167,7 +164,8 @@ static inline uint8_t use_ltran(void) - - static inline bool xdp_eth_enabled(void) - { -- if (strlen(get_global_cfg_params()->xdp_eth_name)) { -+ /* strlen > 0 */ -+ if (get_global_cfg_params()->xdp_eth_name[0] != '\0') { - return true; - } - return false; -diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h -index 6251be7..f70477e 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -13,6 +13,7 @@ - #ifndef _GAZELLE_DPDK_H_ - #define _GAZELLE_DPDK_H_ - -+#include - #include - #include - #include -@@ -20,21 +21,10 @@ - #include "common/gazelle_opt.h" - #include "common/gazelle_dfx_msg.h" - --#define RXTX_CACHE_SZ (VDEV_RX_QUEUE_SZ) -- - #define KNI_NB_MBUF (DEFAULT_RING_SIZE << 4) - --#define MAX_PACKET_SZ 1538 -- - #define RING_SIZE(x) ((x) - 1) - --#define MBUF_SZ (MAX_PACKET_SZ + RTE_PKTMBUF_HEADROOM) -- --/* DPDK limit ring head-tail distance in rte_ring_init. -- * Max value is RTE_RING_SZ_MASK / HTD_MAX_DEF, RTE_RING_SZ_MASK is 0x7fffffff, HTD_MAX_DEF is 8. -- */ --#define MBUF_MAX_NUM 0xfffffff -- - struct protocol_stack; - - int32_t dpdk_eal_init(void); -@@ -47,13 +37,7 @@ int init_dpdk_ethdev(void); - int thread_affinity_default(void); - - 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); --int32_t pktmbuf_pool_init(struct protocol_stack *stack); --struct rte_mempool *create_mempool(const char *name, uint32_t count, uint32_t size, -- uint32_t flags, int32_t idx); --struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_mbuf, -- uint32_t mbuf_cache_size, uint16_t queue_id, unsigned numa_id); --int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num, bool reserve); -+int32_t fill_mbuf_to_ring(int stack_id, struct rte_ring *ring, uint32_t mbuf_num); - - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - void dpdk_skip_nic_init(void); -diff --git a/src/lstack/include/lstack_dummy_api.h b/src/lstack/include/lstack_dummy_api.h -deleted file mode 100644 -index 48bce31..0000000 ---- a/src/lstack/include/lstack_dummy_api.h -+++ /dev/null -@@ -1,23 +0,0 @@ --/* --* 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 _LSTACK_DUMMY_API_H_ --#define _LSTACK_DUMMY_API_H_ -- --int dummy_socket(int domain, int type, int protocol); --ssize_t dummy_write(int s, const void *mem, size_t size); --ssize_t dummy_writev(int s, const struct iovec *iov, int iovcnt); --ssize_t dummy_sendmsg(int s, const struct msghdr *message, int flags); --ssize_t dummy_send(int sockfd, const void *buf, size_t len, int flags); --ssize_t dummy_sendto(int sockfd, const void *buf, size_t len, int flags, -- const struct sockaddr *addr, socklen_t addrlen); --#endif /* __LSTACK_DUMMY_API_H_ */ -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -deleted file mode 100644 -index 4cc9db1..0000000 ---- a/src/lstack/include/lstack_lwip.h -+++ /dev/null -@@ -1,62 +0,0 @@ --/* --* 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_LWIP_H__ --#define __GAZELLE_LWIP_H__ --#include -- --#include "common/gazelle_dfx_msg.h" --#include "common/dpdk_common.h" --#include "same_node.h" -- --struct lwip_sock; --struct rpc_msg; --struct protocol_stack; -- --#define NETCONN_IS_DATAOUT(sock) (gazelle_ring_readover_count((sock)->send_ring) || (sock)->send_pre_del) --#define NETCONN_IS_UDP(sock) (NETCONNTYPE_GROUP(netconn_type((sock)->conn)) == NETCONN_UDP) -- --/* lwip api */ --struct pbuf *do_lwip_tcp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size); --struct pbuf *do_lwip_udp_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size); --void do_lwip_get_from_sendring_over(struct lwip_sock *sock); --ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, uint8_t apiflags); -- --/* lwip api */ --void do_lwip_free_pbuf(struct pbuf *pbuf); --struct pbuf *do_lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type type); -- --/* lwip api */ --void do_lwip_add_recvlist(int32_t fd); --/* stack api */ --void do_lwip_read_recvlist(struct protocol_stack *stack, uint32_t max_num); -- -- --/* app api */ --ssize_t do_lwip_sendmsg_to_stack(struct lwip_sock *sock, int32_t s, -- const struct msghdr *message, int32_t flags); --ssize_t do_lwip_recvmsg_from_stack(int32_t s, const struct msghdr *message, int32_t flags); -- --ssize_t do_lwip_send_to_stack(int32_t fd, const void *buf, size_t len, int32_t flags, -- const struct sockaddr *addr, socklen_t addrlen); --ssize_t do_lwip_read_from_stack(int32_t fd, void *buf, size_t len, int32_t flags, -- struct sockaddr *addr, socklen_t *addrlen); -- --/* stack api */ --bool do_lwip_replenish_sendring(struct protocol_stack *stack, struct lwip_sock *sock); -- --void do_lwip_clone_sockopt(struct lwip_sock *dst_sock, struct lwip_sock *src_sock); -- --uint32_t do_lwip_get_conntable(struct gazelle_stat_lstack_conn_info *conn, uint32_t max_num); --uint32_t do_lwip_get_connnum(void); -- --#endif -diff --git a/src/lstack/include/lstack_mempool.h b/src/lstack/include/lstack_mempool.h -index c6adff0..a602610 100644 ---- a/src/lstack/include/lstack_mempool.h -+++ b/src/lstack/include/lstack_mempool.h -@@ -284,7 +284,7 @@ struct mem_thread { - } __rte_cache_aligned; - - void mem_stack_pool_free(int stack_id); --int mem_stack_pool_init(int stack_id); -+int mem_stack_pool_init(int stack_id, unsigned numa_id); - int mem_stack_mpcache_init(int stack_id, unsigned cpu_id); - - int mem_thread_manager_init(void); -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index b77d5da..8653fb0 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -29,12 +29,6 @@ - #include "lstack_ethdev.h" - #include "lstack_tx_cache.h" - --#define SOCK_RECV_RING_SIZE (get_global_cfg_params()->recv_ring_size) --#define SOCK_RECV_RING_SIZE_MAX (2048) --#define SOCK_SEND_RING_SIZE_MAX (2048) -- --#define MBUFPOOL_RESERVE_NUM (2 * get_global_cfg_params()->rxqueue_size + 1024) -- - struct protocol_stack { - uint32_t tid; - uint16_t queue_id; -@@ -52,7 +46,6 @@ struct protocol_stack { - volatile bool low_power; - volatile uint16_t conn_num; - -- struct rte_mempool *rxtx_mbuf_pool; - struct rte_ring *rx_ring; - struct rte_ring *tx_ring; - struct rte_ring *reg_ring; -@@ -68,9 +61,6 @@ struct protocol_stack { - rpc_queue rpc_queue; - char pad2 __rte_cache_aligned; - -- struct list_node recv_list; -- struct list_node same_node_recv_list; /* used for same node processes communication */ -- - struct stats_ *lwip_stats; - struct gazelle_stack_latency latency; - struct gazelle_stack_stat stats; -@@ -88,7 +78,6 @@ struct protocol_stack_group { - struct protocol_stack *stacks[PROTOCOL_STACK_MAX]; - - sem_t sem_listen_thread; -- struct rte_mempool *total_rxtx_pktmbuf_pool[PROTOCOL_STACK_MAX]; - sem_t sem_stack_setup; - bool stack_setup_fail; - -diff --git a/src/lstack/include/lstack_rtc_api.h b/src/lstack/include/lstack_rtc_api.h -deleted file mode 100644 -index b4b7e1c..0000000 ---- a/src/lstack/include/lstack_rtc_api.h -+++ /dev/null -@@ -1,25 +0,0 @@ --/* --* 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 _LSTACK_RTC_API_H_ --#define _LSTACK_RTC_API_H_ -- --#include -- --/* don't include lwip/sockets.h, conflict with sys/socket.h */ --extern int lwip_fcntl(int s, int cmd, int val); --extern int lwip_ioctl(int s, long cmd, void *argp); -- --void dummy_api_init(posix_api_t *api); --void rtc_api_init(posix_api_t *api); -- --#endif /* __LSTACK_RTC_API_H_ */ -diff --git a/src/lstack/include/lstack_rtw_api.h b/src/lstack/include/lstack_sock_dummy.h -similarity index 77% -rename from src/lstack/include/lstack_rtw_api.h -rename to src/lstack/include/lstack_sock_dummy.h -index 437901a..99491d1 100644 ---- a/src/lstack/include/lstack_rtw_api.h -+++ b/src/lstack/include/lstack_sock_dummy.h -@@ -10,11 +10,9 @@ - * See the Mulan PSL v2 for more details. - */ - --#ifndef _LSTACK_RTW_API_H_ --#define _LSTACK_RTW_API_H_ -+#ifndef _LSTACK_SOCK_DUMMY_H_ -+#define _LSTACK_SOCK_DUMMY_H_ - --#include -+void sock_dummy_api_init(posix_api_t *api); - --void rtw_api_init(posix_api_t *api); -- --#endif /* _LSTACK_RTW_API_H_ */ -+#endif /* _LSTACK_SOCK_DUMMY_H_ */ -diff --git a/src/lstack/include/lstack_stack_stat.h b/src/lstack/include/lstack_stack_stat.h -index ef33365..e6e6abd 100644 ---- a/src/lstack/include/lstack_stack_stat.h -+++ b/src/lstack/include/lstack_stack_stat.h -@@ -13,30 +13,26 @@ - #ifndef GAZELLE_STACK_STAT_H - #define GAZELLE_STACK_STAT_H - -+#include -+#include -+ - struct gazelle_stack_latency; --struct pbuf; - struct rpc_msg; - struct gazelle_stat_low_power_info; --struct wakeup_poll; --struct protocol_stack; - enum GAZELLE_LATENCY_TYPE; - enum GAZELLE_STAT_MODE; - struct gazelle_stat_msg_request; --struct lwip_sock; - --void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, -+void calculate_lstack_latency(int stack_id, struct pbuf *const *pbuf, uint32_t num, - enum GAZELLE_LATENCY_TYPE type, uint64_t time_record); --void calculate_sock_latency(struct gazelle_stack_latency *stack_latency, struct lwip_sock *sock, -- enum GAZELLE_LATENCY_TYPE type); -+void calculate_sock_latency(struct lwip_sock *sock, enum GAZELLE_LATENCY_TYPE type); - void stack_stat_init(void); - int handle_stack_cmd(int fd, struct gazelle_stat_msg_request *msg); - int handle_dpdk_cmd(int fd, enum GAZELLE_STAT_MODE stat_mode); - void lstack_get_low_power_info(struct gazelle_stat_low_power_info *low_power_info); --void unregister_wakeup(struct protocol_stack *stack, struct wakeup_poll *wakeup); - void lstack_calculate_aggregate(int type, uint32_t len); --void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new); -+void time_stamp_into_write(struct pbuf *pbufs[], uint32_t num); - void time_stamp_into_rpcmsg(struct lwip_sock *sock); --void time_stamp_into_recvmbox(struct lwip_sock *sock); - void time_stamp_record(int fd, struct pbuf *pbuf); - - #endif /* GAZELLE_STACK_STAT_H */ -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 427a519..32dde53 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -26,8 +26,6 @@ - #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; -@@ -38,6 +36,7 @@ struct rpc_stats { - uint16_t call_null; - uint64_t call_alloc_fail; - }; -+struct rpc_stats *rpc_stats_get(void); - - union rpc_msg_arg { - int i; -@@ -52,62 +51,34 @@ union rpc_msg_arg { - struct rpc_msg; - typedef void (*rpc_func_t)(struct rpc_msg *msg); - struct rpc_msg { -- int8_t sync_flag : 1; -- int8_t recall_flag : 1; -+#define RPC_MSG_SYNC 0x01 -+#define RPC_MSG_FREE 0x02 -+#define RPC_MSG_EXIT 0x04 -+#define RPC_MSG_RECALL 0x08 -+#define RPC_MSG_REUSE 0x10 -+ int flags; -+ int stack_id; /* the stack to which buf belongs */ - - long result; /* func return val */ - rpc_func_t func; /* msg handle func hook */ - union rpc_msg_arg args[RPM_MSG_ARG_SIZE]; /* resolve by type */ - -- struct rpc_msg_pool { -- struct rte_mempool *mempool; -- } *rpcpool; -- - pthread_spinlock_t lock; /* msg handler unlock notice sender msg process done */ - lockless_queue_node queue_node; - }; - --static inline void rpc_queue_init(rpc_queue *queue, uint16_t queue_id) --{ -- lockless_queue_init(&queue->queue); -- queue->queue_id = queue_id; --} --struct rpc_stats *rpc_stats_get(void); -+struct rpc_msg *rpc_msg_alloc(int stack_id, rpc_func_t func); -+void rpc_msg_free(struct rpc_msg *msg); -+ -+void rpc_queue_init(rpc_queue *queue, uint16_t queue_id); - int rpc_msgcnt(rpc_queue *queue); - int rpc_poll_msg(rpc_queue *queue, int max_num); - --int rpc_call_stack_exit(rpc_queue *queue); -- --/* #include will conflict with lwip/sockets.h */ --struct sockaddr; -- --int rpc_call_close(rpc_queue *queue, int fd); --int rpc_call_shutdown(rpc_queue *queue, int fd, int how); --int rpc_call_socket(rpc_queue *queue, int domain, int type, int protocol); --int rpc_call_bind(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen); --int rpc_call_listen(rpc_queue *queue, int s, int backlog); --int rpc_call_shadow_fd(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen); --int rpc_call_accept(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen, int flags); --int rpc_call_connect(rpc_queue *queue, int fd, const struct sockaddr *addr, socklen_t addrlen); -- --int rpc_call_getpeername(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen); --int rpc_call_getsockname(rpc_queue *queue, int fd, struct sockaddr *addr, socklen_t *addrlen); --int rpc_call_getsockopt(rpc_queue *queue, int fd, int level, int optname, void *optval, socklen_t *optlen); --int rpc_call_setsockopt(rpc_queue *queue, int fd, int level, int optname, const void *optval, socklen_t optlen); -- --int rpc_call_tcp_send(rpc_queue *queue, int fd, size_t len, int flags); --int rpc_call_udp_send(rpc_queue *queue, int fd, size_t len, int flags); -- --int rpc_call_replenish(rpc_queue *queue, void *sock); --int rpc_call_recvlistcnt(rpc_queue *queue); -- --int rpc_call_arp(rpc_queue *queue, void *mbuf); -- --int rpc_call_conntable(rpc_queue *queue, void *conn_table, unsigned max_conn); --int rpc_call_connnum(rpc_queue *queue); --int rpc_call_mbufpoolsize(rpc_queue *queue); -+int rpc_sync_call(rpc_queue *queue, struct rpc_msg *msg); -+void rpc_async_call(rpc_queue *queue, struct rpc_msg *msg, int flags); - --int rpc_call_thread_regphase1(rpc_queue *queue, void *conn); --int rpc_call_thread_regphase2(rpc_queue *queue, void *conn); -+int rpc_call_conntable(int stack_id, void *conn_table, unsigned max_conn); -+int rpc_call_connnum(int stack_id); -+int rpc_call_arp(int stack_id, void *mbuf); - - #endif -diff --git a/src/lstack/include/mbox_ring.h b/src/lstack/include/mbox_ring.h -index c48a47b..7ffdcf4 100644 ---- a/src/lstack/include/mbox_ring.h -+++ b/src/lstack/include/mbox_ring.h -@@ -285,7 +285,7 @@ int mt_ring_create(struct mbox_ring *mr, const char *name, unsigned count) - mr->ops = &g_mbox_rtw_default_ops; - mr->st_obj = NULL; - } -- if ((mr->flags & MBOX_FLAG_RECV) && !dpdk_nic_is_xdp()) { -+ if ((mr->flags & MBOX_FLAG_RECV) && !xdp_eth_enabled()) { - mr->flags |= MBOX_FLAG_PEEK; - mr->ops = &g_mbox_rtw_peek_ops; - mr->ops->create(mr, name, count); -diff --git a/src/lstack/include/same_node.h b/src/lstack/include/same_node.h -index 90a5b76..a7ae64d 100644 ---- a/src/lstack/include/same_node.h -+++ b/src/lstack/include/same_node.h -@@ -19,7 +19,6 @@ - - unsigned same_node_ring_count(const struct lwip_sock *sock); - --void read_same_node_recv_list(struct protocol_stack *stack); - ssize_t gazelle_same_node_ring_recv(struct lwip_sock *sock, const void *buf, size_t len, int32_t flags); - ssize_t gazelle_same_node_ring_send(struct lwip_sock *sock, const void *buf, size_t len, int32_t flags); - -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index a370714..f2ec977 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -31,16 +31,13 @@ - #include "lstack_stack_stat.h" - #include "lstack_log.h" - #include "lstack_dpdk.h" --#include "lstack_lwip.h" - #include "lstack_protocol_stack.h" - #include "lstack_thread_rpc.h" - #include "lstack_flow.h" - #include "lstack_tx_cache.h" - #include "lstack_virtio.h" - #include "lstack_ethdev.h" -- --/* FRAME_MTU + 14byte header */ --#define MBUF_MAX_LEN 1514 -+#include "lstack_mempool.h" - - /* any protocol stack thread receives arp packet and sync it to other threads, - * so that it can have the arp table */ -@@ -62,23 +59,23 @@ static void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cu - continue; - } - -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -- if (ret != 0) { -+ ret = mem_get_mbuf_bulk(stack->stack_idx, &mbuf_copy, 1, true); -+ if (ret == 0) { - stack->stats.rx_allocmbuf_fail++; - return; - } - copy_mbuf(mbuf_copy, mbuf); - -- ret = rpc_call_arp(&stack->rpc_queue, mbuf_copy); -+ ret = rpc_call_arp(stack->stack_idx, mbuf_copy); - if (ret != 0) { -- rte_pktmbuf_free(mbuf_copy); -+ mem_put_mbuf_bulk(&mbuf_copy, 1); - return; - } - } - #if RTE_VERSION < RTE_VERSION_NUM(23, 11, 0, 0) - if (get_global_cfg_params()->kni_switch) { -- ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -- if (ret != 0) { -+ ret = mem_get_mbuf_bulk(cur_stack->stack_idx, &mbuf_copy, 1, true); -+ if (ret == 0) { - cur_stack->stats.rx_allocmbuf_fail++; - return; - } -@@ -87,8 +84,8 @@ static void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cu - } - #endif - if (get_global_cfg_params()->flow_bifurcation) { -- ret = dpdk_alloc_pktmbuf(cur_stack->rxtx_mbuf_pool, &mbuf_copy, 1, true); -- if (ret != 0) { -+ ret = mem_get_mbuf_bulk(cur_stack->stack_idx, &mbuf_copy, 1, true); -+ if (ret == 0) { - cur_stack->stats.rx_allocmbuf_fail++; - return; - } -@@ -100,12 +97,10 @@ static void stack_broadcast_arp(struct rte_mbuf *mbuf, struct protocol_stack *cu - - void eth_dev_recv(struct rte_mbuf *mbuf, struct protocol_stack *stack) - { -- int32_t ret; -- void *payload = NULL; -+ int ret; - struct pbuf *next = NULL; - struct pbuf *prev = NULL; - struct pbuf *head = NULL; -- struct pbuf_custom *pc = NULL; - struct rte_mbuf *m = mbuf; - uint16_t len, pkt_len; - struct rte_mbuf *next_m = NULL; -@@ -114,14 +109,9 @@ void eth_dev_recv(struct rte_mbuf *mbuf, struct protocol_stack *stack) - - while (m != NULL) { - len = (uint16_t)rte_pktmbuf_data_len(m); -- payload = rte_pktmbuf_mtod(m, void *); -- pc = mbuf_to_pbuf(m); -- next = pbuf_alloced_custom(PBUF_RAW, (uint16_t)len, PBUF_RAM, pc, payload, (uint16_t)len); -- if (next == NULL) { -- stack->stats.rx_allocmbuf_fail++; -- break; -- } -- next->tot_len = pkt_len; -+ next = mbuf_to_pbuf(m); -+ mem_init_pbuf(next, PBUF_RAW, pkt_len, len, PBUF_POOL); -+ - pkt_len -= len; - - if (head == NULL) { -@@ -135,6 +125,8 @@ void eth_dev_recv(struct rte_mbuf *mbuf, struct protocol_stack *stack) - next_m = m->next; - m->next = NULL; - m = next_m; -+ -+ mem_preput_pbuf(next); - } - - if (head != NULL) { -@@ -291,15 +283,16 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - struct protocol_stack *stack = get_protocol_stack(); - struct rte_mbuf *pre_mbuf = NULL; - struct rte_mbuf *first_mbuf = NULL; -+ struct rte_mbuf *mbuf; - void *buf_addr; - - while (likely(pbuf != NULL)) { -- struct rte_mbuf *mbuf = pbuf_to_mbuf(pbuf); -- -+ mbuf = pbuf_to_mbuf(pbuf); -+ // rte_mbuf_refcnt_set(mbuf, pbuf->ref + 1); -+ rte_mbuf_refcnt_update(mbuf, 1); - mbuf->data_len = pbuf->len; - mbuf->pkt_len = pbuf->tot_len; - mbuf->next = NULL; -- buf_addr = rte_pktmbuf_mtod(mbuf, void *); - - /* - * |rte_mbuf | mbuf_private | data_off | data | -@@ -307,6 +300,7 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - * buf_addr payload - * m->buf_addr pointer pbuf->payload - */ -+ buf_addr = rte_pktmbuf_mtod(mbuf, void *); - mbuf->data_off += (uint8_t *)pbuf->payload - (uint8_t *)buf_addr; - - if (first_mbuf == NULL) { -@@ -316,26 +310,19 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) - first_mbuf->nb_segs++; - pre_mbuf->next = mbuf; - } -- -- if (likely(first_mbuf->pkt_len > MBUF_MAX_LEN)) { -- mbuf->ol_flags |= RTE_MBUF_F_TX_TCP_SEG; -- mbuf->tso_segsz = MBUF_MAX_DATA_LEN; -- } -- - pre_mbuf = mbuf; -- rte_mbuf_refcnt_update(mbuf, 1); - -- if (get_protocol_stack_group()->latency_start) { -- calculate_lstack_latency(&stack->latency, pbuf, GAZELLE_LATENCY_WRITE_LSTACK, 0); -- } -+ if (get_protocol_stack_group()->latency_start) -+ calculate_lstack_latency(stack->stack_idx, &pbuf, 1, GAZELLE_LATENCY_WRITE_LSTACK, 0); -+ - pbuf = pbuf->next; - } - - uint32_t sent_pkts = stack->dev_ops.tx_xmit(stack, &first_mbuf, 1); - stack->stats.tx += sent_pkts; - if (sent_pkts < 1) { -+ mem_put_mbuf_bulk(&first_mbuf, 1); - stack->stats.tx_drop++; -- rte_pktmbuf_free(first_mbuf); - return ERR_MEM; - } - -@@ -349,7 +336,7 @@ static err_t eth_dev_init(struct netif *netif) - netif->name[0] = 'e'; - netif->name[1] = 't'; - netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP | NETIF_FLAG_MLD6; -- netif->mtu = FRAME_MTU; -+ netif->mtu = GAZELLE_IP_MTU; - netif->output = etharp_output; - netif->linkoutput = eth_dev_output; - netif->output_ip6 = ethip6_output; -@@ -368,18 +355,11 @@ static err_t eth_dev_init(struct netif *netif) - RTE_ETH_RX_OFFLOAD_UDP_CKSUM | - RTE_ETH_RX_OFFLOAD_IPV4_CKSUM); - netif_set_txol_flags(netif, RTE_ETH_TX_OFFLOAD_TCP_CKSUM | RTE_ETH_TX_OFFLOAD_TCP_TSO); -- /* 16: see kernel MAX_SKB_FRAGS define in skbuff.h */ -- netif_set_max_pbuf_frags(netif, 16); -+ netif_set_max_pbuf_frags(netif, OFFLOAD_TX_TSO_4K_FRAGS); - } else { - netif_set_rxol_flags(netif, get_protocol_stack_group()->rx_offload); - netif_set_txol_flags(netif, get_protocol_stack_group()->tx_offload); -- /* 40: dpdk pmd support 40 max segs */ -- netif_set_max_pbuf_frags(netif, 40); -- } -- netif_set_min_tso_seglen(netif, 256); -- -- if (get_global_cfg_params()->stack_mode_rtc) { -- netif_set_rtc_mode(netif); -+ netif_set_max_pbuf_frags(netif, OFFLOAD_TX_TSO_MTU_FRAGS); - } - - return ERR_OK; -@@ -400,7 +380,7 @@ int32_t ethdev_init(struct protocol_stack *stack) - - if (use_ltran()) { - stack->rx_ring_used = 0; -- int32_t ret = fill_mbuf_to_ring(stack->rxtx_mbuf_pool, stack->rx_ring, RING_SIZE(VDEV_RX_QUEUE_SZ)); -+ int32_t ret = fill_mbuf_to_ring(stack->stack_idx, stack->rx_ring, RING_SIZE(VDEV_RX_QUEUE_SZ)); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "fill mbuf to rx_ring failed ret=%d\n", ret); - return ret; -diff --git a/src/lstack/netif/lstack_fault_inject.c b/src/lstack/netif/lstack_fault_inject.c -index 9fae745..59eb8bd 100644 ---- a/src/lstack/netif/lstack_fault_inject.c -+++ b/src/lstack/netif/lstack_fault_inject.c -@@ -161,10 +161,8 @@ static int32_t inject_packet_loss_random(struct protocol_stack *stack, struct rt - if (rand_num > boundary) { - return nr_pkts; - } -- -- for (int32_t i = 0; i < nr_pkts; ++i) { -- rte_pktmbuf_free(pkts[i]); -- } -+ -+ mem_put_mbuf_bulk(pkts, nr_pkts); - return nr_pkts; - } - -@@ -184,7 +182,7 @@ static int32_t inject_packet_duplicate_random(struct protocol_stack *stack, stru - return nr_pkts; - } - -- struct rte_mempool *mp = stack->rxtx_mbuf_pool; -+ struct rte_mempool *mp = mem_get_mbuf_pool(stack->stack_idx); - struct rte_mbuf *mbuf_clone = NULL; - int32_t ret = 0; - -@@ -192,14 +190,14 @@ static int32_t inject_packet_duplicate_random(struct protocol_stack *stack, stru - int32_t count = count_max; - while (count--) { - mbuf_clone = rte_pktmbuf_clone(pkts[i], mp); -- rte_pktmbuf_free(pkts[i]); -+ mem_put_mbuf_bulk(&pkts[i], 1); - if (mbuf_clone == NULL) { - LSTACK_LOG(ERR, LSTACK, "fault inject mbuf_clone fail.\n"); - return 0; - } - ret = vdev_tx_xmit(stack, &mbuf_clone, 1); - if (ret < 1) { -- rte_pktmbuf_free(mbuf_clone); -+ mem_put_mbuf_bulk(&mbuf_clone, 1); - return ret; - } - } -@@ -215,7 +213,7 @@ static int32_t send_reorder_array(struct protocol_stack *stack) - for (int32_t i = 0; i < g_reorder[idx].cur_cnt; ++i) { - ret = vdev_tx_xmit(stack, g_reorder[idx].array + i, 1); - if (ret < 1) { -- rte_pktmbuf_free(*(g_reorder[idx].array + i)); -+ mem_put_mbuf_bulk(g_reorder[idx].array + i, 1); - } - } - g_reorder[idx].cur_cnt = 0; -@@ -239,7 +237,7 @@ static int32_t inject_packet_reorder_random(struct protocol_stack *stack, struct - return nr_pkts; - } - -- struct rte_mempool *mp = stack->rxtx_mbuf_pool; -+ struct rte_mempool *mp = mem_get_mbuf_pool(stack->stack_idx); - struct rte_mbuf *mbuf_clone = NULL; - int32_t idx = stack->stack_idx; - for (int32_t i = 0; i < nr_pkts; ++i) { -@@ -251,8 +249,8 @@ static int32_t inject_packet_reorder_random(struct protocol_stack *stack, struct - } - *(g_reorder[idx].array + g_reorder[idx].cur_cnt++) = mbuf_clone; - /* func rte_pktmbuf_clone will add refcnt of mbuf, so following operation will free mbuf double */ -- rte_pktmbuf_free(pkts[i]); -- rte_pktmbuf_free(pkts[i]); -+ mem_put_mbuf_bulk(&pkts[i], 1); -+ mem_put_mbuf_bulk(&pkts[i], 1); - } else { - send_reorder_array(stack); - } -diff --git a/src/lstack/netif/lstack_flow.c b/src/lstack/netif/lstack_flow.c -index ec09e45..7f2d9bd 100644 ---- a/src/lstack/netif/lstack_flow.c -+++ b/src/lstack/netif/lstack_flow.c -@@ -29,6 +29,7 @@ - #include "lstack_cfg.h" - #include "lstack_protocol_stack.h" - #include "lstack_flow.h" -+#include "lstack_mempool.h" - - #define MAX_PATTERN_NUM 4 - #define MAX_ACTION_NUM 2 -@@ -435,7 +436,7 @@ static void transfer_tcp_to_thread(struct rte_mbuf *mbuf, uint16_t stk_idx) - struct protocol_stack *stack = get_protocol_stack_group()->stacks[stk_idx]; - int ret = -1; - while (ret != 0) { -- ret = rpc_call_arp(&stack->rpc_queue, mbuf); -+ ret = rpc_call_arp(stack->stack_idx, mbuf); - printf("transfer_tcp_to_thread, ret : %d \n", ret); - } - } -@@ -449,17 +450,15 @@ static void parse_arp_and_transefer(char* buf) - int32_t ret; - for (int32_t i = 0; i < stack_group->stack_num; i++) { - stack = stack_group->stacks[i]; -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, false); -- while (ret != 0) { -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, false); -+ while (mem_get_mbuf_bulk(stack->stack_idx, &mbuf_copy, 1, false) == 0) { - stack->stats.rx_allocmbuf_fail++; - } - copy_mbuf(mbuf_copy, mbuf); - -- ret = rpc_call_arp(&stack->rpc_queue, mbuf_copy); -+ ret = rpc_call_arp(stack->stack_idx, mbuf_copy); - - while (ret != 0) { -- rpc_call_arp(&stack->rpc_queue, mbuf_copy); -+ rpc_call_arp(stack->stack_idx, mbuf_copy); - } - } - } -@@ -478,9 +477,7 @@ static void parse_tcp_and_transefer(char* buf) - struct rte_mbuf *mbuf_copy = NULL; - struct protocol_stack *stack = stack_group->stacks[stk_index]; - -- int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, false); -- while (ret != 0) { -- ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, &mbuf_copy, 1, false); -+ while (mem_get_mbuf_bulk(stack->stack_idx, &mbuf_copy, 1, false) == 0) { - stack->stats.rx_allocmbuf_fail++; - } - -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 14d8cc6..425f8dd 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -32,12 +32,11 @@ - #include "common/dpdk_common.h" - #include "lstack_protocol_stack.h" - #include "common/gazelle_reg_msg.h" --#include "lstack_lwip.h" - #include "lstack_flow.h" - #include "lstack_vdev.h" - #include "lstack_port_map.h" - #include "lstack_virtio.h" -- -+#include "lstack_mempool.h" - #include "lstack_interrupt.h" - - /* INUSE_TX_PKTS_WATERMARK < VDEV_RX_QUEUE_SZ; -@@ -64,8 +63,8 @@ static uint32_t ltran_rx_poll(struct protocol_stack *stack, struct rte_mbuf **pk - stack->rx_ring_used += rcvd_pkts; - if (unlikely(stack->rx_ring_used >= USED_RX_PKTS_WATERMARK)) { - uint32_t free_cnt = LWIP_MIN(stack->rx_ring_used, RING_SIZE(VDEV_RX_QUEUE_SZ)); -- int32_t ret = dpdk_alloc_pktmbuf(stack->rxtx_mbuf_pool, (struct rte_mbuf **)free_buf, free_cnt, true); -- if (likely(ret == 0)) { -+ int ret = mem_get_mbuf_bulk(stack->stack_idx, (struct rte_mbuf **)free_buf, free_cnt, true); -+ if (likely(ret > 0)) { - nr_pkts = gazelle_ring_sp_enqueue(stack->rx_ring, (void **)free_buf, free_cnt); - stack->rx_ring_used -= nr_pkts; - } else { -@@ -167,9 +166,7 @@ static uint32_t ltran_tx_xmit(struct protocol_stack *stack, struct rte_mbuf **pk - do { - if (unlikely(stack->tx_ring_used >= INUSE_TX_PKTS_WATERMARK)) { - uint32_t free_pkts = gazelle_ring_sc_dequeue(stack->tx_ring, (void **)free_buf, stack->tx_ring_used); -- for (uint32_t i = 0; i < free_pkts; i++) { -- rte_pktmbuf_free(free_buf[i]); -- } -+ mem_put_mbuf_bulk(free_buf, free_pkts); - stack->tx_ring_used -= free_pkts; - } - -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index f6d1148..1722460 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -740,7 +740,6 @@ static void show_lstack_stats(struct gazelle_stack_dfx_data *lstack_stat) - printf("app_write: %-18"PRIu64" ", lstack_stat->data.pkts.wakeup_stat.app_write_cnt); - printf("write_lwip: %-17"PRIu64" ", lstack_stat->data.pkts.stack_stat.write_lwip_cnt); - printf("app_write_rpc: %-14"PRIu64" \n", lstack_stat->data.pkts.wakeup_stat.app_write_rpc); -- printf("recv_list: %-18"PRIu64" ", lstack_stat->data.pkts.recv_list_cnt); - printf("conn_num: %-19hu ", lstack_stat->data.pkts.conn_num); - - printf("kernel_events: %-14"PRIu64"\n", lstack_stat->data.pkts.wakeup_stat.kernel_events); -@@ -902,11 +901,10 @@ static void gazelle_print_lstack_stat_latency(void *buf, const struct gazelle_st - printf("Recv:\n"); - - printf("range: t0--->t1\n%s", res[GAZELLE_LATENCY_INTO_MBOX].latency_stat_result); -- printf("range: t1--->t2\n%s", res[GAZELLE_LATENCY_READ_LWIP].latency_stat_result); -- printf("range: t2--->t3\n%s", res[GAZELLE_LATENCY_READ_APP_CALL].latency_stat_result); -- printf("range: t3--->t4\n%s", res[GAZELLE_LATENCY_READ_LSTACK].latency_stat_result); -- printf("range: t0--->t4\n%s", res[GAZELLE_LATENCY_READ_MAX].latency_stat_result); -- printf("t0: read from nic t1: into recvmbox t2: into recvring t3: app read start t4: app read end\n"); -+ printf("range: t1--->t2\n%s", res[GAZELLE_LATENCY_READ_APP_CALL].latency_stat_result); -+ printf("range: t2--->t3\n%s", res[GAZELLE_LATENCY_READ_LSTACK].latency_stat_result); -+ printf("range: t0--->t3\n%s", res[GAZELLE_LATENCY_READ_MAX].latency_stat_result); -+ printf("t0: read from nic t1: into recvmbox t2: app read start t3: app read end\n"); - - printf("Send:\n"); - printf("range: t0--->t1\n%s", res[GAZELLE_LATENCY_WRITE_INTO_RING].latency_stat_result); -@@ -1271,7 +1269,7 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - printf("Active Internet connections (servers and established)\n"); - do { - printf("\n------ stack tid: %6u ------time=%s\n", stat->tid, sys_local_time_str); -- printf("No. Proto lwip_recv recv_ring in_send send_ring cwn rcv_wnd snd_wnd snd_buf snd_nxt" -+ printf("No. Proto recvmbox recvtail sendmbox sendtail in_send cwn rcv_wnd snd_wnd snd_buf snd_nxt" - " lastack rcv_nxt events epoll_ev evlist fd Local Address" - " Foreign Address State" - " keep-alive keep-alive(idle,intvl,cnt) pingpong\n"); -@@ -1292,10 +1290,12 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - - sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port); - sprintf_s(str_raddr, sizeof(str_raddr), "%s:%hu", str_rip, conn_info->r_port); -- printf("%-6utcp %-10u%-10u%-8u%-10u%-9d%-9d%-10d%-10d%-15u%-15u%-15u%-10x%-10x%-7d%-7d" -- "%-52s %-52s %s %-5d %s %d\n", -- i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send, -- conn_info->send_ring_cnt, conn_info->cwn, conn_info->rcv_wnd, conn_info->snd_wnd, -+ printf("%-6utcp %-9u%-9u%-9u%-9u%-8u%-9d%-9d%-10d%-10d%-15u%-15u%-15u%-10x%-10x%-7d%-7d" -+ "%-52s %-52s %s %-5d %s %d\n", i, -+ conn_info->recvmbox_cnt, conn_info->recvmbox_tail, -+ conn_info->sendmbox_cnt, conn_info->sendmbox_tail, -+ conn_info->in_send, -+ conn_info->cwn, conn_info->rcv_wnd, conn_info->snd_wnd, - conn_info->snd_buf, conn_info->snd_nxt, conn_info->lastack, conn_info->rcv_nxt, conn_info->events, - conn_info->epoll_events, conn_info->eventlist, conn_info->fd, - str_laddr, str_raddr, tcp_state_to_str(conn_info->tcp_sub_state), -@@ -1304,14 +1304,14 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_ - inet_ntop(domain, lip, str_ip, sizeof(str_ip)); - sprintf_s(str_laddr, sizeof(str_laddr), "%s:%hu", str_ip, conn_info->l_port); - sprintf_s(str_raddr, sizeof(str_raddr), "%s:*", domain == AF_INET ? "0.0.0.0" : "::0"); -- printf("%-6utcp %-147u%-7d%-52s %-52s LISTEN\n", i, conn_info->recv_cnt, -+ printf("%-6utcp %-147u%-7d%-52s %-52s LISTEN\n", i, conn_info->recvmbox_cnt, - conn_info->fd, str_laddr, str_raddr); - } else { - printf("Got unknow tcp conn::%s:%5hu, state:%u\n", - inet_ntop(domain, lip, str_ip, sizeof(str_ip)), conn_info->l_port, conn_info->state); - } -- unread_pkts += conn_info->recv_ring_cnt + conn_info->recv_cnt; -- unsend_pkts += conn_info->send_ring_cnt + conn_info->in_send; -+ unread_pkts += conn_info->recvmbox_cnt; -+ unsend_pkts += conn_info->sendmbox_cnt + conn_info->in_send; - } - if (conn->conn_num > 0) { - printf("Total unread pkts:%u unsend pkts:%u\n", unread_pkts, unsend_pkts); -@@ -1479,12 +1479,6 @@ static void gazelle_print_lstack_aggregate(void *buf, const struct gazelle_stat_ - printf("tx_size_1461_8192 byte: %u\n", stats->size_1461_8192[1]); - printf("tx_size_8193_max byte: %u\n", stats->size_8193_max[1]); - -- printf("app_tx_szie_1_64: %u\n", stats->size_1_64[2]); -- printf("app_tx_size_65_512: %u\n", stats->size_65_512[2]); -- printf("app_tx_size_513_1460 byte: %u\n", stats->size_513_1460[2]); -- printf("app_tx_size_1461_8192 byte: %u\n", stats->size_1461_8192[2]); -- printf("app_tx_size_8193_max byte: %u\n", stats->size_8193_max[2]); -- - if ((dfx->eof != 0) || (ret != GAZELLE_OK)) { - break; - } -diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c -index aef5e46..b62421a 100644 ---- a/src/ltran/ltran_forward.c -+++ b/src/ltran/ltran_forward.c -@@ -292,7 +292,7 @@ static uint32_t get_vlan_offset(const struct rte_mbuf *m) - uint32_t offset = 0; - struct rte_ether_hdr *ethh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); - u16_t type = ethh->ether_type; -- if (type == PP_HTONS(RTE_ETHER_TYPE_VLAN)) { -+ if (type == htons(RTE_ETHER_TYPE_VLAN)) { - offset += sizeof(struct rte_vlan_hdr); - } - return offset; --- -2.33.0 - diff --git a/0330-cfg-add-mem_cache_max-and-change-default-rpc_msg_max.patch b/0330-cfg-add-mem_cache_max-and-change-default-rpc_msg_max.patch deleted file mode 100644 index e399bcd859be4072e4f07565c50fb91e15c62b10..0000000000000000000000000000000000000000 --- a/0330-cfg-add-mem_cache_max-and-change-default-rpc_msg_max.patch +++ /dev/null @@ -1,157 +0,0 @@ -From 9469121fdc2e20ebda9b062bb7876ae8dee921d7 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 24 Mar 2025 17:16:40 +0800 -Subject: [PATCH] cfg: add mem_cache_max and change default rpc_msg_max - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_cfg.c | 14 +++++++++++++- - src/lstack/core/lstack_mempool.c | 8 ++++---- - src/lstack/include/lstack_cfg.h | 7 ++++--- - src/lstack/include/lstack_mempool.h | 2 +- - src/lstack/lstack.conf | 9 --------- - 5 files changed, 22 insertions(+), 18 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 432e4db..78f9198 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -36,6 +36,7 @@ - #include "lstack_log.h" - #include "lstack_dpdk.h" - #include "lstack_cfg.h" -+#include "lstack_mempool.h" - - #define DEFAULT_CONF_FILE "/etc/gazelle/lstack.conf" - #define LSTACK_CONF_ENV "LSTACK_CONF_PATH" -@@ -82,6 +83,7 @@ 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_rpc_msg_max(void); -+static int32_t parse_mem_cache_num(void); - static int32_t parse_send_cache_mode(void); - static int32_t parse_flow_bifurcation(void); - static int32_t parse_stack_interrupt(void); -@@ -120,6 +122,7 @@ static struct config_vector_t g_config_tbl[] = { - { "nic_rxqueue_size", parse_nic_rxqueue_size}, - { "nic_txqueue_size", parse_nic_txqueue_size}, - { "rpc_msg_max", parse_rpc_msg_max }, -+ { "mem_cache_num", parse_mem_cache_num }, - { "app_bind_numa", parse_app_bind_numa }, - { "stack_num", parse_stack_num }, - { "num_cpus", parse_stack_cpu_number }, -@@ -1424,7 +1427,16 @@ static int32_t parse_nic_vlan_mode(void) - static int32_t parse_rpc_msg_max(void) - { - int32_t ret; -- PARSE_ARG(g_config_params.rpc_msg_max, "rpc_msg_max", 4096, 1, 8192, ret); -+ PARSE_ARG(g_config_params.rpc_msg_max, "rpc_msg_max", -+ 4096, GAZELLE_RESERVED_CLIENTS, MEMP_NUM_SYS_MBOX + GAZELLE_RESERVED_CLIENTS, ret); -+ return ret; -+} -+ -+static int32_t parse_mem_cache_num(void) -+{ -+ int32_t ret; -+ PARSE_ARG(g_config_params.mem_cache_num, "mem_cache_num", -+ MEMPOOL_CACHE_NUM, BUF_CACHE_MIN_NUM, BUF_CACHE_MAX_NUM, ret); - return ret; - } - -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index 983f2f0..72c7d67 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -332,7 +332,7 @@ static const struct mempool_ops mbuf_mp_ops = { - }; - - --static struct rte_mempool *mbuf_pool_create(int stack_id, uint16_t numa_id) -+static struct rte_mempool *mbuf_pool_create(int stack_id, unsigned numa_id) - { - struct cfg_params *cfg_params = get_global_cfg_params(); - char name[RTE_MEMPOOL_NAMESIZE]; -@@ -367,7 +367,7 @@ static struct rte_mempool *mbuf_pool_create(int stack_id, uint16_t numa_id) - return pool; - } - --static struct rte_mempool *rpc_pool_create(int stack_id, uint16_t numa_id) -+static struct rte_mempool *rpc_pool_create(int stack_id, unsigned numa_id) - { - char name [RTE_MEMPOOL_NAMESIZE]; - struct rte_mempool *pool; -@@ -478,14 +478,14 @@ int mem_thread_cache_init(struct mem_thread *mt) - char name [RTE_MEMPOOL_NAMESIZE]; - SYS_FORMAT_NAME(name, RTE_MEMPOOL_NAMESIZE, "%s_%p", "migrate_ring", mt); - -- mt->mbuf_migrate_ring = rte_ring_create(name, BUF_CACHE_DEFAULT_NUM, -+ mt->mbuf_migrate_ring = rte_ring_create(name, BUF_CACHE_MAX_NUM, - rte_socket_id(), RING_F_SP_ENQ | RING_F_SC_DEQ); - if (mt->mbuf_migrate_ring == NULL) { - return -1; - } - } - -- mt->mbuf_cache = buf_cache_create(BUF_CACHE_DEFAULT_NUM); -+ mt->mbuf_cache = buf_cache_create(get_global_cfg_params()->mem_cache_num); - if (mt->mbuf_cache == NULL) { - mem_thread_cache_free(mt); - return -1; -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 3e671b5..b4cdd07 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -130,12 +130,13 @@ struct cfg_params { - - uint32_t nic_read_number; - uint32_t rpc_number; -- uint32_t rpc_msg_max; - }; - - struct { // socket -- uint32_t tcp_conn_count; -- uint32_t mbuf_count_per_conn; -+ uint16_t tcp_conn_count; -+ uint16_t mbuf_count_per_conn; -+ uint16_t rpc_msg_max; -+ uint16_t mem_cache_num; - }; - - struct { // deprecated -diff --git a/src/lstack/include/lstack_mempool.h b/src/lstack/include/lstack_mempool.h -index a602610..848509c 100644 ---- a/src/lstack/include/lstack_mempool.h -+++ b/src/lstack/include/lstack_mempool.h -@@ -45,7 +45,7 @@ - #define MEMPOOL_CACHE_NUM 32 - - #define BUF_CACHE_MIN_NUM 32 --#define BUF_CACHE_DEFAULT_NUM 1024 -+#define BUF_CACHE_MAX_NUM 1024 - #define BUF_CACHE_WATERSTEP_SHIFT 4 /* 1/16 */ - - #define BUF_BULK_MAX_NUM 32 -diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf -index 490bdfc..4084ce3 100644 ---- a/src/lstack/lstack.conf -+++ b/src/lstack/lstack.conf -@@ -23,16 +23,7 @@ low_power_mode=0 - tcp_conn_count = 1500 - mbuf_count_per_conn = 170 - --# send ring size, default is 32, max is 2048 --# if udp pktlen exceeds 45952(32 * 1436)B, send_ring_size must be at least 64. --send_ring_size = 32 -- --#recv ring size, default is 128, max is 2048 --recv_ring_size = 128 -- - #protocol stack thread per loop params --#read data form protocol stack into recv_ring --read_connect_number = 4 - #process rpc msg number - rpc_number = 4 - #read nic pkts number --- -2.33.0 - diff --git a/0331-cfg-add-mem_async_mode.patch b/0331-cfg-add-mem_async_mode.patch deleted file mode 100644 index 13a8fc9a3bba09d688ed26b7b840261d57ca1063..0000000000000000000000000000000000000000 --- a/0331-cfg-add-mem_async_mode.patch +++ /dev/null @@ -1,98 +0,0 @@ -From 9da8d8a3e4a37049793db6fac45bb98b60a612a6 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 25 Mar 2025 15:31:55 +0800 -Subject: [PATCH] cfg: add mem_async_mode - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_cfg.c | 11 +++++++++++ - src/lstack/core/lstack_mempool.c | 2 +- - src/lstack/include/lstack_cfg.h | 1 + - src/lstack/include/mbox_ring.h | 10 ++++++---- - 4 files changed, 19 insertions(+), 5 deletions(-) - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 78f9198..ddb419d 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -84,6 +84,7 @@ static int32_t parse_stack_thread_mode(void); - static int32_t parse_nic_vlan_mode(void); - static int32_t parse_rpc_msg_max(void); - static int32_t parse_mem_cache_num(void); -+static int32_t parse_mem_async_mode(void); - static int32_t parse_send_cache_mode(void); - static int32_t parse_flow_bifurcation(void); - static int32_t parse_stack_interrupt(void); -@@ -151,6 +152,7 @@ static struct config_vector_t g_config_tbl[] = { - { "use_sockmap", parse_use_sockmap }, - { "udp_enable", parse_udp_enable }, - { "stack_thread_mode", parse_stack_thread_mode }, -+ { "mem_async_mode", parse_mem_async_mode }, - { "nic_vlan_mode", parse_nic_vlan_mode }, - { "send_cache_mode", parse_send_cache_mode }, - { "flow_bifurcation", parse_flow_bifurcation}, -@@ -1440,6 +1442,15 @@ static int32_t parse_mem_cache_num(void) - return ret; - } - -+static int32_t parse_mem_async_mode(void) -+{ -+ // TODO -+ g_config_params.mem_async_mode = 1; -+ if (g_config_params.stack_mode_rtc || xdp_eth_enabled()) -+ g_config_params.mem_async_mode = 0; -+ return 0; -+} -+ - static int32_t parse_send_cache_mode(void) - { - int32_t ret; -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index 72c7d67..eeae797 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -474,7 +474,7 @@ void mem_thread_cache_free(struct mem_thread *mt) - - int mem_thread_cache_init(struct mem_thread *mt) - { -- if (!get_global_cfg_params()->stack_mode_rtc && !xdp_eth_enabled()) { -+ if (get_global_cfg_params()->mem_async_mode) { - char name [RTE_MEMPOOL_NAMESIZE]; - SYS_FORMAT_NAME(name, RTE_MEMPOOL_NAMESIZE, "%s_%p", "migrate_ring", mt); - -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index b4cdd07..e1639a1 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -137,6 +137,7 @@ struct cfg_params { - uint16_t mbuf_count_per_conn; - uint16_t rpc_msg_max; - uint16_t mem_cache_num; -+ bool mem_async_mode; - }; - - struct { // deprecated -diff --git a/src/lstack/include/mbox_ring.h b/src/lstack/include/mbox_ring.h -index 7ffdcf4..f6acdef 100644 ---- a/src/lstack/include/mbox_ring.h -+++ b/src/lstack/include/mbox_ring.h -@@ -285,10 +285,12 @@ int mt_ring_create(struct mbox_ring *mr, const char *name, unsigned count) - mr->ops = &g_mbox_rtw_default_ops; - mr->st_obj = NULL; - } -- if ((mr->flags & MBOX_FLAG_RECV) && !xdp_eth_enabled()) { -- mr->flags |= MBOX_FLAG_PEEK; -- mr->ops = &g_mbox_rtw_peek_ops; -- mr->ops->create(mr, name, count); -+ if (mr->flags & MBOX_FLAG_RECV) { -+ if (get_global_cfg_params()->mem_async_mode) { -+ mr->flags |= MBOX_FLAG_PEEK; -+ mr->ops = &g_mbox_rtw_peek_ops; -+ mr->ops->create(mr, name, count); -+ } - } - - mr->ring = rte_ring_create_fast(name, count, RING_F_SP_ENQ | RING_F_SC_DEQ); --- -2.33.0 - diff --git a/0332-mempool-add-mem_thread_cache_flush.patch b/0332-mempool-add-mem_thread_cache_flush.patch deleted file mode 100644 index f51c8a7b14f347c3329e7b7821e7c0b76fc41f23..0000000000000000000000000000000000000000 --- a/0332-mempool-add-mem_thread_cache_flush.patch +++ /dev/null @@ -1,617 +0,0 @@ -From 8ff71cad286a1a1952f427ce48a815322569189a Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Thu, 27 Mar 2025 15:20:02 +0800 -Subject: [PATCH] mempool: add mem_thread_cache_flush fix - PBUF_POOL_PREINIT - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_unistd.c | 20 +-- - src/lstack/core/lstack_mempool.c | 259 ++++++++++++++++++++++++---- - src/lstack/include/lstack_mempool.h | 19 +- - src/lstack/include/lstack_unistd.h | 3 + - 4 files changed, 250 insertions(+), 51 deletions(-) - -diff --git a/src/lstack/api/lstack_unistd.c b/src/lstack/api/lstack_unistd.c -index e3b9b1f..431e0a2 100644 ---- a/src/lstack/api/lstack_unistd.c -+++ b/src/lstack/api/lstack_unistd.c -@@ -58,7 +58,7 @@ bool sig_need_dump(int sig) - return true; - } - --static void pthread_block_sig(int sig) -+void pthread_block_sig(int sig) - { - sigset_t mask; - -@@ -67,6 +67,15 @@ static void pthread_block_sig(int sig) - pthread_sigmask(SIG_BLOCK, &mask, NULL); - } - -+void pthread_unblock_sig(int sig) -+{ -+ sigset_t mask; -+ -+ sigemptyset(&mask); -+ sigaddset(&mask, sig); -+ pthread_sigmask(SIG_UNBLOCK, &mask, NULL); -+} -+ - static void lstack_sigaction_default_handler(int sig, siginfo_t *info, void *context) - { - static bool skip_process_exit = false; -@@ -118,15 +127,6 @@ static void lstack_sig_default_handler(int sig) - lstack_sigaction_default_handler(sig, NULL, 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; -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index eeae797..7e2a706 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -21,14 +21,18 @@ - #include "common/dpdk_common.h" - #include "lstack_dpdk.h" - #include "lstack_protocol_stack.h" -+#include "lstack_unistd.h" - --#define MEM_THREAD_MANAGER_TIMEOUT 1 --#define MEM_THREAD_MANAGER_MAX 64 -+#define MEM_THREAD_FLUSH_SIG (SIGRTMIN + 11) -+#define MEM_THREAD_MANAGER_FLUSH_MS 100 -+#define MEM_THREAD_MANAGER_FREE_S 2 -+#define MEM_THREAD_MANAGER_FREE_MAX 64 - - struct mem_thread_manager { - struct list_node mt_work_list; - struct list_node mt_free_list; - rte_spinlock_t list_lock; -+ uint32_t flush_time; - }; - - struct mem_thread_group { -@@ -36,6 +40,9 @@ struct mem_thread_group { - pthread_t thread; - struct list_node mt_node; - struct mem_thread mt_array[PROTOCOL_STACK_MAX]; -+ -+ bool used_flag; -+ uint32_t used_time; - }; - - static struct mem_stack g_mem_stack_group[PROTOCOL_STACK_MAX] = {0}; -@@ -58,11 +65,73 @@ struct rte_mempool *mem_get_rpc_pool(int stack_id) - return g_mem_stack_group[stack_id].rpc_pool; - } - --static void mem_thread_manager_add_work(struct mem_thread_group *mt_group) -+static inline bool mem_thread_group_in_used(const struct mem_thread_group *mt_grooup, uint32_t timeout) - { -- rte_spinlock_lock(&g_mem_thread_manager.list_lock); -- list_add_node(&mt_group->mt_node, &g_mem_thread_manager.mt_work_list); -- rte_spinlock_unlock(&g_mem_thread_manager.list_lock); -+ return mt_grooup->used_flag || -+ (sys_now() - mt_grooup->used_time < timeout); -+} -+ -+static inline void mem_thread_group_used(void) -+{ -+ g_mem_thread_group->used_flag = true; -+ g_mem_thread_group->used_time = sys_now(); -+} -+ -+static inline void mem_thread_group_done(void) -+{ -+ g_mem_thread_group->used_flag = false; -+} -+ -+static void mem_thread_cache_flush(struct mem_thread *mt); -+static unsigned mem_thread_cache_count(const struct mem_thread *mt); -+static void mem_thread_group_action_flush(int signum) -+{ -+ struct mem_thread *mt; -+ int stack_id; -+ -+ if (g_mem_thread_group == NULL) -+ return; -+ if (mem_thread_group_in_used(g_mem_thread_group, MEM_THREAD_MANAGER_FLUSH_MS)) -+ return; -+ -+ for (stack_id = 0; stack_id < PROTOCOL_STACK_MAX; stack_id++) { -+ mt = &g_mem_thread_group->mt_array[stack_id]; -+ mem_thread_cache_flush(mt); -+ } -+} -+ -+static int mem_thread_group_register_flush(void) -+{ -+ sighandler_t handler; -+ handler = signal(MEM_THREAD_FLUSH_SIG, mem_thread_group_action_flush); -+ if (handler == SIG_ERR) { -+ LSTACK_LOG(ERR, LSTACK, "signal failed\n"); -+ return -1; -+ } -+ pthread_unblock_sig(MEM_THREAD_FLUSH_SIG); -+ return 0; -+} -+ -+static inline void mem_thread_group_notify_flush(const struct mem_thread_group *mt_group, uint32_t timeout) -+{ -+ const struct mem_thread *mt; -+ int stack_id; -+ unsigned count = 0; -+ -+ if (mem_thread_group_in_used(mt_group, timeout)) -+ return; -+ -+ for (stack_id = 0; stack_id < PROTOCOL_STACK_MAX; stack_id++) { -+ mt = &mt_group->mt_array[stack_id]; -+ count += mem_thread_cache_count(mt); -+ } -+ if (count == 0) { -+ return; -+ } -+ -+ if (pthread_kill(mt_group->thread, MEM_THREAD_FLUSH_SIG) != 0) { -+ LSTACK_LOG(ERR, LSTACK, "pthread_kill tid %d failed\n", mt_group->tid); -+ } - } - - static inline bool mem_thread_group_exist(const struct mem_thread_group *mt_group) -@@ -72,6 +141,13 @@ static inline bool mem_thread_group_exist(const struct mem_thread_group *mt_grou - return true; - } - -+static void mem_thread_manager_add_work(struct mem_thread_group *mt_group) -+{ -+ rte_spinlock_lock(&g_mem_thread_manager.list_lock); -+ list_add_node(&mt_group->mt_node, &g_mem_thread_manager.mt_work_list); -+ rte_spinlock_unlock(&g_mem_thread_manager.list_lock); -+} -+ - static void mem_thread_group_free(struct mem_thread_group *mt_group) - { - struct mem_thread *mt; -@@ -100,6 +176,8 @@ static int mem_thread_group_init(int stack_id) - LSTACK_LOG(ERR, LSTACK, "alloc mem_thread_group failed, stack_id %d\n", stack_id); - return -1; - } -+ mem_thread_group_register_flush(); -+ - g_mem_thread_group->tid = rte_gettid(); - g_mem_thread_group->thread = pthread_self(); - list_init_node(&g_mem_thread_group->mt_node); -@@ -107,7 +185,7 @@ static int mem_thread_group_init(int stack_id) - } - - mt = &g_mem_thread_group->mt_array[stack_id]; -- if (mem_thread_cache_init(mt) != 0) { -+ if (mem_thread_cache_init(mt, stack_id) != 0) { - LSTACK_LOG(ERR, LSTACK, "mem_thread_cache_init failed, stack_id %d\n", stack_id); - return -1; - } -@@ -133,6 +211,31 @@ static inline struct mem_thread *mem_thread_group_get(int stack_id) - return mt; - } - -+static void mem_thread_manager_flush_all(void) -+{ -+ struct list_node *node, *next; -+ struct mem_thread_group *mt_group; -+ uint32_t now = sys_now(); -+ -+ rte_spinlock_lock(&g_mem_thread_manager.list_lock); -+ -+ if (now - g_mem_thread_manager.flush_time < MEM_THREAD_MANAGER_FLUSH_MS) { -+ rte_spinlock_unlock(&g_mem_thread_manager.list_lock); -+ return; -+ } -+ g_mem_thread_manager.flush_time = now; -+ -+ list_for_each_node(node, next, &g_mem_thread_manager.mt_work_list) { -+ mt_group = container_of(node, struct mem_thread_group, mt_node); -+ /* skip myself */ -+ if (mt_group == g_mem_thread_group) -+ continue; -+ mem_thread_group_notify_flush(mt_group, MEM_THREAD_MANAGER_FLUSH_MS); -+ } -+ -+ rte_spinlock_unlock(&g_mem_thread_manager.list_lock); -+} -+ - static void *mem_thread_manager_thread(void *arg) - { - struct list_node *node, *next; -@@ -142,9 +245,10 @@ static void *mem_thread_manager_thread(void *arg) - rte_spinlock_init(&g_mem_thread_manager.list_lock); - list_init_head(&g_mem_thread_manager.mt_work_list); - list_init_head(&g_mem_thread_manager.mt_free_list); -+ g_mem_thread_manager.flush_time = sys_now(); - - while(true) { -- sleep(MEM_THREAD_MANAGER_TIMEOUT); -+ sleep(MEM_THREAD_MANAGER_FREE_S); - - rte_spinlock_lock(&g_mem_thread_manager.list_lock); - -@@ -156,7 +260,7 @@ static void *mem_thread_manager_thread(void *arg) - - list_for_each_node(node, next, &g_mem_thread_manager.mt_work_list) { - count++; -- if (count > MEM_THREAD_MANAGER_MAX) { -+ if (count > MEM_THREAD_MANAGER_FREE_MAX) { - /* move list head after the current node, - * and start traversing from this node next time */ - list_del_node(&g_mem_thread_manager.mt_work_list); -@@ -166,6 +270,7 @@ static void *mem_thread_manager_thread(void *arg) - - mt_group = container_of(node, struct mem_thread_group, mt_node); - if (mem_thread_group_exist(mt_group)) { -+ mem_thread_group_notify_flush(mt_group, MEM_THREAD_MANAGER_FREE_S * MS_PER_S); - continue; - } - list_del_node(node); -@@ -183,8 +288,7 @@ int mem_thread_manager_init(void) - return thread_create("gzmempool", 0, mem_thread_manager_thread, NULL); - } - --static __rte_always_inline --struct mem_thread *mem_thread_get(int stack_id) -+static inline struct mem_thread *mem_thread_get(int stack_id) - { - /* stack thread uses mbufpool_cache instead of buf_cache */ - if (get_protocol_stack() != NULL) -@@ -443,42 +547,97 @@ unsigned mem_stack_mbuf_pool_count(int stack_id) - return rte_mempool_avail_count(ms->mbuf_pool); - } - --void mem_thread_cache_free(struct mem_thread *mt) -+static void mem_thread_cache_flush(struct mem_thread *mt) - { -- void *obj; -+ struct mem_stack *ms = mem_stack_get(mt->stack_id); -+ void *obj_table[BUF_BULK_MAX_NUM]; -+ unsigned num; - - if (mt->mbuf_migrate_ring != NULL) { -- while (rte_ring_sc_dequeue(mt->mbuf_migrate_ring, &obj) == 0) { -- mem_put_mbuf_bulk((struct rte_mbuf **)&obj, 1); -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(mem_thread=%p, stack_id=%d, mbuf_migrate_ring count=%u)\n", -+ __FUNCTION__, mt, mt->stack_id, rte_ring_count(mt->mbuf_migrate_ring))); -+ -+ while (true) { -+ num = rte_ring_sc_dequeue_burst(mt->mbuf_migrate_ring, obj_table, BUF_BULK_MAX_NUM, NULL); -+ if (num == 0) -+ break; -+ mbuf_mp_ops.put_bulk(ms->mbuf_pool, obj_table, num); - } -- rte_ring_free(mt->mbuf_migrate_ring); -- mt->mbuf_migrate_ring = NULL; - } - - if (mt->mbuf_cache != NULL) { -- while (buf_cache_pop_bulk(mt->mbuf_cache, &obj, 1, NULL) > 0) { -- mem_put_mbuf_bulk((struct rte_mbuf **)&obj, 1); -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(mem_thread=%p, stack_id=%d, mbuf_cache count=%u)\n", -+ __FUNCTION__, mt, mt->stack_id, buf_cache_count(mt->mbuf_cache))); -+ -+ while (true) { -+ num = LWIP_MIN(buf_cache_count(mt->mbuf_cache), BUF_BULK_MAX_NUM); -+ num = buf_cache_pop_bulk(mt->mbuf_cache, obj_table, num, NULL); -+ if (num == 0) -+ break; -+ mbuf_mp_ops.put_bulk(ms->mbuf_pool, obj_table, num); - } -- buf_cache_free(mt->mbuf_cache); -- mt->mbuf_cache = NULL; -+ buf_cache_reset_watermark(mt->mbuf_cache); - } - - if (mt->rpc_cache != NULL) { -- while (buf_cache_pop_bulk(mt->rpc_cache, &obj, 1, NULL) > 0) { -- mem_put_rpc(obj); -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(mem_thread=%p, stack_id=%d, rpc_cache count=%u)\n", -+ __FUNCTION__, mt, mt->stack_id, buf_cache_count(mt->rpc_cache))); -+ -+ while (true) { -+ num = LWIP_MIN(buf_cache_count(mt->rpc_cache), BUF_BULK_MAX_NUM); -+ num = buf_cache_pop_bulk(mt->rpc_cache, obj_table, num, NULL); -+ if (num == 0) -+ break; -+ mem_mp_ops.put_bulk(ms->rpc_pool, obj_table, num); - } -+ buf_cache_reset_watermark(mt->rpc_cache); -+ } -+} -+ -+static unsigned mem_thread_cache_count(const struct mem_thread *mt) -+{ -+ unsigned count = 0; -+ -+ if (mt->mbuf_migrate_ring != NULL) { -+ count += rte_ring_count(mt->mbuf_migrate_ring); -+ } -+ if (mt->mbuf_cache != NULL) { -+ count += buf_cache_count(mt->mbuf_cache); -+ } -+ if (mt->rpc_cache != NULL) { -+ count += buf_cache_count(mt->rpc_cache); -+ } -+ return count; -+} -+ -+void mem_thread_cache_free(struct mem_thread *mt) -+{ -+ mem_thread_cache_flush(mt); -+ -+ if (mt->mbuf_migrate_ring != NULL) { -+ rte_ring_free(mt->mbuf_migrate_ring); -+ mt->mbuf_migrate_ring = NULL; -+ } -+ if (mt->mbuf_cache != NULL) { -+ buf_cache_free(mt->mbuf_cache); -+ mt->mbuf_cache = NULL; -+ } -+ if (mt->rpc_cache != NULL) { - buf_cache_free(mt->rpc_cache); - mt->rpc_cache = NULL; - } - } - --int mem_thread_cache_init(struct mem_thread *mt) -+int mem_thread_cache_init(struct mem_thread *mt, int stack_id) - { -+ mt->stack_id = stack_id; -+ - if (get_global_cfg_params()->mem_async_mode) { - char name [RTE_MEMPOOL_NAMESIZE]; - SYS_FORMAT_NAME(name, RTE_MEMPOOL_NAMESIZE, "%s_%p", "migrate_ring", mt); - -- mt->mbuf_migrate_ring = rte_ring_create(name, BUF_CACHE_MAX_NUM, -+ mt->mbuf_migrate_ring = rte_ring_create(name, -+ LWIP_MAX(get_global_cfg_params()->mem_cache_num, MIGRATE_RING_MIN_NUM), - rte_socket_id(), RING_F_SP_ENQ | RING_F_SC_DEQ); - if (mt->mbuf_migrate_ring == NULL) { - return -1; -@@ -522,9 +681,17 @@ void mem_mbuf_migrate_enqueue(struct mem_thread *mt, unsigned n) - mpcache = ms->mbuf_mpcache; - - mt->stk_migrate_count += n; -+ if (mt->stk_migrate_count < BUF_CACHE_WATERSTEP_MIN) -+ return; -+ if (mpcache->len < ms->migrate_watermark) -+ return; - -- if (mpcache->len <= ms->migrate_watermark) -+ /* no sufficient mbuf */ -+ if (rte_ring_count(ms->mbuf_pool->pool_data) < MBUFPOOL_RESERVE_NUM) { -+ mem_thread_manager_flush_all(); -+ mt->stk_migrate_count = 0; - return; -+ } - - num = LWIP_MIN(mpcache->len - ms->migrate_watermark, - mt->stk_migrate_count); -@@ -654,8 +821,8 @@ static void pool_put_bulk_with_cache(const struct mempool_ops *pool_ops, - - /* dequeue from cache, then put to the pool */ - put_count = count - cache->watermark; -- LWIP_DEBUGF(MEMP_DEBUG, ("pool_put_bulk_with_cache(cache=%p, watermark=%u, put_count=%u)\n", -- cache, cache->watermark, put_count)); -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(cache=%p, watermark=%u, put_count=%u)\n", -+ __FUNCTION__, cache, cache->watermark, put_count)); - - pool_ops->put_bulk(pool, &cache->objs[cache->head - put_count], put_count); - cache->head -= put_count; -@@ -674,10 +841,12 @@ void *mem_get_rpc(int stack_id) - if (mt == NULL) { - ret = mem_mp_ops.get_bulk(ms->rpc_pool, &obj, 1); - } else { -+ mem_thread_group_used(); - ret = pool_get_bulk_with_cache(&mem_mp_ops, ms->rpc_pool, mt->rpc_cache, &obj, 1); -+ mem_thread_group_done(); - } - -- LWIP_DEBUGF(MEMP_DEBUG, ("mem_get_rpc(stack_id=%d, obj=%p)\n", stack_id, obj)); -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(stack_id=%d, obj=%p)\n", __FUNCTION__, stack_id, obj)); - - return ret == 0 ? NULL : obj; - } -@@ -688,12 +857,14 @@ void mem_put_rpc(void *obj) - struct mem_stack *ms = mem_stack_get(stack_id); - struct mem_thread *mt = mem_thread_get(stack_id); - -- LWIP_DEBUGF(MEMP_DEBUG, ("mem_put_rpc(stack_id=%d, obj=%p)\n", stack_id, obj)); -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(stack_id=%d, obj=%p)\n", __FUNCTION__, stack_id, obj)); - - if (mt == NULL) { - mem_mp_ops.put_bulk(ms->rpc_pool, &obj, 1); - } else { -+ mem_thread_group_used(); - pool_put_bulk_with_cache(&mem_mp_ops, ms->rpc_pool, mt->rpc_cache, &obj, 1); -+ mem_thread_group_done(); - } - } - -@@ -712,6 +883,7 @@ unsigned mem_get_mbuf_bulk(int stack_id, struct rte_mbuf **mbuf_table, unsigned - * when RTE_MAX_LCORE is too large, it's time-consuming - */ - if (rte_ring_count(ms->mbuf_pool->pool_data) < MBUFPOOL_RESERVE_NUM + n) { -+ mem_thread_manager_flush_all(); - return 0; - } - } -@@ -719,14 +891,16 @@ unsigned mem_get_mbuf_bulk(int stack_id, struct rte_mbuf **mbuf_table, unsigned - if (mt == NULL) { - ret = mbuf_mp_ops.get_bulk(ms->mbuf_pool, (void **)mbuf_table, n); - } else { -+ mem_thread_group_used(); - mem_mbuf_migrate_dequeue(mt); - ret = pool_get_bulk_with_cache(&mbuf_mp_ops, ms->mbuf_pool, mt->mbuf_cache, (void **)mbuf_table, n); -+ mem_thread_group_done(); - } - - #if MEMP_DEBUG - for (unsigned i = 0; i < ret; ++i) { -- LWIP_DEBUGF(MEMP_DEBUG, ("mem_get_mbuf_bulk(stack_id=%d, n=%u, mbuf_table[%u]=%p, pbuf=%p)\n", -- stack_id, n, i, mbuf_table[i], mbuf_to_pbuf(mbuf_table[i]))); -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(stack_id=%d, n=%u, mbuf_table[%u]=%p, pbuf=%p)\n", -+ __FUNCTION__, stack_id, n, i, mbuf_table[i], mbuf_to_pbuf(mbuf_table[i]))); - } - #endif /* MEMP_DEBUG */ - -@@ -745,15 +919,17 @@ static void mem_put_mbuf_bulk_by_pbuf(struct rte_mbuf *const *mbuf_table, unsign - - #if MEMP_DEBUG - for (unsigned i = 0; i < n; ++i) { -- LWIP_DEBUGF(MEMP_DEBUG, ("mem_put_mbuf_bulk(stack_id=%d, n=%u, mbuf_table[%u]=%p, pbuf=%p)\n", -- stack_id, n, i, mbuf_table[i], mbuf_to_pbuf(mbuf_table[i]))); -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(stack_id=%d, n=%u, mbuf_table[%u]=%p, pbuf=%p)\n", -+ __FUNCTION__, stack_id, n, i, mbuf_table[i], mbuf_to_pbuf(mbuf_table[i]))); - } - #endif /* MEMP_DEBUG */ - - if (mt == NULL) { - mbuf_mp_ops.put_bulk(ms->mbuf_pool, (void *const *)mbuf_table, n); - } else { -+ mem_thread_group_used(); - pool_put_bulk_with_cache(&mbuf_mp_ops, ms->mbuf_pool, mt->mbuf_cache, (void *const *)mbuf_table, n); -+ mem_thread_group_done(); - } - - } -@@ -826,8 +1002,8 @@ struct rte_mbuf *pbuf_to_mbuf_prefree(struct pbuf *p) - struct rte_mbuf *m = pbuf_to_mbuf(p); - #if MEMP_DEBUG - if (rte_mbuf_refcnt_read(m) > 1) { -- LWIP_DEBUGF(MEMP_DEBUG, ("pbuf_to_mbuf_prefree(mbuf=%p, pbuf=%p, refcnt=%u)\n", -- m, p, rte_mbuf_refcnt_read(m))); -+ LWIP_DEBUGF(MEMP_DEBUG, ("%s(mbuf=%p, pbuf=%p, refcnt=%u)\n", -+ __FUNCTION__, m, p, rte_mbuf_refcnt_read(m))); - } - #endif /* MEMP_DEBUG */ - if (p->mbuf_refcnt != 1) { -@@ -868,6 +1044,9 @@ void mem_put_pbuf_list_bulk(struct pbuf *const *pbuf_table, unsigned n) - struct pbuf *q, *next; - struct rte_mbuf *mbuf; - -+ if (mt != NULL) -+ mem_thread_group_used(); -+ - for (unsigned i = 0; i < n; ++i) { - q = pbuf_table[i]; - while (q != NULL) { -@@ -893,6 +1072,10 @@ void mem_put_pbuf_list_bulk(struct pbuf *const *pbuf_table, unsigned n) - __FUNCTION__, stack_id, n, i, mbuf, q)); - } - } -+ -+ if (mt != NULL) -+ mem_thread_group_done(); -+ return; - } - - struct pbuf *mem_get_pbuf(int stack_id, bool reserve) -@@ -1001,7 +1184,9 @@ void mem_init_pbuf(struct pbuf *p, pbuf_layer layer, uint16_t tot_len, uint16_t - struct rte_mbuf *mbuf; - void *data; - -- if (p->type_internal == PBUF_POOL_PREINIT) { -+ /* PBUF_POOL_PREINIT maybe give back to mbuf_pool, and alloc to NIC rx. -+ * so ignore PBUF_POOL_PREINIT at this time. */ -+ if (layer == PBUF_TRANSPORT && p->type_internal == PBUF_POOL_PREINIT) { - p->payload = (uint8_t *)p->payload + LWIP_MEM_ALIGN_SIZE((uint16_t)layer); - p->type_internal = type; - p->len = len; -diff --git a/src/lstack/include/lstack_mempool.h b/src/lstack/include/lstack_mempool.h -index 848509c..e636fda 100644 ---- a/src/lstack/include/lstack_mempool.h -+++ b/src/lstack/include/lstack_mempool.h -@@ -44,12 +44,15 @@ - #define MEMPOOL_OPS_NAME "ring_mt_rts" - #define MEMPOOL_CACHE_NUM 32 - --#define BUF_CACHE_MIN_NUM 32 -+#define BUF_CACHE_MIN_NUM 16 - #define BUF_CACHE_MAX_NUM 1024 - #define BUF_CACHE_WATERSTEP_SHIFT 4 /* 1/16 */ -+#define BUF_CACHE_WATERSTEP_MIN 4 - - #define BUF_BULK_MAX_NUM 32 - -+#define MIGRATE_RING_MIN_NUM (BUF_CACHE_MIN_NUM << 1) -+ - struct buf_cache { - unsigned size; /* Size of cache. */ - unsigned mask; /* Mask (size-1) of cache. */ -@@ -91,8 +94,8 @@ struct buf_cache *buf_cache_create(unsigned count) - cache->tail = 0; - - cache->waterstep = cache->size >> BUF_CACHE_WATERSTEP_SHIFT; -- if (cache->waterstep < BUF_CACHE_WATERSTEP_SHIFT) -- cache->waterstep = BUF_CACHE_WATERSTEP_SHIFT; -+ if (cache->waterstep < BUF_CACHE_WATERSTEP_MIN) -+ cache->waterstep = BUF_CACHE_WATERSTEP_MIN; - cache->watermark = cache->waterstep; - cache->flushthresh = cache->size - cache->waterstep; - -@@ -142,6 +145,12 @@ void buf_cache_sub_watermark(struct buf_cache *cache) - } - } - -+static __rte_always_inline -+void buf_cache_reset_watermark(struct buf_cache *cache) -+{ -+ cache->watermark = cache->waterstep; -+} -+ - static __rte_always_inline - void __buf_cache_copy_objs(void ** dst_table, void *const *src_table, unsigned n) - { -@@ -273,6 +282,8 @@ struct mem_stack { - }; - - struct mem_thread { -+ int stack_id; -+ - struct buf_cache *rpc_cache; - - struct buf_cache *mbuf_cache; -@@ -289,7 +300,7 @@ int mem_stack_mpcache_init(int stack_id, unsigned cpu_id); - - int mem_thread_manager_init(void); - void mem_thread_cache_free(struct mem_thread *mt); --int mem_thread_cache_init(struct mem_thread *mt); -+int mem_thread_cache_init(struct mem_thread *mt, int stack_id); - - unsigned mem_stack_mbuf_pool_count(int stack_id); - struct rte_mempool *mem_get_mbuf_pool(int stack_id); -diff --git a/src/lstack/include/lstack_unistd.h b/src/lstack/include/lstack_unistd.h -index 3bcee5a..397cd19 100644 ---- a/src/lstack/include/lstack_unistd.h -+++ b/src/lstack/include/lstack_unistd.h -@@ -16,6 +16,9 @@ - #include - #include - -+void pthread_block_sig(int sig); -+void pthread_unblock_sig(int sig); -+ - int lstack_signal_init(void); - int lstack_sigaction(int sig_num, const struct sigaction *action, struct sigaction *old_action); - pid_t lstack_fork(void); --- -2.33.0 - diff --git a/0333-dfx-support-sk_wait-stat.patch b/0333-dfx-support-sk_wait-stat.patch deleted file mode 100644 index ebd305d8e6681cd69ae10f7cbf0bdd4af5808907..0000000000000000000000000000000000000000 --- a/0333-dfx-support-sk_wait-stat.patch +++ /dev/null @@ -1,526 +0,0 @@ -From 4884431653c978adfc03053e1803dd93b58ca3a0 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 1 Apr 2025 20:50:08 +0800 -Subject: [PATCH] dfx: support sk_wait stat - -Signed-off-by: Lemmy Huang ---- - src/common/gazelle_dfx_msg.h | 27 ++++++++-------- - src/lstack/api/lstack_sockctl.c | 7 ++-- - src/lstack/api/lstack_sockio.c | 45 +++++++++++++++++--------- - src/lstack/core/lstack_mempool.c | 18 +++++++---- - src/lstack/core/lstack_stack_stat.c | 12 +++---- - src/lstack/core/lstack_thread_rpc.c | 16 ++++----- - src/lstack/core/lstack_wait.c | 15 ++++++--- - src/lstack/include/lstack_mempool.h | 3 +- - src/lstack/include/lstack_thread_rpc.h | 9 ++---- - src/lstack/include/lstack_wait.h | 4 ++- - src/ltran/ltran_dfx.c | 31 ++++++++---------- - 11 files changed, 105 insertions(+), 82 deletions(-) - -diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h -index 2c6462d..2f1066d 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -94,31 +94,33 @@ enum GAZELLE_TCP_LIST_STATE { - }; - - struct gazelle_stack_stat { -+ uint32_t conn_num; -+ uint32_t mbuf_pool_cnt; - uint64_t wakeup_events; -- uint64_t write_lwip_cnt; -- uint64_t send_pkts_fail; -- uint64_t read_lwip_drop; -- uint64_t read_lwip_cnt; - uint64_t rx_allocmbuf_fail; - uint64_t tx_allocmbuf_fail; -- uint64_t call_null; - uint64_t rx_drop; - uint64_t rx; - uint64_t tx_drop; - uint64_t tx; - uint64_t tx_prepare_fail; -- uint64_t accept_fail; -- uint64_t sock_rx_drop; -- uint64_t sock_tx_merge; - }; - - struct gazelle_wakeup_stat { -+ uint64_t kernel_events; - uint64_t app_events; -- uint64_t app_write_rpc; -+ uint64_t accept_fail; - uint64_t app_write_cnt; - uint64_t app_read_cnt; - uint64_t read_null; -- uint64_t kernel_events; -+ uint64_t sock_rx_drop; -+ uint64_t sock_tx_merge; -+}; -+ -+struct gazelle_rpc_stat { -+ uint32_t rpc_pool_cnt; -+ uint64_t call_alloc_fail; -+ uint64_t call_msg_cnt; - }; - - struct gazelle_stack_aggregate_stats { -@@ -134,12 +136,9 @@ struct gazelle_stack_aggregate_stats { - }; - - struct gazelle_stat_pkts { -- uint16_t conn_num; -- uint32_t mbufpool_avail_cnt; -- uint64_t call_msg_cnt; -- uint64_t call_alloc_fail; - struct gazelle_stack_stat stack_stat; - struct gazelle_wakeup_stat wakeup_stat; -+ struct gazelle_rpc_stat rpc_stat; - struct gazelle_stack_aggregate_stats aggregate_stats; - }; - -diff --git a/src/lstack/api/lstack_sockctl.c b/src/lstack/api/lstack_sockctl.c -index 7da7473..7ff7163 100644 ---- a/src/lstack/api/lstack_sockctl.c -+++ b/src/lstack/api/lstack_sockctl.c -@@ -388,13 +388,16 @@ static int rpc_call_shadow_fd(int stack_id, int fd, const struct sockaddr *addr, - - static void callback_accept(struct rpc_msg *msg) - { -+ struct lwip_sock *sock; - int fd = msg->args[MSG_ARG_0].i; - msg->result = -1; -- struct protocol_stack *stack = get_protocol_stack(); - - int accept_fd = lwip_accept4(fd, msg->args[MSG_ARG_1].p, msg->args[MSG_ARG_2].p, msg->args[MSG_ARG_3].i); - if (accept_fd < 0) { -- stack->stats.accept_fail++; -+ sock = lwip_get_socket(fd); -+ if (!POSIX_IS_CLOSED(sock)) { -+ SOCK_WAIT_STAT(sock->sk_wait, accept_fail, 1); -+ } - LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); - return; - } -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 060b3b3..89a6acb 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -49,7 +49,7 @@ struct sockio_ops { - const struct sockaddr *to, socklen_t tolen); - void (*stack_udp_send)(struct lwip_sock *sock); - -- ssize_t (*stack_udp_readmsg)(struct lwip_sock *sock, struct msghdr *msg, int flags); -+ ssize_t (*stack_udp_readmsg)(struct lwip_sock *sock, struct msghdr *msg, size_t len, int flags); - - ssize_t (*stack_tcp_write)(struct lwip_sock *sock, const char *data, size_t len, int flags); - void (*stack_tcp_send)(struct lwip_sock *sock); -@@ -260,6 +260,8 @@ static uint16_t stack_udp_write_one(const struct lwip_sock *sock, struct mbox_ri - mr->ops->enqueue_burst(mr, (void **)&nbuf, 1); - mr->app_free_count -= 1; - -+ SOCK_WAIT_STAT(sock->sk_wait, app_write_cnt, 1); -+ - return len; - } - -@@ -268,7 +270,7 @@ static uint16_t stack_udp_write_bulk(const struct lwip_sock *sock, struct mbox_r - const struct sockaddr *to, socklen_t tolen) - { - struct pbuf *pbuf_pkts[UDP_SND_QUEUELEN_MAX]; -- unsigned pbuf_num; -+ unsigned pbuf_num = 0; - struct netbuf *nbuf; - uint16_t payload_size; - uint8_t optlen; -@@ -328,6 +330,8 @@ static uint16_t stack_udp_write_bulk(const struct lwip_sock *sock, struct mbox_r - mr->ops->push_tail(mr, nbuf); - } - -+ SOCK_WAIT_STAT(sock->sk_wait, app_write_cnt, pbuf_num); -+ - return copied_total; - } - -@@ -473,7 +477,7 @@ static void rtc_stack_udp_send(struct lwip_sock *sock) - } while (output_again); - } - --static ssize_t stack_udp_readmsg(struct lwip_sock *sock, struct msghdr *msg, int flags) -+static ssize_t stack_udp_readmsg(struct lwip_sock *sock, struct msghdr *msg, size_t len, int flags) - { - struct mbox_ring *mr = &sock->conn->recvmbox->mring; - struct pbuf **extcache_list; -@@ -505,6 +509,8 @@ static ssize_t stack_udp_readmsg(struct lwip_sock *sock, struct msghdr *msg, int - err = lwip_recvfrom_udp_raw(sock, flags | MSG_PEEK, msg, &copied_total, 0); - sock->lastdata.netbuf = NULL; - -+ SOCK_WAIT_STAT(sock->sk_wait, app_read_cnt, 1); -+ SOCK_WAIT_STAT(sock->sk_wait, sock_rx_drop, copied_total < len ? 1 : 0); - if (get_protocol_stack_group()->latency_start) - calculate_lstack_latency(sock->stack_id, &nbuf->p, 1, GAZELLE_LATENCY_READ_LSTACK, 0); - -@@ -532,6 +538,8 @@ static ssize_t stack_udp_readmsg(struct lwip_sock *sock, struct msghdr *msg, int - return copied_total; - } - out: -+ SOCK_WAIT_STAT(sock->sk_wait, read_null, 1); -+ - set_errno(err_to_errno(err)); - return -1; - } -@@ -561,6 +569,8 @@ static uint16_t rtw_stack_tcp_write_one(const struct lwip_sock *sock, struct mbo - mr->ops->enqueue_burst(mr, (void **)&p, 1); - mr->app_free_count -= 1; - -+ SOCK_WAIT_STAT(sock->sk_wait, app_write_cnt, 1); -+ - return len; - } - -@@ -582,6 +592,7 @@ static uint16_t rtw_stack_tcp_write_bulk(const struct lwip_sock *sock, struct mb - - write_pbuf_bulk(pbuf_pkts, pbuf_num, TCP_MSS, data, len, 0); - -+ SOCK_WAIT_STAT(sock->sk_wait, app_write_cnt, pbuf_num); - if (get_protocol_stack_group()->latency_start) - calculate_lstack_latency(sock->stack_id, pbuf_pkts, pbuf_num, GAZELLE_LATENCY_WRITE_INTO_RING, 0); - -@@ -670,6 +681,7 @@ static ssize_t rtw_stack_tcp_write(struct lwip_sock *sock, const char *data, siz - } - - copied_total = rtw_stack_tcp_append(mr, data, LWIP_MIN(TCP_MSS, total_copy_len), flags); -+ SOCK_WAIT_STAT(sock->sk_wait, sock_tx_merge, copied_total > 0 ? 1 : 0); - if (copied_total == total_copy_len) { - return copied_total; - } -@@ -843,6 +855,7 @@ static ssize_t stack_tcp_read(struct lwip_sock *sock, char *data, size_t len, in - break; - } - -+ SOCK_WAIT_STAT(sock->sk_wait, app_read_cnt, 1); - if (get_protocol_stack_group()->latency_start) - calculate_lstack_latency(sock->stack_id, &p, 1, GAZELLE_LATENCY_READ_APP_CALL, sys_now_us()); - -@@ -879,6 +892,8 @@ static ssize_t stack_tcp_read(struct lwip_sock *sock, char *data, size_t len, in - return copied_total; - } - -+ SOCK_WAIT_STAT(sock->sk_wait, read_null, 1); -+ - set_errno(err_to_errno(err)); - if (err == ERR_CLSD) { - return 0; -@@ -1133,10 +1148,10 @@ ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, - msg.msg_iovlen = 1; - msg.msg_name = from; - msg.msg_namelen = (fromlen ? *fromlen : 0); -- recvd = ioops.stack_udp_readmsg(sock, &msg, flags); -+ recvd = ioops.stack_udp_readmsg(sock, &msg, len, flags); - if (recvd < 0 && errno == EWOULDBLOCK) { - if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { -- recvd = ioops.stack_udp_readmsg(sock, &msg, flags); -+ recvd = ioops.stack_udp_readmsg(sock, &msg, len, flags); - } - } - if (recvd > 0 && fromlen != NULL) { -@@ -1154,11 +1169,11 @@ ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, - ssize_t sockio_recvmsg(int fd, struct msghdr *msg, int flags) - { - struct lwip_sock *sock = lwip_get_socket(fd); -- ssize_t ret, recvd = 0; -+ ssize_t len, recvd = 0; - -- ret = lwip_recvmsg_check(NULL, msg, flags); -- if (unlikely(ret <= 0)) { -- return ret; -+ len = lwip_recvmsg_check(NULL, msg, flags); -+ if (unlikely(len <= 0)) { -+ return len; - } - - if (unlikely(!sock->affinity_numa)) { -@@ -1169,20 +1184,20 @@ ssize_t sockio_recvmsg(int fd, struct msghdr *msg, int flags) - switch (NETCONN_TYPE(sock->conn)) { - case NETCONN_TCP: - for (int i = 0; i < msg->msg_iovlen; ++i) { -- ret = sockio_recvfrom(fd, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags, NULL, NULL); -- if (ret <= 0) { -+ len = sockio_recvfrom(fd, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags, NULL, NULL); -+ if (len <= 0) { - if (recvd == 0) -- recvd = ret; -+ recvd = len; - break; - } -- recvd += ret; -+ recvd += len; - } - break; - case NETCONN_UDP: -- recvd = ioops.stack_udp_readmsg(sock, msg, flags); -+ recvd = ioops.stack_udp_readmsg(sock, msg, len, flags); - if (recvd < 0 && errno == EWOULDBLOCK) { - if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { -- recvd = ioops.stack_udp_readmsg(sock, msg, flags); -+ recvd = ioops.stack_udp_readmsg(sock, msg, len, flags); - } - } - break; -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index 7e2a706..bb47830 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -65,6 +65,18 @@ struct rte_mempool *mem_get_rpc_pool(int stack_id) - return g_mem_stack_group[stack_id].rpc_pool; - } - -+unsigned mem_stack_mbuf_pool_count(int stack_id) -+{ -+ struct mem_stack *ms = mem_stack_get(stack_id); -+ return rte_mempool_avail_count(ms->mbuf_pool); -+} -+ -+unsigned mem_stack_rpc_pool_count(int stack_id) -+{ -+ struct mem_stack *ms = mem_stack_get(stack_id); -+ return rte_mempool_avail_count(ms->rpc_pool); -+} -+ - static inline bool mem_thread_group_in_used(const struct mem_thread_group *mt_grooup, uint32_t timeout) - { - return mt_grooup->used_flag || -@@ -541,12 +553,6 @@ int mem_stack_mpcache_init(int stack_id, unsigned cpu_id) - return 0; - } - --unsigned mem_stack_mbuf_pool_count(int stack_id) --{ -- struct mem_stack *ms = mem_stack_get(stack_id); -- return rte_mempool_avail_count(ms->mbuf_pool); --} -- - static void mem_thread_cache_flush(struct mem_thread *mt) - { - struct mem_stack *ms = mem_stack_get(mt->stack_id); -diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c -index 3b3bd75..c84b7b1 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -221,6 +221,8 @@ static void get_stack_stats(struct gazelle_stack_dfx_data *dfx, struct protocol_ - - lstack_get_low_power_info(&dfx->low_power_info); - -+ stack->stats.conn_num = stack->conn_num; -+ stack->stats.mbuf_pool_cnt = mem_stack_mbuf_pool_count(stack->stack_idx); - int32_t ret = memcpy_s(&dfx->data.pkts.stack_stat, sizeof(struct gazelle_stack_stat), - &stack->stats, sizeof(struct gazelle_stack_stat)); - if (ret != EOK) { -@@ -229,15 +231,9 @@ static void get_stack_stats(struct gazelle_stack_dfx_data *dfx, struct protocol_ - } - - sock_wait_group_stat(stack->stack_idx, &dfx->data.pkts.wakeup_stat); -+ rpc_get_stat(&stack->rpc_queue, &dfx->data.pkts.rpc_stat); - -- dfx->data.pkts.call_alloc_fail = rpc_stats_get()->call_alloc_fail; -- -- int32_t rpc_call_result = rpc_msgcnt(&stack->rpc_queue); -- dfx->data.pkts.call_msg_cnt = (rpc_call_result < 0) ? 0 : rpc_call_result; -- -- dfx->data.pkts.mbufpool_avail_cnt = mem_stack_mbuf_pool_count(stack->stack_idx); -- -- dfx->data.pkts.conn_num = stack->conn_num; -+ return; - } - - static void get_stack_dfx_data_proto(struct gazelle_stack_dfx_data *dfx, struct protocol_stack *stack, -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 7b3e432..84e5814 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -10,6 +10,8 @@ - * See the Mulan PSL v2 for more details. - */ - -+#include -+ - #include - #include - -@@ -20,11 +22,13 @@ - #include "lstack_thread_rpc.h" - #include "lstack_mempool.h" - --static struct rpc_stats g_rpc_stats; -+static struct gazelle_rpc_stat g_rpc_stats = {0}; - --struct rpc_stats *rpc_stats_get(void) -+void rpc_get_stat(rpc_queue *queue, struct gazelle_rpc_stat *stat) - { -- return &g_rpc_stats; -+ g_rpc_stats.rpc_pool_cnt = mem_stack_rpc_pool_count(queue->queue_id); -+ g_rpc_stats.call_msg_cnt = rpc_msgcnt(queue); -+ memcpy_s(stat, sizeof(struct gazelle_rpc_stat), &g_rpc_stats, sizeof(struct gazelle_rpc_stat)); - } - - __rte_always_inline -@@ -114,11 +118,7 @@ int rpc_poll_msg(rpc_queue *queue, int max_num) - } - msg = container_of(node, struct rpc_msg, queue_node); - -- if (likely(msg->func)) { -- msg->func(msg); -- } else { -- g_rpc_stats.call_null++; -- } -+ msg->func(msg); - - if (msg->flags & RPC_MSG_RECALL) { - msg->flags &= ~RPC_MSG_RECALL; -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -index c67df93..381290c 100644 ---- a/src/lstack/core/lstack_wait.c -+++ b/src/lstack/core/lstack_wait.c -@@ -129,10 +129,17 @@ void sock_wait_group_stat(int stack_id, struct gazelle_wakeup_stat *stat) - list_for_each_node(node, next, &g_wait_group.group_list) { - sk_wait = list_entry(node, struct sock_wait, group_node); - -- if (sk_wait->affinity.bind_stack_id == stack_id) { -- memcpy_s(stat, sizeof(struct gazelle_wakeup_stat), -- &sk_wait->stat, sizeof(struct gazelle_wakeup_stat)); -- } -+ if (sk_wait->affinity.bind_stack_id != stack_id) -+ continue; -+ -+ stat->kernel_events += sk_wait->stat.kernel_events ; -+ stat->app_events += sk_wait->stat.app_events ; -+ stat->accept_fail += sk_wait->stat.accept_fail ; -+ stat->app_write_cnt += sk_wait->stat.app_write_cnt ; -+ stat->app_read_cnt += sk_wait->stat.app_read_cnt ; -+ stat->read_null += sk_wait->stat.read_null ; -+ stat->sock_rx_drop += sk_wait->stat.sock_rx_drop ; -+ stat->sock_tx_merge += sk_wait->stat.sock_tx_merge ; - } - - rte_spinlock_unlock(&g_wait_group.group_list_lock); -diff --git a/src/lstack/include/lstack_mempool.h b/src/lstack/include/lstack_mempool.h -index e636fda..bd170bb 100644 ---- a/src/lstack/include/lstack_mempool.h -+++ b/src/lstack/include/lstack_mempool.h -@@ -302,9 +302,10 @@ int mem_thread_manager_init(void); - void mem_thread_cache_free(struct mem_thread *mt); - int mem_thread_cache_init(struct mem_thread *mt, int stack_id); - --unsigned mem_stack_mbuf_pool_count(int stack_id); - struct rte_mempool *mem_get_mbuf_pool(int stack_id); - struct rte_mempool *mem_get_rpc_pool(int stack_id); -+unsigned mem_stack_mbuf_pool_count(int stack_id); -+unsigned mem_stack_rpc_pool_count(int stack_id); - - void *mem_get_rpc(int stack_id); - void mem_put_rpc(void *obj); -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 32dde53..013ff29 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -16,6 +16,7 @@ - #include - #include - -+#include "common/gazelle_dfx_msg.h" - #include "lstack_lockless_queue.h" - #include "lstack_interrupt.h" - -@@ -32,12 +33,6 @@ struct rpc_queue { - uint16_t queue_id; - }; - --struct rpc_stats { -- uint16_t call_null; -- uint64_t call_alloc_fail; --}; --struct rpc_stats *rpc_stats_get(void); -- - union rpc_msg_arg { - int i; - unsigned int u; -@@ -67,6 +62,8 @@ struct rpc_msg { - lockless_queue_node queue_node; - }; - -+void rpc_get_stat(rpc_queue *queue, struct gazelle_rpc_stat *stat); -+ - struct rpc_msg *rpc_msg_alloc(int stack_id, rpc_func_t func); - void rpc_msg_free(struct rpc_msg *msg); - -diff --git a/src/lstack/include/lstack_wait.h b/src/lstack/include/lstack_wait.h -index ed154b4..306c6a4 100644 ---- a/src/lstack/include/lstack_wait.h -+++ b/src/lstack/include/lstack_wait.h -@@ -73,7 +73,6 @@ struct sock_wait { - - /* dfx stat */ - struct list_node group_node; -- struct gazelle_wakeup_stat stat; - - /* epoll kernel fd */ - int epfd; -@@ -83,6 +82,9 @@ struct sock_wait { - unsigned kernel_nfds; - struct wait_affinity affinity; - -+#define SOCK_WAIT_STAT(sk_wait, name, count) if ((sk_wait) != NULL && (sk_wait)->type != WAIT_CLOSE) { (sk_wait)->stat.name += count; } -+ struct gazelle_wakeup_stat stat; -+ - char pad0 __rte_cache_aligned; /* new cache line */ - - #if SOCK_WAIT_BATCH_NOTIFY -diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c -index 1722460..01ff2c3 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -734,26 +734,23 @@ static void show_lstack_stats(struct gazelle_stack_dfx_data *lstack_stat) - printf("tx_pkts: %-20"PRIu64" ", lstack_stat->data.pkts.stack_stat.tx); - printf("tx_drop: %-20"PRIu64" ", lstack_stat->data.pkts.stack_stat.tx_drop); - printf("tx_allocmbuf_fail: %-10"PRIu64"\n", lstack_stat->data.pkts.stack_stat.tx_allocmbuf_fail); -+ -+ printf("mbuf_pool_freecnt: %-10"PRIu32" ", lstack_stat->data.pkts.stack_stat.mbuf_pool_cnt); -+ printf("conn_num: %-19hu ", lstack_stat->data.pkts.stack_stat.conn_num); -+ printf("wakeup_events: %-14"PRIu64" \n", lstack_stat->data.pkts.stack_stat.wakeup_events); -+ -+ printf("rpc_pool_cnt: %-15"PRIu32" ", lstack_stat->data.pkts.rpc_stat.rpc_pool_cnt); -+ printf("call_alloc_fail: %-12"PRIu64" ", lstack_stat->data.pkts.rpc_stat.call_alloc_fail); -+ printf("call_msg: %-19"PRIu64" \n", lstack_stat->data.pkts.rpc_stat.call_msg_cnt); -+ -+ printf("kernel_events: %-14"PRIu64" ", lstack_stat->data.pkts.wakeup_stat.kernel_events); -+ printf("app_events: %-17"PRIu64" \n", lstack_stat->data.pkts.wakeup_stat.app_events); - printf("app_read: %-19"PRIu64" ", lstack_stat->data.pkts.wakeup_stat.app_read_cnt); -- printf("read_lwip: %-18"PRIu64" ", lstack_stat->data.pkts.stack_stat.read_lwip_cnt); -- printf("read_lwip_drop: %-13"PRIu64" \n", lstack_stat->data.pkts.stack_stat.read_lwip_drop); - printf("app_write: %-18"PRIu64" ", lstack_stat->data.pkts.wakeup_stat.app_write_cnt); -- printf("write_lwip: %-17"PRIu64" ", lstack_stat->data.pkts.stack_stat.write_lwip_cnt); -- printf("app_write_rpc: %-14"PRIu64" \n", lstack_stat->data.pkts.wakeup_stat.app_write_rpc); -- printf("conn_num: %-19hu ", lstack_stat->data.pkts.conn_num); -- -- printf("kernel_events: %-14"PRIu64"\n", lstack_stat->data.pkts.wakeup_stat.kernel_events); -- printf("wakeup_events: %-14"PRIu64" ", lstack_stat->data.pkts.stack_stat.wakeup_events); -- printf("app_events: %-17"PRIu64" ", lstack_stat->data.pkts.wakeup_stat.app_events); - printf("read_null: %-18"PRIu64" \n", lstack_stat->data.pkts.wakeup_stat.read_null); -- printf("call_msg: %-19"PRIu64" ", lstack_stat->data.pkts.call_msg_cnt); -- printf("call_alloc_fail: %-12"PRIu64" ", lstack_stat->data.pkts.call_alloc_fail); -- printf("call_null: %-18"PRIu64" \n", lstack_stat->data.pkts.stack_stat.call_null); -- printf("send_pkts_fail: %-13"PRIu64" ", lstack_stat->data.pkts.stack_stat.send_pkts_fail); -- printf("mbuf_pool_freecnt: %-10"PRIu32" \n", lstack_stat->data.pkts.mbufpool_avail_cnt); -- printf("accpet_fail: %-16"PRIu64" ", lstack_stat->data.pkts.stack_stat.accept_fail); -- printf("sock_rx_drop: %-15"PRIu64" ", lstack_stat->data.pkts.stack_stat.sock_rx_drop); -- printf("sock_tx_merge: %-16"PRIu64" \n", lstack_stat->data.pkts.stack_stat.sock_tx_merge); -+ printf("sock_rx_drop: %-15"PRIu64" ", lstack_stat->data.pkts.wakeup_stat.sock_rx_drop); -+ printf("sock_tx_merge: %-14"PRIu64" ", lstack_stat->data.pkts.wakeup_stat.sock_tx_merge); -+ printf("accpet_fail: %-16"PRIu64" \n", lstack_stat->data.pkts.wakeup_stat.accept_fail); - } - - static void gazelle_print_lstack_stat_detail(struct gazelle_stack_dfx_data *lstack_stat, --- -2.33.0 - diff --git a/0334-mempool-fix-copy_mbuf_private.patch b/0334-mempool-fix-copy_mbuf_private.patch deleted file mode 100644 index 869e6d8953874ae814ceb711788d79a525ff36c0..0000000000000000000000000000000000000000 --- a/0334-mempool-fix-copy_mbuf_private.patch +++ /dev/null @@ -1,75 +0,0 @@ -From b189e23541622329d3df7cf95ecf20b2394e3539 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sun, 6 Apr 2025 16:02:40 +0800 -Subject: [PATCH] mempool: fix copy_mbuf_private - -Signed-off-by: Lemmy Huang ---- - src/common/dpdk_common.h | 18 +++++++++++------- - src/lstack/core/lstack_dpdk.c | 2 +- - 2 files changed, 12 insertions(+), 8 deletions(-) - -diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h -index cff193c..fca4aa3 100644 ---- a/src/common/dpdk_common.h -+++ b/src/common/dpdk_common.h -@@ -38,9 +38,11 @@ struct latency_timestamp { - uint16_t type; // latency type - }; - struct mbuf_private { -- /* struct pbuf_custom must at first */ -+ /* struct pbuf_custom must at first. do not copy in copy_mbuf_private() !!! */ - struct pbuf_custom pc; -- int stack_id; /* the stack to which buf belongs */ -+ /* the stack to which buf belongs. do not copy in copy_mbuf_private() !!! */ -+ int stack_id; -+ - struct latency_timestamp lt; - }; - -@@ -57,11 +59,16 @@ static __rte_always_inline struct mbuf_private *pbuf_to_private(const struct pbu - return mbuf_to_private(pbuf_to_mbuf(p)); - } - -+static __rte_always_inline void copy_mbuf_private(struct mbuf_private *dst, const struct mbuf_private *src) -+{ -+ rte_memcpy(&dst->lt, &src->lt, sizeof(struct latency_timestamp)); -+} -+ - /* NOTE!!! magic code, even the order. - * I wrote it carefully, and check the assembly. for example, there is 24 ins in A72, - * and if there is no cache miss, it only take less than 20 cycle(store pipe is the bottleneck). - */ --static __rte_always_inline void copy_mbuf(struct rte_mbuf *dst, struct rte_mbuf *src) -+static __rte_always_inline void copy_mbuf(struct rte_mbuf *dst, const struct rte_mbuf *src) - { - /* In the direction of tx, data is copied from lstack to ltran. It is necessary to judge whether - the length of data transmitted from lstack has been tampered with to prevent overflow -@@ -79,10 +86,7 @@ static __rte_always_inline void copy_mbuf(struct rte_mbuf *dst, struct rte_mbuf - uint8_t *src_data = rte_pktmbuf_mtod(src, void*); - rte_memcpy(dst_data, src_data, data_len); - -- // copy private date. -- dst_data = (uint8_t *)mbuf_to_private(dst); -- src_data = (uint8_t *)mbuf_to_private(src); -- rte_memcpy(dst_data, src_data, sizeof(struct mbuf_private)); -+ copy_mbuf_private(mbuf_to_private(dst), mbuf_to_private(src)); - } - - static __rte_always_inline void time_stamp_into_mbuf(uint32_t rx_count, struct rte_mbuf *buf[], uint64_t time_stamp) -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index 8f896c9..baba571 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -196,7 +196,7 @@ int32_t fill_mbuf_to_ring(int stack_id, struct rte_ring *ring, uint32_t mbuf_num - batch = LWIP_MIN(remain, RING_SIZE(VDEV_RX_QUEUE_SZ)); - - ret = mem_get_mbuf_bulk(stack_id, free_buf, batch, true); -- if (ret != 0) { -+ if (ret == 0) { - LSTACK_LOG(ERR, LSTACK, "cannot alloc mbuf for ring, count: %u ret=%d\n", batch, ret); - return -1; - } --- -2.33.0 - diff --git a/0335-socket-fix-connect-blocking.patch b/0335-socket-fix-connect-blocking.patch deleted file mode 100644 index eb9d21e82db1159eb53e91f576c436cfdb230556..0000000000000000000000000000000000000000 --- a/0335-socket-fix-connect-blocking.patch +++ /dev/null @@ -1,198 +0,0 @@ -From 3d17332feaa4104d614fb0ba72d29e56b4e87cf2 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Wed, 16 Apr 2025 09:56:46 +0800 -Subject: [PATCH] socket: fix connect blocking - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 17 +++++++++++------ - src/lstack/api/lstack_sockctl.c | 8 ++++---- - src/lstack/api/lstack_sockio.c | 14 +++++++------- - src/lstack/core/lstack_wait.c | 2 +- - src/lstack/include/lstack_epoll.h | 2 +- - 5 files changed, 24 insertions(+), 19 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 3940f43..ed6d2f0 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -814,12 +814,12 @@ void epoll_api_init(posix_api_t *api) - api->select_fn = lstack_select; - } - --bool sock_event_wait(struct lwip_sock *sock, bool noblocking) -+bool sock_event_wait(struct lwip_sock *sock, enum netconn_evt evt, bool noblocking) - { - bool rtc_mode = get_global_cfg_params()->stack_mode_rtc; - uint32_t start; - int timeout; -- unsigned pending; -+ unsigned pending = 0; - - if (!rtc_mode && noblocking) - return false; -@@ -829,6 +829,7 @@ bool sock_event_wait(struct lwip_sock *sock, bool noblocking) - } - if (!(sock->sk_wait->type & WAIT_BLOCK)) { - sock->sk_wait->type |= WAIT_BLOCK; -+ rte_wmb(); - } - - if (rtc_mode) { -@@ -840,13 +841,17 @@ bool sock_event_wait(struct lwip_sock *sock, bool noblocking) - timeout = sock->conn->recv_timeout == 0 ? -1 : sock->conn->recv_timeout; - start = sys_now(); - do { -- pending = sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_RCVPLUS, 0) | -+ pending = sock_event_hold_pending(sock, WAIT_BLOCK, evt, 0) | - sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0); -- if (pending) { -- return true; -+ if (pending != 0) { -+ break; - } - timeout = sock->sk_wait->timedwait_fn(sock->sk_wait, timeout, start); - } while (timeout != 0); - -- return false; -+ if (evt == NETCONN_EVT_SENDPLUS) { -+ /* remove WAIT_BLOCK type */ -+ sock->sk_wait->type &= ~WAIT_BLOCK; -+ } -+ return pending != 0; - } -diff --git a/src/lstack/api/lstack_sockctl.c b/src/lstack/api/lstack_sockctl.c -index 7ff7163..d1ef36a 100644 ---- a/src/lstack/api/lstack_sockctl.c -+++ b/src/lstack/api/lstack_sockctl.c -@@ -448,7 +448,7 @@ static int rpc_call_connect(int stack_id, int fd, const struct sockaddr *addr, s - - if (ret < 0 && errno == EINPROGRESS) { - struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn))) { -+ if (sock_event_wait(sock, NETCONN_EVT_SENDPLUS, netconn_is_nonblocking(sock->conn))) { - ret = 0; - } - } -@@ -607,7 +607,7 @@ static int stack_broadcast_accept4(int fd, struct sockaddr *addr, socklen_t *add - - min_sock = get_min_accept_sock(fd); - if (min_sock == NULL) { -- if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & SOCK_NONBLOCK))) { -+ if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, netconn_is_nonblocking(sock->conn) || (flags & SOCK_NONBLOCK))) { - min_sock = get_min_accept_sock(fd); - } - } -@@ -786,7 +786,7 @@ static int rtc_connect(int s, const struct sockaddr *name, socklen_t namelen) - ret = lwip_connect(s, name, namelen); - if (ret < 0 && errno == EINPROGRESS) { - struct lwip_sock *sock = lwip_get_socket(s); -- if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn))) { -+ if (sock_event_wait(sock, NETCONN_EVT_SENDPLUS, netconn_is_nonblocking(sock->conn))) { - ret = 0; - } - } -@@ -804,7 +804,7 @@ static int rtc_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int fla - - ret = lwip_accept4(s, addr, addrlen, flags); - if (ret < 0 && errno == EWOULDBLOCK) { -- if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & SOCK_NONBLOCK))) { -+ if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, netconn_is_nonblocking(sock->conn) || (flags & SOCK_NONBLOCK))) { - ret = lwip_accept4(s, addr, addrlen, flags); - } - } -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 89a6acb..438f1ce 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -1128,7 +1128,7 @@ ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, - /* TODO: support MSG_WAITALL */ - recvd = ioops.stack_tcp_read(sock, mem, len, flags, from, fromlen); - if (recvd < 0 && errno == EWOULDBLOCK) { -- if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { -+ if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { - recvd = ioops.stack_tcp_read(sock, mem, len, flags, from, fromlen); - } - } -@@ -1150,7 +1150,7 @@ ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, - msg.msg_namelen = (fromlen ? *fromlen : 0); - recvd = ioops.stack_udp_readmsg(sock, &msg, len, flags); - if (recvd < 0 && errno == EWOULDBLOCK) { -- if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { -+ if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { - recvd = ioops.stack_udp_readmsg(sock, &msg, len, flags); - } - } -@@ -1196,7 +1196,7 @@ ssize_t sockio_recvmsg(int fd, struct msghdr *msg, int flags) - case NETCONN_UDP: - recvd = ioops.stack_udp_readmsg(sock, msg, len, flags); - if (recvd < 0 && errno == EWOULDBLOCK) { -- if (sock_event_wait(sock, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { -+ if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { - recvd = ioops.stack_udp_readmsg(sock, msg, len, flags); - } - } -@@ -1233,7 +1233,7 @@ ssize_t sockio_sendto(int fd, const void *mem, size_t len, int flags, - ret = ioops.stack_tcp_write(sock, mem, len, flags); - if (ret < 0) { - if (errno == EWOULDBLOCK) { -- sock_event_wait(sock, true); -+ sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); - } - } else { - ioops.stack_tcp_send(sock); -@@ -1243,7 +1243,7 @@ ssize_t sockio_sendto(int fd, const void *mem, size_t len, int flags, - ret = ioops.stack_udp_write(sock, mem, len, flags, to, tolen); - if (ret < 0) { - if (errno == EWOULDBLOCK) { -- sock_event_wait(sock, true); -+ sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); - } - } else { - ioops.stack_udp_send(sock); -@@ -1284,7 +1284,7 @@ ssize_t sockio_sendmsg(int fd, const struct msghdr *msg, int flags) - ret = ioops.stack_tcp_write(sock, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags | write_more); - if (ret < 0) { - if (errno == EWOULDBLOCK) { -- sock_event_wait(sock, true); -+ sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); - } - break; - } -@@ -1302,7 +1302,7 @@ ssize_t sockio_sendmsg(int fd, const struct msghdr *msg, int flags) - ret = ioops.stack_udp_write(sock, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags | write_more, NULL, 0); - if (ret < 0) { - if (errno == EWOULDBLOCK) { -- sock_event_wait(sock, true); -+ sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); - } - break; - } -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -index 381290c..866e293 100644 ---- a/src/lstack/core/lstack_wait.c -+++ b/src/lstack/core/lstack_wait.c -@@ -421,7 +421,7 @@ unsigned sock_event_hold_pending(const struct lwip_sock *sock, - } - break; - case NETCONN_EVT_SENDPLUS: -- if (sock->sk_event.events & EPOLLOUT) { -+ if (sock->sk_event.events & EPOLLOUT || type & WAIT_BLOCK) { - if (len > 0 || - NETCONN_ALLOW_SEND(sock)) { - event = EPOLLOUT; -diff --git a/src/lstack/include/lstack_epoll.h b/src/lstack/include/lstack_epoll.h -index 655e178..99a7162 100644 ---- a/src/lstack/include/lstack_epoll.h -+++ b/src/lstack/include/lstack_epoll.h -@@ -23,6 +23,6 @@ void poll_destruct_wait(void); - - int lstack_epoll_close(int epfd); - void epoll_api_init(posix_api_t *api); --bool sock_event_wait(struct lwip_sock *sock, bool noblocking); -+bool sock_event_wait(struct lwip_sock *sock, enum netconn_evt evt, bool noblocking); - - #endif /* _GAZELLE_EPOLL_H_ */ --- -2.33.0 - diff --git a/0336-socket-fix-stack_tcp_read-do-not-recv_finish_burst.patch b/0336-socket-fix-stack_tcp_read-do-not-recv_finish_burst.patch deleted file mode 100644 index 9e7972ce534c5f4e8d490d776f6565102d1adb1c..0000000000000000000000000000000000000000 --- a/0336-socket-fix-stack_tcp_read-do-not-recv_finish_burst.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 062a2006981cd9918a3b698241fe1cd64b99fbdb Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Thu, 17 Apr 2025 14:52:26 +0800 -Subject: [PATCH] socket: fix stack_tcp_read do not recv_finish_burst - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockio.c | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 438f1ce..0ebd9e2 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -838,6 +838,14 @@ static ssize_t stack_tcp_read(struct lwip_sock *sock, char *data, size_t len, in - copied_total += buf_copy_len; - total_copy_len -= buf_copy_len; - mr->app_recvd_len += buf_copy_len; -+ -+ if (mr->app_queued_num >= RECV_EXTEND_CACHE_MAX || -+ mr->app_recvd_len >= RECV_EXTEND_CACHE_LEN) { -+ if (sock->lastdata.pbuf == NULL) { -+ mr->ops->recv_finish_burst(mr); -+ mr->app_queued_num = 0; -+ } -+ } - } - - while (total_copy_len > 0) { --- -2.33.0 - diff --git a/0337-tcp-add-GAZELLE_TCP_ASYNC_RECVD.patch b/0337-tcp-add-GAZELLE_TCP_ASYNC_RECVD.patch deleted file mode 100644 index d9127dc3853ab6125e605280194225b7537d749c..0000000000000000000000000000000000000000 --- a/0337-tcp-add-GAZELLE_TCP_ASYNC_RECVD.patch +++ /dev/null @@ -1,167 +0,0 @@ -From b928e5c8027272c75f46395aa2bef25962d844f3 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 18 Apr 2025 14:41:20 +0800 -Subject: [PATCH] tcp: add GAZELLE_TCP_ASYNC_RECVD fix mbuf OOM caused by - untimely sockio_peek_recv_free - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockio.c | 68 ++++++++++++++-------------------- - 1 file changed, 27 insertions(+), 41 deletions(-) - -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 0ebd9e2..46c8992 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -910,47 +910,34 @@ static ssize_t stack_tcp_read(struct lwip_sock *sock, char *data, size_t len, in - } - - --#define RECVD_UNCOMMITTED(msg) ((msg)->args[MSG_ARG_2].ul) --#define RECVD_CURR_SEQ(msg) ((msg)->args[MSG_ARG_3].ul) --#define RECVD_LAST_SEQ(msg) ((msg)->args[MSG_ARG_4].ul) -- --static inline bool rpc_commit_tcp_recvd(struct rpc_msg *recvmsg, unsigned long threshold) -+#if GAZELLE_TCP_ASYNC_RECVD -+#define RECVD_UNSUBMITED(msg) ((msg)->args[MSG_ARG_2].ul) -+static inline bool rpc_submit_tcp_recvd(struct rpc_msg *recvmsg, size_t threshold, size_t recvd) - { -- if (RECVD_UNCOMMITTED(recvmsg) >= threshold) { -- __atomic_add_fetch(&RECVD_CURR_SEQ(recvmsg), RECVD_UNCOMMITTED(recvmsg), __ATOMIC_RELEASE); -- RECVD_UNCOMMITTED(recvmsg) = 0; -+ RECVD_UNSUBMITED(recvmsg) += recvd; -+ if (RECVD_UNSUBMITED(recvmsg) >= threshold) { -+ RECVD_UNSUBMITED(recvmsg) = 0; - return true; - } - return false; - } - --#if TCP_RECV_AND_UPDATE --static inline unsigned long rpc_read_tcp_recvd(struct rpc_msg *recvmsg) --{ -- unsigned long curr_recvd_seq; -- unsigned long recvd; -- -- curr_recvd_seq = __atomic_load_n(&RECVD_CURR_SEQ(recvmsg), __ATOMIC_ACQUIRE); -- recvd = curr_recvd_seq - RECVD_LAST_SEQ(recvmsg); -- if (recvd > 0) { -- /* update last recvd seq */ -- RECVD_LAST_SEQ(recvmsg) = curr_recvd_seq; -- } -- return recvd; --} -- - static void callback_tcp_recvd(struct rpc_msg *recvmsg) - { - struct lwip_sock *sock = recvmsg->args[MSG_ARG_0].p; -- unsigned long recvd; -+ struct mbox_ring *mr; -+ u32_t recvd; - -- recvd = rpc_read_tcp_recvd(recvmsg); -- lwip_tcp_recvd(sock->conn, recvd, 0); -+ mr = &sock->conn->recvmbox->mring; -+ if (mr->flags & MBOX_FLAG_PEEK) { -+ sockio_peek_recv_free(mr, 0); -+ } - -+ recvd = lwip_netconn_get_recvd(sock->conn, 0, 0); -+ lwip_netconn_update_recvd(sock->conn, recvd); - recvmsg->result = recvd; - return; - } --#endif /* TCP_RECV_AND_UPDATE */ - - static inline int rpc_call_tcp_recvd(rpc_queue *queue, struct lwip_sock *sock, size_t recvd, int flags) - { -@@ -960,22 +947,23 @@ static inline int rpc_call_tcp_recvd(rpc_queue *queue, struct lwip_sock *sock, s - recvmsg->args[MSG_ARG_0].p = sock; - recvmsg->result = 0; - -- RECVD_UNCOMMITTED(recvmsg) += recvd; -- if (rpc_commit_tcp_recvd(recvmsg, TCP_WND_UPDATE_THRESHOLD << 1)) { -+ if (rpc_submit_tcp_recvd(recvmsg, TCP_WND >> 1, recvd)) { - rpc_async_call(queue, recvmsg, RPC_MSG_REUSE); - } -- - return 0; - } -+#endif /* GAZELLE_TCP_ASYNC_RECVD */ - - static void rtw_stack_tcp_recvd(struct lwip_sock *sock, ssize_t recvd, int flags) - { -+#if GAZELLE_TCP_ASYNC_RECVD - struct protocol_stack *stack = get_protocol_stack_by_id(sock->stack_id); - - if (recvd <= 0 || flags & MSG_PEEK) { - return; - } - rpc_call_tcp_recvd(&stack->rpc_queue, sock, recvd, flags); -+#endif /* GAZELLE_TCP_ASYNC_RECVD */ - } - - static void rtc_stack_tcp_recvd(struct lwip_sock *sock, ssize_t recvd, int flags) -@@ -1012,14 +1000,14 @@ static void callback_tcp_send(struct rpc_msg *sendmsg) - LSTACK_LOG(ERR, LSTACK, "tcp_output failed, sock %p, err %u\n", sock, err); - } - --#if TCP_RECV_AND_UPDATE -+#if GAZELLE_TCP_ASYNC_RECVD - struct rpc_msg *recvmsg; -- if (RECVD_UNCOMMITTED(sendmsg)) { -- RECVD_UNCOMMITTED(sendmsg) = 0; -+ if (RECVD_UNSUBMITED(sendmsg)) { -+ RECVD_UNSUBMITED(sendmsg) = 0; - recvmsg = sock_mbox_private_get(sock->conn->recvmbox); - callback_tcp_recvd(recvmsg); - } --#endif /* TCP_RECV_AND_UPDATE */ -+#endif /* GAZELLE_TCP_ASYNC_RECVD */ - - return; - } -@@ -1036,11 +1024,11 @@ static inline int rpc_call_tcp_send(rpc_queue *queue, struct lwip_sock *sock) - sendmsg->args[MSG_ARG_0].p = sock; - sendmsg->args[MSG_ARG_1].p = mem_thread_migrate_get(sock->stack_id); - --#if TCP_RECV_AND_UPDATE -+#if GAZELLE_TCP_ASYNC_RECVD - struct rpc_msg *recvmsg; - recvmsg = sock_mbox_private_get(sock->conn->recvmbox); -- RECVD_UNCOMMITTED(sendmsg) = rpc_commit_tcp_recvd(recvmsg, TCP_WND_UPDATE_THRESHOLD); --#endif /* TCP_RECV_AND_UPDATE */ -+ RECVD_UNSUBMITED(sendmsg) = rpc_submit_tcp_recvd(recvmsg, TCP_WND >> 2, 0); -+#endif /* GAZELLE_TCP_ASYNC_RECVD */ - - rpc_async_call(queue, sendmsg, RPC_MSG_REUSE); - return 0; -@@ -1140,11 +1128,9 @@ ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, - recvd = ioops.stack_tcp_read(sock, mem, len, flags, from, fromlen); - } - } --#if TCP_RECV_AND_UPDATE - if (recvd > 0) { - ioops.stack_tcp_recvd(sock, recvd, flags); - } --#endif /* TCP_RECV_AND_UPDATE */ - break; - case NETCONN_UDP: - vec.iov_base = mem; -@@ -1412,11 +1398,11 @@ static int sockio_mbox_init(struct lwip_sock *sock) - switch (NETCONN_TYPE(sock->conn)) { - case NETCONN_TCP: - ret = sock_mbox_private_init(sendmbox, callback_tcp_send); --#if TCP_RECV_AND_UPDATE -+#if GAZELLE_TCP_ASYNC_RECVD - if (sys_mbox_valid(&recvmbox)) { - ret |= sock_mbox_private_init(recvmbox, callback_tcp_recvd); - } --#endif /* TCP_RECV_AND_UPDATE */ -+#endif /* GAZELLE_TCP_ASYNC_RECVD */ - break; - case NETCONN_UDP: - ret = sock_mbox_private_init(sendmbox, callback_udp_send); --- -2.33.0 - diff --git a/0338-socket-fix-tcp-closed.patch b/0338-socket-fix-tcp-closed.patch deleted file mode 100644 index 41f9dcd0a913198a22957ffc70d41891974486c9..0000000000000000000000000000000000000000 --- a/0338-socket-fix-tcp-closed.patch +++ /dev/null @@ -1,95 +0,0 @@ -From 933f0e59f77fe450ab255c07c9f4b994de4be11f Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sat, 19 Apr 2025 21:20:52 +0800 -Subject: [PATCH] socket: fix tcp closed - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockio.c | 48 ++++++++++++++-------------------- - 1 file changed, 19 insertions(+), 29 deletions(-) - -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 46c8992..0bd31ab 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -817,7 +817,7 @@ static ssize_t stack_tcp_read(struct lwip_sock *sock, char *data, size_t len, in - struct mbox_ring *mr = &sock->conn->recvmbox->mring; - struct pbuf **extcache_list; - err_t err = ERR_OK; -- struct pbuf *p; -+ struct pbuf *p = NULL; - - uint32_t buf_copy_len; - uint32_t total_copy_len = len; -@@ -832,50 +832,40 @@ static ssize_t stack_tcp_read(struct lwip_sock *sock, char *data, size_t len, in - extcache_list = (struct pbuf **)&mr->st_obj; - } - -- if (sock->lastdata.pbuf != NULL) { -- // TODO: support MSG_PEEK -- buf_copy_len = pbuf_copy_and_free(&sock->lastdata.pbuf, extcache_list, data, total_copy_len); -- copied_total += buf_copy_len; -- total_copy_len -= buf_copy_len; -- mr->app_recvd_len += buf_copy_len; -- -- if (mr->app_queued_num >= RECV_EXTEND_CACHE_MAX || -- mr->app_recvd_len >= RECV_EXTEND_CACHE_LEN) { -- if (sock->lastdata.pbuf == NULL) { -- mr->ops->recv_finish_burst(mr); -- mr->app_queued_num = 0; -- } -- } -- } -- - while (total_copy_len > 0) { -- if (mr->ops->recv_start_burst(mr, (void **)&p, 1) == 0) { -- if (unlikely(sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0))) { -- err = ERR_CONN; -- } else { -- err = ERR_WOULDBLOCK; -+ if (sock->lastdata.pbuf == NULL) { -+ if (mr->ops->recv_start_burst(mr, (void **)&sock->lastdata.pbuf, 1) == 0) { -+ if (unlikely(sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0))) { -+ err = ERR_CONN; -+ } else { -+ err = ERR_WOULDBLOCK; -+ } -+ break; - } -- break; -+ mr->app_queued_num++; -+ SOCK_WAIT_STAT(sock->sk_wait, app_read_cnt, 1); - } -- mr->app_queued_num++; -- if (unlikely(lwip_netconn_is_err_msg(p, &err))) { -+ -+ if (unlikely(lwip_netconn_is_err_msg(sock->lastdata.pbuf, &err))) { - API_EVENT(sock->conn, NETCONN_EVT_RCVMINUS, copied_total); - break; - } - -- SOCK_WAIT_STAT(sock->sk_wait, app_read_cnt, 1); -- if (get_protocol_stack_group()->latency_start) -+ if (get_protocol_stack_group()->latency_start) { -+ p = sock->lastdata.pbuf; - calculate_lstack_latency(sock->stack_id, &p, 1, GAZELLE_LATENCY_READ_APP_CALL, sys_now_us()); -+ } - -- sock->lastdata.pbuf = p; - // TODO: support MSG_PEEK - buf_copy_len = pbuf_copy_and_free(&sock->lastdata.pbuf, extcache_list, data + copied_total, total_copy_len); - copied_total += buf_copy_len; - total_copy_len -= buf_copy_len; - mr->app_recvd_len += buf_copy_len; - -- if (get_protocol_stack_group()->latency_start) -+ if (get_protocol_stack_group()->latency_start) { - calculate_lstack_latency(sock->stack_id, &p, 1, GAZELLE_LATENCY_READ_LSTACK, 0); -+ p = NULL; -+ } - - if (mr->app_queued_num >= RECV_EXTEND_CACHE_MAX || - mr->app_recvd_len >= RECV_EXTEND_CACHE_LEN) { --- -2.33.0 - diff --git a/0339-socket-fix-sk_wait-cannot-be-interrupted-by-signals.patch b/0339-socket-fix-sk_wait-cannot-be-interrupted-by-signals.patch deleted file mode 100644 index 27c3a6e179ffb0efa0a3805df4e14658f437d11f..0000000000000000000000000000000000000000 --- a/0339-socket-fix-sk_wait-cannot-be-interrupted-by-signals.patch +++ /dev/null @@ -1,139 +0,0 @@ -From 56f8d17ddf0a8668d87d2060f97f6c177bc5ce3d Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sun, 20 Apr 2025 12:54:06 +0800 -Subject: [PATCH] socket: fix sk_wait cannot be interrupted by signals - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 19 +++++++++++++------ - src/lstack/core/lstack_wait.c | 8 ++++---- - src/lstack/include/lstack_wait.h | 2 +- - 3 files changed, 18 insertions(+), 11 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index ed6d2f0..19cc9d6 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -40,13 +40,16 @@ static int rtc_sock_wait_timedwait(struct sock_wait *sk_wait, int timeout, uint3 - - if (timeout > 0 && timeout <= (int)(sys_now() - start)) { - timeout = 0; -+ } else if (timeout < 0) { -+ errno = 0; - } - return timeout; - } - - static int rtw_sock_wait_timedwait(struct sock_wait *sk_wait, int timeout, uint32_t start) - { -- return sys_mutex_timedlock_internal(&sk_wait->mutex, timeout); -+ /* when sem interrupted by signals, errno = EINTR */ -+ return sys_sem_wait_internal(&sk_wait->sem, timeout); - } - - static void rtc_epoll_notify_event(struct sock_wait *sk_wait, struct sock_event *sk_event, -@@ -83,7 +86,7 @@ static void rtw_epoll_notify_event(struct sock_wait *sk_wait, struct sock_event - } - rte_spinlock_unlock(&sk_wait->epcb.lock); - -- sys_mutex_unlock_internal(&sk_wait->mutex); -+ sys_sem_signal_internal(&sk_wait->sem); - } - - static void rtw_epoll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending) -@@ -112,7 +115,7 @@ static void rtw_poll_notify_event(struct sock_wait *sk_wait, struct sock_event * - return; - } - #endif /* SOCK_WAIT_BATCH_NOTIFY */ -- sys_mutex_unlock_internal(&sk_wait->mutex); -+ sys_sem_signal_internal(&sk_wait->sem); - } - static void rtw_poll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending) - { -@@ -433,7 +436,7 @@ int lstack_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int t - } - - timeout = sk_wait->timedwait_fn(sk_wait, timeout, start); -- } while (timeout != 0); -+ } while (timeout > 0 || (timeout < 0 && errno == 0)); - - sk_wait->stat.app_events += lwip_num; - sk_wait->stat.kernel_events += kernel_num; -@@ -706,7 +709,7 @@ int lstack_poll(struct pollfd *fds, nfds_t nfds, int timeout) - } - - timeout = sk_wait->timedwait_fn(sk_wait, timeout, start); -- } while (timeout != 0); -+ } while (timeout > 0 || (timeout < 0 && errno == 0)); - - sk_wait->stat.app_events += lwip_num; - sk_wait->stat.kernel_events += kernel_num; -@@ -847,7 +850,11 @@ bool sock_event_wait(struct lwip_sock *sock, enum netconn_evt evt, bool noblocki - break; - } - timeout = sock->sk_wait->timedwait_fn(sock->sk_wait, timeout, start); -- } while (timeout != 0); -+ } while (timeout > 0 || (timeout < 0 && errno == 0)); -+ -+ if (errno == ETIMEDOUT) { -+ errno = EAGAIN; -+ } - - if (evt == NETCONN_EVT_SENDPLUS) { - /* remove WAIT_BLOCK type */ -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -index 866e293..816f340 100644 ---- a/src/lstack/core/lstack_wait.c -+++ b/src/lstack/core/lstack_wait.c -@@ -208,7 +208,7 @@ void* kernel_wait_thread(void *arg) - if (sk_wait->type == WAIT_CLOSE) - continue; - rte_atomic16_set(&sk_wait->kernel_pending, true); -- sys_mutex_unlock_internal(&sk_wait->mutex); -+ sys_sem_signal_internal(&sk_wait->sem); - } - usleep(KERNEL_EVENT_WAIT_US); - } -@@ -285,7 +285,7 @@ int sock_wait_common_init(struct sock_wait *sk_wait) - { - sk_wait->lwip_nfds = 0; - sk_wait->kernel_nfds = 0; -- sys_mutex_new_internal(&sk_wait->mutex); -+ sys_sem_new_internal(&sk_wait->sem, 0); - - #if SOCK_WAIT_BATCH_NOTIFY - for (int i = 0; i < PROTOCOL_STACK_MAX; ++i) { -@@ -318,7 +318,7 @@ void sock_wait_common_free(struct sock_wait *sk_wait) - #endif /* SOCK_WAIT_BATCH_NOTIFY */ - - sock_wait_group_del(sk_wait); -- sys_mutex_free_internal(&sk_wait->mutex); -+ sys_sem_free_internal(&sk_wait->sem); - } - - int sock_wait_kernel_init(struct sock_wait *sk_wait, int epfd, int stack_num) -@@ -543,7 +543,7 @@ unsigned lwip_wait_foreach_notify(int stack_id) - - sock_wait_foreach_event(sk_wait, stack_id); - -- sys_mutex_unlock_internal(&sk_wait->mutex); -+ sys_sem_signal_internal(&sk_wait->sem); - count++; - } - return count; -diff --git a/src/lstack/include/lstack_wait.h b/src/lstack/include/lstack_wait.h -index 306c6a4..a1d35dd 100644 ---- a/src/lstack/include/lstack_wait.h -+++ b/src/lstack/include/lstack_wait.h -@@ -98,7 +98,7 @@ struct sock_wait { - /* kernel event flag */ - rte_atomic16_t kernel_pending; - /* run-to-wakeup blocking lock */ -- struct sys_mutex mutex; -+ struct sys_sem sem; /* Do not use mutex, as it cannot be interrupted by signals */ - - union { - struct epoll_cb epcb; --- -2.33.0 - diff --git a/0340-mempool-modify-mbuf-num-and-rpc_msg-num.patch b/0340-mempool-modify-mbuf-num-and-rpc_msg-num.patch deleted file mode 100644 index f560ef067eea7b532d41e1ae51b6c0af07c84b16..0000000000000000000000000000000000000000 --- a/0340-mempool-modify-mbuf-num-and-rpc_msg-num.patch +++ /dev/null @@ -1,98 +0,0 @@ -From 243f24d1a2123537bc4b280064f32d38af450826 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sun, 20 Apr 2025 20:06:24 +0800 -Subject: [PATCH] mempool: modify mbuf num and rpc_msg num - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_dpdk.c | 5 +++-- - src/lstack/core/lstack_mempool.c | 24 +++++++++++++----------- - src/lstack/include/lstack_mempool.h | 2 +- - 3 files changed, 17 insertions(+), 14 deletions(-) - -diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c -index baba571..ddcd5ae 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -901,8 +901,9 @@ 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); -+ return (MBUFPOOL_RESERVE_NUM + MBUFPOOL_CACHE_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) -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index bb47830..b03c3ef 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -450,20 +450,15 @@ static const struct mempool_ops mbuf_mp_ops = { - - static struct rte_mempool *mbuf_pool_create(int stack_id, unsigned numa_id) - { -- struct cfg_params *cfg_params = get_global_cfg_params(); - char name[RTE_MEMPOOL_NAMESIZE]; - struct rte_mempool *pool; -- uint32_t total_conn_mbufs, total_nic_mbufs, total_mbufs; -+ uint32_t total_bufs; - uint16_t private_size; - uint16_t xdp_metadata = 0; - -- total_conn_mbufs = cfg_params->mbuf_count_per_conn * cfg_params->tcp_conn_count; -- total_nic_mbufs = cfg_params->rxqueue_size + cfg_params->txqueue_size; -- -- total_mbufs = (total_conn_mbufs / cfg_params->num_queue) + total_nic_mbufs + MBUFPOOL_RESERVE_NUM; -- /* limit mbuf max num based on the dpdk capability */ -- if (total_mbufs > MBUFPOOL_MAX_NUM) { -- LSTACK_LOG(ERR, LSTACK, "total_mbufs %u out of the dpdk mbuf_pool range\n", total_mbufs); -+ total_bufs = dpdk_pktmbuf_mempool_num(); -+ if (total_bufs > MEMPOOL_MAX_NUM) { -+ LSTACK_LOG(ERR, LSTACK, "total_bufs %u out of the dpdk mempool range\n", total_bufs); - return NULL; - } - -@@ -474,7 +469,7 @@ static struct rte_mempool *mbuf_pool_create(int stack_id, unsigned numa_id) - } - private_size = RTE_ALIGN(sizeof(struct mbuf_private) + xdp_metadata, RTE_CACHE_LINE_SIZE); - -- pool = mbuf_mp_ops.create(name, total_mbufs, MBUFPOOL_CACHE_NUM, private_size, MBUF_DATA_SIZE, numa_id); -+ pool = mbuf_mp_ops.create(name, total_bufs, MBUFPOOL_CACHE_NUM, private_size, MBUF_DATA_SIZE, numa_id); - if (pool == NULL) { - LSTACK_LOG(ERR, LSTACK, "rte_pktmbuf_pool_create %s failed, rte_errno %d\n", name, rte_errno); - return NULL; -@@ -487,7 +482,14 @@ static struct rte_mempool *rpc_pool_create(int stack_id, unsigned numa_id) - { - char name [RTE_MEMPOOL_NAMESIZE]; - struct rte_mempool *pool; -- uint32_t total_bufs = get_global_cfg_params()->rpc_msg_max; -+ uint32_t total_bufs; -+ -+ total_bufs = MEMPOOL_CACHE_NUM + BUF_CACHE_MIN_NUM + -+ (get_global_cfg_params()->rpc_msg_max / get_global_cfg_params()->num_queue); -+ if (total_bufs > MEMPOOL_MAX_NUM) { -+ LSTACK_LOG(ERR, LSTACK, "total_bufs %u out of the dpdk mempool range\n", total_bufs); -+ return NULL; -+ } - - SYS_FORMAT_NAME(name, RTE_MEMPOOL_NAMESIZE, "%s_%hu", "rpc_pool", stack_id); - -diff --git a/src/lstack/include/lstack_mempool.h b/src/lstack/include/lstack_mempool.h -index bd170bb..131029e 100644 ---- a/src/lstack/include/lstack_mempool.h -+++ b/src/lstack/include/lstack_mempool.h -@@ -36,7 +36,7 @@ - /* DPDK limit ring head-tail distance in rte_ring_init. - * Max value is RTE_RING_SZ_MASK / HTD_MAX_DEF, RTE_RING_SZ_MASK is 0x7fffffff, HTD_MAX_DEF is 8. - */ --#define MBUFPOOL_MAX_NUM 0xfffffff -+#define MEMPOOL_MAX_NUM 0xfffffff - - #define MBUFPOOL_CACHE_NUM LWIP_MIN(NIC_QUEUE_SIZE_MAX >> 1, RTE_MEMPOOL_CACHE_MAX_SIZE) - #define MBUFPOOL_RESERVE_NUM (NIC_QUEUE_SIZE_MAX + MBUFPOOL_CACHE_NUM) --- -2.33.0 - diff --git a/0341-mempool-fix-mbox_ring-free-not-call-recv_finish_burs.patch b/0341-mempool-fix-mbox_ring-free-not-call-recv_finish_burs.patch deleted file mode 100644 index 86953951813a60d82f30d7563e788a7edd3362f1..0000000000000000000000000000000000000000 --- a/0341-mempool-fix-mbox_ring-free-not-call-recv_finish_burs.patch +++ /dev/null @@ -1,125 +0,0 @@ -From 532f3450a0b4212e03636c05593c05a50e95914d Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 21 Apr 2025 14:42:02 +0800 -Subject: [PATCH] mempool: fix mbox_ring free not call recv_finish_burst - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockio.c | 16 ++++++++++++++-- - src/lstack/include/lstack_lockless_queue.h | 8 ++++---- - src/lstack/include/lstack_sockio.h | 2 +- - src/lstack/include/mbox_ring.h | 8 +++++--- - 4 files changed, 24 insertions(+), 10 deletions(-) - -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 0bd31ab..66e84d2 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -1410,9 +1410,11 @@ static int sockio_mbox_init(struct lwip_sock *sock) - return ret; - } - --bool sockio_mbox_pending(const struct lwip_sock *sock) -+bool sockio_mbox_pending(struct lwip_sock *sock) - { -- struct rpc_msg *msg; -+ const struct rpc_msg *msg; -+ const struct mbox_ring *mr; -+ err_t err; - - if (POSIX_IS_CLOSED(sock)) - return false; -@@ -1428,6 +1430,16 @@ bool sockio_mbox_pending(const struct lwip_sock *sock) - if (msg != NULL && !lockless_queue_node_is_poped(&msg->queue_node)) { - return true; - } -+ -+ /* PEEK lastdata is only used to mark the last read location and not for releasing. -+ * all peek bufs should free after pk_ring_dequeue_burst. */ -+ mr = &sock->conn->recvmbox->mring; -+ if (mr->flags & MBOX_FLAG_PEEK && mr->flags & MBOX_FLAG_TCP) { -+ if (sock->lastdata.pbuf != NULL && -+ !lwip_netconn_is_err_msg(sock->lastdata.pbuf, &err)) { -+ sock->lastdata.pbuf = NULL; -+ } -+ } - } - - return false; -diff --git a/src/lstack/include/lstack_lockless_queue.h b/src/lstack/include/lstack_lockless_queue.h -index bec2564..4f9b37b 100644 ---- a/src/lstack/include/lstack_lockless_queue.h -+++ b/src/lstack/include/lstack_lockless_queue.h -@@ -33,7 +33,7 @@ static inline void lockless_queue_node_set_poped(lockless_queue_node *node) - node->next = node; - } - --static inline bool lockless_queue_node_is_poped(lockless_queue_node *node) -+static inline bool lockless_queue_node_is_poped(const lockless_queue_node *node) - { - return node->next == node; - } -@@ -60,18 +60,18 @@ static inline void lockless_queue_init(lockless_queue *queue) - queue->stub.next = NULL; - } - --static inline bool lockless_queue_empty(lockless_queue *queue) -+static inline bool lockless_queue_empty(const lockless_queue *queue) - { - return (queue->head == queue->tail) && (queue->tail == &queue->stub); - } - --static inline int32_t lockless_queue_count(lockless_queue *queue) -+static inline int32_t lockless_queue_count(const lockless_queue *queue) - { - if (lockless_queue_empty(queue)) { - return 0; - } - -- lockless_queue_node *tail = queue->tail; -+ const lockless_queue_node *tail = queue->tail; - if (tail == &queue->stub) { - tail = queue->stub.next; - } -diff --git a/src/lstack/include/lstack_sockio.h b/src/lstack/include/lstack_sockio.h -index f4e5e99..265d620 100644 ---- a/src/lstack/include/lstack_sockio.h -+++ b/src/lstack/include/lstack_sockio.h -@@ -32,7 +32,7 @@ ssize_t sockio_writev(int fd, const struct iovec *iov, int iovcnt); - - - void sockio_ops_init(void); --bool sockio_mbox_pending(const struct lwip_sock *sock); -+bool sockio_mbox_pending(struct lwip_sock *sock); - - /* just for lwip */ - int do_lwip_init_sock(int fd); -diff --git a/src/lstack/include/mbox_ring.h b/src/lstack/include/mbox_ring.h -index f6acdef..2e3ac6a 100644 ---- a/src/lstack/include/mbox_ring.h -+++ b/src/lstack/include/mbox_ring.h -@@ -84,6 +84,9 @@ void mbox_ring_common_free(struct mbox_ring *mr) - obj = mr->ops->pop_tail(mr, NULL); - if (obj != NULL) - mr->obj_free_fn(mr, obj, true); -+ -+ if (mr->flags & MBOX_FLAG_RECV) -+ mr->ops->recv_finish_burst(mr); - while (true) { - if (mr->ops->dequeue_burst(mr, &obj, 1) == 0) - break; -@@ -479,9 +482,8 @@ static inline - void pk_ring_destroy(struct mbox_ring *mr) - { - void *obj; -- while (mr->ops->recv_start_burst(mr, &obj, 1) > 0) { -- mr->ops->recv_finish_burst(mr); -- } -+ while (mr->ops->recv_start_burst(mr, &obj, 1) > 0) { } -+ mr->ops->recv_finish_burst(mr); - return; - } - --- -2.33.0 - diff --git a/0342-mempool-mem_get_rpc-add-reserve-limit.patch b/0342-mempool-mem_get_rpc-add-reserve-limit.patch deleted file mode 100644 index 49c96f450c9ce8a3075e58405d47f3581a96bae8..0000000000000000000000000000000000000000 --- a/0342-mempool-mem_get_rpc-add-reserve-limit.patch +++ /dev/null @@ -1,363 +0,0 @@ -From 5ce675c15ae4312d115686ce6f6ac7fb322b6f10 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 22 Apr 2025 15:03:00 +0800 -Subject: [PATCH] mempool: mem_get_rpc add reserve limit - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockctl.c | 24 ++++++++-------- - src/lstack/api/lstack_sockio.c | 2 +- - src/lstack/core/lstack_control_plane.c | 4 +-- - src/lstack/core/lstack_mempool.c | 37 +++++++++++++++++-------- - src/lstack/core/lstack_protocol_stack.c | 2 +- - src/lstack/core/lstack_thread_rpc.c | 10 +++---- - src/lstack/include/lstack_mempool.h | 3 +- - src/lstack/include/lstack_thread_rpc.h | 2 +- - 8 files changed, 49 insertions(+), 35 deletions(-) - -diff --git a/src/lstack/api/lstack_sockctl.c b/src/lstack/api/lstack_sockctl.c -index d1ef36a..f53b4cd 100644 ---- a/src/lstack/api/lstack_sockctl.c -+++ b/src/lstack/api/lstack_sockctl.c -@@ -60,7 +60,7 @@ static void callback_setsockopt(struct rpc_msg *msg) - static int rpc_call_getpeername(int stack_id, int fd, struct sockaddr *addr, socklen_t *addrlen) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_getpeername); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_getpeername); - if (msg == NULL) { - return -1; - } -@@ -75,7 +75,7 @@ static int rpc_call_getpeername(int stack_id, int fd, struct sockaddr *addr, soc - static int rpc_call_getsockname(int stack_id, int fd, struct sockaddr *addr, socklen_t *addrlen) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_getsockname); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_getsockname); - if (msg == NULL) { - return -1; - } -@@ -90,7 +90,7 @@ static int rpc_call_getsockname(int stack_id, int fd, struct sockaddr *addr, soc - static int rpc_call_getsockopt(int stack_id, int fd, int level, int optname, void *optval, socklen_t *optlen) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_getsockopt); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_getsockopt); - if (msg == NULL) { - return -1; - } -@@ -107,7 +107,7 @@ static int rpc_call_getsockopt(int stack_id, int fd, int level, int optname, voi - static int rpc_call_setsockopt(int stack_id, int fd, int level, int optname, const void *optval, socklen_t optlen) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_setsockopt); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_setsockopt); - if (msg == NULL) { - return -1; - } -@@ -169,7 +169,7 @@ static void callback_socket(struct rpc_msg *msg) - static int rpc_call_socket(int stack_id, int domain, int type, int protocol) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_socket); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, true, callback_socket); - if (msg == NULL) { - return -1; - } -@@ -221,7 +221,7 @@ static void callback_shutdown(struct rpc_msg *msg) - static int rpc_call_close(int stack_id, int fd) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_close); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_close); - if (msg == NULL) { - return -1; - } -@@ -234,7 +234,7 @@ static int rpc_call_close(int stack_id, int fd) - static int rpc_call_shutdown(int stack_id, int fd, int how) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_shutdown); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_shutdown); - if (msg == NULL) { - return -1; - } -@@ -256,7 +256,7 @@ static void callback_bind(struct rpc_msg *msg) - static int rpc_call_bind(int stack_id, int fd, const struct sockaddr *addr, socklen_t addrlen) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_bind); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_bind); - if (msg == NULL) { - return -1; - } -@@ -289,7 +289,7 @@ static void callback_listen(struct rpc_msg *msg) - static int rpc_call_listen(int stack_id, int s, int backlog) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_listen); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_listen); - if (msg == NULL) { - return -1; - } -@@ -374,7 +374,7 @@ static void callback_create_shadow_fd(struct rpc_msg *msg) - static int rpc_call_shadow_fd(int stack_id, int fd, const struct sockaddr *addr, socklen_t addrlen) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_create_shadow_fd); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_create_shadow_fd); - if (msg == NULL) { - return -1; - } -@@ -407,7 +407,7 @@ static void callback_accept(struct rpc_msg *msg) - static int rpc_call_accept(int stack_id, int fd, struct sockaddr *addr, socklen_t *addrlen, int flags) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_accept); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_accept); - if (msg == NULL) { - return -1; - } -@@ -431,7 +431,7 @@ static void callback_connect(struct rpc_msg *msg) - static int rpc_call_connect(int stack_id, int fd, const struct sockaddr *addr, socklen_t addrlen) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_connect); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_connect); - if (msg == NULL) { - return -1; - } -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 66e84d2..9eafc22 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -143,7 +143,7 @@ static void sock_mbox_private_free(struct mbox_ring *mr) - - static int sock_mbox_private_init(sys_mbox_t mb, rpc_func_t func) - { -- struct rpc_msg *msg = rpc_msg_alloc(get_protocol_stack()->stack_idx, func); -+ struct rpc_msg *msg = rpc_msg_alloc(get_protocol_stack()->stack_idx, true, func); - if (msg == NULL) - return -1; - -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 9d9e012..6ad0192 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -432,7 +432,7 @@ static void thread_register_phase2(struct rpc_msg *msg) - static int rpc_call_thread_regphase1(int stack_id, void *conn) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, thread_register_phase1); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, thread_register_phase1); - if (msg == NULL) { - return -1; - } -@@ -443,7 +443,7 @@ static int rpc_call_thread_regphase1(int stack_id, void *conn) - static int rpc_call_thread_regphase2(int stack_id, void *conn) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, thread_register_phase2); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, thread_register_phase2); - if (msg == NULL) { - return -1; - } -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index b03c3ef..00b299a 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -67,16 +67,24 @@ struct rte_mempool *mem_get_rpc_pool(int stack_id) - - unsigned mem_stack_mbuf_pool_count(int stack_id) - { -- struct mem_stack *ms = mem_stack_get(stack_id); -+ const struct mem_stack *ms = mem_stack_get(stack_id); - return rte_mempool_avail_count(ms->mbuf_pool); - } - - unsigned mem_stack_rpc_pool_count(int stack_id) - { -- struct mem_stack *ms = mem_stack_get(stack_id); -+ const struct mem_stack *ms = mem_stack_get(stack_id); - return rte_mempool_avail_count(ms->rpc_pool); - } - -+static inline unsigned mem_stack_pool_ring_count(const struct rte_mempool *pool) -+{ -+ /* don't use rte_mempool_avail_count, it traverse cpu local cache, -+ * when RTE_MAX_LCORE is too large, it's time-consuming -+ */ -+ return rte_ring_count(pool->pool_data); -+} -+ - static inline bool mem_thread_group_in_used(const struct mem_thread_group *mt_grooup, uint32_t timeout) - { - return mt_grooup->used_flag || -@@ -484,8 +492,7 @@ static struct rte_mempool *rpc_pool_create(int stack_id, unsigned numa_id) - struct rte_mempool *pool; - uint32_t total_bufs; - -- total_bufs = MEMPOOL_CACHE_NUM + BUF_CACHE_MIN_NUM + -- (get_global_cfg_params()->rpc_msg_max / get_global_cfg_params()->num_queue); -+ total_bufs = RPCPOOL_RESERVE_NUM + MEMP_NUM_SYS_MBOX; - if (total_bufs > MEMPOOL_MAX_NUM) { - LSTACK_LOG(ERR, LSTACK, "total_bufs %u out of the dpdk mempool range\n", total_bufs); - return NULL; -@@ -695,7 +702,7 @@ void mem_mbuf_migrate_enqueue(struct mem_thread *mt, unsigned n) - return; - - /* no sufficient mbuf */ -- if (rte_ring_count(ms->mbuf_pool->pool_data) < MBUFPOOL_RESERVE_NUM) { -+ if (mem_stack_pool_ring_count(ms->mbuf_pool) < MBUFPOOL_RESERVE_NUM) { - mem_thread_manager_flush_all(); - mt->stk_migrate_count = 0; - return; -@@ -780,7 +787,8 @@ static unsigned pool_get_bulk_with_cache(const struct mempool_ops *pool_ops, - /* get from the pool */ - ret = pool_ops->get_bulk(pool, obj_table, n); - if (unlikely(ret == 0)) { -- LSTACK_LOG(ERR, LSTACK, "pool %s get_bulk failed, n %u\n", pool->name, n); -+ LSTACK_LOG(ERR, LSTACK, "pool %s get_bulk failed, n %u, count %u\n", -+ pool->name, n, mem_stack_pool_ring_count(pool)); - return 0; - } - -@@ -796,7 +804,8 @@ static unsigned pool_get_bulk_with_cache(const struct mempool_ops *pool_ops, - - ret = pool_ops->get_bulk(pool, &cache->objs[cache->head], get_count); - if (unlikely(ret == 0)) { -- LSTACK_LOG(ERR, LSTACK, "pool %s get_bulk failed, n %u\n", pool->name, get_count); -+ LSTACK_LOG(ERR, LSTACK, "pool %s get_bulk failed, n %u, count %u\n", -+ pool->name, get_count, mem_stack_pool_ring_count(pool)); - } else { - cache->head += get_count; - } -@@ -839,13 +848,20 @@ static void pool_put_bulk_with_cache(const struct mempool_ops *pool_ops, - } - - --void *mem_get_rpc(int stack_id) -+void *mem_get_rpc(int stack_id, bool reserve) - { - struct mem_stack *ms = mem_stack_get(stack_id); - struct mem_thread *mt = mem_thread_get(stack_id); - unsigned ret; - void *obj; - -+ if (reserve) { -+ if (mem_stack_pool_ring_count(ms->rpc_pool) < RPCPOOL_RESERVE_NUM) { -+ mem_thread_manager_flush_all(); -+ return NULL; -+ } -+ } -+ - if (mt == NULL) { - ret = mem_mp_ops.get_bulk(ms->rpc_pool, &obj, 1); - } else { -@@ -887,10 +903,7 @@ unsigned mem_get_mbuf_bulk(int stack_id, struct rte_mbuf **mbuf_table, unsigned - } - - if (reserve) { -- /* don't use rte_mempool_avail_count, it traverse cpu local cache, -- * when RTE_MAX_LCORE is too large, it's time-consuming -- */ -- if (rte_ring_count(ms->mbuf_pool->pool_data) < MBUFPOOL_RESERVE_NUM + n) { -+ if (mem_stack_pool_ring_count(ms->mbuf_pool) < MBUFPOOL_RESERVE_NUM + n) { - mem_thread_manager_flush_all(); - return 0; - } -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index c07d8e7..d375ecc 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -750,7 +750,7 @@ static void stack_exit_by_rpc(struct rpc_msg *msg) - static int rpc_call_stack_exit(int stack_id) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, stack_exit_by_rpc); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, stack_exit_by_rpc); - if (msg == NULL) { - return -1; - } -diff --git a/src/lstack/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index 84e5814..6bf83d0 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -41,11 +41,11 @@ static void rpc_msg_init(struct rpc_msg *msg, rpc_func_t func) - lockless_queue_node_set_poped(&msg->queue_node); - } - --struct rpc_msg *rpc_msg_alloc(int stack_id, rpc_func_t func) -+struct rpc_msg *rpc_msg_alloc(int stack_id, bool reserve, rpc_func_t func) - { - struct rpc_msg *msg; - -- msg = mem_get_rpc(stack_id); -+ msg = mem_get_rpc(stack_id, reserve); - if (unlikely(msg == NULL)) { - g_rpc_stats.call_alloc_fail++; - return NULL; -@@ -152,7 +152,7 @@ static void callback_arp(struct rpc_msg *msg) - int rpc_call_arp(int stack_id, void *mbuf) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_arp); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_arp); - if (msg == NULL) { - return -1; - } -@@ -290,7 +290,7 @@ static void callback_get_connnum(struct rpc_msg *msg) - int rpc_call_conntable(int stack_id, void *conn_table, unsigned max_conn) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->dfx_rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_get_conntable); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_get_conntable); - if (msg == NULL) { - return -1; - } -@@ -304,7 +304,7 @@ int rpc_call_conntable(int stack_id, void *conn_table, unsigned max_conn) - int rpc_call_connnum(int stack_id) - { - rpc_queue *queue = &get_protocol_stack_by_id(stack_id)->dfx_rpc_queue; -- struct rpc_msg *msg = rpc_msg_alloc(stack_id, callback_get_connnum); -+ struct rpc_msg *msg = rpc_msg_alloc(stack_id, false, callback_get_connnum); - if (msg == NULL) { - return -1; - } -diff --git a/src/lstack/include/lstack_mempool.h b/src/lstack/include/lstack_mempool.h -index 131029e..6a31503 100644 ---- a/src/lstack/include/lstack_mempool.h -+++ b/src/lstack/include/lstack_mempool.h -@@ -40,6 +40,7 @@ - - #define MBUFPOOL_CACHE_NUM LWIP_MIN(NIC_QUEUE_SIZE_MAX >> 1, RTE_MEMPOOL_CACHE_MAX_SIZE) - #define MBUFPOOL_RESERVE_NUM (NIC_QUEUE_SIZE_MAX + MBUFPOOL_CACHE_NUM) -+#define RPCPOOL_RESERVE_NUM 512 - - #define MEMPOOL_OPS_NAME "ring_mt_rts" - #define MEMPOOL_CACHE_NUM 32 -@@ -307,7 +308,7 @@ struct rte_mempool *mem_get_rpc_pool(int stack_id); - unsigned mem_stack_mbuf_pool_count(int stack_id); - unsigned mem_stack_rpc_pool_count(int stack_id); - --void *mem_get_rpc(int stack_id); -+void *mem_get_rpc(int stack_id, bool reserve); - void mem_put_rpc(void *obj); - - struct mem_thread *mem_thread_migrate_get(int stack_id); -diff --git a/src/lstack/include/lstack_thread_rpc.h b/src/lstack/include/lstack_thread_rpc.h -index 013ff29..2d577ae 100644 ---- a/src/lstack/include/lstack_thread_rpc.h -+++ b/src/lstack/include/lstack_thread_rpc.h -@@ -64,7 +64,7 @@ struct rpc_msg { - - void rpc_get_stat(rpc_queue *queue, struct gazelle_rpc_stat *stat); - --struct rpc_msg *rpc_msg_alloc(int stack_id, rpc_func_t func); -+struct rpc_msg *rpc_msg_alloc(int stack_id, bool reserve, rpc_func_t func); - void rpc_msg_free(struct rpc_msg *msg); - - void rpc_queue_init(rpc_queue *queue, uint16_t queue_id); --- -2.33.0 - diff --git a/0343-mempool-fix-pthread_tryjoin_np-coredump-when-mysqld-.patch b/0343-mempool-fix-pthread_tryjoin_np-coredump-when-mysqld-.patch deleted file mode 100644 index 073073b7d590981d658389dd38d957566eb051e3..0000000000000000000000000000000000000000 --- a/0343-mempool-fix-pthread_tryjoin_np-coredump-when-mysqld-.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 00b47db8233ba31eabf0b8c4b3b015607afdcf78 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Wed, 23 Apr 2025 09:26:45 +0800 -Subject: [PATCH] mempool: fix pthread_tryjoin_np coredump when mysqld shutdown - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_mempool.c | 14 ++++++++++++-- - 1 file changed, 12 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index 00b299a..4dd7574 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -23,6 +23,8 @@ - #include "lstack_protocol_stack.h" - #include "lstack_unistd.h" - -+#define MEM_THREAD_TASK_PATH "/proc/%d/task/%d/stat" -+#define MEM_THREAD_MAX_PATH 32 /* cat /proc/sys/kernel/pid_max */ - #define MEM_THREAD_FLUSH_SIG (SIGRTMIN + 11) - #define MEM_THREAD_MANAGER_FLUSH_MS 100 - #define MEM_THREAD_MANAGER_FREE_S 2 -@@ -36,6 +38,7 @@ struct mem_thread_manager { - }; - - struct mem_thread_group { -+ char task_path[MEM_THREAD_MAX_PATH]; - int tid; - pthread_t thread; - struct list_node mt_node; -@@ -156,8 +159,13 @@ static inline void mem_thread_group_notify_flush(const struct mem_thread_group * - - static inline bool mem_thread_group_exist(const struct mem_thread_group *mt_group) - { -- if (pthread_tryjoin_np(mt_group->thread, NULL) == 0) -- return false; -+ if (access(mt_group->task_path, R_OK) != 0) { -+ if (errno == ENOENT) { -+ return false; -+ } -+ LSTACK_LOG(ERR, LSTACK, "mem_thread_group_exist access %s failed, errno %d\n", -+ mt_group->task_path, errno); -+ } - return true; - } - -@@ -200,6 +208,8 @@ static int mem_thread_group_init(int stack_id) - - g_mem_thread_group->tid = rte_gettid(); - g_mem_thread_group->thread = pthread_self(); -+ SYS_FORMAT_NAME(g_mem_thread_group->task_path, sizeof(g_mem_thread_group->task_path), -+ MEM_THREAD_TASK_PATH, getpid(), g_mem_thread_group->tid); - list_init_node(&g_mem_thread_group->mt_node); - mem_thread_manager_add_work(g_mem_thread_group); - } --- -2.33.0 - diff --git a/0344-mempool-stop-using-cache-when-too-many-threads.patch b/0344-mempool-stop-using-cache-when-too-many-threads.patch deleted file mode 100644 index ae5f15d6303902decf5778c34a6c81a397965b68..0000000000000000000000000000000000000000 --- a/0344-mempool-stop-using-cache-when-too-many-threads.patch +++ /dev/null @@ -1,158 +0,0 @@ -From ce877b0e0171bc878a4b0a19f328634381bfa375 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Wed, 23 Apr 2025 14:20:08 +0800 -Subject: [PATCH] mempool: stop using cache when too many threads - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_mempool.c | 53 ++++++++++++++++++++++---------- - 1 file changed, 36 insertions(+), 17 deletions(-) - -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index 4dd7574..70ac8c6 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -35,6 +35,7 @@ struct mem_thread_manager { - struct list_node mt_free_list; - rte_spinlock_t list_lock; - uint32_t flush_time; -+ unsigned thread_num; - }; - - struct mem_thread_group { -@@ -173,6 +174,7 @@ static void mem_thread_manager_add_work(struct mem_thread_group *mt_group) - { - rte_spinlock_lock(&g_mem_thread_manager.list_lock); - list_add_node(&mt_group->mt_node, &g_mem_thread_manager.mt_work_list); -+ g_mem_thread_manager.thread_num++; - rte_spinlock_unlock(&g_mem_thread_manager.list_lock); - } - -@@ -305,6 +307,7 @@ static void *mem_thread_manager_thread(void *arg) - } - list_del_node(node); - list_add_node(node, &g_mem_thread_manager.mt_free_list); -+ g_mem_thread_manager.thread_num--; - } - - rte_spinlock_unlock(&g_mem_thread_manager.list_lock); -@@ -502,7 +505,7 @@ static struct rte_mempool *rpc_pool_create(int stack_id, unsigned numa_id) - struct rte_mempool *pool; - uint32_t total_bufs; - -- total_bufs = RPCPOOL_RESERVE_NUM + MEMP_NUM_SYS_MBOX; -+ total_bufs = LWIP_MAX(RPCPOOL_RESERVE_NUM, MBUFPOOL_RESERVE_NUM) + MEMP_NUM_SYS_MBOX; - if (total_bufs > MEMPOOL_MAX_NUM) { - LSTACK_LOG(ERR, LSTACK, "total_bufs %u out of the dpdk mempool range\n", total_bufs); - return NULL; -@@ -783,7 +786,7 @@ void pool_put_with_bufcache(struct rte_mempool *pool, struct buf_cache* cache, v - - static unsigned pool_get_bulk_with_cache(const struct mempool_ops *pool_ops, - struct rte_mempool *pool, struct buf_cache *cache, -- void **obj_table, unsigned n) -+ void **obj_table, unsigned n, unsigned pool_count) - { - unsigned ret; - unsigned count = 0; -@@ -802,6 +805,13 @@ static unsigned pool_get_bulk_with_cache(const struct mempool_ops *pool_ops, - return 0; - } - -+ /* Stop using cache when too many threads. */ -+ ret = MBUFPOOL_RESERVE_NUM + BUF_CACHE_MIN_NUM * g_mem_thread_manager.thread_num; -+ if (unlikely(ret > pool_count)) { -+ buf_cache_reset_watermark(cache); -+ return n; -+ } -+ - buf_cache_add_watermark(cache); - if (count >= cache->watermark) { - return n; -@@ -862,27 +872,32 @@ void *mem_get_rpc(int stack_id, bool reserve) - { - struct mem_stack *ms = mem_stack_get(stack_id); - struct mem_thread *mt = mem_thread_get(stack_id); -- unsigned ret; -+ unsigned ret = 0; -+ unsigned pool_count; - void *obj; - -- if (reserve) { -- if (mem_stack_pool_ring_count(ms->rpc_pool) < RPCPOOL_RESERVE_NUM) { -- mem_thread_manager_flush_all(); -- return NULL; -- } -+ pool_count = mem_stack_pool_ring_count(ms->rpc_pool); -+ if (reserve && pool_count < RPCPOOL_RESERVE_NUM) { -+ goto out; - } - - if (mt == NULL) { - ret = mem_mp_ops.get_bulk(ms->rpc_pool, &obj, 1); - } else { - mem_thread_group_used(); -- ret = pool_get_bulk_with_cache(&mem_mp_ops, ms->rpc_pool, mt->rpc_cache, &obj, 1); -+ ret = pool_get_bulk_with_cache(&mem_mp_ops, ms->rpc_pool, mt->rpc_cache, -+ &obj, 1, pool_count); - mem_thread_group_done(); - } - - LWIP_DEBUGF(MEMP_DEBUG, ("%s(stack_id=%d, obj=%p)\n", __FUNCTION__, stack_id, obj)); - -- return ret == 0 ? NULL : obj; -+out: -+ if (unlikely(ret == 0)) { -+ mem_thread_manager_flush_all(); -+ return NULL; -+ } -+ return obj; - } - - void mem_put_rpc(void *obj) -@@ -906,17 +921,16 @@ unsigned mem_get_mbuf_bulk(int stack_id, struct rte_mbuf **mbuf_table, unsigned - { - struct mem_stack *ms = mem_stack_get(stack_id); - struct mem_thread *mt = mem_thread_get(stack_id); -- unsigned ret; -+ unsigned ret = 0; -+ unsigned pool_count; - - if (unlikely(n == 0)) { - return 0; - } - -- if (reserve) { -- if (mem_stack_pool_ring_count(ms->mbuf_pool) < MBUFPOOL_RESERVE_NUM + n) { -- mem_thread_manager_flush_all(); -- return 0; -- } -+ pool_count = mem_stack_pool_ring_count(ms->mbuf_pool); -+ if (reserve && pool_count < MBUFPOOL_RESERVE_NUM + n) { -+ goto out; - } - - if (mt == NULL) { -@@ -924,7 +938,8 @@ unsigned mem_get_mbuf_bulk(int stack_id, struct rte_mbuf **mbuf_table, unsigned - } else { - mem_thread_group_used(); - mem_mbuf_migrate_dequeue(mt); -- ret = pool_get_bulk_with_cache(&mbuf_mp_ops, ms->mbuf_pool, mt->mbuf_cache, (void **)mbuf_table, n); -+ ret = pool_get_bulk_with_cache(&mbuf_mp_ops, ms->mbuf_pool, mt->mbuf_cache, -+ (void **)mbuf_table, n, pool_count); - mem_thread_group_done(); - } - -@@ -935,6 +950,10 @@ unsigned mem_get_mbuf_bulk(int stack_id, struct rte_mbuf **mbuf_table, unsigned - } - #endif /* MEMP_DEBUG */ - -+out: -+ if (unlikely(ret == 0)) { -+ mem_thread_manager_flush_all(); -+ } - return ret; - } - --- -2.33.0 - diff --git a/0345-sk_wait-fix-lwip_tcp_allow_send-coredump.patch b/0345-sk_wait-fix-lwip_tcp_allow_send-coredump.patch deleted file mode 100644 index 95cbae822fb195c5fa6202535583970371e9ccd3..0000000000000000000000000000000000000000 --- a/0345-sk_wait-fix-lwip_tcp_allow_send-coredump.patch +++ /dev/null @@ -1,45 +0,0 @@ -From f0e0a9cdff414f1089173ea86e697ea3118623eb Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Wed, 23 Apr 2025 16:34:08 +0800 -Subject: [PATCH] sk_wait: fix lwip_tcp_allow_send coredump - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_wait.c | 17 ++++++++++++----- - 1 file changed, 12 insertions(+), 5 deletions(-) - -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -index 816f340..d9db582 100644 ---- a/src/lstack/core/lstack_wait.c -+++ b/src/lstack/core/lstack_wait.c -@@ -366,15 +366,22 @@ static inline bool NETCONN_NEED_RECV(const struct lwip_sock *sock) - - static inline bool NETCONN_ALLOW_SEND(const struct lwip_sock *sock) - { -+ if (sock->conn->pcb.tcp == NULL) { -+ return false; -+ } -+ - if (get_global_cfg_params()->stack_mode_rtc) { - if (NETCONN_TYPE(sock->conn) == NETCONN_TCP) - return lwip_tcp_allow_send(sock->conn->pcb.tcp); -- return false; -- } -- if (sys_mbox_valid(&sock->conn->sendmbox)) { -- const struct mbox_ring *mr = &sock->conn->sendmbox->mring; -- return mr->ops->free_count(mr) > 0; -+ else /* if UDP */ -+ return true; -+ } else { /* if RTW */ -+ if (sys_mbox_valid(&sock->conn->sendmbox)) { -+ const struct mbox_ring *mr = &sock->conn->sendmbox->mring; -+ return mr->ops->free_count(mr) > 0; -+ } - } -+ - return false; - } - --- -2.33.0 - diff --git a/0346-mbox-fix-mbox_ring_common_free-coredump-when-rte_rin.patch b/0346-mbox-fix-mbox_ring_common_free-coredump-when-rte_rin.patch deleted file mode 100644 index fe8c61b04a175a3e60ce9ef32035c88b76169f44..0000000000000000000000000000000000000000 --- a/0346-mbox-fix-mbox_ring_common_free-coredump-when-rte_rin.patch +++ /dev/null @@ -1,52 +0,0 @@ -From c9285237af5d95fc4014963ab9fae2327a0bd265 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 25 Apr 2025 15:09:27 +0800 -Subject: [PATCH] mbox: fix mbox_ring_common_free coredump when rte_ring_create - failed - -Signed-off-by: Lemmy Huang ---- - src/lstack/include/mbox_ring.h | 20 ++++++++++++-------- - 1 file changed, 12 insertions(+), 8 deletions(-) - -diff --git a/src/lstack/include/mbox_ring.h b/src/lstack/include/mbox_ring.h -index 2e3ac6a..893c636 100644 ---- a/src/lstack/include/mbox_ring.h -+++ b/src/lstack/include/mbox_ring.h -@@ -85,12 +85,14 @@ void mbox_ring_common_free(struct mbox_ring *mr) - if (obj != NULL) - mr->obj_free_fn(mr, obj, true); - -- if (mr->flags & MBOX_FLAG_RECV) -- mr->ops->recv_finish_burst(mr); -- while (true) { -- if (mr->ops->dequeue_burst(mr, &obj, 1) == 0) -- break; -- mr->obj_free_fn(mr, obj, false); -+ if (mr->ring != NULL) { -+ if (mr->flags & MBOX_FLAG_RECV) -+ mr->ops->recv_finish_burst(mr); -+ while (true) { -+ if (mr->ops->dequeue_burst(mr, &obj, 1) == 0) -+ break; -+ mr->obj_free_fn(mr, obj, false); -+ } - } - } - -@@ -482,8 +484,10 @@ static inline - void pk_ring_destroy(struct mbox_ring *mr) - { - void *obj; -- while (mr->ops->recv_start_burst(mr, &obj, 1) > 0) { } -- mr->ops->recv_finish_burst(mr); -+ if (mr->ring != NULL) { -+ while (mr->ops->recv_start_burst(mr, &obj, 1) > 0) { } -+ mr->ops->recv_finish_burst(mr); -+ } - return; - } - --- -2.33.0 - diff --git a/0347-sk_wait-fix-sock_wait_common_free.patch b/0347-sk_wait-fix-sock_wait_common_free.patch deleted file mode 100644 index 976d7c2fd0fbf6d1836de4d6ad82c4abecd0cf4f..0000000000000000000000000000000000000000 --- a/0347-sk_wait-fix-sock_wait_common_free.patch +++ /dev/null @@ -1,62 +0,0 @@ -From bd6149bf56dd26a67f835be5b4bc4d36ca8bca96 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Thu, 24 Apr 2025 10:03:25 +0800 -Subject: [PATCH] sk_wait: fix sock_wait_common_free socket: simplify calling - free_count in rtw_stack_tcp_write - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockio.c | 13 +++---------- - src/lstack/core/lstack_wait.c | 5 +++-- - 2 files changed, 6 insertions(+), 12 deletions(-) - -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 9eafc22..aff9d6d 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -671,7 +671,8 @@ static ssize_t rtw_stack_tcp_write(struct lwip_sock *sock, const char *data, siz - return -1; - } - -- if (unlikely(mr->app_free_count < 2)) { -+ if (unlikely(mr->app_free_count < 2) || -+ total_copy_len > mr->app_free_count * TCP_MSS) { - mr->app_free_count = mr->ops->free_count(mr); - if (unlikely(mr->app_free_count < 2)) { - API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -@@ -691,15 +692,7 @@ static ssize_t rtw_stack_tcp_write(struct lwip_sock *sock, const char *data, siz - copied_total += rtw_stack_tcp_write_one(sock, mr, data + copied_total, total_copy_len, flags); - } else { - if (total_copy_len > mr->app_free_count * TCP_MSS) { -- mr->app_free_count = mr->ops->free_count(mr); -- if (unlikely(mr->app_free_count < 2)) { -- API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -- set_errno(EWOULDBLOCK); -- goto out; -- } -- if (total_copy_len > mr->app_free_count * TCP_MSS) { -- total_copy_len = mr->app_free_count * TCP_MSS; -- } -+ total_copy_len = mr->app_free_count * TCP_MSS; - } - /* write bulk pbuf */ - while (total_copy_len > 0) { -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -index d9db582..d0e8d82 100644 ---- a/src/lstack/core/lstack_wait.c -+++ b/src/lstack/core/lstack_wait.c -@@ -307,8 +307,9 @@ void sock_wait_common_free(struct sock_wait *sk_wait) - do { - wait_stack = false; - for (int i = 0; i < PROTOCOL_STACK_MAX; ++i) { -- rte_mb(); -- if (!list_node_null(&sk_wait->stk_notify_node[i])) { -+ rte_rmb(); -+ if (!list_node_null(&sk_wait->stk_notify_node[i]) || -+ !list_head_empty(&sk_wait->stk_event_list[i])) { - wait_stack = true; - usleep(LWIP_EVENT_WAIT_US); - break; --- -2.33.0 - diff --git a/0348-socket-fix-stack_udp_readmsg-return-len.patch b/0348-socket-fix-stack_udp_readmsg-return-len.patch deleted file mode 100644 index 4c82756edd9bbb1f760a5a1f269994f11484b28b..0000000000000000000000000000000000000000 --- a/0348-socket-fix-stack_udp_readmsg-return-len.patch +++ /dev/null @@ -1,60 +0,0 @@ -From 329cbd6b63b4954c01caf9023007557f5efe7b27 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 25 Apr 2025 20:37:39 +0800 -Subject: [PATCH] socket: fix stack_udp_readmsg return len - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockio.c | 12 ++++++------ - 1 file changed, 6 insertions(+), 6 deletions(-) - -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index aff9d6d..4c524ab 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -483,7 +483,7 @@ static ssize_t stack_udp_readmsg(struct lwip_sock *sock, struct msghdr *msg, siz - struct pbuf **extcache_list; - struct netbuf *nbuf; - err_t err = ERR_OK; -- uint16_t copied_total = 0; -+ uint16_t total_len = 0; - - LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(sock=%p, msg=%p, size=%"SZT_F", flags=0x%x)\n", - __FUNCTION__, sock, msg, len, flags)); -@@ -506,11 +506,11 @@ static ssize_t stack_udp_readmsg(struct lwip_sock *sock, struct msghdr *msg, siz - - /* let not free inside by MSG_PEEK */ - sock->lastdata.netbuf = nbuf; -- err = lwip_recvfrom_udp_raw(sock, flags | MSG_PEEK, msg, &copied_total, 0); -+ err = lwip_recvfrom_udp_raw(sock, flags | MSG_PEEK, msg, &total_len, 0); - sock->lastdata.netbuf = NULL; - - SOCK_WAIT_STAT(sock->sk_wait, app_read_cnt, 1); -- SOCK_WAIT_STAT(sock->sk_wait, sock_rx_drop, copied_total < len ? 1 : 0); -+ SOCK_WAIT_STAT(sock->sk_wait, sock_rx_drop, total_len > len ? 1 : 0); - if (get_protocol_stack_group()->latency_start) - calculate_lstack_latency(sock->stack_id, &nbuf->p, 1, GAZELLE_LATENCY_READ_LSTACK, 0); - -@@ -521,7 +521,7 @@ static ssize_t stack_udp_readmsg(struct lwip_sock *sock, struct msghdr *msg, siz - mem_extcache_put_pbuf(nbuf->p, NULL, extcache_list); - } - -- mr->app_recvd_len += copied_total; -+ mr->app_recvd_len += total_len; - mr->app_queued_num++; - if (mr->app_queued_num >= RECV_EXTEND_CACHE_MAX || - mr->app_recvd_len >= RECV_EXTEND_CACHE_LEN) { -@@ -534,8 +534,8 @@ static ssize_t stack_udp_readmsg(struct lwip_sock *sock, struct msghdr *msg, siz - } - - if (err == ERR_OK) { -- API_EVENT(sock->conn, NETCONN_EVT_RCVMINUS, copied_total); -- return copied_total; -+ API_EVENT(sock->conn, NETCONN_EVT_RCVMINUS, total_len); -+ return LWIP_MIN(len, total_len); - } - out: - SOCK_WAIT_STAT(sock->sk_wait, read_null, 1); --- -2.33.0 - diff --git a/0349-sk_wait-fix-lwip_wait_foreach_notify-coredump-at-sta.patch b/0349-sk_wait-fix-lwip_wait_foreach_notify-coredump-at-sta.patch deleted file mode 100644 index dc3473c804b9e8e3aff96e2d5171c0de85d502a3..0000000000000000000000000000000000000000 --- a/0349-sk_wait-fix-lwip_wait_foreach_notify-coredump-at-sta.patch +++ /dev/null @@ -1,61 +0,0 @@ -From 1ff5ffd3634c61c6d6062b51d418b41b3a6a86d0 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 25 Apr 2025 21:40:16 +0800 -Subject: [PATCH] sk_wait: fix lwip_wait_foreach_notify coredump at startup - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_protocol_stack.c | 1 + - src/lstack/core/lstack_wait.c | 3 +-- - src/lstack/include/lstack_wait.h | 2 ++ - 3 files changed, 4 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index d375ecc..8ff6981 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -425,6 +425,7 @@ static struct protocol_stack *stack_thread_init(void *arg) - stack_affinity_numa(stack->numa_id); - } - -+ lwip_wait_init(stack->stack_idx); - if (mem_stack_mpcache_init(stack->stack_idx, stack->cpu_id) < 0) { - goto END; - } -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -index d0e8d82..42ebf05 100644 ---- a/src/lstack/core/lstack_wait.c -+++ b/src/lstack/core/lstack_wait.c -@@ -72,7 +72,7 @@ static inline struct lwip_wait *lwip_wait_get(int stack_id) - return &g_wait_group.lwaits[stack_id]; - } - --static int lwip_wait_init(int stack_id) -+int lwip_wait_init(int stack_id) - { - struct lwip_wait *lwait = lwip_wait_get(stack_id); - LWIP_UNUSED_ARG(lwait); -@@ -191,7 +191,6 @@ void* kernel_wait_thread(void *arg) - free(arg); - sem_post(&get_protocol_stack_group()->sem_stack_setup); - -- lwip_wait_init(stack_id); - kernel_wait_init(stack_id); - kwait = kernel_wait_get(stack_id); - -diff --git a/src/lstack/include/lstack_wait.h b/src/lstack/include/lstack_wait.h -index a1d35dd..58da126 100644 ---- a/src/lstack/include/lstack_wait.h -+++ b/src/lstack/include/lstack_wait.h -@@ -110,6 +110,8 @@ struct sock_wait { - int sock_wait_group_init(void); - void sock_wait_group_stat(int stack_id, struct gazelle_wakeup_stat *stat); - -+int lwip_wait_init(int stack_id); -+ - void* kernel_wait_thread(void *arg); - int kernel_wait_ctl(struct sock_wait *sk_wait, int new_stack_id, int old_stack_id); - --- -2.33.0 - diff --git a/0350-epoll-fix-do_lwip_connected_callback.patch b/0350-epoll-fix-do_lwip_connected_callback.patch deleted file mode 100644 index ed88fafefc4c341a8b05ec3e16477e37211cb68f..0000000000000000000000000000000000000000 --- a/0350-epoll-fix-do_lwip_connected_callback.patch +++ /dev/null @@ -1,212 +0,0 @@ -From b872ae2d9b0aca063e14aa0648d13e49af494a75 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 22 Apr 2025 15:41:53 +0800 -Subject: [PATCH] epoll: fix do_lwip_connected_callback - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 46 +++++++++++++++++++------------ - src/lstack/api/lstack_sockctl.c | 22 --------------- - src/lstack/api/lstack_wrap.c | 25 +++++++++++++++++ - src/lstack/core/lstack_wait.c | 3 +- - src/lstack/include/lstack_epoll.h | 3 ++ - 5 files changed, 58 insertions(+), 41 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 19cc9d6..1a10e24 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -219,7 +219,6 @@ static int epoll_close_internal(int epfd) - sk_wait->type = WAIT_CLOSE; - epoll_cb_free(&sk_wait->epcb); - -- posix_api->close_fn(sk_wait->epfd); - sock_wait_kernel_free(sk_wait); - sock_wait_common_free(sk_wait); - -@@ -259,6 +258,25 @@ int lstack_epoll_close(int epfd) - return posix_api->close_fn(epfd); - } - -+int epoll_ctl_kernel_event(int epfd, int op, int fd, struct epoll_event *event, -+ struct sock_wait *sk_wait) -+{ -+ int ret; -+ -+ ret = posix_api->epoll_ctl_fn(epfd, op, fd, event); -+ if (ret != 0) { -+ LSTACK_LOG(ERR, LSTACK, "epoll_ctl_fn failed, fd=%d epfd=%d op=%d\n", fd, epfd, op); -+ return ret; -+ } -+ if (op == EPOLL_CTL_ADD) { -+ sk_wait->kernel_nfds++; -+ } else if (op == EPOLL_CTL_DEL) { -+ sk_wait->kernel_nfds--; -+ } -+ -+ return ret; -+} -+ - int lstack_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) - { - int ret; -@@ -278,22 +296,13 @@ int lstack_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) - __FUNCTION__, epfd, op, fd, event)); - - enum posix_type sk_type = select_sock_posix_path(sock); -- /* has POSIX_LWIP */ -- if (sk_type != POSIX_LWIP) { -- ret = posix_api->epoll_ctl_fn(epfd, op, fd, event); -- if (ret != 0) { -- LSTACK_LOG(ERR, LSTACK, "epoll_ctl_fn failed, fd=%d epfd=%d op=%d\n", fd, epfd, op); -+ if (sk_type & POSIX_KERNEL) { /* has POSIX_KERNEL */ -+ ret = epoll_ctl_kernel_event(epfd, op, fd, event, sk_wait); -+ if (ret != 0 || -+ sk_type == POSIX_KERNEL) { /* is POSIX_KERNEL */ - return ret; - } -- if (op == EPOLL_CTL_ADD) { -- sk_wait->kernel_nfds++; -- } else if (op == EPOLL_CTL_DEL) { -- sk_wait->kernel_nfds--; -- } - } -- /* is POSIX_KERNEL */ -- if (sk_type == POSIX_KERNEL) -- return ret; - - for (; sock != NULL; sock = sock->listen_next) { - sk_event = &sock->sk_event; -@@ -412,7 +421,8 @@ int lstack_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int t - maxevents = POLL_MAX_EVENTS; - } - /* avoid the starvation of poll events from both kernel and lwip */ -- lwip_maxevents = (maxevents >> 1) + 1; -+ lwip_maxevents = sk_wait->kernel_nfds > 0 ? -+ (maxevents >> 1) + 1 : maxevents; - - start = sys_now(); - -@@ -555,7 +565,7 @@ struct sock_wait *poll_construct_wait(int nfds) - return g_sk_wait; - } - --static bool poll_ctl_kernel_event(int epfd, int fds_id, -+static int poll_ctl_kernel_event(int epfd, int fds_id, - const struct pollfd *new_fds, const struct pollfd *old_fds) - { - int ret; -@@ -575,11 +585,11 @@ static bool poll_ctl_kernel_event(int epfd, int fds_id, - ret |= posix_api->epoll_ctl_fn(epfd, EPOLL_CTL_ADD, new_fds->fd, &epevent); - } - -- if (ret != 0) { -+ if (ret != 0 && errno != EINTR && errno != ENOENT) { - LSTACK_LOG(ERR, LSTACK, "epoll_ctl failed, errno %d, new_fd %d, old_fd %d\n", - errno, new_fds->fd, old_fds->fd); - } -- return true; -+ return ret; - } - - static int poll_wait_kernel_event(int epfd, struct pollfd *fds, int maxevents) -diff --git a/src/lstack/api/lstack_sockctl.c b/src/lstack/api/lstack_sockctl.c -index f53b4cd..856b24e 100644 ---- a/src/lstack/api/lstack_sockctl.c -+++ b/src/lstack/api/lstack_sockctl.c -@@ -455,28 +455,6 @@ static int rpc_call_connect(int stack_id, int fd, const struct sockaddr *addr, s - return ret; - } - --/* for lwip nonblock connected callback */ --void do_lwip_connected_callback(int fd) --{ -- bool has_kernel; -- struct lwip_sock *sock = lwip_get_socket(fd); -- if (POSIX_IS_CLOSED(sock)) { -- return; -- } -- -- has_kernel = POSIX_HAS_TYPE(sock, POSIX_KERNEL); -- POSIX_SET_TYPE(sock, POSIX_LWIP); -- if (has_kernel) { -- /* delete kernel event */ -- if (sock->sk_wait != NULL) { -- posix_api->epoll_ctl_fn(sock->sk_wait->epfd, EPOLL_CTL_DEL, fd, NULL); -- } -- /* shutdown kernel connect, do_connect() has tried both kernel and lwip. */ -- posix_api->shutdown_fn(fd, SHUT_RDWR); -- } -- return; --} -- - /* when fd is listenfd, listenfd of all protocol stack thread will be closed */ - static int stack_broadcast_close(int fd) - { -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index e22937f..8339750 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -378,6 +378,31 @@ static int32_t do_connect(int32_t s, const struct sockaddr *addr, socklen_t addr - return ret; - } - -+/* for lwip nonblock connected callback */ -+void do_lwip_connected_callback(int fd) -+{ -+ struct lwip_sock *sock = lwip_get_socket(fd); -+ if (POSIX_IS_CLOSED(sock)) { -+ return; -+ } -+ -+ if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) { -+ POSIX_SET_TYPE(sock, POSIX_LWIP); -+ /* delete kernel event */ -+ if (sock->sk_wait != NULL) { -+ if (sock->sk_wait->type & WAIT_EPOLL) { -+ epoll_ctl_kernel_event(sock->sk_wait->epfd, EPOLL_CTL_DEL, fd, NULL, sock->sk_wait); -+ } -+ } -+ /* shutdown kernel connect, do_connect() has tried both kernel and lwip. */ -+ posix_api->shutdown_fn(fd, SHUT_RDWR); -+ } else { -+ POSIX_SET_TYPE(sock, POSIX_LWIP); -+ } -+ -+ return; -+} -+ - static inline int32_t do_listen(int32_t s, int32_t backlog) - { - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_KERNEL) { -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -index 42ebf05..7070d3f 100644 ---- a/src/lstack/core/lstack_wait.c -+++ b/src/lstack/core/lstack_wait.c -@@ -392,7 +392,8 @@ static unsigned sock_event_lose_pending(const struct lwip_sock *sock, enum netco - switch (evt) { - case NETCONN_EVT_RCVMINUS: - if (sock->sk_event.events & EPOLLIN) { -- if (!NETCONN_NEED_RECV(sock) && -+ if (!sock->errevent && -+ !NETCONN_NEED_RECV(sock) && - !NETCONN_NEED_ACCEPT(sock)) { - event = EPOLLIN; - } -diff --git a/src/lstack/include/lstack_epoll.h b/src/lstack/include/lstack_epoll.h -index 99a7162..c6d2eb3 100644 ---- a/src/lstack/include/lstack_epoll.h -+++ b/src/lstack/include/lstack_epoll.h -@@ -23,6 +23,9 @@ void poll_destruct_wait(void); - - int lstack_epoll_close(int epfd); - void epoll_api_init(posix_api_t *api); -+int epoll_ctl_kernel_event(int epfd, int op, int fd, struct epoll_event *event, -+ struct sock_wait *sk_wait); -+ - bool sock_event_wait(struct lwip_sock *sock, enum netconn_evt evt, bool noblocking); - - #endif /* _GAZELLE_EPOLL_H_ */ --- -2.33.0 - diff --git a/0351-sockio-fix-rtw_stack_tcp_write-wrong-copied_total-af.patch b/0351-sockio-fix-rtw_stack_tcp_write-wrong-copied_total-af.patch deleted file mode 100644 index 09dc616b00fdd80cb6de8d8d5d7bcb46e447d64c..0000000000000000000000000000000000000000 --- a/0351-sockio-fix-rtw_stack_tcp_write-wrong-copied_total-af.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 0f38dd2b397cc84bfaf1eeac358ad2a916998d73 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Thu, 26 Jun 2025 10:30:45 +0800 -Subject: [PATCH] sockio: fix rtw_stack_tcp_write wrong copied_total after - append - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockio.c | 6 ++++-- - 1 file changed, 4 insertions(+), 2 deletions(-) - -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 4c524ab..8640931 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -683,13 +683,15 @@ static ssize_t rtw_stack_tcp_write(struct lwip_sock *sock, const char *data, siz - - copied_total = rtw_stack_tcp_append(mr, data, LWIP_MIN(TCP_MSS, total_copy_len), flags); - SOCK_WAIT_STAT(sock->sk_wait, sock_tx_merge, copied_total > 0 ? 1 : 0); -- if (copied_total == total_copy_len) { -- return copied_total; -+ total_copy_len -= copied_total; -+ if (total_copy_len == 0) { -+ goto out; - } - - if (total_copy_len <= TCP_MSS) { - /* write one pbuf */ - copied_total += rtw_stack_tcp_write_one(sock, mr, data + copied_total, total_copy_len, flags); -+ total_copy_len -= copied_total; - } else { - if (total_copy_len > mr->app_free_count * TCP_MSS) { - total_copy_len = mr->app_free_count * TCP_MSS; --- -2.33.0 - diff --git a/0352-sk_event-fix-rtw-epoll-wrong-event-notify-and-remove.patch b/0352-sk_event-fix-rtw-epoll-wrong-event-notify-and-remove.patch deleted file mode 100644 index 7abee4053d7649ae3729fa259ce9c07ded9026b2..0000000000000000000000000000000000000000 --- a/0352-sk_event-fix-rtw-epoll-wrong-event-notify-and-remove.patch +++ /dev/null @@ -1,349 +0,0 @@ -From ad2d26c2a9316829724adbf5ed7e201ff85ae7a6 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sat, 28 Jun 2025 14:59:54 +0800 -Subject: [PATCH] sk_event: fix rtw epoll wrong event notify and remove - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 69 +++++++++++++++++++------------- - src/lstack/api/lstack_sockio.c | 2 +- - src/lstack/core/lstack_wait.c | 53 ++++++++++++++---------- - src/lstack/include/lstack_wait.h | 9 +++-- - 4 files changed, 80 insertions(+), 53 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 1a10e24..d39002b 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -53,46 +53,64 @@ static int rtw_sock_wait_timedwait(struct sock_wait *sk_wait, int timeout, uint3 - } - - static void rtc_epoll_notify_event(struct sock_wait *sk_wait, struct sock_event *sk_event, -- unsigned pending, int stack_id) -+ enum netconn_evt evt, int stack_id) - { -- sk_event->pending |= pending; -- if (list_node_null(&sk_event->event_node)) { -- list_add_node(&sk_event->event_node, &sk_wait->epcb.event_list); -+ sk_event->pending |= sock_event_hold_pending(sk_event->sock, sk_wait->type, evt, 0); -+ if (likely(sk_event->pending != 0)) { -+ if (list_node_null(&sk_event->event_node)) { -+ list_add_node(&sk_event->event_node, &sk_wait->epcb.event_list); -+ } - } - } - --static void rtc_epoll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending) -+static void rtc_epoll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, enum netconn_evt evt) - { -- sk_event->pending &= ~pending; -+ sk_event->pending &= ~sock_event_lose_pending(sk_event->sock, evt, 0); - if (sk_event->pending == 0) { - list_del_node(&sk_event->event_node); - } - } - - static void rtw_epoll_notify_event(struct sock_wait *sk_wait, struct sock_event *sk_event, -- unsigned pending, int stack_id) -+ enum netconn_evt evt, int stack_id) - { -+ /* call sock_event_hold_pending in lock to avoid unnecessary events: -+ * stack: mbox_enqueue -> hold_pending -> lock -> notify_event -> unlock -+ * recv: mbox_dequeue -> lose_pending -> lock -> remove_event -> unlock -+ */ -+ - #if SOCK_WAIT_BATCH_NOTIFY - if (likely(stack_id >= 0)) { -- lwip_wait_add_notify(sk_wait, sk_event, pending, stack_id); -+ lwip_wait_add_notify(sk_wait, sk_event, evt, stack_id); - return; - } - #endif /* SOCK_WAIT_BATCH_NOTIFY */ - - rte_spinlock_lock(&sk_wait->epcb.lock); -- sk_event->pending |= pending; -- if (list_node_null(&sk_event->event_node)) { -- list_add_node(&sk_event->event_node, &sk_wait->epcb.event_list); -+ sk_event->pending |= sock_event_hold_pending(sk_event->sock, sk_wait->type, evt, 0); -+ if (likely(sk_event->pending != 0)) { -+ if (list_node_null(&sk_event->event_node)) { -+ list_add_node(&sk_event->event_node, &sk_wait->epcb.event_list); -+ } - } - rte_spinlock_unlock(&sk_wait->epcb.lock); - - sys_sem_signal_internal(&sk_wait->sem); - } - --static void rtw_epoll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending) -+static void rtw_epoll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, enum netconn_evt evt) - { -+ /* call sock_event_hold_pending in lock to avoid wrong remove: -+ * stack: mbox_enqueue -> hold_pending -> lock -> notify_event -> unlock -+ * recv: lose_pending -> lock -> remove_event -> unlock -+ */ -+ -+ if (sock_event_lose_pending(sk_event->sock, evt, 0) == 0) { -+ return; -+ } -+ - rte_spinlock_lock(&sk_wait->epcb.lock); -- sk_event->pending &= ~pending; -+ sk_event->pending &= ~sock_event_lose_pending(sk_event->sock, evt, 0); - if (sk_event->pending == 0) { - list_del_node(&sk_event->event_node); - } -@@ -100,24 +118,24 @@ static void rtw_epoll_remove_event(struct sock_wait *sk_wait, struct sock_event - } - - static void rtc_poll_notify_event(struct sock_wait *sk_wait, struct sock_event *sk_event, -- unsigned pending, int stack_id) -+ enum netconn_evt evt, int stack_id) - { - } --static void rtc_poll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending) -+static void rtc_poll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, enum netconn_evt evt) - { - } - static void rtw_poll_notify_event(struct sock_wait *sk_wait, struct sock_event *sk_event, -- unsigned pending, int stack_id) -+ enum netconn_evt evt, int stack_id) - { - #if SOCK_WAIT_BATCH_NOTIFY - if (likely(stack_id >= 0)) { -- lwip_wait_add_notify(sk_wait, NULL, 0, stack_id); -+ lwip_wait_add_notify(sk_wait, NULL, evt, stack_id); - return; - } - #endif /* SOCK_WAIT_BATCH_NOTIFY */ - sys_sem_signal_internal(&sk_wait->sem); - } --static void rtw_poll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending) -+static void rtw_poll_remove_event(struct sock_wait *sk_wait, struct sock_event *sk_event, enum netconn_evt evt) - { - } - -@@ -284,7 +302,6 @@ int lstack_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) - struct lwip_sock *sock = lwip_get_socket(fd); - struct sock_wait *sk_wait = epsock->sk_wait; - struct sock_event *sk_event; -- unsigned pending; - - if (epfd < 0 || fd < 0 || epfd == fd || \ - (event == NULL && op != EPOLL_CTL_DEL)) { -@@ -316,10 +333,9 @@ int lstack_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) - sk_event->events = event->events | EPOLLERR | EPOLLHUP; - sk_event->ep_data = event->data; - -- pending = sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_RCVPLUS, 0) | -- sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_SENDPLUS, 0) | -- sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_ERROR, 0); -- sk_wait->notify_fn(sk_wait, sk_event, pending, -1); -+ sk_wait->notify_fn(sk_wait, sk_event, NETCONN_EVT_RCVPLUS, -1); -+ sk_wait->notify_fn(sk_wait, sk_event, NETCONN_EVT_SENDPLUS, -1); -+ sk_wait->notify_fn(sk_wait, sk_event, NETCONN_EVT_ERROR, -1); - - sk_wait->lwip_nfds++; - sk_wait->affinity.stack_nfds[sock->stack_id]++; -@@ -327,10 +343,9 @@ int lstack_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) - case EPOLL_CTL_DEL: - sk_event->events = 0; - -- pending = sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_RCVMINUS, 0) | -- sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_SENDMINUS, 0) | -- sock_event_hold_pending(sock, WAIT_EPOLL, NETCONN_EVT_ERROR, 0); -- sk_wait->remove_fn(sk_wait, sk_event, pending); -+ sk_wait->remove_fn(sk_wait, sk_event, NETCONN_EVT_RCVMINUS); -+ sk_wait->remove_fn(sk_wait, sk_event, NETCONN_EVT_SENDMINUS); -+ sk_wait->remove_fn(sk_wait, sk_event, NETCONN_EVT_ERROR); - - sk_wait->lwip_nfds--; - sk_wait->affinity.stack_nfds[sock->stack_id]--; -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 8640931..418311e 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -1461,7 +1461,7 @@ int do_lwip_init_sock(int fd) - } - - sock->sk_wait = NULL; -- ret = sock_event_init(&sock->sk_event); -+ ret = sock_event_init(&sock->sk_event, sock); - if (ret != 0) { - LSTACK_LOG(ERR, LSTACK, "sock_event_init failed\n"); - return -1; -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -index 7070d3f..4714742 100644 ---- a/src/lstack/core/lstack_wait.c -+++ b/src/lstack/core/lstack_wait.c -@@ -256,10 +256,11 @@ void affinity_bind_stack(struct sock_wait *sk_wait, struct wait_affinity *affini - } - } - --int sock_event_init(struct sock_event *sk_event) -+int sock_event_init(struct sock_event *sk_event, struct lwip_sock *sock) - { - memset_s(sk_event, sizeof(struct sock_event), 0, sizeof(struct sock_event)); - -+ sk_event->sock = sock; - list_init_node(&sk_event->event_node); - #if SOCK_WAIT_BATCH_NOTIFY - list_init_node(&sk_event->stk_event_node); -@@ -278,6 +279,7 @@ void sock_event_free(struct sock_event *sk_event, struct sock_wait *sk_wait) - list_del_node(&sk_event->stk_event_node); - #endif /* SOCK_WAIT_BATCH_NOTIFY */ - } -+ sk_event->sock = NULL; - } - - int sock_wait_common_init(struct sock_wait *sk_wait) -@@ -385,7 +387,7 @@ static inline bool NETCONN_ALLOW_SEND(const struct lwip_sock *sock) - return false; - } - --static unsigned sock_event_lose_pending(const struct lwip_sock *sock, enum netconn_evt evt, unsigned len) -+unsigned sock_event_lose_pending(const struct lwip_sock *sock, enum netconn_evt evt, unsigned len) - { - unsigned event = 0; - -@@ -421,8 +423,7 @@ unsigned sock_event_hold_pending(const struct lwip_sock *sock, - switch (evt) { - case NETCONN_EVT_RCVPLUS: - if (sock->sk_event.events & EPOLLIN || type & WAIT_BLOCK) { -- if (len > 0 || -- NETCONN_NEED_RECV(sock) || -+ if (NETCONN_NEED_RECV(sock) || - NETCONN_NEED_ACCEPT(sock)) { - event = EPOLLIN; - } -@@ -430,8 +431,7 @@ unsigned sock_event_hold_pending(const struct lwip_sock *sock, - break; - case NETCONN_EVT_SENDPLUS: - if (sock->sk_event.events & EPOLLOUT || type & WAIT_BLOCK) { -- if (len > 0 || -- NETCONN_ALLOW_SEND(sock)) { -+ if (NETCONN_ALLOW_SEND(sock)) { - event = EPOLLOUT; - } - } -@@ -460,11 +460,7 @@ void sock_event_remove_pending(struct lwip_sock *sock, enum netconn_evt evt, uns - sock->sk_wait = NULL; - return; - } -- -- unsigned pending = sock_event_lose_pending(sock, evt, 0); -- if (pending) { -- sock->sk_wait->remove_fn(sock->sk_wait, &sock->sk_event, pending); -- } -+ sock->sk_wait->remove_fn(sock->sk_wait, &sock->sk_event, evt); - } - - void sock_event_notify_pending(struct lwip_sock *sock, enum netconn_evt evt, unsigned len) -@@ -479,22 +475,18 @@ void sock_event_notify_pending(struct lwip_sock *sock, enum netconn_evt evt, uns - sock->sk_wait = NULL; - return; - } -- -- unsigned pending = sock_event_hold_pending(sock, sock->sk_wait->type, evt, len); -- if (pending) { -- sock->sk_wait->notify_fn(sock->sk_wait, &sock->sk_event, pending, sock->stack_id); -- } -+ sock->sk_wait->notify_fn(sock->sk_wait, &sock->sk_event, evt, sock->stack_id); - } - - #if SOCK_WAIT_BATCH_NOTIFY - /* Only allow stack call */ - void lwip_wait_add_notify(struct sock_wait *sk_wait, struct sock_event *sk_event, -- unsigned pending, int stack_id) -+ enum netconn_evt evt, int stack_id) - { - struct lwip_wait *lwait = lwip_wait_get(stack_id); - - if (sk_event != NULL) { -- sk_event->stk_pending |= pending; -+ sk_event->stk_evts |= evt; - if (list_node_null(&sk_event->stk_event_node)) { - list_add_node(&sk_event->stk_event_node, &sk_wait->stk_event_list[stack_id]); - } -@@ -505,6 +497,23 @@ void lwip_wait_add_notify(struct sock_wait *sk_wait, struct sock_event *sk_event - } - } - -+static unsigned sock_event_get_pending(struct sock_event *sk_event, enum netconn_evt evts) -+{ -+ unsigned pending = 0; -+ -+ if (evts & NETCONN_EVT_SENDPLUS) { -+ pending |= sock_event_hold_pending(sk_event->sock, WAIT_EPOLL, NETCONN_EVT_SENDPLUS, 0); -+ } -+ if (evts & NETCONN_EVT_RCVPLUS) { -+ pending |= sock_event_hold_pending(sk_event->sock, WAIT_EPOLL, NETCONN_EVT_RCVPLUS, 0); -+ } -+ if (evts & NETCONN_EVT_ERROR) { -+ pending |= sock_event_hold_pending(sk_event->sock, WAIT_EPOLL, NETCONN_EVT_ERROR, 0); -+ } -+ sk_event->stk_evts = 0; -+ return pending; -+} -+ - static inline - unsigned sock_wait_foreach_event(struct sock_wait *sk_wait, int stack_id) - { -@@ -523,12 +532,14 @@ unsigned sock_wait_foreach_event(struct sock_wait *sk_wait, int stack_id) - sk_event = container_of(node, struct sock_event, stk_event_node); - - /* see rtw_epoll_notify_event() */ -- sk_event->pending |= sk_event->stk_pending; -+ sk_event->pending |= sock_event_get_pending(sk_event, sk_event->stk_evts); -+ if (unlikely(sk_event->pending == 0)) { -+ continue; -+ } -+ - if (list_node_null(&sk_event->event_node)) { - list_add_node(&sk_event->event_node, &sk_wait->epcb.event_list); - } -- -- sk_event->stk_pending = 0; - count++; - } - -diff --git a/src/lstack/include/lstack_wait.h b/src/lstack/include/lstack_wait.h -index 58da126..8ed2e93 100644 ---- a/src/lstack/include/lstack_wait.h -+++ b/src/lstack/include/lstack_wait.h -@@ -67,9 +67,9 @@ struct sock_wait { - int (*timedwait_fn)(struct sock_wait *sk_wait, int timeout, uint32_t start); - /* trigger event */ - void (*notify_fn)(struct sock_wait *sk_wait, struct sock_event *sk_event, -- unsigned pending, int stack_id); -+ enum netconn_evt evt, int stack_id); - /* remove event */ -- void (*remove_fn)(struct sock_wait *sk_wait, struct sock_event *sk_event, unsigned pending); -+ void (*remove_fn)(struct sock_wait *sk_wait, struct sock_event *sk_event, enum netconn_evt evt); - - /* dfx stat */ - struct list_node group_node; -@@ -117,17 +117,18 @@ int kernel_wait_ctl(struct sock_wait *sk_wait, int new_stack_id, int old_stack_i - - #if SOCK_WAIT_BATCH_NOTIFY - void lwip_wait_add_notify(struct sock_wait *sk_wait, struct sock_event *sk_event, -- unsigned pending, int stack_id); -+ enum netconn_evt evt, int stack_id); - unsigned lwip_wait_foreach_notify(int stack_id); - bool lwip_wait_notify_empty(int stack_id); - #endif /* SOCK_WAIT_BATCH_NOTIFY */ - -+unsigned sock_event_lose_pending(const struct lwip_sock *sock, enum netconn_evt evt, unsigned len); - unsigned sock_event_hold_pending(const struct lwip_sock *sock, - enum sock_wait_type type, enum netconn_evt evt, unsigned len); - void sock_event_notify_pending(struct lwip_sock *sock, enum netconn_evt evt, unsigned len); - void sock_event_remove_pending(struct lwip_sock *sock, enum netconn_evt evt, unsigned len); - --int sock_event_init(struct sock_event *sk_event); -+int sock_event_init(struct sock_event *sk_event, struct lwip_sock *sock); - void sock_event_free(struct sock_event *sk_event, struct sock_wait *sk_wait); - - int sock_wait_common_init(struct sock_wait *sk_wait); --- -2.33.0 - diff --git a/0353-poll-fix-do_lwip_connected_callback-not-delete-poll-.patch b/0353-poll-fix-do_lwip_connected_callback-not-delete-poll-.patch deleted file mode 100644 index 2912a3d121b5d5c3956eeaf62e269fce03bf2354..0000000000000000000000000000000000000000 --- a/0353-poll-fix-do_lwip_connected_callback-not-delete-poll-.patch +++ /dev/null @@ -1,158 +0,0 @@ -From 4931694a535c2371645ab58669e80a6a204a1dd1 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Wed, 2 Jul 2025 09:36:12 +0800 -Subject: [PATCH] poll: fix do_lwip_connected_callback not delete poll kernel - fd - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 73 +++++++++++++++++++------------ - src/lstack/api/lstack_wrap.c | 2 + - src/lstack/include/lstack_epoll.h | 1 + - 3 files changed, 49 insertions(+), 27 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index d39002b..949e10b 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -580,43 +580,62 @@ struct sock_wait *poll_construct_wait(int nfds) - return g_sk_wait; - } - --static int poll_ctl_kernel_event(int epfd, int fds_id, -- const struct pollfd *new_fds, const struct pollfd *old_fds) --{ -- int ret; -+struct poll_kernel_data { -+ union { -+ struct { -+ uint32_t fd; -+ uint16_t fds_id; -+ }; -+ void *ptr; -+ }; -+}; -+int poll_ctl_kernel_event(int epfd, int fds_id, int old_fd, const struct pollfd *new_fds) -+{ -+ int ret = 0; - struct epoll_event epevent; -+ struct poll_kernel_data pdata; - -- LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(epfd=%d, old_fd=%d, new_fd=%d)\n", -- __FUNCTION__, epfd, old_fds->fd, new_fds->fd)); -- -- epevent.data.fd = fds_id; -- epevent.events = new_fds->events; -+ RTE_BUILD_BUG_ON(sizeof(struct poll_kernel_data) > sizeof(void *)); - - /* EPOLL_CTL_MOD may not be any events, but why? */ -- if (old_fds->fd == 0) { -- ret = posix_api->epoll_ctl_fn(epfd, EPOLL_CTL_ADD, new_fds->fd, &epevent); -- } else { -- ret = posix_api->epoll_ctl_fn(epfd, EPOLL_CTL_DEL, old_fds->fd, NULL); -+ if (old_fd > 0) { -+ ret = posix_api->epoll_ctl_fn(epfd, EPOLL_CTL_DEL, old_fd, NULL); -+ } -+ if (new_fds != NULL && new_fds->fd > 0) { -+ pdata.fd = new_fds->fd; -+ pdata.fds_id = fds_id; -+ epevent.data.ptr = pdata.ptr; -+ epevent.events = new_fds->events; - ret |= posix_api->epoll_ctl_fn(epfd, EPOLL_CTL_ADD, new_fds->fd, &epevent); - } - -+ LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(epfd=%d, fds_id %d, old_fd=%d, new_fd=%d)\n", -+ __FUNCTION__, epfd, fds_id, old_fd, new_fds ? new_fds->fd : -1)); -+ - if (ret != 0 && errno != EINTR && errno != ENOENT) { -- LSTACK_LOG(ERR, LSTACK, "epoll_ctl failed, errno %d, new_fd %d, old_fd %d\n", -- errno, new_fds->fd, old_fds->fd); -+ LSTACK_LOG(ERR, LSTACK, "epoll_ctl failed, errno %d, fds_id %d, old_fd %d, new_fd %d\n", -+ errno, fds_id, old_fd, new_fds ? new_fds->fd : -1); - } - return ret; - } - --static int poll_wait_kernel_event(int epfd, struct pollfd *fds, int maxevents) -+static int poll_wait_kernel_event(int epfd, const struct poll_cb *pcb, struct pollfd *fds, int maxevents) - { - struct epoll_event epevents[POLL_MAX_EVENTS]; -- int num = 0; -- int i, fds_id; -- -- num = posix_api->epoll_wait_fn(epfd, epevents, maxevents, 0); -- for (i = 0; i < num; ++i) { -- fds_id = epevents[i].data.fd; -- fds[fds_id].revents = epevents[i].events; -+ struct poll_kernel_data pdata; -+ int ret, i, num = 0; -+ -+ ret = posix_api->epoll_wait_fn(epfd, epevents, maxevents, 0); -+ for (i = 0; i < ret; ++i) { -+ pdata.ptr = epevents[i].data.ptr; -+ if (pdata.fd != fds[pdata.fds_id].fd) { -+ poll_ctl_kernel_event(epfd, pdata.fds_id, pdata.fd, NULL); -+ continue; -+ } -+ /* may be already counted by poll_scan_lwip_event() */ -+ if (fds[pdata.fds_id].revents == 0) -+ num++; -+ fds[pdata.fds_id].revents |= epevents[i].events; - } - - return num; -@@ -635,14 +654,14 @@ static void poll_prepare_wait(struct sock_wait *sk_wait, struct pollfd *fds, nfd - 0, sizeof(sk_wait->affinity.stack_nfds)); - - for (i = 0; i < nfds; ++i) { -+ fds[i].revents = 0; - fd = fds[i].fd; - sock = lwip_get_socket(fd); - sk_type = select_sock_posix_path(sock); - - if (sk_type & POSIX_KERNEL) { -- poll_ctl_kernel_event(sk_wait->epfd, i, &fds[i], -- &pcb->kernel_fds[sk_wait->kernel_nfds]); -- pcb->kernel_fds[sk_wait->kernel_nfds] = fds[i]; -+ poll_ctl_kernel_event(sk_wait->epfd, i, pcb->kernel_fds[i].fd, &fds[i]); -+ pcb->kernel_fds[i] = fds[i]; - sk_wait->kernel_nfds++; - } - -@@ -723,7 +742,7 @@ int lstack_poll(struct pollfd *fds, nfds_t nfds, int timeout) - } - - if (sk_wait->kernel_nfds > 0 && rte_atomic16_read(&sk_wait->kernel_pending)) { -- kernel_num = poll_wait_kernel_event(sk_wait->epfd, fds, sk_wait->kernel_nfds); -+ kernel_num = poll_wait_kernel_event(sk_wait->epfd, &sk_wait->pcb, fds, sk_wait->kernel_nfds); - if (kernel_num == 0 && errno != EINTR && errno != EAGAIN) { - rte_atomic16_set(&sk_wait->kernel_pending, false); - } -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 8339750..6523dc2 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -392,6 +392,8 @@ void do_lwip_connected_callback(int fd) - if (sock->sk_wait != NULL) { - if (sock->sk_wait->type & WAIT_EPOLL) { - epoll_ctl_kernel_event(sock->sk_wait->epfd, EPOLL_CTL_DEL, fd, NULL, sock->sk_wait); -+ } else if (sock->sk_wait->type & WAIT_POLL) { -+ poll_ctl_kernel_event(sock->sk_wait->epfd, 0, fd, NULL); - } - } - /* shutdown kernel connect, do_connect() has tried both kernel and lwip. */ -diff --git a/src/lstack/include/lstack_epoll.h b/src/lstack/include/lstack_epoll.h -index c6d2eb3..94e872d 100644 ---- a/src/lstack/include/lstack_epoll.h -+++ b/src/lstack/include/lstack_epoll.h -@@ -25,6 +25,7 @@ int lstack_epoll_close(int epfd); - void epoll_api_init(posix_api_t *api); - int epoll_ctl_kernel_event(int epfd, int op, int fd, struct epoll_event *event, - struct sock_wait *sk_wait); -+int poll_ctl_kernel_event(int epfd, int fds_id, int old_fd, const struct pollfd *new_fds); - - bool sock_event_wait(struct lwip_sock *sock, enum netconn_evt evt, bool noblocking); - --- -2.33.0 - diff --git a/0354-sockctl-fix-rtw-broadcast-close-and-shutdown.patch b/0354-sockctl-fix-rtw-broadcast-close-and-shutdown.patch deleted file mode 100644 index ed0d99b13037e16a46cfaefcff20d493f2947cc6..0000000000000000000000000000000000000000 --- a/0354-sockctl-fix-rtw-broadcast-close-and-shutdown.patch +++ /dev/null @@ -1,53 +0,0 @@ -From 930c68e37f09c0ad3f5e56ae5407ad397afc48cb Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 4 Jul 2025 08:58:03 +0800 -Subject: [PATCH] sockctl: fix rtw broadcast close and shutdown - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockctl.c | 8 ++++---- - 1 file changed, 4 insertions(+), 4 deletions(-) - -diff --git a/src/lstack/api/lstack_sockctl.c b/src/lstack/api/lstack_sockctl.c -index 856b24e..a224303 100644 ---- a/src/lstack/api/lstack_sockctl.c -+++ b/src/lstack/api/lstack_sockctl.c -@@ -461,7 +461,7 @@ static int stack_broadcast_close(int fd) - int ret = 0; - struct lwip_sock *sock = lwip_get_socket(fd); - -- while (sock != NULL) { -+ do { - if (POSIX_IS_CLOSED(sock)) { - ret = -1; - break; -@@ -469,7 +469,7 @@ static int stack_broadcast_close(int fd) - fd = sock->conn->callback_arg.socket; - ret |= rpc_call_close(sock->stack_id, fd); - sock = sock->listen_next; -- } -+ } while (sock != NULL); - - if (ret != 0) { - GAZELLE_RETURN(EBADF); -@@ -482,7 +482,7 @@ static int stack_broadcast_shutdown(int fd, int how) - int ret = 0; - struct lwip_sock *sock = lwip_get_socket(fd); - -- while (true) { -+ do { - if (POSIX_IS_CLOSED(sock)) { - ret = -1; - break; -@@ -490,7 +490,7 @@ static int stack_broadcast_shutdown(int fd, int how) - fd = sock->conn->callback_arg.socket; - ret |= rpc_call_shutdown(sock->stack_id, fd, how); - sock = sock->listen_next; -- } -+ } while (sock != NULL); - - if (ret != 0) { - GAZELLE_RETURN(EBADF); --- -2.33.0 - diff --git a/0355-mempool-increase-MEM_THREAD_MANAGER_FREE_S-to-avoid-.patch b/0355-mempool-increase-MEM_THREAD_MANAGER_FREE_S-to-avoid-.patch deleted file mode 100644 index ed3c4f5073eb4bcae63732775ab2ff64d0dca1df..0000000000000000000000000000000000000000 --- a/0355-mempool-increase-MEM_THREAD_MANAGER_FREE_S-to-avoid-.patch +++ /dev/null @@ -1,26 +0,0 @@ -From f807fda71067c85f436a294746afc4a56aebe8fa Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 4 Jul 2025 08:58:37 +0800 -Subject: [PATCH] mempool: increase MEM_THREAD_MANAGER_FREE_S to avoid poll - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_mempool.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index 70ac8c6..3f447f0 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -27,7 +27,7 @@ - #define MEM_THREAD_MAX_PATH 32 /* cat /proc/sys/kernel/pid_max */ - #define MEM_THREAD_FLUSH_SIG (SIGRTMIN + 11) - #define MEM_THREAD_MANAGER_FLUSH_MS 100 --#define MEM_THREAD_MANAGER_FREE_S 2 -+#define MEM_THREAD_MANAGER_FREE_S 20 - #define MEM_THREAD_MANAGER_FREE_MAX 64 - - struct mem_thread_manager { --- -2.33.0 - diff --git a/0356-sockio-fix-callback_tcp_send-output-too-many-at-once.patch b/0356-sockio-fix-callback_tcp_send-output-too-many-at-once.patch deleted file mode 100644 index ee77df0a0cf288283af30cfaed0b361d7e040088..0000000000000000000000000000000000000000 --- a/0356-sockio-fix-callback_tcp_send-output-too-many-at-once.patch +++ /dev/null @@ -1,76 +0,0 @@ -From 0199d6397ae4f6c6fe76ed2d741f3b0e72546af2 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 4 Jul 2025 08:59:39 +0800 -Subject: [PATCH] sockio: fix callback_tcp_send output too many at once - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockio.c | 33 ++++++++++++++++++++++----------- - 1 file changed, 22 insertions(+), 11 deletions(-) - -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 418311e..05e82d7 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -964,36 +964,47 @@ static void callback_tcp_send(struct rpc_msg *sendmsg) - struct protocol_stack *stack = get_protocol_stack(); - struct lwip_sock *sock = sendmsg->args[MSG_ARG_0].p; - struct mem_thread *mt = sendmsg->args[MSG_ARG_1].p; -+ const struct tcp_pcb *pcb = sock->conn->pcb.tcp; -+ const struct mbox_ring *mr = &sock->conn->sendmbox->mring; - bool output_again; - err_t err; - -- if (unlikely(sock->conn->pcb.tcp == NULL)) -+ if (unlikely(pcb == NULL)) - return; - -+#if GAZELLE_TCP_ASYNC_RECVD -+ struct rpc_msg *recvmsg; -+ if (RECVD_UNSUBMITED(sendmsg)) { -+ RECVD_UNSUBMITED(sendmsg) = 0; -+ recvmsg = sock_mbox_private_get(sock->conn->recvmbox); -+ callback_tcp_recvd(recvmsg); -+ } -+#endif /* GAZELLE_TCP_ASYNC_RECVD */ -+ -+ /* If LWIP_MIN(snd_wnd, cwnd) limit output. */ -+ if (pcb->unsent != NULL && pcb->unacked != NULL) { -+ rpc_async_call(&stack->rpc_queue, sendmsg, RPC_MSG_REUSE | RPC_MSG_RECALL); -+ return; -+ } -+ - if (get_protocol_stack_group()->latency_start) - calculate_sock_latency(sock, GAZELLE_LATENCY_WRITE_RPC_MSG); - -+ sendmsg->result = 0; - do { -- if (!lwip_tcp_allow_send(sock->conn->pcb.tcp)) { -+ /* Not output too many bufs at once. */ -+ if (sendmsg->result >= mr->ops->get_capacity(mr) || !lwip_tcp_allow_send(sock->conn->pcb.tcp)) { - rpc_async_call(&stack->rpc_queue, sendmsg, RPC_MSG_REUSE | RPC_MSG_RECALL); - break; - } - sendmsg->result += rtw_stack_tcp_output(sock->conn, &output_again, mt); - } while (output_again); -+ - err = tcp_output(sock->conn->pcb.tcp); - if (unlikely(err != ERR_OK)) { - LSTACK_LOG(ERR, LSTACK, "tcp_output failed, sock %p, err %u\n", sock, err); - } - --#if GAZELLE_TCP_ASYNC_RECVD -- struct rpc_msg *recvmsg; -- if (RECVD_UNSUBMITED(sendmsg)) { -- RECVD_UNSUBMITED(sendmsg) = 0; -- recvmsg = sock_mbox_private_get(sock->conn->recvmbox); -- callback_tcp_recvd(recvmsg); -- } --#endif /* GAZELLE_TCP_ASYNC_RECVD */ -- - return; - } - --- -2.33.0 - diff --git a/0357-sockio-fix-sendmbox-full-return-EWOULDBLOCK.patch b/0357-sockio-fix-sendmbox-full-return-EWOULDBLOCK.patch deleted file mode 100644 index d6d8e13ca8b79cbdc7766203eb9f16c969cd7117..0000000000000000000000000000000000000000 --- a/0357-sockio-fix-sendmbox-full-return-EWOULDBLOCK.patch +++ /dev/null @@ -1,336 +0,0 @@ -From 635e86630da1ebfe5955b1598f8adb5a9d547a2f Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 4 Jul 2025 09:00:42 +0800 -Subject: [PATCH] sockio: fix sendmbox full return EWOULDBLOCK - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 34 ++++++++----- - src/lstack/api/lstack_sockctl.c | 8 +-- - src/lstack/api/lstack_sockio.c | 83 +++++++++++++++++++------------ - src/lstack/include/lstack_epoll.h | 2 +- - 4 files changed, 76 insertions(+), 51 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 949e10b..a07968a 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -439,7 +439,7 @@ int lstack_epoll_wait(int epfd, struct epoll_event* events, int maxevents, int t - lwip_maxevents = sk_wait->kernel_nfds > 0 ? - (maxevents >> 1) + 1 : maxevents; - -- start = sys_now(); -+ start = timeout <= 0 ? 0 : sys_now(); - - /* RTC try to recv polling. */ - sk_wait->timedwait_fn(sk_wait, 0, start); -@@ -732,7 +732,7 @@ int lstack_poll(struct pollfd *fds, nfds_t nfds, int timeout) - return posix_api->poll_fn(fds, nfds, timeout); - } - -- start = sys_now(); -+ start = timeout <= 0 ? 0 : sys_now(); - - /* RTC try to recv polling. */ - sk_wait->timedwait_fn(sk_wait, 0, start); -@@ -861,14 +861,17 @@ void epoll_api_init(posix_api_t *api) - api->select_fn = lstack_select; - } - --bool sock_event_wait(struct lwip_sock *sock, enum netconn_evt evt, bool noblocking) -+bool sock_event_wait(struct lwip_sock *sock, enum netconn_evt evt, bool nonblocking) - { - bool rtc_mode = get_global_cfg_params()->stack_mode_rtc; -- uint32_t start; -- int timeout; - unsigned pending = 0; -+ uint32_t start; -+ int timeout = -1; -+ int old_errno; -+ -+ nonblocking |= netconn_is_nonblocking(sock->conn); - -- if (!rtc_mode && noblocking) -+ if (!rtc_mode && nonblocking) - return false; - - if (unlikely(sock->sk_wait == NULL) || sock->sk_wait->type == WAIT_CLOSE) { -@@ -879,14 +882,21 @@ bool sock_event_wait(struct lwip_sock *sock, enum netconn_evt evt, bool noblocki - rte_wmb(); - } - -+ old_errno = errno; - if (rtc_mode) { - /* RTC try to recv polling. */ - sock->sk_wait->timedwait_fn(sock->sk_wait, 0, 0); -- return true; -+ if (nonblocking) { -+ errno = old_errno; -+ return false; -+ } - } - -- timeout = sock->conn->recv_timeout == 0 ? -1 : sock->conn->recv_timeout; -- start = sys_now(); -+ if (evt == NETCONN_EVT_RCVPLUS && sock->conn->recv_timeout > 0) { -+ timeout = sock->conn->recv_timeout; -+ } -+ -+ start = timeout <= 0 ? 0 : sys_now(); - do { - pending = sock_event_hold_pending(sock, WAIT_BLOCK, evt, 0) | - sock_event_hold_pending(sock, WAIT_BLOCK, NETCONN_EVT_ERROR, 0); -@@ -896,13 +906,11 @@ bool sock_event_wait(struct lwip_sock *sock, enum netconn_evt evt, bool noblocki - timeout = sock->sk_wait->timedwait_fn(sock->sk_wait, timeout, start); - } while (timeout > 0 || (timeout < 0 && errno == 0)); - -- if (errno == ETIMEDOUT) { -- errno = EAGAIN; -- } -- - if (evt == NETCONN_EVT_SENDPLUS) { - /* remove WAIT_BLOCK type */ - sock->sk_wait->type &= ~WAIT_BLOCK; - } -+ -+ errno = old_errno; - return pending != 0; - } -diff --git a/src/lstack/api/lstack_sockctl.c b/src/lstack/api/lstack_sockctl.c -index a224303..906d228 100644 ---- a/src/lstack/api/lstack_sockctl.c -+++ b/src/lstack/api/lstack_sockctl.c -@@ -448,7 +448,7 @@ static int rpc_call_connect(int stack_id, int fd, const struct sockaddr *addr, s - - if (ret < 0 && errno == EINPROGRESS) { - struct lwip_sock *sock = lwip_get_socket(fd); -- if (sock_event_wait(sock, NETCONN_EVT_SENDPLUS, netconn_is_nonblocking(sock->conn))) { -+ if (sock_event_wait(sock, NETCONN_EVT_SENDPLUS, false)) { - ret = 0; - } - } -@@ -585,7 +585,7 @@ static int stack_broadcast_accept4(int fd, struct sockaddr *addr, socklen_t *add - - min_sock = get_min_accept_sock(fd); - if (min_sock == NULL) { -- if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, netconn_is_nonblocking(sock->conn) || (flags & SOCK_NONBLOCK))) { -+ if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, flags & SOCK_NONBLOCK)) { - min_sock = get_min_accept_sock(fd); - } - } -@@ -764,7 +764,7 @@ static int rtc_connect(int s, const struct sockaddr *name, socklen_t namelen) - ret = lwip_connect(s, name, namelen); - if (ret < 0 && errno == EINPROGRESS) { - struct lwip_sock *sock = lwip_get_socket(s); -- if (sock_event_wait(sock, NETCONN_EVT_SENDPLUS, netconn_is_nonblocking(sock->conn))) { -+ if (sock_event_wait(sock, NETCONN_EVT_SENDPLUS, false)) { - ret = 0; - } - } -@@ -782,7 +782,7 @@ static int rtc_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int fla - - ret = lwip_accept4(s, addr, addrlen, flags); - if (ret < 0 && errno == EWOULDBLOCK) { -- if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, netconn_is_nonblocking(sock->conn) || (flags & SOCK_NONBLOCK))) { -+ if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, flags & SOCK_NONBLOCK)) { - ret = lwip_accept4(s, addr, addrlen, flags); - } - } -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 05e82d7..b5b203f 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -359,7 +359,7 @@ static ssize_t stack_udp_write(struct lwip_sock *sock, const void *data, size_t - mr->app_free_count = mr->ops->free_count(mr); - if (unlikely(mr->app_free_count < 1)) { - API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -- set_errno(EWOULDBLOCK); -+ set_errno(ENOBUFS); - return -1; - } - } -@@ -370,7 +370,10 @@ static ssize_t stack_udp_write(struct lwip_sock *sock, const void *data, size_t - copied_total = stack_udp_write_bulk(sock, mr, data, len, flags, to, tolen); - } - -- return copied_total > 0 ? copied_total : -1; -+ if (likely(copied_total > 0)) -+ return copied_total; -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -+ return -1; - } - - static ssize_t stack_udp_output(struct netconn *conn, bool *output_again, struct mem_thread *mt) -@@ -676,7 +679,7 @@ static ssize_t rtw_stack_tcp_write(struct lwip_sock *sock, const char *data, siz - mr->app_free_count = mr->ops->free_count(mr); - if (unlikely(mr->app_free_count < 2)) { - API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -- set_errno(EWOULDBLOCK); -+ set_errno(ENOBUFS); - return -1; - } - } -@@ -709,6 +712,8 @@ static ssize_t rtw_stack_tcp_write(struct lwip_sock *sock, const char *data, siz - } - - out: -+ if (unlikely(total_copy_len > 0)) -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); - return copied_total > 0 ? copied_total : -1; - } - -@@ -1058,11 +1063,6 @@ static ssize_t rtc_stack_tcp_write(struct lwip_sock *sock, const char *data, siz - } - - total_copy_len = LWIP_MIN((uint32_t)len, (uint32_t)pcb->snd_buf); -- if (unlikely(total_copy_len == 0)) { -- API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -- set_errno(EWOULDBLOCK); -- return -1; -- } - - while (total_copy_len > 0) { - if (total_copy_len <= TCP_SND_SIZE_MAX) { -@@ -1074,14 +1074,23 @@ static ssize_t rtc_stack_tcp_write(struct lwip_sock *sock, const char *data, siz - - err = tcp_write(pcb, data + copied_total, buf_copy_len, write_flags | write_more); - if (err != ERR_OK) { -- LSTACK_LOG(ERR, LSTACK, "tcp_write failed, errno %d\n", err_to_errno(err)); - break; - } - total_copy_len -= buf_copy_len; - copied_total += buf_copy_len; - } - -- if (copied_total > 0) { -+ /* if OK or memory error, check available space */ -+ if (err == ERR_OK || err == ERR_MEM) { -+ if (!lwip_tcp_allow_send(sock->conn->pcb.tcp)) { -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -+ err = ERR_BUF; -+ } else if (total_copy_len > 0) { -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -+ } -+ } -+ -+ if (likely(copied_total > 0)) { - return copied_total; - } - set_errno(err_to_errno(err)); -@@ -1120,7 +1129,7 @@ ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, - /* TODO: support MSG_WAITALL */ - recvd = ioops.stack_tcp_read(sock, mem, len, flags, from, fromlen); - if (recvd < 0 && errno == EWOULDBLOCK) { -- if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { -+ if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, flags & MSG_DONTWAIT)) { - recvd = ioops.stack_tcp_read(sock, mem, len, flags, from, fromlen); - } - } -@@ -1140,7 +1149,7 @@ ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, - msg.msg_namelen = (fromlen ? *fromlen : 0); - recvd = ioops.stack_udp_readmsg(sock, &msg, len, flags); - if (recvd < 0 && errno == EWOULDBLOCK) { -- if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { -+ if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, flags & MSG_DONTWAIT)) { - recvd = ioops.stack_udp_readmsg(sock, &msg, len, flags); - } - } -@@ -1186,7 +1195,7 @@ ssize_t sockio_recvmsg(int fd, struct msghdr *msg, int flags) - case NETCONN_UDP: - recvd = ioops.stack_udp_readmsg(sock, msg, len, flags); - if (recvd < 0 && errno == EWOULDBLOCK) { -- if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, netconn_is_nonblocking(sock->conn) || (flags & MSG_DONTWAIT))) { -+ if (sock_event_wait(sock, NETCONN_EVT_RCVPLUS, flags & MSG_DONTWAIT)) { - recvd = ioops.stack_udp_readmsg(sock, msg, len, flags); - } - } -@@ -1220,22 +1229,24 @@ ssize_t sockio_sendto(int fd, const void *mem, size_t len, int flags, - - switch (NETCONN_TYPE(sock->conn)) { - case NETCONN_TCP: -- ret = ioops.stack_tcp_write(sock, mem, len, flags); -- if (ret < 0) { -- if (errno == EWOULDBLOCK) { -- sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); -- } -- } else { -+ do { -+ ret = ioops.stack_tcp_write(sock, mem, len, flags); -+ if (likely(ret > 0) || errno != ENOBUFS) -+ break; -+ sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); -+ } while (true); -+ if (ret > 0) { - ioops.stack_tcp_send(sock); - } - break; - case NETCONN_UDP: -- ret = ioops.stack_udp_write(sock, mem, len, flags, to, tolen); -- if (ret < 0) { -- if (errno == EWOULDBLOCK) { -- sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); -- } -- } else { -+ do { -+ ret = ioops.stack_udp_write(sock, mem, len, flags, to, tolen); -+ if (likely(ret > 0) || errno != ENOBUFS) -+ break; -+ sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); -+ } while (true); -+ if (ret > 0) { - ioops.stack_udp_send(sock); - } - break; -@@ -1271,11 +1282,15 @@ ssize_t sockio_sendmsg(int fd, const struct msghdr *msg, int flags) - if (i == msg->msg_iovlen - 1) { - write_more = 0; - } -- ret = ioops.stack_tcp_write(sock, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags | write_more); -+ do { -+ ret = ioops.stack_tcp_write(sock, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags | write_more); -+ if (likely(ret > 0) || errno != ENOBUFS) -+ break; -+ if (written > 0) -+ ioops.stack_tcp_send(sock); -+ sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); -+ } while (true); - if (ret < 0) { -- if (errno == EWOULDBLOCK) { -- sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); -- } - break; - } - written += ret; -@@ -1289,11 +1304,13 @@ ssize_t sockio_sendmsg(int fd, const struct msghdr *msg, int flags) - if (i == msg->msg_iovlen - 1) { - write_more = 0; - } -- ret = ioops.stack_udp_write(sock, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags | write_more, NULL, 0); -+ do { -+ ret = ioops.stack_udp_write(sock, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len, flags | write_more, NULL, 0); -+ if (likely(ret > 0) || errno != ENOBUFS) -+ break; -+ sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); -+ } while (true); - if (ret < 0) { -- if (errno == EWOULDBLOCK) { -- sock_event_wait(sock, NETCONN_EVT_SENDPLUS, true); -- } - break; - } - written += ret; -diff --git a/src/lstack/include/lstack_epoll.h b/src/lstack/include/lstack_epoll.h -index 94e872d..844ef9d 100644 ---- a/src/lstack/include/lstack_epoll.h -+++ b/src/lstack/include/lstack_epoll.h -@@ -27,6 +27,6 @@ int epoll_ctl_kernel_event(int epfd, int op, int fd, struct epoll_event *event, - struct sock_wait *sk_wait); - int poll_ctl_kernel_event(int epfd, int fds_id, int old_fd, const struct pollfd *new_fds); - --bool sock_event_wait(struct lwip_sock *sock, enum netconn_evt evt, bool noblocking); -+bool sock_event_wait(struct lwip_sock *sock, enum netconn_evt evt, bool nonblocking); - - #endif /* _GAZELLE_EPOLL_H_ */ --- -2.33.0 - diff --git a/0358-sk_wait-igonre-mem_thread-flush-signal.patch b/0358-sk_wait-igonre-mem_thread-flush-signal.patch deleted file mode 100644 index e80b167ca37fef1bf6d6476b5e710e6cf61576ac..0000000000000000000000000000000000000000 --- a/0358-sk_wait-igonre-mem_thread-flush-signal.patch +++ /dev/null @@ -1,112 +0,0 @@ -From f388e26bb66ee37fcfdb0adc357dbb4c98a03b64 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 4 Jul 2025 20:24:36 +0800 -Subject: [PATCH] sk_wait: igonre mem_thread flush signal - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 14 ++++++++++++-- - src/lstack/core/lstack_mempool.c | 15 ++++++++++++++- - src/lstack/include/lstack_mempool.h | 1 + - 3 files changed, 27 insertions(+), 3 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index a07968a..0889f13 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -28,6 +28,7 @@ - #include "lstack_cfg.h" - #include "lstack_log.h" - #include "lstack_protocol_stack.h" -+#include "lstack_mempool.h" - - #define POLL_MAX_EVENTS 32 - -@@ -36,20 +37,29 @@ static PER_THREAD struct sock_wait *g_sk_wait = NULL; - - static int rtc_sock_wait_timedwait(struct sock_wait *sk_wait, int timeout, uint32_t start) - { -+ mem_thread_ignore_flush_intr(); -+ - stack_polling(0); - - if (timeout > 0 && timeout <= (int)(sys_now() - start)) { - timeout = 0; - } else if (timeout < 0) { -- errno = 0; -+ if (errno != EINTR || mem_thread_ignore_flush_intr()) { -+ errno = 0; -+ } - } - return timeout; - } - - static int rtw_sock_wait_timedwait(struct sock_wait *sk_wait, int timeout, uint32_t start) - { -+ int ret; - /* when sem interrupted by signals, errno = EINTR */ -- return sys_sem_wait_internal(&sk_wait->sem, timeout); -+ mem_thread_ignore_flush_intr(); -+ do { -+ ret = sys_sem_wait_internal(&sk_wait->sem, timeout); -+ } while (ret < 0 && errno == EINTR && mem_thread_ignore_flush_intr()); -+ return ret; - } - - static void rtc_epoll_notify_event(struct sock_wait *sk_wait, struct sock_event *sk_event, -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index 3f447f0..ef8e7df 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -45,8 +45,9 @@ struct mem_thread_group { - struct list_node mt_node; - struct mem_thread mt_array[PROTOCOL_STACK_MAX]; - -- bool used_flag; - uint32_t used_time; -+ bool used_flag; -+ bool siged_flag; - }; - - static struct mem_stack g_mem_stack_group[PROTOCOL_STACK_MAX] = {0}; -@@ -106,6 +107,15 @@ static inline void mem_thread_group_done(void) - g_mem_thread_group->used_flag = false; - } - -+bool mem_thread_ignore_flush_intr(void) -+{ -+ if (likely(g_mem_thread_group != NULL) && g_mem_thread_group->siged_flag) { -+ g_mem_thread_group->siged_flag = false; -+ return true; -+ } -+ return false; -+} -+ - static void mem_thread_cache_flush(struct mem_thread *mt); - static unsigned mem_thread_cache_count(const struct mem_thread *mt); - static void mem_thread_group_action_flush(int signum) -@@ -115,6 +125,9 @@ static void mem_thread_group_action_flush(int signum) - - if (g_mem_thread_group == NULL) - return; -+ -+ g_mem_thread_group->siged_flag = true; -+ - if (mem_thread_group_in_used(g_mem_thread_group, MEM_THREAD_MANAGER_FLUSH_MS)) - return; - -diff --git a/src/lstack/include/lstack_mempool.h b/src/lstack/include/lstack_mempool.h -index 6a31503..946edd6 100644 ---- a/src/lstack/include/lstack_mempool.h -+++ b/src/lstack/include/lstack_mempool.h -@@ -300,6 +300,7 @@ int mem_stack_pool_init(int stack_id, unsigned numa_id); - int mem_stack_mpcache_init(int stack_id, unsigned cpu_id); - - int mem_thread_manager_init(void); -+bool mem_thread_ignore_flush_intr(void); - void mem_thread_cache_free(struct mem_thread *mt); - int mem_thread_cache_init(struct mem_thread *mt, int stack_id); - --- -2.33.0 - diff --git a/0359-fix-20.03-LTS-build-failed.patch b/0359-fix-20.03-LTS-build-failed.patch deleted file mode 100644 index 540e4016bdc55bb97afdd3e08d302f786d2e0c2c..0000000000000000000000000000000000000000 --- a/0359-fix-20.03-LTS-build-failed.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 39557d189a97a30a63f76b16eb2daee9c52cbc47 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Sun, 6 Jul 2025 17:00:49 +0800 -Subject: [PATCH] fix 20.03-LTS build failed - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_mempool.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/src/lstack/core/lstack_mempool.c b/src/lstack/core/lstack_mempool.c -index ef8e7df..4388722 100644 ---- a/src/lstack/core/lstack_mempool.c -+++ b/src/lstack/core/lstack_mempool.c -@@ -13,6 +13,7 @@ - #include - - #include -+#include - #include - - #include "lstack_mempool.h" --- -2.33.0 - diff --git a/0360-sockio-fix-tcp_write-not-remove-EPOLLOUT.patch b/0360-sockio-fix-tcp_write-not-remove-EPOLLOUT.patch deleted file mode 100644 index 0ab7cf9264b6bcf06167825f42d06dd88eb33070..0000000000000000000000000000000000000000 --- a/0360-sockio-fix-tcp_write-not-remove-EPOLLOUT.patch +++ /dev/null @@ -1,108 +0,0 @@ -From 25e83b84417d5b609ea0d639a9a87d6602b101bf Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 7 Jul 2025 14:27:16 +0800 -Subject: [PATCH] sockio: fix tcp_write not remove EPOLLOUT - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockio.c | 20 +++++++++++--------- - src/lstack/core/lstack_wait.c | 2 +- - src/lstack/include/lstack_wait.h | 2 ++ - 3 files changed, 14 insertions(+), 10 deletions(-) - -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index b5b203f..424cc82 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -355,9 +355,9 @@ static ssize_t stack_udp_write(struct lwip_sock *sock, const void *data, size_t - return -1; - } - -- if (unlikely(mr->app_free_count < 1)) { -+ if (unlikely(mr->app_free_count < SOCK_SENDMBOX_ALLOW_WRITE_SIZE)) { - mr->app_free_count = mr->ops->free_count(mr); -- if (unlikely(mr->app_free_count < 1)) { -+ if (unlikely(mr->app_free_count < SOCK_SENDMBOX_ALLOW_WRITE_SIZE)) { - API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); - set_errno(ENOBUFS); - return -1; -@@ -370,9 +370,12 @@ static ssize_t stack_udp_write(struct lwip_sock *sock, const void *data, size_t - copied_total = stack_udp_write_bulk(sock, mr, data, len, flags, to, tolen); - } - -+ if (mr->app_free_count < SOCK_SENDMBOX_ALLOW_NOTIFY_SIZE) { -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -+ } -+ - if (likely(copied_total > 0)) - return copied_total; -- API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); - return -1; - } - -@@ -674,10 +677,10 @@ static ssize_t rtw_stack_tcp_write(struct lwip_sock *sock, const char *data, siz - return -1; - } - -- if (unlikely(mr->app_free_count < 2) || -+ if (unlikely(mr->app_free_count < SOCK_SENDMBOX_ALLOW_WRITE_SIZE) || - total_copy_len > mr->app_free_count * TCP_MSS) { - mr->app_free_count = mr->ops->free_count(mr); -- if (unlikely(mr->app_free_count < 2)) { -+ if (unlikely(mr->app_free_count < SOCK_SENDMBOX_ALLOW_WRITE_SIZE)) { - API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); - set_errno(ENOBUFS); - return -1; -@@ -712,8 +715,9 @@ static ssize_t rtw_stack_tcp_write(struct lwip_sock *sock, const char *data, siz - } - - out: -- if (unlikely(total_copy_len > 0)) -+ if (mr->app_free_count < SOCK_SENDMBOX_ALLOW_NOTIFY_SIZE) { - API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); -+ } - return copied_total > 0 ? copied_total : -1; - } - -@@ -1082,11 +1086,9 @@ static ssize_t rtc_stack_tcp_write(struct lwip_sock *sock, const char *data, siz - - /* if OK or memory error, check available space */ - if (err == ERR_OK || err == ERR_MEM) { -+ API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); - if (!lwip_tcp_allow_send(sock->conn->pcb.tcp)) { -- API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); - err = ERR_BUF; -- } else if (total_copy_len > 0) { -- API_EVENT(sock->conn, NETCONN_EVT_SENDMINUS, 0); - } - } - -diff --git a/src/lstack/core/lstack_wait.c b/src/lstack/core/lstack_wait.c -index 4714742..855f2ed 100644 ---- a/src/lstack/core/lstack_wait.c -+++ b/src/lstack/core/lstack_wait.c -@@ -380,7 +380,7 @@ static inline bool NETCONN_ALLOW_SEND(const struct lwip_sock *sock) - } else { /* if RTW */ - if (sys_mbox_valid(&sock->conn->sendmbox)) { - const struct mbox_ring *mr = &sock->conn->sendmbox->mring; -- return mr->ops->free_count(mr) > 0; -+ return mr->ops->free_count(mr) >= SOCK_SENDMBOX_ALLOW_NOTIFY_SIZE; - } - } - -diff --git a/src/lstack/include/lstack_wait.h b/src/lstack/include/lstack_wait.h -index 8ed2e93..dca22b6 100644 ---- a/src/lstack/include/lstack_wait.h -+++ b/src/lstack/include/lstack_wait.h -@@ -30,6 +30,8 @@ - #include "lstack_protocol_stack.h" - #include "lstack_cfg.h" - -+#define SOCK_SENDMBOX_ALLOW_WRITE_SIZE 4 -+#define SOCK_SENDMBOX_ALLOW_NOTIFY_SIZE 16 - - #define NETCONN_TYPE(conn) NETCONNTYPE_GROUP(netconn_type((conn))) - --- -2.33.0 - diff --git a/0361-sockio-fix-rpc_send-coredump-after-RPC_MSG_EXIT.patch b/0361-sockio-fix-rpc_send-coredump-after-RPC_MSG_EXIT.patch deleted file mode 100644 index 09e1faa5dec930224c75335c5a34f0f6891cd82a..0000000000000000000000000000000000000000 --- a/0361-sockio-fix-rpc_send-coredump-after-RPC_MSG_EXIT.patch +++ /dev/null @@ -1,335 +0,0 @@ -From ebbd5e477c3cdb5a561f79a09983b5beabb74c0e Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 8 Jul 2025 14:04:29 +0800 -Subject: [PATCH] sockio: fix rpc_send coredump after RPC_MSG_EXIT - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_sockio.c | 64 ++++++++++++++++++++++------- - src/lstack/api/lstack_wrap.c | 22 +++++----- - src/lstack/include/lstack_mempool.h | 6 +-- - src/lstack/include/lstack_sockio.h | 17 +------- - 4 files changed, 65 insertions(+), 44 deletions(-) - -diff --git a/src/lstack/api/lstack_sockio.c b/src/lstack/api/lstack_sockio.c -index 424cc82..ce22134 100644 ---- a/src/lstack/api/lstack_sockio.c -+++ b/src/lstack/api/lstack_sockio.c -@@ -443,6 +443,11 @@ static void callback_udp_send(struct rpc_msg *msg) - struct mem_thread *mt = msg->args[MSG_ARG_1].p; - bool output_again; - -+ if (unlikely(POSIX_IS_CLOSED(sock))) { -+ msg->result = -1; -+ return; -+ } -+ - if (get_protocol_stack_group()->latency_start) - calculate_sock_latency(sock, GAZELLE_LATENCY_WRITE_RPC_MSG); - -@@ -922,6 +927,11 @@ static void callback_tcp_recvd(struct rpc_msg *recvmsg) - struct mbox_ring *mr; - u32_t recvd; - -+ if (unlikely(POSIX_IS_CLOSED(sock))) { -+ recvmsg->result = -1; -+ return; -+ } -+ - mr = &sock->conn->recvmbox->mring; - if (mr->flags & MBOX_FLAG_PEEK) { - sockio_peek_recv_free(mr, 0); -@@ -973,13 +983,21 @@ static void callback_tcp_send(struct rpc_msg *sendmsg) - struct protocol_stack *stack = get_protocol_stack(); - struct lwip_sock *sock = sendmsg->args[MSG_ARG_0].p; - struct mem_thread *mt = sendmsg->args[MSG_ARG_1].p; -- const struct tcp_pcb *pcb = sock->conn->pcb.tcp; -- const struct mbox_ring *mr = &sock->conn->sendmbox->mring; -+ const struct tcp_pcb *pcb; -+ const struct mbox_ring *mr; - bool output_again; - err_t err; - -- if (unlikely(pcb == NULL)) -+ if (unlikely(POSIX_IS_CLOSED(sock))) { -+ sendmsg->result = -1; -+ return; -+ } -+ mr = &sock->conn->sendmbox->mring; -+ pcb = sock->conn->pcb.tcp; -+ if (unlikely(pcb == NULL)) { -+ sendmsg->result = -1; - return; -+ } - - #if GAZELLE_TCP_ASYNC_RECVD - struct rpc_msg *recvmsg; -@@ -1105,7 +1123,7 @@ static void rtc_stack_tcp_send(struct lwip_sock *sock) - } - - --ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, -+static ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, - struct sockaddr *from, socklen_t *fromlen) - { - struct lwip_sock *sock = lwip_get_socket(fd); -@@ -1167,7 +1185,7 @@ ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, - return recvd; - } - --ssize_t sockio_recvmsg(int fd, struct msghdr *msg, int flags) -+static ssize_t sockio_recvmsg(int fd, struct msghdr *msg, int flags) - { - struct lwip_sock *sock = lwip_get_socket(fd); - ssize_t len, recvd = 0; -@@ -1210,7 +1228,7 @@ ssize_t sockio_recvmsg(int fd, struct msghdr *msg, int flags) - return recvd; - } - --ssize_t sockio_sendto(int fd, const void *mem, size_t len, int flags, -+static ssize_t sockio_sendto(int fd, const void *mem, size_t len, int flags, - const struct sockaddr *to, socklen_t tolen) - { - struct lwip_sock *sock = lwip_get_socket(fd); -@@ -1260,7 +1278,7 @@ ssize_t sockio_sendto(int fd, const void *mem, size_t len, int flags, - return ret; - } - --ssize_t sockio_sendmsg(int fd, const struct msghdr *msg, int flags) -+static ssize_t sockio_sendmsg(int fd, const struct msghdr *msg, int flags) - { - struct lwip_sock *sock = lwip_get_socket(fd); - ssize_t ret = -1; -@@ -1329,27 +1347,27 @@ ssize_t sockio_sendmsg(int fd, const struct msghdr *msg, int flags) - return written > 0 ? written : ret; - } - --ssize_t sockio_read(int fd, void *mem, size_t len) -+static ssize_t sockio_read(int fd, void *mem, size_t len) - { - return sockio_recvfrom(fd, mem, len, 0, NULL, NULL); - } - --ssize_t sockio_write(int fd, const void *mem, size_t len) -+static ssize_t sockio_write(int fd, const void *mem, size_t len) - { - return sockio_sendto(fd, mem, len, 0, NULL, 0); - } - --ssize_t sockio_recv(int fd, void *mem, size_t len, int flags) -+static ssize_t sockio_recv(int fd, void *mem, size_t len, int flags) - { - return sockio_recvfrom(fd, mem, len, flags, NULL, NULL); - } - --ssize_t sockio_send(int fd, const void *mem, size_t len, int flags) -+static ssize_t sockio_send(int fd, const void *mem, size_t len, int flags) - { - return sockio_sendto(fd, mem, len, flags, NULL, 0); - } - --ssize_t sockio_readv(int fd, const struct iovec *iov, int iovcnt) -+static ssize_t sockio_readv(int fd, const struct iovec *iov, int iovcnt) - { - struct msghdr msg; - -@@ -1364,7 +1382,7 @@ ssize_t sockio_readv(int fd, const struct iovec *iov, int iovcnt) - return sockio_recvmsg(fd, &msg, 0); - } - --ssize_t sockio_writev(int fd, const struct iovec *iov, int iovcnt) -+static ssize_t sockio_writev(int fd, const struct iovec *iov, int iovcnt) - { - struct msghdr msg; - -@@ -1379,7 +1397,7 @@ ssize_t sockio_writev(int fd, const struct iovec *iov, int iovcnt) - return sockio_sendmsg(fd, &msg, 0); - } - --void sockio_ops_init(void) -+static void sockio_ops_init(void) - { - struct sockio_ops *ops = &ioops; - -@@ -1400,6 +1418,24 @@ void sockio_ops_init(void) - } - } - -+void sockio_api_init(posix_api_t *api) -+{ -+ sockio_ops_init(); -+ -+ api->recvfrom_fn = sockio_recvfrom; -+ api->recvmsg_fn = sockio_recvmsg; -+ api->sendto_fn = sockio_sendto; -+ api->sendmsg_fn = sockio_sendmsg; -+ -+ api->read_fn = sockio_read; -+ api->write_fn = sockio_write; -+ api->recv_fn = sockio_recv; -+ api->send_fn = sockio_send; -+ -+ api->readv_fn = sockio_readv; -+ api->writev_fn = sockio_writev; -+} -+ - static int sockio_mbox_init(struct lwip_sock *sock) - { - int ret; -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 6523dc2..95279da 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -53,7 +53,7 @@ void wrap_api_init(void) - } - - epoll_api_init(g_wrap_api); -- sockio_ops_init(); -+ sockio_api_init(g_wrap_api); - mbox_ring_ops_init(); - } - -@@ -566,7 +566,7 @@ static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) - static inline ssize_t do_recv(int32_t sockfd, void *buf, size_t len, int32_t flags) - { - if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -- return sockio_recv(sockfd, buf, len, flags); -+ return g_wrap_api->recv_fn(sockfd, buf, len, flags); - } - return posix_api->recv_fn(sockfd, buf, len, flags); - } -@@ -574,7 +574,7 @@ static inline ssize_t do_recv(int32_t sockfd, void *buf, size_t len, int32_t fla - static inline ssize_t do_read(int32_t s, void *mem, size_t len) - { - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return sockio_read(s, mem, len); -+ return g_wrap_api->read_fn(s, mem, len); - } - return posix_api->read_fn(s, mem, len); - } -@@ -582,7 +582,7 @@ static inline ssize_t do_read(int32_t s, void *mem, size_t len) - static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) - { - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return sockio_readv(s, iov, iovcnt); -+ return g_wrap_api->readv_fn(s, iov, iovcnt); - } - return posix_api->readv_fn(s, iov, iovcnt); - } -@@ -590,7 +590,7 @@ static inline ssize_t do_readv(int32_t s, const struct iovec *iov, int iovcnt) - static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32_t flags) - { - if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -- return sockio_send(sockfd, buf, len, flags); -+ return g_wrap_api->send_fn(sockfd, buf, len, flags); - } - return posix_api->send_fn(sockfd, buf, len, flags); - } -@@ -598,7 +598,7 @@ static inline ssize_t do_send(int32_t sockfd, const void *buf, size_t len, int32 - static inline ssize_t do_write(int32_t s, const void *mem, size_t size) - { - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return sockio_write(s, mem, size); -+ return g_wrap_api->write_fn(s, mem, size); - } - return posix_api->write_fn(s, mem, size); - } -@@ -606,7 +606,7 @@ static inline ssize_t do_write(int32_t s, const void *mem, size_t size) - static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) - { - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return sockio_writev(s, iov, iovcnt); -+ return g_wrap_api->writev_fn(s, iov, iovcnt); - } - return posix_api->writev_fn(s, iov, iovcnt); - } -@@ -614,7 +614,7 @@ static inline ssize_t do_writev(int32_t s, const struct iovec *iov, int iovcnt) - static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flags) - { - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return sockio_recvmsg(s, message, flags); -+ return g_wrap_api->recvmsg_fn(s, message, flags); - } - return posix_api->recvmsg_fn(s, message, flags); - } -@@ -622,7 +622,7 @@ static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flag - static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_t flags) - { - if (select_sock_posix_path(lwip_get_socket(s)) == POSIX_LWIP) { -- return sockio_sendmsg(s, message, flags); -+ return g_wrap_api->sendmsg_fn(s, message, flags); - } - return posix_api->sendmsg_fn(s, message, flags); - } -@@ -631,7 +631,7 @@ static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t - struct sockaddr *addr, socklen_t *addrlen) - { - if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -- return sockio_recvfrom(sockfd, buf, len, flags, addr, addrlen); -+ return g_wrap_api->recvfrom_fn(sockfd, buf, len, flags, addr, addrlen); - } - return posix_api->recvfrom_fn(sockfd, buf, len, flags, addr, addrlen); - } -@@ -640,7 +640,7 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int - const struct sockaddr *addr, socklen_t addrlen) - { - if (select_sock_posix_path(lwip_get_socket(sockfd)) == POSIX_LWIP) { -- return sockio_sendto(sockfd, buf, len, flags, addr, addrlen); -+ return g_wrap_api->sendto_fn(sockfd, buf, len, flags, addr, addrlen); - } - return posix_api->sendto_fn(sockfd, buf, len, flags, addr, addrlen); - } -diff --git a/src/lstack/include/lstack_mempool.h b/src/lstack/include/lstack_mempool.h -index 946edd6..5e489e4 100644 ---- a/src/lstack/include/lstack_mempool.h -+++ b/src/lstack/include/lstack_mempool.h -@@ -10,8 +10,8 @@ - * See the Mulan PSL v2 for more details. - */ - --#ifndef __GAZELLE_MEM_H__ --#define __GAZELLE_MEM_H__ -+#ifndef __GAZELLE_MEMPOOL_H__ -+#define __GAZELLE_MEMPOOL_H__ - - #include - -@@ -336,4 +336,4 @@ void mem_extcache_flush_pbuf(struct pbuf **extcache_list); - void mem_init_pbuf(struct pbuf *p, pbuf_layer layer, uint16_t tot_len, uint16_t len, pbuf_type type); - - --#endif /* __GAZELLE_MEM_H__ */ -\ No newline at end of file -+#endif /* __GAZELLE_MEMPOOL_H__ */ -\ No newline at end of file -diff --git a/src/lstack/include/lstack_sockio.h b/src/lstack/include/lstack_sockio.h -index 265d620..2e4a8b1 100644 ---- a/src/lstack/include/lstack_sockio.h -+++ b/src/lstack/include/lstack_sockio.h -@@ -16,22 +16,7 @@ - #include - #include - --ssize_t sockio_recvfrom(int fd, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); --ssize_t sockio_recvmsg(int fd, struct msghdr *msg, int flags); --ssize_t sockio_sendto(int fd, const void *mem, size_t len, int flags, const struct sockaddr *to, socklen_t tolen); --ssize_t sockio_sendmsg(int fd, const struct msghdr *msg, int flags); -- --ssize_t sockio_read(int fd, void *mem, size_t len); --ssize_t sockio_write(int fd, const void *mem, size_t len); -- --ssize_t sockio_recv(int fd, void *mem, size_t len, int flags); --ssize_t sockio_send(int fd, const void *mem, size_t len, int flags); -- --ssize_t sockio_readv(int fd, const struct iovec *iov, int iovcnt); --ssize_t sockio_writev(int fd, const struct iovec *iov, int iovcnt); -- -- --void sockio_ops_init(void); -+void sockio_api_init(posix_api_t *api); - bool sockio_mbox_pending(struct lwip_sock *sock); - - /* just for lwip */ --- -2.33.0 - diff --git a/gazelle-1.0.2.tar.gz b/gazelle-1.0.2.tar.gz deleted file mode 100644 index ad49dd50819937aaddf81b133df171cc0bbe6ac8..0000000000000000000000000000000000000000 Binary files a/gazelle-1.0.2.tar.gz and /dev/null differ diff --git a/gazelle-1.0.3.tar.gz b/gazelle-1.0.3.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..5230c8f6156636aaee878afa8e073e91ad9d6321 Binary files /dev/null and b/gazelle-1.0.3.tar.gz differ diff --git a/gazelle.spec b/gazelle.spec index b31e4776d9e584b9cb9d42ace3845db31947c57f..649d843eb9349b3145d1e913c845073ad0cf13d6 100644 --- a/gazelle.spec +++ b/gazelle.spec @@ -1,15 +1,15 @@ %define conf_path %{_sysconfdir}/%{name} Name: gazelle -Version: 1.0.2 -Release: 85 +Version: 1.0.3 +Release: 1 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-63 +BuildRequires: lwip >= 2.2.0-73 BuildRequires: dpdk-devel >= 21.11-5 BuildRequires: numactl-devel libpcap-devel libconfig-devel libboundscheck uthash-devel %ifarch ppc64le @@ -19,365 +19,6 @@ BuildRequires: libarchive libarchive-devel Requires: dpdk >= 21.11-5 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 -Patch9003: 0003-set-localhost-ip-when-bind-ip-is-same-as-ip-in-lstac.patch -Patch9004: 0004-refactoring-preload-module.patch -Patch9005: 0005-fix-previous-commit-refactoring-preload-module.patch -Patch9006: 0006-add-lstack_preload.c-to-makefile.patch -Patch9007: 0007-cosmetic-changes.patch -Patch9008: 0008-add-loongarch64-and-sw64-arch-support.patch -Patch9009: 0009-CFG-fixed-the-dpdk-primary-default-parameter.patch -Patch9010: 0010-suport-clang-build.patch -Patch9011: 0011-ethdev-fix-pbuf-chain-tot_len-incorrect.patch -Patch9012: 0012-kernelevent-kernel-event-thread-report-kernel-events.patch -Patch9013: 0013-fix-bond-port-reta_size-init.patch -Patch9014: 0014-init-remove-sync-sem-between-lstack-thread-and-main-.patch -Patch9015: 0015-lstack_lwip-external-api-start-with-do_lwip_-prefix.patch -Patch9016: 0016-cfg-nic-rx-tx-queue-size-configure.patch -Patch9017: 0017-epoll-distinguish-add-del_sock_event-and-add-del_soc.patch -Patch9018: 0018-preload-support-thread-hijacking-mode.patch -Patch9019: 0019-cfg-add-run-to-completion-mode-configure.patch -Patch9020: 0020-statck-the-for-loop-in-lstack-thread-is-defined-as-s.patch -Patch9021: 0021-delete_rule-bug.patch -Patch9022: 0022-tools-gazelle_setup-adapt-non-ltran-mode.patch -Patch9023: 0023-wrap-add-run-to-completion-wakeup-mode-api.patch -Patch9024: 0024-fix-arping-gazelle-return-value-is-1.patch -Patch9025: 0025-init-stack-setup-in-app-thread-when-app-call-socket-.patch -Patch9026: 0026-epoll-adapt-epoll-interface-for-rtc-mode.patch -Patch9027: 0027-clean-useless-code.patch -Patch9028: 0028-ethdev-fix-arp-unicast-packets-cannot-be-transmitted.patch -Patch9029: 0029-stack-add-semaphore-to-ensure-all-stack-threads-setu.patch -Patch9030: 0030-ethdev-register-offload-to-netif.patch -Patch9031: 0031-epoll-fix-epollet-mode-error.patch -Patch9032: 0032-bond6.patch -Patch9033: 0033-cfg-fix-bond_mode-null.patch -Patch9034: 0034-dfx-add-four-snmp-udp-datas.patch -Patch9035: 0035-cfg-nic-queue-size-only-support-power-of-2.patch -Patch9036: 0036-stack-fix-possible-coredump-when-arp-packet-broadcas.patch -Patch9037: 0037-Fix-coredump-issue-and-skip-rte_pdump_init-for-secon.patch -Patch9038: 0038-solve-problem-that-rte_pktmbuf_poll_creat-in-same-nu.patch -Patch9040: 0040-when-timeout-occurs-process-exits.patch -Patch9041: 0041-wrap-support-select.patch -Patch9042: 0042-add-vlan-support.patch -Patch9043: 0043-slave-mac-addr.patch -Patch9044: 0044-PRE_LOG-modify-prelog-info-transfer-to-terminal-at-t.patch -Patch9045: 0045-ethdev-mbuf-data-start-pointer-pbuf-payload.patch -Patch9047: 0047-cfg-fix-lstack-mempool-lookup-failed-in-ltran-mode.patch -Patch9048: 0048-add-tx-package-timeout.patch -Patch9049: 0049-modif-mem.patch -Patch9050: 0050-enable-ipv6.patch -Patch9051: 0051-wrap-dont-hijack-select-temporarily.patch -Patch9052: 0052-ipv6.patch -Patch9053: 0053-add-gazelle-log.patch -Patch9054: 0054-PRE_LOG-modify-log-info-while-there-are-repeated-ite.patch -Patch9055: 0055-add-gazelle-log.patch -Patch9056: 0056-wrap-fix-connect-wrong-port-after-addr-bind-two-port.patch -Patch9057: 0057-cfg-rm-ipv6_enable.patch -Patch9058: 0058-ltran-support-vlan.patch -Patch9059: 0059-update-src-ltran-ltran_param.c.patch -Patch9060: 0060-dfx-support-bond-get-dpdk-xstats.patch -Patch9061: 0061-add-tcp-faste-timer-cnt.patch -Patch9062: 0062-stack-fix-coredump-caused-by-gazelleclt-in-rtc-mode.patch -Patch9063: 0063-dfx-add-tcp-exception-and-kernel-event-statistics.patch -Patch9064: 0064-add-vlan_id-in-netif.patch -Patch9065: 0065-support-vlan-offload.patch -Patch9066: 0066-gazellectl-fix-gazellectl-lstack-show-1-r-error.patch -Patch9067: 0067-fix-coredump-because-sock-closed-before-send-data-fu.patch -Patch9068: 0068-fix-compilation-error.patch -Patch9069: 0069-fix-coredump-because-of-addr-null-in-lwip_fill_sendr.patch -Patch9070: 0070-add-struct-gz_addr_t.patch -Patch9071: 0071-wrap-support-shutdown.patch -Patch9072: 0072-1.solve-the-problem-of-1w-connection-not-being-able-.patch -Patch9073: 0073-dfx-gazellectl-c-support-ipv6.patch -Patch9074: 0074-The-call-stack-is-not-printed-in-the-proactive-exit-.patch -Patch9075: 0075-dfx-fix-gazellectl-lstack-show-ip-failed.patch -Patch9076: 0076-gazellectl-add-connect-para.patch -Patch9077: 0077-log-optimize-lstack-log.patch -Patch9078: 0078-support-show-nic-offload-and-features.patch -Patch9079: 0079-Fixed-an-issue-where-no-packet-is-sent-or-received-w.patch -Patch9080: 0080-fix-example-print-error.patch -Patch9081: 0081-dfx-fix-kernel_events-stat.patch -Patch9082: 0082-add-keep-alive-info.patch -Patch9083: 0083-fix-close-can-t-exit.patch -Patch9084: 0084-mod-unix-time-stamp-to-local-time.patch -Patch9085: 0085-optimize-gazelle-exit-process.patch -Patch9086: 0086-fix-EPOLLIN-event-error.patch -Patch9087: 0087-mod-time-err.patch -Patch9088: 0088-fix-gazellectl-lstack-show-ip-r-with-ltran-error-log.patch -Patch9089: 0089-fix-udp-multicast-bind-error.patch -Patch9090: 0090-support-netperf.patch -Patch9091: 0091-fix-alloc-not-free.patch -Patch9092: 0092-sigaction-fix-deprecated-signal-flags.patch -Patch9093: 0093-fix-gazellectl-c-msg-error.patch -Patch9094: 0094-CFG-fix-check-func-strdup-return-value-is-NULL.patch -Patch9095: 0095-fix-func-separate_str_to_array-overflow-problem.patch -Patch9096: 0096-use-default-nonblock-mode.patch -Patch9097: 0097-fix-rte_ring_create-free-time-consuming.patch -Patch9098: 0098-optimize-shutdown-exit-process.patch -Patch9099: 0099-fix-func-separate_str_to_array-overflow-problem.patch -Patch9100: 0100-fix-func-separate_str_to_array-overflow-problem.patch -Patch9101: 0101-fix-func-separate_str_to_array-overflow-problem.patch -Patch9102: 0102-fix-func-separate_str_to_array-overflow-problem.patch -Patch9103: 0103-fix-func-stack_setup_thread-array-doesn-t-init.patch -Patch9104: 0104-fix-stack_setup_thread-array-range.patch -Patch9105: 0105-fix-func-separate_str_to_array-overflow-problem.patch -Patch9106: 0106-fix-dpdk_alloc_pktmbuf-time-consuming.patch -Patch9107: 0107-ltran-optimize-config-file-error-message.patch -Patch9108: 0108-replace-with-gz_addr_t.patch -Patch9109: 0109-match_host_addr-func-support-ipv6.patch -Patch9110: 0110-add-example-keep-alive-interval-para.patch -Patch9111: 0111-update-src-common-dpdk_common.c.patch -Patch9112: 0112-listen_shadow-support-ipv6.patch -Patch9113: 0113-lstack_dpdk-limit-mbuf-max-num.patch -Patch9114: 0114-gazellectl-add-tcp_input-empty-ack-cnt.patch -Patch9115: 0115-add-socket-accept-fail-cnt.patch -Patch9116: 0116-diff-lstack-and-ltran-dfx-sock.patch -Patch9117: 0117-fix-host_addr6-can-be-assigned-a-multicast-address.patch -Patch9118: 0118-udp-do-not-merge-data-into-last-pbuf.patch -Patch9119: 0119-adpat-dpdk-23.11.patch -Patch9120: 0120-modify-conf-vlan-default-vlaue.patch -Patch9121: 0121-remove-unused-variables-in-pbuf-and-reduce-mbuf-size.patch -Patch9122: 0122-optimize-recv-exit-process-for-FIN-and-unsupport-SO_.patch -Patch9123: 0123-remove-expand_send_ring.patch -Patch9124: 0124-set-ltran.patch -Patch9125: 0125-add-bond-doc.patch -Patch9126: 0126-cfg-host_addr-is-not-mandatory.patch -Patch9127: 0127-add-bond1-support.patch -Patch9128: 0128-fix-t_params-double-free.patch -Patch9129: 0129-fix-receive-fin-packet-process-error.patch -Patch9130: 0130-support-netperf-UDP_STREAM-and-UDP_RR.patch -Patch9131: 0131-adapt-lwip-2.2.0.patch -Patch9132: 0132-add-observable-method-of-data-aggregation.patch -Patch9133: 0133-try-to-ensure-arp-packet-can-be-sent.patch -Patch9134: 0134-gazellectl-support-send-latency-show.patch -Patch9135: 0135-rpc-function-does-not-depend-on-protocol-stack.patch -Patch9136: 0136-readv-return-1-errno-is-EAGAIN-when-recvring-no-data.patch -Patch9137: 0137-split-the-flow-fules-related-functions-into-separate.patch -Patch9138: 0138-fix-coreddump-when-stack-setup-failed-in-rtc-mode.patch -Patch9139: 0139-diff-udp-and-tcp-read-from-stack.patch -Patch9140: 0140-FAULT-INJECT-gazelle-add-packet-delay-and-packet-dro.patch -Patch9141: 0141-recv-support-MSG_DONTWAIT.patch -Patch9142: 0142-do_setsockopt-function-no-longer-checks-the-results-.patch -Patch9143: 0143-FAUT-INJECT-add-fault-inject-unset-method.patch -Patch9144: 0144-support-udp-pkglen-mtu.patch -Patch9145: 0145-add-limit-with-level-for-sockopt.patch -Patch9146: 0146-udp-add-restriction-message-too-long.patch -Patch9147: 0147-dfx-improve-log-readability-when-connect-ltran-lstac.patch -Patch9148: 0148-fix-rpc_pool-create-failed-coredump.patch -Patch9149: 0149-ensure-the-bond-interface-flow_type_rss_offloads-mat.patch -Patch9150: 0150-FAULT-INJECT-add-duplicate-and-reorder-methods.patch -Patch9151: 0151-select-timeout-arguments-check.patch -Patch9152: 0152-recvfrom-support-timeout.patch -Patch9153: 0153-fix-netperf-setsockopt-fail.patch -Patch9154: 0154-fix-LATENCY_WRITE-increase-in-recv-process.patch -Patch9155: 0155-dpdk-add-vlan-filter.patch -Patch9156: 0156-Correcting-spelling-errors.patch -Patch9157: 0157-perftool-add-lhist-statstic-tool.patch -Patch9158: 0158-add-udp-poll.patch -Patch9159: 0159-DFX-adapt-testcase-for-gazellectl-connect-failed.patch -Patch9160: 0160-warp-add-configuration-check-with-host_addr-and-serv.patch -Patch9161: 0161-add-latency-nodes-READ_APP_CALL-WRITE_RPC_MSG.patch -Patch9162: 0162-fix-vlan-filter-can-be-added-when-vlan_mode-1.patch -Patch9163: 0163-Add-support-for-arch-ppc64le.patch -Patch9164: 0164-dfx-support-get-nic-bond-status.patch -Patch9165: 0165-remove-dpdk_skip_nic_init-for-dpdk-23.11.patch -Patch9166: 0166-gazellectl-add-lwip-stats_proto-print.patch -Patch9167: 0167-fix-port-not-support-vlan-filter.patch -Patch9168: 0168-fix-tcp-recv-does-not-return-pkg-when-ring-buffer-is.patch -Patch9169: 0169-add-tuple_fileter-error-info.patch -Patch9170: 0170-adapt-dpdk-23.11-remove-kni.patch -Patch9171: 0171-fix-ioctl-set-failed.patch -Patch9172: 0172-ltran-memset-quintuple.patch -Patch9173: 0173-gazellectl-add-lwip-stats_proto-print.patch -Patch9174: 0174-CFG-set-multicast-IP-assert.patch -Patch9175: 0175-cfg-devices-must-be-in-bond_slave_mac-for-BONDING_MO.patch -Patch9176: 0176-CFG-fix-multicast-IP-assert-error.patch -Patch9177: 0177-fix-mbuf-leak-in-dpdk-23.11-due-to-kni-removed.patch -Patch9178: 0178-add-riscv64-support.patch -Patch9179: 0179-dfx-fix-gazellectl-x-for-bond.patch -Patch9180: 0180-change-gazelle_stat_lstack_proto-from-u16-to-u64.patch -Patch9181: 0181-memary-error-fix-some-memary-error.patch -Patch9182: 0182-bond-remove-bond-initialization-code-in-dpdk_ethdev_.patch -Patch9183: 0183-make-rpc_msg_max-recv_ring_size-configurable.patch -Patch9184: 0184-EPOLL-fix-coredump-while-event-count-exceed-maxevent.patch -Patch9185: 0185-fix-fin-pack-free-coredump.patch -Patch9186: 0186-fix-MySQL-shutdown-cmd.patch -Patch9187: 0187-cfg-remove-map-perfect-flag-in-lstack.conf.patch -Patch9188: 0188-redis-perf-add-tx-driver-cache.patch -Patch9189: 0189-optimized-latency-distribution-dotting.patch -Patch9190: 0190-rtc-adapt-rtc_close.patch -Patch9191: 0191-virtio-flow_bifurcation-switch.patch -Patch9192: 0192-remove-legacy-mem.patch -Patch9193: 0193-cfg-bond_slave_mac-support-pci-addr.patch -Patch9194: 0194-refactor-tx-cache-module.patch -Patch9195: 0195-virtio-create-and-init-virtio_port.patch -Patch9196: 0196-refactor-udp-send.patch -Patch9197: 0197-solve-compile-err-in-20.03.patch -Patch9198: 0198-fix-function-call-error.patch -Patch9199: 0199-perftool-add-latency-tool.patch -Patch9200: 0200-cfg-del-unnecessary-logs.patch -Patch9201: 0201-fix-dpdk_bond_primary_set-bug.patch -Patch9202: 0202-fix-build-failed-in-2003sp4.patch -Patch9203: 0203-virtio-cfg-ipv4-and-ipv6-addr.patch -Patch9204: 0204-parse-packages-type-in-rx_poll.patch -Patch9205: 0205-virtio-distribute-pkg-by-dst_port.patch -Patch9206: 0206-fix-coredump-when-get-empty-from-udp-sendring.patch -Patch9207: 0207-fix-poll-init-not-clear-old-fd.patch -Patch9208: 0208-virtio-mode-actual_queue_num.patch -Patch9209: 0209-virtio-update-g_rule_port-by-reg_ring_type-enum.patch -Patch9210: 0210-virtio-dfx-data-of-virtio.patch -Patch9211: 0211-add-flow_bifurcation-switch-in-lstack_cfg-file.patch -Patch9212: 0212-example-sync-example-update.patch -Patch9213: 0213-cleancode-improving-makefile-readability.patch -Patch9214: 0214-add-.gitignore.patch -Patch9215: 0215-cleancode-rename-gazelle-files-in-lwip.patch -Patch9216: 0216-cleancode-refactor-lwipsock.h.patch -Patch9217: 0217-cleancode-refactor-posix-type-and-get_socket.patch -Patch9218: 0218-fix-some-error-of-NULL-pointer.patch -Patch9219: 0219-cleancode-refactor-posix_api.patch -Patch9220: 0220-cleancode-refactor-lwipgz_list.h.patch -Patch9221: 0221-fix-EPOLLIN-event-dropd.patch -Patch9222: 0222-cleancode-refactor-lwipgz_hlist.h.patch -Patch9223: 0223-add-sem-post-when-update-event.patch -Patch9224: 0224-cleancode-refactor-sys_now-and-lwip_ioctl.patch -Patch9225: 0225-POSIX-fix-select-timeout-disable-and-build-failed-in.patch -Patch9226: 0226-support-kernel-connect.patch -Patch9227: 0227-Check-the-return-of-lwip_init.patch -Patch9228: 0228-vitio_user-modify-mbuf-index-for-bond4.patch -Patch9229: 0229-fix-redis-coredump-when-hugetlbs-pagesize-is-1024M.patch -Patch9230: 0230-dfx-optimize-gazellectl-x-for-bond.patch -Patch9231: 0231-virtio-fix-dfx-error-with-multiple-cpus.patch -Patch9232: 0232-fix-issue-create-virtio_user-based-on-bond4-main-net.patch -Patch9233: 0233-virtio_user-modify-mbuf-index-for-bond4.patch -Patch9234: 0234-WRAP-fix-double-connect-lead-posix-api-disable.patch -Patch9235: 0235-virtio_user-add-vlan-info-for-kernerl-packets-when-v.patch -Patch9236: 0236-virtio_user-solve-the-issue-that-failed-to-bind-virt.patch -Patch9237: 0237-refector-fill-udp-sendring.patch -Patch9238: 0238-virtio_user-The-program-establishes-a-network-connec.patch -Patch9239: 0239-WRAP-fix-ltran-mode-did-not-bind-kernel-while-open-k.patch -Patch9240: 0240-WRAP-fix-bind-log-error.patch -Patch9241: 0241-virtio-mod-virtio_user_name-when-multi-process-is-on.patch -Patch9242: 0242-fix-redis-coredump-ctrl-c-during-the-pressure-test.patch -Patch9243: 0243-virtio_user-check-netif-status.patch -Patch9244: 0244-virtio-solve-compilation-error-in-2003sp3.patch -Patch9245: 0245-CMAKE-fix-ltran-build-error-in-2403.patch -Patch9246: 0246-fix-mbuf_total-calculation-error.patch -Patch9247: 0247-cfg-modify-maximum-tcp_conn_count-to-2w.patch -Patch9248: 0248-tools-fix-sync-patch-script-date-wrong-and-update-th.patch -Patch9249: 0249-epoll-fix-wild-pointer-detected-by-cooddy.patch -Patch9250: 0250-tools-fix-script-generate-patchname-wrong.patch -Patch9251: 0251-fix-when-errno-is-ENOTCONN-ignore-it.patch -Patch9252: 0252-rtc-do_lwip_init_sock-no-need-to-create-ring-in-rtc-.patch -Patch9253: 0253-example-solve-double-free.patch -Patch9254: 0254-WRAP-support-setsockopt-SO_SNDTIMEO-SO_SNBUF.patch -Patch9255: 0255-DFX-adapt-log-optimization.patch -Patch9256: 0256-LOG-add-log-when-udp-send_ring-is-exhausted.patch -Patch9257: 0257-cleancode-refactor-rtc_api-rtw_api-and-dummy_api.patch -Patch9258: 0258-cleancode-move-some-API-from-stack-to-rpc-and-rtw.patch -Patch9259: 0259-cleancode-add-rpc_async_call-remove-rpc_msg_arg.sock.patch -Patch9260: 0260-cleancode-declare-different-cfg_params-types.patch -Patch9261: 0261-Fill-in-a-portion-of-mbuf-to-send_ring-when-mbuf-is-.patch -Patch9262: 0262-add-pingpong-dfx-support.patch -Patch9263: 0263-add-interrupt-mode-support.patch -Patch9264: 0264-af_xdp-set-rlimit-unlimit-when-gazelle-init.patch -Patch9265: 0265-fix-stack-null-when-register-interrupt.patch -Patch9266: 0266-rtw-fix-send-length-exceeding-send_ring_size.patch -Patch9267: 0267-rpc-fix-rpc_sync_call-spinlock-block-when-msg-be-rec.patch -Patch9268: 0268-bugfix-fix-gazelle-init-failed-while-setup-by-non-ro.patch -Patch9269: 0269-xdp-skip-checksum-temporarily-due-to-kernel-cannot-t.patch -Patch9270: 0270-fix-dpdk_nic_is_xdp-coredump-in-ltran-mode.patch -Patch9271: 0271-fix-the-coredump-when-gazellectl-l.patch -Patch9272: 0272-control-call-epoll_ctl-delete-fd-when-fd-close.patch -Patch9273: 0273-epoll-remove-unnecessary-judgment-code.patch -Patch9274: 0274-slove-compile-err-when-GAZELLE_TCP_REUSE_IPPORT-is-o.patch -Patch9275: 0275-bugfix-start-fail-when-executing-the-popen-command-f.patch -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 -Patch9310: 0310-DUMP-fix-build-error-of-oe2003-because-of-micro-is-n.patch -Patch9311: 0311-SIGNAL-Adjust-sigaction-function-to-keep-lstack-sign.patch -Patch9312: 0312-SIGNAL-Adjust-hijack-sigal-table-to-hijack-SIGABRT-S.patch -Patch9313: 0313-DUMP-fix-abnomal-printing-in-the-dump-process.patch -Patch9314: 0314-fix-the-memory-leak-when-using-strdup.patch -Patch9315: 0315-Stack-unset-stack_stop-while-stacks-exit-by-rpc-mess.patch -Patch9316: 0316-SIGNAL-block-SIGSEGV-during-exit-process.patch -Patch9317: 0317-add-xdp-tx-checksum-tso-offload.patch -Patch9318: 0318-RTC-mode-fix-gazellectl-can-t-print-connenct-info.patch -Patch9319: 0319-Connect-fix-benchmark_dws-connect-failed.patch -Patch9320: 0320-Protocal-fixing-deathlock-between-protocol-threads-a.patch -Patch9321: 0321-update-gazelle-max-numa-nodes-8.patch -Patch9322: 0322-RTC-fixing-program-stuck-while-gazelle-exit-in-multi.patch -Patch9323: 0323-cleancode-add-GAZELLE_SAME_NODE.patch -Patch9324: 0324-cleancode-remove-gazelle_light_ring.patch -Patch9325: 0325-cleancode-remove-get_stack_tid-DPDK_PKT_BURST_SIZE-P.patch -Patch9326: 0326-socket-refactor-sock_event.patch -Patch9327: 0327-socket-adapt-to-sock_event.patch -Patch9328: 0328-socket-refactor-tcp-and-udp.patch -Patch9329: 0329-socket-adapt-to-tcp-and-udp.patch -Patch9330: 0330-cfg-add-mem_cache_max-and-change-default-rpc_msg_max.patch -Patch9331: 0331-cfg-add-mem_async_mode.patch -Patch9332: 0332-mempool-add-mem_thread_cache_flush.patch -Patch9333: 0333-dfx-support-sk_wait-stat.patch -Patch9334: 0334-mempool-fix-copy_mbuf_private.patch -Patch9335: 0335-socket-fix-connect-blocking.patch -Patch9336: 0336-socket-fix-stack_tcp_read-do-not-recv_finish_burst.patch -Patch9337: 0337-tcp-add-GAZELLE_TCP_ASYNC_RECVD.patch -Patch9338: 0338-socket-fix-tcp-closed.patch -Patch9339: 0339-socket-fix-sk_wait-cannot-be-interrupted-by-signals.patch -Patch9340: 0340-mempool-modify-mbuf-num-and-rpc_msg-num.patch -Patch9341: 0341-mempool-fix-mbox_ring-free-not-call-recv_finish_burs.patch -Patch9342: 0342-mempool-mem_get_rpc-add-reserve-limit.patch -Patch9343: 0343-mempool-fix-pthread_tryjoin_np-coredump-when-mysqld-.patch -Patch9344: 0344-mempool-stop-using-cache-when-too-many-threads.patch -Patch9345: 0345-sk_wait-fix-lwip_tcp_allow_send-coredump.patch -Patch9346: 0346-mbox-fix-mbox_ring_common_free-coredump-when-rte_rin.patch -Patch9347: 0347-sk_wait-fix-sock_wait_common_free.patch -Patch9348: 0348-socket-fix-stack_udp_readmsg-return-len.patch -Patch9349: 0349-sk_wait-fix-lwip_wait_foreach_notify-coredump-at-sta.patch -Patch9350: 0350-epoll-fix-do_lwip_connected_callback.patch -Patch9351: 0351-sockio-fix-rtw_stack_tcp_write-wrong-copied_total-af.patch -Patch9352: 0352-sk_event-fix-rtw-epoll-wrong-event-notify-and-remove.patch -Patch9353: 0353-poll-fix-do_lwip_connected_callback-not-delete-poll-.patch -Patch9354: 0354-sockctl-fix-rtw-broadcast-close-and-shutdown.patch -Patch9355: 0355-mempool-increase-MEM_THREAD_MANAGER_FREE_S-to-avoid-.patch -Patch9356: 0356-sockio-fix-callback_tcp_send-output-too-many-at-once.patch -Patch9357: 0357-sockio-fix-sendmbox-full-return-EWOULDBLOCK.patch -Patch9358: 0358-sk_wait-igonre-mem_thread-flush-signal.patch -Patch9359: 0359-fix-20.03-LTS-build-failed.patch -Patch9360: 0360-sockio-fix-tcp_write-not-remove-EPOLLOUT.patch -Patch9361: 0361-sockio-fix-rpc_send-coredump-after-RPC_MSG_EXIT.patch %description %{name} is a high performance user-mode stack. @@ -419,6 +60,9 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b %config(noreplace) %{conf_path}/ltran.conf %changelog +* Fri Aug 1 2025 yinbin - 1.0.3-1 +- update version to 1.0.3 + * Wed Jul 09 2025 yinbin6 - 1.0.2-85 - sockio: fix rpc_send coredump after RPC_MSG_EXIT - sockio: fix tcp_write not remove EPOLLOUT