How to choose VM CPU type

To check run:

bash -c "$(wget -qLO - 'https://cloud.office-dot.de/cloud/s/tcYPmxH9ecKj7Ed/download?path=%2FProxmox%20VE%2FPost%20Install&files=supported-cpu.sh')"

With Proxmox v8.x the release notes says the default CPU type of the new VM is X86-64-v2-AES.

The x86-64-v2-AES model is the new default CPU type for VMs created via the web interface. It provides important extra features over the qemu64/kvm64, and improves performance of many computing operations.

Previously, the default CPU type was kvm64. It may affect the guest OS performance and some OS has a minimum request on CPU.

There are more information on the Proxmox Wiki at: Virtual Machine settings.

The CPU types are from 486 to the latest Xeon processors. Usually, you should select for your VM a processor type that closely matches the CPU of the host system, as it means that the host CPU features(also called CPU flags) will be available in your VMs.

If you want an exact match, you can set the CPU type to host in which case the VM will have exactly the same CPU flags as your host system.

If you are working on the Cluster environment, or more than one Host, you may have a problem when making a live migration of VMs between different hosts. Because two different Hosts use different CPUs, they have different CPU types or different microcode versions.

Important:Setting CPU type to anything else than qemu64/kvm64 or X86-64-v* will break livemigration

Now choose one from the QEMU CPU types.

QEMU CPU Types are virtual CPU types, compatible with both Intel and AMD host CPUs.

At the very beginning, Proxmox VE provides kvm64 CPU model. It is the level of Pentium 4. Our current CPU are far more advanced.

Now on the list of the Proxmo VE CPU type list.

Even though the new default CPU type is x86-64-v2-AES, I still want to know the exact level of my CPU.

Here are two scripts that can run on the Host to check the level.

#!/bin/sh -eu

flags=$(cat /proc/cpuinfo | grep flags | head -n 1 | cut -d: -f2)

supports_v2='awk "/cx16/&&/lahf/&&/popcnt/&&/sse4_1/&&/sse4_2/&&/ssse3/ {found=1} END {exit !found}"'
supports_v2_aes='awk "/cx16/&&/lahf/&&/popcnt/&&/sse4_1/&&/sse4_2/&&/ssse3/&&/aes/ {found=20} END {exit !found}"'
supports_v3='awk "/avx/&&/avx2/&&/bmi1/&&/bmi2/&&/f16c/&&/fma/&&/abm/&&/movbe/&&/xsave/ {found=1} END {exit !found}"'
supports_v4='awk "/avx512f/&&/avx512bw/&&/avx512cd/&&/avx512dq/&&/avx512vl/ {found=1} END {exit !found}"'

echo "$flags" | eval $supports_v2 || exit 2 && echo "CPU supports x86-64-v2"
echo "$flags" | eval $supports_v2_aes || exit 20 && echo "CPU supports x86-64-v2+aes"
echo "$flags" | eval $supports_v3 || exit 3 && echo "CPU supports x86-64-v3"
echo "$flags" | eval $supports_v4 || exit 4 && echo "CPU supports x86-64-v4"

I save the above to a script file named l.sh. Run the script in the terminal of the Host.

root@pve:~# bash l.sh
CPU supports x86-64-v2
CPU supports x86-64-v3
root@pve:~#

The result is x86-64-v2 and x86-64-v3.

The other script content is based on AWK, I save it as s.sh.

#!/usr/bin/awk -f

BEGIN {
    while (!/flags/) if (getline < "/proc/cpuinfo" != 1) exit 1
    if (/lm/&&/cmov/&&/cx8/&&/fpu/&&/fxsr/&&/mmx/&&/syscall/&&/sse2/) level = 1
    if (level == 1 && /cx16/&&/lahf/&&/popcnt/&&/sse4_1/&&/sse4_2/&&/ssse3/) level = 2
    if (level == 2 && /cx16/&&/lahf/&&/popcnt/&&/sse4_1/&&/sse4_2/&&/ssse3/&&/aes/) level = 2.1
    if (level >= 2 && /avx/&&/avx2/&&/bmi1/&&/bmi2/&&/f16c/&&/fma/&&/abm/&&/movbe/&&/xsave/) level = 3
    if (level == 3 && /avx512f/&&/avx512bw/&&/avx512cd/&&/avx512dq/&&/avx512vl/) level = 4
    if (level > 0) {
        if (level == 2.1) {
            print "CPU supports x86-64-v2+aes"; exit level + 1
        } else {
            print "CPU supports x86-64-v" level; exit level + 1
        }
    }
    exit 1
}

Run in the command line:

root@pve:~# ./s.sh
CPU supports x86-64-v3
root@pve:~#

Conclusion.

Now, I change all my VMs CPU types to x86-64-v3 in the Proxmox VE.

Quelle: https://www.yinfor.com/2023/06/how-i-choose-vm-cpu-type-in-proxmox-ve.html