Hardware Locality (hwloc)  2.12.3rc1-git
plugins.h
1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * Copyright © 2013-2024 Inria. All rights reserved.
4  * Copyright © 2016 Cisco Systems, Inc. All rights reserved.
5  * See COPYING in top-level directory.
6  */
7 
8 #ifndef HWLOC_PLUGINS_H
9 #define HWLOC_PLUGINS_H
10 
15 struct hwloc_backend;
16 
17 #include "hwloc.h"
18 
19 #ifdef HWLOC_INSIDE_PLUGIN
20 /* needed for hwloc_plugin_check_namespace() */
21 #ifdef HWLOC_HAVE_LTDL
22 #include <ltdl.h>
23 #else
24 #include <dlfcn.h>
25 #endif
26 #endif
27 
28 
29 
46  const char *name;
47 
51  unsigned phases;
52 
61  unsigned excluded_phases;
62 
66  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);
67 
80  unsigned priority;
81 
86 
91  struct hwloc_disc_component * next;
92 };
93 
95 typedef enum hwloc_disc_phase_e {
101 
105 
109 
113 
117 
121 
125 
131  HWLOC_DISC_PHASE_TWEAK = (1U<<7)
133 
138 };
139 
150 
154  unsigned excluded_phases;
155 
157  unsigned long flags;
158 };
159 
180  struct hwloc_disc_component * component;
182  struct hwloc_topology * topology;
184  int envvar_forced;
186  struct hwloc_backend * next;
187 
191  unsigned phases;
192 
194  unsigned long flags;
195 
203 
205  void * private_data;
209  void (*disable)(struct hwloc_backend *backend);
210 
216  int (*discover)(struct hwloc_backend *backend, struct hwloc_disc_status *status);
217 
222  int (*get_pci_busid_cpuset)(struct hwloc_backend *backend, struct hwloc_pcidev_attr_s *busid, hwloc_bitmap_t cpuset);
223 };
224 
228 HWLOC_DECLSPEC struct hwloc_backend * hwloc_backend_alloc(struct hwloc_topology *topology, struct hwloc_disc_component *component);
229 
231 HWLOC_DECLSPEC int hwloc_backend_enable(struct hwloc_backend *backend);
232 
249 
253 
261  unsigned abi;
262 
280  int (*init)(unsigned long flags);
281 
293  void (*finalize)(unsigned long flags);
294 
297 
299  unsigned long flags;
300 
302  void * data;
303 };
304 
326 static __hwloc_inline int
327 hwloc_plugin_check_namespace(const char *pluginname __hwloc_attribute_unused, const char *symbol __hwloc_attribute_unused)
328 {
329 #ifdef HWLOC_INSIDE_PLUGIN
330  void *sym;
331 #ifdef HWLOC_HAVE_LTDL
332  lt_dlhandle handle = lt_dlopen(NULL);
333 #else
334  void *handle = dlopen(NULL, RTLD_NOW|RTLD_LOCAL);
335 #endif
336  if (!handle)
337  /* cannot check, assume things will work */
338  return 0;
339 #ifdef HWLOC_HAVE_LTDL
340  sym = lt_dlsym(handle, symbol);
341  lt_dlclose(handle);
342 #else
343  sym = dlsym(handle, symbol);
344  dlclose(handle);
345 #endif
346  if (!sym) {
347  static int verboseenv_checked = 0;
348  static int verboseenv_value = 0;
349  if (!verboseenv_checked) {
350  const char *verboseenv = getenv("HWLOC_PLUGINS_VERBOSE");
351  verboseenv_value = verboseenv ? atoi(verboseenv) : 0;
352  verboseenv_checked = 1;
353  }
354  if (verboseenv_value)
355  fprintf(stderr, "Plugin `%s' disabling itself because it cannot find the `%s' core symbol.\n",
356  pluginname, symbol);
357  return -1;
358  }
359 #endif /* HWLOC_INSIDE_PLUGIN */
360  return 0;
361 }
362 
392 HWLOC_DECLSPEC int hwloc_hide_errors(void);
393 
394 #define HWLOC_SHOW_CRITICAL_ERRORS() (hwloc_hide_errors() < 2)
395 #define HWLOC_SHOW_ALL_ERRORS() (hwloc_hide_errors() == 0)
396 
425 HWLOC_DECLSPEC hwloc_obj_t
426 hwloc__insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t root,
427  hwloc_obj_t obj, const char *reason);
428 
445 HWLOC_DECLSPEC void hwloc_insert_object_by_parent(struct hwloc_topology *topology, hwloc_obj_t parent, hwloc_obj_t obj);
446 
451 HWLOC_DECLSPEC hwloc_obj_t hwloc_alloc_setup_object(hwloc_topology_t topology, hwloc_obj_type_t type, unsigned os_index);
452 
461 HWLOC_DECLSPEC int hwloc_obj_add_children_sets(hwloc_obj_t obj);
462 
470 HWLOC_DECLSPEC int hwloc_topology_reconnect(hwloc_topology_t topology, unsigned long flags __hwloc_attribute_unused);
471 
488 static __hwloc_inline int
490 {
491  unsigned baseclass = classid >> 8;
492  return (baseclass == 0x03 /* PCI_BASE_CLASS_DISPLAY */
493  || baseclass == 0x02 /* PCI_BASE_CLASS_NETWORK */
494  || baseclass == 0x01 /* PCI_BASE_CLASS_STORAGE */
495  || baseclass == 0x00 /* Unclassified, for Atos/Bull BXI */
496  || baseclass == 0x0b /* PCI_BASE_CLASS_PROCESSOR */
497  || classid == 0x0c04 /* PCI_CLASS_SERIAL_FIBER */
498  || classid == 0x0c06 /* PCI_CLASS_SERIAL_INFINIBAND */
499  || classid == 0x0502 /* PCI_CLASS_MEMORY_CXL */
500  || baseclass == 0x06 /* PCI_BASE_CLASS_BRIDGE with non-PCI downstream. the core will drop the useless ones later */
501  || baseclass == 0x12 /* Processing Accelerators */);
502 }
503 
508 static __hwloc_inline int
510 {
511  return (subtype != HWLOC_OBJ_OSDEV_DMA);
512 }
513 
520 static __hwloc_inline int
522 {
524  hwloc_topology_get_type_filter(topology, type, &filter);
525  assert(filter != HWLOC_TYPE_FILTER_KEEP_IMPORTANT); /* IMPORTANT only used for I/O */
526  return filter == HWLOC_TYPE_FILTER_KEEP_NONE ? 0 : 1;
527 }
528 
533 static __hwloc_inline int
535 {
536  hwloc_obj_type_t type = obj->type;
538  hwloc_topology_get_type_filter(topology, type, &filter);
539  if (filter == HWLOC_TYPE_FILTER_KEEP_NONE)
540  return 0;
541  if (filter == HWLOC_TYPE_FILTER_KEEP_IMPORTANT) {
542  if (type == HWLOC_OBJ_PCI_DEVICE)
544  if (type == HWLOC_OBJ_OS_DEVICE)
546  }
547  return 1;
548 }
549 
566 HWLOC_DECLSPEC unsigned hwloc_pcidisc_find_cap(const unsigned char *config, unsigned cap);
567 
573 HWLOC_DECLSPEC int hwloc_pcidisc_find_linkspeed(const unsigned char *config, unsigned offset, float *linkspeed);
574 
579 HWLOC_DECLSPEC hwloc_obj_type_t hwloc_pcidisc_check_bridge_type(unsigned device_class, const unsigned char *config);
580 
587 HWLOC_DECLSPEC int hwloc_pcidisc_find_bridge_buses(unsigned domain, unsigned bus, unsigned dev, unsigned func,
588  unsigned *secondary_busp, unsigned *subordinate_busp,
589  const unsigned char *config);
590 
595 HWLOC_DECLSPEC void hwloc_pcidisc_tree_insert_by_busid(struct hwloc_obj **treep, struct hwloc_obj *obj);
596 
602 HWLOC_DECLSPEC int hwloc_pcidisc_tree_attach(struct hwloc_topology *topology, struct hwloc_obj *tree);
603 
627 HWLOC_DECLSPEC struct hwloc_obj * hwloc_pci_find_parent_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func);
628 
635 HWLOC_DECLSPEC struct hwloc_obj * hwloc_pci_find_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func);
636 
637 
652 
661  const char *name, unsigned long kind,
662  unsigned long flags);
663 
675 HWLOC_DECLSPEC int
678  unsigned nbobjs, hwloc_obj_t *objs,
679  hwloc_uint64_t *values,
680  unsigned long flags);
681 
688 HWLOC_DECLSPEC int
691  unsigned long flags);
692 
698 #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.
int hwloc_hide_errors(void)
Check whether error messages are hidden.
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:651
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:534
int hwloc_filter_check_pcidev_subtype_important(unsigned classid)
Check whether the given PCI device classid is important.
Definition: plugins.h:489
int hwloc_filter_check_osdev_subtype_important(hwloc_obj_osdev_type_t subtype)
Check whether the given OS device subtype is important.
Definition: plugins.h:509
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:521
int hwloc_pcidisc_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.
hwloc_obj_type_t hwloc_pcidisc_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_pcidisc_find_cap(const unsigned char *config, unsigned cap)
Return the offset of the given capability in the PCI config space buffer.
int hwloc_pcidisc_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.
void hwloc_pcidisc_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.
int hwloc_pcidisc_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.
struct hwloc_obj * hwloc_pci_find_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_find_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:2445
@ HWLOC_TYPE_FILTER_KEEP_NONE
Ignore all objects of this type.
Definition: hwloc.h:2459
@ HWLOC_TYPE_FILTER_KEEP_IMPORTANT
Only keep likely-important objects of the given type.
Definition: hwloc.h:2488
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:748
int hwloc_backend_enable(struct hwloc_backend *backend)
Enable a previously allocated and setup backend.
enum hwloc_disc_phase_e hwloc_disc_phase_t
Discovery phase.
hwloc_disc_phase_e
Discovery phase.
Definition: plugins.h:95
hwloc_disc_status_flag_e
Discovery status flags.
Definition: plugins.h:135
struct hwloc_backend * hwloc_backend_alloc(struct hwloc_topology *topology, struct hwloc_disc_component *component)
Allocate a backend structure, set good default values, initialize backend->component and topology,...
@ HWLOC_DISC_PHASE_CPU
CPU discovery.
Definition: plugins.h:104
@ HWLOC_DISC_PHASE_PCI
Attach PCI devices and bridges to existing CPU objects.
Definition: plugins.h:112
@ HWLOC_DISC_PHASE_ANNOTATE
Annotating existing objects, adding distances, etc.
Definition: plugins.h:124
@ HWLOC_DISC_PHASE_MISC
Misc objects that gets added below anything else.
Definition: plugins.h:120
@ HWLOC_DISC_PHASE_IO
I/O discovery that requires PCI devices (OS devices such as OpenCL, CUDA, etc.).
Definition: plugins.h:116
@ HWLOC_DISC_PHASE_GLOBAL
xml or synthetic, platform-specific components such as bgq. Discovers everything including CPU,...
Definition: plugins.h:100
@ HWLOC_DISC_PHASE_MEMORY
Attach memory to existing CPU objects.
Definition: plugins.h:108
@ HWLOC_DISC_PHASE_TWEAK
Final tweaks to a ready-to-use topology. This phase runs once the topology is loaded,...
Definition: plugins.h:131
@ HWLOC_DISC_STATUS_FLAG_GOT_ALLOWED_RESOURCES
The sets of allowed resources were already retrieved.
Definition: plugins.h:137
enum hwloc_component_type_e hwloc_component_type_t
Generic component type.
hwloc_component_type_e
Generic component type.
Definition: plugins.h:246
int hwloc_plugin_check_namespace(const char *pluginname, const char *symbol)
Make sure that plugins can lookup core symbols.
Definition: plugins.h:327
@ HWLOC_COMPONENT_TYPE_DISC
The data field must point to a struct hwloc_disc_component.
Definition: plugins.h:248
@ HWLOC_COMPONENT_TYPE_XML
The data field must point to a struct hwloc_xml_component.
Definition: plugins.h:251
enum hwloc_obj_osdev_type_e hwloc_obj_osdev_type_t
Type of a OS device.
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:389
@ HWLOC_OBJ_OS_DEVICE
Operating system device (filtered out by default).
Definition: hwloc.h:310
@ HWLOC_OBJ_PCI_DEVICE
PCI device (filtered out by default).
Definition: hwloc.h:300
Discovery backend structure.
Definition: plugins.h:178
void * private_data
Backend private data, or NULL if none.
Definition: plugins.h:205
void(* disable)(struct hwloc_backend *backend)
Callback for freeing the private_data. May be NULL.
Definition: plugins.h:209
unsigned long flags
Backend flags, currently always 0.
Definition: plugins.h:194
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:222
int is_thissystem
Backend-specific 'is_thissystem' property. Set to 0 if the backend disables the thissystem flag for t...
Definition: plugins.h:202
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:216
unsigned phases
Discovery phases performed by this component, possibly without some of them if excluded by other comp...
Definition: plugins.h:191
Generic component structure.
Definition: plugins.h:259
unsigned abi
Component ABI version, set to HWLOC_COMPONENT_ABI.
Definition: plugins.h:261
void(* finalize)(unsigned long flags)
Process-wide component termination callback.
Definition: plugins.h:293
void * data
Component data, pointing to a struct hwloc_disc_component or struct hwloc_xml_component.
Definition: plugins.h:302
hwloc_component_type_t type
Component type.
Definition: plugins.h:296
unsigned long flags
Component flags, unused for now.
Definition: plugins.h:299
int(* init)(unsigned long flags)
Process-wide component initialization callback.
Definition: plugins.h:280
Discovery component structure.
Definition: plugins.h:42
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:46
unsigned phases
Discovery phases performed by this component. OR'ed set of hwloc_disc_phase_t.
Definition: plugins.h:51
unsigned excluded_phases
Component phases to exclude, as an OR'ed set of hwloc_disc_phase_t.
Definition: plugins.h:61
unsigned enabled_by_default
Enabled by default. If unset, if will be disabled unless explicitly requested.
Definition: plugins.h:85
unsigned priority
Component priority. Used to sort topology->components, higher priority first. Also used to decide bet...
Definition: plugins.h:80
Discovery status structure.
Definition: plugins.h:145
unsigned excluded_phases
Dynamically excluded phases. If a component decides during discovery that some phases are no longer n...
Definition: plugins.h:154
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:149
unsigned long flags
OR'ed set of hwloc_disc_status_flag_e.
Definition: plugins.h:157
hwloc_obj_osdev_type_t type
Definition: hwloc.h:722
unsigned short class_id
The class number (first two bytes, without the prog_if).
Definition: hwloc.h:685
Structure of a topology object.
Definition: hwloc.h:437
char * name
Object-specific name if any. Mostly used for identifying OS devices and Misc objects where a name str...
Definition: hwloc.h:449
hwloc_obj_type_t type
Type of object.
Definition: hwloc.h:439
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:456
struct hwloc_obj_attr_u::hwloc_pcidev_attr_s pcidev
struct hwloc_obj_attr_u::hwloc_osdev_attr_s osdev