Skip to content

Commit

Permalink
lib: turn INT_FLAG_REG_RING into masked flag
Browse files Browse the repository at this point in the history
If INT_FLAG_REG_RING matches IORING_ENTER_REGISTERED_RING, then it's
possible to drop the branches around masking in this value for every
io_uring_enter(2) system call.

This also allows for doing the same with future flags, where it would
be beneficial to have them set for each invocation, without needing
to add branches for that.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
axboe committed Oct 14, 2024
1 parent 2fe16b1 commit cd87073
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
13 changes: 10 additions & 3 deletions src/int_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
#ifndef LIBURING_INT_FLAGS
#define LIBURING_INT_FLAGS

#define INT_FLAGS_MASK (IORING_ENTER_REGISTERED_RING)

enum {
INT_FLAG_REG_RING = 1,
INT_FLAG_REG_REG_RING = 2,
INT_FLAG_APP_MEM = 4,
INT_FLAG_REG_RING = IORING_ENTER_REGISTERED_RING,
INT_FLAG_REG_REG_RING = 1,
INT_FLAG_APP_MEM = 2,
};

static inline int ring_enter_flags(struct io_uring *ring)
{
return ring->int_flags & INT_FLAGS_MASK;
}

#endif
20 changes: 5 additions & 15 deletions src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int _io_uring_get_cqe(struct io_uring *ring,

do {
bool need_enter = false;
unsigned flags = 0;
unsigned flags = ring_enter_flags(ring);
unsigned nr_available;
int ret;

Expand All @@ -94,7 +94,7 @@ static int _io_uring_get_cqe(struct io_uring *ring,
need_enter = true;
}
if (data->wait_nr > nr_available || need_enter) {
flags = IORING_ENTER_GETEVENTS | data->get_flags;
flags |= IORING_ENTER_GETEVENTS | data->get_flags;
need_enter = true;
}
if (sq_ring_needs_enter(ring, data->submit, &flags))
Expand All @@ -109,8 +109,6 @@ static int _io_uring_get_cqe(struct io_uring *ring,
break;
}

if (ring->int_flags & INT_FLAG_REG_RING)
flags |= IORING_ENTER_REGISTERED_RING;
ret = __sys_io_uring_enter2(ring->enter_ring_fd, data->submit,
data->wait_nr, flags, data->arg,
data->sz);
Expand Down Expand Up @@ -149,10 +147,8 @@ int __io_uring_get_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr,

int io_uring_get_events(struct io_uring *ring)
{
int flags = IORING_ENTER_GETEVENTS;
int flags = IORING_ENTER_GETEVENTS | ring_enter_flags(ring);

if (ring->int_flags & INT_FLAG_REG_RING)
flags |= IORING_ENTER_REGISTERED_RING;
return __sys_io_uring_enter(ring->enter_ring_fd, 0, 0, flags, NULL);
}

Expand Down Expand Up @@ -403,17 +399,14 @@ static int __io_uring_submit(struct io_uring *ring, unsigned submitted,
unsigned wait_nr, bool getevents)
{
bool cq_needs_enter = getevents || wait_nr || cq_ring_needs_enter(ring);
unsigned flags;
unsigned flags = ring_enter_flags(ring);
int ret;

liburing_sanitize_ring(ring);

flags = 0;
if (sq_ring_needs_enter(ring, submitted, &flags) || cq_needs_enter) {
if (cq_needs_enter)
flags |= IORING_ENTER_GETEVENTS;
if (ring->int_flags & INT_FLAG_REG_RING)
flags |= IORING_ENTER_REGISTERED_RING;

ret = __sys_io_uring_enter(ring->enter_ring_fd, submitted,
wait_nr, flags, NULL);
Expand Down Expand Up @@ -462,10 +455,7 @@ struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring)

int __io_uring_sqring_wait(struct io_uring *ring)
{
int flags = IORING_ENTER_SQ_WAIT;

if (ring->int_flags & INT_FLAG_REG_RING)
flags |= IORING_ENTER_REGISTERED_RING;
int flags = IORING_ENTER_SQ_WAIT | ring_enter_flags(ring);

return __sys_io_uring_enter(ring->enter_ring_fd, 0, 0, flags, NULL);
}

0 comments on commit cd87073

Please sign in to comment.