summaryrefslogtreecommitdiff
path: root/samples/bpf/trace_event_kern.c
diff options
context:
space:
mode:
authorTeng Qin <qinteng@fb.com>2018-03-06 21:55:02 +0300
committerDaniel Borkmann <daniel@iogearbox.net>2018-03-08 04:22:34 +0300
commit12fe12253c56a26e591ceefbdf0998b391022003 (patch)
tree822b9bb7680c97b84f98f8d471b297637048d473 /samples/bpf/trace_event_kern.c
parent95da0cdb723260362fc126a563285ac66a193da7 (diff)
downloadlinux-12fe12253c56a26e591ceefbdf0998b391022003.tar.xz
samples/bpf: add example to test reading address
This commit adds additional test in the trace_event example, by attaching the bpf program to MEM_UOPS_RETIRED.LOCK_LOADS event with PERF_SAMPLE_ADDR requested, and print the lock address value read from the bpf program to trace_pipe. Signed-off-by: Teng Qin <qinteng@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'samples/bpf/trace_event_kern.c')
-rw-r--r--samples/bpf/trace_event_kern.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/samples/bpf/trace_event_kern.c b/samples/bpf/trace_event_kern.c
index a77a583d94d4..7068fbdde951 100644
--- a/samples/bpf/trace_event_kern.c
+++ b/samples/bpf/trace_event_kern.c
@@ -39,6 +39,7 @@ int bpf_prog1(struct bpf_perf_event_data *ctx)
{
char time_fmt1[] = "Time Enabled: %llu, Time Running: %llu";
char time_fmt2[] = "Get Time Failed, ErrCode: %d";
+ char addr_fmt[] = "Address recorded on event: %llx";
char fmt[] = "CPU-%d period %lld ip %llx";
u32 cpu = bpf_get_smp_processor_id();
struct bpf_perf_event_value value_buf;
@@ -64,6 +65,9 @@ int bpf_prog1(struct bpf_perf_event_data *ctx)
else
bpf_trace_printk(time_fmt2, sizeof(time_fmt2), ret);
+ if (ctx->addr != 0)
+ bpf_trace_printk(addr_fmt, sizeof(addr_fmt), ctx->addr);
+
val = bpf_map_lookup_elem(&counts, &key);
if (val)
(*val)++;