VirtualBox

source: vbox/trunk/src/VBox/VMM/VMInternal.h@ 13299

Last change on this file since 13299 was 12989, checked in by vboxsync, 16 years ago

VMM + VBox/cdefs.h: consolidated all the XYZ*DECLS of the VMM into VMM*DECL. Removed dead DECL and IN_XYZ* macros.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 14.6 KB
Line 
1/* $Id: VMInternal.h 12989 2008-10-06 02:15:39Z vboxsync $ */
2/** @file
3 * VM - Internal header file.
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#ifndef ___VMInternal_h
23#define ___VMInternal_h
24
25#include <VBox/cdefs.h>
26#include <VBox/vmapi.h>
27#include <setjmp.h>
28
29
30
31/** @defgroup grp_vm_int Internals
32 * @ingroup grp_vm
33 * @internal
34 * @{
35 */
36
37
38/**
39 * At-reset callback type.
40 */
41typedef enum VMATRESETTYPE
42{
43 /** Device callback. */
44 VMATRESETTYPE_DEV = 1,
45 /** Internal callback . */
46 VMATRESETTYPE_INTERNAL,
47 /** External callback. */
48 VMATRESETTYPE_EXTERNAL
49} VMATRESETTYPE;
50
51
52/** Pointer to at-reset callback. */
53typedef struct VMATRESET *PVMATRESET;
54
55/**
56 * At reset callback.
57 */
58typedef struct VMATRESET
59{
60 /** Pointer to the next one in the list. */
61 PVMATRESET pNext;
62 /** Callback type. */
63 VMATRESETTYPE enmType;
64 /** User argument for the callback. */
65 void *pvUser;
66 /** Description. */
67 const char *pszDesc;
68 /** Type specific data. */
69 union
70 {
71 /** VMATRESETTYPE_DEV. */
72 struct
73 {
74 /** Callback. */
75 PFNVMATRESET pfnCallback;
76 /** Device instance. */
77 PPDMDEVINS pDevIns;
78 } Dev;
79
80 /** VMATRESETTYPE_INTERNAL. */
81 struct
82 {
83 /** Callback. */
84 PFNVMATRESETINT pfnCallback;
85 } Internal;
86
87 /** VMATRESETTYPE_EXTERNAL. */
88 struct
89 {
90 /** Callback. */
91 PFNVMATRESETEXT pfnCallback;
92 } External;
93 } u;
94} VMATRESET;
95
96
97/**
98 * VM state change callback.
99 */
100typedef struct VMATSTATE
101{
102 /** Pointer to the next one. */
103 struct VMATSTATE *pNext;
104 /** Pointer to the callback. */
105 PFNVMATSTATE pfnAtState;
106 /** The user argument. */
107 void *pvUser;
108} VMATSTATE;
109/** Pointer to a VM state change callback. */
110typedef VMATSTATE *PVMATSTATE;
111
112
113/**
114 * VM error callback.
115 */
116typedef struct VMATERROR
117{
118 /** Pointer to the next one. */
119 struct VMATERROR *pNext;
120 /** Pointer to the callback. */
121 PFNVMATERROR pfnAtError;
122 /** The user argument. */
123 void *pvUser;
124} VMATERROR;
125/** Pointer to a VM error callback. */
126typedef VMATERROR *PVMATERROR;
127
128
129/**
130 * Chunk of memory allocated off the hypervisor heap in which
131 * we copy the error details.
132 */
133typedef struct VMERROR
134{
135 /** The size of the chunk. */
136 uint32_t cbAllocated;
137 /** The current offset into the chunk.
138 * We start by putting the filename and function immediatly
139 * after the end of the buffer. */
140 uint32_t off;
141 /** Offset from the start of this structure to the file name. */
142 uint32_t offFile;
143 /** The line number. */
144 uint32_t iLine;
145 /** Offset from the start of this structure to the function name. */
146 uint32_t offFunction;
147 /** Offset from the start of this structure to the formatted message text. */
148 uint32_t offMessage;
149 /** The VBox status code. */
150 int32_t rc;
151} VMERROR, *PVMERROR;
152
153
154/**
155 * VM runtime error callback.
156 */
157typedef struct VMATRUNTIMEERROR
158{
159 /** Pointer to the next one. */
160 struct VMATRUNTIMEERROR *pNext;
161 /** Pointer to the callback. */
162 PFNVMATRUNTIMEERROR pfnAtRuntimeError;
163 /** The user argument. */
164 void *pvUser;
165} VMATRUNTIMEERROR;
166/** Pointer to a VM error callback. */
167typedef VMATRUNTIMEERROR *PVMATRUNTIMEERROR;
168
169
170/**
171 * Chunk of memory allocated off the hypervisor heap in which
172 * we copy the runtime error details.
173 */
174typedef struct VMRUNTIMEERROR
175{
176 /** The size of the chunk. */
177 uint32_t cbAllocated;
178 /** The current offset into the chunk.
179 * We start by putting the error ID immediatly
180 * after the end of the buffer. */
181 uint32_t off;
182 /** Offset from the start of this structure to the error ID. */
183 uint32_t offErrorID;
184 /** Offset from the start of this structure to the formatted message text. */
185 uint32_t offMessage;
186 /** Whether the error is fatal or not */
187 bool fFatal;
188} VMRUNTIMEERROR, *PVMRUNTIMEERROR;
189
190/** The halt method. */
191typedef enum
192{
193 /** The usual invalid value. */
194 VMHALTMETHOD_INVALID = 0,
195 /** Use the method used during bootstrapping. */
196 VMHALTMETHOD_BOOTSTRAP,
197 /** Use the default method. */
198 VMHALTMETHOD_DEFAULT,
199 /** The old spin/yield/block method. */
200 VMHALTMETHOD_OLD,
201 /** The first go at a block/spin method. */
202 VMHALTMETHOD_1,
203 /** The first go at a more global approach. */
204 VMHALTMETHOD_GLOBAL_1,
205 /** The end of valid methods. (not inclusive of course) */
206 VMHALTMETHOD_END,
207 /** The usual 32-bit max value. */
208 VMHALTMETHOD_32BIT_HACK = 0x7fffffff
209} VMHALTMETHOD;
210
211
212/**
213 * Converts a VMM pointer into a VM pointer.
214 * @returns Pointer to the VM structure the VMM is part of.
215 * @param pVMM Pointer to VMM instance data.
216 */
217#define VMINT2VM(pVMM) ( (PVM)((char*)pVMM - pVMM->offVM) )
218
219
220/**
221 * VM Internal Data (part of VM)
222 */
223typedef struct VMINT
224{
225 /** Offset to the VM structure.
226 * See VMINT2VM(). */
227 RTINT offVM;
228 /** VM Error Message. */
229 R3PTRTYPE(PVMERROR) pErrorR3;
230 /** VM Runtime Error Message. */
231 R3PTRTYPE(PVMRUNTIMEERROR) pRuntimeErrorR3;
232 /** Set by VMR3SuspendNoSave; cleared by VMR3Resume; signals the VM is in an inconsistent state and saving is not allowed. */
233 bool fPreventSaveState;
234} VMINT, *PVMINT;
235
236
237/**
238 * VM internal data kept in the UVM.
239 */
240typedef struct VMINTUSERPERVM
241{
242 /** Head of the request queue. Atomic. */
243 volatile PVMREQ pReqs;
244 /** The last index used during alloc/free. */
245 volatile uint32_t iReqFree;
246 /** Number of free request packets. */
247 volatile uint32_t cReqFree;
248 /** Array of pointers to lists of free request packets. Atomic. */
249 volatile PVMREQ apReqFree[9];
250
251#ifdef VBOX_WITH_STATISTICS
252 /** Number of VMR3ReqAlloc returning a new packet. */
253 STAMCOUNTER StatReqAllocNew;
254 /** Number of VMR3ReqAlloc causing races. */
255 STAMCOUNTER StatReqAllocRaces;
256 /** Number of VMR3ReqAlloc returning a recycled packet. */
257 STAMCOUNTER StatReqAllocRecycled;
258 /** Number of VMR3ReqFree calls. */
259 STAMCOUNTER StatReqFree;
260 /** Number of times the request was actually freed. */
261 STAMCOUNTER StatReqFreeOverflow;
262#endif
263
264 /** Pointer to the support library session.
265 * Mainly for creation and destruction.. */
266 PSUPDRVSESSION pSession;
267
268 /** The handle to the EMT thread. */
269 RTTHREAD ThreadEMT;
270 /** The native of the EMT thread. */
271 RTNATIVETHREAD NativeThreadEMT;
272 /** Wait event semaphore. */
273 RTSEMEVENT EventSemWait;
274 /** Wait/Idle indicator. */
275 bool volatile fWait;
276 /** Force EMT to terminate. */
277 bool volatile fTerminateEMT;
278 /** If set the EMT does the final VM cleanup when it exits.
279 * If clear the VMR3Destroy() caller does so. */
280 bool fEMTDoesTheCleanup;
281
282 /** @name Generic Halt data
283 * @{
284 */
285 /** The current halt method.
286 * Can be selected by CFGM option 'VM/HaltMethod'. */
287 VMHALTMETHOD enmHaltMethod;
288 /** The index into g_aHaltMethods of the current halt method. */
289 uint32_t volatile iHaltMethod;
290 /** The average time (ns) between two halts in the last second. (updated once per second) */
291 uint32_t HaltInterval;
292 /** The average halt frequency for the last second. (updated once per second) */
293 uint32_t HaltFrequency;
294 /** The number of halts in the current period. */
295 uint32_t cHalts;
296 uint32_t padding; /**< alignment padding. */
297 /** When we started counting halts in cHalts (RTTimeNanoTS). */
298 uint64_t u64HaltsStartTS;
299 /** @} */
300
301 /** Union containing data and config for the different halt algorithms. */
302 union
303 {
304 /**
305 * Method 1 & 2 - Block whenever possible, and when lagging behind
306 * switch to spinning with regular blocking every 5-200ms (defaults)
307 * depending on the accumulated lag. The blocking interval is adjusted
308 * with the average oversleeping of the last 64 times.
309 *
310 * The difference between 1 and 2 is that we use native absolute
311 * time APIs for the blocking instead of the millisecond based IPRT
312 * interface.
313 */
314 struct
315 {
316 /** How many times we've blocked while cBlockedNS and cBlockedTooLongNS has been accumulating. */
317 uint32_t cBlocks;
318 /** Avg. time spend oversleeping when blocking. (Re-calculated every so often.) */
319 uint64_t cNSBlockedTooLongAvg;
320 /** Total time spend oversleeping when blocking. */
321 uint64_t cNSBlockedTooLong;
322 /** Total time spent blocking. */
323 uint64_t cNSBlocked;
324 /** The timestamp (RTTimeNanoTS) of the last block. */
325 uint64_t u64LastBlockTS;
326
327 /** When we started spinning relentlessly in order to catch up some of the oversleeping.
328 * This is 0 when we're not spinning. */
329 uint64_t u64StartSpinTS;
330
331 /** The max interval without blocking (when spinning). */
332 uint32_t u32MinBlockIntervalCfg;
333 /** The minimum interval between blocking (when spinning). */
334 uint32_t u32MaxBlockIntervalCfg;
335 /** The value to divide the current lag by to get the raw blocking interval (when spinning). */
336 uint32_t u32LagBlockIntervalDivisorCfg;
337 /** When to start spinning (lag / nano secs). */
338 uint32_t u32StartSpinningCfg;
339 /** When to stop spinning (lag / nano secs). */
340 uint32_t u32StopSpinningCfg;
341 } Method12;
342
343#if 0
344 /**
345 * Method 3 & 4 - Same as method 1 & 2 respectivly, except that we
346 * sprinkle it with yields.
347 */
348 struct
349 {
350 /** How many times we've blocked while cBlockedNS and cBlockedTooLongNS has been accumulating. */
351 uint32_t cBlocks;
352 /** Avg. time spend oversleeping when blocking. (Re-calculated every so often.) */
353 uint64_t cBlockedTooLongNSAvg;
354 /** Total time spend oversleeping when blocking. */
355 uint64_t cBlockedTooLongNS;
356 /** Total time spent blocking. */
357 uint64_t cBlockedNS;
358 /** The timestamp (RTTimeNanoTS) of the last block. */
359 uint64_t u64LastBlockTS;
360
361 /** How many times we've yielded while cBlockedNS and cBlockedTooLongNS has been accumulating. */
362 uint32_t cYields;
363 /** Avg. time spend oversleeping when yielding. */
364 uint32_t cYieldTooLongNSAvg;
365 /** Total time spend oversleeping when yielding. */
366 uint64_t cYieldTooLongNS;
367 /** Total time spent yielding. */
368 uint64_t cYieldedNS;
369 /** The timestamp (RTTimeNanoTS) of the last block. */
370 uint64_t u64LastYieldTS;
371
372 /** When we started spinning relentlessly in order to catch up some of the oversleeping. */
373 uint64_t u64StartSpinTS;
374 } Method34;
375#endif
376 } Halt;
377
378 /** Profiling the halted state; yielding vs blocking.
379 * @{ */
380 STAMPROFILE StatHaltYield;
381 STAMPROFILE StatHaltBlock;
382 STAMPROFILE StatHaltTimers;
383 STAMPROFILE StatHaltPoll;
384 /** @} */
385
386
387 /** List of registered reset callbacks. */
388 PVMATRESET pAtReset;
389 /** List of registered reset callbacks. */
390 PVMATRESET *ppAtResetNext;
391
392 /** List of registered state change callbacks. */
393 PVMATSTATE pAtState;
394 /** List of registered state change callbacks. */
395 PVMATSTATE *ppAtStateNext;
396
397 /** List of registered error callbacks. */
398 PVMATERROR pAtError;
399 /** List of registered error callbacks. */
400 PVMATERROR *ppAtErrorNext;
401
402 /** List of registered error callbacks. */
403 PVMATRUNTIMEERROR pAtRuntimeError;
404 /** List of registered error callbacks. */
405 PVMATRUNTIMEERROR *ppAtRuntimeErrorNext;
406
407 /** Pointer to the DBGC instance data. */
408 void *pvDBGC;
409
410
411 /** vmR3EmulationThread longjmp buffer. Must be last in the structure. */
412 jmp_buf emtJumpEnv;
413} VMINTUSERPERVM;
414
415/** Pointer to the VM internal data kept in the UVM. */
416typedef VMINTUSERPERVM *PVMINTUSERPERVM;
417
418
419DECLCALLBACK(int) vmR3EmulationThread(RTTHREAD ThreadSelf, void *pvArg);
420int vmR3SetHaltMethodU(PUVM pUVM, VMHALTMETHOD enmHaltMethod);
421DECLCALLBACK(int) vmR3Destroy(PVM pVM);
422DECLCALLBACK(void) vmR3SetErrorUV(PUVM pUVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list *args);
423void vmSetErrorCopy(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list args);
424DECLCALLBACK(void) vmR3SetRuntimeErrorV(PVM pVM, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list *args);
425void vmSetRuntimeErrorCopy(PVM pVM, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list args);
426void vmR3DestroyFinalBitFromEMT(PUVM pUVM);
427void vmR3SetState(PVM pVM, VMSTATE enmStateNew);
428
429
430/** @} */
431
432#endif
433
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