VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/darwin/mp-r0drv-darwin.cpp@ 36555

最後變更 在這個檔案從36555是 36264,由 vboxsync 提交於 14 年 前

mp-r0drv-darwin.cpp: Use the generic 'possible' implementation.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 6.5 KB
 
1/* $Id: mp-r0drv-darwin.cpp 36264 2011-03-11 15:05:14Z vboxsync $ */
2/** @file
3 * IPRT - Multiprocessor, Ring-0 Driver, Darwin.
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.alldomusa.eu.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-darwin-kernel.h"
32#include "internal/iprt.h"
33#include <iprt/mp.h>
34
35#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
36# include <iprt/asm-amd64-x86.h>
37#endif
38#include <iprt/cpuset.h>
39#include <iprt/err.h>
40#include "r0drv/mp-r0drv.h"
41
42
43/*******************************************************************************
44* Defined Constants And Macros *
45*******************************************************************************/
46#define MY_DARWIN_MAX_CPUS (0xf + 1) /* see MAX_CPUS */
47
48
49/*******************************************************************************
50* Global Variables *
51*******************************************************************************/
52static int32_t volatile g_cMaxCpus = -1;
53
54
55static int rtMpDarwinInitMaxCpus(void)
56{
57 int32_t cCpus = -1;
58 size_t oldLen = sizeof(cCpus);
59 int rc = sysctlbyname("hw.ncpu", &cCpus, &oldLen, NULL, NULL);
60 if (rc)
61 {
62 printf("IPRT: sysctlbyname(hw.ncpu) failed with rc=%d!\n", rc);
63 cCpus = MY_DARWIN_MAX_CPUS;
64 }
65
66 ASMAtomicWriteS32(&g_cMaxCpus, cCpus);
67 return cCpus;
68}
69
70
71DECLINLINE(int) rtMpDarwinMaxCpus(void)
72{
73 int cCpus = g_cMaxCpus;
74 if (RT_UNLIKELY(cCpus <= 0))
75 return rtMpDarwinInitMaxCpus();
76 return cCpus;
77}
78
79
80RTDECL(RTCPUID) RTMpCpuId(void)
81{
82 return cpu_number();
83}
84
85
86RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu)
87{
88 return idCpu < RTCPUSET_MAX_CPUS && idCpu < MY_DARWIN_MAX_CPUS ? (int)idCpu : -1;
89}
90
91
92RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
93{
94 return (unsigned)iCpu < MY_DARWIN_MAX_CPUS ? (RTCPUID)iCpu : NIL_RTCPUID;
95}
96
97
98RTDECL(RTCPUID) RTMpGetMaxCpuId(void)
99{
100 return rtMpDarwinMaxCpus() - 1;
101}
102
103
104RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu)
105{
106 return idCpu < MY_DARWIN_MAX_CPUS
107 && idCpu < (RTCPUID)rtMpDarwinMaxCpus();
108}
109
110
111RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
112{
113 RTCPUID idCpu;
114
115 RTCpuSetEmpty(pSet);
116 idCpu = RTMpGetMaxCpuId();
117 do
118 {
119 if (RTMpIsCpuPossible(idCpu))
120 RTCpuSetAdd(pSet, idCpu);
121 } while (idCpu-- > 0);
122 return pSet;
123}
124
125
126RTDECL(RTCPUID) RTMpGetCount(void)
127{
128 return rtMpDarwinMaxCpus();
129}
130
131
132RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet)
133{
134 /** @todo darwin R0 MP */
135 return RTMpGetSet(pSet);
136}
137
138
139RTDECL(RTCPUID) RTMpGetOnlineCount(void)
140{
141 /** @todo darwin R0 MP */
142 return RTMpGetCount();
143}
144
145
146RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
147{
148 /** @todo darwin R0 MP */
149 return RTMpIsCpuPossible(idCpu);
150}
151
152
153RTDECL(uint32_t) RTMpGetCurFrequency(RTCPUID idCpu)
154{
155 /** @todo darwin R0 MP (rainy day) */
156 return 0;
157}
158
159
160RTDECL(uint32_t) RTMpGetMaxFrequency(RTCPUID idCpu)
161{
162 /** @todo darwin R0 MP (rainy day) */
163 return 0;
164}
165
166
167RTDECL(bool) RTMpIsCpuWorkPending(void)
168{
169 /** @todo (not used on non-Windows platforms yet). */
170 return false;
171}
172
173
174/**
175 * Wrapper between the native darwin per-cpu callback and PFNRTWORKER
176 * for the RTMpOnAll API.
177 *
178 * @param pvArg Pointer to the RTMPARGS package.
179 */
180static void rtmpOnAllDarwinWrapper(void *pvArg)
181{
182 PRTMPARGS pArgs = (PRTMPARGS)pvArg;
183 pArgs->pfnWorker(cpu_number(), pArgs->pvUser1, pArgs->pvUser2);
184}
185
186
187RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
188{
189 RT_ASSERT_INTS_ON();
190
191 RTMPARGS Args;
192 Args.pfnWorker = pfnWorker;
193 Args.pvUser1 = pvUser1;
194 Args.pvUser2 = pvUser2;
195 Args.idCpu = NIL_RTCPUID;
196 Args.cHits = 0;
197 mp_rendezvous_no_intrs(rtmpOnAllDarwinWrapper, &Args);
198 return VINF_SUCCESS;
199}
200
201
202/**
203 * Wrapper between the native darwin per-cpu callback and PFNRTWORKER
204 * for the RTMpOnOthers API.
205 *
206 * @param pvArg Pointer to the RTMPARGS package.
207 */
208static void rtmpOnOthersDarwinWrapper(void *pvArg)
209{
210 PRTMPARGS pArgs = (PRTMPARGS)pvArg;
211 RTCPUID idCpu = cpu_number();
212 if (pArgs->idCpu != idCpu)
213 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
214}
215
216
217RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
218{
219 RT_ASSERT_INTS_ON();
220
221 int rc;
222 RTMPARGS Args;
223 Args.pfnWorker = pfnWorker;
224 Args.pvUser1 = pvUser1;
225 Args.pvUser2 = pvUser2;
226 Args.idCpu = RTMpCpuId();
227 Args.cHits = 0;
228 mp_rendezvous_no_intrs(rtmpOnOthersDarwinWrapper, &Args);
229 return VINF_SUCCESS;
230}
231
232
233/**
234 * Wrapper between the native darwin per-cpu callback and PFNRTWORKER
235 * for the RTMpOnSpecific API.
236 *
237 * @param pvArg Pointer to the RTMPARGS package.
238 */
239static void rtmpOnSpecificDarwinWrapper(void *pvArg)
240{
241 PRTMPARGS pArgs = (PRTMPARGS)pvArg;
242 RTCPUID idCpu = cpu_number();
243 if (pArgs->idCpu == idCpu)
244 {
245 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
246 ASMAtomicIncU32(&pArgs->cHits);
247 }
248}
249
250
251RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
252{
253 RT_ASSERT_INTS_ON();
254
255 int rc;
256 RTMPARGS Args;
257 Args.pfnWorker = pfnWorker;
258 Args.pvUser1 = pvUser1;
259 Args.pvUser2 = pvUser2;
260 Args.idCpu = idCpu;
261 Args.cHits = 0;
262 mp_rendezvous_no_intrs(rtmpOnSpecificDarwinWrapper, &Args);
263 return Args.cHits == 1
264 ? VINF_SUCCESS
265 : VERR_CPU_NOT_FOUND;
266}
267
268
269RTDECL(int) RTMpPokeCpu(RTCPUID idCpu)
270{
271 RT_ASSERT_INTS_ON();
272
273 /* no unicast IPI */
274 return VERR_NOT_SUPPORTED;
275}
276
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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