This source file includes following definitions.
- hwloc_get_first_largest_obj_inside_cpuset
- hwloc_get_next_obj_inside_cpuset_by_depth
- hwloc_get_next_obj_inside_cpuset_by_type
- hwloc_get_obj_inside_cpuset_by_depth
- hwloc_get_obj_inside_cpuset_by_type
- hwloc_get_nbobjs_inside_cpuset_by_depth
- hwloc_get_nbobjs_inside_cpuset_by_type
- hwloc_get_obj_index_inside_cpuset
- hwloc_get_child_covering_cpuset
- hwloc_get_obj_covering_cpuset
- hwloc_get_next_obj_covering_cpuset_by_depth
- hwloc_get_next_obj_covering_cpuset_by_type
- hwloc_get_ancestor_obj_by_depth
- hwloc_get_ancestor_obj_by_type
- hwloc_get_common_ancestor_obj
- hwloc_obj_is_in_subtree
- hwloc_get_next_child
- hwloc_get_cache_type_depth
- hwloc_get_cache_covering_cpuset
- hwloc_get_shared_cache_covering_obj
- hwloc_get_pu_obj_by_os_index
- hwloc_get_numanode_obj_by_os_index
- hwloc_get_obj_below_by_type
- hwloc_get_obj_below_array_by_type
- hwloc_distrib
- hwloc_topology_get_complete_cpuset
- hwloc_cpuset_from_nodeset
- hwloc_get_non_io_ancestor_obj
- hwloc_get_next_pcidev
- hwloc_get_pcidev_by_busid
- hwloc_get_pcidev_by_busidstring
- hwloc_get_next_osdev
- hwloc_get_next_bridge
- hwloc_bridge_covers_pcibus
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  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 
  29 
  30 
  31 
  32 
  33 
  34 
  35 
  36 
  37 
  38 
  39 
  40 
  41 static __hwloc_inline hwloc_obj_t
  42 hwloc_get_first_largest_obj_inside_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set)
  43 {
  44   hwloc_obj_t obj = hwloc_get_root_obj(topology);
  45   if (!hwloc_bitmap_intersects(obj->cpuset, set))
  46     return NULL;
  47   while (!hwloc_bitmap_isincluded(obj->cpuset, set)) {
  48     
  49     hwloc_obj_t child = obj->first_child;
  50     while (child) {
  51       if (hwloc_bitmap_intersects(child->cpuset, set))
  52         break;
  53       child = child->next_sibling;
  54     }
  55     if (!child)
  56       
  57       return obj;
  58     
  59     obj = child;
  60   }
  61   
  62   return obj;
  63 }
  64 
  65 
  66 
  67 
  68 
  69 HWLOC_DECLSPEC int hwloc_get_largest_objs_inside_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set,
  70                                                  hwloc_obj_t * __hwloc_restrict objs, int max);
  71 
  72 
  73 
  74 
  75 
  76 
  77 
  78 
  79 
  80 
  81 
  82 
  83 
  84 static __hwloc_inline hwloc_obj_t
  85 hwloc_get_next_obj_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
  86                                            int depth, hwloc_obj_t prev)
  87 {
  88   hwloc_obj_t next = hwloc_get_next_obj_by_depth(topology, depth, prev);
  89   if (!next)
  90     return NULL;
  91   while (next && (hwloc_bitmap_iszero(next->cpuset) || !hwloc_bitmap_isincluded(next->cpuset, set)))
  92     next = next->next_cousin;
  93   return next;
  94 }
  95 
  96 
  97 
  98 
  99 
 100 
 101 
 102 
 103 
 104 
 105 
 106 
 107 
 108 static __hwloc_inline hwloc_obj_t
 109 hwloc_get_next_obj_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
 110                                           hwloc_obj_type_t type, hwloc_obj_t prev)
 111 {
 112   int depth = hwloc_get_type_depth(topology, type);
 113   if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
 114     return NULL;
 115   return hwloc_get_next_obj_inside_cpuset_by_depth(topology, set, depth, prev);
 116 }
 117 
 118 
 119 
 120 
 121 
 122 
 123 
 124 
 125 
 126 static __hwloc_inline hwloc_obj_t
 127 hwloc_get_obj_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
 128                                       int depth, unsigned idx) __hwloc_attribute_pure;
 129 static __hwloc_inline hwloc_obj_t
 130 hwloc_get_obj_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
 131                                       int depth, unsigned idx)
 132 {
 133   hwloc_obj_t obj = hwloc_get_obj_by_depth (topology, depth, 0);
 134   unsigned count = 0;
 135   if (!obj)
 136     return NULL;
 137   while (obj) {
 138     if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set)) {
 139       if (count == idx)
 140         return obj;
 141       count++;
 142     }
 143     obj = obj->next_cousin;
 144   }
 145   return NULL;
 146 }
 147 
 148 
 149 
 150 
 151 
 152 
 153 
 154 
 155 
 156 
 157 
 158 
 159 
 160 static __hwloc_inline hwloc_obj_t
 161 hwloc_get_obj_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
 162                                      hwloc_obj_type_t type, unsigned idx) __hwloc_attribute_pure;
 163 static __hwloc_inline hwloc_obj_t
 164 hwloc_get_obj_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
 165                                      hwloc_obj_type_t type, unsigned idx)
 166 {
 167   int depth = hwloc_get_type_depth(topology, type);
 168   if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
 169     return NULL;
 170   return hwloc_get_obj_inside_cpuset_by_depth(topology, set, depth, idx);
 171 }
 172 
 173 
 174 
 175 
 176 
 177 
 178 
 179 
 180 
 181 static __hwloc_inline unsigned
 182 hwloc_get_nbobjs_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
 183                                          int depth) __hwloc_attribute_pure;
 184 static __hwloc_inline unsigned
 185 hwloc_get_nbobjs_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
 186                                          int depth)
 187 {
 188   hwloc_obj_t obj = hwloc_get_obj_by_depth (topology, depth, 0);
 189   unsigned count = 0;
 190   if (!obj)
 191     return 0;
 192   while (obj) {
 193     if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set))
 194       count++;
 195     obj = obj->next_cousin;
 196   }
 197   return count;
 198 }
 199 
 200 
 201 
 202 
 203 
 204 
 205 
 206 
 207 
 208 
 209 
 210 
 211 
 212 static __hwloc_inline int
 213 hwloc_get_nbobjs_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
 214                                         hwloc_obj_type_t type) __hwloc_attribute_pure;
 215 static __hwloc_inline int
 216 hwloc_get_nbobjs_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
 217                                         hwloc_obj_type_t type)
 218 {
 219   int depth = hwloc_get_type_depth(topology, type);
 220   if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
 221     return 0;
 222   if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
 223     return -1; 
 224   return (int) hwloc_get_nbobjs_inside_cpuset_by_depth(topology, set, depth);
 225 }
 226 
 227 
 228 
 229 
 230 
 231 
 232 
 233 
 234 
 235 
 236 
 237 
 238 
 239 
 240 static __hwloc_inline int
 241 hwloc_get_obj_index_inside_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
 242                                    hwloc_obj_t obj) __hwloc_attribute_pure;
 243 static __hwloc_inline int
 244 hwloc_get_obj_index_inside_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
 245                                    hwloc_obj_t obj)
 246 {
 247   int idx = 0;
 248   if (!hwloc_bitmap_isincluded(obj->cpuset, set))
 249     return -1;
 250   
 251   while ((obj = obj->prev_cousin) != NULL)
 252     if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set))
 253       idx++;
 254   return idx;
 255 }
 256 
 257 
 258 
 259 
 260 
 261 
 262 
 263 
 264 
 265 
 266 
 267 
 268 
 269 
 270 
 271 static __hwloc_inline hwloc_obj_t
 272 hwloc_get_child_covering_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
 273                                 hwloc_obj_t parent) __hwloc_attribute_pure;
 274 static __hwloc_inline hwloc_obj_t
 275 hwloc_get_child_covering_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
 276                                 hwloc_obj_t parent)
 277 {
 278   hwloc_obj_t child;
 279   if (hwloc_bitmap_iszero(set))
 280     return NULL;
 281   child = parent->first_child;
 282   while (child) {
 283     if (child->cpuset && hwloc_bitmap_isincluded(set, child->cpuset))
 284       return child;
 285     child = child->next_sibling;
 286   }
 287   return NULL;
 288 }
 289 
 290 
 291 
 292 
 293 
 294 static __hwloc_inline hwloc_obj_t
 295 hwloc_get_obj_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set) __hwloc_attribute_pure;
 296 static __hwloc_inline hwloc_obj_t
 297 hwloc_get_obj_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set)
 298 {
 299   struct hwloc_obj *current = hwloc_get_root_obj(topology);
 300   if (hwloc_bitmap_iszero(set) || !hwloc_bitmap_isincluded(set, current->cpuset))
 301     return NULL;
 302   while (1) {
 303     hwloc_obj_t child = hwloc_get_child_covering_cpuset(topology, set, current);
 304     if (!child)
 305       return current;
 306     current = child;
 307   }
 308 }
 309 
 310 
 311 
 312 
 313 
 314 
 315 
 316 
 317 
 318 
 319 
 320 static __hwloc_inline hwloc_obj_t
 321 hwloc_get_next_obj_covering_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set,
 322                                             int depth, hwloc_obj_t prev)
 323 {
 324   hwloc_obj_t next = hwloc_get_next_obj_by_depth(topology, depth, prev);
 325   if (!next)
 326     return NULL;
 327   while (next && !hwloc_bitmap_intersects(set, next->cpuset))
 328     next = next->next_cousin;
 329   return next;
 330 }
 331 
 332 
 333 
 334 
 335 
 336 
 337 
 338 
 339 
 340 
 341 
 342 
 343 
 344 
 345 
 346 
 347 static __hwloc_inline hwloc_obj_t
 348 hwloc_get_next_obj_covering_cpuset_by_type(hwloc_topology_t topology, hwloc_const_cpuset_t set,
 349                                            hwloc_obj_type_t type, hwloc_obj_t prev)
 350 {
 351   int depth = hwloc_get_type_depth(topology, type);
 352   if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
 353     return NULL;
 354   return hwloc_get_next_obj_covering_cpuset_by_depth(topology, set, depth, prev);
 355 }
 356 
 357 
 358 
 359 
 360 
 361 
 362 
 363 
 364 
 365 
 366 
 367 
 368 
 369 
 370 
 371 static __hwloc_inline hwloc_obj_t
 372 hwloc_get_ancestor_obj_by_depth (hwloc_topology_t topology __hwloc_attribute_unused, int depth, hwloc_obj_t obj) __hwloc_attribute_pure;
 373 static __hwloc_inline hwloc_obj_t
 374 hwloc_get_ancestor_obj_by_depth (hwloc_topology_t topology __hwloc_attribute_unused, int depth, hwloc_obj_t obj)
 375 {
 376   hwloc_obj_t ancestor = obj;
 377   if (obj->depth < depth)
 378     return NULL;
 379   while (ancestor && ancestor->depth > depth)
 380     ancestor = ancestor->parent;
 381   return ancestor;
 382 }
 383 
 384 
 385 static __hwloc_inline hwloc_obj_t
 386 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;
 387 static __hwloc_inline hwloc_obj_t
 388 hwloc_get_ancestor_obj_by_type (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_type_t type, hwloc_obj_t obj)
 389 {
 390   hwloc_obj_t ancestor = obj->parent;
 391   while (ancestor && ancestor->type != type)
 392     ancestor = ancestor->parent;
 393   return ancestor;
 394 }
 395 
 396 
 397 static __hwloc_inline hwloc_obj_t
 398 hwloc_get_common_ancestor_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj1, hwloc_obj_t obj2) __hwloc_attribute_pure;
 399 static __hwloc_inline hwloc_obj_t
 400 hwloc_get_common_ancestor_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj1, hwloc_obj_t obj2)
 401 {
 402   
 403 
 404 
 405 
 406 
 407   while (obj1 != obj2) {
 408     while (obj1->depth > obj2->depth)
 409       obj1 = obj1->parent;
 410     while (obj2->depth > obj1->depth)
 411       obj2 = obj2->parent;
 412     if (obj1 != obj2 && obj1->depth == obj2->depth) {
 413       obj1 = obj1->parent;
 414       obj2 = obj2->parent;
 415     }
 416   }
 417   return obj1;
 418 }
 419 
 420 
 421 
 422 
 423 
 424 
 425 static __hwloc_inline int
 426 hwloc_obj_is_in_subtree (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj, hwloc_obj_t subtree_root) __hwloc_attribute_pure;
 427 static __hwloc_inline int
 428 hwloc_obj_is_in_subtree (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj, hwloc_obj_t subtree_root)
 429 {
 430   return obj->cpuset && subtree_root->cpuset && hwloc_bitmap_isincluded(obj->cpuset, subtree_root->cpuset);
 431 }
 432 
 433 
 434 
 435 
 436 
 437 
 438 
 439 
 440 
 441 
 442 
 443 static __hwloc_inline hwloc_obj_t
 444 hwloc_get_next_child (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t parent, hwloc_obj_t prev)
 445 {
 446   hwloc_obj_t obj;
 447   int state = 0;
 448   if (prev) {
 449     if (prev->type == HWLOC_OBJ_MISC)
 450       state = 3;
 451     else if (prev->type == HWLOC_OBJ_BRIDGE || prev->type == HWLOC_OBJ_PCI_DEVICE || prev->type == HWLOC_OBJ_OS_DEVICE)
 452       state = 2;
 453     else if (prev->type == HWLOC_OBJ_NUMANODE)
 454       state = 1;
 455     obj = prev->next_sibling;
 456   } else {
 457     obj = parent->first_child;
 458   }
 459   if (!obj && state == 0) {
 460     obj = parent->memory_first_child;
 461     state = 1;
 462   }
 463   if (!obj && state == 1) {
 464     obj = parent->io_first_child;
 465     state = 2;
 466   }
 467   if (!obj && state == 2) {
 468     obj = parent->misc_first_child;
 469     state = 3;
 470   }
 471   return obj;
 472 }
 473 
 474 
 475 
 476 
 477 
 478 
 479 
 480 
 481 
 482 
 483 
 484 
 485 
 486 
 487 
 488 
 489 
 490 
 491 
 492 
 493 
 494 
 495 
 496 
 497 
 498 
 499 
 500 HWLOC_DECLSPEC int
 501 hwloc_obj_type_is_normal(hwloc_obj_type_t type);
 502 
 503 
 504 
 505 
 506 
 507 
 508 
 509 
 510 
 511 HWLOC_DECLSPEC int
 512 hwloc_obj_type_is_io(hwloc_obj_type_t type);
 513 
 514 
 515 
 516 
 517 
 518 
 519 
 520 
 521 
 522 HWLOC_DECLSPEC int
 523 hwloc_obj_type_is_memory(hwloc_obj_type_t type);
 524 
 525 
 526 
 527 
 528 
 529 HWLOC_DECLSPEC int
 530 hwloc_obj_type_is_cache(hwloc_obj_type_t type);
 531 
 532 
 533 
 534 
 535 
 536 HWLOC_DECLSPEC int
 537 hwloc_obj_type_is_dcache(hwloc_obj_type_t type);
 538 
 539 
 540 
 541 
 542 
 543 HWLOC_DECLSPEC int
 544 hwloc_obj_type_is_icache(hwloc_obj_type_t type);
 545 
 546 
 547 
 548 
 549 
 550 
 551 
 552 
 553 
 554 
 555 
 556 
 557 
 558 
 559 
 560 
 561 
 562 
 563 
 564 
 565 
 566 
 567 
 568 
 569 
 570 
 571 
 572 
 573 
 574 
 575 static __hwloc_inline int
 576 hwloc_get_cache_type_depth (hwloc_topology_t topology,
 577                             unsigned cachelevel, hwloc_obj_cache_type_t cachetype)
 578 {
 579   int depth;
 580   int found = HWLOC_TYPE_DEPTH_UNKNOWN;
 581   for (depth=0; ; depth++) {
 582     hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, depth, 0);
 583     if (!obj)
 584       break;
 585     if (!hwloc_obj_type_is_dcache(obj->type) || obj->attr->cache.depth != cachelevel)
 586       
 587       continue;
 588     if (cachetype == (hwloc_obj_cache_type_t) -1) {
 589       if (found != HWLOC_TYPE_DEPTH_UNKNOWN) {
 590         
 591         return HWLOC_TYPE_DEPTH_MULTIPLE;
 592       }
 593       
 594       found = depth;
 595       continue;
 596     }
 597     if (obj->attr->cache.type == cachetype || obj->attr->cache.type == HWLOC_OBJ_CACHE_UNIFIED)
 598       
 599       return depth;
 600   }
 601   
 602   return found;
 603 }
 604 
 605 
 606 
 607 
 608 
 609 static __hwloc_inline hwloc_obj_t
 610 hwloc_get_cache_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set) __hwloc_attribute_pure;
 611 static __hwloc_inline hwloc_obj_t
 612 hwloc_get_cache_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set)
 613 {
 614   hwloc_obj_t current = hwloc_get_obj_covering_cpuset(topology, set);
 615   while (current) {
 616     if (hwloc_obj_type_is_dcache(current->type))
 617       return current;
 618     current = current->parent;
 619   }
 620   return NULL;
 621 }
 622 
 623 
 624 
 625 
 626 
 627 static __hwloc_inline hwloc_obj_t
 628 hwloc_get_shared_cache_covering_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj) __hwloc_attribute_pure;
 629 static __hwloc_inline hwloc_obj_t
 630 hwloc_get_shared_cache_covering_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj)
 631 {
 632   hwloc_obj_t current = obj->parent;
 633   if (!obj->cpuset)
 634     return NULL;
 635   while (current) {
 636     if (!hwloc_bitmap_isequal(current->cpuset, obj->cpuset)
 637         && hwloc_obj_type_is_dcache(current->type))
 638       return current;
 639     current = current->parent;
 640   }
 641   return NULL;
 642 }
 643 
 644 
 645 
 646 
 647 
 648 
 649 
 650 
 651 
 652 
 653 
 654 
 655 
 656 
 657 
 658 
 659 
 660 
 661 
 662 
 663 
 664 
 665 
 666 static __hwloc_inline hwloc_obj_t
 667 hwloc_get_pu_obj_by_os_index(hwloc_topology_t topology, unsigned os_index) __hwloc_attribute_pure;
 668 static __hwloc_inline hwloc_obj_t
 669 hwloc_get_pu_obj_by_os_index(hwloc_topology_t topology, unsigned os_index)
 670 {
 671   hwloc_obj_t obj = NULL;
 672   while ((obj = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_PU, obj)) != NULL)
 673     if (obj->os_index == os_index)
 674       return obj;
 675   return NULL;
 676 }
 677 
 678 
 679 
 680 
 681 
 682 
 683 
 684 
 685 
 686 
 687 static __hwloc_inline hwloc_obj_t
 688 hwloc_get_numanode_obj_by_os_index(hwloc_topology_t topology, unsigned os_index) __hwloc_attribute_pure;
 689 static __hwloc_inline hwloc_obj_t
 690 hwloc_get_numanode_obj_by_os_index(hwloc_topology_t topology, unsigned os_index)
 691 {
 692   hwloc_obj_t obj = NULL;
 693   while ((obj = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_NUMANODE, obj)) != NULL)
 694     if (obj->os_index == os_index)
 695       return obj;
 696   return NULL;
 697 }
 698 
 699 
 700 
 701 
 702 
 703 
 704 
 705 
 706 
 707 
 708 
 709 
 710 
 711 HWLOC_DECLSPEC unsigned hwloc_get_closest_objs (hwloc_topology_t topology, hwloc_obj_t src, hwloc_obj_t * __hwloc_restrict objs, unsigned max);
 712 
 713 
 714 
 715 
 716 
 717 
 718 
 719 
 720 
 721 
 722 
 723 
 724 
 725 static __hwloc_inline hwloc_obj_t
 726 hwloc_get_obj_below_by_type (hwloc_topology_t topology,
 727                              hwloc_obj_type_t type1, unsigned idx1,
 728                              hwloc_obj_type_t type2, unsigned idx2) __hwloc_attribute_pure;
 729 static __hwloc_inline hwloc_obj_t
 730 hwloc_get_obj_below_by_type (hwloc_topology_t topology,
 731                              hwloc_obj_type_t type1, unsigned idx1,
 732                              hwloc_obj_type_t type2, unsigned idx2)
 733 {
 734   hwloc_obj_t obj;
 735   obj = hwloc_get_obj_by_type (topology, type1, idx1);
 736   if (!obj)
 737     return NULL;
 738   return hwloc_get_obj_inside_cpuset_by_type(topology, obj->cpuset, type2, idx2);
 739 }
 740 
 741 
 742 
 743 
 744 
 745 
 746 
 747 
 748 
 749 
 750 
 751 
 752 
 753 
 754 
 755 
 756 
 757 
 758 
 759 static __hwloc_inline hwloc_obj_t
 760 hwloc_get_obj_below_array_by_type (hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv) __hwloc_attribute_pure;
 761 static __hwloc_inline hwloc_obj_t
 762 hwloc_get_obj_below_array_by_type (hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv)
 763 {
 764   hwloc_obj_t obj = hwloc_get_root_obj(topology);
 765   int i;
 766   for(i=0; i<nr; i++) {
 767     if (!obj)
 768       return NULL;
 769     obj = hwloc_get_obj_inside_cpuset_by_type(topology, obj->cpuset, typev[i], idxv[i]);
 770   }
 771   return obj;
 772 }
 773 
 774 
 775 
 776 
 777 
 778 
 779 
 780 
 781 
 782 
 783 
 784 enum hwloc_distrib_flags_e {
 785   
 786 
 787 
 788   HWLOC_DISTRIB_FLAG_REVERSE = (1UL<<0)
 789 };
 790 
 791 
 792 
 793 
 794 
 795 
 796 
 797 
 798 
 799 
 800 
 801 
 802 
 803 
 804 
 805 
 806 
 807 
 808 
 809 
 810 
 811 
 812 
 813 
 814 static __hwloc_inline int
 815 hwloc_distrib(hwloc_topology_t topology,
 816               hwloc_obj_t *roots, unsigned n_roots,
 817               hwloc_cpuset_t *set,
 818               unsigned n,
 819               int until, unsigned long flags)
 820 {
 821   unsigned i;
 822   unsigned tot_weight;
 823   unsigned given, givenweight;
 824   hwloc_cpuset_t *cpusetp = set;
 825 
 826   if (flags & ~HWLOC_DISTRIB_FLAG_REVERSE) {
 827     errno = EINVAL;
 828     return -1;
 829   }
 830 
 831   tot_weight = 0;
 832   for (i = 0; i < n_roots; i++)
 833     tot_weight += (unsigned) hwloc_bitmap_weight(roots[i]->cpuset);
 834 
 835   for (i = 0, given = 0, givenweight = 0; i < n_roots; i++) {
 836     unsigned chunk, weight;
 837     hwloc_obj_t root = roots[flags & HWLOC_DISTRIB_FLAG_REVERSE ? n_roots-1-i : i];
 838     hwloc_cpuset_t cpuset = root->cpuset;
 839     if (root->type == HWLOC_OBJ_NUMANODE)
 840       
 841       root = root->parent;
 842     weight = (unsigned) hwloc_bitmap_weight(cpuset);
 843     if (!weight)
 844       continue;
 845     
 846 
 847     chunk = (( (givenweight+weight) * n  + tot_weight-1) / tot_weight)
 848           - ((  givenweight         * n  + tot_weight-1) / tot_weight);
 849     if (!root->arity || chunk <= 1 || root->depth >= until) {
 850       
 851       if (chunk) {
 852         
 853         unsigned j;
 854         for (j=0; j < chunk; j++)
 855           cpusetp[j] = hwloc_bitmap_dup(cpuset);
 856       } else {
 857         
 858 
 859 
 860 
 861         assert(given);
 862         hwloc_bitmap_or(cpusetp[-1], cpusetp[-1], cpuset);
 863       }
 864     } else {
 865       
 866       hwloc_distrib(topology, root->children, root->arity, cpusetp, chunk, until, flags);
 867     }
 868     cpusetp += chunk;
 869     given += chunk;
 870     givenweight += weight;
 871   }
 872 
 873   return 0;
 874 }
 875 
 876 
 877 
 878 
 879 
 880 
 881 
 882 
 883 
 884 
 885 
 886 
 887 
 888 
 889 
 890 
 891 
 892 
 893 HWLOC_DECLSPEC hwloc_const_cpuset_t
 894 hwloc_topology_get_complete_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
 895 
 896 
 897 
 898 
 899 
 900 
 901 
 902 
 903 
 904 
 905 
 906 
 907 HWLOC_DECLSPEC hwloc_const_cpuset_t
 908 hwloc_topology_get_topology_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
 909 
 910 
 911 
 912 
 913 
 914 
 915 
 916 
 917 
 918 
 919 
 920 
 921 
 922 
 923 
 924 
 925 
 926 HWLOC_DECLSPEC hwloc_const_cpuset_t
 927 hwloc_topology_get_allowed_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
 928 
 929 
 930 
 931 
 932 
 933 
 934 
 935 
 936 
 937 
 938 HWLOC_DECLSPEC hwloc_const_nodeset_t
 939 hwloc_topology_get_complete_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
 940 
 941 
 942 
 943 
 944 
 945 
 946 
 947 
 948 
 949 
 950 
 951 
 952 HWLOC_DECLSPEC hwloc_const_nodeset_t
 953 hwloc_topology_get_topology_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
 954 
 955 
 956 
 957 
 958 
 959 
 960 
 961 
 962 
 963 
 964 
 965 
 966 
 967 
 968 
 969 
 970 
 971 HWLOC_DECLSPEC hwloc_const_nodeset_t
 972 hwloc_topology_get_allowed_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
 973 
 974 
 975 
 976 
 977 
 978 
 979 
 980 
 981 
 982 
 983 
 984 
 985 
 986 
 987 
 988 
 989 
 990 
 991 
 992 
 993 static __hwloc_inline int
 994 hwloc_cpuset_to_nodeset(hwloc_topology_t topology, hwloc_const_cpuset_t _cpuset, hwloc_nodeset_t nodeset)
 995 {
 996         int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
 997         hwloc_obj_t obj = NULL;
 998         assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
 999         hwloc_bitmap_zero(nodeset);
1000         while ((obj = hwloc_get_next_obj_covering_cpuset_by_depth(topology, _cpuset, depth, obj)) != NULL)
1001                 if (hwloc_bitmap_set(nodeset, obj->os_index) < 0)
1002                         return -1;
1003         return 0;
1004 }
1005 
1006 
1007 
1008 
1009 
1010 
1011 
1012 
1013 
1014 static __hwloc_inline int
1015 hwloc_cpuset_from_nodeset(hwloc_topology_t topology, hwloc_cpuset_t _cpuset, hwloc_const_nodeset_t nodeset)
1016 {
1017         int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
1018         hwloc_obj_t obj = NULL;
1019         assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
1020         hwloc_bitmap_zero(_cpuset);
1021         while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL) {
1022                 if (hwloc_bitmap_isset(nodeset, obj->os_index))
1023                         
1024                         if (hwloc_bitmap_or(_cpuset, _cpuset, obj->cpuset) < 0)
1025                                 return -1;
1026         }
1027         return 0;
1028 }
1029 
1030 
1031 
1032 
1033 
1034 
1035 
1036 
1037 
1038 
1039 
1040 
1041 
1042 
1043 
1044 
1045 
1046 
1047 
1048 
1049 static __hwloc_inline hwloc_obj_t
1050 hwloc_get_non_io_ancestor_obj(hwloc_topology_t topology __hwloc_attribute_unused,
1051                               hwloc_obj_t ioobj)
1052 {
1053   hwloc_obj_t obj = ioobj;
1054   while (obj && !obj->cpuset) {
1055     obj = obj->parent;
1056   }
1057   return obj;
1058 }
1059 
1060 
1061 
1062 
1063 
1064 static __hwloc_inline hwloc_obj_t
1065 hwloc_get_next_pcidev(hwloc_topology_t topology, hwloc_obj_t prev)
1066 {
1067   return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_PCI_DEVICE, prev);
1068 }
1069 
1070 
1071 
1072 
1073 static __hwloc_inline hwloc_obj_t
1074 hwloc_get_pcidev_by_busid(hwloc_topology_t topology,
1075                           unsigned domain, unsigned bus, unsigned dev, unsigned func)
1076 {
1077   hwloc_obj_t obj = NULL;
1078   while ((obj = hwloc_get_next_pcidev(topology, obj)) != NULL) {
1079     if (obj->attr->pcidev.domain == domain
1080         && obj->attr->pcidev.bus == bus
1081         && obj->attr->pcidev.dev == dev
1082         && obj->attr->pcidev.func == func)
1083       return obj;
1084   }
1085   return NULL;
1086 }
1087 
1088 
1089 
1090 
1091 static __hwloc_inline hwloc_obj_t
1092 hwloc_get_pcidev_by_busidstring(hwloc_topology_t topology, const char *busid)
1093 {
1094   unsigned domain = 0; 
1095   unsigned bus, dev, func;
1096 
1097   if (sscanf(busid, "%x:%x.%x", &bus, &dev, &func) != 3
1098       && sscanf(busid, "%x:%x:%x.%x", &domain, &bus, &dev, &func) != 4) {
1099     errno = EINVAL;
1100     return NULL;
1101   }
1102 
1103   return hwloc_get_pcidev_by_busid(topology, domain, bus, dev, func);
1104 }
1105 
1106 
1107 
1108 
1109 
1110 static __hwloc_inline hwloc_obj_t
1111 hwloc_get_next_osdev(hwloc_topology_t topology, hwloc_obj_t prev)
1112 {
1113   return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_OS_DEVICE, prev);
1114 }
1115 
1116 
1117 
1118 
1119 
1120 static __hwloc_inline hwloc_obj_t
1121 hwloc_get_next_bridge(hwloc_topology_t topology, hwloc_obj_t prev)
1122 {
1123   return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_BRIDGE, prev);
1124 }
1125 
1126 
1127 
1128 static __hwloc_inline int
1129 hwloc_bridge_covers_pcibus(hwloc_obj_t bridge,
1130                            unsigned domain, unsigned bus)
1131 {
1132   return bridge->type == HWLOC_OBJ_BRIDGE
1133     && bridge->attr->bridge.downstream_type == HWLOC_OBJ_BRIDGE_PCI
1134     && bridge->attr->bridge.downstream.pci.domain == domain
1135     && bridge->attr->bridge.downstream.pci.secondary_bus <= bus
1136     && bridge->attr->bridge.downstream.pci.subordinate_bus >= bus;
1137 }
1138 
1139 
1140 
1141 
1142 
1143 #ifdef __cplusplus
1144 } 
1145 #endif
1146 
1147 
1148 #endif