Created
June 9, 2014 18:21
-
-
Save markpapadakis/993a1ae710b80684ed83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (const auto cnt = rowsToWarmup.Size()) | |
| { | |
| int fd = open(finalPath, O_RDONLY|O_LARGEFILE); | |
| const row *const all = rowsToWarmup.Values(); | |
| const auto shift = __builtin_ffs(getpagesize()) - 1; | |
| volatile uint32_t ac = 0; | |
| const auto before = Timings::Microseconds::Tick(); | |
| if (unlikely(fd == -1)) | |
| { | |
| IMPLEMENT_ME; | |
| } | |
| const auto fileSize = lseek64(fd, 0, SEEK_END); | |
| if (unlikely(fileSize == (decltype(fileSize))-1)) | |
| { | |
| IMPLEMENT_ME; | |
| } | |
| void *const fileData = mmap(NULL, fileSize, PROT_READ, MAP_SHARED, fd, 0); | |
| (void)close(fd); | |
| if (unlikely(fileData == MAP_FAILED)) | |
| { | |
| IMPLEMENT_ME; | |
| } | |
| (void)madvise(fileData, fileSize, MADV_SEQUENTIAL); | |
| const uint8_t *const data = (uint8_t *)fileData; | |
| for (uint32_t i = 0; i != cnt; ) | |
| { | |
| const uint32_t page = all[i].offset >> shift; | |
| ac += data[(page << shift) + 1]; | |
| for (++i; (all[i].offset >> shift) == page; ++i) | |
| continue; | |
| } | |
| (void)srand(ac); // do something with ac so that compiler will not eliminate ac access completely | |
| (void)munmap(fileData, fileSize); | |
| SwitchDebug("Took %.3f to warmup\n", Timings::Microseconds::ToSecondsF(Timings::Microseconds::Tick() - before)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment