VirtualBox

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


Ignore:
Timestamp:
Dec 3, 2019 2:40:21 PM (5 years ago)
Author:
vboxsync
Message:

DevHDA,DevIchAc97: Moved the per-stream timers into the stream structures, dropping the ahTimers arrays in the device state structures. This eliminates bunch of unnecessary indexing and pThis parameter passing. bugref:9218

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

Legend:

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

    r82332 r82345  
    155155 * Acquires the TM lock and HDA lock, returns on failure.
    156156 */
    157 #define DEVHDA_LOCK_BOTH_RETURN(a_pDevIns, a_pThis, a_SD, a_rcBusy) \
     157#define DEVHDA_LOCK_BOTH_RETURN(a_pDevIns, a_pThis, a_pStream, a_rcBusy) \
    158158    do { \
    159         VBOXSTRICTRC rcLock = PDMDevHlpTimerLockClock2(pDevIns, (a_pThis)->ahTimers[a_SD], &(a_pThis)->CritSect,  (a_rcBusy)); \
     159        VBOXSTRICTRC rcLock = PDMDevHlpTimerLockClock2(pDevIns, (a_pStream)->hTimer, &(a_pThis)->CritSect,  (a_rcBusy)); \
    160160        if (RT_LIKELY(rcLock == VINF_SUCCESS)) \
    161161        {  /* likely */ } \
     
    167167 * Releases the HDA lock and TM lock.
    168168 */
    169 #define DEVHDA_UNLOCK_BOTH(a_pDevIns, a_pThis, a_SD) \
    170     PDMDevHlpTimerUnlockClock2(pDevIns, (a_pThis)->ahTimers[a_SD], &(a_pThis)->CritSect)
     169#define DEVHDA_UNLOCK_BOTH(a_pDevIns, a_pThis, a_pStream) \
     170    PDMDevHlpTimerUnlockClock2(pDevIns, (a_pStream)->hTimer, &(a_pThis)->CritSect)
    171171
    172172
     
    13021302     *               clock lock here!
    13031303     */
    1304     DEVHDA_LOCK_BOTH_RETURN(pDevIns, pThis, uSD, VINF_IOM_R3_MMIO_WRITE);
     1304    DEVHDA_LOCK_BOTH_RETURN(pDevIns, pThis, pStream, VINF_IOM_R3_MMIO_WRITE);
    13051305
    13061306    const bool fInRun    = RT_BOOL(HDA_REG_IND(pThis, iReg) & HDA_SDCTL_RUN);
     
    14571457    AssertRC(rc2);
    14581458
    1459     DEVHDA_UNLOCK_BOTH(pDevIns, pThis, uSD);
     1459    DEVHDA_UNLOCK_BOTH(pDevIns, pThis, pStream);
    14601460    return VINF_SUCCESS; /* Always return success to the MMIO handler. */
    14611461#else  /* !IN_RING3 */
     
    14771477     *               clock lock here!
    14781478     */
    1479     DEVHDA_LOCK_BOTH_RETURN(pDevIns, pThis, uSD, VINF_IOM_R3_MMIO_WRITE);
     1479    DEVHDA_LOCK_BOTH_RETURN(pDevIns, pThis, pStream, VINF_IOM_R3_MMIO_WRITE);
    14801480
    14811481    hdaR3StreamLock(pStream);
     
    15721572    hdaR3StreamUnlock(pStream);
    15731573
    1574     DEVHDA_UNLOCK_BOTH(pDevIns, pThis, uSD);
     1574    DEVHDA_UNLOCK_BOTH(pDevIns, pThis, pStream);
    15751575    return VINF_SUCCESS;
    15761576#else  /* !IN_RING3 */
     
    28422842    PHDASTATE       pThis   = PDMDEVINS_2_DATA(pDevIns, PHDASTATE);
    28432843    PHDASTREAM      pStream = (PHDASTREAM)pvUser;
    2844     TMTIMERHANDLE   hTimer  = RT_SAFE_SUBSCRIPT8(pThis->ahTimers, pStream->u8SD);
     2844    TMTIMERHANDLE   hTimer  = pStream->hTimer;
    28452845    RT_NOREF(pTimer);
    28462846
     
    49674967    {
    49684968        rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, hdaR3Timer, &pThis->aStreams[i],
    4969                                   TMTIMER_FLAGS_NO_CRIT_SECT, s_apszNames[i], &pThis->ahTimers[i]);
     4969                                  TMTIMER_FLAGS_NO_CRIT_SECT, s_apszNames[i], &pThis->aStreams[i].hTimer);
    49704970        AssertRCReturn(rc, rc);
    49714971
    4972         rc = PDMDevHlpTimerSetCritSect(pDevIns, pThis->ahTimers[i], &pThis->CritSect);
     4972        rc = PDMDevHlpTimerSetCritSect(pDevIns, pThis->aStreams[i].hTimer, &pThis->CritSect);
    49734973        AssertRCReturn(rc, rc);
    49744974    }
  • trunk/src/VBox/Devices/Audio/DevHDA.h

    r82331 r82345  
    138138    /** Number of active (running) SDn streams. */
    139139    uint8_t                 cStreamsActive;
    140     /** The stream timers for pumping data thru the attached LUN drivers.
    141      * Duplicated in HDASTREAM::hTimer. */
    142     TMTIMERHANDLE           ahTimers[HDA_MAX_STREAMS];
    143140    /** Pointer to HDA codec to use. */
    144141    R3PTRTYPE(PHDACODEC)    pCodec;
  • trunk/src/VBox/Devices/Audio/DevIchAc97.cpp

    r82344 r82345  
    412412    uint32_t              Padding1;
    413413#endif
     414    /** The timer for pumping data thru the attached LUN drivers. */
     415    TMTIMERHANDLE           hTimer;
    414416    /** Debug stuff. */
    415417    AC97STREAMDEBUG         Dbg;
     
    501503    /** R3 pointer to the device instance. */
    502504    PPDMDEVINSR3            pDevInsR3;
    503 //    /** R0 pointer to the device instance. */
    504 //    PPDMDEVINSR0            pDevInsR0;
    505 //    /** RC pointer to the device instance. */
    506 //    PPDMDEVINSRC            pDevInsRC;
    507 //    bool                    afPadding0[4];
    508505    /** Global Control (Bus Master Control Register). */
    509506    uint32_t                glob_cnt;
     
    519516    uint16_t                uTimerHz;
    520517    uint16_t                au16Padding1[3];
    521     /** The timer for pumping data thru the attached LUN drivers. */
    522     TMTIMERHANDLE           ahTimers[AC97_MAX_STREAMS];
    523518    /** List of associated LUN drivers (AC97DRIVER). */
    524519    RTLISTANCHORR3          lstDrv;
     
    589584 * Acquires the TM lock and AC'97 lock, returns on failure.
    590585 */
    591 #define DEVAC97_LOCK_BOTH_RETURN(a_pDevIns, a_pThis, a_SD, a_rcBusy) \
     586#define DEVAC97_LOCK_BOTH_RETURN(a_pDevIns, a_pThis, a_pStream, a_rcBusy) \
    592587    do { \
    593         VBOXSTRICTRC rcLock = PDMDevHlpTimerLockClock2((a_pDevIns), RT_SAFE_SUBSCRIPT8((a_pThis)->ahTimers, (a_SD)), \
    594                                                        &(a_pThis)->CritSect, (a_rcBusy)); \
     588        VBOXSTRICTRC rcLock = PDMDevHlpTimerLockClock2((a_pDevIns), (a_pStream)->hTimer, &(a_pThis)->CritSect, (a_rcBusy)); \
    595589        if (RT_LIKELY(rcLock == VINF_SUCCESS)) \
    596590        { /* likely */ } \
     
    605599 * Releases the AC'97 lock and TM lock.
    606600 */
    607 #define DEVAC97_UNLOCK_BOTH(a_pDevIns, a_pThis, a_SD) \
    608     PDMDevHlpTimerUnlockClock2((a_pDevIns), RT_SAFE_SUBSCRIPT8((a_pThis)->ahTimers, (a_SD)), &(a_pThis)->CritSect)
     601#define DEVAC97_UNLOCK_BOTH(a_pDevIns, a_pThis, a_pStream) \
     602    PDMDevHlpTimerUnlockClock2((a_pDevIns), (a_pStream)->hTimer, &(a_pThis)->CritSect)
    609603
    610604#ifdef VBOX_WITH_STATISTICS
     
    659653static void               ichac97R3BDLEDumpAll(PAC97STATE pThis, uint64_t u64BDLBase, uint16_t cBDLE);
    660654# endif
    661 DECLINLINE(void)          ichac97R3TimerSet(PPDMDEVINS pDevIns, PAC97STATE pThis, PAC97STREAM pStream, uint64_t cTicksToDeadline);
     655DECLINLINE(void)          ichac97R3TimerSet(PPDMDEVINS pDevIns, PAC97STREAM pStream, uint64_t cTicksToDeadline);
    662656#endif /* IN_RING3 */
    663657
     
    953947
    954948    int rc = RTCritSectInit(&pStream->State.CritSect);
     949    AssertRCReturn(rc, rc);
    955950
    956951    pStream->Dbg.Runtime.fEnabled = pThis->Dbg.fEnabled;
     
    19481943 * @returns Calculated ticks
    19491944 * @param   pDevIns             The device instance.
    1950  * @param   pThis               AC'97 device state.
    19511945 * @param   pStream             AC'97 stream to calculate ticks for.
    19521946 * @param   cbBytes             Bytes to calculate ticks for.
    19531947 */
    1954 static uint64_t ichac97R3StreamTransferCalcNext(PPDMDEVINS pDevIns, PAC97STATE pThis, PAC97STREAM pStream, uint32_t cbBytes)
     1948static uint64_t ichac97R3StreamTransferCalcNext(PPDMDEVINS pDevIns, PAC97STREAM pStream, uint32_t cbBytes)
    19551949{
    19561950    if (!cbBytes)
     
    19581952
    19591953    const uint64_t usBytes        = DrvAudioHlpBytesToMicro(cbBytes, &pStream->State.Cfg.Props);
    1960     const uint64_t cTransferTicks = PDMDevHlpTimerFromMicro(pDevIns, RT_SAFE_SUBSCRIPT8(pThis->ahTimers, pStream->u8SD), usBytes);
     1954    const uint64_t cTransferTicks = PDMDevHlpTimerFromMicro(pDevIns, pStream->hTimer, usBytes);
    19611955
    19621956    Log3Func(("[SD%RU8] Timer %uHz, cbBytes=%RU32 -> usBytes=%RU64, cTransferTicks=%RU64\n",
     
    19701964 *
    19711965 * @param   pDevIns             The device instance.
    1972  * @param   pThis               AC'97 device state.
    19731966 * @param   pStream             AC'97 stream to update.
    19741967 * @param   cbBytes             Bytes to update next transfer for.
    19751968 */
    1976 static void ichac97R3StreamTransferUpdate(PPDMDEVINS pDevIns, PAC97STATE pThis, PAC97STREAM pStream, uint32_t cbBytes)
     1969static void ichac97R3StreamTransferUpdate(PPDMDEVINS pDevIns, PAC97STREAM pStream, uint32_t cbBytes)
    19771970{
    19781971    if (!cbBytes)
     
    19841977
    19851978    /* Update the transfer ticks. */
    1986     pStream->State.cTransferTicks = ichac97R3StreamTransferCalcNext(pDevIns, pThis, pStream, pStream->State.cbTransferChunk);
     1979    pStream->State.cTransferTicks = ichac97R3StreamTransferCalcNext(pDevIns, pStream, pStream->State.cbTransferChunk);
    19871980    Assert(pStream->State.cTransferTicks); /* Paranoia. */
    19881981}
     
    26262619    AssertPtr(pStream);
    26272620    Assert(PDMDevHlpCritSectIsOwner(pDevIns, &pThis->CritSect));
    2628     Assert(PDMDevHlpTimerIsLockOwner(pDevIns, RT_SAFE_SUBSCRIPT8(pThis->ahTimers, pStream->u8SD)));
     2621    Assert(PDMDevHlpTimerIsLockOwner(pDevIns, pStream->hTimer));
    26292622
    26302623    ichac97R3StreamUpdate(pDevIns, pThis, pStream, true /* fInTimer */);
     
    26332626    if (pSink && AudioMixerSinkIsActive(pSink))
    26342627    {
    2635         ichac97R3StreamTransferUpdate(pDevIns, pThis, pStream, pStream->Regs.picb << 1); /** @todo r=andy Assumes 16-bit samples. */
    2636         ichac97R3TimerSet(pDevIns, pThis, pStream, pStream->State.cTransferTicks);
     2628        ichac97R3StreamTransferUpdate(pDevIns, pStream, pStream->Regs.picb << 1); /** @todo r=andy Assumes 16-bit samples. */
     2629        ichac97R3TimerSet(pDevIns, pStream, pStream->State.cTransferTicks);
    26372630    }
    26382631
     
    26512644 * @remarks This used to be more complicated a long time ago...
    26522645 */
    2653 DECLINLINE(void) ichac97R3TimerSet(PPDMDEVINS pDevIns, PAC97STATE pThis, PAC97STREAM pStream, uint64_t cTicksToDeadline)
    2654 {
    2655     int rc = PDMDevHlpTimerSetRelative(pDevIns, RT_SAFE_SUBSCRIPT8(pThis->ahTimers, pStream->u8SD),
    2656                                        cTicksToDeadline, NULL /*pu64Now*/);
     2646DECLINLINE(void) ichac97R3TimerSet(PPDMDEVINS pDevIns, PAC97STREAM pStream, uint64_t cTicksToDeadline)
     2647{
     2648    int rc = PDMDevHlpTimerSetRelative(pDevIns, pStream->hTimer, cTicksToDeadline, NULL /*pu64Now*/);
    26572649    AssertRC(rc);
    26582650}
     
    30563048        pRegs   = &pStream->Regs;
    30573049
    3058         DEVAC97_LOCK_BOTH_RETURN(pDevIns, pThis, pStream->u8SD, VINF_IOM_R3_IOPORT_WRITE);
     3050        DEVAC97_LOCK_BOTH_RETURN(pDevIns, pThis, pStream, VINF_IOM_R3_IOPORT_WRITE);
    30593051    }
    30603052
     
    31443136                            /* Arm the timer for this stream. */
    31453137                            /** @todo r=bird: This function returns bool, not VBox status! */
    3146                             ichac97R3TimerSet(pDevIns, pThis, pStream, pStream->State.cTransferTicks);
     3138                            ichac97R3TimerSet(pDevIns, pStream, pStream->State.cTransferTicks);
    31473139                        }
    31483140                    }
     
    32293221
    32303222    if (pStream)
    3231         DEVAC97_UNLOCK_BOTH(pDevIns, pThis, pStream->u8SD);
     3223        DEVAC97_UNLOCK_BOTH(pDevIns, pThis, pStream);
    32323224
    32333225    return rc;
     
    36373629        {
    36383630            /* Re-arm the timer for this stream. */
    3639             /** @todo r=bird: This function returns bool, not VBox status! */
    3640             ichac97R3TimerSet(pDevIns, pThis, pStream, pStream->State.cTransferTicks);
     3631            ichac97R3TimerSet(pDevIns, pStream, pStream->State.cTransferTicks);
    36413632        }
    36423633
     
    41394130     * Create all hardware streams.
    41404131     */
     4132    AssertCompile(RT_ELEMENTS(pThis->aStreams) == AC97_MAX_STREAMS);
    41414133    for (unsigned i = 0; i < AC97_MAX_STREAMS; i++)
    41424134    {
    4143         int rc2 = ichac97R3StreamCreate(pThis, &pThis->aStreams[i], i /* SD# */);
    4144         AssertRC(rc2);
    4145         if (RT_SUCCESS(rc))
    4146             rc = rc2;
    4147     }
     4135        rc = ichac97R3StreamCreate(pThis, &pThis->aStreams[i], i /* SD# */);
     4136        AssertRCReturn(rc, rc);
     4137    }
     4138
     4139    /*
     4140     * Create the emulation timers (one per stream).
     4141     *
     4142     * We must the critical section for the timers as the device has a
     4143     * noop section associated with it.
     4144     *
     4145     * Note:  Use TMCLOCK_VIRTUAL_SYNC here, as the guest's AC'97 driver
     4146     *        relies on exact (virtual) DMA timing and uses DMA Position Buffers
     4147     *        instead of the LPIB registers.
     4148     */
     4149    static const char * const s_apszNames[] = { "AC97 PI", "AC97 PO", "AC97 MC" };
     4150    AssertCompile(RT_ELEMENTS(s_apszNames) == AC97_MAX_STREAMS);
     4151    for (unsigned i = 0; i < AC97_MAX_STREAMS; i++)
     4152    {
     4153        rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, ichac97R3Timer, &pThis->aStreams[i],
     4154                                  TMTIMER_FLAGS_NO_CRIT_SECT, s_apszNames[i], &pThis->aStreams[i].hTimer);
     4155        AssertRCReturn(rc, rc);
     4156
     4157        rc = PDMDevHlpTimerSetCritSect(pDevIns, pThis->aStreams[i].hTimer, &pThis->CritSect);
     4158        AssertRCReturn(rc, rc);
     4159    }
     4160
    41484161
    41494162# ifdef VBOX_WITH_AUDIO_AC97_ONETIME_INIT
     
    42434256
    42444257    ichac97R3Reset(pDevIns);
    4245 
    4246     /*
    4247      * Create the emulation timers (one per stream).
    4248      *
    4249      * We must the critical section for the timers as the device has a
    4250      * noop section associated with it.
    4251      *
    4252      * Note:  Use TMCLOCK_VIRTUAL_SYNC here, as the guest's AC'97 driver
    4253      *        relies on exact (virtual) DMA timing and uses DMA Position Buffers
    4254      *        instead of the LPIB registers.
    4255      */
    4256     static const char * const s_apszNames[] = { "AC97 PI", "AC97 PO", "AC97 MC" };
    4257     AssertCompile(RT_ELEMENTS(s_apszNames) == AC97_MAX_STREAMS);
    4258     AssertCompile(RT_ELEMENTS(pThis->ahTimers) == AC97_MAX_STREAMS);
    4259     for (unsigned i = 0; i < AC97_MAX_STREAMS; i++)
    4260     {
    4261         rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, ichac97R3Timer, &pThis->aStreams[i],
    4262                                   TMTIMER_FLAGS_NO_CRIT_SECT, s_apszNames[i], &pThis->ahTimers[i]);
    4263         AssertRCReturn(rc, rc);
    4264 
    4265         rc = PDMDevHlpTimerSetCritSect(pDevIns, pThis->ahTimers[i], &pThis->CritSect);
    4266         AssertRCReturn(rc, rc);
    4267     }
    42684258
    42694259    /*
  • trunk/src/VBox/Devices/Audio/HDAStream.cpp

    r82332 r82345  
    5454    pStream->pMixSink       = NULL;
    5555    pStream->pHDAState      = pThis;
    56     pStream->hTimer         = pThis->ahTimers[u8SD];
     56    Assert(pStream->hTimer != NIL_TMTIMERHANDLE); /* hdaR3Construct initalized this one already. */
    5757
    5858    pStream->State.fInReset = false;
  • trunk/src/VBox/Devices/Audio/HDAStream.h

    r82332 r82345  
    235235    /** Pointer to HDA sink this stream is attached to. */
    236236    R3PTRTYPE(PHDAMIXERSINK) pMixSink;
    237     /** Stream's timer (copy of HDASTATE::ahTimers[u8SD]). */
     237    /** The timer for pumping data thru the attached LUN drivers. */
    238238    TMTIMERHANDLE            hTimer;
    239239    /** The stream'S critical section to serialize access. */
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