VirtualBox

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

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

rebranding: IPRT files again.

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