1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 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
|
/*
* 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 "opal/mca/hwloc/base/base.h"
#include "maffinity_hwloc.h"
#include "opal/mca/hwloc/hwloc.h"
/*
* 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 *);
static int hwloc_module_bind(opal_maffinity_base_segment_t *, size_t, int);
/*
* 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,
hwloc_module_bind
};
int opal_maffinity_hwloc_component_query(mca_base_module_t **module,
int *priority)
{
if (NULL == opal_hwloc_topology) {
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)
{
/* Nothing to do! */
return OPAL_SUCCESS;
}
static int hwloc_module_set(opal_maffinity_base_segment_t *segments,
size_t num_segments)
{
int rc = OPAL_SUCCESS;
char *msg = NULL;
size_t i;
hwloc_cpuset_t cpuset = NULL;
/* bozo check */
if (NULL == opal_hwloc_topology) {
msg = "hwloc_set_area_membind() failure - topology not available";
return opal_hwloc_base_report_bind_failure(__FILE__, __LINE__,
msg, rc);
}
/* 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();
if (NULL == cpuset) {
rc = OPAL_ERR_OUT_OF_RESOURCE;
msg = "hwloc_bitmap_alloc() failure";
goto out;
}
hwloc_get_cpubind(opal_hwloc_topology, cpuset, 0);
for (i = 0; i < num_segments; ++i) {
if (0 != hwloc_set_area_membind(opal_hwloc_topology,
segments[i].mbs_start_addr,
segments[i].mbs_len, cpuset,
HWLOC_MEMBIND_BIND,
HWLOC_MEMBIND_STRICT)) {
rc = OPAL_ERROR;
msg = "hwloc_set_area_membind() failure";
goto out;
}
}
out:
if (NULL != cpuset) {
hwloc_bitmap_free(cpuset);
}
if (OPAL_SUCCESS != rc) {
return opal_hwloc_base_report_bind_failure(__FILE__, __LINE__,
msg, rc);
}
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;
}
static int hwloc_module_bind(opal_maffinity_base_segment_t *segs,
size_t count, int node_id)
{
size_t i;
int rc = OPAL_SUCCESS;
char *msg = NULL;
hwloc_cpuset_t cpuset = NULL;
/* bozo check */
if (NULL == opal_hwloc_topology) {
msg = "hwloc_set_area_membind() failure - topology not available";
return opal_hwloc_base_report_bind_failure(__FILE__, __LINE__,
msg, rc);
}
cpuset = hwloc_bitmap_alloc();
if (NULL == cpuset) {
rc = OPAL_ERR_OUT_OF_RESOURCE;
msg = "hwloc_bitmap_alloc() failure";
goto out;
}
hwloc_bitmap_set(cpuset, node_id);
for(i = 0; i < count; i++) {
if (0 != hwloc_set_area_membind(opal_hwloc_topology,
segs[i].mbs_start_addr,
segs[i].mbs_len, cpuset,
HWLOC_MEMBIND_BIND,
HWLOC_MEMBIND_STRICT)) {
rc = OPAL_ERROR;
msg = "hwloc_set_area_membind() failure";
goto out;
}
}
out:
if (NULL != cpuset) {
hwloc_bitmap_free(cpuset);
}
if (OPAL_SUCCESS != rc) {
return opal_hwloc_base_report_bind_failure(__FILE__, __LINE__,
msg, rc);
}
return OPAL_SUCCESS;
}
|