From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH liburing 4/8] examples: convert reg-wait to new api
Date: Fri, 15 Nov 2024 21:33:51 +0000 [thread overview]
Message-ID: <45f88d24de240c3823e6cc04496a54d62d5d6305.1731705935.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
examples/reg-wait.c | 45 +++++++++++++++++++++++++++++++++++++++------
1 file changed, 39 insertions(+), 6 deletions(-)
diff --git a/examples/reg-wait.c b/examples/reg-wait.c
index 375538c..0e119aa 100644
--- a/examples/reg-wait.c
+++ b/examples/reg-wait.c
@@ -38,6 +38,20 @@ static unsigned long long mtime_since_now(struct timeval *tv)
return mtime_since(tv, &end);
}
+static int register_memory(struct io_uring *ring, void *ptr, size_t size)
+{
+ struct io_uring_region_desc rd = {};
+ struct io_uring_mem_region_reg mr = {};
+
+ rd.user_addr = (__u64)(unsigned long)ptr;
+ rd.size = size;
+ rd.flags = IORING_MEM_REGION_TYPE_USER;
+ mr.region_uptr = (__u64)(unsigned long)&rd;
+ mr.flags = IORING_MEM_REGION_REG_WAIT_ARG;
+
+ return io_uring_register_region(ring, &mr);
+}
+
int main(int argc, char *argv[])
{
struct io_uring_reg_wait *reg;
@@ -48,30 +62,43 @@ int main(int argc, char *argv[])
unsigned long msec;
struct timeval tv;
int ret, fds[2];
+ int page_size;
if (argc > 1) {
fprintf(stdout, "%s: takes no arguments\n", argv[0]);
return 0;
}
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ fprintf(stderr, "sysconf(_SC_PAGESIZE) failed\n");
+ return 1;
+ }
+
if (pipe(fds) < 0) {
perror("pipe");
return 1;
}
- ret = io_uring_queue_init(8, &ring, 0);
+ ret = io_uring_queue_init(8, &ring, IORING_SETUP_R_DISABLED);
if (ret) {
fprintf(stderr, "Queue init: %d\n", ret);
return 1;
}
/*
- * Setup wait region. We'll use 32 here, but 64 is probably a more
- * logical value, as it'll pin a page regardless of size. 64 is the
- * max value on a 4k page size architecture.
+ * Setup a region we'll use to pass wait arguments. It should be
+ * page aligned, we're using only first two wait entries here and
+ * the rest of the memory can be reused for other purposes.
*/
- reg = io_uring_setup_reg_wait(&ring, 32, &ret);
+ reg = aligned_alloc(page_size, page_size);
if (!reg) {
+ fprintf(stderr, "allocation failed\n");
+ return 1;
+ }
+
+ ret = register_memory(&ring, reg, page_size);
+ if (ret) {
if (ret == -EINVAL) {
fprintf(stderr, "Kernel doesn't support registered waits\n");
return 1;
@@ -80,6 +107,12 @@ int main(int argc, char *argv[])
return 1;
}
+ ret = io_uring_enable_rings(&ring);
+ if (ret) {
+ fprintf(stderr, "io_uring_enable_rings failure %i\n", ret);
+ return 1;
+ }
+
/*
* Setup two distinct wait regions. Index 0 will be a 1 second wait,
* and region 2 is a short wait using min_wait_usec as well. Neither
@@ -154,6 +187,6 @@ int main(int argc, char *argv[])
* Cleanup after ourselves
*/
io_uring_queue_exit(&ring);
- io_uring_free_reg_wait(reg, 32);
+ free(reg);
return 0;
}
--
2.46.0
next prev parent reply other threads:[~2024-11-15 21:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-15 21:33 [PATCH liburing 0/8] update reg-wait to use region API Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 1/8] queue: break reg wait setup Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 2/8] Update io_uring.h Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 3/8] queue: add region helpers and fix up wait reg kernel api Pavel Begunkov
2024-11-15 21:33 ` Pavel Begunkov [this message]
2024-11-15 21:33 ` [PATCH liburing 5/8] tests: convert reg-wait to regions Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 6/8] tests: add region testing Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 7/8] tests: test arbitrary offset reg waits Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 8/8] Remove leftovers of old reg-wait registration api Pavel Begunkov
2024-11-16 17:07 ` [PATCH liburing 0/8] update reg-wait to use region API 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=45f88d24de240c3823e6cc04496a54d62d5d6305.1731705935.git.asml.silence@gmail.com \
[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