1 | /** @file
|
---|
2 | * TM - Time Manager. (VMM)
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
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 | RT_C_DECLS_BEGIN
|
---|
36 |
|
---|
37 | /** @defgroup grp_tm The Time Manager 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 | * @remarks Do not use this unless you *must*. */
|
---|
63 | TMCLOCK_VIRTUAL_SYNC,
|
---|
64 | /** Virtual CPU timestamp. (Running only when we're executing guest code.) */
|
---|
65 | TMCLOCK_TSC,
|
---|
66 | /** Number of clocks. */
|
---|
67 | TMCLOCK_MAX
|
---|
68 | } TMCLOCK;
|
---|
69 |
|
---|
70 |
|
---|
71 | /** @defgroup grp_tm_timer_flags Timer flags.
|
---|
72 | * @{ */
|
---|
73 | /** Use the default critical section for the class of timers. */
|
---|
74 | #define TMTIMER_FLAGS_DEFAULT_CRIT_SECT 0
|
---|
75 | /** No critical section needed or a custom one is set using
|
---|
76 | * TMR3TimerSetCritSect(). */
|
---|
77 | #define TMTIMER_FLAGS_NO_CRIT_SECT RT_BIT_32(0)
|
---|
78 | /** @} */
|
---|
79 |
|
---|
80 |
|
---|
81 | VMMDECL(void) TMNotifyStartOfExecution(PVMCPU pVCpu);
|
---|
82 | VMMDECL(void) TMNotifyEndOfExecution(PVMCPU pVCpu);
|
---|
83 | VMM_INT_DECL(void) TMNotifyStartOfHalt(PVMCPU pVCpu);
|
---|
84 | VMM_INT_DECL(void) TMNotifyEndOfHalt(PVMCPU pVCpu);
|
---|
85 | #ifdef IN_RING3
|
---|
86 | VMMR3DECL(int) TMR3NotifySuspend(PVM pVM, PVMCPU pVCpu);
|
---|
87 | VMMR3DECL(int) TMR3NotifyResume(PVM pVM, PVMCPU pVCpu);
|
---|
88 | VMMR3DECL(int) TMR3SetWarpDrive(PVM pVM, uint32_t u32Percent);
|
---|
89 | #endif
|
---|
90 | VMMDECL(uint32_t) TMGetWarpDrive(PVM pVM);
|
---|
91 |
|
---|
92 |
|
---|
93 | /** @name Real Clock Methods
|
---|
94 | * @{
|
---|
95 | */
|
---|
96 | VMM_INT_DECL(uint64_t) TMRealGet(PVM pVM);
|
---|
97 | VMM_INT_DECL(uint64_t) TMRealGetFreq(PVM pVM);
|
---|
98 | /** @} */
|
---|
99 |
|
---|
100 |
|
---|
101 | /** @name Virtual Clock Methods
|
---|
102 | * @{
|
---|
103 | */
|
---|
104 | VMM_INT_DECL(uint64_t) TMVirtualGet(PVM pVM);
|
---|
105 | VMM_INT_DECL(uint64_t) TMVirtualGetNoCheck(PVM pVM);
|
---|
106 | VMM_INT_DECL(uint64_t) TMVirtualSyncGetLag(PVM pVM);
|
---|
107 | VMM_INT_DECL(uint32_t) TMVirtualSyncGetCatchUpPct(PVM pVM);
|
---|
108 | VMM_INT_DECL(uint64_t) TMVirtualGetFreq(PVM pVM);
|
---|
109 | VMM_INT_DECL(uint64_t) TMVirtualSyncGet(PVM pVM);
|
---|
110 | VMM_INT_DECL(uint64_t) TMVirtualSyncGetNoCheck(PVM pVM);
|
---|
111 | VMM_INT_DECL(uint64_t) TMVirtualSyncGetEx(PVM pVM, bool fCheckTimers);
|
---|
112 | VMM_INT_DECL(uint64_t) TMVirtualToNano(PVM pVM, uint64_t u64VirtualTicks);
|
---|
113 | VMM_INT_DECL(uint64_t) TMVirtualToMicro(PVM pVM, uint64_t u64VirtualTicks);
|
---|
114 | VMM_INT_DECL(uint64_t) TMVirtualToMilli(PVM pVM, uint64_t u64VirtualTicks);
|
---|
115 | VMM_INT_DECL(uint64_t) TMVirtualFromNano(PVM pVM, uint64_t u64NanoTS);
|
---|
116 | VMM_INT_DECL(uint64_t) TMVirtualFromMicro(PVM pVM, uint64_t u64MicroTS);
|
---|
117 | VMM_INT_DECL(uint64_t) TMVirtualFromMilli(PVM pVM, uint64_t u64MilliTS);
|
---|
118 | /** @} */
|
---|
119 |
|
---|
120 |
|
---|
121 | /** @name CPU Clock Methods
|
---|
122 | * @{
|
---|
123 | */
|
---|
124 | VMMDECL(uint64_t) TMCpuTickGet(PVMCPU pVCpu);
|
---|
125 | VMM_INT_DECL(uint64_t) TMCpuTickGetNoCheck(PVMCPU pVCpu);
|
---|
126 | VMM_INT_DECL(bool) TMCpuTickCanUseRealTSC(PVMCPU pVCpu, uint64_t *poffRealTSC);
|
---|
127 | VMM_INT_DECL(int) TMCpuTickSet(PVM pVM, PVMCPU pVCpu, uint64_t u64Tick);
|
---|
128 | VMM_INT_DECL(int) TMCpuTickSetLastSeen(PVMCPU pVCpu, uint64_t u64LastSeenTick);
|
---|
129 | VMM_INT_DECL(uint64_t) TMCpuTickGetLastSeen(PVMCPU pVCpu);
|
---|
130 | VMMDECL(uint64_t) TMCpuTicksPerSecond(PVM pVM);
|
---|
131 | /** @} */
|
---|
132 |
|
---|
133 |
|
---|
134 | /** @name Timer Methods
|
---|
135 | * @{
|
---|
136 | */
|
---|
137 | /**
|
---|
138 | * Device timer callback function.
|
---|
139 | *
|
---|
140 | * @param pDevIns Device instance of the device which registered the timer.
|
---|
141 | * @param pTimer The timer handle.
|
---|
142 | * @param pvUser User argument specified upon timer creation.
|
---|
143 | */
|
---|
144 | typedef DECLCALLBACK(void) FNTMTIMERDEV(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser);
|
---|
145 | /** Pointer to a device timer callback function. */
|
---|
146 | typedef FNTMTIMERDEV *PFNTMTIMERDEV;
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Device timer callback function.
|
---|
150 | *
|
---|
151 | * @param pUsbIns The USB device instance the timer is associated
|
---|
152 | * with.
|
---|
153 | * @param pTimer The timer handle.
|
---|
154 | * @param pvUser User argument specified upon timer creation.
|
---|
155 | */
|
---|
156 | typedef DECLCALLBACK(void) FNTMTIMERUSB(PPDMUSBINS pUsbIns, PTMTIMER pTimer, void *pvUser);
|
---|
157 | /** Pointer to a timer callback for a USB device. */
|
---|
158 | typedef FNTMTIMERUSB *PFNTMTIMERUSB;
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Driver timer callback function.
|
---|
162 | *
|
---|
163 | * @param pDrvIns Device instance of the device which registered the timer.
|
---|
164 | * @param pTimer The timer handle.
|
---|
165 | * @param pvUser User argument specified upon timer creation.
|
---|
166 | */
|
---|
167 | typedef DECLCALLBACK(void) FNTMTIMERDRV(PPDMDRVINS pDrvIns, PTMTIMER pTimer, void *pvUser);
|
---|
168 | /** Pointer to a driver timer callback function. */
|
---|
169 | typedef FNTMTIMERDRV *PFNTMTIMERDRV;
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * Service timer callback function.
|
---|
173 | *
|
---|
174 | * @param pSrvIns Service instance of the device which registered the timer.
|
---|
175 | * @param pTimer The timer handle.
|
---|
176 | */
|
---|
177 | typedef DECLCALLBACK(void) FNTMTIMERSRV(PPDMSRVINS pSrvIns, PTMTIMER pTimer);
|
---|
178 | /** Pointer to a service timer callback function. */
|
---|
179 | typedef FNTMTIMERSRV *PFNTMTIMERSRV;
|
---|
180 |
|
---|
181 | /**
|
---|
182 | * Internal timer callback function.
|
---|
183 | *
|
---|
184 | * @param pVM The VM.
|
---|
185 | * @param pTimer The timer handle.
|
---|
186 | * @param pvUser User argument specified upon timer creation.
|
---|
187 | */
|
---|
188 | typedef DECLCALLBACK(void) FNTMTIMERINT(PVM pVM, PTMTIMER pTimer, void *pvUser);
|
---|
189 | /** Pointer to internal timer callback function. */
|
---|
190 | typedef FNTMTIMERINT *PFNTMTIMERINT;
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * External timer callback function.
|
---|
194 | *
|
---|
195 | * @param pvUser User argument as specified when the timer was created.
|
---|
196 | */
|
---|
197 | typedef DECLCALLBACK(void) FNTMTIMEREXT(void *pvUser);
|
---|
198 | /** Pointer to an external timer callback function. */
|
---|
199 | typedef FNTMTIMEREXT *PFNTMTIMEREXT;
|
---|
200 |
|
---|
201 | VMMDECL(PTMTIMERR3) TMTimerR3Ptr(PTMTIMER pTimer);
|
---|
202 | VMMDECL(PTMTIMERR0) TMTimerR0Ptr(PTMTIMER pTimer);
|
---|
203 | VMMDECL(PTMTIMERRC) TMTimerRCPtr(PTMTIMER pTimer);
|
---|
204 | VMMDECL(int) TMTimerSet(PTMTIMER pTimer, uint64_t u64Expire);
|
---|
205 | VMMDECL(int) TMTimerSetRelative(PTMTIMER pTimer, uint64_t cTicksToNext, uint64_t *pu64Now);
|
---|
206 | VMMDECL(int) TMTimerSetMillies(PTMTIMER pTimer, uint32_t cMilliesToNext);
|
---|
207 | VMMDECL(int) TMTimerSetMicro(PTMTIMER pTimer, uint64_t cMicrosToNext);
|
---|
208 | VMMDECL(int) TMTimerSetNano(PTMTIMER pTimer, uint64_t cNanosToNext);
|
---|
209 | VMMDECL(uint64_t) TMTimerGet(PTMTIMER pTimer);
|
---|
210 | VMMDECL(uint64_t) TMTimerGetNano(PTMTIMER pTimer);
|
---|
211 | VMMDECL(uint64_t) TMTimerGetMicro(PTMTIMER pTimer);
|
---|
212 | VMMDECL(uint64_t) TMTimerGetMilli(PTMTIMER pTimer);
|
---|
213 | VMMDECL(uint64_t) TMTimerGetFreq(PTMTIMER pTimer);
|
---|
214 | VMMDECL(uint64_t) TMTimerGetExpire(PTMTIMER pTimer);
|
---|
215 | VMMDECL(uint64_t) TMTimerToNano(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
216 | VMMDECL(uint64_t) TMTimerToMicro(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
217 | VMMDECL(uint64_t) TMTimerToMilli(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
218 | VMMDECL(uint64_t) TMTimerFromNano(PTMTIMER pTimer, uint64_t u64NanoTS);
|
---|
219 | VMMDECL(uint64_t) TMTimerFromMicro(PTMTIMER pTimer, uint64_t u64MicroTS);
|
---|
220 | VMMDECL(uint64_t) TMTimerFromMilli(PTMTIMER pTimer, uint64_t u64MilliTS);
|
---|
221 | VMMDECL(int) TMTimerStop(PTMTIMER pTimer);
|
---|
222 | VMMDECL(bool) TMTimerIsActive(PTMTIMER pTimer);
|
---|
223 | VMMDECL(bool) TMTimerPollBool(PVM pVM, PVMCPU pVCpu);
|
---|
224 | VMM_INT_DECL(void) TMTimerPollVoid(PVM pVM, PVMCPU pVCpu);
|
---|
225 | VMM_INT_DECL(uint64_t) TMTimerPollGIP(PVM pVM, PVMCPU pVCpu, uint64_t *pu64Delta);
|
---|
226 |
|
---|
227 | /** @} */
|
---|
228 |
|
---|
229 |
|
---|
230 | #ifdef IN_RING3
|
---|
231 | /** @defgroup grp_tm_r3 The TM Host Context Ring-3 API
|
---|
232 | * @ingroup grp_tm
|
---|
233 | * @{
|
---|
234 | */
|
---|
235 | VMM_INT_DECL(int) TMR3Init(PVM pVM);
|
---|
236 | VMM_INT_DECL(int) TMR3InitCPU(PVM pVM);
|
---|
237 | VMM_INT_DECL(int) TMR3InitFinalize(PVM pVM);
|
---|
238 | VMM_INT_DECL(void) TMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
|
---|
239 | VMM_INT_DECL(int) TMR3Term(PVM pVM);
|
---|
240 | VMM_INT_DECL(int) TMR3TermCPU(PVM pVM);
|
---|
241 | VMM_INT_DECL(void) TMR3Reset(PVM pVM);
|
---|
242 | VMM_INT_DECL(int) TMR3GetImportRC(PVM pVM, const char *pszSymbol, PRTRCPTR pRCPtrValue);
|
---|
243 | VMM_INT_DECL(int) TMR3TimerCreateDevice(PVM pVM, PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
244 | VMM_INT_DECL(int) TMR3TimerCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
245 | VMMR3DECL(int) TMR3TimerCreateInternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMERINT pfnCallback, void *pvUser, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
246 | VMMR3DECL(PTMTIMERR3) TMR3TimerCreateExternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMEREXT pfnCallback, void *pvUser, const char *pszDesc);
|
---|
247 | VMMR3DECL(int) TMR3TimerDestroy(PTMTIMER pTimer);
|
---|
248 | VMM_INT_DECL(int) TMR3TimerDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
|
---|
249 | VMM_INT_DECL(int) TMR3TimerDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
|
---|
250 | VMMR3DECL(int) TMR3TimerSave(PTMTIMERR3 pTimer, PSSMHANDLE pSSM);
|
---|
251 | VMMR3DECL(int) TMR3TimerLoad(PTMTIMERR3 pTimer, PSSMHANDLE pSSM);
|
---|
252 | VMMR3DECL(int) TMR3TimerSetCritSect(PTMTIMERR3 pTimer, PPDMCRITSECT pCritSect);
|
---|
253 | VMMR3DECL(void) TMR3TimerQueuesDo(PVM pVM);
|
---|
254 | VMM_INT_DECL(void) TMR3VirtualSyncFF(PVM pVM, PVMCPU pVCpu);
|
---|
255 | VMM_INT_DECL(PRTTIMESPEC) TMR3UtcNow(PVM pVM, PRTTIMESPEC pTime);
|
---|
256 | /** @} */
|
---|
257 | #endif /* IN_RING3 */
|
---|
258 |
|
---|
259 |
|
---|
260 | /** @} */
|
---|
261 |
|
---|
262 | RT_C_DECLS_END
|
---|
263 |
|
---|
264 | #endif
|
---|
265 |
|
---|