diff options
| author | Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp> | 2010-11-25 02:04:52 -0500 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2010-11-26 02:15:57 -0500 |
| commit | 49ce8fc651794878189fd5f273228832cdfb5be9 (patch) | |
| tree | 1563fe681d3ff4f9d5a31e8a0745358bf96b1d1b /tools/perf/bench | |
| parent | d9cf837ef9629ab34167bd6fc0141383ddb8813a (diff) | |
perf bench: Print both of prefaulted and no prefaulted results by default
After applying this patch, perf bench mem memcpy prints
both of prefualted and without prefaulted score of memcpy().
New options --no-prefault and --only-prefault are added
to print single result, mainly for scripting usage.
Usage example:
| mitake@X201i:~/linux/.../tools/perf% ./perf bench mem memcpy -l 500MB
| # Running mem/memcpy benchmark...
| # Copying 500MB Bytes ...
|
| 634.969014 MB/Sec
| 4.828062 GB/Sec (with prefault)
| mitake@X201i:~/linux/.../tools/perf% ./perf bench mem memcpy -l 500MB --only-prefault
| # Running mem/memcpy benchmark...
| # Copying 500MB Bytes ...
|
| 4.705192 GB/Sec (with prefault)
| mitake@X201i:~/linux/.../tools/perf% ./perf bench mem memcpy -l 500MB --no-prefault
| # Running mem/memcpy benchmark...
| # Copying 500MB Bytes ...
|
| 642.725568 MB/Sec
Signed-off-by: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
Cc: h.mitake@gmail.com
Cc: Miao Xie <miaox@cn.fujitsu.com>
Cc: Ma Ling <ling.ma@intel.com>
Cc: Zhao Yakui <yakui.zhao@intel.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Andi Kleen <andi@firstfloor.org>
LKML-Reference: <1290668693-27068-1-git-send-email-mitake@dcl.info.waseda.ac.jp>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/bench')
| -rw-r--r-- | tools/perf/bench/mem-memcpy.c | 219 |
1 files changed, 162 insertions, 57 deletions
diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c index 38dae746514..db82021f4b9 100644 --- a/tools/perf/bench/mem-memcpy.c +++ b/tools/perf/bench/mem-memcpy.c | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | #include "../util/parse-options.h" | 12 | #include "../util/parse-options.h" |
| 13 | #include "../util/header.h" | 13 | #include "../util/header.h" |
| 14 | #include "bench.h" | 14 | #include "bench.h" |
| 15 | #include "mem-memcpy-arch.h" | ||
| 15 | 16 | ||
| 16 | #include <stdio.h> | 17 | #include <stdio.h> |
| 17 | #include <stdlib.h> | 18 | #include <stdlib.h> |
| @@ -23,8 +24,10 @@ | |||
| 23 | 24 | ||
| 24 | static const char *length_str = "1MB"; | 25 | static const char *length_str = "1MB"; |
| 25 | static const char *routine = "default"; | 26 | static const char *routine = "default"; |
| 26 | static bool use_clock = false; | 27 | static bool use_clock; |
| 27 | static int clock_fd; | 28 | static int clock_fd; |
| 29 | static bool only_prefault; | ||
| 30 | static bool no_prefault; | ||
| 28 | 31 | ||
| 29 | static const struct option options[] = { | 32 | static const struct option options[] = { |
| 30 | OPT_STRING('l', "length", &length_str, "1MB", | 33 | OPT_STRING('l', "length", &length_str, "1MB", |
| @@ -34,19 +37,33 @@ static const struct option options[] = { | |||
| 34 | "Specify routine to copy"), | 37 | "Specify routine to copy"), |
| 35 | OPT_BOOLEAN('c', "clock", &use_clock, | 38 | OPT_BOOLEAN('c', "clock", &use_clock, |
| 36 | "Use CPU clock for measuring"), | 39 | "Use CPU clock for measuring"), |
| 40 | OPT_BOOLEAN('o', "only-prefault", &only_prefault, | ||
| 41 | "Show only the result with page faults before memcpy()"), | ||
| 42 | OPT_BOOLEAN('n', "no-prefault", &no_prefault, | ||
| 43 | "Show only the result without page faults before memcpy()"), | ||
| 37 | OPT_END() | 44 | OPT_END() |
| 38 | }; | 45 | }; |
| 39 | 46 | ||
| 47 | typedef void *(*memcpy_t)(void *, const void *, size_t); | ||
| 48 | |||
| 40 | struct routine { | 49 | struct routine { |
| 41 | const char *name; | 50 | const char *name; |
| 42 | const char *desc; | 51 | const char *desc; |
| 43 | void * (*fn)(void *dst, const void *src, size_t len); | 52 | memcpy_t fn; |
| 44 | }; | 53 | }; |
| 45 | 54 | ||
| 46 | struct routine routines[] = { | 55 | struct routine routines[] = { |
| 47 | { "default", | 56 | { "default", |
| 48 | "Default memcpy() provided by glibc", | 57 | "Default memcpy() provided by glibc", |
| 49 | memcpy }, | 58 | memcpy }, |
| 59 | #ifdef ARCH_X86_64 | ||
| 60 | |||
| 61 | #define MEMCPY_FN(fn, name, desc) { name, desc, fn }, | ||
| 62 | #include "mem-memcpy-x86-64-asm-def.h" | ||
| 63 | #undef MEMCPY_FN | ||
| 64 | |||
| 65 | #endif | ||
| 66 | |||
| 50 | { NULL, | 67 | { NULL, |
| 51 | NULL, | 68 | NULL, |
| 52 | NULL } | 69 | NULL } |
| @@ -89,29 +106,98 @@ static double timeval2double(struct timeval *ts) | |||
| 89 | (double)ts->tv_usec / (double)1000000; | 106 | (double)ts->tv_usec / (double)1000000; |
| 90 | } | 107 | } |
| 91 | 108 | ||
| 109 | static void alloc_mem(void **dst, void **src, size_t length) | ||
| 110 | { | ||
| 111 | *dst = zalloc(length); | ||
| 112 | if (!dst) | ||
| 113 | die("memory allocation failed - maybe length is too large?\n"); | ||
| 114 | |||
| 115 | *src = zalloc(length); | ||
| 116 | if (!src) | ||
| 117 | die("memory allocation failed - maybe length is too large?\n"); | ||
| 118 | } | ||
| 119 | |||
| 120 | static u64 do_memcpy_clock(memcpy_t fn, size_t len, bool prefault) | ||
| 121 | { | ||
| 122 | u64 clock_start = 0ULL, clock_end = 0ULL; | ||
| 123 | void *src = NULL, *dst = NULL; | ||
| 124 | |||
| 125 | alloc_mem(&src, &dst, len); | ||
| 126 | |||
| 127 | if (prefault) | ||
| 128 | fn(dst, src, len); | ||
| 129 | |||
| 130 | clock_start = get_clock(); | ||
| 131 | fn(dst, src, len); | ||
| 132 | clock_end = get_clock(); | ||
| 133 | |||
| 134 | free(src); | ||
| 135 | free(dst); | ||
| 136 | return clock_end - clock_start; | ||
| 137 | } | ||
| 138 | |||
| 139 | static double do_memcpy_gettimeofday(memcpy_t fn, size_t len, bool prefault) | ||
| 140 | { | ||
| 141 | struct timeval tv_start, tv_end, tv_diff; | ||
| 142 | void *src = NULL, *dst = NULL; | ||
| 143 | |||
| 144 | alloc_mem(&src, &dst, len); | ||
| 145 | |||
| 146 | if (prefault) | ||
| 147 | fn(dst, src, len); | ||
| 148 | |||
| 149 | BUG_ON(gettimeofday(&tv_start, NULL)); | ||
| 150 | fn(dst, src, len); | ||
| 151 | BUG_ON(gettimeofday(&tv_end, NULL)); | ||
| 152 | |||
| 153 | timersub(&tv_end, &tv_start, &tv_diff); | ||
| 154 | |||
| 155 | free(src); | ||
| 156 | free(dst); | ||
| 157 | return (double)((double)len / timeval2double(&tv_diff)); | ||
| 158 | } | ||
| 159 | |||
| 160 | #define pf (no_prefault ? 0 : 1) | ||
| 161 | |||
| 162 | #define print_bps(x) do { \ | ||
| 163 | if (x < K) \ | ||
| 164 | printf(" %14lf B/Sec", x); \ | ||
| 165 | else if (x < K * K) \ | ||
| 166 | printf(" %14lfd KB/Sec", x / K); \ | ||
| 167 | else if (x < K * K * K) \ | ||
| 168 | printf(" %14lf MB/Sec", x / K / K); \ | ||
| 169 | else \ | ||
| 170 | printf(" %14lf GB/Sec", x / K / K / K); \ | ||
| 171 | } while (0) | ||
| 172 | |||
| 92 | int bench_mem_memcpy(int argc, const char **argv, | 173 | int bench_mem_memcpy(int argc, const char **argv, |
| 93 | const char *prefix __used) | 174 | const char *prefix __used) |
| 94 | { | 175 | { |
| 95 | int i; | 176 | int i; |
| 96 | void *dst, *src; | 177 | size_t len; |
| 97 | size_t length; | 178 | double result_bps[2]; |
| 98 | double bps = 0.0; | 179 | u64 result_clock[2]; |
| 99 | struct timeval tv_start, tv_end, tv_diff; | ||
| 100 | u64 clock_start, clock_end, clock_diff; | ||
| 101 | 180 | ||
| 102 | clock_start = clock_end = clock_diff = 0ULL; | ||
| 103 | argc = parse_options(argc, argv, options, | 181 | argc = parse_options(argc, argv, options, |
| 104 | bench_mem_memcpy_usage, 0); | 182 | bench_mem_memcpy_usage, 0); |
| 105 | 183 | ||
| 106 | tv_diff.tv_sec = 0; | 184 | if (use_clock) |
| 107 | tv_diff.tv_usec = 0; | 185 | init_clock(); |
| 108 | length = (size_t)perf_atoll((char *)length_str); | 186 | |
| 187 | len = (size_t)perf_atoll((char *)length_str); | ||
| 109 | 188 | ||
| 110 | if ((s64)length <= 0) { | 189 | result_clock[0] = result_clock[1] = 0ULL; |
| 190 | result_bps[0] = result_bps[1] = 0.0; | ||
| 191 | |||
| 192 | if ((s64)len <= 0) { | ||
| 111 | fprintf(stderr, "Invalid length:%s\n", length_str); | 193 | fprintf(stderr, "Invalid length:%s\n", length_str); |
| 112 | return 1; | 194 | return 1; |
| 113 | } | 195 | } |
| 114 | 196 | ||
| 197 | /* same to without specifying either of prefault and no-prefault */ | ||
| 198 | if (only_prefault && no_prefault) | ||
| 199 | only_prefault = no_prefault = false; | ||
| 200 | |||
| 115 | for (i = 0; routines[i].name; i++) { | 201 | for (i = 0; routines[i].name; i++) { |
| 116 | if (!strcmp(routines[i].name, routine)) | 202 | if (!strcmp(routines[i].name, routine)) |
| 117 | break; | 203 | break; |
| @@ -126,61 +212,80 @@ int bench_mem_memcpy(int argc, const char **argv, | |||
| 126 | return 1; | 212 | return 1; |
| 127 | } | 213 | } |
| 128 | 214 | ||
| 129 | dst = zalloc(length); | 215 | if (bench_format == BENCH_FORMAT_DEFAULT) |
| 130 | if (!dst) | 216 | printf("# Copying %s Bytes ...\n\n", length_str); |
| 131 | die("memory allocation failed - maybe length is too large?\n"); | ||
| 132 | |||
| 133 | src = zalloc(length); | ||
| 134 | if (!src) | ||
| 135 | die("memory allocation failed - maybe length is too large?\n"); | ||
| 136 | |||
| 137 | if (bench_format == BENCH_FORMAT_DEFAULT) { | ||
| 138 | printf("# Copying %s Bytes from %p to %p ...\n\n", | ||
| 139 | length_str, src, dst); | ||
| 140 | } | ||
| 141 | |||
| 142 | if (use_clock) { | ||
| 143 | init_clock(); | ||
| 144 | clock_start = get_clock(); | ||
| 145 | } else { | ||
| 146 | BUG_ON(gettimeofday(&tv_start, NULL)); | ||
| 147 | } | ||
| 148 | |||
| 149 | routines[i].fn(dst, src, length); | ||
| 150 | 217 | ||
| 151 | if (use_clock) { | 218 | if (!only_prefault && !no_prefault) { |
| 152 | clock_end = get_clock(); | 219 | /* show both of results */ |
| 153 | clock_diff = clock_end - clock_start; | 220 | if (use_clock) { |
| 221 | result_clock[0] = | ||
| 222 | do_memcpy_clock(routines[i].fn, len, false); | ||
| 223 | result_clock[1] = | ||
| 224 | do_memcpy_clock(routines[i].fn, len, true); | ||
| 225 | } else { | ||
| 226 | result_bps[0] = | ||
| 227 | do_memcpy_gettimeofday(routines[i].fn, | ||
| 228 | len, false); | ||
| 229 | result_bps[1] = | ||
| 230 | do_memcpy_gettimeofday(routines[i].fn, | ||
| 231 | len, true); | ||
| 232 | } | ||
| 154 | } else { | 233 | } else { |
| 155 | BUG_ON(gettimeofday(&tv_end, NULL)); | 234 | if (use_clock) { |
| 156 | timersub(&tv_end, &tv_start, &tv_diff); | 235 | result_clock[pf] = |
| 157 | bps = (double)((double)length / timeval2double(&tv_diff)); | 236 | do_memcpy_clock(routines[i].fn, |
| 237 | len, only_prefault); | ||
| 238 | } else { | ||
| 239 | result_bps[pf] = | ||
| 240 | do_memcpy_gettimeofday(routines[i].fn, | ||
| 241 | len, only_prefault); | ||
| 242 | } | ||
| 158 | } | 243 | } |
| 159 | 244 | ||
| 160 | switch (bench_format) { | 245 | switch (bench_format) { |
| 161 | case BENCH_FORMAT_DEFAULT: | 246 | case BENCH_FORMAT_DEFAULT: |
| 162 | if (use_clock) { | 247 | if (!only_prefault && !no_prefault) { |
| 163 | printf(" %14lf Clock/Byte\n", | 248 | if (use_clock) { |
| 164 | (double)clock_diff / (double)length); | 249 | printf(" %14lf Clock/Byte\n", |
| 165 | } else { | 250 | (double)result_clock[0] |
| 166 | if (bps < K) | 251 | / (double)len); |
| 167 | printf(" %14lf B/Sec\n", bps); | 252 | printf(" %14lf Clock/Byte (with prefault)\n", |
| 168 | else if (bps < K * K) | 253 | (double)result_clock[1] |
| 169 | printf(" %14lfd KB/Sec\n", bps / 1024); | 254 | / (double)len); |
| 170 | else if (bps < K * K * K) | 255 | } else { |
| 171 | printf(" %14lf MB/Sec\n", bps / 1024 / 1024); | 256 | print_bps(result_bps[0]); |
| 172 | else { | 257 | printf("\n"); |
| 173 | printf(" %14lf GB/Sec\n", | 258 | print_bps(result_bps[1]); |
| 174 | bps / 1024 / 1024 / 1024); | 259 | printf(" (with prefault)\n"); |
| 175 | } | 260 | } |
| 261 | } else { | ||
| 262 | if (use_clock) { | ||
| 263 | printf(" %14lf Clock/Byte", | ||
| 264 | (double)result_clock[pf] | ||
| 265 | / (double)len); | ||
| 266 | } else | ||
| 267 | print_bps(result_bps[pf]); | ||
| 268 | |||
| 269 | printf("%s\n", only_prefault ? " (with prefault)" : ""); | ||
| 176 | } | 270 | } |
| 177 | break; | 271 | break; |
| 178 | case BENCH_FORMAT_SIMPLE: | 272 | case BENCH_FORMAT_SIMPLE: |
| 179 | if (use_clock) { | 273 | if (!only_prefault && !no_prefault) { |
| 180 | printf("%14lf\n", | 274 | if (use_clock) { |
| 181 | (double)clock_diff / (double)length); | 275 | printf("%lf %lf\n", |
| 182 | } else | 276 | (double)result_clock[0] / (double)len, |
| 183 | printf("%lf\n", bps); | 277 | (double)result_clock[1] / (double)len); |
| 278 | } else { | ||
| 279 | printf("%lf %lf\n", | ||
| 280 | result_bps[0], result_bps[1]); | ||
| 281 | } | ||
| 282 | } else { | ||
| 283 | if (use_clock) { | ||
| 284 | printf("%lf\n", (double)result_clock[pf] | ||
| 285 | / (double)len); | ||
| 286 | } else | ||
| 287 | printf("%lf\n", result_bps[pf]); | ||
| 288 | } | ||
| 184 | break; | 289 | break; |
| 185 | default: | 290 | default: |
| 186 | /* reaching this means there's some disaster: */ | 291 | /* reaching this means there's some disaster: */ |
