Tea Inside Mailing List <[email protected]>
 help / color / mirror / Atom feed
* [PATCH liburing v1] queue, liburing.h: Avoid `io_uring_get_sqe()` code duplication
@ 2022-02-25  0:28 Ammar Faizi
  2022-02-25  0:46 ` Alviro Iskandar Setiawan
  0 siblings, 1 reply; 3+ messages in thread
From: Ammar Faizi @ 2022-02-25  0:28 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Ammar Faizi, Nugra, Alviro Iskandar Setiawan,
	GNU/Weeb Mailing List, Tea Inside Mailing List,
	io-uring Mailing List

Since commit 8be8af4afcb4909104c ("queue: provide io_uring_get_sqe()
symbol again"), we have the same defintion 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 <[email protected]>
Cc: Alviro Iskandar Setiawan <[email protected]>
Cc: GNU/Weeb Mailing List <[email protected]>
Cc: Tea Inside Mailing List <[email protected]>
Cc: io-uring Mailing List <[email protected]>
Signed-off-by: Ammar Faizi <[email protected]>
---
 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: 896a1d3ab14a8777a45db6e7b67cf557a44923fb
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH liburing v1] queue, liburing.h: Avoid `io_uring_get_sqe()` code duplication
  2022-02-25  0:28 [PATCH liburing v1] queue, liburing.h: Avoid `io_uring_get_sqe()` code duplication Ammar Faizi
@ 2022-02-25  0:46 ` Alviro Iskandar Setiawan
  2022-02-25  0:51   ` Ammar Faizi
  0 siblings, 1 reply; 3+ messages in thread
From: Alviro Iskandar Setiawan @ 2022-02-25  0:46 UTC (permalink / raw)
  To: Ammar Faizi
  Cc: Jens Axboe, Nugra, GNU/Weeb Mailing List,
	Tea Inside Mailing List, io-uring Mailing List

On Fri, Feb 25, 2022 at 7:29 AM Ammar Faizi <[email protected]> wrote:
>
> Since commit 8be8af4afcb4909104c ("queue: provide io_uring_get_sqe()
> symbol again"), we have the same defintion of `io_uring_get_sqe()` in

Typo
/s/defintion/definition/

with that fixed

Reviewed-by: Alviro Iskandar Setiawan <[email protected]>

> 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()`.
>

Also, I tested this, the fpos test failed. Maybe it needs the recent
kernel fixes? So I assume everything is fine.

  Tests timed out:  <rsrc_tags>
  Tests failed:  <fpos>

  [viro@freezing ~/liburing]$ test/fpos
  inconsistent reads, got 0s:8192 1s:6144
  f_pos incorrect, expected 14336 have 7
  failed read async=0 blocksize=7

Tested-by: Alviro Iskandar Setiawan <[email protected]>

-- Viro

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH liburing v1] queue, liburing.h: Avoid `io_uring_get_sqe()` code duplication
  2022-02-25  0:46 ` Alviro Iskandar Setiawan
@ 2022-02-25  0:51   ` Ammar Faizi
  0 siblings, 0 replies; 3+ messages in thread
From: Ammar Faizi @ 2022-02-25  0:51 UTC (permalink / raw)
  To: Alviro Iskandar Setiawan
  Cc: Jens Axboe, Nugra, GNU/Weeb Mailing List,
	Tea Inside Mailing List, io-uring Mailing List

On 2/25/22 7:46 AM, Alviro Iskandar Setiawan wrote:
> On Fri, Feb 25, 2022 at 7:29 AM Ammar Faizi <[email protected]> wrote:
>>
>> Since commit 8be8af4afcb4909104c ("queue: provide io_uring_get_sqe()
>> symbol again"), we have the same defintion of `io_uring_get_sqe()` in
> 
> Typo
> /s/defintion/definition/
> 
> with that fixed
> 
> Reviewed-by: Alviro Iskandar Setiawan <[email protected]>
> 
>> 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()`.
>>
> 
> Also, I tested this, the fpos test failed. Maybe it needs the recent
> kernel fixes? So I assume everything is fine.
> 
>    Tests timed out:  <rsrc_tags>
>    Tests failed:  <fpos>
> 
>    [viro@freezing ~/liburing]$ test/fpos
>    inconsistent reads, got 0s:8192 1s:6144
>    f_pos incorrect, expected 14336 have 7
>    failed read async=0 blocksize=7
> 
> Tested-by: Alviro Iskandar Setiawan <[email protected]>

Thanks for reviewing and testing. I will fix it and append those tags and
in the v2.

-- 
Ammar Faizi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-25  0:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25  0:28 [PATCH liburing v1] queue, liburing.h: Avoid `io_uring_get_sqe()` code duplication Ammar Faizi
2022-02-25  0:46 ` Alviro Iskandar Setiawan
2022-02-25  0:51   ` Ammar Faizi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox