From: Willy Tarreau Date: Fri, 24 Jun 2022 13:55:11 +0000 (+0200) Subject: MINOR: thread: add a new all_tgroups_mask variable to know about active tgroups X-Git-Tag: v2.7-dev2~123 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cce203aae5017880a846a56fb2134cc8e66728f5;p=thirdparty%2Fhaproxy.git MINOR: thread: add a new all_tgroups_mask variable to know about active tgroups 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. --- diff --git a/include/haproxy/thread.h b/include/haproxy/thread.h index 1d07539abd..969e7dc13f 100644 --- a/include/haproxy/thread.h +++ b/include/haproxy/thread.h @@ -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; diff --git a/src/haproxy.c b/src/haproxy.c index 79d40ab1b7..0a11d3a00b 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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); diff --git a/src/thread.c b/src/thread.c index 6f81f96a13..7d74858d7d 100644 --- a/src/thread.c +++ b/src/thread.c @@ -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; }