Changeset 20784 in vbox
- Timestamp:
- Jun 22, 2009 2:37:39 PM (15 years ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 5 edited
-
TM.cpp (modified) (27 diffs)
-
TMInternal.h (modified) (2 diffs)
-
VMMAll/TMAll.cpp (modified) (16 diffs)
-
testcase/tstVMStructGC.cpp (modified) (1 diff)
-
testcase/tstVMStructSize.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/TM.cpp
r20752 r20784 187 187 AssertCompileMemberAlignment(VM, tm.s, 32); 188 188 AssertCompile(sizeof(pVM->tm.s) <= sizeof(pVM->tm.padding)); 189 AssertCompileMemberAlignment(TM, EmtLock, 8);189 AssertCompileMemberAlignment(TM, TimerCritSect, 8); 190 190 AssertCompileMemberAlignment(TM, VirtualSyncLock, 8); 191 191 … … 274 274 * Init the locks. 275 275 */ 276 rc = PDMR3CritSectInit(pVM, &pVM->tm.s. EmtLock, "TM EMTLock");276 rc = PDMR3CritSectInit(pVM, &pVM->tm.s.TimerCritSect, "TM Timer Lock"); 277 277 if (RT_FAILURE(rc)) 278 278 return rc; … … 977 977 LogFlow(("TMR3Reset:\n")); 978 978 VM_ASSERT_EMT(pVM); 979 tm Lock(pVM);979 tmTimerLock(pVM); 980 980 981 981 /* … … 1012 1012 PVMCPU pVCpuDst = &pVM->aCpus[pVM->tm.s.idTimerCpu]; 1013 1013 VMCPU_FF_CLEAR(pVCpuDst, VMCPU_FF_TIMER); /** @todo FIXME: this isn't right. */ 1014 tm Unlock(pVM);1014 tmTimerUnlock(pVM); 1015 1015 } 1016 1016 … … 1240 1240 1241 1241 /* insert into the list of created timers. */ 1242 tm Lock(pVM);1242 tmTimerLock(pVM); 1243 1243 pTimer->pBigPrev = NULL; 1244 1244 pTimer->pBigNext = pVM->tm.s.pCreated; … … 1249 1249 tmTimerQueuesSanityChecks(pVM, "tmR3TimerCreate"); 1250 1250 #endif 1251 tm Unlock(pVM);1251 tmTimerUnlock(pVM); 1252 1252 1253 1253 *ppTimer = pTimer; … … 1421 1421 * like create does. All the work is done here. 1422 1422 */ 1423 tm Lock(pVM);1423 tmTimerLock(pVM); 1424 1424 for (int cRetries = 1000;; cRetries--) 1425 1425 { … … 1459 1459 case TMTIMERSTATE_PENDING_RESCHEDULE_SET_EXPIRE: 1460 1460 AssertMsgFailed(("%p:.enmState=%s %s\n", pTimer, tmTimerState(enmState), pTimer->pszDesc)); 1461 tm Unlock(pVM);1461 tmTimerUnlock(pVM); 1462 1462 if (!RTThreadYield()) 1463 1463 RTThreadSleep(1); 1464 1464 AssertMsgReturn(cRetries > 0, ("Failed waiting for stable state. state=%d (%s)\n", pTimer->enmState, pTimer->pszDesc), 1465 1465 VERR_TM_UNSTABLE_STATE); 1466 tm Lock(pVM);1466 tmTimerLock(pVM); 1467 1467 continue; 1468 1468 … … 1472 1472 case TMTIMERSTATE_FREE: 1473 1473 case TMTIMERSTATE_DESTROY: 1474 tm Unlock(pVM);1474 tmTimerUnlock(pVM); 1475 1475 AssertLogRelMsgFailedReturn(("pTimer=%p %s\n", pTimer, tmTimerState(enmState)), VERR_TM_INVALID_STATE); 1476 1476 1477 1477 default: 1478 1478 AssertMsgFailed(("Unknown timer state %d (%s)\n", enmState, R3STRING(pTimer->pszDesc))); 1479 tm Unlock(pVM);1479 tmTimerUnlock(pVM); 1480 1480 return VERR_TM_UNKNOWN_STATE; 1481 1481 } … … 1490 1490 break; 1491 1491 AssertMsgFailed(("%p:.enmState=%s %s\n", pTimer, tmTimerState(enmState), pTimer->pszDesc)); 1492 tm Unlock(pVM);1492 tmTimerUnlock(pVM); 1493 1493 AssertMsgReturn(cRetries > 0, ("Failed waiting for stable state. state=%d (%s)\n", pTimer->enmState, pTimer->pszDesc), 1494 1494 VERR_TM_UNSTABLE_STATE); 1495 tm Lock(pVM);1495 tmTimerLock(pVM); 1496 1496 } 1497 1497 … … 1551 1551 tmTimerQueuesSanityChecks(pVM, "TMR3TimerDestroy"); 1552 1552 #endif 1553 tm Unlock(pVM);1553 tmTimerUnlock(pVM); 1554 1554 return VINF_SUCCESS; 1555 1555 } … … 1569 1569 return VERR_INVALID_PARAMETER; 1570 1570 1571 tm Lock(pVM);1571 tmTimerLock(pVM); 1572 1572 PTMTIMER pCur = pVM->tm.s.pCreated; 1573 1573 while (pCur) … … 1582 1582 } 1583 1583 } 1584 tm Unlock(pVM);1584 tmTimerUnlock(pVM); 1585 1585 1586 1586 LogFlow(("TMR3TimerDestroyDevice: returns VINF_SUCCESS\n")); … … 1602 1602 return VERR_INVALID_PARAMETER; 1603 1603 1604 tm Lock(pVM);1604 tmTimerLock(pVM); 1605 1605 PTMTIMER pCur = pVM->tm.s.pCreated; 1606 1606 while (pCur) … … 1615 1615 } 1616 1616 } 1617 tm Unlock(pVM);1617 tmTimerUnlock(pVM); 1618 1618 1619 1619 LogFlow(("TMR3TimerDestroyDriver: returns VINF_SUCCESS\n")); … … 1759 1759 Assert(!pVM->tm.s.fRunningQueues); 1760 1760 ASMAtomicWriteBool(&pVM->tm.s.fRunningQueues, true); 1761 tm Lock(pVM);1761 tmTimerLock(pVM); 1762 1762 1763 1763 /* … … 1807 1807 Log2(("TMR3TimerQueuesDo: returns void\n")); 1808 1808 ASMAtomicWriteBool(&pVM->tm.s.fRunningQueues, false); 1809 tm Unlock(pVM);1809 tmTimerUnlock(pVM); 1810 1810 STAM_PROFILE_STOP(&pVM->tm.s.StatDoQueues, a); 1811 1811 } … … 2232 2232 2233 2233 /* try run it. */ 2234 tm Lock(pVM);2234 tmTimerLock(pVM); 2235 2235 tmVirtualSyncLock(pVM); 2236 2236 if (pVM->tm.s.fVirtualSyncTicking) … … 2251 2251 STAM_PROFILE_STOP(&pVM->tm.s.StatVirtualSyncFF, a); /* before the unlock! */ 2252 2252 tmVirtualSyncUnlock(pVM); 2253 tm Unlock(pVM);2253 tmTimerUnlock(pVM); 2254 2254 } 2255 2255 } … … 2453 2453 * The shared virtual clock (includes virtual sync which is tied to it). 2454 2454 */ 2455 tm Lock(pVM);2455 tmTimerLock(pVM); /* Paranoia: Exploiting the timer lock here. */ 2456 2456 int rc = tmVirtualPauseLocked(pVM); 2457 tm Unlock(pVM);2457 tmTimerUnlock(pVM); 2458 2458 if (RT_FAILURE(rc)) 2459 2459 return rc; … … 2495 2495 * The shared virtual clock (includes virtual sync which is tied to it). 2496 2496 */ 2497 tm Lock(pVM);2497 tmTimerLock(pVM); /* Paranoia: Exploiting the timer lock here. */ 2498 2498 rc = tmVirtualResumeLocked(pVM); 2499 tm Unlock(pVM);2499 tmTimerUnlock(pVM); 2500 2500 2501 2501 return rc; … … 2550 2550 * the warp drive settings. 2551 2551 */ 2552 tm Lock(pVM);2552 tmTimerLock(pVM); /* Paranoia: Exploiting the timer lock here. */ 2553 2553 bool fPaused = !!pVM->tm.s.cVirtualTicking; 2554 2554 if (fPaused) /** @todo this isn't really working, but wtf. */ … … 2562 2562 if (fPaused) 2563 2563 TMR3NotifyResume(pVM, pVCpu); 2564 tm Unlock(pVM);2564 tmTimerUnlock(pVM); 2565 2565 return VINF_SUCCESS; 2566 2566 } … … 2588 2588 "Expire", 2589 2589 "State"); 2590 tm Lock(pVM);2590 tmTimerLock(pVM); 2591 2591 for (PTMTIMERR3 pTimer = pVM->tm.s.pCreated; pTimer; pTimer = pTimer->pBigNext) 2592 2592 { … … 2603 2603 pTimer->pszDesc); 2604 2604 } 2605 tm Unlock(pVM);2605 tmTimerUnlock(pVM); 2606 2606 } 2607 2607 … … 2630 2630 for (unsigned iQueue = 0; iQueue < TMCLOCK_MAX; iQueue++) 2631 2631 { 2632 tm Lock(pVM);2632 tmTimerLock(pVM); 2633 2633 for (PTMTIMERR3 pTimer = TMTIMER_GET_HEAD(&pVM->tm.s.paTimerQueuesR3[iQueue]); 2634 2634 pTimer; … … 2653 2653 pTimer->pszDesc); 2654 2654 } 2655 tm Unlock(pVM);2655 tmTimerUnlock(pVM); 2656 2656 } 2657 2657 } -
trunk/src/VBox/VMM/TMInternal.h
r20752 r20784 438 438 bool u8Alignment[2]; 439 439 440 /** Lock serializing EMT access to TM. */441 PDMCRITSECT EmtLock;440 /** Lock serializing access to the timer lists. */ 441 PDMCRITSECT TimerCritSect; 442 442 /** Lock serializing access to the VirtualSync clock. */ 443 443 PDMCRITSECT VirtualSyncLock; … … 578 578 579 579 #if 0 /* enable this to rule out locking bugs on single cpu guests. */ 580 # define tm Lock(pVM) VINF_SUCCESS581 # define tmT ryLock(pVM) VINF_SUCCESS582 # define tm Unlock(pVM) ((void)0)580 # define tmTimerLock(pVM) VINF_SUCCESS 581 # define tmTimerTryLock(pVM) VINF_SUCCESS 582 # define tmTimerUnlock(pVM) ((void)0) 583 583 # define tmVirtualSyncLock(pVM) VINF_SUCCESS 584 584 # define tmVirtualSyncTryLock(pVM) VINF_SUCCESS 585 585 # define tmVirtualSyncUnlock(pVM) ((void)0) 586 # define TM_ASSERT_ EMT_LOCK(pVM)VM_ASSERT_EMT(pVM)586 # define TM_ASSERT_LOCK(pVM) VM_ASSERT_EMT(pVM) 587 587 #else 588 int tm Lock(PVM pVM);589 int tmT ryLock(PVM pVM);590 void tm Unlock(PVM pVM);591 /** Checks that the caller owns the EMTlock. */592 #define TM_ASSERT_ EMT_LOCK(pVM) Assert(PDMCritSectIsOwner(&pVM->tm.s.EmtLock))588 int tmTimerLock(PVM pVM); 589 int tmTimerTryLock(PVM pVM); 590 void tmTimerUnlock(PVM pVM); 591 /** Checks that the caller owns the timer lock. */ 592 #define TM_ASSERT_LOCK(pVM) Assert(PDMCritSectIsOwner(&pVM->tm.s.TimerCritSect)) 593 593 int tmVirtualSyncLock(PVM pVM); 594 594 int tmVirtualSyncTryLock(PVM pVM); -
trunk/src/VBox/VMM/VMMAll/TMAll.cpp
r20778 r20784 66 66 67 67 68 #ifndef tm Lock69 70 /** 71 * Try take the EMT/TMlock, wait in ring-3 return VERR_SEM_BUSY in R0/RC.68 #ifndef tmTimerLock 69 70 /** 71 * Try take the timer lock, wait in ring-3 return VERR_SEM_BUSY in R0/RC. 72 72 * 73 73 * @retval VINF_SUCCESS on success (always in ring-3). … … 75 75 * 76 76 * @param pVM The VM handle. 77 */ 78 int tmLock(PVM pVM) 77 * 78 * @thread EMTs for the time being. 79 */ 80 int tmTimerLock(PVM pVM) 79 81 { 80 82 VM_ASSERT_EMT(pVM); 81 int rc = PDMCritSectEnter(&pVM->tm.s. EmtLock, VERR_SEM_BUSY);83 int rc = PDMCritSectEnter(&pVM->tm.s.TimerCritSect, VERR_SEM_BUSY); 82 84 return rc; 83 85 } … … 85 87 86 88 /** 87 * Try take the EMT/TMlock, no waiting.89 * Try take the timer lock, no waiting. 88 90 * 89 91 * @retval VINF_SUCCESS on success. … … 92 94 * @param pVM The VM handle. 93 95 */ 94 int tmTryLock(PVM pVM) 95 { 96 VM_ASSERT_EMT(pVM); 97 int rc = PDMCritSectTryEnter(&pVM->tm.s.EmtLock); 96 int tmTimerTryLock(PVM pVM) 97 { 98 int rc = PDMCritSectTryEnter(&pVM->tm.s.TimerCritSect); 98 99 return rc; 99 100 } … … 105 106 * @param pVM The VM handle. 106 107 */ 107 void tm Unlock(PVM pVM)108 { 109 PDMCritSectLeave(&pVM->tm.s. EmtLock);108 void tmTimerUnlock(PVM pVM) 109 { 110 PDMCritSectLeave(&pVM->tm.s.TimerCritSect); 110 111 } 111 112 … … 261 262 PVM pVM = pTimer->CTX_SUFF(pVM); 262 263 if ( VM_IS_EMT(pVM) 263 && RT_SUCCESS(tmT ryLock(pVM)))264 && RT_SUCCESS(tmTimerTryLock(pVM))) 264 265 { 265 266 STAM_PROFILE_START(&pVM->tm.s.CTX_SUFF_Z(StatScheduleOne), a); … … 270 271 #endif 271 272 STAM_PROFILE_STOP(&pVM->tm.s.CTX_SUFF_Z(StatScheduleOne), a); 272 tm Unlock(pVM);273 tmTimerUnlock(pVM); 273 274 } 274 275 else … … 817 818 818 819 STAM_COUNTER_INC(&pVM->tm.s.StatTimerSetOpt); 819 tm Unlock(pVM);820 tmTimerUnlock(pVM); 820 821 return VINF_SUCCESS; 821 822 } … … 866 867 { 867 868 /* Try take the TM lock and check the state again. */ 868 if (RT_SUCCESS_NP(tmT ryLock(pVM)))869 if (RT_SUCCESS_NP(tmTimerTryLock(pVM))) 869 870 { 870 871 if (RT_LIKELY(tmTimerTry(pTimer, TMTIMERSTATE_ACTIVE, enmState))) … … 874 875 return VINF_SUCCESS; 875 876 } 876 tm Unlock(pVM);877 tmTimerUnlock(pVM); 877 878 } 878 879 } … … 1041 1042 1042 1043 STAM_COUNTER_INC(&pVM->tm.s.StatTimerSetRelativeOpt); 1043 tm Unlock(pVM);1044 tmTimerUnlock(pVM); 1044 1045 return VINF_SUCCESS; 1045 1046 } … … 1092 1093 * get the innermost locks. 1093 1094 */ 1094 bool fOwnTMLock = RT_SUCCESS_NP(tmT ryLock(pVM));1095 bool fOwnTMLock = RT_SUCCESS_NP(tmTimerTryLock(pVM)); 1095 1096 #if 1 1096 1097 if ( fOwnTMLock … … 1248 1249 if (!fOwnTMLock) 1249 1250 { 1250 fOwnTMLock = RT_SUCCESS_NP(tmT ryLock(pVM));1251 fOwnTMLock = RT_SUCCESS_NP(tmTimerTryLock(pVM)); 1251 1252 if ( !fOwnTMLock 1252 1253 && enmClock == TMCLOCK_VIRTUAL_SYNC … … 1263 1264 tmVirtualSyncUnlock(pVM); 1264 1265 if (fOwnTMLock) 1265 tm Unlock(pVM);1266 tmTimerUnlock(pVM); 1266 1267 1267 1268 if ( !fOwnTMLock … … 2035 2036 void tmTimerQueueSchedule(PVM pVM, PTMTIMERQUEUE pQueue) 2036 2037 { 2037 TM_ASSERT_ EMT_LOCK(pVM);2038 TM_ASSERT_LOCK(pVM); 2038 2039 2039 2040 /* … … 2076 2077 void tmTimerQueuesSanityChecks(PVM pVM, const char *pszWhere) 2077 2078 { 2078 TM_ASSERT_ EMT_LOCK(pVM);2079 TM_ASSERT_LOCK(pVM); 2079 2080 2080 2081 /* -
trunk/src/VBox/VMM/testcase/tstVMStructGC.cpp
r20747 r20784 854 854 GEN_CHECK_OFF(TM, paTimerQueuesR0); 855 855 GEN_CHECK_OFF(TM, paTimerQueuesRC); 856 GEN_CHECK_OFF(TM, EmtLock);856 GEN_CHECK_OFF(TM, TimerCritSect); 857 857 GEN_CHECK_OFF(TM, VirtualSyncLock); 858 858 GEN_CHECK_OFF(TM, StatDoQueues); -
trunk/src/VBox/VMM/testcase/tstVMStructSize.cpp
r20747 r20784 297 297 298 298 /* TM */ 299 CHECK_MEMBER_ALIGNMENT(TM, EmtLock, sizeof(uintptr_t));299 CHECK_MEMBER_ALIGNMENT(TM, TimerCritSect, sizeof(uintptr_t)); 300 300 CHECK_MEMBER_ALIGNMENT(TM, VirtualSyncLock, sizeof(uintptr_t)); 301 301
Note:
See TracChangeset
for help on using the changeset viewer.

