FreeBSD kernel kern code
subr_witness.c File Reference
#include <sys/cdefs.h>
#include "opt_ddb.h"
#include "opt_hwpmc_hooks.h"
#include "opt_stack.h"
#include "opt_witness.h"
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/sbuf.h>
#include <sys/sched.h>
#include <sys/stack.h>
#include <sys/sysctl.h>
#include <sys/syslog.h>
#include <sys/systm.h>
#include <machine/stdarg.h>
Include dependency graph for subr_witness.c:

Go to the source code of this file.

Data Structures

struct  lock_instance
 
struct  lock_list_entry
 
struct  witness
 
struct  witness_hash
 
struct  witness_lock_order_key
 
struct  witness_lock_order_data
 
struct  witness_lock_order_hash
 
struct  witness_blessed
 
struct  witness_pendhelp
 
struct  witness_order_list_entry
 

Macros

#define KTR_WITNESS   0
 
#define LI_RECURSEMASK   0x0000ffff /* Recursion depth of lock instance. */
 
#define LI_EXCLUSIVE   0x00010000 /* Exclusive lock instance. */
 
#define LI_NORELEASE   0x00020000 /* Lock not allowed to be released. */
 
#define LI_SLEEPABLE   0x00040000 /* Lock may be held while sleeping. */
 
#define WITNESS_COUNT   1536
 
#define WITNESS_HASH_SIZE   251 /* Prime, gives load factor < 2 */
 
#define WITNESS_PENDLIST   (512 + (MAXCPU * 4))
 
#define WITNESS_LO_DATA_COUNT   2048
 
#define WITNESS_LO_HASH_SIZE   1021
 
#define LOCK_NCHILDREN   5
 
#define LOCK_CHILDCOUNT   2048
 
#define MAX_W_NAME   64
 
#define FULLGRAPH_SBUF_SIZE   512
 
#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
 
#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. */
 
#define WITNESS_DTOA(x)   (((x) & WITNESS_RELATED_MASK) >> 2)
 
#define WITNESS_ATOD(x)   (((x) & WITNESS_RELATED_MASK) << 2)
 
#define WITNESS_INDEX_ASSERT(i)    MPASS((i) > 0 && (i) <= w_max_used_index && (i) < witness_count)
 

Enumerations

enum  witness_channel { WITNESS_CONSOLE , WITNESS_LOG , WITNESS_NONE }
 

Functions

 __FBSDID ("$FreeBSD$")
 
static MALLOC_DEFINE (M_WITNESS, "Witness", "Witness")
 
 STAILQ_HEAD (witness_list, witness)
 
static __inline int witness_lock_type_equal (struct witness *w1, struct witness *w2)
 
static __inline int witness_lock_order_key_equal (const struct witness_lock_order_key *a, const struct witness_lock_order_key *b)
 
static int _isitmyx (struct witness *w1, struct witness *w2, int rmask, const char *fname)
 
static void adopt (struct witness *parent, struct witness *child)
 
static int blessed (struct witness *, struct witness *)
 
static void depart (struct witness *w)
 
static struct witnessenroll (const char *description, struct lock_class *lock_class)
 
static struct lock_instancefind_instance (struct lock_list_entry *list, const struct lock_object *lock)
 
static int isitmychild (struct witness *parent, struct witness *child)
 
static int isitmydescendant (struct witness *parent, struct witness *child)
 
static void itismychild (struct witness *parent, struct witness *child)
 
static int sysctl_debug_witness_badstacks (SYSCTL_HANDLER_ARGS)
 
static int sysctl_debug_witness_watch (SYSCTL_HANDLER_ARGS)
 
static int sysctl_debug_witness_fullgraph (SYSCTL_HANDLER_ARGS)
 
static int sysctl_debug_witness_channel (SYSCTL_HANDLER_ARGS)
 
static void witness_add_fullgraph (struct sbuf *sb, struct witness *parent)
 
static void witness_enter_debugger (const char *msg)
 
static void witness_debugger (int cond, const char *msg)
 
static void witness_free (struct witness *m)
 
static struct witnesswitness_get (void)
 
static uint32_t witness_hash_djb2 (const uint8_t *key, uint32_t size)
 
static struct witnesswitness_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)
 
static void witness_lock_list_free (struct lock_list_entry *lle)
 
static struct lock_list_entrywitness_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_datawitness_lock_order_get (struct witness *parent, struct witness *child)
 
static void witness_list_lock (struct lock_instance *instance, int(*prnt)(const char *fmt,...))
 
