VMInternal.h revision c58f1213e628a545081c70e26c6b67a841cff880
/* $Id$ */
/** @file
* VM - Internal header file.
*/
/*
* Copyright (C) 2006-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef ___VMInternal_h
#define ___VMInternal_h
#include <iprt/critsect.h>
#include <setjmp.h>
/** @defgroup grp_vm_int Internals
* @ingroup grp_vm
* @internal
* @{
*/
/**
* VM state change callback.
*/
typedef struct VMATSTATE
{
/** Pointer to the next one. */
/** Pointer to the callback. */
/** The user argument. */
void *pvUser;
} VMATSTATE;
/** Pointer to a VM state change callback. */
typedef VMATSTATE *PVMATSTATE;
/**
* VM error callback.
*/
typedef struct VMATERROR
{
/** Pointer to the next one. */
/** Pointer to the callback. */
/** The user argument. */
void *pvUser;
} VMATERROR;
/** Pointer to a VM error callback. */
typedef VMATERROR *PVMATERROR;
/**
* Chunk of memory allocated off the hypervisor heap in which
* we copy the error details.
*/
typedef struct VMERROR
{
/** The size of the chunk. */
/** The current offset into the chunk.
* We start by putting the filename and function immediately
* after the end of the buffer. */
/** Offset from the start of this structure to the file name. */
/** The line number. */
/** Offset from the start of this structure to the function name. */
/** Offset from the start of this structure to the formatted message text. */
/** The VBox status code. */
/**
* VM runtime error callback.
*/
typedef struct VMATRUNTIMEERROR
{
/** Pointer to the next one. */
struct VMATRUNTIMEERROR *pNext;
/** Pointer to the callback. */
/** The user argument. */
void *pvUser;
/** Pointer to a VM error callback. */
typedef VMATRUNTIMEERROR *PVMATRUNTIMEERROR;
/**
* Chunk of memory allocated off the hypervisor heap in which
* we copy the runtime error details.
*/
typedef struct VMRUNTIMEERROR
{
/** The size of the chunk. */
/** The current offset into the chunk.
* We start by putting the error ID immediately
* after the end of the buffer. */
/** Offset from the start of this structure to the error ID. */
/** Offset from the start of this structure to the formatted message text. */
/** Error flags. */
/** The halt method. */
typedef enum
{
/** The usual invalid value. */
VMHALTMETHOD_INVALID = 0,
/** Use the method used during bootstrapping. */
/** Use the default method. */
/** The first go at a more global approach. */
/** The end of valid methods. (not inclusive of course) */
/** The usual 32-bit max value. */
VMHALTMETHOD_32BIT_HACK = 0x7fffffff
} VMHALTMETHOD;
/**
* VM Internal Data (part of the VM structure).
*
* @todo Move this and all related things to VMM. The VM component was, to some
* extent at least, a bad ad hoc design which should all have been put in
* VMM. @see pg_vm.
*/
typedef struct VMINT
{
/** VM Error Message. */
/** VM Runtime Error Message. */
} VMINT;
/** Pointer to the VM Internal Data (part of the VM structure). */
#ifdef IN_RING3
/**
* VM internal data kept in the UVM.
*/
typedef struct VMINTUSERPERVM
{
/** Head of the standard request queue. Atomic. */
volatile PVMREQ pNormalReqs;
/** Head of the priority request queue. Atomic. */
volatile PVMREQ pPriorityReqs;
/** Number of free request packets. */
/** Array of pointers to lists of free request packets. Atomic. */
/** The reference count of the UVM handle. */
# ifdef VBOX_WITH_STATISTICS
/** Number of VMR3ReqAlloc returning a new packet. */
/** Number of VMR3ReqAlloc causing races. */
/** Number of VMR3ReqAlloc returning a recycled packet. */
/** Number of VMR3ReqFree calls. */
/** Number of times the request was actually freed. */
/** Number of requests served. */
/** Number of times there are more than one request and the others needed to be
* pushed back onto the list. */
/** Number of times we've raced someone when pushing the other requests back
* onto the list. */
# endif
/** Pointer to the support library session.
* Mainly for creation and destruction. */
/** Force EMT to terminate. */
bool volatile fTerminateEMT;
/** Critical section for pAtState and enmPrevVMState. */
/** List of registered state change callbacks. */
/** List of registered state change callbacks. */
/** The previous VM state.
* This is mainly used for the 'Resetting' state, but may come in handy later
* and when debugging. */
/** Critical section for pAtError and pAtRuntimeError. */
/** List of registered error callbacks. */
/** List of registered error callbacks. */
/** The error message count.
* This is incremented every time an error is raised. */
/** The runtime error message count.
* This is incremented every time a runtime error is raised. */
uint32_t volatile cRuntimeErrors;
/** List of registered error callbacks. */
/** List of registered error callbacks. */
/** @name Generic Halt data
* @{
*/
/** The current halt method.
* Can be selected by CFGM option 'VM/HaltMethod'. */
/** The index into g_aHaltMethods of the current halt method. */
uint32_t volatile iHaltMethod;
/** @} */
/** @todo Do NOT add new members here or reuse the current, we need to store the config for
* each halt method separately because we're racing on SMP guest rigs. */
union
{
/**
* Method 1 & 2 - Block whenever possible, and when lagging behind
* switch to spinning with regular blocking every 5-200ms (defaults)
* depending on the accumulated lag. The blocking interval is adjusted
* with the average oversleeping of the last 64 times.
*
* The difference between 1 and 2 is that we use native absolute
* time APIs for the blocking instead of the millisecond based IPRT
* interface.
*/
struct
{
/** The max interval without blocking (when spinning). */
/** The minimum interval between blocking (when spinning). */
/** The value to divide the current lag by to get the raw blocking interval (when spinning). */
/** When to start spinning (lag / nano secs). */
/** When to stop spinning (lag / nano secs). */
} Method12;
/**
* The GVMM manages halted and waiting EMTs.
*/
struct
{
/** The threshold between spinning and blocking. */
} Global1;
} Halt;
/** Pointer to the DBGC instance data. */
void *pvDBGC;
/** TLS index for the VMINTUSERPERVMCPU pointer. */
/** The VM name. (Set after the config constructure has been called.) */
char *pszName;
/** The VM UUID. (Set after the config constructure has been called.) */
# ifdef VBOX_WITH_STATISTICS
# endif
/** Pointer to the VM internal data kept in the UVM. */
typedef VMINTUSERPERVM *PVMINTUSERPERVM;
/**
* VMCPU internal data kept in the UVM.
*
* Almost a copy of VMINTUSERPERVM. Separate data properly later on.
*/
typedef struct VMINTUSERPERVMCPU
{
/** Head of the normal request queue. Atomic. */
volatile PVMREQ pNormalReqs;
/** Head of the priority request queue. Atomic. */
volatile PVMREQ pPriorityReqs;
/** The handle to the EMT thread. */
/** The native of the EMT thread. */
/** Wait event semaphore. */
bool volatile fWait;
/** Align the next bit. */
/** @name Generic Halt data
* @{
*/
/** The average time (ns) between two halts in the last second. (updated once per second) */
/** The average halt frequency for the last second. (updated once per second) */
/** The number of halts in the current period. */
/** When we started counting halts in cHalts (RTTimeNanoTS). */
/** @} */
/** Union containing data and config for the different halt algorithms. */
union
{
/**
* Method 1 & 2 - Block whenever possible, and when lagging behind
* switch to spinning with regular blocking every 5-200ms (defaults)
* depending on the accumulated lag. The blocking interval is adjusted
* with the average oversleeping of the last 64 times.
*
* The difference between 1 and 2 is that we use native absolute
* time APIs for the blocking instead of the millisecond based IPRT
* interface.
*/
struct
{
/** How many times we've blocked while cBlockedNS and cBlockedTooLongNS has been accumulating. */
/** Align the next member. */
/** Avg. time spend oversleeping when blocking. (Re-calculated every so often.) */
/** Total time spend oversleeping when blocking. */
/** Total time spent blocking. */
/** The timestamp (RTTimeNanoTS) of the last block. */
/** When we started spinning relentlessly in order to catch up some of the oversleeping.
* This is 0 when we're not spinning. */
} Method12;
# if 0
/**
* Method 3 & 4 - Same as method 1 & 2 respectivly, except that we
* sprinkle it with yields.
*/
struct
{
/** How many times we've blocked while cBlockedNS and cBlockedTooLongNS has been accumulating. */
/** Avg. time spend oversleeping when blocking. (Re-calculated every so often.) */
/** Total time spend oversleeping when blocking. */
/** Total time spent blocking. */
/** The timestamp (RTTimeNanoTS) of the last block. */
/** How many times we've yielded while cBlockedNS and cBlockedTooLongNS has been accumulating. */
/** Avg. time spend oversleeping when yielding. */
/** Total time spend oversleeping when yielding. */
/** Total time spent yielding. */
/** The timestamp (RTTimeNanoTS) of the last block. */
/** When we started spinning relentlessly in order to catch up some of the oversleeping. */
} Method34;
# endif
} Halt;
/** Profiling the halted state; yielding vs blocking.
* @{ */
/** @} */
/** Pointer to the VM internal data kept in the UVM. */
typedef VMINTUSERPERVMCPU *PVMINTUSERPERVMCPU;
#endif /* IN_RING3 */
DECLCALLBACK(void) vmR3SetErrorUV(PUVM pUVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list *args);
DECLCALLBACK(int) vmR3SetRuntimeError(PVM pVM, uint32_t fFlags, const char *pszErrorId, char *pszMessage);
DECLCALLBACK(int) vmR3SetRuntimeErrorV(PVM pVM, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list *pVa);
void vmSetRuntimeErrorCopy(PVM pVM, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va);
/** @} */
#endif