Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whole one core dedicated to single process

Is there any way in Linux to assign one CPU core to a particular given process and there should not be any other processes or interrupt handlers to be scheduled on this core?

I have read about process affinity in Linux Binding Processes to CPUs using the taskset utility but that's not solving my problem because it just try to affine the given process to that core but it is possible that other processes may be scheduled on this core and this is what I want to avoid.

Should we change the kernel code for scheduling?

like image 705
akp Avatar asked Nov 27 '12 11:11

akp


People also ask

How do I dedicate a core to a single program?

To set CPU Priority, right-click on any process in Task Manager and select Go to details. Next, right-click on the highlighted process and click on Set Priority. Now, choose priority from the list that pops up. If you want your process to run as soon as it needs, select Realtime.

Can a single process run on multiple cores?

Yes, a single process can run multiple threads on different cores. Caching is specific to the hardware. Many modern Intel processors have three layers of caching, where the last level cache is shared across cores.

Does 1 CPU mean 1 core?

Multiple CoresOriginally, CPUs had a single core. That meant the physical CPU had a single central processing unit on it. To increase performance, manufacturers add additional “cores,” or central processing units. A dual-core CPU has two central processing units, so it appears to the operating system as two CPUs.


1 Answers

Yes there is. In fact, there are two separate ways to do it :-)

Right now, the best way to accomplish what you want is to do the following:

  1. Add the parameter isolcpus=[cpu_number] to the Linux kernel command line from the boot loader during boot. This will instruct the Linux scheduler not to run any regular tasks on that CPU unless specifically requested using cpu affinity.

  2. Use IRQ affinity to set other CPUs to handle all interrupts so that your isolated CPU will not receive any interrupts.

  3. Use CPU affinity to fix your specific task to the isolated CPU.

This will give you the best that Linux can provide with regard to CPU isolation without out-of-tree and in-development patches.

Your task will still get interrupted from time to time by Linux code, including other tasks - such as the timer tick interrupt and the scheduler code, IPIs from other CPUs and stuff like work queue kernel threads, although the interruption should be quite minimal.

For an (almost) complete list of interruption sources, check out my page at https://github.com/gby/linux/wiki

The alternative method is to use cpusets which is way more elegant and dynamic but suffers from some weaknesses at this point in time (no migration of timers for example) which makes me recommend the old, crude but effective isolcpus parameter.

Note that work is currently being done by the Linux community to address all these issues and more to give even better isolation.

like image 84
gby Avatar answered Sep 20 '22 01:09

gby