]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
selftests/powerpc: Import Anton's mmap & futex micro benchmarks
authorMichael Ellerman <mpe@ellerman.id.au>
Thu, 2 Jun 2016 12:02:01 +0000 (22:02 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 5 Jul 2016 13:49:50 +0000 (23:49 +1000)
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>
tools/testing/selftests/powerpc/benchmarks/.gitignore
tools/testing/selftests/powerpc/benchmarks/Makefile
tools/testing/selftests/powerpc/benchmarks/futex_bench.c [new file with mode: 0644]
tools/testing/selftests/powerpc/benchmarks/mmap_bench.c [new file with mode: 0644]

index 6fa673316ac2caf6367459a4604446ea1cf8bee6..bce49ebd869ecbbaaf689c92d0dbdadaa6d4e1f0 100644 (file)
@@ -1,2 +1,4 @@
 gettimeofday
 context_switch
+mmap_bench
+futex_bench
\ No newline at end of file
index 6816fc2140cb318a002e9a8138701664dbc7e65d..a9adfb7de78f3f163e5090c9c1ce7690e64b1afe 100644 (file)
@@ -1,4 +1,4 @@
-TEST_PROGS := gettimeofday context_switch
+TEST_PROGS := gettimeofday context_switch mmap_bench futex_bench
 
 CFLAGS += -O2
 
diff --git a/tools/testing/selftests/powerpc/benchmarks/futex_bench.c b/tools/testing/selftests/powerpc/benchmarks/futex_bench.c
new file mode 100644 (file)
index 0000000..2fc711d
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp.
+ * Licensed under GPLv2.
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <sys/syscall.h>
+#include <time.h>
+#include <unistd.h>
+#include <linux/futex.h>
+
+#include "utils.h"
+
+#define ITERATIONS 100000000
+
+#define futex(A, B, C, D, E, F)         syscall(__NR_futex, A, B, C, D, E, F)
+
+int test_futex(void)
+{
+       struct timespec ts_start, ts_end;
+       unsigned long i = ITERATIONS;
+
+       clock_gettime(CLOCK_MONOTONIC, &ts_start);
+
+       while (i--) {
+               unsigned int addr = 0;
+               futex(&addr, FUTEX_WAKE, 1, NULL, NULL, 0);
+       }
+
+       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_futex, "futex_bench");
+}
diff --git a/tools/testing/selftests/powerpc/benchmarks/mmap_bench.c b/tools/testing/selftests/powerpc/benchmarks/mmap_bench.c
new file mode 100644 (file)
index 0000000..8d084a2
--- /dev/null
@@ -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");
+}