VirtualBox

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

Last change on this file since 24912 was 22242, checked in by vboxsync, 15 years ago

Made TSC underflow checking more generic.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 24.8 KB
Line 
1/* $Id: TMInternal.h 22242 2009-08-13 15:38:35Z 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
33RT_C_DECLS_BEGIN
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 } Internal;
156
157 /** TMTIMERTYPE_EXTERNAL. */
158 struct
159 {
160 /** Callback. */
161 R3PTRTYPE(PFNTMTIMEREXT) pfnTimer;
162 } External;
163 } u;
164
165 /** Timer state. */
166 volatile TMTIMERSTATE enmState;
167 /** Timer relative offset to the next timer in the schedule list. */
168 int32_t volatile offScheduleNext;
169
170 /** Timer relative offset to the next timer in the chain. */
171 int32_t offNext;
172 /** Timer relative offset to the previous timer in the chain. */
173 int32_t offPrev;
174
175 /** User argument. */
176 RTR3PTR pvUser;
177 /** The critical section associated with the lock. */
178 R3PTRTYPE(PPDMCRITSECT) pCritSect;
179
180 /** Pointer to the next timer in the list of created or free timers. (TM::pTimers or TM::pFree) */
181 PTMTIMERR3 pBigNext;
182 /** Pointer to the previous timer in the list of all created timers. (TM::pTimers) */
183 PTMTIMERR3 pBigPrev;
184 /** Pointer to the timer description. */
185 R3PTRTYPE(const char *) pszDesc;
186 /** Pointer to the VM the timer belongs to - R3 Ptr. */
187 PVMR3 pVMR3;
188 /** Pointer to the VM the timer belongs to - R0 Ptr. */
189 PVMR0 pVMR0;
190 /** Pointer to the VM the timer belongs to - RC Ptr. */
191 PVMRC pVMRC;
192#if HC_ARCH_BITS == 64
193 RTRCPTR padding0; /**< pad structure to multiple of 8 bytes. */
194#endif
195} TMTIMER;
196AssertCompileMemberSize(TMTIMER, enmState, sizeof(uint32_t));
197
198
199/**
200 * Updates a timer state in the correct atomic manner.
201 */
202#if 1
203# define TM_SET_STATE(pTimer, state) \
204 ASMAtomicWriteU32((uint32_t volatile *)&(pTimer)->enmState, state)
205#else
206# define TM_SET_STATE(pTimer, state) \
207 do { \
208 uint32_t uOld1 = (pTimer)->enmState; \
209 Log(("%s: %p: %d -> %d\n", __FUNCTION__, (pTimer), (pTimer)->enmState, state)); \
210 uint32_t uOld2 = ASMAtomicXchgU32((uint32_t volatile *)&(pTimer)->enmState, state); \
211 Assert(uOld1 == uOld2); \
212 } while (0)
213#endif
214
215/**
216 * Tries to updates a timer state in the correct atomic manner.
217 */
218#if 1
219# define TM_TRY_SET_STATE(pTimer, StateNew, StateOld, fRc) \
220 (fRc) = ASMAtomicCmpXchgU32((uint32_t volatile *)&(pTimer)->enmState, StateNew, StateOld)
221#else
222# define TM_TRY_SET_STATE(pTimer, StateNew, StateOld, fRc) \
223 do { (fRc) = ASMAtomicCmpXchgU32((uint32_t volatile *)&(pTimer)->enmState, StateNew, StateOld); \
224 Log(("%s: %p: %d -> %d %RTbool\n", __FUNCTION__, (pTimer), StateOld, StateNew, fRc)); \
225 } while (0)
226#endif
227
228/** Get the previous timer. */
229#define TMTIMER_GET_PREV(pTimer) ((PTMTIMER)((pTimer)->offPrev ? (intptr_t)(pTimer) + (pTimer)->offPrev : 0))
230/** Get the next timer. */
231#define TMTIMER_GET_NEXT(pTimer) ((PTMTIMER)((pTimer)->offNext ? (intptr_t)(pTimer) + (pTimer)->offNext : 0))
232/** Set the previous timer link. */
233#define TMTIMER_SET_PREV(pTimer, pPrev) ((pTimer)->offPrev = (pPrev) ? (intptr_t)(pPrev) - (intptr_t)(pTimer) : 0)
234/** Set the next timer link. */
235#define TMTIMER_SET_NEXT(pTimer, pNext) ((pTimer)->offNext = (pNext) ? (intptr_t)(pNext) - (intptr_t)(pTimer) : 0)
236
237
238/**
239 * A timer queue.
240 *
241 * This is allocated on the hyper heap.
242 */
243typedef struct TMTIMERQUEUE
244{
245 /** The cached expire time for this queue.
246 * Updated by EMT when scheduling the queue or modifying the head timer.
247 * Assigned UINT64_MAX when there is no head timer. */
248 uint64_t u64Expire;
249 /** Doubly linked list of active timers.
250 *
251 * When no scheduling is pending, this list is will be ordered by expire time (ascending).
252 * Access is serialized by only letting the emulation thread (EMT) do changes.
253 *
254 * The offset is relative to the queue structure.
255 */
256 int32_t offActive;
257 /** List of timers pending scheduling of some kind.
258 *
259 * Timer stats allowed in the list are TMTIMERSTATE_PENDING_STOPPING,
260 * TMTIMERSTATE_PENDING_DESTRUCTION, TMTIMERSTATE_PENDING_STOPPING_DESTRUCTION,
261 * TMTIMERSTATE_PENDING_RESCHEDULING and TMTIMERSTATE_PENDING_SCHEDULE.
262 *
263 * The offset is relative to the queue structure.
264 */
265 int32_t volatile offSchedule;
266 /** The clock for this queue. */
267 TMCLOCK enmClock;
268 /** Pad the structure up to 32 bytes. */
269 uint32_t au32Padding[3];
270} TMTIMERQUEUE;
271
272/** Pointer to a timer queue. */
273typedef TMTIMERQUEUE *PTMTIMERQUEUE;
274
275/** Get the head of the active timer list. */
276#define TMTIMER_GET_HEAD(pQueue) ((PTMTIMER)((pQueue)->offActive ? (intptr_t)(pQueue) + (pQueue)->offActive : 0))
277/** Set the head of the active timer list. */
278#define TMTIMER_SET_HEAD(pQueue, pHead) ((pQueue)->offActive = pHead ? (intptr_t)pHead - (intptr_t)(pQueue) : 0)
279
280
281/**
282 * Converts a TM pointer into a VM pointer.
283 * @returns Pointer to the VM structure the TM is part of.
284 * @param pTM Pointer to TM instance data.
285 */
286#define TM2VM(pTM) ( (PVM)((char*)pTM - pTM->offVM) )
287
288
289/**
290 * TM VM Instance data.
291 * Changes to this must checked against the padding of the cfgm union in VM!
292 */
293typedef struct TM
294{
295 /** Offset to the VM structure.
296 * See TM2VM(). */
297 RTUINT offVM;
298
299 /** Set if we fully virtualize the TSC, i.e. intercept all rdtsc instructions.
300 * Config variable: TSCVirtualized (bool) */
301 bool fTSCVirtualized;
302 /** Set if we use the real TSC as time source or if we use the virtual clock.
303 * If fTSCVirtualized is set we maintain a offset to the TSC and pausing/resuming the
304 * ticking. fTSCVirtualized = false implies fTSCUseRealTSC = true.
305 * Config variable: TSCUseRealTSC (bool) */
306 bool fTSCUseRealTSC;
307 /** Flag indicating that the host TSC is suitable for use in AMD-V and VT-x mode.
308 * Config variable: MaybeUseOffsettedHostTSC (boolean) */
309 bool fMaybeUseOffsettedHostTSC;
310 /** Whether the TSC is tied to the execution of code.
311 * Config variable: TSCTiedToExecution (bool) */
312 bool fTSCTiedToExecution;
313 /** Modifier for fTSCTiedToExecution which pauses the TSC while halting if true.
314 * Config variable: TSCNotTiedToHalt (bool) */
315 bool fTSCNotTiedToHalt;
316 bool afAlignment0[2]; /**< alignment padding */
317 /** The ID of the virtual CPU that normally runs the timers. */
318 VMCPUID idTimerCpu;
319 /** The number of CPU clock ticks per second (TMCLOCK_TSC).
320 * Config variable: TSCTicksPerSecond (64-bit unsigned int)
321 * The config variable implies fTSCVirtualized = true and fTSCUseRealTSC = false. */
322 uint64_t cTSCTicksPerSecond;
323
324 /** Virtual time ticking enabled indicator (counter for each VCPU). (TMCLOCK_VIRTUAL) */
325 uint32_t volatile cVirtualTicking;
326 /** Virtual time is not running at 100%. */
327 bool fVirtualWarpDrive;
328 /** Virtual timer synchronous time ticking enabled indicator (bool). (TMCLOCK_VIRTUAL_SYNC) */
329 bool volatile fVirtualSyncTicking;
330 /** Virtual timer synchronous time catch-up active. */
331 bool volatile fVirtualSyncCatchUp;
332 bool afAlignment[5]; /**< alignment padding */
333 /** WarpDrive percentage.
334 * 100% is normal (fVirtualSyncNormal == true). When other than 100% we apply
335 * this percentage to the raw time source for the period it's been valid in,
336 * i.e. since u64VirtualWarpDriveStart. */
337 uint32_t u32VirtualWarpDrivePercentage;
338
339 /** The offset of the virtual clock relative to it's timesource.
340 * Only valid if fVirtualTicking is set. */
341 uint64_t u64VirtualOffset;
342 /** The guest virtual time when fVirtualTicking is cleared. */
343 uint64_t u64Virtual;
344 /** When the Warp drive was started or last adjusted.
345 * Only valid when fVirtualWarpDrive is set. */
346 uint64_t u64VirtualWarpDriveStart;
347 /** The previously returned nano TS.
348 * This handles TSC drift on SMP systems and expired interval.
349 * This is a valid range u64NanoTS to u64NanoTS + 1000000000 (ie. 1sec). */
350 uint64_t volatile u64VirtualRawPrev;
351 /** The ring-3 data structure for the RTTimeNanoTS workers used by tmVirtualGetRawNanoTS. */
352 RTTIMENANOTSDATAR3 VirtualGetRawDataR3;
353 /** The ring-0 data structure for the RTTimeNanoTS workers used by tmVirtualGetRawNanoTS. */
354 RTTIMENANOTSDATAR0 VirtualGetRawDataR0;
355 /** The ring-0 data structure for the RTTimeNanoTS workers used by tmVirtualGetRawNanoTS. */
356 RTTIMENANOTSDATARC VirtualGetRawDataRC;
357 /** Pointer to the ring-3 tmVirtualGetRawNanoTS worker function. */
358 R3PTRTYPE(PFNTIMENANOTSINTERNAL) pfnVirtualGetRawR3;
359 /** Pointer to the ring-3 tmVirtualGetRawNanoTS worker function. */
360 R0PTRTYPE(PFNTIMENANOTSINTERNAL) pfnVirtualGetRawR0;
361 /** Pointer to the ring-3 tmVirtualGetRawNanoTS worker function. */
362 RCPTRTYPE(PFNTIMENANOTSINTERNAL) pfnVirtualGetRawRC;
363 /** Alignment. */
364 RTRCPTR AlignmentRCPtr;
365 /** The guest virtual timer synchronous time when fVirtualSyncTicking is cleared. */
366 uint64_t volatile u64VirtualSync;
367 /** The offset of the timer synchronous virtual clock (TMCLOCK_VIRTUAL_SYNC) relative
368 * to the virtual clock (TMCLOCK_VIRTUAL).
369 * (This is accessed by the timer thread and must be updated atomically.) */
370 uint64_t volatile offVirtualSync;
371 /** The offset into offVirtualSync that's been irrevocably given up by failed catch-up attempts.
372 * Thus the current lag is offVirtualSync - offVirtualSyncGivenUp. */
373 uint64_t offVirtualSyncGivenUp;
374 /** The TMCLOCK_VIRTUAL at the previous TMVirtualGetSync call when catch-up is active. */
375 uint64_t volatile u64VirtualSyncCatchUpPrev;
376 /** The current catch-up percentage. */
377 uint32_t volatile u32VirtualSyncCatchUpPercentage;
378 /** How much slack when processing timers. */
379 uint32_t u32VirtualSyncScheduleSlack;
380 /** When to stop catch-up. */
381 uint64_t u64VirtualSyncCatchUpStopThreshold;
382 /** When to give up catch-up. */
383 uint64_t u64VirtualSyncCatchUpGiveUpThreshold;
384/** @def TM_MAX_CATCHUP_PERIODS
385 * The number of catchup rates. */
386#define TM_MAX_CATCHUP_PERIODS 10
387 /** The agressivness of the catch-up relative to how far we've lagged behind.
388 * The idea is to have increasing catch-up percentage as the lag increases. */
389 struct TMCATCHUPPERIOD
390 {
391 uint64_t u64Start; /**< When this period starts. (u64VirtualSyncOffset). */
392 uint32_t u32Percentage; /**< The catch-up percent to apply. */
393 uint32_t u32Alignment; /**< Structure alignment */
394 } aVirtualSyncCatchUpPeriods[TM_MAX_CATCHUP_PERIODS];
395
396 /** The UTC offset in ns.
397 * This is *NOT* for converting UTC to local time. It is for converting real
398 * world UTC time to VM UTC time. This feature is indented for doing date
399 * testing of software and similar.
400 * @todo Implement warpdrive on UTC. */
401 int64_t offUTC;
402
403 /** Timer queues for the different clock types - R3 Ptr */
404 R3PTRTYPE(PTMTIMERQUEUE) paTimerQueuesR3;
405 /** Timer queues for the different clock types - R0 Ptr */
406 R0PTRTYPE(PTMTIMERQUEUE) paTimerQueuesR0;
407 /** Timer queues for the different clock types - RC Ptr */
408 RCPTRTYPE(PTMTIMERQUEUE) paTimerQueuesRC;
409
410 /** Pointer to our RC mapping of the GIP. */
411 RCPTRTYPE(void *) pvGIPRC;
412 /** Pointer to our R3 mapping of the GIP. */
413 R3PTRTYPE(void *) pvGIPR3;
414
415 /** Pointer to a singly linked list of free timers.
416 * This chain is using the TMTIMER::pBigNext members.
417 * Only accessible from the emulation thread. */
418 PTMTIMERR3 pFree;
419
420 /** Pointer to a doubly linked list of created timers.
421 * This chain is using the TMTIMER::pBigNext and TMTIMER::pBigPrev members.
422 * Only accessible from the emulation thread. */
423 PTMTIMERR3 pCreated;
424
425 /** The schedulation timer timer handle (runtime timer).
426 * This timer will do freqent check on pending queue schedulations and
427 * raise VM_FF_TIMER to pull EMTs attention to them.
428 */
429 R3PTRTYPE(PRTTIMER) pTimer;
430 /** Interval in milliseconds of the pTimer timer. */
431 uint32_t u32TimerMillies;
432
433 /** Indicates that queues are being run. */
434 bool volatile fRunningQueues;
435 /** Indicates that the virtual sync queue is being run. */
436 bool volatile fRunningVirtualSyncQueue;
437 /* Alignment */
438 bool u8Alignment[2];
439
440 /** Lock serializing access to the timer lists. */
441 PDMCRITSECT TimerCritSect;
442 /** Lock serializing access to the VirtualSync clock. */
443 PDMCRITSECT VirtualSyncLock;
444
445 /** TMR3TimerQueuesDo
446 * @{ */
447 STAMPROFILE StatDoQueues;
448 STAMPROFILEADV aStatDoQueues[TMCLOCK_MAX];
449 /** @} */
450 /** tmSchedule
451 * @{ */
452 STAMPROFILE StatScheduleOneRZ;
453 STAMPROFILE StatScheduleOneR3;
454 STAMCOUNTER StatScheduleSetFF;
455 STAMCOUNTER StatPostponedR3;
456 STAMCOUNTER StatPostponedRZ;
457 /** @} */
458 /** Read the time
459 * @{ */
460 STAMCOUNTER StatVirtualGet;
461 STAMCOUNTER StatVirtualGetSetFF;
462 STAMCOUNTER StatVirtualSyncGet;
463 STAMCOUNTER StatVirtualSyncGetELoop;
464 STAMCOUNTER StatVirtualSyncGetExpired;
465 STAMCOUNTER StatVirtualSyncGetLockless;
466 STAMCOUNTER StatVirtualSyncGetLocked;
467 STAMCOUNTER StatVirtualSyncGetSetFF;
468 STAMCOUNTER StatVirtualPause;
469 STAMCOUNTER StatVirtualResume;
470 /* @} */
471 /** TMTimerPoll
472 * @{ */
473 STAMCOUNTER StatPoll;
474 STAMCOUNTER StatPollAlreadySet;
475 STAMCOUNTER StatPollELoop;
476 STAMCOUNTER StatPollMiss;
477 STAMCOUNTER StatPollRunning;
478 STAMCOUNTER StatPollSimple;
479 STAMCOUNTER StatPollVirtual;
480 STAMCOUNTER StatPollVirtualSync;
481 /** @} */
482 /** TMTimerSet
483 * @{ */
484 STAMCOUNTER StatTimerSet;
485 STAMCOUNTER StatTimerSetOpt;
486 STAMPROFILE StatTimerSetRZ;
487 STAMPROFILE StatTimerSetR3;
488 STAMCOUNTER StatTimerSetStStopped;
489 STAMCOUNTER StatTimerSetStExpDeliver;
490 STAMCOUNTER StatTimerSetStActive;
491 STAMCOUNTER StatTimerSetStPendStop;
492 STAMCOUNTER StatTimerSetStPendStopSched;
493 STAMCOUNTER StatTimerSetStPendSched;
494 STAMCOUNTER StatTimerSetStPendResched;
495 STAMCOUNTER StatTimerSetStOther;
496 /** @} */
497 /** TMTimerSetRelative
498 * @{ */
499 STAMCOUNTER StatTimerSetRelative;
500 STAMPROFILE StatTimerSetRelativeRZ;
501 STAMPROFILE StatTimerSetRelativeR3;
502 STAMCOUNTER StatTimerSetRelativeOpt;
503 STAMCOUNTER StatTimerSetRelativeRacyVirtSync;
504 STAMCOUNTER StatTimerSetRelativeStStopped;
505 STAMCOUNTER StatTimerSetRelativeStExpDeliver;
506 STAMCOUNTER StatTimerSetRelativeStActive;
507 STAMCOUNTER StatTimerSetRelativeStPendStop;
508 STAMCOUNTER StatTimerSetRelativeStPendStopSched;
509 STAMCOUNTER StatTimerSetRelativeStPendSched;
510 STAMCOUNTER StatTimerSetRelativeStPendResched;
511 STAMCOUNTER StatTimerSetRelativeStOther;
512 /** @} */
513 /** TMTimerStop
514 * @{ */
515 STAMPROFILE StatTimerStopRZ;
516 STAMPROFILE StatTimerStopR3;
517 /** @} */
518 /** VirtualSync - Running and Catching Up
519 * @{ */
520 STAMCOUNTER StatVirtualSyncRun;
521 STAMCOUNTER StatVirtualSyncRunRestart;
522 STAMPROFILE StatVirtualSyncRunSlack;
523 STAMCOUNTER StatVirtualSyncRunStop;
524 STAMCOUNTER StatVirtualSyncRunStoppedAlready;
525 STAMCOUNTER StatVirtualSyncGiveUp;
526 STAMCOUNTER StatVirtualSyncGiveUpBeforeStarting;
527 STAMPROFILEADV StatVirtualSyncCatchup;
528 STAMCOUNTER aStatVirtualSyncCatchupInitial[TM_MAX_CATCHUP_PERIODS];
529 STAMCOUNTER aStatVirtualSyncCatchupAdjust[TM_MAX_CATCHUP_PERIODS];
530 /** @} */
531 /** TMR3VirtualSyncFF (non dedicated EMT). */
532 STAMPROFILE StatVirtualSyncFF;
533 /** The timer callback. */
534 STAMCOUNTER StatTimerCallbackSetFF;
535
536 /** Calls to TMCpuTickSet. */
537 STAMCOUNTER StatTSCSet;
538
539 /** @name Reasons for refusing TSC offsetting in TMCpuTickCanUseRealTSC.
540 * @{ */
541 STAMCOUNTER StatTSCNotFixed;
542 STAMCOUNTER StatTSCNotTicking;
543 STAMCOUNTER StatTSCCatchupLE010;
544 STAMCOUNTER StatTSCCatchupLE025;
545 STAMCOUNTER StatTSCCatchupLE100;
546 STAMCOUNTER StatTSCCatchupOther;
547 STAMCOUNTER StatTSCWarp;
548 STAMCOUNTER StatTSCUnderflow;
549 STAMCOUNTER StatTSCSyncNotTicking;
550 /** @} */
551} TM;
552/** Pointer to TM VM instance data. */
553typedef TM *PTM;
554
555/**
556 * TM VMCPU Instance data.
557 * Changes to this must checked against the padding of the tm union in VM!
558 */
559typedef struct TMCPU
560{
561 /** Offset to the VMCPU structure.
562 * See TMCPU2VM(). */
563 RTUINT offVMCPU;
564
565 /** CPU timestamp ticking enabled indicator (bool). (RDTSC) */
566 bool fTSCTicking;
567 bool afAlignment0[3]; /**< alignment padding */
568
569 /** The offset between the raw TSC source and the Guest TSC.
570 * Only valid if fTicking is set and and fTSCUseRealTSC is clear. */
571 uint64_t offTSCRawSrc;
572
573 /** The guest TSC when fTicking is cleared. */
574 uint64_t u64TSC;
575
576 /** The last seen TSC by the guest. */
577 uint64_t u64TSCLastSeen;
578} TMCPU;
579/** Pointer to TM VMCPU instance data. */
580typedef TMCPU *PTMCPU;
581
582#if 0 /* enable this to rule out locking bugs on single cpu guests. */
583# define tmTimerLock(pVM) VINF_SUCCESS
584# define tmTimerTryLock(pVM) VINF_SUCCESS
585# define tmTimerUnlock(pVM) ((void)0)
586# define tmVirtualSyncLock(pVM) VINF_SUCCESS
587# define tmVirtualSyncTryLock(pVM) VINF_SUCCESS
588# define tmVirtualSyncUnlock(pVM) ((void)0)
589# define TM_ASSERT_LOCK(pVM) VM_ASSERT_EMT(pVM)
590#else
591int tmTimerLock(PVM pVM);
592int tmTimerTryLock(PVM pVM);
593void tmTimerUnlock(PVM pVM);
594/** Checks that the caller owns the timer lock. */
595#define TM_ASSERT_LOCK(pVM) Assert(PDMCritSectIsOwner(&pVM->tm.s.TimerCritSect))
596int tmVirtualSyncLock(PVM pVM);
597int tmVirtualSyncTryLock(PVM pVM);
598void tmVirtualSyncUnlock(PVM pVM);
599#endif
600
601const char *tmTimerState(TMTIMERSTATE enmState);
602void tmTimerQueueSchedule(PVM pVM, PTMTIMERQUEUE pQueue);
603#ifdef VBOX_STRICT
604void tmTimerQueuesSanityChecks(PVM pVM, const char *pszWhere);
605#endif
606
607int tmCpuTickPause(PVM pVM, PVMCPU pVCpu);
608int tmCpuTickResume(PVM pVM, PVMCPU pVCpu);
609
610int tmVirtualPauseLocked(PVM pVM);
611int tmVirtualResumeLocked(PVM pVM);
612DECLEXPORT(void) tmVirtualNanoTSBad(PRTTIMENANOTSDATA pData, uint64_t u64NanoTS, uint64_t u64DeltaPrev, uint64_t u64PrevNanoTS);
613DECLEXPORT(uint64_t) tmVirtualNanoTSRediscover(PRTTIMENANOTSDATA pData);
614
615
616/** @} */
617
618RT_C_DECLS_END
619
620#endif
621
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use