Skip to main content

FairClassRq

Struct FairClassRq 

Source
pub struct FairClassRq {
    entities: BTreeMap<(u64, u64), (Arc<Task>, u64)>,
    by_id: BTreeMap<u64, (u64, u64)>,
    min_vruntime: u64,
    total_weight: u64,
    runnable_count: usize,
}
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.

Fields§

§entities: BTreeMap<(u64, u64), (Arc<Task>, u64)>

Primary index: (vruntime, task_id)(Arc<Task>, weight). Ordered so pop_first() yields the task with the smallest vruntime. task_id is part of the key to ensure uniqueness when two tasks share the same vruntime.

§by_id: BTreeMap<u64, (u64, u64)>

Reverse index: task_id → primary key. Allows remove(task_id) to locate and delete the entities entry in O(log n) without scanning the primary map.

§min_vruntime: u64§total_weight: u64§runnable_count: usize

Implementations§

Source§

impl FairClassRq

Source

pub fn new() -> Self

Creates a new instance.

Source

fn period(&self) -> u64

Total scheduling period in ticks.

BASE_SLICE_TICKS * (nr_runnable + 1) : each runnable task gets at least one full BASE_SLICE_TICKS per round. +1 accounts for the currently-running task that is not counted in runnable_count.

Source

fn vtime_slice(&self) -> u64

Virtual-time slice: the vruntime budget for the current task.

Source

fn time_slice(&self, cur_weight: u64) -> u64

Wall-clock time slice scaled by cur_weight relative to total weight.

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
§

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.