]> xenbits.xensource.com Git - people/andrewcoop/hwloc.git/commitdiff
x86: simplify the management of binding hooks
authorBrice Goglin <Brice.Goglin@inria.fr>
Tue, 11 Feb 2014 10:44:10 +0000 (11:44 +0100)
committerBrice Goglin <Brice.Goglin@inria.fr>
Tue, 11 Feb 2014 12:02:54 +0000 (13:02 +0100)
We check early whether binding is available, record the thread or proc
support there, and just use that one later, instead of trying both.

src/topology-x86.c

index d451a059034f9c3f15f18e571beef82b9f52a8e3..87ef067bfe9deec05f2133bb23d9baaf023167c8 100644 (file)
@@ -794,15 +794,27 @@ int hwloc_look_x86(struct hwloc_topology *topology, unsigned nbprocs, int fulldi
   struct hwloc_binding_hooks hooks;
   struct hwloc_topology_support support;
   struct hwloc_topology_membind_support memsupport __hwloc_attribute_unused;
+  int (*get_cpubind)(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
+  int (*set_cpubind)(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
   int ret = -1;
 
+  /* check if binding works */
   memset(&hooks, 0, sizeof(hooks));
   support.membind = &memsupport;
   hwloc_set_native_binding_hooks(&hooks, &support);
-  if (nbprocs > 1 &&
-      !(hooks.get_thisproc_cpubind && hooks.set_thisproc_cpubind)
-   && !(hooks.get_thisthread_cpubind && hooks.set_thisthread_cpubind))
-    goto out;
+  if (hooks.get_thisproc_cpubind && hooks.set_thisproc_cpubind) {
+    get_cpubind = hooks.get_thisproc_cpubind;
+    set_cpubind = hooks.set_thisproc_cpubind;
+  } else if (hooks.get_thisthread_cpubind && hooks.set_thisthread_cpubind) {
+    get_cpubind = hooks.get_thisthread_cpubind;
+    set_cpubind = hooks.set_thisthread_cpubind;
+  } else {
+    /* we need binding support if there are multiple PUs */
+    if (nbprocs > 1)
+      goto out;
+    get_cpubind = NULL;
+    set_cpubind = NULL;
+  }
 
   infos = calloc(nbprocs, sizeof(struct procinfo));
   if (NULL == infos)
@@ -854,22 +866,12 @@ int hwloc_look_x86(struct hwloc_topology *topology, unsigned nbprocs, int fulldi
 
   hwloc_x86_os_state_save(&os_state);
 
-  if (hooks.get_thisthread_cpubind && hooks.set_thisthread_cpubind) {
-    /* trying binding the current thread only */
-    ret = look_procs(topology, nbprocs, infos, fulldiscovery,
-                    highest_cpuid, highest_ext_cpuid, features, cpuid_type,
-                    hooks.get_thisthread_cpubind, hooks.set_thisthread_cpubind);
-    if (ret < 0) {
-      /* fallback trying to bind the entire process */
-      if (hooks.get_thisproc_cpubind && hooks.set_thisproc_cpubind)
-       ret = look_procs(topology, nbprocs, infos, fulldiscovery,
-                        highest_cpuid, highest_ext_cpuid, features, cpuid_type,
-                        hooks.get_thisproc_cpubind, hooks.set_thisproc_cpubind);
-    }
-    if (ret >= 0)
-      /* success, we're done */
-      goto out_with_os_state;
-  }
+  ret = look_procs(topology, nbprocs, infos, fulldiscovery,
+                  highest_cpuid, highest_ext_cpuid, features, cpuid_type,
+                  get_cpubind, set_cpubind);
+  if (ret >= 0)
+    /* success, we're done */
+    goto out_with_os_state;
 
   if (nbprocs == 1) {
     /* only one processor, no need to bind */