VirtualBox

source: vbox/trunk/include/VBox/vmm/tm.h@ 93593

Last change on this file since 93593 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.9 KB
Line 
1/** @file
2 * TM - Time Manager.
3 */
4
5/*
6 * Copyright (C) 2006-2022 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
37RT_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 */
51typedef 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/** Used in ring-0. Must set this or TMTIMER_FLAGS_NO_RING0. */
85#define TMTIMER_FLAGS_RING0 RT_BIT_32(1)
86/** Not used in ring-0 (for refactoring and doc purposes). */
87#define TMTIMER_FLAGS_NO_RING0 RT_BIT_32(31)
88/** @} */
89
90
91VMMDECL(void) TMNotifyStartOfExecution(PVMCC pVM, PVMCPUCC pVCpu);
92VMMDECL(void) TMNotifyEndOfExecution(PVMCC pVM, PVMCPUCC pVCpu, uint64_t uTsc);
93VMM_INT_DECL(void) TMNotifyStartOfHalt(PVMCPUCC pVCpu);
94VMM_INT_DECL(void) TMNotifyEndOfHalt(PVMCPUCC pVCpu);
95#ifdef IN_RING3
96VMMR3DECL(int) TMR3NotifySuspend(PVM pVM, PVMCPU pVCpu);
97VMMR3DECL(int) TMR3NotifyResume(PVM pVM, PVMCPU pVCpu);
98VMMR3DECL(int) TMR3SetWarpDrive(PUVM pUVM, uint32_t u32Percent);
99VMMR3DECL(uint32_t) TMR3GetWarpDrive(PUVM pUVM);
100#endif
101VMM_INT_DECL(uint32_t) TMCalcHostTimerFrequency(PVMCC pVM, PVMCPUCC pVCpu);
102#ifdef IN_RING3
103VMMR3DECL(int) TMR3GetCpuLoadTimes(PVM pVM, VMCPUID idCpu, uint64_t *pcNsTotal, uint64_t *pcNsExecuting,
104 uint64_t *pcNsHalted, uint64_t *pcNsOther);
105VMMR3DECL(int) TMR3GetCpuLoadPercents(PUVM pVUM, VMCPUID idCpu, uint64_t *pcMsInterval, uint8_t *pcPctExecuting,
106 uint8_t *pcPctHalted, uint8_t *pcPctOther);
107#endif
108
109
110/** @name Real Clock Methods
111 * @{
112 */
113VMM_INT_DECL(uint64_t) TMRealGet(PVM pVM);
114VMM_INT_DECL(uint64_t) TMRealGetFreq(PVM pVM);
115/** @} */
116
117
118/** @name Virtual Clock Methods
119 * @{
120 */
121VMM_INT_DECL(uint64_t) TMVirtualGet(PVMCC pVM);
122VMM_INT_DECL(uint64_t) TMVirtualGetNoCheck(PVMCC pVM);
123VMM_INT_DECL(uint64_t) TMVirtualSyncGetLag(PVMCC pVM);
124VMM_INT_DECL(uint32_t) TMVirtualSyncGetCatchUpPct(PVMCC pVM);
125VMM_INT_DECL(uint64_t) TMVirtualGetFreq(PVM pVM);
126VMM_INT_DECL(uint64_t) TMVirtualSyncGet(PVMCC pVM);
127VMM_INT_DECL(uint64_t) TMVirtualSyncGetNoCheck(PVMCC pVM);
128VMM_INT_DECL(uint64_t) TMVirtualSyncGetNoCheckWithTsc(PVMCC pVM, uint64_t *puTscNow);
129VMM_INT_DECL(uint64_t) TMVirtualSyncGetEx(PVMCC pVM, bool fCheckTimers);
130VMM_INT_DECL(uint64_t) TMVirtualSyncGetWithDeadlineNoCheck(PVMCC pVM, uint64_t *pcNsToDeadline,
131 uint64_t *puDeadlineVersion, uint64_t *puTscNow);
132VMMDECL(uint64_t) TMVirtualSyncGetNsToDeadline(PVMCC pVM, uint64_t *puDeadlineVersion, uint64_t *puTscNow);
133VMM_INT_DECL(bool) TMVirtualSyncIsCurrentDeadlineVersion(PVMCC pVM, uint64_t uDeadlineVersion);
134VMM_INT_DECL(uint64_t) TMVirtualToNano(PVM pVM, uint64_t u64VirtualTicks);
135VMM_INT_DECL(uint64_t) TMVirtualToMicro(PVM pVM, uint64_t u64VirtualTicks);
136VMM_INT_DECL(uint64_t) TMVirtualToMilli(PVM pVM, uint64_t u64VirtualTicks);
137VMM_INT_DECL(uint64_t) TMVirtualFromNano(PVM pVM, uint64_t u64NanoTS);
138VMM_INT_DECL(uint64_t) TMVirtualFromMicro(PVM pVM, uint64_t u64MicroTS);
139VMM_INT_DECL(uint64_t) TMVirtualFromMilli(PVM pVM, uint64_t u64MilliTS);
140VMM_INT_DECL(bool) TMVirtualIsTicking(PVM pVM);
141
142VMMR3DECL(uint64_t) TMR3TimeVirtGet(PUVM pUVM);
143VMMR3DECL(uint64_t) TMR3TimeVirtGetMilli(PUVM pUVM);
144VMMR3DECL(uint64_t) TMR3TimeVirtGetMicro(PUVM pUVM);
145VMMR3DECL(uint64_t) TMR3TimeVirtGetNano(PUVM pUVM);
146/** @} */
147
148
149/** @name CPU Clock Methods
150 * @{
151 */
152VMMDECL(uint64_t) TMCpuTickGet(PVMCPUCC pVCpu);
153VMM_INT_DECL(uint64_t) TMCpuTickGetNoCheck(PVMCPUCC pVCpu);
154VMM_INT_DECL(bool) TMCpuTickCanUseRealTSC(PVMCC pVM, PVMCPUCC pVCpu, uint64_t *poffRealTSC, bool *pfParavirtTsc);
155VMM_INT_DECL(uint64_t) TMCpuTickGetDeadlineAndTscOffset(PVMCC pVM, PVMCPUCC pVCpu, uint64_t *poffRealTsc,
156 bool *pfOffsettedTsc, bool *pfParavirtTsc,
157 uint64_t *puTscNow, uint64_t *puDeadlineVersion);
158VMM_INT_DECL(int) TMCpuTickSet(PVMCC pVM, PVMCPUCC pVCpu, uint64_t u64Tick);
159VMM_INT_DECL(int) TMCpuTickSetLastSeen(PVMCPUCC pVCpu, uint64_t u64LastSeenTick);
160VMM_INT_DECL(uint64_t) TMCpuTickGetLastSeen(PVMCPUCC pVCpu);
161VMMDECL(uint64_t) TMCpuTicksPerSecond(PVMCC pVM);
162VMM_INT_DECL(bool) TMCpuTickIsTicking(PVMCPUCC pVCpu);
163/** @} */
164
165
166/** @name Timer Methods
167 * @{
168 */
169/**
170 * Device timer callback function.
171 *
172 * @param pDevIns Device instance of the device which registered the timer.
173 * @param hTimer The timer handle.
174 * @param pvUser User argument specified upon timer creation.
175 */
176typedef DECLCALLBACKTYPE(void, FNTMTIMERDEV,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, void *pvUser));
177/** Pointer to a device timer callback function. */
178typedef FNTMTIMERDEV *PFNTMTIMERDEV;
179
180/**
181 * USB device timer callback function.
182 *
183 * @param pUsbIns The USB device instance the timer is associated
184 * with.
185 * @param hTimer The timer handle.
186 * @param pvUser User argument specified upon timer creation.
187 */
188typedef DECLCALLBACKTYPE(void, FNTMTIMERUSB,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, void *pvUser));
189/** Pointer to a timer callback for a USB device. */
190typedef FNTMTIMERUSB *PFNTMTIMERUSB;
191
192/**
193 * Driver timer callback function.
194 *
195 * @param pDrvIns Device instance of the device which registered the timer.
196 * @param hTimer The timer handle.
197 * @param pvUser User argument specified upon timer creation.
198 */
199typedef DECLCALLBACKTYPE(void, FNTMTIMERDRV,(PPDMDRVINS pDrvIns, TMTIMERHANDLE hTimer, void *pvUser));
200/** Pointer to a driver timer callback function. */
201typedef FNTMTIMERDRV *PFNTMTIMERDRV;
202
203/**
204 * Service timer callback function.
205 *
206 * @param pSrvIns Service instance of the device which registered the timer.
207 * @param hTimer The timer handle.
208 */
209typedef DECLCALLBACKTYPE(void, FNTMTIMERSRV,(PPDMSRVINS pSrvIns, TMTIMERHANDLE hTimer));
210/** Pointer to a service timer callback function. */
211typedef FNTMTIMERSRV *PFNTMTIMERSRV;
212
213/**
214 * Internal timer callback function.
215 *
216 * @param pVM The cross context VM structure.
217 * @param hTimer The timer handle.
218 * @param pvUser User argument specified upon timer creation.
219 */
220typedef DECLCALLBACKTYPE(void, FNTMTIMERINT,(PVM pVM, TMTIMERHANDLE hTimer, void *pvUser));
221/** Pointer to internal timer callback function. */
222typedef FNTMTIMERINT *PFNTMTIMERINT;
223
224/**
225 * External timer callback function.
226 *
227 * @param pvUser User argument as specified when the timer was created.
228 */
229typedef DECLCALLBACKTYPE(void, FNTMTIMEREXT,(void *pvUser));
230/** Pointer to an external timer callback function. */
231typedef FNTMTIMEREXT *PFNTMTIMEREXT;
232
233VMMDECL(int) TMTimerLock(PVMCC pVM, TMTIMERHANDLE hTimer, int rcBusy);
234VMMDECL(void) TMTimerUnlock(PVMCC pVM, TMTIMERHANDLE hTimer);
235VMMDECL(bool) TMTimerIsLockOwner(PVMCC pVM, TMTIMERHANDLE hTimer);
236VMMDECL(int) TMTimerSet(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t u64Expire);
237VMMDECL(int) TMTimerSetRelative(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicksToNext, uint64_t *pu64Now);
238VMMDECL(int) TMTimerSetFrequencyHint(PVMCC pVM, TMTIMERHANDLE hTimer, uint32_t uHz);
239VMMDECL(uint64_t) TMTimerGet(PVMCC pVM, TMTIMERHANDLE hTimer);
240VMMDECL(int) TMTimerStop(PVMCC pVM, TMTIMERHANDLE hTimer);
241VMMDECL(bool) TMTimerIsActive(PVMCC pVM, TMTIMERHANDLE hTimer);
242
243VMMDECL(int) TMTimerSetMillies(PVMCC pVM, TMTIMERHANDLE hTimer, uint32_t cMilliesToNext);
244VMMDECL(int) TMTimerSetMicro(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cMicrosToNext);
245VMMDECL(int) TMTimerSetNano(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cNanosToNext);
246VMMDECL(uint64_t) TMTimerGetNano(PVMCC pVM, TMTIMERHANDLE hTimer);
247VMMDECL(uint64_t) TMTimerGetMicro(PVMCC pVM, TMTIMERHANDLE hTimer);
248VMMDECL(uint64_t) TMTimerGetMilli(PVMCC pVM, TMTIMERHANDLE hTimer);
249VMMDECL(uint64_t) TMTimerGetFreq(PVMCC pVM, TMTIMERHANDLE hTimer);
250VMMDECL(uint64_t) TMTimerGetExpire(PVMCC pVM, TMTIMERHANDLE hTimer);
251VMMDECL(uint64_t) TMTimerToNano(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicks);
252VMMDECL(uint64_t) TMTimerToMicro(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicks);
253VMMDECL(uint64_t) TMTimerToMilli(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicks);
254VMMDECL(uint64_t) TMTimerFromNano(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cNanoSecs);
255VMMDECL(uint64_t) TMTimerFromMicro(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cMicroSecs);
256VMMDECL(uint64_t) TMTimerFromMilli(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cMilliSecs);
257
258VMMDECL(bool) TMTimerPollBool(PVMCC pVM, PVMCPUCC pVCpu);
259VMM_INT_DECL(void) TMTimerPollVoid(PVMCC pVM, PVMCPUCC pVCpu);
260VMM_INT_DECL(uint64_t) TMTimerPollGIP(PVMCC pVM, PVMCPUCC pVCpu, uint64_t *pu64Delta);
261/** @} */
262
263
264/** @defgroup grp_tm_r3 The TM Host Context Ring-3 API
265 * @{
266 */
267VMM_INT_DECL(int) TMR3Init(PVM pVM);
268VMM_INT_DECL(int) TMR3InitFinalize(PVM pVM);
269VMM_INT_DECL(void) TMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
270VMM_INT_DECL(int) TMR3Term(PVM pVM);
271VMM_INT_DECL(void) TMR3Reset(PVM pVM);
272VMM_INT_DECL(int) TMR3TimerCreateDevice(PVM pVM, PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback,
273 void *pvUser, uint32_t fFlags, const char *pszName, PTMTIMERHANDLE phTimer);
274VMM_INT_DECL(int) TMR3TimerCreateUsb(PVM pVM, PPDMUSBINS pUsbIns, TMCLOCK enmClock, PFNTMTIMERUSB pfnCallback,
275 void *pvUser, uint32_t fFlags, const char *pszName, PTMTIMERHANDLE phTimer);
276VMM_INT_DECL(int) TMR3TimerCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback,
277 void *pvUser, uint32_t fFlags, const char *pszName, PTMTIMERHANDLE phTimer);
278VMMR3DECL(int) TMR3TimerCreate(PVM pVM, TMCLOCK enmClock, PFNTMTIMERINT pfnCallback, void *pvUser, uint32_t fFlags,
279 const char *pszName, PTMTIMERHANDLE phTimer);
280VMMR3DECL(int) TMR3TimerDestroy(PVM pVM, TMTIMERHANDLE hTimer);
281VMM_INT_DECL(int) TMR3TimerDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
282VMM_INT_DECL(int) TMR3TimerDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
283VMM_INT_DECL(int) TMR3TimerDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
284VMMR3DECL(int) TMR3TimerSave(PVMCC pVM, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM);
285VMMR3DECL(int) TMR3TimerLoad(PVMCC pVM, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM);
286VMMR3DECL(int) TMR3TimerSkip(PSSMHANDLE pSSM, bool *pfActive);
287VMMR3DECL(int) TMR3TimerSetCritSect(PVMCC pVM, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect);
288VMMR3DECL(void) TMR3TimerQueuesDo(PVM pVM);
289VMMR3_INT_DECL(void) TMR3VirtualSyncFF(PVM pVM, PVMCPU pVCpu);
290VMMR3_INT_DECL(PRTTIMESPEC) TMR3UtcNow(PVM pVM, PRTTIMESPEC pTime);
291
292VMMR3_INT_DECL(int) TMR3CpuTickParavirtEnable(PVM pVM);
293VMMR3_INT_DECL(int) TMR3CpuTickParavirtDisable(PVM pVM);
294VMMR3_INT_DECL(bool) TMR3CpuTickIsFixedRateMonotonic(PVM pVM, bool fWithParavirtEnabled);
295/** @} */
296
297
298/** @defgroup grp_tm_r0 The TM Host Context Ring-0 API
299 * @{
300 */
301VMMR0_INT_DECL(void) TMR0InitPerVMData(PGVM pGVM);
302VMMR0_INT_DECL(void) TMR0CleanupVM(PGVM pGVM);
303VMMR0_INT_DECL(int) TMR0TimerQueueGrow(PGVM pGVM, uint32_t idxQueue, uint32_t cMinTimers);
304/** @} */
305
306
307/** @} */
308
309RT_C_DECLS_END
310
311#endif /* !VBOX_INCLUDED_vmm_tm_h */
312
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