From 70fb1797336cd761348513a18cac297c1af2d3a7 Mon Sep 17 00:00:00 2001 From: wu-changsheng Date: Sun, 18 Dec 2022 19:57:45 +0800 Subject: [PATCH] pkts-bulk-send-to-nic and rpc-dont-send (cherry picked from commit 9c0f841528cc4c493b38114cf005187e802b2ca7) --- 0163-pkts-bulk-send-to-nic.patch | 123 +++++++++++++++++++++++++++++++ 0164-rpc-dont-send.patch | 64 ++++++++++++++++ 0165-recv-pbuf-free-timely.patch | 27 +++++++ gazelle.spec | 8 +- 4 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 0163-pkts-bulk-send-to-nic.patch create mode 100644 0164-rpc-dont-send.patch create mode 100644 0165-recv-pbuf-free-timely.patch diff --git a/0163-pkts-bulk-send-to-nic.patch b/0163-pkts-bulk-send-to-nic.patch new file mode 100644 index 0000000..184357a --- /dev/null +++ b/0163-pkts-bulk-send-to-nic.patch @@ -0,0 +1,123 @@ +From dab68f20b3d6d66fe0c400db81c15cc200c22b22 Mon Sep 17 00:00:00 2001 +From: wu-changsheng +Date: Sun, 18 Dec 2022 19:22:33 +0800 +Subject: [PATCH 1/2] pkts bulk send to nic + +--- + src/lstack/core/lstack_protocol_stack.c | 19 +++++++++++++++++++ + src/lstack/include/lstack_protocol_stack.h | 3 +++ + src/lstack/netif/lstack_ethdev.c | 16 ++++++++++------ + src/lstack/netif/lstack_vdev.c | 8 +------- + 4 files changed, 33 insertions(+), 13 deletions(-) + +diff --git a/src/lstack/core/lstack_protocol_stack.c b/src/lstack/core/lstack_protocol_stack.c +index 2a866e0..870e496 100644 +--- a/src/lstack/core/lstack_protocol_stack.c ++++ b/src/lstack/core/lstack_protocol_stack.c +@@ -413,6 +413,23 @@ static void wakeup_kernel_event(struct protocol_stack *stack) + stack->kernel_event_num = 0; + } + ++static void stack_send_pkts(struct protocol_stack *stack) ++{ ++ if (stack->send_cnt == 0) { ++ return; ++ } ++ ++ uint32_t sent_pkts = stack->dev_ops.tx_xmit(stack, stack->send_pkts, stack->send_cnt); ++ if (sent_pkts < stack->send_cnt && sent_pkts != 0) { ++ for (uint32_t i = sent_pkts; i < stack->send_cnt; i++) { ++ stack->send_pkts[i - sent_pkts] = stack->send_pkts[i]; ++ } ++ } ++ ++ stack->send_cnt -= sent_pkts; ++ stack->stats.tx += sent_pkts; ++} ++ + static void* gazelle_stack_thread(void *arg) + { + uint16_t queue_id = *(uint16_t *)arg; +@@ -449,6 +466,8 @@ static void* gazelle_stack_thread(void *arg) + + send_stack_list(stack, send_connect_number); + ++ stack_send_pkts(stack); ++ + if ((wakeup_tick & 0xf) == 0) { + wakeup_kernel_event(stack); + wakeup_stack_epoll(stack, wakeup_thread_enable); +diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h +index 4cfa243..9463707 100644 +--- a/src/lstack/include/lstack_protocol_stack.h ++++ b/src/lstack/include/lstack_protocol_stack.h +@@ -29,6 +29,7 @@ + #define SOCK_SEND_RING_SIZE (32) + #define SOCK_SEND_REPLENISH_THRES (16) + #define WAKEUP_MAX_NUM (32) ++#define STACK_SEND_MAX RTE_TEST_TX_DESC_DEFAULT + + struct rte_mempool; + struct rte_ring; +@@ -65,6 +66,8 @@ struct protocol_stack { + uint32_t rx_ring_used; + uint32_t tx_ring_used; + ++ uint16_t send_cnt; ++ 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 3958e8d..d870dd3 100644 +--- a/src/lstack/netif/lstack_ethdev.c ++++ b/src/lstack/netif/lstack_ethdev.c +@@ -197,12 +197,16 @@ static err_t eth_dev_output(struct netif *netif, struct pbuf *pbuf) + pbuf = pbuf->next; + } + +- uint32_t sent_pkts = stack->dev_ops.tx_xmit(stack, &first_mbuf, 1); +- stack->stats.tx += sent_pkts; +- if (sent_pkts < 1) { +- stack->stats.tx_drop++; +- rte_pktmbuf_free(first_mbuf); +- return ERR_MEM; ++ if (stack->send_cnt + 1 < STACK_SEND_MAX) { ++ stack->send_pkts[stack->send_cnt++] = first_mbuf; ++ } else { ++ 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 f6e7a1a..801edf8 100644 +--- a/src/lstack/netif/lstack_vdev.c ++++ b/src/lstack/netif/lstack_vdev.c +@@ -129,17 +129,11 @@ 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++; + } + +- 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; ++ return rte_eth_tx_burst(stack->port_id, stack->queue_id, pkts, nr_pkts); + } + + int32_t vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple) +-- +2.23.0 + diff --git a/0164-rpc-dont-send.patch b/0164-rpc-dont-send.patch new file mode 100644 index 0000000..dcb6c45 --- /dev/null +++ b/0164-rpc-dont-send.patch @@ -0,0 +1,64 @@ +From 4b7dd71bd8ab1023b73b2c157719d6a939d75b49 Mon Sep 17 00:00:00 2001 +From: wu-changsheng +Date: Sun, 18 Dec 2022 19:36:52 +0800 +Subject: [PATCH 2/2] rpc-dont-send + +--- + src/common/dpdk_common.h | 4 +++- + src/lstack/core/lstack_lwip.c | 12 +----------- + 2 files changed, 4 insertions(+), 12 deletions(-) + +diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h +index a0c304c..63d651d 100644 +--- a/src/common/dpdk_common.h ++++ b/src/common/dpdk_common.h +@@ -25,7 +25,9 @@ + #define PTR_TO_PRIVATE(mbuf) RTE_PTR_ADD(mbuf, sizeof(struct rte_mbuf)) + + /* Layout: +- * | rte_mbuf | pbuf | custom_free_function | tcp_seg | payload | ++ * | rte_mbuf | gazelle_prive | pbuf | custom_free_function | tcp_seg | payload | ++ * rte_prefetch0 in lwip project,tcp_out.c,tcp_output_segment use constants ++ sizeof(struct rte_mbuf) + GAZELLE_MBUFF_PRIV_SIZE = 128 + 16 + **/ + struct pbuf; + static inline struct rte_mbuf *pbuf_to_mbuf(struct pbuf *p) +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index c04ed27..ae6c98d 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -573,7 +573,6 @@ static inline bool do_lwip_send(struct protocol_stack *stack, int32_t fd, struct + void stack_send(struct rpc_msg *msg) + { + int32_t fd = msg->args[MSG_ARG_0].i; +- int32_t flags = msg->args[MSG_ARG_2].i; + struct protocol_stack *stack = (struct protocol_stack *)msg->args[MSG_ARG_3].p; + + struct lwip_sock *sock = get_socket(fd); +@@ -583,22 +582,13 @@ void stack_send(struct rpc_msg *msg) + } + + __atomic_store_n(&sock->in_send, 0, __ATOMIC_RELEASE); +- rte_mb(); +- +- if (!NETCONN_IS_DATAOUT(sock) || sock->errevent > 0) { +- return; +- } +- +- bool replenish_again = do_lwip_send(stack, fd, sock, flags); + + /* have remain data or replenish again add sendlist */ +- if (NETCONN_IS_DATAOUT(sock) || replenish_again) { ++ if (sock->errevent == 0 && NETCONN_IS_DATAOUT(sock)) { + if (list_is_null(&sock->send_list)) { + list_add_node(&stack->send_list, &sock->send_list); + __atomic_store_n(&sock->in_send, 1, __ATOMIC_RELEASE); + } +- +- stack->stats.send_self_rpc++; + } + } + +-- +2.23.0 + diff --git a/0165-recv-pbuf-free-timely.patch b/0165-recv-pbuf-free-timely.patch new file mode 100644 index 0000000..73f9834 --- /dev/null +++ b/0165-recv-pbuf-free-timely.patch @@ -0,0 +1,27 @@ +From 90575a74f2a4b50ac5ab89a529c5c4426cdf507c Mon Sep 17 00:00:00 2001 +From: wu-changsheng +Date: Sun, 18 Dec 2022 20:18:53 +0800 +Subject: [PATCH] recv pbuf free timely + +--- + src/lstack/core/lstack_lwip.c | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c +index ae6c98d..0b9b684 100644 +--- a/src/lstack/core/lstack_lwip.c ++++ b/src/lstack/core/lstack_lwip.c +@@ -642,9 +642,7 @@ ssize_t read_lwip_data(struct lwip_sock *sock, int32_t flags, u8_t apiflags) + return 0; + } + +- if (gazelle_ring_readover_count(sock->recv_ring) >= SOCK_RECV_FREE_THRES) { +- free_recv_ring_readover(sock->recv_ring); +- } ++ free_recv_ring_readover(sock->recv_ring); + + uint32_t free_count = gazelle_ring_free_count(sock->recv_ring); + if (free_count == 0) { +-- +2.23.0 + diff --git a/gazelle.spec b/gazelle.spec index 5dbc356..ff13ff8 100644 --- a/gazelle.spec +++ b/gazelle.spec @@ -2,7 +2,7 @@ Name: gazelle Version: 1.0.1 -Release: 36 +Release: 37 Summary: gazelle is a high performance user-mode stack License: MulanPSL-2.0 URL: https://gitee.com/openeuler/gazelle @@ -177,6 +177,9 @@ Patch9159: 0159-stack-thread-params-default-val.patch Patch9160: 0160-optimite-net-type.patch Patch9161: 0161-app-bind-numa-when-epoll-poll-create.patch Patch9162: 0162-remove-mbuf-reserve-in-mbuf-alloc.patch +Patch9163: 0163-pkts-bulk-send-to-nic.patch +Patch9164: 0164-rpc-dont-send.patch +Patch9165: 0165-recv-pbuf-free-timely.patch %description %{name} is a high performance user-mode stack. @@ -217,6 +220,9 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b %config(noreplace) %{conf_path}/ltran.conf %changelog +* Sun Dec 18 2022 wuchangsheng - 1.0.1-37 +- pkts-bulk-send-to-nic and rpc-dont-send + * Sat Dec 17 2022 jiangheng - 1.0.1-36 - remove mbuf reserve in mbuf alloc