VirtualBox

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

Last change on this file since 7352 was 7331, checked in by vboxsync, 17 years ago

Solaris RTMp implementation (untested).

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

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