VirtualBox

Changeset 56392 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
Jun 12, 2015 2:56:14 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
100992
Message:

DevATA: Replaced AsyncIORequestMutex (RTSEMMUTEX) with a PDM critical section.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DevATA.cpp

    r56292 r56392  
    435435    /** Magic delay before triggering interrupts in DMA mode. */
    436436    uint32_t            DelayIRQMillies;
    437     /** The mutex protecting the request queue. */
    438     RTSEMMUTEX          AsyncIORequestMutex;
     437    /** The lock protecting the request queue. */
     438    PDMCRITSECT         AsyncIORequestLock;
    439439    /** The event semaphore the thread is waiting on during suspended I/O. */
    440440    RTSEMEVENT          SuspendIOSem;
     
    704704static void ataAsyncIOClearRequests(PATACONTROLLER pCtl)
    705705{
    706     int rc;
    707 
    708     rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
     706    int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED);
    709707    AssertRC(rc);
     708
    710709    pCtl->AsyncIOReqHead = 0;
    711710    pCtl->AsyncIOReqTail = 0;
    712     rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex);
     711
     712    rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock);
    713713    AssertRC(rc);
    714714}
     
    717717static void ataAsyncIOPutRequest(PATACONTROLLER pCtl, const ATARequest *pReq)
    718718{
    719     int rc;
    720 
    721     rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
     719    int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED);
    722720    AssertRC(rc);
     721
    723722    Assert((pCtl->AsyncIOReqHead + 1) % RT_ELEMENTS(pCtl->aAsyncIORequests) != pCtl->AsyncIOReqTail);
    724723    memcpy(&pCtl->aAsyncIORequests[pCtl->AsyncIOReqHead], pReq, sizeof(*pReq));
    725724    pCtl->AsyncIOReqHead++;
    726725    pCtl->AsyncIOReqHead %= RT_ELEMENTS(pCtl->aAsyncIORequests);
    727     rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex);
     726
     727    rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock);
    728728    AssertRC(rc);
     729
    729730    rc = PDMR3CritSectScheduleExitEvent(&pCtl->lock, pCtl->AsyncIOSem);
    730731    if (RT_FAILURE(rc))
     
    738739static const ATARequest *ataAsyncIOGetCurrentRequest(PATACONTROLLER pCtl)
    739740{
    740     int rc;
    741741    const ATARequest *pReq;
    742742
    743     rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
     743    int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED);
    744744    AssertRC(rc);
     745
    745746    if (pCtl->AsyncIOReqHead != pCtl->AsyncIOReqTail)
    746747        pReq = &pCtl->aAsyncIORequests[pCtl->AsyncIOReqTail];
    747748    else
    748749        pReq = NULL;
    749     rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex);
     750
     751    rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock);
    750752    AssertRC(rc);
    751753    return pReq;
     
    763765static void ataAsyncIORemoveCurrentRequest(PATACONTROLLER pCtl, ATAAIO ReqType)
    764766{
    765     int rc;
    766 
    767     rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
     767    int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED);
    768768    AssertRC(rc);
     769
    769770    if (pCtl->AsyncIOReqHead != pCtl->AsyncIOReqTail && pCtl->aAsyncIORequests[pCtl->AsyncIOReqTail].ReqType == ReqType)
    770771    {
     
    772773        pCtl->AsyncIOReqTail %= RT_ELEMENTS(pCtl->aAsyncIORequests);
    773774    }
    774     rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex);
     775
     776    rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock);
    775777    AssertRC(rc);
    776778}
     
    786788static void ataAsyncIODumpRequests(PATACONTROLLER pCtl)
    787789{
    788     int rc;
    789     uint8_t curr;
    790 
    791     rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
     790    int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED);
    792791    AssertRC(rc);
     792
    793793    LogRel(("PIIX3 ATA: Ctl#%d: request queue dump (topmost is current):\n", ATACONTROLLER_IDX(pCtl)));
    794     curr = pCtl->AsyncIOReqTail;
     794    uint8_t curr = pCtl->AsyncIOReqTail;
    795795    do
    796796    {
     
    822822        curr = (curr + 1) % RT_ELEMENTS(pCtl->aAsyncIORequests);
    823823    } while (curr != pCtl->AsyncIOReqTail);
    824     rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex);
     824
     825    rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock);
    825826    AssertRC(rc);
    826827}
     
    836837static bool ataAsyncIOIsIdle(PATACONTROLLER pCtl, bool fStrict)
    837838{
    838     int rc;
    839     bool fIdle;
    840 
    841     rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
     839    int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED);
    842840    AssertRC(rc);
    843     fIdle = pCtl->fRedoIdle;
     841
     842    bool fIdle = pCtl->fRedoIdle;
    844843    if (!fIdle)
    845844        fIdle = (pCtl->AsyncIOReqHead == pCtl->AsyncIOReqTail);
    846845    if (fStrict)
    847846        fIdle &= (pCtl->uAsyncIOState == ATA_AIO_NEW);
    848     rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex);
     847
     848    rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock);
    849849    AssertRC(rc);
    850850    return fIdle;
     
    50375037{
    50385038    /*
    5039      * Take the mutex here and recheck the idle indicator to avoid
     5039     * Take the lock here and recheck the idle indicator to avoid
    50405040     * unnecessary work and racing ataR3WaitForAsyncIOIsIdle.
    50415041     */
    5042     int rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT); AssertRC(rc);
     5042    int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED);
     5043    AssertRC(rc);
    50435044
    50445045    if (    pCtl->fSignalIdle
     
    50495050    }
    50505051
    5051     rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex); AssertRC(rc);
     5052    rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock);
     5053    AssertRC(rc);
    50525054}
    50535055
     
    55385540
    55395541    /* Cleanup the state.  */
    5540     /* Do not destroy request mutex yet, still needed for proper shutdown. */
     5542    /* Do not destroy request lock yet, still needed for proper shutdown. */
    55415543    pCtl->fShutdown = false;
    55425544
     
    64166418            {
    64176419                /* Make it signal PDM & itself when its done */
    6418                 RTSemMutexRequest(pThis->aCts[i].AsyncIORequestMutex, RT_INDEFINITE_WAIT);
     6420                PDMCritSectEnter(&pThis->aCts[i].AsyncIORequestLock, VERR_IGNORED);
    64196421                ASMAtomicWriteBool(&pThis->aCts[i].fSignalIdle, true);
    6420                 RTSemMutexRelease(pThis->aCts[i].AsyncIORequestMutex);
     6422                PDMCritSectLeave(&pThis->aCts[i].AsyncIORequestLock);
     6423
    64216424                fRc = ataAsyncIOIsIdle(&pThis->aCts[i], false /*fStrict*/);
    64226425                if (!fRc)
     
    69146917            if (pThis->aCts[i].AsyncIOThread != NIL_RTTHREAD)
    69156918            {
    6916                 int rc = RTSemMutexRequest(pThis->aCts[i].AsyncIORequestMutex, RT_INDEFINITE_WAIT);
     6919                int rc = PDMCritSectEnter(&pThis->aCts[i].AsyncIORequestLock, VERR_IGNORED);
    69176920                AssertRC(rc);
    69186921
     
    69216924                AssertRC(rc);
    69226925
    6923                 rc = RTSemMutexRelease(pThis->aCts[i].AsyncIORequestMutex);
     6926                rc = PDMCritSectLeave(&pThis->aCts[i].AsyncIORequestLock);
    69246927                AssertRC(rc);
    69256928
     
    70297032    for (uint32_t i = 0; i < RT_ELEMENTS(pThis->aCts); i++)
    70307033    {
    7031         if (pThis->aCts[i].AsyncIORequestMutex != NIL_RTSEMMUTEX)
    7032         {
    7033             RTSemMutexDestroy(pThis->aCts[i].AsyncIORequestMutex);
    7034             pThis->aCts[i].AsyncIORequestMutex = NIL_RTSEMMUTEX;
    7035         }
     7034        if (PDMCritSectIsInitialized(&pThis->aCts[i].AsyncIORequestLock))
     7035            PDMR3CritSectDelete(&pThis->aCts[i].AsyncIORequestLock);
    70367036        if (pThis->aCts[i].AsyncIOSem != NIL_RTSEMEVENT)
    70377037        {
     
    71237123        pThis->aCts[i].AsyncIOSem = NIL_RTSEMEVENT;
    71247124        pThis->aCts[i].SuspendIOSem = NIL_RTSEMEVENT;
    7125         pThis->aCts[i].AsyncIORequestMutex = NIL_RTSEMMUTEX;
    71267125        pThis->aCts[i].AsyncIOThread = NIL_RTTHREAD;
    71277126    }
     
    73767375#endif /* VBOX_WITH_STATISTICS */
    73777376
    7378         /* Initialize per-controller critical section */
    7379         rc = PDMDevHlpCritSectInit(pDevIns, &pThis->aCts[i].lock, RT_SRC_POS, "ATA#%u", i);
    7380         if (RT_FAILURE(rc))
    7381             return PDMDEV_SET_ERROR(pDevIns, rc, N_("PIIX3 cannot initialize critical section"));
     7377        /* Initialize per-controller critical section. */
     7378        rc = PDMDevHlpCritSectInit(pDevIns, &pThis->aCts[i].lock,               RT_SRC_POS, "ATA#%u-Ctl", i);
     7379        AssertLogRelRCReturn(rc, rc);
     7380
     7381        /* Initialize per-controller async I/O request critical section. */
     7382        rc = PDMDevHlpCritSectInit(pDevIns, &pThis->aCts[i].AsyncIORequestLock, RT_SRC_POS, "ATA#%u-Req", i);
     7383        AssertLogRelRCReturn(rc, rc);
    73827384    }
    73837385
     
    74137415        rc = RTSemEventCreate(&pCtl->SuspendIOSem);
    74147416        AssertLogRelRCReturn(rc, rc);
    7415         rc = RTSemMutexCreate(&pCtl->AsyncIORequestMutex);
    7416         AssertLogRelRCReturn(rc, rc);
     7417
    74177418        ataAsyncIOClearRequests(pCtl);
    74187419        rc = RTThreadCreateF(&pCtl->AsyncIOThread, ataAsyncIOLoop, (void *)pCtl, 128*1024 /*cbStack*/,
    74197420                             RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "ATA-%u", i);
    74207421        AssertLogRelRCReturn(rc, rc);
    7421         Assert(pCtl->AsyncIOThread != NIL_RTTHREAD && pCtl->AsyncIOSem != NIL_RTSEMEVENT && pCtl->SuspendIOSem != NIL_RTSEMEVENT && pCtl->AsyncIORequestMutex != NIL_RTSEMMUTEX);
    7422         Log(("%s: controller %d AIO thread id %#x; sem %p susp_sem %p mutex %p\n", __FUNCTION__, i, pCtl->AsyncIOThread, pCtl->AsyncIOSem, pCtl->SuspendIOSem, pCtl->AsyncIORequestMutex));
     7422        Assert(  pCtl->AsyncIOThread != NIL_RTTHREAD    && pCtl->AsyncIOSem != NIL_RTSEMEVENT
     7423               && pCtl->SuspendIOSem != NIL_RTSEMEVENT  && PDMCritSectIsInitialized(&pCtl->AsyncIORequestLock));
     7424        Log(("%s: controller %d AIO thread id %#x; sem %p susp_sem %p\n", __FUNCTION__, i, pCtl->AsyncIOThread, pCtl->AsyncIOSem, pCtl->SuspendIOSem));
    74237425
    74247426        for (uint32_t j = 0; j < RT_ELEMENTS(pCtl->aIfs); j++)
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