Commit | Line | Data |
---|---|---|
5ed3ccbd | 1 | #include <linux/ptrace.h> |
47efb302 KX |
2 | #include <linux/version.h> |
3 | #include <uapi/linux/bpf.h> | |
4 | #include "bpf_helpers.h" | |
5 | ||
41e9a804 | 6 | struct bpf_map_def SEC("maps") counters = { |
47efb302 KX |
7 | .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, |
8 | .key_size = sizeof(int), | |
9 | .value_size = sizeof(u32), | |
41e9a804 TQ |
10 | .max_entries = 64, |
11 | }; | |
12 | struct bpf_map_def SEC("maps") values = { | |
13 | .type = BPF_MAP_TYPE_HASH, | |
14 | .key_size = sizeof(int), | |
15 | .value_size = sizeof(u64), | |
16 | .max_entries = 64, | |
47efb302 KX |
17 | }; |
18 | ||
41e9a804 | 19 | SEC("kprobe/htab_map_get_next_key") |
47efb302 KX |
20 | int bpf_prog1(struct pt_regs *ctx) |
21 | { | |
47efb302 | 22 | u32 key = bpf_get_smp_processor_id(); |
41e9a804 TQ |
23 | u64 count, *val; |
24 | s64 error; | |
25 | ||
26 | count = bpf_perf_event_read(&counters, key); | |
27 | error = (s64)count; | |
28 | if (error <= -2 && error >= -22) | |
29 | return 0; | |
47efb302 | 30 | |
41e9a804 TQ |
31 | val = bpf_map_lookup_elem(&values, &key); |
32 | if (val) | |
33 | *val = count; | |
34 | else | |
35 | bpf_map_update_elem(&values, &key, &count, BPF_NOEXIST); | |
47efb302 KX |
36 | |
37 | return 0; | |
38 | } | |
39 | ||
40 | char _license[] SEC("license") = "GPL"; | |
41 | u32 _version SEC("version") = LINUX_VERSION_CODE; |