Skip to content

Commit 016b16d

Browse files
author
Herton R. Krzesinski
committed
Merge: selftests: net: update udpgso_bench test
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2028 JIRA: https://issues.redhat.com/browse/RHEL-221 Some fixes for net udpgso_bench selftest Signed-off-by: Hangbin Liu <haliu@redhat.com> Approved-by: Florian Westphal <fwestpha@redhat.com> Approved-by: John B. Wyatt IV <jwyatt@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents 5d6d2be + c9bd4a5 commit 016b16d

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

tools/testing/selftests/net/udpgso_bench.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ readonly GREEN='\033[0;92m'
77
readonly YELLOW='\033[0;33m'
88
readonly RED='\033[0;31m'
99
readonly NC='\033[0m' # No Color
10+
readonly TESTPORT=8000
1011

1112
readonly KSFT_PASS=0
1213
readonly KSFT_FAIL=1
@@ -56,11 +57,26 @@ trap wake_children EXIT
5657

5758
run_one() {
5859
local -r args=$@
60+
local nr_socks=0
61+
local i=0
62+
local -r timeout=10
63+
64+
./udpgso_bench_rx -p "$TESTPORT" &
65+
./udpgso_bench_rx -p "$TESTPORT" -t &
66+
67+
# Wait for the above test program to get ready to receive connections.
68+
while [ "$i" -lt "$timeout" ]; do
69+
nr_socks="$(ss -lnHi | grep -c "\*:${TESTPORT}")"
70+
[ "$nr_socks" -eq 2 ] && break
71+
i=$((i + 1))
72+
sleep 1
73+
done
74+
if [ "$nr_socks" -ne 2 ]; then
75+
echo "timed out while waiting for udpgso_bench_rx"
76+
exit 1
77+
fi
5978

60-
./udpgso_bench_rx &
61-
./udpgso_bench_rx -t &
62-
63-
./udpgso_bench_tx ${args}
79+
./udpgso_bench_tx -p "$TESTPORT" ${args}
6480
}
6581

6682
run_in_netns() {

tools/testing/selftests/net/udpgso_bench_rx.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static int recv_msg(int fd, char *buf, int len, int *gso_size)
250250
static void do_flush_udp(int fd)
251251
{
252252
static char rbuf[ETH_MAX_MTU];
253-
int ret, len, gso_size, budget = 256;
253+
int ret, len, gso_size = 0, budget = 256;
254254

255255
len = cfg_read_all ? sizeof(rbuf) : 0;
256256
while (budget--) {
@@ -336,6 +336,8 @@ static void parse_opts(int argc, char **argv)
336336
cfg_verify = true;
337337
cfg_read_all = true;
338338
break;
339+
default:
340+
exit(1);
339341
}
340342
}
341343

tools/testing/selftests/net/udpgso_bench_tx.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static int cfg_payload_len = (1472 * 42);
6262
static int cfg_port = 8000;
6363
static int cfg_runtime_ms = -1;
6464
static bool cfg_poll;
65+
static int cfg_poll_loop_timeout_ms = 2000;
6566
static bool cfg_segment;
6667
static bool cfg_sendmmsg;
6768
static bool cfg_tcp;
@@ -235,16 +236,17 @@ static void flush_errqueue_recv(int fd)
235236
}
236237
}
237238

238-
static void flush_errqueue(int fd, const bool do_poll)
239+
static void flush_errqueue(int fd, const bool do_poll,
240+
unsigned long poll_timeout, const bool poll_err)
239241
{
240242
if (do_poll) {
241243
struct pollfd fds = {0};
242244
int ret;
243245

244246
fds.fd = fd;
245-
ret = poll(&fds, 1, 500);
247+
ret = poll(&fds, 1, poll_timeout);
246248
if (ret == 0) {
247-
if (cfg_verbose)
249+
if ((cfg_verbose) && (poll_err))
248250
fprintf(stderr, "poll timeout\n");
249251
} else if (ret < 0) {
250252
error(1, errno, "poll");
@@ -254,6 +256,20 @@ static void flush_errqueue(int fd, const bool do_poll)
254256
flush_errqueue_recv(fd);
255257
}
256258

259+
static void flush_errqueue_retry(int fd, unsigned long num_sends)
260+
{
261+
unsigned long tnow, tstop;
262+
bool first_try = true;
263+
264+
tnow = gettimeofday_ms();
265+
tstop = tnow + cfg_poll_loop_timeout_ms;
266+
do {
267+
flush_errqueue(fd, true, tstop - tnow, first_try);
268+
first_try = false;
269+
tnow = gettimeofday_ms();
270+
} while ((stat_zcopies != num_sends) && (tnow < tstop));
271+
}
272+
257273
static int send_tcp(int fd, char *data)
258274
{
259275
int ret, done = 0, count = 0;
@@ -413,7 +429,8 @@ static int send_udp_segment(int fd, char *data)
413429

414430
static void usage(const char *filepath)
415431
{
416-
error(1, 0, "Usage: %s [-46acmHPtTuvz] [-C cpu] [-D dst ip] [-l secs] [-M messagenr] [-p port] [-s sendsize] [-S gsosize]",
432+
error(1, 0, "Usage: %s [-46acmHPtTuvz] [-C cpu] [-D dst ip] [-l secs] "
433+
"[-L secs] [-M messagenr] [-p port] [-s sendsize] [-S gsosize]",
417434
filepath);
418435
}
419436

@@ -423,7 +440,7 @@ static void parse_opts(int argc, char **argv)
423440
int max_len, hdrlen;
424441
int c;
425442

426-
while ((c = getopt(argc, argv, "46acC:D:Hl:mM:p:s:PS:tTuvz")) != -1) {
443+
while ((c = getopt(argc, argv, "46acC:D:Hl:L:mM:p:s:PS:tTuvz")) != -1) {
427444
switch (c) {
428445
case '4':
429446
if (cfg_family != PF_UNSPEC)
@@ -452,6 +469,9 @@ static void parse_opts(int argc, char **argv)
452469
case 'l':
453470
cfg_runtime_ms = strtoul(optarg, NULL, 10) * 1000;
454471
break;
472+
case 'L':
473+
cfg_poll_loop_timeout_ms = strtoul(optarg, NULL, 10) * 1000;
474+
break;
455475
case 'm':
456476
cfg_sendmmsg = true;
457477
break;
@@ -490,6 +510,8 @@ static void parse_opts(int argc, char **argv)
490510
case 'z':
491511
cfg_zerocopy = true;
492512
break;
513+
default:
514+
exit(1);
493515
}
494516
}
495517

@@ -677,7 +699,7 @@ int main(int argc, char **argv)
677699
num_sends += send_udp(fd, buf[i]);
678700
num_msgs++;
679701
if ((cfg_zerocopy && ((num_msgs & 0xF) == 0)) || cfg_tx_tstamp)
680-
flush_errqueue(fd, cfg_poll);
702+
flush_errqueue(fd, cfg_poll, 500, true);
681703

682704
if (cfg_msg_nr && num_msgs >= cfg_msg_nr)
683705
break;
@@ -696,7 +718,7 @@ int main(int argc, char **argv)
696718
} while (!interrupted && (cfg_runtime_ms == -1 || tnow < tstop));
697719

698720
if (cfg_zerocopy || cfg_tx_tstamp)
699-
flush_errqueue(fd, true);
721+
flush_errqueue_retry(fd, num_sends);
700722

701723
if (close(fd))
702724
error(1, errno, "close");

0 commit comments

Comments
 (0)