aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/liburing/test/buf-ring-put.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-put.c
parenta83bd2dd3c21e38c6c0807ec5e679497ab567f24 (diff)
downloadydb-afd4899380eea1c70e2a68714b5da1c9919ccdbd.tar.gz
Update contrib/libs/liburing to 2.6
3b51a9fb14de805208d11f1c077c78bb5d487e0f
Diffstat (limited to 'contrib/libs/liburing/test/buf-ring-put.c')
-rw-r--r--contrib/libs/liburing/test/buf-ring-put.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/contrib/libs/liburing/test/buf-ring-put.c b/contrib/libs/liburing/test/buf-ring-put.c
new file mode 100644
index 0000000000..6508f87023
--- /dev/null
+++ b/contrib/libs/liburing/test/buf-ring-put.c
@@ -0,0 +1,84 @@
+#include "../config-host.h"
+/* SPDX-License-Identifier: MIT */
+/*
+ * Description: test persistence of mmap'ed provided ring buffers. Use a range
+ * of buffer group IDs that puts us into both the lower end array
+ * and higher end xarry.
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/mman.h>
+
+#include "liburing.h"
+#include "helpers.h"
+
+#define BGID_START 60
+#define BGID_NR 10
+#define ENTRIES 512
+
+int main(int argc, char *argv[])
+{
+ struct io_uring_buf_ring *br[BGID_NR];
+ struct io_uring ring;
+ size_t ring_size;
+ int ret, i, j;
+
+ if (argc > 1)
+ return T_EXIT_SKIP;
+
+ ret = io_uring_queue_init(1, &ring, 0);
+ if (ret) {
+ fprintf(stderr, "queue init failed %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ ring_size = ENTRIES * sizeof(struct io_uring_buf);
+
+ for (i = 0; i < BGID_NR; i++) {
+ int bgid = BGID_START + i;
+ struct io_uring_buf_reg reg = {
+ .ring_entries = ENTRIES,
+ .bgid = bgid,
+ .flags = IOU_PBUF_RING_MMAP,
+ };
+ off_t off;
+
+ ret = io_uring_register_buf_ring(&ring, &reg, 0);
+ if (ret) {
+ if (ret == -EINVAL)
+ return T_EXIT_SKIP;
+ fprintf(stderr, "reg buf ring: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ off = IORING_OFF_PBUF_RING |
+ (unsigned long long) bgid << IORING_OFF_PBUF_SHIFT;
+ br[i] = mmap(NULL, ring_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_POPULATE, ring.ring_fd, off);
+ if (br[i] == MAP_FAILED) {
+ perror("mmap");
+ return T_EXIT_FAIL;
+ }
+ }
+
+ for (i = 0; i < BGID_NR; i++) {
+ ret = io_uring_unregister_buf_ring(&ring, BGID_START + i);
+ if (ret) {
+ fprintf(stderr, "reg buf ring: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+ }
+
+ for (j = 0; j < 1000; j++) {
+ for (i = 0; i < BGID_NR; i++)
+ memset(br[i], 0x5a, ring_size);
+ usleep(1000);
+ }
+
+ io_uring_queue_exit(&ring);
+ return T_EXIT_PASS;
+}