1 /*
2  * Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp.
3  * Licensed under GPLv2.
4  */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <sys/mman.h>
9 #include <time.h>
10 
11 #include "utils.h"
12 
13 #define ITERATIONS 5000000
14 
15 #define MEMSIZE (128 * 1024 * 1024)
16 
17 int test_mmap(void)
18 {
19 	struct timespec ts_start, ts_end;
20 	unsigned long i = ITERATIONS;
21 
22 	clock_gettime(CLOCK_MONOTONIC, &ts_start);
23 
24 	while (i--) {
25 		char *c = mmap(NULL, MEMSIZE, PROT_READ|PROT_WRITE,
26 			       MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
27 		FAIL_IF(c == MAP_FAILED);
28 		munmap(c, MEMSIZE);
29 	}
30 
31 	clock_gettime(CLOCK_MONOTONIC, &ts_end);
32 
33 	printf("time = %.6f\n", ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9);
34 
35 	return 0;
36 }
37 
38 int main(void)
39 {
40 	return test_harness(test_mmap, "mmap_bench");
41 }
42