From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com
Subject: [PATCH liburing v2 2/5] examples/send-zc: option to bind socket to device
Date: Fri, 2 May 2025 17:53:59 +0100 [thread overview]
Message-ID: <67b6be6a4aea6d47e00aa9fc9a959bf20ad5bf2b.1746204705.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1746204705.git.asml.silence@gmail.com>
Let the user to specify the interface for tx.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
examples/send-zerocopy.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c
index c83ef4d9..b4721672 100644
--- a/examples/send-zerocopy.c
+++ b/examples/send-zerocopy.c
@@ -68,6 +68,7 @@ static bool cfg_defer_taskrun = 0;
static int cfg_cpu = -1;
static bool cfg_rx = 0;
static unsigned cfg_nr_threads = 1;
+static const char *cfg_ifname;
static int cfg_family = PF_UNSPEC;
static int cfg_type = 0;
@@ -343,6 +344,16 @@ static void do_tx(struct thread_data *td, int domain, int type, int protocol)
if (fd == -1)
t_error(1, errno, "socket t");
+ if (cfg_ifname) {
+ struct ifreq ifr;
+
+ memset(&ifr, 0, sizeof(ifr));
+ snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), cfg_ifname);
+
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0)
+ t_error(1, errno, "Binding to device failed\n");
+ }
+
if (connect(fd, (void *)&td->dst_addr, cfg_alen))
t_error(1, errno, "connect, idx %i", td->idx);
@@ -516,7 +527,7 @@ static void parse_opts(int argc, char **argv)
cfg_payload_len = max_payload_len;
- while ((c = getopt(argc, argv, "46D:p:s:t:n:z:b:l:dC:T:Ry")) != -1) {
+ while ((c = getopt(argc, argv, "46D:p:s:t:n:z:I:b:l:dC:T:Ry")) != -1) {
switch (c) {
case '4':
if (cfg_family != PF_UNSPEC)
@@ -530,6 +541,9 @@ static void parse_opts(int argc, char **argv)
cfg_family = PF_INET6;
cfg_alen = sizeof(struct sockaddr_in6);
break;
+ case 'I':
+ cfg_ifname = optarg;
+ break;
case 'D':
daddr = optarg;
break;
@@ -588,6 +602,8 @@ static void parse_opts(int argc, char **argv)
t_error(1, 0, "-s: payload exceeds max (%d)", max_payload_len);
if (!cfg_nr_reqs)
t_error(1, 0, "-n: submit batch can't be zero");
+ if (cfg_ifname && cfg_rx)
+ t_error(1, 0, "Interface can only be specified for tx");
if (cfg_nr_reqs > 1 && cfg_type == SOCK_STREAM)
printf("warning: submit batching >1 with TCP sockets will cause data reordering");
--
2.48.1
next prev parent reply other threads:[~2025-05-02 16:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 16:53 [PATCH liburing v2 0/5] enchance zc benchmarks Pavel Begunkov
2025-05-02 16:53 ` [PATCH liburing v2 1/5] examples/send-zc: warn about data reordering Pavel Begunkov
2025-05-02 16:53 ` Pavel Begunkov [this message]
2025-05-02 16:54 ` [PATCH liburing v2 3/5] examples/send-zc: optionally fill data with a pattern Pavel Begunkov
2025-05-02 16:54 ` [PATCH liburing v2 4/5] examples/send-zc: record time on disconnect Pavel Begunkov
2025-05-02 16:54 ` [PATCH liburing v2 5/5] examples/zcrx: be more verbose on verification failure Pavel Begunkov
2025-05-04 16:53 ` [PATCH liburing v2 0/5] enchance zc benchmarks Jens Axboe
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=67b6be6a4aea6d47e00aa9fc9a959bf20ad5bf2b.1746204705.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=io-uring@vger.kernel.org \
/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