1 | /** @file
|
---|
2 | * TM - Time Monitor.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 |
|
---|
26 | #ifndef ___VBox_tm_h
|
---|
27 | #define ___VBox_tm_h
|
---|
28 |
|
---|
29 | #include <VBox/cdefs.h>
|
---|
30 | #include <VBox/types.h>
|
---|
31 | #ifdef IN_RING3
|
---|
32 | # include <iprt/time.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | __BEGIN_DECLS
|
---|
36 |
|
---|
37 | /** @defgroup grp_tm The Time Monitor API
|
---|
38 | * @{
|
---|
39 | */
|
---|
40 |
|
---|
41 | /** Enable a timer hack which improves the timer response/resolution a bit. */
|
---|
42 | #define VBOX_HIGH_RES_TIMERS_HACK
|
---|
43 |
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Clock type.
|
---|
47 | */
|
---|
48 | typedef enum TMCLOCK
|
---|
49 | {
|
---|
50 | /** Real host time.
|
---|
51 | * This clock ticks all the time, so use with care. */
|
---|
52 | TMCLOCK_REAL = 0,
|
---|
53 | /** Virtual guest time.
|
---|
54 | * This clock only ticks when the guest is running. It's implemented
|
---|
55 | * as an offset to real time. */
|
---|
56 | TMCLOCK_VIRTUAL,
|
---|
57 | /** Virtual guest synchronized timer time.
|
---|
58 | * This is a special clock and timer queue for synchronizing virtual timers and
|
---|
59 | * virtual time sources. This clock is trying to keep up with TMCLOCK_VIRTUAL,
|
---|
60 | * but will wait for timers to be executed. If it lags too far behind TMCLOCK_VIRTUAL,
|
---|
61 | * it will try speed up to close the distance. */
|
---|
62 | TMCLOCK_VIRTUAL_SYNC,
|
---|
63 | /** Virtual CPU timestamp. (Running only when we're executing guest code.) */
|
---|
64 | TMCLOCK_TSC,
|
---|
65 | /** Number of clocks. */
|
---|
66 | TMCLOCK_MAX
|
---|
67 | } TMCLOCK;
|
---|
68 |
|
---|
69 |
|
---|
70 | /** @name Real Clock Methods
|
---|
71 | * @{
|
---|
72 | */
|
---|
73 | TMDECL(uint64_t) TMRealGet(PVM pVM);
|
---|
74 | TMDECL(uint64_t) TMRealGetFreq(PVM pVM);
|
---|
75 | /** @} */
|
---|
76 |
|
---|
77 |
|
---|
78 | /** @name Virtual Clock Methods
|
---|
79 | * @{
|
---|
80 | */
|
---|
81 | TMDECL(uint64_t) TMVirtualGet(PVM pVM);
|
---|
82 | TMDECL(uint64_t) TMVirtualGetEx(PVM pVM, bool fCheckTimers);
|
---|
83 | TMDECL(uint64_t) TMVirtualSyncGetLag(PVM pVM);
|
---|
84 | TMDECL(uint32_t) TMVirtualSyncGetCatchUpPct(PVM pVM);
|
---|
85 | TMDECL(uint64_t) TMVirtualGetFreq(PVM pVM);
|
---|
86 | TMDECL(uint64_t) TMVirtualSyncGetEx(PVM pVM, bool fCheckTimers);
|
---|
87 | TMDECL(uint64_t) TMVirtualSyncGet(PVM pVM);
|
---|
88 | TMDECL(int) TMVirtualResume(PVM pVM);
|
---|
89 | TMDECL(int) TMVirtualPause(PVM pVM);
|
---|
90 | TMDECL(uint64_t) TMVirtualToNano(PVM pVM, uint64_t u64VirtualTicks);
|
---|
91 | TMDECL(uint64_t) TMVirtualToMicro(PVM pVM, uint64_t u64VirtualTicks);
|
---|
92 | TMDECL(uint64_t) TMVirtualToMilli(PVM pVM, uint64_t u64VirtualTicks);
|
---|
93 | TMDECL(uint64_t) TMVirtualFromNano(PVM pVM, uint64_t u64NanoTS);
|
---|
94 | TMDECL(uint64_t) TMVirtualFromMicro(PVM pVM, uint64_t u64MicroTS);
|
---|
95 | TMDECL(uint64_t) TMVirtualFromMilli(PVM pVM, uint64_t u64MilliTS);
|
---|
96 | TMDECL(uint32_t) TMVirtualGetWarpDrive(PVM pVM);
|
---|
97 | TMDECL(int) TMVirtualSetWarpDrive(PVM pVM, uint32_t u32Percent);
|
---|
98 | /** @} */
|
---|
99 |
|
---|
100 |
|
---|
101 | /** @name CPU Clock Methods
|
---|
102 | * @{
|
---|
103 | */
|
---|
104 | TMDECL(int) TMCpuTickResume(PVM pVM);
|
---|
105 | TMDECL(int) TMCpuTickPause(PVM pVM);
|
---|
106 | TMDECL(uint64_t) TMCpuTickGet(PVM pVM);
|
---|
107 | TMDECL(bool) TMCpuTickCanUseRealTSC(PVM pVM, uint64_t *poffRealTSC);
|
---|
108 | TMDECL(int) TMCpuTickSet(PVM pVM, uint64_t u64Tick);
|
---|
109 | TMDECL(uint64_t) TMCpuTicksPerSecond(PVM pVM);
|
---|
110 | /** @} */
|
---|
111 |
|
---|
112 |
|
---|
113 | /** @name Timer Methods
|
---|
114 | * @{
|
---|
115 | */
|
---|
116 | /**
|
---|
117 | * Device timer callback function.
|
---|
118 | *
|
---|
119 | * @param pDevIns Device instance of the device which registered the timer.
|
---|
120 | * @param pTimer The timer handle.
|
---|
121 | */
|
---|
122 | typedef DECLCALLBACK(void) FNTMTIMERDEV(PPDMDEVINS pDevIns, PTMTIMER pTimer);
|
---|
123 | /** Pointer to a device timer callback function. */
|
---|
124 | typedef FNTMTIMERDEV *PFNTMTIMERDEV;
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Driver timer callback function.
|
---|
128 | *
|
---|
129 | * @param pDrvIns Device instance of the device which registered the timer.
|
---|
130 | * @param pTimer The timer handle.
|
---|
131 | */
|
---|
132 | typedef DECLCALLBACK(void) FNTMTIMERDRV(PPDMDRVINS pDrvIns, PTMTIMER pTimer);
|
---|
133 | /** Pointer to a driver timer callback function. */
|
---|
134 | typedef FNTMTIMERDRV *PFNTMTIMERDRV;
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Service timer callback function.
|
---|
138 | *
|
---|
139 | * @param pSrvIns Service instance of the device which registered the timer.
|
---|
140 | * @param pTimer The timer handle.
|
---|
141 | */
|
---|
142 | typedef DECLCALLBACK(void) FNTMTIMERSRV(PPDMSRVINS pSrvIns, PTMTIMER pTimer);
|
---|
143 | /** Pointer to a service timer callback function. */
|
---|
144 | typedef FNTMTIMERSRV *PFNTMTIMERSRV;
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Internal timer callback function.
|
---|
148 | *
|
---|
149 | * @param pVM The VM.
|
---|
150 | * @param pTimer The timer handle.
|
---|
151 | * @param pvUser User argument specified upon timer creation.
|
---|
152 | */
|
---|
153 | typedef DECLCALLBACK(void) FNTMTIMERINT(PVM pVM, PTMTIMER pTimer, void *pvUser);
|
---|
154 | /** Pointer to internal timer callback function. */
|
---|
155 | typedef FNTMTIMERINT *PFNTMTIMERINT;
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * External timer callback function.
|
---|
159 | *
|
---|
160 | * @param pvUser User argument as specified when the timer was created.
|
---|
161 | */
|
---|
162 | typedef DECLCALLBACK(void) FNTMTIMEREXT(void *pvUser);
|
---|
163 | /** Pointer to an external timer callback function. */
|
---|
164 | typedef FNTMTIMEREXT *PFNTMTIMEREXT;
|
---|
165 |
|
---|
166 | TMDECL(PTMTIMERR3) TMTimerR3Ptr(PTMTIMER pTimer);
|
---|
167 | TMDECL(PTMTIMERR0) TMTimerR0Ptr(PTMTIMER pTimer);
|
---|
168 | TMDECL(PTMTIMERGC) TMTimerGCPtr(PTMTIMER pTimer);
|
---|
169 | TMDECL(int) TMTimerDestroy(PTMTIMER pTimer);
|
---|
170 | TMDECL(int) TMTimerSet(PTMTIMER pTimer, uint64_t u64Expire);
|
---|
171 | TMDECL(int) TMTimerSetMillies(PTMTIMER pTimer, uint32_t cMilliesToNext);
|
---|
172 | TMDECL(int) TMTimerSetMicro(PTMTIMER pTimer, uint64_t cMicrosToNext);
|
---|
173 | TMDECL(int) TMTimerSetNano(PTMTIMER pTimer, uint64_t cNanosToNext);
|
---|
174 | TMDECL(uint64_t) TMTimerGet(PTMTIMER pTimer);
|
---|
175 | TMDECL(uint64_t) TMTimerGetNano(PTMTIMER pTimer);
|
---|
176 | TMDECL(uint64_t) TMTimerGetMicro(PTMTIMER pTimer);
|
---|
177 | TMDECL(uint64_t) TMTimerGetMilli(PTMTIMER pTimer);
|
---|
178 | TMDECL(uint64_t) TMTimerGetFreq(PTMTIMER pTimer);
|
---|
179 | TMDECL(uint64_t) TMTimerGetExpire(PTMTIMER pTimer);
|
---|
180 | TMDECL(uint64_t) TMTimerToNano(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
181 | TMDECL(uint64_t) TMTimerToMicro(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
182 | TMDECL(uint64_t) TMTimerToMilli(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
183 | TMDECL(uint64_t) TMTimerFromNano(PTMTIMER pTimer, uint64_t u64NanoTS);
|
---|
184 | TMDECL(uint64_t) TMTimerFromMicro(PTMTIMER pTimer, uint64_t u64MicroTS);
|
---|
185 | TMDECL(uint64_t) TMTimerFromMilli(PTMTIMER pTimer, uint64_t u64MilliTS);
|
---|
186 | TMDECL(int) TMTimerStop(PTMTIMER pTimer);
|
---|
187 | TMDECL(bool) TMTimerIsActive(PTMTIMER pTimer);
|
---|
188 | TMDECL(uint64_t) TMTimerPoll(PVM pVM);
|
---|
189 | TMDECL(uint64_t) TMTimerPollGIP(PVM pVM, uint64_t *pu64Delta);
|
---|
190 |
|
---|
191 | /** @} */
|
---|
192 |
|
---|
193 |
|
---|
194 | #ifdef IN_RING3
|
---|
195 | /** @defgroup grp_tm_r3 The TM Host Context Ring-3 API
|
---|
196 | * @ingroup grp_tm
|
---|
197 | * @{
|
---|
198 | */
|
---|
199 | TMR3DECL(int) TMR3Init(PVM pVM);
|
---|
200 | TMR3DECL(int) TMR3InitFinalize(PVM pVM);
|
---|
201 | TMR3DECL(void) TMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
|
---|
202 | TMR3DECL(int) TMR3Term(PVM pVM);
|
---|
203 | TMR3DECL(void) TMR3Reset(PVM pVM);
|
---|
204 | TMR3DECL(int) TMR3GetImportGC(PVM pVM, const char *pszSymbol, PRTGCPTR pGCPtrValue);
|
---|
205 | TMR3DECL(int) TMR3TimerCreateDevice(PVM pVM, PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
206 | TMR3DECL(int) TMR3TimerCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
207 | TMR3DECL(int) TMR3TimerCreateInternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMERINT pfnCallback, void *pvUser, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
208 | TMR3DECL(PTMTIMERR3) TMR3TimerCreateExternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMEREXT pfnCallback, void *pvUser, const char *pszDesc);
|
---|
209 | TMR3DECL(int) TMR3TimerDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
|
---|
210 | TMR3DECL(int) TMR3TimerDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
|
---|
211 | TMR3DECL(int) TMR3TimerSave(PTMTIMERR3 pTimer, PSSMHANDLE pSSM);
|
---|
212 | TMR3DECL(int) TMR3TimerLoad(PTMTIMERR3 pTimer, PSSMHANDLE pSSM);
|
---|
213 | TMR3DECL(void) TMR3TimerQueuesDo(PVM pVM);
|
---|
214 | TMR3DECL(PRTTIMESPEC) TMR3UTCNow(PVM pVM, PRTTIMESPEC pTime);
|
---|
215 | /** @} */
|
---|
216 | #endif /* IN_RING3 */
|
---|
217 |
|
---|
218 |
|
---|
219 | /** @} */
|
---|
220 |
|
---|
221 | __END_DECLS
|
---|
222 |
|
---|
223 | #endif
|
---|
224 |
|
---|