diff --git a/src/interrupts.rs b/src/interrupts.rs index f6f5c4f..ea2735b 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -1,16 +1,12 @@ use crate::{ - bootinfo::BOOTINFO, - print, println, - tasking::{InvalidPid, IpcMessage, SleepReason}, - virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE}, - TASKING, + bootinfo::BOOTINFO, pit::NUM_INTERRUPTS, print, println, tasking::{InvalidPid, IpcMessage, SleepReason}, virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE}, TASKING }; use alloc::{boxed::Box, vec::Vec}; use az::WrappingCast; use cast::{u64, usize}; use core::{ arch::{asm, naked_asm}, - ptr, slice, + ptr, slice, sync::atomic::Ordering, }; use hashbrown::HashMap; use pic8259::ChainedPics; @@ -809,6 +805,13 @@ extern "C" fn syscall_handler() { } 35 => TASKING.unlock_mutex(usize(regs.rcx)), 36 => TASKING.drop_mutex(usize(regs.rcx)), + 37 => { + // Frequency of clock ticks + retval = 1000; + } + 38 => { + retval = NUM_INTERRUPTS.load(Ordering::Relaxed); + } _ => (), }; unsafe { SYSCALL_REGS = regs }; diff --git a/src/main.rs b/src/main.rs index 0312383..bec0edd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,7 +129,7 @@ pub fn main() { Lazy::force(&KERNEL_SPACE); Lazy::force(&ACTIVE_SPACE); interrupts::init(); - pit::init(100); + pit::init(1000); let initrd = unsafe { let ramdisk_start = BOOTINFO.ramdisk_addr.into_option().expect("initrd no present"); let ramdisk_len = BOOTINFO.ramdisk_len; diff --git a/src/pit.rs b/src/pit.rs index f9c39fd..e8b57d9 100644 --- a/src/pit.rs +++ b/src/pit.rs @@ -1,3 +1,5 @@ +use core::sync::atomic::{AtomicU64, Ordering}; + use crate::{ interrupts::{self, EoiGuard}, println, TASKING, @@ -10,6 +12,8 @@ static CMD: Mutex> = Mutex::new(PortWriteOnly::new(0x43)); const MAX_FREQ: u32 = 1_193_180; +pub static NUM_INTERRUPTS: AtomicU64 = AtomicU64::new(0); + pub fn init(mut freq: u32) { assert_ne!(freq, 0); #[expect( @@ -47,6 +51,7 @@ pub fn init(mut freq: u32) { } fn handler(_irq: u8, eoi_guard: EoiGuard) { + NUM_INTERRUPTS.fetch_add(1, Ordering::Relaxed); drop(eoi_guard); if TASKING.ok_to_yield() { TASKING.task_yield();