VirtualBox

Changeset 82332 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
Dec 3, 2019 12:30:11 AM (5 years ago)
Author:
vboxsync
Message:

DevHDA: Reduce the number of PDMDevHlpTimerGet calls. bugref:9218

Location:
trunk/src/VBox/Devices/Audio
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DevHDA.cpp

    r82331 r82332  
    14271427                    AssertRC(rc2);
    14281428
    1429                     rc2 = hdaR3TimerSet(pDevIns, pThis, pStream,
    1430                                           PDMDevHlpTimerGet(pDevIns, pThis->ahTimers[pStream->u8SD])
    1431                                         + pStream->State.cTransferTicks,
    1432                                         false /* fForce */);
     1429                    uint64_t const tsNow = PDMDevHlpTimerGet(pDevIns, pStream->hTimer);
     1430                    rc2 = hdaR3TimerSet(pDevIns, pStream, tsNow + pStream->State.cTransferTicks, false /* fForce */, tsNow);
    14331431                    AssertRC(rc2);
    14341432                }
     
    15211519    HDA_PROCESS_INTERRUPT(pDevIns, pThis);
    15221520
    1523     const uint64_t tsNow = PDMDevHlpTimerGet(pDevIns, pThis->ahTimers[uSD]);
     1521    const uint64_t tsNow = PDMDevHlpTimerGet(pDevIns, pStream->hTimer);
    15241522    Assert(tsNow >= pStream->State.tsTransferLast);
    15251523
     
    15471545            LogRelMax2(64, ("HDA: Stream #%RU8 interrupt lagging behind (expected %uus, got %uus), trying to catch up ...\n",
    15481546                            pStream->u8SD,
    1549                             (PDMDevHlpTimerGetFreq(pDevIns, pThis->ahTimers[pStream->u8SD]) / pThis->uTimerHz) / 1000,
     1547                            (PDMDevHlpTimerGetFreq(pDevIns, pStream->hTimer) / pThis->uTimerHz) / 1000,
    15501548                            (tsNow - pStream->State.tsTransferLast) / 1000));
    15511549
     
    15681566            /* Re-arm the timer. */
    15691567            LogFunc(("Timer set SD%RU8\n", pStream->u8SD));
    1570             hdaR3TimerSet(pDevIns, pThis, pStream, tsNow + cTicksToNext, false /* fForce */);
     1568            hdaR3TimerSet(pDevIns, pStream, tsNow + cTicksToNext, true /* fForce - we just set tsTransferNext*/, 0 /*tsNow*/);
    15711569        }
    15721570    }
     
    28602858    if (fSinkActive)
    28612859    {
    2862         const bool fTimerScheduled = hdaR3StreamTransferIsScheduled(pDevIns, pStream);
     2860        uint64_t const tsNow = PDMDevHlpTimerGet(pDevIns, hTimer); /* (For virtual sync this remains the same for the whole callout IIRC) */
     2861        const bool fTimerScheduled = hdaR3StreamTransferIsScheduled(pStream, tsNow);
    28632862        Log3Func(("fSinksActive=%RTbool, fTimerScheduled=%RTbool\n", fSinkActive, fTimerScheduled));
    28642863        if (!fTimerScheduled)
    2865             hdaR3TimerSet(pDevIns, pThis, pStream,
    2866                             PDMDevHlpTimerGet(pDevIns, hTimer)
    2867                           + PDMDevHlpTimerGetFreq(pDevIns, hTimer) / pStream->pHDAState->uTimerHz,
    2868                           true /* fForce */);
     2864            hdaR3TimerSet(pDevIns, pStream, tsNow + PDMDevHlpTimerGetFreq(pDevIns, hTimer) / pThis->uTimerHz,
     2865                          true /*fForce*/, tsNow /*fixed*/ );
    28692866    }
    28702867    else
     
    29112908    }
    29122909
    2913     switch(enmAccessType)
     2910    switch (enmAccessType)
    29142911    {
    29152912        case PGMACCESSTYPE_WRITE:
     
    36283625                hdaR3StreamRegisterDMAHandlers(pThis, pStream);
    36293626#endif
    3630                 if (hdaR3StreamTransferIsScheduled(pDevIns, pStream))
    3631                     hdaR3TimerSet(pDevIns, pThis, pStream, hdaR3StreamTransferGetNext(pStream), true /* fForce */);
     3627                if (hdaR3StreamTransferIsScheduled(pStream, PDMDevHlpTimerGet(pDevIns, pStream->hTimer)))
     3628                    hdaR3TimerSet(pDevIns, pStream, hdaR3StreamTransferGetNext(pStream), true /*fForce*/, 0 /*tsNow*/);
    36323629
    36333630                /* Also keep track of the currently active streams. */
  • trunk/src/VBox/Devices/Audio/DevHDACommon.cpp

    r82331 r82332  
    665665 * @returns Whether the new expiration time was set or not.
    666666 * @param   pDevIns     The device instance.
    667  * @param   pThis       HDA state.
    668667 * @param   pStream     HDA stream to set timer for.
    669668 * @param   tsExpire    New (virtual) expiration time to set.
    670669 * @param   fForce      Whether to force setting the expiration time or not.
     670 * @param   tsNow       The current clock timestamp if available, 0 if not.
    671671 *
    672672 * @remark  This function takes all active HDA streams and their
     
    679679 *          Forcing a new expiration time will override the above mechanism.
    680680 */
    681 bool hdaR3TimerSet(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTREAM pStream, uint64_t tsExpire, bool fForce)
    682 {
    683     AssertPtr(pThis);
     681bool hdaR3TimerSet(PPDMDEVINS pDevIns, PHDASTREAM pStream, uint64_t tsExpire, bool fForce, uint64_t tsNow)
     682{
    684683    AssertPtr(pStream);
    685684
    686     uint64_t tsExpireMin = tsExpire;
     685    if (!tsNow)
     686        tsNow = PDMDevHlpTimerGet(pDevIns, pStream->hTimer);
    687687
    688688    if (!fForce)
     
    691691         * PDMDevHlpTimerGet(), so, some callers does one, this does, and then we do
    692692         * right afterwards == very inefficient! */
    693         if (hdaR3StreamTransferIsScheduled(pDevIns, pStream))
     693        if (hdaR3StreamTransferIsScheduled(pStream, tsNow))
    694694        {
    695695            uint64_t const tsNext = hdaR3StreamTransferGetNext(pStream);
    696             if (tsExpireMin > tsNext)
    697                 tsExpireMin = tsNext;
     696            if (tsExpire > tsNext)
     697                tsExpire = tsNext;
    698698        }
    699699    }
    700 
    701     const uint64_t tsNow = PDMDevHlpTimerGet(pDevIns, pStream->hTimer);
    702700
    703701    /*
     
    705703     * This in theory could happen in hdaR3StreamTransferGetNext() from above.
    706704     */
    707     if (tsExpireMin < tsNow)
    708         tsExpireMin = tsNow;
    709 
    710     int rc = PDMDevHlpTimerSet(pDevIns, pStream->hTimer, tsExpireMin);
     705    if (tsExpire < tsNow)
     706        tsExpire = tsNow;
     707
     708    int rc = PDMDevHlpTimerSet(pDevIns, pStream->hTimer, tsExpire);
    711709    AssertRCReturn(rc, false);
    712710
  • trunk/src/VBox/Devices/Audio/DevHDACommon.h

    r82331 r82332  
    653653 */
    654654#ifdef IN_RING3
    655 bool          hdaR3TimerSet(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTREAM pStream, uint64_t u64Expire, bool fForce);
     655bool          hdaR3TimerSet(PPDMDEVINS pDevIns, PHDASTREAM pStream, uint64_t u64Expire, bool fForce, uint64_t tsNow);
    656656#endif
    657657/** @} */
  • trunk/src/VBox/Devices/Audio/HDAStream.cpp

    r82331 r82332  
    720720 *
    721721 * @returns True if a next transfer is scheduled, false if not.
    722  * @param   pDevIns             The device instance.
    723722 * @param   pStream             HDA stream to retrieve schedule status for.
    724  */
    725 bool hdaR3StreamTransferIsScheduled(PPDMDEVINS pDevIns, PHDASTREAM pStream)
     723 * @param   tsNow               The current time.
     724 */
     725bool hdaR3StreamTransferIsScheduled(PHDASTREAM pStream, uint64_t tsNow)
    726726{
    727727    if (pStream)
     
    737737            }
    738738
    739             const uint64_t tsNow = PDMDevHlpTimerGet(pDevIns, pStream->hTimer);
    740739            if (pStream->State.tsTransferNext > tsNow)
    741740            {
     
    913912 * @param   pStream             HDA stream to update.
    914913 * @param   cbToProcessMax      How much data (in bytes) to process as maximum.
    915  */
    916 int hdaR3StreamTransfer(PPDMDEVINS pDevIns, PHDASTREAM pStream, uint32_t cbToProcessMax)
     914 * @param   fInTimer            Set if we're in the timer callout.
     915 */
     916static int hdaR3StreamTransfer(PPDMDEVINS pDevIns, PHDASTREAM pStream, uint32_t cbToProcessMax, bool fInTimer)
    917917{
    918918    AssertPtrReturn(pStream, VERR_INVALID_POINTER);
     
    13791379
    13801380        LogFunc(("Timer set SD%RU8\n", pStream->u8SD));
    1381         hdaR3TimerSet(pDevIns, pStream->pHDAState, pStream, tsTransferNext, false /* fForce */);
     1381        Assert(!fInTimer || tsNow == PDMDevHlpTimerGet(pDevIns, pStream->hTimer));
     1382        hdaR3TimerSet(pDevIns, pStream, tsTransferNext, true /* fForce - skip tsTransferNext check */, fInTimer ? tsNow : 0);
    13821383
    13831384        pStream->State.tsTransferNext = tsTransferNext;
     
    14501451            {
    14511452                /* Do the DMA transfer. */
    1452                 rc2 = hdaR3StreamTransfer(pDevIns, pStream, cbStreamFree);
     1453                rc2 = hdaR3StreamTransfer(pDevIns, pStream, cbStreamFree, fInTimer);
    14531454                AssertRC(rc2);
    14541455            }
     
    15711572            if (cbStreamUsed)
    15721573            {
    1573                 rc2 = hdaR3StreamTransfer(pDevIns, pStream, cbStreamUsed);
     1574                rc2 = hdaR3StreamTransfer(pDevIns, pStream, cbStreamUsed, fInTimer);
    15741575                AssertRC(rc2);
    15751576            }
  • trunk/src/VBox/Devices/Audio/HDAStream.h

    r82331 r82332  
    272272uint32_t          hdaR3StreamGetFree(PHDASTREAM pStream);
    273273uint32_t          hdaR3StreamGetUsed(PHDASTREAM pStream);
    274 bool              hdaR3StreamTransferIsScheduled(PPDMDEVINS pDevIns, PHDASTREAM pStream);
     274bool              hdaR3StreamTransferIsScheduled(PHDASTREAM pStream, uint64_t tsNow);
    275275uint64_t          hdaR3StreamTransferGetNext(PHDASTREAM pStream);
    276 int               hdaR3StreamTransfer(PPDMDEVINS pDevIns, PHDASTREAM pStream, uint32_t cbToProcessMax);
    277276void              hdaR3StreamLock(PHDASTREAM pStream);
    278277void              hdaR3StreamUnlock(PHDASTREAM pStream);
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