static int witness_output (const char *fmt,...) __printflike(1
 
static int static int witness_output_drain (void *arg __unused, const char *data, int len)
 
static int witness_voutput (const char *fmt, va_list ap) __printflike(1
 
static int static void witness_setflag (struct lock_object *lock, int flag, int set)
 
 FEATURE (witness, "kernel has witness(9) support")
 
static SYSCTL_NODE (_debug, OID_AUTO, witness, CTLFLAG_RW|CTLFLAG_MPSAFE, NULL, "Witness Locking")
 
 SYSCTL_PROC (_debug_witness, OID_AUTO, watch, CTLFLAG_RWTUN|CTLTYPE_INT|CTLFLAG_MPSAFE, NULL, 0, sysctl_debug_witness_watch, "I", "witness is watching lock operations")
 
 SYSCTL_INT (_debug_witness, OID_AUTO, skipspin, CTLFLAG_RDTUN, &witness_skipspin, 0, "")
 
 SYSCTL_INT (_debug_witness, OID_AUTO, witness_count, CTLFLAG_RDTUN, &witness_count, 0, "")
 
 SYSCTL_PROC (_debug_witness, OID_AUTO, output_channel, CTLTYPE_STRING|CTLFLAG_RWTUN|CTLFLAG_MPSAFE, NULL, 0, sysctl_debug_witness_channel, "A", "Output channel for warnings")
 
 SYSCTL_PROC (_debug_witness, OID_AUTO, fullgraph, CTLTYPE_STRING|CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, 0, sysctl_debug_witness_fullgraph, "A", "Show locks relation graphs")
 
 SYSCTL_PROC (_debug_witness, OID_AUTO, badstacks, CTLTYPE_STRING|CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, 0, sysctl_debug_witness_badstacks, "A", "Show bad witness stacks")
 
 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, "")
 
static const char * fixup_filename (const char *file)
 
int witness_startup_count (void)
 
void witness_startup (void *mem)
 
void witness_init (struct lock_object *lock, const char *type)
 
void witness_destroy (struct lock_object *lock)
 
int witness_defineorder (struct lock_object *lock1, struct lock_object *lock2)
 
void witness_checkorder (struct lock_object *lock, int flags, const char *file, int line, struct lock_object *interlock)
 
void witness_lock (struct lock_object *lock, int flags, const char *file, int line)
 
void witness_upgrade (struct lock_object *lock, int flags, const char *file, int line)
 
void witness_downgrade (struct lock_object *lock, int flags, const char *file, int line)
 
void witness_unlock (struct lock_object *lock, int flags, const char *file, int line)
 
void witness_thread_exit (struct thread *td)
 
int witness_warn (int flags, struct lock_object *lock, const char *fmt,...)
 
const char * witness_file (struct lock_object *lock)
 
int witness_line (struct lock_object *lock)
 
int witness_list_locks (struct lock_list_entry **lock_list, int(*prnt)(const char *fmt,...))
 
void witness_display_spinlock (struct lock_object *lock, struct thread *owner, int(*prnt)(const char *fmt,...))
 
void witness_save (struct lock_object *lock, const char **filep, int *linep)
 
void witness_restore (struct lock_object *lock, const char *file, int line)
 
void witness_assert (const struct lock_object *lock, int flags, const char *file, int line)
 
void witness_norelease (struct lock_object *lock)
 
void witness_releaseok (struct lock_object *lock)
 
static void sbuf_print_witness_badstacks (struct sbuf *sb, size_t *oldidx)
 

Variables

static int witness_watch = 1
 
int witness_skipspin = 0
 
int badstack_sbuf_size
 
int witness_count = WITNESS_COUNT
 
static enum witness_channel witness_channel = WITNESS_CONSOLE
 
static struct mtx w_mtx
 
static struct witness_list w_free = STAILQ_HEAD_INITIALIZER(w_free)
 
static struct witness_list w_all = STAILQ_HEAD_INITIALIZER(w_all)
 
static struct witness_list w_spin = STAILQ_HEAD_INITIALIZER(w_spin)
 
static struct witness_list w_sleep = STAILQ_HEAD_INITIALIZER(w_sleep)
 
static struct lock_list_entryw_lock_list_free = NULL
 
static struct witness_pendhelp pending_locks [WITNESS_PENDLIST]
 
static u_int pending_cnt
 
static int w_free_cnt
 
static int w_spin_cnt
 
static int w_sleep_cnt
 
static struct witnessw_data
 
static uint8_t ** w_rmatrix
 
static struct lock_list_entry w_locklistdata [LOCK_CHILDCOUNT]
 
static struct witness_hash w_hash
 
static struct witness_lock_order_data w_lodata [WITNESS_LO_DATA_COUNT]
 
static struct witness_lock_order_dataw_lofree = NULL
 
static struct witness_lock_order_hash w_lohash
 
static int w_max_used_index = 0
 
static unsigned int w_generation = 0
 
static const char w_notrunning [] = "Witness not running\n"
 
static const char w_stillcold [] = "Witness is still cold\n"
 
static struct witness_order_list_entry order_lists []
 
static struct witness_blessed blessed_list []
 
static int witness_cold = 1
 
static int witness_spin_warn = 0
 

Macro Definition Documentation

◆ FULLGRAPH_SBUF_SIZE

#define FULLGRAPH_SBUF_SIZE   512

Definition at line 158 of file subr_witness.c.

◆ KTR_WITNESS

#define KTR_WITNESS   0

Definition at line 128 of file subr_witness.c.

◆ LI_EXCLUSIVE

#define LI_EXCLUSIVE   0x00010000 /* Exclusive lock instance. */

Definition at line 132 of file subr_witness.c.

◆ LI_NORELEASE

#define LI_NORELEASE   0x00020000 /* Lock not allowed to be released. */

Definition at line 133 of file subr_witness.c.

◆ LI_RECURSEMASK

#define LI_RECURSEMASK   0x0000ffff /* Recursion depth of lock instance. */

Definition at line 131 of file subr_witness.c.

◆ LI_SLEEPABLE

#define LI_SLEEPABLE   0x00040000 /* Lock may be held while sleeping. */

Definition at line 134 of file subr_witness.c.

◆ LOCK_CHILDCOUNT

#define LOCK_CHILDCOUNT   2048

Definition at line 154 of file subr_witness.c.

◆ LOCK_NCHILDREN

#define LOCK_NCHILDREN   5

Definition at line 153 of file subr_witness.c.

◆ MAX_W_NAME

#define MAX_W_NAME   64

Definition at line 156 of file subr_witness.c.

◆ WITNESS_ANCESTOR

#define WITNESS_ANCESTOR   0x02 /* Direct or indirect ancestor. */

Definition at line 166 of file subr_witness.c.

◆ WITNESS_ANCESTOR_MASK

#define WITNESS_ANCESTOR_MASK   (WITNESS_PARENT | WITNESS_ANCESTOR)

Definition at line 169 of file subr_witness.c.

◆ WITNESS_ATOD

#define WITNESS_ATOD (   x)    (((x) & WITNESS_RELATED_MASK) << 2)

Definition at line 182 of file subr_witness.c.

◆ WITNESS_CHILD

#define WITNESS_CHILD   0x04 /* Child, aka direct descendant. */

Definition at line 167 of file subr_witness.c.

◆ WITNESS_COUNT

#define WITNESS_COUNT   1536

Definition at line 137 of file subr_witness.c.

◆ WITNESS_DESCENDANT

#define WITNESS_DESCENDANT   0x08 /* Direct or indirect descendant. */

Definition at line 168 of file subr_witness.c.

◆ WITNESS_DESCENDANT_MASK

#define WITNESS_DESCENDANT_MASK   (WITNESS_CHILD | WITNESS_DESCENDANT)

Definition at line 170 of file subr_witness.c.

◆ WITNESS_DTOA

#define WITNESS_DTOA (   x)    (((x) & WITNESS_RELATED_MASK) >> 2)

Definition at line 179 of file subr_witness.c.

◆ WITNESS_HASH_SIZE

#define WITNESS_HASH_SIZE   251 /* Prime, gives load factor < 2 */

Definition at line 139 of file subr_witness.c.

◆ WITNESS_INDEX_ASSERT

#define WITNESS_INDEX_ASSERT (   i)     MPASS((i) > 0 && (i) <= w_max_used_index && (i) < witness_count)

Definition at line 184 of file subr_witness.c.

◆ WITNESS_LO_DATA_COUNT

#define WITNESS_LO_DATA_COUNT   2048

Definition at line 143 of file subr_witness.c.

◆ WITNESS_LO_HASH_SIZE

#define WITNESS_LO_HASH_SIZE   1021

Definition at line 146 of file subr_witness.c.

◆ WITNESS_LOCK_ORDER_KNOWN

#define WITNESS_LOCK_ORDER_KNOWN   0x80 /* This lock order is known. */

Definition at line 176 of file subr_witness.c.

◆ WITNESS_PARENT

#define WITNESS_PARENT   0x01 /* Parent, aka direct ancestor. */

Definition at line 165 of file subr_witness.c.

◆ WITNESS_PENDLIST

#define WITNESS_PENDLIST   (512 + (MAXCPU * 4))

Definition at line 140 of file subr_witness.c.

◆ WITNESS_RELATED_MASK

#define WITNESS_RELATED_MASK    (WITNESS_ANCESTOR_MASK | WITNESS_DESCENDANT_MASK)

Definition at line 171 of file subr_witness.c.

◆ WITNESS_RESERVED1

#define WITNESS_RESERVED1   0x20 /* Unused flag, reserved. */

Definition at line 174 of file subr_witness.c.

◆ WITNESS_RESERVED2

#define WITNESS_RESERVED2   0x40 /* Unused flag, reserved. */

Definition at line 175 of file subr_witness.c.

◆ WITNESS_REVERSAL

#define WITNESS_REVERSAL
Value:
0x10 /* A lock order reversal has been
* observed. */

Definition at line 173 of file subr_witness.c.

◆ WITNESS_UNRELATED

#define WITNESS_UNRELATED   0x00 /* No lock order relation. */

Definition at line 164 of file subr_witness.c.

Enumeration Type Documentation

◆ witness_channel

Enumerator
WITNESS_CONSOLE 
WITNESS_LOG 
WITNESS_NONE 

Definition at line 426 of file subr_witness.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ _isitmyx()

static int _isitmyx ( struct witness w1,
struct witness w2,
int  rmask,
const char *  fname 
)
static

Definition at line 2087 of file subr_witness.c.

References kdb_backtrace(), printf(), witness::w_index, w_mtx, witness::w_name, w_rmatrix, WITNESS_ATOD, WITNESS_DTOA, WITNESS_INDEX_ASSERT, WITNESS_RELATED_MASK, and witness_watch.

Referenced by isitmychild(), and isitmydescendant().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adopt()

static void adopt ( struct witness parent,
struct witness child 
)
static

◆ blessed()

static int blessed ( struct witness w1,
struct witness w2 
)
static

Definition at line 2139 of file subr_witness.c.

References witness_blessed::b_lock1, witness_blessed::b_lock2, blessed_list, and witness::w_name.

Referenced by sbuf_print_witness_badstacks(), and witness_checkorder().

Here is the caller graph for this function:

◆ depart()

static void depart ( struct witness w)
static

Definition at line 1945 of file subr_witness.c.

References witness::w_class, w_sleep_cnt, w_spin_cnt, and witness_increment_graph_generation().

Referenced by witness_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enroll()

static struct witness * enroll ( const char *  description,
struct lock_class *  lock_class 
)
static

Definition at line 1890 of file subr_witness.c.

References MAX_W_NAME, w_all, witness::w_class, w_mtx, witness::w_name, w_sleep, w_sleep_cnt, w_spin, w_spin_cnt, witness_get(), witness_hash_get(), witness_hash_put(), witness_increment_graph_generation(), witness_skipspin, and witness_watch.

Referenced by witness_init(), and witness_startup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FEATURE()

FEATURE ( witness  ,
"kernel has witness(9) support"   
)

◆ find_instance()

static struct lock_instance * find_instance ( struct lock_list_entry list,
const struct lock_object *  lock 
)
static

◆ fixup_filename()

static const char * fixup_filename ( const char *  file)
static

Definition at line 757 of file subr_witness.c.

Referenced by witness_assert(), witness_checkorder(), witness_downgrade(), witness_list_lock(), witness_unlock(), and witness_upgrade().

Here is the caller graph for this function:

◆ isitmychild()

static int isitmychild ( struct witness parent,
struct witness child 
)
static

Definition at line 2121 of file subr_witness.c.

References _isitmyx(), child, parent, and WITNESS_PARENT.

Referenced by adopt(), witness_checkorder(), and witness_lock_order_check().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isitmydescendant()

static int isitmydescendant ( struct witness parent,
struct witness child 
)
static

Definition at line 2131 of file subr_witness.c.

References _isitmyx(), and WITNESS_ANCESTOR_MASK.

Referenced by witness_checkorder(), and witness_defineorder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ itismychild()

static void itismychild ( struct witness parent,
struct witness child 
)
static

Definition at line 2056 of file subr_witness.c.

References adopt(), child, parent, w_mtx, witness_cold, and witness_lock_type_equal().

Referenced by witness_checkorder(), witness_defineorder(), and witness_startup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_WITNESS  ,
"Witness"  ,
"Witness"   
)
static

