Tue Feb 15 22:46:29 2022 UTC ()
KERNEL_LOCK(9): New man page for old not-dead-yet hack.

I'm not documenting this to encourage anyone to use it.  I'm only
documenting this to remind myself what the semantics is, because it's
kind of confusing and not at all like mutex(9).


(riastradh)
diff -r1.2411 -r1.2412 src/distrib/sets/lists/comp/mi
diff -r0 -r1.1 src/share/man/man9/KERNEL_LOCK.9
diff -r1.463 -r1.464 src/share/man/man9/Makefile

cvs diff -r1.2411 -r1.2412 src/distrib/sets/lists/comp/mi (expand / switch to unified diff)

--- src/distrib/sets/lists/comp/mi 2022/02/12 17:10:20 1.2411
+++ src/distrib/sets/lists/comp/mi 2022/02/15 22:46:29 1.2412
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: mi,v 1.2411 2022/02/12 17:10:20 riastradh Exp $ 1# $NetBSD: mi,v 1.2412 2022/02/15 22:46:29 riastradh Exp $
2# 2#
3# Note: don't delete entries from here - mark them as "obsolete" instead. 3# Note: don't delete entries from here - mark them as "obsolete" instead.
4./etc/mtree/set.comp comp-sys-root 4./etc/mtree/set.comp comp-sys-root
5./usr/bin/addr2line comp-debug-bin binutils 5./usr/bin/addr2line comp-debug-bin binutils
6./usr/bin/ar comp-util-bin binutils 6./usr/bin/ar comp-util-bin binutils
7./usr/bin/as comp-util-bin binutils 7./usr/bin/as comp-util-bin binutils
8./usr/bin/asa comp-fortran-bin 8./usr/bin/asa comp-fortran-bin
9./usr/bin/atf-compile comp-obsolete obsolete 9./usr/bin/atf-compile comp-obsolete obsolete
10./usr/bin/c++ comp-cxx-bin gcccmds 10./usr/bin/c++ comp-cxx-bin gcccmds
11./usr/bin/c++filt comp-cxx-bin binutils 11./usr/bin/c++filt comp-cxx-bin binutils
12./usr/bin/c11 comp-c-bin 12./usr/bin/c11 comp-c-bin
13./usr/bin/c89 comp-c-bin 13./usr/bin/c89 comp-c-bin
14./usr/bin/c99 comp-c-bin 14./usr/bin/c99 comp-c-bin
@@ -11152,26 +11152,31 @@ @@ -11152,26 +11152,31 @@
11152./usr/share/man/cat9/ETHER_IS_MULTICAST.0 comp-sys-catman .cat 11152./usr/share/man/cat9/ETHER_IS_MULTICAST.0 comp-sys-catman .cat
11153./usr/share/man/cat9/ETHER_NEXT_MULTI.0 comp-sys-catman .cat 11153./usr/share/man/cat9/ETHER_NEXT_MULTI.0 comp-sys-catman .cat
11154./usr/share/man/cat9/FILE_IS_USABLE.0 comp-sys-catman .cat 11154./usr/share/man/cat9/FILE_IS_USABLE.0 comp-sys-catman .cat
11155./usr/share/man/cat9/FILE_SET_MATURE.0 comp-sys-catman .cat 11155./usr/share/man/cat9/FILE_SET_MATURE.0 comp-sys-catman .cat
11156./usr/share/man/cat9/FILE_UNUSE.0 comp-sys-catman .cat 11156./usr/share/man/cat9/FILE_UNUSE.0 comp-sys-catman .cat
11157./usr/share/man/cat9/FILE_USE.0 comp-sys-catman .cat 11157./usr/share/man/cat9/FILE_USE.0 comp-sys-catman .cat
11158./usr/share/man/cat9/FREE.0 comp-sys-catman .cat 11158./usr/share/man/cat9/FREE.0 comp-sys-catman .cat
11159./usr/share/man/cat9/HOLDRELE.0 comp-obsolete obsolete 11159./usr/share/man/cat9/HOLDRELE.0 comp-obsolete obsolete
11160./usr/share/man/cat9/ISSET.0 comp-sys-catman .cat 11160./usr/share/man/cat9/ISSET.0 comp-sys-catman .cat
11161./usr/share/man/cat9/KASSERT.0 comp-sys-catman .cat 11161./usr/share/man/cat9/KASSERT.0 comp-sys-catman .cat
11162./usr/share/man/cat9/KASSERTMSG.0 comp-sys-catman .cat 11162./usr/share/man/cat9/KASSERTMSG.0 comp-sys-catman .cat
11163./usr/share/man/cat9/KDASSERT.0 comp-sys-catman .cat 11163./usr/share/man/cat9/KDASSERT.0 comp-sys-catman .cat
11164./usr/share/man/cat9/KDASSERTMSG.0 comp-sys-catman .cat 11164./usr/share/man/cat9/KDASSERTMSG.0 comp-sys-catman .cat
 11165./usr/share/man/cat9/KERNEL_LOCK.0 comp-sys-catman .cat
 11166./usr/share/man/cat9/KERNEL_LOCKED_P.0 comp-sys-catman .cat
 11167./usr/share/man/cat9/KERNEL_UNLOCK_ALL.0 comp-sys-catman .cat
 11168./usr/share/man/cat9/KERNEL_UNLOCK_LAST.0 comp-sys-catman .cat
 11169./usr/share/man/cat9/KERNEL_UNLOCK_ONE.0 comp-sys-catman .cat
