CPU Dedication

Problem: How can we allocate a CPU to a known process?

Actually, it is quite simple. First, we need an idle CPU to assign. How? We can adjust with kernel parameters in order to select which CPU(s) will be isolated from kernel “CPU pool”. In raspberry pi, you can append “isolcpus=1,2,3” kernel parameter into /boot/cmdline.txt to isolate CPU#1, CPU#2 and CPU#3. The number of CPU starts from #0. So we have 3 idle CPUs, even if the system is heavily loaded. Time to set CPU for a specific task with sched_setaffinity. I found an example code to set the affinity of the process thread. And I rewrite it to run a shell command in specific CPU core.

That’s it. Now you can run your own code in specific CPU.