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