Main Content

Determine and Use Task Timing Information

This example shows how to choose an available method for determining timing information for the tasks on your processor. The Task Manager block uses task timing information to simulate task preemption, overruns, and parallel execution. The accuracy of task timing information provides confidence that the task simulation reflects the actual behavior on your processor.

You can use a variety of methods can be used to determine task timing information. Each method has specific hardware and software requirements and offers different degrees of timing information accuracy. This table lists these methods and their respective characteristics.

The sections in this example explain and demonstrate each method using an example system model. While this example uses the Xilinx Zynq ZedBoard™, these techniques can be used with any supported SoC Blockset™ hardware board or platform. To learn more about simulating task execution, see the What is Task Execution? topic and the Task Execution example.

open_system('soc_task_profiling');

Use Algorithm Timing Specifications

When only system requirements are available, use the worst-case execution time (WCET). The WCET should be set as a percentage of the task period (for example, 80%).

The example model has two tasks with periods 0.01s and 0.03s. Using the WCET, the average execution times should be set to:

  • 8e-03s for Task1

  • 24e-03s for Task2

This approach produces timing information of low accuracy. When you underestimate WCET, the processor resources can be used inefficiently. Similarly, when you overestimate WCET, unwanted task preemptions or overruns can occur.

Profile Algorithm Using Software-in-the-Loop (SIL)

SIL simulation compiles generated source code and then runs the code on your host computer. During simulation, execution-time metrics for the generated code get collected. SIL simulation provides low to medium accuracy timing information, as the host computer generally has different architecture than your processor. This approach can be useful, especially, for comparative analysis. For more information on SIL, see Configure and Run SIL Simulation (Embedded Coder).

These steps show how to use SIL profiling to determine task information for the example model.

1. Right-click the Model block, click Model Parameters (ModelReference), and select Software-in-the-loop (SIL) in the Simulation mode drop-down. Click OK.

2. On the Simulation tab, click Run to run the SIL simulation. When the simulation completes, click the Model block to get the execution-time metrics. This figure shows the execution-time metrics report.

3. The average execution times for Task1 and Task2, which correspond to the rates of these tasks are:

  • 0.30e-03s for Task1

  • 0.25e-03s for Task2

4. Use this task timing information in the Task Manager block to set the task duration mean. You can use other task timing information to set the other task timing parameters in the Task Manager block.

Profile Algorithm Using Processor-in-the-Loop (PIL)

PIL simulation compiles generated source code and then runs the code on your target hardware. During simulation, execution-time metrics for the generated code get collected. PIL simulation provides medium to high accuracy timing information, as it profiles the task algorithm on your processor. With this approach, the timing of a single task is accurate but does not account for subtle effects such as sharing cache memory. For more information on PIL, see Configure and Run PIL Simulation (Embedded Coder).

These steps show how to use PIL profiling to determine task information for this example model.

1. Right-click the Model block, click Model Parameters (ModelReference), and select Processor-in-the-loop (PIL) in the Simulation mode drop-down. Click OK.

2. On the System on Chip tab, click Hardware Settings. Expand the Target hardware resources parameter panel and in the Board Parameters group set Device Address, Username and Password.

3. On the Simulation tab, click Run to run the PIL simulation. When the simulation completes, click the Model block to get the execution-time metrics. This figure shows the execution-time metrics report.

4. The average execution times for Task1 and Task2, which correspond to the rates of these tasks are:

  • 1.93e-03s for Task1

  • 1.69e-03s for Task2

5. Use this task timing information in the Task Manager block to set the task duration mean. You can use other task timing information to set the other task timing parameters in the Task Manager block.

Profile Task Execution on Hardware

SoC Blockset profiling provides the timing information of every task in your model, and captures other related events such as preemptions, overruns, and task drops. Profiling the whole application on hardware provides the most accurate processor task timing information.

These steps show how to use SoC Blockset profiling to determine task information for the example model.

1. Right-click the Model block, click Model Parameters (ModelReference), and select Normal in the Simulation mode drop-down. Click OK.

2. On the System on Chip tab, click Configure, Build & Deploy. Follow the steps provided to prepare the model to build and load for external mode, and click Monitor & Tune. When the external mode completes, run these commands in MATLAB to get the execution times for Task1 and Task2:

exectime = socTaskTimes('soc_task_profiling','Run 1: soc_task_profiling')
exectime.Mean

The execution times for Task1 and Task2 are:

  • 2.00e-03s for Task1

  • 1.80e-03s for Task2

3. The socTaskTimes function also shows the distribution of execution times for each task as shown in these figures.

4. Use this task timing information in the Task Manager block to set the task duration mean. You can use other task timing information to set the other task timing parameters in the Task Manager block.