VirtualBox

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


Ignore:
Timestamp:
Aug 21, 2024 11:52:56 PM (5 months ago)
Author:
vboxsync
Message:

VMM/IEM: End TB if we get back to the first instruction again via an indirect route, e.g. jumping to a point before the TB starts, and optimize this using the loop-jump (todo 14). bugref:10720 bugref:10656

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

Legend:

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

    r105718 r105805  
    21192119}
    21202120
    2121 
    21222121#ifdef IEM_WITH_INTRA_TB_JUMPS
     2122
    21232123/**
    21242124 * Emits the necessary tail calls for a full TB loop-jump.
     
    21712171    return false;
    21722172}
     2173
     2174/**
     2175 * Called by IEM_MC2_BEGIN_EMIT_CALLS when it detects that we're back at the
     2176 * first instruction and we didn't just branch to it (that's handled below).
     2177 *
     2178 * This will emit a loop iff everything is compatible with that.
     2179 */
     2180DECLHIDDEN(int) iemThreadedCompileBackAtFirstInstruction(PVMCPU pVCpu, PIEMTB pTb) RT_NOEXCEPT
     2181{
     2182    /* Check if the mode matches. */
     2183    if (   (pVCpu->iem.s.fExec & IEMTB_F_IEM_F_MASK & IEMTB_F_KEY_MASK)
     2184        == (pTb->fFlags        & IEMTB_F_KEY_MASK   & ~IEMTB_F_CS_LIM_CHECKS))
     2185    {
     2186        STAM_REL_COUNTER_INC(&pVCpu->iem.s.StatTbLoopFullTbDetected2);
     2187        iemThreadedCompileFullTbJump(pVCpu, pTb);
     2188    }
     2189    return VINF_IEM_RECOMPILE_END_TB;
     2190}
     2191
    21732192#endif /* IEM_WITH_INTRA_TB_JUMPS */
    21742193
  • trunk/src/VBox/VMM/VMMAll/IEMAllThrdTables.h

    r105673 r105805  
    174174
    175175
     176#ifndef IEM_WITH_INTRA_TB_JUMPS
     177/**
     178 * Stub for a no-jumps config, see IEMAllThrdRecompiler.cpp for the real thing.
     179 */
     180DECL_FORCE_INLINE(int) iemThreadedCompileBackAtFirstInstruction(PVMCPU pVCpu, PIEMTB pTb)
     181{
     182    RT_NOREF(pTb);
     183    STAM_REL_COUNTER_INC(&pVCpu->iem.s.StatTbLoopFullTbDetected2);
     184    return VINF_IEM_RECOMPILE_END_TB;
     185}
     186#endif
     187
     188
    176189/*
    177190 * Emit call macros.
     
    205218            && !(pTb->fFlags & IEMTB_F_CS_LIM_CHECKS)) \
    206219        { \
    207             /** @todo Custom copy function, given range is 1 thru 15 bytes. */ \
    208             memcpy(&pTb->pabOpcodes[offOpcodeMc2], pVCpu->iem.s.abOpcode, pVCpu->iem.s.offOpcode); \
    209             pTb->cbOpcodes                       = offOpcodeMc2 + pVCpu->iem.s.offOpcode; \
    210             pTb->aRanges[idxRangeMc2].cbOpcodes += cbInstrMc2; \
    211             Assert(pTb->cbOpcodes <= pVCpu->iem.s.cbOpcodesAllocated); \
     220            /* Break/loop if we're back to the first instruction in the TB again. */ \
     221            if (   pTb->aRanges[idxRangeMc2].idxPhysPage != 0 \
     222                ||    (unsigned)pTb->aRanges[idxRangeMc2].offPhysPage + (unsigned)pTb->aRanges[idxRangeMc2].cbOpcodes \
     223                   != (pTb->GCPhysPc & GUEST_PAGE_OFFSET_MASK) \
     224                || offOpcodeMc2 == 0) \
     225            { \
     226                /** @todo Custom copy function, given range is 1 thru 15 bytes. */ \
     227                memcpy(&pTb->pabOpcodes[offOpcodeMc2], pVCpu->iem.s.abOpcode, pVCpu->iem.s.offOpcode); \
     228                pTb->cbOpcodes                       = offOpcodeMc2 + pVCpu->iem.s.offOpcode; \
     229                pTb->aRanges[idxRangeMc2].cbOpcodes += cbInstrMc2; \
     230                Assert(pTb->cbOpcodes <= pVCpu->iem.s.cbOpcodesAllocated); \
     231            } \
     232            else \
     233                return iemThreadedCompileBackAtFirstInstruction(pVCpu, pTb); \
    212234        } \
    213235        else if (iemThreadedCompileBeginEmitCallsComplications(pVCpu, pTb)) \
  • trunk/src/VBox/VMM/VMMR3/IEMR3.cpp

    r105718 r105805  
    686686        STAMR3RegisterF(pVM, (void *)&pVCpu->iem.s.StatTbLoopFullTbDetected, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
    687687                        "Detected loop full TB",  "/IEM/CPU%u/re/LoopFullTbDetected", idCpu);
     688        STAMR3RegisterF(pVM, (void *)&pVCpu->iem.s.StatTbLoopFullTbDetected2, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
     689                        "Detected loop full TB but looping back to before the first TB instruction",
     690                        "/IEM/CPU%u/re/LoopFullTbDetected2", idCpu);
    688691        STAMR3RegisterF(pVM, (void *)&pVCpu->iem.s.StatTbLoopInTbDetected, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
    689692                        "Detected loop within TB", "/IEM/CPU%u/re/LoopInTbDetected", idCpu);
  • trunk/src/VBox/VMM/include/IEMInternal.h

    r105718 r105805  
    22952295    /** Statistics: Times a loop back to the start of the TB was detected. */
    22962296    STAMCOUNTER             StatTbLoopFullTbDetected;
     2297    /** Statistics: Times a loop back to the start of the TB was detected, var 2. */
     2298    STAMCOUNTER             StatTbLoopFullTbDetected2;
    22972299    /** Exec memory allocator statistics: Number of times allocaintg executable memory failed. */
    22982300    STAMCOUNTER             StatNativeExecMemInstrBufAllocFailed;
     
    25172519
    25182520#ifdef IEM_WITH_TLB_TRACE
    2519     uint64_t                au64Padding[7];
     2521    uint64_t                au64Padding[6];
    25202522#else
    2521     uint64_t                au64Padding[1];
     2523    //uint64_t                au64Padding[0];
    25222524#endif
    25232525
     
    68846886bool iemThreadedCompileEmitIrqCheckBefore(PVMCPUCC pVCpu, PIEMTB pTb);
    68856887bool iemThreadedCompileBeginEmitCallsComplications(PVMCPUCC pVCpu, PIEMTB pTb);
     6888#ifdef IEM_WITH_INTRA_TB_JUMPS
     6889DECLHIDDEN(int)     iemThreadedCompileBackAtFirstInstruction(PVMCPU pVCpu, PIEMTB pTb) RT_NOEXCEPT;
     6890#endif
    68866891
    68876892/* Native recompiler public bits: */
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