Skip to content

Commit f058ac3

Browse files
committed
Add automatic generation at config time.
The templates are expanded at configure time. It creates a new header file that generates all the variables/functions needed. Adding this during the autogen automatically generates for each of the available modules. Signed-off-by: Clement Foyer <[email protected]>
1 parent 39f97f9 commit f058ac3

File tree

4 files changed

+115
-35
lines changed

4 files changed

+115
-35
lines changed

ompi/mca/osc/monitoring/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ monitoring_sources = \
1717
osc_monitoring_active_target.h \
1818
osc_monitoring_dynamic.h \
1919
osc_monitoring_module.h \
20-
osc_monitoring_template.h
20+
osc_monitoring_template.h \
21+
osc_monitoring_template_gen.h
2122

2223
if MCA_BUILD_ompi_osc_monitoring_DSO
2324
component_noinst =

ompi/mca/osc/monitoring/configure.m4

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# -*- shell-script -*-
2+
#
3+
# Copyright (c) 2016-2017 Inria. All rights reserved.
4+
# $COPYRIGHT$
5+
#
6+
# Additional copyrights may follow
7+
#
8+
# $HEADER$
9+
#
10+
11+
# mca_ompi_osc_monitoring_generate_templates
12+
#
13+
# Append to file $1 an array of components by listing component names in $2.
14+
#
15+
# $1 = filename
16+
# $2 = osc component names
17+
#
18+
AC_DEFUN([mca_ompi_osc_monitoring_generate_templates],[
19+
m4_ifval([$1], [
20+
cat <<EOF >[$1]
21+
/*
22+
* DO NOT EDIT - This file generated from
23+
* ompi/mca/osc/monitoring/configure.m4
24+
*/
25+
/*
26+
* Copyright (c) 2017 Inria. All rights reserved.
27+
* \$COPYRIGHT$
28+
*
29+
* Additional copyrights may follow
30+
*
31+
* \$HEADER$
32+
*/
33+
34+
#ifndef MCA_OSC_MONITORING_GEN_TEMPLATE_H
35+
#define MCA_OSC_MONITORING_GEN_TEMPLATE_H
36+
37+
#include <string.h>
38+
#include <ompi_config.h>
39+
#include <ompi/mca/osc/osc.h>
40+
#include "osc_monitoring_template.h"
41+
42+
/***************************************/
43+
/* Include template generating macros */
44+
45+
EOF
46+
# Generate each case in order to register the proper template functions
47+
for comp in `echo $2 | sed -e 's/,/ /g' -e 's/monitoring//'`
48+
do
49+
echo "OSC_MONITORING_MODULE_TEMPLATE_GENERATE(${comp})" >>[$1]
50+
done
51+
cat <<EOF >>[$1]
52+
53+
/***************************************/
54+
55+
static inline int
56+
ompi_mca_osc_monitoring_set_template(ompi_osc_base_component_t *best_component,
57+
ompi_osc_base_module_t *module)
58+
{
59+
EOF
60+
echo -n ' ' >>[$1]
61+
for comp in `echo $2 | sed -e 's/,/ /g' -e 's/monitoring//'`
62+
do
63+
echo "if ( 0 == strcmp(\"${comp}\", best_component->osc_version.mca_component_name) ) {" >>[$1]
64+
echo " OSC_MONITORING_SET_TEMPLATE(${comp}, module);" >>[$1]
65+
echo -n ' } else ' >>[$1]
66+
done
67+
echo '' >>[$1]
68+
cat <<EOF >>[$1]
69+
return OMPI_ERR_NOT_SUPPORTED;
70+
return OMPI_SUCCESS;
71+
}
72+
73+
#endif /* MCA_OSC_MONITORING_GEN_TEMPLATE_H */
74+
EOF
75+
])dnl
76+
])dnl
77+
78+
# MCA_ompi_osc_monitoring_CONFIG()
79+
# ------------------------------------------------
80+
AC_DEFUN([MCA_ompi_osc_monitoring_CONFIG],[
81+
AC_CONFIG_FILES([ompi/mca/osc/monitoring/Makefile])
82+
83+
AS_IF([test "$MCA_BUILD_ompi_common_monitoring_DSO_TRUE" = ''],
84+
[$1],
85+
[$2])
86+
87+
mca_ompi_osc_monitoring_generate_templates([$OMPI_TOP_SRCDIR/ompi/mca/osc/monitoring/osc_monitoring_template_gen.h],
88+
[mca_ompi_osc_m4_config_component_list, mca_ompi_osc_no_config_component_list])dnl
89+
])dnl

ompi/mca/osc/monitoring/osc_monitoring_component.c

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
#include <ompi/mca/osc/base/base.h>
1919
#include <opal/mca/base/mca_base_component_repository.h>
2020

