]> xenbits.xensource.com Git - people/andrewcoop/hwloc.git/commitdiff
core: allow backends to reuse a cached uname info when adding uname string infos
authorBrice Goglin <Brice.Goglin@inria.fr>
Mon, 27 Jan 2014 14:43:57 +0000 (15:43 +0100)
committerBrice Goglin <Brice.Goglin@inria.fr>
Thu, 30 Jan 2014 09:38:59 +0000 (10:38 +0100)
And ignore any empty uname field in case the backend gives incomplete info.

14 files changed:
include/private/private.h
src/misc.c
src/topology-aix.c
src/topology-bgq.c
src/topology-darwin.c
src/topology-freebsd.c
src/topology-hpux.c
src/topology-linux.c
src/topology-netbsd.c
src/topology-noos.c
src/topology-osf.c
src/topology-solaris.c
src/topology-windows.c
src/topology-x86.c

index 5e684b0d62ab74436a1710b9e3f8c19cec74ae59..850dc51ea1a728c7a89d3e77f879626b2eb98711 100644 (file)
@@ -184,8 +184,11 @@ extern void hwloc_set_netbsd_hooks(struct hwloc_binding_hooks *binding_hooks, st
 extern void hwloc_set_hpux_hooks(struct hwloc_binding_hooks *binding_hooks, struct hwloc_topology_support *support);
 #endif /* HWLOC_HPUX_SYS */
 
-/* Insert uname-specific names/values in the object infos array */
-extern void hwloc_add_uname_info(struct hwloc_topology *topology);
+/* Insert uname-specific names/values in the object infos array.
+ * If cached_uname isn't NULL, it is used as a struct utsname instead of recalling uname.
+ * Any field that starts with \0 is ignored.
+ */
+extern void hwloc_add_uname_info(struct hwloc_topology *topology, void *cached_uname);
 
 /* Free obj and its attributes assuming it doesn't have any children/parent anymore */
 extern void hwloc_free_unlinked_object(hwloc_obj_t obj);
index 9ef3be379e341b00668937ec65e92d3a7910739a..0cc7349147df2fc97fa2a7f415a2501ec5deeabe 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2009 CNRS
- * Copyright © 2009-2012 Inria.  All rights reserved.
+ * Copyright © 2009-2014 Inria.  All rights reserved.
  * Copyright © 2009-2010 Université Bordeaux 1
  * Copyright © 2009-2011 Cisco Systems, Inc.  All rights reserved.
  * See COPYING in top-level directory.
@@ -85,22 +85,33 @@ int hwloc_namecoloncmp(const char *haystack, const char *needle, size_t n)
   return i < n;
 }
 
-void hwloc_add_uname_info(struct hwloc_topology *topology __hwloc_attribute_unused)
+void hwloc_add_uname_info(struct hwloc_topology *topology __hwloc_attribute_unused,
+                         void *cached_uname __hwloc_attribute_unused)
 {
 #ifdef HAVE_UNAME
-  struct utsname utsname;
-
-  if (uname(&utsname) < 0)
-    return;
+  struct utsname _utsname, *utsname;
 
   if (hwloc_obj_get_info_by_name(topology->levels[0][0], "OSName"))
     /* don't annotate twice */
     return;
 
-  hwloc_obj_add_info(topology->levels[0][0], "OSName", utsname.sysname);
-  hwloc_obj_add_info(topology->levels[0][0], "OSRelease", utsname.release);
-  hwloc_obj_add_info(topology->levels[0][0], "OSVersion", utsname.version);
-  hwloc_obj_add_info(topology->levels[0][0], "HostName", utsname.nodename);
-  hwloc_obj_add_info(topology->levels[0][0], "Architecture", utsname.machine);
+  if (cached_uname)
+    utsname = (struct utsname *) cached_uname;
+  else {
+    utsname = &_utsname;
+    if (uname(utsname) < 0)
+      return;
+  }
+
+  if (*utsname->sysname)
+    hwloc_obj_add_info(topology->levels[0][0], "OSName", utsname->sysname);
+  if (*utsname->release)
+    hwloc_obj_add_info(topology->levels[0][0], "OSRelease", utsname->release);
+  if (*utsname->version)
+    hwloc_obj_add_info(topology->levels[0][0], "OSVersion", utsname->version);
+  if (*utsname->nodename)
+    hwloc_obj_add_info(topology->levels[0][0], "HostName", utsname->nodename);
+  if (*utsname->machine)
+    hwloc_obj_add_info(topology->levels[0][0], "Architecture", utsname->machine);
 #endif /* HAVE_UNAME */
 }
index e19faeb93bbc3a0c4bd574a4b88af3d847c1cba6..e2d34eb2f9c04c74049f72cb49261a3af5227fa8 100644 (file)
@@ -773,7 +773,7 @@ hwloc_look_aix(struct hwloc_backend *backend)
 
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "AIX");
   if (topology->is_thissystem)
-    hwloc_add_uname_info(topology);
+    hwloc_add_uname_info(topology, NULL);
   return 1;
 }
 
