Commit 3a7ab605 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf tools: Move libbpf init in libbpf_init function

Move the libbpf init code into a single function, so that we have a single
place doing that.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org
Link: https://lore.kernel.org/r/20220422100025.1469207-4-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 75eafc97
...@@ -99,16 +99,26 @@ static int bpf_perf_object__add(struct bpf_object *obj) ...@@ -99,16 +99,26 @@ static int bpf_perf_object__add(struct bpf_object *obj)
return perf_obj ? 0 : -ENOMEM; return perf_obj ? 0 : -ENOMEM;
} }
static int libbpf_init(void)
{
if (libbpf_initialized)
return 0;
libbpf_set_print(libbpf_perf_print);
libbpf_initialized = true;
return 0;
}
struct bpf_object * struct bpf_object *
bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz, const char *name) bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz, const char *name)
{ {
LIBBPF_OPTS(bpf_object_open_opts, opts, .object_name = name); LIBBPF_OPTS(bpf_object_open_opts, opts, .object_name = name);
struct bpf_object *obj; struct bpf_object *obj;
int err;
if (!libbpf_initialized) { err = libbpf_init();
libbpf_set_print(libbpf_perf_print); if (err)
libbpf_initialized = true; return ERR_PTR(err);
}
obj = bpf_object__open_mem(obj_buf, obj_buf_sz, &opts); obj = bpf_object__open_mem(obj_buf, obj_buf_sz, &opts);
if (IS_ERR_OR_NULL(obj)) { if (IS_ERR_OR_NULL(obj)) {
...@@ -135,14 +145,13 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source) ...@@ -135,14 +145,13 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
{ {
LIBBPF_OPTS(bpf_object_open_opts, opts, .object_name = filename); LIBBPF_OPTS(bpf_object_open_opts, opts, .object_name = filename);
struct bpf_object *obj; struct bpf_object *obj;
int err;
if (!libbpf_initialized) { err = libbpf_init();
libbpf_set_print(libbpf_perf_print); if (err)
libbpf_initialized = true; return ERR_PTR(err);
}
if (source) { if (source) {
int err;
void *obj_buf; void *obj_buf;
size_t obj_buf_sz; size_t obj_buf_sz;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment