I've tried to search for a solution, but all I found was how to pin processes to CPU using taskset or sched_setaffinity. But it looks like this won't give the process exclusive access to the CPU, i.e., scheduler may assign some other process on this CPU. Is there any way or command by which we can ensure that the CPU is dedicated to the process? With taskset we can make sure a particular process runs only on particular CPU, but I want it to be other way too, where CPU is binded to that process. I've found questions like How to allocate a process specific amount of CPU power? and How to limit a process to one CPU core in Linux? but they got marked as duplicate of How can I set the processor affinity of a process on Linux? which is not what I want.
-
If you pin all processes to other cores, your special process will be the olny one to run on that specific core. But that's probably not what you want. Maybe to need to explain your usage. Applications with a high performance task and guaranteed response times hide a core from the OS and run a bare metal process on that core, for example. – Philippos Jul 17 '19 at 06:51
-
Hmm... Yeah, something like that. I don't have access to the machine. I want everything to happen automatically with, maybe a shell script or c code of the process – user41965 Jul 17 '19 at 07:00
2 Answers
You Need to exclude one CPU from the Overall scheduling, afterwards you can assign the process to it via
taskset
as you already found out. To exclude a CPU, add the boot Parameter
isolcpus=N
The Number (N) is 0-based.

- 2,188
-
Thank you very much for the answer, I think it'll work. What is N? I didn't understand what you wrote. I'm really sorry. – user41965 Jul 17 '19 at 07:02
-
-
1Hey, thank you very much. Just a question. Is there any way to achieve this without having to reboot the system? At least something that'll act like this if not being able to completely isolate the core. Thank you. – user41965 Jul 22 '19 at 05:38
On systems running systemd you can also configure this in the systemd configuration. Assuming that your system has 4 cores you can add
[Manager]
CPUAffinity=0-2
to /etc/systemd/system.conf
to ensure systemd (PID 1) will run on the first three CPUs. By default processes started directly or indirectly by systemd (which is true for all processes) will inherit this setting so the 4th CPU (number 3) will not be used. Just add
[Service]
CPUAffinity=3
to the unit file of the service which you want to run on the 4th core. An advantage of this approach is that you can tweak other real-time related settings like LimitMEMLOCK
or LimitRTPRIO
in the same spot - no need to fiddle with a bunch of different tools.
Note: You need to reboot your system for systemd to pick up the first change. If you only modified the service configuration restarting the affected service is sufficient:
systemctl daemon-reload
systemctl restart my-service.service

- 2,160