Skip to content

Commit

Permalink
perf bench: Allow passing an iteration count to "bench mem mem{cpy,set}"
Browse files Browse the repository at this point in the history
"perf stat ... perf bench mem mem..." is pretty meaningless when using
small block sizes (as the overhead of the invocation of each test run
basically hides the actual test result in the noise). Repeating the
actually interesting function's invocation a number of times allows the
results to become meaningful.

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/4F16D767020000780006D738@nat28.tlf.novell.com
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Jan Beulich authored and Arnaldo Carvalho de Melo committed Jan 24, 2012
1 parent be3de80 commit e3e877e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions tools/perf/bench/mem-memcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

static const char *length_str = "1MB";
static const char *routine = "default";
static int iterations = 1;
static bool use_clock;
static int clock_fd;
static bool only_prefault;
Expand All @@ -35,6 +36,8 @@ static const struct option options[] = {
"available unit: B, MB, GB (upper and lower)"),
OPT_STRING('r', "routine", &routine, "default",
"Specify routine to copy"),
OPT_INTEGER('i', "iterations", &iterations,
"repeat memcpy() invocation this number of times"),
OPT_BOOLEAN('c', "clock", &use_clock,
"Use CPU clock for measuring"),
OPT_BOOLEAN('o', "only-prefault", &only_prefault,
Expand Down Expand Up @@ -121,14 +124,16 @@ 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;
int i;

alloc_mem(&src, &dst, len);

if (prefault)
fn(dst, src, len);

clock_start = get_clock();
fn(dst, src, len);
for (i = 0; i < iterations; ++i)
fn(dst, src, len);
clock_end = get_clock();

free(src);
Expand All @@ -140,14 +145,16 @@ 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;
int i;

alloc_mem(&src, &dst, len);

if (prefault)
fn(dst, src, len);

BUG_ON(gettimeofday(&tv_start, NULL));
fn(dst, src, len);
for (i = 0; i < iterations; ++i)
fn(dst, src, len);
BUG_ON(gettimeofday(&tv_end, NULL));

timersub(&tv_end, &tv_start, &tv_diff);
Expand Down
11 changes: 9 additions & 2 deletions tools/perf/bench/mem-memset.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

static const char *length_str = "1MB";
static const char *routine = "default";
static int iterations = 1;
static bool use_clock;
static int clock_fd;
static bool only_prefault;
Expand All @@ -35,6 +36,8 @@ static const struct option options[] = {
"available unit: B, MB, GB (upper and lower)"),
OPT_STRING('r', "routine", &routine, "default",
"Specify routine to copy"),
OPT_INTEGER('i', "iterations", &iterations,
"repeat memset() invocation this number of times"),
OPT_BOOLEAN('c', "clock", &use_clock,
"Use CPU clock for measuring"),
OPT_BOOLEAN('o', "only-prefault", &only_prefault,
Expand Down Expand Up @@ -117,14 +120,16 @@ static u64 do_memset_clock(memset_t fn, size_t len, bool prefault)
{
u64 clock_start = 0ULL, clock_end = 0ULL;
void *dst = NULL;
int i;

alloc_mem(&dst, len);

if (prefault)
fn(dst, -1, len);

clock_start = get_clock();
fn(dst, 0, len);
for (i = 0; i < iterations; ++i)
fn(dst, i, len);
clock_end = get_clock();

free(dst);
Expand All @@ -135,14 +140,16 @@ static double do_memset_gettimeofday(memset_t fn, size_t len, bool prefault)
{
struct timeval tv_start, tv_end, tv_diff;
void *dst = NULL;
int i;

alloc_mem(&dst, len);

if (prefault)
fn(dst, -1, len);

BUG_ON(gettimeofday(&tv_start, NULL));
fn(dst, 0, len);
for (i = 0; i < iterations; ++i)
fn(dst, i, len);
BUG_ON(gettimeofday(&tv_end, NULL));

timersub(&tv_end, &tv_start, &tv_diff);
Expand Down

0 comments on commit e3e877e

Please sign in to comment.