VirtualBox

Changeset 39917 in vbox for trunk/src/VBox/VMM/VMMR3


Ignore:
Timestamp:
Jan 31, 2012 2:04:52 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
75992
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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
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