summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-09-26 00:38:30 -0600
committerJens Axboe <axboe@kernel.dk>2019-09-26 00:38:30 -0600
commit1148b7e3f1afb004d3ccf8bbf77ca36960b4e6e2 (patch)
treed877b5fe9c8093771105d23e0b042de8b632338a /src
parent4e360f71131918c36774f51688e5c65dea8d43f2 (diff)
parent0b88d72b1a4bbf0a90da2067f489fbb788dc1e92 (diff)
downloadliburing-1148b7e3f1afb004d3ccf8bbf77ca36960b4e6e2.tar.gz
liburing-1148b7e3f1afb004d3ccf8bbf77ca36960b4e6e2.tar.bz2
Merge branch 'cqe_batch_get' of https://github.com/rouzier/liburing
* 'cqe_batch_get' of https://github.com/rouzier/liburing: Add io_uring_peek_batch_cqe() Add io_uring_cq_ready()
Diffstat (limited to 'src')
-rw-r--r--src/include/liburing.h7
-rw-r--r--src/queue.c23
2 files changed, 30 insertions, 0 deletions
diff --git a/src/include/liburing.h b/src/include/liburing.h
index cfce895..6367307 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -72,6 +72,8 @@ extern int io_uring_queue_mmap(int fd, struct io_uring_params *p,
extern void io_uring_queue_exit(struct io_uring *ring);
extern int io_uring_peek_cqe(struct io_uring *ring,
struct io_uring_cqe **cqe_ptr);
+unsigned io_uring_peek_batch_cqe(struct io_uring *ring,
+ struct io_uring_cqe **cqes, unsigned count);
extern int io_uring_wait_cqe(struct io_uring *ring,
struct io_uring_cqe **cqe_ptr);
extern int io_uring_wait_cqes_timeout(struct io_uring *ring,
@@ -248,6 +250,11 @@ static inline unsigned io_uring_sq_space_left(struct io_uring *ring)
return *ring->sq.kring_entries - (ring->sq.sqe_tail - ring->sq.sqe_head);
}
+static inline unsigned io_uring_cq_ready(struct io_uring *ring)
+{
+ return io_uring_smp_load_acquire(ring->cq.ktail) - *ring->cq.khead;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/src/queue.c b/src/queue.c
index 18040d5..470c3a2 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -53,6 +53,29 @@ int io_uring_peek_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr)
}
/*
+ * Fill in an array of IO completions up to count, if any are available.
+ * Returns the amount of IO completions filled.
+ */
+unsigned io_uring_peek_batch_cqe(struct io_uring *ring, struct io_uring_cqe **cqes, unsigned count)
+{
+ unsigned ready = io_uring_cq_ready(ring);
+ if (ready) {
+ count = count > ready ? ready : count;
+ unsigned head = *ring->cq.khead;
+ unsigned last = head + count;
+ unsigned mask = *ring->cq.kring_mask;
+ int i = 0;
+ for (;head!=last;head++,i++) {
+ cqes[i] = &ring->cq.cqes[head & mask];
+ }
+
+ return count;
+ }
+
+ return 0;
+}
+
+/*
* Return an IO completion, waiting for it if necessary. Returns 0 with
* cqe_ptr filled in on success, -errno on failure.
*/