summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_unit.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r312113:ngie2017-01-171-6/+6
| | | | Clean up trailing whitespace
* MFC r312112:ngie2017-01-171-3/+2
| | | | Fix -Wunused on gcc 4.9 (x was set but not used)
* Fix build of kern/subr_unit.c, broken by r300539asomers2016-05-241-3/+3
| | | | | | Reported by: peter Pointyhat to: asomers Sponsored by: Spectra Logic Corp
* Add bit_count to the bitstring(3) apiasomers2016-05-231-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a bit_count function, which efficiently counts the number of bits set in a bitstring. sys/sys/bitstring.h tests/sys/sys/bitstring_test.c share/man/man3/bitstring.3 Add bit_alloc sys/kern/subr_unit.c Use bit_count instead of a naive counting loop in check_unrhdr, used when INVARIANTS are enabled. The userland test runs about 6x faster in a generic build, or 8.5x faster when built for Nehalem, which has the POPCNT instruction. sys/sys/param.h Bump __FreeBSD_version due to the addition of bit_alloc UPDATING Add a note about the ABI incompatibility of the bitstring(3) changes, as suggested by lidl. Suggested by: gibbs Reviewed by: gibbs, ngie MFC after: 9 days X-MFC-With: 299090, 300538 Relnotes: yes Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D6255
* Add explicit cast to fix mips and powerpc build after r299090emaste2016-05-051-1/+1
| | | | Sponsored by: The FreeBSD Foundation
* Improve performance and functionality of the bitstring(3) apiasomers2016-05-041-39/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Automate the subr_unit test.asomers2016-04-291-22/+67
| | | | | | | | | | | | | | | | | | | Build and install the subr_unit test program originally written by phk, and run it with the other ATF tests. tests/sys/kern/Makefile * Build and install the subr_unit test as a plain test sys/kern/subr_unit.c * Reduce the default number of repetitions from 100 to 1, and add a command-line parser to override it. * Don't be so noisy by default * Fix an include problem for the test build Reviewed by: ngie MFC after: 4 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D6038
* Move the definition of the struct unrhdr into a separate header file,kib2013-08-301-27/+18
| | | | | | | | to allow embedding the struct. Add init_unrhdr(9) initializer, which sets up preallocated unrhdr. Reviewed by: alc Tested by: pho, bf
* Correct double "the the"eadler2012-09-141-1/+1
| | | | | Approved by: cperciva MFC after: 3 days
* Fix typos - remove duplicate "the".brucec2011-02-211-2/+2
| | | | | | PR: bin/154928 Submitted by: Eitan Adler <lists at eitanadler.com> MFC after: 3 days
* Remove redundant high >= 0.jh2010-07-091-1/+1
| | | | Reported by: rstone
* Assert that low and high are >= 0. The allocator doesn't support thejh2010-07-081-2/+2
| | | | negative range.
* Extend the kernel unit number allocator for allocating specific unitjh2010-07-051-13/+168
| | | | | | | | | | | numbers. This change adds a new function alloc_unr_specific() which returns the requested unit number if it is free. If the number is already allocated or out of the range, -1 is returned. Update alloc_unr(9) manual page accordingly and add a MLINK for alloc_unr_specific(9). Discussed on: freebsd-hackers
* Correct a comment typo.jh2010-06-271-1/+1
|
* - Fix compilation of the subr_unit.c user space test program.jh2010-06-171-3/+4
| | | | - Use %zu for size_t in a few format strings.
* Since cdev mutex is after system map mutex in global lock order, free()kib2007-07-041-1/+34
| | | | | | | | | | | | | | | | | | shall not be called while holding cdev mutex. devfs_inos unrhdr has cdev as mutex, thus creating this LOR situation. Postpone calling free() in kern/subr_unit.c:alloc_unr() and nested functions until the unrhdr mutex is dropped. Save the freed items on the ppfree list instead, and provide the clean_unrhdrl() and clean_unrhdr() functions to clean the list. Call clean_unrhdrl() after devfs_create() calls immediately before dropping cdev mutex. devfs_create() is the only user of the alloc_unrl() in the tree. Reviewed by: phk Tested by: Peter Holm LOR: 80 Approved by: re (kensmith)
* Add the witness warning for free_unr. Function could sleep, thus callerskib2007-06-191-0/+1
| | | | | | | shall not have any non-sleepable locks held. Submitted by: Hans Petter Selasky <hselasky c2i net> Approved by: re (kensmith)
* Remove debugging printfs.phk2005-03-141-8/+3
|
* Reengineer subr_unitphk2005-03-081-287/+511
| | | | | | | | | | | | | | | Add support for passing in a mutex. If NULL is passed a global subr_unit mutex is used. Add alloc_unrl() which expects the mutex to be held. Allocating a unit will never sleep as it does not need to allocate memory. Cut possible range in half so we can use -1 to mean "out of number". Collapse first and last runs into the head by means of counters. This saves memory in the common case(s).
* Add placeholder mutex argument to new_unrhdr().phk2005-03-071-2/+2
|
* /* -> /*- for copyright notices, minor format tweaks as necessaryimp2005-01-061-2/+3
|
* Add delete_unrhdr() function.phk2004-10-251-2/+19
| | | | It will fail fatally if all allocated numbers have not been returned first.
* Fix a typo to fix the !DIAGNOSTIC build.jhb2004-09-301-1/+1
| | | | Submitted by: many
* Add a new API for allocating unit number (-like) resources.phk2004-09-301-0/+597
Allocation is always lowest free unit number. A mixed range/bitmap strategy for maximum memory efficiency. In the typical case where no unit numbers are freed total memory usage is 56 bytes on i386. malloc is called M_WAITOK but no locking is provided (yet). A bit of experience will be necessary to determine the best strategy. Hopefully a "caller provides locking" strategy can be maintained, but that may require use of M_NOWAIT allocation and failure handling. A userland test driver is included.
OpenPOWER on IntegriCloud