io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] io_uring_peek_batch_cqe should also check cq ring overflow
@ 2020-07-09  7:33 Xiaoguang Wang
  2020-07-09 14:18 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaoguang Wang @ 2020-07-09  7:33 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, joseph.qi, Xiaoguang Wang

In io_uring_peek_batch_cqe(), if the first peek could not find any
cqes, we check cq ring overflow, and if cq ring has been overflowed,
enter kernel to flush cqes, and do the second peek.

Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
---
 src/queue.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/queue.c b/src/queue.c
index 1f00251..be80d7a 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -125,7 +125,9 @@ unsigned io_uring_peek_batch_cqe(struct io_uring *ring,
 				 struct io_uring_cqe **cqes, unsigned count)
 {
 	unsigned ready;
+	bool overflow_checked = false;
 
+again:
 	ready = io_uring_cq_ready(ring);
 	if (ready) {
 		unsigned head = *ring->cq.khead;
@@ -141,6 +143,17 @@ unsigned io_uring_peek_batch_cqe(struct io_uring *ring,
 		return count;
 	}
 
+	if (overflow_checked)
+		goto done;
+
+	if (cq_ring_needs_flush(ring)) {
+		__sys_io_uring_enter(ring->ring_fd, 0, 0,
+				     IORING_ENTER_GETEVENTS, NULL);
+		overflow_checked = true;
+		goto again;
+	}
+
+done:
 	return 0;
 }
 
-- 
2.17.2


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

* Re: [PATCH] io_uring_peek_batch_cqe should also check cq ring overflow
  2020-07-09  7:33 [PATCH] io_uring_peek_batch_cqe should also check cq ring overflow Xiaoguang Wang
@ 2020-07-09 14:18 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2020-07-09 14:18 UTC (permalink / raw)
  To: Xiaoguang Wang, io-uring; +Cc: joseph.qi

On 7/9/20 1:33 AM, Xiaoguang Wang wrote:
> In io_uring_peek_batch_cqe(), if the first peek could not find any
> cqes, we check cq ring overflow, and if cq ring has been overflowed,
> enter kernel to flush cqes, and do the second peek.

Applied, thanks.

-- 
Jens Axboe


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

end of thread, other threads:[~2020-07-09 14:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-09  7:33 [PATCH] io_uring_peek_batch_cqe should also check cq ring overflow Xiaoguang Wang
2020-07-09 14:18 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).