VirtualBox

source: vbox/trunk/include/VBox/tm.h@ 18322

Last change on this file since 18322 was 13778, checked in by vboxsync, 16 years ago

Per VCPU init/term.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 KB
Line 
1/** @file
2 * TM - Time Manager.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_tm_h
31#define ___VBox_tm_h
32
33#include <VBox/cdefs.h>
34#include <VBox/types.h>
35#ifdef IN_RING3
36# include <iprt/time.h>
37#endif
38
39__BEGIN_DECLS
40
41/** @defgroup grp_tm The Time Manager API
42 * @{
43 */
44
45/** Enable a timer hack which improves the timer response/resolution a bit. */
46#define VBOX_HIGH_RES_TIMERS_HACK
47
48
49/**
50 * Clock type.
51 */
52typedef enum TMCLOCK
53{
54 /** Real host time.
55 * This clock ticks all the time, so use with care. */
56 TMCLOCK_REAL = 0,
57 /** Virtual guest time.
58 * This clock only ticks when the guest is running. It's implemented
59 * as an offset to real time. */
60 TMCLOCK_VIRTUAL,
61 /** Virtual guest synchronized timer time.
62 * This is a special clock and timer queue for synchronizing virtual timers and
63 * virtual time sources. This clock is trying to keep up with TMCLOCK_VIRTUAL,
64 * but will wait for timers to be executed. If it lags too far behind TMCLOCK_VIRTUAL,
65 * it will try speed up to close the distance.
66 * @remarks Do not use this unless you *must*. */
67 TMCLOCK_VIRTUAL_SYNC,
68 /** Virtual CPU timestamp. (Running only when we're executing guest code.) */
69 TMCLOCK_TSC,
70 /** Number of clocks. */
71 TMCLOCK_MAX
72} TMCLOCK;
73
74
75VMMDECL(void) TMNotifyStartOfExecution(PVM pVM);
76VMMDECL(void) TMNotifyEndOfExecution(PVM pVM);
77VMMDECL(void) TMNotifyStartOfHalt(PVM pVM);
78VMMDECL(void) TMNotifyEndOfHalt(PVM pVM);
79
80
81/** @name Real Clock Methods
82 * @{
83 */
84VMMDECL(uint64_t) TMRealGet(PVM pVM);
85VMMDECL(uint64_t) TMRealGetFreq(PVM pVM);
86/** @} */
87
88
89/** @name Virtual Clock Methods
90 * @{
91 */
92VMMDECL(uint64_t) TMVirtualGet(PVM pVM);
93VMMDECL(uint64_t) TMVirtualGetEx(PVM pVM, bool fCheckTimers);
94VMMDECL(uint64_t) TMVirtualSyncGetLag(PVM pVM);
95VMMDECL(uint32_t) TMVirtualSyncGetCatchUpPct(PVM pVM);
96VMMDECL(uint64_t) TMVirtualGetFreq(PVM pVM);
97VMMDECL(uint64_t) TMVirtualSyncGetEx(PVM pVM, bool fCheckTimers);
98VMMDECL(uint64_t) TMVirtualSyncGet(PVM pVM);
99VMMDECL(int) TMVirtualResume(PVM pVM);
100VMMDECL(int) TMVirtualPause(PVM pVM);
101VMMDECL(uint64_t) TMVirtualToNano(PVM pVM, uint64_t u64VirtualTicks);
102VMMDECL(uint64_t) TMVirtualToMicro(PVM pVM, uint64_t u64VirtualTicks);
103VMMDECL(uint64_t) TMVirtualToMilli(PVM pVM, uint64_t u64VirtualTicks);
104VMMDECL(uint64_t) TMVirtualFromNano(PVM pVM, uint64_t u64NanoTS);
105VMMDECL(uint64_t) TMVirtualFromMicro(PVM pVM, uint64_t u64MicroTS);
106VMMDECL(uint64_t) TMVirtualFromMilli(PVM pVM, uint64_t u64MilliTS);
107VMMDECL(uint32_t) TMVirtualGetWarpDrive(PVM pVM);
108VMMDECL(int) TMVirtualSetWarpDrive(PVM pVM, uint32_t u32Percent);
109/** @} */
110
111
112/** @name CPU Clock Methods
113 * @{
114 */
115VMMDECL(int) TMCpuTickResume(PVM pVM);
116VMMDECL(int) TMCpuTickPause(PVM pVM);
117VMMDECL(uint64_t) TMCpuTickGet(PVM pVM);
118VMMDECL(bool) TMCpuTickCanUseRealTSC(PVM pVM, uint64_t *poffRealTSC);
119VMMDECL(int) TMCpuTickSet(PVM pVM, uint64_t u64Tick);
120VMMDECL(uint64_t) TMCpuTicksPerSecond(PVM pVM);
121/** @} */
122
123
124/** @name Timer Methods
125 * @{
126 */
127/**
128 * Device timer callback function.
129 *
130 * @param pDevIns Device instance of the device which registered the timer.
131 * @param pTimer The timer handle.
132 */
133typedef DECLCALLBACK(void) FNTMTIMERDEV(PPDMDEVINS pDevIns, PTMTIMER pTimer);
134/** Pointer to a device timer callback function. */
135typedef FNTMTIMERDEV *PFNTMTIMERDEV;
136
137/**
138 * Driver timer callback function.
139 *
140 * @param pDrvIns Device instance of the device which registered the timer.
141 * @param pTimer The timer handle.
142 */
143typedef DECLCALLBACK(void) FNTMTIMERDRV(PPDMDRVINS pDrvIns, PTMTIMER pTimer);
144/** Pointer to a driver timer callback function. */
145typedef FNTMTIMERDRV *PFNTMTIMERDRV;
146
147/**
148 * Service timer callback function.
149 *
150 * @param pSrvIns Service instance of the device which registered the timer.
151 * @param pTimer The timer handle.
152 */
153typedef DECLCALLBACK(void) FNTMTIMERSRV(PPDMSRVINS pSrvIns, PTMTIMER pTimer);
154/** Pointer to a service timer callback function. */
155typedef FNTMTIMERSRV *PFNTMTIMERSRV;
156
157/**
158 * Internal timer callback function.
159 *
160 * @param pVM The VM.
161 * @param pTimer The timer handle.
162 * @param pvUser User argument specified upon timer creation.
163 */
164typedef DECLCALLBACK(void) FNTMTIMERINT(PVM pVM, PTMTIMER pTimer, void *pvUser);
165/** Pointer to internal timer callback function. */
166typedef FNTMTIMERINT *PFNTMTIMERINT;
167
168/**
169 * External timer callback function.
170 *
171 * @param pvUser User argument as specified when the timer was created.
172 */
173typedef DECLCALLBACK(void) FNTMTIMEREXT(void *pvUser);
174/** Pointer to an external timer callback function. */
175typedef FNTMTIMEREXT *PFNTMTIMEREXT;
176
177VMMDECL(PTMTIMERR3) TMTimerR3Ptr(PTMTIMER pTimer);
178VMMDECL(PTMTIMERR0) TMTimerR0Ptr(PTMTIMER pTimer);
179VMMDECL(PTMTIMERRC) TMTimerRCPtr(PTMTIMER pTimer);
180VMMDECL(int) TMTimerDestroy(PTMTIMER pTimer);
181VMMDECL(int) TMTimerSet(PTMTIMER pTimer, uint64_t u64Expire);
182VMMDECL(int) TMTimerSetMillies(PTMTIMER pTimer, uint32_t cMilliesToNext);
183VMMDECL(int) TMTimerSetMicro(PTMTIMER pTimer, uint64_t cMicrosToNext);
184VMMDECL(int) TMTimerSetNano(PTMTIMER pTimer, uint64_t cNanosToNext);
185VMMDECL(uint64_t) TMTimerGet(PTMTIMER pTimer);
186VMMDECL(uint64_t) TMTimerGetNano(PTMTIMER pTimer);
187VMMDECL(uint64_t) TMTimerGetMicro(PTMTIMER pTimer);
188VMMDECL(uint64_t) TMTimerGetMilli(PTMTIMER pTimer);
189VMMDECL(uint64_t) TMTimerGetFreq(PTMTIMER pTimer);
190VMMDECL(uint64_t) TMTimerGetExpire(PTMTIMER pTimer);
191VMMDECL(uint64_t) TMTimerToNano(PTMTIMER pTimer, uint64_t u64Ticks);
192VMMDECL(uint64_t) TMTimerToMicro(PTMTIMER pTimer, uint64_t u64Ticks);
193VMMDECL(uint64_t) TMTimerToMilli(PTMTIMER pTimer, uint64_t u64Ticks);
194VMMDECL(uint64_t) TMTimerFromNano(PTMTIMER pTimer, uint64_t u64NanoTS);
195VMMDECL(uint64_t) TMTimerFromMicro(PTMTIMER pTimer, uint64_t u64MicroTS);
196VMMDECL(uint64_t) TMTimerFromMilli(PTMTIMER pTimer, uint64_t u64MilliTS);
197VMMDECL(int) TMTimerStop(PTMTIMER pTimer);
198VMMDECL(bool) TMTimerIsActive(PTMTIMER pTimer);
199VMMDECL(uint64_t) TMTimerPoll(PVM pVM);
200VMMDECL(uint64_t) TMTimerPollGIP(PVM pVM, uint64_t *pu64Delta);
201
202/** @} */
203
204
205#ifdef IN_RING3
206/** @defgroup grp_tm_r3 The TM Host Context Ring-3 API
207 * @ingroup grp_tm
208 * @{
209 */
210VMMR3DECL(int) TMR3Init(PVM pVM);
211VMMR3DECL(int) TMR3InitCPU(PVM pVM);
212VMMR3DECL(int) TMR3InitFinalize(PVM pVM);
213VMMR3DECL(void) TMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
214VMMR3DECL(int) TMR3Term(PVM pVM);
215VMMR3DECL(int) TMR3TermCPU(PVM pVM);
216VMMR3DECL(void) TMR3Reset(PVM pVM);
217VMMR3DECL(int) TMR3GetImportRC(PVM pVM, const char *pszSymbol, PRTRCPTR pRCPtrValue);
218VMMR3DECL(int) TMR3TimerCreateDevice(PVM pVM, PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer);
219VMMR3DECL(int) TMR3TimerCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer);
220VMMR3DECL(int) TMR3TimerCreateInternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMERINT pfnCallback, void *pvUser, const char *pszDesc, PPTMTIMERR3 ppTimer);
221VMMR3DECL(PTMTIMERR3) TMR3TimerCreateExternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMEREXT pfnCallback, void *pvUser, const char *pszDesc);
222VMMR3DECL(int) TMR3TimerDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
223VMMR3DECL(int) TMR3TimerDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
224VMMR3DECL(int) TMR3TimerSave(PTMTIMERR3 pTimer, PSSMHANDLE pSSM);
225VMMR3DECL(int) TMR3TimerLoad(PTMTIMERR3 pTimer, PSSMHANDLE pSSM);
226VMMR3DECL(void) TMR3TimerQueuesDo(PVM pVM);
227VMMR3DECL(PRTTIMESPEC) TMR3UTCNow(PVM pVM, PRTTIMESPEC pTime);
228/** @} */
229#endif /* IN_RING3 */
230
231
232/** @} */
233
234__END_DECLS
235
236#endif
237
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette