Messages in this thread Patch in this message | | | From | Hitoshi Mitake <> | Subject | [PATCH] perf bench: Make mem/memcpy more friendly | Date | Fri, 20 Nov 2009 12:37:17 +0900 |
| |
mem-memcpy.c uses perf event system calls to obtain CPU clocks. And it suddenly dies with BUG_ON() when it running on Linux doesn't support perf event.
Also fail at calloc() can occur easily when too large length is passed. Fail of calloc() causes sudden death with assert().
These behaviours are not friendly. So I fixed the treat of error.
Signed-off-by: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> --- tools/perf/bench/mem-memcpy.c | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c index d4f4f98..1252d42 100644 --- a/tools/perf/bench/mem-memcpy.c +++ b/tools/perf/bench/mem-memcpy.c @@ -67,6 +67,11 @@ static struct perf_event_attr clock_attr = { static void init_clock(void) { clock_fd = sys_perf_event_open(&clock_attr, getpid(), -1, -1, 0); + if (clock_fd < 0 && errno == ENOSYS) { + fprintf(stderr, "! Your Linux doesn't support perf events!\n"); + fprintf(stderr, "! Measuring clock is impossible. Aborting.\n"); + exit(1); + } BUG_ON(clock_fd < 0); } @@ -124,9 +129,17 @@ int bench_mem_memcpy(int argc, const char **argv, } dst = calloc(length, sizeof(char)); - assert(dst); + if (!dst) { + fprintf(stderr, "Allocating memory failed.\n"); + fprintf(stderr, "Maybe length is too large.\n"); + exit(1); + } src = calloc(length, sizeof(char)); - assert(src); + if (!src) { + fprintf(stderr, "Allocating memory failed.\n"); + fprintf(stderr, "Maybe length is too large.\n"); + exit(1); + } if (bench_format == BENCH_FORMAT_DEFAULT) { printf("# Copying %s Bytes from %p to %p ...\n\n", -- 1.6.5.2
| |