pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/42083?usp=email )


Change subject: osmo_io_uring: Split global init from per-thread init
......................................................................

osmo_io_uring: Split global init from per-thread init

osmo_iofd_init() is expected to be called per-thread, while some code in
osmo_iofd_uring_init() was only expected to be called once.

Change-Id: Ifa5c46d7532ea49869f3cfe7268fdd082906fd10
---
M src/core/osmo_io.c
M src/core/osmo_io_internal.h
M src/core/osmo_io_uring.c
3 files changed, 19 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/83/42083/1

diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index e7645cb..9e159a1 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -101,6 +101,7 @@
        } else if (!strcmp("IO_URING", backend)) {
                g_io_backend = OSMO_IO_BACKEND_IO_URING;
                osmo_iofd_ops = iofd_uring_ops;
+               osmo_iofd_uring_constructor();
 #endif
        } else {
                fprintf(stderr, "Invalid osmo_io backend requested: 
\"%s\"\nCheck the environment variable %s\n", backend, OSMO_IO_BACKEND_ENV);
diff --git a/src/core/osmo_io_internal.h b/src/core/osmo_io_internal.h
index 6b642b9..81a70f3 100644
--- a/src/core/osmo_io_internal.h
+++ b/src/core/osmo_io_internal.h
@@ -21,6 +21,7 @@

 #if defined(HAVE_URING)
 extern const struct iofd_backend_ops iofd_uring_ops;
+void osmo_iofd_uring_constructor(void);
 void osmo_iofd_uring_init(void);
 #endif

diff --git a/src/core/osmo_io_uring.c b/src/core/osmo_io_uring.c
index 3925f94..6ae21cf 100644
--- a/src/core/osmo_io_uring.c
+++ b/src/core/osmo_io_uring.c
@@ -107,15 +107,15 @@
 }

 /*! initialize the uring and tie it into our event loop */
-void osmo_iofd_uring_init(void)
+void osmo_iofd_uring_constructor(void)
 {
        const char *env;
-       int rc, evfd;
+       int rc;

        if ((env = getenv(OSMO_IO_URING_BATCH)))
                g_io_uring_batch = true;

-       if (!g_ring && (env = getenv(OSMO_IO_URING_INITIAL_SIZE))) {
+       if ((env = getenv(OSMO_IO_URING_INITIAL_SIZE))) {
                int env_value;
                rc = osmo_str_to_int(&env_value, env, 10, 1, 
IOFD_URING_MAXIMUM_SIZE);
                if (rc < 0) {
@@ -130,13 +130,6 @@
                g_io_uring_size = env_value;
        }

-       g_ring = talloc_zero(OTC_GLOBAL, struct osmo_io_uring);
-       INIT_LLIST_HEAD(&g_ring->cancel_queue);
-
-       rc = io_uring_queue_init(g_io_uring_size, &g_ring->ring, 0);
-       if (rc < 0)
-               osmo_panic("failure during io_uring_queue_init(): %s\n", 
strerror(-rc));
-
        if ((env = getenv(OSMO_IO_URING_READ_SQE))) {
                g_io_uring_read_sqes = atoi(env);
                if (g_io_uring_read_sqes < 1 || g_io_uring_read_sqes > 
IOFD_MSGHDR_MAX_READ_SQES) {
@@ -145,6 +138,20 @@
                        exit(1);
                }
        }
+}
+
+/*! Per-thread: initialize the uring and tie it into our event loop */
+void osmo_iofd_uring_init(void)
+{
+       int rc, evfd;
+
+       g_ring = talloc_zero(OTC_GLOBAL, struct osmo_io_uring);
+       OSMO_ASSERT(g_ring);
+       INIT_LLIST_HEAD(&g_ring->cancel_queue);
+
+       rc = io_uring_queue_init(g_io_uring_size, &g_ring->ring, 0);
+       if (rc < 0)
+               osmo_panic("failure during io_uring_queue_init(): %s\n", 
strerror(-rc));

        rc = eventfd(0, 0);
        if (rc < 0) {

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/42083?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ifa5c46d7532ea49869f3cfe7268fdd082906fd10
Gerrit-Change-Number: 42083
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>

Reply via email to