From 053852d2ba1956cad6fbf627133678277e76db3e Mon Sep 17 00:00:00 2001 From: kircher Date: Sat, 11 Mar 2023 19:04:09 +0800 Subject: [PATCH] sync when send ring full whether dynamic alloc mbuf is configurable reduce cpu usage when send ring full (cherry picked from commit c9081578ec83717fa883026f571c87d5c0d538d0) --- 0197-fix-private-data-offset-error.patch | 53 +++++ 0198-fix-do_close-core-dump.patch | 25 +++ 0199-remove-rxtx-driver-cache.patch | 195 ++++++++++++++++++ 0200-send-ring-size-is-configure.patch | 150 ++++++++++++++ ...return-1-errno-EAGAIN-when-ring-full.patch | 47 +++++ ...ull-whether-dynamic-alloc-mbuf-is-co.patch | 190 +++++++++++++++++ gazelle.spec | 16 +- 7 files changed, 675 insertions(+), 1 deletion(-) create mode 100644 0197-fix-private-data-offset-error.patch create mode 100644 0198-fix-do_close-core-dump.patch create mode 100644 0199-remove-rxtx-driver-cache.patch create mode 100644 0200-send-ring-size-is-configure.patch create mode 100644 0201-send-should-return-1-errno-EAGAIN-when-ring-full.patch create mode 100644 0202-when-send-ring-full-whether-dynamic-alloc-mbuf-is-co.patch diff --git a/0197-fix-private-data-offset-error.patch b/0197-fix-private-data-offset-error.patch new file mode 100644 index 0000000..4a13d59 --- /dev/null +++ b/0197-fix-private-data-offset-error.patch @@ -0,0 +1,53 @@ +From 0db52001b7e08a243c450ec1c73d4317dc9881b8 Mon Sep 17 00:00:00 2001 +From: wu-changsheng +Date: Sat, 4 Mar 2023 16:03:56 +0800 +Subject: [PATCH] fix private data offset error + +--- + src/common/dpdk_common.h | 2 +- + src/lstack/core/lstack_stack_stat.c | 2 +- + src/ltran/ltran_forward.c | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h +index 4053a2c..1305819 100644 +--- a/src/common/dpdk_common.h ++++ b/src/common/dpdk_common.h +@@ -33,7 +33,7 @@ struct pbuf; + #define LATENCY_OFFSET 96 + static __rte_always_inline uint64_t *mbuf_to_private(struct rte_mbuf *mbuf) + { +- return (uint64_t *)((uint8_t *)(mbuf) - sizeof(struct rte_mbuf) - LATENCY_OFFSET); ++ return (uint64_t *)((uint8_t *)(mbuf) + sizeof(struct rte_mbuf) + LATENCY_OFFSET); + } + static __rte_always_inline struct rte_mbuf *pbuf_to_mbuf(struct pbuf *p) + { +diff --git a/src/lstack/core/lstack_stack_stat.c b/src/lstack/core/lstack_stack_stat.c +index 7243e82..75322d5 100644 +--- a/src/lstack/core/lstack_stack_stat.c ++++ b/src/lstack/core/lstack_stack_stat.c +@@ -50,7 +50,7 @@ uint64_t get_current_time(void) + void calculate_lstack_latency(struct gazelle_stack_latency *stack_latency, const struct pbuf *pbuf, + enum GAZELLE_LATENCY_TYPE type) + { +- const uint64_t *priv = (uint64_t *)((uint8_t *)(pbuf) - LATENCY_OFFSET); ++ const uint64_t *priv = (uint64_t *)((uint8_t *)(pbuf) + LATENCY_OFFSET); + if (*priv != ~(*(priv + 1)) || *priv < stack_latency->start_time) { + return; + } +diff --git a/src/ltran/ltran_forward.c b/src/ltran/ltran_forward.c +index b73c983..4d9c1bb 100644 +--- a/src/ltran/ltran_forward.c ++++ b/src/ltran/ltran_forward.c +@@ -53,7 +53,7 @@ static void calculate_ltran_latency(struct gazelle_stack *stack, const struct rt + uint64_t latency; + uint64_t *priv = NULL; + +- priv = (uint64_t *)RTE_PTR_ADD(mbuf, sizeof(struct rte_mbuf)); ++ priv = (uint64_t *)RTE_PTR_ADD(mbuf, sizeof(struct rte_mbuf) + LATENCY_OFFSET); + // priv--time stamp priv+1 --- vaild check + if (*priv != ~(*(priv + 1))) { + return; +-- +2.33.0 + diff --git a/0198-fix-do_close-core-dump.patch b/0198-fix-do_close-core-dump.patch new file mode 100644 index 0000000..44cd4ef --- /dev/null +++ b/0198-fix-do_close-core-dump.patch @@ -0,0 +1,25 @@ +From 545685aed712e781a25ccbc7aeab85ba5d53da9e Mon Sep 17 00:00:00 2001 +From: compile_success <980965867@qq.com> +Date: Tue, 7 Mar 2023 08:37:22 +0000 +Subject: [PATCH] fix do_close core dump + +--- + src/lstack/api/lstack_wrap.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c +index 77d2442..f438529 100644 +--- a/src/lstack/api/lstack_wrap.c ++++ b/src/lstack/api/lstack_wrap.c +@@ -440,7 +440,7 @@ static inline ssize_t do_sendmsg(int32_t s, const struct msghdr *message, int32_ + static inline int32_t do_close(int32_t s) + { + struct lwip_sock *sock = get_socket_by_fd(s); +- if (sock && sock->wakeup && sock->wakeup->epollfd == s) { ++ if (likely(posix_api->ues_posix == 0) && sock && sock->wakeup && sock->wakeup->epollfd == s) { + return lstack_epoll_close(s); + } + +-- +2.33.0 + diff --git a/0199-remove-rxtx-driver-cache.patch b/0199-remove-rxtx-driver-cache.patch new file mode 100644 index 0000000..1632ad9 --- /dev/null +++ b/0199-remove-rxtx-driver-cache.patch @@ -0,0 +1,195 @@ +From dea4fbb8a7a21877c21ec50573427dd202309973 Mon Sep 17 00:00:00 2001 +From: jiangheng12 +Date: Fri, 10 Mar 2023 10:05:40 +0800 +Subject: [PATCH] remove rxtx driver cache + +--- + src/lstack/core/lstack_lwip.c | 8 +--- + src/lstack/core/lstack_protocol_stack.c | 44 ---------------------- + src/lstack/include/lstack_protocol_stack.h | 14 ------- + src/lstack/netif/lstack_ethdev.c | 23 ++++------- + src/lstack/netif/lstack_vdev.c | 9 ++++- + 5 files changed, 16 insertions(+), 82 deletions(-) + +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index f23419d..51cc9d1 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -215,14 +215,8 @@ void gazelle_free_pbuf(struct pbuf *pbuf) + } + + struct rte_mbuf *mbuf = pbuf_to_mbuf(pbuf); +- struct protocol_stack *stack = get_protocol_stack(); + +- if (STACK_FREE_INDEX(stack->free_end + 1) != STACK_FREE_INDEX(stack->free_start)) { +- stack->free_pkts[STACK_FREE_INDEX(stack->free_end)] = mbuf; +- stack->free_end++; +- } else { +- rte_pktmbuf_free_seg(mbuf); +- } ++ rte_pktmbuf_free_seg(mbuf); + } + + int32_t gazelle_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, uint32_t num) +diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c +index 93204d1..e13034f 100644 +--- a/src/lstack/core/lstack_protocol_stack.c ++++ b/src/lstack/core/lstack_protocol_stack.c +@@ -411,46 +411,6 @@ static void wakeup_kernel_event(struct protocol_stack *stack) + stack->kernel_event_num = 0; + } + +-void stack_send_pkts(struct protocol_stack *stack) +-{ +- uint32_t send_num = stack->send_end - stack->send_start; +- +- if (send_num == 0) { +- return; +- } +- +- uint32_t start = stack->send_start & STACK_SEND_MASK; +- uint32_t end = stack->send_end & STACK_SEND_MASK; +- uint32_t sent_pkts = 0; +- +- if (start < end) { +- sent_pkts = stack->dev_ops.tx_xmit(stack, &stack->send_pkts[start], send_num); +- } else { +- send_num = STACK_SEND_MAX - start; +- sent_pkts = stack->dev_ops.tx_xmit(stack, &stack->send_pkts[start], send_num); +- if (sent_pkts == send_num) { +- sent_pkts += stack->dev_ops.tx_xmit(stack, stack->send_pkts, end); +- } +- } +- +- stack->send_start += sent_pkts; +- stack->stats.tx += sent_pkts; +-} +- +-void stack_free_recv_pkts(struct protocol_stack *stack, uint32_t free_num) +-{ +- if (stack->free_end == stack->free_start) { +- return; +- } +- +- uint32_t num = 0; +- for (uint32_t i = stack->free_start; num < free_num && i < stack->free_end; i++) { +- rte_pktmbuf_free_seg(stack->free_pkts[STACK_FREE_INDEX(i)]); +- num++; +- } +- stack->free_start += num; +-} +- + static void* gazelle_stack_thread(void *arg) + { + uint16_t queue_id = *(uint16_t *)arg; +@@ -483,10 +443,6 @@ static void* gazelle_stack_thread(void *arg) + + send_stack_list(stack, send_connect_number); + +- stack_send_pkts(stack); +- +- stack_free_recv_pkts(stack, nic_read_number); +- + gazelle_eth_dev_poll(stack, use_ltran_flag, nic_read_number); + + read_recv_list(stack, read_connect_number); +diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h +index b093362..1fac220 100644 +--- a/src/lstack/include/lstack_protocol_stack.h ++++ b/src/lstack/include/lstack_protocol_stack.h +@@ -31,14 +31,6 @@ + #define SOCK_SEND_REPLENISH_THRES (16) + #define WAKEUP_MAX_NUM (32) + +-#define STACK_SEND_MAX 2048 +-#define STACK_SEND_MASK (STACK_SEND_MAX - 1) +-#define STACK_SEND_INDEX(index) ((index) & STACK_SEND_MASK) +- +-#define STACK_FREE_MAX 4096 +-#define STACK_FREE_MASK (STACK_FREE_MAX - 1) +-#define STACK_FREE_INDEX(index) ((index) & STACK_FREE_MASK) +- + struct rte_mempool; + struct rte_ring; + struct rte_mbuf; +@@ -74,12 +66,6 @@ struct protocol_stack { + uint32_t rx_ring_used; + uint32_t tx_ring_used; + +- uint32_t free_start; +- uint32_t free_end; +- struct rte_mbuf *free_pkts[STACK_FREE_MAX]; +- uint32_t send_start; +- uint32_t send_end; +- struct rte_mbuf *send_pkts[STACK_SEND_MAX]; + struct rte_mbuf *pkts[RTE_TEST_RX_DESC_DEFAULT]; + struct list_node recv_list; + struct list_node send_list; +diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c +index db353f9..1441f64 100644 +--- a/src/lstack/netif/lstack_ethdev.c ++++ b/src/lstack/netif/lstack_ethdev.c +@@ -147,21 +147,6 @@ int32_t gazelle_eth_dev_poll(struct protocol_stack *stack, bool use_ltran_flag, + return nr_pkts; + } + +-static void add_send_pkt(struct protocol_stack *stack, struct rte_mbuf *mbuf) +-{ +- do { +- if (STACK_SEND_INDEX(stack->send_end + 1) != STACK_SEND_INDEX(stack->send_start)) { +- stack->send_pkts[STACK_SEND_INDEX(stack->send_end)] = mbuf; +- stack->send_end++; +- return; +- } +- +- stack_send_pkts(stack); +- +- stack->stats.send_pkts_fail++; +- } while (1); +-} +- + static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) + { + struct protocol_stack *stack = get_protocol_stack(); +@@ -212,7 +197,13 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) + pbuf = pbuf->next; + } + +- add_send_pkt(stack, first_mbuf); ++ uint32_t sent_pkts = stack->dev_ops.tx_xmit(stack, &first_mbuf, 1); ++ stack->stats.tx += sent_pkts; ++ if (sent_pkts < 1) { ++ stack->stats.tx_drop++; ++ rte_pktmbuf_free(first_mbuf); ++ return ERR_MEM; ++ } + + return ERR_OK; + } +diff --git a/src/lstack/netif/lstack_vdev.c b/src/lstack/netif/lstack_vdev.c +index 801edf8..3d1204e 100644 +--- a/src/lstack/netif/lstack_vdev.c ++++ b/src/lstack/netif/lstack_vdev.c +@@ -129,11 +129,18 @@ static uint32_t ltran_tx_xmit(struct protocol_stack *stack, struct rte_mbuf **pk + + static uint32_t vdev_tx_xmit(struct protocol_stack *stack, struct rte_mbuf **pkts, uint32_t nr_pkts) + { ++ uint32_t sent_pkts = 0; ++ + if (rte_eth_tx_prepare(stack->port_id, stack->queue_id, pkts, nr_pkts) != nr_pkts) { + stack->stats.tx_prepare_fail++; ++ LSTACK_LOG(INFO, LSTACK, "rte_eth_tx_prepare failed\n"); + } + +- return rte_eth_tx_burst(stack->port_id, stack->queue_id, pkts, nr_pkts); ++ do { ++ sent_pkts += rte_eth_tx_burst(stack->port_id, stack->queue_id, &pkts[sent_pkts], nr_pkts - sent_pkts); ++ } while (sent_pkts < nr_pkts); ++ ++ return sent_pkts; + } + + int32_t vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple) +-- +2.33.0 + diff --git a/0200-send-ring-size-is-configure.patch b/0200-send-ring-size-is-configure.patch new file mode 100644 index 0000000..ef16a0f --- /dev/null +++ b/0200-send-ring-size-is-configure.patch @@ -0,0 +1,150 @@ +From 153b54c15eb7c70b137f3df7a37a59d423691ae4 Mon Sep 17 00:00:00 2001 +From: jiangheng12 +Date: Fri, 10 Mar 2023 11:29:02 +0800 +Subject: [PATCH] send ring size is configure + +--- + src/lstack/core/lstack_cfg.c | 9 ++++++++- + src/lstack/core/lstack_lwip.c | 15 +++++++++------ + src/lstack/include/lstack_cfg.h | 1 + + src/lstack/include/lstack_protocol_stack.h | 2 +- + src/lstack/lstack.conf | 2 ++ + 5 files changed, 21 insertions(+), 8 deletions(-) + +diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c +index e1ea38d..1f7dda1 100644 +--- a/src/lstack/core/lstack_cfg.c ++++ b/src/lstack/core/lstack_cfg.c +@@ -64,6 +64,7 @@ static int32_t parse_rpc_number(void); + static int32_t parse_nic_read_number(void); + static int32_t parse_tcp_conn_count(void); + static int32_t parse_mbuf_count_per_conn(void); ++static int32_t parse_send_ring_size(void); + + static inline int32_t parse_int(void *arg, char * arg_string, int32_t default_val, + int32_t min_val, int32_t max_val) +@@ -110,6 +111,7 @@ static struct config_vector_t g_config_tbl[] = { + { "read_connect_number", parse_read_connect_number }, + { "rpc_number", parse_rpc_number }, + { "nic_read_number", parse_nic_read_number }, ++ { "send_ring_size", parse_send_ring_size }, + { NULL, NULL } + }; + +@@ -713,6 +715,12 @@ static int32_t parse_tcp_conn_count(void) + return parse_int(&g_config_params.tcp_conn_count, "tcp_conn_count", TCP_CONN_COUNT, 1, TCP_CONN_COUNT); + } + ++static int32_t parse_send_ring_size(void) ++{ ++ /* send ring size default value is 32 */ ++ return parse_int(&g_config_params.send_ring_size, "send_ring_size", 32, 1, SOCK_SEND_RING_SIZE_MAX); ++} ++ + static int32_t parse_mbuf_count_per_conn(void) + { + return parse_int(&g_config_params.mbuf_count_per_conn, "mbuf_count_per_conn", +@@ -748,7 +756,6 @@ static int32_t parse_listen_shadow(void) + return parse_int(&g_config_params.listen_shadow, "listen_shadow", 0, 0, 1); + } + +- + static int32_t parse_app_bind_numa(void) + { + return parse_int(&g_config_params.app_bind_numa, "app_bind_numa", 1, 0, 1); +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index 51cc9d1..baaa18b 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -33,6 +33,7 @@ + #include "lstack_thread_rpc.h" + #include "dpdk_common.h" + #include "lstack_lwip.h" ++#include "lstack_cfg.h" + + static void free_ring_pbuf(struct rte_ring *ring) + { +@@ -127,7 +128,7 @@ static struct pbuf *init_mbuf_to_pbuf(struct rte_mbuf *mbuf, pbuf_layer layer, u + /* true: need replenish again */ + static bool replenish_send_idlembuf(struct protocol_stack *stack, struct rte_ring *ring) + { +- void *pbuf[SOCK_SEND_RING_SIZE]; ++ void *pbuf[SOCK_SEND_RING_SIZE_MAX]; + + uint32_t replenish_cnt = gazelle_ring_free_count(ring); + if (replenish_cnt == 0) { +@@ -172,7 +173,9 @@ void gazelle_init_sock(int32_t fd) + return; + } + +- sock->send_ring = create_ring("sock_send", SOCK_SEND_RING_SIZE, RING_F_SP_ENQ | RING_F_SC_DEQ, ++ sock->send_ring = create_ring("sock_send", ++ get_global_cfg_params()->send_ring_size, ++ RING_F_SP_ENQ | RING_F_SC_DEQ, + atomic_fetch_add(&name_tick, 1)); + if (sock->send_ring == NULL) { + LSTACK_LOG(ERR, LSTACK, "sock_send create failed. errno: %d.\n", rte_errno); +@@ -416,7 +419,7 @@ static inline ssize_t app_direct_attach(struct protocol_stack *stack, struct pbu + + static inline ssize_t app_buff_write(struct lwip_sock *sock, void *buf, size_t len, uint32_t write_num) + { +- struct pbuf *pbufs[SOCK_SEND_RING_SIZE]; ++ struct pbuf *pbufs[SOCK_SEND_RING_SIZE_MAX]; + + (void)gazelle_ring_read(sock->send_ring, (void **)pbufs, write_num); + +@@ -517,10 +520,10 @@ ssize_t write_stack_data(struct lwip_sock *sock, const void *buf, size_t len) + struct pbuf *last_pbuf = gazelle_ring_readlast(sock->send_ring); + if (last_pbuf) { + send_len += app_direct_attach(stack, last_pbuf, (char *)buf + send_len, len - send_len, write_num); +- gazelle_ring_lastover(last_pbuf); +- if (wakeup) { ++ gazelle_ring_lastover(last_pbuf); ++ if (wakeup) { + wakeup->stat.app_write_cnt += write_num; +- } ++ } + } else { + (void)rpc_call_replenish(stack, sock); + if (wakeup) { +diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h +index 0b89e28..6af081d 100644 +--- a/src/lstack/include/lstack_cfg.h ++++ b/src/lstack/include/lstack_cfg.h +@@ -89,6 +89,7 @@ struct cfg_params { + char **dpdk_argv; + struct secondary_attach_arg sec_attach_arg; + char unix_socket_filename[NAME_MAX]; ++ uint16_t send_ring_size; + }; + + struct cfg_params *get_global_cfg_params(void); +diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h +index 1fac220..795db39 100644 +--- a/src/lstack/include/lstack_protocol_stack.h ++++ b/src/lstack/include/lstack_protocol_stack.h +@@ -27,7 +27,7 @@ + + #define SOCK_RECV_RING_SIZE (128) + #define SOCK_RECV_FREE_THRES (32) +-#define SOCK_SEND_RING_SIZE (32) ++#define SOCK_SEND_RING_SIZE_MAX (2048) + #define SOCK_SEND_REPLENISH_THRES (16) + #define WAKEUP_MAX_NUM (32) + +diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf +index b7a4ede..fb68c32 100644 +--- a/src/lstack/lstack.conf ++++ b/src/lstack/lstack.conf +@@ -20,6 +20,8 @@ listen_shadow=0 + tcp_conn_count = 1500 + mbuf_count_per_conn = 170 + ++# send ring size, default is 32, max is 2048 ++send_ring_size = 256 + + #protocol stack thread per loop params + #send connect to nic +-- +2.33.0 + diff --git a/0201-send-should-return-1-errno-EAGAIN-when-ring-full.patch b/0201-send-should-return-1-errno-EAGAIN-when-ring-full.patch new file mode 100644 index 0000000..eec5d87 --- /dev/null +++ b/0201-send-should-return-1-errno-EAGAIN-when-ring-full.patch @@ -0,0 +1,47 @@ +From 97641d17e754daf5bc2745ebd2d311b5dbf89d05 Mon Sep 17 00:00:00 2001 +From: jiangheng12 +Date: Fri, 10 Mar 2023 17:39:03 +0800 +Subject: [PATCH] send should return -1, errno EAGAIN when ring full + +--- + src/lstack/core/lstack_lwip.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index baaa18b..b9f97e0 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -507,7 +507,8 @@ ssize_t write_stack_data(struct lwip_sock *sock, const void *buf, size_t len) + if (sock->remain_len) { + send_len = merge_data_lastpbuf(sock, (char *)buf, len); + if (send_len >= len) { +- return len; ++ send_len = len; ++ goto END; + } + } + +@@ -531,7 +532,7 @@ ssize_t write_stack_data(struct lwip_sock *sock, const void *buf, size_t len) + } + } + sock->remain_len = 0; +- return send_len; ++ goto END; + } + + /* send_ring have idle */ +@@ -545,6 +546,11 @@ ssize_t write_stack_data(struct lwip_sock *sock, const void *buf, size_t len) + del_data_out_event(sock); + } + ++END: ++ if (send_len == 0) { ++ errno = EAGAIN; ++ return -1; ++ } + return send_len; + } + +-- +2.33.0 + diff --git a/0202-when-send-ring-full-whether-dynamic-alloc-mbuf-is-co.patch b/0202-when-send-ring-full-whether-dynamic-alloc-mbuf-is-co.patch new file mode 100644 index 0000000..a78dc83 --- /dev/null +++ b/0202-when-send-ring-full-whether-dynamic-alloc-mbuf-is-co.patch @@ -0,0 +1,190 @@ +From b72fcd6421f599422d76a969795a7f523c405684 Mon Sep 17 00:00:00 2001 +From: jiangheng12 +Date: Fri, 10 Mar 2023 19:54:47 +0800 +Subject: [PATCH] when send ring full whether dynamic alloc mbuf is + configurable reduce cpu usage when send ring full + +--- + src/common/gazelle_opt.h | 3 +++ + src/lstack/core/lstack_cfg.c | 7 +++++ + src/lstack/core/lstack_lwip.c | 46 +++++++++++++++++++++++++++++---- + src/lstack/include/lstack_cfg.h | 1 + + src/lstack/lstack.conf | 4 +++ + 5 files changed, 56 insertions(+), 5 deletions(-) + +diff --git a/src/common/gazelle_opt.h b/src/common/gazelle_opt.h +index 76b89ce..745fdd8 100644 +--- a/src/common/gazelle_opt.h ++++ b/src/common/gazelle_opt.h +@@ -87,4 +87,7 @@ + #define GAZELLE_RUN_DIR "/var/run/gazelle/" + #define GAZELLE_FILE_PERMISSION 0700 + ++#define SEND_TIME_WAIT_NS 20000 ++#define SECOND_NSECOND 1000000000 ++ + #endif /* _GAZELLE_OPT_H_ */ +diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c +index 1f7dda1..86d0f14 100644 +--- a/src/lstack/core/lstack_cfg.c ++++ b/src/lstack/core/lstack_cfg.c +@@ -65,6 +65,7 @@ static int32_t parse_nic_read_number(void); + static int32_t parse_tcp_conn_count(void); + static int32_t parse_mbuf_count_per_conn(void); + static int32_t parse_send_ring_size(void); ++static int32_t parse_expand_send_ring(void); + + static inline int32_t parse_int(void *arg, char * arg_string, int32_t default_val, + int32_t min_val, int32_t max_val) +@@ -112,6 +113,7 @@ static struct config_vector_t g_config_tbl[] = { + { "rpc_number", parse_rpc_number }, + { "nic_read_number", parse_nic_read_number }, + { "send_ring_size", parse_send_ring_size }, ++ { "expand_send_ring", parse_expand_send_ring }, + { NULL, NULL } + }; + +@@ -721,6 +723,11 @@ static int32_t parse_send_ring_size(void) + return parse_int(&g_config_params.send_ring_size, "send_ring_size", 32, 1, SOCK_SEND_RING_SIZE_MAX); + } + ++static int32_t parse_expand_send_ring(void) ++{ ++ return parse_int(&g_config_params.expand_send_ring, "expand_send_ring", 0, 0, 1); ++} ++ + static int32_t parse_mbuf_count_per_conn(void) + { + return parse_int(&g_config_params.mbuf_count_per_conn, "mbuf_count_per_conn", +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index b9f97e0..dcd7e05 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -126,10 +126,12 @@ static struct pbuf *init_mbuf_to_pbuf(struct rte_mbuf *mbuf, pbuf_layer layer, u + } + + /* true: need replenish again */ +-static bool replenish_send_idlembuf(struct protocol_stack *stack, struct rte_ring *ring) ++static bool replenish_send_idlembuf(struct protocol_stack *stack, struct lwip_sock *sock) + { + void *pbuf[SOCK_SEND_RING_SIZE_MAX]; + ++ struct rte_ring *ring = sock->send_ring; ++ + uint32_t replenish_cnt = gazelle_ring_free_count(ring); + if (replenish_cnt == 0) { + return false; +@@ -152,6 +154,10 @@ static bool replenish_send_idlembuf(struct protocol_stack *stack, struct rte_rin + pbuf_free(pbuf[i]); + } + ++ if (!get_global_cfg_params()->expand_send_ring) { ++ sem_post(&sock->snd_ring_sem); ++ } ++ + return false; + } + +@@ -181,7 +187,7 @@ void gazelle_init_sock(int32_t fd) + LSTACK_LOG(ERR, LSTACK, "sock_send create failed. errno: %d.\n", rte_errno); + return; + } +- (void)replenish_send_idlembuf(stack, sock->send_ring); ++ (void)replenish_send_idlembuf(stack, sock); + + sock->stack = stack; + sock->stack->conn_num++; +@@ -490,6 +496,17 @@ static inline size_t merge_data_lastpbuf(struct lwip_sock *sock, void *buf, size + return send_len; + } + ++int sem_timedwait_nsecs(sem_t *sem) ++{ ++ struct timespec ts; ++ clock_gettime(CLOCK_REALTIME, &ts); ++ long long wait_nsec = ts.tv_nsec + SEND_TIME_WAIT_NS; ++ ts.tv_nsec = wait_nsec % SECOND_NSECOND; ++ long add = wait_nsec / SECOND_NSECOND; ++ ts.tv_sec += add; ++ return sem_timedwait(sem, &ts); ++} ++ + ssize_t write_stack_data(struct lwip_sock *sock, const void *buf, size_t len) + { + if (sock->errevent > 0) { +@@ -518,6 +535,16 @@ ssize_t write_stack_data(struct lwip_sock *sock, const void *buf, size_t len) + + /* send_ring is full, data attach last pbuf */ + if (write_avail == 0) { ++ if (!get_global_cfg_params()->expand_send_ring) { ++ sem_timedwait_nsecs(&sock->snd_ring_sem); ++ if (likely(sock->send_ring != NULL)) { ++ write_avail = gazelle_ring_readable_count(sock->send_ring); ++ } ++ goto END; ++ } ++ if (unlikely(sock->send_ring == NULL)) { ++ goto END; ++ } + struct pbuf *last_pbuf = gazelle_ring_readlast(sock->send_ring); + if (last_pbuf) { + send_len += app_direct_attach(stack, last_pbuf, (char *)buf + send_len, len - send_len, write_num); +@@ -536,8 +563,17 @@ ssize_t write_stack_data(struct lwip_sock *sock, const void *buf, size_t len) + } + + /* send_ring have idle */ +- send_len += (write_num <= write_avail) ? app_buff_write(sock, (char *)buf + send_len, len - send_len, write_num) : +- app_direct_write(stack, sock, (char *)buf + send_len, len - send_len, write_num); ++ if (get_global_cfg_params()->expand_send_ring) { ++ send_len += (write_num <= write_avail) ? app_buff_write(sock, (char *)buf + send_len, len - send_len, write_num) : ++ app_direct_write(stack, sock, (char *)buf + send_len, len - send_len, write_num); ++ } else { ++ if (write_num > write_avail) { ++ write_num = write_avail; ++ len = write_num * MBUF_MAX_DATA_LEN; ++ } ++ send_len += app_buff_write(sock, (char *)buf + send_len, len - send_len, write_num); ++ } ++ + if (wakeup) { + wakeup->stat.app_write_cnt += write_num; + } +@@ -558,7 +594,7 @@ static inline bool replenish_send_ring(struct protocol_stack *stack, struct lwip + { + bool replenish_again = false; + +- replenish_again = replenish_send_idlembuf(stack, sock->send_ring); ++ replenish_again = replenish_send_idlembuf(stack, sock); + + if ((sock->epoll_events & EPOLLOUT) && NETCONN_IS_OUTIDLE(sock)) { + add_sock_event(sock, EPOLLOUT); +diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h +index 6af081d..5f16c19 100644 +--- a/src/lstack/include/lstack_cfg.h ++++ b/src/lstack/include/lstack_cfg.h +@@ -90,6 +90,7 @@ struct cfg_params { + struct secondary_attach_arg sec_attach_arg; + char unix_socket_filename[NAME_MAX]; + uint16_t send_ring_size; ++ bool expand_send_ring; + }; + + struct cfg_params *get_global_cfg_params(void); +diff --git a/src/lstack/lstack.conf b/src/lstack/lstack.conf +index fb68c32..a4571ff 100644 +--- a/src/lstack/lstack.conf ++++ b/src/lstack/lstack.conf +@@ -22,6 +22,10 @@ mbuf_count_per_conn = 170 + + # send ring size, default is 32, max is 2048 + send_ring_size = 256 ++ ++# 0: when send ring full, send return ++# 1: when send ring full, alloc mbuf from mempool to send data ++expand_send_ring = 0 + + #protocol stack thread per loop params + #send connect to nic +-- +2.33.0 + diff --git a/gazelle.spec b/gazelle.spec index 89b9b04..bd69ecc 100644 --- a/gazelle.spec +++ b/gazelle.spec @@ -2,7 +2,7 @@ Name: gazelle Version: 1.0.1 -Release: 50 +Release: 51 Summary: gazelle is a high performance user-mode stack License: MulanPSL-2.0 URL: https://gitee.com/openeuler/gazelle @@ -211,6 +211,12 @@ Patch9193: 0193-check-and-fix-wakeup_list-when-null-appears.patch Patch9194: 0194-eneble-TSO-and-fix-TSO-mbuf-pktlen-error.patch Patch9195: 0195-adapt-unsupport-sock-optname.patch Patch9196: 0196-reduce-duplicate-code-in-lstack_cfg.c.patch +Patch9197: 0197-fix-private-data-offset-error.patch +Patch9198: 0198-fix-do_close-core-dump.patch +Patch9199: 0199-remove-rxtx-driver-cache.patch +Patch9200: 0200-send-ring-size-is-configure.patch +Patch9201: 0201-send-should-return-1-errno-EAGAIN-when-ring-full.patch +Patch9202: 0202-when-send-ring-full-whether-dynamic-alloc-mbuf-is-co.patch %description %{name} is a high performance user-mode stack. @@ -251,6 +257,14 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b %config(noreplace) %{conf_path}/ltran.conf %changelog +* Sat Mar 11 2023 kircher - 1.0.1-51 +- when send ring full whether dynamic alloc mbuf is configurable reduce cpu usage when send ring full +- send should return -1, errno EAGAIN when ring full +- send ring size is configure +- remove rxtx driver cache +- fix do_close core dump +- fix private data offset error + * Mon Feb 27 2023 wu-changsheng - 1.0.1-50 - reduce duplicate code in lstack_cfg.c - adapt unsupport sock optname