1 | /** @file
|
---|
2 | * TM - Time Monitor.
|
---|
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 Monitor 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 | */
|
---|
52 | typedef 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 |
|
---|
75 | /** @name Real Clock Methods
|
---|
76 | * @{
|
---|
77 | */
|
---|
78 | TMDECL(uint64_t) TMRealGet(PVM pVM);
|
---|
79 | TMDECL(uint64_t) TMRealGetFreq(PVM pVM);
|
---|
80 | /** @} */
|
---|
81 |
|
---|
82 |
|
---|
83 | /** @name Virtual Clock Methods
|
---|
84 | * @{
|
---|
85 | */
|
---|
86 | TMDECL(uint64_t) TMVirtualGet(PVM pVM);
|
---|
87 | TMDECL(uint64_t) TMVirtualGetEx(PVM pVM, bool fCheckTimers);
|
---|
88 | TMDECL(uint64_t) TMVirtualSyncGetLag(PVM pVM);
|
---|
89 | TMDECL(uint32_t) TMVirtualSyncGetCatchUpPct(PVM pVM);
|
---|
90 | TMDECL(uint64_t) TMVirtualGetFreq(PVM pVM);
|
---|
91 | TMDECL(uint64_t) TMVirtualSyncGetEx(PVM pVM, bool fCheckTimers);
|
---|
92 | TMDECL(uint64_t) TMVirtualSyncGet(PVM pVM);
|
---|
93 | TMDECL(int) TMVirtualResume(PVM pVM);
|
---|
94 | TMDECL(int) TMVirtualPause(PVM pVM);
|
---|
95 | TMDECL(uint64_t) TMVirtualToNano(PVM pVM, uint64_t u64VirtualTicks);
|
---|
96 | TMDECL(uint64_t) TMVirtualToMicro(PVM pVM, uint64_t u64VirtualTicks);
|
---|
97 | TMDECL(uint64_t) TMVirtualToMilli(PVM pVM, uint64_t u64VirtualTicks);
|
---|
98 | TMDECL(uint64_t) TMVirtualFromNano(PVM pVM, uint64_t u64NanoTS);
|
---|
99 | TMDECL(uint64_t) TMVirtualFromMicro(PVM pVM, uint64_t u64MicroTS);
|
---|
100 | TMDECL(uint64_t) TMVirtualFromMilli(PVM pVM, uint64_t u64MilliTS);
|
---|
101 | TMDECL(uint32_t) TMVirtualGetWarpDrive(PVM pVM);
|
---|
102 | TMDECL(int) TMVirtualSetWarpDrive(PVM pVM, uint32_t u32Percent);
|
---|
103 | /** @} */
|
---|
104 |
|
---|
105 |
|
---|
106 | /** @name CPU Clock Methods
|
---|
107 | * @{
|
---|
108 | */
|
---|
109 | TMDECL(int) TMCpuTickResume(PVM pVM);
|
---|
110 | TMDECL(int) TMCpuTickPause(PVM pVM);
|
---|
111 | TMDECL(uint64_t) TMCpuTickGet(PVM pVM);
|
---|
112 | TMDECL(bool) TMCpuTickCanUseRealTSC(PVM pVM, uint64_t *poffRealTSC);
|
---|
113 | TMDECL(int) TMCpuTickSet(PVM pVM, uint64_t u64Tick);
|
---|
114 | TMDECL(uint64_t) TMCpuTicksPerSecond(PVM pVM);
|
---|
115 | /** @} */
|
---|
116 |
|
---|
117 |
|
---|
118 | /** @name Timer Methods
|
---|
119 | * @{
|
---|
120 | */
|
---|
121 | /**
|
---|
122 | * Device timer callback function.
|
---|
123 | *
|
---|
124 | * @param pDevIns Device instance of the device which registered the timer.
|
---|
125 | * @param pTimer The timer handle.
|
---|
126 | */
|
---|
127 | typedef DECLCALLBACK(void) FNTMTIMERDEV(PPDMDEVINS pDevIns, PTMTIMER pTimer);
|
---|
128 | /** Pointer to a device timer callback function. */
|
---|
129 | typedef FNTMTIMERDEV *PFNTMTIMERDEV;
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Driver timer callback function.
|
---|
133 | *
|
---|
134 | * @param pDrvIns Device instance of the device which registered the timer.
|
---|
135 | * @param pTimer The timer handle.
|
---|
136 | */
|
---|
137 | typedef DECLCALLBACK(void) FNTMTIMERDRV(PPDMDRVINS pDrvIns, PTMTIMER pTimer);
|
---|
138 | /** Pointer to a driver timer callback function. */
|
---|
139 | typedef FNTMTIMERDRV *PFNTMTIMERDRV;
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Service timer callback function.
|
---|
143 | *
|
---|
144 | * @param pSrvIns Service instance of the device which registered the timer.
|
---|
145 | * @param pTimer The timer handle.
|
---|
146 | */
|
---|
147 | typedef DECLCALLBACK(void) FNTMTIMERSRV(PPDMSRVINS pSrvIns, PTMTIMER pTimer);
|
---|
148 | /** Pointer to a service timer callback function. */
|
---|
149 | typedef FNTMTIMERSRV *PFNTMTIMERSRV;
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Internal timer callback function.
|
---|
153 | *
|
---|
154 | * @param pVM The VM.
|
---|
155 | * @param pTimer The timer handle.
|
---|
156 | * @param pvUser User argument specified upon timer creation.
|
---|
157 | */
|
---|
158 | typedef DECLCALLBACK(void) FNTMTIMERINT(PVM pVM, PTMTIMER pTimer, void *pvUser);
|
---|
159 | /** Pointer to internal timer callback function. */
|
---|
160 | typedef FNTMTIMERINT *PFNTMTIMERINT;
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * External timer callback function.
|
---|
164 | *
|
---|
165 | * @param pvUser User argument as specified when the timer was created.
|
---|
166 | */
|
---|
167 | typedef DECLCALLBACK(void) FNTMTIMEREXT(void *pvUser);
|
---|
168 | /** Pointer to an external timer callback function. */
|
---|
169 | typedef FNTMTIMEREXT *PFNTMTIMEREXT;
|
---|
170 |
|
---|
171 | TMDECL(PTMTIMERR3) TMTimerR3Ptr(PTMTIMER pTimer);
|
---|
172 | TMDECL(PTMTIMERR0) TMTimerR0Ptr(PTMTIMER pTimer);
|
---|
173 | TMDECL(PTMTIMERGC) TMTimerGCPtr(PTMTIMER pTimer);
|
---|
174 | TMDECL(int) TMTimerDestroy(PTMTIMER pTimer);
|
---|
175 | TMDECL(int) TMTimerSet(PTMTIMER pTimer, uint64_t u64Expire);
|
---|
176 | TMDECL(int) TMTimerSetMillies(PTMTIMER pTimer, uint32_t cMilliesToNext);
|
---|
177 | TMDECL(int) TMTimerSetMicro(PTMTIMER pTimer, uint64_t cMicrosToNext);
|
---|
178 | TMDECL(int) TMTimerSetNano(PTMTIMER pTimer, uint64_t cNanosToNext);
|
---|
179 | TMDECL(uint64_t) TMTimerGet(PTMTIMER pTimer);
|
---|
180 | TMDECL(uint64_t) TMTimerGetNano(PTMTIMER pTimer);
|
---|
181 | TMDECL(uint64_t) TMTimerGetMicro(PTMTIMER pTimer);
|
---|
182 | TMDECL(uint64_t) TMTimerGetMilli(PTMTIMER pTimer);
|
---|
183 | TMDECL(uint64_t) TMTimerGetFreq(PTMTIMER pTimer);
|
---|
184 | TMDECL(uint64_t) TMTimerGetExpire(PTMTIMER pTimer);
|
---|
185 | TMDECL(uint64_t) TMTimerToNano(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
186 | TMDECL(uint64_t) TMTimerToMicro(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
187 | TMDECL(uint64_t) TMTimerToMilli(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
188 | TMDECL(uint64_t) TMTimerFromNano(PTMTIMER pTimer, uint64_t u64NanoTS);
|
---|
189 | TMDECL(uint64_t) TMTimerFromMicro(PTMTIMER pTimer, uint64_t u64MicroTS);
|
---|
190 | TMDECL(uint64_t) TMTimerFromMilli(PTMTIMER pTimer, uint64_t u64MilliTS);
|
---|
191 | TMDECL(int) TMTimerStop(PTMTIMER pTimer);
|
---|
192 | TMDECL(bool) TMTimerIsActive(PTMTIMER pTimer);
|
---|
193 | TMDECL(uint64_t) TMTimerPoll(PVM pVM);
|
---|
194 | TMDECL(uint64_t) TMTimerPollGIP(PVM pVM, uint64_t *pu64Delta);
|
---|
195 |
|
---|
196 | /** @} */
|
---|
197 |
|
---|
198 |
|
---|
199 | #ifdef IN_RING3
|
---|
200 | /** @defgroup grp_tm_r3 The TM Host Context Ring-3 API
|
---|
201 | * @ingroup grp_tm
|
---|
202 | * @{
|
---|
203 | */
|
---|
204 | TMR3DECL(int) TMR3Init(PVM pVM);
|
---|
205 | TMR3DECL(int) TMR3InitFinalize(PVM pVM);
|
---|
206 | TMR3DECL(void) TMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
|
---|
207 | TMR3DECL(int) TMR3Term(PVM pVM);
|
---|
208 | TMR3DECL(void) TMR3Reset(PVM pVM);
|
---|
209 | TMR3DECL(int) TMR3GetImportGC(PVM pVM, const char *pszSymbol, PRTGCPTR pGCPtrValue);
|
---|
210 | TMR3DECL(int) TMR3TimerCreateDevice(PVM pVM, PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
211 | TMR3DECL(int) TMR3TimerCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
212 | TMR3DECL(int) TMR3TimerCreateInternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMERINT pfnCallback, void *pvUser, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
213 | TMR3DECL(PTMTIMERR3) TMR3TimerCreateExternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMEREXT pfnCallback, void *pvUser, const char *pszDesc);
|
---|
214 | TMR3DECL(int) TMR3TimerDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
|
---|
215 | TMR3DECL(int) TMR3TimerDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
|
---|
216 | TMR3DECL(int) TMR3TimerSave(PTMTIMERR3 pTimer, PSSMHANDLE pSSM);
|
---|
217 | TMR3DECL(int) TMR3TimerLoad(PTMTIMERR3 pTimer, PSSMHANDLE pSSM);
|
---|
218 | TMR3DECL(void) TMR3TimerQueuesDo(PVM pVM);
|
---|
219 | TMR3DECL(PRTTIMESPEC) TMR3UTCNow(PVM pVM, PRTTIMESPEC pTime);
|
---|
220 | /** @} */
|
---|
221 | #endif /* IN_RING3 */
|
---|
222 |
|
---|
223 |
|
---|
224 | /** @} */
|
---|
225 |
|
---|
226 | __END_DECLS
|
---|
227 |
|
---|
228 | #endif
|
---|
229 |
|
---|