Open MPI logo

PLPA Users' Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all PLPA Users mailing list

Subject: [PLPA users] [PATCH 1/5] introduce abstraction from socket_id to index
From: Bert Wesarg (bert.wesarg_at_[hidden])
Date: 2009-07-23 17:47:46


---
 src/libplpa/plpa_map.c |   67 +++++++++++++++++++++++++++++++++--------------
 1 files changed, 47 insertions(+), 20 deletions(-)
diff --git a/src/libplpa/plpa_map.c b/src/libplpa/plpa_map.c
index f51fe01..43265f6 100644
--- a/src/libplpa/plpa_map.c
+++ b/src/libplpa/plpa_map.c
@@ -145,6 +145,16 @@ static tuple_t *map_processor_id_to_tuple = NULL;
 static tuple_t **map_tuple_to_processor_id = NULL;
 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;
+}
+
+static inline int socket_index_to_id(int socket_index)
+{
+    return socket_index;
+}
+
 static void clear_cache(void)
 {
     if (NULL != max_core_id) {
@@ -365,19 +375,17 @@ static void load_cache(void)
 
     /* Find the max core number on each socket */
     for (i = 0; i <= max_processor_id; ++i) {
+        int socket_index =
+            socket_id_to_index(map_processor_id_to_tuple[i].socket_id);
         if (map_processor_id_to_tuple[i].processor_id < 0 ||
             map_processor_id_to_tuple[i].socket_id < 0) {
             continue;
         }
-        if (map_processor_id_to_tuple[i].core_id > 
-            max_core_id[map_processor_id_to_tuple[i].socket_id]) {
-            max_core_id[map_processor_id_to_tuple[i].socket_id] = 
-                map_processor_id_to_tuple[i].core_id;
+        if (map_processor_id_to_tuple[i].core_id > max_core_id[socket_index]) {
+            max_core_id[socket_index] = map_processor_id_to_tuple[i].core_id;
         }
-        if (max_core_id[map_processor_id_to_tuple[i].socket_id] > 
-            max_core_id_overall) {
-            max_core_id_overall = 
-                max_core_id[map_processor_id_to_tuple[i].socket_id];
+        if (max_core_id[socket_index] > max_core_id_overall) {
+            max_core_id_overall = max_core_id[socket_index];
         }
     }
 
@@ -409,8 +417,10 @@ static void load_cache(void)
     }
     for (i = 0; i <= max_processor_id; ++i) {
         if (map_processor_id_to_tuple[i].socket_id >= 0) {
+            int socket_index =
+                socket_id_to_index(map_processor_id_to_tuple[i].socket_id);
             PLPA_CPU_SET(map_processor_id_to_tuple[i].core_id,
-                         &(cores_on_sockets[map_processor_id_to_tuple[i].socket_id]));
+                         &(cores_on_sockets[socket_index]));
         }
     }
     for (i = 0; i <= max_socket_id; ++i) {
@@ -439,6 +449,7 @@ static void load_cache(void)
     }
     /* Compute map */
     for (i = 0; i <= max_socket_id; ++i) {
+        int socket_id = socket_index_to_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];
@@ -453,13 +464,13 @@ static void load_cache(void)
                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_id == i &&
+                if (map_processor_id_to_tuple[k].socket_id == socket_id &&
                     map_processor_id_to_tuple[k].core_id == j) {
                     *tuple_ptr = &map_processor_id_to_tuple[k];
 #if defined(PLPA_DEBUG) && PLPA_DEBUG
                     printf("Creating map [%d]: (socket %d, core %d) -> ID %d\n",
                            i * (max_core_id_overall + 1) + j,
-                           i, j, k);
+                           socket_id, j, k);
 #endif
                     break;
                 }
@@ -515,6 +526,7 @@ int PLPA_NAME(have_topology_information)(int *supported_arg)
 int PLPA_NAME(map_to_processor_id)(int socket_id, int core_id, 
                                    int *processor_id)
 {
+    int socket_index;
     int ret;
 
     /* Initialize if not already done so */
@@ -540,14 +552,19 @@ int PLPA_NAME(map_to_processor_id)(int socket_id, int core_id,
     }
 
     /* Check for some invalid entries */
-    if (socket_id < 0 || socket_id > max_socket_id ||
-        core_id < 0 || core_id > max_core_id[socket_id]) {
+    if (socket_id < 0 || socket_id > max_socket_id) {
+        return ENOENT;
+    }
+    socket_index = socket_id_to_index(socket_id);
+
+    /* Check for some invalid entries */
+    if (core_id < 0 || core_id > max_core_id[socket_index]) {
         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_id * (max_core_id_overall + 1) +
+    ret = map_tuple_to_processor_id[socket_index * (max_core_id_overall + 1) +
                                     core_id]->processor_id;
     if (-1 == ret) {
         return ENOENT;
@@ -891,6 +908,7 @@ int PLPA_NAME(get_socket_id)(int socket_num, int *socket_id)
 int PLPA_NAME(get_core_info)(int socket_id, int *num_cores_arg, 
                              int *max_core_id_arg)
 {
+    int socket_index;
     int ret;
 
     /* Initialize if not already done so */
@@ -916,18 +934,23 @@ int PLPA_NAME(get_core_info)(int socket_id, int *num_cores_arg,
     }
 
     /* Check for some invalid entries */
-    if (socket_id < 0 || socket_id > max_socket_id ||
-        -1 == max_core_id[socket_id]) {
+    if (socket_id < 0 || socket_id > max_socket_id) {
+        return ENOENT;
+    }
+    socket_index = socket_id_to_index(socket_id);
+
+    /* Check for some invalid entries */
+    if (-1 == max_core_id[socket_index]) {
         return ENOENT;
     }
-    ret = num_cores[socket_id];
+    ret = num_cores[socket_index];
     if (-1 == ret) {
         return ENOENT;
     }
 
     /* All done */
     *num_cores_arg = ret;
-    *max_core_id_arg = max_core_id[socket_id];
+    *max_core_id_arg = max_core_id[socket_index];
     return 0;
 }
 
@@ -935,6 +958,7 @@ int PLPA_NAME(get_core_info)(int socket_id, int *num_cores_arg,
    (starting with 0) */
 int PLPA_NAME(get_core_id)(int socket_id, int core_num, int *core_id)
 {
+    int socket_index;
     int ret, i, j, count;
 
     /* Initialize if not already done so */
@@ -964,9 +988,10 @@ int PLPA_NAME(get_core_id)(int socket_id, int core_num, int *core_id)
         core_num < 0 || core_num > max_core_id_overall) {
         return EINVAL;
     }
+    socket_index = socket_id_to_index(socket_id);
 
     /* Find the core_num'th core */
-    for (count = i = 0, j = socket_id * (max_core_id_overall + 1);
+    for (count = i = 0, j = socket_index * (max_core_id_overall + 1);
          i <= max_core_id_overall; ++i) {
         if (map_tuple_to_processor_id[j + i]->processor_id >= 0) {
             if (count++ == core_num) {
@@ -985,6 +1010,7 @@ int PLPA_NAME(get_core_id)(int socket_id, int core_num, int *core_id)
 int PLPA_NAME(get_core_flags)(int socket_id, int core_id,
                               int *exists_arg, int *online_arg)
 {
+    int socket_index;
     int ret, i, exists, online;
 
     /* Initialize if not already done so */
@@ -1014,9 +1040,10 @@ int PLPA_NAME(get_core_flags)(int socket_id, int core_id,
         core_id < 0 || core_id > max_core_id_overall) {
         return EINVAL;
     }
+    socket_index = socket_id_to_index(socket_id);
 
     exists = online = 0;
-    i = socket_id * (max_core_id_overall + 1) + core_id;
+    i = socket_index * (max_core_id_overall + 1) + core_id;
     if (map_tuple_to_processor_id[i]->processor_id >= 0) {
         exists = 1;
         if (map_tuple_to_processor_id[i]->online) {
-- 
1.6.3.3.618.gce7bf