With finite processing resources available in a system, an execution instance of a task might not be able to complete before the start of the next task instance. This task overrun results in the start of the next instance of the task execution to be delayed. As a result, the next task must catch-up to avoid another overrun. This diagram shows a simplified execution of two tasks: a high-priority event-driven task and a low priority timer-driven task.
Due to the long execution time of the event-driven task, the first execution instance of the timer-driven task overruns into the start of the next execution instance. This overrun puts the second execution instance into catch-up mode.
When tasks overrun repeatedly, an execution backlog can develop in the application, potentially breaking the system. These sections discuss typical countermeasures to either reduce the chance of task overruns or handle situations when tasks overrun, preventing an execution backlog.
For timer-driven tasks, reduce the chance of overruns by providing the task with more execution time. Increase available execution time by decreasing the task rate, which is equivalent to increasing the time between task execution instances. This extra time provides each task execution instance a better chance of running to completion, even in the presence of other tasks. The rate of a timer-driven task can be adjusted in the Task Manager block by setting the Period parameter.
Reduction of the task execution interval cannot be guaranteed in all cases. Some of these cases include:
For event-driven tasks, multiple events can occur at the same time, depending on the priority of the event-driven task. This case forces other tasks to overrun due to lack of resources.
Real-time requirements where a task, timer or event driven, must respond to the latest event trigger signal and new data regardless of whether previous task instances completed. This case fixes the task execution interval to a value determined by the design requirements.
In these cases, distributing tasks across multiple processor cores or allowing tasks to drop can be advantageous depending on the design requirements.
Most modern embedded processors provide multiple cores where tasks can be executed. By distributing tasks across these multiple processor cores, tasks can run simultaneously without directly competing for processing resources and reducing the chance of task overruns. In SoC Blockset™, a task can be set to run on a specific processor core in the Task Manager block by setting the Core parameter to the core number. For more information on the selection, execution, and visualization of tasks on multiple cores, see Multicore Execution and Core Visualization.
In some designs, a task must execute when the task trigger signal occurs or with the latest state of the system. If a task has been triggered and a new task trigger occurs, the new instance can be removed or dropped. After dropping the execution instance of the task that overran the next execution instance starts when the event trigger signal arrives. To drop tasks when an overrun occurs, in the Task Manager block, enable the Drop task that overrun parameter.
This example shows how to configure a task in the Task Manager block to drop when a task overrun occurs during simulation.
Task Overrun Without Task Drops
This model simulates a software application running on an ARM processor. A Task Manager block schedules the execution of the Timer Driven Subsystem, inside the Software Application Model Reference block. A Random Number block simulates a data source that the timer-driven task samples.
In this model, the task duration of 0.6 seconds exceeds the task period of
0.5 seconds causing the task to overrun. Click the Run button to build and run the model. When the model finishes running, the Simulation Data Inspector (SDI) display shows the task execution timing.
Inspecting the execution timing of the tasks shows that the start of each following task instance is delayed from the expected
0.5-second interval by the overrun of the previous task.
Task Overrun With Task Drops
Using the same previously shown model, rather than overrunning the timer-driven task, the task drops so the next task instance starts at the
0.5-second interval. Open the Task Manager block dialog mask, and select Drop tasks that overrun. Run the model again. Open the SDI to view the task execution and dropped task instances.