Add CPU configuration.

This commit is contained in:
Michael Lipp 2023-05-24 11:44:47 +02:00
parent c6bf6acb18
commit 11452babe6
3 changed files with 44 additions and 1 deletions

View file

@ -46,4 +46,17 @@
# "maximumRam": "512M" # "maximumRam": "512M"
# "currentRam": "512M" # "currentRam": "512M"
# CPU settings
# "cpuModel": "host"
# Setting maximumCpus to 1 omits the "-smp" options. The defaults (0)
# cause the corresponding property to be omitted from the "-smp" option.
# If currentCpus is greater than maximumCpus, the latter is adjusted.
# "maximumCpus": 1
# "currentCpus": 1
# "cpuSockets": 0
# "diesPerSocket": 0
# "coresPerSocket": 0
# "threadsPerCore": 0
# "accelertor": "kvm"

View file

@ -61,6 +61,14 @@ class Configuration implements Dto {
public String bootMode = "uefi"; public String bootMode = "uefi";
public String maximumRam; public String maximumRam;
public String currentRam; public String currentRam;
public String cpuModel = "host";
public int maximumCpus = 1;
public int currentCpus = 1;
public int cpuSockets;
public int diesPerSocket;
public int coresPerDie;
public int threadsPerCore;
public String accelerator = "kvm";
} }
/** /**
@ -80,6 +88,11 @@ class Configuration implements Dto {
return false; return false;
} }
// Adjust max cpus if necessary
if (vm.currentCpus > vm.maximumCpus) {
vm.maximumCpus = vm.currentCpus;
}
return true; return true;
} }

View file

@ -52,7 +52,24 @@
# Provide RAM # Provide RAM
- [ "-object", "memory-backend-ram,id=pc.ram,\ - [ "-object", "memory-backend-ram,id=pc.ram,\
size=${ vm.maximumRam!"512M" }" ] size=${ vm.maximumRam!"512M" }" ]
<#if vm.useTpm>
# Attach TPM
- [ "-chardev", "socket,id=chrtpm,path=${ runtimeDir }/swtpm-sock" ]
- [ "-tpmdev", "emulator,id=tpm0,chardev=chrtpm" ]
- [ "-device", "tpm-tis,tpmdev=tpm0" ]
</#if>
- [ "-cpu", "${ vm.cpuModel }" ]
<#if vm.maximumCpus gt 1>
- [ "-smp", "${ vm.currentCpus },maxcpus=${ vm.maximumCpus }\
<#if vm.cpuSockets gt 0>,sockets=${ vm.cpuSockets }</#if>\
<#if vm.diesPerSocket gt 0>,cores=${ vm.diesPerSocket }</#if>\
<#if vm.coresPerDie gt 0>,cores=${ vm.coresPerDie }</#if>\
<#if vm.threadsPerCore gt 0>,cores=${ vm.threadsPerCore }</#if>" ]
</#if>
<#if vm.accelerator != "none">
- [ "-accel", "${ vm.accelerator }"]
</#if>
- [ "-chardev", "socket,id=charmonitor,path=${ runtimeDir }/monitor.sock,server=on,wait=off" ] - [ "-chardev", "socket,id=charmonitor,path=${ runtimeDir }/monitor.sock,server=on,wait=off" ]
- [ "-mon", "chardev=charmonitor,id=monitor,mode=control" ] - [ "-mon", "chardev=charmonitor,id=monitor,mode=control" ]
# - [ "-spice", "port=5900,disable-ticketing=on" ] # - [ "-spice", "port=5900,disable-ticketing=on" ]