Guide When and How to Enable CPU Pinning for Guest

Status
Not open for further replies.

ech0

Administrator
Staff member
May 26, 2020
35
0
6
Introduction

First Lets talk about what pinning your cores to the Vm actually does. By pinning you insure that those cores are dedicated to the VM. When you Pin your cores you force all the tasks on the VM to use those cores you pinned.

Note: One thing to note is Pinning your cores doesn't necessary increase performance. Pinning your cores help with LATENCY not THROUGHPUT. This is misunderstand by a lot of people. Most people recommend pinning because most people use their VM gaming so they notice "less lag" or really less overall latency in their Windows VM.



Pinning Examples:

First start by listing your CPU topology (Note that i am overlocked and running performance governor on host):

lscpu -e on an Intel 8C/8HT CPU
Code:
[ech0@ech0-arch ~]$ lscpu -e
....
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE    MAXMHZ   MINMHZ
  0    0      0    0 0:0:0:0          yes 5000.0000 800.0000
  1    0      0    1 1:1:1:0          yes 5000.0000 800.0000
  2    0      0    2 2:2:2:0          yes 5000.0000 800.0000
  3    0      0    3 3:3:3:0          yes 5000.0000 800.0000
  4    0      0    4 4:4:4:0          yes 5000.0000 800.0000
  5    0      0    5 5:5:5:0          yes 5000.0000 800.0000
  6    0      0    6 6:6:6:0          yes 5000.0000 800.0000
  7    0      0    7 7:7:7:0          yes 5000.0000 800.0000
See Example 2 in the Libvirt XML Section below. My CPU (i7-9700KF) is not hyper-threaded. So I can only pass 6 cores and 6 threads to my VM (2C/2HT for the host).


lscpu -e on a 6c/12t Intel 8700k:
Code:
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ    MINMHZ
0   0    0      0    0:0:0:0       yes    4600.0000 800.0000
1   0    0      1    1:1:1:0       yes    4600.0000 800.0000
2   0    0      2    2:2:2:0       yes    4600.0000 800.0000
3   0    0      3    3:3:3:0       yes    4600.0000 800.0000
4   0    0      4    4:4:4:0       yes    4600.0000 800.0000
5   0    0      5    5:5:5:0       yes    4600.0000 800.0000
6   0    0      0    0:0:0:0       yes    4600.0000 800.0000
7   0    0      1    1:1:1:0       yes    4600.0000 800.0000
8   0    0      2    2:2:2:0       yes    4600.0000 800.0000
9   0    0      3    3:3:3:0       yes    4600.0000 800.0000
10  0    0      4    4:4:4:0       yes    4600.0000 800.0000
11  0    0      5    5:5:5:0       yes    4600.0000 800.0000

Libvirt XML Examples:

Example 1: Intel 4C/4HT

Code:
$ virsh edit [vmname]
...
<vcpu placement='static'>4</vcpu>
<cputune>
    <vcpupin vcpu='0' cpuset='0'/>
    <vcpupin vcpu='1' cpuset='1'/>
    <vcpupin vcpu='2' cpuset='2'/>
    <vcpupin vcpu='3' cpuset='3'/>
</cputune>
...
Example 2: Intel 6C/6HT
Code:
$ virsh edit [vmname]
...
<vcpu placement='static'>4</vcpu>
<cputune>
    <vcpupin vcpu='0' cpuset='0'/>
    <vcpupin vcpu='1' cpuset='1'/>
    <vcpupin vcpu='2' cpuset='2'/>
    <vcpupin vcpu='3' cpuset='3'/>
    <vcpupin vcpu='4' cpuset='4'/>
    <vcpupin vcpu='5' cpuset='5'/>
</cputune>
...
Example 3: Intel 4C/8HT
Code:
...
<vcpu placement='static'>4</vcpu>
<cputune>
    <vcpupin vcpu='0' cpuset='2'/>
    <vcpupin vcpu='1' cpuset='3'/>
    <vcpupin vcpu='2' cpuset='6'/>
    <vcpupin vcpu='3' cpuset='7'/>
<emulatorpin cpuset='1,5'/>
</cputune>
...
<cpu>
    <topology sockets='1' cores='4' threads='1'/>
</cpu>
...
 
Last edited:
Status
Not open for further replies.