00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00041 #ifndef TOPOLOGY_LINUX_LIBNUMA_H
00042 #define TOPOLOGY_LINUX_LIBNUMA_H
00043
00044 #include <topology.h>
00045 #include <numa.h>
00046 #include <assert.h>
00047
00048
00064 static __inline__ void
00065 topo_cpuset_to_linux_libnuma_ulongs(topo_topology_t topology, const topo_cpuset_t *cpuset,
00066 unsigned long *mask, unsigned long *maxnode)
00067 {
00068 unsigned long outmaxnode = -1;
00069 topo_obj_t node = NULL;
00070 unsigned nbnodes = topo_get_type_nbobjs(topology, TOPO_OBJ_NODE);
00071 int i;
00072
00073 for(i=0; i<*maxnode/TOPO_BITS_PER_LONG; i++)
00074 mask[i] = 0;
00075
00076 if (nbnodes) {
00077 while ((node = topo_get_next_obj_above_cpuset_by_depth(topology, cpuset, TOPO_OBJ_NODE, node)) != NULL) {
00078 if (node->os_index >= *maxnode)
00079 break;
00080 mask[node->os_index/TOPO_BITS_PER_LONG] |= 1 << (node->os_index % TOPO_BITS_PER_LONG);
00081 outmaxnode = node->os_index;
00082 }
00083
00084 } else {
00085
00086 if (!topo_cpuset_iszero(cpuset)) {
00087 mask[0] = 1;
00088 outmaxnode = 0;
00089 }
00090 }
00091
00092 *maxnode = outmaxnode+1;
00093 }
00094
00104 static __inline__ void
00105 topo_cpuset_from_linux_libnuma_ulongs(topo_topology_t topology, topo_cpuset_t *cpuset,
00106 const unsigned long *mask, unsigned long maxnode)
00107 {
00108 topo_obj_t node;
00109 unsigned depth;
00110 int i;
00111
00112 topo_cpuset_zero(cpuset);
00113
00114 depth = topo_get_type_depth(topology, TOPO_OBJ_NODE);
00115 assert(depth != TOPO_TYPE_DEPTH_MULTIPLE);
00116
00117 if (depth == TOPO_TYPE_DEPTH_UNKNOWN) {
00118
00119 if (mask[0] & 1)
00120 *cpuset = topo_get_system_obj(topology)->cpuset;
00121
00122 } else {
00123 for(i=0; i<maxnode; i++)
00124 if (mask[i/TOPO_BITS_PER_LONG] & (1 << (i% TOPO_BITS_PER_LONG))) {
00125 node = topo_get_obj_by_depth(topology, depth, i);
00126 if (node)
00127 topo_cpuset_orset(cpuset, &node->cpuset);
00128 }
00129 }
00130 }
00131
00148 static __inline__ struct bitmask *
00149 topo_cpuset_to_linux_libnuma_bitmask(topo_topology_t topology, const topo_cpuset_t *cpuset)
00150 {
00151 struct bitmask *bitmask;
00152 topo_obj_t node = NULL;
00153 unsigned nbnodes = topo_get_type_nbobjs(topology, TOPO_OBJ_NODE);
00154
00155 if (nbnodes) {
00156 bitmask = numa_bitmask_alloc(nbnodes);
00157 if (!bitmask)
00158 return NULL;
00159 while ((node = topo_get_next_obj_above_cpuset(topology, cpuset, TOPO_OBJ_NODE, node)) != NULL)
00160 numa_bitmask_setbit(bitmask, node->os_index);
00161
00162 } else {
00163
00164 bitmask = numa_bitmask_alloc(1);
00165 if (!bitmask)
00166 return NULL;
00167 if (!topo_cpuset_iszero(cpuset))
00168 numa_bitmask_setbit(bitmask, 0);
00169 }
00170
00171 return bitmask;
00172 }
00173
00179 static __inline__ void
00180 topo_cpuset_from_linux_libnuma_bitmask(topo_topology_t topology, topo_cpuset_t *cpuset,
00181 const struct bitmask *bitmask)
00182 {
00183 topo_obj_t node;
00184 unsigned depth;
00185 int i;
00186
00187 topo_cpuset_zero(cpuset);
00188
00189 depth = topo_get_type_depth(topology, TOPO_OBJ_NODE);
00190 assert(depth != TOPO_TYPE_DEPTH_MULTIPLE);
00191
00192 if (depth == TOPO_TYPE_DEPTH_UNKNOWN) {
00193
00194 if (numa_bitmask_isbitset(bitmask, 0))
00195 *cpuset = topo_get_system_obj(topology)->cpuset;
00196
00197 } else {
00198 for(i=0; i<NUMA_NUM_NODES; i++)
00199 if (numa_bitmask_isbitset(bitmask, i)) {
00200 node = topo_get_obj_by_depth(topology, depth, i);
00201 if (node)
00202 topo_cpuset_orset(cpuset, &node->cpuset);
00203 }
00204 }
00205 }
00206
00211 #ifdef NUMA_VERSION1_COMPATIBILITY
00212
00222 static __inline__ void
00223 topo_cpuset_to_linux_libnuma_nodemask(topo_topology_t topology, const topo_cpuset_t *cpuset,
00224 nodemask_t *nodemask)
00225 {
00226 topo_obj_t node = NULL;
00227 unsigned nbnodes = topo_get_type_nbobjs(topology, TOPO_OBJ_NODE);
00228
00229 nodemask_zero(nodemask);
00230 if (nbnodes) {
00231 while ((node = topo_get_next_obj_above_cpuset(topology, cpuset, TOPO_OBJ_NODE, node)) != NULL)
00232 nodemask_set(nodemask, node->os_index);
00233
00234 } else {
00235
00236 if (!topo_cpuset_iszero(cpuset))
00237 nodemask_set(nodemask, 0);
00238 }
00239 }
00240
00246 static __inline__ void
00247 topo_cpuset_from_linux_libnuma_nodemask(topo_topology_t topology, topo_cpuset_t *cpuset,
00248 const nodemask_t *nodemask)
00249 {
00250 topo_obj_t node;
00251 unsigned depth;
00252 int i;
00253
00254 topo_cpuset_zero(cpuset);
00255
00256 depth = topo_get_type_depth(topology, TOPO_OBJ_NODE);
00257 assert(depth != TOPO_TYPE_DEPTH_MULTIPLE);
00258
00259 if (depth == TOPO_TYPE_DEPTH_UNKNOWN) {
00260
00261 if (nodemask_isset(nodemask, 0))
00262 *cpuset = topo_get_system_obj(topology)->cpuset;
00263
00264 } else {
00265 for(i=0; i<NUMA_NUM_NODES; i++)
00266 if (nodemask_isset(nodemask, i)) {
00267 node = topo_get_obj_by_depth(topology, depth, i);
00268 if (node)
00269 topo_cpuset_orset(cpuset, &node->cpuset);
00270 }
00271 }
00272 }
00273
00275 #endif
00276
00277
00278 #endif