Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf ebpf: Add the libbpf glue

The 'bpf-loader.[ch]' files are introduced in this patch. Which will be
the interface between perf and libbpf. bpf__prepare_load() resides in
bpf-loader.c. Following patches will enrich these two files.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1444826502-49291-3-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Wang Nan and committed by
Arnaldo Carvalho de Melo
69d262a9 ed63f34c

+86
+57
tools/perf/util/bpf-loader.c
··· 1 + /* 2 + * bpf-loader.c 3 + * 4 + * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com> 5 + * Copyright (C) 2015 Huawei Inc. 6 + */ 7 + 8 + #include <bpf/libbpf.h> 9 + #include <linux/err.h> 10 + #include "perf.h" 11 + #include "debug.h" 12 + #include "bpf-loader.h" 13 + 14 + #define DEFINE_PRINT_FN(name, level) \ 15 + static int libbpf_##name(const char *fmt, ...) \ 16 + { \ 17 + va_list args; \ 18 + int ret; \ 19 + \ 20 + va_start(args, fmt); \ 21 + ret = veprintf(level, verbose, pr_fmt(fmt), args);\ 22 + va_end(args); \ 23 + return ret; \ 24 + } 25 + 26 + DEFINE_PRINT_FN(warning, 0) 27 + DEFINE_PRINT_FN(info, 0) 28 + DEFINE_PRINT_FN(debug, 1) 29 + 30 + struct bpf_object *bpf__prepare_load(const char *filename) 31 + { 32 + struct bpf_object *obj; 33 + static bool libbpf_initialized; 34 + 35 + if (!libbpf_initialized) { 36 + libbpf_set_print(libbpf_warning, 37 + libbpf_info, 38 + libbpf_debug); 39 + libbpf_initialized = true; 40 + } 41 + 42 + obj = bpf_object__open(filename); 43 + if (!obj) { 44 + pr_debug("bpf: failed to load %s\n", filename); 45 + return ERR_PTR(-EINVAL); 46 + } 47 + 48 + return obj; 49 + } 50 + 51 + void bpf__clear(void) 52 + { 53 + struct bpf_object *obj, *tmp; 54 + 55 + bpf_object__for_each_safe(obj, tmp) 56 + bpf_object__close(obj); 57 + }
+29
tools/perf/util/bpf-loader.h
··· 1 + /* 2 + * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com> 3 + * Copyright (C) 2015, Huawei Inc. 4 + */ 5 + #ifndef __BPF_LOADER_H 6 + #define __BPF_LOADER_H 7 + 8 + #include <linux/compiler.h> 9 + #include <linux/err.h> 10 + #include <string.h> 11 + #include "debug.h" 12 + 13 + struct bpf_object; 14 + 15 + #ifdef HAVE_LIBBPF_SUPPORT 16 + struct bpf_object *bpf__prepare_load(const char *filename); 17 + 18 + void bpf__clear(void); 19 + #else 20 + static inline struct bpf_object * 21 + bpf__prepare_load(const char *filename __maybe_unused) 22 + { 23 + pr_debug("ERROR: eBPF object loading is disabled during compiling.\n"); 24 + return ERR_PTR(-ENOTSUP); 25 + } 26 + 27 + static inline void bpf__clear(void) { } 28 + #endif 29 + #endif