From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 1/3] examples/send-zc: add affinity / CPU pinning
Date: Wed, 1 Mar 2023 16:10:10 +0000 [thread overview]
Message-ID: <28b0e6d9c7d0c6adecb17fb72f6dfefb9bb51b47.1677686850.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Pass '-C <cpu_num>' to pin threads and io-wq to the specified CPU.
Signed-off-by: Pavel Begunkov <[email protected]>
---
examples/send-zerocopy.c | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c
index c9b5506..a86106f 100644
--- a/examples/send-zerocopy.c
+++ b/examples/send-zerocopy.c
@@ -12,6 +12,7 @@
#include <stdarg.h>
#include <string.h>
+#include <sched.h>
#include <arpa/inet.h>
#include <linux/errqueue.h>
#include <linux/if_packet.h>
@@ -50,6 +51,7 @@ static int cfg_nr_reqs = 8;
static bool cfg_fixed_buf = 1;
static bool cfg_hugetlb = 0;
static bool cfg_defer_taskrun = 0;
+static int cfg_cpu = -1;
static int cfg_family = PF_UNSPEC;
static int cfg_payload_len;
@@ -79,6 +81,32 @@ static void t_error(int status, int errnum, const char *format, ...)
exit(status);
}
+static void set_cpu_affinity(void)
+{
+ cpu_set_t mask;
+
+ if (cfg_cpu == -1)
+ return;
+
+ CPU_ZERO(&mask);
+ CPU_SET(cfg_cpu, &mask);
+ if (sched_setaffinity(0, sizeof(mask), &mask))
+ t_error(1, errno, "unable to pin cpu\n");
+}
+
+static void set_iowq_affinity(struct io_uring *ring)
+{
+ cpu_set_t mask;
+ int ret;
+
+ if (cfg_cpu == -1)
+ return;
+
+ ret = io_uring_register_iowq_aff(ring, 1, &mask);
+ if (ret)
+ t_error(1, ret, "unabled to set io-wq affinity\n");
+}
+
static unsigned long gettimeofday_ms(void)
{
struct timeval tv;
@@ -172,6 +200,9 @@ static void do_tx(int domain, int type, int protocol)
if (ret)
t_error(1, ret, "io_uring: queue init");
+ set_cpu_affinity();
+ set_iowq_affinity(&ring);
+
if (cfg_fixed_files) {
ret = io_uring_register_files(&ring, &fd, 1);
if (ret < 0)
@@ -303,7 +334,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:d")) != -1) {
+ while ((c = getopt(argc, argv, "46D:p:s:t:n:z:b:l:dC:")) != -1) {
switch (c) {
case '4':
if (cfg_family != PF_UNSPEC)
@@ -344,6 +375,9 @@ static void parse_opts(int argc, char **argv)
case 'd':
cfg_defer_taskrun = 1;
break;
+ case 'C':
+ cfg_cpu = strtol(optarg, NULL, 0);
+ break;
}
}
@@ -363,6 +397,7 @@ int main(int argc, char **argv)
const char *cfg_test;
parse_opts(argc, argv);
+ set_cpu_affinity();
payload = payload_buf;
if (cfg_hugetlb) {
--
2.39.1
next prev parent reply other threads:[~2023-03-01 16:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-01 16:10 [PATCH liburing 0/3] sendzc test improvements Pavel Begunkov
2023-03-01 16:10 ` Pavel Begunkov [this message]
2023-03-01 16:10 ` [PATCH liburing 2/3] examples/send-zc: add multithreading Pavel Begunkov
2023-03-01 16:10 ` [PATCH liburing 3/3] examples/send-zc: add the receive part Pavel Begunkov
2023-03-01 20:00 ` [PATCH liburing 0/3] sendzc test improvements Jens Axboe
2023-03-01 20:31 ` Pavel Begunkov
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=28b0e6d9c7d0c6adecb17fb72f6dfefb9bb51b47.1677686850.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
/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