/** * virNumaGetDistances: * @node: identifier of the requested NUMA node * @distances: array of distances to sibling nodes * @ndistances: size of @distances * * Get array of distances to sibling nodes from @node. If a * distances[x] equals to zero, the node x is not enabled or * doesn't exist. As a special case, if @node itself refers to * disabled or nonexistent NUMA node, then @distances and * @ndistances are set to NULL and zero respectively. * * The distances are a bit of magic. For a local node the value * is 10, for remote it's typically 20 meaning that time penalty * for accessing a remote node is two time bigger than when * accessing a local node. * * Returns 0 on success, -1 otherwise. */ int virNumaGetDistances(int node, int **distances, int *ndistances) { int ret = -1; int max_node; size_t i; if (!virNumaNodeIsAvailable(node)) { VIR_DEBUG("Node %d does not exist", node); *distances = NULL; *ndistances = 0; return 0; } if ((max_node = virNumaGetMaxNode()) < 0) goto cleanup; if (VIR_ALLOC_N(*distances, max_node + 1) < 0) goto cleanup; *ndistances = max_node + 1; for (i = 0; i <= max_node; i++) { if (!virNumaNodeIsAvailable(node)) continue; (*distances)[i] = numa_distance(node, i); } ret = 0; cleanup: return ret; }
static int virNumaGetHugePageInfoPath(char **path, int node, unsigned int page_size, const char *suffix) { int ret; if (node == -1) { /* We are aiming at overall system info */ ret = virAsprintf(path, HUGEPAGES_SYSTEM_PREFIX HUGEPAGES_PREFIX "%ukB/%s", page_size, suffix ? suffix : ""); } else { /* We are aiming on specific NUMA node */ ret = virAsprintf(path, HUGEPAGES_NUMA_PREFIX "node%d/hugepages/" HUGEPAGES_PREFIX "%ukB/%s", node, page_size, suffix ? suffix : ""); } if (ret >= 0 && !virFileExists(*path)) { ret = -1; if (node != -1) { if (!virNumaNodeIsAvailable(node)) { virReportError(VIR_ERR_OPERATION_FAILED, _("NUMA node %d is not available"), node); } else { virReportError(VIR_ERR_OPERATION_FAILED, _("page size %u is not available on node %d"), page_size, node); } } else { virReportError(VIR_ERR_OPERATION_FAILED, _("page size %u is not available"), page_size); } } return ret; }