]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - tools/perf/util/bpf-loader.h
Merge branch 'mkp-fixes' into fixes
[mirror_ubuntu-zesty-kernel.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 36
ba1fae43
WN
37struct bpf_object *bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz,
38 const char *name);
39
69d262a9 40void bpf__clear(void);
aa3abf30
WN
41
42int bpf__probe(struct bpf_object *obj);
43int bpf__unprobe(struct bpf_object *obj);
44int bpf__strerror_probe(struct bpf_object *obj, int err,
45 char *buf, size_t size);
46
1e5e3ee8
WN
47int bpf__load(struct bpf_object *obj);
48int bpf__strerror_load(struct bpf_object *obj, int err,
49 char *buf, size_t size);
4edf30e3
WN
50int bpf__foreach_tev(struct bpf_object *obj,
51 bpf_prog_iter_callback_t func, void *arg);
69d262a9
WN
52#else
53static inline struct bpf_object *
d509db04
WN
54bpf__prepare_load(const char *filename __maybe_unused,
55 bool source __maybe_unused)
69d262a9
WN
56{
57 pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
58 return ERR_PTR(-ENOTSUP);
59}
60
ba1fae43
WN
61static inline struct bpf_object *
62bpf__prepare_load_buffer(void *obj_buf __maybe_unused,
63 size_t obj_buf_sz __maybe_unused)
64{
65 return ERR_PTR(-ENOTSUP);
66}
67
69d262a9 68static inline void bpf__clear(void) { }
aa3abf30
WN
69
70static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
71static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
1e5e3ee8 72static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
aa3abf30 73
4edf30e3
WN
74static inline int
75bpf__foreach_tev(struct bpf_object *obj __maybe_unused,
76 bpf_prog_iter_callback_t func __maybe_unused,
77 void *arg __maybe_unused)
78{
79 return 0;
80}
81
aa3abf30
WN
82static inline int
83__bpf_strerror(char *buf, size_t size)
84{
85 if (!size)
86 return 0;
87 strncpy(buf,
88 "ERROR: eBPF object loading is disabled during compiling.\n",
89 size);
90 buf[size - 1] = '\0';
91 return 0;
92}
93
d3e0ce39
WN
94static inline
95int bpf__strerror_prepare_load(const char *filename __maybe_unused,
96 bool source __maybe_unused,
97 int err __maybe_unused,
98 char *buf, size_t size)
99{
100 return __bpf_strerror(buf, size);
101}
102
aa3abf30
WN
103static inline int
104bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
105 int err __maybe_unused,
106 char *buf, size_t size)
107{
108 return __bpf_strerror(buf, size);
109}
1e5e3ee8
WN
110
111static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused,
112 int err __maybe_unused,
113 char *buf, size_t size)
114{
115 return __bpf_strerror(buf, size);
116}
69d262a9
WN
117#endif
118#endif