Keep track of # of clock ticks and bump PIT freq to 1kHz

This commit is contained in:
pjht 2024-11-28 14:04:38 -06:00
parent 7284cef45a
commit a4a8bf0152
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
3 changed files with 15 additions and 7 deletions

View File

@ -1,16 +1,12 @@
use crate::{ use crate::{
bootinfo::BOOTINFO, bootinfo::BOOTINFO, pit::NUM_INTERRUPTS, print, println, tasking::{InvalidPid, IpcMessage, SleepReason}, virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE}, TASKING
print, println,
tasking::{InvalidPid, IpcMessage, SleepReason},
virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE},
TASKING,
}; };
use alloc::{boxed::Box, vec::Vec}; use alloc::{boxed::Box, vec::Vec};
use az::WrappingCast; use az::WrappingCast;
use cast::{u64, usize}; use cast::{u64, usize};
use core::{ use core::{
arch::{asm, naked_asm}, arch::{asm, naked_asm},
ptr, slice, ptr, slice, sync::atomic::Ordering,
}; };
use hashbrown::HashMap; use hashbrown::HashMap;
use pic8259::ChainedPics; use pic8259::ChainedPics;
@ -809,6 +805,13 @@ extern "C" fn syscall_handler() {
} }
35 => TASKING.unlock_mutex(usize(regs.rcx)), 35 => TASKING.unlock_mutex(usize(regs.rcx)),
36 => TASKING.drop_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 }; unsafe { SYSCALL_REGS = regs };

View File

@ -129,7 +129,7 @@ pub fn main() {
Lazy::force(&KERNEL_SPACE); Lazy::force(&KERNEL_SPACE);
Lazy::force(&ACTIVE_SPACE); Lazy::force(&ACTIVE_SPACE);
interrupts::init(); interrupts::init();
pit::init(100); pit::init(1000);
let initrd = unsafe { let initrd = unsafe {
let ramdisk_start = BOOTINFO.ramdisk_addr.into_option().expect("initrd no present"); let ramdisk_start = BOOTINFO.ramdisk_addr.into_option().expect("initrd no present");
let ramdisk_len = BOOTINFO.ramdisk_len; let ramdisk_len = BOOTINFO.ramdisk_len;

View File

@ -1,3 +1,5 @@
use core::sync::atomic::{AtomicU64, Ordering};
use crate::{ use crate::{
interrupts::{self, EoiGuard}, interrupts::{self, EoiGuard},
println, TASKING, println, TASKING,
@ -10,6 +12,8 @@ static CMD: Mutex<PortWriteOnly<u8>> = Mutex::new(PortWriteOnly::new(0x43));
const MAX_FREQ: u32 = 1_193_180; const MAX_FREQ: u32 = 1_193_180;
pub static NUM_INTERRUPTS: AtomicU64 = AtomicU64::new(0);
pub fn init(mut freq: u32) { pub fn init(mut freq: u32) {
assert_ne!(freq, 0); assert_ne!(freq, 0);
#[expect( #[expect(
@ -47,6 +51,7 @@ pub fn init(mut freq: u32) {
} }
fn handler(_irq: u8, eoi_guard: EoiGuard) { fn handler(_irq: u8, eoi_guard: EoiGuard) {
NUM_INTERRUPTS.fetch_add(1, Ordering::Relaxed);
drop(eoi_guard); drop(eoi_guard);
if TASKING.ok_to_yield() { if TASKING.ok_to_yield() {
TASKING.task_yield(); TASKING.task_yield();