--- src/libplpa/plpa_map.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --quilt old/src/libplpa/plpa_map.c new/src/libplpa/plpa_map.c --- old/src/libplpa/plpa_map.c +++ new/src/libplpa/plpa_map.c @@ -138,11 +138,11 @@ static int num_sockets = -1; static int max_socket_id = -1; static int *max_core_id = NULL; static int *num_cores = NULL; static int max_core_id_overall = -1; static tuple_t *map_processor_id_to_tuple = NULL; -static tuple_t ***map_tuple_to_processor_id = NULL; +static tuple_t **map_tuple_to_processor_id = NULL; static void clear_cache(void) { if (NULL != max_core_id) { free(max_core_id); @@ -155,14 +155,10 @@ static void clear_cache(void) if (NULL != map_processor_id_to_tuple) { free(map_processor_id_to_tuple); map_processor_id_to_tuple = NULL; } if (NULL != map_tuple_to_processor_id) { - if (NULL != map_tuple_to_processor_id[0]) { - free(map_tuple_to_processor_id[0]); - map_tuple_to_processor_id = NULL; - } free(map_tuple_to_processor_id); map_tuple_to_processor_id = NULL; } num_processors = max_processor_id = -1; @@ -366,46 +362,36 @@ static void load_cache(const char *sysfs /* Now go through and build the map in the other direction: (socket,core) => processor_id. This map simply points to entries in the other map (i.e., it's by reference instead of by value). */ - map_tuple_to_processor_id = malloc(sizeof(tuple_t **) * - (max_socket_id + 1)); + map_tuple_to_processor_id = malloc(sizeof(tuple_t *) * + ((max_socket_id + 1) * + (max_core_id_overall + 1))); if (NULL == map_tuple_to_processor_id) { clear_cache(); return; } - map_tuple_to_processor_id[0] = malloc(sizeof(tuple_t *) * - ((max_socket_id + 1) * - (max_core_id_overall + 1))); - if (NULL == map_tuple_to_processor_id[0]) { - clear_cache(); - return; - } - /* Set pointers for 2nd dimension */ - for (i = 1; i <= max_socket_id; ++i) { - map_tuple_to_processor_id[i] = - map_tuple_to_processor_id[i - 1] + max_core_id_overall + 1; - } /* Compute map */ for (i = 0; i <= max_socket_id; ++i) { for (j = 0; j <= max_core_id_overall; ++j) { + tuple_t **tuple_ptr = &map_tuple_to_processor_id[ + i * (max_core_id_overall + 1) + j]; + /* Default to the invalid entry in the other map, meaning that this (socket,core) combination doesn't exist (e.g., the core number does not exist in this socket, although it does exist in other sockets). */ - map_tuple_to_processor_id[i][j] = - &map_processor_id_to_tuple[invalid_entry]; + *tuple_ptr = &map_processor_id_to_tuple[invalid_entry]; /* See if this (socket,core) tuple exists in the other map. If so, set this entry to point to it (overriding the invalid entry default). */ for (k = 0; k <= max_processor_id; ++k) { if (map_processor_id_to_tuple[k].socket == i && map_processor_id_to_tuple[k].core == j) { - map_tuple_to_processor_id[i][j] = - &map_processor_id_to_tuple[k]; + *tuple_ptr = &map_processor_id_to_tuple[k]; #if defined(PLPA_DEBUG) && PLPA_DEBUG printf("Creating map: (socket %d, core %d) -> ID %d\n", i, j, k); #endif break; @@ -491,11 +477,12 @@ int PLPA_NAME(map_to_processor_id)(int s return ENOENT; } /* If the mapping returns -1, then this is a non-existent socket/core combo (even though they fall within the max socket / max core overall values) */ - ret = map_tuple_to_processor_id[socket][core]->processor_id; + ret = map_tuple_to_processor_id[socket * (max_core_id_overall + 1) + + core]->processor_id; if (-1 == ret) { return ENOENT; } /* Ok, all should be good -- return the mapping */