Numbering scheme for CPU affinity

central-processing-unitvmware-esxi

In the VMware Infrastructure Client (no vCenter), under the Resources / Advanced CPU section of each VM's Edit Settings dialog, there is an option to alter the Scheduling Affinity of a VM. It sets the sched.cpu.affinity value in the VMX file.

I believe this allows me to force a VM to only be serviced by a specific physical CPU on the host, judicious use of which might in some cases allow me to license a VM for one physical CPU rather than the two that are in the host.

The description of the config field in Edit Settings is as follows:

Hyperthreading Status: Active

Available CPUs: 12 (logical CPUs)

Select logical processor affinity for this virtual machine.

Use '-' for ranges and ',' to separate values. For example, "0,2-4,7" would indicate processors 0, 2, 3, 4 and 7.

Is it fair to assume (in this and similar cases):

  • numbers 0 to 11 represent each of the physical cores (or are the 'hyperthreads' numbered too)?
  • if I wanted to limit the VM to run on one of the physical CPUs, I should enter either 0-5 or 6-11 (or are these numbers in some different pattern)?

Otherwise, is there a reliable source (VIC screen, shell command, etc.) to look up the number-to-CPU mapping on any particular host?

(For reference, the CPUs are Intel Xeon X5675 units, which are each 6-core with hyperthreading.)

Best Answer

Your software is likely licensed per (visible) CPU socket. If you configure your destination virtual machine with the appropriate socket and core count, it doesn't really matter where ESXi decides to schedule threads on the underlying hardware. Your software should only be concerned with what's visible to the virtual machine. In this case, a 1-socket, 4-core VM should satisfy the requirement.

See: vCPU performance between 1 or 2 vCPU's

Just like taskset and CPU scheduling on Linux, you don't want to go down the path of CPU-affinities and pinning unless you have a compelling reason.


Edit:

The numbering is the same as taskset. For a Westmere 6-core CPU, you will see physical and Hyperthreaded cores according to this schedule:

  NUMANode L#0 (P#0 32GB) + Socket L#0 + L3 L#0 (12MB)
    L2 L#0 (256KB) + L1d L#0 (32KB) + L1i L#0 (32KB) + Core L#0
      PU L#0 (P#0)
      PU L#1 (P#12)
    L2 L#1 (256KB) + L1d L#1 (32KB) + L1i L#1 (32KB) + Core L#1
      PU L#2 (P#2)
      PU L#3 (P#14)
    L2 L#2 (256KB) + L1d L#2 (32KB) + L1i L#2 (32KB) + Core L#2
      PU L#4 (P#4)
      PU L#5 (P#16)
    L2 L#3 (256KB) + L1d L#3 (32KB) + L1i L#3 (32KB) + Core L#3
      PU L#6 (P#6)
      PU L#7 (P#18)
    L2 L#4 (256KB) + L1d L#4 (32KB) + L1i L#4 (32KB) + Core L#4
      PU L#8 (P#8)
      PU L#9 (P#20)
    L2 L#5 (256KB) + L1d L#5 (32KB) + L1i L#5 (32KB) + Core L#5
      PU L#10 (P#10)
      PU L#11 (P#22)
  NUMANode L#1 (P#1 32GB) + Socket L#1 + L3 L#1 (12MB)
    L2 L#6 (256KB) + L1d L#6 (32KB) + L1i L#6 (32KB) + Core L#6
      PU L#12 (P#1)
      PU L#13 (P#13)
    L2 L#7 (256KB) + L1d L#7 (32KB) + L1i L#7 (32KB) + Core L#7
      PU L#14 (P#3)
      PU L#15 (P#15)
    L2 L#8 (256KB) + L1d L#8 (32KB) + L1i L#8 (32KB) + Core L#8
      PU L#16 (P#5)
      PU L#17 (P#17)
    L2 L#9 (256KB) + L1d L#9 (32KB) + L1i L#9 (32KB) + Core L#9
      PU L#18 (P#7)
      PU L#19 (P#19)
    L2 L#10 (256KB) + L1d L#10 (32KB) + L1i L#10 (32KB) + Core L#10
      PU L#20 (P#9)
      PU L#21 (P#21)
    L2 L#11 (256KB) + L1d L#11 (32KB) + L1i L#11 (32KB) + Core L#11
      PU L#22 (P#11)
      PU L#23 (P#23)
Related Topic