hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/tools/testing/selftests/net/udpgso_bench_tx.c
....@@ -62,6 +62,7 @@
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 @@
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");
....@@ -252,6 +254,20 @@
252254 }
253255
254256 flush_errqueue_recv(fd);
257
+}
258
+
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));
255271 }
256272
257273 static int send_tcp(int fd, char *data)
....@@ -413,7 +429,8 @@
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 @@
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)
....@@ -451,6 +468,9 @@
451468 break;
452469 case 'l':
453470 cfg_runtime_ms = strtoul(optarg, NULL, 10) * 1000;
471
+ break;
472
+ case 'L':
473
+ cfg_poll_loop_timeout_ms = strtoul(optarg, NULL, 10) * 1000;
454474 break;
455475 case 'm':
456476 cfg_sendmmsg = true;
....@@ -490,6 +510,8 @@
490510 case 'z':
491511 cfg_zerocopy = true;
492512 break;
513
+ default:
514
+ exit(1);
493515 }
494516 }
495517
....@@ -677,7 +699,7 @@
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 @@
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");