use virBitmap to store cells' cpumask info.

This commit is contained in:
Hu Tao 2012-09-14 15:47:02 +08:00 committed by Laine Stump
parent ee7d23ba4b
commit f4b2dcf550
3 changed files with 15 additions and 48 deletions

View File

@ -83,7 +83,7 @@ virCPUDefFree(virCPUDefPtr def)
virCPUDefFreeModel(def); virCPUDefFreeModel(def);
for (i = 0 ; i < def->ncells ; i++) { for (i = 0 ; i < def->ncells ; i++) {
VIR_FREE(def->cells[i].cpumask); virBitmapFree(def->cells[i].cpumask);
VIR_FREE(def->cells[i].cpustr); VIR_FREE(def->cells[i].cpustr);
} }
VIR_FREE(def->cells); VIR_FREE(def->cells);
@ -164,11 +164,10 @@ virCPUDefCopy(const virCPUDefPtr cpu)
copy->cells[i].cellid = cpu->cells[i].cellid; copy->cells[i].cellid = cpu->cells[i].cellid;
copy->cells[i].mem = cpu->cells[i].mem; copy->cells[i].mem = cpu->cells[i].mem;
if (VIR_ALLOC_N(copy->cells[i].cpumask, copy->cells[i].cpumask = virBitmapNewCopy(cpu->cells[i].cpumask);
VIR_DOMAIN_CPUMASK_LEN) < 0)
if (!copy->cells[i].cpumask)
goto no_memory; goto no_memory;
memcpy(copy->cells[i].cpumask, cpu->cells[i].cpumask,
VIR_DOMAIN_CPUMASK_LEN);
if (!(copy->cells[i].cpustr = strdup(cpu->cells[i].cpustr))) if (!(copy->cells[i].cpustr = strdup(cpu->cells[i].cpustr)))
goto no_memory; goto no_memory;
@ -454,7 +453,6 @@ virCPUDefParseXML(const xmlNodePtr node,
for (i = 0 ; i < n ; i++) { for (i = 0 ; i < n ; i++) {
char *cpus, *memory; char *cpus, *memory;
int cpumasklen = VIR_DOMAIN_CPUMASK_LEN;
int ret, ncpus = 0; int ret, ncpus = 0;
def->cells[i].cellid = i; def->cells[i].cellid = i;
@ -466,11 +464,8 @@ virCPUDefParseXML(const xmlNodePtr node,
} }
def->cells[i].cpustr = cpus; def->cells[i].cpustr = cpus;
if (VIR_ALLOC_N(def->cells[i].cpumask, cpumasklen) < 0) ncpus = virBitmapParse(cpus, 0, &def->cells[i].cpumask,
goto no_memory; VIR_DOMAIN_CPUMASK_LEN);
ncpus = virDomainCpuSetParse(cpus, 0, def->cells[i].cpumask,
cpumasklen);
if (ncpus <= 0) if (ncpus <= 0)
goto error; goto error;
def->cells_cpus += ncpus; def->cells_cpus += ncpus;

View File

@ -27,6 +27,7 @@
# include "util.h" # include "util.h"
# include "buf.h" # include "buf.h"
# include "xml.h" # include "xml.h"
# include "bitmap.h"
# define VIR_CPU_VENDOR_ID_LENGTH 12 # define VIR_CPU_VENDOR_ID_LENGTH 12
@ -92,7 +93,7 @@ typedef struct _virCellDef virCellDef;
typedef virCellDef *virCellDefPtr; typedef virCellDef *virCellDefPtr;
struct _virCellDef { struct _virCellDef {
int cellid; int cellid;
char *cpumask; /* CPUs that are part of this node */ virBitmapPtr cpumask; /* CPUs that are part of this node */
char *cpustr; /* CPUs stored in string form for dumpxml */ char *cpustr; /* CPUs stored in string form for dumpxml */
unsigned int mem; /* Node memory in kB */ unsigned int mem; /* Node memory in kB */
}; };

View File

@ -4314,54 +4314,25 @@ qemuBuildSmpArgStr(const virDomainDefPtr def,
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }
static void
qemuBuildNumaCPUArgStr(char *cpumask, virBufferPtr buf)
{
int i, first, last;
int cpuSet = 0;
first = last = 0;
for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {
if (cpumask[i]) {
if (cpuSet) {
last = i;
} else {
first = last = i;
cpuSet = 1;
}
} else {
if (!cpuSet)
continue;
if (first == last)
virBufferAsprintf(buf, "%d,", first);
else
virBufferAsprintf(buf, "%d-%d,", first, last);
cpuSet = 0;
}
}
if (cpuSet) {
if (first == last)
virBufferAsprintf(buf, "%d,", first);
else
virBufferAsprintf(buf, "%d-%d,", first, last);
}
}
static int static int
qemuBuildNumaArgStr(const virDomainDefPtr def, virCommandPtr cmd) qemuBuildNumaArgStr(const virDomainDefPtr def, virCommandPtr cmd)
{ {
int i; int i;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
char *cpumask;
for (i = 0; i < def->cpu->ncells; i++) { for (i = 0; i < def->cpu->ncells; i++) {
virCommandAddArg(cmd, "-numa"); virCommandAddArg(cmd, "-numa");
virBufferAsprintf(&buf, "node,nodeid=%d", def->cpu->cells[i].cellid); virBufferAsprintf(&buf, "node,nodeid=%d", def->cpu->cells[i].cellid);
virBufferAddLit(&buf, ",cpus="); virBufferAddLit(&buf, ",cpus=");
qemuBuildNumaCPUArgStr(def->cpu->cells[i].cpumask, &buf); cpumask = virBitmapFormat(def->cpu->cells[i].cpumask);
if (cpumask) {
virBufferAsprintf(&buf, "%s", cpumask);
VIR_FREE(cpumask);
}
def->cpu->cells[i].mem = VIR_DIV_UP(def->cpu->cells[i].mem, def->cpu->cells[i].mem = VIR_DIV_UP(def->cpu->cells[i].mem,
1024) * 1024; 1024) * 1024;
virBufferAsprintf(&buf, "mem=%d", def->cpu->cells[i].mem / 1024); virBufferAsprintf(&buf, ",mem=%d", def->cpu->cells[i].mem / 1024);
if (virBufferError(&buf)) if (virBufferError(&buf))
goto error; goto error;