11165./usr/share/man/cat9/KNOTE.0 comp-sys-catman .cat 11170./usr/share/man/cat9/KNOTE.0 comp-sys-catman .cat
11166./usr/share/man/cat9/LWP_CACHE_CREDS.0 comp-sys-catman .cat 11171./usr/share/man/cat9/LWP_CACHE_CREDS.0 comp-sys-catman .cat
11167./usr/share/man/cat9/MALLOC.0 comp-sys-catman .cat 11172./usr/share/man/cat9/MALLOC.0 comp-sys-catman .cat
11168./usr/share/man/cat9/MALLOC_DECLARE.0 comp-sys-catman .cat 11173./usr/share/man/cat9/MALLOC_DECLARE.0 comp-sys-catman .cat
11169./usr/share/man/cat9/MALLOC_DEFINE.0 comp-sys-catman .cat 11174./usr/share/man/cat9/MALLOC_DEFINE.0 comp-sys-catman .cat
11170./usr/share/man/cat9/MALLOC_DEFINE_LIMIT.0 comp-obsolete obsolete 11175./usr/share/man/cat9/MALLOC_DEFINE_LIMIT.0 comp-obsolete obsolete
11171./usr/share/man/cat9/MCHTYPE.0 comp-sys-catman .cat 11176./usr/share/man/cat9/MCHTYPE.0 comp-sys-catman .cat
11172./usr/share/man/cat9/MCLGET.0 comp-sys-catman .cat 11177./usr/share/man/cat9/MCLGET.0 comp-sys-catman .cat
11173./usr/share/man/cat9/MEXTADD.0 comp-sys-catman .cat 11178./usr/share/man/cat9/MEXTADD.0 comp-sys-catman .cat
11174./usr/share/man/cat9/MEXTMALLOC.0 comp-sys-catman .cat 11179./usr/share/man/cat9/MEXTMALLOC.0 comp-sys-catman .cat
11175./usr/share/man/cat9/MEXTREMOVE.0 comp-obsolete obsolete 11180./usr/share/man/cat9/MEXTREMOVE.0 comp-obsolete obsolete
11176./usr/share/man/cat9/MFREE.0 comp-sys-catman .cat 11181./usr/share/man/cat9/MFREE.0 comp-sys-catman .cat
11177./usr/share/man/cat9/MGET.0 comp-sys-catman .cat 11182./usr/share/man/cat9/MGET.0 comp-sys-catman .cat
@@ -19401,26 +19406,31 @@ @@ -19401,26 +19406,31 @@
19401./usr/share/man/html9/ETHER_IS_MULTICAST.html comp-sys-htmlman html 19406./usr/share/man/html9/ETHER_IS_MULTICAST.html comp-sys-htmlman html
19402./usr/share/man/html9/ETHER_NEXT_MULTI.html comp-sys-htmlman html 19407./usr/share/man/html9/ETHER_NEXT_MULTI.html comp-sys-htmlman html
19403./usr/share/man/html9/FILE_IS_USABLE.html comp-sys-htmlman html 19408./usr/share/man/html9/FILE_IS_USABLE.html comp-sys-htmlman html
19404./usr/share/man/html9/FILE_SET_MATURE.html comp-sys-htmlman html 19409./usr/share/man/html9/FILE_SET_MATURE.html comp-sys-htmlman html
19405./usr/share/man/html9/FILE_UNUSE.html comp-sys-htmlman html 19410./usr/share/man/html9/FILE_UNUSE.html comp-sys-htmlman html
19406./usr/share/man/html9/FILE_USE.html comp-sys-htmlman html 19411./usr/share/man/html9/FILE_USE.html comp-sys-htmlman html
19407./usr/share/man/html9/FREE.html comp-sys-htmlman html 19412./usr/share/man/html9/FREE.html comp-sys-htmlman html
19408./usr/share/man/html9/HOLDRELE.html comp-obsolete obsolete 19413./usr/share/man/html9/HOLDRELE.html comp-obsolete obsolete
19409./usr/share/man/html9/ISSET.html comp-sys-htmlman html 19414./usr/share/man/html9/ISSET.html comp-sys-htmlman html
19410./usr/share/man/html9/KASSERT.html comp-sys-htmlman html 19415./usr/share/man/html9/KASSERT.html comp-sys-htmlman html
19411./usr/share/man/html9/KASSERTMSG.html comp-sys-htmlman html 19416./usr/share/man/html9/KASSERTMSG.html comp-sys-htmlman html
19412./usr/share/man/html9/KDASSERT.html comp-sys-htmlman html 19417./usr/share/man/html9/KDASSERT.html comp-sys-htmlman html
19413./usr/share/man/html9/KDASSERTMSG.html comp-sys-htmlman html 19418./usr/share/man/html9/KDASSERTMSG.html comp-sys-htmlman html
 19419./usr/share/man/html9/KERNEL_LOCK.html comp-sys-htmlman html
 19420./usr/share/man/html9/KERNEL_LOCKED_P.html comp-sys-htmlman html
 19421./usr/share/man/html9/KERNEL_UNLOCK_ALL.html comp-sys-htmlman html
 19422./usr/share/man/html9/KERNEL_UNLOCK_LAST.html comp-sys-htmlman html
 19423./usr/share/man/html9/KERNEL_UNLOCK_ONE.html comp-sys-htmlman html
