00001
00002
00003
00004
00005
00006
00007
00008
00019 #ifndef HWLOC_OPENFABRICS_VERBS_H
00020 #define HWLOC_OPENFABRICS_VERBS_H
00021
00022 #include <hwloc.h>
00023 #include <hwloc/autogen/config.h>
00024 #ifdef HWLOC_LINUX_SYS
00025 #include <hwloc/linux.h>
00026 #endif
00027
00028 #include <infiniband/verbs.h>
00029
00030
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034
00035
00061 static __hwloc_inline int
00062 hwloc_ibv_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused,
00063 struct ibv_device *ibdev, hwloc_cpuset_t set)
00064 {
00065 #ifdef HWLOC_LINUX_SYS
00066
00067
00068 #define HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX 128
00069 char path[HWLOC_OPENFABRICS_VERBS_SYSFS_PATH_MAX];
00070 FILE *sysfile = NULL;
00071
00072 if (!hwloc_topology_is_thissystem(topology)) {
00073 errno = EINVAL;
00074 return -1;
00075 }
00076
00077 sprintf(path, "/sys/class/infiniband/%s/device/local_cpus",
00078 ibv_get_device_name(ibdev));
00079 sysfile = fopen(path, "r");
00080 if (!sysfile)
00081 return -1;
00082
00083 hwloc_linux_parse_cpumap_file(sysfile, set);
00084 if (hwloc_bitmap_iszero(set))
00085 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00086
00087 fclose(sysfile);
00088 #else
00089
00090 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00091 #endif
00092 return 0;
00093 }
00094
00109 static __hwloc_inline hwloc_obj_t
00110 hwloc_ibv_get_device_osdev_by_name(hwloc_topology_t topology,
00111 const char *ibname)
00112 {
00113 hwloc_obj_t osdev = NULL;
00114 while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
00115 if (HWLOC_OBJ_OSDEV_OPENFABRICS == osdev->attr->osdev.type
00116 && osdev->name && !strcmp(ibname, osdev->name))
00117 return osdev;
00118 }
00119 return NULL;
00120 }
00121
00136 static __hwloc_inline hwloc_obj_t
00137 hwloc_ibv_get_device_osdev(hwloc_topology_t topology,
00138 struct ibv_device *ibdev)
00139 {
00140 if (!hwloc_topology_is_thissystem(topology)) {
00141 errno = EINVAL;
00142 return NULL;
00143 }
00144 return hwloc_ibv_get_device_osdev_by_name(topology, ibv_get_device_name(ibdev));
00145 }
00146
00150 #ifdef __cplusplus
00151 }
00152 #endif
00153
00154
00155 #endif