VirtualBox

Changeset 24623 in vbox for trunk


Ignore:
Timestamp:
Nov 12, 2009 8:04:13 PM (15 years ago)
Author:
vboxsync
Message:

Virtio: small optimization (static TX buffer)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DevVirtioNet.cpp

    r24616 r24623  
    225225PDMBOTHCBDECL(void)     vnetReset(void *pState);
    226226PDMBOTHCBDECL(void)     vnetReady(void *pState);
    227 #ifdef DEBUG
    228 static const char *vnetGetQueueName(void *pvState, PVQUEUE pQueue);
    229 #endif /* DEBUG */
    230227RT_C_DECLS_END
    231228
     
    982979              pState->Queues[i].uNextUsedIndex,
    983980              pState->Queues[i].uPageNumber));
    984 
    985981}
    986982#else
    987 #define vpciDumpState(x, s)
     983# define vpciDumpState(x, s)  do {} while (0)
    988984#endif
    989985
     
    12661262    uint16_t uStatus;
    12671263};
    1268 
    12691264AssertCompileMemberOffset(struct VNetPCIConfig, uStatus, 6);
    12701265
     
    12901285    uint32_t    padding;
    12911286#endif
    1292     PTMTIMERR3  pLinkUpTimer;                             /**< Link Up(/Restore) Timer. */
     1287
     1288    /** transmit buffer */
     1289    R3PTRTYPE(uint8_t*)     pTxBuf;
     1290    /**< Link Up(/Restore) Timer. */
     1291    PTMTIMERR3              pLinkUpTimer;
    12931292
    12941293    /** PCI config area holding MAC address as well as TBD. */
    1295     struct VNetPCIConfig config;
     1294    struct VNetPCIConfig    config;
    12961295    /** MAC address obtained from the configuration. */
    1297     RTMAC       macConfigured;
     1296    RTMAC                   macConfigured;
    12981297    /** True if physical cable is attached in configuration. */
    1299     bool        fCableConnected;
     1298    bool                    fCableConnected;
    13001299
    13011300    /** Number of packet being sent/received to show in debug log. */
    1302     uint32_t    u32PktNo;
     1301    uint32_t                u32PktNo;
    13031302
    13041303    /** Locked state -- no state alteration possible. */
    1305     bool        fLocked;
     1304    bool                    fLocked;
    13061305
    13071306    /** N/A: */
    1308     bool volatile fMaybeOutOfSpace;
    1309 
    1310     R3PTRTYPE(PVQUEUE) pRxQueue;
    1311     R3PTRTYPE(PVQUEUE) pTxQueue;
    1312     R3PTRTYPE(PVQUEUE) pCtlQueue;
     1307    bool volatile           fMaybeOutOfSpace;
     1308
     1309    R3PTRTYPE(PVQUEUE)      pRxQueue;
     1310    R3PTRTYPE(PVQUEUE)      pTxQueue;
     1311    R3PTRTYPE(PVQUEUE)      pCtlQueue;
    13131312    /* Receive-blocking-related fields ***************************************/
    13141313
     
    13181317    /* Statistic fields ******************************************************/
    13191318
    1320     STAMCOUNTER                         StatReceiveBytes;
    1321     STAMCOUNTER                         StatTransmitBytes;
     1319    STAMCOUNTER             StatReceiveBytes;
     1320    STAMCOUNTER             StatTransmitBytes;
    13221321#if defined(VBOX_WITH_STATISTICS)
    1323     STAMPROFILEADV                      StatReceive;
    1324     STAMPROFILEADV                      StatTransmit;
    1325     STAMPROFILEADV                      StatTransmitSend;
    1326     STAMPROFILE                         StatRxOverflow;
    1327     STAMCOUNTER                         StatRxOverflowWakeup;
     1322    STAMPROFILEADV          StatReceive;
     1323    STAMPROFILEADV          StatTransmit;
     1324    STAMPROFILEADV          StatTransmitSend;
     1325    STAMPROFILE             StatRxOverflow;
     1326    STAMCOUNTER             StatRxOverflowWakeup;
    13281327#endif /* VBOX_WITH_STATISTICS */
    13291328
     
    13381337struct VNetHdr
    13391338{
    1340     uint8_t u8Flags;
    1341     uint8_t u8GSOType;
     1339    uint8_t  u8Flags;
     1340    uint8_t  u8GSOType;
    13421341    uint16_t u16HdrLen;
    13431342    uint16_t u16GSOSize;
     
    13471346typedef struct VNetHdr VNETHDR;
    13481347typedef VNETHDR *PVNETHDR;
     1348AssertCompileSize(VNETHDR, 10);
    13491349
    13501350AssertCompileMemberOffset(VNETSTATE, VPCI, 0);
     
    18001800        else
    18011801        {
    1802             uint8_t *pFrame = (uint8_t *)RTMemAllocZ(VNET_MAX_FRAME_SIZE);
    1803             if (!pFrame)
    1804             {
    1805                 Log(("%s vnetQueueTransmit: Failed to allocate %u bytes.\n",
    1806                      INSTANCE(pState), VNET_MAX_FRAME_SIZE));
    1807                 vqueueElemFree(&elem);
    1808                 break; /* For now we simply ignore the header, but it must be there anyway! */
    1809             }
    1810 
    18111802            /* Assemble a complete frame. */
    18121803            for (unsigned int i = 1; i < elem.nOut && uOffset < VNET_MAX_FRAME_SIZE; i++)
     
    18191810                }
    18201811                PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[i].addr,
    1821                                   pFrame + uOffset, uSize);
     1812                                  pState->pTxBuf + uOffset, uSize);
    18221813                uOffset += uSize;
    18231814            }
    18241815            STAM_PROFILE_ADV_START(&pState->StatTransmitSend, a);
    1825             int rc = pState->pDrv->pfnSend(pState->pDrv, pFrame, uOffset);
     1816            int rc = pState->pDrv->pfnSend(pState->pDrv, pState->pTxBuf, uOffset);
    18261817            STAM_PROFILE_ADV_STOP(&pState->StatTransmitSend, a);
    18271818            STAM_REL_COUNTER_ADD(&pState->StatTransmitBytes, uOffset);
    1828             RTMemFree(pFrame);
    18291819        }
    18301820        vqueuePut(&pState->VPCI, pQueue, &elem, sizeof(VNETHDR) + uOffset);
     
    19681958    rc = SSMR3GetMem(pSSM, &macConfigured, sizeof(macConfigured));
    19691959    AssertRCReturn(rc, rc);
    1970     if (   memcmp(&macConfigured, &pState->macConfigured, sizeof(macConfigured))
    1971            && (uPass == 0 || !PDMDevHlpVMTeleportedAndNotFullyResumedYet(pDevIns)) )
     1960    if (memcmp(&macConfigured, &pState->macConfigured, sizeof(macConfigured))
     1961        && (uPass == 0 || !PDMDevHlpVMTeleportedAndNotFullyResumedYet(pDevIns)))
    19721962        LogRel(("%s: The mac address differs: config=%RTmac saved=%RTmac\n", INSTANCE(pState), &pState->macConfigured, &macConfigured));
    19731963
     
    20512041    pState->INetworkConfig.pfnSetLinkState   = vnetSetLinkState;
    20522042
     2043    pState->pTxBuf = (uint8_t *)RTMemAllocZ(VNET_MAX_FRAME_SIZE);
     2044    AssertMsgReturn(pState->pTxBuf,
     2045                    ("Cannot allocate TX buffer for virtio-net device\n"), VERR_NO_MEMORY);
     2046
    20532047    /* Register save/restore state handlers. */
    20542048    rc = PDMDevHlpSSMRegisterEx(pDevIns, VNET_SAVEDSTATE_VERSION, sizeof(VNETSTATE), NULL,
     
    20572051                                vnetLoadPrep, vnetLoadExec, NULL);
    20582052    if (RT_FAILURE(rc))
    2059     return rc;
     2053        return rc;
    20602054
    20612055    /* Create the RX notifier signaller. */
     
    21352129        RTSemEventDestroy(pState->hEventMoreRxDescAvail);
    21362130        pState->hEventMoreRxDescAvail = NIL_RTSEMEVENT;
     2131    }
     2132
     2133    if (pState->pTxBuf)
     2134    {
     2135        RTMemFree(pState->pTxBuf);
     2136        pState->pTxBuf = NULL;
    21372137    }
    21382138
     
    23482348#endif /* IN_RING3 */
    23492349#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
    2350 
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