Reference Manual For QP/C++ 8.1.6
Loading...
Searching...
No Matches
Preemptive Non-Blocking Kernel

Non-Preemptive KernelPreemptive Dual-Mode Kernel

Remarks
The concepts & definitions related to this SRS section are provided in Conceptual Model of QP/C++, Section QK Preemptive Non-Blocking Kernel.

Requirements


[SRS_QP_REQ_700]

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

  • [SRS_QP_REQ_701] QK kernel shall activate a ready Active Object only if its priority is higher than the system ceiling.
  • [SRS_QP_REQ_702] QK kernel shall activate an Active Object as soon as it meets the activation condition.
  • [SRS_QP_REQ_703] QK kernel shall resume a preempted Active Object only after all Active Objects that preempted it have completed their RTC steps.
  • [SRS_QP_REQ_704] QK kernel shall not activate any Active Object before the kernel is started.
  • [SRS_QP_REQ_710] QK kernel shall provide an idle-callback defined in QP/C++ Application.
  • [SRS_QP_REQ_720] QK kernel shall provide API to selectively lock scheduling Active Objects with priorities up to the specified scheduler-lock ceiling priority.
  • [SRS_QP_REQ_730] QK kernel shall support preemption-threshold scheduling (PTS).
  • [SAS_QP_FFI_20] Architectural view: Event-driven architecture with guaranteed maximum response time with the preemptive priority-based kernel (QK).
  • [SDS_QP_OS_INIT] Design view: Kernel initialization and start.
  • [SDS_QP_CB_START] Design view: Startup and cleanup callbacks.
  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [QK_USE_IRQ_NUM] Use IRQ handler for QK return-from-preemption in ARM Cortex-M
  • [QK_USE_IRQ_HANDLER] Use IRQ handler for QK return-from-preemption in ARM Cortex-M
  • [QP::QK] QK preemptive non-blocking kernel

[SRS_QP_REQ_701]

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

  • [SRS_QP_REQ_700] QP/C++ Framework shall provide preemptive non-blocking QK kernel as one of the built-in kernels.

Forward Traceability

  • [SAS_QP_FFI_20] Architectural view: Event-driven architecture with guaranteed maximum response time with the preemptive priority-based kernel (QK).
  • [SDS_QP_OS_SCHED] Design view: Ready set, scheduling, and scheduler lock.
  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [QP::QF::run()] Transfers control to QF to run the application
  • [QP::QK::sched_()] QK scheduler finds the highest-priority AO ready to run
  • [QP::QK::activate_()] QK activator activates the next active object. The activated AO preempts the currently executing AOs

[SRS_QP_REQ_702]

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:

  • synchronously (see synchronous preemption), within the call that made it eligible at the task level: posting or publishing an event, unlocking the scheduler, or starting an Active Object after QK has been started; and
  • asynchronously (see asynchronous preemption), upon the exit from the interrupt that made it eligible (upon the exit from the last nested kernel-aware interrupt, if interrupts nest).

An event posted in an interrupt shall not cause any activation before the interrupt exits.

Backward Traceability

  • [SRS_QP_REQ_700] QP/C++ Framework shall provide preemptive non-blocking QK kernel as one of the built-in kernels.

Forward Traceability

  • [SAS_QP_FFI_20] Architectural view: Event-driven architecture with guaranteed maximum response time with the preemptive priority-based kernel (QK).
  • [SDS_QP_OS_SCHED] Design view: Ready set, scheduling, and scheduler lock.
  • [SDS_QP_OS_ISR] Design view: Interrupt service routines.
  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TIN_QP_time] Integration test suite for Time Events.
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [QP::QK::sched_()] QK scheduler finds the highest-priority AO ready to run
  • [QP::QK::activate_()] QK activator activates the next active object. The activated AO preempts the currently executing AOs

[SRS_QP_REQ_703]

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

  • [SRS_QP_REQ_700] QP/C++ Framework shall provide preemptive non-blocking QK kernel as one of the built-in kernels.

Forward Traceability

  • [SAS_QP_FFI_20] Architectural view: Event-driven architecture with guaranteed maximum response time with the preemptive priority-based kernel (QK).
  • [SDS_QP_OS_CTXSW] Design view: Context switch.
  • [SDS_QP_QK_PORT] Design view: ARM Cortex-M port of the QK kernel.
  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [QP::QK::activate_()] QK activator activates the next active object. The activated AO preempts the currently executing AOs

