laforge has uploaded this change for review.

View Change

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
---
M src/core/osmo_io_uring.c
M src/core/select.c
2 files changed, 35 insertions(+), 2 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/64/36364/1
diff --git a/src/core/osmo_io_uring.c b/src/core/osmo_io_uring.c
index 569f150..6801eb4 100644
--- a/src/core/osmo_io_uring.c
+++ b/src/core/osmo_io_uring.c
@@ -60,6 +60,7 @@
};

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 @@
{
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 @@
}
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 @@
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 @@
.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 70047f0..0a4302f 100644
--- a/src/core/select.c
+++ b/src/core/select.c
@@ -426,12 +426,16 @@
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();


To view, visit change 36364. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ia27ada909df246f21d110d8ae0b40229aacd579d
Gerrit-Change-Number: 36364
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-MessageType: newchange