diff options
| author | Borislav Petkov <bp@suse.de> | 2015-02-26 12:51:37 -0500 |
|---|---|---|
| committer | Borislav Petkov <bp@suse.de> | 2015-03-03 12:01:48 -0500 |
| commit | 515e23f0193f42dab3b3e89f2c54da16b8bc3481 (patch) | |
| tree | a1978332297d51fdbe1d4c39c3c4ab5e6e74dfb7 | |
| parent | 0cf55934ecace74bb7d26c0e9679fb41675a8903 (diff) | |
perf/bench: Carve out mem routine benchmarking
... so that we can call it multiple times. See next patch.
Reviewed-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
Signed-off-by: Borislav Petkov <bp@suse.de>
| -rw-r--r-- | tools/perf/bench/mem-memcpy.c | 120 |
1 files changed, 58 insertions, 62 deletions
diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c index 6c14afe8c1b1..50991c459ee1 100644 --- a/tools/perf/bench/mem-memcpy.c +++ b/tools/perf/bench/mem-memcpy.c | |||
| @@ -135,84 +135,32 @@ struct bench_mem_info { | |||
| 135 | const char *const *usage; | 135 | const char *const *usage; |
| 136 | }; | 136 | }; |
| 137 | 137 | ||
| 138 | static int bench_mem_common(int argc, const char **argv, | 138 | static void __bench_mem_routine(struct bench_mem_info *info, int r_idx, size_t len, double totallen) |
| 139 | const char *prefix __maybe_unused, | ||
| 140 | struct bench_mem_info *info) | ||
| 141 | { | 139 | { |
| 142 | int i; | 140 | const struct routine *r = &info->routines[r_idx]; |
| 143 | size_t len; | ||
| 144 | double totallen; | ||
| 145 | double result_bps[2]; | 141 | double result_bps[2]; |
| 146 | u64 result_cycle[2]; | 142 | u64 result_cycle[2]; |
| 147 | 143 | ||
| 148 | argc = parse_options(argc, argv, options, | ||
| 149 | info->usage, 0); | ||
| 150 | |||
| 151 | if (no_prefault && only_prefault) { | ||
| 152 | fprintf(stderr, "Invalid options: -o and -n are mutually exclusive\n"); | ||
| 153 | return 1; | ||
| 154 | } | ||
| 155 | |||
| 156 | if (use_cycle) | ||
| 157 | init_cycle(); | ||
| 158 | |||
| 159 | len = (size_t)perf_atoll((char *)length_str); | ||
| 160 | totallen = (double)len * iterations; | ||
| 161 | |||
| 162 | result_cycle[0] = result_cycle[1] = 0ULL; | 144 | result_cycle[0] = result_cycle[1] = 0ULL; |
| 163 | result_bps[0] = result_bps[1] = 0.0; | 145 | result_bps[0] = result_bps[1] = 0.0; |
| 164 | 146 | ||
| 165 | if ((s64)len <= 0) { | ||
| 166 | fprintf(stderr, "Invalid length:%s\n", length_str); | ||
| 167 | return 1; | ||
| 168 | } | ||
| 169 | |||
| 170 | /* same to without specifying either of prefault and no-prefault */ | ||
| 171 | if (only_prefault && no_prefault) | ||
| 172 | only_prefault = no_prefault = false; | ||
| 173 | |||
| 174 | for (i = 0; info->routines[i].name; i++) { | ||
| 175 | if (!strcmp(info->routines[i].name, routine)) | ||
| 176 | break; | ||
| 177 | } | ||
| 178 | if (!info->routines[i].name) { | ||
| 179 | printf("Unknown routine:%s\n", routine); | ||
| 180 | printf("Available routines...\n"); | ||
| 181 | for (i = 0; info->routines[i].name; i++) { | ||
| 182 | printf("\t%s ... %s\n", | ||
| 183 | info->routines[i].name, info->routines[i].desc); | ||
| 184 | } | ||
| 185 | return 1; | ||
| 186 | } | ||
| 187 | |||
| 188 | if (bench_format == BENCH_FORMAT_DEFAULT) | 147 | if (bench_format == BENCH_FORMAT_DEFAULT) |
| 189 | printf("# Copying %s Bytes ...\n\n", length_str); | 148 | printf("# Copying %s Bytes ...\n\n", length_str); |
| 190 | 149 | ||
| 191 | if (!only_prefault && !no_prefault) { | 150 | if (!only_prefault && !no_prefault) { |
| 192 | /* show both of results */ | 151 | /* show both of results */ |
| 193 | if (use_cycle) { | 152 | if (use_cycle) { |
| 194 | result_cycle[0] = | 153 | result_cycle[0] = info->do_cycle(r, len, false); |
| 195 | info->do_cycle(&info->routines[i], len, false); | 154 | result_cycle[1] = info->do_cycle(r, len, true); |
| 196 | result_cycle[1] = | ||
| 197 | info->do_cycle(&info->routines[i], len, true); | ||
| 198 | } else { | 155 | } else { |
| 199 | result_bps[0] = | 156 | result_bps[0] = info->do_gettimeofday(r, len, false); |
| 200 | info->do_gettimeofday(&info->routines[i], | 157 | result_bps[1] = info->do_gettimeofday(r, len, true); |
| 201 | len, false); | ||
| 202 | result_bps[1] = | ||
| 203 | info->do_gettimeofday(&info->routines[i], | ||
| 204 | len, true); | ||
| 205 | } | 158 | } |
| 206 | } else { | 159 | } else { |
| 207 | if (use_cycle) { | 160 | if (use_cycle) |
| 208 | result_cycle[pf] = | 161 | result_cycle[pf] = info->do_cycle(r, len, only_prefault); |
| 209 | info->do_cycle(&info->routines[i], | 162 | else |
| 210 | len, only_prefault); | 163 | result_bps[pf] = info->do_gettimeofday(r, len, only_prefault); |
| 211 | } else { | ||
| 212 | result_bps[pf] = | ||
| 213 | info->do_gettimeofday(&info->routines[i], | ||
| 214 | len, only_prefault); | ||
| 215 | } | ||
| 216 | } | 164 | } |
| 217 | 165 | ||
| 218 | switch (bench_format) { | 166 | switch (bench_format) { |
| @@ -265,6 +213,54 @@ static int bench_mem_common(int argc, const char **argv, | |||
| 265 | die("unknown format: %d\n", bench_format); | 213 | die("unknown format: %d\n", bench_format); |
| 266 | break; | 214 | break; |
| 267 | } | 215 | } |
| 216 | } | ||
| 217 | |||
| 218 | static int bench_mem_common(int argc, const char **argv, | ||
| 219 | const char *prefix __maybe_unused, | ||
| 220 | struct bench_mem_info *info) | ||
| 221 | { | ||
| 222 | int i; | ||
| 223 | size_t len; | ||
| 224 | double totallen; | ||
| 225 | |||
| 226 | argc = parse_options(argc, argv, options, | ||
| 227 | info->usage, 0); | ||
| 228 | |||
| 229 | if (no_prefault && only_prefault) { | ||
| 230 | fprintf(stderr, "Invalid options: -o and -n are mutually exclusive\n"); | ||
| 231 | return 1; | ||
| 232 | } | ||
| 233 | |||
| 234 | if (use_cycle) | ||
| 235 | init_cycle(); | ||
| 236 | |||
| 237 | len = (size_t)perf_atoll((char *)length_str); | ||
| 238 | totallen = (double)len * iterations; | ||
| 239 | |||
| 240 | if ((s64)len <= 0) { | ||
| 241 | fprintf(stderr, "Invalid length:%s\n", length_str); | ||
| 242 | return 1; | ||
| 243 | } | ||
| 244 | |||
| 245 | /* same to without specifying either of prefault and no-prefault */ | ||
| 246 | if (only_prefault && no_prefault) | ||
| 247 | only_prefault = no_prefault = false; | ||
| 248 | |||
| 249 | for (i = 0; info->routines[i].name; i++) { | ||
| 250 | if (!strcmp(info->routines[i].name, routine)) | ||
| 251 | break; | ||
| 252 | } | ||
| 253 | if (!info->routines[i].name) { | ||
| 254 | printf("Unknown routine:%s\n", routine); | ||
| 255 | printf("Available routines...\n"); | ||
| 256 | for (i = 0; info->routines[i].name; i++) { | ||
| 257 | printf("\t%s ... %s\n", | ||
| 258 | info->routines[i].name, info->routines[i].desc); | ||
| 259 | } | ||
| 260 | return 1; | ||
| 261 | } | ||
| 262 | |||
| 263 | __bench_mem_routine(info, i, len, totallen); | ||
| 268 | 264 | ||
| 269 | return 0; | 265 | return 0; |
| 270 | } | 266 | } |