19414./usr/share/man/html9/KNOTE.html comp-sys-htmlman html 19424./usr/share/man/html9/KNOTE.html comp-sys-htmlman html
19415./usr/share/man/html9/LWP_CACHE_CREDS.html comp-sys-htmlman html 19425./usr/share/man/html9/LWP_CACHE_CREDS.html comp-sys-htmlman html
19416./usr/share/man/html9/MALLOC.html comp-sys-htmlman html 19426./usr/share/man/html9/MALLOC.html comp-sys-htmlman html
19417./usr/share/man/html9/MALLOC_DECLARE.html comp-sys-htmlman html 19427./usr/share/man/html9/MALLOC_DECLARE.html comp-sys-htmlman html
19418./usr/share/man/html9/MALLOC_DEFINE.html comp-sys-htmlman html 19428./usr/share/man/html9/MALLOC_DEFINE.html comp-sys-htmlman html
19419./usr/share/man/html9/MALLOC_DEFINE_LIMIT.html comp-obsolete obsolete 19429./usr/share/man/html9/MALLOC_DEFINE_LIMIT.html comp-obsolete obsolete
19420./usr/share/man/html9/MCHTYPE.html comp-sys-htmlman html 19430./usr/share/man/html9/MCHTYPE.html comp-sys-htmlman html
19421./usr/share/man/html9/MCLGET.html comp-sys-htmlman html 19431./usr/share/man/html9/MCLGET.html comp-sys-htmlman html
19422./usr/share/man/html9/MEXTADD.html comp-sys-htmlman html 19432./usr/share/man/html9/MEXTADD.html comp-sys-htmlman html
19423./usr/share/man/html9/MEXTMALLOC.html comp-sys-htmlman html 19433./usr/share/man/html9/MEXTMALLOC.html comp-sys-htmlman html
19424./usr/share/man/html9/MFREE.html comp-sys-htmlman html 19434./usr/share/man/html9/MFREE.html comp-sys-htmlman html
19425./usr/share/man/html9/MGET.html comp-sys-htmlman html 19435./usr/share/man/html9/MGET.html comp-sys-htmlman html
19426./usr/share/man/html9/MGETHDR.html comp-sys-htmlman html 19436./usr/share/man/html9/MGETHDR.html comp-sys-htmlman html
@@ -27731,26 +27741,31 @@ @@ -27731,26 +27741,31 @@
27731./usr/share/man/man9/ETHER_IS_MULTICAST.9 comp-sys-man .man 27741./usr/share/man/man9/ETHER_IS_MULTICAST.9 comp-sys-man .man
27732./usr/share/man/man9/ETHER_NEXT_MULTI.9 comp-sys-man .man 27742./usr/share/man/man9/ETHER_NEXT_MULTI.9 comp-sys-man .man
27733./usr/share/man/man9/FILE_IS_USABLE.9 comp-sys-man .man 27743./usr/share/man/man9/FILE_IS_USABLE.9 comp-sys-man .man
27734./usr/share/man/man9/FILE_SET_MATURE.9 comp-sys-man .man 27744./usr/share/man/man9/FILE_SET_MATURE.9 comp-sys-man .man
27735./usr/share/man/man9/FILE_UNUSE.9 comp-sys-man .man 27745./usr/share/man/man9/FILE_UNUSE.9 comp-sys-man .man
27736./usr/share/man/man9/FILE_USE.9 comp-sys-man .man 27746./usr/share/man/man9/FILE_USE.9 comp-sys-man .man
27737./usr/share/man/man9/FREE.9 comp-sys-man .man 27747./usr/share/man/man9/FREE.9 comp-sys-man .man
27738./usr/share/man/man9/HOLDRELE.9 comp-obsolete obsolete 27748./usr/share/man/man9/HOLDRELE.9 comp-obsolete obsolete
27739./usr/share/man/man9/ISSET.9 comp-sys-man .man 27749./usr/share/man/man9/ISSET.9 comp-sys-man .man
27740./usr/share/man/man9/KASSERT.9 comp-sys-man .man 27750./usr/share/man/man9/KASSERT.9 comp-sys-man .man
27741./usr/share/man/man9/KASSERTMSG.9 comp-sys-man .man 27751./usr/share/man/man9/KASSERTMSG.9 comp-sys-man .man
27742./usr/share/man/man9/KDASSERT.9 comp-sys-man .man 27752./usr/share/man/man9/KDASSERT.9 comp-sys-man .man
27743./usr/share/man/man9/KDASSERTMSG.9 comp-sys-man .man 27753./usr/share/man/man9/KDASSERTMSG.9 comp-sys-man .man
 27754./usr/share/man/man9/KERNEL_LOCK.9 comp-sys-man .man
 27755./usr/share/man/man9/KERNEL_LOCKED_P.9 comp-sys-man .man
 27756./usr/share/man/man9/KERNEL_UNLOCK_ALL.9 comp-sys-man .man
 27757./usr/share/man/man9/KERNEL_UNLOCK_LAST.9 comp-sys-man .man
 27758./usr/share/man/man9/KERNEL_UNLOCK_ONE.9 comp-sys-man .man
