TMAllVirtual.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
2N/A * TM - Timeout Manager, Virtual Time, All Contexts. 2N/A * Copyright (C) 2006 InnoTek Systemberatung GmbH 2N/A * This file is part of VirtualBox Open Source Edition (OSE), as 2N/A * you can redistribute it and/or modify it under the terms of the GNU 2N/A * General Public License as published by the Free Software Foundation, 2N/A * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE 2N/A * distribution. VirtualBox OSE is distributed in the hope that it will 2N/A * be useful, but WITHOUT ANY WARRANTY of any kind. 2N/A * If you received this file as part of a commercial VirtualBox 2N/A * distribution, then only the terms of your commercial VirtualBox 2N/A * license agreement apply instead of the previous paragraph. 2N/A/******************************************************************************* 2N/A*******************************************************************************/ * Gets the current TMCLOCK_VIRTUAL time * @returns The timestamp. * @remark While the flow of time will never go backwards, the speed of the * progress varies due to inaccurate RTTimeNanoTS and TSC. The latter can be * influenced by power saving (SpeedStep, PowerNow!), while the former * makes use of TSC and kernel timers. * Use the chance to check for expired timers. * Gets the current TMCLOCK_VIRTUAL_SYNC time. * @returns The timestamp. * Do TMVirtualGet() to get the current TMCLOCK_VIRTUAL time. * Read the offset and adjust if we're playing catch-up. * The catch-up adjusting work by us decrementing the offset by a percentage of * the time elapsed since the previous TMVritualGetSync call. We take some simple * precautions against racing other threads here, but assume that this isn't going * to be much of a problem since calls to this function is unlikely from threads * It's possible to get a very long or even negative interval between two read * for the following reasons: * - Someone might have suspended the process execution, frequently the case when * - We might be on a different CPU which TSC isn't quite in sync with the * other CPUs in the system. * - RTTimeNanoTS() is returning sligtly different values in GC, R0 and R3 because * of the static variable it uses with the previous read time. * - Another thread is racing us and we might have been preemnted while inside * Assuming nano second virtual time, we can simply ignore any intervals which has * any of the upper 32 bits set. This will have the nice sideeffect of allowing us * to use (faster) 32-bit math. /* we've completely caught up. */ /* Update the previous TMVirtualGetSync time it's not a negative delta. */ Log((
"TMVirtualGetSync: u64Delta=%VRU64\n",
u64Delta));
* Complete the calculation of the current TMCLOCK_VIRTUAL_SYNC time. * The current approach will not let us pass any expired timer. * Gets the current TMCLOCK_VIRTUAL frequency. //#define TM_CONTINUOUS_TIME * Resumes the virtual clock. * @returns VINF_SUCCESS on success. * @returns VINF_INTERNAL_ERROR and VBOX_STRICT assertion if called out of order. * Pauses the virtual clock. * @returns VINF_SUCCESS on success. * @returns VINF_INTERNAL_ERROR and VBOX_STRICT assertion if called out of order. * Converts from virtual ticks to nanoseconds. * @param pVM The VM handle. * @param u64VirtualTicks The virtual ticks to convert. * @remark There could be rounding errors here. We just do a simple integere divide * without any adjustments. * Converts from virtual ticks to microseconds. * @param pVM The VM handle. * @param u64VirtualTicks The virtual ticks to convert. * @remark There could be rounding errors here. We just do a simple integere divide * without any adjustments. * Converts from virtual ticks to milliseconds. * @param pVM The VM handle. * @param u64VirtualTicks The virtual ticks to convert. * @remark There could be rounding errors here. We just do a simple integere divide * without any adjustments. * Converts from nanoseconds to virtual ticks. * @returns virtual ticks. * @param pVM The VM handle. * @param u64NanoTS The nanosecond value ticks to convert. * @remark There could be rounding and overflow errors here. * Converts from microseconds to virtual ticks. * @returns virtual ticks. * @param pVM The VM handle. * @param u64MicroTS The microsecond value ticks to convert. * @remark There could be rounding and overflow errors here. * Converts from milliseconds to virtual ticks. * @returns virtual ticks. * @param pVM The VM handle. * @param u64MilliTS The millisecond value ticks to convert. * @remark There could be rounding and overflow errors here.