Hardware Locality (hwloc)  v2.8-20240516.1852.gitc5dfa82e
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 
952 static __hwloc_inline int
954  hwloc_obj_t *roots, unsigned n_roots,
955  hwloc_cpuset_t *set,
956  unsigned n,
957  int until, unsigned long flags)
958 {
959  unsigned i;
960  unsigned tot_weight;
961  unsigned given, givenweight;
962  hwloc_cpuset_t *cpusetp = set;
963 
964  if (flags & ~HWLOC_DISTRIB_FLAG_REVERSE) {
965  errno = EINVAL;
966  return -1;
967  }
968 
969  tot_weight = 0;
970  for (i = 0; i < n_roots; i++)
971  tot_weight += (unsigned) hwloc_bitmap_weight(roots[i]->cpuset);
972 
973  for (i = 0, given = 0, givenweight = 0; i < n_roots; i++) {
974  unsigned chunk, weight;
975  hwloc_obj_t root = roots[flags & HWLOC_DISTRIB_FLAG_REVERSE ? n_roots-1-i : i];
976  hwloc_cpuset_t cpuset = root->cpuset;
977  while (!hwloc_obj_type_is_normal(root->type))
978  /* If memory/io/misc, walk up to normal parent */
979  root = root->parent;
980  weight = (unsigned) hwloc_bitmap_weight(cpuset);
981  if (!weight)
982  continue;
983  /* Give to root a chunk proportional to its weight.
984  * If previous chunks got rounded-up, we may get a bit less. */
985  chunk = (( (givenweight+weight) * n + tot_weight-1) / tot_weight)
986  - (( givenweight * n + tot_weight-1) / tot_weight);
987  if (!root->arity || chunk <= 1 || root->depth >= until) {
988  /* We can't split any more, put everything there. */
989  if (chunk) {
990  /* Fill cpusets with ours */
991  unsigned j;
992  for (j=0; j < chunk; j++)
993  cpusetp[j] = hwloc_bitmap_dup(cpuset);
994  } else {
995  /* We got no chunk, just merge our cpuset to a previous one
996  * (the first chunk cannot be empty)
997  * so that this root doesn't get ignored.
998  */
999  assert(given);
1000  hwloc_bitmap_or(cpusetp[-1], cpusetp[-1], cpuset);
1001  }
1002  } else {
1003  /* Still more to distribute, recurse into children */
1004  hwloc_distrib(topology, root->children, root->arity, cpusetp, chunk, until, flags);
1005  }
1006  cpusetp += chunk;
1007  given += chunk;
1008  givenweight += weight;
1009  }
1010 
1011  return 0;
1012 }
1013 
1033 HWLOC_DECLSPEC hwloc_const_cpuset_t
1034 hwloc_topology_get_complete_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
1035 
1049 HWLOC_DECLSPEC hwloc_const_cpuset_t
1050 hwloc_topology_get_topology_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
1051 
1070 HWLOC_DECLSPEC hwloc_const_cpuset_t
1071 hwloc_topology_get_allowed_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
1072 
1084 HWLOC_DECLSPEC hwloc_const_nodeset_t
1085 hwloc_topology_get_complete_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
1086 
1100 HWLOC_DECLSPEC hwloc_const_nodeset_t
1101 hwloc_topology_get_topology_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
1102 
1121 HWLOC_DECLSPEC hwloc_const_nodeset_t
1122 hwloc_topology_get_allowed_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
1123 
1147 static __hwloc_inline int
1149 {
1151  hwloc_obj_t obj = NULL;
1152  assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
1154  while ((obj = hwloc_get_next_obj_covering_cpuset_by_depth(topology, _cpuset, depth, obj)) != NULL)
1155  if (hwloc_bitmap_set(nodeset, obj->os_index) < 0)
1156  return -1;
1157  return 0;
1158 }
1159 
1174 static __hwloc_inline int
1176 {
1178  hwloc_obj_t obj = NULL;
1179  assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
1180  hwloc_bitmap_zero(_cpuset);
1181  while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL) {
1182  if (hwloc_bitmap_isset(nodeset, obj->os_index))
1183  /* no need to check obj->cpuset because objects in levels always have a cpuset */
1184  if (hwloc_bitmap_or(_cpuset, _cpuset, obj->cpuset) < 0)
1185  return -1;
1186  }
1187  return 0;
1188 }
1189 
1213 static __hwloc_inline hwloc_obj_t
1214 hwloc_get_non_io_ancestor_obj(hwloc_topology_t topology __hwloc_attribute_unused,
1215  hwloc_obj_t ioobj)
1216 {
1217  hwloc_obj_t obj = ioobj;
1218  while (obj && !obj->cpuset) {
1219  obj = obj->parent;
1220  }
1221  return obj;
1222 }
1223 
1230 static __hwloc_inline hwloc_obj_t
1232 {
1233  return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_PCI_DEVICE, prev);
1234 }
1235 
1241 static __hwloc_inline hwloc_obj_t
1243  unsigned domain, unsigned bus, unsigned dev, unsigned func)
1244 {
1245  hwloc_obj_t obj = NULL;
1246  while ((obj = hwloc_get_next_pcidev(topology, obj)) != NULL) {
1247  if (obj->attr->pcidev.domain == domain
1248  && obj->attr->pcidev.bus == bus
1249  && obj->attr->pcidev.dev == dev
1250  && obj->attr->pcidev.func == func)
1251  return obj;
1252  }
1253  return NULL;
1254 }
1255 
1261 static __hwloc_inline hwloc_obj_t
1263 {
1264  unsigned domain = 0; /* default */
1265  unsigned bus, dev, func;
1266 
1267  if (sscanf(busid, "%x:%x.%x", &bus, &dev, &func) != 3
1268  && sscanf(busid, "%x:%x:%x.%x", &domain, &bus, &dev, &func) != 4) {
1269  errno = EINVAL;
1270  return NULL;
1271  }
1272 
1273  return hwloc_get_pcidev_by_busid(topology, domain, bus, dev, func);
1274 }
1275 
1282 static __hwloc_inline hwloc_obj_t
1284 {
1285  return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_OS_DEVICE, prev);
1286 }
1287 
1294 static __hwloc_inline hwloc_obj_t
1296 {
1297  return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_BRIDGE, prev);
1298 }
1299 
1300 /* \brief Checks whether a given bridge covers a given PCI bus.
1301  *
1302  * \return 1 if it covers, 0 if not.
1303  */
1304 static __hwloc_inline int
1306  unsigned domain, unsigned bus)
1307 {
1308  return bridge->type == HWLOC_OBJ_BRIDGE
1310  && bridge->attr->bridge.downstream.pci.domain == domain
1311  && bridge->attr->bridge.downstream.pci.secondary_bus <= bus
1312  && bridge->attr->bridge.downstream.pci.subordinate_bus >= bus;
1313 }
1314 
1319 #ifdef __cplusplus
1320 } /* extern "C" */
1321 #endif
1322 
1323 
1324 #endif /* HWLOC_HELPER_H */
hwloc_const_cpuset_t hwloc_topology_get_complete_cpuset(hwloc_topology_t topology)
Get complete CPU set.
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.
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:439
hwloc_const_nodeset_t hwloc_topology_get_allowed_nodeset(hwloc_topology_t topology)
Get allowed node set.
hwloc_nodeset_t nodeset
NUMA nodes covered by this object or containing this object.
Definition: hwloc.h:564
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.
struct hwloc_obj * first_child
First normal child.
Definition: hwloc.h:481
struct hwloc_obj ** children
Normal children, children[0 .. arity -1].
Definition: hwloc.h:480
int hwloc_obj_type_is_io(hwloc_obj_type_t type)
Check whether an object type is I/O.
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:1214
hwloc_bitmap_t hwloc_bitmap_dup(hwloc_const_bitmap_t bitmap)
Duplicate bitmap bitmap by allocating a new bitmap and copying bitmap contents.
PCI-side of a bridge.
Definition: hwloc.h:356
static int hwloc_bridge_covers_pcibus(hwloc_obj_t bridge, unsigned domain, unsigned bus)
Definition: helper.h:1305
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:1262
hwloc_cpuset_t cpuset
CPUs covered by this object.
Definition: hwloc.h:536
int hwloc_obj_type_is_memory(hwloc_obj_type_t type)
Check whether an object type is Memory.
hwloc_const_nodeset_t hwloc_topology_get_complete_nodeset(hwloc_topology_t topology)
Get complete node set.
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_const_bitmap_t hwloc_const_cpuset_t
A non-modifiable hwloc_cpuset_t.
Definition: hwloc.h:163
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:517
int hwloc_bitmap_isequal(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Test whether bitmap bitmap1 is equal to bitmap bitmap2.
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
struct hwloc_obj * parent
Parent, NULL if root (Machine object)
Definition: hwloc.h:470
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
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
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:716
union hwloc_obj_attr_u::hwloc_bridge_attr_s::@1 downstream
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_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
struct hwloc_obj_attr_u::hwloc_bridge_attr_s bridge
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.
int hwloc_obj_type_is_dcache(hwloc_obj_type_t type)
Check whether an object type is a CPU Data or Unified Cache.
int depth
Vertical index in the hierarchy.
Definition: hwloc.h:443
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.
unsigned os_index
OS-provided physical index number. It is not guaranteed unique across the entire machine, except for PUs and NUMA nodes. Set to HWLOC_UNKNOWN_INDEX if unknown or irrelevant for this object.
Definition: hwloc.h:425
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
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_const_nodeset_t hwloc_topology_get_topology_nodeset(hwloc_topology_t topology)
Get topology node set.
Distrib in reverse order, starting from the last objects.
Definition: helper.h:924
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.
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
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.
struct hwloc_obj * next_cousin
Next object of same type and depth.
Definition: hwloc.h:466
Operating system device (filtered out by default).
Definition: hwloc.h:300
Processing Unit, or (Logical) Processor. An execution unit (may share a core with some other logical ...
Definition: hwloc.h:222
hwloc_distrib_flags_e
Flags to be given to hwloc_distrib().
Definition: helper.h:920
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
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:1175
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
int hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id)
Add index id in bitmap bitmap.
struct hwloc_obj_attr_u::hwloc_cache_attr_s cache
hwloc_const_bitmap_t hwloc_const_nodeset_t
A non-modifiable hwloc_nodeset_t.
Definition: hwloc.h:181
struct hwloc_obj * prev_cousin
Previous object of same type and depth.
Definition: hwloc.h:467
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:499
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.
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
NUMA node. An object that contains memory that is directly and byte-accessible to the host processors...
Definition: hwloc.h:257
PCI device (filtered out by default).
Definition: hwloc.h:290
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.
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
unsigned arity
Number of normal children. Memory, Misc and I/O children are not listed here but rather in their dedi...
Definition: hwloc.h:476
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
Memory-side cache (filtered out by default). A cache in front of a specific NUMA node.
Definition: hwloc.h:326
int hwloc_get_type_depth(hwloc_topology_t topology, hwloc_obj_type_t type)
Returns the depth of objects of type type.
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_const_cpuset_t hwloc_topology_get_topology_cpuset(hwloc_topology_t topology)
Get topology CPU set.
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
unsigned depth
Depth of cache (e.g., L1, L2, ...etc.)
Definition: hwloc.h:642
void hwloc_bitmap_zero(hwloc_bitmap_t bitmap)
Empty the bitmap bitmap.
struct hwloc_pcidev_attr_s pci
Definition: hwloc.h:672
int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned id)
Test whether index id is part of bitmap bitmap.
No object of given type exists in the topology.
Definition: hwloc.h:853
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
unsigned char bus
Definition: hwloc.h:663
hwloc_obj_cache_type_t type
Cache type.
Definition: hwloc.h:646
struct hwloc_bitmap_s * hwloc_bitmap_t
Set of bits represented as an opaque pointer to an internal bitmap.
Definition: bitmap.h:69
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:953
enum hwloc_obj_cache_type_e hwloc_obj_cache_type_t
Cache type.
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_obj_type_t
Type of topology object.
Definition: hwloc.h:197
int hwloc_obj_type_is_normal(hwloc_obj_type_t type)
Check whether an object type is Normal.
int hwloc_bitmap_intersects(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2)
Test whether bitmaps bitmap1 and bitmap2 intersects.
Miscellaneous objects (filtered out by default). Objects without particular meaning, that can e.g. be added by the application for its own use, or by hwloc for miscellaneous objects such as MemoryModule (DIMMs).
Definition: hwloc.h:311
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_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
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:1231
hwloc_const_cpuset_t hwloc_topology_get_allowed_cpuset(hwloc_topology_t topology)
Get allowed CPU set.
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:1295
Bridge (filtered out by default). Any bridge (or PCI switch) that connects the host or an I/O bus...
Definition: hwloc.h:278
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
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:1242
Unified cache.
Definition: hwloc.h:348
int hwloc_bitmap_singlify_per_core(hwloc_topology_t topology, hwloc_bitmap_t cpuset, unsigned which)
Remove simultaneous multithreading PUs from a CPU set.
struct hwloc_obj * next_sibling
Next object below the same parent (inside the same list of children).
Definition: hwloc.h:472
hwloc_obj_bridge_type_t downstream_type
Definition: hwloc.h:685
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:1283
unsigned char func
Definition: hwloc.h:663
int hwloc_obj_type_is_cache(hwloc_obj_type_t type)
Check whether an object type is a CPU Cache (Data, Unified or Instruction).
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).
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
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
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
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
char * subtype
Subtype string to better describe the type field.
Definition: hwloc.h:423
hwloc_obj_type_t type
Type of object.
Definition: hwloc.h:422
unsigned short domain
Definition: hwloc.h:659
struct hwloc_obj_attr_u::hwloc_pcidev_attr_s pcidev
int hwloc_bitmap_iszero(hwloc_const_bitmap_t bitmap)
Test whether bitmap bitmap is empty.
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
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
Objects of given type exist at different depth in the topology (only for Groups). ...
Definition: hwloc.h:854
int hwloc_obj_type_is_icache(hwloc_obj_type_t type)
Check whether an object type is a CPU Instruction Cache,.
unsigned char dev
Definition: hwloc.h:663
static hwloc_obj_t hwloc_get_root_obj(hwloc_topology_t topology)
Returns the top-object of the topology-tree.
Structure of a topology object.
Definition: hwloc.h:420
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:529
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:1148