hwloc.h 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755
  1. /*
  2. * Copyright © 2009 CNRS
  3. * Copyright © 2009-2022 Inria. All rights reserved.
  4. * Copyright © 2009-2012 Université Bordeaux
  5. * Copyright © 2009-2020 Cisco Systems, Inc. All rights reserved.
  6. * See COPYING in top-level directory.
  7. */
  8. /*=====================================================================
  9. * PLEASE GO READ THE DOCUMENTATION!
  10. * ------------------------------------------------
  11. * $tarball_directory/doc/doxygen-doc/
  12. * or
  13. * https://www.open-mpi.org/projects/hwloc/doc/
  14. *=====================================================================
  15. *
  16. * FAIR WARNING: Do NOT expect to be able to figure out all the
  17. * subtleties of hwloc by simply reading function prototypes and
  18. * constant descrptions here in this file.
  19. *
  20. * Hwloc has wonderful documentation in both PDF and HTML formats for
  21. * your reading pleasure. The formal documentation explains a LOT of
  22. * hwloc-specific concepts, provides definitions, and discusses the
  23. * "big picture" for many of the things that you'll find here in this
  24. * header file.
  25. *
  26. * The PDF/HTML documentation was generated via Doxygen; much of what
  27. * you'll see in there is also here in this file. BUT THERE IS A LOT
  28. * THAT IS IN THE PDF/HTML THAT IS ***NOT*** IN hwloc.h!
  29. *
  30. * There are entire paragraph-length descriptions, discussions, and
  31. * pretty pictures to explain subtle corner cases, provide concrete
  32. * examples, etc.
  33. *
  34. * Please, go read the documentation. :-)
  35. *
  36. * Moreover there are several examples of hwloc use under doc/examples
  37. * in the source tree.
  38. *
  39. *=====================================================================*/
  40. /** \file
  41. * \brief The hwloc API.
  42. *
  43. * See hwloc/bitmap.h for bitmap specific macros.
  44. * See hwloc/helper.h for high-level topology traversal helpers.
  45. * See hwloc/inlines.h for the actual inline code of some functions below.
  46. * See hwloc/export.h for exporting topologies to XML or to synthetic descriptions.
  47. * See hwloc/distances.h for querying and modifying distances between objects.
  48. * See hwloc/diff.h for manipulating differences between similar topologies.
  49. */
  50. #ifndef HWLOC_H
  51. #define HWLOC_H
  52. #include "hwloc/autogen/config.h"
  53. #include <sys/types.h>
  54. #include <stdio.h>
  55. #include <string.h>
  56. #include <limits.h>
  57. /*
  58. * Symbol transforms
  59. */
  60. #include "hwloc/rename.h"
  61. /*
  62. * Bitmap definitions
  63. */
  64. #include "hwloc/bitmap.h"
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. /** \defgroup hwlocality_api_error_reporting Error reporting in the API
  69. * @{
  70. * Most functions in the hwloc API return an integer value.
  71. * Unless documentated differently, they return 0 on success
  72. * and -1 on error.
  73. * Functions that return a pointer type return \c NULL on error.
  74. *
  75. * \p errno will be set to a meaningful value whenever possible.
  76. * This includes the usual \c EINVAL when invalid function parameters are passed
  77. * or \c ENOMEM when an internal allocation fails.
  78. * Some specific \c errno value are also used, for instance for binding
  79. * errors as documented in \ref hwlocality_cpubinding.
  80. *
  81. * Some modules describe return values of their functions
  82. * in their introduction, for instance in \ref hwlocality_bitmap.
  83. * @}
  84. */
  85. /** \defgroup hwlocality_api_version API version
  86. * @{
  87. */
  88. /** \brief Indicate at build time which hwloc API version is being used.
  89. *
  90. * This number is updated to (X<<16)+(Y<<8)+Z when a new release X.Y.Z
  91. * actually modifies the API.
  92. *
  93. * Users may check for available features at build time using this number
  94. * (see \ref faq_version_api).
  95. *
  96. * \note This should not be confused with HWLOC_VERSION, the library version.
  97. * Two stable releases of the same series usually have the same ::HWLOC_API_VERSION
  98. * even if their HWLOC_VERSION are different.
  99. */
  100. #define HWLOC_API_VERSION 0x00020800
  101. /** \brief Indicate at runtime which hwloc API version was used at build time.
  102. *
  103. * Should be ::HWLOC_API_VERSION if running on the same version.
  104. *
  105. * \return the build-time version number.
  106. */
  107. HWLOC_DECLSPEC unsigned hwloc_get_api_version(void);
  108. /** \brief Current component and plugin ABI version (see hwloc/plugins.h) */
  109. #define HWLOC_COMPONENT_ABI 7
  110. /** @} */
  111. /** \defgroup hwlocality_object_sets Object Sets (hwloc_cpuset_t and hwloc_nodeset_t)
  112. *
  113. * Hwloc uses bitmaps to represent two distinct kinds of object sets:
  114. * CPU sets (::hwloc_cpuset_t) and NUMA node sets (::hwloc_nodeset_t).
  115. * These types are both typedefs to a common back end type
  116. * (::hwloc_bitmap_t), and therefore all the hwloc bitmap functions
  117. * are applicable to both ::hwloc_cpuset_t and ::hwloc_nodeset_t (see
  118. * \ref hwlocality_bitmap).
  119. *
  120. * The rationale for having two different types is that even though
  121. * the actions one wants to perform on these types are the same (e.g.,
  122. * enable and disable individual items in the set/mask), they're used
  123. * in very different contexts: one for specifying which processors to
  124. * use and one for specifying which NUMA nodes to use. Hence, the
  125. * name difference is really just to reflect the intent of where the
  126. * type is used.
  127. *
  128. * @{
  129. */
  130. /** \brief A CPU set is a bitmap whose bits are set according to CPU
  131. * physical OS indexes.
  132. *
  133. * It may be consulted and modified with the bitmap API as any
  134. * ::hwloc_bitmap_t (see hwloc/bitmap.h).
  135. *
  136. * Each bit may be converted into a PU object using
  137. * hwloc_get_pu_obj_by_os_index().
  138. */
  139. typedef hwloc_bitmap_t hwloc_cpuset_t;
  140. /** \brief A non-modifiable ::hwloc_cpuset_t. */
  141. typedef hwloc_const_bitmap_t hwloc_const_cpuset_t;
  142. /** \brief A node set is a bitmap whose bits are set according to NUMA
  143. * memory node physical OS indexes.
  144. *
  145. * It may be consulted and modified with the bitmap API as any
  146. * ::hwloc_bitmap_t (see hwloc/bitmap.h).
  147. * Each bit may be converted into a NUMA node object using
  148. * hwloc_get_numanode_obj_by_os_index().
  149. *
  150. * When binding memory on a system without any NUMA node,
  151. * the single main memory bank is considered as NUMA node #0.
  152. *
  153. * See also \ref hwlocality_helper_nodeset_convert.
  154. */
  155. typedef hwloc_bitmap_t hwloc_nodeset_t;
  156. /** \brief A non-modifiable ::hwloc_nodeset_t.
  157. */
  158. typedef hwloc_const_bitmap_t hwloc_const_nodeset_t;
  159. /** @} */
  160. /** \defgroup hwlocality_object_types Object Types
  161. * @{
  162. */
  163. /** \brief Type of topology object.
  164. *
  165. * \note Do not rely on the ordering or completeness of the values as new ones
  166. * may be defined in the future! If you need to compare types, use
  167. * hwloc_compare_types() instead.
  168. */
  169. typedef enum {
  170. /** \cond */
  171. #define HWLOC_OBJ_TYPE_MIN HWLOC_OBJ_MACHINE /* Sentinel value */
  172. /** \endcond */
  173. HWLOC_OBJ_MACHINE, /**< \brief Machine.
  174. * A set of processors and memory with cache
  175. * coherency.
  176. *
  177. * This type is always used for the root object of a topology,
  178. * and never used anywhere else.
  179. * Hence its parent is always \c NULL.
  180. */
  181. HWLOC_OBJ_PACKAGE, /**< \brief Physical package.
  182. * The physical package that usually gets inserted
  183. * into a socket on the motherboard.
  184. * A processor package usually contains multiple cores,
  185. * and possibly some dies.
  186. */
  187. HWLOC_OBJ_CORE, /**< \brief Core.
  188. * A computation unit (may be shared by several
  189. * PUs, aka logical processors).
  190. */
  191. HWLOC_OBJ_PU, /**< \brief Processing Unit, or (Logical) Processor.
  192. * An execution unit (may share a core with some
  193. * other logical processors, e.g. in the case of
  194. * an SMT core).
  195. *
  196. * This is the smallest object representing CPU resources,
  197. * it cannot have any child except Misc objects.
  198. *
  199. * Objects of this kind are always reported and can
  200. * thus be used as fallback when others are not.
  201. */
  202. HWLOC_OBJ_L1CACHE, /**< \brief Level 1 Data (or Unified) Cache. */
  203. HWLOC_OBJ_L2CACHE, /**< \brief Level 2 Data (or Unified) Cache. */
  204. HWLOC_OBJ_L3CACHE, /**< \brief Level 3 Data (or Unified) Cache. */
  205. HWLOC_OBJ_L4CACHE, /**< \brief Level 4 Data (or Unified) Cache. */
  206. HWLOC_OBJ_L5CACHE, /**< \brief Level 5 Data (or Unified) Cache. */
  207. HWLOC_OBJ_L1ICACHE, /**< \brief Level 1 instruction Cache (filtered out by default). */
  208. HWLOC_OBJ_L2ICACHE, /**< \brief Level 2 instruction Cache (filtered out by default). */
  209. HWLOC_OBJ_L3ICACHE, /**< \brief Level 3 instruction Cache (filtered out by default). */
  210. HWLOC_OBJ_GROUP, /**< \brief Group objects.
  211. * Objects which do not fit in the above but are
  212. * detected by hwloc and are useful to take into
  213. * account for affinity. For instance, some operating systems
  214. * expose their arbitrary processors aggregation this
  215. * way. And hwloc may insert such objects to group
  216. * NUMA nodes according to their distances.
  217. * See also \ref faq_groups.
  218. *
  219. * These objects are removed when they do not bring
  220. * any structure (see ::HWLOC_TYPE_FILTER_KEEP_STRUCTURE).
  221. */
  222. HWLOC_OBJ_NUMANODE, /**< \brief NUMA node.
  223. * An object that contains memory that is directly
  224. * and byte-accessible to the host processors.
  225. * It is usually close to some cores (the corresponding objects
  226. * are descendants of the NUMA node object in the hwloc tree).
  227. *
  228. * This is the smallest object representing Memory resources,
  229. * it cannot have any child except Misc objects.
  230. * However it may have Memory-side cache parents.
  231. *
  232. * There is always at least one such object in the topology
  233. * even if the machine is not NUMA.
  234. *
  235. * Memory objects are not listed in the main children list,
  236. * but rather in the dedicated Memory children list.
  237. *
  238. * NUMA nodes have a special depth ::HWLOC_TYPE_DEPTH_NUMANODE
  239. * instead of a normal depth just like other objects in the
  240. * main tree.
  241. */
  242. HWLOC_OBJ_BRIDGE, /**< \brief Bridge (filtered out by default).
  243. * Any bridge (or PCI switch) that connects the host or an I/O bus,
  244. * to another I/O bus.
  245. *
  246. * Bridges are not added to the topology unless their
  247. * filtering is changed (see hwloc_topology_set_type_filter()
  248. * and hwloc_topology_set_io_types_filter()).
  249. *
  250. * I/O objects are not listed in the main children list,
  251. * but rather in the dedicated io children list.
  252. * I/O objects have NULL CPU and node sets.
  253. */
  254. HWLOC_OBJ_PCI_DEVICE, /**< \brief PCI device (filtered out by default).
  255. *
  256. * PCI devices are not added to the topology unless their
  257. * filtering is changed (see hwloc_topology_set_type_filter()
  258. * and hwloc_topology_set_io_types_filter()).
  259. *
  260. * I/O objects are not listed in the main children list,
  261. * but rather in the dedicated io children list.
  262. * I/O objects have NULL CPU and node sets.
  263. */
  264. HWLOC_OBJ_OS_DEVICE, /**< \brief Operating system device (filtered out by default).
  265. *
  266. * OS devices are not added to the topology unless their
  267. * filtering is changed (see hwloc_topology_set_type_filter()
  268. * and hwloc_topology_set_io_types_filter()).
  269. *
  270. * I/O objects are not listed in the main children list,
  271. * but rather in the dedicated io children list.
  272. * I/O objects have NULL CPU and node sets.
  273. */
  274. HWLOC_OBJ_MISC, /**< \brief Miscellaneous objects (filtered out by default).
  275. * Objects without particular meaning, that can e.g. be
  276. * added by the application for its own use, or by hwloc
  277. * for miscellaneous objects such as MemoryModule (DIMMs).
  278. *
  279. * They are not added to the topology unless their filtering
  280. * is changed (see hwloc_topology_set_type_filter()).
  281. *
  282. * These objects are not listed in the main children list,
  283. * but rather in the dedicated misc children list.
  284. * Misc objects may only have Misc objects as children,
  285. * and those are in the dedicated misc children list as well.
  286. * Misc objects have NULL CPU and node sets.
  287. */
  288. HWLOC_OBJ_MEMCACHE, /**< \brief Memory-side cache (filtered out by default).
  289. * A cache in front of a specific NUMA node.
  290. *
  291. * This object always has at least one NUMA node as a memory child.
  292. *
  293. * Memory objects are not listed in the main children list,
  294. * but rather in the dedicated Memory children list.
  295. *
  296. * Memory-side cache have a special depth ::HWLOC_TYPE_DEPTH_MEMCACHE
  297. * instead of a normal depth just like other objects in the
  298. * main tree.
  299. */
  300. HWLOC_OBJ_DIE, /**< \brief Die within a physical package.
  301. * A subpart of the physical package, that contains multiple cores.
  302. */
  303. HWLOC_OBJ_TYPE_MAX /**< \private Sentinel value */
  304. } hwloc_obj_type_t;
  305. /** \brief Cache type. */
  306. typedef enum hwloc_obj_cache_type_e {
  307. HWLOC_OBJ_CACHE_UNIFIED, /**< \brief Unified cache. */
  308. HWLOC_OBJ_CACHE_DATA, /**< \brief Data cache. */
  309. HWLOC_OBJ_CACHE_INSTRUCTION /**< \brief Instruction cache (filtered out by default). */
  310. } hwloc_obj_cache_type_t;
  311. /** \brief Type of one side (upstream or downstream) of an I/O bridge. */
  312. typedef enum hwloc_obj_bridge_type_e {
  313. HWLOC_OBJ_BRIDGE_HOST, /**< \brief Host-side of a bridge, only possible upstream. */
  314. HWLOC_OBJ_BRIDGE_PCI /**< \brief PCI-side of a bridge. */
  315. } hwloc_obj_bridge_type_t;
  316. /** \brief Type of a OS device. */
  317. typedef enum hwloc_obj_osdev_type_e {
  318. HWLOC_OBJ_OSDEV_BLOCK, /**< \brief Operating system block device, or non-volatile memory device.
  319. * For instance "sda" or "dax2.0" on Linux. */
  320. HWLOC_OBJ_OSDEV_GPU, /**< \brief Operating system GPU device.
  321. * For instance ":0.0" for a GL display,
  322. * "card0" for a Linux DRM device. */
  323. HWLOC_OBJ_OSDEV_NETWORK, /**< \brief Operating system network device.
  324. * For instance the "eth0" interface on Linux. */
  325. HWLOC_OBJ_OSDEV_OPENFABRICS, /**< \brief Operating system openfabrics device.
  326. * For instance the "mlx4_0" InfiniBand HCA,
  327. * "hfi1_0" Omni-Path interface,
  328. * or "bxi0" Atos/Bull BXI HCA on Linux. */
  329. HWLOC_OBJ_OSDEV_DMA, /**< \brief Operating system dma engine device.
  330. * For instance the "dma0chan0" DMA channel on Linux. */
  331. HWLOC_OBJ_OSDEV_COPROC /**< \brief Operating system co-processor device.
  332. * For instance "opencl0d0" for a OpenCL device,
  333. * "cuda0" for a CUDA device. */
  334. } hwloc_obj_osdev_type_t;
  335. /** \brief Compare the depth of two object types
  336. *
  337. * Types shouldn't be compared as they are, since newer ones may be added in
  338. * the future.
  339. *
  340. * \return A negative integer if \p type1 objects usually include \p type2 objects.
  341. * \return A positive integer if \p type1 objects are usually included in \p type2 objects.
  342. * \return 0 if \p type1 and \p type2 objects are the same.
  343. * \return ::HWLOC_TYPE_UNORDERED if objects cannot be compared
  344. * (because neither is usually contained in the other).
  345. *
  346. * \note Object types containing CPUs can always be compared
  347. * (usually, a machine contains packages, which contain caches,
  348. * which contain cores, which contain PUs).
  349. *
  350. * \note ::HWLOC_OBJ_PU will always be the deepest,
  351. * while ::HWLOC_OBJ_MACHINE is always the highest.
  352. *
  353. * \note This does not mean that the actual topology will respect that order:
  354. * e.g. as of today cores may also contain caches, and packages may also contain
  355. * nodes. This is thus just to be seen as a fallback comparison method.
  356. */
  357. HWLOC_DECLSPEC int hwloc_compare_types (hwloc_obj_type_t type1, hwloc_obj_type_t type2) __hwloc_attribute_const;
  358. /** \brief Value returned by hwloc_compare_types() when types can not be compared. \hideinitializer */
  359. #define HWLOC_TYPE_UNORDERED INT_MAX
  360. /** @} */
  361. /** \defgroup hwlocality_objects Object Structure and Attributes
  362. * @{
  363. */
  364. union hwloc_obj_attr_u;
  365. /** \brief Structure of a topology object
  366. *
  367. * Applications must not modify any field except \p hwloc_obj.userdata.
  368. */
  369. struct hwloc_obj {
  370. /* physical information */
  371. hwloc_obj_type_t type; /**< \brief Type of object */
  372. char *subtype; /**< \brief Subtype string to better describe the type field. */
  373. unsigned os_index; /**< \brief OS-provided physical index number.
  374. * It is not guaranteed unique across the entire machine,
  375. * except for PUs and NUMA nodes.
  376. * Set to HWLOC_UNKNOWN_INDEX if unknown or irrelevant for this object.
  377. */
  378. #define HWLOC_UNKNOWN_INDEX (unsigned)-1
  379. char *name; /**< \brief Object-specific name if any.
  380. * Mostly used for identifying OS devices and Misc objects where
  381. * a name string is more useful than numerical indexes.
  382. */
  383. hwloc_uint64_t total_memory; /**< \brief Total memory (in bytes) in NUMA nodes below this object. */
  384. union hwloc_obj_attr_u *attr; /**< \brief Object type-specific Attributes,
  385. * may be \c NULL if no attribute value was found */
  386. /* global position */
  387. int depth; /**< \brief Vertical index in the hierarchy.
  388. *
  389. * For normal objects, this is the depth of the horizontal level
  390. * that contains this object and its cousins of the same type.
  391. * If the topology is symmetric, this is equal to the parent depth
  392. * plus one, and also equal to the number of parent/child links
  393. * from the root object to here.
  394. *
  395. * For special objects (NUMA nodes, I/O and Misc) that are not
  396. * in the main tree, this is a special negative value that
  397. * corresponds to their dedicated level,
  398. * see hwloc_get_type_depth() and ::hwloc_get_type_depth_e.
  399. * Those special values can be passed to hwloc functions such
  400. * hwloc_get_nbobjs_by_depth() as usual.
  401. */
  402. unsigned logical_index; /**< \brief Horizontal index in the whole list of similar objects,
  403. * hence guaranteed unique across the entire machine.
  404. * Could be a "cousin_rank" since it's the rank within the "cousin" list below
  405. * Note that this index may change when restricting the topology
  406. * or when inserting a group.
  407. */
  408. /* cousins are all objects of the same type (and depth) across the entire topology */
  409. struct hwloc_obj *next_cousin; /**< \brief Next object of same type and depth */
  410. struct hwloc_obj *prev_cousin; /**< \brief Previous object of same type and depth */
  411. /* children of the same parent are siblings, even if they may have different type and depth */
  412. struct hwloc_obj *parent; /**< \brief Parent, \c NULL if root (Machine object) */
  413. unsigned sibling_rank; /**< \brief Index in parent's \c children[] array. Or the index in parent's Memory, I/O or Misc children list. */
  414. struct hwloc_obj *next_sibling; /**< \brief Next object below the same parent (inside the same list of children). */
  415. struct hwloc_obj *prev_sibling; /**< \brief Previous object below the same parent (inside the same list of children). */
  416. /** @name List and array of normal children below this object (except Memory, I/O and Misc children). */
  417. /**@{*/
  418. unsigned arity; /**< \brief Number of normal children.
  419. * Memory, Misc and I/O children are not listed here
  420. * but rather in their dedicated children list.
  421. */
  422. struct hwloc_obj **children; /**< \brief Normal children, \c children[0 .. arity -1] */
  423. struct hwloc_obj *first_child; /**< \brief First normal child */
  424. struct hwloc_obj *last_child; /**< \brief Last normal child */
  425. /**@}*/
  426. int symmetric_subtree; /**< \brief Set if the subtree of normal objects below this object is symmetric,
  427. * which means all normal children and their children have identical subtrees.
  428. *
  429. * Memory, I/O and Misc children are ignored.
  430. *
  431. * If set in the topology root object, lstopo may export the topology
  432. * as a synthetic string.
  433. */
  434. /** @name List of Memory children below this object. */
  435. /**@{*/
  436. unsigned memory_arity; /**< \brief Number of Memory children.
  437. * These children are listed in \p memory_first_child.
  438. */
  439. struct hwloc_obj *memory_first_child; /**< \brief First Memory child.
  440. * NUMA nodes and Memory-side caches are listed here
  441. * (\p memory_arity and \p memory_first_child)
  442. * instead of in the normal children list.
  443. * See also hwloc_obj_type_is_memory().
  444. *
  445. * A memory hierarchy starts from a normal CPU-side object
  446. * (e.g. Package) and ends with NUMA nodes as leaves.
  447. * There might exist some memory-side caches between them
  448. * in the middle of the memory subtree.
  449. */
  450. /**@}*/
  451. /** @name List of I/O children below this object. */
  452. /**@{*/
  453. unsigned io_arity; /**< \brief Number of I/O children.
  454. * These children are listed in \p io_first_child.
  455. */
  456. struct hwloc_obj *io_first_child; /**< \brief First I/O child.
  457. * Bridges, PCI and OS devices are listed here (\p io_arity and \p io_first_child)
  458. * instead of in the normal children list.
  459. * See also hwloc_obj_type_is_io().
  460. */
  461. /**@}*/
  462. /** @name List of Misc children below this object. */
  463. /**@{*/
  464. unsigned misc_arity; /**< \brief Number of Misc children.
  465. * These children are listed in \p misc_first_child.
  466. */
  467. struct hwloc_obj *misc_first_child; /**< \brief First Misc child.
  468. * Misc objects are listed here (\p misc_arity and \p misc_first_child)
  469. * instead of in the normal children list.
  470. */
  471. /**@}*/
  472. /* cpusets and nodesets */
  473. hwloc_cpuset_t cpuset; /**< \brief CPUs covered by this object
  474. *
  475. * This is the set of CPUs for which there are PU objects in the topology
  476. * under this object, i.e. which are known to be physically contained in this
  477. * object and known how (the children path between this object and the PU
  478. * objects).
  479. *
  480. * If the ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED configuration flag is set,
  481. * some of these CPUs may be online but not allowed for binding,
  482. * see hwloc_topology_get_allowed_cpuset().
  483. *
  484. * \note All objects have non-NULL CPU and node sets except Misc and I/O objects.
  485. *
  486. * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
  487. */
  488. hwloc_cpuset_t complete_cpuset; /**< \brief The complete CPU set of processors of this object,
  489. *
  490. * This may include not only the same as the cpuset field, but also some CPUs for
  491. * which topology information is unknown or incomplete, some offlines CPUs, and
  492. * the CPUs that are ignored when the ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED flag
  493. * is not set.
  494. * Thus no corresponding PU object may be found in the topology, because the
  495. * precise position is undefined. It is however known that it would be somewhere
  496. * under this object.
  497. *
  498. * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
  499. */
  500. hwloc_nodeset_t nodeset; /**< \brief NUMA nodes covered by this object or containing this object
  501. *
  502. * This is the set of NUMA nodes for which there are NUMA node objects in the
  503. * topology under or above this object, i.e. which are known to be physically
  504. * contained in this object or containing it and known how (the children path
  505. * between this object and the NUMA node objects).
  506. *
  507. * In the end, these nodes are those that are close to the current object.
  508. * Function hwloc_get_local_numanode_objs() may be used to list those NUMA
  509. * nodes more precisely.
  510. *
  511. * If the ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED configuration flag is set,
  512. * some of these nodes may be online but not allowed for allocation,
  513. * see hwloc_topology_get_allowed_nodeset().
  514. *
  515. * If there are no NUMA nodes in the machine, all the memory is close to this
  516. * object, so only the first bit may be set in \p nodeset.
  517. *
  518. * \note All objects have non-NULL CPU and node sets except Misc and I/O objects.
  519. *
  520. * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
  521. */
  522. hwloc_nodeset_t complete_nodeset; /**< \brief The complete NUMA node set of this object,
  523. *
  524. * This may include not only the same as the nodeset field, but also some NUMA
  525. * nodes for which topology information is unknown or incomplete, some offlines
  526. * nodes, and the nodes that are ignored when the ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED
  527. * flag is not set.
  528. * Thus no corresponding NUMA node object may be found in the topology, because the
  529. * precise position is undefined. It is however known that it would be
  530. * somewhere under this object.
  531. *
  532. * If there are no NUMA nodes in the machine, all the memory is close to this
  533. * object, so only the first bit is set in \p complete_nodeset.
  534. *
  535. * \note Its value must not be changed, hwloc_bitmap_dup() must be used instead.
  536. */
  537. struct hwloc_info_s *infos; /**< \brief Array of info attributes (name and value strings). */
  538. unsigned infos_count; /**< \brief Size of infos array. */
  539. /* misc */
  540. void *userdata; /**< \brief Application-given private data pointer,
  541. * initialized to \c NULL, use it as you wish.
  542. * See hwloc_topology_set_userdata_export_callback() in hwloc/export.h
  543. * if you wish to export this field to XML. */
  544. hwloc_uint64_t gp_index; /**< \brief Global persistent index.
  545. * Generated by hwloc, unique across the topology (contrary to os_index)
  546. * and persistent across topology changes (contrary to logical_index).
  547. * Mostly used internally, but could also be used by application to identify objects.
  548. */
  549. };
  550. /**
  551. * \brief Convenience typedef; a pointer to a struct hwloc_obj.
  552. */
  553. typedef struct hwloc_obj * hwloc_obj_t;
  554. /** \brief Object type-specific Attributes */
  555. union hwloc_obj_attr_u {
  556. /** \brief NUMA node-specific Object Attributes */
  557. struct hwloc_numanode_attr_s {
  558. hwloc_uint64_t local_memory; /**< \brief Local memory (in bytes) */
  559. unsigned page_types_len; /**< \brief Size of array \p page_types */
  560. /** \brief Array of local memory page types, \c NULL if no local memory and \p page_types is 0.
  561. *
  562. * The array is sorted by increasing \p size fields.
  563. * It contains \p page_types_len slots.
  564. */
  565. struct hwloc_memory_page_type_s {
  566. hwloc_uint64_t size; /**< \brief Size of pages */
  567. hwloc_uint64_t count; /**< \brief Number of pages of this size */
  568. } * page_types;
  569. } numanode;
  570. /** \brief Cache-specific Object Attributes */
  571. struct hwloc_cache_attr_s {
  572. hwloc_uint64_t size; /**< \brief Size of cache in bytes */
  573. unsigned depth; /**< \brief Depth of cache (e.g., L1, L2, ...etc.) */
  574. unsigned linesize; /**< \brief Cache-line size in bytes. 0 if unknown */
  575. int associativity; /**< \brief Ways of associativity,
  576. * -1 if fully associative, 0 if unknown */
  577. hwloc_obj_cache_type_t type; /**< \brief Cache type */
  578. } cache;
  579. /** \brief Group-specific Object Attributes */
  580. struct hwloc_group_attr_s {
  581. unsigned depth; /**< \brief Depth of group object.
  582. * It may change if intermediate Group objects are added. */
  583. unsigned kind; /**< \brief Internally-used kind of group. */
  584. unsigned subkind; /**< \brief Internally-used subkind to distinguish different levels of groups with same kind */
  585. unsigned char dont_merge; /**< \brief Flag preventing groups from being automatically merged with identical parent or children. */
  586. } group;
  587. /** \brief PCI Device specific Object Attributes */
  588. struct hwloc_pcidev_attr_s {
  589. #ifndef HWLOC_HAVE_32BITS_PCI_DOMAIN
  590. unsigned short domain; /* Only 16bits PCI domains are supported by default */
  591. #else
  592. unsigned int domain; /* 32bits PCI domain support break the library ABI, hence it's disabled by default */
  593. #endif
  594. unsigned char bus, dev, func;
  595. unsigned short class_id;
  596. unsigned short vendor_id, device_id, subvendor_id, subdevice_id;
  597. unsigned char revision;
  598. float linkspeed; /* in GB/s */
  599. } pcidev;
  600. /** \brief Bridge specific Object Attributes */
  601. struct hwloc_bridge_attr_s {
  602. union {
  603. struct hwloc_pcidev_attr_s pci;
  604. } upstream;
  605. hwloc_obj_bridge_type_t upstream_type;
  606. union {
  607. struct {
  608. #ifndef HWLOC_HAVE_32BITS_PCI_DOMAIN
  609. unsigned short domain; /* Only 16bits PCI domains are supported by default */
  610. #else
  611. unsigned int domain; /* 32bits PCI domain support break the library ABI, hence it's disabled by default */
  612. #endif
  613. unsigned char secondary_bus, subordinate_bus;
  614. } pci;
  615. } downstream;
  616. hwloc_obj_bridge_type_t downstream_type;
  617. unsigned depth;
  618. } bridge;
  619. /** \brief OS Device specific Object Attributes */
  620. struct hwloc_osdev_attr_s {
  621. hwloc_obj_osdev_type_t type;
  622. } osdev;
  623. };
  624. /** \brief Object info attribute (name and value strings)
  625. *
  626. * \sa hwlocality_info_attr
  627. */
  628. struct hwloc_info_s {
  629. char *name; /**< \brief Info name */
  630. char *value; /**< \brief Info value */
  631. };
  632. /** @} */
  633. /** \defgroup hwlocality_creation Topology Creation and Destruction
  634. * @{
  635. */
  636. struct hwloc_topology;
  637. /** \brief Topology context
  638. *
  639. * To be initialized with hwloc_topology_init() and built with hwloc_topology_load().
  640. */
  641. typedef struct hwloc_topology * hwloc_topology_t;
  642. /** \brief Allocate a topology context.
  643. *
  644. * \param[out] topologyp is assigned a pointer to the new allocated context.
  645. *
  646. * \return 0 on success, -1 on error.
  647. */
  648. HWLOC_DECLSPEC int hwloc_topology_init (hwloc_topology_t *topologyp);
  649. /** \brief Build the actual topology
  650. *
  651. * Build the actual topology once initialized with hwloc_topology_init() and
  652. * tuned with \ref hwlocality_configuration and \ref hwlocality_setsource routines.
  653. * No other routine may be called earlier using this topology context.
  654. *
  655. * \param topology is the topology to be loaded with objects.
  656. *
  657. * \return 0 on success, -1 on error.
  658. *
  659. * \note On failure, the topology is reinitialized. It should be either
  660. * destroyed with hwloc_topology_destroy() or configured and loaded again.
  661. *
  662. * \note This function may be called only once per topology.
  663. *
  664. * \note The binding of the current thread or process may temporarily change
  665. * during this call but it will be restored before it returns.
  666. *
  667. * \sa hwlocality_configuration and hwlocality_setsource
  668. */
  669. HWLOC_DECLSPEC int hwloc_topology_load(hwloc_topology_t topology);
  670. /** \brief Terminate and free a topology context
  671. *
  672. * \param topology is the topology to be freed
  673. */
  674. HWLOC_DECLSPEC void hwloc_topology_destroy (hwloc_topology_t topology);
  675. /** \brief Duplicate a topology.
  676. *
  677. * The entire topology structure as well as its objects
  678. * are duplicated into a new one.
  679. *
  680. * This is useful for keeping a backup while modifying a topology.
  681. *
  682. * \return 0 on success, -1 on error.
  683. *
  684. * \note Object userdata is not duplicated since hwloc does not know what it point to.
  685. * The objects of both old and new topologies will point to the same userdata.
  686. */
  687. HWLOC_DECLSPEC int hwloc_topology_dup(hwloc_topology_t *newtopology, hwloc_topology_t oldtopology);
  688. /** \brief Verify that the topology is compatible with the current hwloc library.
  689. *
  690. * This is useful when using the same topology structure (in memory)
  691. * in different libraries that may use different hwloc installations
  692. * (for instance if one library embeds a specific version of hwloc,
  693. * while another library uses a default system-wide hwloc installation).
  694. *
  695. * If all libraries/programs use the same hwloc installation, this function
  696. * always returns success.
  697. *
  698. * \return \c 0 on success.
  699. *
  700. * \return \c -1 with \p errno set to \c EINVAL if incompatible.
  701. *
  702. * \note If sharing between processes with hwloc_shmem_topology_write(),
  703. * the relevant check is already performed inside hwloc_shmem_topology_adopt().
  704. */
  705. HWLOC_DECLSPEC int hwloc_topology_abi_check(hwloc_topology_t topology);
  706. /** \brief Run internal checks on a topology structure
  707. *
  708. * The program aborts if an inconsistency is detected in the given topology.
  709. *
  710. * \param topology is the topology to be checked
  711. *
  712. * \note This routine is only useful to developers.
  713. *
  714. * \note The input topology should have been previously loaded with
  715. * hwloc_topology_load().
  716. */
  717. HWLOC_DECLSPEC void hwloc_topology_check(hwloc_topology_t topology);
  718. /** @} */
  719. /** \defgroup hwlocality_levels Object levels, depths and types
  720. * @{
  721. *
  722. * Be sure to see the figure in \ref termsanddefs that shows a
  723. * complete topology tree, including depths, child/sibling/cousin
  724. * relationships, and an example of an asymmetric topology where one
  725. * package has fewer caches than its peers.
  726. */
  727. /** \brief Get the depth of the hierarchical tree of objects.
  728. *
  729. * This is the depth of ::HWLOC_OBJ_PU objects plus one.
  730. *
  731. * \return the depth of the object tree.
  732. *
  733. * \note NUMA nodes, I/O and Misc objects are ignored when computing
  734. * the depth of the tree (they are placed on special levels).
  735. */
  736. HWLOC_DECLSPEC int hwloc_topology_get_depth(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure;
  737. /** \brief Returns the depth of objects of type \p type.
  738. *
  739. * \return The depth of objects of type \p type.
  740. *
  741. * \return A negative virtual depth if a NUMA node, I/O or Misc object type is given.
  742. * These objects are stored in special levels that are not CPU-related.
  743. * This virtual depth may be passed to other hwloc functions such as
  744. * hwloc_get_obj_by_depth() but it should not be considered as an actual
  745. * depth by the application. In particular, it should not be compared with
  746. * any other object depth or with the entire topology depth.
  747. *
  748. * \return ::HWLOC_TYPE_DEPTH_UNKNOWN
  749. * if no object of this type is present on the underlying architecture,
  750. * or if the OS doesn't provide this kind of information.
  751. *
  752. * \return ::HWLOC_TYPE_DEPTH_MULTIPLE if type ::HWLOC_OBJ_GROUP is given
  753. * and multiple levels of Groups exist.
  754. *
  755. * \note If the type is absent but a similar type is acceptable, see also
  756. * hwloc_get_type_or_below_depth() and hwloc_get_type_or_above_depth().
  757. *
  758. * \sa hwloc_get_memory_parents_depth() for managing the depth of memory objects.
  759. *
  760. * \sa hwloc_type_sscanf_as_depth() for returning the depth of objects
  761. * whose type is given as a string.
  762. */
  763. HWLOC_DECLSPEC int hwloc_get_type_depth (hwloc_topology_t topology, hwloc_obj_type_t type);
  764. enum hwloc_get_type_depth_e {
  765. HWLOC_TYPE_DEPTH_UNKNOWN = -1, /**< \brief No object of given type exists in the topology. \hideinitializer */
  766. HWLOC_TYPE_DEPTH_MULTIPLE = -2, /**< \brief Objects of given type exist at different depth in the topology (only for Groups). \hideinitializer */
  767. HWLOC_TYPE_DEPTH_NUMANODE = -3, /**< \brief Virtual depth for NUMA nodes. \hideinitializer */
  768. HWLOC_TYPE_DEPTH_BRIDGE = -4, /**< \brief Virtual depth for bridge object level. \hideinitializer */
  769. HWLOC_TYPE_DEPTH_PCI_DEVICE = -5, /**< \brief Virtual depth for PCI device object level. \hideinitializer */
  770. HWLOC_TYPE_DEPTH_OS_DEVICE = -6, /**< \brief Virtual depth for software device object level. \hideinitializer */
  771. HWLOC_TYPE_DEPTH_MISC = -7, /**< \brief Virtual depth for Misc object. \hideinitializer */
  772. HWLOC_TYPE_DEPTH_MEMCACHE = -8 /**< \brief Virtual depth for MemCache object. \hideinitializer */
  773. };
  774. /** \brief Return the depth of parents where memory objects are attached.
  775. *
  776. * Memory objects have virtual negative depths because they are not part of
  777. * the main CPU-side hierarchy of objects. This depth should not be compared
  778. * with other level depths.
  779. *
  780. * If all Memory objects are attached to Normal parents at the same depth,
  781. * this parent depth may be compared to other as usual, for instance
  782. * for knowing whether NUMA nodes is attached above or below Packages.
  783. *
  784. * \return The depth of Normal parents of all memory children
  785. * if all these parents have the same depth. For instance the depth of
  786. * the Package level if all NUMA nodes are attached to Package objects.
  787. *
  788. * \return ::HWLOC_TYPE_DEPTH_MULTIPLE if Normal parents of all
  789. * memory children do not have the same depth. For instance if some
  790. * NUMA nodes are attached to Packages while others are attached to
  791. * Groups.
  792. */
  793. HWLOC_DECLSPEC int hwloc_get_memory_parents_depth (hwloc_topology_t topology);
  794. /** \brief Returns the depth of objects of type \p type or below
  795. *
  796. * If no object of this type is present on the underlying architecture, the
  797. * function returns the depth of the first "present" object typically found
  798. * inside \p type.
  799. *
  800. * This function is only meaningful for normal object types.
  801. * If a memory, I/O or Misc object type is given, the corresponding virtual
  802. * depth is always returned (see hwloc_get_type_depth()).
  803. *
  804. * May return ::HWLOC_TYPE_DEPTH_MULTIPLE for ::HWLOC_OBJ_GROUP just like
  805. * hwloc_get_type_depth().
  806. */
  807. static __hwloc_inline int
  808. hwloc_get_type_or_below_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
  809. /** \brief Returns the depth of objects of type \p type or above
  810. *
  811. * If no object of this type is present on the underlying architecture, the
  812. * function returns the depth of the first "present" object typically
  813. * containing \p type.
  814. *
  815. * This function is only meaningful for normal object types.
  816. * If a memory, I/O or Misc object type is given, the corresponding virtual
  817. * depth is always returned (see hwloc_get_type_depth()).
  818. *
  819. * May return ::HWLOC_TYPE_DEPTH_MULTIPLE for ::HWLOC_OBJ_GROUP just like
  820. * hwloc_get_type_depth().
  821. */
  822. static __hwloc_inline int
  823. hwloc_get_type_or_above_depth (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
  824. /** \brief Returns the type of objects at depth \p depth.
  825. *
  826. * \p depth should between 0 and hwloc_topology_get_depth()-1,
  827. * or a virtual depth such as ::HWLOC_TYPE_DEPTH_NUMANODE.
  828. *
  829. * \return The type of objects at depth \p depth.
  830. * \return (hwloc_obj_type_t)-1 if depth \p depth does not exist.
  831. */
  832. HWLOC_DECLSPEC hwloc_obj_type_t hwloc_get_depth_type (hwloc_topology_t topology, int depth) __hwloc_attribute_pure;
  833. /** \brief Returns the width of level at depth \p depth.
  834. *
  835. * \return The number of objects at topology depth \p depth.
  836. * \return 0 if there are no objects at depth \p depth.
  837. */
  838. HWLOC_DECLSPEC unsigned hwloc_get_nbobjs_by_depth (hwloc_topology_t topology, int depth) __hwloc_attribute_pure;
  839. /** \brief Returns the width of level type \p type
  840. *
  841. * \return The number of objects of type \p type.
  842. * \return -1 if there are multiple levels with objects of that type, e.g. ::HWLOC_OBJ_GROUP.
  843. * \return 0 if there are no objects at depth \p depth.
  844. */
  845. static __hwloc_inline int
  846. hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type) __hwloc_attribute_pure;
  847. /** \brief Returns the top-object of the topology-tree.
  848. *
  849. * Its type is ::HWLOC_OBJ_MACHINE.
  850. *
  851. * This function cannot return \c NULL.
  852. */
  853. static __hwloc_inline hwloc_obj_t
  854. hwloc_get_root_obj (hwloc_topology_t topology) __hwloc_attribute_pure;
  855. /** \brief Returns the topology object at logical index \p idx from depth \p depth
  856. *
  857. * \return The object if it exists.
  858. * \return \c NULL if there is no object with this index and depth.
  859. */
  860. HWLOC_DECLSPEC hwloc_obj_t hwloc_get_obj_by_depth (hwloc_topology_t topology, int depth, unsigned idx) __hwloc_attribute_pure;
  861. /** \brief Returns the topology object at logical index \p idx with type \p type
  862. *
  863. * \return The object if it exists.
  864. * \return \c NULL if there is no object with this index and type.
  865. * \return \c NULL if there are multiple levels with objects of that type (e.g. ::HWLOC_OBJ_GROUP),
  866. * the caller may fallback to hwloc_get_obj_by_depth().
  867. */
  868. static __hwloc_inline hwloc_obj_t
  869. hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx) __hwloc_attribute_pure;
  870. /** \brief Returns the next object at depth \p depth.
  871. *
  872. * \return The first object at depth \p depth if \p prev is \c NULL.
  873. * \return The object after \p prev at depth \p depth if \p prev is not \c NULL.
  874. * \return \c NULL if there is no such object.
  875. */
  876. static __hwloc_inline hwloc_obj_t
  877. hwloc_get_next_obj_by_depth (hwloc_topology_t topology, int depth, hwloc_obj_t prev);
  878. /** \brief Returns the next object of type \p type.
  879. *
  880. * \return The first object of type \p type if \p prev is \c NULL.
  881. * \return The object after \p prev of type \p type if \p prev is not \c NULL.
  882. * \return \c NULL if there is no such object.
  883. * \return \c NULL if there are multiple levels with objects of that type (e.g. ::HWLOC_OBJ_GROUP),
  884. * the caller may fallback to hwloc_get_obj_by_depth().
  885. */
  886. static __hwloc_inline hwloc_obj_t
  887. hwloc_get_next_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type,
  888. hwloc_obj_t prev);
  889. /** @} */
  890. /** \defgroup hwlocality_object_strings Converting between Object Types and Attributes, and Strings
  891. * @{
  892. */
  893. /** \brief Return a constant stringified object type.
  894. *
  895. * This function is the basic way to convert a generic type into a string.
  896. * The output string may be parsed back by hwloc_type_sscanf().
  897. *
  898. * hwloc_obj_type_snprintf() may return a more precise output for a specific
  899. * object, but it requires the caller to provide the output buffer.
  900. *
  901. * \return A constant string containing the object type name or \c "Unknown".
  902. */
  903. HWLOC_DECLSPEC const char * hwloc_obj_type_string (hwloc_obj_type_t type) __hwloc_attribute_const;
  904. /** \brief Stringify the type of a given topology object into a human-readable form.
  905. *
  906. * Contrary to hwloc_obj_type_string(), this function includes object-specific
  907. * attributes (such as the Group depth, the Bridge type, or OS device type)
  908. * in the output, and it requires the caller to provide the output buffer.
  909. *
  910. * The output is guaranteed to be the same for all objects of a same topology level.
  911. *
  912. * If \p verbose is 1, longer type names are used, e.g. L1Cache instead of L1.
  913. *
  914. * The output string may be parsed back by hwloc_type_sscanf().
  915. *
  916. * If \p size is 0, \p string may safely be \c NULL.
  917. *
  918. * \return the number of characters that were actually written if not truncating,
  919. * or that would have been written (not including the ending \\0).
  920. */
  921. HWLOC_DECLSPEC int hwloc_obj_type_snprintf(char * __hwloc_restrict string, size_t size,
  922. hwloc_obj_t obj,
  923. int verbose);
  924. /** \brief Stringify the attributes of a given topology object into a human-readable form.
  925. *
  926. * Attribute values are separated by \p separator.
  927. *
  928. * Only the major attributes are printed in non-verbose mode.
  929. *
  930. * If \p size is 0, \p string may safely be \c NULL.
  931. *
  932. * \return the number of characters that were actually written if not truncating,
  933. * or that would have been written (not including the ending \\0).
  934. */
  935. HWLOC_DECLSPEC int hwloc_obj_attr_snprintf(char * __hwloc_restrict string, size_t size,
  936. hwloc_obj_t obj, const char * __hwloc_restrict separator,
  937. int verbose);
  938. /** \brief Return an object type and attributes from a type string.
  939. *
  940. * Convert strings such as "Package" or "L1iCache" into the corresponding types.
  941. * Matching is case-insensitive, and only the first letters are actually
  942. * required to match.
  943. *
  944. * The matched object type is set in \p typep (which cannot be \c NULL).
  945. *
  946. * Type-specific attributes, for instance Cache type, Cache depth, Group depth,
  947. * Bridge type or OS Device type may be returned in \p attrp.
  948. * Attributes that are not specified in the string (for instance "Group"
  949. * without a depth, or "L2Cache" without a cache type) are set to -1.
  950. *
  951. * \p attrp is only filled if not \c NULL and if its size specified in \p attrsize
  952. * is large enough. It should be at least as large as union hwloc_obj_attr_u.
  953. *
  954. * \return 0 if a type was correctly identified, otherwise -1.
  955. *
  956. * \note This function is guaranteed to match any string returned by
  957. * hwloc_obj_type_string() or hwloc_obj_type_snprintf().
  958. *
  959. * \note This is an extended version of the now deprecated hwloc_obj_type_sscanf().
  960. */
  961. HWLOC_DECLSPEC int hwloc_type_sscanf(const char *string,
  962. hwloc_obj_type_t *typep,
  963. union hwloc_obj_attr_u *attrp, size_t attrsize);
  964. /** \brief Return an object type and its level depth from a type string.
  965. *
  966. * Convert strings such as "Package" or "L1iCache" into the corresponding types
  967. * and return in \p depthp the depth of the corresponding level in the
  968. * topology \p topology.
  969. *
  970. * If no object of this type is present on the underlying architecture,
  971. * ::HWLOC_TYPE_DEPTH_UNKNOWN is returned.
  972. *
  973. * If multiple such levels exist (for instance if giving Group without any depth),
  974. * the function may return ::HWLOC_TYPE_DEPTH_MULTIPLE instead.
  975. *
  976. * The matched object type is set in \p typep if \p typep is non \c NULL.
  977. *
  978. * \note This function is similar to hwloc_type_sscanf() followed
  979. * by hwloc_get_type_depth() but it also automatically disambiguates
  980. * multiple group levels etc.
  981. *
  982. * \note This function is guaranteed to match any string returned by
  983. * hwloc_obj_type_string() or hwloc_obj_type_snprintf().
  984. */
  985. HWLOC_DECLSPEC int hwloc_type_sscanf_as_depth(const char *string,
  986. hwloc_obj_type_t *typep,
  987. hwloc_topology_t topology, int *depthp);
  988. /** @} */
  989. /** \defgroup hwlocality_info_attr Consulting and Adding Info Attributes
  990. *
  991. * @{
  992. */
  993. /** \brief Search the given name in object infos and return the corresponding value.
  994. *
  995. * If multiple info attributes match the given name, only the first one is returned.
  996. *
  997. * \return A pointer to the value string if it exists.
  998. * \return \c NULL if no such info attribute exists.
  999. *
  1000. * \note The string should not be freed by the caller, it belongs to the hwloc library.
  1001. */
  1002. static __hwloc_inline const char *
  1003. hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name) __hwloc_attribute_pure;
  1004. /** \brief Add the given name and value pair to the given object info attributes.
  1005. *
  1006. * The info pair is appended to the existing info array even if another pair
  1007. * with the same name already exists.
  1008. *
  1009. * The input strings are copied before being added in the object infos.
  1010. *
  1011. * \return \c 0 on success, \c -1 on error.
  1012. *
  1013. * \note This function may be used to enforce object colors in the lstopo
  1014. * graphical output by adding "lstopoStyle" as a name and "Background=#rrggbb"
  1015. * as a value. See CUSTOM COLORS in the lstopo(1) manpage for details.
  1016. *
  1017. * \note If \p name or \p value contain some non-printable characters, they will
  1018. * be dropped when exporting to XML, see hwloc_topology_export_xml() in hwloc/export.h.
  1019. */
  1020. HWLOC_DECLSPEC int hwloc_obj_add_info(hwloc_obj_t obj, const char *name, const char *value);
  1021. /** @} */
  1022. /** \defgroup hwlocality_cpubinding CPU binding
  1023. *
  1024. * Some operating systems only support binding threads or processes to a single PU.
  1025. * Others allow binding to larger sets such as entire Cores or Packages or
  1026. * even random sets of individual PUs. In such operating system, the scheduler
  1027. * is free to run the task on one of these PU, then migrate it to another PU, etc.
  1028. * It is often useful to call hwloc_bitmap_singlify() on the target CPU set before
  1029. * passing it to the binding function to avoid these expensive migrations.
  1030. * See the documentation of hwloc_bitmap_singlify() for details.
  1031. *
  1032. * Some operating systems do not provide all hwloc-supported
  1033. * mechanisms to bind processes, threads, etc.
  1034. * hwloc_topology_get_support() may be used to query about the actual CPU
  1035. * binding support in the currently used operating system.
  1036. *
  1037. * When the requested binding operation is not available and the
  1038. * ::HWLOC_CPUBIND_STRICT flag was passed, the function returns -1.
  1039. * \p errno is set to \c ENOSYS when it is not possible to bind the requested kind of object
  1040. * processes/threads. errno is set to \c EXDEV when the requested cpuset
  1041. * can not be enforced (e.g. some systems only allow one CPU, and some
  1042. * other systems only allow one NUMA node).
  1043. *
  1044. * If ::HWLOC_CPUBIND_STRICT was not passed, the function may fail as well,
  1045. * or the operating system may use a slightly different operation
  1046. * (with side-effects, smaller binding set, etc.)
  1047. * when the requested operation is not exactly supported.
  1048. *
  1049. * The most portable version that should be preferred over the others,
  1050. * whenever possible, is the following one which just binds the current program,
  1051. * assuming it is single-threaded:
  1052. *
  1053. * \code
  1054. * hwloc_set_cpubind(topology, set, 0),
  1055. * \endcode
  1056. *
  1057. * If the program may be multithreaded, the following one should be preferred
  1058. * to only bind the current thread:
  1059. *
  1060. * \code
  1061. * hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD),
  1062. * \endcode
  1063. *
  1064. * \sa Some example codes are available under doc/examples/ in the source tree.
  1065. *
  1066. * \note To unbind, just call the binding function with either a full cpuset or
  1067. * a cpuset equal to the system cpuset.
  1068. *
  1069. * \note On some operating systems, CPU binding may have effects on memory binding, see
  1070. * ::HWLOC_CPUBIND_NOMEMBIND
  1071. *
  1072. * \note Running lstopo \--top or hwloc-ps can be a very convenient tool to check
  1073. * how binding actually happened.
  1074. * @{
  1075. */
  1076. /** \brief Process/Thread binding flags.
  1077. *
  1078. * These bit flags can be used to refine the binding policy.
  1079. *
  1080. * The default (0) is to bind the current process, assumed to be
  1081. * single-threaded, in a non-strict way. This is the most portable
  1082. * way to bind as all operating systems usually provide it.
  1083. *
  1084. * \note Not all systems support all kinds of binding. See the
  1085. * "Detailed Description" section of \ref hwlocality_cpubinding for a
  1086. * description of errors that can occur.
  1087. */
  1088. typedef enum {
  1089. /** \brief Bind all threads of the current (possibly) multithreaded process.
  1090. * \hideinitializer */
  1091. HWLOC_CPUBIND_PROCESS = (1<<0),
  1092. /** \brief Bind current thread of current process.
  1093. * \hideinitializer */
  1094. HWLOC_CPUBIND_THREAD = (1<<1),
  1095. /** \brief Request for strict binding from the OS.
  1096. *
  1097. * By default, when the designated CPUs are all busy while other
  1098. * CPUs are idle, operating systems may execute the thread/process
  1099. * on those other CPUs instead of the designated CPUs, to let them
  1100. * progress anyway. Strict binding means that the thread/process
  1101. * will _never_ execute on other CPUs than the designated CPUs, even
  1102. * when those are busy with other tasks and other CPUs are idle.
  1103. *
  1104. * \note Depending on the operating system, strict binding may not
  1105. * be possible (e.g., the OS does not implement it) or not allowed
  1106. * (e.g., for an administrative reasons), and the function will fail
  1107. * in that case.
  1108. *
  1109. * When retrieving the binding of a process, this flag checks
  1110. * whether all its threads actually have the same binding. If the
  1111. * flag is not given, the binding of each thread will be
  1112. * accumulated.
  1113. *
  1114. * \note This flag is meaningless when retrieving the binding of a
  1115. * thread.
  1116. * \hideinitializer
  1117. */
  1118. HWLOC_CPUBIND_STRICT = (1<<2),
  1119. /** \brief Avoid any effect on memory binding
  1120. *
  1121. * On some operating systems, some CPU binding function would also
  1122. * bind the memory on the corresponding NUMA node. It is often not
  1123. * a problem for the application, but if it is, setting this flag
  1124. * will make hwloc avoid using OS functions that would also bind
  1125. * memory. This will however reduce the support of CPU bindings,
  1126. * i.e. potentially return -1 with errno set to \c ENOSYS in some
  1127. * cases.
  1128. *
  1129. * This flag is only meaningful when used with functions that set
  1130. * the CPU binding. It is ignored when used with functions that get
  1131. * CPU binding information.
  1132. * \hideinitializer
  1133. */
  1134. HWLOC_CPUBIND_NOMEMBIND = (1<<3)
  1135. } hwloc_cpubind_flags_t;
  1136. /** \brief Bind current process or thread on CPUs given in physical bitmap \p set.
  1137. *
  1138. * \return 0 on success.
  1139. * \return -1 with errno set to \c ENOSYS if the action is not supported.
  1140. * \return -1 with errno set to \c EXDEV if the binding cannot be enforced.
  1141. */
  1142. HWLOC_DECLSPEC int hwloc_set_cpubind(hwloc_topology_t topology, hwloc_const_cpuset_t set, int flags);
  1143. /** \brief Get current process or thread binding.
  1144. *
  1145. * The CPU-set \p set (previously allocated by the caller)
  1146. * is filled with the list of PUs which the process or
  1147. * thread (according to \e flags) was last bound to.
  1148. *
  1149. * \return 0 on success, -1 on error.
  1150. */
  1151. HWLOC_DECLSPEC int hwloc_get_cpubind(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
  1152. /** \brief Bind a process \p pid on CPUs given in physical bitmap \p set.
  1153. *
  1154. * \return 0 on success, -1 on error.
  1155. *
  1156. * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
  1157. * and \p HANDLE on native Windows platforms.
  1158. *
  1159. * \note As a special case on Linux, if a tid (thread ID) is supplied
  1160. * instead of a pid (process ID) and ::HWLOC_CPUBIND_THREAD is passed in flags,
  1161. * the binding is applied to that specific thread.
  1162. *
  1163. * \note On non-Linux systems, ::HWLOC_CPUBIND_THREAD can not be used in \p flags.
  1164. */
  1165. HWLOC_DECLSPEC int hwloc_set_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_cpuset_t set, int flags);
  1166. /** \brief Get the current physical binding of process \p pid.
  1167. *
  1168. * The CPU-set \p set (previously allocated by the caller)
  1169. * is filled with the list of PUs which the process
  1170. * was last bound to.
  1171. *
  1172. * \return 0 on success, -1 on error.
  1173. *
  1174. * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
  1175. * and \p HANDLE on native Windows platforms.
  1176. *
  1177. * \note As a special case on Linux, if a tid (thread ID) is supplied
  1178. * instead of a pid (process ID) and HWLOC_CPUBIND_THREAD is passed in flags,
  1179. * the binding for that specific thread is returned.
  1180. *
  1181. * \note On non-Linux systems, HWLOC_CPUBIND_THREAD can not be used in \p flags.
  1182. */
  1183. HWLOC_DECLSPEC int hwloc_get_proc_cpubind(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
  1184. #ifdef hwloc_thread_t
  1185. /** \brief Bind a thread \p thread on CPUs given in physical bitmap \p set.
  1186. *
  1187. * \return 0 on success, -1 on error.
  1188. *
  1189. * \note \p hwloc_thread_t is \p pthread_t on Unix platforms,
  1190. * and \p HANDLE on native Windows platforms.
  1191. *
  1192. * \note ::HWLOC_CPUBIND_PROCESS can not be used in \p flags.
  1193. */
  1194. HWLOC_DECLSPEC int hwloc_set_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_const_cpuset_t set, int flags);
  1195. #endif
  1196. #ifdef hwloc_thread_t
  1197. /** \brief Get the current physical binding of thread \p tid.
  1198. *
  1199. * The CPU-set \p set (previously allocated by the caller)
  1200. * is filled with the list of PUs which the thread
  1201. * was last bound to.
  1202. *
  1203. * \return 0 on success, -1 on error.
  1204. *
  1205. * \note \p hwloc_thread_t is \p pthread_t on Unix platforms,
  1206. * and \p HANDLE on native Windows platforms.
  1207. *
  1208. * \note ::HWLOC_CPUBIND_PROCESS can not be used in \p flags.
  1209. */
  1210. HWLOC_DECLSPEC int hwloc_get_thread_cpubind(hwloc_topology_t topology, hwloc_thread_t thread, hwloc_cpuset_t set, int flags);
  1211. #endif
  1212. /** \brief Get the last physical CPU where the current process or thread ran.
  1213. *
  1214. * The CPU-set \p set (previously allocated by the caller)
  1215. * is filled with the list of PUs which the process or
  1216. * thread (according to \e flags) last ran on.
  1217. *
  1218. * The operating system may move some tasks from one processor
  1219. * to another at any time according to their binding,
  1220. * so this function may return something that is already
  1221. * outdated.
  1222. *
  1223. * \p flags can include either ::HWLOC_CPUBIND_PROCESS or ::HWLOC_CPUBIND_THREAD to
  1224. * specify whether the query should be for the whole process (union of all CPUs
  1225. * on which all threads are running), or only the current thread. If the
  1226. * process is single-threaded, flags can be set to zero to let hwloc use
  1227. * whichever method is available on the underlying OS.
  1228. *
  1229. * \return 0 on success, -1 on error.
  1230. */
  1231. HWLOC_DECLSPEC int hwloc_get_last_cpu_location(hwloc_topology_t topology, hwloc_cpuset_t set, int flags);
  1232. /** \brief Get the last physical CPU where a process ran.
  1233. *
  1234. * The CPU-set \p set (previously allocated by the caller)
  1235. * is filled with the list of PUs which the process
  1236. * last ran on.
  1237. *
  1238. * The operating system may move some tasks from one processor
  1239. * to another at any time according to their binding,
  1240. * so this function may return something that is already
  1241. * outdated.
  1242. *
  1243. * \return 0 on success, -1 on error.
  1244. *
  1245. * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
  1246. * and \p HANDLE on native Windows platforms.
  1247. *
  1248. * \note As a special case on Linux, if a tid (thread ID) is supplied
  1249. * instead of a pid (process ID) and ::HWLOC_CPUBIND_THREAD is passed in flags,
  1250. * the last CPU location of that specific thread is returned.
  1251. *
  1252. * \note On non-Linux systems, ::HWLOC_CPUBIND_THREAD can not be used in \p flags.
  1253. */
  1254. HWLOC_DECLSPEC int hwloc_get_proc_last_cpu_location(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_cpuset_t set, int flags);
  1255. /** @} */
  1256. /** \defgroup hwlocality_membinding Memory binding
  1257. *
  1258. * Memory binding can be done three ways:
  1259. *
  1260. * - explicit memory allocation thanks to hwloc_alloc_membind() and friends:
  1261. * the binding will have effect on the memory allocated by these functions.
  1262. * - implicit memory binding through binding policy: hwloc_set_membind() and
  1263. * friends only define the current policy of the process, which will be
  1264. * applied to the subsequent calls to malloc() and friends.
  1265. * - migration of existing memory ranges, thanks to hwloc_set_area_membind()
  1266. * and friends, which move already-allocated data.
  1267. *
  1268. * Not all operating systems support all three ways.
  1269. * hwloc_topology_get_support() may be used to query about the actual memory
  1270. * binding support in the currently used operating system.
  1271. *
  1272. * When the requested binding operation is not available and the
  1273. * ::HWLOC_MEMBIND_STRICT flag was passed, the function returns -1.
  1274. * \p errno will be set to \c ENOSYS when the system does support
  1275. * the specified action or policy
  1276. * (e.g., some systems only allow binding memory on a per-thread
  1277. * basis, whereas other systems only allow binding memory for all
  1278. * threads in a process).
  1279. * \p errno will be set to \c EXDEV when the requested set can not be enforced
  1280. * (e.g., some systems only allow binding memory to a single NUMA node).
  1281. *
  1282. * If ::HWLOC_MEMBIND_STRICT was not passed, the function may fail as well,
  1283. * or the operating system may use a slightly different operation
  1284. * (with side-effects, smaller binding set, etc.)
  1285. * when the requested operation is not exactly supported.
  1286. *
  1287. * The most portable form that should be preferred over the others
  1288. * whenever possible is as follows.
  1289. * It allocates some memory hopefully bound to the specified set.
  1290. * To do so, hwloc will possibly have to change the current memory
  1291. * binding policy in order to actually get the memory bound, if the OS
  1292. * does not provide any other way to simply allocate bound memory
  1293. * without changing the policy for all allocations. That is the
  1294. * difference with hwloc_alloc_membind(), which will never change the
  1295. * current memory binding policy.
  1296. *
  1297. * \code
  1298. * hwloc_alloc_membind_policy(topology, size, set,
  1299. * HWLOC_MEMBIND_BIND, 0);
  1300. * \endcode
  1301. *
  1302. * Each hwloc memory binding function takes a bitmap argument that
  1303. * is a CPU set by default, or a NUMA memory node set if the flag
  1304. * ::HWLOC_MEMBIND_BYNODESET is specified.
  1305. * See \ref hwlocality_object_sets and \ref hwlocality_bitmap for a
  1306. * discussion of CPU sets and NUMA memory node sets.
  1307. * It is also possible to convert between CPU set and node set using
  1308. * hwloc_cpuset_to_nodeset() or hwloc_cpuset_from_nodeset().
  1309. *
  1310. * Memory binding by CPU set cannot work for CPU-less NUMA memory nodes.
  1311. * Binding by nodeset should therefore be preferred whenever possible.
  1312. *
  1313. * \sa Some example codes are available under doc/examples/ in the source tree.
  1314. *
  1315. * \note On some operating systems, memory binding affects the CPU
  1316. * binding; see ::HWLOC_MEMBIND_NOCPUBIND
  1317. * @{
  1318. */
  1319. /** \brief Memory binding policy.
  1320. *
  1321. * These constants can be used to choose the binding policy. Only one policy can
  1322. * be used at a time (i.e., the values cannot be OR'ed together).
  1323. *
  1324. * Not all systems support all kinds of binding.
  1325. * hwloc_topology_get_support() may be used to query about the actual memory
  1326. * binding policy support in the currently used operating system.
  1327. * See the "Detailed Description" section of \ref hwlocality_membinding
  1328. * for a description of errors that can occur.
  1329. */
  1330. typedef enum {
  1331. /** \brief Reset the memory allocation policy to the system default.
  1332. * Depending on the operating system, this may correspond to
  1333. * ::HWLOC_MEMBIND_FIRSTTOUCH (Linux, FreeBSD),
  1334. * or ::HWLOC_MEMBIND_BIND (AIX, HP-UX, Solaris, Windows).
  1335. * This policy is never returned by get membind functions.
  1336. * The nodeset argument is ignored.
  1337. * \hideinitializer */
  1338. HWLOC_MEMBIND_DEFAULT = 0,
  1339. /** \brief Allocate each memory page individually on the local NUMA
  1340. * node of the thread that touches it.
  1341. *
  1342. * The given nodeset should usually be hwloc_topology_get_topology_nodeset()
  1343. * so that the touching thread may run and allocate on any node in the system.
  1344. *
  1345. * On AIX, if the nodeset is smaller, pages are allocated locally (if the local
  1346. * node is in the nodeset) or from a random non-local node (otherwise).
  1347. * \hideinitializer */
  1348. HWLOC_MEMBIND_FIRSTTOUCH = 1,
  1349. /** \brief Allocate memory on the specified nodes.
  1350. *
  1351. * The actual behavior may slightly vary between operating systems,
  1352. * especially when (some of) the requested nodes are full.
  1353. * On Linux, by default, the MPOL_PREFERRED_MANY (or MPOL_PREFERRED) policy
  1354. * is used. However, if the hwloc strict flag is also given, the Linux
  1355. * MPOL_BIND policy is rather used.
  1356. * \hideinitializer */
  1357. HWLOC_MEMBIND_BIND = 2,
  1358. /** \brief Allocate memory on the given nodes in an interleaved
  1359. * / round-robin manner. The precise layout of the memory across
  1360. * multiple NUMA nodes is OS/system specific. Interleaving can be
  1361. * useful when threads distributed across the specified NUMA nodes
  1362. * will all be accessing the whole memory range concurrently, since
  1363. * the interleave will then balance the memory references.
  1364. * \hideinitializer */
  1365. HWLOC_MEMBIND_INTERLEAVE = 3,
  1366. /** \brief For each page bound with this policy, by next time
  1367. * it is touched (and next time only), it is moved from its current
  1368. * location to the local NUMA node of the thread where the memory
  1369. * reference occurred (if it needs to be moved at all).
  1370. * \hideinitializer */
  1371. HWLOC_MEMBIND_NEXTTOUCH = 4,
  1372. /** \brief Returned by get_membind() functions when multiple
  1373. * threads or parts of a memory area have differing memory binding
  1374. * policies.
  1375. * Also returned when binding is unknown because binding hooks are empty
  1376. * when the topology is loaded from XML without HWLOC_THISSYSTEM=1, etc.
  1377. * \hideinitializer */
  1378. HWLOC_MEMBIND_MIXED = -1
  1379. } hwloc_membind_policy_t;
  1380. /** \brief Memory binding flags.
  1381. *
  1382. * These flags can be used to refine the binding policy.
  1383. * All flags can be logically OR'ed together with the exception of
  1384. * ::HWLOC_MEMBIND_PROCESS and ::HWLOC_MEMBIND_THREAD;
  1385. * these two flags are mutually exclusive.
  1386. *
  1387. * Not all systems support all kinds of binding.
  1388. * hwloc_topology_get_support() may be used to query about the actual memory
  1389. * binding support in the currently used operating system.
  1390. * See the "Detailed Description" section of \ref hwlocality_membinding
  1391. * for a description of errors that can occur.
  1392. */
  1393. typedef enum {
  1394. /** \brief Set policy for all threads of the specified (possibly
  1395. * multithreaded) process. This flag is mutually exclusive with
  1396. * ::HWLOC_MEMBIND_THREAD.
  1397. * \hideinitializer */
  1398. HWLOC_MEMBIND_PROCESS = (1<<0),
  1399. /** \brief Set policy for a specific thread of the current process.
  1400. * This flag is mutually exclusive with ::HWLOC_MEMBIND_PROCESS.
  1401. * \hideinitializer */
  1402. HWLOC_MEMBIND_THREAD = (1<<1),
  1403. /** Request strict binding from the OS. The function will fail if
  1404. * the binding can not be guaranteed / completely enforced.
  1405. *
  1406. * This flag has slightly different meanings depending on which
  1407. * function it is used with.
  1408. * \hideinitializer */
  1409. HWLOC_MEMBIND_STRICT = (1<<2),
  1410. /** \brief Migrate existing allocated memory. If the memory cannot
  1411. * be migrated and the ::HWLOC_MEMBIND_STRICT flag is passed, an error
  1412. * will be returned.
  1413. * \hideinitializer */
  1414. HWLOC_MEMBIND_MIGRATE = (1<<3),
  1415. /** \brief Avoid any effect on CPU binding.
  1416. *
  1417. * On some operating systems, some underlying memory binding
  1418. * functions also bind the application to the corresponding CPU(s).
  1419. * Using this flag will cause hwloc to avoid using OS functions that
  1420. * could potentially affect CPU bindings. Note, however, that using
  1421. * NOCPUBIND may reduce hwloc's overall memory binding
  1422. * support. Specifically: some of hwloc's memory binding functions
  1423. * may fail with errno set to \c ENOSYS when used with NOCPUBIND.
  1424. * \hideinitializer
  1425. */
  1426. HWLOC_MEMBIND_NOCPUBIND = (1<<4),
  1427. /** \brief Consider the bitmap argument as a nodeset.
  1428. *
  1429. * The bitmap argument is considered a nodeset if this flag is given,
  1430. * or a cpuset otherwise by default.
  1431. *
  1432. * Memory binding by CPU set cannot work for CPU-less NUMA memory nodes.
  1433. * Binding by nodeset should therefore be preferred whenever possible.
  1434. * \hideinitializer
  1435. */
  1436. HWLOC_MEMBIND_BYNODESET = (1<<5)
  1437. } hwloc_membind_flags_t;
  1438. /** \brief Set the default memory binding policy of the current
  1439. * process or thread to prefer the NUMA node(s) specified by \p set
  1440. *
  1441. * If neither ::HWLOC_MEMBIND_PROCESS nor ::HWLOC_MEMBIND_THREAD is
  1442. * specified, the current process is assumed to be single-threaded.
  1443. * This is the most portable form as it permits hwloc to use either
  1444. * process-based OS functions or thread-based OS functions, depending
  1445. * on which are available.
  1446. *
  1447. * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
  1448. * Otherwise it's a cpuset.
  1449. *
  1450. * \return 0 on success.
  1451. * \return -1 with errno set to \c ENOSYS if the action is not supported.
  1452. * \return -1 with errno set to \c EXDEV if the binding cannot be enforced.
  1453. */
  1454. HWLOC_DECLSPEC int hwloc_set_membind(hwloc_topology_t topology, hwloc_const_bitmap_t set, hwloc_membind_policy_t policy, int flags);
  1455. /** \brief Query the default memory binding policy and physical locality of the
  1456. * current process or thread.
  1457. *
  1458. * The bitmap \p set (previously allocated by the caller)
  1459. * is filled with the process or thread memory binding.
  1460. *
  1461. * This function has two output parameters: \p set and \p policy.
  1462. * The values returned in these parameters depend on both the \p flags
  1463. * passed in and the current memory binding policies and nodesets in
  1464. * the queried target.
  1465. *
  1466. * Passing the ::HWLOC_MEMBIND_PROCESS flag specifies that the query
  1467. * target is the current policies and nodesets for all the threads in
  1468. * the current process. Passing ::HWLOC_MEMBIND_THREAD specifies that
  1469. * the query target is the current policy and nodeset for only the
  1470. * thread invoking this function.
  1471. *
  1472. * If neither of these flags are passed (which is the most portable
  1473. * method), the process is assumed to be single threaded. This allows
  1474. * hwloc to use either process-based OS functions or thread-based OS
  1475. * functions, depending on which are available.
  1476. *
  1477. * ::HWLOC_MEMBIND_STRICT is only meaningful when ::HWLOC_MEMBIND_PROCESS
  1478. * is also specified. In this case, hwloc will check the default
  1479. * memory policies and nodesets for all threads in the process. If
  1480. * they are not identical, -1 is returned and errno is set to \c EXDEV.
  1481. * If they are identical, the values are returned in \p set and \p
  1482. * policy.
  1483. *
  1484. * Otherwise, if ::HWLOC_MEMBIND_PROCESS is specified (and
  1485. * ::HWLOC_MEMBIND_STRICT is \em not specified), the default set
  1486. * from each thread is logically OR'ed together.
  1487. * If all threads' default policies are the same, \p policy is set to
  1488. * that policy. If they are different, \p policy is set to
  1489. * ::HWLOC_MEMBIND_MIXED.
  1490. *
  1491. * In the ::HWLOC_MEMBIND_THREAD case (or when neither
  1492. * ::HWLOC_MEMBIND_PROCESS or ::HWLOC_MEMBIND_THREAD is specified), there
  1493. * is only one set and policy; they are returned in \p set and
  1494. * \p policy, respectively.
  1495. *
  1496. * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
  1497. * Otherwise it's a cpuset.
  1498. *
  1499. * If any other flags are specified, -1 is returned and errno is set
  1500. * to \c EINVAL.
  1501. *
  1502. * \return 0 on success, -1 on error.
  1503. */
  1504. HWLOC_DECLSPEC int hwloc_get_membind(hwloc_topology_t topology, hwloc_bitmap_t set, hwloc_membind_policy_t * policy, int flags);
  1505. /** \brief Set the default memory binding policy of the specified
  1506. * process to prefer the NUMA node(s) specified by \p set
  1507. *
  1508. * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
  1509. * Otherwise it's a cpuset.
  1510. *
  1511. * \return 0 on success.
  1512. * \return -1 with errno set to \c ENOSYS if the action is not supported.
  1513. * \return -1 with errno set to \c EXDEV if the binding cannot be enforced.
  1514. *
  1515. * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
  1516. * and \p HANDLE on native Windows platforms.
  1517. */
  1518. 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);
  1519. /** \brief Query the default memory binding policy and physical locality of the
  1520. * specified process.
  1521. *
  1522. * The bitmap \p set (previously allocated by the caller)
  1523. * is filled with the process memory binding.
  1524. *
  1525. * This function has two output parameters: \p set and \p policy.
  1526. * The values returned in these parameters depend on both the \p flags
  1527. * passed in and the current memory binding policies and nodesets in
  1528. * the queried target.
  1529. *
  1530. * Passing the ::HWLOC_MEMBIND_PROCESS flag specifies that the query
  1531. * target is the current policies and nodesets for all the threads in
  1532. * the specified process. If ::HWLOC_MEMBIND_PROCESS is not specified
  1533. * (which is the most portable method), the process is assumed to be
  1534. * single threaded. This allows hwloc to use either process-based OS
  1535. * functions or thread-based OS functions, depending on which are
  1536. * available.
  1537. *
  1538. * Note that it does not make sense to pass ::HWLOC_MEMBIND_THREAD to
  1539. * this function.
  1540. *
  1541. * If ::HWLOC_MEMBIND_STRICT is specified, hwloc will check the default
  1542. * memory policies and nodesets for all threads in the specified
  1543. * process. If they are not identical, -1 is returned and errno is
  1544. * set to \c EXDEV. If they are identical, the values are returned in \p
  1545. * set and \p policy.
  1546. *
  1547. * Otherwise, \p set is set to the logical OR of all threads'
  1548. * default set. If all threads' default policies
  1549. * are the same, \p policy is set to that policy. If they are
  1550. * different, \p policy is set to ::HWLOC_MEMBIND_MIXED.
  1551. *
  1552. * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
  1553. * Otherwise it's a cpuset.
  1554. *
  1555. * If any other flags are specified, -1 is returned and errno is set
  1556. * to \c EINVAL.
  1557. *
  1558. * \return 0 on success, -1 on error.
  1559. *
  1560. * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
  1561. * and \p HANDLE on native Windows platforms.
  1562. */
  1563. 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);
  1564. /** \brief Bind the already-allocated memory identified by (addr, len)
  1565. * to the NUMA node(s) specified by \p set.
  1566. *
  1567. * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
  1568. * Otherwise it's a cpuset.
  1569. *
  1570. * \return 0 on success or if \p len is 0.
  1571. * \return -1 with errno set to \c ENOSYS if the action is not supported.
  1572. * \return -1 with errno set to \c EXDEV if the binding cannot be enforced.
  1573. */
  1574. 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);
  1575. /** \brief Query the CPUs near the physical NUMA node(s) and binding policy of
  1576. * the memory identified by (\p addr, \p len ).
  1577. *
  1578. * The bitmap \p set (previously allocated by the caller)
  1579. * is filled with the memory area binding.
  1580. *
  1581. * This function has two output parameters: \p set and \p policy.
  1582. * The values returned in these parameters depend on both the \p flags
  1583. * passed in and the memory binding policies and nodesets of the pages
  1584. * in the address range.
  1585. *
  1586. * If ::HWLOC_MEMBIND_STRICT is specified, the target pages are first
  1587. * checked to see if they all have the same memory binding policy and
  1588. * nodeset. If they do not, -1 is returned and errno is set to \c EXDEV.
  1589. * If they are identical across all pages, the set and policy are
  1590. * returned in \p set and \p policy, respectively.
  1591. *
  1592. * If ::HWLOC_MEMBIND_STRICT is not specified, the union of all NUMA
  1593. * node(s) containing pages in the address range is calculated.
  1594. * If all pages in the target have the same policy, it is returned in
  1595. * \p policy. Otherwise, \p policy is set to ::HWLOC_MEMBIND_MIXED.
  1596. *
  1597. * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
  1598. * Otherwise it's a cpuset.
  1599. *
  1600. * If any other flags are specified, -1 is returned and errno is set
  1601. * to \c EINVAL.
  1602. *
  1603. * \return 0 on success.
  1604. * \return -1 with errno set to \c EINVAL if \p len is 0.
  1605. */
  1606. 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);
  1607. /** \brief Get the NUMA nodes where memory identified by (\p addr, \p len ) is physically allocated.
  1608. *
  1609. * The bitmap \p set (previously allocated by the caller)
  1610. * is filled according to the NUMA nodes where the memory area pages
  1611. * are physically allocated. If no page is actually allocated yet,
  1612. * \p set may be empty.
  1613. *
  1614. * If pages spread to multiple nodes, it is not specified whether they spread
  1615. * equitably, or whether most of them are on a single node, etc.
  1616. *
  1617. * The operating system may move memory pages from one processor
  1618. * to another at any time according to their binding,
  1619. * so this function may return something that is already
  1620. * outdated.
  1621. *
  1622. * If ::HWLOC_MEMBIND_BYNODESET is specified in \p flags, set is
  1623. * considered a nodeset. Otherwise it's a cpuset.
  1624. *
  1625. * If \p len is 0, \p set is emptied.
  1626. *
  1627. * \return 0 on success, -1 on error.
  1628. */
  1629. HWLOC_DECLSPEC int hwloc_get_area_memlocation(hwloc_topology_t topology, const void *addr, size_t len, hwloc_bitmap_t set, int flags);
  1630. /** \brief Allocate some memory
  1631. *
  1632. * This is equivalent to malloc(), except that it tries to allocate
  1633. * page-aligned memory from the OS.
  1634. *
  1635. * \return a pointer to the allocated area, or \c NULL on error.
  1636. *
  1637. * \note The allocated memory should be freed with hwloc_free().
  1638. */
  1639. HWLOC_DECLSPEC void *hwloc_alloc(hwloc_topology_t topology, size_t len);
  1640. /** \brief Allocate some memory on NUMA memory nodes specified by \p set
  1641. *
  1642. * \return a pointer to the allocated area.
  1643. * \return NULL with errno set to \c ENOSYS if the action is not supported
  1644. * and ::HWLOC_MEMBIND_STRICT is given.
  1645. * \return NULL with errno set to \c EXDEV if the binding cannot be enforced
  1646. * and ::HWLOC_MEMBIND_STRICT is given.
  1647. * \return NULL with errno set to \c ENOMEM if the memory allocation failed
  1648. * even before trying to bind.
  1649. *
  1650. * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
  1651. * Otherwise it's a cpuset.
  1652. *
  1653. * \note The allocated memory should be freed with hwloc_free().
  1654. */
  1655. 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;
  1656. /** \brief Allocate some memory on NUMA memory nodes specified by \p set
  1657. *
  1658. * First, try to allocate properly with hwloc_alloc_membind().
  1659. * On failure, the current process or thread memory binding policy
  1660. * is changed with hwloc_set_membind() before allocating memory.
  1661. * Thus this function works in more cases, at the expense of changing
  1662. * the current state (possibly affecting future allocations that
  1663. * would not specify any policy).
  1664. *
  1665. * If ::HWLOC_MEMBIND_BYNODESET is specified, set is considered a nodeset.
  1666. * Otherwise it's a cpuset.
  1667. *
  1668. * \return a pointer to the allocated area, or \c NULL on error.
  1669. */
  1670. static __hwloc_inline void *
  1671. 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;
  1672. /** \brief Free memory that was previously allocated by hwloc_alloc()
  1673. * or hwloc_alloc_membind().
  1674. *
  1675. * \return 0 on success, -1 on error.
  1676. */
  1677. HWLOC_DECLSPEC int hwloc_free(hwloc_topology_t topology, void *addr, size_t len);
  1678. /** @} */
  1679. /** \defgroup hwlocality_setsource Changing the Source of Topology Discovery
  1680. *
  1681. * These functions must be called between hwloc_topology_init() and hwloc_topology_load().
  1682. * Otherwise, they will return -1 with errno set to \c EBUSY.
  1683. *
  1684. * If none of the functions below is called, the default is to detect all the objects
  1685. * of the machine that the caller is allowed to access.
  1686. *
  1687. * This default behavior may also be modified through environment variables
  1688. * if the application did not modify it already.
  1689. * Setting HWLOC_XMLFILE in the environment enforces the discovery from a XML
  1690. * file as if hwloc_topology_set_xml() had been called.
  1691. * Setting HWLOC_SYNTHETIC enforces a synthetic topology as if
  1692. * hwloc_topology_set_synthetic() had been called.
  1693. *
  1694. * Finally, HWLOC_THISSYSTEM enforces the return value of
  1695. * hwloc_topology_is_thissystem().
  1696. *
  1697. * @{
  1698. */
  1699. /** \brief Change which process the topology is viewed from.
  1700. *
  1701. * On some systems, processes may have different views of the machine, for
  1702. * instance the set of allowed CPUs. By default, hwloc exposes the view from
  1703. * the current process. Calling hwloc_topology_set_pid() permits to make it
  1704. * expose the topology of the machine from the point of view of another
  1705. * process.
  1706. *
  1707. * \note \p hwloc_pid_t is \p pid_t on Unix platforms,
  1708. * and \p HANDLE on native Windows platforms.
  1709. *
  1710. * \note -1 is returned and errno is set to \c ENOSYS on platforms that do not
  1711. * support this feature.
  1712. *
  1713. * \return 0 on success, -1 on error.
  1714. */
  1715. HWLOC_DECLSPEC int hwloc_topology_set_pid(hwloc_topology_t __hwloc_restrict topology, hwloc_pid_t pid);
  1716. /** \brief Enable synthetic topology.
  1717. *
  1718. * Gather topology information from the given \p description,
  1719. * a space-separated string of <type:number> describing
  1720. * the object type and arity at each level.
  1721. * All types may be omitted (space-separated string of numbers) so that
  1722. * hwloc chooses all types according to usual topologies.
  1723. * See also the \ref synthetic.
  1724. *
  1725. * Setting the environment variable HWLOC_SYNTHETIC
  1726. * may also result in this behavior.
  1727. *
  1728. * If \p description was properly parsed and describes a valid topology
  1729. * configuration, this function returns 0.
  1730. * Otherwise -1 is returned and errno is set to \c EINVAL.
  1731. *
  1732. * Note that this function does not actually load topology
  1733. * information; it just tells hwloc where to load it from. You'll
  1734. * still need to invoke hwloc_topology_load() to actually load the
  1735. * topology information.
  1736. *
  1737. * \return 0 on success.
  1738. * \return -1 with errno set to \c EINVAL if the description was invalid.
  1739. *
  1740. * \note For convenience, this backend provides empty binding hooks which just
  1741. * return success.
  1742. *
  1743. * \note On success, the synthetic component replaces the previously enabled
  1744. * component (if any), but the topology is not actually modified until
  1745. * hwloc_topology_load().
  1746. */
  1747. HWLOC_DECLSPEC int hwloc_topology_set_synthetic(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict description);
  1748. /** \brief Enable XML-file based topology.
  1749. *
  1750. * Gather topology information from the XML file given at \p xmlpath.
  1751. * Setting the environment variable HWLOC_XMLFILE may also result in this behavior.
  1752. * This file may have been generated earlier with hwloc_topology_export_xml() in hwloc/export.h,
  1753. * or lstopo file.xml.
  1754. *
  1755. * Note that this function does not actually load topology
  1756. * information; it just tells hwloc where to load it from. You'll
  1757. * still need to invoke hwloc_topology_load() to actually load the
  1758. * topology information.
  1759. *
  1760. * \return 0 on success.
  1761. * \return -1 with errno set to \c EINVAL on failure to read the XML file.
  1762. *
  1763. * \note See also hwloc_topology_set_userdata_import_callback()
  1764. * for importing application-specific object userdata.
  1765. *
  1766. * \note For convenience, this backend provides empty binding hooks which just
  1767. * return success. To have hwloc still actually call OS-specific hooks, the
  1768. * ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM has to be set to assert that the loaded
  1769. * file is really the underlying system.
  1770. *
  1771. * \note On success, the XML component replaces the previously enabled
  1772. * component (if any), but the topology is not actually modified until
  1773. * hwloc_topology_load().
  1774. */
  1775. HWLOC_DECLSPEC int hwloc_topology_set_xml(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict xmlpath);
  1776. /** \brief Enable XML based topology using a memory buffer (instead of
  1777. * a file, as with hwloc_topology_set_xml()).
  1778. *
  1779. * Gather topology information from the XML memory buffer given at \p
  1780. * buffer and of length \p size. This buffer may have been filled
  1781. * earlier with hwloc_topology_export_xmlbuffer() in hwloc/export.h.
  1782. *
  1783. * Note that this function does not actually load topology
  1784. * information; it just tells hwloc where to load it from. You'll
  1785. * still need to invoke hwloc_topology_load() to actually load the
  1786. * topology information.
  1787. *
  1788. * \return 0 on success.
  1789. * \return -1 with errno set to \c EINVAL on failure to read the XML buffer.
  1790. *
  1791. * \note See also hwloc_topology_set_userdata_import_callback()
  1792. * for importing application-specific object userdata.
  1793. *
  1794. * \note For convenience, this backend provides empty binding hooks which just
  1795. * return success. To have hwloc still actually call OS-specific hooks, the
  1796. * ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM has to be set to assert that the loaded
  1797. * file is really the underlying system.
  1798. *
  1799. * \note On success, the XML component replaces the previously enabled
  1800. * component (if any), but the topology is not actually modified until
  1801. * hwloc_topology_load().
  1802. */
  1803. HWLOC_DECLSPEC int hwloc_topology_set_xmlbuffer(hwloc_topology_t __hwloc_restrict topology, const char * __hwloc_restrict buffer, int size);
  1804. /** \brief Flags to be passed to hwloc_topology_set_components()
  1805. */
  1806. enum hwloc_topology_components_flag_e {
  1807. /** \brief Blacklist the target component from being used.
  1808. * \hideinitializer
  1809. */
  1810. HWLOC_TOPOLOGY_COMPONENTS_FLAG_BLACKLIST = (1UL<<0)
  1811. };
  1812. /** \brief Prevent a discovery component from being used for a topology.
  1813. *
  1814. * \p name is the name of the discovery component that should not be used
  1815. * when loading topology \p topology. The name is a string such as "cuda".
  1816. *
  1817. * For components with multiple phases, it may also be suffixed with the name
  1818. * of a phase, for instance "linux:io".
  1819. *
  1820. * \p flags should be ::HWLOC_TOPOLOGY_COMPONENTS_FLAG_BLACKLIST.
  1821. *
  1822. * This may be used to avoid expensive parts of the discovery process.
  1823. * For instance, CUDA-specific discovery may be expensive and unneeded
  1824. * while generic I/O discovery could still be useful.
  1825. *
  1826. * \return 0 on success.
  1827. * \return -1 on error, for instance if flags are invalid.
  1828. */
  1829. HWLOC_DECLSPEC int hwloc_topology_set_components(hwloc_topology_t __hwloc_restrict topology, unsigned long flags, const char * __hwloc_restrict name);
  1830. /** @} */
  1831. /** \defgroup hwlocality_configuration Topology Detection Configuration and Query
  1832. *
  1833. * Several functions can optionally be called between hwloc_topology_init() and
  1834. * hwloc_topology_load() to configure how the detection should be performed,
  1835. * e.g. to ignore some objects types, define a synthetic topology, etc.
  1836. *
  1837. * @{
  1838. */
  1839. /** \brief Flags to be set onto a topology context before load.
  1840. *
  1841. * Flags should be given to hwloc_topology_set_flags().
  1842. * They may also be returned by hwloc_topology_get_flags().
  1843. */
  1844. enum hwloc_topology_flags_e {
  1845. /** \brief Detect the whole system, ignore reservations, include disallowed objects.
  1846. *
  1847. * Gather all online resources, even if some were disabled by the administrator.
  1848. * For instance, ignore Linux Cgroup/Cpusets and gather all processors and memory nodes.
  1849. * However offline PUs and NUMA nodes are still ignored.
  1850. *
  1851. * When this flag is not set, PUs and NUMA nodes that are disallowed are not added to the topology.
  1852. * Parent objects (package, core, cache, etc.) are added only if some of their children are allowed.
  1853. * All existing PUs and NUMA nodes in the topology are allowed.
  1854. * hwloc_topology_get_allowed_cpuset() and hwloc_topology_get_allowed_nodeset()
  1855. * are equal to the root object cpuset and nodeset.
  1856. *
  1857. * When this flag is set, the actual sets of allowed PUs and NUMA nodes are given
  1858. * by hwloc_topology_get_allowed_cpuset() and hwloc_topology_get_allowed_nodeset().
  1859. * They may be smaller than the root object cpuset and nodeset.
  1860. *
  1861. * If the current topology is exported to XML and reimported later, this flag
  1862. * should be set again in the reimported topology so that disallowed resources
  1863. * are reimported as well.
  1864. * \hideinitializer
  1865. */
  1866. HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED = (1UL<<0),
  1867. /** \brief Assume that the selected backend provides the topology for the
  1868. * system on which we are running.
  1869. *
  1870. * This forces hwloc_topology_is_thissystem() to return 1, i.e. makes hwloc assume that
  1871. * the selected backend provides the topology for the system on which we are running,
  1872. * even if it is not the OS-specific backend but the XML backend for instance.
  1873. * This means making the binding functions actually call the OS-specific
  1874. * system calls and really do binding, while the XML backend would otherwise
  1875. * provide empty hooks just returning success.
  1876. *
  1877. * Setting the environment variable HWLOC_THISSYSTEM may also result in the
  1878. * same behavior.
  1879. *
  1880. * This can be used for efficiency reasons to first detect the topology once,
  1881. * save it to an XML file, and quickly reload it later through the XML
  1882. * backend, but still having binding functions actually do bind.
  1883. * \hideinitializer
  1884. */
  1885. HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM = (1UL<<1),
  1886. /** \brief Get the set of allowed resources from the local operating system even if the topology was loaded from XML or synthetic description.
  1887. *
  1888. * If the topology was loaded from XML or from a synthetic string,
  1889. * restrict it by applying the current process restrictions such as
  1890. * Linux Cgroup/Cpuset.
  1891. *
  1892. * This is useful when the topology is not loaded directly from
  1893. * the local machine (e.g. for performance reason) and it comes
  1894. * with all resources, while the running process is restricted
  1895. * to only parts of the machine.
  1896. *
  1897. * This flag is ignored unless ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM is
  1898. * also set since the loaded topology must match the underlying machine
  1899. * where restrictions will be gathered from.
  1900. *
  1901. * Setting the environment variable HWLOC_THISSYSTEM_ALLOWED_RESOURCES
  1902. * would result in the same behavior.
  1903. * \hideinitializer
  1904. */
  1905. HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES = (1UL<<2),
  1906. /** \brief Import support from the imported topology.
  1907. *
  1908. * When importing a XML topology from a remote machine, binding is
  1909. * disabled by default (see ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM).
  1910. * This disabling is also marked by putting zeroes in the corresponding
  1911. * supported feature bits reported by hwloc_topology_get_support().
  1912. *
  1913. * The flag ::HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT actually imports
  1914. * support bits from the remote machine. It also sets the flag
  1915. * \p imported_support in the struct hwloc_topology_misc_support array.
  1916. * If the imported XML did not contain any support information
  1917. * (exporter hwloc is too old), this flag is not set.
  1918. *
  1919. * Note that these supported features are only relevant for the hwloc
  1920. * installation that actually exported the XML topology
  1921. * (it may vary with the operating system, or with how hwloc was compiled).
  1922. *
  1923. * Note that setting this flag however does not enable binding for the
  1924. * locally imported hwloc topology, it only reports what the remote
  1925. * hwloc and machine support.
  1926. *
  1927. */
  1928. HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT = (1UL<<3),
  1929. /** \brief Do not consider resources outside of the process CPU binding.
  1930. *
  1931. * If the binding of the process is limited to a subset of cores,
  1932. * ignore the other cores during discovery.
  1933. *
  1934. * The resulting topology is identical to what a call to hwloc_topology_restrict()
  1935. * would generate, but this flag also prevents hwloc from ever touching other
  1936. * resources during the discovery.
  1937. *
  1938. * This flag especially tells the x86 backend to never temporarily
  1939. * rebind a thread on any excluded core. This is useful on Windows
  1940. * because such temporary rebinding can change the process binding.
  1941. * Another use-case is to avoid cores that would not be able to
  1942. * perform the hwloc discovery anytime soon because they are busy
  1943. * executing some high-priority real-time tasks.
  1944. *
  1945. * If process CPU binding is not supported,
  1946. * the thread CPU binding is considered instead if supported,
  1947. * or the flag is ignored.
  1948. *
  1949. * This flag requires ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM as well
  1950. * since binding support is required.
  1951. */
  1952. HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING = (1UL<<4),
  1953. /** \brief Do not consider resources outside of the process memory binding.
  1954. *
  1955. * If the binding of the process is limited to a subset of NUMA nodes,
  1956. * ignore the other NUMA nodes during discovery.
  1957. *
  1958. * The resulting topology is identical to what a call to hwloc_topology_restrict()
  1959. * would generate, but this flag also prevents hwloc from ever touching other
  1960. * resources during the discovery.
  1961. *
  1962. * This flag is meant to be used together with
  1963. * ::HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING when both cores
  1964. * and NUMA nodes should be ignored outside of the process binding.
  1965. *
  1966. * If process memory binding is not supported,
  1967. * the thread memory binding is considered instead if supported,
  1968. * or the flag is ignored.
  1969. *
  1970. * This flag requires ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM as well
  1971. * since binding support is required.
  1972. */
  1973. HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_MEMBINDING = (1UL<<5),
  1974. /** \brief Do not ever modify the process or thread binding during discovery.
  1975. *
  1976. * This flag disables all hwloc discovery steps that require a change of
  1977. * the process or thread binding. This currently only affects the x86
  1978. * backend which gets entirely disabled.
  1979. *
  1980. * This is useful when hwloc_topology_load() is called while the
  1981. * application also creates additional threads or modifies the binding.
  1982. *
  1983. * This flag is also a strict way to make sure the process binding will
  1984. * not change to due thread binding changes on Windows
  1985. * (see ::HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING).
  1986. */
  1987. HWLOC_TOPOLOGY_FLAG_DONT_CHANGE_BINDING = (1UL<<6),
  1988. /** \brief Ignore distances.
  1989. *
  1990. * Ignore distance information from the operating systems (and from XML)
  1991. * and hence do not use distances for grouping.
  1992. */
  1993. HWLOC_TOPOLOGY_FLAG_NO_DISTANCES = (1UL<<7),
  1994. /** \brief Ignore memory attributes.
  1995. *
  1996. * Ignore memory attribues from the operating systems (and from XML).
  1997. */
  1998. HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS = (1UL<<8),
  1999. /** \brief Ignore CPU Kinds.
  2000. *
  2001. * Ignore CPU kind information from the operating systems (and from XML).
  2002. */
  2003. HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS = (1UL<<9)
  2004. };
  2005. /** \brief Set OR'ed flags to non-yet-loaded topology.
  2006. *
  2007. * Set a OR'ed set of ::hwloc_topology_flags_e onto a topology that was not yet loaded.
  2008. *
  2009. * If this function is called multiple times, the last invocation will erase
  2010. * and replace the set of flags that was previously set.
  2011. *
  2012. * By default, no flags are set (\c 0).
  2013. *
  2014. * The flags set in a topology may be retrieved with hwloc_topology_get_flags().
  2015. *
  2016. * \return 0 on success.
  2017. * \return -1 on error, for instance if flags are invalid.
  2018. */
  2019. HWLOC_DECLSPEC int hwloc_topology_set_flags (hwloc_topology_t topology, unsigned long flags);
  2020. /** \brief Get OR'ed flags of a topology.
  2021. *
  2022. * Get the OR'ed set of ::hwloc_topology_flags_e of a topology.
  2023. *
  2024. * If hwloc_topology_set_flags() was not called earlier,
  2025. * no flags are set (\c 0 is returned).
  2026. *
  2027. * \return the flags previously set with hwloc_topology_set_flags().
  2028. *
  2029. * \note This function may also be called after hwloc_topology_load().
  2030. */
  2031. HWLOC_DECLSPEC unsigned long hwloc_topology_get_flags (hwloc_topology_t topology);
  2032. /** \brief Does the topology context come from this system?
  2033. *
  2034. * \return 1 if this topology context was built using the system
  2035. * running this program.
  2036. * \return 0 instead (for instance if using another file-system root,
  2037. * a XML topology file, or a synthetic topology).
  2038. *
  2039. * \note This function may also be called after hwloc_topology_load().
  2040. */
  2041. HWLOC_DECLSPEC int hwloc_topology_is_thissystem(hwloc_topology_t __hwloc_restrict topology) __hwloc_attribute_pure;
  2042. /** \brief Flags describing actual discovery support for this topology. */
  2043. struct hwloc_topology_discovery_support {
  2044. /** \brief Detecting the number of PU objects is supported. */
  2045. unsigned char pu;
  2046. /** \brief Detecting the number of NUMA nodes is supported. */
  2047. unsigned char numa;
  2048. /** \brief Detecting the amount of memory in NUMA nodes is supported. */
  2049. unsigned char numa_memory;
  2050. /** \brief Detecting and identifying PU objects that are not available to the current process is supported. */
  2051. unsigned char disallowed_pu;
  2052. /** \brief Detecting and identifying NUMA nodes that are not available to the current process is supported. */
  2053. unsigned char disallowed_numa;
  2054. /** \brief Detecting the efficiency of CPU kinds is supported, see \ref hwlocality_cpukinds. */
  2055. unsigned char cpukind_efficiency;
  2056. };
  2057. /** \brief Flags describing actual PU binding support for this topology.
  2058. *
  2059. * A flag may be set even if the feature isn't supported in all cases
  2060. * (e.g. binding to random sets of non-contiguous objects).
  2061. */
  2062. struct hwloc_topology_cpubind_support {
  2063. /** Binding the whole current process is supported. */
  2064. unsigned char set_thisproc_cpubind;
  2065. /** Getting the binding of the whole current process is supported. */
  2066. unsigned char get_thisproc_cpubind;
  2067. /** Binding a whole given process is supported. */
  2068. unsigned char set_proc_cpubind;
  2069. /** Getting the binding of a whole given process is supported. */
  2070. unsigned char get_proc_cpubind;
  2071. /** Binding the current thread only is supported. */
  2072. unsigned char set_thisthread_cpubind;
  2073. /** Getting the binding of the current thread only is supported. */
  2074. unsigned char get_thisthread_cpubind;
  2075. /** Binding a given thread only is supported. */
  2076. unsigned char set_thread_cpubind;
  2077. /** Getting the binding of a given thread only is supported. */
  2078. unsigned char get_thread_cpubind;
  2079. /** Getting the last processors where the whole current process ran is supported */
  2080. unsigned char get_thisproc_last_cpu_location;
  2081. /** Getting the last processors where a whole process ran is supported */
  2082. unsigned char get_proc_last_cpu_location;
  2083. /** Getting the last processors where the current thread ran is supported */
  2084. unsigned char get_thisthread_last_cpu_location;
  2085. };
  2086. /** \brief Flags describing actual memory binding support for this topology.
  2087. *
  2088. * A flag may be set even if the feature isn't supported in all cases
  2089. * (e.g. binding to random sets of non-contiguous objects).
  2090. */
  2091. struct hwloc_topology_membind_support {
  2092. /** Binding the whole current process is supported. */
  2093. unsigned char set_thisproc_membind;
  2094. /** Getting the binding of the whole current process is supported. */
  2095. unsigned char get_thisproc_membind;
  2096. /** Binding a whole given process is supported. */
  2097. unsigned char set_proc_membind;
  2098. /** Getting the binding of a whole given process is supported. */
  2099. unsigned char get_proc_membind;
  2100. /** Binding the current thread only is supported. */
  2101. unsigned char set_thisthread_membind;
  2102. /** Getting the binding of the current thread only is supported. */
  2103. unsigned char get_thisthread_membind;
  2104. /** Binding a given memory area is supported. */
  2105. unsigned char set_area_membind;
  2106. /** Getting the binding of a given memory area is supported. */
  2107. unsigned char get_area_membind;
  2108. /** Allocating a bound memory area is supported. */
  2109. unsigned char alloc_membind;
  2110. /** First-touch policy is supported. */
  2111. unsigned char firsttouch_membind;
  2112. /** Bind policy is supported. */
  2113. unsigned char bind_membind;
  2114. /** Interleave policy is supported. */
  2115. unsigned char interleave_membind;
  2116. /** Next-touch migration policy is supported. */
  2117. unsigned char nexttouch_membind;
  2118. /** Migration flags is supported. */
  2119. unsigned char migrate_membind;
  2120. /** Getting the last NUMA nodes where a memory area was allocated is supported */
  2121. unsigned char get_area_memlocation;
  2122. };
  2123. /** \brief Flags describing miscellaneous features.
  2124. */
  2125. struct hwloc_topology_misc_support {
  2126. /** Support was imported when importing another topology, see ::HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT. */
  2127. unsigned char imported_support;
  2128. };
  2129. /** \brief Set of flags describing actual support for this topology.
  2130. *
  2131. * This is retrieved with hwloc_topology_get_support() and will be valid until
  2132. * the topology object is destroyed. Note: the values are correct only after
  2133. * discovery.
  2134. */
  2135. struct hwloc_topology_support {
  2136. struct hwloc_topology_discovery_support *discovery;
  2137. struct hwloc_topology_cpubind_support *cpubind;
  2138. struct hwloc_topology_membind_support *membind;
  2139. struct hwloc_topology_misc_support *misc;
  2140. };
  2141. /** \brief Retrieve the topology support.
  2142. *
  2143. * Each flag indicates whether a feature is supported.
  2144. * If set to 0, the feature is not supported.
  2145. * If set to 1, the feature is supported, but the corresponding
  2146. * call may still fail in some corner cases.
  2147. *
  2148. * These features are also listed by hwloc-info \--support
  2149. *
  2150. * The reported features are what the current topology supports
  2151. * on the current machine. If the topology was exported to XML
  2152. * from another machine and later imported here, support still
  2153. * describes what is supported for this imported topology after
  2154. * import. By default, binding will be reported as unsupported
  2155. * in this case (see ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM).
  2156. *
  2157. * Topology flag ::HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT may be used
  2158. * to report the supported features of the original remote machine
  2159. * instead. If it was successfully imported, \p imported_support
  2160. * will be set in the struct hwloc_topology_misc_support array.
  2161. *
  2162. * \return A pointer to a support structure.
  2163. *
  2164. * \note The function cannot return \c NULL.
  2165. * \note The returned pointer should not be freed, it belongs to the hwloc library.
  2166. *
  2167. * \note This function may be called before or after hwloc_topology_load()
  2168. * but the support structure only contains valid information after.
  2169. */
  2170. HWLOC_DECLSPEC const struct hwloc_topology_support *hwloc_topology_get_support(hwloc_topology_t __hwloc_restrict topology);
  2171. /** \brief Type filtering flags.
  2172. *
  2173. * By default, most objects are kept (::HWLOC_TYPE_FILTER_KEEP_ALL).
  2174. * Instruction caches, I/O and Misc objects are ignored by default (::HWLOC_TYPE_FILTER_KEEP_NONE).
  2175. * Die and Group levels are ignored unless they bring structure (::HWLOC_TYPE_FILTER_KEEP_STRUCTURE).
  2176. *
  2177. * Note that group objects are also ignored individually (without the entire level)
  2178. * when they do not bring structure.
  2179. */
  2180. enum hwloc_type_filter_e {
  2181. /** \brief Keep all objects of this type.
  2182. *
  2183. * Cannot be set for ::HWLOC_OBJ_GROUP (groups are designed only to add more structure to the topology).
  2184. * \hideinitializer
  2185. */
  2186. HWLOC_TYPE_FILTER_KEEP_ALL = 0,
  2187. /** \brief Ignore all objects of this type.
  2188. *
  2189. * The bottom-level type ::HWLOC_OBJ_PU, the ::HWLOC_OBJ_NUMANODE type, and
  2190. * the top-level type ::HWLOC_OBJ_MACHINE may not be ignored.
  2191. * \hideinitializer
  2192. */
  2193. HWLOC_TYPE_FILTER_KEEP_NONE = 1,
  2194. /** \brief Only ignore objects if their entire level does not bring any structure.
  2195. *
  2196. * Keep the entire level of objects if at least one of these objects adds
  2197. * structure to the topology. An object brings structure when it has multiple
  2198. * children and it is not the only child of its parent.
  2199. *
  2200. * If all objects in the level are the only child of their parent, and if none
  2201. * of them has multiple children, the entire level is removed.
  2202. *
  2203. * Cannot be set for I/O and Misc objects since the topology structure does not matter there.
  2204. * \hideinitializer
  2205. */
  2206. HWLOC_TYPE_FILTER_KEEP_STRUCTURE = 2,
  2207. /** \brief Only keep likely-important objects of the given type.
  2208. *
  2209. * It is only useful for I/O object types.
  2210. * For ::HWLOC_OBJ_PCI_DEVICE and ::HWLOC_OBJ_OS_DEVICE, it means that only objects
  2211. * of major/common kinds are kept (storage, network, OpenFabrics, CUDA,
  2212. * OpenCL, RSMI, NVML, and displays).
  2213. * Also, only OS devices directly attached on PCI (e.g. no USB) are reported.
  2214. * For ::HWLOC_OBJ_BRIDGE, it means that bridges are kept only if they have children.
  2215. *
  2216. * This flag equivalent to ::HWLOC_TYPE_FILTER_KEEP_ALL for Normal, Memory and Misc types
  2217. * since they are likely important.
  2218. * \hideinitializer
  2219. */
  2220. HWLOC_TYPE_FILTER_KEEP_IMPORTANT = 3
  2221. };
  2222. /** \brief Set the filtering for the given object type.
  2223. *
  2224. * \return 0 on success, -1 on error.
  2225. */
  2226. HWLOC_DECLSPEC int hwloc_topology_set_type_filter(hwloc_topology_t topology, hwloc_obj_type_t type, enum hwloc_type_filter_e filter);
  2227. /** \brief Get the current filtering for the given object type.
  2228. *
  2229. * \return 0 on success, -1 on error.
  2230. */
  2231. HWLOC_DECLSPEC int hwloc_topology_get_type_filter(hwloc_topology_t topology, hwloc_obj_type_t type, enum hwloc_type_filter_e *filter);
  2232. /** \brief Set the filtering for all object types.
  2233. *
  2234. * If some types do not support this filtering, they are silently ignored.
  2235. *
  2236. * \return 0 on success, -1 on error.
  2237. */
  2238. HWLOC_DECLSPEC int hwloc_topology_set_all_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
  2239. /** \brief Set the filtering for all CPU cache object types.
  2240. *
  2241. * Memory-side caches are not involved since they are not CPU caches.
  2242. *
  2243. * \return 0 on success, -1 on error.
  2244. */
  2245. HWLOC_DECLSPEC int hwloc_topology_set_cache_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
  2246. /** \brief Set the filtering for all CPU instruction cache object types.
  2247. *
  2248. * Memory-side caches are not involved since they are not CPU caches.
  2249. *
  2250. * \return 0 on success, -1 on error.
  2251. */
  2252. HWLOC_DECLSPEC int hwloc_topology_set_icache_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
  2253. /** \brief Set the filtering for all I/O object types.
  2254. *
  2255. * \return 0 on success, -1 on error.
  2256. */
  2257. HWLOC_DECLSPEC int hwloc_topology_set_io_types_filter(hwloc_topology_t topology, enum hwloc_type_filter_e filter);
  2258. /** \brief Set the topology-specific userdata pointer.
  2259. *
  2260. * Each topology may store one application-given private data pointer.
  2261. * It is initialized to \c NULL.
  2262. * hwloc will never modify it.
  2263. *
  2264. * Use it as you wish, after hwloc_topology_init() and until hwloc_topolog_destroy().
  2265. *
  2266. * This pointer is not exported to XML.
  2267. */
  2268. HWLOC_DECLSPEC void hwloc_topology_set_userdata(hwloc_topology_t topology, const void *userdata);
  2269. /** \brief Retrieve the topology-specific userdata pointer.
  2270. *
  2271. * Retrieve the application-given private data pointer that was
  2272. * previously set with hwloc_topology_set_userdata().
  2273. *
  2274. * \return A pointer to the private-data if any.
  2275. * \return \c NULL if no private-data was previoulsy set.
  2276. */
  2277. HWLOC_DECLSPEC void * hwloc_topology_get_userdata(hwloc_topology_t topology);
  2278. /** @} */
  2279. /** \defgroup hwlocality_tinker Modifying a loaded Topology
  2280. * @{
  2281. */
  2282. /** \brief Flags to be given to hwloc_topology_restrict(). */
  2283. enum hwloc_restrict_flags_e {
  2284. /** \brief Remove all objects that became CPU-less.
  2285. * By default, only objects that contain no PU and no memory are removed.
  2286. * This flag may not be used with ::HWLOC_RESTRICT_FLAG_BYNODESET.
  2287. * \hideinitializer
  2288. */
  2289. HWLOC_RESTRICT_FLAG_REMOVE_CPULESS = (1UL<<0),
  2290. /** \brief Restrict by nodeset instead of CPU set.
  2291. * Only keep objects whose nodeset is included or partially included in the given set.
  2292. * This flag may not be used with ::HWLOC_RESTRICT_FLAG_REMOVE_CPULESS.
  2293. */
  2294. HWLOC_RESTRICT_FLAG_BYNODESET = (1UL<<3),
  2295. /** \brief Remove all objects that became Memory-less.
  2296. * By default, only objects that contain no PU and no memory are removed.
  2297. * This flag may only be used with ::HWLOC_RESTRICT_FLAG_BYNODESET.
  2298. * \hideinitializer
  2299. */
  2300. HWLOC_RESTRICT_FLAG_REMOVE_MEMLESS = (1UL<<4),
  2301. /** \brief Move Misc objects to ancestors if their parents are removed during restriction.
  2302. * If this flag is not set, Misc objects are removed when their parents are removed.
  2303. * \hideinitializer
  2304. */
  2305. HWLOC_RESTRICT_FLAG_ADAPT_MISC = (1UL<<1),
  2306. /** \brief Move I/O objects to ancestors if their parents are removed during restriction.
  2307. * If this flag is not set, I/O devices and bridges are removed when their parents are removed.
  2308. * \hideinitializer
  2309. */
  2310. HWLOC_RESTRICT_FLAG_ADAPT_IO = (1UL<<2)
  2311. };
  2312. /** \brief Restrict the topology to the given CPU set or nodeset.
  2313. *
  2314. * Topology \p topology is modified so as to remove all objects that
  2315. * are not included (or partially included) in the CPU set \p set.
  2316. * All objects CPU and node sets are restricted accordingly.
  2317. *
  2318. * By default, \p set is a CPU set. It means that the set of PUs in
  2319. * the topology is restricted. Once some PUs got removed, their parents
  2320. * may also get removed recursively if they became child-less.
  2321. *
  2322. * If ::HWLOC_RESTRICT_FLAG_BYNODESET is passed in \p flags,
  2323. * \p set is considered a nodeset instead of a CPU set.
  2324. * It means that the set of NUMA nodes in the topology is restricted
  2325. * (instead of PUs). Once some NUMA nodes got removed, their parents
  2326. * may also get removed recursively if they became child-less.
  2327. *
  2328. * \p flags is a OR'ed set of ::hwloc_restrict_flags_e.
  2329. *
  2330. * \note Restricting the topology removes some locality information,
  2331. * hence the remaining objects may get reordered (including PUs and NUMA nodes),
  2332. * and their logical indexes may change.
  2333. *
  2334. * \note This call may not be reverted by restricting back to a larger
  2335. * set. Once dropped during restriction, objects may not be brought
  2336. * back, except by loading another topology with hwloc_topology_load().
  2337. *
  2338. * \return 0 on success.
  2339. *
  2340. * \return -1 with errno set to \c EINVAL if the input set is invalid.
  2341. * The topology is not modified in this case.
  2342. *
  2343. * \return -1 with errno set to \c ENOMEM on failure to allocate internal data.
  2344. * The topology is reinitialized in this case. It should be either
  2345. * destroyed with hwloc_topology_destroy() or configured and loaded again.
  2346. */
  2347. HWLOC_DECLSPEC int hwloc_topology_restrict(hwloc_topology_t __hwloc_restrict topology, hwloc_const_bitmap_t set, unsigned long flags);
  2348. /** \brief Flags to be given to hwloc_topology_allow(). */
  2349. enum hwloc_allow_flags_e {
  2350. /** \brief Mark all objects as allowed in the topology.
  2351. *
  2352. * \p cpuset and \p nođeset given to hwloc_topology_allow() must be \c NULL.
  2353. * \hideinitializer */
  2354. HWLOC_ALLOW_FLAG_ALL = (1UL<<0),
  2355. /** \brief Only allow objects that are available to the current process.
  2356. *
  2357. * The topology must have ::HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM so that the set
  2358. * of available resources can actually be retrieved from the operating system.
  2359. *
  2360. * \p cpuset and \p nođeset given to hwloc_topology_allow() must be \c NULL.
  2361. * \hideinitializer */
  2362. HWLOC_ALLOW_FLAG_LOCAL_RESTRICTIONS = (1UL<<1),
  2363. /** \brief Allow a custom set of objects, given to hwloc_topology_allow() as \p cpuset and/or \p nodeset parameters.
  2364. * \hideinitializer */
  2365. HWLOC_ALLOW_FLAG_CUSTOM = (1UL<<2)
  2366. };
  2367. /** \brief Change the sets of allowed PUs and NUMA nodes in the topology.
  2368. *
  2369. * This function only works if the ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED
  2370. * was set on the topology. It does not modify any object, it only changes
  2371. * the sets returned by hwloc_topology_get_allowed_cpuset() and
  2372. * hwloc_topology_get_allowed_nodeset().
  2373. *
  2374. * It is notably useful when importing a topology from another process
  2375. * running in a different Linux Cgroup.
  2376. *
  2377. * \p flags must be set to one flag among ::hwloc_allow_flags_e.
  2378. *
  2379. * \return 0 on success, -1 on error.
  2380. *
  2381. * \note Removing objects from a topology should rather be performed with
  2382. * hwloc_topology_restrict().
  2383. */
  2384. 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);
  2385. /** \brief Add a MISC object as a leaf of the topology
  2386. *
  2387. * A new MISC object will be created and inserted into the topology at the
  2388. * position given by parent. It is appended to the list of existing Misc children,
  2389. * without ever adding any intermediate hierarchy level. This is useful for
  2390. * annotating the topology without actually changing the hierarchy.
  2391. *
  2392. * \p name is supposed to be unique across all Misc objects in the topology.
  2393. * It will be duplicated to setup the new object attributes.
  2394. *
  2395. * The new leaf object will not have any \p cpuset.
  2396. *
  2397. * \return the newly-created object
  2398. *
  2399. * \return \c NULL on error.
  2400. *
  2401. * \return \c NULL if Misc objects are filtered-out of the topology (::HWLOC_TYPE_FILTER_KEEP_NONE).
  2402. *
  2403. * \note If \p name contains some non-printable characters, they will
  2404. * be dropped when exporting to XML, see hwloc_topology_export_xml() in hwloc/export.h.
  2405. */
  2406. HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_misc_object(hwloc_topology_t topology, hwloc_obj_t parent, const char *name);
  2407. /** \brief Allocate a Group object to insert later with hwloc_topology_insert_group_object().
  2408. *
  2409. * This function returns a new Group object.
  2410. *
  2411. * The caller should (at least) initialize its sets before inserting
  2412. * the object in the topology. See hwloc_topology_insert_group_object().
  2413. *
  2414. * \return The allocated object on success.
  2415. * \return \c NULL on error.
  2416. */
  2417. HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_alloc_group_object(hwloc_topology_t topology);
  2418. /** \brief Add more structure to the topology by adding an intermediate Group
  2419. *
  2420. * The caller should first allocate a new Group object with hwloc_topology_alloc_group_object().
  2421. * Then it must setup at least one of its CPU or node sets to specify
  2422. * the final location of the Group in the topology.
  2423. * Then the object can be passed to this function for actual insertion in the topology.
  2424. *
  2425. * Either the cpuset or nodeset field (or both, if compatible) must be set
  2426. * to a non-empty bitmap. The complete_cpuset or complete_nodeset may be set
  2427. * instead if inserting with respect to the complete topology
  2428. * (including disallowed, offline or unknown objects).
  2429. * If grouping several objects, hwloc_obj_add_other_obj_sets() is an easy way
  2430. * to build the Group sets iteratively.
  2431. * These sets cannot be larger than the current topology, or they would get
  2432. * restricted silently.
  2433. * The core will setup the other sets after actual insertion.
  2434. *
  2435. * The \p subtype object attribute may be defined (to a dynamically
  2436. * allocated string) to display something else than "Group" as the
  2437. * type name for this object in lstopo.
  2438. * Custom name-value info pairs may be added with hwloc_obj_add_info() after
  2439. * insertion.
  2440. *
  2441. * The group \p dont_merge attribute may be set to \c 1 to prevent
  2442. * the hwloc core from ever merging this object with another
  2443. * hierarchically-identical object.
  2444. * This is useful when the Group itself describes an important feature
  2445. * that cannot be exposed anywhere else in the hierarchy.
  2446. *
  2447. * The group \p kind attribute may be set to a high value such
  2448. * as \c 0xffffffff to tell hwloc that this new Group should always
  2449. * be discarded in favor of any existing Group with the same locality.
  2450. *
  2451. * \note Inserting a group adds some locality information to the topology,
  2452. * hence the existing objects may get reordered (including PUs and NUMA nodes),
  2453. * and their logical indexes may change.
  2454. *
  2455. * \return The inserted object if it was properly inserted.
  2456. *
  2457. * \return An existing object if the Group was merged or discarded
  2458. * because the topology already contained an object at the same
  2459. * location (the Group did not add any hierarchy information).
  2460. *
  2461. * \return \c NULL if the insertion failed because of conflicting sets in topology tree.
  2462. *
  2463. * \return \c NULL if Group objects are filtered-out of the topology (::HWLOC_TYPE_FILTER_KEEP_NONE).
  2464. *
  2465. * \return \c NULL if the object was discarded because no set was
  2466. * initialized in the Group before insert, or all of them were empty.
  2467. */
  2468. HWLOC_DECLSPEC hwloc_obj_t hwloc_topology_insert_group_object(hwloc_topology_t topology, hwloc_obj_t group);
  2469. /** \brief Setup object cpusets/nodesets by OR'ing another object's sets.
  2470. *
  2471. * For each defined cpuset or nodeset in \p src, allocate the corresponding set
  2472. * in \p dst and add \p src to it by OR'ing sets.
  2473. *
  2474. * This function is convenient between hwloc_topology_alloc_group_object()
  2475. * and hwloc_topology_insert_group_object(). It builds the sets of the new Group
  2476. * that will be inserted as a new intermediate parent of several objects.
  2477. *
  2478. * \return 0 on success.
  2479. * \return -1 with errno set to \c ENOMEM if some internal reallocation failed.
  2480. */
  2481. HWLOC_DECLSPEC int hwloc_obj_add_other_obj_sets(hwloc_obj_t dst, hwloc_obj_t src);
  2482. /** \brief Refresh internal structures after topology modification.
  2483. *
  2484. * Modifying the topology (by restricting, adding objects, modifying structures
  2485. * such as distances or memory attributes, etc.) may cause some internal caches
  2486. * to become invalid. These caches are automatically refreshed when accessed
  2487. * but this refreshing is not thread-safe.
  2488. *
  2489. * This function is not thread-safe either, but it is a good way to end a
  2490. * non-thread-safe phase of topology modification. Once this refresh is done,
  2491. * multiple threads may concurrently consult the topology, objects, distances,
  2492. * attributes, etc.
  2493. *
  2494. * See also \ref threadsafety
  2495. *
  2496. * \return 0 on success.
  2497. * \return -1 on error, for instance if some internal reallocation failed.
  2498. */
  2499. HWLOC_DECLSPEC int hwloc_topology_refresh(hwloc_topology_t topology);
  2500. /** @} */
  2501. #ifdef __cplusplus
  2502. } /* extern "C" */
  2503. #endif
  2504. /* high-level helpers */
  2505. #include "hwloc/helper.h"
  2506. /* inline code of some functions above */
  2507. #include "hwloc/inlines.h"
  2508. /* memory attributes */
  2509. #include "hwloc/memattrs.h"
  2510. /* kinds of CPU cores */
  2511. #include "hwloc/cpukinds.h"
  2512. /* exporting to XML or synthetic */
  2513. #include "hwloc/export.h"
  2514. /* distances */
  2515. #include "hwloc/distances.h"
  2516. /* topology diffs */
  2517. #include "hwloc/diff.h"
  2518. /* deprecated headers */
  2519. #include "hwloc/deprecated.h"
  2520. #endif /* HWLOC_H */