mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
use virBitmap to store numa nodemask info.
This commit is contained in:
parent
f1a43a8e41
commit
75b198b3e7
@ -1699,7 +1699,7 @@ void virDomainDefFree(virDomainDefPtr def)
|
||||
|
||||
virDomainVcpuPinDefFree(def->cputune.emulatorpin);
|
||||
|
||||
VIR_FREE(def->numatune.memory.nodemask);
|
||||
virBitmapFree(def->numatune.memory.nodemask);
|
||||
|
||||
virSysinfoDefFree(def->sysinfo);
|
||||
|
||||
@ -8747,19 +8747,10 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
|
||||
|
||||
nodeset = virXMLPropString(cur, "nodeset");
|
||||
if (nodeset) {
|
||||
char *set = nodeset;
|
||||
int nodemasklen = VIR_DOMAIN_CPUMASK_LEN;
|
||||
|
||||
if (VIR_ALLOC_N(def->numatune.memory.nodemask,
|
||||
nodemasklen) < 0) {
|
||||
virReportOOMError();
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* "nodeset" uses the same syntax as "cpuset". */
|
||||
if (virDomainCpuSetParse(set, 0,
|
||||
def->numatune.memory.nodemask,
|
||||
nodemasklen) < 0) {
|
||||
if (virBitmapParse(nodeset,
|
||||
0,
|
||||
&def->numatune.memory.nodemask,
|
||||
VIR_DOMAIN_CPUMASK_LEN) < 0) {
|
||||
VIR_FREE(nodeset);
|
||||
goto error;
|
||||
}
|
||||
@ -8801,7 +8792,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
|
||||
|
||||
/* Ignore 'nodeset' if 'placement' is 'auto' finally */
|
||||
if (placement_mode == VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_AUTO)
|
||||
VIR_FREE(def->numatune.memory.nodemask);
|
||||
virBitmapFree(def->numatune.memory.nodemask);
|
||||
|
||||
/* Copy 'placement' of <numatune> to <vcpu> if its 'placement'
|
||||
* is not specified and 'placement' of <numatune> is specified.
|
||||
@ -13604,8 +13595,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
|
||||
|
||||
if (def->numatune.memory.placement_mode ==
|
||||
VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_STATIC) {
|
||||
nodemask = virDomainCpuSetFormat(def->numatune.memory.nodemask,
|
||||
VIR_DOMAIN_CPUMASK_LEN);
|
||||
nodemask = virBitmapFormat(def->numatune.memory.nodemask);
|
||||
if (nodemask == NULL) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("failed to format nodeset for "
|
||||
|
@ -1587,7 +1587,7 @@ typedef struct _virDomainNumatuneDef virDomainNumatuneDef;
|
||||
typedef virDomainNumatuneDef *virDomainNumatuneDefPtr;
|
||||
struct _virDomainNumatuneDef {
|
||||
struct {
|
||||
char *nodemask;
|
||||
virBitmapPtr nodemask;
|
||||
int mode;
|
||||
int placement_mode; /* enum virDomainNumatuneMemPlacementMode */
|
||||
} memory;
|
||||
|
@ -418,8 +418,8 @@ static int virLXCControllerSetupNUMAPolicy(virLXCControllerPtr ctrl)
|
||||
|
||||
/* Convert nodemask to NUMA bitmask. */
|
||||
nodemask_zero(&mask);
|
||||
for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {
|
||||
if (ctrl->def->numatune.memory.nodemask[i]) {
|
||||
i = -1;
|
||||
while ((i = virBitmapNextSetBit(ctrl->def->numatune.memory.nodemask, i)) >= 0) {
|
||||
if (i > NUMA_NUM_NODES) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Host cannot support NUMA node %d"), i);
|
||||
@ -432,7 +432,6 @@ static int virLXCControllerSetupNUMAPolicy(virLXCControllerPtr ctrl)
|
||||
}
|
||||
nodemask_set(&mask, i);
|
||||
}
|
||||
}
|
||||
|
||||
mode = ctrl->def->numatune.memory.mode;
|
||||
|
||||
|
@ -1466,7 +1466,7 @@ parallelsApplyChanges(virDomainObjPtr dom, virDomainDefPtr new)
|
||||
|
||||
if (old->numatune.memory.mode != new->numatune.memory.mode ||
|
||||
old->numatune.memory.placement_mode != new->numatune.memory.placement_mode ||
|
||||
!STREQ_NULLABLE(old->numatune.memory.nodemask, new->numatune.memory.nodemask)) {
|
||||
!virBitmapEqual(old->numatune.memory.nodemask, new->numatune.memory.nodemask)) {
|
||||
|
||||
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
|
||||
_("numa parameters are not supported "
|
||||
|
@ -195,7 +195,7 @@ int qemuSetupHostUsbDeviceCgroup(usbDevice *dev ATTRIBUTE_UNUSED,
|
||||
|
||||
int qemuSetupCgroup(struct qemud_driver *driver,
|
||||
virDomainObjPtr vm,
|
||||
char *nodemask)
|
||||
virBitmapPtr nodemask)
|
||||
{
|
||||
virCgroupPtr cgroup = NULL;
|
||||
int rc;
|
||||
@ -412,10 +412,9 @@ int qemuSetupCgroup(struct qemud_driver *driver,
|
||||
char *mask = NULL;
|
||||
if (vm->def->numatune.memory.placement_mode ==
|
||||
VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_AUTO)
|
||||
mask = virDomainCpuSetFormat(nodemask, VIR_DOMAIN_CPUMASK_LEN);
|
||||
mask = virBitmapFormat(nodemask);
|
||||
else
|
||||
mask = virDomainCpuSetFormat(vm->def->numatune.memory.nodemask,
|
||||
VIR_DOMAIN_CPUMASK_LEN);
|
||||
mask = virBitmapFormat(vm->def->numatune.memory.nodemask);
|
||||
if (!mask) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("failed to convert memory nodemask"));
|
||||
|
@ -49,7 +49,7 @@ int qemuSetupHostUsbDeviceCgroup(usbDevice *dev,
|
||||
void *opaque);
|
||||
int qemuSetupCgroup(struct qemud_driver *driver,
|
||||
virDomainObjPtr vm,
|
||||
char *nodemask);
|
||||
virBitmapPtr nodemask);
|
||||
int qemuSetupCgroupVcpuBW(virCgroupPtr cgroup,
|
||||
unsigned long long period,
|
||||
long long quota);
|
||||
|
@ -7517,17 +7517,11 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
|
||||
}
|
||||
} else if (STREQ(param->field, VIR_DOMAIN_NUMA_NODESET)) {
|
||||
int rc;
|
||||
char *nodeset = NULL;
|
||||
virBitmapPtr nodeset = NULL;
|
||||
char *nodeset_str = NULL;
|
||||
|
||||
if (VIR_ALLOC_N(nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0) {
|
||||
virReportOOMError();
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
};
|
||||
|
||||
if (virDomainCpuSetParse(params[i].value.s,
|
||||
0, nodeset,
|
||||
if (virBitmapParse(params[i].value.s,
|
||||
0, &nodeset,
|
||||
VIR_DOMAIN_CPUMASK_LEN) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Failed to parse nodeset"));
|
||||
@ -7541,17 +7535,16 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
|
||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||
_("change of nodeset for running domain "
|
||||
"requires strict numa mode"));
|
||||
VIR_FREE(nodeset);
|
||||
virBitmapFree(nodeset);
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Ensure the cpuset string is formated before passing to cgroup */
|
||||
if (!(nodeset_str = virDomainCpuSetFormat(nodeset,
|
||||
VIR_DOMAIN_CPUMASK_LEN))) {
|
||||
if (!(nodeset_str = virBitmapFormat(nodeset))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Failed to format nodeset"));
|
||||
VIR_FREE(nodeset);
|
||||
virBitmapFree(nodeset);
|
||||
ret = -1;
|
||||
continue;
|
||||
}
|
||||
@ -7559,7 +7552,7 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
|
||||
if ((rc = virCgroupSetCpusetMems(group, nodeset_str) != 0)) {
|
||||
virReportSystemError(-rc, "%s",
|
||||
_("unable to set numa tunable"));
|
||||
VIR_FREE(nodeset);
|
||||
virBitmapFree(nodeset);
|
||||
VIR_FREE(nodeset_str);
|
||||
ret = -1;
|
||||
continue;
|
||||
@ -7568,40 +7561,22 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
|
||||
|
||||
/* update vm->def here so that dumpxml can read the new
|
||||
* values from vm->def. */
|
||||
if (!vm->def->numatune.memory.nodemask) {
|
||||
if (VIR_ALLOC_N(vm->def->numatune.memory.nodemask,
|
||||
VIR_DOMAIN_CPUMASK_LEN) < 0) {
|
||||
virReportOOMError();
|
||||
VIR_FREE(nodeset);
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
VIR_FREE(vm->def->numatune.memory.nodemask);
|
||||
}
|
||||
virBitmapFree(vm->def->numatune.memory.nodemask);
|
||||
|
||||
vm->def->numatune.memory.nodemask = nodeset;
|
||||
vm->def->numatune.memory.placement_mode =
|
||||
VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_STATIC;
|
||||
vm->def->numatune.memory.nodemask = virBitmapNewCopy(nodeset);
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||
if (!persistentDef->numatune.memory.nodemask) {
|
||||
if (VIR_ALLOC_N(persistentDef->numatune.memory.nodemask,
|
||||
VIR_DOMAIN_CPUMASK_LEN) < 0) {
|
||||
virReportOOMError();
|
||||
VIR_FREE(nodeset);
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
VIR_FREE(persistentDef->numatune.memory.nodemask);
|
||||
}
|
||||
virBitmapFree(persistentDef->numatune.memory.nodemask);
|
||||
|
||||
persistentDef->numatune.memory.nodemask = nodeset;
|
||||
persistentDef->numatune.memory.placement_mode =
|
||||
VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_STATIC;
|
||||
nodeset = NULL;
|
||||
}
|
||||
virBitmapFree(nodeset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7696,11 +7671,8 @@ qemuDomainGetNumaParameters(virDomainPtr dom,
|
||||
|
||||
case 1: /* fill numa nodeset here */
|
||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||
char *mask = persistentDef->numatune.memory.nodemask;
|
||||
if (mask)
|
||||
nodeset = virDomainCpuSetFormat(mask,
|
||||
VIR_DOMAIN_CPUMASK_LEN);
|
||||
else
|
||||
nodeset = virBitmapFormat(persistentDef->numatune.memory.nodemask);
|
||||
if (!nodeset)
|
||||
nodeset = strdup("");
|
||||
} else {
|
||||
rc = virCgroupGetCpusetMems(group, &nodeset);
|
||||
|
@ -63,6 +63,7 @@
|
||||
#include "uuid.h"
|
||||
#include "virtime.h"
|
||||
#include "virnetdevtap.h"
|
||||
#include "bitmap.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_QEMU
|
||||
|
||||
@ -1704,7 +1705,7 @@ qemuProcessDetectVcpuPIDs(struct qemud_driver *driver,
|
||||
#if HAVE_NUMACTL
|
||||
static int
|
||||
qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm,
|
||||
const char *nodemask)
|
||||
virBitmapPtr nodemask)
|
||||
{
|
||||
nodemask_t mask;
|
||||
int mode = -1;
|
||||
@ -1714,7 +1715,7 @@ qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm,
|
||||
int maxnode = 0;
|
||||
bool warned = false;
|
||||
virDomainNumatuneDef numatune = vm->def->numatune;
|
||||
const char *tmp_nodemask = NULL;
|
||||
virBitmapPtr tmp_nodemask = NULL;
|
||||
|
||||
if (numatune.memory.placement_mode ==
|
||||
VIR_DOMAIN_NUMATUNE_MEM_PLACEMENT_MODE_STATIC) {
|
||||
@ -1739,8 +1740,8 @@ qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm,
|
||||
maxnode = numa_max_node() + 1;
|
||||
/* Convert nodemask to NUMA bitmask. */
|
||||
nodemask_zero(&mask);
|
||||
for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {
|
||||
if (tmp_nodemask[i]) {
|
||||
i = -1;
|
||||
while ((i = virBitmapNextSetBit(tmp_nodemask, i)) >= 0) {
|
||||
if (i > NUMA_NUM_NODES) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Host cannot support NUMA node %d"), i);
|
||||
@ -1753,7 +1754,6 @@ qemuProcessInitNumaMemoryPolicy(virDomainObjPtr vm,
|
||||
}
|
||||
nodemask_set(&mask, i);
|
||||
}
|
||||
}
|
||||
|
||||
mode = numatune.memory.mode;
|
||||
|
||||
@ -1848,7 +1848,7 @@ qemuGetNumadAdvice(virDomainDefPtr def ATTRIBUTE_UNUSED)
|
||||
static int
|
||||
qemuProcessInitCpuAffinity(struct qemud_driver *driver,
|
||||
virDomainObjPtr vm,
|
||||
const char *nodemask)
|
||||
virBitmapPtr nodemask)
|
||||
{
|
||||
int ret = -1;
|
||||
int i, hostcpus, maxcpu = QEMUD_CPUMASK_LEN;
|
||||
@ -1878,7 +1878,10 @@ qemuProcessInitCpuAffinity(struct qemud_driver *driver,
|
||||
for (i = 0; i < driver->caps->host.nnumaCell; i++) {
|
||||
int j;
|
||||
int cur_ncpus = driver->caps->host.numaCell[i]->ncpus;
|
||||
if (nodemask[i]) {
|
||||
bool result;
|
||||
if (virBitmapGetBit(nodemask, i, &result) < 0)
|
||||
goto cleanup;
|
||||
if (result) {
|
||||
for (j = 0; j < cur_ncpus; j++)
|
||||
ignore_value(virBitmapSetBit(cpumap,
|
||||
driver->caps->host.numaCell[i]->cpus[j]));
|
||||
@ -2583,7 +2586,7 @@ struct qemuProcessHookData {
|
||||
virConnectPtr conn;
|
||||
virDomainObjPtr vm;
|
||||
struct qemud_driver *driver;
|
||||
char *nodemask;
|
||||
virBitmapPtr nodemask;
|
||||
};
|
||||
|
||||
static int qemuProcessHook(void *data)
|
||||
@ -3340,7 +3343,7 @@ int qemuProcessStart(virConnectPtr conn,
|
||||
unsigned long cur_balloon;
|
||||
int i;
|
||||
char *nodeset = NULL;
|
||||
char *nodemask = NULL;
|
||||
virBitmapPtr nodemask = NULL;
|
||||
unsigned int stop_flags;
|
||||
|
||||
/* Okay, these are just internal flags,
|
||||
@ -3537,12 +3540,7 @@ int qemuProcessStart(virConnectPtr conn,
|
||||
|
||||
VIR_DEBUG("Nodeset returned from numad: %s", nodeset);
|
||||
|
||||
if (VIR_ALLOC_N(nodemask, VIR_DOMAIN_CPUMASK_LEN) < 0) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virDomainCpuSetParse(nodeset, 0, nodemask,
|
||||
if (virBitmapParse(nodeset, 0, &nodemask,
|
||||
VIR_DOMAIN_CPUMASK_LEN) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
@ -3872,7 +3870,7 @@ cleanup:
|
||||
* if we failed to initialize the now running VM. kill it off and
|
||||
* pretend we never started it */
|
||||
VIR_FREE(nodeset);
|
||||
VIR_FREE(nodemask);
|
||||
virBitmapFree(nodemask);
|
||||
virCommandFree(cmd);
|
||||
VIR_FORCE_CLOSE(logfile);
|
||||
qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, stop_flags);
|
||||
|
Loading…
Reference in New Issue
Block a user