VMs: enable cpu cache passthrough; AMD + multithreaded

This commit is contained in:
Eric Schultz
2020-02-10 04:35:23 -06:00
committed by GitHub
parent bf78f59d75
commit 0f94acd8fb

View File

@@ -321,11 +321,22 @@
$intCPUThreadsPerCore = 1;
$cpumode = '';
$cpucache = '';
$cpufeatures = '';
if (!empty($domain['cpumode']) && $domain['cpumode'] == 'host-passthrough') {
$cpumode .= "mode='host-passthrough'";
$cpucache = "<cache mode='passthrough'/>";
// detect if the processor is hyperthreaded:
$intCPUThreadsPerCore = max(intval(shell_exec('/usr/bin/lscpu | grep \'Thread(s) per core\' | awk \'{print $4}\'')), 1);
// detect if the processor is AMD + multithreaded, and if so, enable topoext cpu feature
if ($intCPUThreadsPerCore > 1) {
$strCPUInfo = file_get_contents('/proc/cpuinfo');
if (strpos($strCPUInfo, 'AuthenticAMD') !== false) {
$cpufeatures .= "<feature policy='require' name='topoext'/>";
}
}
// even amount of cores assigned and cpu is hyperthreaded: pass that info along to the cpu section below
if ($intCPUThreadsPerCore > 1 && ($vcpus % $intCPUThreadsPerCore == 0)) {
@@ -336,6 +347,8 @@
$cpustr = "<cpu $cpumode>
<topology sockets='1' cores='{$intCores}' threads='{$intThreads}'/>
$cpucache
$cpufeatures
</cpu>
<vcpu placement='static'>{$vcpus}</vcpu>
<cputune>