VirtualBox

Changeset 26419 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Feb 10, 2010 11:21:14 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
57523
Message:

tstRTMemCache: Testcase + bug fixes. Works pretty well, but should try tune it a bit.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/alloc/memcache.cpp

    r26418 r26419  
    207207            while (iObj-- > 0)
    208208                if (ASMBitTestAndClear(pPage->pbmCtor, iObj))
    209                     pThis->pfnDtor(hMemCache, (uint8_t *)pPage->pbObjects + iObj * pThis->cPerPage, pThis->pvUser);
     209                    pThis->pfnDtor(hMemCache, pPage->pbObjects + iObj * pThis->cbObject, pThis->pvUser);
    210210        }
    211211
     
    238238         */
    239239        PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)RTMemPageAlloc(PAGE_SIZE);
    240         if (!pPage)
    241         {
    242             uint32_t cObjects = pThis->cPerPage;
    243             if (pThis->cTotal + cObjects > pThis->cMax)
    244                 cObjects = pThis->cTotal - pThis->cMax;
     240        if (pPage)
     241        {
     242            uint32_t const cObjects = RT_MIN(pThis->cPerPage, pThis->cMax - pThis->cTotal);
    245243
    246244            ASMMemZeroPage(pPage);
     
    248246            pPage->pNext        = NULL;
    249247            pPage->cFree        = cObjects;
    250             pPage->pbmAlloc     = (pThis + 1);
     248            pPage->cObjects     = cObjects;
     249            pPage->pbmAlloc     = pPage + 1;
    251250            pPage->pbmCtor      = (uint8_t *)pPage->pbmAlloc + pThis->cBits / 8;
    252251            pPage->pbObjects    = (uint8_t *)pPage->pbmCtor  + pThis->cBits / 8;
     
    317316        {
    318317            ASMAtomicIncS32(&pThis->cFree);
    319             return VERR_CACHE_EMPTY;
     318            return VERR_MEM_CACHE_MAX_SIZE;
    320319        }
    321320
     
    369368            else if (!ASMAtomicBitTestAndSet(pPage->pbmAlloc, iObj))
    370369                break;
    371             Assert(cLoops2 != 2);
    372             Assert(cLoops2 != 10);
     370            Assert(cLoops2 != 40);
    373371        }
    374372        Assert(iObj >= 0);
    375373    }
    376374    void *pvObj = &pPage->pbObjects[iObj * pThis->cbObject];
     375    Assert((uintptr_t)pvObj - (uintptr_t)pPage < PAGE_SIZE);
    377376
    378377    /*
     
    391390    }
    392391
     392    *ppvObj = pvObj;
    393393    return VINF_SUCCESS;
    394394}
     
    423423     * Find the cache page.  The page structure is at the start of the page.
    424424     */
    425     PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)(((uintptr_t)pvObj) & ~(uintptr_t)PAGE_SIZE);
     425    PRTMEMCACHEPAGE pPage = (PRTMEMCACHEPAGE)(((uintptr_t)pvObj) & ~(uintptr_t)PAGE_OFFSET_MASK);
    426426    AssertReturnVoid(pPage->pCache == pThis);
    427427    AssertReturnVoid(ASMAtomicUoReadS32(&pPage->cFree) < (int32_t)pThis->cPerPage);
     
    430430     * Clear the bitmap bit and update the two object counter. Order matters!
    431431     */
    432     uintptr_t iObj = (uintptr_t)pvObj - (uintptr_t)pPage->pbObjects;
    433     AssertReturnVoid(iObj < pThis->cPerPage);
     432    uintptr_t offObj = (uintptr_t)pvObj - (uintptr_t)pPage->pbObjects;
     433    uintptr_t iObj   = offObj / pThis->cbObject;
     434    AssertReturnVoid(iObj * pThis->cbObject == offObj);
     435    Assert(iObj < pThis->cPerPage);
    434436    AssertReturnVoid(ASMAtomicBitTestAndClear(pPage->pbmAlloc, iObj));
    435437
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r26224 r26419  
    7878        tstLog \
    7979        tstMemAutoPtr \
     80        tstRTMemCache \
    8081        tstRTMemPool \
    8182        tstRTR0MemUserKernelDriver \
     
    309310tstMemAutoPtr_SOURCES = tstMemAutoPtr.cpp
    310311
     312tstRTMemCache_TEMPLATE = VBOXR3TSTEXE
     313tstRTMemCache_SOURCES = tstRTMemCache.cpp
     314
    311315tstRTMemPool_TEMPLATE = VBOXR3TSTEXE
    312316tstRTMemPool_SOURCES = tstRTMemPool.cpp
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