Fix some issues of ff msg.

This commit is contained in:
fengbojiang 2021-01-28 22:50:22 +08:00
parent a7607b336a
commit 527e34d48a
3 changed files with 33 additions and 20 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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;
}