]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tinfo: add the tgid to the thread_info struct
authorWilly Tarreau <w@1wt.eu>
Tue, 28 Jun 2022 08:49:57 +0000 (10:49 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Jul 2022 17:15:14 +0000 (19:15 +0200)
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
include/haproxy/tinfo-t.h
src/debug.c
src/thread.c

index 6ed080ecbc01f9804491acf99559aa49a3601959..1d07539abda2ca47c0746c8ecf532e85aede9ac2 100644 (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;
index 15ebcd17d48b091151c1e9ef233c1a670d1a1b49..bbba5a1dbc644e4613bc4ae241cb10e35fcc4f8c 100644 (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 */
index ee037980999f399f8c99bf3cd4c253a3f249c958..2ee10387d9bca414efb9f3b92d5f09d2488301ed 100644 (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));
 
index 9a0811bfd35fc5accfb96da68ae2342aaf8404d6..c5f06038f317f5d76bc4049ca61b6f77eb9a9c30 100644 (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++;
                }