]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: add a thread-local thread_info pointer "ti"
authorWilly Tarreau <w@1wt.eu>
Mon, 20 May 2019 16:57:53 +0000 (18:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 20 May 2019 19:14:12 +0000 (21:14 +0200)
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
src/haproxy.c
src/hathreads.c

index 6c420dd3fa6971a6a2c0cf076afbf9523ed89c1f..b3c45641ff21a980331032d7c395103df1f5c444 100644 (file)
@@ -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)
index 1c5898e935318b16582978bd1e95a80cc001dc8a..eae096577f9409582a273fb4d3daa8e01ae73d38 100644 (file)
@@ -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);
index 2dbf467e81b75f408e6a21eb745df8c1411cebbb..b159d5eb39f6c17df3059cf4359bfa9a8589a8fd 100644 (file)
@@ -30,6 +30,7 @@
 #include <proto/fd.h>
 
 struct thread_info thread_info[MAX_THREADS];
+THREAD_LOCAL struct thread_info *ti = &thread_info[0];
 
 #ifdef USE_THREAD