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