VirtualBox

Ignore:
Timestamp:
Jul 21, 2010 11:44:27 AM (14 years ago)
Author:
vboxsync
Message:

AsyncCompletion: Don't do the credit updating if the bandwidth is unlimited. Saves a few CPU cycles and might fix I/O timeouts.

File:
1 edited

Legend:

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

    r30297 r30952  
    518518bool pdmacFileBwMgrIsTransferAllowed(PPDMACFILEBWMGR pBwMgr, uint32_t cbTransfer)
    519519{
    520     bool fAllowed = false;
     520    bool fAllowed = true;
    521521
    522522    LogFlowFunc(("pBwMgr=%p cbTransfer=%u\n", pBwMgr, cbTransfer));
    523523
    524     uint32_t cbOld = ASMAtomicSubU32(&pBwMgr->cbVMTransferAllowed, cbTransfer);
    525     if (RT_LIKELY(cbOld >= cbTransfer))
    526         fAllowed = true;
    527     else
    528     {
    529         /* We are out of ressources  Check if we can update again. */
    530         uint64_t tsNow          = RTTimeSystemNanoTS();
    531         uint64_t tsUpdatedLast  = ASMAtomicUoReadU64(&pBwMgr->tsUpdatedLast);
    532 
    533         if (tsNow - tsUpdatedLast >= (1000*1000*1000))
     524    if (pBwMgr->cbVMTransferPerSecMax != UINT32_MAX) /* No need to check if bandwidth is unlimited. */
     525    {
     526        uint32_t cbOld = ASMAtomicSubU32(&pBwMgr->cbVMTransferAllowed, cbTransfer);
     527        if (RT_LIKELY(cbOld >= cbTransfer))
     528            fAllowed = true;
     529        else
    534530        {
    535             if (ASMAtomicCmpXchgU64(&pBwMgr->tsUpdatedLast, tsNow, tsUpdatedLast))
     531            fAllowed = false;
     532
     533            /* We are out of ressources  Check if we can update again. */
     534            uint64_t tsNow          = RTTimeSystemNanoTS();
     535            uint64_t tsUpdatedLast  = ASMAtomicUoReadU64(&pBwMgr->tsUpdatedLast);
     536
     537            if (tsNow - tsUpdatedLast >= (1000*1000*1000))
    536538            {
    537                 if (pBwMgr->cbVMTransferPerSecStart < pBwMgr->cbVMTransferPerSecMax)
     539                if (ASMAtomicCmpXchgU64(&pBwMgr->tsUpdatedLast, tsNow, tsUpdatedLast))
    538540                {
    539                    pBwMgr->cbVMTransferPerSecStart = RT_MIN(pBwMgr->cbVMTransferPerSecMax, pBwMgr->cbVMTransferPerSecStart + pBwMgr->cbVMTransferPerSecStep);
    540                    LogFlow(("AIOMgr: Increasing maximum bandwidth to %u bytes/sec\n", pBwMgr->cbVMTransferPerSecStart));
     541                    if (pBwMgr->cbVMTransferPerSecStart < pBwMgr->cbVMTransferPerSecMax)
     542                    {
     543                       pBwMgr->cbVMTransferPerSecStart = RT_MIN(pBwMgr->cbVMTransferPerSecMax, pBwMgr->cbVMTransferPerSecStart + pBwMgr->cbVMTransferPerSecStep);
     544                       LogFlow(("AIOMgr: Increasing maximum bandwidth to %u bytes/sec\n", pBwMgr->cbVMTransferPerSecStart));
     545                    }
     546
     547                    /* Update */
     548                    ASMAtomicWriteU32(&pBwMgr->cbVMTransferAllowed, pBwMgr->cbVMTransferPerSecStart - cbTransfer);
     549                    fAllowed = true;
     550                    LogFlow(("AIOMgr: Refreshed bandwidth\n"));
    541551                }
    542 
    543                 /* Update */
    544                 ASMAtomicWriteU32(&pBwMgr->cbVMTransferAllowed, pBwMgr->cbVMTransferPerSecStart - cbTransfer);
    545                 fAllowed = true;
    546                 LogFlow(("AIOMgr: Refreshed bandwidth\n"));
    547552            }
     553            else
     554                ASMAtomicAddU32(&pBwMgr->cbVMTransferAllowed, cbTransfer);
    548555        }
    549         else
    550             ASMAtomicAddU32(&pBwMgr->cbVMTransferAllowed, cbTransfer);
    551556    }
    552557
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