freebsd-dev/sys
Alan Somers 8907f744ff Improve performance and functionality 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 perhaps they should be uninlined
and moved to a library, but that is beyond the scope of this commit.

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 the initialization state of the bit strings
        allocated/declared by bit_alloc() and bit_decl().

        Correct documentation 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.

etc/mtree/BSD.tests.dist:
tests/sys/Makefile:
tests/sys/sys/Makefile:
tests/sys/sys/bitstring.c:
        Add tests for all existing and new functionality.

include/bitstring.h
	Include all headers needed by sys/bitstring.h

lib/libbluetooth/bluetooth.h:
usr.sbin/bluetooth/hccontrol/le.c:
        Include bitstring.h instead of sys/bitstring.h.

sbin/hastd/activemap.c:
        Correct usage of bitstr_size().

sys/dev/xen/blkback/blkback.c
        Use new bit_alloc.

sys/kern/subr_unit.c:
        Remove hard-coded assumption that sizeof(bitstr_t) is 1.  Get rid of
        unrb.busy, which caches the number of bits set in unrb.map.  When
        INVARIANTS are disabled, nothing needs to know that information.
        callapse_unr can be adapted to use bit_ffs and bit_ffc instead.
        Eliminating unrb.busy saves memory, simplifies the code, and
        provides a slight speedup when INVARIANTS are disabled.

sys/net/flowtable.c:
        Use the new kernel implementation of bit-alloc, instead of hacking
        the old libc-dependent macro.

sys/sys/param.h
        Update __FreeBSD_version to indicate availability of new API

Submitted by:   gibbs, asomers
Reviewed by:    gibbs, ngie
MFC after:      4 weeks
Sponsored by:   Spectra Logic Corp
Differential Revision:  https://reviews.freebsd.org/D6004
2016-05-04 22:34:11 +00:00
..
amd64 Explain why pmap_copy(), pmap_enter_pde(), and pmap_enter_quick_locked() 2016-05-04 17:54:13 +00:00
arm Add driver for Allwinner A83T/H3/A64 Gigabit Ethernet. 2016-05-04 20:06:20 +00:00
arm64 Disable ACPI on arm64 ad it has only had minimal testing and is causing 2016-04-26 14:21:39 +00:00
boot Change a rounding operation that had missing braces into a roundup2() 2016-05-03 00:09:13 +00:00
bsm
cam Fix a memory leak in the devctl notify code. 2016-05-03 14:30:26 +00:00
cddl Fix a use-after-free when "zpool import" fails 2016-04-29 21:29:37 +00:00
compat sys/compat/linux*: spelling fixes. 2016-04-30 00:53:10 +00:00
conf Misc. build: minor spelling fixes. 2016-05-03 22:01:48 +00:00
contrib Revert AccessWidth/BitOffset support for AcpiHwWrite() and AcpiHwRead() for 2016-04-30 06:48:48 +00:00
crypto aesni(4): Initialize error before use 2016-04-20 03:05:32 +00:00
ddb Enhance the ddb examine (x) command. 2016-05-02 19:32:06 +00:00
dev Improve performance and functionality of the bitstring(3) api 2016-05-04 22:34:11 +00:00
fs Rationalize license numbering in fdescfs(5) 2016-04-30 16:01:37 +00:00
gdb
geom sys: Make use of our rounddown() macro when sys/param.h is available. 2016-04-30 14:41:18 +00:00
gnu Change OpenWRT imported dtsi files 2016-04-20 14:29:03 +00:00
i386 xen/i386: enable the platform hypercall for i386 2016-05-03 08:05:14 +00:00
isa sys/isa: minor spelling fixes. 2016-05-03 21:51:52 +00:00
kern Improve performance and functionality of the bitstring(3) api 2016-05-04 22:34:11 +00:00
kgssapi kgssapi: insignificant spelling fix. 2016-05-03 22:05:03 +00:00
libkern sys: Make use of our rounddown() macro when sys/param.h is available. 2016-04-30 14:41:18 +00:00
mips When attempting to satisfy mmap() requests for superpage alignment on 2016-04-30 19:29:03 +00:00
modules Misc. build: minor spelling fixes. 2016-05-03 22:01:48 +00:00
net Improve performance and functionality of the bitstring(3) api 2016-05-04 22:34:11 +00:00
net80211 net80211: do not hardcode size of ic_modecaps field. 2016-05-04 17:22:35 +00:00
netgraph sys/netgraph: spelling fixes in comments. 2016-04-29 21:25:05 +00:00
netinet sys/net*: minor spelling fixes. 2016-05-03 18:05:43 +00:00
netinet6 sys/net*: minor spelling fixes. 2016-05-03 18:05:43 +00:00
netipsec sys/net*: minor spelling fixes. 2016-05-03 18:05:43 +00:00
netnatm kernel: use our nitems() macro when it is available through param.h. 2016-04-19 23:48:27 +00:00
netpfil sys/net*: minor spelling fixes. 2016-05-03 18:05:43 +00:00
netsmb sys/net*: minor spelling fixes. 2016-05-03 18:05:43 +00:00
nfs NFS: spelling fixes on comments. 2016-04-29 16:07:25 +00:00
nfsclient
nfsserver
nlm Remove slightly used const values that can be replaced with nitems(). 2016-04-21 15:38:28 +00:00
ofed Fix NOIP kernels to compile. 2016-04-24 15:56:05 +00:00
opencrypto
pc98 Move 'device pci' for the PCI bus driver to the MI NOTES file. 2016-04-29 23:53:55 +00:00
powerpc powerpc: Replace rounddown() from r298856 with roundup(). 2016-04-30 19:50:59 +00:00
riscv Rework the list of all pmaps: embed the list link into pmap. 2016-04-26 14:38:18 +00:00
rpc sys: Make use of our rounddown() macro when sys/param.h is available. 2016-04-30 14:41:18 +00:00
security sys: use our nitems() macro when param.h is available. 2016-04-21 19:40:10 +00:00
sparc64 sys/sparc64: minor spelling fixes. 2016-05-04 15:52:40 +00:00
sys Improve performance and functionality of the bitstring(3) api 2016-05-04 22:34:11 +00:00
teken
tests
tools Fix MFS builds when both MD_ROOT_SIZE and MFS_IMAGE are specified 2016-02-02 07:02:51 +00:00
ufs UFS: spelling fixes on comments. 2016-04-29 20:43:51 +00:00
vm sys/vm: minor spelling fixes in comments. 2016-05-02 20:16:29 +00:00
x86 Work around (ignore) broken SRAT tables 2016-05-03 20:14:04 +00:00
xdr RPC: for pointers replace 0 with NULL. 2016-04-14 17:06:37 +00:00
xen
Makefile Add riscv to the list of architectures for cscope. 2016-02-29 16:39:27 +00:00