perf tools: Create probe points for BPF programs
[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
69d262a9
WN
26#else
27static inline struct bpf_object *
28bpf__prepare_load(const char *filename __maybe_unused)
29{
30 pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
31 return ERR_PTR(-ENOTSUP);
32}
33
34static inline void bpf__clear(void) { }
aa3abf30
WN
35
36static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
37static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
38
39static inline int
40__bpf_strerror(char *buf, size_t size)
41{
42 if (!size)
43 return 0;
44 strncpy(buf,
45 "ERROR: eBPF object loading is disabled during compiling.\n",
46 size);
47 buf[size - 1] = '\0';
48 return 0;
49}
50
51static inline int
52bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
53 int err __maybe_unused,
54 char *buf, size_t size)
55{
56 return __bpf_strerror(buf, size);
57}
69d262a9
WN
58#endif
59#endif