◆ sbuf_print_witness_badstacks()

static void sbuf_print_witness_badstacks ( struct sbuf *  sb,
size_t *  oldidx 
)
static

◆ STAILQ_HEAD()

STAILQ_HEAD ( witness_list  ,
witness   
)

◆ sysctl_debug_witness_badstacks()

static int sysctl_debug_witness_badstacks ( SYSCTL_HANDLER_ARGS  )
static

◆ sysctl_debug_witness_channel()

static int sysctl_debug_witness_channel ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 2798 of file subr_witness.c.

References buf, name, snprintf(), sysctl_handle_string(), WITNESS_CONSOLE, WITNESS_LOG, and WITNESS_NONE.

Here is the call graph for this function:

◆ sysctl_debug_witness_fullgraph()

static int sysctl_debug_witness_fullgraph ( SYSCTL_HANDLER_ARGS  )
static

◆ sysctl_debug_witness_watch()

static int sysctl_debug_witness_watch ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 2880 of file subr_witness.c.

References sysctl_handle_int(), value, and witness_watch.

Here is the call graph for this function:

◆ SYSCTL_INT() [1/5]

SYSCTL_INT ( _debug_witness  ,
OID_AUTO  ,
free_cnt  ,
CTLFLAG_RD  ,
w_free_cnt,
,
""   
)

