FreeBSD kernel kern code
kern_mutex.c File Reference
#include <sys/cdefs.h>
#include "opt_adaptive_mutexes.h"
#include "opt_ddb.h"
#include "opt_global.h"
#include "opt_hwpmc_hooks.h"
#include "opt_kdtrace.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/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 mtx_unowned(m)   ((m)->mtx_lock == MTX_UNOWNED)
 
#define mtx_destroyed(m)   ((m)->mtx_lock == MTX_DESTROYED)
 
#define mtx_owner(m)   ((struct thread *)((m)->mtx_lock & ~MTX_FLAGMASK))
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static void assert_mtx (struct lock_object *lock, int what)
 
static void lock_mtx (struct lock_object *lock, int how)
 
static void lock_spin (struct lock_object *lock, int how)
 
static int unlock_mtx (struct lock_object *lock)
 
static int unlock_spin (struct lock_object *lock)
 
void _mtx_lock_flags (struct mtx *m, int opts, const char *file, int line)
 
void _mtx_unlock_flags (struct mtx *m, int opts, const char *file, int line)
 
void _mtx_lock_spin_flags (struct mtx *m, int opts, const char *file, int line)
 
void _mtx_unlock_spin_flags (struct mtx *m, int opts, const char *file, int line)
 
int _mtx_trylock (struct mtx *m, int opts, const char *file, int line)
 
void _mtx_lock_sleep (struct mtx *m, uintptr_t tid, int opts, const char *file, int line)
 
static void _mtx_lock_spin_failed (struct mtx *m)
 
void _thread_lock_flags (struct thread *td, int opts, const char *file, int line)
 
struct mtx * thread_lock_block (struct thread *td)
 
void thread_lock_unblock (struct thread *td, struct mtx *new)
 
void thread_lock_set (struct thread *td, struct mtx *new)
 
void _mtx_unlock_sleep (struct mtx *m, int opts, const char *file, int line)
 
void mtx_sysinit (void *arg)
 
void mtx_init (struct mtx *m, const char *name, const char *type, int opts)
 
void mtx_destroy (struct mtx *m)
 
void mutex_init (void)
 

Variables

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

Macro Definition Documentation

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

Definition at line 90 of file kern_mutex.c.

#define mtx_owner (   m)    ((struct thread *)((m)->mtx_lock & ~MTX_FLAGMASK))

Definition at line 92 of file kern_mutex.c.

Referenced by _mtx_lock_sleep(), and _mtx_lock_spin_failed().

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

Definition at line 88 of file kern_mutex.c.

Referenced by mtx_destroy().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
void _mtx_lock_flags ( struct mtx *  m,
int  opts,
const char *  file,
int  line 
)

Definition at line 197 of file kern_mutex.c.

References kdb_active, and lock_class_mtx_sleep.

void _mtx_lock_sleep ( struct mtx *  m,
uintptr_t  tid,
int  opts,
const char *  file,
int  line 
)

Definition at line 338 of file kern_mutex.c.

References mtx_owner, ts, turnstile_cancel(), turnstile_trywait(), turnstile_wait(), and waittime.

Here is the call graph for this function:

static void _mtx_lock_spin_failed ( struct mtx *  m)
static

Definition at line 507 of file kern_mutex.c.

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

Referenced by _thread_lock_flags().

Here is the call graph for this function:

Here is the caller graph for this function:

void _mtx_lock_spin_flags ( struct mtx *  m,
int  opts,
const char *  file,
int  line 
)

Definition at line 243 of file kern_mutex.c.

References lock_class_mtx_spin.

int _mtx_trylock ( struct mtx *  m,
int  opts,
const char *  file,
int  line 
)

Definition at line 290 of file kern_mutex.c.

References kdb_active, lock_class_mtx_sleep, and waittime.

void _mtx_unlock_flags ( struct mtx *  m,
int  opts,
const char *  file,
int  line 
)

Definition at line 221 of file kern_mutex.c.

References lock_class_mtx_sleep.

void _mtx_unlock_sleep ( struct mtx *  m,
int  opts,
const char *  file,
int  line 
)

Definition at line 711 of file kern_mutex.c.

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

Here is the call graph for this function:

void _mtx_unlock_spin_flags ( struct mtx *  m,
int  opts,
const char *  file,
int  line 
)

Definition at line 266 of file kern_mutex.c.

References lock_class_mtx_spin.

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

Definition at line 592 of file kern_mutex.c.

References _mtx_lock_spin_failed(), kdb_active, lock_class_mtx_spin, and panicstr.

Here is the call graph for this function:

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

Definition at line 143 of file kern_mutex.c.

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

Definition at line 150 of file kern_mutex.c.

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

Definition at line 157 of file kern_mutex.c.

References panic().

Here is the call graph for this function:

void mtx_sysinit ( void *  arg)

Definition at line 823 of file kern_mutex.c.

References mtx_init().

Here is the call graph for this function:

void mutex_init ( void  )

Definition at line 914 of file kern_mutex.c.

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

Here is the call graph for this function:

struct mtx* thread_lock_block ( struct thread *  td)

Definition at line 672 of file kern_mutex.c.

References blocked_lock.

Referenced by sched_switch(), and sched_switch_migrate().

Here is the caller graph for this function:

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

Definition at line 693 of file kern_mutex.c.

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

Here is the caller graph for this function:

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

Definition at line 685 of file kern_mutex.c.

References blocked_lock.

int unlock_mtx ( struct lock_object *  lock)
static

Definition at line 164 of file kern_mutex.c.

int unlock_spin ( struct lock_object *  lock)
static

Definition at line 175 of file kern_mutex.c.

References panic().

Here is the call graph for this function:

Variable Documentation

struct mtx blocked_lock

Definition at line 139 of file kern_mutex.c.

Referenced by mutex_init(), thread_lock_block(), and thread_lock_unblock().

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 int unlock_mtx(struct lock_object *lock)
Definition: kern_mutex.c:164
static void lock_mtx(struct lock_object *lock, int how)
Definition: kern_mutex.c:150
static void assert_mtx(struct lock_object *lock, int what)
Definition: kern_mutex.c:143

Definition at line 109 of file kern_mutex.c.

Referenced by _mtx_lock_flags(), _mtx_trylock(), _mtx_unlock_flags(), and mtx_init().

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 int unlock_spin(struct lock_object *lock)
Definition: kern_mutex.c:175
static void assert_mtx(struct lock_object *lock, int what)
Definition: kern_mutex.c:143
static void lock_spin(struct lock_object *lock, int how)
Definition: kern_mutex.c:157

Definition at line 122 of file kern_mutex.c.

Referenced by _mtx_lock_spin_flags(), _mtx_unlock_spin_flags(), _thread_lock_flags(), mtx_destroy(), and mtx_init().