aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/powerpc/benchmarks/mmap_bench.c
diff options
context:
space:
mode:
authorMichael Ellerman <mpe@ellerman.id.au>2016-06-02 22:02:01 +1000
committerMichael Ellerman <mpe@ellerman.id.au>2016-07-05 23:49:50 +1000
commit0c63e8b7b97fb72ef38c8edbfbe751d3602e03a1 (patch)
tree9302619bd2b3c51930f538445b499ef302142df1 /tools/testing/selftests/powerpc/benchmarks/mmap_bench.c
parentselftests/powerpc: Fix generation of vector instructions/types in context_switch (diff)
downloadlinux-dev-0c63e8b7b97fb72ef38c8edbfbe751d3602e03a1.tar.xz
linux-dev-0c63e8b7b97fb72ef38c8edbfbe751d3602e03a1.zip
selftests/powerpc: Import Anton's mmap & futex micro benchmarks
These are useful little loops for smoke testing performance. Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'tools/testing/selftests/powerpc/benchmarks/mmap_bench.c')
-rw-r--r--tools/testing/selftests/powerpc/benchmarks/mmap_bench.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/testing/selftests/powerpc/benchmarks/mmap_bench.c b/tools/testing/selftests/powerpc/benchmarks/mmap_bench.c
new file mode 100644
index 000000000000..8d084a2d6e74
--- /dev/null
+++ b/tools/testing/selftests/powerpc/benchmarks/mmap_bench.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp.
+ * Licensed under GPLv2.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <time.h>
+
+#include "utils.h"
+
+#define ITERATIONS 5000000
+
+#define MEMSIZE (128 * 1024 * 1024)
+
+int test_mmap(void)
+{
+ struct timespec ts_start, ts_end;
+ unsigned long i = ITERATIONS;
+
+ clock_gettime(CLOCK_MONOTONIC, &ts_start);
+
+ while (i--) {
+ char *c = mmap(NULL, MEMSIZE, PROT_READ|PROT_WRITE,
+ MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+ FAIL_IF(c == MAP_FAILED);
+ munmap(c, MEMSIZE);
+ }
+
+ clock_gettime(CLOCK_MONOTONIC, &ts_end);
+
+ printf("time = %.6f\n", ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9);
+
+ return 0;
+}
+
+int main(void)
+{
+ return test_harness(test_mmap, "mmap_bench");
+}