提交 17924643 编写于 作者: J Jiri Denemark

cpu_x86: Check vendor early

When searching for the best CPU model for CPUID data we can easily
ignore models with non-matching vendor before spending time on CPUID
data to virCPUDef conversion.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
上级 1cc9a1d0
...@@ -431,7 +431,7 @@ x86DataToCPUFeatures(virCPUDefPtr cpu, ...@@ -431,7 +431,7 @@ x86DataToCPUFeatures(virCPUDefPtr cpu,
/* also removes bits corresponding to vendor string from data */ /* also removes bits corresponding to vendor string from data */
static virCPUx86VendorPtr static virCPUx86VendorPtr
x86DataToVendor(virCPUx86Data *data, x86DataToVendor(const virCPUx86Data *data,
virCPUx86MapPtr map) virCPUx86MapPtr map)
{ {
virCPUx86VendorPtr vendor = map->vendors; virCPUx86VendorPtr vendor = map->vendors;
...@@ -1591,6 +1591,7 @@ x86Decode(virCPUDefPtr cpu, ...@@ -1591,6 +1591,7 @@ x86Decode(virCPUDefPtr cpu,
virCPUx86Data *copy = NULL; virCPUx86Data *copy = NULL;
virCPUx86Data *features = NULL; virCPUx86Data *features = NULL;
const virCPUx86Data *cpuData = NULL; const virCPUx86Data *cpuData = NULL;
virCPUx86VendorPtr vendor;
size_t i; size_t i;
int rc; int rc;
...@@ -1600,6 +1601,8 @@ x86Decode(virCPUDefPtr cpu, ...@@ -1600,6 +1601,8 @@ x86Decode(virCPUDefPtr cpu,
if (!data || !(map = virCPUx86GetMap())) if (!data || !(map = virCPUx86GetMap()))
return -1; return -1;
vendor = x86DataToVendor(data, map);
for (candidate = map->models; candidate; candidate = candidate->next) { for (candidate = map->models; candidate; candidate = candidate->next) {
if (!cpuModelIsAllowed(candidate->name, models, nmodels)) { if (!cpuModelIsAllowed(candidate->name, models, nmodels)) {
if (preferred && STREQ(candidate->name, preferred)) { if (preferred && STREQ(candidate->name, preferred)) {
...@@ -1620,19 +1623,19 @@ x86Decode(virCPUDefPtr cpu, ...@@ -1620,19 +1623,19 @@ x86Decode(virCPUDefPtr cpu,
continue; continue;
} }
if (!(cpuCandidate = x86DataToCPU(data, candidate, map))) /* Both vendor and candidate->vendor are pointers to a single list of
goto cleanup; * known vendors stored in the map.
cpuCandidate->type = cpu->type; */
if (vendor && candidate->vendor && vendor != candidate->vendor) {
if (candidate->vendor && cpuCandidate->vendor &&
STRNEQ(candidate->vendor->name, cpuCandidate->vendor)) {
VIR_DEBUG("CPU vendor %s of model %s differs from %s; ignoring", VIR_DEBUG("CPU vendor %s of model %s differs from %s; ignoring",
candidate->vendor->name, candidate->name, candidate->vendor->name, candidate->name, vendor->name);
cpuCandidate->vendor);
virCPUDefFree(cpuCandidate);
continue; continue;
} }
if (!(cpuCandidate = x86DataToCPU(data, candidate, map)))
goto cleanup;
cpuCandidate->type = cpu->type;
if ((rc = x86DecodeUseCandidate(cpuModel, cpuCandidate, preferred, if ((rc = x86DecodeUseCandidate(cpuModel, cpuCandidate, preferred,
cpu->type == VIR_CPU_TYPE_HOST))) { cpu->type == VIR_CPU_TYPE_HOST))) {
virCPUDefFree(cpuModel); virCPUDefFree(cpuModel);
...@@ -1677,8 +1680,10 @@ x86Decode(virCPUDefPtr cpu, ...@@ -1677,8 +1680,10 @@ x86Decode(virCPUDefPtr cpu,
goto cleanup; goto cleanup;
} }
if (vendor && VIR_STRDUP(cpu->vendor, vendor->name) < 0)
goto cleanup;
cpu->model = cpuModel->model; cpu->model = cpuModel->model;
cpu->vendor = cpuModel->vendor;
cpu->nfeatures = cpuModel->nfeatures; cpu->nfeatures = cpuModel->nfeatures;
cpu->features = cpuModel->features; cpu->features = cpuModel->features;
VIR_FREE(cpuModel); VIR_FREE(cpuModel);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册