From b3ccf93dec7581adfcfaf99c6ea8b8478da263b1 Mon Sep 17 00:00:00 2001 From: wu-changsheng Date: Sat, 8 Oct 2022 11:10:24 +0800 Subject: [PATCH 15/21] fix lwip_send fail free pbuf miss data --- src/common/dpdk_common.h | 25 +++++++++++++++++++++++++ src/lstack/core/lstack_lwip.c | 7 ++++++- src/lstack/include/lstack_lwip.h | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/common/dpdk_common.h b/src/common/dpdk_common.h index 1c3e7e8..c2cbda7 100644 --- a/src/common/dpdk_common.h +++ b/src/common/dpdk_common.h @@ -177,6 +177,31 @@ static __rte_always_inline uint32_t gazelle_ring_sc_dequeue(struct rte_ring *r, return n; } +/* get ring obj dont dequeue */ +static __rte_always_inline uint32_t gazelle_ring_sc_peek(struct rte_ring *r, void **obj_table, uint32_t n) +{ + uint32_t prod = __atomic_load_n(&r->prod.tail, __ATOMIC_ACQUIRE); + uint32_t cons = r->cons.tail; + + uint32_t entries = prod - cons; + if (n > entries) { + n = entries; + } + if (unlikely(n == 0)) { + return 0; + } + + + __rte_ring_dequeue_elems(r, cons, obj_table, sizeof(void *), n); + + return n; +} + +static __rte_always_inline void gazelle_ring_dequeue_over(struct rte_ring *r, uint32_t n) +{ + r->cons.tail += n; +} + static __rte_always_inline uint32_t gazelle_ring_read(struct rte_ring *r, void **obj_table, uint32_t n) { uint32_t cons = __atomic_load_n(&r->cons.head, __ATOMIC_ACQUIRE); diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c index 6f08a1c..3f21a3a 100644 --- a/src/lstack/core/lstack_lwip.c +++ b/src/lstack/core/lstack_lwip.c @@ -229,7 +229,7 @@ struct pbuf *write_lwip_data(struct lwip_sock *sock, uint16_t remain_size, uint8 { struct pbuf *pbuf = NULL; - if (gazelle_ring_sc_dequeue(sock->send_ring, (void **)&pbuf, 1) != 1) { + if (gazelle_ring_sc_peek(sock->send_ring, (void **)&pbuf, 1) != 1) { *apiflags &= ~TCP_WRITE_FLAG_MORE; return NULL; } @@ -238,6 +238,11 @@ struct pbuf *write_lwip_data(struct lwip_sock *sock, uint16_t remain_size, uint8 return pbuf; } +void write_lwip_over(struct lwip_sock *sock, uint32_t n) +{ + gazelle_ring_dequeue_over(sock->send_ring, n); +} + static inline void del_data_out_event(struct lwip_sock *sock) { pthread_spin_lock(&sock->wakeup->event_list_lock); diff --git a/src/lstack/include/lstack_lwip.h b/src/lstack/include/lstack_lwip.h index c62e99d..968eff2 100644 --- a/src/lstack/include/lstack_lwip.h +++ b/src/lstack/include/lstack_lwip.h @@ -27,6 +27,7 @@ void gazelle_init_sock(int32_t fd); int32_t gazelle_socket(int domain, int type, int protocol); void gazelle_clean_sock(int32_t fd); struct pbuf *write_lwip_data(struct lwip_sock *sock, uint16_t remain_size, uint8_t *apiflags); +void write_lwip_over(struct lwip_sock *sock, uint32_t n); ssize_t write_stack_data(struct lwip_sock *sock, const void *buf, size_t len); ssize_t read_stack_data(int32_t fd, void *buf, size_t len, int32_t flags); ssize_t read_lwip_data(struct lwip_sock *sock, int32_t flags, uint8_t apiflags); -- 2.23.0