From 2e01933dc5c0c1903c1b7f86e453829fee9a541b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 12:17:50 -0300 Subject: kernel: smaller BPF records, syscall tracepoints sorted out in place, the README Syscall entries and kprobes send the event alone (a kernel function's registers are not the thread's; a syscall's are its arguments), a probe's event is not inherited (it failed the target's clone). The per-syscall tracepoints are told entry from exit on the events themselves, not on a second set. The VM has two CPUs and a time limit. README: the kernel's view, with what each mode costs. Co-Authored-By: Claude Fable 5.2 --- src/trace/perf.zig | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/trace/perf.zig') diff --git a/src/trace/perf.zig b/src/trace/perf.zig index c251741..36eaaf8 100644 --- a/src/trace/perf.zig +++ b/src/trace/perf.zig @@ -281,17 +281,19 @@ pub const Session = struct { } // shortcut: ids below 4096; scan further if a kernel has more trace events than that. for (0..4096) |id| { - var attr: linux.perf_event_attr = .{ .type = .TRACEPOINT, .config = id, .sample_period_or_freq = 1, .sample_type = PERF.SAMPLE.RAW }; - // Only a syscall's exit has a field `ret`: a filter on it is - // accepted there and nowhere else. On an event of its own, since - // a filter cannot be taken off again. - const probe = perfOpen(&attr, s.pid, -1) catch |err| switch (err) { + s.add(.{ .type = .TRACEPOINT, .config = id, .sample_period_or_freq = 1, .sample_type = PERF.SAMPLE.RAW }, .syscall_enter) catch |err| switch (err) { error.PerfAccess, error.PerfNoSuchEvent => continue, else => |e| return e, }; - const is_exit = linux.errno(linux.ioctl(probe, PERF.EVENT_IOC.SET_FILTER, @intFromPtr("ret==0"))) == .SUCCESS; - _ = linux.close(probe); - try s.add(attr, if (is_exit) .syscall_exit else .syscall_enter); + // Entry or exit? Only an exit has a field `ret`: a filter on it + // is accepted there and nowhere else. It cannot be taken off + // again, so it is one that every exit passes. + for (s.fds.items[s.fds.items.len - s.rings.len ..]) |fd| { + if (linux.errno(linux.ioctl(fd, PERF.EVENT_IOC.SET_FILTER, @intFromPtr("ret >= 0 || ret < 0"))) != .SUCCESS) break; + var event_id: u64 = 0; + _ = linux.ioctl(fd, PERF.EVENT_IOC.ID, @intFromPtr(&event_id)); + try s.sources.put(s.gpa, event_id, .syscall_exit); + } } } -- cgit v1.3