00001
00002
00003
00004
00005
00006
00007
00008
00013 #ifndef HWLOC_HELPER_H
00014 #define HWLOC_HELPER_H
00015
00016 #ifndef HWLOC_H
00017 #error Please include the main hwloc.h instead
00018 #endif
00019
00020 #include <stdlib.h>
00021 #include <errno.h>
00022
00023
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027
00028
00041 static __hwloc_inline hwloc_obj_t
00042 hwloc_get_first_largest_obj_inside_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set)
00043 {
00044 hwloc_obj_t obj = hwloc_get_root_obj(topology);
00045 if (!hwloc_bitmap_intersects(obj->cpuset, set))
00046 return NULL;
00047 while (!hwloc_bitmap_isincluded(obj->cpuset, set)) {
00048
00049 hwloc_obj_t child = obj->first_child;
00050 while (child) {
00051 if (hwloc_bitmap_intersects(child->cpuset, set))
00052 break;
00053 child = child->next_sibling;
00054 }
00055 if (!child)
00056
00057 return obj;
00058
00059 obj = child;
00060 }
00061
00062 return obj;
00063 }
00064
00069 HWLOC_DECLSPEC int hwloc_get_largest_objs_inside_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set,
00070 hwloc_obj_t * __hwloc_restrict objs, int max);
00071
00084 static __hwloc_inline hwloc_obj_t
00085 hwloc_get_next_obj_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
00086 int depth, hwloc_obj_t prev)
00087 {
00088 hwloc_obj_t next = hwloc_get_next_obj_by_depth(topology, depth, prev);
00089 if (!next)
00090 return NULL;
00091 while (next && (hwloc_bitmap_iszero(next->cpuset) || !hwloc_bitmap_isincluded(next->cpuset, set)))
00092 next = next->next_cousin;
00093 return next;
00094 }
00095
00108 static __hwloc_inline hwloc_obj_t
00109 hwloc_get_next_obj_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
00110 hwloc_obj_type_t type, hwloc_obj_t prev)
00111 {
00112 int depth = hwloc_get_type_depth(topology, type);
00113 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
00114 return NULL;
00115 return hwloc_get_next_obj_inside_cpuset_by_depth(topology, set, depth, prev);
00116 }
00117
00126 static __hwloc_inline hwloc_obj_t
00127 hwloc_get_obj_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
00128 int depth, unsigned idx) __hwloc_attribute_pure;
00129 static __hwloc_inline hwloc_obj_t
00130 hwloc_get_obj_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
00131 int depth, unsigned idx)
00132 {
00133 hwloc_obj_t obj = hwloc_get_obj_by_depth (topology, depth, 0);
00134 unsigned count = 0;
00135 if (!obj)
00136 return NULL;
00137 while (obj) {
00138 if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set)) {
00139 if (count == idx)
00140 return obj;
00141 count++;
00142 }
00143 obj = obj->next_cousin;
00144 }
00145 return NULL;
00146 }
00147
00160 static __hwloc_inline hwloc_obj_t
00161 hwloc_get_obj_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
00162 hwloc_obj_type_t type, unsigned idx) __hwloc_attribute_pure;
00163 static __hwloc_inline hwloc_obj_t
00164 hwloc_get_obj_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
00165 hwloc_obj_type_t type, unsigned idx)
00166 {
00167 int depth = hwloc_get_type_depth(topology, type);
00168 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
00169 return NULL;
00170 return hwloc_get_obj_inside_cpuset_by_depth(topology, set, depth, idx);
00171 }
00172
00181 static __hwloc_inline unsigned
00182 hwloc_get_nbobjs_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
00183 int depth) __hwloc_attribute_pure;
00184 static __hwloc_inline unsigned
00185 hwloc_get_nbobjs_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
00186 int depth)
00187 {
00188 hwloc_obj_t obj = hwloc_get_obj_by_depth (topology, depth, 0);
00189 unsigned count = 0;
00190 if (!obj)
00191 return 0;
00192 while (obj) {
00193 if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set))
00194 count++;
00195 obj = obj->next_cousin;
00196 }
00197 return count;
00198 }
00199
00212 static __hwloc_inline int
00213 hwloc_get_nbobjs_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
00214 hwloc_obj_type_t type) __hwloc_attribute_pure;
00215 static __hwloc_inline int
00216 hwloc_get_nbobjs_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
00217 hwloc_obj_type_t type)
00218 {
00219 int depth = hwloc_get_type_depth(topology, type);
00220 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
00221 return 0;
00222 if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
00223 return -1;
00224 return (int) hwloc_get_nbobjs_inside_cpuset_by_depth(topology, set, depth);
00225 }
00226
00240 static __hwloc_inline int
00241 hwloc_get_obj_index_inside_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
00242 hwloc_obj_t obj) __hwloc_attribute_pure;
00243 static __hwloc_inline int
00244 hwloc_get_obj_index_inside_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
00245 hwloc_obj_t obj)
00246 {
00247 int idx = 0;
00248 if (!hwloc_bitmap_isincluded(obj->cpuset, set))
00249 return -1;
00250
00251 while ((obj = obj->prev_cousin) != NULL)
00252 if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set))
00253 idx++;
00254 return idx;
00255 }
00256
00271 static __hwloc_inline hwloc_obj_t
00272 hwloc_get_child_covering_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
00273 hwloc_obj_t parent) __hwloc_attribute_pure;
00274 static __hwloc_inline hwloc_obj_t
00275 hwloc_get_child_covering_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
00276 hwloc_obj_t parent)
00277 {
00278 hwloc_obj_t child;
00279 if (hwloc_bitmap_iszero(set))
00280 return NULL;
00281 child = parent->first_child;
00282 while (child) {
00283 if (child->cpuset && hwloc_bitmap_isincluded(set, child->cpuset))
00284 return child;
00285 child = child->next_sibling;
00286 }
00287 return NULL;
00288 }
00289
00294 static __hwloc_inline hwloc_obj_t
00295 hwloc_get_obj_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set) __hwloc_attribute_pure;
00296 static __hwloc_inline hwloc_obj_t
00297 hwloc_get_obj_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set)
00298 {
00299 struct hwloc_obj *current = hwloc_get_root_obj(topology);
00300 if (hwloc_bitmap_iszero(set) || !hwloc_bitmap_isincluded(set, current->cpuset))
00301 return NULL;
00302 while (1) {
00303 hwloc_obj_t child = hwloc_get_child_covering_cpuset(topology, set, current);
00304 if (!child)
00305 return current;
00306 current = child;
00307 }
00308 }
00309
00320 static __hwloc_inline hwloc_obj_t
00321 hwloc_get_next_obj_covering_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set,
00322 int depth, hwloc_obj_t prev)
00323 {
00324 hwloc_obj_t next = hwloc_get_next_obj_by_depth(topology, depth, prev);
00325 if (!next)
00326 return NULL;
00327 while (next && !hwloc_bitmap_intersects(set, next->cpuset))
00328 next = next->next_cousin;
00329 return next;
00330 }
00331
00347 static __hwloc_inline hwloc_obj_t
00348 hwloc_get_next_obj_covering_cpuset_by_type(hwloc_topology_t topology, hwloc_const_cpuset_t set,
00349 hwloc_obj_type_t type, hwloc_obj_t prev)
00350 {
00351 int depth = hwloc_get_type_depth(topology, type);
00352 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
00353 return NULL;
00354 return hwloc_get_next_obj_covering_cpuset_by_depth(topology, set, depth, prev);
00355 }
00356
00377 static __hwloc_inline hwloc_obj_t
00378 hwloc_get_ancestor_obj_by_depth (hwloc_topology_t topology __hwloc_attribute_unused, int depth, hwloc_obj_t obj) __hwloc_attribute_pure;
00379 static __hwloc_inline hwloc_obj_t
00380 hwloc_get_ancestor_obj_by_depth (hwloc_topology_t topology __hwloc_attribute_unused, int depth, hwloc_obj_t obj)
00381 {
00382 hwloc_obj_t ancestor = obj;
00383 if (obj->depth < depth)
00384 return NULL;
00385 while (ancestor && ancestor->depth > depth)
00386 ancestor = ancestor->parent;
00387 return ancestor;
00388 }
00389
00397 static __hwloc_inline hwloc_obj_t
00398 hwloc_get_ancestor_obj_by_type (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_type_t type, hwloc_obj_t obj) __hwloc_attribute_pure;
00399 static __hwloc_inline hwloc_obj_t
00400 hwloc_get_ancestor_obj_by_type (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_type_t type, hwloc_obj_t obj)
00401 {
00402 hwloc_obj_t ancestor = obj->parent;
00403 while (ancestor && ancestor->type != type)
00404 ancestor = ancestor->parent;
00405 return ancestor;
00406 }
00407
00409 static __hwloc_inline hwloc_obj_t
00410 hwloc_get_common_ancestor_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj1, hwloc_obj_t obj2) __hwloc_attribute_pure;
00411 static __hwloc_inline hwloc_obj_t
00412 hwloc_get_common_ancestor_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj1, hwloc_obj_t obj2)
00413 {
00414
00415
00416
00417
00418
00419 while (obj1 != obj2) {
00420 while (obj1->depth > obj2->depth)
00421 obj1 = obj1->parent;
00422 while (obj2->depth > obj1->depth)
00423 obj2 = obj2->parent;
00424 if (obj1 != obj2 && obj1->depth == obj2->depth) {
00425 obj1 = obj1->parent;
00426 obj2 = obj2->parent;
00427 }
00428 }
00429 return obj1;
00430 }
00431
00437 static __hwloc_inline int
00438 hwloc_obj_is_in_subtree (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj, hwloc_obj_t subtree_root) __hwloc_attribute_pure;
00439 static __hwloc_inline int
00440 hwloc_obj_is_in_subtree (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj, hwloc_obj_t subtree_root)
00441 {
00442 return obj->cpuset && subtree_root->cpuset && hwloc_bitmap_isincluded(obj->cpuset, subtree_root->cpuset);
00443 }
00444
00455 static __hwloc_inline hwloc_obj_t
00456 hwloc_get_next_child (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t parent, hwloc_obj_t prev)
00457 {
00458 hwloc_obj_t obj;
00459 int state = 0;
00460 if (prev) {
00461 if (prev->type == HWLOC_OBJ_MISC)
00462 state = 3;
00463 else if (prev->type == HWLOC_OBJ_BRIDGE || prev->type == HWLOC_OBJ_PCI_DEVICE || prev->type == HWLOC_OBJ_OS_DEVICE)
00464 state = 2;
00465 else if (prev->type == HWLOC_OBJ_NUMANODE)
00466 state = 1;
00467 obj = prev->next_sibling;
00468 } else {
00469 obj = parent->first_child;
00470 }
00471 if (!obj && state == 0) {
00472 obj = parent->memory_first_child;
00473 state = 1;
00474 }
00475 if (!obj && state == 1) {
00476 obj = parent->io_first_child;
00477 state = 2;
00478 }
00479 if (!obj && state == 2) {
00480 obj = parent->misc_first_child;
00481 state = 3;
00482 }
00483 return obj;
00484 }
00485
00512 HWLOC_DECLSPEC int
00513 hwloc_obj_type_is_normal(hwloc_obj_type_t type);
00514
00523 HWLOC_DECLSPEC int
00524 hwloc_obj_type_is_io(hwloc_obj_type_t type);
00525
00534 HWLOC_DECLSPEC int
00535 hwloc_obj_type_is_memory(hwloc_obj_type_t type);
00536
00543 HWLOC_DECLSPEC int
00544 hwloc_obj_type_is_cache(hwloc_obj_type_t type);
00545
00552 HWLOC_DECLSPEC int
00553 hwloc_obj_type_is_dcache(hwloc_obj_type_t type);
00554
00561 HWLOC_DECLSPEC int
00562 hwloc_obj_type_is_icache(hwloc_obj_type_t type);
00563
00593 static __hwloc_inline int
00594 hwloc_get_cache_type_depth (hwloc_topology_t topology,
00595 unsigned cachelevel, hwloc_obj_cache_type_t cachetype)
00596 {
00597 int depth;
00598 int found = HWLOC_TYPE_DEPTH_UNKNOWN;
00599 for (depth=0; ; depth++) {
00600 hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, depth, 0);
00601 if (!obj)
00602 break;
00603 if (!hwloc_obj_type_is_dcache(obj->type) || obj->attr->cache.depth != cachelevel)
00604
00605 continue;
00606 if (cachetype == (hwloc_obj_cache_type_t) -1) {
00607 if (found != HWLOC_TYPE_DEPTH_UNKNOWN) {
00608
00609 return HWLOC_TYPE_DEPTH_MULTIPLE;
00610 }
00611
00612 found = depth;
00613 continue;
00614 }
00615 if (obj->attr->cache.type == cachetype || obj->attr->cache.type == HWLOC_OBJ_CACHE_UNIFIED)
00616
00617 return depth;
00618 }
00619
00620 return found;
00621 }
00622
00627 static __hwloc_inline hwloc_obj_t
00628 hwloc_get_cache_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set) __hwloc_attribute_pure;
00629 static __hwloc_inline hwloc_obj_t
00630 hwloc_get_cache_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set)
00631 {
00632 hwloc_obj_t current = hwloc_get_obj_covering_cpuset(topology, set);
00633 while (current) {
00634 if (hwloc_obj_type_is_dcache(current->type))
00635 return current;
00636 current = current->parent;
00637 }
00638 return NULL;
00639 }
00640
00645 static __hwloc_inline hwloc_obj_t
00646 hwloc_get_shared_cache_covering_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj) __hwloc_attribute_pure;
00647 static __hwloc_inline hwloc_obj_t
00648 hwloc_get_shared_cache_covering_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj)
00649 {
00650 hwloc_obj_t current = obj->parent;
00651 if (!obj->cpuset)
00652 return NULL;
00653 while (current) {
00654 if (!hwloc_bitmap_isequal(current->cpuset, obj->cpuset)
00655 && hwloc_obj_type_is_dcache(current->type))
00656 return current;
00657 current = current->parent;
00658 }
00659 return NULL;
00660 }
00661
00684 static __hwloc_inline hwloc_obj_t
00685 hwloc_get_pu_obj_by_os_index(hwloc_topology_t topology, unsigned os_index) __hwloc_attribute_pure;
00686 static __hwloc_inline hwloc_obj_t
00687 hwloc_get_pu_obj_by_os_index(hwloc_topology_t topology, unsigned os_index)
00688 {
00689 hwloc_obj_t obj = NULL;
00690 while ((obj = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_PU, obj)) != NULL)
00691 if (obj->os_index == os_index)
00692 return obj;
00693 return NULL;
00694 }
00695
00705 static __hwloc_inline hwloc_obj_t
00706 hwloc_get_numanode_obj_by_os_index(hwloc_topology_t topology, unsigned os_index) __hwloc_attribute_pure;
00707 static __hwloc_inline hwloc_obj_t
00708 hwloc_get_numanode_obj_by_os_index(hwloc_topology_t topology, unsigned os_index)
00709 {
00710 hwloc_obj_t obj = NULL;
00711 while ((obj = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_NUMANODE, obj)) != NULL)
00712 if (obj->os_index == os_index)
00713 return obj;
00714 return NULL;
00715 }
00716
00728
00729 HWLOC_DECLSPEC unsigned hwloc_get_closest_objs (hwloc_topology_t topology, hwloc_obj_t src, hwloc_obj_t * __hwloc_restrict objs, unsigned max);
00730
00743 static __hwloc_inline hwloc_obj_t
00744 hwloc_get_obj_below_by_type (hwloc_topology_t topology,
00745 hwloc_obj_type_t type1, unsigned idx1,
00746 hwloc_obj_type_t type2, unsigned idx2) __hwloc_attribute_pure;
00747 static __hwloc_inline hwloc_obj_t
00748 hwloc_get_obj_below_by_type (hwloc_topology_t topology,
00749 hwloc_obj_type_t type1, unsigned idx1,
00750 hwloc_obj_type_t type2, unsigned idx2)
00751 {
00752 hwloc_obj_t obj;
00753 obj = hwloc_get_obj_by_type (topology, type1, idx1);
00754 if (!obj)
00755 return NULL;
00756 return hwloc_get_obj_inside_cpuset_by_type(topology, obj->cpuset, type2, idx2);
00757 }
00758
00777 static __hwloc_inline hwloc_obj_t
00778 hwloc_get_obj_below_array_by_type (hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv) __hwloc_attribute_pure;
00779 static __hwloc_inline hwloc_obj_t
00780 hwloc_get_obj_below_array_by_type (hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv)
00781 {
00782 hwloc_obj_t obj = hwloc_get_root_obj(topology);
00783 int i;
00784 for(i=0; i<nr; i++) {
00785 if (!obj)
00786 return NULL;
00787 obj = hwloc_get_obj_inside_cpuset_by_type(topology, obj->cpuset, typev[i], idxv[i]);
00788 }
00789 return obj;
00790 }
00791
00802 enum hwloc_distrib_flags_e {
00806 HWLOC_DISTRIB_FLAG_REVERSE = (1UL<<0)
00807 };
00808
00832 static __hwloc_inline int
00833 hwloc_distrib(hwloc_topology_t topology,
00834 hwloc_obj_t *roots, unsigned n_roots,
00835 hwloc_cpuset_t *set,
00836 unsigned n,
00837 int until, unsigned long flags)
00838 {
00839 unsigned i;
00840 unsigned tot_weight;
00841 unsigned given, givenweight;
00842 hwloc_cpuset_t *cpusetp = set;
00843
00844 if (flags & ~HWLOC_DISTRIB_FLAG_REVERSE) {
00845 errno = EINVAL;
00846 return -1;
00847 }
00848
00849 tot_weight = 0;
00850 for (i = 0; i < n_roots; i++)
00851 tot_weight += (unsigned) hwloc_bitmap_weight(roots[i]->cpuset);
00852
00853 for (i = 0, given = 0, givenweight = 0; i < n_roots; i++) {
00854 unsigned chunk, weight;
00855 hwloc_obj_t root = roots[flags & HWLOC_DISTRIB_FLAG_REVERSE ? n_roots-1-i : i];
00856 hwloc_cpuset_t cpuset = root->cpuset;
00857 if (root->type == HWLOC_OBJ_NUMANODE)
00858
00859 root = root->parent;
00860 weight = (unsigned) hwloc_bitmap_weight(cpuset);
00861 if (!weight)
00862 continue;
00863
00864
00865 chunk = (( (givenweight+weight) * n + tot_weight-1) / tot_weight)
00866 - (( givenweight * n + tot_weight-1) / tot_weight);
00867 if (!root->arity || chunk <= 1 || root->depth >= until) {
00868
00869 if (chunk) {
00870
00871 unsigned j;
00872 for (j=0; j < chunk; j++)
00873 cpusetp[j] = hwloc_bitmap_dup(cpuset);
00874 } else {
00875
00876
00877
00878
00879 assert(given);
00880 hwloc_bitmap_or(cpusetp[-1], cpusetp[-1], cpuset);
00881 }
00882 } else {
00883
00884 hwloc_distrib(topology, root->children, root->arity, cpusetp, chunk, until, flags);
00885 }
00886 cpusetp += chunk;
00887 given += chunk;
00888 givenweight += weight;
00889 }
00890
00891 return 0;
00892 }
00893
00911 HWLOC_DECLSPEC hwloc_const_cpuset_t
00912 hwloc_topology_get_complete_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
00913
00925 HWLOC_DECLSPEC hwloc_const_cpuset_t
00926 hwloc_topology_get_topology_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
00927
00944 HWLOC_DECLSPEC hwloc_const_cpuset_t
00945 hwloc_topology_get_allowed_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
00946
00956 HWLOC_DECLSPEC hwloc_const_nodeset_t
00957 hwloc_topology_get_complete_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
00958
00970 HWLOC_DECLSPEC hwloc_const_nodeset_t
00971 hwloc_topology_get_topology_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
00972
00989 HWLOC_DECLSPEC hwloc_const_nodeset_t
00990 hwloc_topology_get_allowed_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
00991
01012 static __hwloc_inline int
01013 hwloc_cpuset_to_nodeset(hwloc_topology_t topology, hwloc_const_cpuset_t _cpuset, hwloc_nodeset_t nodeset)
01014 {
01015 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
01016 hwloc_obj_t obj = NULL;
01017 assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
01018 hwloc_bitmap_zero(nodeset);
01019 while ((obj = hwloc_get_next_obj_covering_cpuset_by_depth(topology, _cpuset, depth, obj)) != NULL)
01020 if (hwloc_bitmap_set(nodeset, obj->os_index) < 0)
01021 return -1;
01022 return 0;
01023 }
01024
01036 static __hwloc_inline int
01037 hwloc_cpuset_from_nodeset(hwloc_topology_t topology, hwloc_cpuset_t _cpuset, hwloc_const_nodeset_t nodeset)
01038 {
01039 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
01040 hwloc_obj_t obj = NULL;
01041 assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
01042 hwloc_bitmap_zero(_cpuset);
01043 while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL) {
01044 if (hwloc_bitmap_isset(nodeset, obj->os_index))
01045
01046 if (hwloc_bitmap_or(_cpuset, _cpuset, obj->cpuset) < 0)
01047 return -1;
01048 }
01049 return 0;
01050 }
01051
01071 static __hwloc_inline hwloc_obj_t
01072 hwloc_get_non_io_ancestor_obj(hwloc_topology_t topology __hwloc_attribute_unused,
01073 hwloc_obj_t ioobj)
01074 {
01075 hwloc_obj_t obj = ioobj;
01076 while (obj && !obj->cpuset) {
01077 obj = obj->parent;
01078 }
01079 return obj;
01080 }
01081
01086 static __hwloc_inline hwloc_obj_t
01087 hwloc_get_next_pcidev(hwloc_topology_t topology, hwloc_obj_t prev)
01088 {
01089 return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_PCI_DEVICE, prev);
01090 }
01091
01095 static __hwloc_inline hwloc_obj_t
01096 hwloc_get_pcidev_by_busid(hwloc_topology_t topology,
01097 unsigned domain, unsigned bus, unsigned dev, unsigned func)
01098 {
01099 hwloc_obj_t obj = NULL;
01100 while ((obj = hwloc_get_next_pcidev(topology, obj)) != NULL) {
01101 if (obj->attr->pcidev.domain == domain
01102 && obj->attr->pcidev.bus == bus
01103 && obj->attr->pcidev.dev == dev
01104 && obj->attr->pcidev.func == func)
01105 return obj;
01106 }
01107 return NULL;
01108 }
01109
01113 static __hwloc_inline hwloc_obj_t
01114 hwloc_get_pcidev_by_busidstring(hwloc_topology_t topology, const char *busid)
01115 {
01116 unsigned domain = 0;
01117 unsigned bus, dev, func;
01118
01119 if (sscanf(busid, "%x:%x.%x", &bus, &dev, &func) != 3
01120 && sscanf(busid, "%x:%x:%x.%x", &domain, &bus, &dev, &func) != 4) {
01121 errno = EINVAL;
01122 return NULL;
01123 }
01124
01125 return hwloc_get_pcidev_by_busid(topology, domain, bus, dev, func);
01126 }
01127
01132 static __hwloc_inline hwloc_obj_t
01133 hwloc_get_next_osdev(hwloc_topology_t topology, hwloc_obj_t prev)
01134 {
01135 return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_OS_DEVICE, prev);
01136 }
01137
01142 static __hwloc_inline hwloc_obj_t
01143 hwloc_get_next_bridge(hwloc_topology_t topology, hwloc_obj_t prev)
01144 {
01145 return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_BRIDGE, prev);
01146 }
01147
01148
01149
01150 static __hwloc_inline int
01151 hwloc_bridge_covers_pcibus(hwloc_obj_t bridge,
01152 unsigned domain, unsigned bus)
01153 {
01154 return bridge->type == HWLOC_OBJ_BRIDGE
01155 && bridge->attr->bridge.downstream_type == HWLOC_OBJ_BRIDGE_PCI
01156 && bridge->attr->bridge.downstream.pci.domain == domain
01157 && bridge->attr->bridge.downstream.pci.secondary_bus <= bus
01158 && bridge->attr->bridge.downstream.pci.subordinate_bus >= bus;
01159 }
01160
01165 #ifdef __cplusplus
01166 }
01167 #endif
01168
01169
01170 #endif