Commit fd0815ae authored by Tushar Vyavahare's avatar Tushar Vyavahare Committed by Daniel Borkmann

selftests/xsk: Iterate over all the sockets in the send pkts function

Update send_pkts() to handle multiple sockets for sending packets.
Multiple TX sockets are utilized alternately based on the batch size for
improve packet transmission.
Signed-off-by: default avatarTushar Vyavahare <tushar.vyavahare@intel.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarMagnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/bpf/20230927135241.2287547-7-tushar.vyavahare@intel.com
parent 46e43786
...@@ -1194,13 +1194,13 @@ static int receive_pkts(struct test_spec *test) ...@@ -1194,13 +1194,13 @@ static int receive_pkts(struct test_spec *test)
return TEST_PASS; return TEST_PASS;
} }
static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeout) static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk, bool timeout)
{ {
u32 i, idx = 0, valid_pkts = 0, valid_frags = 0, buffer_len; u32 i, idx = 0, valid_pkts = 0, valid_frags = 0, buffer_len;
struct pkt_stream *pkt_stream = ifobject->xsk->pkt_stream; struct pkt_stream *pkt_stream = xsk->pkt_stream;
struct xsk_socket_info *xsk = ifobject->xsk;
struct xsk_umem_info *umem = ifobject->umem; struct xsk_umem_info *umem = ifobject->umem;
bool use_poll = ifobject->use_poll; bool use_poll = ifobject->use_poll;
struct pollfd fds = { };
int ret; int ret;
buffer_len = pkt_get_buffer_len(umem, pkt_stream->max_pkt_len); buffer_len = pkt_get_buffer_len(umem, pkt_stream->max_pkt_len);
...@@ -1212,9 +1212,12 @@ static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeo ...@@ -1212,9 +1212,12 @@ static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeo
return TEST_CONTINUE; return TEST_CONTINUE;
} }
fds.fd = xsk_socket__fd(xsk->xsk);
fds.events = POLLOUT;
while (xsk_ring_prod__reserve(&xsk->tx, BATCH_SIZE, &idx) < BATCH_SIZE) { while (xsk_ring_prod__reserve(&xsk->tx, BATCH_SIZE, &idx) < BATCH_SIZE) {
if (use_poll) { if (use_poll) {
ret = poll(fds, 1, POLL_TMOUT); ret = poll(&fds, 1, POLL_TMOUT);
if (timeout) { if (timeout) {
if (ret < 0) { if (ret < 0) {
ksft_print_msg("ERROR: [%s] Poll error %d\n", ksft_print_msg("ERROR: [%s] Poll error %d\n",
...@@ -1293,7 +1296,7 @@ static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeo ...@@ -1293,7 +1296,7 @@ static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeo
xsk->outstanding_tx += valid_frags; xsk->outstanding_tx += valid_frags;
if (use_poll) { if (use_poll) {
ret = poll(fds, 1, POLL_TMOUT); ret = poll(&fds, 1, POLL_TMOUT);
if (ret <= 0) { if (ret <= 0) {
if (ret == 0 && timeout) if (ret == 0 && timeout)
return TEST_PASS; return TEST_PASS;
...@@ -1339,27 +1342,43 @@ static int wait_for_tx_completion(struct xsk_socket_info *xsk) ...@@ -1339,27 +1342,43 @@ static int wait_for_tx_completion(struct xsk_socket_info *xsk)
return TEST_PASS; return TEST_PASS;
} }
bool all_packets_sent(struct test_spec *test, unsigned long *bitmap)
{
return bitmap_full(bitmap, test->nb_sockets);
}
static int send_pkts(struct test_spec *test, struct ifobject *ifobject) static int send_pkts(struct test_spec *test, struct ifobject *ifobject)
{ {
struct pkt_stream *pkt_stream = ifobject->xsk->pkt_stream;
bool timeout = !is_umem_valid(test->ifobj_rx); bool timeout = !is_umem_valid(test->ifobj_rx);
struct pollfd fds = { }; DECLARE_BITMAP(bitmap, test->nb_sockets);
u32 ret; u32 i, ret;
fds.fd = xsk_socket__fd(ifobject->xsk->xsk); while (!(all_packets_sent(test, bitmap))) {
fds.events = POLLOUT; for (i = 0; i < test->nb_sockets; i++) {
struct pkt_stream *pkt_stream;
while (pkt_stream->current_pkt_nb < pkt_stream->nb_pkts) { pkt_stream = ifobject->xsk_arr[i].pkt_stream;
ret = __send_pkts(ifobject, &fds, timeout); if (!pkt_stream || pkt_stream->current_pkt_nb >= pkt_stream->nb_pkts) {
__set_bit(i, bitmap);
continue;
}
ret = __send_pkts(ifobject, &ifobject->xsk_arr[i], timeout);
if (ret == TEST_CONTINUE && !test->fail) if (ret == TEST_CONTINUE && !test->fail)
continue; continue;
if ((ret || test->fail) && !timeout) if ((ret || test->fail) && !timeout)
return TEST_FAILURE; return TEST_FAILURE;
if (ret == TEST_PASS && timeout) if (ret == TEST_PASS && timeout)
return ret; return ret;
ret = wait_for_tx_completion(&ifobject->xsk_arr[i]);
if (ret)
return TEST_FAILURE;
}
} }
return wait_for_tx_completion(ifobject->xsk); return TEST_PASS;
} }
static int get_xsk_stats(struct xsk_socket *xsk, struct xdp_statistics *stats) static int get_xsk_stats(struct xsk_socket *xsk, struct xdp_statistics *stats)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment