All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Ammar Faizi <ammarfaizi2@gnuweeb.org>,
	Nugra <richiisei@gmail.com>,
	Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
	GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>,
	Tea Inside Mailing List <timl@vger.teainside.org>,
	io-uring Mailing List <io-uring@vger.kernel.org>
Subject: [PATCH liburing v2] queue, liburing.h: Avoid `io_uring_get_sqe()` code duplication
Date: Fri, 25 Feb 2022 07:58:14 +0700	[thread overview]
Message-ID: <20220225005814.146492-1-ammarfaizi2@gnuweeb.org> (raw)

Since commit 8be8af4afcb4909104c ("queue: provide io_uring_get_sqe()
symbol again"), we have the same definition of `io_uring_get_sqe()` in
queue.c and liburing.h.

Make it simpler, maintain it in a single place, create a new static
inline function wrapper with name `_io_uring_get_sqe()`. Then tail
call both `io_uring_get_sqe()` functions to `_io_uring_get_sqe()`.

Cc: Nugra <richiisei@gmail.com>
Cc: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
Cc: GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>
Cc: Tea Inside Mailing List <timl@vger.teainside.org>
Cc: io-uring Mailing List <io-uring@vger.kernel.org>
Link: https://lore.kernel.org/io-uring/20220225002852.111521-1-ammarfaizi2@gnuweeb.org # v1
Reviewed-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
Tested-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
---

  v2:
    - Address a comment from Alviro (fix typo).
    - Append Reviewed-by and Tested-by tag from Alviro.

 src/include/liburing.h |  9 +++++++--
 src/queue.c            | 11 +----------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/include/liburing.h b/src/include/liburing.h
index 590fe7f..ef5a4cd 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -831,8 +831,7 @@ static inline int io_uring_wait_cqe(struct io_uring *ring,
  *
  * Returns a vacant sqe, or NULL if we're full.
  */
-#ifndef LIBURING_INTERNAL
-static inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
+static inline struct io_uring_sqe *_io_uring_get_sqe(struct io_uring *ring)
 {
 	struct io_uring_sq *sq = &ring->sq;
 	unsigned int head = io_uring_smp_load_acquire(sq->khead);
@@ -845,6 +844,12 @@ static inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
 	}
 	return sqe;
 }
+
+#ifndef LIBURING_INTERNAL
+static inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
+{
+	return _io_uring_get_sqe(ring);
+}
 #else
 struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring);
 #endif
diff --git a/src/queue.c b/src/queue.c
index 6b63490..f9b6c86 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -405,16 +405,7 @@ int io_uring_submit_and_wait(struct io_uring *ring, unsigned wait_nr)
 
 struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)
 {
-	struct io_uring_sq *sq = &ring->sq;
-	unsigned int head = io_uring_smp_load_acquire(sq->khead);
-	unsigned int next = sq->sqe_tail + 1;
-	struct io_uring_sqe *sqe = NULL;
-
-	if (next - head <= *sq->kring_entries) {
-		sqe = &sq->sqes[sq->sqe_tail & *sq->kring_mask];
-		sq->sqe_tail = next;
-	}
-	return sqe;
+	return _io_uring_get_sqe(ring);
 }
 
 int __io_uring_sqring_wait(struct io_uring *ring)

base-commit: 868be37473052893b68a8586d45a750980be4329
-- 
2.32.0


             reply	other threads:[~2022-02-25  0:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-25  0:58 Ammar Faizi [this message]
2022-02-25 14:16 ` [PATCH liburing v2] queue, liburing.h: Avoid `io_uring_get_sqe()` code duplication Jens Axboe

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=20220225005814.146492-1-ammarfaizi2@gnuweeb.org \
    --to=ammarfaizi2@gnuweeb.org \
    --cc=alviro.iskandar@gnuweeb.org \
    --cc=axboe@kernel.dk \
    --cc=gwml@vger.gnuweeb.org \
    --cc=io-uring@vger.kernel.org \
    --cc=richiisei@gmail.com \
    --cc=timl@vger.teainside.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.