Deficit based Weighted Round Robin Scheduler
This commit is contained in:
committed by
Jeremy Soller
parent
74895c4f0f
commit
b7dabfc3c2
+72
-1
@@ -7,9 +7,10 @@ use syscall::data::GlobalSchemes;
|
||||
use crate::{
|
||||
context::{
|
||||
context::SyscallFrame,
|
||||
contexts,
|
||||
file::{FileDescription, FileDescriptor, InternalFlags},
|
||||
memory::{AddrSpace, Grant, PageSpan},
|
||||
ContextRef,
|
||||
ContextLock, ContextRef,
|
||||
},
|
||||
event,
|
||||
sync::{CleanLockToken, RwLock},
|
||||
@@ -274,3 +275,73 @@ fn insert_fd(scheme: SchemeId, number: usize, cloexec: bool, token: &mut CleanLo
|
||||
.expect("failed to insert fd to current context")
|
||||
.get()
|
||||
}
|
||||
|
||||
pub unsafe fn setpriority(which: usize, who: usize, prio: usize) -> Result<usize> {
|
||||
if prio >= 40 {
|
||||
return Err(Error::new(EINVAL));
|
||||
}
|
||||
|
||||
if which != 0 {
|
||||
return Err(Error::new(EINVAL)); // TODO: Support for PRIO_PGRP and PRIO_USER
|
||||
}
|
||||
|
||||
let mut token = unsafe { CleanLockToken::new() };
|
||||
let mut local_token = unsafe { CleanLockToken::new() };
|
||||
|
||||
let context_lock = {
|
||||
if who == 0 {
|
||||
context::current()
|
||||
} else {
|
||||
let contexts_guard = contexts(token.token());
|
||||
|
||||
let found = contexts_guard.iter().filter_map(|r| r.upgrade()).find(|c| {
|
||||
let guard = c.read(local_token.token());
|
||||
guard.pid == who
|
||||
});
|
||||
|
||||
match found {
|
||||
Some(c) => c,
|
||||
None => return Err(Error::new(ESRCH)),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
let current_lock = context::current();
|
||||
let current_euid = context::current().read(local_token.token()).euid;
|
||||
let target_euid = context_lock.read(local_token.token()).euid;
|
||||
|
||||
if current_euid != 0 && current_euid != target_euid {
|
||||
return Err(Error::new(EPERM));
|
||||
}
|
||||
}
|
||||
|
||||
match context::set_priority(&context_lock, prio, &mut local_token) {
|
||||
Ok(_) => Ok(0),
|
||||
Err(_) => Err(Error::new(ESRCH)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getpriority(which: usize, who: usize) -> Result<usize> {
|
||||
let mut token = unsafe { CleanLockToken::new() };
|
||||
let mut local_token = unsafe { CleanLockToken::new() };
|
||||
|
||||
let context_lock = {
|
||||
if who == 0 {
|
||||
context::current()
|
||||
} else {
|
||||
let contexts_guard = contexts(token.token());
|
||||
|
||||
let found = contexts_guard.iter().filter_map(|r| r.upgrade()).find(|c| {
|
||||
let guard = c.read(local_token.token());
|
||||
guard.pid == who
|
||||
});
|
||||
|
||||
match found {
|
||||
Some(c) => c,
|
||||
None => return Err(Error::new(ESRCH)),
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok(context_lock.read(local_token.token()).prio)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user