Main Content

Scheduling Tasks in SoC Application Design

This example shows how to schedule application tasks across multiple cores in an SoC Blockset model by using the Schedule Editor tool. Consider an application that has two periodic tasks:

  • The first periodic task, periodicTask1, which runs every second.

  • * The second periodic task, periodicTask2, which runs every two seconds.

The application also has two aperiodic tasks, aperiodicTask1 and aperiodicTask2, running sporadically. The model implements the application on a hardware board that has a two-core processor.

Task Management without Schedule Editor

Inspect the model and its tasks.

open_system('soc_schedule_editor_initial')

Assume that, after the initial implementation and profiling of the task execution on the hardware board, you obtain these task durations. For more information, on task profiling see Task Profiling on Processor.

period (s) duration (s)

periodicTask1 1 0.45

periodicTask2 2 2.05

aperiodicTask1 N/A 0.35

aperiodicTask2 N/A 0.15

The second periodic task takes too long to execute and starves the computational resources on the processor, which necessitate an alternative implementation.

The second periodic task contains two independent data paths. Therefore, this task can be split into two periodic tasks, each running every two seconds: periodicTask2a and periodicTask2b. Profiling the tasks again produces updated task durations.

period (s) duration (s)

periodicTask1 1 0.45

periodicTask2a 2 0.50

periodicTask2b 2 1.55

aperiodicTask1 N/A 0.35

aperiodicTask2 N/A 0.15

Assigning periodicTask2a and periodicTask2b to two different cores produces a schedulable implementation. By default, you cannot create more than one task for each discrete rate in a Simulink® model. To create periodicTask2a and periodicTask2b in Simulink, use the Schedule Editor tool.

Task Management with Schedule Editor

The Schedule Editor creates task partitions that can be periodic or aperiodic. Unlike the default Simulink rate grouping, multiple task partitions can share the same rate. You can now create the two subtasks of the second task and set them to run on separate cores.

Creating Schedule Editor Task Partitions

Convert all rates to task partitions. To create a partition, create a Simulink atomic subsystem and give it a partition name. For a periodic task, create a periodic partition and set its period. Similarly, for an aperiodic task, create an aperiodic partition. The model has two periodic partitions with a period of 2 and two aperiodic partitions.

open_system('soc_schedule_editor')

Open the Schedule Editor and review the default execution order of the partitions.

soc_schedule_editor_periodic.png

Connect Task Partitions to Task Manager Block

Connect a Model block that contains the algorithm model to the Task Manager block in a new top model. Rate ports on the Model block represent the partitions in the reference model and must connect to the Task Manager block. Each partition must be matched to the corresponding task.

Click the Task Manager block. Configure the Task Manager block to use the execution order from Schedule Editor by checking Use Schedule Editor Ordering. The Task Manager block specifies the task core affinity. Configure periodicTask2a and periodicTask2b to run on different cores and the asynchronous tasks to run on the same core as periodicTask3 by setting the Core property.

period (s) duration (s) core

periodicTask1 1 0.45 0

periodicTask2a 2 0.50 0

periodicTask2b 2 1.55 1

aperiodicTask1 N/A 0.20 1

aperiodicTask2 N/A 0.05 1

Simulate the model and analyze the task profiling results in the Simulation Data Inspector. The two subtasks of the second periodic task run every two seconds in parllel and no tasks overrun.

soc_schedule_editor_periodic_profile.png

Controlling Priority of Aperiodic Tasks

In the task profiling results, aperiodicTask1 runs first and aperiodicTask2 runs second.

soc_schedule_editor_aperiodic_order1_profile.png

The Event Source2 block triggers aperiodicTask2, creating a trigger at 5.7 s, as set by the timeseries object ts2. Since aperiodicTask1 has higher priority, the model does not preempt this task.

You can change the priority of the aperiodic partitions by changing their execution order in the Schedule Editor. Open the Schedule Editor in the reference model and drag aperiodicTask2 above aperiodicTask1.

soc_schedule_editor_aperiodic.png

Run the simulation again. In this case, aperiodicTask2 preempts aperiodicTask1 as soon as the trigger for aperiodicTask2 occurs.

soc_schedule_editor_aperiodic_order2_profile.png

Further Exploration

  • Run the model on a supported hardware board in external mode. Confirm that the timer-driven task specifications match those set in the Schedule Editor.

  • Replace the Event Source blocks with I/O peripheral blocks, such as UDP Read, for your hardware board. Verify the behavior of the event-driven tasks.