If you have an Alder Lake or newer Intel CPU, you probably want the option to load a qube on the P or E cores, and this might help someone who is new to xen.
https://dev.qubes-os.org/projects/core-admin/en/latest/libvirt.html https://libvirt.org/formatdomain.html#cpu-allocation
First, you need to add the following to GRUB
dom0_max_vcpus=4 dom0_vcpus_pin smt=on sched-gran=core
You can leave out smt=on if you don’t want to enable SMT, and if you want to use SMT read the notes at the end.
The CPU I’m using is the 12900K, which has 16 physical cores and 24 threads with SMT enabled. The cores 0-15 are P cores and 16-23 are E cores.
If you want to move dom0 to the E cores, it can be done like this:
/usr/sbin/xl vcpu-pin Domain-0 0 20-23
/usr/sbin/xl vcpu-pin Domain-0 1 20-23
/usr/sbin/xl vcpu-pin Domain-0 2 20-23
/usr/sbin/xl vcpu-pin Domain-0 3 20-23
It’s easy to make a xen-user.xml that uses jinja to automatically set the cpuset of a qube based on the name, this is an example of how you can do it with prefixing the name with p-core or e-core.
You probably don’t want to just make two groups, this is just an example of how it can be done.
{% extends 'libvirt/xen.xml' %}
{% block basic %}
<name>{{ vm.name }}</name>
<uuid>{{ vm.uuid }}</uuid>
{% if ((vm.virt_mode == 'hvm' and vm.devices['pci'].persistent() | list)
or vm.maxmem == 0) -%}
<memory unit="MiB">{{ vm.memory }}</memory>
{% else -%}
<memory unit="MiB">{{ vm.maxmem }}</memory>
{% endif -%}
<currentMemory unit="MiB">{{ vm.memory }}</currentMemory>
{% if vm.name.startswith('p-core') -%}
<vcpu cpuset="0-15">{{ vm.vcpus }}</vcpu>
{% elif vm.name.startswith('e-core') -%}
<vcpu cpuset="16-23">{{ vm.vcpus }}</vcpu>
{% else -%}
<vcpu cpuset="0-15">{{ vm.vcpus }}</vcpu>
{% endif -%}
{% endblock %}
/usr/sbin/xl vcpu-list
You can change the performance state of the individual cores:
/usr/sbin/xenpm set-scaling-governor 0 performance
This needs to be set every time the system boots, and the default setting is ondemand.
Notes on SMT.
Using sched-gran=core
doesn't seem to work with Alder Lake, xen dmesg has the following warning.
(XEN) ***************************************************
(XEN) Asymmetric cpu configuration.
(XEN) Falling back to sched-gran=cpu.
(XEN) ***************************************************
Unless you understand and are okay with the consequences of enabling SMT, you should just leave it off.
If you are running your system with SMT enabled you can take advantage of the fact that E cores can’t hyper thread, even with SMT enabled the E cores are essentially running with SMT off.
You can also disable SMT for individual cores by changing the cpuset, where you don't use the sibling core.
E.g. with SMT enabled, core 0 and 1 are running on the same physical core, but if you don't use core 1 that core is no longer able to hyper thread.
Disabling SMT is that same as xen using the cpuset 0,2,4,6,8,10,12,14