~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/benchmarks/mmap_bench.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp.
  4  */
  5 
  6 #include <stdio.h>
  7 #include <stdlib.h>
  8 #include <sys/mman.h>
  9 #include <time.h>
 10 #include <getopt.h>
 11 
 12 #include "utils.h"
 13 
 14 #define ITERATIONS 5000000
 15 
 16 #define MEMSIZE (1UL << 27)
 17 #define PAGE_SIZE (1UL << 16)
 18 #define CHUNK_COUNT (MEMSIZE/PAGE_SIZE)
 19 
 20 static int pg_fault;
 21 static int iterations = ITERATIONS;
 22 
 23 static struct option options[] = {
 24         { "pgfault", no_argument, &pg_fault, 1 },
 25         { "iterations", required_argument, 0, 'i' },
 26         { 0, },
 27 };
 28 
 29 static void usage(void)
 30 {
 31         printf("mmap_bench <--pgfault> <--iterations count>\n");
 32 }
 33 
 34 int test_mmap(void)
 35 {
 36         struct timespec ts_start, ts_end;
 37         unsigned long i = iterations;
 38 
 39         clock_gettime(CLOCK_MONOTONIC, &ts_start);
 40 
 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';
 49                 }
 50                 munmap(c, MEMSIZE);
 51         }
 52 
 53         clock_gettime(CLOCK_MONOTONIC, &ts_end);
 54 
 55         printf("time = %.6f\n", ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9);
 56 
 57         return 0;
 58 }
 59 
 60 int main(int argc, char *argv[])
 61 {
 62         signed char c;
 63         while (1) {
 64                 int option_index = 0;
 65 
 66                 c = getopt_long(argc, argv, "", options, &option_index);
 67 
 68                 if (c == -1)
 69                         break;
 70 
 71                 switch (c) {
 72                 case 0:
 73                         if (options[option_index].flag != 0)
 74                                 break;
 75 
 76                         usage();
 77                         exit(1);
 78                         break;
 79                 case 'i':
 80                         iterations = atoi(optarg);
 81                         break;
 82                 default:
 83                         usage();
 84                         exit(1);
 85                 }
 86         }
 87 
 88         test_harness_set_timeout(300);
 89         return test_harness(test_mmap, "mmap_bench");
 90 }
 91 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php