Skip to content

Commit

Permalink
samples/bpf: Fix possible hang in xdpsock with multiple threads
Browse files Browse the repository at this point in the history
Fix a possible hang in xdpsock that can occur when using multiple
threads. In this case, one or more of the threads might get stuck in
the while-loop in tx_only after the user has signaled the main thread
to stop execution. In this case, no more Tx packets will be sent, so a
thread might get stuck in the aforementioned while-loop. Fix this by
introducing a test inside the while-loop to check if the benchmark has
been terminated. If so, return from the function.

Fixes: cd9e72b ("samples/bpf: xdpsock: Add option to specify batch size")
Signed-off-by: Magnus Karlsson <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
magnus-karlsson authored and borkmann committed Dec 10, 2020
1 parent 41003dd commit 092fde0
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions samples/bpf/xdpsock_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,8 @@ static void tx_only(struct xsk_socket_info *xsk, u32 *frame_nb, int batch_size)
while (xsk_ring_prod__reserve(&xsk->tx, batch_size, &idx) <
batch_size) {
complete_tx_only(xsk, batch_size);
if (benchmark_done)
return;
}

for (i = 0; i < batch_size; i++) {
Expand Down

0 comments on commit 092fde0

Please sign in to comment.