CURPROC(9)
π curproc(9) β current processor, thread, and process π¦
okay so this is a page from the Kernel Developer's Manual, bestie, and it's literally about three little things that tell you where you are and who you are inside the kernel. main character energy fr π
β¨ 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 π
okay so these three retrieve the current CPU, process, and thread (that's a lightweight process, aka LWP, iykyk) respectively β one for each, slay:
curcpu()β returns a pointer to thestruct cpu_infostructure that represents the CPU the code calling it is running on. β¨
β οΈ bestie listen β the value ofcurcpu()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)). like, it literally expires on contact π
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(). π«Ά like, assert with it, don't decide with it β that's the whole vibe check.
curprocβ yields a pointer to thestruct procstructure representing the currently running process. π
The 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. no cap, it just is π
curlwpβ yields a pointer to thestruct lwpstructure representing the currently running thread. π§
The 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. same energy, iconic behaviour π
π¦ SOURCE REFERENCES π¦
- the
curcpu()macro is defined in the machine-independentmachine/cpu.h⨠- the
curprocmacro is defined insys/lwp.h - the
curlwpmacro has a machine-independent definition insys/lwp.h, but it may be overridden bymachine/cpu.h, and must be overridden on architectures supporting multiprocessing and kernel preemption π₯ (so on those archs,sys/lwp.h's version is not the final word β periodt) - the
curcpu_stable()function is defined inkern/subr_cpu.cπ
π SEE ALSO π
okay that's the whole page, go off π and yeah β this cutie came from Debian, dated July 8, 2023. mwah π«Άπ
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2002 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms