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