[libvirt] [PATCH 0/2] vmx: start reading/writing CPU topology

Read/write only cpuid.coresPerSocket for now. Pino Toscano (2): vmx: convert cpuid.coresPerSocket for CPU topology vmx: write cpuid.coresPerSocket back from CPU topology src/vmx/vmx.c | 57 ++++++++++++++++++++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml | 3 ++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.vmx | 72 +++++++++++++++++++++++++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.xml | 37 +++++++++++++ tests/vmx2xmltest.c | 1 + tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.vmx | 39 ++++++++++++++ tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.xml | 37 +++++++++++++ tests/xml2vmxtest.c | 1 + 8 files changed, 247 insertions(+) create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.vmx create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.xml create mode 100644 tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.vmx create mode 100644 tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.xml -- 2.14.3

Convert the cpuid.coresPerSocket key as both number of CPU sockets, and cores per socket. Add the VMX file attached to RHBZ#1568148 as testcase esx-in-the-wild-9; adapt the resulting XML of testcase esx-in-the-wild-8 to the CPU topology present in that VMX. https://bugzilla.redhat.com/show_bug.cgi?id=1568148 Signed-off-by: Pino Toscano <ptoscano@redhat.com> --- src/vmx/vmx.c | 28 ++++++++++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml | 3 ++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.vmx | 72 +++++++++++++++++++++++++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.xml | 37 +++++++++++++ tests/vmx2xmltest.c | 1 + 5 files changed, 141 insertions(+) create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.vmx create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.xml diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index cd43d9c49b..939fa840ab 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1353,6 +1353,8 @@ virVMXParseConfig(virVMXContext *ctx, long long sharedFolder_maxNum = 0; int cpumasklen; struct virVMXConfigScanResults results = { -1 }; + long long coresPerSocket = 0; + virCPUDefPtr cpu = NULL; if (ctx->parseFileName == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1516,6 +1518,31 @@ virVMXParseConfig(virVMXContext *ctx, if (virDomainDefSetVcpus(def, numvcpus) < 0) goto cleanup; + /* vmx:cpuid.coresPerSocket -> def:cpu */ + if (virVMXGetConfigLong(conf, "cpuid.coresPerSocket", &coresPerSocket, 1, + true) < 0) + goto cleanup; + + if (coresPerSocket > 1) { + if (VIR_ALLOC(cpu) < 0) + goto cleanup; + + cpu->type = VIR_CPU_TYPE_GUEST; + cpu->mode = VIR_CPU_MODE_CUSTOM; + + cpu->sockets = numvcpus / coresPerSocket; + if (cpu->sockets <= 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("VMX entry 'cpuid.coresPerSocket' smaller than " + "'numvcpus'")); + goto cleanup; + } + cpu->cores = coresPerSocket; + cpu->threads = 1; + + VIR_STEAL_PTR(def->cpu, cpu); + } + /* vmx:sched.cpu.affinity -> def:cpumask */ /* NOTE: maps to VirtualMachine:config.cpuAffinity.affinitySet */ if (virVMXGetConfigString(conf, "sched.cpu.affinity", &sched_cpu_affinity, @@ -1881,6 +1908,7 @@ virVMXParseConfig(virVMXContext *ctx, VIR_FREE(sched_cpu_affinity); VIR_FREE(sched_cpu_shares); VIR_FREE(guestOS); + virCPUDefFree(cpu); return def; } diff --git a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml index c85ccf3649..eba5f4734a 100644 --- a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml +++ b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml @@ -10,6 +10,9 @@ <os> <type arch='x86_64'>hvm</type> </os> + <cpu> + <topology sockets='4' cores='2' threads='1'/> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> diff --git a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.vmx b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.vmx new file mode 100644 index 0000000000..8c3f5b4ba8 --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.vmx @@ -0,0 +1,72 @@ +.encoding = "UTF-8" +config.version = "8" +virtualHW.version = "10" +vmci0.present = "TRUE" +svga.vramSize = "8388608" +numvcpus = "16" +memSize = "16384" +sched.cpu.units = "mhz" +sched.cpu.latencySensitivity = "normal" +tools.upgrade.policy = "manual" +scsi0.virtualDev = "lsisas1068" +scsi0.present = "TRUE" +sata0.present = "TRUE" +scsi0:0.deviceType = "scsi-hardDisk" +scsi0:0.fileName = "v2v-windows-kkulkarn.vmdk" +sched.scsi0:0.shares = "normal" +sched.scsi0:0.throughputCap = "off" +scsi0:0.present = "TRUE" +ethernet0.virtualDev = "vmxnet3" +ethernet0.networkName = "VM Network" +ethernet0.addressType = "vpx" +ethernet0.generatedAddress = "00:50:56:80:b3:81" +ethernet0.uptCompatibility = "TRUE" +ethernet0.present = "TRUE" +floppy0.startConnected = "FALSE" +floppy0.clientDevice = "TRUE" +floppy0.fileName = "Floppy 0" +sata0:0.startConnected = "FALSE" +sata0:0.deviceType = "atapi-cdrom" +sata0:0.clientDevice = "TRUE" +sata0:0.fileName = "CD/DVD drive 0" +sata0:0.present = "TRUE" +displayName = "v2v-windows-kkulkarn" +guestOS = "windows8srv-64" +toolScripts.afterPowerOn = "TRUE" +toolScripts.afterResume = "TRUE" +toolScripts.beforeSuspend = "TRUE" +toolScripts.beforePowerOff = "TRUE" +tools.syncTime = "FALSE" +tools.guest.desktop.autolock = "FALSE" +uuid.bios = "42 00 93 72 17 da be 73-77 9d 00 7c cf 1b d2 28" +vc.uuid = "50 00 d2 b0 61 6e 61 29-8c 06 82 b0 74 40 a8 71" +nvram = "v2v-windows-kkulkarn.nvram" +pciBridge0.present = "TRUE" +svga.present = "TRUE" +pciBridge4.present = "TRUE" +pciBridge4.virtualDev = "pcieRootPort" +pciBridge4.functions = "8" +pciBridge5.present = "TRUE" +pciBridge5.virtualDev = "pcieRootPort" +pciBridge5.functions = "8" +pciBridge6.present = "TRUE" +pciBridge6.virtualDev = "pcieRootPort" +pciBridge6.functions = "8" +pciBridge7.present = "TRUE" +pciBridge7.virtualDev = "pcieRootPort" +pciBridge7.functions = "8" +hpet0.present = "TRUE" +scsi0.pciSlotNumber = "160" +sata0.pciSlotNumber = "33" +vmci0.pciSlotNumber = "32" +ethernet0.pciSlotNumber = "192" +disk.EnableUUID = "TRUE" +migrate.hostLog = "v2v-windows-kkulkarn-1017c46c.hlog" +sched.cpu.min = "0" +sched.cpu.shares = "normal" +sched.mem.min = "0" +sched.mem.minSize = "0" +sched.mem.shares = "normal" +migrate.encryptionMode = "opportunistic" +annotation = "MIQ GUID=b55c806d-99b9-4fa5-bbcc-a4de04f822e5" +cpuid.coresPerSocket = "4" diff --git a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.xml b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.xml new file mode 100644 index 0000000000..f1fe6dd4c9 --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.xml @@ -0,0 +1,37 @@ +<domain type='vmware'> + <name>v2v-windows-kkulkarn</name> + <uuid>42009372-17da-be73-779d-007ccf1bd228</uuid> + <description>MIQ GUID=b55c806d-99b9-4fa5-bbcc-a4de04f822e5</description> + <memory unit='KiB'>16777216</memory> + <currentMemory unit='KiB'>16777216</currentMemory> + <vcpu placement='static'>16</vcpu> + <cputune> + <shares>16000</shares> + </cputune> + <os> + <type arch='x86_64'>hvm</type> + </os> + <cpu> + <topology sockets='4' cores='4' threads='1'/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='[datastore] directory/v2v-windows-kkulkarn.vmdk'/> + <target dev='sda' bus='scsi'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <controller type='scsi' index='0' model='lsisas1068'/> + <interface type='bridge'> + <mac address='00:50:56:80:b3:81'/> + <source bridge='VM Network'/> + <model type='vmxnet3'/> + </interface> + <video> + <model type='vmvga' vram='8192' primary='yes'/> + </video> + </devices> +</domain> diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 319bf345a3..60913b6b11 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -269,6 +269,7 @@ mymain(void) DO_TEST("esx-in-the-wild-6", "esx-in-the-wild-6"); DO_TEST("esx-in-the-wild-7", "esx-in-the-wild-7"); DO_TEST("esx-in-the-wild-8", "esx-in-the-wild-8"); + DO_TEST("esx-in-the-wild-9", "esx-in-the-wild-9"); DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1"); DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2"); -- 2.14.3

