| CURPROC(9) | Kernel Developer's Manual | CURPROC(9) |
curcpu, curlwp,
curproc — current processor,
thread, and process
#include
<sys/proc.h>
struct cpu_info *
curcpu(void);
struct proc *curproc;
struct lwp *curlwp;
#include
<sys/cpu.h>
bool
curcpu_stable(void);
The following retrieve the current CPU, process, and thread (lightweight process, or LWP), respectively:
curcpu()The value of
curcpu()
is unstable and may be stale as soon as it is read unless the caller
prevents preemption by raising the IPL
(spl(9),
mutex(9)), by disabling
preemption
(kpreempt_disable(9)),
or by binding the thread to its CPU
(curlwp_bind(9)).
The function
curcpu_stable()
can be used in assertions
(KASSERT(9)) to verify
that curcpu() is stable in the current context.
curcpu_stable() MUST NOT be used to make dynamic
decisions about whether to query curcpu().
curprocThe value of curproc is stable and
does not change during execution except in machine-dependent logic to
perform context switches, so it works like a global constant, not like a
stateful procedure.
curlwpThe value of curlwp is stable and does
not change during execution except in machine-dependent logic to perform
context switches, so it works like a global constant, not like a
stateful procedure.
The
curcpu()
macro is defined in the machine-independent
machine/cpu.h.
The curproc macro is defined in
sys/lwp.h.
The curlwp macro has a machine-independent
definition in sys/lwp.h, but it may be overridden by
machine/cpu.h, and must be overridden on
architectures supporting multiprocessing and kernel preemption.
The
curcpu_stable()
function is defined in kern/subr_cpu.c.
| July 8, 2023 | NetBSD 11.0 |