diff options
| author | Jan Beulich <jbeulich@suse.com> | 2012-01-24 07:03:22 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-01-24 17:25:32 -0500 |
| commit | be3de80dc2e671d9ee15e69fe9cd84d2b71e2225 (patch) | |
| tree | 8c9519ac9c6235ad8469d3f8d7ef2da660840bc5 /tools/perf/bench | |
| parent | 800eb01484b3ca1eaf4eb5186df13fb24de2db19 (diff) | |
perf bench: Also allow measuring memset()
This simply clones the respective memcpy() implementation.
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/4F16D743020000780006D735@nat28.tlf.novell.com
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/bench')
| -rw-r--r-- | tools/perf/bench/bench.h | 1 | ||||
| -rw-r--r-- | tools/perf/bench/mem-memset-arch.h | 12 | ||||
| -rw-r--r-- | tools/perf/bench/mem-memset-x86-64-asm-def.h | 12 | ||||
| -rw-r--r-- | tools/perf/bench/mem-memset-x86-64-asm.S | 6 | ||||
| -rw-r--r-- | tools/perf/bench/mem-memset.c | 291 |
5 files changed, 322 insertions, 0 deletions
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h index f7781c6267c0..a09bece6dad2 100644 --- a/tools/perf/bench/bench.h +++ b/tools/perf/bench/bench.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | extern int bench_sched_messaging(int argc, const char **argv, const char *prefix); | 4 | extern int bench_sched_messaging(int argc, const char **argv, const char *prefix); |
| 5 | extern int bench_sched_pipe(int argc, const char **argv, const char *prefix); | 5 | extern int bench_sched_pipe(int argc, const char **argv, const char *prefix); |
| 6 | extern int bench_mem_memcpy(int argc, const char **argv, const char *prefix __used); | 6 | extern int bench_mem_memcpy(int argc, const char **argv, const char *prefix __used); |
| 7 | extern int bench_mem_memset(int argc, const char **argv, const char *prefix); | ||
| 7 | 8 | ||
| 8 | #define BENCH_FORMAT_DEFAULT_STR "default" | 9 | #define BENCH_FORMAT_DEFAULT_STR "default" |
| 9 | #define BENCH_FORMAT_DEFAULT 0 | 10 | #define BENCH_FORMAT_DEFAULT 0 |
diff --git a/tools/perf/bench/mem-memset-arch.h b/tools/perf/bench/mem-memset-arch.h new file mode 100644 index 000000000000..a040fa77665b --- /dev/null +++ b/tools/perf/bench/mem-memset-arch.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | |||
| 2 | #ifdef ARCH_X86_64 | ||
| 3 | |||
| 4 | #define MEMSET_FN(fn, name, desc) \ | ||
| 5 | extern void *fn(void *, int, size_t); | ||
| 6 | |||
| 7 | #include "mem-memset-x86-64-asm-def.h" | ||
| 8 | |||
| 9 | #undef MEMSET_FN | ||
| 10 | |||
| 11 | #endif | ||
| 12 | |||
diff --git a/tools/perf/bench/mem-memset-x86-64-asm-def.h b/tools/perf/bench/mem-memset-x86-64-asm-def.h new file mode 100644 index 000000000000..a71dff97c1f5 --- /dev/null +++ b/tools/perf/bench/mem-memset-x86-64-asm-def.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | |||
| 2 | MEMSET_FN(__memset, | ||
| 3 | "x86-64-unrolled", | ||
| 4 | "unrolled memset() in arch/x86/lib/memset_64.S") | ||
| 5 | |||
| 6 | MEMSET_FN(memset_c, | ||
| 7 | "x86-64-stosq", | ||
| 8 | "movsq-based memset() in arch/x86/lib/memset_64.S") | ||
| 9 | |||
| 10 | MEMSET_FN(memset_c_e, | ||
| 11 | "x86-64-stosb", | ||
| 12 | "movsb-based memset() in arch/x86/lib/memset_64.S") | ||
diff --git a/tools/perf/bench/mem-memset-x86-64-asm.S b/tools/perf/bench/mem-memset-x86-64-asm.S new file mode 100644 index 000000000000..cb9217063776 --- /dev/null +++ b/tools/perf/bench/mem-memset-x86-64-asm.S | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #define memset MEMSET /* don't hide glibc's memset() */ | ||
| 2 | #define altinstr_replacement text | ||
| 3 | #define globl p2align 4; .globl | ||
| 4 | #define Lmemset_c globl memset_c; memset_c | ||
| 5 | #define Lmemset_c_e globl memset_c_e; memset_c_e | ||
| 6 | #include "../../../arch/x86/lib/memset_64.S" | ||
diff --git a/tools/perf/bench/mem-memset.c b/tools/perf/bench/mem-memset.c new file mode 100644 index 000000000000..9c0c6f0cba9b --- /dev/null +++ b/tools/perf/bench/mem-memset.c | |||
| @@ -0,0 +1,291 @@ | |||
| 1 | /* | ||
| 2 | * mem-memset.c | ||
| 3 | * | ||
| 4 | * memset: Simple memory set in various ways | ||
| 5 | * | ||
| 6 | * Trivial clone of mem-memcpy.c. | ||
| 7 | */ | ||
| 8 | #include <ctype.h> | ||
| 9 | |||
| 10 | #include "../perf.h" | ||
| 11 | #include "../util/util.h" | ||
| 12 | #include "../util/parse-options.h" | ||
| 13 | #include "../util/header.h" | ||
| 14 | #include "bench.h" | ||
| 15 | #include "mem-memset-arch.h" | ||
| 16 | |||
| 17 | #include <stdio.h> | ||
| 18 | #include <stdlib.h> | ||
| 19 | #include <string.h> | ||
| 20 | #include <sys/time.h> | ||
| 21 | #include <errno.h> | ||
| 22 | |||
| 23 | #define K 1024 | ||
| 24 | |||
| 25 | static const char *length_str = "1MB"; | ||
| 26 | static const char *routine = "default"; | ||
| 27 | static bool use_clock; | ||
| 28 | static int clock_fd; | ||
| 29 | static bool only_prefault; | ||
| 30 | static bool no_prefault; | ||
| 31 | |||
| 32 | static const struct option options[] = { | ||
| 33 | OPT_STRING('l', "length", &length_str, "1MB", | ||
| 34 | "Specify length of memory to copy. " | ||
| 35 | "available unit: B, MB, GB (upper and lower)"), | ||
| 36 | OPT_STRING('r', "routine", &routine, "default", | ||
| 37 | "Specify routine to copy"), | ||
| 38 | OPT_BOOLEAN('c', "clock", &use_clock, | ||
| 39 | "Use CPU clock for measuring"), | ||
| 40 | OPT_BOOLEAN('o', "only-prefault", &only_prefault, | ||
| 41 | "Show only the result with page faults before memset()"), | ||
| 42 | OPT_BOOLEAN('n', "no-prefault", &no_prefault, | ||
| 43 | "Show only the result without page faults before memset()"), | ||
| 44 | OPT_END() | ||
| 45 | }; | ||
| 46 | |||
| 47 | typedef void *(*memset_t)(void *, int, size_t); | ||
| 48 | |||
| 49 | struct routine { | ||
| 50 | const char *name; | ||
| 51 | const char *desc; | ||
| 52 | memset_t fn; | ||
| 53 | }; | ||
| 54 | |||
| 55 | static const struct routine routines[] = { | ||
| 56 | { "default", | ||
| 57 | "Default memset() provided by glibc", | ||
| 58 | memset }, | ||
| 59 | #ifdef ARCH_X86_64 | ||
| 60 | |||
| 61 | #define MEMSET_FN(fn, name, desc) { name, desc, fn }, | ||
| 62 | #include "mem-memset-x86-64-asm-def.h" | ||
| 63 | #undef MEMSET_FN | ||
| 64 | |||
| 65 | #endif | ||
| 66 | |||
| 67 | { NULL, | ||
| 68 | NULL, | ||
| 69 | NULL } | ||
| 70 | }; | ||
| 71 | |||
| 72 | static const char * const bench_mem_memset_usage[] = { | ||
| 73 | "perf bench mem memset <options>", | ||
| 74 | NULL | ||
| 75 | }; | ||
| 76 | |||
| 77 | static struct perf_event_attr clock_attr = { | ||
| 78 | .type = PERF_TYPE_HARDWARE, | ||
| 79 | .config = PERF_COUNT_HW_CPU_CYCLES | ||
| 80 | }; | ||
| 81 | |||
| 82 | static void init_clock(void) | ||
| 83 | { | ||
| 84 | clock_fd = sys_perf_event_open(&clock_attr, getpid(), -1, -1, 0); | ||
| 85 | |||
| 86 | if (clock_fd < 0 && errno == ENOSYS) | ||
| 87 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); | ||
| 88 | else | ||
| 89 | BUG_ON(clock_fd < 0); | ||
| 90 | } | ||
| 91 | |||
| 92 | static u64 get_clock(void) | ||
| 93 | { | ||
| 94 | int ret; | ||
| 95 | u64 clk; | ||
| 96 | |||
| 97 | ret = read(clock_fd, &clk, sizeof(u64)); | ||
| 98 | BUG_ON(ret != sizeof(u64)); | ||
| 99 | |||
| 100 | return clk; | ||
| 101 | } | ||
| 102 | |||
| 103 | static double timeval2double(struct timeval *ts) | ||
| 104 | { | ||
| 105 | return (double)ts->tv_sec + | ||
| 106 | (double)ts->tv_usec / (double)1000000; | ||
| 107 | } | ||
| 108 | |||
| 109 | static void alloc_mem(void **dst, size_t length) | ||
| 110 | { | ||
| 111 | *dst = zalloc(length); | ||
| 112 | if (!dst) | ||
| 113 | die("memory allocation failed - maybe length is too large?\n"); | ||
| 114 | } | ||
| 115 | |||
| 116 | static u64 do_memset_clock(memset_t fn, size_t len, bool prefault) | ||
| 117 | { | ||
| 118 | u64 clock_start = 0ULL, clock_end = 0ULL; | ||
| 119 | void *dst = NULL; | ||
| 120 | |||
| 121 | alloc_mem(&dst, len); | ||
| 122 | |||
| 123 | if (prefault) | ||
| 124 | fn(dst, -1, len); | ||
| 125 | |||
| 126 | clock_start = get_clock(); | ||
| 127 | fn(dst, 0, len); | ||
| 128 | clock_end = get_clock(); | ||
| 129 | |||
| 130 | free(dst); | ||
| 131 | return clock_end - clock_start; | ||
| 132 | } | ||
| 133 | |||
| 134 | static double do_memset_gettimeofday(memset_t fn, size_t len, bool prefault) | ||
| 135 | { | ||
| 136 | struct timeval tv_start, tv_end, tv_diff; | ||
| 137 | void *dst = NULL; | ||
| 138 | |||
| 139 | alloc_mem(&dst, len); | ||
| 140 | |||