27744./usr/share/man/man9/KNOTE.9 comp-sys-man .man 27759./usr/share/man/man9/KNOTE.9 comp-sys-man .man
27745./usr/share/man/man9/LWP_CACHE_CREDS.9 comp-sys-man .man 27760./usr/share/man/man9/LWP_CACHE_CREDS.9 comp-sys-man .man
27746./usr/share/man/man9/MALLOC.9 comp-sys-man .man 27761./usr/share/man/man9/MALLOC.9 comp-sys-man .man
27747./usr/share/man/man9/MALLOC_DECLARE.9 comp-sys-man .man 27762./usr/share/man/man9/MALLOC_DECLARE.9 comp-sys-man .man
27748./usr/share/man/man9/MALLOC_DEFINE.9 comp-sys-man .man 27763./usr/share/man/man9/MALLOC_DEFINE.9 comp-sys-man .man
27749./usr/share/man/man9/MALLOC_DEFINE_LIMIT.9 comp-obsolete obsolete 27764./usr/share/man/man9/MALLOC_DEFINE_LIMIT.9 comp-obsolete obsolete
27750./usr/share/man/man9/MCHTYPE.9 comp-sys-man .man 27765./usr/share/man/man9/MCHTYPE.9 comp-sys-man .man
27751./usr/share/man/man9/MCLGET.9 comp-sys-man .man 27766./usr/share/man/man9/MCLGET.9 comp-sys-man .man
27752./usr/share/man/man9/MEXTADD.9 comp-sys-man .man 27767./usr/share/man/man9/MEXTADD.9 comp-sys-man .man
27753./usr/share/man/man9/MEXTMALLOC.9 comp-sys-man .man 27768./usr/share/man/man9/MEXTMALLOC.9 comp-sys-man .man
27754./usr/share/man/man9/MEXTREMOVE.9 comp-obsolete obsolete 27769./usr/share/man/man9/MEXTREMOVE.9 comp-obsolete obsolete
27755./usr/share/man/man9/MFREE.9 comp-sys-man .man 27770./usr/share/man/man9/MFREE.9 comp-sys-man .man
27756./usr/share/man/man9/MGET.9 comp-sys-man .man 27771./usr/share/man/man9/MGET.9 comp-sys-man .man

