Priority Scheduler

This commit is contained in:
Akshit Gaur
2026-04-18 00:45:46 +00:00
committed by Jeremy Soller
parent c35c291bea
commit 87b16e6d12
5 changed files with 52 additions and 18 deletions
Generated
+4 -4
View File
@@ -256,9 +256,9 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
[[package]]
name = "libredox"
version = "0.1.14"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1744e39d1d6a9948f4f388969627434e31128196de472883b39f148769bfe30a"
checksum = "e02f3bb43d335493c96bf3fd3a321600bf6bd07ed34bc64118e9293bdffea46c"
dependencies = [
"bitflags",
"libc",
@@ -472,9 +472,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.7.3"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce70a74e890531977d37e532c34d45e9055d2409ed08ddba14529471ed0be16"
checksum = "f450ad9c3b1da563fb6948a8e0fb0fb9269711c9c73d9ea1de5058c79c8d643a"
dependencies = [
"bitflags",
]
+2 -2
View File
@@ -67,8 +67,8 @@ bitflags = "2"
ioslice = { version = "0.6", default-features = false }
plain = "0.2"
redox-path = "0.3"
redox_protocols = { package = "libredox", version = "0.1.14", default-features = false, features = ["protocol"] }
redox_syscall = "0.7.3"
redox_protocols = { package = "libredox", version = "0.1.16", default-features = false, features = ["protocol"] }
redox_syscall = "0.7.4"
[build-dependencies]
cc = "1"
+1 -1
View File
@@ -1119,7 +1119,7 @@ pub fn new_child_process(args: &ForkArgs<'_>) -> Result<NewChildProc> {
pid: 0,
euid: 0,
egid: 0,
ens: 1,
prio: !0, // Value is overwritten later
debug_name: {
let mut buf = [0; 32];
let src = b"[init]";
+31
View File
@@ -110,6 +110,37 @@ pub fn posix_getppid() -> u32 {
this_proc_call(&mut [], CallFlags::empty(), &[ProcCall::Getppid as u64]).expect("cannot fail")
as u32
}
#[inline]
pub fn posix_setpriority(which: i32, who: u32, prio: u32) -> Result<(), syscall::Error> {
if which != 0 {
return Err(syscall::Error::new(syscall::EINVAL)); // TODO: Add support for PRIO_PGRP and PRIO_PROCESS
}
this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::SetProcPriority as u64, who as u64, prio as u64],
)?;
Ok(())
}
#[inline]
pub fn posix_getpriority(which: i32, who: u32) -> Result<u32, syscall::Error> {
if which != 0 {
return Err(syscall::Error::new(syscall::EINVAL));
}
let res = this_proc_call(
&mut [],
CallFlags::empty(),
&[ProcCall::GetProcPriority as u64, who as u64],
)?;
Ok(res as u32)
}
#[inline]
pub unsafe fn sys_futex_wait(addr: *mut u32, val: u32, deadline: Option<&TimeSpec>) -> Result<()> {
wrapper(true, false, || {
+14 -11
View File
@@ -634,8 +634,13 @@ impl Pal for Sys {
}
fn getpriority(which: c_int, who: id_t) -> Result<c_int> {
todo_skip!(0, "getpriority({}, {}): not implemented", which, who);
Err(Errno(ENOSYS))
match redox_rt::sys::posix_getpriority(which, who as u32) {
Ok(kernel_prio) => {
let posix_prio = (kernel_prio as i32 * -1) + 40 as i32;
Ok(posix_prio)
}
Err(e) => Err(Errno(e.errno)),
}
}
fn getrandom(buf: &mut [u8], flags: c_uint) -> Result<usize> {
@@ -1197,15 +1202,13 @@ impl Pal for Sys {
}
fn setpriority(which: c_int, who: id_t, prio: c_int) -> Result<()> {
// TODO
todo_skip!(
0,
"setpriority({}, {}, {}): not implemented",
which,
who,
prio
);
Err(Errno(ENOSYS))
let clamped_prio = prio.clamp(-20, 19);
let kernel_prio = (20 + clamped_prio) as u32;
match redox_rt::sys::posix_setpriority(which, who as u32, kernel_prio) {
Ok(_) => Ok(()),
Err(e) => Err(Errno(e.errno)),
}
}
fn setsid() -> Result<c_int> {