- Timestamp:
- Oct 30, 2023 9:28:02 AM (16 months ago)
- svn:sync-xref-src-repo-rev:
- 159734
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/fs/FsPerf.cpp
r99775 r101645 480 480 /** The test handle. */ 481 481 static RTTEST g_hTest; 482 /** The page size of the system. */ 483 static uint32_t g_cbPage; 484 /** Page offset mask. */ 485 static uintptr_t g_fPageOffset; 486 /** Page shift in bits. */ 487 static uint32_t g_cPageShift; 482 488 /** The number of nanoseconds a RTTimeNanoTS call takes. 483 489 * This is used for adjusting loop count estimates. */ … … 3914 3920 RTTestISub("sendfile"); 3915 3921 # 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); 3917 3923 # 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); 3919 3925 # endif 3920 3926 signal(SIGPIPE, SIG_IGN); … … 3959 3965 3960 3966 cbToSend /= 2; 3961 } while (cbToSend >= PAGE_SIZE&& ((unsigned)bFiller - 0xf7U) < 64);3967 } while (cbToSend >= g_cbPage && ((unsigned)bFiller - 0xf7U) < 64); 3962 3968 3963 3969 /* … … 4174 4180 } 4175 4181 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); 4177 4183 signal(SIGPIPE, SIG_IGN); 4178 4184 … … 4216 4222 4217 4223 cbToSend /= 2; 4218 } while (cbToSend >= PAGE_SIZE&& ((unsigned)bFiller - 0xf7U) < 64);4224 } while (cbToSend >= g_cbPage && ((unsigned)bFiller - 0xf7U) < 64); 4219 4225 4220 4226 /* … … 4398 4404 } 4399 4405 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); 4401 4407 signal(SIGPIPE, SIG_IGN); 4402 4408 … … 4782 4788 * Do uncached access, must be page aligned. 4783 4789 */ 4784 uint32_t cbPage = PAGE_SIZE;4785 4790 memset(pbBuf, 0x66, cbBuf); 4786 4791 if (!g_fIgnoreNoCache || hFileNoCache != NIL_RTFILE) … … 4789 4794 for (size_t offBuf = 0; offBuf < cbBuf; ) 4790 4795 { 4791 uint32_t const cPagesLeft = (uint32_t)((cbBuf - offBuf) / cbPage);4796 uint32_t const cPagesLeft = (uint32_t)((cbBuf - offBuf) / g_cbPage); 4792 4797 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; 4794 4799 size_t cbActual = 0; 4795 4800 RTTESTI_CHECK_RC(RTFileRead(hFileNoCache, &pbBuf[offBuf], cbToRead, &cbActual), VINF_SUCCESS); … … 4803 4808 else 4804 4809 { 4805 memset(&pbBuf[offBuf], 0x11, cbPage);4806 offBuf += cbPage;4810 memset(&pbBuf[offBuf], 0x11, g_cbPage); 4811 offBuf += g_cbPage; 4807 4812 } 4808 4813 } … … 4899 4904 if (iAlign & 2) /* end is page aligned */ 4900 4905 { 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; 4903 4908 } 4904 4909 … … 4909 4914 size_t cbSeg = cbLeft != 0 ? RTRandU32Ex(0, cbSegMax) : 0; 4910 4915 if (iAlign & 1) /* start is page aligned */ 4911 cbSeg += ((uintptr_t)pbCur - cbSeg) & PAGE_OFFSET_MASK;4916 cbSeg += ((uintptr_t)pbCur - cbSeg) & g_fPageOffset; 4912 4917 4913 4918 if (iSeg - iZeroSeg < cZeroSegs) … … 5161 5166 RTTESTI_CHECK_RC(RTFileSeek(ahFiles[iFile], 0, RTFILE_SEEK_BEGIN, NULL), VINF_SUCCESS); 5162 5167 5163 uint32_t cbPage = PAGE_SIZE;5164 5168 for (size_t offBuf = 0; offBuf < cbBuf; ) 5165 5169 { 5166 uint32_t const cPagesLeft = (uint32_t)((cbBuf - offBuf) / cbPage);5170 uint32_t const cPagesLeft = (uint32_t)((cbBuf - offBuf) / g_cbPage); 5167 5171 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; 5169 5173 size_t cbActual = 0; 5170 5174 RTTESTI_CHECK_RC(RTFileWrite(ahFiles[iFile], &pbBuf[offBuf], cbToWrite, &cbActual), VINF_SUCCESS); … … 5182 5186 else 5183 5187 { 5184 memset(&pbBuf[offBuf], 0x11, cbPage);5185 offBuf += cbPage;5188 memset(&pbBuf[offBuf], 0x11, g_cbPage); 5189 offBuf += g_cbPage; 5186 5190 } 5187 5191 } … … 5272 5276 if (iAlign & 2) /* end is page aligned */ 5273 5277 { 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; 5276 5280 } 5277 5281 … … 5282 5286 size_t cbSeg = cbLeft != 0 ? RTRandU32Ex(0, cbSegMax) : 0; 5283 5287 if (iAlign & 1) /* start is page aligned */ 5284 cbSeg += ((uintptr_t)pbCur - cbSeg) & PAGE_OFFSET_MASK;5288 cbSeg += ((uintptr_t)pbCur - cbSeg) & g_fPageOffset; 5285 5289 5286 5290 if (iSeg - iZeroSeg < cZeroSegs) … … 5371 5375 PROFILE_FN(RTFileFlush(hFile1), g_nsTestRun, "RTFileFlush"); 5372 5376 5373 size_t cbBuf = PAGE_SIZE;5377 size_t cbBuf = g_cbPage; 5374 5378 uint8_t *pbBuf = (uint8_t *)RTMemPageAlloc(cbBuf); 5375 5379 RTTESTI_CHECK_RETV(pbBuf != NULL); … … 5391 5395 { 5392 5396 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) 5394 5398 *(size_t volatile *)&pbCur[offFlush + 8] = cbFlush; 5395 5399 # ifdef RT_OS_WINDOWS … … 5473 5477 * Time page-ins just for fun. 5474 5478 */ 5475 size_t const cPages = cbMapping >> PAGE_SHIFT;5479 size_t const cPages = cbMapping >> g_cPageShift; 5476 5480 size_t uDummy = 0; 5477 5481 uint64_t ns = RTTimeNanoTS(); 5478 5482 for (size_t iPage = 0; iPage < cPages; iPage++) 5479 uDummy += ASMAtomicReadU8(&pbMapping[iPage << PAGE_SHIFT]);5483 uDummy += ASMAtomicReadU8(&pbMapping[iPage << g_cPageShift]); 5480 5484 ns = RTTimeNanoTS() - ns; 5481 5485 RTTestIValueF(ns / cPages, RTTESTUNIT_NS_PER_OCCURRENCE, "page-in %s", s_apszStates[enmState]); … … 5511 5515 if (enmState == kMMap_ReadWrite) 5512 5516 { 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 }; 5514 5518 for (unsigned iFlushSize = 0 ; iFlushSize < RT_ELEMENTS(s_acbFlush); iFlushSize++) 5515 5519 { … … 5549 5553 RTTESTI_CHECK_RC(RTFileRead(hFileNoCache, pbBuf, cbToRead, NULL), VINF_SUCCESS); 5550 5554 5551 for (size_t offFlush = 0; offFlush < cbToRead; offFlush += PAGE_SIZE)5555 for (size_t offFlush = 0; offFlush < cbToRead; offFlush += g_cbPage) 5552 5556 if (*(size_t volatile *)&pbBuf[offFlush + 8] != cbFlush) 5553 5557 { … … 5642 5646 * Memory mappings without open handles (pretty common). 5643 5647 */ 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). */ 5680 5687 #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); 5686 5693 # 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)); 5692 5699 # endif 5693 5700 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); 5699 5750 } 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 } 5747 5754 5748 5755 #else … … 6387 6394 RTListInit(&g_ManyTreeHead); 6388 6395 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 6389 6401 /* 6390 6402 * Default values.
Note:
See TracChangeset
for help on using the changeset viewer.