aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2018-08-06 08:53:35 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-08-08 14:55:56 -0400
commit92bbe8d834d293c4db7a70fd53884ec1c95d61dc (patch)
treeafe584cfc5046cf4b01da805d6d5a4c370722bed /tools
parent5941d856a90435b32a3296c0b7df8f0075430b81 (diff)
perf bpf: Generalize bpf__setup_stdout()
We will use it to set up other bpf-output events, for instance to generate augmented syscall entry tracepoints with pointer contents. 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-4r7kw0nsyi4vyz6xm1tzx6a3@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/bpf-loader.c26
-rw-r--r--tools/perf/util/bpf-loader.h7
2 files changed, 24 insertions, 9 deletions
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index e864a7e0ff12..95a27bb6f1a1 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -1535,10 +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#define bpf__for_each_stdout_map(pos, obj, objtmp) \ 1538int bpf__setup_output_event(struct perf_evlist *evlist, const char *name)
1539 bpf__for_each_map_named(pos, obj, objtmp, "__bpf_stdout__")
1540
1541int bpf__setup_stdout(struct perf_evlist *evlist)
1542{ 1539{
1543 struct bpf_map_priv *tmpl_priv = NULL; 1540 struct bpf_map_priv *tmpl_priv = NULL;
1544 struct bpf_object *obj, *tmp; 1541 struct bpf_object *obj, *tmp;
@@ -1547,7 +1544,7 @@ int bpf__setup_stdout(struct perf_evlist *evlist)
1547 int err; 1544 int err;
1548 bool need_init = false; 1545 bool need_init = false;
1549 1546
1550 bpf__for_each_stdout_map(map, obj, tmp) { 1547 bpf__for_each_map_named(map, obj, tmp, name) {
1551 struct bpf_map_priv *priv = bpf_map__priv(map); 1548 struct bpf_map_priv *priv = bpf_map__priv(map);
1552 1549
1553 if (IS_ERR(priv)) 1550 if (IS_ERR(priv))
@@ -1567,17 +1564,23 @@ int bpf__setup_stdout(struct perf_evlist *evlist)
1567 return 0; 1564 return 0;
1568 1565
1569 if (!tmpl_priv) { 1566 if (!tmpl_priv) {
1570 err = parse_events(evlist, "bpf-output/no-inherit=1,name=__bpf_stdout__/", 1567 char *event_definition = NULL;
1571 NULL); 1568
1569 if (asprintf(&event_definition, "bpf-output/no-inherit=1,name=%s/", name) < 0)
1570 return -ENOMEM;
1571
1572 err = parse_events(evlist, event_definition, NULL);
1573 free(event_definition);
1574
1572 if (err) { 1575 if (err) {
1573 pr_debug("ERROR: failed to create bpf-output event\n"); 1576 pr_debug("ERROR: failed to create the \"%s\" bpf-output event\n", name);
1574 return -err; 1577 return -err;
1575 } 1578 }
1576 1579
1577 evsel = perf_evlist__last(evlist); 1580 evsel = perf_evlist__last(evlist);
1578 } 1581 }
1579 1582
1580 bpf__for_each_stdout_map(map, obj, tmp) { 1583 bpf__for_each_map_named(map, obj, tmp, name) {
1581 struct bpf_map_priv *priv = bpf_map__priv(map); 1584 struct bpf_map_priv *priv = bpf_map__priv(map);
1582 1585
1583 if (IS_ERR(priv)) 1586 if (IS_ERR(priv))
@@ -1609,6 +1612,11 @@ int bpf__setup_stdout(struct perf_evlist *evlist)
1609 return 0; 1612 return 0;
1610} 1613}
1611 1614
1615int bpf__setup_stdout(struct perf_evlist *evlist)
1616{
1617 return bpf__setup_output_event(evlist, "__bpf_stdout__");
1618}
1619
1612#define ERRNO_OFFSET(e) ((e) - __BPF_LOADER_ERRNO__START) 1620#define ERRNO_OFFSET(e) ((e) - __BPF_LOADER_ERRNO__START)
1613#define ERRCODE_OFFSET(c) ERRNO_OFFSET(BPF_LOADER_ERRNO__##c) 1621#define ERRCODE_OFFSET(c) ERRNO_OFFSET(BPF_LOADER_ERRNO__##c)
1614#define NR_ERRNO (__BPF_LOADER_ERRNO__END - __BPF_LOADER_ERRNO__START) 1622#define NR_ERRNO (__BPF_LOADER_ERRNO__END - __BPF_LOADER_ERRNO__START)
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index 5d3aefd6fae7..6be0eec043c6 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -82,6 +82,7 @@ int bpf__apply_obj_config(void);
82int bpf__strerror_apply_obj_config(int err, char *buf, size_t size); 82int bpf__strerror_apply_obj_config(int err, char *buf, size_t size);
83 83
84int bpf__setup_stdout(struct perf_evlist *evlist); 84int bpf__setup_stdout(struct perf_evlist *evlist);
85int bpf__setup_output_event(struct perf_evlist *evlist, const char *name);
85int bpf__strerror_setup_stdout(struct perf_evlist *evlist, int err, 86int bpf__strerror_setup_stdout(struct perf_evlist *evlist, int err,
86 char *buf, size_t size); 87 char *buf, size_t size);
87 88
@@ -139,6 +140,12 @@ bpf__setup_stdout(struct perf_evlist *evlist __maybe_unused)
139} 140}
140 141
141static inline int 142static inline int
143bpf__setup_output_event(struct perf_evlist *evlist __maybe_unused, const char *name __maybe_unused)
144{
145 return 0;
146}
147
148static inline int
142__bpf_strerror(char *buf, size_t size) 149__bpf_strerror(char *buf, size_t size)
143{ 150{
144 if (!size) 151 if (!size)