[SRS_QP_REQ_704]

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

  • [SRS_QP_REQ_700] QP/C++ Framework shall provide preemptive non-blocking QK kernel as one of the built-in kernels.

Forward Traceability

  • [SDS_QP_OSAL_KSVC] Design view: Framework services implemented by the kernel.
  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [QP::QF::run()] Transfers control to QF to run the application

[SRS_QP_REQ_710]

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

  • [SRS_QP_REQ_700] QP/C++ Framework shall provide preemptive non-blocking QK kernel as one of the built-in kernels.

Forward Traceability


[SRS_QP_REQ_720]

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

  • [SRS_QP_REQ_700] QP/C++ Framework shall provide preemptive non-blocking QK kernel as one of the built-in kernels.

Forward Traceability

  • [SSM_QP_ASR_614] Resources shared among Active Objects under the QK kernel shall be protected with correctly configured priority ceilings or preemption thresholds.
  • [SRS_QP_REQ_721] QK kernel shall provide API to unlock scheduling Active Objects.
  • [SAS_QP_SCT_15] Architectural view: Static synchronization of access to shared resources in QP/C++ Framework component.
  • [SDS_QP_OS_SCHED] Design view: Ready set, scheduling, and scheduler lock.
  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TIN_QP_time] Integration test suite for Time Events.
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [QP::QK::schedLock()] QK selective scheduler lock

[SRS_QP_REQ_721]

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

  • [SRS_QP_REQ_720] QK kernel shall provide API to selectively lock scheduling Active Objects with priorities up to the specified scheduler-lock ceiling priority.

Forward Traceability

  • [SDS_QP_OS_SCHED] Design view: Ready set, scheduling, and scheduler lock.
  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TIN_QP_time] Integration test suite for Time Events.
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [QP::QK::schedUnlock()] QK selective scheduler unlock

[SRS_QP_REQ_730]

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

  • [SRS_QP_REQ_700] QP/C++ Framework shall provide preemptive non-blocking QK kernel as one of the built-in kernels.

Forward Traceability

  • [SSM_QP_ASR_614] Resources shared among Active Objects under the QK kernel shall be protected with correctly configured priority ceilings or preemption thresholds.
  • [SRS_QP_REQ_731] The preemption-threshold assigned to an Active Object shall be consistent with its unique QP/C++ priority.
  • [SAS_QP_SCT_15] Architectural view: Static synchronization of access to shared resources in QP/C++ Framework component.
  • [TUN_QP_qk] Unit test for qk: Preemptive QK kernel implementation
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [QP::QK::activate_()] QK activator activates the next active object. The activated AO preempts the currently executing AOs

[SRS_QP_REQ_731]

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:

  • Default: when no preemption-threshold is specified, the preemption-threshold is equal to the priority (thre = prio), which means no additional restriction of preemption.
  • Not below the priority: prio ≤ thre.
  • Within the range of priorities: thre ≤ QF_MAX_ACTIVE.
  • Non-decreasing with the priority: for any two started Active Objects A and B with prio(A) < prio(B), it must hold that thre(A) ≤ thre(B). In other words, an Active Object cannot have a preemption-threshold lower than any lower-priority Active Object, or higher than any higher-priority Active Object.

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

  • [SRS_QP_REQ_730] QK kernel shall support preemption-threshold scheduling (PTS).

Forward Traceability

  • [TUN_QP_qf_qact64] Unit test for qf_qact: QActive registration, priority management (64 configured AOs)
  • [TUN_QP_qf_qact32] Unit test for qf_qact: QActive registration, priority management (32 configured AOs)
  • [TUN_QP_qf_qact16] Unit test for qf_qact: QActive registration, priority management (16 configured AOs)
  • [TUN_QP_qf_qact8] Unit test for qf_qact: QActive registration, priority management (8 configured AOs)
  • [TUN_QP_qf_qmact] Unit test for qf_qmact: QMActive class implementation
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [QP::QActive::start()] Starts execution of an active object and registers the object with the framework

Non-Preemptive KernelNon-Functional Requirements