2 * Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
14 #define ITERATIONS 5000000
16 #define MEMSIZE (1UL << 27)
17 #define PAGE_SIZE (1UL << 16)
18 #define CHUNK_COUNT (MEMSIZE/PAGE_SIZE)
21 static int iterations = ITERATIONS;
23 static struct option options[] = {
24 { "pgfault", no_argument, &pg_fault, 1 },
25 { "iterations", required_argument, 0, 'i' },
29 static void usage(void)
31 printf("mmap_bench <--pgfault> <--iterations count>\n");
36 struct timespec ts_start, ts_end;
37 unsigned long i = iterations;
39 clock_gettime(CLOCK_MONOTONIC, &ts_start);
42 char *c = mmap(NULL, MEMSIZE, PROT_READ|PROT_WRITE,
43 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
44 FAIL_IF(c == MAP_FAILED);
47 for (count = 0; count < CHUNK_COUNT; count++)
53 clock_gettime(CLOCK_MONOTONIC, &ts_end);
55 printf("time = %.6f\n", ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9);
60 int main(int argc, char *argv[])
66 c = getopt_long(argc, argv, "", options, &option_index);
73 if (options[option_index].flag != 0)
80 iterations = atoi(optarg);
88 test_harness_set_timeout(300);
89 return test_harness(test_mmap, "mmap_bench");