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: SchedClassTableScheduler class table (pick order, steal order, class metadata)
Implementations§
Source§impl GlobalSchedState
impl GlobalSchedState
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new global scheduler state (no per-CPU runqueues : those live in LOCAL_SCHEDULERS).
Sourcepub(crate) fn member_add(
map: &mut BTreeMap<Pid, Vec<TaskId>>,
key: Pid,
task_id: TaskId,
)
pub(crate) fn member_add( map: &mut BTreeMap<Pid, Vec<TaskId>>, key: Pid, task_id: TaskId, )
Performs the member add operation.
Sourcepub(crate) fn member_remove(
map: &mut BTreeMap<Pid, Vec<TaskId>>,
key: Pid,
task_id: TaskId,
)
pub(crate) fn member_remove( map: &mut BTreeMap<Pid, Vec<TaskId>>, key: Pid, task_id: TaskId, )
Performs the member remove operation.
Sourcepub(crate) fn register_identity_locked(
identity: &mut SchedIdentity,
task: &Arc<Task>,
)
pub(crate) fn register_identity_locked( identity: &mut SchedIdentity, task: &Arc<Task>, )
Performs the register identity locked operation.
Sourcepub(crate) fn unregister_identity_locked(
identity: &mut SchedIdentity,
task_id: TaskId,
pid: Pid,
tid: Tid,
)
pub(crate) fn unregister_identity_locked( identity: &mut SchedIdentity, task_id: TaskId, pid: Pid, tid: Tid, )
Performs the unregister identity locked operation.
Sourcepub fn add_task_with_parent(
&mut self,
task: Arc<Task>,
parent: TaskId,
) -> Option<usize>
pub fn add_task_with_parent( &mut self, task: Arc<Task>, parent: TaskId, ) -> Option<usize>
Performs the add task with parent operation.
Sourcefn add_task_on_cpu(
&mut self,
task: Arc<Task>,
cpu_index: usize,
) -> Option<usize>
fn add_task_on_cpu( &mut self, task: Arc<Task>, cpu_index: usize, ) -> Option<usize>
Performs the add task on cpu operation.
pub(super) fn insert_all_task_locked( &mut self, task_id: TaskId, task: Arc<Task>, )
pub(super) fn remove_all_task_locked( &mut self, task_id: TaskId, ) -> Option<Arc<Task>>
Sourcepub fn clear_task_wake_deadline_locked(&mut self, id: TaskId) -> bool
pub fn clear_task_wake_deadline_locked(&mut self, id: TaskId) -> bool
Performs the clear task wake deadline locked operation.
Sourcepub fn set_task_wake_deadline_locked(
&mut self,
id: TaskId,
deadline: u64,
) -> bool
pub fn set_task_wake_deadline_locked( &mut self, id: TaskId, deadline: u64, ) -> bool
Sets task wake deadline locked.
Sourcepub fn wake_task_locked(&mut self, id: TaskId) -> (bool, Option<usize>)
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.
Sourcepub fn try_reap_child_locked(
&mut self,
parent: TaskId,
target: Option<TaskId>,
) -> WaitChildResult
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.
Sourcefn select_cpu_for_task(&self) -> usize
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.
Sourcepub fn migrate_ready_tasks_for_new_class_table(&mut self)
pub fn migrate_ready_tasks_for_new_class_table(&mut self)
Performs the migrate ready tasks for new class table operation.
Auto Trait Implementations§
impl !RefUnwindSafe for GlobalSchedState
impl !UnwindSafe for GlobalSchedState
impl Freeze for GlobalSchedState
impl Send for GlobalSchedState
impl Sync for GlobalSchedState
impl Unpin for GlobalSchedState
impl UnsafeUnpin for GlobalSchedState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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