tm.h revision 3ee05df7c67eccd6d1ecff48edb69e0afd75bb25
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * TM - Time Monitor.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Copyright (C) 2006-2007 innotek GmbH
a3e5b1cf4ab5395f45b7ed855c72f70e4bcf4219vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a3e5b1cf4ab5395f45b7ed855c72f70e4bcf4219vboxsync * available from http://www.virtualbox.org. This file is free software;
a3e5b1cf4ab5395f45b7ed855c72f70e4bcf4219vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a3e5b1cf4ab5395f45b7ed855c72f70e4bcf4219vboxsync * General Public License as published by the Free Software Foundation,
a3e5b1cf4ab5395f45b7ed855c72f70e4bcf4219vboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
a3e5b1cf4ab5395f45b7ed855c72f70e4bcf4219vboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
a3e5b1cf4ab5395f45b7ed855c72f70e4bcf4219vboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync/** @defgroup grp_tm The Time Monitor API
319f8f820db4356edaff70c2e019376e1ec71487vboxsync/** Enable a timer hack which improves the timer response/resolution a bit. */
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Clock type.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync /** Real host time.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * This clock ticks all the time, so use with care. */
319f8f820db4356edaff70c2e019376e1ec71487vboxsync /** Virtual guest time.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * This clock only ticks when the guest is running. It's implemented
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * as an offset to real time. */
319f8f820db4356edaff70c2e019376e1ec71487vboxsync /** Virtual guest synchronized timer time.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * This is a special clock and timer queue for synchronizing virtual timers and
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * virtual time sources. This clock is trying to keep up with TMCLOCK_VIRTUAL,
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * but will wait for timers to be executed. If it lags too far behind TMCLOCK_VIRTUAL,
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * it will try speed up to close the distance. */
319f8f820db4356edaff70c2e019376e1ec71487vboxsync /** Virtual CPU timestamp. (Running only when we're executing guest code.) */
319f8f820db4356edaff70c2e019376e1ec71487vboxsync /** Number of clocks. */
319f8f820db4356edaff70c2e019376e1ec71487vboxsync/** @name Real Clock Methods
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Gets the current TMCLOCK_REAL time.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns Real time.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM The VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Gets the frequency of the TMCLOCK_REAL clock.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns frequency.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM The VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync/** @name Virtual Clock Methods
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Gets the current TMCLOCK_VIRTUAL time.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns The timestamp.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @remark While the flow of time will never go backwards, the speed of the
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * progress varies due to inaccurate RTTimeNanoTS and TSC. The latter can be
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * influenced by power saving (SpeedStep, PowerNow!), while the former
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * makes use of TSC and kernel timers.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Gets the current TMCLOCK_VIRTUAL time
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns The timestamp.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param fCheckTimers Check timers or not
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @remark While the flow of time will never go backwards, the speed of the
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * progress varies due to inaccurate RTTimeNanoTS and TSC. The latter can be
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * influenced by power saving (SpeedStep, PowerNow!), while the former
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * makes use of TSC and kernel timers.
319f8f820db4356edaff70c2e019376e1ec71487vboxsyncTMDECL(uint64_t) TMVirtualGetEx(PVM pVM, bool fCheckTimers);
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Gets the current lag of the synchronous virtual clock (relative to the virtual clock).
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @return The current lag.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Get the current catch-up percent.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @return The current catch0up percent. 0 means running at the same speed as the virtual clock.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsyncTMDECL(uint32_t) TMVirtualSyncGetCatchUpPct(PVM pVM);
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Gets the current TMCLOCK_VIRTUAL frequency.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns The freqency.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Gets the current TMCLOCK_VIRTUAL_SYNC time.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns The timestamp.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param fCheckTimers Check timers or not
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @thread EMT.
319f8f820db4356edaff70c2e019376e1ec71487vboxsyncTMDECL(uint64_t) TMVirtualSyncGetEx(PVM pVM, bool fCheckTimers);
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Gets the current TMCLOCK_VIRTUAL_SYNC time.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns The timestamp.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @thread EMT.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Resumes the virtual clock.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns VINF_SUCCESS on success.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns VINF_INTERNAL_ERROR and VBOX_STRICT assertion if called out of order.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Pauses the virtual clock.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns VINF_SUCCESS on success.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns VINF_INTERNAL_ERROR and VBOX_STRICT assertion if called out of order.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Converts from virtual ticks to nanoseconds.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns nanoseconds.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM The VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param u64VirtualTicks The virtual ticks to convert.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @remark There could be rounding errors here. We just do a simple integere divide
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * without any adjustments.
319f8f820db4356edaff70c2e019376e1ec71487vboxsyncTMDECL(uint64_t) TMVirtualToNano(PVM pVM, uint64_t u64VirtualTicks);
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Converts from virtual ticks to microseconds.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns microseconds.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM The VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param u64VirtualTicks The virtual ticks to convert.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @remark There could be rounding errors here. We just do a simple integere divide
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * without any adjustments.
319f8f820db4356edaff70c2e019376e1ec71487vboxsyncTMDECL(uint64_t) TMVirtualToMicro(PVM pVM, uint64_t u64VirtualTicks);
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * Converts from virtual ticks to milliseconds.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @returns milliseconds.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param pVM The VM handle.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @param u64VirtualTicks The virtual ticks to convert.
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * @remark There could be rounding errors here. We just do a simple integere divide
319f8f820db4356edaff70c2e019376e1ec71487vboxsync * without any adjustments.
319f8f820db4356edaff70c2e019376e1ec71487vboxsyncTMDECL(uint64_t) TMVirtualToMilli(PVM pVM, uint64_t u64VirtualTicks);
#ifdef IN_RING3
TMR3DECL(int) TMR3TimerCreateDevice(PVM pVM, PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer);
TMR3DECL(int) TMR3TimerCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer);
TMR3DECL(int) TMR3TimerCreateInternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMERINT pfnCallback, void *pvUser, const char *pszDesc, PPTMTIMERR3 ppTimer);
TMR3DECL(PTMTIMERR3) TMR3TimerCreateExternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMEREXT pfnCallback, void *pvUser, const char *pszDesc);
#ifdef IN_GC