When writing the VMX file from the domain XML, write cpuid.coresPerSocket if there is a specified CPU topology in the guest. Use the domain XML of esx-in-the-wild-9 in vmx2xml as testcase for xml2vmxtest. Signed-off-by: Pino Toscano <ptoscano@redhat.com> --- src/vmx/vmx.c | 29 ++++++++++++++++++ tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.vmx | 39 +++++++++++++++++++++++++ tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.xml | 37 +++++++++++++++++++++++ tests/xml2vmxtest.c | 1 + 4 files changed, 106 insertions(+) create mode 100644 tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.vmx create mode 100644 tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.xml diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 939fa840ab..8027a7bba6 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -3246,6 +3246,35 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe virBufferAsprintf(&buffer, "numvcpus = \"%d\"\n", maxvcpus); + if (def->cpu) { + unsigned int calculated_vcpus; + + if (def->cpu->mode != VIR_CPU_MODE_CUSTOM) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Expecting domain XML CPU mode 'custom' but " + "found '%s'"), + virCPUModeTypeToString(def->cpu->mode)); + goto cleanup; + } + + if (def->cpu->threads != 1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Only 1 thread per core is supported")); + goto cleanup; + } + + calculated_vcpus = def->cpu->sockets * def->cpu->cores; + if (calculated_vcpus != maxvcpus) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Expecting domain XML CPU sockets per core as %d " + "but found %d"), + maxvcpus, calculated_vcpus); + goto cleanup; + } + + virBufferAsprintf(&buffer, "cpuid.coresPerSocket = \"%d\"\n", def->cpu->cores); + } + /* def:cpumask -> vmx:sched.cpu.affinity */ if (def->cpumask && virBitmapSize(def->cpumask) > 0) { int bit; diff --git a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.vmx b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.vmx new file mode 100644 index 0000000000..f92650f7ea --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.vmx @@ -0,0 +1,39 @@ +.encoding = "UTF-8" +config.version = "8" +virtualHW.version = "10" +guestOS = "other-64" +uuid.bios = "42 00 93 72 17 da be 73-77 9d 00 7c cf 1b d2 28" +displayName = "v2v-windows-kkulkarn" +annotation = "MIQ GUID=b55c806d-99b9-4fa5-bbcc-a4de04f822e5" +memsize = "16384" +numvcpus = "16" +cpuid.coresPerSocket = "4" +sched.cpu.shares = "normal" +scsi0.present = "true" +scsi0.virtualDev = "lsisas1068" +scsi0:0.present = "true" +scsi0:0.deviceType = "scsi-hardDisk" +scsi0:0.fileName = "/vmfs/volumes/datastore/directory/v2v-windows-kkulkarn.vmdk" +floppy0.present = "false" +floppy1.present = "false" +ethernet0.present = "true" +ethernet0.virtualDev = "vmxnet3" +ethernet0.networkName = "VM Network" +ethernet0.connectionType = "bridged" +ethernet0.addressType = "vpx" +ethernet0.generatedAddress = "00:50:56:80:b3:81" +svga.vramSize = "8388608" +pciBridge0.present = "true" +pciBridge4.present = "true" +pciBridge4.virtualDev = "pcieRootPort" +pciBridge4.functions = "8" +pciBridge5.present = "true" +pciBridge5.virtualDev = "pcieRootPort" +pciBridge5.functions = "8" +pciBridge6.present = "true" +pciBridge6.virtualDev = "pcieRootPort" +pciBridge6.functions = "8" +pciBridge7.present = "true" +pciBridge7.virtualDev = "pcieRootPort" +pciBridge7.functions = "8" +vmci0.present = "true" diff --git a/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.xml b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.xml new file mode 100644 index 0000000000..f1fe6dd4c9 --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.xml @@ -0,0 +1,37 @@ +<domain type='vmware'> + <name>v2v-windows-kkulkarn</name> + <uuid>42009372-17da-be73-779d-007ccf1bd228</uuid> + <description>MIQ GUID=b55c806d-99b9-4fa5-bbcc-a4de04f822e5</description> + <memory unit='KiB'>16777216</memory> + <currentMemory unit='KiB'>16777216</currentMemory> + <vcpu placement='static'>16</vcpu> + <cputune> + <shares>16000</shares> + </cputune> + <os> + <type arch='x86_64'>hvm</type> + </os> + <cpu> + <topology sockets='4' cores='4' threads='1'/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <source file='[datastore] directory/v2v-windows-kkulkarn.vmdk'/> + <target dev='sda' bus='scsi'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <controller type='scsi' index='0' model='lsisas1068'/> + <interface type='bridge'> + <mac address='00:50:56:80:b3:81'/> + <source bridge='VM Network'/> + <model type='vmxnet3'/> + </interface> + <video> + <model type='vmvga' vram='8192' primary='yes'/> + </video> + </devices> +</domain> diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 7b01151974..f6bcd7b012 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -279,6 +279,7 @@ mymain(void) DO_TEST("esx-in-the-wild-5", "esx-in-the-wild-5", 4); DO_TEST("esx-in-the-wild-6", "esx-in-the-wild-6", 4); DO_TEST("esx-in-the-wild-7", "esx-in-the-wild-7", 4); + DO_TEST("esx-in-the-wild-9", "esx-in-the-wild-9", 10); DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1", 4); DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2", 4); -- 2.14.3

