1 | /** @file
|
---|
2 | * IPRT - Multiprocessor.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2008 Sun Microsystems, Inc.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | *
|
---|
25 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ___iprt_mp_h
|
---|
31 | #define ___iprt_mp_h
|
---|
32 |
|
---|
33 | #include <iprt/cdefs.h>
|
---|
34 | #include <iprt/types.h>
|
---|
35 |
|
---|
36 |
|
---|
37 | __BEGIN_DECLS
|
---|
38 |
|
---|
39 | /** @defgroup grp_rt_mp RTMp - Multiprocessor
|
---|
40 | * @ingroup grp_rt
|
---|
41 | * @{
|
---|
42 | */
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Gets the identifier of the CPU executing the call.
|
---|
46 | *
|
---|
47 | * When called from a system mode where scheduling is active, like ring-3 or
|
---|
48 | * kernel mode with interrupts enabled on some systems, no assumptions should
|
---|
49 | * be made about the current CPU when the call returns.
|
---|
50 | *
|
---|
51 | * @returns CPU Id.
|
---|
52 | */
|
---|
53 | RTDECL(RTCPUID) RTMpCpuId(void);
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Converts a CPU identifier to a CPU set index.
|
---|
57 | *
|
---|
58 | * This may or may not validate the precense of the CPU.
|
---|
59 | *
|
---|
60 | * @returns The CPU set index on success, -1 on failure.
|
---|
61 | * @param idCpu The identifier of the CPU.
|
---|
62 | */
|
---|
63 | RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu);
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Converts a CPU set index to a a CPU identifier.
|
---|
67 | *
|
---|
68 | * This may or may not validate the precense of the CPU, so, use
|
---|
69 | * RTMpDoesCpuExist for that.
|
---|
70 | *
|
---|
71 | * @returns The corresponding CPU identifier, NIL_RTCPUID on failure.
|
---|
72 | * @param iCpu The CPU set index.
|
---|
73 | */
|
---|
74 | RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu);
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Gets the max CPU identifier (inclusive).
|
---|
78 | *
|
---|
79 | * Inteded for brute force enumerations, but use with
|
---|
80 | * care as it may be expensive.
|
---|
81 | *
|
---|
82 | * @returns The current higest CPU identifier value.
|
---|
83 | */
|
---|
84 | RTDECL(RTCPUID) RTMpGetMaxCpuId(void);
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Checks if a CPU is online or not.
|
---|
88 | *
|
---|
89 | * @returns true/false accordingly.
|
---|
90 | * @param idCpu The identifier of the CPU.
|
---|
91 | */
|
---|
92 | RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu);
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Checks if a CPU exist or not / validates a CPU id.
|
---|
96 | *
|
---|
97 | * @returns true/false accordingly.
|
---|
98 | * @param idCpu The identifier of the CPU.
|
---|
99 | */
|
---|
100 | RTDECL(bool) RTMpDoesCpuExist(RTCPUID idCpu);
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Gets set of the CPUs present in the system.
|
---|
104 | *
|
---|
105 | * This may or may not validate the precense of the CPU, so, use
|
---|
106 | * RTMpDoesCpuExist for that.
|
---|
107 | *
|
---|
108 | * @returns pSet.
|
---|
109 | * @param pSet Where to put the set.
|
---|
110 | */
|
---|
111 | RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet);
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Get the count of CPUs presetn in the system.
|
---|
115 | *
|
---|
116 | * @return The count.
|
---|
117 | */
|
---|
118 | RTDECL(RTCPUID) RTMpGetCount(void);
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Gets set of the CPUs present that are currently online.
|
---|
122 | *
|
---|
123 | * @returns pSet.
|
---|
124 | * @param pSet Where to put the set.
|
---|
125 | */
|
---|
126 | RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet);
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Get the count of CPUs that are currently online.
|
---|
130 | *
|
---|
131 | * @return The count.
|
---|
132 | */
|
---|
133 | RTDECL(RTCPUID) RTMpGetOnlineCount(void);
|
---|
134 |
|
---|
135 |
|
---|
136 | #ifdef IN_RING0
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Worker function passed to RTMpOnAll, RTMpOnOthers and RTMpOnSpecific that
|
---|
140 | * is to be called on the target cpus.
|
---|
141 | *
|
---|
142 | * @param idCpu The identifier for the CPU the function is called on.
|
---|
143 | * @param pvUser1 The 1st user argument.
|
---|
144 | * @param pvUser2 The 2nd user argument.
|
---|
145 | */
|
---|
146 | typedef DECLCALLBACK(void) FNRTMPWORKER(RTCPUID idCpu, void *pvUser1, void *pvUser2);
|
---|
147 | /** Pointer to a FNRTMPWORKER. */
|
---|
148 | typedef FNRTMPWORKER *PFNRTMPWORKER;
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Executes a function on each (online) CPU in the system.
|
---|
152 | *
|
---|
153 | * @returns IPRT status code.
|
---|
154 | * @retval VINF_SUCCESS on success.
|
---|
155 | * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
|
---|
156 | *
|
---|
157 | * @param pfnWorker The worker function.
|
---|
158 | * @param pvUser1 The first user argument for the worker.
|
---|
159 | * @param pvUser2 The second user argument for the worker.
|
---|
160 | *
|
---|
161 | * @remarks The execution isn't in any way guaranteed to be simultaneous,
|
---|
162 | * it might even be serial (cpu by cpu).
|
---|
163 | */
|
---|
164 | RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Executes a function on a all other (online) CPUs in the system.
|
---|
168 | *
|
---|
169 | * @returns IPRT status code.
|
---|
170 | * @retval VINF_SUCCESS on success.
|
---|
171 | * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
|
---|
172 | *
|
---|
173 | * @param pfnWorker The worker function.
|
---|
174 | * @param pvUser1 The first user argument for the worker.
|
---|
175 | * @param pvUser2 The second user argument for the worker.
|
---|
176 | *
|
---|
177 | * @remarks The execution isn't in any way guaranteed to be simultaneous,
|
---|
178 | * it might even be serial (cpu by cpu).
|
---|
179 | */
|
---|
180 | RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Executes a function on a specific CPU in the system.
|
---|
184 | *
|
---|
185 | * @returns IPRT status code.
|
---|
186 | * @retval VINF_SUCCESS on success.
|
---|
187 | * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
|
---|
188 | * @retval VERR_CPU_OFFLINE if the CPU is offline.
|
---|
189 | * @retval VERR_CPU_NOT_FOUND if the CPU wasn't found.
|
---|
190 | *
|
---|
191 | * @param idCpu The id of the CPU.
|
---|
192 | * @param pfnWorker The worker function.
|
---|
193 | * @param pvUser1 The first user argument for the worker.
|
---|
194 | * @param pvUser2 The second user argument for the worker.
|
---|
195 | */
|
---|
196 | RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
|
---|
197 |
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * MP event, see FNRTMPNOTIFICATION.
|
---|
201 | */
|
---|
202 | typedef enum RTMPEVENT
|
---|
203 | {
|
---|
204 | /** The CPU goes online. */
|
---|
205 | RTMPEVENT_ONLINE = 1,
|
---|
206 | /** The CPU goes offline. */
|
---|
207 | RTMPEVENT_OFFLINE
|
---|
208 | } RTMPEVENT;
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Notification callback.
|
---|
212 | *
|
---|
213 | * The context this is called in differs a bit from platform to
|
---|
214 | * platform, so be careful while in here.
|
---|
215 | *
|
---|
216 | * @param idCpu The CPU this applies to.
|
---|
217 | * @param enmEvent The event.
|
---|
218 | * @param pvUser The user argument.
|
---|
219 | */
|
---|
220 | typedef DECLCALLBACK(void) FNRTMPNOTIFICATION(RTMPEVENT enmEvent, RTCPUID idCpu, void *pvUser);
|
---|
221 | /** Pointer to a FNRTMPNOTIFICATION(). */
|
---|
222 | typedef FNRTMPNOTIFICATION *PFNRTMPNOTIFICATION;
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Registers a notification callback for cpu events.
|
---|
226 | *
|
---|
227 | * On platforms which doesn't do cpu offline/online events this API
|
---|
228 | * will just be a no-op that pretends to work.
|
---|
229 | *
|
---|
230 | * @returns IPRT status code.
|
---|
231 | * @retval VINF_SUCCESS on success.
|
---|
232 | * @retval VERR_NO_MEMORY if a registration record cannot be allocated.
|
---|
233 | * @retval VERR_ALREADY_EXISTS if the pfnCallback and pvUser already exist
|
---|
234 | * in the callback list.
|
---|
235 | *
|
---|
236 | * @param pfnCallback The callback.
|
---|
237 | * @param pvUser The user argument to the callback function.
|
---|
238 | */
|
---|
239 | RTDECL(int) RTMpNotificationRegister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser);
|
---|
240 |
|
---|
241 | /**
|
---|
242 | * This deregisters a notification callback registered via RTMpNotificationRegister().
|
---|
243 | *
|
---|
244 | * The pfnCallback and pvUser arguments must be identical to the registration call
|
---|
245 | * of we won't find the right entry.
|
---|
246 | *
|
---|
247 | * @returns IPRT status code.
|
---|
248 | * @retval VINF_SUCCESS on success.
|
---|
249 | * @retval VERR_NOT_FOUND if no matching entry was found.
|
---|
250 | *
|
---|
251 | * @param pfnCallback The callback.
|
---|
252 | * @param pvUser The user argument to the callback function.
|
---|
253 | */
|
---|
254 | RTDECL(int) RTMpNotificationDeregister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser);
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * Initializes the multiprocessor event notifcations.
|
---|
258 | *
|
---|
259 | * This must be called before calling RTMpNotificationRegister(). This is an
|
---|
260 | * inconvenice caused Visual C++ not implmenting weak externals.
|
---|
261 | *
|
---|
262 | * @returns IPRT status code.
|
---|
263 | * @param pvOS Reserved, pass NULL.
|
---|
264 | */
|
---|
265 | RTR0DECL(int) RTR0MpNotificationInit(void *pvOS);
|
---|
266 |
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * Terminates the multiprocessor event notifcations.
|
---|
270 | *
|
---|
271 | * The number of RTR0MpNotificationInit calls must match the calls to this
|
---|
272 | * function exactly.
|
---|
273 | *
|
---|
274 | * @returns IPRT status code.
|
---|
275 | * @param pvOS Reserved, pass NULL.
|
---|
276 | */
|
---|
277 | RTR0DECL(void) RTR0MpNotificationTerm(void *pvOS);
|
---|
278 |
|
---|
279 | #endif /* IN_RING0 */
|
---|
280 |
|
---|
281 | /** @} */
|
---|
282 |
|
---|
283 | __END_DECLS
|
---|
284 |
|
---|
285 | #endif
|
---|
286 |
|
---|