00001
00002
00003
00004
00005
00013 #ifndef HWLOC_INTEL_MIC_H
00014 #define HWLOC_INTEL_MIC_H
00015
00016 #include <hwloc.h>
00017 #include <hwloc/autogen/config.h>
00018 #include <hwloc/helper.h>
00019 #ifdef HWLOC_LINUX_SYS
00020 #include <hwloc/linux.h>
00021 #include <dirent.h>
00022 #include <string.h>
00023 #endif
00024
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027
00028
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032
00033
00057 static __hwloc_inline int
00058 hwloc_intel_mic_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused,
00059 int idx __hwloc_attribute_unused,
00060 hwloc_cpuset_t set)
00061 {
00062 #ifdef HWLOC_LINUX_SYS
00063
00064 #define HWLOC_INTEL_MIC_DEVICE_SYSFS_PATH_MAX 128
00065 char path[HWLOC_INTEL_MIC_DEVICE_SYSFS_PATH_MAX];
00066 DIR *sysdir = NULL;
00067 struct dirent *dirent;
00068 unsigned pcibus, pcidev, pcifunc;
00069
00070 if (!hwloc_topology_is_thissystem(topology)) {
00071 errno = EINVAL;
00072 return -1;
00073 }
00074
00075 sprintf(path, "/sys/class/mic/mic%d", idx);
00076 sysdir = opendir(path);
00077 if (!sysdir)
00078 return -1;
00079
00080 while ((dirent = readdir(sysdir)) != NULL) {
00081 if (sscanf(dirent->d_name, "pci_%02x:%02x.%02x", &pcibus, &pcidev, &pcifunc) == 3) {
00082 sprintf(path, "/sys/class/mic/mic%d/pci_%02x:%02x.%02x/local_cpus", idx, pcibus, pcidev, pcifunc);
00083 if (hwloc_linux_read_path_as_cpumask(path, set) < 0
00084 || hwloc_bitmap_iszero(set))
00085 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00086 break;
00087 }
00088 }
00089
00090 closedir(sysdir);
00091 #else
00092
00093 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00094 #endif
00095 return 0;
00096 }
00097
00111 static __hwloc_inline hwloc_obj_t
00112 hwloc_intel_mic_get_device_osdev_by_index(hwloc_topology_t topology,
00113 unsigned idx)
00114 {
00115 hwloc_obj_t osdev = NULL;
00116 while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
00117 if (HWLOC_OBJ_OSDEV_COPROC == osdev->attr->osdev.type
00118 && osdev->name
00119 && !strncmp("mic", osdev->name, 3)
00120 && atoi(osdev->name + 3) == (int) idx)
00121 return osdev;
00122 }
00123 return NULL;
00124 }
00125
00129 #ifdef __cplusplus
00130 }
00131 #endif
00132
00133
00134 #endif