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 s64 counter; 52 } __attribute__((preserve_access_index)) atomic64_t; 53 54 typedef atomic64_t atomic_long_t; 55 56 struct raw_spinlock { 57 int rawlock; 58 } __attribute__((preserve_access_index)); 59 60 typedef struct raw_spinlock raw_spinlock_t; 61 62 typedef struct { 63 struct raw_spinlock rlock; 64 } __attribute__((preserve_access_index)) spinlock_t; 65 66 struct sighand_struct { 67 spinlock_t siglock; 68 } __attribute__((preserve_access_index)); 69 70 struct rw_semaphore { 71 atomic_long_t owner; 72 } __attribute__((preserve_access_index)); 73 74 struct mutex { 75 atomic_long_t owner; 76 } __attribute__((preserve_access_index)); 77 78 struct kernfs_node { 79 u64 id; 80 } __attribute__((preserve_access_index)); 81 82 struct cgroup { 83 struct kernfs_node *kn; 84 int level; 85 } __attribute__((preserve_access_index)); 86 87 struct cgroup_subsys_state { 88 struct cgroup *cgroup; 89 } __attribute__((preserve_access_index)); 90 91 struct css_set { 92 struct cgroup_subsys_state *subsys[13]; 93 struct cgroup *dfl_cgrp; 94 } __attribute__((preserve_access_index)); 95 96 struct mm_struct { 97 struct rw_semaphore mmap_lock; 98 } __attribute__((preserve_access_index)); 99 100 struct task_struct { 101 unsigned int flags; 102 struct mm_struct *mm; 103 pid_t pid; 104 pid_t tgid; 105 char comm[16]; 106 struct sighand_struct *sighand; 107 struct css_set *cgroups; 108 } __attribute__((preserve_access_index)); 109 110 struct trace_entry { 111 short unsigned int type; 112 unsigned char flags; 113 unsigned char preempt_count; 114 int pid; 115 } __attribute__((preserve_access_index)); 116 117 struct trace_event_raw_irq_handler_entry { 118 struct trace_entry ent; 119 int irq; 120 u32 __data_loc_name; 121 char __data[]; 122 } __attribute__((preserve_access_index)); 123 124 struct trace_event_raw_irq_handler_exit { 125 struct trace_entry ent; 126 int irq; 127 int ret; 128 char __data[]; 129 } __attribute__((preserve_access_index)); 130 131 struct trace_event_raw_softirq { 132 struct trace_entry ent; 133 unsigned int vec; 134 char __data[]; 135 } __attribute__((preserve_access_index)); 136 137 struct trace_event_raw_workqueue_execute_start { 138 struct trace_entry ent; 139 void *work; 140 void *function; 141 char __data[]; 142 } __attribute__((preserve_access_index)); 143 144 struct trace_event_raw_workqueue_execute_end { 145 struct trace_entry ent; 146 void *work; 147 void *function; 148 char __data[]; 149 } __attribute__((preserve_access_index)); 150 151 struct trace_event_raw_workqueue_activate_work { 152 struct trace_entry ent; 153 void *work; 154 char __data[]; 155 } __attribute__((preserve_access_index)); 156 157 struct perf_sample_data { 158 u64 addr; 159 u64 period; 160 union perf_sample_weight weight; 161 u64 txn; 162 union perf_mem_data_src data_src; 163 u64 ip; 164 struct { 165 u32 pid; 166 u32 tid; 167 } tid_entry; 168 u64 time; 169 u64 id; 170 struct { 171 u32 cpu; 172 } cpu_entry; 173 u64 phys_addr; 174 u64 data_page_size; 175 u64 code_page_size; 176 } __attribute__((__aligned__(64))) __attribute__((preserve_access_index)); 177 178 struct bpf_perf_event_data_kern { 179 struct perf_sample_data *data; 180 struct perf_event *event; 181 } __attribute__((preserve_access_index)); 182 183 /* 184 * If 'struct rq' isn't defined for lock_contention.bpf.c, for the sake of 185 * rq___old and rq___new, then the type for the 'runqueue' variable ends up 186 * being a forward declaration (BTF_KIND_FWD) while the kernel has it defined 187 * (BTF_KIND_STRUCT). The definition appears in vmlinux.h rather than 188 * lock_contention.bpf.c for consistency with a generated vmlinux.h. 189 */ 190 struct rq {}; 191 192 #endif // __VMLINUX_H 193