VirtualBox

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

Last change on this file since 77923 was 77128, checked in by vboxsync, 6 years ago

mp-r0drv-freebsd.cpp: Fix compliation on newer FreeBSD kernels where smp_no_rendezvous_barrier was renamed from smp_no_rendevous_barrier

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