00001
00002
00003
00004
00005
00013 #ifndef HWLOC_LINUX_LIBNUMA_H
00014 #define HWLOC_LINUX_LIBNUMA_H
00015
00016 #include <hwloc.h>
00017 #include <numa.h>
00018
00019
00035 static __hwloc_inline int
00036 hwloc_cpuset_to_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset,
00037 unsigned long *mask, unsigned long *maxnode)
00038 {
00039 unsigned long outmaxnode = -1;
00040 hwloc_obj_t node = NULL;
00041 unsigned nbnodes = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NODE);
00042 unsigned i;
00043
00044 for(i=0; i<*maxnode/HWLOC_BITS_PER_LONG; i++)
00045 mask[i] = 0;
00046
00047 if (nbnodes) {
00048 while ((node = hwloc_get_next_obj_covering_cpuset_by_type(topology, cpuset, HWLOC_OBJ_NODE, node)) != NULL) {
00049 if (node->os_index >= *maxnode)
00050 break;
00051 mask[node->os_index/HWLOC_BITS_PER_LONG] |= 1 << (node->os_index % HWLOC_BITS_PER_LONG);
00052 outmaxnode = node->os_index;
00053 }
00054
00055 } else {
00056
00057 if (!hwloc_cpuset_iszero(cpuset)) {
00058 mask[0] = 1;
00059 outmaxnode = 0;
00060 }
00061 }
00062
00063 *maxnode = outmaxnode+1;
00064 return 0;
00065 }
00066
00076 static __hwloc_inline int
00077 hwloc_cpuset_from_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_cpuset_t cpuset,
00078 const unsigned long *mask, unsigned long maxnode)
00079 {
00080 hwloc_obj_t node;
00081 int depth;
00082 unsigned i;
00083
00084 depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NODE);
00085
00086
00087 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
00088
00089 if (mask[0] & 1)
00090 hwloc_cpuset_copy(cpuset, hwloc_topology_get_complete_cpuset(topology));
00091 else
00092 hwloc_cpuset_zero(cpuset);
00093
00094 } else {
00095 hwloc_cpuset_zero(cpuset);
00096 for(i=0; i<maxnode; i++)
00097 if (mask[i/HWLOC_BITS_PER_LONG] & (1 << (i% HWLOC_BITS_PER_LONG))) {
00098 node = hwloc_get_obj_by_depth(topology, depth, i);
00099 if (node)
00100 hwloc_cpuset_or(cpuset, cpuset, node->cpuset);
00101 }
00102 }
00103
00104 return 0;
00105 }
00106
00125 static __hwloc_inline struct bitmask * __hwloc_attribute_malloc
00126 hwloc_cpuset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset)
00127 {
00128 struct bitmask *bitmask;
00129 hwloc_obj_t node = NULL;
00130 unsigned nbnodes = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NODE);
00131
00132 if (nbnodes) {
00133 bitmask = numa_bitmask_alloc(nbnodes);
00134 if (!bitmask)
00135 return NULL;
00136 while ((node = hwloc_get_next_obj_covering_cpuset_by_type(topology, cpuset, HWLOC_OBJ_NODE, node)) != NULL)
00137 numa_bitmask_setbit(bitmask, node->os_index);
00138
00139 } else {
00140
00141 bitmask = numa_bitmask_alloc(1);
00142 if (!bitmask)
00143 return NULL;
00144 if (!hwloc_cpuset_iszero(cpuset))
00145 numa_bitmask_setbit(bitmask, 0);
00146 }
00147
00148 return bitmask;
00149 }
00150
00156 static __hwloc_inline int
00157 hwloc_cpuset_from_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_cpuset_t cpuset,
00158 const struct bitmask *bitmask)
00159 {
00160 hwloc_obj_t node;
00161 int depth;
00162 int i;
00163
00164 depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NODE);
00165
00166
00167 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
00168
00169 if (numa_bitmask_isbitset(bitmask, 0))
00170 hwloc_cpuset_copy(cpuset, hwloc_topology_get_complete_cpuset(topology));
00171 else
00172 hwloc_cpuset_zero(cpuset);
00173
00174 } else {
00175 hwloc_cpuset_zero(cpuset);
00176 for(i=0; i<NUMA_NUM_NODES; i++)
00177 if (numa_bitmask_isbitset(bitmask, i)) {
00178 node = hwloc_get_obj_by_depth(topology, depth, i);
00179 if (node)
00180 hwloc_cpuset_or(cpuset, cpuset, node->cpuset);
00181 }
00182 }
00183
00184 return 0;
00185 }
00186
00191 #ifdef NUMA_VERSION1_COMPATIBILITY
00192
00202 static __hwloc_inline int
00203 hwloc_cpuset_to_linux_libnuma_nodemask(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset,
00204 nodemask_t *nodemask)
00205 {
00206 hwloc_obj_t node = NULL;
00207 unsigned nbnodes = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_NODE);
00208
00209 nodemask_zero(nodemask);
00210 if (nbnodes) {
00211 while ((node = hwloc_get_next_obj_covering_cpuset_by_type(topology, cpuset, HWLOC_OBJ_NODE, node)) != NULL)
00212 nodemask_set(nodemask, node->os_index);
00213
00214 } else {
00215
00216 if (!hwloc_cpuset_iszero(cpuset))
00217 nodemask_set(nodemask, 0);
00218 }
00219
00220 return 0;
00221 }
00222
00228 static __hwloc_inline int
00229 hwloc_cpuset_from_linux_libnuma_nodemask(hwloc_topology_t topology, hwloc_cpuset_t cpuset,
00230 const nodemask_t *nodemask)
00231 {
00232 hwloc_obj_t node;
00233 int depth;
00234 int i;
00235
00236 depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NODE);
00237
00238
00239 if (depth == HWLOC_TYPE_DEPTH_UNKNOWN) {
00240
00241 if (nodemask_isset(nodemask, 0))
00242 hwloc_cpuset_copy(cpuset, hwloc_topology_get_complete_cpuset(topology));
00243 else
00244 hwloc_cpuset_zero(cpuset);
00245
00246 } else {
00247 hwloc_cpuset_zero(cpuset);
00248 for(i=0; i<NUMA_NUM_NODES; i++)
00249 if (nodemask_isset(nodemask, i)) {
00250 node = hwloc_get_obj_by_depth(topology, depth, i);
00251 if (node)
00252 hwloc_cpuset_or(cpuset, cpuset, node->cpuset);
00253 }
00254 }
00255
00256 return 0;
00257 }
00258
00260 #endif
00261
00262
00263 #endif