Fix profiling && + toggle support via debug scheme.

This commit is contained in:
4lDO2
2024-10-07 10:15:35 +02:00
parent dc1ba28f91
commit 8d4ee26ff1
3 changed files with 34 additions and 6 deletions
+1
View File
@@ -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)]
+3 -3
View File
@@ -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<RingBuffer> = AtomicPtr::new(core::ptr::null_mut());
pub static BUFS: [AtomicPtr<RingBuffer>; 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);
}
+30 -3
View File
@@ -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
{