HACK: Allow io_uring_submit batching just ahead of poll

Let's add a mode (enabled via the LIBOSMO_IO_URING_BATCH environment
variable), where we don't call io_uring_submit() after every operation
we add to the submission queue.  Rather, do that once before we go into
poll.

This should massively reduce the amount of io_uring_enter() syscalls
we're seeing.

Change-Id: Ia27ada909df246f21d110d8ae0b40229aacd579d
This commit is contained in:
Harald Welte 2024-03-19 21:30:25 +01:00
parent bd71e8eb15
commit 5215cb93e3
2 changed files with 18 additions and 2 deletions

View File

@ -60,6 +60,7 @@ struct osmo_io_uring {
};
static __thread struct osmo_io_uring g_ring;
static bool g_batch = false;
static void iofd_uring_cqe(struct io_uring *ring);
@ -90,6 +91,9 @@ void osmo_iofd_uring_init(void)
{
int rc, evfd;
if (getenv("LIBOSMO_IO_URING_BATCH"))
g_batch = true;
rc = io_uring_queue_init(IOFD_URING_ENTRIES, &g_ring.ring, 0);
if (rc < 0)
osmo_panic("failure during io_uring_queue_init(): %s\n", strerror(-rc));
@ -175,7 +179,8 @@ static void iofd_uring_submit_recv(struct osmo_io_fd *iofd, enum iofd_msg_action
}
io_uring_sqe_set_data(sqe, msghdr);
io_uring_submit(&g_ring.ring);
if (!g_batch)
io_uring_submit(&g_ring.ring);
/* NOTE: This only works if we have one read per fd */
iofd->u.uring.read_msghdr = msghdr;
}
@ -315,7 +320,8 @@ static int iofd_uring_submit_tx(struct osmo_io_fd *iofd)
OSMO_ASSERT(0);
}
io_uring_submit(&g_ring.ring);
if (!g_batch)
io_uring_submit(&g_ring.ring);
iofd->u.uring.write_msghdr = msghdr;
return 0;
@ -529,4 +535,10 @@ const struct iofd_backend_ops iofd_uring_ops = {
.notify_connected = iofd_uring_notify_connected,
};
void osmo_io_uring_submit(void)
{
if (g_batch)
io_uring_submit(&g_ring.ring);
}
#endif /* defined(__linux__) */

View File

@ -426,12 +426,16 @@ static int poll_disp_fds(unsigned int n_fd)
return work;
}
void osmo_io_uring_submit(void);
static int _osmo_select_main(int polling)
{
unsigned int n_poll;
int rc;
int timeout = 0;
osmo_io_uring_submit();
/* prepare read and write fdsets */
n_poll = poll_fill_fds();