diff --git a/src/main.rs b/src/main.rs index ee3fc28da8..57815f0455 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,6 +48,7 @@ #![feature(iter_next_chunk)] #![feature(let_chains)] #![feature(naked_functions)] +#![feature(new_uninit)] #![feature(sync_unsafe_cell)] #![feature(variant_count)] #![cfg_attr(not(test), no_std)] diff --git a/src/profiling.rs b/src/profiling.rs index 341b995530..5d07943b1c 100644 --- a/src/profiling.rs +++ b/src/profiling.rs @@ -15,7 +15,7 @@ use crate::{ syscall::{error::*, usercopy::UserSliceWo}, }; -const N: usize = 64 * 1024 * 1024; +const N: usize = 16 * 1024 * 1024; pub const HARDCODED_CPU_COUNT: u32 = 4; @@ -96,7 +96,7 @@ const NULL: AtomicPtr = AtomicPtr::new(core::ptr::null_mut()); pub static BUFS: [AtomicPtr; 4] = [NULL; 4]; pub const PROFILE_TOGGLEABLE: bool = true; -pub static IS_PROFILING: AtomicBool = AtomicBool::new(true); +pub static IS_PROFILING: AtomicBool = AtomicBool::new(false); pub fn serio_command(index: usize, data: u8) { if PROFILE_TOGGLEABLE { @@ -255,5 +255,5 @@ pub fn maybe_setup_timer(idt: &mut Idt, cpu_id: LogicalCpuId) { return; } idt.entries[32].set_func(aux_timer); - idt.set_reserved(32, true); + idt.set_reserved_mut(32, true); } diff --git a/src/scheme/debug.rs b/src/scheme/debug.rs index f73dc8132b..b6374527ca 100644 --- a/src/scheme/debug.rs +++ b/src/scheme/debug.rs @@ -45,6 +45,9 @@ enum SpecialFds { Default = !0, NoPreserve = !0 - 1, DisableGraphicalDebug = !0 - 2, + + #[cfg(feature = "profiling")] + CtlProfiling = !0 - 3, } impl KernelScheme for DebugScheme { @@ -70,6 +73,9 @@ impl KernelScheme for DebugScheme { path[10..].parse().map_err(|_| Error::new(ENOENT))? } + #[cfg(feature = "profiling")] + "ctl-profiling" => SpecialFds::CtlProfiling as usize, + _ => return Err(Error::new(ENOENT)), }; @@ -97,7 +103,6 @@ impl KernelScheme for DebugScheme { Ok(()) } - /// Close the file `number` fn close(&self, id: usize) -> Result<()> { let _handle = { let mut handles = HANDLES.write(); @@ -113,9 +118,14 @@ impl KernelScheme for DebugScheme { }; if handle.num == SpecialFds::NoPreserve as usize - && handle.num == SpecialFds::DisableGraphicalDebug as usize + || handle.num == SpecialFds::DisableGraphicalDebug as usize { - return Err(Error::new(EINVAL)); + return Err(Error::new(EBADF)); + } + + #[cfg(feature = "profiling")] + if handle.num == SpecialFds::CtlProfiling as usize { + return Err(Error::new(EBADF)); } #[cfg(feature = "profiling")] @@ -140,6 +150,23 @@ impl KernelScheme for DebugScheme { let handles = HANDLES.read(); *handles.get(&id).ok_or(Error::new(EBADF))? }; + + #[cfg(feature = "profiling")] + if handle.num == SpecialFds::CtlProfiling as usize { + let mut dst = [0]; + buf.copy_to_slice(&mut dst)?; + + let is_profiling = match dst[0] { + b'0' => false, + b'1' => true, + _ => return Err(Error::new(EINVAL)), + }; + log::info!("Wrote {is_profiling} to IS_PROFILING"); + crate::profiling::IS_PROFILING.store(is_profiling, Ordering::Relaxed); + + return Ok(1); + } + if handle.num != SpecialFds::Default as usize && handle.num != SpecialFds::NoPreserve as usize {