Add functionality to and improve performance of the bitstring(3)
API.
Two new functions are provided, bit_ffs_at() and bit_ffc_at(),
which allow for efficient searching of set or cleared bits starting
from any bit offset within the bit string.
Performance is improved by operating on longs instead of bytes and
using ffsl() for searches within a long. ffsl() is a compiler
builtin in both clang and gcc for most architectures, converting what
was a brute force while loop search into a couple of instructions.
All of the bitstring(3) API continues to be contained in the header
file. Some of the functions are large enough that they should be
uninlined and moved to a library. However, this task is deferred
until the issue can be discussed with the FreeBSD community to
determine which library (old or new) should be used.
sys/sys/bitstring.h:
Convert the majority of the existing bit string implementation from macros to inline functions. Properly protect the implementation from inadvertant macro expansion when included in a user's program by prefixing all private macros/functions and local variables with '_'. Add bit_ffs_at() and bit_ffc_at(). Implement bit_ffs() and bit_ffc() in terms of their "at" counterparts. Provide a kernel implementation of bit_alloc(), making the full API usable in the kernel. Improve code documenation.
share/man/man3/bitstring.3:
Add pre-exisiting API bit_ffc() to the synopsis. Document new APIs. Document pre-existing requirement to include stdlib.h. This was masked by bit_alloc() being a macro and few consumers using it. Document new requirement to include strings.h for ffsl(). Document the initialization state of the bit strings allocated/declared by bit_alloc() and bit_decl(). Correct documenation for bitstr_size(). The original code comments indicate the size is in bytes, not "elements of bitstr_t". The new implementation follows this lead. Only hastd assumed "elements" rather than bytes and it has been corrected.
share/man/man9/bitstring.9:
Document kernel version of the bit string API.
tests/lib/Makefile:
tests/lib/bitstring/Makefile:
tests/lib/bitstring/bitstring.c:
Add tests for all existing and new functionality.
lib/libbluetooth/bluetooth.h:
Include bitstring.h instead of sys/bitstring.h. Include stdlib.h and strings.h.
sbin/hastd/activemap.c:
sbin/hastd/nv.c:
usr.sbin/cron/cron/cron.h:
Include strings.h. Include bitstring.h after stdlib.h and strings.h.
sbin/hastd/activemap.c:
Correct usage of bitstr_size().
sys/dev/xen/blkback/blkback.c:
Convert from old bitstring(3) usage to bitstring(9).
sys/kern/subr_unit.c:
Remove hard-coded assumption that sizeof(bitstr_t) is 1. Convert struct unrb (a "unit number bitmap") from a struct containing a u_char counter of set bits followed by a bit string bitmap, to a union of a bit string bitmap and an array of u_char. Reduce the number of bits used in the bitmap by 8 and use this area to store the busy count.
sys/netgraph/bluetooth/socket/ng_btsocket.c:
sys/netgraph/bluetooth/socket/ng_btsocket_hci_raw.c:
sys/netgraph/bluetooth/socket/ng_btsocket_l2cap.c:
sys/netgraph/bluetooth/socket/ng_btsocket_l2cap_raw.c:
sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c:
sys/netgraph/bluetooth/socket/ng_btsocket_sco.c:
Include sys/malloc.h before sys/bitstring.h.