From 6effda429020e186f4080f9f95bd8d6dd23d2cd5 Mon Sep 17 00:00:00 2001 From: Lemmy Huang Date: Mon, 8 Jul 2024 18:15:22 +0800 Subject: [PATCH] cleancode: improving makefile readability cleancode: remove perf Signed-off-by: Lemmy Huang (cherry picked from commit a47e06640116c144a038f330f4b044c9e4741fcf) --- ...ncode-improving-makefile-readability.patch | 182 +++++ 0146-cleancode-remove-perf.patch | 767 ++++++++++++++++++ lwip.spec | 10 +- 3 files changed, 957 insertions(+), 2 deletions(-) create mode 100644 0145-cleancode-improving-makefile-readability.patch create mode 100644 0146-cleancode-remove-perf.patch diff --git a/0145-cleancode-improving-makefile-readability.patch b/0145-cleancode-improving-makefile-readability.patch new file mode 100644 index 0000000..5bcaa96 --- /dev/null +++ b/0145-cleancode-improving-makefile-readability.patch @@ -0,0 +1,182 @@ +From cdf21c93fd91d074e3b5ba21d85d3c2cd891503c Mon Sep 17 00:00:00 2001 +From: Lemmy Huang +Date: Mon, 8 Jul 2024 15:34:42 +0800 +Subject: [PATCH 1/2] cleancode: improving makefile readability + +Signed-off-by: Lemmy Huang +--- + src/Makefile | 59 +++++++++++++++------------- + src/Printlog.mk | 15 +++++++ + src/api/{dir.mk => gazelle_dir.mk} | 0 + src/api/posix_api.c | 1 - + src/api/sys_arch.c | 1 - + src/core/{dir.mk => gazelle_dir.mk} | 0 + src/netif/{dir.mk => gazelle_dir.mk} | 0 + 7 files changed, 47 insertions(+), 29 deletions(-) + create mode 100644 src/Printlog.mk + rename src/api/{dir.mk => gazelle_dir.mk} (100%) + rename src/core/{dir.mk => gazelle_dir.mk} (100%) + rename src/netif/{dir.mk => gazelle_dir.mk} (100%) + +diff --git a/src/Makefile b/src/Makefile +index ce059e1..06e64f6 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -1,6 +1,8 @@ + LWIP_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) + ROOT_DIR := $(dir $(abspath $(LWIP_DIR))) + ++include $(LWIP_DIR)/Printlog.mk ++ + LWIP_INC = $(LWIP_DIR)/include + DPDK_VERSION := $(shell rpm -q --queryformat '%{VERSION}' dpdk) + ifeq ($(DPDK_VERSION),21.11) +@@ -9,58 +11,61 @@ else + DPDK_INCLUDE_FILE := /usr/include/dpdk + endif + +-SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIRY_SOURCE=2 -O2 +- + CC = gcc + AR = ar +-OPTIMIZATION = -O3 +-INC = -I$(LWIP_DIR) \ +- -I$(LWIP_INC) \ +- -I$(DPDK_INCLUDE_FILE) +- +-CFLAGS = -g $(OPTIMIZATION) $(INC) $(SEC_FLAGS) + ARFLAGS = crDP + ++SEC_FLAGS = -fstack-protector-strong -Werror -Wall -Wl,-z,relro,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIC -D_FORTIRY_SOURCE=2 ++CFLAGS = $(SEC_FLAGS) ++CFLAGS += -D__USE_GNU=1 -D_GNU_SOURCE=1 ++CFLAGS += -O2 -g ++ + ifeq ($(shell $(CC) -dumpmachine | cut -d"-" -f1), x86_64) + CFLAGS += -mssse3 + endif + ++INC = -I$(LWIP_DIR) \ ++ -I$(LWIP_INC) \ ++ -I$(DPDK_INCLUDE_FILE) ++ ++CFLAGS += $(INC) ++$(info [CFLAGS] $(CFLAGS)) ++ ++ + SRCS = + DIRS = api core netif + + define register_dir +-SRCS += $(patsubst %, $(1)/%, $(2)) ++ SRCS += $(patsubst %, $(1)/%, $(2)) + endef +- +-include $(patsubst %, %/dir.mk, $(DIRS)) ++include $(patsubst %, %/gazelle_dir.mk, $(DIRS)) + + OBJS = $(subst .c,.o,$(SRCS)) +-TMPS := $(subst .c,.s,$(SRCS)) +-TMPS += $(subst .c,.i,$(SRCS)) + + LWIP_LIB = liblwip.a + + INSTALL_LIB = $(DESTDIR)/usr/lib64 + INSTALL_INC = $(DESTDIR)/usr/include/lwip + +-.PHONY: all ++.PHONY: all install clean + all: $(LWIP_LIB) + +-.depend: $(SRCS) +- rm -f ./.depend +- $(foreach SRC,$(SRCS),$(CC) $(CFLAGS) -MM -MT $(SRC:.c=.o) $(SRC) >> .depend;) +- +--include .depend +- + $(LWIP_LIB): $(OBJS) +- $(AR) $(ARFLAGS) $@ $(OBJS) ++ $(call printlog, BUILD, $@) ++ $(QUIET) $(AR) $(ARFLAGS) $@ $(OBJS) ++ ++%.o: %.c ++ $(call printlog, BUILD, $@) ++ $(QUIET) $(CC) $(CFLAGS) -c $(filter %.c,$^) -o $@ + +-.PHONY: install + install: +- install -dp $(INSTALL_LIB) $(INSTALL_INC) +- install -Dp $(LWIP_DIR)/$(LWIP_LIB) $(INSTALL_LIB) +- cp -pr $(LWIP_INC)/* $(INSTALL_INC)/ ++ $(QUIET) install -dp $(INSTALL_LIB) $(INSTALL_INC) ++ $(call printlog, INSTALL, $(INSTALL_LIB)/$(LWIP_LIB)) ++ $(QUIET) install -Dp $(LWIP_DIR)/$(LWIP_LIB) $(INSTALL_LIB) ++ $(call printlog, INSTALL, $(INSTALL_INC)) ++ $(QUIET) cp -pr $(LWIP_INC)/* $(INSTALL_INC)/ ++ $(QUIET) cp -p Printlog.mk $(INSTALL_INC)/ + +-.PHONY: clean + clean: +- $(RM) $(LWIP_LIB) $(OBJS) $(TMPS) .depend ++ $(call printlog, CLEAN, $(LWIP_LIB)) ++ $(QUIET) $(RM) $(LWIP_LIB) $(OBJS) +diff --git a/src/Printlog.mk b/src/Printlog.mk +new file mode 100644 +index 0000000..740035c +--- /dev/null ++++ b/src/Printlog.mk +@@ -0,0 +1,15 @@ ++ ++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/api/dir.mk b/src/api/gazelle_dir.mk +similarity index 100% +rename from src/api/dir.mk +rename to src/api/gazelle_dir.mk +diff --git a/src/api/posix_api.c b/src/api/posix_api.c +index 0dc6ad1..fc5a78a 100644 +--- a/src/api/posix_api.c ++++ b/src/api/posix_api.c +@@ -30,7 +30,6 @@ + * + */ + +-#define _GNU_SOURCE + #include + #include + #include +diff --git a/src/api/sys_arch.c b/src/api/sys_arch.c +index b80c0a8..3586357 100644 +--- a/src/api/sys_arch.c ++++ b/src/api/sys_arch.c +@@ -30,7 +30,6 @@ + * + */ + +-#define _GNU_SOURCE + #include + #include + #include +diff --git a/src/core/dir.mk b/src/core/gazelle_dir.mk +similarity index 100% +rename from src/core/dir.mk +rename to src/core/gazelle_dir.mk +diff --git a/src/netif/dir.mk b/src/netif/gazelle_dir.mk +similarity index 100% +rename from src/netif/dir.mk +rename to src/netif/gazelle_dir.mk +-- +2.33.0 + diff --git a/0146-cleancode-remove-perf.patch b/0146-cleancode-remove-perf.patch new file mode 100644 index 0000000..acf6b55 --- /dev/null +++ b/0146-cleancode-remove-perf.patch @@ -0,0 +1,767 @@ +From caaae52ed2af00869270221f64e20deaaed6368c Mon Sep 17 00:00:00 2001 +From: Lemmy Huang +Date: Mon, 8 Jul 2024 17:40:25 +0800 +Subject: [PATCH 2/2] cleancode: remove perf + +Signed-off-by: Lemmy Huang +--- + src/api/api_lib.c | 2 - + src/api/api_msg.c | 4 - + src/api/gazelle_dir.mk | 2 +- + src/api/perf.c | 182 ---------------------------------------- + src/core/ipv4/ip4.c | 14 +--- + src/core/ipv6/ip6.c | 10 --- + src/core/tcp.c | 1 - + src/core/tcp_in.c | 22 ----- + src/core/tcp_out.c | 19 ----- + src/core/udp.c | 22 +---- + src/include/arch/perf.h | 155 ---------------------------------- + src/include/lwipopts.h | 3 +- + 12 files changed, 7 insertions(+), 429 deletions(-) + delete mode 100644 src/api/perf.c + delete mode 100644 src/include/arch/perf.h + +diff --git a/src/api/api_lib.c b/src/api/api_lib.c +index 1721d49..851c7cc +--- a/src/api/api_lib.c ++++ b/src/api/api_lib.c +@@ -1075,9 +1075,7 @@ netconn_write_vectors_partly(struct netconn *conn, struct netvector *vectors, u1 + /* For locking the core: this _can_ be delayed on low memory/low send buffer, + but if it is, this is done inside api_msg.c:do_write(), so we can use the + non-blocking version here. */ +- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_DATA_SEND); + err = netconn_apimsg(lwip_netconn_do_write, &API_MSG_VAR_REF(msg)); +- PERF_STOP_INCREASE_COUNT("lwip_netconn_do_write", PERF_LAYER_TCP); + if (err == ERR_OK) { + if (bytes_written != NULL) { + *bytes_written = API_MSG_VAR_REF(msg).msg.w.offset; +diff --git a/src/api/api_msg.c b/src/api/api_msg.c +index 0d33c67..60801c4 +--- a/src/api/api_msg.c ++++ b/src/api/api_msg.c +@@ -1410,7 +1410,6 @@ lwip_netconn_do_connected(void *arg, struct tcp_pcb *pcb, err_t err) + if (was_blocking) { + sys_sem_signal(op_completed_sem); + } +- + return ERR_OK; + } + #endif /* LWIP_TCP */ +@@ -1445,7 +1444,6 @@ lwip_netconn_do_connect(void *m) + #endif /* LWIP_UDP */ + #if LWIP_TCP + case NETCONN_TCP: +- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_SEND); + /* Prevent connect while doing any other action. */ + if (msg->conn->state == NETCONN_CONNECT) { + err = ERR_ALREADY; +@@ -1463,7 +1461,6 @@ lwip_netconn_do_connect(void *m) + err = ERR_INPROGRESS; + } else { + msg->conn->current_msg = msg; +- PERF_STOP_INCREASE_COUNT("lwip_netconn_do_connect", PERF_LAYER_TCP); + /* sys_sem_signal() is called from lwip_netconn_do_connected (or err_tcp()), + when the connection is established! */ + #if LWIP_TCPIP_CORE_LOCKING +@@ -1477,7 +1474,6 @@ lwip_netconn_do_connect(void *m) + } + } + } +- PERF_STOP_INCREASE_COUNT("lwip_netconn_do_connect", PERF_LAYER_TCP); + break; + #endif /* LWIP_TCP */ + default: +diff --git a/src/api/gazelle_dir.mk b/src/api/gazelle_dir.mk +index afbf863..c069a29 100644 +--- a/src/api/gazelle_dir.mk ++++ b/src/api/gazelle_dir.mk +@@ -1,3 +1,3 @@ +-SRC = api_lib.c api_msg.c err.c netbuf.c netdb.c netifapi.c sockets.c tcpip.c perf.c posix_api.c sys_arch.c ++SRC = api_lib.c api_msg.c err.c netbuf.c netdb.c netifapi.c sockets.c tcpip.c posix_api.c sys_arch.c + + $(eval $(call register_dir, api, $(SRC))) +diff --git a/src/api/perf.c b/src/api/perf.c +deleted file mode 100644 +index 1c2a273..0000000 +--- a/src/api/perf.c ++++ /dev/null +@@ -1,182 +0,0 @@ +-/* +- * Copyright (c) 2001-2004 Swedish Institute of Computer Science. +- * All rights reserved. +- * +- * Redistribution and use in source and binary forms, with or without modification, +- * are permitted provided that the following conditions are met: +- * +- * 1. Redistributions of source code must retain the above copyright notice, +- * this list of conditions and the following disclaimer. +- * 2. Redistributions in binary form must reproduce the above copyright notice, +- * this list of conditions and the following disclaimer in the documentation +- * and/or other materials provided with the distribution. +- * 3. The name of the author may not be used to endorse or promote products +- * derived from this software without specific prior written permission. +- * +- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +- * OF SUCH DAMAGE. +- * +- * This file is part of the lwIP TCP/IP stack. +- * +- * Author: Huawei Technologies +- * +- */ +- +-#include "arch/perf.h" +- +-#include +- +-#include +- +-#if LWIP_RECORD_PERF +- +-#define SIG_FUNC_NUM 3 +- +-#define SIG_STATS_DISPLAY 38 +-#define SIG_PERF_BEGIN 39 +-#define SIG_PERF_END 40 +- +-typedef void (*pSignalFunc) (int); +-static void signal_stats_display(int s); +-static void signal_perf_begin(int s); +-static void signal_perf_end(int s); +- +-uint32_t g_record_perf; +-__thread uint64_t g_timeTaken[PERF_POINT_END]; +-__thread int g_perfPoint[PERF_LAYER_END]; +-__thread struct timespec tvStart[PERF_LAYER_END]; +-volatile uint64_t g_perfMaxtime[PERF_POINT_END]; +-volatile uint64_t g_astPacketCnt[PERF_POINT_END]; +-volatile uint64_t g_astPacketProcTime[PERF_POINT_END]; +- +-char *g_ppLayerName[PERF_POINT_END] = { +- "IP_RECV", +- "TCP_DATA_RECV", +- "UDP_PARTIAL", +- "TCP_SYN_RECV", +- "TCP_SYN_ACK_SEND", +- "TCP_ACK_RECV", +- "TCP_SYN_SEND", +- "TCP_SYN_ACK_RECV", +- "TCP_ACK_SEND", +- "TCP_DATA_SEND", +- "IP_SEND" +-}; +- +-static int gsig_arr[SIG_FUNC_NUM] = { +- SIG_STATS_DISPLAY, +- SIG_PERF_BEGIN, +- SIG_PERF_END +-}; +- +-static pSignalFunc g_Funcs[SIG_FUNC_NUM] = { +- signal_stats_display, +- signal_perf_begin, +- signal_perf_end, +-}; +- +-static void print_perf_data_and_reset() +-{ +- int i; +- printf("\n********* PERF DATA START*************\n"); +- for (i = 0; i < PERF_POINT_END; i++) { +- printf("%-20s Total: PacketProcTime: %-15"PRIu64", Maxtime: %-15"PRIu64", packetCnt: %-15"PRIu64"\n", +- g_ppLayerName[i], __sync_fetch_and_or(&g_astPacketProcTime[i], 0), +- __sync_fetch_and_or(&g_perfMaxtime[i], 0), +- __sync_fetch_and_or(&g_astPacketCnt[i], 0)); +- +- if (__sync_fetch_and_or(&g_astPacketProcTime[i], 0) && __sync_fetch_and_or(&g_astPacketCnt[i], 0)) { +- printf("%-20s Average: PacketProcTime: %-15lf, MaxTime: %-15"PRIu64"\n", g_ppLayerName[i], +- (double)__sync_fetch_and_or(&g_astPacketProcTime[i], 0) / (double)__sync_fetch_and_or(&g_astPacketCnt[i], 0), +- __sync_or_and_fetch(&g_perfMaxtime[i], 0)); +- } +- +- __sync_fetch_and_and (&g_astPacketProcTime[i], 0); +- __sync_fetch_and_and (&g_astPacketCnt[i], 0); +- __sync_fetch_and_and (&g_perfMaxtime[i], 0); +- } +- printf("\n********* PERF DATA END*************\n"); +-} +- +-static void signal_stats_display(int s) +-{ +- struct sigaction s_test; +- printf("Received signal %d, stats display.\n", s); +- stats_display(); +- s_test.sa_handler = (void *) signal_stats_display; +- if (sigemptyset(&s_test.sa_mask) != 0) { +- printf("sigemptyset failed.\n"); +- } +- s_test.sa_flags = SA_RESETHAND; +- if (sigaction(s, &s_test, NULL) != 0) { +- printf("Could not register %d signal handler.\n", s); +- } +-} +- +-static void signal_perf_begin(int s) +-{ +- struct sigaction s_test; +- printf("Received signal %d, perf_begin.\n", s); +- g_record_perf = 1; +- s_test.sa_handler = (void *) signal_perf_begin; +- if (sigemptyset(&s_test.sa_mask) != 0) { +- printf("sigemptyset failed.\n"); +- } +- s_test.sa_flags = SA_RESETHAND; +- if (sigaction(s, &s_test, NULL) != 0) { +- printf("Could not register %d signal handler.\n", s); +- } +-} +- +-static void signal_perf_end(int s) +-{ +- struct sigaction s_test; +- printf("Received signal %d, perf_end\n", s); +- g_record_perf = 0; +- print_perf_data_and_reset(); +- s_test.sa_handler = (void *) signal_perf_end; +- if (sigemptyset(&s_test.sa_mask) != 0) { +- printf("sigemptyset failed.\n"); +- } +- s_test.sa_flags = SA_RESETHAND; +- if (sigaction(s, &s_test, NULL) != 0) { +- printf("Could not register %d signal handler.\n", s); +- } +-} +- +-int check_layer_point(int layer, int point) +-{ +- if (point == g_perfPoint[layer]) { +- return 1; +- } +- return 0; +-} +- +-int perf_init(void) +-{ +- int i; +- struct sigaction s_test; +- for (i = 0; i < SIG_FUNC_NUM; i++) { +- s_test.sa_handler = (void *) g_Funcs[i]; +- if (sigemptyset(&s_test.sa_mask) != 0) { +- printf("sigemptyset failed.\n"); +- return 1; +- } +- +- s_test.sa_flags = SA_RESETHAND; +- if (sigaction(gsig_arr[i], &s_test, NULL) != 0) { +- printf("Could not register %d signal handler.\n", gsig_arr[i]); +- return 1; +- } +- } +- return 0; +-} +-#endif +diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c +index 0bbeefc..9e27023 +--- a/src/core/ipv4/ip4.c ++++ b/src/core/ipv4/ip4.c +@@ -286,9 +286,7 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) + { + struct netif *netif; + +-#ifndef LWIP_PERF + PERF_START; +-#endif + LWIP_UNUSED_ARG(inp); + + if (!ip4_canforward(p)) { +@@ -386,9 +384,7 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) + IP_STATS_INC(ip.xmit); + #endif + +-#ifndef LWIP_PERF + PERF_STOP("ip4_forward"); +-#endif + /* don't fragment if interface has mtu set to 0 [loopif] */ + if (netif->mtu && (p->tot_len > netif->mtu)) { + if ((IPH_OFFSET(iphdr) & PP_NTOHS(IP_DF)) == 0) { +@@ -485,8 +481,6 @@ ip4_input(struct pbuf *p, struct netif *inp) + + LWIP_ASSERT_CORE_LOCKED(); + +- PERF_START(PERF_LAYER_IP, PERF_POINT_IP_RECV); +- + #if GAZELLE_ENABLE + IP_STATS_INC(ip.rx_in); + #else +@@ -762,19 +756,13 @@ ip4_input(struct pbuf *p, struct netif *inp) + case IP_PROTO_UDPLITE: + #endif /* LWIP_UDPLITE */ + MIB2_STATS_INC(mib2.ipindelivers); +- PERF_PAUSE(PERF_LAYER_IP); + udp_input(p, inp); +- PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); + break; + #endif /* LWIP_UDP */ + #if LWIP_TCP + case IP_PROTO_TCP: + MIB2_STATS_INC(mib2.ipindelivers); +- PERF_PAUSE(PERF_LAYER_IP); +- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_RECV); + tcp_input(p, inp); +- PERF_STOP_INCREASE_COUNT("tcp_input", PERF_LAYER_TCP); +- PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); + break; + #endif /* LWIP_TCP */ + #if LWIP_ICMP +@@ -823,7 +811,6 @@ ip4_input(struct pbuf *p, struct netif *inp) + ip4_addr_set_any(ip4_current_src_addr()); + ip4_addr_set_any(ip4_current_dest_addr()); + +- PERF_STOP_INCREASE_COUNT("ip4_input", PERF_LAYER_IP); + #if GAZELLE_ENABLE + IP_STATS_INC(ip.rx_out); + #endif +@@ -1124,6 +1111,7 @@ ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, + struct netif *netif; + + LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p); ++ + if ((netif = ip4_route_src(src, dest)) == NULL) { + LWIP_DEBUGF(IP_DEBUG, ("ip4_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", + ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest))); +diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c +index 9017d87..4ee73f6 +--- a/src/core/ipv6/ip6.c ++++ b/src/core/ipv6/ip6.c +@@ -526,8 +526,6 @@ ip6_input(struct pbuf *p, struct netif *inp) + + LWIP_ASSERT_CORE_LOCKED(); + +- PERF_START(PERF_LAYER_IP, PERF_POINT_IP_RECV); +- + IP6_STATS_INC(ip6.recv); + + /* identify the IP header */ +@@ -1075,18 +1073,12 @@ options_done: + #if LWIP_UDPLITE + case IP6_NEXTH_UDPLITE: + #endif /* LWIP_UDPLITE */ +- PERF_PAUSE(PERF_LAYER_IP); + udp_input(p, inp); +- PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); + break; + #endif /* LWIP_UDP */ + #if LWIP_TCP + case IP6_NEXTH_TCP: +- PERF_PAUSE(PERF_LAYER_IP); +- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_RECV); + tcp_input(p, inp); +- PERF_STOP_INCREASE_COUNT("tcp_input", PERF_LAYER_TCP); +- PERF_RESUME(PERF_LAYER_IP, PERF_POINT_IP_RECV); + break; + #endif /* LWIP_TCP */ + #if LWIP_ICMP6 +@@ -1127,8 +1119,6 @@ ip6_input_cleanup: + ip6_addr_set_zero(ip6_current_src_addr()); + ip6_addr_set_zero(ip6_current_dest_addr()); + +- PERF_STOP_INCREASE_COUNT("ip6_input", PERF_LAYER_IP); +- + return ERR_OK; + } + +diff --git a/src/core/tcp.c b/src/core/tcp.c +index 69f6953..cf6b76d +--- a/src/core/tcp.c ++++ b/src/core/tcp.c +@@ -561,7 +561,6 @@ tcp_close(struct tcp_pcb *pcb) + /* Set a flag not to receive any more data... */ + tcp_set_flags(pcb, TF_RXCLOSED); + } +- + /* ... and close */ + return tcp_close_shutdown(pcb, 1); + } +diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c +index 6c960a6..08796b8 +--- a/src/core/tcp_in.c ++++ b/src/core/tcp_in.c +@@ -658,19 +658,7 @@ tcp_input(struct pbuf *p, struct netif *inp) + goto aborted; + } + /* Try to send something out. */ +-#if LWIP_RECORD_PERF +- if (check_layer_point(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_RECV)) { +- PERF_PAUSE(PERF_LAYER_TCP); +- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_ACK_SEND); +- } +-#endif + tcp_output(pcb); +-#if LWIP_RECORD_PERF +- if (check_layer_point(PERF_LAYER_TCP, PERF_POINT_TCP_ACK_SEND)) { +- PERF_STOP_INCREASE_COUNT("tcp_in", PERF_LAYER_TCP); +- PERF_RESUME(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_RECV); +- } +-#endif + #if TCP_INPUT_DEBUG + #if TCP_DEBUG + tcp_debug_print_state(pcb->state); +@@ -707,9 +695,7 @@ aborted: + } + + LWIP_ASSERT("tcp_input: tcp_pcbs_sane()", tcp_pcbs_sane()); +-#ifndef LWIP_PERF + PERF_STOP("tcp_input"); +-#endif + return; + dropped: + TCP_STATS_INC(tcp.drop); +@@ -780,7 +766,6 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) + tcp_rst_netif(ip_data.current_input_netif, ackno, seqno + tcplen, ip_current_dest_addr(), + ip_current_src_addr(), tcphdr->dest, tcphdr->src); + } else if (flags & TCP_SYN) { +- PERF_UPDATE_POINT(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_RECV); + LWIP_DEBUGF(TCP_DEBUG, ("TCP connection request %"U16_F" -> %"U16_F".\n", tcphdr->src, tcphdr->dest)); + #if TCP_LISTEN_BACKLOG + if (pcb->accepts_pending >= pcb->backlog) { +@@ -865,19 +850,14 @@ tcp_listen_input(struct tcp_pcb_listen *pcb) + } + #endif + +- PERF_PAUSE(PERF_LAYER_TCP); +- PERF_START(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_SEND); + /* Send a SYN|ACK together with the MSS option. */ + rc = tcp_enqueue_flags(npcb, TCP_SYN | TCP_ACK); + if (rc != ERR_OK) { + LWIP_DEBUGF(GAZELLE_DEBUG_SERIOUS, ("tcp_listen_input: send SYN or ACK failed\n")); + tcp_abandon(npcb, 0); +- PERF_RESUME(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_RECV); + return; + } + tcp_output(npcb); +- PERF_STOP_INCREASE_COUNT("tcp_output", PERF_LAYER_TCP); +- PERF_RESUME(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_RECV); + } + return; + } +@@ -1024,7 +1004,6 @@ tcp_process(struct tcp_pcb *pcb) + /* received SYN ACK with expected sequence number? */ + if ((flags & TCP_ACK) && (flags & TCP_SYN) + && (ackno == pcb->lastack + 1)) { +- PERF_UPDATE_POINT(PERF_LAYER_TCP, PERF_POINT_TCP_SYN_ACK_RECV); + pcb->rcv_nxt = seqno + 1; + pcb->rcv_ann_right_edge = pcb->rcv_nxt; + pcb->lastack = ackno; +@@ -1105,7 +1084,6 @@ tcp_process(struct tcp_pcb *pcb) + /* expected ACK number? */ + if (TCP_SEQ_BETWEEN(ackno, pcb->lastack + 1, pcb->snd_nxt)) { + pcb->state = ESTABLISHED; +- PERF_UPDATE_POINT(PERF_LAYER_TCP, PERF_POINT_TCP_ACK_RECV); + LWIP_DEBUGF(TCP_DEBUG, ("TCP connection established %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); + #if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG + if (pcb->listener == NULL) { +diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c +index 839e904..ed0c791 +--- a/src/core/tcp_out.c ++++ b/src/core/tcp_out.c +@@ -1822,11 +1822,6 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif + err_t err; + u16_t len; + u32_t *opts; +- +-#if LWIP_RECORD_PERF +- int tmpPoint; +-#endif +- + #if TCP_CHECKSUM_ON_COPY + int seg_chksum_was_swapped = 0; + #endif +@@ -2025,8 +2020,6 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif + #if !GAZELLE_ENABLE + TCP_STATS_INC(tcp.xmit); + #endif +- PERF_PAUSE_RETURN_POINT(PERF_LAYER_TCP, tmpPoint); +- PERF_START(PERF_LAYER_IP, PERF_POINT_IP_SEND); + + NETIF_SET_HINTS(netif, &(pcb->netif_hints)); + +@@ -2046,8 +2039,6 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif + #if GAZELLE_ENABLE + TCP_STATS_INC(tcp.tx_out); + #endif +- PERF_STOP_INCREASE_COUNT("ip_out", PERF_LAYER_IP); +- PERF_RESUME(PERF_LAYER_TCP, tmpPoint); + + return err; + } +@@ -2563,10 +2554,6 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) + u8_t optlen, optflags = 0; + u8_t num_sacks = 0; + +-#if LWIP_RECORD_PERF +- int tmpPoint; +-#endif +- + LWIP_ASSERT("tcp_send_empty_ack: invalid pcb", pcb != NULL); + + #if LWIP_TCP_TIMESTAMPS +@@ -2583,9 +2570,6 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) + } + #endif + +- PERF_PAUSE_RETURN_POINT(PERF_LAYER_TCP, tmpPoint); +- PERF_START(PERF_LAYER_IP, PERF_POINT_IP_SEND); +- + p = tcp_output_alloc_header(pcb, optlen, 0, lwip_htonl(pcb->snd_nxt)); + if (p == NULL) { + /* let tcp_fasttmr retry sending this ACK */ +@@ -2610,9 +2594,6 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) + tcp_clear_flags(pcb, TF_ACK_DELAY | TF_ACK_NOW); + } + +- PERF_STOP_INCREASE_COUNT("ip_out", PERF_LAYER_IP); +- PERF_RESUME(PERF_LAYER_TCP, tmpPoint); +- + return err; + } + +diff --git a/src/core/udp.c b/src/core/udp.c +index 6b11bf6..fd42bc2 +--- a/src/core/udp.c ++++ b/src/core/udp.c +@@ -269,11 +269,7 @@ udp_input(struct pbuf *p, struct netif *inp) + LWIP_ASSERT("udp_input: invalid pbuf", p != NULL); + LWIP_ASSERT("udp_input: invalid netif", inp != NULL); + +-#if LWIP_RECORD_PERF +- PERF_START(PERF_LAYER_UDP, PERF_POINT_UDP); +-#else +- //PERF_START; +-#endif ++ PERF_START; + + #if !GAZELLE_ENABLE + UDP_STATS_INC(udp.recv); +@@ -526,12 +522,7 @@ udp_input(struct pbuf *p, struct netif *inp) + UDP_STATS_INC(udp.rx_out); + #endif + end: +-#if LWIP_RECORD_PERF +- PERF_STOP_INCREASE_COUNT("udp_input", PERF_LAYER_UDP); +-#else +- //PERF_STOP("udp_input"); +-#endif +- ++ PERF_STOP("udp_input"); + return; + #if CHECKSUM_CHECK_UDP + chkerr: +@@ -541,13 +532,7 @@ chkerr: + UDP_STATS_INC(udp.drop); + MIB2_STATS_INC(mib2.udpinerrors); + pbuf_free(p); +- +-#if LWIP_RECORD_PERF +- PERF_STOP_INCREASE_COUNT("udp_input", PERF_LAYER_UDP); +-#else +- //PERF_STOP("udp_input"); +-#endif +- ++ PERF_STOP("udp_input"); + #endif /* CHECKSUM_CHECK_UDP */ + } + +@@ -596,6 +581,7 @@ udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p, + { + LWIP_ERROR("udp_send_chksum: invalid pcb", pcb != NULL, return ERR_ARG); + LWIP_ERROR("udp_send_chksum: invalid pbuf", p != NULL, return ERR_ARG); ++ + if (IP_IS_ANY_TYPE_VAL(pcb->remote_ip)) { + return ERR_VAL; + } +diff --git a/src/include/arch/perf.h b/src/include/arch/perf.h +deleted file mode 100644 +index e505da7..0000000 +--- a/src/include/arch/perf.h ++++ /dev/null +@@ -1,155 +0,0 @@ +-/* +- * Copyright (c) 2001-2004 Swedish Institute of Computer Science. +- * All rights reserved. +- * +- * Redistribution and use in source and binary forms, with or without modification, +- * are permitted provided that the following conditions are met: +- * +- * 1. Redistributions of source code must retain the above copyright notice, +- * this list of conditions and the following disclaimer. +- * 2. Redistributions in binary form must reproduce the above copyright notice, +- * this list of conditions and the following disclaimer in the documentation +- * and/or other materials provided with the distribution. +- * 3. The name of the author may not be used to endorse or promote products +- * derived from this software without specific prior written permission. +- * +- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +- * OF SUCH DAMAGE. +- * +- * This file is part of the lwIP TCP/IP stack. +- * +- * Author: Huawei Technologies +- * +- */ +- +-#ifndef LWIP_ARCH_PERF_H +-#define LWIP_ARCH_PERF_H +- +-#include +- +-#include "lwip/debug.h" +- +-#if LWIP_RECORD_PERF +-enum PERF_POINT { +- PERF_POINT_IP_RECV, +- PERF_POINT_TCP_RECV, +- PERF_POINT_UDP, +- PERF_POINT_TCP_SYN_RECV, +- PERF_POINT_TCP_SYN_ACK_SEND, +- PERF_POINT_TCP_ACK_RECV, +- PERF_POINT_TCP_SYN_SEND, +- PERF_POINT_TCP_SYN_ACK_RECV, +- PERF_POINT_TCP_ACK_SEND, +- PERF_POINT_TCP_DATA_SEND, +- PERF_POINT_IP_SEND, +- PERF_POINT_END +-}; +- +-enum PERF_LAYER { +- PERF_LAYER_IP, +- PERF_LAYER_TCP, +- PERF_LAYER_UDP, +- PERF_LAYER_END +-}; +- +-extern uint32_t g_record_perf; +- +-extern __thread uint64_t g_timeTaken[PERF_POINT_END]; +-extern __thread int g_perfPoint[PERF_LAYER_END]; +-extern __thread struct timespec tvStart[PERF_LAYER_END]; +- +-extern char *g_ppLayerName[PERF_POINT_END]; +-extern volatile uint64_t g_perfMaxtime[PERF_POINT_END]; +-extern volatile uint64_t g_astPacketCnt[PERF_POINT_END]; +-extern volatile uint64_t g_astPacketProcTime[PERF_POINT_END]; +- +-#define PERF_START(layer, point) do {\ +- g_perfPoint[(layer)] = (point);\ +- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("set point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ +- clock_gettime(CLOCK_MONOTONIC, &tvStart[(layer)]);\ +- g_timeTaken[(point)] = 0;\ +-} while (0) +- +-#define PERF_UPDATE_POINT(layer, point) do {\ +- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("old point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ +- g_timeTaken[(point)] = g_timeTaken[g_perfPoint[(layer)]];\ +- g_timeTaken[g_perfPoint[(layer)]] = 0;\ +- g_perfPoint[(layer)] = (point);\ +- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("new point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ +-} while (0) +- +-#define PERF_PAUSE(layer) do {\ +- struct timespec tvEnd;\ +- clock_gettime(CLOCK_MONOTONIC, &tvEnd);\ +- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("perf pause layer%d\n", layer));\ +- g_timeTaken[g_perfPoint[(layer)]] += ((tvEnd.tv_sec - tvStart[(layer)].tv_sec) \ +- * (1000000000UL) + (tvEnd.tv_nsec - tvStart[(layer)].tv_nsec));\ +-} while (0) +- +-#define PERF_PAUSE_RETURN_POINT(layer, pause_point) do {\ +- struct timespec tvEnd;\ +- clock_gettime(CLOCK_MONOTONIC, &tvEnd);\ +- g_timeTaken[g_perfPoint[(layer)]] += ((tvEnd.tv_sec - tvStart[(layer)].tv_sec) \ +- * (1000000000UL) + (tvEnd.tv_nsec - tvStart[(layer)].tv_nsec));\ +- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("perf pause point %d:%s\n", layer, g_ppLayerName[g_perfPoint[(layer)]]));\ +- (pause_point) = g_perfPoint[(layer)];\ +-} while (0) +- +- +-#define PERF_RESUME(layer, point) do {\ +- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("perf resule point %d:%s\n", layer, g_ppLayerName[point]));\ +- clock_gettime(CLOCK_MONOTONIC, &tvStart[(layer)]);\ +- g_perfPoint[(layer)] = (point);\ +-} while (0) +- +- +-/* x is a prompt */ +-#define PERF_STOP_INCREASE_COUNT(x, layer) do {\ +- if (g_record_perf)\ +- {\ +- struct timespec tvEnd;\ +- int i = 2;\ +- uint32_t oldValue = 0;\ +- clock_gettime(CLOCK_MONOTONIC, &tvEnd);\ +- g_timeTaken[g_perfPoint[(layer)]] += ((tvEnd.tv_sec - tvStart[(layer)].tv_sec) \ +- * (1000000000UL) + (tvEnd.tv_nsec - tvStart[(layer)].tv_nsec));\ +- while (i && !oldValue)\ +- {\ +- oldValue = __sync_or_and_fetch(&g_perfMaxtime[g_perfPoint[(layer)]], 0);\ +- if (oldValue >= g_timeTaken[g_perfPoint[(layer)]])\ +- {\ +- break;\ +- }\ +- oldValue = __sync_val_compare_and_swap(&g_perfMaxtime[g_perfPoint[(layer)]],\ +- oldValue, g_timeTaken[g_perfPoint[(layer)]]);\ +- i--;\ +- }\ +- __sync_fetch_and_add(&g_astPacketCnt[g_perfPoint[(layer)]], 1);\ +- __sync_fetch_and_add(&g_astPacketProcTime[g_perfPoint[(layer)]], g_timeTaken[g_perfPoint[(layer)]]);\ +- LWIP_DEBUGF(PERF_OUTPUT_DEBUG, ("Time for %s is: %ld\n",\ +- g_ppLayerName[g_perfPoint[(layer)]], g_timeTaken[g_perfPoint[(layer)]]));\ +- }\ +-} while (0) +- +- +-int check_layer_point(int layer, int point); +-int perf_init(); +- +-#else +-#define PERF_START(layer, point) do { } while (0) +-#define PERF_UPDATE_POINT(layer, point) do { } while (0) +-#define PERF_PAUSE(layer) do { } while (0) +-#define PERF_PAUSE_RETURN_POINT(layer, pause_point) do { } while (0) +-#define PERF_RESUME(layer, point) do { } while (0) +-#define PERF_STOP_INCREASE_COUNT(x, layer) do { } while (0) +-#endif +- +-#endif /* LWIP_ARCH_PERF_H */ +diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h +index 44dcddf..0b18629 100644 +--- a/src/include/lwipopts.h ++++ b/src/include/lwipopts.h +@@ -38,8 +38,7 @@ + ---------- gazelle options ---------- + ------------------------------------- + */ +-#define LWIP_PERF 1 +-#define LWIP_RECORD_PERF 0 ++#define LWIP_PERF 0 + + #define GAZELLE_USE_DPDK_LOG 1 + +-- +2.33.0 + diff --git a/lwip.spec b/lwip.spec index 5b48f75..611c061 100644 --- a/lwip.spec +++ b/lwip.spec @@ -4,7 +4,7 @@ Summary: lwip is a small independent implementation of the TCP/IP protocol suite Name: lwip Version: 2.2.0 -Release: 37 +Release: 38 License: BSD URL: http://savannah.nongnu.org/projects/lwip/ Source0: http://download.savannah.nongnu.org/releases/lwip/%{name}-%{version}.zip @@ -156,6 +156,8 @@ Patch9140: 0141-Improve-size-of-multicast-specifications.patch Patch9141: 0142-virtio-record-local_port-for-port_map-of-virtio.patch Patch9142: 0143-add-MCAST_MSFILTER-to-setsockopt-for-IGMPv3.patch Patch9143: 0144-add-MCAST_MSFILTER-in-setsockopt-for-MLDv2-of-IPv6.patch +Patch9144: 0145-cleancode-improving-makefile-readability.patch +Patch9145: 0146-cleancode-remove-perf.patch BuildRequires: gcc-c++ dos2unix dpdk-devel @@ -173,7 +175,7 @@ find %{_builddir}/%{name}-%{version} -type f -exec dos2unix -q {} \; %build cd %{_builddir}/%{name}-%{version}/src -%make_build +%make_build V=0 %install cd %{_builddir}/%{name}-%{version}/src @@ -185,6 +187,10 @@ cd %{_builddir}/%{name}-%{version}/src %{_libdir}/liblwip.a %changelog +* Mon Jul 8 2024 LemmyHuang - 2.2.0-38 +- cleancode improving makefile readability +- cleancode remove perf + * Wed Jul 3 2024 wanfeng - 2.2.0-37 - add MCAST_MSFILTER in setsockopt for MLDv2 of IPv6