Reference Manual For QP/C 8.1.6
Loading...
Searching...
No Matches
Event Delivery Mechanisms

State MachinesEvent Memory Management

Remarks
The concepts & definitions related to this SRS section are provided in Conceptual Model of QP/C, Section Event Delivery Mechanisms.

Requirements


[SRS_QP_REQ_300]

QP/C Framework shall provide direct event posting to Active Object instances based on the FIFO policy.

Description

The direct event posting mechanism shall post events to the event queue of the recipient Active Object utilizing the FIFO (First-In-First-Out) policy. Direct event posting with the default FIFO policy shall be available to all possible event producers, such as Active Objects, but also interrupts (ISRs), "device drivers", and "naked" threads of an RTOS (if an RTOS is used to run QP/C).

Backward Traceability

  • [SRS_QP_REQ_020] Active Object abstraction shall provide an event queue for each Active Object instance
  • [SRS_QP_REQ_021] Active Object event queue shall provide FIFO policy for posting events from outside the Active Object

Forward Traceability

  • [SRS_QP_REQ_310] QP/C Framework shall provide event delivery guarantee for the direct event posting mechanism.
  • [SRS_QP_REQ_331] QP/C Framework may provide alternative best-effort event posting mechanism without event delivery guarantee
  • [SAS_QP_IFC_01B] Architectural view: QP/C Framework component API.
  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).
  • [TIN_QP_ao] Integration test suite for Active Objects and direct event posting.
  • [QActive::QActive_post_()] Posts an event e directly to the event queue of the active object using the First-In-First-Out (FIFO) policy
  • [QACTIVE_POST()] Invoke the direct event posting facility QActive_post_()

[SRS_QP_REQ_301]

QP/C Framework shall provide direct event self-posting to Active Object instances based on the LIFO policy

Description

Self-posting means that a given Active Object instance posts an event to its event queue. Such a self-posting mechanism shall use the same event queue as the default FIFO policy. Still, in addition to the default FIFO policy, it should also provide the LIFO (Last-In-First-Out) policy. This self-posting with the LIFO policy shall use a distinctly different API than the default direct event posting with the FIFO policy.

Use case

Self-posting of events with the LIFO policy can be useful for recalling events that the Active Object instance has deferred.

Backward Traceability

  • [SRS_QP_REQ_020] Active Object abstraction shall provide an event queue for each Active Object instance
  • [SRS_QP_REQ_022] Active Object event queue shall additionally provide LIFO policy for self-posting events from within the Active Object

Forward Traceability

  • [SAS_QP_IFC_01B] Architectural view: QP/C Framework component API.
  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).
  • [TUN_QP_qf_defer] Unit test for qf_defer: event deferral for QActive class.
  • [TIN_QP_ao] Integration test suite for Active Objects and direct event posting.
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [TIN_QP_qv] Integration test suite for the non-preemptive QV kernel.
  • [QActive::QActive_postLIFO_()] Posts an event e directly to the event queue of the active object using the Last-In-First-Out (LIFO) policy
  • [QACTIVE_POST_LIFO()] Post an event to an active object using the Last-In-First-Out (LIFO) policy

[SRS_QP_REQ_302]

QP/C Framework shall provide "raw" thread-safe event queues that are not associated with any Active Object.

Description

A "raw" event queue stores events by reference (zero-copy, see [SRS_QP_REQ_380]), with the same FIFO and LIFO posting policies as the Active Object event queues ([SRS_QP_REQ_021], [SRS_QP_REQ_022]), and with both the reliable posting (an overflow is a detected error) and the best-effort posting with a margin ([SRS_QP_REQ_331]). The event-management rules are the same as for the Active Object event queues: a mutable event stored in a raw event queue holds a reference to the event, which the QP/C Application releases after removing the event from the queue (e.g., by explicitly recycling the event, [SRS_QP_REQ_385]). The storage for the queue is provided by the QP/C Application ([SRS_QP_REQ_913]). Events can be posted to a raw event queue from Active Objects and from ISRs. A raw event queue never blocks and does not trigger any scheduling.

Use Cases

Delivering events from the Active Object level to the ISR level (see Direct Event Posting); private event queues of an Active Object, such as the queues for deferred events ([SRS_QP_REQ_080]).

