mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
numa: Introduce virNumaGetMaxNode and use it instead of numa_max_node
Avoid necessary checks for the numa library with this helper.
This commit is contained in:
parent
0ce5d94636
commit
f72cfea1ab
@ -1523,6 +1523,7 @@ virNodeSuspendGetTargetMask;
|
|||||||
virDomainNumatuneMemModeTypeFromString;
|
virDomainNumatuneMemModeTypeFromString;
|
||||||
virDomainNumatuneMemModeTypeToString;
|
virDomainNumatuneMemModeTypeToString;
|
||||||
virNumaGetAutoPlacementAdvice;
|
virNumaGetAutoPlacementAdvice;
|
||||||
|
virNumaGetMaxNode;
|
||||||
virNumaIsAvailable;
|
virNumaIsAvailable;
|
||||||
virNumaSetupMemoryPolicy;
|
virNumaSetupMemoryPolicy;
|
||||||
virNumaTuneMemPlacementModeTypeFromString;
|
virNumaTuneMemPlacementModeTypeFromString;
|
||||||
|
@ -988,25 +988,21 @@ int nodeGetMemoryStats(int cellNum ATTRIBUTE_UNUSED,
|
|||||||
int ret;
|
int ret;
|
||||||
char *meminfo_path = NULL;
|
char *meminfo_path = NULL;
|
||||||
FILE *meminfo;
|
FILE *meminfo;
|
||||||
|
int max_node;
|
||||||
|
|
||||||
if (cellNum == VIR_NODE_MEMORY_STATS_ALL_CELLS) {
|
if (cellNum == VIR_NODE_MEMORY_STATS_ALL_CELLS) {
|
||||||
if (VIR_STRDUP(meminfo_path, MEMINFO_PATH) < 0)
|
if (VIR_STRDUP(meminfo_path, MEMINFO_PATH) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
if (!virNumaIsAvailable()) {
|
if ((max_node = virNumaGetMaxNode()) < 0)
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"%s", _("NUMA not supported on this host"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
# if WITH_NUMACTL
|
if (cellNum > max_node) {
|
||||||
if (cellNum > numa_max_node()) {
|
|
||||||
virReportInvalidArg(cellNum,
|
virReportInvalidArg(cellNum,
|
||||||
_("cellNum in %s must be less than or equal to %d"),
|
_("cellNum in %s must be less than or equal to %d"),
|
||||||
__FUNCTION__, numa_max_node());
|
__FUNCTION__, max_node);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
|
|
||||||
if (virAsprintf(&meminfo_path, "%s/node/node%d/meminfo",
|
if (virAsprintf(&meminfo_path, "%s/node/node%d/meminfo",
|
||||||
SYSFS_SYSTEM_PATH, cellNum) < 0)
|
SYSFS_SYSTEM_PATH, cellNum) < 0)
|
||||||
@ -1609,31 +1605,35 @@ nodeCapsInitNUMA(virCapsPtr caps)
|
|||||||
virCapsHostNUMACellCPUPtr cpus = NULL;
|
virCapsHostNUMACellCPUPtr cpus = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int max_n_cpus = NUMA_MAX_N_CPUS;
|
int max_n_cpus = NUMA_MAX_N_CPUS;
|
||||||
|
int mask_n_bytes = max_n_cpus / 8;
|
||||||
int ncpus = 0;
|
int ncpus = 0;
|
||||||
bool topology_failed = false;
|
bool topology_failed = false;
|
||||||
|
int max_node;
|
||||||
|
|
||||||
if (!virNumaIsAvailable())
|
if (!virNumaIsAvailable())
|
||||||
return nodeCapsInitNUMAFake(caps);
|
return nodeCapsInitNUMAFake(caps);
|
||||||
|
|
||||||
int mask_n_bytes = max_n_cpus / 8;
|
if ((max_node = virNumaGetMaxNode()) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(mask, mask_n_bytes / sizeof(*mask)) < 0)
|
if (VIR_ALLOC_N(mask, mask_n_bytes / sizeof(*mask)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (VIR_ALLOC_N(allonesmask, mask_n_bytes / sizeof(*mask)) < 0)
|
if (VIR_ALLOC_N(allonesmask, mask_n_bytes / sizeof(*mask)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
memset(allonesmask, 0xff, mask_n_bytes);
|
memset(allonesmask, 0xff, mask_n_bytes);
|
||||||
|
|
||||||
for (n = 0; n <= numa_max_node(); n++) {
|
for (n = 0; n <= max_node; n++) {
|
||||||
size_t i;
|
size_t i;
|
||||||
/* The first time this returns -1, ENOENT if node doesn't exist... */
|
/* The first time this returns -1, ENOENT if node doesn't exist... */
|
||||||
if (numa_node_to_cpus(n, mask, mask_n_bytes) < 0) {
|
if (numa_node_to_cpus(n, mask, mask_n_bytes) < 0) {
|
||||||
VIR_WARN("NUMA topology for cell %d of %d not available, ignoring",
|
VIR_WARN("NUMA topology for cell %d of %d not available, ignoring",
|
||||||
n, numa_max_node()+1);
|
n, max_node + 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* second, third... times it returns an all-1's mask */
|
/* second, third... times it returns an all-1's mask */
|
||||||
if (memcmp(mask, allonesmask, mask_n_bytes) == 0) {
|
if (memcmp(mask, allonesmask, mask_n_bytes) == 0) {
|
||||||
VIR_DEBUG("NUMA topology for cell %d of %d is all ones, ignoring",
|
VIR_DEBUG("NUMA topology for cell %d of %d is all ones, ignoring",
|
||||||
n, numa_max_node()+1);
|
n, max_node + 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1688,7 +1688,9 @@ nodeGetCellsFreeMemory(unsigned long long *freeMems,
|
|||||||
return nodeGetCellsFreeMemoryFake(freeMems,
|
return nodeGetCellsFreeMemoryFake(freeMems,
|
||||||
startCell, maxCells);
|
startCell, maxCells);
|
||||||
|
|
||||||
maxCell = numa_max_node();
|
if ((maxCell = virNumaGetMaxNode()) < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (startCell > maxCell) {
|
if (startCell > maxCell) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("start cell %d out of range (0-%d)"),
|
_("start cell %d out of range (0-%d)"),
|
||||||
@ -1716,13 +1718,16 @@ unsigned long long
|
|||||||
nodeGetFreeMemory(void)
|
nodeGetFreeMemory(void)
|
||||||
{
|
{
|
||||||
unsigned long long freeMem = 0;
|
unsigned long long freeMem = 0;
|
||||||
|
int max_node;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (!virNumaIsAvailable())
|
if (!virNumaIsAvailable())
|
||||||
return nodeGetFreeMemoryFake();
|
return nodeGetFreeMemoryFake();
|
||||||
|
|
||||||
|
if ((max_node = virNumaGetMaxNode()) < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
for (n = 0; n <= numa_max_node(); n++) {
|
for (n = 0; n <= max_node; n++) {
|
||||||
long long mem;
|
long long mem;
|
||||||
if (numa_node_size64(n, &mem) < 0)
|
if (numa_node_size64(n, &mem) < 0)
|
||||||
continue;
|
continue;
|
||||||
@ -1750,7 +1755,9 @@ static unsigned long long nodeGetCellMemory(int cell)
|
|||||||
int maxCell;
|
int maxCell;
|
||||||
|
|
||||||
/* Make sure the provided cell number is valid. */
|
/* Make sure the provided cell number is valid. */
|
||||||
maxCell = numa_max_node();
|
if ((maxCell = virNumaGetMaxNode()) < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (cell > maxCell) {
|
if (cell > maxCell) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cell %d out of range (0-%d)"),
|
_("cell %d out of range (0-%d)"),
|
||||||
|
@ -174,6 +174,34 @@ virNumaIsAvailable(void)
|
|||||||
{
|
{
|
||||||
return numa_available() != -1;
|
return numa_available() != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virNumaGetMaxNode:
|
||||||
|
* Get the highest node number available on the current system.
|
||||||
|
* (See the node numbers in /sys/devices/system/node/ ).
|
||||||
|
*
|
||||||
|
* Returns the highes NUMA node id on success, -1 on error.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virNumaGetMaxNode(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!virNumaIsAvailable()) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("NUMA isn't available on this host"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ret = numa_max_node()) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("Failed to request maximum NUMA node id"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
int
|
int
|
||||||
virNumaSetupMemoryPolicy(virNumaTuneDef numatune,
|
virNumaSetupMemoryPolicy(virNumaTuneDef numatune,
|
||||||
@ -195,4 +223,13 @@ virNumaIsAvailable(void)
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
virNumaGetMaxNode(void)
|
||||||
|
{
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("NUMA isn't available on this host"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,4 +57,6 @@ int virNumaSetupMemoryPolicy(virNumaTuneDef numatune,
|
|||||||
virBitmapPtr nodemask);
|
virBitmapPtr nodemask);
|
||||||
|
|
||||||
bool virNumaIsAvailable(void);
|
bool virNumaIsAvailable(void);
|
||||||
|
int virNumaGetMaxNode(void);
|
||||||
|
|
||||||
#endif /* __VIR_NUMA_H__ */
|
#endif /* __VIR_NUMA_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user