1 #include <linux/ptrace.h>
2 #include <linux/version.h>
3 #include <uapi/linux/bpf.h>
4 #include "bpf_helpers.h"
6 struct bpf_map_def
SEC("maps") counters
= {
7 .type
= BPF_MAP_TYPE_PERF_EVENT_ARRAY
,
8 .key_size
= sizeof(int),
9 .value_size
= sizeof(u32
),
12 struct bpf_map_def
SEC("maps") values
= {
13 .type
= BPF_MAP_TYPE_HASH
,
14 .key_size
= sizeof(int),
15 .value_size
= sizeof(u64
),
18 struct bpf_map_def
SEC("maps") values2
= {
19 .type
= BPF_MAP_TYPE_HASH
,
20 .key_size
= sizeof(int),
21 .value_size
= sizeof(struct bpf_perf_event_value
),
25 SEC("kprobe/htab_map_get_next_key")
26 int bpf_prog1(struct pt_regs
*ctx
)
28 u32 key
= bpf_get_smp_processor_id();
32 count
= bpf_perf_event_read(&counters
, key
);
34 if (error
<= -2 && error
>= -22)
37 val
= bpf_map_lookup_elem(&values
, &key
);
41 bpf_map_update_elem(&values
, &key
, &count
, BPF_NOEXIST
);
46 SEC("kprobe/htab_map_lookup_elem")
47 int bpf_prog2(struct pt_regs
*ctx
)
49 u32 key
= bpf_get_smp_processor_id();
50 struct bpf_perf_event_value
*val
, buf
;
53 error
= bpf_perf_event_read_value(&counters
, key
, &buf
, sizeof(buf
));
57 val
= bpf_map_lookup_elem(&values2
, &key
);
61 bpf_map_update_elem(&values2
, &key
, &buf
, BPF_NOEXIST
);
66 char _license
[] SEC("license") = "GPL";
67 u32 _version
SEC("version") = LINUX_VERSION_CODE
;