public inbox for [email protected]
 help / color / mirror / Atom feed
From: Oliver Crumrine <[email protected]>
To: [email protected], [email protected], [email protected],
	 [email protected], [email protected], [email protected],
	[email protected],  [email protected]
Cc: [email protected], [email protected],
	 [email protected], [email protected]
Subject: [PATCH 2/3] io_uring: Add io_uring_peek_cqe to mini_liburing
Date: Thu, 4 Apr 2024 18:19:01 -0400	[thread overview]
Message-ID: <44916a6a3f94bfcff78da2c602c916c856d7cfcf.1712268605.git.ozlinuxc@gmail.com> (raw)
In-Reply-To: <[email protected]>

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 <[email protected]>
---
 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


  parent reply	other threads:[~2024-04-05  2:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-04 22:16 [PATCH 0/3] Add REQ_F_CQE_SKIP support to io_uring zerocopy Oliver Crumrine
2024-04-04 22:17 ` [PATCH 1/3] io_uring: Add REQ_F_CQE_SKIP support for " Oliver Crumrine
2024-04-05 13:01   ` Pavel Begunkov
2024-04-05 20:04     ` Oliver Crumrine
2024-04-06 21:23       ` Pavel Begunkov
2024-04-07 13:13         ` Oliver Crumrine
2024-04-07 19:14           ` Oliver Crumrine
2024-04-07 23:46             ` Pavel Begunkov
2024-04-09  1:33               ` Oliver Crumrine
2024-04-10 12:05                 ` Pavel Begunkov
2024-04-11  0:52                   ` Oliver Crumrine
2024-04-12 13:20                     ` Pavel Begunkov
2024-04-15 23:51                       ` Oliver Crumrine
2024-04-04 22:19 ` Oliver Crumrine [this message]
2024-04-04 22:19 ` [PATCH 3/3] io_uring: Support IOSQE_CQE_SKIP_SUCCESS in io_uring zerocopy test Oliver Crumrine
2024-04-06 20:33   ` Muhammad Usama Anjum
2024-04-05 12:06 ` [PATCH 0/3] Add REQ_F_CQE_SKIP support to io_uring zerocopy Pavel Begunkov

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=44916a6a3f94bfcff78da2c602c916c856d7cfcf.1712268605.git.ozlinuxc@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [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