authorgravatar for PecoraInPannaCotta@gmail.comGiuseppe Cesarano <PecoraInPannaCotta@gmail.com> 2025-08-18 23:32:44+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-08-18 21:32:44+00:00
logb734d03340c0b120a7f6376000714b9765c5dbcc
treeb16ddfb64c7a6dfd128ceea13ab1fa1f79b14ecc
parent001ec07772f35ffee031429a558506b89d02cdca
signaturebadge-check Signed by PGP key B5690EEEBB952194

Expanded std.os.linux perf-related definitions (#24264)

* Added perf_event_header definition * Added perf_event_mmap_page definition * Removed default values for perf_event_header * Fixed comments typos * Updated perf_event_attr definition * Explicit packet struct type * PERF.RECORD from struct to enum * fix typo: miscs to misc * misc as packed struct * cpu_mode as named enum * Rescoping CPU_MODE

1 files changed, 167 insertions(+), 2 deletions(-)

lib/std/os/linux.zig+167-2
...@@ -9162,8 +9162,26 @@ pub const perf_event_attr = extern struct {...@@ -9162,8 +9162,26 @@ pub const perf_event_attr = extern struct {
9162 write_backward: bool = false,9162 write_backward: bool = false,
9163 /// include namespaces data9163 /// include namespaces data
9164 namespaces: bool = false,9164 namespaces: bool = false,
91659165 /// include ksymbol events
9166 __reserved_1: u35 = 0,9166 ksymbol: bool = false,
9167 /// include BPF events
9168 bpf_event: bool = false,
9169 /// generate AUX records instead of events
9170 aux_output: bool = false,
9171 /// include cgroup events
9172 cgroup: bool = false,
9173 /// include text poke events
9174 text_poke: bool = false,
9175 /// use build ID in mmap2 events
9176 build_id: bool = false,
9177 /// children only inherit if cloned with CLONE_THREAD
9178 inherit_thread: bool = false,
9179 /// event is removed from task on exec
9180 remove_on_exec: bool = false,
9181 /// send synchronous SIGTRAP on event
9182 sigtrap: bool = false,
9183
9184 __reserved_1: u26 = 0,
9167 } = .{},9185 } = .{},
9168 /// wakeup every n events, or9186 /// wakeup every n events, or
9169 /// bytes before wakeup9187 /// bytes before wakeup
...@@ -9206,6 +9224,118 @@ pub const perf_event_attr = extern struct {...@@ -9206,6 +9224,118 @@ pub const perf_event_attr = extern struct {
9206 sample_max_stack: u16 = 0,9224 sample_max_stack: u16 = 0,
9207 /// Align to u649225 /// Align to u64
9208 __reserved_2: u16 = 0,9226 __reserved_2: u16 = 0,
9227
9228 aux_sample_size: u32 = 0,
9229 aux_action: packed struct(u32) {
9230 /// start AUX area tracing paused
9231 start_paused: bool = false,
9232 /// on overflow, pause AUX area tracing
9233 pause: bool = false,
9234 /// on overflow, resume AUX area tracing
9235 @"resume": bool = false,
9236
9237 __reserved_3: u29 = 0,
9238 } = .{},
9239
9240 /// User provided data if sigtrap == true
9241 sig_data: u64 = 0,
9242
9243 /// Extension of config2
9244 config3: u64 = 0,
9245};
9246
9247pub const perf_event_header = extern struct {
9248 /// Event type: sample/mmap/fork/etc.
9249 type: PERF.RECORD,
9250 /// Additional informations on the event: kernel/user/hypervisor/etc.
9251 misc: packed struct(u16) {
9252 cpu_mode: PERF.RECORD.MISC.CPU_MODE,
9253 _: u9,
9254 PROC_MAP_PARSE_TIMEOUT: bool,
9255 bit13: packed union {
9256 MMAP_DATA: bool,
9257 COMM_EXEC: bool,
9258 FORK_EXEC: bool,
9259 SWITCH_OUT: bool,
9260 },
9261 bit14: packed union {
9262 EXACT_IP: bool,
9263 SWITCH_OUT_PREEMPT: bool,
9264 MMAP_BUILD_ID: bool,
9265 },
9266 EXT_RESERVED: bool,
9267 },
9268 /// Size of the following record
9269 size: u16,
9270};
9271
9272pub const perf_event_mmap_page = extern struct {
9273 /// Version number of this struct
9274 version: u32,
9275 /// Lowest version this is compatible with
9276 compt_version: u32,
9277 /// Seqlock for synchronization
9278 lock: u32,
9279 /// Hardware counter identifier
9280 index: u32,
9281 /// Add to hardware counter value
9282 offset: i64,
9283 /// Time the event was active
9284 time_enabled: u64,
9285 /// Time the event was running
9286 time_running: u64,
9287 capabilities: packed struct(u64) {
9288 /// If kernel version < 3.12
9289 /// this rapresents both user_rdpmc and user_time (user_rdpmc | user_time)
9290 /// otherwise deprecated.
9291 bit0: bool,
9292 /// Set if bit0 is deprecated
9293 bit0_is_deprecated: bool,
9294 /// Hardware support for userspace read of performance counters
9295 user_rdpmc: bool,
9296 /// Hardware support for a constant non stop timestamp counter (Eg. TSC on x86)
9297 user_time: bool,
9298 /// The time_zero field is used
9299 user_time_zero: bool,
9300 /// The time_{cycle,mask} fields are used
9301 user_time_short: bool,
9302 ____res: u58,
9303 },
9304 /// If capabilities.user_rdpmc
9305 /// this field reports the bit-width of the value read with rdpmc() or equivalent
9306 pcm_width: u16,
9307 /// If capabilities.user_time the following fields can be used to compute the time
9308 /// delta since time_enabled (in ns) using RDTSC or similar
9309 time_shift: u16,
9310 time_mult: u32,
9311 time_offset: u64,
9312 /// If capabilities.user_time_zero the hardware clock can be calculated from
9313 /// sample timestamps
9314 time_zero: u64,
9315 /// Header size
9316 size: u32,
9317 __reserved_1: u32,
9318 /// The following fields are used to compute the timestamp when the hardware clock
9319 /// is less than 64bit wide
9320 time_cycles: u64,
9321 time_mask: u64,
9322 __reserved: [116 * 8]u8,
9323 /// Head in the data section
9324 data_head: u64,
9325 /// Userspace written tail
9326 data_tail: u64,
9327 /// Where the buffer starts
9328 data_offset: u64,
9329 /// Data buffer size
9330 data_size: u64,
9331 // if aux is used, head in the data section
9332 aux_head: u64,
9333 // if aux is used, userspace written tail
9334 aux_tail: u64,
9335 // if aux is used, where the buffer starts
9336 aux_offset: u64,
9337 // if aux is used, data buffer size
9338 aux_size: u64,
9209};9339};
92109340
9211pub const PERF = struct {9341pub const PERF = struct {
...@@ -9320,6 +9450,41 @@ pub const PERF = struct {...@@ -9320,6 +9450,41 @@ pub const PERF = struct {
9320 };9450 };
9321 };9451 };
93229452
9453 pub const RECORD = enum(u32) {
9454 MMAP = 1,
9455 LOST = 2,
9456 COMM = 3,
9457 EXIT = 4,
9458 THROTTLE = 5,
9459 UNTHROTTLE = 6,
9460 FORK = 7,
9461 READ = 8,
9462 SAMPLE = 9,
9463 MMAP2 = 10,
9464 AUX = 11,
9465 ITRACE_START = 12,
9466 LOST_SAMPLES = 13,
9467 SWITCH = 14,
9468 SWITCH_CPU_WIDE = 15,
9469 NAMESPACES = 16,
9470 KSYMBOL = 17,
9471 BPF_EVENT = 18,
9472 CGROUP = 19,
9473 TEXT_POKE = 20,
9474 AUX_OUTPUT_HW_ID = 21,
9475
9476 const MISC = struct {
9477 pub const CPU_MODE = enum(u3) {
9478 UNKNOWN = 0,
9479 KERNEL = 1,
9480 USER = 2,
9481 HYPERVISOR = 3,
9482 GUEST_KERNEL = 4,
9483 GUEST_USER = 5,
9484 };
9485 };
9486 };
9487
9323 pub const FLAG = struct {9488 pub const FLAG = struct {
9324 pub const FD_NO_GROUP = 1 << 0;9489 pub const FD_NO_GROUP = 1 << 0;
9325 pub const FD_OUTPUT = 1 << 1;9490 pub const FD_OUTPUT = 1 << 1;