From e864f391bc48bd2473ac66356fe08370385f7b40 Mon Sep 17 00:00:00 2001
From: yangchen <yangchen145@huawei.com>
Date: Mon, 17 Jun 2024 16:49:55 +0800
Subject: [PATCH] lwip_sock: add sock_time_stamp

---
 src/api/api_msg.c      |  2 ++
 src/include/lwipsock.h | 11 +++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/api/api_msg.c b/src/api/api_msg.c
index 9da4869..0d33c67 100644
--- a/src/api/api_msg.c
+++ b/src/api/api_msg.c
@@ -331,6 +331,7 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
     SYS_ARCH_INC(conn->recv_avail, len);
 #endif /* LWIP_SO_RCVBUF */
 #if GAZELLE_UDP_ENABLE
+    time_stamp_record(conn->callback_arg.socket, p);
     do_lwip_add_recvlist(conn->callback_arg.socket);
 #endif /* GAZELLE_UDP_ENABLE */
     /* Register event with callback */
@@ -393,6 +394,7 @@ recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
     SYS_ARCH_INC(conn->recv_avail, len);
 #endif /* LWIP_SO_RCVBUF */
 #if GAZELLE_ENABLE
+    time_stamp_record(conn->callback_arg.socket, p);
     do_lwip_add_recvlist(conn->callback_arg.socket);
 #endif
     /* Register event with callback */
diff --git a/src/include/lwipsock.h b/src/include/lwipsock.h
index dc2e9d3..d700cee 100644
--- a/src/include/lwipsock.h
+++ b/src/include/lwipsock.h
@@ -76,6 +76,11 @@ struct same_node_ring {
     unsigned long long sndbegin;
     unsigned long long sndend;
 };
+
+struct sock_time_stamp {
+    uint64_t rpc_time_stamp;
+    uint64_t mbox_time_stamp;
+};
 #endif
 
 /** Contains all internal pointers and states used for a socket */
@@ -138,6 +143,8 @@ struct lwip_sock {
   struct same_node_ring *same_node_tx_ring;
   const struct rte_memzone *same_node_tx_ring_mz;
   uint8_t already_bind_numa;
+
+  struct sock_time_stamp stamp;
 #endif
 };
 
@@ -167,11 +174,9 @@ extern struct lwip_sock *sockets;
 extern void do_lwip_init_sock(int32_t fd);
 extern void do_lwip_clean_sock(int32_t fd);
 extern void do_lwip_connected_callback(struct netconn *conn);
-
 extern struct pbuf *do_lwip_get_from_sendring(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags);
 extern void do_lwip_get_from_sendring_over(struct lwip_sock *sock);
 extern ssize_t do_lwip_read_from_lwip(struct lwip_sock *sock, int32_t flags, u8_t apiflags);
-
 extern void do_lwip_add_recvlist(int32_t fd);
 
 extern void netif_poll(struct netif *netif);
@@ -183,6 +188,8 @@ extern err_t create_same_node_ring(struct tcp_pcb *pcb);
 extern err_t find_same_node_ring(struct tcp_pcb *pcb);
 extern void lstack_calculate_aggregate(int type, uint32_t len);
 extern void time_stamp_transfer_pbuf(struct pbuf *pbuf_old, struct pbuf *pbuf_new);
+extern void time_stamp_record(int fd, struct pbuf *pbuf);
+
 #endif /* GAZELLE_ENABLE */
 
 struct lwip_sock *get_socket(int s);
-- 
2.33.0

