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.
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 @@
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 @@
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 @@
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 @@
}
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 @@
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 @@
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 @@
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++;
}