cpu_x86: Make x86cpuidMatch more general

The function now works on virCPUx86DataItem and it's called
virCPUx86DataItemMatch.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Jiri Denemark 2019-03-15 19:57:59 +01:00
parent 2eea67a98e
commit 10b80165db
1 changed files with 10 additions and 11 deletions

View File

@ -37,8 +37,6 @@ VIR_LOG_INIT("cpu.cpu_x86");
#define VENDOR_STRING_LENGTH 12 #define VENDOR_STRING_LENGTH 12
static const virCPUx86CPUID cpuidNull = { 0 };
static const virArch archs[] = { VIR_ARCH_I686, VIR_ARCH_X86_64 }; static const virArch archs[] = { VIR_ARCH_I686, VIR_ARCH_X86_64 };
typedef struct _virCPUx86Vendor virCPUx86Vendor; typedef struct _virCPUx86Vendor virCPUx86Vendor;
@ -194,13 +192,13 @@ struct _virCPUx86DataIterator {
static bool static bool
x86cpuidMatch(const virCPUx86CPUID *cpuid1, virCPUx86DataItemMatch(const virCPUx86DataItem *item1,
const virCPUx86CPUID *cpuid2) const virCPUx86DataItem *item2)
{ {
return (cpuid1->eax == cpuid2->eax && return (item1->cpuid.eax == item2->cpuid.eax &&
cpuid1->ebx == cpuid2->ebx && item1->cpuid.ebx == item2->cpuid.ebx &&
cpuid1->ecx == cpuid2->ecx && item1->cpuid.ecx == item2->cpuid.ecx &&
cpuid1->edx == cpuid2->edx); item1->cpuid.edx == item2->cpuid.edx);
} }
@ -319,6 +317,7 @@ static virCPUx86DataItemPtr
virCPUx86DataNext(virCPUx86DataIteratorPtr iterator) virCPUx86DataNext(virCPUx86DataIteratorPtr iterator)
{ {
const virCPUx86Data *data = iterator->data; const virCPUx86Data *data = iterator->data;
virCPUx86DataItem zero = { 0 };
if (!data) if (!data)
return NULL; return NULL;
@ -326,7 +325,7 @@ virCPUx86DataNext(virCPUx86DataIteratorPtr iterator)
while (++iterator->pos < data->len) { while (++iterator->pos < data->len) {
virCPUx86DataItemPtr item = data->items + iterator->pos; virCPUx86DataItemPtr item = data->items + iterator->pos;
if (!x86cpuidMatch(&item->cpuid, &cpuidNull)) if (!virCPUx86DataItemMatch(item, &zero))
return item; return item;
} }
@ -1156,7 +1155,7 @@ x86ModelCompare(virCPUx86ModelPtr model1,
virCPUx86CompareResult match = SUPERSET; virCPUx86CompareResult match = SUPERSET;
if ((item2 = virCPUx86DataGet(&model2->data, item1))) { if ((item2 = virCPUx86DataGet(&model2->data, item1))) {
if (x86cpuidMatch(&item1->cpuid, &item2->cpuid)) if (virCPUx86DataItemMatch(item1, item2))
continue; continue;
else if (!virCPUx86DataItemMatchMasked(item1, item2)) else if (!virCPUx86DataItemMatchMasked(item1, item2))
match = SUBSET; match = SUBSET;
@ -1172,7 +1171,7 @@ x86ModelCompare(virCPUx86ModelPtr model1,
virCPUx86CompareResult match = SUBSET; virCPUx86CompareResult match = SUBSET;
if ((item1 = virCPUx86DataGet(&model1->data, item2))) { if ((item1 = virCPUx86DataGet(&model1->data, item2))) {
if (x86cpuidMatch(&item2->cpuid, &item1->cpuid)) if (virCPUx86DataItemMatch(item2, item1))
continue; continue;
else if (!virCPUx86DataItemMatchMasked(item2, item1)) else if (!virCPUx86DataItemMatchMasked(item2, item1))
match = SUPERSET; match = SUPERSET;