How to pin Citrix Hypervisor Virtual CPUs to specific Physical CPUs

How to pin Citrix Hypervisor Virtual CPUs to specific Physical CPUs

book

Article ID: CTX246466

calendar_today

Updated On:

Description

Citrix Hypervisor maps vCPUs to pCPUs by default in a semi-even way to distribute VM load on the host. In some cases it may be needed to have a specific mapping, for example, if some VMs will be CPU intensive while other wont, the intensive VMs can be mapped to exclusive physical CPUs while the others share resources. This can lead to performance improvements in the Hypervisor.

The following example will be used to change hard affinity. This means where the vCPU is allowed to run. In this sense, once a vCPU is pinned to a pCPU with hard affinity, the vCPU won't be able to run in any other pCPU.

Soft affinity is used to define where does the vCPU prefers to run but it doesn't restrict where it is allowed to run.

To determine which type of mapping to use, analyze the type of workload that the guest VMs are going to be running. Ultimately the best way to determine the best mapping is through testing different configurations with real workloads and observing the results. There is not a perfect ratio since workloads change depending on many factors, such as OS type, patches, apps run by users, employee work schedules, etc.

 


Instructions


Command definitions

xl vcpu-pin <domain#> <vcpu#> <pCPUhard> <pCPUsoft> (VMs are called domains in Xen terminology)

xl vcpu-list (helps you find the current domain numbers, current pinning and affinity)



Sample commands

xl vcpu-pin 1 2 3 (Pin Domain 1 machine vCPU 2 to pCPU 3 with hard affinity)

xl vcpu-pin 0 1 all 0-2 (Pin domain 0 vCPU 1 with hard affinity to all and soft affinity to 0, 1 and 2 pCPUs)


Sample configuration change, before and after.
[root@lab ~]# xl vcpu-list
Name                                ID  VCPU   CPU State   Time(s) Affinity (Hard / Soft)
Domain-0                             0     0    5   -b-  123489.6  all / all
Domain-0                             0     1   10   -b-  123852.0  all / all
Domain-0                             0     2    7   -b-  120716.0  all / all
Domain-0                             0     3    7   -b-  123082.4  all / all
Domain-0                             0     4   10   -b-  120731.4  all / all
Domain-0                             0     5    3   -b-  128169.0  all / all
Domain-0                             0     6    8   r--  288875.7  all / all
Domain-0                             0     7   10   -b-  134935.5  all / all
Domain-0                             0     8    9   -b-  129905.5  all / all
Domain-0                             0     9    1   -b-  129339.3  all / all
Domain-0                             0    10   11   -b-  131645.5  all / all
Domain-0                             0    11    3   -b-  200675.1  all / all
vm1                                109     0    1   -b-   13003.2  all / all
vm1                                109     1    5   -b-   14843.0  all / all
vm2                                122     0   10   -b-    9517.5  all / all
vm2                                122     1    6   -b-    2338.2  all / all
vm3                                127     0   11   -b-   30649.4  all / all
vm3                                127     1    6   -b-    3141.9  all / all
vm4                                161     0    1   -b-   21896.7  all / all
vm4                                161     1    0   -b-    8084.3  all / all
vm5                                237     0    8   -b-    2594.5  all / all
vm6                                238     0    5   -b-    4820.9  all / all
vm6                                238     1    5   -b-    4608.6  all / all
vm7                                242     0    6   -b-   25274.0  all / all
vm7                                242     1    4   r--  468972.1  all / all
vm8                                244     0    7   -b-    3969.3  all / all
vm8                                244     1    5   -b-     531.4  all / all
vm8                                244     2    9   -b-    1251.7  all / all
vm8                                244     3   10   -b-     483.6  all / all
vm9                                255     0   10   -b-    6186.4  all / all
vm9                                255     1    3   -b-    1432.1  all / all
vm10                               260     0   11   -b-    4724.3  all / all
vm10                               260     1    7   -b-    1342.8  all / all
vm11                               262     0    0   -b-   10335.3  all / all
vm11                               262     1    9   -b-    5015.9  all / all

