VirtualBox

source: vbox/trunk/src/VBox/VMM/TMInternal.h@ 20050

Last change on this file since 20050 was 20050, checked in by vboxsync, 16 years ago

TM: new state and more logging (gee).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 23.1 KB
Line 
1/* $Id: TMInternal.h 20050 2009-05-26 17:12:12Z vboxsync $ */
2/** @file
3 * TM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef ___TMInternal_h
23#define ___TMInternal_h
24
25#include <VBox/cdefs.h>
26#include <VBox/types.h>
27#include <iprt/time.h>
28#include <iprt/timer.h>
29#include <iprt/assert.h>
30#include <VBox/stam.h>
31#include <VBox/pdmcritsect.h>
32
33__BEGIN_DECLS
34
35
36/** @defgroup grp_tm_int Internal
37 * @ingroup grp_tm
38 * @internal
39 * @{
40 */
41
42/** Frequency of the real clock. */
43#define TMCLOCK_FREQ_REAL UINT32_C(1000)
44/** Frequency of the virtual clock. */
45#define TMCLOCK_FREQ_VIRTUAL UINT32_C(1000000000)
46
47
48/**
49 * Timer type.
50 */
51typedef enum TMTIMERTYPE
52{
53 /** Device timer. */
54 TMTIMERTYPE_DEV = 1,
55 /** Driver timer. */
56 TMTIMERTYPE_DRV,
57 /** Internal timer . */
58 TMTIMERTYPE_INTERNAL,
59 /** External timer. */
60 TMTIMERTYPE_EXTERNAL
61} TMTIMERTYPE;
62
63/**
64 * Timer state
65 */
66typedef enum TMTIMERSTATE
67{
68 /** Timer is stopped. */
69 TMTIMERSTATE_STOPPED = 1,
70 /** Timer is active. */
71 TMTIMERSTATE_ACTIVE,
72 /** Timer is expired, getting expire and unlinking. */
73 TMTIMERSTATE_EXPIRED_GET_UNLINK,
74 /** Timer is expired and is being delivered. */
75 TMTIMERSTATE_EXPIRED_DELIVER,
76
77 /** Timer is stopped but still in the active list.
78 * Currently in the ScheduleTimers list. */
79 TMTIMERSTATE_PENDING_STOP,
80 /** Timer is stopped but needs unlinking from the ScheduleTimers list.
81 * Currently in the ScheduleTimers list. */
82 TMTIMERSTATE_PENDING_STOP_SCHEDULE,
83 /** Timer is being modified and will soon be pending scheduling.
84 * Currently in the ScheduleTimers list. */
85 TMTIMERSTATE_PENDING_SCHEDULE_SET_EXPIRE,
86 /** Timer is pending scheduling.
87 * Currently in the ScheduleTimers list. */
88 TMTIMERSTATE_PENDING_SCHEDULE,
89 /** Timer is being modified and will soon be pending rescheduling.
90 * Currently in the ScheduleTimers list and the active list. */
91 TMTIMERSTATE_PENDING_RESCHEDULE_SET_EXPIRE,
92 /** Timer is modified and is now pending rescheduling.
93 * Currently in the ScheduleTimers list and the active list. */
94 TMTIMERSTATE_PENDING_RESCHEDULE,
95 /** Timer is being destroyed. */
96 TMTIMERSTATE_DESTROY,
97 /** Timer is free. */
98 TMTIMERSTATE_FREE
99} TMTIMERSTATE;
100
101/** Predicate that returns true if the give state is pending scheduling or
102 * rescheduling of any kind. Will reference the argument more than once! */
103#define TMTIMERSTATE_IS_PENDING_SCHEDULING(enmState) \
104 ( (enmState) <= TMTIMERSTATE_PENDING_RESCHEDULE \
105 && (enmState) >= TMTIMERSTATE_PENDING_SCHEDULE_SET_EXPIRE)
106
107
108/**
109 * Internal representation of a timer.
110 *
111 * For correct serialization (without the use of semaphores and
112 * other blocking/slow constructs) certain rules applies to updating
113 * this structure:
114 * - For thread other than EMT only u64Expire, enmState and pScheduleNext*
115 * are changeable. Everything else is out of bounds.
116 * - Updating of u64Expire timer can only happen in the TMTIMERSTATE_STOPPED
117 * and TMTIMERSTATE_PENDING_RESCHEDULING_SET_EXPIRE states.
118 * - Timers in the TMTIMERSTATE_EXPIRED state are only accessible from EMT.
119 * - Actual destruction of a timer can only be done at scheduling time.
120 */
121typedef struct TMTIMER
122{
123 /** Expire time. */
124 volatile uint64_t u64Expire;
125 /** Clock to apply to u64Expire. */
126 TMCLOCK enmClock;
127 /** Timer callback type. */
128 TMTIMERTYPE enmType;
129 /** Type specific data. */
130 union
131 {
132 /** TMTIMERTYPE_DEV. */
133 struct
134 {
135 /** Callback. */
136 R3PTRTYPE(PFNTMTIMERDEV) pfnTimer;
137 /** Device instance. */
138 PPDMDEVINSR3 pDevIns;
139 } Dev;
140
141 /** TMTIMERTYPE_DRV. */
142 struct
143 {
144 /** Callback. */
145 R3PTRTYPE(PFNTMTIMERDRV) pfnTimer;
146 /** Device instance. */
147 R3PTRTYPE(PPDMDRVINS) pDrvIns;
148 } Drv;
149
150 /** TMTIMERTYPE_INTERNAL. */
151 struct
152 {
153 /** Callback. */
154 R3PTRTYPE(PFNTMTIMERINT) pfnTimer;
155 /** User argument. */
156 RTR3PTR pvUser;
157 } Internal;
158
159 /** TMTIMERTYPE_EXTERNAL. */
160 struct
161 {
162 /** Callback. */
163 R3PTRTYPE(PFNTMTIMEREXT) pfnTimer;
164 /** User data. */
165 RTR3PTR pvUser;
166 } External;
167 } u;
168
169 /** Timer state. */
170 volatile TMTIMERSTATE enmState;
171 /** Timer relative offset to the next timer in the schedule list. */
172 int32_t volatile offScheduleNext;
173
174 /** Timer relative offset to the next timer in the chain. */
175 int32_t offNext;
176 /** Timer relative offset to the previous timer in the chain. */
177 int32_t offPrev;
178
179 /** Pointer to the next timer in the list of created or free timers. (TM::pTimers or TM::pFree) */
180 PTMTIMERR3 pBigNext;
181 /** Pointer to the previous timer in the list of all created timers. (TM::pTimers) */
182 PTMTIMERR3 pBigPrev;
183 /** Pointer to the timer description. */
184 R3PTRTYPE(const char *) pszDesc;
185 /** Pointer to the VM the timer belongs to - R3 Ptr. */
186 PVMR3 pVMR3;
187 /** Pointer to the VM the timer belongs to - R0 Ptr. */
188 PVMR0 pVMR0;
189 /** Pointer to the VM the timer belongs to - RC Ptr. */
190 PVMRC pVMRC;
191#if HC_ARCH_BITS == 64
192 RTRCPTR padding0; /**< pad structure to multiple of 8 bytes. */
193#endif
194} TMTIMER;
195AssertCompileMemberSize(TMTIMER, enmState, sizeof(uint32_t));
196
197
198/**
199 * Updates a timer state in the correct atomic manner.
200 */
201#if 1
202# define TM_SET_STATE(pTimer, state) \
203 ASMAtomicWriteU32((uint32_t volatile *)&(pTimer)->enmState, state)
204#else
205# define TM_SET_STATE(pTimer, state) \
206 do { \
207 uint32_t uOld1 = (pTimer)->enmState; \
208 Log(("%s: %p: %d -> %d\n", __FUNCTION__, (pTimer), (pTimer)->enmState, state)); \
209 uint32_t uOld2 = ASMAtomicXchgU32((uint32_t volatile *)&(pTimer)->enmState, state); \
210 Assert(uOld1 == uOld2); \
211 } while (0)
212#endif
213
214/**
215 * Tries to updates a timer state in the correct atomic manner.
216 */
217#if 1
218# define TM_TRY_SET_STATE(pTimer, StateNew, StateOld, fRc) \
219 (fRc) = ASMAtomicCmpXchgU32((uint32_t volatile *)&(pTimer)->enmState, StateNew, StateOld)
220#else
221# define TM_TRY_SET_STATE(pTimer, StateNew, StateOld, fRc) \
222 do { (fRc) = ASMAtomicCmpXchgU32((uint32_t volatile *)&(pTimer)->enmState, StateNew, StateOld); \
223 Log(("%s: %p: %d -> %d %RTbool\n", __FUNCTION__, (pTimer), StateOld, StateNew, fRc)); \
224 } while (0)
225#endif
226
227/** Get the previous timer. */
228#define TMTIMER_GET_PREV(pTimer) ((PTMTIMER)((pTimer)->offPrev ? (intptr_t)(pTimer) + (pTimer)->offPrev : 0))
229/** Get the next timer. */
230#define TMTIMER_GET_NEXT(pTimer) ((PTMTIMER)((pTimer)->offNext ? (intptr_t)(pTimer) + (pTimer)->offNext : 0))
231/** Set the previous timer link. */
232#define TMTIMER_SET_PREV(pTimer, pPrev) ((pTimer)->offPrev = (pPrev) ? (intptr_t)(pPrev) - (intptr_t)(pTimer) : 0)
233/** Set the next timer link. */
234#define TMTIMER_SET_NEXT(pTimer, pNext) ((pTimer)->offNext = (pNext) ? (intptr_t)(pNext) - (intptr_t)(pTimer) : 0)
235
236
237/**
238 * A timer queue.
239 *
240 * This is allocated on the hyper heap.
241 */
242typedef struct TMTIMERQUEUE
243{
244 /** The cached expire time for this queue.
245 * Updated by EMT when scheduling the queue or modifying the head timer.
246 * Assigned UINT64_MAX when there is no head timer. */
247 uint64_t u64Expire;
248 /** Doubly linked list of active timers.
249 *
250 * When no scheduling is pending, this list is will be ordered by expire time (ascending).
251 * Access is serialized by only letting the emulation thread (EMT) do changes.
252 *
253 * The offset is relative to the queue structure.
254 */
255 int32_t offActive;
256 /** List of timers pending scheduling of some kind.
257 *
258 * Timer stats allowed in the list are TMTIMERSTATE_PENDING_STOPPING,
259 * TMTIMERSTATE_PENDING_DESTRUCTION, TMTIMERSTATE_PENDING_STOPPING_DESTRUCTION,
260 * TMTIMERSTATE_PENDING_RESCHEDULING and TMTIMERSTATE_PENDING_SCHEDULE.
261 *
262 * The offset is relative to the queue structure.
263 */
264 int32_t volatile offSchedule;
265 /** The clock for this queue. */
266 TMCLOCK enmClock;
267 /** Pad the structure up to 32 bytes. */
268 uint32_t au32Padding[3];
269} TMTIMERQUEUE;
270
271/** Pointer to a timer queue. */
272typedef TMTIMERQUEUE *PTMTIMERQUEUE;
273
274/** Get the head of the active timer list. */
275#define TMTIMER_GET_HEAD(pQueue) ((PTMTIMER)((pQueue)->offActive ? (intptr_t)(pQueue) + (pQueue)->offActive : 0))
276/** Set the head of the active timer list. */
277#define TMTIMER_SET_HEAD(pQueue, pHead) ((pQueue)->offActive = pHead ? (intptr_t)pHead - (intptr_t)(pQueue) : 0)
278
279
280/**
281 * Converts a TM pointer into a VM pointer.
282 * @returns Pointer to the VM structure the TM is part of.
283 * @param pTM Pointer to TM instance data.
284 */
285#define TM2VM(pTM) ( (PVM)((char*)pTM - pTM->offVM) )
286
287
288/**
289 * TM VM Instance data.
290 * Changes to this must checked against the padding of the cfgm union in VM!
291 */
292typedef struct TM
293{
294 /** Offset to the VM structure.
295 * See TM2VM(). */
296 RTUINT offVM;
297
298 /** Set if we fully virtualize the TSC, i.e. intercept all rdtsc instructions.
299 * Config variable: TSCVirtualized (bool) */
300 bool fTSCVirtualized;
301 /** Set if we use the real TSC as time source or if we use the virtual clock.
302 * If fTSCVirtualized is set we maintain a offset to the TSC and pausing/resuming the
303 * ticking. fTSCVirtualized = false implies fTSCUseRealTSC = true.
304 * Config variable: TSCUseRealTSC (bool) */
305 bool fTSCUseRealTSC;
306 /** Flag indicating that the host TSC is suitable for use in AMD-V and VT-x mode.
307 * Config variable: MaybeUseOffsettedHostTSC (boolean) */
308 bool fMaybeUseOffsettedHostTSC;
309 /** Whether the TSC is tied to the execution of code.
310 * Config variable: TSCTiedToExecution (bool) */
311 bool fTSCTiedToExecution;
312 /** Modifier for fTSCTiedToExecution which pauses the TSC while halting if true.
313 * Config variable: TSCNotTiedToHalt (bool) */
314 bool fTSCNotTiedToHalt;
315 bool afAlignment0[2]; /**< alignment padding */
316 /** The ID of the virtual CPU that normally runs the timers. */
317 VMCPUID idTimerCpu;
318 /** The number of CPU clock ticks per second (TMCLOCK_TSC).
319 * Config variable: TSCTicksPerSecond (64-bit unsigned int)
320 * The config variable implies fTSCVirtualized = true and fTSCUseRealTSC = false. */
321 uint64_t cTSCTicksPerSecond;
322
323 /** Virtual time ticking enabled indicator (counter for each VCPU). (TMCLOCK_VIRTUAL) */
324 uint32_t volatile cVirtualTicking;
325 /** Virtual time is not running at 100%. */
326 bool fVirtualWarpDrive;
327 /** Virtual timer synchronous time ticking enabled indicator (bool). (TMCLOCK_VIRTUAL_SYNC) */
328 bool volatile fVirtualSyncTicking;
329 /** Virtual timer synchronous time catch-up active. */
330 bool volatile fVirtualSyncCatchUp;
331 bool afAlignment[5]; /**< alignment padding */
332 /** WarpDrive percentage.
333 * 100% is normal (fVirtualSyncNormal == true). When other than 100% we apply
334 * this percentage to the raw time source for the period it's been valid in,
335 * i.e. since u64VirtualWarpDriveStart. */
336 uint32_t u32VirtualWarpDrivePercentage;
337
338 /** The offset of the virtual clock relative to it's timesource.
339 * Only valid if fVirtualTicking is set. */
340 uint64_t u64VirtualOffset;
341 /** The guest virtual time when fVirtualTicking is cleared. */
342 uint64_t u64Virtual;
343 /** When the Warp drive was started or last adjusted.
344 * Only valid when fVirtualWarpDrive is set. */
345 uint64_t u64VirtualWarpDriveStart;
346 /** The previously returned nano TS.
347 * This handles TSC drift on SMP systems and expired interval.
348 * This is a valid range u64NanoTS to u64NanoTS + 1000000000 (ie. 1sec). */
349 uint64_t volatile u64VirtualRawPrev;
350 /** The ring-3 data structure for the RTTimeNanoTS workers used by tmVirtualGetRawNanoTS. */
351 RTTIMENANOTSDATAR3 VirtualGetRawDataR3;
352 /** The ring-0 data structure for the RTTimeNanoTS workers used by tmVirtualGetRawNanoTS. */
353 RTTIMENANOTSDATAR0 VirtualGetRawDataR0;
354 /** The ring-0 data structure for the RTTimeNanoTS workers used by tmVirtualGetRawNanoTS. */
355 RTTIMENANOTSDATARC VirtualGetRawDataRC;
356 /** Pointer to the ring-3 tmVirtualGetRawNanoTS worker function. */
357 R3PTRTYPE(PFNTIMENANOTSINTERNAL) pfnVirtualGetRawR3;
358 /** Pointer to the ring-3 tmVirtualGetRawNanoTS worker function. */
359 R0PTRTYPE(PFNTIMENANOTSINTERNAL) pfnVirtualGetRawR0;
360 /** Pointer to the ring-3 tmVirtualGetRawNanoTS worker function. */
361 RCPTRTYPE(PFNTIMENANOTSINTERNAL) pfnVirtualGetRawRC;
362 /** Alignment. */
363 RTRCPTR AlignmentRCPtr;
364 /** The guest virtual timer synchronous time when fVirtualSyncTicking is cleared. */
365 uint64_t volatile u64VirtualSync;
366 /** The offset of the timer synchronous virtual clock (TMCLOCK_VIRTUAL_SYNC) relative
367 * to the virtual clock (TMCLOCK_VIRTUAL).
368 * (This is accessed by the timer thread and must be updated atomically.) */
369 uint64_t volatile offVirtualSync;
370 /** The offset into offVirtualSync that's been irrevocably given up by failed catch-up attempts.
371 * Thus the current lag is offVirtualSync - offVirtualSyncGivenUp. */
372 uint64_t offVirtualSyncGivenUp;
373 /** The TMCLOCK_VIRTUAL at the previous TMVirtualGetSync call when catch-up is active. */
374 uint64_t volatile u64VirtualSyncCatchUpPrev;
375 /** The current catch-up percentage. */
376 uint32_t volatile u32VirtualSyncCatchUpPercentage;
377 /** How much slack when processing timers. */
378 uint32_t u32VirtualSyncScheduleSlack;
379 /** When to stop catch-up. */
380 uint64_t u64VirtualSyncCatchUpStopThreshold;
381 /** When to give up catch-up. */
382 uint64_t u64VirtualSyncCatchUpGiveUpThreshold;
383/** @def TM_MAX_CATCHUP_PERIODS
384 * The number of catchup rates. */
385#define TM_MAX_CATCHUP_PERIODS 10
386 /** The agressivness of the catch-up relative to how far we've lagged behind.
387 * The idea is to have increasing catch-up percentage as the lag increases. */
388 struct TMCATCHUPPERIOD
389 {
390 uint64_t u64Start; /**< When this period starts. (u64VirtualSyncOffset). */
391 uint32_t u32Percentage; /**< The catch-up percent to apply. */
392 uint32_t u32Alignment; /**< Structure alignment */
393 } aVirtualSyncCatchUpPeriods[TM_MAX_CATCHUP_PERIODS];
394
395 /** The UTC offset in ns.
396 * This is *NOT* for converting UTC to local time. It is for converting real
397 * world UTC time to VM UTC time. This feature is indented for doing date
398 * testing of software and similar.
399 * @todo Implement warpdrive on UTC. */
400 int64_t offUTC;
401
402 /** Timer queues for the different clock types - R3 Ptr */
403 R3PTRTYPE(PTMTIMERQUEUE) paTimerQueuesR3;
404 /** Timer queues for the different clock types - R0 Ptr */
405 R0PTRTYPE(PTMTIMERQUEUE) paTimerQueuesR0;
406 /** Timer queues for the different clock types - RC Ptr */
407 RCPTRTYPE(PTMTIMERQUEUE) paTimerQueuesRC;
408
409 /** Pointer to our RC mapping of the GIP. */
410 RCPTRTYPE(void *) pvGIPRC;
411 /** Pointer to our R3 mapping of the GIP. */
412 R3PTRTYPE(void *) pvGIPR3;
413
414 /** Pointer to a singly linked list of free timers.
415 * This chain is using the TMTIMER::pBigNext members.
416 * Only accessible from the emulation thread. */
417 PTMTIMERR3 pFree;
418
419 /** Pointer to a doubly linked list of created timers.
420 * This chain is using the TMTIMER::pBigNext and TMTIMER::pBigPrev members.
421 * Only accessible from the emulation thread. */
422 PTMTIMERR3 pCreated;
423
424 /** The schedulation timer timer handle (runtime timer).
425 * This timer will do freqent check on pending queue schedulations and
426 * raise VM_FF_TIMER to pull EMTs attention to them.
427 */
428 R3PTRTYPE(PRTTIMER) pTimer;
429 /** Interval in milliseconds of the pTimer timer. */
430 uint32_t u32TimerMillies;
431
432 /** Indicates that queues are being run. */
433 bool volatile fRunningQueues;
434 /** Indicates that the virtual sync queue is being run. */
435 bool volatile fRunningVirtualSyncQueue;
436 /* Alignment */
437 bool u8Alignment[2];
438
439 /** Lock serializing EMT access to TM. */
440 PDMCRITSECT EmtLock;
441 /** Lock serializing access to the VirtualSync clock. */
442 PDMCRITSECT VirtualSyncLock;
443
444 /** TMR3TimerQueuesDo
445 * @{ */
446 STAMPROFILE StatDoQueues;
447 STAMPROFILEADV aStatDoQueues[TMCLOCK_MAX];
448 /** @} */
449 /** tmSchedule
450 * @{ */
451 STAMPROFILE StatScheduleOneRZ;
452 STAMPROFILE StatScheduleOneR3;
453 STAMCOUNTER StatScheduleSetFF;
454 STAMCOUNTER StatPostponedR3;
455 STAMCOUNTER StatPostponedRZ;
456 /** @} */
457 /** Read the time
458 * @{ */
459 STAMCOUNTER StatVirtualGet;
460 STAMCOUNTER StatVirtualGetSetFF;
461 STAMCOUNTER StatVirtualSyncGet;
462 STAMCOUNTER StatVirtualSyncGetELoop;
463 STAMCOUNTER StatVirtualSyncGetExpired;
464 STAMCOUNTER StatVirtualSyncGetLockless;
465 STAMCOUNTER StatVirtualSyncGetLocked;
466 STAMCOUNTER StatVirtualSyncGetSetFF;
467 STAMCOUNTER StatVirtualPause;
468 STAMCOUNTER StatVirtualResume;
469 /* @} */
470 /** TMTimerPoll
471 * @{ */
472 STAMCOUNTER StatPoll;
473 STAMCOUNTER StatPollAlreadySet;
474 STAMCOUNTER StatPollELoop;
475 STAMCOUNTER StatPollMiss;
476 STAMCOUNTER StatPollRunning;
477 STAMCOUNTER StatPollSimple;
478 STAMCOUNTER StatPollVirtual;
479 STAMCOUNTER StatPollVirtualSync;
480 /** @} */
481 /** TMTimerSet
482 * @{ */
483 STAMPROFILE StatTimerSetRZ;
484 STAMPROFILE StatTimerSetR3;
485 /** @} */
486 /** TMTimerStop
487 * @{ */
488 STAMPROFILE StatTimerStopRZ;
489 STAMPROFILE StatTimerStopR3;
490 /** @} */
491 /** VirtualSync - Running and Catching Up
492 * @{ */
493 STAMCOUNTER StatVirtualSyncRun;
494 STAMCOUNTER StatVirtualSyncRunRestart;
495 STAMPROFILE StatVirtualSyncRunSlack;
496 STAMCOUNTER StatVirtualSyncRunStop;
497 STAMCOUNTER StatVirtualSyncRunStoppedAlready;
498 STAMCOUNTER StatVirtualSyncGiveUp;
499 STAMCOUNTER StatVirtualSyncGiveUpBeforeStarting;
500 STAMPROFILEADV StatVirtualSyncCatchup;
501 STAMCOUNTER aStatVirtualSyncCatchupInitial[TM_MAX_CATCHUP_PERIODS];
502 STAMCOUNTER aStatVirtualSyncCatchupAdjust[TM_MAX_CATCHUP_PERIODS];
503 /** @} */
504 /** TMR3VirtualSyncFF (non dedicated EMT). */
505 STAMPROFILE StatVirtualSyncFF;
506 /** The timer callback. */
507 STAMCOUNTER StatTimerCallbackSetFF;
508
509 /** @name Reasons for refusing TSC offsetting in TMCpuTickCanUseRealTSC.
510 * @{ */
511 STAMCOUNTER StatTSCNotFixed;
512 STAMCOUNTER StatTSCNotTicking;
513 STAMCOUNTER StatTSCCatchupLE010;
514 STAMCOUNTER StatTSCCatchupLE025;
515 STAMCOUNTER StatTSCCatchupLE100;
516 STAMCOUNTER StatTSCCatchupOther;
517 STAMCOUNTER StatTSCWarp;
518 STAMCOUNTER StatTSCSyncNotTicking;
519 /** @} */
520} TM;
521/** Pointer to TM VM instance data. */
522typedef TM *PTM;
523
524/**
525 * TM VMCPU Instance data.
526 * Changes to this must checked against the padding of the tm union in VM!
527 */
528typedef struct TMCPU
529{
530 /** Offset to the VMCPU structure.
531 * See TMCPU2VM(). */
532 RTUINT offVMCPU;
533
534 /** CPU timestamp ticking enabled indicator (bool). (RDTSC) */
535 bool fTSCTicking;
536 bool afAlignment0[3]; /**< alignment padding */
537
538 /** The offset between the host TSC and the Guest TSC.
539 * Only valid if fTicking is set and and fTSCUseRealTSC is clear. */
540 uint64_t u64TSCOffset;
541
542 /** The guest TSC when fTicking is cleared. */
543 uint64_t u64TSC;
544
545} TMCPU;
546/** Pointer to TM VMCPU instance data. */
547typedef TMCPU *PTMCPU;
548
549#if 0 /* enable this to rule out locking bugs on single cpu guests. */
550# define tmLock(pVM) VINF_SUCCESS
551# define tmTryLock(pVM) VINF_SUCCESS
552# define tmUnlock(pVM) ((void)0)
553# define tmVirtualSyncLock(pVM) VINF_SUCCESS
554# define tmVirtualSyncTryLock(pVM) VINF_SUCCESS
555# define tmVirtualSyncUnlock(pVM) ((void)0)
556# define TM_ASSERT_EMT_LOCK(pVM) VM_ASSERT_EMT(pVM)
557#else
558int tmLock(PVM pVM);
559int tmTryLock(PVM pVM);
560void tmUnlock(PVM pVM);
561/** Checks that the caller owns the EMT lock. */
562#define TM_ASSERT_EMT_LOCK(pVM) Assert(PDMCritSectIsOwner(&pVM->tm.s.EmtLock))
563int tmVirtualSyncLock(PVM pVM);
564int tmVirtualSyncTryLock(PVM pVM);
565void tmVirtualSyncUnlock(PVM pVM);
566#endif
567
568const char *tmTimerState(TMTIMERSTATE enmState);
569void tmTimerQueueSchedule(PVM pVM, PTMTIMERQUEUE pQueue);
570#ifdef VBOX_STRICT
571void tmTimerQueuesSanityChecks(PVM pVM, const char *pszWhere);
572#endif
573
574int tmCpuTickPause(PVM pVM, PVMCPU pVCpu);
575int tmCpuTickResume(PVM pVM, PVMCPU pVCpu);
576
577int tmVirtualPauseLocked(PVM pVM);
578int tmVirtualResumeLocked(PVM pVM);
579DECLEXPORT(void) tmVirtualNanoTSBad(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS);
580DECLEXPORT(uint64_t) tmVirtualNanoTSRediscover(PRTTIMENANOTSDATA pData);
581
582
583/** @} */
584
585__END_DECLS
586
587#endif
588
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