1
0
Fork 0
forked from AbleOS/ableos

scheduler rewrite

This commit is contained in:
Able 2022-02-01 15:27:40 -06:00
parent 098c27590a
commit 3b9a3ab18a
6 changed files with 105 additions and 13 deletions

View file

@ -119,6 +119,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
print!("{:?}", KeyCode::from(key)) print!("{:?}", KeyCode::from(key))
} }
}, },
// Register a keyboard interrupt handler for the given scancode.
} }
} }
} }

View file

@ -26,14 +26,6 @@ use {
log::*, log::*,
}; };
#[no_mangle]
#[allow(unconditional_recursion)]
pub extern "C" fn stack_overflow() -> u8 {
stack_overflow();
// meme number
69 // NOTE: Any specific reason for this number aside from memes?
}
lazy_static! { lazy_static! {
pub static ref TICK: AtomicU64 = AtomicU64::new(0); pub static ref TICK: AtomicU64 = AtomicU64::new(0);
pub static ref BOOT_CONF: BootConfig = boot_conf::BootConfig::new(); pub static ref BOOT_CONF: BootConfig = boot_conf::BootConfig::new();
@ -83,8 +75,6 @@ pub fn kernel_main() -> ! {
} }
} }
crate::tests::screen_writer_test();
use crate::wasm::WasmProgram; use crate::wasm::WasmProgram;
let ret = WasmProgram::new_from_bytes(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]); let ret = WasmProgram::new_from_bytes(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
trace!("Binary Valid: {:?}", ret.validate_header()); trace!("Binary Valid: {:?}", ret.validate_header());

View file

@ -1,8 +1,17 @@
#![warn(missing_docs)] #![warn(missing_docs)]
use alloc::{vec, vec::Vec};
//! The standard ableOS scheduler named
//!
//! # Notes
//! The scheduler is also responsible for choosing the priority of a process.
//! The scheduler is responsible for choosing which process to execute next.
use alloc::vec::Vec;
pub mod capabilities; pub mod capabilities;
pub mod proc; pub mod proc;
mod new_sched;
use proc::{Process, PID}; use proc::{Process, PID};
#[cfg(test)] #[cfg(test)]
@ -13,7 +22,6 @@ use crate::file::PathRep;
use self::capabilities::Capabilities; use self::capabilities::Capabilities;
lazy_static::lazy_static!( lazy_static::lazy_static!(
/// The standard implementation for ableOS /// The standard implementation for ableOS
pub static ref SCHEDULER: spin::Mutex<Scheduler> = spin::Mutex::new(Scheduler::new()); pub static ref SCHEDULER: spin::Mutex<Scheduler> = spin::Mutex::new(Scheduler::new());

View file

@ -0,0 +1,85 @@
use alloc::vec::Vec;
use crate::{
capabilities::Capabilities,
proc::{Process, PID},
Priority,
};
/// Add additional wake conditions to the list
pub enum WakeCondition {
/// Wake when the process has been blocked for a certain amount of time
TimerInterrupt(u64),
SocketRead(PID),
SocketWrite(PID),
SocketOpen(PID),
SocketClose(PID),
// HardwareEvent,
}
// NOTE: Define what is a sleeping process in the context of the ableOS kernel.
// Blocked processes are processes that are waiting for a certain event to occur.
pub struct BlockedProcess {
pub pid: PID,
pub wake_time: u64,
}
pub struct Scheduler {
pub free_pid: PID,
pub process_exec_time: u64,
pub execution_queue: Vec<Process>,
pub sleeping_queue: Vec<Process>,
// pub blocked_queue: Vec<BlockedProcess>,
// / All timed processes sorted by wake time
// pub timed_blocked_queue: Vec<BlockedProcess>,
}
impl Scheduler {
/// Create a new scheduler
pub fn new() -> Self {
Self {
free_pid: PID(0),
process_exec_time: 0,
execution_queue: Vec::new(),
sleeping_queue: Vec::new(),
}
}
/// Change the current process to the next process in the list
pub fn next_process(&mut self) {
self.process_exec_time = 0;
let previous_task = self.execution_queue[0].clone();
self.execution_queue.remove(0);
self.execution_queue.push(previous_task);
}
/// Creates a new process
/// # Arguments
/// * `priority` - The priority of the process
/// # Example
///
/// ```
/// let mut scheduler = scheduler();
/// let mut process = scheduler.new_process(Priority::Medium);
/// ```
///
/// TODO: Add a priority queue
/// TODO: Add a process queue
pub fn new_process(&mut self, priority: Priority) -> Process {
let process = Process {
id: self.free_pid,
priority,
capabilities: Capabilities::empty(),
};
self.free_pid.0 += 1;
process
}
pub fn sleep_process(&mut self, process: &mut Process) {
let sleeping_process = BlockedProcess {
pid: process.id,
wake_time: 0,
};
self.sleeping_queue.push(process.clone());
self.execution_queue.remove(0);
}
}

View file

@ -3,7 +3,7 @@
use super::{capabilities::Capabilities, FileAccessTypes, Priority}; use super::{capabilities::Capabilities, FileAccessTypes, Priority};
/// Process Identification /// Process Identification
#[derive(Clone, PartialEq, Debug)] #[derive(Clone, Copy, PartialEq, Debug)]
pub struct PID(pub usize); pub struct PID(pub usize);

View file

@ -16,3 +16,11 @@ mod tests {
assert_eq!(type_of(&1), "i32"); assert_eq!(type_of(&1), "i32");
} }
} }
#[no_mangle]
#[allow(unconditional_recursion)]
pub extern "C" fn stack_overflow() -> u8 {
stack_overflow();
// meme number
69 // NOTE: Any specific reason for this number aside from memes?
}