[RFC PATCH v2 17/26] perf bpf: Add methods to set/check ubpf engine for bpf programs

From: He Kuang
Date: Sun Jun 26 2016 - 07:25:51 EST


Add methods to set ubpf engine for a bpf program and to check whether
a program's engine is ubpf.

Signed-off-by: He Kuang <hekuang@xxxxxxxxxx>
Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
---
tools/lib/bpf/engine-ubpf.c | 12 ++++++++++++
tools/lib/bpf/libbpf.h | 17 +++++++++++++++++
2 files changed, 29 insertions(+)

diff --git a/tools/lib/bpf/engine-ubpf.c b/tools/lib/bpf/engine-ubpf.c
index 0ab3310..9a0b425 100644
--- a/tools/lib/bpf/engine-ubpf.c
+++ b/tools/lib/bpf/engine-ubpf.c
@@ -95,3 +95,15 @@ struct bpf_engine uengine = {
.unload = engine__unload,
.get_nth = engine__get_nth,
};
+
+int bpf_program__set_ubpf(struct bpf_program *prog)
+{
+ prog->engine = &uengine;
+
+ return 0;
+}
+
+bool bpf_program__is_ubpf(struct bpf_program *prog)
+{
+ return prog->engine == &uengine;
+}
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index b0e6c68..e01ab8e 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -27,6 +27,7 @@ enum libbpf_errno {
LIBBPF_ERRNO__PROG2BIG, /* Program too big */
LIBBPF_ERRNO__KVER, /* Incorrect kernel version */
LIBBPF_ERRNO__LOADUBPF, /* Failed to load user space BPF program */
+ LIBBPF_ERRNO__NOUBPF,/* UBPF support is not compiled */
__LIBBPF_ERRNO__END,
};

@@ -192,4 +193,20 @@ struct ubpf_entry {
struct bpf_insn *insns;
};

+#ifdef HAVE_UBPF_SUPPORT
+int bpf_program__set_ubpf(struct bpf_program *prog);
+bool bpf_program__is_ubpf(struct bpf_program *prog);
+#else
+static inline int
+bpf_program__set_ubpf(struct bpf_program *prog __maybe_unused)
+{
+ return -LIBBPF_ERRNO__NOUBPF;
+}
+static inline bool
+bpf_program__is_ubpf(struct bpf_program *prog __maybe_unused)
+{
+ return false;
+}
+#endif
+
#endif
--
1.8.5.2