domcaps: Add CPU usable flag

In case a hypervisor is able to tell us a list of supported CPU models
and whether each CPU models can be used on the current host, we can
propagate this to domain capabilities. This is a better alternative
to calling virConnectCompareCPU for each supported CPU model.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2016-06-15 16:15:44 +02:00
parent 33f9ccc141
commit d4c007e6d5
14 changed files with 213 additions and 168 deletions

View File

@ -156,9 +156,9 @@
&lt;mode name='host-passthrough' supported='yes'/&gt;
&lt;mode name='host-model' supported='yes'/&gt;
&lt;mode name='custom' supported='yes'&gt;
&lt;model&gt;Broadwell&lt;/model&gt;
&lt;model&gt;Broadwell-noTSX&lt;/model&gt;
&lt;model&gt;Haswell&lt;/model&gt;
&lt;model usable='no'&gt;Broadwell&lt;/model&gt;
&lt;model usable='yes'&gt;Broadwell-noTSX&lt;/model&gt;
&lt;model usable='no'&gt;Haswell&lt;/model&gt;
...
&lt;/mode&gt;
&lt;/cpu&gt;
@ -183,6 +183,10 @@
<dd>
The <code>mode</code> element contains a list of supported CPU
models, each described by a dedicated <code>model</code> element.
The <code>usable</code> attribute specifies whether the model can
be used on the host. A special value <code>unknown</code> indicates
libvirt does not have enough information to provide the usability
data.
</dd>
</dl>

View File

@ -105,6 +105,13 @@
<ref name='supported'/>
<zeroOrMore>
<element name='model'>
<attribute name='usable'>
<choice>
<value>yes</value>
<value>no</value>
<value>unknown</value>
</choice>
</attribute>
<text/>
</element>
</zeroOrMore>

View File

