Changeset 71789 in vbox for trunk/src/VBox/Devices/Network
- Timestamp:
- Apr 9, 2018 4:09:39 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DevVirtioNet.cpp
r71788 r71789 1316 1316 break; /* For now we simply ignore the header, but it must be there anyway! */ 1317 1317 } 1318 else 1319 { 1320 VNETHDR Hdr; 1321 unsigned int uSize = 0; 1322 STAM_PROFILE_ADV_START(&pThis->StatTransmit, a); 1323 /* Compute total frame size. */ 1324 for (unsigned int i = 1; i < elem.nOut && uSize < VNET_MAX_FRAME_SIZE; i++) 1325 uSize += elem.aSegsOut[i].cb; 1326 Log5(("%s vnetTransmitPendingPackets: complete frame is %u bytes.\n", INSTANCE(pThis), uSize)); 1327 Assert(uSize <= VNET_MAX_FRAME_SIZE); 1328 /* Truncate oversized frames. */ 1329 if (uSize > VNET_MAX_FRAME_SIZE) 1330 uSize = VNET_MAX_FRAME_SIZE; 1331 if (pThis->pDrv && vnetReadHeader(pThis, elem.aSegsOut[0].addr, &Hdr, uSize)) 1318 RT_UNTRUSTED_VALIDATED_FENCE(); 1319 1320 VNETHDR Hdr; 1321 unsigned int uSize = 0; 1322 STAM_PROFILE_ADV_START(&pThis->StatTransmit, a); 1323 1324 /* Compute total frame size. */ 1325 for (unsigned int i = 1; i < elem.nOut && uSize < VNET_MAX_FRAME_SIZE; i++) 1326 uSize += elem.aSegsOut[i].cb; 1327 Log5(("%s vnetTransmitPendingPackets: complete frame is %u bytes.\n", INSTANCE(pThis), uSize)); 1328 Assert(uSize <= VNET_MAX_FRAME_SIZE); 1329 1330 /* Truncate oversized frames. */ 1331 if (uSize > VNET_MAX_FRAME_SIZE) 1332 uSize = VNET_MAX_FRAME_SIZE; 1333 if (pThis->pDrv && vnetReadHeader(pThis, elem.aSegsOut[0].addr, &Hdr, uSize)) 1334 { 1335 RT_UNTRUSTED_VALIDATED_FENCE(); 1336 STAM_REL_COUNTER_INC(&pThis->StatTransmitPackets); 1337 STAM_PROFILE_START(&pThis->StatTransmitSend, a); 1338 1339 PDMNETWORKGSO Gso; 1340 PDMNETWORKGSO *pGso = vnetSetupGsoCtx(&Gso, &Hdr); 1341 1342 /** @todo Optimize away the extra copying! (lazy bird) */ 1343 PPDMSCATTERGATHER pSgBuf; 1344 int rc = pThis->pDrv->pfnAllocBuf(pThis->pDrv, uSize, pGso, &pSgBuf); 1345 if (RT_SUCCESS(rc)) 1332 1346 { 1333 PDMNETWORKGSO Gso, *pGso; 1334 1335 STAM_REL_COUNTER_INC(&pThis->StatTransmitPackets); 1336 1337 STAM_PROFILE_START(&pThis->StatTransmitSend, a); 1338 1339 pGso = vnetSetupGsoCtx(&Gso, &Hdr); 1340 /** @todo Optimize away the extra copying! (lazy bird) */ 1341 PPDMSCATTERGATHER pSgBuf; 1342 int rc = pThis->pDrv->pfnAllocBuf(pThis->pDrv, uSize, pGso, &pSgBuf); 1343 if (RT_SUCCESS(rc)) 1347 Assert(pSgBuf->cSegs == 1); 1348 pSgBuf->cbUsed = uSize; 1349 1350 /* Assemble a complete frame. */ 1351 for (unsigned int i = 1; i < elem.nOut && uSize > 0; i++) 1344 1352 { 1345 Assert(pSgBuf->cSegs == 1); 1346 pSgBuf->cbUsed = uSize; 1347 /* Assemble a complete frame. */ 1348 for (unsigned int i = 1; i < elem.nOut && uSize > 0; i++) 1349 { 1350 unsigned int cbSegment = RT_MIN(uSize, elem.aSegsOut[i].cb); 1351 PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[i].addr, 1352 ((uint8_t*)pSgBuf->aSegs[0].pvSeg) + uOffset, 1353 cbSegment); 1354 uOffset += cbSegment; 1355 uSize -= cbSegment; 1356 } 1357 rc = vnetTransmitFrame(pThis, pSgBuf, pGso, &Hdr); 1353 unsigned int cbSegment = RT_MIN(uSize, elem.aSegsOut[i].cb); 1354 PDMDevHlpPhysRead(pThis->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[i].addr, 1355 ((uint8_t*)pSgBuf->aSegs[0].pvSeg) + uOffset, 1356 cbSegment); 1357 uOffset += cbSegment; 1358 uSize -= cbSegment; 1358 1359 } 1359 else 1360 { 1361 Log4(("virtio-net: failed to allocate SG buffer: size=%u rc=%Rrc\n", uSize, rc)); 1362 STAM_PROFILE_STOP(&pThis->StatTransmitSend, a); 1363 STAM_PROFILE_ADV_STOP(&pThis->StatTransmit, a); 1364 /* Stop trying to fetch TX descriptors until we get more bandwidth. */ 1365 break; 1366 } 1367 1360 rc = vnetTransmitFrame(pThis, pSgBuf, pGso, &Hdr); 1361 } 1362 else 1363 { 1364 Log4(("virtio-net: failed to allocate SG buffer: size=%u rc=%Rrc\n", uSize, rc)); 1368 1365 STAM_PROFILE_STOP(&pThis->StatTransmitSend, a); 1369 STAM_REL_COUNTER_ADD(&pThis->StatTransmitBytes, uOffset); 1366 STAM_PROFILE_ADV_STOP(&pThis->StatTransmit, a); 1367 /* Stop trying to fetch TX descriptors until we get more bandwidth. */ 1368 break; 1370 1369 } 1371 } 1370 1371 STAM_PROFILE_STOP(&pThis->StatTransmitSend, a); 1372 STAM_REL_COUNTER_ADD(&pThis->StatTransmitBytes, uOffset); 1373 } 1374 1372 1375 /* Remove this descriptor chain from the available ring */ 1373 1376 vqueueSkip(&pThis->VPCI, pQueue);
Note:
See TracChangeset
for help on using the changeset viewer.