]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
bitset(9): Introduce BIT_FOREACH_ISSET and BIT_FOREACH_ISCLR
authorMark Johnston <markj@FreeBSD.org>
Tue, 21 Sep 2021 15:32:23 +0000 (11:32 -0400)
committerMark Johnston <markj@FreeBSD.org>
Tue, 21 Sep 2021 16:07:39 +0000 (12:07 -0400)
commitdfd3bde5775ecf88851d5dffd6a8ed6076b53566
tree4219e2f0c3525e4b86e6080e64ad9f621f736754
parent8678140127296c15894094087b81f71fe79a21d9
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
share/man/man9/Makefile
share/man/man9/bitset.9
sys/sys/bitset.h