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
This commit is contained in:
Giuseppe Cesarano 2025-08-18 23:32:44 +02:00 committed by GitHub
parent 001ec07772
commit b734d03340
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9162,8 +9162,26 @@ pub const perf_event_attr = extern struct {
write_backward: bool = false,
/// include namespaces data
namespaces: bool = false,
/// include ksymbol events
ksymbol: bool = false,
/// include BPF events
bpf_event: bool = false,
/// generate AUX records instead of events
aux_output: bool = false,
/// include cgroup events
cgroup: bool = false,
/// include text poke events
text_poke: bool = false,
/// use build ID in mmap2 events
build_id: bool = false,
/// children only inherit if cloned with CLONE_THREAD
inherit_thread: bool = false,
/// event is removed from task on exec
remove_on_exec: bool = false,
/// send synchronous SIGTRAP on event
sigtrap: bool = false,
__reserved_1: u35 = 0,
__reserved_1: u26 = 0,
} = .{},
/// wakeup every n events, or
/// bytes before wakeup
@ -9206,6 +9224,118 @@ pub const perf_event_attr = extern struct {
sample_max_stack: u16 = 0,
/// Align to u64
__reserved_2: u16 = 0,
aux_sample_size: u32 = 0,
aux_action: packed struct(u32) {
/// start AUX area tracing paused
start_paused: bool = false,
/// on overflow, pause AUX area tracing
pause: bool = false,
/// on overflow, resume AUX area tracing
@"resume": bool = false,
__reserved_3: u29 = 0,
} = .{},
/// User provided data if sigtrap == true
sig_data: u64 = 0,
/// Extension of config2
config3: u64 = 0,
};
pub const perf_event_header = extern struct {
/// Event type: sample/mmap/fork/etc.
type: PERF.RECORD,
/// Additional informations on the event: kernel/user/hypervisor/etc.
misc: packed struct(u16) {
cpu_mode: PERF.RECORD.MISC.CPU_MODE,
_: u9,
PROC_MAP_PARSE_TIMEOUT: bool,
bit13: packed union {
MMAP_DATA: bool,
COMM_EXEC: bool,
FORK_EXEC: bool,
SWITCH_OUT: bool,
},
bit14: packed union {
EXACT_IP: bool,
SWITCH_OUT_PREEMPT: bool,
MMAP_BUILD_ID: bool,
},
EXT_RESERVED: bool,
},
/// Size of the following record
size: u16,
};
pub const perf_event_mmap_page = extern struct {
/// Version number of this struct
version: u32,
/// Lowest version this is compatible with
compt_version: u32,
/// Seqlock for synchronization
lock: u32,
/// Hardware counter identifier
index: u32,
/// Add to hardware counter value
offset: i64,
/// Time the event was active
time_enabled: u64,
/// Time the event was running
time_running: u64,
capabilities: packed struct(u64) {
/// If kernel version < 3.12
/// this rapresents both user_rdpmc and user_time (user_rdpmc | user_time)
/// otherwise deprecated.
bit0: bool,
/// Set if bit0 is deprecated
bit0_is_deprecated: bool,
/// Hardware support for userspace read of performance counters
user_rdpmc: bool,
/// Hardware support for a constant non stop timestamp counter (Eg. TSC on x86)
user_time: bool,
/// The time_zero field is used
user_time_zero: bool,
/// The time_{cycle,mask} fields are used
user_time_short: bool,
____res: u58,
},
/// If capabilities.user_rdpmc
/// this field reports the bit-width of the value read with rdpmc() or equivalent
pcm_width: u16,
/// If capabilities.user_time the following fields can be used to compute the time
/// delta since time_enabled (in ns) using RDTSC or similar
time_shift: u16,
time_mult: u32,
time_offset: u64,
/// If capabilities.user_time_zero the hardware clock can be calculated from
/// sample timestamps
time_zero: u64,
/// Header size
size: u32,
__reserved_1: u32,
/// The following fields are used to compute the timestamp when the hardware clock
/// is less than 64bit wide
time_cycles: u64,
time_mask: u64,
__reserved: [116 * 8]u8,
/// Head in the data section
data_head: u64,
/// Userspace written tail
data_tail: u64,
/// Where the buffer starts
data_offset: u64,
/// Data buffer size
data_size: u64,
// if aux is used, head in the data section
aux_head: u64,
// if aux is used, userspace written tail
aux_tail: u64,
// if aux is used, where the buffer starts
aux_offset: u64,
// if aux is used, data buffer size
aux_size: u64,
};
pub const PERF = struct {
@ -9320,6 +9450,41 @@ pub const PERF = struct {
};
};
pub const RECORD = enum(u32) {
MMAP = 1,
LOST = 2,
COMM = 3,
EXIT = 4,
THROTTLE = 5,
UNTHROTTLE = 6,
FORK = 7,
READ = 8,
SAMPLE = 9,
MMAP2 = 10,
AUX = 11,
ITRACE_START = 12,
LOST_SAMPLES = 13,
SWITCH = 14,
SWITCH_CPU_WIDE = 15,
NAMESPACES = 16,
KSYMBOL = 17,
BPF_EVENT = 18,
CGROUP = 19,
TEXT_POKE = 20,
AUX_OUTPUT_HW_ID = 21,
const MISC = struct {
pub const CPU_MODE = enum(u3) {
UNKNOWN = 0,
KERNEL = 1,
USER = 2,
HYPERVISOR = 3,
GUEST_KERNEL = 4,
GUEST_USER = 5,
};
};
};
pub const FLAG = struct {
pub const FD_NO_GROUP = 1 << 0;
pub const FD_OUTPUT = 1 << 1;