index 5a2e61127daaef518344c2cd6bbfe09c981a9566..ac7825a6c3daaf3b256ab0555cce79f383a6687a 100644 (file)
@@ -104,7 +104,7 @@ hwloc_look_bgq(struct hwloc_backend *backend)
 
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "BGQ");
   if (topology->is_thissystem)
-    hwloc_add_uname_info(topology);
+    hwloc_add_uname_info(topology, NULL);
   return 1;
 }
 
index 39e13a3f35460b8f126e3b60a81a09165f38ef21..7934c390a9a93a2a7cd3c3f2d14ac8fcd3520cd0 100644 (file)
@@ -265,7 +265,7 @@ hwloc_look_darwin(struct hwloc_backend *backend)
 
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "Darwin");
   if (topology->is_thissystem)
-    hwloc_add_uname_info(topology);
+    hwloc_add_uname_info(topology, NULL);
   return 1;
 }
 
index 7e13ca166bbeec81123a9f6c758c6975542897a7..eecedb58b525c228ab03f8ceb107a57744409ba3 100644 (file)
@@ -192,7 +192,7 @@ hwloc_look_freebsd(struct hwloc_backend *backend)
 #endif
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "FreeBSD");
   if (topology->is_thissystem)
-    hwloc_add_uname_info(topology);
+    hwloc_add_uname_info(topology, NULL);
   return 1;
 }
 
index bd843793144ea26d278708d94ee44187e64f8750..02c3940eb4c297bddfeefa278d3109ca0058ca41 100644 (file)
@@ -247,7 +247,7 @@ hwloc_look_hpux(struct hwloc_backend *backend)
 
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "HP-UX");
   if (topology->is_thissystem)
-    hwloc_add_uname_info(topology);
+    hwloc_add_uname_info(topology, NULL);
   return 1;
 }
 
index 11fd29c7effab32c7e618a280189ca871573bc8c..9104a012a38e69fc089d277f8d2a322492702c5f 100644 (file)
@@ -3591,7 +3591,7 @@ hwloc_look_linuxfs(struct hwloc_backend *backend)
 
   /* gather uname info if fsroot wasn't changed */
   if (topology->is_thissystem)
-     hwloc_add_uname_info(topology);
+    hwloc_add_uname_info(topology, NULL);
 
   return 1;
 }
index c88ba874e774a8bbf2db1436f4a015545f9ffe02..2d1b3a6b622d40a654da4c2e56a9d5c2bb82b220 100644 (file)
@@ -147,7 +147,7 @@ hwloc_look_netbsd(struct hwloc_backend *backend)
 
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "NetBSD");
   if (topology->is_thissystem)
-    hwloc_add_uname_info(topology);
+    hwloc_add_uname_info(topology, NULL);
   return 1;
 }
 
index 8c74ded20ae29ff12943b1ffe0d50fbe2672d4c0..e944afdb67ef7e8f8bb8ef3d9716b61b32fe9a9f 100644 (file)
@@ -22,7 +22,7 @@ hwloc_look_noos(struct hwloc_backend *backend)
   hwloc_alloc_obj_cpusets(topology->levels[0][0]);
   hwloc_setup_pu_level(topology, hwloc_fallback_nbprocessors(topology));
   if (topology->is_thissystem)
-    hwloc_add_uname_info(topology);
+    hwloc_add_uname_info(topology, NULL);
   return 1;
 }
 
index 52300fc2edefe9d3a4d836c415c5e11139502b51..c7ed7b245780561fb7df530e6b216abd9c588dec 100644 (file)
@@ -336,7 +336,7 @@ hwloc_look_osf(struct hwloc_backend *backend)
 
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "OSF");
   if (topology->is_thissystem)
-    hwloc_add_uname_info(topology);
+    hwloc_add_uname_info(topology, NULL);
   return 1;
 }
 
index fec511dd261d7dad7ee32f79ae2f236772a4708b..6753a27695f125ad6213060af6a10b9c58d2d1d1 100644 (file)
@@ -741,7 +741,7 @@ hwloc_look_solaris(struct hwloc_backend *backend)
 
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "Solaris");
   if (topology->is_thissystem)
-    hwloc_add_uname_info(topology);
+    hwloc_add_uname_info(topology, NULL);
   return 1;
 }
 
index 8d811c78505f64bd5a0275b3c729b3c7d6b01a12..bda75717e8702a3e84337c2f3b8e2738e527ce97 100644 (file)
@@ -748,7 +748,7 @@ hwloc_look_windows(struct hwloc_backend *backend)
 
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "Windows");
   if (topology->is_thissystem)
-    hwloc_add_uname_info(topology);
+    hwloc_add_uname_info(topology, NULL);
   return 1;
 }
 
index ccf4524b5bead304835a76549ac8c876073e1024..e470eda5268484239aae41064a9f673b9083df50 100644 (file)
@@ -934,7 +934,7 @@ fulldiscovery:
   hwloc_obj_add_info(topology->levels[0][0], "Backend", "x86");
 
 #ifdef HAVE_UNAME
-  hwloc_add_uname_info(topology); /* we already know is_thissystem() is true */
+  hwloc_add_uname_info(topology, NULL); /* we already know is_thissystem() is true */
 #else
   /* uname isn't available, manually setup the "Architecture" info */
 #ifdef HWLOC_X86_64_ARCH