xref: /netbsd-src/share/man/man9/cpu_need_resched.9 (revision e1ebacd1d35fadbe8b8acbf5d7cfe8216e35fa4a)
1.\"     $NetBSD: cpu_need_resched.9,v 1.10 2019/11/23 19:46:38 ad Exp $
2.\"
3.\" Copyright (c) 2002, 2019 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Gregory McGarry, and Andrew Doran.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd November 17, 2019
31.Dt CPU_NEED_RESCHED 9
32.Os
33.Sh NAME
34.Nm cpu_need_resched
35.Nd context switch notification
36.Sh SYNOPSIS
37.In sys/cpu.h
38.Ft void
39.Fn cpu_need_resched "struct cpu_info *ci" "struct lwp *l" "int flags"
40.Sh DESCRIPTION
41The
42.Fn cpu_need_resched
43function is the machine-independent interface for the scheduler to
44notify machine-dependent code that a context switch from the current
45LWP
46.Fa l ,
47on the cpu
48.Fa ci ,
49is required.
50This event may occur if a higher priority LWP appears on the run
51queue or if the current LWP has exceeded its time slice.
52.Fa l
53is the last LWP observed running on the CPU.
54It may no longer be running, as
55.Fn cpu_need_resched
56can be called without holding scheduler locks.
57.Pp
58If the
59.Dv RESCHED_KPREEMPT
60flag is specified in
61.Fa flags
62and
63.Dv __HAVE_PREEMPTION
64C pre-processor macro is defined in
65.In machine/intr.h ,
66machine-dependent code should make a context switch happen as soon as possible
67even if the CPU is running in kernel mode.
68If the
69.Dv RESCHED_KPREEMPT
70flag is not specified, then
71.Dv RESCHED_UPREEMPT
72is specified instead.
73.Pp
74If the
75.Dv RESCHED_IDLE
76flag is specified in
77.Fa flags ,
78the last thread observed running on the CPU was the idle LWP.
79.Pp
80If
81.Dv RESCHED_REMOTE
82flag is specified in
83.Fa flags ,
84the request is not for the current CPU.
85The opposite also holds true.
86If
87.Fa ci
88is not the current processor,
89.Fn cpu_need_resched
90typically issues an inter processor call to the processor to make it
91notice the need of a context switch as soon as possible.
92.Pp
93.Fn cpu_need_resched
94is always called with kernel preemption disabled.
95.Pp
96Typically, the
97.Fn cpu_need_resched
98function will perform the following operations:
99.Bl -bullet -offset indent
100.It
101Set a per-processor flag which is checked by
102.Xr userret 9
103when returning to user-mode execution.
104.It
105Post an asynchronous software trap
106.Pq Tn AST .
107.It
108Send an inter processor interrupt to wake up
109.Xr cpu_idle 9
110and/or force an user process across the user/kernel boundary, thus making a
111trip through
112.Fn userret .
113.El
114.Sh SEE ALSO
115.Xr sched_4bsd 9 ,
116.Xr userret 9
117