Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1534815

[tip:perf/core] tools lib bpf: Retrive bpf_map through offset of bpf_map_def

From tip-bot for Wang Nan <tipbot@zytor.com>
Newsgroups linux.kernel
Subject [tip:perf/core] tools lib bpf: Retrive bpf_map through offset of bpf_map_def
Date 2016-12-02 11:40 +0100
Message-ID <sJTq2-2EV-27@gated-at.bofh.it> (permalink)
References <sHFrc-3qJ-31@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Commit-ID:  5a6acad17d2e81765dd4c2fce7346a6f045eab25
Gitweb:     http://git.kernel.org/tip/5a6acad17d2e81765dd4c2fce7346a6f045eab25
Author:     Wang Nan <wangnan0@huawei.com>
AuthorDate: Sat, 26 Nov 2016 07:03:27 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 29 Nov 2016 12:10:19 -0300

tools lib bpf: Retrive bpf_map through offset of bpf_map_def

Add a new API to libbpf, caller is able to get bpf_map through the
offset of bpf_map_def to 'maps' section.

The API will be used to help jitted perf hook code find fd of a map.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Joe Stringer <joe@ovn.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/20161126070354.141764-4-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/bpf/libbpf.c | 12 ++++++++++++
 tools/lib/bpf/libbpf.h |  8 ++++++++
 2 files changed, 20 insertions(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 866d5cd..2e97459 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1524,3 +1524,15 @@ bpf_object__find_map_by_name(struct bpf_object *obj, const char *name)
 	}
 	return NULL;
 }
+
+struct bpf_map *
+bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset)
+{
+	int i;
+
+	for (i = 0; i < obj->nr_maps; i++) {
+		if (obj->maps[i].offset == offset)
+			return &obj->maps[i];
+	}
+	return ERR_PTR(-ENOENT);
+}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 0c0b012..a5a8b86 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <linux/err.h>
+#include <sys/types.h>  // for size_t
 
 enum libbpf_errno {
 	__LIBBPF_ERRNO__START = 4000,
@@ -200,6 +201,13 @@ struct bpf_map;
 struct bpf_map *
 bpf_object__find_map_by_name(struct bpf_object *obj, const char *name);
 
+/*
+ * Get bpf_map through the offset of corresponding struct bpf_map_def
+ * in the bpf object file.
+ */
+struct bpf_map *
+bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset);
+
 struct bpf_map *
 bpf_map__next(struct bpf_map *map, struct bpf_object *obj);
 #define bpf_map__for_each(pos, obj)		\

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH v3 00/30] perf clang: Builtin clang and perfhook support Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:20 +0100
  [PATCH v3 08/30] tools build: Add feature detection for clang Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:20 +0100
    [tip:perf/core] tools build: Add feature detection for clang tip-bot for Wang Nan <tipbot@zytor.com> - 2016-12-06 09:30 +0100
  [PATCH v3 11/30] perf clang: Use real file system for #include Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:20 +0100
    [tip:perf/core] perf clang: Use real file system for #include tip-bot for Wang Nan <tipbot@zytor.com> - 2016-12-06 09:30 +0100
  [PATCH v3 15/30] perf clang: Compile BPF script use builtin clang support Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:20 +0100
    [tip:perf/core] perf clang: Compile BPF script using builtin clang  support tip-bot for Wang Nan <tipbot@zytor.com> - 2016-12-06 09:50 +0100
  [PATCH v3 03/30] tools lib bpf: Retrive bpf_map through offset of bpf_map_def Wang Nan <wangnan0@huawei.com> - 2016-11-26 08:20 +0100
    Re: [PATCH v3 03/30] tools lib bpf: Retrive bpf_map through offset  of bpf_map_def Alexei Starovoitov <alexei.starovoitov@gmail.com> - 2016-11-26 18:20 +0100
    [tip:perf/core] tools lib bpf: Retrive bpf_map through offset of  bpf_map_def tip-bot for Wang Nan <tipbot@zytor.com> - 2016-12-02 11:40 +0100

csiph-web