On Thu, Feb 23, 2017 at 03:15:07PM +0100, Jiri Denemark wrote:
Querying "host" CPU model expansion only makes sense for
KVM. QEMU 2.9.0
introduces a new "max" CPU model which can be used to ask QEMU what the
best CPU it can provide to a TCG domain is.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 3:
- s/type/virtType/ in virQEMUCapsLoadHostCPUModelInfo as type variable
was added in the previous patch
Version 2:
- no change
src/qemu/qemu_capabilities.c | 151 ++++++++++++-----
src/qemu/qemu_capabilities.h | 3 +-
src/qemu/qemu_capspriv.h | 3 +-
src/qemu/qemu_command.c | 2 +-
src/qemu/qemu_process.c | 5 +-
.../qemucapabilitiesdata/caps_2.8.0.s390x.replies | 8 +
tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml | 2 +-
.../qemucapabilitiesdata/caps_2.9.0.x86_64.replies | 179 +++++++++++++++++++++
tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml | 172 +++++++++++++++++++-
tests/qemuxml2argvtest.c | 3 +-
10 files changed, 480 insertions(+), 48 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 0b611c323..f31a9ce6e 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -401,13 +401,15 @@ struct _virQEMUCaps {
size_t ngicCapabilities;
virGICCapability *gicCapabilities;
- qemuMonitorCPUModelInfoPtr hostCPUModelInfo;
+ qemuMonitorCPUModelInfoPtr kvmCPUModelInfo;
+ qemuMonitorCPUModelInfoPtr tcgCPUModelInfo;
/* Anything below is not stored in the cache since the values are
* re-computed from the other fields or external data sources every
* time we probe QEMU or load the results from the cache.
*/
- virCPUDefPtr hostCPUModel;
+ virCPUDefPtr kvmCPUModel;
+ virCPUDefPtr tcgCPUModel;
};
struct virQEMUCapsSearchData {
@@ -2164,12 +2166,20 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
goto error;
}
- if (qemuCaps->hostCPUModel &&
- !(ret->hostCPUModel = virCPUDefCopy(qemuCaps->hostCPUModel)))
+ if (qemuCaps->kvmCPUModel &&
+ !(ret->kvmCPUModel = virCPUDefCopy(qemuCaps->kvmCPUModel)))
goto error;
- if (qemuCaps->hostCPUModelInfo &&
- !(ret->hostCPUModelInfo =
qemuMonitorCPUModelInfoCopy(qemuCaps->hostCPUModelInfo)))
+ if (qemuCaps->tcgCPUModel &&
+ !(ret->tcgCPUModel = virCPUDefCopy(qemuCaps->tcgCPUModel)))
+ goto error;
+
+ if (qemuCaps->kvmCPUModelInfo &&
+ !(ret->kvmCPUModelInfo =
qemuMonitorCPUModelInfoCopy(qemuCaps->kvmCPUModelInfo)))
+ goto error;
+
+ if (qemuCaps->tcgCPUModelInfo &&
+ !(ret->tcgCPUModelInfo =
qemuMonitorCPUModelInfoCopy(qemuCaps->tcgCPUModelInfo)))
goto error;
if (VIR_ALLOC_N(ret->machineTypes, qemuCaps->nmachineTypes) < 0)
@@ -2218,8 +2228,10 @@ void virQEMUCapsDispose(void *obj)
VIR_FREE(qemuCaps->gicCapabilities);
- qemuMonitorCPUModelInfoFree(qemuCaps->hostCPUModelInfo);
- virCPUDefFree(qemuCaps->hostCPUModel);
+ qemuMonitorCPUModelInfoFree(qemuCaps->kvmCPUModelInfo);
+ qemuMonitorCPUModelInfoFree(qemuCaps->tcgCPUModelInfo);
+ virCPUDefFree(qemuCaps->kvmCPUModel);
+ virCPUDefFree(qemuCaps->tcgCPUModel);
}
void
@@ -2436,9 +2448,13 @@ virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
virCPUDefPtr
-virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps)
+virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps,
+ virDomainVirtType type)
{
- return qemuCaps->hostCPUModel;
+ if (type == VIR_DOMAIN_VIRT_KVM)
+ return qemuCaps->kvmCPUModel;
+ else
+ return qemuCaps->tcgCPUModel;
}
@@ -2456,7 +2472,7 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch);
case VIR_CPU_MODE_HOST_MODEL:
- return !!qemuCaps->hostCPUModel;
+ return !!virQEMUCapsGetHostModel(qemuCaps, type);
case VIR_CPU_MODE_CUSTOM:
if (type == VIR_DOMAIN_VIRT_KVM)
@@ -2823,14 +2839,24 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
static int
virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
- qemuMonitorPtr mon)
+ qemuMonitorPtr mon,
+ bool tcg)
{
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION) ||
- !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
+ qemuMonitorCPUModelInfoPtr *modelInfo;
+ const char *model;
+
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
return 0;
- return qemuMonitorGetCPUModelExpansion(mon, "static", "host",
- &qemuCaps->hostCPUModelInfo);
+ if (tcg || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
+ modelInfo = &qemuCaps->tcgCPUModelInfo;
+ model = "max";
+ } else {
+ modelInfo = &qemuCaps->kvmCPUModelInfo;
+ model = "host";
+ }
+
+ return qemuMonitorGetCPUModelExpansion(mon, "static", model, modelInfo);
}
struct tpmTypeToCaps {
@@ -3055,12 +3081,16 @@ virQEMUCapsCPUFilterFeatures(const char *name,
*/
static int
virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
+ virDomainVirtType type,
virCPUDefPtr cpu)
{
- qemuMonitorCPUModelInfoPtr modelInfo = qemuCaps->hostCPUModelInfo;
+ qemuMonitorCPUModelInfoPtr modelInfo;
size_t i;
- if (!modelInfo) {
+ if (type != VIR_DOMAIN_VIRT_KVM)
+ return -1;
It would be nice to have some error message in this case as well. Before
this patch the following error would be used because the "hostCPUModelInfo"
would be empty for TCG.
ACK with that fixed
Pavel
+
+ if (!(modelInfo = qemuCaps->kvmCPUModelInfo)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("missing host CPU model info from QEMU capabilities
"
"for binary %s"),