Skip to content

Commit c2a218c

Browse files
committed
perf bench: Remove one more die() call
Propagate the error instead. Cc: David Ahern <[email protected]> Cc: Hitoshi Mitake <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 042a181 commit c2a218c

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

tools/perf/bench/mem-functions.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Written by Hitoshi Mitake <[email protected]>
77
*/
88

9+
#include "debug.h"
910
#include "../perf.h"
1011
#include "../util/util.h"
1112
#include <subcmd/parse-options.h>
@@ -63,14 +64,16 @@ static struct perf_event_attr cycle_attr = {
6364
.config = PERF_COUNT_HW_CPU_CYCLES
6465
};
6566

66-
static void init_cycles(void)
67+
static int init_cycles(void)
6768
{
6869
cycles_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1, perf_event_open_cloexec_flag());
6970

70-
if (cycles_fd < 0 && errno == ENOSYS)
71-
die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
72-
else
73-
BUG_ON(cycles_fd < 0);
71+
if (cycles_fd < 0 && errno == ENOSYS) {
72+
pr_debug("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
73+
return -1;
74+
}
75+
76+
return cycles_fd;
7477
}
7578

7679
static u64 get_cycles(void)
@@ -155,8 +158,13 @@ static int bench_mem_common(int argc, const char **argv, struct bench_mem_info *
155158

156159
argc = parse_options(argc, argv, options, info->usage, 0);
157160

158-
if (use_cycles)
159-
init_cycles();
161+
if (use_cycles) {
162+
i = init_cycles();
163+
if (i < 0) {
164+
fprintf(stderr, "Failed to open cycles counter\n");
165+
return i;
166+
}
167+
}
160168

161169
size = (size_t)perf_atoll((char *)size_str);
162170
size_total = (double)size * nr_loops;

0 commit comments

Comments
 (0)