@ -29,6 +29,9 @@
#define VIR_FROM_THIS VIR_FROM_CAPABILITIES
VIR_ENUM_IMPL(virDomainCapsCPUUsable, VIR_DOMCAPS_CPU_USABLE_LAST,
"unknown", "yes", "no");
static virClassPtr virDomainCapsClass;
static virClassPtr virDomainCapsCPUModelsClass;
@ -157,7 +160,9 @@ virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr old)
return NULL;
for (i = 0; i < old->nmodels; i++) {
if (virDomainCapsCPUModelsAdd(cpuModels, old->models[i].name, -1) < 0)
if (virDomainCapsCPUModelsAdd(cpuModels,
old->models[i].name, -1,
old->models[i].usable) < 0)
goto error;
}
@ -184,7 +189,8 @@ virDomainCapsCPUModelsFilter(virDomainCapsCPUModelsPtr old,
continue;
if (virDomainCapsCPUModelsAdd(cpuModels,
old->models[i].name, -1) < 0)
old->models[i].name, -1,
old->models[i].usable) < 0)
goto error;
}
@ -198,13 +204,16 @@ virDomainCapsCPUModelsFilter(virDomainCapsCPUModelsPtr old,
int
virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
char **name)
char **name,
virDomainCapsCPUUsable usable)
{
if (VIR_RESIZE_N(cpuModels->models, cpuModels->nmodels_max,
cpuModels->nmodels, 1) < 0)
return -1;
VIR_STEAL_PTR(cpuModels->models[cpuModels->nmodels++].name, *name);
cpuModels->models[cpuModels->nmodels].usable = usable;
VIR_STEAL_PTR(cpuModels->models[cpuModels->nmodels].name, *name);
cpuModels->nmodels++;
return 0;
}
@ -212,14 +221,15 @@ virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
int
virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr cpuModels,
const char *name,
ssize_t nameLen)
ssize_t nameLen,
virDomainCapsCPUUsable usable)
{
char *copy = NULL;
if (VIR_STRNDUP(copy, name, nameLen) < 0)
goto error;
if (virDomainCapsCPUModelsAddSteal(cpuModels, &copy) < 0)
if (virDomainCapsCPUModelsAddSteal(cpuModels, &copy, usable) < 0)
goto error;
return 0;
@ -372,8 +382,10 @@ virDomainCapsCPUCustomFormat(virBufferPtr buf,
virBufferAdjustIndent(buf, 2);
for (i = 0; i < custom->nmodels; i++) {
virBufferAsprintf(buf, "<model>%s</model>\n",
custom->models[i].name);
virDomainCapsCPUModelPtr model = custom->models + i;
virBufferAsprintf(buf, "<model usable='%s'>%s</model>\n",
virDomainCapsCPUUsableTypeToString(model->usable),
model->name);
}
virBufferAdjustIndent(buf, -2);

View File

@ -102,10 +102,20 @@ struct _virDomainCapsFeatureGIC {
virDomainCapsEnum version; /* Info about virGICVersion */
};
typedef enum {
VIR_DOMCAPS_CPU_USABLE_UNKNOWN,
VIR_DOMCAPS_CPU_USABLE_YES,
VIR_DOMCAPS_CPU_USABLE_NO,
VIR_DOMCAPS_CPU_USABLE_LAST
} virDomainCapsCPUUsable;
VIR_ENUM_DECL(virDomainCapsCPUUsable);
typedef struct _virDomainCapsCPUModel virDomainCapsCPUModel;
typedef virDomainCapsCPUModel *virDomainCapsCPUModelPtr;
struct _virDomainCapsCPUModel {
char *name;
virDomainCapsCPUUsable usable;
};
typedef struct _virDomainCapsCPUModels virDomainCapsCPUModels;
@ -159,10 +169,12 @@ virDomainCapsCPUModelsPtr virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr o
virDomainCapsCPUModelsPtr virDomainCapsCPUModelsFilter(virDomainCapsCPUModelsPtr old,
const char **models);
int virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
char **name);
char **name,
virDomainCapsCPUUsable usable);
int virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr cpuModels,
const char *name,
ssize_t nameLen);
ssize_t nameLen,
virDomainCapsCPUUsable usable);
# define VIR_DOMAIN_CAPS_ENUM_SET(capsEnum, ...) \
do { \

View File

@ -158,6 +158,8 @@ virDomainCapsCPUModelsAddSteal;
virDomainCapsCPUModelsCopy;
virDomainCapsCPUModelsFilter;
virDomainCapsCPUModelsNew;
virDomainCapsCPUUsableTypeFromString;
virDomainCapsCPUUsableTypeToString;
virDomainCapsEnumClear;
virDomainCapsEnumSet;
virDomainCapsFormat;

View File

@ -671,7 +671,8 @@ virQEMUCapsParseX86Models(const char *output,
len -= 2;
}
if (virDomainCapsCPUModelsAdd(cpus, p, len) < 0)
if (virDomainCapsCPUModelsAdd(cpus, p, len,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
goto error;
} while ((p = next));
@ -719,7 +720,8 @@ virQEMUCapsParsePPCModels(const char *output,
if (*p == '\n')
continue;
if (virDomainCapsCPUModelsAdd(cpus, p, t - p - 1) < 0)
if (virDomainCapsCPUModelsAdd(cpus, p, t - p - 1,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
goto error;
} while ((p = next));
@ -2306,7 +2308,8 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
return -1;
for (i = 0; i < count; i++) {
if (virDomainCapsCPUModelsAdd(qemuCaps->cpuDefinitions, name[i], -1) < 0)
if (virDomainCapsCPUModelsAdd(qemuCaps->cpuDefinitions, name[i], -1,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
return -1;
}
@ -2674,7 +2677,8 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
for (i = 0; i < ncpus; i++) {
if (virDomainCapsCPUModelsAddSteal(qemuCaps->cpuDefinitions,
&cpus[i]->name) < 0)
&cpus[i]->name,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
goto cleanup;
}
@ -3041,7 +3045,8 @@ virQEMUCapsLoadCache(virQEMUCapsPtr qemuCaps, const char *filename,
}
if (virDomainCapsCPUModelsAddSteal(qemuCaps->cpuDefinitions,
&str) < 0)
&str,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
goto cleanup;
}
}

View File

@ -23,9 +23,9 @@
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='custom' supported='yes'>
<model>Model1</model>
<model>Model2</model>
<model>Model3</model>
<model usable='unknown'>Model1</model>
<model usable='no'>Model2</model>
<model usable='yes'>Model3</model>
</mode>
</cpu>
<devices>

View File

@ -22,30 +22,30 @@
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='custom' supported='yes'>
<model>Opteron_G5</model>
<model>Opteron_G4</model>
<model>Opteron_G3</model>
<model>Opteron_G2</model>
<model>Opteron_G1</model>
<model>Haswell</model>
<model>SandyBridge</model>
<model>Westmere</model>
<model>Nehalem</model>
<model>Penryn</model>
<model>Conroe</model>
<model>n270</model>
<model>athlon</model>
<model>pentium3</model>
<model>pentium2</model>
<model>pentium</model>
<model>486</model>
<model>coreduo</model>
<model>kvm32</model>
<model>qemu32</model>
<model>kvm64</model>
<model>core2duo</model>
<model>phenom</model>
<model>qemu64</model>
<model usable='unknown'>Opteron_G5</model>
<model usable='unknown'>Opteron_G4</model>
<model usable='unknown'>Opteron_G3</model>
<model usable='unknown'>Opteron_G2</model>
<model usable='unknown'>Opteron_G1</model>
<model usable='unknown'>Haswell</model>
<model usable='unknown'>SandyBridge</model>
<model usable='unknown'>Westmere</model>
<model usable='unknown'>Nehalem</model>
<model usable='unknown'>Penryn</model>
<model usable='unknown'>Conroe</model>
<model usable='unknown'>n270</model>
<model usable='unknown'>athlon</model>
<model usable='unknown'>pentium3</model>
<model usable='unknown'>pentium2</model>
<model usable='unknown'>pentium</model>
<model usable='unknown'>486</model>
<model usable='unknown'>coreduo</model>
<model usable='unknown'>kvm32</model>
<model usable='unknown'>qemu32</model>
<model usable='unknown'>kvm64</model>
<model usable='unknown'>core2duo</model>
<model usable='unknown'>phenom</model>
<model usable='unknown'>qemu64</model>
</mode>
</cpu>
<devices>

View File

@ -22,36 +22,36 @@
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='custom' supported='yes'>
<model>pxa262</model>
<model>pxa270-a0</model>
<model>arm1136</model>
<model>cortex-a15</model>
<model>pxa260</model>
<model>arm1136-r2</model>
<model>pxa261</model>
<model>pxa255</model>
<model>arm926</model>
<model>arm11mpcore</model>
<model>pxa250</model>
<model>ti925t</model>
<model>cortex-a57</model>
<model>sa1110</model>
<model>arm1176</model>
<model>cortex-a53</model>
<model>sa1100</model>
<model>pxa270-c5</model>
<model>cortex-a9</model>
<model>cortex-a8</model>
<model>pxa270-c0</model>
<model>arm1026</model>
<model>pxa270-b1</model>
<model>cortex-m3</model>
<model>cortex-m4</model>
<model>pxa270-b0</model>
<model>arm946</model>
<model>cortex-r5</model>
<model>pxa270-a1</model>
<model>pxa270</model>
<model usable='unknown'>pxa262</model>
<model usable='unknown'>pxa270-a0</model>
<model usable='unknown'>arm1136</model>
<model usable='unknown'>cortex-a15</model>
<model usable='unknown'>pxa260</model>
<model usable='unknown'>arm1136-r2</model>
<model usable='unknown'>pxa261</model>
<model usable='unknown'>pxa255</model>
<model usable='unknown'>arm926</model>
<model usable='unknown'>arm11mpcore</model>
<model usable='unknown'>pxa250</model>
<model usable='unknown'>ti925t</model>
<model usable='unknown'>cortex-a57</model>
<model usable='unknown'>sa1110</model>
<model usable='unknown'>arm1176</model>
<model usable='unknown'>cortex-a53</model>
<model usable='unknown'>sa1100</model>
<model usable='unknown'>pxa270-c5</model>
<model usable='unknown'>cortex-a9</model>
<model usable='unknown'>cortex-a8</model>
<model usable='unknown'>pxa270-c0</model>
<model usable='unknown'>arm1026</model>
<model usable='unknown'>pxa270-b1</model>
<model usable='unknown'>cortex-m3</model>
<model usable='unknown'>cortex-m4</model>
<model usable='unknown'>pxa270-b0</model>
<model usable='unknown'>arm946</model>
<model usable='unknown'>cortex-r5</model>
<model usable='unknown'>pxa270-a1</model>
<model usable='unknown'>pxa270</model>
</mode>
</cpu>
<devices>

View File

@ -22,36 +22,36 @@
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='custom' supported='yes'>
<model>pxa262</model>
<model>pxa270-a0</model>
<model>arm1136</model>
<model>cortex-a15</model>
<model>pxa260</model>
<model>arm1136-r2</model>
<model>pxa261</model>
<model>pxa255</model>
<model>arm926</model>
<model>arm11mpcore</model>
<model>pxa250</model>
<model>ti925t</model>
<model>cortex-a57</model>
<model>sa1110</model>
<model>arm1176</model>
<model>cortex-a53</model>
<model>sa1100</model>
<model>pxa270-c5</model>
<model>cortex-a9</model>
<model>cortex-a8</model>
<model>pxa270-c0</model>
<model>arm1026</model>
<model>pxa270-b1</model>
<model>cortex-m3</model>
<model>cortex-m4</model>
<model>pxa270-b0</model>
<model>arm946</model>
<model>cortex-r5</model>
<model>pxa270-a1</model>
<model>pxa270</model>
<model usable='unknown'>pxa262</model>
<model usable='unknown'>pxa270-a0</model>
<model usable='unknown'>arm1136</model>
<model usable='unknown'>cortex-a15</model>
<model usable='unknown'>pxa260</model>
<model usable='unknown'>arm1136-r2</model>
<model usable='unknown'>pxa261</model>
<model usable='unknown'>pxa255</model>
<model usable='unknown'>arm926</model>
<model usable='unknown'>arm11mpcore</model>
<model usable='unknown'>pxa250</model>
<model usable='unknown'>ti925t</model>
<model usable='unknown'>cortex-a57</model>
<model usable='unknown'>sa1110</model>
<model usable='unknown'>arm1176</model>
<model usable='unknown'>cortex-a53</model>
<model usable='unknown'>sa1100</model>
<model usable='unknown'>pxa270-c5</model>
<model usable='unknown'>cortex-a9</model>
<model usable='unknown'>cortex-a8</model>
<model usable='unknown'>pxa270-c0</model>
<model usable='unknown'>arm1026</model>
<model usable='unknown'>pxa270-b1</model>
<model usable='unknown'>cortex-m3</model>
<model usable='unknown'>cortex-m4</model>
<model usable='unknown'>pxa270-b0</model>
<model usable='unknown'>arm946</model>
<model usable='unknown'>cortex-r5</model>
<model usable='unknown'>pxa270-a1</model>
<model usable='unknown'>pxa270</model>
</mode>
</cpu>
<devices>

View File

@ -22,36 +22,36 @@
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='custom' supported='yes'>
<model>pxa262</model>
<model>pxa270-a0</model>
<model>arm1136</model>
<model>cortex-a15</model>
<model>pxa260</model>
<model>arm1136-r2</model>
<model>pxa261</model>
<model>pxa255</model>
<model>arm926</model>
<model>arm11mpcore</model>
<model>pxa250</model>
<model>ti925t</model>
<model>cortex-a57</model>
<model>sa1110</model>
<model>arm1176</model>
<model>cortex-a53</model>
<model>sa1100</model>
<model>pxa270-c5</model>
<model>cortex-a9</model>
<model>cortex-a8</model>
<model>pxa270-c0</model>
<model>arm1026</model>
<model>pxa270-b1</model>
<model>cortex-m3</model>
<model>cortex-m4</model>
<model>pxa270-b0</model>
<model>arm946</model>
<model>cortex-r5</model>
<model>pxa270-a1</model>
<model>pxa270</model>
<model usable='unknown'>pxa262</model>
<model usable='unknown'>pxa270-a0</model>
<model usable='unknown'>arm1136</model>
<model usable='unknown'>cortex-a15</model>
<model usable='unknown'>pxa260</model>
<model usable='unknown'>arm1136-r2</model>
<model usable='unknown'>pxa261</model>
<model usable='unknown'>pxa255</model>
<model usable='unknown'>arm926</model>
<model usable='unknown'>arm11mpcore</model>
<model usable='unknown'>pxa250</model>
<model usable='unknown'>ti925t</model>
<model usable='unknown'>cortex-a57</model>
<model usable='unknown'>sa1110</model>
<model usable='unknown'>arm1176</model>
<model usable='unknown'>cortex-a53</model>
<model usable='unknown'>sa1100</model>
<model usable='unknown'>pxa270-c5</model>
<model usable='unknown'>cortex-a9</model>
<model usable='unknown'>cortex-a8</model>
<model usable='unknown'>pxa270-c0</model>
<model usable='unknown'>arm1026</model>
<model usable='unknown'>pxa270-b1</model>
<model usable='unknown'>cortex-m3</model>
<model usable='unknown'>cortex-m4</model>
<model usable='unknown'>pxa270-b0</model>
<model usable='unknown'>arm946</model>
<model usable='unknown'>cortex-r5</model>
<model usable='unknown'>pxa270-a1</model>
<model usable='unknown'>pxa270</model>
</mode>
</cpu>
<devices>

View File

@ -22,8 +22,8 @@
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='custom' supported='yes'>
<model>POWER8</model>
<model>POWER7</model>
<model usable='unknown'>POWER8</model>
<model usable='unknown'>POWER7</model>
</mode>
</cpu>
<devices>

View File

@ -22,34 +22,34 @@
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='custom' supported='yes'>
<model>Opteron_G5</model>
<model>Opteron_G4</model>
<model>Opteron_G3</model>
<model>Opteron_G2</model>
<model>Opteron_G1</model>
<model>Broadwell</model>
<model>Broadwell-noTSX</model>
<model>Haswell</model>
<model>Haswell-noTSX</model>
<model>IvyBridge</model>
<model>SandyBridge</model>
<model>Westmere</model>
<model>Nehalem</model>
<model>Penryn</model>
<model>Conroe</model>
<model>n270</model>
<model>athlon</model>
<model>pentium3</model>
<model>pentium2</model>
<model>pentium</model>
<model>486</model>
<model>coreduo</model>
<model>kvm32</model>
<model>qemu32</model>
<model>kvm64</model>
<model>core2duo</model>
<model>phenom</model>
<model>qemu64</model>
<model usable='unknown'>Opteron_G5</model>
<model usable='unknown'>Opteron_G4</model>
<model usable='unknown'>Opteron_G3</model>
<model usable='unknown'>Opteron_G2</model>
<model usable='unknown'>Opteron_G1</model>
<model usable='unknown'>Broadwell</model>
<model usable='unknown'>Broadwell-noTSX</model>
<model usable='unknown'>Haswell</model>
<model usable='unknown'>Haswell-noTSX</model>
<model usable='unknown'>IvyBridge</model>
<model usable='unknown'>SandyBridge</model>
<model usable='unknown'>Westmere</model>
<model usable='unknown'>Nehalem</model>
<model usable='unknown'>Penryn</model>
<model usable='unknown'>Conroe</model>
<model usable='unknown'>n270</model>
<model usable='unknown'>athlon</model>
<model usable='unknown'>pentium3</model>
<model usable='unknown'>pentium2</model>
<model usable='unknown'>pentium</model>
<model usable='unknown'>486</model>
<model usable='unknown'>coreduo</model>
<model usable='unknown'>kvm32</model>
<model usable='unknown'>qemu32</model>
<model usable='unknown'>kvm64</model>
<model usable='unknown'>core2duo</model>
<model usable='unknown'>phenom</model>
<model usable='unknown'>qemu64</model>
</mode>
</cpu>
<devices>

View File

@ -81,9 +81,12 @@ fillAllCaps(virDomainCapsPtr domCaps)
cpu->hostPassthrough = true;
cpu->hostModel = true;
if (!(cpu->custom = virDomainCapsCPUModelsNew(3)) ||
virDomainCapsCPUModelsAdd(cpu->custom, "Model1", -1) < 0 ||
virDomainCapsCPUModelsAdd(cpu->custom, "Model2", -1) < 0 ||
virDomainCapsCPUModelsAdd(cpu->custom, "Model3", -1) < 0)
virDomainCapsCPUModelsAdd(cpu->custom, "Model1", -1,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 ||
virDomainCapsCPUModelsAdd(cpu->custom, "Model2", -1,
VIR_DOMCAPS_CPU_USABLE_NO) < 0 ||
virDomainCapsCPUModelsAdd(cpu->custom, "Model3", -1,
VIR_DOMCAPS_CPU_USABLE_YES) < 0)
return -1;
disk->supported = true;