From f065e072711b0714aa49556afc88d9f1efaa405c Mon Sep 17 00:00:00 2001
From: wu-changsheng <wuchangsheng2@huawei.com>
Date: Sat, 3 Dec 2022 21:58:44 +0800
Subject: [PATCH] optimize-app-thread-write-buff-block

---
 src/core/tcp_out.c      |  2 +-
 src/include/lwip/pbuf.h |  3 +++
 src/include/lwipsock.h  | 33 +++++++++++++++++++++++----------
 3 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c
index c4584ea..a4d511e 100644
--- a/src/core/tcp_out.c
+++ b/src/core/tcp_out.c
@@ -763,7 +763,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags)
 
     pos += seglen;
 #if USE_LIBOS
-    write_lwip_over((struct lwip_sock*)arg, 1);
+    write_lwip_over((struct lwip_sock*)arg);
 #endif
   }
 
diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h
index d9d2e71..200dbf2 100644
--- a/src/include/lwip/pbuf.h
+++ b/src/include/lwip/pbuf.h
@@ -230,6 +230,9 @@ struct pbuf {
   u64_t l4_len:8;
   u16_t header_off;
   u8_t rexmit;
+  u8_t in_write;
+  u8_t head;
+  struct pbuf *last;
 #endif /* USE_LIBOS CHECKSUM_OFFLOAD_SWITCH */
 };
 
diff --git a/src/include/lwipsock.h b/src/include/lwipsock.h
index 9fa4c57..4c578b3 100644
--- a/src/include/lwipsock.h
+++ b/src/include/lwipsock.h
@@ -94,17 +94,30 @@ struct lwip_sock {
 #endif
 
 #if USE_LIBOS
-  struct pbuf *send_lastdata;
-  uint16_t send_datalen;
-  volatile uint32_t events __rte_cache_aligned; /* available events */
-  struct pbuf *recv_lastdata __rte_cache_aligned; /* unread data in one pbuf */
-  struct list_node recv_list __rte_cache_aligned;
-  struct list_node event_list __rte_cache_aligned;
-  struct list_node send_list __rte_cache_aligned;
-  uint32_t in_send __rte_cache_aligned; /* avoid sock too much send rpc msg*/
+  char pad0 __rte_cache_aligned;
+  /* app thread use */
+  struct pbuf *recv_lastdata; /* unread data in one pbuf */
+  uint16_t remain_len;
   uint32_t epoll_events; /* registered events, EPOLLONESHOT write frequently */
-  char pad __rte_cache_aligned;
+  volatile uint32_t events; /* available events */
+  struct list_node event_list;
+
+  char pad1 __rte_cache_aligned;
+  /* app and stack thread all use */
+  uint32_t in_send; /* avoid sock too much send rpc msg*/
+  pthread_spinlock_t sock_lock;
+
+  char pad2 __rte_cache_aligned;
+  /* stack thread all use */
+  struct list_node recv_list;
+  struct list_node send_list;
+  struct pbuf *send_lastdata;
+  struct pbuf *send_pre_del;
+  uint64_t recv_all;
+  uint64_t send_all;
 
+  char pad3 __rte_cache_aligned;
+  /* nerver change */
   struct wakeup_poll *wakeup;
   epoll_data_t ep_data;
   struct lwip_sock *listen_next; /* listenfd list */
@@ -132,7 +145,7 @@ extern ssize_t read_lwip_data(struct lwip_sock *sock, int32_t flags, u8_t apifla
 extern struct pbuf *write_lwip_data(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags);
 extern void gazelle_init_sock(int32_t fd);
 extern void gazelle_clean_sock(int32_t fd);
-extern void write_lwip_over(struct lwip_sock *sock, uint32_t n);
+extern void write_lwip_over(struct lwip_sock *sock);
 #endif /* USE_LIBOS */
 
 struct lwip_sock *get_socket(int s);
-- 
2.23.0