Forward Traceability

  • [TUN_QP_qf_qeq8] Unit test for qf_qeq: QEQueue native thread-safe event queue (8-bit queue counters)
  • [TUN_QP_qf_qeq16] Unit test for qf_qeq: QEQueue native thread-safe event queue (16-bit queue counters)
  • [TIN_QP_ao] Integration test suite for Active Objects and direct event posting.
  • [TIN_QP_defer] Integration test suite for event deferral.
  • [QEQueue] Native QF Event Queue
  • [QEQueue::QEQueue_init()] Initialize the native QF event queue
  • [QEQueue::QEQueue_post()] Post an event to the "raw" thread-safe event queue (FIFO)
  • [QEQueue::QEQueue_postLIFO()] Post an event to the "raw" thread-safe event queue (LIFO)
  • [QEQueue::QEQueue_get()] Obtain an event from the "raw" thread-safe queue

[SRS_QP_REQ_310]

QP/C Framework shall provide event delivery guarantee for the direct event posting mechanism.

Description

The event delivery guarantee shall be implemented with the SSFs based on failure assertion programming specified in SSRS_QP_SREQ_000. QP/C Framework shall detect all conditions that could prevent a posted event from reaching the recipient Active Object (in particular, event queue overflow and event-pool depletion for mutable events). In case any such condition occurs, QP/C Framework shall relinquish control and invoke the Custom Error Handler defined in QP/C Application (see HARA_QP_SHR_03A). That way, QP/C Application does not need to check whether direct event posting was successful (because continuing execution means that it was).

Backward Traceability

  • [SRS_QP_REQ_300] QP/C Framework shall provide direct event posting to Active Object instances based on the FIFO policy.
  • [SSRS_QP_SREQ_400] QP/C Framework shall treat every condition that prevents the delivery of an event with event delivery guarantee as a fault.

Forward Traceability

  • [SDS_QP_QUEUE] Design view: Active Object event queue (native QEQueue).
  • [SDS_QP_OSAL_EQ] Design view: Active Object event queue as an OSAL element.
  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).
  • [TUN_QP_qf_qeq8] Unit test for qf_qeq: QEQueue native thread-safe event queue (8-bit queue counters)
  • [TUN_QP_qf_qeq16] Unit test for qf_qeq: QEQueue native thread-safe event queue (16-bit queue counters)
  • [QActive::QActive_post_()] Posts an event e directly to the event queue of the active object using the First-In-First-Out (FIFO) policy
  • [QF_NO_MARGIN] Special value of margin that causes asserting failure in case event allocation or event posting fails
  • [QACTIVE_POST()] Invoke the direct event posting facility QActive_post_()

[SRS_QP_REQ_320]

QP/C Framework shall provide publish-subscribe event delivery mechanism

Description

Publish-subscribe shall use direct event posting (default, reliable variant based on FIFO policy) as the underlying low-level mechanism to multicast the subscribed events.

Forward Traceability

  • [SSM_QP_ASR_502] QP/C Application must initialize the publish-subscribe correctly and adequately.
  • [SRS_QP_REQ_321] The publish-subscribe event delivery mechanism shall be configurable and optional
  • [SRS_QP_REQ_322] QP/C Framework shall allow Active Object instances to subscribe to a given event signal at run-time.
  • [SRS_QP_REQ_323] QP/C Framework shall allow Active Object instances to unsubscribe from a subscribed event signal at run-time.
  • [SRS_QP_REQ_324] QP/C Framework shall allow Active Object instances to unsubscribe from all subscribed event signals at run-time.
  • [SRS_QP_REQ_325] Event multicasting during publishing shall be completed before the processing of the published events.
  • [SAS_QP_IFC_01B] Architectural view: QP/C Framework component API.
  • [SAS_QP_RES_05] Architectural view: Subscription lists allocation policy and responsibilities.
  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery
  • [TIN_QP_ps] Integration test suite for publish-subscribe event delivery.
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [TIN_QP_qv] Integration test suite for the non-preemptive QV kernel.
  • [QActive::QActive_publish_()] Publish event to all subscribers of a given signal e->sig
  • [QACTIVE_PUBLISH()] Publish an event to all subscriber Active Objects

[SRS_QP_REQ_321]

The publish-subscribe event delivery mechanism shall be configurable and optional

Description

The QP/C Application shall initialize and configure the publish-subscribe delivery mechanism by supplying the maximum number of event signals that can be subscribed to and a memory buffer to store the subscription information. As a special case, QP/C Application might choose not to initialize publish-subscribe, in which case the feature shall be inactive and shall not cause any waste of resources (RAM).

