1
1

Improvements to the MCA param system: allow querying to find out where

an MCA parameter's value came from.  Note that the actual value of the
parameter is irrelevant.  For example, if a value was specified in an
MCA parameter file that happened to have the same defaultvalue that
was specified when the parameter was registered, the returned location
will indicate that the value was set from the file.

Possible answers:

 * '''MCA_BASE_PARAM_SOURCE_DEFAULT:''' no user-specified values were
   found, so the default value was used
 * '''MCA_BASE_PARAM_SOURCE_ENV:''' the value came from the
   environment (which also means the mpirun/orterun command line!)
 * '''MCA_BASE_PARAM_SOURCE_FILE:''' the value came a file (or the
   Windows registry)
 * '''MCA_BASE_PARAM_SOURCE_KEYVAL:''' the value came from a keyval
   (can currently never happen)
 * '''MCA_BASE_PARAM_SOURCE_OVERRIDE:''' the value came from an MCA
   param API "set" function

This commit was SVN r18770.
Этот коммит содержится в:
Jeff Squyres 2008-06-28 15:13:25 +00:00
родитель 59b7665a3a
Коммит 8efe67e08c
2 изменённых файлов: 80 добавлений и 17 удалений

Просмотреть файл

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -87,7 +88,8 @@ static int param_register(const char *type_name,
mca_base_param_storage_t *override_value,
mca_base_param_storage_t *current_value);
static bool param_lookup(size_t index, mca_base_param_storage_t *storage,
opal_hash_table_t *attrs);
opal_hash_table_t *attrs,
mca_base_param_source_t *source);
static bool param_set_override(size_t index,
mca_base_param_storage_t *storage,
mca_base_param_type_t type);
@ -459,7 +461,7 @@ int mca_base_param_lookup_int(int index, int *value)
{
mca_base_param_storage_t storage;
if (param_lookup(index, &storage, NULL)) {
if (param_lookup(index, &storage, NULL, NULL)) {
*value = storage.intval;
return OPAL_SUCCESS;
}
@ -475,7 +477,7 @@ int mca_base_param_kv_lookup_int(int index, opal_hash_table_t *attrs,
{
mca_base_param_storage_t storage;
if (param_lookup(index, &storage, attrs)) {
if (param_lookup(index, &storage, attrs, NULL)) {
*value = storage.intval;
return OPAL_SUCCESS;
}
@ -504,7 +506,7 @@ int mca_base_param_lookup_string(int index, char **value)
{
mca_base_param_storage_t storage;
if (param_lookup(index, &storage, NULL)) {
if (param_lookup(index, &storage, NULL, NULL)) {
*value = storage.stringval;
return OPAL_SUCCESS;
}
@ -520,7 +522,7 @@ int mca_base_param_kv_lookup_string(int index, opal_hash_table_t *attrs,
{
mca_base_param_storage_t storage;
if (param_lookup(index, &storage, attrs)) {
if (param_lookup(index, &storage, attrs, NULL)) {
*value = storage.stringval;
return OPAL_SUCCESS;
}
@ -542,6 +544,19 @@ int mca_base_param_set_string(int index, char *value)
}
/*
* Lookup the source of an MCA param's value
*/
bool mca_base_param_lookup_source(int index, mca_base_param_source_t *source)
{
mca_base_param_storage_t storage;
if (param_lookup(index, &storage, NULL, source)) {
return OPAL_SUCCESS;
}
return OPAL_ERROR;
}
/*
* Unset a parameter
*/
@ -781,7 +796,7 @@ int mca_base_param_build_env(char ***env, int *num_env, bool internal)
}
if (array[i].mbp_internal == internal || internal) {
if (param_lookup(i, &storage, NULL)) {
if (param_lookup(i, &storage, NULL, NULL)) {
if (MCA_BASE_PARAM_TYPE_INT == array[i].mbp_type) {
asprintf(&str, "%s=%d", array[i].mbp_env_var_name,
storage.intval);
@ -1444,7 +1459,7 @@ static int param_register(const char *type_name,
/* Finally, if we have a lookup value, look it up */
if (NULL != current_value) {
if (!param_lookup(i, current_value, NULL)) {
if (!param_lookup(i, current_value, NULL, NULL)) {
return OPAL_ERR_NOT_FOUND;
}
}
@ -1466,7 +1481,7 @@ static int param_register(const char *type_name,
/* Finally, if we have a lookup value, look it up */
if (NULL != current_value) {
if (!param_lookup(ret, current_value, NULL)) {
if (!param_lookup(ret, current_value, NULL, NULL)) {
return OPAL_ERR_NOT_FOUND;
}
}
@ -1518,12 +1533,13 @@ static bool param_set_override(size_t index,
* Lookup a parameter in multiple places
*/
static bool param_lookup(size_t index, mca_base_param_storage_t *storage,
opal_hash_table_t *attrs)
opal_hash_table_t *attrs,
mca_base_param_source_t *source_param)
{
size_t size;
mca_base_param_t *array;
char *p, *q;
bool found;
mca_base_param_source_t source = MCA_BASE_PARAM_SOURCE_MAX;
/* Lookup the index and see if it's valid */
@ -1555,15 +1571,26 @@ static bool param_lookup(size_t index, mca_base_param_storage_t *storage,
opal_show_help("help-mca-param.txt", "read-only-param-set",
true, array[index].mbp_full_name);
}
found = lookup_default(&array[index], storage);
if (lookup_default(&array[index], storage)) {
source = MCA_BASE_PARAM_SOURCE_DEFAULT;
}
} else {
found = (lookup_override(&array[index], storage) ||
lookup_keyvals(&array[index], storage, attrs) ||
lookup_env(&array[index], storage) ||
lookup_file(&array[index], storage) ||
lookup_default(&array[index], storage));
if (lookup_override(&array[index], storage)) {
source = MCA_BASE_PARAM_SOURCE_OVERRIDE;
} else if (lookup_keyvals(&array[index], storage, attrs)) {
source = MCA_BASE_PARAM_SOURCE_KEYVAL;
} else if (lookup_env(&array[index], storage)) {
source = MCA_BASE_PARAM_SOURCE_ENV;
} else if (lookup_file(&array[index], storage)) {
source = MCA_BASE_PARAM_SOURCE_FILE;
} else if (lookup_default(&array[index], storage)) {
source = MCA_BASE_PARAM_SOURCE_DEFAULT;
}
}
if (found) {
if (MCA_BASE_PARAM_SOURCE_MAX != source) {
if (NULL != source_param) {
*source_param = source;
}
/* If we're returning a string, replace all instances of "~/"
with the user's home directory */

Просмотреть файл

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -80,6 +81,26 @@ typedef enum {
} mca_base_param_type_t;
/**
* Source of an MCA parameter's value
*/
typedef enum {
/** The default value */
MCA_BASE_PARAM_SOURCE_DEFAULT,
/** The value came from the environment (or command line!) */
MCA_BASE_PARAM_SOURCE_ENV,
/** The value came from a file */
MCA_BASE_PARAM_SOURCE_FILE,
/** The value came from a keyval */
MCA_BASE_PARAM_SOURCE_KEYVAL,
/** The value came a "set" API call */
MCA_BASE_PARAM_SOURCE_OVERRIDE,
/** Maximum source type */
MCA_BASE_PARAM_SOURCE_MAX
} mca_base_param_source_t;
/**
* Struct for holding name/type info. Used in mca_base_param_dump(),
* below.
@ -491,6 +512,21 @@ extern "C" {
struct opal_hash_table_t *attrs,
char **value);
/**
* Lookup the source of an MCA parameter's value
*
* @param index [in] Index of MCA parameter to set
* @param value [in] The integer value to set
*
* @retval OPAL_ERROR If the parameter was not found.
* @retval OPAL_SUCCESS Upon success.
*
* This function looks up to see where the value of an MCA
* parameter came from.
*/
OPAL_DECLSPEC bool mca_base_param_lookup_source(int index,
mca_base_param_source_t *source);
/**
* Sets an "override" value for an integer MCA parameter.
*