From dd91f0ec11d1d8989bf4657cd831d8b68281b3e7 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 28 Mar 2025 09:55:01 -0400 Subject: [PATCH] MT#55283 centralise uring methods Introduce struct to keep uring-specific thread-local method pointers Change-Id: I7b0d1fd82cf5f3d114e8072553cb74054ac7e133 --- daemon/helpers.c | 2 +- daemon/main.c | 2 +- daemon/media_player.c | 2 +- daemon/stun.c | 2 +- daemon/timerthread.c | 3 ++- lib/poller.c | 10 +--------- lib/poller.h | 7 ------- lib/uring.c | 12 +++++++++--- lib/uring.h | 9 +++++++-- perf-tester/Makefile | 2 +- 10 files changed, 24 insertions(+), 27 deletions(-) diff --git a/daemon/helpers.c b/daemon/helpers.c index 557bd9219..f2f294e5d 100644 --- a/daemon/helpers.c +++ b/daemon/helpers.c @@ -304,7 +304,7 @@ static void thread_looper_helper(void *fp) { enum thread_looper_action ret = lh.f(); - uring_thread_loop(); + uring_methods.thread_loop(); if (ret == TLA_BREAK) break; diff --git a/daemon/main.c b/daemon/main.c index 4af97b845..8890b2d3d 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1473,7 +1473,7 @@ static void clib_cleanup(void) { #endif } static void clib_loop(void) { - uring_thread_loop(); + uring_methods.thread_loop(); append_thread_lpr_to_glob_lpr(); } #endif diff --git a/daemon/media_player.c b/daemon/media_player.c index 0ebaeafd0..43470c58e 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -366,7 +366,7 @@ static bool __send_timer_send_1(struct rtp_header *rh, struct packet_stream *sin .msg_iovlen = 1, }; req->buf = bufferpool_ref(cp->s.s); - uring_sendmsg(&sink_fd->socket, &req->msg, &sink->endpoint, &req->sin, &req->req); + uring_methods.sendmsg(&sink_fd->socket, &req->msg, &sink->endpoint, &req->sin, &req->req); if (sink->call->recording && rtpe_config.rec_egress) { // fill in required members diff --git a/daemon/stun.c b/daemon/stun.c index df429b443..0644e9241 100644 --- a/daemon/stun.c +++ b/daemon/stun.c @@ -709,7 +709,7 @@ int stun_binding_request(const endpoint_t *dst, uint32_t transaction[3], str *pw fingerprint(&r->mh, &r->fp); output_finish_src(&r->mh); - uring_sendmsg(sock, &r->mh, dst, &r->sin, &r->req); + uring_methods.sendmsg(sock, &r->mh, dst, &r->sin, &r->req); return 0; } diff --git a/daemon/timerthread.c b/daemon/timerthread.c index 58f1139d4..6cf4aee78 100644 --- a/daemon/timerthread.c +++ b/daemon/timerthread.c @@ -4,6 +4,7 @@ #include "log_funcs.h" #include "poller.h" #include "main.h" +#include "uring.h" static int tt_obj_cmp(const void *a, const void *b) { @@ -97,7 +98,7 @@ static void timerthread_run(void *p) { obj_put(tt_obj); log_info_reset(); - uring_thread_loop(); + uring_methods.thread_loop(); mutex_lock(&tt->lock); continue; diff --git a/lib/poller.c b/lib/poller.c index 34d263af5..9af36d4be 100644 --- a/lib/poller.c +++ b/lib/poller.c @@ -299,14 +299,6 @@ void poller_error(struct poller *p, void *fdp) { it->blocked = 1; } -#ifdef HAVE_LIBURING - -static unsigned int __uring_thread_loop_dummy(void) { return 0; } - -__thread unsigned int (*uring_thread_loop)(void) = __uring_thread_loop_dummy; - -#endif - bool poller_isblocked(struct poller *p, void *fdp) { int fd = GPOINTER_TO_INT(fdp); int ret; @@ -344,7 +336,7 @@ void poller_loop(void *d) { int ret = poller_poll(p, thread_sleep_time, evs, poller_size); if (ret < 0) usleep(20 * 1000); - uring_thread_loop(); + uring_methods.thread_loop(); } thread_cleanup_pop(true); diff --git a/lib/poller.h b/lib/poller.h index 5a91f3c1e..77bbdf8e4 100644 --- a/lib/poller.h +++ b/lib/poller.h @@ -56,11 +56,4 @@ extern bool (*rtpe_poller_isblocked)(struct poller *, void *); extern void (*rtpe_poller_error)(struct poller *, void *); -#ifdef HAVE_LIBURING -extern __thread unsigned int (*uring_thread_loop)(void); -#else -INLINE unsigned int uring_thread_loop(void) { return 0; } -#endif - - #endif diff --git a/lib/uring.c b/lib/uring.c index b75a528c4..3d658ab64 100644 --- a/lib/uring.c +++ b/lib/uring.c @@ -54,9 +54,15 @@ static ssize_t __socket_sendmsg(socket_t *s, struct msghdr *m, const endpoint_t r->handler(r, 0, 0); return ret; } +static unsigned int __dummy_thread_loop(void) { + return 0; +} -__thread __typeof(__socket_sendmsg) (*uring_sendmsg) = __socket_sendmsg; +__thread struct uring_methods uring_methods = { + .sendmsg = __socket_sendmsg, + .thread_loop = __dummy_thread_loop, +}; #ifdef HAVE_LIBURING @@ -107,8 +113,8 @@ void uring_thread_init(void) { if (ret) die("io_uring init failed (%s)", strerror(errno)); - uring_sendmsg = __uring_sendmsg; - uring_thread_loop = __uring_thread_loop; + uring_methods.sendmsg = __uring_sendmsg; + uring_methods.thread_loop = __uring_thread_loop; } void uring_thread_cleanup(void) { diff --git a/lib/uring.h b/lib/uring.h index 5de045e83..ed2d88dda 100644 --- a/lib/uring.h +++ b/lib/uring.h @@ -11,8 +11,13 @@ struct uring_req { uring_req_handler_fn *handler; }; -extern __thread ssize_t (*uring_sendmsg)(socket_t *, struct msghdr *, const endpoint_t *, - struct sockaddr_storage *, struct uring_req *); +struct uring_methods { + ssize_t (*sendmsg)(socket_t *, struct msghdr *, const endpoint_t *, + struct sockaddr_storage *, struct uring_req *); + unsigned int (*thread_loop)(void); +}; + +extern __thread struct uring_methods uring_methods; INLINE void uring_req_buffer_free(struct uring_req *r, int32_t res, uint32_t flags) { g_free(r); diff --git a/perf-tester/Makefile b/perf-tester/Makefile index e97a017b0..b75debc0b 100644 --- a/perf-tester/Makefile +++ b/perf-tester/Makefile @@ -55,7 +55,7 @@ LDLIBS += $(LDLIBS_CODEC_CHAIN) SRCS = main.c log.c LIBSRCS = codeclib.strhash.c loglib.c auxlib.c resample.c str.c dtmflib.c rtplib.c poller.c ssllib.c bufferpool.c \ - bencode.c + bencode.c uring.c LIBASM = mvr2s_x64_avx2.S mvr2s_x64_avx512.S OBJS = $(SRCS:.c=.o) $(LIBSRCS:.c=.o) $(LIBASM:.S=.o)