Optimize do_register by combining feature check with internal flag
Introduce the new internal flag INT_FLAG_REG_REG_RING, set when setting
INT_FLAG_REG_RING if the kernel supports IORING_FEAT_REG_REG_RING. This
allows all the register functions to just check INT_FLAG_REG_REG_RING.
Suggested-by: Dylan Yudaken <dylany@meta.com>
Signed-off-by: Josh Triplett <josh@joshtriplett.org>
diff --git a/src/int_flags.h b/src/int_flags.h
index 90505ec..71774fb 100644
--- a/src/int_flags.h
+++ b/src/int_flags.h
@@ -4,6 +4,7 @@
enum {
INT_FLAG_REG_RING = 1,
+ INT_FLAG_REG_REG_RING = 2,
};
#endif
diff --git a/src/register.c b/src/register.c
index b6d3979..a3fcc78 100644
--- a/src/register.c
+++ b/src/register.c
@@ -11,8 +11,7 @@
static inline int do_register(struct io_uring *ring, unsigned int opcode,
const void *arg, unsigned int nr_args)
{
- if (ring->features & IORING_FEAT_REG_REG_RING
- && ring->int_flags & INT_FLAG_REG_RING) {
+ if (ring->int_flags & INT_FLAG_REG_REG_RING) {
opcode |= IORING_REGISTER_USE_REGISTERED_RING;
return __sys_io_uring_register(ring->enter_ring_fd, opcode, arg, nr_args);
}
@@ -268,6 +267,9 @@
if (ret == 1) {
ring->enter_ring_fd = up.offset;
ring->int_flags |= INT_FLAG_REG_RING;
+ if (ring->features & IORING_FEAT_REG_REG_RING) {
+ ring->int_flags |= INT_FLAG_REG_REG_RING;
+ }
}
return ret;
}
@@ -286,7 +288,7 @@
ret = do_register(ring, IORING_UNREGISTER_RING_FDS, &up, 1);
if (ret == 1) {
ring->enter_ring_fd = ring->ring_fd;
- ring->int_flags &= ~INT_FLAG_REG_RING;
+ ring->int_flags &= ~(INT_FLAG_REG_RING | INT_FLAG_REG_REG_RING);
}
return ret;
}