FreeBSD kernel kern code
kern_lock.c File Reference
#include "opt_adaptive_lockmgrs.h"
#include "opt_ddb.h"
#include "opt_hwpmc_hooks.h"
#include "opt_kdtrace.h"
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/kdb.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/lock_profile.h>
#include <sys/lockmgr.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/sleepqueue.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <machine/cpu.h>
Include dependency graph for kern_lock.c:

Go to the source code of this file.

Macros

#define SQ_EXCLUSIVE_QUEUE   0
 
#define SQ_SHARED_QUEUE   1
 
#define _lockmgr_assert(lk, what, file, line)
 
#define TD_LOCKS_INC(td)
 
#define TD_LOCKS_DEC(td)
 
#define TD_SLOCKS_INC(td)   ((td)->td_lk_slocks++)
 
#define TD_SLOCKS_DEC(td)   ((td)->td_lk_slocks--)
 
#define STACK_PRINT(lk)
 
#define STACK_SAVE(lk)
 
#define STACK_ZERO(lk)
 
#define LOCK_LOG2(lk, string, arg1, arg2)
 
#define LOCK_LOG3(lk, string, arg1, arg2, arg3)
 
#define GIANT_DECLARE
 
#define GIANT_RESTORE()
 
#define GIANT_SAVE()
 
#define LK_CAN_SHARE(x)
 
#define LK_TRYOP(x)   ((x) & LK_NOWAIT)
 
#define LK_CAN_WITNESS(x)   (((x) & LK_NOWITNESS) == 0 && !LK_TRYOP(x))
 
#define LK_TRYWIT(x)   (LK_TRYOP(x) ? LOP_TRYLOCK : 0)
 
#define LK_CAN_ADAPT(lk, f)
 
#define lockmgr_disowned(lk)   (((lk)->lk_lock & ~(LK_FLAGMASK & ~LK_SHARE)) == LK_KERNPROC)
 
#define lockmgr_xlocked(lk)   (((lk)->lk_lock & ~(LK_FLAGMASK & ~LK_SHARE)) == (uintptr_t)curthread)
 

Functions

 __FBSDID ("$BSDSUniX$")
 
 CTASSERT (((LK_ADAPTIVE|LK_NOSHARE)&LO_CLASSFLAGS)==(LK_ADAPTIVE|LK_NOSHARE))
 
 CTASSERT (LK_UNLOCKED==(LK_UNLOCKED & ~(LK_ALL_WAITERS|LK_EXCLUSIVE_SPINNERS)))
 
static void assert_lockmgr (struct lock_object *lock, int how)
 
static void lock_lockmgr (struct lock_object *lock, int how)
 
static int unlock_lockmgr (struct lock_object *lock)
 
static __inline struct thread * lockmgr_xholder (struct lock *lk)
 
static __inline int sleeplk (struct lock *lk, u_int flags, struct lock_object *ilk, const char *wmesg, int pri, int timo, int queue)
 
static __inline int wakeupshlk (struct lock *lk, const char *file, int line)
 
void lockinit (struct lock *lk, int pri, const char *wmesg, int timo, int flags)
 
void lockallowshare (struct lock *lk)
 
void lockallowrecurse (struct lock *lk)
 
void lockdisablerecurse (struct lock *lk)
 
void lockdestroy (struct lock *lk)
 
int __lockmgr_args (struct lock *lk, u_int flags, struct lock_object *ilk, const char *wmesg, int pri, int timo, const char *file, int line)
 
void _lockmgr_disown (struct lock *lk, const char *file, int line)
 
void lockmgr_printinfo (struct lock *lk)
 
int lockstatus (struct lock *lk)
 

Variables

struct lock_class lock_class_lockmgr
 

Macro Definition Documentation

#define _lockmgr_assert (   lk,
  what,
  file,
  line 
)

Definition at line 77 of file kern_lock.c.

Referenced by __lockmgr_args(), and _lockmgr_disown().

#define GIANT_DECLARE
Value:
int _i = 0; \
WITNESS_SAVE_DECL(Giant)
struct mtx Giant
Definition: kern_mutex.c:140

Definition at line 104 of file kern_lock.c.

Referenced by __lockmgr_args(), and sleeplk().

#define GIANT_RESTORE ( )
Value:
do { \
if (_i > 0) { \
while (_i--) \
mtx_lock(&Giant); \
WITNESS_RESTORE(&Giant.lock_object, Giant); \
} \
} while (0)
struct mtx Giant
Definition: kern_mutex.c:140

Definition at line 107 of file kern_lock.c.

Referenced by __lockmgr_args(), and sleeplk().