Backward Traceability

  • [SRS_QP_REQ_320] QP/C Framework shall provide publish-subscribe event delivery mechanism

Use case

QP/C Application initializes the publish-subscribe event delivery for a given maximum number of event signals. It provides a memory buffer capable of holding that many signals for the maximum allowed number of Active Objects in the QP/C Application (see [SRS_QP_REQ_001]).

Forward Traceability

  • [SSM_QP_ASR_502] QP/C Application must initialize the publish-subscribe correctly and adequately.
  • [SAS_QP_RES_05] Architectural view: Subscription lists allocation policy and responsibilities.
  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery
  • [TIN_QP_ps] Integration test suite for publish-subscribe event delivery.
  • [QActive::QActive_psInit()] Initializes the publish-subscribe facility for the application.

[SRS_QP_REQ_322]

QP/C Framework shall allow Active Object instances to subscribe to a given event signal at run-time.

Description

QP/C Framework shall provide an API for Active Objects to subscribe to one event signal at a time. The API shall be callable multiple times by a given Active Object to subscribe to various event signals. Event subscription requires initialization of the publish-subscribe feature, and attempts to subscribe without prior initialization shall be treated as a programming error. Subscribing to a signal that is already subscribed (by the same Active Object) shall leave the subscriptions unchanged (the operation is idempotent).

Backward Traceability

  • [SRS_QP_REQ_320] QP/C Framework shall provide publish-subscribe event delivery mechanism

Forward Traceability

  • [SAS_QP_IFC_01B] Architectural view: QP/C Framework component API.
  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery
  • [TIN_QP_ps] Integration test suite for publish-subscribe event delivery.
  • [QActive::QActive_subscribe()] Subscribes for delivery of signal sig to the active object

[SRS_QP_REQ_323]

QP/C Framework shall allow Active Object instances to unsubscribe from a subscribed event signal at run-time.

Description

QP/C Framework shall provide API for Active Objects to unsubscribe one event signal at a time. The API shall be callable multiple times by a given Active Object to unsubscribe from various event signals. Event un-subscription requires initialization of the publish-subscribe feature, and attempts to unsubscribe without prior initialization shall be treated as a programming error. Unsubscribing from a signal that is not subscribed (by the same Active Object) shall leave the subscriptions unchanged (the operation is idempotent).

Backward Traceability

  • [SRS_QP_REQ_320] QP/C Framework shall provide publish-subscribe event delivery mechanism

Forward Traceability

  • [SAS_QP_IFC_01B] Architectural view: QP/C Framework component API.
  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery
  • [TIN_QP_ps] Integration test suite for publish-subscribe event delivery.
  • [QActive::QActive_unsubscribe()] Unsubscribes from the delivery of signal sig to the active object

[SRS_QP_REQ_324]

QP/C Framework shall allow Active Object instances to unsubscribe from all subscribed event signals at run-time.

Description

QP/C Framework shall provide an API for Active Objects to unsubscribe from all event signals at once. Event un-subscription requires initialization of the publish-subscribe feature, and attempts to unsubscribe without prior initialization shall be treated as a programming error.

Backward Traceability

  • [SRS_QP_REQ_320] QP/C Framework shall provide publish-subscribe event delivery mechanism

Forward Traceability

  • [SAS_QP_IFC_01B] Architectural view: QP/C Framework component API.
  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery
  • [TIN_QP_ps] Integration test suite for publish-subscribe event delivery.
  • [QActive::QActive_unsubscribeAll()] Unsubscribes from the delivery of all signals to the active object

[SRS_QP_REQ_325]

Event multicasting during publishing shall be completed before the processing of the published events.

Description

The purpose of this requirement is to prevent event publishing from creating unexpected event sequences when the QP/C Framework runs on top of a preemptive kernel. As specified in [SRS_QP_REQ_320], event multicasting (required when multiple Active Objects subscribe to a given event signal) uses the default direct event posting mechanism. However, if the priority of the event producer is lower than the priority of the recipient Active Object, direct event posting would typically lead to preemption (before multicasting completes). Such a preemption would then cause the high-priority Active Object to immediately process the published event, which might produce other events. These different events would then appear in the event queues of Active Objects before the published initially event. This would generate a confusing event sequence.

