VirtualBox

source: vbox/trunk/include/iprt/mp.h@ 46636

Last change on this file since 46636 was 46636, checked in by vboxsync, 12 years ago

Completed the RTMpGetCoreCount documentation. If anyone disagrees, they've got the API name wrong!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.0 KB
Line 
1/** @file
2 * IPRT - Multiprocessor.
3 */
4
5/*
6 * Copyright (C) 2008-2010 Oracle Corporation
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
26#ifndef ___iprt_mp_h
27#define ___iprt_mp_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31
32
33RT_C_DECLS_BEGIN
34
35/** @defgroup grp_rt_mp RTMp - Multiprocessor
36 * @ingroup grp_rt
37 * @{
38 */
39
40/**
41 * Gets the identifier of the CPU executing the call.
42 *
43 * When called from a system mode where scheduling is active, like ring-3 or
44 * kernel mode with interrupts enabled on some systems, no assumptions should
45 * be made about the current CPU when the call returns.
46 *
47 * @returns CPU Id.
48 */
49RTDECL(RTCPUID) RTMpCpuId(void);
50
51/**
52 * Converts a CPU identifier to a CPU set index.
53 *
54 * This may or may not validate the presence of the CPU.
55 *
56 * @returns The CPU set index on success, -1 on failure.
57 * @param idCpu The identifier of the CPU.
58 */
59RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu);
60
61/**
62 * Converts a CPU set index to a a CPU identifier.
63 *
64 * This may or may not validate the presence of the CPU, so, use
65 * RTMpIsCpuPossible for that.
66 *
67 * @returns The corresponding CPU identifier, NIL_RTCPUID on failure.
68 * @param iCpu The CPU set index.
69 */
70RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu);
71
72/**
73 * Gets the max CPU identifier (inclusive).
74 *
75 * Intended for brute force enumerations, but use with
76 * care as it may be expensive.
77 *
78 * @returns The current higest CPU identifier value.
79 */
80RTDECL(RTCPUID) RTMpGetMaxCpuId(void);
81
82/**
83 * Gets the size of a CPU array that is indexed by CPU set index.
84 *
85 * This takes both online, offline and hot-plugged cpus into account.
86 *
87 * @returns Number of elements.
88 *
89 * @remarks Use RTMpCpuIdToSetIndex to convert a RTCPUID into an array index.
90 */
91RTDECL(uint32_t) RTMpGetArraySize(void);
92
93/**
94 * Checks if a CPU exists in the system or may possibly be hotplugged later.
95 *
96 * @returns true/false accordingly.
97 * @param idCpu The identifier of the CPU.
98 */
99RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu);
100
101/**
102 * Gets set of the CPUs present in the system plus any that may
103 * possibly be hotplugged later.
104 *
105 * @returns pSet.
106 * @param pSet Where to put the set.
107 */
108RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet);
109
110/**
111 * Get the count of CPUs present in the system plus any that may
112 * possibly be hotplugged later.
113 *
114 * @returns The count.
115 * @remarks Don't use this for CPU array sizing, use RTMpGetArraySize instead.
116 */
117RTDECL(RTCPUID) RTMpGetCount(void);
118
119/**
120 * Get the count of physical CPU cores present in the system plus any that may
121 * possibly be hotplugged later.
122 *
123 * @returns The number of cores.
124 */
125RTDECL(RTCPUID) RTMpGetCoreCount(void);
126
127/**
128 * Gets set of the CPUs present that are currently online.
129 *
130 * @returns pSet.
131 * @param pSet Where to put the set.
132 */
133RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet);
134
135/**
136 * Get the count of CPUs that are currently online.
137 *
138 * @return The count.
139 */
140RTDECL(RTCPUID) RTMpGetOnlineCount(void);
141
142/**
143 * Checks if a CPU is online or not.
144 *
145 * @returns true/false accordingly.
146 * @param idCpu The identifier of the CPU.
147 */
148RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu);
149
150
151/**
152 * Gets set of the CPUs present in the system.
153 *
154 * @returns pSet.
155 * @param pSet Where to put the set.
156 */
157RTDECL(PRTCPUSET) RTMpGetPresentSet(PRTCPUSET pSet);
158
159/**
160 * Get the count of CPUs that are present in the system.
161 *
162 * @return The count.
163 */
164RTDECL(RTCPUID) RTMpGetPresentCount(void);
165
166/**
167 * Checks if a CPU is present in the system.
168 *
169 * @returns true/false accordingly.
170 * @param idCpu The identifier of the CPU.
171 */
172RTDECL(bool) RTMpIsCpuPresent(RTCPUID idCpu);
173
174
175/**
176 * Get the current frequency of a CPU.
177 *
178 * The CPU must be online.
179 *
180 * @returns The frequency as MHz. 0 if the CPU is offline
181 * or the information is not available.
182 * @param idCpu The identifier of the CPU.
183 */
184RTDECL(uint32_t) RTMpGetCurFrequency(RTCPUID idCpu);
185
186/**
187 * Get the maximum frequency of a CPU.
188 *
189 * The CPU must be online.
190 *
191 * @returns The frequency as MHz. 0 if the CPU is offline
192 * or the information is not available.
193 * @param idCpu The identifier of the CPU.
194 */
195RTDECL(uint32_t) RTMpGetMaxFrequency(RTCPUID idCpu);
196
197/**
198 * Get the CPU description string.
199 *
200 * The CPU must be online.
201 *
202 * @returns IPRT status code.
203 * @param idCpu The identifier of the CPU.
204 * @param pszBuf The output buffer.
205 * @param cbBuf The size of the output buffer.
206 */
207RTDECL(int) RTMpGetDescription(RTCPUID idCpu, char *pszBuf, size_t cbBuf);
208
209
210#ifdef IN_RING0
211
212/**
213 * Check if there's work (DPCs on Windows) pending on the current CPU.
214 *
215 * @return true if there's pending work on the current CPU, false otherwise.
216 */
217RTDECL(bool) RTMpIsCpuWorkPending(void);
218
219
220/**
221 * Worker function passed to RTMpOnAll, RTMpOnOthers and RTMpOnSpecific that
222 * is to be called on the target cpus.
223 *
224 * @param idCpu The identifier for the CPU the function is called on.
225 * @param pvUser1 The 1st user argument.
226 * @param pvUser2 The 2nd user argument.
227 */
228typedef DECLCALLBACK(void) FNRTMPWORKER(RTCPUID idCpu, void *pvUser1, void *pvUser2);
229/** Pointer to a FNRTMPWORKER. */
230typedef FNRTMPWORKER *PFNRTMPWORKER;
231
232/**
233 * Executes a function on each (online) CPU in the system.
234 *
235 * @returns IPRT status code.
236 * @retval VINF_SUCCESS on success.
237 * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
238 *
239 * @param pfnWorker The worker function.
240 * @param pvUser1 The first user argument for the worker.
241 * @param pvUser2 The second user argument for the worker.
242 *
243 * @remarks The execution isn't in any way guaranteed to be simultaneous,
244 * it might even be serial (cpu by cpu).
245 */
246RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
247
248/**
249 * Executes a function on a all other (online) CPUs in the system.
250 *
251 * The caller must disable preemption prior to calling this API if the outcome
252 * is to make any sense. But do *not* disable interrupts.
253 *
254 * @returns IPRT status code.
255 * @retval VINF_SUCCESS on success.
256 * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
257 *
258 * @param pfnWorker The worker function.
259 * @param pvUser1 The first user argument for the worker.
260 * @param pvUser2 The second user argument for the worker.
261 *
262 * @remarks The execution isn't in any way guaranteed to be simultaneous,
263 * it might even be serial (cpu by cpu).
264 */
265RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
266
267/**
268 * Executes a function on a specific CPU in the system.
269 *
270 * @returns IPRT status code.
271 * @retval VINF_SUCCESS on success.
272 * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
273 * @retval VERR_CPU_OFFLINE if the CPU is offline.
274 * @retval VERR_CPU_NOT_FOUND if the CPU wasn't found.
275 *
276 * @param idCpu The id of the CPU.
277 * @param pfnWorker The worker function.
278 * @param pvUser1 The first user argument for the worker.
279 * @param pvUser2 The second user argument for the worker.
280 */
281RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
282
283/**
284 * Pokes the specified CPU.
285 *
286 * This should cause the execution on the CPU to be interrupted and forcing it
287 * to enter kernel context. It is optimized version of a RTMpOnSpecific call
288 * with a worker which returns immediately.
289 *
290 * @returns IPRT status code.
291 * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the
292 * system. The caller must not automatically assume that this API works
293 * when any of the RTMpOn* APIs works. This is because not all systems
294 * supports unicast MP events and this API will not be implemented as a
295 * broadcast.
296 * @retval VERR_CPU_OFFLINE if the CPU is offline.
297 * @retval VERR_CPU_NOT_FOUND if the CPU wasn't found.
298 *
299 * @param idCpu The id of the CPU to poke.
300 */
301RTDECL(int) RTMpPokeCpu(RTCPUID idCpu);
302
303
304/**
305 * MP event, see FNRTMPNOTIFICATION.
306 */
307typedef enum RTMPEVENT
308{
309 /** The CPU goes online. */
310 RTMPEVENT_ONLINE = 1,
311 /** The CPU goes offline. */
312 RTMPEVENT_OFFLINE
313} RTMPEVENT;
314
315/**
316 * Notification callback.
317 *
318 * The context this is called in differs a bit from platform to
319 * platform, so be careful while in here.
320 *
321 * @param idCpu The CPU this applies to.
322 * @param enmEvent The event.
323 * @param pvUser The user argument.
324 */
325typedef DECLCALLBACK(void) FNRTMPNOTIFICATION(RTMPEVENT enmEvent, RTCPUID idCpu, void *pvUser);
326/** Pointer to a FNRTMPNOTIFICATION(). */
327typedef FNRTMPNOTIFICATION *PFNRTMPNOTIFICATION;
328
329/**
330 * Registers a notification callback for cpu events.
331 *
332 * On platforms which doesn't do cpu offline/online events this API
333 * will just be a no-op that pretends to work.
334 *
335 * @todo We'll be adding a flag to this soon to indicate whether the callback should be called on all
336 * CPUs that are currently online while it's being registered. This is to help avoid some race
337 * conditions (we'll hopefully be able to implement this on linux, solaris/win is no issue).
338 *
339 * @returns IPRT status code.
340 * @retval VINF_SUCCESS on success.
341 * @retval VERR_NO_MEMORY if a registration record cannot be allocated.
342 * @retval VERR_ALREADY_EXISTS if the pfnCallback and pvUser already exist
343 * in the callback list.
344 *
345 * @param pfnCallback The callback.
346 * @param pvUser The user argument to the callback function.
347 */
348RTDECL(int) RTMpNotificationRegister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser);
349
350/**
351 * This deregisters a notification callback registered via RTMpNotificationRegister().
352 *
353 * The pfnCallback and pvUser arguments must be identical to the registration call
354 * of we won't find the right entry.
355 *
356 * @returns IPRT status code.
357 * @retval VINF_SUCCESS on success.
358 * @retval VERR_NOT_FOUND if no matching entry was found.
359 *
360 * @param pfnCallback The callback.
361 * @param pvUser The user argument to the callback function.
362 */
363RTDECL(int) RTMpNotificationDeregister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser);
364
365#endif /* IN_RING0 */
366
367/** @} */
368
369RT_C_DECLS_END
370
371#endif
372
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette