VirtualBox

Changeset 92267 in vbox for trunk/src


Ignore:
Timestamp:
Nov 8, 2021 12:22:09 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
148109
Message:

ValKit/bs3-memalloc-1: Time the 2nd and an additional 3rd round of memory accesses to mesure page pool efficiency. This also provides comparsion points for the allocation speed. bugref:10093

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-memalloc-1.c64

    r92266 r92267  
    4949
    5050
     51/**
     52 * For subsequence touch iterations that doesn't allocate any RAM.
     53 *
     54 * This may cause page pool activitiy if we've got more memory than we have room
     55 * for in the pool.  This depends on amount of guest RAM and how much could be
     56 * backed by large pages.
     57 */
    5158static uint64_t CheckTouchedMemory(void)
    5259{
     
    5663    for (iEntry = 0; iEntry < g_cEntries; iEntry++)
    5764    {
    58         uint64_t *pu64Cur = (uint64_t *)g_aEntries[iEntry].uBaseAddr;
    59         uint64_t  cbLeft  = g_aEntries[iEntry].cbRange;
     65        uint64_t volatile *pu64Cur = (uint64_t *)g_aEntries[iEntry].uBaseAddr;
     66        uint64_t           cbLeft  = g_aEntries[iEntry].cbRange;
    6067        while (cbLeft >= X86_PAGE_SIZE)
    6168        {
    62             if (   pu64Cur[0] == iPage
    63                 && pu64Cur[1] == iPage)
     69            /* Check first. */
     70            if (RT_LIKELY(   pu64Cur[0] == iPage
     71                          && pu64Cur[1] == iPage))
    6472            { /* likely */ }
    6573            else
     
    6977            }
    7078
     79            /* Then write again. */
     80            pu64Cur[0] = iPage;
     81            pu64Cur[1] = iPage;
     82
     83            /* Advance. */
    7184            iPage++;
    7285            pu64Cur += X86_PAGE_SIZE / sizeof(*pu64Cur);
     
    7891
    7992
    80 static uint64_t TouchMemory(void)
     93/**
     94 * First touching of memory, assuming content is ZERO.
     95 */
     96static uint64_t FirstTouchMemory(void)
    8197{
    8298    unsigned iEntry;
     
    84100    for (iEntry = 0; iEntry < g_cEntries; iEntry++)
    85101    {
    86         uint64_t *pu64Cur = (uint64_t *)g_aEntries[iEntry].uBaseAddr;
    87         uint64_t  cbLeft  = g_aEntries[iEntry].cbRange;
     102        uint64_t volatile *pu64Cur = (uint64_t volatile *)g_aEntries[iEntry].uBaseAddr;
     103        uint64_t           cbLeft  = g_aEntries[iEntry].cbRange;
    88104        while (cbLeft >= X86_PAGE_SIZE)
    89105        {
     106            /*
     107             * Write to the page first so we won't waste time mapping the zero
     108             * page and get straight to the actual page allocation.
     109             */
    90110            pu64Cur[0] = iPage;
    91             if (pu64Cur[1] != 0)
     111
     112            /* Then check that the 2nd qword is zero before writing it. */
     113            if (RT_LIKELY(pu64Cur[1] == 0))
     114            { /* likely */ }
     115            else
    92116                Bs3TestFailedF("%p: %#llx, expected zero\n", pu64Cur, pu64Cur[1]);
    93117            pu64Cur[1] = iPage;
    94118
     119            /* Advance. */
    95120            iPage++;
    96121            pu64Cur += X86_PAGE_SIZE / sizeof(*pu64Cur);
     
    174199                      g_cEntries, g_cbInteresting, (unsigned)(g_cbInteresting / _1G), g_uInterestingStart, g_uInterestingEnd);
    175200
     201        if (g_uBs3EndOfRamAbove4G < g_uInterestingEnd)
     202            Bs3TestFailedF("g_uBs3EndOfRamAbove4G (%#llx) is lower than g_uInterestingEnd (%#llx)!\n",
     203                           g_uBs3EndOfRamAbove4G, g_uInterestingEnd);
     204
     205
    176206        /*
    177207         * Map all the memory (Bs3Kit only maps memory below 4G).
     
    184214        else if (RT_SUCCESS(rc = Bs3PagingMapRamAbove4GForLM(&uFailurePoint)))
    185215        {
     216#define PAGES_2_MB(a_cPages) ((a_cPages) / (_1M / X86_PAGE_SIZE))
     217            uint64_t cTotalPages;
     218
     219            /*
     220             * Time touching all the memory.
     221             */
    186222            Bs3TestSub("Allocation speed");
    187223            {
    188                 /*
    189                  * Time touching all the memory.
    190                  */
    191224                uint64_t const  nsStart       = Bs3TestNow();
    192225                uint64_t const  uTscStart     = ASMReadTSC();
    193                 uint64_t const  cPages        = TouchMemory();
     226                uint64_t const  cPages        = FirstTouchMemory();
    194227                uint64_t const  cTicksElapsed = ASMReadTSC() - uTscStart;
    195228                uint64_t const  cNsElapsed    = Bs3TestNow() - nsStart;
    196229                uint64_t uThruput;
    197 #define PAGES_2_MB(a_cPages) ((a_cPages) / (_1M / X86_PAGE_SIZE))
    198230                Bs3TestValue("Pages",                       cPages,                 VMMDEV_TESTING_UNIT_PAGES);
    199231                Bs3TestValue("MiBs",                        PAGES_2_MB(cPages),     VMMDEV_TESTING_UNIT_MEGABYTES);
    200                 Bs3TestValue("Elapsed",                     cNsElapsed,             VMMDEV_TESTING_UNIT_NS);
    201                 Bs3TestValue("Elapsed in ticks",            cTicksElapsed,          VMMDEV_TESTING_UNIT_TICKS);
     232                Bs3TestValue("Alloc elapsed",               cNsElapsed,             VMMDEV_TESTING_UNIT_NS);
     233                Bs3TestValue("Alloc elapsed in ticks",      cTicksElapsed,          VMMDEV_TESTING_UNIT_TICKS);
    202234                Bs3TestValue("Page alloc time",             cNsElapsed / cPages,    VMMDEV_TESTING_UNIT_NS_PER_PAGE);
    203235                Bs3TestValue("Page alloc time in ticks",    cTicksElapsed / cPages, VMMDEV_TESTING_UNIT_TICKS_PER_PAGE);
    204236                uThruput = cPages * RT_NS_1SEC / cNsElapsed;
    205                 Bs3TestValue("Thruput",                     uThruput,               VMMDEV_TESTING_UNIT_PAGES_PER_SEC);
    206                 Bs3TestValue("Thruput in MiBs",             PAGES_2_MB(uThruput),   VMMDEV_TESTING_UNIT_MEGABYTES_PER_SEC);
    207                 CheckTouchedMemory();
     237                Bs3TestValue("Alloc thruput",               uThruput,               VMMDEV_TESTING_UNIT_PAGES_PER_SEC);
     238                Bs3TestValue("Alloc thruput in MiBs",       PAGES_2_MB(uThruput),   VMMDEV_TESTING_UNIT_MEGABYTES_PER_SEC);
     239                cTotalPages = cPages;
     240            }
     241
     242            /*
     243             * Time accessing all the memory again.  This might give a clue as to page pool performance.
     244             */
     245            for (unsigned iLoop = 0; iLoop < 2; iLoop++)
     246            {
     247                Bs3TestSub(iLoop == 0 ? "2nd access" : "3rd access");
     248                {
     249                    uint64_t const  nsStart       = Bs3TestNow();
     250                    uint64_t const  uTscStart     = ASMReadTSC();
     251                    uint64_t const  cErrors       = CheckTouchedMemory();
     252                    uint64_t const  cTicksElapsed = ASMReadTSC() - uTscStart;
     253                    uint64_t const  cNsElapsed    = Bs3TestNow() - nsStart;
     254                    uint64_t uThruput;
     255                    Bs3TestValue("Access elapsed",              cNsElapsed,             VMMDEV_TESTING_UNIT_NS);
     256                    Bs3TestValue("Access elapsed in ticks",     cTicksElapsed,          VMMDEV_TESTING_UNIT_TICKS);
     257                    Bs3TestValue("Page access time",            cNsElapsed / cTotalPages, VMMDEV_TESTING_UNIT_NS_PER_PAGE);
     258                    Bs3TestValue("Page access time in ticks",   cTicksElapsed / cTotalPages, VMMDEV_TESTING_UNIT_TICKS_PER_PAGE);
     259                    uThruput = cTotalPages * RT_NS_1SEC / cNsElapsed;
     260                    Bs3TestValue("Access thruput",              uThruput,               VMMDEV_TESTING_UNIT_PAGES_PER_SEC);
     261                    Bs3TestValue("Access thruput in MiBs",      PAGES_2_MB(uThruput),   VMMDEV_TESTING_UNIT_MEGABYTES_PER_SEC);
     262                }
    208263            }
    209264        }
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