diff --git a/src/arch/x86_64/interrupt/exception.rs b/src/arch/x86_64/interrupt/exception.rs index 6679ee480e..997232189c 100644 --- a/src/arch/x86_64/interrupt/exception.rs +++ b/src/arch/x86_64/interrupt/exception.rs @@ -3,6 +3,7 @@ use core::sync::atomic::Ordering; use x86::irq::PageFaultError; use crate::memory::GenericPfFlags; +use crate::scheme::serio::IS_PROFILING; use crate::{ interrupt::stack_trace, paging::VirtualAddress, @@ -50,6 +51,9 @@ interrupt_stack!(non_maskable, @paranoid, |stack| { let Some(profiling) = crate::percpu::PercpuBlock::current().profiling else { return; }; + if !IS_PROFILING.load(Ordering::Relaxed) { + return; + } if stack.iret.cs & 0b00 == 0b11 { profiling.nmi_ucount.store(profiling.nmi_ucount.load(Ordering::Relaxed) + 1, Ordering::Relaxed); return; diff --git a/src/scheme/serio.rs b/src/scheme/serio.rs index 198e874e79..b46595d7f2 100644 --- a/src/scheme/serio.rs +++ b/src/scheme/serio.rs @@ -1,7 +1,7 @@ //! PS/2 unfortunately requires a kernel driver to prevent race conditions due //! to how status is utilized use core::str; -use core::sync::atomic::{AtomicUsize, Ordering}; +use core::sync::atomic::{AtomicUsize, Ordering, AtomicBool}; use spin::RwLock; @@ -25,8 +25,20 @@ struct Handle { // Using BTreeMap as hashbrown doesn't have a const constructor. static HANDLES: RwLock> = RwLock::new(BTreeMap::new()); +pub const PROFILE_TOGGLEABLE: bool = true; +pub static IS_PROFILING: AtomicBool = AtomicBool::new(false); + /// Add to the input queue pub fn serio_input(index: usize, data: u8) { + if PROFILE_TOGGLEABLE { + if index == 0 && data == 30 { + log::info!("Enabling profiling"); + IS_PROFILING.store(true, Ordering::SeqCst); + } else if index == 0 && data == 48 { + log::info!("Disabling profiling"); + IS_PROFILING.store(false, Ordering::SeqCst); + } + } INPUT[index].send(data); for (id, _handle) in HANDLES.read().iter() {