mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 08/13] bpf tools: Add API for fetching ubpf_vm
Date: Wed, 20 Apr 2016 18:01:48 +0000	[thread overview]
Message-ID: <1461175313-38310-9-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <1461175313-38310-1-git-send-email-wangnan0@huawei.com>

Introduce bpf_program__vm and bpf_program__nth_vm for fetching ubpf
program instance.

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 |  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

  parent reply	other threads:[~2016-04-20 18:04 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 ` Wang Nan [this message]
2016-04-20 18:01 ` [RFC PATCH 09/13] bpf tools: Register extern functions for ubpf programs Wang Nan
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-9-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®