00001
00002
00003
00004
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
00020 #ifdef HWLOC_HAVE_LTDL
00021 #include <ltdl.h>
00022 #else
00023 #include <dlfcn.h>
00024 #endif
00025 #endif
00026
00027
00028
00038 struct hwloc_disc_component {
00042 const char *name;
00043
00047 unsigned phases;
00048
00057 unsigned excluded_phases;
00058
00062 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);
00063
00076 unsigned priority;
00077
00081 unsigned enabled_by_default;
00082
00087 struct hwloc_disc_component * next;
00088 };
00089
00100 typedef enum hwloc_disc_phase_e {
00105 HWLOC_DISC_PHASE_GLOBAL = (1U<<0),
00106
00109 HWLOC_DISC_PHASE_CPU = (1U<<1),
00110
00113 HWLOC_DISC_PHASE_MEMORY = (1U<<2),
00114
00117 HWLOC_DISC_PHASE_PCI = (1U<<3),
00118
00121 HWLOC_DISC_PHASE_IO = (1U<<4),
00122
00125 HWLOC_DISC_PHASE_MISC = (1U<<5),
00126
00129 HWLOC_DISC_PHASE_ANNOTATE = (1U<<6),
00130
00136 HWLOC_DISC_PHASE_TWEAK = (1U<<7)
00137 } hwloc_disc_phase_t;
00138
00140 enum hwloc_disc_status_flag_e {
00142 HWLOC_DISC_STATUS_FLAG_GOT_ALLOWED_RESOURCES = (1UL<<1)
00143 };
00144
00150 struct hwloc_disc_status {
00154 hwloc_disc_phase_t phase;
00155
00159 unsigned excluded_phases;
00160
00162 unsigned long flags;
00163 };
00164
00183 struct hwloc_backend {
00185 struct hwloc_disc_component * component;
00187 struct hwloc_topology * topology;
00189 int envvar_forced;
00191 struct hwloc_backend * next;
00192
00196 unsigned phases;
00197
00199 unsigned long flags;
00200
00207 int is_thissystem;
00208
00210 void * private_data;
00214 void (*disable)(struct hwloc_backend *backend);
00215
00221 int (*discover)(struct hwloc_backend *backend, struct hwloc_disc_status *status);
00222
00227 int (*get_pci_busid_cpuset)(struct hwloc_backend *backend, struct hwloc_pcidev_attr_s *busid, hwloc_bitmap_t cpuset);
00228 };
00229
00233 HWLOC_DECLSPEC struct hwloc_backend * hwloc_backend_alloc(struct hwloc_topology *topology, struct hwloc_disc_component *component);
00234
00236 HWLOC_DECLSPEC int hwloc_backend_enable(struct hwloc_backend *backend);
00237
00248 typedef enum hwloc_component_type_e {
00250 HWLOC_COMPONENT_TYPE_DISC,
00251
00253 HWLOC_COMPONENT_TYPE_XML
00254 } hwloc_component_type_t;
00255
00261 struct hwloc_component {
00263 unsigned abi;
00264
00282 int (*init)(unsigned long flags);
00283
00295 void (*finalize)(unsigned long flags);
00296
00298 hwloc_component_type_t type;
00299
00301 unsigned long flags;
00302
00304 void * data;
00305 };
00306
00340 HWLOC_DECLSPEC struct hwloc_obj *hwloc_insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t obj);
00341
00343 typedef void (*hwloc_report_error_t)(const char * msg, int line);
00345 HWLOC_DECLSPEC void hwloc_report_os_error(const char * msg, int line);
00347 HWLOC_DECLSPEC int hwloc_hide_errors(void);
00348
00355 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);
00356
00373 HWLOC_DECLSPEC void hwloc_insert_object_by_parent(struct hwloc_topology *topology, hwloc_obj_t parent, hwloc_obj_t obj);
00374
00379 HWLOC_DECLSPEC hwloc_obj_t hwloc_alloc_setup_object(hwloc_topology_t topology, hwloc_obj_type_t type, unsigned os_index);
00380
00389 HWLOC_DECLSPEC int hwloc_obj_add_children_sets(hwloc_obj_t obj);
00390
00398 HWLOC_DECLSPEC int hwloc_topology_reconnect(hwloc_topology_t topology, unsigned long flags __hwloc_attribute_unused);
00399
00421 static __hwloc_inline int
00422 hwloc_plugin_check_namespace(const char *pluginname __hwloc_attribute_unused, const char *symbol __hwloc_attribute_unused)
00423 {
00424 #ifdef HWLOC_INSIDE_PLUGIN
00425 void *sym;
00426 #ifdef HWLOC_HAVE_LTDL
00427 lt_dlhandle handle = lt_dlopen(NULL);
00428 #else
00429 void *handle = dlopen(NULL, RTLD_NOW|RTLD_LOCAL);
00430 #endif
00431 if (!handle)
00432
00433 return 0;
00434 #ifdef HWLOC_HAVE_LTDL
00435 sym = lt_dlsym(handle, symbol);
00436 lt_dlclose(handle);
00437 #else
00438 sym = dlsym(handle, symbol);
00439 dlclose(handle);
00440 #endif
00441 if (!sym) {
00442 static int verboseenv_checked = 0;
00443 static int verboseenv_value = 0;
00444 if (!verboseenv_checked) {
00445 const char *verboseenv = getenv("HWLOC_PLUGINS_VERBOSE");
00446 verboseenv_value = verboseenv ? atoi(verboseenv) : 0;
00447 verboseenv_checked = 1;
00448 }
00449 if (verboseenv_value)
00450 fprintf(stderr, "Plugin `%s' disabling itself because it cannot find the `%s' core symbol.\n",
00451 pluginname, symbol);
00452 return -1;
00453 }
00454 #endif
00455 return 0;
00456 }
00457
00471 static __hwloc_inline int
00472 hwloc_filter_check_pcidev_subtype_important(unsigned classid)
00473 {
00474 unsigned baseclass = classid >> 8;
00475 return (baseclass == 0x03
00476 || baseclass == 0x02
00477 || baseclass == 0x01
00478 || baseclass == 0x0b
00479 || classid == 0x0c04
00480 || classid == 0x0c06
00481 || baseclass == 0x12 );
00482 }
00483
00488 static __hwloc_inline int
00489 hwloc_filter_check_osdev_subtype_important(hwloc_obj_osdev_type_t subtype)
00490 {
00491 return (subtype != HWLOC_OBJ_OSDEV_DMA);
00492 }
00493
00500 static __hwloc_inline int
00501 hwloc_filter_check_keep_object_type(hwloc_topology_t topology, hwloc_obj_type_t type)
00502 {
00503 enum hwloc_type_filter_e filter = HWLOC_TYPE_FILTER_KEEP_NONE;
00504 hwloc_topology_get_type_filter(topology, type, &filter);
00505 assert(filter != HWLOC_TYPE_FILTER_KEEP_IMPORTANT);
00506 return filter == HWLOC_TYPE_FILTER_KEEP_NONE ? 0 : 1;
00507 }
00508
00513 static __hwloc_inline int
00514 hwloc_filter_check_keep_object(hwloc_topology_t topology, hwloc_obj_t obj)
00515 {
00516 hwloc_obj_type_t type = obj->type;
00517 enum hwloc_type_filter_e filter = HWLOC_TYPE_FILTER_KEEP_NONE;
00518 hwloc_topology_get_type_filter(topology, type, &filter);
00519 if (filter == HWLOC_TYPE_FILTER_KEEP_NONE)
00520 return 0;
00521 if (filter == HWLOC_TYPE_FILTER_KEEP_IMPORTANT) {
00522 if (type == HWLOC_OBJ_PCI_DEVICE)
00523 return hwloc_filter_check_pcidev_subtype_important(obj->attr->pcidev.class_id);
00524 if (type == HWLOC_OBJ_OS_DEVICE)
00525 return hwloc_filter_check_osdev_subtype_important(obj->attr->osdev.type);
00526 }
00527 return 1;
00528 }
00529
00543 HWLOC_DECLSPEC unsigned hwloc_pcidisc_find_cap(const unsigned char *config, unsigned cap);
00544
00550 HWLOC_DECLSPEC int hwloc_pcidisc_find_linkspeed(const unsigned char *config, unsigned offset, float *linkspeed);
00551
00556 HWLOC_DECLSPEC hwloc_obj_type_t hwloc_pcidisc_check_bridge_type(unsigned device_class, const unsigned char *config);
00557
00564 HWLOC_DECLSPEC int hwloc_pcidisc_find_bridge_buses(unsigned domain, unsigned bus, unsigned dev, unsigned func,
00565 unsigned *secondary_busp, unsigned *subordinate_busp,
00566 const unsigned char *config);
00567
00572 HWLOC_DECLSPEC void hwloc_pcidisc_tree_insert_by_busid(struct hwloc_obj **treep, struct hwloc_obj *obj);
00573
00579 HWLOC_DECLSPEC int hwloc_pcidisc_tree_attach(struct hwloc_topology *topology, struct hwloc_obj *tree);
00580
00597 HWLOC_DECLSPEC struct hwloc_obj * hwloc_pci_find_parent_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func);
00598
00604 #endif