Skip to content

Commit fd0815a

Browse files
tvyavahaborkmann
authored andcommitted
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: Tushar Vyavahare <tushar.vyavahare@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Magnus Karlsson <magnus.karlsson@intel.com> Link: https://lore.kernel.org/bpf/20230927135241.2287547-7-tushar.vyavahare@intel.com
1 parent 46e4378 commit fd0815a

1 file changed

Lines changed: 38 additions & 19 deletions

File tree

tools/testing/selftests/bpf/xskxceiver.c

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,13 +1194,13 @@ static int receive_pkts(struct test_spec *test)
11941194
return TEST_PASS;
11951195
}
11961196

1197-
static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeout)
1197+
static int __send_pkts(struct ifobject *ifobject, struct xsk_socket_info *xsk, bool timeout)
11981198
{
11991199
u32 i, idx = 0, valid_pkts = 0, valid_frags = 0, buffer_len;
1200-
struct pkt_stream *pkt_stream = ifobject->xsk->pkt_stream;
1201-
struct xsk_socket_info *xsk = ifobject->xsk;
1200+
struct pkt_stream *pkt_stream = xsk->pkt_stream;
12021201
struct xsk_umem_info *umem = ifobject->umem;
12031202
bool use_poll = ifobject->use_poll;
1203+
struct pollfd fds = { };
12041204
int ret;
12051205

12061206
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
12121212
return TEST_CONTINUE;
12131213
}
12141214

1215+
fds.fd = xsk_socket__fd(xsk->xsk);
1216+
fds.events = POLLOUT;
1217+
12151218
while (xsk_ring_prod__reserve(&xsk->tx, BATCH_SIZE, &idx) < BATCH_SIZE) {
12161219
if (use_poll) {
1217-
ret = poll(fds, 1, POLL_TMOUT);
1220+
ret = poll(&fds, 1, POLL_TMOUT);
12181221
if (timeout) {
12191222
if (ret < 0) {
12201223
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
12931296
xsk->outstanding_tx += valid_frags;
12941297

12951298
if (use_poll) {
1296-
ret = poll(fds, 1, POLL_TMOUT);
1299+
ret = poll(&fds, 1, POLL_TMOUT);
12971300
if (ret <= 0) {
12981301
if (ret == 0 && timeout)
12991302
return TEST_PASS;
@@ -1339,27 +1342,43 @@ static int wait_for_tx_completion(struct xsk_socket_info *xsk)
13391342
return TEST_PASS;
13401343
}
13411344

1345+
bool all_packets_sent(struct test_spec *test, unsigned long *bitmap)
1346+
{
1347+
return bitmap_full(bitmap, test->nb_sockets);
1348+
}
1349+
13421350
static int send_pkts(struct test_spec *test, struct ifobject *ifobject)
13431351
{
1344-
struct pkt_stream *pkt_stream = ifobject->xsk->pkt_stream;
13451352
bool timeout = !is_umem_valid(test->ifobj_rx);
1346-
struct pollfd fds = { };
1347-
u32 ret;
1353+
DECLARE_BITMAP(bitmap, test->nb_sockets);
1354+
u32 i, ret;
13481355

1349-
fds.fd = xsk_socket__fd(ifobject->xsk->xsk);
1350-
fds.events = POLLOUT;
1356+
while (!(all_packets_sent(test, bitmap))) {
1357+
for (i = 0; i < test->nb_sockets; i++) {
1358+
struct pkt_stream *pkt_stream;
13511359

1352-
while (pkt_stream->current_pkt_nb < pkt_stream->nb_pkts) {
1353-
ret = __send_pkts(ifobject, &fds, timeout);
1354-
if (ret == TEST_CONTINUE && !test->fail)
1355-
continue;
1356-
if ((ret || test->fail) && !timeout)
1357-
return TEST_FAILURE;
1358-
if (ret == TEST_PASS && timeout)
1359-
return ret;
1360+
pkt_stream = ifobject->xsk_arr[i].pkt_stream;
1361+
if (!pkt_stream || pkt_stream->current_pkt_nb >= pkt_stream->nb_pkts) {
1362+
__set_bit(i, bitmap);
1363+
continue;
1364+
}
1365+
ret = __send_pkts(ifobject, &ifobject->xsk_arr[i], timeout);
1366+
if (ret == TEST_CONTINUE && !test->fail)
1367+
continue;
1368+
1369+
if ((ret || test->fail) && !timeout)
1370+
return TEST_FAILURE;
1371+
1372+
if (ret == TEST_PASS && timeout)
1373+
return ret;
1374+
1375+
ret = wait_for_tx_completion(&ifobject->xsk_arr[i]);
1376+
if (ret)
1377+
return TEST_FAILURE;
1378+
}
13601379
}
13611380

1362-
return wait_for_tx_completion(ifobject->xsk);
1381+
return TEST_PASS;
13631382
}
13641383

13651384
static int get_xsk_stats(struct xsk_socket *xsk, struct xdp_statistics *stats)

0 commit comments

Comments
 (0)