perf tools: Load eBPF object into kernel
[linux-2.6-block.git] / tools / perf / util / bpf-loader.h
CommitLineData
69d262a9
WN
1/*
2 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
3 * Copyright (C) 2015, Huawei Inc.
4 */
5#ifndef __BPF_LOADER_H
6#define __BPF_LOADER_H
7
8#include <linux/compiler.h>
9#include <linux/err.h>
10#include <string.h>
11#include "debug.h"
12
13struct bpf_object;
aa3abf30 14#define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
69d262a9
WN
15
16#ifdef HAVE_LIBBPF_SUPPORT
17struct bpf_object *bpf__prepare_load(const char *filename);
18
19void bpf__clear(void);
aa3abf30
WN
20
21int bpf__probe(struct bpf_object *obj);
22int bpf__unprobe(struct bpf_object *obj);
23int bpf__strerror_probe(struct bpf_object *obj, int err,
24 char *buf, size_t size);
25
1e5e3ee8
WN
26int bpf__load(struct bpf_object *obj);
27int bpf__strerror_load(struct bpf_object *obj, int err,
28 char *buf, size_t size);
69d262a9
WN
29#else
30static inline struct bpf_object *
31bpf__prepare_load(const char *filename __maybe_unused)
32{
33 pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
34 return ERR_PTR(-ENOTSUP);
35}
36
37static inline void bpf__clear(void) { }
aa3abf30
WN
38
39static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
40static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
1e5e3ee8 41static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
aa3abf30
WN
42
43static inline int
44__bpf_strerror(char *buf, size_t size)
45{
46 if (!size)
47 return 0;
48 strncpy(buf,
49 "ERROR: eBPF object loading is disabled during compiling.\n",
50 size);
51 buf[size - 1] = '\0';
52 return 0;
53}
54
55static inline int
56bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
57 int err __maybe_unused,
58 char *buf, size_t size)
59{
60 return __bpf_strerror(buf, size);
61}
1e5e3ee8
WN
62
63static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused,
64 int err __maybe_unused,
65 char *buf, size_t size)
66{
67 return __bpf_strerror(buf, size);
68}
69d262a9
WN
69#endif
70#endif