◆ SYSCTL_INT() [2/5]

SYSCTL_INT ( _debug_witness  ,
OID_AUTO  ,
skipspin  ,
CTLFLAG_RDTUN  ,
witness_skipspin,
,
""   
)

◆ SYSCTL_INT() [3/5]

SYSCTL_INT ( _debug_witness  ,
OID_AUTO  ,
sleep_cnt  ,
CTLFLAG_RD  ,
w_sleep_cnt,
,
""   
)

◆ SYSCTL_INT() [4/5]

SYSCTL_INT ( _debug_witness  ,
OID_AUTO  ,
spin_cnt  ,
CTLFLAG_RD  ,
w_spin_cnt,
,
""   
)

◆ SYSCTL_INT() [5/5]

SYSCTL_INT ( _debug_witness  ,
OID_AUTO  ,
witness_count  ,
CTLFLAG_RDTUN  ,
witness_count,
,
""   
)

◆ SYSCTL_NODE()

static SYSCTL_NODE ( _debug  ,
OID_AUTO  ,
witness  ,
CTLFLAG_RW|  CTLFLAG_MPSAFE,
NULL  ,
"Witness Locking"   
)
static

◆ SYSCTL_PROC() [1/4]

SYSCTL_PROC ( _debug_witness  ,
OID_AUTO  ,
badstacks  ,
CTLTYPE_STRING|CTLFLAG_RD|  CTLFLAG_MPSAFE,
NULL  ,
,
sysctl_debug_witness_badstacks  ,
"A"  ,
"Show bad witness stacks"   
)