21+
/**************************************/
22+
/* Include templated macros */
23+
24+
#include "osc_monitoring_template_gen.h"
25+
2126
/***************************************/
2227

2328
static opal_hash_table_t *win_to_comm_ht = NULL;
@@ -32,17 +37,6 @@ ompi_osc_monitoring_get_comm(ompi_win_t *win)
3237
return OPAL_SUCCESS == ret ? comm : NULL;
3338
}
3439

35-
/***************************************/
36-
/* Include template generating macros */
37-
#include "osc_monitoring_template.h"
38-
39-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(rdma)
40-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(sm)
41-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(pt2pt)
42-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(portals4)
43-
44-
/***************************************/
45-
4640
static int mca_osc_monitoring_component_init(bool enable_progress_threads,
4741
bool enable_mpi_threads)
4842
{
@@ -121,20 +115,11 @@ static int mca_osc_monitoring_component_select(struct ompi_win_t *win, void **ba
121115
ret = best_component->osc_select(win, base, size, disp_unit, comm, info, flavor, model);
122116
if( OMPI_SUCCESS == ret ) {
123117
/* Intercept module functions with ours, based on selected component */
124-
if( 0 == strcmp("rdma", best_component->osc_version.mca_component_name) ) {
125-
OSC_MONITORING_SET_TEMPLATE(rdma, win->w_osc_module);
126-
} else if( 0 == strcmp("sm", best_component->osc_version.mca_component_name) ) {
127-
OSC_MONITORING_SET_TEMPLATE(sm, win->w_osc_module);
128-
} else if( 0 == strcmp("pt2pt", best_component->osc_version.mca_component_name) ) {
129-
OSC_MONITORING_SET_TEMPLATE(pt2pt, win->w_osc_module);
130-
#ifdef OMPI_WITH_OSC_PORTALS4
131-
} else if( 0 == strcmp("portals4", best_component->osc_version.mca_component_name) ) {
132-
OSC_MONITORING_SET_TEMPLATE(portals4, win->w_osc_module);
133-
#endif /* OMPI_WITH_OSC_PORTALS4 */
134-
} else {
118+
ret = ompi_mca_osc_monitoring_set_template(best_component, win->w_osc_module);
119+
if (OMPI_ERR_NOT_SUPPORTED == ret) {
135120
OPAL_MONITORING_PRINT_WARN("osc: monitoring disabled: no module for this component "
136121
"(%s)", best_component->osc_version.mca_component_name);
137-
return ret;
122+
return OMPI_SUCCESS;
138123
}
139124
}
140125
if( OPAL_SUCCESS != opal_hash_table_set_value_uint64(win_to_comm_ht, win, (void *)comm) ) {

ompi/mca/osc/monitoring/osc_monitoring_template.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,25 @@
5555
ompi_osc_monitoring_## template ##_set_template (ompi_osc_base_module_t*module) \
5656
{ \
5757
if( 1 == opal_atomic_add_32(&(OMPI_OSC_MONITORING_MODULE_INIT(template)), 1) ) { \
58-
/* Saves the original module functions in \
59-
* ompi_osc_monitoring_module_## template ##_template \
60-
*/ \
61-
memcpy(&OMPI_OSC_MONITORING_MODULE_VARIABLE(template), \
62-
module, sizeof(ompi_osc_base_module_t)); \
63-
} \
64-
/* Replace the original functions with our generated ones */ \
65-
memcpy(module, &OMPI_OSC_MONITORING_TEMPLATE_VARIABLE(template), \
66-
sizeof(ompi_osc_base_module_t)); \
67-
return module; \
58+
/* Saves the original module functions in \
59+
* ompi_osc_monitoring_module_## template ##_template \
60+
*/ \
61+
memcpy(&OMPI_OSC_MONITORING_MODULE_VARIABLE(template), \
62+
module, sizeof(ompi_osc_base_module_t)); \
63+
} \
64+
/* Replace the original functions with our generated ones */ \
65+
memcpy(module, &OMPI_OSC_MONITORING_TEMPLATE_VARIABLE(template), \
66+
sizeof(ompi_osc_base_module_t)); \
67+
return module; \
6868
}
6969

70-
#define OSC_MONITORING_SET_TEMPLATE(template, module) \
70+
#define OSC_MONITORING_SET_TEMPLATE(template, module) \
7171
ompi_osc_monitoring_## template ##_set_template(module)
7272

73+
/* Accessory function to retreive the communicator's address given a
74+
* window pointer.
75+
*/
76+
static inline struct ompi_communicator_t* ompi_osc_monitoring_get_comm(ompi_win_t *win);
77+
7378
#endif /* MCA_OSC_MONITORING_TEMPLATE_H */
7479

0 commit comments

Comments
 (0)