how to force an application to run in one core and no other applications run in that core on windows?

2.2k views Asked by At

I think my questions are unusual, but I want to work on real-time targeting in MATLAB Simulink, but I don't want to use XPC target. I just want no interruption on the program (simulink) when it is running in order to have a real-time interruptless control system. In that order, I can use my control module without a target system.

  1. can we force a core to only be used by Simulink and nothing else?
  2. what is the average and maximum time that an interrupt takes?
  3. is there any other way that we can use in Simulink?
3

There are 3 answers

4
Arno On

a. In case you have a multicore platform: Stay away from core 0. Windows assigns certain tasks specifically to core 0. See the SetThreadAffinityMask function to get information how to run a thread on specific cores.

b. Possibly raise the thread/process priority. See the SetThreadPriority function and the SetPriorityClass function for details about setting priorities and Scheduling Priorities for dertails about the priority ranges.

Priority class REALTIME_PRIORITY_CLASS with thread priority THREAD_PRIORITY_TIME_CRITICAL will run your thread at utmost priority whenever it is ready to run. Be aware that such a priority setting will disallow any other process/thread to gain CPU on that core while your thread is running.

3
am304 On

Well, Simulink is essentially a single-threaded application. There are some ways in which you can use a second core when running in Rapid Accelerator mode (see documentation), but by and large, everything runs on one core. I'm guessing it may change in the future, as a lot of people would like to split the execution of a single large model across multiple cores, but right now it's not possible as far as I know.

Simulink, however is not a real-time application, given that it runs on Windows or other non-real time O/S. Why do you not want to use xPC Target? As you are working on a real-time target, that would be the best option. Other options would be to use Real-Time Windows Target, SIL or even PIL if you have access to your real-time target hardware. Have a look at the example Software and Processor-in-the-Loop (SIL and PIL) Simulation. I think you can configure the code generation process to be executed on one core only, but better to ask MathWorks to be sure.

0
Big Zee On

Using imageCFG you can preset affinity of a program. It modifies the exe file to run on desired core. http://www2.robpol86.com/guides/ImageCFG/