Changeset 56392 in vbox for trunk/src/VBox/Devices/Storage
- Timestamp:
- Jun 12, 2015 2:56:14 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 100992
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DevATA.cpp
r56292 r56392 435 435 /** Magic delay before triggering interrupts in DMA mode. */ 436 436 uint32_t DelayIRQMillies; 437 /** The mutexprotecting the request queue. */438 RTSEMMUTEX AsyncIORequestMutex;437 /** The lock protecting the request queue. */ 438 PDMCRITSECT AsyncIORequestLock; 439 439 /** The event semaphore the thread is waiting on during suspended I/O. */ 440 440 RTSEMEVENT SuspendIOSem; … … 704 704 static void ataAsyncIOClearRequests(PATACONTROLLER pCtl) 705 705 { 706 int rc; 707 708 rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT); 706 int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED); 709 707 AssertRC(rc); 708 710 709 pCtl->AsyncIOReqHead = 0; 711 710 pCtl->AsyncIOReqTail = 0; 712 rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex); 711 712 rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock); 713 713 AssertRC(rc); 714 714 } … … 717 717 static void ataAsyncIOPutRequest(PATACONTROLLER pCtl, const ATARequest *pReq) 718 718 { 719 int rc; 720 721 rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT); 719 int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED); 722 720 AssertRC(rc); 721 723 722 Assert((pCtl->AsyncIOReqHead + 1) % RT_ELEMENTS(pCtl->aAsyncIORequests) != pCtl->AsyncIOReqTail); 724 723 memcpy(&pCtl->aAsyncIORequests[pCtl->AsyncIOReqHead], pReq, sizeof(*pReq)); 725 724 pCtl->AsyncIOReqHead++; 726 725 pCtl->AsyncIOReqHead %= RT_ELEMENTS(pCtl->aAsyncIORequests); 727 rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex); 726 727 rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock); 728 728 AssertRC(rc); 729 729 730 rc = PDMR3CritSectScheduleExitEvent(&pCtl->lock, pCtl->AsyncIOSem); 730 731 if (RT_FAILURE(rc)) … … 738 739 static const ATARequest *ataAsyncIOGetCurrentRequest(PATACONTROLLER pCtl) 739 740 { 740 int rc;741 741 const ATARequest *pReq; 742 742 743 rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);743 int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED); 744 744 AssertRC(rc); 745 745 746 if (pCtl->AsyncIOReqHead != pCtl->AsyncIOReqTail) 746 747 pReq = &pCtl->aAsyncIORequests[pCtl->AsyncIOReqTail]; 747 748 else 748 749 pReq = NULL; 749 rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex); 750 751 rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock); 750 752 AssertRC(rc); 751 753 return pReq; … … 763 765 static void ataAsyncIORemoveCurrentRequest(PATACONTROLLER pCtl, ATAAIO ReqType) 764 766 { 765 int rc; 766 767 rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT); 767 int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED); 768 768 AssertRC(rc); 769 769 770 if (pCtl->AsyncIOReqHead != pCtl->AsyncIOReqTail && pCtl->aAsyncIORequests[pCtl->AsyncIOReqTail].ReqType == ReqType) 770 771 { … … 772 773 pCtl->AsyncIOReqTail %= RT_ELEMENTS(pCtl->aAsyncIORequests); 773 774 } 774 rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex); 775 776 rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock); 775 777 AssertRC(rc); 776 778 } … … 786 788 static void ataAsyncIODumpRequests(PATACONTROLLER pCtl) 787 789 { 788 int rc; 789 uint8_t curr; 790 791 rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT); 790 int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED); 792 791 AssertRC(rc); 792 793 793 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; 795 795 do 796 796 { … … 822 822 curr = (curr + 1) % RT_ELEMENTS(pCtl->aAsyncIORequests); 823 823 } while (curr != pCtl->AsyncIOReqTail); 824 rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex); 824 825 rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock); 825 826 AssertRC(rc); 826 827 } … … 836 837 static bool ataAsyncIOIsIdle(PATACONTROLLER pCtl, bool fStrict) 837 838 { 838 int rc; 839 bool fIdle; 840 841 rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT); 839 int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED); 842 840 AssertRC(rc); 843 fIdle = pCtl->fRedoIdle; 841 842 bool fIdle = pCtl->fRedoIdle; 844 843 if (!fIdle) 845 844 fIdle = (pCtl->AsyncIOReqHead == pCtl->AsyncIOReqTail); 846 845 if (fStrict) 847 846 fIdle &= (pCtl->uAsyncIOState == ATA_AIO_NEW); 848 rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex); 847 848 rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock); 849 849 AssertRC(rc); 850 850 return fIdle; … … 5037 5037 { 5038 5038 /* 5039 * Take the mutexhere and recheck the idle indicator to avoid5039 * Take the lock here and recheck the idle indicator to avoid 5040 5040 * unnecessary work and racing ataR3WaitForAsyncIOIsIdle. 5041 5041 */ 5042 int rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT); AssertRC(rc); 5042 int rc = PDMCritSectEnter(&pCtl->AsyncIORequestLock, VERR_IGNORED); 5043 AssertRC(rc); 5043 5044 5044 5045 if ( pCtl->fSignalIdle … … 5049 5050 } 5050 5051 5051 rc = RTSemMutexRelease(pCtl->AsyncIORequestMutex); AssertRC(rc); 5052 rc = PDMCritSectLeave(&pCtl->AsyncIORequestLock); 5053 AssertRC(rc); 5052 5054 } 5053 5055 … … 5538 5540 5539 5541 /* Cleanup the state. */ 5540 /* Do not destroy request mutexyet, still needed for proper shutdown. */5542 /* Do not destroy request lock yet, still needed for proper shutdown. */ 5541 5543 pCtl->fShutdown = false; 5542 5544 … … 6416 6418 { 6417 6419 /* 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); 6419 6421 ASMAtomicWriteBool(&pThis->aCts[i].fSignalIdle, true); 6420 RTSemMutexRelease(pThis->aCts[i].AsyncIORequestMutex); 6422 PDMCritSectLeave(&pThis->aCts[i].AsyncIORequestLock); 6423 6421 6424 fRc = ataAsyncIOIsIdle(&pThis->aCts[i], false /*fStrict*/); 6422 6425 if (!fRc) … … 6914 6917 if (pThis->aCts[i].AsyncIOThread != NIL_RTTHREAD) 6915 6918 { 6916 int rc = RTSemMutexRequest(pThis->aCts[i].AsyncIORequestMutex, RT_INDEFINITE_WAIT);6919 int rc = PDMCritSectEnter(&pThis->aCts[i].AsyncIORequestLock, VERR_IGNORED); 6917 6920 AssertRC(rc); 6918 6921 … … 6921 6924 AssertRC(rc); 6922 6925 6923 rc = RTSemMutexRelease(pThis->aCts[i].AsyncIORequestMutex);6926 rc = PDMCritSectLeave(&pThis->aCts[i].AsyncIORequestLock); 6924 6927 AssertRC(rc); 6925 6928 … … 7029 7032 for (uint32_t i = 0; i < RT_ELEMENTS(pThis->aCts); i++) 7030 7033 { 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); 7036 7036 if (pThis->aCts[i].AsyncIOSem != NIL_RTSEMEVENT) 7037 7037 { … … 7123 7123 pThis->aCts[i].AsyncIOSem = NIL_RTSEMEVENT; 7124 7124 pThis->aCts[i].SuspendIOSem = NIL_RTSEMEVENT; 7125 pThis->aCts[i].AsyncIORequestMutex = NIL_RTSEMMUTEX;7126 7125 pThis->aCts[i].AsyncIOThread = NIL_RTTHREAD; 7127 7126 } … … 7376 7375 #endif /* VBOX_WITH_STATISTICS */ 7377 7376 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); 7382 7384 } 7383 7385 … … 7413 7415 rc = RTSemEventCreate(&pCtl->SuspendIOSem); 7414 7416 AssertLogRelRCReturn(rc, rc); 7415 rc = RTSemMutexCreate(&pCtl->AsyncIORequestMutex); 7416 AssertLogRelRCReturn(rc, rc); 7417 7417 7418 ataAsyncIOClearRequests(pCtl); 7418 7419 rc = RTThreadCreateF(&pCtl->AsyncIOThread, ataAsyncIOLoop, (void *)pCtl, 128*1024 /*cbStack*/, 7419 7420 RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "ATA-%u", i); 7420 7421 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)); 7423 7425 7424 7426 for (uint32_t j = 0; j < RT_ELEMENTS(pCtl->aIfs); j++)
Note:
See TracChangeset
for help on using the changeset viewer.