!233 [sync] PR-230: free-recv-pkts-bluks

From: @openeuler-sync-bot 
Reviewed-by: @wu-changsheng 
Signed-off-by: @wu-changsheng
This commit is contained in:
openeuler-ci-bot 2022-12-22 15:52:13 +00:00 committed by Gitee
commit 3573cfbb25
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 303 additions and 1 deletions

View File

@ -0,0 +1,95 @@
From aab7dc09d29f1281d8843c67d56f9f69540f5801 Mon Sep 17 00:00:00 2001
From: wu-changsheng <wuchangsheng2@huawei.com>
Date: Thu, 22 Dec 2022 23:10:19 +0800
Subject: [PATCH 1/4] add-rcv-nxt-dfx-info
---
src/common/gazelle_dfx_msg.h | 1 +
src/lstack/core/lstack_lwip.c | 3 ++-
src/lstack/include/lstack_dpdk.h | 2 --
src/ltran/ltran_dfx.c | 9 +++++----
4 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/common/gazelle_dfx_msg.h b/src/common/gazelle_dfx_msg.h
index 9225b53..674f2d7 100644
--- a/src/common/gazelle_dfx_msg.h
+++ b/src/common/gazelle_dfx_msg.h
@@ -164,6 +164,7 @@ struct gazelle_stat_lstack_conn_info {
uint32_t snd_buf;
uint32_t lastack;
uint32_t snd_nxt;
+ uint32_t rcv_nxt;
int32_t fd;
uint32_t events;
uint32_t epoll_events;
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index 018b6c6..bb6fe44 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -755,7 +755,7 @@ static void put_pbufs_into_recv_ring(struct lwip_sock *sock, struct pbuf *pbufs[
last_pbuf->last = new_pbuf->last;
gazelle_ring_lastover(last_pbuf);
- if (last_pbuf->tot_len > SOCK_READ_MAXLEN) {
+ if (last_pbuf->tot_len > TCP_WND) {
sock->read_wait = true;
}
}
@@ -1111,6 +1111,7 @@ static void copy_pcb_to_conn(struct gazelle_stat_lstack_conn_info *conn, const s
conn->snd_buf = pcb->snd_buf;
conn->lastack = pcb->lastack;
conn->snd_nxt = pcb->snd_nxt;
+ conn->rcv_nxt = pcb->rcv_nxt;
if (netconn != NULL && netconn->recvmbox != NULL) {
conn->recv_cnt = rte_ring_count(netconn->recvmbox->ring);
diff --git a/src/lstack/include/lstack_dpdk.h b/src/lstack/include/lstack_dpdk.h
index ac068b8..c3bc527 100644
--- a/src/lstack/include/lstack_dpdk.h
+++ b/src/lstack/include/lstack_dpdk.h
@@ -24,8 +24,6 @@
#define MAX_PACKET_SZ 2048
-#define SOCK_READ_MAXLEN 0x200000
-
#define RING_SIZE(x) ((x) - 1)
#define MBUF_SZ (MAX_PACKET_SZ + RTE_PKTMBUF_HEADROOM)
diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c
index 7dda51c..53d1b47 100644
--- a/src/ltran/ltran_dfx.c
+++ b/src/ltran/ltran_dfx.c
@@ -880,7 +880,8 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_
do {
printf("\n------ stack tid: %6u ------time=%lu\n", stat->tid, time.tv_sec * 1000000 + time.tv_usec);
printf("No. Proto lwip_recv recv_ring in_send send_ring cwn rcv_wnd snd_wnd snd_buf snd_nxt"
- " lastack events epoll_ev evlist fd Local Address Foreign Address State\n");
+ " lastack rcv_nxt events epoll_ev evlist fd Local Address "
+ "Foreign Address State\n");
uint32_t unread_pkts = 0;
uint32_t unsend_pkts = 0;
for (i = 0; i < conn->conn_num && i < GAZELLE_LSTACK_MAX_CONN; i++) {
@@ -889,16 +890,16 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_
rip.s_addr = conn_info->rip;
lip.s_addr = conn_info->lip;
if ((conn_info->state == GAZELLE_ACTIVE_LIST) || (conn_info->state == GAZELLE_TIME_WAIT_LIST)) {
- printf("%-6utcp %-10u%-10u%-8u%-10u%-9d%-9d%-10d%-10d%-15u%-15u%-10x%-10x%-7d%-7d"
+ printf("%-6utcp %-10u%-10u%-8u%-10u%-9d%-9d%-10d%-10d%-15u%-15u%-15u%-10x%-10x%-7d%-7d"
"%s:%hu %s:%hu %s\n", i, conn_info->recv_cnt, conn_info->recv_ring_cnt, conn_info->in_send,
conn_info->send_ring_cnt, conn_info->cwn, conn_info->rcv_wnd, conn_info->snd_wnd,
- conn_info->snd_buf, conn_info->snd_nxt, conn_info->lastack, conn_info->events,
+ conn_info->snd_buf, conn_info->snd_nxt, conn_info->lastack, conn_info->rcv_nxt, conn_info->events,
conn_info->epoll_events, conn_info->eventlist, conn_info->fd,
inet_ntop(AF_INET, &lip, str_ip, sizeof(str_ip)), conn_info->l_port,
inet_ntop(AF_INET, &rip, str_rip, sizeof(str_rip)), conn_info->r_port,
tcp_state_to_str(conn_info->tcp_sub_state));
} else if (conn_info->state == GAZELLE_LISTEN_LIST) {
- printf("%-6utcp %-57u%-7d%s:%hu 0.0.0.0:* LISTEN\n", i, conn_info->recv_cnt,
+ printf("%-6utcp %-147u%-7d%s:%hu 0.0.0.0:* LISTEN\n", i, conn_info->recv_cnt,
conn_info->fd, inet_ntop(AF_INET, &lip, str_ip, sizeof(str_ip)), conn_info->l_port);
} else {
printf("Got unknow tcp conn::%s:%5hu, state:%u\n",
--
2.23.0

View File

@ -0,0 +1,44 @@
From d6428e24a2024f8583d0747abb832fe73393f82b Mon Sep 17 00:00:00 2001
From: wu-changsheng <wuchangsheng2@huawei.com>
Date: Thu, 22 Dec 2022 23:15:38 +0800
Subject: [PATCH 2/4] mbuf-private-data-size-align-cache-line
---
src/common/dpdk_common.h | 4 ++--
src/lstack/core/lstack_dpdk.c | 5 +++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h
index e4a447a..08ce4a1 100644
--- a/src/common/dpdk_common.h
+++ b/src/common/dpdk_common.h
@@ -25,8 +25,8 @@
#define PTR_TO_PRIVATE(mbuf) RTE_PTR_ADD(mbuf, sizeof(struct rte_mbuf))
/* Layout:
- * | rte_mbuf | gazelle_prive | custom_free_function | tcp_seg | payload |
- * | 128 | 16 | 56 | 32 |
+ * | rte_mbuf | gazelle_prive | pbuf_custom | tcp_seg | payload |
+ * | 128 | 16 | 64 | 32 |
* rte_prefetch0 in lwip project,tcp_out.c,tcp_output_segment use constants
**/
struct pbuf;
diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c
index 76ebe96..de87d48 100644
--- a/src/lstack/core/lstack_dpdk.c
+++ b/src/lstack/core/lstack_dpdk.c
@@ -144,8 +144,9 @@ static struct rte_mempool *create_pktmbuf_mempool(const char *name, uint32_t nb_
}
/* time stamp before pbuf_custom as priv_data */
- pool = rte_pktmbuf_pool_create(pool_name, nb_mbuf, mbuf_cache_size,
- sizeof(struct tcp_seg) + sizeof(struct pbuf_custom) + GAZELLE_MBUFF_PRIV_SIZE, MBUF_SZ, rte_socket_id());
+ uint16_t private_size = sizeof(struct tcp_seg) + sizeof(struct pbuf_custom) + GAZELLE_MBUFF_PRIV_SIZE;
+ private_size = RTE_ALIGN(private_size, RTE_CACHE_LINE_SIZE);
+ pool = rte_pktmbuf_pool_create(pool_name, nb_mbuf, mbuf_cache_size, private_size, MBUF_SZ, rte_socket_id());
if (pool == NULL) {
LSTACK_LOG(ERR, LSTACK, "cannot create %s pool rte_err=%d\n", pool_name, rte_errno);
}
--
2.23.0

View File

@ -0,0 +1,59 @@
From 24754f47cefc0284aeea0d122698789c51ff050d Mon Sep 17 00:00:00 2001
From: wu-changsheng <wuchangsheng2@huawei.com>
Date: Thu, 22 Dec 2022 23:19:09 +0800
Subject: [PATCH 3/4] fix-send-pkts-bluk-err
---
src/lstack/include/lstack_protocol_stack.h | 2 ++
src/lstack/netif/lstack_ethdev.c | 16 ++++++----------
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/src/lstack/include/lstack_protocol_stack.h b/src/lstack/include/lstack_protocol_stack.h
index c706afc..de3d312 100644
--- a/src/lstack/include/lstack_protocol_stack.h
+++ b/src/lstack/include/lstack_protocol_stack.h
@@ -29,8 +29,10 @@
#define SOCK_SEND_RING_SIZE (32)
#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)
struct rte_mempool;
struct rte_ring;
diff --git a/src/lstack/netif/lstack_ethdev.c b/src/lstack/netif/lstack_ethdev.c
index 5729ebf..4426b1a 100644
--- a/src/lstack/netif/lstack_ethdev.c
+++ b/src/lstack/netif/lstack_ethdev.c
@@ -149,20 +149,16 @@ int32_t gazelle_eth_dev_poll(struct protocol_stack *stack, bool use_ltran_flag,
static void add_send_pkt(struct protocol_stack *stack, struct rte_mbuf *mbuf)
{
- if (stack->send_end + 1 != stack->send_start) {
- stack->send_pkts[stack->send_end & STACK_SEND_MASK] = mbuf;
- stack->send_end++;
- return;
- }
-
- stack->stats.send_pkts_fail++;
do {
- stack_send_pkts(stack);
- if (stack->send_end + 1 != stack->send_start) {
- stack->send_pkts[stack->send_end & STACK_SEND_MASK] = mbuf;
+ 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);
}
--
2.23.0

View File

@ -0,0 +1,94 @@
From 7edbb73f77c64706e9bf35ccfc8454f706c3b553 Mon Sep 17 00:00:00 2001
From: wu-changsheng <wuchangsheng2@huawei.com>
Date: Thu, 22 Dec 2022 23:26:54 +0800
Subject: [PATCH 4/4] free-recv-pkts-bluks
---
src/lstack/core/lstack_lwip.c | 10 ++++++++--
src/lstack/core/lstack_protocol_stack.c | 16 ++++++++++++++++
src/lstack/include/lstack_protocol_stack.h | 7 +++++++
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index bb6fe44..31f87cf 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -221,8 +221,14 @@ void gazelle_free_pbuf(struct pbuf *pbuf)
}
struct rte_mbuf *mbuf = pbuf_to_mbuf(pbuf);
- pbuf->next = NULL;
- rte_pktmbuf_free_seg(mbuf);
+ 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);
+ }
}
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 16b124e..7b53b91 100644
--- a/src/lstack/core/lstack_protocol_stack.c
+++ b/src/lstack/core/lstack_protocol_stack.c
@@ -439,6 +439,20 @@ void stack_send_pkts(struct protocol_stack *stack)
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;
@@ -469,6 +483,8 @@ static void* gazelle_stack_thread(void *arg)
for (;;) {
poll_rpc_msg(stack, rpc_number);
+ 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 de3d312..4fe06cd 100644
--- a/src/lstack/include/lstack_protocol_stack.h
+++ b/src/lstack/include/lstack_protocol_stack.h
@@ -34,6 +34,10 @@
#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;
@@ -69,6 +73,9 @@ 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];
--
2.23.0

View File

@ -2,7 +2,7 @@
Name: gazelle
Version: 1.0.1
Release: 39
Release: 40
Summary: gazelle is a high performance user-mode stack
License: MulanPSL-2.0
URL: https://gitee.com/openeuler/gazelle
@ -184,6 +184,10 @@ Patch9166: 0166-optimite-send-pkts-dul-index.patch
Patch9167: 0167-expand-data-recv-buff.patch
Patch9168: 0168-dfx-add-mempool-count-info.patch
Patch9169: 0169--write-support-without-epoll-poll.patch
Patch9170: 0170-add-rcv-nxt-dfx-info.patch
Patch9171: 0171-mbuf-private-data-size-align-cache-line.patch
Patch9172: 0172-fix-send-pkts-bluk-err.patch
Patch9173: 0173-free-recv-pkts-bluks.patch
%description
%{name} is a high performance user-mode stack.
@ -224,6 +228,12 @@ install -Dpm 0640 %{_builddir}/%{name}-%{version}/src/ltran/ltran.conf %{b
%config(noreplace) %{conf_path}/ltran.conf
%changelog
* Thu Dec 22 2022 wuchangsheng <wuchangsheng2@huawei.com> - 1.0.1-40
- add dfx rcv_nxt info
mbuf private cache line align
send pkts index bug fix
free recv pkts in main loop
* Wed Dec 21 2022 wuchangsheng <wuchangsheng2@huawei.com> - 1.0.1-39
- add mempool dfx info
write support without epoll/poll