MINOR: tinfo: add the tgid to the thread_info struct

At several places we're dereferencing the thread group just to catch
the group number, and this will become even more required once we start
to use per-group contexts. Let's just add the tgid in the thread_info
struct to make this easier.
This commit is contained in:
Willy Tarreau 2022-06-28 10:49:57 +02:00
parent e7475c8e79
commit 66ad98a772
4 changed files with 12 additions and 7 deletions

View File

@ -225,14 +225,14 @@ static inline void ha_set_thread(const struct thread_info *thr)
if (thr) {
BUG_ON(!thr->ltid_bit);
BUG_ON(!thr->tg);
BUG_ON(!thr->tg->tgid);
BUG_ON(!thr->tgid);
ti = thr;
tg = thr->tg;
tid = thr->tid;
tgid = thr->tgid;
tid_bit = 1UL << tid; /* FIXME: must become thr->ltid_bit */
th_ctx = &ha_thread_ctx[tid];
tgid = tg->tgid;
} else {
tgid = 1;
tid = 0;

View File

@ -70,6 +70,7 @@ struct thread_info {
const struct tgroup_info *tg; /* config of the thread-group this thread belongs to */
uint tid, ltid; /* process-wide and group-wide thread ID (start at 0) */
ulong ltid_bit; /* bit masks for the tid/ltid */
uint tgid; /* ID of the thread group this thread belongs to (starts at 1; 0=unset) */
/* pad to cache line (64B) */
char __pad[0]; /* unused except to check remaining room */

View File

@ -178,7 +178,7 @@ void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
MT_LIST_ISEMPTY(&ha_thread_ctx[thr].shared_tasklet_list)),
ha_thread_ctx[thr].tasks_in_list,
ha_thread_ctx[thr].rq_total,
ha_thread_info[thr].tg->tgid, ha_thread_info[thr].ltid + 1,
ha_thread_info[thr].tgid, ha_thread_info[thr].ltid + 1,
stuck,
!!(th_ctx->flags & TH_FL_TASK_PROFILING));

View File

@ -1061,6 +1061,7 @@ int thread_map_to_groups()
}
ha_tgroup_info[g].count++;
ha_thread_info[t].tgid = g + 1;
ha_thread_info[t].tg = &ha_tgroup_info[g];
ut--;
@ -1119,11 +1120,11 @@ int thread_resolve_group_mask(uint igid, ulong imask, uint *ogid, ulong *omask,
imask &= all_threads_mask;
for (t = 0; t < global.nbthread; t++) {
if (imask & (1UL << t)) {
if (ha_thread_info[t].tg->tgid != igid) {
if (ha_thread_info[t].tgid != igid) {
if (!igid)
igid = ha_thread_info[t].tg->tgid;
igid = ha_thread_info[t].tgid;
else {
memprintf(err, "'thread' directive spans multiple groups (at least %u and %u)", igid, ha_thread_info[t].tg->tgid);
memprintf(err, "'thread' directive spans multiple groups (at least %u and %u)", igid, ha_thread_info[t].tgid);
return -1;
}
}
@ -1259,8 +1260,10 @@ static int cfg_parse_thread_group(char **args, int section_type, struct proxy *c
for (tnum = ha_tgroup_info[tgroup-1].base;
tnum < ha_tgroup_info[tgroup-1].base + ha_tgroup_info[tgroup-1].count;
tnum++) {
if (ha_thread_info[tnum-1].tg == &ha_tgroup_info[tgroup-1])
if (ha_thread_info[tnum-1].tg == &ha_tgroup_info[tgroup-1]) {
ha_thread_info[tnum-1].tg = NULL;
ha_thread_info[tnum-1].tgid = 0;
}
}
ha_tgroup_info[tgroup-1].count = ha_tgroup_info[tgroup-1].base = 0;
}
@ -1299,6 +1302,7 @@ static int cfg_parse_thread_group(char **args, int section_type, struct proxy *c
ha_tgroup_info[tgroup-1].base = tnum - 1;
}
ha_thread_info[tnum-1].tgid = tgroup;
ha_thread_info[tnum-1].tg = &ha_tgroup_info[tgroup-1];
tot++;
}