user@dom0 ~ % python3
Python 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 12.3.1 20230508 (Red Hat 12.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.sensors_battery().power_plugged
True
Personally, I’d still prefer to pin qubes to p-cores even on battery power, but I can see your use-case.
Implementing this in the vCPU pinning script would be very simple and I will gladly accept a PR (or do it myself, but I don’t think I’ll have time right now). It would not apply to aleady-started qubes, though, so that makes me think that it may be a good idea to also write something that would use udev triggers to re-pin all VMs to e-cores on battery power. Technically it could be integrated within this script, too (maybe via pyudev).
EDIT:
For what it’s worth, it may also be interesting to consider applying settings for xen_hwp, e.g. xenpm set-cpufreq-hwp powersave maximum:25 for power saving and xenpm set-cpufreq-hwp balance otherwise.
I need some help to ensure my parameters are correct with regard to the CPU topology. I though it was 0-7 for P and 8-15 for E but it turns I was wrong? (or it changed?)
The output of xenpm get-cpu-topology is the following:
Was there a patch for Xen recently that made it work with asymmetric CPUs + SMT securely? Last I checked it had some problems with that (setting scheduling granularity failed).
Affinity doesn’t work with credit2, you can set it, but Xen doesn’t respect it, I think it’s a bug.
AMD CPUs can use NUMA to keep cores on the same CCD, this also doesn’t work with credit2. It correctly sets the affinity for each CCD, but doesn’t respect it when assigning the cores.
I was referring to this comment by @renehoj, wherein you could help make SMT (moderately) more secure by setting sched-gran=core, but it was not possible with asymmetric CPUs.
I am not fully sure about that, althought the Xen wiki page about CPU pinning does not mention that it should only work with credit(1). Later in the day I can do some testing based on the amount of fan noise/temperature rise when I perform soft pinning.