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>
This commit is contained in:
parent
d9cf837ef9
commit
49ce8fc651
|
@ -12,6 +12,7 @@
|
||||||
#include "../util/parse-options.h"
|
#include "../util/parse-options.h"
|
||||||
#include "../util/header.h"
|
#include "../util/header.h"
|
||||||
#include "bench.h"
|
#include "bench.h"
|
||||||
|
#include "mem-memcpy-arch.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -23,8 +24,10 @@
|
||||||
|
|
||||||
static const char *length_str = "1MB";
|
static const char *length_str = "1MB";
|
||||||
static const char *routine = "default";
|
static const char *routine = "default";
|
||||||
static bool use_clock = false;
|
static bool use_clock;
|
||||||
static int clock_fd;
|
static int clock_fd;
|
||||||
|
static bool only_prefault;
|
||||||
|
static bool no_prefault;
|
||||||
|
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
OPT_STRING('l', "length", &length_str, "1MB",
|
OPT_STRING('l', "length", &length_str, "1MB",
|
||||||
|
@ -34,19 +37,33 @@ static const struct option options[] = {
|
||||||
"Specify routine to copy"),
|
"Specify routine to copy"),
|
||||||
OPT_BOOLEAN('c', "clock", &use_clock,
|
OPT_BOOLEAN('c', "clock", &use_clock,
|
||||||
"Use CPU clock for measuring"),
|
"Use CPU clock for measuring"),
|
||||||
|
OPT_BOOLEAN('o', "only-prefault", &only_prefault,
|
||||||
|
"Show only the result with page faults before memcpy()"),
|
||||||
|
OPT_BOOLEAN('n', "no-prefault", &no_prefault,
|
||||||
|
"Show only the result without page faults before memcpy()"),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void *(*memcpy_t)(void *, const void *, size_t);
|
||||||
|
|
||||||
struct routine {
|
struct routine {
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *desc;
|
const char *desc;
|
||||||
void * (*fn)(void *dst, const void *src, size_t len);
|
memcpy_t fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct routine routines[] = {
|
struct routine routines[] = {
|
||||||
{ "default",
|
{ "default",
|
||||||
"Default memcpy() provided by glibc",
|
"Default memcpy() provided by glibc",
|
||||||
memcpy },
|
memcpy },
|
||||||
|
#ifdef ARCH_X86_64
|
||||||
|
|
||||||
|
#define MEMCPY_FN(fn, name, desc) { name, desc, fn },
|
||||||
|
#include "mem-memcpy-x86-64-asm-def.h"
|
||||||
|
#undef MEMCPY_FN
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
{ NULL,
|
{ NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL }
|
NULL }
|
||||||
|
@ -89,29 +106,98 @@ static double timeval2double(struct timeval *ts)
|
||||||
(double)ts->tv_usec / (double)1000000;
|
(double)ts->tv_usec / (double)1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void alloc_mem(void **dst, void **src, size_t length)
|
||||||
|
{
|
||||||
|
*dst = zalloc(length);
|
||||||
|
if (!dst)
|
||||||
|
die("memory allocation failed - maybe length is too large?\n");
|
||||||
|
|
||||||
|
*src = zalloc(length);
|
||||||
|
if (!src)
|
||||||
|
die("memory allocation failed - maybe length is too large?\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static u64 do_memcpy_clock(memcpy_t fn, size_t len, bool prefault)
|
||||||
|
{
|
||||||
|
u64 clock_start = 0ULL, clock_end = 0ULL;
|
||||||
|
void *src = NULL, *dst = NULL;
|
||||||
|
|
||||||
|
alloc_mem(&src, &dst, len);
|
||||||
|
|
||||||
|
if (prefault)
|
||||||
|
fn(dst, src, len);
|
||||||
|
|
||||||
|
clock_start = get_clock();
|
||||||
|
fn(dst, src, len);
|
||||||
|
clock_end = get_clock();
|
||||||
|
|
||||||
|
free(src);
|
||||||
|
free(dst);
|
||||||
|
return clock_end - clock_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double do_memcpy_gettimeofday(memcpy_t fn, size_t len, bool prefault)
|
||||||
|
{
|
||||||
|
struct timeval tv_start, tv_end, tv_diff;
|
||||||
|
void *src = NULL, *dst = NULL;
|
||||||
|
|
||||||
|
alloc_mem(&src, &dst, len);
|
||||||
|
|
||||||
|
if (prefault)
|
||||||
|
fn(dst, src, len);
|
||||||
|
|
||||||
|
BUG_ON(gettimeofday(&tv_start, NULL));
|
||||||
|
fn(dst, src, len);
|
||||||
|
BUG_ON(gettimeofday(&tv_end, NULL));
|
||||||
|
|
||||||
|
timersub(&tv_end, &tv_start, &tv_diff);
|
||||||
|
|
||||||
|
free(src);
|
||||||
|
free(dst);
|
||||||
|
return (double)((double)len / timeval2double(&tv_diff));
|
||||||
|
}
|
||||||
|
|
||||||
|
#define pf (no_prefault ? 0 : 1)
|
||||||
|
|
||||||
|
#define print_bps(x) do { \
|
||||||
|
if (x < K) \
|
||||||
|
printf(" %14lf B/Sec", x); \
|
||||||
|
else if (x < K * K) \
|
||||||
|
printf(" %14lfd KB/Sec", x / K); \
|
||||||
|
else if (x < K * K * K) \
|
||||||
|
printf(" %14lf MB/Sec", x / K / K); \
|
||||||
|
else \
|
||||||
|
printf(" %14lf GB/Sec", x / K / K / K); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
int bench_mem_memcpy(int argc, const char **argv,
|
int bench_mem_memcpy(int argc, const char **argv,
|
||||||
const char *prefix __used)
|
const char *prefix __used)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
void *dst, *src;
|
size_t len;
|
||||||
size_t length;
|
double result_bps[2];
|
||||||
double bps = 0.0;
|
u64 result_clock[2];
|
||||||
struct timeval tv_start, tv_end, tv_diff;
|
|
||||||
u64 clock_start, clock_end, clock_diff;
|
|
||||||
|
|
||||||
clock_start = clock_end = clock_diff = 0ULL;
|
|
||||||
argc = parse_options(argc, argv, options,
|
argc = parse_options(argc, argv, options,
|
||||||
bench_mem_memcpy_usage, 0);
|
bench_mem_memcpy_usage, 0);
|
||||||
|
|
||||||
tv_diff.tv_sec = 0;
|
if (use_clock)
|
||||||
tv_diff.tv_usec = 0;
|
init_clock();
|
||||||
length = (size_t)perf_atoll((char *)length_str);
|
|
||||||
|
|
||||||
if ((s64)length <= 0) {
|
len = (size_t)perf_atoll((char *)length_str);
|
||||||
|
|
||||||
|
result_clock[0] = result_clock[1] = 0ULL;
|
||||||
|
result_bps[0] = result_bps[1] = 0.0;
|
||||||
|
|
||||||
|
if ((s64)len <= 0) {
|
||||||
fprintf(stderr, "Invalid length:%s\n", length_str);
|
fprintf(stderr, "Invalid length:%s\n", length_str);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* same to without specifying either of prefault and no-prefault */
|
||||||
|
if (only_prefault && no_prefault)
|
||||||
|
only_prefault = no_prefault = false;
|
||||||
|
|
||||||
for (i = 0; routines[i].name; i++) {
|
for (i = 0; routines[i].name; i++) {
|
||||||
if (!strcmp(routines[i].name, routine))
|
if (!strcmp(routines[i].name, routine))
|
||||||
break;
|
break;
|
||||||
|
@ -126,61 +212,80 @@ int bench_mem_memcpy(int argc, const char **argv,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dst = zalloc(length);
|
if (bench_format == BENCH_FORMAT_DEFAULT)
|
||||||
if (!dst)
|
printf("# Copying %s Bytes ...\n\n", length_str);
|
||||||
die("memory allocation failed - maybe length is too large?\n");
|
|
||||||
|
|
||||||
src = zalloc(length);
|
if (!only_prefault && !no_prefault) {
|
||||||
if (!src)
|
/* show both of results */
|
||||||
die("memory allocation failed - maybe length is too large?\n");
|
if (use_clock) {
|
||||||
|
result_clock[0] =
|
||||||
if (bench_format == BENCH_FORMAT_DEFAULT) {
|
do_memcpy_clock(routines[i].fn, len, false);
|
||||||
printf("# Copying %s Bytes from %p to %p ...\n\n",
|
result_clock[1] =
|
||||||
length_str, src, dst);
|
do_memcpy_clock(routines[i].fn, len, true);
|
||||||
}
|
} else {
|
||||||
|
result_bps[0] =
|
||||||
if (use_clock) {
|
do_memcpy_gettimeofday(routines[i].fn,
|
||||||
init_clock();
|
len, false);
|
||||||
clock_start = get_clock();
|
result_bps[1] =
|
||||||
|
do_memcpy_gettimeofday(routines[i].fn,
|
||||||
|
len, true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
BUG_ON(gettimeofday(&tv_start, NULL));
|
if (use_clock) {
|
||||||
}
|
result_clock[pf] =
|
||||||
|
do_memcpy_clock(routines[i].fn,
|
||||||
routines[i].fn(dst, src, length);
|
len, only_prefault);
|
||||||
|
} else {
|
||||||
if (use_clock) {
|
result_bps[pf] =
|
||||||
clock_end = get_clock();
|
do_memcpy_gettimeofday(routines[i].fn,
|
||||||
clock_diff = clock_end - clock_start;
|
len, only_prefault);
|
||||||
} else {
|
}
|
||||||
BUG_ON(gettimeofday(&tv_end, NULL));
|
|
||||||
timersub(&tv_end, &tv_start, &tv_diff);
|
|
||||||
bps = (double)((double)length / timeval2double(&tv_diff));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (bench_format) {
|
switch (bench_format) {
|
||||||
case BENCH_FORMAT_DEFAULT:
|
case BENCH_FORMAT_DEFAULT:
|
||||||
if (use_clock) {
|
if (!only_prefault && !no_prefault) {
|
||||||
printf(" %14lf Clock/Byte\n",
|
if (use_clock) {
|
||||||
(double)clock_diff / (double)length);
|
printf(" %14lf Clock/Byte\n",
|
||||||
} else {
|
(double)result_clock[0]
|
||||||
if (bps < K)
|
/ (double)len);
|
||||||
printf(" %14lf B/Sec\n", bps);
|
printf(" %14lf Clock/Byte (with prefault)\n",
|
||||||
else if (bps < K * K)
|
(double)result_clock[1]
|
||||||
printf(" %14lfd KB/Sec\n", bps / 1024);
|
/ (double)len);
|
||||||
else if (bps < K * K * K)
|
} else {
|
||||||
printf(" %14lf MB/Sec\n", bps / 1024 / 1024);
|
print_bps(result_bps[0]);
|
||||||
else {
|
printf("\n");
|
||||||
printf(" %14lf GB/Sec\n",
|
print_bps(result_bps[1]);
|
||||||
bps / 1024 / 1024 / 1024);
|
printf(" (with prefault)\n");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (use_clock) {
|
||||||
|
printf(" %14lf Clock/Byte",
|
||||||
|
(double)result_clock[pf]
|
||||||
|
/ (double)len);
|
||||||
|
} else
|
||||||
|
print_bps(result_bps[pf]);
|
||||||
|
|
||||||
|
printf("%s\n", only_prefault ? " (with prefault)" : "");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BENCH_FORMAT_SIMPLE:
|
case BENCH_FORMAT_SIMPLE:
|
||||||
if (use_clock) {
|
if (!only_prefault && !no_prefault) {
|
||||||
printf("%14lf\n",
|
if (use_clock) {
|
||||||
(double)clock_diff / (double)length);
|
printf("%lf %lf\n",
|
||||||
} else
|
(double)result_clock[0] / (double)len,
|
||||||
printf("%lf\n", bps);
|
(double)result_clock[1] / (double)len);
|
||||||
|
} else {
|
||||||
|
printf("%lf %lf\n",
|
||||||
|
result_bps[0], result_bps[1]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (use_clock) {
|
||||||
|
printf("%lf\n", (double)result_clock[pf]
|
||||||
|
/ (double)len);
|
||||||
|
} else
|
||||||
|
printf("%lf\n", result_bps[pf]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* reaching this means there's some disaster: */
|
/* reaching this means there's some disaster: */
|
||||||
|
|
Loading…
Reference in New Issue