VirtualBox

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

Last change on this file since 56291 was 54845, checked in by vboxsync, 10 years ago

VMM/GIM,TM: paranoia assertions.

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