MINOR: thread: keep a bitmask of enabled groups in thread_set

We're only checking for 0, 1, or >1 groups enabled there, and we'll soon
need to be more precise and know quickly which groups are non-empty.
Let's just replace the count with a mask of enabled groups. This will
allow to quickly spot the presence of any such group in a set.
This commit is contained in:
Willy Tarreau 2023-03-01 11:24:29 +01:00
parent 3f210970bf
commit 97da942ba6
4 changed files with 17 additions and 18 deletions

View File

@ -40,7 +40,7 @@ struct thread_set {
ulong abs[(MAX_THREADS + LONGBITS - 1) / LONGBITS];
ulong rel[MAX_TGROUPS];
};
uint nbgrp; /* number of non-empty groups in this set, 0 for abs */
ulong grps; /* bit field of all non-empty groups, 0 for abs */
};
/* tasklet classes */

View File

@ -77,7 +77,7 @@ static inline int thread_set_nth_group(const struct thread_set *ts, int n)
{
int i;
if (ts->nbgrp) {
if (ts->grps) {
for (i = 0; i < MAX_TGROUPS; i++)
if (ts->rel[i] && !n--)
return i + 1;
@ -95,7 +95,7 @@ static inline ulong thread_set_nth_tmask(const struct thread_set *ts, int n)
{
int i;
if (ts->nbgrp) {
if (ts->grps) {
for (i = 0; i < MAX_TGROUPS; i++)
if (ts->rel[i] && !n--)
return ts->rel[i];
@ -111,7 +111,7 @@ static inline void thread_set_pin_grp1(struct thread_set *ts, ulong mask)
{
int i;
ts->nbgrp = 1;
ts->grps = 1;
ts->rel[0] = mask;
for (i = 1; i < MAX_TGROUPS; i++)
ts->rel[i] = 0;

View File

@ -2998,18 +2998,16 @@ int check_config_validity()
bit = (bind_conf->thread_set.rel[grp] & ~mask) & -(bind_conf->thread_set.rel[grp] & ~mask);
new_ts.rel[grp] |= bit;
mask |= bit;
if (!atleast2(new_ts.rel[grp])) // first time we add a bit: new group
new_ts.nbgrp++;
new_ts.grps |= 1UL << grp;
done += shards;
};
BUG_ON(!new_ts.nbgrp); // no more bits left unassigned
BUG_ON(!new_ts.grps); // no more bits left unassigned
if (new_ts.nbgrp > 1) {
if (atleast2(new_ts.grps)) {
ha_alert("Proxy '%s': shard number %d spans %d groups in 'bind %s' at [%s:%d]\n",
curproxy->id, shard, new_ts.nbgrp, bind_conf->arg, bind_conf->file, bind_conf->line);
curproxy->id, shard, my_popcountl(new_ts.grps), bind_conf->arg, bind_conf->file, bind_conf->line);
cfgerr++;
err_code |= ERR_FATAL | ERR_ALERT;
goto out;
@ -4450,7 +4448,7 @@ int check_config_validity()
free(err);
cfgerr++;
}
else if (bind_conf->thread_set.nbgrp > 1) {
else if (atleast2(bind_conf->thread_set.grps)) {
ha_alert("Peers section '%s': 'thread' spans more than one group in 'bind %s' at [%s:%d].\n",
curpeers->peers_fe->id, bind_conf->arg, bind_conf->file, bind_conf->line);
cfgerr++;

View File

@ -1240,7 +1240,7 @@ int thread_resolve_group_mask(struct thread_set *ts, int defgrp, char **err)
ulong mask, imask;
uint g;
if (!ts->nbgrp) {
if (!ts->grps) {
/* unspecified group, IDs are global */
if (thread_set_is_empty(ts)) {
/* all threads of all groups, unless defgrp is set and
@ -1248,7 +1248,8 @@ int thread_resolve_group_mask(struct thread_set *ts, int defgrp, char **err)
*/
for (g = defgrp ? defgrp-1 : 0; g < (defgrp ? defgrp : global.nbtgroups); g++) {
new_ts.rel[g] = ha_tgroup_info[g].threads_enabled;
new_ts.nbgrp++;
if (new_ts.rel[g])
new_ts.grps |= 1UL << g;
}
} else {
/* some absolute threads are set, we must remap them to
@ -1271,9 +1272,9 @@ int thread_resolve_group_mask(struct thread_set *ts, int defgrp, char **err)
/* now the mask exactly matches the threads to be enabled
* in this group.
*/
if (!new_ts.rel[g] && mask)
new_ts.nbgrp++;
new_ts.rel[g] |= mask;
if (new_ts.rel[g])
new_ts.grps |= 1UL << g;
}
}
} else {
@ -1310,7 +1311,8 @@ int thread_resolve_group_mask(struct thread_set *ts, int defgrp, char **err)
}
new_ts.rel[g] = imask & mask;
new_ts.nbgrp++;
if (new_ts.rel[g])
new_ts.grps |= 1UL << g;
}
}
@ -1521,8 +1523,7 @@ int parse_thread_set(const char *arg, struct thread_set *ts, char **err)
if (ts) {
if (is_rel) {
/* group-relative thread numbers */
if (!ts->rel[tg - 1])
ts->nbgrp++;
ts->grps |= 1UL << (tg - 1);
if (max >= min) {
for (v = min; v <= max; v++)