File Added: src/share/man/man9/KERNEL_LOCK.9
.\"	$NetBSD: KERNEL_LOCK.9,v 1.1 2022/02/15 22:46:29 riastradh Exp $
.\"
.\" Copyright (c) 2022 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd February 13, 2022
.Dt KERNEL_LOCK 9
.Os
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh NAME
.Nm KERNEL_LOCK
.Nd compatibility with legacy uniprocessor code
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh SYNOPSIS
.In sys/systm.h
.\"
.Ft void
.Fn KERNEL_LOCK "int nlocks" "struct lwp *l"
.Ft void
.Fn KERNEL_UNLOCK_ONE "struct lwp *l"
.Ft void
.Fn KERNEL_UNLOCK_ALL "struct lwp *l" "int *nlocksp"
.Ft void
.Fn KERNEL_UNLOCK_LAST "struct lwp *l"
.Ft bool
.Fn KERNEL_LOCKED_P
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh DESCRIPTION
The
.Nm
facility serves to gradually transition software from the kernel's
legacy uniprocessor execution model, where the kernel runs on only a
single CPU and never in parallel on multiple CPUs, to a multiprocessor
system.
.Pp
.Sy New code should not use Nm .
.Nm
is meant only for gradual transition of
.Nx
to natively MP-safe code, which uses
.Xr mutex 9
or other
.Xr locking 9
facilities to synchronize between threads and interrupt handlers.
Use of
.Nm
hurts system performance and responsiveness.
This man page exists only to document the legacy API in order to make
it easier to transition away from.
.Pp
The kernel lock, sometimes also known as
.Sq giant lock
or
.Sq big lock ,
is a recursive exclusive spin-lock that can be held by a CPU at any
interrupt priority level and is dropped while sleeping.
This means:
.Bl -tag -width "held by a CPU"
.It recursive
If a CPU already holds the kernel lock, it can be acquired again and
again, as long as it is released an equal number of times.
.It exclusive
Only one CPU at a time can hold the kernel lock.
.It spin-lock
When one CPU holds the kernel lock and another CPU wants to hold it,
the second CPU
.Sq spins ,
i.e., repeatedly executes instructions to see if the kernel lock is
available yet, until the first CPU releases it.
During this time, no other threads can run on the spinning CPU.
.Pp
This means holding the kernel lock for long periods of time, such as
nontrivial computation, must be avoided.
Under
.Dv LOCKDEBUG
kernels, holding the kernel lock for too long can lead to
.Sq spinout
crashes.
.It held by a CPU
The kernel lock is held by a CPU, not by a process, kthread, LWP, or
interrupt handler.
It may be shared by a kthread LWP and several softint LWPs at the same
time, for example, if the softints interrupted the thread on a CPU.
.It any interrupt priority level
The kernel lock
.Em does not
block interrupts; subsystems running with the kernel lock use
.Xr spl 9
to synchronize with interrupt handlers.
.Pp
Interrupt handlers that are not marked MP-safe are always run with the
kernel lock.
If the interrupt arrives on a CPU where the kernel lock is already
held, it is simply taken again recursively on interrupt entry and
released to its original recursion depth on interrupt exit.
.It dropped while sleeping
Any time the kernel sleeps to let other threads run, for any reason
including
.Xr tsleep 9
or
.Xr condvar 9
or even adaptive
.Xr mutex 9
locks, it releases the kernel lock before going to sleep and then
reacquires it afterward.
.Pp
This means, for instance, that although data structures accessed only
under the kernel lock won't be changed before the sleep, they may be
changed by another thread during the sleep.
For example, the following program may crash on an assertion failure
because the sleep in
.Xr mutex_enter 9
can allow another CPU to run and change the global variable
.Dv x :
.Bd -literal
	KERNEL_LOCK(1, NULL);
	x = 42;
	mutex_enter(...);
	...
	mutex_exit(...);
	KASSERT(x == 42);
	KERNEL_UNLOCK_ONE(NULL);
