summaryrefslogtreecommitdiffstats
path: root/contrib/libs/liburing/test/helpers.c
diff options
context:
space:
mode:
authorthegeorg <[email protected]>2023-07-26 17:26:21 +0300
committerthegeorg <[email protected]>2023-07-26 17:26:21 +0300
commit3785d5f97965bccf048718d8717904cf50f9f8f9 (patch)
treeb7ce8ae67d7eb7fcf7767c54379f0564c281147f /contrib/libs/liburing/test/helpers.c
parent1f6b57071583f89299bb5abd3863d594f23c5be5 (diff)
Update contrib/libs/liburing to 2.4
Diffstat (limited to 'contrib/libs/liburing/test/helpers.c')
-rw-r--r--contrib/libs/liburing/test/helpers.c56
1 files changed, 54 insertions, 2 deletions
diff --git a/contrib/libs/liburing/test/helpers.c b/contrib/libs/liburing/test/helpers.c
index a29c7b59667..7133b00b914 100644
--- a/contrib/libs/liburing/test/helpers.c
+++ b/contrib/libs/liburing/test/helpers.c
@@ -9,6 +9,7 @@
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
+#include <stdarg.h>
#include <sys/types.h>
#include <arpa/inet.h>
@@ -135,7 +136,8 @@ enum t_setup_ret t_create_ring_params(int depth, struct io_uring *ring,
return T_SETUP_SKIP;
}
- fprintf(stderr, "queue_init: %s\n", strerror(-ret));
+ if (ret != -EINVAL)
+ fprintf(stderr, "queue_init: %s\n", strerror(-ret));
return ret;
}
@@ -174,7 +176,7 @@ int t_create_socket_pair(int fd[2], bool stream)
int val;
struct sockaddr_in serv_addr;
struct sockaddr *paddr;
- size_t paddrlen;
+ socklen_t paddrlen;
type |= SOCK_CLOEXEC;
fd[0] = socket(AF_INET, type, 0);
@@ -267,3 +269,53 @@ bool t_probe_defer_taskrun(void)
io_uring_queue_exit(&ring);
return true;
}
+
+/*
+ * Sync internal state with kernel ring state on the SQ side. Returns the
+ * number of pending items in the SQ ring, for the shared ring.
+ */
+unsigned __io_uring_flush_sq(struct io_uring *ring)
+{
+ struct io_uring_sq *sq = &ring->sq;
+ unsigned tail = sq->sqe_tail;
+
+ if (sq->sqe_head != tail) {
+ sq->sqe_head = tail;
+ /*
+ * Ensure kernel sees the SQE updates before the tail update.
+ */
+ if (!(ring->flags & IORING_SETUP_SQPOLL))
+ IO_URING_WRITE_ONCE(*sq->ktail, tail);
+ else
+ io_uring_smp_store_release(sq->ktail, tail);
+ }
+ /*
+ * This _may_ look problematic, as we're not supposed to be reading
+ * SQ->head without acquire semantics. When we're in SQPOLL mode, the
+ * kernel submitter could be updating this right now. For non-SQPOLL,
+ * task itself does it, and there's no potential race. But even for
+ * SQPOLL, the load is going to be potentially out-of-date the very
+ * instant it's done, regardless or whether or not it's done
+ * atomically. Worst case, we're going to be over-estimating what
+ * we can submit. The point is, we need to be able to deal with this
+ * situation regardless of any perceived atomicity.
+ */
+ return tail - *sq->khead;
+}
+
+/*
+ * Implementation of error(3), prints an error message and exits.
+ */
+void t_error(int status, int errnum, const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+
+ vfprintf(stderr, format, args);
+ if (errnum)
+ fprintf(stderr, ": %s", strerror(errnum));
+
+ fprintf(stderr, "\n");
+ va_end(args);
+ exit(status);
+}