NetBSD/share/man/man9/curproc.9

108 lines
3.4 KiB
Groff

.\" $NetBSD: curproc.9,v 1.6 2022/09/22 14:02:24 riastradh Exp $
.\"
.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Gregory McGarry.
.\"
.\" 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 July 1, 2010
.Dt CURPROC 9
.Os
.Sh NAME
.Nm curproc ,
.Nm curcpu ,
.Nm curlwp
.Nd current process, processor, and
.Tn LWP
.Sh SYNOPSIS
.In sys/proc.h
.Ft struct cpu_info *
.Fn curcpu "void"
.Vt struct proc *curproc ;
.Vt struct lwp *curlwp ;
.Sh DESCRIPTION
The following macros retrieve
the current CPU, process, and thread
.Pq lightweight process, or Tn LWP ,
respectively:
.Bl -tag -width Dv
.It Fn curcpu
Returns a pointer to the
.Vt "struct cpu_info"
structure representing the CPU that the code calling it is running on.
.Pp
The value of
.Fn curcpu
is unstable and may be stale as soon as it is read unless the caller
prevents preemption by raising the IPL
.Pq Xr spl 9 , Xr mutex 9 ,
by disabling preemption
.Pq Xr kpreempt_disable 9 ,
or by binding the thread to its CPU
.Pq Xr curlwp_bind 9 .
.It Dv curproc
Yields a pointer to the
.Vt "struct proc"
structure representing the currently running process.
.Pp
The value of
.Dv 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.
.It Dv curlwp
Yields a pointer to the
.Vt "struct lwp"
structure representing the currently running thread.
.Pp
The value of
.Dv 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.
.El
.Sh SOURCE REFERENCES
The
.Fn curcpu
macro is defined in the machine-independent
.Pa machine/cpu.h .
.Pp
The
.Dv curproc
macro is defined in
.Pa sys/lwp.h .
.Pp
The
.Dv curlwp
macro has a machine-independent definition in
.Pa sys/lwp.h ,
but it may be overridden by
.Pa machine/cpu.h ,
and must be overridden on architectures supporting multiprocessing and
kernel preemption.
.Sh SEE ALSO
.Xr cpu_number 9 ,
.Xr proc_find 9