Make keyboard lock-free (and fix Doom deadlock) by only pushing

scancodes to a spsc queue from the interrupts and only process them
inside syscalls. Also make CURRENT_PID atomic to use less locking
This commit is contained in:
csd4ni3l
2026-04-19 18:22:16 +02:00
parent 2b8a965c92
commit f4c2657b94
11 changed files with 218 additions and 131 deletions
+22 -6
View File
@@ -1,11 +1,27 @@
use core::sync::atomic::{AtomicU64, Ordering};
use alloc::collections::btree_map::BTreeMap;
use x86_64::instructions::interrupts::without_interrupts;
use crate::{arch::arch::enter_usermode, task::process::Process, util::Locked};
pub static CURRENT_PID: AtomicU64 = AtomicU64::new(0);
#[inline]
pub fn current_pid() -> Option<u64> {
match CURRENT_PID.load(Ordering::Relaxed) {
0 => None,
pid => Some(pid),
}
}
#[inline]
pub fn set_current_pid(pid: Option<u64>) {
CURRENT_PID.store(pid.unwrap_or(0), Ordering::Relaxed);
}
pub struct Scheduler {
pub processes: BTreeMap<u64, Process>,
pub current_process: i64,
next_pid: u64,
}
@@ -13,7 +29,6 @@ impl Scheduler {
pub const fn new() -> Scheduler {
Scheduler {
processes: BTreeMap::new(),
current_process: -1,
next_pid: 1,
}
}
@@ -31,11 +46,12 @@ impl Locked<Scheduler> {
}
pub fn run_process(&self, pid: u64, entry_point: *const u8) {
let mut guard = without_interrupts(|| self.lock());
let stack_top = guard.processes[&pid].stack_top;
guard.current_process = pid as i64;
let stack_top = {
let guard = without_interrupts(|| self.lock());
guard.processes[&pid].stack_top
};
drop(guard);
set_current_pid(Some(pid));
enter_usermode(entry_point as u64, (stack_top & !0xF) - 8);
}