2022-09-22 17:02:24 +03:00
|
|
|
.\" $NetBSD: curproc.9,v 1.6 2022/09/22 14:02:24 riastradh Exp $
|
2002-05-25 06:16:35 +04:00
|
|
|
.\"
|
|
|
|
.\" 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.
|
|
|
|
.\"
|
2010-07-01 19:12:31 +04:00
|
|
|
.Dd July 1, 2010
|
2002-05-25 06:16:35 +04:00
|
|
|
.Dt CURPROC 9
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm curproc ,
|
2010-04-13 09:40:12 +04:00
|
|
|
.Nm curcpu ,
|
|
|
|
.Nm curlwp
|
|
|
|
.Nd current process, processor, and
|
|
|
|
.Tn LWP
|
2002-05-25 06:16:35 +04:00
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In sys/proc.h
|
2002-05-25 06:16:35 +04:00
|
|
|
.Ft struct cpu_info *
|
|
|
|
.Fn curcpu "void"
|
2022-09-22 17:02:24 +03:00
|
|
|
.Vt struct proc *curproc ;
|
|
|
|
.Vt struct lwp *curlwp ;
|
2002-05-25 06:16:35 +04:00
|
|
|
.Sh DESCRIPTION
|
2022-09-22 17:02:24 +03:00
|
|
|
The following macros retrieve
|
|
|
|
the current CPU, process, and thread
|
|
|
|
.Pq lightweight process, or Tn LWP ,
|
2010-04-13 09:40:12 +04:00
|
|
|
respectively:
|
2022-09-22 17:02:24 +03:00
|
|
|
.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
|
2002-05-25 06:16:35 +04:00
|
|
|
.Fn curcpu
|
2022-09-22 17:02:24 +03:00
|
|
|
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.
|
2010-04-13 09:40:12 +04:00
|
|
|
.El
|
2022-09-22 17:02:24 +03:00
|
|
|
.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.
|
2010-04-13 09:40:12 +04:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr cpu_number 9 ,
|
2010-07-01 19:12:31 +04:00
|
|
|
.Xr proc_find 9
|