◆ SYSCTL_PROC() [2/4]

SYSCTL_PROC ( _debug_witness  ,
OID_AUTO  ,
fullgraph  ,
CTLTYPE_STRING|CTLFLAG_RD|  CTLFLAG_MPSAFE,
NULL  ,
,
sysctl_debug_witness_fullgraph  ,
"A"  ,
"Show locks relation graphs"   
)

◆ SYSCTL_PROC() [3/4]

SYSCTL_PROC ( _debug_witness  ,
OID_AUTO  ,
output_channel  ,
CTLTYPE_STRING|CTLFLAG_RWTUN|  CTLFLAG_MPSAFE,
NULL  ,
,
sysctl_debug_witness_channel  ,
"A"  ,
"Output channel for warnings"   
)

◆ SYSCTL_PROC() [4/4]

SYSCTL_PROC ( _debug_witness  ,
OID_AUTO  ,
watch  ,
CTLFLAG_RWTUN|CTLTYPE_INT|  CTLFLAG_MPSAFE,
NULL  ,
,
sysctl_debug_witness_watch  ,
"I"  ,
"witness is watching lock operations"   
)

◆ witness_add_fullgraph()

static void witness_add_fullgraph ( struct sbuf *  sb,
struct witness parent 
)
static

Definition at line 2896 of file subr_witness.c.

References sbuf_printf(), w_data, witness::w_index, w_max_used_index, witness::w_name, w_rmatrix, witness_add_fullgraph(), WITNESS_INDEX_ASSERT, and WITNESS_PARENT.

Referenced by sysctl_debug_witness_fullgraph(), and witness_add_fullgraph().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_assert()

void witness_assert ( const struct lock_object *  lock,
int  flags,
const char *  file,
int  line 
)

Definition at line 2426 of file subr_witness.c.

References find_instance(), fixup_filename(), flags, LI_EXCLUSIVE, lock_instance::li_flags, LI_RECURSEMASK, and witness_watch.

Here is the call graph for this function:

◆ witness_checkorder()

◆ witness_debugger()

static void witness_debugger ( int  cond,
const char *  msg 
)
static

Definition at line 3107 of file subr_witness.c.

References buf, sbuf_finish(), sbuf_new(), sbuf_set_drain(), st, stack_zero(), witness_enter_debugger(), witness_output(), and witness_output_drain().

Referenced by witness_checkorder(), and witness_warn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_defineorder()

int witness_defineorder ( struct lock_object *  lock1,
struct lock_object *  lock2 
)

