Performance considerations when using Simulink Desktop Real-Time (SLDRT)

6 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 28 May 2020
Edited: MathWorks Support Team on 28 May 2020
Performance of SLDRT Normal Mode simulation:
SLDRT Normal Mode is good for not-so-fast systems, with sample rates up to a couple of hundred Hz, for simple or moderately complex models. The lower the sample rate, the more complex the model can be (this is a general rule)..
However, in SLDRT Normal mode, there is no guarantee of real-time (only a detection if real-time constrains are met or not). There is no real-time executable and only the I/O is done by the real-time kernel. So, on each sample hit, I/O is performed. The rest of the algorithm runs in Simulink and Simulink tries to synchronize to the real-time I/O. If Simulink makes it in time, there is no missed tick. If Simulink is late, it is indicated by the number of missed ticks Simulink lags behind.
Performance of External Mode real-time simulation:
SLDRT External Mode is usable to up to 10 or 20 kHz of sample rate (highly depending on model complexity and number and type of I/O). Nothing but the highest-priority catastrophic interrupt (such as memory parity error or other hardware failure) can interrupt a running real-time executable on the core it is running on. "Regular" system interrupts are handled by the other cores in the system and do not interfere with the real-time executable.
Compared to SLDRT Normal Mode, the advantage of External Mode is a guarantee of real-time, and quite a good performance.
How are Windows interrupts handled in External mode?
Interrupts are not disabled even for the core the real-time kernel runs on. However, it is true that the real-time executable (in External mode) runs on one selected core. But the highest priority of execution does not mean that the real-time executable gets 100% of the core. It means that whenever there is a sample hit, anything running on that core is interrupted and a single step of the real-time executable gets executed instead. Because this runs on very high priority, it is not being interrupted by anything else. When the executable finishes its time step, control is given back to whatever was running before. Because total execution time of the single time step of the executable must be less than the sample period, there is always some time left for other processes running on the same core, although this may be just a small fraction of the total processing time.
What happens to MATLAB overhead tasks in External mode?
Typically, all the other processes including MATLAB are running on other cores on multicore computers which are standard nowadays. In the rare case of a single-core machine, there is still some time left for processing of other tasks as per the above, but performance would suffer badly and using a single-core machine is highly discouraged.
Important performance considerations when using SLDRT:
- Approximate complexity of the model (a few blocks vs. thousands of blocks)
- Model sample rate
- Numbers and types of I/O (analog, digital, communication, other, ...)
- Other products used (especially look for Simscape)
It is not all about the computing power (i.e. interrupt latency and real-time behavior), there are other factors as well.
Use Simulink Real-Time (SLRT) for best real-time performance
SLRT is a two-machine solution with a host computer (Simulink) and a dedicated target computer (Speedgoat machine with real-time OS). It has generally wider I/O capabilities (but there are exceptions) and best performance. The downside is the much higher cost, more complex setup and the need of an additional hardware device (but this may be perceived as an advantage by some). See the following MATLAB Answers post for more information about the differences between SLRT and SLDRT:

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!