accel/qaic: Add AIC200 support
[drm/drm-misc.git] / tools / testing / selftests / powerpc / benchmarks / mmap_bench.c
blob2525adf64342983fe41f3aa146b1f1d3490eabf1
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp.
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <sys/mman.h>
9 #include <time.h>
10 #include <getopt.h>
12 #include "utils.h"
14 #define ITERATIONS 5000000
16 #define MEMSIZE (1UL << 27)
17 #define PAGE_SIZE (1UL << 16)
18 #define CHUNK_COUNT (MEMSIZE/PAGE_SIZE)
20 static int pg_fault;
21 static int iterations = ITERATIONS;
23 static struct option options[] = {
24 { "pgfault", no_argument, &pg_fault, 1 },
25 { "iterations", required_argument, 0, 'i' },
26 { 0, },
29 static void usage(void)
31 printf("mmap_bench <--pgfault> <--iterations count>\n");
34 int test_mmap(void)
36 struct timespec ts_start, ts_end;
37 unsigned long i = iterations;
39 clock_gettime(CLOCK_MONOTONIC, &ts_start);
41 while (i--) {
42 char *c = mmap(NULL, MEMSIZE, PROT_READ|PROT_WRITE,
43 MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
44 FAIL_IF(c == MAP_FAILED);
45 if (pg_fault) {
46 int count;
47 for (count = 0; count < CHUNK_COUNT; count++)
48 c[count << 16] = 'c';
50 munmap(c, MEMSIZE);
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);
57 return 0;
60 int main(int argc, char *argv[])
62 signed char c;
63 while (1) {
64 int option_index = 0;
66 c = getopt_long(argc, argv, "", options, &option_index);
68 if (c == -1)
69 break;
71 switch (c) {
72 case 0:
73 if (options[option_index].flag != 0)
74 break;
76 usage();
77 exit(1);
78 break;
79 case 'i':
80 iterations = atoi(optarg);
81 break;
82 default:
83 usage();
84 exit(1);
88 test_harness_set_timeout(300);
89 return test_harness(test_mmap, "mmap_bench");