10#ifndef STK_STRATEGY_PTHRESHOLD_H_
11#define STK_STRATEGY_PTHRESHOLD_H_
82template <u
int8_t MAX_PRIORITIES,
bool TIMESLICE = false>
105 return static_cast<Weight>((
static_cast<Weight>(priority) << 8) |
static_cast<Weight>(threshold));
114 return MakeWeight(
static_cast<uint8_t
>((MAX_PRIORITIES - 1U) - tx_priority),
115 static_cast<uint8_t
>((MAX_PRIORITIES - 1U) - tx_threshold));
143 const bool is_tail = (
m_prev[prio] ==
m_tasks[prio].GetLast());
151 if (is_tail && !TIMESLICE)
219 next = (*
m_prev[hi]->GetNext());
250 first_task = (*
m_sleep.GetFirst());
264 size_t total =
m_sleep.GetSize();
265 for (
Priority i = 0U; i < MAX_PRIORITIES; ++i)
317 if (old_prio == new_prio)
324 const bool was_held = (
m_held[old_prio] == task);
358 bool handled =
false;
361 if ((prio < MAX_PRIORITIES) && (task->
GetHead() == &
m_tasks[prio]))
392 bool rotated =
false;
403 (
m_tasks[prio].GetSize() > 1U))
430 STK_ASSERT((threshold >= priority) && (threshold < MAX_PRIORITIES));
480 else if (
m_prev[prio] == task)
508 else if (
m_held[prio] == task)
521 return static_cast<Priority>((
static_cast<uint32_t
>(weight) >> 8) & 0xFFU);
531 return static_cast<Priority>(
static_cast<uint32_t
>(weight) & 0xFFU);
548 return (thr > prio ? thr : prio);
Contains interface definitions of the library.
#define __stk_forceinline
Forces compiler to always inline the decorated function, regardless of optimisation level.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
#define __stk_constexpr_cpp17
constexpr definition for C++17 and above.
#define STK_STATIC_ASSERT_DESC(X, DESC)
Compile-time assertion with a custom error description. Produces a compilation error if X is false.
#define STK_VIRT_DTOR
Makes destructors virtual and compliant to strict rules if STK_STRICT_COMPLIANCY=0.
Namespace of STK package.
static uint32_t CountLeadingZeros(const uint32_t value) noexcept
Count leading zeros.
SwitchStrategyPreemptionThreshold< 32 > SwitchStrategyPT32
SwitchStrategyPreemptionThreshold with 32 priority levels.
SwitchStrategyPreemptionThreshold< 32, true > SwitchStrategyPT32_TS
SwitchStrategyPreemptionThreshold with 32 priority levels and per-task time-slicing,...
Word TId
Task (thread) id.
int32_t Weight
Weight value (aka priority).
Scheduling-strategy-facing interface for a kernel task slot.
virtual Weight GetWeight() const =0
Get static base weight assigned to the task.
virtual Weight GetBaseWeight() const =0
Get the base (configured) weight of the task, ignoring any priority-inheritance boost.
DLHeadType ListHeadType
List head type for IKernelTask elements.
virtual bool IsSleeping() const =0
Check whether the task is currently sleeping.
Interface for a task switching strategy implementation.
Interface for the kernel services exposed to the user processes during run-time when Kernel started s...
virtual Weight SetWeight(TId tid, Weight weight)=0
Change the base weight of the task at run-time (replaces ITask::GetWeight() value).
DLEntryType * GetNext()
Get the next entry in the list.
DLHeadType * GetHead()
Get the list head this entry currently belongs to.
DLEntryType * GetPrev()
Get the previous entry in the list.
Fixed-priority scheduling with Preemption-Threshold (PTS), modelled on Azure RTOS / ThreadX....
bool OnTaskTimeSlice(IKernelTask *task) override
Time slice of the running task expired: rotate to the next task of the same priority.
void AddTask(IKernelTask *task) override
Add task to the runnable set at its priority level.
SwitchStrategyPreemptionThreshold()
Construct an empty strategy.
static __stk_forceinline Priority GetHighestReadyPriority(uint32_t bitmap)
static __stk_forceinline Priority GetTaskThreshold(IKernelTask *task)
IKernelTask * m_prev[MAX_PRIORITIES]
static __stk_forceinline Priority GetTaskPriority(IKernelTask *task)
static __stk_forceinline Priority GetRawThreshold(IKernelTask *task)
Configured threshold from the task's base weight (unaffected by priority inheritance).
void UpdateHold(IKernelTask *task, const Priority prio)
Apply a threshold change to a runnable task that stays on the same level.
static uint8_t ChangeThreshold(IKernelService &service, TId tid, uint8_t priority, uint8_t threshold)
Change the preemption-threshold of a task at run-time (tx_thread_preemption_change).
static constexpr Weight FromThreadX(uint8_t tx_priority, uint8_t tx_threshold)
Build a task weight from ThreadX numbers (0 = highest priority).
void OnTaskWake(IKernelTask *task) override
Task became runnable again; re-enters its priority level (not held).
size_t GetSize() const override
Total number of tasks (runnable + sleeping).
void OnTaskSleep(IKernelTask *task) override
Task went to sleep: leaves the runnable set and releases its hold.
void RemoveActive(IKernelTask *task, const Priority prio)
EConfig
Compile-time capability flags reported to the kernel.
@ PRIORITY_INHERITANCE_API
IKernelTask * GetNext() override
Select the next task to run.
static __stk_forceinline Priority DecodePriority(Weight weight)
void RemoveTask(IKernelTask *task) override
Remove task from whichever list it occupies (drops its hold if any).
IKernelTask::ListHeadType m_sleep
IKernelTask * GetFirst() override
First task in the managed set (highest ready level, else first sleeping).
static __stk_forceinline Priority DecodeThreshold(Weight weight)
STK_NONCOPYABLE_CLASS(SwitchStrategyPreemptionThreshold)
static constexpr Weight MakeWeight(uint8_t priority, uint8_t threshold)
Build a task weight from an STK priority and threshold.
IKernelTask::ListHeadType m_tasks[MAX_PRIORITIES]
void AddActive(IKernelTask *task)
IKernelTask * m_held[MAX_PRIORITIES]
bool OnTaskYield(IKernelTask *task) override
Yield: hand the CPU to the next task of the same priority.
uint32_t m_advance_bitmap
STK_VIRT_DTOR ~SwitchStrategyPreemptionThreshold()=default
Destructor.
void OnTaskWeightChange(IKernelTask *task, Weight old_weight) override
Task weight changed (priority inheritance / restore): move to the new level.