File indexing completed on 2026-05-05 08:40:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef HWLOC_LINUX_LIBNUMA_H
0017 #define HWLOC_LINUX_LIBNUMA_H
0018
0019 #include "hwloc.h"
0020
0021 #include <numa.h>
0022
0023
0024 #ifdef __cplusplus
0025 extern "C" {
0026 #endif
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060 static __hwloc_inline int
0061 hwloc_cpuset_to_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset,
0062 unsigned long *mask, unsigned long *maxnode)
0063 {
0064 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
0065 unsigned long outmaxnode = -1;
0066 hwloc_obj_t node = NULL;
0067
0068
0069 *maxnode = (*maxnode + 8*sizeof(*mask) - 1) & ~(8*sizeof(*mask) - 1);
0070 memset(mask, 0, *maxnode/8);
0071
0072 while ((node = hwloc_get_next_obj_covering_cpuset_by_depth(topology, cpuset, depth, node)) != NULL) {
0073 if (node->os_index >= *maxnode)
0074 continue;
0075 mask[node->os_index/sizeof(*mask)/8] |= 1UL << (node->os_index % (sizeof(*mask)*8));
0076 if (outmaxnode == (unsigned long) -1 || outmaxnode < node->os_index)
0077 outmaxnode = node->os_index;
0078 }
0079
0080 *maxnode = outmaxnode+1;
0081 return 0;
0082 }
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 static __hwloc_inline int
0097 hwloc_nodeset_to_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset,
0098 unsigned long *mask, unsigned long *maxnode)
0099 {
0100 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
0101 unsigned long outmaxnode = -1;
0102 hwloc_obj_t node = NULL;
0103
0104
0105 *maxnode = (*maxnode + 8*sizeof(*mask) - 1) & ~(8*sizeof(*mask) - 1);
0106 memset(mask, 0, *maxnode/8);
0107
0108 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL) {
0109 if (node->os_index >= *maxnode)
0110 continue;
0111 if (!hwloc_bitmap_isset(nodeset, node->os_index))
0112 continue;
0113 mask[node->os_index/sizeof(*mask)/8] |= 1UL << (node->os_index % (sizeof(*mask)*8));
0114 if (outmaxnode == (unsigned long) -1 || outmaxnode < node->os_index)
0115 outmaxnode = node->os_index;
0116 }
0117
0118 *maxnode = outmaxnode+1;
0119 return 0;
0120 }
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 static __hwloc_inline int
0135 hwloc_cpuset_from_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_cpuset_t cpuset,
0136 const unsigned long *mask, unsigned long maxnode)
0137 {
0138 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
0139 hwloc_obj_t node = NULL;
0140 hwloc_bitmap_zero(cpuset);
0141 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
0142 if (node->os_index < maxnode
0143 && (mask[node->os_index/sizeof(*mask)/8] & (1UL << (node->os_index % (sizeof(*mask)*8)))))
0144 if (hwloc_bitmap_or(cpuset, cpuset, node->cpuset) < 0)
0145 return -1;
0146 return 0;
0147 }
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161 static __hwloc_inline int
0162 hwloc_nodeset_from_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_nodeset_t nodeset,
0163 const unsigned long *mask, unsigned long maxnode)
0164 {
0165 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
0166 hwloc_obj_t node = NULL;
0167 hwloc_bitmap_zero(nodeset);
0168 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
0169 if (node->os_index < maxnode
0170 && (mask[node->os_index/sizeof(*mask)/8] & (1UL << (node->os_index % (sizeof(*mask)*8)))))
0171 if (hwloc_bitmap_set(nodeset, node->os_index) < 0)
0172 return -1;
0173 return 0;
0174 }
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208 static __hwloc_inline struct bitmask *
0209 hwloc_cpuset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset) __hwloc_attribute_malloc;
0210 static __hwloc_inline struct bitmask *
0211 hwloc_cpuset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset)
0212 {
0213 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
0214 hwloc_obj_t node = NULL;
0215 struct bitmask *bitmask = numa_allocate_cpumask();
0216 if (!bitmask)
0217 return NULL;
0218 while ((node = hwloc_get_next_obj_covering_cpuset_by_depth(topology, cpuset, depth, node)) != NULL)
0219 if (node->attr->numanode.local_memory)
0220 numa_bitmask_setbit(bitmask, node->os_index);
0221 return bitmask;
0222 }
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233 static __hwloc_inline struct bitmask *
0234 hwloc_nodeset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset) __hwloc_attribute_malloc;
0235 static __hwloc_inline struct bitmask *
0236 hwloc_nodeset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset)
0237 {
0238 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
0239 hwloc_obj_t node = NULL;
0240 struct bitmask *bitmask = numa_allocate_cpumask();
0241 if (!bitmask)
0242 return NULL;
0243 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
0244 if (hwloc_bitmap_isset(nodeset, node->os_index) && node->attr->numanode.local_memory)
0245 numa_bitmask_setbit(bitmask, node->os_index);
0246 return bitmask;
0247 }
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257 static __hwloc_inline int
0258 hwloc_cpuset_from_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_cpuset_t cpuset,
0259 const struct bitmask *bitmask)
0260 {
0261 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
0262 hwloc_obj_t node = NULL;
0263 hwloc_bitmap_zero(cpuset);
0264 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
0265 if (numa_bitmask_isbitset(bitmask, node->os_index))
0266 if (hwloc_bitmap_or(cpuset, cpuset, node->cpuset) < 0)
0267 return -1;
0268 return 0;
0269 }
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279 static __hwloc_inline int
0280 hwloc_nodeset_from_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_nodeset_t nodeset,
0281 const struct bitmask *bitmask)
0282 {
0283 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
0284 hwloc_obj_t node = NULL;
0285 hwloc_bitmap_zero(nodeset);
0286 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
0287 if (numa_bitmask_isbitset(bitmask, node->os_index))
0288 if (hwloc_bitmap_set(nodeset, node->os_index) < 0)
0289 return -1;
0290 return 0;
0291 }
0292
0293
0294
0295
0296 #ifdef __cplusplus
0297 }
0298 #endif
0299
0300
0301 #endif