| ... | @@ -1638,6 +1638,23 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize { | ... | @@ -1638,6 +1638,23 @@ pub fn fadvise(fd: fd_t, offset: i64, len: i64, advice: usize) usize { |
| 1638 | } | 1638 | } |
| 1639 | } | 1639 | } |
| 1640 | | 1640 | |
| | 1641 | pub fn perf_event_open( |
| | 1642 | attr: *perf_event_attr, |
| | 1643 | pid: pid_t, |
| | 1644 | cpu: i32, |
| | 1645 | group_fd: fd_t, |
| | 1646 | flags: usize, |
| | 1647 | ) usize { |
| | 1648 | return syscall5( |
| | 1649 | .perf_event_open, |
| | 1650 | @ptrToInt(attr), |
| | 1651 | @bitCast(usize, @as(isize, pid)), |
| | 1652 | @bitCast(usize, @as(isize, cpu)), |
| | 1653 | @bitCast(usize, @as(isize, group_fd)), |
| | 1654 | flags, |
| | 1655 | ); |
| | 1656 | } |
| | 1657 | |
| 1641 | pub const E = switch (native_arch) { | 1658 | pub const E = switch (native_arch) { |
| 1642 | .mips, .mipsel => @import("linux/errno/mips.zig").E, | 1659 | .mips, .mipsel => @import("linux/errno/mips.zig").E, |
| 1643 | .sparc, .sparcel, .sparcv9 => @import("linux/errno/sparc.zig").E, | 1660 | .sparc, .sparcel, .sparcv9 => @import("linux/errno/sparc.zig").E, |
| ... | @@ -3781,10 +3798,6 @@ pub const MFD_HUGE_1GB = HUGETLB_FLAG_ENCODE_1GB; | ... | @@ -3781,10 +3798,6 @@ pub const MFD_HUGE_1GB = HUGETLB_FLAG_ENCODE_1GB; |
| 3781 | pub const MFD_HUGE_2GB = HUGETLB_FLAG_ENCODE_2GB; | 3798 | pub const MFD_HUGE_2GB = HUGETLB_FLAG_ENCODE_2GB; |
| 3782 | pub const MFD_HUGE_16GB = HUGETLB_FLAG_ENCODE_16GB; | 3799 | pub const MFD_HUGE_16GB = HUGETLB_FLAG_ENCODE_16GB; |
| 3783 | | 3800 | |
| 3784 | pub const RUSAGE_SELF = 0; | | |
| 3785 | pub const RUSAGE_CHILDREN = -1; | | |
| 3786 | pub const RUSAGE_THREAD = 1; | | |
| 3787 | | | |
| 3788 | pub const rusage = extern struct { | 3801 | pub const rusage = extern struct { |
| 3789 | utime: timeval, | 3802 | utime: timeval, |
| 3790 | stime: timeval, | 3803 | stime: timeval, |
| ... | @@ -3803,6 +3816,10 @@ pub const rusage = extern struct { | ... | @@ -3803,6 +3816,10 @@ pub const rusage = extern struct { |
| 3803 | nvcsw: isize, | 3816 | nvcsw: isize, |
| 3804 | nivcsw: isize, | 3817 | nivcsw: isize, |
| 3805 | __reserved: [16]isize = [1]isize{0} ** 16, | 3818 | __reserved: [16]isize = [1]isize{0} ** 16, |
| | 3819 | |
| | 3820 | pub const SELF = 0; |
| | 3821 | pub const CHILDREN = -1; |
| | 3822 | pub const THREAD = 1; |
| 3806 | }; | 3823 | }; |
| 3807 | | 3824 | |
| 3808 | pub const cc_t = u8; | 3825 | pub const cc_t = u8; |
| ... | @@ -4925,3 +4942,263 @@ pub const rtnl_link_stats64 = extern struct { | ... | @@ -4925,3 +4942,263 @@ pub const rtnl_link_stats64 = extern struct { |
| 4925 | /// dropped, no handler found | 4942 | /// dropped, no handler found |
| 4926 | rx_nohandler: u64, | 4943 | rx_nohandler: u64, |
| 4927 | }; | 4944 | }; |
| | 4945 | |
| | 4946 | pub const perf_event_attr = extern struct { |
| | 4947 | /// Major type: hardware/software/tracepoint/etc. |
| | 4948 | type: PERF.TYPE = undefined, |
| | 4949 | /// Size of the attr structure, for fwd/bwd compat. |
| | 4950 | size: u32 = @sizeOf(perf_event_attr), |
| | 4951 | /// Type specific configuration information. |
| | 4952 | config: u64 = 0, |
| | 4953 | |
| | 4954 | sample_period_or_freq: u64 = 0, |
| | 4955 | sample_type: u64 = 0, |
| | 4956 | read_format: u64 = 0, |
| | 4957 | |
| | 4958 | flags: packed struct { |
| | 4959 | /// off by default |
| | 4960 | disabled: bool = false, |
| | 4961 | /// children inherit it |
| | 4962 | inherit: bool = false, |
| | 4963 | /// must always be on PMU |
| | 4964 | pinned: bool = false, |
| | 4965 | /// only group on PMU |
| | 4966 | exclusive: bool = false, |
| | 4967 | /// don't count user |
| | 4968 | exclude_user: bool = false, |
| | 4969 | /// ditto kernel |
| | 4970 | exclude_kernel: bool = false, |
| | 4971 | /// ditto hypervisor |
| | 4972 | exclude_hv: bool = false, |
| | 4973 | /// don't count when idle |
| | 4974 | exclude_idle: bool = false, |
| | 4975 | /// include mmap data |
| | 4976 | mmap: bool = false, |
| | 4977 | /// include comm data |
| | 4978 | comm: bool = false, |
| | 4979 | /// use freq, not period |
| | 4980 | freq: bool = false, |
| | 4981 | /// per task counts |
| | 4982 | inherit_stat: bool = false, |
| | 4983 | /// next exec enables |
| | 4984 | enable_on_exec: bool = false, |
| | 4985 | /// trace fork/exit |
| | 4986 | task: bool = false, |
| | 4987 | /// wakeup_watermark |
| | 4988 | watermark: bool = false, |
| | 4989 | /// precise_ip: |
| | 4990 | /// |
| | 4991 | /// 0 - SAMPLE_IP can have arbitrary skid |
| | 4992 | /// 1 - SAMPLE_IP must have constant skid |
| | 4993 | /// 2 - SAMPLE_IP requested to have 0 skid |
| | 4994 | /// 3 - SAMPLE_IP must have 0 skid |
| | 4995 | /// |
| | 4996 | /// See also PERF_RECORD_MISC_EXACT_IP |
| | 4997 | /// skid constraint |
| | 4998 | precise_ip: u2 = 0, |
| | 4999 | /// non-exec mmap data |
| | 5000 | mmap_data: bool = false, |
| | 5001 | /// sample_type all events |
| | 5002 | sample_id_all: bool = false, |
| | 5003 | |
| | 5004 | /// don't count in host |
| | 5005 | exclude_host: bool = false, |
| | 5006 | /// don't count in guest |
| | 5007 | exclude_guest: bool = false, |
| | 5008 | |
| | 5009 | /// exclude kernel callchains |
| | 5010 | exclude_callchain_kernel: bool = false, |
| | 5011 | /// exclude user callchains |
| | 5012 | exclude_callchain_user: bool = false, |
| | 5013 | /// include mmap with inode data |
| | 5014 | mmap2: bool = false, |
| | 5015 | /// flag comm events that are due to an exec |
| | 5016 | comm_exec: bool = false, |
| | 5017 | /// use @clockid for time fields |
| | 5018 | use_clockid: bool = false, |
| | 5019 | /// context switch data |
| | 5020 | context_switch: bool = false, |
| | 5021 | /// Write ring buffer from end to beginning |
| | 5022 | write_backward: bool = false, |
| | 5023 | /// include namespaces data |
| | 5024 | namespaces: bool = false, |
| | 5025 | |
| | 5026 | __reserved_1: u35 = 0, |
| | 5027 | } = .{}, |
| | 5028 | /// wakeup every n events, or |
| | 5029 | /// bytes before wakeup |
| | 5030 | wakeup_events_or_watermark: u32 = 0, |
| | 5031 | |
| | 5032 | bp_type: u32 = 0, |
| | 5033 | |
| | 5034 | /// This field is also used for: |
| | 5035 | /// bp_addr |
| | 5036 | /// kprobe_func for perf_kprobe |
| | 5037 | /// uprobe_path for perf_uprobe |
| | 5038 | config1: u64 = 0, |
| | 5039 | /// This field is also used for: |
| | 5040 | /// bp_len |
| | 5041 | /// kprobe_addr when kprobe_func == null |
| | 5042 | /// probe_offset for perf_[k,u]probe |
| | 5043 | config2: u64 = 0, |
| | 5044 | |
| | 5045 | /// enum perf_branch_sample_type |
| | 5046 | branch_sample_type: u64 = 0, |
| | 5047 | |
| | 5048 | /// Defines set of user regs to dump on samples. |
| | 5049 | /// See asm/perf_regs.h for details. |
| | 5050 | sample_regs_user: u64 = 0, |
| | 5051 | |
| | 5052 | /// Defines size of the user stack to dump on samples. |
| | 5053 | sample_stack_user: u32 = 0, |
| | 5054 | |
| | 5055 | clockid: i32 = 0, |
| | 5056 | /// Defines set of regs to dump for each sample |
| | 5057 | /// state captured on: |
| | 5058 | /// - precise = 0: PMU interrupt |
| | 5059 | /// - precise > 0: sampled instruction |
| | 5060 | /// |
| | 5061 | /// See asm/perf_regs.h for details. |
| | 5062 | sample_regs_intr: u64 = 0, |
| | 5063 | |
| | 5064 | /// Wakeup watermark for AUX area |
| | 5065 | aux_watermark: u32 = 0, |
| | 5066 | sample_max_stack: u16 = 0, |
| | 5067 | /// Align to u64 |
| | 5068 | __reserved_2: u16 = 0, |
| | 5069 | }; |
| | 5070 | |
| | 5071 | pub const PERF = struct { |
| | 5072 | pub const TYPE = enum(u32) { |
| | 5073 | HARDWARE, |
| | 5074 | SOFTWARE, |
| | 5075 | TRACEPOINT, |
| | 5076 | HW_CACHE, |
| | 5077 | RAW, |
| | 5078 | BREAKPOINT, |
| | 5079 | MAX, |
| | 5080 | }; |
| | 5081 | |
| | 5082 | pub const COUNT = struct { |
| | 5083 | pub const HW = enum(u32) { |
| | 5084 | CPU_CYCLES, |
| | 5085 | INSTRUCTIONS, |
| | 5086 | CACHE_REFERENCES, |
| | 5087 | CACHE_MISSES, |
| | 5088 | BRANCH_INSTRUCTIONS, |
| | 5089 | BRANCH_MISSES, |
| | 5090 | BUS_CYCLES, |
| | 5091 | STALLED_CYCLES_FRONTEND, |
| | 5092 | STALLED_CYCLES_BACKEND, |
| | 5093 | REF_CPU_CYCLES, |
| | 5094 | MAX, |
| | 5095 | |
| | 5096 | pub const CACHE = enum(u32) { |
| | 5097 | L1D, |
| | 5098 | L1I, |
| | 5099 | LL, |
| | 5100 | DTLB, |
| | 5101 | ITLB, |
| | 5102 | BPU, |
| | 5103 | NODE, |
| | 5104 | MAX, |
| | 5105 | |
| | 5106 | pub const OP = enum(u32) { |
| | 5107 | READ, |
| | 5108 | WRITE, |
| | 5109 | PREFETCH, |
| | 5110 | MAX, |
| | 5111 | }; |
| | 5112 | |
| | 5113 | pub const RESULT = enum(u32) { |
| | 5114 | ACCESS, |
| | 5115 | MISS, |
| | 5116 | MAX, |
| | 5117 | }; |
| | 5118 | }; |
| | 5119 | }; |
| | 5120 | |
| | 5121 | pub const SW = enum(u32) { |
| | 5122 | CPU_CLOCK, |
| | 5123 | TASK_CLOCK, |
| | 5124 | PAGE_FAULTS, |
| | 5125 | CONTEXT_SWITCHES, |
| | 5126 | CPU_MIGRATIONS, |
| | 5127 | PAGE_FAULTS_MIN, |
| | 5128 | PAGE_FAULTS_MAJ, |
| | 5129 | ALIGNMENT_FAULTS, |
| | 5130 | EMULATION_FAULTS, |
| | 5131 | DUMMY, |
| | 5132 | BPF_OUTPUT, |
| | 5133 | MAX, |
| | 5134 | }; |
| | 5135 | }; |
| | 5136 | |
| | 5137 | pub const SAMPLE = struct { |
| | 5138 | pub const IP = 1; |
| | 5139 | pub const TID = 2; |
| | 5140 | pub const TIME = 4; |
| | 5141 | pub const ADDR = 8; |
| | 5142 | pub const READ = 16; |
| | 5143 | pub const CALLCHAIN = 32; |
| | 5144 | pub const ID = 64; |
| | 5145 | pub const CPU = 128; |
| | 5146 | pub const PERIOD = 256; |
| | 5147 | pub const STREAM_ID = 512; |
| | 5148 | pub const RAW = 1024; |
| | 5149 | pub const BRANCH_STACK = 2048; |
| | 5150 | pub const REGS_USER = 4096; |
| | 5151 | pub const STACK_USER = 8192; |
| | 5152 | pub const WEIGHT = 16384; |
| | 5153 | pub const DATA_SRC = 32768; |
| | 5154 | pub const IDENTIFIER = 65536; |
| | 5155 | pub const TRANSACTION = 131072; |
| | 5156 | pub const REGS_INTR = 262144; |
| | 5157 | pub const PHYS_ADDR = 524288; |
| | 5158 | pub const MAX = 1048576; |
| | 5159 | |
| | 5160 | pub const BRANCH = struct { |
| | 5161 | pub const USER = 1 << 0; |
| | 5162 | pub const KERNEL = 1 << 1; |
| | 5163 | pub const HV = 1 << 2; |
| | 5164 | pub const ANY = 1 << 3; |
| | 5165 | pub const ANY_CALL = 1 << 4; |
| | 5166 | pub const ANY_RETURN = 1 << 5; |
| | 5167 | pub const IND_CALL = 1 << 6; |
| | 5168 | pub const ABORT_TX = 1 << 7; |
| | 5169 | pub const IN_TX = 1 << 8; |
| | 5170 | pub const NO_TX = 1 << 9; |
| | 5171 | pub const COND = 1 << 10; |
| | 5172 | pub const CALL_STACK = 1 << 11; |
| | 5173 | pub const IND_JUMP = 1 << 12; |
| | 5174 | pub const CALL = 1 << 13; |
| | 5175 | pub const NO_FLAGS = 1 << 14; |
| | 5176 | pub const NO_CYCLES = 1 << 15; |
| | 5177 | pub const TYPE_SAVE = 1 << 16; |
| | 5178 | pub const MAX = 1 << 17; |
| | 5179 | }; |
| | 5180 | }; |
| | 5181 | |
| | 5182 | pub const FLAG = struct { |
| | 5183 | pub const FD_NO_GROUP = 1 << 0; |
| | 5184 | pub const FD_OUTPUT = 1 << 1; |
| | 5185 | pub const PID_CGROUP = 1 << 2; |
| | 5186 | pub const FD_CLOEXEC = 1 << 3; |
| | 5187 | }; |
| | 5188 | |
| | 5189 | pub const EVENT_IOC = struct { |
| | 5190 | pub const ENABLE = 9216; |
| | 5191 | pub const DISABLE = 9217; |
| | 5192 | pub const REFRESH = 9218; |
| | 5193 | pub const RESET = 9219; |
| | 5194 | pub const PERIOD = 1074275332; |
| | 5195 | pub const SET_OUTPUT = 9221; |
| | 5196 | pub const SET_FILTER = 1074275334; |
| | 5197 | pub const SET_BPF = 1074013192; |
| | 5198 | pub const PAUSE_OUTPUT = 1074013193; |
| | 5199 | pub const QUERY_BPF = 3221758986; |
| | 5200 | pub const MODIFY_ATTRIBUTES = 1074275339; |
| | 5201 | }; |
| | 5202 | |
| | 5203 | pub const IOC_FLAG_GROUP = 1; |
| | 5204 | }; |