From bc0bf4e97ac7ac45731b7a7e629e680e51d8eefe Mon Sep 17 00:00:00 2001 From: Stephen Gregoratto Date: Thu, 28 Sep 2023 18:27:37 +1000 Subject: [PATCH] Linux: Add cachestat wrapper. Can be tested using this program I whipped up: https://gist.github.com/The-King-of-Toasters/aee448f5975c50f735fd1946794574f7 --- lib/std/os/linux.zig | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 4a59446a8d..dea3cea875 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -1876,6 +1876,21 @@ pub fn ptrace( ); } +pub fn cachestat( + fd: fd_t, + cstat_range: *const cache_stat_range, + cstat: *cache_stat, + flags: u32, +) usize { + return syscall4( + .cachestat, + @as(usize, @bitCast(@as(isize, fd))), + @intFromPtr(cstat_range), + @intFromPtr(cstat), + flags, + ); +} + pub const E = switch (native_arch) { .mips, .mipsel => @import("linux/errno/mips.zig").E, .sparc, .sparcel, .sparc64 => @import("linux/errno/sparc.zig").E, @@ -5829,3 +5844,16 @@ pub const PTRACE = struct { pub const SECCOMP_GET_METADATA = 0x420d; pub const GET_SYSCALL_INFO = 0x420e; }; + +pub const cache_stat_range = extern struct { + off: u64, + len: u64, +}; + +pub const cache_stat = extern struct { + cache: u64, + dirty: u64, + writeback: u64, + evicted: u64, + recently_evicted: u64, +};