1 | /** @file
|
---|
2 | * TM - Time Manager.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2019 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_INCLUDED_vmm_tm_h
|
---|
27 | #define VBOX_INCLUDED_vmm_tm_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <VBox/types.h>
|
---|
33 | #ifdef IN_RING3
|
---|
34 | # include <iprt/time.h>
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | RT_C_DECLS_BEGIN
|
---|
38 |
|
---|
39 | /** @defgroup grp_tm The Time Manager API
|
---|
40 | * @ingroup grp_vmm
|
---|
41 | * @{
|
---|
42 | */
|
---|
43 |
|
---|
44 | /** Enable a timer hack which improves the timer response/resolution a bit. */
|
---|
45 | #define VBOX_HIGH_RES_TIMERS_HACK
|
---|
46 |
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Clock type.
|
---|
50 | */
|
---|
51 | typedef enum TMCLOCK
|
---|
52 | {
|
---|
53 | /** Real host time.
|
---|
54 | * This clock ticks all the time, so use with care. */
|
---|
55 | TMCLOCK_REAL = 0,
|
---|
56 | /** Virtual guest time.
|
---|
57 | * This clock only ticks when the guest is running. It's implemented
|
---|
58 | * as an offset to monotonic real time (GIP). */
|
---|
59 | TMCLOCK_VIRTUAL,
|
---|
60 | /** Virtual guest synchronized timer time.
|
---|
61 | * This is a special clock and timer queue for synchronizing virtual timers
|
---|
62 | * and virtual time sources. This clock is trying to keep up with
|
---|
63 | * TMCLOCK_VIRTUAL, but will wait for timers to be executed. If it lags
|
---|
64 | * too far behind TMCLOCK_VIRTUAL, it will try speed up to close the
|
---|
65 | * distance.
|
---|
66 | * @remarks Do not use this unless you really *must*. */
|
---|
67 | TMCLOCK_VIRTUAL_SYNC,
|
---|
68 | /** Virtual CPU timestamp.
|
---|
69 | * By default this is a function of TMCLOCK_VIRTUAL_SYNC and the virtual
|
---|
70 | * CPU frequency. */
|
---|
71 | TMCLOCK_TSC,
|
---|
72 | /** Number of clocks. */
|
---|
73 | TMCLOCK_MAX
|
---|
74 | } TMCLOCK;
|
---|
75 |
|
---|
76 |
|
---|
77 | /** @defgroup grp_tm_timer_flags Timer flags.
|
---|
78 | * @{ */
|
---|
79 | /** Use the default critical section for the class of timers. */
|
---|
80 | #define TMTIMER_FLAGS_DEFAULT_CRIT_SECT 0
|
---|
81 | /** No critical section needed or a custom one is set using
|
---|
82 | * TMR3TimerSetCritSect(). */
|
---|
83 | #define TMTIMER_FLAGS_NO_CRIT_SECT RT_BIT_32(0)
|
---|
84 | /** @} */
|
---|
85 |
|
---|
86 |
|
---|
87 | VMMDECL(void) TMNotifyStartOfExecution(PVMCC pVM, PVMCPUCC pVCpu);
|
---|
88 | VMMDECL(void) TMNotifyEndOfExecution(PVMCC pVM, PVMCPUCC pVCpu);
|
---|
89 | VMM_INT_DECL(void) TMNotifyStartOfHalt(PVMCPUCC pVCpu);
|
---|
90 | VMM_INT_DECL(void) TMNotifyEndOfHalt(PVMCPUCC pVCpu);
|
---|
91 | #ifdef IN_RING3
|
---|
92 | VMMR3DECL(int) TMR3NotifySuspend(PVM pVM, PVMCPU pVCpu);
|
---|
93 | VMMR3DECL(int) TMR3NotifyResume(PVM pVM, PVMCPU pVCpu);
|
---|
94 | VMMR3DECL(int) TMR3SetWarpDrive(PUVM pUVM, uint32_t u32Percent);
|
---|
95 | VMMR3DECL(uint32_t) TMR3GetWarpDrive(PUVM pUVM);
|
---|
96 | #endif
|
---|
97 | VMM_INT_DECL(uint32_t) TMCalcHostTimerFrequency(PVMCC pVM, PVMCPUCC pVCpu);
|
---|
98 | #ifdef IN_RING3
|
---|
99 | VMMR3DECL(int) TMR3GetCpuLoadTimes(PVM pVM, VMCPUID idCpu, uint64_t *pcNsTotal, uint64_t *pcNsExecuting,
|
---|
100 | uint64_t *pcNsHalted, uint64_t *pcNsOther);
|
---|
101 | #endif
|
---|
102 | VMMR3DECL(int) TMR3GetCpuLoadPercents(PUVM pVUM, VMCPUID idCpu, uint64_t *pcMsInterval, uint8_t *pcPctExecuting,
|
---|
103 | uint8_t *pcPctHalted, uint8_t *pcPctOther);
|
---|
104 |
|
---|
105 |
|
---|
106 | /** @name Real Clock Methods
|
---|
107 | * @{
|
---|
108 | */
|
---|
109 | VMM_INT_DECL(uint64_t) TMRealGet(PVM pVM);
|
---|
110 | VMM_INT_DECL(uint64_t) TMRealGetFreq(PVM pVM);
|
---|
111 | /** @} */
|
---|
112 |
|
---|
113 |
|
---|
114 | /** @name Virtual Clock Methods
|
---|
115 | * @{
|
---|
116 | */
|
---|
117 | VMM_INT_DECL(uint64_t) TMVirtualGet(PVMCC pVM);
|
---|
118 | VMM_INT_DECL(uint64_t) TMVirtualGetNoCheck(PVMCC pVM);
|
---|
119 | VMM_INT_DECL(uint64_t) TMVirtualSyncGetLag(PVMCC pVM);
|
---|
120 | VMM_INT_DECL(uint32_t) TMVirtualSyncGetCatchUpPct(PVMCC pVM);
|
---|
121 | VMM_INT_DECL(uint64_t) TMVirtualGetFreq(PVM pVM);
|
---|
122 | VMM_INT_DECL(uint64_t) TMVirtualSyncGet(PVMCC pVM);
|
---|
123 | VMM_INT_DECL(uint64_t) TMVirtualSyncGetNoCheck(PVMCC pVM);
|
---|
124 | VMM_INT_DECL(uint64_t) TMVirtualSyncGetEx(PVMCC pVM, bool fCheckTimers);
|
---|
125 | VMM_INT_DECL(uint64_t) TMVirtualSyncGetWithDeadlineNoCheck(PVMCC pVM, uint64_t *pcNsToDeadline);
|
---|
126 | VMMDECL(uint64_t) TMVirtualSyncGetNsToDeadline(PVMCC pVM);
|
---|
127 | VMM_INT_DECL(uint64_t) TMVirtualToNano(PVM pVM, uint64_t u64VirtualTicks);
|
---|
128 | VMM_INT_DECL(uint64_t) TMVirtualToMicro(PVM pVM, uint64_t u64VirtualTicks);
|
---|
129 | VMM_INT_DECL(uint64_t) TMVirtualToMilli(PVM pVM, uint64_t u64VirtualTicks);
|
---|
130 | VMM_INT_DECL(uint64_t) TMVirtualFromNano(PVM pVM, uint64_t u64NanoTS);
|
---|
131 | VMM_INT_DECL(uint64_t) TMVirtualFromMicro(PVM pVM, uint64_t u64MicroTS);
|
---|
132 | VMM_INT_DECL(uint64_t) TMVirtualFromMilli(PVM pVM, uint64_t u64MilliTS);
|
---|
133 | VMM_INT_DECL(bool) TMVirtualIsTicking(PVM pVM);
|
---|
134 |
|
---|
135 | VMMR3DECL(uint64_t) TMR3TimeVirtGet(PUVM pUVM);
|
---|
136 | VMMR3DECL(uint64_t) TMR3TimeVirtGetMilli(PUVM pUVM);
|
---|
137 | VMMR3DECL(uint64_t) TMR3TimeVirtGetMicro(PUVM pUVM);
|
---|
138 | VMMR3DECL(uint64_t) TMR3TimeVirtGetNano(PUVM pUVM);
|
---|
139 | /** @} */
|
---|
140 |
|
---|
141 |
|
---|
142 | /** @name CPU Clock Methods
|
---|
143 | * @{
|
---|
144 | */
|
---|
145 | VMMDECL(uint64_t) TMCpuTickGet(PVMCPUCC pVCpu);
|
---|
146 | VMM_INT_DECL(uint64_t) TMCpuTickGetNoCheck(PVMCPUCC pVCpu);
|
---|
147 | VMM_INT_DECL(bool) TMCpuTickCanUseRealTSC(PVMCC pVM, PVMCPUCC pVCpu, uint64_t *poffRealTSC, bool *pfParavirtTsc);
|
---|
148 | VMM_INT_DECL(uint64_t) TMCpuTickGetDeadlineAndTscOffset(PVMCC pVM, PVMCPUCC pVCpu, uint64_t *poffRealTSC, bool *pfOffsettedTsc, bool *pfParavirtTsc);
|
---|
149 | VMM_INT_DECL(int) TMCpuTickSet(PVMCC pVM, PVMCPUCC pVCpu, uint64_t u64Tick);
|
---|
150 | VMM_INT_DECL(int) TMCpuTickSetLastSeen(PVMCPUCC pVCpu, uint64_t u64LastSeenTick);
|
---|
151 | VMM_INT_DECL(uint64_t) TMCpuTickGetLastSeen(PVMCPUCC pVCpu);
|
---|
152 | VMMDECL(uint64_t) TMCpuTicksPerSecond(PVMCC pVM);
|
---|
153 | VMM_INT_DECL(bool) TMCpuTickIsTicking(PVMCPUCC pVCpu);
|
---|
154 | /** @} */
|
---|
155 |
|
---|
156 |
|
---|
157 | /** @name Timer Methods
|
---|
158 | * @{
|
---|
159 | */
|
---|
160 | /**
|
---|
161 | * Device timer callback function.
|
---|
162 | *
|
---|
163 | * @param pDevIns 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) FNTMTIMERDEV(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser);
|
---|
168 | /** Pointer to a device timer callback function. */
|
---|
169 | typedef FNTMTIMERDEV *PFNTMTIMERDEV;
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * USB device timer callback function.
|
---|
173 | *
|
---|
174 | * @param pUsbIns The USB device instance the timer is associated
|
---|
175 | * with.
|
---|
176 | * @param pTimer The timer handle.
|
---|
177 | * @param pvUser User argument specified upon timer creation.
|
---|
178 | */
|
---|
179 | typedef DECLCALLBACK(void) FNTMTIMERUSB(PPDMUSBINS pUsbIns, PTMTIMER pTimer, void *pvUser);
|
---|
180 | /** Pointer to a timer callback for a USB device. */
|
---|
181 | typedef FNTMTIMERUSB *PFNTMTIMERUSB;
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * Driver timer callback function.
|
---|
185 | *
|
---|
186 | * @param pDrvIns Device instance of the device which registered the timer.
|
---|
187 | * @param pTimer The timer handle.
|
---|
188 | * @param pvUser User argument specified upon timer creation.
|
---|
189 | */
|
---|
190 | typedef DECLCALLBACK(void) FNTMTIMERDRV(PPDMDRVINS pDrvIns, PTMTIMER pTimer, void *pvUser);
|
---|
191 | /** Pointer to a driver timer callback function. */
|
---|
192 | typedef FNTMTIMERDRV *PFNTMTIMERDRV;
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Service timer callback function.
|
---|
196 | *
|
---|
197 | * @param pSrvIns Service instance of the device which registered the timer.
|
---|
198 | * @param pTimer The timer handle.
|
---|
199 | */
|
---|
200 | typedef DECLCALLBACK(void) FNTMTIMERSRV(PPDMSRVINS pSrvIns, PTMTIMER pTimer);
|
---|
201 | /** Pointer to a service timer callback function. */
|
---|
202 | typedef FNTMTIMERSRV *PFNTMTIMERSRV;
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * Internal timer callback function.
|
---|
206 | *
|
---|
207 | * @param pVM The cross context VM structure.
|
---|
208 | * @param pTimer The timer handle.
|
---|
209 | * @param pvUser User argument specified upon timer creation.
|
---|
210 | */
|
---|
211 | typedef DECLCALLBACK(void) FNTMTIMERINT(PVM pVM, PTMTIMER pTimer, void *pvUser);
|
---|
212 | /** Pointer to internal timer callback function. */
|
---|
213 | typedef FNTMTIMERINT *PFNTMTIMERINT;
|
---|
214 |
|
---|
215 | /**
|
---|
216 | * External timer callback function.
|
---|
217 | *
|
---|
218 | * @param pvUser User argument as specified when the timer was created.
|
---|
219 | */
|
---|
220 | typedef DECLCALLBACK(void) FNTMTIMEREXT(void *pvUser);
|
---|
221 | /** Pointer to an external timer callback function. */
|
---|
222 | typedef FNTMTIMEREXT *PFNTMTIMEREXT;
|
---|
223 |
|
---|
224 | VMMDECL(PTMTIMERR3) TMTimerR3Ptr(PTMTIMER pTimer);
|
---|
225 | VMMDECL(PTMTIMERR0) TMTimerR0Ptr(PTMTIMER pTimer);
|
---|
226 | VMMDECL(PTMTIMERRC) TMTimerRCPtr(PTMTIMER pTimer);
|
---|
227 | VMMDECL(int) TMTimerLock(PTMTIMER pTimer, int rcBusy);
|
---|
228 | VMMDECL(void) TMTimerUnlock(PTMTIMER pTimer);
|
---|
229 | VMMDECL(bool) TMTimerIsLockOwner(PTMTIMER pTimer);
|
---|
230 | VMMDECL(int) TMTimerSet(PTMTIMER pTimer, uint64_t u64Expire);
|
---|
231 | VMMDECL(int) TMTimerSetRelative(PTMTIMER pTimer, uint64_t cTicksToNext, uint64_t *pu64Now);
|
---|
232 | VMMDECL(int) TMTimerSetFrequencyHint(PTMTIMER pTimer, uint32_t uHz);
|
---|
233 | VMMDECL(uint64_t) TMTimerGet(PTMTIMER pTimer);
|
---|
234 | VMMDECL(int) TMTimerStop(PTMTIMER pTimer);
|
---|
235 | VMMDECL(bool) TMTimerIsActive(PTMTIMER pTimer);
|
---|
236 |
|
---|
237 | VMMDECL(int) TMTimerSetMillies(PTMTIMER pTimer, uint32_t cMilliesToNext);
|
---|
238 | VMMDECL(int) TMTimerSetMicro(PTMTIMER pTimer, uint64_t cMicrosToNext);
|
---|
239 | VMMDECL(int) TMTimerSetNano(PTMTIMER pTimer, uint64_t cNanosToNext);
|
---|
240 | VMMDECL(uint64_t) TMTimerGetNano(PTMTIMER pTimer);
|
---|
241 | VMMDECL(uint64_t) TMTimerGetMicro(PTMTIMER pTimer);
|
---|
242 | VMMDECL(uint64_t) TMTimerGetMilli(PTMTIMER pTimer);
|
---|
243 | VMMDECL(uint64_t) TMTimerGetFreq(PTMTIMER pTimer);
|
---|
244 | VMMDECL(uint64_t) TMTimerGetExpire(PTMTIMER pTimer);
|
---|
245 | VMMDECL(uint64_t) TMTimerToNano(PTMTIMER pTimer, uint64_t cTicks);
|
---|
246 | VMMDECL(uint64_t) TMTimerToMicro(PTMTIMER pTimer, uint64_t cTicks);
|
---|
247 | VMMDECL(uint64_t) TMTimerToMilli(PTMTIMER pTimer, uint64_t cTicks);
|
---|
248 | VMMDECL(uint64_t) TMTimerFromNano(PTMTIMER pTimer, uint64_t cNanoSecs);
|
---|
249 | VMMDECL(uint64_t) TMTimerFromMicro(PTMTIMER pTimer, uint64_t cMicroSecs);
|
---|
250 | VMMDECL(uint64_t) TMTimerFromMilli(PTMTIMER pTimer, uint64_t cMilliSecs);
|
---|
251 |
|
---|
252 | VMMDECL(bool) TMTimerPollBool(PVMCC pVM, PVMCPUCC pVCpu);
|
---|
253 | VMM_INT_DECL(void) TMTimerPollVoid(PVMCC pVM, PVMCPUCC pVCpu);
|
---|
254 | VMM_INT_DECL(uint64_t) TMTimerPollGIP(PVMCC pVM, PVMCPUCC pVCpu, uint64_t *pu64Delta);
|
---|
255 | /** @} */
|
---|
256 |
|
---|
257 |
|
---|
258 | #ifdef IN_RING3
|
---|
259 | /** @defgroup grp_tm_r3 The TM Host Context Ring-3 API
|
---|
260 | * @{
|
---|
261 | */
|
---|
262 | VMM_INT_DECL(int) TMR3Init(PVM pVM);
|
---|
263 | VMM_INT_DECL(int) TMR3InitFinalize(PVM pVM);
|
---|
264 | VMM_INT_DECL(void) TMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
|
---|
265 | VMM_INT_DECL(int) TMR3Term(PVM pVM);
|
---|
266 | VMM_INT_DECL(void) TMR3Reset(PVM pVM);
|
---|
267 | VMM_INT_DECL(int) TMR3GetImportRC(PVM pVM, const char *pszSymbol, PRTRCPTR pRCPtrValue);
|
---|
268 | VMM_INT_DECL(int) TMR3TimerCreateDevice(PVM pVM, PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
269 | VMM_INT_DECL(int) TMR3TimerCreateUsb(PVM pVM, PPDMUSBINS pUsbIns, TMCLOCK enmClock, PFNTMTIMERUSB pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
270 | VMM_INT_DECL(int) TMR3TimerCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
271 | VMMR3DECL(int) TMR3TimerCreateInternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMERINT pfnCallback, void *pvUser, const char *pszDesc, PPTMTIMERR3 ppTimer);
|
---|
272 | VMMR3DECL(PTMTIMERR3) TMR3TimerCreateExternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMEREXT pfnCallback, void *pvUser, const char *pszDesc);
|
---|
273 | VMMR3DECL(int) TMR3TimerDestroy(PTMTIMER pTimer);
|
---|
274 | VMM_INT_DECL(int) TMR3TimerDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
|
---|
275 | VMM_INT_DECL(int) TMR3TimerDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
|
---|
276 | VMM_INT_DECL(int) TMR3TimerDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
|
---|
277 | VMMR3DECL(int) TMR3TimerSave(PTMTIMERR3 pTimer, PSSMHANDLE pSSM);
|
---|
278 | VMMR3DECL(int) TMR3TimerLoad(PTMTIMERR3 pTimer, PSSMHANDLE pSSM);
|
---|
279 | VMMR3DECL(int) TMR3TimerSkip(PSSMHANDLE pSSM, bool *pfActive);
|
---|
280 | VMMR3DECL(int) TMR3TimerSetCritSect(PTMTIMERR3 pTimer, PPDMCRITSECT pCritSect);
|
---|
281 | VMMR3DECL(void) TMR3TimerQueuesDo(PVM pVM);
|
---|
282 | VMMR3_INT_DECL(void) TMR3VirtualSyncFF(PVM pVM, PVMCPU pVCpu);
|
---|
283 | VMMR3_INT_DECL(PRTTIMESPEC) TMR3UtcNow(PVM pVM, PRTTIMESPEC pTime);
|
---|
284 |
|
---|
285 | VMMR3_INT_DECL(int) TMR3CpuTickParavirtEnable(PVM pVM);
|
---|
286 | VMMR3_INT_DECL(int) TMR3CpuTickParavirtDisable(PVM pVM);
|
---|
287 | VMMR3_INT_DECL(bool) TMR3CpuTickIsFixedRateMonotonic(PVM pVM, bool fWithParavirtEnabled);
|
---|
288 | /** @} */
|
---|
289 | #endif /* IN_RING3 */
|
---|
290 |
|
---|
291 |
|
---|
292 | /** @} */
|
---|
293 |
|
---|
294 | RT_C_DECLS_END
|
---|
295 |
|
---|
296 | #endif /* !VBOX_INCLUDED_vmm_tm_h */
|
---|
297 |
|
---|