VirtualBox

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

Last change on this file since 32736 was 29499, checked in by vboxsync, 15 years ago

mp-r0drv-freebsd.c: Use smp_no_rendevous_barrier as teardown function

  • 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-freebsd.c 29499 2010-05-14 21:19:32Z vboxsync $ */
2/** @file
3 * IPRT - Multiprocessor, Ring-0 Driver, FreeBSD.
4 */
5
6/*
7 * Copyright (C) 2008 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 <= 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 rendezvouing cpus, so check up front. */
164 if (RTMpGetOnlineCount() > 1)
165 {
166#if __FreeBSD_version >= 700000
167 cpumask_t Mask = ~(cpumask_t)curcpu;
168#endif
169 RTMPARGS Args;
170
171 Args.pfnWorker = pfnWorker;
172 Args.pvUser1 = pvUser1;
173 Args.pvUser2 = pvUser2;
174 Args.idCpu = RTMpCpuId();
175 Args.cHits = 0;
176#if __FreeBSD_version >= 700000
177 smp_rendezvous_cpus(Mask, NULL, rtmpOnOthersFreeBSDWrapper, smp_no_rendevous_barrier, &Args);
178#else
179 smp_rendezvous(NULL, rtmpOnOthersFreeBSDWrapper, NULL, &Args);
180#endif
181 }
182 return VINF_SUCCESS;
183}
184
185
186/**
187 * Wrapper between the native FreeBSD per-cpu callback and PFNRTWORKER
188 * for the RTMpOnSpecific API.
189 *
190 * @param pvArg Pointer to the RTMPARGS package.
191 */
192static void rtmpOnSpecificFreeBSDWrapper(void *pvArg)
193{
194 PRTMPARGS pArgs = (PRTMPARGS)pvArg;
195 RTCPUID idCpu = curcpu;
196 if (pArgs->idCpu == idCpu)
197 {
198 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
199 ASMAtomicIncU32(&pArgs->cHits);
200 }
201}
202
203
204RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
205{
206#if __FreeBSD_version >= 700000
207 cpumask_t Mask = 1 << idCpu;
208#endif
209 RTMPARGS Args;
210
211 /* Will panic if no rendezvouing cpus, so make sure the cpu is online. */
212 if (!RTMpIsCpuOnline(idCpu))
213 return VERR_CPU_NOT_FOUND;
214
215 Args.pfnWorker = pfnWorker;
216 Args.pvUser1 = pvUser1;
217 Args.pvUser2 = pvUser2;
218 Args.idCpu = idCpu;
219 Args.cHits = 0;
220#if __FreeBSD_version >= 700000
221 Mask = (cpumask_t)1 << idCpu;
222 smp_rendezvous_cpus(Mask, NULL, rtmpOnSpecificFreeBSDWrapper, smp_no_rendevous_barrier, &Args);
223#else
224 smp_rendezvous(NULL, rtmpOnSpecificFreeBSDWrapper, NULL, &Args);
225#endif
226 return Args.cHits == 1
227 ? VINF_SUCCESS
228 : VERR_CPU_NOT_FOUND;
229}
230
231
232#if __FreeBSD_version >= 700000
233/**
234 * Dummy callback for RTMpPokeCpu.
235 * @param pvArg Ignored
236 */
237static void rtmpFreeBSDPokeCallback(void *pvArg)
238{
239 NOREF(pvArg);
240}
241
242
243RTDECL(int) RTMpPokeCpu(RTCPUID idCpu)
244{
245 cpumask_t Mask;
246
247 /* Will panic if no rendezvouing cpus, so make sure the cpu is online. */
248 if (!RTMpIsCpuOnline(idCpu))
249 return VERR_CPU_NOT_FOUND;
250
251 Mask = (cpumask_t)1 << idCpu;
252 smp_rendezvous_cpus(Mask, NULL, rtmpFreeBSDPokeCallback, smp_no_rendevous_barrier, NULL);
253
254 return VINF_SUCCESS;
255}
256
257#else /* < 7.0 */
258RTDECL(int) RTMpPokeCpu(RTCPUID idCpu)
259{
260 return VERR_NOT_SUPPORTED;
261}
262#endif /* < 7.0 */
263
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