1 | /** @file
|
---|
2 | * TM - Time Monitor.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * If you received this file as part of a commercial VirtualBox
|
---|
17 | * distribution, then only the terms of your commercial VirtualBox
|
---|
18 | * license agreement apply instead of the previous paragraph.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef ___VBox_tm_h
|
---|
22 | #define ___VBox_tm_h
|
---|
23 |
|
---|
24 | #include <VBox/cdefs.h>
|
---|
25 | #include <VBox/types.h>
|
---|
26 | #ifdef IN_RING3
|
---|
27 | # include <iprt/time.h>
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | __BEGIN_DECLS
|
---|
31 |
|
---|
32 | /** @defgroup grp_tm The Time Monitor API
|
---|
33 | * @{
|
---|
34 | */
|
---|
35 |
|
---|
36 | /** Enable a timer hack which improves the timer response/resolution a bit. */
|
---|
37 | #define VBOX_HIGH_RES_TIMERS_HACK
|
---|
38 |
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Clock type.
|
---|
42 | */
|
---|
43 | typedef enum TMCLOCK
|
---|
44 | {
|
---|
45 | /** Real host time.
|
---|
46 | * This clock ticks all the time, so use with care. */
|
---|
47 | TMCLOCK_REAL = 0,
|
---|
48 | /** Virtual guest time.
|
---|
49 | * This clock only ticks when the guest is running. It's implemented
|
---|
50 | * as an offset to real time. */
|
---|
51 | TMCLOCK_VIRTUAL,
|
---|
52 | /** Virtual guest synchronized timer time.
|
---|
53 | * This is a special clock and timer queue for synchronizing virtual timers and
|
---|
54 | * virtual time sources. This clock is trying to keep up with TMCLOCK_VIRTUAL,
|
---|
55 | * but will wait for timers to be executed. If it lags too far behind TMCLOCK_VIRTUAL,
|
---|
56 | * it will try speed up to close the distance. */
|
---|
57 | TMCLOCK_VIRTUAL_SYNC,
|
---|
58 | /** Virtual CPU timestamp. (Running only when we're executing guest code.) */
|
---|
59 | TMCLOCK_TSC,
|
---|
60 | /** Number of clocks. */
|
---|
61 | TMCLOCK_MAX
|
---|
62 | } TMCLOCK;
|
---|
63 |
|
---|
64 |
|
---|
65 | /** @name Real Clock Methods
|
---|
66 | * @{
|
---|
67 | */
|
---|
68 | /**
|
---|
69 | * Gets the current TMCLOCK_REAL time.
|
---|
70 | *
|
---|
71 | * @returns Real time.
|
---|
72 | * @param pVM The VM handle.
|
---|
73 | */
|
---|
74 | TMDECL(uint64_t) TMRealGet(PVM pVM);
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Gets the frequency of the TMCLOCK_REAL clock.
|
---|
78 | *
|
---|
79 | * @returns frequency.
|
---|
80 | * @param pVM The VM handle.
|
---|
81 | */
|
---|
82 | TMDECL(uint64_t) TMRealGetFreq(PVM pVM);
|
---|
83 | /** @} */
|
---|
84 |
|
---|
85 |
|
---|
86 | /** @name Virtual Clock Methods
|
---|
87 | * @{
|
---|
88 | */
|
---|
89 | /**
|
---|
90 | * Gets the current TMCLOCK_VIRTUAL time.
|
---|
91 | *
|
---|
92 | * @returns The timestamp.
|
---|
93 | * @param pVM VM handle.
|
---|
94 | *
|
---|
95 | * @remark While the flow of time will never go backwards, the speed of the
|
---|
96 | * progress varies due to inaccurate RTTimeNanoTS and TSC. The latter can be
|
---|
97 | * influenced by power saving (SpeedStep, PowerNow!), while the former
|
---|
98 | * makes use of TSC and kernel timers.
|
---|
99 | */
|
---|
100 | TMDECL(uint64_t) TMVirtualGet(PVM pVM);
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Gets the current TMCLOCK_VIRTUAL time
|
---|
104 | *
|
---|
105 | * @returns The timestamp.
|
---|
106 | * @param pVM VM handle.
|
---|
107 | * @param fCheckTimers Check timers or not
|
---|
108 | *
|
---|
109 | * @remark While the flow of time will never go backwards, the speed of the
|
---|
110 | * progress varies due to inaccurate RTTimeNanoTS and TSC. The latter can be
|
---|
111 | * influenced by power saving (SpeedStep, PowerNow!), while the former
|
---|
112 | * makes use of TSC and kernel timers.
|
---|
113 | */
|
---|
114 | TMDECL(uint64_t) TMVirtualGetEx(PVM pVM, bool fCheckTimers);
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Gets the current lag of the synchronous virtual clock (relative to the virtual clock).
|
---|
118 | *
|
---|
119 | * @return The current lag.
|
---|
120 | * @param pVM VM handle.
|
---|
121 | */
|
---|
122 | TMDECL(uint64_t) TMVirtualSyncGetLag(PVM pVM);
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Get the current catch-up percent.
|
---|
126 | *
|
---|
127 | * @return The current catch0up percent. 0 means running at the same speed as the virtual clock.
|
---|
128 | * @param pVM VM handle.
|
---|
129 | */
|
---|
130 | TMDECL(uint32_t) TMVirtualSyncGetCatchUpPct(PVM pVM);
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Gets the current TMCLOCK_VIRTUAL frequency.
|
---|
134 | *
|
---|
135 | * @returns The freqency.
|
---|
136 | * @param pVM VM handle.
|
---|
137 | */
|
---|
138 | TMDECL(uint64_t) TMVirtualGetFreq(PVM pVM);
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Gets the current TMCLOCK_VIRTUAL_SYNC time.
|
---|
142 | *
|
---|
143 | * @returns The timestamp.
|
---|
144 | * @param pVM VM handle.
|
---|
145 | * @param fCheckTimers Check timers or not
|
---|
146 | * @thread EMT.
|
---|
147 | */
|
---|
148 | TMDECL(uint64_t) TMVirtualSyncGetEx(PVM pVM, bool fCheckTimers);
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Gets the current TMCLOCK_VIRTUAL_SYNC time.
|
---|
152 | *
|
---|
153 | * @returns The timestamp.
|
---|
154 | * @param pVM VM handle.
|
---|
155 | * @thread EMT.
|
---|
156 | */
|
---|
157 | TMDECL(uint64_t) TMVirtualSyncGet(PVM pVM);
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * Resumes the virtual clock.
|
---|
161 | *
|
---|
162 | * @returns VINF_SUCCESS on success.
|
---|
163 | * @returns VINF_INTERNAL_ERROR and VBOX_STRICT assertion if called out of order.
|
---|
164 | * @param pVM VM handle.
|
---|
165 | */
|
---|
166 | TMDECL(int) TMVirtualResume(PVM pVM);
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Pauses the virtual clock.
|
---|
170 | *
|
---|
171 | * @returns VINF_SUCCESS on success.
|
---|
172 | * @returns VINF_INTERNAL_ERROR and VBOX_STRICT assertion if called out of order.
|
---|
173 | * @param pVM VM handle.
|
---|
174 | */
|
---|
175 | TMDECL(int) TMVirtualPause(PVM pVM);
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Converts from virtual ticks to nanoseconds.
|
---|
179 | *
|
---|
180 | * @returns nanoseconds.
|
---|
181 | * @param pVM The VM handle.
|
---|
182 | * @param u64VirtualTicks The virtual ticks to convert.
|
---|
183 | * @remark There could be rounding errors here. We just do a simple integere divide
|
---|
184 | * without any adjustments.
|
---|
185 | */
|
---|
186 | TMDECL(uint64_t) TMVirtualToNano(PVM pVM, uint64_t u64VirtualTicks);
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Converts from virtual ticks to microseconds.
|
---|
190 | *
|
---|
191 | * @returns microseconds.
|
---|
192 | * @param pVM The VM handle.
|
---|
193 | * @param u64VirtualTicks The virtual ticks to convert.
|
---|
194 | * @remark There could be rounding errors here. We just do a simple integere divide
|
---|
195 | * without any adjustments.
|
---|
196 | */
|
---|
197 | TMDECL(uint64_t) TMVirtualToMicro(PVM pVM, uint64_t u64VirtualTicks);
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * Converts from virtual ticks to milliseconds.
|
---|
201 | *
|
---|
202 | * @returns milliseconds.
|
---|
203 | * @param pVM The VM handle.
|
---|
204 | * @param u64VirtualTicks The virtual ticks to convert.
|
---|
205 | * @remark There could be rounding errors here. We just do a simple integere divide
|
---|
206 | * without any adjustments.
|
---|
207 | */
|
---|
208 | TMDECL(uint64_t) TMVirtualToMilli(PVM pVM, uint64_t u64VirtualTicks);
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Converts from nanoseconds to virtual ticks.
|
---|
212 | *
|
---|
213 | * @returns virtual ticks.
|
---|
214 | * @param pVM The VM handle.
|
---|
215 | * @param u64NanoTS The nanosecond value ticks to convert.
|
---|
216 | * @remark There could be rounding and overflow errors here.
|
---|
217 | */
|
---|
218 | TMDECL(uint64_t) TMVirtualFromNano(PVM pVM, uint64_t u64NanoTS);
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * Converts from microseconds to virtual ticks.
|
---|
222 | *
|
---|
223 | * @returns virtual ticks.
|
---|
224 | * @param pVM The VM handle.
|
---|
225 | * @param u64MicroTS The microsecond value ticks to convert.
|
---|
226 | * @remark There could be rounding and overflow errors here.
|
---|
227 | */
|
---|
228 | TMDECL(uint64_t) TMVirtualFromMicro(PVM pVM, uint64_t u64MicroTS);
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Converts from milliseconds to virtual ticks.
|
---|
232 | *
|
---|
233 | * @returns virtual ticks.
|
---|
234 | * @param pVM The VM handle.
|
---|
235 | * @param u64MilliTS The millisecond value ticks to convert.
|
---|
236 | * @remark There could be rounding and overflow errors here.
|
---|
237 | */
|
---|
238 | TMDECL(uint64_t) TMVirtualFromMilli(PVM pVM, uint64_t u64MilliTS);
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * Gets the current warp drive percent.
|
---|
242 | *
|
---|
243 | * @returns The warp drive percent.
|
---|
244 | * @param pVM The VM handle.
|
---|
245 | */
|
---|
246 | TMDECL(uint32_t) TMVirtualGetWarpDrive(PVM pVM);
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Sets the warp drive percent of the virtual time.
|
---|
250 | *
|
---|
251 | * @returns VBox status code.
|
---|
252 | * @param pVM The VM handle.
|
---|
253 | * @param u32Percent The new percentage. 100 means normal operation.
|
---|
254 | */
|
---|
255 | TMDECL(int) TMVirtualSetWarpDrive(PVM pVM, uint32_t u32Percent);
|
---|
256 |
|
---|
257 | /** @} */
|
---|
258 |
|
---|
259 |
|
---|
260 | /** @name CPU Clock Methods
|
---|
261 | * @{
|
---|
262 | */
|
---|
263 | /**
|
---|
264 | * Resumes the CPU timestamp counter ticking.
|
---|
265 | *
|
---|
266 | * @returns VBox status code.
|
---|
267 | * @param pVM The VM to operate on.
|
---|
268 | */
|
---|
269 | TMDECL(int) TMCpuTickResume(PVM pVM);
|
---|
270 |
|
---|
271 | /**
|
---|
272 | * Pauses the CPU timestamp counter ticking.
|
---|
273 | *
|
---|
274 | * @returns VBox status code.
|
---|
275 | * @param pVM The VM to operate on.
|
---|
276 | */
|
---|
277 | TMDECL(int) TMCpuTickPause(PVM pVM);
|
---|
278 |
|
---|
279 | /**
|
---|
280 | * Read the current CPU timstamp counter.
|
---|
281 | *
|
---|
282 | * @returns Gets the CPU tsc.
|
---|
283 | * @param pVM The VM to operate on.
|
---|
284 | */
|
---|
285 | TMDECL(uint64_t) TMCpuTickGet(PVM pVM);
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * Returns the TSC offset (virtual TSC - host TSC)
|
---|
289 | *
|
---|
290 | * @returns TSC ofset
|
---|
291 | * @param pVM The VM to operate on.
|
---|
292 | * @todo Remove this when the code has been switched to TMCpuTickCanUseRealTSC.
|
---|
293 | */
|
---|
294 | TMDECL(uint64_t) TMCpuTickGetOffset(PVM pVM);
|
---|
295 |
|
---|
296 | /**
|
---|
297 | * Checks if AMD-V / VT-x can use an offsetted hardware TSC or not.
|
---|
298 | *
|
---|
299 | * @returns true/false accordingly.
|
---|
300 | * @param pVM The VM handle.
|
---|
301 | * @param poffRealTSC The offset against the TSC of the current CPU.
|
---|
302 | * Can be NULL.
|
---|
303 | * @thread EMT.
|
---|
304 | */
|
---|
305 | TMDECL(bool) TMCpuTickCanUseRealTSC(PVM pVM, uint64_t *poffRealTSC);
|
---|
306 |
|
---|
307 | /**
|
---|
308 | * Sets the current CPU timestamp counter.
|
---|
309 | *
|
---|
310 | * @returns VBox status code.
|
---|
311 | * @param pVM The VM to operate on.
|
---|
312 | * @param u64Tick The new timestamp value.
|
---|
313 | */
|
---|
314 | TMDECL(int) TMCpuTickSet(PVM pVM, uint64_t u64Tick);
|
---|
315 |
|
---|
316 | /**
|
---|
317 | * Get the timestamp frequency.
|
---|
318 | *
|
---|
319 | * @returns Number of ticks per second.
|
---|
320 | * @param pVM The VM.
|
---|
321 | */
|
---|
322 | TMDECL(uint64_t) TMCpuTicksPerSecond(PVM pVM);
|
---|
323 |
|
---|
324 | /** @} */
|
---|
325 |
|
---|
326 |
|
---|
327 | /** @name Timer Methods
|
---|
328 | * @{
|
---|
329 | */
|
---|
330 | /**
|
---|
331 | * Device timer callback function.
|
---|
332 | *
|
---|
333 | * @param pDevIns Device instance of the device which registered the timer.
|
---|
334 | * @param pTimer The timer handle.
|
---|
335 | */
|
---|
336 | typedef DECLCALLBACK(void) FNTMTIMERDEV(PPDMDEVINS pDevIns, PTMTIMER pTimer);
|
---|
337 | /** Pointer to a device timer callback function. */
|
---|
338 | typedef FNTMTIMERDEV *PFNTMTIMERDEV;
|
---|
339 |
|
---|
340 | /**
|
---|
341 | * Driver timer callback function.
|
---|
342 | *
|
---|
343 | * @param pDrvIns Device instance of the device which registered the timer.
|
---|
344 | * @param pTimer The timer handle.
|
---|
345 | */
|
---|
346 | typedef DECLCALLBACK(void) FNTMTIMERDRV(PPDMDRVINS pDrvIns, PTMTIMER pTimer);
|
---|
347 | /** Pointer to a driver timer callback function. */
|
---|
348 | typedef FNTMTIMERDRV *PFNTMTIMERDRV;
|
---|
349 |
|
---|
350 | /**
|
---|
351 | * Service timer callback function.
|
---|
352 | *
|
---|
353 | * @param pSrvIns Service instance of the device which registered the timer.
|
---|
354 | * @param pTimer The timer handle.
|
---|
355 | */
|
---|
356 | typedef DECLCALLBACK(void) FNTMTIMERSRV(PPDMSRVINS pSrvIns, PTMTIMER pTimer);
|
---|
357 | /** Pointer to a service timer callback function. */
|
---|
358 | typedef FNTMTIMERSRV *PFNTMTIMERSRV;
|
---|
359 |
|
---|
360 | /**
|
---|
361 | * Internal timer callback function.
|
---|
362 | *
|
---|
363 | * @param pVM The VM.
|
---|
364 | * @param pTimer The timer handle.
|
---|
365 | * @param pvUser User argument specified upon timer creation.
|
---|
366 | */
|
---|
367 | typedef DECLCALLBACK(void) FNTMTIMERINT(PVM pVM, PTMTIMER pTimer, void *pvUser);
|
---|
368 | /** Pointer to internal timer callback function. */
|
---|
369 | typedef FNTMTIMERINT *PFNTMTIMERINT;
|
---|
370 |
|
---|
371 | /**
|
---|
372 | * External timer callback function.
|
---|
373 | *
|
---|
374 | * @param pvUser User argument as specified when the timer was created.
|
---|
375 | */
|
---|
376 | typedef DECLCALLBACK(void) FNTMTIMEREXT(void *pvUser);
|
---|
377 | /** Pointer to an external timer callback function. */
|
---|
378 | typedef FNTMTIMEREXT *PFNTMTIMEREXT;
|
---|
379 |
|
---|
380 |
|
---|
381 | /**
|
---|
382 | * Gets the host context ring-3 pointer of the timer.
|
---|
383 | *
|
---|
384 | * @returns HC R3 pointer.
|
---|
385 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
386 | */
|
---|
387 | TMDECL(PTMTIMERR3) TMTimerR3Ptr(PTMTIMER pTimer);
|
---|
388 |
|
---|
389 | /**
|
---|
390 | * Gets the host context ring-0 pointer of the timer.
|
---|
391 | *
|
---|
392 | * @returns HC R0 pointer.
|
---|
393 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
394 | */
|
---|
395 | TMDECL(PTMTIMERR0) TMTimerR0Ptr(PTMTIMER pTimer);
|
---|
396 |
|
---|
397 | /**
|
---|
398 | * Gets the GC pointer of the timer.
|
---|
399 | *
|
---|
400 | * @returns GC pointer.
|
---|
401 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
402 | */
|
---|
403 | TMDECL(PTMTIMERGC) TMTimerGCPtr(PTMTIMER pTimer);
|
---|
404 |
|
---|
405 | /**
|
---|
406 | * Gets the GC pointer of the timer.
|
---|
407 | *
|
---|
408 | * @returns GC pointer.
|
---|
409 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
410 | * @deprecated
|
---|
411 | */
|
---|
412 | DECLINLINE(PTMTIMERHC) TMTimerHCPtr(PTMTIMER pTimer)
|
---|
413 | {
|
---|
414 | return (PTMTIMERHC)TMTimerR3Ptr(pTimer);
|
---|
415 | }
|
---|
416 |
|
---|
417 | /**
|
---|
418 | * Destroy a timer
|
---|
419 | *
|
---|
420 | * @returns VBox status.
|
---|
421 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
422 | */
|
---|
423 | TMDECL(int) TMTimerDestroy(PTMTIMER pTimer);
|
---|
424 |
|
---|
425 | /**
|
---|
426 | * Arm a timer with a (new) expire time.
|
---|
427 | *
|
---|
428 | * @returns VBox status.
|
---|
429 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
430 | * @param u64Expire New expire time.
|
---|
431 | */
|
---|
432 | TMDECL(int) TMTimerSet(PTMTIMER pTimer, uint64_t u64Expire);
|
---|
433 |
|
---|
434 | /**
|
---|
435 | * Arm a timer with a (new) expire time relative to current clock.
|
---|
436 | *
|
---|
437 | * @returns VBox status.
|
---|
438 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
439 | * @param cMilliesToNext Number of millieseconds to the next tick.
|
---|
440 | */
|
---|
441 | TMDECL(int) TMTimerSetMillies(PTMTIMER pTimer, uint32_t cMilliesToNext);
|
---|
442 |
|
---|
443 | /**
|
---|
444 | * Get the current clock time.
|
---|
445 | * Handy for calculating the new expire time.
|
---|
446 | *
|
---|
447 | * @returns Current clock time.
|
---|
448 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
449 | */
|
---|
450 | TMDECL(uint64_t) TMTimerGet(PTMTIMER pTimer);
|
---|
451 |
|
---|
452 | /**
|
---|
453 | * Get the current clock time as nanoseconds.
|
---|
454 | *
|
---|
455 | * @returns The timer clock as nanoseconds.
|
---|
456 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
457 | */
|
---|
458 | TMDECL(uint64_t) TMTimerGetNano(PTMTIMER pTimer);
|
---|
459 |
|
---|
460 | /**
|
---|
461 | * Get the current clock time as microseconds.
|
---|
462 | *
|
---|
463 | * @returns The timer clock as microseconds.
|
---|
464 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
465 | */
|
---|
466 | TMDECL(uint64_t) TMTimerGetMicro(PTMTIMER pTimer);
|
---|
467 |
|
---|
468 | /**
|
---|
469 | * Get the current clock time as milliseconds.
|
---|
470 | *
|
---|
471 | * @returns The timer clock as milliseconds.
|
---|
472 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
473 | */
|
---|
474 | TMDECL(uint64_t) TMTimerGetMilli(PTMTIMER pTimer);
|
---|
475 |
|
---|
476 | /**
|
---|
477 | * Get the freqency of the timer clock.
|
---|
478 | *
|
---|
479 | * @returns Clock frequency (as Hz of course).
|
---|
480 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
481 | */
|
---|
482 | TMDECL(uint64_t) TMTimerGetFreq(PTMTIMER pTimer);
|
---|
483 |
|
---|
484 | /**
|
---|
485 | * Get the expire time of the timer.
|
---|
486 | * Only valid for active timers.
|
---|
487 | *
|
---|
488 | * @returns Expire time of the timer.
|
---|
489 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
490 | */
|
---|
491 | TMDECL(uint64_t) TMTimerGetExpire(PTMTIMER pTimer);
|
---|
492 |
|
---|
493 | /**
|
---|
494 | * Converts the specified timer clock time to nanoseconds.
|
---|
495 | *
|
---|
496 | * @returns nanoseconds.
|
---|
497 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
498 | * @param u64Ticks The clock ticks.
|
---|
499 | * @remark There could be rounding errors here. We just do a simple integere divide
|
---|
500 | * without any adjustments.
|
---|
501 | */
|
---|
502 | TMDECL(uint64_t) TMTimerToNano(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
503 |
|
---|
504 | /**
|
---|
505 | * Converts the specified timer clock time to microseconds.
|
---|
506 | *
|
---|
507 | * @returns microseconds.
|
---|
508 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
509 | * @param u64Ticks The clock ticks.
|
---|
510 | * @remark There could be rounding errors here. We just do a simple integere divide
|
---|
511 | * without any adjustments.
|
---|
512 | */
|
---|
513 | TMDECL(uint64_t) TMTimerToMicro(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
514 |
|
---|
515 | /**
|
---|
516 | * Converts the specified timer clock time to milliseconds.
|
---|
517 | *
|
---|
518 | * @returns milliseconds.
|
---|
519 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
520 | * @param u64Ticks The clock ticks.
|
---|
521 | * @remark There could be rounding errors here. We just do a simple integere divide
|
---|
522 | * without any adjustments.
|
---|
523 | */
|
---|
524 | TMDECL(uint64_t) TMTimerToMilli(PTMTIMER pTimer, uint64_t u64Ticks);
|
---|
525 |
|
---|
526 | /**
|
---|
527 | * Converts the specified nanosecond timestamp to timer clock ticks.
|
---|
528 | *
|
---|
529 | * @returns timer clock ticks.
|
---|
530 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
531 | * @param u64NanoTS The nanosecond value ticks to convert.
|
---|
532 | * @remark There could be rounding and overflow errors here.
|
---|
533 | */
|
---|
534 | TMDECL(uint64_t) TMTimerFromNano(PTMTIMER pTimer, uint64_t u64NanoTS);
|
---|
535 |
|
---|
536 | /**
|
---|
537 | * Converts the specified microsecond timestamp to timer clock ticks.
|
---|
538 | *
|
---|
539 | * @returns timer clock ticks.
|
---|
540 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
541 | * @param u64MicroTS The microsecond value ticks to convert.
|
---|
542 | * @remark There could be rounding and overflow errors here.
|
---|
543 | */
|
---|
544 | TMDECL(uint64_t) TMTimerFromMicro(PTMTIMER pTimer, uint64_t u64MicroTS);
|
---|
545 |
|
---|
546 | /**
|
---|
547 | * Converts the specified millisecond timestamp to timer clock ticks.
|
---|
548 | *
|
---|
549 | * @returns timer clock ticks.
|
---|
550 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
551 | * @param u64MilliTS The millisecond value ticks to convert.
|
---|
552 | * @remark There could be rounding and overflow errors here.
|
---|
553 | */
|
---|
554 | TMDECL(uint64_t) TMTimerFromMilli(PTMTIMER pTimer, uint64_t u64MilliTS);
|
---|
555 |
|
---|
556 | /**
|
---|
557 | * Stop the timer.
|
---|
558 | * Use TMR3TimerArm() to "un-stop" the timer.
|
---|
559 | *
|
---|
560 | * @returns VBox status.
|
---|
561 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
562 | */
|
---|
563 | TMDECL(int) TMTimerStop(PTMTIMER pTimer);
|
---|
564 |
|
---|
565 | /**
|
---|
566 | * Checks if a timer is active or not.
|
---|
567 | *
|
---|
568 | * @returns True if active.
|
---|
569 | * @returns False if not active.
|
---|
570 | * @param pTimer Timer handle as returned by one of the create functions.
|
---|
571 | */
|
---|
572 | TMDECL(bool) TMTimerIsActive(PTMTIMER pTimer);
|
---|
573 |
|
---|
574 | /**
|
---|
575 | * Set FF if we've passed the next virtual event.
|
---|
576 | *
|
---|
577 | * This function is called before FFs are checked in the inner execution EM loops.
|
---|
578 | *
|
---|
579 | * @returns Virtual timer ticks to the next event.
|
---|
580 | * @thread The emulation thread.
|
---|
581 | */
|
---|
582 | TMDECL(uint64_t) TMTimerPoll(PVM pVM);
|
---|
583 |
|
---|
584 | /** @} */
|
---|
585 |
|
---|
586 |
|
---|
587 | #ifdef IN_RING3
|
---|
588 | /** @defgroup grp_tm_r3 The TM Host Context Ring-3 API
|
---|
589 | * @ingroup grp_tm
|
---|
590 | * @{
|
---|
591 | */
|
---|
592 |
|
---|
593 | /**
|
---|
594 | * Initializes the TM.
|
---|
595 | *
|
---|
596 | * @returns VBox status code.
|
---|
597 | * @param pVM The VM to operate on.
|
---|
598 | */
|
---|
599 | TMR3DECL(int) TMR3Init(PVM pVM);
|
---|
600 |
|
---|
601 | /**
|
---|
602 | * Applies relocations to data and code managed by this
|
---|
603 | * component. This function will be called at init and
|
---|
604 | * whenever the VMM need to relocate it self inside the GC.
|
---|
605 | *
|
---|
606 | * @param pVM The VM.
|
---|
607 | * @param offDelta Relocation delta relative to old location.
|
---|
608 | */
|
---|
609 | TMR3DECL(void) TMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
|
---|
610 |
|
---|
611 | /**
|
---|
612 | * Terminates the TM.
|
---|
613 | *
|
---|
614 | * Termination means cleaning up and freeing all resources,
|
---|
615 | * the VM it self is at this point powered off or suspended.
|
---|
616 | *
|
---|
617 | * @returns VBox status code.
|
---|
618 | * @param pVM The VM to operate on.
|
---|
619 | */
|
---|
620 | TMR3DECL(int) TMR3Term(PVM pVM);
|
---|
621 |
|
---|
622 | /**
|
---|
623 | * The VM is being reset.
|
---|
624 | *
|
---|
625 | * For the TM component this means that a rescheduling is preformed,
|
---|
626 | * the FF is cleared and but without running the queues. We'll have to
|
---|
627 | * check if this makes sense or not, but it seems like a good idea now....
|
---|
628 | *
|
---|
629 | * @param pVM VM handle.
|
---|
630 | */
|
---|
631 | TMR3DECL(void) TMR3Reset(PVM pVM);
|
---|
632 |
|
---|
633 | /**
|
---|
634 | * Resolve a builtin GC symbol.
|
---|
635 | * Called by PDM when loading or relocating GC modules.
|
---|
636 | *
|
---|
637 | * @returns VBox status
|
---|
638 | * @param pVM VM Handle.
|
---|
639 | * @param pszSymbol Symbol to resolv
|
---|
640 | * @param pGCPtrValue Where to store the symbol value.
|
---|
641 | * @remark This has to work before TMR3Relocate() is called.
|
---|
642 | */
|
---|
643 | TMR3DECL(int) TMR3GetImportGC(PVM pVM, const char *pszSymbol, PRTGCPTR pGCPtrValue);
|
---|
644 |
|
---|
645 | /**
|
---|
646 | * Creates a device timer.
|
---|
647 | *
|
---|
648 | * @returns VBox status.
|
---|
649 | * @param pVM The VM to create the timer in.
|
---|
650 | * @param pDevIns Device instance.
|
---|
651 | * @param enmClock The clock to use on this timer.
|
---|
652 | * @param pfnCallback Callback function.
|
---|
653 | * @param pszDesc Pointer to description string which must stay around
|
---|
654 | * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
|
---|
655 | * @param ppTimer Where to store the timer on success.
|
---|
656 | */
|
---|
657 | TMR3DECL(int) TMR3TimerCreateDevice(PVM pVM, PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, const char *pszDesc, PPTMTIMERHC ppTimer);
|
---|
658 |
|
---|
659 | /**
|
---|
660 | * Creates a driver timer.
|
---|
661 | *
|
---|
662 | * @returns VBox status.
|
---|
663 | * @param pVM The VM to create the timer in.
|
---|
664 | * @param pDrvIns Driver instance.
|
---|
665 | * @param enmClock The clock to use on this timer.
|
---|
666 | * @param pfnCallback Callback function.
|
---|
667 | * @param pszDesc Pointer to description string which must stay around
|
---|
668 | * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
|
---|
669 | * @param ppTimer Where to store the timer on success.
|
---|
670 | */
|
---|
671 | TMR3DECL(int) TMR3TimerCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, const char *pszDesc, PPTMTIMERHC ppTimer);
|
---|
672 |
|
---|
673 | /**
|
---|
674 | * Creates an internal timer.
|
---|
675 | *
|
---|
676 | * @returns VBox status.
|
---|
677 | * @param pVM The VM to create the timer in.
|
---|
678 | * @param enmClock The clock to use on this timer.
|
---|
679 | * @param pfnCallback Callback function.
|
---|
680 | * @param pvUser User argument to be passed to the callback.
|
---|
681 | * @param pszDesc Pointer to description string which must stay around
|
---|
682 | * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
|
---|
683 | * @param ppTimer Where to store the timer on success.
|
---|
684 | */
|
---|
685 | TMR3DECL(int) TMR3TimerCreateInternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMERINT pfnCallback, void *pvUser, const char *pszDesc, PPTMTIMERHC ppTimer);
|
---|
686 |
|
---|
687 | /**
|
---|
688 | * Creates an external timer.
|
---|
689 | *
|
---|
690 | * @returns Timer handle on success.
|
---|
691 | * @returns NULL on failure.
|
---|
692 | * @param pVM The VM to create the timer in.
|
---|
693 | * @param enmClock The clock to use on this timer.
|
---|
694 | * @param pfnCallback Callback function.
|
---|
695 | * @param pvUser User argument.
|
---|
696 | * @param pszDesc Pointer to description string which must stay around
|
---|
697 | * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
|
---|
698 | */
|
---|
699 | TMR3DECL(PTMTIMERHC) TMR3TimerCreateExternal(PVM pVM, TMCLOCK enmClock, PFNTMTIMEREXT pfnCallback, void *pvUser, const char *pszDesc);
|
---|
700 |
|
---|
701 | /**
|
---|
702 | * Destroy all timers owned by a device.
|
---|
703 | *
|
---|
704 | * @returns VBox status.
|
---|
705 | * @param pVM VM handle.
|
---|
706 | * @param pDevIns Device which timers should be destroyed.
|
---|
707 | */
|
---|
708 | TMR3DECL(int) TMR3TimerDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
|
---|
709 |
|
---|
710 | /**
|
---|
711 | * Destroy all timers owned by a driver.
|
---|
712 | *
|
---|
713 | * @returns VBox status.
|
---|
714 | * @param pVM VM handle.
|
---|
715 | * @param pDrvIns Driver which timers should be destroyed.
|
---|
716 | */
|
---|
717 | TMR3DECL(int) TMR3TimerDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
|
---|
718 |
|
---|
719 | /**
|
---|
720 | * Saves the state of a timer to a saved state.
|
---|
721 | *
|
---|
722 | * @returns VBox status.
|
---|
723 | * @param pTimer Timer to save.
|
---|
724 | * @param pSSM Save State Manager handle.
|
---|
725 | */
|
---|
726 | TMR3DECL(int) TMR3TimerSave(PTMTIMERHC pTimer, PSSMHANDLE pSSM);
|
---|
727 |
|
---|
728 | /**
|
---|
729 | * Loads the state of a timer from a saved state.
|
---|
730 | *
|
---|
731 | * @returns VBox status.
|
---|
732 | * @param pTimer Timer to restore.
|
---|
733 | * @param pSSM Save State Manager handle.
|
---|
734 | */
|
---|
735 | TMR3DECL(int) TMR3TimerLoad(PTMTIMERHC pTimer, PSSMHANDLE pSSM);
|
---|
736 |
|
---|
737 | /**
|
---|
738 | * Schedules and runs any pending timers.
|
---|
739 | *
|
---|
740 | * This is normally called from a forced action handler in EMT.
|
---|
741 | *
|
---|
742 | * @param pVM The VM to run the timers for.
|
---|
743 | * @thread The emulation thread.
|
---|
744 | */
|
---|
745 | TMR3DECL(void) TMR3TimerQueuesDo(PVM pVM);
|
---|
746 |
|
---|
747 | /**
|
---|
748 | * Get the real world UTC time adjusted for VM lag.
|
---|
749 | *
|
---|
750 | * @returns pTime.
|
---|
751 | * @param pVM The VM instance.
|
---|
752 | * @param pTime Where to store the time.
|
---|
753 | */
|
---|
754 | TMR3DECL(PRTTIMESPEC) TMR3UTCNow(PVM pVM, PRTTIMESPEC pTime);
|
---|
755 |
|
---|
756 | /** @} */
|
---|
757 | #endif
|
---|
758 |
|
---|
759 |
|
---|
760 | #ifdef IN_GC
|
---|
761 | /** @defgroup grp_tm_gc The TM Guest Context API
|
---|
762 | * @ingroup grp_tm
|
---|
763 | * @{
|
---|
764 | */
|
---|
765 |
|
---|
766 |
|
---|
767 | /** @} */
|
---|
768 | #endif
|
---|
769 |
|
---|
770 | /** @} */
|
---|
771 |
|
---|
772 | __END_DECLS
|
---|
773 |
|
---|
774 | #endif
|
---|
775 |
|
---|