Definition at line 1076 of file subr_witness.c.

References isitmydescendant(), itismychild(), KTR_WITNESS, w_mtx, and witness_watch.

Here is the call graph for this function:

◆ witness_destroy()

void witness_destroy ( struct lock_object *  lock)

Definition at line 917 of file subr_witness.c.

References depart(), panic(), w_mtx, and witness_cold.

Here is the call graph for this function:

◆ witness_display_spinlock()

void witness_display_spinlock ( struct lock_object *  lock,
struct thread *  owner,
int(*)(const char *fmt,...)  prnt 
)

Definition at line 2339 of file subr_witness.c.

References find_instance(), pcpu_find(), and witness_list_lock().

Referenced by _mtx_lock_indefinite_check().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_downgrade()

void witness_downgrade ( struct lock_object *  lock,
int  flags,
const char *  file,
int  line 
)

Definition at line 1608 of file subr_witness.c.

References find_instance(), fixup_filename(), LI_EXCLUSIVE, lock_instance::li_flags, LI_RECURSEMASK, witness_cold, and witness_watch.

Here is the call graph for this function:

◆ witness_enter_debugger()

static void witness_enter_debugger ( const char *  msg)
static

Definition at line 3132 of file subr_witness.c.

References kdb_enter().

Referenced by witness_checkorder(), and witness_debugger().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_file()

const char * witness_file ( struct lock_object *  lock)

Definition at line 1868 of file subr_witness.c.

References witness_cold.

◆ witness_free()

static void witness_free ( struct witness m)
static

Definition at line 2191 of file subr_witness.c.

References w_free, and w_free_cnt.

Referenced by witness_startup().

Here is the caller graph for this function:

◆ witness_get()

static struct witness * witness_get ( void  )
static

Definition at line 2159 of file subr_witness.c.

References printf(), w_free, w_free_cnt, witness::w_index, w_max_used_index, w_mtx, witness_cold, witness_count, and witness_watch.

Referenced by enroll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_hash_djb2()

static uint32_t witness_hash_djb2 ( const uint8_t *  key,
uint32_t  size 
)
static

Definition at line 2921 of file subr_witness.c.

Referenced by witness_hash_get(), witness_hash_put(), witness_lock_order_add(), and witness_lock_order_get().

Here is the caller graph for this function:

◆ witness_hash_get()

static struct witness * witness_hash_get ( const char *  key)
static

Definition at line 2969 of file subr_witness.c.

References w_hash, w_mtx, witness::w_name, witness_hash::wh_array, witness_hash::wh_size, witness_cold, and witness_hash_djb2().

Referenced by enroll(), and witness_hash_put().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_hash_put()

static void witness_hash_put ( struct witness w)
static

Definition at line 2990 of file subr_witness.c.

References w_hash, w_mtx, witness::w_name, witness_hash::wh_array, witness_hash::wh_count, witness_hash::wh_size, witness_cold, witness_hash_djb2(), and witness_hash_get().

Referenced by enroll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_increment_graph_generation()

static void witness_increment_graph_generation ( void  )
static

Definition at line 3090 of file subr_witness.c.

References w_generation, w_mtx, and witness_cold.

Referenced by adopt(), depart(), enroll(), and witness_checkorder().

Here is the caller graph for this function:

◆ witness_init()

void witness_init ( struct lock_object *  lock,
const char *  type 
)

Definition at line 876 of file subr_witness.c.

References enroll(), panic(), pending_cnt, pending_locks, type, witness_pendhelp::wh_lock, witness_pendhelp::wh_type, witness_cold, WITNESS_PENDLIST, and witness_watch.

Here is the call graph for this function:

◆ witness_init_hash_tables()

◆ witness_line()

int witness_line ( struct lock_object *  lock)

Definition at line 1879 of file subr_witness.c.

References witness_cold.

◆ witness_list_lock()

static void witness_list_lock ( struct lock_instance instance,
int(*)(const char *fmt,...)  prnt 
)
static

Definition at line 2246 of file subr_witness.c.

References fixup_filename(), LI_EXCLUSIVE, lock_instance::li_file, lock_instance::li_flags, lock_instance::li_line, lock_instance::li_lock, and LI_RECURSEMASK.

Referenced by witness_display_spinlock(), witness_list_locks(), witness_thread_exit(), and witness_warn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_list_locks()

int witness_list_locks ( struct lock_list_entry **  lock_list,
int(*)(const char *fmt,...)  prnt 
)

Definition at line 2316 of file subr_witness.c.

References lock_list_entry::ll_children, lock_list_entry::ll_count, lock_list_entry::ll_next, and witness_list_lock().

Referenced by witness_warn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_lock()

