Real-Time Execution in Run in Kernel Mode
The Run in Kernel mode is the highest-performance mode of operation. In Run in Kernel mode, you use Simulink® Coder™ to link generated algorithm code to I/O driver code generated from the I/O blocks. The resulting executable runs at the kernel privilege level on a selected CPU core of the development computer.
Tip
Unlike Priority mode, Run in Kernel mode execution is scheduled to a single CPU by a built-in low-level scheduler, without any intervention by the operating system. This execution provides maximum real-time performance and minimum scheduling fluctuations. Use Run in Kernel mode for maximum real-time performance (especially for single-rate systems) and minimum jitter. Some platforms, such as macOS running on Apple Silicon, do not support Run in Kernel mode.
The executable exchanges parameter data with Simulink through a shared memory interface.
Signal acquisition — You can capture and display signals from your real-time application while it is running. Signal data is retrieved from the real-time application and displayed in the same Simulink
Scopeblocks that you used for simulating your model.Parameter tuning — You can change parameters in your Simulink block diagram and have the new parameters passed automatically to the real-time application. External mode changes parameters in your real-time application while it is running in real time.
The Run in Kernel mode executable is fully synchronized with the real-time clock. The main role of Simulink is to read and display simulation results returned from the executable.
Procedures related to real-time execution in run in kernel mode include:
Set Run in Kernel Mode or Priority Mode Code Generation Parameters
Set Run in Kernel Mode or Priority Mode (External Mode) Scope Parameters
Execute Real-Time Application in Run in Kernel Mode or Priority Mode by Using Run in Real Time
Execute Real-Time Application in Run in Kernel Mode or Priority Mode by Using Step by Step Commands
Execute Real-Time Application with S-Functions in Run in Kernel Mode or Priority Mode
Note
Use a fixed-step solver in Run in Kernel mode.
In Run in Kernel mode, the real-time application and the I/O drivers run in the kernel mode process. Using the I/O drivers to communicate with the hardware, the application stores contiguous response data in memory accessible to Simulink until a data buffer is filled. When the buffer is filled, the real-time application continues to run while Simulink transfers the data to the MATLAB® environment through Simulink external mode. Transfer of data is less critical than maintaining deterministic real-time updates at the required sample interval. After model computations are finished, data transfer runs at a lower priority while the process waits for another interrupt to trigger the next model update.
Data captured within one buffer is contiguous. When a buffer of data has been
transferred, the data is immediately plotted in a Simulink
Scope block. You can save the data directly to a MAT-file by using
data archiving in Simulink external mode.
With data archiving, you can save each buffer of data to its own MAT-file. The MAT-file names can be automatically incremented, enabling you to capture and store many data buffers. Although points within a buffer are contiguous, the time required to transfer data back to Simulink pauses data collection until the entire buffer has been transferred. This pause can result in lost sample points between data buffers.
See Also
Topics
- Set Run in Kernel Mode or Priority Mode Code Generation Parameters
- Prepare Run in Kernel Mode or Priority Mode Application
- Set Run in Kernel Mode or Priority Mode (External Mode) Scope Parameters
- Execute Real-Time Application in Run in Kernel Mode or Priority Mode by Using Run in Real Time
- Run Application from MATLAB Command Line
- Real-Time Van der Pol Simulation