From fd92d76f0a44af814d61b36c12c150aaadcfcb6d Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 27 Feb 2017 14:52:38 +0200 Subject: [PATCH] Avoid accessing tls data The thread id is copied to a local variable to avoid having __tls_get_addr from unnecessarily being called over and over again. Together that used to amount to some 1% of the execution time. --- server/core/poll.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/core/poll.c b/server/core/poll.c index 1b0bd729a..45bafd917 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -94,7 +94,7 @@ typedef struct fake_event struct fake_event *next; /*< The next event */ } fake_event_t; -thread_local int thread_id; /**< This thread's ID */ +thread_local int current_thread_id; /**< This thread's ID */ static int *epoll_fd; /*< The epoll file descriptor */ static int next_epoll_fd = 0; /*< Which thread handles the next DCB */ static fake_event_t **fake_events; /*< Thread-specific fake event queue */ @@ -653,9 +653,11 @@ poll_waitevents(void *arg) { struct epoll_event events[MAX_EVENTS]; int i, nfds, timeout_bias = 1; - thread_id = (intptr_t)arg; + current_thread_id = (intptr_t)arg; int poll_spins = 0; + int thread_id = current_thread_id; + if (thread_data) { thread_data[thread_id].state = THREAD_IDLE; @@ -1635,7 +1637,7 @@ void poll_send_message(enum poll_message msg, void *data) for (int i = 0; i < nthr; i++) { - if (i != thread_id) + if (i != current_thread_id) { while (poll_msg[i] & msg) { @@ -1650,6 +1652,8 @@ void poll_send_message(enum poll_message msg, void *data) static void poll_check_message() { + int thread_id = current_thread_id; + if (poll_msg[thread_id] & POLL_MSG_CLEAN_PERSISTENT) { SERVER *server = (SERVER*)poll_msg_data;