2014-06-06 14:50:39 +00:00
|
|
|
/*
|
2015-02-11 09:08:35 +00:00
|
|
|
* numa_conf.c
|
2014-06-06 14:50:39 +00:00
|
|
|
*
|
2015-02-11 09:08:35 +00:00
|
|
|
* Copyright (C) 2014-2015 Red Hat, Inc.
|
2014-06-06 14:50:39 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2015-02-11 09:08:35 +00:00
|
|
|
#include "numa_conf.h"
|
2014-06-06 14:50:39 +00:00
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
#include "domain_conf.h"
|
|
|
|
#include "viralloc.h"
|
2014-11-06 11:16:54 +00:00
|
|
|
#include "virnuma.h"
|
2014-06-09 13:00:22 +00:00
|
|
|
#include "virstring.h"
|
|
|
|
|
2017-11-02 15:47:20 +00:00
|
|
|
/*
|
|
|
|
* Distance definitions defined Conform ACPI 2.0 SLIT.
|
|
|
|
* See include/linux/topology.h
|
|
|
|
*/
|
|
|
|
#define LOCAL_DISTANCE 10
|
|
|
|
#define REMOTE_DISTANCE 20
|
|
|
|
/* SLIT entry value is a one-byte unsigned integer. */
|
|
|
|
#define UNREACHABLE 255
|
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_DOMAIN
|
|
|
|
|
2014-06-06 14:50:39 +00:00
|
|
|
VIR_ENUM_IMPL(virDomainNumatuneMemMode,
|
|
|
|
VIR_DOMAIN_NUMATUNE_MEM_LAST,
|
|
|
|
"strict",
|
|
|
|
"preferred",
|
2019-01-20 16:30:15 +00:00
|
|
|
"interleave",
|
|
|
|
);
|
2014-06-06 14:50:39 +00:00
|
|
|
|
2014-06-08 17:15:42 +00:00
|
|
|
VIR_ENUM_IMPL(virDomainNumatunePlacement,
|
|
|
|
VIR_DOMAIN_NUMATUNE_PLACEMENT_LAST,
|
2014-06-06 14:50:39 +00:00
|
|
|
"default",
|
|
|
|
"static",
|
2019-01-20 16:30:15 +00:00
|
|
|
"auto",
|
|
|
|
);
|
2014-06-09 13:00:22 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virDomainMemoryAccess,
|
|
|
|
VIR_DOMAIN_MEMORY_ACCESS_LAST,
|
2015-02-11 14:40:27 +00:00
|
|
|
"default",
|
|
|
|
"shared",
|
2019-01-20 16:30:15 +00:00
|
|
|
"private",
|
|
|
|
);
|
2017-02-02 13:27:30 +00:00
|
|
|
|
2017-11-02 15:47:20 +00:00
|
|
|
typedef struct _virDomainNumaDistance virDomainNumaDistance;
|
|
|
|
typedef virDomainNumaDistance *virDomainNumaDistancePtr;
|
2015-02-11 14:40:27 +00:00
|
|
|
|
2015-02-11 13:54:59 +00:00
|
|
|
typedef struct _virDomainNumaNode virDomainNumaNode;
|
|
|
|
typedef virDomainNumaNode *virDomainNumaNodePtr;
|
2014-07-15 09:39:44 +00:00
|
|
|
|
2015-02-11 13:54:59 +00:00
|
|
|
struct _virDomainNuma {
|
2014-06-09 13:00:22 +00:00
|
|
|
struct {
|
2014-07-15 09:39:44 +00:00
|
|
|
bool specified;
|
2014-06-09 13:00:22 +00:00
|
|
|
virBitmapPtr nodeset;
|
|
|
|
virDomainNumatuneMemMode mode;
|
|
|
|
virDomainNumatunePlacement placement;
|
|
|
|
} memory; /* pinning for all the memory */
|
|
|
|
|
2015-02-11 13:54:59 +00:00
|
|
|
struct _virDomainNumaNode {
|
2015-02-16 16:28:48 +00:00
|
|
|
unsigned long long mem; /* memory size in KiB */
|
|
|
|
virBitmapPtr cpumask; /* bitmap of vCPUs corresponding to the node */
|
|
|
|
virBitmapPtr nodeset; /* host memory nodes where this guest node resides */
|
|
|
|
virDomainNumatuneMemMode mode; /* memory mode selection */
|
2017-02-02 13:27:30 +00:00
|
|
|
virDomainMemoryAccess memAccess; /* shared memory access configuration */
|
2018-05-11 13:08:53 +00:00
|
|
|
virTristateBool discard; /* discard-data for memory-backend-file */
|
2017-11-02 15:47:20 +00:00
|
|
|
|
|
|
|
struct _virDomainNumaDistance {
|
|
|
|
unsigned int value; /* locality value for node i->j or j->i */
|
|
|
|
unsigned int cellid;
|
|
|
|
} *distances; /* remote node distances */
|
|
|
|
size_t ndistances;
|
2015-02-16 16:28:48 +00:00
|
|
|
} *mem_nodes; /* guest node configuration */
|
2014-07-15 09:39:44 +00:00
|
|
|
size_t nmem_nodes;
|
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
/* Future NUMA tuning related stuff should go here. */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-03-03 07:14:37 +00:00
|
|
|
bool
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumatuneNodeSpecified(virDomainNumaPtr numatune,
|
2014-06-26 17:46:45 +00:00
|
|
|
int cellid)
|
|
|
|
{
|
|
|
|
if (numatune &&
|
|
|
|
cellid >= 0 &&
|
|
|
|
cellid < numatune->nmem_nodes)
|
|
|
|
return numatune->mem_nodes[cellid].nodeset;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-15 09:39:44 +00:00
|
|
|
static int
|
2015-02-16 16:19:15 +00:00
|
|
|
virDomainNumatuneNodeParseXML(virDomainNumaPtr numa,
|
2014-07-15 09:39:44 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
|
|
|
char *tmp = NULL;
|
2014-08-25 22:26:56 +00:00
|
|
|
int n = 0;
|
2014-07-15 09:39:44 +00:00
|
|
|
int ret = -1;
|
|
|
|
size_t i = 0;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
|
|
|
|
if ((n = virXPathNodeSet("./numatune/memnode", ctxt, &nodes)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot extract memnode nodes"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!n)
|
|
|
|
return 0;
|
|
|
|
|
2015-02-16 16:19:15 +00:00
|
|
|
if (numa->memory.specified &&
|
|
|
|
numa->memory.placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO) {
|
2014-07-15 09:39:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Per-node binding is not compatible with "
|
|
|
|
"automatic NUMA placement."));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-02-16 16:28:48 +00:00
|
|
|
if (!numa->nmem_nodes) {
|
2014-07-15 09:39:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Element 'memnode' is invalid without "
|
|
|
|
"any guest NUMA cells"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
int mode = 0;
|
|
|
|
unsigned int cellid = 0;
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumaNodePtr mem_node = NULL;
|
2014-07-15 09:39:44 +00:00
|
|
|
xmlNodePtr cur_node = nodes[i];
|
|
|
|
|
|
|
|
tmp = virXMLPropString(cur_node, "cellid");
|
|
|
|
if (!tmp) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Missing required cellid attribute "
|
|
|
|
"in memnode element"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virStrToLong_uip(tmp, NULL, 10, &cellid) < 0) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Invalid cellid attribute in memnode element: %s"),
|
|
|
|
tmp);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
|
2015-02-16 16:19:15 +00:00
|
|
|
if (cellid >= numa->nmem_nodes) {
|
2014-07-15 09:39:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Argument 'cellid' in memnode element must "
|
|
|
|
"correspond to existing guest's NUMA cell"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-02-16 16:19:15 +00:00
|
|
|
mem_node = &numa->mem_nodes[cellid];
|
2014-07-15 09:39:44 +00:00
|
|
|
|
|
|
|
if (mem_node->nodeset) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Multiple memnode elements with cellid %u"),
|
|
|
|
cellid);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = virXMLPropString(cur_node, "mode");
|
|
|
|
if (!tmp) {
|
|
|
|
mem_node->mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
|
|
|
|
} else {
|
|
|
|
if ((mode = virDomainNumatuneMemModeTypeFromString(tmp)) < 0) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Invalid mode attribute in memnode element"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
mem_node->mode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = virXMLPropString(cur_node, "nodeset");
|
|
|
|
if (!tmp) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Missing required nodeset attribute "
|
|
|
|
"in memnode element"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2016-06-17 12:56:45 +00:00
|
|
|
if (virBitmapParse(tmp, &mem_node->nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
2014-07-15 09:39:44 +00:00
|
|
|
goto cleanup;
|
2015-04-10 09:11:21 +00:00
|
|
|
|
|
|
|
if (virBitmapIsAllClear(mem_node->nodeset)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Invalid value of 'nodeset': %s"), tmp);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-07-15 09:39:44 +00:00
|
|
|
VIR_FREE(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
int
|
2015-02-16 16:19:15 +00:00
|
|
|
virDomainNumatuneParseXML(virDomainNumaPtr numa,
|
2014-07-21 09:32:33 +00:00
|
|
|
bool placement_static,
|
2014-06-09 13:00:22 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
|
|
|
char *tmp = NULL;
|
|
|
|
int mode = -1;
|
|
|
|
int n = 0;
|
|
|
|
int placement = -1;
|
|
|
|
int ret = -1;
|
|
|
|
virBitmapPtr nodeset = NULL;
|
|
|
|
xmlNodePtr node = NULL;
|
|
|
|
|
|
|
|
if (virXPathInt("count(./numatune)", ctxt, &n) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("cannot extract numatune nodes"));
|
|
|
|
goto cleanup;
|
|
|
|
} else if (n > 1) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("only one numatune is supported"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = virXPathNode("./numatune/memory[1]", ctxt);
|
|
|
|
|
2015-02-12 15:04:45 +00:00
|
|
|
if (!placement_static && !node)
|
|
|
|
placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO;
|
|
|
|
|
|
|
|
if (node) {
|
|
|
|
if ((tmp = virXMLPropString(node, "mode")) &&
|
|
|
|
(mode = virDomainNumatuneMemModeTypeFromString(tmp)) < 0) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Unsupported NUMA memory tuning mode '%s'"), tmp);
|
2014-07-15 09:39:44 +00:00
|
|
|
goto cleanup;
|
2015-02-12 15:04:45 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
2014-06-09 13:00:22 +00:00
|
|
|
|
2015-02-12 15:04:45 +00:00
|
|
|
if ((tmp = virXMLPropString(node, "placement")) &&
|
|
|
|
(placement = virDomainNumatunePlacementTypeFromString(tmp)) < 0) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Unsupported NUMA memory placement mode '%s'"), tmp);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
2014-06-09 13:00:22 +00:00
|
|
|
|
2015-04-10 09:11:21 +00:00
|
|
|
tmp = virXMLPropString(node, "nodeset");
|
|
|
|
if (tmp) {
|
2016-06-17 12:56:45 +00:00
|
|
|
if (virBitmapParse(tmp, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
2015-04-10 09:11:21 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virBitmapIsAllClear(nodeset)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Invalid value of 'nodeset': %s"), tmp);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
}
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 16:19:15 +00:00
|
|
|
if (virDomainNumatuneSet(numa,
|
2014-07-21 09:32:33 +00:00
|
|
|
placement_static,
|
|
|
|
placement,
|
|
|
|
mode,
|
|
|
|
nodeset) < 0)
|
2014-06-09 13:00:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-02-16 16:28:48 +00:00
|
|
|
if (virDomainNumatuneNodeParseXML(numa, ctxt) < 0)
|
2014-06-09 13:00:22 +00:00
|
|
|
goto cleanup;
|
2014-07-15 09:39:44 +00:00
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virBitmapFree(nodeset);
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
virDomainNumatuneFormatXML(virBufferPtr buf,
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumaPtr numatune)
|
2014-06-09 13:00:22 +00:00
|
|
|
{
|
|
|
|
const char *tmp = NULL;
|
|
|
|
char *nodeset = NULL;
|
2015-02-16 13:17:41 +00:00
|
|
|
bool nodesetSpecified = false;
|
2014-07-15 09:39:44 +00:00
|
|
|
size_t i = 0;
|
2014-06-09 13:00:22 +00:00
|
|
|
|
|
|
|
if (!numatune)
|
|
|
|
return 0;
|
|
|
|
|
2015-02-16 13:17:41 +00:00
|
|
|
for (i = 0; i < numatune->nmem_nodes; i++) {
|
|
|
|
if (numatune->mem_nodes[i].nodeset) {
|
|
|
|
nodesetSpecified = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nodesetSpecified && !numatune->memory.specified)
|
|
|
|
return 0;
|
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
virBufferAddLit(buf, "<numatune>\n");
|
|
|
|
virBufferAdjustIndent(buf, 2);
|
|
|
|
|
2014-07-15 09:39:44 +00:00
|
|
|
if (numatune->memory.specified) {
|
|
|
|
tmp = virDomainNumatuneMemModeTypeToString(numatune->memory.mode);
|
|
|
|
virBufferAsprintf(buf, "<memory mode='%s' ", tmp);
|
|
|
|
|
|
|
|
if (numatune->memory.placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC) {
|
|
|
|
if (!(nodeset = virBitmapFormat(numatune->memory.nodeset)))
|
|
|
|
return -1;
|
|
|
|
virBufferAsprintf(buf, "nodeset='%s'/>\n", nodeset);
|
|
|
|
VIR_FREE(nodeset);
|
|
|
|
} else if (numatune->memory.placement) {
|
|
|
|
tmp = virDomainNumatunePlacementTypeToString(numatune->memory.placement);
|
|
|
|
virBufferAsprintf(buf, "placement='%s'/>\n", tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < numatune->nmem_nodes; i++) {
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumaNodePtr mem_node = &numatune->mem_nodes[i];
|
2014-06-09 13:00:22 +00:00
|
|
|
|
2014-07-15 09:39:44 +00:00
|
|
|
if (!mem_node->nodeset)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!(nodeset = virBitmapFormat(mem_node->nodeset)))
|
2014-06-09 13:00:22 +00:00
|
|
|
return -1;
|
2014-07-15 09:39:44 +00:00
|
|
|
|
|
|
|
virBufferAsprintf(buf,
|
|
|
|
"<memnode cellid='%zu' mode='%s' nodeset='%s'/>\n",
|
|
|
|
i,
|
|
|
|
virDomainNumatuneMemModeTypeToString(mem_node->mode),
|
|
|
|
nodeset);
|
2014-06-09 13:00:22 +00:00
|
|
|
VIR_FREE(nodeset);
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</numatune>\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumaFree(virDomainNumaPtr numa)
|
2014-06-09 13:00:22 +00:00
|
|
|
{
|
2014-07-15 09:39:44 +00:00
|
|
|
size_t i = 0;
|
|
|
|
|
2015-02-11 13:54:59 +00:00
|
|
|
if (!numa)
|
2014-06-09 13:00:22 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-11 13:54:59 +00:00
|
|
|
virBitmapFree(numa->memory.nodeset);
|
2015-02-16 16:28:48 +00:00
|
|
|
for (i = 0; i < numa->nmem_nodes; i++) {
|
|
|
|
virBitmapFree(numa->mem_nodes[i].cpumask);
|
2015-02-11 13:54:59 +00:00
|
|
|
virBitmapFree(numa->mem_nodes[i].nodeset);
|
2017-11-21 23:18:46 +00:00
|
|
|
|
|
|
|
if (numa->mem_nodes[i].ndistances > 0)
|
|
|
|
VIR_FREE(numa->mem_nodes[i].distances);
|
2015-02-16 16:28:48 +00:00
|
|
|
}
|
2015-02-11 13:54:59 +00:00
|
|
|
VIR_FREE(numa->mem_nodes);
|
2014-06-09 13:00:22 +00:00
|
|
|
|
2015-02-11 13:54:59 +00:00
|
|
|
VIR_FREE(numa);
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 09:55:26 +00:00
|
|
|
/**
|
|
|
|
* virDomainNumatuneGetMode:
|
|
|
|
* @numatune: pointer to numatune definition
|
|
|
|
* @cellid: cell selector
|
|
|
|
* @mode: where to store the result
|
|
|
|
*
|
|
|
|
* Get the defined mode for domain's memory. It's safe to pass
|
|
|
|
* NULL to @mode if the return value is the only info needed.
|
|
|
|
*
|
|
|
|
* Returns: 0 on success (with @mode updated)
|
|
|
|
* -1 if no mode was defined in XML
|
|
|
|
*/
|
|
|
|
int virDomainNumatuneGetMode(virDomainNumaPtr numatune,
|
|
|
|
int cellid,
|
|
|
|
virDomainNumatuneMemMode *mode)
|
2014-06-09 13:00:22 +00:00
|
|
|
{
|
2015-05-19 09:55:26 +00:00
|
|
|
int ret = -1;
|
|
|
|
virDomainNumatuneMemMode tmp_mode;
|
|
|
|
|
2014-06-26 17:46:45 +00:00
|
|
|
if (!numatune)
|
2015-05-19 09:55:26 +00:00
|
|
|
return ret;
|
2014-06-26 17:46:45 +00:00
|
|
|
|
|
|
|
if (virDomainNumatuneNodeSpecified(numatune, cellid))
|
2015-05-19 09:55:26 +00:00
|
|
|
tmp_mode = numatune->mem_nodes[cellid].mode;
|
|
|
|
else if (numatune->memory.specified)
|
|
|
|
tmp_mode = numatune->memory.mode;
|
|
|
|
else
|
|
|
|
goto cleanup;
|
2014-06-26 17:46:45 +00:00
|
|
|
|
2015-05-19 09:55:26 +00:00
|
|
|
if (mode)
|
|
|
|
*mode = tmp_mode;
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
return ret;
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virBitmapPtr
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumatuneGetNodeset(virDomainNumaPtr numatune,
|
2014-06-26 17:46:45 +00:00
|
|
|
virBitmapPtr auto_nodeset,
|
|
|
|
int cellid)
|
2014-06-09 13:00:22 +00:00
|
|
|
{
|
|
|
|
if (!numatune)
|
|
|
|
return NULL;
|
|
|
|
|
2014-06-26 17:46:45 +00:00
|
|
|
if (numatune->memory.specified &&
|
|
|
|
numatune->memory.placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO)
|
2014-06-09 13:00:22 +00:00
|
|
|
return auto_nodeset;
|
|
|
|
|
2014-06-26 17:46:45 +00:00
|
|
|
if (virDomainNumatuneNodeSpecified(numatune, cellid))
|
|
|
|
return numatune->mem_nodes[cellid].nodeset;
|
|
|
|
|
|
|
|
if (!numatune->memory.specified)
|
2014-06-09 13:00:22 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return numatune->memory.nodeset;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumatuneFormatNodeset(virDomainNumaPtr numatune,
|
2014-06-26 17:46:45 +00:00
|
|
|
virBitmapPtr auto_nodeset,
|
|
|
|
int cellid)
|
2014-06-09 13:00:22 +00:00
|
|
|
{
|
|
|
|
return virBitmapFormat(virDomainNumatuneGetNodeset(numatune,
|
2014-06-26 17:46:45 +00:00
|
|
|
auto_nodeset,
|
|
|
|
cellid));
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 21:40:15 +00:00
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
int
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumatuneMaybeGetNodeset(virDomainNumaPtr numatune,
|
2015-01-15 21:40:15 +00:00
|
|
|
virBitmapPtr auto_nodeset,
|
|
|
|
virBitmapPtr *retNodeset,
|
|
|
|
int cellid)
|
2014-06-09 13:00:22 +00:00
|
|
|
{
|
2015-01-15 21:40:15 +00:00
|
|
|
*retNodeset = NULL;
|
2014-06-09 13:00:22 +00:00
|
|
|
|
|
|
|
if (!numatune)
|
|
|
|
return 0;
|
|
|
|
|
2014-06-26 17:46:45 +00:00
|
|
|
if (!virDomainNumatuneNodeSpecified(numatune, cellid) &&
|
|
|
|
!numatune->memory.specified)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (numatune->memory.specified &&
|
|
|
|
numatune->memory.placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO &&
|
2014-06-09 13:00:22 +00:00
|
|
|
!auto_nodeset) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Advice from numad is needed in case of "
|
|
|
|
"automatic numa placement"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-01-15 21:40:15 +00:00
|
|
|
*retNodeset = virDomainNumatuneGetNodeset(numatune, auto_nodeset, cellid);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumatuneMaybeFormatNodeset(virDomainNumaPtr numatune,
|
2015-01-15 21:40:15 +00:00
|
|
|
virBitmapPtr auto_nodeset,
|
|
|
|
char **mask,
|
|
|
|
int cellid)
|
|
|
|
{
|
|
|
|
virBitmapPtr nodeset;
|
|
|
|
|
|
|
|
if (virDomainNumatuneMaybeGetNodeset(numatune, auto_nodeset, &nodeset,
|
|
|
|
cellid) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (nodeset &&
|
|
|
|
!(*mask = virBitmapFormat(nodeset)))
|
2014-06-09 13:00:22 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-02-16 16:05:46 +00:00
|
|
|
virDomainNumatuneSet(virDomainNumaPtr numa,
|
2014-07-21 09:32:33 +00:00
|
|
|
bool placement_static,
|
2014-06-09 13:00:22 +00:00
|
|
|
int placement,
|
|
|
|
int mode,
|
|
|
|
virBitmapPtr nodeset)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
/* No need to do anything in this case */
|
|
|
|
if (mode == -1 && placement == -1 && !nodeset)
|
|
|
|
return 0;
|
|
|
|
|
2015-02-16 16:05:46 +00:00
|
|
|
if (!numa->memory.specified) {
|
2014-08-22 14:05:37 +00:00
|
|
|
if (mode == -1)
|
|
|
|
mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
|
|
|
|
if (placement == -1)
|
|
|
|
placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
/* Range checks */
|
|
|
|
if (mode != -1 &&
|
|
|
|
(mode < 0 || mode >= VIR_DOMAIN_NUMATUNE_MEM_LAST)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Unsupported numatune mode '%d'"),
|
|
|
|
mode);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-08-22 14:05:37 +00:00
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
if (placement != -1 &&
|
|
|
|
(placement < 0 || placement >= VIR_DOMAIN_NUMATUNE_PLACEMENT_LAST)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Unsupported numatune placement '%d'"),
|
|
|
|
mode);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != -1)
|
2015-02-16 16:05:46 +00:00
|
|
|
numa->memory.mode = mode;
|
2014-08-22 14:05:37 +00:00
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
if (nodeset) {
|
2015-02-16 16:05:46 +00:00
|
|
|
virBitmapFree(numa->memory.nodeset);
|
|
|
|
if (!(numa->memory.nodeset = virBitmapNewCopy(nodeset)))
|
2014-06-09 13:00:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
if (placement == -1)
|
|
|
|
placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT) {
|
2015-02-16 16:05:46 +00:00
|
|
|
if (numa->memory.nodeset || placement_static)
|
2014-06-09 13:00:22 +00:00
|
|
|
placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC;
|
|
|
|
else
|
|
|
|
placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC &&
|
2015-02-16 16:05:46 +00:00
|
|
|
!numa->memory.nodeset) {
|
2014-06-09 13:00:22 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("nodeset for NUMA memory tuning must be set "
|
|
|
|
"if 'placement' is 'static'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-08-22 14:05:37 +00:00
|
|
|
/* setting nodeset when placement auto is invalid */
|
|
|
|
if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO &&
|
2015-02-16 16:05:46 +00:00
|
|
|
numa->memory.nodeset) {
|
|
|
|
virBitmapFree(numa->memory.nodeset);
|
|
|
|
numa->memory.nodeset = NULL;
|
2014-08-22 14:05:37 +00:00
|
|
|
}
|
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
if (placement != -1)
|
2015-02-16 16:05:46 +00:00
|
|
|
numa->memory.placement = placement;
|
2014-06-09 13:00:22 +00:00
|
|
|
|
2015-02-16 16:05:46 +00:00
|
|
|
numa->memory.specified = true;
|
2014-07-15 09:39:44 +00:00
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
ret = 0;
|
2014-08-22 14:05:37 +00:00
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
cleanup:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-26 17:46:45 +00:00
|
|
|
static bool
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumaNodesEqual(virDomainNumaPtr n1,
|
|
|
|
virDomainNumaPtr n2)
|
2014-06-26 17:46:45 +00:00
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
if (n1->nmem_nodes != n2->nmem_nodes)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i = 0; i < n1->nmem_nodes; i++) {
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumaNodePtr nd1 = &n1->mem_nodes[i];
|
|
|
|
virDomainNumaNodePtr nd2 = &n2->mem_nodes[i];
|
2014-06-26 17:46:45 +00:00
|
|
|
|
|
|
|
if (!nd1->nodeset && !nd2->nodeset)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (nd1->mode != nd2->mode)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!virBitmapEqual(nd1->nodeset, nd2->nodeset))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
bool
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumaEquals(virDomainNumaPtr n1,
|
|
|
|
virDomainNumaPtr n2)
|
2014-06-09 13:00:22 +00:00
|
|
|
{
|
|
|
|
if (!n1 && !n2)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!n1 || !n2)
|
|
|
|
return false;
|
|
|
|
|
2014-07-15 09:39:44 +00:00
|
|
|
if (!n1->memory.specified && !n2->memory.specified)
|
2015-02-11 13:54:59 +00:00
|
|
|
return virDomainNumaNodesEqual(n1, n2);
|
2014-07-15 09:39:44 +00:00
|
|
|
|
|
|
|
if (!n1->memory.specified || !n2->memory.specified)
|
|
|
|
return false;
|
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
if (n1->memory.mode != n2->memory.mode)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (n1->memory.placement != n2->memory.placement)
|
|
|
|
return false;
|
|
|
|
|
2014-06-26 17:46:45 +00:00
|
|
|
if (!virBitmapEqual(n1->memory.nodeset, n2->memory.nodeset))
|
|
|
|
return false;
|
|
|
|
|
2015-02-11 13:54:59 +00:00
|
|
|
return virDomainNumaNodesEqual(n1, n2);
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumatuneHasPlacementAuto(virDomainNumaPtr numatune)
|
2014-06-09 13:00:22 +00:00
|
|
|
{
|
|
|
|
if (!numatune)
|
|
|
|
return false;
|
|
|
|
|
2014-07-15 09:39:44 +00:00
|
|
|
if (!numatune->memory.specified)
|
|
|
|
return false;
|
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
if (numatune->memory.placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-26 17:46:45 +00:00
|
|
|
|
|
|
|
bool
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumatuneHasPerNodeBinding(virDomainNumaPtr numatune)
|
2014-06-26 17:46:45 +00:00
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
if (!numatune)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i = 0; i < numatune->nmem_nodes; i++) {
|
|
|
|
if (numatune->mem_nodes[i].nodeset)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-04 02:44:40 +00:00
|
|
|
|
|
|
|
int
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumatuneSpecifiedMaxNode(virDomainNumaPtr numatune)
|
2014-11-04 02:44:40 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virBitmapPtr nodemask = NULL;
|
|
|
|
size_t i;
|
|
|
|
int bit;
|
|
|
|
|
|
|
|
if (!numatune)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
nodemask = virDomainNumatuneGetNodeset(numatune, NULL, -1);
|
|
|
|
if (nodemask)
|
|
|
|
ret = virBitmapLastSetBit(nodemask);
|
|
|
|
|
|
|
|
for (i = 0; i < numatune->nmem_nodes; i++) {
|
|
|
|
nodemask = numatune->mem_nodes[i].nodeset;
|
|
|
|
if (!nodemask)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bit = virBitmapLastSetBit(nodemask);
|
|
|
|
if (bit > ret)
|
|
|
|
ret = bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2014-11-06 11:16:54 +00:00
|
|
|
|
|
|
|
bool
|
2015-02-11 13:54:59 +00:00
|
|
|
virDomainNumatuneNodesetIsAvailable(virDomainNumaPtr numatune,
|
2014-11-06 11:16:54 +00:00
|
|
|
virBitmapPtr auto_nodeset)
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
virBitmapPtr b = NULL;
|
|
|
|
|
|
|
|
if (!numatune)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
b = virDomainNumatuneGetNodeset(numatune, auto_nodeset, -1);
|
|
|
|
if (!virNumaNodesetIsAvailable(b))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i = 0; i < numatune->nmem_nodes; i++) {
|
|
|
|
b = virDomainNumatuneGetNodeset(numatune, auto_nodeset, i);
|
|
|
|
if (!virNumaNodesetIsAvailable(b))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-11 11:27:53 +00:00
|
|
|
|
|
|
|
|
2017-11-02 15:47:20 +00:00
|
|
|
static int
|
|
|
|
virDomainNumaDefNodeDistanceParseXML(virDomainNumaPtr def,
|
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
unsigned int cur_cell)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int sibling;
|
|
|
|
char *tmp = NULL;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
size_t i, ndistances = def->nmem_nodes;
|
|
|
|
|
2017-11-21 23:13:43 +00:00
|
|
|
if (ndistances == 0)
|
2017-11-02 15:47:20 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* check if NUMA distances definition is present */
|
|
|
|
if (!virXPathNode("./distances[1]", ctxt))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((sibling = virXPathNodeSet("./distances[1]/sibling", ctxt, &nodes)) <= 0) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("NUMA distances defined without siblings"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sibling; i++) {
|
|
|
|
virDomainNumaDistancePtr ldist, rdist;
|
|
|
|
unsigned int sibling_id, sibling_value;
|
|
|
|
|
|
|
|
/* siblings are in order of parsing or explicitly numbered */
|
|
|
|
if (!(tmp = virXMLPropString(nodes[i], "id"))) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Missing 'id' attribute in NUMA "
|
|
|
|
"distances under 'cell id %d'"),
|
|
|
|
cur_cell);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The "id" needs to be applicable */
|
|
|
|
if (virStrToLong_uip(tmp, NULL, 10, &sibling_id) < 0) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Invalid 'id' attribute in NUMA "
|
|
|
|
"distances for sibling: '%s'"),
|
|
|
|
tmp);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
|
|
|
|
/* The "id" needs to be within numa/cell range */
|
|
|
|
if (sibling_id >= ndistances) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("'sibling_id %d' does not refer to a "
|
|
|
|
"valid cell within NUMA 'cell id %d'"),
|
|
|
|
sibling_id, cur_cell);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We need a locality value. Check and correct
|
|
|
|
* distance to local and distance to remote node.
|
|
|
|
*/
|
|
|
|
if (!(tmp = virXMLPropString(nodes[i], "value"))) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Missing 'value' attribute in NUMA distances "
|
|
|
|
"under 'cell id %d' for 'sibling id %d'"),
|
|
|
|
cur_cell, sibling_id);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The "value" needs to be applicable */
|
|
|
|
if (virStrToLong_uip(tmp, NULL, 10, &sibling_value) < 0) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("'value %s' is invalid for "
|
|
|
|
"'sibling id %d' under NUMA 'cell id %d'"),
|
|
|
|
tmp, sibling_id, cur_cell);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
|
|
|
|
/* Assure LOCAL_DISTANCE <= "value" <= UNREACHABLE
|
|
|
|
* and correct LOCAL_DISTANCE setting if such applies.
|
|
|
|
*/
|
|
|
|
if ((sibling_value < LOCAL_DISTANCE ||
|
|
|
|
sibling_value > UNREACHABLE) ||
|
|
|
|
(sibling_id == cur_cell &&
|
|
|
|
sibling_value != LOCAL_DISTANCE) ||
|
|
|
|
(sibling_id != cur_cell &&
|
|
|
|
sibling_value == LOCAL_DISTANCE)) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("'value %d' is invalid for "
|
|
|
|
"'sibling id %d' under NUMA 'cell id %d'"),
|
|
|
|
sibling_value, sibling_id, cur_cell);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apply the local / remote distance */
|
|
|
|
ldist = def->mem_nodes[cur_cell].distances;
|
|
|
|
if (!ldist) {
|
|
|
|
if (VIR_ALLOC_N(ldist, ndistances) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ldist[cur_cell].value = LOCAL_DISTANCE;
|
|
|
|
ldist[cur_cell].cellid = cur_cell;
|
|
|
|
def->mem_nodes[cur_cell].ndistances = ndistances;
|
2017-11-21 23:13:43 +00:00
|
|
|
def->mem_nodes[cur_cell].distances = ldist;
|
2017-11-02 15:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ldist[sibling_id].cellid = sibling_id;
|
|
|
|
ldist[sibling_id].value = sibling_value;
|
|
|
|
|
|
|
|
/* Apply symmetry if none given */
|
|
|
|
rdist = def->mem_nodes[sibling_id].distances;
|
|
|
|
if (!rdist) {
|
|
|
|
if (VIR_ALLOC_N(rdist, ndistances) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
rdist[sibling_id].value = LOCAL_DISTANCE;
|
|
|
|
rdist[sibling_id].cellid = sibling_id;
|
|
|
|
def->mem_nodes[sibling_id].ndistances = ndistances;
|
2017-11-21 23:13:43 +00:00
|
|
|
def->mem_nodes[sibling_id].distances = rdist;
|
2017-11-02 15:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rdist[cur_cell].cellid = cur_cell;
|
|
|
|
if (!rdist[cur_cell].value)
|
|
|
|
rdist[cur_cell].value = sibling_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2017-11-21 23:13:43 +00:00
|
|
|
if (ret < 0) {
|
2017-11-02 15:47:20 +00:00
|
|
|
for (i = 0; i < ndistances; i++)
|
|
|
|
VIR_FREE(def->mem_nodes[i].distances);
|
2017-11-21 23:13:43 +00:00
|
|
|
def->mem_nodes[i].ndistances = 0;
|
2017-11-02 15:47:20 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-11 11:27:53 +00:00
|
|
|
int
|
2015-02-16 16:28:48 +00:00
|
|
|
virDomainNumaDefCPUParseXML(virDomainNumaPtr def,
|
2015-02-11 11:27:53 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
xmlNodePtr oldNode = ctxt->node;
|
2015-02-11 12:31:09 +00:00
|
|
|
char *tmp = NULL;
|
2015-02-11 11:27:53 +00:00
|
|
|
int n;
|
2017-11-02 15:47:20 +00:00
|
|
|
size_t i, j;
|
2015-02-11 11:27:53 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2015-02-11 12:31:09 +00:00
|
|
|
/* check if NUMA definition is present */
|
2015-03-19 10:13:04 +00:00
|
|
|
if (!virXPathNode("./cpu/numa[1]", ctxt))
|
2015-02-11 12:31:09 +00:00
|
|
|
return 0;
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2015-03-19 10:13:04 +00:00
|
|
|
if ((n = virXPathNodeSet("./cpu/numa[1]/cell", ctxt, &nodes)) <= 0) {
|
2015-02-11 12:31:09 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("NUMA topology defined without NUMA cells"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-02-16 16:28:48 +00:00
|
|
|
if (VIR_ALLOC_N(def->mem_nodes, n) < 0)
|
2015-02-11 12:31:09 +00:00
|
|
|
goto cleanup;
|
2015-02-16 16:28:48 +00:00
|
|
|
def->nmem_nodes = n;
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2015-02-11 12:31:09 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2015-02-12 08:37:13 +00:00
|
|
|
int rc;
|
2015-02-11 12:31:09 +00:00
|
|
|
unsigned int cur_cell = i;
|
|
|
|
|
|
|
|
/* cells are in order of parsing or explicitly numbered */
|
|
|
|
if ((tmp = virXMLPropString(nodes[i], "id"))) {
|
|
|
|
if (virStrToLong_uip(tmp, NULL, 10, &cur_cell) < 0) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Invalid 'id' attribute in NUMA cell: '%s'"),
|
|
|
|
tmp);
|
|
|
|
goto cleanup;
|
2015-02-11 11:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_cell >= n) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Exactly one 'cell' element per guest "
|
|
|
|
"NUMA cell allowed, non-contiguous ranges or "
|
|
|
|
"ranges not starting from 0 are not allowed"));
|
2015-02-11 12:31:09 +00:00
|
|
|
goto cleanup;
|
2015-02-11 11:27:53 +00:00
|
|
|
}
|
2015-02-11 12:31:09 +00:00
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2015-02-16 16:28:48 +00:00
|
|
|
if (def->mem_nodes[cur_cell].cpumask) {
|
2015-02-11 12:31:09 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Duplicate NUMA cell info for cell id '%u'"),
|
|
|
|
cur_cell);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2015-02-11 12:31:09 +00:00
|
|
|
if (!(tmp = virXMLPropString(nodes[i], "cpus"))) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Missing 'cpus' attribute in NUMA cell"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2016-06-17 12:56:45 +00:00
|
|
|
if (virBitmapParse(tmp, &def->mem_nodes[cur_cell].cpumask,
|
2015-02-11 16:38:29 +00:00
|
|
|
VIR_DOMAIN_CPUMASK_LEN) < 0)
|
2015-02-11 12:31:09 +00:00
|
|
|
goto cleanup;
|
2015-02-12 08:37:13 +00:00
|
|
|
|
2015-02-16 16:28:48 +00:00
|
|
|
if (virBitmapIsAllClear(def->mem_nodes[cur_cell].cpumask)) {
|
2015-02-11 16:38:29 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("NUMA cell %d has no vCPUs assigned"), cur_cell);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2015-02-11 13:06:20 +00:00
|
|
|
VIR_FREE(tmp);
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2015-09-08 04:59:10 +00:00
|
|
|
for (j = 0; j < n; j++) {
|
|
|
|
if (j == cur_cell || !def->mem_nodes[j].cpumask)
|
|
|
|
continue;
|
|
|
|
|
2015-05-05 10:13:38 +00:00
|
|
|
if (virBitmapOverlaps(def->mem_nodes[j].cpumask,
|
2015-09-08 04:59:10 +00:00
|
|
|
def->mem_nodes[cur_cell].cpumask)) {
|
2015-05-05 10:13:38 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2015-09-08 04:59:10 +00:00
|
|
|
_("NUMA cells %u and %zu have overlapping vCPU ids"),
|
|
|
|
cur_cell, j);
|
2015-05-05 10:13:38 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 12:31:09 +00:00
|
|
|
ctxt->node = nodes[i];
|
|
|
|
if (virDomainParseMemory("./@memory", "./@unit", ctxt,
|
2015-02-16 16:28:48 +00:00
|
|
|
&def->mem_nodes[cur_cell].mem, true, false) < 0)
|
2015-02-11 12:31:09 +00:00
|
|
|
goto cleanup;
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2015-02-11 12:31:09 +00:00
|
|
|
if ((tmp = virXMLPropString(nodes[i], "memAccess"))) {
|
2017-02-02 13:27:30 +00:00
|
|
|
if ((rc = virDomainMemoryAccessTypeFromString(tmp)) <= 0) {
|
2015-02-11 12:31:09 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Invalid 'memAccess' attribute value '%s'"),
|
|
|
|
tmp);
|
|
|
|
goto cleanup;
|
2015-02-11 11:27:53 +00:00
|
|
|
}
|
2015-02-11 12:31:09 +00:00
|
|
|
|
2015-02-16 16:28:48 +00:00
|
|
|
def->mem_nodes[cur_cell].memAccess = rc;
|
2015-02-11 12:31:09 +00:00
|
|
|
VIR_FREE(tmp);
|
2015-02-11 11:27:53 +00:00
|
|
|
}
|
2017-11-02 15:47:20 +00:00
|
|
|
|
2018-05-11 13:08:53 +00:00
|
|
|
if ((tmp = virXMLPropString(nodes[i], "discard"))) {
|
|
|
|
if ((rc = virTristateBoolTypeFromString(tmp)) <= 0) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Invalid 'discard' attribute value '%s'"),
|
|
|
|
tmp);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
def->mem_nodes[cur_cell].discard = rc;
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
}
|
|
|
|
|
2017-11-02 15:47:20 +00:00
|
|
|
/* Parse NUMA distances info */
|
|
|
|
if (virDomainNumaDefNodeDistanceParseXML(def, ctxt, cur_cell) < 0)
|
|
|
|
goto cleanup;
|
2015-02-11 11:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ctxt->node = oldNode;
|
|
|
|
VIR_FREE(nodes);
|
2015-02-11 12:31:09 +00:00
|
|
|
VIR_FREE(tmp);
|
2015-02-11 11:27:53 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2015-02-11 13:26:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
2017-09-08 14:47:14 +00:00
|
|
|
virDomainNumaDefCPUFormatXML(virBufferPtr buf,
|
|
|
|
virDomainNumaPtr def)
|
2015-02-11 13:26:19 +00:00
|
|
|
{
|
2017-02-02 13:27:30 +00:00
|
|
|
virDomainMemoryAccess memAccess;
|
2018-05-11 13:08:53 +00:00
|
|
|
virTristateBool discard;
|
2015-02-11 13:26:19 +00:00
|
|
|
char *cpustr;
|
2015-02-16 17:11:46 +00:00
|
|
|
size_t ncells = virDomainNumaGetNodeCount(def);
|
2015-02-11 13:26:19 +00:00
|
|
|
size_t i;
|
|
|
|
|
2015-02-16 17:11:46 +00:00
|
|
|
if (ncells == 0)
|
2015-02-11 13:26:19 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
virBufferAddLit(buf, "<numa>\n");
|
|
|
|
virBufferAdjustIndent(buf, 2);
|
2015-02-16 17:11:46 +00:00
|
|
|
for (i = 0; i < ncells; i++) {
|
2017-11-02 15:47:20 +00:00
|
|
|
int ndistances;
|
|
|
|
|
2015-02-16 17:51:36 +00:00
|
|
|
memAccess = virDomainNumaGetNodeMemoryAccessMode(def, i);
|
2018-05-11 13:08:53 +00:00
|
|
|
discard = virDomainNumaGetNodeDiscard(def, i);
|
2015-02-11 13:26:19 +00:00
|
|
|
|
2015-02-16 17:38:43 +00:00
|
|
|
if (!(cpustr = virBitmapFormat(virDomainNumaGetNodeCpumask(def, i))))
|
2015-02-11 13:26:19 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
virBufferAddLit(buf, "<cell");
|
|
|
|
virBufferAsprintf(buf, " id='%zu'", i);
|
|
|
|
virBufferAsprintf(buf, " cpus='%s'", cpustr);
|
2015-02-16 18:14:23 +00:00
|
|
|
virBufferAsprintf(buf, " memory='%llu'",
|
|
|
|
virDomainNumaGetNodeMemorySize(def, i));
|
2015-02-11 13:26:19 +00:00
|
|
|
virBufferAddLit(buf, " unit='KiB'");
|
|
|
|
if (memAccess)
|
|
|
|
virBufferAsprintf(buf, " memAccess='%s'",
|
2017-02-02 13:27:30 +00:00
|
|
|
virDomainMemoryAccessTypeToString(memAccess));
|
2017-11-02 15:47:20 +00:00
|
|
|
|
2018-05-11 13:08:53 +00:00
|
|
|
if (discard)
|
|
|
|
virBufferAsprintf(buf, " discard='%s'",
|
|
|
|
virTristateBoolTypeToString(discard));
|
|
|
|
|
2017-11-02 15:47:20 +00:00
|
|
|
ndistances = def->mem_nodes[i].ndistances;
|
2017-11-21 23:17:58 +00:00
|
|
|
if (ndistances == 0) {
|
2017-11-02 15:47:20 +00:00
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
} else {
|
|
|
|
size_t j;
|
|
|
|
virDomainNumaDistancePtr distances = def->mem_nodes[i].distances;
|
|
|
|
|
|
|
|
virBufferAddLit(buf, ">\n");
|
|
|
|
virBufferAdjustIndent(buf, 2);
|
|
|
|
virBufferAddLit(buf, "<distances>\n");
|
|
|
|
virBufferAdjustIndent(buf, 2);
|
|
|
|
for (j = 0; j < ndistances; j++) {
|
|
|
|
if (distances[j].value) {
|
|
|
|
virBufferAddLit(buf, "<sibling");
|
|
|
|
virBufferAsprintf(buf, " id='%d'", distances[j].cellid);
|
|
|
|
virBufferAsprintf(buf, " value='%d'", distances[j].value);
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</distances>\n");
|
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</cell>\n");
|
|
|
|
}
|
|
|
|
|
2015-02-11 13:26:19 +00:00
|
|
|
VIR_FREE(cpustr);
|
|
|
|
}
|
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</numa>\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-02-12 08:37:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
unsigned int
|
2015-02-16 16:28:48 +00:00
|
|
|
virDomainNumaGetCPUCountTotal(virDomainNumaPtr numa)
|
2015-02-12 08:37:13 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
unsigned int ret = 0;
|
|
|
|
|
2015-02-16 16:28:48 +00:00
|
|
|
for (i = 0; i < numa->nmem_nodes; i++)
|
2015-02-16 17:38:43 +00:00
|
|
|
ret += virBitmapCountBits(virDomainNumaGetNodeCpumask(numa, i));
|
2015-02-12 08:37:13 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2015-02-16 15:42:13 +00:00
|
|
|
|
2015-08-07 14:31:57 +00:00
|
|
|
unsigned int
|
|
|
|
virDomainNumaGetMaxCPUID(virDomainNumaPtr numa)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
unsigned int ret = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < numa->nmem_nodes; i++) {
|
|
|
|
int bit;
|
|
|
|
|
|
|
|
bit = virBitmapLastSetBit(virDomainNumaGetNodeCpumask(numa, i));
|
|
|
|
if (bit > ret)
|
|
|
|
ret = bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-16 15:42:13 +00:00
|
|
|
|
|
|
|
virDomainNumaPtr
|
|
|
|
virDomainNumaNew(void)
|
|
|
|
{
|
|
|
|
virDomainNumaPtr ret = NULL;
|
|
|
|
|
|
|
|
ignore_value(VIR_ALLOC(ret));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2015-02-16 17:11:46 +00:00
|
|
|
|
|
|
|
|
2015-02-16 19:34:37 +00:00
|
|
|
bool
|
|
|
|
virDomainNumaCheckABIStability(virDomainNumaPtr src,
|
|
|
|
virDomainNumaPtr tgt)
|
|
|
|
{
|
|
|
|
size_t i;
|
2018-02-06 16:11:40 +00:00
|
|
|
size_t j;
|
2015-02-16 19:34:37 +00:00
|
|
|
|
|
|
|
if (virDomainNumaGetNodeCount(src) != virDomainNumaGetNodeCount(tgt)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Target NUMA node count '%zu' doesn't match "
|
|
|
|
"source '%zu'"),
|
|
|
|
virDomainNumaGetNodeCount(tgt),
|
|
|
|
virDomainNumaGetNodeCount(src));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < virDomainNumaGetNodeCount(src); i++) {
|
|
|
|
if (virDomainNumaGetNodeMemorySize(src, i) !=
|
|
|
|
virDomainNumaGetNodeMemorySize(tgt, i)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Size of target NUMA node %zu (%llu) doesn't "
|
|
|
|
"match source (%llu)"), i,
|
|
|
|
virDomainNumaGetNodeMemorySize(tgt, i),
|
|
|
|
virDomainNumaGetNodeMemorySize(src, i));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virBitmapEqual(virDomainNumaGetNodeCpumask(src, i),
|
|
|
|
virDomainNumaGetNodeCpumask(tgt, i))) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Processor mask of target NUMA node %zu doesn't "
|
|
|
|
"match source"), i);
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-06 16:11:40 +00:00
|
|
|
|
|
|
|
for (j = 0; j < virDomainNumaGetNodeCount(src); j++) {
|
|
|
|
if (virDomainNumaGetNodeDistance(src, i, j) !=
|
|
|
|
virDomainNumaGetNodeDistance(tgt, i, j)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Target NUMA distance from %zu to %zu "
|
|
|
|
"doesn't match source"), i, j);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 19:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-16 17:11:46 +00:00
|
|
|
size_t
|
2015-02-16 16:28:48 +00:00
|
|
|
virDomainNumaGetNodeCount(virDomainNumaPtr numa)
|
2015-02-16 17:11:46 +00:00
|
|
|
{
|
|
|
|
if (!numa)
|
|
|
|
return 0;
|
|
|
|
|
2015-02-16 16:28:48 +00:00
|
|
|
return numa->nmem_nodes;
|
2015-02-16 17:11:46 +00:00
|
|
|
}
|
2015-02-16 17:38:43 +00:00
|
|
|
|
|
|
|
|
xenconfig: add domxml conversions for xen-xl
This patch converts NUMA configurations between the Xen libxl
configuration file format and libvirt's XML format.
XML HVM domain on a 4 node (2 cores/socket) configuration:
<cpu>
<numa>
<cell id='0' cpus='0-1' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='10'/>
<sibling id='1' value='21'/>
<sibling id='2' value='31'/>
<sibling id='3' value='21'/>
</distances>
</cell>
<cell id='1' cpus='2-3' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='21'/>
<sibling id='1' value='10'/>
<sibling id='2' value='21'/>
<sibling id='3' value='31'/>
</distances>
</cell>
<cell id='2' cpus='3-4' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='31'/>
<sibling id='1' value='21'/>
<sibling id='2' value='10'/>
<sibling id='3' value='21'/>
</distances>
</cell>
<cell id='3' cpus='5-6' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='21'/>
<sibling id='1' value='31'/>
<sibling id='2' value='21'/>
<sibling id='3' value='10'/>
</distances>
</cell>
</numa>
</cpu>
Xen xl.cfg domain configuration:
vnuma = [["pnode=0","size=2048","vcpus=0-1","vdistances=10,21,31,21"],
["pnode=1","size=2048","vcpus=2-3","vdistances=21,10,21,31"],
["pnode=2","size=2048","vcpus=4-5","vdistances=31,21,10,21"],
["pnode=3","size=2048","vcpus=6-7","vdistances=21,31,21,10"]]
If there is no XML <distances> description amongst the <cell> data the
conversion schema from xml to native will generate 10 for local and 20
for all remote instances.
Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2017-11-02 15:47:21 +00:00
|
|
|
size_t
|
|
|
|
virDomainNumaSetNodeCount(virDomainNumaPtr numa, size_t nmem_nodes)
|
|
|
|
{
|
|
|
|
if (!nmem_nodes) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot set an empty mem_nodes set"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numa->mem_nodes) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot alter an existing mem_nodes set"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(numa->mem_nodes, nmem_nodes) < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
numa->nmem_nodes = nmem_nodes;
|
|
|
|
|
|
|
|
return numa->nmem_nodes;
|
|
|
|
}
|
|
|
|
|
2017-11-14 13:28:11 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
virDomainNumaNodeDistanceIsUsingDefaults(virDomainNumaPtr numa,
|
|
|
|
size_t node,
|
|
|
|
size_t sibling)
|
|
|
|
{
|
|
|
|
if (node >= numa->nmem_nodes ||
|
|
|
|
sibling >= numa->nmem_nodes)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!numa->mem_nodes[node].distances)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (numa->mem_nodes[node].distances[sibling].value == LOCAL_DISTANCE ||
|
|
|
|
numa->mem_nodes[node].distances[sibling].value == REMOTE_DISTANCE)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
xenconfig: add domxml conversions for xen-xl
This patch converts NUMA configurations between the Xen libxl
configuration file format and libvirt's XML format.
XML HVM domain on a 4 node (2 cores/socket) configuration:
<cpu>
<numa>
<cell id='0' cpus='0-1' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='10'/>
<sibling id='1' value='21'/>
<sibling id='2' value='31'/>
<sibling id='3' value='21'/>
</distances>
</cell>
<cell id='1' cpus='2-3' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='21'/>
<sibling id='1' value='10'/>
<sibling id='2' value='21'/>
<sibling id='3' value='31'/>
</distances>
</cell>
<cell id='2' cpus='3-4' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='31'/>
<sibling id='1' value='21'/>
<sibling id='2' value='10'/>
<sibling id='3' value='21'/>
</distances>
</cell>
<cell id='3' cpus='5-6' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='21'/>
<sibling id='1' value='31'/>
<sibling id='2' value='21'/>
<sibling id='3' value='10'/>
</distances>
</cell>
</numa>
</cpu>
Xen xl.cfg domain configuration:
vnuma = [["pnode=0","size=2048","vcpus=0-1","vdistances=10,21,31,21"],
["pnode=1","size=2048","vcpus=2-3","vdistances=21,10,21,31"],
["pnode=2","size=2048","vcpus=4-5","vdistances=31,21,10,21"],
["pnode=3","size=2048","vcpus=6-7","vdistances=21,31,21,10"]]
If there is no XML <distances> description amongst the <cell> data the
conversion schema from xml to native will generate 10 for local and 20
for all remote instances.
Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2017-11-02 15:47:21 +00:00
|
|
|
size_t
|
|
|
|
virDomainNumaGetNodeDistance(virDomainNumaPtr numa,
|
|
|
|
size_t node,
|
|
|
|
size_t cellid)
|
|
|
|
{
|
|
|
|
virDomainNumaDistancePtr distances = NULL;
|
|
|
|
|
|
|
|
if (node < numa->nmem_nodes)
|
|
|
|
distances = numa->mem_nodes[node].distances;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Present the configured distance value. If
|
|
|
|
* out of range or not available set the platform
|
|
|
|
* defined default for local and remote nodes.
|
|
|
|
*/
|
|
|
|
if (!distances ||
|
2017-11-14 13:24:20 +00:00
|
|
|
cellid >= numa->nmem_nodes ||
|
|
|
|
!distances[cellid].value)
|
xenconfig: add domxml conversions for xen-xl
This patch converts NUMA configurations between the Xen libxl
configuration file format and libvirt's XML format.
XML HVM domain on a 4 node (2 cores/socket) configuration:
<cpu>
<numa>
<cell id='0' cpus='0-1' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='10'/>
<sibling id='1' value='21'/>
<sibling id='2' value='31'/>
<sibling id='3' value='21'/>
</distances>
</cell>
<cell id='1' cpus='2-3' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='21'/>
<sibling id='1' value='10'/>
<sibling id='2' value='21'/>
<sibling id='3' value='31'/>
</distances>
</cell>
<cell id='2' cpus='3-4' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='31'/>
<sibling id='1' value='21'/>
<sibling id='2' value='10'/>
<sibling id='3' value='21'/>
</distances>
</cell>
<cell id='3' cpus='5-6' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='21'/>
<sibling id='1' value='31'/>
<sibling id='2' value='21'/>
<sibling id='3' value='10'/>
</distances>
</cell>
</numa>
</cpu>
Xen xl.cfg domain configuration:
vnuma = [["pnode=0","size=2048","vcpus=0-1","vdistances=10,21,31,21"],
["pnode=1","size=2048","vcpus=2-3","vdistances=21,10,21,31"],
["pnode=2","size=2048","vcpus=4-5","vdistances=31,21,10,21"],
["pnode=3","size=2048","vcpus=6-7","vdistances=21,31,21,10"]]
If there is no XML <distances> description amongst the <cell> data the
conversion schema from xml to native will generate 10 for local and 20
for all remote instances.
Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2017-11-02 15:47:21 +00:00
|
|
|
return (node == cellid) ? LOCAL_DISTANCE : REMOTE_DISTANCE;
|
|
|
|
|
|
|
|
return distances[cellid].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
virDomainNumaSetNodeDistance(virDomainNumaPtr numa,
|
|
|
|
size_t node,
|
|
|
|
size_t cellid,
|
|
|
|
unsigned int value)
|
|
|
|
{
|
|
|
|
virDomainNumaDistancePtr distances;
|
|
|
|
|
|
|
|
if (node >= numa->nmem_nodes) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Argument 'node' %zu outranges "
|
|
|
|
"defined number of NUMA nodes"),
|
|
|
|
node);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
distances = numa->mem_nodes[node].distances;
|
|
|
|
if (!distances ||
|
|
|
|
cellid >= numa->mem_nodes[node].ndistances) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Arguments under memnode element do not "
|
|
|
|
"correspond with existing guest's NUMA cell"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Advanced Configuration and Power Interface
|
|
|
|
* Specification version 6.1. Chapter 5.2.17
|
|
|
|
* System Locality Distance Information Table
|
|
|
|
* ... Distance values of 0-9 are reserved.
|
|
|
|
*/
|
|
|
|
if (value < LOCAL_DISTANCE ||
|
|
|
|
value > UNREACHABLE) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Distance value of %d is not in valid range"),
|
|
|
|
value);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value == LOCAL_DISTANCE && node != cellid) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Distance value %d under node %zu is "
|
|
|
|
"LOCAL_DISTANCE and should be set to 10"),
|
|
|
|
value, node);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
distances[cellid].cellid = cellid;
|
|
|
|
distances[cellid].value = value;
|
|
|
|
|
|
|
|
return distances[cellid].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
virDomainNumaSetNodeDistanceCount(virDomainNumaPtr numa,
|
|
|
|
size_t node,
|
|
|
|
size_t ndistances)
|
|
|
|
{
|
|
|
|
virDomainNumaDistancePtr distances;
|
|
|
|
|
|
|
|
distances = numa->mem_nodes[node].distances;
|
|
|
|
if (distances) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Cannot alter an existing nmem_nodes distances set for node: %zu"),
|
|
|
|
node);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(distances, ndistances) < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
numa->mem_nodes[node].distances = distances;
|
|
|
|
numa->mem_nodes[node].ndistances = ndistances;
|
|
|
|
|
|
|
|
return numa->mem_nodes[node].ndistances;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-16 17:38:43 +00:00
|
|
|
virBitmapPtr
|
2015-02-16 16:28:48 +00:00
|
|
|
virDomainNumaGetNodeCpumask(virDomainNumaPtr numa,
|
2015-02-16 17:38:43 +00:00
|
|
|
size_t node)
|
|
|
|
{
|
2015-02-16 16:28:48 +00:00
|
|
|
return numa->mem_nodes[node].cpumask;
|
2015-02-16 17:38:43 +00:00
|
|
|
}
|
2015-02-16 17:51:36 +00:00
|
|
|
|
|
|
|
|
xenconfig: add domxml conversions for xen-xl
This patch converts NUMA configurations between the Xen libxl
configuration file format and libvirt's XML format.
XML HVM domain on a 4 node (2 cores/socket) configuration:
<cpu>
<numa>
<cell id='0' cpus='0-1' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='10'/>
<sibling id='1' value='21'/>
<sibling id='2' value='31'/>
<sibling id='3' value='21'/>
</distances>
</cell>
<cell id='1' cpus='2-3' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='21'/>
<sibling id='1' value='10'/>
<sibling id='2' value='21'/>
<sibling id='3' value='31'/>
</distances>
</cell>
<cell id='2' cpus='3-4' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='31'/>
<sibling id='1' value='21'/>
<sibling id='2' value='10'/>
<sibling id='3' value='21'/>
</distances>
</cell>
<cell id='3' cpus='5-6' memory='2097152' unit='KiB'>
<distances>
<sibling id='0' value='21'/>
<sibling id='1' value='31'/>
<sibling id='2' value='21'/>
<sibling id='3' value='10'/>
</distances>
</cell>
</numa>
</cpu>
Xen xl.cfg domain configuration:
vnuma = [["pnode=0","size=2048","vcpus=0-1","vdistances=10,21,31,21"],
["pnode=1","size=2048","vcpus=2-3","vdistances=21,10,21,31"],
["pnode=2","size=2048","vcpus=4-5","vdistances=31,21,10,21"],
["pnode=3","size=2048","vcpus=6-7","vdistances=21,31,21,10"]]
If there is no XML <distances> description amongst the <cell> data the
conversion schema from xml to native will generate 10 for local and 20
for all remote instances.
Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2017-11-02 15:47:21 +00:00
|
|
|
virBitmapPtr
|
|
|
|
virDomainNumaSetNodeCpumask(virDomainNumaPtr numa,
|
|
|
|
size_t node,
|
|
|
|
virBitmapPtr cpumask)
|
|
|
|
{
|
|
|
|
numa->mem_nodes[node].cpumask = cpumask;
|
|
|
|
|
|
|
|
return numa->mem_nodes[node].cpumask;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-02 13:27:30 +00:00
|
|
|
virDomainMemoryAccess
|
2015-02-16 16:28:48 +00:00
|
|
|
virDomainNumaGetNodeMemoryAccessMode(virDomainNumaPtr numa,
|
2015-02-16 17:51:36 +00:00
|
|
|
size_t node)
|
|
|
|
{
|
2015-02-16 16:28:48 +00:00
|
|
|
return numa->mem_nodes[node].memAccess;
|
2015-02-16 17:51:36 +00:00
|
|
|
}
|
2015-02-16 18:14:23 +00:00
|
|
|
|
|
|
|
|
2018-05-11 13:08:53 +00:00
|
|
|
virTristateBool
|
|
|
|
virDomainNumaGetNodeDiscard(virDomainNumaPtr numa,
|
|
|
|
size_t node)
|
|
|
|
{
|
|
|
|
return numa->mem_nodes[node].discard;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-16 18:14:23 +00:00
|
|
|
unsigned long long
|
2015-02-16 16:28:48 +00:00
|
|
|
virDomainNumaGetNodeMemorySize(virDomainNumaPtr numa,
|
2015-02-16 18:14:23 +00:00
|
|
|
size_t node)
|
|
|
|
{
|
2015-02-16 16:28:48 +00:00
|
|
|
return numa->mem_nodes[node].mem;
|
2015-02-16 18:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2015-02-16 16:28:48 +00:00
|
|
|
virDomainNumaSetNodeMemorySize(virDomainNumaPtr numa,
|
2015-02-16 18:14:23 +00:00
|
|
|
size_t node,
|
|
|
|
unsigned long long size)
|
|
|
|
{
|
2015-02-16 16:28:48 +00:00
|
|
|
numa->mem_nodes[node].mem = size;
|
2015-02-16 18:14:23 +00:00
|
|
|
}
|
2015-02-16 19:15:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
unsigned long long
|
|
|
|
virDomainNumaGetMemorySize(virDomainNumaPtr numa)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
unsigned long long ret = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < numa->nmem_nodes; i++)
|
|
|
|
ret += numa->mem_nodes[i].mem;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|