Creating a Time Budget
- Updated2023-02-17
- 2 minute(s) read
Creating a Time Budget
Minimize CPU usage and jitter in your application by creating a time budget for each task in your application. To create a time budget, you must determine the amount of time required to execute each task and set the rates of the loops accordingly.
- Determine the required period of each task in your application.
- Benchmark your application to determine the duration of each task in your application. Allow the benchmark to run for several thousand iterations and record the worst-case execution time as the duration.
-
Record the duration and period of each task in a time budget table, as shown in the following example.
Task Duration (µS) Period (µS) Control 400 1,000 Monitor 3,000 10,000 Log 16,000 30,000 -
Use the following formula to target CPU usage at well below 100%: .
By plugging the numbers from the table into this formula, you can see that the CPU usage in this example is .
-
To decrease CPU usage, you can increase the period of one or more loops while ensuring that each loop executes at the requested rate.
For example, by increasing the period of the monitoring loop to 25,000 µS and increasing the period of the logging loop to 80,000 µS, the theoretical CPU usage becomes .
Related Information
- Benchmarking in Real-Time Applications
Benchmarking is the act of measuring how long specific sections of code take to execute, often over extended periods of time, in order to evaluate the performance and determinism of the measured code.
- Minimizing CPU Usage on an RT Controller
By targeting CPU usage well below 100%, you can minimize jitter and ensure that the tasks in your application do not need to compete for CPU time. Refer to the following guidelines for minimizing CPU usage in your real-time application.
- Minimizing Jitter in a Deterministic Loop
The variation between the expected timing and the actual timing for a task is known as jitter. Minimize jitter in deterministic loops to ensure precise timing in your real-time application.
- Designing a Real-Time Application
- Designing a Real-Time Application