Commit 12fe1225 authored by Teng Qin's avatar Teng Qin Committed by Daniel Borkmann

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: default avatarTeng Qin <qinteng@fb.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 95da0cdb
...@@ -39,6 +39,7 @@ int bpf_prog1(struct bpf_perf_event_data *ctx) ...@@ -39,6 +39,7 @@ int bpf_prog1(struct bpf_perf_event_data *ctx)
{ {
char time_fmt1[] = "Time Enabled: %llu, Time Running: %llu"; char time_fmt1[] = "Time Enabled: %llu, Time Running: %llu";
char time_fmt2[] = "Get Time Failed, ErrCode: %d"; char time_fmt2[] = "Get Time Failed, ErrCode: %d";
char addr_fmt[] = "Address recorded on event: %llx";
char fmt[] = "CPU-%d period %lld ip %llx"; char fmt[] = "CPU-%d period %lld ip %llx";
u32 cpu = bpf_get_smp_processor_id(); u32 cpu = bpf_get_smp_processor_id();
struct bpf_perf_event_value value_buf; struct bpf_perf_event_value value_buf;
...@@ -64,6 +65,9 @@ int bpf_prog1(struct bpf_perf_event_data *ctx) ...@@ -64,6 +65,9 @@ int bpf_prog1(struct bpf_perf_event_data *ctx)
else else
bpf_trace_printk(time_fmt2, sizeof(time_fmt2), ret); 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); val = bpf_map_lookup_elem(&counts, &key);
if (val) if (val)
(*val)++; (*val)++;
......
...@@ -215,6 +215,17 @@ static void test_bpf_perf_event(void) ...@@ -215,6 +215,17 @@ static void test_bpf_perf_event(void)
/* Intel Instruction Retired */ /* Intel Instruction Retired */
.config = 0xc0, .config = 0xc0,
}; };
struct perf_event_attr attr_type_raw_lock_load = {
.sample_freq = SAMPLE_FREQ,
.freq = 1,
.type = PERF_TYPE_RAW,
/* Intel MEM_UOPS_RETIRED.LOCK_LOADS */
.config = 0x21d0,
/* Request to record lock address from PEBS */
.sample_type = PERF_SAMPLE_ADDR,
/* Record address value requires precise event */
.precise_ip = 2,
};
printf("Test HW_CPU_CYCLES\n"); printf("Test HW_CPU_CYCLES\n");
test_perf_event_all_cpu(&attr_type_hw); test_perf_event_all_cpu(&attr_type_hw);
...@@ -236,6 +247,10 @@ static void test_bpf_perf_event(void) ...@@ -236,6 +247,10 @@ static void test_bpf_perf_event(void)
test_perf_event_all_cpu(&attr_type_raw); test_perf_event_all_cpu(&attr_type_raw);
test_perf_event_task(&attr_type_raw); test_perf_event_task(&attr_type_raw);
printf("Test Lock Load\n");
test_perf_event_all_cpu(&attr_type_raw_lock_load);
test_perf_event_task(&attr_type_raw_lock_load);
printf("*** PASS ***\n"); printf("*** PASS ***\n");
} }
......
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