VirtualBox

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

Last change on this file since 3741 was 3723, checked in by vboxsync, 17 years ago

Double underscore cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 14.2 KB
Line 
1/* $Id: VMInternal.h 3723 2007-07-19 18:46:00Z vboxsync $ */
2/** @file
3 * VM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
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#if !defined(IN_VM_R3) && !defined(IN_VM_R0) && !defined(IN_VM_GC)
30# error "Not in VM! This is an internal header!"
31#endif
32
33
34/** @defgroup grp_vm_int Internals
35 * @ingroup grp_vm
36 * @internal
37 * @{
38 */
39
40
41/**
42 * At-reset callback type.
43 */
44typedef enum VMATRESETTYPE
45{
46 /** Device callback. */
47 VMATRESETTYPE_DEV = 1,
48 /** Internal callback . */
49 VMATRESETTYPE_INTERNAL,
50 /** External callback. */
51 VMATRESETTYPE_EXTERNAL
52} VMATRESETTYPE;
53
54
55/** Pointer to at-reset callback. */
56typedef struct VMATRESET *PVMATRESET;
57
58/**
59 * At reset callback.
60 */
61typedef struct VMATRESET
62{
63 /** Pointer to the next one in the list. */
64 PVMATRESET pNext;
65 /** Callback type. */
66 VMATRESETTYPE enmType;
67 /** User argument for the callback. */
68 void *pvUser;
69 /** Description. */
70 const char *pszDesc;
71 /** Type specific data. */
72 union
73 {
74 /** VMATRESETTYPE_DEV. */
75 struct
76 {
77 /** Callback. */
78 PFNVMATRESET pfnCallback;
79 /** Device instance. */
80 PPDMDEVINS pDevIns;
81 } Dev;
82
83 /** VMATRESETTYPE_INTERNAL. */
84 struct
85 {
86 /** Callback. */
87 PFNVMATRESETINT pfnCallback;
88 } Internal;
89
90 /** VMATRESETTYPE_EXTERNAL. */
91 struct
92 {
93 /** Callback. */
94 PFNVMATRESETEXT pfnCallback;
95 } External;
96 } u;
97} VMATRESET;
98
99
100/**
101 * VM state change callback.
102 */
103typedef struct VMATSTATE
104{
105 /** Pointer to the next one. */
106 struct VMATSTATE *pNext;
107 /** Pointer to the callback. */
108 PFNVMATSTATE pfnAtState;
109 /** The user argument. */
110 void *pvUser;
111} VMATSTATE;
112/** Pointer to a VM state change callback. */
113typedef VMATSTATE *PVMATSTATE;
114
115
116/**
117 * VM error callback.
118 */
119typedef struct VMATERROR
120{
121 /** Pointer to the next one. */
122 struct VMATERROR *pNext;
123 /** Pointer to the callback. */
124 PFNVMATERROR pfnAtError;
125 /** The user argument. */
126 void *pvUser;
127} VMATERROR;
128/** Pointer to a VM error callback. */
129typedef VMATERROR *PVMATERROR;
130
131
132/**
133 * Chunk of memory allocated off the hypervisor heap in which
134 * we copy the error details.
135 */
136typedef struct VMERROR
137{
138 /** The size of the chunk. */
139 uint32_t cbAllocated;
140 /** The current offset into the chunk.
141 * We start by putting the filename and function immediatly
142 * after the end of the buffer. */
143 uint32_t off;
144 /** Offset from the start of this structure to the file name. */
145 uint32_t offFile;
146 /** The line number. */
147 uint32_t iLine;
148 /** Offset from the start of this structure to the function name. */
149 uint32_t offFunction;
150 /** Offset from the start of this structure to the formatted message text. */
151 uint32_t offMessage;
152 /** The VBox status code. */
153 int32_t rc;
154} VMERROR, *PVMERROR;
155
156
157/**
158 * VM runtime error callback.
159 */
160typedef struct VMATRUNTIMEERROR
161{
162 /** Pointer to the next one. */
163 struct VMATRUNTIMEERROR *pNext;
164 /** Pointer to the callback. */
165 PFNVMATRUNTIMEERROR pfnAtRuntimeError;
166 /** The user argument. */
167 void *pvUser;
168} VMATRUNTIMEERROR;
169/** Pointer to a VM error callback. */
170typedef VMATRUNTIMEERROR *PVMATRUNTIMEERROR;
171
172
173/**
174 * Chunk of memory allocated off the hypervisor heap in which
175 * we copy the runtime error details.
176 */
177typedef struct VMRUNTIMEERROR
178{
179 /** The size of the chunk. */
180 uint32_t cbAllocated;
181 /** The current offset into the chunk.
182 * We start by putting the error ID immediatly
183 * after the end of the buffer. */
184 uint32_t off;
185 /** Offset from the start of this structure to the error ID. */
186 uint32_t offErrorID;
187 /** Offset from the start of this structure to the formatted message text. */
188 uint32_t offMessage;
189 /** Whether the error is fatal or not */
190 bool fFatal;
191} VMRUNTIMEERROR, *PVMRUNTIMEERROR;
192
193/** The halt method. */
194typedef enum
195{
196 /** The usual invalid value. */
197 VMHALTMETHOD_INVALID = 0,
198 /** Use the default method. */
199 VMHALTMETHOD_DEFAULT,
200 /** The old spin/yield/block method. */
201 VMHALTMETHOD_OLD,
202 /** The first go at a block/spin method. */
203 VMHALTMETHOD_1,
204 /** The end of valid methods. (not inclusive of course) */
205 VMHALTMETHOD_END,
206 /** The usual 32-bit max value. */
207 VMHALTMETHOD_32BIT_HACK = 0x7fffffff
208} VMHALTMETHOD;
209
210
211/**
212 * Converts a VMM pointer into a VM pointer.
213 * @returns Pointer to the VM structure the VMM is part of.
214 * @param pVMM Pointer to VMM instance data.
215 */
216#define VMINT2VM(pVMM) ( (PVM)((char*)pVMM - pVMM->offVM) )
217
218
219/**
220 * VM Internal Data (part of VM)
221 */
222typedef struct VMINT
223{
224 /** Offset to the VM structure.
225 * See VMINT2VM(). */
226 RTINT offVM;
227
228 /** List of registered reset callbacks. */
229 HCPTRTYPE(PVMATRESET) pAtReset;
230 /** List of registered reset callbacks. */
231 HCPTRTYPE(PVMATRESET *) ppAtResetNext;
232
233 /** List of registered state change callbacks. */
234 HCPTRTYPE(PVMATSTATE) pAtState;
235 /** List of registered state change callbacks. */
236 HCPTRTYPE(PVMATSTATE *) ppAtStateNext;
237
238 /** List of registered error callbacks. */
239 HCPTRTYPE(PVMATERROR) pAtError;
240 /** List of registered error callbacks. */
241 HCPTRTYPE(PVMATERROR *) ppAtErrorNext;
242
243 /** List of registered error callbacks. */
244 HCPTRTYPE(PVMATRUNTIMEERROR) pAtRuntimeError;
245 /** List of registered error callbacks. */
246 HCPTRTYPE(PVMATRUNTIMEERROR *) ppAtRuntimeErrorNext;
247
248 /** Head of the request queue. Atomic. */
249 volatile HCPTRTYPE(PVMREQ) pReqs;
250 /** The last index used during alloc/free. */
251 volatile uint32_t iReqFree;
252 /** Array of pointers to lists of free request packets. Atomic. */
253 volatile HCPTRTYPE(PVMREQ) apReqFree[9];
254 /** Number of free request packets. */
255 volatile uint32_t cReqFree;
256
257 /** Wait/Idle indicator. */
258 volatile uint32_t fWait;
259 /** Wait event semaphore. */
260 HCPTRTYPE(RTSEMEVENT) EventSemWait;
261
262 /** VM Error Message. */
263 R3PTRTYPE(PVMERROR) pErrorR3;
264
265 /** VM Runtime Error Message. */
266 R3PTRTYPE(PVMRUNTIMEERROR) pRuntimeErrorR3;
267
268 /** Pointer to the DBGC instance data. */
269 HCPTRTYPE(void *) pvDBGC;
270
271 /** If set the EMT does the final VM cleanup when it exits.
272 * If clear the VMR3Destroy() caller does so. */
273 bool fEMTDoesTheCleanup;
274
275 /** Set by VMR3SuspendNoSave; cleared by VMR3Resume; signals the VM is in an inconsistent state and saving is not allowed. */
276 bool fPreventSaveState;
277
278 /** vmR3EmulationThread longjmp buffer
279 * @todo r=bird: requires union with padding. See EMInternal.h. */
280 jmp_buf emtJumpEnv;
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 /** @} */
379
380 /** Number of VMR3ReqAlloc returning a new packet. */
381 STAMCOUNTER StatReqAllocNew;
382 /** Number of VMR3ReqAlloc causing races. */
383 STAMCOUNTER StatReqAllocRaces;
384 /** Number of VMR3ReqAlloc returning a recycled packet. */
385 STAMCOUNTER StatReqAllocRecycled;
386 /** Number of VMR3ReqFree calls. */
387 STAMCOUNTER StatReqFree;
388 /** Number of times the request was actually freed. */
389 STAMCOUNTER StatReqFreeOverflow;
390
391 /** Profiling the halted state; yielding vs blocking. */
392 STAMPROFILE StatHaltYield;
393 STAMPROFILE StatHaltBlock;
394 STAMPROFILE StatHaltTimers;
395 STAMPROFILE StatHaltPoll;
396} VMINT, *PVMINT;
397
398
399/**
400 * Emulation thread arguments.
401 */
402typedef struct VMEMULATIONTHREADARGS
403{
404 /** Pointer to the VM structure. */
405 PVM pVM;
406} VMEMULATIONTHREADARGS;
407/** Pointer to the emulation thread arguments. */
408typedef VMEMULATIONTHREADARGS *PVMEMULATIONTHREADARGS;
409
410DECLCALLBACK(int) vmR3EmulationThread(RTTHREAD ThreadSelf, void *pvArg);
411int vmR3SetHaltMethod(PVM pVM, VMHALTMETHOD enmHaltMethod);
412DECLCALLBACK(int) vmR3Destroy(PVM pVM);
413DECLCALLBACK(void) vmR3SetErrorV(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list *args);
414void vmSetErrorCopy(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list args);
415DECLCALLBACK(void) vmR3SetRuntimeErrorV(PVM pVM, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list *args);
416void vmSetRuntimeErrorCopy(PVM pVM, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list args);
417void vmR3DestroyFinalBit(PVM pVM);
418
419
420/** @} */
421
422#endif
423
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