MINOR: threads: add the current group ID in thread-local "tgid" variable

This is the equivalent of "tid" for ease of access. In the future if we
make th_cfg a pure thread-local array (not a pointer), it may make sense
to move it there.
This commit is contained in:
Willy Tarreau 2021-09-30 08:00:11 +02:00
parent 43ab05b3da
commit b90935c908
2 changed files with 6 additions and 0 deletions

View File

@ -61,6 +61,7 @@ enum { threads_sync_mask = 0 };
enum { threads_want_rdv_mask = 0 }; enum { threads_want_rdv_mask = 0 };
enum { tid_bit = 1UL }; enum { tid_bit = 1UL };
enum { tid = 0 }; enum { tid = 0 };
enum { tgid = 1 };
#define HA_SPIN_INIT(l) do { /* do nothing */ } while(0) #define HA_SPIN_INIT(l) do { /* do nothing */ } while(0)
#define HA_SPIN_DESTROY(l) do { /* do nothing */ } while(0) #define HA_SPIN_DESTROY(l) do { /* do nothing */ } while(0)
@ -184,6 +185,7 @@ extern volatile unsigned long threads_sync_mask;
extern volatile unsigned long threads_want_rdv_mask; extern volatile unsigned long threads_want_rdv_mask;
extern THREAD_LOCAL unsigned long tid_bit; /* The bit corresponding to the thread id */ extern THREAD_LOCAL unsigned long tid_bit; /* The bit corresponding to the thread id */
extern THREAD_LOCAL unsigned int tid; /* The thread id */ extern THREAD_LOCAL unsigned int tid; /* The thread id */
extern THREAD_LOCAL unsigned int tgid; /* The thread group id (starts at 1) */
/* explanation for threads_want_rdv_mask, threads_harmless_mask, and /* explanation for threads_want_rdv_mask, threads_harmless_mask, and
* threads_sync_mask : * threads_sync_mask :
@ -222,13 +224,16 @@ static inline void ha_set_thread(const struct thread_info *thr)
if (thr) { if (thr) {
BUG_ON(!thr->tid_bit); BUG_ON(!thr->tid_bit);
BUG_ON(!thr->tg); BUG_ON(!thr->tg);
BUG_ON(!thr->tg->tgid);
ti = thr; ti = thr;
tg = thr->tg; tg = thr->tg;
tid = thr->tid; tid = thr->tid;
tid_bit = thr->tid_bit; tid_bit = thr->tid_bit;
th_ctx = &ha_thread_ctx[tid]; th_ctx = &ha_thread_ctx[tid];
tgid = tg->tgid;
} else { } else {
tgid = 1;
tid = 0; tid = 0;
tid_bit = 1; tid_bit = 1;
ti = &ha_thread_info[0]; ti = &ha_thread_info[0];

View File

@ -66,6 +66,7 @@ volatile unsigned long threads_harmless_mask = 0;
volatile unsigned long threads_idle_mask = 0; volatile unsigned long threads_idle_mask = 0;
volatile unsigned long threads_sync_mask = 0; volatile unsigned long threads_sync_mask = 0;
volatile unsigned long all_threads_mask __read_mostly = 1; // nbthread 1 assumed by default volatile unsigned long all_threads_mask __read_mostly = 1; // nbthread 1 assumed by default
THREAD_LOCAL unsigned int tgid = 1; // thread ID starts at 1
THREAD_LOCAL unsigned int tid = 0; THREAD_LOCAL unsigned int tid = 0;
THREAD_LOCAL unsigned long tid_bit = (1UL << 0); THREAD_LOCAL unsigned long tid_bit = (1UL << 0);
int thread_cpus_enabled_at_boot = 1; int thread_cpus_enabled_at_boot = 1;