Main Content

Visualize Task Scheduling in XCP External Mode Simulation

If you run an XCP-based external mode simulation with code execution profiling enabled, you can use the Simulation Data Inspector to visualize how the target hardware executes generated code.

This example shows how to configure and run the simulation and display task activity and diagnostics and CPU activity and utilization.

Model Configuration

  1.  Create and configure a model in a folder.

  2. Treat each discrete rate as a separate task.

    set_param(gcs, 'EnableMultiTasking', 'on');
  3. Enable code execution profiling.

    set_param(gcs, 'CodeExecutionProfiling', 'on');
    set_param(gcs, 'CodeProfilingInstrumentation', 'Detailed');
    set_param(gcs, 'CodeProfilingSaveOptions', 'AllData');
  4. Open the Simulation Data Inspector.

    Simulink.sdi.view;
  5. Start the simulation.

    set_param(gcs, 'SimulationCommand', 'start');

Run-Time Visualization

In the Simulation Data Inspector, the Inspect pane provides display groups. This table describes the profiling information that is available.

Display GroupInformation Available

Profiling

For each task, the variation of execution time over simulation time.

Task Activity

For each task, the variation of its state over time. A task can be in one of these states:

  • NotActive — Task has not started.

  • Running — Task is running on a processor core.

  • Preempted — Execution of task is preempted by another task that has a higher priority.

Task Diagnostics

For each task, the variation of task diagnostic values over simulation time. A task diagnostic can have one of these values:

  • OK — No scheduling issue detected.

  • Warn — Warning that the task is preempted by a task with lower priority.

  • PriorityInversion — Priority inversion detected

The software uses a rate-monotonic analysis to determine task priorities.

Task diagnostics are available only for target applications that are generated to run on:

  • Your development computer

  • Target devices that are Linux®-based.

CPU Activity

For each CPU core, the names of tasks that run on the CPU core over simulation time. At any instant, if no task is running on the CPU core, the value idle is displayed.

CPU Utilization

For each CPU core that tasks run on, normalized utilization over simulation time. Utilization values range between 0.0 and 1.0. For example, a value of 0.5 indicates that the CPU core is idle for 50% of the time.

To monitor task preemption and priority inversion:

  1. Select a subplot. Then, on the Inspect pane, from the Task Activity display group, select the myModel_step0 [0.01 0] and myModel_step1 [0.02 0] check boxes.

  2. Select the next subplot. Then, on the Inspect pane, from the Task Diagnostics display group, select the myModel_step0 [0.01 0] and myModel_step1 [0.02 0] check boxes.

  3. Using the Zoom in Time (Ctrl+Shift+T) control, view a specific time section.

To monitor CPU core activity and utilization:

  1. Select a subplot. On the Inspect pane, from the CPU Activity display group, select, for example, the Core 1, Core 2, Core 3, and Core 4 check boxes.

  2. Select the next subplot. On the Inspect pane, from the CPU Utilization display group, select, for example, the Core 1, Core 2, Core 3, and Core 4 check boxes.

  3. Using the Zoom in Time (Ctrl+Shift+T) control, view a specific time section.

Offline Visualization

After the completion of the simulation, you can use the schedule function to regenerate displays (except for task diagnostics). For this example, run:

schedule(executionProfile)

The function adds the task activity, CPU core activity, and CPU core utilization displays to the Profiling group. By default, the function produces eight subplots.

To visualize specific task scheduling and related CPU activity for specific tasks, you can use Simulink.sdi functions. For example, to observe task activity for myModel_step0 and myModel_step1 and CPU core activity and utilization for Core 4:

  1. Clear the displays and specify three subplots.

    Simulink.sdi.clearAllSubPlots;
    Simulink.sdi.setSubPlotLayout(3,1);

  2. In the Simulation Data Inspector, perform these actions:

    • Click subplot 1, and then select the Task: myModel_step0 [0.01 0] and Task: myModel_step1 [0.02 0] check boxes.

    • Click subplot 2, and then select the Core 4 check box.

    • Click subplot 3, and then select the Usage Core 4 check box.

  3. Using the Zoom in Time (Ctrl+Shift+T) control, view activity for a specific time section.

See Also

Related Topics