]> xenbits.xensource.com Git - people/andrewcoop/hwloc.git/commitdiff
Never merge explicitly-custom-inserted groups
authorBrice Goglin <brice.goglin@inria.fr>
Wed, 29 May 2013 09:52:47 +0000 (09:52 +0000)
committerBrice Goglin <brice.goglin@inria.fr>
Wed, 29 May 2013 09:52:47 +0000 (09:52 +0000)
If the user inserts one, don't remove it.

This relies on string info attributes (added in previous commits),
and we try to not look at these and strcmp() their value unless
all lights are green.

This commit fixes #103

This commit was SVN r5652.

NEWS
src/topology.c
tests/hwloc_custom.c

diff --git a/NEWS b/NEWS
index 846c3f9b4e2c90ef60114ffb44a92843b0859a98..2f01e1fd78a4dfc1f0e9cfb28075b98d2eab3304 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,8 @@ Version 1.8.0
     Linux when full discovery with libpciaccess or libpci isn't available.
     It misses bridges and device names.
 * Misc
+  + Never merge Group objects that were added explicitly by the user with
+    hwloc_custom_insert_group_object_by_parent().
   + Add --with-hwloc-plugins-path to specify the install/load directories
     of plugins.
   + Calling hwloc_topology_load() or hwloc_topology_set_*() on an already
index 66ccf370ff8cee0a9f3fe920038d81720a4549f3..339651da98a8cdc35adba15b7db154f6e75f9133 100644 (file)
@@ -1546,6 +1546,21 @@ restrict_object_nodeset(hwloc_topology_t topology, hwloc_obj_t *pobj, hwloc_node
   for_each_child_safe(child, obj, pchild)
     restrict_object_nodeset(topology, pchild, droppednodeset);
 }
+
+/* we don't want to merge groups that were inserted explicitly with the custom interface */
+static int
+can_merge_group(hwloc_topology_t topology, hwloc_obj_t obj)
+{
+  const char *value;
+  /* custom-inserted groups are in custom topologies and have no cpusets,
+   * don't bother calling hwloc_obj_get_info_by_name() and strcmp() uselessly.
+   */
+  if (!topology->backends->is_custom || obj->cpuset)
+    return 1;
+  value = hwloc_obj_get_info_by_name(obj, "Backend");
+  return (!value) || strcmp(value, "Custom");
+}
+
 /*
  * Merge with the only child if either the parent or the child has a type to be
  * ignored while keeping structure
@@ -1578,12 +1593,16 @@ merge_useless_child(hwloc_topology_t topology, hwloc_obj_t *pparent)
   child->next_sibling = NULL;
 
   /* Check whether parent and/or child can be replaced */
-  if (topology->ignored_types[parent->type] == HWLOC_IGNORE_TYPE_KEEP_STRUCTURE)
-    /* Parent can be ignored in favor of the child.  */
-    replaceparent = 1;
-  if (topology->ignored_types[child->type] == HWLOC_IGNORE_TYPE_KEEP_STRUCTURE)
-    /* Child can be ignored in favor of the parent.  */
-    replacechild = 1;
+  if (topology->ignored_types[parent->type] == HWLOC_IGNORE_TYPE_KEEP_STRUCTURE) {
+    if (parent->type != HWLOC_OBJ_GROUP || can_merge_group(topology, parent))
+      /* Parent can be ignored in favor of the child.  */
+      replaceparent = 1;
+  }
+  if (topology->ignored_types[child->type] == HWLOC_IGNORE_TYPE_KEEP_STRUCTURE) {
+    if (child->type != HWLOC_OBJ_GROUP || can_merge_group(topology, child))
+      /* Child can be ignored in favor of the parent.  */
+      replacechild = 1;
+  }
 
   /* Decide which one to actually replace */
   if (replaceparent && replacechild) {
index 1164b62e24b3ffca0843b371caf7081f7c58fd44..26655d269d1c88cc3ef9c2e48286988b27049bc5 100644 (file)
@@ -48,9 +48,9 @@ int main(void)
   sw21 = hwloc_custom_insert_group_object_by_parent(global, sw2, 1);
   hwloc_custom_insert_topology(global, sw21, local, NULL);
   hwloc_custom_insert_topology(global, sw21, local, NULL);
+  hwloc_custom_insert_topology(global, sw21, local, NULL);
   sw22 = hwloc_custom_insert_group_object_by_parent(global, sw2, 1);
-  hwloc_custom_insert_topology(global, sw22, local, NULL);
-  hwloc_custom_insert_topology(global, sw22, local, NULL);
+  hwloc_custom_insert_topology(global, sw22, local, NULL); /* only one to check that it won't get merged */
 
   hwloc_topology_destroy(local);
 
@@ -64,7 +64,7 @@ int main(void)
   assert(hwloc_get_depth_type(global, 1) == HWLOC_OBJ_GROUP);
   assert(hwloc_get_nbobjs_by_depth(global, 1) == 2);
   assert(hwloc_get_depth_type(global, 2) == HWLOC_OBJ_GROUP);
-  assert(hwloc_get_nbobjs_by_depth(global, 2) == 4);
+  assert(hwloc_get_nbobjs_by_depth(global, 2) == 4); /* the last group of this level shouldn't be merged */
   assert(hwloc_get_depth_type(global, 3) == HWLOC_OBJ_MACHINE);
   assert(hwloc_get_nbobjs_by_type(global, HWLOC_OBJ_MACHINE) == 8);
   assert(hwloc_get_depth_type(global, 4) == HWLOC_OBJ_NODE);