xref: /linux/tools/perf/util/bpf_skel/vmlinux/vmlinux.h (revision ae22a94997b8a03dcb3c922857c203246711f9d4)
1 #ifndef __VMLINUX_H
2 #define __VMLINUX_H
3 
4 #include <linux/stddef.h> // for define __always_inline
5 #include <linux/bpf.h>
6 #include <linux/types.h>
7 #include <linux/perf_event.h>
8 #include <stdbool.h>
9 
10 // non-UAPI kernel data structures, used in the .bpf.c BPF tool component.
11 
12 // Just the fields used in these tools preserving the access index so that
13 // libbpf can fixup offsets with the ones used in the kernel when loading the
14 // BPF bytecode, if they differ from what is used here.
15 
16 typedef __u8 u8;
17 typedef __u32 u32;
18 typedef __u64 u64;
19 typedef __s64 s64;
20 
21 typedef int pid_t;
22 
23 typedef __s64 time64_t;
24 
25 struct timespec64 {
26         time64_t        tv_sec;
27         long int        tv_nsec;
28 };
29 
30 enum cgroup_subsys_id {
31 	perf_event_cgrp_id  = 8,
32 };
33 
34 enum {
35 	HI_SOFTIRQ = 0,
36 	TIMER_SOFTIRQ,
37 	NET_TX_SOFTIRQ,
38 	NET_RX_SOFTIRQ,
39 	BLOCK_SOFTIRQ,
40 	IRQ_POLL_SOFTIRQ,
41 	TASKLET_SOFTIRQ,
42 	SCHED_SOFTIRQ,
43 	HRTIMER_SOFTIRQ,
44 	RCU_SOFTIRQ,    /* Preferable RCU should always be the last softirq */
45 
46 	NR_SOFTIRQS
47 };
48 
49 typedef struct {
50 	s64	counter;
51 } __attribute__((preserve_access_index)) atomic64_t;
52 
53 typedef atomic64_t atomic_long_t;
54 
55 struct raw_spinlock {
56 	int rawlock;
57 } __attribute__((preserve_access_index));
58 
59 typedef struct raw_spinlock raw_spinlock_t;
60 
61 typedef struct {
62 	struct raw_spinlock rlock;
63 } __attribute__((preserve_access_index)) spinlock_t;
64 
65 struct sighand_struct {
66 	spinlock_t siglock;
67 } __attribute__((preserve_access_index));
68 
69 struct rw_semaphore {
70 	atomic_long_t owner;
71 } __attribute__((preserve_access_index));
72 
73 struct mutex {
74 	atomic_long_t owner;
75 } __attribute__((preserve_access_index));
76 
77 struct kernfs_node {
78 	u64 id;
79 } __attribute__((preserve_access_index));
80 
81 struct cgroup {
82 	struct kernfs_node *kn;
83 	int                level;
84 }  __attribute__((preserve_access_index));
85 
86 struct cgroup_subsys_state {
87 	struct cgroup *cgroup;
88 } __attribute__((preserve_access_index));
89 
90 struct css_set {
91 	struct cgroup_subsys_state *subsys[13];
92 	struct cgroup *dfl_cgrp;
93 } __attribute__((preserve_access_index));
94 
95 struct mm_struct {
96 	struct rw_semaphore mmap_lock;
97 } __attribute__((preserve_access_index));
98 
99 struct task_struct {
100 	unsigned int	      flags;
101 	struct mm_struct      *mm;
102 	pid_t		      pid;
103 	pid_t		      tgid;
104 	char		      comm[16];
105 	struct sighand_struct *sighand;
106 	struct css_set	      *cgroups;
107 } __attribute__((preserve_access_index));
108 
109 struct trace_entry {
110 	short unsigned int type;
111 	unsigned char	   flags;
112 	unsigned char	   preempt_count;
113 	int		   pid;
114 } __attribute__((preserve_access_index));
115 
116 struct trace_event_raw_irq_handler_entry {
117 	struct trace_entry ent;
118 	int		   irq;
119 	u32		   __data_loc_name;
120 	char		   __data[];
121 } __attribute__((preserve_access_index));
122 
123 struct trace_event_raw_irq_handler_exit {
124 	struct trace_entry ent;
125 	int		   irq;
126 	int		   ret;
127 	char		   __data[];
128 } __attribute__((preserve_access_index));
129 
130 struct trace_event_raw_softirq {
131 	struct trace_entry ent;
132 	unsigned int	   vec;
133 	char		   __data[];
134 } __attribute__((preserve_access_index));
135 
136 struct trace_event_raw_workqueue_execute_start {
137 	struct trace_entry ent;
138 	void		   *work;
139 	void		   *function;
140 	char		   __data[];
141 } __attribute__((preserve_access_index));
142 
143 struct trace_event_raw_workqueue_execute_end {
144 	struct trace_entry ent;
145 	void		   *work;
146 	void		   *function;
147 	char		  __data[];
148 } __attribute__((preserve_access_index));
149 
150 struct trace_event_raw_workqueue_activate_work {
151 	struct trace_entry ent;
152 	void		   *work;
153 	char		   __data[];
154 } __attribute__((preserve_access_index));
155 
156 struct perf_sample_data {
157 	u64			 addr;
158 	u64			 period;
159 	union perf_sample_weight weight;
160 	u64			 txn;
161 	union perf_mem_data_src	 data_src;
162 	u64			 ip;
163 	struct {
164 		u32		 pid;
165 		u32		 tid;
166 	} tid_entry;
167 	u64			 time;
168 	u64			 id;
169 	struct {
170 		u32		 cpu;
171 	} cpu_entry;
172 	u64			 phys_addr;
173 	u64			 data_page_size;
174 	u64			 code_page_size;
175 } __attribute__((__aligned__(64))) __attribute__((preserve_access_index));
176 
177 struct bpf_perf_event_data_kern {
178 	struct perf_sample_data *data;
179 	struct perf_event	*event;
180 } __attribute__((preserve_access_index));
181 
182 /*
183  * If 'struct rq' isn't defined for lock_contention.bpf.c, for the sake of
184  * rq___old and rq___new, then the type for the 'runqueue' variable ends up
185  * being a forward declaration (BTF_KIND_FWD) while the kernel has it defined
186  * (BTF_KIND_STRUCT). The definition appears in vmlinux.h rather than
187  * lock_contention.bpf.c for consistency with a generated vmlinux.h.
188  */
189 struct rq {};
190 
191 #endif // __VMLINUX_H
192