From 81612f267642ab611e83bd0863035346bd888720 Mon Sep 17 00:00:00 2001 From: fengbojiang Date: Thu, 28 Jan 2021 22:50:22 +0800 Subject: [PATCH] Fix some issues of ff msg. --- lib/ff_dpdk_if.c | 30 +++++++++++++++++++++++------- tools/compat/ff_ipc.c | 7 +++++++ tools/compat/sysctl.c | 16 +++------------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/lib/ff_dpdk_if.c b/lib/ff_dpdk_if.c index 7664adf85..ad8c91837 100644 --- a/lib/ff_dpdk_if.c +++ b/lib/ff_dpdk_if.c @@ -1600,17 +1600,33 @@ handle_msg(struct ff_msg *msg, uint16_t proc_id) handle_default_msg(msg); break; } - rte_ring_enqueue(msg_ring[proc_id].ring[msg->msg_type], msg); + if (rte_ring_enqueue(msg_ring[proc_id].ring[msg->msg_type], msg) < 0) { + if (msg->original_buf) { + rte_free(msg->buf_addr); + msg->buf_addr = msg->original_buf; + msg->buf_len = msg->original_buf_len; + msg->original_buf = NULL; + } + + rte_mempool_put(message_pool, msg); + } } static inline int -process_msg_ring(uint16_t proc_id) +process_msg_ring(uint16_t proc_id, struct rte_mbuf **pkts_burst) { - void *msg; - int ret = rte_ring_dequeue(msg_ring[proc_id].ring[0], &msg); + /* read msg from ring buf and to process */ + uint16_t nb_rb; + int i; - if (unlikely(ret == 0)) { - handle_msg((struct ff_msg *)msg, proc_id); + nb_rb = rte_ring_dequeue_burst(msg_ring[proc_id].ring[0], + (void **)pkts_burst, MAX_PKT_BURST, NULL); + + if (likely(nb_rb == 0)) + return 0; + + for (i = 0; i < nb_rb; ++i) { + handle_msg((struct ff_msg *)pkts_burst[i], proc_id); } return 0; @@ -1902,7 +1918,7 @@ main_loop(void *arg) } } - process_msg_ring(qconf->proc_id); + process_msg_ring(qconf->proc_id, pkts_burst); div_tsc = rte_rdtsc(); diff --git a/tools/compat/ff_ipc.c b/tools/compat/ff_ipc.c index 879e385d2..1d6a27676 100644 --- a/tools/compat/ff_ipc.c +++ b/tools/compat/ff_ipc.c @@ -114,6 +114,13 @@ ff_ipc_msg_free(struct ff_msg *msg) return -1; } + if (msg->original_buf) { + rte_free(msg->buf_addr); + msg->buf_addr = msg->original_buf; + msg->buf_len = msg->original_buf_len; + msg->original_buf = NULL; + } + rte_mempool_put(message_pool, msg); return 0; diff --git a/tools/compat/sysctl.c b/tools/compat/sysctl.c index 7e8c645fe..96320b8cd 100644 --- a/tools/compat/sysctl.c +++ b/tools/compat/sysctl.c @@ -30,16 +30,6 @@ #include "ff_ipc.h" -#define FREE_FF_MSG(m) do { \ - if (m->original_buf) { \ - rte_free(m->buf_addr); \ - m->buf_addr = m->original_buf; \ - m->buf_len = m->original_buf_len; \ - m->original_buf = NULL; \ - } \ - ff_ipc_msg_free(m); \ - } while (0); - int sysctl(int *name, unsigned namelen, void *old, size_t *oldlenp, const void *new, size_t newlen) @@ -64,7 +54,7 @@ sysctl(int *name, unsigned namelen, void *old, oldlen = *oldlenp; } - total_len = namelen + oldlen + newlen; + total_len = namelen * sizeof(int) + sizeof(size_t) + oldlen + newlen; if (total_len > msg->buf_len) { extra_buf = rte_malloc(NULL, total_len, 0); if (extra_buf == NULL) { @@ -123,7 +113,7 @@ sysctl(int *name, unsigned namelen, void *old, do { if (retmsg != NULL) { - FREE_FF_MSG(retmsg) + ff_ipc_msg_free(retmsg); } ret = ff_ipc_recv(&retmsg, msg->msg_type); if (ret < 0) { @@ -147,7 +137,7 @@ sysctl(int *name, unsigned namelen, void *old, } error: - FREE_FF_MSG(msg) + ff_ipc_msg_free(msg); return ret; }