2005-08-26 23:51:02 +04:00
|
|
|
/*
|
2008-05-06 22:08:45 +04:00
|
|
|
* Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
|
2005-11-05 22:57:48 +03:00
|
|
|
* 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.
|
2005-08-26 23:51:02 +04:00
|
|
|
* 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.
|
2008-06-16 21:26:42 +04:00
|
|
|
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
|
2005-08-26 23:51:02 +04:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal_config.h"
|
2005-08-26 23:51:02 +04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <numa.h>
|
2008-06-15 11:27:29 +04:00
|
|
|
#include <numaif.h>
|
2005-08-26 23:51:02 +04:00
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal/constants.h"
|
2005-08-26 23:51:02 +04:00
|
|
|
#include "opal/mca/maffinity/maffinity.h"
|
|
|
|
#include "opal/mca/maffinity/base/base.h"
|
|
|
|
#include "maffinity_libnuma.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local functions
|
|
|
|
*/
|
|
|
|
static int libnuma_module_init(void);
|
|
|
|
static int libnuma_module_set(opal_maffinity_base_segment_t *segments,
|
2005-09-02 16:57:02 +04:00
|
|
|
size_t num_segments);
|
2008-06-15 11:27:29 +04:00
|
|
|
static int libnuma_module_node_name_to_id(char *, int *);
|
|
|
|
static int libnuma_modules_bind(opal_maffinity_base_segment_t *, size_t, int);
|
2005-08-26 23:51:02 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Libnuma maffinity module
|
|
|
|
*/
|
2008-05-06 22:08:45 +04:00
|
|
|
static const opal_maffinity_base_module_1_0_0_t loc_module = {
|
2005-08-26 23:51:02 +04:00
|
|
|
/* Initialization function */
|
|
|
|
libnuma_module_init,
|
|
|
|
|
|
|
|
/* Module function pointers */
|
2008-06-15 11:27:29 +04:00
|
|
|
libnuma_module_set,
|
|
|
|
libnuma_module_node_name_to_id,
|
|
|
|
libnuma_modules_bind
|
2005-08-26 23:51:02 +04:00
|
|
|
};
|
|
|
|
|
2008-05-06 22:08:45 +04:00
|
|
|
int opal_maffinity_libnuma_component_query(mca_base_module_t **module, int *priority)
|
2005-08-26 23:51:02 +04:00
|
|
|
{
|
|
|
|
int param;
|
|
|
|
|
|
|
|
if (-1 == numa_available()) {
|
2008-05-06 22:08:45 +04:00
|
|
|
return OPAL_ERROR;
|
2005-08-26 23:51:02 +04:00
|
|
|
}
|
|
|
|
param = mca_base_param_find("maffinity", "libnuma", "priority");
|
2008-05-06 22:08:45 +04:00
|
|
|
mca_base_param_lookup_int(param, priority);
|
|
|
|
|
|
|
|
*module = (mca_base_module_t *)&loc_module;
|
2005-08-26 23:51:02 +04:00
|
|
|
|
2008-05-06 22:08:45 +04:00
|
|
|
return OPAL_SUCCESS;
|
2005-08-26 23:51:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int libnuma_module_init(void)
|
|
|
|
{
|
2005-08-29 19:13:54 +04:00
|
|
|
/* Tell libnuma that we want all memory affinity to be local (but
|
|
|
|
it's not an error if we can't -- prefer running in degraded
|
|
|
|
mode to not running at all!). */
|
2005-08-26 23:51:02 +04:00
|
|
|
|
2005-08-29 19:13:54 +04:00
|
|
|
numa_set_strict(0);
|
2005-08-26 23:51:02 +04:00
|
|
|
numa_set_localalloc();
|
|
|
|
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int libnuma_module_set(opal_maffinity_base_segment_t *segments,
|
2005-09-02 16:57:02 +04:00
|
|
|
size_t num_segments)
|
2005-08-26 23:51:02 +04:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
2005-08-29 19:13:54 +04:00
|
|
|
/* Kinda crummy that we have to allocate each portion individually
|
|
|
|
rather than provide a top-level function call that does it all,
|
|
|
|
but the libnuma() interface doesn't seem to allow that
|
|
|
|
flexability -- they allow "interleaving", but not fine grained
|
|
|
|
placement of pages. */
|
2005-08-26 23:51:02 +04:00
|
|
|
|
|
|
|
for (i = 0; i < num_segments; ++i) {
|
2005-09-02 16:57:02 +04:00
|
|
|
numa_setlocal_memory(segments[i].mbs_start_addr,
|
|
|
|
segments[i].mbs_len);
|
2005-08-26 23:51:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
2008-06-15 11:27:29 +04:00
|
|
|
|
|
|
|
static int libnuma_module_node_name_to_id(char *node_name, int *id)
|
|
|
|
{
|
|
|
|
/* GLB: fix me */
|
|
|
|
*id = atoi(node_name + 3);
|
|
|
|
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int libnuma_modules_bind(opal_maffinity_base_segment_t *segs,
|
|
|
|
size_t count, int node_id)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
int rc;
|
|
|
|
unsigned long node_mask = (1 << node_id);
|
|
|
|
|
|
|
|
for(i = 0; i < count; i++) {
|
|
|
|
rc = mbind(segs[i].mbs_start_addr, segs[i].mbs_len, MPOL_PREFERRED,
|
2008-06-16 21:26:42 +04:00
|
|
|
&node_mask, sizeof(node_mask) * 8,
|
|
|
|
#ifdef HAVE_MPOL_MF_MOVE
|
|
|
|
MPOL_MF_MOVE
|
|
|
|
#else
|
|
|
|
MPOL_MF_STRICT
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
if (0 != rc) {
|
2008-06-15 11:27:29 +04:00
|
|
|
return OPAL_ERROR;
|
2008-06-16 21:26:42 +04:00
|
|
|
}
|
2008-06-15 11:27:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|