main content

task execution -凯发k8网页登录

this example shows how to simulate task execution and how to generate code and run it on an soc hardware board.

application development often includes simulating an algorithm to ensure the correct behavior. such simulations usually ignore the real-time aspects of an embedded system environment. this may allow certain timing problems to remain undiscovered until the application runs on hardware.

the timing problems often lead to incorrect application behavior. soc blockset helps you detect these problems in simulation rather than on hardware. this can help you avoid costly debugging on hardware.

timing problems are more likely to occur as applications become more complex. for example, rate overruns and undesired rate preemption are more frequent in applications with multiple tasks due to resource constraints and task dependencies. simulating multitasking applications with soc blockset will help you in detecting these problems early.

in this example, task execution is simulated using soc blockset. you will learn about different techniques for simulating task duration and when to use them. you will also learn how to verify the timing specifications on hardware.

supported hardware platforms:

  • xilinx® zynq® zc706 evaluation kit

  • xilinx zynq ultrascale™ mpsoc zcu102 evaluation kit

  • zedboard™ zynq-7000 development board

  • altera® cyclone® v soc development kit

  • altera arria® 10 soc development kit

the models used in this example are set for xilinx zynq zc706 evaluation kit board. to use a different hardware board, select one of the hardware boards listed in the hardware board on the system on chip tab. do the same for the top model and the referenced model.

introduction

soc blockset simulates the execution of software tasks as they would execute on an soc processor. the simulation honors the parameters of the task, such as period, priority and processor core. soc blockset simulates task preemption, task overruns, and concurrent task execution.

the following diagram illustrates the above-mentioned task execution simulation aspects. in the first two subplots, you can observe that task1 executes every 0.1 s and, since they both share core 0, task1 preempts task2 that executes every 0.2 s. in the third subplot, you can observe that core 0 still has some idle time. the last two subplots show task3 running every 0.3 s on core 1.

to learn more about simulating task execution, see what is task execution?

the block allows you to configure execution of the tasks in your model. in the block dialog, you define how many tasks you need in your system using add and delete buttons. on the main tab of the dialog, you set the main task properties, while on the simulation tab you set the simulation task properties.

the following figure illustrates the main tab of the task manager block.

a task has a name so that it can be identified in the model and the various associated plots. port labels on the task manager block use the task names for easy identification.

a task can be of two types. an event-driven task executes when triggered by an event. an event line from an io data source block connected to the task manager block triggers the task. a timer-driven task executes with a defined period as defined in the main tab of the task manager.

you define the priority of event-driven tasks in the main tab of the task manager. timer-driven task priority is assigned automatically.

in the task manager dialog you may also set the processor core on which to execute a task so that, if your hardware board has multiple cores, you may set the tasks to execute concurrently.

the task manager block also allows you to configure how task overruns are handled. for example, you may decide to drop an instance of a task if the previous task instance has not started or completed. or, you may decide to try to catch up with the task schedule despite overruns.

to simulate real-time task effects, such as preemption and overruns, soc blockset requires you to provide the duration of each task. the duration is defined as the time elapsed between the task start and the task end. ideally, you will measure the task duration on your hardware board. if that is not possible, look up the task duration in the data sheets provided by the task algorithm developers. as a last resort, you should set the duration relative to the task period or the shortest recurrence interval for aperiodic tasks.

soc blockset has several choices for setting the task duration. as the task duration is applied only to simulation, these choices are found in the simulation tab of the task manager dialog.

the following figure illustrates the simulation tab of the task manager dialog.

the most commonly used options are:

  • dialog - allows you to specify task duration via a normal distribution, or a combination of multiple normal distributions, using the mean and the standard deviation parameters.

  • input port - allows you to specify task duration on an instance basis. for example, you may create a model that calculates task duration and connect it to the task manager input port.

the following flowchart will guide you in selecting the most appropriate option.

if the duration times for your task have different distributions and causes, select the most fitting options using the flowchart as general guidance.

you can configure additional simulation and execution parameters for soc blockset in the model configuration dialog. task profiling, in simulation and on processor, allows you to profile task execution, stream results to data inspector and save them into a file.

you can also set the kernel latency value to affect task execution in simulation. this value varies a lot but is typically much smaller than task duration. therefore, we recommend you leave the value set to 0 s unless you can deterministically find the appropriate value for your hardware board.

the following figure shows soc parameters related to task execution in the model configuration parameters dialog. note that the task profiling on processor panel shows only if you install all required products and hardware support packages.

