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 __s32 s32; 19 typedef __u64 u64; 20 typedef __s64 s64; 21 22 typedef int pid_t; 23 24 typedef __s64 time64_t; 25 26 struct timespec64 { 27 time64_t tv_sec; 28 long int tv_nsec; 29 }; 30 31 enum cgroup_subsys_id { 32 perf_event_cgrp_id = 8, 33 }; 34 35 enum { 36 HI_SOFTIRQ = 0, 37 TIMER_SOFTIRQ, 38 NET_TX_SOFTIRQ, 39 NET_RX_SOFTIRQ, 40 BLOCK_SOFTIRQ, 41 IRQ_POLL_SOFTIRQ, 42 TASKLET_SOFTIRQ, 43 SCHED_SOFTIRQ, 44 HRTIMER_SOFTIRQ, 45 RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */ 46 47 NR_SOFTIRQS 48 }; 49 50 typedef struct { 51 int counter; 52 } __attribute__((preserve_access_index)) atomic_t; 53 54 typedef struct { 55 s64 counter; 56 } __attribute__((preserve_access_index)) atomic64_t; 57 58 typedef atomic64_t atomic_long_t; 59 60 struct raw_spinlock { 61 int rawlock; 62 } __attribute__((preserve_access_index)); 63 64 typedef struct raw_spinlock raw_spinlock_t; 65 66 typedef struct { 67 struct raw_spinlock rlock; 68 } __attribute__((preserve_access_index)) spinlock_t; 69 70 struct sighand_struct { 71 spinlock_t siglock; 72 } __attribute__((preserve_access_index)); 73 74 struct signal_struct { 75 atomic_t live; 76 } __attribute__((preserve_access_index)); 77 78 struct rw_semaphore { 79 atomic_long_t owner; 80 } __attribute__((preserve_access_index)); 81 82 struct mutex { 83 atomic_long_t owner; 84 } __attribute__((preserve_access_index)); 85 86 struct kernfs_node { 87 u64 id; 88 } __attribute__((preserve_access_index)); 89 90 struct cgroup { 91 struct kernfs_node *kn; 92 int level; 93 } __attribute__((preserve_access_index)); 94 95 struct cgroup_subsys_state { 96 struct cgroup *cgroup; 97 } __attribute__((preserve_access_index)); 98 99 struct css_set { 100 struct cgroup_subsys_state *subsys[13]; 101 struct cgroup *dfl_cgrp; 102 } __attribute__((preserve_access_index)); 103 104 struct mm_struct { 105 struct rw_semaphore mmap_lock; 106 } __attribute__((preserve_access_index)); 107 108 struct task_struct { 109 unsigned int flags; 110 struct mm_struct *mm; 111 pid_t pid; 112 pid_t tgid; 113 char comm[16]; 114 struct signal_struct *signal; 115 struct sighand_struct *sighand; 116 struct css_set *cgroups; 117 } __attribute__((preserve_access_index)); 118 119 struct trace_entry { 120 short unsigned int type; 121 unsigned char flags; 122 unsigned char preempt_count; 123 int pid; 124 } __attribute__((preserve_access_index)); 125 126 struct trace_event_raw_irq_handler_entry { 127 struct trace_entry ent; 128 int irq; 129 u32 __data_loc_name; 130 char __data[]; 131 } __attribute__((preserve_access_index)); 132 133 struct trace_event_raw_irq_handler_exit { 134 struct trace_entry ent; 135 int irq; 136 int ret; 137 char __data[]; 138 } __attribute__((preserve_access_index)); 139 140 struct trace_event_raw_softirq { 141 struct trace_entry ent; 142 unsigned int vec; 143 char __data[]; 144 } __attribute__((preserve_access_index)); 145 146 struct trace_event_raw_workqueue_execute_start { 147 struct trace_entry ent; 148 void *work; 149 void *function; 150 char __data[]; 151 } __attribute__((preserve_access_index)); 152 153 struct trace_event_raw_workqueue_execute_end { 154 struct trace_entry ent; 155 void *work; 156 void *function; 157 char __data[]; 158 } __attribute__((preserve_access_index)); 159 160 struct trace_event_raw_workqueue_activate_work { 161 struct trace_entry ent; 162 void *work; 163 char __data[]; 164 } __attribute__((preserve_access_index)); 165 166 struct perf_sample_data { 167 u64 addr; 168 u64 period; 169 union perf_sample_weight weight; 170 u64 txn; 171 union perf_mem_data_src data_src; 172 u64 ip; 173 struct { 174 u32 pid; 175 u32 tid; 176 } tid_entry; 177 u64 time; 178 u64 id; 179 struct { 180 u32 cpu; 181 } cpu_entry; 182 u64 phys_addr; 183 u64 cgroup; 184 u64 data_page_size; 185 u64 code_page_size; 186 } __attribute__((__aligned__(64))) __attribute__((preserve_access_index)); 187 188 struct perf_event { 189 struct perf_event *parent; 190 u64 id; 191 } __attribute__((preserve_access_index)); 192 193 struct bpf_perf_event_data_kern { 194 struct perf_sample_data *data; 195 struct perf_event *event; 196 } __attribute__((preserve_access_index)); 197 198 /* 199 * If 'struct rq' isn't defined for lock_contention.bpf.c, for the sake of 200 * rq___old and rq___new, then the type for the 'runqueue' variable ends up 201 * being a forward declaration (BTF_KIND_FWD) while the kernel has it defined 202 * (BTF_KIND_STRUCT). The definition appears in vmlinux.h rather than 203 * lock_contention.bpf.c for consistency with a generated vmlinux.h. 204 */ 205 struct rq {}; 206 207 struct kmem_cache { 208 const char *name; 209 } __attribute__((preserve_access_index)); 210 211 struct bpf_iter__kmem_cache { 212 struct kmem_cache *s; 213 } __attribute__((preserve_access_index)); 214 215 struct zone { 216 spinlock_t lock; 217 } __attribute__((preserve_access_index)); 218 219 struct pglist_data { 220 struct zone node_zones[6]; /* value for all possible config */ 221 int nr_zones; 222 } __attribute__((preserve_access_index)); 223 224 #endif // __VMLINUX_H 225