main content

simulate scheduler of a multicore control system -凯发k8网页登录

overview

this example shows how to model the task scheduling of a control application using simevents® blocks. simevents expands simulink® with the capability to model and simulate architectural components of a real-time system.

the top model includes two areas of blocks:

  • functional components includes two closed-loop systems. each has a proportional controller operating a plant.

  • architectural components includes simevents blocks modeling the tasks and scheduler of this control system.

modeling tasks and scheduler

this example models a controller as a simulink exported function model. it maps execution of a controller to a software task that an operating system periodically schedules and executes. a task can be divided into multiple segments (or subtasks). due to data dependencies, these segments must be executed in sequential order.

a task is specified with the following parameters:

  • id: unique identifier of a task.

  • period: how frequently a task is instantiated for execution.

  • priority: priority of the task (smaller value indicates higher priority).

  • list of runnable segments (functions): executables associated with each segment of the task. these executables are represented by simulink functions of an exported function model.

  • segment execution duration: time for a task segment to complete, if it is executed on a processor without interruption.

  • needs disk i/o resource for each segment: whether a segment of the task requires the use of a mutex-protected shared resource (a hard disk).

for example, block task 2 specifies a task for the second controller (block controller2). the task includes two segments, "t2_run" and "t2_write", both modeled as simulink functions in model seswccontroller2. in these segments, "t2_write" requires the use of the mutex-protected shared resource.

scheduler of the operating system is modelled with the following components:

  • task creation: block task 1 and task 2 create tasks and manage task states. a simevents entity represents an instance of a task. properties of a task (such as its priority) are modelled as entity attributes.

  • task queue: upon instantiation, a task joins a ready task queue, which is modelled by the entity queue block os task queue. to simulate a non-preemptive priority-based scheduling policy, the queue block is configured to sort tasks by the taskpriority attribute.

  • cpu: the processor of the system is modelled as an entity server block cpu. it accepts entities from the os task queue and processes the entity for a duration as specified by the task's segment execution duration parameter. at the end of this delay, the corresponding simulink function of this task segment is called, as a part of the block's service complete action.

  • lock/unlock mutex: before a task segment enters the block cpu, it must acquire the required resource at the preceding lock mutex block. after the task segment completes and exits the block cpu, the resource is released at the unlock mutex block.

  • managing task states: blocks under the mask of task 1 and task 2 manage the run-time state of tasks. upon completion of a task segment, if the task has subsequent segments to execute, the task is routed back to the os task queue. otherwise, this task instance is completed and discarded.

results and displays

the block cpu is configured with two cores. simulating the model generates the following gantt chart.

  • the higher priority task, task 2 (red bars), is scheduled to core 1 (y = 1).

  • the lower priority task, task 1 (blue bars), is scheduled to core 2 (y = 2).

  • the second segment of task 2 uses the mutex disklock. green bars indicate the usage (y = 3).

explore the model

change the following parameters and explore how task schedules and controller performance changes with re-configured architectural parameters.

  • in block cpu, configure parameter capacity to change the number of cores.

  • in blocks task 1 and task 2, configure parameters such as period and priority to change task specifications.

for example, if we change need disk i/o resource for each segment parameter of the task 1 block to [0 0 1], the t1_write segment of controller 1 must acquire mutex disklock before it can start to run. simulation generates a gantt chart that illustrates that change.

  • both tasks have segments that use mutex disklock, as indicated by green bars (y = 3).

  • the third segment of task 1 now must execute in a serial fashion with the second segment of task 2 (see y = 1), because both segments share the mutex disklock.

related examples

see also

| | | | |

related topics

网站地图