|
|
|||
Warning, file /include/hwloc.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright © 2009 CNRS 0003 * Copyright © 2009-2024 Inria. All rights reserved. 0004 * Copyright © 2009-2012 Université Bordeaux 0005 * Copyright © 2009-2020 Cisco Systems, Inc. All rights reserved. 0006 * See COPYING in top-level directory. 0007 */ 0008 0009 /*===================================================================== 0010 * PLEASE GO READ THE DOCUMENTATION! 0011 * ------------------------------------------------ 0012 * $tarball_directory/doc/doxygen-doc/ 0013 * or 0014 * https://www.open-mpi.org/projects/hwloc/doc/ 0015 *===================================================================== 0016 * 0017 * FAIR WARNING: Do NOT expect to be able to figure out all the 0018 * subtleties of hwloc by simply reading function prototypes and 0019 * constant descrptions here in this file. 0020 * 0021 * Hwloc has wonderful documentation in both PDF and HTML formats for 0022 * your reading pleasure. The formal documentation explains a LOT of 0023 * hwloc-specific concepts, provides definitions, and discusses the 0024 * "big picture" for many of the things that you'll find here in this 0025 * header file. 0026 * 0027 * The PDF/HTML documentation was generated via Doxygen; much of what 0028 * you'll see in there is also here in this file. BUT THERE IS A LOT 0029 * THAT IS IN THE PDF/HTML THAT IS ***NOT*** IN hwloc.h! 0030 * 0031 * There are entire paragraph-length descriptions, discussions, and 0032 * pretty pictures to explain subtle corner cases, provide concrete 0033 * examples, etc. 0034 * 0035 * Please, go read the documentation. :-) 0036 * 0037 * Moreover there are several examples of hwloc use under doc/examples 0038 * in the source tree. 0039 * 0040 *=====================================================================*/ 0041 0042 /** \file 0043 * \brief The hwloc API. 0044 * 0045 * See hwloc/bitmap.h for bitmap specific macros. 0046 * See hwloc/helper.h for high-level topology traversal helpers. 0047 * See hwloc/inlines.h for the actual inline code of some functions below. 0048 * See hwloc/export.h for exporting topologies to XML or to synthetic descriptions. 0049 * See hwloc/distances.h for querying and modifying distances between objects. 0050 * See hwloc/diff.h for manipulating differences between similar topologies. 0051 */ 0052 0053 #ifndef HWLOC_H 0054 #define HWLOC_H 0055 0056 #include "hwloc/autogen/config.h" 0057 0058 #include <sys/types.h> 0059 #include <stdio.h> 0060 #include <string.h> 0061 #include <limits.h> 0062 0063 /* 0064 * Symbol transforms 0065 */ 0066 #include "hwloc/rename.h" 0067 0068 /* 0069 * Bitmap definitions 0070 */ 0071 0072 #include "hwloc/bitmap.h" 0073 0074 0075 #ifdef __cplusplus 0076 extern "C" { 0077 #endif 0078 0079 0080 /** \defgroup hwlocality_api_error_reporting Error reporting in the API 0081 * @{ 0082 * Most functions in the hwloc API return an integer value. 0083 * Unless documentated differently, they return 0 on success 0084 * and -1 on error. 0085 * Functions that return a pointer type return \c NULL on error. 0086 * 0087 * \p errno will be set to a meaningful value whenever possible. 0088 * This includes the usual \c EINVAL when invalid function parameters are passed 0089 * or \c ENOMEM when an internal allocation fails. 0090 * Some specific \c errno value are also used, for instance for binding 0091 * errors as documented in \ref hwlocality_cpubinding. 0092 * 0093 * Some modules describe return values of their functions 0094 * in their introduction, for instance in \ref hwlocality_bitmap. 0095 * @} 0096 */ 0097 0098 0099 /** \defgroup hwlocality_api_version API version 0100 * @{ 0101 */ 0102 0103 /** \brief Indicate at build time which hwloc API version is being used. 0104 * 0105 * This number is updated to (X<<16)+(Y<<8)+Z when a new release X.Y.Z 0106 * actually modifies the API. 0107 * 0108 * Users may check for available features at build time using this number 0109 * (see \ref faq_version_api). 0110 * 0111 * \note This should not be confused with HWLOC_VERSION, the library version. 0112 * Two stable releases of the same series usually have the same ::HWLOC_API_VERSION 0113 * even if their HWLOC_VERSION are different. 0114 */ 0115 #define HWLOC_API_VERSION 0x00020b00 0116 0117 /** \brief Indicate at runtime which hwloc API version was used at build time. 0118 * 0119 * Should be ::HWLOC_API_VERSION if running on the same version. 0120 * 0121 * \return the build-time version number. 0122 */ 0123 HWLOC_DECLSPEC unsigned hwloc_get_api_version(void); 0124 0125 /** \brief Current component and plugin ABI version (see hwloc/plugins.h) */ 0126 #define HWLOC_COMPONENT_ABI 7 0127 0128 /** @} */ 0129 0130 0131 0132 /** \defgroup hwlocality_object_sets Object Sets (hwloc_cpuset_t and hwloc_nodeset_t) 0133 * 0134 * Hwloc uses bitmaps to represent two distinct kinds of object sets: 0135 * CPU sets (::hwloc_cpuset_t) and NUMA node sets (::hwloc_nodeset_t). 0136 * These types are both typedefs to a common back end type 0137 * (::hwloc_bitmap_t), and therefore all the hwloc bitmap functions 0138 * are applicable to both ::hwloc_cpuset_t and ::hwloc_nodeset_t (see 0139 * \ref hwlocality_bitmap). 0140 * 0141 * The rationale for having two different types is that even though 0142 * the actions one wants to perform on these types are the same (e.g., 0143 * enable and disable individual items in the set/mask), they're used 0144 * in very different contexts: one for specifying which processors to 0145 * use and one for specifying which NUMA nodes to use. Hence, the 0146 * name difference is really just to reflect the intent of where the 0147 * type is used. 0148 * 0149 * @{ 0150 */ 0151 0152 /** \brief A CPU set is a bitmap whose bits are set according to CPU 0153 * physical OS indexes. 0154 * 0155 * It may be consulted and modified with the bitmap API as any 0156 * ::hwloc_bitmap_t (see hwloc/bitmap.h). 0157 * 0158 * Each bit may be converted into a PU object using 0159 * hwloc_get_pu_obj_by_os_index(). 0160 */ 0161 typedef hwloc_bitmap_t hwloc_cpuset_t; 0162 /** \brief A non-modifiable ::hwloc_cpuset_t. */ 0163 typedef hwloc_const_bitmap_t hwloc_const_cpuset_t; 0164 0165 /** \brief A node set is a bitmap whose bits are set according to NUMA 0166 * memory node physical OS indexes. 0167 * 0168 * It may be consulted and modified with the bitmap API as any 0169 * ::hwloc_bitmap_t (see hwloc/bitmap.h). 0170 * Each bit may be converted into a NUMA node object using 0171 * hwloc_get_numanode_obj_by_os_index(). 0172 * 0173 * When binding memory on a system without any NUMA node, 0174 * the single main memory bank is considered as NUMA node #0. 0175 * 0176 * See also \ref hwlocality_helper_nodeset_convert. 0177 */ 0178 typedef hwloc_bitmap_t hwloc_nodeset_t; 0179 /** \brief A non-modifiable ::hwloc_nodeset_t. 0180 */ 0181 typedef hwloc_const_bitmap_t hwloc_const_nodeset_t; 0182 0183 /** @} */ 0184 0185 0186 0187 /** \defgroup hwlocality_object_types Object Types 0188 * @{ 0189 */ 0190 0191 /** \brief Type of topology object. 0192 * 0193 * \note Do not rely on the ordering or completeness of the values as new ones 0194 * may be defined in the future! If you need to compare types, use 0195 * hwloc_compare_types() instead. 0196 */ 0197 typedef enum { 0198 0199 /** \cond */ 0200 #define HWLOC_OBJ_TYPE_MIN HWLOC_OBJ_MACHINE /* Sentinel value */ 0201 /** \endcond */ 0202 0203 HWLOC_OBJ_MACHINE, /**< \brief Machine. 0204 * A set of processors and memory with cache 0205 * coherency. 0206 * 0207 * This type is always used for the root object of a topology, 0208 * and never used anywhere else. 0209 * Hence its parent is always \c NULL. 0210 */ 0211 0212 HWLOC_OBJ_PACKAGE, /**< \brief Physical package. 0213 * The physical package that usually gets inserted 0214 * into a socket on the motherboard. 0215 * A processor package usually contains multiple cores, 0216 * and possibly some dies. 0217 */ 0218 HWLOC_OBJ_CORE, /**< \brief Core. 0219 * A computation unit (may be shared by several 0220 * PUs, aka logical processors). 0221 */ 0222 HWLOC_OBJ_PU, /**< \brief Processing Unit, or (Logical) Processor. 0223 * An execution unit (may share a core with some 0224 * other logical processors, e.g. in the case of 0225 * an SMT core). 0226 * 0227 * This is the smallest object representing CPU resources, 0228 * it cannot have any child except Misc objects. 0229 * 0230 * Objects of this kind are always reported and can 0231 * thus be used as fallback when others are not. 0232 */ 0233 0234 HWLOC_OBJ_L1CACHE, /**< \brief Level 1 Data (or Unified) Cache. */ 0235 HWLOC_OBJ_L2CACHE, /**< \brief Level 2 Data (or Unified) Cache. */ 0236 HWLOC_OBJ_L3CACHE, /**< \brief Level 3 Data (or Unified) Cache. */ 0237 HWLOC_OBJ_L4CACHE, /**< \brief Level 4 Data (or Unified) Cache. */ 0238 HWLOC_OBJ_L5CACHE, /**< \brief Level 5 Data (or Unified) Cache. */ 0239 0240 HWLOC_OBJ_L1ICACHE, /**< \brief Level 1 instruction Cache (filtered out by default). */ 0241 HWLOC_OBJ_L2ICACHE, /**< \brief Level 2 instruction Cache (filtered out by default). */ 0242 HWLOC_OBJ_L3ICACHE, /**< \brief Level 3 instruction Cache (filtered out by default). */ 0243 0244 HWLOC_OBJ_GROUP, /**< \brief Group objects. 0245 * Objects which do not fit in the above but are 0246 * detected by hwloc and are useful to take into 0247 * account for affinity. For instance, some operating systems 0248 * expose their arbitrary processors aggregation this 0249 * way. And hwloc may insert such objects to group 0250 * NUMA nodes according to their distances. 0251 * See also \ref faq_groups. 0252 * 0253 * These objects are removed when they do not bring 0254 * any structure (see ::HWLOC_TYPE_FILTER_KEEP_STRUCTURE). 0255 */ 0256 0257 HWLOC_OBJ_NUMANODE, /**< \brief NUMA node. 0258 * An object that contains memory that is directly 0259 * and byte-accessible to the host processors. 0260 * It is usually close to some cores (the corresponding objects 0261 * are descendants of the NUMA node object in the hwloc tree). 0262 * 0263 * This is the smallest object representing Memory resources, 0264 * it cannot have any child except Misc objects. 0265 * However it may have Memory-side cache parents. 0266 * 0267 * NUMA nodes may correspond to different kinds of memory 0268 * (DRAM, HBM, CXL-DRAM, etc.). When hwloc is able to guess 0269 * that kind, it is specified in the subtype field of the object. 0270 * See also \ref attributes_normal in the main documentation. 0271 * 0272 * There is always at least one such object in the topology 0273 * even if the machine is not NUMA. 0274 * 0275 * Memory objects are not listed in the main children list, 0276 * but rather in the dedicated Memory children list. 0277 * 0278 * NUMA nodes have a special depth ::HWLOC_TYPE_DEPTH_NUMANODE 0279 * instead of a normal depth just like other objects in the 0280 * main tree. 0281 */ 0282 0283 HWLOC_OBJ_BRIDGE, /**< \brief Bridge (filtered out by default). 0284 * Any bridge (or PCI switch) that connects the host or an I/O bus, 0285 * to another I/O bus. 0286 * 0287 * Bridges are not added to the topology unless their 0288 * filtering is changed (see hwloc_topology_set_type_filter() 0289 * and hwloc_topology_set_io_types_filter()). 0290 * 0291 * I/O objects are not listed in the main children list, 0292 * but rather in the dedicated io children list. 0293 * I/O objects have NULL CPU and node sets. 0294 */ 0295 HWLOC_OBJ_PCI_DEVICE, /**< \brief PCI device (filtered out by default). 0296 * 0297 * PCI devices are not added to the topology unless their 0298 * filtering is changed (see hwloc_topology_set_type_filter() 0299 * and hwloc_topology_set_io_types_filter()). 0300 * 0301 * I/O objects are not listed in the main children list, 0302 * but rather in the dedicated io children list. 0303 * I/O objects have NULL CPU and node sets. 0304 */ 0305 HWLOC_OBJ_OS_DEVICE, /**< \brief Operating system device (filtered out by default). 0306 * 0307 * OS devices are not added to the topology unless their 0308 * filtering is changed (see hwloc_topology_set_type_filter() 0309 * and hwloc_topology_set_io_types_filter()). 0310 * 0311 * I/O objects are not listed in the main children list, 0312 * but rather in the dedicated io children list. 0313 * I/O objects have NULL CPU and node sets. 0314 */ 0315 0316 HWLOC_OBJ_MISC, /**< \brief Miscellaneous objects (filtered out by default). 0317 * Objects without particular meaning, that can e.g. be 0318 * added by the application for its own use, or by hwloc 0319 * for miscellaneous objects such as MemoryModule (DIMMs). 0320 * 0321 * They are not added to the topology unless their filtering 0322 * is changed (see hwloc_topology_set_type_filter()). 0323 * 0324 * These objects are not listed in the main children list, 0325 * but rather in the dedicated misc children list. 0326 * Misc objects may only have Misc objects as children, 0327 * and those are in the dedicated misc children list as well. 0328 * Misc objects have NULL CPU and node sets. 0329 */ 0330 0331 HWLOC_OBJ_MEMCACHE, /**< \brief Memory-side cache (filtered out by default). 0332 * A cache in front of a specific NUMA node. 0333 * 0334 * This object always has at least one NUMA node as a memory child. 0335 * 0336 * Memory objects are not listed in the main children list, 0337 * but rather in the dedicated Memory children list. 0338 * 0339 * Memory-side cache have a special depth ::HWLOC_TYPE_DEPTH_MEMCACHE 0340 * instead of a normal depth just like other objects in the 0341 * main tree. 0342 */ 0343 0344 HWLOC_OBJ_DIE, /**< \brief Die within a physical package. 0345 * A subpart of the physical package, that contains multiple cores. 0346 * 0347 * Some operating systems (e.g. Linux) may expose a single die per package 0348 * even if the hardware does not support dies at all. To avoid showing 0349 * such non-existing dies, the corresponding hwloc backend may filter them out. 0350 * This is functionally equivalent to ::HWLOC_TYPE_FILTER_KEEP_STRUCTURE 0351 * being enforced. 0352 */ 0353 0354 HWLOC_OBJ_TYPE_MAX /**< \private Sentinel value */ 0355 } hwloc_obj_type_t; 0356 0357 /** \brief Cache type. */ 0358 typedef enum hwloc_obj_cache_type_e { 0359 HWLOC_OBJ_CACHE_UNIFIED, /**< \brief Unified cache. */ 0360 HWLOC_OBJ_CACHE_DATA, /**< \brief Data cache. */ 0361 HWLOC_OBJ_CACHE_INSTRUCTION /**< \brief Instruction cache (filtered out by default). */ 0362 } hwloc_obj_cache_type_t; 0363 0364 /** \brief Type of one side (upstream or downstream) of an I/O bridge. */ 0365 typedef enum hwloc_obj_bridge_type_e { 0366 HWLOC_OBJ_BRIDGE_HOST, /**< \brief Host-side of a bridge, only possible upstream. */ 0367 HWLOC_OBJ_BRIDGE_PCI /**< \brief PCI-side of a bridge. */ 0368 } hwloc_obj_bridge_type_t; 0369 0370 /** \brief Type of a OS device. */ 0371 typedef enum hwloc_obj_osdev_type_e { 0372 HWLOC_OBJ_OSDEV_BLOCK, /**< \brief Operating system block device, or non-volatile memory device. 0373 * For instance "sda" or "dax2.0" on Linux. */ 0374 HWLOC_OBJ_OSDEV_GPU, /**< \brief Operating system GPU device. 0375 * For instance ":0.0" for a GL display, 0376 * "card0" for a Linux DRM device. */ 0377 HWLOC_OBJ_OSDEV_NETWORK, /**< \brief Operating system network device. 0378 * For instance the "eth0" interface on Linux. */ 0379 HWLOC_OBJ_OSDEV_OPENFABRICS, /**< \brief Operating system openfabrics device. 0380 * For instance the "mlx4_0" InfiniBand HCA, 0381 * "hfi1_0" Omni-Path interface, 0382 * or "bxi0" Atos/Bull BXI HCA on Linux. */ 0383 HWLOC_OBJ_OSDEV_DMA, /**< \brief Operating system dma engine device. 0384 * For instance the "dma0chan0" DMA channel on Linux. */ 0385 HWLOC_OBJ_OSDEV_COPROC /**< \brief Operating system co-processor device. 0386 * For instance "opencl0d0" for a OpenCL device, 0387 * "cuda0" for a CUDA device. */ 0388 } hwloc_obj_osdev_type_t; 0389 0390 /** \brief Compare the depth of two object types 0391 * 0392 * Types shouldn't be compared as they are, since newer ones may be added in 0393 * the future. 0394 * 0395 * \return A negative integer if \p type1 objects usually include \p type2 objects. 0396 * \return A positive integer if \p type1 objects are usually included in \p type2 objects. 0397 * \return 0 if \p type1 and \p type2 objects are the same. 0398 * \return ::HWLOC_TYPE_UNORDERED if objects cannot be compared 0399 * (because neither is usually contained in the other). 0400 * 0401 * \note Object types containing CPUs can always be compared 0402 * (usually, a machine contains packages, which contain caches, 0403 * which contain cores, which contain PUs). 0404 * 0405 * \note ::HWLOC_OBJ_PU will always be the deepest, 0406 * while ::HWLOC_OBJ_MACHINE is always the highest. 0407 * 0408 * \note This does not mean that the actual topology will respect that order: 0409 * e.g. as of today cores may also contain caches, and packages may also contain 0410 * nodes. This is thus just to be seen as a fallback comparison method. 0411 */ 0412 HWLOC_DECLSPEC int hwloc_compare_types (hwloc_obj_type_t type1, hwloc_obj_type_t type2) __hwloc_attribute_const; 0413 0414 /** \brief Value returned by hwloc_compare_types() when types can not be compared. \hideinitializer */ 0415 #define HWLOC_TYPE_UNORDERED INT_MAX 0416 0417 /** @} */ 0418 0419 0420 0421 /** \defgroup hwlocality_objects Object Structure and Attributes 0422 * @{ 0423 */ 0424 0425 union hwloc_obj_attr_u; 0426 0427 /** \brief Structure of a topology object 0428 * 0429 * Applications must not modify any field except \p hwloc_obj.userdata. 0430 */ 0431 struct hwloc_obj { 0432 /* physical information */ 0433 hwloc_obj_type_t type; /**< \brief Type of object */ 0434 char *subtype; /**< \brief Subtype string to better describe the type field. */ 0435 0436 unsigned os_index; /**< \brief OS-provided physical index number. 0437 * It is not guaranteed unique across the entire machine, 0438 * except for PUs and NUMA nodes. 0439 * Set to HWLOC_UNKNOWN_INDEX if unknown or irrelevant for this object. 0440 */ 0441 #define HWLOC_UNKNOWN_INDEX (unsigned)-1 0442 0443 char *name; /**< \brief Object-specific name if any. 0444 * Mostly used for identifying OS devices and Misc objects where 0445 * a name string is more useful than numerical indexes. 0446 */ 0447 0448 hwloc_uint64_t total_memory; /**< \brief Total memory (in bytes) in NUMA nodes below this object. */ 0449 0450 union hwloc_obj_attr_u *attr; /**< \brief Object type-specific Attributes, 0451 * may be \c NULL if no attribute value was found */ 0452 0453 /* global position */ 0454 int depth; /**< \brief Vertical index in the hierarchy. 0455 * 0456 * For normal objects, this is the depth of the horizontal level 0457 * that contains this object and its cousins of the same type. 0458 * If the topology is symmetric, this is equal to the parent depth 0459 * plus one, and also equal to the number of parent/child links 0460 * from the root object to here. 0461 * 0462 * For special objects (NUMA nodes, I/O and Misc) that are not 0463 * in the main tree, this is a special negative value that 0464 * corresponds to their dedicated level, 0465 * see hwloc_get_type_depth() and ::hwloc_get_type_depth_e. 0466 * Those special values can be passed to hwloc functions such 0467 * hwloc_get_nbobjs_by_depth() as usual. 0468 */ 0469 unsigned logical_index; /**< \brief Horizontal index in the whole list of similar objects, 0470 * hence guaranteed unique across the entire machine. 0471 * Could be a "cousin_rank" since it's the rank within the "cousin" list below 0472 * Note that this index may change when restricting the topology 0473 * or when inserting a group. 0474 */ 0475 0476 /* cousins are all objects of the same type (and depth) across the entire topology */ 0477 struct hwloc_obj *next_cousin; /**< \brief Next object of same type and depth */ 0478 struct hwloc_obj *prev_cousin; /**< \brief Previous object of same type and depth */ 0479 0480 /* children of the same parent are siblings, even if they may have different type and depth */ 0481 struct hwloc_obj *parent; /**< \brief Parent, \c NULL if root (Machine object) */ 0482 unsigned sibling_rank; /**< \brief Index in parent's \c children[] array. Or the index in parent's Memory, I/O or Misc children list. */ 0483 struct hwloc_obj *next_sibling; /**< \brief Next object below the same parent (inside the same list of children). */ 0484 struct hwloc_obj *prev_sibling; /**< \brief Previous object below the same parent (inside the same list of children). */ 0485 /** @name List and array of normal children below this object (except Memory, I/O and Misc children). */ 0486 /**@{*/ 0487 unsigned arity; /**< \brief Number of normal children. 0488 * Memory, Misc and I/O children are not listed here 0489 * but rather in their dedicated children list. 0490 */ 0491 struct hwloc_obj **children; /**< \brief Normal children, \c children[0 .. arity -1] */ 0492 struct hwloc_obj *first_child; /**< \brief First normal child */ 0493 struct hwloc_obj *last_child; /**< \brief Last normal child */ 0494 /**@}*/ 0495 0496 int symmetric_subtree; /**< \brief Set if the subtree of normal objects below this object is symmetric, 0497 * which means all normal children and their children have identical subtrees. 0498 * 0499 * Memory, I/O and Misc children are ignored. 0500 * 0501 * If set in the topology root object, lstopo may export the topology 0502 * as a synthetic string. 0503 */ 0504 0505 /** @name List of Memory children below this object. */ 0506 /**@{*/ 0507 unsigned memory_arity; /**< \brief Number of Memory children. 0508 * These children are listed in \p memory_first_child. 0509 */ 0510 struct hwloc_obj *memory_first_child; /**< \brief First Memory child. 0511 * NUMA nodes and Memory-side caches are listed here 0512 * (\p memory_arity and \p memory_first_child) 0513 * instead of in the normal children list. 0514 * See also hwloc_obj_type_is_memory(). 0515 * 0516 * A memory hierarchy starts from a normal CPU-side object 0517 * (e.g. Package) and ends with NUMA nodes as leaves. 0518 * There might exist some memory-side caches between them 0519 * in the middle of the memory subtree. 0520 */ 0521 /**@}*/ 0522 0523 /** @name List of I/O children below this object. */ 0524 /**@{*/ 0525 unsigned io_arity; /**< \brief Number of I/O children. 0526 * These children are listed in \p io_first_child. 0527 */ 0528 struct hwloc_obj *io_first_child; /**< \brief First I/O child. 0529 * Bridges, PCI and OS devices are listed here (\p io_arity and \p io_first_child) 0530 * instead of in the normal children list. 0531 * See also hwloc_obj_type_is_io(). 0532 */ 0533 /**@}*/ 0534 0535 /** @name List of Misc children below this object. */ 0536 /**@{*/ 0537 unsigned misc_arity; /**< \brief Number of Misc children. 0538 * These children are listed in \p misc_first_child. 0539 */ 0540 struct hwloc_obj *misc_first_child; /**< \brief First Misc child. 0541 * Misc objects are listed here (\p misc_arity and \p misc_first_child) 0542 * instead of in the normal children list. 0543 */ 0544 /**@}*/ 0545 0546 /* cpusets and nodesets */ 0547 hwloc_cpuset_t cpuset; /**< \brief CPUs covered by this object 0548 * 0549 * This is the set of CPUs for which there are PU objects in the topology 0550 * under this object, i.e. which are known to be physically contained in this 0551 * object and known how (the children path between this object and the PU 0552 * objects). 0553 * 0554 * If the ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED configuration flag is set, 0555 * some of these CPUs may be online but not allowed for binding, 0556 * see hwloc_topology_get_allowed_cpuset(). 0557 * 0558 * \note All objects have non-NULL CPU and node sets except Misc and I/O objects. 0559 * 0560 * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead. 0561 */ 0562 hwloc_cpuset_t complete_cpuset; /**< \brief The complete CPU set of processors of this object, 0563 * 0564 * This may include not only the same as the cpuset field, but also some CPUs for 0565 * which topology information is unknown or incomplete, some offlines CPUs, and 0566 * the CPUs that are ignored when the ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED flag 0567 * is not set. 0568 * Thus no corresponding PU object may be found in the topology, because the 0569 * precise position is undefined. It is however known that it would be somewhere 0570 * under this object. 0571 * 0572 * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead. 0573 */ 0574 0575 hwloc_nodeset_t nodeset; /**< \brief NUMA nodes covered by this object or containing this object 0576 * 0577 * This is the set of NUMA nodes for which there are NUMA node objects in the 0578 * topology under or above this object, i.e. which are known to be physically 0579 * contained in this object or containing it and known how (the children path 0580 * between this object and the NUMA node objects). 0581 * 0582 * In the end, these nodes are those that are close to the current object. 0583 * Function hwloc_get_local_numanode_objs() may be used to list those NUMA 0584 * nodes more precisely. 0585 * 0586 * If the ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED configuration flag is set, 0587 * some of these nodes may be online but not allowed for allocation, 0588 * see hwloc_topology_get_allowed_nodeset(). 0589 * 0590 * If there are no NUMA nodes in the machine, all the memory is close to this 0591 * object, so only the first bit may be set in \p nodeset. 0592 * 0593 * \note All objects have non-NULL CPU and node sets except Misc and I/O objects. 0594 * 0595 * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead. 0596 */ 0597 hwloc_nodeset_t complete_nodeset; /**< \brief The complete NUMA node set of this object, 0598 * 0599 * This may include not only the same as the nodeset field, but also some NUMA 0600 * nodes for which topology information is unknown or incomplete, some offlines 0601 * nodes, and the nodes that are ignored when the ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED 0602 * flag is not set. 0603 * Thus no corresponding NUMA node object may be found in the topology, because the 0604 * precise position is undefined. It is however known that it would be 0605 * somewhere under this object. 0606 * 0607 * If there are no NUMA nodes in the machine, all the memory is close to this 0608 * object, so only the first bit is set in \p complete_nodeset. 0609 * 0610 * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead. 0611 */ 0612 0613 struct hwloc_info_s *infos; /**< \brief Array of info attributes (name and value strings). */ 0614 unsigned infos_count; /**< \brief Size of infos array. */ 0615 0616 /* misc */ 0617 void *userdata; /**< \brief Application-given private data pointer, 0618 * initialized to \c NULL, use it as you wish. 0619 * See hwloc_topology_set_userdata_export_callback() in hwloc/export.h 0620 * if you wish to export this field to XML. */ 0621 0622 hwloc_uint64_t gp_index; /**< \brief Global persistent index. 0623 * Generated by hwloc, unique across the topology (contrary to os_index) 0624 * and persistent across topology changes (contrary to logical_index). 0625 * Mostly used internally, but could also be used by application to identify objects. 0626 */ 0627 }; 0628 /** 0629 * \brief Convenience typedef; a pointer to a struct hwloc_obj. 0630 */ 0631 typedef struct hwloc_obj * hwloc_obj_t; 0632 0633 /** \brief Object type-specific Attributes */ 0634 union hwloc_obj_attr_u { 0635 /** \brief NUMA node-specific Object Attributes */ 0636 struct hwloc_numanode_attr_s { 0637 hwloc_uint64_t local_memory; /**< \brief Local memory (in bytes) */ 0638 unsigned page_types_len; /**< \brief Size of array \p page_types */ 0639 /** \brief Array of local memory page types, \c NULL if no local memory and \p page_types is 0. 0640 * 0641 * The array is sorted by increasing \p size fields. 0642 * It contains \p page_types_len slots. 0643 */ 0644 struct hwloc_memory_page_type_s { 0645 hwloc_uint64_t size; /**< \brief Size of pages */ 0646 hwloc_uint64_t count; /**< \brief Number of pages of this size */ 0647 } * page_types; 0648 } numanode; 0649 0650 /** \brief Cache-specific Object Attributes */ 0651 struct hwloc_cache_attr_s { 0652 hwloc_uint64_t size; /**< \brief Size of cache in bytes */ 0653 unsigned depth; /**< \brief Depth of cache (e.g., L1, L2, ...etc.) */ 0654 unsigned linesize; /**< \brief Cache-line size in bytes. 0 if unknown */ 0655 int associativity; /**< \brief Ways of associativity, 0656 * -1 if fully associative, 0 if unknown */ 0657 hwloc_obj_cache_type_t type; /**< \brief Cache type */ 0658 } cache; 0659 /** \brief Group-specific Object Attributes */ 0660 struct hwloc_group_attr_s { 0661 unsigned depth; /**< \brief Depth of group object. 0662 * It may change if intermediate Group objects are added. */ 0663 unsigned kind; /**< \brief Internally-used kind of group. */ 0664 unsigned subkind; /**< \brief Internally-used subkind to distinguish different levels of groups with same kind */ 0665 unsigned char dont_merge; /**< \brief Flag preventing groups from being automatically merged with identical parent or children. */ 0666 } group; 0667 /** \brief PCI Device specific Object Attributes */ 0668 struct hwloc_pcidev_attr_s { 0669 #ifndef HWLOC_HAVE_32BITS_PCI_DOMAIN 0670 unsigned short domain; /**< \brief Domain number (xxxx in the PCI BDF notation xxxx:yy:zz.t). 0671 * Only 16bits PCI domains are supported by default. */ 0672 #else 0673 unsigned int domain; /**< \brief Domain number (xxxx in the PCI BDF notation xxxx:yy:zz.t). 0674 * 32bits PCI domain support break the library ABI, hence it's disabled by default. */ 0675 #endif 0676 unsigned char bus; /**< \brief Bus number (yy in the PCI BDF notation xxxx:yy:zz.t). */ 0677 unsigned char dev; /**< \brief Device number (zz in the PCI BDF notation xxxx:yy:zz.t). */ 0678 unsigned char func; /**< \brief Function number (t in the PCI BDF notation xxxx:yy:zz.t). */ 0679 unsigned short class_id; /**< \brief The class number (first two bytes, without the prog_if). */ 0680 unsigned short vendor_id; /**< \brief Vendor ID (xxxx in [xxxx:yyyy]). */ 0681 unsigned short device_id; /**< \brief Device ID (yyyy in [xxxx:yyyy]). */ 0682 unsigned short subvendor_id; /**< \brief Sub-Vendor ID. */ 0683 unsigned short subdevice_id; /**< \brief Sub-Device ID. */ 0684 unsigned char revision; /**< \brief Revision number. */ 0685 float linkspeed; /**< \brief Link speed in GB/s. 0686 * This datarate is the currently configured speed of the entire PCI link 0687 * (sum of the bandwidth of all PCI lanes in that link). 0688 * It may change during execution since some devices are able to 0689 * slow their PCI links down when idle. 0690 */ 0691 } pcidev; 0692 /** \brief Bridge specific Object Attributes */ 0693 struct hwloc_bridge_attr_s { 0694 union { 0695 struct hwloc_pcidev_attr_s pci; /**< \brief PCI attribute of the upstream part as a PCI device. */ 0696 } upstream; 0697 hwloc_obj_bridge_type_t upstream_type; /**< \brief Upstream Bridge type. */ 0698 union { 0699 struct { 0700 #ifndef HWLOC_HAVE_32BITS_PCI_DOMAIN 0701 unsigned short domain; /**< \brief Domain number the downstream PCI buses. 0702 * Only 16bits PCI domains are supported by default. */ 0703 #else 0704 unsigned int domain; /**< \brief Domain number the downstream PCI buses. 0705 * 32bits PCI domain support break the library ABI, hence it's disabled by default */ 0706 #endif 0707 unsigned char secondary_bus; /**< \brief First PCI bus number below the bridge. */ 0708 unsigned char subordinate_bus; /**< \brief Highest PCI bus number below the bridge. */ 0709 } pci; 0710 } downstream; 0711 hwloc_obj_bridge_type_t downstream_type; /**< \brief Downstream Bridge type. */ 0712 unsigned depth; 0713 } bridge; 0714 /** \brief OS Device specific Object Attributes */ 0715 struct hwloc_osdev_attr_s { 0716 hwloc_obj_osdev_type_t type; 0717 } osdev; 0718 }; 0719 0720 /** \brief Object info attribute (name and value strings) 0721 * 0722 * \sa hwlocality_info_attr 0723 */ 0724 struct hwloc_info_s { 0725 char *name; /**< \brief Info name */ 0726 char *value; /**< \brief Info value */ 0727 }; 0728 0729 /** @} */ 0730 0731 0732 0733 /** \defgroup hwlocality_creation Topology Creation and Destruction 0734 * @{ 0735 */ 0736 0737 struct hwloc_topology; 0738 /** \brief Topology context 0739 * 0740 * To be initialized with hwloc_topology_init() and built with hwloc_topology_load(). 0741 */ 0742 typedef struct hwloc_topology * hwloc_topology_t; 0743 0744 /** \brief Allocate a topology context. 0745 * 0746 * \param[out] topologyp is assigned a pointer to the new allocated context. 0747 * 0748 * \return 0 on success, -1 on error. 0749 */ 0750 HWLOC_DECLSPEC int hwloc_topology_init (hwloc_topology_t *topologyp); 0751 0752 /** \brief Build the actual topology 0753 * 0754 * Build the actual topology once initialized with hwloc_topology_init() and 0755 * tuned with \ref hwlocality_configuration and \ref hwlocality_setsource routines. 0756 * No other routine may be called earlier using this topology context. 0757 * 0758 * \param topology is the topology to be loaded with objects. 0759 * 0760 * \return 0 on success, -1 on error. 0761 * 0762 * \note On failure, the topology is reinitialized. It should be either 0763 * destroyed with hwloc_topology_destroy() or configured and loaded again. 0764 * 0765 * \note This function may be called only once per topology. 0766 * 0767 * \note The binding of the current thread or process may temporarily change 0768 * during this call but it will be restored before it returns. 0769 * 0770 * \sa hwlocality_configuration and hwlocality_setsource 0771 */ 0772 HWLOC_DECLSPEC int hwloc_topology_load(hwloc_topology_t topology); 0773 0774 /** \brief Terminate and free a topology context 0775 * 0776 * \param topology is the topology to be freed 0777 */ 0778 HWLOC_DECLSPEC void hwloc_topology_destroy (hwloc_topology_t topology); 0779 0780 /** \brief Duplicate a topology. 0781 * 0782 * The entire topology structure as well as its objects 0783 * are duplicated into a new one. 0784 * 0785 * This is useful for keeping a backup while modifying a topology. 0786 * 0787 * \return 0 on success, -1 on error. 0788 * 0789 * \note Object userdata is not duplicated since hwloc does not know what it point to. 0790 * The objects of both old and new topologies will point to the same userdata. 0791 */ 0792 HWLOC_DECLSPEC int hwloc_topology_dup(hwloc_topology_t *newtopology, hwloc_topology_t oldtopology); 0793 0794 /** \brief Verify that the topology is compatible with the current hwloc library. 0795 * 0796 * This is useful when using the same topology structure (in memory) 0797 * in different libraries that may use different hwloc installations 0798 * (for instance if one library embeds a specific version of hwloc, 0799 * while another library uses a default system-wide hwloc installation). 0800 * 0801 * If all libraries/programs use the same hwloc installation, this function 0802 * always returns success. 0803 * 0804 * \return \c 0 on success. 0805 * 0806 * \return \c -1 with \p errno set to \c EINVAL if incompatible. 0807 * 0808 * \note If sharing between processes with hwloc_shmem_topology_write(), 0809 * the relevant check is already performed inside hwloc_shmem_topology_adopt(). 0810 */ 0811 HWLOC_DECLSPEC int hwloc_topology_abi_check(hwloc_topology_t topology); 0812 0813 /** \brief Run internal checks on a topology structure 0814 * 0815 * The program aborts if an inconsistency is detected in the given topology. 0816 * 0817 * \param topology is the topology to be checked 0818 * 0819 * \note This routine is only useful to developers. 0820 * 0821 * \note The input topology should have been previously loaded with 0822 * hwloc_topology_load(). 0823 */ 0824 HWLOC_DECLSPEC void hwloc_topology_check(hwloc_topology_t topology); 0825 0826 /** @} */ 0827 0828 0829 0830 /** \defgroup hwlocality_levels Object levels, depths and types 0831 * @{ 0832 * 0833 * Be sure to see the figure in \ref termsanddefs that shows a 0834 * complete topology tree, including depths, child/sibling/cousin 0835 * relationships, and an example of an asymmetric topology where one 0836 * package has fewer caches than its peers. 0837 */ 0838 0839 /** \brief Get the depth of the hierarchical tree of objects. 0840 * 0841 * This is the depth of ::HWLOC_OBJ_PU objects plus one. 0842 * 0843 * \return the depth of the object tree. 0844 * 0845 * \note NUMA nodes, I/O and Misc objects are ignored when computing 0846 * the depth of the tree (they are placed on special levels). 0847 */ 0848 HWLOC_DECLSPEC int hwloc_topology_get_depth(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure; 0849 0850 /** \brief Returns the depth of objects of type \p type. 0851 * 0852 * \return The depth of objects of type \p type. 0853 * 0854 * \return A negative virtual depth if a NUMA node, I/O or Misc object type is given. 0855 * These objects are stored in special levels that are not CPU-related. 0856 * This virtual depth may be passed to other hwloc functions such as 0857 * hwloc_get_obj_by_depth() but it should not be considered as an actual 0858 * depth by the application. In particular, it should not be compared with 0859 * any other object depth or with the entire topology depth. 0860 * 0861 * \return ::HWLOC_TYPE_DEPTH_UNKNOWN 0862 * if no object of this type is present on the underlying architecture, 0863 * or if the OS doesn't provide this kind of information. 0864 * 0865 * \return ::HWLOC_TYPE_DEPTH_MULTIPLE if type ::HWLOC_OBJ_GROUP is given 0866 * and multiple levels of Groups exist. 0867 * 0868 * \note If the type is absent but a similar type is acceptable, see also 0869 * hwloc_get_type_or_below_depth() and hwloc_get_type_or_above_depth(). 0870 * 0871 * \sa hwloc_get_memory_parents_depth() for managing the depth of memory objects. 0872 * 0873 * \sa hwloc_type_sscanf_as_depth() for returning the depth of objects 0874 * whose type is given as a string. 0875 */ 0876 HWLOC_DECLSPEC int hwloc_get_type_depth (hwloc_topology_t topology, hwloc_obj_type_t type); 0877 0878 enum hwloc_get_type_depth_e { 0879 HWLOC_TYPE_DEPTH_UNKNOWN = -1, /**< \brief No object of given type exists in the topology. \hideinitializer */ 0880 HWLOC_TYPE_DEPTH_MULTIPLE = -2, /**< \brief Objects of given type exist at different depth in the topology (only for Groups). \hideinitializer */ 0881 HWLOC_TYPE_DEPTH_NUMANODE = -3, /**< \brief Virtual depth for NUMA nodes. \hideinitializer */ 0882 HWLOC_TYPE_DEPTH_BRIDGE = -4, /**< \brief Virtual depth for bridge object level. \hideinitializer */ 0883 HWLOC_TYPE_DEPTH_PCI_DEVICE = -5, /**< \brief Virtual depth for PCI device object level. \hideinitializer */ 0884 HWLOC_TYPE_DEPTH_OS_DEVICE = -6, /**< \brief Virtual depth for software device object level. \hideinitializer */ 0885 HWLOC_TYPE_DEPTH_MISC = -7, /**< \brief Virtual depth for Misc object. \hideinitializer */ 0886 HWLOC_TYPE_DEPTH_MEMCACHE = -8 /**< \brief Virtual depth for MemCache object. \hideinitializer */ 0887 }; 0888 0889 /** \brief Return the depth of parents where memory objects are attached. 0890 * 0891 * Memory objects have virtual negative depths because they are not part of 0892 * the main CPU-side hierarchy of objects. This depth should not be compared 0893 * with other level depths. 0894 * 0895 * If all Memory objects are attached to Normal parents at the same depth, 0896 * this parent depth may be compared to other as usual, for instance 0897 * for knowing whether NUMA nodes is attached above or below Packages. 0898 * 0899 * \return The depth of Normal parents of all memory children 0900 * if all these parents have the same depth. For instance the depth of 0901 * the Package level if all NUMA nodes are attached to Package objects. 0902 * 0903 * \return ::HWLOC_TYPE_DEPTH_MULTIPLE if Normal parents of all 0904 * memory children do not have the same depth. For instance if some 0905 * NUMA nodes are attached to Packages while others are attached to 0906 * Groups. 0907 */ 0908 HWLOC_DECLSPEC int hwloc_get_memory_parents_depth (hwloc_topology_t topology); 0909 0910 /** \brief Returns the depth of objects of type \p type or below 0911 * 0912 * If no object of this type is present on the underlying architecture, the 0913 * function returns the depth of the first "present" object typically found 0914 * inside \p type. 0915 * 0916 * This function is only meaningful for normal object types. 0917 * If a memory, I/O or Misc object type is given, the corresponding virtual 0918 * depth is always returned (see hwloc_get_type_depth()). 0919 * 0920 * May return ::HWLOC_TYPE_DEPTH_MULTIPLE for ::HWLOC_OBJ_GROUP just like 0921 * hwloc_get_type_depth(). 0922 */ 0923 static __hwloc_inline int 0924 hwloc_get_type_or_below_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure; 0925 0926 /** \brief Returns the depth of objects of type \p type or above 0927 * 0928 * If no object of this type is present on the underlying architecture, the 0929 * function returns the depth of the first "present" object typically 0930 * containing \p type. 0931 * 0932 * This function is only meaningful for normal object types. 0933 * If a memory, I/O or Misc object type is given, the corresponding virtual 0934 * depth is always returned (see hwloc_get_type_depth()). 0935 * 0936 * May return ::HWLOC_TYPE_DEPTH_MULTIPLE for ::HWLOC_OBJ_GROUP just like 0937 * hwloc_get_type_depth(). 0938 */ 0939 static __hwloc_inline int 0940 hwloc_get_type_or_above_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure; 0941 0942 /** \brief Returns the type of objects at depth \p depth. 0943 * 0944 * \p depth should between 0 and hwloc_topology_get_depth()-1, 0945 * or a virtual depth such as ::HWLOC_TYPE_DEPTH_NUMANODE. 0946 * 0947 * \return The type of objects at depth \p depth. 0948 * \return (hwloc_obj_type_t)-1 if depth \p depth does not exist. 0949 */ 0950 HWLOC_DECLSPEC hwloc_obj_type_t hwloc_get_depth_type (hwloc_topology_t topology, int depth) __hwloc_attribute_pure; 0951 0952 /** \brief Returns the width of level at depth \p depth. 0953 * 0954 * \return The number of objects at topology depth \p depth. 0955 * \return 0 if there are no objects at depth \p depth. 0956 */ 0957 HWLOC_DECLSPEC unsigned hwloc_get_nbobjs_by_depth (hwloc_topology_t topology, int depth) __hwloc_attribute_pure; 0958 0959 /** \brief Returns the width of level type \p type 0960 * 0961 * \return The number of objects of type \p type. 0962 * \return -1 if there are multiple levels with objects of that type, e.g. ::HWLOC_OBJ_GROUP. 0963 * \return 0 if there are no objects at depth \p depth. 0964 */ 0965 static __hwloc_inline int 0966 hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure; 0967 0968 /** \brief Returns the top-object of the topology-tree. 0969 * 0970 * Its type is ::HWLOC_OBJ_MACHINE. 0971 * 0972 * This function cannot return \c NULL. 0973 */ 0974 static __hwloc_inline hwloc_obj_t 0975 hwloc_get_root_obj (hwloc_topology_t topology) __hwloc_attribute_pure; 0976 0977 /** \brief Returns the topology object at logical index \p idx from depth \p depth 0978 * 0979 * \return The object if it exists. 0980 * \return \c NULL if there is no object with this index and depth. 0981 */ 0982 HWLOC_DECLSPEC hwloc_obj_t hwloc_get_obj_by_depth (hwloc_topology_t topology, int depth, unsigned idx) __hwloc_attribute_pure; 0983 0984 /** \brief Returns the topology object at logical index \p idx with type \p type 0985 * 0986 * \return The object if it exists. 0987 * \return \c NULL if there is no object with this index and type. 0988 * \return \c NULL if there are multiple levels with objects of that type (e.g. ::HWLOC_OBJ_GROUP), 0989 * the caller may fallback to hwloc_get_obj_by_depth(). 0990 */ 0991 static __hwloc_inline hwloc_obj_t 0992 hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx) __hwloc_attribute_pure; 0993 0994 /** \brief Returns the next object at depth \p depth. 0995 * 0996 * \return The first object at depth \p depth if \p prev is \c NULL. 0997 * \return The object after \p prev at depth \p depth if \p prev is not \c NULL. 0998 * \return \c NULL if there is no such object. 0999 */ 1000 static __hwloc_inline hwloc_obj_t 1001 hwloc_get_next_obj_by_depth (hwloc_topology_t topology, int depth, hwloc_obj_t prev); 1002 1003 /** \brief Returns the next object of type \p type. 1004 * 1005 * \return The first object of type \p type if \p prev is \c NULL. 1006 * \return The object after \p prev of type \p type if \p prev is not \c NULL. 1007 * \return \c NULL if there is no such object. 1008 * \return \c NULL if there are multiple levels with objects of that type (e.g. ::HWLOC_OBJ_GROUP), 1009 * the caller may fallback to hwloc_get_obj_by_depth(). 1010 */ 1011 static __hwloc_inline hwloc_obj_t 1012 hwloc_get_next_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, 1013 hwloc_obj_t prev); 1014 1015 /** @} */ 1016 1017 1018 1019 /** \defgroup hwlocality_object_strings Converting between Object Types and Attributes, and Strings 1020 * @{ 1021 */ 1022 1023 /** \brief Return a constant stringified object type. 1024 * 1025 * This function is the basic way to convert a generic type into a string. 1026 * The output string may be parsed back by hwloc_type_sscanf(). 1027 * 1028 * hwloc_obj_type_snprintf() may return a more precise output for a specific 1029 * object, but it requires the caller to provide the output buffer. 1030 * 1031 * \return A constant string containing the object type name or \c "Unknown". 1032 */ 1033 HWLOC_DECLSPEC const char * hwloc_obj_type_string (hwloc_obj_type_t type) __hwloc_attribute_const; 1034 1035 /** \brief Stringify the type of a given topology object into a human-readable form. 1036 * 1037 * Contrary to hwloc_obj_type_string(), this function includes object-specific 1038 * attributes (such as the Group depth, the Bridge type, or OS device type) 1039 * in the output, and it requires the caller to provide the output buffer. 1040 * 1041 * The output is guaranteed to be the same for all objects of a same topology level. 1042 * 1043 * If \p verbose is 1, longer type names are used, e.g. L1Cache instead of L1. 1044 * 1045 * The output string may be parsed back by hwloc_type_sscanf(). 1046 * 1047 * If \p size is 0, \p string may safely be \c NULL. 1048 * 1049 * \return the number of characters that were actually written if not truncating, 1050 * or that would have been written (not including the ending \\0). 1051 */ 1052 HWLOC_DECLSPEC int hwloc_obj_type_snprintf(char * __hwloc_restrict string, size_t size, 1053 hwloc_obj_t obj, 1054 int verbose); 1055 1056 /** \brief Stringify the attributes of a given topology object into a human-readable form. 1057 * 1058 * Attribute values are separated by \p separator. 1059 * 1060 * Only the major attributes are printed in non-verbose mode. 1061 * 1062 * If \p size is 0, \p string may safely be \c NULL. 1063 * 1064 * \return the number of characters that were actually written if not truncating, 1065 * or that would have been written (not including the ending \\0). 1066 */ 1067 HWLOC_DECLSPEC int hwloc_obj_attr_snprintf(char * __hwloc_restrict string, size_t size, 1068 hwloc_obj_t obj, const char * __hwloc_restrict separator, 1069 int verbose); 1070 1071 /** \brief Return an object type and attributes from a type string. 1072 * 1073 * Convert strings such as "Package" or "L1iCache" into the corresponding types. 1074 * Matching is case-insensitive, and only the first letters are actually 1075 * required to match. 1076 * 1077 * The matched object type is set in \p typep (which cannot be \c NULL). 1078 * 1079 * Type-specific attributes, for instance Cache type, Cache depth, Group depth, 1080 * Bridge type or OS Device type may be returned in \p attrp. 1081 * Attributes that are not specified in the string (for instance "Group" 1082 * without a depth, or "L2Cache" without a cache type) are set to -1. 1083 * 1084 * \p attrp is only filled if not \c NULL and if its size specified in \p attrsize 1085 * is large enough. It should be at least as large as union hwloc_obj_attr_u. 1086 * 1087 * \return 0 if a type was correctly identified, otherwise -1. 1088 * 1089 * \note This function is guaranteed to match any string returned by 1090 * hwloc_obj_type_string() or hwloc_obj_type_snprintf(). 1091 * 1092 * \note This is an extended version of the now deprecated hwloc_obj_type_sscanf(). 1093 */ 1094 HWLOC_DECLSPEC int hwloc_type_sscanf(const char *string, 1095 hwloc_obj_type_t *typep, 1096 union hwloc_obj_attr_u *attrp, size_t attrsize); 1097 1098 /** \brief Return an object type and its level depth from a type string. 1099 * 1100 * Convert strings such as "Package" or "L1iCache" into the corresponding types 1101 * and return in \p depthp the depth of the corresponding level in the 1102 * topology \p topology. 1103 * 1104 * If no object of this type is present on the underlying architecture, 1105 * ::HWLOC_TYPE_DEPTH_UNKNOWN is returned. 1106 * 1107 * If multiple such levels exist (for instance if giving Group without any depth), 1108 * the function may return ::HWLOC_TYPE_DEPTH_MULTIPLE instead. 1109 * 1110 * The matched object type is set in \p typep if \p typep is non \c NULL. 1111 * 1112 * \note This function is similar to hwloc_type_sscanf() followed 1113 * by hwloc_get_type_depth() but it also automatically disambiguates 1114 * multiple group levels etc. 1115 * 1116 * \note This function is guaranteed to match any string returned by 1117 * hwloc_obj_type_string() or hwloc_obj_type_snprintf(). 1118 */ 1119 HWLOC_DECLSPEC int hwloc_type_sscanf_as_depth(const char *string, 1120 hwloc_obj_type_t *typep, 1121 hwloc_topology_t topology, int *depthp); 1122 1123 /** @} */ 1124 1125 1126 1127 /** \defgroup hwlocality_info_attr Consulting and Adding Info Attributes 1128 * 1129 * @{ 1130 */ 1131 1132 /** \brief Search the given name in object infos and return the corresponding value. 1133 * 1134 * If multiple info attributes match the given name, only the first one is returned. 1135 * 1136 * \return A pointer to the value string if it exists. 1137 * \return \c NULL if no such info attribute exists. 1138 * 1139 * \note The string should not be freed by the caller, it belongs to the hwloc library. 1140 */ 1141 static __hwloc_inline const char * 1142 hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name) __hwloc_attribute_pure; 1143 1144 /** \brief Add the given name and value pair to the given object info attributes. 1145 * 1146 * The info pair is appended to the existing info array even if another pair 1147 * with the same name already exists. 1148 * 1149 * The input strings are copied before being added in the object infos. 1150 * 1151 * \return \c 0 on success, \c -1 on error. 1152 * 1153 * \note This function may be used to enforce object colors in the lstopo 1154 * graphical output by adding "lstopoStyle" as a name and "Background=#rrggbb" 1155 * as a value. See CUSTOM COLORS in the lstopo(1) manpage for details. 1156 * 1157 * \note If \p name or \p value contain some non-printable characters, they will 1158 * be dropped when exporting to XML, see hwloc_topology_export_xml() in hwloc/export.h. 1159 */ 1160 HWLOC_DECLSPEC int hwloc_obj_add_info(hwloc_obj_t obj, const char *name, const char *value); 1161 1162 /** \brief Set (or replace) the subtype of an object. 1163 * 1164 * The given \p subtype is copied internally, the caller is responsible 1165 * for freeing the original \p subtype if needed. 1166 * 1167 * If another subtype already exists in \p object, it is replaced. 1168 * The given \p subtype may be \c NULL to remove the existing subtype. 1169 * 1170 * \note This function is mostly meant to initialize the subtype of user-added 1171 * objects such as groups with hwloc_topology_alloc_group_object(). 1172 * 1173 * \return \c 0 on success. 1174 * \return \c -1 with \p errno set to \c ENOMEM on failure to allocate memory. 1175 */ 1176 HWLOC_DECLSPEC int hwloc_obj_set_subtype(hwloc_topology_t topology, hwloc_obj_t obj, const char *subtype); 1177 1178 /** @} */ 1179 1180 1181 1182 /** \defgroup hwlocality_cpubinding CPU binding 1183 * 1184 * Some operating systems only support binding threads or processes to a single PU. 1185 * Others allow binding to larger sets such as entire Cores or Packages or 1186 * even random sets of individual PUs. In such operating system, the scheduler 1187 * is free to run the task on one of these PU, then migrate it to another PU, etc. 1188 * It is often useful to call hwloc_bitmap_singlify() on the target CPU set before 1189 * passing it to the binding function to avoid these expensive migrations. 1190 * See the documentation of hwloc_bitmap_singlify() for details. 1191 * 1192 * Some operating systems do not provide all hwloc-supported 1193 * mechanisms to bind processes, threads, etc. 1194 * hwloc_topology_get_support() may be used to query about the actual CPU 1195 * binding support in the currently used operating system. 1196 * 1197 * When the requested binding operation is not available and the 1198 * ::HWLOC_CPUBIND_STRICT flag was passed, the function returns -1. 1199 * \p errno is set to \c ENOSYS when it is not possible to bind the requested kind of object 1200 * processes/threads. errno is set to \c EXDEV when the requested cpuset 1201 * can not be enforced (e.g. some systems only allow one CPU, and some 1202 * other systems only allow one NUMA node). 1203 * 1204 * If ::HWLOC_CPUBIND_STRICT was not passed, the function may fail as well, 1205 * or the operating system may use a slightly different operation 1206 * (with side-effects, smaller binding set, etc.) 1207 * when the requested operation is not exactly supported. 1208 * 1209 * The most portable version that should be preferred over the others, 1210 * whenever possible, is the following one which just binds the current program, 1211 * assuming it is single-threaded: 1212 * 1213 * \code 1214 * hwloc_set_cpubind(topology, set, 0), 1215 * \endcode 1216 * 1217 * If the program may be multithreaded, the following one should be preferred 1218 * to only bind the current thread: 1219 * 1220 * \code 1221 * hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD), 1222 * \endcode 1223 * 1224 * \sa Some example codes are available under doc/examples/ in the source tree. 1225 * 1226 * \note To unbind, just call the binding function with either a full cpuset or 1227 * a cpuset equal to the system cpuset. 1228 * 1229 * \note On some operating systems, CPU binding may have effects on memory binding, see 1230 * ::HWLOC_CPUBIND_NOMEMBIND 1231 * 1232 * \note Running lstopo \--top or hwloc-ps can be a very convenient tool to check 1233 * how binding actually happened. 1234 * @{ 1235 */ 1236 1237 /** \brief Process/Thread binding flags. 1238 * 1239 * These bit flags can be used to refine the binding policy. 1240 * 1241 * The default (0) is to bind the current process, assumed to be 1242 * single-threaded, in a non-strict way. This is the most portable 1243 * way to bind as all operating systems usually provide it. 1244 * 1245 * \note Not all systems support all kinds of binding. See the 1246 * "Detailed Description" section of \ref hwlocality_cpubinding for a 1247 * description of errors that can occur. 1248 */ 1249 typedef enum { 1250 /** \brief Bind all threads of the current (possibly) multithreaded process. 1251 * \hideinitializer */ 1252 HWLOC_CPUBIND_PROCESS = (1<<0), 1253 1254 /** \brief Bind current thread of current process. 1255 * \hideinitializer */ 1256 HWLOC_CPUBIND_THREAD = (1<<1), 1257 1258 /** \brief Request for strict binding from the OS. 1259 * 1260 * By default, when the designated CPUs are all busy while other 1261 * CPUs are idle, operating systems may execute the thread/process 1262 * on those other CPUs instead of the designated CPUs, to let them 1263 * progress anyway. Strict binding means that the thread/process 1264 * will _never_ execute on other CPUs than the designated CPUs, even 1265 * when those are busy with other tasks and other CPUs are idle. 1266 * 1267 * \note Depending on the operating system, strict binding may not 1268 * be possible (e.g., the OS does not implement it) or not allowed 1269 * (e.g., for an administrative reasons), and the function will fail 1270 * in that case. 1271 * 1272 * When retrieving the binding of a process, this flag checks 1273 * whether all its threads actually have the same binding. If the 1274 * flag is not given, the binding of each thread will be 1275 * accumulated. 1276 * 1277 * \note This flag is meaningless when retrieving the binding of a 1278 * thread. 1279 * \hideinitializer 1280 */ 1281 HWLOC_CPUBIND_STRICT = (1<<2), 1282 1283 /** \brief Avoid any effect on memory binding 1284 * 1285 * On some operating systems, some CPU binding function would also 1286 * bind the memory on the corresponding NUMA node. It is often not 1287 * a problem for the application, but if it is, setting this flag 1288 * will make hwloc avoid using OS functions that would also bind 1289 * memory. This will however reduce the support of CPU bindings, 1290 * i.e. potentially return -1 with errno set to \c ENOSYS in some 1291 * cases. 1292 * 1293 * This flag is only meaningful when used with functions that set 1294 * the CPU binding. It is ignored when used with functions that get 1295 * CPU binding information. 1296 * \hideinitializer 1297 */ 1298 HWLOC_CPUBIND_NOMEMBIND = (1<<3) 1299 } hwloc_cpubind_flags_t; 1300 1301 /** \brief Bind current process or thread on CPUs given in physical bitmap \p set. 1302 * 1303 * \return 0 on success. 1304 * \return -1 with errno set to \c ENOSYS if the action is not supported. 1305 * \return -1 with errno set to \c EXDEV if the binding cannot be enforced. 1306 */ 1307 HWLOC_DECLSPEC int hwloc_set_cpubind(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags); 1308 1309 /** \brief Get current process or thread binding. 1310 * 1311 * The CPU-set \p set (previously allocated by the caller) 1312 * is filled with the list of PUs which the process or 1313 * thread (according to \e flags) was last bound to. 1314 * 1315 * \return 0 on success, -1 on error. 1316 */ 1317 HWLOC_DECLSPEC int hwloc_get_cpubind(hwloc_topology_t topology, hwloc_cpuset_t set, int flags); 1318 1319 /** \brief Bind a process \p pid on CPUs given in physical bitmap \p set. 1320 * 1321 * \return 0 on success, -1 on error. 1322 * 1323 * \note \p hwloc_pid_t is \p pid_t on Unix platforms, 1324 * and \p HANDLE on native Windows platforms. 1325 * 1326 * \note As a special case on Linux, if a tid (thread ID) is supplied 1327 * instead of a pid (process ID) and ::HWLOC_CPUBIND_THREAD is passed in flags, 1328 * the binding is applied to that specific thread. 1329 * 1330 * \note On non-Linux systems, ::HWLOC_CPUBIND_THREAD can not be used in \p flags. 1331 */ 1332 HWLOC_DECLSPEC int hwloc_set_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t set, int flags); 1333 1334 /** \brief Get the current physical binding of process \p pid. 1335 * 1336 * The CPU-set \p set (previously allocated by the caller) 1337 * is filled with the list of PUs which the process 1338 * was last bound to. 1339 * 1340 * \return 0 on success, -1 on error. 1341 * 1342 * \note \p hwloc_pid_t is \p pid_t on Unix platforms, 1343 * and \p HANDLE on native Windows platforms. 1344 * 1345 * \note As a special case on Linux, if a tid (thread ID) is supplied 1346 * instead of a pid (process ID) and HWLOC_CPUBIND_THREAD is passed in flags, 1347 * the binding for that specific thread is returned. 1348 * 1349 * \note On non-Linux systems, HWLOC_CPUBIND_THREAD can not be used in \p flags. 1350 */ 1351 HWLOC_DECLSPEC int hwloc_get_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags); 1352 1353 #ifdef hwloc_thread_t 1354 /** \brief Bind a thread \p thread on CPUs given in physical bitmap \p set. 1355 * 1356 * \return 0 on success, -1 on error. 1357 * 1358 * \note \p hwloc_thread_t is \p pthread_t on Unix platforms, 1359 * and \p HANDLE on native Windows platforms. 1360 * 1361 * \note ::HWLOC_CPUBIND_PROCESS can not be used in \p flags. 1362 */ 1363 HWLOC_DECLSPEC int hwloc_set_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_const_cpuset_t set, int flags); 1364 #endif 1365 1366 #ifdef hwloc_thread_t 1367 /** \brief Get the current physical binding of thread \p tid. 1368 * 1369 * The CPU-set \p set (previously allocated by the caller) 1370 * is filled with the list of PUs which the thread 1371 * was last bound to. 1372 * 1373 * \return 0 on success, -1 on error. 1374 * 1375 * \note \p hwloc_thread_t is \p pthread_t on Unix platforms, 1376 * and \p HANDLE on native Windows platforms. 1377 * 1378 * \note ::HWLOC_CPUBIND_PROCESS can not be used in \p flags. 1379 */ 1380 HWLOC_DECLSPEC int hwloc_get_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_cpuset_t set, int flags); 1381 #endif 1382 1383 /** \brief Get the last physical CPU where the current process or thread ran. 1384 * 1385 * The CPU-set \p set (previously allocated by the caller) 1386 * is filled with the list of PUs which the process or 1387 * thread (according to \e flags) last ran on. 1388 * 1389 * The operating system may move some tasks from one processor 1390 * to another at any time according to their binding, 1391 * so this function may return something that is already 1392 * outdated. 1393 * 1394 * \p flags can include either ::HWLOC_CPUBIND_PROCESS or ::HWLOC_CPUBIND_THREAD to 1395 * specify whether the query should be for the whole process (union of all CPUs 1396 * on which all threads are running), or only the current thread. If the 1397 * process is single-threaded, flags can be set to zero to let hwloc use 1398 * whichever method is available on the underlying OS. 1399 * 1400 * \return 0 on success, -1 on error. 1401 */ 1402 HWLOC_DECLSPEC int hwloc_get_last_cpu_location(hwloc_topology_t topology, hwloc_cpuset_t set, int flags); 1403 1404 /** \brief Get the last physical CPU where a process ran. 1405 * 1406 * The CPU-set \p set (previously allocated by the caller) 1407 * is filled with the list of PUs which the process 1408 * last ran on. 1409 * 1410 * The operating system may move some tasks from one processor 1411 * to another at any time according to their binding, 1412 * so this function may return something that is already 1413 * outdated. 1414 * 1415 * \return 0 on success, -1 on error. 1416 * 1417 * \note \p hwloc_pid_t is \p pid_t on Unix platforms, 1418 * and \p HANDLE on native Windows platforms. 1419 * 1420 * \note As a special case on Linux, if a tid (thread ID) is supplied 1421 * instead of a pid (process ID) and ::HWLOC_CPUBIND_THREAD is passed in flags, 1422 * the last CPU location of that specific thread is returned. 1423 * 1424 * \note On non-Linux systems, ::HWLOC_CPUBIND_THREAD can not be used in \p flags. 1425 */ 1426 HWLOC_DECLSPEC int hwloc_get_proc_last_cpu_location(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags); 1427 1428 /** @} */ 1429 1430 1431 1432 /** \defgroup hwlocality_membinding Memory binding 1433 * 1434 * Memory binding can be done three ways: 1435 * 1436 * - explicit memory allocation thanks to hwloc_alloc_membind() and friends: 1437 * the binding will have effect on the memory allocated by these functions. 1438 * - implicit memory binding through binding policy: hwloc_set_membind() and 1439 * friends only define the current policy of the process, which will be 1440 * applied to the subsequent calls to malloc() and friends. 1441 * - migration of existing memory ranges, thanks to hwloc_set_area_membind() 1442 * and friends, which move already-allocated data. 1443 * 1444 * Not all operating systems support all three ways. 1445 * hwloc_topology_get_support() may be used to query about the actual memory 1446 * binding support in the currently used operating system. 1447 * 1448 * When the requested binding operation is not available and the 1449 * ::HWLOC_MEMBIND_STRICT flag was passed, the function returns -1. 1450 * \p errno will be set to \c ENOSYS when the system does support 1451 * the specified action or policy 1452 * (e.g., some systems only allow binding memory on a per-thread 1453 * basis, whereas other systems only allow binding memory for all 1454 * threads in a process). 1455 * \p errno will be set to \c EXDEV when the requested set can not be enforced 1456 * (e.g., some systems only allow binding memory to a single NUMA node). 1457 * 1458 * If ::HWLOC_MEMBIND_STRICT was not passed, the function may fail as well, 1459 * or the operating system may use a slightly different operation 1460 * (with side-effects, smaller binding set, etc.) 1461 * when the requested operation is not exactly supported. 1462 * 1463 * The most portable form that should be preferred over the others 1464 * whenever possible is as follows. 1465 * It allocates some memory hopefully bound to the specified set. 1466 * To do so, hwloc will possibly have to change the current memory 1467 * binding policy in order to actually get the memory bound, if the OS 1468 * does not provide any other way to simply allocate bound memory 1469 * without changing the policy for all allocations. That is the 1470 * difference with hwloc_alloc_membind(), which will never change the 1471 * current memory binding policy. 1472 * 1473 * \code 1474 * hwloc_alloc_membind_policy(topology, size, set, 1475 * HWLOC_MEMBIND_BIND, 0); 1476 * \endcode 1477 * 1478 * Each hwloc memory binding function takes a bitmap argument that 1479 * is a CPU set by default, or a NUMA memory node set if the flag 1480 * ::HWLOC_MEMBIND_BYNODESET is specified. 1481 * See \ref hwlocality_object_sets and \ref hwlocality_bitmap for a 1482 * discussion of CPU sets and NUMA memory node sets. 1483 * It is also possible to convert between CPU set and node set using 1484 * hwloc_cpuset_to_nodeset() or hwloc_cpuset_from_nodeset(). 1485 * 1486 * Memory binding by CPU set cannot work for CPU-less NUMA memory nodes. 1487 * Binding by nodeset should therefore be preferred whenever possible. 1488 * 1489 * \sa Some example codes are available under doc/examples/ in the source tree. 1490 * 1491 * \note On some operating systems, memory binding affects the CPU 1492 * binding; see ::HWLOC_MEMBIND_NOCPUBIND 1493 * @{ 1494 */ 1495 1496 /** \brief Memory binding policy. 1497 * 1498 * These constants can be used to choose the binding policy. Only one policy can 1499 * be used at a time (i.e., the values cannot be OR'ed together). 1500 * 1501 * Not all systems support all kinds of binding. 1502 * hwloc_topology_get_support() may be used to query about the actual memory 1503 * binding policy support in the currently used operating system. 1504 * See the "Detailed Description" section of \ref hwlocality_membinding 1505 * for a description of errors that can occur. 1506 */ 1507 typedef enum { 1508 /** \brief Reset the memory allocation policy to the system default. 1509 * Depending on the operating system, this may correspond to 1510 * ::HWLOC_MEMBIND_FIRSTTOUCH (Linux, FreeBSD), 1511 * or ::HWLOC_MEMBIND_BIND (AIX, HP-UX, Solaris, Windows). 1512 * This policy is never returned by get membind functions. 1513 * The nodeset argument is ignored. 1514 * \hideinitializer */ 1515 HWLOC_MEMBIND_DEFAULT = 0, 1516 1517 /** \brief Allocate each memory page individually on the local NUMA 1518 * node of the thread that touches it. 1519 * 1520 * The given nodeset should usually be hwloc_topology_get_topology_nodeset() 1521 * so that the touching thread may run and allocate on any node in the system. 1522 * 1523 * On AIX, if the nodeset is smaller, pages are allocated locally (if the local 1524 * node is in the nodeset) or from a random non-local node (otherwise). 1525 * \hideinitializer */ 1526 HWLOC_MEMBIND_FIRSTTOUCH = 1, 1527 1528 /** \brief Allocate memory on the specified nodes. 1529 * 1530 * The actual behavior may slightly vary between operating systems, 1531 * especially when (some of) the requested nodes are full. 1532 * On Linux, by default, the MPOL_PREFERRED_MANY (or MPOL_PREFERRED) policy 1533 * is used. However, if the hwloc strict flag is also given, the Linux 1534 * MPOL_BIND policy is rather used. 1535 * \hideinitializer */ 1536 HWLOC_MEMBIND_BIND = 2, 1537 1538 /** \brief Allocate memory on the given nodes in an interleaved 1539 * / round-robin manner. The precise layout of the memory across 1540 * multiple NUMA nodes is OS/system specific. Interleaving can be 1541 * useful when threads distributed across the specified NUMA nodes 1542 * will all be accessing the whole memory range concurrently, since 1543 * the interleave will then balance the memory references. 1544 * \hideinitializer */ 1545 HWLOC_MEMBIND_INTERLEAVE = 3, 1546 1547 /** \brief Allocate memory on the given nodes in an interleaved 1548 * / weighted manner. The precise layout of the memory across 1549 * multiple NUMA nodes is OS/system specific. Weighted interleaving 1550 * can be useful when threads distributed across the specified NUMA 1551 * nodes with different bandwidth capabilities will all be accessing 1552 * the whole memory range concurrently, since the interleave will then 1553 * balance the memory references. 1554 * \hideinitializer */ 1555 HWLOC_MEMBIND_WEIGHTED_INTERLEAVE = 5, 1556 1557 /** \brief For each page bound with this policy, by next time 1558 * it is touched (and next time only), it is moved from its current 1559 * location to the local NUMA node of the thread where the memory 1560 * reference occurred (if it needs to be moved at all). 1561 * \hideinitializer */ 1562 HWLOC_MEMBIND_NEXTTOUCH = 4, 1563 1564 /** \brief Returned by get_membind() functions when multiple 1565 * threads or parts of a memory area have differing memory binding 1566 * policies. 1567 * Also returned when binding is unknown because binding hooks are empty 1568 * when the topology is loaded from XML without HWLOC_THISSYSTEM=1, etc. 1569 * \hideinitializer */ 1570 HWLOC_MEMBIND_MIXED = -1 1571 } hwloc_membind_policy_t; 1572 1573 /** \brief Memory binding flags. 1574 * 1575 * These flags can be used to refine the binding policy. 1576 * All flags can be logically OR'ed together with the exception of 1577 * ::HWLOC_MEMBIND_PROCESS and ::HWLOC_MEMBIND_THREAD; 1578 * these two flags are mutually exclusive. 1579 * 1580 * Not all systems support all kinds of binding. 1581 * hwloc_topology_get_support() may be used to query about the actual memory 1582 * binding support in the currently used operating system. 1583 * See the "Detailed Description" section of \ref hwlocality_membinding 1584 * for a description of errors that can occur. 1585 */ 1586 typedef enum { 1587 /** \brief Set policy for all threads of the specified (possibly 1588 * multithreaded) process. This flag is mutually exclusive with 1589 * ::HWLOC_MEMBIND_THREAD. 1590 * \hideinitializer */ 1591 HWLOC_MEMBIND_PROCESS = (1<<0), 1592 1593 /** \brief Set policy for a specific thread of the current process. 1594 * This flag is mutually exclusive with ::HWLOC_MEMBIND_PROCESS. 1595 * \hideinitializer */ 1596 HWLOC_MEMBIND_THREAD = (1<<1), 1597 1598 /** Request strict binding from the OS. The function will fail if 1599 * the binding can not be guaranteed / completely enforced. 1600 * 1601 * This flag has slightly different meanings depending on which 1602 * function it is used with. 1603 * \hideinitializer */ 1604 HWLOC_MEMBIND_STRICT = (1<<2), 1605 1606 /** \brief Migrate existing allocated memory. If the memory cannot 1607 * be migrated and the ::HWLOC_MEMBIND_STRICT flag is passed, an error 1608 * will be returned. 1609 * \hideinitializer */ 1610 HWLOC_MEMBIND_MIGRATE = (1<<3), 1611 1612 /** \brief Avoid any effect on CPU binding. 1613 * 1614 * On some operating systems, some underlying memory binding 1615 * functions also bind the application to the corresponding CPU(s). 1616 * Using this flag will cause hwloc to avoid using OS functions that 1617 * could potentially affect CPU bindings. Note, however, that using 1618 * NOCPUBIND may reduce hwloc's overall memory binding 1619 * support. Specifically: some of hwloc's memory binding functions 1620 * may fail with errno set to \c ENOSYS when used with NOCPUBIND. 1621 * \hideinitializer 1622 */ 1623 HWLOC_MEMBIND_NOCPUBIND = (1<<4), 1624 1625 /** \brief Consider the bitmap argument as a nodeset. 1626 * 1627 * The bitmap argument is considered a nodeset if this flag is given, 1628 * or a cpuset otherwise by default. 1629 * 1630 * Memory binding by CPU set cannot work for CPU-less NUMA memory nodes. 1631 * Binding by nodeset should therefore be preferred whenever possible. 1632 * \hideinitializer 1633 */ 1634 HWLOC_MEMBIND_BYNODESET = (1<<5) 1635 } hwloc_membind_flags_t; 1636 1637 /** \brief Set the default memory binding policy of the current 1638 * process or thread to prefer the NUMA node(s) specified by \p set 1639 * 1640 * If neither ::HWLOC_MEMBIND_PROCESS nor ::HWLOC_MEMBIND_THREAD is 1641 * specified, the current process is assumed to be single-threaded. 1642 * This is the most portable form as it permits hwloc to use either 1643 * process-based OS functions or thread-based OS functions, depending 1644 * on which are available. 1645 * 1646 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset. 1647 * Otherwise it's a cpuset. 1648 * 1649 * \return 0 on success. 1650 * \return -1 with errno set to \c ENOSYS if the action is not supported. 1651 * \return -1 with errno set to \c EXDEV if the binding cannot be enforced. 1652 */ 1653 HWLOC_DECLSPEC int hwloc_set_membind(hwloc_topology_t topology, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags); 1654 1655 /** \brief Query the default memory binding policy and physical locality of the 1656 * current process or thread. 1657 * 1658 * The bitmap \p set (previously allocated by the caller) 1659 * is filled with the process or thread memory binding. 1660 * 1661 * This function has two output parameters: \p set and \p policy. 1662 * The values returned in these parameters depend on both the \p flags 1663 * passed in and the current memory binding policies and nodesets in 1664 * the queried target. 1665 * 1666 * Passing the ::HWLOC_MEMBIND_PROCESS flag specifies that the query 1667 * target is the current policies and nodesets for all the threads in 1668 * the current process. Passing ::HWLOC_MEMBIND_THREAD specifies that 1669 * the query target is the current policy and nodeset for only the 1670 * thread invoking this function. 1671 * 1672 * If neither of these flags are passed (which is the most portable 1673 * method), the process is assumed to be single threaded. This allows 1674 * hwloc to use either process-based OS functions or thread-based OS 1675 * functions, depending on which are available. 1676 * 1677 * ::HWLOC_MEMBIND_STRICT is only meaningful when ::HWLOC_MEMBIND_PROCESS 1678 * is also specified. In this case, hwloc will check the default 1679 * memory policies and nodesets for all threads in the process. If 1680 * they are not identical, -1 is returned and errno is set to \c EXDEV. 1681 * If they are identical, the values are returned in \p set and \p 1682 * policy. 1683 * 1684 * Otherwise, if ::HWLOC_MEMBIND_PROCESS is specified (and 1685 * ::HWLOC_MEMBIND_STRICT is \em not specified), the default set 1686 * from each thread is logically OR'ed together. 1687 * If all threads' default policies are the same, \p policy is set to 1688 * that policy. If they are different, \p policy is set to 1689 * ::HWLOC_MEMBIND_MIXED. 1690 * 1691 * In the ::HWLOC_MEMBIND_THREAD case (or when neither 1692 * ::HWLOC_MEMBIND_PROCESS or ::HWLOC_MEMBIND_THREAD is specified), there 1693 * is only one set and policy; they are returned in \p set and 1694 * \p policy, respectively. 1695 * 1696 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset. 1697 * Otherwise it's a cpuset. 1698 * 1699 * If any other flags are specified, -1 is returned and errno is set 1700 * to \c EINVAL. 1701 * 1702 * \return 0 on success, -1 on error. 1703 */ 1704 HWLOC_DECLSPEC int hwloc_get_membind(hwloc_topology_t topology, hwloc_bitmap_t set, hwloc_membind_policy_t * policy, int flags); 1705 1706 /** \brief Set the default memory binding policy of the specified 1707 * process to prefer the NUMA node(s) specified by \p set 1708 * 1709 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset. 1710 * Otherwise it's a cpuset. 1711 * 1712 * \return 0 on success. 1713 * \return -1 with errno set to \c ENOSYS if the action is not supported. 1714 * \return -1 with errno set to \c EXDEV if the binding cannot be enforced. 1715 * 1716 * \note \p hwloc_pid_t is \p pid_t on Unix platforms, 1717 * and \p HANDLE on native Windows platforms. 1718 */ 1719 HWLOC_DECLSPEC int hwloc_set_proc_membind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags); 1720 1721 /** \brief Query the default memory binding policy and physical locality of the 1722 * specified process. 1723 * 1724 * The bitmap \p set (previously allocated by the caller) 1725 * is filled with the process memory binding. 1726 * 1727 * This function has two output parameters: \p set and \p policy. 1728 * The values returned in these parameters depend on both the \p flags 1729 * passed in and the current memory binding policies and nodesets in 1730 * the queried target. 1731 * 1732 * Passing the ::HWLOC_MEMBIND_PROCESS flag specifies that the query 1733 * target is the current policies and nodesets for all the threads in 1734 * the specified process. If ::HWLOC_MEMBIND_PROCESS is not specified 1735 * (which is the most portable method), the process is assumed to be 1736 * single threaded. This allows hwloc to use either process-based OS 1737 * functions or thread-based OS functions, depending on which are 1738 * available. 1739 * 1740 * Note that it does not make sense to pass ::HWLOC_MEMBIND_THREAD to 1741 * this function. 1742 * 1743 * If ::HWLOC_MEMBIND_STRICT is specified, hwloc will check the default 1744 * memory policies and nodesets for all threads in the specified 1745 * process. If they are not identical, -1 is returned and errno is 1746 * set to \c EXDEV. If they are identical, the values are returned in \p 1747 * set and \p policy. 1748 * 1749 * Otherwise, \p set is set to the logical OR of all threads' 1750 * default set. If all threads' default policies 1751 * are the same, \p policy is set to that policy. If they are 1752 * different, \p policy is set to ::HWLOC_MEMBIND_MIXED. 1753 * 1754 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset. 1755 * Otherwise it's a cpuset. 1756 * 1757 * If any other flags are specified, -1 is returned and errno is set 1758 * to \c EINVAL. 1759 * 1760 * \return 0 on success, -1 on error. 1761 * 1762 * \note \p hwloc_pid_t is \p pid_t on Unix platforms, 1763 * and \p HANDLE on native Windows platforms. 1764 */ 1765 HWLOC_DECLSPEC int hwloc_get_proc_membind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_bitmap_t set, hwloc_membind_policy_t * policy, int flags); 1766 1767 /** \brief Bind the already-allocated memory identified by (addr, len) 1768 * to the NUMA node(s) specified by \p set. 1769 * 1770 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset. 1771 * Otherwise it's a cpuset. 1772 * 1773 * \return 0 on success or if \p len is 0. 1774 * \return -1 with errno set to \c ENOSYS if the action is not supported. 1775 * \return -1 with errno set to \c EXDEV if the binding cannot be enforced. 1776 */ 1777 HWLOC_DECLSPEC int hwloc_set_area_membind(hwloc_topology_t topology, const void *addr, size_t len, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags); 1778 1779 /** \brief Query the CPUs near the physical NUMA node(s) and binding policy of 1780 * the memory identified by (\p addr, \p len ). 1781 * 1782 * The bitmap \p set (previously allocated by the caller) 1783 * is filled with the memory area binding. 1784 * 1785 * This function has two output parameters: \p set and \p policy. 1786 * The values returned in these parameters depend on both the \p flags 1787 * passed in and the memory binding policies and nodesets of the pages 1788 * in the address range. 1789 * 1790 * If ::HWLOC_MEMBIND_STRICT is specified, the target pages are first 1791 * checked to see if they all have the same memory binding policy and 1792 * nodeset. If they do not, -1 is returned and errno is set to \c EXDEV. 1793 * If they are identical across all pages, the set and policy are 1794 * returned in \p set and \p policy, respectively. 1795 * 1796 * If ::HWLOC_MEMBIND_STRICT is not specified, the union of all NUMA 1797 * node(s) containing pages in the address range is calculated. 1798 * If all pages in the target have the same policy, it is returned in 1799 * \p policy. Otherwise, \p policy is set to ::HWLOC_MEMBIND_MIXED. 1800 * 1801 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset. 1802 * Otherwise it's a cpuset. 1803 * 1804 * If any other flags are specified, -1 is returned and errno is set 1805 * to \c EINVAL. 1806 * 1807 * \return 0 on success. 1808 * \return -1 with errno set to \c EINVAL if \p len is 0. 1809 */ 1810 HWLOC_DECLSPEC int hwloc_get_area_membind(hwloc_topology_t topology, const void *addr, size_t len, hwloc_bitmap_t set, hwloc_membind_policy_t * policy, int flags); 1811 1812 /** \brief Get the NUMA nodes where memory identified by (\p addr, \p len ) is physically allocated. 1813 * 1814 * The bitmap \p set (previously allocated by the caller) 1815 * is filled according to the NUMA nodes where the memory area pages 1816 * are physically allocated. If no page is actually allocated yet, 1817 * \p set may be empty. 1818 * 1819 * If pages spread to multiple nodes, it is not specified whether they spread 1820 * equitably, or whether most of them are on a single node, etc. 1821 * 1822 * The operating system may move memory pages from one processor 1823 * to another at any time according to their binding, 1824 * so this function may return something that is already 1825 * outdated. 1826 * 1827 * If ::HWLOC_MEMBIND_BYNODESET is specified in \p flags, set is 1828 * considered a nodeset. Otherwise it's a cpuset. 1829 * 1830 * If \p len is 0, \p set is emptied. 1831 * 1832 * \return 0 on success, -1 on error. 1833 */ 1834 HWLOC_DECLSPEC int hwloc_get_area_memlocation(hwloc_topology_t topology, const void *addr, size_t len, hwloc_bitmap_t set, int flags); 1835 1836 /** \brief Allocate some memory 1837 * 1838 * This is equivalent to malloc(), except that it tries to allocate 1839 * page-aligned memory from the OS. 1840 * 1841 * \return a pointer to the allocated area, or \c NULL on error. 1842 * 1843 * \note The allocated memory should be freed with hwloc_free(). 1844 */ 1845 HWLOC_DECLSPEC void *hwloc_alloc(hwloc_topology_t topology, size_t len); 1846 1847 /** \brief Allocate some memory on NUMA memory nodes specified by \p set 1848 * 1849 * \return a pointer to the allocated area. 1850 * \return NULL with errno set to \c ENOSYS if the action is not supported 1851 * and ::HWLOC_MEMBIND_STRICT is given. 1852 * \return NULL with errno set to \c EXDEV if the binding cannot be enforced 1853 * and ::HWLOC_MEMBIND_STRICT is given. 1854 * \return NULL with errno set to \c ENOMEM if the memory allocation failed 1855 * even before trying to bind. 1856 * 1857 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset. 1858 * Otherwise it's a cpuset. 1859 * 1860 * \note The allocated memory should be freed with hwloc_free(). 1861 */ 1862 HWLOC_DECLSPEC void *hwloc_alloc_membind(hwloc_topology_t topology, size_t len, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags) __hwloc_attribute_malloc; 1863 1864 /** \brief Allocate some memory on NUMA memory nodes specified by \p set 1865 * 1866 * First, try to allocate properly with hwloc_alloc_membind(). 1867 * On failure, the current process or thread memory binding policy 1868 * is changed with hwloc_set_membind() before allocating memory. 1869 * Thus this function works in more cases, at the expense of changing 1870 * the current state (possibly affecting future allocations that 1871 * would not specify any policy). 1872 * 1873 * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset. 1874 * Otherwise it's a cpuset. 1875 * 1876 * \return a pointer to the allocated area, or \c NULL on error. 1877 */ 1878 static __hwloc_inline void * 1879 hwloc_alloc_membind_policy(hwloc_topology_t topology, size_t len, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags) __hwloc_attribute_malloc; 1880 1881 /** \brief Free memory that was previously allocated by hwloc_alloc() 1882 * or hwloc_alloc_membind(). 1883 * 1884 * \return 0 on success, -1 on error. 1885 */ 1886 HWLOC_DECLSPEC int hwloc_free(hwloc_topology_t topology, void *addr, size_t len); 1887 1888 /** @} */ 1889 1890 1891 1892 /** \defgroup hwlocality_setsource Changing the Source of Topology Discovery 1893 * 1894 * These functions must be called between hwloc_topology_init() and hwloc_topology_load(). 1895 * Otherwise, they will return -1 with errno set to \c EBUSY. 1896 * 1897 * If none of the functions below is called, the default is to detect all the objects 1898 * of the machine that the caller is allowed to access. 1899 * 1900 * This default behavior may also be modified through environment variables 1901 * if the application did not modify it already. 1902 * Setting HWLOC_XMLFILE in the environment enforces the discovery from a XML 1903 * file as if hwloc_topology_set_xml() had been called. 1904 * Setting HWLOC_SYNTHETIC enforces a synthetic topology as if 1905 * hwloc_topology_set_synthetic() had been called. 1906 * 1907 * Finally, HWLOC_THISSYSTEM enforces the return value of 1908 * hwloc_topology_is_thissystem(). 1909 * 1910 * @{ 1911 */ 1912 1913 /** \brief Change which process the topology is viewed from. 1914 * 1915 * On some systems, processes may have different views of the machine, for 1916 * instance the set of allowed CPUs. By default, hwloc exposes the view from 1917 * the current process. Calling hwloc_topology_set_pid() permits to make it 1918 * expose the topology of the machine from the point of view of another 1919 * process. 1920 * 1921 * \note \p hwloc_pid_t is \p pid_t on Unix platforms, 1922 * and \p HANDLE on native Windows platforms. 1923 * 1924 * \note -1 is returned and errno is set to \c ENOSYS on platforms that do not 1925 * support this feature. 1926 * 1927 * \note The PID will not actually be used until hwloc_topology_load(). 1928 * If the corresponding process exits in the meantime, hwloc will ignore the PID. 1929 * If another process reuses the PID, the view of that process will be used. 1930 * 1931 * \return 0 on success, -1 on error. 1932 */ 1933 HWLOC_DECLSPEC int hwloc_topology_set_pid(hwloc_topology_t __hwloc_restrict topology, hwloc_pid_t pid); 1934 1935 /** \brief Enable synthetic topology. 1936 * 1937 * Gather topology information from the given \p description, 1938 * a space-separated string of <type:number> describing 1939 * the object type and arity at each level. 1940 * All types may be omitted (space-separated string of numbers) so that 1941 * hwloc chooses all types according to usual topologies. 1942 * See also the \ref synthetic. 1943 * 1944 * Setting the environment variable HWLOC_SYNTHETIC 1945 * may also result in this behavior. 1946 * 1947 * If \p description was properly parsed and describes a valid topology 1948 * configuration, this function returns 0. 1949 * Otherwise -1 is returned and errno is set to \c EINVAL. 1950 * 1951 * Note that this function does not actually load topology 1952 * information; it just tells hwloc where to load it from. You'll 1953 * still need to invoke hwloc_topology_load() to actually load the 1954 * topology information. 1955 * 1956 * \return 0 on success. 1957 * \return -1 with errno set to \c EINVAL if the description was invalid. 1958 * 1959 * \note For convenience, this backend provides empty binding hooks which just 1960 * return success. 1961 * 1962 * \note On success, the synthetic component replaces the previously enabled 1963 * component (if any), but the topology is not actually modified until 1964 * hwloc_topology_load(). 1965 */ 1966 HWLOC_DECLSPEC int hwloc_topology_set_synthetic(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict description); 1967 1968 /** \brief Enable XML-file based topology. 1969 * 1970 * Gather topology information from the XML file given at \p xmlpath. 1971 * Setting the environment variable HWLOC_XMLFILE may also result in this behavior. 1972 * This file may have been generated earlier with hwloc_topology_export_xml() in hwloc/export.h, 1973 * or lstopo file.xml. 1974 * 1975 * Note that this function does not actually load topology 1976 * information; it just tells hwloc where to load it from. You'll 1977 * still need to invoke hwloc_topology_load() to actually load the 1978 * topology information. 1979 * 1980 * \return 0 on success. 1981 * \return -1 with errno set to \c EINVAL on failure to read the XML file. 1982 * 1983 * \note See also hwloc_topology_set_userdata_import_callback() 1984 * for importing application-specific object userdata. 1985 * 1986 * \note For convenience, this backend provides empty binding hooks which just 1987 * return success. To have hwloc still actually call OS-specific hooks, the 1988 * ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM has to be set to assert that the loaded 1989 * file is really the underlying system. 1990 * 1991 * \note On success, the XML component replaces the previously enabled 1992 * component (if any), but the topology is not actually modified until 1993 * hwloc_topology_load(). 1994 * 1995 * \note If an invalid XML input file is given, the error may be reported 1996 * either here or later by hwloc_topology_load() depending on the XML library 1997 * used by hwloc. 1998 */ 1999 HWLOC_DECLSPEC int hwloc_topology_set_xml(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict xmlpath); 2000 2001 /** \brief Enable XML based topology using a memory buffer (instead of 2002 * a file, as with hwloc_topology_set_xml()). 2003 * 2004 * Gather topology information from the XML memory buffer given at 2005 * \p buffer and of length \p size (including an ending \0). 2006 * This buffer may have been filled earlier with 2007 * hwloc_topology_export_xmlbuffer() in hwloc/export.h. 2008 * 2009 * Note that this function does not actually load topology 2010 * information; it just tells hwloc where to load it from. You'll 2011 * still need to invoke hwloc_topology_load() to actually load the 2012 * topology information. 2013 * 2014 * \return 0 on success. 2015 * \return -1 with errno set to \c EINVAL on failure to read the XML buffer. 2016 * 2017 * \note See also hwloc_topology_set_userdata_import_callback() 2018 * for importing application-specific object userdata. 2019 * 2020 * \note For convenience, this backend provides empty binding hooks which just 2021 * return success. To have hwloc still actually call OS-specific hooks, the 2022 * ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM has to be set to assert that the loaded 2023 * file is really the underlying system. 2024 * 2025 * \note On success, the XML component replaces the previously enabled 2026 * component (if any), but the topology is not actually modified until 2027 * hwloc_topology_load(). 2028 * 2029 * \note If an invalid XML input file is given, the error may be reported 2030 * either here or later by hwloc_topology_load() depending on the XML library 2031 * used by hwloc. 2032 */ 2033 HWLOC_DECLSPEC int hwloc_topology_set_xmlbuffer(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict buffer, int size); 2034 2035 /** \brief Flags to be passed to hwloc_topology_set_components() 2036 */ 2037 enum hwloc_topology_components_flag_e { 2038 /** \brief Blacklist the target component from being used. 2039 * \hideinitializer 2040 */ 2041 HWLOC_TOPOLOGY_COMPONENTS_FLAG_BLACKLIST = (1UL<<0) 2042 }; 2043 2044 /** \brief Prevent a discovery component from being used for a topology. 2045 * 2046 * \p name is the name of the discovery component that should not be used 2047 * when loading topology \p topology. The name is a string such as "cuda". 2048 * 2049 * For components with multiple phases, it may also be suffixed with the name 2050 * of a phase, for instance "linux:io". 2051 * 2052 * \p flags should be ::HWLOC_TOPOLOGY_COMPONENTS_FLAG_BLACKLIST. 2053 * 2054 * This may be used to avoid expensive parts of the discovery process. 2055 * For instance, CUDA-specific discovery may be expensive and unneeded 2056 * while generic I/O discovery could still be useful. 2057 * 2058 * \return 0 on success. 2059 * \return -1 on error, for instance if flags are invalid. 2060 */ 2061 HWLOC_DECLSPEC int hwloc_topology_set_components(hwloc_topology_t __hwloc_restrict topology, unsigned long flags, const char * __hwloc_restrict name); 2062 2063 /** @} */ 2064 2065 2066 2067 /** \defgroup hwlocality_configuration Topology Detection Configuration and Query 2068 * 2069 * Several functions can optionally be called between hwloc_topology_init() and 2070 * hwloc_topology_load() to configure how the detection should be performed, 2071 * e.g. to ignore some objects types, define a synthetic topology, etc. 2072 * 2073 * @{ 2074 */ 2075 2076 /** \brief Flags to be set onto a topology context before load. 2077 * 2078 * Flags should be given to hwloc_topology_set_flags(). 2079 * They may also be returned by hwloc_topology_get_flags(). 2080 */ 2081 enum hwloc_topology_flags_e { 2082 /** \brief Detect the whole system, ignore reservations, include disallowed objects. 2083 * 2084 * Gather all online resources, even if some were disabled by the administrator. 2085 * For instance, ignore Linux Cgroup/Cpusets and gather all processors and memory nodes. 2086 * However offline PUs and NUMA nodes are still ignored. 2087 * 2088 * When this flag is not set, PUs and NUMA nodes that are disallowed are not added to the topology. 2089 * Parent objects (package, core, cache, etc.) are added only if some of their children are allowed. 2090 * All existing PUs and NUMA nodes in the topology are allowed. 2091 * hwloc_topology_get_allowed_cpuset() and hwloc_topology_get_allowed_nodeset() 2092 * are equal to the root object cpuset and nodeset. 2093 * 2094 * When this flag is set, the actual sets of allowed PUs and NUMA nodes are given 2095 * by hwloc_topology_get_allowed_cpuset() and hwloc_topology_get_allowed_nodeset(). 2096 * They may be smaller than the root object cpuset and nodeset. 2097 * 2098 * If the current topology is exported to XML and reimported later, this flag 2099 * should be set again in the reimported topology so that disallowed resources 2100 * are reimported as well. 2101 * \hideinitializer 2102 */ 2103 HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED = (1UL<<0), 2104 2105 /** \brief Assume that the selected backend provides the topology for the 2106 * system on which we are running. 2107 * 2108 * This forces hwloc_topology_is_thissystem() to return 1, i.e. makes hwloc assume that 2109 * the selected backend provides the topology for the system on which we are running, 2110 * even if it is not the OS-specific backend but the XML backend for instance. 2111 * This means making the binding functions actually call the OS-specific 2112 * system calls and really do binding, while the XML backend would otherwise 2113 * provide empty hooks just returning success. 2114 * 2115 * Setting the environment variable HWLOC_THISSYSTEM may also result in the 2116 * same behavior. 2117 * 2118 * This can be used for efficiency reasons to first detect the topology once, 2119 * save it to an XML file, and quickly reload it later through the XML 2120 * backend, but still having binding functions actually do bind. 2121 * \hideinitializer 2122 */ 2123 HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM = (1UL<<1), 2124 2125 /** \brief Get the set of allowed resources from the local operating system even if the topology was loaded from XML or synthetic description. 2126 * 2127 * If the topology was loaded from XML or from a synthetic string, 2128 * restrict it by applying the current process restrictions such as 2129 * Linux Cgroup/Cpuset. 2130 * 2131 * This is useful when the topology is not loaded directly from 2132 * the local machine (e.g. for performance reason) and it comes 2133 * with all resources, while the running process is restricted 2134 * to only parts of the machine. 2135 * 2136 * This flag is ignored unless ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM is 2137 * also set since the loaded topology must match the underlying machine 2138 * where restrictions will be gathered from. 2139 * 2140 * Setting the environment variable HWLOC_THISSYSTEM_ALLOWED_RESOURCES 2141 * would result in the same behavior. 2142 * \hideinitializer 2143 */ 2144 HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES = (1UL<<2), 2145 2146 /** \brief Import support from the imported topology. 2147 * 2148 * When importing a XML topology from a remote machine, binding is 2149 * disabled by default (see ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM). 2150 * This disabling is also marked by putting zeroes in the corresponding 2151 * supported feature bits reported by hwloc_topology_get_support(). 2152 * 2153 * The flag ::HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT actually imports 2154 * support bits from the remote machine. It also sets the flag 2155 * \p imported_support in the struct hwloc_topology_misc_support array. 2156 * If the imported XML did not contain any support information 2157 * (exporter hwloc is too old), this flag is not set. 2158 * 2159 * Note that these supported features are only relevant for the hwloc 2160 * installation that actually exported the XML topology 2161 * (it may vary with the operating system, or with how hwloc was compiled). 2162 * 2163 * Note that setting this flag however does not enable binding for the 2164 * locally imported hwloc topology, it only reports what the remote 2165 * hwloc and machine support. 2166 * 2167 */ 2168 HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT = (1UL<<3), 2169 2170 /** \brief Do not consider resources outside of the process CPU binding. 2171 * 2172 * If the binding of the process is limited to a subset of cores, 2173 * ignore the other cores during discovery. 2174 * 2175 * The resulting topology is identical to what a call to hwloc_topology_restrict() 2176 * would generate, but this flag also prevents hwloc from ever touching other 2177 * resources during the discovery. 2178 * 2179 * This flag especially tells the x86 backend to never temporarily 2180 * rebind a thread on any excluded core. This is useful on Windows 2181 * because such temporary rebinding can change the process binding. 2182 * Another use-case is to avoid cores that would not be able to 2183 * perform the hwloc discovery anytime soon because they are busy 2184 * executing some high-priority real-time tasks. 2185 * 2186 * If process CPU binding is not supported, 2187 * the thread CPU binding is considered instead if supported, 2188 * or the flag is ignored. 2189 * 2190 * This flag requires ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM as well 2191 * since binding support is required. 2192 */ 2193 HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING = (1UL<<4), 2194 2195 /** \brief Do not consider resources outside of the process memory binding. 2196 * 2197 * If the binding of the process is limited to a subset of NUMA nodes, 2198 * ignore the other NUMA nodes during discovery. 2199 * 2200 * The resulting topology is identical to what a call to hwloc_topology_restrict() 2201 * would generate, but this flag also prevents hwloc from ever touching other 2202 * resources during the discovery. 2203 * 2204 * This flag is meant to be used together with 2205 * ::HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING when both cores 2206 * and NUMA nodes should be ignored outside of the process binding. 2207 * 2208 * If process memory binding is not supported, 2209 * the thread memory binding is considered instead if supported, 2210 * or the flag is ignored. 2211 * 2212 * This flag requires ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM as well 2213 * since binding support is required. 2214 */ 2215 HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_MEMBINDING = (1UL<<5), 2216 2217 /** \brief Do not ever modify the process or thread binding during discovery. 2218 * 2219 * This flag disables all hwloc discovery steps that require a change of 2220 * the process or thread binding. This currently only affects the x86 2221 * backend which gets entirely disabled. 2222 * 2223 * This is useful when hwloc_topology_load() is called while the 2224 * application also creates additional threads or modifies the binding. 2225 * 2226 * This flag is also a strict way to make sure the process binding will 2227 * not change to due thread binding changes on Windows 2228 * (see ::HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING). 2229 */ 2230 HWLOC_TOPOLOGY_FLAG_DONT_CHANGE_BINDING = (1UL<<6), 2231 2232 /** \brief Ignore distances. 2233 * 2234 * Ignore distance information from the operating systems (and from XML) 2235 * and hence do not use distances for grouping. 2236 */ 2237 HWLOC_TOPOLOGY_FLAG_NO_DISTANCES = (1UL<<7), 2238 2239 /** \brief Ignore memory attributes and tiers. 2240 * 2241 * Ignore memory attribues from the operating systems (and from XML) 2242 * Hence also do not try to build memory tiers. 2243 */ 2244 HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS = (1UL<<8), 2245 2246 /** \brief Ignore CPU Kinds. 2247 * 2248 * Ignore CPU kind information from the operating systems (and from XML). 2249 */ 2250 HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS = (1UL<<9) 2251 }; 2252 2253 /** \brief Set OR'ed flags to non-yet-loaded topology. 2254 * 2255 * Set a OR'ed set of ::hwloc_topology_flags_e onto a topology that was not yet loaded. 2256 * 2257 * If this function is called multiple times, the last invocation will erase 2258 * and replace the set of flags that was previously set. 2259 * 2260 * By default, no flags are set (\c 0). 2261 * 2262 * The flags set in a topology may be retrieved with hwloc_topology_get_flags(). 2263 * 2264 * \return 0 on success. 2265 * \return -1 on error, for instance if flags are invalid. 2266 */ 2267 HWLOC_DECLSPEC int hwloc_topology_set_flags (hwloc_topology_t topology, unsigned long flags); 2268 2269 /** \brief Get OR'ed flags of a topology. 2270 * 2271 * Get the OR'ed set of ::hwloc_topology_flags_e of a topology. 2272 * 2273 * If hwloc_topology_set_flags() was not called earlier, 2274 * no flags are set (\c 0 is returned). 2275 * 2276 * \return the flags previously set with hwloc_topology_set_flags(). 2277 * 2278 * \note This function may also be called after hwloc_topology_load(). 2279 */ 2280 HWLOC_DECLSPEC unsigned long hwloc_topology_get_flags (hwloc_topology_t topology); 2281 2282 /** \brief Does the topology context come from this system? 2283 * 2284 * \return 1 if this topology context was built using the system 2285 * running this program. 2286 * \return 0 instead (for instance if using another file-system root, 2287 * a XML topology file, or a synthetic topology). 2288 * 2289 * \note This function may also be called after hwloc_topology_load(). 2290 */ 2291 HWLOC_DECLSPEC int hwloc_topology_is_thissystem(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure; 2292 2293 /** \brief Flags describing actual discovery support for this topology. */ 2294 struct hwloc_topology_discovery_support { 2295 /** \brief Detecting the number of PU objects is supported. */ 2296 unsigned char pu; 2297 /** \brief Detecting the number of NUMA nodes is supported. */ 2298 unsigned char numa; 2299 /** \brief Detecting the amount of memory in NUMA nodes is supported. */ 2300 unsigned char numa_memory; 2301 /** \brief Detecting and identifying PU objects that are not available to the current process is supported. */ 2302 unsigned char disallowed_pu; 2303 /** \brief Detecting and identifying NUMA nodes that are not available to the current process is supported. */ 2304 unsigned char disallowed_numa; 2305 /** \brief Detecting the efficiency of CPU kinds is supported, see \ref hwlocality_cpukinds. */ 2306 unsigned char cpukind_efficiency; 2307 }; 2308 2309 /** \brief Flags describing actual PU binding support for this topology. 2310 * 2311 * A flag may be set even if the feature isn't supported in all cases 2312 * (e.g. binding to random sets of non-contiguous objects). 2313 */ 2314 struct hwloc_topology_cpubind_support { 2315 /** Binding the whole current process is supported. */ 2316 unsigned char set_thisproc_cpubind; 2317 /** Getting the binding of the whole current process is supported. */ 2318 unsigned char get_thisproc_cpubind; 2319 /** Binding a whole given process is supported. */ 2320 unsigned char set_proc_cpubind; 2321 /** Getting the binding of a whole given process is supported. */ 2322 unsigned char get_proc_cpubind; 2323 /** Binding the current thread only is supported. */ 2324 unsigned char set_thisthread_cpubind; 2325 /** Getting the binding of the current thread only is supported. */ 2326 unsigned char get_thisthread_cpubind; 2327 /** Binding a given thread only is supported. */ 2328 unsigned char set_thread_cpubind; 2329 /** Getting the binding of a given thread only is supported. */ 2330 unsigned char get_thread_cpubind; 2331 /** Getting the last processors where the whole current process ran is supported */ 2332 unsigned char get_thisproc_last_cpu_location; 2333 /** Getting the last processors where a whole process ran is supported */ 2334 unsigned char get_proc_last_cpu_location; 2335 /** Getting the last processors where the current thread ran is supported */ 2336 unsigned char get_thisthread_last_cpu_location; 2337 }; 2338 2339 /** \brief Flags describing actual memory binding support for this topology. 2340 * 2341 * A flag may be set even if the feature isn't supported in all cases 2342 * (e.g. binding to random sets of non-contiguous objects). 2343 */ 2344 struct hwloc_topology_membind_support { 2345 /** Binding the whole current process is supported. */ 2346 unsigned char set_thisproc_membind; 2347 /** Getting the binding of the whole current process is supported. */ 2348 unsigned char get_thisproc_membind; 2349 /** Binding a whole given process is supported. */ 2350 unsigned char set_proc_membind; 2351 /** Getting the binding of a whole given process is supported. */ 2352 unsigned char get_proc_membind; 2353 /** Binding the current thread only is supported. */ 2354 unsigned char set_thisthread_membind; 2355 /** Getting the binding of the current thread only is supported. */ 2356 unsigned char get_thisthread_membind; 2357 /** Binding a given memory area is supported. */ 2358 unsigned char set_area_membind; 2359 /** Getting the binding of a given memory area is supported. */ 2360 unsigned char get_area_membind; 2361 /** Allocating a bound memory area is supported. */ 2362 unsigned char alloc_membind; 2363 /** First-touch policy is supported. */ 2364 unsigned char firsttouch_membind; 2365 /** Bind policy is supported. */ 2366 unsigned char bind_membind; 2367 /** Interleave policy is supported. */ 2368 unsigned char interleave_membind; 2369 /** Next-touch migration policy is supported. */ 2370 unsigned char nexttouch_membind; 2371 /** Migration flags is supported. */ 2372 unsigned char migrate_membind; 2373 /** Getting the last NUMA nodes where a memory area was allocated is supported */ 2374 unsigned char get_area_memlocation; 2375 /** Weighted interleave policy is supported. */ 2376 unsigned char weighted_interleave_membind; 2377 }; 2378 2379 /** \brief Flags describing miscellaneous features. 2380 */ 2381 struct hwloc_topology_misc_support { 2382 /** Support was imported when importing another topology, see ::HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT. */ 2383 unsigned char imported_support; 2384 }; 2385 2386 /** \brief Set of flags describing actual support for this topology. 2387 * 2388 * This is retrieved with hwloc_topology_get_support() and will be valid until 2389 * the topology object is destroyed. Note: the values are correct only after 2390 * discovery. 2391 */ 2392 struct hwloc_topology_support { 2393 struct hwloc_topology_discovery_support *discovery; 2394 struct hwloc_topology_cpubind_support *cpubind; 2395 struct hwloc_topology_membind_support *membind; 2396 struct hwloc_topology_misc_support *misc; 2397 }; 2398 2399 /** \brief Retrieve the topology support. 2400 * 2401 * Each flag indicates whether a feature is supported. 2402 * If set to 0, the feature is not supported. 2403 * If set to 1, the feature is supported, but the corresponding 2404 * call may still fail in some corner cases. 2405 * 2406 * These features are also listed by hwloc-info \--support 2407 * 2408 * The reported features are what the current topology supports 2409 * on the current machine. If the topology was exported to XML 2410 * from another machine and later imported here, support still 2411 * describes what is supported for this imported topology after 2412 * import. By default, binding will be reported as unsupported 2413 * in this case (see ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM). 2414 * 2415 * Topology flag ::HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT may be used 2416 * to report the supported features of the original remote machine 2417 * instead. If it was successfully imported, \p imported_support 2418 * will be set in the struct hwloc_topology_misc_support array. 2419 * 2420 * \return A pointer to a support structure. 2421 * 2422 * \note The function cannot return \c NULL. 2423 * \note The returned pointer should not be freed, it belongs to the hwloc library. 2424 * 2425 * \note This function may be called before or after hwloc_topology_load() 2426 * but the support structure only contains valid information after. 2427 */ 2428 HWLOC_DECLSPEC const struct hwloc_topology_support *hwloc_topology_get_support(hwloc_topology_t __hwloc_restrict topology); 2429 2430 /** \brief Type filtering flags. 2431 * 2432 * By default, most objects are kept (::HWLOC_TYPE_FILTER_KEEP_ALL). 2433 * Instruction caches, memory-side caches, I/O and Misc objects are ignored by default (::HWLOC_TYPE_FILTER_KEEP_NONE). 2434 * Group levels are ignored unless they bring structure (::HWLOC_TYPE_FILTER_KEEP_STRUCTURE). 2435 * 2436 * Note that group objects are also ignored individually (without the entire level) 2437 * when they do not bring structure. 2438 */ 2439 enum hwloc_type_filter_e { 2440 /** \brief Keep all objects of this type. 2441 * 2442 * Cannot be set for ::HWLOC_OBJ_GROUP (groups are designed only to add more structure to the topology). 2443 * \hideinitializer 2444 */ 2445 HWLOC_TYPE_FILTER_KEEP_ALL = 0, 2446 2447 /** \brief Ignore all objects of this type. 2448 * 2449 * The bottom-level type ::HWLOC_OBJ_PU, the ::HWLOC_OBJ_NUMANODE type, and 2450 * the top-level type ::HWLOC_OBJ_MACHINE may not be ignored. 2451 * \hideinitializer 2452 */ 2453 HWLOC_TYPE_FILTER_KEEP_NONE = 1, 2454 2455 /** \brief Only ignore objects if their entire level does not bring any structure. 2456 * 2457 * Keep the entire level of objects if at least one of these objects adds 2458 * structure to the topology. An object brings structure when it has multiple 2459 * children and it is not the only child of its parent. 2460 * 2461 * If all objects in the level are the only child of their parent, and if none 2462 * of them has multiple children, the entire level is removed. 2463 * 2464 * Cannot be set for I/O and Misc objects since the topology structure does not matter there. 2465 * \hideinitializer 2466 */ 2467 HWLOC_TYPE_FILTER_KEEP_STRUCTURE = 2, 2468 2469 /** \brief Only keep likely-important objects of the given type. 2470 * 2471 * It is only useful for I/O object types. 2472 * For ::HWLOC_OBJ_PCI_DEVICE and ::HWLOC_OBJ_OS_DEVICE, it means that only objects 2473 * of major/common kinds are kept (storage, network, OpenFabrics, CUDA, 2474 * OpenCL, RSMI, NVML, and displays). 2475 * Also, only OS devices directly attached on PCI (e.g. no USB) are reported. 2476 * For ::HWLOC_OBJ_BRIDGE, it means that bridges are kept only if they have children. 2477 * 2478 * This flag equivalent to ::HWLOC_TYPE_FILTER_KEEP_ALL for Normal, Memory and Misc types 2479 * since they are likely important. 2480 * \hideinitializer 2481 */ 2482 HWLOC_TYPE_FILTER_KEEP_IMPORTANT = 3 2483 }; 2484 2485 /** \brief Set the filtering for the given object type. 2486 * 2487 * \return 0 on success, -1 on error. 2488 */ 2489 HWLOC_DECLSPEC int hwloc_topology_set_type_filter(hwloc_topology_t topology, hwloc_obj_type_t type, enum hwloc_type_filter_e filter); 2490 2491 /** \brief Get the current filtering for the given object type. 2492 * 2493 * \return 0 on success, -1 on error. 2494 */ 2495 HWLOC_DECLSPEC int hwloc_topology_get_type_filter(hwloc_topology_t topology, hwloc_obj_type_t type, enum hwloc_type_filter_e *filter); 2496 2497 /** \brief Set the filtering for all object types. 2498 * 2499 * If some types do not support this filtering, they are silently ignored. 2500 * 2501 * \return 0 on success, -1 on error. 2502 */ 2503 HWLOC_DECLSPEC int hwloc_topology_set_all_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter); 2504 2505 /** \brief Set the filtering for all CPU cache object types. 2506 * 2507 * Memory-side caches are not involved since they are not CPU caches. 2508 * 2509 * \return 0 on success, -1 on error. 2510 */ 2511 HWLOC_DECLSPEC int hwloc_topology_set_cache_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter); 2512 2513 /** \brief Set the filtering for all CPU instruction cache object types. 2514 * 2515 * Memory-side caches are not involved since they are not CPU caches. 2516 * 2517 * \return 0 on success, -1 on error. 2518 */ 2519 HWLOC_DECLSPEC int hwloc_topology_set_icache_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter); 2520 2521 /** \brief Set the filtering for all I/O object types. 2522 * 2523 * \return 0 on success, -1 on error. 2524 */ 2525 HWLOC_DECLSPEC int hwloc_topology_set_io_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter); 2526 2527 /** \brief Set the topology-specific userdata pointer. 2528 * 2529 * Each topology may store one application-given private data pointer. 2530 * It is initialized to \c NULL. 2531 * hwloc will never modify it. 2532 * 2533 * Use it as you wish, after hwloc_topology_init() and until hwloc_topolog_destroy(). 2534 * 2535 * This pointer is not exported to XML. 2536 */ 2537 HWLOC_DECLSPEC void hwloc_topology_set_userdata(hwloc_topology_t topology, const void *userdata); 2538 2539 /** \brief Retrieve the topology-specific userdata pointer. 2540 * 2541 * Retrieve the application-given private data pointer that was 2542 * previously set with hwloc_topology_set_userdata(). 2543 * 2544 * \return A pointer to the private-data if any. 2545 * \return \c NULL if no private-data was previoulsy set. 2546 */ 2547 HWLOC_DECLSPEC void * hwloc_topology_get_userdata(hwloc_topology_t topology); 2548 2549 /** @} */ 2550 2551 2552 2553 /** \defgroup hwlocality_tinker Modifying a loaded Topology 2554 * @{ 2555 */ 2556 2557 /** \brief Flags to be given to hwloc_topology_restrict(). */ 2558 enum hwloc_restrict_flags_e { 2559 /** \brief Remove all objects that became CPU-less. 2560 * By default, only objects that contain no PU and no memory are removed. 2561 * This flag may not be used with ::HWLOC_RESTRICT_FLAG_BYNODESET. 2562 * \hideinitializer 2563 */ 2564 HWLOC_RESTRICT_FLAG_REMOVE_CPULESS = (1UL<<0), 2565 2566 /** \brief Restrict by nodeset instead of CPU set. 2567 * Only keep objects whose nodeset is included or partially included in the given set. 2568 * This flag may not be used with ::HWLOC_RESTRICT_FLAG_REMOVE_CPULESS. 2569 */ 2570 HWLOC_RESTRICT_FLAG_BYNODESET = (1UL<<3), 2571 2572 /** \brief Remove all objects that became Memory-less. 2573 * By default, only objects that contain no PU and no memory are removed. 2574 * This flag may only be used with ::HWLOC_RESTRICT_FLAG_BYNODESET. 2575 * \hideinitializer 2576 */ 2577 HWLOC_RESTRICT_FLAG_REMOVE_MEMLESS = (1UL<<4), 2578 2579 /** \brief Move Misc objects to ancestors if their parents are removed during restriction. 2580 * If this flag is not set, Misc objects are removed when their parents are removed. 2581 * \hideinitializer 2582 */ 2583 HWLOC_RESTRICT_FLAG_ADAPT_MISC = (1UL<<1), 2584 2585 /** \brief Move I/O objects to ancestors if their parents are removed during restriction. 2586 * If this flag is not set, I/O devices and bridges are removed when their parents are removed. 2587 * \hideinitializer 2588 */ 2589 HWLOC_RESTRICT_FLAG_ADAPT_IO = (1UL<<2) 2590 }; 2591 2592 /** \brief Restrict the topology to the given CPU set or nodeset. 2593 * 2594 * Topology \p topology is modified so as to remove all objects that 2595 * are not included (or partially included) in the CPU set \p set. 2596 * All objects CPU and node sets are restricted accordingly. 2597 * 2598 * By default, \p set is a CPU set. It means that the set of PUs in 2599 * the topology is restricted. Once some PUs got removed, their parents 2600 * may also get removed recursively if they became child-less. 2601 * 2602 * If ::HWLOC_RESTRICT_FLAG_BYNODESET is passed in \p flags, 2603 * \p set is considered a nodeset instead of a CPU set. 2604 * It means that the set of NUMA nodes in the topology is restricted 2605 * (instead of PUs). Once some NUMA nodes got removed, their parents 2606 * may also get removed recursively if they became child-less. 2607 * 2608 * \p flags is a OR'ed set of ::hwloc_restrict_flags_e. 2609 * 2610 * \note Restricting the topology removes some locality information, 2611 * hence the remaining objects may get reordered (including PUs and NUMA nodes), 2612 * and their logical indexes may change. 2613 * 2614 * \note This call may not be reverted by restricting back to a larger 2615 * set. Once dropped during restriction, objects may not be brought 2616 * back, except by loading another topology with hwloc_topology_load(). 2617 * 2618 * \return 0 on success. 2619 * 2620 * \return -1 with errno set to \c EINVAL if the input set is invalid. 2621 * The topology is not modified in this case. 2622 * 2623 * \return -1 with errno set to \c ENOMEM on failure to allocate internal data. 2624 * The topology is reinitialized in this case. It should be either 2625 * destroyed with hwloc_topology_destroy() or configured and loaded again. 2626 */ 2627 HWLOC_DECLSPEC int hwloc_topology_restrict(hwloc_topology_t __hwloc_restrict topology, hwloc_const_bitmap_t set, unsigned long flags); 2628 2629 /** \brief Flags to be given to hwloc_topology_allow(). */ 2630 enum hwloc_allow_flags_e { 2631 /** \brief Mark all objects as allowed in the topology. 2632 * 2633 * \p cpuset and \p nođeset given to hwloc_topology_allow() must be \c NULL. 2634 * \hideinitializer */ 2635 HWLOC_ALLOW_FLAG_ALL = (1UL<<0), 2636 2637 /** \brief Only allow objects that are available to the current process. 2638 * 2639 * The topology must have ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM so that the set 2640 * of available resources can actually be retrieved from the operating system. 2641 * 2642 * \p cpuset and \p nođeset given to hwloc_topology_allow() must be \c NULL. 2643 * \hideinitializer */ 2644 HWLOC_ALLOW_FLAG_LOCAL_RESTRICTIONS = (1UL<<1), 2645 2646 /** \brief Allow a custom set of objects, given to hwloc_topology_allow() as \p cpuset and/or \p nodeset parameters. 2647 * \hideinitializer */ 2648 HWLOC_ALLOW_FLAG_CUSTOM = (1UL<<2) 2649 }; 2650 2651 /** \brief Change the sets of allowed PUs and NUMA nodes in the topology. 2652 * 2653 * This function only works if the ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED 2654 * was set on the topology. It does not modify any object, it only changes 2655 * the sets returned by hwloc_topology_get_allowed_cpuset() and 2656 * hwloc_topology_get_allowed_nodeset(). 2657 * 2658 * It is notably useful when importing a topology from another process 2659 * running in a different Linux Cgroup. 2660 * 2661 * \p flags must be set to one flag among ::hwloc_allow_flags_e. 2662 * 2663 * \return 0 on success, -1 on error. 2664 * 2665 * \note Removing objects from a topology should rather be performed with 2666 * hwloc_topology_restrict(). 2667 */ 2668 HWLOC_DECLSPEC int hwloc_topology_allow(hwloc_topology_t __hwloc_restrict topology, hwloc_const_cpuset_t cpuset, hwloc_const_nodeset_t nodeset, unsigned long flags); 2669 2670 /** \brief Add a MISC object as a leaf of the topology 2671 * 2672 * A new MISC object will be created and inserted into the topology at the 2673 * position given by parent. It is appended to the list of existing Misc children, 2674 * without ever adding any intermediate hierarchy level. This is useful for 2675 * annotating the topology without actually changing the hierarchy. 2676 * 2677 * \p name is supposed to be unique across all Misc objects in the topology. 2678 * It will be duplicated to setup the new object attributes. 2679 * 2680 * The new leaf object will not have any \p cpuset. 2681 * 2682 * The \p subtype object attribute may be defined with hwloc_obj_set_subtype() 2683 * after successful insertion. 2684 * 2685 * \return the newly-created object 2686 * 2687 * \return \c NULL on error. 2688 * 2689 * \return \c NULL if Misc objects are filtered-out of the topology (::HWLOC_TYPE_FILTER_KEEP_NONE). 2690 * 2691 * \note If \p name contains some non-printable characters, they will 2692 * be dropped when exporting to XML, see hwloc_topology_export_xml() in hwloc/export.h. 2693 */ 2694 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_misc_object(hwloc_topology_t topology, hwloc_obj_t parent, const char *name); 2695 2696 /** \brief Allocate a Group object to insert later with hwloc_topology_insert_group_object(). 2697 * 2698 * This function returns a new Group object. 2699 * 2700 * The caller should (at least) initialize its sets before inserting 2701 * the object in the topology, see hwloc_topology_insert_group_object(). 2702 * Or it may decide not to insert and just free the group object 2703 * by calling hwloc_topology_free_group_object(). 2704 * 2705 * \return The allocated object on success. 2706 * \return \c NULL on error. 2707 * 2708 * \note If successfully inserted by hwloc_topology_insert_group_object(), 2709 * the object will be freed when the entire topology is freed. 2710 * If insertion failed (e.g. \c NULL or empty CPU and node-sets), 2711 * it is freed before returning the error. 2712 */ 2713 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_alloc_group_object(hwloc_topology_t topology); 2714 2715 /** \brief Free a group object allocated with hwloc_topology_alloc_group_object(). 2716 * 2717 * This function is only useful if the group object was not given 2718 * to hwloc_topology_insert_group_object() as planned. 2719 * 2720 * \note \p topology must be the same as the one previously passed 2721 * to hwloc_topology_alloc_group_object(). 2722 * 2723 * \return \c 0 on success. 2724 * \return \c -1 on error, for instance if an invalid topology is given. 2725 */ 2726 HWLOC_DECLSPEC int hwloc_topology_free_group_object(hwloc_topology_t topology, hwloc_obj_t group); 2727 2728 /** \brief Add more structure to the topology by adding an intermediate Group 2729 * 2730 * The caller should first allocate a new Group object with hwloc_topology_alloc_group_object(). 2731 * Then it must setup at least one of its CPU or node sets to specify 2732 * the final location of the Group in the topology. 2733 * Then the object can be passed to this function for actual insertion in the topology. 2734 * 2735 * The main use case for this function is to group a subset of 2736 * siblings among the list of children below a single parent. 2737 * For instance, if grouping 4 cores out of a 8-core socket, 2738 * the logical list of cores will be reordered so that the 4 grouped 2739 * ones are consecutive. 2740 * Then, if needed, a new depth is added between the parent and those 2741 * children, and the Group is inserted there. 2742 * At the end, the 4 grouped cores are now children of the Group, 2743 * which replaces them as a child of the original parent. 2744 * 2745 * In practice, the grouped objects are specified through cpusets 2746 * and/or nodesets, for instance using hwloc_obj_add_other_obj_sets() 2747 * iteratively. 2748 * Hence it is possible to group objects that are not children of the 2749 * same parent, for instance some PUs below the 4 cores in example above. 2750 * However this general case may fail if the expected Group conflicts 2751 * with the existing hierarchy. 2752 * For instance if each core has two PUs, it is not possible to insert 2753 * a Group containing a single PU of each core. 2754 * 2755 * To specify the objects to group, either the cpuset or nodeset field 2756 * (or both, if compatible) must be set to a non-empty bitmap. 2757 * The complete_cpuset or complete_nodeset may be set instead if 2758 * inserting with respect to the complete topology 2759 * (including disallowed, offline or unknown objects). 2760 * These sets cannot be larger than the current topology, or they would get 2761 * restricted silently. 2762 * The core will setup the other sets after actual insertion. 2763 * 2764 * The \p subtype object attribute may be defined with hwloc_obj_set_subtype() 2765 * to display something else than "Group" as the type name for this object in lstopo. 2766 * Custom name-value info pairs may be added with hwloc_obj_add_info() after 2767 * insertion. 2768 * 2769 * The group \p dont_merge attribute may be set to \c 1 to prevent 2770 * the hwloc core from ever merging this object with another 2771 * hierarchically-identical object. 2772 * This is useful when the Group itself describes an important feature 2773 * that cannot be exposed anywhere else in the hierarchy. 2774 * 2775 * The group \p kind attribute may be set to a high value such 2776 * as \c 0xffffffff to tell hwloc that this new Group should always 2777 * be discarded in favor of any existing Group with the same locality. 2778 * 2779 * \note Inserting a group adds some locality information to the topology, 2780 * hence the existing objects may get reordered (including PUs and NUMA nodes), 2781 * and their logical indexes may change. 2782 * 2783 * \note If the insertion fails, the input group object is freed. 2784 * 2785 * \note If the group object should be discarded instead of inserted, 2786 * it may be passed to hwloc_topology_free_group_object() instead. 2787 * 2788 * \note \p topology must be the same as the one previously passed 2789 * to hwloc_topology_alloc_group_object(). 2790 * 2791 * \return The inserted object if it was properly inserted. 2792 * 2793 * \return An existing object if the Group was merged or discarded 2794 * because the topology already contained an object at the same 2795 * location (the Group did not add any hierarchy information). 2796 * 2797 * \return \c NULL if the insertion failed because of conflicting sets in topology tree. 2798 * 2799 * \return \c NULL if Group objects are filtered-out of the topology (::HWLOC_TYPE_FILTER_KEEP_NONE). 2800 * 2801 * \return \c NULL if the object was discarded because no set was 2802 * initialized in the Group before insert, or all of them were empty. 2803 */ 2804 HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_group_object(hwloc_topology_t topology, hwloc_obj_t group); 2805 2806 /** \brief Setup object cpusets/nodesets by OR'ing another object's sets. 2807 * 2808 * For each defined cpuset or nodeset in \p src, allocate the corresponding set 2809 * in \p dst and add \p src to it by OR'ing sets. 2810 * 2811 * This function is convenient between hwloc_topology_alloc_group_object() 2812 * and hwloc_topology_insert_group_object(). It builds the sets of the new Group 2813 * that will be inserted as a new intermediate parent of several objects. 2814 * 2815 * \return 0 on success. 2816 * \return -1 with errno set to \c ENOMEM if some internal reallocation failed. 2817 */ 2818 HWLOC_DECLSPEC int hwloc_obj_add_other_obj_sets(hwloc_obj_t dst, hwloc_obj_t src); 2819 2820 /** \brief Refresh internal structures after topology modification. 2821 * 2822 * Modifying the topology (by restricting, adding objects, modifying structures 2823 * such as distances or memory attributes, etc.) may cause some internal caches 2824 * to become invalid. These caches are automatically refreshed when accessed 2825 * but this refreshing is not thread-safe. 2826 * 2827 * This function is not thread-safe either, but it is a good way to end a 2828 * non-thread-safe phase of topology modification. Once this refresh is done, 2829 * multiple threads may concurrently consult the topology, objects, distances, 2830 * attributes, etc. 2831 * 2832 * See also \ref threadsafety 2833 * 2834 * \return 0 on success. 2835 * \return -1 on error, for instance if some internal reallocation failed. 2836 */ 2837 HWLOC_DECLSPEC int hwloc_topology_refresh(hwloc_topology_t topology); 2838 2839 /** @} */ 2840 2841 2842 2843 #ifdef __cplusplus 2844 } /* extern "C" */ 2845 #endif 2846 2847 2848 /* high-level helpers */ 2849 #include "hwloc/helper.h" 2850 2851 /* inline code of some functions above */ 2852 #include "hwloc/inlines.h" 2853 2854 /* memory attributes */ 2855 #include "hwloc/memattrs.h" 2856 2857 /* kinds of CPU cores */ 2858 #include "hwloc/cpukinds.h" 2859 2860 /* exporting to XML or synthetic */ 2861 #include "hwloc/export.h" 2862 2863 /* distances */ 2864 #include "hwloc/distances.h" 2865 2866 /* topology diffs */ 2867 #include "hwloc/diff.h" 2868 2869 /* deprecated headers */ 2870 #include "hwloc/deprecated.h" 2871 2872 #endif /* HWLOC_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|