summaryrefslogtreecommitdiff
path: root/static/netbsd/man9/ipi.9
blob: 9410db4a62f1020b26c62a0795cd298f6d162d5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
.\" $NetBSD: ipi.9,v 1.6 2022/02/12 01:21:11 riastradh Exp $
.\"
.\" Copyright (c) 2014, 2019 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Mindaugas Rasiukevicius.
.\"
.\" 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.
.\"
.Dd March 31, 2019
.Dt IPI 9
.Os
.Sh NAME
.Nm ipi
.Nd machine-independent interprocessor interrupts
.Sh SYNOPSIS
.In sys/ipi.h
.Vt typedef void (*ipi_func_t)(void *);
.\" -----
.Ft u_int
.Fn ipi_register "ipi_func_t func" "void *arg"
.Ft void
.Fn ipi_unregister "u_int ipi_id"
.Ft void
.Fn ipi_trigger "u_int ipi_id" "struct cpu_info *ci"
.Ft void
.Fn ipi_trigger_multi "u_int ipi_id" "const kcpuset_t *target"
.Ft void
.Fn ipi_trigger_broadcast "u_int ipi_id" "bool skip_self"
.\" -----
.Ft void
.Fn ipi_unicast "ipi_msg_t *msg" "struct cpu_info *ci"
.Ft void
.Fn ipi_multicast "ipi_msg_t *msg" "const kcpuset_t *target"
.Ft void
.Fn ipi_broadcast "ipi_msg_t *msg" "bool skip_self"
.Ft void
.Fn ipi_wait "ipi_msg_t *msg"
.\" -----
.Sh DESCRIPTION
The machine-independent
.Nm
interface provides capability to send inter-processor interrupts (IPIs)
amongst CPUs.
The interface has two mechanisms: asynchronous IPI to invoke functions
with a constant argument and synchronous IPIs with the cross-call support.
.Pp
Other synchronization interfaces are built using the MI IPI interface.
For a general purpose inter-processor cross-calls or remote
interrupts, use the
.Xr xcall 9
or
.Xr softint 9
interfaces.
.Pp
The primary use cases of the MI IPIs include the following:
.Bl -hyphen -compact
.It
provide a facility for the
.Xr softint 9
subsystem to schedule software interrupts on remote CPUs
.It
provide a facility for the
.Xr xcall 9
subsystem
.It
abstract IPI handling and facilitate machine-dependent code
.El
.\" -----
.Ss Asynchronous IPI interface
This interface allows dynamic registration of IPI handlers with a constant
argument and asynchronous triggering of interrupts.
.Bl -tag -width compact
.It Fn ipi_register "func" "arg"
Register an IPI handler
.Fa func
with an arbitrary argument
.Fa arg .
Returns a non-zero IPI identifier on success and zero on failure.
.It Fn ipi_unregister "ipi_id"
Unregister the IPI handler identified by the
.Fa ipi_id .
.It Fn ipi_trigger "ipi_id" "ci"
Trigger an IPI identified by
.Fa ipi_id
on a remote CPU specified by
.Fa ci .
This function must be called with kernel preemption disabled and
the target CPU must be remote.
.It Fn ipi_trigger_multi "ipi_id" "target"
Trigger an IPI identified by
.Fa ipi_id
on all of the CPUs in the set specified by
.Fa target .
This function must be called with kernel preemption disabled.
The sending CPU may be included in the CPU set; when this is the case,
the IPI on the sending CPU is processes synchronously.
.It Fn ipi_trigger_broadcast "ipi_id" "skip_self"
Trigger an IPI identified by
.Fa ipi_id
on all of the attached CPUs.
This function must be called with kernel preemption disabled.
Optionally, the sending CPU may be skipped by passing
.Dv true
for
.Fa skip_self .
.El
.\" -----
.Ss Synchronous IPI interface
This interface provides capability to perform cross-calls, i.e. invoke
an arbitrary function on a remote CPU.
The invocations are performed synchronously and the caller must wait
for completion.
The cross-call is described by an IPI "message".
The caller has to fill in an
.Vt ipi_msg_t
structure which has the following public members:
.Bd -literal
        ipi_func_t	func;
        void		arg;
.Ed
.Pp
The
.Ar func
member specifies a function to invoke and
.Ar arg
is the argument to be passed to the function.
.Bl -tag -width compact
.It Fn ipi_unicast "msg" "ci"
Send an IPI to a remote CPU specified by
.Fa ci .
.It Fn ipi_multicast "msg" "target"
Send IPIs to a CPU set specified by
.Fa target .
.It Fn ipi_broadcast "msg" "skip_self"
Send IPIs to all CPUs.
Optionally, the sending CPU may be skipped by passing
.Dv true
for
.Fa skip_self .
.It Fn ipi_wait "msg"
Wait until all IPIs complete.
.El
.Pp
All described functions, except
.Fn ipi_wait ,
must be called with the kernel preemption disabled.
All synchronous IPI invocations must be completed (wait for them with the
.Fn ipi_wait
function) before the IPI message structure can be destroyed or new
cross-call requests can be performed.
.\" -----
.Sh MEMORY ORDER
All memory operations that happen before triggering an IPI, via
.Fn ipi_trigger ,
.Fn ipi_trigger_multi ,
.Fn ipi_trigger_broadcast ,
.Fn ipi_unicast ,
.Fn ipi_multicast ,
or
.Fn ipi_broadcast ,
also happen before any memory operations in the IPI handler function on
the remote CPU.
.Pp
For synchronous IPIs, all memory operations that happen before the IPI
handler function has returned on the remote CPU also happen before
.Fn ipi_wait
returns on the waiting CPU.
.\" -----
.Sh NOTES
Functions being called must be lightweight.
They run at
.Dv IPL_HIGH
and should generally not use any other synchronization interfaces
such as
.Xr mutex 9 .
If spin-locks are used, they must be used carefully and have no contention.
.\" -----
.Sh CODE REFERENCES
The
.Nm
interface is implemented within the file
.Pa sys/kern/subr_ipi.c .
.\" -----
.Sh SEE ALSO
.Xr kcpuset 9 ,
.Xr kpreempt 9 ,
.Xr softint 9 ,
.Xr spl 9 ,
.Xr xcall 9
.Sh HISTORY
The
.Nm
interface first appeared in
.Nx 7.0 .
.Sh AUTHORS
.An Mindaugas Rasiukevicius Aq Mt rmind@NetBSD.org