VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/TMAllVirtual.cpp@ 37503

Last change on this file since 37503 was 37439, checked in by vboxsync, 14 years ago

TMAllVirtual.cpp: Added some trace points.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 36.7 KB
Line 
1/* $Id: TMAllVirtual.cpp 37439 2011-06-14 14:30:40Z vboxsync $ */
2/** @file
3 * TM - Timeout Manager, Virtual Time, All Contexts.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_TM
23#include <VBox/vmm/tm.h>
24#include <VBox/vmm/dbgftrace.h>
25#ifdef IN_RING3
26# include <VBox/vmm/rem.h>
27# include <iprt/thread.h>
28#endif
29#include "TMInternal.h"
30#include <VBox/vmm/vm.h>
31#include <VBox/vmm/vmm.h>
32#include <VBox/err.h>
33#include <VBox/log.h>
34#include <VBox/sup.h>
35
36#include <iprt/time.h>
37#include <iprt/assert.h>
38#include <iprt/asm.h>
39#include <iprt/asm-math.h>
40
41
42
43/**
44 * Helper function that's used by the assembly routines when something goes bust.
45 *
46 * @param pData Pointer to the data structure.
47 * @param u64NanoTS The calculated nano ts.
48 * @param u64DeltaPrev The delta relative to the previously returned timestamp.
49 * @param u64PrevNanoTS The previously returned timestamp (as it was read it).
50 */
51DECLEXPORT(void) tmVirtualNanoTSBad(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS)
52{
53 //PVM pVM = (PVM)((uint8_t *)pData - RT_OFFSETOF(VM, CTXALLSUFF(s.tm.VirtualGetRawData)));
54 pData->cBadPrev++;
55 if ((int64_t)u64DeltaPrev < 0)
56 LogRel(("TM: u64DeltaPrev=%RI64 u64PrevNanoTS=0x%016RX64 u64NanoTS=0x%016RX64\n",
57 u64DeltaPrev, u64PrevNanoTS, u64NanoTS));
58 else
59 Log(("TM: u64DeltaPrev=%RI64 u64PrevNanoTS=0x%016RX64 u64NanoTS=0x%016RX64 (debugging?)\n",
60 u64DeltaPrev, u64PrevNanoTS, u64NanoTS));
61}
62
63
64/**
65 * Called the first time somebody asks for the time or when the GIP
66 * is mapped/unmapped.
67 *
68 * This should never ever happen.
69 */
70DECLEXPORT(uint64_t) tmVirtualNanoTSRediscover(PRTTIMENANOTSDATA pData)
71{
72 //PVM pVM = (PVM)((uint8_t *)pData - RT_OFFSETOF(VM, CTXALLSUFF(s.tm.VirtualGetRawData)));
73 PSUPGLOBALINFOPAGE pGip = g_pSUPGlobalInfoPage;
74 AssertFatalMsgFailed(("pGip=%p u32Magic=%#x\n", pGip, VALID_PTR(pGip) ? pGip->u32Magic : 0));
75 return 0; /* gcc false positive warning */
76}
77
78
79#if 1
80
81/**
82 * Wrapper around the IPRT GIP time methods.
83 */
84DECLINLINE(uint64_t) tmVirtualGetRawNanoTS(PVM pVM)
85{
86# ifdef IN_RING3
87 uint64_t u64 = CTXALLSUFF(pVM->tm.s.pfnVirtualGetRaw)(&CTXALLSUFF(pVM->tm.s.VirtualGetRawData));
88# else /* !IN_RING3 */
89 uint32_t cPrevSteps = pVM->tm.s.CTX_SUFF(VirtualGetRawData).c1nsSteps;
90 uint64_t u64 = pVM->tm.s.CTX_SUFF(pfnVirtualGetRaw)(&pVM->tm.s.CTX_SUFF(VirtualGetRawData));
91 if (cPrevSteps != pVM->tm.s.CTX_SUFF(VirtualGetRawData).c1nsSteps)
92 VMCPU_FF_SET(VMMGetCpu(pVM), VMCPU_FF_TO_R3);
93# endif /* !IN_RING3 */
94 /*DBGFTRACE_POS_U64(pVM, u64);*/
95 return u64;
96}
97
98#else
99
100/**
101 * This is (mostly) the same as rtTimeNanoTSInternal() except
102 * for the two globals which live in TM.
103 *
104 * @returns Nanosecond timestamp.
105 * @param pVM The VM handle.
106 */
107static uint64_t tmVirtualGetRawNanoTS(PVM pVM)
108{
109 uint64_t u64Delta;
110 uint32_t u32NanoTSFactor0;
111 uint64_t u64TSC;
112 uint64_t u64NanoTS;
113 uint32_t u32UpdateIntervalTSC;
114 uint64_t u64PrevNanoTS;
115
116 /*
117 * Read the GIP data and the previous value.
118 */
119 for (;;)
120 {
121 uint32_t u32TransactionId;
122 PSUPGLOBALINFOPAGE pGip = g_pSUPGlobalInfoPage;
123#ifdef IN_RING3
124 if (RT_UNLIKELY(!pGip || pGip->u32Magic != SUPGLOBALINFOPAGE_MAGIC))
125 return RTTimeSystemNanoTS();
126#endif
127
128 if (pGip->u32Mode != SUPGIPMODE_ASYNC_TSC)
129 {
130 u32TransactionId = pGip->aCPUs[0].u32TransactionId;
131#ifdef RT_OS_L4
132 Assert((u32TransactionId & 1) == 0);
133#endif
134 u32UpdateIntervalTSC = pGip->aCPUs[0].u32UpdateIntervalTSC;
135 u64NanoTS = pGip->aCPUs[0].u64NanoTS;
136 u64TSC = pGip->aCPUs[0].u64TSC;
137 u32NanoTSFactor0 = pGip->u32UpdateIntervalNS;
138 u64Delta = ASMReadTSC();
139 u64PrevNanoTS = ASMAtomicReadU64(&pVM->tm.s.u64VirtualRawPrev);
140 if (RT_UNLIKELY( pGip->aCPUs[0].u32TransactionId != u32TransactionId
141 || (u32TransactionId & 1)))
142 continue;
143 }
144 else
145 {
146 /* SUPGIPMODE_ASYNC_TSC */
147 PSUPGIPCPU pGipCpu;
148
149 uint8_t u8ApicId = ASMGetApicId();
150 if (RT_LIKELY(u8ApicId < RT_ELEMENTS(pGip->aCPUs)))
151 pGipCpu = &pGip->aCPUs[u8ApicId];
152 else
153 {
154 AssertMsgFailed(("%x\n", u8ApicId));
155 pGipCpu = &pGip->aCPUs[0];
156 }
157
158 u32TransactionId = pGipCpu->u32TransactionId;
159#ifdef RT_OS_L4
160 Assert((u32TransactionId & 1) == 0);
161#endif
162 u32UpdateIntervalTSC = pGipCpu->u32UpdateIntervalTSC;
163 u64NanoTS = pGipCpu->u64NanoTS;
164 u64TSC = pGipCpu->u64TSC;
165 u32NanoTSFactor0 = pGip->u32UpdateIntervalNS;
166 u64Delta = ASMReadTSC();
167 u64PrevNanoTS = ASMAtomicReadU64(&pVM->tm.s.u64VirtualRawPrev);
168#ifdef IN_RC
169 Assert(!(ASMGetFlags() & X86_EFL_IF));
170#else
171 if (RT_UNLIKELY(u8ApicId != ASMGetApicId()))
172 continue;
173 if (RT_UNLIKELY( pGipCpu->u32TransactionId != u32TransactionId
174 || (u32TransactionId & 1)))
175 continue;
176#endif
177 }
178 break;
179 }
180
181 /*
182 * Calc NanoTS delta.
183 */
184 u64Delta -= u64TSC;
185 if (u64Delta > u32UpdateIntervalTSC)
186 {
187 /*
188 * We've expired the interval, cap it. If we're here for the 2nd
189 * time without any GIP update in-between, the checks against
190 * pVM->tm.s.u64VirtualRawPrev below will force 1ns stepping.
191 */
192 u64Delta = u32UpdateIntervalTSC;
193 }
194#if !defined(_MSC_VER) || defined(RT_ARCH_AMD64) /* GCC makes very pretty code from these two inline calls, while MSC cannot. */
195 u64Delta = ASMMult2xU32RetU64((uint32_t)u64Delta, u32NanoTSFactor0);
196 u64Delta = ASMDivU64ByU32RetU32(u64Delta, u32UpdateIntervalTSC);
197#else
198 __asm
199 {
200 mov eax, dword ptr [u64Delta]
201 mul dword ptr [u32NanoTSFactor0]
202 div dword ptr [u32UpdateIntervalTSC]
203 mov dword ptr [u64Delta], eax
204 xor edx, edx
205 mov dword ptr [u64Delta + 4], edx
206 }
207#endif
208
209 /*
210 * Calculate the time and compare it with the previously returned value.
211 *
212 * Since this function is called *very* frequently when the VM is running
213 * and then mostly on EMT, we can restrict the valid range of the delta
214 * (-1s to 2*GipUpdates) and simplify/optimize the default path.
215 */
216 u64NanoTS += u64Delta;
217 uint64_t u64DeltaPrev = u64NanoTS - u64PrevNanoTS;
218 if (RT_LIKELY(u64DeltaPrev < 1000000000 /* 1s */))
219 /* frequent - less than 1s since last call. */;
220 else if ( (int64_t)u64DeltaPrev < 0
221 && (int64_t)u64DeltaPrev + u32NanoTSFactor0 * 2 > 0)
222 {
223 /* occasional - u64NanoTS is in the 'past' relative to previous returns. */
224 ASMAtomicIncU32(&pVM->tm.s.CTX_SUFF(VirtualGetRawData).c1nsSteps);
225 u64NanoTS = u64PrevNanoTS + 1;
226#ifndef IN_RING3
227 VM_FF_SET(pVM, VM_FF_TO_R3); /* S10 hack */
228#endif
229 }
230 else if (u64PrevNanoTS)
231 {
232 /* Something has gone bust, if negative offset it's real bad. */
233 ASMAtomicIncU32(&pVM->tm.s.CTX_SUFF(VirtualGetRawData).cBadPrev);
234 if ((int64_t)u64DeltaPrev < 0)
235 LogRel(("TM: u64DeltaPrev=%RI64 u64PrevNanoTS=0x%016RX64 u64NanoTS=0x%016RX64 u64Delta=%#RX64\n",
236 u64DeltaPrev, u64PrevNanoTS, u64NanoTS, u64Delta));
237 else
238 Log(("TM: u64DeltaPrev=%RI64 u64PrevNanoTS=0x%016RX64 u64NanoTS=0x%016RX64 u64Delta=%#RX64 (debugging?)\n",
239 u64DeltaPrev, u64PrevNanoTS, u64NanoTS, u64Delta));
240#ifdef DEBUG_bird
241 /** @todo there are some hickups during boot and reset that can cause 2-5 seconds delays. Investigate... */
242 AssertMsg(u64PrevNanoTS > UINT64_C(100000000000) /* 100s */,
243 ("u64DeltaPrev=%RI64 u64PrevNanoTS=0x%016RX64 u64NanoTS=0x%016RX64 u64Delta=%#RX64\n",
244 u64DeltaPrev, u64PrevNanoTS, u64NanoTS, u64Delta));
245#endif
246 }
247 /* else: We're resuming (see TMVirtualResume). */
248 if (RT_LIKELY(ASMAtomicCmpXchgU64(&pVM->tm.s.u64VirtualRawPrev, u64NanoTS, u64PrevNanoTS)))
249 return u64NanoTS;
250
251 /*
252 * Attempt updating the previous value, provided we're still ahead of it.
253 *
254 * There is no point in recalculating u64NanoTS because we got preempted or if
255 * we raced somebody while the GIP was updated, since these are events
256 * that might occur at any point in the return path as well.
257 */
258 for (int cTries = 50;;)
259 {
260 u64PrevNanoTS = ASMAtomicReadU64(&pVM->tm.s.u64VirtualRawPrev);
261 if (u64PrevNanoTS >= u64NanoTS)
262 break;
263 if (ASMAtomicCmpXchgU64(&pVM->tm.s.u64VirtualRawPrev, u64NanoTS, u64PrevNanoTS))
264 break;
265 AssertBreak(--cTries <= 0);
266 if (cTries < 25 && !VM_IS_EMT(pVM)) /* give up early */
267 break;
268 }
269
270 return u64NanoTS;
271}
272
273#endif
274
275
276/**
277 * Get the time when we're not running at 100%
278 *
279 * @returns The timestamp.
280 * @param pVM The VM handle.
281 */
282static uint64_t tmVirtualGetRawNonNormal(PVM pVM)
283{
284 /*
285 * Recalculate the RTTimeNanoTS() value for the period where
286 * warp drive has been enabled.
287 */
288 uint64_t u64 = tmVirtualGetRawNanoTS(pVM);
289 u64 -= pVM->tm.s.u64VirtualWarpDriveStart;
290 u64 *= pVM->tm.s.u32VirtualWarpDrivePercentage;
291 u64 /= 100;
292 u64 += pVM->tm.s.u64VirtualWarpDriveStart;
293
294 /*
295 * Now we apply the virtual time offset.
296 * (Which is the negated tmVirtualGetRawNanoTS() value for when the virtual
297 * machine started if it had been running continuously without any suspends.)
298 */
299 u64 -= pVM->tm.s.u64VirtualOffset;
300 return u64;
301}
302
303
304/**
305 * Get the raw virtual time.
306 *
307 * @returns The current time stamp.
308 * @param pVM The VM handle.
309 */
310DECLINLINE(uint64_t) tmVirtualGetRaw(PVM pVM)
311{
312 if (RT_LIKELY(!pVM->tm.s.fVirtualWarpDrive))
313 return tmVirtualGetRawNanoTS(pVM) - pVM->tm.s.u64VirtualOffset;
314 return tmVirtualGetRawNonNormal(pVM);
315}
316
317
318/**
319 * Inlined version of tmVirtualGetEx.
320 */
321DECLINLINE(uint64_t) tmVirtualGet(PVM pVM, bool fCheckTimers)
322{
323 uint64_t u64;
324 if (RT_LIKELY(pVM->tm.s.cVirtualTicking))
325 {
326 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualGet);
327 u64 = tmVirtualGetRaw(pVM);
328
329 /*
330 * Use the chance to check for expired timers.
331 */
332 if (fCheckTimers)
333 {
334 PVMCPU pVCpuDst = &pVM->aCpus[pVM->tm.s.idTimerCpu];
335 if ( !VMCPU_FF_ISSET(pVCpuDst, VMCPU_FF_TIMER)
336 && !pVM->tm.s.fRunningQueues
337 && ( pVM->tm.s.CTX_SUFF(paTimerQueues)[TMCLOCK_VIRTUAL].u64Expire <= u64
338 || ( pVM->tm.s.fVirtualSyncTicking
339 && pVM->tm.s.CTX_SUFF(paTimerQueues)[TMCLOCK_VIRTUAL_SYNC].u64Expire <= u64 - pVM->tm.s.offVirtualSync
340 )
341 )
342 && !pVM->tm.s.fRunningQueues
343 )
344 {
345 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualGetSetFF);
346 Log5(("TMAllVirtual(%u): FF: %d -> 1\n", __LINE__, VMCPU_FF_ISPENDING(pVCpuDst, VMCPU_FF_TIMER)));
347 VMCPU_FF_SET(pVCpuDst, VMCPU_FF_TIMER);
348#ifdef IN_RING3
349 REMR3NotifyTimerPending(pVM, pVCpuDst);
350 VMR3NotifyCpuFFU(pVCpuDst->pUVCpu, VMNOTIFYFF_FLAGS_DONE_REM);
351#endif
352 }
353 }
354 }
355 else
356 u64 = pVM->tm.s.u64Virtual;
357 return u64;
358}
359
360
361/**
362 * Gets the current TMCLOCK_VIRTUAL time
363 *
364 * @returns The timestamp.
365 * @param pVM VM handle.
366 *
367 * @remark While the flow of time will never go backwards, the speed of the
368 * progress varies due to inaccurate RTTimeNanoTS and TSC. The latter can be
369 * influenced by power saving (SpeedStep, PowerNow!), while the former
370 * makes use of TSC and kernel timers.
371 */
372VMM_INT_DECL(uint64_t) TMVirtualGet(PVM pVM)
373{
374 return tmVirtualGet(pVM, true /*fCheckTimers*/);
375}
376
377
378/**
379 * Gets the current TMCLOCK_VIRTUAL time without checking
380 * timers or anything.
381 *
382 * Meaning, this has no side effect on FFs like TMVirtualGet may have.
383 *
384 * @returns The timestamp.
385 * @param pVM VM handle.
386 *
387 * @remarks See TMVirtualGet.
388 */
389VMM_INT_DECL(uint64_t) TMVirtualGetNoCheck(PVM pVM)
390{
391 return tmVirtualGet(pVM, false /*fCheckTimers*/);
392}
393
394
395/**
396 * Converts the dead line interval from TMCLOCK_VIRTUAL to host nano seconds.
397 *
398 * @returns Host nano second count.
399 * @param pVM The VM handle.
400 * @param cVirtTicksToDeadline The TMCLOCK_VIRTUAL interval.
401 */
402DECLINLINE(uint64_t) tmVirtualVirtToNsDeadline(PVM pVM, uint64_t cVirtTicksToDeadline)
403{
404 if (RT_UNLIKELY(pVM->tm.s.fVirtualWarpDrive))
405 return ASMMultU64ByU32DivByU32(cVirtTicksToDeadline, 100, pVM->tm.s.u32VirtualWarpDrivePercentage);
406 return cVirtTicksToDeadline;
407}
408
409
410/**
411 * tmVirtualSyncGetLocked worker for handling catch-up when owning the lock.
412 *
413 * @returns The timestamp.
414 * @param pVM VM handle.
415 * @param u64 raw virtual time.
416 * @param off offVirtualSync.
417 * @param pcNsToDeadline Where to return the number of nano seconds to
418 * the next virtual sync timer deadline. Can be
419 * NULL.
420 */
421DECLINLINE(uint64_t) tmVirtualSyncGetHandleCatchUpLocked(PVM pVM, uint64_t u64, uint64_t off, uint64_t *pcNsToDeadline)
422{
423 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetLocked);
424
425 /*
426 * Don't make updates until we've check the timer queue.
427 */
428 bool fUpdatePrev = true;
429 bool fUpdateOff = true;
430 bool fStop = false;
431 const uint64_t u64Prev = pVM->tm.s.u64VirtualSyncCatchUpPrev;
432 uint64_t u64Delta = u64 - u64Prev;
433 if (RT_LIKELY(!(u64Delta >> 32)))
434 {
435 uint64_t u64Sub = ASMMultU64ByU32DivByU32(u64Delta, pVM->tm.s.u32VirtualSyncCatchUpPercentage, 100);
436 if (off > u64Sub + pVM->tm.s.offVirtualSyncGivenUp)
437 {
438 off -= u64Sub;
439 Log4(("TM: %'RU64/-%'8RU64: sub %RU32 [vsghcul]\n", u64 - off, off - pVM->tm.s.offVirtualSyncGivenUp, u64Sub));
440 }
441 else
442 {
443 /* we've completely caught up. */
444 STAM_PROFILE_ADV_STOP(&pVM->tm.s.StatVirtualSyncCatchup, c);
445 off = pVM->tm.s.offVirtualSyncGivenUp;
446 fStop = true;
447 Log4(("TM: %'RU64/0: caught up [vsghcul]\n", u64));
448 }
449 }
450 else
451 {
452 /* More than 4 seconds since last time (or negative), ignore it. */
453 fUpdateOff = false;
454 fUpdatePrev = !(u64Delta & RT_BIT_64(63));
455 Log(("TMVirtualGetSync: u64Delta=%RX64\n", u64Delta));
456 }
457
458 /*
459 * Complete the calculation of the current TMCLOCK_VIRTUAL_SYNC time. The current
460 * approach is to never pass the head timer. So, when we do stop the clock and
461 * set the timer pending flag.
462 */
463 u64 -= off;
464 uint64_t u64Expire = ASMAtomicReadU64(&pVM->tm.s.CTX_SUFF(paTimerQueues)[TMCLOCK_VIRTUAL_SYNC].u64Expire);
465 if (u64 < u64Expire)
466 {
467 if (fUpdateOff)
468 ASMAtomicWriteU64(&pVM->tm.s.offVirtualSync, off);
469 if (fStop)
470 ASMAtomicWriteBool(&pVM->tm.s.fVirtualSyncCatchUp, false);
471 if (fUpdatePrev)
472 ASMAtomicWriteU64(&pVM->tm.s.u64VirtualSyncCatchUpPrev, u64);
473 if (pcNsToDeadline)
474 {
475 uint64_t cNsToDeadline = u64Expire - u64;
476 if (pVM->tm.s.fVirtualSyncCatchUp)
477 cNsToDeadline = ASMMultU64ByU32DivByU32(cNsToDeadline, 100,
478 pVM->tm.s.u32VirtualSyncCatchUpPercentage + 100);
479 *pcNsToDeadline = tmVirtualVirtToNsDeadline(pVM, cNsToDeadline);
480 }
481 tmVirtualSyncUnlock(pVM);
482 }
483 else
484 {
485 u64 = u64Expire;
486 ASMAtomicWriteU64(&pVM->tm.s.u64VirtualSync, u64);
487 ASMAtomicWriteBool(&pVM->tm.s.fVirtualSyncTicking, false);
488
489 VM_FF_SET(pVM, VM_FF_TM_VIRTUAL_SYNC);
490 PVMCPU pVCpuDst = &pVM->aCpus[pVM->tm.s.idTimerCpu];
491 VMCPU_FF_SET(pVCpuDst, VMCPU_FF_TIMER);
492 Log5(("TMAllVirtual(%u): FF: %d -> 1\n", __LINE__, VMCPU_FF_ISPENDING(pVCpuDst, VMCPU_FF_TIMER)));
493 Log4(("TM: %'RU64/-%'8RU64: exp tmr=>ff [vsghcul]\n", u64, pVM->tm.s.offVirtualSync - pVM->tm.s.offVirtualSyncGivenUp));
494 tmVirtualSyncUnlock(pVM);
495
496 if (pcNsToDeadline)
497 *pcNsToDeadline = 0;
498#ifdef IN_RING3
499 REMR3NotifyTimerPending(pVM, pVCpuDst);
500 VMR3NotifyCpuFFU(pVCpuDst->pUVCpu, VMNOTIFYFF_FLAGS_DONE_REM);
501#endif
502 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetSetFF);
503 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetExpired);
504 }
505 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetLocked);
506
507 Log6(("tmVirtualSyncGetHandleCatchUpLocked -> %'RU64\n", u64));
508 DBGFTRACE_U64_TAG(pVM, u64, "tmVirtualSyncGetHandleCatchUpLocked");
509 return u64;
510}
511
512
513/**
514 * tmVirtualSyncGetEx worker for when we get the lock.
515 *
516 * @returns timesamp.
517 * @param pVM The VM handle.
518 * @param u64 The virtual clock timestamp.
519 * @param pcNsToDeadline Where to return the number of nano seconds to
520 * the next virtual sync timer deadline. Can be
521 * NULL.
522 */
523DECLINLINE(uint64_t) tmVirtualSyncGetLocked(PVM pVM, uint64_t u64, uint64_t *pcNsToDeadline)
524{
525 /*
526 * Not ticking?
527 */
528 if (!pVM->tm.s.fVirtualSyncTicking)
529 {
530 u64 = ASMAtomicUoReadU64(&pVM->tm.s.u64VirtualSync);
531 tmVirtualSyncUnlock(pVM);
532 if (pcNsToDeadline)
533 *pcNsToDeadline = 0;
534 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetLocked);
535 Log6(("tmVirtualSyncGetLocked -> %'RU64 [stopped]\n", u64));
536 DBGFTRACE_U64_TAG(pVM, u64, "tmVirtualSyncGetLocked-stopped");
537 return u64;
538 }
539
540 /*
541 * Handle catch up in a separate function.
542 */
543 uint64_t off = ASMAtomicUoReadU64(&pVM->tm.s.offVirtualSync);
544 if (ASMAtomicUoReadBool(&pVM->tm.s.fVirtualSyncCatchUp))
545 return tmVirtualSyncGetHandleCatchUpLocked(pVM, u64, off, pcNsToDeadline);
546
547 /*
548 * Complete the calculation of the current TMCLOCK_VIRTUAL_SYNC time. The current
549 * approach is to never pass the head timer. So, when we do stop the clock and
550 * set the timer pending flag.
551 */
552 u64 -= off;
553 uint64_t u64Expire = ASMAtomicReadU64(&pVM->tm.s.CTX_SUFF(paTimerQueues)[TMCLOCK_VIRTUAL_SYNC].u64Expire);
554 if (u64 < u64Expire)
555 {
556 tmVirtualSyncUnlock(pVM);
557 if (pcNsToDeadline)
558 *pcNsToDeadline = tmVirtualVirtToNsDeadline(pVM, u64Expire - u64);
559 }
560 else
561 {
562 u64 = u64Expire;
563 ASMAtomicWriteU64(&pVM->tm.s.u64VirtualSync, u64);
564 ASMAtomicWriteBool(&pVM->tm.s.fVirtualSyncTicking, false);
565
566 VM_FF_SET(pVM, VM_FF_TM_VIRTUAL_SYNC);
567 PVMCPU pVCpuDst = &pVM->aCpus[pVM->tm.s.idTimerCpu];
568 VMCPU_FF_SET(pVCpuDst, VMCPU_FF_TIMER);
569 Log5(("TMAllVirtual(%u): FF: %d -> 1\n", __LINE__, !!VMCPU_FF_ISPENDING(pVCpuDst, VMCPU_FF_TIMER)));
570 Log4(("TM: %'RU64/-%'8RU64: exp tmr=>ff [vsgl]\n", u64, pVM->tm.s.offVirtualSync - pVM->tm.s.offVirtualSyncGivenUp));
571 tmVirtualSyncUnlock(pVM);
572
573#ifdef IN_RING3
574 REMR3NotifyTimerPending(pVM, pVCpuDst);
575 VMR3NotifyCpuFFU(pVCpuDst->pUVCpu, VMNOTIFYFF_FLAGS_DONE_REM);
576#endif
577 if (pcNsToDeadline)
578 *pcNsToDeadline = 0;
579 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetSetFF);
580 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetExpired);
581 }
582 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetLocked);
583 Log6(("tmVirtualSyncGetLocked -> %'RU64\n", u64));
584 DBGFTRACE_U64_TAG(pVM, u64, "tmVirtualSyncGetLocked");
585 return u64;
586}
587
588
589/**
590 * Gets the current TMCLOCK_VIRTUAL_SYNC time.
591 *
592 * @returns The timestamp.
593 * @param pVM VM handle.
594 * @param fCheckTimers Check timers or not
595 * @param pcNsToDeadline Where to return the number of nano seconds to
596 * the next virtual sync timer deadline. Can be
597 * NULL.
598 * @thread EMT.
599 */
600DECLINLINE(uint64_t) tmVirtualSyncGetEx(PVM pVM, bool fCheckTimers, uint64_t *pcNsToDeadline)
601{
602 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGet);
603
604 uint64_t u64;
605 if (!pVM->tm.s.fVirtualSyncTicking)
606 {
607 if (pcNsToDeadline)
608 *pcNsToDeadline = 0;
609 u64 = pVM->tm.s.u64VirtualSync;
610 DBGFTRACE_U64_TAG(pVM, u64, "tmVirtualSyncGetEx-stopped1");
611 return u64;
612 }
613
614 /*
615 * Query the virtual clock and do the usual expired timer check.
616 */
617 Assert(pVM->tm.s.cVirtualTicking);
618 u64 = tmVirtualGetRaw(pVM);
619 if (fCheckTimers)
620 {
621 PVMCPU pVCpuDst = &pVM->aCpus[pVM->tm.s.idTimerCpu];
622 if ( !VMCPU_FF_ISSET(pVCpuDst, VMCPU_FF_TIMER)
623 && pVM->tm.s.CTX_SUFF(paTimerQueues)[TMCLOCK_VIRTUAL].u64Expire <= u64)
624 {
625 Log5(("TMAllVirtual(%u): FF: 0 -> 1\n", __LINE__));
626 VMCPU_FF_SET(pVCpuDst, VMCPU_FF_TIMER);
627#ifdef IN_RING3
628 REMR3NotifyTimerPending(pVM, pVCpuDst);
629 VMR3NotifyCpuFFU(pVCpuDst->pUVCpu, VMNOTIFYFF_FLAGS_DONE_REM /** @todo |VMNOTIFYFF_FLAGS_POKE*/);
630#endif
631 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetSetFF);
632 }
633 }
634
635 /*
636 * When the clock is ticking, not doing catch ups and not running into an
637 * expired time, we can get away without locking. Try this first.
638 */
639 uint64_t off;
640 if (ASMAtomicUoReadBool(&pVM->tm.s.fVirtualSyncTicking))
641 {
642 if (!ASMAtomicUoReadBool(&pVM->tm.s.fVirtualSyncCatchUp))
643 {
644 off = ASMAtomicReadU64(&pVM->tm.s.offVirtualSync);
645 if (RT_LIKELY( ASMAtomicUoReadBool(&pVM->tm.s.fVirtualSyncTicking)
646 && !ASMAtomicUoReadBool(&pVM->tm.s.fVirtualSyncCatchUp)
647 && off == ASMAtomicReadU64(&pVM->tm.s.offVirtualSync)))
648 {
649 off = u64 - off;
650 uint64_t const u64Expire = ASMAtomicReadU64(&pVM->tm.s.CTX_SUFF(paTimerQueues)[TMCLOCK_VIRTUAL_SYNC].u64Expire);
651 if (off < u64Expire)
652 {
653 if (pcNsToDeadline)
654 *pcNsToDeadline = tmVirtualVirtToNsDeadline(pVM, u64Expire - off);
655 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetLockless);
656 Log6(("tmVirtualSyncGetEx -> %'RU64 [lockless]\n", off));
657 DBGFTRACE_U64_TAG(pVM, off, "tmVirtualSyncGetEx-lockless");
658 return off;
659 }
660 }
661 }
662 }
663 else
664 {
665 off = ASMAtomicReadU64(&pVM->tm.s.u64VirtualSync);
666 if (RT_LIKELY(!ASMAtomicReadBool(&pVM->tm.s.fVirtualSyncTicking)))
667 {
668 if (pcNsToDeadline)
669 *pcNsToDeadline = 0;
670 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetLockless);
671 Log6(("tmVirtualSyncGetEx -> %'RU64 [lockless/stopped]\n", off));
672 DBGFTRACE_U64_TAG(pVM, off, "tmVirtualSyncGetEx-stopped2");
673 return off;
674 }
675 }
676
677 /*
678 * Read the offset and adjust if we're playing catch-up.
679 *
680 * The catch-up adjusting work by us decrementing the offset by a percentage of
681 * the time elapsed since the previous TMVirtualGetSync call.
682 *
683 * It's possible to get a very long or even negative interval between two read
684 * for the following reasons:
685 * - Someone might have suspended the process execution, frequently the case when
686 * debugging the process.
687 * - We might be on a different CPU which TSC isn't quite in sync with the
688 * other CPUs in the system.
689 * - Another thread is racing us and we might have been preempted while inside
690 * this function.
691 *
692 * Assuming nano second virtual time, we can simply ignore any intervals which has
693 * any of the upper 32 bits set.
694 */
695 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000);
696 int cOuterTries = 42;
697 for (;; cOuterTries--)
698 {
699 /* Try grab the lock, things get simpler when owning the lock. */
700 int rcLock = tmVirtualSyncTryLock(pVM);
701 if (RT_SUCCESS_NP(rcLock))
702 return tmVirtualSyncGetLocked(pVM, u64, pcNsToDeadline);
703
704 /* Re-check the ticking flag. */
705 if (!ASMAtomicReadBool(&pVM->tm.s.fVirtualSyncTicking))
706 {
707 off = ASMAtomicReadU64(&pVM->tm.s.u64VirtualSync);
708 if ( ASMAtomicReadBool(&pVM->tm.s.fVirtualSyncTicking)
709 && cOuterTries > 0)
710 continue;
711 if (pcNsToDeadline)
712 *pcNsToDeadline = 0;
713 Log6(("tmVirtualSyncGetEx -> %'RU64 [stopped]\n", off));
714 DBGFTRACE_U64_TAG(pVM, off, "tmVirtualSyncGetEx-stopped3");
715 return off;
716 }
717
718 off = ASMAtomicReadU64(&pVM->tm.s.offVirtualSync);
719 if (ASMAtomicReadBool(&pVM->tm.s.fVirtualSyncCatchUp))
720 {
721 /* No changes allowed, try get a consistent set of parameters. */
722 uint64_t const u64Prev = ASMAtomicReadU64(&pVM->tm.s.u64VirtualSyncCatchUpPrev);
723 uint64_t const offGivenUp = ASMAtomicReadU64(&pVM->tm.s.offVirtualSyncGivenUp);
724 uint32_t const u32Pct = ASMAtomicReadU32(&pVM->tm.s.u32VirtualSyncCatchUpPercentage);
725 if ( ( u64Prev == ASMAtomicReadU64(&pVM->tm.s.u64VirtualSyncCatchUpPrev)
726 && offGivenUp == ASMAtomicReadU64(&pVM->tm.s.offVirtualSyncGivenUp)
727 && u32Pct == ASMAtomicReadU32(&pVM->tm.s.u32VirtualSyncCatchUpPercentage)
728 && ASMAtomicReadBool(&pVM->tm.s.fVirtualSyncCatchUp))
729 || cOuterTries <= 0)
730 {
731 uint64_t u64Delta = u64 - u64Prev;
732 if (RT_LIKELY(!(u64Delta >> 32)))
733 {
734 uint64_t u64Sub = ASMMultU64ByU32DivByU32(u64Delta, u32Pct, 100);
735 if (off > u64Sub + offGivenUp)
736 {
737 off -= u64Sub;
738 Log4(("TM: %'RU64/-%'8RU64: sub %RU32 [NoLock]\n", u64 - off, pVM->tm.s.offVirtualSync - offGivenUp, u64Sub));
739 }
740 else
741 {
742 /* we've completely caught up. */
743 STAM_PROFILE_ADV_STOP(&pVM->tm.s.StatVirtualSyncCatchup, c);
744 off = offGivenUp;
745 Log4(("TM: %'RU64/0: caught up [NoLock]\n", u64));
746 }
747 }
748 else
749 /* More than 4 seconds since last time (or negative), ignore it. */
750 Log(("TMVirtualGetSync: u64Delta=%RX64 (NoLock)\n", u64Delta));
751
752 /* Check that we're still running and in catch up. */
753 if ( ASMAtomicUoReadBool(&pVM->tm.s.fVirtualSyncTicking)
754 && ASMAtomicReadBool(&pVM->tm.s.fVirtualSyncCatchUp))
755 break;
756 if (cOuterTries <= 0)
757 break; /* enough */
758 }
759 }
760 else if ( off == ASMAtomicReadU64(&pVM->tm.s.offVirtualSync)
761 && !ASMAtomicReadBool(&pVM->tm.s.fVirtualSyncCatchUp))
762 break; /* Got an consistent offset */
763 else if (cOuterTries <= 0)
764 break; /* enough */
765 }
766 if (cOuterTries <= 0)
767 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetELoop);
768
769 /*
770 * Complete the calculation of the current TMCLOCK_VIRTUAL_SYNC time. The current
771 * approach is to never pass the head timer. So, when we do stop the clock and
772 * set the timer pending flag.
773 */
774 u64 -= off;
775 uint64_t u64Expire = ASMAtomicReadU64(&pVM->tm.s.CTX_SUFF(paTimerQueues)[TMCLOCK_VIRTUAL_SYNC].u64Expire);
776 if (u64 >= u64Expire)
777 {
778 PVMCPU pVCpuDst = &pVM->aCpus[pVM->tm.s.idTimerCpu];
779 if (!VMCPU_FF_ISSET(pVCpuDst, VMCPU_FF_TIMER))
780 {
781 Log5(("TMAllVirtual(%u): FF: %d -> 1 (NoLock)\n", __LINE__, VMCPU_FF_ISPENDING(pVCpuDst, VMCPU_FF_TIMER)));
782 VM_FF_SET(pVM, VM_FF_TM_VIRTUAL_SYNC); /* Hmm? */
783 VMCPU_FF_SET(pVCpuDst, VMCPU_FF_TIMER);
784#ifdef IN_RING3
785 REMR3NotifyTimerPending(pVM, pVCpuDst);
786 VMR3NotifyCpuFFU(pVCpuDst->pUVCpu, VMNOTIFYFF_FLAGS_DONE_REM);
787#endif
788 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetSetFF);
789 Log4(("TM: %'RU64/-%'8RU64: exp tmr=>ff [NoLock]\n", u64, pVM->tm.s.offVirtualSync - pVM->tm.s.offVirtualSyncGivenUp));
790 }
791 else
792 Log4(("TM: %'RU64/-%'8RU64: exp tmr [NoLock]\n", u64, pVM->tm.s.offVirtualSync - pVM->tm.s.offVirtualSyncGivenUp));
793 if (pcNsToDeadline)
794 *pcNsToDeadline = 0;
795 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualSyncGetExpired);
796 }
797 else if (pcNsToDeadline)
798 {
799 uint64_t cNsToDeadline = u64Expire - u64;
800 if (ASMAtomicReadBool(&pVM->tm.s.fVirtualSyncCatchUp))
801 cNsToDeadline = ASMMultU64ByU32DivByU32(cNsToDeadline, 100,
802 ASMAtomicReadU32(&pVM->tm.s.u32VirtualSyncCatchUpPercentage) + 100);
803 *pcNsToDeadline = tmVirtualVirtToNsDeadline(pVM, cNsToDeadline);
804 }
805
806 Log6(("tmVirtualSyncGetEx -> %'RU64\n", u64));
807 DBGFTRACE_U64_TAG(pVM, u64, "tmVirtualSyncGetEx-nolock");
808 return u64;
809}
810
811
812/**
813 * Gets the current TMCLOCK_VIRTUAL_SYNC time.
814 *
815 * @returns The timestamp.
816 * @param pVM VM handle.
817 * @thread EMT.
818 * @remarks May set the timer and virtual sync FFs.
819 */
820VMM_INT_DECL(uint64_t) TMVirtualSyncGet(PVM pVM)
821{
822 return tmVirtualSyncGetEx(pVM, true /*fCheckTimers*/, NULL /*pcNsToDeadline*/);
823}
824
825
826/**
827 * Gets the current TMCLOCK_VIRTUAL_SYNC time without checking timers running on
828 * TMCLOCK_VIRTUAL.
829 *
830 * @returns The timestamp.
831 * @param pVM VM handle.
832 * @thread EMT.
833 * @remarks May set the timer and virtual sync FFs.
834 */
835VMM_INT_DECL(uint64_t) TMVirtualSyncGetNoCheck(PVM pVM)
836{
837 return tmVirtualSyncGetEx(pVM, false /*fCheckTimers*/, NULL /*pcNsToDeadline*/);
838}
839
840
841/**
842 * Gets the current TMCLOCK_VIRTUAL_SYNC time.
843 *
844 * @returns The timestamp.
845 * @param pVM VM handle.
846 * @param fCheckTimers Check timers on the virtual clock or not.
847 * @thread EMT.
848 * @remarks May set the timer and virtual sync FFs.
849 */
850VMM_INT_DECL(uint64_t) TMVirtualSyncGetEx(PVM pVM, bool fCheckTimers)
851{
852 return tmVirtualSyncGetEx(pVM, fCheckTimers, NULL /*pcNsToDeadline*/);
853}
854
855
856/**
857 * Gets the current TMCLOCK_VIRTUAL_SYNC time and ticks to the next deadline
858 * without checking timers running on TMCLOCK_VIRTUAL.
859 *
860 * @returns The timestamp.
861 * @param pVM VM handle.
862 * @param pcNsToDeadline Where to return the number of nano seconds to
863 * the next virtual sync timer deadline.
864 * @thread EMT.
865 * @remarks May set the timer and virtual sync FFs.
866 */
867VMM_INT_DECL(uint64_t) TMVirtualSyncGetWithDeadlineNoCheck(PVM pVM, uint64_t *pcNsToDeadline)
868{
869 uint64_t cNsToDeadlineTmp; /* try convince the compiler to skip the if tests. */
870 uint64_t u64Now = tmVirtualSyncGetEx(pVM, false /*fCheckTimers*/, &cNsToDeadlineTmp);
871 *pcNsToDeadline = cNsToDeadlineTmp;
872 return u64Now;
873}
874
875
876/**
877 * Gets the number of nano seconds to the next virtual sync deadline.
878 *
879 * @returns The number of TMCLOCK_VIRTUAL ticks.
880 * @param pVM VM handle.
881 * @thread EMT.
882 * @remarks May set the timer and virtual sync FFs.
883 */
884VMM_INT_DECL(uint64_t) TMVirtualSyncGetNsToDeadline(PVM pVM)
885{
886 uint64_t cNsToDeadline;
887 tmVirtualSyncGetEx(pVM, false /*fCheckTimers*/, &cNsToDeadline);
888 return cNsToDeadline;
889}
890
891
892/**
893 * Gets the current lag of the synchronous virtual clock (relative to the virtual clock).
894 *
895 * @return The current lag.
896 * @param pVM VM handle.
897 */
898VMM_INT_DECL(uint64_t) TMVirtualSyncGetLag(PVM pVM)
899{
900 return pVM->tm.s.offVirtualSync - pVM->tm.s.offVirtualSyncGivenUp;
901}
902
903
904/**
905 * Get the current catch-up percent.
906 *
907 * @return The current catch0up percent. 0 means running at the same speed as the virtual clock.
908 * @param pVM VM handle.
909 */
910VMM_INT_DECL(uint32_t) TMVirtualSyncGetCatchUpPct(PVM pVM)
911{
912 if (pVM->tm.s.fVirtualSyncCatchUp)
913 return pVM->tm.s.u32VirtualSyncCatchUpPercentage;
914 return 0;
915}
916
917
918/**
919 * Gets the current TMCLOCK_VIRTUAL frequency.
920 *
921 * @returns The frequency.
922 * @param pVM VM handle.
923 */
924VMM_INT_DECL(uint64_t) TMVirtualGetFreq(PVM pVM)
925{
926 return TMCLOCK_FREQ_VIRTUAL;
927}
928
929
930/**
931 * Worker for TMR3PauseClocks.
932 *
933 * @returns VINF_SUCCESS or VERR_INTERNAL_ERROR (asserted).
934 * @param pVM The VM handle.
935 */
936int tmVirtualPauseLocked(PVM pVM)
937{
938 uint32_t c = ASMAtomicDecU32(&pVM->tm.s.cVirtualTicking);
939 AssertMsgReturn(c < pVM->cCpus, ("%u vs %u\n", c, pVM->cCpus), VERR_INTERNAL_ERROR);
940 if (c == 0)
941 {
942 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualPause);
943 pVM->tm.s.u64Virtual = tmVirtualGetRaw(pVM);
944 ASMAtomicWriteBool(&pVM->tm.s.fVirtualSyncTicking, false);
945 }
946 return VINF_SUCCESS;
947}
948
949
950/**
951 * Worker for TMR3ResumeClocks.
952 *
953 * @returns VINF_SUCCESS or VERR_INTERNAL_ERROR (asserted).
954 * @param pVM The VM handle.
955 */
956int tmVirtualResumeLocked(PVM pVM)
957{
958 uint32_t c = ASMAtomicIncU32(&pVM->tm.s.cVirtualTicking);
959 AssertMsgReturn(c <= pVM->cCpus, ("%u vs %u\n", c, pVM->cCpus), VERR_INTERNAL_ERROR);
960 if (c == 1)
961 {
962 STAM_COUNTER_INC(&pVM->tm.s.StatVirtualResume);
963 pVM->tm.s.u64VirtualRawPrev = 0;
964 pVM->tm.s.u64VirtualWarpDriveStart = tmVirtualGetRawNanoTS(pVM);
965 pVM->tm.s.u64VirtualOffset = pVM->tm.s.u64VirtualWarpDriveStart - pVM->tm.s.u64Virtual;
966 ASMAtomicWriteBool(&pVM->tm.s.fVirtualSyncTicking, true);
967 }
968 return VINF_SUCCESS;
969}
970
971
972/**
973 * Converts from virtual ticks to nanoseconds.
974 *
975 * @returns nanoseconds.
976 * @param pVM The VM handle.
977 * @param u64VirtualTicks The virtual ticks to convert.
978 * @remark There could be rounding errors here. We just do a simple integer divide
979 * without any adjustments.
980 */
981VMM_INT_DECL(uint64_t) TMVirtualToNano(PVM pVM, uint64_t u64VirtualTicks)
982{
983 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000);
984 return u64VirtualTicks;
985}
986
987
988/**
989 * Converts from virtual ticks to microseconds.
990 *
991 * @returns microseconds.
992 * @param pVM The VM handle.
993 * @param u64VirtualTicks The virtual ticks to convert.
994 * @remark There could be rounding errors here. We just do a simple integer divide
995 * without any adjustments.
996 */
997VMM_INT_DECL(uint64_t) TMVirtualToMicro(PVM pVM, uint64_t u64VirtualTicks)
998{
999 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000);
1000 return u64VirtualTicks / 1000;
1001}
1002
1003
1004/**
1005 * Converts from virtual ticks to milliseconds.
1006 *
1007 * @returns milliseconds.
1008 * @param pVM The VM handle.
1009 * @param u64VirtualTicks The virtual ticks to convert.
1010 * @remark There could be rounding errors here. We just do a simple integer divide
1011 * without any adjustments.
1012 */
1013VMM_INT_DECL(uint64_t) TMVirtualToMilli(PVM pVM, uint64_t u64VirtualTicks)
1014{
1015 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000);
1016 return u64VirtualTicks / 1000000;
1017}
1018
1019
1020/**
1021 * Converts from nanoseconds to virtual ticks.
1022 *
1023 * @returns virtual ticks.
1024 * @param pVM The VM handle.
1025 * @param u64NanoTS The nanosecond value ticks to convert.
1026 * @remark There could be rounding and overflow errors here.
1027 */
1028VMM_INT_DECL(uint64_t) TMVirtualFromNano(PVM pVM, uint64_t u64NanoTS)
1029{
1030 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000);
1031 return u64NanoTS;
1032}
1033
1034
1035/**
1036 * Converts from microseconds to virtual ticks.
1037 *
1038 * @returns virtual ticks.
1039 * @param pVM The VM handle.
1040 * @param u64MicroTS The microsecond value ticks to convert.
1041 * @remark There could be rounding and overflow errors here.
1042 */
1043VMM_INT_DECL(uint64_t) TMVirtualFromMicro(PVM pVM, uint64_t u64MicroTS)
1044{
1045 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000);
1046 return u64MicroTS * 1000;
1047}
1048
1049
1050/**
1051 * Converts from milliseconds to virtual ticks.
1052 *
1053 * @returns virtual ticks.
1054 * @param pVM The VM handle.
1055 * @param u64MilliTS The millisecond value ticks to convert.
1056 * @remark There could be rounding and overflow errors here.
1057 */
1058VMM_INT_DECL(uint64_t) TMVirtualFromMilli(PVM pVM, uint64_t u64MilliTS)
1059{
1060 AssertCompile(TMCLOCK_FREQ_VIRTUAL == 1000000000);
1061 return u64MilliTS * 1000000;
1062}
1063
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