HomeFreeBSD

bitset(9): Introduce BIT_FOREACH_ISSET and BIT_FOREACH_ISCLR

Description

bitset(9): Introduce BIT_FOREACH_ISSET and BIT_FOREACH_ISCLR

These allow one to non-destructively iterate over the set or clear bits
in a bitset. The motivation is that we have several code fragments
which iterate over a CPU set like this:

while ((cpu = CPU_FFS(&cpus)) != 0) {
cpu--;
CPU_CLR(cpu, &cpus);
<do something>;
}

This is slow since CPU_FFS begins the search at the beginning of the
bitset each time. On amd64 and arm64, CPU sets have size 256, so there
are four limbs in the bitset and we do a lot of unnecessary scanning.

A second problem is that this is destructive, so code which needs to
preserve the original set has to make a copy. In particular, we have
quite a few functions which take a cpuset_t parameter by value, meaning
that each call has to copy the 32 byte cpuset_t.

The new macros address both problems.

Reviewed by: cem, kib
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D32028

Details

Provenance
markjAuthored on Sep 21 2021, 3:32 PM
Reviewer
cem
Differential Revision
D32028: bitset(9): Introduce BIT_FOREACH_SET and BIT_FOREACH_CLR
Parents
rG867814012729: syslog.conf.5: Fix the message priority order
Branches
Unknown
Tags
Unknown