Changeset 30952 in vbox for trunk/src/VBox/VMM/PDMAsyncCompletionFile.cpp
- Timestamp:
- Jul 21, 2010 11:44:27 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/PDMAsyncCompletionFile.cpp
r30297 r30952 518 518 bool pdmacFileBwMgrIsTransferAllowed(PPDMACFILEBWMGR pBwMgr, uint32_t cbTransfer) 519 519 { 520 bool fAllowed = false;520 bool fAllowed = true; 521 521 522 522 LogFlowFunc(("pBwMgr=%p cbTransfer=%u\n", pBwMgr, cbTransfer)); 523 523 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 534 530 { 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)) 536 538 { 537 if ( pBwMgr->cbVMTransferPerSecStart < pBwMgr->cbVMTransferPerSecMax)539 if (ASMAtomicCmpXchgU64(&pBwMgr->tsUpdatedLast, tsNow, tsUpdatedLast)) 538 540 { 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")); 541 551 } 542 543 /* Update */544 ASMAtomicWriteU32(&pBwMgr->cbVMTransferAllowed, pBwMgr->cbVMTransferPerSecStart - cbTransfer);545 fAllowed = true;546 LogFlow(("AIOMgr: Refreshed bandwidth\n"));547 552 } 553 else 554 ASMAtomicAddU32(&pBwMgr->cbVMTransferAllowed, cbTransfer); 548 555 } 549 else550 ASMAtomicAddU32(&pBwMgr->cbVMTransferAllowed, cbTransfer);551 556 } 552 557
Note:
See TracChangeset
for help on using the changeset viewer.