VirtualBox

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

Last change on this file since 41628 was 40968, checked in by vboxsync, 13 years ago

Runtime/r0drv/solaris: VBI integrate, move files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 KB
Line 
1/* $Id: mp-r0drv-solaris.c 40968 2012-04-17 17:35:53Z vboxsync $ */
2/** @file
3 * IPRT - Multiprocessor, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2008 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.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
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include "the-solaris-kernel.h"
32#include "internal/iprt.h"
33#include <iprt/mp.h>
34#include <iprt/cpuset.h>
35#include <iprt/thread.h>
36
37#include <iprt/asm.h>
38#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
39# include <iprt/asm-amd64-x86.h>
40#endif
41#include <iprt/err.h>
42#include "r0drv/mp-r0drv.h"
43
44typedef int FNRTMPSOLWORKER(void *pvUser1, void *pvUser2, void *pvUser3);
45typedef FNRTMPSOLWORKER *PFNRTMPSOLWORKER;
46
47
48RTDECL(bool) RTMpIsCpuWorkPending(void)
49{
50 return false;
51}
52
53
54RTDECL(RTCPUID) RTMpCpuId(void)
55{
56 return CPU->cpu_id;
57}
58
59
60RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu)
61{
62 return idCpu < RTCPUSET_MAX_CPUS && idCpu <= max_cpuid ? idCpu : -1;
63}
64
65
66RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
67{
68 return (unsigned)iCpu <= max_cpuid ? iCpu : NIL_RTCPUID;
69}
70
71
72RTDECL(RTCPUID) RTMpGetMaxCpuId(void)
73{
74 return max_cpuid;
75}
76
77
78RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
79{
80 /*
81 * We cannot query CPU status recursively, check cpu member from cached set.
82 */
83 if (idCpu >= ncpus)
84 return false;
85
86 return RTCpuSetIsMember(&g_rtMpSolCpuSet, idCpu);
87}
88
89
90RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu)
91{
92 return idCpu < ncpus;
93}
94
95
96RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
97{
98 RTCPUID idCpu;
99
100 RTCpuSetEmpty(pSet);
101 idCpu = RTMpGetMaxCpuId(); /* it's inclusive */
102 do
103 {
104 if (RTMpIsCpuPossible(idCpu))
105 RTCpuSetAdd(pSet, idCpu);
106 } while (idCpu-- > 0);
107
108 return pSet;
109}
110
111
112RTDECL(RTCPUID) RTMpGetCount(void)
113{
114 return ncpus;
115}
116
117
118RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet)
119{
120 /*
121 * We cannot query CPU status recursively, return the cached set.
122 */
123 *pSet = g_rtMpSolCpuSet;
124 return pSet;
125}
126
127
128RTDECL(RTCPUID) RTMpGetOnlineCount(void)
129{
130 RTCPUSET Set;
131 RTMpGetOnlineSet(&Set);
132 return RTCpuSetCount(&Set);
133}
134
135
136/**
137 * Wrapper to Solaris IPI infrastructure.
138 *
139 * @param pCpuSet Pointer to Solaris CPU set.
140 * @param pfnSolWorker Function to execute on target CPU(s).
141 * @param pArgs Pointer to RTMPARGS to pass to @a pfnSolWorker.
142 *
143 * @returns Solaris error code.
144 */
145static void rtMpSolCrossCall(PRTSOLCPUSET pCpuSet, PFNRTMPSOLWORKER pfnSolWorker, PRTMPARGS pArgs)
146{
147 AssertPtrReturnVoid(pCpuSet);
148 AssertPtrReturnVoid(pfnSolWorker);
149 AssertPtrReturnVoid(pCpuSet);
150
151 if (g_frtSolOldIPI)
152 {
153 if (g_frtSolOldIPIUlong)
154 {
155 g_rtSolXcCall.u.pfnSol_xc_call_old_ulong((xc_arg_t)pArgs, /* Arg to IPI function */
156 0, /* Arg2, ignored */
157 0, /* Arg3, ignored */
158 IPRT_SOL_X_CALL_HIPRI, /* IPI priority */
159 pCpuSet->auCpus[0], /* Target CPU(s) */
160 (xc_func_t)pfnSolWorker); /* Function to execute on target(s) */
161 }
162 else
163 {
164 g_rtSolXcCall.u.pfnSol_xc_call_old((xc_arg_t)pArgs, /* Arg to IPI function */
165 0, /* Arg2, ignored */
166 0, /* Arg3, ignored */
167 IPRT_SOL_X_CALL_HIPRI, /* IPI priority */
168 *pCpuSet, /* Target CPU set */
169 (xc_func_t)pfnSolWorker); /* Function to execute on target(s) */
170 }
171 }
172 else
173 {
174 g_rtSolXcCall.u.pfnSol_xc_call((xc_arg_t)pArgs, /* Arg to IPI function */
175 0, /* Arg2 */
176 0, /* Arg3 */
177 &pCpuSet->auCpus[0], /* Target CPU set */
178 (xc_func_t)pfnSolWorker); /* Function to execute on target(s) */
179 }
180}
181
182
183/**
184 * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
185 * for the RTMpOnAll API.
186 *
187 * @param uArgs Pointer to the RTMPARGS package.
188 * @param uIgnored1 Ignored.
189 * @param uIgnored2 Ignored.
190 */
191static int rtMpSolOnAllCpuWrapper(void *uArg, void *uIgnored1, void *uIgnored2)
192{
193 PRTMPARGS pArgs = (PRTMPARGS)(uArg);
194
195 /*
196 * Solaris CPU cross calls execute on offline CPUs too. Check our CPU cache
197 * set and ignore if it's offline.
198 */
199 if (!RTMpIsCpuOnline(RTMpCpuId()))
200 return 0;
201
202 pArgs->pfnWorker(RTMpCpuId(), pArgs->pvUser1, pArgs->pvUser2);
203
204 NOREF(uIgnored1);
205 NOREF(uIgnored2);
206 return 0;
207}
208
209
210RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
211{
212 RTMPARGS Args;
213 RT_ASSERT_INTS_ON();
214
215 Args.pfnWorker = pfnWorker;
216 Args.pvUser1 = pvUser1;
217 Args.pvUser2 = pvUser2;
218 Args.idCpu = NIL_RTCPUID;
219 Args.cHits = 0;
220
221 RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
222 RTThreadPreemptDisable(&PreemptState);
223
224 RTSOLCPUSET CpuSet;
225 for (int i = 0; i < IPRT_SOL_SET_WORDS; i++)
226 CpuSet.auCpus[i] = (ulong_t)-1L;
227
228 rtMpSolCrossCall(&CpuSet, rtMpSolOnAllCpuWrapper, &Args);
229
230 RTThreadPreemptRestore(&PreemptState);
231
232 return VINF_SUCCESS;
233}
234
235
236/**
237 * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
238 * for the RTMpOnOthers API.
239 *
240 * @param uArgs Pointer to the RTMPARGS package.
241 * @param uIgnored1 Ignored.
242 * @param uIgnored2 Ignored.
243 */
244static int rtMpSolOnOtherCpusWrapper(void *uArg, void *uIgnored1, void *uIgnored2)
245{
246 PRTMPARGS pArgs = (PRTMPARGS)(uArg);
247 RTCPUID idCpu = RTMpCpuId();
248
249 Assert(idCpu != pArgs->idCpu);
250 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
251
252 NOREF(uIgnored1);
253 NOREF(uIgnored2);
254 return 0;
255}
256
257
258RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
259{
260 RTMPARGS Args;
261 RT_ASSERT_INTS_ON();
262
263 Args.pfnWorker = pfnWorker;
264 Args.pvUser1 = pvUser1;
265 Args.pvUser2 = pvUser2;
266 Args.idCpu = RTMpCpuId();
267 Args.cHits = 0;
268
269 /* The caller is supposed to have disabled preemption, but take no chances. */
270 RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
271 RTThreadPreemptDisable(&PreemptState);
272
273 RTSOLCPUSET CpuSet;
274 for (int i = 0; i < IPRT_SOL_SET_WORDS; i++)
275 CpuSet.auCpus[0] = (ulong_t)-1L;
276 BT_CLEAR(CpuSet.auCpus, RTMpCpuId());
277
278 rtMpSolCrossCall(&CpuSet, rtMpSolOnOtherCpusWrapper, &Args);
279
280 RTThreadPreemptRestore(&PreemptState);
281
282 return VINF_SUCCESS;
283}
284
285
286/**
287 * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
288 * for the RTMpOnSpecific API.
289 *
290 * @param uArgs Pointer to the RTMPARGS package.
291 * @param uIgnored1 Ignored.
292 * @param uIgnored2 Ignored.
293 *
294 * @returns Solaris error code.
295 */
296static int rtMpSolOnSpecificCpuWrapper(void *uArg, void *uIgnored1, void *uIgnored2)
297{
298 PRTMPARGS pArgs = (PRTMPARGS)(uArg);
299 RTCPUID idCpu = RTMpCpuId();
300
301 Assert(idCpu == pArgs->idCpu);
302 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
303 ASMAtomicIncU32(&pArgs->cHits);
304
305 NOREF(uIgnored1);
306 NOREF(uIgnored2);
307 return 0;
308}
309
310
311RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
312{
313 RTMPARGS Args;
314 RT_ASSERT_INTS_ON();
315
316 if (idCpu >= ncpus)
317 return VERR_CPU_NOT_FOUND;
318
319 if (RT_UNLIKELY(!RTMpIsCpuOnline(idCpu)))
320 return RTMpIsCpuPresent(idCpu) ? VERR_CPU_OFFLINE : VERR_CPU_NOT_FOUND;
321
322 Args.pfnWorker = pfnWorker;
323 Args.pvUser1 = pvUser1;
324 Args.pvUser2 = pvUser2;
325 Args.idCpu = idCpu;
326 Args.cHits = 0;
327
328 RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
329 RTThreadPreemptDisable(&PreemptState);
330
331 RTSOLCPUSET CpuSet;
332 for (int i = 0; i < IPRT_SOL_SET_WORDS; i++)
333 CpuSet.auCpus[i] = 0;
334 BT_SET(CpuSet.auCpus, idCpu);
335
336 rtMpSolCrossCall(&CpuSet, rtMpSolOnSpecificCpuWrapper, &Args);
337
338 RTThreadPreemptRestore(&PreemptState);
339
340 Assert(ASMAtomicUoReadU32(&Args.cHits) <= 1);
341
342 return ASMAtomicUoReadU32(&Args.cHits) == 1
343 ? VINF_SUCCESS
344 : VERR_CPU_NOT_FOUND;
345}
346
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