XHP Mode, Multi-rate & Multi-Tasking
What is the link between XHP mode, Multi-rate and Multi-Tasking?
Multi-rate + XHP in Single-Tasking mode of Simulink: Supported
Multi-rate + XHP in Multi-Tasking mode of Simulink: NOT Supported
In Simulink, under Simulation/Configuration Parameters there is the option "Tasking mode for periodic sample times" which allows the user to choose between "Single-Tasking" and "Multi-Tasking". We usually leave it to default value which is "Auto". The difference between those 2 modes are:
In Single-Tasking, the Simulink model is computed as a single thread. In a model that contains an algorithm running at Ts and another algorithm running at 10*Ts (therefore called multi-rate), it is possible to see that the computation time will be larger at every 10 steps because these steps, the tenth ones, must compute 2 algorithms instead of one, compared to the other 9 steps.
In Multi-Tasking, the Simulink model is computed in multiple threads depending on the rate. In a model that contains an algorithm running at Ts and another algorithm running at 10*Ts (therefore called multi-rate), a thread runs the algorithm at Ts and another thread runs the 10*Ts algorithm in parallel. Instead of computing the 10*Ts algorithm in one step as in Single-Tasking, the Multi-Tasking mode divide this secondary algorithm so it is computed in a few steps, which allows a lighter computation, as it knows that it has up to 10 steps to do the complete computation. Finally, during the famous 10th step, there is some data exchange between the 2 threads as the results are ready. This data exchange process is very light computation compared to compute the whole 10*Ts algorithm during this step.
The multi-rate mode on 1 core in XHP is not supported. Why?
The limitation comes from XHP only in this case. The XHP mode takes all processes running on a target that are not to be used by RT-LAB and shields them on a second core, leaving all the place to the RT-LAB executable on its own core. Therefore, the XHP mode needs at least 2 cores to be able to run. On a 8-core target for example, it is possible to run up to 7 subsystems in XHP mode while the 8th core will run all RT-LAB unused processes coming from the other 7 cores.
Why is this combination not supported: Multi-rate + XHP in Multi-Tasking mode of Simulink?
For now, the second thread in multi-tasking mode is considered as a running process that is not going to be used by RT-LAB (see previous answer). Therefore, in XHP mode, it would get shielded on the core that runs the unused processes, which is not possible and that is why it is not supported. The reason for this is that RT-LAB assigns its threads using subsystems. One subsystem per core. To fix this, it would need to assign its threads using rates, which is not available for now.




