![]() |
SuperTinyKernel™ RTOS 1.06.0
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Earliest Deadline First (EDF) scheduling strategy: always selects the runnable task with the least time remaining before its deadline expires. More...
#include <stk_strategy_edf.h>
Public Types | |
| enum | EConfig { WEIGHT_API = 0 , SLEEP_EVENT_API = 1 , DEADLINE_MISSED_API = 0 } |
| Compile-time capability flags reported to the kernel. More... | |
Public Member Functions | |
| SwitchStrategyEDF () | |
| Construct an empty strategy with no tasks. | |
| ~SwitchStrategyEDF () | |
| Destructor. | |
| void | AddTask (IKernelTask *task) |
| Add task to the runnable set. | |
| void | RemoveTask (IKernelTask *task) |
| Remove task from whichever list it currently occupies. | |
| IKernelTask * | GetNext () |
| Select and return the task with the earliest (minimum) relative deadline. | |
| IKernelTask * | GetFirst () const |
| Get first task in the managed set (used by the kernel for initial scheduling). | |
| size_t | GetSize () const |
| Get total number of tasks managed by this strategy. | |
| void | OnTaskSleep (IKernelTask *task) |
| Notification that a task has entered the sleeping state. | |
| void | OnTaskWake (IKernelTask *task) |
| Notification that a task has become runnable again. | |
| bool | OnTaskDeadlineMissed (IKernelTask *) |
| Not supported, asserts unconditionally. | |
Protected Member Functions | |
| STK_NONCOPYABLE_CLASS (SwitchStrategyEDF) | |
Protected Attributes | |
| IKernelTask::ListHeadType | m_tasks |
| Runnable tasks eligible for scheduling. Scanned in full by GetNext() each tick to find the minimum relative deadline. | |
| IKernelTask::ListHeadType | m_sleep |
| Sleeping (blocked) tasks not eligible for scheduling. Deadline tracking continues in the kernel while tasks are in this list. | |
Earliest Deadline First (EDF) scheduling strategy: always selects the runnable task with the least time remaining before its deadline expires.
IKernelTask::GetHrtRelativeDeadline() = deadline - duration (ticks remaining before the task must complete and call Yield()). The task with the minimum relative deadline, i.e. the one closest to missing its deadline is selected.KERNEL_HRT mode. In HRT mode the kernel tracks duration (active ticks elapsed) per task, making GetHrtRelativeDeadline() produce meaningful, monotonically decreasing values. Outside HRT mode GetHrtRelativeDeadline() returns 0 for every task, making selection order arbitrary.m_tasks wins. Insertion order therefore determines tie priority. This behaviour is implementation-defined and not guaranteed to remain stable across kernel versions.KERNEL_HRT mode, tasks do not need to override ITask::GetWeight(). Definition at line 60 of file stk_strategy_edf.h.
Compile-time capability flags reported to the kernel.
| Enumerator | |
|---|---|
| WEIGHT_API | This strategy does not use per-task weights. Deadline tracking is handled by the kernel in KERNEL_HRT mode via GetHrtRelativeDeadline(). |
| SLEEP_EVENT_API | This strategy requires OnTaskSleep() / OnTaskWake() events to move tasks between the runnable and sleeping lists. |
| DEADLINE_MISSED_API | This strategy does not use OnTaskDeadlineMissed() events. |
Definition at line 66 of file stk_strategy_edf.h.
|
inlineexplicit |
Construct an empty strategy with no tasks.
Definition at line 75 of file stk_strategy_edf.h.
References m_sleep, and m_tasks.
Referenced by STK_NONCOPYABLE_CLASS().
|
inline |
Destructor.
Definition at line 81 of file stk_strategy_edf.h.
|
inlinevirtual |
Add task to the runnable set.
| [in] | task | Task to add. Must not be NULL and must not already be in any list. |
m_tasks. Unlike RR and FP strategies, no cursor or bitmap state is updated here — all scheduling decisions are deferred to GetNext(), which scans m_tasks at selection time. Implements stk::ITaskSwitchStrategy.
Definition at line 92 of file stk_strategy_edf.h.
References stk::util::DListEntry< T, _ClosedLoop >::GetHead(), m_tasks, and STK_ASSERT.
|
inlinevirtual |
Get first task in the managed set (used by the kernel for initial scheduling).
m_tasks if any task is runnable; otherwise the first task in m_sleep. Asserts if the combined set is empty (GetSize() == 0). Implements stk::ITaskSwitchStrategy.
Definition at line 159 of file stk_strategy_edf.h.
References GetSize(), m_sleep, m_tasks, and STK_ASSERT.
|
inlinevirtual |
Select and return the task with the earliest (minimum) relative deadline.
GetHrtRelativeDeadline() is smallest, or NULL if m_tasks is empty (no runnable tasks — kernel will sleep). m_tasks is empty, return NULL immediately.earliest to the first task in m_tasks (acts as the initial minimum sentinel — avoids the need for a special INT32_MAX guard).earliest whenever a task has a strictly smaller GetHrtRelativeDeadline() value.earliest. m_tasks (i.e. added earlier) is returned. This is consistent with AddTask() insertion order. GetHrtRelativeDeadline() calls per tick. Implements stk::ITaskSwitchStrategy.
Definition at line 134 of file stk_strategy_edf.h.
References stk::IKernelTask::GetHrtRelativeDeadline(), stk::util::DListEntry< T, _ClosedLoop >::GetNext(), and m_tasks.
|
inlinevirtual |
Get total number of tasks managed by this strategy.
m_tasks (runnable) and m_sleep (sleeping). Implements stk::ITaskSwitchStrategy.
Definition at line 172 of file stk_strategy_edf.h.
References m_sleep, and m_tasks.
Referenced by GetFirst(), and RemoveTask().
|
inlinevirtual |
Not supported, asserts unconditionally.
Implements stk::ITaskSwitchStrategy.
Definition at line 214 of file stk_strategy_edf.h.
References STK_ASSERT.
|
inlinevirtual |
Notification that a task has entered the sleeping state.
| [in] | task | The task that is now sleeping. Must be in m_tasks (asserted). |
m_tasks and appends to m_sleep. No cursor or bitmap state is affected — EDF maintains no per-task cursor, so this is a simpler operation than the equivalent in RR or FP strategies. Implements stk::ITaskSwitchStrategy.
Definition at line 183 of file stk_strategy_edf.h.
References stk::util::DListEntry< T, _ClosedLoop >::GetHead(), stk::IKernelTask::IsSleeping(), m_sleep, m_tasks, and STK_ASSERT.
|
inlinevirtual |
Notification that a task has become runnable again.
| [in] | task | The task that woke up. Must be in m_sleep (asserted). |
m_sleep and appends to the back of m_tasks. No priority boost is applied (unlike SwitchStrategySmoothWeightedRoundRobin) and no bitmap is updated (unlike SwitchStrategyFixedPriority). The waking task's deadline urgency is determined naturally by GetHrtRelativeDeadline() on the next GetNext() call. Implements stk::ITaskSwitchStrategy.
Definition at line 201 of file stk_strategy_edf.h.
References stk::util::DListEntry< T, _ClosedLoop >::GetHead(), stk::IKernelTask::IsSleeping(), m_sleep, m_tasks, and STK_ASSERT.
|
inlinevirtual |
Remove task from whichever list it currently occupies.
| [in] | task | Task to remove. Must not be NULL and must belong to either m_tasks or m_sleep (asserted). |
Implements stk::ITaskSwitchStrategy.
Definition at line 106 of file stk_strategy_edf.h.
References stk::util::DListEntry< T, _ClosedLoop >::GetHead(), GetSize(), m_sleep, m_tasks, and STK_ASSERT.
|
protected |
|
protected |
Sleeping (blocked) tasks not eligible for scheduling. Deadline tracking continues in the kernel while tasks are in this list.
Definition at line 225 of file stk_strategy_edf.h.
Referenced by GetFirst(), GetSize(), OnTaskSleep(), OnTaskWake(), RemoveTask(), and SwitchStrategyEDF().
|
protected |
Runnable tasks eligible for scheduling. Scanned in full by GetNext() each tick to find the minimum relative deadline.
Definition at line 224 of file stk_strategy_edf.h.
Referenced by AddTask(), GetFirst(), GetNext(), GetSize(), OnTaskSleep(), OnTaskWake(), RemoveTask(), and SwitchStrategyEDF().