VirtualBox

Changeset 12983 in vbox


Ignore:
Timestamp:
Oct 4, 2008 10:17:38 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
37416
Message:

#1865: PDMCritSect.

Location:
trunk
Files:
5 edited

Legend:

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

    r9216 r12983  
    5959typedef const PDMCRITSECT *PCPDMCRITSECT;
    6060
    61 /**
    62  * Initializes a PDM critical section for internal use.
    63  *
    64  * The PDM critical sections are derived from the IPRT critical sections, but
    65  * works in GC as well.
    66  *
    67  * @returns VBox status code.
    68  * @param   pVM             The VM handle.
    69  * @param   pDevIns         Device instance.
    70  * @param   pCritSect       Pointer to the critical section.
    71  * @param   pszName         The name of the critical section (for statistics).
    72  */
    73 PDMR3DECL(int) PDMR3CritSectInit(PVM pVM, PPDMCRITSECT pCritSect, const char *pszName);
    74 
    75 /**
    76  * Enters a PDM critical section.
    77  *
    78  * @returns VINF_SUCCESS if entered successfully.
    79  * @returns rcBusy when encountering a busy critical section in GC/R0.
    80  * @returns VERR_SEM_DESTROYED if the critical section is dead.
    81  *
    82  * @param   pCritSect           The PDM critical section to enter.
    83  * @param   rcBusy              The status code to return when we're in GC or R0
    84  *                              and the section is busy.
    85  */
    86 PDMDECL(int) PDMCritSectEnter(PPDMCRITSECT pCritSect, int rcBusy);
    87 
    88 /**
    89  * Enters a PDM critical section.
    90  *
    91  * @returns VINF_SUCCESS if entered successfully.
    92  * @returns rcBusy when encountering a busy critical section in GC/R0.
    93  * @returns VERR_SEM_DESTROYED if the critical section is dead.
    94  *
    95  * @param   pCritSect           The PDM critical section to enter.
    96  * @param   fCallHost           Whether this is a VMMGCCallHost() or VMMR0CallHost() request.
    97  */
    98 PDMR3DECL(int) PDMR3CritSectEnterEx(PPDMCRITSECT pCritSect, bool fCallHost);
    99 
    100 /**
    101  * Leaves a critical section entered with PDMCritSectEnter().
    102  *
    103  * @param   pCritSect           The PDM critical section to leave.
    104  */
    105 PDMDECL(void) PDMCritSectLeave(PPDMCRITSECT pCritSect);
    106 
    107 /**
    108  * Checks the caller is the owner of the critical section.
    109  *
    110  * @returns true if owner.
    111  * @returns false if not owner.
    112  * @param   pCritSect   The critical section.
    113  */
    114 PDMDECL(bool) PDMCritSectIsOwner(PCPDMCRITSECT pCritSect);
    115 
    116 /**
    117  * Checks if a critical section is initialized or not.
    118  *
    119  * @returns true if initialized.
    120  * @returns false if not initialized.
    121  * @param   pCritSect   The critical section.
    122  */
    123 PDMDECL(bool) PDMCritSectIsInitialized(PCPDMCRITSECT pCritSect);
    124 
    125 /**
    126  * Try enter a critical section.
    127  *
    128  * @returns VINF_SUCCESS on success.
    129  * @returns VERR_SEM_BUSY if the critsect was owned.
    130  * @returns VERR_SEM_NESTED if nested enter on a no nesting section. (Asserted.)
    131  * @returns VERR_SEM_DESTROYED if RTCritSectDelete was called while waiting.
    132  * @param   pCritSect   The critical section.
    133  */
    134 PDMR3DECL(int) PDMR3CritSectTryEnter(PPDMCRITSECT pCritSect);
    135 
    136 /**
    137  * Schedule a event semaphore for signalling upon critsect exit.
    138  *
    139  * @returns VINF_SUCCESS on success.
    140  * @returns VERR_TOO_MANY_SEMAPHORES if an event was already scheduled.
    141  * @returns VERR_NOT_OWNER if we're not the critsect owner.
    142  * @returns VERR_SEM_DESTROYED if RTCritSectDelete was called while waiting.
    143  * @param   pCritSect       The critical section.
    144  * @param   EventToSignal     The semapore that should be signalled.
    145  */
    146 PDMR3DECL(int) PDMR3CritSectScheduleExitEvent(PPDMCRITSECT pCritSect, RTSEMEVENT EventToSignal);
    147 
    148 /**
    149  * Deletes the critical section.
    150  *
    151  * @returns VBox status code.
    152  * @param   pCritSect           The PDM critical section to destroy.
    153  */
    154 PDMR3DECL(int) PDMR3CritSectDelete(PPDMCRITSECT pCritSect);
    155 
    156 /**
    157  * Deletes all remaining critical sections.
    158  *
    159  * This is called at the end of the termination process.
    160  *
    161  * @returns VBox status.
    162  *          First error code, rest is lost.
    163  * @param   pVM         The VM handle.
    164  * @remark  Don't confuse this with PDMR3CritSectDelete.
    165  */
    166 PDMDECL(int) PDMR3CritSectTerm(PVM pVM);
    167 
    168 /**
    169  * Process the critical sections queued for ring-3 'leave'.
    170  *
    171  * @param   pVM         The VM handle.
    172  */
     61PDMR3DECL(int)  PDMR3CritSectInit(PVM pVM, PPDMCRITSECT pCritSect, const char *pszName);
     62PDMDECL(int)    PDMCritSectEnter(PPDMCRITSECT pCritSect, int rcBusy);
     63PDMR3DECL(int)  PDMR3CritSectEnterEx(PPDMCRITSECT pCritSect, bool fCallHost);
     64PDMDECL(void)   PDMCritSectLeave(PPDMCRITSECT pCritSect);
     65PDMDECL(bool)   PDMCritSectIsOwner(PCPDMCRITSECT pCritSect);
     66PDMDECL(bool)   PDMCritSectIsInitialized(PCPDMCRITSECT pCritSect);
     67PDMR3DECL(int)  PDMR3CritSectTryEnter(PPDMCRITSECT pCritSect);
     68PDMR3DECL(int)  PDMR3CritSectScheduleExitEvent(PPDMCRITSECT pCritSect, RTSEMEVENT EventToSignal);
     69PDMR3DECL(int)  PDMR3CritSectDelete(PPDMCRITSECT pCritSect);
     70PDMDECL(int)    PDMR3CritSectTerm(PVM pVM);
    17371PDMR3DECL(void) PDMR3CritSectFF(PVM pVM);
    17472
  • trunk/src/VBox/VMM/PDMCritSect.cpp

    r9154 r12983  
    11/* $Id$ */
    22/** @file
    3  * PDM Critical Sections
     3 * PDM - Critical Sections, Ring-3.
    44 */
    55
     
    1919 * additional information or have any questions.
    2020 */
    21 
    2221
    2322
     
    7170         pCur;
    7271         pCur = pCur->pNext)
    73         pCur->pVMGC = pVM->pVMGC;
     72        pCur->pVMRC = pVM->pVMRC;
    7473}
    7574
     
    117116        pCritSect->pVMR3 = pVM;
    118117        pCritSect->pVMR0 = (RTR0PTR)pVM;//pVM->pVMR0;
    119         pCritSect->pVMGC = pVM->pVMGC;
     118        pCritSect->pVMRC = pVM->pVMRC;
    120119        pCritSect->pvKey = pvKey;
    121120        pCritSect->EventToSignal = NIL_RTSEMEVENT;
     
    123122        pVM->pdm.s.pCritSects = pCritSect;
    124123#ifdef VBOX_WITH_STATISTICS
    125         STAMR3RegisterF(pVM, &pCritSect->StatContentionR0GCLock,   STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionR0GCLock", pszName);
    126         STAMR3RegisterF(pVM, &pCritSect->StatContentionR0GCUnlock, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionR0GCUnlock", pszName);
    127         STAMR3RegisterF(pVM, &pCritSect->StatContentionR3,         STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionR3", pszName);
    128         STAMR3RegisterF(pVM, &pCritSect->StatLocked,           STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, NULL, "/PDM/CritSects/%s/Locked", pszName);
     124        STAMR3RegisterF(pVM, &pCritSect->StatContentionRZLock,  STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionRZLock", pszName);
     125        STAMR3RegisterF(pVM, &pCritSect->StatContentionRZUnlock,STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionRZUnlock", pszName);
     126        STAMR3RegisterF(pVM, &pCritSect->StatContentionR3,      STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionR3", pszName);
     127        STAMR3RegisterF(pVM, &pCritSect->StatLocked,        STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, NULL, "/PDM/CritSects/%s/Locked", pszName);
    129128#endif
    130129    }
     
    191190    /* delete */
    192191    pCritSect->pNext = NULL;
    193     pCritSect->pVMGC = 0;
     192    pCritSect->pvKey = NULL;
    194193    pCritSect->pVMR3 = NULL;
    195194    pCritSect->pVMR0 = NIL_RTR0PTR;
    196     pCritSect->pvKey = NULL;
     195    pCritSect->pVMRC = NIL_RTRCPTR;
    197196#ifdef VBOX_WITH_STATISTICS
    198197    if (!fFinal)
    199198    {
    200         STAMR3Deregister(pVM, &pCritSect->StatContentionR0GCLock);
    201         STAMR3Deregister(pVM, &pCritSect->StatContentionR0GCUnlock);
     199        STAMR3Deregister(pVM, &pCritSect->StatContentionRZLock);
     200        STAMR3Deregister(pVM, &pCritSect->StatContentionRZUnlock);
    202201        STAMR3Deregister(pVM, &pCritSect->StatContentionR3);
    203202        STAMR3Deregister(pVM, &pCritSect->StatLocked);
  • trunk/src/VBox/VMM/PDMInternal.h

    r12980 r12983  
    196196    RTCRITSECT                      Core;
    197197    /** Pointer to the next critical section.
    198      * This chain is used for relocating pVMGC and device cleanup. */
     198     * This chain is used for relocating pVMRC and device cleanup. */
    199199    R3PTRTYPE(struct PDMCRITSECTINT *) pNext;
    200200    /** Owner identifier.
     
    203203    RTR3PTR                         pvKey;
    204204    /** Pointer to the VM - R3Ptr. */
    205     R3PTRTYPE(PVM)                  pVMR3;
     205    PVMR3                           pVMR3;
    206206    /** Pointer to the VM - R0Ptr. */
    207     R0PTRTYPE(PVM)                  pVMR0;
     207    PVMR0                           pVMR0;
    208208    /** Pointer to the VM - GCPtr. */
    209     RCPTRTYPE(PVM)                  pVMGC;
     209    PVMRC                           pVMRC;
    210210#if HC_ARCH_BITS == 64
    211     uint32_t            padding;
     211    RTRCPTR                         padding;
    212212#endif
    213213    /** Event semaphore that is scheduled to be signaled upon leaving the
    214214     * critical section. This is Ring-3 only of course. */
    215215    RTSEMEVENT                      EventToSignal;
    216     /** R0/GC lock contention. */
    217     STAMCOUNTER                     StatContentionR0GCLock;
    218     /** R0/GC unlock contention. */
    219     STAMCOUNTER                     StatContentionR0GCUnlock;
     216    /** R0/RC lock contention. */
     217    STAMCOUNTER                     StatContentionRZLock;
     218    /** R0/RC unlock contention. */
     219    STAMCOUNTER                     StatContentionRZUnlock;
    220220    /** R3 lock contention. */
    221221    STAMCOUNTER                     StatContentionR3;
    222222    /** Profiling the time the section is locked. */
    223223    STAMPROFILEADV                  StatLocked;
    224 } PDMCRITSECTINT, *PPDMCRITSECTINT;
     224} PDMCRITSECTINT;
     225typedef PDMCRITSECTINT *PPDMCRITSECTINT;
    225226
    226227
  • trunk/src/VBox/VMM/VMMAll/PDMAllCritSect.cpp

    r10204 r12983  
    11/* $Id$ */
    22/** @file
    3  * PDM Critical Sections
     3 * PDM - Critical Sections, All Contexts.
    44 */
    55
     
    6161    return rc;
    6262
    63 #else
     63#else  /* !IN_RING3 */
    6464    AssertMsgReturn(pCritSect->s.Core.u32Magic == RTCRITSECT_MAGIC, ("%RX32\n", pCritSect->s.Core.u32Magic),
    6565                    VERR_SEM_DESTROYED);
    66     PVM pVM = pCritSect->s.CTXALLSUFF(pVM);
     66    PVM pVM = pCritSect->s.CTX_SUFF(pVM);
    6767    Assert(pVM);
    6868
     
    9191     * Failed.
    9292     */
    93     LogFlow(("PDMCritSectEnter: locked => HC (%Vrc)\n", rcBusy));
    94     STAM_COUNTER_INC(&pCritSect->s.StatContentionR0GCLock);
     93    LogFlow(("PDMCritSectEnter: locked => R3 (%Vrc)\n", rcBusy));
     94    STAM_COUNTER_INC(&pCritSect->s.StatContentionRZLock);
    9595    return rcBusy;
    96 #endif
     96#endif /* !IN_RING3 */
    9797}
    9898
     
    157157    Assert(pCritSect->s.Core.cNestings > 0);
    158158    Assert(pCritSect->s.Core.cLockers >= 0);
    159     PVM pVM = pCritSect->s.CTXALLSUFF(pVM);
     159    PVM pVM = pCritSect->s.CTX_SUFF(pVM);
    160160    Assert(pVM);
    161161    Assert(pCritSect->s.Core.NativeThreadOwner == pVM->NativeThreadEMT);
     
    198198    VM_FF_SET(pVM, VM_FF_TO_R3);
    199199    STAM_COUNTER_INC(&pVM->pdm.s.StatQueuedCritSectLeaves);
    200     STAM_COUNTER_INC(&pCritSect->s.StatContentionR0GCUnlock);
    201 #endif
     200    STAM_COUNTER_INC(&pCritSect->s.StatContentionRZUnlock);
     201#endif /* !IN_RING3 */
    202202}
    203203
     
    215215    return RTCritSectIsOwner(&pCritSect->s.Core);
    216216#else
    217     PVM pVM = pCritSect->s.CTXALLSUFF(pVM);
     217    PVM pVM = pCritSect->s.CTX_SUFF(pVM);
    218218    Assert(pVM);
    219219    return pCritSect->s.Core.NativeThreadOwner == pVM->NativeThreadEMT;
  • trunk/src/VBox/VMM/testcase/tstVMStructGC.cpp

    r12970 r12983  
    338338    GEN_CHECK_OFF(PDMCRITSECTINT, pVMR3);
    339339    GEN_CHECK_OFF(PDMCRITSECTINT, pVMR0);
    340     GEN_CHECK_OFF(PDMCRITSECTINT, pVMGC);
    341     GEN_CHECK_OFF(PDMCRITSECTINT, StatContentionR0GCLock);
    342     GEN_CHECK_OFF(PDMCRITSECTINT, StatContentionR0GCUnlock);
     340    GEN_CHECK_OFF(PDMCRITSECTINT, pVMRC);
     341    GEN_CHECK_OFF(PDMCRITSECTINT, StatContentionRZLock);
     342    GEN_CHECK_OFF(PDMCRITSECTINT, StatContentionRZUnlock);
    343343    GEN_CHECK_OFF(PDMCRITSECTINT, StatContentionR3);
    344344    GEN_CHECK_OFF(PDMCRITSECTINT, StatLocked);
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