Skip to contentSkip to conversation

selftests: udp gso with corking

RFC PATCH In review Willem de Bruijn 1 participant 2 messages Apr 17, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 10/11 selftests: udp gso with corking

From: Willem de Bruijn <[email protected]>

Corked sockets take a different path to construct a udp datagram than the lockless fast path. Test this alternate path.

Segmentation offload requires checksum offload, which is not supported with corked sockets. This test fails after commit d749c9cbffd6 ("ipv4: no CHECKSUM_PARTIAL on MSG_MORE corked sockets") and commit 682b1a9d3f96 ("ipv6: no CHECKSUM_PARTIAL on MSG_MORE corked sockets").

---
 tools/testing/selftests/net/udpgso.c  | 42 ++++++++++++++++++++-------
 tools/testing/selftests/net/udpgso.sh |  8 +++++
 2 files changed, 40 insertions(+), 10 deletions(-)
tools/testing/selftests/net/udpgso.c +32 -10
index a47dca025346..6b1998b9f7df 100644
@@ -49,6 +49,7 @@ static bool		cfg_do_ipv4;
 static bool		cfg_do_ipv6;
 static bool		cfg_do_connected;
 static bool		cfg_do_connectionless;
+static bool		cfg_do_msgmore;
 static bool		cfg_do_setsockopt;
 static int		cfg_specific_test_id = -1;
 
@@ -369,6 +370,23 @@ static void set_route_mtu(int mtu, bool is_ipv4)
 	fprintf(stderr, "route mtu (test): %u\n", mtu);
 }
 
+static bool __send_one(int fd, struct msghdr *msg, int flags)
+{
+	int ret;
+
+	ret = sendmsg(fd, msg, flags);
+	if (ret == -1 && (errno == EMSGSIZE || errno == ENOMEM))
+		return false;
+	if (ret == -1)
+		error(1, errno, "sendmsg");
+	if (ret != msg->msg_iov->iov_len)
+		error(1, 0, "sendto: %d != %lu", ret, msg->msg_iov->iov_len);
+	if (msg->msg_flags)
+		error(1, 0, "sendmsg: return flags 0x%x\n", msg->msg_flags);
+
+	return true;
+}
+
 static bool send_one(int fd, int len, int gso_len,
 		     struct sockaddr *addr, socklen_t alen)
 {
@@ -376,7 +394,6 @@ static bool send_one(int fd, int len, int gso_len,
 	struct msghdr msg = {0};
 	struct iovec iov = {0};
 	struct cmsghdr *cm;
-	int ret;
 
 	iov.iov_base = buf;
 	iov.iov_len = len;
@@ -398,15 +415,17 @@ static bool send_one(int fd, int len, int gso_len,
 		*((uint16_t *) CMSG_DATA(cm)) = gso_len;
 	}
 
-	ret = sendmsg(fd, &msg, 0);
-	if (ret == -1 && (errno == EMSGSIZE || errno == ENOMEM))
-		return false;
-	if (ret == -1)
-		error(1, errno, "sendmsg");
-	if (ret != len)
-		error(1, 0, "sendto: %d != %u", ret, len);
+	/* If MSG_MORE, send 1 byte followed by remainder */
+	if (cfg_do_msgmore && len > 1) {
+		iov.iov_len = 1;
+		if (!__send_one(fd, &msg, MSG_MORE))
+			error(1, 0, "send 1B failed");
 
-	return true;
+		iov.iov_base++;
+		iov.iov_len = len - 1;
+	}
+
+	return __send_one(fd, &msg, 0);
 }
 
 static int recv_one(int fd, int flags)
@@ -558,7 +577,7 @@ static void parse_opts(int argc, char **argv)
 {
 	int c;
 
-	while ((c = getopt(argc, argv, "46cCst:")) != -1) {
+	while ((c = getopt(argc, argv, "46cCmst:")) != -1) {
 		switch (c) {
 		case '4':
 			cfg_do_ipv4 = true;
@@ -572,6 +591,9 @@ static void parse_opts(int argc, char **argv)
 		case 'C':
 			cfg_do_connectionless = true;
 			break;
+		case 'm':
+			cfg_do_msgmore = true;
+			break;
 		case 's':
 			cfg_do_setsockopt = true;
 			break;
tools/testing/selftests/net/udpgso.sh +8 -0
index 7cdf0e7c1dde..47acfbbbae38 100755
@@ -21,3 +21,11 @@ echo "ipv4 connected"
 # blocked on 2nd loopback address
 # echo "ipv6 connected"
 # ./in_netns.sh ./udpgso -6 -c
+
+# ip forces CHECKSUM_NONE with MSG_MORE
+# echo "ipv4 msg_more"
+# ./in_netns.sh ./udpgso -4 -C -m
+
+# ipv6 forces CHECKSUM_NONE with MSG_MORE
+# echo "ipv6 msg_more"
+# ./in_netns.sh ./udpgso -6 -C -m
Signature · 1 line
2.17.0.484.g0c8726318c-goog
#1 lore raw

RFC PATCH 11/11 selftests: udp gso benchmark

From: Willem de Bruijn <[email protected]>

Send udp data between a source and sink, optionally with udp gso. The two processes are expected to be run on separate hosts.

A script is included that runs them together over loopback in a single namespace.

---
 tools/testing/selftests/net/.gitignore        |   2 +
 tools/testing/selftests/net/Makefile          |   4 +-
 tools/testing/selftests/net/udpgso_bench.sh   |  74 ++++
 tools/testing/selftests/net/udpgso_bench_rx.c | 265 ++++++++++++
 tools/testing/selftests/net/udpgso_bench_tx.c | 379 ++++++++++++++++++
 5 files changed, 722 insertions(+), 2 deletions(-)
 create mode 100755 tools/testing/selftests/net/udpgso_bench.sh
 create mode 100644 tools/testing/selftests/net/udpgso_bench_rx.c
 create mode 100644 tools/testing/selftests/net/udpgso_bench_tx.c
tools/testing/selftests/net/.gitignore +2 -0
index 6333b789c8fa..bb9329387181 100644
@@ -8,3 +8,5 @@ reuseport_bpf_numa
 reuseport_dualstack
 reuseaddr_conflict
 udpgso
+udpgso_bench_rx
+udpgso_bench_tx
tools/testing/selftests/net/Makefile +2 -2
index a05a657489b9..750fbe371338 100644
@@ -5,13 +5,13 @@ CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g
 CFLAGS += -I../../../../usr/include/
 
 TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh rtnetlink.sh
-TEST_PROGS += fib_tests.sh fib-onlink-tests.sh pmtu.sh udpgso.sh
+TEST_PROGS += fib_tests.sh fib-onlink-tests.sh pmtu.sh udpgso.sh udpgso_bench.sh
 TEST_GEN_FILES =  socket
 TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy
 TEST_GEN_FILES += tcp_mmap
 TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
 TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict
-TEST_GEN_PROGS += udpgso
+TEST_GEN_PROGS += udpgso udpgso_bench_tx udpgso_bench_rx
 
 include ../lib.mk
 
tools/testing/selftests/net/udpgso_bench.sh new file +74 -0

74 lines not on this page · raw message

tools/testing/selftests/net/udpgso_bench_rx.c new file +265 -0

265 lines not on this page · raw message

tools/testing/selftests/net/udpgso_bench_tx.c new file +379 -0

379 lines not on this page · raw message

Signature · 1 line
2.17.0.484.g0c8726318c-goog