- NetBSD Manual Pages
CPU_SWITCHTO(9) NetBSD Kernel Developer's Manual CPU_SWITCHTO(9)
Powered by man-cgi (2021-06-01).
Maintained for NetBSD
by Kimmo Suominen.
Based on man-cgi by Panagiotis Christias.
cpu_switchto -- machine-dependent LWP context switching interface
cpu_switchto(lwp_t *oldlwp, lwp_t *newlwp, bool returning);
The cpu_switchto() function saves the context of the LWP which is cur-
rently running on the processor, and restores the context of the LWP
specified by newlwp.
1. cpu_switchto() does not switch address spaces.
2. cpu_switchto() sets curlwp(9) to newlwp. If the architecture
does non-interlocked adaptive mutex release, cpu_switchto()
does an equivalent of membar_producer(3), before and after the
modification of curlwp(9).
3. cpu_switchto() should be called at IPL_SCHED. When the func-
tion returns, the caller should lower the priority level as
soon as possible.
4. cpu_switchto() might be called with spin mutexes held.
The function takes the following arguments.
oldlwp Specify the LWP from which the switch is going to be
made, i.e., the calling LWP. If it was NULL, the con-
text of the LWP currently running on this processor is
newlwp Specify the LWP to which to switch. It must not be
returning Only meaningful if the architecture implements fast
software interrupts. If true, it indicates that oldlwp
is a soft interrupt LWP that is blocking. It is a good
indication that any kind of address space or user
activity can be completely ignored. For example:
ras_lookup(9), cache flushes, TLB wirings, adjusting
lazy FPU state. All that is required is to restore the
register state and stack, and return to the interrupted
The cpu_switchto() function does not return until another LWP calls
cpu_switchto(). It returns the oldlwp argument of the cpu_switchto()
which is called to switch back to our LWP. It is either a LWP which
called cpu_switchto() to switch to us or NULL in case the LWP was exit-
membar_producer(3), swapcontext(3), intro(9), mutex(9), spl(9)
NetBSD 8.1 June 2, 2011 NetBSD 8.1