Files
moss-kernel/src/process/threading/mod.rs
Matthew Leach 35efecad76 process: split Task into Task (shared) and OwnedTask (local)
This commit refactors the core process representation to decouple
"Identity/Resources" from "Execution/Scheduling". Previously, a
monolithic `Task` struct wrapped in `Arc<SpinLock<>>` caused lock
contention during hot scheduling paths and conflated shared state with
CPU-local state.

The `Task` struct has been split into:

1. `Task` (Shared): Holds process-wide resources (VM, FileTable,
Credentials). Managed via `Arc` and internal fine-grained locking.

2. `OwnedTask` (Private): Holds execution state (Context, v_runtime,
signal mask). Strictly owned by a specific CPU (via the Scheduler) and
accessed lock-free.

Key changes:

* Scheduler:
  chedState` now owns tasks via `Box<OwnedTask>`.
  - Transitions between `run_queue` and `running_task` involve strictly
    moving ownership of the Box, ensuring pointer stability.
  - The EEVDF comparison logic now explicitly handles comparisons
    between the queued candidates and the currently running task (which is
    not in the queue).

* Current Task Access:
  - `current()` now returns a `CurrentTaskGuard` which:
    1. Disables preemption (preventing context switches while holding
       the reference).
    2. Performs a runtime borrow check (panic on double-mutable borrow).
    3. Dereferences a cached Per-CPU raw pointer for O(1) access.
2026-01-01 22:54:43 +00:00

44 lines
902 B
Rust

use core::ffi::c_long;
use core::mem::size_of;
use crate::sched::current::current_task;
use libkernel::{
error::{KernelError, Result},
memory::address::TUA,
};
pub mod futex;
pub fn sys_set_tid_address(tidptr: TUA<u32>) -> Result<usize> {
let mut task = current_task();
task.child_tid_ptr = Some(tidptr);
Ok(task.tid.value() as _)
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct RobustList {
next: TUA<RobustList>,
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct RobustListHead {
list: RobustList,
futex_offset: c_long,
list_op_pending: RobustList,
}
pub async fn sys_set_robust_list(head: TUA<RobustListHead>, len: usize) -> Result<usize> {
if core::hint::unlikely(len != size_of::<RobustListHead>()) {
return Err(KernelError::InvalidValue);
}
let mut task = current_task();
task.robust_list.replace(head);
Ok(0)
}