mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
cpu_x86: Compare CPU candidates in a separate function
Splitting the comparison into a separate function makes the code cleaner and easier to update in the future. Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
5b991c44ed
commit
ea51e6a045
@ -1564,6 +1564,43 @@ x86GuestData(virCPUDefPtr host,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checks whether cpuCandidate is a better fit for the CPU data than the
|
||||||
|
* currently selected one from cpuCurrent.
|
||||||
|
*
|
||||||
|
* Returns 0 if cpuCurrent is better,
|
||||||
|
* 1 if cpuCandidate is better,
|
||||||
|
* 2 if cpuCandidate is the best one (search should stop now).
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
x86DecodeUseCandidate(virCPUDefPtr cpuCurrent,
|
||||||
|
virCPUDefPtr cpuCandidate,
|
||||||
|
const char *preferred,
|
||||||
|
bool checkPolicy)
|
||||||
|
{
|
||||||
|
if (checkPolicy) {
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < cpuCandidate->nfeatures; i++) {
|
||||||
|
if (cpuCandidate->features[i].policy == VIR_CPU_FEATURE_DISABLE)
|
||||||
|
return 0;
|
||||||
|
cpuCandidate->features[i].policy = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preferred &&
|
||||||
|
STREQ(cpuCandidate->model, preferred))
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
if (!cpuCurrent)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (cpuCurrent->nfeatures > cpuCandidate->nfeatures)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
x86Decode(virCPUDefPtr cpu,
|
x86Decode(virCPUDefPtr cpu,
|
||||||
const virCPUx86Data *data,
|
const virCPUx86Data *data,
|
||||||
@ -1581,6 +1618,7 @@ x86Decode(virCPUDefPtr cpu,
|
|||||||
virCPUx86Data *features = NULL;
|
virCPUx86Data *features = NULL;
|
||||||
const virCPUx86Data *cpuData = NULL;
|
const virCPUx86Data *cpuData = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
int rc;
|
||||||
|
|
||||||
virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES |
|
virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES |
|
||||||
VIR_CONNECT_BASELINE_CPU_MIGRATABLE, -1);
|
VIR_CONNECT_BASELINE_CPU_MIGRATABLE, -1);
|
||||||
@ -1611,6 +1649,7 @@ x86Decode(virCPUDefPtr cpu,
|
|||||||
|
|
||||||
if (!(cpuCandidate = x86DataToCPU(data, candidate, map)))
|
if (!(cpuCandidate = x86DataToCPU(data, candidate, map)))
|
||||||
goto out;
|
goto out;
|
||||||
|
cpuCandidate->type = cpu->type;
|
||||||
|
|
||||||
if (candidate->vendor && cpuCandidate->vendor &&
|
if (candidate->vendor && cpuCandidate->vendor &&
|
||||||
STRNEQ(candidate->vendor->name, cpuCandidate->vendor)) {
|
STRNEQ(candidate->vendor->name, cpuCandidate->vendor)) {
|
||||||
@ -1621,31 +1660,13 @@ x86Decode(virCPUDefPtr cpu,
|
|||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cpu->type == VIR_CPU_TYPE_HOST) {
|
if ((rc = x86DecodeUseCandidate(cpuModel, cpuCandidate, preferred,
|
||||||
cpuCandidate->type = VIR_CPU_TYPE_HOST;
|
cpu->type == VIR_CPU_TYPE_HOST))) {
|
||||||
for (i = 0; i < cpuCandidate->nfeatures; i++) {
|
|
||||||
switch (cpuCandidate->features[i].policy) {
|
|
||||||
case VIR_CPU_FEATURE_DISABLE:
|
|
||||||
virCPUDefFree(cpuCandidate);
|
|
||||||
goto next;
|
|
||||||
default:
|
|
||||||
cpuCandidate->features[i].policy = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preferred && STREQ(cpuCandidate->model, preferred)) {
|
|
||||||
virCPUDefFree(cpuModel);
|
|
||||||
cpuModel = cpuCandidate;
|
|
||||||
cpuData = candidate->data;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cpuModel == NULL
|
|
||||||
|| cpuModel->nfeatures > cpuCandidate->nfeatures) {
|
|
||||||
virCPUDefFree(cpuModel);
|
virCPUDefFree(cpuModel);
|
||||||
cpuModel = cpuCandidate;
|
cpuModel = cpuCandidate;
|
||||||
cpuData = candidate->data;
|
cpuData = candidate->data;
|
||||||
|
if (rc == 2)
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
virCPUDefFree(cpuCandidate);
|
virCPUDefFree(cpuCandidate);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user