Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions lib/std/os/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,58 @@ pub fn fremovexattr(fd: usize, name: [*:0]const u8) usize {
return syscall2(.fremovexattr, fd, @intFromPtr(name));
}

pub const sched_param = extern struct {
sched_priority: i32,
};

pub const SCHED = packed struct(i32) {
pub const Mode = enum(u3) {
/// normal multi-user scheduling
OTHER = 0,
/// FIFO realtime scheduling
FIFO = 1,
/// Round-robin realtime scheduling
RR = 2,
/// For "batch" style execution of processes
BATCH = 3,
/// Low latency scheduling
ISO = 4,
/// For running very low priority background jobs
IDLE = 5,
/// Sporadic task model deadline scheduling
DEADLINE = 6,
};
mode: Mode, //bits [0, 2]
_3: u27 = 0, //bits [3, 29]
/// set to true to stop children from inheriting policies
RESET_ON_FORK: bool = false, //bit 30
_31: u1 = 0, //bit 31
};

pub fn sched_setparam(pid: pid_t, param: *const sched_param) usize {
return syscall2(.sched_setparam, @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(param));
}

pub fn sched_getparam(pid: pid_t, param: *sched_param) usize {
return syscall2(.sched_getparam, @as(usize, @bitCast(@as(isize, pid))), @intFromPtr(param));
}

pub fn sched_setscheduler(pid: pid_t, policy: SCHED, param: *const sched_param) usize {
return syscall3(.sched_setscheduler, @as(usize, @bitCast(@as(isize, pid))), @intCast(@as(u32, @bitCast(policy))), @intFromPtr(param));
}

pub fn sched_getscheduler(pid: pid_t) SCHED {
return @bitCast( @as(u32, @intCast(syscall1(.sched_getscheduler, @as(usize, @bitCast(@as(isize, pid)))))));
}

pub fn sched_get_priority_max(policy: SCHED) isize {
return @bitCast(syscall1(.sched_get_priority_max,@intCast(@as(u32, @bitCast(policy)))));
}

pub fn sched_get_priority_min(policy: SCHED) isize {
return @bitCast(syscall1(.sched_get_priority_min, @intCast(@as(u32, @bitCast(policy)))));
}

pub fn sched_yield() usize {
return syscall0(.sched_yield);
}
Expand Down