VirtualBox

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

Last change on this file since 76585 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

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