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",
|
2021-04-13 06:38:06 +00:00
|
|
|
"restrictive",
|
2019-01-20 16:30:15 +00:00
|
|
|
);
|
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
|
|
|
|
2021-05-20 15:00:50 +00:00
|
|
|
VIR_ENUM_IMPL(virNumaCacheAssociativity,
|
|
|
|
VIR_NUMA_CACHE_ASSOCIATIVITY_LAST,
|
2020-05-27 09:46:33 +00:00
|
|
|
"none",
|
|
|
|
"direct",
|
|
|
|
"full",
|
|
|
|
);
|
|
|
|
|
2021-05-20 15:00:50 +00:00
|
|
|
VIR_ENUM_IMPL(virNumaCachePolicy,
|
|
|
|
VIR_NUMA_CACHE_POLICY_LAST,
|
2020-05-27 09:46:33 +00:00
|
|
|
"none",
|
|
|
|
"writeback",
|
|
|
|
"writethrough",
|
|
|
|
);
|
|
|
|
|
2021-05-17 15:14:16 +00:00
|
|
|
VIR_ENUM_IMPL(virMemoryLatency,
|
|
|
|
VIR_MEMORY_LATENCY_LAST,
|
2020-05-27 09:46:33 +00:00
|
|
|
"none",
|
|
|
|
"access",
|
|
|
|
"read",
|
|
|
|
"write"
|
|
|
|
);
|
|
|
|
|
2015-02-11 13:54:59 +00:00
|
|
|
typedef struct _virDomainNumaNode virDomainNumaNode;
|
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;
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *nodeset;
|
2014-06-09 13:00:22 +00:00
|
|
|
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 */
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *cpumask; /* bitmap of vCPUs corresponding to the node */
|
|
|
|
virBitmap *nodeset; /* host memory nodes where this guest node resides */
|
2015-02-16 16:28:48 +00:00
|
|
|
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
|
|
|
|
2021-05-14 13:25:47 +00:00
|
|
|
virNumaDistance *distances; /* remote node distances */
|
2017-11-02 15:47:20 +00:00
|
|
|
size_t ndistances;
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-05-03 12:11:26 +00:00
|
|
|
virNumaCache *caches;
|
2020-05-27 09:46:33 +00:00
|
|
|
size_t ncaches;
|
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;
|
|
|
|
|
2021-05-03 12:45:27 +00:00
|
|
|
virNumaInterconnect *interconnects;
|
2020-05-27 09:46:33 +00:00
|
|
|
size_t ninterconnects;
|
|
|
|
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneNodeSpecified(virDomainNuma *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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneNodeParseXML(virDomainNuma *numa,
|
2014-07-15 09:39:44 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2014-08-25 22:26:56 +00:00
|
|
|
int n = 0;
|
2014-07-15 09:39:44 +00:00
|
|
|
size_t i = 0;
|
2021-05-13 15:31:58 +00:00
|
|
|
g_autofree xmlNodePtr *nodes = NULL;
|
2014-07-15 09:39:44 +00:00
|
|
|
|
|
|
|
if ((n = virXPathNodeSet("./numatune/memnode", ctxt, &nodes)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot extract memnode nodes"));
|
2021-05-13 15:31:58 +00:00
|
|
|
return -1;
|
2014-07-15 09:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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."));
|
2021-05-13 15:31:58 +00:00
|
|
|
return -1;
|
2014-07-15 09:39:44 +00:00
|
|
|
}
|
|
|
|
|
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"));
|
2021-05-13 15:31:58 +00:00
|
|
|
return -1;
|
2014-07-15 09:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
unsigned int cellid = 0;
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaNode *mem_node = NULL;
|
2014-07-15 09:39:44 +00:00
|
|
|
xmlNodePtr cur_node = nodes[i];
|
2021-05-13 15:31:58 +00:00
|
|
|
g_autofree char *tmp = NULL;
|
2014-07-15 09:39:44 +00:00
|
|
|
|
2021-05-13 15:31:57 +00:00
|
|
|
if (virXMLPropUInt(cur_node, "cellid", 10, VIR_XML_PROP_REQUIRED,
|
|
|
|
&cellid) < 0)
|
2021-05-13 15:31:58 +00:00
|
|
|
return -1;
|
2014-07-15 09:39:44 +00:00
|
|
|
|
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"));
|
2021-05-13 15:31:58 +00:00
|
|
|
return -1;
|
2014-07-15 09:39:44 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2021-05-13 15:31:58 +00:00
|
|
|
return -1;
|
2014-07-15 09:39:44 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 15:31:57 +00:00
|
|
|
if (virXMLPropEnumDefault(cur_node, "mode",
|
|
|
|
virDomainNumatuneMemModeTypeFromString,
|
|
|
|
VIR_XML_PROP_NONE, &mem_node->mode,
|
|
|
|
VIR_DOMAIN_NUMATUNE_MEM_STRICT) < 0)
|
2021-05-13 15:31:58 +00:00
|
|
|
return -1;
|
2021-05-13 15:31:57 +00:00
|
|
|
|
|
|
|
if (numa->memory.mode == VIR_DOMAIN_NUMATUNE_MEM_RESTRICTIVE &&
|
|
|
|
mem_node->mode != VIR_DOMAIN_NUMATUNE_MEM_RESTRICTIVE) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("'restrictive' mode is required in memnode element "
|
|
|
|
"when mode is 'restrictive' in memory element"));
|
2021-05-13 15:31:58 +00:00
|
|
|
return -1;
|
2014-07-15 09:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tmp = virXMLPropString(cur_node, "nodeset");
|
|
|
|
if (!tmp) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Missing required nodeset attribute "
|
|
|
|
"in memnode element"));
|
2021-05-13 15:31:58 +00:00
|
|
|
return -1;
|
2014-07-15 09:39:44 +00:00
|
|
|
}
|
2016-06-17 12:56:45 +00:00
|
|
|
if (virBitmapParse(tmp, &mem_node->nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
2021-05-13 15:31:58 +00:00
|
|
|
return -1;
|
2015-04-10 09:11:21 +00:00
|
|
|
|
|
|
|
if (virBitmapIsAllClear(mem_node->nodeset)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Invalid value of 'nodeset': %s"), tmp);
|
2021-05-13 15:31:58 +00:00
|
|
|
return -1;
|
2015-04-10 09:11:21 +00:00
|
|
|
}
|
2014-07-15 09:39:44 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 15:31:58 +00:00
|
|
|
return 0;
|
2014-07-15 09:39:44 +00:00
|
|
|
}
|
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneParseXML(virDomainNuma *numa,
|
2014-07-21 09:32:33 +00:00
|
|
|
bool placement_static,
|
2014-06-09 13:00:22 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
|
|
|
{
|
2021-12-07 16:17:13 +00:00
|
|
|
g_autofree char *modestr = NULL;
|
2014-06-09 13:00:22 +00:00
|
|
|
int mode = -1;
|
2021-12-07 16:17:13 +00:00
|
|
|
g_autofree char *placementstr = NULL;
|
2014-06-09 13:00:22 +00:00
|
|
|
int placement = -1;
|
2021-12-07 16:17:13 +00:00
|
|
|
g_autofree char *nodesetstr = NULL;
|
|
|
|
g_autoptr(virBitmap) nodeset = NULL;
|
2014-06-09 13:00:22 +00:00
|
|
|
xmlNodePtr node = NULL;
|
|
|
|
|
2022-10-05 10:33:19 +00:00
|
|
|
if (virXPathBoolean("count(./numatune) > 1", ctxt) == 1) {
|
2014-06-09 13:00:22 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("only one numatune is supported"));
|
2021-12-07 16:17:13 +00:00
|
|
|
return -1;
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2021-12-07 16:17:13 +00:00
|
|
|
if ((modestr = virXMLPropString(node, "mode")) &&
|
|
|
|
(mode = virDomainNumatuneMemModeTypeFromString(modestr)) < 0) {
|
2015-02-12 15:04:45 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2021-12-07 16:17:13 +00:00
|
|
|
_("Unsupported NUMA memory tuning mode '%s'"), modestr);
|
|
|
|
return -1;
|
2015-02-12 15:04:45 +00:00
|
|
|
}
|
2014-06-09 13:00:22 +00:00
|
|
|
|
2021-12-07 16:17:13 +00:00
|
|
|
if ((placementstr = virXMLPropString(node, "placement")) &&
|
|
|
|
(placement = virDomainNumatunePlacementTypeFromString(placementstr)) < 0) {
|
2015-02-12 15:04:45 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2021-12-07 16:17:13 +00:00
|
|
|
_("Unsupported NUMA memory placement mode '%s'"), placementstr);
|
|
|
|
return -1;
|
2015-02-12 15:04:45 +00:00
|
|
|
}
|
2014-06-09 13:00:22 +00:00
|
|
|
|
2021-12-07 16:17:13 +00:00
|
|
|
if ((nodesetstr = virXMLPropString(node, "nodeset"))) {
|
|
|
|
if (virBitmapParse(nodesetstr, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
|
|
|
return -1;
|
2015-04-10 09:11:21 +00:00
|
|
|
|
|
|
|
if (virBitmapIsAllClear(nodeset)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2021-12-07 16:17:13 +00:00
|
|
|
_("Invalid value of 'nodeset': %s"), nodesetstr);
|
|
|
|
return -1;
|
2015-04-10 09:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
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)
|
2021-12-07 16:17:13 +00:00
|
|
|
return -1;
|
2014-06-09 13:00:22 +00:00
|
|
|
|
2015-02-16 16:28:48 +00:00
|
|
|
if (virDomainNumatuneNodeParseXML(numa, ctxt) < 0)
|
2021-12-07 16:17:13 +00:00
|
|
|
return -1;
|
2014-07-15 09:39:44 +00:00
|
|
|
|
2021-12-07 16:17:13 +00:00
|
|
|
return 0;
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneFormatXML(virBuffer *buf,
|
|
|
|
virDomainNuma *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++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaNode *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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaFree(virDomainNuma *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)
|
2021-02-03 19:34:14 +00:00
|
|
|
g_free(numa->mem_nodes[i].distances);
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-02-03 19:34:14 +00:00
|
|
|
g_free(numa->mem_nodes[i].caches);
|
2015-02-16 16:28:48 +00:00
|
|
|
}
|
2021-02-03 19:34:14 +00:00
|
|
|
g_free(numa->mem_nodes);
|
2014-06-09 13:00:22 +00:00
|
|
|
|
2021-02-03 19:34:14 +00:00
|
|
|
g_free(numa->interconnects);
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-02-03 19:34:14 +00:00
|
|
|
g_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
|
|
|
|
*/
|
2021-03-11 07:16:13 +00:00
|
|
|
int virDomainNumatuneGetMode(virDomainNuma *numatune,
|
2015-05-19 09:55:26 +00:00
|
|
|
int cellid,
|
|
|
|
virDomainNumatuneMemMode *mode)
|
2014-06-09 13:00:22 +00:00
|
|
|
{
|
2015-05-19 09:55:26 +00:00
|
|
|
virDomainNumatuneMemMode tmp_mode;
|
|
|
|
|
2014-06-26 17:46:45 +00:00
|
|
|
if (!numatune)
|
2019-10-21 18:18:51 +00:00
|
|
|
return -1;
|
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
|
2019-10-21 18:18:51 +00:00
|
|
|
return -1;
|
2014-06-26 17:46:45 +00:00
|
|
|
|
2015-05-19 09:55:26 +00:00
|
|
|
if (mode)
|
|
|
|
*mode = tmp_mode;
|
2019-10-21 18:18:51 +00:00
|
|
|
|
|
|
|
return 0;
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *
|
|
|
|
virDomainNumatuneGetNodeset(virDomainNuma *numatune,
|
|
|
|
virBitmap *auto_nodeset,
|
2014-06-26 17:46:45 +00:00
|
|
|
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 *
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneFormatNodeset(virDomainNuma *numatune,
|
|
|
|
virBitmap *auto_nodeset,
|
2014-06-26 17:46:45 +00:00
|
|
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneMaybeGetNodeset(virDomainNuma *numatune,
|
|
|
|
virBitmap *auto_nodeset,
|
|
|
|
virBitmap **retNodeset,
|
2015-01-15 21:40:15 +00:00
|
|
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneMaybeFormatNodeset(virDomainNuma *numatune,
|
|
|
|
virBitmap *auto_nodeset,
|
2015-01-15 21:40:15 +00:00
|
|
|
char **mask,
|
|
|
|
int cellid)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *nodeset;
|
2015-01-15 21:40:15 +00:00
|
|
|
|
|
|
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneSet(virDomainNuma *numa,
|
2014-07-21 09:32:33 +00:00
|
|
|
bool placement_static,
|
2014-06-09 13:00:22 +00:00
|
|
|
int placement,
|
|
|
|
int mode,
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *nodeset)
|
2014-06-09 13:00:22 +00:00
|
|
|
{
|
|
|
|
/* 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);
|
2019-10-21 18:18:51 +00:00
|
|
|
return -1;
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
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);
|
2019-10-21 18:18:51 +00:00
|
|
|
return -1;
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-10-02 08:34:53 +00:00
|
|
|
numa->memory.nodeset = virBitmapNewCopy(nodeset);
|
|
|
|
|
2014-06-09 13:00:22 +00:00
|
|
|
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'"));
|
2019-10-21 18:18:51 +00:00
|
|
|
return -1;
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2022-01-28 17:42:45 +00:00
|
|
|
g_clear_pointer(&numa->memory.nodeset, virBitmapFree);
|
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
|
|
|
|
2019-10-21 18:18:51 +00:00
|
|
|
return 0;
|
2014-06-09 13:00:22 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:46:45 +00:00
|
|
|
static bool
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaNodesEqual(virDomainNuma *n1,
|
|
|
|
virDomainNuma *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++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaNode *nd1 = &n1->mem_nodes[i];
|
|
|
|
virDomainNumaNode *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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaEquals(virDomainNuma *n1,
|
|
|
|
virDomainNuma *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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneHasPlacementAuto(virDomainNuma *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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneHasPerNodeBinding(virDomainNuma *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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneSpecifiedMaxNode(virDomainNuma *numatune)
|
2014-11-04 02:44:40 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *nodemask = NULL;
|
2014-11-04 02:44:40 +00:00
|
|
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumatuneNodesetIsAvailable(virDomainNuma *numatune,
|
|
|
|
virBitmap *auto_nodeset)
|
2014-11-06 11:16:54 +00:00
|
|
|
{
|
|
|
|
size_t i = 0;
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *b = NULL;
|
2014-11-06 11:16:54 +00:00
|
|
|
|
|
|
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaDefNodeDistanceParseXML(virDomainNuma *def,
|
2017-11-02 15:47:20 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
unsigned int cur_cell)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int sibling;
|
|
|
|
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++) {
|
2021-05-17 07:15:24 +00:00
|
|
|
virNumaDistance *ldist;
|
|
|
|
virNumaDistance *rdist;
|
2017-11-02 15:47:20 +00:00
|
|
|
unsigned int sibling_id, sibling_value;
|
|
|
|
|
2021-05-13 15:31:59 +00:00
|
|
|
if (virXMLPropUInt(nodes[i], "id", 10, VIR_XML_PROP_REQUIRED,
|
|
|
|
&sibling_id) < 0)
|
2017-11-02 15:47:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2021-05-13 15:31:59 +00:00
|
|
|
if (virXMLPropUInt(nodes[i], "value", 10, VIR_XML_PROP_REQUIRED,
|
|
|
|
&sibling_value) < 0)
|
2017-11-02 15:47:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* 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) {
|
2021-05-17 07:15:24 +00:00
|
|
|
ldist = g_new0(virNumaDistance, ndistances);
|
2017-11-02 15:47:20 +00:00
|
|
|
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) {
|
2021-05-17 07:15:24 +00:00
|
|
|
rdist = g_new0(virNumaDistance, ndistances);
|
2017-11-02 15:47:20 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-05-27 09:46:33 +00:00
|
|
|
|
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaDefNodeCacheParseXML(virDomainNuma *def,
|
2020-05-27 09:46:33 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
unsigned int cur_cell)
|
|
|
|
{
|
|
|
|
g_autofree xmlNodePtr *nodes = NULL;
|
|
|
|
int n;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if ((n = virXPathNodeSet("./cache", ctxt, &nodes)) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2021-05-20 15:00:50 +00:00
|
|
|
def->mem_nodes[cur_cell].caches = g_new0(virNumaCache, n);
|
2020-05-27 09:46:33 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2020-07-28 19:47:48 +00:00
|
|
|
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
2021-05-20 15:00:50 +00:00
|
|
|
virNumaCache *cache = &def->mem_nodes[cur_cell].caches[i];
|
2020-05-27 09:46:33 +00:00
|
|
|
g_autofree char *tmp = NULL;
|
|
|
|
unsigned int level;
|
|
|
|
int associativity;
|
|
|
|
int policy;
|
|
|
|
unsigned long long size;
|
|
|
|
unsigned long long line;
|
|
|
|
|
|
|
|
if (!(tmp = virXMLPropString(nodes[i], "level"))) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Missing 'level' attribute in cache "
|
|
|
|
"element for NUMA node %d"),
|
|
|
|
cur_cell);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virStrToLong_uip(tmp, NULL, 10, &level) < 0 ||
|
|
|
|
level == 0) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Invalid 'level' attribute in cache "
|
|
|
|
"element for NUMA node %d"),
|
|
|
|
cur_cell);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
|
|
|
|
if (!(tmp = virXMLPropString(nodes[i], "associativity"))) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Missing 'associativity' attribute in cache "
|
|
|
|
"element for NUMA node %d"),
|
|
|
|
cur_cell);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-05-20 15:00:50 +00:00
|
|
|
if ((associativity = virNumaCacheAssociativityTypeFromString(tmp)) < 0) {
|
2020-05-27 09:46:33 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Invalid cache associativity '%s'"),
|
|
|
|
tmp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
|
|
|
|
if (!(tmp = virXMLPropString(nodes[i], "policy"))) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Missing 'policy' attribute in cache "
|
|
|
|
"element for NUMA node %d"),
|
|
|
|
cur_cell);
|
|
|
|
}
|
|
|
|
|
2021-05-20 15:00:50 +00:00
|
|
|
if ((policy = virNumaCachePolicyTypeFromString(tmp)) < 0) {
|
2020-05-27 09:46:33 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Invalid cache policy '%s'"),
|
|
|
|
tmp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
|
|
|
|
ctxt->node = nodes[i];
|
|
|
|
if (virDomainParseMemory("./size/@value", "./size/unit",
|
|
|
|
ctxt, &size, true, false) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virParseScaledValue("./line/@value", "./line/unit",
|
|
|
|
ctxt, &line, 1, ULLONG_MAX, true) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2021-05-20 15:00:50 +00:00
|
|
|
*cache = (virNumaCache){level, size, line, associativity, policy};
|
2020-05-27 09:46:33 +00:00
|
|
|
def->mem_nodes[cur_cell].ncaches++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-11 11:27:53 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaDefParseXML(virDomainNuma *def,
|
2020-05-28 14:52:22 +00:00
|
|
|
xmlXPathContextPtr ctxt)
|
2015-02-11 11:27:53 +00:00
|
|
|
{
|
2021-05-13 15:32:01 +00:00
|
|
|
g_autofree xmlNodePtr *cell = NULL;
|
|
|
|
g_autofree xmlNodePtr *interconnect = 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
|
|
|
|
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
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
if ((n = virXPathNodeSet("./cpu/numa[1]/cell", ctxt, &cell)) <= 0) {
|
2015-02-11 12:31:09 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("NUMA topology defined without NUMA cells"));
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2015-02-11 12:31:09 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 19:14:18 +00:00
|
|
|
def->mem_nodes = g_new0(struct _virDomainNumaNode, n);
|
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++) {
|
2020-07-28 19:47:48 +00:00
|
|
|
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
2021-05-13 15:32:01 +00:00
|
|
|
g_autofree char *tmp = NULL;
|
2015-02-12 08:37:13 +00:00
|
|
|
int rc;
|
2021-05-13 15:32:00 +00:00
|
|
|
unsigned int cur_cell;
|
2015-02-11 12:31:09 +00:00
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
if ((rc = virXMLPropUInt(cell[i], "id", 10, VIR_XML_PROP_NONE,
|
2021-05-13 15:32:00 +00:00
|
|
|
&cur_cell)) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2021-05-13 15:32:00 +00:00
|
|
|
if (rc == 0)
|
|
|
|
cur_cell = i;
|
|
|
|
|
|
|
|
/* cells are in order of parsing or explicitly numbered */
|
|
|
|
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"));
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2015-02-11 12:31:09 +00:00
|
|
|
}
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2020-05-27 11:42:22 +00:00
|
|
|
if (def->mem_nodes[cur_cell].mem) {
|
2015-02-11 12:31:09 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Duplicate NUMA cell info for cell id '%u'"),
|
|
|
|
cur_cell);
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2015-02-11 12:31:09 +00:00
|
|
|
}
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
if ((tmp = virXMLPropString(cell[i], "cpus"))) {
|
2020-05-27 11:42:22 +00:00
|
|
|
g_autoptr(virBitmap) cpumask = NULL;
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2020-05-27 11:42:22 +00:00
|
|
|
if (virBitmapParse(tmp, &cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2015-02-12 08:37:13 +00:00
|
|
|
|
2020-05-27 11:42:22 +00:00
|
|
|
if (!virBitmapIsAllClear(cpumask))
|
|
|
|
def->mem_nodes[cur_cell].cpumask = g_steal_pointer(&cpumask);
|
2015-02-11 16:38:29 +00:00
|
|
|
}
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2015-09-08 04:59:10 +00:00
|
|
|
for (j = 0; j < n; j++) {
|
2020-05-27 11:42:22 +00:00
|
|
|
if (j == cur_cell ||
|
|
|
|
!def->mem_nodes[j].cpumask ||
|
|
|
|
!def->mem_nodes[cur_cell].cpumask)
|
2015-09-08 04:59:10 +00:00
|
|
|
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);
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2015-05-05 10:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
ctxt->node = cell[i];
|
2015-02-11 12:31:09 +00:00
|
|
|
if (virDomainParseMemory("./@memory", "./@unit", ctxt,
|
2015-02-16 16:28:48 +00:00
|
|
|
&def->mem_nodes[cur_cell].mem, true, false) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2015-02-11 11:27:53 +00:00
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
if (virXMLPropEnum(cell[i], "memAccess",
|
2021-05-13 15:32:00 +00:00
|
|
|
virDomainMemoryAccessTypeFromString,
|
|
|
|
VIR_XML_PROP_NONZERO,
|
|
|
|
&def->mem_nodes[cur_cell].memAccess) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2018-05-11 13:08:53 +00:00
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
if (virXMLPropTristateBool(cell[i], "discard", VIR_XML_PROP_NONE,
|
2021-05-13 15:32:00 +00:00
|
|
|
&def->mem_nodes[cur_cell].discard) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2018-05-11 13:08:53 +00:00
|
|
|
|
2017-11-02 15:47:20 +00:00
|
|
|
/* Parse NUMA distances info */
|
|
|
|
if (virDomainNumaDefNodeDistanceParseXML(def, ctxt, cur_cell) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2020-05-27 09:46:33 +00:00
|
|
|
|
|
|
|
/* Parse cache info */
|
|
|
|
if (virDomainNumaDefNodeCacheParseXML(def, ctxt, cur_cell) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2020-05-27 09:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((n = virXPathNodeSet("./cpu/numa[1]/interconnects[1]/latency|"
|
2021-05-13 15:32:01 +00:00
|
|
|
"./cpu/numa[1]/interconnects[1]/bandwidth", ctxt,
|
|
|
|
&interconnect)) < 0)
|
|
|
|
return -1;
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-05-17 15:14:16 +00:00
|
|
|
def->interconnects = g_new0(virNumaInterconnect, n);
|
2020-05-27 09:46:33 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2021-05-17 15:14:16 +00:00
|
|
|
virNumaInterconnectType type;
|
2020-05-27 09:46:33 +00:00
|
|
|
unsigned int initiator;
|
|
|
|
unsigned int target;
|
|
|
|
unsigned int cache = 0;
|
2021-05-17 15:14:16 +00:00
|
|
|
virMemoryLatency accessType;
|
2020-05-27 09:46:33 +00:00
|
|
|
unsigned long long value;
|
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
if (virXMLNodeNameEqual(interconnect[i], "latency")) {
|
2021-05-17 15:14:16 +00:00
|
|
|
type = VIR_NUMA_INTERCONNECT_TYPE_LATENCY;
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
if (virXMLPropULongLong(interconnect[i], "value", 10,
|
2021-05-13 15:32:00 +00:00
|
|
|
VIR_XML_PROP_REQUIRED, &value) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
|
|
|
} else if (virXMLNodeNameEqual(interconnect[i], "bandwidth")) {
|
2020-07-28 19:47:48 +00:00
|
|
|
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
2021-05-17 15:14:16 +00:00
|
|
|
type = VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH;
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
ctxt->node = interconnect[i];
|
2020-05-27 09:46:33 +00:00
|
|
|
|
|
|
|
if (virDomainParseMemory("./@value", "./@unit", ctxt, &value, true, false) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2020-05-27 09:46:33 +00:00
|
|
|
} else {
|
|
|
|
/* Ignore yet unknown child elements. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
if (virXMLPropUInt(interconnect[i], "initiator", 10, VIR_XML_PROP_REQUIRED,
|
2021-05-13 15:32:00 +00:00
|
|
|
&initiator) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
if (virXMLPropUInt(interconnect[i], "target", 10, VIR_XML_PROP_REQUIRED,
|
2021-05-13 15:32:00 +00:00
|
|
|
&target) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
if (virXMLPropUInt(interconnect[i], "cache", 10, VIR_XML_PROP_NONE,
|
2021-05-13 15:32:00 +00:00
|
|
|
&cache) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
if (virXMLPropEnum(interconnect[i], "type",
|
2021-05-17 15:14:16 +00:00
|
|
|
virMemoryLatencyTypeFromString,
|
2021-05-13 15:32:00 +00:00
|
|
|
VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
|
|
|
|
&accessType) < 0)
|
2021-05-13 15:32:01 +00:00
|
|
|
return -1;
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-05-17 15:14:16 +00:00
|
|
|
def->interconnects[i] = (virNumaInterconnect) {type, initiator, target,
|
|
|
|
cache, accessType, value};
|
2020-05-27 09:46:33 +00:00
|
|
|
def->ninterconnects++;
|
2015-02-11 11:27:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 15:32:01 +00:00
|
|
|
return 0;
|
2015-02-11 11:27:53 +00:00
|
|
|
}
|
2015-02-11 13:26:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaDefFormatXML(virBuffer *buf,
|
|
|
|
virDomainNuma *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-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++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *cpumask = virDomainNumaGetNodeCpumask(def, i);
|
2021-05-03 11:25:47 +00:00
|
|
|
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
|
|
|
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
|
2017-11-02 15:47:20 +00:00
|
|
|
|
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
|
|
|
|
2021-05-03 11:25:47 +00:00
|
|
|
virBufferAsprintf(&attrBuf, " id='%zu'", i);
|
2020-05-27 11:42:22 +00:00
|
|
|
|
|
|
|
if (cpumask) {
|
|
|
|
g_autofree char *cpustr = virBitmapFormat(cpumask);
|
|
|
|
|
|
|
|
if (!cpustr)
|
|
|
|
return -1;
|
2021-05-03 11:25:47 +00:00
|
|
|
virBufferAsprintf(&attrBuf, " cpus='%s'", cpustr);
|
2020-05-27 11:42:22 +00:00
|
|
|
}
|
2021-05-03 11:25:47 +00:00
|
|
|
virBufferAsprintf(&attrBuf, " memory='%llu'",
|
2015-02-16 18:14:23 +00:00
|
|
|
virDomainNumaGetNodeMemorySize(def, i));
|
2021-05-03 11:25:47 +00:00
|
|
|
virBufferAddLit(&attrBuf, " unit='KiB'");
|
2015-02-11 13:26:19 +00:00
|
|
|
if (memAccess)
|
2021-05-03 11:25:47 +00:00
|
|
|
virBufferAsprintf(&attrBuf, " 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)
|
2021-05-03 11:25:47 +00:00
|
|
|
virBufferAsprintf(&attrBuf, " discard='%s'",
|
2018-05-11 13:08:53 +00:00
|
|
|
virTristateBoolTypeToString(discard));
|
|
|
|
|
2021-05-14 13:25:47 +00:00
|
|
|
virNumaDistanceFormat(&childBuf,
|
|
|
|
def->mem_nodes[i].distances,
|
|
|
|
def->mem_nodes[i].ndistances);
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-05-03 12:11:26 +00:00
|
|
|
virNumaCacheFormat(&childBuf,
|
|
|
|
def->mem_nodes[i].caches,
|
|
|
|
def->mem_nodes[i].ncaches);
|
2021-05-03 11:25:47 +00:00
|
|
|
|
|
|
|
virXMLFormatElement(buf, "cell", &attrBuf, &childBuf);
|
2015-02-11 13:26:19 +00:00
|
|
|
}
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2021-05-03 12:45:27 +00:00
|
|
|
virNumaInterconnectFormat(buf, def->interconnects, def->ninterconnects);
|
2020-05-27 09:46:33 +00:00
|
|
|
|
2015-02-11 13:26:19 +00:00
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</numa>\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-02-12 08:37:13 +00:00
|
|
|
|
|
|
|
|
2020-05-28 15:23:00 +00:00
|
|
|
int
|
|
|
|
virDomainNumaDefValidate(const virDomainNuma *def)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
if (!def)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < def->nmem_nodes; i++) {
|
|
|
|
const virDomainNumaNode *node = &def->mem_nodes[i];
|
2020-10-01 15:02:16 +00:00
|
|
|
g_autoptr(virBitmap) levelsSeen = virBitmapNew(0);
|
2020-05-28 15:23:00 +00:00
|
|
|
|
|
|
|
for (j = 0; j < node->ncaches; j++) {
|
2021-05-20 15:00:50 +00:00
|
|
|
const virNumaCache *cache = &node->caches[j];
|
2020-05-28 15:23:00 +00:00
|
|
|
|
|
|
|
/* Relax this if there's ever fourth layer of cache */
|
|
|
|
if (cache->level > 3) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Ain't nobody heard of that much cache level"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virBitmapIsBitSet(levelsSeen, cache->level)) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("Cache level '%u' already defined"),
|
|
|
|
cache->level);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:55:46 +00:00
|
|
|
virBitmapSetBitExpand(levelsSeen, cache->level);
|
2020-05-28 15:23:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < def->ninterconnects; i++) {
|
2021-05-17 15:14:16 +00:00
|
|
|
const virNumaInterconnect *l = &def->interconnects[i];
|
2020-05-28 15:23:00 +00:00
|
|
|
|
|
|
|
if (l->initiator >= def->nmem_nodes) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("'initiator' refers to a non-existent NUMA node"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l->target >= def->nmem_nodes) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("'target' refers to a non-existent NUMA node"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!def->mem_nodes[l->initiator].cpumask) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("NUMA nodes without CPUs can't be initiator"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l->cache > 0) {
|
|
|
|
for (j = 0; j < def->mem_nodes[l->target].ncaches; j++) {
|
2021-05-20 15:00:50 +00:00
|
|
|
const virNumaCache *cache = &def->mem_nodes[l->target].caches[j];
|
2020-05-28 15:23:00 +00:00
|
|
|
|
|
|
|
if (l->cache == cache->level)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == def->mem_nodes[l->target].ncaches) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("'cache' refers to a non-existent NUMA node cache"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < i; j++) {
|
2021-05-17 15:14:16 +00:00
|
|
|
const virNumaInterconnect *ll = &def->interconnects[j];
|
2020-05-28 15:23:00 +00:00
|
|
|
|
|
|
|
if (l->type == ll->type &&
|
|
|
|
l->initiator == ll->initiator &&
|
|
|
|
l->target == ll->target &&
|
|
|
|
l->cache == ll->cache &&
|
|
|
|
l->accessType == ll->accessType) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Duplicate info for NUMA latencies"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (l->initiator != l->target &&
|
|
|
|
l->initiator == ll->target &&
|
|
|
|
l->target == ll->initiator) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Link already defined"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-12 08:37:13 +00:00
|
|
|
unsigned int
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaGetCPUCountTotal(virDomainNuma *numa)
|
2015-02-12 08:37:13 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
unsigned int ret = 0;
|
|
|
|
|
2020-05-27 11:42:22 +00:00
|
|
|
for (i = 0; i < numa->nmem_nodes; i++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *cpumask = virDomainNumaGetNodeCpumask(numa, i);
|
2020-05-27 11:42:22 +00:00
|
|
|
|
|
|
|
if (cpumask)
|
|
|
|
ret += virBitmapCountBits(cpumask);
|
|
|
|
}
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaGetMaxCPUID(virDomainNuma *numa)
|
2015-08-07 14:31:57 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
unsigned int ret = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < numa->nmem_nodes; i++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *cpumask = virDomainNumaGetNodeCpumask(numa, i);
|
2015-08-07 14:31:57 +00:00
|
|
|
int bit;
|
|
|
|
|
2020-05-27 11:42:22 +00:00
|
|
|
if (cpumask) {
|
|
|
|
bit = virBitmapLastSetBit(cpumask);
|
|
|
|
if (bit > ret)
|
|
|
|
ret = bit;
|
|
|
|
}
|
2015-08-07 14:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-16 15:42:13 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNuma *
|
2015-02-16 15:42:13 +00:00
|
|
|
virDomainNumaNew(void)
|
|
|
|
{
|
2020-10-07 19:14:18 +00:00
|
|
|
return g_new0(virDomainNuma, 1);
|
2015-02-16 15:42:13 +00:00
|
|
|
}
|
2015-02-16 17:11:46 +00:00
|
|
|
|
|
|
|
|
2015-02-16 19:34:37 +00:00
|
|
|
bool
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaCheckABIStability(virDomainNuma *src,
|
|
|
|
virDomainNuma *tgt)
|
2015-02-16 19:34:37 +00:00
|
|
|
{
|
|
|
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaGetNodeCount(virDomainNuma *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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaSetNodeCount(virDomainNuma *numa, size_t nmem_nodes)
|
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
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-10-07 19:14:18 +00:00
|
|
|
numa->mem_nodes = g_new0(struct _virDomainNumaNode, nmem_nodes);
|
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
|
|
|
|
|
|
|
numa->nmem_nodes = nmem_nodes;
|
|
|
|
|
|
|
|
return numa->nmem_nodes;
|
|
|
|
}
|
|
|
|
|
2017-11-14 13:28:11 +00:00
|
|
|
|
|
|
|
bool
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaNodeDistanceIsUsingDefaults(virDomainNuma *numa,
|
2017-11-14 13:28:11 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-09 23:15:11 +00:00
|
|
|
bool
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaNodesDistancesAreBeingSet(virDomainNuma *numa)
|
2019-12-09 23:15:11 +00:00
|
|
|
{
|
|
|
|
size_t ncells = virDomainNumaGetNodeCount(numa);
|
|
|
|
size_t i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < ncells; i++) {
|
|
|
|
for (j = 0; j < ncells; j++) {
|
|
|
|
if (virDomainNumaNodeDistanceIsUsingDefaults(numa, i, j))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaGetNodeDistance(virDomainNuma *numa,
|
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 node,
|
|
|
|
size_t cellid)
|
|
|
|
{
|
2021-05-17 07:15:24 +00:00
|
|
|
virNumaDistance *distances = NULL;
|
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
|
|
|
|
|
|
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaSetNodeDistance(virDomainNuma *numa,
|
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 node,
|
|
|
|
size_t cellid,
|
|
|
|
unsigned int value)
|
|
|
|
{
|
2021-05-17 07:15:24 +00:00
|
|
|
virNumaDistance *distances;
|
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
|
|
|
|
|
|
|
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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaSetNodeDistanceCount(virDomainNuma *numa,
|
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 node,
|
|
|
|
size_t ndistances)
|
|
|
|
{
|
2021-05-17 07:15:24 +00:00
|
|
|
virNumaDistance *distances;
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-05-17 07:15:24 +00:00
|
|
|
distances = g_new0(virNumaDistance, ndistances);
|
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
|
|
|
|
|
|
|
numa->mem_nodes[node].distances = distances;
|
|
|
|
numa->mem_nodes[node].ndistances = ndistances;
|
|
|
|
|
|
|
|
return numa->mem_nodes[node].ndistances;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *
|
|
|
|
virDomainNumaGetNodeCpumask(virDomainNuma *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
|
|
|
|
|
|
|
|
2020-05-27 09:49:51 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaSetNodeCpumask(virDomainNuma *numa,
|
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 node,
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *cpumask)
|
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
|
|
|
{
|
|
|
|
numa->mem_nodes[node].cpumask = cpumask;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-02 13:27:30 +00:00
|
|
|
virDomainMemoryAccess
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaGetNodeMemoryAccessMode(virDomainNuma *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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaGetNodeDiscard(virDomainNuma *numa,
|
2018-05-11 13:08:53 +00:00
|
|
|
size_t node)
|
|
|
|
{
|
|
|
|
return numa->mem_nodes[node].discard;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-16 18:14:23 +00:00
|
|
|
unsigned long long
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaGetNodeMemorySize(virDomainNuma *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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaSetNodeMemorySize(virDomainNuma *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
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaGetMemorySize(virDomainNuma *numa)
|
2015-02-16 19:15:04 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
unsigned long long ret = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < numa->nmem_nodes; i++)
|
|
|
|
ret += numa->mem_nodes[i].mem;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2020-06-10 18:35:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virDomainNumaFillCPUsInNode(virDomainNuma *numa,
|
2020-06-10 18:35:50 +00:00
|
|
|
size_t node,
|
|
|
|
unsigned int maxCpus)
|
|
|
|
{
|
|
|
|
g_autoptr(virBitmap) maxCPUsBitmap = virBitmapNew(maxCpus);
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (node >= virDomainNumaGetNodeCount(numa))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
virBitmapSetAll(maxCPUsBitmap);
|
|
|
|
|
|
|
|
for (i = 0; i < numa->nmem_nodes; i++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virBitmap *nodeCpus = virDomainNumaGetNodeCpumask(numa, i);
|
2020-06-10 18:35:50 +00:00
|
|
|
|
2020-09-30 08:37:29 +00:00
|
|
|
if (i == node || !nodeCpus)
|
2020-06-10 18:35:50 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
virBitmapSubtract(maxCPUsBitmap, nodeCpus);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!virBitmapEqual(numa->mem_nodes[node].cpumask, maxCPUsBitmap)) {
|
|
|
|
virBitmapFree(numa->mem_nodes[node].cpumask);
|
|
|
|
numa->mem_nodes[node].cpumask = g_steal_pointer(&maxCPUsBitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-05-29 12:55:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
virDomainNumaHasHMAT(const virDomainNuma *numa)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!numa)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (numa->ninterconnects)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (i = 0; i < numa->nmem_nodes; i++) {
|
|
|
|
if (numa->mem_nodes[i].ncaches)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
virDomainNumaGetNodeCacheCount(const virDomainNuma *numa,
|
|
|
|
size_t node)
|
|
|
|
{
|
|
|
|
if (!numa || node >= numa->nmem_nodes)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return numa->mem_nodes[node].ncaches;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
virDomainNumaGetNodeCache(const virDomainNuma *numa,
|
|
|
|
size_t node,
|
|
|
|
size_t cache,
|
|
|
|
unsigned int *level,
|
|
|
|
unsigned int *size,
|
|
|
|
unsigned int *line,
|
2021-05-20 15:00:50 +00:00
|
|
|
virNumaCacheAssociativity *associativity,
|
|
|
|
virNumaCachePolicy *policy)
|
2020-05-29 12:55:57 +00:00
|
|
|
{
|
|
|
|
const virDomainNumaNode *cell;
|
|
|
|
|
|
|
|
if (!numa || node >= numa->nmem_nodes)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
cell = &numa->mem_nodes[node];
|
|
|
|
|
|
|
|
if (cache >= cell->ncaches)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*level = cell->caches[cache].level;
|
|
|
|
*size = cell->caches[cache].size;
|
|
|
|
*line = cell->caches[cache].line;
|
|
|
|
*associativity = cell->caches[cache].associativity;
|
|
|
|
*policy = cell->caches[cache].policy;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
virDomainNumaGetNodeInitiator(const virDomainNuma *numa,
|
|
|
|
size_t node)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
unsigned int maxBandwidth = 0;
|
|
|
|
ssize_t candidateBandwidth = -1;
|
|
|
|
unsigned int minLatency = UINT_MAX;
|
|
|
|
ssize_t candidateLatency = -1;
|
|
|
|
|
|
|
|
if (!numa || node >= numa->nmem_nodes)
|
|
|
|
return -1;
|
|
|
|
|
2020-07-08 09:28:37 +00:00
|
|
|
/* A NUMA node which has at least one vCPU is initiator to itself by
|
|
|
|
* definition. */
|
|
|
|
if (numa->mem_nodes[node].cpumask)
|
|
|
|
return node;
|
|
|
|
|
|
|
|
/* For the rest, "NUMA node that has best performance (the lowest
|
|
|
|
* latency or largest bandwidth) to this NUMA node." */
|
2020-05-29 12:55:57 +00:00
|
|
|
for (i = 0; i < numa->ninterconnects; i++) {
|
2021-05-17 15:14:16 +00:00
|
|
|
const virNumaInterconnect *l = &numa->interconnects[i];
|
2020-05-29 12:55:57 +00:00
|
|
|
|
|
|
|
if (l->target != node)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (l->type) {
|
2021-05-17 15:14:16 +00:00
|
|
|
case VIR_NUMA_INTERCONNECT_TYPE_LATENCY:
|
2020-05-29 12:55:57 +00:00
|
|
|
if (l->value < minLatency) {
|
|
|
|
minLatency = l->value;
|
|
|
|
candidateLatency = l->initiator;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-05-17 15:14:16 +00:00
|
|
|
case VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH:
|
2020-05-29 12:55:57 +00:00
|
|
|
if (l->value > maxBandwidth) {
|
|
|
|
maxBandwidth = l->value;
|
|
|
|
candidateBandwidth = l->initiator;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (candidateLatency >= 0)
|
|
|
|
return candidateLatency;
|
|
|
|
|
|
|
|
return candidateBandwidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
virDomainNumaGetInterconnectsCount(const virDomainNuma *numa)
|
|
|
|
{
|
|
|
|
if (!numa)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return numa->ninterconnects;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
virDomainNumaGetInterconnect(const virDomainNuma *numa,
|
|
|
|
size_t i,
|
2021-05-17 15:14:16 +00:00
|
|
|
virNumaInterconnectType *type,
|
2020-05-29 12:55:57 +00:00
|
|
|
unsigned int *initiator,
|
|
|
|
unsigned int *target,
|
|
|
|
unsigned int *cache,
|
2021-05-17 15:14:16 +00:00
|
|
|
virMemoryLatency *accessType,
|
2020-05-29 12:55:57 +00:00
|
|
|
unsigned long *value)
|
|
|
|
{
|
2021-05-17 15:14:16 +00:00
|
|
|
const virNumaInterconnect *l;
|
2020-05-29 12:55:57 +00:00
|
|
|
|
|
|
|
if (!numa || i >= numa->ninterconnects)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
l = &numa->interconnects[i];
|
|
|
|
*type = l->type;
|
|
|
|
*initiator = l->initiator;
|
|
|
|
*target = l->target;
|
|
|
|
*cache = l->cache;
|
|
|
|
*accessType = l->accessType;
|
|
|
|
*value = l->value;
|
|
|
|
return 0;
|
|
|
|
}
|
2021-05-14 13:25:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virNumaDistanceFormat(virBuffer *buf,
|
|
|
|
const virNumaDistance *distances,
|
|
|
|
size_t ndistances)
|
|
|
|
{
|
|
|
|
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < ndistances; i++) {
|
|
|
|
if (distances[i].value == 0)
|
|
|
|
continue;
|
|
|
|
virBufferAddLit(&childBuf, "<sibling");
|
|
|
|
virBufferAsprintf(&childBuf, " id='%d'", distances[i].cellid);
|
|
|
|
virBufferAsprintf(&childBuf, " value='%d'", distances[i].value);
|
|
|
|
virBufferAddLit(&childBuf, "/>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
virXMLFormatElement(buf, "distances", NULL, &childBuf);
|
|
|
|
}
|
2021-05-03 12:11:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virNumaCacheFormat(virBuffer *buf,
|
|
|
|
const virNumaCache *caches,
|
|
|
|
size_t ncaches)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < ncaches; i++) {
|
|
|
|
const virNumaCache *cache = &caches[i];
|
|
|
|
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
|
|
|
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
|
|
|
|
|
|
|
|
virBufferAsprintf(&attrBuf, " level='%u'", cache->level);
|
|
|
|
if (cache->associativity) {
|
|
|
|
virBufferAsprintf(&attrBuf, " associativity='%s'",
|
|
|
|
virNumaCacheAssociativityTypeToString(cache->associativity));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cache->policy) {
|
|
|
|
virBufferAsprintf(&attrBuf, " policy='%s'",
|
|
|
|
virNumaCachePolicyTypeToString(cache->policy));
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAsprintf(&childBuf,
|
2022-11-05 00:20:20 +00:00
|
|
|
"<size value='%llu' unit='KiB'/>\n",
|
2021-05-03 12:11:26 +00:00
|
|
|
cache->size);
|
|
|
|
|
|
|
|
if (cache->line) {
|
|
|
|
virBufferAsprintf(&childBuf,
|
|
|
|
"<line value='%u' unit='B'/>\n",
|
|
|
|
cache->line);
|
|
|
|
}
|
|
|
|
|
|
|
|
virXMLFormatElement(buf, "cache", &attrBuf, &childBuf);
|
|
|
|
}
|
|
|
|
}
|
2021-05-03 12:45:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virNumaInterconnectFormat(virBuffer *buf,
|
|
|
|
const virNumaInterconnect *interconnects,
|
|
|
|
size_t ninterconnects)
|
|
|
|
{
|
|
|
|
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < ninterconnects; i++) {
|
|
|
|
const virNumaInterconnect *l = &interconnects[i];
|
|
|
|
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
|
|
|
const char *elem = NULL;
|
|
|
|
|
|
|
|
switch (l->type) {
|
|
|
|
case VIR_NUMA_INTERCONNECT_TYPE_LATENCY:
|
|
|
|
elem = "latency";
|
|
|
|
break;
|
|
|
|
case VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH:
|
|
|
|
elem = "bandwidth";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAsprintf(&attrBuf,
|
|
|
|
" initiator='%u' target='%u'",
|
|
|
|
l->initiator, l->target);
|
|
|
|
|
|
|
|
if (l->cache > 0) {
|
|
|
|
virBufferAsprintf(&attrBuf,
|
|
|
|
" cache='%u'",
|
|
|
|
l->cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAsprintf(&attrBuf,
|
|
|
|
" type='%s' value='%lu'",
|
|
|
|
virMemoryLatencyTypeToString(l->accessType),
|
|
|
|
l->value);
|
|
|
|
|
|
|
|
if (l->type == VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH)
|
|
|
|
virBufferAddLit(&attrBuf, " unit='KiB'");
|
|
|
|
|
|
|
|
virXMLFormatElement(&childBuf, elem, &attrBuf, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
virXMLFormatElement(buf, "interconnects", NULL, &childBuf);
|
|
|
|
}
|