Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1339255
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 09/48] perf tools: Pass tracepoint options to BPF script |
| Date | 2016-02-22 10:20 +0100 |
| Message-ID | <r4UOT-3pt-41@gated-at.bofh.it> (permalink) |
| References | <r4UOR-3pt-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Users can pass options to tracepoints defined in the BPF script.
For example:
# perf record -e ./test.c/no-inherit/ bash
# dd if=/dev/zero of=/dev/null count=10000
# exit
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.022 MB perf.data (139 samples) ]
(no-inherit works, only sys_read issued by bash is captured, at least
10000 sys_read issued by dd is skipped.)
test.c:
#define SEC(NAME) __attribute__((section(NAME), used))
SEC("func=sys_read")
int bpf_func__sys_read(void *ctx)
{
return 1;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
no-inherit is applied to the kprobe event defined in test.c.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
tools/perf/tests/bpf.c | 2 +-
tools/perf/util/parse-events.c | 56 +++++++++++++++++++++++++++++++++++++-----
tools/perf/util/parse-events.h | 3 ++-
3 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 4aed5cb..199501c 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -112,7 +112,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
parse_evlist.error = &parse_error;
INIT_LIST_HEAD(&parse_evlist.list);
- err = parse_events_load_bpf_obj(&parse_evlist, &parse_evlist.list, obj);
+ err = parse_events_load_bpf_obj(&parse_evlist, &parse_evlist.list, obj, NULL);
if (err || list_empty(&parse_evlist.list)) {
pr_debug("Failed to add events selected by BPF\n");
return TEST_FAIL;
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 6e2f203..4c19d5e 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -581,6 +581,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
struct __add_bpf_event_param {
struct parse_events_evlist *data;
struct list_head *list;
+ struct list_head *head_config;
};
static int add_bpf_event(struct probe_trace_event *tev, int fd,
@@ -597,7 +598,8 @@ static int add_bpf_event(struct probe_trace_event *tev, int fd,
tev->group, tev->event, fd);
err = parse_events_add_tracepoint(&new_evsels, &evlist->idx, tev->group,
- tev->event, evlist->error, NULL);
+ tev->event, evlist->error,
+ param->head_config);
if (err) {
struct perf_evsel *evsel, *tmp;
@@ -622,11 +624,12 @@ static int add_bpf_event(struct probe_trace_event *tev, int fd,
int parse_events_load_bpf_obj(struct parse_events_evlist *data,
struct list_head *list,
- struct bpf_object *obj)
+ struct bpf_object *obj,
+ struct list_head *head_config)
{
int err;
char errbuf[BUFSIZ];
- struct __add_bpf_event_param param = {data, list};
+ struct __add_bpf_event_param param = {data, list, head_config};
static bool registered_unprobe_atexit = false;
if (IS_ERR(obj) || !obj) {
@@ -720,14 +723,47 @@ parse_events_config_bpf(struct parse_events_evlist *data,
return 0;
}
+/*
+ * Split config terms:
+ * perf record -e bpf.c/call-graph=fp,map:array.value[0]=1/ ...
+ * 'call-graph=fp' is 'evt config', should be applied to each
+ * events in bpf.c.
+ * 'map:array.value[0]=1' is 'obj config', should be processed
+ * with parse_events_config_bpf.
+ *
+ * Move object config terms from the first list to obj_head_config.
+ */
+static void
+split_bpf_config_terms(struct list_head *evt_head_config,
+ struct list_head *obj_head_config)
+{
+ struct parse_events_term *term, *temp;
+
+ /*
+ * Currectly, all possible user config term
+ * belong to bpf object. parse_events__is_hardcoded_term()
+ * happends to be a good flag.
+ *
+ * See parse_events_config_bpf() and
+ * config_term_tracepoint().
+ */
+ list_for_each_entry_safe(term, temp, evt_head_config, list)
+ if (!parse_events__is_hardcoded_term(term))
+ list_move_tail(&term->list, obj_head_config);
+}
+
int parse_events_load_bpf(struct parse_events_evlist *data,
struct list_head *list,
char *bpf_file_name,
bool source,
struct list_head *head_config)
{
- struct bpf_object *obj;
int err;
+ struct bpf_object *obj;
+ LIST_HEAD(obj_head_config);
+
+ if (head_config)
+ split_bpf_config_terms(head_config, &obj_head_config);
obj = bpf__prepare_load(bpf_file_name, source);
if (IS_ERR(obj)) {
@@ -749,10 +785,18 @@ int parse_events_load_bpf(struct parse_events_evlist *data,
return err;
}
- err = parse_events_load_bpf_obj(data, list, obj);
+ err = parse_events_load_bpf_obj(data, list, obj, head_config);
if (err)
return err;
- return parse_events_config_bpf(data, obj, head_config);
+ err = parse_events_config_bpf(data, obj, &obj_head_config);
+
+ /*
+ * Caller doesn't know anything about obj_head_config,
+ * so combine them together again before returnning.
+ */
+ if (head_config)
+ list_splice_tail(&obj_head_config, head_config);
+ return err;
}
static int
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index e445622..67e4930 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -146,7 +146,8 @@ int parse_events_load_bpf(struct parse_events_evlist *data,
struct bpf_object;
int parse_events_load_bpf_obj(struct parse_events_evlist *data,
struct list_head *list,
- struct bpf_object *obj);
+ struct bpf_object *obj,
+ struct list_head *head_config);
int parse_events_add_numeric(struct parse_events_evlist *data,
struct list_head *list,
u32 type, u64 config,
--
1.8.3.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/48] perf tools: Bugfix, BPF improvements and overwrite ring buffer support Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:20 +0100 [PATCH 15/48] perf core: Prepare writing into ring buffer from end Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:20 +0100 [PATCH 28/48] perf record: Disable buildid cache options by default in switch output mode Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:20 +0100 [PATCH 09/48] perf tools: Pass tracepoint options to BPF script Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:20 +0100 [PATCH 27/48] perf record: Force enable --timestamp-filename when --switch-output is provided Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:20 +0100 [PATCH 31/48] perf record: Ensure return non-zero rc when mmap fail Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:20 +0100 [PATCH 19/48] perf tools: Print write_backward value in perf_event_attr__fprintf Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:20 +0100 [PATCH 40/48] perf tools: Enable overwrite settings Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:20 +0100 [PATCH 22/48] perf tools: Add perf_data_file__switch() helper Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 25/48] perf record: Add '--timestamp-filename' option to append timestamp to output filename Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 18/48] perf tools: Only validate is_pos for tracking evsels Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 17/48] perf core: Reduce perf event output overhead by new overflow handler Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 39/48] perf tools: Detect avalibility of write_backward Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 02/48] perf tools: Adjust symbol for shared objects Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 34/48] perf tools: Automatically add new channel according to evlist Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 43/48] perf tools: Add API to pause a channel Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 04/48] perf tools: Enable BPF object configure syntax Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 44/48] perf record: Toggle overwrite ring buffer for reading Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 32/48] perf record: Prevent reading invalid data in record__mmap_read Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 21/48] perf record: Extract synthesize code to record__synthesize() Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 11/48] perf data: Support converting data from bpf_perf_event_output() Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:30 +0100 [PATCH 05/48] perf record: Apply config to BPF objects before recording Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 01/48] perf tools: Record text offset in dso to calculate objdump address Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 24/48] perf record: Introduce record__finish_output() to finish a perf.data Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 07/48] perf tools: Support setting different slots in a BPF map separately Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 47/48] perf record: Allow generate tracking events at the end of output Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 38/48] perf record: Don't poll on overwrite channel Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 48/48] perf tools: Don't warn about out of order event if write_backward is used Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 06/48] perf tools: Enable passing event to BPF object Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 42/48] perf tools: Record fd into perf_mmap Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 20/48] perf tools: Make ordered_events reusable Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 16/48] perf core: Add backward attribute to perf event Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 29/48] perf record: Re-synthesize tracking events after output switching Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 12/48] perf data: Explicitly set byte order for integer types Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100 [PATCH 03/48] perf bpf: Add API to set values to map entries in a bpf object Wang Nan <wangnan0@huawei.com> - 2016-02-22 10:40 +0100
csiph-web