Skip to content

Commit 704d6e1

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 <clement.foyer@inria.fr>
1 parent b24d371 commit 704d6e1

File tree

4 files changed

+112
-41
lines changed

4 files changed

+112
-41
lines changed

ompi/mca/osc/monitoring/Makefile.am

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2016 Inria. All rights reserved.
2+
# Copyright (c) 2016-2017 Inria. All rights reserved.
33
# Copyright (c) 2017 IBM Corporation. All rights reserved.
44
# $COPYRIGHT$
55
#
@@ -32,8 +32,14 @@ mcacomponent_LTLIBRARIES = $(component_install)
3232
mca_osc_monitoring_la_SOURCES = $(monitoring_sources)
3333
mca_osc_monitoring_la_LDFLAGS = -module -avoid-version
3434
mca_osc_monitoring_la_LIBADD = $(top_builddir)/ompi/lib@OMPI_LIBMPI_NAME@.la \
35-
$(OMPI_TOP_BUILDDIR)/ompi/mca/common/monitoring/libmca_common_monitoring.la
35+
$(OMPI_TOP_BUILDDIR)/ompi/mca/common/monitoring/libmca_common_monitoring.la
3636

3737
noinst_LTLIBRARIES = $(component_noinst)
3838
libmca_osc_monitoring_la_SOURCES = $(monitoring_sources)
3939
libmca_osc_monitoring_la_LDFLAGS = -module -avoid-version
40+
41+
# C file depends on the header file generated at configure time
42+
$(srcdir)/osc_monitoring_component.c: $(builddir)/osc_monitoring_template_gen.h
43+
44+
distclean-local:
45+
rm -f $(builddir)/osc_monitoring_template_gen.h

ompi/mca/osc/monitoring/configure.m4

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

1184
# MCA_ompi_osc_monitoring_CONFIG()
1285
# ------------------------------------------------
@@ -16,7 +89,7 @@ AC_DEFUN([MCA_ompi_osc_monitoring_CONFIG],[
1689
AS_IF([test "$MCA_BUILD_ompi_common_monitoring_DSO_TRUE" = ''],
1790
[$1],
1891
[$2])
19-
OPAL_CHECK_PORTALS4([osc_monitoring],
20-
[AC_DEFINE([OMPI_WITH_OSC_PORTALS4], [1], [Whether or not to generate template for osc_portals4])],
21-
[])
92+
93+
mca_ompi_osc_monitoring_generate_templates([ompi/mca/osc/monitoring/osc_monitoring_template_gen.h],
94+
[mca_ompi_osc_m4_config_component_list, mca_ompi_osc_no_config_component_list])dnl
2295
])dnl

ompi/mca/osc/monitoring/osc_monitoring_component.c

+6-19
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@
1818
#include <ompi/mca/osc/base/base.h>
1919
#include <opal/mca/base/mca_base_component_repository.h>
2020

21-
/***************************************/
22-
/* Include template generating macros */
23-
#include "osc_monitoring_template.h"
21+
/**************************************/
22+
/* Include templated macros */
2423

25-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(rdma)
26-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(sm)
27-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(pt2pt)
28-
OSC_MONITORING_MODULE_TEMPLATE_GENERATE(portals4)
24+
#include "osc_monitoring_template_gen.h"
2925

3026
/***************************************/
3127

@@ -95,20 +91,11 @@ static int mca_osc_monitoring_component_select(struct ompi_win_t *win, void **ba
9591
ret = best_component->osc_select(win, base, size, disp_unit, comm, info, flavor, model);
9692
if( OMPI_SUCCESS == ret ) {
9793
/* Intercept module functions with ours, based on selected component */
98-
if( 0 == strcmp("rdma", best_component->osc_version.mca_component_name) ) {
99-
OSC_MONITORING_SET_TEMPLATE(rdma, win->w_osc_module);
100-
} else if( 0 == strcmp("sm", best_component->osc_version.mca_component_name) ) {
101-
OSC_MONITORING_SET_TEMPLATE(sm, win->w_osc_module);
102-
} else if( 0 == strcmp("pt2pt", best_component->osc_version.mca_component_name) ) {
103-
OSC_MONITORING_SET_TEMPLATE(pt2pt, win->w_osc_module);
104-
#ifdef OMPI_WITH_OSC_PORTALS4
105-
} else if( 0 == strcmp("portals4", best_component->osc_version.mca_component_name) ) {
106-
OSC_MONITORING_SET_TEMPLATE(portals4, win->w_osc_module);
107-
#endif /* OMPI_WITH_OSC_PORTALS4 */
108-
} else {
94+
ret = ompi_mca_osc_monitoring_set_template(best_component, win->w_osc_module);
95+
if (OMPI_ERR_NOT_SUPPORTED == ret) {
10996
OPAL_MONITORING_PRINT_WARN("osc: monitoring disabled: no module for this component "
11097
"(%s)", best_component->osc_version.mca_component_name);
111-
return ret;
98+
return OMPI_SUCCESS;
11299
}
113100
}
114101
return ret;

ompi/mca/osc/monitoring/osc_monitoring_template.h

+16-11
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_fetch_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)