This source file includes following definitions.
- hwloc_cpuset_to_linux_libnuma_ulongs
- hwloc_nodeset_to_linux_libnuma_ulongs
- hwloc_cpuset_from_linux_libnuma_ulongs
- hwloc_nodeset_from_linux_libnuma_ulongs
- hwloc_cpuset_to_linux_libnuma_bitmask
- hwloc_nodeset_to_linux_libnuma_bitmask
- hwloc_cpuset_from_linux_libnuma_bitmask
- hwloc_nodeset_from_linux_libnuma_bitmask
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #ifndef HWLOC_LINUX_LIBNUMA_H
16 #define HWLOC_LINUX_LIBNUMA_H
17
18 #include <hwloc.h>
19 #include <numa.h>
20
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 static __hwloc_inline int
54 hwloc_cpuset_to_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset,
55 unsigned long *mask, unsigned long *maxnode)
56 {
57 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
58 unsigned long outmaxnode = -1;
59 hwloc_obj_t node = NULL;
60
61
62 *maxnode = (*maxnode + 8*sizeof(*mask) - 1) & ~(8*sizeof(*mask) - 1);
63 memset(mask, 0, *maxnode/8);
64
65 while ((node = hwloc_get_next_obj_covering_cpuset_by_depth(topology, cpuset, depth, node)) != NULL) {
66 if (node->os_index >= *maxnode)
67 continue;
68 mask[node->os_index/sizeof(*mask)/8] |= 1UL << (node->os_index % (sizeof(*mask)*8));
69 if (outmaxnode == (unsigned long) -1 || outmaxnode < node->os_index)
70 outmaxnode = node->os_index;
71 }
72
73 *maxnode = outmaxnode+1;
74 return 0;
75 }
76
77
78
79
80
81
82
83
84
85
86
87 static __hwloc_inline int
88 hwloc_nodeset_to_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset,
89 unsigned long *mask, unsigned long *maxnode)
90 {
91 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
92 unsigned long outmaxnode = -1;
93 hwloc_obj_t node = NULL;
94
95
96 *maxnode = (*maxnode + 8*sizeof(*mask) - 1) & ~(8*sizeof(*mask) - 1);
97 memset(mask, 0, *maxnode/8);
98
99 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL) {
100 if (node->os_index >= *maxnode)
101 continue;
102 if (!hwloc_bitmap_isset(nodeset, node->os_index))
103 continue;
104 mask[node->os_index/sizeof(*mask)/8] |= 1UL << (node->os_index % (sizeof(*mask)*8));
105 if (outmaxnode == (unsigned long) -1 || outmaxnode < node->os_index)
106 outmaxnode = node->os_index;
107 }
108
109 *maxnode = outmaxnode+1;
110 return 0;
111 }
112
113
114
115
116
117
118
119
120
121
122 static __hwloc_inline int
123 hwloc_cpuset_from_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_cpuset_t cpuset,
124 const unsigned long *mask, unsigned long maxnode)
125 {
126 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
127 hwloc_obj_t node = NULL;
128 hwloc_bitmap_zero(cpuset);
129 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
130 if (node->os_index < maxnode
131 && (mask[node->os_index/sizeof(*mask)/8] & (1UL << (node->os_index % (sizeof(*mask)*8)))))
132 hwloc_bitmap_or(cpuset, cpuset, node->cpuset);
133 return 0;
134 }
135
136
137
138
139
140
141
142
143
144
145 static __hwloc_inline int
146 hwloc_nodeset_from_linux_libnuma_ulongs(hwloc_topology_t topology, hwloc_nodeset_t nodeset,
147 const unsigned long *mask, unsigned long maxnode)
148 {
149 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
150 hwloc_obj_t node = NULL;
151 hwloc_bitmap_zero(nodeset);
152 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
153 if (node->os_index < maxnode
154 && (mask[node->os_index/sizeof(*mask)/8] & (1UL << (node->os_index % (sizeof(*mask)*8)))))
155 hwloc_bitmap_set(nodeset, node->os_index);
156 return 0;
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188 static __hwloc_inline struct bitmask *
189 hwloc_cpuset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset) __hwloc_attribute_malloc;
190 static __hwloc_inline struct bitmask *
191 hwloc_cpuset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_cpuset_t cpuset)
192 {
193 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
194 hwloc_obj_t node = NULL;
195 struct bitmask *bitmask = numa_allocate_cpumask();
196 if (!bitmask)
197 return NULL;
198 while ((node = hwloc_get_next_obj_covering_cpuset_by_depth(topology, cpuset, depth, node)) != NULL)
199 if (node->attr->numanode.local_memory)
200 numa_bitmask_setbit(bitmask, node->os_index);
201 return bitmask;
202 }
203
204
205
206
207
208
209
210
211
212
213 static __hwloc_inline struct bitmask *
214 hwloc_nodeset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset) __hwloc_attribute_malloc;
215 static __hwloc_inline struct bitmask *
216 hwloc_nodeset_to_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset)
217 {
218 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
219 hwloc_obj_t node = NULL;
220 struct bitmask *bitmask = numa_allocate_cpumask();
221 if (!bitmask)
222 return NULL;
223 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
224 if (hwloc_bitmap_isset(nodeset, node->os_index) && node->attr->numanode.local_memory)
225 numa_bitmask_setbit(bitmask, node->os_index);
226 return bitmask;
227 }
228
229
230
231
232
233
234 static __hwloc_inline int
235 hwloc_cpuset_from_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_cpuset_t cpuset,
236 const struct bitmask *bitmask)
237 {
238 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
239 hwloc_obj_t node = NULL;
240 hwloc_bitmap_zero(cpuset);
241 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
242 if (numa_bitmask_isbitset(bitmask, node->os_index))
243 hwloc_bitmap_or(cpuset, cpuset, node->cpuset);
244 return 0;
245 }
246
247
248
249
250
251
252 static __hwloc_inline int
253 hwloc_nodeset_from_linux_libnuma_bitmask(hwloc_topology_t topology, hwloc_nodeset_t nodeset,
254 const struct bitmask *bitmask)
255 {
256 int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
257 hwloc_obj_t node = NULL;
258 hwloc_bitmap_zero(nodeset);
259 while ((node = hwloc_get_next_obj_by_depth(topology, depth, node)) != NULL)
260 if (numa_bitmask_isbitset(bitmask, node->os_index))
261 hwloc_bitmap_set(nodeset, node->os_index);
262 return 0;
263 }
264
265
266
267
268 #ifdef __cplusplus
269 }
270 #endif
271
272
273 #endif