VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/freebsd/mp-r0drv-freebsd.c@ 44529

Last change on this file since 44529 was 44529, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: mp-r0drv-freebsd.c 44529 2013-02-04 15:54:15Z vboxsync $ */
2/** @file
3 * IPRT - Multiprocessor, Ring-0 Driver, FreeBSD.
4 */
5
6/*
7 * Copyright (C) 2008-2011 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-freebsd-kernel.h"
32
33#include <iprt/mp.h>
34#include <iprt/err.h>
35#include <iprt/asm.h>
36#include <iprt/cpuset.h>
37#include "r0drv/mp-r0drv.h"
38
39
40RTDECL(RTCPUID) RTMpCpuId(void)
41{
42 return curcpu;
43}
44
45
46RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu)
47{
48 return idCpu < RTCPUSET_MAX_CPUS && idCpu <= mp_maxid ? (int)idCpu : -1;
49}
50
51
52RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
53{
54 return (unsigned)iCpu <= mp_maxid ? (RTCPUID)iCpu : NIL_RTCPUID;
55}
56
57
58RTDECL(RTCPUID) RTMpGetMaxCpuId(void)
59{
60 return mp_maxid;
61}
62
63
64RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu)
65{
66 return idCpu <= mp_maxid;
67}
68
69
70RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
71{
72 RTCPUID idCpu;
73
74 RTCpuSetEmpty(pSet);
75 idCpu = RTMpGetMaxCpuId();
76 do
77 {
78 if (RTMpIsCpuPossible(idCpu))
79 RTCpuSetAdd(pSet, idCpu);
80 } while (idCpu-- > 0);
81 return pSet;
82}
83
84
85RTDECL(RTCPUID) RTMpGetCount(void)
86{
87 return mp_maxid + 1;
88}
89
90
91RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
92{
93 return idCpu <= mp_maxid
94 && !CPU_ABSENT(idCpu);
95}
96
97
98RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet)
99{
100 RTCPUID idCpu;
101
102 RTCpuSetEmpty(pSet);
103 idCpu = RTMpGetMaxCpuId();
104 do
105 {
106 if (RTMpIsCpuOnline(idCpu))
107 RTCpuSetAdd(pSet, idCpu);
108 } while (idCpu-- > 0);
109
110 return pSet;
111}
112
113
114RTDECL(RTCPUID) RTMpGetOnlineCount(void)
115{
116 return mp_ncpus;
117}
118
119
120/**
121 * Wrapper between the native FreeBSD per-cpu callback and PFNRTWORKER
122 * for the RTMpOnAll API.
123 *
124 * @param pvArg Pointer to the RTMPARGS package.
125 */
126static void rtmpOnAllFreeBSDWrapper(void *pvArg)
127{
128 PRTMPARGS pArgs = (PRTMPARGS)pvArg;
129 pArgs->pfnWorker(curcpu, pArgs->pvUser1, pArgs->pvUser2);
130}
131
132
133RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
134{
135 RTMPARGS Args;
136 Args.pfnWorker = pfnWorker;
137 Args.pvUser1 = pvUser1;
138 Args.pvUser2 = pvUser2;
139 Args.idCpu = NIL_RTCPUID;
140 Args.cHits = 0;
141 smp_rendezvous(NULL, rtmpOnAllFreeBSDWrapper, smp_no_rendevous_barrier, &Args);
142 return VINF_SUCCESS;
143}
144
145
146/**
147 * Wrapper between the native FreeBSD per-cpu callback and PFNRTWORKER
148 * for the RTMpOnOthers API.
149 *
150 * @param pvArg Pointer to the RTMPARGS package.
151 */
152static void rtmpOnOthersFreeBSDWrapper(void *pvArg)
153{
154 PRTMPARGS pArgs = (PRTMPARGS)pvArg;
155 RTCPUID idCpu = curcpu;
156 if (pArgs->idCpu != idCpu)
157 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
158}
159
160
161RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
162{
163 /* Will panic if no rendezvousing cpus, so check up front. */
164 if (RTMpGetOnlineCount() > 1)
165 {
166#if __FreeBSD_version >= 900000
167 cpuset_t Mask;
168#elif __FreeBSD_version >= 700000
169 cpumask_t Mask;
170#endif
171 RTMPARGS Args;
172
173 Args.pfnWorker = pfnWorker;
174 Args.pvUser1 = pvUser1;
175 Args.pvUser2 = pvUser2;
176 Args.idCpu = RTMpCpuId();
177 Args.cHits = 0;
178#if __FreeBSD_version >= 700000
179# if __FreeBSD_version >= 900000
180 Mask = all_cpus;
181 CPU_CLR(curcpu, &Mask);
182# else
183 Mask = ~(cpumask_t)curcpu;
184# endif
185 smp_rendezvous_cpus(Mask, NULL, rtmpOnOthersFreeBSDWrapper, smp_no_rendevous_barrier, &Args);
186#else
187 smp_rendezvous(NULL, rtmpOnOthersFreeBSDWrapper, NULL, &Args);
188#endif
189 }
190 return VINF_SUCCESS;
191}
192
193
194/**
195 * Wrapper between the native FreeBSD per-cpu callback and PFNRTWORKER
196 * for the RTMpOnSpecific API.
197 *
198 * @param pvArg Pointer to the RTMPARGS package.
199 */
200static void rtmpOnSpecificFreeBSDWrapper(void *pvArg)
201{
202 PRTMPARGS pArgs = (PRTMPARGS)pvArg;
203 RTCPUID idCpu = curcpu;
204 if (pArgs->idCpu == idCpu)
205 {
206 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
207 ASMAtomicIncU32(&pArgs->cHits);
208 }
209}
210
211
212RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
213{
214#if __FreeBSD_version >= 900000
215 cpuset_t Mask;
216#elif __FreeBSD_version >= 700000
217 cpumask_t Mask;
218#endif
219 RTMPARGS Args;
220
221 /* Will panic if no rendezvousing cpus, so make sure the cpu is online. */
222 if (!RTMpIsCpuOnline(idCpu))
223 return VERR_CPU_NOT_FOUND;
224
225 Args.pfnWorker = pfnWorker;
226 Args.pvUser1 = pvUser1;
227 Args.pvUser2 = pvUser2;
228 Args.idCpu = idCpu;
229 Args.cHits = 0;
230#if __FreeBSD_version >= 700000
231# if __FreeBSD_version >= 900000
232 CPU_SETOF(idCpu, &Mask);
233# else
234 Mask = (cpumask_t)1 << idCpu;
235# endif
236 smp_rendezvous_cpus(Mask, NULL, rtmpOnSpecificFreeBSDWrapper, smp_no_rendevous_barrier, &Args);
237#else
238 smp_rendezvous(NULL, rtmpOnSpecificFreeBSDWrapper, NULL, &Args);
239#endif
240 return Args.cHits == 1
241 ? VINF_SUCCESS
242 : VERR_CPU_NOT_FOUND;
243}
244
245
246#if __FreeBSD_version >= 700000
247/**
248 * Dummy callback for RTMpPokeCpu.
249 * @param pvArg Ignored
250 */
251static void rtmpFreeBSDPokeCallback(void *pvArg)
252{
253 NOREF(pvArg);
254}
255
256
257RTDECL(int) RTMpPokeCpu(RTCPUID idCpu)
258{
259#if __FreeBSD_version >= 900000
260 cpuset_t Mask;
261#elif __FreeBSD_version >= 700000
262 cpumask_t Mask;
263#endif
264
265 /* Will panic if no rendezvousing cpus, so make sure the cpu is online. */
266 if (!RTMpIsCpuOnline(idCpu))
267 return VERR_CPU_NOT_FOUND;
268
269# if __FreeBSD_version >= 900000
270 CPU_SETOF(idCpu, &Mask);
271# else
272 Mask = (cpumask_t)1 << idCpu;
273# endif
274 smp_rendezvous_cpus(Mask, NULL, rtmpFreeBSDPokeCallback, smp_no_rendevous_barrier, NULL);
275
276 return VINF_SUCCESS;
277}
278
279#else /* < 7.0 */
280RTDECL(int) RTMpPokeCpu(RTCPUID idCpu)
281{
282 return VERR_NOT_SUPPORTED;
283}
284#endif /* < 7.0 */
285
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