From: Stefan Kober <[email protected]> Parse the user provided cpu topology information and transform it into correct cloud-hypervisor API calls.
On-behalf-of: SAP [email protected] On-behalf-of: SAP [email protected] Signed-off-by: Stefan Kober <[email protected]> Signed-off-by: Thomas Prescher <[email protected]> --- src/ch/ch_monitor.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index bcfff58995..15fded2274 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -69,13 +69,35 @@ virCHMonitorPut(virCHMonitor *mon, domainLogContext *logCtxt, virJSONValue **answer); +static int +virCHMonitorBuildCPUTopologyJSON(virJSONValue *content, + virDomainDef *vmdef) +{ + int rc; + + if ((rc = virDomainDefGetVcpusTopology(vmdef, NULL)) != 0) + return rc; + + if (virJSONValueObjectAdd(&content, + "u:threads_per_core", vmdef->cpu->threads, + "u:cores_per_die", vmdef->cpu->cores, + "u:dies_per_package", vmdef->cpu->dies, + "u:packages", vmdef->cpu->sockets, + NULL) < 0) + return -1; + + return 0; +} + static int virCHMonitorBuildCPUJson(virJSONValue *content, virDomainDef *vmdef) { g_autoptr(virJSONValue) cpus = NULL; + g_autoptr(virJSONValue) topology = virJSONValueNewObject(); unsigned int maxvcpus = 0; unsigned int nvcpus = 0; virDomainVcpuDef *vcpu; + int rc; size_t i; /* count maximum allowed number vcpus and enabled vcpus when boot.*/ @@ -92,6 +114,17 @@ virCHMonitorBuildCPUJson(virJSONValue *content, virDomainDef *vmdef) return -1; if (virJSONValueObjectAppendNumberInt(cpus, "max_vcpus", vmdef->maxvcpus) < 0) return -1; + if ((rc = virCHMonitorBuildCPUTopologyJSON(topology, vmdef)) < 0) + return -1; + + if (rc == 0) { + VIR_DEBUG("Using CPU topology: %u:%u:%u:%u", + vmdef->cpu->sockets, vmdef->cpu->dies, + vmdef->cpu->cores, vmdef->cpu->threads); + if (virJSONValueObjectAppend(cpus, "topology", &topology) < 0) + return -1; + } + if (virJSONValueObjectAppend(content, "cpus", &cpus) < 0) return -1; } -- 2.53.0
