Mostly use cfg!() rather than #[cfg] for controlling sys_stat

This only adds 48 bytes overhead per cpu core in the PerCpuBlock struct.
Also fixes compilation with sys_stat enabled on x86_64.
This commit is contained in:
bjorn3
2025-09-07 12:27:04 +02:00
parent 0a58e9e806
commit b5822ac118
9 changed files with 50 additions and 45 deletions
+1 -3
View File
@@ -8,13 +8,12 @@ use core::{
use spin::RwLock;
use syscall::{SigProcControl, Sigcontrol, UPPER_FDTBL_TAG};
#[cfg(feature = "sys_stat")]
use crate::cpu_stats;
use crate::{
arch::{interrupt::InterruptStack, paging::PAGE_SIZE},
common::aligned_box::AlignedBox,
context::{self, arch, file::FileDescriptor},
cpu_set::{LogicalCpuId, LogicalCpuSet},
cpu_stats,
ipi::{ipi, IpiKind, IpiTarget},
memory::{allocate_p2frame, deallocate_p2frame, Enomem, Frame, RaiiFrame},
paging::{RmmA, RmmArch},
@@ -190,7 +189,6 @@ impl Context {
#[cfg(feature = "syscall_debug")]
syscall_debug_info: crate::syscall::debug::SyscallDebugInfo::default(),
};
#[cfg(feature = "sys_stat")]
cpu_stats::add_context();
Ok(this)
}
+10 -22
View File
@@ -15,14 +15,11 @@ use syscall::PtraceFlags;
use crate::{
context::{arch, contexts, Context},
cpu_set::LogicalCpuId,
interrupt,
cpu_stats, interrupt,
percpu::PercpuBlock,
ptrace, time,
};
#[cfg(feature = "sys_stat")]
use crate::cpu_stats;
use super::ContextRef;
enum UpdateResult {
@@ -141,13 +138,10 @@ pub enum SwitchResult {
/// to an idle context.
pub fn switch() -> SwitchResult {
let percpu = PercpuBlock::current();
#[cfg(feature = "sys_stat")]
{
cpu_stats::add_context_switch();
percpu
.stats
.add_time(percpu.switch_internals.pit_ticks.get());
}
cpu_stats::add_context_switch();
percpu
.stats
.add_time(percpu.switch_internals.pit_ticks.get());
//set PIT Interrupt counter to 0, giving each process same amount of PIT ticks
percpu.switch_internals.pit_ticks.set(0);
@@ -292,13 +286,10 @@ pub fn switch() -> SwitchResult {
// need to use the `switch_finish_hook` to be able to release the locks. Newly created
// contexts will return directly to the function pointer passed to context::spawn, and not
// reach this code until the next context switch back.
#[cfg(feature = "sys_stat")]
{
if next_context.userspace {
percpu.stats.set_state(cpu_stats::CpuState::User);
} else {
percpu.stats.set_state(cpu_stats::CpuState::Kernel);
}
if next_context.userspace {
percpu.stats.set_state(cpu_stats::CpuState::User);
} else {
percpu.stats.set_state(cpu_stats::CpuState::Kernel);
}
SwitchResult::Switched
@@ -306,10 +297,7 @@ pub fn switch() -> SwitchResult {
// No target was found, unset global lock and return
arch::CONTEXT_SWITCH_LOCK.store(false, Ordering::SeqCst);
#[cfg(feature = "sys_stat")]
{
percpu.stats.set_state(cpu_stats::CpuState::Idle);
}
percpu.stats.set_state(cpu_stats::CpuState::Idle);
SwitchResult::AllContextsIdle
}