[RFC PATCH v2 33/37] tools perf bpf: load eBPF object into kernel.

From: Wang Nan
Date: Fri May 15 2015 - 04:15:37 EST


This patch utilizes bpf_load_object() provided by libbpf to load all
objects into kernel.

Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
---
tools/perf/builtin-bpf.c | 5 +++++
tools/perf/util/bpf-loader.c | 16 ++++++++++++++++
tools/perf/util/bpf-loader.h | 3 ++-
3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-bpf.c b/tools/perf/builtin-bpf.c
index 95e0c65..8155f39 100644
--- a/tools/perf/builtin-bpf.c
+++ b/tools/perf/builtin-bpf.c
@@ -162,6 +162,11 @@ static int cmd_bpf_record(int argc, const char **argv,
goto errout;
}

+ if (bpf_load()) {
+ pr_err("bpf: failed to load\n");
+ goto errout;
+ }
+
return start_bpf_record(argc, argv);
usage:
usage_with_options(bpf_record_usage, options);
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index c820d1a..7295a3b 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -214,3 +214,19 @@ int bpf_probe(void)

return err < 0 ? err : 0;
}
+
+int bpf_load(void)
+{
+ size_t i;
+ int err;
+
+ for (i = 0; i < params.nr_objects; i++) {
+ err = bpf_load_object(params.objects[i]);
+ if (err) {
+ pr_err("failed to load object\n");
+ return err;
+ }
+ }
+
+ return 0;
+}
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index 30dea2e..1ccebdf 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -9,7 +9,8 @@

int bpf_prepare_load(const char *filename);
int bpf_probe(void);
-int bpf_unprobe(void);
+int bpf_load(void);

+int bpf_unprobe(void);
void bpf_clear(void);
#endif
--
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/