the remaining steps of this example will illustrate some of the options shown in the above flowchart.

simulating an algorithm with single code path

this case requires you to simulate a dsp algorithm that processes a frame of data. the following product is required for that:

  • dsp system toolbox

if you do not have this product, proceed to the next case after reviewing the description of this case.

in this case, you will learn how to model the task duration when the task algorithm has a single code path.

assume that you are tasked with developing an application that processes rf (radio frequency) data on an soc board. after being preprocessed in the fpga core, the data is streamed to the processor core using the axi4 protocol. the algorithm running on the processor core should determine whether the data contains a high-frequency or a low-frequency signal. to that end, a low-pass and a high-pass filter are applied to the data. the resulting signals are then compared to a selected threshold. based on this description, this task has a single code path, with no major code branches. the source code for the task function might have the following form.

double datareadtask(double in[])
{
    /* frame size is always 1000 */
    int signaltype; /* 0 - lp, 1 - hp */
    double out1[1000], out2[1000];
    filterlp(in, out1, 1000);
    filterhp(in, out2, 1000);
    signaltype = thresholding(out1, out2, 1000);
}

1. open the . note the test data subsystem. the rf data source block in the subsystem represents the external memory and the fpga core. the rf data source block has two output ports, stream data and event. they output the rf data and a notification when new data frame is available, respectively.

2. note that the rf data source block generates frames of 1000 samples every 0.01 s. the frames are samples of a 1 khz sine waveform.

3. click the task manager block. observe that it sets an event-driven task datareadtask. the task is triggered by the arrival of a new data frame.

4. click the simulation tab in the task manager dialog to define the task duration for simulation.

since the algorithm consists of two filters executing without conditions, the application has a single code path. therefore, you follow the first left branch in the flowchart shown in the introduction and you expect that the algorithm execution times have a normal distribution.

based on the information given by the algorithm developer, you determine that the mean execution time is 0.0095 s and that the standard deviation is 0.0001 s. to represent the real-time limits, you also decide to set the min and the max execution times to 0.00925 s and 0.00975 s, respectively.

set the duration parameters in the task manager dialog in the simulation tab as described above.

5. in the model, click run to start the simulation. wait until the simulation completes.

6. from the model toolbar, open the data inspector and inspect the datareadtask. zoom in to inspect the task execution times more closely.

7. run the following command to perform the statistical analysis of the task execution times. observe the data inspector run numbers. modify the command if your run numbers are different.

  soctasktimes('soc_task_execution', 'run 1: soc_task_execution')

observe that the task durations vary. as expected, the histogram of the task duration times indicates that the algorithm has one code path. the duration values are clustered around the mean value of 0.0095 s.

8. close the model without making any changes.

simulating an algorithm with two code paths

in this case, you will learn how to model the task duration when the task algorithm has two code paths and it can be predicted which path will be taken.

assume that you are developing a video surveillance application. the task is to constantly process video data to determine if there was intrusion in the system. the algorithm calculates the amount of scene change between consecutive video data frames. if the scene change exceeds the selected threshold, such frames are recorded as they may be used as evidence of potential intrusion. thus, this algorithm has two code paths. the source code of this algorithm may be represented in the following form.

void videotask(single in[], in length, double threshold)
{
    double energy;
    energy = calcscenechange(in, length);
    if (energy > threshold)
        recordframe(in, length);
    }
}

1. open the . note the data source block that outputs the frames of video data.

2. click the model block and observe that the algorithm calculates motion energy between consecutive frames of data. if the calculated motion energy exceeds the threshold, the main algorithm is executed.

3. click the task manager block. observe that it sets a timer-driven task videotask. this task runs every 0.33333 s, which is the video frame rate.

4. click the simulation tab in task manager dialog to define the task duration for simulation.

since the algorithm has two code paths and it can be predicted which code path will be taken, follow the second left branch in the flowchart.

model task duration to depend on motion energy. depending on whether the motion energy threshold is exceeded or not, you will assign the task duration with the mean of 75% or 50% of the frame rate, respectively.

click the task duration estimation subsystem to understand how to model task duration.

5. in the model, click run to start the simulation. wait until the simulation completes.

6. from the model toolbar, open the data inspector and inspect videotask. zoom in to inspect the task execution times more closely.

