VirtualBox

Changeset 101096 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Sep 12, 2023 10:59:30 PM (17 months ago)
Author:
vboxsync
Message:

VMM/IEM: Fixed a bug in the TB allocator pruning code and another one wrt initial chunk allocations. bugref:10369

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAllThrdRecompiler.cpp

    r101091 r101096  
    788788        pTbAllocator->cTotalTbs       += cTbsPerChunk;
    789789
    790         if (idxChunk * cTbsPerChunk >= cInitialTbs)
     790        if ((idxChunk + 1) * cTbsPerChunk >= cInitialTbs)
    791791            break;
    792792    }
     
    10031003    STAM_PROFILE_START(&pTbAllocator->StatPrune, a);
    10041004    uint32_t const msNow          = pVCpu->iem.s.msRecompilerPollNow;
     1005    uint32_t const cTbsToPrune    = 128;
     1006    uint32_t const cTbsPerGroup   = 4;
    10051007    uint32_t       cFreedTbs      = 0;
    10061008#ifdef IEMTB_SIZE_IS_POWER_OF_TWO
    1007     uint32_t       idxTbPruneFrom = pTbAllocator->iPruneFrom & ~(uint32_t)3;
     1009    uint32_t       idxTbPruneFrom = pTbAllocator->iPruneFrom & ~(uint32_t)(cTbsToPrune - 1); /* Stay within a chunk! */
    10081010#else
    10091011    uint32_t       idxTbPruneFrom = pTbAllocator->iPruneFrom;
    10101012#endif
    1011     if (idxTbPruneFrom > pTbAllocator->cMaxTbs)
     1013    if (idxTbPruneFrom >= pTbAllocator->cMaxTbs)
    10121014        idxTbPruneFrom = 0;
    1013     for (uint32_t i = 0; i < 128; i += 4, idxTbPruneFrom += 4)
     1015    for (uint32_t i = 0; i < cTbsToPrune; i += cTbsPerGroup, idxTbPruneFrom += cTbsPerGroup)
    10141016    {
    10151017        uint32_t idxChunk   = IEMTBALLOC_IDX_TO_CHUNK(pTbAllocator, idxTbPruneFrom);
     
    10171019        PIEMTB   pTb        = &pTbAllocator->aChunks[idxChunk].paTbs[idxInChunk];
    10181020        uint32_t cMsAge     = msNow - pTb->msLastUsed;
    1019         for (uint32_t j = 1, idxChunk2 = idxChunk, idxInChunk2 = idxInChunk + 1; j < 4; j++, idxInChunk2++)
     1021        for (uint32_t j = 1, idxChunk2 = idxChunk, idxInChunk2 = idxInChunk + 1; j < cTbsPerGroup; j++, idxInChunk2++)
    10201022        {
    10211023#ifndef IEMTB_SIZE_IS_POWER_OF_TWO
  • trunk/src/VBox/VMM/VMMR3/IEMR3.cpp

    r101088 r101096  
    116116
    117117#ifdef VBOX_WITH_IEM_RECOMPILER
    118     /** @cfgm{/IEM/InitialTbCount, uint32_t, 32768}
    119      * Initial (minimum) number of TBs per EMT in ring-3. */
    120     uint32_t cInitialTbs = 0;
    121     rc = CFGMR3QueryU32Def(pIem, "InitialTbCount", &cInitialTbs, _32K);
    122     AssertLogRelRCReturn(rc, rc);
    123     if (cInitialTbs < _16K || cInitialTbs > _8M)
    124         return VMSetError(pVM, VERR_OUT_OF_RANGE, RT_SRC_POS,
    125                           "InitialTbCount value %u (%#x) is out of range (min %u, max %u)", cInitialTbs, cInitialTbs, _16K, _8M);
    126 
    127118    /** @cfgm{/IEM/MaxTbCount, uint32_t, 524288}
    128119     * Max number of TBs per EMT. */
     
    130121    rc = CFGMR3QueryU32Def(pIem, "MaxTbCount", &cMaxTbs, _512K);
    131122    AssertLogRelRCReturn(rc, rc);
    132     if (cMaxTbs < cInitialTbs || cMaxTbs > _8M)
     123    if (cMaxTbs < _16K || cMaxTbs > _8M)
    133124        return VMSetError(pVM, VERR_OUT_OF_RANGE, RT_SRC_POS,
    134                           "MaxTbCount value %u (%#x) is out of range (min %u, max %u)", cMaxTbs, cMaxTbs, cInitialTbs, _8M);
     125                          "MaxTbCount value %u (%#x) is out of range (min %u, max %u)", cMaxTbs, cMaxTbs, _16K, _8M);
     126
     127    /** @cfgm{/IEM/InitialTbCount, uint32_t, 32678}
     128     * Initial (minimum) number of TBs per EMT in ring-3. */
     129    uint32_t cInitialTbs = 0;
     130    rc = CFGMR3QueryU32Def(pIem, "InitialTbCount", &cInitialTbs, RT_MIN(cMaxTbs, _32K));
     131    AssertLogRelRCReturn(rc, rc);
     132    if (cInitialTbs < _16K || cInitialTbs > _8M)
     133        return VMSetError(pVM, VERR_OUT_OF_RANGE, RT_SRC_POS,
     134                          "InitialTbCount value %u (%#x) is out of range (min %u, max %u)", cInitialTbs, cInitialTbs, _16K, _8M);
     135
     136    /* Check that the two values makes sense together. Expect user/api to do
     137       the right thing or get lost. */
     138    if (cInitialTbs > cMaxTbs)
     139        return VMSetError(pVM, VERR_OUT_OF_RANGE, RT_SRC_POS,
     140                          "InitialTbCount value %u (%#x) is higher than the MaxTbCount value %u (%#x)",
     141                          cInitialTbs, cInitialTbs, cMaxTbs, cMaxTbs);
    135142#endif
    136143
     
    285292
    286293        PIEMTBALLOCATOR const pTbAllocator = pVCpu->iem.s.pTbAllocatorR3;
    287         STAMR3RegisterF(pVM, (void *)&pTbAllocator->StatAllocs,         STAMTYPE_COUNTER,   STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    288                         "Translation block allocations",                "/IEM/CPU%u/re/cTbAllocs", idCpu);
    289         STAMR3RegisterF(pVM, (void *)&pTbAllocator->StatFrees,          STAMTYPE_COUNTER,   STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
    290                         "Translation block frees",                      "/IEM/CPU%u/re/cTbFrees", idCpu);
     294        STAMR3RegisterF(pVM, (void *)&pTbAllocator->StatAllocs,         STAMTYPE_COUNTER,   STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS,
     295                        "Translation block allocations",                "/IEM/CPU%u/re/cTbAllocCalls", idCpu);
     296        STAMR3RegisterF(pVM, (void *)&pTbAllocator->StatFrees,          STAMTYPE_COUNTER,   STAMVISIBILITY_ALWAYS, STAMUNIT_CALLS,
     297                        "Translation block frees",                      "/IEM/CPU%u/re/cTbFreeCalls", idCpu);
    291298# ifdef VBOX_WITH_STATISTICS
    292299        STAMR3RegisterF(pVM, (void *)&pTbAllocator->StatPrune,          STAMTYPE_PROFILE,   STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
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