Skip to content

Commit 0a9ac2e

Browse files
Paolo Abenidavem330
authored andcommitted
selftests: add GRO support to udp bench rx program
And fix a couple of buglets (port option processing, clean termination on SIGINT). This is preparatory work for GRO tests. rfc v2 -> rfc v3: - use ETH_MAX_MTU Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cf329aa commit 0a9ac2e

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

tools/testing/selftests/net/udpgso_bench_rx.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@
3131
#include <sys/wait.h>
3232
#include <unistd.h>
3333

34+
#ifndef UDP_GRO
35+
#define UDP_GRO 104
36+
#endif
37+
3438
static int cfg_port = 8000;
3539
static bool cfg_tcp;
3640
static bool cfg_verify;
41+
static bool cfg_read_all;
42+
static bool cfg_gro_segment;
3743

3844
static bool interrupted;
3945
static unsigned long packets, bytes;
@@ -63,14 +69,16 @@ static void do_poll(int fd)
6369

6470
do {
6571
ret = poll(&pfd, 1, 10);
72+
if (interrupted)
73+
break;
6674
if (ret == -1)
6775
error(1, errno, "poll");
6876
if (ret == 0)
6977
continue;
7078
if (pfd.revents != POLLIN)
7179
error(1, errno, "poll: 0x%x expected 0x%x\n",
7280
pfd.revents, POLLIN);
73-
} while (!ret && !interrupted);
81+
} while (!ret);
7482
}
7583

7684
static int do_socket(bool do_tcp)
@@ -102,6 +110,8 @@ static int do_socket(bool do_tcp)
102110
error(1, errno, "listen");
103111

104112
do_poll(accept_fd);
113+
if (interrupted)
114+
exit(0);
105115

106116
fd = accept(accept_fd, NULL, NULL);
107117
if (fd == -1)
@@ -167,18 +177,18 @@ static void do_verify_udp(const char *data, int len)
167177
/* Flush all outstanding datagrams. Verify first few bytes of each. */
168178
static void do_flush_udp(int fd)
169179
{
170-
static char rbuf[ETH_DATA_LEN];
180+
static char rbuf[ETH_MAX_MTU];
171181
int ret, len, budget = 256;
172182

173-
len = cfg_verify ? sizeof(rbuf) : 0;
183+
len = cfg_read_all ? sizeof(rbuf) : 0;
174184
while (budget--) {
175185
/* MSG_TRUNC will make return value full datagram length */
176186
ret = recv(fd, rbuf, len, MSG_TRUNC | MSG_DONTWAIT);
177187
if (ret == -1 && errno == EAGAIN)
178188
return;
179189
if (ret == -1)
180190
error(1, errno, "recv");
181-
if (len) {
191+
if (len && cfg_verify) {
182192
if (ret == 0)
183193
error(1, errno, "recv: 0 byte datagram\n");
184194

@@ -192,23 +202,30 @@ static void do_flush_udp(int fd)
192202

193203
static void usage(const char *filepath)
194204
{
195-
error(1, 0, "Usage: %s [-tv] [-p port]", filepath);
205+
error(1, 0, "Usage: %s [-Grtv] [-p port]", filepath);
196206
}
197207

198208
static void parse_opts(int argc, char **argv)
199209
{
200210
int c;
201211

202-
while ((c = getopt(argc, argv, "ptv")) != -1) {
212+
while ((c = getopt(argc, argv, "Gp:rtv")) != -1) {
203213
switch (c) {
214+
case 'G':
215+
cfg_gro_segment = true;
216+
break;
204217
case 'p':
205-
cfg_port = htons(strtoul(optarg, NULL, 0));
218+
cfg_port = strtoul(optarg, NULL, 0);
219+
break;
220+
case 'r':
221+
cfg_read_all = true;
206222
break;
207223
case 't':
208224
cfg_tcp = true;
209225
break;
210226
case 'v':
211227
cfg_verify = true;
228+
cfg_read_all = true;
212229
break;
213230
}
214231
}
@@ -227,6 +244,12 @@ static void do_recv(void)
227244

228245
fd = do_socket(cfg_tcp);
229246

247+
if (cfg_gro_segment && !cfg_tcp) {
248+
int val = 1;
249+
if (setsockopt(fd, IPPROTO_UDP, UDP_GRO, &val, sizeof(val)))
250+
error(1, errno, "setsockopt UDP_GRO");
251+
}
252+
230253
treport = gettimeofday_ms() + 1000;
231254
do {
232255
do_poll(fd);

0 commit comments

Comments
 (0)