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 FILE *sysfile = NULL;
00068 struct dirent *dirent;
00069 unsigned pcibus, pcidev, pcifunc;
00070
00071 if (!hwloc_topology_is_thissystem(topology)) {
00072 errno = EINVAL;
00073 return -1;
00074 }
00075
00076 sprintf(path, "/sys/class/mic/mic%d", idx);
00077 sysdir = opendir(path);
00078 if (!sysdir)
00079 return -1;
00080
00081 while ((dirent = readdir(sysdir)) != NULL) {
00082 if (sscanf(dirent->d_name, "pci_%02x:%02x.%02x", &pcibus, &pcidev, &pcifunc) == 3) {
00083 sprintf(path, "/sys/class/mic/mic%d/pci_%02x:%02x.%02x/local_cpus", idx, pcibus, pcidev, pcifunc);
00084 sysfile = fopen(path, "r");
00085 if (!sysfile) {
00086 closedir(sysdir);
00087 return -1;
00088 }
00089
00090 if (hwloc_linux_parse_cpumap_file(sysfile, set) < 0
00091 || hwloc_bitmap_iszero(set))
00092 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00093
00094 fclose(sysfile);
00095 break;
00096 }
00097 }
00098
00099 closedir(sysdir);
00100 #else
00101
00102 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
00103 #endif
00104 return 0;
00105 }
00106
00120 static __hwloc_inline hwloc_obj_t
00121 hwloc_intel_mic_get_device_osdev_by_index(hwloc_topology_t topology,
00122 unsigned idx)
00123 {
00124 hwloc_obj_t osdev = NULL;
00125 while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
00126 if (HWLOC_OBJ_OSDEV_COPROC == osdev->attr->osdev.type
00127 && osdev->name
00128 && !strncmp("mic", osdev->name, 3)
00129 && atoi(osdev->name + 3) == (int) idx)
00130 return osdev;
00131 }
00132 return NULL;
00133 }
00134
00138 #ifdef __cplusplus
00139 }
00140 #endif
00141
00142
00143 #endif