Commit cd102d70 authored by Wang Nan's avatar Wang Nan Committed by Arnaldo Carvalho de Melo

perf bpf: Rename bpf__foreach_tev() to bpf__foreach_event()

Following commit will allow BPF script attach to tracepoints.
bpf__foreach_tev() will iterate over all events, not only kprobes.
Rename it to bpf__foreach_event().

Since only group and event are used by caller, there's no need to pass
full 'struct probe_trace_event' to bpf_prog_iter_callback_t. Pass only
these two strings. After this patch bpf_prog_iter_callback_t natually
support tracepoints.
Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1468406646-21642-5-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 8c619d6a
...@@ -693,9 +693,9 @@ int bpf__load(struct bpf_object *obj) ...@@ -693,9 +693,9 @@ int bpf__load(struct bpf_object *obj)
return 0; return 0;
} }
int bpf__foreach_tev(struct bpf_object *obj, int bpf__foreach_event(struct bpf_object *obj,
bpf_prog_iter_callback_t func, bpf_prog_iter_callback_t func,
void *arg) void *arg)
{ {
struct bpf_program *prog; struct bpf_program *prog;
int err; int err;
...@@ -728,7 +728,7 @@ int bpf__foreach_tev(struct bpf_object *obj, ...@@ -728,7 +728,7 @@ int bpf__foreach_tev(struct bpf_object *obj,
return fd; return fd;
} }
err = (*func)(tev, fd, arg); err = (*func)(tev->group, tev->event, fd, arg);
if (err) { if (err) {
pr_debug("bpf: call back failed, stop iterate\n"); pr_debug("bpf: call back failed, stop iterate\n");
return err; return err;
......
...@@ -46,7 +46,7 @@ struct bpf_object; ...@@ -46,7 +46,7 @@ struct bpf_object;
struct parse_events_term; struct parse_events_term;
#define PERF_BPF_PROBE_GROUP "perf_bpf_probe" #define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev, typedef int (*bpf_prog_iter_callback_t)(const char *group, const char *event,
int fd, void *arg); int fd, void *arg);
#ifdef HAVE_LIBBPF_SUPPORT #ifdef HAVE_LIBBPF_SUPPORT
...@@ -67,8 +67,8 @@ int bpf__strerror_probe(struct bpf_object *obj, int err, ...@@ -67,8 +67,8 @@ int bpf__strerror_probe(struct bpf_object *obj, int err,
int bpf__load(struct bpf_object *obj); int bpf__load(struct bpf_object *obj);
int bpf__strerror_load(struct bpf_object *obj, int err, int bpf__strerror_load(struct bpf_object *obj, int err,
char *buf, size_t size); char *buf, size_t size);
int bpf__foreach_tev(struct bpf_object *obj, int bpf__foreach_event(struct bpf_object *obj,
bpf_prog_iter_callback_t func, void *arg); bpf_prog_iter_callback_t func, void *arg);
int bpf__config_obj(struct bpf_object *obj, struct parse_events_term *term, int bpf__config_obj(struct bpf_object *obj, struct parse_events_term *term,
struct perf_evlist *evlist, int *error_pos); struct perf_evlist *evlist, int *error_pos);
...@@ -107,9 +107,9 @@ static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0 ...@@ -107,9 +107,9 @@ static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0
static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; } static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
static inline int static inline int
bpf__foreach_tev(struct bpf_object *obj __maybe_unused, bpf__foreach_event(struct bpf_object *obj __maybe_unused,
bpf_prog_iter_callback_t func __maybe_unused, bpf_prog_iter_callback_t func __maybe_unused,
void *arg __maybe_unused) void *arg __maybe_unused)
{ {
return 0; return 0;
} }
......
...@@ -584,7 +584,7 @@ struct __add_bpf_event_param { ...@@ -584,7 +584,7 @@ struct __add_bpf_event_param {
struct list_head *head_config; struct list_head *head_config;
}; };
static int add_bpf_event(struct probe_trace_event *tev, int fd, static int add_bpf_event(const char *group, const char *event, int fd,
void *_param) void *_param)
{ {
LIST_HEAD(new_evsels); LIST_HEAD(new_evsels);
...@@ -595,27 +595,27 @@ static int add_bpf_event(struct probe_trace_event *tev, int fd, ...@@ -595,27 +595,27 @@ static int add_bpf_event(struct probe_trace_event *tev, int fd,
int err; int err;
pr_debug("add bpf event %s:%s and attach bpf program %d\n", pr_debug("add bpf event %s:%s and attach bpf program %d\n",
tev->group, tev->event, fd); group, event, fd);
err = parse_events_add_tracepoint(&new_evsels, &evlist->idx, tev->group, err = parse_events_add_tracepoint(&new_evsels, &evlist->idx, group,
tev->event, evlist->error, event, evlist->error,
param->head_config); param->head_config);
if (err) { if (err) {
struct perf_evsel *evsel, *tmp; struct perf_evsel *evsel, *tmp;
pr_debug("Failed to add BPF event %s:%s\n", pr_debug("Failed to add BPF event %s:%s\n",
tev->group, tev->event); group, event);
list_for_each_entry_safe(evsel, tmp, &new_evsels, node) { list_for_each_entry_safe(evsel, tmp, &new_evsels, node) {
list_del(&evsel->node); list_del(&evsel->node);
perf_evsel__delete(evsel); perf_evsel__delete(evsel);
} }
return err; return err;
} }
pr_debug("adding %s:%s\n", tev->group, tev->event); pr_debug("adding %s:%s\n", group, event);
list_for_each_entry(pos, &new_evsels, node) { list_for_each_entry(pos, &new_evsels, node) {
pr_debug("adding %s:%s to %p\n", pr_debug("adding %s:%s to %p\n",
tev->group, tev->event, pos); group, event, pos);
pos->bpf_fd = fd; pos->bpf_fd = fd;
} }
list_splice(&new_evsels, list); list_splice(&new_evsels, list);
...@@ -661,7 +661,7 @@ int parse_events_load_bpf_obj(struct parse_events_evlist *data, ...@@ -661,7 +661,7 @@ int parse_events_load_bpf_obj(struct parse_events_evlist *data,
goto errout; goto errout;
} }
err = bpf__foreach_tev(obj, add_bpf_event, &param); err = bpf__foreach_event(obj, add_bpf_event, &param);
if (err) { if (err) {
snprintf(errbuf, sizeof(errbuf), snprintf(errbuf, sizeof(errbuf),
"Attach events in BPF object failed"); "Attach events in BPF object failed");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment