---
src/libplpa/plpa_map.c | 23 ++++++++++++++++++-----
1 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/libplpa/plpa_map.c b/src/libplpa/plpa_map.c
index d3e8f62..8882782 100644
--- a/src/libplpa/plpa_map.c
+++ b/src/libplpa/plpa_map.c
@@ -127,6 +127,7 @@
#include <errno.h>
#include <stdlib.h>
#include <stdbool.h>
+#include <strings.h>
typedef struct tuple_t_ {
int processor_id, socket_id, core_id, online;
@@ -140,6 +141,7 @@ static int num_sockets = -1;
static int min_socket_id = INT_MAX;
static int max_socket_id = -1;
static int socket_index_extent = 0;
+static int socket_index_shift = 0;
static int *max_core_id = NULL;
static int *num_cores = NULL;
static int max_core_id_overall = -1;
@@ -149,12 +151,12 @@ static PLPA_NAME(cache_behavior_t) cache_behavior = PLPA_NAME_CAPS(CACHE_IGNORE)
static inline int socket_id_to_index(int socket_id)
{
- return socket_id - min_socket_id;
+ return (socket_id - min_socket_id) >> socket_index_shift;
}
static inline int socket_index_to_id(int socket_index)
{
- return socket_index + min_socket_id;
+ return (socket_index << socket_index_shift) + min_socket_id;
}
static void clear_cache(void)
@@ -179,13 +181,13 @@ static void clear_cache(void)
num_processors = max_processor_id = -1;
num_sockets = max_socket_id = -1;
min_socket_id = INT_MAX;
- socket_index_extent = 0;
+ socket_index_extent = socket_index_shift = 0;
max_core_id_overall = -1;
}
static void load_cache(void)
{
- int i, j, k, invalid_entry, fd, found_online;
+ int i, j, k, invalid_entry, fd, found_online, socket_or;
char path[PATH_MAX], buf[8];
PLPA_NAME(cpu_set_t) valid_processors;
PLPA_NAME(cpu_set_t) *cores_on_sockets;
@@ -272,6 +274,7 @@ static void load_cache(void)
map_processor_id_to_tuple[invalid_entry].core_id = -1;
/* Build a cached map of (socket,core) tuples */
+ socket_or = 0;
for (found = 0, i = 0; i <= max_processor_id; ++i) {
/* Check for invalid processor ID */
@@ -354,6 +357,10 @@ static void load_cache(void)
if (map_processor_id_to_tuple[i].socket_id < min_socket_id) {
min_socket_id = map_processor_id_to_tuple[i].socket_id;
}
+
+ /* collect all set bits in any socket_id, to shift away common
+ trailing zeros */
+ socket_or |= map_processor_id_to_tuple[i].socket_id;
}
/* If we didn't find any core_id/physical_package_id's, then we
@@ -363,8 +370,14 @@ static void load_cache(void)
return;
}
+ /* don't do any shifting if negative numbers are involved */
+ if (socket_or > 0) {
+ /* we shift away common trailing zeros */
+ socket_index_shift = ffs(socket_or) - 1;
+ }
/* index range for sockets, [0, socket_index_extent) */
- socket_index_extent = max_socket_id - min_socket_id + 1;
+ socket_index_extent =
+ ((max_socket_id - min_socket_id) >> socket_index_shift) + 1;
/* Now that we know the max number of sockets, allocate some
arrays */
--
1.6.3.3.618.gce7bf
|