From 2178f995b92066877629dea0f550ab139e9982ba Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Wed, 26 Aug 2009 01:55:30 +0000 Subject: [PATCH] Add a new "test" module to the paffinity framework that mimics a system that supports affinity when running on a Mac for development purposes. Only active if specifically called out. This commit was SVN r21881. --- opal/mca/paffinity/test/Makefile.am | 43 +++++ opal/mca/paffinity/test/configure.m4 | 34 ++++ opal/mca/paffinity/test/configure.params | 28 +++ opal/mca/paffinity/test/paffinity_test.h | 41 +++++ .../paffinity/test/paffinity_test_component.c | 83 +++++++++ .../paffinity/test/paffinity_test_module.c | 164 ++++++++++++++++++ 6 files changed, 393 insertions(+) create mode 100644 opal/mca/paffinity/test/Makefile.am create mode 100644 opal/mca/paffinity/test/configure.m4 create mode 100644 opal/mca/paffinity/test/configure.params create mode 100644 opal/mca/paffinity/test/paffinity_test.h create mode 100644 opal/mca/paffinity/test/paffinity_test_component.c create mode 100644 opal/mca/paffinity/test/paffinity_test_module.c diff --git a/opal/mca/paffinity/test/Makefile.am b/opal/mca/paffinity/test/Makefile.am new file mode 100644 index 0000000000..fcd67cbde1 --- /dev/null +++ b/opal/mca/paffinity/test/Makefile.am @@ -0,0 +1,43 @@ +# +# Copyright (c) 2004-2005 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$ +# +# Additional copyrights may follow +# +# $HEADER$ +# + +sources = \ + paffinity_test.h \ + paffinity_test_component.c \ + paffinity_test_module.c + +# Make the output library in this directory, and name it either +# mca__.la (for DSO builds) or libmca__.la +# (for static builds). + +if OMPI_BUILD_paffinity_test_DSO +component_noinst = +component_install = mca_paffinity_test.la +else +component_noinst = libmca_paffinity_test.la +component_install = +endif + +mcacomponentdir = $(pkglibdir) +mcacomponent_LTLIBRARIES = $(component_install) +mca_paffinity_test_la_SOURCES = $(sources) +mca_paffinity_test_la_LDFLAGS = -module -avoid-version + +noinst_LTLIBRARIES = $(component_noinst) +libmca_paffinity_test_la_SOURCES =$(sources) +libmca_paffinity_test_la_LDFLAGS = -module -avoid-version diff --git a/opal/mca/paffinity/test/configure.m4 b/opal/mca/paffinity/test/configure.m4 new file mode 100644 index 0000000000..fe13a0b03e --- /dev/null +++ b/opal/mca/paffinity/test/configure.m4 @@ -0,0 +1,34 @@ +# -*- shell-script -*- +# +# Copyright (c) 2004-2005 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) 2007-2008 Cisco, Inc. All rights reserved. +# Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# + +# MCA_paffinity_test_CONFIG([action-if-found], [action-if-not-found]) +# ----------------------------------------------------------- +AC_DEFUN([MCA_paffinity_test_CONFIG],[ + OMPI_VAR_SCOPE_PUSH([paff_test_happy]) + # check to see if we have + # as this is a Darwin-specific thing and + # we are a test module for that environment + AC_CHECK_HEADER([mach/mach_host.h], [paff_test_happy=yes], [paff_test_happy=no]) + + AS_IF([test "$paff_test_happy" = "yes"], [$1], [$2]) + OMPI_VAR_SCOPE_POP +])dnl + diff --git a/opal/mca/paffinity/test/configure.params b/opal/mca/paffinity/test/configure.params new file mode 100644 index 0000000000..06c35fda22 --- /dev/null +++ b/opal/mca/paffinity/test/configure.params @@ -0,0 +1,28 @@ +# -*- shell-script -*- +# +# Copyright (c) 2004-2005 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) 2007 Los Alamos National Security, LLC. All rights +# reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# + +PARAM_CONFIG_FILES="Makefile" + +# +# Set the config priority so that, if we can build, +# only this component will build + +PARAM_CONFIG_PRIORITY=50 diff --git a/opal/mca/paffinity/test/paffinity_test.h b/opal/mca/paffinity/test/paffinity_test.h new file mode 100644 index 0000000000..bdd9ec22fa --- /dev/null +++ b/opal/mca/paffinity/test/paffinity_test.h @@ -0,0 +1,41 @@ +/* + * 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) 2007 Cisco, Inc. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef MCA_PAFFINITY_TEST_EXPORT_H +#define MCA_PAFFINITY_TEST_EXPORT_H + +#include "opal_config.h" + +#include "opal/mca/mca.h" +#include "opal/mca/paffinity/paffinity.h" + +BEGIN_C_DECLS + +/* + * Globally exported variable + */ + +OPAL_DECLSPEC extern const opal_paffinity_base_component_2_0_0_t mca_paffinity_test_component; + +/* query function */ +int opal_paffinity_test_component_query(mca_base_module_t **module, int *priority); + +END_C_DECLS + +#endif /* MCA_PAFFINITY_TEST_EXPORT_H */ diff --git a/opal/mca/paffinity/test/paffinity_test_component.c b/opal/mca/paffinity/test/paffinity_test_component.c new file mode 100644 index 0000000000..9311ce2a87 --- /dev/null +++ b/opal/mca/paffinity/test/paffinity_test_component.c @@ -0,0 +1,83 @@ +/* + * 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) 2007 Cisco, Inc. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + * + * These symbols are in a file by themselves to provide nice linker + * semantics. Since linkers generally pull in symbols by object + * files, keeping these symbols as the only symbols in this file + * prevents utility programs such as "ompi_info" from having to import + * entire components just to query their version and parameters. + */ + +#include "opal_config.h" + +#include "opal/constants.h" +#include "opal/mca/paffinity/paffinity.h" +#include "paffinity_test.h" + +/* + * Public string showing the paffinity ompi_test component version number + */ +const char *opal_paffinity_test_component_version_string = + "OPAL test paffinity MCA component version " OPAL_VERSION; + +/* + * Local function + */ +static int test_open(void); + +/* + * Instantiate the public struct with all of our public information + * and pointers to our public functions in it + */ + +const opal_paffinity_base_component_2_0_0_t mca_paffinity_test_component = { + + /* First, the mca_component_t struct containing meta information + about the component itself */ + + { + /* Indicate that we are a paffinity v1.1.0 component (which also + implies a specific MCA version) */ + + OPAL_PAFFINITY_BASE_VERSION_2_0_0, + + /* Component name and version */ + + "test", + OPAL_MAJOR_VERSION, + OPAL_MINOR_VERSION, + OPAL_RELEASE_VERSION, + + /* Component open and close functions */ + + test_open, + NULL, + opal_paffinity_test_component_query + }, + /* Next the MCA v1.0.0 component meta data */ + { + /* The component is checkpoint ready */ + MCA_BASE_METADATA_PARAM_CHECKPOINT + } +}; + + +static int test_open(void) +{ + return OPAL_SUCCESS; +} diff --git a/opal/mca/paffinity/test/paffinity_test_module.c b/opal/mca/paffinity/test/paffinity_test_module.c new file mode 100644 index 0000000000..e82151b1ce --- /dev/null +++ b/opal/mca/paffinity/test/paffinity_test_module.c @@ -0,0 +1,164 @@ +/* + * 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) 2007 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved. + * + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "opal_config.h" +#include "opal/constants.h" + +#include "opal/mca/base/mca_base_param.h" +#include "opal/mca/paffinity/paffinity.h" +#include "opal/mca/paffinity/base/base.h" + +#include "paffinity_test.h" + +/* Fake an arch */ +#define NUM_SOCKETS 4 +#define NUM_CORES 4 + +/* + * Local functions + */ +static int init(void); +static int set(opal_paffinity_base_cpu_set_t cpumask); +static int get(opal_paffinity_base_cpu_set_t *cpumask); +static int finalize(void); +static int map_to_processor_id(int socket, int core, int *processor_id); +static int map_to_socket_core(int processor_id, int *socket, int *core); +static int get_processor_info(int *num_processors); +static int get_socket_info(int *num_sockets); +static int get_core_info(int socket, int *num_cores); +static int get_physical_processor_id(int logical_processor_id); +static int get_physical_socket_id(int logical_socket_id); +static int get_physical_core_id(int physical_socket_id, int logical_core_id); + +/* + * Test paffinity module + */ +static const opal_paffinity_base_module_1_1_0_t loc_module = { + /* Initialization function */ + init, + + /* Module function pointers */ + set, + get, + map_to_processor_id, + map_to_socket_core, + get_processor_info, + get_socket_info, + get_core_info, + get_physical_processor_id, + get_physical_socket_id, + get_physical_core_id, + finalize +}; + +int opal_paffinity_test_component_query(mca_base_module_t **module, int *priority) +{ + /* set this priority so I can only be selected if directed */ + *priority = 00; + *module = (mca_base_module_t *)&loc_module; + + return OPAL_SUCCESS; +} + +/* do nothing here. both mpirun and processes would run init(), but + * only processes would run the set function */ +static int init(void) +{ + return OPAL_SUCCESS; +} + +/* this gives us a cpumask which tells which CPU to bind */ +static int set(opal_paffinity_base_cpu_set_t cpumask) +{ + return OPAL_SUCCESS; +} + +/* This get function returns the CPU id that's currently binded, + * and then sets the cpumask. */ +static int get(opal_paffinity_base_cpu_set_t *cpumask) +{ + int i; + + OPAL_PAFFINITY_CPU_ZERO(*cpumask); + for (i=0; i < NUM_SOCKETS*NUM_CORES; i+=2) { + OPAL_PAFFINITY_CPU_SET(i, *cpumask); + } + /* assign all cores in the 2nd socket */ + for (i=NUM_CORES; i < 2*NUM_CORES; i++) { + OPAL_PAFFINITY_CPU_SET(i, *cpumask); + } + return OPAL_SUCCESS; +} + +static int map_to_processor_id(int socket, int core, int *processor_id) +{ + *processor_id = socket*NUM_CORES + core; + return OPAL_SUCCESS; +} + +static int map_to_socket_core(int processor_id, int *socket, int *core) +{ + *socket = processor_id / NUM_CORES; + *core = processor_id % NUM_CORES; + return OPAL_SUCCESS; +} + +static int get_processor_info(int *num_processors) +{ + *num_processors = NUM_SOCKETS * NUM_CORES; + return OPAL_SUCCESS; +} + +static int get_socket_info(int *num_sockets) +{ + *num_sockets = NUM_SOCKETS; + return OPAL_SUCCESS; +} + +static int get_core_info(int socket, int *num_cores) +{ + *num_cores = NUM_CORES; + return OPAL_SUCCESS; +} + +static int get_physical_processor_id(int logical_processor_id) +{ + return logical_processor_id; +} + +static int get_physical_socket_id(int logical_socket_id) +{ + return logical_socket_id; +} + +static int get_physical_core_id(int physical_socket_id, int logical_core_id) +{ + if (NUM_CORES < logical_core_id) { + return OPAL_ERROR; + } + return logical_core_id; +} + +static int finalize(void) +{ + return OPAL_SUCCESS; +} +