void witness_lock ( struct lock_object *  lock,
int  flags,
const char *  file,
int  line 
)

◆ witness_lock_list_free()

static void witness_lock_list_free ( struct lock_list_entry lle)
static

Definition at line 2220 of file subr_witness.c.

References lock_list_entry::ll_next, w_lock_list_free, and w_mtx.

Referenced by witness_startup(), witness_thread_exit(), and witness_unlock().

Here is the caller graph for this function:

◆ witness_lock_list_get()

static struct lock_list_entry * witness_lock_list_get ( void  )
static

Definition at line 2199 of file subr_witness.c.

References lock_list_entry::ll_next, printf(), w_lock_list_free, w_mtx, and witness_watch.

Referenced by witness_lock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_lock_order_add()

static int witness_lock_order_add ( struct witness parent,
struct witness child 
)
static

◆ witness_lock_order_check()

static int witness_lock_order_check ( struct witness parent,
struct witness child 
)
static

Definition at line 3044 of file subr_witness.c.

References child, isitmychild(), parent, w_rmatrix, and WITNESS_LOCK_ORDER_KNOWN.

Referenced by witness_checkorder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_lock_order_get()

static struct witness_lock_order_data * witness_lock_order_get ( struct witness parent,
struct witness child 
)
static

◆ witness_lock_order_key_equal()

static __inline int witness_lock_order_key_equal ( const struct witness_lock_order_key a,
const struct witness_lock_order_key b 
)
static

Definition at line 306 of file subr_witness.c.

References witness_lock_order_key::from, and witness_lock_order_key::to.

Referenced by witness_lock_order_get().

Here is the caller graph for this function:

◆ witness_lock_type_equal()

static __inline int witness_lock_type_equal ( struct witness w1,
struct witness w2 
)
static

Definition at line 298 of file subr_witness.c.

References witness::w_class.

Referenced by itismychild().

Here is the caller graph for this function:

◆ witness_norelease()

void witness_norelease ( struct lock_object *  lock)

Definition at line 2528 of file subr_witness.c.

References LI_NORELEASE, and witness_setflag().

Here is the call graph for this function:

◆ witness_output()

static int witness_output ( const char *  fmt,
  ... 
)
static

Definition at line 2262 of file subr_witness.c.

References witness_voutput().

Referenced by witness_checkorder(), witness_debugger(), witness_output_drain(), witness_thread_exit(), and witness_unlock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_output_drain()

static int witness_output_drain ( void *arg  __unused,
const char *  data,
int  len 
)
static

Definition at line 3099 of file subr_witness.c.

References data, and witness_output().

Referenced by witness_checkorder(), and witness_debugger().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_releaseok()

void witness_releaseok ( struct lock_object *  lock)

Definition at line 2535 of file subr_witness.c.

References LI_NORELEASE, and witness_setflag().

Here is the call graph for this function:

◆ witness_restore()

void witness_restore ( struct lock_object *  lock,
const char *  file,
int  line 
)

Definition at line 2389 of file subr_witness.c.

References find_instance(), lock_instance::li_file, lock_instance::li_line, witness_cold, witness_skipspin, and witness_watch.

Here is the call graph for this function:

◆ witness_save()

void witness_save ( struct lock_object *  lock,
const char **  filep,
int *  linep 
)

Definition at line 2354 of file subr_witness.c.

References find_instance(), lock_instance::li_file, lock_instance::li_line, witness_cold, witness_skipspin, and witness_watch.

Here is the call graph for this function:

◆ witness_setflag()

static void witness_setflag ( struct lock_object *  lock,
int  flag,
int  set 
)
static

Definition at line 2498 of file subr_witness.c.

References find_instance(), flag, lock_instance::li_flags, set, witness_skipspin, and witness_watch.

Referenced by witness_norelease(), and witness_releaseok().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_startup()

◆ witness_startup_count()

int witness_startup_count ( void  )

Definition at line 771 of file subr_witness.c.

References w_rmatrix, and witness_count.

◆ witness_thread_exit()

void witness_thread_exit ( struct thread *  td)

Definition at line 1763 of file subr_witness.c.

References lock_list_entry::ll_children, lock_list_entry::ll_count, lock_list_entry::ll_next, witness_list_lock(), witness_lock_list_free(), and witness_output().

Referenced by thread_exit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_unlock()

void witness_unlock ( struct lock_object *  lock,
int  flags,
const char *  file,
int  line 
)

◆ witness_upgrade()

void witness_upgrade ( struct lock_object *  lock,
int  flags,
const char *  file,
int  line 
)

Definition at line 1563 of file subr_witness.c.

References find_instance(), fixup_filename(), LI_EXCLUSIVE, lock_instance::li_flags, LI_RECURSEMASK, witness_cold, and witness_watch.

