Skip to content

Commit

Permalink
perf bpf: Rename bpf__foreach_tev() to bpf__foreach_event()
Browse files Browse the repository at this point in the history
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: Wang Nan <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Zefan Li <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
WangNan0 authored and acmel committed Jul 14, 2016
1 parent 8c619d6 commit cd102d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions tools/perf/util/bpf-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,9 @@ int bpf__load(struct bpf_object *obj)
return 0;
}

int bpf__foreach_tev(struct bpf_object *obj,
bpf_prog_iter_callback_t func,
void *arg)
int bpf__foreach_event(struct bpf_object *obj,
bpf_prog_iter_callback_t func,
void *arg)
{
struct bpf_program *prog;
int err;
Expand Down Expand Up @@ -728,7 +728,7 @@ int bpf__foreach_tev(struct bpf_object *obj,
return fd;
}

err = (*func)(tev, fd, arg);
err = (*func)(tev->group, tev->event, fd, arg);
if (err) {
pr_debug("bpf: call back failed, stop iterate\n");
return err;
Expand Down
12 changes: 6 additions & 6 deletions tools/perf/util/bpf-loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct bpf_object;
struct parse_events_term;
#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);

#ifdef HAVE_LIBBPF_SUPPORT
Expand All @@ -67,8 +67,8 @@ int bpf__strerror_probe(struct bpf_object *obj, int err,
int bpf__load(struct bpf_object *obj);
int bpf__strerror_load(struct bpf_object *obj, int err,
char *buf, size_t size);
int bpf__foreach_tev(struct bpf_object *obj,
bpf_prog_iter_callback_t func, void *arg);
int bpf__foreach_event(struct bpf_object *obj,
bpf_prog_iter_callback_t func, void *arg);

int bpf__config_obj(struct bpf_object *obj, struct parse_events_term *term,
struct perf_evlist *evlist, int *error_pos);
Expand Down Expand Up @@ -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__foreach_tev(struct bpf_object *obj __maybe_unused,
bpf_prog_iter_callback_t func __maybe_unused,
void *arg __maybe_unused)
bpf__foreach_event(struct bpf_object *obj __maybe_unused,
bpf_prog_iter_callback_t func __maybe_unused,
void *arg __maybe_unused)
{
return 0;
}
Expand Down
16 changes: 8 additions & 8 deletions tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ struct __add_bpf_event_param {
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)
{
LIST_HEAD(new_evsels);
Expand All @@ -595,27 +595,27 @@ static int add_bpf_event(struct probe_trace_event *tev, int fd,
int err;

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,
tev->event, evlist->error,
err = parse_events_add_tracepoint(&new_evsels, &evlist->idx, group,
event, evlist->error,
param->head_config);
if (err) {
struct perf_evsel *evsel, *tmp;

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_del(&evsel->node);
perf_evsel__delete(evsel);
}
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) {
pr_debug("adding %s:%s to %p\n",
tev->group, tev->event, pos);
group, event, pos);
pos->bpf_fd = fd;
}
list_splice(&new_evsels, list);
Expand Down Expand Up @@ -661,7 +661,7 @@ int parse_events_load_bpf_obj(struct parse_events_evlist *data,
goto errout;
}

err = bpf__foreach_tev(obj, add_bpf_event, &param);
err = bpf__foreach_event(obj, add_bpf_event, &param);
if (err) {
snprintf(errbuf, sizeof(errbuf),
"Attach events in BPF object failed");
Expand Down

0 comments on commit cd102d7

Please sign in to comment.