perf bpf: Decouple creating the evlist from adding the SB event

Renaming bpf_event__add_sb_event() to evlist__add_sb_event() and
requiring that the evlist be allocated beforehand.

This will allow using the same side band thread and evlist to be used
for multiple purposes in addition to react to PERF_RECORD_BPF_EVENT soon
after they are generated.
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Song Liu <songliubraving@fb.com>
Link: http://lore.kernel.org/lkml/20200429131106.27974-4-acme@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent ca6c9c8b
...@@ -1573,16 +1573,27 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) ...@@ -1573,16 +1573,27 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
goto out_child; goto out_child;
} }
err = -1;
if (!rec->no_buildid if (!rec->no_buildid
&& !perf_header__has_feat(&session->header, HEADER_BUILD_ID)) { && !perf_header__has_feat(&session->header, HEADER_BUILD_ID)) {
pr_err("Couldn't generate buildids. " pr_err("Couldn't generate buildids. "
"Use --no-buildid to profile anyway.\n"); "Use --no-buildid to profile anyway.\n");
err = -1;
goto out_child; goto out_child;
} }
if (!opts->no_bpf_event) if (!opts->no_bpf_event) {
bpf_event__add_sb_event(&rec->sb_evlist, &session->header.env); rec->sb_evlist = evlist__new();
if (rec->sb_evlist == NULL) {
pr_err("Couldn't create side band evlist.\n.");
goto out_child;
}
if (evlist__add_bpf_sb_event(rec->sb_evlist, &session->header.env)) {
pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n.");
goto out_child;
}
}
if (perf_evlist__start_sb_thread(rec->sb_evlist, &rec->opts.target)) { if (perf_evlist__start_sb_thread(rec->sb_evlist, &rec->opts.target)) {
pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n"); pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n");
......
...@@ -1742,8 +1742,19 @@ int cmd_top(int argc, const char **argv) ...@@ -1742,8 +1742,19 @@ int cmd_top(int argc, const char **argv)
goto out_delete_evlist; goto out_delete_evlist;
} }
if (!top.record_opts.no_bpf_event) if (!top.record_opts.no_bpf_event) {
bpf_event__add_sb_event(&top.sb_evlist, &perf_env); top.sb_evlist = evlist__new();
if (top.sb_evlist == NULL) {
pr_err("Couldn't create side band evlist.\n.");
goto out_delete_evlist;
}
if (evlist__add_bpf_sb_event(top.sb_evlist, &perf_env)) {
pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n.");
goto out_delete_evlist;
}
}
if (perf_evlist__start_sb_thread(top.sb_evlist, target)) { if (perf_evlist__start_sb_thread(top.sb_evlist, target)) {
pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n"); pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n");
......
...@@ -509,8 +509,7 @@ static int bpf_event__sb_cb(union perf_event *event, void *data) ...@@ -509,8 +509,7 @@ static int bpf_event__sb_cb(union perf_event *event, void *data)
return 0; return 0;
} }
int bpf_event__add_sb_event(struct evlist **evlist, int evlist__add_bpf_sb_event(struct evlist *evlist, struct perf_env *env)
struct perf_env *env)
{ {
struct perf_event_attr attr = { struct perf_event_attr attr = {
.type = PERF_TYPE_SOFTWARE, .type = PERF_TYPE_SOFTWARE,
......
...@@ -33,8 +33,7 @@ struct btf_node { ...@@ -33,8 +33,7 @@ struct btf_node {
#ifdef HAVE_LIBBPF_SUPPORT #ifdef HAVE_LIBBPF_SUPPORT
int machine__process_bpf(struct machine *machine, union perf_event *event, int machine__process_bpf(struct machine *machine, union perf_event *event,
struct perf_sample *sample); struct perf_sample *sample);
int bpf_event__add_sb_event(struct evlist **evlist, int evlist__add_bpf_sb_event(struct evlist *evlist, struct perf_env *env);
struct perf_env *env);
void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info, void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info,
struct perf_env *env, struct perf_env *env,
FILE *fp); FILE *fp);
...@@ -46,8 +45,8 @@ static inline int machine__process_bpf(struct machine *machine __maybe_unused, ...@@ -46,8 +45,8 @@ static inline int machine__process_bpf(struct machine *machine __maybe_unused,
return 0; return 0;
} }
static inline int bpf_event__add_sb_event(struct evlist **evlist __maybe_unused, static inline int evlist__add_bpf_sb_event(struct evlist *evlist __maybe_unused,
struct perf_env *env __maybe_unused) struct perf_env *env __maybe_unused)
{ {
return 0; return 0;
} }
......
...@@ -1705,39 +1705,26 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list, ...@@ -1705,39 +1705,26 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list,
return leader; return leader;
} }
int perf_evlist__add_sb_event(struct evlist **evlist, int perf_evlist__add_sb_event(struct evlist *evlist,
struct perf_event_attr *attr, struct perf_event_attr *attr,
perf_evsel__sb_cb_t cb, perf_evsel__sb_cb_t cb,
void *data) void *data)
{ {
struct evsel *evsel; struct evsel *evsel;
bool new_evlist = (*evlist) == NULL;
if (*evlist == NULL)
*evlist = evlist__new();
if (*evlist == NULL)
return -1;
if (!attr->sample_id_all) { if (!attr->sample_id_all) {
pr_warning("enabling sample_id_all for all side band events\n"); pr_warning("enabling sample_id_all for all side band events\n");
attr->sample_id_all = 1; attr->sample_id_all = 1;
} }
evsel = perf_evsel__new_idx(attr, (*evlist)->core.nr_entries); evsel = perf_evsel__new_idx(attr, evlist->core.nr_entries);
if (!evsel) if (!evsel)
goto out_err; return -1;
evsel->side_band.cb = cb; evsel->side_band.cb = cb;
evsel->side_band.data = data; evsel->side_band.data = data;
evlist__add(*evlist, evsel); evlist__add(evlist, evsel);
return 0; return 0;
out_err:
if (new_evlist) {
evlist__delete(*evlist);
*evlist = NULL;
}
return -1;
} }
static void *perf_evlist__poll_thread(void *arg) static void *perf_evlist__poll_thread(void *arg)
......
...@@ -107,7 +107,7 @@ int __perf_evlist__add_default_attrs(struct evlist *evlist, ...@@ -107,7 +107,7 @@ int __perf_evlist__add_default_attrs(struct evlist *evlist,
int perf_evlist__add_dummy(struct evlist *evlist); int perf_evlist__add_dummy(struct evlist *evlist);
int perf_evlist__add_sb_event(struct evlist **evlist, int perf_evlist__add_sb_event(struct evlist *evlist,
struct perf_event_attr *attr, struct perf_event_attr *attr,
perf_evsel__sb_cb_t cb, perf_evsel__sb_cb_t cb,
void *data); void *data);
......
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