diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-08-07 15:19:05 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-08-08 14:55:58 -0400 |
commit | 78e890ea8683f7d570f911637b23b23d27be4aed (patch) | |
tree | 06e74fa399e98744f89cc77ea1b41151726ca541 | |
parent | e0b6d2ef329098bd9780ec00a75db3b11922031a (diff) |
perf bpf: Make bpf__setup_output_event() return the bpf-output event
We're calling it to setup that event, and we'll need it later to decide
if the bpf-output event we're handling is the one setup for a specific
purpose, return it using ERR_PTR, etc.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-zhachv7il2n1lopt9aonwhu7@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-trace.c | 9 | ||||
-rw-r--r-- | tools/perf/util/bpf-loader.c | 23 | ||||
-rw-r--r-- | tools/perf/util/bpf-loader.h | 7 |
3 files changed, 21 insertions, 18 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 9b4e24217c46..43a699cfcadf 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -3216,8 +3216,9 @@ int cmd_trace(int argc, const char **argv) | |||
3216 | }; | 3216 | }; |
3217 | bool __maybe_unused max_stack_user_set = true; | 3217 | bool __maybe_unused max_stack_user_set = true; |
3218 | bool mmap_pages_user_set = true; | 3218 | bool mmap_pages_user_set = true; |
3219 | struct perf_evsel *evsel; | ||
3219 | const char * const trace_subcommands[] = { "record", NULL }; | 3220 | const char * const trace_subcommands[] = { "record", NULL }; |
3220 | int err; | 3221 | int err = -1; |
3221 | char bf[BUFSIZ]; | 3222 | char bf[BUFSIZ]; |
3222 | 3223 | ||
3223 | signal(SIGSEGV, sighandler_dump_stack); | 3224 | signal(SIGSEGV, sighandler_dump_stack); |
@@ -3240,9 +3241,9 @@ int cmd_trace(int argc, const char **argv) | |||
3240 | "cgroup monitoring only available in system-wide mode"); | 3241 | "cgroup monitoring only available in system-wide mode"); |
3241 | } | 3242 | } |
3242 | 3243 | ||
3243 | err = bpf__setup_output_event(trace.evlist, "__augmented_syscalls__"); | 3244 | evsel = bpf__setup_output_event(trace.evlist, "__augmented_syscalls__"); |
3244 | if (err) { | 3245 | if (IS_ERR(evsel)) { |
3245 | bpf__strerror_setup_output_event(trace.evlist, err, bf, sizeof(bf)); | 3246 | bpf__strerror_setup_output_event(trace.evlist, PTR_ERR(evsel), bf, sizeof(bf)); |
3246 | pr_err("ERROR: Setup trace syscalls enter failed: %s\n", bf); | 3247 | pr_err("ERROR: Setup trace syscalls enter failed: %s\n", bf); |
3247 | goto out; | 3248 | goto out; |
3248 | } | 3249 | } |
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 80dead642719..47aac41349a2 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c | |||
@@ -1535,7 +1535,7 @@ int bpf__apply_obj_config(void) | |||
1535 | (strcmp(name, \ | 1535 | (strcmp(name, \ |
1536 | bpf_map__name(pos)) == 0)) | 1536 | bpf_map__name(pos)) == 0)) |
1537 | 1537 | ||
1538 | int bpf__setup_output_event(struct perf_evlist *evlist, const char *name) | 1538 | struct perf_evsel *bpf__setup_output_event(struct perf_evlist *evlist, const char *name) |
1539 | { | 1539 | { |
1540 | struct bpf_map_priv *tmpl_priv = NULL; | 1540 | struct bpf_map_priv *tmpl_priv = NULL; |
1541 | struct bpf_object *obj, *tmp; | 1541 | struct bpf_object *obj, *tmp; |
@@ -1548,7 +1548,7 @@ int bpf__setup_output_event(struct perf_evlist *evlist, const char *name) | |||
1548 | struct bpf_map_priv *priv = bpf_map__priv(map); | 1548 | struct bpf_map_priv *priv = bpf_map__priv(map); |
1549 | 1549 | ||
1550 | if (IS_ERR(priv)) | 1550 | if (IS_ERR(priv)) |
1551 | return -BPF_LOADER_ERRNO__INTERNAL; | 1551 | return ERR_PTR(-BPF_LOADER_ERRNO__INTERNAL); |
1552 | 1552 | ||
1553 | /* | 1553 | /* |
1554 | * No need to check map type: type should have been | 1554 | * No need to check map type: type should have been |
@@ -1561,20 +1561,20 @@ int bpf__setup_output_event(struct perf_evlist *evlist, const char *name) | |||
1561 | } | 1561 | } |
1562 | 1562 | ||
1563 | if (!need_init) | 1563 | if (!need_init) |
1564 | return 0; | 1564 | return NULL; |
1565 | 1565 | ||
1566 | if (!tmpl_priv) { | 1566 | if (!tmpl_priv) { |
1567 | char *event_definition = NULL; | 1567 | char *event_definition = NULL; |
1568 | 1568 | ||
1569 | if (asprintf(&event_definition, "bpf-output/no-inherit=1,name=%s/", name) < 0) | 1569 | if (asprintf(&event_definition, "bpf-output/no-inherit=1,name=%s/", name) < 0) |
1570 | return -ENOMEM; | 1570 | return ERR_PTR(-ENOMEM); |
1571 | 1571 | ||
1572 | err = parse_events(evlist, event_definition, NULL); | 1572 | err = parse_events(evlist, event_definition, NULL); |
1573 | free(event_definition); | 1573 | free(event_definition); |
1574 | 1574 | ||
1575 | if (err) { | 1575 | if (err) { |
1576 | pr_debug("ERROR: failed to create the \"%s\" bpf-output event\n", name); | 1576 | pr_debug("ERROR: failed to create the \"%s\" bpf-output event\n", name); |
1577 | return -err; | 1577 | return ERR_PTR(-err); |
1578 | } | 1578 | } |
1579 | 1579 | ||
1580 | evsel = perf_evlist__last(evlist); | 1580 | evsel = perf_evlist__last(evlist); |
@@ -1584,37 +1584,38 @@ int bpf__setup_output_event(struct perf_evlist *evlist, const char *name) | |||
1584 | struct bpf_map_priv *priv = bpf_map__priv(map); | 1584 | struct bpf_map_priv *priv = bpf_map__priv(map); |
1585 | 1585 | ||
1586 | if (IS_ERR(priv)) | 1586 | if (IS_ERR(priv)) |
1587 | return -BPF_LOADER_ERRNO__INTERNAL; | 1587 | return ERR_PTR(-BPF_LOADER_ERRNO__INTERNAL); |
1588 | if (priv) | 1588 | if (priv) |
1589 | continue; | 1589 | continue; |
1590 | 1590 | ||
1591 | if (tmpl_priv) { | 1591 | if (tmpl_priv) { |
1592 | priv = bpf_map_priv__clone(tmpl_priv); | 1592 | priv = bpf_map_priv__clone(tmpl_priv); |
1593 | if (!priv) | 1593 | if (!priv) |
1594 | return -ENOMEM; | 1594 | return ERR_PTR(-ENOMEM); |
1595 | 1595 | ||
1596 | err = bpf_map__set_priv(map, priv, bpf_map_priv__clear); | 1596 | err = bpf_map__set_priv(map, priv, bpf_map_priv__clear); |
1597 | if (err) { | 1597 | if (err) { |
1598 | bpf_map_priv__clear(map, priv); | 1598 | bpf_map_priv__clear(map, priv); |
1599 | return err; | 1599 | return ERR_PTR(err); |
1600 | } | 1600 | } |
1601 | } else if (evsel) { | 1601 | } else if (evsel) { |
1602 | struct bpf_map_op *op; | 1602 | struct bpf_map_op *op; |
1603 | 1603 | ||
1604 | op = bpf_map__add_newop(map, NULL); | 1604 | op = bpf_map__add_newop(map, NULL); |
1605 | if (IS_ERR(op)) | 1605 | if (IS_ERR(op)) |
1606 | return PTR_ERR(op); | 1606 | return ERR_PTR(PTR_ERR(op)); |
1607 | op->op_type = BPF_MAP_OP_SET_EVSEL; | 1607 | op->op_type = BPF_MAP_OP_SET_EVSEL; |
1608 | op->v.evsel = evsel; | 1608 | op->v.evsel = evsel; |
1609 | } | 1609 | } |
1610 | } | 1610 | } |
1611 | 1611 | ||
1612 | return 0; | 1612 | return evsel; |
1613 | } | 1613 | } |
1614 | 1614 | ||
1615 | int bpf__setup_stdout(struct perf_evlist *evlist) | 1615 | int bpf__setup_stdout(struct perf_evlist *evlist) |
1616 | { | 1616 | { |
1617 | return bpf__setup_output_event(evlist, "__bpf_stdout__"); | 1617 | struct perf_evsel *evsel = bpf__setup_output_event(evlist, "__bpf_stdout__"); |
1618 | return IS_ERR(evsel) ? PTR_ERR(evsel) : 0; | ||
1618 | } | 1619 | } |
1619 | 1620 | ||
1620 | #define ERRNO_OFFSET(e) ((e) - __BPF_LOADER_ERRNO__START) | 1621 | #define ERRNO_OFFSET(e) ((e) - __BPF_LOADER_ERRNO__START) |
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h index 8eca75145ac2..62d245a90e1d 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h | |||
@@ -43,6 +43,7 @@ enum bpf_loader_errno { | |||
43 | __BPF_LOADER_ERRNO__END, | 43 | __BPF_LOADER_ERRNO__END, |
44 | }; | 44 | }; |
45 | 45 | ||
46 | struct perf_evsel; | ||
46 | struct bpf_object; | 47 | struct bpf_object; |
47 | struct parse_events_term; | 48 | struct parse_events_term; |
48 | #define PERF_BPF_PROBE_GROUP "perf_bpf_probe" | 49 | #define PERF_BPF_PROBE_GROUP "perf_bpf_probe" |
@@ -82,7 +83,7 @@ int bpf__apply_obj_config(void); | |||
82 | int bpf__strerror_apply_obj_config(int err, char *buf, size_t size); | 83 | int bpf__strerror_apply_obj_config(int err, char *buf, size_t size); |
83 | 84 | ||
84 | int bpf__setup_stdout(struct perf_evlist *evlist); | 85 | int bpf__setup_stdout(struct perf_evlist *evlist); |
85 | int bpf__setup_output_event(struct perf_evlist *evlist, const char *name); | 86 | struct perf_evsel *bpf__setup_output_event(struct perf_evlist *evlist, const char *name); |
86 | int bpf__strerror_setup_output_event(struct perf_evlist *evlist, int err, char *buf, size_t size); | 87 | int bpf__strerror_setup_output_event(struct perf_evlist *evlist, int err, char *buf, size_t size); |
87 | #else | 88 | #else |
88 | #include <errno.h> | 89 | #include <errno.h> |
@@ -137,10 +138,10 @@ bpf__setup_stdout(struct perf_evlist *evlist __maybe_unused) | |||
137 | return 0; | 138 | return 0; |
138 | } | 139 | } |
139 | 140 | ||
140 | static inline int | 141 | static inline struct perf_evsel * |
141 | bpf__setup_output_event(struct perf_evlist *evlist __maybe_unused, const char *name __maybe_unused) | 142 | bpf__setup_output_event(struct perf_evlist *evlist __maybe_unused, const char *name __maybe_unused) |
142 | { | 143 | { |
143 | return 0; | 144 | return NULL; |
144 | } | 145 | } |
145 | 146 | ||
146 | static inline int | 147 | static inline int |