1 #include <linux/ptrace.h>
2 #include <linux/version.h>
3 #include <uapi/linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
7 __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
8 __uint(key_size, sizeof(int));
9 __uint(value_size, sizeof(u32));
10 __uint(max_entries, 64);
11 } counters SEC(".maps");
14 __uint(type, BPF_MAP_TYPE_HASH);
17 __uint(max_entries, 64);
18 } values SEC(".maps");
21 __uint(type, BPF_MAP_TYPE_HASH);
23 __type(value, struct bpf_perf_event_value);
24 __uint(max_entries, 64);
25 } values2 SEC(".maps");
27 SEC("kprobe/htab_map_get_next_key")
28 int bpf_prog1(struct pt_regs *ctx)
30 u32 key = bpf_get_smp_processor_id();
34 count = bpf_perf_event_read(&counters, key);
36 if (error <= -2 && error >= -22)
39 val = bpf_map_lookup_elem(&values, &key);
43 bpf_map_update_elem(&values, &key, &count, BPF_NOEXIST);
48 SEC("kprobe/htab_map_lookup_elem")
49 int bpf_prog2(struct pt_regs *ctx)
51 u32 key = bpf_get_smp_processor_id();
52 struct bpf_perf_event_value *val, buf;
55 error = bpf_perf_event_read_value(&counters, key, &buf, sizeof(buf));
59 val = bpf_map_lookup_elem(&values2, &key);
63 bpf_map_update_elem(&values2, &key, &buf, BPF_NOEXIST);
68 char _license[] SEC("license") = "GPL";
69 u32 _version SEC("version") = LINUX_VERSION_CODE;