VirtualBox

Changeset 39917 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 31, 2012 2:04:52 PM (13 years ago)
Author:
vboxsync
Message:

STAM,GMM,VBoxDbg: Adding GMM statistics (at last). Introduces STAMTYPE_BOOL and STAMTYPE_BOOL_RESET. Fixes a beyond end of string access in VBoxDbg (memcmp).

Location:
trunk/src/VBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/VBoxDbgStatsQt4.cpp

    r33540 r39917  
    126126        /** STAMTYPE_U64 & STAMTYPE_U64_RESET. */
    127127        uint64_t            u64;
     128        /** STAMTYPE_BOOL and STAMTYPE_BOOL_RESET. */
     129        bool                f;
    128130        /** STAMTYPE_CALLBACK. */
    129131        QString            *pStr;
     
    10871089            break;
    10881090
     1091        case STAMTYPE_BOOL:
     1092        case STAMTYPE_BOOL_RESET:
     1093            pNode->Data.f = *(bool *)pvSample;
     1094            break;
     1095
    10891096        default:
    10901097            AssertMsgFailed(("%d\n", enmType));
     
    12551262                break;
    12561263            }
     1264
     1265            case STAMTYPE_BOOL:
     1266            case STAMTYPE_BOOL_RESET:
     1267            {
     1268                bool fPrev = pNode->Data.f;
     1269                pNode->Data.f = *(bool *)pvSample;
     1270                iDelta = pNode->Data.f - fPrev;
     1271                if (iDelta || pNode->i64Delta)
     1272                {
     1273                    pNode->i64Delta = iDelta;
     1274                    pNode->enmState = kDbgGuiStatsNodeState_kRefresh;
     1275                }
     1276                break;
     1277            }
     1278
    12571279            default:
    12581280                AssertMsgFailed(("%d\n", enmType));
     
    14751497            {
    14761498                int32_t i = iStart + (iLast + 1 - iStart) / 2;
    1477                 int iDiff = memcmp(pszSubName, pNode->papChildren[i]->pszName, cchSubName);
     1499                int iDiff;
     1500                size_t const cchCompare = RT_MIN(pNode->papChildren[i]->cchName, cchSubName);
     1501                iDiff = memcmp(pszSubName, pNode->papChildren[i]->pszName, cchCompare);
    14781502                if (!iDiff)
    1479                     iDiff = '\0' - pNode->papChildren[i]->pszName[cchSubName];
     1503                    iDiff = cchSubName == cchCompare ? 0 : cchSubName > cchCompare ? 1 : -1;
    14801504                if (iDiff > 0)
    14811505                {
     
    21522176            return formatHexNumber(sz, pNode->Data.u64, 16);
    21532177
     2178        case STAMTYPE_BOOL:
     2179        case STAMTYPE_BOOL_RESET:
     2180            return pNode->Data.f ? "true" : "false";
     2181
    21542182        default:
    21552183            AssertMsgFailed(("%d\n", pNode->enmType));
     
    22632291        case STAMTYPE_X64:
    22642292        case STAMTYPE_X64_RESET:
     2293        case STAMTYPE_BOOL:
     2294        case STAMTYPE_BOOL_RESET:
    22652295            return formatNumberSigned(sz, pNode->i64Delta);
    22662296        default:
     
    24252455            break;
    24262456
     2457        case STAMTYPE_BOOL:
     2458        case STAMTYPE_BOOL_RESET:
     2459            RTStrPrintf(szBuf, sizeof(szBuf), "%s %s", a_pNode->Data.f ? "true    " : "false   ", STAMR3GetUnit(a_pNode->enmUnit));
     2460            break;
     2461
    24272462        default:
    24282463            AssertMsgFailed(("enmType=%d\n", a_pNode->enmType));
  • trunk/src/VBox/VMM/VMMR0/GMMR0.cpp

    r39909 r39917  
    492492    /** @todo separate trees for distinctly different guest OSes. */
    493493    PAVLGCPTRNODECORE   pGlobalSharedModuleTree;
     494    /** Sharable modules (count of nodes in pGlobalSharedModuleTree). */
     495    uint32_t            cShareableModules;
    494496
    495497    /** The chunk list.  For simplifying the cleanup process. */
     
    874876    AssertCompile(RT_SIZEOFMEMB(GVM,gmm.s) <= RT_SIZEOFMEMB(GVM,gmm.padding));
    875877
    876     pGVM->gmm.s.enmPolicy = GMMOCPOLICY_INVALID;
    877     pGVM->gmm.s.enmPriority = GMMPRIORITY_INVALID;
    878     pGVM->gmm.s.fMayAllocate = false;
     878    pGVM->gmm.s.Stats.enmPolicy = GMMOCPOLICY_INVALID;
     879    pGVM->gmm.s.Stats.enmPriority = GMMPRIORITY_INVALID;
     880    pGVM->gmm.s.Stats.fMayAllocate = false;
    879881}
    880882
     
    11531155     * request has been serviced.
    11541156     */
    1155     if (    pGVM->gmm.s.enmPolicy > GMMOCPOLICY_INVALID
    1156         &&  pGVM->gmm.s.enmPolicy < GMMOCPOLICY_END)
     1157    if (    pGVM->gmm.s.Stats.enmPolicy > GMMOCPOLICY_INVALID
     1158        &&  pGVM->gmm.s.Stats.enmPolicy < GMMOCPOLICY_END)
    11571159    {
    11581160        /*
     
    11711173         * shared pages will be 'left behind'.)
    11721174         */
    1173         uint64_t    cPrivatePages = pGVM->gmm.s.cPrivatePages; /* save */
     1175        uint64_t    cPrivatePages = pGVM->gmm.s.Stats.cPrivatePages; /* save */
    11741176
    11751177        unsigned    iCountDown = 64;
     
    12011203        } while (fRedoFromStart);
    12021204
    1203         if (pGVM->gmm.s.cPrivatePages)
    1204             SUPR0Printf("GMMR0CleanupVM: hGVM=%#x has %#x private pages that cannot be found!\n", pGVM->hSelf, pGVM->gmm.s.cPrivatePages);
     1205        if (pGVM->gmm.s.Stats.cPrivatePages)
     1206            SUPR0Printf("GMMR0CleanupVM: hGVM=%#x has %#x private pages that cannot be found!\n", pGVM->hSelf, pGVM->gmm.s.Stats.cPrivatePages);
    12051207
    12061208        pGMM->cAllocatedPages -= cPrivatePages;
     
    12511253         * Account for shared pages that weren't freed.
    12521254         */
    1253         if (pGVM->gmm.s.cSharedPages)
    1254         {
    1255             Assert(pGMM->cSharedPages >= pGVM->gmm.s.cSharedPages);
    1256             SUPR0Printf("GMMR0CleanupVM: hGVM=%#x left %#x shared pages behind!\n", pGVM->hSelf, pGVM->gmm.s.cSharedPages);
    1257             pGMM->cLeftBehindSharedPages += pGVM->gmm.s.cSharedPages;
     1255        if (pGVM->gmm.s.Stats.cSharedPages)
     1256        {
     1257            Assert(pGMM->cSharedPages >= pGVM->gmm.s.Stats.cSharedPages);
     1258            SUPR0Printf("GMMR0CleanupVM: hGVM=%#x left %#x shared pages behind!\n", pGVM->hSelf, pGVM->gmm.s.Stats.cSharedPages);
     1259            pGMM->cLeftBehindSharedPages += pGVM->gmm.s.Stats.cSharedPages;
    12581260        }
    12591261
     
    12611263         * Clean up balloon statistics in case the VM process crashed.
    12621264         */
    1263         Assert(pGMM->cBalloonedPages >= pGVM->gmm.s.cBalloonedPages);
    1264         pGMM->cBalloonedPages -= pGVM->gmm.s.cBalloonedPages;
     1265        Assert(pGMM->cBalloonedPages >= pGVM->gmm.s.Stats.cBalloonedPages);
     1266        pGMM->cBalloonedPages -= pGVM->gmm.s.Stats.cBalloonedPages;
    12651267
    12661268        /*
    12671269         * Update the over-commitment management statistics.
    12681270         */
    1269         pGMM->cReservedPages -= pGVM->gmm.s.Reserved.cBasePages
    1270                               + pGVM->gmm.s.Reserved.cFixedPages
    1271                               + pGVM->gmm.s.Reserved.cShadowPages;
    1272         switch (pGVM->gmm.s.enmPolicy)
     1271        pGMM->cReservedPages -= pGVM->gmm.s.Stats.Reserved.cBasePages
     1272                              + pGVM->gmm.s.Stats.Reserved.cFixedPages
     1273                              + pGVM->gmm.s.Stats.Reserved.cShadowPages;
     1274        switch (pGVM->gmm.s.Stats.enmPolicy)
    12731275        {
    12741276            case GMMOCPOLICY_NO_OC:
     
    12811283
    12821284    /* zap the GVM data. */
    1283     pGVM->gmm.s.enmPolicy = GMMOCPOLICY_INVALID;
    1284     pGVM->gmm.s.enmPriority = GMMPRIORITY_INVALID;
    1285     pGVM->gmm.s.fMayAllocate = false;
     1285    pGVM->gmm.s.Stats.enmPolicy    = GMMOCPOLICY_INVALID;
     1286    pGVM->gmm.s.Stats.enmPriority = GMMPRIORITY_INVALID;
     1287    pGVM->gmm.s.Stats.fMayAllocate = false;
    12861288
    12871289    GMM_CHECK_SANITY_UPON_LEAVING(pGMM);
     
    13391341                    pChunk->cPrivate--;
    13401342                    pChunk->cFree++;
    1341                     pGVM->gmm.s.cPrivatePages--;
     1343                    pGVM->gmm.s.Stats.cPrivatePages--;
    13421344                    cFree++;
    13431345                }
     
    14771479    if (GMM_CHECK_SANITY_UPON_ENTERING(pGMM))
    14781480    {
    1479         if (    !pGVM->gmm.s.Reserved.cBasePages
    1480             &&  !pGVM->gmm.s.Reserved.cFixedPages
    1481             &&  !pGVM->gmm.s.Reserved.cShadowPages)
     1481        if (    !pGVM->gmm.s.Stats.Reserved.cBasePages
     1482            &&  !pGVM->gmm.s.Stats.Reserved.cFixedPages
     1483            &&  !pGVM->gmm.s.Stats.Reserved.cShadowPages)
    14821484        {
    14831485            /*
     
    14901492                 * Update the records.
    14911493                 */
    1492                 pGVM->gmm.s.Reserved.cBasePages = cBasePages;
    1493                 pGVM->gmm.s.Reserved.cFixedPages = cFixedPages;
    1494                 pGVM->gmm.s.Reserved.cShadowPages = cShadowPages;
    1495                 pGVM->gmm.s.enmPolicy = enmPolicy;
    1496                 pGVM->gmm.s.enmPriority = enmPriority;
    1497                 pGVM->gmm.s.fMayAllocate = true;
     1494                pGVM->gmm.s.Stats.Reserved.cBasePages  = cBasePages;
     1495                pGVM->gmm.s.Stats.Reserved.cFixedPages = cFixedPages;
     1496                pGVM->gmm.s.Stats.Reserved.cShadowPages = cShadowPages;
     1497                pGVM->gmm.s.Stats.enmPolicy            = enmPolicy;
     1498                pGVM->gmm.s.Stats.enmPriority          = enmPriority;
     1499                pGVM->gmm.s.Stats.fMayAllocate          = true;
    14981500
    14991501                pGMM->cReservedPages += cBasePages + cFixedPages + cShadowPages;
     
    15721574    if (GMM_CHECK_SANITY_UPON_ENTERING(pGMM))
    15731575    {
    1574         if (    pGVM->gmm.s.Reserved.cBasePages
    1575             &&  pGVM->gmm.s.Reserved.cFixedPages
    1576             &&  pGVM->gmm.s.Reserved.cShadowPages)
     1576        if (    pGVM->gmm.s.Stats.Reserved.cBasePages
     1577            &&  pGVM->gmm.s.Stats.Reserved.cFixedPages
     1578            &&  pGVM->gmm.s.Stats.Reserved.cShadowPages)
    15771579        {
    15781580            /*
     
    15851587                 * Update the records.
    15861588                 */
    1587                 pGMM->cReservedPages -= pGVM->gmm.s.Reserved.cBasePages
    1588                                       + pGVM->gmm.s.Reserved.cFixedPages
    1589                                       + pGVM->gmm.s.Reserved.cShadowPages;
     1589                pGMM->cReservedPages -= pGVM->gmm.s.Stats.Reserved.cBasePages
     1590                                      + pGVM->gmm.s.Stats.Reserved.cFixedPages
     1591                                      + pGVM->gmm.s.Stats.Reserved.cShadowPages;
    15901592                pGMM->cReservedPages += cBasePages + cFixedPages + cShadowPages;
    15911593
    1592                 pGVM->gmm.s.Reserved.cBasePages = cBasePages;
    1593                 pGVM->gmm.s.Reserved.cFixedPages = cFixedPages;
    1594                 pGVM->gmm.s.Reserved.cShadowPages = cShadowPages;
     1594                pGVM->gmm.s.Stats.Reserved.cBasePages  = cBasePages;
     1595                pGVM->gmm.s.Stats.Reserved.cFixedPages = cFixedPages;
     1596                pGVM->gmm.s.Stats.Reserved.cShadowPages = cShadowPages;
    15951597            }
    15961598        }
     
    23392341     * Don't allocate a new chunk if we're
    23402342     */
    2341     uint64_t cPgReserved  = pGVM->gmm.s.Reserved.cBasePages
    2342                           + pGVM->gmm.s.Reserved.cFixedPages
    2343                           - pGVM->gmm.s.cBalloonedPages
     2343    uint64_t cPgReserved  = pGVM->gmm.s.Stats.Reserved.cBasePages
     2344                          + pGVM->gmm.s.Stats.Reserved.cFixedPages
     2345                          - pGVM->gmm.s.Stats.cBalloonedPages
    23442346                          /** @todo what about shared pages? */;
    2345     uint64_t cPgAllocated = pGVM->gmm.s.Allocated.cBasePages
    2346                           + pGVM->gmm.s.Allocated.cFixedPages;
     2347    uint64_t cPgAllocated = pGVM->gmm.s.Stats.Allocated.cBasePages
     2348                          + pGVM->gmm.s.Stats.Allocated.cFixedPages;
    23472349    uint64_t cPgDelta = cPgReserved - cPgAllocated;
    23482350    if (cPgDelta < GMM_CHUNK_NUM_PAGES * 4)
     
    23942396    {
    23952397        case GMMACCOUNT_BASE:
    2396             if (RT_UNLIKELY(  pGVM->gmm.s.Allocated.cBasePages + pGVM->gmm.s.cBalloonedPages + cPages
    2397                             > pGVM->gmm.s.Reserved.cBasePages))
     2398            if (RT_UNLIKELY(  pGVM->gmm.s.Stats.Allocated.cBasePages + pGVM->gmm.s.Stats.cBalloonedPages + cPages
     2399                            > pGVM->gmm.s.Stats.Reserved.cBasePages))
    23982400            {
    23992401                Log(("gmmR0AllocatePages:Base: Reserved=%#llx Allocated+Ballooned+Requested=%#llx+%#llx+%#x!\n",
    2400                      pGVM->gmm.s.Reserved.cBasePages, pGVM->gmm.s.Allocated.cBasePages, pGVM->gmm.s.cBalloonedPages, cPages));
     2402                     pGVM->gmm.s.Stats.Reserved.cBasePages, pGVM->gmm.s.Stats.Allocated.cBasePages,
     2403                     pGVM->gmm.s.Stats.cBalloonedPages, cPages));
    24012404                return VERR_GMM_HIT_VM_ACCOUNT_LIMIT;
    24022405            }
    24032406            break;
    24042407        case GMMACCOUNT_SHADOW:
    2405             if (RT_UNLIKELY(pGVM->gmm.s.Allocated.cShadowPages + cPages > pGVM->gmm.s.Reserved.cShadowPages))
     2408            if (RT_UNLIKELY(pGVM->gmm.s.Stats.Allocated.cShadowPages + cPages > pGVM->gmm.s.Stats.Reserved.cShadowPages))
    24062409            {
    24072410                Log(("gmmR0AllocatePages:Shadow: Reserved=%#x Allocated+Requested=%#x+%#x!\n",
    2408                      pGVM->gmm.s.Reserved.cShadowPages, pGVM->gmm.s.Allocated.cShadowPages, cPages));
     2411                     pGVM->gmm.s.Stats.Reserved.cShadowPages, pGVM->gmm.s.Stats.Allocated.cShadowPages, cPages));
    24092412                return VERR_GMM_HIT_VM_ACCOUNT_LIMIT;
    24102413            }
    24112414            break;
    24122415        case GMMACCOUNT_FIXED:
    2413             if (RT_UNLIKELY(pGVM->gmm.s.Allocated.cFixedPages + cPages > pGVM->gmm.s.Reserved.cFixedPages))
     2416            if (RT_UNLIKELY(pGVM->gmm.s.Stats.Allocated.cFixedPages + cPages > pGVM->gmm.s.Stats.Reserved.cFixedPages))
    24142417            {
    24152418                Log(("gmmR0AllocatePages:Fixed: Reserved=%#x Allocated+Requested=%#x+%#x!\n",
    2416                      pGVM->gmm.s.Reserved.cFixedPages, pGVM->gmm.s.Allocated.cFixedPages, cPages));
     2419                     pGVM->gmm.s.Stats.Reserved.cFixedPages, pGVM->gmm.s.Stats.Allocated.cFixedPages, cPages));
    24172420                return VERR_GMM_HIT_VM_ACCOUNT_LIMIT;
    24182421            }
     
    24402443    switch (enmAccount)
    24412444    {
    2442         case GMMACCOUNT_BASE:   pGVM->gmm.s.Allocated.cBasePages   += cPages; break;
    2443         case GMMACCOUNT_SHADOW: pGVM->gmm.s.Allocated.cShadowPages += cPages; break;
    2444         case GMMACCOUNT_FIXED:  pGVM->gmm.s.Allocated.cFixedPages  += cPages; break;
     2445        case GMMACCOUNT_BASE:   pGVM->gmm.s.Stats.Allocated.cBasePages   += cPages; break;
     2446        case GMMACCOUNT_SHADOW: pGVM->gmm.s.Stats.Allocated.cShadowPages += cPages; break;
     2447        case GMMACCOUNT_FIXED:  pGVM->gmm.s.Stats.Allocated.cFixedPages  += cPages; break;
    24452448        default:                AssertMsgFailedReturn(("enmAccount=%d\n", enmAccount), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
    24462449    }
    2447     pGVM->gmm.s.cPrivatePages += cPages;
    2448     pGMM->cAllocatedPages     += cPages;
     2450    pGVM->gmm.s.Stats.cPrivatePages += cPages;
     2451    pGMM->cAllocatedPages           += cPages;
    24492452
    24502453    /*
     
    25252528    {
    25262529        /* Update the statistics. */
    2527         pGVM->gmm.s.cPrivatePages -= cPages;
    2528         pGMM->cAllocatedPages     -= cPages - iPage;
     2530        pGVM->gmm.s.Stats.cPrivatePages -= cPages;
     2531        pGMM->cAllocatedPages           -= cPages - iPage;
    25292532        switch (enmAccount)
    25302533        {
    2531             case GMMACCOUNT_BASE:   pGVM->gmm.s.Allocated.cBasePages   -= cPages; break;
    2532             case GMMACCOUNT_SHADOW: pGVM->gmm.s.Allocated.cShadowPages -= cPages; break;
    2533             case GMMACCOUNT_FIXED:  pGVM->gmm.s.Allocated.cFixedPages  -= cPages; break;
     2534            case GMMACCOUNT_BASE:   pGVM->gmm.s.Stats.Allocated.cBasePages   -= cPages; break;
     2535            case GMMACCOUNT_SHADOW: pGVM->gmm.s.Stats.Allocated.cShadowPages -= cPages; break;
     2536            case GMMACCOUNT_FIXED:  pGVM->gmm.s.Stats.Allocated.cFixedPages  -= cPages; break;
    25342537            default:                AssertMsgFailedReturn(("enmAccount=%d\n", enmAccount), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
    25352538        }
     
    26432646    {
    26442647        /* No allocations before the initial reservation has been made! */
    2645         if (RT_LIKELY(    pGVM->gmm.s.Reserved.cBasePages
    2646                       &&  pGVM->gmm.s.Reserved.cFixedPages
    2647                       &&  pGVM->gmm.s.Reserved.cShadowPages))
     2648        if (RT_LIKELY(    pGVM->gmm.s.Stats.Reserved.cBasePages
     2649                      &&  pGVM->gmm.s.Stats.Reserved.cFixedPages
     2650                      &&  pGVM->gmm.s.Stats.Reserved.cShadowPages))
    26482651        {
    26492652            /*
     
    27042707                            AssertCompile(NIL_RTHCPHYS > GMM_GCPHYS_LAST && GMM_GCPHYS_UNSHAREABLE > GMM_GCPHYS_LAST);
    27052708                            Assert(pPage->Shared.cRefs);
    2706                             Assert(pGVM->gmm.s.cSharedPages);
    2707                             Assert(pGVM->gmm.s.Allocated.cBasePages);
     2709                            Assert(pGVM->gmm.s.Stats.cSharedPages);
     2710                            Assert(pGVM->gmm.s.Stats.Allocated.cBasePages);
    27082711
    27092712                            Log(("GMMR0AllocateHandyPages: free shared page %x cRefs=%d\n", paPages[iPage].idSharedPage, pPage->Shared.cRefs));
    2710                             pGVM->gmm.s.cSharedPages--;
    2711                             pGVM->gmm.s.Allocated.cBasePages--;
     2713                            pGVM->gmm.s.Stats.cSharedPages--;
     2714                            pGVM->gmm.s.Stats.Allocated.cBasePages--;
    27122715                            if (!--pPage->Shared.cRefs)
    27132716                                gmmR0FreeSharedPage(pGMM, pGVM, paPages[iPage].idSharedPage, pPage);
     
    28252828
    28262829        /* No allocations before the initial reservation has been made! */
    2827         if (RT_LIKELY(    pGVM->gmm.s.Reserved.cBasePages
    2828                       &&  pGVM->gmm.s.Reserved.cFixedPages
    2829                       &&  pGVM->gmm.s.Reserved.cShadowPages))
     2830        if (RT_LIKELY(    pGVM->gmm.s.Stats.Reserved.cBasePages
     2831                      &&  pGVM->gmm.s.Stats.Reserved.cFixedPages
     2832                      &&  pGVM->gmm.s.Stats.Reserved.cShadowPages))
    28302833            rc = gmmR0AllocatePagesNew(pGMM, pGVM, cPages, paPages, enmAccount);
    28312834        else
     
    29132916    {
    29142917        const unsigned cPages = (GMM_CHUNK_SIZE >> PAGE_SHIFT);
    2915         if (RT_UNLIKELY(  pGVM->gmm.s.Allocated.cBasePages + pGVM->gmm.s.cBalloonedPages + cPages
    2916                         > pGVM->gmm.s.Reserved.cBasePages))
     2918        if (RT_UNLIKELY(  pGVM->gmm.s.Stats.Allocated.cBasePages + pGVM->gmm.s.Stats.cBalloonedPages + cPages
     2919                        > pGVM->gmm.s.Stats.Reserved.cBasePages))
    29172920        {
    29182921            Log(("GMMR0AllocateLargePage: Reserved=%#llx Allocated+Requested=%#llx+%#x!\n",
    2919                  pGVM->gmm.s.Reserved.cBasePages, pGVM->gmm.s.Allocated.cBasePages, cPages));
     2922                 pGVM->gmm.s.Stats.Reserved.cBasePages, pGVM->gmm.s.Stats.Allocated.cBasePages, cPages));
    29202923            gmmR0MutexRelease(pGMM);
    29212924            return VERR_GMM_HIT_VM_ACCOUNT_LIMIT;
     
    29592962
    29602963                /* Update accounting. */
    2961                 pGVM->gmm.s.Allocated.cBasePages += cPages;
    2962                 pGVM->gmm.s.cPrivatePages        += cPages;
    2963                 pGMM->cAllocatedPages            += cPages;
     2964                pGVM->gmm.s.Stats.Allocated.cBasePages += cPages;
     2965                pGVM->gmm.s.Stats.cPrivatePages        += cPages;
     2966                pGMM->cAllocatedPages                  += cPages;
    29642967
    29652968                gmmR0LinkChunk(pChunk, pSet);
     
    30123015        const unsigned cPages = (GMM_CHUNK_SIZE >> PAGE_SHIFT);
    30133016
    3014         if (RT_UNLIKELY(pGVM->gmm.s.Allocated.cBasePages < cPages))
    3015         {
    3016             Log(("GMMR0FreeLargePage: allocated=%#llx cPages=%#x!\n", pGVM->gmm.s.Allocated.cBasePages, cPages));
     3017        if (RT_UNLIKELY(pGVM->gmm.s.Stats.Allocated.cBasePages < cPages))
     3018        {
     3019            Log(("GMMR0FreeLargePage: allocated=%#llx cPages=%#x!\n", pGVM->gmm.s.Stats.Allocated.cBasePages, cPages));
    30173020            gmmR0MutexRelease(pGMM);
    30183021            return VERR_GMM_ATTEMPT_TO_FREE_TOO_MUCH;
     
    30323035
    30333036            /* Update accounting. */
    3034             pGVM->gmm.s.Allocated.cBasePages -= cPages;
    3035             pGVM->gmm.s.cPrivatePages        -= cPages;
    3036             pGMM->cAllocatedPages            -= cPages;
     3037            pGVM->gmm.s.Stats.Allocated.cBasePages -= cPages;
     3038            pGVM->gmm.s.Stats.cPrivatePages        -= cPages;
     3039            pGMM->cAllocatedPages                  -= cPages;
    30373040        }
    30383041        else
     
    32933296    {
    32943297        case GMMACCOUNT_BASE:
    3295             if (RT_UNLIKELY(pGVM->gmm.s.Allocated.cBasePages < cPages))
     3298            if (RT_UNLIKELY(pGVM->gmm.s.Stats.Allocated.cBasePages < cPages))
    32963299            {
    3297                 Log(("gmmR0FreePages: allocated=%#llx cPages=%#x!\n", pGVM->gmm.s.Allocated.cBasePages, cPages));
     3300                Log(("gmmR0FreePages: allocated=%#llx cPages=%#x!\n", pGVM->gmm.s.Stats.Allocated.cBasePages, cPages));
    32983301                return VERR_GMM_ATTEMPT_TO_FREE_TOO_MUCH;
    32993302            }
    33003303            break;
    33013304        case GMMACCOUNT_SHADOW:
    3302             if (RT_UNLIKELY(pGVM->gmm.s.Allocated.cShadowPages < cPages))
     3305            if (RT_UNLIKELY(pGVM->gmm.s.Stats.Allocated.cShadowPages < cPages))
    33033306            {
    3304                 Log(("gmmR0FreePages: allocated=%#llx cPages=%#x!\n", pGVM->gmm.s.Allocated.cShadowPages, cPages));
     3307                Log(("gmmR0FreePages: allocated=%#llx cPages=%#x!\n", pGVM->gmm.s.Stats.Allocated.cShadowPages, cPages));
    33053308                return VERR_GMM_ATTEMPT_TO_FREE_TOO_MUCH;
    33063309            }
    33073310            break;
    33083311        case GMMACCOUNT_FIXED:
    3309             if (RT_UNLIKELY(pGVM->gmm.s.Allocated.cFixedPages < cPages))
     3312            if (RT_UNLIKELY(pGVM->gmm.s.Stats.Allocated.cFixedPages < cPages))
    33103313            {
    3311                 Log(("gmmR0FreePages: allocated=%#llx cPages=%#x!\n", pGVM->gmm.s.Allocated.cFixedPages, cPages));
     3314                Log(("gmmR0FreePages: allocated=%#llx cPages=%#x!\n", pGVM->gmm.s.Stats.Allocated.cFixedPages, cPages));
    33123315                return VERR_GMM_ATTEMPT_TO_FREE_TOO_MUCH;
    33133316            }
     
    33353338                if (RT_LIKELY(pPage->Private.hGVM == pGVM->hSelf))
    33363339                {
    3337                     Assert(pGVM->gmm.s.cPrivatePages);
    3338                     pGVM->gmm.s.cPrivatePages--;
     3340                    Assert(pGVM->gmm.s.Stats.cPrivatePages);
     3341                    pGVM->gmm.s.Stats.cPrivatePages--;
    33393342                    gmmR0FreePrivatePage(pGMM, pGVM, idPage, pPage);
    33403343                }
     
    33493352            else if (RT_LIKELY(GMM_PAGE_IS_SHARED(pPage)))
    33503353            {
    3351                 Assert(pGVM->gmm.s.cSharedPages);
    3352                 pGVM->gmm.s.cSharedPages--;
     3354                Assert(pGVM->gmm.s.Stats.cSharedPages);
     3355                pGVM->gmm.s.Stats.cSharedPages--;
    33533356                Assert(pPage->Shared.cRefs);
    33543357                if (!--pPage->Shared.cRefs)
     
    33813384    switch (enmAccount)
    33823385    {
    3383         case GMMACCOUNT_BASE:   pGVM->gmm.s.Allocated.cBasePages   -= iPage; break;
    3384         case GMMACCOUNT_SHADOW: pGVM->gmm.s.Allocated.cShadowPages -= iPage; break;
    3385         case GMMACCOUNT_FIXED:  pGVM->gmm.s.Allocated.cFixedPages  -= iPage; break;
     3386        case GMMACCOUNT_BASE:   pGVM->gmm.s.Stats.Allocated.cBasePages   -= iPage; break;
     3387        case GMMACCOUNT_SHADOW: pGVM->gmm.s.Stats.Allocated.cShadowPages -= iPage; break;
     3388        case GMMACCOUNT_FIXED:  pGVM->gmm.s.Stats.Allocated.cFixedPages  -= iPage; break;
    33863389        default:
    33873390            AssertMsgFailedReturn(("enmAccount=%d\n", enmAccount), VERR_IPE_NOT_REACHED_DEFAULT_CASE);
     
    35273530            case GMMBALLOONACTION_INFLATE:
    35283531            {
    3529                 if (RT_LIKELY(pGVM->gmm.s.Allocated.cBasePages + pGVM->gmm.s.cBalloonedPages + cBalloonedPages <= pGVM->gmm.s.Reserved.cBasePages))
     3532                if (RT_LIKELY(pGVM->gmm.s.Stats.Allocated.cBasePages + pGVM->gmm.s.Stats.cBalloonedPages + cBalloonedPages
     3533                              <= pGVM->gmm.s.Stats.Reserved.cBasePages))
    35303534                {
    35313535                    /*
     
    35333537                     */
    35343538                    pGMM->cBalloonedPages += cBalloonedPages;
    3535                     if (pGVM->gmm.s.cReqBalloonedPages)
     3539                    if (pGVM->gmm.s.Stats.cReqBalloonedPages)
    35363540                    {
    35373541                        /* Codepath never taken. Might be interesting in the future to request ballooned memory from guests in low memory conditions.. */
    35383542                        AssertFailed();
    35393543
    3540                         pGVM->gmm.s.cBalloonedPages += cBalloonedPages;
    3541                         pGVM->gmm.s.cReqActuallyBalloonedPages += cBalloonedPages;
    3542                         Log(("GMMR0BalloonedPages: +%#x - Global=%#llx / VM: Total=%#llx Req=%#llx Actual=%#llx (pending)\n", cBalloonedPages,
    3543                              pGMM->cBalloonedPages, pGVM->gmm.s.cBalloonedPages, pGVM->gmm.s.cReqBalloonedPages, pGVM->gmm.s.cReqActuallyBalloonedPages));
     3544                        pGVM->gmm.s.Stats.cBalloonedPages            += cBalloonedPages;
     3545                        pGVM->gmm.s.Stats.cReqActuallyBalloonedPages += cBalloonedPages;
     3546                        Log(("GMMR0BalloonedPages: +%#x - Global=%#llx / VM: Total=%#llx Req=%#llx Actual=%#llx (pending)\n",
     3547                             cBalloonedPages, pGMM->cBalloonedPages, pGVM->gmm.s.Stats.cBalloonedPages,
     3548                             pGVM->gmm.s.Stats.cReqBalloonedPages, pGVM->gmm.s.Stats.cReqActuallyBalloonedPages));
    35443549                    }
    35453550                    else
    35463551                    {
    3547                         pGVM->gmm.s.cBalloonedPages += cBalloonedPages;
     3552                        pGVM->gmm.s.Stats.cBalloonedPages += cBalloonedPages;
    35483553                        Log(("GMMR0BalloonedPages: +%#x - Global=%#llx / VM: Total=%#llx (user)\n",
    3549                              cBalloonedPages, pGMM->cBalloonedPages, pGVM->gmm.s.cBalloonedPages));
     3554                             cBalloonedPages, pGMM->cBalloonedPages, pGVM->gmm.s.Stats.cBalloonedPages));
    35503555                    }
    35513556                }
     
    35533558                {
    35543559                    Log(("GMMR0BalloonedPages: cBasePages=%#llx Total=%#llx cBalloonedPages=%#llx Reserved=%#llx\n",
    3555                          pGVM->gmm.s.Allocated.cBasePages, pGVM->gmm.s.cBalloonedPages, cBalloonedPages, pGVM->gmm.s.Reserved.cBasePages));
     3560                         pGVM->gmm.s.Stats.Allocated.cBasePages, pGVM->gmm.s.Stats.cBalloonedPages, cBalloonedPages,
     3561                         pGVM->gmm.s.Stats.Reserved.cBasePages));
    35563562                    rc = VERR_GMM_ATTEMPT_TO_FREE_TOO_MUCH;
    35573563                }
     
    35623568            {
    35633569                /* Deflate. */
    3564                 if (pGVM->gmm.s.cBalloonedPages >= cBalloonedPages)
     3570                if (pGVM->gmm.s.Stats.cBalloonedPages >= cBalloonedPages)
    35653571                {
    35663572                    /*
     
    35683574                     */
    35693575                    Assert(pGMM->cBalloonedPages >= cBalloonedPages);
    3570                     pGMM->cBalloonedPages       -= cBalloonedPages;
    3571                     pGVM->gmm.s.cBalloonedPages -= cBalloonedPages;
    3572                     if (pGVM->gmm.s.cReqDeflatePages)
     3576                    pGMM->cBalloonedPages             -= cBalloonedPages;
     3577                    pGVM->gmm.s.Stats.cBalloonedPages -= cBalloonedPages;
     3578                    if (pGVM->gmm.s.Stats.cReqDeflatePages)
    35733579                    {
    35743580                        AssertFailed(); /* This is path is for later. */
    35753581                        Log(("GMMR0BalloonedPages: -%#x - Global=%#llx / VM: Total=%#llx Req=%#llx\n",
    3576                              cBalloonedPages, pGMM->cBalloonedPages, pGVM->gmm.s.cBalloonedPages, pGVM->gmm.s.cReqDeflatePages));
     3582                             cBalloonedPages, pGMM->cBalloonedPages, pGVM->gmm.s.Stats.cBalloonedPages, pGVM->gmm.s.Stats.cReqDeflatePages));
    35773583
    35783584                        /*
    35793585                         * Anything we need to do here now when the request has been completed?
    35803586                         */
    3581                         pGVM->gmm.s.cReqDeflatePages = 0;
     3587                        pGVM->gmm.s.Stats.cReqDeflatePages = 0;
    35823588                    }
    35833589                    else
    35843590                        Log(("GMMR0BalloonedPages: -%#x - Global=%#llx / VM: Total=%#llx (user)\n",
    3585                              cBalloonedPages, pGMM->cBalloonedPages, pGVM->gmm.s.cBalloonedPages));
     3591                             cBalloonedPages, pGMM->cBalloonedPages, pGVM->gmm.s.Stats.cBalloonedPages));
    35863592                }
    35873593                else
    35883594                {
    3589                     Log(("GMMR0BalloonedPages: Total=%#llx cBalloonedPages=%#llx\n", pGVM->gmm.s.cBalloonedPages, cBalloonedPages));
     3595                    Log(("GMMR0BalloonedPages: Total=%#llx cBalloonedPages=%#llx\n", pGVM->gmm.s.Stats.cBalloonedPages, cBalloonedPages));
    35903596                    rc = VERR_GMM_ATTEMPT_TO_DEFLATE_TOO_MUCH;
    35913597                }
     
    35963602            {
    35973603                /* Reset to an empty balloon. */
    3598                 Assert(pGMM->cBalloonedPages >= pGVM->gmm.s.cBalloonedPages);
    3599 
    3600                 pGMM->cBalloonedPages       -= pGVM->gmm.s.cBalloonedPages;
    3601                 pGVM->gmm.s.cBalloonedPages  = 0;
     3604                Assert(pGMM->cBalloonedPages >= pGVM->gmm.s.Stats.cBalloonedPages);
     3605
     3606                pGMM->cBalloonedPages             -= pGVM->gmm.s.Stats.cBalloonedPages;
     3607                pGVM->gmm.s.Stats.cBalloonedPages  = 0;
    36023608                break;
    36033609            }
     
    37083714    if (GMM_CHECK_SANITY_UPON_ENTERING(pGMM))
    37093715    {
    3710         pReq->cAllocPages     = pGVM->gmm.s.Allocated.cBasePages;
    3711         pReq->cBalloonedPages = pGVM->gmm.s.cBalloonedPages;
    3712         pReq->cMaxPages       = pGVM->gmm.s.Reserved.cBasePages;
     3716        pReq->cAllocPages     = pGVM->gmm.s.Stats.Allocated.cBasePages;
     3717        pReq->cBalloonedPages = pGVM->gmm.s.Stats.cBalloonedPages;
     3718        pReq->cMaxPages       = pGVM->gmm.s.Stats.Reserved.cBasePages;
    37133719        pReq->cFreePages      = pReq->cMaxPages - pReq->cAllocPages;
    37143720    }
     
    42914297            bool fInsert = RTAvlGCPtrInsert(&pGMM->pGlobalSharedModuleTree, &pGlobalModule->Core);
    42924298            Assert(fInsert); NOREF(fInsert);
     4299            pGMM->cShareableModules++;
    42934300
    42944301            Log(("GMMR0RegisterSharedModule: new global module %s\n", pszModuleName));
     
    44284435                        /* Remove from the tree and free memory. */
    44294436                        RTAvlGCPtrRemove(&pGMM->pGlobalSharedModuleTree, pRec->Core.Key);
     4437                        pGMM->cShareableModules--;
    44304438                        RTMemFree(pRec);
    44314439                    }
     
    44964504
    44974505    pPage->Shared.cRefs++;
    4498     pGVM->gmm.s.cSharedPages++;
    4499     pGVM->gmm.s.Allocated.cBasePages++;
     4506    pGVM->gmm.s.Stats.cSharedPages++;
     4507    pGVM->gmm.s.Stats.Allocated.cBasePages++;
    45004508}
    45014509
     
    45224530    pGMM->cSharedPages++;
    45234531
    4524     pGVM->gmm.s.cSharedPages++;
    4525     pGVM->gmm.s.cPrivatePages--;
     4532    pGVM->gmm.s.Stats.cSharedPages++;
     4533    pGVM->gmm.s.Stats.cPrivatePages--;
    45264534
    45274535    /* Modify the page structure. */
     
    47334741            GMM_GET_VALID_INSTANCE(pGMM, VERR_GMM_INSTANCE);
    47344742            RTAvlGCPtrRemove(&pGMM->pGlobalSharedModuleTree, pRec->Core.Key);
     4743            pGMM->cShareableModules--;
    47354744            RTMemFree(pRec);
    47364745        }
     
    50655074#endif /* VBOX_STRICT && HC_ARCH_BITS == 64 */
    50665075
     5076
     5077/**
     5078 * Retrieves the GMM statistics visible to the caller.
     5079 *
     5080 * @returns VBox status code.
     5081 *
     5082 * @param   pStats      Where to put the statistics.
     5083 * @param   pSession    The current session.
     5084 * @param   pVM         The VM to obtain statistics for. Optional.
     5085 */
     5086GMMR0DECL(int) GMMR0QueryStatistics(PGMMSTATS pStats, PSUPDRVSESSION pSession, PVM pVM)
     5087{
     5088    LogFlow(("GVMMR0QueryStatistics: pStats=%p pSession=%p pVM=%p\n", pStats, pSession, pVM));
     5089
     5090    /*
     5091     * Validate input.
     5092     */
     5093    AssertPtrReturn(pSession, VERR_INVALID_POINTER);
     5094    AssertPtrReturn(pStats, VERR_INVALID_POINTER);
     5095    pStats->cMaxPages = 0; /* (crash before taking the mutex...) */
     5096
     5097    PGMM pGMM;
     5098    GMM_GET_VALID_INSTANCE(pGMM, VERR_GMM_INSTANCE);
     5099
     5100    /*
     5101     * Resolve the VM handle, if not NULL, and lock the GMM.
     5102     */
     5103    int rc;
     5104    PGVM pGVM;
     5105    if (pVM)
     5106    {
     5107        rc = GVMMR0ByVM(pVM, &pGVM);
     5108        if (RT_FAILURE(rc))
     5109            return rc;
     5110    }
     5111    else
     5112        pGVM = NULL;
     5113
     5114    rc = gmmR0MutexAcquire(pGMM);
     5115    if (RT_FAILURE(rc))
     5116        return rc;
     5117
     5118    /*
     5119     * Copy out the GMM statistics.
     5120     */
     5121    pStats->cMaxPages                   = pGMM->cMaxPages;
     5122    pStats->cReservedPages              = pGMM->cReservedPages;
     5123    pStats->cOverCommittedPages         = pGMM->cOverCommittedPages;
     5124    pStats->cAllocatedPages             = pGMM->cAllocatedPages;
     5125    pStats->cSharedPages                = pGMM->cSharedPages;
     5126    pStats->cDuplicatePages             = pGMM->cDuplicatePages;
     5127    pStats->cLeftBehindSharedPages      = pGMM->cLeftBehindSharedPages;
     5128    pStats->cBalloonedPages             = pGMM->cBalloonedPages;
     5129    pStats->cChunks                     = pGMM->cChunks;
     5130    pStats->cFreedChunks                = pGMM->cFreedChunks;
     5131    pStats->cShareableModules           = pGMM->cShareableModules;
     5132    RT_ZERO(pStats->au64Reserved);
     5133
     5134    /*
     5135     * Copy out the VM statistics.
     5136     */
     5137    if (pGVM)
     5138        pStats->VMStats = pGVM->gmm.s.Stats;
     5139    else
     5140        RT_ZERO(pStats->VMStats);
     5141
     5142    gmmR0MutexRelease(pGMM);
     5143    return rc;
     5144}
     5145
     5146
     5147/**
     5148 * VMMR0 request wrapper for GMMR0QueryStatistics.
     5149 *
     5150 * @returns see GMMR0QueryStatistics.
     5151 * @param   pVM             Pointer to the shared VM structure. Optional.
     5152 * @param   pReq            The request packet.
     5153 */
     5154GMMR0DECL(int) GMMR0QueryStatisticsReq(PVM pVM, PGMMQUERYSTATISTICSSREQ pReq)
     5155{
     5156    /*
     5157     * Validate input and pass it on.
     5158     */
     5159    AssertPtrReturn(pReq, VERR_INVALID_POINTER);
     5160    AssertMsgReturn(pReq->Hdr.cbReq == sizeof(*pReq), ("%#x != %#x\n", pReq->Hdr.cbReq, sizeof(*pReq)), VERR_INVALID_PARAMETER);
     5161
     5162    return GMMR0QueryStatistics(&pReq->Stats, pReq->pSession, pVM);
     5163}
     5164
     5165
     5166/**
     5167 * Resets the specified GMM statistics.
     5168 *
     5169 * @returns VBox status code.
     5170 *
     5171 * @param   pStats      Which statistics to reset, that is, non-zero fields
     5172 *                      indicates which to reset.
     5173 * @param   pSession    The current session.
     5174 * @param   pVM         The VM to reset statistics for. Optional.
     5175 */
     5176GMMR0DECL(int) GMMR0ResetStatistics(PCGMMSTATS pStats, PSUPDRVSESSION pSession, PVM pVM)
     5177{
     5178    /* Currently nothing we can reset at the moment. */
     5179    return VINF_SUCCESS;
     5180}
     5181
     5182
     5183/**
     5184 * VMMR0 request wrapper for GMMR0ResetStatistics.
     5185 *
     5186 * @returns see GMMR0ResetStatistics.
     5187 * @param   pVM             Pointer to the shared VM structure. Optional.
     5188 * @param   pReq            The request packet.
     5189 */
     5190GMMR0DECL(int) GMMR0ResetStatisticsReq(PVM pVM, PGMMRESETSTATISTICSSREQ pReq)
     5191{
     5192    /*
     5193     * Validate input and pass it on.
     5194     */
     5195    AssertPtrReturn(pReq, VERR_INVALID_POINTER);
     5196    AssertMsgReturn(pReq->Hdr.cbReq == sizeof(*pReq), ("%#x != %#x\n", pReq->Hdr.cbReq, sizeof(*pReq)), VERR_INVALID_PARAMETER);
     5197
     5198    return GMMR0ResetStatistics(&pReq->Stats, pReq->pSession, pVM);
     5199}
     5200
  • trunk/src/VBox/VMM/VMMR0/GMMR0Internal.h

    r37248 r39917  
    2121#include <VBox/vmm/gmm.h>
    2222#include <iprt/avl.h>
    23 
    24 /**
    25  * The allocation sizes.
    26  */
    27 typedef struct GMMVMSIZES
    28 {
    29     /** The number of pages of base memory.
    30      * This is the sum of RAM, ROMs and handy pages. */
    31     uint64_t        cBasePages;
    32     /** The number of pages for the shadow pool. (Can be squeezed for memory.) */
    33     uint32_t        cShadowPages;
    34     /** The number of pages for fixed allocations like MMIO2 and the hyper heap. */
    35     uint32_t        cFixedPages;
    36 } GMMVMSIZES;
    37 /** Pointer to a GMMVMSIZES. */
    38 typedef GMMVMSIZES *PGMMVMSIZES;
    3923
    4024
     
    9983    /** Free set for use in bound mode. */
    10084    GMMCHUNKFREESET     Private;
    101 
    102     /** The reservations. */
    103     GMMVMSIZES          Reserved;
    104     /** The actual allocations.
    105      * This includes both private and shared page allocations. */
    106     GMMVMSIZES          Allocated;
    107 
    108     /** The current number of private pages. */
    109     uint64_t            cPrivatePages;
    110     /** The current number of shared pages. */
    111     uint64_t            cSharedPages;
    112     /** The current over-commitment policy. */
    113     GMMOCPOLICY         enmPolicy;
    114     /** The VM priority for arbitrating VMs in low and out of memory situation.
    115      * Like which VMs to start squeezing first. */
    116     GMMPRIORITY         enmPriority;
     85    /** The VM statistics. */
     86    GMMVMSTATS          Stats;
     87    /** Shared module tree (per-vm). */
     88    PAVLGCPTRNODECORE   pSharedModuleTree;
    11789    /** Hints at the last chunk we allocated some memory from. */
    11890    uint32_t            idLastChunkHint;
    119 
    120     /** The current number of ballooned pages. */
    121     uint64_t            cBalloonedPages;
    122     /** The max number of pages that can be ballooned. */
    123     uint64_t            cMaxBalloonedPages;
    124     /** The number of pages we've currently requested the guest to give us.
    125      * This is 0 if no pages currently requested. */
    126     uint64_t            cReqBalloonedPages;
    127     /** The number of pages the guest has given us in response to the request.
    128      * This is not reset on request completed and may be used in later decisions. */
    129     uint64_t            cReqActuallyBalloonedPages;
    130     /** The number of pages we've currently requested the guest to take back. */
    131     uint64_t            cReqDeflatePages;
    132 
    133     /** Shared module tree (per-vm). */
    134     PAVLGCPTRNODECORE   pSharedModuleTree;
    135 
    136     /** Whether ballooning is enabled or not. */
    137     bool                fBallooningEnabled;
    138 
    139     /** Whether shared paging is enabled or not. */
    140     bool                fSharedPagingEnabled;
    141 
    142     /** Whether the VM is allowed to allocate memory or not.
    143      * This is used when the reservation update request fails or when the VM has
    144      * been told to suspend/save/die in an out-of-memory case. */
    145     bool                fMayAllocate;
    14691} GMMPERVM;
    14792/** Pointer to the per-VM GMM data. */
  • trunk/src/VBox/VMM/VMMR0/VMMR0.cpp

    r39303 r39917  
    10991099#if defined(VBOX_STRICT) && HC_ARCH_BITS == 64
    11001100        case VMMR0_DO_GMM_FIND_DUPLICATE_PAGE:
    1101         {
    11021101            if (u64Arg)
    11031102                return VERR_INVALID_PARAMETER;
    11041103            return GMMR0FindDuplicatePageReq(pVM, (PGMMFINDDUPLICATEPAGEREQ)pReqHdr);
    1105         }
    1106 #endif
     1104#endif
     1105
     1106        case VMMR0_DO_GMM_QUERY_STATISTICS:
     1107            if (u64Arg)
     1108                return VERR_INVALID_PARAMETER;
     1109            return GMMR0QueryStatisticsReq(pVM, (PGMMQUERYSTATISTICSSREQ)pReqHdr);
     1110
     1111        case VMMR0_DO_GMM_RESET_STATISTICS:
     1112            if (u64Arg)
     1113                return VERR_INVALID_PARAMETER;
     1114            return GMMR0ResetStatisticsReq(pVM, (PGMMRESETSTATISTICSSREQ)pReqHdr);
    11071115
    11081116        /*
  • trunk/src/VBox/VMM/VMMR3/STAM.cpp

    r39078 r39917  
    218218
    219219/**
     220 * The GMM mapping records.
     221 */
     222static const STAMR0SAMPLE g_aGMMStats[] =
     223{
     224    { RT_UOFFSETOF(GMMSTATS, cMaxPages),                        STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/cMaxPages",                   "The maximum number of pages GMM is allowed to allocate." },
     225    { RT_UOFFSETOF(GMMSTATS, cReservedPages),                   STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/cReservedPages",              "The number of pages that has been reserved." },
     226    { RT_UOFFSETOF(GMMSTATS, cOverCommittedPages),              STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/cOverCommittedPages",         "The number of pages that we have over-committed in reservations." },
     227    { RT_UOFFSETOF(GMMSTATS, cAllocatedPages),                  STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/cAllocatedPages",             "The number of actually allocated (committed if you like) pages." },
     228    { RT_UOFFSETOF(GMMSTATS, cSharedPages),                     STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/cSharedPages",                "The number of pages that are shared. A subset of cAllocatedPages." },
     229    { RT_UOFFSETOF(GMMSTATS, cDuplicatePages),                  STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/cDuplicatePages",             "The number of pages that are actually shared between VMs." },
     230    { RT_UOFFSETOF(GMMSTATS, cLeftBehindSharedPages),           STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/cLeftBehindSharedPages",      "The number of pages that are shared that has been left behind by VMs not doing proper cleanups." },
     231    { RT_UOFFSETOF(GMMSTATS, cBalloonedPages),                  STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/cBalloonedPages",             "The number of current ballooned pages." },
     232    { RT_UOFFSETOF(GMMSTATS, cChunks),                          STAMTYPE_U32,   STAMUNIT_PAGES, "/GMM/cChunks",                     "The number of allocation chunks." },
     233    { RT_UOFFSETOF(GMMSTATS, cFreedChunks),                     STAMTYPE_U32,   STAMUNIT_PAGES, "/GMM/cFreedChunks",                "The number of freed chunks ever." },
     234    { RT_UOFFSETOF(GMMSTATS, cShareableModules),                STAMTYPE_U32,   STAMUNIT_PAGES, "/GMM/cShareableModules",           "The number of shareable modules." },
     235    { RT_UOFFSETOF(GMMSTATS, VMStats.Reserved.cBasePages),      STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/VM/Reserved/cBasePages",      "The amount of base memory (RAM, ROM, ++) reserved by the VM." },
     236    { RT_UOFFSETOF(GMMSTATS, VMStats.Reserved.cShadowPages),    STAMTYPE_U32,   STAMUNIT_PAGES, "/GMM/VM/Reserved/cShadowPages",    "The amount of memory reserved for shadow/nested page tables." },
     237    { RT_UOFFSETOF(GMMSTATS, VMStats.Reserved.cFixedPages),     STAMTYPE_U32,   STAMUNIT_PAGES, "/GMM/VM/Reserved/cFixedPages",     "The amount of memory reserved for fixed allocations like MMIO2 and the hyper heap." },
     238    { RT_UOFFSETOF(GMMSTATS, VMStats.Allocated.cBasePages),     STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/VM/Allocated/cBasePages",     "The amount of base memory (RAM, ROM, ++) allocated by the VM." },
     239    { RT_UOFFSETOF(GMMSTATS, VMStats.Allocated.cShadowPages),   STAMTYPE_U32,   STAMUNIT_PAGES, "/GMM/VM/Allocated/cShadowPages",   "The amount of memory allocated for shadow/nested page tables." },
     240    { RT_UOFFSETOF(GMMSTATS, VMStats.Allocated.cFixedPages),    STAMTYPE_U32,   STAMUNIT_PAGES, "/GMM/VM/Allocated/cFixedPages",    "The amount of memory allocated for fixed allocations like MMIO2 and the hyper heap." },
     241    { RT_UOFFSETOF(GMMSTATS, VMStats.cPrivatePages),            STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/VM/cPrivatePages",            "The current number of private pages." },
     242    { RT_UOFFSETOF(GMMSTATS, VMStats.cSharedPages),             STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/VM/cSharedPages",             "The current number of shared pages." },
     243    { RT_UOFFSETOF(GMMSTATS, VMStats.cBalloonedPages),          STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/VM/cBalloonedPages",          "The current number of ballooned pages." },
     244    { RT_UOFFSETOF(GMMSTATS, VMStats.cMaxBalloonedPages),       STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/VM/cMaxBalloonedPages",       "The max number of pages that can be ballooned." },
     245    { RT_UOFFSETOF(GMMSTATS, VMStats.cReqBalloonedPages),       STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/VM/cReqBalloonedPages",       "The number of pages we've currently requested the guest to give us." },
     246    { RT_UOFFSETOF(GMMSTATS, VMStats.cReqActuallyBalloonedPages),STAMTYPE_U64,  STAMUNIT_PAGES, "/GMM/VM/cReqActuallyBalloonedPages","The number of pages the guest has given us in response to the request." },
     247    { RT_UOFFSETOF(GMMSTATS, VMStats.cReqDeflatePages),         STAMTYPE_U64,   STAMUNIT_PAGES, "/GMM/VM/cReqDeflatePages",         "The number of pages we've currently requested the guest to take back." },
     248    { RT_UOFFSETOF(GMMSTATS, VMStats.enmPolicy),                STAMTYPE_U32,   STAMUNIT_NONE,  "/GMM/VM/enmPolicy",                "The current over-commit policy." },
     249    { RT_UOFFSETOF(GMMSTATS, VMStats.enmPriority),              STAMTYPE_U32,   STAMUNIT_NONE,  "/GMM/VM/enmPriority",              "The VM priority for arbitrating VMs in low and out of memory situation." },
     250    { RT_UOFFSETOF(GMMSTATS, VMStats.fBallooningEnabled),       STAMTYPE_BOOL,  STAMUNIT_NONE,  "/GMM/VM/fBallooningEnabled",       "Whether ballooning is enabled or not." },
     251    { RT_UOFFSETOF(GMMSTATS, VMStats.fBallooningEnabled),       STAMTYPE_BOOL,  STAMUNIT_NONE,  "/GMM/VM/fSharedPagingEnabled",     "Whether shared paging is enabled or not." },
     252    { RT_UOFFSETOF(GMMSTATS, VMStats.fBallooningEnabled),       STAMTYPE_BOOL,  STAMUNIT_NONE,  "/GMM/VM/fMayAllocate",             "Whether the VM is allowed to allocate memory or not." },
     253};
     254
     255
     256/**
    220257 * Initializes the STAM.
    221258 *
     
    636673        case STAMTYPE_X8:
    637674        case STAMTYPE_X8_RESET:
     675        case STAMTYPE_BOOL:
     676        case STAMTYPE_BOOL_RESET:
    638677        case STAMTYPE_CALLBACK:
    639678            break;
     
    765804    /* ring-0 */
    766805    GVMMRESETSTATISTICSSREQ GVMMReq;
    767     //GMMRESETSTATISTICSSREQ GMMReq;
     806    GMMRESETSTATISTICSSREQ GMMReq;
    768807    bool fGVMMMatched = !pszPat || !*pszPat;
    769     //bool fGMMMatched = fGVMMMatched;
     808    bool fGMMMatched = fGVMMMatched;
    770809    if (fGVMMMatched)
     810    {
    771811        memset(&GVMMReq.Stats, 0xff, sizeof(GVMMReq.Stats));
     812        memset(&GMMReq.Stats,  0xff, sizeof(GMMReq.Stats));
     813    }
    772814    else
    773815    {
     
    779821
    780822        /* GVMM */
    781         memset(&GVMMReq.Stats, 0, sizeof(GVMMReq.Stats));
     823        RT_ZERO(GVMMReq.Stats);
    782824        for (unsigned i = 0; i < RT_ELEMENTS(g_aGVMMStats); i++)
    783825            if (stamR3MultiMatch(papszExpressions, cExpressions, NULL, g_aGVMMStats[i].pszName))
     
    792834
    793835        /* GMM */
    794 //        memset(&GMMReq.Stats, 0, sizeof(GMMReq.Stats));
    795 //        for (unsigned i = 0; i < RT_ELEMENTS(g_aGMMStats); i++)
    796 //            if (stamR3MultiMatch(papszExpressions, cExpressions, NULL, g_aGMMStats[i].pszName))
    797 //            {
    798 //                 *((uint8_t *)&GMMReq.Stats + g_aGMMStats[i].offVar) = 0xff;
    799 //                 fGMMMatched = true;
    800 //            }
     836        RT_ZERO(GMMReq.Stats);
     837        for (unsigned i = 0; i < RT_ELEMENTS(g_aGMMStats); i++)
     838            if (stamR3MultiMatch(papszExpressions, cExpressions, NULL, g_aGMMStats[i].pszName))
     839            {
     840                 *((uint8_t *)&GMMReq.Stats + g_aGMMStats[i].offVar) = 0xff;
     841                 fGMMMatched = true;
     842            }
    801843
    802844        RTMemTmpFree(papszExpressions);
     
    805847
    806848    STAM_LOCK_WR(pUVM);
     849
    807850    if (fGVMMMatched)
    808851    {
    809852        PVM pVM = pUVM->pVM;
    810         GVMMReq.Hdr.cbReq = sizeof(GVMMReq);
     853        GVMMReq.Hdr.cbReq    = sizeof(GVMMReq);
    811854        GVMMReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
    812         GVMMReq.pSession = pVM->pSession;
     855        GVMMReq.pSession     = pVM->pSession;
    813856        rc = SUPR3CallVMMR0Ex(pVM->pVMR0, NIL_VMCPUID, VMMR0_DO_GVMM_RESET_STATISTICS, 0, &GVMMReq.Hdr);
    814857    }
    815858
    816 //    if (fGMMMatched)
    817 //    {
    818 //        PVM pVM = pUVM->pVM;
    819 //        GMMReq.Hdr.cbReq = sizeof(Req);
    820 //        GMMReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
    821 //        GMMReq.pSession = pVM->pSession;
    822 //        rc = SUPR3CallVMMR0Ex(pVM->pVMR0, VMMR0_DO_GMM_RESET_STATISTICS, 0, &Req.Hdr);
    823 //    }
     859    if (fGMMMatched)
     860    {
     861        PVM pVM = pUVM->pVM;
     862        GMMReq.Hdr.cbReq    = sizeof(GMMReq);
     863        GMMReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
     864        GMMReq.pSession    = pVM->pSession;
     865        rc = SUPR3CallVMMR0Ex(pVM->pVMR0, NIL_VMCPUID, VMMR0_DO_GMM_RESET_STATISTICS, 0, &GMMReq.Hdr);
     866    }
    824867
    825868    /* and the reset */
     
    829872    return rc;
    830873}
     874
    831875
    832876/**
     
    898942        case STAMTYPE_X64_RESET:
    899943            ASMAtomicXchgU64(pDesc->u.pu64, 0);
     944            break;
     945
     946        case STAMTYPE_BOOL_RESET:
     947            ASMAtomicXchgBool(pDesc->u.pf, false);
    900948            break;
    901949
     
    910958        case STAMTYPE_X64:
    911959        case STAMTYPE_RATIO_U32:
     960        case STAMTYPE_BOOL:
    912961            break;
    913962
     
    10921141                return VINF_SUCCESS;
    10931142            stamR3SnapshotPrintf(pThis, "<X64 val=\"%#llx\"", *pDesc->u.pu64);
     1143            break;
     1144
     1145        case STAMTYPE_BOOL:
     1146        case STAMTYPE_BOOL_RESET:
     1147            if (pDesc->enmVisibility == STAMVISIBILITY_USED && *pDesc->u.pf == false)
     1148                return VINF_SUCCESS;
     1149            stamR3SnapshotPrintf(pThis, "<BOOL val=\"%RTbool\"", *pDesc->u.pf);
    10941150            break;
    10951151
     
    15121568            break;
    15131569
     1570        case STAMTYPE_BOOL:
     1571        case STAMTYPE_BOOL_RESET:
     1572            if (pDesc->enmVisibility == STAMVISIBILITY_USED && *pDesc->u.pf == false)
     1573                return VINF_SUCCESS;
     1574            pArgs->pfnPrintf(pArgs, "%-32s %s %s\n", pDesc->pszName, *pDesc->u.pf ? "true    " : "false   ", STAMR3GetUnit(pDesc->enmUnit));
     1575            break;
     1576
    15141577        default:
    15151578            AssertMsgFailed(("enmType=%d\n", pDesc->enmType));
     
    17791842                        g_aGVMMStats[i].enmUnit, g_aGVMMStats[i].pszDesc);
    17801843    pUVM->stam.s.cRegisteredHostCpus = 0;
     1844
     1845    /* GMM */
     1846    for (unsigned i = 0; i < RT_ELEMENTS(g_aGMMStats); i++)
     1847        stamR3RegisterU(pUVM, (uint8_t *)&pUVM->stam.s.GMMStats + g_aGMMStats[i].offVar, NULL, NULL,
     1848                        g_aGMMStats[i].enmType, STAMVISIBILITY_ALWAYS, g_aGMMStats[i].pszName,
     1849                        g_aGMMStats[i].enmUnit, g_aGMMStats[i].pszDesc);
    17811850}
    17821851
     
    18091878        return;
    18101879
    1811     /* GVMM */
     1880    /*
     1881     * GVMM
     1882     */
    18121883    bool fUpdate = false;
    18131884    for (unsigned i = 0; i < RT_ELEMENTS(g_aGVMMStats); i++)
     
    18701941        }
    18711942    }
     1943
     1944    /*
     1945     * GMM
     1946     */
     1947    fUpdate = false;
     1948    for (unsigned i = 0; i < RT_ELEMENTS(g_aGMMStats); i++)
     1949        if (stamR3MultiMatch(papszExpressions, cExpressions, NULL, g_aGMMStats[i].pszName))
     1950        {
     1951            fUpdate = true;
     1952            break;
     1953        }
     1954    if (fUpdate)
     1955    {
     1956        GMMQUERYSTATISTICSSREQ Req;
     1957        Req.Hdr.cbReq    = sizeof(Req);
     1958        Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
     1959        Req.pSession     = pVM->pSession;
     1960        int rc = SUPR3CallVMMR0Ex(pVM->pVMR0, NIL_VMCPUID, VMMR0_DO_GMM_QUERY_STATISTICS, 0, &Req.Hdr);
     1961        if (RT_SUCCESS(rc))
     1962            pUVM->stam.s.GMMStats = Req.Stats;
     1963    }
    18721964}
    18731965
  • trunk/src/VBox/VMM/include/STAMInternal.h

    r35346 r39917  
    2323#include <VBox/vmm/stam.h>
    2424#include <VBox/vmm/gvmm.h>
     25#include <VBox/vmm/gmm.h>
    2526#include <iprt/semaphore.h>
    2627
     
    6970        /** Simple void pointer. */
    7071        void           *pv;
     72        /** Boolean. */
     73        bool           *pf;
    7174        /** */
    7275        struct STAMDESCSAMPLEDATACALLBACKS
     
    105108    /** The number of registered host CPU leaves. */
    106109    uint32_t                cRegisteredHostCpus;
     110
     111    /** The copy of the GMM statistics. */
     112    GMMSTATS                GMMStats;
    107113} STAMUSERPERVM;
    108114/** Pointer to the STAM data kept in the UVM. */
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