FreeBSD kernel kern code
kern_mutex.c File Reference
#include <sys/cdefs.h>
#include "opt_adaptive_mutexes.h"
#include "opt_ddb.h"
#include "opt_hwpmc_hooks.h"
#include "opt_sched.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/conf.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/proc.h>
#include <sys/resourcevar.h>
#include <sys/sched.h>
#include <sys/sbuf.h>
#include <sys/smp.h>
#include <sys/sysctl.h>
#include <sys/turnstile.h>
#include <sys/vmmeter.h>
#include <sys/lock_profile.h>
#include <machine/atomic.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <ddb/ddb.h>
#include <fs/devfs/devfs_int.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>
Include dependency graph for kern_mutex.c:

Go to the source code of this file.

Macros

#define mtxlock2mtx(c)   (__containerof(c, struct mtx, mtx_lock))
 
#define mtx_unowned(m)   ((m)->mtx_lock == MTX_UNOWNED)
 
#define mtx_destroyed(m)   ((m)->mtx_lock == MTX_DESTROYED)
 
#define mtx_spin_delay   locks_delay
 
#define thread_lock_validate(m, opts, file, line)   do { } while (0)
 

Functions

 __FBSDID ("$FreeBSD$")
 
static void assert_mtx (const struct lock_object *lock, int what)
 
static void lock_mtx (struct lock_object *lock, uintptr_t how)
 
static void lock_spin (struct lock_object *lock, uintptr_t how)
 
static uintptr_t unlock_mtx (struct lock_object *lock)
 
static uintptr_t unlock_spin (struct lock_object *lock)
 
static void _mtx_lock_indefinite_check (struct mtx *, struct lock_delay_arg *)
 
void __mtx_lock_flags (volatile uintptr_t *c, int opts, const char *file, int line)
 
void __mtx_unlock_flags (volatile uintptr_t *c, int opts, const char *file, int line)
 
void __mtx_lock_spin_flags (volatile uintptr_t *c, int opts, const char *file, int line)
 
int __mtx_trylock_spin_flags (volatile uintptr_t *c, int opts, const char *file, int line)
 
void __mtx_unlock_spin_flags (volatile uintptr_t *c, int opts, const char *file, int line)
 
int _mtx_trylock_flags_int (struct mtx *m, int opts LOCK_FILE_LINE_ARG_DEF)
 
int _mtx_trylock_flags_ (volatile uintptr_t *c, int opts, const char *file, int line)
 
void __mtx_lock_sleep (volatile uintptr_t *c, uintptr_t v)
 
void _thread_lock (struct thread *td)
 
void thread_lock_flags_ (struct thread *td, int opts, const char *file, int line)
 
struct mtxthread_lock_block (struct thread *td)
 
void thread_lock_unblock (struct thread *td, struct mtx *new)
 
void thread_lock_block_wait (struct thread *td)
 
void thread_lock_set (struct thread *td, struct mtx *new)
 
void __mtx_unlock_sleep (volatile uintptr_t *c, uintptr_t v)
 
void mtx_sysinit (void *arg)
 
void _mtx_init (volatile uintptr_t *c, const char *name, const char *type, int opts)
 
void _mtx_destroy (volatile uintptr_t *c)
 
void mutex_init (void)
 
void mtx_spin_wait_unlocked (struct mtx *m)
 
void mtx_wait_unlocked (struct mtx *m)
 

Variables

struct lock_class lock_class_mtx_sleep
 
struct lock_class lock_class_mtx_spin
 
struct mtx blocked_lock
 
struct mtx __exclusive_cache_line Giant
 

Macro Definition Documentation

◆ mtx_destroyed

#define mtx_destroyed (   m)    ((m)->mtx_lock == MTX_DESTROYED)

Definition at line 97 of file kern_mutex.c.

◆ mtx_spin_delay

#define mtx_spin_delay   locks_delay

Definition at line 174 of file kern_mutex.c.

◆ mtx_unowned

#define mtx_unowned (   m)    ((m)->mtx_lock == MTX_UNOWNED)

Definition at line 95 of file kern_mutex.c.

◆ mtxlock2mtx

#define mtxlock2mtx (   c)    (__containerof(c, struct mtx, mtx_lock))

Definition at line 90 of file kern_mutex.c.

◆ thread_lock_validate

#define thread_lock_validate (   m,
  opts,
  file,
  line 
)    do { } while (0)

Definition at line 821 of file kern_mutex.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ __mtx_lock_flags()

void __mtx_lock_flags ( volatile uintptr_t *  c,
int  opts,
const char *  file,
int  line 
)

