⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

DeadlineScheduler

Struct DeadlineScheduler 

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

The Earliest Deadline First (EDF) deadline scheduler.

Manages deadline tasks separately from CFS. Deadline tasks always have higher priority than CFS tasks. Among deadline tasks, the one with the earliest absolute deadline that still has runtime remaining is selected.

Implementations§

Source§

impl DeadlineScheduler

Source

pub const fn new() -> Self

Create a new empty deadline scheduler.

Source

pub fn task_count(&self) -> usize

Return the number of registered deadline tasks.

Source

pub fn total_utilization(&self) -> u64

Return the total utilization in permille.

Source

pub fn has_task(&self, pid: ProcessId) -> bool

Check if a task with the given PID is registered.

Source

pub fn add_task( &mut self, pid: ProcessId, runtime_ns: u64, deadline_ns: u64, period_ns: u64, now_ns: u64, ) -> Result<(), KernelError>

Add a deadline task with admission control.

Performs admission control: the new task is accepted only if total utilization (including this task) does not exceed 1000 permille (100%).

§Arguments
  • pid - Process ID
  • runtime_ns - Worst-case execution time per period (nanoseconds)
  • deadline_ns - Relative deadline (nanoseconds, must be <= period)
  • period_ns - Activation period (nanoseconds)
  • now_ns - Current time in nanoseconds since boot
§Errors

Returns KernelError if:

  • Parameters are invalid (zero values, runtime > deadline > period)
  • Admission control fails (total utilization would exceed 100%)
  • Maximum number of deadline tasks reached
  • Task already registered
Source

pub fn add_task_attr( &mut self, pid: ProcessId, attr: &SchedAttr, now_ns: u64, ) -> Result<(), KernelError>

Add a task using SchedAttr parameters.

Source

pub fn remove_task( &mut self, pid: ProcessId, ) -> Result<DeadlineEntity, KernelError>

Remove a deadline task.

Returns the removed entity, or an error if the task was not found.

Source

pub fn pick_next(&mut self) -> Option<ProcessId>

Pick the next deadline task to run.

Returns the PID of the task with the earliest absolute deadline that still has runtime remaining (not throttled). Returns None if no eligible deadline task exists.

Source

pub fn tick(&mut self, elapsed_ns: u64) -> bool

Account elapsed time against the currently running deadline task.

Decrements runtime_remaining for the currently running deadline task. If runtime is exhausted, the task is throttled until the next period.

§Arguments
  • elapsed_ns - Nanoseconds elapsed since last tick
§Returns

true if the current task was throttled (needs reschedule), false otherwise.

Source

pub fn replenish(&mut self, now_ns: u64) -> usize

Replenish runtime for tasks whose periods have expired.

Iterates all deadline tasks and resets runtime for any whose period has elapsed. Should be called periodically (e.g., on timer tick).

§Arguments
  • now_ns - Current time in nanoseconds since boot
§Returns

Number of tasks that were replenished.

Source

pub fn next_deadline_event(&self, now_ns: u64) -> Option<u64>

Compute the time (in nanoseconds) until the next deadline event.

This is the minimum of:

  • The runtime remaining for the current task (throttle point)
  • The time until the next period boundary (replenishment point)
  • The time until the earliest absolute deadline

Returns None if there are no deadline tasks. The returned value can be used to program the APIC timer for precise deadline scheduling.

Source

pub fn should_preempt_cfs(&self) -> bool

Check whether a deadline task should preempt the current CFS task.

Returns true if any non-throttled deadline task with remaining runtime exists, meaning it should preempt CFS.

Source

pub fn get_task(&self, pid: ProcessId) -> Option<&DeadlineEntity>

Get a reference to a deadline entity by PID.

Source

pub fn set_current(&mut self, pid: Option<ProcessId>)

Set the currently running deadline task PID.

Source

pub fn current(&self) -> Option<ProcessId>

Get the currently running deadline task PID.

Trait Implementations§

Source§

impl Default for DeadlineScheduler

Available on crate feature alloc only.
Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for DeadlineScheduler

§

impl RefUnwindSafe for DeadlineScheduler

§

impl Send for DeadlineScheduler

§

impl Sync for DeadlineScheduler

§

impl Unpin for DeadlineScheduler

§

impl UnwindSafe for DeadlineScheduler

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.