perf test: Enhance the LLVM tests: add kbuild test
[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>
d3e0ce39 11#include <bpf/libbpf.h>
4edf30e3 12#include "probe-event.h"
69d262a9
WN
13#include "debug.h"
14
d3e0ce39
WN
15enum bpf_loader_errno {
16 __BPF_LOADER_ERRNO__START = __LIBBPF_ERRNO__START - 100,
17 /* Invalid config string */
18 BPF_LOADER_ERRNO__CONFIG = __BPF_LOADER_ERRNO__START,
19 BPF_LOADER_ERRNO__GROUP, /* Invalid group name */
20 BPF_LOADER_ERRNO__EVENTNAME, /* Event name is missing */
21 BPF_LOADER_ERRNO__INTERNAL, /* BPF loader internal error */
22 BPF_LOADER_ERRNO__COMPILE, /* Error when compiling BPF scriptlet */
23 __BPF_LOADER_ERRNO__END,
24};
25
69d262a9 26struct bpf_object;
aa3abf30 27#define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
69d262a9 28
4edf30e3
WN
29typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev,
30 int fd, void *arg);
31
69d262a9 32#ifdef HAVE_LIBBPF_SUPPORT
d509db04 33struct bpf_object *bpf__prepare_load(const char *filename, bool source);
d3e0ce39
WN
34int bpf__strerror_prepare_load(const char *filename, bool source,
35 int err, char *buf, size_t size);
69d262a9
WN
36
37void bpf__clear(void);
aa3abf30
WN
38
39int bpf__probe(struct bpf_object *obj);
40int bpf__unprobe(struct bpf_object *obj);
41int bpf__strerror_probe(struct bpf_object *obj, int err,
42 char *buf, size_t size);
43
1e5e3ee8
WN
44int bpf__load(struct bpf_object *obj);
45int bpf__strerror_load(struct bpf_object *obj, int err,
46 char *buf, size_t size);
4edf30e3
WN
47int bpf__foreach_tev(struct bpf_object *obj,
48 bpf_prog_iter_callback_t func, void *arg);
69d262a9
WN
49#else
50static inline struct bpf_object *
d509db04
WN
51bpf__prepare_load(const char *filename __maybe_unused,
52 bool source __maybe_unused)
69d262a9
WN
53{
54 pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
55 return ERR_PTR(-ENOTSUP);
56}
57
58static inline void bpf__clear(void) { }
aa3abf30
WN
59
60static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
61static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
1e5e3ee8 62static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
aa3abf30 63
4edf30e3
WN
64static inline int
65bpf__foreach_tev(struct bpf_object *obj __maybe_unused,
66 bpf_prog_iter_callback_t func __maybe_unused,
67 void *arg __maybe_unused)
68{
69 return 0;
70}
71
aa3abf30
WN
72static inline int
73__bpf_strerror(char *buf, size_t size)
74{
75 if (!size)
76 return 0;
77 strncpy(buf,
78 "ERROR: eBPF object loading is disabled during compiling.\n",
79 size);
80 buf[size - 1] = '\0';
81 return 0;
82}
83
d3e0ce39
WN
84static inline
85int bpf__strerror_prepare_load(const char *filename __maybe_unused,
86 bool source __maybe_unused,
87 int err __maybe_unused,
88 char *buf, size_t size)
89{
90 return __bpf_strerror(buf, size);
91}
92
aa3abf30
WN
93static inline int
94bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
95 int err __maybe_unused,
96 char *buf, size_t size)
97{
98 return __bpf_strerror(buf, size);
99}
1e5e3ee8
WN
100
101static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused,
102 int err __maybe_unused,
103 char *buf, size_t size)
104{
105 return __bpf_strerror(buf, size);
106}
69d262a9
WN
107#endif
108#endif