VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/VMEmt.cpp@ 108959

Last change on this file since 108959 was 108387, checked in by vboxsync, 8 weeks ago

VMMR3/VMEmt.cpp,VMMR3/TM.cpp,VMMR3/NEMR3Native-win-armv8.cpp: Workaround for Windows/ARM hosts to allow for guests to use more than 1 vCPU, bugref:10392 [fix for when not using driverless mode]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 54.3 KB
Line 
1/* $Id: VMEmt.cpp 108387 2025-02-26 10:02:21Z vboxsync $ */
2/** @file
3 * VM - Virtual Machine, The Emulation Thread.
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_VM
33#include <VBox/vmm/tm.h>
34#include <VBox/vmm/dbgf.h>
35#include <VBox/vmm/em.h>
36#include <VBox/vmm/gvmm.h>
37#include <VBox/vmm/nem.h>
38#include <VBox/vmm/pdmapi.h>
39#include <VBox/vmm/tm.h>
40#include "VMInternal.h"
41#include <VBox/vmm/vmcc.h>
42
43#include <VBox/err.h>
44#include <VBox/log.h>
45#include <iprt/assert.h>
46#include <iprt/asm.h>
47#include <iprt/asm-math.h>
48#include <iprt/semaphore.h>
49#include <iprt/string.h>
50#include <iprt/thread.h>
51#include <iprt/time.h>
52
53
54/*********************************************************************************************************************************
55* Internal Functions *
56*********************************************************************************************************************************/
57int vmR3EmulationThreadWithId(RTTHREAD hThreadSelf, PUVMCPU pUVCpu, VMCPUID idCpu);
58
59
60/**
61 * The emulation thread main function.
62 *
63 * @returns Thread exit code.
64 * @param hThreadSelf The handle to the executing thread.
65 * @param pvArgs Pointer to the user mode per-VCpu structure (UVMPCU).
66 */
67DECLCALLBACK(int) vmR3EmulationThread(RTTHREAD hThreadSelf, void *pvArgs)
68{
69 PUVMCPU pUVCpu = (PUVMCPU)pvArgs;
70 return vmR3EmulationThreadWithId(hThreadSelf, pUVCpu, pUVCpu->idCpu);
71}
72
73
74/**
75 * The emulation thread main function, with Virtual CPU ID for debugging.
76 *
77 * @returns Thread exit code.
78 * @param hThreadSelf The handle to the executing thread.
79 * @param pUVCpu Pointer to the user mode per-VCpu structure.
80 * @param idCpu The virtual CPU ID, for backtrace purposes.
81 */
82int vmR3EmulationThreadWithId(RTTHREAD hThreadSelf, PUVMCPU pUVCpu, VMCPUID idCpu)
83{
84 PUVM pUVM = pUVCpu->pUVM;
85 int rc;
86 RT_NOREF_PV(hThreadSelf);
87
88 AssertReleaseMsg(RT_VALID_PTR(pUVM) && pUVM->u32Magic == UVM_MAGIC,
89 ("Invalid arguments to the emulation thread!\n"));
90
91 rc = RTTlsSet(pUVM->vm.s.idxTLS, pUVCpu);
92 AssertReleaseMsgRCReturn(rc, ("RTTlsSet %x failed with %Rrc\n", pUVM->vm.s.idxTLS, rc), rc);
93
94 if ( pUVM->pVmm2UserMethods
95 && pUVM->pVmm2UserMethods->pfnNotifyEmtInit)
96 pUVM->pVmm2UserMethods->pfnNotifyEmtInit(pUVM->pVmm2UserMethods, pUVM, pUVCpu);
97
98 /*
99 * The request loop.
100 */
101 rc = VINF_SUCCESS;
102 Log(("vmR3EmulationThread: Emulation thread starting the days work... Thread=%#x pUVM=%p\n", hThreadSelf, pUVM));
103#ifdef LOG_ENABLED
104 VMSTATE enmBefore = VMSTATE_CREATED; /* (only used for logging atm.) */
105#endif
106 ASMAtomicIncU32(&pUVM->vm.s.cActiveEmts);
107 for (;;)
108 {
109 /*
110 * During early init there is no pVM and/or pVCpu, so make a special path
111 * for that to keep things clearly separate.
112 */
113 PVM pVM = pUVM->pVM;
114 PVMCPU pVCpu = pUVCpu->pVCpu;
115 if (!pVCpu || !pVM)
116 {
117 /*
118 * Check for termination first.
119 */
120 if (pUVM->vm.s.fTerminateEMT)
121 {
122 rc = VINF_EM_TERMINATE;
123 break;
124 }
125
126 /*
127 * Only the first VCPU may initialize the VM during early init
128 * and must therefore service all VMCPUID_ANY requests.
129 * See also VMR3Create
130 */
131 if ( (pUVM->vm.s.pNormalReqs || pUVM->vm.s.pPriorityReqs)
132 && pUVCpu->idCpu == 0)
133 {
134 /*
135 * Service execute in any EMT request.
136 */
137 rc = VMR3ReqProcessU(pUVM, VMCPUID_ANY, false /*fPriorityOnly*/);
138 Log(("vmR3EmulationThread: Req rc=%Rrc, VM state %s -> %s\n", rc, VMR3GetStateName(enmBefore), pUVM->pVM ? VMR3GetStateName(pUVM->pVM->enmVMState) : "CREATING"));
139 }
140 else if (pUVCpu->vm.s.pNormalReqs || pUVCpu->vm.s.pPriorityReqs)
141 {
142 /*
143 * Service execute in specific EMT request.
144 */
145 rc = VMR3ReqProcessU(pUVM, pUVCpu->idCpu, false /*fPriorityOnly*/);
146 Log(("vmR3EmulationThread: Req (cpu=%u) rc=%Rrc, VM state %s -> %s\n", pUVCpu->idCpu, rc, VMR3GetStateName(enmBefore), pUVM->pVM ? VMR3GetStateName(pUVM->pVM->enmVMState) : "CREATING"));
147 }
148 else
149 {
150 /*
151 * Nothing important is pending, so wait for something.
152 */
153 rc = VMR3WaitU(pUVCpu);
154 if (RT_FAILURE(rc))
155 {
156 AssertLogRelMsgFailed(("VMR3WaitU failed with %Rrc\n", rc));
157 break;
158 }
159 }
160 }
161 else
162 {
163 /*
164 * Pending requests which needs servicing?
165 *
166 * We check for state changes in addition to status codes when
167 * servicing requests. (Look after the ifs.)
168 */
169#ifdef LOG_ENABLED
170 enmBefore = pVM->enmVMState;
171#endif
172 if (pUVM->vm.s.fTerminateEMT)
173 {
174 rc = VINF_EM_TERMINATE;
175 break;
176 }
177
178 if (VM_FF_IS_SET(pVM, VM_FF_EMT_RENDEZVOUS))
179 {
180 rc = VMMR3EmtRendezvousFF(pVM, pVM->apCpusR3[idCpu]);
181 Log(("vmR3EmulationThread: Rendezvous rc=%Rrc, VM state %s -> %s\n", rc, VMR3GetStateName(enmBefore), VMR3GetStateName(pVM->enmVMState)));
182 }
183 else if (pUVM->vm.s.pNormalReqs || pUVM->vm.s.pPriorityReqs)
184 {
185 /*
186 * Service execute in any EMT request.
187 */
188 rc = VMR3ReqProcessU(pUVM, VMCPUID_ANY, false /*fPriorityOnly*/);
189 Log(("vmR3EmulationThread: Req rc=%Rrc, VM state %s -> %s\n", rc, VMR3GetStateName(enmBefore), VMR3GetStateName(pVM->enmVMState)));
190 }
191 else if (pUVCpu->vm.s.pNormalReqs || pUVCpu->vm.s.pPriorityReqs)
192 {
193 /*
194 * Service execute in specific EMT request.
195 */
196 rc = VMR3ReqProcessU(pUVM, pUVCpu->idCpu, false /*fPriorityOnly*/);
197 Log(("vmR3EmulationThread: Req (cpu=%u) rc=%Rrc, VM state %s -> %s\n", pUVCpu->idCpu, rc, VMR3GetStateName(enmBefore), VMR3GetStateName(pVM->enmVMState)));
198 }
199 else if ( VM_FF_IS_SET(pVM, VM_FF_DBGF)
200 || VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_DBGF))
201 {
202 /*
203 * Service the debugger request.
204 */
205 rc = DBGFR3VMMForcedAction(pVM, pVCpu);
206 Log(("vmR3EmulationThread: Dbg rc=%Rrc, VM state %s -> %s\n", rc, VMR3GetStateName(enmBefore), VMR3GetStateName(pVM->enmVMState)));
207 }
208 else if (VM_FF_TEST_AND_CLEAR(pVM, VM_FF_RESET))
209 {
210 /*
211 * Service a delayed reset request.
212 */
213 rc = VBOXSTRICTRC_VAL(VMR3ResetFF(pVM));
214 VM_FF_CLEAR(pVM, VM_FF_RESET);
215 Log(("vmR3EmulationThread: Reset rc=%Rrc, VM state %s -> %s\n", rc, VMR3GetStateName(enmBefore), VMR3GetStateName(pVM->enmVMState)));
216 }
217 else
218 {
219 /*
220 * Nothing important is pending, so wait for something.
221 */
222 rc = VMR3WaitU(pUVCpu);
223 if (RT_FAILURE(rc))
224 {
225 AssertLogRelMsgFailed(("VMR3WaitU failed with %Rrc\n", rc));
226 break;
227 }
228 }
229
230 /*
231 * Check for termination requests, these have extremely high priority.
232 */
233 if ( rc == VINF_EM_TERMINATE
234 || pUVM->vm.s.fTerminateEMT)
235 break;
236 }
237
238 /*
239 * Some requests (both VMR3Req* and the DBGF) can potentially resume
240 * or start the VM, in that case we'll get a change in VM status
241 * indicating that we're now running.
242 */
243 if (RT_SUCCESS(rc))
244 {
245 pVM = pUVM->pVM;
246 if (pVM)
247 {
248 pVCpu = pVM->apCpusR3[idCpu];
249 if ( pVM->enmVMState == VMSTATE_RUNNING
250 && VMCPUSTATE_IS_STARTED(VMCPU_GET_STATE(pVCpu)))
251 {
252 rc = EMR3ExecuteVM(pVM, pVCpu);
253 Log(("vmR3EmulationThread: EMR3ExecuteVM() -> rc=%Rrc, enmVMState=%d\n", rc, pVM->enmVMState));
254 }
255 }
256 }
257
258 } /* forever */
259
260
261 /*
262 * Decrement the active EMT count if we haven't done it yet in vmR3Destroy.
263 */
264 if (!pUVCpu->vm.s.fBeenThruVmDestroy)
265 ASMAtomicDecU32(&pUVM->vm.s.cActiveEmts);
266
267
268 /*
269 * Cleanup and exit.
270 * EMT0 does the VM destruction after all other EMTs have deregistered and terminated.
271 */
272 Log(("vmR3EmulationThread: Terminating emulation thread! Thread=%#x pUVM=%p rc=%Rrc enmBefore=%d enmVMState=%d\n",
273 hThreadSelf, pUVM, rc, enmBefore, pUVM->pVM ? pUVM->pVM->enmVMState : VMSTATE_TERMINATED));
274 PVM pVM;
275 if ( idCpu == 0
276 && (pVM = pUVM->pVM) != NULL)
277 {
278 /* Wait for any other EMTs to terminate before we destroy the VM (see vmR3DestroyVM). */
279 for (VMCPUID iCpu = 1; iCpu < pUVM->cCpus; iCpu++)
280 {
281 RTTHREAD hThread;
282 ASMAtomicXchgHandle(&pUVM->aCpus[iCpu].vm.s.ThreadEMT, NIL_RTTHREAD, &hThread);
283 if (hThread != NIL_RTTHREAD)
284 {
285 int rc2 = RTThreadWait(hThread, 5 * RT_MS_1SEC, NULL);
286 AssertLogRelMsgRC(rc2, ("iCpu=%u rc=%Rrc\n", iCpu, rc2));
287 if (RT_FAILURE(rc2))
288 pUVM->aCpus[iCpu].vm.s.ThreadEMT = hThread;
289 }
290 }
291
292 /* Switch to the terminated state, clearing the VM pointer and finally destroy the VM. */
293 vmR3SetTerminated(pVM);
294
295 pUVM->pVM = NULL;
296 for (VMCPUID iCpu = 0; iCpu < pUVM->cCpus; iCpu++)
297 {
298 pUVM->aCpus[iCpu].pVM = NULL;
299 pUVM->aCpus[iCpu].pVCpu = NULL;
300 }
301
302 int rc2 = GVMMR3DestroyVM(pUVM, pVM);
303 AssertLogRelRC(rc2);
304 }
305 /* Deregister the EMT with VMMR0. */
306 else if ( idCpu != 0
307 && (pVM = pUVM->pVM) != NULL)
308 {
309 int rc2 = GVMMR3DeregisterVCpu(pVM, idCpu);
310 AssertLogRelRC(rc2);
311 }
312
313 if ( pUVM->pVmm2UserMethods
314 && pUVM->pVmm2UserMethods->pfnNotifyEmtTerm)
315 pUVM->pVmm2UserMethods->pfnNotifyEmtTerm(pUVM->pVmm2UserMethods, pUVM, pUVCpu);
316
317 pUVCpu->vm.s.NativeThreadEMT = NIL_RTNATIVETHREAD;
318 Log(("vmR3EmulationThread: EMT is terminated.\n"));
319 return rc;
320}
321
322
323/**
324 * Gets the name of a halt method.
325 *
326 * @returns Pointer to a read only string.
327 * @param enmMethod The method.
328 */
329static const char *vmR3GetHaltMethodName(VMHALTMETHOD enmMethod)
330{
331 switch (enmMethod)
332 {
333 case VMHALTMETHOD_BOOTSTRAP: return "bootstrap";
334 case VMHALTMETHOD_DEFAULT: return "default";
335 case VMHALTMETHOD_OLD: return "old";
336 case VMHALTMETHOD_1: return "method1";
337 //case VMHALTMETHOD_2: return "method2";
338 case VMHALTMETHOD_GLOBAL_1: return "global1";
339 default: return "unknown";
340 }
341}
342
343
344/**
345 * Signal a fatal wait error.
346 *
347 * @returns Fatal error code to be propagated up the call stack.
348 * @param pUVCpu The user mode per CPU structure of the calling
349 * EMT.
350 * @param pszFmt The error format with a single %Rrc in it.
351 * @param rcFmt The status code to format.
352 */
353static int vmR3FatalWaitError(PUVMCPU pUVCpu, const char *pszFmt, int rcFmt)
354{
355 /** @todo This is wrong ... raise a fatal error / guru meditation
356 * instead. */
357 AssertLogRelMsgFailed((pszFmt, rcFmt));
358 ASMAtomicUoWriteBool(&pUVCpu->pUVM->vm.s.fTerminateEMT, true);
359 if (pUVCpu->pVM)
360 VM_FF_SET(pUVCpu->pVM, VM_FF_CHECK_VM_STATE);
361 return VERR_VM_FATAL_WAIT_ERROR;
362}
363
364
365/**
366 * The old halt loop.
367 */
368static DECLCALLBACK(int) vmR3HaltOldDoHalt(PUVMCPU pUVCpu, const uint64_t fMask, uint64_t /* u64Now*/)
369{
370 /*
371 * Halt loop.
372 */
373 PVM pVM = pUVCpu->pVM;
374 PVMCPU pVCpu = pUVCpu->pVCpu;
375
376 int rc = VINF_SUCCESS;
377 ASMAtomicWriteBool(&pUVCpu->vm.s.fWait, true);
378 //unsigned cLoops = 0;
379 for (;;)
380 {
381 /*
382 * Work the timers and check if we can exit.
383 * The poll call gives us the ticks left to the next event in
384 * addition to perhaps set an FF.
385 */
386 uint64_t const u64StartTimers = RTTimeNanoTS();
387 TMR3TimerQueuesDo(pVM);
388 uint64_t const cNsElapsedTimers = RTTimeNanoTS() - u64StartTimers;
389 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltTimers, cNsElapsedTimers);
390 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_EXTERNAL_HALTED_MASK)
391 || VMCPU_FF_IS_ANY_SET(pVCpu, fMask))
392 break;
393 uint64_t u64NanoTS;
394 TMTimerPollGIP(pVM, pVCpu, &u64NanoTS);
395 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_EXTERNAL_HALTED_MASK)
396 || VMCPU_FF_IS_ANY_SET(pVCpu, fMask))
397 break;
398
399 /*
400 * Wait for a while. Someone will wake us up or interrupt the call if
401 * anything needs our attention.
402 */
403 if (u64NanoTS < 50000)
404 {
405 //RTLogPrintf("u64NanoTS=%RI64 cLoops=%d spin\n", u64NanoTS, cLoops++);
406 /* spin */;
407 }
408 else
409 {
410 VMMR3YieldStop(pVM);
411 //uint64_t u64Start = RTTimeNanoTS();
412 if (u64NanoTS < 870000) /* this is a bit speculative... works fine on linux. */
413 {
414 //RTLogPrintf("u64NanoTS=%RI64 cLoops=%d yield", u64NanoTS, cLoops++);
415 uint64_t const u64StartSchedYield = RTTimeNanoTS();
416 RTThreadYield(); /* this is the best we can do here */
417 uint64_t const cNsElapsedSchedYield = RTTimeNanoTS() - u64StartSchedYield;
418 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltYield, cNsElapsedSchedYield);
419 }
420 else if (u64NanoTS < 2000000)
421 {
422 //RTLogPrintf("u64NanoTS=%RI64 cLoops=%d sleep 1ms", u64NanoTS, cLoops++);
423 uint64_t const u64StartSchedHalt = RTTimeNanoTS();
424 rc = RTSemEventWait(pUVCpu->vm.s.EventSemWait, 1);
425 uint64_t const cNsElapsedSchedHalt = RTTimeNanoTS() - u64StartSchedHalt;
426 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltBlock, cNsElapsedSchedHalt);
427 }
428 else
429 {
430 //RTLogPrintf("u64NanoTS=%RI64 cLoops=%d sleep %dms", u64NanoTS, cLoops++, (uint32_t)RT_MIN((u64NanoTS - 500000) / 1000000, 15));
431 uint64_t const u64StartSchedHalt = RTTimeNanoTS();
432 rc = RTSemEventWait(pUVCpu->vm.s.EventSemWait, RT_MIN((u64NanoTS - 1000000) / 1000000, 15));
433 uint64_t const cNsElapsedSchedHalt = RTTimeNanoTS() - u64StartSchedHalt;
434 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltBlock, cNsElapsedSchedHalt);
435 }
436 //uint64_t u64Slept = RTTimeNanoTS() - u64Start;
437 //RTLogPrintf(" -> rc=%Rrc in %RU64 ns / %RI64 ns delta\n", rc, u64Slept, u64NanoTS - u64Slept);
438 }
439 if (rc == VERR_TIMEOUT)
440 rc = VINF_SUCCESS;
441 else if (RT_FAILURE(rc))
442 {
443 rc = vmR3FatalWaitError(pUVCpu, "RTSemEventWait->%Rrc\n", rc);
444 break;
445 }
446 }
447
448 ASMAtomicUoWriteBool(&pUVCpu->vm.s.fWait, false);
449 return rc;
450}
451
452
453/**
454 * Initialize the configuration of halt method 1 & 2.
455 *
456 * @return VBox status code. Failure on invalid CFGM data.
457 * @param pUVM The user mode VM structure.
458 */
459static int vmR3HaltMethod12ReadConfigU(PUVM pUVM)
460{
461 /*
462 * The defaults.
463 */
464#if 1 /* DEBUGGING STUFF - REMOVE LATER */
465 pUVM->vm.s.Halt.Method12.u32LagBlockIntervalDivisorCfg = 4;
466 pUVM->vm.s.Halt.Method12.u32MinBlockIntervalCfg = 2*1000000;
467 pUVM->vm.s.Halt.Method12.u32MaxBlockIntervalCfg = 75*1000000;
468 pUVM->vm.s.Halt.Method12.u32StartSpinningCfg = 30*1000000;
469 pUVM->vm.s.Halt.Method12.u32StopSpinningCfg = 20*1000000;
470#else
471 pUVM->vm.s.Halt.Method12.u32LagBlockIntervalDivisorCfg = 4;
472 pUVM->vm.s.Halt.Method12.u32MinBlockIntervalCfg = 5*1000000;
473 pUVM->vm.s.Halt.Method12.u32MaxBlockIntervalCfg = 200*1000000;
474 pUVM->vm.s.Halt.Method12.u32StartSpinningCfg = 20*1000000;
475 pUVM->vm.s.Halt.Method12.u32StopSpinningCfg = 2*1000000;
476#endif
477
478 /*
479 * Query overrides.
480 *
481 * I don't have time to bother with niceties such as invalid value checks
482 * here right now. sorry.
483 */
484 PCFGMNODE pCfg = CFGMR3GetChild(CFGMR3GetRoot(pUVM->pVM), "/VMM/HaltedMethod1");
485 if (pCfg)
486 {
487 uint32_t u32;
488 if (RT_SUCCESS(CFGMR3QueryU32(pCfg, "LagBlockIntervalDivisor", &u32)))
489 pUVM->vm.s.Halt.Method12.u32LagBlockIntervalDivisorCfg = u32;
490 if (RT_SUCCESS(CFGMR3QueryU32(pCfg, "MinBlockInterval", &u32)))
491 pUVM->vm.s.Halt.Method12.u32MinBlockIntervalCfg = u32;
492 if (RT_SUCCESS(CFGMR3QueryU32(pCfg, "MaxBlockInterval", &u32)))
493 pUVM->vm.s.Halt.Method12.u32MaxBlockIntervalCfg = u32;
494 if (RT_SUCCESS(CFGMR3QueryU32(pCfg, "StartSpinning", &u32)))
495 pUVM->vm.s.Halt.Method12.u32StartSpinningCfg = u32;
496 if (RT_SUCCESS(CFGMR3QueryU32(pCfg, "StopSpinning", &u32)))
497 pUVM->vm.s.Halt.Method12.u32StopSpinningCfg = u32;
498 LogRel(("VMEmt: HaltedMethod1 config: %d/%d/%d/%d/%d\n",
499 pUVM->vm.s.Halt.Method12.u32LagBlockIntervalDivisorCfg,
500 pUVM->vm.s.Halt.Method12.u32MinBlockIntervalCfg,
501 pUVM->vm.s.Halt.Method12.u32MaxBlockIntervalCfg,
502 pUVM->vm.s.Halt.Method12.u32StartSpinningCfg,
503 pUVM->vm.s.Halt.Method12.u32StopSpinningCfg));
504 }
505
506 return VINF_SUCCESS;
507}
508
509
510/**
511 * Initialize halt method 1.
512 *
513 * @return VBox status code.
514 * @param pUVM Pointer to the user mode VM structure.
515 */
516static DECLCALLBACK(int) vmR3HaltMethod1Init(PUVM pUVM)
517{
518 return vmR3HaltMethod12ReadConfigU(pUVM);
519}
520
521
522/**
523 * Method 1 - Block whenever possible, and when lagging behind
524 * switch to spinning for 10-30ms with occasional blocking until
525 * the lag has been eliminated.
526 */
527static DECLCALLBACK(int) vmR3HaltMethod1Halt(PUVMCPU pUVCpu, const uint64_t fMask, uint64_t u64Now)
528{
529 PUVM pUVM = pUVCpu->pUVM;
530 PVMCPU pVCpu = pUVCpu->pVCpu;
531 PVM pVM = pUVCpu->pVM;
532
533 /*
534 * To simplify things, we decide up-front whether we should switch to spinning or
535 * not. This makes some ASSUMPTIONS about the cause of the spinning (PIT/RTC/PCNet)
536 * and that it will generate interrupts or other events that will cause us to exit
537 * the halt loop.
538 */
539 bool fBlockOnce = false;
540 bool fSpinning = false;
541 uint32_t u32CatchUpPct = TMVirtualSyncGetCatchUpPct(pVM);
542 if (u32CatchUpPct /* non-zero if catching up */)
543 {
544 if (pUVCpu->vm.s.Halt.Method12.u64StartSpinTS)
545 {
546 fSpinning = TMVirtualSyncGetLag(pVM) >= pUVM->vm.s.Halt.Method12.u32StopSpinningCfg;
547 if (fSpinning)
548 {
549 uint64_t u64Lag = TMVirtualSyncGetLag(pVM);
550 fBlockOnce = u64Now - pUVCpu->vm.s.Halt.Method12.u64LastBlockTS
551 > RT_MAX(pUVM->vm.s.Halt.Method12.u32MinBlockIntervalCfg,
552 RT_MIN(u64Lag / pUVM->vm.s.Halt.Method12.u32LagBlockIntervalDivisorCfg,
553 pUVM->vm.s.Halt.Method12.u32MaxBlockIntervalCfg));
554 }
555 else
556 {
557 //RTLogRelPrintf("Stopped spinning (%u ms)\n", (u64Now - pUVCpu->vm.s.Halt.Method12.u64StartSpinTS) / 1000000);
558 pUVCpu->vm.s.Halt.Method12.u64StartSpinTS = 0;
559 }
560 }
561 else
562 {
563 fSpinning = TMVirtualSyncGetLag(pVM) >= pUVM->vm.s.Halt.Method12.u32StartSpinningCfg;
564 if (fSpinning)
565 pUVCpu->vm.s.Halt.Method12.u64StartSpinTS = u64Now;
566 }
567 }
568 else if (pUVCpu->vm.s.Halt.Method12.u64StartSpinTS)
569 {
570 //RTLogRelPrintf("Stopped spinning (%u ms)\n", (u64Now - pUVCpu->vm.s.Halt.Method12.u64StartSpinTS) / 1000000);
571 pUVCpu->vm.s.Halt.Method12.u64StartSpinTS = 0;
572 }
573
574#ifdef VBOX_VMM_TARGET_ARMV8
575 uint64_t cNsVTimerActivate = TMCpuGetVTimerActivationNano(pVCpu);
576 const bool fVTimerActive = cNsVTimerActivate != UINT64_MAX;
577#endif
578
579 /*
580 * Halt loop.
581 */
582 int rc = VINF_SUCCESS;
583 ASMAtomicWriteBool(&pUVCpu->vm.s.fWait, true);
584 unsigned cLoops = 0;
585 for (;; cLoops++)
586 {
587 /*
588 * Work the timers and check if we can exit.
589 */
590 uint64_t const u64StartTimers = RTTimeNanoTS();
591 TMR3TimerQueuesDo(pVM);
592 uint64_t const cNsElapsedTimers = RTTimeNanoTS() - u64StartTimers;
593 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltTimers, cNsElapsedTimers);
594 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_EXTERNAL_HALTED_MASK)
595 || VMCPU_FF_IS_ANY_SET(pVCpu, fMask)
596#ifdef VBOX_VMM_TARGET_ARMV8
597 || cNsElapsedTimers >= cNsVTimerActivate
598#endif
599 )
600 {
601#ifdef VBOX_VMM_TARGET_ARMV8
602 cNsVTimerActivate = 0;
603#endif
604 break;
605 }
606
607#ifdef VBOX_VMM_TARGET_ARMV8
608 cNsVTimerActivate -= cNsElapsedTimers;
609#endif
610
611 /*
612 * Estimate time left to the next event.
613 */
614 uint64_t u64NanoTS;
615 TMTimerPollGIP(pVM, pVCpu, &u64NanoTS);
616 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_EXTERNAL_HALTED_MASK)
617 || VMCPU_FF_IS_ANY_SET(pVCpu, fMask))
618 break;
619
620#ifdef VBOX_VMM_TARGET_ARMV8
621 u64NanoTS = RT_MIN(cNsVTimerActivate, u64NanoTS);
622#endif
623
624 /*
625 * Block if we're not spinning and the interval isn't all that small.
626 */
627 if ( ( !fSpinning
628 || fBlockOnce)
629#if 1 /* DEBUGGING STUFF - REMOVE LATER */
630 && u64NanoTS >= 100000) /* 0.100 ms */
631#else
632 && u64NanoTS >= 250000) /* 0.250 ms */
633#endif
634 {
635 const uint64_t Start = pUVCpu->vm.s.Halt.Method12.u64LastBlockTS = RTTimeNanoTS();
636 VMMR3YieldStop(pVM);
637
638 uint32_t cMilliSecs = RT_MIN(u64NanoTS / RT_NS_1MS, 15);
639 if (cMilliSecs <= pUVCpu->vm.s.Halt.Method12.cNSBlockedTooLongAvg / RT_NS_1MS)
640 cMilliSecs = 1;
641 else
642 cMilliSecs -= pUVCpu->vm.s.Halt.Method12.cNSBlockedTooLongAvg / RT_NS_1MS;
643
644 //RTLogRelPrintf("u64NanoTS=%RI64 cLoops=%3d sleep %02dms (%7RU64) ", u64NanoTS, cLoops, cMilliSecs, u64NanoTS);
645 uint64_t const u64StartSchedHalt = RTTimeNanoTS();
646 rc = RTSemEventWait(pUVCpu->vm.s.EventSemWait, cMilliSecs);
647 uint64_t const cNsElapsedSchedHalt = RTTimeNanoTS() - u64StartSchedHalt;
648 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltBlock, cNsElapsedSchedHalt);
649
650 if (rc == VERR_TIMEOUT)
651 rc = VINF_SUCCESS;
652 else if (RT_FAILURE(rc))
653 {
654 rc = vmR3FatalWaitError(pUVCpu, "RTSemEventWait->%Rrc\n", rc);
655 break;
656 }
657
658 /*
659 * Calc the statistics.
660 * Update averages every 16th time, and flush parts of the history every 64th time.
661 */
662 const uint64_t Elapsed = RTTimeNanoTS() - Start;
663 pUVCpu->vm.s.Halt.Method12.cNSBlocked += Elapsed;
664 if (Elapsed > u64NanoTS)
665 pUVCpu->vm.s.Halt.Method12.cNSBlockedTooLong += Elapsed - u64NanoTS;
666 pUVCpu->vm.s.Halt.Method12.cBlocks++;
667 if (!(pUVCpu->vm.s.Halt.Method12.cBlocks & 0xf))
668 {
669 pUVCpu->vm.s.Halt.Method12.cNSBlockedTooLongAvg = pUVCpu->vm.s.Halt.Method12.cNSBlockedTooLong / pUVCpu->vm.s.Halt.Method12.cBlocks;
670 if (!(pUVCpu->vm.s.Halt.Method12.cBlocks & 0x3f))
671 {
672 pUVCpu->vm.s.Halt.Method12.cNSBlockedTooLong = pUVCpu->vm.s.Halt.Method12.cNSBlockedTooLongAvg * 0x40;
673 pUVCpu->vm.s.Halt.Method12.cBlocks = 0x40;
674 }
675 }
676 //RTLogRelPrintf(" -> %7RU64 ns / %7RI64 ns delta%s\n", Elapsed, Elapsed - u64NanoTS, fBlockOnce ? " (block once)" : "");
677
678 /*
679 * Clear the block once flag if we actually blocked.
680 */
681 if ( fBlockOnce
682 && Elapsed > 100000 /* 0.1 ms */)
683 fBlockOnce = false;
684
685#ifdef VBOX_VMM_TARGET_ARMV8
686 cNsVTimerActivate -= RT_MIN(cNsVTimerActivate, Elapsed);
687 /* Did the vTimer expire? */
688 if (!cNsVTimerActivate)
689 break;
690#endif
691 }
692 }
693 //if (fSpinning) RTLogRelPrintf("spun for %RU64 ns %u loops; lag=%RU64 pct=%d\n", RTTimeNanoTS() - u64Now, cLoops, TMVirtualSyncGetLag(pVM), u32CatchUpPct);
694
695#ifdef VBOX_VMM_TARGET_ARMV8
696 if (fVTimerActive)
697 {
698 if (!cNsVTimerActivate)
699 VMCPU_FF_SET(pVCpu, VMCPU_FF_VTIMER_ACTIVATED);
700
701 TMCpuSetVTimerNextActivation(pVCpu, cNsVTimerActivate);
702 }
703#endif
704 ASMAtomicUoWriteBool(&pUVCpu->vm.s.fWait, false);
705 return rc;
706}
707
708
709/**
710 * Initialize the global 1 halt method.
711 *
712 * @return VBox status code.
713 * @param pUVM Pointer to the user mode VM structure.
714 */
715static DECLCALLBACK(int) vmR3HaltGlobal1Init(PUVM pUVM)
716{
717 /*
718 * The defaults.
719 */
720 uint32_t cNsResolution = SUPSemEventMultiGetResolution(pUVM->vm.s.pSession);
721 if (cNsResolution > 5*RT_NS_100US)
722 pUVM->vm.s.Halt.Global1.cNsSpinBlockThresholdCfg = 50000;
723 else if (cNsResolution > RT_NS_100US)
724 pUVM->vm.s.Halt.Global1.cNsSpinBlockThresholdCfg = cNsResolution / 4;
725 else
726 pUVM->vm.s.Halt.Global1.cNsSpinBlockThresholdCfg = 2000;
727
728 /*
729 * Query overrides.
730 *
731 * I don't have time to bother with niceties such as invalid value checks
732 * here right now. sorry.
733 */
734 PCFGMNODE pCfg = CFGMR3GetChild(CFGMR3GetRoot(pUVM->pVM), "/VMM/HaltedGlobal1");
735 if (pCfg)
736 {
737 uint32_t u32;
738 if (RT_SUCCESS(CFGMR3QueryU32(pCfg, "SpinBlockThreshold", &u32)))
739 pUVM->vm.s.Halt.Global1.cNsSpinBlockThresholdCfg = u32;
740 }
741 LogRel(("VMEmt: HaltedGlobal1 config: cNsSpinBlockThresholdCfg=%u\n",
742 pUVM->vm.s.Halt.Global1.cNsSpinBlockThresholdCfg));
743 return VINF_SUCCESS;
744}
745
746
747/**
748 * The global 1 halt method - Block in GMM (ring-0) and let it
749 * try take care of the global scheduling of EMT threads.
750 */
751static DECLCALLBACK(int) vmR3HaltGlobal1Halt(PUVMCPU pUVCpu, const uint64_t fMask, uint64_t u64Now)
752{
753 PUVM pUVM = pUVCpu->pUVM;
754 PVMCPU pVCpu = pUVCpu->pVCpu;
755 PVM pVM = pUVCpu->pVM;
756 Assert(VMMGetCpu(pVM) == pVCpu);
757 NOREF(u64Now);
758
759 /*
760 * Halt loop.
761 */
762 //uint64_t u64NowLog, u64Start;
763 //u64Start = u64NowLog = RTTimeNanoTS();
764 int rc = VINF_SUCCESS;
765 ASMAtomicWriteBool(&pUVCpu->vm.s.fWait, true);
766 unsigned cLoops = 0;
767 for (;; cLoops++)
768 {
769 /*
770 * Work the timers and check if we can exit.
771 */
772 uint64_t const u64StartTimers = RTTimeNanoTS();
773 TMR3TimerQueuesDo(pVM);
774 uint64_t const cNsElapsedTimers = RTTimeNanoTS() - u64StartTimers;
775 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltTimers, cNsElapsedTimers);
776 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_EXTERNAL_HALTED_MASK)
777 || VMCPU_FF_IS_ANY_SET(pVCpu, fMask))
778 break;
779
780 /*
781 * Estimate time left to the next event.
782 */
783 //u64NowLog = RTTimeNanoTS();
784 uint64_t u64Delta;
785 uint64_t u64GipTime = TMTimerPollGIP(pVM, pVCpu, &u64Delta);
786 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_EXTERNAL_HALTED_MASK)
787 || VMCPU_FF_IS_ANY_SET(pVCpu, fMask))
788 break;
789
790 /*
791 * Block if we're not spinning and the interval isn't all that small.
792 */
793 if (u64Delta >= pUVM->vm.s.Halt.Global1.cNsSpinBlockThresholdCfg)
794 {
795 VMMR3YieldStop(pVM);
796 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_EXTERNAL_HALTED_MASK)
797 || VMCPU_FF_IS_ANY_SET(pVCpu, fMask))
798 break;
799
800 //RTLogPrintf("loop=%-3d u64GipTime=%'llu / %'llu now=%'llu / %'llu\n", cLoops, u64GipTime, u64Delta, u64NowLog, u64GipTime - u64NowLog);
801 uint64_t const u64StartSchedHalt = RTTimeNanoTS();
802 rc = SUPR3CallVMMR0Ex(VMCC_GET_VMR0_FOR_CALL(pVM), pVCpu->idCpu, VMMR0_DO_GVMM_SCHED_HALT, u64GipTime, NULL);
803 uint64_t const u64EndSchedHalt = RTTimeNanoTS();
804 uint64_t const cNsElapsedSchedHalt = u64EndSchedHalt - u64StartSchedHalt;
805 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltBlock, cNsElapsedSchedHalt);
806
807 if (rc == VERR_INTERRUPTED)
808 rc = VINF_SUCCESS;
809 else if (RT_FAILURE(rc))
810 {
811 rc = vmR3FatalWaitError(pUVCpu, "vmR3HaltGlobal1Halt: VMMR0_DO_GVMM_SCHED_HALT->%Rrc\n", rc);
812 break;
813 }
814 else
815 {
816 int64_t const cNsOverslept = u64EndSchedHalt - u64GipTime;
817 if (cNsOverslept > 50000)
818 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltBlockOverslept, cNsOverslept);
819 else if (cNsOverslept < -50000)
820 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltBlockInsomnia, cNsElapsedSchedHalt);
821 else
822 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltBlockOnTime, cNsElapsedSchedHalt);
823 }
824 }
825 /*
826 * When spinning call upon the GVMM and do some wakups once
827 * in a while, it's not like we're actually busy or anything.
828 */
829 else if (!(cLoops & 0x1fff))
830 {
831 uint64_t const u64StartSchedYield = RTTimeNanoTS();
832 rc = SUPR3CallVMMR0Ex(VMCC_GET_VMR0_FOR_CALL(pVM), pVCpu->idCpu, VMMR0_DO_GVMM_SCHED_POLL, false /* don't yield */, NULL);
833 uint64_t const cNsElapsedSchedYield = RTTimeNanoTS() - u64StartSchedYield;
834 STAM_REL_PROFILE_ADD_PERIOD(&pUVCpu->vm.s.StatHaltYield, cNsElapsedSchedYield);
835 }
836 }
837 //RTLogPrintf("*** %u loops %'llu; lag=%RU64\n", cLoops, u64NowLog - u64Start, TMVirtualSyncGetLag(pVM));
838
839 ASMAtomicUoWriteBool(&pUVCpu->vm.s.fWait, false);
840 return rc;
841}
842
843
844/**
845 * The global 1 halt method - VMR3Wait() worker.
846 *
847 * @returns VBox status code.
848 * @param pUVCpu Pointer to the user mode VMCPU structure.
849 */
850static DECLCALLBACK(int) vmR3HaltGlobal1Wait(PUVMCPU pUVCpu)
851{
852 ASMAtomicWriteBool(&pUVCpu->vm.s.fWait, true);
853
854 PVM pVM = pUVCpu->pUVM->pVM;
855 PVMCPU pVCpu = VMMGetCpu(pVM);
856 Assert(pVCpu->idCpu == pUVCpu->idCpu);
857
858 int rc = VINF_SUCCESS;
859 for (;;)
860 {
861 /*
862 * Check Relevant FFs.
863 */
864 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_EXTERNAL_SUSPENDED_MASK)
865 || VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_EXTERNAL_SUSPENDED_MASK))
866 break;
867
868 /*
869 * Wait for a while. Someone will wake us up or interrupt the call if
870 * anything needs our attention.
871 */
872 rc = SUPR3CallVMMR0Ex(VMCC_GET_VMR0_FOR_CALL(pVM), pVCpu->idCpu, VMMR0_DO_GVMM_SCHED_HALT, RTTimeNanoTS() + 1000000000 /* +1s */, NULL);
873 if (rc == VERR_INTERRUPTED)
874 rc = VINF_SUCCESS;
875 else if (RT_FAILURE(rc))
876 {
877 rc = vmR3FatalWaitError(pUVCpu, "vmR3HaltGlobal1Wait: VMMR0_DO_GVMM_SCHED_HALT->%Rrc\n", rc);
878 break;
879 }
880 }
881
882 ASMAtomicUoWriteBool(&pUVCpu->vm.s.fWait, false);
883 return rc;
884}
885
886
887/**
888 * The global 1 halt method - VMR3NotifyFF() worker.
889 *
890 * @param pUVCpu Pointer to the user mode VMCPU structure.
891 * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_*.
892 */
893static DECLCALLBACK(void) vmR3HaltGlobal1NotifyCpuFF(PUVMCPU pUVCpu, uint32_t fFlags)
894{
895 /*
896 * With ring-0 halting, the fWait flag isn't set, so we have to check the
897 * CPU state to figure out whether to do a wakeup call.
898 */
899 PVMCPU pVCpu = pUVCpu->pVCpu;
900 if (pVCpu)
901 {
902 VMCPUSTATE enmState = VMCPU_GET_STATE(pVCpu);
903 if (enmState == VMCPUSTATE_STARTED_HALTED || pUVCpu->vm.s.fWait)
904 {
905 int rc = SUPR3CallVMMR0Ex(VMCC_GET_VMR0_FOR_CALL(pUVCpu->pVM), pUVCpu->idCpu, VMMR0_DO_GVMM_SCHED_WAKE_UP, 0, NULL);
906 AssertRC(rc);
907
908 }
909 else if ( (fFlags & VMNOTIFYFF_FLAGS_POKE)
910 || !(fFlags & VMNOTIFYFF_FLAGS_DONE_REM))
911 {
912 if (enmState == VMCPUSTATE_STARTED_EXEC)
913 {
914 if (fFlags & VMNOTIFYFF_FLAGS_POKE)
915 {
916 int rc = SUPR3CallVMMR0Ex(VMCC_GET_VMR0_FOR_CALL(pUVCpu->pVM), pUVCpu->idCpu, VMMR0_DO_GVMM_SCHED_POKE, 0, NULL);
917 AssertRC(rc);
918 }
919 }
920 else if ( enmState == VMCPUSTATE_STARTED_EXEC_NEM
921 || enmState == VMCPUSTATE_STARTED_EXEC_NEM_WAIT)
922 NEMR3NotifyFF(pUVCpu->pVM, pVCpu, fFlags);
923 }
924 }
925 /* This probably makes little sense: */
926 else if (pUVCpu->vm.s.fWait)
927 {
928 int rc = SUPR3CallVMMR0Ex(VMCC_GET_VMR0_FOR_CALL(pUVCpu->pVM), pUVCpu->idCpu, VMMR0_DO_GVMM_SCHED_WAKE_UP, 0, NULL);
929 AssertRC(rc);
930 }
931}
932
933
934/**
935 * Bootstrap VMR3Wait() worker.
936 *
937 * @returns VBox status code.
938 * @param pUVCpu Pointer to the user mode VMCPU structure.
939 */
940static DECLCALLBACK(int) vmR3BootstrapWait(PUVMCPU pUVCpu)
941{
942 PUVM pUVM = pUVCpu->pUVM;
943
944 ASMAtomicWriteBool(&pUVCpu->vm.s.fWait, true);
945
946 int rc = VINF_SUCCESS;
947 for (;;)
948 {
949 /*
950 * Check Relevant FFs.
951 */
952 if (pUVM->vm.s.pNormalReqs || pUVM->vm.s.pPriorityReqs) /* global requests pending? */
953 break;
954 if (pUVCpu->vm.s.pNormalReqs || pUVCpu->vm.s.pPriorityReqs) /* local requests pending? */
955 break;
956
957 if ( pUVCpu->pVM
958 && ( VM_FF_IS_ANY_SET(pUVCpu->pVM, VM_FF_EXTERNAL_SUSPENDED_MASK)
959 || VMCPU_FF_IS_ANY_SET(VMMGetCpu(pUVCpu->pVM), VMCPU_FF_EXTERNAL_SUSPENDED_MASK)
960 )
961 )
962 break;
963 if (pUVM->vm.s.fTerminateEMT)
964 break;
965
966 /*
967 * Wait for a while. Someone will wake us up or interrupt the call if
968 * anything needs our attention.
969 */
970 rc = RTSemEventWait(pUVCpu->vm.s.EventSemWait, 1000);
971 if (rc == VERR_TIMEOUT)
972 rc = VINF_SUCCESS;
973 else if (RT_FAILURE(rc))
974 {
975 rc = vmR3FatalWaitError(pUVCpu, "RTSemEventWait->%Rrc\n", rc);
976 break;
977 }
978 }
979
980 ASMAtomicUoWriteBool(&pUVCpu->vm.s.fWait, false);
981 return rc;
982}
983
984
985/**
986 * Bootstrap VMR3NotifyFF() worker.
987 *
988 * @param pUVCpu Pointer to the user mode VMCPU structure.
989 * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_*.
990 */
991static DECLCALLBACK(void) vmR3BootstrapNotifyCpuFF(PUVMCPU pUVCpu, uint32_t fFlags)
992{
993 if (pUVCpu->vm.s.fWait)
994 {
995 int rc = RTSemEventSignal(pUVCpu->vm.s.EventSemWait);
996 AssertRC(rc);
997 }
998 NOREF(fFlags);
999}
1000
1001
1002/**
1003 * Default VMR3Wait() worker.
1004 *
1005 * @returns VBox status code.
1006 * @param pUVCpu Pointer to the user mode VMCPU structure.
1007 */
1008static DECLCALLBACK(int) vmR3DefaultWait(PUVMCPU pUVCpu)
1009{
1010 ASMAtomicWriteBool(&pUVCpu->vm.s.fWait, true);
1011
1012 PVM pVM = pUVCpu->pVM;
1013 PVMCPU pVCpu = pUVCpu->pVCpu;
1014 int rc = VINF_SUCCESS;
1015 for (;;)
1016 {
1017 /*
1018 * Check Relevant FFs.
1019 */
1020 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_EXTERNAL_SUSPENDED_MASK)
1021 || VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_EXTERNAL_SUSPENDED_MASK))
1022 break;
1023
1024 /*
1025 * Wait for a while. Someone will wake us up or interrupt the call if
1026 * anything needs our attention.
1027 */
1028 rc = RTSemEventWait(pUVCpu->vm.s.EventSemWait, 1000);
1029 if (rc == VERR_TIMEOUT)
1030 rc = VINF_SUCCESS;
1031 else if (RT_FAILURE(rc))
1032 {
1033 rc = vmR3FatalWaitError(pUVCpu, "RTSemEventWait->%Rrc", rc);
1034 break;
1035 }
1036 }
1037
1038 ASMAtomicUoWriteBool(&pUVCpu->vm.s.fWait, false);
1039 return rc;
1040}
1041
1042
1043/**
1044 * Default VMR3NotifyFF() worker.
1045 *
1046 * @param pUVCpu Pointer to the user mode VMCPU structure.
1047 * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_*.
1048 */
1049static DECLCALLBACK(void) vmR3DefaultNotifyCpuFF(PUVMCPU pUVCpu, uint32_t fFlags)
1050{
1051 if (pUVCpu->vm.s.fWait)
1052 {
1053 int rc = RTSemEventSignal(pUVCpu->vm.s.EventSemWait);
1054 AssertRC(rc);
1055 }
1056 else
1057 {
1058 PVMCPU pVCpu = pUVCpu->pVCpu;
1059 if (pVCpu)
1060 {
1061 VMCPUSTATE enmState = pVCpu->enmState;
1062 if ( enmState == VMCPUSTATE_STARTED_EXEC_NEM
1063 || enmState == VMCPUSTATE_STARTED_EXEC_NEM_WAIT)
1064 NEMR3NotifyFF(pUVCpu->pVM, pVCpu, fFlags);
1065 }
1066 }
1067}
1068
1069
1070#if defined(VBOX_VMM_TARGET_ARMV8) && defined(RT_OS_WINDOWS)
1071
1072/**
1073 * Method NEM - The host (NEM) does the halting.
1074 */
1075static DECLCALLBACK(int) vmR3HaltNemHalt(PUVMCPU pUVCpu, const uint64_t fMask, uint64_t u64Now)
1076{
1077 PVMCPU pVCpu = pUVCpu->pVCpu;
1078
1079 RT_NOREF(fMask, u64Now);
1080 return NEMR3Halt(pUVCpu->pVM, pVCpu);
1081}
1082
1083
1084/**
1085 * Default VMR3NotifyFF() worker.
1086 *
1087 * @param pUVCpu Pointer to the user mode VMCPU structure.
1088 * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_*.
1089 */
1090static DECLCALLBACK(void) vmR3NemNotifyCpuFF(PUVMCPU pUVCpu, uint32_t fFlags)
1091{
1092 PVMCPU pVCpu = pUVCpu->pVCpu;
1093 if (pVCpu)
1094 NEMR3NotifyFF(pUVCpu->pVM, pVCpu, fFlags);
1095}
1096#endif
1097
1098
1099/**
1100 * Array with halt method descriptors.
1101 * VMINT::iHaltMethod contains an index into this array.
1102 */
1103static const struct VMHALTMETHODDESC
1104{
1105 /** The halt method ID. */
1106 VMHALTMETHOD enmHaltMethod;
1107 /** Set if the method support halting directly in ring-0. */
1108 bool fMayHaltInRing0;
1109 /** The init function for loading config and initialize variables. */
1110 DECLR3CALLBACKMEMBER(int, pfnInit,(PUVM pUVM));
1111 /** The term function. */
1112 DECLR3CALLBACKMEMBER(void, pfnTerm,(PUVM pUVM));
1113 /** The VMR3WaitHaltedU function. */
1114 DECLR3CALLBACKMEMBER(int, pfnHalt,(PUVMCPU pUVCpu, const uint64_t fMask, uint64_t u64Now));
1115 /** The VMR3WaitU function. */
1116 DECLR3CALLBACKMEMBER(int, pfnWait,(PUVMCPU pUVCpu));
1117 /** The VMR3NotifyCpuFFU function. */
1118 DECLR3CALLBACKMEMBER(void, pfnNotifyCpuFF,(PUVMCPU pUVCpu, uint32_t fFlags));
1119 /** The VMR3NotifyGlobalFFU function. */
1120 DECLR3CALLBACKMEMBER(void, pfnNotifyGlobalFF,(PUVM pUVM, uint32_t fFlags));
1121} g_aHaltMethods[] =
1122{
1123 { VMHALTMETHOD_BOOTSTRAP, false, NULL, NULL, NULL, vmR3BootstrapWait, vmR3BootstrapNotifyCpuFF, NULL },
1124 { VMHALTMETHOD_OLD, false, NULL, NULL, vmR3HaltOldDoHalt, vmR3DefaultWait, vmR3DefaultNotifyCpuFF, NULL },
1125 { VMHALTMETHOD_1, false, vmR3HaltMethod1Init, NULL, vmR3HaltMethod1Halt, vmR3DefaultWait, vmR3DefaultNotifyCpuFF, NULL },
1126 { VMHALTMETHOD_GLOBAL_1, true, vmR3HaltGlobal1Init, NULL, vmR3HaltGlobal1Halt, vmR3HaltGlobal1Wait, vmR3HaltGlobal1NotifyCpuFF, NULL },
1127#if defined(VBOX_VMM_TARGET_ARMV8) && defined(RT_OS_WINDOWS)
1128 { VMHALTMETHOD_NEM, false, NULL, NULL, vmR3HaltNemHalt, vmR3DefaultWait, vmR3NemNotifyCpuFF, NULL },
1129#endif
1130};
1131
1132
1133/**
1134 * Notify the emulation thread (EMT) about pending Forced Action (FF).
1135 *
1136 * This function is called by thread other than EMT to make
1137 * sure EMT wakes up and promptly service an FF request.
1138 *
1139 * @param pUVM Pointer to the user mode VM structure.
1140 * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_*.
1141 * @internal
1142 */
1143VMMR3_INT_DECL(void) VMR3NotifyGlobalFFU(PUVM pUVM, uint32_t fFlags)
1144{
1145 LogFlow(("VMR3NotifyGlobalFFU:\n"));
1146 uint32_t iHaltMethod = pUVM->vm.s.iHaltMethod;
1147
1148 if (g_aHaltMethods[iHaltMethod].pfnNotifyGlobalFF) /** @todo make mandatory. */
1149 g_aHaltMethods[iHaltMethod].pfnNotifyGlobalFF(pUVM, fFlags);
1150 else
1151 for (VMCPUID iCpu = 0; iCpu < pUVM->cCpus; iCpu++)
1152 g_aHaltMethods[iHaltMethod].pfnNotifyCpuFF(&pUVM->aCpus[iCpu], fFlags);
1153}
1154
1155
1156/**
1157 * Notify the emulation thread (EMT) about pending Forced Action (FF).
1158 *
1159 * This function is called by thread other than EMT to make
1160 * sure EMT wakes up and promptly service an FF request.
1161 *
1162 * @param pUVCpu Pointer to the user mode per CPU VM structure.
1163 * @param fFlags Notification flags, VMNOTIFYFF_FLAGS_*.
1164 * @internal
1165 */
1166VMMR3_INT_DECL(void) VMR3NotifyCpuFFU(PUVMCPU pUVCpu, uint32_t fFlags)
1167{
1168 PUVM pUVM = pUVCpu->pUVM;
1169
1170 LogFlow(("VMR3NotifyCpuFFU:\n"));
1171 g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnNotifyCpuFF(pUVCpu, fFlags);
1172}
1173
1174
1175/**
1176 * Halted VM Wait.
1177 * Any external event will unblock the thread.
1178 *
1179 * @returns VINF_SUCCESS unless a fatal error occurred. In the latter
1180 * case an appropriate status code is returned.
1181 * @param pVM The cross context VM structure.
1182 * @param pVCpu The cross context virtual CPU structure.
1183 * @param fFlags Combination of VMWAITHALTED_F_XXX.
1184 * @thread The emulation thread.
1185 * @remarks Made visible for implementing vmsvga sync register.
1186 * @internal
1187 */
1188VMMR3_INT_DECL(int) VMR3WaitHalted(PVM pVM, PVMCPU pVCpu, uint32_t fFlags)
1189{
1190 LogFlow(("VMR3WaitHalted: fFlags=%#x\n", fFlags));
1191
1192 /*
1193 * Check Relevant FFs.
1194 */
1195#ifdef VBOX_VMM_TARGET_ARMV8
1196 const uint64_t fMaskIrqs = ((fFlags & VMWAITHALTED_F_IGNORE_IRQS) ? VMCPU_FF_INTERRUPT_IRQ : 0)
1197 | ((fFlags & VMWAITHALTED_F_IGNORE_FIQS) ? VMCPU_FF_INTERRUPT_FIQ : 0);
1198 const uint64_t fMask = VMCPU_FF_EXTERNAL_HALTED_MASK & ~fMaskIrqs;
1199#else
1200 const uint64_t fMask = !(fFlags & VMWAITHALTED_F_IGNORE_IRQS)
1201 ? VMCPU_FF_EXTERNAL_HALTED_MASK
1202 : VMCPU_FF_EXTERNAL_HALTED_MASK & ~(VMCPU_FF_UPDATE_APIC | VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC);
1203#endif
1204
1205 if ( VM_FF_IS_ANY_SET(pVM, VM_FF_EXTERNAL_HALTED_MASK)
1206 || VMCPU_FF_IS_ANY_SET(pVCpu, fMask))
1207 {
1208 LogFlow(("VMR3WaitHalted: returns VINF_SUCCESS (FF %#x FFCPU %#RX64)\n", pVM->fGlobalForcedActions, (uint64_t)pVCpu->fLocalForcedActions));
1209 return VINF_SUCCESS;
1210 }
1211
1212 /*
1213 * The yielder is suspended while we're halting, while TM might have clock(s) running
1214 * only at certain times and need to be notified..
1215 */
1216 if (pVCpu->idCpu == 0)
1217 VMMR3YieldSuspend(pVM);
1218 TMNotifyStartOfHalt(pVCpu);
1219
1220 /*
1221 * Record halt averages for the last second.
1222 */
1223 PUVMCPU pUVCpu = pVCpu->pUVCpu;
1224 uint64_t u64Now = RTTimeNanoTS();
1225 int64_t off = u64Now - pUVCpu->vm.s.u64HaltsStartTS;
1226 if (off > 1000000000)
1227 {
1228 if (off > _4G || !pUVCpu->vm.s.cHalts)
1229 {
1230 pUVCpu->vm.s.HaltInterval = 1000000000 /* 1 sec */;
1231 pUVCpu->vm.s.HaltFrequency = 1;
1232 }
1233 else
1234 {
1235 pUVCpu->vm.s.HaltInterval = (uint32_t)off / pUVCpu->vm.s.cHalts;
1236 pUVCpu->vm.s.HaltFrequency = ASMMultU64ByU32DivByU32(pUVCpu->vm.s.cHalts, 1000000000, (uint32_t)off);
1237 }
1238 pUVCpu->vm.s.u64HaltsStartTS = u64Now;
1239 pUVCpu->vm.s.cHalts = 0;
1240 }
1241 pUVCpu->vm.s.cHalts++;
1242
1243 /*
1244 * Do the halt.
1245 */
1246 VMCPU_ASSERT_STATE_2(pVCpu, VMCPUSTATE_STARTED, VMCPUSTATE_STARTED_EXEC_NEM);
1247 VMCPUSTATE enmStateOld = VMCPU_GET_STATE(pVCpu);
1248 VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED_HALTED);
1249 PUVM pUVM = pUVCpu->pUVM;
1250 int rc = g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnHalt(pUVCpu, fMask, u64Now);
1251 VMCPU_SET_STATE(pVCpu, enmStateOld);
1252
1253 /*
1254 * Notify TM and resume the yielder
1255 */
1256 TMNotifyEndOfHalt(pVCpu);
1257 if (pVCpu->idCpu == 0)
1258 VMMR3YieldResume(pVM);
1259
1260 LogFlow(("VMR3WaitHalted: returns %Rrc (FF %#x)\n", rc, pVM->fGlobalForcedActions));
1261 return rc;
1262}
1263
1264
1265/**
1266 * Suspended VM Wait.
1267 * Only a handful of forced actions will cause the function to
1268 * return to the caller.
1269 *
1270 * @returns VINF_SUCCESS unless a fatal error occurred. In the latter
1271 * case an appropriate status code is returned.
1272 * @param pUVCpu Pointer to the user mode VMCPU structure.
1273 * @thread The emulation thread.
1274 * @internal
1275 */
1276VMMR3_INT_DECL(int) VMR3WaitU(PUVMCPU pUVCpu)
1277{
1278 LogFlow(("VMR3WaitU:\n"));
1279
1280 /*
1281 * Check Relevant FFs.
1282 */
1283 PVM pVM = pUVCpu->pVM;
1284 PVMCPU pVCpu = pUVCpu->pVCpu;
1285
1286 if ( pVM
1287 && ( VM_FF_IS_ANY_SET(pVM, VM_FF_EXTERNAL_SUSPENDED_MASK)
1288 || VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_EXTERNAL_SUSPENDED_MASK)
1289 )
1290 )
1291 {
1292 LogFlow(("VMR3Wait: returns VINF_SUCCESS (FF %#x)\n", pVM->fGlobalForcedActions));
1293 return VINF_SUCCESS;
1294 }
1295
1296 /*
1297 * Do waiting according to the halt method (so VMR3NotifyFF
1298 * doesn't have to special case anything).
1299 */
1300 PUVM pUVM = pUVCpu->pUVM;
1301 int rc = g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnWait(pUVCpu);
1302 LogFlow(("VMR3WaitU: returns %Rrc (FF %#x)\n", rc, pUVM->pVM ? pUVM->pVM->fGlobalForcedActions : 0));
1303 return rc;
1304}
1305
1306
1307/**
1308 * Interface that PDMR3Suspend, PDMR3PowerOff and PDMR3Reset uses when they wait
1309 * for the handling of asynchronous notifications to complete.
1310 *
1311 * @returns VINF_SUCCESS unless a fatal error occurred. In the latter
1312 * case an appropriate status code is returned.
1313 * @param pUVCpu Pointer to the user mode VMCPU structure.
1314 * @thread The emulation thread.
1315 */
1316VMMR3_INT_DECL(int) VMR3AsyncPdmNotificationWaitU(PUVMCPU pUVCpu)
1317{
1318 LogFlow(("VMR3AsyncPdmNotificationWaitU:\n"));
1319 return VMR3WaitU(pUVCpu);
1320}
1321
1322
1323/**
1324 * Interface that PDM the helper asynchronous notification completed methods
1325 * uses for EMT0 when it is waiting inside VMR3AsyncPdmNotificationWaitU().
1326 *
1327 * @param pUVM Pointer to the user mode VM structure.
1328 */
1329VMMR3_INT_DECL(void) VMR3AsyncPdmNotificationWakeupU(PUVM pUVM)
1330{
1331 LogFlow(("VMR3AsyncPdmNotificationWakeupU:\n"));
1332 VM_FF_SET(pUVM->pVM, VM_FF_REQUEST); /* this will have to do for now. */
1333 g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnNotifyCpuFF(&pUVM->aCpus[0], 0 /*fFlags*/);
1334}
1335
1336
1337/**
1338 * Rendezvous callback that will be called once.
1339 *
1340 * @returns VBox strict status code.
1341 * @param pVM The cross context VM structure.
1342 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
1343 * @param pvUser The new g_aHaltMethods index.
1344 */
1345static DECLCALLBACK(VBOXSTRICTRC) vmR3SetHaltMethodCallback(PVM pVM, PVMCPU pVCpu, void *pvUser)
1346{
1347 PUVM pUVM = pVM->pUVM;
1348 int rc = VINF_SUCCESS;
1349 uintptr_t i = (uintptr_t)pvUser;
1350 Assert(i < RT_ELEMENTS(g_aHaltMethods));
1351
1352 /*
1353 * Main job is done once on EMT0 (it goes thru here first).
1354 */
1355 if (pVCpu->idCpu == 0)
1356 {
1357 /*
1358 * Terminate the old one.
1359 */
1360 if ( pUVM->vm.s.enmHaltMethod != VMHALTMETHOD_INVALID
1361 && g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnTerm)
1362 {
1363 g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnTerm(pUVM);
1364 pUVM->vm.s.enmHaltMethod = VMHALTMETHOD_INVALID;
1365 }
1366
1367 /* Assert that the failure fallback is where we expect. */
1368 Assert(g_aHaltMethods[0].enmHaltMethod == VMHALTMETHOD_BOOTSTRAP);
1369 Assert(!g_aHaltMethods[0].pfnTerm && !g_aHaltMethods[0].pfnInit);
1370
1371 /*
1372 * Init the new one.
1373 */
1374 memset(&pUVM->vm.s.Halt, 0, sizeof(pUVM->vm.s.Halt));
1375 if (g_aHaltMethods[i].pfnInit)
1376 {
1377 rc = g_aHaltMethods[i].pfnInit(pUVM);
1378 if (RT_FAILURE(rc))
1379 {
1380 /* Fall back on the bootstrap method. This requires no
1381 init/term (see assertion above), and will always work. */
1382 AssertLogRelRC(rc);
1383 i = 0;
1384 }
1385 }
1386
1387 /*
1388 * Commit it.
1389 */
1390 pUVM->vm.s.enmHaltMethod = g_aHaltMethods[i].enmHaltMethod;
1391 ASMAtomicWriteU32(&pUVM->vm.s.iHaltMethod, i);
1392 }
1393 else
1394 i = pUVM->vm.s.iHaltMethod;
1395
1396 /*
1397 * All EMTs must update their ring-0 halt configuration.
1398 */
1399 VMMR3SetMayHaltInRing0(pVCpu, g_aHaltMethods[i].fMayHaltInRing0,
1400 g_aHaltMethods[i].enmHaltMethod == VMHALTMETHOD_GLOBAL_1
1401 ? pUVM->vm.s.Halt.Global1.cNsSpinBlockThresholdCfg : 0);
1402
1403 return rc;
1404}
1405
1406
1407/**
1408 * Changes the halt method.
1409 *
1410 * @returns VBox status code.
1411 * @param pUVM Pointer to the user mode VM structure.
1412 * @param enmHaltMethod The new halt method.
1413 * @thread EMT.
1414 */
1415int vmR3SetHaltMethodU(PUVM pUVM, VMHALTMETHOD enmHaltMethod)
1416{
1417 PVM pVM = pUVM->pVM; Assert(pVM);
1418 VM_ASSERT_EMT(pVM);
1419 AssertReturn(enmHaltMethod > VMHALTMETHOD_INVALID && enmHaltMethod < VMHALTMETHOD_END, VERR_INVALID_PARAMETER);
1420
1421 /*
1422 * Resolve default (can be overridden in the configuration).
1423 */
1424 if (enmHaltMethod == VMHALTMETHOD_DEFAULT)
1425 {
1426 uint32_t u32;
1427 int rc = CFGMR3QueryU32(CFGMR3GetChild(CFGMR3GetRoot(pVM), "VM"), "HaltMethod", &u32);
1428 if (RT_SUCCESS(rc))
1429 {
1430 enmHaltMethod = (VMHALTMETHOD)u32;
1431 if (enmHaltMethod <= VMHALTMETHOD_INVALID || enmHaltMethod >= VMHALTMETHOD_END)
1432 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS, N_("Invalid VM/HaltMethod value %d"), enmHaltMethod);
1433 }
1434 else if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_CHILD_NOT_FOUND)
1435 return VMSetError(pVM, rc, RT_SRC_POS, N_("Failed to Query VM/HaltMethod as uint32_t"));
1436 else
1437 enmHaltMethod = VMHALTMETHOD_GLOBAL_1;
1438 //enmHaltMethod = VMHALTMETHOD_1;
1439 //enmHaltMethod = VMHALTMETHOD_OLD;
1440
1441#if defined(VBOX_VMM_TARGET_ARMV8) && defined(RT_OS_WINDOWS)
1442 /*
1443 * We can't use the global halt method on Windows/ARM with Hyper-V
1444 * as APs can't be brought online by the guest due to missing
1445 * PSCI VM exits currently.
1446 */
1447 enmHaltMethod = VMHALTMETHOD_NEM;
1448#endif
1449 }
1450
1451 /*
1452 * The global halt method doesn't work in driverless mode, so fall back on
1453 * method #1 instead.
1454 */
1455 if (!SUPR3IsDriverless() || enmHaltMethod != VMHALTMETHOD_GLOBAL_1)
1456 LogRel(("VMEmt: Halt method %s (%d)\n", vmR3GetHaltMethodName(enmHaltMethod), enmHaltMethod));
1457 else
1458 {
1459 LogRel(("VMEmt: Halt method %s (%d) not available in driverless mode, using %s (%d) instead\n",
1460 vmR3GetHaltMethodName(enmHaltMethod), enmHaltMethod, vmR3GetHaltMethodName(VMHALTMETHOD_1), VMHALTMETHOD_1));
1461#if defined(VBOX_VMM_TARGET_ARMV8) && defined(RT_OS_WINDOWS)
1462 enmHaltMethod = VMHALTMETHOD_NEM;
1463#else
1464 enmHaltMethod = VMHALTMETHOD_1;
1465#endif
1466 }
1467
1468
1469 /*
1470 * Find the descriptor.
1471 */
1472 unsigned i = 0;
1473 while ( i < RT_ELEMENTS(g_aHaltMethods)
1474 && g_aHaltMethods[i].enmHaltMethod != enmHaltMethod)
1475 i++;
1476 AssertReturn(i < RT_ELEMENTS(g_aHaltMethods), VERR_INVALID_PARAMETER);
1477
1478 /*
1479 * This needs to be done while the other EMTs are not sleeping or otherwise messing around.
1480 */
1481 return VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_ASCENDING, vmR3SetHaltMethodCallback, (void *)(uintptr_t)i);
1482}
1483
1484
1485/**
1486 * Special interface for implementing a HLT-like port on a device.
1487 *
1488 * This can be called directly from device code, provide the device is trusted
1489 * to access the VMM directly. Since we may not have an accurate register set
1490 * and the caller certainly shouldn't (device code does not access CPU
1491 * registers), this function will return when interrupts are pending regardless
1492 * of the actual EFLAGS.IF state.
1493 *
1494 * @returns VBox error status (never informational statuses).
1495 * @param pVM The cross context VM structure.
1496 * @param idCpu The id of the calling EMT.
1497 */
1498VMMR3DECL(int) VMR3WaitForDeviceReady(PVM pVM, VMCPUID idCpu)
1499{
1500 /*
1501 * Validate caller and resolve the CPU ID.
1502 */
1503 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
1504 AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
1505 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
1506 VMCPU_ASSERT_EMT_RETURN(pVCpu, VERR_VM_THREAD_NOT_EMT);
1507
1508 /*
1509 * Tag along with the HLT mechanics for now.
1510 */
1511 int rc = VMR3WaitHalted(pVM, pVCpu, false /*fIgnoreInterrupts*/);
1512 if (RT_SUCCESS(rc))
1513 return VINF_SUCCESS;
1514 return rc;
1515}
1516
1517
1518/**
1519 * Wakes up a CPU that has called VMR3WaitForDeviceReady.
1520 *
1521 * @returns VBox error status (never informational statuses).
1522 * @param pVM The cross context VM structure.
1523 * @param idCpu The id of the calling EMT.
1524 */
1525VMMR3DECL(int) VMR3NotifyCpuDeviceReady(PVM pVM, VMCPUID idCpu)
1526{
1527 /*
1528 * Validate caller and resolve the CPU ID.
1529 */
1530 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
1531 AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
1532 PVMCPU pVCpu = pVM->apCpusR3[idCpu];
1533
1534 /*
1535 * Pretend it was an FF that got set since we've got logic for that already.
1536 */
1537 VMR3NotifyCpuFFU(pVCpu->pUVCpu, VMNOTIFYFF_FLAGS_DONE_REM);
1538 return VINF_SUCCESS;
1539}
1540
1541
1542/**
1543 * Returns the number of active EMTs.
1544 *
1545 * This is used by the rendezvous code during VM destruction to avoid waiting
1546 * for EMTs that aren't around any more.
1547 *
1548 * @returns Number of active EMTs. 0 if invalid parameter.
1549 * @param pUVM The user mode VM structure.
1550 */
1551VMMR3_INT_DECL(uint32_t) VMR3GetActiveEmts(PUVM pUVM)
1552{
1553 UVM_ASSERT_VALID_EXT_RETURN(pUVM, 0);
1554 return pUVM->vm.s.cActiveEmts;
1555}
1556
Note: See TracBrowser for help on using the repository browser.

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