Hardware Locality (hwloc)  v2.9-20240516.0330.gitc804b6c6
helper.h
1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2023 Inria. All rights reserved.
4  * Copyright © 2009-2012 Université Bordeaux
5  * Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved.
6  * See COPYING in top-level directory.
7  */
8 
13 #ifndef HWLOC_HELPER_H
14 #define HWLOC_HELPER_H
15 
16 #ifndef HWLOC_H
17 #error Please include the main hwloc.h instead
18 #endif
19 
20 #include <stdlib.h>
21 #include <errno.h>
22 
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 
42 static __hwloc_inline hwloc_obj_t
44 {
45  hwloc_obj_t obj = hwloc_get_root_obj(topology);
46  if (!hwloc_bitmap_intersects(obj->cpuset, set))
47  return NULL;
48  while (!hwloc_bitmap_isincluded(obj->cpuset, set)) {
49  /* while the object intersects without being included, look at its children */
50  hwloc_obj_t child = obj->first_child;
51  while (child) {
52  if (hwloc_bitmap_intersects(child->cpuset, set))
53  break;
54  child = child->next_sibling;
55  }
56  if (!child)
57  /* no child intersects, return their father */
58  return obj;
59  /* found one intersecting child, look at its children */
60  obj = child;
61  }
62  /* obj is included, return it */
63  return obj;
64 }
65 
72  hwloc_obj_t * __hwloc_restrict objs, int max);
73 
89 static __hwloc_inline hwloc_obj_t
91  int depth, hwloc_obj_t prev)
92 {
93  hwloc_obj_t next = hwloc_get_next_obj_by_depth(topology, depth, prev);
94  if (!next)
95  return NULL;
96  while (next && (hwloc_bitmap_iszero(next->cpuset) || !hwloc_bitmap_isincluded(next->cpuset, set)))
97  next = next->next_cousin;
98  return next;
99 }
100 
119 static __hwloc_inline hwloc_obj_t
121  hwloc_obj_type_t type, hwloc_obj_t prev)
122 {
123  int depth = hwloc_get_type_depth(topology, type);
124  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
125  return NULL;
126  return hwloc_get_next_obj_inside_cpuset_by_depth(topology, set, depth, prev);
127 }
128 
139 static __hwloc_inline hwloc_obj_t
141  int depth, unsigned idx) __hwloc_attribute_pure;
142 static __hwloc_inline hwloc_obj_t
144  int depth, unsigned idx)
145 {
146  hwloc_obj_t obj = hwloc_get_obj_by_depth (topology, depth, 0);
147  unsigned count = 0;
148  if (!obj)
149  return NULL;
150  while (obj) {
151  if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set)) {
152  if (count == idx)
153  return obj;
154  count++;
155  }
156  obj = obj->next_cousin;
157  }
158  return NULL;
159 }
160 
175 static __hwloc_inline hwloc_obj_t
177  hwloc_obj_type_t type, unsigned idx) __hwloc_attribute_pure;
178 static __hwloc_inline hwloc_obj_t
180  hwloc_obj_type_t type, unsigned idx)
181 {
182  int depth = hwloc_get_type_depth(topology, type);
183  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
184  return NULL;
185  return hwloc_get_obj_inside_cpuset_by_depth(topology, set, depth, idx);
186 }
187 
199 static __hwloc_inline unsigned
201  int depth) __hwloc_attribute_pure;
202 static __hwloc_inline unsigned
204  int depth)
205 {
206  hwloc_obj_t obj = hwloc_get_obj_by_depth (topology, depth, 0);
207  unsigned count = 0;
208  if (!obj)
209  return 0;
210  while (obj) {
211  if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set))
212  count++;
213  obj = obj->next_cousin;
214  }
215  return count;
216 }
217 
231 static __hwloc_inline int
233  hwloc_obj_type_t type) __hwloc_attribute_pure;
234 static __hwloc_inline int
236  hwloc_obj_type_t type)
237 {
238  int depth = hwloc_get_type_depth(topology, type);
239  if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
240  return 0;
241  if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
242  return -1; /* FIXME: agregate nbobjs from different levels? */
243  return (int) hwloc_get_nbobjs_inside_cpuset_by_depth(topology, set, depth);
244 }
245 
262 static __hwloc_inline int
263 hwloc_get_obj_index_inside_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
264  hwloc_obj_t obj) __hwloc_attribute_pure;
265 static __hwloc_inline int
267  hwloc_obj_t obj)
268 {
269  int idx = 0;
270  if (!hwloc_bitmap_isincluded(obj->cpuset, set))
271  return -1;
272  /* count how many objects are inside the cpuset on the way from us to the beginning of the level */
273  while ((obj = obj->prev_cousin) != NULL)
274  if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set))
275  idx++;
276  return idx;
277 }
278 
294 static __hwloc_inline hwloc_obj_t
295 hwloc_get_child_covering_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
296  hwloc_obj_t parent) __hwloc_attribute_pure;
297 static __hwloc_inline hwloc_obj_t
299  hwloc_obj_t parent)
300 {
301  hwloc_obj_t child;
302  if (hwloc_bitmap_iszero(set))
303  return NULL;
304  child = parent->first_child;
305  while (child) {
306  if (child->cpuset && hwloc_bitmap_isincluded(set, child->cpuset))
307  return child;
308  child = child->next_sibling;
309  }
310  return NULL;
311 }
312 
318 static __hwloc_inline hwloc_obj_t
319 hwloc_get_obj_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set) __hwloc_attribute_pure;
320 static __hwloc_inline hwloc_obj_t
322 {
323  struct hwloc_obj *current = hwloc_get_root_obj(topology);
324  if (hwloc_bitmap_iszero(set) || !hwloc_bitmap_isincluded(set, current->cpuset))
325  return NULL;
326  while (1) {
327  hwloc_obj_t child = hwloc_get_child_covering_cpuset(topology, set, current);
328  if (!child)
329  return current;
330  current = child;
331  }
332 }
333 
347 static __hwloc_inline hwloc_obj_t
349  int depth, hwloc_obj_t prev)
350 {
351  hwloc_obj_t next = hwloc_get_next_obj_by_depth(topology, depth, prev);
352  if (!next)
353  return NULL;
354  while (next && !hwloc_bitmap_intersects(set, next->cpuset))
355  next = next->next_cousin;
356  return next;
357 }
358 
375 static __hwloc_inline hwloc_obj_t
378 {
379  int depth = hwloc_get_type_depth(topology, type);
381  return NULL;
382  return hwloc_get_next_obj_covering_cpuset_by_depth(topology, set, depth, prev);
383 }
384 
408 static __hwloc_inline hwloc_obj_t
409 hwloc_get_ancestor_obj_by_depth (hwloc_topology_t topology __hwloc_attribute_unused, int depth, hwloc_obj_t obj) __hwloc_attribute_pure;
410 static __hwloc_inline hwloc_obj_t
411 hwloc_get_ancestor_obj_by_depth (hwloc_topology_t topology __hwloc_attribute_unused, int depth, hwloc_obj_t obj)
412 {
413  hwloc_obj_t ancestor = obj;
414  if (obj->depth < depth)
415  return NULL;
416  while (ancestor && ancestor->depth > depth)
417  ancestor = ancestor->parent;
418  return ancestor;
419 }
420 
434 static __hwloc_inline hwloc_obj_t
435 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;
436 static __hwloc_inline hwloc_obj_t
438 {
439  hwloc_obj_t ancestor = obj->parent;
440  while (ancestor && ancestor->type != type)
441  ancestor = ancestor->parent;
442  return ancestor;
443 }
444 
451 static __hwloc_inline hwloc_obj_t
452 hwloc_get_common_ancestor_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj1, hwloc_obj_t obj2) __hwloc_attribute_pure;
453 static __hwloc_inline hwloc_obj_t
454 hwloc_get_common_ancestor_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj1, hwloc_obj_t obj2)
455 {
456  /* the loop isn't so easy since intermediate ancestors may have
457  * different depth, causing us to alternate between using obj1->parent
458  * and obj2->parent. Also, even if at some point we find ancestors of
459  * of the same depth, their ancestors may have different depth again.
460  */
461  while (obj1 != obj2) {
462  while (obj1->depth > obj2->depth)
463  obj1 = obj1->parent;
464  while (obj2->depth > obj1->depth)
465  obj2 = obj2->parent;
466  if (obj1 != obj2 && obj1->depth == obj2->depth) {
467  obj1 = obj1->parent;
468  obj2 = obj2->parent;
469  }
470  }
471  return obj1;
472 }
473 
481 static __hwloc_inline int
482 hwloc_obj_is_in_subtree (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj, hwloc_obj_t subtree_root) __hwloc_attribute_pure;
483 static __hwloc_inline int
484 hwloc_obj_is_in_subtree (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj, hwloc_obj_t subtree_root)
485 {
486  return obj->cpuset && subtree_root->cpuset && hwloc_bitmap_isincluded(obj->cpuset, subtree_root->cpuset);
487 }
488 
499 static __hwloc_inline hwloc_obj_t
500 hwloc_get_next_child (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t parent, hwloc_obj_t prev)
501 {
502  hwloc_obj_t obj;
503  int state = 0;
504  if (prev) {
505  if (prev->type == HWLOC_OBJ_MISC)
506  state = 3;
507  else if (prev->type == HWLOC_OBJ_BRIDGE || prev->type == HWLOC_OBJ_PCI_DEVICE || prev->type == HWLOC_OBJ_OS_DEVICE)
508  state = 2;
509  else if (prev->type == HWLOC_OBJ_NUMANODE || prev->type == HWLOC_OBJ_MEMCACHE)
510  state = 1;
511  obj = prev->next_sibling;
512  } else {
513  obj = parent->first_child;
514  }
515  if (!obj && state == 0) {
516  obj = parent->memory_first_child;
517  state = 1;
518  }
519  if (!obj && state == 1) {
520  obj = parent->io_first_child;
521  state = 2;
522  }
523  if (!obj && state == 2) {
524  obj = parent->misc_first_child;
525  state = 3;
526  }
527  return obj;
528 }
529 
556 HWLOC_DECLSPEC int
558 
567 HWLOC_DECLSPEC int
569 
578 HWLOC_DECLSPEC int
580 
587 HWLOC_DECLSPEC int
589 
596 HWLOC_DECLSPEC int
598 
605 HWLOC_DECLSPEC int
607 
639 static __hwloc_inline int
641  unsigned cachelevel, hwloc_obj_cache_type_t cachetype)
642 {
643  int depth;
644  int found = HWLOC_TYPE_DEPTH_UNKNOWN;
645  for (depth=0; ; depth++) {
646  hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, depth, 0);
647  if (!obj)
648  break;
649  if (!hwloc_obj_type_is_dcache(obj->type) || obj->attr->cache.depth != cachelevel)
650  /* doesn't match, try next depth */
651  continue;
652  if (cachetype == (hwloc_obj_cache_type_t) -1) {
653  if (found != HWLOC_TYPE_DEPTH_UNKNOWN) {
654  /* second match, return MULTIPLE */
656  }
657  /* first match, mark it as found */
658  found = depth;
659  continue;
660  }
661  if (obj->attr->cache.type == cachetype || obj->attr->cache.type == HWLOC_OBJ_CACHE_UNIFIED)
662  /* exact match (either unified is alone, or we match instruction or data), return immediately */
663  return depth;
664  }
665  /* went to the bottom, return what we found */
666  return found;
667 }
668 
673 static __hwloc_inline hwloc_obj_t
674 hwloc_get_cache_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set) __hwloc_attribute_pure;
675 static __hwloc_inline hwloc_obj_t
677 {
678  hwloc_obj_t current = hwloc_get_obj_covering_cpuset(topology, set);
679  while (current) {
680  if (hwloc_obj_type_is_dcache(current->type))
681  return current;
682  current = current->parent;
683  }
684  return NULL;
685 }
686 
692 static __hwloc_inline hwloc_obj_t
693 hwloc_get_shared_cache_covering_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj) __hwloc_attribute_pure;
694 static __hwloc_inline hwloc_obj_t
695 hwloc_get_shared_cache_covering_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj)
696 {
697  hwloc_obj_t current = obj->parent;
698  if (!obj->cpuset)
699  return NULL;
700  while (current) {
701  if (!hwloc_bitmap_isequal(current->cpuset, obj->cpuset)
702  && hwloc_obj_type_is_dcache(current->type))
703  return current;
704  current = current->parent;
705  }
706  return NULL;
707 }
708 
740 HWLOC_DECLSPEC int hwloc_bitmap_singlify_per_core(hwloc_topology_t topology, hwloc_bitmap_t cpuset, unsigned which);
741 
753 static __hwloc_inline hwloc_obj_t
754 hwloc_get_pu_obj_by_os_index(hwloc_topology_t topology, unsigned os_index) __hwloc_attribute_pure;
755 static __hwloc_inline hwloc_obj_t
757 {
758  hwloc_obj_t obj = NULL;
759  while ((obj = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_PU, obj)) != NULL)
760  if (obj->os_index == os_index)
761  return obj;
762  return NULL;
763 }
764 
776 static __hwloc_inline hwloc_obj_t
777 hwloc_get_numanode_obj_by_os_index(hwloc_topology_t topology, unsigned os_index) __hwloc_attribute_pure;
778 static __hwloc_inline hwloc_obj_t
780 {
781  hwloc_obj_t obj = NULL;
782  while ((obj = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_NUMANODE, obj)) != NULL)
783  if (obj->os_index == os_index)
784  return obj;
785  return NULL;
786 }
787 
799 /* TODO: rather provide an iterator? Provide a way to know how much should be allocated? By returning the total number of objects instead? */
800 HWLOC_DECLSPEC unsigned hwloc_get_closest_objs (hwloc_topology_t topology, hwloc_obj_t src, hwloc_obj_t * __hwloc_restrict objs, unsigned max);
801 
816 static __hwloc_inline hwloc_obj_t
818  hwloc_obj_type_t type1, unsigned idx1,
819  hwloc_obj_type_t type2, unsigned idx2) __hwloc_attribute_pure;
820 static __hwloc_inline hwloc_obj_t
822  hwloc_obj_type_t type1, unsigned idx1,
823  hwloc_obj_type_t type2, unsigned idx2)
824 {
825  hwloc_obj_t obj;
826  obj = hwloc_get_obj_by_type (topology, type1, idx1);
827  if (!obj)
828  return NULL;
829  return hwloc_get_obj_inside_cpuset_by_type(topology, obj->cpuset, type2, idx2);
830 }
831 
852 static __hwloc_inline hwloc_obj_t
853 hwloc_get_obj_below_array_by_type (hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv) __hwloc_attribute_pure;
854 static __hwloc_inline hwloc_obj_t
855 hwloc_get_obj_below_array_by_type (hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv)
856 {
857  hwloc_obj_t obj = hwloc_get_root_obj(topology);
858  int i;
859  for(i=0; i<nr; i++) {
860  if (!obj)
861  return NULL;
862  obj = hwloc_get_obj_inside_cpuset_by_type(topology, obj->cpuset, typev[i], idxv[i]);
863  }
864  return obj;
865 }
866 
905 HWLOC_DECLSPEC hwloc_obj_t
907  hwloc_obj_type_t type, const char *subtype, const char *nameprefix,
908  unsigned long flags);
909 
925 };
926 
949 static __hwloc_inline int
951  hwloc_obj_t *roots, unsigned n_roots,
952  hwloc_cpuset_t *set,
953  unsigned n,
954  int until, unsigned long flags)
955 {
956  unsigned i;
957  unsigned tot_weight;
958  unsigned given, givenweight;
959  hwloc_cpuset_t *cpusetp = set;
960 
961  if (flags & ~HWLOC_DISTRIB_FLAG_REVERSE) {
962  errno = EINVAL;
963  return -1;
964  }
965 
966  tot_weight = 0;
967  for (i = 0; i < n_roots; i++)
968  tot_weight += (unsigned) hwloc_bitmap_weight(roots[i]->cpuset);
969 
970  for (i = 0, given = 0, givenweight = 0; i < n_roots; i++) {
971  unsigned chunk, weight;
972  hwloc_obj_t root = roots[flags & HWLOC_DISTRIB_FLAG_REVERSE ? n_roots-1-i : i];
973  hwloc_cpuset_t cpuset = root->cpuset;
974  while (!hwloc_obj_type_is_normal(root->type))
975  /* If memory/io/misc, walk up to normal parent */
976  root = root->parent;
977  weight = (unsigned) hwloc_bitmap_weight(cpuset);
978  if (!weight)
979  continue;
980  /* Give to root a chunk proportional to its weight.
981  * If previous chunks got rounded-up, we may get a bit less. */
982  chunk = (( (givenweight+weight) * n + tot_weight-1) / tot_weight)
983  - (( givenweight * n + tot_weight-1) / tot_weight);
984  if (!root->arity || chunk <= 1 || root->depth >= until) {
985  /* We can't split any more, put everything there. */
986  if (chunk) {
987  /* Fill cpusets with ours */
988  unsigned j;
989  for (j=0; j < chunk; j++)
990  cpusetp[j] = hwloc_bitmap_dup(cpuset);
991  } else {
992  /* We got no chunk, just merge our cpuset to a previous one
993  * (the first chunk cannot be empty)
994  * so that this root doesn't get ignored.
995  */
996  assert(given);
997  hwloc_bitmap_or(cpusetp[-1], cpusetp[-1], cpuset);
998  }
999  } else {
1000  /* Still more to distribute, recurse into children */
1001  hwloc_distrib(topology, root->children, root->arity, cpusetp, chunk, until, flags);
1002  }
1003  cpusetp += chunk;
1004  given += chunk;
1005  givenweight += weight;
1006  }
1007 
1008  return 0;
1009 }
1010 
1030 HWLOC_DECLSPEC hwloc_const_cpuset_t
1031 hwloc_topology_get_complete_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
1032 
1046 HWLOC_DECLSPEC hwloc_const_cpuset_t
1047 hwloc_topology_get_topology_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
1048 
1067 HWLOC_DECLSPEC hwloc_const_cpuset_t
1068 hwloc_topology_get_allowed_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
1069 
1081 HWLOC_DECLSPEC hwloc_const_nodeset_t
1082 hwloc_topology_get_complete_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
1083 
1097 HWLOC_DECLSPEC hwloc_const_nodeset_t
1098 hwloc_topology_get_topology_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
1099 
1118 HWLOC_DECLSPEC hwloc_const_nodeset_t
1119 hwloc_topology_get_allowed_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
1120 
1144 static __hwloc_inline int
1146 {
1148  hwloc_obj_t obj = NULL;
1149  assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
1151  while ((obj = hwloc_get_next_obj_covering_cpuset_by_depth(topology, _cpuset, depth, obj)) != NULL)
1152  if (hwloc_bitmap_set(nodeset, obj->os_index) < 0)
1153  return -1;
1154  return 0;
1155 }
1156 
1171 static __hwloc_inline int
1173 {
1175  hwloc_obj_t obj = NULL;
1176  assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
1177  hwloc_bitmap_zero(_cpuset);
1178  while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL) {
1179  if (hwloc_bitmap_isset(nodeset, obj->os_index))
1180  /* no need to check obj->cpuset because objects in levels always have a cpuset */
1181  if (hwloc_bitmap_or(_cpuset, _cpuset, obj->cpuset) < 0)
1182  return -1;
1183  }
1184  return 0;
1185 }
1186 
1210 static __hwloc_inline hwloc_obj_t
1211 hwloc_get_non_io_ancestor_obj(hwloc_topology_t topology __hwloc_attribute_unused,
1212  hwloc_obj_t ioobj)
1213 {
1214  hwloc_obj_t obj = ioobj;
1215  while (obj && !obj->cpuset) {
1216  obj = obj->parent;
1217  }
1218  return obj;
1219 }
1220 
1227 static __hwloc_inline hwloc_obj_t
1229 {
1230  return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_PCI_DEVICE, prev);
1231 }
1232 
1238 static __hwloc_inline hwloc_obj_t
1240  unsigned domain, unsigned bus, unsigned dev, unsigned func)
1241 {
1242  hwloc_obj_t obj = NULL;
1243  while ((obj = hwloc_get_next_pcidev(topology, obj)) != NULL) {
1244  if (obj->attr->pcidev.domain == domain
1245  && obj->attr->pcidev.bus == bus
1246  && obj->attr->pcidev.dev == dev
1247  && obj->attr->pcidev.func == func)
1248  return obj;
1249  }
1250  return NULL;
1251 }
1252 
1258 static __hwloc_inline hwloc_obj_t
1260 {
1261  unsigned domain = 0; /* default */
1262  unsigned bus, dev, func;
1263 
1264  if (sscanf(busid, "%x:%x.%x", &bus, &dev, &func) != 3
1265  && sscanf(busid, "%x:%x:%x.%x", &domain, &bus, &dev, &func) != 4) {
1266  errno = EINVAL;
1267  return NULL;
1268  }
1269 
1270  return hwloc_get_pcidev_by_busid(topology, domain, bus, dev, func);
1271 }
1272 
1279 static __hwloc_inline hwloc_obj_t
1281 {
1282  return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_OS_DEVICE, prev);
1283 }
1284 
1291 static __hwloc_inline hwloc_obj_t
1293 {
1294  return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_BRIDGE, prev);
1295 }
1296 
1297 /* \brief Checks whether a given bridge covers a given PCI bus.
1298  *
1299  * \return 1 if it covers, 0 if not.
1300  */
1301 static __hwloc_inline int
1303  unsigned domain, unsigned bus)
1304 {
1305  return bridge->type == HWLOC_OBJ_BRIDGE
1307  && bridge->attr->bridge.downstream.pci.domain == domain
1308  && bridge->attr->bridge.downstream.pci.secondary_bus <= bus
1309  && bridge->attr->bridge.downstream.pci.subordinate_bus >= bus;
1310 }
1311 
1316 #ifdef __cplusplus
1317 } /* extern "C" */
1318 #endif
1319 
1320 
1321 #endif /* HWLOC_HELPER_H */
hwloc_get_pcidev_by_busidstring
static hwloc_obj_t hwloc_get_pcidev_by_busidstring(hwloc_topology_t topology, const char *busid)
Find the PCI device object matching the PCI bus id given as a string xxxx:yy:zz.t or yy:zz....
Definition: helper.h:1259
hwloc_const_cpuset_t
hwloc_const_bitmap_t hwloc_const_cpuset_t
A non-modifiable hwloc_cpuset_t.
Definition: hwloc.h:163
hwloc_get_pu_obj_by_os_index
static hwloc_obj_t hwloc_get_pu_obj_by_os_index(hwloc_topology_t topology, unsigned os_index)
Returns the object of type HWLOC_OBJ_PU with os_index.
Definition: helper.h:756
hwloc_get_root_obj
static hwloc_obj_t hwloc_get_root_obj(hwloc_topology_t topology)
Returns the top-object of the topology-tree.
hwloc_bitmap_or
int hwloc_bitmap_or(hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Or bitmaps bitmap1 and bitmap2 and store the result in bitmap res.
hwloc_obj_type_is_io
int hwloc_obj_type_is_io(hwloc_obj_type_t type)
Check whether an object type is I/O.
hwloc_topology_get_complete_cpuset
hwloc_const_cpuset_t hwloc_topology_get_complete_cpuset(hwloc_topology_t topology)
Get complete CPU set.
HWLOC_OBJ_CACHE_UNIFIED
@ HWLOC_OBJ_CACHE_UNIFIED
Unified cache.
Definition: hwloc.h:354
hwloc_topology_get_topology_nodeset
hwloc_const_nodeset_t hwloc_topology_get_topology_nodeset(hwloc_topology_t topology)
Get topology node set.
hwloc_bitmap_isequal
int hwloc_bitmap_isequal(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Test whether bitmap bitmap1 is equal to bitmap bitmap2.
hwloc_get_ancestor_obj_by_depth
static hwloc_obj_t hwloc_get_ancestor_obj_by_depth(hwloc_topology_t topology, int depth, hwloc_obj_t obj)
Returns the ancestor object of obj at depth depth.
Definition: helper.h:411
hwloc_get_cache_type_depth
static int hwloc_get_cache_type_depth(hwloc_topology_t topology, unsigned cachelevel, hwloc_obj_cache_type_t cachetype)
Find the depth of cache objects matching cache level and type.
Definition: helper.h:640
hwloc_bitmap_iszero
int hwloc_bitmap_iszero(hwloc_const_bitmap_t bitmap)
Test whether bitmap bitmap is empty.
hwloc_get_next_obj_inside_cpuset_by_depth
static hwloc_obj_t hwloc_get_next_obj_inside_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, int depth, hwloc_obj_t prev)
Return the next object at depth depth included in CPU set set.
Definition: helper.h:90
hwloc_obj::nodeset
hwloc_nodeset_t nodeset
NUMA nodes covered by this object or containing this object.
Definition: hwloc.h:570
hwloc_obj_type_is_memory
int hwloc_obj_type_is_memory(hwloc_obj_type_t type)
Check whether an object type is Memory.
hwloc_get_non_io_ancestor_obj
static hwloc_obj_t hwloc_get_non_io_ancestor_obj(hwloc_topology_t topology, hwloc_obj_t ioobj)
Get the first non-I/O ancestor object.
Definition: helper.h:1211
hwloc_get_obj_by_depth
hwloc_obj_t hwloc_get_obj_by_depth(hwloc_topology_t topology, int depth, unsigned idx)
Returns the topology object at logical index idx from depth depth.
hwloc_obj::subtype
char * subtype
Subtype string to better describe the type field.
Definition: hwloc.h:429
hwloc_obj_attr_u::hwloc_pcidev_attr_s::bus
unsigned char bus
Definition: hwloc.h:669
hwloc_get_child_covering_cpuset
static hwloc_obj_t hwloc_get_child_covering_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_t parent)
Get the child covering at least CPU set set.
Definition: helper.h:298
hwloc_bridge_covers_pcibus
static int hwloc_bridge_covers_pcibus(hwloc_obj_t bridge, unsigned domain, unsigned bus)
Definition: helper.h:1302
hwloc_obj_is_in_subtree
static int hwloc_obj_is_in_subtree(hwloc_topology_t topology, hwloc_obj_t obj, hwloc_obj_t subtree_root)
Returns true if obj is inside the subtree beginning with ancestor object subtree_root.
Definition: helper.h:484
hwloc_obj_attr_u::hwloc_pcidev_attr_s::domain
unsigned short domain
Definition: hwloc.h:665
hwloc_get_largest_objs_inside_cpuset
int hwloc_get_largest_objs_inside_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_t *restrict objs, int max)
Get the set of largest objects covering exactly a given cpuset set.
hwloc_get_next_child
static hwloc_obj_t hwloc_get_next_child(hwloc_topology_t topology, hwloc_obj_t parent, hwloc_obj_t prev)
Return the next child.
Definition: helper.h:500
hwloc_get_common_ancestor_obj
static hwloc_obj_t hwloc_get_common_ancestor_obj(hwloc_topology_t topology, hwloc_obj_t obj1, hwloc_obj_t obj2)
Returns the common parent object to objects obj1 and obj2.
Definition: helper.h:454
HWLOC_OBJ_NUMANODE
@ HWLOC_OBJ_NUMANODE
NUMA node. An object that contains memory that is directly and byte-accessible to the host processors...
Definition: hwloc.h:257
hwloc_bitmap_dup
hwloc_bitmap_t hwloc_bitmap_dup(hwloc_const_bitmap_t bitmap)
Duplicate bitmap bitmap by allocating a new bitmap and copying bitmap contents.
hwloc_obj::misc_first_child
struct hwloc_obj * misc_first_child
First Misc child. Misc objects are listed here (misc_arity and misc_first_child) instead of in the no...
Definition: hwloc.h:535
hwloc_obj_attr_u::hwloc_bridge_attr_s::pci
struct hwloc_pcidev_attr_s pci
Definition: hwloc.h:678
hwloc_get_nbobjs_inside_cpuset_by_depth
static unsigned hwloc_get_nbobjs_inside_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, int depth)
Return the number of objects at depth depth included in CPU set set.
Definition: helper.h:203
hwloc_get_obj_covering_cpuset
static hwloc_obj_t hwloc_get_obj_covering_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set)
Get the lowest object covering at least CPU set set.
Definition: helper.h:321
hwloc_obj::next_cousin
struct hwloc_obj * next_cousin
Next object of same type and depth.
Definition: hwloc.h:472
hwloc_cpuset_t
hwloc_bitmap_t hwloc_cpuset_t
A CPU set is a bitmap whose bits are set according to CPU physical OS indexes.
Definition: hwloc.h:161
hwloc_get_ancestor_obj_by_type
static hwloc_obj_t hwloc_get_ancestor_obj_by_type(hwloc_topology_t topology, hwloc_obj_type_t type, hwloc_obj_t obj)
Returns the ancestor object of obj with type type.
Definition: helper.h:437
hwloc_obj::next_sibling
struct hwloc_obj * next_sibling
Next object below the same parent (inside the same list of children).
Definition: hwloc.h:478
hwloc_obj_attr_u::hwloc_cache_attr_s::type
hwloc_obj_cache_type_t type
Cache type.
Definition: hwloc.h:652
hwloc_bitmap_singlify_per_core
int hwloc_bitmap_singlify_per_core(hwloc_topology_t topology, hwloc_bitmap_t cpuset, unsigned which)
Remove simultaneous multithreading PUs from a CPU set.
hwloc_obj::children
struct hwloc_obj ** children
Normal children, children[0 .. arity -1].
Definition: hwloc.h:486
hwloc_get_shared_cache_covering_obj
static hwloc_obj_t hwloc_get_shared_cache_covering_obj(hwloc_topology_t topology, hwloc_obj_t obj)
Get the first data (or unified) cache shared between an object and somebody else.
Definition: helper.h:695
hwloc_obj::cpuset
hwloc_cpuset_t cpuset
CPUs covered by this object.
Definition: hwloc.h:542
hwloc_get_obj_by_type
static hwloc_obj_t hwloc_get_obj_by_type(hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx)
Returns the topology object at logical index idx with type type.
hwloc_obj::type
hwloc_obj_type_t type
Type of object.
Definition: hwloc.h:428
hwloc_get_first_largest_obj_inside_cpuset
static hwloc_obj_t hwloc_get_first_largest_obj_inside_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set)
Get the first largest object included in the given cpuset set.
Definition: helper.h:43
hwloc_get_nbobjs_inside_cpuset_by_type
static int hwloc_get_nbobjs_inside_cpuset_by_type(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_type_t type)
Return the number of objects of type type included in CPU set set.
Definition: helper.h:235
hwloc_get_obj_inside_cpuset_by_depth
static hwloc_obj_t hwloc_get_obj_inside_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, int depth, unsigned idx)
Return the (logically) idx -th object at depth depth included in CPU set set.
Definition: helper.h:143
hwloc_get_cache_covering_cpuset
static hwloc_obj_t hwloc_get_cache_covering_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set)
Get the first data (or unified) cache covering a cpuset set.
Definition: helper.h:676
hwloc_get_obj_index_inside_cpuset
static int hwloc_get_obj_index_inside_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_t obj)
Return the logical index among the objects included in CPU set set.
Definition: helper.h:266
hwloc_bitmap_zero
void hwloc_bitmap_zero(hwloc_bitmap_t bitmap)
Empty the bitmap bitmap.
hwloc_get_next_obj_inside_cpuset_by_type
static hwloc_obj_t hwloc_get_next_obj_inside_cpuset_by_type(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_type_t type, hwloc_obj_t prev)
Return the next object of type type included in CPU set set.
Definition: helper.h:120
hwloc_bitmap_isincluded
int hwloc_bitmap_isincluded(hwloc_const_bitmap_t sub_bitmap, hwloc_const_bitmap_t super_bitmap)
Test whether bitmap sub_bitmap is part of bitmap super_bitmap.
hwloc_bitmap_t
struct hwloc_bitmap_s * hwloc_bitmap_t
Set of bits represented as an opaque pointer to an internal bitmap.
Definition: bitmap.h:69
hwloc_obj_type_is_cache
int hwloc_obj_type_is_cache(hwloc_obj_type_t type)
Check whether an object type is a CPU Cache (Data, Unified or Instruction).
hwloc_bitmap_isset
int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned id)
Test whether index id is part of bitmap bitmap.
hwloc_topology_get_allowed_cpuset
hwloc_const_cpuset_t hwloc_topology_get_allowed_cpuset(hwloc_topology_t topology)
Get allowed CPU set.
hwloc_bitmap_set
int hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id)
Add index id in bitmap bitmap.
hwloc_obj_type_is_dcache
int hwloc_obj_type_is_dcache(hwloc_obj_type_t type)
Check whether an object type is a CPU Data or Unified Cache.
hwloc_get_obj_inside_cpuset_by_type
static hwloc_obj_t hwloc_get_obj_inside_cpuset_by_type(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_type_t type, unsigned idx)
Return the idx -th object of type type included in CPU set set.
Definition: helper.h:179
hwloc_obj_attr_u::cache
struct hwloc_obj_attr_u::hwloc_cache_attr_s cache
HWLOC_OBJ_PU
@ HWLOC_OBJ_PU
Processing Unit, or (Logical) Processor. An execution unit (may share a core with some other logical ...
Definition: hwloc.h:222
hwloc_obj_type_is_normal
int hwloc_obj_type_is_normal(hwloc_obj_type_t type)
Check whether an object type is Normal.
hwloc_nodeset_t
hwloc_bitmap_t hwloc_nodeset_t
A node set is a bitmap whose bits are set according to NUMA memory node physical OS indexes.
Definition: hwloc.h:178
hwloc_get_next_obj_covering_cpuset_by_depth
static hwloc_obj_t hwloc_get_next_obj_covering_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set, int depth, hwloc_obj_t prev)
Iterate through same-depth objects covering at least CPU set set.
Definition: helper.h:348
hwloc_get_next_obj_covering_cpuset_by_type
static hwloc_obj_t hwloc_get_next_obj_covering_cpuset_by_type(hwloc_topology_t topology, hwloc_const_cpuset_t set, hwloc_obj_type_t type, hwloc_obj_t prev)
Iterate through same-type objects covering at least CPU set set.
Definition: helper.h:376
hwloc_obj_attr_u::bridge
struct hwloc_obj_attr_u::hwloc_bridge_attr_s bridge
hwloc_cpuset_from_nodeset
static int hwloc_cpuset_from_nodeset(hwloc_topology_t topology, hwloc_cpuset_t _cpuset, hwloc_const_nodeset_t nodeset)
Convert a NUMA node set into a CPU set.
Definition: helper.h:1172
hwloc_obj::prev_cousin
struct hwloc_obj * prev_cousin
Previous object of same type and depth.
Definition: hwloc.h:473
HWLOC_OBJ_MISC
@ HWLOC_OBJ_MISC
Miscellaneous objects (filtered out by default). Objects without particular meaning,...
Definition: hwloc.h:311
hwloc_get_next_osdev
static hwloc_obj_t hwloc_get_next_osdev(hwloc_topology_t topology, hwloc_obj_t prev)
Get the next OS device in the system.
Definition: helper.h:1280
HWLOC_OBJ_PCI_DEVICE
@ HWLOC_OBJ_PCI_DEVICE
PCI device (filtered out by default).
Definition: hwloc.h:290
hwloc_obj::io_first_child
struct hwloc_obj * io_first_child
First I/O child. Bridges, PCI and OS devices are listed here (io_arity and io_first_child) instead of...
Definition: hwloc.h:523
hwloc_get_numanode_obj_by_os_index
static hwloc_obj_t hwloc_get_numanode_obj_by_os_index(hwloc_topology_t topology, unsigned os_index)
Returns the object of type HWLOC_OBJ_NUMANODE with os_index.
Definition: helper.h:779
HWLOC_OBJ_OS_DEVICE
@ HWLOC_OBJ_OS_DEVICE
Operating system device (filtered out by default).
Definition: hwloc.h:300
hwloc_obj::arity
unsigned arity
Number of normal children. Memory, Misc and I/O children are not listed here but rather in their dedi...
Definition: hwloc.h:482
hwloc_const_nodeset_t
hwloc_const_bitmap_t hwloc_const_nodeset_t
A non-modifiable hwloc_nodeset_t.
Definition: hwloc.h:181
HWLOC_OBJ_MEMCACHE
@ HWLOC_OBJ_MEMCACHE
Memory-side cache (filtered out by default). A cache in front of a specific NUMA node.
Definition: hwloc.h:326
hwloc_obj_attr_u::hwloc_pcidev_attr_s::dev
unsigned char dev
Definition: hwloc.h:669
HWLOC_DISTRIB_FLAG_REVERSE
@ HWLOC_DISTRIB_FLAG_REVERSE
Distrib in reverse order, starting from the last objects.
Definition: helper.h:924
hwloc_obj_attr_u::hwloc_bridge_attr_s::downstream
union hwloc_obj_attr_u::hwloc_bridge_attr_s::@1 downstream
hwloc_get_obj_below_by_type
static hwloc_obj_t hwloc_get_obj_below_by_type(hwloc_topology_t topology, hwloc_obj_type_t type1, unsigned idx1, hwloc_obj_type_t type2, unsigned idx2)
Find an object below another object, both specified by types and indexes.
Definition: helper.h:821
hwloc_obj_attr_u::pcidev
struct hwloc_obj_attr_u::hwloc_pcidev_attr_s pcidev
HWLOC_TYPE_DEPTH_MULTIPLE
@ HWLOC_TYPE_DEPTH_MULTIPLE
Objects of given type exist at different depth in the topology (only for Groups).
Definition: hwloc.h:860
hwloc_obj::parent
struct hwloc_obj * parent
Parent, NULL if root (Machine object)
Definition: hwloc.h:476
hwloc_bitmap_intersects
int hwloc_bitmap_intersects(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Test whether bitmaps bitmap1 and bitmap2 intersects.
hwloc_obj_cache_type_t
enum hwloc_obj_cache_type_e hwloc_obj_cache_type_t
Cache type.
hwloc_obj_attr_u::hwloc_bridge_attr_s::downstream_type
hwloc_obj_bridge_type_t downstream_type
Definition: hwloc.h:691
hwloc_obj_attr_u::hwloc_cache_attr_s::depth
unsigned depth
Depth of cache (e.g., L1, L2, ...etc.)
Definition: hwloc.h:648
hwloc_get_closest_objs
unsigned hwloc_get_closest_objs(hwloc_topology_t topology, hwloc_obj_t src, hwloc_obj_t *restrict objs, unsigned max)
Do a depth-first traversal of the topology to find and sort.
hwloc_topology_get_complete_nodeset
hwloc_const_nodeset_t hwloc_topology_get_complete_nodeset(hwloc_topology_t topology)
Get complete node set.
hwloc_get_next_obj_by_type
static hwloc_obj_t hwloc_get_next_obj_by_type(hwloc_topology_t topology, hwloc_obj_type_t type, hwloc_obj_t prev)
Returns the next object of type type.
hwloc_obj::depth
int depth
Vertical index in the hierarchy.
Definition: hwloc.h:449
hwloc_get_next_pcidev
static hwloc_obj_t hwloc_get_next_pcidev(hwloc_topology_t topology, hwloc_obj_t prev)
Get the next PCI device in the system.
Definition: helper.h:1228
hwloc_obj_type_t
hwloc_obj_type_t
Type of topology object.
Definition: hwloc.h:197
hwloc_get_obj_below_array_by_type
static hwloc_obj_t hwloc_get_obj_below_array_by_type(hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv)
Find an object below a chain of objects specified by types and indexes.
Definition: helper.h:855
hwloc_distrib_flags_e
hwloc_distrib_flags_e
Flags to be given to hwloc_distrib().
Definition: helper.h:920
hwloc_get_next_obj_by_depth
static hwloc_obj_t hwloc_get_next_obj_by_depth(hwloc_topology_t topology, int depth, hwloc_obj_t prev)
Returns the next object at depth depth.
hwloc_get_next_bridge
static hwloc_obj_t hwloc_get_next_bridge(hwloc_topology_t topology, hwloc_obj_t prev)
Get the next bridge in the system.
Definition: helper.h:1292
hwloc_distrib
static int hwloc_distrib(hwloc_topology_t topology, hwloc_obj_t *roots, unsigned n_roots, hwloc_cpuset_t *set, unsigned n, int until, unsigned long flags)
Distribute n items over the topology under roots.
Definition: helper.h:950
hwloc_topology_t
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:722
hwloc_obj::memory_first_child
struct hwloc_obj * memory_first_child
First Memory child. NUMA nodes and Memory-side caches are listed here (memory_arity and memory_first_...
Definition: hwloc.h:505
hwloc_topology_get_topology_cpuset
hwloc_const_cpuset_t hwloc_topology_get_topology_cpuset(hwloc_topology_t topology)
Get topology CPU set.
HWLOC_OBJ_BRIDGE_PCI
@ HWLOC_OBJ_BRIDGE_PCI
PCI-side of a bridge.
Definition: hwloc.h:362
hwloc_obj::attr
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:445
hwloc_obj_type_is_icache
int hwloc_obj_type_is_icache(hwloc_obj_type_t type)
Check whether an object type is a CPU Instruction Cache,.
hwloc_topology_get_allowed_nodeset
hwloc_const_nodeset_t hwloc_topology_get_allowed_nodeset(hwloc_topology_t topology)
Get allowed node set.
hwloc_obj
Structure of a topology object.
Definition: hwloc.h:426
HWLOC_OBJ_BRIDGE
@ HWLOC_OBJ_BRIDGE
Bridge (filtered out by default). Any bridge (or PCI switch) that connects the host or an I/O bus,...
Definition: hwloc.h:278
hwloc_get_obj_with_same_locality
hwloc_obj_t hwloc_get_obj_with_same_locality(hwloc_topology_t topology, hwloc_obj_t src, hwloc_obj_type_t type, const char *subtype, const char *nameprefix, unsigned long flags)
Return an object of a different type with same locality.
hwloc_get_pcidev_by_busid
static hwloc_obj_t hwloc_get_pcidev_by_busid(hwloc_topology_t topology, unsigned domain, unsigned bus, unsigned dev, unsigned func)
Find the PCI device object matching the PCI bus id given domain, bus device and function PCI bus id.
Definition: helper.h:1239
hwloc_cpuset_to_nodeset
static int hwloc_cpuset_to_nodeset(hwloc_topology_t topology, hwloc_const_cpuset_t _cpuset, hwloc_nodeset_t nodeset)
Convert a CPU set into a NUMA node set.
Definition: helper.h:1145
hwloc_get_type_depth
int hwloc_get_type_depth(hwloc_topology_t topology, hwloc_obj_type_t type)
Returns the depth of objects of type type.
hwloc_bitmap_weight
int hwloc_bitmap_weight(hwloc_const_bitmap_t bitmap)
Compute the "weight" of bitmap bitmap (i.e., number of indexes that are in the bitmap).
hwloc_obj_attr_u::hwloc_pcidev_attr_s::func
unsigned char func
Definition: hwloc.h:669
hwloc_obj::os_index
unsigned os_index
OS-provided physical index number. It is not guaranteed unique across the entire machine,...
Definition: hwloc.h:431
HWLOC_TYPE_DEPTH_UNKNOWN
@ HWLOC_TYPE_DEPTH_UNKNOWN
No object of given type exists in the topology.
Definition: hwloc.h:859
hwloc_obj::first_child
struct hwloc_obj * first_child
First normal child.
Definition: hwloc.h:487