Skip to main content

FairClassRq

Struct FairClassRq 

Source
pub struct FairClassRq { /* private fields */ }
Expand description

Per-CPU run queue for the Completely Fair Scheduler.

Uses two BTreeMaps for O(log n) operations without allocation on the fast paths (pick_next, remove):

  • entities: primary map keyed by (vruntime, task_id) : the minimum entry is always the next task to schedule.
  • by_id: reverse index mapping task_id → primary key : enables O(log n) removal by task ID in remove() without scanning entities.

This replaces the previous BinaryHeap-based design which used lazy deletion (O(n) remove() scan, phantom entries, generation counters). The BTreeMap approach gives:

OperationComplexityAllocates?
enqueueO(log n)yes : 2 BTreeMap nodes (wakeup path)
pick_nextO(log n)no : removes 2 nodes
removeO(log n)no : removes 2 nodes

No phantom entries means no generation counter, no prune_stale_head(), and no per-entry liveness checks. The BTreeMap pair is the authoritative record of which tasks are currently on the run queue.

Implementations§

Source§

impl FairClassRq

Source

pub fn new() -> Self

Creates a new instance.

Trait Implementations§

Source§

impl SchedClassRq for FairClassRq

Source§

fn enqueue(&mut self, task: Arc<Task>)

Enqueues a task onto the run queue.

Clamps vruntime to min_vruntime so waking tasks do not receive an unfair head start over tasks that have been waiting. O(log n); allocates two BTreeMap nodes.

Source§

fn len(&self) -> usize

Returns the number of tasks currently on the run queue.

Source§

fn pick_next(&mut self) -> Option<Arc<Task>>

Picks the next task to run: the one with the smallest vruntime.

O(log n), allocation-free.

Source§

fn update_current( &mut self, rt: &CurrentRuntime, task: &Task, is_yield: bool, ) -> bool

Updates the vruntime of the currently-running task and decides whether it should be preempted.

Returns true if the task has exhausted its time slice or its vruntime has overtaken the leftmost task’s vruntime by more than vtime_slice.

Source§

fn remove(&mut self, task_id: TaskId) -> bool

Removes the task identified by task_id from the run queue.

Uses the by_id reverse index for O(log n) lookup, then removes both entries. Allocation-free. Returns true if the task was present.

Source§

fn is_empty(&self) -> bool

Returns whether empty.

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
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
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.