[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1461175313-38310-9-git-send-email-wangnan0@huawei.com>
Date: Wed, 20 Apr 2016 18:01:48 +0000
From: Wang Nan <wangnan0@...wei.com>
To: <acme@...nel.org>, <jolsa@...hat.com>, <brendan.d.gregg@...il.com>
CC: <linux-kernel@...r.kernel.org>, <pi3orama@....com>,
Wang Nan <wangnan0@...wei.com>,
Arnaldo Carvalho de Melo <acme@...hat.com>,
"Alexei Starovoitov" <ast@...nel.org>,
Jiri Olsa <jolsa@...nel.org>, Li Zefan <lizefan@...wei.com>
Subject: [RFC PATCH 08/13] bpf tools: Add API for fetching ubpf_vm
Introduce bpf_program__vm and bpf_program__nth_vm for fetching ubpf
program instance.
Signed-off-by: Wang Nan <wangnan0@...wei.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Alexei Starovoitov <ast@...nel.org>
Cc: Brendan Gregg <brendan.d.gregg@...il.com>
Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Li Zefan <lizefan@...wei.com>
---
tools/lib/bpf/libbpf.c | 38 ++++++++++++++++++++++++++++++++++++++
tools/lib/bpf/libbpf.h | 2 ++
2 files changed, 40 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e4a1e77..4045a7e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1375,6 +1375,11 @@ int bpf_program__fd(struct bpf_program *prog)
return bpf_program__nth_fd(prog, 0);
}
+struct ubpf_vm *bpf_program__vm(struct bpf_program *prog)
+{
+ return bpf_program__nth_vm(prog, 0);
+}
+
int bpf_program__set_prep(struct bpf_program *prog, int nr_instances,
bpf_program_prep_t prep)
{
@@ -1429,6 +1434,32 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n)
}
#ifdef HAVE_UBPF_SUPPORT
+struct ubpf_vm *bpf_program__nth_vm(struct bpf_program *prog, int n)
+{
+ struct ubpf_vm *vm;
+
+ if (prog->engine != ENGINE_UBPF) {
+ pr_warning("Can't get ubpf_vm from program %s: engine not UBPF or not loaded\n",
+ prog->section_name);
+ return ERR_PTR(-EINVAL);
+ }
+
+ if (n >= prog->instances.nr || n < 0) {
+ pr_warning("Can't get the %dth vm from program %s: only %d instances\n",
+ n, prog->section_name, prog->instances.nr);
+ return ERR_PTR(-EINVAL);
+ }
+
+ vm = prog->instances.array[n].vm;
+ if (!vm) {
+ pr_warning("%dth instance of program '%s' is invalid\n",
+ n, prog->section_name);
+ return ERR_PTR(-ENOENT);
+ }
+
+ return vm;
+}
+
int bpf_program__set_ubpf(struct bpf_program *prog)
{
if (prog->engine != ENGINE_UNKNOWN) {
@@ -1454,6 +1485,13 @@ bool bpf_program__is_ubpf(struct bpf_program *prog __maybe_unused)
{
return false;
}
+
+struct ubpf_vm *
+bpf_program__nth_vm(struct bpf_program *prog __maybe_unused,
+ int n __maybe_unused)
+{
+ return ERR_PTR(-LIBBPF_ERRNO__NOUBPF);
+}
#endif
int bpf_map__get_fd(struct bpf_map *map)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 8e69c6f..41c35fd 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -92,6 +92,7 @@ int bpf_program__set_ubpf(struct bpf_program *prog);
bool bpf_program__is_ubpf(struct bpf_program *prog);
int bpf_program__fd(struct bpf_program *prog);
+struct ubpf_vm *bpf_program__vm(struct bpf_program *prog);
struct bpf_insn;
@@ -162,6 +163,7 @@ int bpf_program__set_prep(struct bpf_program *prog, int nr_instance,
bpf_program_prep_t prep);
int bpf_program__nth_fd(struct bpf_program *prog, int n);
+struct ubpf_vm *bpf_program__nth_vm(struct bpf_program *prog, int n);
/*
* We don't need __attribute__((packed)) now since it is
--
1.8.3.4
Powered by blists - more mailing lists