TMAllCpu.cpp revision 4bfa7b58e362a1bca0628643c352c137900bf01a
137N/A * TM - Timeout Manager, CPU Time, All Contexts. 137N/A * Copyright (C) 2006-2007 Oracle Corporation 919N/A * This file is part of VirtualBox Open Source Edition (OSE), as 919N/A * you can redistribute it and/or modify it under the terms of the GNU 919N/A * General Public License (GPL) as published by the Free Software 919N/A * Foundation, in version 2 as it comes in the "COPYING" file of the 919N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the 919N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 919N/A/******************************************************************************* 919N/A*******************************************************************************/ 911N/A * Gets the raw cpu tick from current virtual time. 137N/A * Resumes the CPU timestamp counter ticking. 137N/A * @returns VBox status code. 493N/A * @param pVM The VM to operate on. 137N/A * @param pVCpu The VMCPU to operate on. /** @todo Test that pausing and resuming doesn't cause lag! (I.e. that we're * unpaused before the virtual time and stopped after it. */ * Pauses the CPU timestamp counter ticking. * @returns VBox status code. * @param pVCpu The VMCPU to operate on. * Record why we refused to use offsetted TSC. * Used by TMCpuTickCanUseRealTSC and TMCpuTickGetDeadlineAndTscOffset. * @param pVM Pointer to the VM. * @param pVCpu The current CPU. /* Sample the reason for refusing. */ * Checks if AMD-V / VT-x can use an offsetted hardware TSC or not. * @param pVCpu The VMCPU to operate on. * @param poffRealTSC The offset against the TSC of the current CPU. * 1. A fixed TSC, this is checked at init time. * 2. That the TSC is ticking (we shouldn't be here if it isn't) * 3. Either that we're using the real TSC as time source or * a) we don't have any lag to catch up, and * b) the virtual sync clock hasn't been halted by an expired timer, and * c) we're not using warp drive (accelerated virtual guest time). /* The source is the timer synchronous virtual clock. */ /** @todo When we start collecting statistics on how much time we spend executing * guest code before exiting, we should check this against the next virtual sync * timer timeout. If it's lower than the avg. length, we should trap rdtsc to increase * the chance that we'll get interrupted right after the timer expired. */ /* The source is the real TSC. */ * Calculates the number of host CPU ticks till the next virtual sync deadline. * @note To save work, this function will not bother calculating the accurate * tick count for deadlines that are more than a second ahead. * @returns The number of host cpu ticks to the next deadline. Max one second. * @param cNsToDeadline The number of nano seconds to the next virtual cTicks -=
4000;
/* fudge to account for overhead */ * Gets the next deadline in host CPU clock ticks and the TSC offset if we can * @returns The number of host CPU clock ticks to the next timer deadline. * @param pVCpu The current CPU. * @param poffRealTSC The offset against the TSC of the current CPU. * @remarks Superset of TMCpuTickCanUseRealTSC. * 1. A fixed TSC, this is checked at init time. * 2. That the TSC is ticking (we shouldn't be here if it isn't) * 3. Either that we're using the real TSC as time source or * a) we don't have any lag to catch up, and * b) the virtual sync clock hasn't been halted by an expired timer, and * c) we're not using warp drive (accelerated virtual guest time). /* The source is the timer synchronous virtual clock. */ /* The source is the real TSC. */ * Read the current CPU timestamp counter. * @returns Gets the CPU tsc. * @param pVCpu The VMCPU to operate on. /* Never return a value lower than what the guest has already seen. */ * Read the current CPU timestamp counter. * @returns Gets the CPU tsc. * @param pVCpu The VMCPU to operate on. * Read the current CPU timestamp counter, don't check for expired timers. * @returns Gets the CPU tsc. * @param pVCpu The VMCPU to operate on. * Sets the current CPU timestamp counter. * @returns VBox status code. * @param pVM Pointer to the VM. * @param pVCpu The virtual CPU to operate on. * @param u64Tick The new timestamp value. * @thread EMT which TSC is to be set. * This is easier to do when the TSC is paused since resume will * do all the calculations for us. Actually, we don't need to * call tmCpuTickPause here since we overwrite u64TSC anyway. /** @todo Try help synchronizing it better among the virtual CPUs? */ * Sets the last seen CPU timestamp counter. * @returns VBox status code. * @param pVCpu The virtual CPU to operate on. * @param u64LastSeenTick The last seen timestamp value. * @thread EMT which TSC is to be set. * Gets the last seen CPU timestamp counter. * @param pVCpu The virtual CPU to operate on. * @thread EMT which TSC is to be set. * Get the timestamp frequency. * @returns Number of ticks per second.