1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2022 Google */
3 #include "vmlinux.h"
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
6 
7 struct bpf_testmod_btf_type_tag_1 {
8 	int a;
9 };
10 
11 struct bpf_testmod_btf_type_tag_2 {
12 	struct bpf_testmod_btf_type_tag_1 *p;
13 };
14 
15 __u64 g;
16 
17 SEC("fentry/bpf_testmod_test_btf_type_tag_percpu_1")
BPF_PROG(test_percpu1,struct bpf_testmod_btf_type_tag_1 * arg)18 int BPF_PROG(test_percpu1, struct bpf_testmod_btf_type_tag_1 *arg)
19 {
20 	g = arg->a;
21 	return 0;
22 }
23 
24 SEC("fentry/bpf_testmod_test_btf_type_tag_percpu_2")
BPF_PROG(test_percpu2,struct bpf_testmod_btf_type_tag_2 * arg)25 int BPF_PROG(test_percpu2, struct bpf_testmod_btf_type_tag_2 *arg)
26 {
27 	g = arg->p->a;
28 	return 0;
29 }
30 
31 /* trace_cgroup_mkdir(struct cgroup *cgrp, const char *path)
32  *
33  * struct cgroup_rstat_cpu {
34  *   ...
35  *   struct cgroup *updated_children;
36  *   ...
37  * };
38  *
39  * struct cgroup {
40  *   ...
41  *   struct cgroup_rstat_cpu __percpu *rstat_cpu;
42  *   ...
43  * };
44  */
45 SEC("tp_btf/cgroup_mkdir")
BPF_PROG(test_percpu_load,struct cgroup * cgrp,const char * path)46 int BPF_PROG(test_percpu_load, struct cgroup *cgrp, const char *path)
47 {
48 	g = (__u64)cgrp->rstat_cpu->updated_children;
49 	return 0;
50 }
51 
52 SEC("tp_btf/cgroup_mkdir")
BPF_PROG(test_percpu_helper,struct cgroup * cgrp,const char * path)53 int BPF_PROG(test_percpu_helper, struct cgroup *cgrp, const char *path)
54 {
55 	struct cgroup_rstat_cpu *rstat;
56 	__u32 cpu;
57 
58 	cpu = bpf_get_smp_processor_id();
59 	rstat = (struct cgroup_rstat_cpu *)bpf_per_cpu_ptr(cgrp->rstat_cpu, cpu);
60 	if (rstat) {
61 		/* READ_ONCE */
62 		*(volatile int *)rstat;
63 	}
64 
65 	return 0;
66 }
67 char _license[] SEC("license") = "GPL";
68