diff options
Diffstat (limited to 'tools/testing/selftests/bpf/test_stacktrace_build_id.c')
-rw-r--r-- | tools/testing/selftests/bpf/test_stacktrace_build_id.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/tools/testing/selftests/bpf/test_stacktrace_build_id.c b/tools/testing/selftests/bpf/test_stacktrace_build_id.c index b755bd783ce5..d86c281e957f 100644 --- a/tools/testing/selftests/bpf/test_stacktrace_build_id.c +++ b/tools/testing/selftests/bpf/test_stacktrace_build_id.c | |||
@@ -19,7 +19,7 @@ struct bpf_map_def SEC("maps") stackid_hmap = { | |||
19 | .type = BPF_MAP_TYPE_HASH, | 19 | .type = BPF_MAP_TYPE_HASH, |
20 | .key_size = sizeof(__u32), | 20 | .key_size = sizeof(__u32), |
21 | .value_size = sizeof(__u32), | 21 | .value_size = sizeof(__u32), |
22 | .max_entries = 10000, | 22 | .max_entries = 16384, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | struct bpf_map_def SEC("maps") stackmap = { | 25 | struct bpf_map_def SEC("maps") stackmap = { |
@@ -31,6 +31,14 @@ struct bpf_map_def SEC("maps") stackmap = { | |||
31 | .map_flags = BPF_F_STACK_BUILD_ID, | 31 | .map_flags = BPF_F_STACK_BUILD_ID, |
32 | }; | 32 | }; |
33 | 33 | ||
34 | struct bpf_map_def SEC("maps") stack_amap = { | ||
35 | .type = BPF_MAP_TYPE_ARRAY, | ||
36 | .key_size = sizeof(__u32), | ||
37 | .value_size = sizeof(struct bpf_stack_build_id) | ||
38 | * PERF_MAX_STACK_DEPTH, | ||
39 | .max_entries = 128, | ||
40 | }; | ||
41 | |||
34 | /* taken from /sys/kernel/debug/tracing/events/random/urandom_read/format */ | 42 | /* taken from /sys/kernel/debug/tracing/events/random/urandom_read/format */ |
35 | struct random_urandom_args { | 43 | struct random_urandom_args { |
36 | unsigned long long pad; | 44 | unsigned long long pad; |
@@ -42,7 +50,10 @@ struct random_urandom_args { | |||
42 | SEC("tracepoint/random/urandom_read") | 50 | SEC("tracepoint/random/urandom_read") |
43 | int oncpu(struct random_urandom_args *args) | 51 | int oncpu(struct random_urandom_args *args) |
44 | { | 52 | { |
53 | __u32 max_len = sizeof(struct bpf_stack_build_id) | ||
54 | * PERF_MAX_STACK_DEPTH; | ||
45 | __u32 key = 0, val = 0, *value_p; | 55 | __u32 key = 0, val = 0, *value_p; |
56 | void *stack_p; | ||
46 | 57 | ||
47 | value_p = bpf_map_lookup_elem(&control_map, &key); | 58 | value_p = bpf_map_lookup_elem(&control_map, &key); |
48 | if (value_p && *value_p) | 59 | if (value_p && *value_p) |
@@ -50,8 +61,13 @@ int oncpu(struct random_urandom_args *args) | |||
50 | 61 | ||
51 | /* The size of stackmap and stackid_hmap should be the same */ | 62 | /* The size of stackmap and stackid_hmap should be the same */ |
52 | key = bpf_get_stackid(args, &stackmap, BPF_F_USER_STACK); | 63 | key = bpf_get_stackid(args, &stackmap, BPF_F_USER_STACK); |
53 | if ((int)key >= 0) | 64 | if ((int)key >= 0) { |
54 | bpf_map_update_elem(&stackid_hmap, &key, &val, 0); | 65 | bpf_map_update_elem(&stackid_hmap, &key, &val, 0); |
66 | stack_p = bpf_map_lookup_elem(&stack_amap, &key); | ||
67 | if (stack_p) | ||
68 | bpf_get_stack(args, stack_p, max_len, | ||
69 | BPF_F_USER_STACK | BPF_F_USER_BUILD_ID); | ||
70 | } | ||
55 | 71 | ||
56 | return 0; | 72 | return 0; |
57 | } | 73 | } |