From 359d62c1b012db43e3b553aabdce4b83480842a9 Mon Sep 17 00:00:00 2001 From: MunirG05 Date: Mon, 10 Jul 2023 17:14:11 +0530 Subject: [PATCH 1/5] i pushed so i can work on it in windows thanks --- kernel/src/kmain.rs | 20 +++++++++------ kernel/src/scheduler.rs | 55 +++++++++++++++++++++++++++++------------ repbuild/src/main.rs | 2 +- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 5a3fd52..72cb2e3 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -6,6 +6,8 @@ use { arch::logging::SERIAL_CONSOLE, bootmodules::{build_cmd, BootModules}, device_tree::DeviceTree, + scheduler::Scheduler, + }, alloc::format, log::{debug, info, trace}, @@ -30,7 +32,7 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! { let dt = DEVICE_TREE.lock(); - info!("Device Tree{}", dt); + info!("Device Tree: {}", dt); info!("Boot complete. Moving to init_system"); // TODO: schedule the disk driver from the initramfs @@ -59,13 +61,17 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! { // log::error!("Program validation error: {e:?}"); } Ok(_) => { + // log::info!("valid program"); - use {crate::host::TrapHandler, hbvm::vm::Vm}; - let mut vm; - unsafe { - vm = Vm::new_unchecked(&prog, TrapHandler); - vm.memory.insert_test_page(); - } + // use {crate::host::TrapHandler, hbvm::vm::Vm}; + let mut sched = Scheduler::new(); + sched.new_process(prog.clone()); + sched.scheduler_loop(); + // let mut vm; + // unsafe { + // vm = Vm::new_unchecked(&prog, TrapHandler); + // vm.memory.insert_test_page(); + // } // log::info!("Program interrupt: {:?}", vm.run()); // log::debug!("{:?}", vm.registers); } diff --git a/kernel/src/scheduler.rs b/kernel/src/scheduler.rs index 6543e6c..8af7bfa 100644 --- a/kernel/src/scheduler.rs +++ b/kernel/src/scheduler.rs @@ -1,22 +1,45 @@ -use {crate::host::TrapHandler, alloc::vec::Vec, hbvm::vm::Vm}; +use alloc::{collections::VecDeque, vec::Vec, rc::Rc, slice}; +use hbvm::validate::validate; + +use {crate::host::TrapHandler, hbvm::vm::Vm}; pub struct Scheduler<'a> { - data: Vec>, + data: VecDeque>, } impl Scheduler<'_> { - // fn new_process(&mut self, program: Vec) { - // let prog = program.clone(); - // #[allow(clippy::redundant_else)] - // if let Err(e) = validate(&prog) { - // log::error!("Program validation error: {e:?}"); - // } else { - // log::info!("valid program"); - // unsafe { - // let mut vm = Vm::new_unchecked(&prog, TrapHandler); - // vm.memory.insert_test_page(); - // self.data.push(vm); - // } - // } - // } + pub fn new() -> Self { + Self { + data: VecDeque::new(), + } + } + pub fn new_process(&mut self, program: Vec) { + let prog = program.clone(); + let prog_arc = Rc::new(prog); + + let binding = Rc::try_unwrap(prog_arc).ok().unwrap(); + + + + #[allow(clippy::redundant_else)] + if let Err(e) = validate(&program.as_slice()) { + log::error!("Program validation error: {e:?}"); + } else { + log::info!("valid program"); + unsafe { + let slice = slice::from_raw_parts(binding.as_ptr(), binding.len()); + let mut vm = Vm::new_unchecked(&*slice, TrapHandler); + vm.memory.insert_test_page(); + self.data.push_front(vm); + } + } + } + + pub fn scheduler_loop(&mut self){ + loop { + let mut prog = self.data.pop_front().unwrap(); + prog.run().unwrap(); + self.data.push_back(prog); + } + } } diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 1424038..68ebe26 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -187,7 +187,7 @@ fn run(release: bool, target: Target) -> Result<(), Error> { #[cfg(target_os = "linux")] { - // com.args(["-enable-kvm", "-cpu", "host"]); + //com.args(["-enable-kvm", "-cpu", "host"]); } } From bb27f48f4a19cba74c902b8b4d5a2440c4537ab6 Mon Sep 17 00:00:00 2001 From: MunirG05 Date: Mon, 10 Jul 2023 23:43:42 +0530 Subject: [PATCH 2/5] scheduler but i stole the code from the engine and tried to stuff it into the scheduler and i have no idea if it works or not but it porbably does --- a.out | 0 kernel/src/kmain.rs | 2 +- kernel/src/scheduler.rs | 35 ++++++++++++++++++++++++++++------- 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 a.out diff --git a/a.out b/a.out new file mode 100644 index 0000000..e69de29 diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 72cb2e3..e6bd82e 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -66,7 +66,7 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! { // use {crate::host::TrapHandler, hbvm::vm::Vm}; let mut sched = Scheduler::new(); sched.new_process(prog.clone()); - sched.scheduler_loop(); + sched.scheduler_run(); // let mut vm; // unsafe { // vm = Vm::new_unchecked(&prog, TrapHandler); diff --git a/kernel/src/scheduler.rs b/kernel/src/scheduler.rs index 8af7bfa..066bb53 100644 --- a/kernel/src/scheduler.rs +++ b/kernel/src/scheduler.rs @@ -1,26 +1,37 @@ -use alloc::{collections::VecDeque, vec::Vec, rc::Rc, slice}; -use hbvm::validate::validate; +use { + alloc::{collections::VecDeque, rc::Rc, slice, vec::Vec}, + hbvm::validate::validate, +}; use {crate::host::TrapHandler, hbvm::vm::Vm}; pub struct Scheduler<'a> { data: VecDeque>, + pub tick_callback: Option u64>, + pub last_timer_count: u64, + pub tick_limit: u64, } +// NOTE: This is a very simple schduler and it sucks and should be replaced with a better one +// Written By Yours Truly: Munir + + + impl Scheduler<'_> { pub fn new() -> Self { Self { data: VecDeque::new(), + tick_callback: None, + last_timer_count: 0, + tick_limit: 64, } } pub fn new_process(&mut self, program: Vec) { let prog = program.clone(); let prog_arc = Rc::new(prog); - + let binding = Rc::try_unwrap(prog_arc).ok().unwrap(); - - - + #[allow(clippy::redundant_else)] if let Err(e) = validate(&program.as_slice()) { log::error!("Program validation error: {e:?}"); @@ -35,11 +46,21 @@ impl Scheduler<'_> { } } - pub fn scheduler_loop(&mut self){ + pub fn scheduler_run(&mut self) -> Option { loop { let mut prog = self.data.pop_front().unwrap(); prog.run().unwrap(); self.data.push_back(prog); + if self.tick_callback.is_some() { + let ret = self.tick_callback.unwrap()(); + if (ret - self.last_timer_count) >= self.tick_limit { + + return Some(0); + + } + } + break; } + Some(1) } } From 7a00dff4b9cc31acfbd9474999208290b521d76b Mon Sep 17 00:00:00 2001 From: MunirG05 Date: Tue, 11 Jul 2023 13:30:45 +0530 Subject: [PATCH 3/5] fix the dumb --- kernel/src/scheduler.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/kernel/src/scheduler.rs b/kernel/src/scheduler.rs index 066bb53..cca1dfc 100644 --- a/kernel/src/scheduler.rs +++ b/kernel/src/scheduler.rs @@ -7,9 +7,6 @@ use {crate::host::TrapHandler, hbvm::vm::Vm}; pub struct Scheduler<'a> { data: VecDeque>, - pub tick_callback: Option u64>, - pub last_timer_count: u64, - pub tick_limit: u64, } // NOTE: This is a very simple schduler and it sucks and should be replaced with a better one @@ -51,16 +48,5 @@ impl Scheduler<'_> { let mut prog = self.data.pop_front().unwrap(); prog.run().unwrap(); self.data.push_back(prog); - if self.tick_callback.is_some() { - let ret = self.tick_callback.unwrap()(); - if (ret - self.last_timer_count) >= self.tick_limit { - - return Some(0); - - } - } - break; - } - Some(1) } } From 2af768453295cea2a0c998a136aff2115b2ec94c Mon Sep 17 00:00:00 2001 From: MunirG05 Date: Tue, 11 Jul 2023 13:32:40 +0530 Subject: [PATCH 4/5] fix the dumb --- kernel/src/scheduler.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/src/scheduler.rs b/kernel/src/scheduler.rs index cca1dfc..d7724fd 100644 --- a/kernel/src/scheduler.rs +++ b/kernel/src/scheduler.rs @@ -18,9 +18,7 @@ impl Scheduler<'_> { pub fn new() -> Self { Self { data: VecDeque::new(), - tick_callback: None, - last_timer_count: 0, - tick_limit: 64, + } } pub fn new_process(&mut self, program: Vec) { @@ -48,5 +46,6 @@ impl Scheduler<'_> { let mut prog = self.data.pop_front().unwrap(); prog.run().unwrap(); self.data.push_back(prog); + } } } From 56ec28550f4f66aa8ab5a510bc92b3c541877837 Mon Sep 17 00:00:00 2001 From: MunirG05 Date: Wed, 12 Jul 2023 22:16:14 +0530 Subject: [PATCH 5/5] does this fix the issue?? --- repbuild/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 68ebe26..1424038 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -187,7 +187,7 @@ fn run(release: bool, target: Target) -> Result<(), Error> { #[cfg(target_os = "linux")] { - //com.args(["-enable-kvm", "-cpu", "host"]); + // com.args(["-enable-kvm", "-cpu", "host"]); } }