1
1
/*
2
- * Copyright © 2013-2016 Inria. All rights reserved.
2
+ * Copyright © 2013-2017 Inria. All rights reserved.
3
3
* See COPYING in top-level directory.
4
4
*/
5
5
17
17
18
18
#ifndef HWLOC_DISABLE_BGQ_PORT_TEST
19
19
20
+ #define HWLOC_BGQ_CORES 17 /* spare core ignored for now */
21
+
20
22
static int
21
- hwloc_look_bgq (struct hwloc_backend * backend )
23
+ hwloc_bgq__get_allowed_resources (struct hwloc_topology * topology )
22
24
{
23
- struct hwloc_topology * topology = backend -> topology ;
24
- hwloc_bitmap_t set ;
25
- hwloc_obj_t obj ;
26
- unsigned i ;
27
25
const char * env ;
26
+ unsigned i ;
28
27
29
- if (topology -> levels [0 ][0 ]-> cpuset )
30
- /* somebody discovered things */
31
- return -1 ;
32
-
33
- #define HWLOC_BGQ_CORES 17 /* spare core ignored for now */
34
-
35
- hwloc_alloc_obj_cpusets (topology -> levels [0 ][0 ]);
36
28
/* mark the 17th core (OS-reserved) as disallowed */
37
29
hwloc_bitmap_clr_range (topology -> levels [0 ][0 ]-> allowed_cpuset , (HWLOC_BGQ_CORES - 1 )* 4 , HWLOC_BGQ_CORES * 4 - 1 );
38
30
39
- if (topology -> is_thissystem ) {
31
+ if (topology -> is_thissystem ) { /* don't call CNK unless thissystem */
40
32
env = getenv ("BG_THREADMODEL" );
41
33
if (!env || atoi (env ) != 2 ) {
42
- /* process cannot use cores/threads outside of its Kernel_ThreadMask() */
34
+ /* process cannot use cores/threads outside of its Kernel_ThreadMask() unless BG_THREADMODEL=2 */
43
35
uint64_t bgmask = Kernel_ThreadMask (Kernel_MyTcoord ());
44
36
/* the mask is reversed, manually reverse it */
45
37
for (i = 0 ; i < 64 ; i ++ )
46
38
if (((bgmask >> i ) & 1 ) == 0 )
47
39
hwloc_bitmap_clr (topology -> levels [0 ][0 ]-> allowed_cpuset , 63 - i );
48
40
}
49
41
}
42
+ return 0 ;
43
+ }
44
+
45
+ static int
46
+ hwloc_look_bgq (struct hwloc_backend * backend )
47
+ {
48
+ struct hwloc_topology * topology = backend -> topology ;
49
+ hwloc_bitmap_t set ;
50
+ hwloc_obj_t obj ;
51
+ unsigned i ;
52
+
53
+ if (topology -> levels [0 ][0 ]-> cpuset )
54
+ /* somebody discovered things */
55
+ return -1 ;
56
+
57
+ hwloc_alloc_obj_cpusets (topology -> levels [0 ][0 ]);
58
+
59
+ hwloc_bgq__get_allowed_resources (topology );
50
60
51
61
/* a single memory bank */
52
62
obj = hwloc_alloc_setup_object (topology , HWLOC_OBJ_NUMANODE , 0 );
@@ -204,6 +214,21 @@ hwloc_bgq_set_thisthread_cpubind(hwloc_topology_t topology, hwloc_const_bitmap_t
204
214
return hwloc_bgq_set_thread_cpubind (topology , pthread_self (), hwloc_set , flags );
205
215
}
206
216
217
+ static int
218
+ hwloc_bgq_get_allowed_resources (struct hwloc_topology * topology )
219
+ {
220
+ /* Loading BGQ from XML isn't much useful since everything is hardwired anyway.
221
+ * But still implement XML + this callback in case portable applications want to always use XMLs.
222
+ */
223
+
224
+ /* In theory, when applying local restrictions to a XML-loaded topology,
225
+ * we should check that the current topology contains 1 NUMA nodes and 17*4 PUs.
226
+ *
227
+ * Just trust the user when he sets THISSYSTEM=1.
228
+ */
229
+ return hwloc_bgq__get_allowed_resources (topology );
230
+ }
231
+
207
232
void
208
233
hwloc_set_bgq_hooks (struct hwloc_binding_hooks * hooks __hwloc_attribute_unused ,
209
234
struct hwloc_topology_support * support __hwloc_attribute_unused )
@@ -215,6 +240,8 @@ hwloc_set_bgq_hooks(struct hwloc_binding_hooks *hooks __hwloc_attribute_unused,
215
240
/* threads cannot be bound to more than one PU, so get_last_cpu_location == get_cpubind */
216
241
hooks -> get_thisthread_last_cpu_location = hwloc_bgq_get_thisthread_cpubind ;
217
242
/* hooks->get_thread_last_cpu_location = hwloc_bgq_get_thread_cpubind; */
243
+
244
+ hooks -> get_allowed_resources = hwloc_bgq_get_allowed_resources ;
218
245
}
219
246
220
247
static struct hwloc_backend *
@@ -249,7 +276,8 @@ hwloc_bgq_component_instantiate(struct hwloc_disc_component *component,
249
276
if (!backend )
250
277
return NULL ;
251
278
backend -> discover = hwloc_look_bgq ;
252
- backend -> is_thissystem = !forced_nonbgq ;
279
+ if (forced_nonbgq )
280
+ backend -> is_thissystem = 0 ;
253
281
return backend ;
254
282
}
255
283
0 commit comments