From: Wang Nan <wangnan0@huawei.com>
To: <acme@kernel.org>, <jolsa@redhat.com>, <brendan.d.gregg@gmail.com>
Cc: <linux-kernel@vger.kernel.org>, <pi3orama@163.com>,
Wang Nan <wangnan0@huawei.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
"Alexei Starovoitov" <ast@kernel.org>,
Jiri Olsa <jolsa@kernel.org>, Li Zefan <lizefan@huawei.com>
Subject: [RFC PATCH 09/13] bpf tools: Register extern functions for ubpf programs
Date: Wed, 20 Apr 2016 18:01:49 +0000 [thread overview]
Message-ID: <1461175313-38310-10-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <1461175313-38310-1-git-send-email-wangnan0@huawei.com>
Introduce libbpf_register_ubpf_func(), allow caller (perf) to
register extern functions. Registered functions are stored into
an array and registered to each ubpf_vm when loading.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
---
tools/lib/bpf/libbpf.c | 38 +++++++++++++++++++++++++++++++++++++-
tools/lib/bpf/libbpf.h | 4 ++++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 4045a7e..f6df743 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -951,19 +951,48 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
}
#ifdef HAVE_UBPF_SUPPORT
+static struct {
+ const char *name;
+ void *func;
+} ubpf_funcs[MAX_UBPF_FUNC];
+
+int libbpf_register_ubpf_func(unsigned int idx, const char *name, void *func)
+{
+ if (idx >= MAX_UBPF_FUNC)
+ return -E2BIG;
+ if (!func)
+ return -EINVAL;
+
+ ubpf_funcs[idx].name = name;
+ ubpf_funcs[idx].func = func;
+ return 0;
+}
+
static int
load_ubpf_program(struct bpf_insn *insns, int insns_cnt,
struct ubpf_vm **pvm)
{
struct ubpf_vm *vm = ubpf_create();
char *message;
- int err;
+ int i, err;
if (!vm) {
pr_warning("Failed to create ubpf vm\n");
return -LIBBPF_ERRNO__LOADUBPF;
}
+ for (i = 0; i < MAX_UBPF_FUNC; i++) {
+ if (ubpf_funcs[i].func) {
+ err = ubpf_register(vm, i, ubpf_funcs[i].name,
+ ubpf_funcs[i].func);
+ if (err) {
+ pr_warning("Failed to register %s\n",
+ ubpf_funcs[i].name);
+ return -LIBBPF_ERRNO__LOADUBPF;
+ }
+ }
+ }
+
err = ubpf_load(vm, insns, insns_cnt * sizeof(insns[0]), &message);
if (err < 0) {
pr_warning("Failed to load ubpf program: %s\n", message);
@@ -973,6 +1002,13 @@ load_ubpf_program(struct bpf_insn *insns, int insns_cnt,
*pvm = vm;
return 0;
}
+#else
+int libbpf_register_ubpf_func(unsigned int idx __maybe_unused,
+ const char *name __maybe_unused,
+ void *func __maybe_unused)
+{
+ return -LIBBPF_ERRNO__NOUBPF;
+}
#endif
static int
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 41c35fd..a764dee 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -45,6 +45,10 @@ void libbpf_set_print(libbpf_print_fn_t warn,
libbpf_print_fn_t info,
libbpf_print_fn_t debug);
+#define MAX_UBPF_FUNC 64
+
+int libbpf_register_ubpf_func(unsigned int idx, const char *name, void *func);
+
/* Hide internal to user */
struct bpf_object;
--
1.8.3.4
next prev parent reply other threads:[~2016-04-20 18:02 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-20 18:01 [RFC PATCH 00/13] perf tools: Support uBPF script Wang Nan
2016-04-20 18:01 ` [RFC PATCH 01/13] bpf tools: Add map related BPF helper Wang Nan
2016-04-20 18:01 ` [RFC PATCH 02/13] tools: Add ubpf feature test Wang Nan
2016-04-20 19:11 ` Arnaldo Carvalho de Melo
2016-04-20 18:01 ` [RFC PATCH 03/13] bpf tools: Add ubpf include and makefile options Wang Nan
2016-04-20 18:01 ` [RFC PATCH 04/13] bpf tools: Replace fd array to union array Wang Nan
2016-04-20 19:20 ` Arnaldo Carvalho de Melo
2016-04-20 18:01 ` [RFC PATCH 05/13] bpf tools: Save engine type in bpf_program Wang Nan
2016-04-20 19:23 ` Arnaldo Carvalho de Melo
2016-04-20 19:29 ` pi3orama
2016-04-20 18:01 ` [RFC PATCH 06/13] bpf tools: Introduce ubpf_vm to program instance union Wang Nan
2016-04-20 19:30 ` Arnaldo Carvalho de Melo
2016-04-20 18:01 ` [RFC PATCH 07/13] bpf tools: Load ubpf program Wang Nan
2016-04-20 19:34 ` Arnaldo Carvalho de Melo
2016-04-20 18:01 ` [RFC PATCH 08/13] bpf tools: Add API for fetching ubpf_vm Wang Nan
2016-04-20 18:01 ` Wang Nan [this message]
2016-04-20 18:01 ` [RFC PATCH 10/13] perf tools: Register basic UBPF helpers Wang Nan
2016-04-20 18:01 ` [RFC PATCH 11/13] perf bpf: Accept ubpf programs Wang Nan
2016-04-20 18:01 ` [RFC PATCH 12/13] perf record: Add UBPF hooks at beginning and end of perf record Wang Nan
2016-04-20 18:01 ` [RFC PATCH 13/13] perf tests: Add UBPF test case Wang Nan
2016-04-20 22:06 ` [RFC PATCH 00/13] perf tools: Support uBPF script Alexei Starovoitov
2016-04-21 8:17 ` Wangnan (F)
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=1461175313-38310-10-git-send-email-wangnan0@huawei.com \
--to=wangnan0@huawei.com \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--cc=ast@kernel.org \
--cc=brendan.d.gregg@gmail.com \
--cc=jolsa@kernel.org \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=pi3orama@163.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
all inboxes | Powered by JetHome®