scheduler work done

This commit is contained in:
Able 2022-01-25 19:02:22 -06:00
parent 21b5add99d
commit 6010397f4a

View file

@ -1,5 +1,14 @@
#![allow(clippy::empty_loop)]
use alloc::{format, vec::Vec};
use crate::{
boot_conf::BootConfig,
scheduler::{self, SCHEDULER},
};
// use crate::scheduler;
use {
crate::{
arch::{init, sloop},
@ -12,11 +21,9 @@ use {
relib::math::rand::RAND_HANDLE,
relib::network::socket::Socket,
relib::network::socket::{SimpleSock, SocketReturns},
scheduler::{test_fn, Thread, ThreadList},
vga_e::{self, num_to_vga16},
},
alloc::{
format,
string::{String, ToString},
vec,
},
@ -39,64 +46,76 @@ pub extern "C" fn stack_overflow() -> u8 {
lazy_static! {
pub static ref KEY_BUFFER: spin::Mutex<String> = spin::Mutex::new("".to_string());
pub static ref THREAD_LIST: spin::Mutex<ThreadList> = spin::Mutex::new(vec![]);
pub static ref TICK: AtomicU64 = AtomicU64::new(0);
pub static ref BOOT_CONF: BootConfig = boot_conf::BootConfig::new();
}
#[no_mangle]
pub fn kernel_main() -> ! {
let boot_conf = boot_conf::BootConfig::new();
init::init();
log::set_max_level(boot_conf.log_level());
log::set_max_level(BOOT_CONF.log_level());
// info!("Initialized");
graphics_pipe_startup();
/*
if false {
let mut proc_1 = SimpleSock::new();
proc_1.register_protocol("ProcessSpawner".to_string());
{
let mut proc_1 = SimpleSock::new();
proc_1.register_protocol("ProcSpawner".to_string());
let version = 0;
use rkyv::ser::Serializer;
let mut serializer = AllocSerializer::<0>::default();
serializer.serialize_value(&version).unwrap();
let version = 0;
use rkyv::ser::Serializer;
let mut serializer = AllocSerializer::<0>::default();
serializer.serialize_value(&version).unwrap();
let bytes = serializer.into_serializer().into_inner();
proc_1.write(bytes.into_vec());
unsafe {
let the_bytes = proc_1.read(3).unwrap();
let archived = rkyv::archived_root::<Version>(&the_bytes);
let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap();
// trace!("{:?}", deserialized);
}
let bytes = serializer.into_serializer().into_inner();
proc_1.write(bytes.into_vec());
unsafe {
let the_bytes = proc_1.read(3).unwrap();
let archived = rkyv::archived_root::<Version>(&the_bytes);
let deserialized: Version = archived.deserialize(&mut rkyv::Infallible).unwrap();
trace!("{:?}", deserialized);
}
*/
}
let mut graphics = SCREEN_BUFFER.lock();
graphics.force_redraw();
graphics.clear();
use crate::scheduler::Priority;
let mut scheduler = SCHEDULER.lock();
screen_writer_test();
graphics.draw_filled_circle(100, 100, 50, 0x9900ff00);
use Priority::*;
scheduler.new_process(High);
scheduler.new_process(High);
scheduler.new_process(Low);
scheduler.new_process(Low);
scheduler.new_process(Low);
scheduler.new_process(Low);
scheduler.new_process(Medium);
scheduler.new_process(Medium);
scheduler.new_process(High);
graphics.copy_to_buffer();
for x in &scheduler.list {
trace!("{:?}", x);
}
drop(scheduler);
if boot_conf.run_tests {
use crate::wasm::WasmProgram;
let ret = WasmProgram::new_from_bytes(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
trace!("Binary Valid: {:?}", ret.validate_header());
// add a plus b
if BOOT_CONF.run_tests {
// quick and dirty testing framework
screen_writer_test();
socket_test();
graphics_pipe_test();
socket_startup_rng();
socket_test_rng();
}
if boot_conf.run_demos {
if BOOT_CONF.run_demos {
graphics_api_demo();
}
if boot_conf.run_shader_tests {
if BOOT_CONF.run_shader_tests {
shader_tests();
}
@ -115,6 +134,10 @@ pub fn tick() {
RAND_HANDLE.lock().seed_entropy_timer(data);
crate::kernel_state::KERNEL_STATE.lock().update_state();
let mut scheduler = SCHEDULER.lock();
scheduler.bump_exec();
TICK.store(data, Relaxed)
}
@ -122,14 +145,6 @@ pub fn key_entropy(key: u8) {
RAND_HANDLE.lock().seed_entropy_keyboard(key);
}
pub fn test_threads() {
let mut a_thread = Thread::new();
a_thread.new_task(test_fn);
a_thread.new_task(test_fn);
THREAD_LIST.lock().push(a_thread);
}
pub fn cpu_socket_startup() {
let mut cpu_info_socket = SimpleSock::new();
cpu_info_socket.register_protocol("CPU_INFO".to_string());
@ -197,10 +212,13 @@ pub fn screen_writer_test() {
let mut sock_print_id = SimpleSock::new();
sock_print_id.register_protocol("Screen Printer".to_string());
//
// sock_print_id.write(format!("a原 b画 cフ dァ eイ fル 集").into());
// sock_print_id.write(format!("λ³ Half Life 3 booting up ㎣").into());
sock_print_id.write(format!("Happy birthday 🎉").into());
// sock_print_id.write(format!("⋮").into());
sock_print_id.write(format!("λ³ Half Life 3 booting up ㎣").into());
// sock_print_id.write(format!("Happy birthday 🎉").into());
// sock_print_id.write(format!("I look forward to ur ai stuff :^>").into());
// sock_print_id.write(format!("1....2....3....4....5....6....7....8....9").into());
let mut prev = None;