VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/haiku/mp-r0drv-haiku.c@ 61572

Last change on this file since 61572 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/* $Id: mp-r0drv-haiku.c 57358 2015-08-14 15:16:38Z vboxsync $ */
2/** @file
3 * IPRT - Multiprocessor, Ring-0 Driver, Haiku.
4 */
5
6/*
7 * Copyright (C) 2012-2015 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-haiku-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 smp_get_current_cpu();
43}
44
45
46RTDECL(int) RTMpCurSetIndex(void)
47{
48 return smp_get_current_cpu();
49}
50
51
52RTDECL(int) RTMpCurSetIndexAndId(PRTCPUID pidCpu)
53{
54 return *pidCpu = smp_get_current_cpu();
55}
56
57
58RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu)
59{
60 return idCpu < smp_get_num_cpus() ? (int)idCpu : -1;
61}
62
63
64RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
65{
66 return (unsigned)iCpu < smp_get_num_cpus() ? (RTCPUID)iCpu : NIL_RTCPUID;
67}
68
69
70RTDECL(RTCPUID) RTMpGetMaxCpuId(void)
71{
72 return smp_get_num_cpus() - 1;
73}
74
75
76RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu)
77{
78 return idCpu < smp_get_num_cpus();
79}
80
81
82RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
83{
84 RTCPUID idCpu;
85
86 RTCpuSetEmpty(pSet);
87 idCpu = RTMpGetMaxCpuId();
88 do
89 {
90 if (RTMpIsCpuPossible(idCpu))
91 RTCpuSetAdd(pSet, idCpu);
92 } while (idCpu-- > 0);
93 return pSet;
94}
95
96
97RTDECL(RTCPUID) RTMpGetCount(void)
98{
99 return smp_get_num_cpus();
100}
101
102
103RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
104{
105 return idCpu < smp_get_num_cpus();
106 /** @todo: FixMe && !CPU_ABSENT(idCpu) */
107}
108
109
110RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet)
111{
112 RTCPUID idCpu;
113
114 RTCpuSetEmpty(pSet);
115 idCpu = RTMpGetMaxCpuId();
116 do
117 {
118 if (RTMpIsCpuOnline(idCpu))
119 RTCpuSetAdd(pSet, idCpu);
120 } while (idCpu-- > 0);
121
122 return pSet;
123}
124
125
126RTDECL(RTCPUID) RTMpGetOnlineCount(void)
127{
128 return smp_get_num_cpus();
129}
130
131
132/**
133 * Wrapper between the native Haiku per-cpu callback and PFNRTWORKER
134 * for the RTMpOnAll API.
135 *
136 * @param pvArg Pointer to the RTMPARGS package.
137 */
138static void rtmpOnAllHaikuWrapper(void *pvArg, int current)
139{
140 PRTMPARGS pArgs = (PRTMPARGS)pvArg;
141 pArgs->pfnWorker(current, pArgs->pvUser1, pArgs->pvUser2);
142}
143
144
145RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
146{
147 RTMPARGS Args;
148 Args.pfnWorker = pfnWorker;
149 Args.pvUser1 = pvUser1;
150 Args.pvUser2 = pvUser2;
151 Args.idCpu = NIL_RTCPUID;
152 Args.cHits = 0;
153 /* is _sync needed ? */
154 call_all_cpus_sync(rtmpOnAllHaikuWrapper, &Args);
155 return VINF_SUCCESS;
156}
157
158
159/**
160 * Wrapper between the native Haiku per-cpu callback and PFNRTWORKER
161 * for the RTMpOnOthers API.
162 *
163 * @param pvArg Pointer to the RTMPARGS package.
164 */
165static void rtmpOnOthersHaikuWrapper(void *pvArg, int current)
166{
167 PRTMPARGS pArgs = (PRTMPARGS)pvArg;
168 RTCPUID idCpu = current;
169 if (pArgs->idCpu != idCpu)
170 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
171}
172
173
174RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
175{
176 /* Will panic if no rendezvousing cpus, so check up front. */
177 if (RTMpGetOnlineCount() > 1)
178 {
179 RTMPARGS Args;
180
181 Args.pfnWorker = pfnWorker;
182 Args.pvUser1 = pvUser1;
183 Args.pvUser2 = pvUser2;
184 Args.idCpu = RTMpCpuId();
185 Args.cHits = 0;
186 /* is _sync needed ? */
187 call_all_cpus_sync(rtmpOnOthersHaikuWrapper, &Args);
188 }
189 return VINF_SUCCESS;
190}
191
192
193/**
194 * Wrapper between the native Haiku per-cpu callback and PFNRTWORKER
195 * for the RTMpOnSpecific API.
196 *
197 * @param pvArg Pointer to the RTMPARGS package.
198 */
199static void rtmpOnSpecificHaikuWrapper(void *pvArg, int current)
200{
201 PRTMPARGS pArgs = (PRTMPARGS)pvArg;
202 RTCPUID idCpu = current;
203 if (pArgs->idCpu == idCpu)
204 {
205 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
206 ASMAtomicIncU32(&pArgs->cHits);
207 }
208}
209
210
211RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
212{
213 RTMPARGS Args;
214
215 /* Will panic if no rendezvousing cpus, so make sure the cpu is online. */
216 if (!RTMpIsCpuOnline(idCpu))
217 return VERR_CPU_NOT_FOUND;
218
219 Args.pfnWorker = pfnWorker;
220 Args.pvUser1 = pvUser1;
221 Args.pvUser2 = pvUser2;
222 Args.idCpu = idCpu;
223 Args.cHits = 0;
224 /* is _sync needed ? */
225 call_all_cpus_sync(rtmpOnSpecificHaikuWrapper, &Args);
226 return Args.cHits == 1
227 ? VINF_SUCCESS
228 : VERR_CPU_NOT_FOUND;
229}
230
231
232RTDECL(bool) RTMpOnAllIsConcurrentSafe(void)
233{
234 return true;
235}
236
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