Debian Codegraph @

examples/tracepoint_in_c/tracepoint.c

raw symbols SCIP
1 //go:build ignore
2
3 #include "common.h"
4
5 char __license[] SEC("license") = "Dual MIT/GPL";
6
7 struct {
8 __uint(type, BPF_MAP_TYPE_ARRAY);
9 __type(key, u32);
10 __type(value, u64);
11 __uint(max_entries, 1);
12 } counting_map SEC(".maps");
13
14 // This struct is defined according to the following format file:
15 // /sys/kernel/tracing/events/kmem/mm_page_alloc/format
16 struct alloc_info {
17 /* The first 8 bytes is not allowed to read */
18 unsigned long pad;
19
20 unsigned long pfn;
21 unsigned int order;
22 unsigned int gfp_flags;
23 int migratetype;
24 };
25
26 // This tracepoint is defined in mm/page_alloc.c:__alloc_pages_nodemask()
27 // Userspace pathname: /sys/kernel/tracing/events/kmem/mm_page_alloc
28 SEC("tracepoint/kmem/mm_page_alloc")
29 int mm_page_alloc(struct alloc_info *info) {
30 u32 key = 0;
31 u64 initval = 1, *valp;
32
33 valp = bpf_map_lookup_elem(&counting_map, &key);
34 if (!valp) {
35 bpf_map_update_elem(&counting_map, &key, &initval, BPF_ANY);
36 return 0;
37 }
38 __sync_fetch_and_add(valp, 1);
39 return 0;
40 }