![]() |
SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Monotonic scheduling strategy: Rate-Monotonic (RM) or Deadline-Monotonic (DM), selected at compile time by the TStrategyType template parameter. More...
#include <stk_strategy_monotonic.h>
Public Types | |
| enum | EConfig { WEIGHT_API = 0 , SLEEP_EVENT_API = 0 , DEADLINE_MISSED_API = 0 , PRIORITY_INHERITANCE_API = 0 } |
| Compile-time capability flags reported to the kernel. More... | |
Public Member Functions | |
| SwitchStrategyMonotonic () | |
| Construct an empty strategy with no tasks. | |
| STK_VIRT_DTOR | ~SwitchStrategyMonotonic ()=default |
| Destructor. | |
| void | AddTask (IKernelTask *task) override |
| Add a task to the priority-sorted runnable list. | |
| void | RemoveTask (IKernelTask *task) override |
| Remove a task from the list. | |
| IKernelTask * | GetNext () override |
| Select and return the highest-priority non-sleeping task. | |
| IKernelTask * | GetFirst () override |
| Get the first task in the managed set (used by the kernel for initial scheduling). | |
| size_t | GetSize () const override |
| Get the total number of tasks managed by this strategy. | |
| void | OnTaskSleep (IKernelTask *) override |
| Not supported, asserts unconditionally. | |
| void | OnTaskWake (IKernelTask *) override |
| Not supported, asserts unconditionally. | |
| virtual bool | OnTaskDeadlineMissed (IKernelTask *task) |
| Notification that a task has exceeded its HRT deadline; returns whether the strategy can recover without a hard fault. | |
| virtual void | OnTaskWeightChange (IKernelTask *task, Weight old_weight) |
| Notification that a runnable task's scheduling weight has changed. | |
Private Member Functions | |
| STK_NONCOPYABLE_CLASS (SwitchStrategyMonotonic) | |
Private Attributes | |
| IKernelTask::ListHeadType | m_tasks |
| All tasks (runnable and sleeping) in priority order. GetNext() skips sleeping tasks via IsSleeping(). AddTask() maintains sort order. | |
Monotonic scheduling strategy: Rate-Monotonic (RM) or Deadline-Monotonic (DM), selected at compile time by the TStrategyType template parameter.
| TStrategyType | Policy selector (EMonotonicSwitchStrategyType):
|
m_tasks is maintained as a priority-sorted intrusive list. AddTask() inserts each new task at the correct sorted position (O(n) insertion sort) so that GetNext() need only scan from the front: the first non-sleeping task it encounters is always the highest-priority runnable task. No re-sorting occurs at runtime after a task is added.m_tasks in their sorted position and are skipped by GetNext() via IKernelTask::IsSleeping(). OnTaskSleep() and OnTaskWake() assert unconditionally, the kernel must not be configured to deliver these events to this strategy.KERNEL_HRT mode; using this strategy without KERNEL_HRT produces undefined priority ordering.IKernel::AddTask(periodicity_tc, deadline_tc, ...). Definition at line 69 of file stk_strategy_monotonic.h.
| enum stk::SwitchStrategyMonotonic::EConfig |
Compile-time capability flags reported to the kernel.
| Enumerator | |
|---|---|
| WEIGHT_API | This strategy does not use per-task weights. Priority is derived from HRT timing parameters (GetHrtPeriodicity() for RM, GetHrtDeadline() for DM) at AddTask() time. |
| SLEEP_EVENT_API | This strategy does not use OnTaskSleep() / OnTaskWake() events. Sleeping tasks remain in |
| DEADLINE_MISSED_API | This strategy does not use OnTaskDeadlineMissed() events. |
| PRIORITY_INHERITANCE_API | This strategy does not require Priority Inheritance and OnTaskPriorityChange() events. |
Definition at line 75 of file stk_strategy_monotonic.h.
|
inlineexplicit |
Construct an empty strategy with no tasks.
Definition at line 85 of file stk_strategy_monotonic.h.
|
default |
Destructor.
|
inlineoverridevirtual |
Add a task to the priority-sorted runnable list.
| [in] | task | Task to add. Must not be NULL and must not already be in any list. |
m_tasks so that higher-priority tasks appear closer to the head. The sort key depends on TStrategyType: MSS_TYPE_RATE: key = GetHrtPeriodicity() (smaller -> nearer to head).MSS_TYPE_DEADLINE: key = GetHrtDeadline() (smaller -> nearer to head). Implements stk::ITaskSwitchStrategy.
Definition at line 109 of file stk_strategy_monotonic.h.
|
inlineoverridevirtual |
Get the first task in the managed set (used by the kernel for initial scheduling).
m_tasks (highest priority due to sort order). Asserts if m_tasks is empty. m_tasks there is no sleep-list fallback path, unlike RR, SWRR, EDF, and FP strategies. The returned task may be sleeping; the kernel uses it only to seed the initial context before the first GetNext() call. Implements stk::ITaskSwitchStrategy.
Definition at line 220 of file stk_strategy_monotonic.h.
|
inlineoverridevirtual |
Select and return the highest-priority non-sleeping task.
m_tasks, or NULL if every task in the list is currently sleeping (kernel will sleep until the next activation). m_tasks is sorted in descending priority order by AddTask(), a linear scan from the head is sufficient: the first task for which IsSleeping() returns false is always the highest-priority runnable task. Complexity is O(k) where k is the number of sleeping tasks at the front of the list (i.e. higher-priority tasks currently between activations). Implements stk::ITaskSwitchStrategy.
Definition at line 185 of file stk_strategy_monotonic.h.
|
inlineoverridevirtual |
Get the total number of tasks managed by this strategy.
m_tasks. Includes both runnable and sleeping tasks since this strategy does not maintain a separate sleep list. Implements stk::ITaskSwitchStrategy.
Definition at line 231 of file stk_strategy_monotonic.h.
Referenced by stk::SwitchStrategyMonotonic< MSS_TYPE_RATE >::RemoveTask().
|
inlinevirtualinherited |
Notification that a task has exceeded its HRT deadline; returns whether the strategy can recover without a hard fault.
| [in] | task | The task whose deadline was missed. Must not be nullptr. |
true — the strategy has absorbed the overrun (e.g. by escalating its scheduling mode): the kernel must not call HrtHardFailDeadline() for this tick. false — the strategy cannot recover: the kernel must call HrtHardFailDeadline() as normal. DEADLINE_MISSED_API == 1 in the concrete strategy's EConfig. Strategies that set DEADLINE_MISSED_API = 0 do not need to implement this method; the kernel will not call it and will proceed directly to HrtHardFailDeadline(). true carries no implicit side-effects on task sleep state or duration counters — normal tick-driven scheduling remains responsible for those. This call only communicates "do not hard-fault this tick." false (unrecoverable), which is the correct default for strategies that do not implement overrun recovery. Definition at line 1371 of file stk_common.h.
References STK_UNUSED.
|
inlineoverridevirtual |
Not supported, asserts unconditionally.
m_tasks in their sorted position and are detected by IsSleeping() in GetNext(). Calling this method indicates a kernel/strategy configuration mismatch. Implements stk::ITaskSwitchStrategy.
Definition at line 241 of file stk_strategy_monotonic.h.
|
inlineoverridevirtual |
Not supported, asserts unconditionally.
Implements stk::ITaskSwitchStrategy.
Definition at line 250 of file stk_strategy_monotonic.h.
|
inlinevirtualinherited |
Notification that a runnable task's scheduling weight has changed.
| [in] | task | The task whose weight was just updated via SetWeight(). |
| [in] | old_weight | The previous weight of this task (required to remove it from the priority list belonging to that weight). |
Reimplemented in stk::SwitchStrategyFixedPriority< MAX_PRIORITIES >, and stk::SwitchStrategyFixedPriority< 32 >.
Definition at line 1389 of file stk_common.h.
References STK_UNUSED.
|
inlineoverridevirtual |
Remove a task from the list.
| [in] | task | Task to remove. Must not be NULL. Must be in m_tasks (asserted). |
m_tasks, so this method simply unlinks the task unconditionally without a list-membership check. Implements stk::ITaskSwitchStrategy.
Definition at line 167 of file stk_strategy_monotonic.h.
|
private |
|
private |
All tasks (runnable and sleeping) in priority order. GetNext() skips sleeping tasks via IsSleeping(). AddTask() maintains sort order.
Definition at line 259 of file stk_strategy_monotonic.h.