VirtualBox

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

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

RTMpGetSet, RTMpGetCount, RTMpGetOnlineSet, RTMpGetOnlineCount.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 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 * @returns The CPU set index on success, -1 on failure.
77 * @param idCpu The identifier of the CPU.
78 */
79RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu);
80
81/**
82 * Gets set of the CPUs present in the system.
83 *
84 * This set includes CPUs in any state, see RTGetOnlineSet()
85 * for an alternative.
86 *
87 * @returns pSet.
88 * @param pSet Where to put the set.
89 */
90RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet);
91
92/**
93 * Get the count of CPUs presetn in the system.
94 *
95 * @return The count.
96 */
97RTDECL(RTCPUID) RTMpGetCount(void);
98
99/**
100 * Gets set of the CPUs present that are currently online.
101 *
102 * @returns pSet.
103 * @param pSet Where to put the set.
104 */
105RTDECL(void) RTMpGetOnlineSet(PRTCPUSET pSet);
106
107/**
108 * Get the count of CPUs that are currently online.
109 *
110 * @return The count.
111 */
112RTDECL(RTCPUID) RTMpGetOnlineCount(void);
113
114
115#ifdef IN_RING0
116
117/**
118 * Worker function passed to RTMpOnAll, RTMpOnOthers and RTMpOnSpecific that
119 * is to be called on the target cpus.
120 *
121 * @param idCpu The identifier for the CPU the function is called on.
122 * @param pvUser1 The 1st user argument.
123 * @param pvUser2 The 2nd user argument.
124 */
125typedef DECLCALLBACK(void) FNRTMPWORKER(RTCPUID idCpu, void *pvUser1, void *pvUser2);
126/** Pointer to a FNRTMPWORKER. */
127typedef FNRTMPWORKER *PFNRTMPWORKER;
128
129/**
130 * Executes a function on each (online) CPU in the system.
131 *
132 * @returns IPRT status code.
133 * @retval VINF_SUCCESS on success.
134 * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
135 *
136 * @param pfnWorker The worker function.
137 * @param pvUser1 The first user argument for the worker.
138 * @param pvUser2 The second user argument for the worker.
139 *
140 * @remarks The execution isn't in any way guaranteed to be simultaneous,
141 * it might even be serial (cpu by cpu).
142 */
143RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
144
145/**
146 * Executes a function on a all other (online) CPUs in the system.
147 *
148 * @returns IPRT status code.
149 * @retval VINF_SUCCESS on success.
150 * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
151 *
152 * @param pfnWorker The worker function.
153 * @param pvUser1 The first user argument for the worker.
154 * @param pvUser2 The second user argument for the worker.
155 *
156 * @remarks The execution isn't in any way guaranteed to be simultaneous,
157 * it might even be serial (cpu by cpu).
158 */
159RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
160
161/**
162 * Executes a function on a specific CPU in the system.
163 *
164 * @returns IPRT status code.
165 * @retval VINF_SUCCESS on success.
166 * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
167 * @retval VERR_CPU_OFFLINE if the CPU is offline.
168 * @retval VERR_CPU_NOT_FOUND if the CPU wasn't found.
169 *
170 * @param idCpu The id of the CPU.
171 * @param pfnWorker The worker function.
172 * @param pvUser1 The first user argument for the worker.
173 * @param pvUser2 The second user argument for the worker.
174 */
175RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
176
177#endif /* IN_RING0 */
178
179/** @} */
180
181__END_DECLS
182
183#endif
184
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