1 // SPDX-License-Identifier: GPL-2.0
3 #include <bpf/bpf_helpers.h>
5 #define TEST_STACK_DEPTH 2
6 #define TEST_MAX_ENTRIES 16384
8 typedef __u64 stack_trace_t[TEST_STACK_DEPTH];
11 __uint(type, BPF_MAP_TYPE_STACK_TRACE);
12 __uint(max_entries, TEST_MAX_ENTRIES);
14 __type(value, stack_trace_t);
15 } stackmap SEC(".maps");
18 __uint(type, BPF_MAP_TYPE_HASH);
19 __uint(max_entries, TEST_MAX_ENTRIES);
22 } stackid_hmap SEC(".maps");
25 __uint(type, BPF_MAP_TYPE_ARRAY);
26 __uint(max_entries, TEST_MAX_ENTRIES);
28 __type(value, stack_trace_t);
29 } stack_amap SEC(".maps");
35 SEC("tracepoint/sched/sched_switch")
36 int oncpu(struct trace_event_raw_sched_switch *ctx)
38 __u32 max_len = TEST_STACK_DEPTH * sizeof(__u64);
39 __u32 key = 0, val = 0;
42 if (pid != (bpf_get_current_pid_tgid() >> 32))
48 /* it should allow skipping whole buffer size entries */
49 key = bpf_get_stackid(ctx, &stackmap, TEST_STACK_DEPTH);
51 /* The size of stackmap and stack_amap should be the same */
52 bpf_map_update_elem(&stackid_hmap, &key, &val, 0);
53 stack_p = bpf_map_lookup_elem(&stack_amap, &key);
55 bpf_get_stack(ctx, stack_p, max_len, TEST_STACK_DEPTH);
56 /* it wrongly skipped all the entries and filled zero */
61 /* old kernel doesn't support skipping that many entries */
68 char _license[] SEC("license") = "GPL";