Browse Source

MT#55283 centralise uring methods

Introduce struct to keep uring-specific thread-local method pointers

Change-Id: I7b0d1fd82cf5f3d114e8072553cb74054ac7e133
pull/1923/head
Richard Fuchs 9 months ago
parent
commit
dd91f0ec11
10 changed files with 24 additions and 27 deletions
  1. +1
    -1
      daemon/helpers.c
  2. +1
    -1
      daemon/main.c
  3. +1
    -1
      daemon/media_player.c
  4. +1
    -1
      daemon/stun.c
  5. +2
    -1
      daemon/timerthread.c
  6. +1
    -9
      lib/poller.c
  7. +0
    -7
      lib/poller.h
  8. +9
    -3
      lib/uring.c
  9. +7
    -2
      lib/uring.h
  10. +1
    -1
      perf-tester/Makefile

+ 1
- 1
daemon/helpers.c View File

@ -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;


+ 1
- 1
daemon/main.c View File

@ -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


+ 1
- 1
daemon/media_player.c View File

@ -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


+ 1
- 1
daemon/stun.c View File

@ -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;
}

+ 2
- 1
daemon/timerthread.c View File

@ -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;


+ 1
- 9
lib/poller.c View File

@ -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);


+ 0
- 7
lib/poller.h View File

@ -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

+ 9
- 3
lib/uring.c View File

@ -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) {


+ 7
- 2
lib/uring.h View File

@ -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);


+ 1
- 1
perf-tester/Makefile View File

@ -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)


Loading…
Cancel
Save