From 8323a375bc1e78b8078674b45b967687a7752005 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 20 May 2019 18:57:53 +0200 Subject: [PATCH] MINOR: threads: add a thread-local thread_info pointer "ti" Since we're likely to access this thread_info struct more frequently in the future, let's reserve the thread-local symbol to access it directly and avoid always having to combine thread_info and tid. This pointer is set when tid is set. --- include/common/hathreads.h | 5 +++++ src/haproxy.c | 4 ++-- src/hathreads.c | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/common/hathreads.h b/include/common/hathreads.h index 6c420dd3f..b3c45641f 100644 --- a/include/common/hathreads.h +++ b/include/common/hathreads.h @@ -56,6 +56,8 @@ extern struct thread_info { char __end[0] __attribute__((aligned(64))); } thread_info[MAX_THREADS]; +extern THREAD_LOCAL struct thread_info *ti; /* thread_info for the current thread */ + #define __decl_hathreads(decl) #define __decl_spinlock(lock) #define __decl_aligned_spinlock(lock) @@ -140,6 +142,7 @@ extern struct thread_info { static inline void ha_set_tid(unsigned int tid) { + ti = &thread_info[tid]; } static inline void ha_thread_relax(void) @@ -386,6 +389,7 @@ extern struct thread_info { extern THREAD_LOCAL unsigned int tid; /* The thread id */ extern THREAD_LOCAL unsigned long tid_bit; /* The bit corresponding to the thread id */ +extern THREAD_LOCAL struct thread_info *ti; /* thread_info for the current thread */ extern volatile unsigned long all_threads_mask; extern volatile unsigned long threads_want_rdv_mask; extern volatile unsigned long threads_harmless_mask; @@ -416,6 +420,7 @@ static inline void ha_set_tid(unsigned int data) { tid = data; tid_bit = (1UL << tid); + ti = &thread_info[tid]; } static inline void ha_thread_relax(void) diff --git a/src/haproxy.c b/src/haproxy.c index 1c5898e93..eae096577 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2499,9 +2499,9 @@ static void *run_thread_poll_loop(void *data) ha_set_tid((unsigned long)data); #ifdef USE_THREAD - pthread_getcpuclockid(pthread_self(), &thread_info[tid].clock_id); + pthread_getcpuclockid(pthread_self(), &ti->clock_id); #else - thread_info[tid].clock_id = CLOCK_THREAD_CPUTIME_ID; + ti->clock_id = CLOCK_THREAD_CPUTIME_ID; #endif tv_update_date(-1,-1); diff --git a/src/hathreads.c b/src/hathreads.c index 2dbf467e8..b159d5eb3 100644 --- a/src/hathreads.c +++ b/src/hathreads.c @@ -30,6 +30,7 @@ #include struct thread_info thread_info[MAX_THREADS]; +THREAD_LOCAL struct thread_info *ti = &thread_info[0]; #ifdef USE_THREAD