VirtualBox

Changeset 106329 in vbox


Ignore:
Timestamp:
Oct 15, 2024 2:19:43 PM (6 weeks ago)
Author:
vboxsync
Message:

VMM/IEM: Some minor perf tweaks for iemExecMemAllocatorPrune. bugref:10720

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

Legend:

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

    r106326 r106329  
    367367     * Before we can start, we must process delayed frees.
    368368     */
     369#if 1
     370    PIEMTBALLOCATOR const pTbAllocator = iemTbAllocatorFreeBulkStart(pVCpu);
     371#else
    369372    iemTbAllocatorProcessDelayedFrees(pVCpu, pVCpu->iem.s.pTbAllocatorR3);
     373#endif
    370374
    371375    AssertCompile(RT_IS_POWER_OF_TWO(IEMEXECMEM_ALT_SUB_ALLOC_UNIT_SIZE));
     
    455459            cbPruned += cbBlock;
    456460
     461#if 1
     462            iemTbAllocatorFreeBulk(pVCpu, pTbAllocator, pTb);
     463#else
    457464            iemTbAllocatorFree(pVCpu, pTb);
     465#endif
    458466        }
    459467        else
     
    461469    }
    462470    STAM_REL_PROFILE_ADD_PERIOD(&pExecMemAllocator->StatPruneRecovered, cbPruned);
     471
     472    pVCpu->iem.s.ppTbLookupEntryR3 = &pVCpu->iem.s.pTbLookupEntryDummyR3;
    463473
    464474    /*
  • trunk/src/VBox/VMM/VMMAll/IEMAllThrdRecompiler.cpp

    r106313 r106329  
    912912/**
    913913 * Inner free worker.
    914  */
    915 static void iemTbAllocatorFreeInner(PVMCPUCC pVCpu, PIEMTBALLOCATOR pTbAllocator,
    916                                     PIEMTB pTb, uint32_t idxChunk, uint32_t idxInChunk)
    917 {
     914 *
     915 * The @a a_fType parameter allows us to eliminate the type check when we know
     916 * which type of TB is being freed.
     917 */
     918template<uint32_t a_fType>
     919DECL_FORCE_INLINE(void)
     920iemTbAllocatorFreeInner(PVMCPUCC pVCpu, PIEMTBALLOCATOR pTbAllocator, PIEMTB pTb, uint32_t idxChunk, uint32_t idxInChunk)
     921{
     922#ifdef VBOX_WITH_IEM_NATIVE_RECOMPILER
     923    AssertCompile(a_fType == 0 || a_fType == IEMTB_F_TYPE_THREADED || a_fType == IEMTB_F_TYPE_NATIVE);
     924#else
     925    AssertCompile(a_fType == 0 || a_fType == IEMTB_F_TYPE_THREADED);
     926#endif
    918927    Assert(idxChunk < pTbAllocator->cAllocatedChunks); RT_NOREF(idxChunk);
    919928    Assert(idxInChunk < pTbAllocator->cTbsPerChunk); RT_NOREF(idxInChunk);
     
    932941     * Free the TB itself.
    933942     */
    934     switch (pTb->fFlags & IEMTB_F_TYPE_MASK)
    935     {
    936         case IEMTB_F_TYPE_THREADED:
    937             pTbAllocator->cThreadedTbs -= 1;
    938             RTMemFree(pTb->Thrd.paCalls);
    939             break;
     943    if RT_CONSTEXPR_IF(a_fType == 0)
     944        switch (pTb->fFlags & IEMTB_F_TYPE_MASK)
     945        {
     946            case IEMTB_F_TYPE_THREADED:
     947                pTbAllocator->cThreadedTbs -= 1;
     948                RTMemFree(pTb->Thrd.paCalls);
     949                break;
    940950#ifdef VBOX_WITH_IEM_NATIVE_RECOMPILER
    941         case IEMTB_F_TYPE_NATIVE:
    942             pTbAllocator->cNativeTbs -= 1;
    943             iemExecMemAllocatorFree(pVCpu, pTb->Native.paInstructions,
    944                                     pTb->Native.cInstructions * sizeof(pTb->Native.paInstructions[0]));
    945             pTb->Native.paInstructions = NULL; /* required by iemExecMemAllocatorPrune */
    946             break;
    947 #endif
    948         default:
    949             AssertFailed();
     951            case IEMTB_F_TYPE_NATIVE:
     952                pTbAllocator->cNativeTbs -= 1;
     953                iemExecMemAllocatorFree(pVCpu, pTb->Native.paInstructions,
     954                                        pTb->Native.cInstructions * sizeof(pTb->Native.paInstructions[0]));
     955                pTb->Native.paInstructions = NULL; /* required by iemExecMemAllocatorPrune */
     956                break;
     957#endif
     958            default:
     959                AssertFailed();
     960        }
     961#ifdef VBOX_WITH_IEM_NATIVE_RECOMPILER
     962    else if RT_CONSTEXPR_IF(a_fType == IEMTB_F_TYPE_NATIVE)
     963    {
     964        Assert((pTb->fFlags & IEMTB_F_TYPE_MASK) == IEMTB_F_TYPE_NATIVE);
     965        pTbAllocator->cNativeTbs -= 1;
     966        iemExecMemAllocatorFree(pVCpu, pTb->Native.paInstructions,
     967                                pTb->Native.cInstructions * sizeof(pTb->Native.paInstructions[0]));
     968        pTb->Native.paInstructions = NULL; /* required by iemExecMemAllocatorPrune */
     969    }
     970#endif
     971    else
     972    {
     973        Assert((pTb->fFlags & IEMTB_F_TYPE_MASK) == IEMTB_F_TYPE_THREADED);
     974        pTbAllocator->cThreadedTbs -= 1;
     975        RTMemFree(pTb->Thrd.paCalls);
    950976    }
    951977
     
    9931019     */
    9941020    pVCpu->iem.s.ppTbLookupEntryR3 = &pVCpu->iem.s.pTbLookupEntryDummyR3;
    995     iemTbAllocatorFreeInner(pVCpu, pTbAllocator, pTb, idxChunk, (uint32_t)idxInChunk);
    996 }
    997 
     1021    iemTbAllocatorFreeInner<0>(pVCpu, pTbAllocator, pTb, idxChunk, (uint32_t)idxInChunk);
     1022}
     1023
     1024#ifdef VBOX_WITH_IEM_NATIVE_RECOMPILER
     1025
     1026/**
     1027 * Interface used by iemExecMemAllocatorPrune.
     1028 */
     1029DECLHIDDEN(void) iemTbAllocatorFreeBulk(PVMCPUCC pVCpu, PIEMTBALLOCATOR pTbAllocator, PIEMTB pTb)
     1030{
     1031    Assert(pTbAllocator->uMagic == IEMTBALLOCATOR_MAGIC);
     1032
     1033    uint8_t const idxChunk = pTb->idxAllocChunk;
     1034    AssertLogRelReturnVoid(idxChunk < pTbAllocator->cAllocatedChunks);
     1035    uintptr_t const idxInChunk = pTb - pTbAllocator->aChunks[idxChunk].paTbs;
     1036    AssertLogRelReturnVoid(idxInChunk < pTbAllocator->cTbsPerChunk);
     1037
     1038    iemTbAllocatorFreeInner<IEMTB_F_TYPE_NATIVE>(pVCpu, pTbAllocator, pTb, idxChunk, (uint32_t)idxInChunk);
     1039}
     1040
     1041
     1042/**
     1043 * Interface used by iemExecMemAllocatorPrune.
     1044 */
     1045DECLHIDDEN(PIEMTBALLOCATOR) iemTbAllocatorFreeBulkStart(PVMCPUCC pVCpu)
     1046{
     1047    PIEMTBALLOCATOR const pTbAllocator = pVCpu->iem.s.pTbAllocatorR3;
     1048    Assert(pTbAllocator && pTbAllocator->uMagic == IEMTBALLOCATOR_MAGIC);
     1049
     1050    iemTbAllocatorProcessDelayedFrees(pVCpu, pTbAllocator);
     1051
     1052    /* It should be sufficient to do this once. */
     1053    pVCpu->iem.s.ppTbLookupEntryR3 = &pVCpu->iem.s.pTbLookupEntryDummyR3;
     1054
     1055    return pTbAllocator;
     1056}
     1057
     1058#endif /* VBOX_WITH_IEM_NATIVE_RECOMPILER */
    9981059
    9991060/**
     
    10831144            PIEMTB const pTb = &paTbs[idxTb];
    10841145            if (pTb->fFlags)
    1085                 iemTbAllocatorFreeInner(pVCpu, pTbAllocator, pTb, idxChunk, idxTb);
     1146                iemTbAllocatorFreeInner<0>(pVCpu, pTbAllocator, pTb, idxChunk, idxTb);
    10861147        }
    10871148    }
     
    12471308
    12481309        /* Free the TB. */
    1249         iemTbAllocatorFreeInner(pVCpu, pTbAllocator, pTb, idxChunk, idxInChunk);
     1310        iemTbAllocatorFreeInner<0>(pVCpu, pTbAllocator, pTb, idxChunk, idxInChunk);
    12501311        cFreedTbs++; /* paranoia */
    12511312    }
     
    13701431        {
    13711432            cMaxInstrs = RT_MAX(cMaxInstrs, pTb->Native.cInstructions);
    1372             iemTbAllocatorFreeInner(pVCpu, pTbAllocator, pTb, idxChunk, idxInChunk);
     1433            iemTbAllocatorFreeInner<IEMTB_F_TYPE_NATIVE>(pVCpu, pTbAllocator, pTb, idxChunk, idxInChunk);
    13731434            cFreedTbs++;
    13741435            if (cFreedTbs >= 8 && cMaxInstrs >= cNeededInstrs)
  • trunk/src/VBox/VMM/include/IEMInternal.h

    r106297 r106329  
    67046704void                iemTbAllocatorProcessDelayedFrees(PVMCPUCC pVCpu, PIEMTBALLOCATOR pTbAllocator);
    67056705void                iemTbAllocatorFreeupNativeSpace(PVMCPUCC pVCpu, uint32_t cNeededInstrs);
     6706DECLHIDDEN(PIEMTBALLOCATOR) iemTbAllocatorFreeBulkStart(PVMCPUCC pVCpu);
     6707DECLHIDDEN(void)    iemTbAllocatorFreeBulk(PVMCPUCC pVCpu, PIEMTBALLOCATOR pTbAllocator, PIEMTB pTb);
    67066708DECLHIDDEN(const char *) iemTbFlagsToString(uint32_t fFlags, char *pszBuf, size_t cbBuf) RT_NOEXCEPT;
    67076709DECLHIDDEN(void)    iemThreadedDisassembleTb(PCIEMTB pTb, PCDBGFINFOHLP pHlp) RT_NOEXCEPT;
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