summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_sx.c
Commit message (Collapse)AuthorAgeFilesLines
* /* -> /*- for copyright notices, minor format tweaks as necessaryimp2005-01-061-1/+1
|
* Fix _sx_assert() to panic() rather than printf() when an assertion failsjhb2004-02-271-3/+5
| | | | and ignore assertions if we have already paniced.
* Simplify check. We are only able to check exclusive lock and ifpjd2004-02-191-1/+5
| | | | | | 2nd condition is true, first one is true for sure. Approved by: jhb, scottl (mentor)
* Allow assert that the current thread does not hold the sx(9) lock.pjd2004-02-041-0/+11
| | | | | | Reviewed by: jhb In cooperation with: juli, jhb Approved by: jhb, scottl (mentor)
* Rework witness_lock() to make it slightly more useful and flexible.jhb2004-01-281-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | - witness_lock() is split into two pieces: witness_checkorder() and witness_lock(). Witness_checkorder() determines if acquiring a specified lock at the time it is called would result in a lock order. It optionally adds a new lock order relationship as well. witness_lock() updates witness's data structures to assume that a lock has been acquired by stick a new lock instance in the appropriate lock instance list. - The mutex and sx lock functions now call checkorder() prior to trying to acquire a lock and continue to call witness_lock() after the acquire is completed. This will let witness catch a deadlock before it happens rather than trying to do so after the threads have deadlocked (i.e. never actually report it). - A new function witness_defineorder() has been added that adds a lock order between two locks at runtime without having to acquire the locks. If the lock order cannot be added it will return an error. This function is available to programmers via the WITNESS_DEFINEORDER() macro which accepts either two mutexes or two sx locks as its arguments. - A few simple wrapper macros were added to allow developers to call witness_checkorder() anywhere as a way of enforcing locking assertions in code that might acquire a certain lock in some situations. The macros are: witness_check_{mutex,shared_sx,exclusive_sx} and take an appropriate lock as the sole argument. - The code to remove a lock instance from a lock list in witness_unlock() was unnested by using a goto to vastly improve the readability of this function.
* Extend the mutex pool implementation to permit the creation and use oftruckman2003-07-131-1/+1
| | | | | | | | | | | | | | | | multiple mutex pools with different options and sizes. Mutex pools can be created with either the default sleep mutexes or with spin mutexes. A dynamically created mutex pool can now be destroyed if it is no longer needed. Create two pools by default, one that matches the existing pool that uses the MTX_NOWITNESS option that should be used for building higher level locks, and a new pool with witness checking enabled. Modify the users of the existing mutex pool to use the appropriate pool in the new implementation. Reviewed by: jhb
* Use __FBSDID().obrien2003-06-111-2/+3
|
* Set the lock type equal to the lock name for now as all of the currentjhb2002-04-041-1/+1
| | | | sx locks don't use very specific lock names.
* - Add MTX_SYSINIT and SX_SYSINIT as macro glue for allowing sx and mtxarr2002-04-021-0/+8
| | | | | | | | | | locks to be able to setup a SYSINIT call. This helps in places where a lock is needed to protect some data, but the data is not truly associated with a subsystem that can properly initialize it's lock. The macros use the mtx_sysinit() and sx_sysinit() functions, respectively, as the handler argument to SYSINIT(). Reviewed by: alfred, jhb, smp@
* Invert the test of sx_xholder for SX_LOCKED. We need to warn if atanimura2002-01-181-3/+3
| | | | | | thread other than the curthread holds an sx. While I am here, break a line at the end of warning.
* Update to C99, s/__FUNCTION__/__func__/.obrien2001-12-101-3/+3
|
* Create a mutex pool API for short term leaf mutexes.dillon2001-11-131-28/+27
| | | | | Replace the manual mutex pool in kern_lock.c (lockmgr locks) with the new API. Replace the mutexes embedded in sxlocks with the new API.
* Fix this to actually compile in the !INVARIANTS case.jhb2001-10-241-0/+8
| | | | Reported by: Maxime Henrion <mux@qualys.com>
* Change the sx(9) assertion API to use a sx_assert() function similar tojhb2001-10-231-4/+43
| | | | mtx_assert(9) rather than several SX_ASSERT_* macros.
* The mtx_init() and sx_init() functions bzero'd locks before handing themjhb2001-10-201-1/+3
| | | | | | off to witness_init() making the check for double intializating a lock by testing the LO_INITIALIZED flag moot. Workaround this by checking the LO_INITIALIZED flag ourself before we bzero the lock structure.
* KSE Milestone 2julian2001-09-121-5/+5
| | | | | | | | | | | | | | Note ALL MODULES MUST BE RECOMPILED make the kernel aware that there are smaller units of scheduling than the process. (but only allow one thread per process at this time). This is functionally equivalent to teh previousl -current except that there is a thread associated with each process. Sorry john! (your next MFC will be a doosie!) Reviewed by: peter@freebsd.org, dillon@freebsd.org X-MFC after: ha ha ha ha
* Use witness_upgrade/downgrade for sx_try_upgrade/downgrade.jhb2001-08-231-8/+6
|
* Clear the sx_xholder pointer when downgrading an exclusive lock.jhb2001-08-231-0/+1
|
* Add sx_try_upgrade() and sx_downgrade().jasone2001-08-131-0/+46
| | | | Submitted by: Alexander Kabaev <ak03@gte.com>
* - Add trylock variants of shared and exclusive locks.jhb2001-06-271-4/+42
| | | | | | | | | | | - The sx assertions don't actually need the internal sx mutex lock, so don't bother doing so. - Add a new assertion SX_ASSERT_LOCKED() that asserts that either a shared or exclusive lock should be held. This assertion should be used instead of SX_ASSERT_SLOCKED() in almost all cases. - Adjust some KASSERT()'s to include file and line information. - Use the new witness_assert() function in the WITNESS case for sx slock asserts to verify that the current thread actually owns a slock.
* - Move state about lock objects out of struct lock_object and into a newjhb2001-05-041-27/+3
| | | | | | | | | | | | | | | | | | | | struct lock_instance that is stored in the per-process and per-CPU lock lists. Previously, the lock lists just kept a pointer to each lock held. That pointer is now replaced by a lock instance which contains a pointer to the lock object, the file and line of the last acquisition of a lock, and various flags about a lock including its recursion count. - If we sleep while holding a sleepable lock, then mark that lock instance as having slept and ignore any lock order violations that occur while acquiring Giant when we wake up with slept locks. This is ok because of Giant's special nature. - Allow witness to differentiate between shared and exclusive locks and unlocks of a lock. Witness will now detect the case when a lock is acquired first in one mode and then in another. Mutexes are always locked and unlocked exclusively. Witness will also now detect the case where a process attempts to unlock a shared lock while holding an exclusive lock and vice versa. - Fix a bug in the lock list implementation where we used the wrong constant to detect the case where a lock list entry was full.
* Rework the witness code to work with sx locks as well as mutexes.jhb2001-03-281-10/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Introduce lock classes and lock objects. Each lock class specifies a name and set of flags (or properties) shared by all locks of a given type. Currently there are three lock classes: spin mutexes, sleep mutexes, and sx locks. A lock object specifies properties of an additional lock along with a lock name and all of the extra stuff needed to make witness work with a given lock. This abstract lock stuff is defined in sys/lock.h. The lockmgr constants, types, and prototypes have been moved to sys/lockmgr.h. For temporary backwards compatability, sys/lock.h includes sys/lockmgr.h. - Replace proc->p_spinlocks with a per-CPU list, PCPU(spinlocks), of spin locks held. By making this per-cpu, we do not have to jump through magic hoops to deal with sched_lock changing ownership during context switches. - Replace proc->p_heldmtx, formerly a list of held sleep mutexes, with proc->p_sleeplocks, which is a list of held sleep locks including sleep mutexes and sx locks. - Add helper macros for logging lock events via the KTR_LOCK KTR logging level so that the log messages are consistent. - Add some new flags that can be passed to mtx_init(): - MTX_NOWITNESS - specifies that this lock should be ignored by witness. This is used for the mutex that blocks a sx lock for example. - MTX_QUIET - this is not new, but you can pass this to mtx_init() now and no events will be logged for this lock, so that one doesn't have to change all the individual mtx_lock/unlock() operations. - All lock objects maintain an initialized flag. Use this flag to export a mtx_initialized() macro that can be safely called from drivers. Also, we on longer walk the all_mtx list if MUTEX_DEBUG is defined as witness performs the corresponding checks using the initialized flag. - The lock order reversal messages have been improved to output slightly more accurate file and line numbers.
* In order to avoid recursing on the backing mutex for sx locks in thejhb2001-03-061-2/+2
| | | | | | | INVARIANTS case, define the actual KASSERT() in _SX_ASSERT_[SX]LOCKED macros that are used in the sx code itself and convert the SX_ASSERT_[SX]LOCKED macros to simple wrappers that grab the mutex for the duration of the check.
* - Add sx_descr description member to sx lock structurebmilekic2001-03-061-6/+26
| | | | | | | | | | | | | | | | | - Add sx_xholder member to sx struct which is used for INVARIANTS-enabled assertions. It indicates the thread that presently owns the xlock. - Add some assertions to the sx lock code that will detect the fatal API abuse: xlock --> xlock xlock --> slock which now works thanks to sx_xholder. Notice that the remaining two problematic cases: slock --> xlock slock --> slock (a little less problematic, but still recursion) will need to be handled by witness eventually, as they are more involved. Reviewed by: jhb, jake, jasone
* Implement shared/exclusive locks.jasone2001-03-051-0/+160
Reviewed by: bmilekic, jake, jhb
OpenPOWER on IntegriCloud