VirtualBox

Changeset 101645 in vbox for trunk


Ignore:
Timestamp:
Oct 30, 2023 9:28:02 AM (16 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
159734
Message:

ValidationKit/utils/FsPerf: Allow building on linux.arm64, bugref:10541

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/utils/fs/FsPerf.cpp

    r99775 r101645  
    480480/** The test handle. */
    481481static RTTEST       g_hTest;
     482/** The page size of the system. */
     483static uint32_t     g_cbPage;
     484/** Page offset mask. */
     485static uintptr_t    g_fPageOffset;
     486/** Page shift in bits. */
     487static uint32_t     g_cPageShift;
    482488/** The number of nanoseconds a RTTimeNanoTS call takes.
    483489 * This is used for adjusting loop count estimates.  */
     
    39143920    RTTestISub("sendfile");
    39153921# ifdef RT_OS_LINUX
    3916     uint64_t const cbFileMax = RT_MIN(cbFile, UINT32_MAX - PAGE_OFFSET_MASK);
     3922    uint64_t const cbFileMax = RT_MIN(cbFile, UINT32_MAX - g_fPageOffset);
    39173923# else
    3918     uint64_t const cbFileMax = RT_MIN(cbFile, SSIZE_MAX - PAGE_OFFSET_MASK);
     3924    uint64_t const cbFileMax = RT_MIN(cbFile, SSIZE_MAX - g_fPageOffset);
    39193925# endif
    39203926    signal(SIGPIPE, SIG_IGN);
     
    39593965
    39603966        cbToSend /= 2;
    3961     } while (cbToSend >= PAGE_SIZE && ((unsigned)bFiller - 0xf7U) < 64);
     3967    } while (cbToSend >= g_cbPage && ((unsigned)bFiller - 0xf7U) < 64);
    39623968
    39633969    /*
     
    41744180    }
    41754181
    4176     uint64_t const cbFileMax = RT_MIN(cbFile, UINT32_MAX - PAGE_OFFSET_MASK);
     4182    uint64_t const cbFileMax = RT_MIN(cbFile, UINT32_MAX - g_fPageOffset);
    41774183    signal(SIGPIPE, SIG_IGN);
    41784184
     
    42164222
    42174223        cbToSend /= 2;
    4218     } while (cbToSend >= PAGE_SIZE && ((unsigned)bFiller - 0xf7U) < 64);
     4224    } while (cbToSend >= g_cbPage && ((unsigned)bFiller - 0xf7U) < 64);
    42194225
    42204226    /*
     
    43984404    }
    43994405
    4400     uint64_t const cbFileMax = RT_MIN(cbFile, UINT32_MAX - PAGE_OFFSET_MASK);
     4406    uint64_t const cbFileMax = RT_MIN(cbFile, UINT32_MAX - g_fPageOffset);
    44014407    signal(SIGPIPE, SIG_IGN);
    44024408
     
    47824788     * Do uncached access, must be page aligned.
    47834789     */
    4784     uint32_t cbPage = PAGE_SIZE;
    47854790    memset(pbBuf, 0x66, cbBuf);
    47864791    if (!g_fIgnoreNoCache || hFileNoCache != NIL_RTFILE)
     
    47894794        for (size_t offBuf = 0; offBuf < cbBuf; )
    47904795        {
    4791             uint32_t const cPagesLeft   = (uint32_t)((cbBuf - offBuf) / cbPage);
     4796            uint32_t const cPagesLeft   = (uint32_t)((cbBuf - offBuf) / g_cbPage);
    47924797            uint32_t const cPagesToRead = RTRandU32Ex(1, cPagesLeft);
    4793             size_t const   cbToRead     = cPagesToRead * (size_t)cbPage;
     4798            size_t const   cbToRead     = cPagesToRead * (size_t)g_cbPage;
    47944799            size_t cbActual = 0;
    47954800            RTTESTI_CHECK_RC(RTFileRead(hFileNoCache, &pbBuf[offBuf], cbToRead, &cbActual), VINF_SUCCESS);
     
    48034808                else
    48044809                {
    4805                     memset(&pbBuf[offBuf], 0x11, cbPage);
    4806                     offBuf += cbPage;
     4810                    memset(&pbBuf[offBuf], 0x11, g_cbPage);
     4811                    offBuf += g_cbPage;
    48074812                }
    48084813            }
     
    48994904            if (iAlign & 2) /* end is page aligned */
    49004905            {
    4901                 cbLeft -= (uintptr_t)pbCur & PAGE_OFFSET_MASK;
    4902                 pbCur  -= (uintptr_t)pbCur & PAGE_OFFSET_MASK;
     4906                cbLeft -= (uintptr_t)pbCur & g_fPageOffset;
     4907                pbCur  -= (uintptr_t)pbCur & g_fPageOffset;
    49034908            }
    49044909
     
    49094914            size_t cbSeg       = cbLeft != 0 ? RTRandU32Ex(0, cbSegMax) : 0;
    49104915            if (iAlign & 1) /* start is page aligned */
    4911                 cbSeg += ((uintptr_t)pbCur - cbSeg) & PAGE_OFFSET_MASK;
     4916                cbSeg += ((uintptr_t)pbCur - cbSeg) & g_fPageOffset;
    49124917
    49134918            if (iSeg - iZeroSeg < cZeroSegs)
     
    51615166        RTTESTI_CHECK_RC(RTFileSeek(ahFiles[iFile], 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS);
    51625167
    5163         uint32_t cbPage = PAGE_SIZE;
    51645168        for (size_t offBuf = 0; offBuf < cbBuf; )
    51655169        {
    5166             uint32_t const cPagesLeft    = (uint32_t)((cbBuf - offBuf) / cbPage);
     5170            uint32_t const cPagesLeft    = (uint32_t)((cbBuf - offBuf) / g_cbPage);
    51675171            uint32_t const cPagesToWrite = RTRandU32Ex(1, cPagesLeft);
    5168             size_t const   cbToWrite     = cPagesToWrite * (size_t)cbPage;
     5172            size_t const   cbToWrite     = cPagesToWrite * (size_t)g_cbPage;
    51695173            size_t cbActual = 0;
    51705174            RTTESTI_CHECK_RC(RTFileWrite(ahFiles[iFile], &pbBuf[offBuf], cbToWrite, &cbActual), VINF_SUCCESS);
     
    51825186                else
    51835187                {
    5184                     memset(&pbBuf[offBuf], 0x11, cbPage);
    5185                     offBuf += cbPage;
     5188                    memset(&pbBuf[offBuf], 0x11, g_cbPage);
     5189                    offBuf += g_cbPage;
    51865190                }
    51875191            }
     
    52725276            if (iAlign & 2) /* end is page aligned */
    52735277            {
    5274                 cbLeft -= (uintptr_t)pbCur & PAGE_OFFSET_MASK;
    5275                 pbCur  -= (uintptr_t)pbCur & PAGE_OFFSET_MASK;
     5278                cbLeft -= (uintptr_t)pbCur & g_fPageOffset;
     5279                pbCur  -= (uintptr_t)pbCur & g_fPageOffset;
    52765280            }
    52775281
     
    52825286            size_t cbSeg       = cbLeft != 0 ? RTRandU32Ex(0, cbSegMax) : 0;
    52835287            if (iAlign & 1) /* start is page aligned */
    5284                 cbSeg += ((uintptr_t)pbCur - cbSeg) & PAGE_OFFSET_MASK;
     5288                cbSeg += ((uintptr_t)pbCur - cbSeg) & g_fPageOffset;
    52855289
    52865290            if (iSeg - iZeroSeg < cZeroSegs)
     
    53715375    PROFILE_FN(RTFileFlush(hFile1), g_nsTestRun, "RTFileFlush");
    53725376
    5373     size_t   cbBuf = PAGE_SIZE;
     5377    size_t   cbBuf = g_cbPage;
    53745378    uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf);
    53755379    RTTESTI_CHECK_RETV(pbBuf != NULL);
     
    53915395{
    53925396    uint8_t *pbCur = &pbMapping[offMapping];
    5393     for (size_t offFlush = 0; offFlush < cbFlush; offFlush += PAGE_SIZE)
     5397    for (size_t offFlush = 0; offFlush < cbFlush; offFlush += g_cbPage)
    53945398        *(size_t volatile *)&pbCur[offFlush + 8] = cbFlush;
    53955399# ifdef RT_OS_WINDOWS
     
    54735477         * Time page-ins just for fun.
    54745478         */
    5475         size_t const cPages = cbMapping >> PAGE_SHIFT;
     5479        size_t const cPages = cbMapping >> g_cPageShift;
    54765480        size_t uDummy = 0;
    54775481        uint64_t ns = RTTimeNanoTS();
    54785482        for (size_t iPage = 0; iPage < cPages; iPage++)
    5479             uDummy += ASMAtomicReadU8(&pbMapping[iPage << PAGE_SHIFT]);
     5483            uDummy += ASMAtomicReadU8(&pbMapping[iPage << g_cPageShift]);
    54805484        ns = RTTimeNanoTS() - ns;
    54815485        RTTestIValueF(ns / cPages, RTTESTUNIT_NS_PER_OCCURRENCE,  "page-in %s", s_apszStates[enmState]);
     
    55115515            if (enmState == kMMap_ReadWrite)
    55125516            {
    5513                 static size_t const s_acbFlush[] = { PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 3, PAGE_SIZE * 8, PAGE_SIZE * 16, _2M };
     5517                static size_t const s_acbFlush[] = { g_cbPage, g_cbPage * 2, g_cbPage * 3, g_cbPage * 8, g_cbPage * 16, _2M };
    55145518                for (unsigned iFlushSize = 0 ; iFlushSize < RT_ELEMENTS(s_acbFlush); iFlushSize++)
    55155519                {
     
    55495553                                RTTESTI_CHECK_RC(RTFileRead(hFileNoCache, pbBuf, cbToRead, NULL), VINF_SUCCESS);
    55505554
    5551                                 for (size_t offFlush = 0; offFlush < cbToRead; offFlush += PAGE_SIZE)
     5555                                for (size_t offFlush = 0; offFlush < cbToRead; offFlush += g_cbPage)
    55525556                                    if (*(size_t volatile *)&pbBuf[offFlush + 8] != cbFlush)
    55535557                                    {
     
    56425646     * Memory mappings without open handles (pretty common).
    56435647     */
    5644     for (uint32_t i = 0; i < 32; i++)
    5645     {
    5646         /* Create a new file, 256 KB in size, and fill it with random bytes.
    5647            Try uncached access if we can to force the page-in to do actual reads. */
    5648         char szFile2[FSPERF_MAX_PATH + 32];
    5649         memcpy(szFile2, g_szDir, g_cchDir);
    5650         RTStrPrintf(&szFile2[g_cchDir], sizeof(szFile2) - g_cchDir, "mmap-%u.noh", i);
    5651         RTFILE hFile2 = NIL_RTFILE;
    5652         int rc = (i & 3) == 3 ? VERR_TRY_AGAIN
    5653                : RTFileOpen(&hFile2, szFile2, RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_NO_CACHE);
    5654         if (RT_FAILURE(rc))
    5655         {
    5656             RTTESTI_CHECK_RC_BREAK(RTFileOpen(&hFile2, szFile2, RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE),
    5657                                    VINF_SUCCESS);
    5658         }
    5659 
    5660         static char  s_abContentUnaligned[256*1024 + PAGE_SIZE - 1];
    5661         char * const pbContent = &s_abContentUnaligned[PAGE_SIZE - ((uintptr_t)&s_abContentUnaligned[0] & PAGE_OFFSET_MASK)];
    5662         size_t const cbContent = 256*1024;
    5663         RTRandBytes(pbContent, cbContent);
    5664         RTTESTI_CHECK_RC(rc = RTFileWrite(hFile2, pbContent, cbContent, NULL), VINF_SUCCESS);
    5665         RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
    5666         if (RT_SUCCESS(rc))
    5667         {
    5668             /* Reopen the file with normal caching.  Every second time, we also
    5669                does a read-only open of it to confuse matters. */
    5670             RTFILE hFile3 = NIL_RTFILE;
    5671             if ((i & 3) == 3)
    5672                 RTTESTI_CHECK_RC(RTFileOpen(&hFile3, szFile2, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), VINF_SUCCESS);
    5673             hFile2 = NIL_RTFILE;
    5674             RTTESTI_CHECK_RC_BREAK(RTFileOpen(&hFile2, szFile2, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE),
    5675                                    VINF_SUCCESS);
    5676             if ((i & 3) == 1)
    5677                 RTTESTI_CHECK_RC(RTFileOpen(&hFile3, szFile2, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), VINF_SUCCESS);
    5678 
    5679             /* Memory map it read-write (no COW). */
     5648    char *pbContentUnaligned = (char *)RTMemAlloc(256*1024 + g_cbPage - 1);
     5649    RTTESTI_CHECK(pbContentUnaligned != NULL);
     5650    if (pbContentUnaligned)
     5651    {
     5652        for (uint32_t i = 0; i < 32; i++)
     5653        {
     5654            /* Create a new file, 256 KB in size, and fill it with random bytes.
     5655               Try uncached access if we can to force the page-in to do actual reads. */
     5656            char szFile2[FSPERF_MAX_PATH + 32];
     5657            memcpy(szFile2, g_szDir, g_cchDir);
     5658            RTStrPrintf(&szFile2[g_cchDir], sizeof(szFile2) - g_cchDir, "mmap-%u.noh", i);
     5659            RTFILE hFile2 = NIL_RTFILE;
     5660            int rc = (i & 3) == 3 ? VERR_TRY_AGAIN
     5661                   : RTFileOpen(&hFile2, szFile2, RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE | RTFILE_O_NO_CACHE);
     5662            if (RT_FAILURE(rc))
     5663            {
     5664                RTTESTI_CHECK_RC_BREAK(RTFileOpen(&hFile2, szFile2, RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE),
     5665                                       VINF_SUCCESS);
     5666            }
     5667
     5668            char * const pbContent = &pbContentUnaligned[g_cbPage - ((uintptr_t)&pbContentUnaligned[0] & g_fPageOffset)];
     5669            size_t const cbContent = 256*1024;
     5670            RTRandBytes(pbContent, cbContent);
     5671            RTTESTI_CHECK_RC(rc = RTFileWrite(hFile2, pbContent, cbContent, NULL), VINF_SUCCESS);
     5672            RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
     5673            if (RT_SUCCESS(rc))
     5674            {
     5675                /* Reopen the file with normal caching.  Every second time, we also
     5676                   does a read-only open of it to confuse matters. */
     5677                RTFILE hFile3 = NIL_RTFILE;
     5678                if ((i & 3) == 3)
     5679                    RTTESTI_CHECK_RC(RTFileOpen(&hFile3, szFile2, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), VINF_SUCCESS);
     5680                hFile2 = NIL_RTFILE;
     5681                RTTESTI_CHECK_RC_BREAK(RTFileOpen(&hFile2, szFile2, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE),
     5682                                       VINF_SUCCESS);
     5683                if ((i & 3) == 1)
     5684                    RTTESTI_CHECK_RC(RTFileOpen(&hFile3, szFile2, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE), VINF_SUCCESS);
     5685
     5686                /* Memory map it read-write (no COW). */
    56805687#ifdef RT_OS_WINDOWS
    5681             HANDLE hSection = CreateFileMapping((HANDLE)RTFileToNative(hFile2), NULL, PAGE_READWRITE, 0, cbContent, NULL);
    5682             CHECK_WINAPI_CALL(hSection != NULL);
    5683             uint8_t *pbMapping = (uint8_t *)MapViewOfFile(hSection, FILE_MAP_WRITE, 0, 0, cbContent);
    5684             CHECK_WINAPI_CALL(pbMapping != NULL);
    5685             CHECK_WINAPI_CALL(CloseHandle(hSection) == TRUE);
     5688                HANDLE hSection = CreateFileMapping((HANDLE)RTFileToNative(hFile2), NULL, PAGE_READWRITE, 0, cbContent, NULL);
     5689                CHECK_WINAPI_CALL(hSection != NULL);
     5690                uint8_t *pbMapping = (uint8_t *)MapViewOfFile(hSection, FILE_MAP_WRITE, 0, 0, cbContent);
     5691                CHECK_WINAPI_CALL(pbMapping != NULL);
     5692                CHECK_WINAPI_CALL(CloseHandle(hSection) == TRUE);
    56865693# else
    5687             uint8_t *pbMapping = (uint8_t *)mmap(NULL, cbContent, PROT_READ | PROT_WRITE, MAP_SHARED,
    5688                                                  (int)RTFileToNative(hFile2), 0);
    5689             if ((void *)pbMapping == MAP_FAILED)
    5690                 pbMapping = NULL;
    5691             RTTESTI_CHECK_MSG(pbMapping != NULL, ("errno=%s (%d)\n", strerror(errno), errno));
     5694                uint8_t *pbMapping = (uint8_t *)mmap(NULL, cbContent, PROT_READ | PROT_WRITE, MAP_SHARED,
     5695                                                     (int)RTFileToNative(hFile2), 0);
     5696                if ((void *)pbMapping == MAP_FAILED)
     5697                    pbMapping = NULL;
     5698                RTTESTI_CHECK_MSG(pbMapping != NULL, ("errno=%s (%d)\n", strerror(errno), errno));
    56925699# endif
    56935700
    5694             /* Close the file handles. */
    5695             if ((i & 7) == 7)
    5696             {
    5697                 RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS);
    5698                 hFile3 = NIL_RTFILE;
     5701                /* Close the file handles. */
     5702                if ((i & 7) == 7)
     5703                {
     5704                    RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS);
     5705                    hFile3 = NIL_RTFILE;
     5706                }
     5707                RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
     5708                if ((i & 7) == 5)
     5709                {
     5710                    RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS);
     5711                    hFile3 = NIL_RTFILE;
     5712                }
     5713                if (pbMapping)
     5714                {
     5715                    RTThreadSleep(2); /* fudge for cleanup/whatever */
     5716
     5717                    /* Page in the mapping by comparing with the content we wrote above. */
     5718                    RTTESTI_CHECK(memcmp(pbMapping, pbContent, cbContent) == 0);
     5719
     5720                    /* Now dirty everything by inverting everything. */
     5721                    size_t *puCur = (size_t *)pbMapping;
     5722                    size_t  cLeft = cbContent / sizeof(*puCur);
     5723                    while (cLeft-- > 0)
     5724                    {
     5725                        *puCur = ~*puCur;
     5726                        puCur++;
     5727                    }
     5728
     5729                    /* Sync it all. */
     5730#  ifdef RT_OS_WINDOWS
     5731                    //CHECK_WINAPI_CALL(FlushViewOfFile(pbMapping, cbContent) == TRUE);
     5732                    SetLastError(0);
     5733                    if (FlushViewOfFile(pbMapping, cbContent) != TRUE)
     5734                        RTTestIFailed("line %u, i=%u: FlushViewOfFile(%p, %#zx) failed: %u / %#x", __LINE__, i,
     5735                                      pbMapping, cbContent, GetLastError(), RTNtLastStatusValue());
     5736#  else
     5737                    RTTESTI_CHECK(msync(pbMapping, cbContent, MS_SYNC) == 0);
     5738#  endif
     5739
     5740                    /* Unmap it. */
     5741# ifdef RT_OS_WINDOWS
     5742                    CHECK_WINAPI_CALL(UnmapViewOfFile(pbMapping) == TRUE);
     5743# else
     5744                    RTTESTI_CHECK(munmap(pbMapping, cbContent) == 0);
     5745# endif
     5746                }
     5747
     5748                if (hFile3 != NIL_RTFILE)
     5749                    RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS);
    56995750            }
    5700             RTTESTI_CHECK_RC(RTFileClose(hFile2), VINF_SUCCESS);
    5701             if ((i & 7) == 5)
    5702             {
    5703                 RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS);
    5704                 hFile3 = NIL_RTFILE;
    5705             }
    5706             if (pbMapping)
    5707             {
    5708                 RTThreadSleep(2); /* fudge for cleanup/whatever */
    5709 
    5710                 /* Page in the mapping by comparing with the content we wrote above. */
    5711                 RTTESTI_CHECK(memcmp(pbMapping, pbContent, cbContent) == 0);
    5712 
    5713                 /* Now dirty everything by inverting everything. */
    5714                 size_t *puCur = (size_t *)pbMapping;
    5715                 size_t  cLeft = cbContent / sizeof(*puCur);
    5716                 while (cLeft-- > 0)
    5717                 {
    5718                     *puCur = ~*puCur;
    5719                     puCur++;
    5720                 }
    5721 
    5722                 /* Sync it all. */
    5723 #  ifdef RT_OS_WINDOWS
    5724                 //CHECK_WINAPI_CALL(FlushViewOfFile(pbMapping, cbContent) == TRUE);
    5725                 SetLastError(0);
    5726                 if (FlushViewOfFile(pbMapping, cbContent) != TRUE)
    5727                     RTTestIFailed("line %u, i=%u: FlushViewOfFile(%p, %#zx) failed: %u / %#x", __LINE__, i,
    5728                                   pbMapping, cbContent, GetLastError(), RTNtLastStatusValue());
    5729 #  else
    5730                 RTTESTI_CHECK(msync(pbMapping, cbContent, MS_SYNC) == 0);
    5731 #  endif
    5732 
    5733                 /* Unmap it. */
    5734 # ifdef RT_OS_WINDOWS
    5735                 CHECK_WINAPI_CALL(UnmapViewOfFile(pbMapping) == TRUE);
    5736 # else
    5737                 RTTESTI_CHECK(munmap(pbMapping, cbContent) == 0);
    5738 # endif
    5739             }
    5740 
    5741             if (hFile3 != NIL_RTFILE)
    5742                 RTTESTI_CHECK_RC(RTFileClose(hFile3), VINF_SUCCESS);
    5743         }
    5744         RTTESTI_CHECK_RC(RTFileDelete(szFile2), VINF_SUCCESS);
    5745     }
    5746 
     5751            RTTESTI_CHECK_RC(RTFileDelete(szFile2), VINF_SUCCESS);
     5752        }
     5753    }
    57475754
    57485755#else
     
    63876394    RTListInit(&g_ManyTreeHead);
    63886395
     6396    /* Query page size, offset mask and page shift of the system. */
     6397    g_cbPage      = RTSystemGetPageSize();
     6398    g_fPageOffset = RTSystemGetPageOffsetMask();
     6399    g_cPageShift  = RTSystemGetPageShift();
     6400
    63896401    /*
    63906402     * Default values.
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