Skip to content

Commit 3afadba

Browse files
author
Ralph Castain
authored
Merge pull request #3142 from rhc54/topic/sensor
Restore sensor framework
2 parents 74125ec + ab50665 commit 3afadba

32 files changed

+2992
-0
lines changed

orte/mca/sensor/Makefile.am

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright (c) 2009-2010 Cisco Systems, Inc. All rights reserved.
3+
#
4+
# Copyright (c) 2017 Intel, Inc. All rights reserved.
5+
# $COPYRIGHT$
6+
#
7+
# Additional copyrights may follow
8+
#
9+
# $HEADER$
10+
#
11+
12+
# main library setup
13+
noinst_LTLIBRARIES = libmca_sensor.la
14+
libmca_sensor_la_SOURCES =
15+
16+
# local files
17+
headers = sensor.h \
18+
sensor_types.h
19+
20+
libmca_sensor_la_SOURCES += $(headers)
21+
22+
# Conditionally install the header files
23+
if WANT_INSTALL_HEADERS
24+
ortedir = $(ompiincludedir)/$(subdir)
25+
nobase_orte_HEADERS = $(headers)
26+
endif
27+
28+
include base/Makefile.am
29+
30+
distclean-local:
31+
rm -f base/static-components.h

orte/mca/sensor/base/Makefile.am

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
3+
# Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
4+
#
5+
# Copyright (c) 2017 Intel, Inc. All rights reserved.
6+
# $COPYRIGHT$
7+
#
8+
# Additional copyrights may follow
9+
#
10+
# $HEADER$
11+
#
12+
13+
headers += \
14+
base/base.h \
15+
base/sensor_private.h
16+
17+
libmca_sensor_la_SOURCES += \
18+
base/sensor_base_frame.c \
19+
base/sensor_base_select.c \
20+
base/sensor_base_fns.c

orte/mca/sensor/base/base.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
3+
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights reserved.
4+
*
5+
* Copyright (c) 2017 Intel, Inc. All rights reserved.
6+
* $COPYRIGHT$
7+
*
8+
* Additional copyrights may follow
9+
*
10+
* $HEADER$
11+
*/
12+
/** @file:
13+
*/
14+
15+
#ifndef MCA_SENSOR_BASE_H
16+
#define MCA_SENSOR_BASE_H
17+
18+
/*
19+
* includes
20+
*/
21+
#include "orte_config.h"
22+
23+
#include "opal/class/opal_list.h"
24+
#include "opal/mca/base/base.h"
25+
26+
#include "orte/mca/sensor/sensor.h"
27+
28+
BEGIN_C_DECLS
29+
30+
/*
31+
* MCA Framework
32+
*/
33+
ORTE_DECLSPEC extern mca_base_framework_t orte_sensor_base_framework;
34+
/* select a component */
35+
ORTE_DECLSPEC int orte_sensor_base_select(void);
36+
37+
38+
END_C_DECLS
39+
#endif
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2+
/*
3+
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
4+
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
5+
*
6+
* Copyright (c) 2017 Intel, Inc. All rights reserved.
7+
* $COPYRIGHT$
8+
*
9+
* Additional copyrights may follow
10+
*
11+
* $HEADER$
12+
*/
13+
14+
15+
#include "orte_config.h"
16+
#include "orte/constants.h"
17+
18+
#include "opal/mca/mca.h"
19+
#include "opal/util/argv.h"
20+
#include "opal/util/output.h"
21+
#include "opal/mca/base/base.h"
22+
#include "opal/class/opal_pointer_array.h"
23+
24+
#ifdef HAVE_STRING_H
25+
#include <string.h>
26+
#endif
27+
28+
#include "orte/mca/sensor/base/base.h"
29+
#include "orte/mca/sensor/base/sensor_private.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+
37+
#include "orte/mca/sensor/base/static-components.h"
38+
39+
/*
40+
* Global variables
41+
*/
42+
orte_sensor_base_API_module_t orte_sensor = {
43+
orte_sensor_base_start,
44+
orte_sensor_base_stop
45+
};
46+
orte_sensor_base_t orte_sensor_base;
47+
48+
/*
49+
* Local variables
50+
*/
51+
static int orte_sensor_base_sample_rate = 0;
52+
53+
static int orte_sensor_base_register(mca_base_register_flag_t flags)
54+
{
55+
int var_id;
56+
57+
orte_sensor_base_sample_rate = 0;
58+
var_id = mca_base_var_register("orte", "sensor", "base", "sample_rate",
59+
"Sample rate in seconds",
60+
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
61+
OPAL_INFO_LVL_9,
62+
MCA_BASE_VAR_SCOPE_READONLY,
63+
&orte_sensor_base_sample_rate);
64+
mca_base_var_register_synonym(var_id, "orte", "sensor", NULL, "sample_rate",
65+
MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
66+
67+
/* see if we want samples logged */
68+
orte_sensor_base.log_samples = false;
69+
var_id = mca_base_var_register("orte", "sensor", "base", "log_samples",
70+
"Log samples to database",
71+
MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
72+
OPAL_INFO_LVL_9,
73+
MCA_BASE_VAR_SCOPE_READONLY,
74+
&orte_sensor_base.log_samples);
75+
mca_base_var_register_synonym(var_id, "orte", "sensor", NULL, "log_samples",
76+
MCA_BASE_VAR_SYN_FLAG_DEPRECATED);
77+
78+
return ORTE_SUCCESS;
79+
}
80+
81+
static int orte_sensor_base_close(void)
82+
{
83+
orte_sensor_active_module_t *i_module;
84+
int i;
85+
86+
for (i=0; i < orte_sensor_base.modules.size; i++) {
87+
if (NULL == (i_module = (orte_sensor_active_module_t*)opal_pointer_array_get_item(&orte_sensor_base.modules, i))) {
88+
continue;
89+
}
90+
if (NULL != i_module->module->finalize) {
91+
i_module->module->finalize();
92+
}
93+
}
94+
OBJ_DESTRUCT(&orte_sensor_base.modules);
95+
96+
/* Close all remaining available components */
97+
return mca_base_framework_components_close(&orte_sensor_base_framework, NULL);
98+
}
99+
100+
/**
101+
* Function for finding and opening either all MCA components, or the one
102+
* that was specifically requested via a MCA parameter.
103+
*/
104+
static int orte_sensor_base_open(mca_base_open_flag_t flags)
105+
{
106+
/* initialize globals */
107+
orte_sensor_base.active = false;
108+
109+
/* construct the array of modules */
110+
OBJ_CONSTRUCT(&orte_sensor_base.modules, opal_pointer_array_t);
111+
opal_pointer_array_init(&orte_sensor_base.modules, 3, INT_MAX, 1);
112+
113+
/* get the sample rate */
114+
orte_sensor_base.rate.tv_sec = orte_sensor_base_sample_rate;
115+
orte_sensor_base.rate.tv_usec = 0;
116+
117+
/* Open up all available components */
118+
return mca_base_framework_components_open(&orte_sensor_base_framework, flags);
119+
}
120+
121+
MCA_BASE_FRAMEWORK_DECLARE(orte, sensor, "ORTE Monitoring Sensors",
122+
orte_sensor_base_register,
123+
orte_sensor_base_open, orte_sensor_base_close,
124+
mca_sensor_base_static_components, 0);
125+
126+
static void cons(orte_sensor_active_module_t *t)
127+
{
128+
t->sampling = true;
129+
}
130+
OBJ_CLASS_INSTANCE(orte_sensor_active_module_t,
131+
opal_object_t,
132+
cons, NULL);

0 commit comments

Comments
 (0)