public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
To: Dylan Yudaken <dylany@meta.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	Pavel Begunkov <asml.silence@gmail.com>,
	Gilang Fachrezy <gilang4321@gmail.com>,
	Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
	Muhammad Rizki <kiizuha@gnuweeb.org>,
	io-uring Mailing List <io-uring@vger.kernel.org>,
	GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>,
	VNLX Kernel Department <kernel@vnlx.org>
Subject: Re: [PATCH liburing v1 1/7] liburing.h: Export `__io_uring_flush_sq()` function
Date: Thu, 24 Nov 2022 18:47:24 +0700	[thread overview]
Message-ID: <b303bde6-91b1-2ea2-7b1d-e64546c8ae7f@gnuweeb.org> (raw)
In-Reply-To: <f750be65c33e5d3a782cebf85954319caa77672f.camel@fb.com>

On 11/24/22 5:14 PM, Dylan Yudaken wrote:
> I think changing the tests to use the public API is probably better
> than exporting this function. I don't believe it has much general use?

But there is no public API that does the same thing. I'll mark it
as static and create a copy of that function in iopoll.c (in v2).

Something like this, what do you think?

  src/queue.c   |  2 +-
  test/iopoll.c | 33 ++++++++++++++++++++++++++++++++-
  2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/queue.c b/src/queue.c
index feea0ad..b784b10 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -201,7 +201,7 @@ again:
   * 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)
+static unsigned __io_uring_flush_sq(struct io_uring *ring)
  {
  	struct io_uring_sq *sq = &ring->sq;
  	unsigned tail = sq->sqe_tail;
diff --git a/test/iopoll.c b/test/iopoll.c
index 20f91c7..5edd5c3 100644
--- a/test/iopoll.c
+++ b/test/iopoll.c
@@ -201,7 +201,38 @@ err:
  	return 1;
  }
  
-extern unsigned __io_uring_flush_sq(struct io_uring *ring);
+/*
+ * 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.
+ */
+static 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;
+}
  
  /*
   * if we are polling io_uring_submit needs to always enter the


-- 
Ammar Faizi


  reply	other threads:[~2022-11-24 11:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24  8:00 [PATCH liburing v1 0/7] Ensure we mark internal functions and variables as static Ammar Faizi
2022-11-24  8:00 ` [PATCH liburing v1 1/7] liburing.h: Export `__io_uring_flush_sq()` function Ammar Faizi
2022-11-24 10:14   ` Dylan Yudaken
2022-11-24 11:47     ` Ammar Faizi [this message]
2022-11-24 13:27       ` Jens Axboe
2022-11-24  8:00 ` [PATCH liburing v1 2/7] test/io_uring_setup: Remove unused functions Ammar Faizi
2022-11-24  8:00 ` [PATCH liburing v1 3/7] ucontext-cp: Remove an unused function Ammar Faizi
2022-11-24  8:00 ` [PATCH liburing v1 4/7] tests: Mark internal functions as static Ammar Faizi
2022-11-24  8:01 ` [PATCH liburing v1 5/7] ucontext-cp: " Ammar Faizi
2022-11-24  8:01 ` [PATCH liburing v1 6/7] test/Makefile: Omit `-Wmissing-prototypes` from the C++ compiler flags Ammar Faizi
2022-11-24  8:01 ` [PATCH liburing v1 7/7] github: Add `-Wmissing-prototypes` for GitHub CI bot Ammar Faizi

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=b303bde6-91b1-2ea2-7b1d-e64546c8ae7f@gnuweeb.org \
    --to=ammarfaizi2@gnuweeb.org \
    --cc=alviro.iskandar@gnuweeb.org \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=dylany@meta.com \
    --cc=gilang4321@gmail.com \
    --cc=gwml@vger.gnuweeb.org \
    --cc=io-uring@vger.kernel.org \
    --cc=kernel@vnlx.org \
    --cc=kiizuha@gnuweeb.org \
    /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