7. run the following command to perform the statistical analysis of the task execution times. observe the data inspector run numbers. modify the command if your run numbers are different.

  soctasktimes('soc_task_execution_step2', 'run 2: soc_task_execution_step2')

observe that the task durations vary. as expected, the histogram of the task duration times indicates that the algorithm has two code paths.

8. close the model without making any changes.

simulating an algorithm with indeterminate number of code paths

in this case, you will learn how to model the task duration when the task algorithm has an indeterminate number of code paths, but the code paths are repeatable for the given set of data.

in this case, assume that you are developing a complex application that processes data on an soc board. due to the complexity of the processing, the algorithm has an indeterminate number of code paths. as a result, it is not possible to predict which code path will be taken. however, it is known that the distribution of task durations is repeatable in multiple experiments. the source code for such an algorithm might have the following form.

int mytask(int arr[], int length)
{
    int i = 0;
    int sum = 0;
    while (i < length) {
        if (arr[i] > 0)
            sum = sum   arr[i]
        i  ;
    }
}

1. open the .

2. click the task manager block and select the task mytask. click the simulation tab. observe that we define the probability distribution as a combination of two normal distributions.

3. click run to start the simulation. the task execution data will be streamed to the data inspector.

4. run the following command to perform the statistical analysis of the task execution times obtained in simulation. observe the data inspector run number. modify the command if your run number is different.

  soctasktimes('soc_task_execution_step3', 'run 3: soc_task_execution_step3')

notice that the task duration distribution obtained in simulation matches the expected results.

5. close this model without making any changes.

simulating an application using proxy tasks

assume that you are developing a complex application that adds one more task to the model developed in the previous case. the implementation of this task is not currently available, but the timing specification for this task is known. the task executes every 0.02 s with the duration described by a normal distribution. the distribution has a mean of 0.008 s and standard deviation of 0.0009 s.

1. open the .

2. click the task manager block and select the task proxytask. click the simulation tab. observe that we define the probability distribution as a normal distribution with the parameters mentioned in the introduction of this task.

3. inside the model block open the proxy task block and inspect the sample time value. the sample time value must match the period value entered in the task manager block. click cancel.

4. click run to start the simulation. the task execution data will be streamed to the data inspector.

5. run the following command to perform the statistical analysis of the task execution times obtained in simulation. observe the data inspector run number. modify the command if your run number is different.

  soctasktimes('soc_task_execution_step4', 'run 4: soc_task_execution_step4')

notice that the task durations obtained in simulation for both application and the proxy tasks.

6. close this model without making any changes.

compare the simulation results with the results on hardware

in this section, you will compare the timing results obtained in the previous simulation to the timing results obtained on your hardware board.

required products:

  • embedded coder

  • soc blockset support package for xilinx devices, or

  • soc blockset support package for intel devices

1. on the system on chip tab, click configure, build & deploy.

2. follow the soc builder workflow until you get to the select build action screen.

3. select build and load for external mode and continue until you complete the workflow.

4. click on monitor & tune to deploy the model to the hardware. the model is already set to profile task execution as it runs on hardware and stream the profiling data to data inspector in real-time.

5. run the following command to perform the statistical analysis of the task execution times obtained on hardware. observe the data inspector run number. modify the command if your run number is different.

  soctasktimes('soc_task_execution_step4', 'run 5: soc_task_execution_step4')

notice that the task durations obtained on hardware match the results obtained in simulation.

6. close this model without making any changes.

summary

this example showed you how to simulate task execution in a multitasking operating system, how to generate code and run it on a hardware board, and how to collect the real-time task execution data.

in this example, we used simple applications, each with one task. in a typical application, however, multiple tasks must be performed. embedded applications must run each task per defined schedule. to allow for using the processor most efficiently and to react quickly to external events, a priority-based preemptive scheduling algorithm is used.

with priority-based preemptive scheduling, when a task gets preempted, a task switch occurs. the data used by the task (task context) is saved so that it can be restored when the task resumes executing. in this example, the task switching times are dwarfed by the task duration and are not simulated. in applications with much shorter task duration, you may need to consider them.

if a hardware board has multiple processor cores, embedded applications typically attempt to use all cores for the most efficient implementation. soc blockset uses a priority-based preemptive scheduling algorithm even when the processor has multiple cores. soc blockset honors assignment of tasks per core in both simulation and generated code.

next, we recommend completing streaming data from hardware to software example that illustrates a systematic approach to designing a complex soc application using soc blockset.

网站地图