Skip to content

Commit cd92833

Browse files
committed
bgq: port to the new get_allowed_resources() hook
Loading BGQ from XML isn't much useful since everything is hardwired anyway. But still implement XML + this callback in case portable applications want to always use XMLs. Signed-off-by: Brice Goglin <[email protected]>
1 parent 9b53fe5 commit cd92833

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

hwloc/topology-bgq.c

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2013-2016 Inria. All rights reserved.
2+
* Copyright © 2013-2017 Inria. All rights reserved.
33
* See COPYING in top-level directory.
44
*/
55

@@ -17,36 +17,46 @@
1717

1818
#ifndef HWLOC_DISABLE_BGQ_PORT_TEST
1919

20+
#define HWLOC_BGQ_CORES 17 /* spare core ignored for now */
21+
2022
static int
21-
hwloc_look_bgq(struct hwloc_backend *backend)
23+
hwloc_bgq__get_allowed_resources(struct hwloc_topology *topology)
2224
{
23-
struct hwloc_topology *topology = backend->topology;
24-
hwloc_bitmap_t set;
25-
hwloc_obj_t obj;
26-
unsigned i;
2725
const char *env;
26+
unsigned i;
2827

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]);
3628
/* mark the 17th core (OS-reserved) as disallowed */
3729
hwloc_bitmap_clr_range(topology->levels[0][0]->allowed_cpuset, (HWLOC_BGQ_CORES-1)*4, HWLOC_BGQ_CORES*4-1);
3830

39-
if (topology->is_thissystem) {
31+
if (topology->is_thissystem) { /* don't call CNK unless thissystem */
4032
env = getenv("BG_THREADMODEL");
4133
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 */
4335
uint64_t bgmask = Kernel_ThreadMask(Kernel_MyTcoord());
4436
/* the mask is reversed, manually reverse it */
4537
for(i=0; i<64; i++)
4638
if (((bgmask >> i) & 1) == 0)
4739
hwloc_bitmap_clr(topology->levels[0][0]->allowed_cpuset, 63-i);
4840
}
4941
}
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);
5060

5161
/* a single memory bank */
5262
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
204214
return hwloc_bgq_set_thread_cpubind(topology, pthread_self(), hwloc_set, flags);
205215
}
206216

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+
207232
void
208233
hwloc_set_bgq_hooks(struct hwloc_binding_hooks *hooks __hwloc_attribute_unused,
209234
struct hwloc_topology_support *support __hwloc_attribute_unused)
@@ -215,6 +240,8 @@ hwloc_set_bgq_hooks(struct hwloc_binding_hooks *hooks __hwloc_attribute_unused,
215240
/* threads cannot be bound to more than one PU, so get_last_cpu_location == get_cpubind */
216241
hooks->get_thisthread_last_cpu_location = hwloc_bgq_get_thisthread_cpubind;
217242
/* hooks->get_thread_last_cpu_location = hwloc_bgq_get_thread_cpubind; */
243+
244+
hooks->get_allowed_resources = hwloc_bgq_get_allowed_resources;
218245
}
219246

220247
static struct hwloc_backend *
@@ -249,7 +276,8 @@ hwloc_bgq_component_instantiate(struct hwloc_disc_component *component,
249276
if (!backend)
250277
return NULL;
251278
backend->discover = hwloc_look_bgq;
252-
backend->is_thissystem = !forced_nonbgq;
279+
if (forced_nonbgq)
280+
backend->is_thissystem = 0;
253281
return backend;
254282
}
255283

0 commit comments

Comments
 (0)