Start probing page fault behaviour
This commit is contained in:
parent
7ce7101240
commit
9104a41e2d
1
haversine_02/.gitignore
vendored
1
haversine_02/.gitignore
vendored
@ -6,4 +6,5 @@ main
|
|||||||
genhavr
|
genhavr
|
||||||
prochavr
|
prochavr
|
||||||
reptest
|
reptest
|
||||||
|
memtest
|
||||||
timer_test*
|
timer_test*
|
||||||
|
@ -64,6 +64,13 @@ PROCSRC="./$JSON_BUILD_DIR/*.o \
|
|||||||
./src/processor/main.cpp "
|
./src/processor/main.cpp "
|
||||||
PROCOUT=prochavr
|
PROCOUT=prochavr
|
||||||
|
|
||||||
|
# MEMTESTER
|
||||||
|
MEMTESTSRC="./src/memtester/*.c"
|
||||||
|
MEMTESTOUT=memtest
|
||||||
|
|
||||||
|
(set -x ; $CC $CFLAGS $MEMTESTSRC -o $MEMTESTOUT)
|
||||||
|
echo
|
||||||
|
|
||||||
if [[ $BASIC_PROFILING == true ]] || [[ $FULL_PROFILING == true ]]; then
|
if [[ $BASIC_PROFILING == true ]] || [[ $FULL_PROFILING == true ]]; then
|
||||||
if [[ $FULL_PROFILING == true ]]; then
|
if [[ $FULL_PROFILING == true ]]; then
|
||||||
JSONFLAGS+="-DFULL_PROFILING"
|
JSONFLAGS+="-DFULL_PROFILING"
|
||||||
@ -91,7 +98,7 @@ if [[ $BASIC_PROFILING == true ]] || [[ $FULL_PROFILING == true ]]; then
|
|||||||
REPTESTSRC="./src/repetition_testing/*.cpp ./$PROF_BUILD_DIR/*.o"
|
REPTESTSRC="./src/repetition_testing/*.cpp ./$PROF_BUILD_DIR/*.o"
|
||||||
REPTESTOUT=reptest
|
REPTESTOUT=reptest
|
||||||
|
|
||||||
(set -x ; $CC $CFLAGS $REPTESTFLAGS $REPTESTSRC -o $REPTESTOUT)
|
(set -x ; $CXX $CFLAGS $REPTESTFLAGS $REPTESTSRC -o $REPTESTOUT)
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
62
haversine_02/src/memtester/main.c
Normal file
62
haversine_02/src/memtester/main.c
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#include "aliases.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#define PAGESIZE 4096
|
||||||
|
|
||||||
|
typedef struct rusage rusage_t;
|
||||||
|
|
||||||
|
u64 page_fault_count() {
|
||||||
|
rusage_t usage;
|
||||||
|
|
||||||
|
getrusage(RUSAGE_SELF, &usage);
|
||||||
|
|
||||||
|
return usage.ru_minflt + usage.ru_majflt;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
if (argc < 2 || argc > 2) {
|
||||||
|
printf("Usage: %s [NUMBER OF PAGES TO ALLOCATE]\n", argv[0]);
|
||||||
|
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 page_count = atol(argv[1]);
|
||||||
|
u64 alloc_size = page_count * PAGESIZE;
|
||||||
|
u64 touch_size = 0;
|
||||||
|
|
||||||
|
printf("Page Count,Touch Count,Fault Count,Extra Faults\n");
|
||||||
|
|
||||||
|
for (u64 touch_count = 0; touch_count <= page_count; ++touch_count) {
|
||||||
|
touch_size = touch_count * PAGESIZE;
|
||||||
|
|
||||||
|
u8 *data = (u8 *)mmap(NULL, alloc_size, PROT_READ | PROT_WRITE,
|
||||||
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
printf("Failed to allocate memory\n");
|
||||||
|
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 fault_start = page_fault_count();
|
||||||
|
|
||||||
|
for (u64 i = 0; i < touch_size; ++i) {
|
||||||
|
data[i] = (u8)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 fault_end = page_fault_count();
|
||||||
|
|
||||||
|
u64 faults = fault_end - fault_start;
|
||||||
|
|
||||||
|
printf("%lu,%lu,%lu,%ld\n", page_count, touch_count, faults,
|
||||||
|
((i64)faults - touch_count));
|
||||||
|
|
||||||
|
munmap((void *)data, alloc_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user