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