]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: thread: add a new all_tgroups_mask variable to know about active tgroups
authorWilly Tarreau <w@1wt.eu>
Fri, 24 Jun 2022 13:55:11 +0000 (15:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Jul 2022 17:15:15 +0000 (19:15 +0200)
In order to kill all_threads_mask we'll need to have an equivalent for
the thread groups. The all_tgroups_mask does just this, it keeps one bit
set per enabled group.

include/haproxy/thread.h
src/haproxy.c
src/thread.c

index 1d07539abda2ca47c0746c8ecf532e85aede9ac2..969e7dc13f5f2c4c461f8d97eb65a3983ded7dfd 100644 (file)
@@ -56,6 +56,7 @@ extern int thread_cpus_enabled_at_boot;
  * at build time.
  */
 enum { all_threads_mask = 1UL };
+enum { all_tgroups_mask = 1UL };
 enum { threads_harmless_mask = 0 };
 enum { threads_idle_mask = 0 };
 enum { threads_sync_mask = 0 };
@@ -180,6 +181,7 @@ void set_thread_cpu_affinity();
 unsigned long long ha_get_pthread_id(unsigned int thr);
 
 extern volatile unsigned long all_threads_mask;
+extern volatile unsigned long all_tgroups_mask;
 extern volatile unsigned long threads_harmless_mask;
 extern volatile unsigned long threads_idle_mask;
 extern volatile unsigned long threads_sync_mask;
index 79d40ab1b772015226b2fc57614510091a2c4e3f..0a11d3a00bfa714cec567930d2f7cdc209d400b1 100644 (file)
@@ -2973,7 +2973,8 @@ static void *run_thread_poll_loop(void *data)
                ptff->fct();
 
 #ifdef USE_THREAD
-       _HA_ATOMIC_AND(&ha_tgroup_info[ti->tgid].threads_enabled, ~ti->ltid_bit);
+       if (!_HA_ATOMIC_AND_FETCH(&ha_tgroup_info[ti->tgid].threads_enabled, ~ti->ltid_bit))
+               _HA_ATOMIC_AND(&all_tgroups_mask, ~tg->tgid_bit);
        _HA_ATOMIC_AND(&all_threads_mask, ~tid_bit);
        if (tid > 0)
                pthread_exit(NULL);
index 6f81f96a13812663f5deae9b85d6c0e3543c0f42..7d74858d7db70a092024a0df4d1971cc14b021fc 100644 (file)
@@ -65,6 +65,7 @@ volatile unsigned long threads_harmless_mask = 0;
 volatile unsigned long threads_idle_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_tgroups_mask __read_mostly  = 1; // nbtgroup 1 assumed by default
 THREAD_LOCAL unsigned int  tgid          = 1; // thread ID starts at 1
 THREAD_LOCAL unsigned int  tid           = 0;
 THREAD_LOCAL unsigned long tid_bit       = (1UL << 0);
@@ -1008,6 +1009,7 @@ int thread_map_to_groups()
 {
        int t, g, ut, ug;
        int q, r;
+       ulong m __maybe_unused;
 
        ut = ug = 0; // unassigned threads & groups
 
@@ -1082,11 +1084,18 @@ int thread_map_to_groups()
                ha_thread_info[t].ltid_bit = 1UL << ha_thread_info[t].ltid;
        }
 
+       m = 0;
        for (g = 0; g < global.nbtgroups; g++) {
                ha_tgroup_info[g].threads_enabled = nbits(ha_tgroup_info[g].count);
+               if (!ha_tgroup_info[g].count)
+                       continue;
+               m |= 1UL << g;
 
        }
 
+#ifdef USE_THREAD
+       all_tgroups_mask = m;
+#endif
        return 0;
 }