00001
00002
00003
00004
00005
00006
00007
00015 #ifndef HWLOC_LINUX_LIBNUMA_H
00016 #define HWLOC_LINUX_LIBNUMA_H
00017
00018 #include <hwloc.h>
00019 #include <numa.h>
00020
00021
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025
00026
00053 static __hwloc_inline int
00054 hwloc_cpuset_to_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset,
00055 unsigned long *mask, unsigned long *maxnode)
00056 {
00057 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
00058 unsigned long outmaxnode = -1;
00059 hwloc_obj_t node = NULL;
00060
00061
00062 *maxnode = (*maxnode + 8*sizeof(*mask) - 1) & ~(8*sizeof(*mask) - 1);
00063 memset(mask, 0, *maxnode/8);
00064
00065 while ((node = hwloc_get_next_obj_covering_cpuset_by_depth(topology, cpuset, depth, node)) != NULL) {
00066 if (node->os_index >= *maxnode)
00067 continue;
00068 mask[node->os_index/sizeof(*mask)/8] |= 1UL << (node->os_index % (sizeof(*mask)*8));
00069 if (outmaxnode == (unsigned long) -1 || outmaxnode < node->os_index)
00070 outmaxnode = node->os_index;
00071 }
00072
00073 *maxnode = outmaxnode+1;
00074 return 0;
00075 }
00076
00087 static __hwloc_inline int
00088 hwloc_nodeset_to_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset,
00089 unsigned long *mask, unsigned long *maxnode)
00090 {
00091 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
00092 unsigned long outmaxnode = -1;
00093 hwloc_obj_t node = NULL;
00094
00095
00096 *maxnode = (*maxnode + 8*sizeof(*mask) - 1) & ~(8*sizeof(*mask) - 1);
00097 memset(mask, 0, *maxnode/8);
00098
00099 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL) {
00100 if (node->os_index >= *maxnode)
00101 continue;
00102 if (!hwloc_bitmap_isset(nodeset, node->os_index))
00103 continue;
00104 mask[node->os_index/sizeof(*mask)/8] |= 1UL << (node->os_index % (sizeof(*mask)*8));
00105 if (outmaxnode == (unsigned long) -1 || outmaxnode < node->os_index)
00106 outmaxnode = node->os_index;
00107 }
00108
00109 *maxnode = outmaxnode+1;
00110 return 0;
00111 }
00112
00122 static __hwloc_inline int
00123 hwloc_cpuset_from_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_cpuset_t cpuset,
00124 const unsigned long *mask, unsigned long maxnode)
00125 {
00126 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
00127 hwloc_obj_t node = NULL;
00128 hwloc_bitmap_zero(cpuset);
00129 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
00130 if (node->os_index < maxnode
00131 && (mask[node->os_index/sizeof(*mask)/8] & (1UL << (node->os_index % (sizeof(*mask)*8)))))
00132 hwloc_bitmap_or(cpuset, cpuset, node->cpuset);
00133 return 0;
00134 }
00135
00145 static __hwloc_inline int
00146 hwloc_nodeset_from_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_nodeset_t nodeset,
00147 const unsigned long *mask, unsigned long maxnode)
00148 {
00149 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
00150 hwloc_obj_t node = NULL;
00151 hwloc_bitmap_zero(nodeset);
00152 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
00153 if (node->os_index < maxnode
00154 && (mask[node->os_index/sizeof(*mask)/8] & (1UL << (node->os_index % (sizeof(*mask)*8)))))
00155 hwloc_bitmap_set(nodeset, node->os_index);
00156 return 0;
00157 }
00158
00188 static __hwloc_inline struct bitmask *
00189 hwloc_cpuset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset) __hwloc_attribute_malloc;
00190 static __hwloc_inline struct bitmask *
00191 hwloc_cpuset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset)
00192 {
00193 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
00194 hwloc_obj_t node = NULL;
00195 struct bitmask *bitmask = numa_allocate_cpumask();
00196 if (!bitmask)
00197 return NULL;
00198 while ((node = hwloc_get_next_obj_covering_cpuset_by_depth(topology, cpuset, depth, node)) != NULL)
00199 if (node->attr->numanode.local_memory)
00200 numa_bitmask_setbit(bitmask, node->os_index);
00201 return bitmask;
00202 }
00203
00213 static __hwloc_inline struct bitmask *
00214 hwloc_nodeset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset) __hwloc_attribute_malloc;
00215 static __hwloc_inline struct bitmask *
00216 hwloc_nodeset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset)
00217 {
00218 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
00219 hwloc_obj_t node = NULL;
00220 struct bitmask *bitmask = numa_allocate_cpumask();
00221 if (!bitmask)
00222 return NULL;
00223 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
00224 if (hwloc_bitmap_isset(nodeset, node->os_index) && node->attr->numanode.local_memory)
00225 numa_bitmask_setbit(bitmask, node->os_index);
00226 return bitmask;
00227 }
00228
00234 static __hwloc_inline int
00235 hwloc_cpuset_from_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_cpuset_t cpuset,
00236 const struct bitmask *bitmask)
00237 {
00238 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
00239 hwloc_obj_t node = NULL;
00240 hwloc_bitmap_zero(cpuset);
00241 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
00242 if (numa_bitmask_isbitset(bitmask, node->os_index))
00243 hwloc_bitmap_or(cpuset, cpuset, node->cpuset);
00244 return 0;
00245 }
00246
00252 static __hwloc_inline int
00253 hwloc_nodeset_from_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_nodeset_t nodeset,
00254 const struct bitmask *bitmask)
00255 {
00256 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
00257 hwloc_obj_t node = NULL;
00258 hwloc_bitmap_zero(nodeset);
00259 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
00260 if (numa_bitmask_isbitset(bitmask, node->os_index))
00261 hwloc_bitmap_set(nodeset, node->os_index);
00262 return 0;
00263 }
00264
00268 #ifdef __cplusplus
00269 }
00270 #endif
00271
00272
00273 #endif