Hardware Locality (hwloc) 3.0.0a1-git
plugins.h
1/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright © 2013-2026 Inria. All rights reserved.
4 * Copyright © 2016 Cisco Systems, Inc. All rights reserved.
5 * Copyright © 2025 Siemens Corporation and/or its affiliates. All rights reserved.
6 * See COPYING in top-level directory.
7 */
8
9#ifndef HWLOC_PLUGINS_H
10#define HWLOC_PLUGINS_H
11
15
16struct hwloc_backend;
17
18#include "hwloc.h"
19
20#ifdef HWLOC_INSIDE_PLUGIN
21/* needed for hwloc_plugin_check_namespace() */
22#ifdef HWLOC_HAVE_LTDL
23#include <ltdl.h>
24#elif !defined(HWLOC_WIN_SYS)
25#include <dlfcn.h>
26#endif
27#endif
28
29
30
37
47 const char *name;
48
52 unsigned phases;
53
63
67 struct hwloc_backend * (*instantiate)(struct hwloc_topology *topology, struct hwloc_disc_component *component, unsigned excluded_phases, const void *data1, const void *data2, const void *data3);
68
81 unsigned priority;
82
87
92 struct hwloc_disc_component * next;
93};
94
139
145
156
161
163 unsigned long flags;
164};
165
186 struct hwloc_disc_component * component;
188 struct hwloc_topology * topology;
190 int envvar_forced;
192 struct hwloc_backend * next;
193
197 unsigned phases;
198
200 unsigned long flags;
201
209
213 void (*disable)(struct hwloc_backend *backend);
214
220 int (*discover)(struct hwloc_backend *backend, struct hwloc_disc_status *status);
221
226 int (*get_pci_busid_cpuset)(struct hwloc_backend *backend, struct hwloc_pcidev_attr_s *busid, hwloc_bitmap_t cpuset);
227};
228
230#define HWLOC_BACKEND_PRIVATE_DATA(_backend) (void*)(((char*)(_backend)) + sizeof(struct hwloc_backend))
231
238HWLOC_DECLSPEC struct hwloc_backend * hwloc_backend_alloc(struct hwloc_topology *topology, struct hwloc_disc_component *component, unsigned long private_data_size);
239
241HWLOC_DECLSPEC int hwloc_backend_enable(struct hwloc_backend *backend);
242
244
245
246
247
254
263
271 unsigned abi;
272
290 int (*init)(unsigned long flags);
291
303 void (*finalize)(unsigned long flags);
304
307
309 unsigned long flags;
310
312 void * data;
313};
314
336static __hwloc_inline int
337hwloc_plugin_check_namespace(const char *pluginname __hwloc_attribute_unused, const char *symbol __hwloc_attribute_unused)
338{
339#ifdef HWLOC_INSIDE_PLUGIN
340 void *sym;
341#ifdef HWLOC_HAVE_LTDL
342 lt_dlhandle handle = lt_dlopen(NULL);
343#elif defined(HWLOC_WIN_SYS)
344 HMODULE handle = GetModuleHandleA(NULL);
345#else
346 void *handle = dlopen(NULL, RTLD_NOW|RTLD_LOCAL);
347#endif
348 if (!handle)
349 /* cannot check, assume things will work */
350 return 0;
351#ifdef HWLOC_HAVE_LTDL
352 sym = lt_dlsym(handle, symbol);
353 lt_dlclose(handle);
354#elif defined(HWLOC_WIN_SYS)
355 sym = GetModuleHandleA("hwloc.dll");
356 FreeLibrary(handle);
357#else
358 sym = dlsym(handle, symbol);
359 dlclose(handle);
360#endif
361 if (!sym) {
362 static int verboseenv_checked = 0;
363 static int verboseenv_value = 0;
364 if (!verboseenv_checked) {
365 const char *verboseenv = getenv("HWLOC_PLUGINS_VERBOSE");
366 verboseenv_value = verboseenv ? atoi(verboseenv) : 0;
367 verboseenv_checked = 1;
368 }
369 if (verboseenv_value)
370 fprintf(stderr, "Plugin `%s' disabling itself because it cannot find the `%s' core symbol.\n",
371 pluginname, symbol);
372 return -1;
373 }
374#endif /* HWLOC_INSIDE_PLUGIN */
375 return 0;
376}
377
379
380
381
382
389
403HWLOC_DECLSPEC unsigned long hwloc_show_errors_mask(void);
404
405#define HWLOC_SHOW_ERRORS(_flag) (hwloc_show_errors_mask() & (_flag))
406
407#define HWLOC_SHOWMSG_CRITICAL (1UL<<0)
408/* Kinds of messages: failure to initialize CUDA, etc.
409 * At least one of these should be passed to HWLOC_SHOW_ERRORS() */
410#define HWLOC_SHOWMSG_BIND (1UL<<1) /* binding */
411#define HWLOC_SHOWMSG_SYNTHETIC (1UL<<2) /* synthetic */
412#define HWLOC_SHOWMSG_XML (1UL<<3) /* XML */
413#define HWLOC_SHOWMSG_COMPONENTS (1UL<<4) /* Components */
414#define HWLOC_SHOWMSG_PLUGINS (1UL<<5) /* Plugins */
415#define HWLOC_SHOWMSG_RSMI (1UL<<6) /* RSMI */
416#define HWLOC_SHOWMSG_CUDA (1UL<<7) /* CUDA */
417#define HWLOC_SHOWMSG_NVML (1UL<<8) /* NVML */
418#define HWLOC_SHOWMSG_L0 (1UL<<9) /* L0 */
419#define HWLOC_SHOWMSG_OPENCL (1UL<<10) /* OpenCL */
420#define HWLOC_SHOWMSG_GL (1UL<<11) /* GL */
421#define HWLOC_SHOWMSG_OS (1UL<<12) /* Operating system */
422#define HWLOC_SHOWMSG_PCI (1UL<<13) /* PCI */
423#define HWLOC_SHOWMSG_X86 (1UL<<14) /* x86 */
424#define HWLOC_SHOWMSG_CORE (1UL<<15) /* Issues in hwloc core */
425#define HWLOC_SHOWMSG_MISC (1UL<<16) /* Misc messages that don't belong anywhere else */
426#define HWLOC_SHOWMSG_USER (1UL<<17) /* Error caused by invalid user-given information (environment variables, etc) */
427/* all messages */
428#define HWLOC_SHOWMSG_ALL (~0UL)
429
430
459HWLOC_DECLSPEC hwloc_obj_t
460hwloc__insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t root,
461 hwloc_obj_t obj, const char *reason);
462
479HWLOC_DECLSPEC void hwloc_insert_object_by_parent(struct hwloc_topology *topology, hwloc_obj_t parent, hwloc_obj_t obj);
480
485HWLOC_DECLSPEC hwloc_obj_t hwloc_alloc_setup_object(hwloc_topology_t topology, hwloc_obj_type_t type, unsigned os_index);
486
496
504HWLOC_DECLSPEC int hwloc_topology_reconnect(hwloc_topology_t topology, unsigned long flags __hwloc_attribute_unused);
505
507
508
509
510
517
522static __hwloc_inline int
524{
525 unsigned baseclass = classid >> 8;
526 return (baseclass == 0x03 /* PCI_BASE_CLASS_DISPLAY */
527 || baseclass == 0x02 /* PCI_BASE_CLASS_NETWORK */
528 || baseclass == 0x01 /* PCI_BASE_CLASS_STORAGE */
529 || baseclass == 0x00 /* Unclassified, for Atos/Bull BXI */
530 || baseclass == 0x0b /* PCI_BASE_CLASS_PROCESSOR */
531 || classid == 0x0c04 /* PCI_CLASS_SERIAL_FIBER */
532 || classid == 0x0c06 /* PCI_CLASS_SERIAL_INFINIBAND */
533 || classid == 0x0502 /* PCI_CLASS_MEMORY_CXL */
534 || baseclass == 0x06 /* PCI_BASE_CLASS_BRIDGE with non-PCI downstream. the core will drop the useless ones later */
535 || baseclass == 0x12 /* Processing Accelerators */);
536}
537
542static __hwloc_inline int
547
554static __hwloc_inline int
556{
558 hwloc_topology_get_type_filter(topology, type, &filter);
559 assert(filter != HWLOC_TYPE_FILTER_KEEP_IMPORTANT); /* IMPORTANT only used for I/O */
560 return filter == HWLOC_TYPE_FILTER_KEEP_NONE ? 0 : 1;
561}
562
567static __hwloc_inline int
569{
570 hwloc_obj_type_t type = obj->type;
572 hwloc_topology_get_type_filter(topology, type, &filter);
573 if (filter == HWLOC_TYPE_FILTER_KEEP_NONE)
574 return 0;
575 if (filter == HWLOC_TYPE_FILTER_KEEP_IMPORTANT) {
576 if (type == HWLOC_OBJ_PCI_DEVICE)
578 if (type == HWLOC_OBJ_OS_DEVICE)
580 }
581 return 1;
582}
583
585
586
587
588
595
600HWLOC_DECLSPEC unsigned hwloc_pcicommon_configspace_find_cap(const unsigned char *config, unsigned cap);
601
607HWLOC_DECLSPEC int hwloc_pcicommon_configspace_find_linkspeed(const unsigned char *config, unsigned offset, float *linkspeed);
608
613HWLOC_DECLSPEC hwloc_obj_type_t hwloc_pcicommon_configspace_check_bridge_type(unsigned device_class, const unsigned char *config);
614
621HWLOC_DECLSPEC int hwloc_pcicommon_configspace_find_bridge_buses(unsigned domain, unsigned bus, unsigned dev, unsigned func,
622 unsigned *secondary_busp, unsigned *subordinate_busp,
623 const unsigned char *config);
624
629HWLOC_DECLSPEC void hwloc_pcicommon_tree_insert_by_busid(struct hwloc_obj **treep, struct hwloc_obj *obj);
630
636HWLOC_DECLSPEC int hwloc_pcicommon_tree_attach(struct hwloc_topology *topology, struct hwloc_obj *tree);
637
639
640
641
642
649
661HWLOC_DECLSPEC struct hwloc_obj * hwloc_pci_get_parent_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func);
662
669HWLOC_DECLSPEC struct hwloc_obj * hwloc_pci_get_obj_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func);
670
671
673
674
675
676
683
686
695 const char *name, unsigned long kind,
696 unsigned long flags);
697
709HWLOC_DECLSPEC int
712 unsigned nbobjs, hwloc_obj_t *objs,
713 hwloc_uint64_t *values,
714 unsigned long flags);
715
722HWLOC_DECLSPEC int
725 unsigned long flags);
726
728
729
730
731
732#endif /* HWLOC_PLUGINS_H */
struct hwloc_bitmap_s * hwloc_bitmap_t
Set of bits represented as an opaque pointer to an internal bitmap.
Definition bitmap.h:70
hwloc_obj_t hwloc_alloc_setup_object(hwloc_topology_t topology, hwloc_obj_type_t type, unsigned os_index)
Allocate and initialize an object of the given type and physical index.
void hwloc_insert_object_by_parent(struct hwloc_topology *topology, hwloc_obj_t parent, hwloc_obj_t obj)
Insert an object somewhere in the topology.
int hwloc_topology_reconnect(hwloc_topology_t topology, unsigned long flags)
Request a reconnection of children and levels in the topology.
hwloc_obj_t hwloc__insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t root, hwloc_obj_t obj, const char *reason)
Add an object to the topology.
int hwloc_obj_add_children_sets(hwloc_obj_t obj)
Setup object cpusets/nodesets by OR'ing its children.
unsigned long hwloc_show_errors_mask(void)
Get the mask of error messages to display.
int hwloc_backend_distances_add_commit(hwloc_topology_t topology, hwloc_backend_distances_add_handle_t handle, unsigned long flags)
Commit a new distances structure.
int hwloc_backend_distances_add_values(hwloc_topology_t topology, hwloc_backend_distances_add_handle_t handle, unsigned nbobjs, hwloc_obj_t *objs, hwloc_uint64_t *values, unsigned long flags)
Specify the objects and values in a new empty distances structure.
hwloc_backend_distances_add_handle_t hwloc_backend_distances_add_create(hwloc_topology_t topology, const char *name, unsigned long kind, unsigned long flags)
Create a new empty distances structure.
void * hwloc_backend_distances_add_handle_t
Handle to a new distances structure during its addition to the topology.
Definition plugins.h:685
int hwloc_filter_check_keep_object(hwloc_topology_t topology, hwloc_obj_t obj)
Check whether the given object should be filtered-out.
Definition plugins.h:568
int hwloc_filter_check_osdev_subtype_important(hwloc_obj_osdev_types_t subtype)
Check whether the given OS device subtype is important.
Definition plugins.h:543
int hwloc_filter_check_pcidev_subtype_important(unsigned classid)
Check whether the given PCI device classid is important.
Definition plugins.h:523
int hwloc_filter_check_keep_object_type(hwloc_topology_t topology, hwloc_obj_type_t type)
Check whether a non-I/O object type should be filtered-out.
Definition plugins.h:555
int hwloc_pcicommon_configspace_find_bridge_buses(unsigned domain, unsigned bus, unsigned dev, unsigned func, unsigned *secondary_busp, unsigned *subordinate_busp, const unsigned char *config)
Fills the attributes of the given PCI bridge using the given PCI config space.
int hwloc_pcicommon_configspace_find_linkspeed(const unsigned char *config, unsigned offset, float *linkspeed)
Fill linkspeed by reading the PCI config space where PCI_CAP_ID_EXP is at position offset.
int hwloc_pcicommon_tree_attach(struct hwloc_topology *topology, struct hwloc_obj *tree)
Add some hostbridges on top of the given tree of PCI objects and attach them to the topology.
void hwloc_pcicommon_tree_insert_by_busid(struct hwloc_obj **treep, struct hwloc_obj *obj)
Insert a PCI object in the given PCI tree by looking at PCI bus IDs.
hwloc_obj_type_t hwloc_pcicommon_configspace_check_bridge_type(unsigned device_class, const unsigned char *config)
Return the hwloc object type (PCI device or Bridge) for the given class and configuration space.
unsigned hwloc_pcicommon_configspace_find_cap(const unsigned char *config, unsigned cap)
Return the offset of the given capability in the PCI config space buffer.
struct hwloc_obj * hwloc_pci_get_obj_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func)
Find the PCI device or bridge matching a PCI bus ID exactly.
struct hwloc_obj * hwloc_pci_get_parent_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func)
Find the object or a parent of a PCI bus ID.
int hwloc_topology_get_type_filter(hwloc_topology_t topology, hwloc_obj_type_t type, enum hwloc_type_filter_e *filter)
Get the current filtering for the given object type.
hwloc_type_filter_e
Type filtering flags.
Definition hwloc.h:2614
@ HWLOC_TYPE_FILTER_KEEP_NONE
Ignore all objects of this type.
Definition hwloc.h:2628
@ HWLOC_TYPE_FILTER_KEEP_IMPORTANT
Only keep likely-important objects of the given type.
Definition hwloc.h:2659
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition hwloc.h:788
int hwloc_backend_enable(struct hwloc_backend *backend)
Enable a previously allocated and setup backend.
struct hwloc_backend * hwloc_backend_alloc(struct hwloc_topology *topology, struct hwloc_disc_component *component, unsigned long private_data_size)
Allocate a backend structure, set good default values, initialize backend->component and topology,...
enum hwloc_disc_phase_e hwloc_disc_phase_t
Discovery phase.
hwloc_disc_phase_e
Discovery phase.
Definition plugins.h:96
hwloc_disc_status_flag_e
Discovery status flags.
Definition plugins.h:141
@ HWLOC_DISC_PHASE_CPU
CPU discovery.
Definition plugins.h:105
@ HWLOC_DISC_PHASE_PCI
Attach PCI devices and bridges to existing CPU objects.
Definition plugins.h:113
@ HWLOC_DISC_PHASE_ANNOTATE
Annotating existing objects, adding distances, etc.
Definition plugins.h:125
@ HWLOC_DISC_PHASE_MISC
Misc objects that gets added below anything else.
Definition plugins.h:121
@ HWLOC_DISC_PHASE_IO
I/O discovery that requires PCI devices (OS devices such as OpenCL, CUDA, etc.).
Definition plugins.h:117
@ HWLOC_DISC_PHASE_GLOBAL
xml or synthetic, platform-specific components. Discovers everything including CPU,...
Definition plugins.h:101
@ HWLOC_DISC_PHASE_ANNOTATE_INDEPENDENT
Annotating existing objects with a OS/hardware independent things, for instance converting PCI vendor...
Definition plugins.h:130
@ HWLOC_DISC_PHASE_MEMORY
Attach memory to existing CPU objects.
Definition plugins.h:109
@ HWLOC_DISC_PHASE_TWEAK
Final tweaks to a ready-to-use topology. This phase runs once the topology is loaded,...
Definition plugins.h:137
@ HWLOC_DISC_STATUS_FLAG_GOT_ALLOWED_RESOURCES
The sets of allowed resources were already retrieved.
Definition plugins.h:143
enum hwloc_component_type_e hwloc_component_type_t
Generic component type.
hwloc_component_type_e
Generic component type.
Definition plugins.h:256
int hwloc_plugin_check_namespace(const char *pluginname, const char *symbol)
Make sure that plugins can lookup core symbols.
Definition plugins.h:337
@ HWLOC_COMPONENT_TYPE_DISC
The data field must point to a struct hwloc_disc_component.
Definition plugins.h:258
@ HWLOC_COMPONENT_TYPE_XML
The data field must point to a struct hwloc_xml_component.
Definition plugins.h:261
unsigned long hwloc_obj_osdev_types_t
Type(s) of a OS device. OR'ed set of hwloc_obj_osdev_type_e.
Definition hwloc.h:428
hwloc_obj_type_t
Type of topology object.
Definition hwloc.h:202
@ HWLOC_OBJ_OSDEV_DMA
Operating system dma engine device. For instance the "dma0chan0" DMA channel on Linux.
Definition hwloc.h:419
@ HWLOC_OBJ_OS_DEVICE
Operating system device (filtered out by default).
Definition hwloc.h:334
@ HWLOC_OBJ_PCI_DEVICE
PCI device (filtered out by default).
Definition hwloc.h:324
struct hwloc_obj * hwloc_obj_t
Convenience typedef; a pointer to a struct hwloc_obj.
Definition hwloc.h:691
Discovery backend structure.
Definition plugins.h:184
void(* disable)(struct hwloc_backend *backend)
Callback for freeing things stored inside the private data. May be NULL.
Definition plugins.h:213
unsigned long flags
Backend flags, currently always 0.
Definition plugins.h:200
int(* get_pci_busid_cpuset)(struct hwloc_backend *backend, struct hwloc_pcidev_attr_s *busid, hwloc_bitmap_t cpuset)
Callback to retrieve the locality of a PCI object. Called by the PCI core when attaching PCI hierarch...
Definition plugins.h:226
int is_thissystem
Backend-specific 'is_thissystem' property. Set to 0 if the backend disables the thissystem flag for t...
Definition plugins.h:208
int(* discover)(struct hwloc_backend *backend, struct hwloc_disc_status *status)
Main discovery callback. returns -1 on error, either because it couldn't add its objects ot the exist...
Definition plugins.h:220
unsigned phases
Discovery phases performed by this component, possibly without some of them if excluded by other comp...
Definition plugins.h:197
Generic component structure.
Definition plugins.h:269
unsigned abi
Component ABI version, set to HWLOC_COMPONENT_ABI.
Definition plugins.h:271
void(* finalize)(unsigned long flags)
Process-wide component termination callback.
Definition plugins.h:303
void * data
Component data, pointing to a struct hwloc_disc_component or struct hwloc_xml_component.
Definition plugins.h:312
hwloc_component_type_t type
Component type.
Definition plugins.h:306
unsigned long flags
Component flags, unused for now.
Definition plugins.h:309
int(* init)(unsigned long flags)
Process-wide component initialization callback.
Definition plugins.h:290
Discovery component structure.
Definition plugins.h:43
const char * name
Name. If this component is built as a plugin, this name does not have to match the plugin filename.
Definition plugins.h:47
unsigned phases
Discovery phases performed by this component. OR'ed set of hwloc_disc_phase_t.
Definition plugins.h:52
unsigned excluded_phases
Component phases to exclude, as an OR'ed set of hwloc_disc_phase_t.
Definition plugins.h:62
unsigned enabled_by_default
Enabled by default. If unset, if will be disabled unless explicitly requested.
Definition plugins.h:86
unsigned priority
Component priority. Used to sort topology->components, higher priority first. Also used to decide bet...
Definition plugins.h:81
Discovery status structure.
Definition plugins.h:151
unsigned excluded_phases
Dynamically excluded phases. If a component decides during discovery that some phases are no longer n...
Definition plugins.h:160
hwloc_disc_phase_t phase
The current discovery phase that is performed. Must match one of the phases in the component phases f...
Definition plugins.h:155
unsigned long flags
OR'ed set of hwloc_disc_status_flag_e.
Definition plugins.h:163
hwloc_obj_osdev_types_t types
OR'ed set of at least one hwloc_obj_osdev_type_e.
Definition hwloc.h:771
unsigned short class_id
The class number (first two bytes, without the prog_if).
Definition hwloc.h:740
Structure of a topology object.
Definition hwloc.h:492
char * name
Object-specific name if any. Mostly used for identifying OS devices and Misc objects where a name str...
Definition hwloc.h:504
hwloc_obj_type_t type
Type of object.
Definition hwloc.h:494
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition hwloc.h:511
struct hwloc_obj_attr_u::hwloc_pcidev_attr_s pcidev
struct hwloc_obj_attr_u::hwloc_osdev_attr_s osdev