VirtualBox

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

Last change on this file since 7340 was 7330, checked in by vboxsync, 17 years ago

RTMpGetMaxCpuId

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/** @file
2 * innotek Portable Runtime - Multiprocessor.
3 */
4
5/*
6 * Copyright (C) 2008 innotek GmbH
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
33__BEGIN_DECLS
34
35/** @defgroup grp_rt_mp RTMp - Multiprocessor
36 * @ingroup grp_rt
37 * @{
38 */
39
40/** Maximum number of CPUs we support in one system.
41 * @remarks The current limit in Windows (affinity mask)
42 */
43#define RT_MP_MAX_CPU 64
44
45
46/**
47 * Gets the identifier of the CPU executing the call.
48 *
49 * When called from a system mode where scheduling is active, like ring-3 or
50 * kernel mode with interrupts enabled on some systems, no assumptions should
51 * be made about the current CPU when the call returns.
52 *
53 * @returns CPU Id.
54 */
55RTDECL(RTCPUID) RTMpCpuId(void);
56
57/**
58 * Checks if a CPU is online or not.
59 *
60 * @returns true/false accordingly.
61 * @param idCpu The identifier of the CPU.
62 */
63RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu);
64
65/**
66 * Checks if a CPU exist or not / validates a CPU id.
67 *
68 * @returns true/false accordingly.
69 * @param idCpu The identifier of the CPU.
70 */
71RTDECL(bool) RTMpDoesCpuExist(RTCPUID idCpu);
72
73/**
74 * Converts a CPU identifier to a CPU set index.
75 *
76 * This may or may not validate the precense of the CPU.
77 *
78 * @returns The CPU set index on success, -1 on failure.
79 * @param idCpu The identifier of the CPU.
80 */
81RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu);
82
83/**
84 * Converts a CPU set index to a a CPU identifier.
85 *
86 * This may or may not validate the precense of the CPU, so, use
87 * RTMpDoesCpuExist for that.
88 *
89 * @returns The corresponding CPU identifier, NIL_RTCPUID on failure.
90 * @param iCpu The CPU set index.
91 */
92RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu);
93
94/**
95 * Gets the max CPU identifier (inclusive).
96 *
97 * Inteded for brute force enumerations, but use with
98 * care as it may be expensive.
99 *
100 * @returns The current higest CPU identifier value.
101 */
102RTDECL(RTCPUID) RTMpGetMaxCpuId(void);
103
104/**
105 * Gets set of the CPUs present in the system.
106 *
107 * This may or may not validate the precense of the CPU, so, use
108 * RTMpDoesCpuExist for that.
109 *
110 * @returns pSet.
111 * @param pSet Where to put the set.
112 */
113RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet);
114
115/**
116 * Get the count of CPUs presetn in the system.
117 *
118 * @return The count.
119 */
120RTDECL(RTCPUID) RTMpGetCount(void);
121
122/**
123 * Gets set of the CPUs present that are currently online.
124 *
125 * @returns pSet.
126 * @param pSet Where to put the set.
127 */
128RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet);
129
130/**
131 * Get the count of CPUs that are currently online.
132 *
133 * @return The count.
134 */
135RTDECL(RTCPUID) RTMpGetOnlineCount(void);
136
137
138#ifdef IN_RING0
139
140/**
141 * Worker function passed to RTMpOnAll, RTMpOnOthers and RTMpOnSpecific that
142 * is to be called on the target cpus.
143 *
144 * @param idCpu The identifier for the CPU the function is called on.
145 * @param pvUser1 The 1st user argument.
146 * @param pvUser2 The 2nd user argument.
147 */
148typedef DECLCALLBACK(void) FNRTMPWORKER(RTCPUID idCpu, void *pvUser1, void *pvUser2);
149/** Pointer to a FNRTMPWORKER. */
150typedef FNRTMPWORKER *PFNRTMPWORKER;
151
152/**
153 * Executes a function on each (online) CPU in the system.
154 *
155 * @returns IPRT status code.
156 * @retval VINF_SUCCESS on success.
157 * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
158 *
159 * @param pfnWorker The worker function.
160 * @param pvUser1 The first user argument for the worker.
161 * @param pvUser2 The second user argument for the worker.
162 *
163 * @remarks The execution isn't in any way guaranteed to be simultaneous,
164 * it might even be serial (cpu by cpu).
165 */
166RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
167
168/**
169 * Executes a function on a all other (online) CPUs in the system.
170 *
171 * @returns IPRT status code.
172 * @retval VINF_SUCCESS on success.
173 * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
174 *
175 * @param pfnWorker The worker function.
176 * @param pvUser1 The first user argument for the worker.
177 * @param pvUser2 The second user argument for the worker.
178 *
179 * @remarks The execution isn't in any way guaranteed to be simultaneous,
180 * it might even be serial (cpu by cpu).
181 */
182RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
183
184/**
185 * Executes a function on a specific CPU in the system.
186 *
187 * @returns IPRT status code.
188 * @retval VINF_SUCCESS on success.
189 * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
190 * @retval VERR_CPU_OFFLINE if the CPU is offline.
191 * @retval VERR_CPU_NOT_FOUND if the CPU wasn't found.
192 *
193 * @param idCpu The id of the CPU.
194 * @param pfnWorker The worker function.
195 * @param pvUser1 The first user argument for the worker.
196 * @param pvUser2 The second user argument for the worker.
197 */
198RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
199
200#endif /* IN_RING0 */
201
202/** @} */
203
204__END_DECLS
205
206#endif
207
Note: See TracBrowser for help on using the repository browser.

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