Skip to content

Commit f40bdbb

Browse files
bganneayourtch
authored andcommitted
af_xdp: make sure all packets are transmitted
AF_XDP socket will only tx enqueued packets up to a max batch size so we need to retry until everything has been sent. Type: fix Change-Id: Ia487ab63d3e85a478471cd1d679c5fb471804ba3 Signed-off-by: Benoît Ganne <[email protected]>
1 parent f441b5d commit f40bdbb

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/plugins/af_xdp/input.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*------------------------------------------------------------------
1616
*/
1717

18-
#include <poll.h>
1918
#include <vlib/vlib.h>
2019
#include <vlib/unix/unix.h>
2120
#include <vlib/pci/pci.h>
@@ -89,8 +88,7 @@ af_xdp_device_input_refill_db (vlib_main_t * vm,
8988

9089
if (clib_spinlock_trylock_if_init (&rxq->syscall_lock))
9190
{
92-
struct pollfd fd = { .fd = rxq->xsk_fd, .events = POLLIN | POLLOUT };
93-
int ret = poll (&fd, 1, 0);
91+
int ret = recvmsg (rxq->xsk_fd, 0, MSG_DONTWAIT);
9492
clib_spinlock_unlock_if_init (&rxq->syscall_lock);
9593
if (PREDICT_FALSE (ret < 0))
9694
{

src/plugins/af_xdp/output.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <poll.h>
21
#include <string.h>
32
#include <vlib/vlib.h>
43
#include <vlib/unix/unix.h>
@@ -101,11 +100,19 @@ af_xdp_device_output_tx_db (vlib_main_t * vm,
101100

102101
if (xsk_ring_prod__needs_wakeup (&txq->tx))
103102
{
104-
struct pollfd fd = { .fd = txq->xsk_fd, .events = POLLIN | POLLOUT };
105-
int ret = poll (&fd, 1, 0);
103+
const struct msghdr msg = {};
104+
int ret;
105+
/* On tx, xsk socket will only tx up to TX_BATCH_SIZE, as defined in
106+
* kernel net/xdp/xsk.c. Unfortunately we do not know how much this is,
107+
* our only option is to retry until everything is sent... */
108+
do
109+
{
110+
ret = sendmsg (txq->xsk_fd, &msg, MSG_DONTWAIT);
111+
}
112+
while (ret < 0 && EAGAIN == errno);
106113
if (PREDICT_FALSE (ret < 0))
107114
{
108-
/* something bad is happening */
115+
/* not EAGAIN: something bad is happening */
109116
vlib_error_count (vm, node->node_index,
110117
AF_XDP_TX_ERROR_SYSCALL_FAILURES, 1);
111118
af_xdp_device_error (ad, "tx poll() failed");

0 commit comments

Comments
 (0)