add page fault prober
This commit is contained in:
parent
a7d0e49ab9
commit
46578d7ce9
4
Makefile
4
Makefile
@ -22,5 +22,9 @@ build/guess_cpu_speed: src/guess_cpu_speed.c src/timer.c
|
|||||||
mkdir -p build
|
mkdir -p build
|
||||||
gcc -o build/guess_cpu_speed src/guess_cpu_speed.c $(CFLAGS)
|
gcc -o build/guess_cpu_speed src/guess_cpu_speed.c $(CFLAGS)
|
||||||
|
|
||||||
|
build/page_fault_prober: src/page_fault_prober.c
|
||||||
|
mkdir -p build
|
||||||
|
gcc -o build/page_fault_prober src/page_fault_prober.c $(CFLAGS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -r build
|
rm -r build
|
||||||
|
49
src/page_fault_prober.c
Normal file
49
src/page_fault_prober.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
#define RPROF_IMPLEMENTATION
|
||||||
|
#include "rprof.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
if (argc != 3) {
|
||||||
|
printf("Usage: %s <output-file> <page-count>\n", argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t page_size = sysconf(_SC_PAGESIZE);
|
||||||
|
char *output_path = argv[1];
|
||||||
|
uint64_t page_count = atol(argv[2]);
|
||||||
|
|
||||||
|
char *memory = mmap(NULL, page_size * page_count, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, 0, 0);
|
||||||
|
if (memory == NULL) {
|
||||||
|
perror("mmap");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// char *memory = malloc(page_size * page_count);
|
||||||
|
// if (memory == NULL) {
|
||||||
|
// perror("malloc");
|
||||||
|
// return -1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
FILE *f = fopen(output_path, "w");
|
||||||
|
if (f == NULL) {
|
||||||
|
perror("fopen");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < page_count; i++) {
|
||||||
|
uint64_t fault_count = read_page_faults();
|
||||||
|
memory[i*page_size] = i;
|
||||||
|
uint64_t page_fault_diff = read_page_faults() - fault_count;
|
||||||
|
|
||||||
|
char line[128];
|
||||||
|
int line_length = snprintf(line, sizeof(line), "%d,%lu\n", i+1, page_fault_diff);
|
||||||
|
fwrite(line, line_length, 1, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -71,15 +71,6 @@ void print_repetition_time(char *label, float cpu_time, uint64_t bytes, uint64_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t read_page_faults() {
|
|
||||||
// NOTE: ru_minflt the number of page faults serviced without any I/O activity.
|
|
||||||
// ru_majflt the number of page faults serviced that required I/O activity.
|
|
||||||
struct rusage usage = {};
|
|
||||||
getrusage(RUSAGE_SELF, &usage);
|
|
||||||
int Result = usage.ru_minflt + usage.ru_majflt;
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool repetition_tester_continue(struct repetition_tester *tester, struct repetition_results *results) {
|
bool repetition_tester_continue(struct repetition_tester *tester, struct repetition_results *results) {
|
||||||
if (tester->state != STATE_RUNNING) {
|
if (tester->state != STATE_RUNNING) {
|
||||||
return false;
|
return false;
|
||||||
|
13
src/rprof.h
13
src/rprof.h
@ -142,6 +142,19 @@ static uint64_t rprof_get_cpu_timer_hz(uint64_t measure_time_ms)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------ Page faults -------------------------
|
||||||
|
|
||||||
|
#include <sys/resource.h>
|
||||||
|
|
||||||
|
uint64_t read_page_faults() {
|
||||||
|
// NOTE: ru_minflt the number of page faults serviced without any I/O activity.
|
||||||
|
// ru_majflt the number of page faults serviced that required I/O activity.
|
||||||
|
struct rusage usage = {};
|
||||||
|
getrusage(RUSAGE_SELF, &usage);
|
||||||
|
int Result = usage.ru_minflt + usage.ru_majflt;
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------ Profiling -------------------------
|
// ------------------------ Profiling -------------------------
|
||||||
|
|
||||||
void rprof_init()
|
void rprof_init()
|
||||||
|
@ -166,7 +166,5 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("page faults: %lu\n", read_page_faults());
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user