Page MenuHomeFreeBSD

Improve performance and add "find at" APIs to bitstring(3)
AbandonedPublic

Authored by asomers on Dec 31 2014, 10:52 PM.
Tags
None
Referenced Files
F87097982: D1408.diff
Sat, Jun 29, 7:52 AM
Unknown Object (File)
Sun, Jun 23, 8:58 PM
Unknown Object (File)
Sat, Jun 22, 10:06 PM
Unknown Object (File)
Fri, Jun 21, 8:44 PM
Unknown Object (File)
May 17 2024, 4:26 AM
Unknown Object (File)
May 5 2024, 5:54 PM
Unknown Object (File)
Mar 9 2024, 1:30 AM
Unknown Object (File)
Dec 20 2023, 12:02 AM
Subscribers

Details

Reviewers
will
gibbs
imp
Group Reviewers
manpages
Summary

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.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

gibbs retitled this revision from to Improve performance and add "find at" APIs to bitstring(3).
gibbs updated this object.
gibbs added a reviewer: will.

Improve man pages. Fix compilation errors in blkback.c.

imp added a reviewer: imp.
imp added a subscriber: imp.
imp added inline comments.
sys/sys/bitstring.h
44

We should get core to use the substantially similar language in the model FreeBSD license.

This revision is now accepted and ready to land.Jan 2 2015, 6:20 PM
asomers added a reviewer: gibbs.
asomers added a subscriber: asomers.

The same functionality is going in as part of D6004.