linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Wang Nan <wangnan0@huawei.com>,
	He Kuang <hekuang@huawei.com>, Jiri Olsa <jolsa@kernel.org>,
	Joe Stringer <joe@ovn.org>, Zefan Li <lizefan@huawei.com>,
	pi3orama@163.com, Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 07/19] tools lib bpf: Retrive bpf_map through offset of bpf_map_def
Date: Thu,  1 Dec 2016 15:02:23 -0300	[thread overview]
Message-ID: <20161201180235.18392-8-acme@kernel.org> (raw)
In-Reply-To: <20161201180235.18392-1-acme@kernel.org>

From: Wang Nan <wangnan0@huawei.com>

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 866d5cdeffc7..2e974593f3e8 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 0c0b0127e03e..a5a8b86a06fe 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)		\
-- 
2.9.3

  parent reply	other threads:[~2016-12-01 18:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-01 18:02 [GIT PULL 00/19] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 01/19] perf ui helpline: Provide a printf variant Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 02/19] perf annotate: Show invalid jump offset in error message Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 03/19] perf sched timehist: Handle cpu migration events Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 04/19] perf trace: Update tid/pid filtering option to leverage symbol_conf Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 05/19] tools lib bpf: Add missing BPF functions Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 06/19] tools lib bpf: Add private field for bpf_object Arnaldo Carvalho de Melo
2016-12-01 18:02 ` Arnaldo Carvalho de Melo [this message]
2016-12-01 18:02 ` [PATCH 08/19] perf tools: Introduce perf hooks Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 09/19] perf test: Remove "test" and similar strings from test descriptions Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 10/19] perf kmem stat: Track memory freed Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 11/19] perf script: Add option to stop printing callchain Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 12/19] perf tools: Add time-based utility functions Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 13/19] perf tools: Move parse_nsec_time to time-utils.c Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 14/19] perf script: Add option to specify time window of interest Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 15/19] perf sched timehist: " Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 16/19] perf kmem: " Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 17/19] perf report: " Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 18/19] perf annotate: Use arch->objdump.comment_char in dec__parse() Arnaldo Carvalho de Melo
2016-12-01 18:02 ` [PATCH 19/19] perf annotate: AArch64 support Arnaldo Carvalho de Melo
2016-12-02  9:10 ` [GIT PULL 00/19] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161201180235.18392-8-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=hekuang@huawei.com \
    --cc=joe@ovn.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=mingo@kernel.org \
    --cc=pi3orama@163.com \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).