1 | /* $Id: mp-r0drv-solaris.c 22073 2009-08-07 15:26:56Z 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/cpuset.h>
|
---|
41 | #include <iprt/err.h>
|
---|
42 | #include "r0drv/mp-r0drv.h"
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 | RTDECL(RTCPUID) RTMpCpuId(void)
|
---|
47 | {
|
---|
48 | return cpuid_get_chipid(CPU); /* is there a better way? */
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu)
|
---|
53 | {
|
---|
54 | return idCpu < NCPU ? idCpu : -1;
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
|
---|
59 | {
|
---|
60 | return (unsigned)iCpu < NCPU ? iCpu : NIL_RTCPUID;
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | RTDECL(RTCPUID) RTMpGetMaxCpuId(void)
|
---|
65 | {
|
---|
66 | return NCPU - 1;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu)
|
---|
71 | {
|
---|
72 | cpu_t *pCpu = idCpu < NCPU ? cpu_get(idCpu) : NULL;
|
---|
73 | return pCpu != NULL;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
|
---|
78 | {
|
---|
79 | RTCPUID idCpu;
|
---|
80 |
|
---|
81 | RTCpuSetEmpty(pSet);
|
---|
82 | idCpu = RTMpGetMaxCpuId(); /* it's inclusive */
|
---|
83 | do
|
---|
84 | {
|
---|
85 | if (RTMpIsCpuPossible(idCpu))
|
---|
86 | RTCpuSetAdd(pSet, idCpu);
|
---|
87 | } while (idCpu-- > 0);
|
---|
88 |
|
---|
89 | return pSet;
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | RTDECL(RTCPUID) RTMpGetCount(void)
|
---|
94 | {
|
---|
95 | return ncpus;
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
|
---|
100 | {
|
---|
101 | cpu_t *pCpu = idCpu < NCPU ? cpu_get(idCpu) : NULL;
|
---|
102 | return pCpu
|
---|
103 | && cpu_is_online(pCpu);
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet)
|
---|
108 | {
|
---|
109 | RTCPUID idCpu;
|
---|
110 |
|
---|
111 | RTCpuSetEmpty(pSet);
|
---|
112 | idCpu = RTMpGetMaxCpuId(); /* it's inclusive */
|
---|
113 | do
|
---|
114 | {
|
---|
115 | if (RTMpIsCpuOnline(idCpu))
|
---|
116 | RTCpuSetAdd(pSet, idCpu);
|
---|
117 | } while (idCpu-- > 0);
|
---|
118 |
|
---|
119 | return pSet;
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | RTDECL(RTCPUID) RTMpGetOnlineCount(void)
|
---|
124 | {
|
---|
125 | return ncpus_online;
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | RTDECL(bool) RTMpIsCpuWorkPending(void)
|
---|
130 | {
|
---|
131 | /** @todo (not used on non-Windows platforms yet). */
|
---|
132 | return false;
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
|
---|
138 | * for the RTMpOnAll API.
|
---|
139 | *
|
---|
140 | * @param uArgs Pointer to the RTMPARGS package.
|
---|
141 | * @param uIgnored1 Ignored.
|
---|
142 | * @param uIgnored2 Ignored.
|
---|
143 | */
|
---|
144 | static int rtmpOnAllSolarisWrapper(xc_arg_t uArg, xc_arg_t uIgnored1, xc_arg_t uIgnored2)
|
---|
145 | {
|
---|
146 | PRTMPARGS pArgs = (PRTMPARGS)(uArg);
|
---|
147 |
|
---|
148 | pArgs->pfnWorker(RTMpCpuId(), pArgs->pvUser1, pArgs->pvUser2);
|
---|
149 |
|
---|
150 | NOREF(uIgnored1);
|
---|
151 | NOREF(uIgnored2);
|
---|
152 | return 0;
|
---|
153 | }
|
---|
154 |
|
---|
155 |
|
---|
156 | RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
|
---|
157 | {
|
---|
158 | cpuset_t Set;
|
---|
159 | RTMPARGS Args;
|
---|
160 | RT_ASSERT_INTS_ON();
|
---|
161 |
|
---|
162 | Args.pfnWorker = pfnWorker;
|
---|
163 | Args.pvUser1 = pvUser1;
|
---|
164 | Args.pvUser2 = pvUser2;
|
---|
165 | Args.idCpu = NIL_RTCPUID;
|
---|
166 | Args.cHits = 0;
|
---|
167 |
|
---|
168 | kpreempt_disable();
|
---|
169 |
|
---|
170 | CPUSET_ALL(Set);
|
---|
171 | xc_call((uintptr_t)&Args, 0, 0, X_CALL_HIPRI, Set, rtmpOnAllSolarisWrapper);
|
---|
172 |
|
---|
173 | kpreempt_enable();
|
---|
174 |
|
---|
175 | return VINF_SUCCESS;
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
|
---|
181 | * for the RTMpOnOthers API.
|
---|
182 | *
|
---|
183 | * @param uArgs Pointer to the RTMPARGS package.
|
---|
184 | * @param uIgnored1 Ignored.
|
---|
185 | * @param uIgnored2 Ignored.
|
---|
186 | */
|
---|
187 | static int rtmpOnOthersSolarisWrapper(xc_arg_t uArg, xc_arg_t uIgnored1, xc_arg_t uIgnored2)
|
---|
188 | {
|
---|
189 | PRTMPARGS pArgs = (PRTMPARGS)(uArg);
|
---|
190 | RTCPUID idCpu = RTMpCpuId();
|
---|
191 |
|
---|
192 | Assert(idCpu != pArgs->idCpu);
|
---|
193 | pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
|
---|
194 |
|
---|
195 | NOREF(uIgnored1);
|
---|
196 | NOREF(uIgnored2);
|
---|
197 | return 0;
|
---|
198 | }
|
---|
199 |
|
---|
200 |
|
---|
201 | RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
|
---|
202 | {
|
---|
203 | int rc;
|
---|
204 | cpuset_t Set;
|
---|
205 | RTMPARGS Args;
|
---|
206 | RT_ASSERT_INTS_ON();
|
---|
207 |
|
---|
208 | /* The caller should disable preemption, but take no chances. */
|
---|
209 | kpreempt_disable();
|
---|
210 |
|
---|
211 | Args.pfnWorker = pfnWorker;
|
---|
212 | Args.pvUser1 = pvUser1;
|
---|
213 | Args.pvUser2 = pvUser2;
|
---|
214 | Args.idCpu = RTMpCpuId();
|
---|
215 | Args.cHits = 0;
|
---|
216 |
|
---|
217 | CPUSET_ALL_BUT(Set, Args.idCpu);
|
---|
218 | xc_call((uintptr_t)&Args, 0, 0, X_CALL_HIPRI, Set, rtmpOnOthersSolarisWrapper);
|
---|
219 |
|
---|
220 | kpreempt_enable();
|
---|
221 |
|
---|
222 | return VINF_SUCCESS;
|
---|
223 | }
|
---|
224 |
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
|
---|
228 | * for the RTMpOnSpecific API.
|
---|
229 | *
|
---|
230 | *
|
---|
231 | * @param uArgs Pointer to the RTMPARGS package.
|
---|
232 | * @param uIgnored1 Ignored.
|
---|
233 | * @param uIgnored2 Ignored.
|
---|
234 | */
|
---|
235 | static int rtmpOnSpecificSolarisWrapper(xc_arg_t uArg, xc_arg_t uIgnored1, xc_arg_t uIgnored2)
|
---|
236 | {
|
---|
237 | PRTMPARGS pArgs = (PRTMPARGS)(uArg);
|
---|
238 | RTCPUID idCpu = RTMpCpuId();
|
---|
239 |
|
---|
240 | Assert(idCpu != pArgs->idCpu);
|
---|
241 | pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
|
---|
242 | ASMAtomicIncU32(&pArgs->cHits);
|
---|
243 |
|
---|
244 | NOREF(uIgnored1);
|
---|
245 | NOREF(uIgnored2);
|
---|
246 | return 0;
|
---|
247 | }
|
---|
248 |
|
---|
249 |
|
---|
250 | RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
|
---|
251 | {
|
---|
252 | int rc;
|
---|
253 | cpuset_t Set;
|
---|
254 | RTMPARGS Args;
|
---|
255 | RT_ASSERT_INTS_ON();
|
---|
256 |
|
---|
257 | if (idCpu >= NCPU)
|
---|
258 | return VERR_CPU_NOT_FOUND;
|
---|
259 |
|
---|
260 | Args.pfnWorker = pfnWorker;
|
---|
261 | Args.pvUser1 = pvUser1;
|
---|
262 | Args.pvUser2 = pvUser2;
|
---|
263 | Args.idCpu = idCpu;
|
---|
264 | Args.cHits = 0;
|
---|
265 |
|
---|
266 | kpreempt_disable();
|
---|
267 |
|
---|
268 | CPUSET_ZERO(Set);
|
---|
269 | CPUSET_ADD(Set, idCpu);
|
---|
270 |
|
---|
271 | xc_call((uintptr_t)&Args, 0, 0, X_CALL_HIPRI, Set, rtmpOnSpecificSolarisWrapper);
|
---|
272 |
|
---|
273 | kpreempt_enable();
|
---|
274 |
|
---|
275 | Assert(ASMAtomicUoReadU32(&Args.cHits) <= 1);
|
---|
276 |
|
---|
277 | return ASMAtomicUoReadU32(&Args.cHits) == 1
|
---|
278 | ? VINF_SUCCESS
|
---|
279 | : VERR_CPU_NOT_FOUND;
|
---|
280 | }
|
---|
281 |
|
---|