VirtualBox

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

Last change on this file since 97342 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
Line 
1/** @file
2 * TM - Time Manager.
3 */
4
5/*
6 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef VBOX_INCLUDED_vmm_tm_h
37#define VBOX_INCLUDED_vmm_tm_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <VBox/types.h>
43#ifdef IN_RING3
44# include <iprt/time.h>
45#endif
46
47RT_C_DECLS_BEGIN
48
49/** @defgroup grp_tm The Time Manager API
50 * @ingroup grp_vmm
51 * @{
52 */
53
54/** Enable a timer hack which improves the timer response/resolution a bit. */
55#define VBOX_HIGH_RES_TIMERS_HACK
56
57
58/**
59 * Clock type.
60 */
61typedef enum TMCLOCK
62{
63 /** Real host time.
64 * This clock ticks all the time, so use with care. */
65 TMCLOCK_REAL = 0,
66 /** Virtual guest time.
67 * This clock only ticks when the guest is running. It's implemented
68 * as an offset to monotonic real time (GIP). */
69 TMCLOCK_VIRTUAL,
70 /** Virtual guest synchronized timer time.
71 * This is a special clock and timer queue for synchronizing virtual timers
72 * and virtual time sources. This clock is trying to keep up with
73 * TMCLOCK_VIRTUAL, but will wait for timers to be executed. If it lags
74 * too far behind TMCLOCK_VIRTUAL, it will try speed up to close the
75 * distance.
76 * @remarks Do not use this unless you really *must*. */
77 TMCLOCK_VIRTUAL_SYNC,
78 /** Virtual CPU timestamp.
79 * By default this is a function of TMCLOCK_VIRTUAL_SYNC and the virtual
80 * CPU frequency. */
81 TMCLOCK_TSC,
82 /** Number of clocks. */
83 TMCLOCK_MAX
84} TMCLOCK;
85
86
87/** @defgroup grp_tm_timer_flags Timer flags.
88 * @{ */
89/** Use the default critical section for the class of timers. */
90#define TMTIMER_FLAGS_DEFAULT_CRIT_SECT 0
91/** No critical section needed or a custom one is set using
92 * TMR3TimerSetCritSect(). */
93#define TMTIMER_FLAGS_NO_CRIT_SECT RT_BIT_32(0)
94/** Used in ring-0. Must set this or TMTIMER_FLAGS_NO_RING0. */
95#define TMTIMER_FLAGS_RING0 RT_BIT_32(1)
96/** Not used in ring-0 (for refactoring and doc purposes). */
97#define TMTIMER_FLAGS_NO_RING0 RT_BIT_32(31)
98/** @} */
99
100
101VMMDECL(void) TMNotifyStartOfExecution(PVMCC pVM, PVMCPUCC pVCpu);
102VMMDECL(void) TMNotifyEndOfExecution(PVMCC pVM, PVMCPUCC pVCpu, uint64_t uTsc);
103VMM_INT_DECL(void) TMNotifyStartOfHalt(PVMCPUCC pVCpu);
104VMM_INT_DECL(void) TMNotifyEndOfHalt(PVMCPUCC pVCpu);
105#ifdef IN_RING3
106VMMR3DECL(int) TMR3NotifySuspend(PVM pVM, PVMCPU pVCpu);
107VMMR3DECL(int) TMR3NotifyResume(PVM pVM, PVMCPU pVCpu);
108VMMR3DECL(int) TMR3SetWarpDrive(PUVM pUVM, uint32_t u32Percent);
109VMMR3DECL(uint32_t) TMR3GetWarpDrive(PUVM pUVM);
110#endif
111VMM_INT_DECL(uint32_t) TMCalcHostTimerFrequency(PVMCC pVM, PVMCPUCC pVCpu);
112#ifdef IN_RING3
113VMMR3DECL(int) TMR3GetCpuLoadTimes(PVM pVM, VMCPUID idCpu, uint64_t *pcNsTotal, uint64_t *pcNsExecuting,
114 uint64_t *pcNsHalted, uint64_t *pcNsOther);
115VMMR3DECL(int) TMR3GetCpuLoadPercents(PUVM pVUM, VMCPUID idCpu, uint64_t *pcMsInterval, uint8_t *pcPctExecuting,
116 uint8_t *pcPctHalted, uint8_t *pcPctOther);
117#endif
118
119
120/** @name Real Clock Methods
121 * @{
122 */
123VMM_INT_DECL(uint64_t) TMRealGet(PVM pVM);
124VMM_INT_DECL(uint64_t) TMRealGetFreq(PVM pVM);
125/** @} */
126
127
128/** @name Virtual Clock Methods
129 * @{
130 */
131VMM_INT_DECL(uint64_t) TMVirtualGet(PVMCC pVM);
132VMM_INT_DECL(uint64_t) TMVirtualGetNoCheck(PVMCC pVM);
133VMM_INT_DECL(uint64_t) TMVirtualSyncGetLag(PVMCC pVM);
134VMM_INT_DECL(uint32_t) TMVirtualSyncGetCatchUpPct(PVMCC pVM);
135VMM_INT_DECL(uint64_t) TMVirtualGetFreq(PVM pVM);
136VMM_INT_DECL(uint64_t) TMVirtualSyncGet(PVMCC pVM);
137VMM_INT_DECL(uint64_t) TMVirtualSyncGetNoCheck(PVMCC pVM);
138VMM_INT_DECL(uint64_t) TMVirtualSyncGetNoCheckWithTsc(PVMCC pVM, uint64_t *puTscNow);
139VMM_INT_DECL(uint64_t) TMVirtualSyncGetEx(PVMCC pVM, bool fCheckTimers);
140VMM_INT_DECL(uint64_t) TMVirtualSyncGetWithDeadlineNoCheck(PVMCC pVM, uint64_t *pcNsToDeadline,
141 uint64_t *puDeadlineVersion, uint64_t *puTscNow);
142VMMDECL(uint64_t) TMVirtualSyncGetNsToDeadline(PVMCC pVM, uint64_t *puDeadlineVersion, uint64_t *puTscNow);
143VMM_INT_DECL(bool) TMVirtualSyncIsCurrentDeadlineVersion(PVMCC pVM, uint64_t uDeadlineVersion);
144VMM_INT_DECL(uint64_t) TMVirtualToNano(PVM pVM, uint64_t u64VirtualTicks);
145VMM_INT_DECL(uint64_t) TMVirtualToMicro(PVM pVM, uint64_t u64VirtualTicks);
146VMM_INT_DECL(uint64_t) TMVirtualToMilli(PVM pVM, uint64_t u64VirtualTicks);
147VMM_INT_DECL(uint64_t) TMVirtualFromNano(PVM pVM, uint64_t u64NanoTS);
148VMM_INT_DECL(uint64_t) TMVirtualFromMicro(PVM pVM, uint64_t u64MicroTS);
149VMM_INT_DECL(uint64_t) TMVirtualFromMilli(PVM pVM, uint64_t u64MilliTS);
150VMM_INT_DECL(bool) TMVirtualIsTicking(PVM pVM);
151
152VMMR3DECL(uint64_t) TMR3TimeVirtGet(PUVM pUVM);
153VMMR3DECL(uint64_t) TMR3TimeVirtGetMilli(PUVM pUVM);
154VMMR3DECL(uint64_t) TMR3TimeVirtGetMicro(PUVM pUVM);
155VMMR3DECL(uint64_t) TMR3TimeVirtGetNano(PUVM pUVM);
156/** @} */
157
158
159/** @name CPU Clock Methods
160 * @{
161 */
162VMMDECL(uint64_t) TMCpuTickGet(PVMCPUCC pVCpu);
163VMM_INT_DECL(uint64_t) TMCpuTickGetNoCheck(PVMCPUCC pVCpu);
164VMM_INT_DECL(bool) TMCpuTickCanUseRealTSC(PVMCC pVM, PVMCPUCC pVCpu, uint64_t *poffRealTSC, bool *pfParavirtTsc);
165VMM_INT_DECL(uint64_t) TMCpuTickGetDeadlineAndTscOffset(PVMCC pVM, PVMCPUCC pVCpu, uint64_t *poffRealTsc,
166 bool *pfOffsettedTsc, bool *pfParavirtTsc,
167 uint64_t *puTscNow, uint64_t *puDeadlineVersion);
168VMM_INT_DECL(int) TMCpuTickSet(PVMCC pVM, PVMCPUCC pVCpu, uint64_t u64Tick);
169VMM_INT_DECL(int) TMCpuTickSetLastSeen(PVMCPUCC pVCpu, uint64_t u64LastSeenTick);
170VMM_INT_DECL(uint64_t) TMCpuTickGetLastSeen(PVMCPUCC pVCpu);
171VMMDECL(uint64_t) TMCpuTicksPerSecond(PVMCC pVM);
172VMM_INT_DECL(bool) TMCpuTickIsTicking(PVMCPUCC pVCpu);
173/** @} */
174
175
176/** @name Timer Methods
177 * @{
178 */
179/**
180 * Device timer callback function.
181 *
182 * @param pDevIns Device instance of the device which registered the timer.
183 * @param hTimer The timer handle.
184 * @param pvUser User argument specified upon timer creation.
185 */
186typedef DECLCALLBACKTYPE(void, FNTMTIMERDEV,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, void *pvUser));
187/** Pointer to a device timer callback function. */
188typedef FNTMTIMERDEV *PFNTMTIMERDEV;
189
190/**
191 * USB device timer callback function.
192 *
193 * @param pUsbIns The USB device instance the timer is associated
194 * with.
195 * @param hTimer The timer handle.
196 * @param pvUser User argument specified upon timer creation.
197 */
198typedef DECLCALLBACKTYPE(void, FNTMTIMERUSB,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, void *pvUser));
199/** Pointer to a timer callback for a USB device. */
200typedef FNTMTIMERUSB *PFNTMTIMERUSB;
201
202/**
203 * Driver timer callback function.
204 *
205 * @param pDrvIns Device instance of the device which registered the timer.
206 * @param hTimer The timer handle.
207 * @param pvUser User argument specified upon timer creation.
208 */
209typedef DECLCALLBACKTYPE(void, FNTMTIMERDRV,(PPDMDRVINS pDrvIns, TMTIMERHANDLE hTimer, void *pvUser));
210/** Pointer to a driver timer callback function. */
211typedef FNTMTIMERDRV *PFNTMTIMERDRV;
212
213/**
214 * Service timer callback function.
215 *
216 * @param pSrvIns Service instance of the device which registered the timer.
217 * @param hTimer The timer handle.
218 */
219typedef DECLCALLBACKTYPE(void, FNTMTIMERSRV,(PPDMSRVINS pSrvIns, TMTIMERHANDLE hTimer));
220/** Pointer to a service timer callback function. */
221typedef FNTMTIMERSRV *PFNTMTIMERSRV;
222
223/**
224 * Internal timer callback function.
225 *
226 * @param pVM The cross context VM structure.
227 * @param hTimer The timer handle.
228 * @param pvUser User argument specified upon timer creation.
229 */
230typedef DECLCALLBACKTYPE(void, FNTMTIMERINT,(PVM pVM, TMTIMERHANDLE hTimer, void *pvUser));
231/** Pointer to internal timer callback function. */
232typedef FNTMTIMERINT *PFNTMTIMERINT;
233
234/**
235 * External timer callback function.
236 *
237 * @param pvUser User argument as specified when the timer was created.
238 */
239typedef DECLCALLBACKTYPE(void, FNTMTIMEREXT,(void *pvUser));
240/** Pointer to an external timer callback function. */
241typedef FNTMTIMEREXT *PFNTMTIMEREXT;
242
243VMMDECL(int) TMTimerLock(PVMCC pVM, TMTIMERHANDLE hTimer, int rcBusy);
244VMMDECL(void) TMTimerUnlock(PVMCC pVM, TMTIMERHANDLE hTimer);
245VMMDECL(bool) TMTimerIsLockOwner(PVMCC pVM, TMTIMERHANDLE hTimer);
246VMMDECL(int) TMTimerSet(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t u64Expire);
247VMMDECL(int) TMTimerSetRelative(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicksToNext, uint64_t *pu64Now);
248VMMDECL(int) TMTimerSetFrequencyHint(PVMCC pVM, TMTIMERHANDLE hTimer, uint32_t uHz);
249VMMDECL(uint64_t) TMTimerGet(PVMCC pVM, TMTIMERHANDLE hTimer);
250VMMDECL(int) TMTimerStop(PVMCC pVM, TMTIMERHANDLE hTimer);
251VMMDECL(bool) TMTimerIsActive(PVMCC pVM, TMTIMERHANDLE hTimer);
252
253VMMDECL(int) TMTimerSetMillies(PVMCC pVM, TMTIMERHANDLE hTimer, uint32_t cMilliesToNext);
254VMMDECL(int) TMTimerSetMicro(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cMicrosToNext);
255VMMDECL(int) TMTimerSetNano(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cNanosToNext);
256VMMDECL(uint64_t) TMTimerGetNano(PVMCC pVM, TMTIMERHANDLE hTimer);
257VMMDECL(uint64_t) TMTimerGetMicro(PVMCC pVM, TMTIMERHANDLE hTimer);
258VMMDECL(uint64_t) TMTimerGetMilli(PVMCC pVM, TMTIMERHANDLE hTimer);
259VMMDECL(uint64_t) TMTimerGetFreq(PVMCC pVM, TMTIMERHANDLE hTimer);
260VMMDECL(uint64_t) TMTimerGetExpire(PVMCC pVM, TMTIMERHANDLE hTimer);
261VMMDECL(uint64_t) TMTimerToNano(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicks);
262VMMDECL(uint64_t) TMTimerToMicro(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicks);
263VMMDECL(uint64_t) TMTimerToMilli(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cTicks);
264VMMDECL(uint64_t) TMTimerFromNano(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cNanoSecs);
265VMMDECL(uint64_t) TMTimerFromMicro(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cMicroSecs);
266VMMDECL(uint64_t) TMTimerFromMilli(PVMCC pVM, TMTIMERHANDLE hTimer, uint64_t cMilliSecs);
267
268VMMDECL(bool) TMTimerPollBool(PVMCC pVM, PVMCPUCC pVCpu);
269VMM_INT_DECL(void) TMTimerPollVoid(PVMCC pVM, PVMCPUCC pVCpu);
270VMM_INT_DECL(uint64_t) TMTimerPollGIP(PVMCC pVM, PVMCPUCC pVCpu, uint64_t *pu64Delta);
271/** @} */
272
273
274/** @defgroup grp_tm_r3 The TM Host Context Ring-3 API
275 * @{
276 */
277VMM_INT_DECL(int) TMR3Init(PVM pVM);
278VMM_INT_DECL(int) TMR3InitFinalize(PVM pVM);
279VMM_INT_DECL(void) TMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
280VMM_INT_DECL(int) TMR3Term(PVM pVM);
281VMM_INT_DECL(void) TMR3Reset(PVM pVM);
282VMM_INT_DECL(int) TMR3TimerCreateDevice(PVM pVM, PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback,
283 void *pvUser, uint32_t fFlags, const char *pszName, PTMTIMERHANDLE phTimer);
284VMM_INT_DECL(int) TMR3TimerCreateUsb(PVM pVM, PPDMUSBINS pUsbIns, TMCLOCK enmClock, PFNTMTIMERUSB pfnCallback,
285 void *pvUser, uint32_t fFlags, const char *pszName, PTMTIMERHANDLE phTimer);
286VMM_INT_DECL(int) TMR3TimerCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback,
287 void *pvUser, uint32_t fFlags, const char *pszName, PTMTIMERHANDLE phTimer);
288VMMR3DECL(int) TMR3TimerCreate(PVM pVM, TMCLOCK enmClock, PFNTMTIMERINT pfnCallback, void *pvUser, uint32_t fFlags,
289 const char *pszName, PTMTIMERHANDLE phTimer);
290VMMR3DECL(int) TMR3TimerDestroy(PVM pVM, TMTIMERHANDLE hTimer);
291VMM_INT_DECL(int) TMR3TimerDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
292VMM_INT_DECL(int) TMR3TimerDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
293VMM_INT_DECL(int) TMR3TimerDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
294VMMR3DECL(int) TMR3TimerSave(PVMCC pVM, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM);
295VMMR3DECL(int) TMR3TimerLoad(PVMCC pVM, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM);
296VMMR3DECL(int) TMR3TimerSkip(PSSMHANDLE pSSM, bool *pfActive);
297VMMR3DECL(int) TMR3TimerSetCritSect(PVMCC pVM, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect);
298VMMR3DECL(void) TMR3TimerQueuesDo(PVM pVM);
299VMMR3_INT_DECL(void) TMR3VirtualSyncFF(PVM pVM, PVMCPU pVCpu);
300VMMR3_INT_DECL(PRTTIMESPEC) TMR3UtcNow(PVM pVM, PRTTIMESPEC pTime);
301
302VMMR3_INT_DECL(int) TMR3CpuTickParavirtEnable(PVM pVM);
303VMMR3_INT_DECL(int) TMR3CpuTickParavirtDisable(PVM pVM);
304VMMR3_INT_DECL(bool) TMR3CpuTickIsFixedRateMonotonic(PVM pVM, bool fWithParavirtEnabled);
305/** @} */
306
307
308/** @defgroup grp_tm_r0 The TM Host Context Ring-0 API
309 * @{
310 */
311VMMR0_INT_DECL(void) TMR0InitPerVMData(PGVM pGVM);
312VMMR0_INT_DECL(void) TMR0CleanupVM(PGVM pGVM);
313VMMR0_INT_DECL(int) TMR0TimerQueueGrow(PGVM pGVM, uint32_t idxQueue, uint32_t cMinTimers);
314/** @} */
315
316
317/** @} */
318
319RT_C_DECLS_END
320
321#endif /* !VBOX_INCLUDED_vmm_tm_h */
322
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