|
| 1 | +/* |
| 2 | + * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. |
| 3 | + * Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved. |
| 4 | + * Copyright (c) 2014-2017 Intel, Inc. All rights reserved. |
| 5 | + * |
| 6 | + * $COPYRIGHT$ |
| 7 | + * |
| 8 | + * Additional copyrights may follow |
| 9 | + * |
| 10 | + * $HEADER$ |
| 11 | + */ |
| 12 | + |
| 13 | + |
| 14 | +#include "orte_config.h" |
| 15 | +#include "orte/constants.h" |
| 16 | + |
| 17 | +#include "opal/dss/dss.h" |
| 18 | +#include "opal/mca/event/event.h" |
| 19 | + |
| 20 | +#include "orte/mca/sensor/base/base.h" |
| 21 | +#include "orte/mca/sensor/base/sensor_private.h" |
| 22 | + |
| 23 | +static bool mods_active = false; |
| 24 | + |
| 25 | +void orte_sensor_base_start(orte_jobid_t job) |
| 26 | +{ |
| 27 | + orte_sensor_active_module_t *i_module; |
| 28 | + int i; |
| 29 | + |
| 30 | + if (0 < orte_sensor_base.rate.tv_sec) { |
| 31 | + opal_output_verbose(5, orte_sensor_base_framework.framework_output, |
| 32 | + "%s sensor:base: starting sensors", |
| 33 | + ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)); |
| 34 | + /* call the start function of all modules in priority order */ |
| 35 | + for (i=0; i < orte_sensor_base.modules.size; i++) { |
| 36 | + if (NULL == (i_module = (orte_sensor_active_module_t*)opal_pointer_array_get_item(&orte_sensor_base.modules, i))) { |
| 37 | + continue; |
| 38 | + } |
| 39 | + mods_active = true; |
| 40 | + if (NULL != i_module->module->start) { |
| 41 | + i_module->module->start(job); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + if (mods_active && !orte_sensor_base.active) { |
| 46 | + /* setup a buffer to collect samples */ |
| 47 | + orte_sensor_base.samples = OBJ_NEW(opal_buffer_t); |
| 48 | + /* startup a timer to wake us up periodically |
| 49 | + * for a data sample |
| 50 | + */ |
| 51 | + orte_sensor_base.active = true; |
| 52 | + opal_event_evtimer_set(orte_event_base, &orte_sensor_base.sample_ev, |
| 53 | + orte_sensor_base_sample, NULL); |
| 54 | + opal_event_evtimer_add(&orte_sensor_base.sample_ev, &orte_sensor_base.rate); |
| 55 | + } |
| 56 | + } |
| 57 | + return; |
| 58 | +} |
| 59 | + |
| 60 | +void orte_sensor_base_stop(orte_jobid_t job) |
| 61 | +{ |
| 62 | + orte_sensor_active_module_t *i_module; |
| 63 | + int i; |
| 64 | + |
| 65 | + if (!mods_active) { |
| 66 | + return; |
| 67 | + } |
| 68 | + |
| 69 | + opal_output_verbose(5, orte_sensor_base_framework.framework_output, |
| 70 | + "%s sensor:base: stopping sensors", |
| 71 | + ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)); |
| 72 | + |
| 73 | + if (orte_sensor_base.active) { |
| 74 | + opal_event_del(&orte_sensor_base.sample_ev); |
| 75 | + orte_sensor_base.active = false; |
| 76 | + } |
| 77 | + |
| 78 | + /* call the stop function of all modules in priority order */ |
| 79 | + for (i=0; i < orte_sensor_base.modules.size; i++) { |
| 80 | + if (NULL == (i_module = (orte_sensor_active_module_t*)opal_pointer_array_get_item(&orte_sensor_base.modules, i))) { |
| 81 | + continue; |
| 82 | + } |
| 83 | + if (NULL != i_module->module->stop) { |
| 84 | + i_module->module->stop(job); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + return; |
| 89 | +} |
| 90 | + |
| 91 | +void orte_sensor_base_sample(int fd, short args, void *cbdata) |
| 92 | +{ |
| 93 | + orte_sensor_active_module_t *i_module; |
| 94 | + int i; |
| 95 | + |
| 96 | + if (!mods_active) { |
| 97 | + return; |
| 98 | + } |
| 99 | + |
| 100 | + /* see if we were ordered to stop */ |
| 101 | + if (!orte_sensor_base.active) { |
| 102 | + return; |
| 103 | + } |
| 104 | + |
| 105 | + opal_output_verbose(5, orte_sensor_base_framework.framework_output, |
| 106 | + "%s sensor:base: sampling sensors", |
| 107 | + ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)); |
| 108 | + |
| 109 | + /* call the sample function of all modules in priority order from |
| 110 | + * highest to lowest - the heartbeat should always be the lowest |
| 111 | + * priority, so it will send any collected data |
| 112 | + */ |
| 113 | + for (i=0; i < orte_sensor_base.modules.size; i++) { |
| 114 | + if (NULL == (i_module = (orte_sensor_active_module_t*)opal_pointer_array_get_item(&orte_sensor_base.modules, i))) { |
| 115 | + continue; |
| 116 | + } |
| 117 | + if (NULL != i_module->module->sample) { |
| 118 | + opal_output_verbose(5, orte_sensor_base_framework.framework_output, |
| 119 | + "%s sensor:base: sampling component %s", |
| 120 | + ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), |
| 121 | + i_module->component->base_version.mca_component_name); |
| 122 | + i_module->module->sample(); |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + /* restart the timer */ |
| 127 | + opal_event_evtimer_add(&orte_sensor_base.sample_ev, &orte_sensor_base.rate); |
| 128 | + |
| 129 | + return; |
| 130 | +} |
| 131 | + |
| 132 | +void orte_sensor_base_log(char *comp, opal_buffer_t *data) |
| 133 | +{ |
| 134 | + int i; |
| 135 | + orte_sensor_active_module_t *i_module; |
| 136 | + |
| 137 | + if (NULL == comp) { |
| 138 | + /* nothing we can do */ |
| 139 | + return; |
| 140 | + } |
| 141 | + |
| 142 | + opal_output_verbose(5, orte_sensor_base_framework.framework_output, |
| 143 | + "%s sensor:base: logging sensor %s", |
| 144 | + ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), comp); |
| 145 | + |
| 146 | + /* find the specified module */ |
| 147 | + for (i=0; i < orte_sensor_base.modules.size; i++) { |
| 148 | + if (NULL == (i_module = (orte_sensor_active_module_t*)opal_pointer_array_get_item(&orte_sensor_base.modules, i))) { |
| 149 | + continue; |
| 150 | + } |
| 151 | + if (0 == strcmp(comp, i_module->component->base_version.mca_component_name)) { |
| 152 | + if (NULL != i_module->module->log) { |
| 153 | + i_module->module->log(data); |
| 154 | + } |
| 155 | + return; |
| 156 | + } |
| 157 | + } |
| 158 | +} |
0 commit comments