Skip to main content

GlobalSchedState

Struct GlobalSchedState 

Source
pub struct GlobalSchedState {
    pub(crate) all_tasks: BTreeMap<TaskId, Arc<Task>>,
    pub(crate) all_tasks_scan: Vec<Arc<Task>>,
    task_cpu: BTreeMap<TaskId, usize>,
    wake_deadlines: BTreeMap<u64, Vec<TaskId>>,
    wake_deadline_of: BTreeMap<TaskId, u64>,
    zombies: BTreeMap<TaskId, (i32, Pid)>,
    class_table: SchedClassTable,
}
Expand description

Global task registry : cold path: fork, exit, all_tasks scan.

Lock order: acquire GLOBAL_SCHED_STATE before LOCAL when both are needed. Per-CPU runqueues and current-task tracking live in LOCAL_SCHEDULERS. Blocked tasks are tracked in BLOCKED_TASKS (separate lock). Identity maps (PID/TID, pgid, sid, parent/child) are in SCHED_IDENTITY (separate lock). This struct holds only data that is accessed by cold paths (fork, exit, all_tasks scan, zombie management, wake deadlines) and is protected by the GLOBAL_SCHED_STATE lock.

Fields§

§all_tasks: BTreeMap<TaskId, Arc<Task>>

All tasks in the system (for lookup by TaskId)

§all_tasks_scan: Vec<Arc<Task>>

Flat task snapshot used by IRQ-safe scans such as tick_all_timers.

Unlike BTreeMap::iter(), iterating a contiguous Vec<Arc<Task>> avoids tree-walk pointer chasing in hard-IRQ context. The authoritative storage remains all_tasks; this mirror is updated under the same scheduler lock.

§task_cpu: BTreeMap<TaskId, usize>

Map TaskId -> CPU index (for wake/resume routing)

§wake_deadlines: BTreeMap<u64, Vec<TaskId>>

Deadline -> task ids map for sleeping tasks (ordered wakeups).

§wake_deadline_of: BTreeMap<TaskId, u64>

Task -> deadline reverse index.

§zombies: BTreeMap<TaskId, (i32, Pid)>

Zombie exit statuses: child -> (exit_code, pid)

§class_table: SchedClassTable

Scheduler class table (pick order, steal order, class metadata)

Implementations§

Source§

impl GlobalSchedState

Source

pub fn new() -> Self

Create a new global scheduler state (no per-CPU runqueues : those live in LOCAL_SCHEDULERS).

Source

pub(crate) fn member_add( map: &mut BTreeMap<Pid, Vec<TaskId>>, key: Pid, task_id: TaskId, )

Performs the member add operation.

Source

pub(crate) fn member_remove( map: &mut BTreeMap<Pid, Vec<TaskId>>, key: Pid, task_id: TaskId, )

Performs the member remove operation.

Source

pub(crate) fn register_identity_locked( identity: &mut SchedIdentity, task: &Arc<Task>, )

Performs the register identity locked operation.

Source

pub(crate) fn unregister_identity_locked( identity: &mut SchedIdentity, task_id: TaskId, pid: Pid, tid: Tid, )

Performs the unregister identity locked operation.

Source

pub fn add_task(&mut self, task: Arc<Task>) -> Option<usize>

Add a task to the scheduler

Source

pub fn add_task_with_parent( &mut self, task: Arc<Task>, parent: TaskId, ) -> Option<usize>

Performs the add task with parent operation.

Source

fn add_task_on_cpu( &mut self, task: Arc<Task>, cpu_index: usize, ) -> Option<usize>

Performs the add task on cpu operation.

Source

pub(super) fn insert_all_task_locked( &mut self, task_id: TaskId, task: Arc<Task>, )

Source

pub(super) fn remove_all_task_locked( &mut self, task_id: TaskId, ) -> Option<Arc<Task>>

Source

pub fn clear_task_wake_deadline_locked(&mut self, id: TaskId) -> bool

Performs the clear task wake deadline locked operation.

Source

pub fn set_task_wake_deadline_locked( &mut self, id: TaskId, deadline: u64, ) -> bool

Sets task wake deadline locked.

Source

pub fn wake_task_locked(&mut self, id: TaskId) -> (bool, Option<usize>)

Performs the wake task locked operation.

Returns (was_woken, ipi_cpu). The caller must send a resched IPI to ipi_cpu after releasing the scheduler lock.

NOTE: blocked_tasks lives in the separate BLOCKED_TASKS lock. This method handles waking the task directly if it is already in BLOCKED_TASKS, or setting wake_pending as a fallback if the task is still transitioning to Blocked.

Source

pub fn try_reap_child_locked( &mut self, parent: TaskId, target: Option<TaskId>, ) -> WaitChildResult

Attempts to reap child locked. If target is Some(tid), only reaps that child; otherwise, reaps any child. Returns WaitChildResult indicating the outcome. Must be called with the scheduler lock held.

Source

fn select_cpu_for_task(&self) -> usize

Select the least-loaded CPU for a newly created task.

Uses blocking LOCAL_SCHEDULERS[i].lock() for each CPU while GLOBAL_SCHED_STATE is already held by the caller. This is safe because the hot-path only ever does try_lock_no_irqsave on GLOBAL_SCHED_STATE (so it cannot deadlock with us), but it may briefly stall behind a timer tick that holds a LOCAL lock. The stall is bounded by one tick period.

Source

pub fn migrate_ready_tasks_for_new_class_table(&mut self)

Performs the migrate ready tasks for new class table operation.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.