[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <44916a6a3f94bfcff78da2c602c916c856d7cfcf.1712268605.git.ozlinuxc@gmail.com>
Date: Thu, 4 Apr 2024 18:19:01 -0400
From: Oliver Crumrine <ozlinuxc@...il.com>
To: axboe@...nel.dk, asml.silence@...il.com, davem@...emloft.net,
edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com, shuah@...nel.org,
leitao@...ian.org
Cc: io-uring@...r.kernel.org, netdev@...r.kernel.org,
linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 2/3] io_uring: Add io_uring_peek_cqe to mini_liburing
mini_liburing.h is used by the io_uring tests as a stand-in for
liburing. The next patch in this series needs the io_uring_peek_cqe
function, and I speculate that future tests will too, so add that here.
Please scrutinize this code, I am somewhat new to io_uring, and whilst I
have tested this and know it to work, I very well could've made a
mistake somewhere without noticing.
Signed-off-by: Oliver Crumrine <ozlinuxc@...il.com>
---
tools/include/io_uring/mini_liburing.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/tools/include/io_uring/mini_liburing.h b/tools/include/io_uring/mini_liburing.h
index 9ccb16074eb5..94dcc7f9aa33 100644
--- a/tools/include/io_uring/mini_liburing.h
+++ b/tools/include/io_uring/mini_liburing.h
@@ -182,6 +182,24 @@ static inline int io_uring_wait_cqe(struct io_uring *ring,
return 0;
}
+static inline int io_uring_peek_cqe(struct io_uring *ring,
+ struct io_uring_cqe **cqe_ptr)
+{
+ struct io_uring_cq *cq = &ring->cq;
+ const unsigned int mask = *cq->kring_mask;
+ unsigned int head = *cq->khead;
+ unsigned int tail = *cq->ktail;
+
+ *cqe_ptr = NULL;
+
+ read_barrier();
+ if (head-tail) {
+ *cqe_ptr = &cq->cqes[head & mask];
+ return 0;
+ }
+ return -EAGAIN;
+}
+
static inline int io_uring_submit(struct io_uring *ring)
{
struct io_uring_sq *sq = &ring->sq;
--
2.44.0
Powered by blists - more mailing lists