curproc(9)
- NetBSD Manual Pages
CURPROC(9) NetBSD Kernel Developer's Manual CURPROC(9)
NAME
curcpu, curlwp, curproc -- current processor, thread, and process
SYNOPSIS
#include <sys/proc.h>
struct cpu_info *
curcpu(void);
struct proc *curproc;
struct lwp *curlwp;
#include <sys/cpu.h>
bool
curcpu_stable(void);
DESCRIPTION
The following retrieve the current CPU, process, and thread (lightweight
process, or LWP), respectively:
curcpu() Returns a pointer to the struct cpu_info structure repre-
senting the CPU that the code calling it is running on.
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 cur-
rent context. curcpu_stable() MUST NOT be used to make
dynamic decisions about whether to query curcpu().
curproc Yields a pointer to the struct proc structure representing
the currently running process.
The value of curproc is stable and does not change during
execution except in machine-dependent logic to perform con-
text switches, so it works like a global constant, not like
a stateful procedure.
curlwp Yields a pointer to the struct lwp structure representing
the currently running thread.
The value of curlwp is stable and does not change during
execution except in machine-dependent logic to perform con-
text switches, so it works like a global constant, not like
a stateful procedure.
SOURCE REFERENCES
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 archi-
tectures supporting multiprocessing and kernel preemption.
The curcpu_stable() function is defined in kern/subr_cpu.c.
SEE ALSO
cpu_number(9), proc_find(9)
NetBSD 10.99 July 8, 2023 NetBSD 10.99
Powered by man-cgi (2021-06-01).
Maintained for NetBSD
by Kimmo Suominen.
Based on man-cgi by Panagiotis Christias.