.Ed
.Pp
This means simply introducing calls to
.Xr mutex_enter 9
and
.Xr mutex_exit 9
can break kernel-locked assumptions.
Subsystems need to be consistently converted from
.Xr KERNEL_LOCK 9
and
.Xr spl 9
to
.Xr mutex 9 ,
.Xr condvar 9 ,
etc.; mixing
.Xr mutex 9
and
.Nm
usually doesn't work.
.El
.Pp
Holding the kernel lock
.Em does not
prevent other code from running on other CPUs at the same time.
It only prevents other
.Em kernel-locked
code from running on other CPUs at the same time.
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh FUNCTIONS
.Bl -tag -width abcd
.It Fn KERNEL_LOCK nlocks l
Acquire
.Fa nlocks
recursive levels of kernel lock.
.Pp
If the kernel lock is already held by another CPU, spins until it can
be acquired by this one.
If the kernel lock is already held by this CPU, records the kernel
lock recursion depth and returns immediately.
.Pp
Most of the time
.Fa nlocks
is 1, but code that deliberately releases all of the kernel locks held
by the current CPU in order to sleep and later reacquire the same
number of kernel locks will pass a value of
.Fa nlocks
obtained from
.Fn KERNEL_UNLOCK_ALL .
.It Fn KERNEL_UNLOCK_ONE l
Release one level of the kernel lock.
Equivalent to
.Fo KERNEL_UNLOCK
.Li 1 ,
.Fa l ,
.Dv NULL
.Fc .
.It Fn KERNEL_UNLOCK_ALL l nlocksp
Store the kernel lock recursion depth at
.Fa nlocksp
and release all recursive levels of the kernel lock.
.Pp
This is often used inside logic implementing sleep, around a call to
.Xr mi_switch 9 ,
so that the same number of recursive kernel locks can be reacquired
afterward once the thread is reawoken:
.Bd -literal
	int nlocks;

	KERNEL_UNLOCK_ALL(l, &nlocks);
	... mi_switch(l) ...
	KERNEL_LOCK(nlocks, l);
