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.
This commit is contained in:
Willy Tarreau 2022-06-24 15:55:11 +02:00
parent c6cf64bb5e
commit cce203aae5
3 changed files with 13 additions and 1 deletions

View File

@ -56,6 +56,7 @@ extern int thread_cpus_enabled_at_boot;
* at build time. * at build time.
*/ */
enum { all_threads_mask = 1UL }; enum { all_threads_mask = 1UL };
enum { all_tgroups_mask = 1UL };
enum { threads_harmless_mask = 0 }; enum { threads_harmless_mask = 0 };
enum { threads_idle_mask = 0 }; enum { threads_idle_mask = 0 };
enum { threads_sync_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); unsigned long long ha_get_pthread_id(unsigned int thr);
extern volatile unsigned long all_threads_mask; 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_harmless_mask;
extern volatile unsigned long threads_idle_mask; extern volatile unsigned long threads_idle_mask;
extern volatile unsigned long threads_sync_mask; extern volatile unsigned long threads_sync_mask;

View File

@ -2973,7 +2973,8 @@ static void *run_thread_poll_loop(void *data)
ptff->fct(); ptff->fct();
#ifdef USE_THREAD #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); _HA_ATOMIC_AND(&all_threads_mask, ~tid_bit);
if (tid > 0) if (tid > 0)
pthread_exit(NULL); pthread_exit(NULL);

View File

@ -65,6 +65,7 @@ volatile unsigned long threads_harmless_mask = 0;
volatile unsigned long threads_idle_mask = 0; volatile unsigned long threads_idle_mask = 0;
volatile unsigned long threads_sync_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_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 tgid = 1; // thread ID starts at 1
THREAD_LOCAL unsigned int tid = 0; THREAD_LOCAL unsigned int tid = 0;
THREAD_LOCAL unsigned long tid_bit = (1UL << 0); THREAD_LOCAL unsigned long tid_bit = (1UL << 0);
@ -1008,6 +1009,7 @@ int thread_map_to_groups()
{ {
int t, g, ut, ug; int t, g, ut, ug;
int q, r; int q, r;
ulong m __maybe_unused;
ut = ug = 0; // unassigned threads & groups 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; ha_thread_info[t].ltid_bit = 1UL << ha_thread_info[t].ltid;
} }
m = 0;
for (g = 0; g < global.nbtgroups; g++) { for (g = 0; g < global.nbtgroups; g++) {
ha_tgroup_info[g].threads_enabled = nbits(ha_tgroup_info[g].count); 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; return 0;
} }