/* $Id$ */
/** @file
* IPRT - Time using SUPLib.
*/
/*
* Copyright (C) 2006-2015 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.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
# include <iprt/asm-amd64-x86.h>
#endif
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static DECLCALLBACK(void) rtTimeNanoTSInternalBitch(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS);
static DECLCALLBACK(uint64_t) rtTimeNanoTSInternalBadCpuIndex(PRTTIMENANOTSDATA pData, uint16_t idApic, uint16_t iCpuSet, uint16_t iGipCpu);
#endif
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The previous timestamp value returned by RTTimeNanoTS. */
/** The RTTimeNanoTS data structure that's passed down to the worker functions. */
{
/* .pu64Prev = */ &g_TimeNanoTSPrev,
/* .pfnBad = */ rtTimeNanoTSInternalBitch,
/* .pfnRediscover = */ rtTimeNanoTSInternalRediscover,
/* .pfnBadCpuIndex = */ rtTimeNanoTSInternalBadCpuIndex,
/* .c1nsSteps = */ 0,
/* .cExpired = */ 0,
/* .cBadPrev = */ 0,
/* .cUpdateRaces = */ 0
};
# ifdef IN_RC
/** Array of rtTimeNanoTSInternal worker functions.
* This array is indexed by g_iWorker. */
{
# define RTTIMENANO_WORKER_DETECT 0
};
/** The index into g_apfnWorkers for the function to use.
* @remarks This cannot be a pointer because that'll break down in RC due to
* code relocation. */
# else
/** Pointer to the worker */
# endif /* IN_RC */
/**
* @interface_method_impl{RTTIMENANOTSDATA, pfnBad}
*/
static DECLCALLBACK(void) rtTimeNanoTSInternalBitch(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev,
{
if ((int64_t)u64DeltaPrev < 0)
LogRel(("TM: u64DeltaPrev=%RI64 u64PrevNanoTS=0x%016RX64 u64NanoTS=0x%016RX64\n",
else
Log(("TM: u64DeltaPrev=%RI64 u64PrevNanoTS=0x%016RX64 u64NanoTS=0x%016RX64 (debugging?)\n",
}
/**
* @interface_method_impl{RTTIMENANOTSDATA, pfnBadCpuIndex}
*/
static DECLCALLBACK(uint64_t) rtTimeNanoTSInternalBadCpuIndex(PRTTIMENANOTSDATA pData, uint16_t idApic,
{
# ifndef IN_RC
return RTTimeSystemNanoTS();
# else
return 0;
# endif
}
/**
* Fallback function.
*/
{
if ( pGip
return rtTimeNanoTSInternalRediscover(pData);
# ifndef IN_RC
return RTTimeSystemNanoTS();
# else
return 0;
# endif
}
/**
* Called the first time somebody asks for the time or when the GIP
*/
{
# ifdef IN_RC
# else
# endif
if ( pGip
{
{
# ifdef IN_RC
# else
else
# endif
}
else
{
# ifdef IN_RC
# else
else
# endif
}
}
else
# ifdef IN_RC
# else
# endif
# ifdef IN_RC
# else
# endif
}
#endif /* !IN_GUEST && !RT_NO_GIP */
/**
* Internal worker for getting the current nanosecond timestamp.
*/
{
# ifdef IN_RC
# else
return g_pfnWorker(&g_TimeNanoTSData);
# endif
#else
return RTTimeSystemNanoTS();
#endif
}
/**
* Gets the current nanosecond timestamp.
*
* @returns nanosecond timestamp.
*/
{
return rtTimeNanoTSInternal();
}
/**
* Gets the current millisecond timestamp.
*
* @returns millisecond timestamp.
*/
{
return rtTimeNanoTSInternal() / 1000000;
}
/**
* Debugging the time api.
*
* @returns the number of 1ns steps which has been applied by RTTimeNanoTS().
*/
{
return g_TimeNanoTSData.c1nsSteps;
}
/**
* Debugging the time api.
*
* @returns the number of times the TSC interval expired RTTimeNanoTS().
*/
{
return g_TimeNanoTSData.cExpired;
}
/**
* Debugging the time api.
*
* @returns the number of bad previous values encountered by RTTimeNanoTS().
*/
{
return g_TimeNanoTSData.cBadPrev;
}
/**
* Debugging the time api.
*
* @returns the number of update races in RTTimeNanoTS().
*/
{
return g_TimeNanoTSData.cUpdateRaces;
}
#endif /* !IN_GUEST && !RT_NO_GIP */