.Ed
.It Fn KERNEL_UNLOCK_LAST l
Release the kernel lock, which must be held at exactly one level.
.Pp
This is normally used at the end of a non-MP-safe thread, which was
known to have started with exactly one level of the kernel lock, and is
now about to exit.
.It Fn KERNEL_LOCKED_P
True if the kernel lock is held.
.Pp
To be used only in diagnostic assertions with
.Xr KASSERT 9 .
.El
.Pp
The legacy argument
.Fa l
must be
.Dv NULL
or
.Dv curlwp ,
which mean the same thing.
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh NOTES
Some
.Nx
kernel abstractions execute caller-specified funtions with the kernel
lock held by default, for compatibility with legacy code, but can be
explicitly instructed
.Em not
to hold the kernel lock by passing an MP-safe flag:
.Bl -bullet
.It
.Xr callout 9 ,
.Dv CALLOUT_MPSAFE
.It
.Xr kfilter_register 9
and
.Xr knote 9 ,
.Dv FILTEROPS_MPSAFE
.It
.Xr kthread 9 ,
.Dv KTHREAD_MPSAFE
.It
.Xr pci_intr 9 ,
.Dv PCI_INTR_MPSAFE
.It
.Xr scsipi 9 ,
.Dv SCSIPI_ADAPT_MPSAFE
.It
.Xr softint 9 ,
.Dv SOFTINT_MPSAFE
.It
.Xr usbdi 9
pipes,
.Dv USBD_MPSAFE
.It
.Xr usbdi 9
tasks,
.Dv USB_TASKQ_MPSAFE
.It
.Xr vnode 9 ,
.Dv VV_MPSAFE
.It
.Xr workqueue 9 ,
.Dv WQ_MPSAFE
.El
.Pp
The following
.Nx
subsystems are still kernel-locked and need re-engineering to take
advantage of parallelism on multiprocessor systems:
.Bl -bullet
.It
.Xr ata 4 ,
.Xr atapi 4 ,
.Xr wd 4
.It
.Xr video 4
.It
.Xr autoconf 9
.It
most of the network stack by default, unless the option
.Dv NET_MPSAFE
is enabled
.It
.No ...
.El
.Pp
All interrupt handlers at
.Dv IPL_VM ,
or lower
.Pq Xr spl 9
run with the kernel lock on most ports.
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh SEE ALSO
.Xr locking 9 ,
.Xr mutex 9 ,
.Xr spl 9

cvs diff -r1.463 -r1.464 src/share/man/man9/Makefile (expand / switch to unified diff)

