Hardware Locality (hwloc)  2.1.0
plugins.h
1 /*
2  * Copyright © 2013-2019 Inria. All rights reserved.
3  * Copyright © 2016 Cisco Systems, Inc. All rights reserved.
4  * See COPYING in top-level directory.
5  */
6 
7 #ifndef HWLOC_PLUGINS_H
8 #define HWLOC_PLUGINS_H
9 
14 struct hwloc_backend;
15 
16 #include "hwloc.h"
17 
18 #ifdef HWLOC_INSIDE_PLUGIN
19 /* needed for hwloc_plugin_check_namespace() */
20 #include <ltdl.h>
21 #endif
22 
23 
24 
38  const char *name;
39 
43  unsigned phases;
44 
53  unsigned excluded_phases;
54 
58  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);
59 
72  unsigned priority;
73 
78 
83  struct hwloc_disc_component * next;
84 };
85 
96 typedef enum hwloc_disc_phase_e {
102 
106 
110 
114 
118 
122 
126 
134 
139 };
140 
151 
155  unsigned excluded_phases;
156 
158  unsigned long flags;
159 };
160 
181  struct hwloc_disc_component * component;
183  struct hwloc_topology * topology;
185  int envvar_forced;
187  struct hwloc_backend * next;
188 
192  unsigned phases;
193 
195  unsigned long flags;
196 
204 
206  void * private_data;
210  void (*disable)(struct hwloc_backend *backend);
211 
217  int (*discover)(struct hwloc_backend *backend, struct hwloc_disc_status *status);
218 
223  int (*get_pci_busid_cpuset)(struct hwloc_backend *backend, struct hwloc_pcidev_attr_s *busid, hwloc_bitmap_t cpuset);
224 };
225 
229 HWLOC_DECLSPEC struct hwloc_backend * hwloc_backend_alloc(struct hwloc_topology *topology, struct hwloc_disc_component *component);
230 
232 HWLOC_DECLSPEC int hwloc_backend_enable(struct hwloc_backend *backend);
233 
247 
251 
259  unsigned abi;
260 
278  int (*init)(unsigned long flags);
279 
291  void (*finalize)(unsigned long flags);
292 
294  hwloc_component_type_t type;
295 
297  unsigned long flags;
298 
300  void * data;
301 };
302 
336 HWLOC_DECLSPEC struct hwloc_obj *hwloc_insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t obj);
337 
339 typedef void (*hwloc_report_error_t)(const char * msg, int line);
341 HWLOC_DECLSPEC void hwloc_report_os_error(const char * msg, int line);
343 HWLOC_DECLSPEC int hwloc_hide_errors(void);
344 
351 HWLOC_DECLSPEC struct hwloc_obj *hwloc__insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t root, hwloc_obj_t obj, hwloc_report_error_t report_error);
352 
369 HWLOC_DECLSPEC void hwloc_insert_object_by_parent(struct hwloc_topology *topology, hwloc_obj_t parent, hwloc_obj_t obj);
370 
376 
385 HWLOC_DECLSPEC int hwloc_obj_add_children_sets(hwloc_obj_t obj);
386 
394 HWLOC_DECLSPEC int hwloc_topology_reconnect(hwloc_topology_t topology, unsigned long flags __hwloc_attribute_unused);
395 
417 static __hwloc_inline int
418 hwloc_plugin_check_namespace(const char *pluginname __hwloc_attribute_unused, const char *symbol __hwloc_attribute_unused)
419 {
420 #ifdef HWLOC_INSIDE_PLUGIN
421  lt_dlhandle handle;
422  void *sym;
423  handle = lt_dlopen(NULL);
424  if (!handle)
425  /* cannot check, assume things will work */
426  return 0;
427  sym = lt_dlsym(handle, symbol);
428  lt_dlclose(handle);
429  if (!sym) {
430  static int verboseenv_checked = 0;
431  static int verboseenv_value = 0;
432  if (!verboseenv_checked) {
433  const char *verboseenv = getenv("HWLOC_PLUGINS_VERBOSE");
434  verboseenv_value = verboseenv ? atoi(verboseenv) : 0;
435  verboseenv_checked = 1;
436  }
437  if (verboseenv_value)
438  fprintf(stderr, "Plugin `%s' disabling itself because it cannot find the `%s' core symbol.\n",
439  pluginname, symbol);
440  return -1;
441  }
442 #endif /* HWLOC_INSIDE_PLUGIN */
443  return 0;
444 }
445 
459 static __hwloc_inline int
461 {
462  unsigned baseclass = classid >> 8;
463  return (baseclass == 0x03 /* PCI_BASE_CLASS_DISPLAY */
464  || baseclass == 0x02 /* PCI_BASE_CLASS_NETWORK */
465  || baseclass == 0x01 /* PCI_BASE_CLASS_STORAGE */
466  || baseclass == 0x0b /* PCI_BASE_CLASS_PROCESSOR */
467  || classid == 0x0c04 /* PCI_CLASS_SERIAL_FIBER */
468  || classid == 0x0c06 /* PCI_CLASS_SERIAL_INFINIBAND */
469  || baseclass == 0x12 /* Processing Accelerators */);
470 }
471 
476 static __hwloc_inline int
478 {
479  return (subtype != HWLOC_OBJ_OSDEV_DMA);
480 }
481 
488 static __hwloc_inline int
490 {
492  hwloc_topology_get_type_filter(topology, type, &filter);
493  assert(filter != HWLOC_TYPE_FILTER_KEEP_IMPORTANT); /* IMPORTANT only used for I/O */
494  return filter == HWLOC_TYPE_FILTER_KEEP_NONE ? 0 : 1;
495 }
496 
501 static __hwloc_inline int
503 {
504  hwloc_obj_type_t type = obj->type;
506  hwloc_topology_get_type_filter(topology, type, &filter);
507  if (filter == HWLOC_TYPE_FILTER_KEEP_NONE)
508  return 0;
509  if (filter == HWLOC_TYPE_FILTER_KEEP_IMPORTANT) {
510  if (type == HWLOC_OBJ_PCI_DEVICE)
512  if (type == HWLOC_OBJ_OS_DEVICE)
514  }
515  return 1;
516 }
517 
531 HWLOC_DECLSPEC unsigned hwloc_pcidisc_find_cap(const unsigned char *config, unsigned cap);
532 
538 HWLOC_DECLSPEC int hwloc_pcidisc_find_linkspeed(const unsigned char *config, unsigned offset, float *linkspeed);
539 
544 HWLOC_DECLSPEC hwloc_obj_type_t hwloc_pcidisc_check_bridge_type(unsigned device_class, const unsigned char *config);
545 
552 HWLOC_DECLSPEC int hwloc_pcidisc_find_bridge_buses(unsigned domain, unsigned bus, unsigned dev, unsigned func,
553  unsigned *secondary_busp, unsigned *subordinate_busp,
554  const unsigned char *config);
555 
560 HWLOC_DECLSPEC void hwloc_pcidisc_tree_insert_by_busid(struct hwloc_obj **treep, struct hwloc_obj *obj);
561 
567 HWLOC_DECLSPEC int hwloc_pcidisc_tree_attach(struct hwloc_topology *topology, struct hwloc_obj *tree);
568 
585 HWLOC_DECLSPEC struct hwloc_obj * hwloc_pci_find_parent_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func);
586 
592 #endif /* HWLOC_PLUGINS_H */
int hwloc_hide_errors(void)
Check whether insertion errors are hidden.
hwloc_obj_type_t type
Type of object.
Definition: hwloc.h:383
hwloc_component_type_e
Generic component type.
Definition: plugins.h:244
struct hwloc_obj * parent
Parent, NULL if root (Machine object)
Definition: hwloc.h:431
Attach memory to existing CPU objects.
Definition: plugins.h:109
unsigned os_index
OS-provided physical index number. It is not guaranteed unique across the entire machine, except for PUs and NUMA nodes. Set to HWLOC_UNKNOWN_INDEX if unknown or irrelevant for this object.
Definition: hwloc.h:386
char * subtype
Subtype string to better describe the type field.
Definition: hwloc.h:384
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.
Generic component structure.
Definition: plugins.h:257
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.
Only keep likely-important objects of the given type.
Definition: hwloc.h:2108
int hwloc_backend_enable(struct hwloc_backend *backend)
Enable a previously allocated and setup backend.
Discovery component structure.
Definition: plugins.h:34
The data field must point to a struct hwloc_disc_component.
Definition: plugins.h:246
struct hwloc_obj_attr_u::hwloc_osdev_attr_s osdev
unsigned abi
Component ABI version, set to HWLOC_COMPONENT_ABI.
Definition: plugins.h:259
The sets of allowed resources were already retrieved.
Definition: plugins.h:138
static int hwloc_plugin_check_namespace(const char *pluginname, const char *symbol)
Make sure that plugins can lookup core symbols.
Definition: plugins.h:418
Misc objects that gets added below anything else.
Definition: plugins.h:121
enum hwloc_disc_phase_e hwloc_disc_phase_t
Discovery phase.
unsigned long flags
Component flags, unused for now.
Definition: plugins.h:297
struct hwloc_obj * hwloc_insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t obj)
Add an object to the topology.
Final tweaks to a ready-to-use topology. This phase runs once the topology is loaded, before it is returned to the topology. Hence it may only use the main hwloc API for modifying the topology, for instance by restricting it, adding info attributes, etc.
Definition: plugins.h:132
Discovery backend structure.
Definition: plugins.h:179
Attach PCI devices and bridges to existing CPU objects.
Definition: plugins.h:113
struct hwloc_bitmap_s * hwloc_bitmap_t
Set of bits represented as an opaque pointer to an internal bitmap.
Definition: bitmap.h:68
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...
unsigned excluded_phases
Dynamically excluded phases. If a component decides during discovery that some phases are no longer n...
Definition: plugins.h:155
struct hwloc_topology * hwloc_topology_t
Topology context.
Definition: hwloc.h:667
unsigned long flags
Backend flags, currently always 0.
Definition: plugins.h:195
Structure of a topology object.
Definition: hwloc.h:381
hwloc_component_type_t type
Component type.
Definition: plugins.h:294
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.
void(* disable)(struct hwloc_backend *backend)
Callback for freeing the private_data. May be NULL.
Definition: plugins.h:210
int is_thissystem
Backend-specific &#39;is_thissystem&#39; property. Set to 0 if the backend disables the thissystem flag for t...
Definition: plugins.h:203
int hwloc_topology_reconnect(hwloc_topology_t topology, unsigned long flags)
Request a reconnection of children and levels in the topology.
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:150
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.
void hwloc_report_os_error(const char *msg, int line)
Report an insertion error from a backend.
enum hwloc_obj_osdev_type_e hwloc_obj_osdev_type_t
Type of a OS device.
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__insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t root, hwloc_obj_t obj, hwloc_report_error_t report_error)
Add an object to the topology and specify which error callback to use.
unsigned hwloc_pcidisc_find_cap(const unsigned char *config, unsigned cap)
Return the offset of the given capability in the PCI config space buffer.
hwloc_obj_type_t
Definition: hwloc.h:177
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...
static 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:502
static 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:477
I/O discovery that requires PCI devices (OS devices such as OpenCL, CUDA, etc.).
Definition: plugins.h:117
struct hwloc_obj_attr_u::hwloc_pcidev_attr_s pcidev
unsigned phases
Discovery phases performed by this component. OR&#39;ed set of hwloc_disc_phase_t.
Definition: plugins.h:43
hwloc_disc_status_flag_e
Discovery status flags.
Definition: plugins.h:136
Ignore all objects of this type.
Definition: hwloc.h:2079
hwloc_type_filter_e
Type filtering flags.
Definition: hwloc.h:2065
void * data
Component data, pointing to a struct hwloc_disc_component or struct hwloc_xml_component.
Definition: plugins.h:300
unsigned excluded_phases
Component phases to exclude, as an OR&#39;ed set of hwloc_disc_phase_t.
Definition: plugins.h:53
void(* hwloc_report_error_t)(const char *msg, int line)
Type of error callbacks during object insertion.
Definition: plugins.h:339
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.
static 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:489
unsigned enabled_by_default
Enabled by default. If unset, if will be disabled unless explicitly requested.
Definition: plugins.h:77
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:38
int hwloc_obj_add_children_sets(hwloc_obj_t obj)
Setup object cpusets/nodesets by OR&#39;ing its children.
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...
struct hwloc_obj * hwloc_pci_find_parent_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func)
Find the normal parent of a PCI bus ID.
Operating system dma engine device. For instance the "dma0chan0" DMA channel on Linux.
Definition: hwloc.h:334
int(* discover)(struct hwloc_backend *backend, struct hwloc_disc_status *status)
Main discovery callback. returns -1 on error, either because it couldn&#39;t add its objects ot the exist...
Definition: plugins.h:217
CPU discovery.
Definition: plugins.h:105
unsigned short class_id
Definition: hwloc.h:619
static int hwloc_filter_check_pcidev_subtype_important(unsigned classid)
Check whether the given PCI device classid is important.
Definition: plugins.h:460
unsigned phases
Discovery phases performed by this component, possibly without some of them if excluded by other comp...
Definition: plugins.h:192
Operating system device (filtered out by default). They are not added to the topology unless I/O disc...
Definition: hwloc.h:269
unsigned long flags
OR&#39;ed set of hwloc_disc_status_flag_e.
Definition: plugins.h:158
hwloc_obj_osdev_type_t type
Definition: hwloc.h:641
enum hwloc_component_type_e hwloc_component_type_t
Generic component type.
void * private_data
Backend private data, or NULL if none.
Definition: plugins.h:206
unsigned priority
Component priority. Used to sort topology->components, higher priority first. Also used to decide bet...
Definition: plugins.h:72
PCI device (filtered out by default). They are not added to the topology unless I/O discovery is enab...
Definition: hwloc.h:262
xml or synthetic, platform-specific components such as bgq. Discovers everything including CPU...
Definition: plugins.h:101
Discovery status structure.
Definition: plugins.h:146
hwloc_disc_phase_e
Discovery phase.
Definition: plugins.h:96
union hwloc_obj_attr_u * attr
Object type-specific Attributes, may be NULL if no attribute value was found.
Definition: hwloc.h:400
The data field must point to a struct hwloc_xml_component.
Definition: plugins.h:249
Annotating existing objects, adding distances, etc.
Definition: plugins.h:125