VirtualBox

Changeset 28328 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 14, 2010 8:46:56 PM (15 years ago)
Author:
vboxsync
Message:

Network/D*: Moving XMIT threads, part 2.

Location:
trunk/src/VBox/Devices
Files:
4 edited

Legend:

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

    r28324 r28328  
    952952    PDMCRITSECT csRx;                                     /**< RX Critical section. */
    953953//    PDMCRITSECT csTx;                                     /**< TX Critical section. */
    954 #endif
    955 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    956     /** Transmit thread blocker. */
    957 # ifdef E1K_USE_SUPLIB_SEMEVENT
    958     SUPSEMEVENT hTxSem;
    959 # else
    960     RTSEMEVENT  hTxSem;
    961 # endif
    962 #endif
    963 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    964     PPDMTHREAD  pTxThread;                                    /**< Transmit thread. */
    965954#endif
    966955    /** Base address of memory-mapped registers. */
     
    38203809}
    38213810
    3822 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    3823 
    3824 /**
    3825  * Wake up callback for transmission thread.
    3826  *
    3827  * @returns VBox status code. Returning failure will naturally terminate the thread.
    3828  * @param   pDevIns     The pcnet device instance.
    3829  * @param   pThread     The thread.
    3830  */
    3831 static DECLCALLBACK(int) e1kTxThreadWakeUp(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
    3832 {
    3833     E1KSTATE *pState = PDMINS_2_DATA(pDevIns, E1KSTATE *);
    3834 #ifdef E1K_USE_SUPLIB_SEMEVENT
    3835     int rc = SUPSemEventSignal(PDMDevHlpGetVM(pDevIns)->pSession, pState->hTxSem);
    3836 #else
    3837     int rc = RTSemEventSignal(pState->hTxSem);
    3838 #endif
    3839     AssertRC(rc);
    3840     return VINF_SUCCESS;
    3841 }
    3842 
    3843 /**
    3844  * I/O thread for packet transmission.
    3845  *
    3846  * @returns VBox status code. Returning failure will naturally terminate the thread.
    3847  * @param   pDevIns     Pointer to device instance structure.
    3848  * @param   pThread     The thread.
    3849  * @thread  E1000_TX
    3850  */
    3851 static DECLCALLBACK(int) e1kTxThread(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
    3852 {
    3853     E1KSTATE *pState = PDMINS_2_DATA(pDevIns, E1KSTATE *);
    3854 
    3855     while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    3856     {
    3857 #ifdef E1K_USE_SUPLIB_SEMEVENT
    3858         int rc = SUPSemEventWaitNoResume(PDMDevHlpGetVM(pDevIns)->pSession, pState->hTxSem, RT_INDEFINITE_WAIT);
    3859 #else
    3860         int rc = RTSemEventWaitNoResume(pState->hTxSem, RT_INDEFINITE_WAIT);
    3861 #endif
    3862         if (rc == VERR_INTERRUPTED)
    3863             continue;
    3864         AssertRCReturn(rc, rc);
    3865         if (RT_UNLIKELY(pThread->enmState != PDMTHREADSTATE_RUNNING))
    3866             break;
    3867 
    3868         if (pThread->enmState == PDMTHREADSTATE_RUNNING)
    3869         {
    3870             rc = e1kXmitPending(pState, true /*fOnWorkerThread*/);
    3871             AssertMsgReturn(RT_SUCCESS(rc) || rc == VERR_TRY_AGAIN, ("%Rrc\n", rc), rc);
    3872         }
    3873     }
    3874     return VINF_SUCCESS;
    3875 }
    3876 
    3877 #endif /* VBOX_WITH_TX_THREAD_IN_NET_DEVICES */
    3878 
    38793811/**
    38803812 * Callback for consuming from transmit queue. It gets called in R3 whenever
     
    38923824    E1kLog2(("%s e1kTxQueueConsumer: Waking up TX thread...\n", INSTANCE(pState)));
    38933825
    3894 #ifndef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    38953826    int rc = e1kXmitPending(pState, false /*fOnWorkerThread*/);
    38963827    AssertMsg(RT_SUCCESS(rc) || rc == VERR_TRY_AGAIN, ("%Rrc\n", rc));
    3897 #else
    3898 # ifdef E1K_USE_SUPLIB_SEMEVENT
    3899     int rc = SUPSemEventSignal(PDMDevHlpGetVM(pDevIns)->pSession, pState->hTxSem);
    3900 # else
    3901     int rc = RTSemEventSignal(pState->hTxSem);
    3902 # endif
    3903     AssertRC(rc);
    3904 #endif
    39053828
    39063829    return true;
     
    39463869        E1kLog(("%s e1kRegWriteTDT: %d descriptors to process, waking up E1000_TX thread\n",
    39473870                 INSTANCE(pState), e1kGetTxLen(pState)));
    3948 #ifndef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    39493871        e1kCsTxLeave(pState);
    39503872
     
    39663888            AssertRC(rc);
    39673889        }
    3968 #else
    3969 # if (defined(IN_RING3) || defined(IN_RING0)) && defined(E1K_USE_SUPLIB_SEMEVENT)
    3970         rc = SUPSemEventSignal(PDMDevHlpGetVM(pState->CTX_SUFF(pDevIns))->pSession, pState->hTxSem);
    3971         AssertRC(rc);
    3972 # elif defined(IN_RING3)
    3973         rc = RTSemEventSignal(pState->hTxSem);
    3974         AssertRC(rc);
    3975 # else
    3976         PPDMQUEUEITEMCORE pItem = PDMQueueAlloc(pState->CTX_SUFF(pTxQueue));
    3977         if (RT_UNLIKELY(pItem))
    3978             PDMQueueInsert(pState->CTX_SUFF(pTxQueue), pItem);
    3979 # endif /* !IN_RING3 */
    3980 #endif
    3981 
    39823890    }
    39833891    else
     
    55345442            pState->hEventMoreRxDescAvail = NIL_RTSEMEVENT;
    55355443        }
    5536 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    5537 # ifdef E1K_USE_SUPLIB_SEMEVENT
    5538         if (pState->hTxSem != NIL_SUPSEMEVENT)
    5539         {
    5540             SUPSemEventClose(PDMDevHlpGetVM(pDevIns)->pSession, pState->hTxSem);
    5541             pState->hTxSem = NIL_SUPSEMEVENT;
    5542         }
    5543 # else
    5544         if (pState->hTxSem != NIL_RTSEMEVENT)
    5545         {
    5546             RTSemEventDestroy(pState->hTxSem);
    5547             pState->hTxSem = NIL_RTSEMEVENT;
    5548         }
    5549 # endif
    5550 #endif
    55515444#ifndef E1K_GLOBAL_MUTEX
    55525445        PDMR3CritSectDelete(&pState->csRx);
     
    56755568    RTStrPrintf(pState->szInstance, sizeof(pState->szInstance), "E1000#%d", iInstance);
    56765569    E1kLog(("%s Constructing new instance sizeof(E1KRXDESC)=%d\n", INSTANCE(pState), sizeof(E1KRXDESC)));
    5677 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    5678 # ifdef E1K_USE_SUPLIB_SEMEVENT
    5679     pState->hTxSem = NIL_SUPSEMEVENT;
    5680 # else
    5681     pState->hTxSem = NIL_RTSEMEVENT;
    5682 # endif
    5683 #endif
    56845570    pState->hEventMoreRxDescAvail = NIL_RTSEMEVENT;
    56855571
     
    59215807        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to attach the network LUN"));
    59225808
    5923 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    5924 # ifdef E1K_USE_SUPLIB_SEMEVENT
    5925     rc = SUPSemEventCreate(PDMDevHlpGetVM(pDevIns)->pSession, &pState->hTxSem);
    5926 # else
    5927     rc = RTSemEventCreate(&pState->hTxSem);
    5928 # endif
    5929     if (RT_FAILURE(rc))
    5930         return rc;
    5931 #endif
    59325809    rc = RTSemEventCreate(&pState->hEventMoreRxDescAvail);
    59335810    if (RT_FAILURE(rc))
     
    59355812
    59365813    e1kHardReset(pState);
    5937 
    5938 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    5939     rc = PDMDevHlpThreadCreate(pDevIns, &pState->pTxThread, pState, e1kTxThread, e1kTxThreadWakeUp, 0, RTTHREADTYPE_IO, "E1000_TX");
    5940     if (RT_FAILURE(rc))
    5941         return rc;
    5942 #endif
    59435814
    59445815#if defined(VBOX_WITH_STATISTICS) || defined(E1K_REL_STATS)
  • trunk/src/VBox/Devices/Network/DevPCNet.cpp

    r28320 r28328  
    241241    /** Partner of ILeds. */
    242242    R3PTRTYPE(PPDMILEDCONNECTORS)       pLedsConnector;
    243 
    244 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    245     /** Async send thread */
    246     RTSEMEVENT                          hSendEventSem;
    247     /** The Async send thread. */
    248     PPDMTHREAD                          pSendThread;
    249 #endif
    250243
    251244    /** Access critical section. */
     
    20672060    NOREF(pItem);
    20682061
    2069 #ifndef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    20702062    /*
    20712063     * Transmit as much as we can.
    20722064     */
    20732065    pcnetXmitPending(pThis, true /*fOnWorkerThread*/);
    2074 #else
    2075     /*
    2076      * Wake up the TX thread.
    2077      */
    2078     int rc = RTSemEventSignal(pThis->hSendEventSem);
    2079     AssertRC(rc);
    2080 #endif
     2066
    20812067    return true;
    20822068}
     
    23722358    pThis->aCSR[0] &= ~0x0008;
    23732359
    2374 #ifndef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    23752360    /*
    23762361     * Transmit pending packets if possible, defere it if we cannot do it
    23772362     * in the current context.
    23782363     */
    2379 # if defined(IN_RING0) || defined(IN_RC)
     2364#if defined(IN_RING0) || defined(IN_RC)
    23802365    if (!pThis->CTX_SUFF(pDrv))
    23812366    {
     
    23852370    }
    23862371    else
    2387 # endif
     2372#endif
    23882373    {
    23892374        int rc = pcnetXmitPending(pThis, false /*fOnWorkerThread*/);
     
    23922377        AssertRC(rc);
    23932378    }
    2394 #else  /* VBOX_WITH_TX_THREAD_IN_NET_DEVICES */
    2395     /*
    2396      * If we're in Ring-3 we should flush the queue now, in GC/R0 we'll queue a flush job.
    2397      */
    2398 # ifdef IN_RING3
    2399     int rc = RTSemEventSignal(pThis->hSendEventSem);
    2400     AssertRC(rc);
    2401 # else
    2402     PPDMQUEUEITEMCORE pItem = PDMQueueAlloc(pThis->CTX_SUFF(pXmitQueue));
    2403     if (RT_UNLIKELY(pItem))
    2404         PDMQueueInsert(pThis->CTX_SUFF(pXmitQueue), pItem);
    2405 # endif
    2406 #endif /* VBOX_WITH_TX_THREAD_IN_NET_DEVICES */
    24072379}
    24082380
     
    27112683}
    27122684
    2713 #ifdef IN_RING3
    2714 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    2715 
    2716 /**
    2717  * Async I/O thread for delayed sending of packets.
    2718  *
    2719  * @returns VBox status code. Returning failure will naturally terminate the thread.
    2720  * @param   pDevIns     The pcnet device instance.
    2721  * @param   pThread     The thread.
    2722  */
    2723 static DECLCALLBACK(int) pcnetAsyncSendThread(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
    2724 {
    2725     PCNetState *pThis = PDMINS_2_DATA(pDevIns, PCNetState *);
    2726 
    2727     /*
    2728      * We can enter this function in two states, initializing or resuming.
    2729      *
    2730      * The idea about the initializing bit is that we can do per-thread
    2731      * initialization while the creator thread can still pick up errors.
    2732      * At present, there is nothing to init, or at least nothing that
    2733      * need initing in the thread.
    2734      */
    2735     if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
    2736         return VINF_SUCCESS;
    2737 
    2738     /*
    2739      * Stay in the run-loop until we're supposed to leave the
    2740      * running state. If something really bad happens, we'll
    2741      * quit the loop while in the running state and return
    2742      * an error status to PDM and let it terminate the thread.
    2743      */
    2744     while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    2745     {
    2746         /*
    2747          * Block until we've got something to send or is supposed
    2748          * to leave the running state.
    2749          */
    2750         int rc = RTSemEventWait(pThis->hSendEventSem, RT_INDEFINITE_WAIT);
    2751         AssertRCReturn(rc, rc);
    2752         if (RT_UNLIKELY(pThread->enmState != PDMTHREADSTATE_RUNNING))
    2753             break;
    2754 
    2755         /*
    2756          * Perform async send.
    2757          */
    2758         rc = pcnetXmitPending(pThis, true /*fOnWorkerThread*/);
    2759         AssertMsg(rc == VINF_SUCCESS || rc == VERR_TRY_AGAIN, ("%Rrc\n", rc));
    2760    }
    2761 
    2762     /* The thread is being suspended or terminated. */
    2763     return VINF_SUCCESS;
    2764 }
    2765 
    2766 
    2767 /**
    2768  * Unblock the send thread so it can respond to a state change.
    2769  *
    2770  * @returns VBox status code.
    2771  * @param   pDevIns     The pcnet device instance.
    2772  * @param   pThread     The send thread.
    2773  */
    2774 static DECLCALLBACK(int) pcnetAsyncSendThreadWakeUp(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
    2775 {
    2776     PCNetState *pThis = PDMINS_2_DATA(pDevIns, PCNetState *);
    2777     return RTSemEventSignal(pThis->hSendEventSem);
    2778 }
    2779 
    2780 # endif /* VBOX_WITH_TX_THREAD_IN_NET_DEVICES*/
    2781 #endif /* IN_RING3 */
    27822685
    27832686/**
     
    50814984    if (PDMCritSectIsInitialized(&pThis->CritSect))
    50824985    {
    5083 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    5084         /*
    5085          * At this point the send thread is suspended and will not enter
    5086          * this module again. So, no coordination is needed here and PDM
    5087          * will take care of terminating and cleaning up the thread.
    5088          */
    5089         RTSemEventDestroy(pThis->hSendEventSem);
    5090         pThis->hSendEventSem = NIL_RTSEMEVENT;
    5091 #endif
    50924986        RTSemEventSignal(pThis->hEventOutOfRxSpace);
    50934987        RTSemEventDestroy(pThis->hEventOutOfRxSpace);
     
    51215015     */
    51225016    pThis->hEventOutOfRxSpace = NIL_RTSEMEVENT;
    5123 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    5124     pThis->hSendEventSem = NIL_RTSEMEVENT;
    5125 #endif
    51265017
    51275018    /*
     
    53935284     */
    53945285    pcnetHardReset(pThis);
    5395 
    5396 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    5397     /* Create send queue for the async send thread. */
    5398     rc = RTSemEventCreate(&pThis->hSendEventSem);
    5399     AssertRC(rc);
    5400 
    5401     /* Create asynchronous thread */
    5402     rc = PDMDevHlpThreadCreate(pDevIns, &pThis->pSendThread, pThis, pcnetAsyncSendThread, pcnetAsyncSendThreadWakeUp, 0, RTTHREADTYPE_IO, "PCNET_TX");
    5403     AssertRCReturn(rc, rc);
    5404 #endif
    54055286
    54065287#ifdef VBOX_WITH_STATISTICS
  • trunk/src/VBox/Devices/Network/DrvIntNet.cpp

    r28325 r28328  
    3131#include <VBox/intnetinline.h>
    3232#include <VBox/vmm.h>
     33#include <VBox/sup.h>
    3334#include <VBox/err.h>
    3435
     
    109110    /** The thread state. */
    110111    ASYNCSTATE volatile             enmState;
    111     /** Reader thread. */
    112     RTTHREAD                        hRxThread;
    113     /** Event semaphore the Thread waits on while the VM is suspended. */
    114     RTSEMEVENT                      hEvtSuspended;
     112    /** The receive thread. */
     113    RTTHREAD                        hRecvThread;
     114    /** The event semaphore that the receive thread waits on.  */
     115    RTSEMEVENT                      hRecvEvt;
     116    /** The transmit thread.  */
     117    PPDMTHREAD                      pXmitThread;
     118    /** The event semaphore that the transmit thread waits on.  */
     119    SUPSEMEVENT                     hXmitEvt;
     120    /** The support driver session handle. */
     121    PSUPDRVSESSION                  pSupDrvSession;
    115122    /** Scatter/gather descriptor cache. */
    116123    RTMEMCACHE                      hSgCache;
     
    118125     * When the link is down all incoming packets will be dropped. */
    119126    bool volatile                   fLinkDown;
     127    /** Set when the xmit thread has been signalled. (atomic) */
     128    bool volatile                   fXmitSignalled;
     129    /** Set if the transmit thread the one busy transmitting. */
     130    bool volatile                   fXmitOnXmitThread;
    120131    /** Set if data transmission should start immediately and deactivate
    121132     * as late as possible. */
    122133    bool                            fActivateEarlyDeactivateLate;
     134#if HC_ARCH_BITS == 64
    123135    /** Padding. */
    124     bool                            afReserved[HC_ARCH_BITS == 64 ? 2+4 : 2];
     136    bool                            afReserved[HC_ARCH_BITS == 64 ? 4 : 0];
     137#endif
    125138    /** The network name. */
    126139    char                            szNetwork[INTNET_MAX_NETWORK_NAME];
     
    207220
    208221
    209 
    210222/* -=-=-=-=- PDMINETWORKUP -=-=-=-=- */
    211223
     
    216228{
    217229    PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, INetworkUpR3);
     230#if 1
    218231    int rc = PDMCritSectTryEnter(&pThis->XmitLock);
    219     if (RT_UNLIKELY(rc == VERR_SEM_BUSY))
     232#else
     233    int rc = fOnWorkerThread ? PDMCritSectTryEnter(&pThis->XmitLock) : VERR_SEM_BUSY;
     234#endif
     235    if (RT_SUCCESS(rc))
     236    {
     237        if (fOnWorkerThread)
     238        {
     239            ASMAtomicUoWriteBool(&pThis->fXmitOnXmitThread, true);
     240            ASMAtomicWriteBool(&pThis->fXmitSignalled, false);
     241        }
     242    }
     243    else if (rc == VERR_SEM_BUSY)
     244    {
     245        /** @todo Does this actually make sense if the other dude is an EMT and so
     246         *        forth?  I seriously think this is ring-0 only... */
     247        if (    !fOnWorkerThread
     248            &&  !ASMAtomicUoReadBool(&pThis->fXmitOnXmitThread)
     249            &&  ASMAtomicCmpXchgBool(&pThis->fXmitSignalled, true, false))
     250        {
     251            rc = SUPSemEventSignal(pThis->pSupDrvSession, pThis->hXmitEvt);
     252            AssertRC(rc);
     253        }
    220254        rc = VERR_TRY_AGAIN;
     255    }
    221256    return rc;
    222257}
     
    248283                                         &pHdr, &pSgBuf->aSegs[0].pvSeg);
    249284
    250 #if 1 /** @todo implement VERR_TRY_AGAIN once this moves to EMT. */
     285#if 1 /** @todo implement VERR_TRY_AGAIN once this moves to EMT?  -- Not needed unless we make the consumer side (ring-0) asynchronous. */
    251286        if (    RT_FAILURE(rc)
    252287            &&  pThis->pBufR3->cbSend >= cbMin * 2 + sizeof(INTNETHDR))
     
    362397{
    363398    PDRVINTNET pThis = RT_FROM_MEMBER(pInterface, DRVINTNET, INetworkUpR3);
     399    ASMAtomicUoWriteBool(&pThis->fXmitOnXmitThread, false);
    364400    PDMCritSectLeave(&pThis->XmitLock);
    365401}
     
    408444
    409445
     446/* -=-=-=-=- Transmit Thread -=-=-=-=- */
     447
     448/**
     449 * Async I/O thread for defered packet transmission.
     450 *
     451 * @returns VBox status code. Returning failure will naturally terminate the thread.
     452 * @param   pDrvIns     The internal networking driver instance.
     453 * @param   pThread     The thread.
     454 */
     455static DECLCALLBACK(int) drvR3IntNetXmitThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
     456{
     457    PDRVINTNET pThis = PDMINS_2_DATA(pDrvIns, PDRVINTNET);
     458
     459    while (pThread->enmState == PDMTHREADSTATE_RUNNING)
     460    {
     461        /*
     462         * Block until we've got something to send or is supposed
     463         * to leave the running state.
     464         */
     465        int rc = SUPSemEventWaitNoResume(pThis->pSupDrvSession, pThis->hXmitEvt, RT_INDEFINITE_WAIT);
     466        AssertLogRelMsgReturn(RT_SUCCESS(rc) || rc == VERR_INTERRUPTED, ("%Rrc\n", rc), rc);
     467        if (RT_UNLIKELY(pThread->enmState != PDMTHREADSTATE_RUNNING))
     468            break;
     469
     470        /*
     471         * Transmit any pending packets.
     472         */
     473        pThis->pIAboveNet->pfnXmitPending(pThis->pIAboveNet);
     474   }
     475
     476    /* The thread is being initialized, suspended or terminated. */
     477    return VINF_SUCCESS;
     478}
     479
     480
     481/**
     482 * @copydoc FNPDMTHREADWAKEUPDRV
     483 */
     484static DECLCALLBACK(int) drvR3IntNetXmitWakeUp(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
     485{
     486    PDRVINTNET pThis = PDMINS_2_DATA(pDrvIns, PDRVINTNET);
     487    return SUPSemEventSignal(pThis->pSupDrvSession, pThis->hXmitEvt);
     488}
     489
     490
     491/* -=-=-=-=- Receive Thread -=-=-=-=- */
     492
    410493/**
    411494 * Wait for space to become available up the driver/device chain.
     
    416499 * @param   pThis       Pointer to the instance data.
    417500 */
    418 static int drvR3IntNetAsyncIoWaitForSpace(PDRVINTNET pThis)
    419 {
    420     LogFlow(("drvR3IntNetAsyncIoWaitForSpace:\n"));
     501static int drvR3IntNetRecvWaitForSpace(PDRVINTNET pThis)
     502{
     503    LogFlow(("drvR3IntNetRecvWaitForSpace:\n"));
    421504    STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
    422505    int rc = pThis->pIAboveNet->pfnWaitReceiveAvail(pThis->pIAboveNet, RT_INDEFINITE_WAIT);
    423506    STAM_PROFILE_ADV_START(&pThis->StatReceive, a);
    424     LogFlow(("drvR3IntNetAsyncIoWaitForSpace: returns %Rrc\n", rc));
     507    LogFlow(("drvR3IntNetRecvWaitForSpace: returns %Rrc\n", rc));
    425508    return rc;
    426509}
     
    434517 * @param   pThis       The driver instance data.
    435518 */
    436 static int drvR3IntNetAsyncIoRun(PDRVINTNET pThis)
     519static int drvR3IntNetRecvRun(PDRVINTNET pThis)
    437520{
    438521    PPDMDRVINS pDrvIns = pThis->pDrvInsR3;
    439     LogFlow(("drvR3IntNetAsyncIoRun: pThis=%p\n", pThis));
     522    LogFlow(("drvR3IntNetRecvRun: pThis=%p\n", pThis));
    440523
    441524    /*
     
    459542            {
    460543                STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
    461                 LogFlow(("drvR3IntNetAsyncIoRun: returns VERR_STATE_CHANGED (state changed - #0)\n"));
     544                LogFlow(("drvR3IntNetRecvRun: returns VERR_STATE_CHANGED (state changed - #0)\n"));
    462545                return VERR_STATE_CHANGED;
    463546            }
     
    485568                        {
    486569                            uint64_t u64Now = RTTimeProgramNanoTS();
    487                             LogFlow(("drvR3IntNetAsyncIoRun: %-4d bytes at %llu ns  deltas: r=%llu t=%llu\n",
     570                            LogFlow(("drvR3IntNetRecvRun: %-4d bytes at %llu ns  deltas: r=%llu t=%llu\n",
    488571                                     cbFrame, u64Now, u64Now - pThis->u64LastReceiveTS, u64Now - pThis->u64LastTransferTS));
    489572                            pThis->u64LastReceiveTS = u64Now;
    490                             Log2(("drvR3IntNetAsyncIoRun: cbFrame=%#x\n"
     573                            Log2(("drvR3IntNetRecvRun: cbFrame=%#x\n"
    491574                                  "%.*Rhxd\n",
    492575                                  cbFrame, cbFrame, INTNETHdrGetFramePtr(pHdr, pBuf)));
     
    519602                            {
    520603                                uint64_t u64Now = RTTimeProgramNanoTS();
    521                                 LogFlow(("drvR3IntNetAsyncIoRun: %-4d bytes at %llu ns  deltas: r=%llu t=%llu; GSO - %u segs\n",
     604                                LogFlow(("drvR3IntNetRecvRun: %-4d bytes at %llu ns  deltas: r=%llu t=%llu; GSO - %u segs\n",
    522605                                         cbFrame, u64Now, u64Now - pThis->u64LastReceiveTS, u64Now - pThis->u64LastTransferTS, cSegs));
    523606                                pThis->u64LastReceiveTS = u64Now;
    524                                 Log2(("drvR3IntNetAsyncIoRun: cbFrame=%#x type=%d cbHdrs=%#x Hdr1=%#x Hdr2=%#x MMS=%#x\n"
     607                                Log2(("drvR3IntNetRecvRun: cbFrame=%#x type=%d cbHdrs=%#x Hdr1=%#x Hdr2=%#x MMS=%#x\n"
    525608                                      "%.*Rhxd\n",
    526609                                      cbFrame, pGso->u8Type, pGso->cbHdrs, pGso->offHdr1, pGso->offHdr2, pGso->cbMaxSeg,
     
    533616                                void    *pvSegFrame = PDMNetGsoCarveSegmentQD(pGso, (uint8_t *)(pGso + 1), cbFrame, abHdrScratch,
    534617                                                                              iSeg, cSegs, &cbSegFrame);
    535                                 rc = drvR3IntNetAsyncIoWaitForSpace(pThis);
     618                                rc = drvR3IntNetRecvWaitForSpace(pThis);
    536619                                if (RT_FAILURE(rc))
    537620                                {
    538                                     Log(("drvR3IntNetAsyncIoRun: drvR3IntNetAsyncIoWaitForSpace -> %Rrc; iSeg=%u cSegs=%u\n", iSeg, cSegs));
     621                                    Log(("drvR3IntNetRecvRun: drvR3IntNetRecvWaitForSpace -> %Rrc; iSeg=%u cSegs=%u\n", iSeg, cSegs));
    539622                                    break; /* we drop the rest. */
    540623                                }
     
    558641                     * Wait for sufficient space to become available and then retry.
    559642                     */
    560                     rc = drvR3IntNetAsyncIoWaitForSpace(pThis);
     643                    rc = drvR3IntNetRecvWaitForSpace(pThis);
    561644                    if (RT_FAILURE(rc))
    562645                    {
     
    572655                        {
    573656                            STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
    574                             LogFlow(("drvR3IntNetAsyncIoRun: returns %Rrc (wait-for-space)\n", rc));
     657                            LogFlow(("drvR3IntNetRecvRun: returns %Rrc (wait-for-space)\n", rc));
    575658                            return rc;
    576659                        }
     
    595678        {
    596679            STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
    597             LogFlow(("drvR3IntNetAsyncIoRun: returns VINF_SUCCESS (state changed - #1)\n"));
     680            LogFlow(("drvR3IntNetRecvRun: returns VINF_SUCCESS (state changed - #1)\n"));
    598681            return VERR_STATE_CHANGED;
    599682        }
     
    610693            &&  rc != VERR_INTERRUPTED)
    611694        {
    612             LogFlow(("drvR3IntNetAsyncIoRun: returns %Rrc\n", rc));
     695            LogFlow(("drvR3IntNetRecvRun: returns %Rrc\n", rc));
    613696            return rc;
    614697        }
     
    625708 * @param   pvUser          Pointer to a DRVINTNET structure.
    626709 */
    627 static DECLCALLBACK(int) drvR3IntNetAsyncIoThread(RTTHREAD ThreadSelf, void *pvUser)
     710static DECLCALLBACK(int) drvR3IntNetRecvThread(RTTHREAD ThreadSelf, void *pvUser)
    628711{
    629712    PDRVINTNET pThis = (PDRVINTNET)pvUser;
    630     LogFlow(("drvR3IntNetAsyncIoThread: pThis=%p\n", pThis));
     713    LogFlow(("drvR3IntNetRecvThread: pThis=%p\n", pThis));
    631714    STAM_PROFILE_ADV_START(&pThis->StatReceive, a);
    632715
     
    641724            case ASYNCSTATE_SUSPENDED:
    642725            {
    643                 int rc = RTSemEventWait(pThis->hEvtSuspended, 30000);
     726                int rc = RTSemEventWait(pThis->hRecvEvt, 30000);
    644727                if (    RT_FAILURE(rc)
    645728                    &&  rc != VERR_TIMEOUT)
    646729                {
    647                     LogFlow(("drvR3IntNetAsyncIoThread: returns %Rrc\n", rc));
     730                    LogFlow(("drvR3IntNetRecvThread: returns %Rrc\n", rc));
    648731                    return rc;
    649732                }
     
    653736            case ASYNCSTATE_RUNNING:
    654737            {
    655                 int rc = drvR3IntNetAsyncIoRun(pThis);
     738                int rc = drvR3IntNetRecvRun(pThis);
    656739                if (    rc != VERR_STATE_CHANGED
    657740                    &&  RT_FAILURE(rc))
    658741                {
    659                     LogFlow(("drvR3IntNetAsyncIoThread: returns %Rrc\n", rc));
     742                    LogFlow(("drvR3IntNetRecvThread: returns %Rrc\n", rc));
    660743                    return rc;
    661744                }
     
    666749                AssertMsgFailed(("Invalid state %d\n", enmState));
    667750            case ASYNCSTATE_TERMINATE:
    668                 LogFlow(("drvR3IntNetAsyncIoThread: returns VINF_SUCCESS\n"));
     751                LogFlow(("drvR3IntNetRecvThread: returns VINF_SUCCESS\n"));
    669752                return VINF_SUCCESS;
    670753        }
    671754    }
    672755}
     756
    673757
    674758/* -=-=-=-=- PDMIBASERC -=-=-=-=- */
     
    686770    return NIL_RTRCPTR;
    687771}
     772
    688773
    689774/* -=-=-=-=- PDMIBASER0 -=-=-=-=- */
     
    701786}
    702787
     788
    703789/* -=-=-=-=- PDMIBASE -=-=-=-=- */
    704790
     
    717803    return NULL;
    718804}
     805
    719806
    720807/* -=-=-=-=- PDMDRVREG -=-=-=-=- */
     
    786873    {
    787874        ASMAtomicXchgSize(&pThis->enmState, ASYNCSTATE_RUNNING);
    788         RTSemEventSignal(pThis->hEvtSuspended);
     875        RTSemEventSignal(pThis->hRecvEvt);
    789876        drvR3IntNetUpdateMacAddress(pThis); /* (could be a state restore) */
    790877        drvR3IntNetSetActive(pThis, true /* fActive */);
     
    848935    {
    849936        ASMAtomicXchgSize(&pThis->enmState, ASYNCSTATE_RUNNING);
    850         RTSemEventSignal(pThis->hEvtSuspended);
     937        RTSemEventSignal(pThis->hRecvEvt);
    851938        drvR3IntNetUpdateMacAddress(pThis);
    852939        drvR3IntNetSetActive(pThis, true /* fActive */);
     
    883970    ASMAtomicXchgSize(&pThis->enmState, ASYNCSTATE_TERMINATE);
    884971    ASMAtomicXchgSize(&pThis->fLinkDown, true);
    885     RTSEMEVENT hEvtSuspended = pThis->hEvtSuspended;
    886     pThis->hEvtSuspended = NIL_RTSEMEVENT;
     972    RTSEMEVENT hRecvEvt = pThis->hRecvEvt;
     973    pThis->hRecvEvt = NIL_RTSEMEVENT;
    887974
    888975    /*
     
    904991     * Wait for the thread to terminate.
    905992     */
    906     if (pThis->hRxThread != NIL_RTTHREAD)
    907     {
    908         if (hEvtSuspended != NIL_RTSEMEVENT)
    909             RTSemEventSignal(hEvtSuspended);
    910         int rc = RTThreadWait(pThis->hRxThread, 5000, NULL);
     993    if (pThis->hRecvThread != NIL_RTTHREAD)
     994    {
     995        if (hRecvEvt != NIL_RTSEMEVENT)
     996            RTSemEventSignal(hRecvEvt);
     997        int rc = RTThreadWait(pThis->hRecvThread, 5000, NULL);
    911998        AssertRC(rc);
    912         pThis->hRxThread = NIL_RTTHREAD;
     999        pThis->hRecvThread = NIL_RTTHREAD;
    9131000    }
    9141001
     
    9161003     * Destroy the semaphore, S/G cache and xmit lock.
    9171004     */
    918     if (hEvtSuspended != NIL_RTSEMEVENT)
    919         RTSemEventDestroy(hEvtSuspended);
     1005    if (hRecvEvt != NIL_RTSEMEVENT)
     1006        RTSemEventDestroy(hRecvEvt);
    9201007
    9211008    RTMemCacheDestroy(pThis->hSgCache);
     
    9661053    pThis->pDrvInsR3                                = pDrvIns;
    9671054    pThis->hIf                                      = INTNET_HANDLE_INVALID;
    968     pThis->hRxThread                                = NIL_RTTHREAD;
    969     pThis->hEvtSuspended                            = NIL_RTSEMEVENT;
     1055    pThis->hRecvThread                              = NIL_RTTHREAD;
     1056    pThis->hRecvEvt                                 = NIL_RTSEMEVENT;
     1057    pThis->pXmitThread                              = NULL;
     1058    pThis->hXmitEvt                                 = NIL_SUPSEMEVENT;
     1059    pThis->pSupDrvSession                           = PDMDrvHlpGetSupDrvSession(pDrvIns);
    9701060    pThis->hSgCache                                 = NIL_RTMEMCACHE;
    9711061    pThis->enmState                                 = ASYNCSTATE_SUSPENDED;
     
    12491339     * Create the event semaphore, S/G cache and xmit critsect.
    12501340     */
    1251     rc = RTSemEventCreate(&pThis->hEvtSuspended);
     1341    rc = RTSemEventCreate(&pThis->hRecvEvt);
    12521342    if (RT_FAILURE(rc))
    12531343        return rc;
     
    12581348    if (RT_FAILURE(rc))
    12591349        return rc;
    1260 
    12611350
    12621351    /*
     
    12891378
    12901379    /*
    1291      * Create the async I/O thread.
     1380     * Create the async I/O threads.
    12921381     * Note! Using a PDM thread here doesn't fit with the IsService=true operation.
    12931382     */
    1294     rc = RTThreadCreate(&pThis->hRxThread, drvR3IntNetAsyncIoThread, pThis, _128K, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "INTNET");
     1383    rc = RTThreadCreate(&pThis->hRecvThread, drvR3IntNetRecvThread, pThis, 0,
     1384                        RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "INTNET-RECV");
    12951385    if (RT_FAILURE(rc))
    12961386    {
     
    12981388        return rc;
    12991389    }
     1390
     1391    rc = SUPSemEventCreate(pThis->pSupDrvSession, &pThis->hXmitEvt);
     1392    AssertRCReturn(rc, rc);
     1393
     1394    rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pXmitThread, pThis,
     1395                               drvR3IntNetXmitThread, drvR3IntNetXmitWakeUp, 0, RTTHREADTYPE_IO, "INTNET-XMIT");
     1396    AssertRCReturn(rc, rc);
     1397
     1398    /*
     1399     * Register statistics.
     1400     */
    13001401    PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->Recv.cbStatWritten, "Bytes/Received",       STAMUNIT_BYTES, "Number of received bytes.");
    13011402    PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->Send.cbStatWritten, "Bytes/Sent",           STAMUNIT_BYTES, "Number of sent bytes.");
     
    13221423    {
    13231424        ASMAtomicXchgSize(&pThis->enmState, ASYNCSTATE_RUNNING);
    1324         RTSemEventSignal(pThis->hEvtSuspended);
     1425        RTSemEventSignal(pThis->hRecvEvt);
     1426
    13251427        drvR3IntNetUpdateMacAddress(pThis);
    13261428        drvR3IntNetSetActive(pThis, true /* fActive */);
     
    13291431   return rc;
    13301432}
     1433
    13311434
    13321435
  • trunk/src/VBox/Devices/testcase/tstDeviceStructSizeRC.cpp

    r28320 r28328  
    413413    GEN_CHECK_OFF(PCNetState, ILeds);
    414414    GEN_CHECK_OFF(PCNetState, pLedsConnector);
    415 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    416     GEN_CHECK_OFF(PCNetState, hSendEventSem);
    417     GEN_CHECK_OFF(PCNetState, pSendThread);
    418 #endif
    419415    GEN_CHECK_OFF(PCNetState, CritSect);
    420416#ifdef PCNET_NO_POLLING
     
    13091305    GEN_CHECK_OFF(E1KSTATE, csRx);
    13101306#endif
    1311 #ifdef VBOX_WITH_TX_THREAD_IN_NET_DEVICES
    1312     GEN_CHECK_OFF(E1KSTATE, hTxSem);
    1313     GEN_CHECK_OFF(E1KSTATE, pTxThread);
    1314 #endif
    13151307    GEN_CHECK_OFF(E1KSTATE, addrMMReg);
    13161308    GEN_CHECK_OFF(E1KSTATE, macConfigured);
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