#define GIANT_SAVE ( )
Value:
do { \
if (mtx_owned(&Giant)) { \
WITNESS_SAVE(&Giant.lock_object, Giant); \
while (mtx_owned(&Giant)) { \
_i++; \
mtx_unlock(&Giant); \
} \
} \
} while (0)
struct mtx Giant
Definition: kern_mutex.c:140

Definition at line 114 of file kern_lock.c.

Referenced by __lockmgr_args(), and sleeplk().

#define LK_CAN_ADAPT (   lk,
 
)
Value:
(((lk)->lock_object.lo_flags & LK_ADAPTIVE) != 0 && \
((f) & LK_SLEEPFAIL) == 0)

Definition at line 136 of file kern_lock.c.

Referenced by __lockmgr_args().

#define LK_CAN_SHARE (   x)
Value:
(((x) & LK_SHARE) && (((x) & LK_EXCLUSIVE_WAITERS) == 0 || \
((x) & LK_EXCLUSIVE_SPINNERS) == 0 || \
curthread->td_lk_slocks || (curthread->td_pflags & TDP_DEADLKTREAT)))

Definition at line 124 of file kern_lock.c.

Referenced by __lockmgr_args().

#define LK_CAN_WITNESS (   x)    (((x) & LK_NOWITNESS) == 0 && !LK_TRYOP(x))

Definition at line 131 of file kern_lock.c.

Referenced by __lockmgr_args().

#define LK_TRYOP (   x)    ((x) & LK_NOWAIT)

Definition at line 128 of file kern_lock.c.

Referenced by __lockmgr_args().

#define LK_TRYWIT (   x)    (LK_TRYOP(x) ? LOP_TRYLOCK : 0)

Definition at line 133 of file kern_lock.c.

Referenced by __lockmgr_args().

#define LOCK_LOG2 (   lk,
  string,
  arg1,
  arg2 
)
Value:
if (LOCK_LOG_TEST(&(lk)->lock_object, 0)) \
CTR2(KTR_LOCK, (string), (arg1), (arg2))

Definition at line 97 of file kern_lock.c.

Referenced by __lockmgr_args(), and wakeupshlk().

#define LOCK_LOG3 (   lk,
  string,
  arg1,
  arg2,
  arg3 
)
Value:
if (LOCK_LOG_TEST(&(lk)->lock_object, 0)) \
CTR3(KTR_LOCK, (string), (arg1), (arg2), (arg3))

Definition at line 100 of file kern_lock.c.

Referenced by __lockmgr_args(), sleeplk(), and wakeupshlk().

#define lockmgr_disowned (   lk)    (((lk)->lk_lock & ~(LK_FLAGMASK & ~LK_SHARE)) == LK_KERNPROC)

Definition at line 140 of file kern_lock.c.

#define lockmgr_xlocked (   lk)    (((lk)->lk_lock & ~(LK_FLAGMASK & ~LK_SHARE)) == (uintptr_t)curthread)

Definition at line 143 of file kern_lock.c.

Referenced by __lockmgr_args().

#define SQ_EXCLUSIVE_QUEUE   0

Definition at line 68 of file kern_lock.c.

Referenced by __lockmgr_args(), sleeplk(), and wakeupshlk().

#define SQ_SHARED_QUEUE   1

Definition at line 69 of file kern_lock.c.

Referenced by __lockmgr_args(), and wakeupshlk().

#define STACK_PRINT (   lk)

Definition at line 88 of file kern_lock.c.

Referenced by lockmgr_printinfo().

#define STACK_SAVE (   lk)

Definition at line 89 of file kern_lock.c.

Referenced by __lockmgr_args(), and _lockmgr_disown().

#define STACK_ZERO (   lk)

Definition at line 90 of file kern_lock.c.

Referenced by lockinit().

#define TD_LOCKS_DEC (   td)

Definition at line 79 of file kern_lock.c.

Referenced by __lockmgr_args(), _lockmgr_disown(), and wakeupshlk().

#define TD_LOCKS_INC (   td)

Definition at line 78 of file kern_lock.c.

Referenced by __lockmgr_args().

#define TD_SLOCKS_DEC (   td)    ((td)->td_lk_slocks--)

Definition at line 85 of file kern_lock.c.

Referenced by __lockmgr_args(), and wakeupshlk().

#define TD_SLOCKS_INC (   td)    ((td)->td_lk_slocks++)

Definition at line 84 of file kern_lock.c.