On Thu, Apr 19, 2018 at 03:03:36PM +0200, Pino Toscano wrote:
Read/write only cpuid.coresPerSocket for now.
Pino Toscano (2): vmx: convert cpuid.coresPerSocket for CPU topology vmx: write cpuid.coresPerSocket back from CPU topology
src/vmx/vmx.c | 57 ++++++++++++++++++++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml | 3 ++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.vmx | 72 +++++++++++++++++++++++++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.xml | 37 +++++++++++++ tests/vmx2xmltest.c | 1 + tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.vmx | 39 ++++++++++++++ tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.xml | 37 +++++++++++++ tests/xml2vmxtest.c | 1 + 8 files changed, 247 insertions(+) create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.vmx create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.xml create mode 100644 tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.vmx create mode 100644 tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.xml
The code and tests look fine to me, so ACK here. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/

On Thu, Apr 19, 2018 at 03:03:36PM +0200, Pino Toscano wrote:
Read/write only cpuid.coresPerSocket for now.
Pino Toscano (2): vmx: convert cpuid.coresPerSocket for CPU topology vmx: write cpuid.coresPerSocket back from CPU topology
src/vmx/vmx.c | 57 ++++++++++++++++++++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml | 3 ++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.vmx | 72 +++++++++++++++++++++++++ tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.xml | 37 +++++++++++++ tests/vmx2xmltest.c | 1 + tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.vmx | 39 ++++++++++++++ tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.xml | 37 +++++++++++++ tests/xml2vmxtest.c | 1 + 8 files changed, 247 insertions(+) create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.vmx create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-9.xml create mode 100644 tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.vmx create mode 100644 tests/xml2vmxdata/xml2vmx-esx-in-the-wild-9.xml
Reviewed-by: Ján Tomko <jtomko@redhat.com> and pushed Jano
participants (3)
-
Ján Tomko
-
Pino Toscano
-
Richard W.M. Jones