Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758299AbZKTDhQ (ORCPT ); Thu, 19 Nov 2009 22:37:16 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758243AbZKTDhP (ORCPT ); Thu, 19 Nov 2009 22:37:15 -0500 Received: from ns.dcl.info.waseda.ac.jp ([133.9.216.194]:51687 "EHLO ns.dcl.info.waseda.ac.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758218AbZKTDhP (ORCPT ); Thu, 19 Nov 2009 22:37:15 -0500 From: Hitoshi Mitake To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Hitoshi Mitake , Peter Zijlstra , Paul Mackerras , Frederic Weisbecker Subject: [PATCH] perf bench: Make mem/memcpy more friendly Date: Fri, 20 Nov 2009 12:37:17 +0900 Message-Id: <1258688237-3797-1-git-send-email-mitake@dcl.info.waseda.ac.jp> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <20091119072252.GA11452@elte.hu> References: <20091119072252.GA11452@elte.hu> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2017 Lines: 62 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 Cc: Peter Zijlstra Cc: Paul Mackerras Cc: Frederic Weisbecker --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/