VirtualBox

Changeset 20784 in vbox


Ignore:
Timestamp:
Jun 22, 2009 2:37:39 PM (15 years ago)
Author:
vboxsync
Message:

TM: Renamed the EmtLock to TimerCritSect as it's almost only used for timer list serialization and we want to let other threads do that too.

Location:
trunk/src/VBox/VMM
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/TM.cpp

    r20752 r20784  
    187187    AssertCompileMemberAlignment(VM, tm.s, 32);
    188188    AssertCompile(sizeof(pVM->tm.s) <= sizeof(pVM->tm.padding));
    189     AssertCompileMemberAlignment(TM, EmtLock, 8);
     189    AssertCompileMemberAlignment(TM, TimerCritSect, 8);
    190190    AssertCompileMemberAlignment(TM, VirtualSyncLock, 8);
    191191
     
    274274     * Init the locks.
    275275     */
    276     rc = PDMR3CritSectInit(pVM, &pVM->tm.s.EmtLock, "TM EMT Lock");
     276    rc = PDMR3CritSectInit(pVM, &pVM->tm.s.TimerCritSect, "TM Timer Lock");
    277277    if (RT_FAILURE(rc))
    278278        return rc;
     
    977977    LogFlow(("TMR3Reset:\n"));
    978978    VM_ASSERT_EMT(pVM);
    979     tmLock(pVM);
     979    tmTimerLock(pVM);
    980980
    981981    /*
     
    10121012    PVMCPU pVCpuDst = &pVM->aCpus[pVM->tm.s.idTimerCpu];
    10131013    VMCPU_FF_CLEAR(pVCpuDst, VMCPU_FF_TIMER); /** @todo FIXME: this isn't right. */
    1014     tmUnlock(pVM);
     1014    tmTimerUnlock(pVM);
    10151015}
    10161016
     
    12401240
    12411241    /* insert into the list of created timers. */
    1242     tmLock(pVM);
     1242    tmTimerLock(pVM);
    12431243    pTimer->pBigPrev        = NULL;
    12441244    pTimer->pBigNext        = pVM->tm.s.pCreated;
     
    12491249    tmTimerQueuesSanityChecks(pVM, "tmR3TimerCreate");
    12501250#endif
    1251     tmUnlock(pVM);
     1251    tmTimerUnlock(pVM);
    12521252
    12531253    *ppTimer = pTimer;
     
    14211421     * like create does. All the work is done here.
    14221422     */
    1423     tmLock(pVM);
     1423    tmTimerLock(pVM);
    14241424    for (int cRetries = 1000;; cRetries--)
    14251425    {
     
    14591459            case TMTIMERSTATE_PENDING_RESCHEDULE_SET_EXPIRE:
    14601460                AssertMsgFailed(("%p:.enmState=%s %s\n", pTimer, tmTimerState(enmState), pTimer->pszDesc));
    1461                 tmUnlock(pVM);
     1461                tmTimerUnlock(pVM);
    14621462                if (!RTThreadYield())
    14631463                    RTThreadSleep(1);
    14641464                AssertMsgReturn(cRetries > 0, ("Failed waiting for stable state. state=%d (%s)\n", pTimer->enmState, pTimer->pszDesc),
    14651465                                VERR_TM_UNSTABLE_STATE);
    1466                 tmLock(pVM);
     1466                tmTimerLock(pVM);
    14671467                continue;
    14681468
     
    14721472            case TMTIMERSTATE_FREE:
    14731473            case TMTIMERSTATE_DESTROY:
    1474                 tmUnlock(pVM);
     1474                tmTimerUnlock(pVM);
    14751475                AssertLogRelMsgFailedReturn(("pTimer=%p %s\n", pTimer, tmTimerState(enmState)), VERR_TM_INVALID_STATE);
    14761476
    14771477            default:
    14781478                AssertMsgFailed(("Unknown timer state %d (%s)\n", enmState, R3STRING(pTimer->pszDesc)));
    1479                 tmUnlock(pVM);
     1479                tmTimerUnlock(pVM);
    14801480                return VERR_TM_UNKNOWN_STATE;
    14811481        }
     
    14901490            break;
    14911491        AssertMsgFailed(("%p:.enmState=%s %s\n", pTimer, tmTimerState(enmState), pTimer->pszDesc));
    1492         tmUnlock(pVM);
     1492        tmTimerUnlock(pVM);
    14931493        AssertMsgReturn(cRetries > 0, ("Failed waiting for stable state. state=%d (%s)\n", pTimer->enmState, pTimer->pszDesc),
    14941494                        VERR_TM_UNSTABLE_STATE);
    1495         tmLock(pVM);
     1495        tmTimerLock(pVM);
    14961496    }
    14971497
     
    15511551    tmTimerQueuesSanityChecks(pVM, "TMR3TimerDestroy");
    15521552#endif
    1553     tmUnlock(pVM);
     1553    tmTimerUnlock(pVM);
    15541554    return VINF_SUCCESS;
    15551555}
     
    15691569        return VERR_INVALID_PARAMETER;
    15701570
    1571     tmLock(pVM);
     1571    tmTimerLock(pVM);
    15721572    PTMTIMER    pCur = pVM->tm.s.pCreated;
    15731573    while (pCur)
     
    15821582        }
    15831583    }
    1584     tmUnlock(pVM);
     1584    tmTimerUnlock(pVM);
    15851585
    15861586    LogFlow(("TMR3TimerDestroyDevice: returns VINF_SUCCESS\n"));
     
    16021602        return VERR_INVALID_PARAMETER;
    16031603
    1604     tmLock(pVM);
     1604    tmTimerLock(pVM);
    16051605    PTMTIMER    pCur = pVM->tm.s.pCreated;
    16061606    while (pCur)
     
    16151615        }
    16161616    }
    1617     tmUnlock(pVM);
     1617    tmTimerUnlock(pVM);
    16181618
    16191619    LogFlow(("TMR3TimerDestroyDriver: returns VINF_SUCCESS\n"));
     
    17591759    Assert(!pVM->tm.s.fRunningQueues);
    17601760    ASMAtomicWriteBool(&pVM->tm.s.fRunningQueues, true);
    1761     tmLock(pVM);
     1761    tmTimerLock(pVM);
    17621762
    17631763    /*
     
    18071807    Log2(("TMR3TimerQueuesDo: returns void\n"));
    18081808    ASMAtomicWriteBool(&pVM->tm.s.fRunningQueues, false);
    1809     tmUnlock(pVM);
     1809    tmTimerUnlock(pVM);
    18101810    STAM_PROFILE_STOP(&pVM->tm.s.StatDoQueues, a);
    18111811}
     
    22322232
    22332233            /* try run it. */
    2234             tmLock(pVM);
     2234            tmTimerLock(pVM);
    22352235            tmVirtualSyncLock(pVM);
    22362236            if (pVM->tm.s.fVirtualSyncTicking)
     
    22512251            STAM_PROFILE_STOP(&pVM->tm.s.StatVirtualSyncFF, a); /* before the unlock! */
    22522252            tmVirtualSyncUnlock(pVM);
    2253             tmUnlock(pVM);
     2253            tmTimerUnlock(pVM);
    22542254        }
    22552255    }
     
    24532453     * The shared virtual clock (includes virtual sync which is tied to it).
    24542454     */
    2455     tmLock(pVM);
     2455    tmTimerLock(pVM);                           /* Paranoia: Exploiting the timer lock here. */
    24562456    int rc = tmVirtualPauseLocked(pVM);
    2457     tmUnlock(pVM);
     2457    tmTimerUnlock(pVM);
    24582458    if (RT_FAILURE(rc))
    24592459        return rc;
     
    24952495     * The shared virtual clock (includes virtual sync which is tied to it).
    24962496     */
    2497     tmLock(pVM);
     2497    tmTimerLock(pVM);                           /* Paranoia: Exploiting the timer lock here. */
    24982498    rc = tmVirtualResumeLocked(pVM);
    2499     tmUnlock(pVM);
     2499    tmTimerUnlock(pVM);
    25002500
    25012501    return rc;
     
    25502550     * the warp drive settings.
    25512551     */
    2552     tmLock(pVM);
     2552    tmTimerLock(pVM);                           /* Paranoia: Exploiting the timer lock here. */
    25532553    bool fPaused = !!pVM->tm.s.cVirtualTicking;
    25542554    if (fPaused) /** @todo this isn't really working, but wtf. */
     
    25622562    if (fPaused)
    25632563        TMR3NotifyResume(pVM, pVCpu);
    2564     tmUnlock(pVM);
     2564    tmTimerUnlock(pVM);
    25652565    return VINF_SUCCESS;
    25662566}
     
    25882588                                                "Expire",
    25892589                                                "State");
    2590     tmLock(pVM);
     2590    tmTimerLock(pVM);
    25912591    for (PTMTIMERR3 pTimer = pVM->tm.s.pCreated; pTimer; pTimer = pTimer->pBigNext)
    25922592    {
     
    26032603                        pTimer->pszDesc);
    26042604    }
    2605     tmUnlock(pVM);
     2605    tmTimerUnlock(pVM);
    26062606}
    26072607
     
    26302630    for (unsigned iQueue = 0; iQueue < TMCLOCK_MAX; iQueue++)
    26312631    {
    2632         tmLock(pVM);
     2632        tmTimerLock(pVM);
    26332633        for (PTMTIMERR3 pTimer = TMTIMER_GET_HEAD(&pVM->tm.s.paTimerQueuesR3[iQueue]);
    26342634             pTimer;
     
    26532653                            pTimer->pszDesc);
    26542654        }
    2655         tmUnlock(pVM);
     2655        tmTimerUnlock(pVM);
    26562656    }
    26572657}
  • trunk/src/VBox/VMM/TMInternal.h

    r20752 r20784  
    438438    bool                        u8Alignment[2];
    439439
    440     /** Lock serializing EMT access to TM. */
    441     PDMCRITSECT                 EmtLock;
     440    /** Lock serializing access to the timer lists. */
     441    PDMCRITSECT                 TimerCritSect;
    442442    /** Lock serializing access to the VirtualSync clock. */
    443443    PDMCRITSECT                 VirtualSyncLock;
     
    578578
    579579#if 0 /* enable this to rule out locking bugs on single cpu guests. */
    580 # define tmLock(pVM)                VINF_SUCCESS
    581 # define tmTryLock(pVM)             VINF_SUCCESS
    582 # define tmUnlock(pVM)              ((void)0)
     580# define tmTimerLock(pVM)                VINF_SUCCESS
     581# define tmTimerTryLock(pVM)             VINF_SUCCESS
     582# define tmTimerUnlock(pVM)              ((void)0)
    583583# define tmVirtualSyncLock(pVM)     VINF_SUCCESS
    584584# define tmVirtualSyncTryLock(pVM)  VINF_SUCCESS
    585585# 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)
    587587#else
    588 int                     tmLock(PVM pVM);
    589 int                     tmTryLock(PVM pVM);
    590 void                    tmUnlock(PVM pVM);
    591 /** Checks that the caller owns the EMT lock.  */
    592 #define TM_ASSERT_EMT_LOCK(pVM) Assert(PDMCritSectIsOwner(&pVM->tm.s.EmtLock))
     588int                     tmTimerLock(PVM pVM);
     589int                     tmTimerTryLock(PVM pVM);
     590void                    tmTimerUnlock(PVM pVM);
     591/** Checks that the caller owns the timer lock.  */
     592#define TM_ASSERT_LOCK(pVM) Assert(PDMCritSectIsOwner(&pVM->tm.s.TimerCritSect))
    593593int                     tmVirtualSyncLock(PVM pVM);
    594594int                     tmVirtualSyncTryLock(PVM pVM);
  • trunk/src/VBox/VMM/VMMAll/TMAll.cpp

    r20778 r20784  
    6666
    6767
    68 #ifndef tmLock
    69 
    70 /**
    71  * Try take the EMT/TM lock, 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.
    7272 *
    7373 * @retval  VINF_SUCCESS on success (always in ring-3).
     
    7575 *
    7676 * @param   pVM         The VM handle.
    77  */
    78 int tmLock(PVM pVM)
     77 *
     78 * @thread  EMTs for the time being.
     79 */
     80int tmTimerLock(PVM pVM)
    7981{
    8082    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);
    8284    return rc;
    8385}
     
    8587
    8688/**
    87  * Try take the EMT/TM lock, no waiting.
     89 * Try take the timer lock, no waiting.
    8890 *
    8991 * @retval  VINF_SUCCESS on success.
     
    9294 * @param   pVM         The VM handle.
    9395 */
    94 int tmTryLock(PVM pVM)
    95 {
    96     VM_ASSERT_EMT(pVM);
    97     int rc = PDMCritSectTryEnter(&pVM->tm.s.EmtLock);
     96int tmTimerTryLock(PVM pVM)
     97{
     98    int rc = PDMCritSectTryEnter(&pVM->tm.s.TimerCritSect);
    9899    return rc;
    99100}
     
    105106 * @param   pVM         The VM handle.
    106107 */
    107 void tmUnlock(PVM pVM)
    108 {
    109     PDMCritSectLeave(&pVM->tm.s.EmtLock);
     108void tmTimerUnlock(PVM pVM)
     109{
     110    PDMCritSectLeave(&pVM->tm.s.TimerCritSect);
    110111}
    111112
     
    261262    PVM pVM = pTimer->CTX_SUFF(pVM);
    262263    if (    VM_IS_EMT(pVM)
    263         &&  RT_SUCCESS(tmTryLock(pVM)))
     264        &&  RT_SUCCESS(tmTimerTryLock(pVM)))
    264265    {
    265266        STAM_PROFILE_START(&pVM->tm.s.CTX_SUFF_Z(StatScheduleOne), a);
     
    270271#endif
    271272        STAM_PROFILE_STOP(&pVM->tm.s.CTX_SUFF_Z(StatScheduleOne), a);
    272         tmUnlock(pVM);
     273        tmTimerUnlock(pVM);
    273274    }
    274275    else
     
    817818
    818819    STAM_COUNTER_INC(&pVM->tm.s.StatTimerSetOpt);
    819     tmUnlock(pVM);
     820    tmTimerUnlock(pVM);
    820821    return VINF_SUCCESS;
    821822}
     
    866867    {
    867868        /* Try take the TM lock and check the state again. */
    868         if (RT_SUCCESS_NP(tmTryLock(pVM)))
     869        if (RT_SUCCESS_NP(tmTimerTryLock(pVM)))
    869870        {
    870871            if (RT_LIKELY(tmTimerTry(pTimer, TMTIMERSTATE_ACTIVE, enmState)))
     
    874875                return VINF_SUCCESS;
    875876            }
    876             tmUnlock(pVM);
     877            tmTimerUnlock(pVM);
    877878        }
    878879    }
     
    10411042
    10421043    STAM_COUNTER_INC(&pVM->tm.s.StatTimerSetRelativeOpt);
    1043     tmUnlock(pVM);
     1044    tmTimerUnlock(pVM);
    10441045    return VINF_SUCCESS;
    10451046}
     
    10921093     *       get the innermost locks.
    10931094     */
    1094     bool fOwnTMLock = RT_SUCCESS_NP(tmTryLock(pVM));
     1095    bool fOwnTMLock = RT_SUCCESS_NP(tmTimerTryLock(pVM));
    10951096#if 1
    10961097    if (    fOwnTMLock
     
    12481249        if (!fOwnTMLock)
    12491250        {
    1250             fOwnTMLock = RT_SUCCESS_NP(tmTryLock(pVM));
     1251            fOwnTMLock = RT_SUCCESS_NP(tmTimerTryLock(pVM));
    12511252            if (    !fOwnTMLock
    12521253                &&  enmClock == TMCLOCK_VIRTUAL_SYNC
     
    12631264        tmVirtualSyncUnlock(pVM);
    12641265    if (fOwnTMLock)
    1265         tmUnlock(pVM);
     1266        tmTimerUnlock(pVM);
    12661267
    12671268    if (    !fOwnTMLock
     
    20352036void tmTimerQueueSchedule(PVM pVM, PTMTIMERQUEUE pQueue)
    20362037{
    2037     TM_ASSERT_EMT_LOCK(pVM);
     2038    TM_ASSERT_LOCK(pVM);
    20382039
    20392040    /*
     
    20762077void tmTimerQueuesSanityChecks(PVM pVM, const char *pszWhere)
    20772078{
    2078     TM_ASSERT_EMT_LOCK(pVM);
     2079    TM_ASSERT_LOCK(pVM);
    20792080
    20802081    /*
  • trunk/src/VBox/VMM/testcase/tstVMStructGC.cpp

    r20747 r20784  
    854854    GEN_CHECK_OFF(TM, paTimerQueuesR0);
    855855    GEN_CHECK_OFF(TM, paTimerQueuesRC);
    856     GEN_CHECK_OFF(TM, EmtLock);
     856    GEN_CHECK_OFF(TM, TimerCritSect);
    857857    GEN_CHECK_OFF(TM, VirtualSyncLock);
    858858    GEN_CHECK_OFF(TM, StatDoQueues);
  • trunk/src/VBox/VMM/testcase/tstVMStructSize.cpp

    r20747 r20784  
    297297
    298298    /* TM */
    299     CHECK_MEMBER_ALIGNMENT(TM, EmtLock, sizeof(uintptr_t));
     299    CHECK_MEMBER_ALIGNMENT(TM, TimerCritSect, sizeof(uintptr_t));
    300300    CHECK_MEMBER_ALIGNMENT(TM, VirtualSyncLock, sizeof(uintptr_t));
    301301
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette