diff --git a/0179-add-debug-cnt-about-tcp.patch b/0179-add-debug-cnt-about-tcp.patch new file mode 100644 index 0000000000000000000000000000000000000000..28583ba6a4ad72a4c028fffc29ae1d3d22463584 --- /dev/null +++ b/0179-add-debug-cnt-about-tcp.patch @@ -0,0 +1,454 @@ +From f20b472e360190f51f1ae62053db5f64a11d78f6 Mon Sep 17 00:00:00 2001 +From: hankangkang +Date: Fri, 10 Jan 2025 17:27:25 +0800 +Subject: [PATCH] add debug cnt about tcp + +--- + src/api/api_lib.c | 24 ++++++++++++++++++++++++ + src/api/api_msg.c | 31 +++++++++++++++++++++++++++++++ + src/api/lwipgz_sock.c | 21 +++++++++++++++++---- + src/api/sockets.c | 20 ++++++++++++++++++++ + src/api/sys_arch.c | 8 +++++--- + src/core/tcp_in.c | 13 +++++++++++++ + src/include/lwip/stats.h | 37 +++++++++++++++++++++++++++++++++++++ + 7 files changed, 147 insertions(+), 7 deletions(-) + +diff --git a/src/api/api_lib.c b/src/api/api_lib.c +index 851c7cc..a27cacb 100644 +--- a/src/api/api_lib.c ++++ b/src/api/api_lib.c +@@ -488,11 +488,17 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn) + err = netconn_err(conn); + if (err != ERR_OK) { + /* return pending error */ ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.netconn_accept_err); ++#endif + return err; + } + if (!NETCONN_ACCEPTMBOX_WAITABLE(conn)) { + /* don't accept if closed: this might block the application task + waiting on acceptmbox forever! */ ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.netconn_accept_acceptmbox_err_clsd); ++#endif + return ERR_CLSD; + } + +@@ -503,6 +509,9 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn) + if (sys_arch_mbox_tryfetch(&conn->acceptmbox, &accept_ptr) == SYS_MBOX_EMPTY) { + API_MSG_VAR_FREE_ACCEPT(msg); + NETCONN_MBOX_WAITING_DEC(conn); ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.netconn_accept_acceptmbox_tryfetch_err); ++#endif + return ERR_WOULDBLOCK; + } + } else { +@@ -510,6 +519,9 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn) + if (sys_arch_mbox_fetch(&conn->acceptmbox, &accept_ptr, conn->recv_timeout) == SYS_ARCH_TIMEOUT) { + API_MSG_VAR_FREE_ACCEPT(msg); + NETCONN_MBOX_WAITING_DEC(conn); ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.netconn_accept_acceptmbox_tryfetch_err_timeout); ++#endif + return ERR_TIMEOUT; + } + #else +@@ -522,6 +534,9 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn) + if (lwip_netconn_is_deallocated_msg(accept_ptr)) { + /* the netconn has been closed from another thread */ + API_MSG_VAR_FREE_ACCEPT(msg); ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.netconn_deallocated); ++#endif + return ERR_CONN; + } + } +@@ -533,11 +548,17 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn) + if (lwip_netconn_is_err_msg(accept_ptr, &err)) { + /* a connection has been aborted: e.g. out of pcbs or out of netconns during accept */ + API_MSG_VAR_FREE_ACCEPT(msg); ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.netconn_msg_err); ++#endif + return err; + } + if (accept_ptr == NULL) { + /* connection has been aborted */ + API_MSG_VAR_FREE_ACCEPT(msg); ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.netconn_accept_ptr_null); ++#endif + return ERR_CLSD; + } + newconn = (struct netconn *)accept_ptr; +@@ -551,6 +572,9 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn) + + *new_conn = newconn; + /* don't set conn->last_err: it's only ERR_OK, anyway */ ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.netconn_accept_success); ++#endif + return ERR_OK; + #else /* LWIP_TCP */ + LWIP_UNUSED_ARG(conn); +diff --git a/src/api/api_msg.c b/src/api/api_msg.c +index acd4697..15f7930 100644 +--- a/src/api/api_msg.c ++++ b/src/api/api_msg.c +@@ -364,8 +364,15 @@ recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) + } + LWIP_ASSERT("recv_tcp: recv for wrong pcb!", conn->pcb.tcp == pcb); + ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.recv_tcp_in); ++#endif ++ + if (!NETCONN_MBOX_VALID(conn, &conn->recvmbox)) { + /* recvmbox already deleted */ ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.recv_tcp_recvmbox_invaild); ++#endif + if (p != NULL) { + tcp_recved(pcb, p->tot_len); + pbuf_free(p); +@@ -386,6 +393,9 @@ recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) + + if (sys_mbox_trypost(&conn->recvmbox, msg) != ERR_OK) { + /* don't deallocate p: it is presented to us later again from tcp_fasttmr! */ ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.recv_tcp_post_recvmbox_err); ++#endif + return ERR_MEM; + } else { + #if LWIP_SO_RCVBUF +@@ -399,6 +409,9 @@ recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) + API_EVENT(conn, NETCONN_EVT_RCVPLUS, len); + } + ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.recv_tcp_out); ++#endif + return ERR_OK; + } + +@@ -603,6 +616,9 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err) + } + if (!NETCONN_MBOX_VALID(conn, &conn->acceptmbox)) { + LWIP_DEBUGF(API_MSG_DEBUG, ("accept_function: acceptmbox already deleted\n")); ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.tcp_acceptmbox_invaild); ++#endif + return ERR_VAL; + } + +@@ -612,6 +628,9 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err) + /* Register event with callback */ + API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0); + } ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.tcp_acceptmbox_newpcb_null); ++#endif + return ERR_VAL; + } + LWIP_ASSERT("expect newpcb == NULL or err == ERR_OK", err == ERR_OK); +@@ -628,6 +647,9 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err) + /* Register event with callback */ + API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0); + } ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.tcp_netconn_alloc_faild); ++#endif + return ERR_MEM; + } + newconn->pcb.tcp = newpcb; +@@ -846,6 +868,9 @@ netconn_alloc(enum netconn_type t, netconn_callback callback) + return conn; + free_and_return: + memp_free(MEMP_NETCONN, conn); ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.tcp_netconn_err); ++#endif + return NULL; + } + +@@ -1562,6 +1587,9 @@ lwip_netconn_do_listen(void *m) + err = sys_mbox_new(&msg->conn->acceptmbox, DEFAULT_ACCEPTMBOX_SIZE); + } + if (err == ERR_OK) { ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.tcp_listen_new_acceptmbox_success); ++#endif + msg->conn->state = NETCONN_LISTEN; + msg->conn->pcb.tcp = lpcb; + tcp_arg(msg->conn->pcb.tcp, msg->conn); +@@ -1570,6 +1598,9 @@ lwip_netconn_do_listen(void *m) + /* since the old pcb is already deallocated, free lpcb now */ + tcp_close(lpcb); + msg->conn->pcb.tcp = NULL; ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.tcp_listen_new_acceptmbox_err); ++#endif + } + } + } +diff --git a/src/api/lwipgz_sock.c b/src/api/lwipgz_sock.c +index fc98568..63ce317 100644 +--- a/src/api/lwipgz_sock.c ++++ b/src/api/lwipgz_sock.c +@@ -36,6 +36,8 @@ + #include "lwipgz_sock.h" + #include "lwipgz_posix_api.h" + #include "lwip/tcp.h" ++#include "lwip/stats.h" ++ + + extern struct lwip_sock *sockets; + +@@ -84,12 +86,18 @@ int gazelle_alloc_socket(struct netconn *newconn, int accepted, int flags) + flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK; + + fd = socket_new_sysfd(newconn, flags); +- if (fd < 0) ++ if (fd < 0) { ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.accept4_sock_alloc_sys_failed); ++#endif + return -1; ++ } ++ + sock = lwip_get_socket(fd); +- if (sock == NULL) ++ if (sock == NULL) { + goto out; +- ++ } ++ + sock->conn = newconn; + sock->lastdata.pbuf = NULL; + #if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL +@@ -101,8 +109,12 @@ int gazelle_alloc_socket(struct netconn *newconn, int accepted, int flags) + sock->errevent = 0; + #endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ + +- if (do_lwip_init_sock(fd) != 0) ++ if (do_lwip_init_sock(fd) != 0) { ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.accept4_sock_init_failed); ++#endif + goto out; ++ } + + if (accepted) { + int ret = 0; +@@ -111,6 +123,7 @@ int gazelle_alloc_socket(struct netconn *newconn, int accepted, int flags) + ret = find_same_node_memzone(pcb, sock); + } + if (pcb == NULL || ret != 0) { ++ LWIP_DEBUGF(LWIPGZ_LOG_ERR,(" accept faild fd = %d pcb = %p ret = %d\n",fd , pcb, ret)); + goto out; + } + } +diff --git a/src/api/sockets.c b/src/api/sockets.c +index 69c3086..7eb8bd5 100644 +--- a/src/api/sockets.c ++++ b/src/api/sockets.c +@@ -698,6 +698,10 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) + return -1; + } + ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.accept4_in); ++#endif ++ + /* wait for a new connection */ + err = netconn_accept(sock->conn, &newconn); + if (err != ERR_OK) { +@@ -714,6 +718,10 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) + } + LWIP_ASSERT("newconn != NULL", newconn != NULL); + ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.accept4_netconn_accept_success); ++#endif ++ + newsock = alloc_socket(newconn, 1, flags); + if (newsock == -1) { + netconn_delete(newconn); +@@ -721,6 +729,10 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) + done_socket(sock); + return -1; + } ++ ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.accept4_accept_alloc_socket_success); ++#endif + LWIP_ASSERT("invalid socket index", (newsock >= LWIP_SOCKET_OFFSET) && (newsock < NUM_SOCKETS + LWIP_SOCKET_OFFSET)); + nsock = &sockets[newsock - LWIP_SOCKET_OFFSET]; + +@@ -774,6 +786,10 @@ lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) + set_errno(0); + done_socket(sock); + done_socket(nsock); ++ ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.accept4_accept_out); ++#endif + return newsock; + } + +@@ -2653,10 +2669,12 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) + #if GAZELLE_ENABLE + if (netif_is_rtc_mode(netif_default)) { + if (sock->rcvevent == 1) { ++ TCP_STATS_INC(tcp.tcp_event_pollin); + add_sock_event_nolock(sock, POLLIN); + } + } else { + if (conn->acceptmbox != NULL && !sys_mbox_empty(conn->acceptmbox)) { ++ TCP_STATS_INC(tcp.tcp_event_pollin); + add_sock_event(sock, POLLIN); + } + } +@@ -2700,8 +2718,10 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) + sock->errevent = 1; + #if GAZELLE_ENABLE + if (netif_is_rtc_mode(netif_default)) { ++ TCP_STATS_INC(tcp.tcp_event_epollerr); + add_sock_event_nolock(sock, EPOLLERR); + } else { ++ TCP_STATS_INC(tcp.tcp_event_epollerr); + add_sock_event(sock, EPOLLERR); + } + #endif +diff --git a/src/api/sys_arch.c b/src/api/sys_arch.c +index 4413b0f..48d4bf2 100644 +--- a/src/api/sys_arch.c ++++ b/src/api/sys_arch.c +@@ -155,6 +155,7 @@ struct rte_ring *gazelle_ring_create_fast(const char *name, uint32_t size, uint3 + ssize_t ring_size; + char ring_name[RTE_MEMZONE_NAMESIZE] = {0}; + struct rte_ring *ring; ++ int ret = 0; + + ring_size = rte_ring_get_memsize(size); + if (ring_size < 0) { +@@ -168,7 +169,7 @@ struct rte_ring *gazelle_ring_create_fast(const char *name, uint32_t size, uint3 + */ + ring = rte_malloc_socket(NULL, ring_size, RTE_CACHE_LINE_SIZE, rte_socket_id()); + if (ring == NULL) { +- RTE_LOG(ERR, EAL, "cannot create rte_ring for mbox\n"); ++ RTE_LOG(ERR, EAL, "cannot create rte_ring for mbox name %s size %u flags %u ring_size %ld\n",name, size, flags, ring_size); + return NULL; + } + +@@ -178,9 +179,10 @@ struct rte_ring *gazelle_ring_create_fast(const char *name, uint32_t size, uint3 + return NULL; + } + +- if (rte_ring_init(ring, ring_name, size, flags) != 0) { ++ ret = rte_ring_init(ring, ring_name, size, flags); ++ if (ret != 0) { + rte_free(ring); +- RTE_LOG(ERR, EAL, "cannot init rte_ring for mbox\n"); ++ RTE_LOG(ERR, EAL, "cannot init rte_ring for mbox ring_name %s, size %u , flags %u ret %d\n", name, size, flags, ret); + return NULL; + } + +diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c +index 905f7cf..ab5c0f5 100644 +--- a/src/core/tcp_in.c ++++ b/src/core/tcp_in.c +@@ -190,6 +190,9 @@ tcp_input(struct pbuf *p, struct netif *inp) + /* drop short packets */ + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: short packet (%"U16_F" bytes) discarded\n", p->tot_len)); + TCP_STATS_INC(tcp.lenerr); ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.pkg_lenerr_pbuf_len_short); ++#endif + goto dropped; + } + +@@ -296,6 +299,9 @@ tcp_input(struct pbuf *p, struct netif *inp) + /* u16_t overflow, cannot handle this */ + LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: length u16_t overflow, cannot handle this\n")); + TCP_STATS_INC(tcp.lenerr); ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.pkg_lenerr_over_flow); ++#endif + goto dropped; + } + } +@@ -549,6 +555,9 @@ tcp_input(struct pbuf *p, struct netif *inp) + application that the connection is dead before we + deallocate the PCB. */ + TCP_EVENT_ERR(pcb->state, pcb->errf, pcb->callback_arg, ERR_RST); ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.pkg_tcp_rst); ++#endif + tcp_pcb_remove(&tcp_active_pcbs, pcb); + tcp_free(pcb); + } else { +@@ -876,6 +885,10 @@ tcp_timewait_input(struct tcp_pcb *pcb) + + LWIP_ASSERT("tcp_timewait_input: invalid pcb", pcb != NULL); + ++#if GAZELLE_ENABLE ++ TCP_STATS_INC(tcp.pkg_tcp_timewait); ++#endif ++ + /* - fourth, check the SYN bit, */ + if (flags & TCP_SYN) { + /* If an incoming segment is not acceptable, an acknowledgment +diff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h +index a83a442..5874fb4 100644 +--- a/src/include/lwip/stats.h ++++ b/src/include/lwip/stats.h +@@ -72,6 +72,43 @@ struct stats_proto { + STAT_COUNTER tx_out; /* Transmitted out packets. */ + STAT_COUNTER rx_in; /* Received in packets. */ + STAT_COUNTER rx_out; /* Received out packets. */ ++ ++ // add debug cnt ++ STAT_COUNTER tcp_acceptmbox_invaild; ++ STAT_COUNTER tcp_acceptmbox_newpcb_null; ++ STAT_COUNTER tcp_netconn_alloc_faild; ++ STAT_COUNTER tcp_netconn_err; ++ ++ STAT_COUNTER accept4_in; ++ STAT_COUNTER accept4_sock_alloc_sys_failed; ++ STAT_COUNTER accept4_sock_init_failed; ++ STAT_COUNTER accept4_netconn_accept_success; ++ STAT_COUNTER accept4_accept_alloc_socket_success; ++ STAT_COUNTER accept4_accept_out; ++ ++ STAT_COUNTER netconn_accept_err; ++ STAT_COUNTER netconn_accept_acceptmbox_err_clsd; ++ STAT_COUNTER netconn_accept_acceptmbox_tryfetch_err; ++ STAT_COUNTER netconn_accept_acceptmbox_tryfetch_err_timeout; ++ STAT_COUNTER netconn_msg_err; ++ STAT_COUNTER netconn_accept_ptr_null; ++ STAT_COUNTER netconn_accept_success; ++ ++ STAT_COUNTER recv_tcp_in; ++ STAT_COUNTER recv_tcp_out; ++ STAT_COUNTER recv_tcp_recvmbox_invaild; ++ STAT_COUNTER recv_tcp_post_recvmbox_err; ++ ++ STAT_COUNTER tcp_listen_new_acceptmbox_err; ++ STAT_COUNTER tcp_listen_new_acceptmbox_success; ++ ++ STAT_COUNTER pkg_lenerr_pbuf_len_short; ++ STAT_COUNTER pkg_lenerr_over_flow; ++ STAT_COUNTER pkg_tcp_timewait; ++ STAT_COUNTER pkg_tcp_rst; ++ ++ STAT_COUNTER tcp_event_pollin; ++ STAT_COUNTER tcp_event_epollerr; + #endif + STAT_COUNTER fw; /* Forwarded packets. */ + STAT_COUNTER drop; /* Dropped packets. */ +-- +2.33.0 + diff --git a/lwip.spec b/lwip.spec index 64a01d004c9610240e5d75a0a2280f9dd09c3a39..51d33c26409d26f9af164e41083acbfaffb50109 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: 67 +Release: 68 License: BSD URL: http://savannah.nongnu.org/projects/lwip/ Source0: http://download.savannah.nongnu.org/releases/lwip/%{name}-%{version}.zip @@ -192,6 +192,7 @@ Patch9175: 0176-fix-no-ack-response-when-lcoal-only-receive-but-not-.patch Patch9176: 0001-bug-free-sock-when-func-goto-out.patch Patch9177: 0177-pingpong-fix-spelling-error.patch Patch9178: 0178-add-recv_block-in-lwip_sock.patch +Patch9179: 0179-add-debug-cnt-about-tcp.patch BuildRequires: gcc-c++ dos2unix dpdk-devel @@ -221,6 +222,9 @@ cd %{_builddir}/%{name}-%{version}/src %{_libdir}/liblwip.a %changelog +* Fri Jan 10 2025 hankangkang - 2.2.0-68 +- dfx: add debug cnt about tcp + * Tue Dec 10 2024 jiangheng - 2.2.0-67 - add recv_block in lwip_sock