QP/C++ Framework shall provide preemptive non-blocking QK kernel as one of the built-in kernels.
Description
QP/C++ Framework shall provide the QK kernel implementation and ports to the supported CPU/compiler combinations as one of the optional software components. QP/C++ Application can then choose the QK kernel to execute Active Objects. Such a selection is exclusive, meaning that when the QP/C++ Application selects the QK kernel, other kernels are excluded and cannot be used.
Description
QP/C++ Framework can implement the QK kernel component by reusing already existing mechanisms, such as event queues for Active Objects, event delivery mechanisms, event memory management, etc. That way, the QK kernel implementation can be quite small and consist only of the missing pieces, such as the QK scheduler and "activator".
Forward Traceability
QK kernel shall activate a ready Active Object only if its priority is higher than the system ceiling.
Description
The system ceiling is the larger of the preemption-threshold of the currently running Active Object (0 when QK executes its idle loop) and the current scheduler-lock ceiling (0 when the scheduler is not locked). A ready Active Object (i.e., with a non-empty event queue) whose priority is equal to or lower than the system ceiling shall not be activated until the system ceiling drops below its priority. Among the ready Active Objects whose priorities are higher than the system ceiling, QK shall activate the one with the highest priority.
Rationale
This is the scheduling rule of the Stack Resource Policy with fixed priorities (see Relation to the Stack Resource Policy and Similar Kernels), which allows all Active Objects to share a single stack and bounds the blocking of every Active Object.
Backward Traceability
Forward Traceability
QK kernel shall activate an Active Object as soon as it meets the activation condition.
Description
When an Active Object meets the activation condition ([SRS_QP_REQ_701]), QK shall activate it immediately:
An event posted in an interrupt shall not cause any activation before the interrupt exits.
Backward Traceability
Forward Traceability
QK kernel shall resume a preempted Active Object only after all Active Objects that preempted it have completed their RTC steps.
Description
Preemptions in QK nest on the single stack in the last-in, first-out order. A preempted Active Object shall resume its RTC step only after the preempting Active Object, and all Active Objects activated while it was preempted that meet the activation condition with respect to the preempted Active Object ([SRS_QP_REQ_701]), have completed their RTC steps. When no Active Object meets the activation condition, QK shall return to the idle loop ([SRS_QP_REQ_710]).
Backward Traceability
Forward Traceability
QK kernel shall not activate any Active Object before the kernel is started.
Description
Active Objects started before the QK kernel is started (by QF_run()) shall execute their top-most initial transitions, but shall not be activated, even if events are posted to them. Upon the start, QK shall activate the Active Objects that have become ready in the meantime ([SRS_QP_REQ_701]) before it enters the idle loop for the first time.
Backward Traceability
Forward Traceability
QK kernel shall provide an idle-callback defined in QP/C++ Application.
Description
When no Active Object meets the activation condition ([SRS_QP_REQ_701]), QK kernel shall execute the QK idle loop. This QK idle loop shall repeatedly invoke an idle-callback (a function) defined in QP/C++ Application. The idle-callback shall be invoked with interrupts enabled, and it shall be preempted by any Active Object that becomes eligible for activation ([SRS_QP_REQ_702]).
Use Case
The idle-callback can perform any processing, including putting the CPU and peripherals in a low-power sleep mode, Software Tracing data transfer to the host, or receiving test commands.
Backward Traceability
Forward Traceability
QK kernel shall provide API to selectively lock scheduling Active Objects with priorities up to the specified scheduler-lock ceiling priority.
Description
The selective scheduler locking API shall prevent activating any Active Objects whose unique priority is equal to or lower than the specified scheduler-lock ceiling priority (see [SRS_QP_REQ_701]), without affecting Active Objects of higher priority and without masking interrupts. A lock request shall only raise the scheduler-lock ceiling: a request with a ceiling equal to or lower than the current scheduler-lock ceiling shall leave it unchanged. The locking API shall return the status needed to undo the lock request ([SRS_QP_REQ_721]), which indicates whether the lock request changed the ceiling.
Use Case
The main use case for selective scheduler locking is during multicasting events to prevent unexpected and confusing event sequences (see [SRS_QP_REQ_325]).
Backward Traceability
Forward Traceability
Resources shared among Active Objects under the QK kernel shall be protected with correctly configured priority ceilings or preemption thresholds.QK kernel shall provide API to unlock scheduling Active Objects.
Description
The scheduler unlocking API shall complement the scheduler locking API (see [SRS_QP_REQ_720]). Given the status returned by the matching lock request, the scheduler unlocking API shall restore the scheduler-lock ceiling that was in effect before that request, or shall have no effect if that request did not change the ceiling. Nested lock requests shall be undone in the reverse order. Upon restoring a lower ceiling, QK shall activate the Active Objects that meet the activation condition ([SRS_QP_REQ_701], [SRS_QP_REQ_702]).
Use Case
The main use case for selective scheduler unlocking (matching the use case in [SRS_QP_REQ_720]) is ending the multicasting of events (see [SRS_QP_REQ_325]) or ending the access to a resource shared among Active Objects.
Backward Traceability
Forward Traceability
QK kernel shall support preemption-threshold scheduling (PTS).
Description
Support for preemption-threshold scheduling (PTS) means that each Active Object can be assigned a preemption-threshold (alongside its unique QP/C++ priority). The running Active Object with a given preemption-threshold shall not be preempted by Active Objects whose unique QP/C++ priorities are equal to or lower than the preemption threshold (see [SRS_QP_REQ_701]); Active Objects with priorities higher than the preemption threshold can still preempt it.
Backward Traceability
Forward Traceability
Resources shared among Active Objects under the QK kernel shall be protected with correctly configured priority ceilings or preemption thresholds.The preemption-threshold assigned to an Active Object shall be consistent with its unique QP/C++ priority.
Description
The preemption-threshold (thre) of every Active Object, given together with its unique QP/C++ priority (prio) when the Active Object is started, shall satisfy the following rules:
For example, four Active Objects with the priorities 1, 2, 3, 4 and the preemption-thresholds 2, 2, 4, 4 satisfy the rules and form two groups, {1, 2} and {3, 4}, in which the Active Objects cannot preempt each other, while the group {3, 4} can still preempt the group {1, 2}. In contrast, the preemption-thresholds 3, 2, 3, 4 violate the non-decreasing rule (priority 1 with threshold 3 below priority 2 with threshold 2), and the preemption-threshold 2 for priority 3 violates the rule "not below the priority".
Rationale
The requirement that the preemption-threshold is not lower than the priority is inherent to preemption-threshold scheduling [PTS:99]. The additional requirement of non-decreasing preemption-thresholds is a restriction of QP/C++: it makes every group of Active Objects that cannot preempt one another a contiguous range of priorities, which simplifies the configuration and its review, as well as the schedulability and stack-usage analysis of the QP/C++ Application.
Backward Traceability
Forward Traceability