diff options
author | Wang Nan <wangnan0@huawei.com> | 2015-08-26 22:30:55 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-08-31 15:53:15 -0400 |
commit | acf860ae7c53cc8b0c5d372c218332aac3eeba4f (patch) | |
tree | 95c0521fcfff8e0c2dc88bca26ecb5fd3e9ec885 | |
parent | 97db62062ac76e314c8bda4dc5b63f0ea906d15f (diff) |
bpf tools: New API to get name from a BPF object
Before this patch there's no way to connect a loaded bpf object
to its source file. However, during applying perf's '--filter' to BPF
object, without this connection makes things harder, because perf loads
all programs together, but '--filter' setting is for each object.
The API of bpf_object__open_buffer() is changed to allow passing a name.
Fortunately, at this time there's only one user of it (perf test LLVM),
so we change it together.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: 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/1440742821-44548-2-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/lib/bpf/libbpf.c | 25 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.h | 4 | ||||
-rw-r--r-- | tools/perf/tests/llvm.c | 2 |
3 files changed, 26 insertions, 5 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 4fa4bc4505f5..4252fc22f78f 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
@@ -880,15 +880,26 @@ struct bpf_object *bpf_object__open(const char *path) | |||
880 | } | 880 | } |
881 | 881 | ||
882 | struct bpf_object *bpf_object__open_buffer(void *obj_buf, | 882 | struct bpf_object *bpf_object__open_buffer(void *obj_buf, |
883 | size_t obj_buf_sz) | 883 | size_t obj_buf_sz, |
884 | const char *name) | ||
884 | { | 885 | { |
886 | char tmp_name[64]; | ||
887 | |||
885 | /* param validation */ | 888 | /* param validation */ |
886 | if (!obj_buf || obj_buf_sz <= 0) | 889 | if (!obj_buf || obj_buf_sz <= 0) |
887 | return NULL; | 890 | return NULL; |
888 | 891 | ||
889 | pr_debug("loading object from buffer\n"); | 892 | if (!name) { |
893 | snprintf(tmp_name, sizeof(tmp_name), "%lx-%lx", | ||
894 | (unsigned long)obj_buf, | ||
895 | (unsigned long)obj_buf_sz); | ||
896 | tmp_name[sizeof(tmp_name) - 1] = '\0'; | ||
897 | name = tmp_name; | ||
898 | } | ||
899 | pr_debug("loading object '%s' from buffer\n", | ||
900 | name); | ||
890 | 901 | ||
891 | return __bpf_object__open("[buffer]", obj_buf, obj_buf_sz); | 902 | return __bpf_object__open(name, obj_buf, obj_buf_sz); |
892 | } | 903 | } |
893 | 904 | ||
894 | int bpf_object__unload(struct bpf_object *obj) | 905 | int bpf_object__unload(struct bpf_object *obj) |
@@ -975,6 +986,14 @@ bpf_object__next(struct bpf_object *prev) | |||
975 | return next; | 986 | return next; |
976 | } | 987 | } |
977 | 988 | ||
989 | const char * | ||
990 | bpf_object__get_name(struct bpf_object *obj) | ||
991 | { | ||
992 | if (!obj) | ||
993 | return NULL; | ||
994 | return obj->path; | ||
995 | } | ||
996 | |||
978 | struct bpf_program * | 997 | struct bpf_program * |
979 | bpf_program__next(struct bpf_program *prev, struct bpf_object *obj) | 998 | bpf_program__next(struct bpf_program *prev, struct bpf_object *obj) |
980 | { | 999 | { |
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index ea8adc206b62..f16170c95ffd 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h | |||
@@ -28,12 +28,14 @@ struct bpf_object; | |||
28 | 28 | ||
29 | struct bpf_object *bpf_object__open(const char *path); | 29 | struct bpf_object *bpf_object__open(const char *path); |
30 | struct bpf_object *bpf_object__open_buffer(void *obj_buf, | 30 | struct bpf_object *bpf_object__open_buffer(void *obj_buf, |
31 | size_t obj_buf_sz); | 31 | size_t obj_buf_sz, |
32 | const char *name); | ||
32 | void bpf_object__close(struct bpf_object *object); | 33 | void bpf_object__close(struct bpf_object *object); |
33 | 34 | ||
34 | /* Load/unload object into/from kernel */ | 35 | /* Load/unload object into/from kernel */ |
35 | int bpf_object__load(struct bpf_object *obj); | 36 | int bpf_object__load(struct bpf_object *obj); |
36 | int bpf_object__unload(struct bpf_object *obj); | 37 | int bpf_object__unload(struct bpf_object *obj); |
38 | const char *bpf_object__get_name(struct bpf_object *obj); | ||
37 | 39 | ||
38 | struct bpf_object *bpf_object__next(struct bpf_object *prev); | 40 | struct bpf_object *bpf_object__next(struct bpf_object *prev); |
39 | #define bpf_object__for_each_safe(pos, tmp) \ | 41 | #define bpf_object__for_each_safe(pos, tmp) \ |
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c index a337356fd979..52d55971f66f 100644 --- a/tools/perf/tests/llvm.c +++ b/tools/perf/tests/llvm.c | |||
@@ -26,7 +26,7 @@ static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz) | |||
26 | { | 26 | { |
27 | struct bpf_object *obj; | 27 | struct bpf_object *obj; |
28 | 28 | ||
29 | obj = bpf_object__open_buffer(obj_buf, obj_buf_sz); | 29 | obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL); |
30 | if (!obj) | 30 | if (!obj) |
31 | return -1; | 31 | return -1; |
32 | bpf_object__close(obj); | 32 | bpf_object__close(obj); |