7

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.

1
  • 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. Commented Jun 19, 2018 at 18:25

3 Answers 3

6

You can see which cores are on which processors by taking at look at /proc/cpuinfo. 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,1,2,3 

or:

taskset -c 4,5,6,7 
2
  • 1
    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?) Commented Jan 30, 2017 at 21:29
  • 1
    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. Commented Jun 19, 2018 at 18:26
2

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
  • 1
    This still does not explain if taskset uses physical or logical indexing. If I run taskset -c 0,1,2,3 on the system above, will it bind to the first two physical cores (logical PUs 0-3) or to the first logical PU on each physical core? Commented Nov 22, 2020 at 9:43
1

You can use like:

taskset -c -p 0-3 pid

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.