Changeset 25148 in vbox
- Timestamp:
- Dec 2, 2009 2:20:41 PM (15 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DevVirtioNet.cpp
r24982 r25148 114 114 VPCISTATE VPCI; 115 115 116 PDMCRITSECT csRx; /**< Protects RX queue. */ 117 116 118 PDMINETWORKPORT INetworkPort; 117 119 PDMINETWORKCONFIG INetworkConfig; … … 250 252 } 251 253 254 DECLINLINE(int) vnetCsRxEnter(PVNETSTATE pState, int rcBusy) 255 { 256 return PDMCritSectEnter(&pState->csRx, rcBusy); 257 } 258 259 DECLINLINE(void) vnetCsRxLeave(PVNETSTATE pState) 260 { 261 PDMCritSectLeave(&pState->csRx); 262 } 263 252 264 253 265 PDMBOTHCBDECL(uint32_t) vnetGetHostFeatures(void *pvState) … … 313 325 VNETSTATE *pState = (VNETSTATE*)pvState; 314 326 Log(("%s Reset triggered\n", INSTANCE(pState))); 327 328 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY); 329 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 330 { 331 LogRel(("vnetReset failed to enter RX critical section!\n")); 332 return; 333 } 315 334 vpciReset(&pState->VPCI); 335 vnetCsRxLeave(pState); 336 316 337 // TODO: Implement reset 317 338 if (pState->fCableConnected) … … 358 379 VNETSTATE *pState = (VNETSTATE *)pvUser; 359 380 381 int rc = vnetCsEnter(pState, VERR_SEM_BUSY); 382 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 383 return; 360 384 STATUS |= VNET_S_LINK_UP; 361 385 vpciRaiseInterrupt(&pState->VPCI, VERR_SEM_BUSY, VPCI_ISR_CONFIG); 362 386 vnetWakeupReceive(pDevIns); 387 vnetCsLeave(pState); 363 388 } 364 389 … … 457 482 static int vnetCanReceive(VNETSTATE *pState) 458 483 { 459 int rc = vnetCsEnter(pState, VERR_SEM_BUSY); 484 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY); 485 AssertRCReturn(rc, rc); 486 460 487 LogFlow(("%s vnetCanReceive\n", INSTANCE(pState))); 461 488 if (!(pState->VPCI.uStatus & VPCI_STATUS_DRV_OK)) … … 475 502 476 503 LogFlow(("%s vnetCanReceive -> %Vrc\n", INSTANCE(pState), rc)); 477 vnetCs Leave(pState);504 vnetCsRxLeave(pState); 478 505 return rc; 479 506 } … … 675 702 { 676 703 VNETSTATE *pState = IFACE_TO_STATE(pInterface, INetworkPort); 677 int rc = VINF_SUCCESS;678 704 679 705 Log2(("%s vnetReceive: pvBuf=%p cb=%u\n", INSTANCE(pState), pvBuf, cb)); 680 rc = vnetCanReceive(pState);706 int rc = vnetCanReceive(pState); 681 707 if (RT_FAILURE(rc)) 682 708 return rc; … … 693 719 if (vnetAddressFilter(pState, pvBuf, cb)) 694 720 { 695 rc = vnetHandleRxPacket(pState, pvBuf, cb); 696 STAM_REL_COUNTER_ADD(&pState->StatReceiveBytes, cb); 721 rc = vnetCsRxEnter(pState, VERR_SEM_BUSY); 722 if (RT_SUCCESS(rc)) 723 { 724 rc = vnetHandleRxPacket(pState, pvBuf, cb); 725 STAM_REL_COUNTER_ADD(&pState->StatReceiveBytes, cb); 726 vnetCsRxLeave(pState); 727 } 697 728 } 698 729 vpciSetReadLed(&pState->VPCI, false); 699 730 STAM_PROFILE_ADV_STOP(&pState->StatReceive, a); 700 701 731 return rc; 702 732 } … … 856 886 VNETSTATE *pState = (VNETSTATE*)pvUser; 857 887 888 int rc = vnetCsEnter(pState, VERR_SEM_BUSY); 889 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 890 return; 858 891 vringSetNotification(&pState->VPCI, &pState->pTxQueue->VRing, true); 859 892 Log3(("%s vnetTxTimer: Expired, %d packets pending\n", INSTANCE(pState), 860 893 vringReadAvailIndex(&pState->VPCI, &pState->pTxQueue->VRing) - pState->pTxQueue->uNextAvailIndex)); 861 894 vnetTransmitPendingPackets(pState, pState->pTxQueue); 895 vnetCsLeave(pState); 862 896 } 863 897 … … 1114 1148 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*); 1115 1149 1116 int rc = vnetCs Enter(pState, VERR_SEM_BUSY);1150 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY); 1117 1151 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 1118 1152 return rc; 1119 vnetCs Leave(pState);1153 vnetCsRxLeave(pState); 1120 1154 return VINF_SUCCESS; 1121 1155 } … … 1168 1202 VNETSTATE* pState = PDMINS_2_DATA(pDevIns, VNETSTATE*); 1169 1203 1170 int rc = vnetCs Enter(pState, VERR_SEM_BUSY);1204 int rc = vnetCsRxEnter(pState, VERR_SEM_BUSY); 1171 1205 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 1172 1206 return rc; 1173 vnetCs Leave(pState);1207 vnetCsRxLeave(pState); 1174 1208 return VINF_SUCCESS; 1175 1209 } … … 1395 1429 ("Cannot allocate TX buffer for virtio-net device\n"), VERR_NO_MEMORY); 1396 1430 1431 /* Initialize critical section. */ 1432 char szTmp[sizeof(pState->VPCI.szInstance) + 2]; 1433 RTStrPrintf(szTmp, sizeof(szTmp), "%sRX", pState->VPCI.szInstance); 1434 rc = PDMDevHlpCritSectInit(pDevIns, &pState->csRx, szTmp); 1435 if (RT_FAILURE(rc)) 1436 return rc; 1437 1397 1438 /* Map our ports to IO space. */ 1398 1439 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, … … 1505 1546 pState->pTxBuf = NULL; 1506 1547 } 1548 if (PDMCritSectIsInitialized(&pState->csRx)) 1549 PDMR3CritSectDelete(&pState->csRx); 1507 1550 1508 1551 return vpciDestruct(&pState->VPCI); … … 1563 1606 AssertLogRelReturnVoid(iLUN == 0); 1564 1607 1565 vnetCsEnter(pState, VERR_SEM_BUSY); 1608 int rc = vnetCsEnter(pState, VERR_SEM_BUSY); 1609 if (RT_FAILURE(rc)) 1610 { 1611 LogRel(("vnetDetach failed to enter critical section!\n")); 1612 return; 1613 } 1566 1614 1567 1615 /* … … 1594 1642 AssertLogRelReturn(iLUN == 0, VERR_PDM_NO_SUCH_LUN); 1595 1643 1596 vnetCsEnter(pState, VERR_SEM_BUSY); 1644 int rc = vnetCsEnter(pState, VERR_SEM_BUSY); 1645 if (RT_FAILURE(rc)) 1646 { 1647 LogRel(("vnetAttach failed to enter critical section!\n")); 1648 return rc; 1649 } 1597 1650 1598 1651 /* 1599 1652 * Attach the driver. 1600 1653 */ 1601 intrc = PDMDevHlpDriverAttach(pDevIns, 0, &pState->VPCI.IBase, &pState->pDrvBase, "Network Port");1654 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pState->VPCI.IBase, &pState->pDrvBase, "Network Port"); 1602 1655 if (RT_SUCCESS(rc)) 1603 1656 { -
trunk/src/VBox/Devices/VirtIO/Virtio.cpp
r25007 r25148 258 258 int vpciRaiseInterrupt(VPCISTATE *pState, int rcBusy, uint8_t u8IntCause) 259 259 { 260 int rc = vpciCsEnter(pState, rcBusy);261 if (RT_UNLIKELY(rc != VINF_SUCCESS))262 return rc;260 // int rc = vpciCsEnter(pState, rcBusy); 261 // if (RT_UNLIKELY(rc != VINF_SUCCESS)) 262 // return rc; 263 263 264 264 STAM_COUNTER_INC(&pState->StatIntsRaised); … … 268 268 pState->uISR |= u8IntCause; 269 269 PDMDevHlpPCISetIrq(pState->CTX_SUFF(pDevIns), 0, 1); 270 vpciCsLeave(pState);270 // vpciCsLeave(pState); 271 271 return VINF_SUCCESS; 272 272 } … … 314 314 const char *szInst = INSTANCE(pState); 315 315 STAM_PROFILE_ADV_START(&pState->CTXSUFF(StatIORead), a); 316 317 /* 318 * We probably do not need to enter critical section when reading registers 319 * as the most of them are either constant or being changed during 320 * initialization only, the exception being ISR which can be raced by all 321 * threads but I see no big harm in it. It also happens to be the most read 322 * register as it gets read in interrupt handler. By dropping cs protection 323 * here we gain the ability to deliver RX packets to the guest while TX is 324 * holding cs transmitting queued packets. 325 * 326 rc = vpciCsEnter(pState, VINF_IOM_HC_IOPORT_READ); 327 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 328 { 329 STAM_PROFILE_ADV_STOP(&pState->CTXSUFF(StatIORead), a); 330 return rc; 331 }*/ 316 332 317 333 port -= pState->addrIOPort; … … 371 387 szInst, port, cb*2, *pu32)); 372 388 STAM_PROFILE_ADV_STOP(&pState->CTXSUFF(StatIORead), a); 389 //vpciCsLeave(pState); 373 390 return rc; 374 391 } … … 405 422 bool fHasBecomeReady; 406 423 STAM_PROFILE_ADV_START(&pState->CTXSUFF(StatIOWrite), a); 424 425 rc = vpciCsEnter(pState, VINF_IOM_HC_IOPORT_WRITE); 426 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 427 { 428 STAM_PROFILE_ADV_STOP(&pState->CTXSUFF(StatIOWrite), a); 429 return rc; 430 } 431 407 432 408 433 port -= pState->addrIOPort; … … 494 519 495 520 STAM_PROFILE_ADV_STOP(&pState->CTXSUFF(StatIOWrite), a); 521 vpciCsLeave(pState); 496 522 return rc; 497 523 }
Note:
See TracChangeset
for help on using the changeset viewer.