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