From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH liburing 8/8] test/reg-wait: test various sized regions
Date: Sat, 16 Nov 2024 21:27:48 +0000 [thread overview]
Message-ID: <84233449abb8f5f3c878e7ccabf8520880bac624.1731792294.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 80 insertions(+), 1 deletion(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index 559228f..b7c823a 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -9,6 +9,8 @@
#include <string.h>
#include <fcntl.h>
#include <sys/time.h>
+#include <sys/mman.h>
+#include <linux/mman.h>
#include "liburing.h"
#include "helpers.h"
@@ -63,6 +65,12 @@ err:
return ret;
}
+static int init_ring_with_region(struct io_uring *ring, unsigned ring_flags,
+ struct io_uring_mem_region_reg *pr)
+{
+ return __init_ring_with_region(ring, ring_flags, pr, true);
+}
+
static int page_size;
static struct io_uring_reg_wait *reg;
@@ -109,6 +117,14 @@ static int test_offsets(struct io_uring *ring, struct io_uring_reg_wait *base,
int copy_size;
int ret;
+ rw = base;
+ memcpy(rw, &brief_wait, sizeof(brief_wait));
+ ret = io_uring_submit_and_wait_reg(ring, &cqe, 1, 0);
+ if (ret != -ETIME) {
+ fprintf(stderr, "0 index failed: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
if (overallocated) {
rw = base + max_index;
memcpy(rw, &brief_wait, sizeof(brief_wait));
@@ -134,7 +150,7 @@ static int test_offsets(struct io_uring *ring, struct io_uring_reg_wait *base,
return T_EXIT_FAIL;
}
- offset = page_size - sizeof(long);
+ offset = size - sizeof(long);
rw = (void *)base + offset;
copy_size = overallocated ? sizeof(brief_wait) : sizeof(long);
memcpy(rw, &brief_wait, copy_size);
@@ -354,6 +370,62 @@ static int test_regions(void)
return 0;
}
+static void *alloc_region_buffer(size_t size, bool huge)
+{
+ int flags = MAP_PRIVATE | MAP_ANONYMOUS;
+ void *p;
+
+ if (huge)
+ flags |= MAP_HUGETLB | MAP_HUGE_2MB;
+ p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0);
+ return p == MAP_FAILED ? NULL : p;
+}
+
+static int test_region_buffer_types(void)
+{
+ const size_t huge_size = 1024 * 1024 * 2;
+ const size_t map_sizes[] = { page_size, page_size * 2, page_size * 16,
+ huge_size, 2 * huge_size};
+ struct io_uring_region_desc rd = {};
+ struct io_uring_mem_region_reg mr = {};
+ struct io_uring ring;
+ int sz_idx, ret;
+
+ mr.region_uptr = (__u64)(unsigned long)&rd;
+ mr.flags = IORING_MEM_REGION_REG_WAIT_ARG;
+
+ for (sz_idx = 0; sz_idx < ARRAY_SIZE(map_sizes); sz_idx++) {
+ size_t size = map_sizes[sz_idx];
+ void *buffer;
+
+ buffer = alloc_region_buffer(size, size >= huge_size);
+ if (!buffer)
+ continue;
+
+ rd.user_addr = (__u64)(unsigned long)buffer;
+ rd.size = size;
+ rd.flags = IORING_MEM_REGION_TYPE_USER;
+
+ ret = init_ring_with_region(&ring, 0, &mr);
+ if (ret) {
+ fprintf(stderr, "init ring failed %i\n", ret);
+ return 1;
+ }
+
+ ret = test_offsets(&ring, buffer, size, false);
+ if (ret) {
+ fprintf(stderr, "test_offsets failed, size %lu\n",
+ (unsigned long)size);
+ return 1;
+ }
+
+ munmap(buffer, size);
+ io_uring_queue_exit(&ring);
+ }
+
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int ret;
@@ -381,5 +453,12 @@ int main(int argc, char *argv[])
fprintf(stderr, "test_wait_arg failed\n");
return 1;
}
+
+ ret = test_region_buffer_types();
+ if (ret == T_EXIT_FAIL) {
+ fprintf(stderr, "test_region_buffer_types failed\n");
+ return 1;
+ }
+
return 0;
}
--
2.46.0
next prev parent reply other threads:[~2024-11-16 21:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-16 21:27 [PATCH liburing 0/8] region test fixes + improvements Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 1/8] test/reg-wait: fix test_regions Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 2/8] test/reg-wait: pass right timeout indexes Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 3/8] test/reg-wait: use queried page_size Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 4/8] test/reg-wait: skip when R_DISABLED is not supported Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 5/8] test/reg-wait: dedup regwait init Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 6/8] test/reg-wait: parameterise test_offsets Pavel Begunkov
2024-11-16 21:27 ` [PATCH liburing 7/8] test/reg-wait: add registration helper Pavel Begunkov
2024-11-16 21:27 ` Pavel Begunkov [this message]
2024-11-17 16:03 ` [PATCH liburing 0/8] region test fixes + improvements 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=84233449abb8f5f3c878e7ccabf8520880bac624.1731792294.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