static void memkind_hbw_closest_numanode_init(void) { struct memkind_hbw_closest_numanode_t *g = &memkind_hbw_closest_numanode_g; int *bandwidth = NULL; int num_unique = 0; int high_bandwidth = 0; int i; struct bandwidth_nodes_t *bandwidth_nodes = NULL; g->num_cpu = numa_num_configured_cpus(); g->closest_numanode = (int *)jemk_malloc(sizeof(int) * g->num_cpu); bandwidth = (int *)jemk_malloc(sizeof(int) * NUMA_NUM_NODES); if (!(g->closest_numanode && bandwidth)) { g->init_err = MEMKIND_ERROR_MALLOC; log_err("jemk_malloc() failed."); goto exit; } g->init_err = fill_nodes_bandwidth(bandwidth, NUMA_NUM_NODES); if (g->init_err) goto exit; g->init_err = create_bandwidth_nodes(NUMA_NUM_NODES, bandwidth, &num_unique, &bandwidth_nodes); if (g->init_err) goto exit; if (num_unique == 1) { g->init_err = MEMKIND_ERROR_UNAVAILABLE; goto exit; } high_bandwidth = bandwidth_nodes[num_unique-1].bandwidth; g->init_err = set_closest_numanode(num_unique, bandwidth_nodes, high_bandwidth, g->num_cpu, g->closest_numanode); for(i=0; i<bandwidth_nodes[num_unique-1].num_numanodes; i++) { log_info("NUMA node %d is high-bandwidth memory.", bandwidth_nodes[num_unique-1].numanodes[i]); } exit: jemk_free(bandwidth_nodes); jemk_free(bandwidth); if (g->init_err) { jemk_free(g->closest_numanode); g->closest_numanode = NULL; } }
static void memkind_hbw_closest_numanode_init(void) { struct memkind_hbw_closest_numanode_t *g = &memkind_hbw_closest_numanode_g; int *bandwidth = NULL; int num_unique = 0; int high_bandwidth = 0; int node; struct bandwidth_nodes_t *bandwidth_nodes = NULL; char *hbw_nodes_env; struct bitmask *hbw_nodes_bm; g->num_cpu = numa_num_configured_cpus(); g->closest_numanode = (int *)je_malloc(sizeof(int) * g->num_cpu); bandwidth = (int *)je_malloc(sizeof(int) * NUMA_NUM_NODES); if (!(g->closest_numanode && bandwidth)) { g->init_err = MEMKIND_ERROR_MALLOC; } if (!g->init_err) { hbw_nodes_env = getenv("MEMKIND_HBW_NODES"); if (hbw_nodes_env) { hbw_nodes_bm = numa_parse_nodestring(hbw_nodes_env); if (!hbw_nodes_bm) { g->init_err = MEMKIND_ERROR_ENVIRON; } else { for (node = 0; node < NUMA_NUM_NODES; ++node) { if (numa_bitmask_isbitset(hbw_nodes_bm, node)) { bandwidth[node] = 2; } else { bandwidth[node] = 1; } } numa_bitmask_free(hbw_nodes_bm); } } else { g->init_err = parse_node_bandwidth(NUMA_NUM_NODES, bandwidth, MEMKIND_BANDWIDTH_PATH); } } if (!g->init_err) { g->init_err = create_bandwidth_nodes(NUMA_NUM_NODES, bandwidth, &num_unique, &bandwidth_nodes); } if (!g->init_err) { if (num_unique == 1) { g->init_err = MEMKIND_ERROR_UNAVAILABLE; } } if (!g->init_err) { high_bandwidth = bandwidth_nodes[num_unique-1].bandwidth; g->init_err = set_closest_numanode(num_unique, bandwidth_nodes, high_bandwidth, g->num_cpu, g->closest_numanode); } if (bandwidth_nodes) { je_free(bandwidth_nodes); } if (bandwidth) { je_free(bandwidth); } if (g->init_err) { if (g->closest_numanode) { je_free(g->closest_numanode); g->closest_numanode = NULL; } } }