TMAllCpu.cpp revision dab63c7d7208886c4c613eeec9af4c33360f72e8
/* $Id$ */
/** @file
* TM - Timeout Manager, CPU Time, All Contexts.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_TM
#include "../TMInternal.h"
/**
* Gets the raw cpu tick from current virtual time.
*/
{
if (u64 != TMCLOCK_FREQ_VIRTUAL)
return u64;
}
/**
* Resumes the CPU timestamp counter ticking.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param pVCpu The VMCPU to operate on.
* @internal
*/
{
{
{
/** @todo Test that pausing and resuming doesn't cause lag! (I.e. that we're
* unpaused before the virtual time and stopped after it. */
else
}
return VINF_SUCCESS;
}
AssertFailed();
return VERR_INTERNAL_ERROR;
}
/**
* Pauses the CPU timestamp counter ticking.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param pVCpu The VMCPU to operate on.
* @internal
*/
{
{
return VINF_SUCCESS;
}
AssertFailed();
return VERR_INTERNAL_ERROR;
}
/**
* 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.
* Can be NULL.
* @thread EMT.
*/
{
/*
* We require:
* 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. */
if (poffRealTSC)
{
/** @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. */
}
}
else if (poffRealTSC)
{
/* The source is the real TSC. */
else
*poffRealTSC = 0;
}
/** @todo count this? */
return true;
}
#ifdef VBOX_WITH_STATISTICS
/* Sample the reason for refusing. */
{
{
else
}
}
#endif
return false;
}
/**
* Read the current CPU timstamp counter.
*
* @returns Gets the CPU tsc.
* @param pVCpu The VMCPU to operate on.
*/
{
{
{
u64 = ASMReadTSC();
else
}
else
u64 = ASMReadTSC();
}
else
return u64;
}
/**
* Read the current CPU timstamp counter.
*
* @returns Gets the CPU tsc.
* @param pVCpu The VMCPU to operate on.
*/
{
}
/**
* Read the current CPU timstamp 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 The VM handle.
* @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 calcuations for us.
*/
if (fTSCTicking)
/** @todo Try help synchronizing it better among the virtual CPUs? */
if (fTSCTicking)
return VINF_SUCCESS;
}
/**
* Get the timestamp frequency.
*
* @returns Number of ticks per second.
* @param pVM The VM.
*/
{
{
return cTSCTicksPerSecond;
}
}