Backward Traceability

  • [SRS_QP_REQ_320] QP/C Framework shall provide publish-subscribe event delivery mechanism
  • [SSRS_QP_SREQ_402] QP/C event multicasting shall be completed before any recipient processes the published event.

Use Case

QP/C Framework can fulfill this requirement by preventing preemption during the event multicasting (only needed when QP/C Framework runs on top of a preemptive kernel). The preemption should be prevented only for the priorities of Active Objects involved in this particular multicasting. An ideal mechanism for that is selective scheduler locking based on the priority ceiling protocol. The priority ceiling shall be set to the highest priority subscriber to a given event.

Forward Traceability

  • [SDS_QP_OSAL_SCHED] Design view: Scheduler locking OSAL API.
  • [TUN_QP_qf_ps] Unit test for qf_ps: QActive publish-subscribe event delivery
  • [TIN_QP_ps] Integration test suite for publish-subscribe event delivery.
  • [TIN_QP_qk] Integration test suite for the preemptive QK kernel.
  • [QActive::QActive_publish_()] Publish event to all subscribers of a given signal e->sig

[SRS_QP_REQ_331]

QP/C Framework may provide alternative best-effort event posting mechanism without event delivery guarantee

Description

The alternative best-effort event posting mechanism without event delivery guarantee shall detect that a given event cannot be posted, but QP/C Framework should pass this information to QP/C Application instead of entering a fail-safe state. The alternative direct event posting mechanism without event delivery guarantee must use a different API than the default mechanism with delivery guarantee.

Use Case

Event posting without event delivery guarantee is useful for events that the application can afford to lose occasionally and can apply only best effort to handle.

Backward Traceability

  • [SRS_QP_REQ_300] QP/C Framework shall provide direct event posting to Active Object instances based on the FIFO policy.
  • [SSRS_QP_SREQ_401] QP/C best-effort event delivery shall not interfere with the event delivery guarantee.

Forward Traceability

  • [SRS_QP_REQ_332] The alternative unreliable event posting mechanism shall not interfere with the default reliable event posting
  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).
  • [TUN_QP_qf_qeq8] Unit test for qf_qeq: QEQueue native thread-safe event queue (8-bit queue counters)
  • [TUN_QP_qf_qeq16] Unit test for qf_qeq: QEQueue native thread-safe event queue (16-bit queue counters)
  • [TIN_QP_ao] Integration test suite for Active Objects and direct event posting.
  • [QActive::QActive_post_()] Posts an event e directly to the event queue of the active object using the First-In-First-Out (FIFO) policy
  • [QACTIVE_POST_X()] Invoke the direct event posting facility QActive_post_() without delivery guarantee

[SRS_QP_REQ_332]

The alternative unreliable event posting mechanism shall not interfere with the default reliable event posting

Description

An example of interference between the two event posting mechanisms is exhausting the queue capacity by the unreliable event posting, so that the reliable event posting fails. Consequently, the unreliable event posting mechanism should not exhaust the event queue resource completely, but rather leave a specified number of unused queue entries (a safety margin) for the reliable event delivery.

Use Case

When using the unreliable direct event posting mechanism, the QP/C Application shall specify a non-zero safety margin of the event queue to which it posts events that can be lost. The unreliable posting should fail (and convey this failure to the QP/C Application) when the safety margin is reached. That way, some space in the queue remains available to the reliable (default) event posting mechanism.

Backward Traceability

  • [SRS_QP_REQ_331] QP/C Framework may provide alternative best-effort event posting mechanism without event delivery guarantee
  • [SSRS_QP_SREQ_401] QP/C best-effort event delivery shall not interfere with the event delivery guarantee.

Forward Traceability

  • [TUN_QP_qf_actq8] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (8-bit queue counters).
  • [TUN_QP_qf_actq16] Unit test for qf_actq: QActive native event queue implementation based on QEQueue (16-bit queue counters).
  • [TIN_QP_ao] Integration test suite for Active Objects and direct event posting.

[SRS_QP_REQ_334]

Mutable event allocation shall be reliable. This requirement also means that the QP/C Application is responsible for adequately sizing all event pools.

Description

"Reliable" event allocation means that the QP/C Framework shall detect if the mutable event cannot be allocated (e.g., due to depletion of an event pool of a given block size). In case allocation fails, the QP/C Framework shall enter a fail-safe state. This reliable event allocation policy shall be the default.

Use Case

