/* * 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" /* This component will only be compiled on Solaris, where we are guaranteed to have these headers */ #include #include #include #include #include #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_solaris.h" #include "opal/util/output.h" /* * Local functions */ static int solaris_module_init(void); static int solaris_module_set(opal_paffinity_base_cpu_set_t cpumask); static int solaris_module_get(opal_paffinity_base_cpu_set_t *cpumask); static int solaris_module_finalize(void); static int cpumask_to_id(opal_paffinity_base_cpu_set_t cpumask); static int solaris_module_map_to_processor_id(int socket, int core, int *processor_id); static int solaris_module_map_to_socket_core(int processor_id, int *socket, int *core); static int solaris_module_get_processor_info(int *num_processors); static int solaris_module_get_socket_info(int *num_sockets); static int solaris_module_get_core_info(int socket, int *num_cores); static int solaris_module_get_physical_processor_id(int logical_processor_id); static int solaris_module_get_physical_socket_id(int logical_socket_id); static int solaris_module_get_physical_core_id(int physical_socket_id, int logical_core_id); /* * Solaris paffinity module */ static const opal_paffinity_base_module_1_1_0_t loc_module = { /* Initialization function */ solaris_module_init, /* Module function pointers */ solaris_module_set, solaris_module_get, solaris_module_map_to_processor_id, solaris_module_map_to_socket_core, solaris_module_get_processor_info, solaris_module_get_socket_info, solaris_module_get_core_info, solaris_module_get_physical_processor_id, solaris_module_get_physical_socket_id, solaris_module_get_physical_core_id, solaris_module_finalize }; int opal_paffinity_solaris_component_query(mca_base_module_t **module, int *priority) { int param; param = mca_base_param_find("paffinity", "solaris", "priority"); mca_base_param_lookup_int(param, priority); *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 solaris_module_set function */ static int solaris_module_init(void) { return OPAL_SUCCESS; } /* this gives us a cpumask which tells which CPU to bind */ static int solaris_module_set(opal_paffinity_base_cpu_set_t cpumask) { processorid_t cpuid; /* Find out where in the cpumask is the location of the current CPU. */ cpuid = cpumask_to_id(cpumask); if (-1 == cpuid) { opal_output(0, "paffinity:solaris: Error when coverting cpumask to id"); return OPAL_ERR_IN_ERRNO; } if (0 != processor_bind(P_PID, P_MYID, cpuid, NULL)) { opal_output(0, "paffinity:solaris: Error when binding to CPU #%d: %s", cpuid, strerror(errno)); return OPAL_ERR_IN_ERRNO; } opal_output_verbose(5, opal_paffinity_base_output, "paffinity:solaris: Successfully bind to CPU #%d", cpuid); return OPAL_SUCCESS; } /* this takes a cpumask and converts it to CPU id on a node */ static int cpumask_to_id(opal_paffinity_base_cpu_set_t cpumask) { int currid; for(currid=0; currid