提交 22137d39 编写于 作者: J Jiri Denemark

cpu_x86: Use array of vendors in CPU map

There's no reason for keeping the vendors in a linked list. Especially
when we know upfront the total number of models we are loading.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
上级 6f46bf7f
...@@ -49,8 +49,6 @@ typedef virCPUx86Vendor *virCPUx86VendorPtr; ...@@ -49,8 +49,6 @@ typedef virCPUx86Vendor *virCPUx86VendorPtr;
struct _virCPUx86Vendor { struct _virCPUx86Vendor {
char *name; char *name;
virCPUx86CPUID cpuid; virCPUx86CPUID cpuid;
virCPUx86VendorPtr next;
}; };
typedef struct _virCPUx86Feature virCPUx86Feature; typedef struct _virCPUx86Feature virCPUx86Feature;
...@@ -102,7 +100,8 @@ struct _virCPUx86Model { ...@@ -102,7 +100,8 @@ struct _virCPUx86Model {
typedef struct _virCPUx86Map virCPUx86Map; typedef struct _virCPUx86Map virCPUx86Map;
typedef virCPUx86Map *virCPUx86MapPtr; typedef virCPUx86Map *virCPUx86MapPtr;
struct _virCPUx86Map { struct _virCPUx86Map {
virCPUx86VendorPtr vendors; size_t nvendors;
virCPUx86VendorPtr *vendors;
virCPUx86FeaturePtr features; virCPUx86FeaturePtr features;
size_t nmodels; size_t nmodels;
virCPUx86ModelPtr *models; virCPUx86ModelPtr *models;
...@@ -433,16 +432,16 @@ static virCPUx86VendorPtr ...@@ -433,16 +432,16 @@ static virCPUx86VendorPtr
x86DataToVendor(const virCPUx86Data *data, x86DataToVendor(const virCPUx86Data *data,
virCPUx86MapPtr map) virCPUx86MapPtr map)
{ {
virCPUx86VendorPtr vendor = map->vendors;
virCPUx86CPUID *cpuid; virCPUx86CPUID *cpuid;
size_t i;
while (vendor) { for (i = 0; i < map->nvendors; i++) {
virCPUx86VendorPtr vendor = map->vendors[i];
if ((cpuid = x86DataCpuid(data, vendor->cpuid.function)) && if ((cpuid = x86DataCpuid(data, vendor->cpuid.function)) &&
x86cpuidMatchMasked(cpuid, &vendor->cpuid)) { x86cpuidMatchMasked(cpuid, &vendor->cpuid)) {
x86cpuidClearBits(cpuid, &vendor->cpuid); x86cpuidClearBits(cpuid, &vendor->cpuid);
return vendor; return vendor;
} }
vendor = vendor->next;
} }
return NULL; return NULL;
...@@ -506,14 +505,11 @@ static virCPUx86VendorPtr ...@@ -506,14 +505,11 @@ static virCPUx86VendorPtr
x86VendorFind(virCPUx86MapPtr map, x86VendorFind(virCPUx86MapPtr map,
const char *name) const char *name)
{ {
virCPUx86VendorPtr vendor; size_t i;
vendor = map->vendors;
while (vendor) {
if (STREQ(vendor->name, name))
return vendor;
vendor = vendor->next; for (i = 0; i < map->nvendors; i++) {
if (STREQ(map->vendors[i]->name, name))
return map->vendors[i];
} }
return NULL; return NULL;
...@@ -562,9 +558,8 @@ x86VendorLoad(xmlXPathContextPtr ctxt, ...@@ -562,9 +558,8 @@ x86VendorLoad(xmlXPathContextPtr ctxt,
vendor->cpuid.edx = virReadBufInt32LE(string + 4); vendor->cpuid.edx = virReadBufInt32LE(string + 4);
vendor->cpuid.ecx = virReadBufInt32LE(string + 8); vendor->cpuid.ecx = virReadBufInt32LE(string + 8);
vendor->next = map->vendors; if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0)
map->vendors = vendor; goto cleanup;
vendor = NULL;
ret = 0; ret = 0;
...@@ -1121,11 +1116,9 @@ x86MapFree(virCPUx86MapPtr map) ...@@ -1121,11 +1116,9 @@ x86MapFree(virCPUx86MapPtr map)
x86ModelFree(map->models[i]); x86ModelFree(map->models[i]);
VIR_FREE(map->models); VIR_FREE(map->models);
while (map->vendors) { for (i = 0; i < map->nvendors; i++)
virCPUx86VendorPtr vendor = map->vendors; x86VendorFree(map->vendors[i]);
map->vendors = vendor->next; VIR_FREE(map->vendors);
x86VendorFree(vendor);
}
while (map->migrate_blockers) { while (map->migrate_blockers) {
virCPUx86FeaturePtr migrate_blocker = map->migrate_blockers; virCPUx86FeaturePtr migrate_blocker = map->migrate_blockers;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册