VirtualBox

Changeset 26376 in vbox


Ignore:
Timestamp:
Feb 9, 2010 2:25:28 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
57469
Message:

HPET: reworking locking per Knut suggestions

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/pdmdev.h

    r26172 r26376  
    16261626
    16271627/** Current PDMHPETREG version number. */
    1628 #define PDM_HPETREG_VERSION     0x1f010000
     1628#define PDM_HPETREG_VERSION     0x1f010001
    16291629
    16301630/**
     
    16361636    uint32_t                u32Version;
    16371637
    1638     /**
    1639      * Acquires the PDM lock.
    1640      *
    1641      * @returns VINF_SUCCESS on success.
    1642      * @returns rc if we failed to acquire the lock.
    1643      * @param   pDevIns         The HPET device instance.
    1644      * @param   rc              What to return if we fail to acquire the lock.
    1645      */
    1646     DECLRCCALLBACKMEMBER(int,   pfnLock,(PPDMDEVINS pDevIns, int rc));
    1647 
    1648     /**
    1649      * Releases the PDM lock.
    1650      *
    1651      * @param   pDevIns         The HPET device instance.
    1652      */
    1653     DECLRCCALLBACKMEMBER(void,  pfnUnlock,(PPDMDEVINS pDevIns));
     1638    /* just leave in case HPET will need PDM interaction in RC */
    16541639
    16551640    /** Just a safety precaution. */
     
    16631648
    16641649/** Current PDMHPETHLPRC version number. */
    1665 #define PDM_HPETHLPRC_VERSION                   PDM_VERSION_MAKE(0xffee, 1, 0)
     1650#define PDM_HPETHLPRC_VERSION                   PDM_VERSION_MAKE(0xffee, 1, 1)
    16661651
    16671652
     
    16741659    uint32_t                u32Version;
    16751660
    1676     /**
    1677      * Acquires the PDM lock.
    1678      *
    1679      * @returns VINF_SUCCESS on success.
    1680      * @returns rc if we failed to acquire the lock.
    1681      * @param   pDevIns         The HPET device instance.
    1682      * @param   rc              What to return if we fail to acquire the lock.
    1683      */
    1684     DECLR0CALLBACKMEMBER(int,   pfnLock,(PPDMDEVINS pDevIns, int rc));
    1685 
    1686     /**
    1687      * Releases the PDM lock.
    1688      *
    1689      * @param   pDevIns         The HPET device instance.
    1690      */
    1691     DECLR0CALLBACKMEMBER(void,  pfnUnlock,(PPDMDEVINS pDevIns));
     1661
     1662    /* just leave in case HPET will need PDM interaction in R0 */
    16921663
    16931664    /** Just a safety precaution. */
     
    17011672
    17021673/** Current PDMHPETHLPR0 version number. */
    1703 #define PDM_HPETHLPR0_VERSION                   PDM_VERSION_MAKE(0xffed, 1, 0)
     1674#define PDM_HPETHLPR0_VERSION                   PDM_VERSION_MAKE(0xffed, 1, 1)
    17041675
    17051676/**
     
    17201691     */
    17211692    DECLR3CALLBACKMEMBER(int, pfnSetLegacyMode,(PPDMDEVINS pDevIns, bool fActivate));
    1722 
    1723     /**
    1724      * Acquires the PDM lock.
    1725      *
    1726      * @returns VINF_SUCCESS on success.
    1727      * @returns rc if we failed to acquire the lock.
    1728      * @param   pDevIns         The HPET device instance.
    1729      * @param   rc              What to return if we fail to acquire the lock.
    1730      */
    1731     DECLR3CALLBACKMEMBER(int,   pfnLock,(PPDMDEVINS pDevIns, int rc));
    1732 
    1733     /**
    1734      * Releases the PDM lock.
    1735      *
    1736      * @param   pDevIns         The HPET device instance.
    1737      */
    1738     DECLR3CALLBACKMEMBER(void,  pfnUnlock,(PPDMDEVINS pDevIns));
    17391693
    17401694    /**
  • trunk/src/VBox/Devices/PC/DevHPET.cpp

    r26329 r26376  
    177177    /* main counter */
    178178    uint64_t             u64HpetCounter;
     179
     180    /* Global device lock */
     181    PDMCRITSECT          csLock;
    179182} HpetState;
    180183
     
    199202static const bool fHpetLocking = true;
    200203
    201 DECLINLINE(int) hpetLock(HpetState* pThis)
     204DECLINLINE(int) hpetLock(HpetState* pThis, int rcBusy)
    202205{
    203206    if (!fHpetLocking)
    204         return 0;
    205 
    206     return pThis->CTX_SUFF(pHpetHlp)->pfnLock(pThis->CTX_SUFF(pDevIns),
    207                                               VERR_INTERNAL_ERROR);
     207        return VINF_SUCCESS;
     208
     209    return PDMCritSectEnter(&pThis->csLock, rcBusy);
    208210}
    209211
     
    213215        return;
    214216
    215     pThis->CTX_SUFF(pHpetHlp)->pfnUnlock(pThis->CTX_SUFF(pDevIns));
     217    PDMCritSectLeave(&pThis->csLock);
    216218}
    217219
     
    706708    LogFlow(("hpetMMIORead: %llx (%x)\n", (uint64_t)GCPhysAddr, iIndex));
    707709
    708     rc = hpetLock(pThis);
    709     AssertLogRelRCReturn(rc, rc);
     710    rc = hpetLock(pThis, VINF_IOM_HC_MMIO_READ);
     711    if (RT_UNLIKELY(rc != VINF_SUCCESS))
     712        return rc;
    710713
    711714    switch (cb)
     
    748751             (uint64_t)GCPhysAddr, iIndex, *(uint32_t*)pv));
    749752
    750     rc = hpetLock(pThis);
    751     AssertLogRelRCReturn(rc, rc);
     753    rc = hpetLock(pThis, VINF_IOM_HC_MMIO_WRITE);
     754    if (RT_UNLIKELY(rc != VINF_SUCCESS))
     755        return rc;
    752756
    753757    switch (cb)
     
    921925        return;
    922926
    923     rc = hpetLock(pThis);
     927    /* Lock in R3 must either block or succeed */
     928    rc = hpetLock(pThis, VERR_IGNORED);
     929   
    924930    AssertLogRelRCReturnVoid(rc);
    925931
     
    11221128        return rc;
    11231129    }
     1130
     1131    /*
     1132     * Initialize critical section.
     1133     */
     1134    rc = PDMDevHlpCritSectInit(pDevIns, &pThis->csLock, RT_SRC_POS, "HPET");
     1135    if (RT_FAILURE(rc))
     1136        return PDMDEV_SET_ERROR(pDevIns, rc, N_("HPET cannot initialize critical section"));
     1137
    11241138    /*
    11251139     * Register the MMIO range, PDM API requests page aligned
  • trunk/src/VBox/VMM/PDMDevMiscHlp.cpp

    r26165 r26376  
    564564}
    565565
    566 
    567 /** @interface_method_impl{PDMHPETHLPR3,pfnLock} */
    568 static DECLCALLBACK(int) pdmR3HpetHlp_Lock(PPDMDEVINS pDevIns, int rc)
    569 {
    570     PDMDEV_ASSERT_DEVINS(pDevIns);
    571     LogFlow(("pdmR3HpetHlp_Lock: caller='%s'/%d: rc=%Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
    572     return pdmLockEx(pDevIns->Internal.s.pVMR3, rc);
    573 }
    574 
    575 
    576 /** @interface_method_impl{PDMHPETHLPR3,pfnUnlock} */
    577 static DECLCALLBACK(void) pdmR3HpetHlp_Unlock(PPDMDEVINS pDevIns)
    578 {
    579     PDMDEV_ASSERT_DEVINS(pDevIns);
    580     LogFlow(("pdmR3HpetHlp_Unlock: caller='%s'/%d:\n", pDevIns->pReg->szName, pDevIns->iInstance));
    581     pdmUnlock(pDevIns->Internal.s.pVMR3);
    582 }
    583 
    584 
    585566/** @interface_method_impl{PDMHPETHLPR3,pfnGetRCHelpers} */
    586567static DECLCALLBACK(PCPDMHPETHLPRC) pdmR3HpetHlp_GetRCHelpers(PPDMDEVINS pDevIns)
     
    620601    PDM_HPETHLPR3_VERSION,
    621602    pdmR3HpetHlp_SetLegacyMode,
    622     pdmR3HpetHlp_Lock,
    623     pdmR3HpetHlp_Unlock,
    624603    pdmR3HpetHlp_GetRCHelpers,
    625604    pdmR3HpetHlp_GetR0Helpers,
  • trunk/src/VBox/VMM/VMMGC/PDMGCDevice.cpp

    r26271 r26376  
    587587 */
    588588
    589 /** @interface_method_impl{PDMHPETHLPRC,pfnLock} */
    590 static DECLCALLBACK(int) pdmRCHpetHlp_Lock(PPDMDEVINS pDevIns, int rc)
    591 {
    592     PDMDEV_ASSERT_DEVINS(pDevIns);
    593     return pdmLockEx(pDevIns->Internal.s.pVMRC, rc);
    594 }
    595 
    596 
    597 /** @interface_method_impl{PDMHPETHLPRC,pfnUnlock} */
    598 static DECLCALLBACK(void) pdmRCHpetHlp_Unlock(PPDMDEVINS pDevIns)
    599 {
    600     PDMDEV_ASSERT_DEVINS(pDevIns);
    601     pdmUnlock(pDevIns->Internal.s.pVMRC);
    602 }
    603 
    604589
    605590/**
     
    609594{
    610595    PDM_HPETHLPRC_VERSION,
    611     pdmRCHpetHlp_Lock,
    612     pdmRCHpetHlp_Unlock,
    613596    PDM_HPETHLPRC_VERSION, /* the end */
    614597};
     
    785768    }
    786769}
    787 
  • trunk/src/VBox/VMM/VMMR0/PDMR0Device.cpp

    r26175 r26376  
    622622 */
    623623
    624 /** @interface_method_impl{PDMHPETHLPR0,pfnLock} */
    625 static DECLCALLBACK(int) pdmR0HpetHlp_Lock(PPDMDEVINS pDevIns, int rc)
    626 {
    627     PDMDEV_ASSERT_DEVINS(pDevIns);
    628     return pdmLockEx(pDevIns->Internal.s.pVMR0, rc);
    629 }
    630 
    631 
    632 /** @interface_method_impl{PDMHPETHLPR0,pfnUnlock} */
    633 static DECLCALLBACK(void) pdmR0HpetHlp_Unlock(PPDMDEVINS pDevIns)
    634 {
    635     PDMDEV_ASSERT_DEVINS(pDevIns);
    636     pdmUnlock(pDevIns->Internal.s.pVMR0);
    637 }
    638 
    639 
    640624/**
    641625 * The Ring-0 HPET Helper Callbacks.
     
    644628{
    645629    PDM_HPETHLPR0_VERSION,
    646     pdmR0HpetHlp_Lock,
    647     pdmR0HpetHlp_Unlock,
    648630    PDM_HPETHLPR0_VERSION, /* the end */
    649631};
     
    818800    }
    819801}
    820 
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette