2011-06-03 12:06:54 +04:00
|
|
|
.\" $NetBSD: cpu_switchto.9,v 1.14 2011/06/03 08:06:54 wiz Exp $
|
2007-02-17 19:23:08 +03:00
|
|
|
.\"
|
|
|
|
.\" 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.
|
|
|
|
.\"
|
|
|
|
.\" ------------------------------------------------------------
|
2011-06-02 04:58:26 +04:00
|
|
|
.Dd June 2, 2011
|
2007-02-17 19:23:08 +03:00
|
|
|
.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
|
2007-02-17 19:23:08 +03:00
|
|
|
.\" ------------------------------------------------------------
|
|
|
|
.Sh SYNOPSIS
|
2007-03-20 14:11:51 +03:00
|
|
|
.In sys/cpu.h
|
2007-02-17 19:23:08 +03:00
|
|
|
.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2007-04-21 21:52:09 +04:00
|
|
|
.Ft lwp_t *
|
2007-02-17 19:23:08 +03:00
|
|
|
.Fn cpu_switchto \
|
2008-01-25 02:06:10 +03:00
|
|
|
"lwp_t *oldlwp" "lwp_t *newlwp" "bool returning"
|
2007-02-17 19:23:08 +03:00
|
|
|
.\" ------------------------------------------------------------
|
|
|
|
.Sh DESCRIPTION
|
2010-04-13 10:05:56 +04:00
|
|
|
The
|
2007-02-17 19:23:08 +03:00
|
|
|
.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
|
2007-02-17 19:23:08 +03:00
|
|
|
.Fa newlwp .
|
|
|
|
.Pp
|
2010-04-13 10:05:56 +04:00
|
|
|
Remarks:
|
|
|
|
.Bl -enum -offset indent
|
|
|
|
.It
|
2007-02-17 19:23:08 +03:00
|
|
|
.Fn cpu_switchto
|
2010-04-13 10:05:56 +04:00
|
|
|
does not switch address spaces.
|
|
|
|
.It
|
2007-02-17 19:23:08 +03:00
|
|
|
.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 .
|
2011-06-02 04:58:26 +04:00
|
|
|
If the architecture does non-interlocked adaptive mutex release,
|
|
|
|
.Fn cpu_switchto
|
|
|
|
does an equivalent of
|
2011-06-03 08:33:31 +04:00
|
|
|
.Xr membar_producer 3 ,
|
2011-06-02 04:58:26 +04:00
|
|
|
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
|
2007-02-17 19:23:08 +03:00
|
|
|
.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 .
|
2007-02-17 19:23:08 +03:00
|
|
|
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.
|
2007-02-17 19:23:08 +03:00
|
|
|
.It Fa newlwp
|
2010-04-13 10:05:56 +04:00
|
|
|
Specify the
|
|
|
|
.Tn LWP
|
|
|
|
to which to switch.
|
2007-02-17 19:23:08 +03:00
|
|
|
It must not be
|
|
|
|
.Dv NULL .
|
2008-01-25 02:06:10 +03:00
|
|
|
.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
|
2008-01-25 02:06:10 +03:00
|
|
|
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
|
2008-01-25 02:06:10 +03:00
|
|
|
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 .
|
2007-02-17 19:23:08 +03:00
|
|
|
.El
|
|
|
|
.\" ------------------------------------------------------------
|
|
|
|
.Sh RETURN VALUES
|
2010-04-13 10:05:56 +04:00
|
|
|
The
|
2007-02-17 19:23:08 +03:00
|
|
|
.Fn cpu_switchto
|
2010-04-13 10:05:56 +04:00
|
|
|
function does not return until another
|
|
|
|
.Tn LWP
|
|
|
|
calls
|
|
|
|
.Fn cpu_switchto .
|
2007-05-21 06:30:47 +04:00
|
|
|
It returns the
|
2010-04-13 10:05:56 +04:00
|
|
|
.Vt oldlwp
|
2007-05-21 06:30:47 +04:00
|
|
|
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
|
2007-05-21 06:30:47 +04:00
|
|
|
to switch to us or
|
|
|
|
.Dv NULL
|
2010-04-13 10:05:56 +04:00
|
|
|
in case the
|
|
|
|
.Tn LWP
|
|
|
|
was exiting.
|
2007-02-17 19:23:08 +03:00
|
|
|
.\" ------------------------------------------------------------
|
|
|
|
.Sh SEE ALSO
|
2011-06-03 12:06:54 +04:00
|
|
|
.Xr membar_producer 3 ,
|
2007-02-17 19:23:08 +03:00
|
|
|
.Xr swapcontext 3 ,
|
|
|
|
.Xr intro 9 ,
|
|
|
|
.Xr mutex 9 ,
|
|
|
|
.Xr spl 9
|