authorgravatar for 58759586+curuvar@users.noreply.github.comcuruvar <58759586+curuvar@users.noreply.github.com> 2024-11-16 15:55:39-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-11-16 20:55:39+00:00
log53a232e51d193ffc816347bda64921e869e6f32a
treeaeb18dc82da320620d6c941f561cb19fd492d571
parent7cc7ae1fd3d3edb586f2661c5b3adda17b872f9f
signaturebadge-check Signed by PGP key B5690EEEBB952194

Add realtime scheduling calls to std.os.linux (issue #19671) (#19675)

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

1 files changed, 78 insertions(+), 0 deletions(-)

lib/std/os/linux.zig+78
...@@ -2065,6 +2065,84 @@ pub fn fremovexattr(fd: usize, name: [*:0]const u8) usize {...@@ -2065,6 +2065,84 @@ pub fn fremovexattr(fd: usize, name: [*:0]const u8) usize {
2065 return syscall2(.fremovexattr, fd, @intFromPtr(name));2065 return syscall2(.fremovexattr, fd, @intFromPtr(name));
2066}2066}
20672067
2068pub const sched_param = extern struct {
2069 priority: i32,
2070};
2071
2072pub const SCHED = packed struct(i32) {
2073 pub const Mode = enum(u3) {
2074 /// normal multi-user scheduling
2075 NORMAL = 0,
2076 /// FIFO realtime scheduling
2077 FIFO = 1,
2078 /// Round-robin realtime scheduling
2079 RR = 2,
2080 /// For "batch" style execution of processes
2081 BATCH = 3,
2082 /// Low latency scheduling
2083 IDLE = 5,
2084 /// Sporadic task model deadline scheduling
2085 DEADLINE = 6,
2086 };
2087 mode: Mode, //bits [0, 2]
2088 _3: u27 = 0, //bits [3, 29]
2089 /// set to true to stop children from inheriting policies
2090 RESET_ON_FORK: bool = false, //bit 30
2091 _31: u1 = 0, //bit 31
2092};
2093
2094pub fn sched_setparam(pid: pid_t, param: *const sched_param) usize {
2095 return syscall2(.sched_setparam, @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(param));
2096}
2097
2098pub fn sched_getparam(pid: pid_t, param: *sched_param) usize {
2099 return syscall2(.sched_getparam, @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(param));
2100}
2101
2102pub fn sched_setscheduler(pid: pid_t, policy: SCHED, param: *const sched_param) usize {
2103 return syscall3(.sched_setscheduler, @as(usize, @bitCast(@as(isize, pid))), @intCast(@as(u32, @bitCast(policy))), @intFromPtr(param));
2104}
2105
2106pub fn sched_getscheduler(pid: pid_t) usize {
2107 return syscall1(.sched_getscheduler, @as(usize, @bitCast(@as(isize, pid))));
2108}
2109
2110pub fn sched_get_priority_max(policy: SCHED) usize {
2111 return syscall1(.sched_get_priority_max, @intCast(@as(u32, @bitCast(policy))));
2112}
2113
2114pub fn sched_get_priority_min(policy: SCHED) usize {
2115 return syscall1(.sched_get_priority_min, @intCast(@as(u32, @bitCast(policy))));
2116}
2117
2118pub fn getcpu(cpu: ?*usize, node: ?*usize) usize {
2119 return syscall2(.getcpu, @intFromPtr(cpu), @intFromPtr(node));
2120}
2121
2122pub const sched_attr = extern struct {
2123 size: u32 = 48, // Size of this structure
2124 policy: u32 = 0, // Policy (SCHED_*)
2125 flags: u64 = 0, // Flags
2126 nice: u32 = 0, // Nice value (SCHED_OTHER, SCHED_BATCH)
2127 priority: u32 = 0, // Static priority (SCHED_FIFO, SCHED_RR)
2128 // Remaining fields are for SCHED_DEADLINE
2129 runtime: u64 = 0,
2130 deadline: u64 = 0,
2131 period: u64 = 0,
2132};
2133
2134pub fn sched_setattr(pid: pid_t, attr: *const sched_attr, flags: usize) usize {
2135 return syscall3(.sched_setattr, @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(attr), flags);
2136}
2137
2138pub fn sched_getattr(pid: pid_t, attr: *sched_attr, size: usize, flags: usize) usize {
2139 return syscall4(.sched_getattr, @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(attr), size, flags);
2140}
2141
2142pub fn sched_rr_get_interval(pid: pid_t, tp: *timespec) usize {
2143 return syscall2(.sched_rr_get_interval, @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(tp));
2144}
2145
2068pub fn sched_yield() usize {2146pub fn sched_yield() usize {
2069 return syscall0(.sched_yield);2147 return syscall0(.sched_yield);
2070}2148}