Referenced by __lockmgr_args().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
int __lockmgr_args ( struct lock *  lk,
u_int  flags,
struct lock_object *  ilk,
const char *  wmesg,
int  pri,
int  timo,
const char *  file,
int  line 
)
void _lockmgr_disown ( struct lock *  lk,
const char *  file,
int  line 
)

Definition at line 1260 of file kern_lock.c.

References _lockmgr_assert, STACK_SAVE, and TD_LOCKS_DEC.

static void assert_lockmgr ( struct lock_object *  lock,
int  how 
)
static

Definition at line 341 of file kern_lock.c.

References panic().

Here is the call graph for this function:

CTASSERT ( ((LK_ADAPTIVE|LK_NOSHARE)&LO_CLASSFLAGS)  = =(LK_ADAPTIVE|LK_NOSHARE))
CTASSERT ( LK_UNLOCKED  = =(LK_UNLOCKED &       ~(LK_ALL_WAITERS|LK_EXCLUSIVE_SPINNERS)))
static void lock_lockmgr ( struct lock_object *  lock,
int  how 
)
static

Definition at line 348 of file kern_lock.c.

References panic().

Here is the call graph for this function:

void lockallowrecurse ( struct lock *  lk)

Definition at line 415 of file kern_lock.c.

void lockallowshare ( struct lock *  lk)

Definition at line 407 of file kern_lock.c.

void lockdestroy ( struct lock *  lk)

Definition at line 431 of file kern_lock.c.

References lock_destroy().

Referenced by mount_fini(), and vdropl().

Here is the call graph for this function:

Here is the caller graph for this function:

void lockdisablerecurse ( struct lock *  lk)

Definition at line 423 of file kern_lock.c.

void lockinit ( struct lock *  lk,
int  pri,
const char *  wmesg,
int  timo,
int  flags 
)

Definition at line 371 of file kern_lock.c.

References lock_init(), and STACK_ZERO.

Referenced by getnewvnode(), and mount_init().

Here is the call graph for this function:

Here is the caller graph for this function:

void lockmgr_printinfo ( struct lock *  lk)

Definition at line 1296 of file kern_lock.c.

References lockmgr_xholder(), printf(), and STACK_PRINT.

Referenced by vn_printf().

Here is the call graph for this function:

Here is the caller graph for this function:

static __inline struct thread* lockmgr_xholder ( struct lock *  lk)
static

Definition at line 171 of file kern_lock.c.

Referenced by lockmgr_printinfo().

Here is the caller graph for this function:

int lockstatus ( struct lock *  lk)

Definition at line 1325 of file kern_lock.c.

Referenced by vop_stdislocked().

Here is the caller graph for this function:

static __inline int sleeplk ( struct lock *  lk,
u_int  flags,
struct lock_object *  ilk,
const char *  wmesg,
int  pri,
int  timo,
int  queue 
)
static

Definition at line 186 of file kern_lock.c.

References GIANT_DECLARE, GIANT_RESTORE, GIANT_SAVE, LOCK_LOG3, sleepq_add(), sleepq_set_timeout(), sleepq_timedwait(), sleepq_timedwait_sig(), sleepq_wait(), sleepq_wait_sig(), and SQ_EXCLUSIVE_QUEUE.

Referenced by __lockmgr_args().

Here is the call graph for this function:

Here is the caller graph for this function:

static int unlock_lockmgr ( struct lock_object *  lock)
static

Definition at line 355 of file kern_lock.c.

References panic().

Here is the call graph for this function:

static __inline int wakeupshlk ( struct lock *  lk,
const char *  file,
int  line 
)
static

Definition at line 230 of file kern_lock.c.

References LOCK_LOG2, LOCK_LOG3, sleepq_broadcast(), sleepq_lock(), sleepq_release(), sleepq_sleepcnt(), SQ_EXCLUSIVE_QUEUE, SQ_SHARED_QUEUE, TD_LOCKS_DEC, and TD_SLOCKS_DEC.

Referenced by __lockmgr_args().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

struct lock_class lock_class_lockmgr
Initial value:
= {
.lc_name = "lockmgr",
.lc_flags = LC_RECURSABLE | LC_SLEEPABLE | LC_SLEEPLOCK | LC_UPGRADABLE,
.lc_assert = assert_lockmgr,
.lc_lock = lock_lockmgr,
.lc_unlock = unlock_lockmgr,
}
static int unlock_lockmgr(struct lock_object *lock)
Definition: kern_lock.c:355
static void lock_lockmgr(struct lock_object *lock, int how)
Definition: kern_lock.c:348
static void assert_lockmgr(struct lock_object *lock, int how)
Definition: kern_lock.c:341

Definition at line 156 of file kern_lock.c.