Minimizing Jitter in a Deterministic Loop
- Updated2023-02-17
- 2 minute(s) read
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.
-
Refer to the following guidelines for interacting with deterministic loops:
- Memory allocation— Pre-allocate arrays before using them in deterministic loops. Use the Replace Array Subset node to modify pre-allocated arrays within a deterministic loop. Use the Real-Time Trace Viewer to identify Wait for Memory system event flags, which indicate memory management operations.
- Opening and closing references—Open references in an initialization phase before entering a deterministic loop. Close references in a shutdown phase after the deterministic loop terminates. Opening and closing references inside a loop can add jitter in a deterministic loop.
- Communication—Use the RT FIFO nodes to communicate with a deterministic loop. RT FIFOs buffer data so that a deterministic loop can access the data without being blocked by a lower-priority loop.
- SubVIs—For best performance, use inlined subVIs in deterministic loops. Inlined subVIs decrease CPU overhead because they do not need to be called at run time. If you do not use inlined subVIs, close all subVI documents before running a VI that contains a deterministic loop.
-
Avoid placing the following items in deterministic loops:
- File I/O—Accessing the hard disk using file I/O operations can introduce unbounded jitter in a deterministic loop.
- Networking operations— Networking operations can introduce unbounded jitter in a deterministic loop.
- Variable-size data structures—Using variable-size data structures in deterministic loops leads to variation in loop execution times. Instead, pre-allocate memory before using a data structure in a deterministic loop.
- Shared resources—Accessing resources that are shared between a deterministic loop and another loop, such as hardware resources, I/O channels, or non-reentrant subVIs, may cause the deterministic loop to wait for the other loop to release the shared resource.
- Shared data—Sharing data with a deterministic loop through objects such as queues, data value references, and duplicated terminals can introduce jitter in a deterministic loop . Instead, use RT FIFO nodes to communicate with a deterministic loop.
- Algorithms with unbounded jitter—Certain algorithms are non-deterministic by nature and can introduce unbounded jitter. Do not include algorithms with unbounded jitter in a deterministic loop. If you are not sure about the jitter characteristics of a program, benchmark it.
- Controls and indicators—Placing data terminals within a deterministic loop can negatively impact performance, which introduces jitter.
Related Information
- 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.
- 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.
- 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.