Definition at line 262 of file kern_mutex.c.

References kdb_active, lock_class_mtx_sleep, mtx, and mtxlock2mtx.

◆ __mtx_lock_sleep()

void __mtx_lock_sleep ( volatile uintptr_t *  c,
uintptr_t  v 
)

Definition at line 497 of file kern_mutex.c.

References lock_delay(), lockstat_nsecs(), mtx, mtxlock2mtx, sched_tdname(), ts, turnstile_cancel(), turnstile_trywait(), and turnstile_wait().

Here is the call graph for this function:

◆ __mtx_lock_spin_flags()

void __mtx_lock_spin_flags ( volatile uintptr_t *  c,
int  opts,
const char *  file,
int  line 
)

Definition at line 321 of file kern_mutex.c.

References lock_class_mtx_spin, mtx, and mtxlock2mtx.

◆ __mtx_trylock_spin_flags()

int __mtx_trylock_spin_flags ( volatile uintptr_t *  c,
int  opts,
const char *  file,
int  line 
)

Definition at line 362 of file kern_mutex.c.

References lock_class_mtx_spin, mtx, and mtxlock2mtx.

◆ __mtx_unlock_flags()

void __mtx_unlock_flags ( volatile uintptr_t *  c,
int  opts,
const char *  file,
int  line 
)

Definition at line 296 of file kern_mutex.c.

References __mtx_unlock_sleep(), lock_class_mtx_sleep, mtx, and mtxlock2mtx.

Here is the call graph for this function:

◆ __mtx_unlock_sleep()

void __mtx_unlock_sleep ( volatile uintptr_t *  c,
uintptr_t  v 
)

Definition at line 1020 of file kern_mutex.c.

References mtx, mtxlock2mtx, ts, turnstile_broadcast(), turnstile_chain_lock(), turnstile_chain_unlock(), turnstile_lookup(), and turnstile_unpend().

Referenced by __mtx_unlock_flags().

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

◆ __mtx_unlock_spin_flags()

void __mtx_unlock_spin_flags ( volatile uintptr_t *  c,
int  opts,
const char *  file,
int  line 
)

Definition at line 390 of file kern_mutex.c.

References lock_class_mtx_spin, mtx, and mtxlock2mtx.

◆ _mtx_destroy()

void _mtx_destroy ( volatile uintptr_t *  c)

Definition at line 1180 of file kern_mutex.c.

References lock_class_mtx_spin, lock_destroy(), mtx, mtx_unowned, and mtxlock2mtx.

Here is the call graph for this function:

◆ _mtx_init()

void _mtx_init ( volatile uintptr_t *  c,
const char *  name,
const char *  type,
int  opts 
)

Definition at line 1133 of file kern_mutex.c.

References flags, lock_class_mtx_sleep, lock_class_mtx_spin, lock_init(), mtx, mtxlock2mtx, name, and type.

Here is the call graph for this function:

◆ _mtx_lock_indefinite_check()

static void __noinline _mtx_lock_indefinite_check ( struct mtx m,
struct lock_delay_arg *  ldap 
)
static

Definition at line 1237 of file kern_mutex.c.

References kdb_active, panic(), printf(), and witness_display_spinlock().

Referenced by mtx_spin_wait_unlocked(), and thread_lock_flags_().

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

◆ _mtx_trylock_flags_()

int _mtx_trylock_flags_ ( volatile uintptr_t *  c,
int  opts,
const char *  file,
int  line 
)

Definition at line 477 of file kern_mutex.c.

References _mtx_trylock_flags_int(), mtx, and mtxlock2mtx.

Here is the call graph for this function:

◆ _mtx_trylock_flags_int()

int _mtx_trylock_flags_int ( struct mtx m,
int opts  LOCK_FILE_LINE_ARG_DEF 
)

Definition at line 416 of file kern_mutex.c.

References kdb_active, and lock_class_mtx_sleep.

Referenced by _mtx_trylock_flags_().

Here is the caller graph for this function:

◆ _thread_lock()

void _thread_lock ( struct thread *  td)

Definition at line 830 of file kern_mutex.c.

References blocked_lock, mtx, thread_lock_flags_(), and thread_lock_validate.

Here is the call graph for this function:

◆ assert_mtx()

void assert_mtx ( const struct lock_object *  lock,
int  what 
)
static

Definition at line 186 of file kern_mutex.c.

References mtx.

◆ lock_mtx()

void lock_mtx ( struct lock_object *  lock,
uintptr_t  how 
)
static

Definition at line 208 of file kern_mutex.c.

References mtx.

◆ lock_spin()

