VirtualBox

Changeset 18532 in vbox for trunk/src


Ignore:
Timestamp:
Mar 30, 2009 12:01:20 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
45397
Message:

PDMCritSect: Increased the padding size on 32-bit (+32 bytes) for saving the name. Added PDMR3CritSectCountOwned(). Promoted three of the stats to release stats.

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/PDMCritSect.cpp

    r14657 r18532  
    3535#include <iprt/assert.h>
    3636#include <iprt/thread.h>
     37#include <iprt/string.h>
    3738
    3839
     
    114115    if (RT_SUCCESS(rc))
    115116    {
    116         pCritSect->pVMR3 = pVM;
    117         pCritSect->pVMR0 = pVM->pVMR0;
    118         pCritSect->pVMRC = pVM->pVMRC;
    119         pCritSect->pvKey = pvKey;
     117        pCritSect->pVMR3         = pVM;
     118        pCritSect->pVMR0         = pVM->pVMR0;
     119        pCritSect->pVMRC         = pVM->pVMRC;
     120        pCritSect->pvKey         = pvKey;
    120121        pCritSect->EventToSignal = NIL_RTSEMEVENT;
    121         pCritSect->pNext = pVM->pdm.s.pCritSects;
     122        pCritSect->pNext         = pVM->pdm.s.pCritSects;
     123        pCritSect->pszName       = RTStrDup(pszName);
    122124        pVM->pdm.s.pCritSects = pCritSect;
    123 #ifdef VBOX_WITH_STATISTICS
    124125        STAMR3RegisterF(pVM, &pCritSect->StatContentionRZLock,  STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionRZLock", pszName);
    125126        STAMR3RegisterF(pVM, &pCritSect->StatContentionRZUnlock,STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionRZUnlock", pszName);
    126127        STAMR3RegisterF(pVM, &pCritSect->StatContentionR3,      STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,          NULL, "/PDM/CritSects/%s/ContentionR3", pszName);
     128#ifdef VBOX_WITH_STATISTICS
    127129        STAMR3RegisterF(pVM, &pCritSect->StatLocked,        STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, NULL, "/PDM/CritSects/%s/Locked", pszName);
    128130#endif
     
    189191
    190192    /* delete */
    191     pCritSect->pNext = NULL;
    192     pCritSect->pvKey = NULL;
    193     pCritSect->pVMR3 = NULL;
    194     pCritSect->pVMR0 = NIL_RTR0PTR;
    195     pCritSect->pVMRC = NIL_RTRCPTR;
    196 #ifdef VBOX_WITH_STATISTICS
     193    pCritSect->pNext   = NULL;
     194    pCritSect->pvKey   = NULL;
     195    pCritSect->pVMR3   = NULL;
     196    pCritSect->pVMR0   = NIL_RTR0PTR;
     197    pCritSect->pVMRC   = NIL_RTRCPTR;
     198    RTStrFree((char *)pCritSect->pszName);
     199    pCritSect->pszName = NULL;
    197200    if (!fFinal)
    198201    {
     
    200203        STAMR3Deregister(pVM, &pCritSect->StatContentionRZUnlock);
    201204        STAMR3Deregister(pVM, &pCritSect->StatContentionR3);
     205#ifdef VBOX_WITH_STATISTICS
    202206        STAMR3Deregister(pVM, &pCritSect->StatLocked);
    203     }
    204207#endif
     208    }
    205209    return RTCritSectDelete(&pCritSect->Core);
    206210}
     
    334338 * @returns VERR_SEM_DESTROYED if RTCritSectDelete was called while waiting.
    335339 * @param   pCritSect       The critical section.
    336  * @param   EventToSignal     The semapore that should be signalled.
     340 * @param   EventToSignal   The semapore that should be signalled.
    337341 */
    338342VMMR3DECL(int) PDMR3CritSectScheduleExitEvent(PPDMCRITSECT pCritSect, RTSEMEVENT EventToSignal)
     
    350354}
    351355
     356
     357/**
     358 * Counts the critical sections owned by the calling thread, optionally
     359 * returning a comma separated list naming them.
     360 *
     361 * This is for diagnostic purposes only.
     362 *
     363 * @returns Lock count.
     364 *
     365 * @param   pVM             The VM handle.
     366 * @param   pszNames        Where to return the critical section names.
     367 * @param   cbNames         The size of the buffer.
     368 */
     369VMMR3DECL(uint32_t) PDMR3CritSectCountOwned(PVM pVM, char *pszNames, size_t cbNames)
     370{
     371    /*
     372     * Init the name buffer.
     373     */
     374    size_t cchLeft = cbNames;
     375    if (cchLeft)
     376    {
     377        cchLeft--;
     378        pszNames[0] = pszNames[cchLeft] = '\0';
     379    }
     380
     381    /*
     382     * Iterate the critical sections.
     383     */
     384    /* This is unsafe, but wtf. */
     385    RTNATIVETHREAD const    hNativeThread = RTThreadNativeSelf();
     386    uint32_t                cCritSects = 0;
     387    for (PPDMCRITSECTINT pCur = pVM->pdm.s.pCritSects;
     388         pCur;
     389         pCur = pCur->pNext)
     390    {
     391        /* Same as RTCritSectIsOwner(). */
     392        if (pCur->Core.NativeThreadOwner == hNativeThread)
     393        {
     394            cCritSects++;
     395
     396            /*
     397             * Copy the name if there is space. Fun stuff.
     398             */
     399            if (cchLeft)
     400            {
     401                /* try add comma. */
     402                if (cCritSects != 1)
     403                {
     404                    *pszNames++ = ',';
     405                    if (--cchLeft)
     406                    {
     407                        *pszNames++ = ' ';
     408                        cchLeft--;
     409                    }
     410                }
     411
     412                /* try copy the name. */
     413                if (cchLeft)
     414                {
     415                    size_t const cchName = strlen(pCur->pszName);
     416                    if (cchName < cchLeft)
     417                    {
     418                        memcpy(pszNames, pCur->pszName, cchName);
     419                        pszNames += cchName;
     420                        cchLeft -= cchName;
     421                    }
     422                    else
     423                    {
     424                        if (cchLeft > 2)
     425                        {
     426                            memcpy(pszNames, pCur->pszName, cchLeft - 2);
     427                            pszNames += cchLeft - 2;
     428                            cchLeft = 2;
     429                        }
     430                        while (cchLeft-- > 0)
     431                            *pszNames++ = '+';
     432                    }
     433                }
     434                *pszNames = '\0';
     435            }
     436        }
     437    }
     438
     439    return cCritSects;
     440}
  • trunk/src/VBox/VMM/VMMAll/PDMAllCritSect.cpp

    r13898 r18532  
    5757    NOREF(rcBusy);
    5858
    59     STAM_STATS({ if (pCritSect->s.Core.cLockers >= 0 && !RTCritSectIsOwner(&pCritSect->s.Core)) STAM_COUNTER_INC(&pCritSect->s.StatContentionR3); });
     59    STAM_REL_STATS({if (pCritSect->s.Core.cLockers >= 0 && !RTCritSectIsOwner(&pCritSect->s.Core))
     60                        STAM_COUNTER_INC(&pCritSect->s.StatContentionR3); });
    6061    int rc = RTCritSectEnter(&pCritSect->s.Core);
    6162    STAM_STATS({ if (pCritSect->s.Core.cNestings == 1) STAM_PROFILE_ADV_START(&pCritSect->s.StatLocked, l); });
     
    9596     */
    9697    LogFlow(("PDMCritSectEnter: locked => R3 (%Rrc)\n", rcBusy));
    97     STAM_COUNTER_INC(&pCritSect->s.StatContentionRZLock);
     98    STAM_REL_COUNTER_INC(&pCritSect->s.StatContentionRZLock);
    9899    return rcBusy;
    99100#endif /* !IN_RING3 */
     
    203204    VM_FF_SET(pVM, VM_FF_PDM_CRITSECT);
    204205    VM_FF_SET(pVM, VM_FF_TO_R3);
    205     STAM_COUNTER_INC(&pVM->pdm.s.StatQueuedCritSectLeaves);
    206     STAM_COUNTER_INC(&pCritSect->s.StatContentionRZUnlock);
     206    STAM_REL_COUNTER_INC(&pVM->pdm.s.StatQueuedCritSectLeaves);
     207    STAM_REL_COUNTER_INC(&pCritSect->s.StatContentionRZUnlock);
    207208#endif /* !IN_RING3 */
    208209}
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