VirtualBox

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

Last change on this file since 13762 was 13667, checked in by vboxsync, 16 years ago

#1865: VM.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 37.6 KB
Line 
1/* $Id: VMEmt.cpp 13667 2008-10-29 18:27:15Z vboxsync $ */
2/** @file
3 * VM - Virtual Machine, The Emulation Thread.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_VM
27#include <VBox/tm.h>
28#include <VBox/dbgf.h>
29#include <VBox/em.h>
30#include <VBox/pdmapi.h>
31#include <VBox/rem.h>
32#include <VBox/tm.h>
33#include "VMInternal.h"
34#include <VBox/vm.h>
35#include <VBox/uvm.h>
36
37#include <VBox/err.h>
38#include <VBox/log.h>
39#include <iprt/assert.h>
40#include <iprt/asm.h>
41#include <iprt/semaphore.h>
42#include <iprt/string.h>
43#include <iprt/thread.h>
44#include <iprt/time.h>
45
46
47/**
48 * The emulation thread.
49 *
50 * @returns Thread exit code.
51 * @param ThreadSelf The handle to the executing thread.
52 * @param pvArgs Pointer to the user mode VM structure (UVM).
53 */
54DECLCALLBACK(int) vmR3EmulationThread(RTTHREAD ThreadSelf, void *pvArgs)
55{
56 PUVM pUVM = (PUVM)pvArgs;
57 AssertReleaseMsg(VALID_PTR(pUVM) && pUVM->u32Magic == UVM_MAGIC,
58 ("Invalid arguments to the emulation thread!\n"));
59
60 /*
61 * Init the native thread member.
62 */
63 pUVM->vm.s.NativeThreadEMT = RTThreadGetNative(ThreadSelf);
64
65 /*
66 * The request loop.
67 */
68 int rc = VINF_SUCCESS;
69 volatile VMSTATE enmBefore = VMSTATE_CREATING; /* volatile because of setjmp */
70 Log(("vmR3EmulationThread: Emulation thread starting the days work... Thread=%#x pUVM=%p\n", ThreadSelf, pUVM));
71 for (;;)
72 {
73 /* Requested to exit the EMT thread out of sync? (currently only VMR3WaitForResume) */
74 if (setjmp(pUVM->vm.s.emtJumpEnv) != 0)
75 {
76 rc = VINF_SUCCESS;
77 break;
78 }
79
80 /*
81 * During early init there is no pVM, so make a special path
82 * for that to keep things clearly separate.
83 */
84 if (!pUVM->pVM)
85 {
86 /*
87 * Check for termination first.
88 */
89 if (pUVM->vm.s.fTerminateEMT)
90 {
91 rc = VINF_EM_TERMINATE;
92 break;
93 }
94 if (pUVM->vm.s.pReqs)
95 {
96 /*
97 * Service execute in EMT request.
98 */
99 rc = VMR3ReqProcessU(pUVM);
100 Log(("vmR3EmulationThread: Req rc=%Vrc, VM state %d -> %d\n", rc, enmBefore, pUVM->pVM ? pUVM->pVM->enmVMState : VMSTATE_CREATING));
101 }
102 else
103 {
104 /*
105 * Nothing important is pending, so wait for something.
106 */
107 rc = VMR3WaitU(pUVM);
108 if (VBOX_FAILURE(rc))
109 break;
110 }
111 }
112 else
113 {
114
115 /*
116 * Pending requests which needs servicing?
117 *
118 * We check for state changes in addition to status codes when
119 * servicing requests. (Look after the ifs.)
120 */
121 PVM pVM = pUVM->pVM;
122 enmBefore = pVM->enmVMState;
123 if ( VM_FF_ISSET(pVM, VM_FF_TERMINATE)
124 || pUVM->vm.s.fTerminateEMT)
125 {
126 rc = VINF_EM_TERMINATE;
127 break;
128 }
129 if (pUVM->vm.s.pReqs)
130 {
131 /*
132 * Service execute in EMT request.
133 */
134 rc = VMR3ReqProcessU(pUVM);
135 Log(("vmR3EmulationThread: Req rc=%Vrc, VM state %d -> %d\n", rc, enmBefore, pVM->enmVMState));
136 }
137 else if (VM_FF_ISSET(pVM, VM_FF_DBGF))
138 {
139 /*
140 * Service the debugger request.
141 */
142 rc = DBGFR3VMMForcedAction(pVM);
143 Log(("vmR3EmulationThread: Dbg rc=%Vrc, VM state %d -> %d\n", rc, enmBefore, pVM->enmVMState));
144 }
145 else if (VM_FF_ISSET(pVM, VM_FF_RESET))
146 {
147 /*
148 * Service a delayed reset request.
149 */
150 rc = VMR3Reset(pVM);
151 VM_FF_CLEAR(pVM, VM_FF_RESET);
152 Log(("vmR3EmulationThread: Reset rc=%Vrc, VM state %d -> %d\n", rc, enmBefore, pVM->enmVMState));
153 }
154 else
155 {
156 /*
157 * Nothing important is pending, so wait for something.
158 */
159 rc = VMR3WaitU(pUVM);
160 if (VBOX_FAILURE(rc))
161 break;
162 }
163
164 /*
165 * Check for termination requests, these have extremely high priority.
166 */
167 if ( rc == VINF_EM_TERMINATE
168 || VM_FF_ISSET(pVM, VM_FF_TERMINATE)
169 || pUVM->vm.s.fTerminateEMT)
170 break;
171 }
172
173 /*
174 * Some requests (both VMR3Req* and the DBGF) can potentially
175 * resume or start the VM, in that case we'll get a change in
176 * VM status indicating that we're now running.
177 */
178 if ( VBOX_SUCCESS(rc)
179 && pUVM->pVM
180 && enmBefore != pUVM->pVM->enmVMState
181 && pUVM->pVM->enmVMState == VMSTATE_RUNNING)
182 {
183 PVM pVM = pUVM->pVM;
184 rc = EMR3ExecuteVM(pVM);
185 Log(("vmR3EmulationThread: EMR3ExecuteVM() -> rc=%Vrc, enmVMState=%d\n", rc, pVM->enmVMState));
186 if ( EMGetState(pVM) == EMSTATE_GURU_MEDITATION
187 && pVM->enmVMState == VMSTATE_RUNNING)
188 vmR3SetState(pVM, VMSTATE_GURU_MEDITATION);
189 }
190
191 } /* forever */
192
193
194 /*
195 * Exiting.
196 */
197 Log(("vmR3EmulationThread: Terminating emulation thread! Thread=%#x pUVM=%p rc=%Vrc enmBefore=%d enmVMState=%d\n",
198 ThreadSelf, pUVM, rc, enmBefore, pUVM->pVM ? pUVM->pVM->enmVMState : VMSTATE_TERMINATED));
199 if (pUVM->vm.s.fEMTDoesTheCleanup)
200 {
201 Log(("vmR3EmulationThread: executing delayed Destroy\n"));
202 Assert(pUVM->pVM);
203 vmR3Destroy(pUVM->pVM);
204 vmR3DestroyFinalBitFromEMT(pUVM);
205 }
206 else
207 {
208 vmR3DestroyFinalBitFromEMT(pUVM);
209
210 /* we don't reset ThreadEMT here because it's used in waiting. */
211 pUVM->vm.s.NativeThreadEMT = NIL_RTNATIVETHREAD;
212 }
213 Log(("vmR3EmulationThread: EMT is terminated.\n"));
214 return rc;
215}
216
217
218/**
219 * Wait for VM to be resumed. Handle events like vmR3EmulationThread does.
220 * In case the VM is stopped, clean up and long jump to the main EMT loop.
221 *
222 * @returns VINF_SUCCESS or doesn't return
223 * @param pVM VM handle.
224 */
225VMMR3DECL(int) VMR3WaitForResume(PVM pVM)
226{
227 /*
228 * The request loop.
229 */
230 PUVM pUVM = pVM->pUVM;
231 VMSTATE enmBefore;
232 int rc;
233 for (;;)
234 {
235
236 /*
237 * Pending requests which needs servicing?
238 *
239 * We check for state changes in addition to status codes when
240 * servicing requests. (Look after the ifs.)
241 */
242 enmBefore = pVM->enmVMState;
243 if ( VM_FF_ISSET(pVM, VM_FF_TERMINATE)
244 || pUVM->vm.s.fTerminateEMT)
245 {
246 rc = VINF_EM_TERMINATE;
247 break;
248 }
249 else if (pUVM->vm.s.pReqs)
250 {
251 /*
252 * Service execute in EMT request.
253 */
254 rc = VMR3ReqProcessU(pUVM);
255 Log(("vmR3EmulationThread: Req rc=%Vrc, VM state %d -> %d\n", rc, enmBefore, pVM->enmVMState));
256 }
257 else if (VM_FF_ISSET(pVM, VM_FF_DBGF))
258 {
259 /*
260 * Service the debugger request.
261 */
262 rc = DBGFR3VMMForcedAction(pVM);
263 Log(("vmR3EmulationThread: Dbg rc=%Vrc, VM state %d -> %d\n", rc, enmBefore, pVM->enmVMState));
264 }
265 else if (VM_FF_ISSET(pVM, VM_FF_RESET))
266 {
267 /*
268 * Service a delay reset request.
269 */
270 rc = VMR3Reset(pVM);
271 VM_FF_CLEAR(pVM, VM_FF_RESET);
272 Log(("vmR3EmulationThread: Reset rc=%Vrc, VM state %d -> %d\n", rc, enmBefore, pVM->enmVMState));
273 }
274 else
275 {
276 /*
277 * Nothing important is pending, so wait for something.
278 */
279 rc = VMR3WaitU(pUVM);
280 if (VBOX_FAILURE(rc))
281 break;
282 }
283
284 /*
285 * Check for termination requests, these are extremely high priority.
286 */
287 if ( rc == VINF_EM_TERMINATE
288 || VM_FF_ISSET(pVM, VM_FF_TERMINATE)
289 || pUVM->vm.s.fTerminateEMT)
290 break;
291
292 /*
293 * Some requests (both VMR3Req* and the DBGF) can potentially
294 * resume or start the VM, in that case we'll get a change in
295 * VM status indicating that we're now running.
296 */
297 if ( VBOX_SUCCESS(rc)
298 && enmBefore != pVM->enmVMState
299 && pVM->enmVMState == VMSTATE_RUNNING)
300 {
301 /* Only valid exit reason. */
302 return VINF_SUCCESS;
303 }
304
305 } /* forever */
306
307 /* Return to the main loop in vmR3EmulationThread, which will clean up for us. */
308 longjmp(pUVM->vm.s.emtJumpEnv, 1);
309}
310
311
312/**
313 * Gets the name of a halt method.
314 *
315 * @returns Pointer to a read only string.
316 * @param enmMethod The method.
317 */
318static const char *vmR3GetHaltMethodName(VMHALTMETHOD enmMethod)
319{
320 switch (enmMethod)
321 {
322 case VMHALTMETHOD_BOOTSTRAP: return "bootstrap";
323 case VMHALTMETHOD_DEFAULT: return "default";
324 case VMHALTMETHOD_OLD: return "old";
325 case VMHALTMETHOD_1: return "method1";
326 //case VMHALTMETHOD_2: return "method2";
327 case VMHALTMETHOD_GLOBAL_1: return "global1";
328 default: return "unknown";
329 }
330}
331
332
333/**
334 * The old halt loop.
335 *
336 * @param pUVM Pointer to the user mode VM structure.
337 */
338static DECLCALLBACK(int) vmR3HaltOldDoHalt(PUVM pUVM, const uint32_t fMask, uint64_t /* u64Now*/)
339{
340 /*
341 * Halt loop.
342 */
343 PVM pVM = pUVM->pVM;
344 int rc = VINF_SUCCESS;
345 ASMAtomicWriteBool(&pUVM->vm.s.fWait, true);
346 //unsigned cLoops = 0;
347 for (;;)
348 {
349 /*
350 * Work the timers and check if we can exit.
351 * The poll call gives us the ticks left to the next event in
352 * addition to perhaps set an FF.
353 */
354 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltPoll, a);
355 PDMR3Poll(pVM);
356 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltPoll, a);
357 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltTimers, b);
358 TMR3TimerQueuesDo(pVM);
359 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltTimers, b);
360 if (VM_FF_ISPENDING(pVM, fMask))
361 break;
362 uint64_t u64NanoTS = TMVirtualToNano(pVM, TMTimerPoll(pVM));
363 if (VM_FF_ISPENDING(pVM, fMask))
364 break;
365
366 /*
367 * Wait for a while. Someone will wake us up or interrupt the call if
368 * anything needs our attention.
369 */
370 if (u64NanoTS < 50000)
371 {
372 //RTLogPrintf("u64NanoTS=%RI64 cLoops=%d spin\n", u64NanoTS, cLoops++);
373 /* spin */;
374 }
375 else
376 {
377 VMMR3YieldStop(pVM);
378 //uint64_t u64Start = RTTimeNanoTS();
379 if (u64NanoTS < 870000) /* this is a bit speculative... works fine on linux. */
380 {
381 //RTLogPrintf("u64NanoTS=%RI64 cLoops=%d yield", u64NanoTS, cLoops++);
382 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltYield, a);
383 RTThreadYield(); /* this is the best we can do here */
384 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltYield, a);
385 }
386 else if (u64NanoTS < 2000000)
387 {
388 //RTLogPrintf("u64NanoTS=%RI64 cLoops=%d sleep 1ms", u64NanoTS, cLoops++);
389 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltBlock, a);
390 rc = RTSemEventWait(pUVM->vm.s.EventSemWait, 1);
391 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltBlock, a);
392 }
393 else
394 {
395 //RTLogPrintf("u64NanoTS=%RI64 cLoops=%d sleep %dms", u64NanoTS, cLoops++, (uint32_t)RT_MIN((u64NanoTS - 500000) / 1000000, 15));
396 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltBlock, a);
397 rc = RTSemEventWait(pUVM->vm.s.EventSemWait, RT_MIN((u64NanoTS - 1000000) / 1000000, 15));
398 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltBlock, a);
399 }
400 //uint64_t u64Slept = RTTimeNanoTS() - u64Start;
401 //RTLogPrintf(" -> rc=%Vrc in %RU64 ns / %RI64 ns delta\n", rc, u64Slept, u64NanoTS - u64Slept);
402 }
403 if (rc == VERR_TIMEOUT)
404 rc = VINF_SUCCESS;
405 else if (VBOX_FAILURE(rc))
406 {
407 AssertRC(rc != VERR_INTERRUPTED);
408 AssertMsgFailed(("RTSemEventWait->%Vrc\n", rc));
409 ASMAtomicUoWriteBool(&pUVM->vm.s.fTerminateEMT, true);
410 VM_FF_SET(pVM, VM_FF_TERMINATE);
411 rc = VERR_INTERNAL_ERROR;
412 break;
413 }
414 }
415
416 ASMAtomicUoWriteBool(&pUVM->vm.s.fWait, false);
417 return rc;
418}
419
420
421/**
422 * Initialize the configuration of halt method 1 & 2.
423 *
424 * @return VBox status code. Failure on invalid CFGM data.
425 * @param pVM The VM handle.
426 */
427static int vmR3HaltMethod12ReadConfigU(PUVM pUVM)
428{
429 /*
430 * The defaults.
431 */
432#if 1 /* DEBUGGING STUFF - REMOVE LATER */
433 pUVM->vm.s.Halt.Method12.u32LagBlockIntervalDivisorCfg = 4;
434 pUVM->vm.s.Halt.Method12.u32MinBlockIntervalCfg = 2*1000000;
435 pUVM->vm.s.Halt.Method12.u32MaxBlockIntervalCfg = 75*1000000;
436 pUVM->vm.s.Halt.Method12.u32StartSpinningCfg = 30*1000000;
437 pUVM->vm.s.Halt.Method12.u32StopSpinningCfg = 20*1000000;
438#else
439 pUVM->vm.s.Halt.Method12.u32LagBlockIntervalDivisorCfg = 4;
440 pUVM->vm.s.Halt.Method12.u32MinBlockIntervalCfg = 5*1000000;
441 pUVM->vm.s.Halt.Method12.u32MaxBlockIntervalCfg = 200*1000000;
442 pUVM->vm.s.Halt.Method12.u32StartSpinningCfg = 20*1000000;
443 pUVM->vm.s.Halt.Method12.u32StopSpinningCfg = 2*1000000;
444#endif
445
446 /*
447 * Query overrides.
448 *
449 * I don't have time to bother with niceities such as invalid value checks
450 * here right now. sorry.
451 */
452 PCFGMNODE pCfg = CFGMR3GetChild(CFGMR3GetRoot(pUVM->pVM), "/VMM/HaltedMethod1");
453 if (pCfg)
454 {
455 uint32_t u32;
456 if (RT_SUCCESS(CFGMR3QueryU32(pCfg, "LagBlockIntervalDivisor", &u32)))
457 pUVM->vm.s.Halt.Method12.u32LagBlockIntervalDivisorCfg = u32;
458 if (RT_SUCCESS(CFGMR3QueryU32(pCfg, "MinBlockInterval", &u32)))
459 pUVM->vm.s.Halt.Method12.u32MinBlockIntervalCfg = u32;
460 if (RT_SUCCESS(CFGMR3QueryU32(pCfg, "MaxBlockInterval", &u32)))
461 pUVM->vm.s.Halt.Method12.u32MaxBlockIntervalCfg = u32;
462 if (RT_SUCCESS(CFGMR3QueryU32(pCfg, "StartSpinning", &u32)))
463 pUVM->vm.s.Halt.Method12.u32StartSpinningCfg = u32;
464 if (RT_SUCCESS(CFGMR3QueryU32(pCfg, "StopSpinning", &u32)))
465 pUVM->vm.s.Halt.Method12.u32StopSpinningCfg = u32;
466 LogRel(("HaltedMethod1 config: %d/%d/%d/%d/%d\n",
467 pUVM->vm.s.Halt.Method12.u32LagBlockIntervalDivisorCfg,
468 pUVM->vm.s.Halt.Method12.u32MinBlockIntervalCfg,
469 pUVM->vm.s.Halt.Method12.u32MaxBlockIntervalCfg,
470 pUVM->vm.s.Halt.Method12.u32StartSpinningCfg,
471 pUVM->vm.s.Halt.Method12.u32StopSpinningCfg));
472 }
473
474 return VINF_SUCCESS;
475}
476
477
478/**
479 * Initialize halt method 1.
480 *
481 * @return VBox status code.
482 * @param pUVM Pointer to the user mode VM structure.
483 */
484static DECLCALLBACK(int) vmR3HaltMethod1Init(PUVM pUVM)
485{
486 return vmR3HaltMethod12ReadConfigU(pUVM);
487}
488
489
490/**
491 * Method 1 - Block whenever possible, and when lagging behind
492 * switch to spinning for 10-30ms with occational blocking until
493 * the lag has been eliminated.
494 */
495static DECLCALLBACK(int) vmR3HaltMethod1Halt(PUVM pUVM, const uint32_t fMask, uint64_t u64Now)
496{
497 PVM pVM = pUVM->pVM;
498
499 /*
500 * To simplify things, we decide up-front whether we should switch to spinning or
501 * not. This makes some ASSUMPTIONS about the cause of the spinning (PIT/RTC/PCNet)
502 * and that it will generate interrupts or other events that will cause us to exit
503 * the halt loop.
504 */
505 bool fBlockOnce = false;
506 bool fSpinning = false;
507 uint32_t u32CatchUpPct = TMVirtualSyncGetCatchUpPct(pVM);
508 if (u32CatchUpPct /* non-zero if catching up */)
509 {
510 if (pUVM->vm.s.Halt.Method12.u64StartSpinTS)
511 {
512 fSpinning = TMVirtualSyncGetLag(pVM) >= pUVM->vm.s.Halt.Method12.u32StopSpinningCfg;
513 if (fSpinning)
514 {
515 uint64_t u64Lag = TMVirtualSyncGetLag(pVM);
516 fBlockOnce = u64Now - pUVM->vm.s.Halt.Method12.u64LastBlockTS
517 > RT_MAX(pUVM->vm.s.Halt.Method12.u32MinBlockIntervalCfg,
518 RT_MIN(u64Lag / pUVM->vm.s.Halt.Method12.u32LagBlockIntervalDivisorCfg,
519 pUVM->vm.s.Halt.Method12.u32MaxBlockIntervalCfg));
520 }
521 else
522 {
523 //RTLogRelPrintf("Stopped spinning (%u ms)\n", (u64Now - pUVM->vm.s.Halt.Method12.u64StartSpinTS) / 1000000);
524 pUVM->vm.s.Halt.Method12.u64StartSpinTS = 0;
525 }
526 }
527 else
528 {
529 fSpinning = TMVirtualSyncGetLag(pVM) >= pUVM->vm.s.Halt.Method12.u32StartSpinningCfg;
530 if (fSpinning)
531 pUVM->vm.s.Halt.Method12.u64StartSpinTS = u64Now;
532 }
533 }
534 else if (pUVM->vm.s.Halt.Method12.u64StartSpinTS)
535 {
536 //RTLogRelPrintf("Stopped spinning (%u ms)\n", (u64Now - pUVM->vm.s.Halt.Method12.u64StartSpinTS) / 1000000);
537 pUVM->vm.s.Halt.Method12.u64StartSpinTS = 0;
538 }
539
540 /*
541 * Halt loop.
542 */
543 int rc = VINF_SUCCESS;
544 ASMAtomicWriteBool(&pUVM->vm.s.fWait, true);
545 unsigned cLoops = 0;
546 for (;; cLoops++)
547 {
548 /*
549 * Work the timers and check if we can exit.
550 */
551 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltPoll, a);
552 PDMR3Poll(pVM);
553 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltPoll, a);
554 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltTimers, b);
555 TMR3TimerQueuesDo(pVM);
556 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltTimers, b);
557 if (VM_FF_ISPENDING(pVM, fMask))
558 break;
559
560 /*
561 * Estimate time left to the next event.
562 */
563 uint64_t u64NanoTS = TMVirtualToNano(pVM, TMTimerPoll(pVM));
564 if (VM_FF_ISPENDING(pVM, fMask))
565 break;
566
567 /*
568 * Block if we're not spinning and the interval isn't all that small.
569 */
570 if ( ( !fSpinning
571 || fBlockOnce)
572#if 1 /* DEBUGGING STUFF - REMOVE LATER */
573 && u64NanoTS >= 100000) /* 0.100 ms */
574#else
575 && u64NanoTS >= 250000) /* 0.250 ms */
576#endif
577 {
578 const uint64_t Start = pUVM->vm.s.Halt.Method12.u64LastBlockTS = RTTimeNanoTS();
579 VMMR3YieldStop(pVM);
580
581 uint32_t cMilliSecs = RT_MIN(u64NanoTS / 1000000, 15);
582 if (cMilliSecs <= pUVM->vm.s.Halt.Method12.cNSBlockedTooLongAvg)
583 cMilliSecs = 1;
584 else
585 cMilliSecs -= pUVM->vm.s.Halt.Method12.cNSBlockedTooLongAvg;
586 //RTLogRelPrintf("u64NanoTS=%RI64 cLoops=%3d sleep %02dms (%7RU64) ", u64NanoTS, cLoops, cMilliSecs, u64NanoTS);
587 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltBlock, a);
588 rc = RTSemEventWait(pUVM->vm.s.EventSemWait, cMilliSecs);
589 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltBlock, a);
590 if (rc == VERR_TIMEOUT)
591 rc = VINF_SUCCESS;
592 else if (VBOX_FAILURE(rc))
593 {
594 AssertRC(rc != VERR_INTERRUPTED);
595 AssertMsgFailed(("RTSemEventWait->%Vrc\n", rc));
596 ASMAtomicUoWriteBool(&pUVM->vm.s.fTerminateEMT, true);
597 VM_FF_SET(pVM, VM_FF_TERMINATE);
598 rc = VERR_INTERNAL_ERROR;
599 break;
600 }
601
602 /*
603 * Calc the statistics.
604 * Update averages every 16th time, and flush parts of the history every 64th time.
605 */
606 const uint64_t Elapsed = RTTimeNanoTS() - Start;
607 pUVM->vm.s.Halt.Method12.cNSBlocked += Elapsed;
608 if (Elapsed > u64NanoTS)
609 pUVM->vm.s.Halt.Method12.cNSBlockedTooLong += Elapsed - u64NanoTS;
610 pUVM->vm.s.Halt.Method12.cBlocks++;
611 if (!(pUVM->vm.s.Halt.Method12.cBlocks & 0xf))
612 {
613 pUVM->vm.s.Halt.Method12.cNSBlockedTooLongAvg = pUVM->vm.s.Halt.Method12.cNSBlockedTooLong / pUVM->vm.s.Halt.Method12.cBlocks;
614 if (!(pUVM->vm.s.Halt.Method12.cBlocks & 0x3f))
615 {
616 pUVM->vm.s.Halt.Method12.cNSBlockedTooLong = pUVM->vm.s.Halt.Method12.cNSBlockedTooLongAvg * 0x40;
617 pUVM->vm.s.Halt.Method12.cBlocks = 0x40;
618 }
619 }
620 //RTLogRelPrintf(" -> %7RU64 ns / %7RI64 ns delta%s\n", Elapsed, Elapsed - u64NanoTS, fBlockOnce ? " (block once)" : "");
621
622 /*
623 * Clear the block once flag if we actually blocked.
624 */
625 if ( fBlockOnce
626 && Elapsed > 100000 /* 0.1 ms */)
627 fBlockOnce = false;
628 }
629 }
630 //if (fSpinning) RTLogRelPrintf("spun for %RU64 ns %u loops; lag=%RU64 pct=%d\n", RTTimeNanoTS() - u64Now, cLoops, TMVirtualSyncGetLag(pVM), u32CatchUpPct);
631
632 ASMAtomicUoWriteBool(&pUVM->vm.s.fWait, false);
633 return rc;
634}
635
636
637/**
638 * Initialize the global 1 halt method.
639 *
640 * @return VBox status code.
641 * @param pUVM Pointer to the user mode VM structure.
642 */
643static DECLCALLBACK(int) vmR3HaltGlobal1Init(PUVM pUVM)
644{
645 return VINF_SUCCESS;
646}
647
648
649/**
650 * The global 1 halt method - Block in GMM (ring-0) and let it
651 * try take care of the global scheduling of EMT threads.
652 */
653static DECLCALLBACK(int) vmR3HaltGlobal1Halt(PUVM pUVM, const uint32_t fMask, uint64_t u64Now)
654{
655 PVM pVM = pUVM->pVM;
656
657 /*
658 * Halt loop.
659 */
660 int rc = VINF_SUCCESS;
661 ASMAtomicWriteBool(&pUVM->vm.s.fWait, true);
662 unsigned cLoops = 0;
663 for (;; cLoops++)
664 {
665 /*
666 * Work the timers and check if we can exit.
667 */
668 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltPoll, a);
669 PDMR3Poll(pVM);
670 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltPoll, a);
671 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltTimers, b);
672 TMR3TimerQueuesDo(pVM);
673 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltTimers, b);
674 if (VM_FF_ISPENDING(pVM, fMask))
675 break;
676
677 /*
678 * Estimate time left to the next event.
679 */
680 uint64_t u64Delta;
681 uint64_t u64GipTime = TMTimerPollGIP(pVM, &u64Delta);
682 if (VM_FF_ISPENDING(pVM, fMask))
683 break;
684
685 /*
686 * Block if we're not spinning and the interval isn't all that small.
687 */
688 if (u64Delta > 50000 /* 0.050ms */)
689 {
690 VMMR3YieldStop(pVM);
691 if (VM_FF_ISPENDING(pVM, fMask))
692 break;
693
694 //RTLogRelPrintf("u64NanoTS=%RI64 cLoops=%3d sleep %02dms (%7RU64) ", u64NanoTS, cLoops, cMilliSecs, u64NanoTS);
695 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltBlock, c);
696 rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_GVMM_SCHED_HALT, u64GipTime, NULL);
697 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltBlock, c);
698 if (rc == VERR_INTERRUPTED)
699 rc = VINF_SUCCESS;
700 else if (VBOX_FAILURE(rc))
701 {
702 AssertMsgFailed(("VMMR0_DO_GVMM_SCHED_HALT->%Vrc\n", rc));
703 ASMAtomicUoWriteBool(&pUVM->vm.s.fTerminateEMT, true);
704 VM_FF_SET(pVM, VM_FF_TERMINATE);
705 rc = VERR_INTERNAL_ERROR;
706 break;
707 }
708 }
709 /*
710 * When spinning call upon the GVMM and do some wakups once
711 * in a while, it's not like we're actually busy or anything.
712 */
713 else if (!(cLoops & 0x1fff))
714 {
715 STAM_REL_PROFILE_START(&pUVM->vm.s.StatHaltYield, d);
716 rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_GVMM_SCHED_POLL, false /* don't yield */, NULL);
717 STAM_REL_PROFILE_STOP(&pUVM->vm.s.StatHaltYield, d);
718 }
719 }
720 //if (fSpinning) RTLogRelPrintf("spun for %RU64 ns %u loops; lag=%RU64 pct=%d\n", RTTimeNanoTS() - u64Now, cLoops, TMVirtualSyncGetLag(pVM), u32CatchUpPct);
721
722 ASMAtomicUoWriteBool(&pUVM->vm.s.fWait, false);
723 return rc;
724}
725
726
727/**
728 * The global 1 halt method - VMR3Wait() worker.
729 *
730 * @returns VBox status code.
731 * @param pUVM Pointer to the user mode VM structure.
732 */
733static DECLCALLBACK(int) vmR3HaltGlobal1Wait(PUVM pUVM)
734{
735 ASMAtomicWriteBool(&pUVM->vm.s.fWait, true);
736
737 PVM pVM = pUVM->pVM;
738 int rc = VINF_SUCCESS;
739 for (;;)
740 {
741 /*
742 * Check Relevant FFs.
743 */
744 if (VM_FF_ISPENDING(pVM, VM_FF_EXTERNAL_SUSPENDED_MASK))
745 break;
746
747 /*
748 * Wait for a while. Someone will wake us up or interrupt the call if
749 * anything needs our attention.
750 */
751 rc = SUPCallVMMR0Ex(pVM->pVMR0, VMMR0_DO_GVMM_SCHED_HALT, RTTimeNanoTS() + 1000000000 /* +1s */, NULL);
752 if (rc == VERR_INTERRUPTED)
753 rc = VINF_SUCCESS;
754 else if (VBOX_FAILURE(rc))
755 {
756 AssertMsgFailed(("RTSemEventWait->%Vrc\n", rc));
757 ASMAtomicUoWriteBool(&pUVM->vm.s.fTerminateEMT, true);
758 VM_FF_SET(pVM, VM_FF_TERMINATE);
759 rc = VERR_INTERNAL_ERROR;
760 break;
761 }
762
763 }
764
765 ASMAtomicUoWriteBool(&pUVM->vm.s.fWait, false);
766 return rc;
767}
768
769
770/**
771 * The global 1 halt method - VMR3NotifyFF() worker.
772 *
773 * @param pUVM Pointer to the user mode VM structure.
774 * @param fNotifiedREM See VMR3NotifyFF().
775 */
776static DECLCALLBACK(void) vmR3HaltGlobal1NotifyFF(PUVM pUVM, bool fNotifiedREM)
777{
778 if (pUVM->vm.s.fWait)
779 {
780 int rc = SUPCallVMMR0Ex(pUVM->pVM->pVMR0, VMMR0_DO_GVMM_SCHED_WAKE_UP, 0, NULL);
781 AssertRC(rc);
782 }
783 else if (!fNotifiedREM)
784 REMR3NotifyFF(pUVM->pVM);
785}
786
787
788/**
789 * Bootstrap VMR3Wait() worker.
790 *
791 * @returns VBox status code.
792 * @param pUVM Pointer to the user mode VM structure.
793 */
794static DECLCALLBACK(int) vmR3BootstrapWait(PUVM pUVM)
795{
796 ASMAtomicWriteBool(&pUVM->vm.s.fWait, true);
797
798 int rc = VINF_SUCCESS;
799 for (;;)
800 {
801 /*
802 * Check Relevant FFs.
803 */
804 if (pUVM->vm.s.pReqs)
805 break;
806 if ( pUVM->pVM
807 && VM_FF_ISPENDING(pUVM->pVM, VM_FF_EXTERNAL_SUSPENDED_MASK))
808 break;
809 if (pUVM->vm.s.fTerminateEMT)
810 break;
811
812 /*
813 * Wait for a while. Someone will wake us up or interrupt the call if
814 * anything needs our attention.
815 */
816 rc = RTSemEventWait(pUVM->vm.s.EventSemWait, 1000);
817 if (rc == VERR_TIMEOUT)
818 rc = VINF_SUCCESS;
819 else if (VBOX_FAILURE(rc))
820 {
821 AssertMsgFailed(("RTSemEventWait->%Vrc\n", rc));
822 ASMAtomicUoWriteBool(&pUVM->vm.s.fTerminateEMT, true);
823 if (pUVM->pVM)
824 VM_FF_SET(pUVM->pVM, VM_FF_TERMINATE);
825 rc = VERR_INTERNAL_ERROR;
826 break;
827 }
828
829 }
830
831 ASMAtomicUoWriteBool(&pUVM->vm.s.fWait, false);
832 return rc;
833}
834
835
836/**
837 * Bootstrap VMR3NotifyFF() worker.
838 *
839 * @param pUVM Pointer to the user mode VM structure.
840 * @param fNotifiedREM See VMR3NotifyFF().
841 */
842static DECLCALLBACK(void) vmR3BootstrapNotifyFF(PUVM pUVM, bool fNotifiedREM)
843{
844 if (pUVM->vm.s.fWait)
845 {
846 int rc = RTSemEventSignal(pUVM->vm.s.EventSemWait);
847 AssertRC(rc);
848 }
849}
850
851
852/**
853 * Default VMR3Wait() worker.
854 *
855 * @returns VBox status code.
856 * @param pUVM Pointer to the user mode VM structure.
857 */
858static DECLCALLBACK(int) vmR3DefaultWait(PUVM pUVM)
859{
860 ASMAtomicWriteBool(&pUVM->vm.s.fWait, true);
861
862 PVM pVM = pUVM->pVM;
863 int rc = VINF_SUCCESS;
864 for (;;)
865 {
866 /*
867 * Check Relevant FFs.
868 */
869 if (VM_FF_ISPENDING(pVM, VM_FF_EXTERNAL_SUSPENDED_MASK))
870 break;
871
872 /*
873 * Wait for a while. Someone will wake us up or interrupt the call if
874 * anything needs our attention.
875 */
876 rc = RTSemEventWait(pUVM->vm.s.EventSemWait, 1000);
877 if (rc == VERR_TIMEOUT)
878 rc = VINF_SUCCESS;
879 else if (VBOX_FAILURE(rc))
880 {
881 AssertMsgFailed(("RTSemEventWait->%Vrc\n", rc));
882 ASMAtomicUoWriteBool(&pUVM->vm.s.fTerminateEMT, true);
883 VM_FF_SET(pVM, VM_FF_TERMINATE);
884 rc = VERR_INTERNAL_ERROR;
885 break;
886 }
887
888 }
889
890 ASMAtomicUoWriteBool(&pUVM->vm.s.fWait, false);
891 return rc;
892}
893
894
895/**
896 * Default VMR3NotifyFF() worker.
897 *
898 * @param pUVM Pointer to the user mode VM structure.
899 * @param fNotifiedREM See VMR3NotifyFF().
900 */
901static DECLCALLBACK(void) vmR3DefaultNotifyFF(PUVM pUVM, bool fNotifiedREM)
902{
903 if (pUVM->vm.s.fWait)
904 {
905 int rc = RTSemEventSignal(pUVM->vm.s.EventSemWait);
906 AssertRC(rc);
907 }
908 else if (!fNotifiedREM)
909 REMR3NotifyFF(pUVM->pVM);
910}
911
912
913/**
914 * Array with halt method descriptors.
915 * VMINT::iHaltMethod contains an index into this array.
916 */
917static const struct VMHALTMETHODDESC
918{
919 /** The halt method id. */
920 VMHALTMETHOD enmHaltMethod;
921 /** The init function for loading config and initialize variables. */
922 DECLR3CALLBACKMEMBER(int, pfnInit,(PUVM pUVM));
923 /** The term function. */
924 DECLR3CALLBACKMEMBER(void, pfnTerm,(PUVM pUVM));
925 /** The halt function. */
926 DECLR3CALLBACKMEMBER(int, pfnHalt,(PUVM pUVM, const uint32_t fMask, uint64_t u64Now));
927 /** The wait function. */
928 DECLR3CALLBACKMEMBER(int, pfnWait,(PUVM pUVM));
929 /** The notifyFF function. */
930 DECLR3CALLBACKMEMBER(void, pfnNotifyFF,(PUVM pUVM, bool fNotifiedREM));
931} g_aHaltMethods[] =
932{
933 { VMHALTMETHOD_BOOTSTRAP, NULL, NULL, NULL, vmR3BootstrapWait, vmR3BootstrapNotifyFF },
934 { VMHALTMETHOD_OLD, NULL, NULL, vmR3HaltOldDoHalt, vmR3DefaultWait, vmR3DefaultNotifyFF },
935 { VMHALTMETHOD_1, vmR3HaltMethod1Init, NULL, vmR3HaltMethod1Halt, vmR3DefaultWait, vmR3DefaultNotifyFF },
936 //{ VMHALTMETHOD_2, vmR3HaltMethod2Init, vmR3HaltMethod2Term, vmR3HaltMethod2DoHalt, vmR3HaltMethod2Wait, vmR3HaltMethod2NotifyFF },
937 { VMHALTMETHOD_GLOBAL_1,vmR3HaltGlobal1Init, NULL, vmR3HaltGlobal1Halt, vmR3HaltGlobal1Wait, vmR3HaltGlobal1NotifyFF },
938};
939
940
941/**
942 * Notify the emulation thread (EMT) about pending Forced Action (FF).
943 *
944 * This function is called by thread other than EMT to make
945 * sure EMT wakes up and promptly service an FF request.
946 *
947 * @param pVM VM handle.
948 * @param fNotifiedREM Set if REM have already been notified. If clear the
949 * generic REMR3NotifyFF() method is called.
950 */
951VMMR3DECL(void) VMR3NotifyFF(PVM pVM, bool fNotifiedREM)
952{
953 LogFlow(("VMR3NotifyFF:\n"));
954 PUVM pUVM = pVM->pUVM;
955 g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnNotifyFF(pUVM, fNotifiedREM);
956}
957
958
959/**
960 * Notify the emulation thread (EMT) about pending Forced Action (FF).
961 *
962 * This function is called by thread other than EMT to make
963 * sure EMT wakes up and promptly service an FF request.
964 *
965 * @param pUVM Pointer to the user mode VM structure.
966 * @param fNotifiedREM Set if REM have already been notified. If clear the
967 * generic REMR3NotifyFF() method is called.
968 */
969VMMR3DECL(void) VMR3NotifyFFU(PUVM pUVM, bool fNotifiedREM)
970{
971 LogFlow(("VMR3NotifyFF:\n"));
972 g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnNotifyFF(pUVM, fNotifiedREM);
973}
974
975
976/**
977 * Halted VM Wait.
978 * Any external event will unblock the thread.
979 *
980 * @returns VINF_SUCCESS unless a fatal error occured. In the latter
981 * case an appropriate status code is returned.
982 * @param pVM VM handle.
983 * @param fIgnoreInterrupts If set the VM_FF_INTERRUPT flags is ignored.
984 * @thread The emulation thread.
985 */
986VMMR3DECL(int) VMR3WaitHalted(PVM pVM, bool fIgnoreInterrupts)
987{
988 LogFlow(("VMR3WaitHalted: fIgnoreInterrupts=%d\n", fIgnoreInterrupts));
989
990 /*
991 * Check Relevant FFs.
992 */
993 const uint32_t fMask = !fIgnoreInterrupts
994 ? VM_FF_EXTERNAL_HALTED_MASK
995 : VM_FF_EXTERNAL_HALTED_MASK & ~(VM_FF_INTERRUPT_APIC | VM_FF_INTERRUPT_PIC);
996 if (VM_FF_ISPENDING(pVM, fMask))
997 {
998 LogFlow(("VMR3WaitHalted: returns VINF_SUCCESS (FF %#x)\n", pVM->fForcedActions));
999 return VINF_SUCCESS;
1000 }
1001
1002 /*
1003 * The yielder is suspended while we're halting, while TM might have clock(s) running
1004 * only at certain times and need to be notified..
1005 */
1006 VMMR3YieldSuspend(pVM);
1007 TMNotifyStartOfHalt(pVM);
1008
1009 /*
1010 * Record halt averages for the last second.
1011 */
1012 PUVM pUVM = pVM->pUVM;
1013 uint64_t u64Now = RTTimeNanoTS();
1014 int64_t off = u64Now - pUVM->vm.s.u64HaltsStartTS;
1015 if (off > 1000000000)
1016 {
1017 if (off > _4G || !pUVM->vm.s.cHalts)
1018 {
1019 pUVM->vm.s.HaltInterval = 1000000000 /* 1 sec */;
1020 pUVM->vm.s.HaltFrequency = 1;
1021 }
1022 else
1023 {
1024 pUVM->vm.s.HaltInterval = (uint32_t)off / pUVM->vm.s.cHalts;
1025 pUVM->vm.s.HaltFrequency = ASMMultU64ByU32DivByU32(pUVM->vm.s.cHalts, 1000000000, (uint32_t)off);
1026 }
1027 pUVM->vm.s.u64HaltsStartTS = u64Now;
1028 pUVM->vm.s.cHalts = 0;
1029 }
1030 pUVM->vm.s.cHalts++;
1031
1032 /*
1033 * Do the halt.
1034 */
1035 int rc = g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnHalt(pUVM, fMask, u64Now);
1036
1037 /*
1038 * Notify TM and resume the yielder
1039 */
1040 TMNotifyEndOfHalt(pVM);
1041 VMMR3YieldResume(pVM);
1042
1043 LogFlow(("VMR3WaitHalted: returns %Vrc (FF %#x)\n", rc, pVM->fForcedActions));
1044 return rc;
1045}
1046
1047
1048/**
1049 * Suspended VM Wait.
1050 * Only a handful of forced actions will cause the function to
1051 * return to the caller.
1052 *
1053 * @returns VINF_SUCCESS unless a fatal error occured. In the latter
1054 * case an appropriate status code is returned.
1055 * @param pUVM Pointer to the user mode VM structure.
1056 * @thread The emulation thread.
1057 */
1058VMMR3DECL(int) VMR3WaitU(PUVM pUVM)
1059{
1060 LogFlow(("VMR3WaitU:\n"));
1061
1062 /*
1063 * Check Relevant FFs.
1064 */
1065 PVM pVM = pUVM->pVM;
1066 if ( pVM
1067 && VM_FF_ISPENDING(pVM, VM_FF_EXTERNAL_SUSPENDED_MASK))
1068 {
1069 LogFlow(("VMR3Wait: returns VINF_SUCCESS (FF %#x)\n", pVM->fForcedActions));
1070 return VINF_SUCCESS;
1071 }
1072
1073 /*
1074 * Do waiting according to the halt method (so VMR3NotifyFF
1075 * doesn't have to special case anything).
1076 */
1077 int rc = g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnWait(pUVM);
1078 LogFlow(("VMR3WaitU: returns %Vrc (FF %#x)\n", rc, pVM ? pVM->fForcedActions : 0));
1079 return rc;
1080}
1081
1082
1083/**
1084 * Changes the halt method.
1085 *
1086 * @returns VBox status code.
1087 * @param pUVM Pointer to the user mode VM structure.
1088 * @param enmHaltMethod The new halt method.
1089 * @thread EMT.
1090 */
1091int vmR3SetHaltMethodU(PUVM pUVM, VMHALTMETHOD enmHaltMethod)
1092{
1093 PVM pVM = pUVM->pVM; Assert(pVM);
1094 VM_ASSERT_EMT(pVM);
1095 AssertReturn(enmHaltMethod > VMHALTMETHOD_INVALID && enmHaltMethod < VMHALTMETHOD_END, VERR_INVALID_PARAMETER);
1096
1097 /*
1098 * Resolve default (can be overridden in the configuration).
1099 */
1100 if (enmHaltMethod == VMHALTMETHOD_DEFAULT)
1101 {
1102 uint32_t u32;
1103 int rc = CFGMR3QueryU32(CFGMR3GetChild(CFGMR3GetRoot(pVM), "VM"), "HaltMethod", &u32);
1104 if (VBOX_SUCCESS(rc))
1105 {
1106 enmHaltMethod = (VMHALTMETHOD)u32;
1107 if (enmHaltMethod <= VMHALTMETHOD_INVALID || enmHaltMethod >= VMHALTMETHOD_END)
1108 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS, N_("Invalid VM/HaltMethod value %d"), enmHaltMethod);
1109 }
1110 else if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_CHILD_NOT_FOUND)
1111 return VMSetError(pVM, rc, RT_SRC_POS, N_("Failed to Query VM/HaltMethod as uint32_t"));
1112 else
1113 enmHaltMethod = VMHALTMETHOD_GLOBAL_1;
1114 //enmHaltMethod = VMHALTMETHOD_1;
1115 //enmHaltMethod = VMHALTMETHOD_OLD;
1116 }
1117 LogRel(("VM: Halt method %s (%d)\n", vmR3GetHaltMethodName(enmHaltMethod), enmHaltMethod));
1118
1119 /*
1120 * Find the descriptor.
1121 */
1122 unsigned i = 0;
1123 while ( i < RT_ELEMENTS(g_aHaltMethods)
1124 && g_aHaltMethods[i].enmHaltMethod != enmHaltMethod)
1125 i++;
1126 AssertReturn(i < RT_ELEMENTS(g_aHaltMethods), VERR_INVALID_PARAMETER);
1127
1128 /*
1129 * Terminate the old one.
1130 */
1131 if ( pUVM->vm.s.enmHaltMethod != VMHALTMETHOD_INVALID
1132 && g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnTerm)
1133 {
1134 g_aHaltMethods[pUVM->vm.s.iHaltMethod].pfnTerm(pUVM);
1135 pUVM->vm.s.enmHaltMethod = VMHALTMETHOD_INVALID;
1136 }
1137
1138 /*
1139 * Init the new one.
1140 */
1141 memset(&pUVM->vm.s.Halt, 0, sizeof(pUVM->vm.s.Halt));
1142 if (g_aHaltMethods[i].pfnInit)
1143 {
1144 int rc = g_aHaltMethods[i].pfnInit(pUVM);
1145 AssertRCReturn(rc, rc);
1146 }
1147 pUVM->vm.s.enmHaltMethod = enmHaltMethod;
1148
1149 ASMAtomicWriteU32(&pUVM->vm.s.iHaltMethod, i);
1150 return VINF_SUCCESS;
1151}
1152
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use