VirtualBox

Changeset 7786 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 8, 2008 8:18:43 AM (17 years ago)
Author:
vboxsync
Message:

do it like DrvTAPOs2 and ensure that we never miss a receive wakeup

File:
1 edited

Legend:

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

    r7785 r7786  
    121121    PPDMTHREAD              pThread;
    122122    /** We are waiting for more receive buffers. */
    123     uint32_t volatile       fOutOfSpace;
     123    bool volatile           fMaybeOutOfSpace;
    124124    /** Event semaphore for blocking on receive. */
    125125    RTSEMEVENT              EventOutOfSpace;
     
    249249
    250250    LogFlow(("drvTAPNotifyCanReceive:\n"));
    251     /** @todo r=bird: With a bit unfavorable scheduling it's possible to get here
    252      * before fOutOfSpace is set by the overflow code. This will mean that, unless
    253      * more receive descriptors become available, the receive thread will be stuck
    254      * until it times out and cause a hickup in the network traffic.
    255      * There is a simple, but not perfect, workaround for this problem in DrvTAPOs2.cpp.
    256      *
    257      * A better solution would be to ditch the NotifyCanReceive callback and instead
    258      * change the CanReceive to do all the work. This will reduce the amount of code
    259      * duplication, and would permit pcnet to avoid queuing unnecessary ring-3 tasks.
    260      */
    261 
    262     /* ensure we wake up only once */
    263     if (ASMAtomicXchgU32(&pData->fOutOfSpace, false))
     251    /** @todo r=bird: A better solution would be to ditch the NotifyCanReceive callback
     252     *                and instead change the CanReceive to do all the work. This will
     253     *                reduce the amount of code duplication, and would permit pcnet to
     254     *                avoid queuing unnecessary ring-3 tasks.
     255     */
     256
     257    if (pData->fMaybeOutOfSpace)
    264258        RTSemEventSignal(pData->EventOutOfSpace);
    265259#endif
     
    348342                 *    overflow error to allocate more receive buffers
    349343                 */
     344                ASMAtomicXchgBool(&pData->fMaybeOutOfSpace, true);
    350345                size_t cbMax = pData->pPort->pfnCanReceive(pData->pPort);
    351346                if (cbMax == 0)
     
    359354                        LogFlow(("drvTAPAsyncIoThread: cbMax=%d cbRead=%d waiting...\n", cbMax, cbRead));
    360355                        /* We get signalled by the network driver. 50ms is just for sanity */
    361                         ASMAtomicXchgU32(&pData->fOutOfSpace, true);
    362356                        RTSemEventWait(pData->EventOutOfSpace, 50);
    363357                        cbMax = pData->pPort->pfnCanReceive(pData->pPort);
    364358                    }
    365                     ASMAtomicXchgU32(&pData->fOutOfSpace, false);
    366359                    STAM_PROFILE_STOP(&pData->StatRecvOverflows, b);
    367360                    STAM_PROFILE_ADV_START(&pData->StatReceive, a);
    368                     if (pThread->enmState != PDMTHREADSTATE_RUNNING)
    369                         break;
    370361                }
     362                ASMAtomicXchgBool(&pData->fMaybeOutOfSpace, false);
     363                if (pThread->enmState != PDMTHREADSTATE_RUNNING)
     364                    break;
    371365
    372366                /*
     
    445439    /* Ensure that it does not spin in the CanReceive loop.
    446440       (May assert in IPRT if we're really unlucky.) */
    447     if (ASMAtomicXchgU32(&pData->fOutOfSpace, false))
     441    if (pData->fMaybeOutOfSpace)
    448442        RTSemEventSignal(pData->EventOutOfSpace);
    449443
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