buffer awaiting -> free performance and free bugs

This commit is contained in:
koniifer 2024-11-27 16:53:17 +00:00
parent fd26ec734b
commit a551b2672f
7 changed files with 60 additions and 14 deletions

View file

@ -80,6 +80,10 @@ pub fn handler(vm: &mut Vm, pid: &usize) {
let length = vm.registers[5].cast::<u64>() as usize; let length = vm.registers[5].cast::<u64>() as usize;
trace!("IPC address: {:?}", mem_addr); trace!("IPC address: {:?}", mem_addr);
unsafe { LazyCell::<Executor>::get_mut(&mut EXECUTOR) }
.unwrap()
.send_buffer(buffer_id as usize);
match buffer_id { match buffer_id {
0 => match sds_msg_handler(vm, mem_addr, length) { 0 => match sds_msg_handler(vm, mem_addr, length) {
Ok(()) => {} Ok(()) => {}
@ -246,12 +250,22 @@ pub fn handler(vm: &mut Vm, pid: &usize) {
// Wait till interrupt // Wait till interrupt
use crate::kmain::EXECUTOR; use crate::kmain::EXECUTOR;
let interrupt_type = vm.registers[3].cast::<u8>(); let interrupt_type = vm.registers[3].cast::<u8>();
info!("Interrupt subscribled: {}", interrupt_type); debug!("Interrupt subscribed: {}", interrupt_type);
unsafe { unsafe {
EXECUTOR.pause(pid.clone());
LazyCell::<Executor>::get_mut(&mut EXECUTOR) LazyCell::<Executor>::get_mut(&mut EXECUTOR)
.unwrap() .unwrap()
.interrupt_subscribe(pid.clone(), interrupt_type); .interrupt_subscribe(*pid, interrupt_type);
}
}
7 => {
// Wait till buffer
use crate::kmain::EXECUTOR;
let buffer_id = vm.registers[3].cast::<u64>() as usize;
debug!("Buffer subscribed: {}", buffer_id);
unsafe {
LazyCell::<Executor>::get_mut(&mut EXECUTOR)
.unwrap()
.buffer_subscribe(*pid, buffer_id);
} }
} }
_ => { _ => {

View file

@ -1,5 +1,9 @@
use { use {
alloc::{boxed::Box, sync::Arc}, alloc::{
boxed::Box,
collections::{BTreeMap, BTreeSet},
sync::Arc,
},
core::{ core::{
future::Future, future::Future,
pin::Pin, pin::Pin,
@ -36,6 +40,7 @@ pub struct Executor {
tasks: Slab<Task>, tasks: Slab<Task>,
task_queue: Arc<SegQueue<usize>>, task_queue: Arc<SegQueue<usize>>,
interrupt_lookup: [Option<usize>; u8::MAX as usize], interrupt_lookup: [Option<usize>; u8::MAX as usize],
buffer_lookup: BTreeMap<usize, BTreeSet<usize>>,
} }
impl Executor { impl Executor {
@ -44,6 +49,7 @@ impl Executor {
tasks: Slab::new(), tasks: Slab::new(),
task_queue: Arc::new(SegQueue::new()), task_queue: Arc::new(SegQueue::new()),
interrupt_lookup: [None; u8::MAX as usize], interrupt_lookup: [None; u8::MAX as usize],
buffer_lookup: BTreeMap::new(),
} }
} }
@ -68,9 +74,19 @@ impl Executor {
} }
pub fn interrupt_subscribe(&mut self, pid: usize, interrupt_type: u8) { pub fn interrupt_subscribe(&mut self, pid: usize, interrupt_type: u8) {
self.pause(pid);
self.interrupt_lookup[interrupt_type as usize] = Some(pid); self.interrupt_lookup[interrupt_type as usize] = Some(pid);
} }
pub fn buffer_subscribe(&mut self, pid: usize, buffer_id: usize) {
self.pause(pid);
if let Some(buf) = self.buffer_lookup.get_mut(&buffer_id) {
buf.insert(pid);
} else {
self.buffer_lookup.insert(buffer_id, BTreeSet::from([pid]));
}
}
pub fn run(&mut self) { pub fn run(&mut self) {
let mut task_batch = [0; 32]; let mut task_batch = [0; 32];
loop { loop {
@ -108,6 +124,9 @@ impl Executor {
} }
return pid; return pid;
}); });
self.buffer_lookup.iter_mut().for_each(|(_, pid_set)| {
pid_set.remove(&id);
});
} }
} }
} }
@ -120,6 +139,11 @@ impl Executor {
self.unpause(id); self.unpause(id);
} }
} }
pub fn send_buffer(&self, id: usize) {
if let Some(buf) = self.buffer_lookup.get(&id) {
buf.iter().for_each(|pid| self.unpause(*pid));
}
}
} }
struct Task { struct Task {

View file

@ -1,5 +1,9 @@
string := @use("string.hb") string := @use("string.hb")
$await := fn(buffer_id: uint): void {
return @eca(7, buffer_id)
}
$recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void { $recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void {
return @eca(4, buffer_id, memory_map_location, @sizeof(Expr)) return @eca(4, buffer_id, memory_map_location, @sizeof(Expr))
} }

View file

@ -48,6 +48,8 @@ await_channel := fn(): Channel {
await_message := fn($Expr: type, buffer_id: uint): Message(Expr) { await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
response := @as(?Message(Expr), null) response := @as(?Message(Expr), null)
loop { loop {
// awaiting here causes flickering... idk why
buffer.await(buffer_id)
buffer.recv(?Message(Expr), buffer_id, &response) buffer.recv(?Message(Expr), buffer_id, &response)
if response != null { if response != null {
return @as(Message(Expr), response) return @as(Message(Expr), response)
@ -58,9 +60,11 @@ await_message := fn($Expr: type, buffer_id: uint): Message(Expr) {
await_header := fn(buffer_id: uint): MessageHeader { await_header := fn(buffer_id: uint): MessageHeader {
response := @as(?MessageHeader, null) response := @as(?MessageHeader, null)
loop { loop {
// awaiting here causes flickering... idk why
buffer.await(buffer_id)
buffer.recv(?MessageHeader, buffer_id, &response) buffer.recv(?MessageHeader, buffer_id, &response)
if response != null { if response != null {
return @as(?MessageHeader, response) return @as(MessageHeader, response)
} }
} }
} }

View file

@ -91,8 +91,8 @@ main := fn(): int {
// Mouse cursor // Mouse cursor
{ {
render.put_filled_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR_DARKER) render.put_filled_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR_DARKER)
render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR) render.put_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR)
} }
render.sync(screen) render.sync(screen)

View file

@ -3,5 +3,5 @@ serial_driver := @use("./tests/serial_driver.hb")
main := fn(): uint { main := fn(): uint {
// return serial_driver.test() // return serial_driver.test()
return stn.process.test() return stn.sleep.test()
} }

View file

@ -34,14 +34,14 @@ path = "boot:///ps2_mouse_driver.hbf"
# [boot.limine.ableos.modules.ps2_keyboard_driver] # [boot.limine.ableos.modules.ps2_keyboard_driver]
# path = "boot:///ps2_keyboard_driver.hbf" # path = "boot:///ps2_keyboard_driver.hbf"
# [boot.limine.ableos.modules.sunset_client] [boot.limine.ableos.modules.sunset_client]
# path = "boot:///sunset_client.hbf" path = "boot:///sunset_client.hbf"
# [boot.limine.ableos.modules.sunset_client_2] [boot.limine.ableos.modules.sunset_client_2]
# path = "boot:///sunset_client_2.hbf" path = "boot:///sunset_client_2.hbf"
[boot.limine.ableos.modules.sdoom] # [boot.limine.ableos.modules.sdoom]
path = "boot:///sdoom.hbf" # path = "boot:///sdoom.hbf"
[boot.limine.ableos.modules.sunset_server] [boot.limine.ableos.modules.sunset_server]
path = "boot:///sunset_server.hbf" path = "boot:///sunset_server.hbf"