From: Joe Damato <jdamato@fastly.com>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, asml.silence@gmail.com,
linux-fsdevel@vger.kernel.org, edumazet@google.com,
pabeni@redhat.com, horms@kernel.org, linux-api@vger.kernel.org,
linux-arch@vger.kernel.org, viro@zeniv.linux.org.uk,
jack@suse.cz, kuba@kernel.org, shuah@kernel.org, sdf@fomichev.me,
mingo@redhat.com, arnd@arndb.de, brauner@kernel.org,
akpm@linux-foundation.org, tglx@linutronix.de, jolsa@kernel.org,
linux-kselftest@vger.kernel.org, Joe Damato <jdamato@fastly.com>
Subject: [RFC -next 10/10] selftests: Add sendfile zerocopy notification test
Date: Wed, 19 Mar 2025 00:15:21 +0000 [thread overview]
Message-ID: <20250319001521.53249-11-jdamato@fastly.com> (raw)
In-Reply-To: <20250319001521.53249-1-jdamato@fastly.com>
Extend the existing the msg_zerocopy test to allow testing sendfile to
ensure that notifications are generated.
Signed-off-by: Joe Damato <jdamato@fastly.com>
---
tools/testing/selftests/net/msg_zerocopy.c | 54 ++++++++++++++++++++-
tools/testing/selftests/net/msg_zerocopy.sh | 5 ++
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/msg_zerocopy.c b/tools/testing/selftests/net/msg_zerocopy.c
index 7ea5fb28c93d..20e334b25fbd 100644
--- a/tools/testing/selftests/net/msg_zerocopy.c
+++ b/tools/testing/selftests/net/msg_zerocopy.c
@@ -30,6 +30,7 @@
#include <arpa/inet.h>
#include <error.h>
#include <errno.h>
+#include <fcntl.h>
#include <limits.h>
#include <linux/errqueue.h>
#include <linux/if_packet.h>
@@ -50,6 +51,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <sys/sendfile.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
@@ -74,6 +76,14 @@
#define MSG_ZEROCOPY 0x4000000
#endif
+#ifndef SENDFILE_ZC
+#define SENDFILE_ZC (0x2)
+#endif
+
+#ifndef __NR_sendfile2
+#define __NR_sendfile2 467
+#endif
+
static int cfg_cork;
static bool cfg_cork_mixed;
static int cfg_cpu = -1; /* default: pin to last cpu */
@@ -87,6 +97,8 @@ static int cfg_verbose;
static int cfg_waittime_ms = 500;
static int cfg_notification_limit = 32;
static bool cfg_zerocopy;
+static bool cfg_sendfile;
+static const char *cfg_sendfile_path;
static socklen_t cfg_alen;
static struct sockaddr_storage cfg_dst_addr;
@@ -182,6 +194,37 @@ static void add_zcopy_cookie(struct msghdr *msg, uint32_t cookie)
memcpy(CMSG_DATA(cm), &cookie, sizeof(cookie));
}
+static bool do_sendfile(int fd)
+{
+ int from_fd = open(cfg_sendfile_path, O_RDONLY, 0);
+ struct stat buf;
+ ssize_t total = 0;
+ ssize_t ret = 0;
+ off_t off = 0;
+
+ if (fd < 0)
+ error(1, errno, "couldn't open sendfile path");
+
+ if (fstat(from_fd, &buf))
+ error(1, errno, "couldn't fstat");
+
+ while (total < buf.st_size) {
+ ret = syscall(__NR_sendfile2, fd, from_fd, &off, buf.st_size,
+ SENDFILE_ZC);
+ if (ret < 0)
+ error(1, errno, "unable to sendfile");
+ total += ret;
+ sends_since_notify++;
+ bytes += ret;
+ packets++;
+ if (ret > 0)
+ expected_completions++;
+ }
+
+ close(from_fd);
+ return total == buf.st_size;
+}
+
static bool do_sendmsg(int fd, struct msghdr *msg, bool do_zerocopy, int domain)
{
int ret, len, i, flags;
@@ -550,6 +593,8 @@ static void do_tx(int domain, int type, int protocol)
do {
if (cfg_cork)
do_sendmsg_corked(fd, &msg);
+ else if (cfg_sendfile)
+ do_sendfile(fd);
else
do_sendmsg(fd, &msg, cfg_zerocopy, domain);
@@ -715,7 +760,7 @@ static void parse_opts(int argc, char **argv)
cfg_payload_len = max_payload_len;
- while ((c = getopt(argc, argv, "46c:C:D:i:l:mp:rs:S:t:vz")) != -1) {
+ while ((c = getopt(argc, argv, "46c:C:D:i:l:mp:rs:S:t:vzf:w:")) != -1) {
switch (c) {
case '4':
if (cfg_family != PF_UNSPEC)
@@ -767,9 +812,16 @@ static void parse_opts(int argc, char **argv)
case 'v':
cfg_verbose++;
break;
+ case 'f':
+ cfg_sendfile = true;
+ cfg_sendfile_path = optarg;
+ break;
case 'z':
cfg_zerocopy = true;
break;
+ case 'w':
+ cfg_waittime_ms = 200 + strtoul(optarg, NULL, 10) * 1000;
+ break;
}
}
diff --git a/tools/testing/selftests/net/msg_zerocopy.sh b/tools/testing/selftests/net/msg_zerocopy.sh
index 89c22f5320e0..c735e4ab86b5 100755
--- a/tools/testing/selftests/net/msg_zerocopy.sh
+++ b/tools/testing/selftests/net/msg_zerocopy.sh
@@ -74,6 +74,7 @@ esac
cleanup() {
ip netns del "${NS2}"
ip netns del "${NS1}"
+ rm -f sendfile_data
}
trap cleanup EXIT
@@ -106,6 +107,9 @@ ip -netns "${NS2}" addr add fd::2/64 dev "${DEV}" nodad
# Optionally disable sg or csum offload to test edge cases
# ip netns exec "${NS1}" ethtool -K "${DEV}" sg off
+# create sendfile test data
+dd if=/dev/zero of=sendfile_data bs=1M count=8 2> /dev/null
+
do_test() {
local readonly ARGS="$1"
@@ -118,4 +122,5 @@ do_test() {
do_test "${EXTRA_ARGS}"
do_test "-z ${EXTRA_ARGS}"
+do_test "-z -f sendfile_data ${EXTRA_ARGS}"
echo ok
--
2.43.0
next prev parent reply other threads:[~2025-03-19 0:15 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-19 0:15 [RFC -next 00/10] Add ZC notifications to splice and sendfile Joe Damato
2025-03-19 0:15 ` [RFC -next 01/10] splice: Add ubuf_info to prepare for ZC Joe Damato
2025-03-19 0:15 ` [RFC -next 02/10] splice: Add helper that passes through splice_desc Joe Damato
2025-03-19 0:15 ` [RFC -next 03/10] splice: Factor splice_socket into a helper Joe Damato
2025-03-19 0:15 ` [RFC -next 04/10] splice: Add SPLICE_F_ZC and attach ubuf Joe Damato
2025-03-19 0:15 ` [RFC -next 05/10] fs: Add splice_write_sd to file operations Joe Damato
2025-03-19 0:15 ` [RFC -next 06/10] fs: Extend do_sendfile to take a flags argument Joe Damato
2025-03-19 0:15 ` [RFC -next 07/10] fs: Add sendfile2 which accepts " Joe Damato
2025-03-19 0:15 ` [RFC -next 08/10] fs: Add sendfile flags for sendfile2 Joe Damato
2025-03-19 0:15 ` [RFC -next 09/10] fs: Add sendfile2 syscall Joe Damato
2025-03-19 0:15 ` Joe Damato [this message]
2025-03-19 8:04 ` [RFC -next 00/10] Add ZC notifications to splice and sendfile Christoph Hellwig
2025-03-19 15:32 ` Joe Damato
2025-03-19 16:07 ` Jens Axboe
2025-03-19 17:04 ` Joe Damato
2025-03-19 17:20 ` Jens Axboe
2025-03-19 17:45 ` Joe Damato
2025-03-19 18:37 ` Jens Axboe
2025-03-19 19:15 ` Stefan Metzmacher
2025-03-20 10:46 ` Pavel Begunkov
2025-03-21 7:55 ` Stefan Metzmacher
2025-03-21 20:51 ` Pavel Begunkov
2025-03-19 19:16 ` Joe Damato
2025-03-21 11:11 ` Jens Axboe
2025-03-20 5:57 ` Christoph Hellwig
2025-03-20 18:23 ` Joe Damato
2025-03-21 5:56 ` Christoph Hellwig
2025-03-21 11:14 ` Jens Axboe
2025-03-21 16:36 ` Joe Damato
2025-03-21 20:30 ` Joe Damato
2025-03-21 20:33 ` Jens Axboe
2025-03-21 21:28 ` Joe Damato
2025-03-21 20:35 ` Jens Axboe
2025-03-21 16:44 ` Joe Damato
2025-03-19 23:22 ` Joe Damato
2025-03-21 11:13 ` Jens Axboe
2025-03-20 5:50 ` Christoph Hellwig
2025-03-20 18:05 ` Joe Damato
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250319001521.53249-11-jdamato@fastly.com \
--to=jdamato@fastly.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=asml.silence@gmail.com \
--cc=brauner@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jack@suse.cz \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox