VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/vbi/mp-r0drv-solaris.c@ 22991

最後變更 在這個檔案從22991是 22347,由 vboxsync 提交於 16 年 前

Solaris/mpnotification: Cache CPU set to avoid recursive calls to vbi_cpu_online.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 6.6 KB
 
1/* $Id: mp-r0drv-solaris.c 22347 2009-08-19 14:02:05Z vboxsync $ */
2/** @file
3 * IPRT - Multiprocessor, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2008 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include "the-solaris-kernel.h"
36#include "internal/iprt.h"
37#include <iprt/mp.h>
38
39#include <iprt/asm.h>
40#include <iprt/err.h>
41#include "internal-r0drv-solaris.h"
42#include "r0drv/mp-r0drv.h"
43
44
45
46RTDECL(bool) RTMpIsCpuWorkPending(void)
47{
48 return false;
49}
50
51
52RTDECL(RTCPUID) RTMpCpuId(void)
53{
54 return vbi_cpu_id();
55}
56
57
58RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu)
59{
60 return idCpu < vbi_cpu_maxcount() ? idCpu : -1;
61}
62
63
64RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
65{
66 return (unsigned)iCpu < vbi_cpu_maxcount() ? iCpu : NIL_RTCPUID;
67}
68
69
70RTDECL(RTCPUID) RTMpGetMaxCpuId(void)
71{
72 return vbi_max_cpu_id();
73}
74
75
76RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
77{
78 /*
79 * We cannot query CPU status recursively, check cpu member from cached set.
80 */
81 if (idCpu >= vbi_cpu_count())
82 return false;
83
84 return RTCpuSetIsMember(&g_rtMpSolarisCpuSet, idCpu);
85
86#if 0
87 return idCpu < vbi_cpu_count() && vbi_cpu_online(idCpu);
88#endif
89}
90
91
92RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu)
93{
94 return idCpu < vbi_cpu_count();
95}
96
97
98RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
99{
100 RTCPUID idCpu;
101
102 RTCpuSetEmpty(pSet);
103 idCpu = RTMpGetMaxCpuId(); /* it's inclusive */
104 do
105 {
106 if (RTMpIsCpuPossible(idCpu))
107 RTCpuSetAdd(pSet, idCpu);
108 } while (idCpu-- > 0);
109
110 return pSet;
111}
112
113
114RTDECL(RTCPUID) RTMpGetCount(void)
115{
116 return vbi_cpu_count();
117}
118
119
120RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet)
121{
122 /*
123 * We cannot query CPU status recursively, return the cached set.
124 */
125 *pSet = g_rtMpSolarisCpuSet;
126 return pSet;
127
128#if 0
129 RTCPUID idCpu;
130
131 RTCpuSetEmpty(pSet);
132 idCpu = RTMpGetMaxCpuId(); /* it's inclusive */
133 do
134 {
135 if (RTMpIsCpuOnline(idCpu))
136 RTCpuSetAdd(pSet, idCpu);
137 } while (idCpu-- > 0);
138
139 return pSet;
140#endif
141}
142
143
144RTDECL(RTCPUID) RTMpGetOnlineCount(void)
145{
146 RTCPUSET Set;
147 RTMpGetOnlineSet(&Set);
148 return RTCpuSetCount(&Set);
149
150#if 0
151 int c;
152 int cnt = 0;
153
154 for (c = 0; c < vbi_cpu_count(); ++c)
155 {
156 if (vbi_cpu_online(c))
157 ++cnt;
158 }
159 return cnt;
160#endif
161}
162
163
164
165/**
166 * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
167 * for the RTMpOnAll API.
168 *
169 * @param uArgs Pointer to the RTMPARGS package.
170 * @param uIgnored1 Ignored.
171 * @param uIgnored2 Ignored.
172 */
173static int rtmpOnAllSolarisWrapper(void *uArg, void *uIgnored1, void *uIgnored2)
174{
175 PRTMPARGS pArgs = (PRTMPARGS)(uArg);
176
177 pArgs->pfnWorker(RTMpCpuId(), pArgs->pvUser1, pArgs->pvUser2);
178
179 NOREF(uIgnored1);
180 NOREF(uIgnored2);
181 return 0;
182}
183
184
185RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
186{
187 RTMPARGS Args;
188 RT_ASSERT_INTS_ON();
189
190 Args.pfnWorker = pfnWorker;
191 Args.pvUser1 = pvUser1;
192 Args.pvUser2 = pvUser2;
193 Args.idCpu = NIL_RTCPUID;
194 Args.cHits = 0;
195
196 vbi_preempt_disable();
197
198 vbi_execute_on_all(rtmpOnAllSolarisWrapper, &Args);
199
200 vbi_preempt_enable();
201
202 return VINF_SUCCESS;
203}
204
205
206/**
207 * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
208 * for the RTMpOnOthers API.
209 *
210 * @param uArgs Pointer to the RTMPARGS package.
211 * @param uIgnored1 Ignored.
212 * @param uIgnored2 Ignored.
213 */
214static int rtmpOnOthersSolarisWrapper(void *uArg, void *uIgnored1, void *uIgnored2)
215{
216 PRTMPARGS pArgs = (PRTMPARGS)(uArg);
217 RTCPUID idCpu = RTMpCpuId();
218
219 Assert(idCpu != pArgs->idCpu);
220 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
221
222 NOREF(uIgnored1);
223 NOREF(uIgnored2);
224 return 0;
225}
226
227
228RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
229{
230 int rc;
231 RTMPARGS Args;
232 RT_ASSERT_INTS_ON();
233
234 /* The caller is supposed to have disabled preemption, but take no chances. */
235 vbi_preempt_disable();
236
237 Args.pfnWorker = pfnWorker;
238 Args.pvUser1 = pvUser1;
239 Args.pvUser2 = pvUser2;
240 Args.idCpu = RTMpCpuId();
241 Args.cHits = 0;
242
243 vbi_execute_on_others(rtmpOnOthersSolarisWrapper, &Args);
244
245 vbi_preempt_enable();
246
247 return VINF_SUCCESS;
248}
249
250
251/**
252 * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
253 * for the RTMpOnSpecific API.
254 *
255 *
256 * @param uArgs Pointer to the RTMPARGS package.
257 * @param uIgnored1 Ignored.
258 * @param uIgnored2 Ignored.
259 */
260static int rtmpOnSpecificSolarisWrapper(void *uArg, void *uIgnored1, void *uIgnored2)
261{
262 PRTMPARGS pArgs = (PRTMPARGS)(uArg);
263 RTCPUID idCpu = RTMpCpuId();
264
265 Assert(idCpu == pArgs->idCpu);
266 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
267 ASMAtomicIncU32(&pArgs->cHits);
268
269 NOREF(uIgnored1);
270 NOREF(uIgnored2);
271 return 0;
272}
273
274
275RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
276{
277 int rc;
278 RTMPARGS Args;
279 RT_ASSERT_INTS_ON();
280
281 if (idCpu >= vbi_cpu_count())
282 return VERR_CPU_NOT_FOUND;
283
284 Args.pfnWorker = pfnWorker;
285 Args.pvUser1 = pvUser1;
286 Args.pvUser2 = pvUser2;
287 Args.idCpu = idCpu;
288 Args.cHits = 0;
289
290 vbi_preempt_disable();
291
292 vbi_execute_on_one(rtmpOnSpecificSolarisWrapper, &Args, idCpu);
293
294 vbi_preempt_enable();
295
296 Assert(ASMAtomicUoReadU32(&Args.cHits) <= 1);
297
298 return ASMAtomicUoReadU32(&Args.cHits) == 1
299 ? VINF_SUCCESS
300 : VERR_CPU_NOT_FOUND;
301}
302
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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