VMInternal.h revision 0030f46ad9598f1af9e85adc03691021e18c5ddf
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * VM - Internal header file.
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * available from http://www.virtualbox.org. This file is free software;
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * you can redistribute it and/or modify it under the terms of the GNU
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * General Public License (GPL) as published by the Free Software
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * additional information or have any questions.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync/** @defgroup grp_vm_int Internals
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * @ingroup grp_vm
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * @internal
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync * At-reset callback type.
b72d3233df38e3122eda39b39a27b35c27209615vboxsync /** Device callback. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync /** Internal callback . */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync /** External callback. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync/** Pointer to at-reset callback. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync * At reset callback.
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsynctypedef struct VMATRESET
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync /** Pointer to the next one in the list. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync /** Callback type. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync /** User argument for the callback. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync /** Description. */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync const char *pszDesc;
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync /** Type specific data. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** VMATRESETTYPE_DEV. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Callback. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Device instance. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** VMATRESETTYPE_INTERNAL. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** Callback. */
39c2eccedfdb7455c52225543c355e33a65f0c81vboxsync /** VMATRESETTYPE_EXTERNAL. */
39c2eccedfdb7455c52225543c355e33a65f0c81vboxsync /** Callback. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * VM state change callback.
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsynctypedef struct VMATSTATE
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** Pointer to the next one. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** Pointer to the callback. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** The user argument. */
0368e9c310393e82ef37c480b6acbd0f107cf0edvboxsync/** Pointer to a VM state change callback. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync * VM error callback.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsynctypedef struct VMATERROR
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsync /** Pointer to the next one. */
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsync /** Pointer to the callback. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** The user argument. */
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsync/** Pointer to a VM error callback. */
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsync * Chunk of memory allocated off the hypervisor heap in which
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsync * we copy the error details.
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsynctypedef struct VMERROR
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** The size of the chunk. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** The current offset into the chunk.
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsync * We start by putting the filename and function immediatly
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsync * after the end of the buffer. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** Offset from the start of this structure to the file name. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** The line number. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** Offset from the start of this structure to the function name. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** Offset from the start of this structure to the formatted message text. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** The VBox status code. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * VM runtime error callback.
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsync /** Pointer to the next one. */
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsync /** Pointer to the callback. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** The user argument. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync/** Pointer to a VM error callback. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * Chunk of memory allocated off the hypervisor heap in which
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * we copy the runtime error details.
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsync /** The size of the chunk. */
d1c36fd86d36726777e3d6f9d040573e0aaf30devboxsync /** The current offset into the chunk.
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * We start by putting the error ID immediatly
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync * after the end of the buffer. */
84f746c9015f34e9ab096b87e063d0d6ab7fc7aevboxsync /** Offset from the start of this structure to the error ID. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync /** Offset from the start of this structure to the formatted message text. */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync /** Error flags. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync/** The halt method. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsynctypedef enum
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync /** The usual invalid value. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync /** Use the method used during bootstrapping. */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync /** Use the default method. */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync /** The old spin/yield/block method. */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync /** The first go at a block/spin method. */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync /** The first go at a more global approach. */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync /** The end of valid methods. (not inclusive of course) */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync /** The usual 32-bit max value. */
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync * VM Internal Data (part of the VM structure).
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync * @todo Move this and all related things to VMM. The VM component was, to some
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync * extent at least, a bad ad hoc design which should all have been put in
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync * VMM. @see pg_vm.
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsynctypedef struct VMINT
e2a73964f463b9e91f6f096f9e15974a3edcc416vboxsync /** VM Error Message. */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync /** VM Runtime Error Message. */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync /** Set by VMR3SuspendNoSave; cleared by VMR3Resume; signals the VM is in an
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync * inconsistent state and saving is not allowed. */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync/** Pointer to the VM Internal Data (part of the VM structure). */
39c2eccedfdb7455c52225543c355e33a65f0c81vboxsync * VM internal data kept in the UVM.
b72d3233df38e3122eda39b39a27b35c27209615vboxsync /** Head of the request queue. Atomic. */
39c2eccedfdb7455c52225543c355e33a65f0c81vboxsync /** The last index used during alloc/free. */
39c2eccedfdb7455c52225543c355e33a65f0c81vboxsync /** Number of free request packets. */
39c2eccedfdb7455c52225543c355e33a65f0c81vboxsync /** Array of pointers to lists of free request packets. Atomic. */
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync /** Number of VMR3ReqAlloc returning a new packet. */
39c2eccedfdb7455c52225543c355e33a65f0c81vboxsync /** Number of VMR3ReqAlloc causing races. */
39c2eccedfdb7455c52225543c355e33a65f0c81vboxsync /** Number of VMR3ReqAlloc returning a recycled packet. */
39c2eccedfdb7455c52225543c355e33a65f0c81vboxsync /** Number of VMR3ReqFree calls. */
39c2eccedfdb7455c52225543c355e33a65f0c81vboxsync /** Number of times the request was actually freed. */
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync /** Pointer to the support library session.
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync * Mainly for creation and destruction.. */
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync /** Force EMT to terminate. */
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync bool volatile fTerminateEMT;
b35e3948f1287430503b6b432945b8cf4bfd3a23vboxsync /** If set the EMT does the final VM cleanup when it exits.
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync * If clear the VMR3Destroy() caller does so. */
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync /** List of registered reset callbacks. */
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync /** List of registered reset callbacks. */
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync /** List of registered state change callbacks. */
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync /** List of registered state change callbacks. */
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync /** List of registered error callbacks. */
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync /** List of registered error callbacks. */
d8dee9a7ef33d4c705d5fd087d5af9c7cb071f85vboxsync /** List of registered error callbacks. */
0612e2adbcc146b9eb7748983c720e35e38d0dc9vboxsync /** List of registered error callbacks. */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** @name Generic Halt data
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** The current halt method.
683eff3070b1b86fe71b71af7fda82766ea19d17vboxsync * Can be selected by CFGM option 'VM/HaltMethod'. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** The index into g_aHaltMethods of the current halt method. */
683eff3070b1b86fe71b71af7fda82766ea19d17vboxsync /** @todo Do NOT add new members here or resue the current, we need to store the config for
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * each halt method seperately because we're racing on SMP guest rigs. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * Method 1 & 2 - Block whenever possible, and when lagging behind
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync * switch to spinning with regular blocking every 5-200ms (defaults)
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync * depending on the accumulated lag. The blocking interval is adjusted
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * with the average oversleeping of the last 64 times.
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * The difference between 1 and 2 is that we use native absolute
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * time APIs for the blocking instead of the millisecond based IPRT
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * interface.
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** The max interval without blocking (when spinning). */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** The minimum interval between blocking (when spinning). */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** The value to divide the current lag by to get the raw blocking interval (when spinning). */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** When to start spinning (lag / nano secs). */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** When to stop spinning (lag / nano secs). */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** Pointer to the DBGC instance data. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** TLS index for the VMINTUSERPERVMCPU pointer. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync/** Pointer to the VM internal data kept in the UVM. */
683eff3070b1b86fe71b71af7fda82766ea19d17vboxsync * VMCPU internal data kept in the UVM.
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * Almost a copy of VMINTUSERPERVM. Separate data properly later on.
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Head of the request queue. Atomic. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** The handle to the EMT thread. */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** The native of the EMT thread. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Wait event semaphore. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Wait/Idle indicator. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync bool volatile fWait;
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Force EMT to terminate. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync bool volatile fTerminateEMT;
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** If set the EMT does the final VM cleanup when it exits.
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync * If clear the VMR3Destroy() caller does so. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** @name Generic Halt data
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** The average time (ns) between two halts in the last second. (updated once per second) */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** The average halt frequency for the last second. (updated once per second) */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** The number of halts in the current period. */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** When we started counting halts in cHalts (RTTimeNanoTS). */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Union containing data and config for the different halt algorithms. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * Method 1 & 2 - Block whenever possible, and when lagging behind
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync * switch to spinning with regular blocking every 5-200ms (defaults)
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * depending on the accumulated lag. The blocking interval is adjusted
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * with the average oversleeping of the last 64 times.
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync * The difference between 1 and 2 is that we use native absolute
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync * time APIs for the blocking instead of the millisecond based IPRT
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * interface.
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** How many times we've blocked while cBlockedNS and cBlockedTooLongNS has been accumulating. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Avg. time spend oversleeping when blocking. (Re-calculated every so often.) */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Total time spend oversleeping when blocking. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Total time spent blocking. */
683eff3070b1b86fe71b71af7fda82766ea19d17vboxsync /** The timestamp (RTTimeNanoTS) of the last block. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** When we started spinning relentlessly in order to catch up some of the oversleeping.
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * This is 0 when we're not spinning. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * Method 3 & 4 - Same as method 1 & 2 respectivly, except that we
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync * sprinkle it with yields.
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** How many times we've blocked while cBlockedNS and cBlockedTooLongNS has been accumulating. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Avg. time spend oversleeping when blocking. (Re-calculated every so often.) */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Total time spend oversleeping when blocking. */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** Total time spent blocking. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** The timestamp (RTTimeNanoTS) of the last block. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** How many times we've yielded while cBlockedNS and cBlockedTooLongNS has been accumulating. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Avg. time spend oversleeping when yielding. */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** Total time spend oversleeping when yielding. */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** Total time spent yielding. */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** The timestamp (RTTimeNanoTS) of the last block. */
6d41476175401a18893ea8cb8a40d125eefa04f3vboxsync /** When we started spinning relentlessly in order to catch up some of the oversleeping. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync /** Profiling the halted state; yielding vs blocking.
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsync/** Pointer to the VM internal data kept in the UVM. */
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsyncDECLCALLBACK(int) vmR3EmulationThread(RTTHREAD ThreadSelf, void *pvArg);
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsyncint vmR3SetHaltMethodU(PUVM pUVM, VMHALTMETHOD enmHaltMethod);
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsyncDECLCALLBACK(void) vmR3SetErrorUV(PUVM pUVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list *args);
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsyncvoid vmSetErrorCopy(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list args);
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsyncDECLCALLBACK(int) vmR3SetRuntimeErrorV(PVM pVM, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list *pVa);
9b456547aefb8a2e8f5600eba9ec377dbc9b4475vboxsyncvoid vmSetRuntimeErrorCopy(PVM pVM, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va);