aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2024-03-19 21:30:25 +0100
committerHarald Welte <laforge@osmocom.org>2024-03-20 19:03:15 +0100
commit548d2cddeb3c1c7e442aae15c1078a2142a00701 (patch)
tree8093a55b851a33c2e0ddadfedd26dc4820b2c9a9
parentc6f6b166e1b10f9569b93996ed959d48f6be7a53 (diff)
HACK: Allow io_uring_submit batching just ahead of polllaforge/io_uring_batch
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
-rw-r--r--src/core/osmo_io_uring.c16
-rw-r--r--src/core/select.c4
2 files changed, 18 insertions, 2 deletions
diff --git a/src/core/osmo_io_uring.c b/src/core/osmo_io_uring.c
index 569f1505..6801eb4f 100644
--- a/src/core/osmo_io_uring.c
+++ b/src/core/osmo_io_uring.c
@@ -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__) */
diff --git a/src/core/select.c b/src/core/select.c
index 70047f09..0a4302f2 100644
--- a/src/core/select.c
+++ b/src/core/select.c
@@ -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();