2011-02-23 02:21:48 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2006-2011 Cisco Systems, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opal_config.h"
|
|
|
|
|
|
|
|
/* This component will only be compiled on Hwloc, where we are
|
|
|
|
guaranteed to have <unistd.h> and friends */
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "opal/constants.h"
|
|
|
|
#include "opal/mca/base/mca_base_param.h"
|
|
|
|
#include "opal/mca/maffinity/maffinity.h"
|
|
|
|
#include "opal/mca/maffinity/base/base.h"
|
|
|
|
#include "maffinity_hwloc.h"
|
2011-09-11 23:02:24 +04:00
|
|
|
#include "opal/mca/hwloc/hwloc.h"
|
2011-02-23 02:21:48 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local functions
|
|
|
|
*/
|
|
|
|
static int hwloc_module_init(void);
|
|
|
|
static int hwloc_module_set(opal_maffinity_base_segment_t *segments,
|
|
|
|
size_t num_segments);
|
|
|
|
static int hwloc_module_node_name_to_id(char *, int *);
|
2011-04-26 17:31:07 +04:00
|
|
|
static int hwloc_module_bind(opal_maffinity_base_segment_t *, size_t, int);
|
2011-02-23 02:21:48 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hwloc maffinity module
|
|
|
|
*/
|
|
|
|
static const opal_maffinity_base_module_1_0_0_t local_module = {
|
|
|
|
/* Initialization function */
|
|
|
|
hwloc_module_init,
|
|
|
|
|
|
|
|
/* Module function pointers */
|
|
|
|
hwloc_module_set,
|
|
|
|
hwloc_module_node_name_to_id,
|
2011-04-26 17:31:07 +04:00
|
|
|
hwloc_module_bind
|
2011-02-23 02:21:48 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
int opal_maffinity_hwloc_component_query(mca_base_module_t **module,
|
|
|
|
int *priority)
|
|
|
|
{
|
2011-09-17 17:13:36 +04:00
|
|
|
if (NULL == opal_hwloc_topology) {
|
2011-02-23 02:21:48 +03:00
|
|
|
return OPAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
*priority = mca_maffinity_hwloc_component.priority;
|
|
|
|
*module = (mca_base_module_t *) &local_module;
|
|
|
|
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int hwloc_module_init(void)
|
|
|
|
{
|
2011-09-19 20:10:37 +04:00
|
|
|
/* Nothing to do! */
|
2011-04-26 17:31:07 +04:00
|
|
|
|
2011-09-19 20:10:37 +04:00
|
|
|
return OPAL_SUCCESS;
|
2011-02-23 02:21:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int hwloc_module_set(opal_maffinity_base_segment_t *segments,
|
|
|
|
size_t num_segments)
|
|
|
|
{
|
2011-04-26 17:31:07 +04:00
|
|
|
int rc = OPAL_SUCCESS;
|
|
|
|
char *msg = NULL;
|
2011-02-23 02:21:48 +03:00
|
|
|
size_t i;
|
2011-04-26 17:31:07 +04:00
|
|
|
hwloc_cpuset_t cpuset = NULL;
|
2011-02-23 02:21:48 +03:00
|
|
|
|
|
|
|
/* This module won't be used unless the process is already
|
|
|
|
processor-bound. So find out where we're processor bound, and
|
|
|
|
bind our memory there, too. */
|
|
|
|
cpuset = hwloc_bitmap_alloc();
|
2011-04-26 17:31:07 +04:00
|
|
|
if (NULL == cpuset) {
|
|
|
|
rc = OPAL_ERR_OUT_OF_RESOURCE;
|
|
|
|
msg = "hwloc_bitmap_alloc() failure";
|
|
|
|
goto out;
|
|
|
|
}
|
2011-09-17 17:13:36 +04:00
|
|
|
hwloc_get_cpubind(opal_hwloc_topology, cpuset, 0);
|
2011-02-23 02:21:48 +03:00
|
|
|
for (i = 0; i < num_segments; ++i) {
|
2011-09-17 17:13:36 +04:00
|
|
|
if (0 != hwloc_set_area_membind(opal_hwloc_topology,
|
2011-02-23 02:21:48 +03:00
|
|
|
segments[i].mbs_start_addr,
|
|
|
|
segments[i].mbs_len, cpuset,
|
|
|
|
HWLOC_MEMBIND_BIND,
|
|
|
|
HWLOC_MEMBIND_STRICT)) {
|
2011-04-26 17:31:07 +04:00
|
|
|
rc = OPAL_ERROR;
|
|
|
|
msg = "hwloc_set_area_membind() failure";
|
|
|
|
goto out;
|
2011-02-23 02:21:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-26 17:31:07 +04:00
|
|
|
out:
|
|
|
|
if (NULL != cpuset) {
|
|
|
|
hwloc_bitmap_free(cpuset);
|
|
|
|
}
|
|
|
|
if (OPAL_SUCCESS != rc) {
|
|
|
|
return opal_maffinity_base_report_bind_failure(__FILE__, __LINE__,
|
|
|
|
msg, rc);
|
|
|
|
}
|
2011-02-23 02:21:48 +03:00
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hwloc_module_node_name_to_id(char *node_name, int *id)
|
|
|
|
{
|
|
|
|
/* GLB: fix me */
|
|
|
|
*id = atoi(node_name + 3);
|
|
|
|
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-04-26 17:31:07 +04:00
|
|
|
static int hwloc_module_bind(opal_maffinity_base_segment_t *segs,
|
|
|
|
size_t count, int node_id)
|
2011-02-23 02:21:48 +03:00
|
|
|
{
|
|
|
|
size_t i;
|
2011-04-26 17:31:07 +04:00
|
|
|
int rc = OPAL_SUCCESS;
|
|
|
|
char *msg = NULL;
|
|
|
|
hwloc_cpuset_t cpuset = NULL;
|
2011-02-23 02:21:48 +03:00
|
|
|
|
|
|
|
cpuset = hwloc_bitmap_alloc();
|
2011-04-26 17:31:07 +04:00
|
|
|
if (NULL == cpuset) {
|
|
|
|
rc = OPAL_ERR_OUT_OF_RESOURCE;
|
|
|
|
msg = "hwloc_bitmap_alloc() failure";
|
|
|
|
goto out;
|
|
|
|
}
|
2011-02-23 02:21:48 +03:00
|
|
|
hwloc_bitmap_set(cpuset, node_id);
|
|
|
|
for(i = 0; i < count; i++) {
|
2011-09-17 17:13:36 +04:00
|
|
|
if (0 != hwloc_set_area_membind(opal_hwloc_topology,
|
2011-02-23 02:21:48 +03:00
|
|
|
segs[i].mbs_start_addr,
|
|
|
|
segs[i].mbs_len, cpuset,
|
|
|
|
HWLOC_MEMBIND_BIND,
|
|
|
|
HWLOC_MEMBIND_STRICT)) {
|
2011-04-26 17:31:07 +04:00
|
|
|
rc = OPAL_ERROR;
|
|
|
|
msg = "hwloc_set_area_membind() failure";
|
|
|
|
goto out;
|
2011-02-23 02:21:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-26 17:31:07 +04:00
|
|
|
out:
|
|
|
|
if (NULL != cpuset) {
|
|
|
|
hwloc_bitmap_free(cpuset);
|
|
|
|
}
|
|
|
|
if (OPAL_SUCCESS != rc) {
|
|
|
|
return opal_maffinity_base_report_bind_failure(__FILE__, __LINE__,
|
|
|
|
msg, rc);
|
|
|
|
}
|
2011-02-23 02:21:48 +03:00
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|