void lock_spin ( struct lock_object *  lock,
uintptr_t  how 
)
static

Definition at line 215 of file kern_mutex.c.

References mtx.

◆ mtx_spin_wait_unlocked()

void mtx_spin_wait_unlocked ( struct mtx m)

Definition at line 1262 of file kern_mutex.c.

References _mtx_lock_indefinite_check(), and lock_class_mtx_spin.

Referenced by proc_reap().

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

◆ mtx_sysinit()

void mtx_sysinit ( void *  arg)

Definition at line 1118 of file kern_mutex.c.

References mtx.

◆ mtx_wait_unlocked()

void mtx_wait_unlocked ( struct mtx m)

Definition at line 1287 of file kern_mutex.c.

References lock_class_mtx_sleep.

Referenced by cache_purge_vgone().

Here is the caller graph for this function:

◆ mutex_init()

void mutex_init ( void  )

Definition at line 1215 of file kern_mutex.c.

References blocked_lock, devmtx, Giant, init_turnstiles(), and proc0.

Here is the call graph for this function:

◆ thread_lock_block()

struct mtx * thread_lock_block ( struct thread *  td)

Definition at line 963 of file kern_mutex.c.

References blocked_lock, and mtx.

Referenced by sched_switch(), and sched_throw().

Here is the caller graph for this function:

◆ thread_lock_block_wait()

void thread_lock_block_wait ( struct thread *  td)

Definition at line 986 of file kern_mutex.c.

References blocked_lock.

Referenced by callout_process(), propagate_priority(), sleepq_resume_thread(), and turnstile_unpend().

Here is the caller graph for this function:

◆ thread_lock_flags_()

void thread_lock_flags_ ( struct thread *  td,
int  opts,
const char *  file,
int  line 
)

Definition at line 864 of file kern_mutex.c.

References _mtx_lock_indefinite_check(), lock_delay(), lockstat_enabled, lockstat_nsecs(), mtx, mtx_spin_delay, and thread_lock_validate.

Referenced by _thread_lock().

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

◆ thread_lock_set()

void thread_lock_set ( struct thread *  td,
struct mtx new 
)

Definition at line 997 of file kern_mutex.c.

References mtx.

Referenced by sched_add(), sleepq_switch(), softclock_thread(), start_softclock(), and turnstile_wait().

Here is the caller graph for this function:

◆ thread_lock_unblock()

void thread_lock_unblock ( struct thread *  td,
struct mtx new 
)

Definition at line 975 of file kern_mutex.c.

References blocked_lock.

◆ unlock_mtx()

uintptr_t unlock_mtx ( struct lock_object *  lock)
static

Definition at line 222 of file kern_mutex.c.

References mtx.

◆ unlock_spin()

uintptr_t unlock_spin ( struct lock_object *  lock)
static

Definition at line 233 of file kern_mutex.c.

References mtx.

Variable Documentation

◆ blocked_lock

struct mtx blocked_lock

◆ Giant

◆ lock_class_mtx_sleep

struct lock_class lock_class_mtx_sleep
Initial value:
= {
.lc_name = "sleep mutex",
.lc_flags = LC_SLEEPLOCK | LC_RECURSABLE,
.lc_assert = assert_mtx,
.lc_lock = lock_mtx,
.lc_unlock = unlock_mtx,
}
static void lock_mtx(struct lock_object *lock, uintptr_t how)
Definition: kern_mutex.c:208
static uintptr_t unlock_mtx(struct lock_object *lock)
Definition: kern_mutex.c:222
static void assert_mtx(const struct lock_object *lock, int what)
Definition: kern_mutex.c:186

Definition at line 115 of file kern_mutex.c.

Referenced by __mtx_lock_flags(), __mtx_unlock_flags(), _mtx_init(), _mtx_trylock_flags_int(), and mtx_wait_unlocked().

◆ lock_class_mtx_spin

struct lock_class lock_class_mtx_spin
Initial value:
= {
.lc_name = "spin mutex",
.lc_flags = LC_SPINLOCK | LC_RECURSABLE,
.lc_assert = assert_mtx,
.lc_lock = lock_spin,
.lc_unlock = unlock_spin,
}
static void lock_spin(struct lock_object *lock, uintptr_t how)
Definition: kern_mutex.c:215
static uintptr_t unlock_spin(struct lock_object *lock)
Definition: kern_mutex.c:233

Definition at line 128 of file kern_mutex.c.

Referenced by __mtx_lock_spin_flags(), __mtx_trylock_spin_flags(), __mtx_unlock_spin_flags(), _mtx_destroy(), _mtx_init(), and mtx_spin_wait_unlocked().