VirtualBox

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

Last change on this file since 18130 was 15843, checked in by vboxsync, 16 years ago

RTMpIsCpuWorkPending() -> RTMpIsCpuWorkPending(void), corrected source location and added the missing generic stub function.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* $Id: mp-r0drv-solaris.c 15843 2009-01-07 18:35:24Z 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) RTMpIsCpuPossible(RTCPUID idCpu)
69{
70 cpu_t *pCpu = idCpu < NCPU ? cpu_get(idCpu) : NULL;
71 return pCpu != NULL;
72}
73
74
75RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
76{
77 RTCPUID idCpu;
78
79 RTCpuSetEmpty(pSet);
80 idCpu = RTMpGetMaxCpuId(); /* it's inclusive */
81 do
82 {
83 if (RTMpIsCpuPossible(idCpu))
84 RTCpuSetAdd(pSet, idCpu);
85 } while (idCpu-- > 0);
86
87 return pSet;
88}
89
90
91RTDECL(RTCPUID) RTMpGetCount(void)
92{
93 return ncpus;
94}
95
96
97RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
98{
99 cpu_t *pCpu = idCpu < NCPU ? cpu_get(idCpu) : NULL;
100 return pCpu
101 && cpu_is_online(pCpu);
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
127RTDECL(bool) RTMpIsCpuWorkPending(void)
128{
129 /** @todo (not used on non-Windows platforms yet). */
130 return false;
131}
132
133
134/**
135 * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
136 * for the RTMpOnAll API.
137 *
138 * @param uArgs Pointer to the RTMPARGS package.
139 * @param uIgnored1 Ignored.
140 * @param uIgnored2 Ignored.
141 */
142static int rtmpOnAllSolarisWrapper(xc_arg_t uArg, xc_arg_t uIgnored1, xc_arg_t uIgnored2)
143{
144 PRTMPARGS pArgs = (PRTMPARGS)(uArg);
145
146 pArgs->pfnWorker(RTMpCpuId(), pArgs->pvUser1, pArgs->pvUser2);
147
148 NOREF(uIgnored1);
149 NOREF(uIgnored2);
150 return 0;
151}
152
153
154RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
155{
156 cpuset_t Set;
157 RTMPARGS Args;
158
159 Args.pfnWorker = pfnWorker;
160 Args.pvUser1 = pvUser1;
161 Args.pvUser2 = pvUser2;
162 Args.idCpu = NIL_RTCPUID;
163 Args.cHits = 0;
164
165 kpreempt_disable();
166
167 CPUSET_ALL(Set);
168 xc_call((uintptr_t)&Args, 0, 0, X_CALL_HIPRI, Set, rtmpOnAllSolarisWrapper);
169
170 kpreempt_enable();
171
172 return VINF_SUCCESS;
173}
174
175
176/**
177 * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
178 * for the RTMpOnOthers API.
179 *
180 * @param uArgs Pointer to the RTMPARGS package.
181 * @param uIgnored1 Ignored.
182 * @param uIgnored2 Ignored.
183 */
184static int rtmpOnOthersSolarisWrapper(xc_arg_t uArg, xc_arg_t uIgnored1, xc_arg_t uIgnored2)
185{
186 PRTMPARGS pArgs = (PRTMPARGS)(uArg);
187 RTCPUID idCpu = RTMpCpuId();
188
189 Assert(idCpu != pArgs->idCpu);
190 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
191
192 NOREF(uIgnored1);
193 NOREF(uIgnored2);
194 return 0;
195}
196
197
198RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
199{
200 int rc;
201 cpuset_t Set;
202 RTMPARGS Args;
203
204 Args.pfnWorker = pfnWorker;
205 Args.pvUser1 = pvUser1;
206 Args.pvUser2 = pvUser2;
207 Args.idCpu = RTMpCpuId(); /** @todo should disable pre-emption before doing this.... */
208 Args.cHits = 0;
209
210 kpreempt_disable();
211
212 CPUSET_ALL_BUT(Set, Args.idCpu);
213 xc_call((uintptr_t)&Args, 0, 0, X_CALL_HIPRI, Set, rtmpOnOthersSolarisWrapper);
214
215 kpreempt_enable();
216
217 return VINF_SUCCESS;
218}
219
220
221/**
222 * Wrapper between the native solaris per-cpu callback and PFNRTWORKER
223 * for the RTMpOnSpecific API.
224 *
225 *
226 * @param uArgs Pointer to the RTMPARGS package.
227 * @param uIgnored1 Ignored.
228 * @param uIgnored2 Ignored.
229 */
230static int rtmpOnSpecificSolarisWrapper(xc_arg_t uArg, xc_arg_t uIgnored1, xc_arg_t uIgnored2)
231{
232 PRTMPARGS pArgs = (PRTMPARGS)(uArg);
233 RTCPUID idCpu = RTMpCpuId();
234
235 Assert(idCpu != pArgs->idCpu);
236 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
237 ASMAtomicIncU32(&pArgs->cHits);
238
239 NOREF(uIgnored1);
240 NOREF(uIgnored2);
241 return 0;
242}
243
244
245RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
246{
247 int rc;
248 cpuset_t Set;
249 RTMPARGS Args;
250
251 if (idCpu >= NCPU)
252 return VERR_CPU_NOT_FOUND;
253
254 Args.pfnWorker = pfnWorker;
255 Args.pvUser1 = pvUser1;
256 Args.pvUser2 = pvUser2;
257 Args.idCpu = idCpu;
258 Args.cHits = 0;
259
260 kpreempt_disable();
261
262 CPUSET_ZERO(Set);
263 CPUSET_ADD(Set, idCpu);
264
265 xc_call((uintptr_t)&Args, 0, 0, X_CALL_HIPRI, Set, rtmpOnSpecificSolarisWrapper);
266
267 kpreempt_enable();
268
269 Assert(ASMAtomicUoReadU32(&Args.cHits) <= 1);
270
271 return ASMAtomicUoReadU32(&Args.cHits) == 1
272 ? VINF_SUCCESS
273 : VERR_CPU_NOT_FOUND;
274}
275
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