From e28ea55184eca3163957d19198f622885473f7dc Mon Sep 17 00:00:00 2001 From: jiangheng12 Date: Tue, 6 Jun 2023 20:37:05 +0800 Subject: [PATCH] revert cleancode series patches (cherry picked from commit d087197c911683b8c083ed0b38faf5b1271d0233) --- ...ncode-improving-makefile-readability.patch | 906 ------------------ ...n-read_lwip_data-to-fix-mem-overflow.patch | 0 ...eancode-rename-gazelle-files-in-lwip.patch | 324 ------- 0243-cleancode-refactor-lwipsock.h.patch | 421 -------- ...eancode-refactor-gazelle_posix_api.h.patch | 171 ---- 0245-cleancode-refactor-gazelle_list.h.patch | 455 --------- 0246-cleancode-refactor-gazelle_hlist.h.patch | 314 ------ ...code-refactor-sys_now-and-lwip_ioctl.patch | 651 ------------- 0248-cleancode-refactor-memp.patch | 34 - ...dump-caused-by-lwip_get_socket_nouse.patch | 135 --- 0251-fix-socket-init-and-clean.patch | 65 -- gazelle.spec | 17 +- 12 files changed, 5 insertions(+), 3488 deletions(-) delete mode 100644 0241-cleancode-improving-makefile-readability.patch rename 0249-drop-netbuf-in-read_lwip_data-to-fix-mem-overflow.patch => 0241-drop-netbuf-in-read_lwip_data-to-fix-mem-overflow.patch (100%) delete mode 100644 0242-cleancode-rename-gazelle-files-in-lwip.patch delete mode 100644 0243-cleancode-refactor-lwipsock.h.patch delete mode 100644 0244-cleancode-refactor-gazelle_posix_api.h.patch delete mode 100644 0245-cleancode-refactor-gazelle_list.h.patch delete mode 100644 0246-cleancode-refactor-gazelle_hlist.h.patch delete mode 100644 0247-cleancode-refactor-sys_now-and-lwip_ioctl.patch delete mode 100644 0248-cleancode-refactor-memp.patch delete mode 100644 0250-fix-coredump-caused-by-lwip_get_socket_nouse.patch delete mode 100644 0251-fix-socket-init-and-clean.patch diff --git a/0241-cleancode-improving-makefile-readability.patch b/0241-cleancode-improving-makefile-readability.patch deleted file mode 100644 index e6d39ae..0000000 --- a/0241-cleancode-improving-makefile-readability.patch +++ /dev/null @@ -1,906 +0,0 @@ -From 8e97abb619efd77fa3499bb2ab224d000b1173c4 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Thu, 18 May 2023 11:36:42 +0800 -Subject: [PATCH] cleancode: improving makefile readability - -Signed-off-by: Lemmy Huang ---- - src/common/dir.mk | 13 ---- - src/lstack/Makefile | 62 +++++++--------- - src/lstack/Printlog.mk | 14 ++++ - src/lstack/api/dir.mk | 14 ---- - src/lstack/api/lstack_epoll.c | 4 +- - src/lstack/api/lstack_signal.c | 2 +- - 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_protocol_stack.c | 6 +- - src/lstack/core/lstack_stack_stat.c | 4 +- - src/lstack/core/lstack_thread_rpc.c | 2 +- - src/lstack/include/lstack_cfg.h | 2 +- - src/lstack/include/lstack_dpdk.h | 4 +- - src/lstack/include/lstack_protocol_stack.h | 4 +- - src/lstack/include/posix/lstack_epoll.h | 4 +- - src/lstack/netif/dir.mk | 12 --- - src/lstack/netif/lstack_ethdev.c | 2 +- - src/lstack/netif/lstack_vdev.c | 4 +- - src/ltran/CMakeLists.txt | 86 ++++++++++++++-------- - 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 +- - 41 files changed, 149 insertions(+), 177 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/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 ab039ec..86a9c1e 100644 ---- a/src/lstack/Makefile -+++ b/src/lstack/Makefile -@@ -8,31 +8,21 @@ - # 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)))) - --LWIP_INCLUDE_FILE ?= /usr/include/lwip - LIB_PATH ?= /usr/lib64 -+LWIP_INCLUDE_FILE ?= /usr/include/lwip -+ -+include $(ROOT_DIR)/Printlog.mk - - AR = ar - ARFLAGS = crDP - CC ?= gcc --OPTIMIZATION = -O2 -g - RM = rm -f -+OPTIMIZATION = -O2 -g - LDFLAGS = -shared -ldl -lm -lpthread -lrt -lnuma -lconfig -lboundscheck -- --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 --else -- SEC_FLAGS = -fstack-protector-strong -Werror -Wall -fPIC --endif --$(info $(CC):$(SEC_FLAGS)) -- --INC = -I$(LSTACK_DIR)/include \ -- -I$(LSTACK_DIR)/../common \ -- -I$(LWIP_INCLUDE_FILE) -- --CFLAGS = $(OPTIMIZATION) -fno-strict-aliasing $(INC) -+CFLAGS = $(OPTIMIZATION) -fno-strict-aliasing -+CFLAGS += -D__USE_GNU=1 -D_GNU_SOURCE=1 - - ifeq ($(GAZELLE_COVERAGE_ENABLE), 1) - LDFLAGS += -fprofile-arcs -ftest-coverage -@@ -43,17 +33,21 @@ ifeq ($(shell $(CC) -dumpmachine | cut -d"-" -f1), x86_64) - CFLAGS += -mssse3 - endif - -+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 -+else -+ SEC_FLAGS = -fstack-protector-strong -Werror -Wall -fPIC -+endif - CFLAGS += $(SEC_FLAGS) - --SRCS = --DIRS = core netif api ../common -- --define register_dir --SRCS += $(patsubst %, $(1)/%, $(2)) --endef -+INC = -I$(ROOT_DIR)/include \ -+ -I$(ROOT_DIR)/../ \ -+ -I$(LWIP_INCLUDE_FILE) - --include $(patsubst %, %/dir.mk, $(DIRS)) -+$(info $(CC):$(CFLAGS)) -+CFLAGS += $(INC) - -+SRCS = $(wildcard ./api/*.c ./core/*.c ./netif/*.c ../common/*.c) - # Linking object and library - OBJS = $(subst .c,.o,$(SRCS)) - -@@ -96,19 +90,17 @@ LDFLAGS += -Wl,--whole-archive $(DEP_LIBS) $(OBJS) -Wl,--no-whole-archive - 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) -Wl,--whole-archive -Wl,--no-whole-archive -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 f5370a2..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 -- --$(eval $(call register_dir, api, $(SRC))) -- -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 06bd71b..888552c 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -30,8 +30,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_signal.c b/src/lstack/api/lstack_signal.c -index 03118f5..0c0ed1f 100644 ---- a/src/lstack/api/lstack_signal.c -+++ b/src/lstack/api/lstack_signal.c -@@ -19,7 +19,7 @@ - #include - - #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 505e33d..b3afa73 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 - -@@ -37,7 +36,7 @@ - #include "lstack_cfg.h" - #include "lstack_lwip.h" - #include "lstack_protocol_stack.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_base_func.h" - #include "lstack_thread_rpc.h" - - #ifndef SOCK_TYPE_MASK -diff --git a/src/lstack/core/dir.mk b/src/lstack/core/dir.mk -deleted file mode 100644 -index 88c1e08..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_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_cfg.c b/src/lstack/core/lstack_cfg.c -index a21992e..66399db 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 -@@ -28,9 +27,9 @@ - #include - #include - --#include "gazelle_reg_msg.h" -+#include "common/gazelle_reg_msg.h" - #include "lstack_log.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_base_func.h" - #include "lstack_protocol_stack.h" - #include "lstack_cfg.h" - -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index be156dc..3dfe622 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 b321c18..fa33ff8 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 -@@ -40,7 +39,7 @@ - #include - - #include "lstack_log.h" --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "lstack_lockless_queue.h" - #include "lstack_protocol_stack.h" - #include "lstack_thread_rpc.h" -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 4fbbc14..7d4edd4 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" - - #define LSTACK_PRELOAD_ENV_SYS "LD_PRELOAD" -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 12c2aa6..09c5261 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -26,7 +26,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" -@@ -34,7 +34,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_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index d5523df..2f71f97 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 - -@@ -24,9 +24,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 60832b4..8c4f298 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -21,8 +21,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/core/lstack_thread_rpc.c b/src/lstack/core/lstack_thread_rpc.c -index fe3b757..a4b2a51 100644 ---- a/src/lstack/core/lstack_thread_rpc.c -+++ b/src/lstack/core/lstack_thread_rpc.c -@@ -19,7 +19,7 @@ - #include "lstack_lwip.h" - #include "lstack_protocol_stack.h" - #include "lstack_control_plane.h" --#include "gazelle_base_func.h" -+#include "common/gazelle_base_func.h" - #include "lstack_dpdk.h" - #include "lstack_thread_rpc.h" - -diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h -index 4d0f611..684ff5e 100644 ---- a/src/lstack/include/lstack_cfg.h -+++ b/src/lstack/include/lstack_cfg.h -@@ -17,7 +17,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 a189557..610feec 100644 ---- a/src/lstack/include/lstack_dpdk.h -+++ b/src/lstack/include/lstack_dpdk.h -@@ -13,8 +13,8 @@ - #ifndef _GAZELLE_DPDK_H_ - #define _GAZELLE_DPDK_H_ - --#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) - #define KNI_NB_MBUF (DEFAULT_RING_SIZE << 4) -diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 3a447dc..5e2b8e6 100644 ---- a/src/lstack/include/lstack_protocol_stack.h -+++ b/src/lstack/include/lstack_protocol_stack.h -@@ -20,10 +20,10 @@ - #include - #include - --#include "gazelle_dfx_msg.h" -+#include "common/gazelle_dfx_msg.h" - #include "lstack_lockless_queue.h" - #include "lstack_ethdev.h" --#include "gazelle_opt.h" -+#include "common/gazelle_opt.h" - - #define SOCK_RECV_RING_SIZE (128) - #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 d6c81a7..08cd092 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 ec7c4ad..0000000 ---- a/src/lstack/netif/dir.mk -+++ /dev/null -@@ -1,12 +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 --$(eval $(call register_dir, netif, $(SRC))) -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index e4e7ebd..3d609eb 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -34,7 +34,7 @@ - #include "lstack_log.h" - #include "lstack_dpdk.h" - #include "lstack_lwip.h" --#include "dpdk_common.h" -+#include "common/dpdk_common.h" - #include "lstack_protocol_stack.h" - #include "lstack_thread_rpc.h" - #include "lstack_ethdev.h" -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 5ea1f31..87df325 100644 ---- a/src/lstack/netif/lstack_vdev.c -+++ b/src/lstack/netif/lstack_vdev.c -@@ -26,9 +26,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_vdev.h" - -diff --git a/src/ltran/CMakeLists.txt b/src/ltran/CMakeLists.txt -index f37a232..f74c403 100644 ---- a/src/ltran/CMakeLists.txt -+++ b/src/ltran/CMakeLists.txt -@@ -14,7 +14,6 @@ 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") -@@ -27,40 +26,63 @@ if($ENV{GAZELLE_COVERAGE_ENABLE}) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage -fprofile-arcs") - endif($ENV{GAZELLE_COVERAGE_ENABLE}) - --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) -+set(LTRAN_C_FLAGS -march=native -fno-strict-aliasing -D__ARM_FEATURE_CRC32=1 -+ -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 -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough -+ -D_FORTIFY_SOURCE=2) - --target_include_directories(ltran PRIVATE ${COMMON_DIR} ${PROJECT_SOURCE_DIR} ${LWIP_DIR}) --target_compile_options(ltran PRIVATE -march=native -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 -- -Wdeprecated -Wwrite-strings -Wno-implicit-fallthrough -D_FORTIFY_SOURCE=2) -+set(LTRAN_DPDK_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(LTRAN_LD_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_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_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") -+ -+# compile info -+#set(CMAKE_VERBOSE_MAKEFILE ON) -+message("[CMAKE_C_FLAGS] ${CMAKE_C_FLAGS}") -+message("[LTRAN_C_FLAGS] ${LTRAN_C_FLAGS}") -+message("[LTRAN_DPDK_FLAGS] ${LTRAN_DPDK_FLAGS}") -+message("[LTRAN_LD_FLAGS] ${LTRAN_LD_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}) -+target_compile_options(ltran PRIVATE ${LTRAN_C_FLAGS} ${LTRAN_DPDK_FLAGS}) - - 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_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_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") -+set_target_properties(ltran PROPERTIES LINK_FLAGS ${LTRAN_LD_FLAGS}) - - add_executable(gazellectl ltran_dfx.c ${COMMON_DIR}/gazelle_dfx_msg.c) --target_include_directories(gazellectl PRIVATE $ENV{DPDK_INCLUDE_FILE} ${COMMON_DIR}) -+target_include_directories(gazellectl PRIVATE $ENV{DPDK_INCLUDE_FILE} ${COMMON_DIR}/../ ${LWIP_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 6be9152..6e1a4e4 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 e41c6db..c415211 100644 ---- a/src/ltran/ltran_dfx.c -+++ b/src/ltran/ltran_dfx.c -@@ -27,7 +27,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 e2eb4a8..f723f29 100644 ---- a/src/ltran/ltran_ethdev.c -+++ b/src/ltran/ltran_ethdev.c -@@ -25,13 +25,13 @@ - #include - #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 b41e1e2..55105f6 100644 ---- a/src/ltran/ltran_forward.c -+++ b/src/ltran/ltran_forward.c -@@ -23,7 +23,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 d163a47..5112ec3 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 e16e648..9235caa 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 40a92b1..71b2b57 100644 ---- a/src/ltran/ltran_param.h -+++ b/src/ltran/ltran_param.h -@@ -16,7 +16,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 d4e935e..d2ec9f5 100644 ---- a/src/ltran/ltran_stack.c -+++ b/src/ltran/ltran_stack.c -@@ -15,7 +15,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 c17a5c1..25dda50 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 d6a0d17..9bc2c45 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 87f1e14..3156851 100644 ---- a/src/ltran/main.c -+++ b/src/ltran/main.c -@@ -18,7 +18,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.23.0 - diff --git a/0249-drop-netbuf-in-read_lwip_data-to-fix-mem-overflow.patch b/0241-drop-netbuf-in-read_lwip_data-to-fix-mem-overflow.patch similarity index 100% rename from 0249-drop-netbuf-in-read_lwip_data-to-fix-mem-overflow.patch rename to 0241-drop-netbuf-in-read_lwip_data-to-fix-mem-overflow.patch diff --git a/0242-cleancode-rename-gazelle-files-in-lwip.patch b/0242-cleancode-rename-gazelle-files-in-lwip.patch deleted file mode 100644 index 0d93af6..0000000 --- a/0242-cleancode-rename-gazelle-files-in-lwip.patch +++ /dev/null @@ -1,324 +0,0 @@ -From 8a32751b05845921e3bf7fdc74592a084d67c8cc Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 23 May 2023 16:32:26 +0800 -Subject: [PATCH] cleancode: rename gazelle files in lwip - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 4 ++-- - src/lstack/api/lstack_fork.c | 2 +- - src/lstack/api/lstack_signal.c | 2 +- - src/lstack/api/lstack_wrap.c | 2 +- - src/lstack/core/lstack_cfg.c | 2 +- - src/lstack/core/lstack_control_plane.c | 4 ++-- - src/lstack/core/lstack_dpdk.c | 4 ++-- - src/lstack/core/lstack_init.c | 2 +- - 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/lstack_protocol_stack.h | 2 +- - src/lstack/include/posix/lstack_epoll.h | 2 +- - src/lstack/netif/lstack_ethdev.c | 2 +- - src/lstack/netif/lstack_vdev.c | 2 +- - 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 +- - 21 files changed, 25 insertions(+), 25 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 888552c..a25b0de 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -20,11 +20,11 @@ - - #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..4cdfff3 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_signal.c b/src/lstack/api/lstack_signal.c -index 0c0ed1f..f6ac876 100644 ---- a/src/lstack/api/lstack_signal.c -+++ b/src/lstack/api/lstack_signal.c -@@ -16,7 +16,7 @@ - #include - #include - #include --#include -+#include - - #include "lstack_cfg.h" - #include "common/dpdk_common.h" -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index b3afa73..4e83501 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -25,7 +25,7 @@ - #include - #include - --#include -+#include - #include - #include - -diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c -index 66399db..fa014e8 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -24,7 +24,7 @@ - #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 3dfe622..30cf4c8 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 fa33ff8..d927b60 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -29,10 +29,10 @@ - #include - #include - #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 7d4edd4..7bb1a66 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -32,7 +32,7 @@ - #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 09c5261..1a82a2e 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -19,7 +19,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 2f71f97..f04f736 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -20,7 +20,7 @@ - #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 8c4f298..a66445b 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -15,10 +15,10 @@ - #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/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h -index 5e2b8e6..76ecf67 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_dfx_msg.h" -diff --git a/src/lstack/include/posix/lstack_epoll.h b/src/lstack/include/posix/lstack_epoll.h -index 08cd092..205bae0 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 3d609eb..3923b77 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 - #include -diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c -index 87df325..82127fc 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 -diff --git a/src/ltran/ltran_instance.h b/src/ltran/ltran_instance.h -index f0fe580..b32885a 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..ca3bc5b 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..80e9f80 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 9bc2c45..9206675 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..d724613 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 85ea324..690eca5 100644 ---- a/src/ltran/ltran_timer.c -+++ b/src/ltran/ltran_timer.c -@@ -16,7 +16,7 @@ - #include - #include - #include --#include -+#include - - #include "ltran_param.h" - #include "ltran_log.h" --- -2.23.0 - diff --git a/0243-cleancode-refactor-lwipsock.h.patch b/0243-cleancode-refactor-lwipsock.h.patch deleted file mode 100644 index 3001d6d..0000000 --- a/0243-cleancode-refactor-lwipsock.h.patch +++ /dev/null @@ -1,421 +0,0 @@ -From bf872f6a1dfbe1da9aec8e82cd7b89c0c743c2d7 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Tue, 23 May 2023 19:55:21 +0800 -Subject: [PATCH] cleancode: refactor lwipsock.h - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 22 ++++++++-------- - src/lstack/api/lstack_wrap.c | 12 ++++----- - src/lstack/core/lstack_init.c | 3 --- - src/lstack/core/lstack_lwip.c | 35 ++++++++++++++----------- - src/lstack/core/lstack_protocol_stack.c | 18 ++++++------- - src/lstack/include/lstack_lwip.h | 10 ++++++- - 6 files changed, 55 insertions(+), 45 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index a25b0de..2fba2ee 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -120,7 +120,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 (POSIX_IS_TYPE(sock, POSIX_LWIP)) { - event |= EPOLLOUT; - } - } -@@ -142,7 +142,7 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s - - if (NETCONN_IS_OUTIDLE(sock)) { - /* lwip_netconn_do_connected set LIBOS FLAGS when connected */ -- if (sock->conn && CONN_TYPE_IS_LIBOS(sock->conn)) { -+ if (POSIX_IS_TYPE(sock, POSIX_LWIP)) { - event |= EPOLLOUT; - } - } -@@ -168,7 +168,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_nouse(fd); - if (sock == NULL) { - LSTACK_LOG(ERR, LSTACK, "fd=%d sock is NULL errno=%d\n", fd, errno); - posix_api->close_fn(fd); -@@ -231,7 +231,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_nouse(fd); - if (sock == NULL) { - LSTACK_LOG(ERR, LSTACK, "fd=%d sock is NULL errno=%d\n", fd, errno); - GAZELLE_RETURN(EINVAL); -@@ -315,18 +315,18 @@ int32_t lstack_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_even - GAZELLE_RETURN(EINVAL); - } - -- struct lwip_sock *epoll_sock = get_socket_by_fd(epfd); -+ struct lwip_sock *epoll_sock = lwip_get_socket_nouse(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); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - if (sock == 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); -@@ -409,7 +409,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_nouse(fd); - while (sock && sock->conn) { - uint32_t events = update_events(sock); - if (events) { -@@ -463,7 +463,7 @@ static void ms_to_timespec(struct timespec *timespec, int32_t timeout) - - int32_t lstack_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_nouse(epfd); - if (sock == NULL || sock->wakeup == NULL) { - return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); - } -@@ -627,7 +627,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_nouse(fd); - - if (fd == wakeup->last_fds[i].fd && fds[i].events == wakeup->last_fds[i].events) { - /* fd close then socket may get same fd. */ -@@ -639,7 +639,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; - -- 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_wrap.c b/src/lstack/api/lstack_wrap.c -index 4e83501..160cf8e 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -66,14 +66,14 @@ static inline enum KERNEL_LWIP_PATH select_path(int fd, struct lwip_sock **socke - return PATH_KERNEL; - } - -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - - /* AF_UNIX case */ -- if (!sock || !sock->conn || CONN_TYPE_IS_HOST(sock->conn)) { -+ if (!sock || !sock->conn || POSIX_IS_TYPE(sock, POSIX_KERNEL)) { - return PATH_KERNEL; - } - -- if (likely(CONN_TYPE_IS_LIBOS(sock->conn))) { -+ if (likely(POSIX_IS_TYPE(sock, POSIX_LWIP))) { - if (socket) { - *socket = sock; - } -@@ -287,7 +287,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - return posix_api->connect_fn(s, name, namelen); - } - -- sock = get_socket(s); -+ sock = lwip_get_socket_nouse(s); - if (sock == NULL) { - return posix_api->connect_fn(s, name, namelen); - } -@@ -303,10 +303,10 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - "listen_rx_ring_%d", remote_port); - if (is_dst_ip_localhost(name) && 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 = rpc_call_connect(s, name, namelen); -- SET_CONN_TYPE_LIBOS(sock->conn); -+ POSIX_SET_TYPE(sock, POSIX_LWIP); - } - - return ret; -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 7bb1a66..894f549 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -359,9 +359,6 @@ __attribute__((constructor)) void gazelle_network_init(void) - } - } - -- /* 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) { -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 1a82a2e..035311f 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -92,6 +92,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; -@@ -171,11 +172,16 @@ void gazelle_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); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - if (sock == NULL) { - return; - } - -+ 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; -+ - reset_sock_data(sock); - - sock->recv_ring = create_ring("sock_recv", SOCK_RECV_RING_SIZE, RING_F_SP_ENQ | RING_F_SC_DEQ, -@@ -202,7 +208,7 @@ void gazelle_init_sock(int32_t fd) - - void gazelle_clean_sock(int32_t fd) - { -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - if (sock == NULL || sock->stack == NULL) { - return; - } -@@ -680,7 +686,7 @@ void stack_send(struct rpc_msg *msg) - struct protocol_stack *stack = (struct protocol_stack *)msg->args[MSG_ARG_3].p; - bool replenish_again; - -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - if (sock == NULL) { - msg->result = -1; - LSTACK_LOG(ERR, LSTACK, "stack_send: sock error!\n"); -@@ -971,7 +977,7 @@ ssize_t gazelle_send(int32_t fd, const void *buf, size_t len, int32_t flags, - return 0; - } - -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - - thread_bind_stack(sock); - -@@ -1047,7 +1053,7 @@ ssize_t read_stack_data(int32_t fd, void *buf, size_t len, int32_t flags, struct - struct pbuf *pbuf = NULL; - ssize_t recvd = 0; - uint32_t copy_len; -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - bool latency_enable = get_protocol_stack_group()->latency_start; - - if (sock->errevent > 0 && !NETCONN_IS_DATAIN(sock)) { -@@ -1113,7 +1119,7 @@ ssize_t read_stack_data(int32_t fd, void *buf, size_t len, int32_t flags, struct - - void add_recv_list(int32_t fd) - { -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - - if (sock && sock->stack && list_is_null(&sock->recv_list)) { - list_add_node(&sock->stack->recv_list, &sock->recv_list); -@@ -1179,7 +1185,7 @@ void gazelle_connected_callback(struct netconn *conn) - } - - int32_t fd = conn->socket; -- struct lwip_sock *sock = get_socket_by_fd(fd); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - if (sock == NULL || sock->conn == NULL) { - return; - } -@@ -1190,8 +1196,7 @@ void gazelle_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); - } - -@@ -1217,7 +1222,7 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - conn->recv_cnt = rte_ring_count(netconn->recvmbox->ring); - conn->fd = netconn->socket; - -- struct lwip_sock *sock = get_socket(netconn->socket); -+ struct lwip_sock *sock = lwip_get_socket_nouse(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); - conn->recv_ring_cnt += (sock->recv_lastdata) ? 1 : 0; -@@ -1252,7 +1257,7 @@ int32_t gazelle_socket(int domain, int type, int protocol) - - gazelle_init_sock(fd); - -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - if (sock == NULL || sock->stack == NULL) { - lwip_close(fd); - gazelle_clean_sock(fd); -@@ -1276,8 +1281,8 @@ void create_shadow_fd(struct rpc_msg *msg) - return; - } - -- struct lwip_sock *sock = get_socket_by_fd(fd); -- struct lwip_sock *clone_sock = get_socket_by_fd(clone_fd); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); -+ struct lwip_sock *clone_sock = lwip_get_socket_nouse(clone_fd); - if (sock == NULL || clone_sock == NULL) { - LSTACK_LOG(ERR, LSTACK, "get sock null fd=%d clone_fd=%d\n", fd, clone_fd); - msg->result = -1; -@@ -1552,7 +1557,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 = lwip_get_socket_nouse(netconn->socket); - - pcb->client_rx_ring = NULL; - pcb->client_tx_ring = NULL; -@@ -1567,7 +1572,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 = lwip_get_socket_nouse(netconn->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 f04f736..b7aeeae 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -109,7 +109,7 @@ 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); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - if (sock == NULL) { - return NULL; - } -@@ -666,7 +666,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_nouse(fd); - if (sock == NULL) { - msg->result = -1; - return; -@@ -690,7 +690,7 @@ void stack_accept(struct rpc_msg *msg) - return; - } - -- struct lwip_sock *sock = get_socket(accept_fd); -+ struct lwip_sock *sock = lwip_get_socket_nouse(accept_fd); - if (sock == NULL || sock->stack == NULL) { - lwip_close(accept_fd); - gazelle_clean_sock(accept_fd); -@@ -820,7 +820,7 @@ void stack_clean_epoll(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); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - int32_t ret = 0; - - if (sock == NULL) { -@@ -857,7 +857,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_nouse(fd); - if (sock == NULL) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null\n", get_stack_tid(), fd); - GAZELLE_RETURN(EINVAL); -@@ -887,9 +887,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_nouse(clone_fd)->conn->is_master_fd = 1; - } else { -- get_socket_by_fd(clone_fd)->conn->is_master_fd = 0; -+ lwip_get_socket_nouse(clone_fd)->conn->is_master_fd = 0; - } - - ret = rpc_call_listen(clone_fd, backlog); -@@ -903,7 +903,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_nouse(fd); - struct lwip_sock *min_sock = NULL; - - while (sock) { -@@ -941,7 +941,7 @@ int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *ad - { - int32_t ret = -1; - -- struct lwip_sock *sock = get_socket(fd); -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); - if (sock == NULL) { - errno = EINVAL; - return -1; -diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h -index 223ff93..d4f49e0 100644 ---- a/src/lstack/include/lstack_lwip.h -+++ b/src/lstack/include/lstack_lwip.h -@@ -13,13 +13,21 @@ - #ifndef __GAZELLE_LWIP_H__ - #define __GAZELLE_LWIP_H__ - -+#include -+ -+static inline 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; -+} -+ - #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_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; --- -2.23.0 - diff --git a/0244-cleancode-refactor-gazelle_posix_api.h.patch b/0244-cleancode-refactor-gazelle_posix_api.h.patch deleted file mode 100644 index 55d2bf7..0000000 --- a/0244-cleancode-refactor-gazelle_posix_api.h.patch +++ /dev/null @@ -1,171 +0,0 @@ -From d883b06f3860189356dc15b96745e3077d9b3fb6 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Wed, 24 May 2023 11:54:32 +0800 -Subject: [PATCH] cleancode: refactor gazelle_posix_api.h - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_wrap.c | 24 ++++++++++++------------ - src/lstack/core/lstack_control_plane.c | 4 ++-- - src/lstack/core/lstack_init.c | 4 ++-- - 3 files changed, 16 insertions(+), 16 deletions(-) - -diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c -index 160cf8e..e8a3b75 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -62,7 +62,7 @@ static inline enum KERNEL_LWIP_PATH select_path(int fd, struct lwip_sock **socke - return PATH_KERNEL; - } - -- if (unlikely(posix_api->ues_posix)) { -+ if (unlikely(posix_api->use_kernel)) { - return PATH_KERNEL; - } - -@@ -110,7 +110,7 @@ static inline int32_t do_epoll_create1(int32_t flags) - return posix_api->epoll_create1_fn(flags); - } - -- if (unlikely(posix_api->ues_posix)) { -+ if (unlikely(posix_api->use_kernel)) { - return posix_api->epoll_create1_fn(flags); - } - -@@ -127,7 +127,7 @@ static inline int32_t do_epoll_create(int32_t size) - return posix_api->epoll_create_fn(size); - } - -- if (unlikely(posix_api->ues_posix)) { -+ if (unlikely(posix_api->use_kernel)) { - return posix_api->epoll_create_fn(size); - } - -@@ -136,7 +136,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 (unlikely(posix_api->use_kernel)) { - return posix_api->epoll_ctl_fn(epfd, op, fd, event); - } - -@@ -145,7 +145,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 (unlikely(posix_api->use_kernel)) { - return posix_api->epoll_wait_fn(epfd, events, maxevents, timeout); - } - -@@ -402,7 +402,7 @@ 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) -- || posix_api->ues_posix) { -+ || posix_api->use_kernel) { - return posix_api->socket_fn(domain, type, protocol); - } - -@@ -518,7 +518,7 @@ static inline ssize_t do_recvmsg(int32_t s, struct msghdr *message, int32_t flag - return recvmsg_from_stack(s, message, flags); - } - -- return posix_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) -@@ -532,7 +532,7 @@ static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_ - return sendmsg_to_stack(sock, s, message, flags); - } - -- return posix_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, -@@ -551,7 +551,7 @@ static inline ssize_t do_recvfrom(int32_t sockfd, void *buf, size_t len, int32_t - return read_stack_data(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, -@@ -559,7 +559,7 @@ static inline ssize_t do_sendto(int32_t sockfd, const void *buf, size_t len, int - { - struct lwip_sock *sock = NULL; - if (select_path(sockfd, &sock) != PATH_LWIP) { -- return posix_api->send_to(sockfd, buf, len, flags, addr, addrlen); -+ return posix_api->sendto_fn(sockfd, buf, len, flags, addr, addrlen); - } - - return gazelle_send(sockfd, buf, len, flags, addr, addrlen); -@@ -570,7 +570,7 @@ static inline int32_t do_close(int32_t s) - struct lwip_sock *sock = NULL; - if (select_path(s, &sock) == PATH_KERNEL) { - /* we called lwip_socket, even if kernel fd */ -- if (posix_api != NULL && !posix_api->ues_posix && -+ if (posix_api != NULL && !posix_api->use_kernel && - /* contain posix_api->close_fn if success */ - stack_broadcast_close(s) == 0) { - return 0; -@@ -586,7 +586,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 (unlikely(posix_api->use_kernel) || fds == NULL || nfds == 0) { - return posix_api->poll_fn(fds, nfds, timeout); - } - -diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c -index 30cf4c8..a26420e 100644 ---- a/src/lstack/core/lstack_control_plane.c -+++ b/src/lstack/core/lstack_control_plane.c -@@ -741,7 +741,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; - } -@@ -790,7 +790,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 894f549..541480d 100644 ---- a/src/lstack/core/lstack_init.c -+++ b/src/lstack/core/lstack_init.c -@@ -180,7 +180,7 @@ static int32_t check_preload_bind_proc(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(); - } - -@@ -373,7 +373,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(); - } --- -2.23.0 - diff --git a/0245-cleancode-refactor-gazelle_list.h.patch b/0245-cleancode-refactor-gazelle_list.h.patch deleted file mode 100644 index 456b3fd..0000000 --- a/0245-cleancode-refactor-gazelle_list.h.patch +++ /dev/null @@ -1,455 +0,0 @@ -From a62c495e7124a958f80615a375fa1c1c32852936 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Thu, 25 May 2023 16:25:11 +0800 -Subject: [PATCH] cleancode: refactor gazelle_list.h - -Signed-off-by: Lemmy Huang ---- - src/common/gazelle_base_func.h | 6 --- - src/lstack/api/lstack_epoll.c | 72 +++++++++++-------------- - src/lstack/core/lstack_lwip.c | 55 +++++++------------ - src/lstack/core/lstack_protocol_stack.c | 16 +++--- - src/lstack/core/lstack_stack_stat.c | 7 +-- - 5 files changed, 64 insertions(+), 92 deletions(-) - -diff --git a/src/common/gazelle_base_func.h b/src/common/gazelle_base_func.h -index d21ef5f..f83a8eb 100644 ---- a/src/common/gazelle_base_func.h -+++ b/src/common/gazelle_base_func.h -@@ -25,16 +25,10 @@ - return -1; \ - } while (0) - --#define NODE_ENTRY(node, type, member) \ -- ((type*)((char*)(node) - (size_t)&((type*)0)->member)) -- - 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); - - int32_t filename_check(const char* args); - --#undef container_of --#define container_of(ptr, type, field) ((type *)(void*)(((char *)(ptr)) - offsetof(type, field))) -- - #endif /* ifndef __GAZELLE_BASE_FUNC_H__ */ -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 2fba2ee..64c3600 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -67,35 +67,26 @@ void add_sock_event(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); - } - 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]); -+ if (list_node_null(&wakeup->wakeup_list[stack->stack_idx])) { -+ list_add_node(&wakeup->wakeup_list[stack->stack_idx], &stack->wakeup_list); - } - } - - void wakeup_stack_epoll(struct protocol_stack *stack) - { -- struct list_node *node, *temp; -- -- list_for_each_safe(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; -+ struct list_node *node, *next; - -- struct wakeup_poll *wakeup = container_of((node - stack->stack_idx), struct wakeup_poll, wakeup_list); -+ list_for_each_node(node, next, &stack->wakeup_list) { -+ node -= stack->stack_idx; /* array header address */ -+ wakeup = list_entry((typeof(((struct wakeup_poll *)0)->wakeup_list) *)node, struct wakeup_poll, wakeup_list); - - if (__atomic_load_n(&wakeup->in_wait, __ATOMIC_ACQUIRE)) { - __atomic_store_n(&wakeup->in_wait, false, __ATOMIC_RELEASE); -@@ -104,7 +95,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]); - } - } - -@@ -155,8 +146,8 @@ static void raise_pending_events(struct wakeup_poll *wakeup, struct lwip_sock *s - pthread_spin_lock(&wakeup->event_list_lock); - 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); - } -@@ -183,7 +174,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 (pthread_mutex_init(&wakeup->wait, NULL) != 0) { -@@ -195,12 +186,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; -@@ -239,6 +230,7 @@ int32_t lstack_epoll_close(int32_t fd) - - struct protocol_stack_group *stack_group = get_protocol_stack_group(); - struct wakeup_poll *wakeup = sock->wakeup; -+ struct list_node *node, *next; - if (wakeup == NULL) { - return 0; - } -@@ -247,17 +239,16 @@ int32_t lstack_epoll_close(int32_t fd) - - stack_broadcast_clean_epoll(wakeup); - -- 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, next, &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); - - pthread_mutex_destroy(&wakeup->wait); -@@ -348,7 +339,7 @@ int32_t lstack_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_even - 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: -@@ -364,26 +355,27 @@ int32_t lstack_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_even - static int32_t epoll_lwip_event(struct wakeup_poll *wakeup, struct epoll_event *events, uint32_t maxevents) - { - int32_t event_num = 0; -- struct list_node *node, *temp; -+ struct lwip_sock *sock; -+ struct list_node *node, *next; - - 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_for_each_node(node, next, &wakeup->event_list) { -+ sock = list_entry(node, struct lwip_sock, event_list); - - if ((sock->epoll_events & sock->events) == 0) { -- list_del_node_null(&sock->event_list); -+ list_del_node(&sock->event_list); - continue; - } - - if (sock->epoll_events & EPOLLET) { -- list_del_node_null(&sock->event_list); -+ list_del_node(&sock->event_list); - } - - /* 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(&sock->event_list); - sock->epoll_events = 0; - } - -@@ -519,7 +511,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); -@@ -542,9 +534,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/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 035311f..08836da 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -202,8 +202,8 @@ void gazelle_init_sock(int32_t fd) - (void)replenish_send_idlembuf(stack, sock); - - 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); - } - - void gazelle_clean_sock(int32_t fd) -@@ -215,7 +215,7 @@ void gazelle_clean_sock(int32_t 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); - } - -@@ -223,7 +223,7 @@ void gazelle_clean_sock(int32_t fd) - - reset_sock_data(sock); - -- list_del_node_null(&sock->recv_list); -+ list_del_node(&sock->recv_list); - } - - void gazelle_free_pbuf(struct pbuf *pbuf) -@@ -342,7 +342,7 @@ static inline void del_data_out_event(struct lwip_sock *sock) - sock->events &= ~EPOLLOUT; - - if (sock->events == 0) { -- list_del_node_null(&sock->event_list); -+ list_del_node(&sock->event_list); - } - } - -@@ -874,7 +874,7 @@ static inline void del_data_in_event(struct lwip_sock *sock) - sock->events &= ~EPOLLIN; - - if (sock->events == 0) { -- list_del_node_null(&sock->event_list); -+ list_del_node(&sock->event_list); - } - } - -@@ -1121,20 +1121,18 @@ void add_recv_list(int32_t fd) - { - struct lwip_sock *sock = lwip_get_socket_nouse(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); - } - } - - 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 list_node *node, *next; - 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, next, &stack->same_node_recv_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); - } -@@ -1143,23 +1141,22 @@ void read_same_node_recv_list(struct protocol_stack *stack) - - void read_recv_list(struct protocol_stack *stack, uint32_t max_num) - { -- struct list_node *list = &(stack->recv_list); -- struct list_node *node, *temp; -+ struct list_node *node, *next; - 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, next, &stack->recv_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; - } - -@@ -1229,7 +1226,7 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s - conn->send_ring_cnt = 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); - } - } - } -@@ -1368,18 +1365,6 @@ void get_lwip_connnum(struct rpc_msg *msg) - 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; -@@ -1391,7 +1376,7 @@ 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); -+ msg->result = list_get_count(&stack->recv_list); - } - - void netif_poll(struct netif *netif) -@@ -1513,7 +1498,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 b7aeeae..c31e65b 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -288,9 +288,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(); -@@ -421,8 +421,8 @@ static void wakeup_kernel_event(struct protocol_stack *stack) - } - - __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]); -+ if (list_node_null(&wakeup->wakeup_list[stack->stack_idx])) { -+ list_add_node(&wakeup->wakeup_list[stack->stack_idx], &stack->wakeup_list); - } - } - -@@ -545,7 +545,7 @@ int32_t init_protocol_stack(void) - stack_group->stack_num = get_global_cfg_params()->num_cpu * 2; - } - -- 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); - -@@ -814,7 +814,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]); - } - - /* when fd is listenfd, listenfd of all protocol stack thread will be closed */ -@@ -929,7 +929,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 a66445b..9f2e93a 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -128,12 +128,13 @@ 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; -+ struct wakeup_poll *wakeup; -+ struct list_node *node, *next; - - 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, next, &stack_group->poll_list) { -+ wakeup = list_entry(node, struct wakeup_poll, poll_list); - - if (wakeup->bind_stack == stack) { - stat->app_events += wakeup->stat.app_events; --- -2.23.0 - diff --git a/0246-cleancode-refactor-gazelle_hlist.h.patch b/0246-cleancode-refactor-gazelle_hlist.h.patch deleted file mode 100644 index d5aef95..0000000 --- a/0246-cleancode-refactor-gazelle_hlist.h.patch +++ /dev/null @@ -1,314 +0,0 @@ -From 57f45b4269de6e428e21f0376cc90f9f9a515960 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Thu, 25 May 2023 21:34:29 +0800 -Subject: [PATCH] cleancode: refactor gazelle_hlist.h - -Signed-off-by: Lemmy Huang ---- - src/ltran/ltran_stack.c | 12 +++++------- - src/ltran/ltran_stat.c | 6 ++---- - src/ltran/ltran_tcp_conn.c | 12 +++++------- - src/ltran/ltran_tcp_sock.c | 18 +++++++----------- - src/ltran/ltran_timer.c | 6 +++--- - 5 files changed, 22 insertions(+), 32 deletions(-) - -diff --git a/src/ltran/ltran_stack.c b/src/ltran/ltran_stack.c -index d2ec9f5..907518b 100644 ---- a/src/ltran/ltran_stack.c -+++ b/src/ltran/ltran_stack.c -@@ -42,7 +42,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; -@@ -67,7 +67,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); - } - } -@@ -87,7 +87,6 @@ const struct gazelle_stack *gazelle_stack_get_by_tid(const struct gazelle_stack_ - uint32_t index; - const struct gazelle_stack *stack = NULL; - const struct gazelle_stack_hbucket *stack_hbucket = NULL; -- struct hlist_node *node = NULL; - const struct hlist_head *head = NULL; - - index = tid_hash_fn(tid) % GAZELLE_MAX_STACK_HTABLE_SIZE; -@@ -97,7 +96,7 @@ const struct gazelle_stack *gazelle_stack_get_by_tid(const struct gazelle_stack_ - } - - head = &stack_hbucket->chain; -- hlist_for_each_entry(stack, node, head, stack_node) { -+ hlist_for_each_entry(stack, head, stack_node) { - if ((stack->tid == tid) && INSTANCE_IS_ON(stack)) { - return stack; - } -@@ -144,7 +143,6 @@ void gazelle_stack_del_by_tid(struct gazelle_stack_htable *stack_htable, uint32_ - { - struct gazelle_stack *stack = NULL; - struct gazelle_stack_hbucket *stack_hbucket = NULL; -- struct hlist_node *node = NULL; - struct hlist_head *head = NULL; - uint32_t backup_size; - uint32_t index; -@@ -156,7 +154,7 @@ void gazelle_stack_del_by_tid(struct gazelle_stack_htable *stack_htable, uint32_ - } - - head = &stack_hbucket->chain; -- hlist_for_each_entry(stack, node, head, stack_node) { -+ hlist_for_each_entry(stack, head, stack_node) { - if (stack->tid == tid) { - break; - } -@@ -180,7 +178,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_stat.c b/src/ltran/ltran_stat.c -index 25dda50..774b9cc 100644 ---- a/src/ltran/ltran_stat.c -+++ b/src/ltran/ltran_stat.c -@@ -214,7 +214,6 @@ void handle_resp_ltran_total(int32_t fd) - void handle_resp_ltran_sock(int32_t fd) - { - struct gazelle_tcp_sock *tcp_sock = NULL; -- struct hlist_node *node = NULL; - struct hlist_head *head = NULL; - struct gazelle_tcp_sock_htable *sock_htable = gazelle_get_tcp_sock_htable(); - struct gazelle_stat_forward_table forward_table = {0}; -@@ -227,7 +226,7 @@ void handle_resp_ltran_sock(int32_t fd) - - for (int32_t i = 0; i < GAZELLE_MAX_TCP_SOCK_HTABLE_SIZE; i++) { - head = &sock_htable->array[i].chain; -- hlist_for_each_entry(tcp_sock, node, head, tcp_sock_node) { -+ hlist_for_each_entry(tcp_sock, head, tcp_sock_node) { - if (index < GAZELLE_LSTACK_MAX_CONN) { - forward_table.conn_list[index].dst_ip = tcp_sock->ip; - forward_table.conn_list[index].tid = tcp_sock->tid; -@@ -248,7 +247,6 @@ void handle_resp_ltran_sock(int32_t fd) - - void handle_resp_ltran_conn(int32_t fd) - { -- struct hlist_node *node = NULL; - struct hlist_head *head = NULL; - struct gazelle_tcp_conn_htable *conn_htable = gazelle_get_tcp_conn_htable(); - struct gazelle_tcp_sock_htable *sock_htable = gazelle_get_tcp_sock_htable(); -@@ -263,7 +261,7 @@ void handle_resp_ltran_conn(int32_t fd) - - for (int32_t i = 0; i < GAZELLE_MAX_CONN_HTABLE_SIZE; i++) { - head = &conn_htable->array[i].chain; -- hlist_for_each_entry(conn, node, head, conn_node) { -+ hlist_for_each_entry(conn, head, conn_node) { - if (index < GAZELLE_LSTACK_MAX_CONN) { - forward_table.conn_list[index].protocol = conn->quintuple.protocol; - forward_table.conn_list[index].tid = conn->tid; -diff --git a/src/ltran/ltran_tcp_conn.c b/src/ltran/ltran_tcp_conn.c -index e0ad562..ca1f414 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); - } - } -@@ -132,7 +132,6 @@ struct gazelle_tcp_conn *gazelle_conn_get_by_quintuple(struct gazelle_tcp_conn_h - { - struct gazelle_tcp_conn *conn = NULL; - struct gazelle_tcp_conn_hbucket *conn_hbucket = NULL; -- struct hlist_node *node = NULL; - struct hlist_head *head = NULL; - - conn_hbucket = gazelle_conn_hbucket_get(conn_htable, quintuple); -@@ -141,7 +140,7 @@ struct gazelle_tcp_conn *gazelle_conn_get_by_quintuple(struct gazelle_tcp_conn_h - } - - head = &conn_hbucket->chain; -- hlist_for_each_entry(conn, node, head, conn_node) { -+ hlist_for_each_entry(conn, head, conn_node) { - if (!INSTANCE_IS_ON(conn)) { - continue; - } -@@ -156,7 +155,6 @@ void gazelle_conn_del_by_quintuple(struct gazelle_tcp_conn_htable *conn_htable, - { - struct gazelle_tcp_conn *conn = NULL; - struct gazelle_tcp_conn_hbucket *conn_hbucket = NULL; -- struct hlist_node *node = NULL; - struct hlist_head *head = NULL; - - conn_hbucket = gazelle_conn_hbucket_get(conn_htable, quintuple); -@@ -165,7 +163,7 @@ void gazelle_conn_del_by_quintuple(struct gazelle_tcp_conn_htable *conn_htable, - } - - head = &conn_hbucket->chain; -- hlist_for_each_entry(conn, node, head, conn_node) { -+ hlist_for_each_entry(conn, head, conn_node) { - if (memcmp(&conn->quintuple, quintuple, sizeof(struct gazelle_quintuple)) == 0) { - break; - } -@@ -175,7 +173,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 9206675..4bc441a 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); - } - } -@@ -96,14 +96,13 @@ static void recover_sock_info_from_conn(struct gazelle_tcp_sock *tcp_sock) - { - uint32_t count = 0; - struct gazelle_tcp_conn *conn = NULL; -- struct hlist_node *node = NULL; - struct hlist_head *head = NULL; - struct gazelle_tcp_conn_htable *conn_htable = gazelle_get_tcp_conn_htable(); - - for (int32_t i = 0; i < GAZELLE_MAX_CONN_HTABLE_SIZE; i++) { - head = &conn_htable->array[i].chain; - -- hlist_for_each_entry(conn, node, head, conn_node) { -+ hlist_for_each_entry(conn, head, conn_node) { - if ((conn->quintuple.dst_ip != tcp_sock->ip) || (conn->quintuple.dst_port != tcp_sock->port) || - (conn->tid != tcp_sock->tid)) { - continue; -@@ -122,7 +121,6 @@ struct gazelle_tcp_sock *gazelle_sock_add_by_ipporttid(struct gazelle_tcp_sock_h - uint16_t port, uint32_t tid) - { - struct gazelle_tcp_sock *tcp_sock = NULL; -- struct hlist_node *node = NULL; - struct hlist_head *head = NULL; - struct gazelle_tcp_sock_hbucket *tcp_sock_hbucket = NULL; - -@@ -133,7 +131,7 @@ struct gazelle_tcp_sock *gazelle_sock_add_by_ipporttid(struct gazelle_tcp_sock_h - - /* avoid reinit */ - head = &tcp_sock_hbucket->chain; -- hlist_for_each_entry(tcp_sock, node, head, tcp_sock_node) { -+ hlist_for_each_entry(tcp_sock, head, tcp_sock_node) { - if ((tcp_sock->tid == tid) && INSTANCE_IS_ON(tcp_sock)) { - return tcp_sock; - } -@@ -166,7 +164,6 @@ void gazelle_sock_del_by_ipporttid(struct gazelle_tcp_sock_htable *tcp_sock_htab - uint32_t tid) - { - struct gazelle_tcp_sock *tcp_sock = NULL; -- struct hlist_node *node = NULL; - struct hlist_head *head = NULL; - struct gazelle_tcp_sock_hbucket *tcp_sock_hbucket = NULL; - -@@ -176,7 +173,7 @@ void gazelle_sock_del_by_ipporttid(struct gazelle_tcp_sock_htable *tcp_sock_htab - } - - head = &tcp_sock_hbucket->chain; -- hlist_for_each_entry(tcp_sock, node, head, tcp_sock_node) { -+ hlist_for_each_entry(tcp_sock, head, tcp_sock_node) { - if (tcp_sock->tid == tid) { - break; - } -@@ -186,7 +183,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--; -@@ -198,7 +195,6 @@ struct gazelle_tcp_sock *gazelle_sock_get_by_min_conn(struct gazelle_tcp_sock_ht - struct gazelle_tcp_sock_hbucket *tcp_sock_hbucket = NULL; - struct gazelle_tcp_sock *tcp_sock_tmp = NULL; - struct gazelle_tcp_sock *tcp_sock = NULL; -- struct hlist_node *node = NULL; - struct hlist_head *head = NULL; - uint32_t min_tcp_con = GAZELLE_STACK_MAX_TCP_CON_NUM; - -@@ -209,7 +205,7 @@ struct gazelle_tcp_sock *gazelle_sock_get_by_min_conn(struct gazelle_tcp_sock_ht - - head = &tcp_sock_hbucket->chain; - -- hlist_for_each_entry(tcp_sock, node, head, tcp_sock_node) { -+ hlist_for_each_entry(tcp_sock, head, tcp_sock_node) { - if (!INSTANCE_IS_ON(tcp_sock)) { - continue; - } -diff --git a/src/ltran/ltran_timer.c b/src/ltran/ltran_timer.c -index 690eca5..af37679 100644 ---- a/src/ltran/ltran_timer.c -+++ b/src/ltran/ltran_timer.c -@@ -62,7 +62,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", -@@ -98,7 +98,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", -@@ -145,7 +145,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.23.0 - diff --git a/0247-cleancode-refactor-sys_now-and-lwip_ioctl.patch b/0247-cleancode-refactor-sys_now-and-lwip_ioctl.patch deleted file mode 100644 index 0e4431d..0000000 --- a/0247-cleancode-refactor-sys_now-and-lwip_ioctl.patch +++ /dev/null @@ -1,651 +0,0 @@ -From 2b1e966ac4542bd78d3de05111d4539843cb2fa2 Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 29 May 2023 15:51:22 +0800 -Subject: [PATCH] cleancode: refactor sys_now and lwip_ioctl - -Signed-off-by: Lemmy Huang ---- - src/common/dpdk_common.c | 11 +++++++ - src/common/dpdk_common.h | 1 + - src/common/gazelle_dfx_msg.h | 8 ++++- - src/lstack/api/lstack_wrap.c | 37 +++++++++++------------- - src/lstack/core/lstack_cfg.c | 1 - - src/lstack/core/lstack_control_plane.c | 21 ++++++++------ - src/lstack/core/lstack_dpdk.c | 9 +++--- - src/lstack/core/lstack_init.c | 2 -- - src/lstack/core/lstack_lwip.c | 14 ++++----- - src/lstack/core/lstack_protocol_stack.c | 14 ++++----- - src/lstack/core/lstack_stack_stat.c | 23 ++------------- - src/lstack/include/lstack_stack_stat.h | 1 - - src/lstack/include/lstack_thread_rpc.h | 1 - - src/lstack/include/posix/lstack_socket.h | 2 +- - src/lstack/netif/lstack_ethdev.c | 4 +-- - src/ltran/ltran_forward.c | 10 +++---- - src/ltran/ltran_stat.c | 2 +- - src/ltran/ltran_stat.h | 6 ---- - src/ltran/ltran_timer.c | 17 ----------- - src/ltran/ltran_timer.h | 2 -- - test/unitest/stub.c | 2 +- - 21 files changed, 75 insertions(+), 113 deletions(-) - -diff --git a/src/common/dpdk_common.c b/src/common/dpdk_common.c -index 23c96d6..dcfe802 100644 ---- a/src/common/dpdk_common.c -+++ b/src/common/dpdk_common.c -@@ -10,6 +10,7 @@ - * See the Mulan PSL v2 for more details. - */ - -+#include - #include - #include - #include -@@ -34,6 +35,16 @@ - #define COMMON_INFO(fmt, ...) LSTACK_LOG(INFO, LSTACK, fmt, ##__VA_ARGS__) - #endif - -+uint64_t get_now_us(void) -+{ -+ 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); -+} -+ - struct rte_kni *g_pkni = NULL; - static volatile bool g_kni_started = false; - -diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h -index 2f0e8d1..6ae0f7b 100644 ---- a/src/common/dpdk_common.h -+++ b/src/common/dpdk_common.h -@@ -94,6 +94,7 @@ static __rte_always_inline void time_stamp_into_mbuf(uint32_t rx_count, struct r - } - } - -+uint64_t get_now_us(void); - 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 a89b82c..69896a6 100644 ---- a/src/common/gazelle_dfx_msg.h -+++ b/src/common/gazelle_dfx_msg.h -@@ -53,6 +53,12 @@ enum GAZELLE_LATENCY_TYPE { - GAZELLE_LATENCY_READ, - }; - -+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; -@@ -146,7 +152,6 @@ struct gazelle_stat_lstack_snmp { - uint32_t icmp_out_echo_reps; - }; - --/* same as define in lwip/tcp.h - struct tcp_pcb_dp */ - struct gazelle_stat_lstack_conn_info { - uint32_t state; - uint32_t rip; -@@ -158,6 +163,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_wrap.c b/src/lstack/api/lstack_wrap.c -index e8a3b75..776646f 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -623,23 +623,20 @@ static int32_t do_sigaction(int32_t signum, const struct sigaction *act, struct - return lstack_sigaction(signum, act, oldact); - } - --#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 = NULL; \ -- if (select_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); \ -+ unsigned long __val; \ -+ va_list __ap; \ -+ va_start(__ap, cmd); \ -+ __val = va_arg(__ap, typeof(__val)); \ -+ va_end(__ap); \ -+ \ -+ int __ret = kernel_fn(fd, cmd, __val); \ -+ if (__ret == -1 || select_path(fd, NULL) == PATH_KERNEL) \ -+ return __ret; \ -+ return lwip_fn(fd, cmd, (type)__val); \ - } while (0) - -- - /* -------------------------------------------------------- - * ------- LD_PRELOAD mode replacement interface -------- - * -------------------------------------------------------- -@@ -662,15 +659,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) - { -@@ -806,15 +803,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 fa014e8..09e1b09 100644 ---- a/src/lstack/core/lstack_cfg.c -+++ b/src/lstack/core/lstack_cfg.c -@@ -24,7 +24,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 a26420e..c903952 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" -@@ -344,7 +347,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; -@@ -362,7 +365,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) && -+ if ((table_state == GAZELLE_LISTEN_LIST) && - (!match_host_addr(qtuple.src_ip))) { - continue; - } -@@ -391,16 +394,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; - } -@@ -409,9 +412,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 d927b60..f7d10b7 100644 ---- a/src/lstack/core/lstack_dpdk.c -+++ b/src/lstack/core/lstack_dpdk.c -@@ -29,15 +29,14 @@ - #include - #include - #include --#include --#include --#include --#include --#include - #include - #include - #include - -+#include -+#include -+#include -+ - #include "lstack_log.h" - #include "common/dpdk_common.h" - #include "lstack_lockless_queue.h" -diff --git a/src/lstack/core/lstack_init.c b/src/lstack/core/lstack_init.c -index 541480d..7f484f4 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 08836da..805ac82 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -12,19 +12,19 @@ - - #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" -@@ -1316,20 +1316,20 @@ void get_lwip_conntable(struct rpc_msg *msg) - } - - 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 = pcbl->local_ip.addr; - 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 c31e65b..eea0a47 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -12,17 +12,16 @@ - - #include - #include -- -+#include -+#include - #include - - #include --#include -+#include - #include - #include - #include - #include --#include --#include - - #include "common/gazelle_base_func.h" - #include "lstack_thread_rpc.h" -@@ -292,9 +291,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); - -@@ -378,9 +374,9 @@ static struct protocol_stack *stack_thread_init(void *arg) - } - RTE_PER_LCORE(_lcore_id) = stack->cpu_id; - -+ sys_timer_init(); - hugepage_init(); -- -- 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 9f2e93a..00679ab 100644 ---- a/src/lstack/core/lstack_stack_stat.c -+++ b/src/lstack/core/lstack_stack_stat.c -@@ -29,25 +29,6 @@ - #include "lstack_dpdk.h" - #include "lstack_stack_stat.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 calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, - enum GAZELLE_LATENCY_TYPE type) - { -@@ -62,7 +43,7 @@ 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; -+ latency = get_now_us() - lt->stamp; - - struct stack_latency *latency_stat = (type == GAZELLE_LATENCY_LWIP) ? - &stack_latency->lwip_latency : &stack_latency->read_latency; -@@ -117,7 +98,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 = get_now_us(); - stack->latency.lwip_latency.latency_min = ~((uint64_t)0); - stack->latency.read_latency.latency_min = ~((uint64_t)0); - memset_s(&stack->aggregate_stats, sizeof(struct gazelle_stack_aggregate_stats), -diff --git a/src/lstack/include/lstack_stack_stat.h b/src/lstack/include/lstack_stack_stat.h -index 5737bae..c42c68c 100644 ---- a/src/lstack/include/lstack_stack_stat.h -+++ b/src/lstack/include/lstack_stack_stat.h -@@ -25,7 +25,6 @@ void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const - enum GAZELLE_LATENCY_TYPE type); - void stack_stat_init(void); - int32_t handle_stack_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 657ffa9..4384581 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 "lstack_lockless_queue.h" - -diff --git a/src/lstack/include/posix/lstack_socket.h b/src/lstack/include/posix/lstack_socket.h -index a3ce1eb..45add74 100644 ---- a/src/lstack/include/posix/lstack_socket.h -+++ b/src/lstack/include/posix/lstack_socket.h -@@ -37,7 +37,7 @@ ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, void *from, void - ssize_t lwip_recv(int s, void *mem, size_t len, int flags); - - int lwip_fcntl(int s, int cmd, int val); --int lwip_ioctl(int s, int cmd, ...); -+int lwip_ioctl(int s, long cmd, void *argp); - - #ifdef __cplusplus - } -diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c -index 3923b77..ccaea7d 100644 ---- a/src/lstack/netif/lstack_ethdev.c -+++ b/src/lstack/netif/lstack_ethdev.c -@@ -134,7 +134,7 @@ int32_t eth_dev_poll(void) - } - - if (!cfg->use_ltran && get_protocol_stack_group()->latency_start) { -- uint64_t time_stamp = get_current_time(); -+ uint64_t time_stamp = get_now_us(); - time_stamp_into_mbuf(nr_pkts, stack->pkts, time_stamp); - } - -@@ -768,7 +768,7 @@ int32_t gazelle_eth_dev_poll(struct protocol_stack *stack, uint8_t use_ltran_fla - } - - if (!use_ltran_flag && get_protocol_stack_group()->latency_start) { -- uint64_t time_stamp = get_current_time(); -+ uint64_t time_stamp = get_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 55105f6..4e69f11 100644 ---- a/src/ltran/ltran_forward.c -+++ b/src/ltran/ltran_forward.c -@@ -19,7 +19,6 @@ - #include - #include - #include --#include - #include - #include - -@@ -65,7 +64,7 @@ static void calculate_ltran_latency(struct gazelle_stack *stack, const struct rt - return; - } - -- latency = get_current_time() - lt->stamp; -+ latency = get_now_us() - lt->stamp; - - stack->stack_stats.latency_total += latency; - stack->stack_stats.latency_pkts++; -@@ -561,7 +560,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 = get_now_us(); - } - - rx_count = rte_eth_rx_burst(port_id, queue_id, buf, GAZELLE_PACKET_READ_SIZE); -@@ -623,9 +622,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 = get_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++) { -@@ -637,7 +635,7 @@ void upstream_forward(const uint16_t *port) - rte_kni_handle_request(get_gazelle_kni()); - } - -- now_time = get_current_time(); -+ now_time = get_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 774b9cc..384a9a0 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 = get_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 af37679..2a068ea 100644 ---- a/src/ltran/ltran_timer.c -+++ b/src/ltran/ltran_timer.c -@@ -15,7 +15,6 @@ - - #include - #include --#include - #include - - #include "ltran_param.h" -@@ -25,22 +24,6 @@ - #include "ltran_instance.h" - #include "ltran_timer.h" - --static uint64_t g_cycles_per_us = 0; -- --uint64_t get_current_time(void) --{ -- if (g_cycles_per_us == 0) { -- return 0; -- } -- -- 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..59aa21b 100644 ---- a/src/ltran/ltran_timer.h -+++ b/src/ltran/ltran_timer.h -@@ -16,8 +16,6 @@ - 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..5e334ff 100644 ---- a/test/unitest/stub.c -+++ b/test/unitest/stub.c -@@ -13,7 +13,7 @@ - #include - #include - --uint64_t get_current_time(void) -+uint64_t get_now_us(void) - { - return 0; - } --- -2.23.0 - diff --git a/0248-cleancode-refactor-memp.patch b/0248-cleancode-refactor-memp.patch deleted file mode 100644 index d30ed32..0000000 --- a/0248-cleancode-refactor-memp.patch +++ /dev/null @@ -1,34 +0,0 @@ -From bae01ffd9e3970490ff8ab407008219b9fb3988c Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Mon, 29 May 2023 19:30:55 +0800 -Subject: [PATCH] cleancode: refactor memp - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_protocol_stack.c | 3 --- - 1 file changed, 3 deletions(-) - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index eea0a47..2fbe3eb 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -19,7 +19,6 @@ - #include - #include - #include --#include - #include - #include - -@@ -374,8 +373,6 @@ static struct protocol_stack *stack_thread_init(void *arg) - } - RTE_PER_LCORE(_lcore_id) = stack->cpu_id; - -- sys_timer_init(); -- hugepage_init(); - lwip_init(); - - if (use_ltran()) { --- -2.23.0 - diff --git a/0250-fix-coredump-caused-by-lwip_get_socket_nouse.patch b/0250-fix-coredump-caused-by-lwip_get_socket_nouse.patch deleted file mode 100644 index ccc9b41..0000000 --- a/0250-fix-coredump-caused-by-lwip_get_socket_nouse.patch +++ /dev/null @@ -1,135 +0,0 @@ -From f67317cc61f686bc68c79019a7e1686eab160c5e Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 2 Jun 2023 14:35:16 +0800 -Subject: [PATCH] fix coredump caused by lwip_get_socket_nouse - -Signed-off-by: Lemmy Huang ---- - src/lstack/api/lstack_epoll.c | 2 +- - src/lstack/api/lstack_wrap.c | 2 +- - src/lstack/core/lstack_lwip.c | 6 +++--- - src/lstack/core/lstack_protocol_stack.c | 15 +++++++++------ - 4 files changed, 14 insertions(+), 11 deletions(-) - -diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c -index 64c3600..621762d 100644 ---- a/src/lstack/api/lstack_epoll.c -+++ b/src/lstack/api/lstack_epoll.c -@@ -313,7 +313,7 @@ int32_t lstack_epoll_ctl(int32_t epfd, int32_t op, int32_t fd, struct epoll_even - - struct wakeup_poll *wakeup = epoll_sock->wakeup; - struct lwip_sock *sock = lwip_get_socket_nouse(fd); -- if (sock == NULL) { -+ if (sock == NULL || sock->conn == NULL) { - 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 776646f..1f04ae2 100644 ---- a/src/lstack/api/lstack_wrap.c -+++ b/src/lstack/api/lstack_wrap.c -@@ -288,7 +288,7 @@ static int32_t do_connect(int32_t s, const struct sockaddr *name, socklen_t name - } - - sock = lwip_get_socket_nouse(s); -- if (sock == NULL) { -+ if (sock == NULL || sock->conn == NULL) { - return posix_api->connect_fn(s, name, namelen); - } - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 62b4838..2e40862 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -173,7 +173,7 @@ void gazelle_init_sock(int32_t fd) - static _Atomic uint32_t name_tick = 0; - struct protocol_stack *stack = get_protocol_stack(); - struct lwip_sock *sock = lwip_get_socket_nouse(fd); -- if (sock == NULL) { -+ if (sock == NULL || sock->conn == NULL) { - return; - } - -@@ -687,7 +687,7 @@ void stack_send(struct rpc_msg *msg) - bool replenish_again; - - struct lwip_sock *sock = lwip_get_socket_nouse(fd); -- if (sock == NULL) { -+ if (sock == NULL || sock->conn == NULL) { - msg->result = -1; - LSTACK_LOG(ERR, LSTACK, "stack_send: sock error!\n"); - rpc_msg_free(msg); -@@ -1251,7 +1251,7 @@ int32_t gazelle_socket(int domain, int type, int protocol) - gazelle_init_sock(fd); - - struct lwip_sock *sock = lwip_get_socket_nouse(fd); -- if (sock == NULL || sock->stack == NULL) { -+ if (sock == NULL || sock->conn == NULL || sock->stack == NULL) { - lwip_close(fd); - gazelle_clean_sock(fd); - posix_api->close_fn(fd); -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index ce1c6de..8638cd5 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -108,7 +108,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_nouse(fd); -- if (sock == NULL) { -+ if (sock == NULL || sock->conn == NULL) { - return NULL; - } - -@@ -683,7 +683,7 @@ void stack_accept(struct rpc_msg *msg) - } - - struct lwip_sock *sock = lwip_get_socket_nouse(accept_fd); -- if (sock == NULL || sock->stack == NULL) { -+ if (sock == NULL || sock->conn == NULL || sock->stack == NULL) { - lwip_close(accept_fd); - gazelle_clean_sock(accept_fd); - posix_api->close_fn(accept_fd); -@@ -815,7 +815,7 @@ int32_t stack_broadcast_close(int32_t fd) - struct lwip_sock *sock = lwip_get_socket_nouse(fd); - int32_t ret = 0; - -- if (sock == NULL) { -+ if (sock == NULL || sock->conn == NULL) { - return -1; - } - -@@ -850,7 +850,7 @@ int32_t stack_broadcast_listen(int32_t fd, int32_t backlog) - int32_t ret, clone_fd; - - struct lwip_sock *sock = lwip_get_socket_nouse(fd); -- if (sock == NULL) { -+ if (sock == NULL || sock->conn == NULL) { - LSTACK_LOG(ERR, LSTACK, "tid %ld, %d get sock null\n", get_stack_tid(), fd); - GAZELLE_RETURN(EINVAL); - } -@@ -895,8 +895,11 @@ 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 = lwip_get_socket_nouse(fd); - struct lwip_sock *min_sock = NULL; -+ struct lwip_sock *sock = lwip_get_socket_nouse(fd); -+ if (sock == NULL || sock->conn == NULL) { -+ return NULL; -+ } - - while (sock) { - if (!NETCONN_IS_ACCEPTIN(sock)) { -@@ -934,7 +937,7 @@ int32_t stack_broadcast_accept4(int32_t fd, struct sockaddr *addr, socklen_t *ad - int32_t ret = -1; - - struct lwip_sock *sock = lwip_get_socket_nouse(fd); -- if (sock == NULL) { -+ if (sock == NULL || sock->conn == NULL) { - errno = EINVAL; - return -1; - } --- -2.23.0 - diff --git a/0251-fix-socket-init-and-clean.patch b/0251-fix-socket-init-and-clean.patch deleted file mode 100644 index df44ef2..0000000 --- a/0251-fix-socket-init-and-clean.patch +++ /dev/null @@ -1,65 +0,0 @@ -From 30d1ef00734485405c4babbf7d4cfe670ac8b52f Mon Sep 17 00:00:00 2001 -From: Lemmy Huang -Date: Fri, 2 Jun 2023 15:31:08 +0800 -Subject: [PATCH] fix socket init and clean - -Signed-off-by: Lemmy Huang ---- - src/lstack/core/lstack_lwip.c | 6 +----- - src/lstack/core/lstack_protocol_stack.c | 6 ------ - 2 files changed, 1 insertion(+), 11 deletions(-) - -diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c -index 2e40862..ca63c22 100644 ---- a/src/lstack/core/lstack_lwip.c -+++ b/src/lstack/core/lstack_lwip.c -@@ -173,7 +173,7 @@ void gazelle_init_sock(int32_t fd) - static _Atomic uint32_t name_tick = 0; - struct protocol_stack *stack = get_protocol_stack(); - struct lwip_sock *sock = lwip_get_socket_nouse(fd); -- if (sock == NULL || sock->conn == NULL) { -+ if (sock == NULL) { - return; - } - -@@ -1248,13 +1248,9 @@ int32_t gazelle_socket(int domain, int type, int protocol) - return fd; - } - -- gazelle_init_sock(fd); -- - struct lwip_sock *sock = lwip_get_socket_nouse(fd); - if (sock == NULL || sock->conn == NULL || sock->stack == NULL) { - lwip_close(fd); -- gazelle_clean_sock(fd); -- posix_api->close_fn(fd); - return -1; - } - -diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c -index 8638cd5..2fbe62c 100644 ---- a/src/lstack/core/lstack_protocol_stack.c -+++ b/src/lstack/core/lstack_protocol_stack.c -@@ -639,10 +639,6 @@ void stack_close(struct rpc_msg *msg) - 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); - } -- -- gazelle_clean_sock(fd); -- -- posix_api->close_fn(fd); - } - - void stack_bind(struct rpc_msg *msg) -@@ -685,8 +681,6 @@ void stack_accept(struct rpc_msg *msg) - struct lwip_sock *sock = lwip_get_socket_nouse(accept_fd); - if (sock == NULL || sock->conn == NULL || sock->stack == NULL) { - lwip_close(accept_fd); -- gazelle_clean_sock(accept_fd); -- posix_api->close_fn(accept_fd); - LSTACK_LOG(ERR, LSTACK, "fd %d ret %d\n", fd, accept_fd); - return; - } --- -2.23.0 - diff --git a/gazelle.spec b/gazelle.spec index f8ed440..ea834df 100644 --- a/gazelle.spec +++ b/gazelle.spec @@ -2,7 +2,7 @@ Name: gazelle Version: 1.0.1 -Release: 60 +Release: 61 Summary: gazelle is a high performance user-mode stack License: MulanPSL-2.0 URL: https://gitee.com/openeuler/gazelle @@ -255,17 +255,7 @@ Patch9237: 0237-add-bond4-suport.patch Patch9238: 0238-clean-code.patch Patch9239: 0239-add-udp-multicast-support-in-gazelle.patch Patch9240: 0240-modify-huge-dir-dir-name.patch -Patch9241: 0241-cleancode-improving-makefile-readability.patch -Patch9242: 0242-cleancode-rename-gazelle-files-in-lwip.patch -Patch9243: 0243-cleancode-refactor-lwipsock.h.patch -Patch9244: 0244-cleancode-refactor-gazelle_posix_api.h.patch -Patch9245: 0245-cleancode-refactor-gazelle_list.h.patch -Patch9246: 0246-cleancode-refactor-gazelle_hlist.h.patch -Patch9247: 0247-cleancode-refactor-sys_now-and-lwip_ioctl.patch -Patch9248: 0248-cleancode-refactor-memp.patch -Patch9249: 0249-drop-netbuf-in-read_lwip_data-to-fix-mem-overflow.patch -Patch9250: 0250-fix-coredump-caused-by-lwip_get_socket_nouse.patch -Patch9251: 0251-fix-socket-init-and-clean.patch +Patch9241: 0241-drop-netbuf-in-read_lwip_data-to-fix-mem-overflow.patch %description %{name} is a high performance user-mode stack. @@ -306,6 +296,9 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b %config(noreplace) %{conf_path}/ltran.conf %changelog +* Tue Jun 6 2023 jiangheng - 1.0.1-61 +- revert cleancode series patches + * Fri Jun 2 2023 LemmyHuang - 1.0.1-60 - fix socket init and clean - fix coredump caused by lwip_get_socket_nouse