VirtualBox

Changeset 57126 in vbox


Ignore:
Timestamp:
Jul 30, 2015 10:17:57 AM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
101864
Message:

VMM: Optimizations for memory scanning, trying to make 'detect' run faster against 64-bit guest systems.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/Makefile.kmk

    r56792 r57126  
    180180        VMMR3/PGM.cpp \
    181181        VMMR3/PGMDbg.cpp \
     182        VMMR3/PGMR3DbgA.asm \
    182183        VMMR3/PGMHandler.cpp \
    183184        VMMR3/PGMMap.cpp \
  • trunk/src/VBox/VMM/VMMR3/PGMDbg.cpp

    r57006 r57126  
    9494
    9595
     96/**
     97 * Assembly scanning function.
     98 *
     99 * @returns Pointer to possible match or NULL.
     100 * @param   pvHaystack      Pointer to what we search in.
     101 * @param   cbHaystack      Number of bytes to search.
     102 * @param   pvNeedle        Pointer to what we search for.
     103 * @param   cbNeedle        Size of what we're searching for.
     104 */
     105typedef DECLCALLBACK(uint8_t const *) FNPGMR3DBGFIXEDMEMSCAN(void const *pvHaystack, uint32_t cbHaystack,
     106                                                             void const *pvNeedle, size_t cbNeedle);
     107/** Pointer to an fixed size and step assembly scanner function. */
     108typedef FNPGMR3DBGFIXEDMEMSCAN *PFNPGMR3DBGFIXEDMEMSCAN;
     109
     110
     111/*******************************************************************************
     112*   Internal Functions                                                         *
     113*******************************************************************************/
     114DECLASM(uint8_t const *) pgmR3DbgFixedMemScan8Wide8Step(void const *, uint32_t, void const *, size_t cbNeedle);
     115DECLASM(uint8_t const *) pgmR3DbgFixedMemScan4Wide4Step(void const *, uint32_t, void const *, size_t cbNeedle);
     116DECLASM(uint8_t const *) pgmR3DbgFixedMemScan2Wide2Step(void const *, uint32_t, void const *, size_t cbNeedle);
     117DECLASM(uint8_t const *) pgmR3DbgFixedMemScan1Wide1Step(void const *, uint32_t, void const *, size_t cbNeedle);
     118DECLASM(uint8_t const *) pgmR3DbgFixedMemScan4Wide1Step(void const *, uint32_t, void const *, size_t cbNeedle);
     119DECLASM(uint8_t const *) pgmR3DbgFixedMemScan8Wide1Step(void const *, uint32_t, void const *, size_t cbNeedle);
     120
    96121
    97122/**
     
    470495 */
    471496static bool pgmR3DbgScanPage(const uint8_t *pbPage, int32_t *poff, uint32_t cb, uint32_t uAlign,
    472                              const uint8_t *pabNeedle, size_t cbNeedle,
     497                             const uint8_t *pabNeedle, size_t cbNeedle, PFNPGMR3DBGFIXEDMEMSCAN pfnFixedMemScan,
    473498                             uint8_t *pabPrev, size_t *pcbPrev)
    474499{
     
    517542     */
    518543    const uint8_t *pb = pbPage + *poff;
    519     const uint8_t *pbEnd = pb + cb;
     544    const uint8_t * const pbEnd = pb + cb;
    520545    for (;;)
    521546    {
    522         pb = pgmR3DbgAlignedMemChr(pb, *pabNeedle, cb, uAlign);
     547        AssertMsg(((uintptr_t)pb & (uAlign - 1)) == 0, ("%#p %#x\n", pb, uAlign));
     548        if (pfnFixedMemScan)
     549            pb = pfnFixedMemScan(pb, cb, pabNeedle, cbNeedle);
     550        else
     551            pb = pgmR3DbgAlignedMemChr(pb, *pabNeedle, cb, uAlign);
    523552        if (!pb)
    524553            break;
     
    554583    return false;
    555584}
     585
     586
     587static void pgmR3DbgSelectMemScanFunction(PFNPGMR3DBGFIXEDMEMSCAN *ppfnMemScan, uint32_t GCPhysAlign, size_t cbNeedle)
     588{
     589    *ppfnMemScan = NULL;
     590    switch (GCPhysAlign)
     591    {
     592        case 1:
     593            if (cbNeedle >= 8)
     594                *ppfnMemScan = pgmR3DbgFixedMemScan8Wide1Step;
     595            else if (cbNeedle >= 4)
     596                *ppfnMemScan = pgmR3DbgFixedMemScan8Wide1Step;
     597            else
     598                *ppfnMemScan = pgmR3DbgFixedMemScan1Wide1Step;
     599            break;
     600        case 2:
     601            if (cbNeedle >= 2)
     602                *ppfnMemScan = pgmR3DbgFixedMemScan2Wide2Step;
     603            break;
     604        case 4:
     605            if (cbNeedle >= 4)
     606                *ppfnMemScan = pgmR3DbgFixedMemScan4Wide4Step;
     607            break;
     608        case 8:
     609            if (cbNeedle >= 8)
     610                *ppfnMemScan = pgmR3DbgFixedMemScan8Wide8Step;
     611            break;
     612    }
     613}
     614
    556615
    557616
     
    621680                               ? GCPhys + cbRange - 1
    622681                               : ~(RTGCPHYS)0;
     682
     683    PFNPGMR3DBGFIXEDMEMSCAN pfnMemScan;
     684    pgmR3DbgSelectMemScanFunction(&pfnMemScan, (uint32_t)GCPhysAlign, cbNeedle);
    623685
    624686    /*
     
    677739                                              : (GCPhysLast & PAGE_OFFSET_MASK) + 1 - (uint32_t)offPage;
    678740                            fRc = pgmR3DbgScanPage((uint8_t const *)pvPage, &offHit, cbSearch, (uint32_t)GCPhysAlign,
    679                                                    pabNeedle, cbNeedle, &abPrev[0], &cbPrev);
     741                                                   pabNeedle, cbNeedle, pfnMemScan, &abPrev[0], &cbPrev);
    680742                        }
    681743                        else
     
    796858    uint32_t        offPage   = GCPtr & PAGE_OFFSET_MASK;
    797859    GCPtr &= ~(RTGCPTR)PAGE_OFFSET_MASK;
     860
     861    PFNPGMR3DBGFIXEDMEMSCAN pfnMemScan;
     862    pgmR3DbgSelectMemScanFunction(&pfnMemScan, (uint32_t)GCPtrAlign, cbNeedle);
     863
     864    uint32_t        cYieldCountDown = 4096;
     865    pgmLock(pVM);
    798866    for (;; offPage = 0)
    799867    {
     
    822890                                          : (GCPtrLast & PAGE_OFFSET_MASK) + 1 - (uint32_t)offPage;
    823891                        fRc = pgmR3DbgScanPage((uint8_t const *)pvPage, &offHit, cbSearch, (uint32_t)GCPtrAlign,
    824                                                pabNeedle, cbNeedle, &abPrev[0], &cbPrev);
     892                                               pabNeedle, cbNeedle, pfnMemScan, &abPrev[0], &cbPrev);
    825893                    }
    826894                    else
     
    831899                    {
    832900                        *pGCPtrHit = GCPtr + offHit;
     901                        pgmUnlock(pVM);
    833902                        return VINF_SUCCESS;
    834903                    }
     
    905974        cPages -= cIncPages;
    906975        GCPtr += (RTGCPTR)cIncPages << X86_PT_PAE_SHIFT;
    907     }
     976
     977        /* Yield the PGM lock every now and then. */
     978        if (!--cYieldCountDown)
     979        {
     980            PDMR3CritSectYield(&pVM->pgm.s.CritSectX);
     981            cYieldCountDown = 4096;
     982        }
     983    }
     984    pgmUnlock(pVM);
    908985    return VERR_DBGF_MEM_NOT_FOUND;
    909986}
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