VirtualBox

Changeset 105179 in vbox for trunk/src/VBox/VMM/VMMAll


Ignore:
Timestamp:
Jul 8, 2024 10:38:14 AM (7 months ago)
Author:
vboxsync
Message:

VMM/IEM: Introduce a small cache of recently freed TBs for immediate consumption by the allocator to reduce the amount of time required in ASMBitFirstClear()/ASMBitNextClear() to scan for freed TBs when allocating a new TB, bugref:10653

File:
1 edited

Legend:

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

    r105178 r105179  
    946946    pTb->pabOpcodes         = NULL;
    947947
    948     ASMBitClear(&pTbAllocator->bmAllocated, IEMTBALLOC_IDX_MAKE(pTbAllocator, idxChunk, idxInChunk));
     948    if (pTbAllocator->idxTbCacheFree < RT_ELEMENTS(pTbAllocator->apTbFreeCache))
     949        pTbAllocator->apTbFreeCache[pTbAllocator->idxTbCacheFree++] = pTb;
     950    else
     951        ASMBitClear(&pTbAllocator->bmAllocated, IEMTBALLOC_IDX_MAKE(pTbAllocator, idxChunk, idxInChunk));
    949952    Assert(pTbAllocator->cInUseTbs > 0);
    950953
     
    10921095    Assert(pTbAllocator->cInUseTbs < pTbAllocator->cTotalTbs);
    10931096
    1094     int idxTb;
    1095     if (pTbAllocator->iStartHint < pTbAllocator->cTotalTbs)
    1096         idxTb = ASMBitNextClear(pTbAllocator->bmAllocated,
    1097                                 pTbAllocator->cTotalTbs,
    1098                                 pTbAllocator->iStartHint & ~(uint32_t)63);
     1097    PIEMTB pTb;
     1098    if (pTbAllocator->idxTbCacheFree)
     1099        pTb = pTbAllocator->apTbFreeCache[--pTbAllocator->idxTbCacheFree];
    10991100    else
    1100         idxTb = -1;
    1101     if (idxTb < 0)
    1102     {
    1103         idxTb = ASMBitFirstClear(pTbAllocator->bmAllocated, pTbAllocator->cTotalTbs);
    1104         AssertLogRelReturn(idxTb >= 0, NULL);
    1105     }
    1106     Assert((uint32_t)idxTb < pTbAllocator->cTotalTbs);
    1107     pTbAllocator->iStartHint = idxTb;
    1108     ASMBitSet(pTbAllocator->bmAllocated, idxTb);
    1109 
    1110     /** @todo shift/mask optimization for power of two IEMTB sizes. */
    1111     uint32_t const idxChunk     = IEMTBALLOC_IDX_TO_CHUNK(pTbAllocator, idxTb);
    1112     uint32_t const idxTbInChunk = IEMTBALLOC_IDX_TO_INDEX_IN_CHUNK(pTbAllocator, idxTb, idxChunk);
    1113     PIEMTB const   pTb          = &pTbAllocator->aChunks[idxChunk].paTbs[idxTbInChunk];
    1114     Assert(pTb->idxAllocChunk == idxChunk);
     1101    {
     1102        int idxTb;
     1103        if (pTbAllocator->iStartHint < pTbAllocator->cTotalTbs)
     1104            idxTb = ASMBitNextClear(pTbAllocator->bmAllocated,
     1105                                    pTbAllocator->cTotalTbs,
     1106                                    pTbAllocator->iStartHint & ~(uint32_t)63);
     1107        else
     1108            idxTb = -1;
     1109        if (idxTb < 0)
     1110        {
     1111            idxTb = ASMBitFirstClear(pTbAllocator->bmAllocated, pTbAllocator->cTotalTbs);
     1112            AssertLogRelReturn(idxTb >= 0, NULL);
     1113        }
     1114        Assert((uint32_t)idxTb < pTbAllocator->cTotalTbs);
     1115        pTbAllocator->iStartHint = idxTb;
     1116        ASMBitSet(pTbAllocator->bmAllocated, idxTb);
     1117
     1118        /** @todo shift/mask optimization for power of two IEMTB sizes. */
     1119        uint32_t const idxChunk     = IEMTBALLOC_IDX_TO_CHUNK(pTbAllocator, idxTb);
     1120        uint32_t const idxTbInChunk = IEMTBALLOC_IDX_TO_INDEX_IN_CHUNK(pTbAllocator, idxTb, idxChunk);
     1121        pTb          = &pTbAllocator->aChunks[idxChunk].paTbs[idxTbInChunk];
     1122        Assert(pTb->idxAllocChunk == idxChunk);
     1123    }
    11151124
    11161125    pTbAllocator->cInUseTbs        += 1;
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