VirtualBox

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

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

Alignment fixes

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