VirtualBox

source: vbox/trunk/include/VBox/tm.h@ 27084

Last change on this file since 27084 was 26944, checked in by vboxsync, 15 years ago

PDM,IOM,TM: Added an optional per-device critsect for avoiding the global IOM lock. Only port I/O and timer callbacks use it, cannot yet be used with MMIO callbacks (will assert and fail).

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