Hardware Locality (hwloc)
v2.1-20200123.0330.git0a8b367
|
00001 /* 00002 * Copyright © 2013-2019 Inria. All rights reserved. 00003 * Copyright © 2016 Cisco Systems, Inc. All rights reserved. 00004 * See COPYING in top-level directory. 00005 */ 00006 00007 #ifndef HWLOC_PLUGINS_H 00008 #define HWLOC_PLUGINS_H 00009 00014 struct hwloc_backend; 00015 00016 #include "hwloc.h" 00017 00018 #ifdef HWLOC_INSIDE_PLUGIN 00019 /* needed for hwloc_plugin_check_namespace() */ 00020 #include <ltdl.h> 00021 #endif 00022 00023 00024 00034 struct hwloc_disc_component { 00038 const char *name; 00039 00043 unsigned phases; 00044 00053 unsigned excluded_phases; 00054 00058 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); 00059 00072 unsigned priority; 00073 00077 unsigned enabled_by_default; 00078 00083 struct hwloc_disc_component * next; 00084 }; 00085 00096 typedef enum hwloc_disc_phase_e { 00101 HWLOC_DISC_PHASE_GLOBAL = (1U<<0), 00102 00105 HWLOC_DISC_PHASE_CPU = (1U<<1), 00106 00109 HWLOC_DISC_PHASE_MEMORY = (1U<<2), 00110 00113 HWLOC_DISC_PHASE_PCI = (1U<<3), 00114 00117 HWLOC_DISC_PHASE_IO = (1U<<4), 00118 00121 HWLOC_DISC_PHASE_MISC = (1U<<5), 00122 00125 HWLOC_DISC_PHASE_ANNOTATE = (1U<<6), 00126 00132 HWLOC_DISC_PHASE_TWEAK = (1U<<7) 00133 } hwloc_disc_phase_t; 00134 00136 enum hwloc_disc_status_flag_e { 00138 HWLOC_DISC_STATUS_FLAG_GOT_ALLOWED_RESOURCES = (1UL<<1) 00139 }; 00140 00146 struct hwloc_disc_status { 00150 hwloc_disc_phase_t phase; 00151 00155 unsigned excluded_phases; 00156 00158 unsigned long flags; 00159 }; 00160 00179 struct hwloc_backend { 00181 struct hwloc_disc_component * component; 00183 struct hwloc_topology * topology; 00185 int envvar_forced; 00187 struct hwloc_backend * next; 00188 00192 unsigned phases; 00193 00195 unsigned long flags; 00196 00203 int is_thissystem; 00204 00206 void * private_data; 00210 void (*disable)(struct hwloc_backend *backend); 00211 00217 int (*discover)(struct hwloc_backend *backend, struct hwloc_disc_status *status); 00218 00223 int (*get_pci_busid_cpuset)(struct hwloc_backend *backend, struct hwloc_pcidev_attr_s *busid, hwloc_bitmap_t cpuset); 00224 }; 00225 00229 HWLOC_DECLSPEC struct hwloc_backend * hwloc_backend_alloc(struct hwloc_topology *topology, struct hwloc_disc_component *component); 00230 00232 HWLOC_DECLSPEC int hwloc_backend_enable(struct hwloc_backend *backend); 00233 00244 typedef enum hwloc_component_type_e { 00246 HWLOC_COMPONENT_TYPE_DISC, 00247 00249 HWLOC_COMPONENT_TYPE_XML 00250 } hwloc_component_type_t; 00251 00257 struct hwloc_component { 00259 unsigned abi; 00260 00278 int (*init)(unsigned long flags); 00279 00291 void (*finalize)(unsigned long flags); 00292 00294 hwloc_component_type_t type; 00295 00297 unsigned long flags; 00298 00300 void * data; 00301 }; 00302 00336 HWLOC_DECLSPEC struct hwloc_obj *hwloc_insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t obj); 00337 00339 typedef void (*hwloc_report_error_t)(const char * msg, int line); 00341 HWLOC_DECLSPEC void hwloc_report_os_error(const char * msg, int line); 00343 HWLOC_DECLSPEC int hwloc_hide_errors(void); 00344 00351 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); 00352 00369 HWLOC_DECLSPEC void hwloc_insert_object_by_parent(struct hwloc_topology *topology, hwloc_obj_t parent, hwloc_obj_t obj); 00370 00375 HWLOC_DECLSPEC hwloc_obj_t hwloc_alloc_setup_object(hwloc_topology_t topology, hwloc_obj_type_t type, unsigned os_index); 00376 00385 HWLOC_DECLSPEC int hwloc_obj_add_children_sets(hwloc_obj_t obj); 00386 00394 HWLOC_DECLSPEC int hwloc_topology_reconnect(hwloc_topology_t topology, unsigned long flags __hwloc_attribute_unused); 00395 00417 static __hwloc_inline int 00418 hwloc_plugin_check_namespace(const char *pluginname __hwloc_attribute_unused, const char *symbol __hwloc_attribute_unused) 00419 { 00420 #ifdef HWLOC_INSIDE_PLUGIN 00421 lt_dlhandle handle; 00422 void *sym; 00423 handle = lt_dlopen(NULL); 00424 if (!handle) 00425 /* cannot check, assume things will work */ 00426 return 0; 00427 sym = lt_dlsym(handle, symbol); 00428 lt_dlclose(handle); 00429 if (!sym) { 00430 static int verboseenv_checked = 0; 00431 static int verboseenv_value = 0; 00432 if (!verboseenv_checked) { 00433 const char *verboseenv = getenv("HWLOC_PLUGINS_VERBOSE"); 00434 verboseenv_value = verboseenv ? atoi(verboseenv) : 0; 00435 verboseenv_checked = 1; 00436 } 00437 if (verboseenv_value) 00438 fprintf(stderr, "Plugin `%s' disabling itself because it cannot find the `%s' core symbol.\n", 00439 pluginname, symbol); 00440 return -1; 00441 } 00442 #endif /* HWLOC_INSIDE_PLUGIN */ 00443 return 0; 00444 } 00445 00459 static __hwloc_inline int 00460 hwloc_filter_check_pcidev_subtype_important(unsigned classid) 00461 { 00462 unsigned baseclass = classid >> 8; 00463 return (baseclass == 0x03 /* PCI_BASE_CLASS_DISPLAY */ 00464 || baseclass == 0x02 /* PCI_BASE_CLASS_NETWORK */ 00465 || baseclass == 0x01 /* PCI_BASE_CLASS_STORAGE */ 00466 || baseclass == 0x0b /* PCI_BASE_CLASS_PROCESSOR */ 00467 || classid == 0x0c04 /* PCI_CLASS_SERIAL_FIBER */ 00468 || classid == 0x0c06 /* PCI_CLASS_SERIAL_INFINIBAND */ 00469 || baseclass == 0x12 /* Processing Accelerators */); 00470 } 00471 00476 static __hwloc_inline int 00477 hwloc_filter_check_osdev_subtype_important(hwloc_obj_osdev_type_t subtype) 00478 { 00479 return (subtype != HWLOC_OBJ_OSDEV_DMA); 00480 } 00481 00488 static __hwloc_inline int 00489 hwloc_filter_check_keep_object_type(hwloc_topology_t topology, hwloc_obj_type_t type) 00490 { 00491 enum hwloc_type_filter_e filter = HWLOC_TYPE_FILTER_KEEP_NONE; 00492 hwloc_topology_get_type_filter(topology, type, &filter); 00493 assert(filter != HWLOC_TYPE_FILTER_KEEP_IMPORTANT); /* IMPORTANT only used for I/O */ 00494 return filter == HWLOC_TYPE_FILTER_KEEP_NONE ? 0 : 1; 00495 } 00496 00501 static __hwloc_inline int 00502 hwloc_filter_check_keep_object(hwloc_topology_t topology, hwloc_obj_t obj) 00503 { 00504 hwloc_obj_type_t type = obj->type; 00505 enum hwloc_type_filter_e filter = HWLOC_TYPE_FILTER_KEEP_NONE; 00506 hwloc_topology_get_type_filter(topology, type, &filter); 00507 if (filter == HWLOC_TYPE_FILTER_KEEP_NONE) 00508 return 0; 00509 if (filter == HWLOC_TYPE_FILTER_KEEP_IMPORTANT) { 00510 if (type == HWLOC_OBJ_PCI_DEVICE) 00511 return hwloc_filter_check_pcidev_subtype_important(obj->attr->pcidev.class_id); 00512 if (type == HWLOC_OBJ_OS_DEVICE) 00513 return hwloc_filter_check_osdev_subtype_important(obj->attr->osdev.type); 00514 } 00515 return 1; 00516 } 00517 00531 HWLOC_DECLSPEC unsigned hwloc_pcidisc_find_cap(const unsigned char *config, unsigned cap); 00532 00538 HWLOC_DECLSPEC int hwloc_pcidisc_find_linkspeed(const unsigned char *config, unsigned offset, float *linkspeed); 00539 00544 HWLOC_DECLSPEC hwloc_obj_type_t hwloc_pcidisc_check_bridge_type(unsigned device_class, const unsigned char *config); 00545 00552 HWLOC_DECLSPEC int hwloc_pcidisc_find_bridge_buses(unsigned domain, unsigned bus, unsigned dev, unsigned func, 00553 unsigned *secondary_busp, unsigned *subordinate_busp, 00554 const unsigned char *config); 00555 00560 HWLOC_DECLSPEC void hwloc_pcidisc_tree_insert_by_busid(struct hwloc_obj **treep, struct hwloc_obj *obj); 00561 00567 HWLOC_DECLSPEC int hwloc_pcidisc_tree_attach(struct hwloc_topology *topology, struct hwloc_obj *tree); 00568 00585 HWLOC_DECLSPEC struct hwloc_obj * hwloc_pci_find_parent_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func); 00586 00592 #endif /* HWLOC_PLUGINS_H */