lkml.org 
[lkml]   [2016]   [Jun]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH v2 17/26] perf bpf: Add methods to set/check ubpf engine for bpf programs
Date
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@huawei.com>
Signed-off-by: Wang Nan <wangnan0@huawei.com>
---
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
\
 
 \ /
  Last update: 2016-06-26 14:01    [W:1.476 / U:0.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site