6

I have quad core CPU with hyper threading enabled. So I have 8 logical cores. I want to limit my application to use only 4 cores and I want this 4 cores to be different physical cores. Which taskset options (core numbers) should I use? :

  • taskset -c 0,1,2,3 command or
  • taskset -c 0,2,4,6 command

Thank you.

  • Just to be clear on the Linux terminology, you have 8 logical "processors" distributed among 4 physical "cores". You want to pick 4 logical processors that correspond to 4 distinct cores. – Mark Lakata Jun 19 '18 at 18:25
4

You can see which cores are on which processors by taking at look at /proc/cpu info. For example, you will see on a machine with a dual core cpu

processor   : 0
(snip)
core id     : 0
cpu cores   : 2

for the first core on the processor and

processor   : 1
(snip)
core id : 1
cpu cores   : 2

on the second.

So, generally speaking, I think you would want

taskset -c 0,2,4,6

or

taskset -c 1,3,5,7
  • Um. just curious. If "processor 0" corresponds to [physical] core 0, and "processor 1" corresponds to [physical] core 1…then doesn't that mean that, to have all 4 cores selected, both 0 and 1 must necessarily be selected? (That is, 0/2/4/6 would only use physical cores 0 and 2?) – JamesTheAwesomeDude Jan 30 '17 at 21:29
  • In your example, processor:0 is on core:0 and process:1 is on core:1. Those two processors are on different cores, so assuming that the pattern continues, the argument to taskset should be -c 0,1,2,3. – Mark Lakata Jun 19 '18 at 18:26
1

You may want to take a look at CPU Set (cset) to create a CPU shield group for your application. This way you can ensure that real cores are being used for the important work. I typically disable hyperthreading (on Nehalem systems) for my realtime and low-latency applications.

Here's a tutorial for creating groups of CPUs for specific applications/processes using cset, which is a little more organized than taskset. https://rt.wiki.kernel.org/index.php/Cpuset_management_utility/tutorial

As far as determining the core count and location assignments, take a look at: http://dag.wieers.com/blog/is-hyper-threading-enabled-on-a-linux-system

A quick run of the utility linked on a quad-core Nehalem with hyperthreading enabled shows:

[root@XXX ~/hwloc-1.0.3]# ./utils/lstopo 
Machine (7980MB) + Socket #0 + L3 #0 (8192KB)
  L2 #0 (256KB) + L1 #0 (32KB) + Core #0
    PU #0 (phys=0)
    PU #1 (phys=4)
  L2 #1 (256KB) + L1 #1 (32KB) + Core #1
    PU #2 (phys=1)
    PU #3 (phys=5)
  L2 #2 (256KB) + L1 #2 (32KB) + Core #2
    PU #4 (phys=2)
    PU #5 (phys=6)
  L2 #3 (256KB) + L1 #3 (32KB) + Core #3
    PU #6 (phys=3)
    PU #7 (phys=7)
1

You can use like:

taskset -c -p 0-3 pid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.