VirtualBox

Ignore:
Timestamp:
Jan 27, 2013 8:23:39 PM (12 years ago)
Author:
vboxsync
Message:

AsyncCompletion: Only use range locks if the request is unaligned, pass everything through otherwise

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/PDMAsyncCompletionFileNormal.cpp

    r44235 r44397  
    638638static bool pdmacFileAioMgrNormalIsRangeLocked(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint,
    639639                                               RTFOFF offStart, size_t cbRange,
    640                                                PPDMACTASKFILE pTask)
     640                                               PPDMACTASKFILE pTask, bool fAlignedReq)
    641641{
    642642    AssertMsg(   pTask->enmTransferType == PDMACTASKFILETRANSFER_WRITE
    643643              || pTask->enmTransferType == PDMACTASKFILETRANSFER_READ,
    644644                 ("Invalid task type %d\n", pTask->enmTransferType));
     645
     646    /*
     647     * If there is no unaligned request active and the current one is aligned
     648     * just pass it through.
     649     */
     650    if (!pEndpoint->AioMgr.cLockedReqsActive && fAlignedReq)
     651        return false;
    645652
    646653    PPDMACFILERANGELOCK pRangeLock;
     
    659666
    660667    /* Check whether we have one of the situations explained below */
    661     if (   pRangeLock
    662 #if 0 /** @todo later. For now we will just block all requests if they interfere */
    663         && (   (pRangeLock->fReadLock && pTask->enmTransferType == PDMACTASKFILETRANSFER_WRITE)
    664             || (!pRangeLock->fReadLock)
    665 #endif
    666         )
     668    if (pRangeLock)
    667669    {
    668670        /* Add to the list. */
     
    690692                                          PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint,
    691693                                          RTFOFF offStart, size_t cbRange,
    692                                           PPDMACTASKFILE pTask)
     694                                          PPDMACTASKFILE pTask, bool fAlignedReq)
    693695{
    694696    LogFlowFunc(("pAioMgr=%#p pEndpoint=%#p offStart=%RTfoff cbRange=%zu pTask=%#p\n",
    695697                 pAioMgr, pEndpoint, offStart, cbRange, pTask));
    696698
    697     AssertMsg(!pdmacFileAioMgrNormalIsRangeLocked(pEndpoint, offStart, cbRange, pTask),
     699    AssertMsg(!pdmacFileAioMgrNormalIsRangeLocked(pEndpoint, offStart, cbRange, pTask, fAlignedReq),
    698700              ("Range is already locked offStart=%RTfoff cbRange=%u\n",
    699701               offStart, cbRange));
     702
     703    /*
     704     * If there is no unaligned request active and the current one is aligned
     705     * just don't use the lock.
     706     */
     707    if (!pEndpoint->AioMgr.cLockedReqsActive && fAlignedReq)
     708    {
     709        pTask->pRangeLock = NULL;
     710        return VINF_SUCCESS;
     711    }
    700712
    701713    PPDMACFILERANGELOCK pRangeLock = (PPDMACFILERANGELOCK)RTMemCacheAlloc(pAioMgr->hMemCacheRangeLocks);
     
    716728    /* Let the task point to its lock. */
    717729    pTask->pRangeLock = pRangeLock;
     730    pEndpoint->AioMgr.cLockedReqsActive++;
    718731
    719732    return VINF_SUCCESS;
     
    729742                 pAioMgr, pEndpoint, pRangeLock));
    730743
    731     AssertPtr(pRangeLock);
     744    /* pRangeLock can be NULL if there was no lock assigned with the task. */
     745    if (!pRangeLock)
     746        return NULL;
     747
    732748    Assert(pRangeLock->cRefs == 1);
    733749
     
    737753    pRangeLock->pWaitingTasksTail = NULL;
    738754    RTMemCacheFree(pAioMgr->hMemCacheRangeLocks, pRangeLock);
     755    pEndpoint->AioMgr.cLockedReqsActive--;
    739756
    740757    return pTasksWaitingHead;
     
    772789     */
    773790    int  rc = VINF_SUCCESS;
    774     bool fLocked = pdmacFileAioMgrNormalIsRangeLocked(pEndpoint, pTask->Off, pTask->DataSeg.cbSeg, pTask);
     791    bool fLocked = pdmacFileAioMgrNormalIsRangeLocked(pEndpoint, pTask->Off, pTask->DataSeg.cbSeg, pTask,
     792                                                      true /* fAlignedReq */);
    775793    if (!fLocked)
    776794    {
     
    800818        rc = pdmacFileAioMgrNormalRangeLock(pAioMgr, pEndpoint, pTask->Off,
    801819                                            pTask->DataSeg.cbSeg,
    802                                             pTask);
     820                                            pTask, true /* fAlignedReq */);
    803821
    804822        if (RT_SUCCESS(rc))
     
    826844    size_t cbToTransfer = RT_ALIGN_Z(pTask->DataSeg.cbSeg + (pTask->Off - offStart), 512);
    827845    PDMACTASKFILETRANSFER enmTransferType = pTask->enmTransferType;
     846    bool fAlignedReq =     cbToTransfer == pTask->DataSeg.cbSeg
     847                        && offStart == pTask->Off;
    828848
    829849    AssertMsg(   pTask->enmTransferType == PDMACTASKFILETRANSFER_WRITE
     
    853873     */
    854874    int  rc = VINF_SUCCESS;
    855     bool fLocked = pdmacFileAioMgrNormalIsRangeLocked(pEndpoint, offStart, cbToTransfer, pTask);
     875    bool fLocked = pdmacFileAioMgrNormalIsRangeLocked(pEndpoint, offStart, cbToTransfer, pTask, fAlignedReq);
    856876    if (!fLocked)
    857877    {
     
    863883        AssertMsg(hReq != NIL_RTFILEAIOREQ, ("Out of request handles\n"));
    864884
    865         if (   RT_UNLIKELY(cbToTransfer != pTask->DataSeg.cbSeg)
    866             || RT_UNLIKELY(offStart != pTask->Off)
     885        if (   !fAlignedReq
    867886            || ((pEpClassFile->uBitmaskAlignment & (RTR3UINTPTR)pvBuf) != (RTR3UINTPTR)pvBuf))
    868887        {
     
    929948            AssertRC(rc);
    930949
    931             rc = pdmacFileAioMgrNormalRangeLock(pAioMgr, pEndpoint, offStart, cbToTransfer, pTask);
    932 
     950            rc = pdmacFileAioMgrNormalRangeLock(pAioMgr, pEndpoint, offStart, cbToTransfer, pTask, fAlignedReq);
    933951            if (RT_SUCCESS(rc))
    934952            {
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