NetBSD/share/man/man9/cpu_switchto.9

150 lines
4.0 KiB
Groff
Raw Normal View History

2011-06-03 12:06:54 +04:00
.\" $NetBSD: cpu_switchto.9,v 1.14 2011/06/03 08:06:54 wiz Exp $
.\"
.\" Copyright (c)2007 YAMAMOTO Takashi,
.\" All rights reserved.
.\"
.\" 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 AUTHOR 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 AUTHOR 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 June 2, 2011
.Dt CPU_SWITCHTO 9
.Os
.\" ------------------------------------------------------------
.Sh NAME
.Nm cpu_switchto
2010-04-13 10:05:56 +04:00
.Nd machine-dependent
.Tn LWP
context switching interface
.\" ------------------------------------------------------------
.Sh SYNOPSIS
2007-03-20 14:11:51 +03:00
.In sys/cpu.h
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2007-04-21 21:52:09 +04:00
.Ft lwp_t *
.Fn cpu_switchto \
"lwp_t *oldlwp" "lwp_t *newlwp" "bool returning"
.\" ------------------------------------------------------------
.Sh DESCRIPTION
2010-04-13 10:05:56 +04:00
The
.Fn cpu_switchto
2010-04-13 10:05:56 +04:00
function saves the context of the
.Tn LWP
which is currently running on the processor,
and restores the context of the
.Tn LWP
specified by
.Fa newlwp .
.Pp
2010-04-13 10:05:56 +04:00
Remarks:
.Bl -enum -offset indent
.It
.Fn cpu_switchto
2010-04-13 10:05:56 +04:00
does not switch address spaces.
.It
.Fn cpu_switchto
2007-04-18 16:19:45 +04:00
sets
2010-04-13 10:05:56 +04:00
.Xr curlwp 9
2007-04-18 16:19:45 +04:00
to
.Fa newlwp .
If the architecture does non-interlocked adaptive mutex release,
.Fn cpu_switchto
does an equivalent of
.Xr membar_producer 3 ,
before and after the modification of
.Xr curlwp 9 .
2010-04-13 10:05:56 +04:00
.It
2007-02-17 20:24:01 +03:00
.Fn cpu_switchto
2007-04-18 16:19:45 +04:00
should be called at
.Dv IPL_SCHED .
2010-04-13 10:05:56 +04:00
When the function returns, the caller should lower
the priority level as soon as possible.
.It
2007-02-17 20:24:01 +03:00
.Fn cpu_switchto
2007-04-18 16:19:45 +04:00
might be called with spin mutexes held.
2010-04-13 10:05:56 +04:00
.El
2007-02-17 20:24:01 +03:00
.Pp
2010-04-13 10:05:56 +04:00
The function takes the following arguments.
.Bl -tag -width "returning " -offset indent
.It Fa oldlwp
2010-04-13 10:05:56 +04:00
Specify the
.Tn LWP
from which the switch is going to be made, i.e., the calling
.Tn LWP .
If it was
.Dv NULL ,
2010-04-13 10:05:56 +04:00
the context of the
.Tn LWP
currently running on this processor is not saved.
.It Fa newlwp
2010-04-13 10:05:56 +04:00
Specify the
.Tn LWP
to which to switch.
It must not be
.Dv NULL .
.It Fa returning
Only meaningful if the architecture implements fast software interrupts.
If true, it indicates that
.Fa oldlwp
2010-04-13 10:05:56 +04:00
is a soft interrupt
.Tn LWP
that is blocking.
It is a good indication that any kind of address space or user activity
can be completely ignored.
2008-05-26 00:00:30 +04:00
For example:
2010-04-13 10:05:56 +04:00
.Xr ras_lookup 9 ,
cache flushes, TLB wirings, adjusting lazy
.Tn FPU
state.
All that is required is to restore the register state and stack, and
2010-04-13 10:05:56 +04:00
return to the interrupted
.Tn LWP .
.El
.\" ------------------------------------------------------------
.Sh RETURN VALUES
2010-04-13 10:05:56 +04:00
The
.Fn cpu_switchto
2010-04-13 10:05:56 +04:00
function does not return until another
.Tn LWP
calls
.Fn cpu_switchto .
It returns the
2010-04-13 10:05:56 +04:00
.Vt oldlwp
argument of the
.Fn cpu_switchto
2010-04-13 10:05:56 +04:00
which is called to switch back to our
.Tn LWP .
It is either a
.Tn LWP
which called
.Fn cpu_switchto
to switch to us or
.Dv NULL
2010-04-13 10:05:56 +04:00
in case the
.Tn LWP
was exiting.
.\" ------------------------------------------------------------
.Sh SEE ALSO
2011-06-03 12:06:54 +04:00
.Xr membar_producer 3 ,
.Xr swapcontext 3 ,
.Xr intro 9 ,
.Xr mutex 9 ,
.Xr spl 9