Make PercpuBlock const constructable

This commit is contained in:
bjorn3
2025-09-15 19:00:03 +02:00
parent 3329a41121
commit 4884d749af
8 changed files with 62 additions and 11 deletions
+6 -1
View File
@@ -51,5 +51,10 @@ pub unsafe fn init_devicetree(fdt: &Fdt) {
}
}
#[derive(Default)]
pub struct ArchPercpuMisc;
impl ArchPercpuMisc {
pub const fn default() -> Self {
Self
}
}
+6 -1
View File
@@ -101,5 +101,10 @@ pub unsafe fn init_noncore() {
}
}
#[derive(Default)]
pub struct ArchPercpuMisc;
impl ArchPercpuMisc {
pub const fn default() -> Self {
Self
}
}
+10 -1
View File
@@ -81,9 +81,18 @@ pub unsafe fn init_ap() {
}
}
#[derive(Default)]
pub struct ArchPercpuMisc {
pub apic_id_opt: Cell<Option<local_apic::ApicId>>,
#[cfg(feature = "x86_kvm_pv")]
pub tsc_info: tsc::TscPercpu,
}
impl ArchPercpuMisc {
pub const fn default() -> Self {
Self {
apic_id_opt: Cell::new(None),
#[cfg(feature = "x86_kvm_pv")]
tsc_info: tsc::TscPercpu::default(),
}
}
}
+2 -2
View File
@@ -46,8 +46,8 @@ pub struct TscPercpu {
vcpu_page: Cell<*const PvclockVcpuTimeInfo>,
prev: Cell<u128>,
}
impl Default for TscPercpu {
fn default() -> Self {
impl TscPercpu {
pub const fn default() -> Self {
Self {
vcpu_page: Cell::new(core::ptr::null()),
prev: Cell::new(0),
+10 -1
View File
@@ -315,7 +315,6 @@ pub fn switch() -> SwitchResult {
///
/// This struct contains information such as the idle context, current context, and PIT tick counts,
/// as well as fields required for managing ptrace sessions and signals.
#[derive(Default)]
pub struct ContextSwitchPercpu {
switch_result: Cell<Option<SwitchResultInner>>,
pit_ticks: Cell<usize>,
@@ -329,6 +328,16 @@ pub struct ContextSwitchPercpu {
}
impl ContextSwitchPercpu {
pub const fn default() -> Self {
Self {
switch_result: Cell::new(None),
pit_ticks: Cell::new(0),
current_ctxt: RefCell::new(None),
idle_ctxt: RefCell::new(None),
being_sigkilled: Cell::new(false),
}
}
/// Applies a function to the current context, allowing controlled access.
///
/// # Parameters
+13
View File
@@ -44,6 +44,19 @@ pub struct CpuStats {
state: AtomicU8,
}
impl CpuStats {
pub const fn default() -> Self {
Self {
user: AtomicUsize::new(0),
nice: AtomicUsize::new(0),
kernel: AtomicUsize::new(0),
idle: AtomicUsize::new(0),
irq: AtomicUsize::new(0),
state: AtomicU8::new(0),
}
}
}
pub struct CpuStatsData {
/// Number of ticks spent on userspace contexts
pub user: usize,
+5 -4
View File
@@ -8,6 +8,7 @@ use rmm::Arch;
use syscall::PtraceFlags;
use crate::{
arch::device::ArchPercpuMisc,
context::{empty_cr3, memory::AddrSpaceWrapper, switch::ContextSwitchPercpu},
cpu_set::{LogicalCpuId, MAX_CPU_COUNT},
cpu_stats::CpuStats,
@@ -167,14 +168,14 @@ pub unsafe fn switch_arch_hook() {
}
}
impl PercpuBlock {
pub fn init(cpu_id: LogicalCpuId) -> Self {
pub const fn init(cpu_id: LogicalCpuId) -> Self {
Self {
cpu_id,
switch_internals: Default::default(),
switch_internals: ContextSwitchPercpu::default(),
current_addrsp: RefCell::new(None),
new_addrsp_tmp: Cell::new(None),
wants_tlb_shootdown: AtomicBool::new(false),
ptrace_flags: Cell::new(Default::default()),
ptrace_flags: Cell::new(PtraceFlags::empty()),
ptrace_session: RefCell::new(None),
inside_syscall: Cell::new(false),
@@ -183,7 +184,7 @@ impl PercpuBlock {
#[cfg(feature = "profiling")]
profiling: None,
misc_arch_info: Default::default(),
misc_arch_info: ArchPercpuMisc::default(),
stats: CpuStats::default(),
}
+10 -1
View File
@@ -196,12 +196,21 @@ pub struct SyscallDebugInfo {
accumulated_time: u128,
do_debug: bool,
}
#[cfg(feature = "syscall_debug")]
impl SyscallDebugInfo {
pub const fn default() -> Self {
Self {
this_switch_time: 0,
accumulated_time: 0,
do_debug: false,
}
}
#[cfg(feature = "syscall_debug")]
pub fn on_switch_from(&mut self) {
let now = crate::time::monotonic();
self.accumulated_time += now - core::mem::replace(&mut self.this_switch_time, now);
}
#[cfg(feature = "syscall_debug")]
pub fn on_switch_to(&mut self) {
self.this_switch_time = crate::time::monotonic();
}