|
| 1 | +/* |
| 2 | + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana |
| 3 | + * University Research and Technology |
| 4 | + * Corporation. All rights reserved. |
| 5 | + * Copyright (c) 2004-2005 The University of Tennessee and The University |
| 6 | + * of Tennessee Research Foundation. All rights |
| 7 | + * reserved. |
| 8 | + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, |
| 9 | + * University of Stuttgart. All rights reserved. |
| 10 | + * Copyright (c) 2004-2005 The Regents of the University of California. |
| 11 | + * All rights reserved. |
| 12 | + * Copyright (c) 2021 Google, LLC. All rights reserved. |
| 13 | + * $COPYRIGHT$ |
| 14 | + * |
| 15 | + * Additional copyrights may follow |
| 16 | + * |
| 17 | + * $HEADER$ |
| 18 | + */ |
| 19 | + |
| 20 | +#include "opal_config.h" |
| 21 | +#include <stdio.h> |
| 22 | +#include <string.h> |
| 23 | + |
| 24 | +#include "opal/class/opal_list.h" |
| 25 | +#include "opal/mca/base/base.h" |
| 26 | +#include "opal/mca/mca.h" |
| 27 | +#include "opal/mca/smsc/base/base.h" |
| 28 | +#include "opal/mca/smsc/smsc.h" |
| 29 | +#include "opal/util/printf.h" |
| 30 | + |
| 31 | +/* |
| 32 | + * The following file was created by configure. It contains extern |
| 33 | + * statements and the definition of an array of pointers to each |
| 34 | + * component's public mca_base_component_t struct. |
| 35 | + */ |
| 36 | +#include "opal/mca/smsc/base/static-components.h" |
| 37 | + |
| 38 | +mca_smsc_component_t *selected_component = NULL; |
| 39 | +mca_smsc_module_t *mca_smsc = NULL; |
| 40 | + |
| 41 | +/* |
| 42 | + * Global variables |
| 43 | + */ |
| 44 | +MCA_BASE_FRAMEWORK_DECLARE(opal, smsc, NULL, NULL, NULL, NULL, mca_smsc_base_static_components, 0); |
| 45 | + |
| 46 | +static int mca_smsc_compare_components(opal_list_item_t **a, opal_list_item_t **b) |
| 47 | +{ |
| 48 | + mca_smsc_component_t *componenta |
| 49 | + = (mca_smsc_component_t *) ((mca_base_component_list_item_t *) *a)->cli_component; |
| 50 | + mca_smsc_component_t *componentb |
| 51 | + = (mca_smsc_component_t *) ((mca_base_component_list_item_t *) *b)->cli_component; |
| 52 | + |
| 53 | + return (componenta->priority > componentb->priority) |
| 54 | + ? -1 |
| 55 | + : ((componenta->priority < componentb->priority) ? 1 : 0); |
| 56 | +} |
| 57 | + |
| 58 | +int mca_smsc_base_select(void) |
| 59 | +{ |
| 60 | + mca_base_component_list_item_t *cli, *next; |
| 61 | + |
| 62 | + OPAL_LIST_FOREACH_SAFE (cli, next, &opal_smsc_base_framework.framework_components, |
| 63 | + mca_base_component_list_item_t) { |
| 64 | + mca_smsc_component_t *component = (mca_smsc_component_t *) cli->cli_component; |
| 65 | + |
| 66 | + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, opal_smsc_base_framework.framework_output, |
| 67 | + "mca_smsc_base_select: checking component %s", |
| 68 | + component->smsc_version.mca_component_name); |
| 69 | + |
| 70 | + int ret = component->query(); |
| 71 | + if (OPAL_SUCCESS != ret) { |
| 72 | + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, |
| 73 | + opal_smsc_base_framework.framework_output, |
| 74 | + "mca_smsc_base_select: could not select component %s. query " |
| 75 | + "returned error code %d", |
| 76 | + component->smsc_version.mca_component_name, ret); |
| 77 | + opal_list_remove_item(&opal_smsc_base_framework.framework_components, &cli->super); |
| 78 | + OBJ_RELEASE(cli); |
| 79 | + mca_base_component_close(&component->smsc_version, |
| 80 | + opal_smsc_base_framework.framework_output); |
| 81 | + continue; |
| 82 | + } |
| 83 | + opal_output_verbose(MCA_BASE_VERBOSE_COMPONENT, opal_smsc_base_framework.framework_output, |
| 84 | + "mca_smsc_base_select: component %s priority=%d", |
| 85 | + component->smsc_version.mca_component_name, component->priority); |
| 86 | + } |
| 87 | + |
| 88 | + opal_list_sort(&opal_smsc_base_framework.framework_components, mca_smsc_compare_components); |
| 89 | + |
| 90 | + if (opal_list_get_size(&opal_smsc_base_framework.framework_components) > 0) { |
| 91 | + cli = (mca_base_component_list_item_t *) opal_list_get_first( |
| 92 | + &opal_smsc_base_framework.framework_components); |
| 93 | + |
| 94 | + selected_component = (mca_smsc_component_t *) cli->cli_component; |
| 95 | + mca_smsc = selected_component->enable(); |
| 96 | + |
| 97 | + opal_output_verbose( |
| 98 | + MCA_BASE_VERBOSE_COMPONENT, opal_smsc_base_framework.framework_output, |
| 99 | + "mca_smsc_base_select: selected shared-memory single-copy component: %s", |
| 100 | + selected_component->smsc_version.mca_component_name); |
| 101 | + } else { |
| 102 | + opal_output_verbose( |
| 103 | + MCA_BASE_VERBOSE_COMPONENT, opal_smsc_base_framework.framework_output, |
| 104 | + "mca_smsc_base_select: no shared-memory single-copy component available for selection"); |
| 105 | + } |
| 106 | + |
| 107 | + return OPAL_SUCCESS; |
| 108 | +} |
| 109 | + |
| 110 | +void mca_smsc_base_register_default_params(mca_smsc_component_t *component, int default_priority) |
| 111 | +{ |
| 112 | + |
| 113 | + char *tmp; |
| 114 | + (void) opal_asprintf(&tmp, "Priority of the %s component (default: %d)", |
| 115 | + component->smsc_version.mca_component_name, default_priority); |
| 116 | + component->priority = default_priority; |
| 117 | + (void) mca_base_component_var_register(&component->smsc_version, "priority", /*help_msg=*/tmp, |
| 118 | + MCA_BASE_VAR_TYPE_INT, /*enumerator=*/NULL, /*bind=*/0, |
| 119 | + MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3, |
| 120 | + MCA_BASE_VAR_SCOPE_ALL_EQ, &component->priority); |
| 121 | + free(tmp); |
| 122 | +} |
0 commit comments