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 presence 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 presence of the CPU, so, use
|
---|
69 | * RTMpIsCpuPossible 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 | /**
|
---|
88 | * Checks if a CPU exists in the system or may possibly be hotplugged later.
|
---|
89 | *
|
---|
90 | * @returns true/false accordingly.
|
---|
91 | * @param idCpu The identifier of the CPU.
|
---|
92 | */
|
---|
93 | RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu);
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Gets set of the CPUs present in the system pluss any that may
|
---|
97 | * possibly be hotplugged later.
|
---|
98 | *
|
---|
99 | * @returns pSet.
|
---|
100 | * @param pSet Where to put the set.
|
---|
101 | */
|
---|
102 | RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet);
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Get the count of CPUs present in the system plus any that may
|
---|
106 | * possibly be hotplugged later.
|
---|
107 | *
|
---|
108 | * @return The count.
|
---|
109 | */
|
---|
110 | RTDECL(RTCPUID) RTMpGetCount(void);
|
---|
111 |
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Gets set of the CPUs present that are currently online.
|
---|
115 | *
|
---|
116 | * @returns pSet.
|
---|
117 | * @param pSet Where to put the set.
|
---|
118 | */
|
---|
119 | RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet);
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Get the count of CPUs that are currently online.
|
---|
123 | *
|
---|
124 | * @return The count.
|
---|
125 | */
|
---|
126 | RTDECL(RTCPUID) RTMpGetOnlineCount(void);
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Checks if a CPU is online or not.
|
---|
130 | *
|
---|
131 | * @returns true/false accordingly.
|
---|
132 | * @param idCpu The identifier of the CPU.
|
---|
133 | */
|
---|
134 | RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu);
|
---|
135 |
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * Gets set of the CPUs present in the system.
|
---|
139 | *
|
---|
140 | * @returns pSet.
|
---|
141 | * @param pSet Where to put the set.
|
---|
142 | */
|
---|
143 | RTDECL(PRTCPUSET) RTMpGetPresentSet(PRTCPUSET pSet);
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Get the count of CPUs that are present in the system.
|
---|
147 | *
|
---|
148 | * @return The count.
|
---|
149 | */
|
---|
150 | RTDECL(RTCPUID) RTMpGetPresentCount(void);
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Checks if a CPU is present in the system.
|
---|
154 | *
|
---|
155 | * @returns true/false accordingly.
|
---|
156 | * @param idCpu The identifier of the CPU.
|
---|
157 | */
|
---|
158 | RTDECL(bool) RTMpIsCpuPresent(RTCPUID idCpu);
|
---|
159 |
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Get the current frequency of a CPU.
|
---|
163 | *
|
---|
164 | * The CPU must be online.
|
---|
165 | *
|
---|
166 | * @returns The frequency as MHz. 0 if the CPU is offline
|
---|
167 | * or the information is not available.
|
---|
168 | * @param idCpu The identifier of the CPU.
|
---|
169 | */
|
---|
170 | RTDECL(uint32_t) RTMpGetCurFrequency(RTCPUID idCpu);
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * Get the maximum frequency of a CPU.
|
---|
174 | *
|
---|
175 | * The CPU must be online.
|
---|
176 | *
|
---|
177 | * @returns The frequency as MHz. 0 if the CPU is offline
|
---|
178 | * or the information is not available.
|
---|
179 | * @param idCpu The identifier of the CPU.
|
---|
180 | */
|
---|
181 | RTDECL(uint32_t) RTMpGetMaxFrequency(RTCPUID idCpu);
|
---|
182 |
|
---|
183 |
|
---|
184 | #ifdef IN_RING0
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Check if there's work (DPCs on Windows) pending on the current CPU.
|
---|
188 | *
|
---|
189 | * @return true if there's pending work on the current CPU, false otherwise.
|
---|
190 | */
|
---|
191 | RTDECL(bool) RTMpIsCpuWorkPending(void);
|
---|
192 |
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Worker function passed to RTMpOnAll, RTMpOnOthers and RTMpOnSpecific that
|
---|
196 | * is to be called on the target cpus.
|
---|
197 | *
|
---|
198 | * @param idCpu The identifier for the CPU the function is called on.
|
---|
199 | * @param pvUser1 The 1st user argument.
|
---|
200 | * @param pvUser2 The 2nd user argument.
|
---|
201 | */
|
---|
202 | typedef DECLCALLBACK(void) FNRTMPWORKER(RTCPUID idCpu, void *pvUser1, void *pvUser2);
|
---|
203 | /** Pointer to a FNRTMPWORKER. */
|
---|
204 | typedef FNRTMPWORKER *PFNRTMPWORKER;
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Executes a function on each (online) CPU in the system.
|
---|
208 | *
|
---|
209 | * @returns IPRT status code.
|
---|
210 | * @retval VINF_SUCCESS on success.
|
---|
211 | * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
|
---|
212 | *
|
---|
213 | * @param pfnWorker The worker function.
|
---|
214 | * @param pvUser1 The first user argument for the worker.
|
---|
215 | * @param pvUser2 The second user argument for the worker.
|
---|
216 | *
|
---|
217 | * @remarks The execution isn't in any way guaranteed to be simultaneous,
|
---|
218 | * it might even be serial (cpu by cpu).
|
---|
219 | */
|
---|
220 | RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
|
---|
221 |
|
---|
222 | /**
|
---|
223 | * Executes a function on a all other (online) CPUs in the system.
|
---|
224 | *
|
---|
225 | * The caller must disable preemption prior to calling this API if the outcome
|
---|
226 | * is to make any sense. But do *not* disable interrupts.
|
---|
227 | *
|
---|
228 | * @returns IPRT status code.
|
---|
229 | * @retval VINF_SUCCESS on success.
|
---|
230 | * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
|
---|
231 | *
|
---|
232 | * @param pfnWorker The worker function.
|
---|
233 | * @param pvUser1 The first user argument for the worker.
|
---|
234 | * @param pvUser2 The second user argument for the worker.
|
---|
235 | *
|
---|
236 | * @remarks The execution isn't in any way guaranteed to be simultaneous,
|
---|
237 | * it might even be serial (cpu by cpu).
|
---|
238 | */
|
---|
239 | RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
|
---|
240 |
|
---|
241 | /**
|
---|
242 | * Executes a function on a specific CPU in the system.
|
---|
243 | *
|
---|
244 | * @returns IPRT status code.
|
---|
245 | * @retval VINF_SUCCESS on success.
|
---|
246 | * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
|
---|
247 | * @retval VERR_CPU_OFFLINE if the CPU is offline.
|
---|
248 | * @retval VERR_CPU_NOT_FOUND if the CPU wasn't found.
|
---|
249 | *
|
---|
250 | * @param idCpu The id of the CPU.
|
---|
251 | * @param pfnWorker The worker function.
|
---|
252 | * @param pvUser1 The first user argument for the worker.
|
---|
253 | * @param pvUser2 The second user argument for the worker.
|
---|
254 | */
|
---|
255 | RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
|
---|
256 |
|
---|
257 | /**
|
---|
258 | * Pokes the specified CPU.
|
---|
259 | *
|
---|
260 | * This should cause the execution on the CPU to be interrupted and forcing it
|
---|
261 | * to enter kernel context. It is optimized version of a RTMpOnSpecific call
|
---|
262 | * with a worker which returns immediately.
|
---|
263 | *
|
---|
264 | * @returns IPRT status code.
|
---|
265 | * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the
|
---|
266 | * system. The caller must not automatically assume that this API works
|
---|
267 | * when any of the RTMpOn* APIs works. This is because not all systems
|
---|
268 | * supports unicast MP events and this API will not be implemented as a
|
---|
269 | * broadcast.
|
---|
270 | * @retval VERR_CPU_OFFLINE if the CPU is offline.
|
---|
271 | * @retval VERR_CPU_NOT_FOUND if the CPU wasn't found.
|
---|
272 | *
|
---|
273 | * @param idCpu The id of the CPU to poke.
|
---|
274 | */
|
---|
275 | RTDECL(int) RTMpPokeCpu(RTCPUID idCpu);
|
---|
276 |
|
---|
277 |
|
---|
278 | /**
|
---|
279 | * MP event, see FNRTMPNOTIFICATION.
|
---|
280 | */
|
---|
281 | typedef enum RTMPEVENT
|
---|
282 | {
|
---|
283 | /** The CPU goes online. */
|
---|
284 | RTMPEVENT_ONLINE = 1,
|
---|
285 | /** The CPU goes offline. */
|
---|
286 | RTMPEVENT_OFFLINE
|
---|
287 | } RTMPEVENT;
|
---|
288 |
|
---|
289 | /**
|
---|
290 | * Notification callback.
|
---|
291 | *
|
---|
292 | * The context this is called in differs a bit from platform to
|
---|
293 | * platform, so be careful while in here.
|
---|
294 | *
|
---|
295 | * @param idCpu The CPU this applies to.
|
---|
296 | * @param enmEvent The event.
|
---|
297 | * @param pvUser The user argument.
|
---|
298 | */
|
---|
299 | typedef DECLCALLBACK(void) FNRTMPNOTIFICATION(RTMPEVENT enmEvent, RTCPUID idCpu, void *pvUser);
|
---|
300 | /** Pointer to a FNRTMPNOTIFICATION(). */
|
---|
301 | typedef FNRTMPNOTIFICATION *PFNRTMPNOTIFICATION;
|
---|
302 |
|
---|
303 | /**
|
---|
304 | * Registers a notification callback for cpu events.
|
---|
305 | *
|
---|
306 | * On platforms which doesn't do cpu offline/online events this API
|
---|
307 | * will just be a no-op that pretends to work.
|
---|
308 | *
|
---|
309 | * @todo We'll be adding a flag to this soon to indicate whether the callback should be called on all
|
---|
310 | * CPUs that are currently online while it's being registered. This is to help avoid some race
|
---|
311 | * conditions (we'll hopefully be able to implement this on linux, solaris/win is no issue).
|
---|
312 | *
|
---|
313 | * @returns IPRT status code.
|
---|
314 | * @retval VINF_SUCCESS on success.
|
---|
315 | * @retval VERR_NO_MEMORY if a registration record cannot be allocated.
|
---|
316 | * @retval VERR_ALREADY_EXISTS if the pfnCallback and pvUser already exist
|
---|
317 | * in the callback list.
|
---|
318 | *
|
---|
319 | * @param pfnCallback The callback.
|
---|
320 | * @param pvUser The user argument to the callback function.
|
---|
321 | */
|
---|
322 | RTDECL(int) RTMpNotificationRegister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser);
|
---|
323 |
|
---|
324 | /**
|
---|
325 | * This deregisters a notification callback registered via RTMpNotificationRegister().
|
---|
326 | *
|
---|
327 | * The pfnCallback and pvUser arguments must be identical to the registration call
|
---|
328 | * of we won't find the right entry.
|
---|
329 | *
|
---|
330 | * @returns IPRT status code.
|
---|
331 | * @retval VINF_SUCCESS on success.
|
---|
332 | * @retval VERR_NOT_FOUND if no matching entry was found.
|
---|
333 | *
|
---|
334 | * @param pfnCallback The callback.
|
---|
335 | * @param pvUser The user argument to the callback function.
|
---|
336 | */
|
---|
337 | RTDECL(int) RTMpNotificationDeregister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser);
|
---|
338 |
|
---|
339 | #endif /* IN_RING0 */
|
---|
340 |
|
---|
341 | /** @} */
|
---|
342 |
|
---|
343 | __END_DECLS
|
---|
344 |
|
---|
345 | #endif
|
---|
346 |
|
---|