This chapter is maintained by the FreeBSD SMP Next Generation Project. Please direct any comments or suggestions to its FreeBSD symmetric multiprocessing mailing list <freebsd-smp@FreeBSD.org>.
This document outlines the locking used in the FreeBSD kernel to permit effective multi-processing within the kernel. Locking can be achieved via several means. Data structures can be protected by mutexes or lockmgr(9) locks. A few variables are protected simply by always using atomic operations to access them.
A mutex is simply a lock used to guarantee mutual exclusion. Specifically, a mutex may only be owned by one entity at a time. If another entity wishes to obtain a mutex that is already owned, it must wait until the mutex is released. In the FreeBSD kernel, mutexes are owned by processes.
Mutexes may be recursively acquired, but they are intended to be held for a short period of time. Specifically, one may not sleep while holding a mutex. If you need to hold a lock across a sleep, use a lockmgr(9) lock.
Each mutex has several properties of interest:
The name of the struct mtx variable in the kernel source.
The name of the mutex assigned to it by mtx_init. This name is displayed in KTR trace messages and witness errors and warnings and is used to distinguish mutexes in the witness code.
The type of the mutex in terms of the MTX_* flags. The meaning for each flag is related to its meaning as documented in mutex(9).
A sleep mutex
A spin mutex
This mutex is initialized very early. Thus, it must be declared via MUTEX_DECLARE, and the MTX_COLD flag must be passed to mtx_init.
This spin mutex does not disable interrupts.
This mutex is not allowed to recurse.
A list of data structures or data structure members that this entry protects. For data structure members, the name will be in the form of structure name.member name.
Functions that can only be called if this mutex is held.
Table 10-1. Mutex List
Variable Name | Logical Name | Type | Protectees | Dependent Functions |
---|---|---|---|---|
sched_lock | ``sched lock'' | MTX_SPIN | MTX_COLD | _gmonparam, cnt.v_swtch, cp_time, curpriority, mtx.mtx_blocked, mtx.mtx_contested, proc.p_contested, proc.p_blocked, proc.p_flag (P_PROFIL XXX, P_INMEM, P_SINTR, P_TIMEOUT, P_SWAPINREQ XXX, P_INMEN XXX), proc.p_nice, proc.p_procq, proc.p_blocked, proc.p_estcpu, proc.p_nativepri, proc.p_priority, proc.p_usrpri, proc.p_rtprio, proc.p_rqindex, proc.p_stats->p_prof, proc.p_stats->p_ru, proc.p_stat, proc.p_cpticks proc.p_iticks, proc.p_uticks, proc.p_sticks, proc.p_swtime, proc.p_slptime, proc.p_runtime, proc.p_pctcpu, proc.p_oncpu, proc.p_asleep, proc.p_wchan, proc.p_wmesg, proc.p_slpq, proc.p_vmspace (XXX - in statclock), pscnt, slpque, itqueuebits, itqueues, rtqueuebits, rtqueues, queuebits, queues, idqueuebits, idqueues, switchtime, | setrunqueue, remrunqueue, mi_switch, chooseproc, schedclock, resetpriority, updatepri, maybe_resched, cpu_switch, cpu_throw |
vm86pcb_lock | ``vm86pcb lock'' | MTX_DEF | MTX_COLD | vm86pcb | vm86_bioscall |
Giant | ``Giant'' | MTX_DEF | MTX_COLD | nearly everything | lots |
callout_lock | ``callout lock'' | MTX_SPIN | callfree, callwheel, nextsoftcheck, proc.p_itcallout, proc.p_slpcallout, softticks, ticks |
This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.
For questions about FreeBSD, read the
documentation
before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |