2000-09-07 01:33:02 +00:00
|
|
|
/*-
|
2008-08-13 18:24:22 +00:00
|
|
|
* Copyright (c) 2008 Isilon Systems, Inc.
|
|
|
|
* Copyright (c) 2008 Ilya Maykov <ivmaykov@gmail.com>
|
|
|
|
* Copyright (c) 1998 Berkeley Software Design, Inc.
|
|
|
|
* All rights reserved.
|
2000-09-07 01:33:02 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Berkeley Software Design Inc's name may not be used to endorse or
|
|
|
|
* promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* from BSDI $Id: mutex_witness.c,v 1.1.2.20 2000/04/27 03:10:27 cp Exp $
|
- Make the mutex code almost completely machine independent. This greatly
reducues the maintenance load for the mutex code. The only MD portions
of the mutex code are in machine/mutex.h now, which include the assembly
macros for handling mutexes as well as optionally overriding the mutex
micro-operations. For example, we use optimized micro-ops on the x86
platform #ifndef I386_CPU.
- Change the behavior of the SMP_DEBUG kernel option. In the new code,
mtx_assert() only depends on INVARIANTS, allowing other kernel developers
to have working mutex assertiions without having to include all of the
mutex debugging code. The SMP_DEBUG kernel option has been renamed to
MUTEX_DEBUG and now just controls extra mutex debugging code.
- Abolish the ugly mtx_f hack. Instead, we dynamically allocate
seperate mtx_debug structures on the fly in mtx_init, except for mutexes
that are initiated very early in the boot process. These mutexes
are declared using a special MUTEX_DECLARE() macro, and use a new
flag MTX_COLD when calling mtx_init. This is still somewhat hackish,
but it is less evil than the mtx_f filler struct, and the mtx struct is
now the same size with and without mutex debugging code.
- Add some micro-micro-operation macros for doing the actual atomic
operations on the mutex mtx_lock field to make it easier for other archs
to override/optimize mutex ops if needed. These new tiny ops also clean
up the code in some places by replacing long atomic operation function
calls that spanned 2-3 lines with a short 1-line macro call.
- Don't call mi_switch() from mtx_enter_hard() when we block while trying
to obtain a sleep mutex. Calling mi_switch() would bogusly release
Giant before switching to the next process. Instead, inline most of the
code from mi_switch() in the mtx_enter_hard() function. Note that when
we finally kill Giant we can back this out and go back to calling
mi_switch().
2000-10-20 07:26:37 +00:00
|
|
|
* and BSDI $Id: synch_machdep.c,v 2.3.2.39 2000/04/27 03:10:25 cp Exp $
|
2000-09-07 01:33:02 +00:00
|
|
|
*/
|
|
|
|
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
/*
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
* Implementation of the `witness' lock verifier. Originally implemented for
|
|
|
|
* mutexes in BSD/OS. Extended to handle generic lock objects and lock
|
|
|
|
* classes in FreeBSD.
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
*/
|
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
/*
|
|
|
|
* Main Entry: witness
|
|
|
|
* Pronunciation: 'wit-n&s
|
|
|
|
* Function: noun
|
|
|
|
* Etymology: Middle English witnesse, from Old English witnes knowledge,
|
|
|
|
* testimony, witness, from 2wit
|
|
|
|
* Date: before 12th century
|
|
|
|
* 1 : attestation of a fact or event : TESTIMONY
|
|
|
|
* 2 : one that gives evidence; specifically : one who testifies in
|
|
|
|
* a cause or before a judicial tribunal
|
|
|
|
* 3 : one asked to be present at a transaction so as to be able to
|
|
|
|
* testify to its having taken place
|
|
|
|
* 4 : one who has personal knowledge of something
|
|
|
|
* 5 a : something serving as evidence or proof : SIGN
|
|
|
|
* b : public affirmation by word or example of usually
|
|
|
|
* religious faith or conviction <the heroic witness to divine
|
|
|
|
* life -- Pilot>
|
|
|
|
* 6 capitalized : a member of the Jehovah's Witnesses
|
|
|
|
*/
|
|
|
|
|
2003-03-04 20:56:39 +00:00
|
|
|
/*
|
|
|
|
* Special rules concerning Giant and lock orders:
|
|
|
|
*
|
|
|
|
* 1) Giant must be acquired before any other mutexes. Stated another way,
|
|
|
|
* no other mutex may be held when Giant is acquired.
|
|
|
|
*
|
|
|
|
* 2) Giant must be released when blocking on a sleepable lock.
|
|
|
|
*
|
|
|
|
* This rule is less obvious, but is a result of Giant providing the same
|
|
|
|
* semantics as spl(). Basically, when a thread sleeps, it must release
|
|
|
|
* Giant. When a thread blocks on a sleepable lock, it sleeps. Hence rule
|
|
|
|
* 2).
|
|
|
|
*
|
|
|
|
* 3) Giant may be acquired before or after sleepable locks.
|
|
|
|
*
|
|
|
|
* This rule is also not quite as obvious. Giant may be acquired after
|
|
|
|
* a sleepable lock because it is a non-sleepable lock and non-sleepable
|
|
|
|
* locks may always be acquired while holding a sleepable lock. The second
|
|
|
|
* case, Giant before a sleepable lock, follows from rule 2) above. Suppose
|
|
|
|
* you have two threads T1 and T2 and a sleepable lock X. Suppose that T1
|
|
|
|
* acquires X and blocks on Giant. Then suppose that T2 acquires Giant and
|
|
|
|
* blocks on X. When T2 blocks on X, T2 will release Giant allowing T1 to
|
|
|
|
* execute. Thus, acquiring Giant both before and after a sleepable lock
|
|
|
|
* will not result in a lock order reversal.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-11-15 22:08:16 +00:00
|
|
|
#include "opt_ddb.h"
|
2007-04-19 08:02:51 +00:00
|
|
|
#include "opt_hwpmc_hooks.h"
|
2008-08-13 18:24:22 +00:00
|
|
|
#include "opt_stack.h"
|
2000-10-27 02:59:30 +00:00
|
|
|
#include "opt_witness.h"
|
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/param.h>
|
- Make the mutex code almost completely machine independent. This greatly
reducues the maintenance load for the mutex code. The only MD portions
of the mutex code are in machine/mutex.h now, which include the assembly
macros for handling mutexes as well as optionally overriding the mutex
micro-operations. For example, we use optimized micro-ops on the x86
platform #ifndef I386_CPU.
- Change the behavior of the SMP_DEBUG kernel option. In the new code,
mtx_assert() only depends on INVARIANTS, allowing other kernel developers
to have working mutex assertiions without having to include all of the
mutex debugging code. The SMP_DEBUG kernel option has been renamed to
MUTEX_DEBUG and now just controls extra mutex debugging code.
- Abolish the ugly mtx_f hack. Instead, we dynamically allocate
seperate mtx_debug structures on the fly in mtx_init, except for mutexes
that are initiated very early in the boot process. These mutexes
are declared using a special MUTEX_DECLARE() macro, and use a new
flag MTX_COLD when calling mtx_init. This is still somewhat hackish,
but it is less evil than the mtx_f filler struct, and the mtx struct is
now the same size with and without mutex debugging code.
- Add some micro-micro-operation macros for doing the actual atomic
operations on the mutex mtx_lock field to make it easier for other archs
to override/optimize mutex ops if needed. These new tiny ops also clean
up the code in some places by replacing long atomic operation function
calls that spanned 2-3 lines with a short 1-line macro call.
- Don't call mi_switch() from mtx_enter_hard() when we block while trying
to obtain a sleep mutex. Calling mi_switch() would bogusly release
Giant before switching to the next process. Instead, inline most of the
code from mi_switch() in the mtx_enter_hard() function. Note that when
we finally kill Giant we can back this out and go back to calling
mi_switch().
2000-10-20 07:26:37 +00:00
|
|
|
#include <sys/bus.h>
|
2004-07-10 21:42:16 +00:00
|
|
|
#include <sys/kdb.h>
|
- Make the mutex code almost completely machine independent. This greatly
reducues the maintenance load for the mutex code. The only MD portions
of the mutex code are in machine/mutex.h now, which include the assembly
macros for handling mutexes as well as optionally overriding the mutex
micro-operations. For example, we use optimized micro-ops on the x86
platform #ifndef I386_CPU.
- Change the behavior of the SMP_DEBUG kernel option. In the new code,
mtx_assert() only depends on INVARIANTS, allowing other kernel developers
to have working mutex assertiions without having to include all of the
mutex debugging code. The SMP_DEBUG kernel option has been renamed to
MUTEX_DEBUG and now just controls extra mutex debugging code.
- Abolish the ugly mtx_f hack. Instead, we dynamically allocate
seperate mtx_debug structures on the fly in mtx_init, except for mutexes
that are initiated very early in the boot process. These mutexes
are declared using a special MUTEX_DECLARE() macro, and use a new
flag MTX_COLD when calling mtx_init. This is still somewhat hackish,
but it is less evil than the mtx_f filler struct, and the mtx struct is
now the same size with and without mutex debugging code.
- Add some micro-micro-operation macros for doing the actual atomic
operations on the mutex mtx_lock field to make it easier for other archs
to override/optimize mutex ops if needed. These new tiny ops also clean
up the code in some places by replacing long atomic operation function
calls that spanned 2-3 lines with a short 1-line macro call.
- Don't call mi_switch() from mtx_enter_hard() when we block while trying
to obtain a sleep mutex. Calling mi_switch() would bogusly release
Giant before switching to the next process. Instead, inline most of the
code from mi_switch() in the mtx_enter_hard() function. Note that when
we finally kill Giant we can back this out and go back to calling
mi_switch().
2000-10-20 07:26:37 +00:00
|
|
|
#include <sys/kernel.h>
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
#include <sys/ktr.h>
|
|
|
|
#include <sys/lock.h>
|
- Make the mutex code almost completely machine independent. This greatly
reducues the maintenance load for the mutex code. The only MD portions
of the mutex code are in machine/mutex.h now, which include the assembly
macros for handling mutexes as well as optionally overriding the mutex
micro-operations. For example, we use optimized micro-ops on the x86
platform #ifndef I386_CPU.
- Change the behavior of the SMP_DEBUG kernel option. In the new code,
mtx_assert() only depends on INVARIANTS, allowing other kernel developers
to have working mutex assertiions without having to include all of the
mutex debugging code. The SMP_DEBUG kernel option has been renamed to
MUTEX_DEBUG and now just controls extra mutex debugging code.
- Abolish the ugly mtx_f hack. Instead, we dynamically allocate
seperate mtx_debug structures on the fly in mtx_init, except for mutexes
that are initiated very early in the boot process. These mutexes
are declared using a special MUTEX_DECLARE() macro, and use a new
flag MTX_COLD when calling mtx_init. This is still somewhat hackish,
but it is less evil than the mtx_f filler struct, and the mtx struct is
now the same size with and without mutex debugging code.
- Add some micro-micro-operation macros for doing the actual atomic
operations on the mutex mtx_lock field to make it easier for other archs
to override/optimize mutex ops if needed. These new tiny ops also clean
up the code in some places by replacing long atomic operation function
calls that spanned 2-3 lines with a short 1-line macro call.
- Don't call mi_switch() from mtx_enter_hard() when we block while trying
to obtain a sleep mutex. Calling mi_switch() would bogusly release
Giant before switching to the next process. Instead, inline most of the
code from mi_switch() in the mtx_enter_hard() function. Note that when
we finally kill Giant we can back this out and go back to calling
mi_switch().
2000-10-20 07:26:37 +00:00
|
|
|
#include <sys/malloc.h>
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
#include <sys/mutex.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/proc.h>
|
2008-05-07 21:41:36 +00:00
|
|
|
#include <sys/sbuf.h>
|
2008-10-16 12:42:56 +00:00
|
|
|
#include <sys/sched.h>
|
2008-08-13 18:24:22 +00:00
|
|
|
#include <sys/stack.h>
|
2000-10-27 02:59:30 +00:00
|
|
|
#include <sys/sysctl.h>
|
2015-11-19 05:56:59 +00:00
|
|
|
#include <sys/syslog.h>
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/systm.h>
|
- Make the mutex code almost completely machine independent. This greatly
reducues the maintenance load for the mutex code. The only MD portions
of the mutex code are in machine/mutex.h now, which include the assembly
macros for handling mutexes as well as optionally overriding the mutex
micro-operations. For example, we use optimized micro-ops on the x86
platform #ifndef I386_CPU.
- Change the behavior of the SMP_DEBUG kernel option. In the new code,
mtx_assert() only depends on INVARIANTS, allowing other kernel developers
to have working mutex assertiions without having to include all of the
mutex debugging code. The SMP_DEBUG kernel option has been renamed to
MUTEX_DEBUG and now just controls extra mutex debugging code.
- Abolish the ugly mtx_f hack. Instead, we dynamically allocate
seperate mtx_debug structures on the fly in mtx_init, except for mutexes
that are initiated very early in the boot process. These mutexes
are declared using a special MUTEX_DECLARE() macro, and use a new
flag MTX_COLD when calling mtx_init. This is still somewhat hackish,
but it is less evil than the mtx_f filler struct, and the mtx struct is
now the same size with and without mutex debugging code.
- Add some micro-micro-operation macros for doing the actual atomic
operations on the mutex mtx_lock field to make it easier for other archs
to override/optimize mutex ops if needed. These new tiny ops also clean
up the code in some places by replacing long atomic operation function
calls that spanned 2-3 lines with a short 1-line macro call.
- Don't call mi_switch() from mtx_enter_hard() when we block while trying
to obtain a sleep mutex. Calling mi_switch() would bogusly release
Giant before switching to the next process. Instead, inline most of the
code from mi_switch() in the mtx_enter_hard() function. Note that when
we finally kill Giant we can back this out and go back to calling
mi_switch().
2000-10-20 07:26:37 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
#ifdef DDB
|
2000-11-15 22:08:16 +00:00
|
|
|
#include <ddb/ddb.h>
|
2008-08-13 18:24:22 +00:00
|
|
|
#endif
|
2000-11-15 22:08:16 +00:00
|
|
|
|
2003-03-04 20:56:39 +00:00
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
#if !defined(DDB) && !defined(STACK)
|
|
|
|
#error "DDB or STACK options are required for WITNESS"
|
|
|
|
#endif
|
|
|
|
|
2006-01-25 14:57:23 +00:00
|
|
|
/* Note that these traces do not work with KTR_ALQ. */
|
2006-01-24 22:23:45 +00:00
|
|
|
#if 0
|
|
|
|
#define KTR_WITNESS KTR_SUBSYS
|
|
|
|
#else
|
|
|
|
#define KTR_WITNESS 0
|
|
|
|
#endif
|
|
|
|
|
2008-04-13 01:20:47 +00:00
|
|
|
#define LI_RECURSEMASK 0x0000ffff /* Recursion depth of lock instance. */
|
|
|
|
#define LI_EXCLUSIVE 0x00010000 /* Exclusive lock instance. */
|
2009-01-21 04:19:18 +00:00
|
|
|
#define LI_NORELEASE 0x00020000 /* Lock not allowed to be released. */
|
2008-04-13 01:20:47 +00:00
|
|
|
|
2002-10-20 08:48:39 +00:00
|
|
|
/* Define this to check for blessed mutexes */
|
|
|
|
#undef BLESSING
|
|
|
|
|
2014-08-03 05:00:43 +00:00
|
|
|
#ifndef WITNESS_COUNT
|
2014-01-20 01:59:35 +00:00
|
|
|
#define WITNESS_COUNT 1536
|
2014-08-03 05:00:43 +00:00
|
|
|
#endif
|
2008-08-13 18:24:22 +00:00
|
|
|
#define WITNESS_HASH_SIZE 251 /* Prime, gives load factor < 2 */
|
2014-04-29 17:22:29 +00:00
|
|
|
#define WITNESS_PENDLIST (1024 + MAXCPU)
|
2008-08-13 18:24:22 +00:00
|
|
|
|
|
|
|
/* Allocate 256 KB of stack data space */
|
|
|
|
#define WITNESS_LO_DATA_COUNT 2048
|
|
|
|
|
|
|
|
/* Prime, gives load factor of ~2 at full load */
|
|
|
|
#define WITNESS_LO_HASH_SIZE 1021
|
|
|
|
|
2001-01-24 10:57:01 +00:00
|
|
|
/*
|
2008-08-13 18:24:22 +00:00
|
|
|
* XXX: This is somewhat bogus, as we assume here that at most 2048 threads
|
|
|
|
* will hold LOCK_NCHILDREN locks. We handle failure ok, and we should
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
* probably be safe for the most part, but it's still a SWAG.
|
2001-01-24 10:57:01 +00:00
|
|
|
*/
|
2008-08-13 18:24:22 +00:00
|
|
|
#define LOCK_NCHILDREN 5
|
|
|
|
#define LOCK_CHILDCOUNT 2048
|
2001-01-24 10:57:01 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
#define MAX_W_NAME 64
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
|
2010-09-16 16:13:12 +00:00
|
|
|
#define FULLGRAPH_SBUF_SIZE 512
|
2008-04-13 01:20:47 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
|
|
|
* These flags go in the witness relationship matrix and describe the
|
|
|
|
* relationship between any two struct witness objects.
|
|
|
|
*/
|
|
|
|
#define WITNESS_UNRELATED 0x00 /* No lock order relation. */
|
|
|
|
#define WITNESS_PARENT 0x01 /* Parent, aka direct ancestor. */
|
|
|
|
#define WITNESS_ANCESTOR 0x02 /* Direct or indirect ancestor. */
|
|
|
|
#define WITNESS_CHILD 0x04 /* Child, aka direct descendant. */
|
|
|
|
#define WITNESS_DESCENDANT 0x08 /* Direct or indirect descendant. */
|
|
|
|
#define WITNESS_ANCESTOR_MASK (WITNESS_PARENT | WITNESS_ANCESTOR)
|
|
|
|
#define WITNESS_DESCENDANT_MASK (WITNESS_CHILD | WITNESS_DESCENDANT)
|
|
|
|
#define WITNESS_RELATED_MASK \
|
|
|
|
(WITNESS_ANCESTOR_MASK | WITNESS_DESCENDANT_MASK)
|
|
|
|
#define WITNESS_REVERSAL 0x10 /* A lock order reversal has been
|
|
|
|
* observed. */
|
|
|
|
#define WITNESS_RESERVED1 0x20 /* Unused flag, reserved. */
|
|
|
|
#define WITNESS_RESERVED2 0x40 /* Unused flag, reserved. */
|
|
|
|
#define WITNESS_LOCK_ORDER_KNOWN 0x80 /* This lock order is known. */
|
|
|
|
|
|
|
|
/* Descendant to ancestor flags */
|
|
|
|
#define WITNESS_DTOA(x) (((x) & WITNESS_RELATED_MASK) >> 2)
|
|
|
|
|
|
|
|
/* Ancestor to descendant flags */
|
|
|
|
#define WITNESS_ATOD(x) (((x) & WITNESS_RELATED_MASK) << 2)
|
|
|
|
|
|
|
|
#define WITNESS_INDEX_ASSERT(i) \
|
2014-10-11 02:02:58 +00:00
|
|
|
MPASS((i) > 0 && (i) <= w_max_used_index && (i) < witness_count)
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_WITNESS, "Witness", "Witness");
|
2001-01-21 07:52:20 +00:00
|
|
|
|
2008-04-13 01:20:47 +00:00
|
|
|
/*
|
|
|
|
* Lock instances. A lock instance is the data associated with a lock while
|
|
|
|
* it is held by witness. For example, a lock instance will hold the
|
|
|
|
* recursion count of a lock. Lock instances are held in lists. Spin locks
|
|
|
|
* are held in a per-cpu list while sleep locks are held in per-thread list.
|
|
|
|
*/
|
|
|
|
struct lock_instance {
|
2008-08-13 18:24:22 +00:00
|
|
|
struct lock_object *li_lock;
|
|
|
|
const char *li_file;
|
|
|
|
int li_line;
|
|
|
|
u_int li_flags;
|
2008-04-13 01:20:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A simple list type used to build the list of locks held by a thread
|
|
|
|
* or CPU. We can't simply embed the list in struct lock_object since a
|
|
|
|
* lock may be held by more than one thread if it is a shared lock. Locks
|
|
|
|
* are added to the head of the list, so we fill up each list entry from
|
|
|
|
* "the back" logically. To ease some of the arithmetic, we actually fill
|
|
|
|
* in each list entry the normal way (children[0] then children[1], etc.) but
|
|
|
|
* when we traverse the list we read children[count-1] as the first entry
|
|
|
|
* down to children[0] as the final entry.
|
|
|
|
*/
|
|
|
|
struct lock_list_entry {
|
|
|
|
struct lock_list_entry *ll_next;
|
|
|
|
struct lock_instance ll_children[LOCK_NCHILDREN];
|
|
|
|
u_int ll_count;
|
|
|
|
};
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
|
|
|
* The main witness structure. One of these per named lock type in the system
|
|
|
|
* (for example, "vnode interlock").
|
|
|
|
*/
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
struct witness {
|
2008-08-13 18:24:22 +00:00
|
|
|
char w_name[MAX_W_NAME];
|
|
|
|
uint32_t w_index; /* Index in the relationship matrix */
|
|
|
|
struct lock_class *w_class;
|
|
|
|
STAILQ_ENTRY(witness) w_list; /* List of all witnesses. */
|
|
|
|
STAILQ_ENTRY(witness) w_typelist; /* Witnesses of a type. */
|
|
|
|
struct witness *w_hash_next; /* Linked list in hash buckets. */
|
|
|
|
const char *w_file; /* File where last acquired */
|
|
|
|
uint32_t w_line; /* Line where last acquired */
|
|
|
|
uint32_t w_refcount;
|
|
|
|
uint16_t w_num_ancestors; /* direct/indirect
|
|
|
|
* ancestor count */
|
|
|
|
uint16_t w_num_descendants; /* direct/indirect
|
|
|
|
* descendant count */
|
|
|
|
int16_t w_ddb_level;
|
2009-02-03 07:50:41 +00:00
|
|
|
unsigned w_displayed:1;
|
|
|
|
unsigned w_reversed:1;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
};
|
2001-01-21 07:52:20 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
STAILQ_HEAD(witness_list, witness);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The witness hash table. Keys are witness names (const char *), elements are
|
|
|
|
* witness objects (struct witness *).
|
|
|
|
*/
|
|
|
|
struct witness_hash {
|
|
|
|
struct witness *wh_array[WITNESS_HASH_SIZE];
|
|
|
|
uint32_t wh_size;
|
|
|
|
uint32_t wh_count;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
};
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
|
|
|
* Key type for the lock order data hash table.
|
|
|
|
*/
|
|
|
|
struct witness_lock_order_key {
|
|
|
|
uint16_t from;
|
|
|
|
uint16_t to;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct witness_lock_order_data {
|
|
|
|
struct stack wlod_stack;
|
|
|
|
struct witness_lock_order_key wlod_key;
|
|
|
|
struct witness_lock_order_data *wlod_next;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The witness lock order data hash table. Keys are witness index tuples
|
|
|
|
* (struct witness_lock_order_key), elements are lock order data objects
|
|
|
|
* (struct witness_lock_order_data).
|
|
|
|
*/
|
|
|
|
struct witness_lock_order_hash {
|
|
|
|
struct witness_lock_order_data *wloh_array[WITNESS_LO_HASH_SIZE];
|
|
|
|
u_int wloh_size;
|
|
|
|
u_int wloh_count;
|
|
|
|
};
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2002-10-20 08:48:39 +00:00
|
|
|
#ifdef BLESSING
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
struct witness_blessed {
|
2008-08-13 18:24:22 +00:00
|
|
|
const char *b_lock1;
|
|
|
|
const char *b_lock2;
|
2000-09-14 20:15:16 +00:00
|
|
|
};
|
2002-10-20 08:48:39 +00:00
|
|
|
#endif
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2008-05-15 20:10:06 +00:00
|
|
|
struct witness_pendhelp {
|
|
|
|
const char *wh_type;
|
|
|
|
struct lock_object *wh_lock;
|
|
|
|
};
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
struct witness_order_list_entry {
|
|
|
|
const char *w_name;
|
|
|
|
struct lock_class *w_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns 0 if one of the locks is a spin lock and the other is not.
|
|
|
|
* Returns 1 otherwise.
|
|
|
|
*/
|
|
|
|
static __inline int
|
|
|
|
witness_lock_type_equal(struct witness *w1, struct witness *w2)
|
|
|
|
{
|
|
|
|
|
|
|
|
return ((w1->w_class->lc_flags & (LC_SLEEPLOCK | LC_SPINLOCK)) ==
|
|
|
|
(w2->w_class->lc_flags & (LC_SLEEPLOCK | LC_SPINLOCK)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int
|
|
|
|
witness_lock_order_key_equal(const struct witness_lock_order_key *a,
|
|
|
|
const struct witness_lock_order_key *b)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (a->from == b->from && a->to == b->to);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _isitmyx(struct witness *w1, struct witness *w2, int rmask,
|
|
|
|
const char *fname);
|
|
|
|
static void adopt(struct witness *parent, struct witness *child);
|
2003-03-11 22:07:35 +00:00
|
|
|
#ifdef BLESSING
|
|
|
|
static int blessed(struct witness *, struct witness *);
|
|
|
|
#endif
|
2008-05-15 20:10:06 +00:00
|
|
|
static void depart(struct witness *w);
|
2008-08-13 18:24:22 +00:00
|
|
|
static struct witness *enroll(const char *description,
|
|
|
|
struct lock_class *lock_class);
|
|
|
|
static struct lock_instance *find_instance(struct lock_list_entry *list,
|
2011-11-16 21:51:17 +00:00
|
|
|
const struct lock_object *lock);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
static int isitmychild(struct witness *parent, struct witness *child);
|
|
|
|
static int isitmydescendant(struct witness *parent, struct witness *child);
|
2008-08-13 18:24:22 +00:00
|
|
|
static void itismychild(struct witness *parent, struct witness *child);
|
|
|
|
static int sysctl_debug_witness_badstacks(SYSCTL_HANDLER_ARGS);
|
2003-03-24 21:03:53 +00:00
|
|
|
static int sysctl_debug_witness_watch(SYSCTL_HANDLER_ARGS);
|
2008-08-13 18:24:22 +00:00
|
|
|
static int sysctl_debug_witness_fullgraph(SYSCTL_HANDLER_ARGS);
|
2015-11-19 05:56:59 +00:00
|
|
|
static int sysctl_debug_witness_channel(SYSCTL_HANDLER_ARGS);
|
2008-08-13 18:24:22 +00:00
|
|
|
static void witness_add_fullgraph(struct sbuf *sb, struct witness *parent);
|
|
|
|
#ifdef DDB
|
|
|
|
static void witness_ddb_compute_levels(void);
|
2010-05-11 17:01:14 +00:00
|
|
|
static void witness_ddb_display(int(*)(const char *fmt, ...));
|
|
|
|
static void witness_ddb_display_descendants(int(*)(const char *fmt, ...),
|
2008-08-13 18:24:22 +00:00
|
|
|
struct witness *, int indent);
|
2010-05-11 17:01:14 +00:00
|
|
|
static void witness_ddb_display_list(int(*prnt)(const char *fmt, ...),
|
2008-08-13 18:24:22 +00:00
|
|
|
struct witness_list *list);
|
|
|
|
static void witness_ddb_level_descendants(struct witness *parent, int l);
|
|
|
|
static void witness_ddb_list(struct thread *td);
|
|
|
|
#endif
|
2015-11-19 05:56:59 +00:00
|
|
|
static void witness_debugger(int cond, const char *msg);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
static void witness_free(struct witness *m);
|
2008-08-13 18:24:22 +00:00
|
|
|
static struct witness *witness_get(void);
|
|
|
|
static uint32_t witness_hash_djb2(const uint8_t *key, uint32_t size);
|
|
|
|
static struct witness *witness_hash_get(const char *key);
|
|
|
|
static void witness_hash_put(struct witness *w);
|
|
|
|
static void witness_init_hash_tables(void);
|
|
|
|
static void witness_increment_graph_generation(void);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
static void witness_lock_list_free(struct lock_list_entry *lle);
|
2008-08-13 18:24:22 +00:00
|
|
|
static struct lock_list_entry *witness_lock_list_get(void);
|
|
|
|
static int witness_lock_order_add(struct witness *parent,
|
|
|
|
struct witness *child);
|
|
|
|
static int witness_lock_order_check(struct witness *parent,
|
|
|
|
struct witness *child);
|
|
|
|
static struct witness_lock_order_data *witness_lock_order_get(
|
|
|
|
struct witness *parent,
|
|
|
|
struct witness *child);
|
2010-05-11 18:24:22 +00:00
|
|
|
static void witness_list_lock(struct lock_instance *instance,
|
|
|
|
int (*prnt)(const char *fmt, ...));
|
2015-11-19 05:56:59 +00:00
|
|
|
static int witness_output(const char *fmt, ...) __printflike(1, 2);
|
|
|
|
static int witness_voutput(const char *fmt, va_list ap) __printflike(1, 0);
|
2009-01-21 04:19:18 +00:00
|
|
|
static void witness_setflag(struct lock_object *lock, int flag, int set);
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2011-11-07 15:43:11 +00:00
|
|
|
static SYSCTL_NODE(_debug, OID_AUTO, witness, CTLFLAG_RW, NULL,
|
|
|
|
"Witness Locking");
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
2003-03-24 21:03:53 +00:00
|
|
|
/*
|
2008-09-24 18:47:24 +00:00
|
|
|
* If set to 0, lock order checking is disabled. If set to -1,
|
|
|
|
* witness is completely disabled. Otherwise witness performs full
|
|
|
|
* lock order checking for all locks. At runtime, lock order checking
|
|
|
|
* may be toggled. However, witness cannot be reenabled once it is
|
|
|
|
* completely disabled.
|
2003-03-24 21:03:53 +00:00
|
|
|
*/
|
2001-06-06 22:17:08 +00:00
|
|
|
static int witness_watch = 1;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_PROC(_debug_witness, OID_AUTO, watch, CTLFLAG_RWTUN | CTLTYPE_INT, NULL, 0,
|
2003-03-24 21:03:53 +00:00
|
|
|
sysctl_debug_witness_watch, "I", "witness is watching lock operations");
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
2004-07-10 21:42:16 +00:00
|
|
|
#ifdef KDB
|
2000-09-07 01:33:02 +00:00
|
|
|
/*
|
2008-08-13 18:24:22 +00:00
|
|
|
* When KDB is enabled and witness_kdb is 1, it will cause the system
|
2004-07-10 21:42:16 +00:00
|
|
|
* to drop into kdebug() when:
|
2005-10-24 15:57:27 +00:00
|
|
|
* - a lock hierarchy violation occurs
|
2000-09-07 01:33:02 +00:00
|
|
|
* - locks are held when going to sleep.
|
|
|
|
*/
|
2004-07-10 21:42:16 +00:00
|
|
|
#ifdef WITNESS_KDB
|
|
|
|
int witness_kdb = 1;
|
2000-10-27 02:59:30 +00:00
|
|
|
#else
|
2004-07-10 21:42:16 +00:00
|
|
|
int witness_kdb = 0;
|
2000-09-07 01:33:02 +00:00
|
|
|
#endif
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_INT(_debug_witness, OID_AUTO, kdb, CTLFLAG_RWTUN, &witness_kdb, 0, "");
|
2015-11-19 05:56:59 +00:00
|
|
|
#endif /* KDB */
|
2003-02-13 01:35:56 +00:00
|
|
|
|
2015-11-19 05:56:59 +00:00
|
|
|
#if defined(DDB) || defined(KDB)
|
2003-02-13 01:35:56 +00:00
|
|
|
/*
|
2015-11-19 05:56:59 +00:00
|
|
|
* When DDB or KDB is enabled and witness_trace is 1, it will cause the system
|
2003-02-13 01:35:56 +00:00
|
|
|
* to print a stack trace:
|
2005-10-24 15:57:27 +00:00
|
|
|
* - a lock hierarchy violation occurs
|
2003-02-13 01:35:56 +00:00
|
|
|
* - locks are held when going to sleep.
|
|
|
|
*/
|
|
|
|
int witness_trace = 1;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_INT(_debug_witness, OID_AUTO, trace, CTLFLAG_RWTUN, &witness_trace, 0, "");
|
2015-11-19 05:56:59 +00:00
|
|
|
#endif /* DDB || KDB */
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2000-10-27 02:59:30 +00:00
|
|
|
#ifdef WITNESS_SKIPSPIN
|
2001-06-06 22:17:08 +00:00
|
|
|
int witness_skipspin = 1;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
#else
|
2001-06-06 22:17:08 +00:00
|
|
|
int witness_skipspin = 0;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
#endif
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_INT(_debug_witness, OID_AUTO, skipspin, CTLFLAG_RDTUN, &witness_skipspin, 0, "");
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2014-10-11 16:34:01 +00:00
|
|
|
int badstack_sbuf_size;
|
2014-10-11 02:02:58 +00:00
|
|
|
|
2014-10-11 16:34:01 +00:00
|
|
|
int witness_count = WITNESS_COUNT;
|
2014-10-11 02:02:58 +00:00
|
|
|
SYSCTL_INT(_debug_witness, OID_AUTO, witness_count, CTLFLAG_RDTUN,
|
|
|
|
&witness_count, 0, "");
|
|
|
|
|
2015-11-19 05:56:59 +00:00
|
|
|
/*
|
|
|
|
* Output channel for witness messages. By default we print to the console.
|
|
|
|
*/
|
|
|
|
enum witness_channel {
|
|
|
|
WITNESS_CONSOLE,
|
|
|
|
WITNESS_LOG,
|
|
|
|
WITNESS_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum witness_channel witness_channel = WITNESS_CONSOLE;
|
|
|
|
SYSCTL_PROC(_debug_witness, OID_AUTO, output_channel, CTLTYPE_STRING |
|
|
|
|
CTLFLAG_RWTUN, NULL, 0, sysctl_debug_witness_channel, "A",
|
|
|
|
"Output channel for warnings");
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
|
|
|
* Call this to print out the relations between locks.
|
|
|
|
*/
|
|
|
|
SYSCTL_PROC(_debug_witness, OID_AUTO, fullgraph, CTLTYPE_STRING | CTLFLAG_RD,
|
|
|
|
NULL, 0, sysctl_debug_witness_fullgraph, "A", "Show locks relation graphs");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call this to print out the witness faulty stacks.
|
|
|
|
*/
|
|
|
|
SYSCTL_PROC(_debug_witness, OID_AUTO, badstacks, CTLTYPE_STRING | CTLFLAG_RD,
|
|
|
|
NULL, 0, sysctl_debug_witness_badstacks, "A", "Show bad witness stacks");
|
2000-09-07 01:33:02 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
static struct mtx w_mtx;
|
2008-08-13 18:24:22 +00:00
|
|
|
|
|
|
|
/* w_list */
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
static struct witness_list w_free = STAILQ_HEAD_INITIALIZER(w_free);
|
|
|
|
static struct witness_list w_all = STAILQ_HEAD_INITIALIZER(w_all);
|
2008-08-13 18:24:22 +00:00
|
|
|
|
|
|
|
/* w_typelist */
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
static struct witness_list w_spin = STAILQ_HEAD_INITIALIZER(w_spin);
|
|
|
|
static struct witness_list w_sleep = STAILQ_HEAD_INITIALIZER(w_sleep);
|
2008-08-13 18:24:22 +00:00
|
|
|
|
|
|
|
/* lock list */
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
static struct lock_list_entry *w_lock_list_free = NULL;
|
2008-05-15 20:10:06 +00:00
|
|
|
static struct witness_pendhelp pending_locks[WITNESS_PENDLIST];
|
|
|
|
static u_int pending_cnt;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
static int w_free_cnt, w_spin_cnt, w_sleep_cnt;
|
2005-08-25 03:47:37 +00:00
|
|
|
SYSCTL_INT(_debug_witness, OID_AUTO, free_cnt, CTLFLAG_RD, &w_free_cnt, 0, "");
|
|
|
|
SYSCTL_INT(_debug_witness, OID_AUTO, spin_cnt, CTLFLAG_RD, &w_spin_cnt, 0, "");
|
|
|
|
SYSCTL_INT(_debug_witness, OID_AUTO, sleep_cnt, CTLFLAG_RD, &w_sleep_cnt, 0,
|
|
|
|
"");
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
static struct witness *w_data;
|
2014-10-11 02:02:58 +00:00
|
|
|
static uint8_t **w_rmatrix;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
static struct lock_list_entry w_locklistdata[LOCK_CHILDCOUNT];
|
2008-08-13 18:24:22 +00:00
|
|
|
static struct witness_hash w_hash; /* The witness hash table. */
|
|
|
|
|
|
|
|
/* The lock order data hash */
|
|
|
|
static struct witness_lock_order_data w_lodata[WITNESS_LO_DATA_COUNT];
|
|
|
|
static struct witness_lock_order_data *w_lofree = NULL;
|
|
|
|
static struct witness_lock_order_hash w_lohash;
|
|
|
|
static int w_max_used_index = 0;
|
|
|
|
static unsigned int w_generation = 0;
|
2009-09-06 13:31:05 +00:00
|
|
|
static const char w_notrunning[] = "Witness not running\n";
|
|
|
|
static const char w_stillcold[] = "Witness is still cold\n";
|
2008-08-13 18:24:22 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
|
|
|
static struct witness_order_list_entry order_lists[] = {
|
2005-09-02 20:23:49 +00:00
|
|
|
/*
|
|
|
|
* sx locks
|
|
|
|
*/
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
{ "proctree", &lock_class_sx },
|
|
|
|
{ "allproc", &lock_class_sx },
|
2007-04-05 23:32:32 +00:00
|
|
|
{ "allprison", &lock_class_sx },
|
2005-09-02 20:23:49 +00:00
|
|
|
{ NULL, NULL },
|
|
|
|
/*
|
|
|
|
* Various mutexes
|
|
|
|
*/
|
2003-03-06 17:25:06 +00:00
|
|
|
{ "Giant", &lock_class_mtx_sleep },
|
2002-12-22 16:32:34 +00:00
|
|
|
{ "pipe mutex", &lock_class_mtx_sleep },
|
2002-05-06 19:31:28 +00:00
|
|
|
{ "sigio lock", &lock_class_mtx_sleep },
|
2002-02-23 11:12:57 +00:00
|
|
|
{ "process group", &lock_class_mtx_sleep },
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
{ "process lock", &lock_class_mtx_sleep },
|
2002-02-23 11:12:57 +00:00
|
|
|
{ "session", &lock_class_mtx_sleep },
|
2008-03-17 11:48:40 +00:00
|
|
|
{ "uidinfo hash", &lock_class_rw },
|
2007-04-19 08:02:51 +00:00
|
|
|
#ifdef HWPMC_HOOKS
|
|
|
|
{ "pmc-sleep", &lock_class_mtx_sleep },
|
|
|
|
#endif
|
2010-06-21 21:15:51 +00:00
|
|
|
{ "time lock", &lock_class_mtx_sleep },
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
{ NULL, NULL },
|
2015-02-28 04:19:02 +00:00
|
|
|
/*
|
|
|
|
* umtx
|
|
|
|
*/
|
|
|
|
{ "umtx lock", &lock_class_mtx_sleep },
|
|
|
|
{ NULL, NULL },
|
2004-06-02 23:28:06 +00:00
|
|
|
/*
|
|
|
|
* Sockets
|
|
|
|
*/
|
|
|
|
{ "accept", &lock_class_mtx_sleep },
|
2004-06-13 00:23:03 +00:00
|
|
|
{ "so_snd", &lock_class_mtx_sleep },
|
|
|
|
{ "so_rcv", &lock_class_mtx_sleep },
|
2004-06-02 23:28:06 +00:00
|
|
|
{ "sellck", &lock_class_mtx_sleep },
|
|
|
|
{ NULL, NULL },
|
|
|
|
/*
|
|
|
|
* Routing
|
|
|
|
*/
|
2004-06-13 00:23:03 +00:00
|
|
|
{ "so_rcv", &lock_class_mtx_sleep },
|
2008-12-07 21:15:43 +00:00
|
|
|
{ "radix node head", &lock_class_rw },
|
2004-06-02 23:28:06 +00:00
|
|
|
{ "rtentry", &lock_class_mtx_sleep },
|
|
|
|
{ "ifaddr", &lock_class_mtx_sleep },
|
|
|
|
{ NULL, NULL },
|
Introduce in_multi_mtx, which will protect IPv4-layer multicast address
lists, as well as accessor macros. For now, this is a recursive mutex
due code sequences where IPv4 multicast calls into IGMP calls into
ip_output(), which then tests for a multicast forwarding case.
For support macros in in_var.h to check multicast address lists, assert
that in_multi_mtx is held.
Acquire in_multi_mtx around iteration over the IPv4 multicast address
lists, such as in ip_input() and ip_output().
Acquire in_multi_mtx when manipulating the IPv4 layer multicast addresses,
as well as over the manipulation of ifnet multicast address lists in order
to keep the two layers in sync.
Lock down accesses to IPv4 multicast addresses in IGMP, or assert the
lock when performing IGMP join/leave events.
Eliminate spl's associated with IPv4 multicast addresses, portions of
IGMP that weren't previously expunged by IGMP locking.
Add in_multi_mtx, igmp_mtx, and if_addr_mtx lock order to hard-coded
lock order in WITNESS, in that order.
Problem reported by: Ed Maste <emaste at phaedrus dot sandvine dot ca>
MFC after: 10 days
2005-08-03 19:29:47 +00:00
|
|
|
/*
|
Bite the bullet, and make the IPv6 SSM and MLDv2 mega-commit:
import from p4 bms_netdev. Summary of changes:
* Connect netinet6/in6_mcast.c to build.
The legacy KAME KPIs are mostly preserved.
* Eliminate now dead code from ip6_output.c.
Don't do mbuf bingo, we are not going to do RFC 2292 style
CMSG tricks for multicast options as they are not required
by any current IPv6 normative reference.
* Refactor transports (UDP, raw_ip6) to do own mcast filtering.
SCTP, TCP unaffected by this change.
* Add ip6_msource, in6_msource structs to in6_var.h.
* Hookup mld_ifinfo state to in6_ifextra, allocate from
domifattach path.
* Eliminate IN6_LOOKUP_MULTI(), it is no longer referenced.
Kernel consumers which need this should use in6m_lookup().
* Refactor IPv6 socket group memberships to use a vector (like IPv4).
* Update ifmcstat(8) for IPv6 SSM.
* Add witness lock order for IN6_MULTI_LOCK.
* Move IN6_MULTI_LOCK out of lower ip6_output()/ip6_input() paths.
* Introduce IP6STAT_ADD/SUB/INC/DEC as per rwatson's IPv4 cleanup.
* Update carp(4) for new IPv6 SSM KPIs.
* Virtualize ip6_mrouter socket.
Changes mostly localized to IPv6 MROUTING.
* Don't do a local group lookup in MROUTING.
* Kill unused KAME prototypes in6_purgemkludge(), in6_restoremkludge().
* Preserve KAME DAD timer jitter behaviour in MLDv1 compatibility mode.
* Bump __FreeBSD_version to 800084.
* Update UPDATING.
NOTE WELL:
* This code hasn't been tested against real MLDv2 queriers
(yet), although the on-wire protocol has been verified in Wireshark.
* There are a few unresolved issues in the socket layer APIs to
do with scope ID propagation.
* There is a LOR present in ip6_output()'s use of
in6_setscope() which needs to be resolved. See comments in mld6.c.
This is believed to be benign and can't be avoided for the moment
without re-introducing an indirect netisr.
This work was mostly derived from the IGMPv3 implementation, and
has been sponsored by a third party.
2009-04-29 19:19:13 +00:00
|
|
|
* IPv4 multicast:
|
|
|
|
* protocol locks before interface locks, after UDP locks.
|
Introduce in_multi_mtx, which will protect IPv4-layer multicast address
lists, as well as accessor macros. For now, this is a recursive mutex
due code sequences where IPv4 multicast calls into IGMP calls into
ip_output(), which then tests for a multicast forwarding case.
For support macros in in_var.h to check multicast address lists, assert
that in_multi_mtx is held.
Acquire in_multi_mtx around iteration over the IPv4 multicast address
lists, such as in ip_input() and ip_output().
Acquire in_multi_mtx when manipulating the IPv4 layer multicast addresses,
as well as over the manipulation of ifnet multicast address lists in order
to keep the two layers in sync.
Lock down accesses to IPv4 multicast addresses in IGMP, or assert the
lock when performing IGMP join/leave events.
Eliminate spl's associated with IPv4 multicast addresses, portions of
IGMP that weren't previously expunged by IGMP locking.
Add in_multi_mtx, igmp_mtx, and if_addr_mtx lock order to hard-coded
lock order in WITNESS, in that order.
Problem reported by: Ed Maste <emaste at phaedrus dot sandvine dot ca>
MFC after: 10 days
2005-08-03 19:29:47 +00:00
|
|
|
*/
|
2008-04-17 21:38:18 +00:00
|
|
|
{ "udpinp", &lock_class_rw },
|
Introduce in_multi_mtx, which will protect IPv4-layer multicast address
lists, as well as accessor macros. For now, this is a recursive mutex
due code sequences where IPv4 multicast calls into IGMP calls into
ip_output(), which then tests for a multicast forwarding case.
For support macros in in_var.h to check multicast address lists, assert
that in_multi_mtx is held.
Acquire in_multi_mtx around iteration over the IPv4 multicast address
lists, such as in ip_input() and ip_output().
Acquire in_multi_mtx when manipulating the IPv4 layer multicast addresses,
as well as over the manipulation of ifnet multicast address lists in order
to keep the two layers in sync.
Lock down accesses to IPv4 multicast addresses in IGMP, or assert the
lock when performing IGMP join/leave events.
Eliminate spl's associated with IPv4 multicast addresses, portions of
IGMP that weren't previously expunged by IGMP locking.
Add in_multi_mtx, igmp_mtx, and if_addr_mtx lock order to hard-coded
lock order in WITNESS, in that order.
Problem reported by: Ed Maste <emaste at phaedrus dot sandvine dot ca>
MFC after: 10 days
2005-08-03 19:29:47 +00:00
|
|
|
{ "in_multi_mtx", &lock_class_mtx_sleep },
|
|
|
|
{ "igmp_mtx", &lock_class_mtx_sleep },
|
2012-01-09 19:34:12 +00:00
|
|
|
{ "if_addr_lock", &lock_class_rw },
|
Introduce in_multi_mtx, which will protect IPv4-layer multicast address
lists, as well as accessor macros. For now, this is a recursive mutex
due code sequences where IPv4 multicast calls into IGMP calls into
ip_output(), which then tests for a multicast forwarding case.
For support macros in in_var.h to check multicast address lists, assert
that in_multi_mtx is held.
Acquire in_multi_mtx around iteration over the IPv4 multicast address
lists, such as in ip_input() and ip_output().
Acquire in_multi_mtx when manipulating the IPv4 layer multicast addresses,
as well as over the manipulation of ifnet multicast address lists in order
to keep the two layers in sync.
Lock down accesses to IPv4 multicast addresses in IGMP, or assert the
lock when performing IGMP join/leave events.
Eliminate spl's associated with IPv4 multicast addresses, portions of
IGMP that weren't previously expunged by IGMP locking.
Add in_multi_mtx, igmp_mtx, and if_addr_mtx lock order to hard-coded
lock order in WITNESS, in that order.
Problem reported by: Ed Maste <emaste at phaedrus dot sandvine dot ca>
MFC after: 10 days
2005-08-03 19:29:47 +00:00
|
|
|
{ NULL, NULL },
|
Bite the bullet, and make the IPv6 SSM and MLDv2 mega-commit:
import from p4 bms_netdev. Summary of changes:
* Connect netinet6/in6_mcast.c to build.
The legacy KAME KPIs are mostly preserved.
* Eliminate now dead code from ip6_output.c.
Don't do mbuf bingo, we are not going to do RFC 2292 style
CMSG tricks for multicast options as they are not required
by any current IPv6 normative reference.
* Refactor transports (UDP, raw_ip6) to do own mcast filtering.
SCTP, TCP unaffected by this change.
* Add ip6_msource, in6_msource structs to in6_var.h.
* Hookup mld_ifinfo state to in6_ifextra, allocate from
domifattach path.
* Eliminate IN6_LOOKUP_MULTI(), it is no longer referenced.
Kernel consumers which need this should use in6m_lookup().
* Refactor IPv6 socket group memberships to use a vector (like IPv4).
* Update ifmcstat(8) for IPv6 SSM.
* Add witness lock order for IN6_MULTI_LOCK.
* Move IN6_MULTI_LOCK out of lower ip6_output()/ip6_input() paths.
* Introduce IP6STAT_ADD/SUB/INC/DEC as per rwatson's IPv4 cleanup.
* Update carp(4) for new IPv6 SSM KPIs.
* Virtualize ip6_mrouter socket.
Changes mostly localized to IPv6 MROUTING.
* Don't do a local group lookup in MROUTING.
* Kill unused KAME prototypes in6_purgemkludge(), in6_restoremkludge().
* Preserve KAME DAD timer jitter behaviour in MLDv1 compatibility mode.
* Bump __FreeBSD_version to 800084.
* Update UPDATING.
NOTE WELL:
* This code hasn't been tested against real MLDv2 queriers
(yet), although the on-wire protocol has been verified in Wireshark.
* There are a few unresolved issues in the socket layer APIs to
do with scope ID propagation.
* There is a LOR present in ip6_output()'s use of
in6_setscope() which needs to be resolved. See comments in mld6.c.
This is believed to be benign and can't be avoided for the moment
without re-introducing an indirect netisr.
This work was mostly derived from the IGMPv3 implementation, and
has been sponsored by a third party.
2009-04-29 19:19:13 +00:00
|
|
|
/*
|
|
|
|
* IPv6 multicast:
|
|
|
|
* protocol locks before interface locks, after UDP locks.
|
|
|
|
*/
|
|
|
|
{ "udpinp", &lock_class_rw },
|
|
|
|
{ "in6_multi_mtx", &lock_class_mtx_sleep },
|
|
|
|
{ "mld_mtx", &lock_class_mtx_sleep },
|
2012-01-09 19:34:12 +00:00
|
|
|
{ "if_addr_lock", &lock_class_rw },
|
Bite the bullet, and make the IPv6 SSM and MLDv2 mega-commit:
import from p4 bms_netdev. Summary of changes:
* Connect netinet6/in6_mcast.c to build.
The legacy KAME KPIs are mostly preserved.
* Eliminate now dead code from ip6_output.c.
Don't do mbuf bingo, we are not going to do RFC 2292 style
CMSG tricks for multicast options as they are not required
by any current IPv6 normative reference.
* Refactor transports (UDP, raw_ip6) to do own mcast filtering.
SCTP, TCP unaffected by this change.
* Add ip6_msource, in6_msource structs to in6_var.h.
* Hookup mld_ifinfo state to in6_ifextra, allocate from
domifattach path.
* Eliminate IN6_LOOKUP_MULTI(), it is no longer referenced.
Kernel consumers which need this should use in6m_lookup().
* Refactor IPv6 socket group memberships to use a vector (like IPv4).
* Update ifmcstat(8) for IPv6 SSM.
* Add witness lock order for IN6_MULTI_LOCK.
* Move IN6_MULTI_LOCK out of lower ip6_output()/ip6_input() paths.
* Introduce IP6STAT_ADD/SUB/INC/DEC as per rwatson's IPv4 cleanup.
* Update carp(4) for new IPv6 SSM KPIs.
* Virtualize ip6_mrouter socket.
Changes mostly localized to IPv6 MROUTING.
* Don't do a local group lookup in MROUTING.
* Kill unused KAME prototypes in6_purgemkludge(), in6_restoremkludge().
* Preserve KAME DAD timer jitter behaviour in MLDv1 compatibility mode.
* Bump __FreeBSD_version to 800084.
* Update UPDATING.
NOTE WELL:
* This code hasn't been tested against real MLDv2 queriers
(yet), although the on-wire protocol has been verified in Wireshark.
* There are a few unresolved issues in the socket layer APIs to
do with scope ID propagation.
* There is a LOR present in ip6_output()'s use of
in6_setscope() which needs to be resolved. See comments in mld6.c.
This is believed to be benign and can't be avoided for the moment
without re-introducing an indirect netisr.
This work was mostly derived from the IGMPv3 implementation, and
has been sponsored by a third party.
2009-04-29 19:19:13 +00:00
|
|
|
{ NULL, NULL },
|
2004-06-02 23:28:06 +00:00
|
|
|
/*
|
|
|
|
* UNIX Domain Sockets
|
2004-06-03 20:07:44 +00:00
|
|
|
*/
|
2014-10-20 20:21:40 +00:00
|
|
|
{ "unp_link_rwlock", &lock_class_rw },
|
2009-03-08 21:48:29 +00:00
|
|
|
{ "unp_list_lock", &lock_class_mtx_sleep },
|
2004-06-13 00:23:03 +00:00
|
|
|
{ "unp", &lock_class_mtx_sleep },
|
|
|
|
{ "so_snd", &lock_class_mtx_sleep },
|
|
|
|
{ NULL, NULL },
|
2004-06-02 23:28:06 +00:00
|
|
|
/*
|
|
|
|
* UDP/IP
|
|
|
|
*/
|
2008-04-17 21:38:18 +00:00
|
|
|
{ "udp", &lock_class_rw },
|
|
|
|
{ "udpinp", &lock_class_rw },
|
2004-06-13 00:23:03 +00:00
|
|
|
{ "so_snd", &lock_class_mtx_sleep },
|
2004-06-02 23:28:06 +00:00
|
|
|
{ NULL, NULL },
|
|
|
|
/*
|
|
|
|
* TCP/IP
|
|
|
|
*/
|
2008-04-17 21:38:18 +00:00
|
|
|
{ "tcp", &lock_class_rw },
|
|
|
|
{ "tcpinp", &lock_class_rw },
|
2004-06-13 00:23:03 +00:00
|
|
|
{ "so_snd", &lock_class_mtx_sleep },
|
2004-06-02 23:28:06 +00:00
|
|
|
{ NULL, NULL },
|
2004-09-09 05:01:37 +00:00
|
|
|
/*
|
|
|
|
* BPF
|
|
|
|
*/
|
|
|
|
{ "bpf global lock", &lock_class_mtx_sleep },
|
2012-04-06 06:53:58 +00:00
|
|
|
{ "bpf interface lock", &lock_class_rw },
|
2012-05-21 22:17:29 +00:00
|
|
|
{ "bpf cdev lock", &lock_class_mtx_sleep },
|
2005-04-09 11:31:31 +00:00
|
|
|
{ NULL, NULL },
|
2005-03-09 21:38:53 +00:00
|
|
|
/*
|
|
|
|
* NFS server
|
|
|
|
*/
|
|
|
|
{ "nfsd_mtx", &lock_class_mtx_sleep },
|
|
|
|
{ "so_snd", &lock_class_mtx_sleep },
|
2004-09-09 05:01:37 +00:00
|
|
|
{ NULL, NULL },
|
Update 802.11 wireless support:
o major overhaul of the way channels are handled: channels are now
fully enumerated and uniquely identify the operating characteristics;
these changes are visible to user applications which require changes
o make scanning support independent of the state machine to enable
background scanning and roaming
o move scanning support into loadable modules based on the operating
mode to enable different policies and reduce the memory footprint
on systems w/ constrained resources
o add background scanning in station mode (no support for adhoc/ibss
mode yet)
o significantly speedup sta mode scanning with a variety of techniques
o add roaming support when background scanning is supported; for now
we use a simple algorithm to trigger a roam: we threshold the rssi
and tx rate, if either drops too low we try to roam to a new ap
o add tx fragmentation support
o add first cut at 802.11n support: this code works with forthcoming
drivers but is incomplete; it's included now to establish a baseline
for other drivers to be developed and for user applications
o adjust max_linkhdr et. al. to reflect 802.11 requirements; this eliminates
prepending mbufs for traffic generated locally
o add support for Atheros protocol extensions; mainly the fast frames
encapsulation (note this can be used with any card that can tx+rx
large frames correctly)
o add sta support for ap's that beacon both WPA1+2 support
o change all data types from bsd-style to posix-style
o propagate noise floor data from drivers to net80211 and on to user apps
o correct various issues in the sta mode state machine related to handling
authentication and association failures
o enable the addition of sta mode power save support for drivers that need
net80211 support (not in this commit)
o remove old WI compatibility ioctls (wicontrol is officially dead)
o change the data structures returned for get sta info and get scan
results so future additions will not break user apps
o fixed tx rate is now maintained internally as an ieee rate and not an
index into the rate set; this needs to be extended to deal with
multi-mode operation
o add extended channel specifications to radiotap to enable 11n sniffing
Drivers:
o ath: add support for bg scanning, tx fragmentation, fast frames,
dynamic turbo (lightly tested), 11n (sniffing only and needs
new hal)
o awi: compile tested only
o ndis: lightly tested
o ipw: lightly tested
o iwi: add support for bg scanning (well tested but may have some
rough edges)
o ral, ural, rum: add suppoort for bg scanning, calibrate rssi data
o wi: lightly tested
This work is based on contributions by Atheros, kmacy, sephe, thompsa,
mlaier, kevlo, and others. Much of the scanning work was supported by
Atheros. The 11n work was supported by Marvell.
2007-06-11 03:36:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IEEE 802.11
|
|
|
|
*/
|
|
|
|
{ "802.11 com lock", &lock_class_mtx_sleep},
|
|
|
|
{ NULL, NULL },
|
|
|
|
/*
|
|
|
|
* Network drivers
|
|
|
|
*/
|
|
|
|
{ "network driver", &lock_class_mtx_sleep},
|
|
|
|
{ NULL, NULL },
|
|
|
|
|
2007-04-01 15:48:10 +00:00
|
|
|
/*
|
|
|
|
* Netgraph
|
|
|
|
*/
|
|
|
|
{ "ng_node", &lock_class_mtx_sleep },
|
|
|
|
{ "ng_worklist", &lock_class_mtx_sleep },
|
|
|
|
{ NULL, NULL },
|
2005-04-09 13:32:01 +00:00
|
|
|
/*
|
|
|
|
* CDEV
|
|
|
|
*/
|
2012-06-27 03:45:25 +00:00
|
|
|
{ "vm map (system)", &lock_class_mtx_sleep },
|
|
|
|
{ "vm page queue", &lock_class_mtx_sleep },
|
2005-04-22 22:43:31 +00:00
|
|
|
{ "vnode interlock", &lock_class_mtx_sleep },
|
|
|
|
{ "cdev", &lock_class_mtx_sleep },
|
2005-04-09 13:32:01 +00:00
|
|
|
{ NULL, NULL },
|
2010-04-30 00:46:43 +00:00
|
|
|
/*
|
|
|
|
* VM
|
|
|
|
*/
|
2012-06-27 03:45:25 +00:00
|
|
|
{ "vm map (user)", &lock_class_sx },
|
2013-03-09 10:16:08 +00:00
|
|
|
{ "vm object", &lock_class_rw },
|
2012-06-27 03:45:25 +00:00
|
|
|
{ "vm page", &lock_class_mtx_sleep },
|
|
|
|
{ "vm page queue", &lock_class_mtx_sleep },
|
|
|
|
{ "pmap pv global", &lock_class_rw },
|
2010-04-30 00:46:43 +00:00
|
|
|
{ "pmap", &lock_class_mtx_sleep },
|
2012-06-27 03:45:25 +00:00
|
|
|
{ "pmap pv list", &lock_class_rw },
|
|
|
|
{ "vm page free queue", &lock_class_mtx_sleep },
|
2010-04-30 00:46:43 +00:00
|
|
|
{ NULL, NULL },
|
2007-02-02 09:02:18 +00:00
|
|
|
/*
|
|
|
|
* kqueue/VFS interaction
|
|
|
|
*/
|
|
|
|
{ "kqueue", &lock_class_mtx_sleep },
|
|
|
|
{ "struct mount mtx", &lock_class_mtx_sleep },
|
|
|
|
{ "vnode interlock", &lock_class_mtx_sleep },
|
|
|
|
{ NULL, NULL },
|
2009-05-20 02:51:48 +00:00
|
|
|
/*
|
|
|
|
* ZFS locking
|
|
|
|
*/
|
|
|
|
{ "dn->dn_mtx", &lock_class_sx },
|
|
|
|
{ "dr->dt.di.dr_mtx", &lock_class_sx },
|
|
|
|
{ "db->db_mtx", &lock_class_sx },
|
|
|
|
{ NULL, NULL },
|
2001-04-13 08:31:38 +00:00
|
|
|
/*
|
|
|
|
* spin locks
|
|
|
|
*/
|
2001-10-01 22:50:30 +00:00
|
|
|
#ifdef SMP
|
|
|
|
{ "ap boot", &lock_class_mtx_spin },
|
2001-02-09 15:19:41 +00:00
|
|
|
#endif
|
2005-09-26 18:30:12 +00:00
|
|
|
{ "rm.mutex_mtx", &lock_class_mtx_spin },
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
{ "sio", &lock_class_mtx_spin },
|
2007-11-24 04:32:32 +00:00
|
|
|
{ "scrlock", &lock_class_mtx_spin },
|
2001-02-09 15:19:41 +00:00
|
|
|
#ifdef __i386__
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
{ "cy", &lock_class_mtx_spin },
|
2007-06-16 23:30:57 +00:00
|
|
|
#endif
|
|
|
|
#ifdef __sparc64__
|
|
|
|
{ "pcib_mtx", &lock_class_mtx_spin },
|
|
|
|
{ "rtc_mtx", &lock_class_mtx_spin },
|
2001-02-09 15:19:41 +00:00
|
|
|
#endif
|
2006-04-07 22:15:54 +00:00
|
|
|
{ "scc_hwmtx", &lock_class_mtx_spin },
|
2004-01-25 15:04:37 +00:00
|
|
|
{ "uart_hwmtx", &lock_class_mtx_spin },
|
2006-08-26 11:21:25 +00:00
|
|
|
{ "fast_taskqueue", &lock_class_mtx_spin },
|
2003-11-03 22:38:30 +00:00
|
|
|
{ "intr table", &lock_class_mtx_spin },
|
2007-04-19 08:02:51 +00:00
|
|
|
#ifdef HWPMC_HOOKS
|
|
|
|
{ "pmc-per-proc", &lock_class_mtx_spin },
|
|
|
|
#endif
|
Commit 10/14 of sched_lock decomposition.
- Add new spinlocks to support thread_lock() and adjust ordering.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-04 23:55:45 +00:00
|
|
|
{ "process slock", &lock_class_mtx_spin },
|
2004-02-27 18:33:09 +00:00
|
|
|
{ "sleepq chain", &lock_class_mtx_spin },
|
2007-11-24 04:32:32 +00:00
|
|
|
{ "rm_spinlock", &lock_class_mtx_spin },
|
Add an implementation of turnstiles and change the sleep mutex code to use
turnstiles to implement blocking isntead of implementing a thread queue
directly. These turnstiles are somewhat similar to those used in Solaris 7
as described in Solaris Internals but are also different.
Turnstiles do not come out of a fixed-sized pool. Rather, each thread is
assigned a turnstile when it is created that it frees when it is destroyed.
When a thread blocks on a lock, it donates its turnstile to that lock to
serve as queue of blocked threads. The queue associated with a given lock
is found by a lookup in a simple hash table. The turnstile itself is
protected by a lock associated with its entry in the hash table. This
means that sched_lock is no longer needed to contest on a mutex. Instead,
sched_lock is only used when manipulating run queues or thread priorities.
Turnstiles also implement priority propagation inherently.
Currently turnstiles only support mutexes. Eventually, however, turnstiles
may grow two queue's to support a non-sleepable reader/writer lock
implementation. For more details, see the comments in sys/turnstile.h and
kern/subr_turnstile.c.
The two primary advantages from the turnstile code include: 1) the size
of struct mutex shrinks by four pointers as it no longer stores the
thread queue linkages directly, and 2) less contention on sched_lock in
SMP systems including the ability for multiple CPUs to contend on different
locks simultaneously (not that this last detail is necessarily that much of
a big win). Note that 1) means that this commit is a kernel ABI breaker,
so don't mix old modules with a new kernel and vice versa.
Tested on: i386 SMP, sparc64 SMP, alpha SMP
2003-11-11 22:07:29 +00:00
|
|
|
{ "turnstile chain", &lock_class_mtx_spin },
|
Commit 10/14 of sched_lock decomposition.
- Add new spinlocks to support thread_lock() and adjust ordering.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-04 23:55:45 +00:00
|
|
|
{ "turnstile lock", &lock_class_mtx_spin },
|
|
|
|
{ "sched lock", &lock_class_mtx_spin },
|
Add an implementation of turnstiles and change the sleep mutex code to use
turnstiles to implement blocking isntead of implementing a thread queue
directly. These turnstiles are somewhat similar to those used in Solaris 7
as described in Solaris Internals but are also different.
Turnstiles do not come out of a fixed-sized pool. Rather, each thread is
assigned a turnstile when it is created that it frees when it is destroyed.
When a thread blocks on a lock, it donates its turnstile to that lock to
serve as queue of blocked threads. The queue associated with a given lock
is found by a lookup in a simple hash table. The turnstile itself is
protected by a lock associated with its entry in the hash table. This
means that sched_lock is no longer needed to contest on a mutex. Instead,
sched_lock is only used when manipulating run queues or thread priorities.
Turnstiles also implement priority propagation inherently.
Currently turnstiles only support mutexes. Eventually, however, turnstiles
may grow two queue's to support a non-sleepable reader/writer lock
implementation. For more details, see the comments in sys/turnstile.h and
kern/subr_turnstile.c.
The two primary advantages from the turnstile code include: 1) the size
of struct mutex shrinks by four pointers as it no longer stores the
thread queue linkages directly, and 2) less contention on sched_lock in
SMP systems including the ability for multiple CPUs to contend on different
locks simultaneously (not that this last detail is necessarily that much of
a big win). Note that 1) means that this commit is a kernel ABI breaker,
so don't mix old modules with a new kernel and vice versa.
Tested on: i386 SMP, sparc64 SMP, alpha SMP
2003-11-11 22:07:29 +00:00
|
|
|
{ "td_contested", &lock_class_mtx_spin },
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
{ "callout", &lock_class_mtx_spin },
|
2004-10-11 08:26:18 +00:00
|
|
|
{ "entropy harvest mutex", &lock_class_mtx_spin },
|
2006-09-13 15:48:15 +00:00
|
|
|
{ "syscons video lock", &lock_class_mtx_spin },
|
2007-09-20 20:38:43 +00:00
|
|
|
#ifdef SMP
|
|
|
|
{ "smp rendezvous", &lock_class_mtx_spin },
|
2008-03-03 17:17:00 +00:00
|
|
|
#endif
|
|
|
|
#ifdef __powerpc__
|
|
|
|
{ "tlb0", &lock_class_mtx_spin },
|
2007-09-20 20:38:43 +00:00
|
|
|
#endif
|
2000-09-07 01:33:02 +00:00
|
|
|
/*
|
|
|
|
* leaf locks
|
|
|
|
*/
|
2008-04-12 13:51:18 +00:00
|
|
|
{ "intrcnt", &lock_class_mtx_spin },
|
2001-12-20 23:48:31 +00:00
|
|
|
{ "icu", &lock_class_mtx_spin },
|
o Revert the other functional half of r239864, i. e. the merge of r134227
from x86 to use smp_ipi_mtx spin lock not only for smp_rendezvous_cpus()
but also for the MD cache invalidation, TLB demapping and remote register
reading IPIs due to the following reasons:
- The cross-IPI SMP deadlock x86 otherwise is subject to can't happen on
sparc64. That's because on sparc64, spin locks don't disable interrupts
completely but only raise the processor interrupt level to PIL_TICK. This
means that IPIs still get delivered and direct dispatch IPIs such as the
cache invalidation etc. IPIs in question are still executed.
- In smp_rendezvous_cpus(), smp_ipi_mtx is held not only while sending an
IPI_RENDEZVOUS, but until all CPUs have processed smp_rendezvous_action().
Consequently, smp_ipi_mtx may be locked for an extended amount of time as
queued IPIs (as opposed to the direct ones) such as IPI_RENDEZVOUS are
scheduled via a soft interrupt. Moreover, given that this soft interrupt
is only delivered at PIL_RENDEZVOUS, processing of smp_rendezvous_action()
on a target may be interrupted by f. e. a tick interrupt at PIL_TICK, in
turn leading to the target in question trying to send an IPI by itself
while IPI_RENDEZVOUS isn't fully handled, yet, and, thus, resulting in a
deadlock.
o As mentioned in the commit message of r245850, on least some sun4u platforms
concurrent sending of IPIs by different CPUs is fatal. Therefore, hold the
reintroduced MD ipi_mtx also while delivering cross-traps via MI helpers,
i. e. ipi_{all_but_self,cpu,selected}().
o Akin to x86, let the last CPU to process cpu_mp_bootstrap() set smp_started
instead of the BSP in cpu_mp_unleash(). This ensures that all APs actually
are started, when smp_started is no longer 0.
o In all MD and MI IPI helpers, check for smp_started == 1 rather than for
smp_cpus > 1 or nothing at all. This avoids races during boot causing IPIs
trying to be delivered to APs that in fact aren't up and running, yet.
While at it, move setting of the cpu_ipi_{selected,single}() pointers to
the appropriate delivery functions from mp_init() to cpu_mp_start() where
it's better suited and allows to get rid of the global isjbus variable.
o Given that now concurrent IPI delivery no longer is possible, also nuke
the delays before completely disabling interrupts again in the CPU-specific
cross-trap delivery functions, previously giving other CPUs a window for
sending IPIs on their part. Actually, we now should be able to entirely get
rid of completely disabling interrupts in these functions. Such a change
needs more testing, though.
o In {s,}tick_get_timecount_mp(), make the {s,}tick variable static. While not
necessary for correctness, this avoids page faults when accessing the stack
of a foreign CPU as {s,}tick now is locked into the TLBs as part of static
kernel data. Hence, {s,}tick_get_timecount_mp() always execute as fast as
possible, avoiding jitter.
PR: 201245
MFC after: 3 days
2015-07-24 15:13:21 +00:00
|
|
|
#if defined(SMP) && defined(__sparc64__)
|
|
|
|
{ "ipi", &lock_class_mtx_spin },
|
|
|
|
#endif
|
2007-09-20 20:38:43 +00:00
|
|
|
#ifdef __i386__
|
|
|
|
{ "allpmaps", &lock_class_mtx_spin },
|
|
|
|
{ "descriptor tables", &lock_class_mtx_spin },
|
2001-02-09 15:19:41 +00:00
|
|
|
#endif
|
2001-06-25 23:17:52 +00:00
|
|
|
{ "clk", &lock_class_mtx_spin },
|
2008-04-12 13:51:18 +00:00
|
|
|
{ "cpuset", &lock_class_mtx_spin },
|
2007-09-20 20:38:43 +00:00
|
|
|
{ "mprof lock", &lock_class_mtx_spin },
|
Commit 10/14 of sched_lock decomposition.
- Add new spinlocks to support thread_lock() and adjust ordering.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-04 23:55:45 +00:00
|
|
|
{ "zombie lock", &lock_class_mtx_spin },
|
2002-09-22 07:11:57 +00:00
|
|
|
{ "ALD Queue", &lock_class_mtx_spin },
|
2003-05-31 06:42:37 +00:00
|
|
|
#if defined(__i386__) || defined(__amd64__)
|
2003-02-18 03:36:49 +00:00
|
|
|
{ "pcicfg", &lock_class_mtx_spin },
|
When you call MiniportInitialize() for an 802.11 driver, it will
at some point result in a status event being triggered (it should
be a link down event: the Microsoft driver design guide says you
should generate one when the NIC is initialized). Some drivers
generate the event during MiniportInitialize(), such that by the
time MiniportInitialize() completes, the NIC is ready to go. But
some drivers, in particular the ones for Atheros wireless NICs,
don't generate the event until after a device interrupt occurs
at some point after MiniportInitialize() has completed.
The gotcha is that you have to wait until the link status event
occurs one way or the other before you try to fiddle with any
settings (ssid, channel, etc...). For the drivers that set the
event sycnhronously this isn't a problem, but for the others
we have to pause after calling ndis_init_nic() and wait for the event
to arrive before continuing. Failing to wait can cause big trouble:
on my SMP system, calling ndis_setstate_80211() after ndis_init_nic()
completes, but _before_ the link event arrives, will lock up or
reset the system.
What we do now is check to see if a link event arrived while
ndis_init_nic() was running, and if it didn't we msleep() until
it does.
Along the way, I discovered a few other problems:
- Defered procedure calls run at PASSIVE_LEVEL, not DISPATCH_LEVEL.
ntoskrnl_run_dpc() has been fixed accordingly. (I read the documentation
wrong.)
- Similarly, the NDIS interrupt handler, which is essentially a
DPC, also doesn't need to run at DISPATCH_LEVEL. ndis_intrtask()
has been fixed accordingly.
- MiniportQueryInformation() and MiniportSetInformation() run at
DISPATCH_LEVEL, and each request must complete before another
can be submitted. ndis_get_info() and ndis_set_info() have been
fixed accordingly.
- Turned the sleep lock that guards the NDIS thread job list into
a spin lock. We never do anything with this lock held except manage
the job list (no other locks are held), so it's safe to do this,
and it's possible that ndis_sched() and ndis_unsched() can be
called from DISPATCH_LEVEL, so using a sleep lock here is
semantically incorrect. Also updated subr_witness.c to add the
lock to the order list.
2005-03-07 03:05:31 +00:00
|
|
|
{ "NDIS thread lock", &lock_class_mtx_spin },
|
2002-10-12 00:33:36 +00:00
|
|
|
#endif
|
2005-04-12 22:07:11 +00:00
|
|
|
{ "tw_osl_io_lock", &lock_class_mtx_spin },
|
|
|
|
{ "tw_osl_q_lock", &lock_class_mtx_spin },
|
|
|
|
{ "tw_cl_io_lock", &lock_class_mtx_spin },
|
|
|
|
{ "tw_cl_intr_lock", &lock_class_mtx_spin },
|
|
|
|
{ "tw_cl_gen_lock", &lock_class_mtx_spin },
|
2007-04-19 08:02:51 +00:00
|
|
|
#ifdef HWPMC_HOOKS
|
|
|
|
{ "pmc-leaf", &lock_class_mtx_spin },
|
|
|
|
#endif
|
Commit 10/14 of sched_lock decomposition.
- Add new spinlocks to support thread_lock() and adjust ordering.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-04 23:55:45 +00:00
|
|
|
{ "blocked lock", &lock_class_mtx_spin },
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
{ NULL, NULL },
|
|
|
|
{ NULL, NULL }
|
2000-09-07 01:33:02 +00:00
|
|
|
};
|
|
|
|
|
2002-10-20 08:48:39 +00:00
|
|
|
#ifdef BLESSING
|
2000-09-07 01:33:02 +00:00
|
|
|
/*
|
|
|
|
* Pairs of locks which have been blessed
|
|
|
|
* Don't complain about order problems with blessed locks
|
|
|
|
*/
|
2000-09-14 20:15:16 +00:00
|
|
|
static struct witness_blessed blessed_list[] = {
|
2000-09-07 01:33:02 +00:00
|
|
|
};
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
static int blessed_count =
|
|
|
|
sizeof(blessed_list) / sizeof(struct witness_blessed);
|
2002-10-20 08:48:39 +00:00
|
|
|
#endif
|
2000-09-07 01:33:02 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
/*
|
|
|
|
* This global is set to 0 once it becomes safe to use the witness code.
|
|
|
|
*/
|
|
|
|
static int witness_cold = 1;
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2005-10-24 20:14:24 +00:00
|
|
|
/*
|
|
|
|
* This global is set to 1 once the static lock orders have been enrolled
|
|
|
|
* so that a warning can be issued for any spin locks enrolled later.
|
|
|
|
*/
|
|
|
|
static int witness_spin_warn = 0;
|
|
|
|
|
2011-10-26 15:17:42 +00:00
|
|
|
/* Trim useless garbage from filenames. */
|
|
|
|
static const char *
|
|
|
|
fixup_filename(const char *file)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (file == NULL)
|
|
|
|
return (NULL);
|
|
|
|
while (strncmp(file, "../", 3) == 0)
|
|
|
|
file += 3;
|
|
|
|
return (file);
|
|
|
|
}
|
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
/*
|
2005-12-05 20:45:24 +00:00
|
|
|
* The WITNESS-enabled diagnostic code. Note that the witness code does
|
|
|
|
* assume that the early boot is single-threaded at least until after this
|
|
|
|
* routine is completed.
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
*/
|
2001-01-21 22:34:43 +00:00
|
|
|
static void
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
witness_initialize(void *dummy __unused)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
struct lock_object *lock;
|
|
|
|
struct witness_order_list_entry *order;
|
|
|
|
struct witness *w, *w1;
|
|
|
|
int i;
|
|
|
|
|
2014-10-11 02:02:58 +00:00
|
|
|
w_data = malloc(sizeof (struct witness) * witness_count, M_WITNESS,
|
2014-10-11 16:34:01 +00:00
|
|
|
M_WAITOK | M_ZERO);
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2014-10-11 16:34:01 +00:00
|
|
|
w_rmatrix = malloc(sizeof(*w_rmatrix) * (witness_count + 1),
|
|
|
|
M_WITNESS, M_WAITOK | M_ZERO);
|
2014-10-11 02:02:58 +00:00
|
|
|
|
2014-10-11 16:34:01 +00:00
|
|
|
for (i = 0; i < witness_count + 1; i++) {
|
|
|
|
w_rmatrix[i] = malloc(sizeof(*w_rmatrix[i]) *
|
|
|
|
(witness_count + 1), M_WITNESS, M_WAITOK | M_ZERO);
|
2014-10-11 02:02:58 +00:00
|
|
|
}
|
|
|
|
badstack_sbuf_size = witness_count * 256;
|
2014-10-11 16:34:01 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
/*
|
|
|
|
* We have to release Giant before initializing its witness
|
|
|
|
* structure so that WITNESS doesn't get confused.
|
|
|
|
*/
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
mtx_assert(&Giant, MA_NOTOWNED);
|
|
|
|
|
2001-12-10 05:40:12 +00:00
|
|
|
CTR1(KTR_WITNESS, "%s: initializing witness", __func__);
|
2002-04-04 20:45:21 +00:00
|
|
|
mtx_init(&w_mtx, "witness lock", NULL, MTX_SPIN | MTX_QUIET |
|
2006-11-11 03:18:07 +00:00
|
|
|
MTX_NOWITNESS | MTX_NOPROFILE);
|
2014-10-11 02:02:58 +00:00
|
|
|
for (i = witness_count - 1; i >= 0; i--) {
|
2008-08-13 18:24:22 +00:00
|
|
|
w = &w_data[i];
|
|
|
|
memset(w, 0, sizeof(*w));
|
|
|
|
w_data[i].w_index = i; /* Witness index never changes. */
|
|
|
|
witness_free(w);
|
|
|
|
}
|
|
|
|
KASSERT(STAILQ_FIRST(&w_free)->w_index == 0,
|
|
|
|
("%s: Invalid list of free witness objects", __func__));
|
|
|
|
|
|
|
|
/* Witness with index 0 is not used to aid in debugging. */
|
|
|
|
STAILQ_REMOVE_HEAD(&w_free, w_list);
|
|
|
|
w_free_cnt--;
|
|
|
|
|
2014-10-11 16:34:01 +00:00
|
|
|
for (i = 0; i < witness_count; i++) {
|
|
|
|
memset(w_rmatrix[i], 0, sizeof(*w_rmatrix[i]) *
|
2014-10-11 02:02:58 +00:00
|
|
|
(witness_count + 1));
|
|
|
|
}
|
2008-08-13 18:24:22 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
for (i = 0; i < LOCK_CHILDCOUNT; i++)
|
|
|
|
witness_lock_list_free(&w_locklistdata[i]);
|
2008-08-13 18:24:22 +00:00
|
|
|
witness_init_hash_tables();
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
|
|
|
/* First add in all the specified order lists. */
|
|
|
|
for (order = order_lists; order->w_name != NULL; order++) {
|
|
|
|
w = enroll(order->w_name, order->w_class);
|
2001-04-17 03:35:38 +00:00
|
|
|
if (w == NULL)
|
|
|
|
continue;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
w->w_file = "order list";
|
|
|
|
for (order++; order->w_name != NULL; order++) {
|
|
|
|
w1 = enroll(order->w_name, order->w_class);
|
2001-04-17 03:35:38 +00:00
|
|
|
if (w1 == NULL)
|
|
|
|
continue;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
w1->w_file = "order list";
|
2008-08-13 18:24:22 +00:00
|
|
|
itismychild(w, w1);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
w = w1;
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-24 20:14:24 +00:00
|
|
|
witness_spin_warn = 1;
|
2000-09-07 01:33:02 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
/* Iterate through all locks and add them to witness. */
|
2008-05-15 20:10:06 +00:00
|
|
|
for (i = 0; pending_locks[i].wh_lock != NULL; i++) {
|
|
|
|
lock = pending_locks[i].wh_lock;
|
2005-12-05 20:45:24 +00:00
|
|
|
KASSERT(lock->lo_flags & LO_WITNESS,
|
|
|
|
("%s: lock %s is on pending list but not LO_WITNESS",
|
|
|
|
__func__, lock->lo_name));
|
2008-05-15 20:10:06 +00:00
|
|
|
lock->lo_witness = enroll(pending_locks[i].wh_type,
|
|
|
|
LOCK_CLASS(lock));
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark the witness code as being ready for use. */
|
2005-10-24 20:14:24 +00:00
|
|
|
witness_cold = 0;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
}
|
2008-03-16 10:58:09 +00:00
|
|
|
SYSINIT(witness_init, SI_SUB_WITNESS, SI_ORDER_FIRST, witness_initialize,
|
|
|
|
NULL);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
|
|
|
void
|
2008-05-15 20:10:06 +00:00
|
|
|
witness_init(struct lock_object *lock, const char *type)
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
{
|
|
|
|
struct lock_class *class;
|
|
|
|
|
2005-12-05 20:45:24 +00:00
|
|
|
/* Various sanity checks. */
|
2006-01-06 18:07:32 +00:00
|
|
|
class = LOCK_CLASS(lock);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
if ((lock->lo_flags & LO_RECURSABLE) != 0 &&
|
|
|
|
(class->lc_flags & LC_RECURSABLE) == 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("%s: lock (%s) %s can not be recursable",
|
|
|
|
__func__, class->lc_name, lock->lo_name);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
if ((lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
|
|
|
(class->lc_flags & LC_SLEEPABLE) == 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("%s: lock (%s) %s can not be sleepable",
|
|
|
|
__func__, class->lc_name, lock->lo_name);
|
2001-08-23 22:47:05 +00:00
|
|
|
if ((lock->lo_flags & LO_UPGRADABLE) != 0 &&
|
|
|
|
(class->lc_flags & LC_UPGRADABLE) == 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("%s: lock (%s) %s can not be upgradable",
|
|
|
|
__func__, class->lc_name, lock->lo_name);
|
2001-08-23 22:47:05 +00:00
|
|
|
|
2005-12-05 20:45:24 +00:00
|
|
|
/*
|
|
|
|
* If we shouldn't watch this lock, then just clear lo_witness.
|
|
|
|
* Otherwise, if witness_cold is set, then it is too early to
|
|
|
|
* enroll this lock, so defer it to witness_initialize() by adding
|
|
|
|
* it to the pending_locks list. If it is not too early, then enroll
|
|
|
|
* the lock now.
|
|
|
|
*/
|
2008-08-29 15:47:53 +00:00
|
|
|
if (witness_watch < 1 || panicstr != NULL ||
|
2005-12-05 20:45:24 +00:00
|
|
|
(lock->lo_flags & LO_WITNESS) == 0)
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
lock->lo_witness = NULL;
|
2005-12-05 20:45:24 +00:00
|
|
|
else if (witness_cold) {
|
2008-05-15 20:10:06 +00:00
|
|
|
pending_locks[pending_cnt].wh_lock = lock;
|
|
|
|
pending_locks[pending_cnt++].wh_type = type;
|
|
|
|
if (pending_cnt > WITNESS_PENDLIST)
|
2012-12-11 01:23:50 +00:00
|
|
|
panic("%s: pending locks list is too small, "
|
|
|
|
"increase WITNESS_PENDLIST\n",
|
2008-05-15 20:10:06 +00:00
|
|
|
__func__);
|
2005-12-05 20:45:24 +00:00
|
|
|
} else
|
2008-05-15 20:10:06 +00:00
|
|
|
lock->lo_witness = enroll(type, class);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
witness_destroy(struct lock_object *lock)
|
|
|
|
{
|
2006-01-06 18:07:32 +00:00
|
|
|
struct lock_class *class;
|
2001-04-09 22:34:05 +00:00
|
|
|
struct witness *w;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
2006-01-06 18:07:32 +00:00
|
|
|
class = LOCK_CLASS(lock);
|
2008-08-13 18:24:22 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
if (witness_cold)
|
|
|
|
panic("lock (%s) %s destroyed while witness_cold",
|
2006-01-06 18:07:32 +00:00
|
|
|
class->lc_name, lock->lo_name);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
2001-05-04 17:15:16 +00:00
|
|
|
/* XXX: need to verify that no one holds the lock */
|
2008-08-13 18:24:22 +00:00
|
|
|
if ((lock->lo_flags & LO_WITNESS) == 0 || lock->lo_witness == NULL)
|
|
|
|
return;
|
|
|
|
w = lock->lo_witness;
|
2003-03-11 22:07:35 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
mtx_lock_spin(&w_mtx);
|
|
|
|
MPASS(w->w_refcount > 0);
|
|
|
|
w->w_refcount--;
|
|
|
|
|
|
|
|
if (w->w_refcount == 0)
|
|
|
|
depart(w);
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
2003-03-11 21:38:49 +00:00
|
|
|
#ifdef DDB
|
2005-09-11 07:57:06 +00:00
|
|
|
static void
|
2008-08-13 18:24:22 +00:00
|
|
|
witness_ddb_compute_levels(void)
|
2005-09-11 07:57:06 +00:00
|
|
|
{
|
2008-08-13 18:24:22 +00:00
|
|
|
struct witness *w;
|
2005-09-11 07:57:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First clear all levels.
|
|
|
|
*/
|
2008-08-13 18:24:22 +00:00
|
|
|
STAILQ_FOREACH(w, &w_all, w_list)
|
|
|
|
w->w_ddb_level = -1;
|
2005-09-11 07:57:06 +00:00
|
|
|
|
|
|
|
/*
|
2008-08-13 18:24:22 +00:00
|
|
|
* Look for locks with no parents and level all their descendants.
|
2005-09-11 07:57:06 +00:00
|
|
|
*/
|
|
|
|
STAILQ_FOREACH(w, &w_all, w_list) {
|
2008-08-13 18:24:22 +00:00
|
|
|
|
|
|
|
/* If the witness has ancestors (is not a root), skip it. */
|
|
|
|
if (w->w_num_ancestors > 0)
|
|
|
|
continue;
|
|
|
|
witness_ddb_level_descendants(w, 0);
|
2005-09-11 07:57:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-08-13 18:24:22 +00:00
|
|
|
witness_ddb_level_descendants(struct witness *w, int l)
|
2005-09-11 07:57:06 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
if (w->w_ddb_level >= l)
|
|
|
|
return;
|
|
|
|
|
|
|
|
w->w_ddb_level = l;
|
|
|
|
l++;
|
|
|
|
|
|
|
|
for (i = 1; i <= w_max_used_index; i++) {
|
|
|
|
if (w_rmatrix[w->w_index][i] & WITNESS_PARENT)
|
|
|
|
witness_ddb_level_descendants(&w_data[i], l);
|
|
|
|
}
|
2005-09-11 07:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-11 17:01:14 +00:00
|
|
|
witness_ddb_display_descendants(int(*prnt)(const char *fmt, ...),
|
2008-08-13 18:24:22 +00:00
|
|
|
struct witness *w, int indent)
|
2005-09-11 07:57:06 +00:00
|
|
|
{
|
2008-08-13 18:24:22 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < indent; i++)
|
|
|
|
prnt(" ");
|
|
|
|
prnt("%s (type: %s, depth: %d, active refs: %d)",
|
|
|
|
w->w_name, w->w_class->lc_name,
|
|
|
|
w->w_ddb_level, w->w_refcount);
|
|
|
|
if (w->w_displayed) {
|
|
|
|
prnt(" -- (already displayed)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
w->w_displayed = 1;
|
|
|
|
if (w->w_file != NULL && w->w_line != 0)
|
2011-10-26 15:17:42 +00:00
|
|
|
prnt(" -- last acquired @ %s:%d\n", fixup_filename(w->w_file),
|
2008-08-13 18:24:22 +00:00
|
|
|
w->w_line);
|
2005-09-11 07:57:06 +00:00
|
|
|
else
|
2008-08-13 18:24:22 +00:00
|
|
|
prnt(" -- never acquired\n");
|
|
|
|
indent++;
|
|
|
|
WITNESS_INDEX_ASSERT(w->w_index);
|
|
|
|
for (i = 1; i <= w_max_used_index; i++) {
|
2012-08-22 20:00:41 +00:00
|
|
|
if (db_pager_quit)
|
|
|
|
return;
|
2008-08-13 18:24:22 +00:00
|
|
|
if (w_rmatrix[w->w_index][i] & WITNESS_PARENT)
|
|
|
|
witness_ddb_display_descendants(prnt, &w_data[i],
|
|
|
|
indent);
|
2005-09-11 07:57:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-21 22:34:43 +00:00
|
|
|
static void
|
2010-05-11 17:01:14 +00:00
|
|
|
witness_ddb_display_list(int(*prnt)(const char *fmt, ...),
|
2008-08-13 18:24:22 +00:00
|
|
|
struct witness_list *list)
|
2001-01-21 22:34:43 +00:00
|
|
|
{
|
2003-03-11 22:14:21 +00:00
|
|
|
struct witness *w;
|
2001-01-21 22:34:43 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
STAILQ_FOREACH(w, list, w_typelist) {
|
2008-08-13 18:24:22 +00:00
|
|
|
if (w->w_file == NULL || w->w_ddb_level > 0)
|
2001-01-21 22:34:43 +00:00
|
|
|
continue;
|
2008-08-13 18:24:22 +00:00
|
|
|
|
|
|
|
/* This lock has no anscestors - display its descendants. */
|
|
|
|
witness_ddb_display_descendants(prnt, w, 0);
|
2012-08-22 20:00:41 +00:00
|
|
|
if (db_pager_quit)
|
|
|
|
return;
|
2001-01-21 22:34:43 +00:00
|
|
|
}
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
}
|
|
|
|
|
2008-05-07 21:41:36 +00:00
|
|
|
static void
|
2010-05-11 17:01:14 +00:00
|
|
|
witness_ddb_display(int(*prnt)(const char *fmt, ...))
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
{
|
|
|
|
struct witness *w;
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
KASSERT(witness_cold == 0, ("%s: witness_cold", __func__));
|
|
|
|
witness_ddb_compute_levels();
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
2003-03-11 22:14:21 +00:00
|
|
|
/* Clear all the displayed flags. */
|
2008-08-13 18:24:22 +00:00
|
|
|
STAILQ_FOREACH(w, &w_all, w_list)
|
2003-03-11 22:14:21 +00:00
|
|
|
w->w_displayed = 0;
|
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
/*
|
2001-03-28 12:39:40 +00:00
|
|
|
* First, handle sleep locks which have been acquired at least
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
* once.
|
|
|
|
*/
|
|
|
|
prnt("Sleep locks:\n");
|
2008-08-13 18:24:22 +00:00
|
|
|
witness_ddb_display_list(prnt, &w_sleep);
|
2012-08-22 20:00:41 +00:00
|
|
|
if (db_pager_quit)
|
|
|
|
return;
|
2001-02-09 15:19:41 +00:00
|
|
|
|
|
|
|
/*
|
2001-03-28 12:39:40 +00:00
|
|
|
* Now do spin locks which have been acquired at least once.
|
2001-02-09 15:19:41 +00:00
|
|
|
*/
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
prnt("\nSpin locks:\n");
|
2008-08-13 18:24:22 +00:00
|
|
|
witness_ddb_display_list(prnt, &w_spin);
|
2012-08-22 20:00:41 +00:00
|
|
|
if (db_pager_quit)
|
|
|
|
return;
|
2001-02-09 15:19:41 +00:00
|
|
|
|
|
|
|
/*
|
2001-03-28 12:39:40 +00:00
|
|
|
* Finally, any locks which have not been acquired yet.
|
2001-02-09 15:19:41 +00:00
|
|
|
*/
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
prnt("\nLocks which were never acquired:\n");
|
|
|
|
STAILQ_FOREACH(w, &w_all, w_list) {
|
2002-06-06 19:04:38 +00:00
|
|
|
if (w->w_file != NULL || w->w_refcount == 0)
|
2001-01-21 22:34:43 +00:00
|
|
|
continue;
|
2008-08-13 18:24:22 +00:00
|
|
|
prnt("%s (type: %s, depth: %d)\n", w->w_name,
|
|
|
|
w->w_class->lc_name, w->w_ddb_level);
|
2012-08-22 20:00:41 +00:00
|
|
|
if (db_pager_quit)
|
|
|
|
return;
|
2001-01-21 22:34:43 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-11 21:38:49 +00:00
|
|
|
#endif /* DDB */
|
2001-01-21 22:34:43 +00:00
|
|
|
|
2004-01-28 20:39:57 +00:00
|
|
|
int
|
|
|
|
witness_defineorder(struct lock_object *lock1, struct lock_object *lock2)
|
|
|
|
{
|
|
|
|
|
2008-08-30 13:20:35 +00:00
|
|
|
if (witness_watch == -1 || panicstr != NULL)
|
2004-01-28 20:39:57 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Require locks that witness knows about. */
|
|
|
|
if (lock1 == NULL || lock1->lo_witness == NULL || lock2 == NULL ||
|
|
|
|
lock2->lo_witness == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
mtx_assert(&w_mtx, MA_NOTOWNED);
|
2004-01-28 20:39:57 +00:00
|
|
|
mtx_lock_spin(&w_mtx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we already have either an explicit or implied lock order that
|
|
|
|
* is the other way around, then return an error.
|
|
|
|
*/
|
2008-08-30 13:20:35 +00:00
|
|
|
if (witness_watch &&
|
|
|
|
isitmydescendant(lock2->lo_witness, lock1->lo_witness)) {
|
2004-01-28 20:39:57 +00:00
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
return (EDOOFUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to add the new order. */
|
|
|
|
CTR3(KTR_WITNESS, "%s: adding %s as a child of %s", __func__,
|
2008-05-15 20:10:06 +00:00
|
|
|
lock2->lo_witness->w_name, lock1->lo_witness->w_name);
|
2008-08-13 18:24:22 +00:00
|
|
|
itismychild(lock1->lo_witness, lock2->lo_witness);
|
2004-01-28 20:39:57 +00:00
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
void
|
2004-01-28 20:39:57 +00:00
|
|
|
witness_checkorder(struct lock_object *lock, int flags, const char *file,
|
2008-09-10 19:13:30 +00:00
|
|
|
int line, struct lock_object *interlock)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
2008-10-16 12:42:56 +00:00
|
|
|
struct lock_list_entry *lock_list, *lle;
|
2008-09-10 19:13:30 +00:00
|
|
|
struct lock_instance *lock1, *lock2, *plock;
|
2013-06-03 17:41:11 +00:00
|
|
|
struct lock_class *class, *iclass;
|
2000-09-14 20:15:16 +00:00
|
|
|
struct witness *w, *w1;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
int i, j;
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2008-08-29 15:47:53 +00:00
|
|
|
if (witness_cold || witness_watch < 1 || lock->lo_witness == NULL ||
|
2001-07-31 17:44:57 +00:00
|
|
|
panicstr != NULL)
|
2000-12-13 21:53:42 +00:00
|
|
|
return;
|
2004-01-28 20:39:57 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
w = lock->lo_witness;
|
2006-01-06 18:07:32 +00:00
|
|
|
class = LOCK_CLASS(lock);
|
2001-09-12 08:38:13 +00:00
|
|
|
td = curthread;
|
2000-09-07 01:33:02 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
if (class->lc_flags & LC_SLEEPLOCK) {
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2002-04-02 16:51:20 +00:00
|
|
|
/*
|
|
|
|
* Since spin locks include a critical section, this check
|
2004-07-09 17:46:27 +00:00
|
|
|
* implicitly enforces a lock order of all sleep locks before
|
2002-04-02 16:51:20 +00:00
|
|
|
* all spin locks.
|
|
|
|
*/
|
2004-10-09 08:16:37 +00:00
|
|
|
if (td->td_critnest != 0 && !kdb_active)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("acquiring blockable sleep lock with "
|
|
|
|
"spinlock or critical section held (%s) %s @ %s:%d",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2004-07-09 17:46:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is the first lock acquired then just return as
|
|
|
|
* no order checking is needed.
|
|
|
|
*/
|
2008-10-16 12:42:56 +00:00
|
|
|
lock_list = td->td_sleeplocks;
|
|
|
|
if (lock_list == NULL || lock_list->ll_count == 0)
|
2004-07-09 17:46:27 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2004-07-09 17:46:27 +00:00
|
|
|
/*
|
|
|
|
* If this is the first lock, just return as no order
|
2008-10-16 12:42:56 +00:00
|
|
|
* checking is needed. Avoid problems with thread
|
|
|
|
* migration pinning the thread while checking if
|
|
|
|
* spinlocks are held. If at least one spinlock is held
|
|
|
|
* the thread is in a safe path and it is allowed to
|
|
|
|
* unpin it.
|
2004-07-09 17:46:27 +00:00
|
|
|
*/
|
2008-10-16 12:42:56 +00:00
|
|
|
sched_pin();
|
|
|
|
lock_list = PCPU_GET(spinlocks);
|
|
|
|
if (lock_list == NULL || lock_list->ll_count == 0) {
|
|
|
|
sched_unpin();
|
2004-07-09 17:46:27 +00:00
|
|
|
return;
|
2008-10-16 12:42:56 +00:00
|
|
|
}
|
|
|
|
sched_unpin();
|
2004-07-09 17:46:27 +00:00
|
|
|
}
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2001-05-04 17:15:16 +00:00
|
|
|
/*
|
2004-01-28 20:39:57 +00:00
|
|
|
* Check to see if we are recursing on a lock we already own. If
|
|
|
|
* so, make sure that we don't mismatch exclusive and shared lock
|
|
|
|
* acquires.
|
2001-05-04 17:15:16 +00:00
|
|
|
*/
|
2008-10-16 12:42:56 +00:00
|
|
|
lock1 = find_instance(lock_list, lock);
|
2001-05-04 17:15:16 +00:00
|
|
|
if (lock1 != NULL) {
|
|
|
|
if ((lock1->li_flags & LI_EXCLUSIVE) != 0 &&
|
|
|
|
(flags & LOP_EXCLUSIVE) == 0) {
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output("shared lock of (%s) %s @ %s:%d\n",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output("while exclusively locked from %s:%d\n",
|
2011-10-12 09:21:02 +00:00
|
|
|
fixup_filename(lock1->li_file), lock1->li_line);
|
2013-06-03 17:41:11 +00:00
|
|
|
kassert_panic("excl->share");
|
2001-05-04 17:15:16 +00:00
|
|
|
}
|
|
|
|
if ((lock1->li_flags & LI_EXCLUSIVE) == 0 &&
|
|
|
|
(flags & LOP_EXCLUSIVE) != 0) {
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output("exclusive lock of (%s) %s @ %s:%d\n",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output("while share locked from %s:%d\n",
|
2011-10-12 09:21:02 +00:00
|
|
|
fixup_filename(lock1->li_file), lock1->li_line);
|
2013-06-03 17:41:11 +00:00
|
|
|
kassert_panic("share->excl");
|
2001-05-04 17:15:16 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-03 17:41:11 +00:00
|
|
|
/* Warn if the interlock is not locked exactly once. */
|
|
|
|
if (interlock != NULL) {
|
|
|
|
iclass = LOCK_CLASS(interlock);
|
|
|
|
lock1 = find_instance(lock_list, interlock);
|
|
|
|
if (lock1 == NULL)
|
2013-09-04 11:52:28 +00:00
|
|
|
kassert_panic("interlock (%s) %s not locked @ %s:%d",
|
2013-06-03 17:41:11 +00:00
|
|
|
iclass->lc_name, interlock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
|
|
|
else if ((lock1->li_flags & LI_RECURSEMASK) != 0)
|
2013-09-04 11:52:28 +00:00
|
|
|
kassert_panic("interlock (%s) %s recursed @ %s:%d",
|
2013-06-03 17:41:11 +00:00
|
|
|
iclass->lc_name, interlock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
|
|
|
}
|
|
|
|
|
2008-09-10 19:13:30 +00:00
|
|
|
/*
|
|
|
|
* Find the previously acquired lock, but ignore interlocks.
|
|
|
|
*/
|
2008-10-16 12:42:56 +00:00
|
|
|
plock = &lock_list->ll_children[lock_list->ll_count - 1];
|
2008-09-10 19:13:30 +00:00
|
|
|
if (interlock != NULL && plock->li_lock == interlock) {
|
2008-10-16 12:42:56 +00:00
|
|
|
if (lock_list->ll_count > 1)
|
|
|
|
plock =
|
|
|
|
&lock_list->ll_children[lock_list->ll_count - 2];
|
|
|
|
else {
|
|
|
|
lle = lock_list->ll_next;
|
2008-09-12 21:44:01 +00:00
|
|
|
|
2008-09-10 19:13:30 +00:00
|
|
|
/*
|
|
|
|
* The interlock is the only lock we hold, so
|
2008-10-16 12:42:56 +00:00
|
|
|
* simply return.
|
2008-09-10 19:13:30 +00:00
|
|
|
*/
|
2008-10-16 12:42:56 +00:00
|
|
|
if (lle == NULL)
|
|
|
|
return;
|
|
|
|
plock = &lle->ll_children[lle->ll_count - 1];
|
2008-09-10 19:13:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
|
|
|
* Try to perform most checks without a lock. If this succeeds we
|
2015-06-07 18:59:47 +00:00
|
|
|
* can skip acquiring the lock and return success. Otherwise we redo
|
|
|
|
* the check with the lock held to handle races with concurrent updates.
|
2008-08-13 18:24:22 +00:00
|
|
|
*/
|
2008-09-10 19:13:30 +00:00
|
|
|
w1 = plock->li_lock->lo_witness;
|
2008-08-13 18:24:22 +00:00
|
|
|
if (witness_lock_order_check(w1, w))
|
|
|
|
return;
|
|
|
|
|
2015-06-07 18:59:47 +00:00
|
|
|
mtx_lock_spin(&w_mtx);
|
|
|
|
if (witness_lock_order_check(w1, w)) {
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
witness_lock_order_add(w1, w);
|
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
/*
|
|
|
|
* Check for duplicate locks of the same type. Note that we only
|
|
|
|
* have to check for this on the last lock we just acquired. Any
|
|
|
|
* other cases will be caught as lock order violations.
|
|
|
|
*/
|
|
|
|
if (w1 == w) {
|
2008-08-13 18:24:22 +00:00
|
|
|
i = w->w_index;
|
|
|
|
if (!(lock->lo_flags & LO_DUPOK) && !(flags & LOP_DUPOK) &&
|
|
|
|
!(w_rmatrix[i][i] & WITNESS_REVERSAL)) {
|
|
|
|
w_rmatrix[i][i] |= WITNESS_REVERSAL;
|
|
|
|
w->w_reversed = 1;
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(
|
2008-10-03 18:13:05 +00:00
|
|
|
"acquiring duplicate lock of same type: \"%s\"\n",
|
2008-08-13 18:24:22 +00:00
|
|
|
w->w_name);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(" 1st %s @ %s:%d\n", plock->li_lock->lo_name,
|
2011-10-26 15:17:42 +00:00
|
|
|
fixup_filename(plock->li_file), plock->li_line);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(" 2nd %s @ %s:%d\n", lock->lo_name,
|
2011-10-12 09:21:02 +00:00
|
|
|
fixup_filename(file), line);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_debugger(1, __func__);
|
2011-10-26 15:17:42 +00:00
|
|
|
} else
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
2004-01-28 20:39:57 +00:00
|
|
|
return;
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
2008-08-13 18:24:22 +00:00
|
|
|
mtx_assert(&w_mtx, MA_OWNED);
|
|
|
|
|
2003-03-04 20:56:39 +00:00
|
|
|
/*
|
2011-02-21 09:01:34 +00:00
|
|
|
* If we know that the lock we are acquiring comes after
|
2003-03-04 20:56:39 +00:00
|
|
|
* the lock we most recently acquired in the lock order tree,
|
|
|
|
* then there is no need for any further checks.
|
|
|
|
*/
|
2008-08-13 18:24:22 +00:00
|
|
|
if (isitmychild(w1, w))
|
|
|
|
goto out;
|
|
|
|
|
2008-10-16 12:42:56 +00:00
|
|
|
for (j = 0, lle = lock_list; lle != NULL; lle = lle->ll_next) {
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
for (i = lle->ll_count - 1; i >= 0; i--, j++) {
|
|
|
|
|
2015-07-07 19:29:18 +00:00
|
|
|
MPASS(j < LOCK_CHILDCOUNT * LOCK_NCHILDREN);
|
2001-05-04 17:15:16 +00:00
|
|
|
lock1 = &lle->ll_children[i];
|
2008-09-10 19:13:30 +00:00
|
|
|
|
|
|
|
/*
|
2013-06-03 17:41:11 +00:00
|
|
|
* Ignore the interlock.
|
2008-09-10 19:13:30 +00:00
|
|
|
*/
|
2013-06-03 17:41:11 +00:00
|
|
|
if (interlock == lock1->li_lock)
|
2008-09-10 19:13:30 +00:00
|
|
|
continue;
|
2000-09-07 01:33:02 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
/*
|
|
|
|
* If this lock doesn't undergo witness checking,
|
|
|
|
* then skip it.
|
|
|
|
*/
|
2008-09-10 19:13:30 +00:00
|
|
|
w1 = lock1->li_lock->lo_witness;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
if (w1 == NULL) {
|
2001-05-04 17:15:16 +00:00
|
|
|
KASSERT((lock1->li_lock->lo_flags & LO_WITNESS) == 0,
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
("lock missing witness structure"));
|
|
|
|
continue;
|
|
|
|
}
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2001-05-04 17:15:16 +00:00
|
|
|
/*
|
2003-03-04 20:56:39 +00:00
|
|
|
* If we are locking Giant and this is a sleepable
|
2001-05-04 17:15:16 +00:00
|
|
|
* lock, then skip it.
|
|
|
|
*/
|
2003-03-04 20:56:39 +00:00
|
|
|
if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
2007-03-21 21:20:51 +00:00
|
|
|
lock == &Giant.lock_object)
|
2001-05-04 17:15:16 +00:00
|
|
|
continue;
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2002-04-02 19:27:21 +00:00
|
|
|
/*
|
|
|
|
* If we are locking a sleepable lock and this lock
|
2003-03-04 20:56:39 +00:00
|
|
|
* is Giant, then skip it.
|
|
|
|
*/
|
|
|
|
if ((lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
2007-03-21 21:20:51 +00:00
|
|
|
lock1->li_lock == &Giant.lock_object)
|
2003-03-04 20:56:39 +00:00
|
|
|
continue;
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2003-03-04 20:56:39 +00:00
|
|
|
/*
|
|
|
|
* If we are locking a sleepable lock and this lock
|
|
|
|
* isn't sleepable, we want to treat it as a lock
|
|
|
|
* order violation to enfore a general lock order of
|
|
|
|
* sleepable locks before non-sleepable locks.
|
2002-04-02 19:27:21 +00:00
|
|
|
*/
|
2005-09-02 20:23:49 +00:00
|
|
|
if (((lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
2003-03-04 20:56:39 +00:00
|
|
|
(lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0))
|
2005-09-02 20:23:49 +00:00
|
|
|
goto reversal;
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2005-09-15 19:07:14 +00:00
|
|
|
/*
|
|
|
|
* If we are locking Giant and this is a non-sleepable
|
|
|
|
* lock, then treat it as a reversal.
|
|
|
|
*/
|
|
|
|
if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0 &&
|
2007-03-21 21:20:51 +00:00
|
|
|
lock == &Giant.lock_object)
|
2005-09-15 19:07:14 +00:00
|
|
|
goto reversal;
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2005-09-02 20:23:49 +00:00
|
|
|
/*
|
|
|
|
* Check the lock order hierarchy for a reveresal.
|
|
|
|
*/
|
|
|
|
if (!isitmydescendant(w, w1))
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
continue;
|
2005-09-02 20:23:49 +00:00
|
|
|
reversal:
|
2008-08-13 18:24:22 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
/*
|
|
|
|
* We have a lock order violation, check to see if it
|
|
|
|
* is allowed or has already been yelled about.
|
|
|
|
*/
|
2002-10-20 08:48:39 +00:00
|
|
|
#ifdef BLESSING
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2004-01-28 20:39:57 +00:00
|
|
|
/*
|
|
|
|
* If the lock order is blessed, just bail. We don't
|
|
|
|
* look for other lock order violations though, which
|
|
|
|
* may be a bug.
|
|
|
|
*/
|
2000-09-07 01:33:02 +00:00
|
|
|
if (blessed(w, w1))
|
2008-08-13 18:24:22 +00:00
|
|
|
goto out;
|
2002-10-20 08:48:39 +00:00
|
|
|
#endif
|
2008-08-13 18:24:22 +00:00
|
|
|
|
|
|
|
/* Bail if this violation is known */
|
|
|
|
if (w_rmatrix[w1->w_index][w->w_index] & WITNESS_REVERSAL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Record this as a violation */
|
|
|
|
w_rmatrix[w1->w_index][w->w_index] |= WITNESS_REVERSAL;
|
|
|
|
w_rmatrix[w->w_index][w1->w_index] |= WITNESS_REVERSAL;
|
|
|
|
w->w_reversed = w1->w_reversed = 1;
|
|
|
|
witness_increment_graph_generation();
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
2013-05-09 16:28:18 +00:00
|
|
|
|
|
|
|
#ifdef WITNESS_NO_VNODE
|
|
|
|
/*
|
|
|
|
* There are known LORs between VNODE locks. They are
|
|
|
|
* not an indication of a bug. VNODE locks are flagged
|
|
|
|
* as such (LO_IS_VNODE) and we don't yell if the LOR
|
|
|
|
* is between 2 VNODE locks.
|
|
|
|
*/
|
|
|
|
if ((lock->lo_flags & LO_IS_VNODE) != 0 &&
|
|
|
|
(lock1->li_lock->lo_flags & LO_IS_VNODE) != 0)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
/*
|
|
|
|
* Ok, yell about it.
|
|
|
|
*/
|
2005-09-15 19:07:14 +00:00
|
|
|
if (((lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
|
|
|
(lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0))
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(
|
2005-09-15 19:07:14 +00:00
|
|
|
"lock order reversal: (sleepable after non-sleepable)\n");
|
|
|
|
else if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0
|
2007-03-21 21:20:51 +00:00
|
|
|
&& lock == &Giant.lock_object)
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(
|
2005-09-15 19:07:14 +00:00
|
|
|
"lock order reversal: (Giant after non-sleepable)\n");
|
|
|
|
else
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output("lock order reversal:\n");
|
2008-08-13 18:24:22 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
/*
|
|
|
|
* Try to locate an earlier lock with
|
|
|
|
* witness w in our list.
|
|
|
|
*/
|
|
|
|
do {
|
2001-05-04 17:15:16 +00:00
|
|
|
lock2 = &lle->ll_children[i];
|
|
|
|
MPASS(lock2->li_lock != NULL);
|
|
|
|
if (lock2->li_lock->lo_witness == w)
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
break;
|
|
|
|
if (i == 0 && lle->ll_next != NULL) {
|
|
|
|
lle = lle->ll_next;
|
|
|
|
i = lle->ll_count - 1;
|
2002-11-11 16:36:20 +00:00
|
|
|
MPASS(i >= 0 && i < LOCK_NCHILDREN);
|
2004-01-28 20:39:57 +00:00
|
|
|
} else
|
|
|
|
i--;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
} while (i >= 0);
|
2001-05-04 17:15:16 +00:00
|
|
|
if (i < 0) {
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(" 1st %p %s (%s) @ %s:%d\n",
|
2002-04-04 20:45:21 +00:00
|
|
|
lock1->li_lock, lock1->li_lock->lo_name,
|
2011-10-12 09:21:02 +00:00
|
|
|
w1->w_name, fixup_filename(lock1->li_file),
|
|
|
|
lock1->li_line);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(" 2nd %p %s (%s) @ %s:%d\n", lock,
|
2011-10-12 09:21:02 +00:00
|
|
|
lock->lo_name, w->w_name,
|
|
|
|
fixup_filename(file), line);
|
2001-05-04 17:15:16 +00:00
|
|
|
} else {
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(" 1st %p %s (%s) @ %s:%d\n",
|
2002-04-04 20:45:21 +00:00
|
|
|
lock2->li_lock, lock2->li_lock->lo_name,
|
2008-05-15 20:10:06 +00:00
|
|
|
lock2->li_lock->lo_witness->w_name,
|
2011-10-12 09:21:02 +00:00
|
|
|
fixup_filename(lock2->li_file),
|
|
|
|
lock2->li_line);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(" 2nd %p %s (%s) @ %s:%d\n",
|
2002-04-04 20:45:21 +00:00
|
|
|
lock1->li_lock, lock1->li_lock->lo_name,
|
2011-10-12 09:21:02 +00:00
|
|
|
w1->w_name, fixup_filename(lock1->li_file),
|
|
|
|
lock1->li_line);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(" 3rd %p %s (%s) @ %s:%d\n", lock,
|
2011-10-12 09:21:02 +00:00
|
|
|
lock->lo_name, w->w_name,
|
|
|
|
fixup_filename(file), line);
|
2001-05-04 17:15:16 +00:00
|
|
|
}
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_debugger(1, __func__);
|
2004-01-28 20:39:57 +00:00
|
|
|
return;
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
}
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2001-06-27 06:27:29 +00:00
|
|
|
/*
|
2004-01-28 20:39:57 +00:00
|
|
|
* If requested, build a new lock order. However, don't build a new
|
|
|
|
* relationship between a sleepable lock and Giant if it is in the
|
|
|
|
* wrong direction. The correct lock order is that sleepable locks
|
|
|
|
* always come before Giant.
|
2001-06-27 06:27:29 +00:00
|
|
|
*/
|
2004-01-28 20:39:57 +00:00
|
|
|
if (flags & LOP_NEWORDER &&
|
2008-09-10 19:13:30 +00:00
|
|
|
!(plock->li_lock == &Giant.lock_object &&
|
2003-03-11 22:07:35 +00:00
|
|
|
(lock->lo_flags & LO_SLEEPABLE) != 0)) {
|
2001-12-10 05:40:12 +00:00
|
|
|
CTR3(KTR_WITNESS, "%s: adding %s as a child of %s", __func__,
|
2008-09-10 19:13:30 +00:00
|
|
|
w->w_name, plock->li_lock->lo_witness->w_name);
|
|
|
|
itismychild(plock->li_lock->lo_witness, w);
|
2008-08-13 18:24:22 +00:00
|
|
|
}
|
|
|
|
out:
|
2003-03-11 22:07:35 +00:00
|
|
|
mtx_unlock_spin(&w_mtx);
|
2004-01-28 20:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
witness_lock(struct lock_object *lock, int flags, const char *file, int line)
|
|
|
|
{
|
|
|
|
struct lock_list_entry **lock_list, *lle;
|
|
|
|
struct lock_instance *instance;
|
|
|
|
struct witness *w;
|
|
|
|
struct thread *td;
|
|
|
|
|
2008-08-29 15:47:53 +00:00
|
|
|
if (witness_cold || witness_watch == -1 || lock->lo_witness == NULL ||
|
2004-01-28 20:39:57 +00:00
|
|
|
panicstr != NULL)
|
|
|
|
return;
|
|
|
|
w = lock->lo_witness;
|
|
|
|
td = curthread;
|
|
|
|
|
|
|
|
/* Determine lock list for this lock. */
|
2006-01-06 18:07:32 +00:00
|
|
|
if (LOCK_CLASS(lock)->lc_flags & LC_SLEEPLOCK)
|
2004-01-28 20:39:57 +00:00
|
|
|
lock_list = &td->td_sleeplocks;
|
|
|
|
else
|
|
|
|
lock_list = PCPU_PTR(spinlocks);
|
|
|
|
|
|
|
|
/* Check to see if we are recursing on a lock we already own. */
|
|
|
|
instance = find_instance(*lock_list, lock);
|
|
|
|
if (instance != NULL) {
|
|
|
|
instance->li_flags++;
|
|
|
|
CTR4(KTR_WITNESS, "%s: pid %d recursed on %s r=%d", __func__,
|
|
|
|
td->td_proc->p_pid, lock->lo_name,
|
|
|
|
instance->li_flags & LI_RECURSEMASK);
|
|
|
|
instance->li_file = file;
|
|
|
|
instance->li_line = line;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update per-witness last file and line acquire. */
|
2000-09-07 01:33:02 +00:00
|
|
|
w->w_file = file;
|
|
|
|
w->w_line = line;
|
2004-01-28 20:39:57 +00:00
|
|
|
|
|
|
|
/* Find the next open lock instance in the list and fill it. */
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
lle = *lock_list;
|
2001-05-04 17:15:16 +00:00
|
|
|
if (lle == NULL || lle->ll_count == LOCK_NCHILDREN) {
|
2001-06-25 23:17:52 +00:00
|
|
|
lle = witness_lock_list_get();
|
|
|
|
if (lle == NULL)
|
2000-09-07 01:33:02 +00:00
|
|
|
return;
|
2001-06-25 23:17:52 +00:00
|
|
|
lle->ll_next = *lock_list;
|
2001-12-10 05:40:12 +00:00
|
|
|
CTR3(KTR_WITNESS, "%s: pid %d added lle %p", __func__,
|
2001-10-08 21:05:46 +00:00
|
|
|
td->td_proc->p_pid, lle);
|
2001-06-25 23:17:52 +00:00
|
|
|
*lock_list = lle;
|
2001-01-19 01:59:14 +00:00
|
|
|
}
|
2004-01-28 20:39:57 +00:00
|
|
|
instance = &lle->ll_children[lle->ll_count++];
|
|
|
|
instance->li_lock = lock;
|
|
|
|
instance->li_line = line;
|
|
|
|
instance->li_file = file;
|
2001-05-04 17:15:16 +00:00
|
|
|
if ((flags & LOP_EXCLUSIVE) != 0)
|
2004-01-28 20:39:57 +00:00
|
|
|
instance->li_flags = LI_EXCLUSIVE;
|
2001-05-04 17:15:16 +00:00
|
|
|
else
|
2004-01-28 20:39:57 +00:00
|
|
|
instance->li_flags = 0;
|
2001-12-10 05:40:12 +00:00
|
|
|
CTR4(KTR_WITNESS, "%s: pid %d added %s as lle[%d]", __func__,
|
2001-10-08 21:05:46 +00:00
|
|
|
td->td_proc->p_pid, lock->lo_name, lle->ll_count - 1);
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
2001-08-23 22:47:05 +00:00
|
|
|
void
|
|
|
|
witness_upgrade(struct lock_object *lock, int flags, const char *file, int line)
|
|
|
|
{
|
|
|
|
struct lock_instance *instance;
|
|
|
|
struct lock_class *class;
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
KASSERT(witness_cold == 0, ("%s: witness_cold", __func__));
|
2008-08-30 13:20:35 +00:00
|
|
|
if (lock->lo_witness == NULL || witness_watch == -1 || panicstr != NULL)
|
2001-08-23 22:47:05 +00:00
|
|
|
return;
|
2006-01-06 18:07:32 +00:00
|
|
|
class = LOCK_CLASS(lock);
|
2008-08-30 13:20:35 +00:00
|
|
|
if (witness_watch) {
|
|
|
|
if ((lock->lo_flags & LO_UPGRADABLE) == 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"upgrade of non-upgradable lock (%s) %s @ %s:%d",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2008-08-30 13:20:35 +00:00
|
|
|
if ((class->lc_flags & LC_SLEEPLOCK) == 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"upgrade of non-sleep lock (%s) %s @ %s:%d",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2008-08-30 13:20:35 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
instance = find_instance(curthread->td_sleeplocks, lock);
|
2012-12-11 07:08:14 +00:00
|
|
|
if (instance == NULL) {
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("upgrade of unlocked lock (%s) %s @ %s:%d",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2012-12-11 07:08:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-08-30 13:20:35 +00:00
|
|
|
if (witness_watch) {
|
|
|
|
if ((instance->li_flags & LI_EXCLUSIVE) != 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"upgrade of exclusive lock (%s) %s @ %s:%d",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2008-08-30 13:20:35 +00:00
|
|
|
if ((instance->li_flags & LI_RECURSEMASK) != 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"upgrade of recursed lock (%s) %s r=%d @ %s:%d",
|
2008-08-30 13:20:35 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
2011-10-12 09:21:02 +00:00
|
|
|
instance->li_flags & LI_RECURSEMASK,
|
|
|
|
fixup_filename(file), line);
|
2008-08-30 13:20:35 +00:00
|
|
|
}
|
2001-08-23 22:47:05 +00:00
|
|
|
instance->li_flags |= LI_EXCLUSIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
witness_downgrade(struct lock_object *lock, int flags, const char *file,
|
|
|
|
int line)
|
|
|
|
{
|
|
|
|
struct lock_instance *instance;
|
|
|
|
struct lock_class *class;
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
KASSERT(witness_cold == 0, ("%s: witness_cold", __func__));
|
2008-08-30 13:20:35 +00:00
|
|
|
if (lock->lo_witness == NULL || witness_watch == -1 || panicstr != NULL)
|
2001-08-23 22:47:05 +00:00
|
|
|
return;
|
2006-01-06 18:07:32 +00:00
|
|
|
class = LOCK_CLASS(lock);
|
2008-08-30 13:20:35 +00:00
|
|
|
if (witness_watch) {
|
|
|
|
if ((lock->lo_flags & LO_UPGRADABLE) == 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"downgrade of non-upgradable lock (%s) %s @ %s:%d",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2008-08-30 13:20:35 +00:00
|
|
|
if ((class->lc_flags & LC_SLEEPLOCK) == 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"downgrade of non-sleep lock (%s) %s @ %s:%d",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2008-08-30 13:20:35 +00:00
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
instance = find_instance(curthread->td_sleeplocks, lock);
|
2012-12-11 07:08:14 +00:00
|
|
|
if (instance == NULL) {
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("downgrade of unlocked lock (%s) %s @ %s:%d",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2012-12-11 07:08:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-08-30 13:20:35 +00:00
|
|
|
if (witness_watch) {
|
|
|
|
if ((instance->li_flags & LI_EXCLUSIVE) == 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"downgrade of shared lock (%s) %s @ %s:%d",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2008-08-30 13:20:35 +00:00
|
|
|
if ((instance->li_flags & LI_RECURSEMASK) != 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"downgrade of recursed lock (%s) %s r=%d @ %s:%d",
|
2008-08-30 13:20:35 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
2011-10-26 15:17:42 +00:00
|
|
|
instance->li_flags & LI_RECURSEMASK,
|
|
|
|
fixup_filename(file), line);
|
2008-08-30 13:20:35 +00:00
|
|
|
}
|
2001-08-23 22:47:05 +00:00
|
|
|
instance->li_flags &= ~LI_EXCLUSIVE;
|
|
|
|
}
|
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
void
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
witness_unlock(struct lock_object *lock, int flags, const char *file, int line)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
struct lock_list_entry **lock_list, *lle;
|
2001-05-04 17:15:16 +00:00
|
|
|
struct lock_instance *instance;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
struct lock_class *class;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2002-03-21 06:11:09 +00:00
|
|
|
register_t s;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
int i, j;
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2008-08-29 15:47:53 +00:00
|
|
|
if (witness_cold || lock->lo_witness == NULL || panicstr != NULL)
|
2001-01-21 22:34:43 +00:00
|
|
|
return;
|
2001-09-12 08:38:13 +00:00
|
|
|
td = curthread;
|
2006-01-06 18:07:32 +00:00
|
|
|
class = LOCK_CLASS(lock);
|
2004-01-28 20:39:57 +00:00
|
|
|
|
|
|
|
/* Find lock instance associated with this lock. */
|
2001-05-04 17:15:16 +00:00
|
|
|
if (class->lc_flags & LC_SLEEPLOCK)
|
2001-09-12 08:38:13 +00:00
|
|
|
lock_list = &td->td_sleeplocks;
|
2001-05-04 17:15:16 +00:00
|
|
|
else
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
lock_list = PCPU_PTR(spinlocks);
|
2008-08-13 18:24:22 +00:00
|
|
|
lle = *lock_list;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
for (; *lock_list != NULL; lock_list = &(*lock_list)->ll_next)
|
2001-05-04 17:15:16 +00:00
|
|
|
for (i = 0; i < (*lock_list)->ll_count; i++) {
|
|
|
|
instance = &(*lock_list)->ll_children[i];
|
2004-01-28 20:39:57 +00:00
|
|
|
if (instance->li_lock == lock)
|
|
|
|
goto found;
|
2001-05-04 17:15:16 +00:00
|
|
|
}
|
2008-08-29 15:47:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When disabling WITNESS through witness_watch we could end up in
|
2008-08-30 13:20:35 +00:00
|
|
|
* having registered locks in the td_sleeplocks queue.
|
2008-08-29 15:47:53 +00:00
|
|
|
* We have to make sure we flush these queues, so just search for
|
2008-08-30 13:20:35 +00:00
|
|
|
* eventual register locks and remove them.
|
2008-08-29 15:47:53 +00:00
|
|
|
*/
|
2012-12-11 07:08:14 +00:00
|
|
|
if (witness_watch > 0) {
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("lock (%s) %s not locked @ %s:%d", class->lc_name,
|
2011-10-12 09:21:02 +00:00
|
|
|
lock->lo_name, fixup_filename(file), line);
|
2008-08-29 15:47:53 +00:00
|
|
|
return;
|
2012-12-11 07:08:14 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2004-01-28 20:39:57 +00:00
|
|
|
found:
|
|
|
|
|
|
|
|
/* First, check for shared/exclusive mismatches. */
|
2008-08-29 15:47:53 +00:00
|
|
|
if ((instance->li_flags & LI_EXCLUSIVE) != 0 && witness_watch > 0 &&
|
2004-01-28 20:39:57 +00:00
|
|
|
(flags & LOP_EXCLUSIVE) == 0) {
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output("shared unlock of (%s) %s @ %s:%d\n",
|
|
|
|
class->lc_name, lock->lo_name, fixup_filename(file), line);
|
|
|
|
witness_output("while exclusively locked from %s:%d\n",
|
2011-10-12 09:21:02 +00:00
|
|
|
fixup_filename(instance->li_file), instance->li_line);
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("excl->ushare");
|
2004-01-28 20:39:57 +00:00
|
|
|
}
|
2008-08-29 15:47:53 +00:00
|
|
|
if ((instance->li_flags & LI_EXCLUSIVE) == 0 && witness_watch > 0 &&
|
2004-01-28 20:39:57 +00:00
|
|
|
(flags & LOP_EXCLUSIVE) != 0) {
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output("exclusive unlock of (%s) %s @ %s:%d\n",
|
|
|
|
class->lc_name, lock->lo_name, fixup_filename(file), line);
|
|
|
|
witness_output("while share locked from %s:%d\n",
|
2011-10-12 09:21:02 +00:00
|
|
|
fixup_filename(instance->li_file),
|
2004-01-28 20:39:57 +00:00
|
|
|
instance->li_line);
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("share->uexcl");
|
2004-01-28 20:39:57 +00:00
|
|
|
}
|
|
|
|
/* If we are recursed, unrecurse. */
|
|
|
|
if ((instance->li_flags & LI_RECURSEMASK) > 0) {
|
|
|
|
CTR4(KTR_WITNESS, "%s: pid %d unrecursed on %s r=%d", __func__,
|
|
|
|
td->td_proc->p_pid, instance->li_lock->lo_name,
|
|
|
|
instance->li_flags);
|
|
|
|
instance->li_flags--;
|
|
|
|
return;
|
|
|
|
}
|
2009-02-28 19:10:43 +00:00
|
|
|
/* The lock is now being dropped, check for NORELEASE flag */
|
|
|
|
if ((instance->li_flags & LI_NORELEASE) != 0 && witness_watch > 0) {
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output("forbidden unlock of (%s) %s @ %s:%d\n",
|
|
|
|
class->lc_name, lock->lo_name, fixup_filename(file), line);
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("lock marked norelease");
|
2009-02-28 19:10:43 +00:00
|
|
|
}
|
2004-01-28 20:39:57 +00:00
|
|
|
|
|
|
|
/* Otherwise, remove this item from the list. */
|
|
|
|
s = intr_disable();
|
|
|
|
CTR4(KTR_WITNESS, "%s: pid %d removed %s from lle[%d]", __func__,
|
|
|
|
td->td_proc->p_pid, instance->li_lock->lo_name,
|
|
|
|
(*lock_list)->ll_count - 1);
|
|
|
|
for (j = i; j < (*lock_list)->ll_count - 1; j++)
|
|
|
|
(*lock_list)->ll_children[j] =
|
|
|
|
(*lock_list)->ll_children[j + 1];
|
|
|
|
(*lock_list)->ll_count--;
|
|
|
|
intr_restore(s);
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
2008-09-12 21:44:01 +00:00
|
|
|
* In order to reduce contention on w_mtx, we want to keep always an
|
|
|
|
* head object into lists so that frequent allocation from the
|
|
|
|
* free witness pool (and subsequent locking) is avoided.
|
|
|
|
* In order to maintain the current code simple, when the head
|
|
|
|
* object is totally unloaded it means also that we do not have
|
|
|
|
* further objects in the list, so the list ownership needs to be
|
|
|
|
* hand over to another object if the current head needs to be freed.
|
2008-08-13 18:24:22 +00:00
|
|
|
*/
|
2008-09-12 21:44:01 +00:00
|
|
|
if ((*lock_list)->ll_count == 0) {
|
|
|
|
if (*lock_list == lle) {
|
|
|
|
if (lle->ll_next == NULL)
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
lle = *lock_list;
|
2004-01-28 20:39:57 +00:00
|
|
|
*lock_list = lle->ll_next;
|
|
|
|
CTR3(KTR_WITNESS, "%s: pid %d removed lle %p", __func__,
|
|
|
|
td->td_proc->p_pid, lle);
|
|
|
|
witness_lock_list_free(lle);
|
|
|
|
}
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
void
|
|
|
|
witness_thread_exit(struct thread *td)
|
|
|
|
{
|
|
|
|
struct lock_list_entry *lle;
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
lle = td->td_sleeplocks;
|
|
|
|
if (lle == NULL || panicstr != NULL)
|
|
|
|
return;
|
|
|
|
if (lle->ll_count != 0) {
|
|
|
|
for (n = 0; lle != NULL; lle = lle->ll_next)
|
|
|
|
for (i = lle->ll_count - 1; i >= 0; i--) {
|
|
|
|
if (n == 0)
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(
|
|
|
|
"Thread %p exiting with the following locks held:\n", td);
|
2008-08-13 18:24:22 +00:00
|
|
|
n++;
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_list_lock(&lle->ll_children[i],
|
|
|
|
witness_output);
|
2008-08-13 18:24:22 +00:00
|
|
|
|
|
|
|
}
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"Thread %p cannot exit while holding sleeplocks\n", td);
|
2008-08-13 18:24:22 +00:00
|
|
|
}
|
|
|
|
witness_lock_list_free(lle);
|
|
|
|
}
|
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
/*
|
2003-03-04 20:56:39 +00:00
|
|
|
* Warn if any locks other than 'lock' are held. Flags can be passed in to
|
|
|
|
* exempt Giant and sleepable locks from the checks as well. If any
|
|
|
|
* non-exempt locks are held, then a supplied message is printed to the
|
2015-11-19 05:56:59 +00:00
|
|
|
* output channel along with a list of the offending locks. If indicated in the
|
2003-03-04 20:56:39 +00:00
|
|
|
* flags then a failure results in a panic as well.
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
*/
|
2000-09-07 01:33:02 +00:00
|
|
|
int
|
2003-03-04 20:56:39 +00:00
|
|
|
witness_warn(int flags, struct lock_object *lock, const char *fmt, ...)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
2008-10-16 12:42:56 +00:00
|
|
|
struct lock_list_entry *lock_list, *lle;
|
2001-05-04 17:15:16 +00:00
|
|
|
struct lock_instance *lock1;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2003-03-04 20:56:39 +00:00
|
|
|
va_list ap;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
int i, n;
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2008-08-29 15:47:53 +00:00
|
|
|
if (witness_cold || witness_watch < 1 || panicstr != NULL)
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
return (0);
|
|
|
|
n = 0;
|
2001-09-12 08:38:13 +00:00
|
|
|
td = curthread;
|
2003-03-04 20:56:39 +00:00
|
|
|
for (lle = td->td_sleeplocks; lle != NULL; lle = lle->ll_next)
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
for (i = lle->ll_count - 1; i >= 0; i--) {
|
2001-05-04 17:15:16 +00:00
|
|
|
lock1 = &lle->ll_children[i];
|
2003-03-04 20:56:39 +00:00
|
|
|
if (lock1->li_lock == lock)
|
|
|
|
continue;
|
|
|
|
if (flags & WARN_GIANTOK &&
|
2007-03-21 21:20:51 +00:00
|
|
|
lock1->li_lock == &Giant.lock_object)
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
continue;
|
2003-03-04 20:56:39 +00:00
|
|
|
if (flags & WARN_SLEEPOK &&
|
|
|
|
(lock1->li_lock->lo_flags & LO_SLEEPABLE) != 0)
|
2001-05-04 17:15:16 +00:00
|
|
|
continue;
|
2003-03-04 20:56:39 +00:00
|
|
|
if (n == 0) {
|
|
|
|
va_start(ap, fmt);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_voutput(fmt, ap);
|
2003-03-04 20:56:39 +00:00
|
|
|
va_end(ap);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(
|
|
|
|
" with the following %slocks held:\n",
|
|
|
|
(flags & WARN_SLEEPOK) != 0 ?
|
|
|
|
"non-sleepable " : "");
|
2001-05-04 17:15:16 +00:00
|
|
|
}
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
n++;
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_list_lock(lock1, witness_output);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
}
|
2008-10-16 12:42:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pin the thread in order to avoid problems with thread migration.
|
|
|
|
* Once that all verifies are passed about spinlocks ownership,
|
|
|
|
* the thread is in a safe path and it can be unpinned.
|
|
|
|
*/
|
|
|
|
sched_pin();
|
|
|
|
lock_list = PCPU_GET(spinlocks);
|
2008-10-20 19:22:16 +00:00
|
|
|
if (lock_list != NULL && lock_list->ll_count != 0) {
|
2008-10-16 12:42:56 +00:00
|
|
|
sched_unpin();
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2002-05-20 17:49:46 +00:00
|
|
|
/*
|
2008-10-16 12:42:56 +00:00
|
|
|
* We should only have one spinlock and as long as
|
|
|
|
* the flags cannot match for this locks class,
|
|
|
|
* check if the first spinlock is the one curthread
|
|
|
|
* should hold.
|
2002-05-20 17:49:46 +00:00
|
|
|
*/
|
2008-10-16 12:42:56 +00:00
|
|
|
lock1 = &lock_list->ll_children[lock_list->ll_count - 1];
|
2008-10-20 19:22:16 +00:00
|
|
|
if (lock_list->ll_count == 1 && lock_list->ll_next == NULL &&
|
|
|
|
lock1->li_lock == lock && n == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_voutput(fmt, ap);
|
2008-10-20 19:22:16 +00:00
|
|
|
va_end(ap);
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_output(" with the following %slocks held:\n",
|
|
|
|
(flags & WARN_SLEEPOK) != 0 ? "non-sleepable " : "");
|
|
|
|
n += witness_list_locks(&lock_list, witness_output);
|
2008-10-16 12:42:56 +00:00
|
|
|
} else
|
|
|
|
sched_unpin();
|
2003-03-04 20:56:39 +00:00
|
|
|
if (flags & WARN_PANIC && n)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("%s", __func__);
|
2008-08-13 18:24:22 +00:00
|
|
|
else
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_debugger(n, __func__);
|
2000-09-07 01:33:02 +00:00
|
|
|
return (n);
|
|
|
|
}
|
|
|
|
|
2002-08-26 18:31:26 +00:00
|
|
|
const char *
|
|
|
|
witness_file(struct lock_object *lock)
|
|
|
|
{
|
|
|
|
struct witness *w;
|
|
|
|
|
2008-08-29 15:47:53 +00:00
|
|
|
if (witness_cold || witness_watch < 1 || lock->lo_witness == NULL)
|
2002-08-26 18:31:26 +00:00
|
|
|
return ("?");
|
|
|
|
w = lock->lo_witness;
|
|
|
|
return (w->w_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
witness_line(struct lock_object *lock)
|
|
|
|
{
|
|
|
|
struct witness *w;
|
|
|
|
|
2008-08-29 15:47:53 +00:00
|
|
|
if (witness_cold || witness_watch < 1 || lock->lo_witness == NULL)
|
2002-08-26 18:31:26 +00:00
|
|
|
return (0);
|
|
|
|
w = lock->lo_witness;
|
|
|
|
return (w->w_line);
|
|
|
|
}
|
|
|
|
|
2000-09-14 20:15:16 +00:00
|
|
|
static struct witness *
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
enroll(const char *description, struct lock_class *lock_class)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
struct witness *w;
|
2008-08-13 18:24:22 +00:00
|
|
|
struct witness_list *typelist;
|
|
|
|
|
|
|
|
MPASS(description != NULL);
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2008-08-30 13:20:35 +00:00
|
|
|
if (witness_watch == -1 || panicstr != NULL)
|
2000-09-07 01:33:02 +00:00
|
|
|
return (NULL);
|
2008-08-13 18:24:22 +00:00
|
|
|
if ((lock_class->lc_flags & LC_SPINLOCK)) {
|
|
|
|
if (witness_skipspin)
|
|
|
|
return (NULL);
|
|
|
|
else
|
|
|
|
typelist = &w_spin;
|
2012-12-11 07:08:14 +00:00
|
|
|
} else if ((lock_class->lc_flags & LC_SLEEPLOCK)) {
|
2008-08-13 18:24:22 +00:00
|
|
|
typelist = &w_sleep;
|
2012-12-11 07:08:14 +00:00
|
|
|
} else {
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("lock class %s is not sleep or spin",
|
2008-08-13 18:24:22 +00:00
|
|
|
lock_class->lc_name);
|
2012-12-11 07:08:14 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
2008-08-13 18:24:22 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
mtx_lock_spin(&w_mtx);
|
2008-08-13 18:24:22 +00:00
|
|
|
w = witness_hash_get(description);
|
|
|
|
if (w)
|
|
|
|
goto found;
|
|
|
|
if ((w = witness_get()) == NULL)
|
|
|
|
return (NULL);
|
|
|
|
MPASS(strlen(description) < MAX_W_NAME);
|
|
|
|
strcpy(w->w_name, description);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
w->w_class = lock_class;
|
2001-04-09 22:34:05 +00:00
|
|
|
w->w_refcount = 1;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
STAILQ_INSERT_HEAD(&w_all, w, w_list);
|
2005-08-25 03:47:37 +00:00
|
|
|
if (lock_class->lc_flags & LC_SPINLOCK) {
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
STAILQ_INSERT_HEAD(&w_spin, w, w_typelist);
|
2005-08-25 03:47:37 +00:00
|
|
|
w_spin_cnt++;
|
|
|
|
} else if (lock_class->lc_flags & LC_SLEEPLOCK) {
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
STAILQ_INSERT_HEAD(&w_sleep, w, w_typelist);
|
2005-08-25 03:47:37 +00:00
|
|
|
w_sleep_cnt++;
|
2001-04-10 00:56:19 +00:00
|
|
|
}
|
2008-08-13 18:24:22 +00:00
|
|
|
|
|
|
|
/* Insert new witness into the hash */
|
|
|
|
witness_hash_put(w);
|
|
|
|
witness_increment_graph_generation();
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
mtx_unlock_spin(&w_mtx);
|
2008-08-13 18:24:22 +00:00
|
|
|
return (w);
|
|
|
|
found:
|
|
|
|
w->w_refcount++;
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
if (lock_class != w->w_class)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
2008-08-13 18:24:22 +00:00
|
|
|
"lock (%s) %s does not match earlier (%s) lock",
|
|
|
|
description, lock_class->lc_name,
|
|
|
|
w->w_class->lc_name);
|
2000-09-07 01:33:02 +00:00
|
|
|
return (w);
|
|
|
|
}
|
|
|
|
|
2008-05-15 20:10:06 +00:00
|
|
|
static void
|
2003-03-11 22:07:35 +00:00
|
|
|
depart(struct witness *w)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
struct witness_list *list;
|
2003-03-11 22:07:35 +00:00
|
|
|
|
|
|
|
MPASS(w->w_refcount == 0);
|
2005-08-25 03:47:37 +00:00
|
|
|
if (w->w_class->lc_flags & LC_SLEEPLOCK) {
|
2003-03-11 22:07:35 +00:00
|
|
|
list = &w_sleep;
|
2005-08-25 03:47:37 +00:00
|
|
|
w_sleep_cnt--;
|
|
|
|
} else {
|
2003-03-11 22:07:35 +00:00
|
|
|
list = &w_spin;
|
2005-08-25 03:47:37 +00:00
|
|
|
w_spin_cnt--;
|
|
|
|
}
|
2003-03-11 22:07:35 +00:00
|
|
|
/*
|
2008-08-13 18:24:22 +00:00
|
|
|
* Set file to NULL as it may point into a loadable module.
|
2003-03-11 22:07:35 +00:00
|
|
|
*/
|
2008-08-13 18:24:22 +00:00
|
|
|
w->w_file = NULL;
|
|
|
|
w->w_line = 0;
|
|
|
|
witness_increment_graph_generation();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
adopt(struct witness *parent, struct witness *child)
|
|
|
|
{
|
|
|
|
int pi, ci, i, j;
|
|
|
|
|
|
|
|
if (witness_cold == 0)
|
|
|
|
mtx_assert(&w_mtx, MA_OWNED);
|
|
|
|
|
|
|
|
/* If the relationship is already known, there's no work to be done. */
|
|
|
|
if (isitmychild(parent, child))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* When the structure of the graph changes, bump up the generation. */
|
|
|
|
witness_increment_graph_generation();
|
2003-03-11 22:07:35 +00:00
|
|
|
|
|
|
|
/*
|
2008-08-13 18:24:22 +00:00
|
|
|
* The hard part ... create the direct relationship, then propagate all
|
|
|
|
* indirect relationships.
|
2003-03-11 22:07:35 +00:00
|
|
|
*/
|
2008-08-13 18:24:22 +00:00
|
|
|
pi = parent->w_index;
|
|
|
|
ci = child->w_index;
|
|
|
|
WITNESS_INDEX_ASSERT(pi);
|
|
|
|
WITNESS_INDEX_ASSERT(ci);
|
|
|
|
MPASS(pi != ci);
|
|
|
|
w_rmatrix[pi][ci] |= WITNESS_PARENT;
|
|
|
|
w_rmatrix[ci][pi] |= WITNESS_CHILD;
|
2003-03-11 22:07:35 +00:00
|
|
|
|
|
|
|
/*
|
2008-08-13 18:24:22 +00:00
|
|
|
* If parent was not already an ancestor of child,
|
|
|
|
* then we increment the descendant and ancestor counters.
|
2003-03-11 22:07:35 +00:00
|
|
|
*/
|
2008-08-13 18:24:22 +00:00
|
|
|
if ((w_rmatrix[pi][ci] & WITNESS_ANCESTOR) == 0) {
|
|
|
|
parent->w_num_descendants++;
|
|
|
|
child->w_num_ancestors++;
|
|
|
|
}
|
2003-03-11 22:07:35 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
|
|
|
* Find each ancestor of 'pi'. Note that 'pi' itself is counted as
|
|
|
|
* an ancestor of 'pi' during this loop.
|
|
|
|
*/
|
|
|
|
for (i = 1; i <= w_max_used_index; i++) {
|
|
|
|
if ((w_rmatrix[i][pi] & WITNESS_ANCESTOR_MASK) == 0 &&
|
|
|
|
(i != pi))
|
|
|
|
continue;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/* Find each descendant of 'i' and mark it as a descendant. */
|
|
|
|
for (j = 1; j <= w_max_used_index; j++) {
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
|
|
|
* Skip children that are already marked as
|
|
|
|
* descendants of 'i'.
|
|
|
|
*/
|
|
|
|
if (w_rmatrix[i][j] & WITNESS_ANCESTOR_MASK)
|
|
|
|
continue;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
|
|
|
* We are only interested in descendants of 'ci'. Note
|
|
|
|
* that 'ci' itself is counted as a descendant of 'ci'.
|
|
|
|
*/
|
|
|
|
if ((w_rmatrix[ci][j] & WITNESS_ANCESTOR_MASK) == 0 &&
|
|
|
|
(j != ci))
|
|
|
|
continue;
|
|
|
|
w_rmatrix[i][j] |= WITNESS_ANCESTOR;
|
|
|
|
w_rmatrix[j][i] |= WITNESS_DESCENDANT;
|
|
|
|
w_data[i].w_num_descendants++;
|
|
|
|
w_data[j].w_num_ancestors++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we aren't marking a node as both an
|
|
|
|
* ancestor and descendant. We should have caught
|
|
|
|
* this as a lock order reversal earlier.
|
|
|
|
*/
|
|
|
|
if ((w_rmatrix[i][j] & WITNESS_ANCESTOR_MASK) &&
|
|
|
|
(w_rmatrix[i][j] & WITNESS_DESCENDANT_MASK)) {
|
|
|
|
printf("witness rmatrix paradox! [%d][%d]=%d "
|
|
|
|
"both ancestor and descendant\n",
|
|
|
|
i, j, w_rmatrix[i][j]);
|
|
|
|
kdb_backtrace();
|
|
|
|
printf("Witness disabled.\n");
|
2008-08-29 15:47:53 +00:00
|
|
|
witness_watch = -1;
|
2008-08-13 18:24:22 +00:00
|
|
|
}
|
|
|
|
if ((w_rmatrix[j][i] & WITNESS_ANCESTOR_MASK) &&
|
|
|
|
(w_rmatrix[j][i] & WITNESS_DESCENDANT_MASK)) {
|
|
|
|
printf("witness rmatrix paradox! [%d][%d]=%d "
|
|
|
|
"both ancestor and descendant\n",
|
|
|
|
j, i, w_rmatrix[j][i]);
|
|
|
|
kdb_backtrace();
|
|
|
|
printf("Witness disabled.\n");
|
2008-08-29 15:47:53 +00:00
|
|
|
witness_watch = -1;
|
2008-08-13 18:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-11 22:07:35 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
static void
|
2003-03-11 22:07:35 +00:00
|
|
|
itismychild(struct witness *parent, struct witness *child)
|
|
|
|
{
|
2012-12-11 07:08:14 +00:00
|
|
|
int unlocked;
|
2003-03-11 22:07:35 +00:00
|
|
|
|
|
|
|
MPASS(child != NULL && parent != NULL);
|
2008-08-13 18:24:22 +00:00
|
|
|
if (witness_cold == 0)
|
|
|
|
mtx_assert(&w_mtx, MA_OWNED);
|
2003-03-11 22:07:35 +00:00
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
if (!witness_lock_type_equal(parent, child)) {
|
2012-12-11 07:08:14 +00:00
|
|
|
if (witness_cold == 0) {
|
|
|
|
unlocked = 1;
|
2008-08-13 18:24:22 +00:00
|
|
|
mtx_unlock_spin(&w_mtx);
|
2012-12-11 07:08:14 +00:00
|
|
|
} else {
|
|
|
|
unlocked = 0;
|
|
|
|
}
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"%s: parent \"%s\" (%s) and child \"%s\" (%s) are not "
|
2008-08-13 18:24:22 +00:00
|
|
|
"the same lock type", __func__, parent->w_name,
|
|
|
|
parent->w_class->lc_name, child->w_name,
|
|
|
|
child->w_class->lc_name);
|
2012-12-11 07:08:14 +00:00
|
|
|
if (unlocked)
|
|
|
|
mtx_lock_spin(&w_mtx);
|
2008-08-13 18:24:22 +00:00
|
|
|
}
|
|
|
|
adopt(parent, child);
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
|
|
|
* Generic code for the isitmy*() functions. The rmask parameter is the
|
|
|
|
* expected relationship of w1 to w2.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
_isitmyx(struct witness *w1, struct witness *w2, int rmask, const char *fname)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
2008-08-13 18:24:22 +00:00
|
|
|
unsigned char r1, r2;
|
|
|
|
int i1, i2;
|
|
|
|
|
|
|
|
i1 = w1->w_index;
|
|
|
|
i2 = w2->w_index;
|
|
|
|
WITNESS_INDEX_ASSERT(i1);
|
|
|
|
WITNESS_INDEX_ASSERT(i2);
|
|
|
|
r1 = w_rmatrix[i1][i2] & WITNESS_RELATED_MASK;
|
|
|
|
r2 = w_rmatrix[i2][i1] & WITNESS_RELATED_MASK;
|
|
|
|
|
|
|
|
/* The flags on one better be the inverse of the flags on the other */
|
|
|
|
if (!((WITNESS_ATOD(r1) == r2 && WITNESS_DTOA(r2) == r1) ||
|
2015-06-07 18:59:47 +00:00
|
|
|
(WITNESS_DTOA(r1) == r2 && WITNESS_ATOD(r2) == r1))) {
|
|
|
|
/* Don't squawk if we're potentially racing with an update. */
|
|
|
|
if (!mtx_owned(&w_mtx))
|
|
|
|
return (0);
|
2008-08-13 18:24:22 +00:00
|
|
|
printf("%s: rmatrix mismatch between %s (index %d) and %s "
|
|
|
|
"(index %d): w_rmatrix[%d][%d] == %hhx but "
|
|
|
|
"w_rmatrix[%d][%d] == %hhx\n",
|
|
|
|
fname, w1->w_name, i1, w2->w_name, i2, i1, i2, r1,
|
|
|
|
i2, i1, r2);
|
|
|
|
kdb_backtrace();
|
|
|
|
printf("Witness disabled.\n");
|
2008-08-29 15:47:53 +00:00
|
|
|
witness_watch = -1;
|
2008-08-13 18:24:22 +00:00
|
|
|
}
|
|
|
|
return (r1 & rmask);
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
|
|
|
* Checks if @child is a direct child of @parent.
|
|
|
|
*/
|
2000-09-07 01:33:02 +00:00
|
|
|
static int
|
2000-09-14 20:15:16 +00:00
|
|
|
isitmychild(struct witness *parent, struct witness *child)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
return (_isitmyx(parent, child, WITNESS_PARENT, __func__));
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
/*
|
|
|
|
* Checks if @descendant is a direct or inderect descendant of @ancestor.
|
|
|
|
*/
|
2000-09-07 01:33:02 +00:00
|
|
|
static int
|
2008-08-13 18:24:22 +00:00
|
|
|
isitmydescendant(struct witness *ancestor, struct witness *descendant)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
return (_isitmyx(ancestor, descendant, WITNESS_ANCESTOR_MASK,
|
|
|
|
__func__));
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 08:48:39 +00:00
|
|
|
#ifdef BLESSING
|
2000-09-07 01:33:02 +00:00
|
|
|
static int
|
2000-09-14 20:15:16 +00:00
|
|
|
blessed(struct witness *w1, struct witness *w2)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
|
|
|
int i;
|
2000-09-14 20:15:16 +00:00
|
|
|
struct witness_blessed *b;
|
2000-09-07 01:33:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < blessed_count; i++) {
|
|
|
|
b = &blessed_list[i];
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
if (strcmp(w1->w_name, b->b_lock1) == 0) {
|
|
|
|
if (strcmp(w2->w_name, b->b_lock2) == 0)
|
2000-09-07 01:33:02 +00:00
|
|
|
return (1);
|
|
|
|
continue;
|
|
|
|
}
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
if (strcmp(w1->w_name, b->b_lock2) == 0)
|
|
|
|
if (strcmp(w2->w_name, b->b_lock1) == 0)
|
2000-09-07 01:33:02 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
2002-10-20 08:48:39 +00:00
|
|
|
#endif
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2000-09-14 20:15:16 +00:00
|
|
|
static struct witness *
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
witness_get(void)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
2000-09-14 20:15:16 +00:00
|
|
|
struct witness *w;
|
2008-08-13 18:24:22 +00:00
|
|
|
int index;
|
|
|
|
|
|
|
|
if (witness_cold == 0)
|
|
|
|
mtx_assert(&w_mtx, MA_OWNED);
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2008-08-30 13:20:35 +00:00
|
|
|
if (witness_watch == -1) {
|
2001-05-11 20:25:29 +00:00
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
return (NULL);
|
|
|
|
}
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
if (STAILQ_EMPTY(&w_free)) {
|
2008-08-29 15:47:53 +00:00
|
|
|
witness_watch = -1;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
mtx_unlock_spin(&w_mtx);
|
2008-08-13 18:24:22 +00:00
|
|
|
printf("WITNESS: unable to allocate a new witness object\n");
|
2000-09-07 01:33:02 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
w = STAILQ_FIRST(&w_free);
|
|
|
|
STAILQ_REMOVE_HEAD(&w_free, w_list);
|
2005-08-25 03:47:37 +00:00
|
|
|
w_free_cnt--;
|
2008-08-13 18:24:22 +00:00
|
|
|
index = w->w_index;
|
|
|
|
MPASS(index > 0 && index == w_max_used_index+1 &&
|
2014-10-11 02:02:58 +00:00
|
|
|
index < witness_count);
|
2000-09-14 20:15:16 +00:00
|
|
|
bzero(w, sizeof(*w));
|
2008-08-13 18:24:22 +00:00
|
|
|
w->w_index = index;
|
|
|
|
if (index > w_max_used_index)
|
|
|
|
w_max_used_index = index;
|
2000-09-07 01:33:02 +00:00
|
|
|
return (w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-09-14 20:15:16 +00:00
|
|
|
witness_free(struct witness *w)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
|
|
|
STAILQ_INSERT_HEAD(&w_free, w, w_list);
|
2005-08-25 03:47:37 +00:00
|
|
|
w_free_cnt++;
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
static struct lock_list_entry *
|
|
|
|
witness_lock_list_get(void)
|
|
|
|
{
|
|
|
|
struct lock_list_entry *lle;
|
2001-01-27 07:51:34 +00:00
|
|
|
|
2008-08-29 15:47:53 +00:00
|
|
|
if (witness_watch == -1)
|
2001-05-11 20:25:29 +00:00
|
|
|
return (NULL);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
mtx_lock_spin(&w_mtx);
|
|
|
|
lle = w_lock_list_free;
|
|
|
|
if (lle == NULL) {
|
2008-08-29 15:47:53 +00:00
|
|
|
witness_watch = -1;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
printf("%s: witness exhausted\n", __func__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
w_lock_list_free = lle->ll_next;
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
bzero(lle, sizeof(*lle));
|
|
|
|
return (lle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
witness_lock_list_free(struct lock_list_entry *lle)
|
2001-01-27 07:51:34 +00:00
|
|
|
{
|
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
mtx_lock_spin(&w_mtx);
|
|
|
|
lle->ll_next = w_lock_list_free;
|
|
|
|
w_lock_list_free = lle;
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
2001-01-27 07:51:34 +00:00
|
|
|
}
|
|
|
|
|
2001-05-04 17:15:16 +00:00
|
|
|
static struct lock_instance *
|
2011-11-16 21:51:17 +00:00
|
|
|
find_instance(struct lock_list_entry *list, const struct lock_object *lock)
|
2001-05-04 17:15:16 +00:00
|
|
|
{
|
|
|
|
struct lock_list_entry *lle;
|
|
|
|
struct lock_instance *instance;
|
|
|
|
int i;
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
for (lle = list; lle != NULL; lle = lle->ll_next)
|
2001-05-04 17:15:16 +00:00
|
|
|
for (i = lle->ll_count - 1; i >= 0; i--) {
|
|
|
|
instance = &lle->ll_children[i];
|
|
|
|
if (instance->li_lock == lock)
|
|
|
|
return (instance);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2003-03-04 20:56:39 +00:00
|
|
|
static void
|
2010-05-11 18:24:22 +00:00
|
|
|
witness_list_lock(struct lock_instance *instance,
|
|
|
|
int (*prnt)(const char *fmt, ...))
|
2003-03-04 20:56:39 +00:00
|
|
|
{
|
|
|
|
struct lock_object *lock;
|
|
|
|
|
|
|
|
lock = instance->li_lock;
|
2010-05-11 18:24:22 +00:00
|
|
|
prnt("%s %s %s", (instance->li_flags & LI_EXCLUSIVE) != 0 ?
|
2006-01-06 18:07:32 +00:00
|
|
|
"exclusive" : "shared", LOCK_CLASS(lock)->lc_name, lock->lo_name);
|
2008-05-15 20:10:06 +00:00
|
|
|
if (lock->lo_witness->w_name != lock->lo_name)
|
2010-05-11 18:24:22 +00:00
|
|
|
prnt(" (%s)", lock->lo_witness->w_name);
|
|
|
|
prnt(" r = %d (%p) locked @ %s:%d\n",
|
2011-10-12 09:21:02 +00:00
|
|
|
instance->li_flags & LI_RECURSEMASK, lock,
|
2011-10-26 15:17:42 +00:00
|
|
|
fixup_filename(instance->li_file), instance->li_line);
|
2003-03-04 20:56:39 +00:00
|
|
|
}
|
|
|
|
|
2015-11-19 05:56:59 +00:00
|
|
|
static int
|
|
|
|
witness_output(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
ret = witness_voutput(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
witness_voutput(const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
switch (witness_channel) {
|
|
|
|
case WITNESS_CONSOLE:
|
|
|
|
ret = vprintf(fmt, ap);
|
|
|
|
break;
|
|
|
|
case WITNESS_LOG:
|
|
|
|
vlog(LOG_NOTICE, fmt, ap);
|
|
|
|
break;
|
|
|
|
case WITNESS_NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2005-01-22 21:14:21 +00:00
|
|
|
#ifdef DDB
|
2004-12-26 22:52:24 +00:00
|
|
|
static int
|
|
|
|
witness_thread_has_locks(struct thread *td)
|
|
|
|
{
|
|
|
|
|
2008-09-12 21:44:01 +00:00
|
|
|
if (td->td_sleeplocks == NULL)
|
|
|
|
return (0);
|
|
|
|
return (td->td_sleeplocks->ll_count != 0);
|
2004-12-26 22:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
witness_proc_has_locks(struct proc *p)
|
|
|
|
{
|
|
|
|
struct thread *td;
|
|
|
|
|
|
|
|
FOREACH_THREAD_IN_PROC(p, td) {
|
|
|
|
if (witness_thread_has_locks(td))
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
2005-01-22 21:14:21 +00:00
|
|
|
#endif
|
2004-12-26 22:52:24 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
int
|
2010-05-11 18:24:22 +00:00
|
|
|
witness_list_locks(struct lock_list_entry **lock_list,
|
|
|
|
int (*prnt)(const char *fmt, ...))
|
2001-02-09 15:19:41 +00:00
|
|
|
{
|
2001-04-06 21:37:52 +00:00
|
|
|
struct lock_list_entry *lle;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
int i, nheld;
|
|
|
|
|
|
|
|
nheld = 0;
|
|
|
|
for (lle = *lock_list; lle != NULL; lle = lle->ll_next)
|
|
|
|
for (i = lle->ll_count - 1; i >= 0; i--) {
|
2010-05-11 18:24:22 +00:00
|
|
|
witness_list_lock(&lle->ll_children[i], prnt);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
nheld++;
|
|
|
|
}
|
2001-04-06 21:37:52 +00:00
|
|
|
return (nheld);
|
|
|
|
}
|
|
|
|
|
2003-07-31 18:50:58 +00:00
|
|
|
/*
|
|
|
|
* This is a bit risky at best. We call this function when we have timed
|
|
|
|
* out acquiring a spin lock, and we assume that the other CPU is stuck
|
|
|
|
* with this lock held. So, we go groveling around in the other CPU's
|
|
|
|
* per-cpu data to try to find the lock instance for this spin lock to
|
|
|
|
* see when it was last acquired.
|
|
|
|
*/
|
|
|
|
void
|
2010-05-11 18:24:22 +00:00
|
|
|
witness_display_spinlock(struct lock_object *lock, struct thread *owner,
|
|
|
|
int (*prnt)(const char *fmt, ...))
|
2003-07-31 18:50:58 +00:00
|
|
|
{
|
|
|
|
struct lock_instance *instance;
|
|
|
|
struct pcpu *pc;
|
|
|
|
|
|
|
|
if (owner->td_critnest == 0 || owner->td_oncpu == NOCPU)
|
|
|
|
return;
|
|
|
|
pc = pcpu_find(owner->td_oncpu);
|
|
|
|
instance = find_instance(pc->pc_spinlocks, lock);
|
|
|
|
if (instance != NULL)
|
2010-05-11 18:24:22 +00:00
|
|
|
witness_list_lock(instance, prnt);
|
2003-07-31 18:50:58 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
void
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
witness_save(struct lock_object *lock, const char **filep, int *linep)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
2005-12-29 20:54:25 +00:00
|
|
|
struct lock_list_entry *lock_list;
|
2001-05-04 17:15:16 +00:00
|
|
|
struct lock_instance *instance;
|
2006-01-06 18:07:32 +00:00
|
|
|
struct lock_class *class;
|
2001-01-21 07:52:20 +00:00
|
|
|
|
panic: add a switch and infrastructure for stopping other CPUs in SMP case
Historical behavior of letting other CPUs merily go on is a default for
time being. The new behavior can be switched on via
kern.stop_scheduler_on_panic tunable and sysctl.
Stopping of the CPUs has (at least) the following benefits:
- more of the system state at panic time is preserved intact
- threads and interrupts do not interfere with dumping of the system
state
Only one thread runs uninterrupted after panic if stop_scheduler_on_panic
is set. That thread might call code that is also used in normal context
and that code might use locks to prevent concurrent execution of certain
parts. Those locks might be held by the stopped threads and would never
be released. To work around this issue, it was decided that instead of
explicit checks for panic context, we would rather put those checks
inside the locking primitives.
This change has substantial portions written and re-written by attilio
and kib at various times. Other changes are heavily based on the ideas
and patches submitted by jhb and mdf. bde has provided many insights
into the details and history of the current code.
The new behavior may cause problems for systems that use a USB keyboard
for interfacing with system console. This is because of some unusual
locking patterns in the ukbd code which have to be used because on one
hand ukbd is below syscons, but on the other hand it has to interface
with other usb code that uses regular mutexes/Giant for its concurrency
protection. Dumping to USB-connected disks may also be affected.
PR: amd64/139614 (at least)
In cooperation with: attilio, jhb, kib, mdf
Discussed with: arch@, bde
Tested by: Eugene Grosbein <eugen@grosbein.net>,
gnn,
Steven Hartland <killing@multiplay.co.uk>,
glebius,
Andrew Boyer <aboyer@averesystems.com>
(various versions of the patch)
MFC after: 3 months (or never)
2011-12-11 21:02:01 +00:00
|
|
|
/*
|
|
|
|
* This function is used independently in locking code to deal with
|
|
|
|
* Giant, SCHEDULER_STOPPED() check can be removed here after Giant
|
|
|
|
* is gone.
|
|
|
|
*/
|
|
|
|
if (SCHEDULER_STOPPED())
|
|
|
|
return;
|
2008-08-13 18:24:22 +00:00
|
|
|
KASSERT(witness_cold == 0, ("%s: witness_cold", __func__));
|
2008-08-30 13:20:35 +00:00
|
|
|
if (lock->lo_witness == NULL || witness_watch == -1 || panicstr != NULL)
|
2001-01-21 22:34:43 +00:00
|
|
|
return;
|
2006-01-06 18:07:32 +00:00
|
|
|
class = LOCK_CLASS(lock);
|
|
|
|
if (class->lc_flags & LC_SLEEPLOCK)
|
2005-12-29 20:54:25 +00:00
|
|
|
lock_list = curthread->td_sleeplocks;
|
|
|
|
else {
|
|
|
|
if (witness_skipspin)
|
|
|
|
return;
|
|
|
|
lock_list = PCPU_GET(spinlocks);
|
|
|
|
}
|
|
|
|
instance = find_instance(lock_list, lock);
|
2012-12-11 07:08:14 +00:00
|
|
|
if (instance == NULL) {
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("%s: lock (%s) %s not locked", __func__,
|
2006-01-06 18:07:32 +00:00
|
|
|
class->lc_name, lock->lo_name);
|
2012-12-11 07:08:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-05-04 17:15:16 +00:00
|
|
|
*filep = instance->li_file;
|
|
|
|
*linep = instance->li_line;
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
witness_restore(struct lock_object *lock, const char *file, int line)
|
2000-09-07 01:33:02 +00:00
|
|
|
{
|
2005-12-29 20:54:25 +00:00
|
|
|
struct lock_list_entry *lock_list;
|
2001-05-04 17:15:16 +00:00
|
|
|
struct lock_instance *instance;
|
2006-01-06 18:07:32 +00:00
|
|
|
struct lock_class *class;
|
2001-01-21 07:52:20 +00:00
|
|
|
|
panic: add a switch and infrastructure for stopping other CPUs in SMP case
Historical behavior of letting other CPUs merily go on is a default for
time being. The new behavior can be switched on via
kern.stop_scheduler_on_panic tunable and sysctl.
Stopping of the CPUs has (at least) the following benefits:
- more of the system state at panic time is preserved intact
- threads and interrupts do not interfere with dumping of the system
state
Only one thread runs uninterrupted after panic if stop_scheduler_on_panic
is set. That thread might call code that is also used in normal context
and that code might use locks to prevent concurrent execution of certain
parts. Those locks might be held by the stopped threads and would never
be released. To work around this issue, it was decided that instead of
explicit checks for panic context, we would rather put those checks
inside the locking primitives.
This change has substantial portions written and re-written by attilio
and kib at various times. Other changes are heavily based on the ideas
and patches submitted by jhb and mdf. bde has provided many insights
into the details and history of the current code.
The new behavior may cause problems for systems that use a USB keyboard
for interfacing with system console. This is because of some unusual
locking patterns in the ukbd code which have to be used because on one
hand ukbd is below syscons, but on the other hand it has to interface
with other usb code that uses regular mutexes/Giant for its concurrency
protection. Dumping to USB-connected disks may also be affected.
PR: amd64/139614 (at least)
In cooperation with: attilio, jhb, kib, mdf
Discussed with: arch@, bde
Tested by: Eugene Grosbein <eugen@grosbein.net>,
gnn,
Steven Hartland <killing@multiplay.co.uk>,
glebius,
Andrew Boyer <aboyer@averesystems.com>
(various versions of the patch)
MFC after: 3 months (or never)
2011-12-11 21:02:01 +00:00
|
|
|
/*
|
|
|
|
* This function is used independently in locking code to deal with
|
|
|
|
* Giant, SCHEDULER_STOPPED() check can be removed here after Giant
|
|
|
|
* is gone.
|
|
|
|
*/
|
|
|
|
if (SCHEDULER_STOPPED())
|
|
|
|
return;
|
2008-08-13 18:24:22 +00:00
|
|
|
KASSERT(witness_cold == 0, ("%s: witness_cold", __func__));
|
2008-08-30 13:20:35 +00:00
|
|
|
if (lock->lo_witness == NULL || witness_watch == -1 || panicstr != NULL)
|
2001-01-21 22:34:43 +00:00
|
|
|
return;
|
2006-01-06 18:07:32 +00:00
|
|
|
class = LOCK_CLASS(lock);
|
|
|
|
if (class->lc_flags & LC_SLEEPLOCK)
|
2005-12-29 20:54:25 +00:00
|
|
|
lock_list = curthread->td_sleeplocks;
|
|
|
|
else {
|
|
|
|
if (witness_skipspin)
|
|
|
|
return;
|
|
|
|
lock_list = PCPU_GET(spinlocks);
|
|
|
|
}
|
|
|
|
instance = find_instance(lock_list, lock);
|
2001-08-23 22:44:47 +00:00
|
|
|
if (instance == NULL)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("%s: lock (%s) %s not locked", __func__,
|
2006-01-06 18:07:32 +00:00
|
|
|
class->lc_name, lock->lo_name);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
lock->lo_witness->w_file = file;
|
|
|
|
lock->lo_witness->w_line = line;
|
2012-12-11 07:08:14 +00:00
|
|
|
if (instance == NULL)
|
|
|
|
return;
|
2001-05-04 17:15:16 +00:00
|
|
|
instance->li_file = file;
|
|
|
|
instance->li_line = line;
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
}
|
|
|
|
|
2001-06-27 06:27:29 +00:00
|
|
|
void
|
2011-11-16 21:51:17 +00:00
|
|
|
witness_assert(const struct lock_object *lock, int flags, const char *file,
|
|
|
|
int line)
|
2001-06-27 06:27:29 +00:00
|
|
|
{
|
|
|
|
#ifdef INVARIANT_SUPPORT
|
|
|
|
struct lock_instance *instance;
|
2006-01-06 18:07:32 +00:00
|
|
|
struct lock_class *class;
|
2001-06-27 06:27:29 +00:00
|
|
|
|
2008-08-29 15:47:53 +00:00
|
|
|
if (lock->lo_witness == NULL || witness_watch < 1 || panicstr != NULL)
|
2001-06-28 22:22:20 +00:00
|
|
|
return;
|
2006-01-06 18:07:32 +00:00
|
|
|
class = LOCK_CLASS(lock);
|
|
|
|
if ((class->lc_flags & LC_SLEEPLOCK) != 0)
|
2001-09-12 08:38:13 +00:00
|
|
|
instance = find_instance(curthread->td_sleeplocks, lock);
|
2006-01-06 18:07:32 +00:00
|
|
|
else if ((class->lc_flags & LC_SPINLOCK) != 0)
|
2001-06-27 06:27:29 +00:00
|
|
|
instance = find_instance(PCPU_GET(spinlocks), lock);
|
2001-11-15 19:46:36 +00:00
|
|
|
else {
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("Lock (%s) %s is not sleep or spin!",
|
2006-01-06 18:07:32 +00:00
|
|
|
class->lc_name, lock->lo_name);
|
2012-12-11 05:59:16 +00:00
|
|
|
return;
|
2001-11-15 19:46:36 +00:00
|
|
|
}
|
2001-06-27 06:27:29 +00:00
|
|
|
switch (flags) {
|
|
|
|
case LA_UNLOCKED:
|
|
|
|
if (instance != NULL)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("Lock (%s) %s locked @ %s:%d.",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2001-06-27 06:27:29 +00:00
|
|
|
break;
|
|
|
|
case LA_LOCKED:
|
|
|
|
case LA_LOCKED | LA_RECURSED:
|
|
|
|
case LA_LOCKED | LA_NOTRECURSED:
|
|
|
|
case LA_SLOCKED:
|
|
|
|
case LA_SLOCKED | LA_RECURSED:
|
|
|
|
case LA_SLOCKED | LA_NOTRECURSED:
|
|
|
|
case LA_XLOCKED:
|
|
|
|
case LA_XLOCKED | LA_RECURSED:
|
|
|
|
case LA_XLOCKED | LA_NOTRECURSED:
|
2001-11-15 19:46:36 +00:00
|
|
|
if (instance == NULL) {
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("Lock (%s) %s not locked @ %s:%d.",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2001-11-15 19:46:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-06-27 06:27:29 +00:00
|
|
|
if ((flags & LA_XLOCKED) != 0 &&
|
|
|
|
(instance->li_flags & LI_EXCLUSIVE) == 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"Lock (%s) %s not exclusively locked @ %s:%d.",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2001-06-27 06:27:29 +00:00
|
|
|
if ((flags & LA_SLOCKED) != 0 &&
|
|
|
|
(instance->li_flags & LI_EXCLUSIVE) != 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic(
|
|
|
|
"Lock (%s) %s exclusively locked @ %s:%d.",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2001-06-27 06:27:29 +00:00
|
|
|
if ((flags & LA_RECURSED) != 0 &&
|
|
|
|
(instance->li_flags & LI_RECURSEMASK) == 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("Lock (%s) %s not recursed @ %s:%d.",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2001-06-27 06:27:29 +00:00
|
|
|
if ((flags & LA_NOTRECURSED) != 0 &&
|
|
|
|
(instance->li_flags & LI_RECURSEMASK) != 0)
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("Lock (%s) %s recursed @ %s:%d.",
|
2011-10-12 09:21:02 +00:00
|
|
|
class->lc_name, lock->lo_name,
|
|
|
|
fixup_filename(file), line);
|
2001-06-27 06:27:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("Invalid lock assertion at %s:%d.",
|
2011-10-12 09:21:02 +00:00
|
|
|
fixup_filename(file), line);
|
2001-06-27 06:27:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* INVARIANT_SUPPORT */
|
|
|
|
}
|
|
|
|
|
2009-01-21 04:19:18 +00:00
|
|
|
static void
|
|
|
|
witness_setflag(struct lock_object *lock, int flag, int set)
|
|
|
|
{
|
|
|
|
struct lock_list_entry *lock_list;
|
|
|
|
struct lock_instance *instance;
|
|
|
|
struct lock_class *class;
|
|
|
|
|
|
|
|
if (lock->lo_witness == NULL || witness_watch == -1 || panicstr != NULL)
|
|
|
|
return;
|
|
|
|
class = LOCK_CLASS(lock);
|
|
|
|
if (class->lc_flags & LC_SLEEPLOCK)
|
|
|
|
lock_list = curthread->td_sleeplocks;
|
|
|
|
else {
|
|
|
|
if (witness_skipspin)
|
|
|
|
return;
|
|
|
|
lock_list = PCPU_GET(spinlocks);
|
|
|
|
}
|
|
|
|
instance = find_instance(lock_list, lock);
|
2012-12-11 07:08:14 +00:00
|
|
|
if (instance == NULL) {
|
2012-12-11 01:23:50 +00:00
|
|
|
kassert_panic("%s: lock (%s) %s not locked", __func__,
|
2009-01-21 04:19:18 +00:00
|
|
|
class->lc_name, lock->lo_name);
|
2012-12-11 07:08:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-01-21 04:19:18 +00:00
|
|
|
|
|
|
|
if (set)
|
|
|
|
instance->li_flags |= flag;
|
|
|
|
else
|
|
|
|
instance->li_flags &= ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
witness_norelease(struct lock_object *lock)
|
|
|
|
{
|
|
|
|
|
|
|
|
witness_setflag(lock, LI_NORELEASE, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
witness_releaseok(struct lock_object *lock)
|
|
|
|
{
|
|
|
|
|
|
|
|
witness_setflag(lock, LI_NORELEASE, 0);
|
|
|
|
}
|
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
#ifdef DDB
|
2003-03-10 17:03:57 +00:00
|
|
|
static void
|
2008-08-13 18:24:22 +00:00
|
|
|
witness_ddb_list(struct thread *td)
|
2003-03-10 17:03:57 +00:00
|
|
|
{
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
KASSERT(witness_cold == 0, ("%s: witness_cold", __func__));
|
2004-07-10 21:42:16 +00:00
|
|
|
KASSERT(kdb_active, ("%s: not in the debugger", __func__));
|
2003-03-10 17:03:57 +00:00
|
|
|
|
2008-08-29 15:47:53 +00:00
|
|
|
if (witness_watch < 1)
|
2003-03-10 17:03:57 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-11 18:24:22 +00:00
|
|
|
witness_list_locks(&td->td_sleeplocks, db_printf);
|
2003-03-10 17:03:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We only handle spinlocks if td == curthread. This is somewhat broken
|
|
|
|
* if td is currently executing on some other CPU and holds spin locks
|
|
|
|
* as we won't display those locks. If we had a MI way of getting
|
|
|
|
* the per-cpu data for a given cpu then we could use
|
2003-04-10 17:35:44 +00:00
|
|
|
* td->td_oncpu to get the list of spinlocks for this thread
|
2003-03-10 17:03:57 +00:00
|
|
|
* and "fix" this.
|
|
|
|
*
|
Commit 10/14 of sched_lock decomposition.
- Add new spinlocks to support thread_lock() and adjust ordering.
Tested by: kris, current@
Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc.
Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
2007-06-04 23:55:45 +00:00
|
|
|
* That still wouldn't really fix this unless we locked the scheduler
|
|
|
|
* lock or stopped the other CPU to make sure it wasn't changing the
|
|
|
|
* list out from under us. It is probably best to just not try to
|
|
|
|
* handle threads on other CPU's for now.
|
2003-03-10 17:03:57 +00:00
|
|
|
*/
|
|
|
|
if (td == curthread && PCPU_GET(spinlocks) != NULL)
|
2010-05-11 18:24:22 +00:00
|
|
|
witness_list_locks(PCPU_PTR(spinlocks), db_printf);
|
2003-03-10 17:03:57 +00:00
|
|
|
}
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
|
2001-03-28 12:39:40 +00:00
|
|
|
DB_SHOW_COMMAND(locks, db_witness_list)
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2001-04-06 21:37:52 +00:00
|
|
|
|
2006-04-25 20:24:23 +00:00
|
|
|
if (have_addr)
|
2015-05-21 15:16:18 +00:00
|
|
|
td = db_lookup_thread(addr, true);
|
2006-04-25 20:24:23 +00:00
|
|
|
else
|
|
|
|
td = kdb_thread;
|
2008-08-13 18:24:22 +00:00
|
|
|
witness_ddb_list(td);
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
2008-09-15 22:45:14 +00:00
|
|
|
DB_SHOW_ALL_COMMAND(locks, db_witness_list_all)
|
2004-12-26 22:52:24 +00:00
|
|
|
{
|
|
|
|
struct thread *td;
|
|
|
|
struct proc *p;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It would be nice to list only threads and processes that actually
|
|
|
|
* held sleep locks, but that information is currently not exported
|
|
|
|
* by WITNESS.
|
|
|
|
*/
|
|
|
|
FOREACH_PROC_IN_SYSTEM(p) {
|
|
|
|
if (!witness_proc_has_locks(p))
|
|
|
|
continue;
|
|
|
|
FOREACH_THREAD_IN_PROC(p, td) {
|
|
|
|
if (!witness_thread_has_locks(td))
|
|
|
|
continue;
|
2005-12-29 20:53:01 +00:00
|
|
|
db_printf("Process %d (%s) thread %p (%d)\n", p->p_pid,
|
2008-09-12 21:44:01 +00:00
|
|
|
p->p_comm, td, td->td_tid);
|
2008-08-13 18:24:22 +00:00
|
|
|
witness_ddb_list(td);
|
2012-08-22 20:00:41 +00:00
|
|
|
if (db_pager_quit)
|
|
|
|
return;
|
2004-12-26 22:52:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-15 22:45:14 +00:00
|
|
|
DB_SHOW_ALIAS(alllocks, db_witness_list_all)
|
2004-12-26 22:52:24 +00:00
|
|
|
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
DB_SHOW_COMMAND(witness, db_witness_display)
|
|
|
|
{
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
witness_ddb_display(db_printf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_debug_witness_badstacks(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct witness_lock_order_data *data1, *data2, *tmp_data1, *tmp_data2;
|
|
|
|
struct witness *tmp_w1, *tmp_w2, *w1, *w2;
|
|
|
|
struct sbuf *sb;
|
|
|
|
u_int w_rmatrix1, w_rmatrix2;
|
|
|
|
int error, generation, i, j;
|
|
|
|
|
|
|
|
tmp_data1 = NULL;
|
|
|
|
tmp_data2 = NULL;
|
|
|
|
tmp_w1 = NULL;
|
|
|
|
tmp_w2 = NULL;
|
2008-08-29 15:47:53 +00:00
|
|
|
if (witness_watch < 1) {
|
2008-08-13 18:24:22 +00:00
|
|
|
error = SYSCTL_OUT(req, w_notrunning, sizeof(w_notrunning));
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
if (witness_cold) {
|
|
|
|
error = SYSCTL_OUT(req, w_stillcold, sizeof(w_stillcold));
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
error = 0;
|
2014-10-11 02:02:58 +00:00
|
|
|
sb = sbuf_new(NULL, NULL, badstack_sbuf_size, SBUF_AUTOEXTEND);
|
2008-08-13 18:24:22 +00:00
|
|
|
if (sb == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
/* Allocate and init temporary storage space. */
|
|
|
|
tmp_w1 = malloc(sizeof(struct witness), M_TEMP, M_WAITOK | M_ZERO);
|
|
|
|
tmp_w2 = malloc(sizeof(struct witness), M_TEMP, M_WAITOK | M_ZERO);
|
|
|
|
tmp_data1 = malloc(sizeof(struct witness_lock_order_data), M_TEMP,
|
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
tmp_data2 = malloc(sizeof(struct witness_lock_order_data), M_TEMP,
|
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
stack_zero(&tmp_data1->wlod_stack);
|
|
|
|
stack_zero(&tmp_data2->wlod_stack);
|
|
|
|
|
|
|
|
restart:
|
|
|
|
mtx_lock_spin(&w_mtx);
|
|
|
|
generation = w_generation;
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
sbuf_printf(sb, "Number of known direct relationships is %d\n",
|
|
|
|
w_lohash.wloh_count);
|
|
|
|
for (i = 1; i < w_max_used_index; i++) {
|
|
|
|
mtx_lock_spin(&w_mtx);
|
|
|
|
if (generation != w_generation) {
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
|
|
|
|
/* The graph has changed, try again. */
|
|
|
|
req->oldidx = 0;
|
|
|
|
sbuf_clear(sb);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
|
|
|
|
w1 = &w_data[i];
|
|
|
|
if (w1->w_reversed == 0) {
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy w1 locally so we can release the spin lock. */
|
|
|
|
*tmp_w1 = *w1;
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
|
|
|
|
if (tmp_w1->w_reversed == 0)
|
|
|
|
continue;
|
|
|
|
for (j = 1; j < w_max_used_index; j++) {
|
|
|
|
if ((w_rmatrix[i][j] & WITNESS_REVERSAL) == 0 || i > j)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mtx_lock_spin(&w_mtx);
|
|
|
|
if (generation != w_generation) {
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
|
|
|
|
/* The graph has changed, try again. */
|
|
|
|
req->oldidx = 0;
|
|
|
|
sbuf_clear(sb);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
|
|
|
|
w2 = &w_data[j];
|
|
|
|
data1 = witness_lock_order_get(w1, w2);
|
|
|
|
data2 = witness_lock_order_get(w2, w1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy information locally so we can release the
|
|
|
|
* spin lock.
|
|
|
|
*/
|
|
|
|
*tmp_w2 = *w2;
|
|
|
|
w_rmatrix1 = (unsigned int)w_rmatrix[i][j];
|
|
|
|
w_rmatrix2 = (unsigned int)w_rmatrix[j][i];
|
|
|
|
|
|
|
|
if (data1) {
|
|
|
|
stack_zero(&tmp_data1->wlod_stack);
|
|
|
|
stack_copy(&data1->wlod_stack,
|
|
|
|
&tmp_data1->wlod_stack);
|
|
|
|
}
|
|
|
|
if (data2 && data2 != data1) {
|
|
|
|
stack_zero(&tmp_data2->wlod_stack);
|
|
|
|
stack_copy(&data2->wlod_stack,
|
|
|
|
&tmp_data2->wlod_stack);
|
|
|
|
}
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
|
|
|
|
sbuf_printf(sb,
|
|
|
|
"\nLock order reversal between \"%s\"(%s) and \"%s\"(%s)!\n",
|
|
|
|
tmp_w1->w_name, tmp_w1->w_class->lc_name,
|
|
|
|
tmp_w2->w_name, tmp_w2->w_class->lc_name);
|
|
|
|
if (data1) {
|
|
|
|
sbuf_printf(sb,
|
|
|
|
"Lock order \"%s\"(%s) -> \"%s\"(%s) first seen at:\n",
|
|
|
|
tmp_w1->w_name, tmp_w1->w_class->lc_name,
|
|
|
|
tmp_w2->w_name, tmp_w2->w_class->lc_name);
|
|
|
|
stack_sbuf_print(sb, &tmp_data1->wlod_stack);
|
|
|
|
sbuf_printf(sb, "\n");
|
|
|
|
}
|
|
|
|
if (data2 && data2 != data1) {
|
|
|
|
sbuf_printf(sb,
|
|
|
|
"Lock order \"%s\"(%s) -> \"%s\"(%s) first seen at:\n",
|
|
|
|
tmp_w2->w_name, tmp_w2->w_class->lc_name,
|
|
|
|
tmp_w1->w_name, tmp_w1->w_class->lc_name);
|
|
|
|
stack_sbuf_print(sb, &tmp_data2->wlod_stack);
|
|
|
|
sbuf_printf(sb, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_lock_spin(&w_mtx);
|
|
|
|
if (generation != w_generation) {
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The graph changed while we were printing stack data,
|
|
|
|
* try again.
|
|
|
|
*/
|
|
|
|
req->oldidx = 0;
|
|
|
|
sbuf_clear(sb);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
|
|
|
|
/* Free temporary storage space. */
|
|
|
|
free(tmp_data1, M_TEMP);
|
|
|
|
free(tmp_data2, M_TEMP);
|
|
|
|
free(tmp_w1, M_TEMP);
|
|
|
|
free(tmp_w2, M_TEMP);
|
|
|
|
|
|
|
|
sbuf_finish(sb);
|
|
|
|
error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1);
|
|
|
|
sbuf_delete(sb);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2015-11-19 05:56:59 +00:00
|
|
|
static int
|
|
|
|
sysctl_debug_witness_channel(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
static const struct {
|
|
|
|
enum witness_channel channel;
|
|
|
|
const char *name;
|
|
|
|
} channels[] = {
|
|
|
|
{ WITNESS_CONSOLE, "console" },
|
|
|
|
{ WITNESS_LOG, "log" },
|
|
|
|
{ WITNESS_NONE, "none" },
|
|
|
|
};
|
|
|
|
char buf[16];
|
|
|
|
u_int i;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
for (i = 0; i < nitems(channels); i++)
|
|
|
|
if (witness_channel == channels[i].channel) {
|
|
|
|
snprintf(buf, sizeof(buf), "%s", channels[i].name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
error = EINVAL;
|
|
|
|
for (i = 0; i < nitems(channels); i++)
|
|
|
|
if (strcmp(channels[i].name, buf) == 0) {
|
|
|
|
witness_channel = channels[i].channel;
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
static int
|
|
|
|
sysctl_debug_witness_fullgraph(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct witness *w;
|
|
|
|
struct sbuf *sb;
|
|
|
|
int error;
|
|
|
|
|
2008-08-29 15:47:53 +00:00
|
|
|
if (witness_watch < 1) {
|
2008-08-13 18:24:22 +00:00
|
|
|
error = SYSCTL_OUT(req, w_notrunning, sizeof(w_notrunning));
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
if (witness_cold) {
|
|
|
|
error = SYSCTL_OUT(req, w_stillcold, sizeof(w_stillcold));
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
error = 0;
|
2011-01-27 00:34:12 +00:00
|
|
|
|
|
|
|
error = sysctl_wire_old_buffer(req, 0);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2010-09-16 16:13:12 +00:00
|
|
|
sb = sbuf_new_for_sysctl(NULL, NULL, FULLGRAPH_SBUF_SIZE, req);
|
2008-08-13 18:24:22 +00:00
|
|
|
if (sb == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
sbuf_printf(sb, "\n");
|
|
|
|
|
|
|
|
mtx_lock_spin(&w_mtx);
|
|
|
|
STAILQ_FOREACH(w, &w_all, w_list)
|
|
|
|
w->w_displayed = 0;
|
|
|
|
STAILQ_FOREACH(w, &w_all, w_list)
|
|
|
|
witness_add_fullgraph(sb, w);
|
|
|
|
mtx_unlock_spin(&w_mtx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close the sbuf and return to userland.
|
|
|
|
*/
|
2010-09-16 16:13:12 +00:00
|
|
|
error = sbuf_finish(sb);
|
2008-08-13 18:24:22 +00:00
|
|
|
sbuf_delete(sb);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_debug_witness_watch(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error, value;
|
|
|
|
|
2008-08-30 13:20:35 +00:00
|
|
|
value = witness_watch;
|
2008-08-13 18:24:22 +00:00
|
|
|
error = sysctl_handle_int(oidp, &value, 0, req);
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return (error);
|
2008-08-29 15:47:53 +00:00
|
|
|
if (value > 1 || value < -1 ||
|
|
|
|
(witness_watch == -1 && value != witness_watch))
|
2008-08-13 18:24:22 +00:00
|
|
|
return (EINVAL);
|
2008-08-29 15:47:53 +00:00
|
|
|
witness_watch = value;
|
2008-08-13 18:24:22 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
witness_add_fullgraph(struct sbuf *sb, struct witness *w)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (w->w_displayed != 0 || (w->w_file == NULL && w->w_line == 0))
|
|
|
|
return;
|
|
|
|
w->w_displayed = 1;
|
|
|
|
|
|
|
|
WITNESS_INDEX_ASSERT(w->w_index);
|
|
|
|
for (i = 1; i <= w_max_used_index; i++) {
|
|
|
|
if (w_rmatrix[w->w_index][i] & WITNESS_PARENT) {
|
|
|
|
sbuf_printf(sb, "\"%s\",\"%s\"\n", w->w_name,
|
|
|
|
w_data[i].w_name);
|
|
|
|
witness_add_fullgraph(sb, &w_data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A simple hash function. Takes a key pointer and a key size. If size == 0,
|
|
|
|
* interprets the key as a string and reads until the null
|
|
|
|
* terminator. Otherwise, reads the first size bytes. Returns an unsigned 32-bit
|
|
|
|
* hash value computed from the key.
|
|
|
|
*/
|
|
|
|
static uint32_t
|
|
|
|
witness_hash_djb2(const uint8_t *key, uint32_t size)
|
|
|
|
{
|
|
|
|
unsigned int hash = 5381;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* hash = hash * 33 + key[i] */
|
|
|
|
if (size)
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
hash = ((hash << 5) + hash) + (unsigned int)key[i];
|
|
|
|
else
|
|
|
|
for (i = 0; key[i] != 0; i++)
|
|
|
|
hash = ((hash << 5) + hash) + (unsigned int)key[i];
|
|
|
|
|
|
|
|
return (hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes the two witness hash tables. Called exactly once from
|
|
|
|
* witness_initialize().
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
witness_init_hash_tables(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
MPASS(witness_cold);
|
|
|
|
|
|
|
|
/* Initialize the hash tables. */
|
|
|
|
for (i = 0; i < WITNESS_HASH_SIZE; i++)
|
|
|
|
w_hash.wh_array[i] = NULL;
|
|
|
|
|
|
|
|
w_hash.wh_size = WITNESS_HASH_SIZE;
|
|
|
|
w_hash.wh_count = 0;
|
|
|
|
|
|
|
|
/* Initialize the lock order data hash. */
|
|
|
|
w_lofree = NULL;
|
|
|
|
for (i = 0; i < WITNESS_LO_DATA_COUNT; i++) {
|
|
|
|
memset(&w_lodata[i], 0, sizeof(w_lodata[i]));
|
|
|
|
w_lodata[i].wlod_next = w_lofree;
|
|
|
|
w_lofree = &w_lodata[i];
|
|
|
|
}
|
|
|
|
w_lohash.wloh_size = WITNESS_LO_HASH_SIZE;
|
|
|
|
w_lohash.wloh_count = 0;
|
|
|
|
for (i = 0; i < WITNESS_LO_HASH_SIZE; i++)
|
|
|
|
w_lohash.wloh_array[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct witness *
|
|
|
|
witness_hash_get(const char *key)
|
|
|
|
{
|
|
|
|
struct witness *w;
|
|
|
|
uint32_t hash;
|
|
|
|
|
|
|
|
MPASS(key != NULL);
|
|
|
|
if (witness_cold == 0)
|
|
|
|
mtx_assert(&w_mtx, MA_OWNED);
|
|
|
|
hash = witness_hash_djb2(key, 0) % w_hash.wh_size;
|
|
|
|
w = w_hash.wh_array[hash];
|
|
|
|
while (w != NULL) {
|
|
|
|
if (strcmp(w->w_name, key) == 0)
|
|
|
|
goto out;
|
|
|
|
w = w->w_hash_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return (w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
witness_hash_put(struct witness *w)
|
|
|
|
{
|
|
|
|
uint32_t hash;
|
|
|
|
|
|
|
|
MPASS(w != NULL);
|
|
|
|
MPASS(w->w_name != NULL);
|
|
|
|
if (witness_cold == 0)
|
|
|
|
mtx_assert(&w_mtx, MA_OWNED);
|
|
|
|
KASSERT(witness_hash_get(w->w_name) == NULL,
|
|
|
|
("%s: trying to add a hash entry that already exists!", __func__));
|
|
|
|
KASSERT(w->w_hash_next == NULL,
|
|
|
|
("%s: w->w_hash_next != NULL", __func__));
|
|
|
|
|
|
|
|
hash = witness_hash_djb2(w->w_name, 0) % w_hash.wh_size;
|
|
|
|
w->w_hash_next = w_hash.wh_array[hash];
|
|
|
|
w_hash.wh_array[hash] = w;
|
|
|
|
w_hash.wh_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct witness_lock_order_data *
|
|
|
|
witness_lock_order_get(struct witness *parent, struct witness *child)
|
|
|
|
{
|
|
|
|
struct witness_lock_order_data *data = NULL;
|
|
|
|
struct witness_lock_order_key key;
|
|
|
|
unsigned int hash;
|
|
|
|
|
|
|
|
MPASS(parent != NULL && child != NULL);
|
|
|
|
key.from = parent->w_index;
|
|
|
|
key.to = child->w_index;
|
|
|
|
WITNESS_INDEX_ASSERT(key.from);
|
|
|
|
WITNESS_INDEX_ASSERT(key.to);
|
|
|
|
if ((w_rmatrix[parent->w_index][child->w_index]
|
|
|
|
& WITNESS_LOCK_ORDER_KNOWN) == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
hash = witness_hash_djb2((const char*)&key,
|
|
|
|
sizeof(key)) % w_lohash.wloh_size;
|
|
|
|
data = w_lohash.wloh_array[hash];
|
|
|
|
while (data != NULL) {
|
|
|
|
if (witness_lock_order_key_equal(&data->wlod_key, &key))
|
|
|
|
break;
|
|
|
|
data = data->wlod_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that parent and child have a known relationship, are not the same,
|
|
|
|
* and child is actually a child of parent. This is done without w_mtx
|
|
|
|
* to avoid contention in the common case.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
witness_lock_order_check(struct witness *parent, struct witness *child)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (parent != child &&
|
|
|
|
w_rmatrix[parent->w_index][child->w_index]
|
|
|
|
& WITNESS_LOCK_ORDER_KNOWN &&
|
|
|
|
isitmychild(parent, child))
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
witness_lock_order_add(struct witness *parent, struct witness *child)
|
|
|
|
{
|
|
|
|
struct witness_lock_order_data *data = NULL;
|
|
|
|
struct witness_lock_order_key key;
|
|
|
|
unsigned int hash;
|
|
|
|
|
|
|
|
MPASS(parent != NULL && child != NULL);
|
|
|
|
key.from = parent->w_index;
|
|
|
|
key.to = child->w_index;
|
|
|
|
WITNESS_INDEX_ASSERT(key.from);
|
|
|
|
WITNESS_INDEX_ASSERT(key.to);
|
|
|
|
if (w_rmatrix[parent->w_index][child->w_index]
|
|
|
|
& WITNESS_LOCK_ORDER_KNOWN)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
hash = witness_hash_djb2((const char*)&key,
|
|
|
|
sizeof(key)) % w_lohash.wloh_size;
|
|
|
|
w_rmatrix[parent->w_index][child->w_index] |= WITNESS_LOCK_ORDER_KNOWN;
|
|
|
|
data = w_lofree;
|
|
|
|
if (data == NULL)
|
|
|
|
return (0);
|
|
|
|
w_lofree = data->wlod_next;
|
|
|
|
data->wlod_next = w_lohash.wloh_array[hash];
|
|
|
|
data->wlod_key = key;
|
|
|
|
w_lohash.wloh_array[hash] = data;
|
|
|
|
w_lohash.wloh_count++;
|
|
|
|
stack_zero(&data->wlod_stack);
|
|
|
|
stack_save(&data->wlod_stack);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call this whenver the structure of the witness graph changes. */
|
|
|
|
static void
|
|
|
|
witness_increment_graph_generation(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (witness_cold == 0)
|
|
|
|
mtx_assert(&w_mtx, MA_OWNED);
|
|
|
|
w_generation++;
|
|
|
|
}
|
|
|
|
|
2015-11-19 05:56:59 +00:00
|
|
|
static int
|
|
|
|
witness_output_drain(void *arg __unused, const char *data, int len)
|
|
|
|
{
|
|
|
|
|
2015-11-23 18:45:35 +00:00
|
|
|
witness_output("%.*s", len, data);
|
2015-11-19 05:56:59 +00:00
|
|
|
return (len);
|
|
|
|
}
|
|
|
|
|
2008-08-13 18:24:22 +00:00
|
|
|
static void
|
2015-11-19 05:56:59 +00:00
|
|
|
witness_debugger(int cond, const char *msg)
|
2008-08-13 18:24:22 +00:00
|
|
|
{
|
2015-11-19 05:56:59 +00:00
|
|
|
char buf[32];
|
|
|
|
struct sbuf sb;
|
|
|
|
struct stack st;
|
2008-08-13 18:24:22 +00:00
|
|
|
|
2015-11-19 05:56:59 +00:00
|
|
|
if (!cond)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (witness_trace) {
|
|
|
|
sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
|
|
|
|
sbuf_set_drain(&sb, witness_output_drain, NULL);
|
|
|
|
|
|
|
|
stack_zero(&st);
|
|
|
|
stack_save(&st);
|
|
|
|
witness_output("stack backtrace:\n");
|
|
|
|
stack_sbuf_print_ddb(&sb, &st);
|
|
|
|
|
|
|
|
sbuf_finish(&sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef KDB
|
|
|
|
if (witness_kdb)
|
2008-08-13 18:24:22 +00:00
|
|
|
kdb_enter(KDB_WHY_WITNESS, msg);
|
Rework the witness code to work with sx locks as well as mutexes.
- 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.
2001-03-28 09:03:24 +00:00
|
|
|
#endif
|
2015-11-19 05:56:59 +00:00
|
|
|
}
|