Here is the call graph for this function:

◆ witness_voutput()

static int witness_voutput ( const char *  fmt,
va_list  ap 
)
static

Definition at line 2274 of file subr_witness.c.

References vlog(), vprintf(), WITNESS_CONSOLE, WITNESS_LOG, and WITNESS_NONE.

Referenced by witness_output().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witness_warn()

int witness_warn ( int  flags,
struct lock_object *  lock,
const char *  fmt,
  ... 
)

Variable Documentation

◆ badstack_sbuf_size

int badstack_sbuf_size

Definition at line 417 of file subr_witness.c.

Referenced by sysctl_debug_witness_badstacks(), and witness_startup().

◆ blessed_list

struct witness_blessed blessed_list[]
static
Initial value:
= {
{ "dirhash", "bufwait" },
{ "ufs", "bufwait" },
}

Definition at line 729 of file subr_witness.c.

Referenced by blessed().

◆ order_lists

struct witness_order_list_entry order_lists[]
static

Definition at line 492 of file subr_witness.c.

Referenced by witness_startup().

◆ pending_cnt

u_int pending_cnt
static

Definition at line 467 of file subr_witness.c.

Referenced by witness_init().

◆ pending_locks

struct witness_pendhelp pending_locks[WITNESS_PENDLIST]
static

Definition at line 466 of file subr_witness.c.

Referenced by witness_init(), and witness_startup().

◆ w_all

struct witness_list w_all = STAILQ_HEAD_INITIALIZER(w_all)
static

Definition at line 458 of file subr_witness.c.

Referenced by enroll(), and sysctl_debug_witness_fullgraph().

◆ w_data

struct witness* w_data
static

◆ w_free

struct witness_list w_free = STAILQ_HEAD_INITIALIZER(w_free)
static

Definition at line 457 of file subr_witness.c.

Referenced by witness_free(), witness_get(), and witness_startup().

◆ w_free_cnt

int w_free_cnt
static

Definition at line 469 of file subr_witness.c.

Referenced by witness_free(), witness_get(), and witness_startup().

◆ w_generation

unsigned int w_generation = 0
static

◆ w_hash

struct witness_hash w_hash
static

Definition at line 478 of file subr_witness.c.

Referenced by witness_hash_get(), witness_hash_put(), and witness_init_hash_tables().

◆ w_lock_list_free

struct lock_list_entry* w_lock_list_free = NULL
static

Definition at line 465 of file subr_witness.c.

Referenced by witness_lock_list_free(), and witness_lock_list_get().

◆ w_locklistdata

struct lock_list_entry w_locklistdata[LOCK_CHILDCOUNT]
static

Definition at line 477 of file subr_witness.c.

Referenced by witness_startup().

◆ w_lodata

Definition at line 481 of file subr_witness.c.

Referenced by witness_init_hash_tables().

◆ w_lofree

struct witness_lock_order_data* w_lofree = NULL
static

Definition at line 482 of file subr_witness.c.

Referenced by witness_init_hash_tables(), and witness_lock_order_add().

◆ w_lohash

◆ w_max_used_index

int w_max_used_index = 0
static

◆ w_mtx

◆ w_notrunning

const char w_notrunning[] = "Witness not running\n"
static

◆ w_rmatrix

◆ w_sleep

struct witness_list w_sleep = STAILQ_HEAD_INITIALIZER(w_sleep)
static

Definition at line 462 of file subr_witness.c.

Referenced by enroll().

◆ w_sleep_cnt

int w_sleep_cnt
static

Definition at line 469 of file subr_witness.c.

Referenced by depart(), and enroll().

◆ w_spin

struct witness_list w_spin = STAILQ_HEAD_INITIALIZER(w_spin)
static

Definition at line 461 of file subr_witness.c.

Referenced by enroll().

◆ w_spin_cnt

int w_spin_cnt
static

Definition at line 469 of file subr_witness.c.

Referenced by depart(), and enroll().

◆ w_stillcold

const char w_stillcold[] = "Witness is still cold\n"
static

◆ witness_channel

Definition at line 432 of file subr_witness.c.

◆ witness_cold

◆ witness_count

int witness_count = WITNESS_COUNT

Definition at line 419 of file subr_witness.c.

Referenced by witness_get(), witness_startup(), and witness_startup_count().

◆ witness_skipspin

int witness_skipspin = 0

Definition at line 413 of file subr_witness.c.

Referenced by enroll(), witness_restore(), witness_save(), and witness_setflag().

◆ witness_spin_warn

int witness_spin_warn = 0
static

Definition at line 753 of file subr_witness.c.

Referenced by witness_startup().

◆ witness_watch