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
impl DeadlineScheduler
Sourcepub fn task_count(&self) -> usize
pub fn task_count(&self) -> usize
Return the number of registered deadline tasks.
Sourcepub fn total_utilization(&self) -> u64
pub fn total_utilization(&self) -> u64
Return the total utilization in permille.
Sourcepub fn has_task(&self, pid: ProcessId) -> bool
pub fn has_task(&self, pid: ProcessId) -> bool
Check if a task with the given PID is registered.
Sourcepub fn add_task(
&mut self,
pid: ProcessId,
runtime_ns: u64,
deadline_ns: u64,
period_ns: u64,
now_ns: u64,
) -> Result<(), KernelError>
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 IDruntime_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
Sourcepub fn add_task_attr(
&mut self,
pid: ProcessId,
attr: &SchedAttr,
now_ns: u64,
) -> Result<(), KernelError>
pub fn add_task_attr( &mut self, pid: ProcessId, attr: &SchedAttr, now_ns: u64, ) -> Result<(), KernelError>
Add a task using SchedAttr parameters.
Sourcepub fn remove_task(
&mut self,
pid: ProcessId,
) -> Result<DeadlineEntity, KernelError>
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.
Sourcepub fn pick_next(&mut self) -> Option<ProcessId>
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.
Sourcepub fn tick(&mut self, elapsed_ns: u64) -> bool
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.
Sourcepub fn next_deadline_event(&self, now_ns: u64) -> Option<u64>
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.
Sourcepub fn should_preempt_cfs(&self) -> bool
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.
Sourcepub fn get_task(&self, pid: ProcessId) -> Option<&DeadlineEntity>
pub fn get_task(&self, pid: ProcessId) -> Option<&DeadlineEntity>
Get a reference to a deadline entity by PID.
Sourcepub fn set_current(&mut self, pid: Option<ProcessId>)
pub fn set_current(&mut self, pid: Option<ProcessId>)
Set the currently running deadline task PID.