xl vcpu-pin 0 0 0
xl vcpu-pin 0 1 1
xl vcpu-pin 0 2 2
xl vcpu-pin 0 3 3
xl vcpu-pin 0 4 4
xl vcpu-pin 0 5 5
xl vcpu-pin 0 6 0
xl vcpu-pin 0 7 1
xl vcpu-pin 0 8 2
xl vcpu-pin 0 9 3
xl vcpu-pin 0 10 4
xl vcpu-pin 0 11 5
xl vcpu-pin 109 0 0
xl vcpu-pin 109 1 1
xl vcpu-pin 122 0 2
xl vcpu-pin 122 1 3
xl vcpu-pin 127 0 4
xl vcpu-pin 127 1 5
xl vcpu-pin 161 0 6
xl vcpu-pin 161 1 7
xl vcpu-pin 237 0 8
xl vcpu-pin 238 0 9
xl vcpu-pin 238 1 10
xl vcpu-pin 242 0 11
xl vcpu-pin 242 1 0
xl vcpu-pin 244 0 1
xl vcpu-pin 244 1 2 
xl vcpu-pin 244 2 3
xl vcpu-pin 244 3 4
xl vcpu-pin 255 0 5
xl vcpu-pin 255 1 6
xl vcpu-pin 260 0 7
xl vcpu-pin 260 1 8
xl vcpu-pin 262 0 9
xl vcpu-pin 262 1 10

[root@lab ~]# xl vcpu-list
Name                                ID  VCPU   CPU State   Time(s) Affinity (Hard / Soft)
Domain-0                             0     0    0   -b-  123501.4  0 / all
Domain-0                             0     1    1   -b-  123861.7  1 / all
Domain-0                             0     2    2   -b-  120728.9  2 / all
Domain-0                             0     3    3   -b-  123093.3  3 / all
Domain-0                             0     4    4   -b-  120743.4  4 / all
Domain-0                             0     5    5   -b-  128180.6  5 / all
Domain-0                             0     6    0   -b-  288889.3  0 / all
Domain-0                             0     7    1   -b-  134947.2  1 / all
Domain-0                             0     8    2   -b-  129918.8  2 / all
Domain-0                             0     9    3   r--  129355.4  3 / all
Domain-0                             0    10    4   -b-  131656.6  4 / all
Domain-0                             0    11    5   -b-  200695.5  5 / all
vm1                                109     0    0   -b-   13008.5  0 / all
vm1                                109     1    1   -b-   14848.2  1 / all
vm2                                122     0    2   -b-    9523.1  2 / all
vm2                                122     1    3   -b-    2339.5  3 / all
vm3                                127     0    4   -b-   30668.0  4 / all
vm3                                127     1    5   -b-    3143.6  5 / all
vm4                                161     0    6   -b-   21921.4  6 / all
vm4                                161     1    7   -b-    8099.3  7 / all
vm5                                237     0    8   -b-    2596.5  8 / all
vm6                                238     0    9   -b-    4827.6  9 / all
vm6                                238     1   10   -b-    4614.7  10 / all
vm7                                242     0   11   -b-   25316.6  11 / all
vm7                                242     1    0   r--  469803.4  0 / all
vm8                                244     0    1   -b-    3979.5  1 / all
vm8                                244     1    2   -b-     532.7  2 / all
vm8                                244     2    3   -b-    1254.8  3 / all
vm8                                244     3    4   -b-     484.7  4 / all
vm9                                255     0    5   -b-    6207.9  5 / all
vm9                                255     1    6   -b-    1438.0  6 / all
vm10                               260     0    7   -b-    4735.4  7 / all
vm10                               260     1    8   -b-    1346.1  8 / all
vm11                               262     0    9   -b-   10400.3  9 / all
vm11                               262     1   10   -b-    5044.6  10 / all