xref: /linux/tools/testing/selftests/bpf/progs/test_pe_preserve_elems.c (revision 26fbb4c8c7c3ee9a4c3b4de555a8587b5a19154e)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Facebook
3 #include <linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
6 
7 struct {
8 	__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
9 	__uint(max_entries, 1);
10 	__uint(key_size, sizeof(int));
11 	__uint(value_size, sizeof(int));
12 } array_1 SEC(".maps");
13 
14 struct {
15 	__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
16 	__uint(max_entries, 1);
17 	__uint(key_size, sizeof(int));
18 	__uint(value_size, sizeof(int));
19 	__uint(map_flags, BPF_F_PRESERVE_ELEMS);
20 } array_2 SEC(".maps");
21 
22 SEC("raw_tp/sched_switch")
23 int BPF_PROG(read_array_1)
24 {
25 	struct bpf_perf_event_value val;
26 
27 	return bpf_perf_event_read_value(&array_1, 0, &val, sizeof(val));
28 }
29 
30 SEC("raw_tp/task_rename")
31 int BPF_PROG(read_array_2)
32 {
33 	struct bpf_perf_event_value val;
34 
35 	return bpf_perf_event_read_value(&array_2, 0, &val, sizeof(val));
36 }
37 
38 char LICENSE[] SEC("license") = "GPL";
39