--- src/share/man/man9/Makefile 2022/02/12 17:10:20 1.463
+++ src/share/man/man9/Makefile 2022/02/15 22:46:29 1.464
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: Makefile,v 1.463 2022/02/12 17:10:20 riastradh Exp $ 1# $NetBSD: Makefile,v 1.464 2022/02/15 22:46:29 riastradh Exp $
2 2
3# Makefile for section 9 (kernel function and variable) manual pages. 3# Makefile for section 9 (kernel function and variable) manual pages.
4 4
5MAN= accept_filter.9 accf_data.9 accf_http.9 acl.9 \ 5MAN= accept_filter.9 accf_data.9 accf_http.9 acl.9 \
6 altq.9 arp.9 audio.9 autoconf.9 \ 6 altq.9 arp.9 audio.9 autoconf.9 \
7 bcdtobin.9 bcmp.9 bcopy.9 bintime_add.9 bluetooth.9 boothowto.9 bpf.9 \ 7 bcdtobin.9 bcmp.9 bcopy.9 bintime_add.9 bluetooth.9 boothowto.9 bpf.9 \
8 buffercache.9 bufferio.9 bufq.9 bus_dma.9 bus_space.9 byteorder.9 \ 8 buffercache.9 bufferio.9 bufq.9 bus_dma.9 bus_space.9 byteorder.9 \
9 bzero.9 \ 9 bzero.9 \
10 callback.9 callout.9 cardbus.9 clock.9 cnmagic.9 condvar.9 config.9 \ 10 callback.9 callout.9 cardbus.9 clock.9 cnmagic.9 condvar.9 config.9 \
11 cons.9 copy.9 coredump_write.9 \ 11 cons.9 copy.9 coredump_write.9 \
12 cpu_configure.9 cpu_coredump.9 cpu_dumpconf.9 \ 12 cpu_configure.9 cpu_coredump.9 cpu_dumpconf.9 \
13 cpu_lwp_fork.9 \ 13 cpu_lwp_fork.9 \
14 cpu_idle.9 cpu_initclocks.9 cpu_need_resched.9 \ 14 cpu_idle.9 cpu_initclocks.9 cpu_need_resched.9 \
@@ -115,26 +115,32 @@ MLINKS+=dmover.9 dmover_backend_register @@ -115,26 +115,32 @@ MLINKS+=dmover.9 dmover_backend_register
115 dmover.9 dmover_session_create.9 \ 115 dmover.9 dmover_session_create.9 \
116 dmover.9 dmover_session_destroy.9 \ 116 dmover.9 dmover_session_destroy.9 \
117 dmover.9 dmover_request_alloc.9 \ 117 dmover.9 dmover_request_alloc.9 \
118 dmover.9 dmover_request_free.9 \ 118 dmover.9 dmover_request_free.9 \
119 dmover.9 dmover_process.9 \ 119 dmover.9 dmover_process.9 \
120 dmover.9 dmover_done.9 120 dmover.9 dmover_done.9
121 121
122MAN+= CTASSERT.9 122MAN+= CTASSERT.9
123MAN+= KASSERT.9 123MAN+= KASSERT.9
124MLINKS+=KASSERT.9 KASSERTMSG.9 \ 124MLINKS+=KASSERT.9 KASSERTMSG.9 \
125 KASSERT.9 KDASSERT.9 \ 125 KASSERT.9 KDASSERT.9 \
126 KASSERT.9 KDASSERTMSG.9 126 KASSERT.9 KDASSERTMSG.9
127 127
 128MAN+= KERNEL_LOCK.9
 129MLINKS+=KERNEL_LOCK.9 KERNEL_LOCKED_P.9 \
 130 KERNEL_LOCK.9 KERNEL_UNLOCK_ALL.9 \
 131 KERNEL_LOCK.9 KERNEL_UNLOCK_LAST.9 \
 132 KERNEL_LOCK.9 KERNEL_UNLOCK_ONE.9
 133
128MLINKS+=accept_filter.9 accept_filt_add.9 134MLINKS+=accept_filter.9 accept_filt_add.9
129MLINKS+=accept_filter.9 accept_filt_del.9 135MLINKS+=accept_filter.9 accept_filt_del.9
130MLINKS+=accept_filter.9 accept_filt_generic_mod_event.9 136MLINKS+=accept_filter.9 accept_filt_generic_mod_event.9
131MLINKS+=accept_filter.9 accept_filt_get.9 137MLINKS+=accept_filter.9 accept_filt_get.9
132 138
133MLINKS+=arp.9 arp_ifinit.9 arp.9 arpresolve.9 arp.9 arpintr.9 139MLINKS+=arp.9 arp_ifinit.9 arp.9 arpresolve.9 arp.9 arpintr.9
134MLINKS+=autoconf.9 config_search.9 \ 140MLINKS+=autoconf.9 config_search.9 \
135 autoconf.9 config_found.9 \ 141 autoconf.9 config_found.9 \
136 autoconf.9 config_match.9 \ 142 autoconf.9 config_match.9 \
137 autoconf.9 config_attach.9 \ 143 autoconf.9 config_attach.9 \
138 autoconf.9 config_attach_pseudo.9 \ 144 autoconf.9 config_attach_pseudo.9 \
139 autoconf.9 config_detach.9 \ 145 autoconf.9 config_detach.9 \
140 autoconf.9 config_detach_children.9 \ 146 autoconf.9 config_detach_children.9 \