diff options
author | Michael Ellerman <mpe@ellerman.id.au> | 2016-06-02 08:02:01 -0400 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2016-07-05 09:49:50 -0400 |
commit | 0c63e8b7b97fb72ef38c8edbfbe751d3602e03a1 (patch) | |
tree | 9302619bd2b3c51930f538445b499ef302142df1 | |
parent | f2418ae8a81760b4dec8d5e3e7f1faf45c422e9d (diff) |
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>
4 files changed, 86 insertions, 1 deletions
diff --git a/tools/testing/selftests/powerpc/benchmarks/.gitignore b/tools/testing/selftests/powerpc/benchmarks/.gitignore index 6fa673316ac2..bce49ebd869e 100644 --- a/tools/testing/selftests/powerpc/benchmarks/.gitignore +++ b/tools/testing/selftests/powerpc/benchmarks/.gitignore | |||
@@ -1,2 +1,4 @@ | |||
1 | gettimeofday | 1 | gettimeofday |
2 | context_switch | 2 | context_switch |
3 | mmap_bench | ||
4 | futex_bench \ No newline at end of file | ||
diff --git a/tools/testing/selftests/powerpc/benchmarks/Makefile b/tools/testing/selftests/powerpc/benchmarks/Makefile index 6816fc2140cb..a9adfb7de78f 100644 --- a/tools/testing/selftests/powerpc/benchmarks/Makefile +++ b/tools/testing/selftests/powerpc/benchmarks/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | TEST_PROGS := gettimeofday context_switch | 1 | TEST_PROGS := gettimeofday context_switch mmap_bench futex_bench |
2 | 2 | ||
3 | CFLAGS += -O2 | 3 | CFLAGS += -O2 |
4 | 4 | ||
diff --git a/tools/testing/selftests/powerpc/benchmarks/futex_bench.c b/tools/testing/selftests/powerpc/benchmarks/futex_bench.c new file mode 100644 index 000000000000..2fc711d9150d --- /dev/null +++ b/tools/testing/selftests/powerpc/benchmarks/futex_bench.c | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp. | ||
3 | * Licensed under GPLv2. | ||
4 | */ | ||
5 | |||
6 | #define _GNU_SOURCE | ||
7 | |||
8 | #include <stdio.h> | ||
9 | #include <sys/syscall.h> | ||
10 | #include <time.h> | ||
11 | #include <unistd.h> | ||
12 | #include <linux/futex.h> | ||
13 | |||
14 | #include "utils.h" | ||
15 | |||
16 | #define ITERATIONS 100000000 | ||
17 | |||
18 | #define futex(A, B, C, D, E, F) syscall(__NR_futex, A, B, C, D, E, F) | ||
19 | |||
20 | int test_futex(void) | ||
21 | { | ||
22 | struct timespec ts_start, ts_end; | ||
23 | unsigned long i = ITERATIONS; | ||
24 | |||
25 | clock_gettime(CLOCK_MONOTONIC, &ts_start); | ||
26 | |||
27 | while (i--) { | ||
28 | unsigned int addr = 0; | ||
29 | futex(&addr, FUTEX_WAKE, 1, NULL, NULL, 0); | ||
30 | } | ||
31 | |||
32 | clock_gettime(CLOCK_MONOTONIC, &ts_end); | ||
33 | |||
34 | printf("time = %.6f\n", ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9); | ||
35 | |||
36 | return 0; | ||
37 | } | ||
38 | |||
39 | int main(void) | ||
40 | { | ||
41 | return test_harness(test_futex, "futex_bench"); | ||
42 | } | ||
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 @@ | |||
1 | /* | ||
2 | * Copyright 2016, Anton Blanchard, Michael Ellerman, IBM Corp. | ||
3 | * Licensed under GPLv2. | ||
4 | */ | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <sys/mman.h> | ||
9 | #include <time.h> | ||
10 | |||
11 | #include "utils.h" | ||
12 | |||
13 | #define ITERATIONS 5000000 | ||
14 | |||
15 | #define MEMSIZE (128 * 1024 * 1024) | ||
16 | |||
17 | int test_mmap(void) | ||
18 | { | ||
19 | struct timespec ts_start, ts_end; | ||
20 | unsigned long i = ITERATIONS; | ||
21 | |||
22 | clock_gettime(CLOCK_MONOTONIC, &ts_start); | ||
23 | |||
24 | while (i--) { | ||
25 | char *c = mmap(NULL, MEMSIZE, PROT_READ|PROT_WRITE, | ||
26 | MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); | ||
27 | FAIL_IF(c == MAP_FAILED); | ||
28 | munmap(c, MEMSIZE); | ||
29 | } | ||
30 | |||
31 | clock_gettime(CLOCK_MONOTONIC, &ts_end); | ||
32 | |||
33 | printf("time = %.6f\n", ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9); | ||
34 | |||
35 | return 0; | ||
36 | } | ||
37 | |||
38 | int main(void) | ||
39 | { | ||
40 | return test_harness(test_mmap, "mmap_bench"); | ||
41 | } | ||