The default (reliable) event allocation policy frees the QP/C Application from checking whether event allocation was successful (because continuing execution means that it was).

Backward Traceability

  • [SRS_QP_REQ_370] QP/C Framework shall provide a method of allocating mutable events at runtime.
  • [SSRS_QP_SREQ_400] QP/C Framework shall treat every condition that prevents the delivery of an event with event delivery guarantee as a fault.

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.
  • [TUN_QP_qf_dyn_raii] Unit test for qf_dyn with QEVT_PAR_INIT: initialization of mutable events at allocation (RAII).
  • [TIN_QP_evt] Integration test suite for events and event memory management.
  • [QF::QF_newX_()] Internal QF implementation of creating new mutable (dynamic) event
  • [Q_NEW()] Allocate a mutable (dynamic) event

[SRS_QP_REQ_335]

QP/C Framework may provide alternative unreliable method of allocating mutable events.

Description

The alternative, best-effort only method of allocating mutable events must use a different API than the default reliable event allocation. QP/C Framework still shall detect that a mutable event cannot be allocated, but the framework should pass this information to the QP/C Application instead of entering a fail-safe state. The unreliable event allocation policy shall be a special case and should be used with caution.

Use Case

Unreliable event allocation is useful for events that the application can afford to lose occasionally and can apply only "best effort" to allocate and deliver.

Backward Traceability

  • [SRS_QP_REQ_370] QP/C Framework shall provide a method of allocating mutable events at runtime.
  • [SSRS_QP_SREQ_401] QP/C best-effort event delivery shall not interfere with the event delivery guarantee.

Forward Traceability

  • [SRS_QP_REQ_336] The alternative best-effort event allocation method shall not interfere with the default reliable event allocation.
  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.
  • [TUN_QP_qf_dyn_raii] Unit test for qf_dyn with QEVT_PAR_INIT: initialization of mutable events at allocation (RAII).
  • [TUN_QP_qf_mem] Unit test for qf_mem: fixed-size memory pools.
  • [TIN_QP_evt] Integration test suite for events and event memory management.
  • [QF::QF_newX_()] Internal QF implementation of creating new mutable (dynamic) event
  • [Q_NEW_X()] Non-asserting allocate a mutable (dynamic) event

[SRS_QP_REQ_336]

The alternative best-effort event allocation method shall not interfere with the default reliable event allocation.

Description

The alternative unreliable event allocation must co-exist with the default reliable event allocation. An example of interference between the two event allocation methods is exhausting queue capacity by the unreliable event posting, so that the reliable event posting fails and causes the system to enter a fail-safe state.

Backward Traceability

  • [SRS_QP_REQ_335] QP/C Framework may provide alternative unreliable method of allocating mutable events.
  • [SSRS_QP_SREQ_401] QP/C best-effort event delivery shall not interfere with the event delivery guarantee.

Forward Traceability

  • [TUN_QP_qf_dyn] Unit test for qf_dyn: QF dynamic (mutable) event management.
  • [TUN_QP_qf_mem] Unit test for qf_mem: fixed-size memory pools.
  • [TIN_QP_evt] Integration test suite for events and event memory management.

[SRS_QP_REQ_340]

All event delivery mechanisms shall be free of concurrency hazards.

Description

"Free of concurrency hazards" means free of such hazards as race conditions and data races. It also means that the QP/C Framework must ensure that the current event does not change (e.g., is not corrupted or prematurely recycled) throughout all RTC steps it is involved in (see [SRS_QP_REQ_381]).

Backward Traceability

  • [SSRS_QP_SREQ_404] QP/C Framework shall deliver every event exactly once to each intended recipient and shall detect corruption of its event-delivery bookkeeping.

Forward Traceability

  • [TIN_QP_evt] Integration test suite for events and event memory management.
  • [TIN_QP_ps] Integration test suite for publish-subscribe event delivery.

[SRS_QP_REQ_341]

All event delivery mechanism shall be deterministic.

Description

"Deterministic" means that the process of event posting or publishing has a known and constant upper bound on its execution time. In the case of event publishing, the QP/C Framework cannot meet this requirement alone because the time of event multicasting depends on the number of subscribers to a given event, so it is not constant. Therefore, the QP/C Application must be designed in such a way that the multicasting time is acceptable.

Forward Traceability

  • [STP_QP_NOTEST] Software requirements not verified, or only partly verified, by dynamic testing.

State MachinesEvent Memory Management