From 66ad98a772047121f2687fb5ce0c432e88d9b2d9 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 28 Jun 2022 10:49:57 +0200 Subject: [PATCH] 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. --- include/haproxy/thread.h | 4 ++-- include/haproxy/tinfo-t.h | 1 + src/debug.c | 2 +- src/thread.c | 12 ++++++++---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/haproxy/thread.h b/include/haproxy/thread.h index 6ed080e..1d07539 100644 --- a/include/haproxy/thread.h +++ b/include/haproxy/thread.h @@ -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; diff --git a/include/haproxy/tinfo-t.h b/include/haproxy/tinfo-t.h index 15ebcd1..bbba5a1 100644 --- a/include/haproxy/tinfo-t.h +++ b/include/haproxy/tinfo-t.h @@ -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 */ diff --git a/src/debug.c b/src/debug.c index ee03798..2ee1038 100644 --- a/src/debug.c +++ b/src/debug.c @@ -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)); diff --git a/src/thread.c b/src/thread.c index 9a0811b..c5f0603 100644 --- a/src/thread.c +++ b/src/thread.c @@ -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++; } -- 1.7.10.4