From: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org,
Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Mackerras <paulus@samba.org>,
Frederic Weisbecker <fweisbec@gmail.com>
Subject: [PATCH] perf bench: Make mem/memcpy more friendly
Date: Fri, 20 Nov 2009 12:37:17 +0900 [thread overview]
Message-ID: <1258688237-3797-1-git-send-email-mitake@dcl.info.waseda.ac.jp> (raw)
In-Reply-To: <20091119072252.GA11452@elte.hu>
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
next parent reply other threads:[~2009-11-20 3:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20091119072252.GA11452@elte.hu>
2009-11-20 3:37 ` Hitoshi Mitake [this message]
2009-11-22 8:43 ` [tip:perf/bench] perf bench: Make the mem/memcpy tests more user-friendly tip-bot for Hitoshi Mitake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1258688237-3797-1-git-send-email-mitake@dcl.info.waseda.ac.jp \
--to=mitake@dcl.info.waseda.ac.jp \
--cc=a.p.zijlstra@chello.nl \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®