aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/liburing/test/buf-ring.c
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.com>2024-06-09 11:55:21 +0300
committerthegeorg <thegeorg@yandex-team.com>2024-06-09 12:07:55 +0300
commitafd4899380eea1c70e2a68714b5da1c9919ccdbd (patch)
treecd5120708784139bc6a0f8881da1ed8389a065b3 /contrib/libs/liburing/test/buf-ring.c
parenta83bd2dd3c21e38c6c0807ec5e679497ab567f24 (diff)
downloadydb-afd4899380eea1c70e2a68714b5da1c9919ccdbd.tar.gz
Update contrib/libs/liburing to 2.6
3b51a9fb14de805208d11f1c077c78bb5d487e0f
Diffstat (limited to 'contrib/libs/liburing/test/buf-ring.c')
-rw-r--r--contrib/libs/liburing/test/buf-ring.c49
1 files changed, 42 insertions, 7 deletions
diff --git a/contrib/libs/liburing/test/buf-ring.c b/contrib/libs/liburing/test/buf-ring.c
index 08f03f99ec..682a97ec28 100644
--- a/contrib/libs/liburing/test/buf-ring.c
+++ b/contrib/libs/liburing/test/buf-ring.c
@@ -293,7 +293,7 @@ static int test_one_read(int fd, int bgid, struct io_uring *ring)
return cqe->flags >> 16;
}
-static int test_running(int bgid, int entries, int loops)
+static int test_running(int bgid, int entries, int loops, int use_mmap)
{
int ring_mask = io_uring_buf_ring_mask(entries);
struct io_uring_buf_ring *br;
@@ -308,11 +308,37 @@ static int test_running(int bgid, int entries, int loops)
else if (ret != T_SETUP_OK)
return 1;
- br = io_uring_setup_buf_ring(&ring, entries, bgid, 0, &ret);
- if (!br) {
- /* by now should have checked if this is supported or not */
- fprintf(stderr, "Buffer ring register failed %d\n", ret);
- return 1;
+ if (!use_mmap) {
+ br = io_uring_setup_buf_ring(&ring, entries, bgid, 0, &ret);
+ if (!br) {
+ /* by now should have checked if this is supported or not */
+ fprintf(stderr, "Buffer ring register failed %d\n", ret);
+ return 1;
+ }
+ } else {
+ struct io_uring_buf_reg reg = {
+ .ring_entries = entries,
+ .bgid = bgid,
+ .flags = IOU_PBUF_RING_MMAP,
+ };
+ size_t ring_size;
+ off_t off;
+
+ ret = io_uring_register_buf_ring(&ring, &reg, 0);
+ if (ret) {
+ fprintf(stderr, "mmap ring register failed %d\n", ret);
+ return 1;
+ }
+
+ off = IORING_OFF_PBUF_RING |
+ (unsigned long long) bgid << IORING_OFF_PBUF_SHIFT;
+ ring_size = sizeof(struct io_uring_buf) * entries;
+ br = mmap(NULL, ring_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_POPULATE, ring.ring_fd, off);
+ if (br == MAP_FAILED) {
+ perror("mmap");
+ return 1;
+ }
}
buffers = malloc(sizeof(bool) * entries);
@@ -424,12 +450,21 @@ int main(int argc, char *argv[])
}
for (i = 0; !no_buf_ring && entries[i] != -1; i++) {
- ret = test_running(2, entries[i], 3);
+ ret = test_running(2, entries[i], 3, 0);
if (ret) {
fprintf(stderr, "test_running(%d) failed\n", entries[i]);
return T_EXIT_FAIL;
}
}
+ for (i = 0; !no_buf_ring && entries[i] != -1; i++) {
+ ret = test_running(2, entries[i], 3, 1);
+ if (ret) {
+ fprintf(stderr, "test_running(%d) mmap failed\n", entries[i]);
+ return T_EXIT_FAIL;
+ }
+ }
+
+
return T_EXIT_PASS;
}