Skip to content

Commit a53118e

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]> Reduce the amount of symbols defined. Most of variables could be static inside functions, reducing the impact in term of used symbols. Signed-off-by: Clement Foyer <[email protected]>
1 parent ff207ee commit a53118e

File tree

5 files changed

+176
-110
lines changed

5 files changed

+176
-110
lines changed

ompi/mca/osc/monitoring/Makefile.am

Lines changed: 8 additions & 2 deletions
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@[email protected] \
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
Lines changed: 82 additions & 9 deletions
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_FCT_NAME(${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

Lines changed: 6 additions & 19 deletions
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_module.h

Lines changed: 70 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,69 +22,87 @@
2222
#define OMPI_OSC_MONITORING_MODULE_VARIABLE(template) \
2323
ompi_osc_monitoring_module_## template ##_template
2424

25-
/* Define once and for all the module_template variable name */
26-
#define OMPI_OSC_MONITORING_MODULE_INIT(template) \
27-
ompi_osc_monitoring_module_## template ##_init_done
28-
29-
/* Define once and for all the template variable name */
30-
#define OMPI_OSC_MONITORING_TEMPLATE_VARIABLE(template) \
31-
ompi_osc_monitoring_## template ##_template
25+
/* Define once and for all the
26+
* ompi_osc_monitoring_## template ##_set_template function name
27+
*/
28+
#define OSC_MONITORING_SET_TEMPLATE_FCT_NAME(template) \
29+
ompi_osc_monitoring_## template ##_set_template
3230

33-
/* Define the ompi_osc_monitoring_module_## template ##_template variable */
31+
/* Define the ompi_osc_monitoring_module_## template ##_template
32+
* variable
33+
*/
3434
#define OMPI_OSC_MONITORING_MODULE_GENERATE(template) \
35-
static ompi_osc_base_module_t OMPI_OSC_MONITORING_MODULE_VARIABLE(template)
35+
/* Define the ompi_osc_monitoring_module_## template ##_template */ \
36+
static ompi_osc_base_module_t OMPI_OSC_MONITORING_MODULE_VARIABLE(template);
3637

37-
/* Define the ompi_osc_monitoring_module_## template ##_init_done variable */
38-
#define OMPI_OSC_MONITORING_MODULE_INIT_GENERATE(template) \
39-
static int32_t OMPI_OSC_MONITORING_MODULE_INIT(template)
38+
#define OSC_MONITORING_GENERATE_TEMPLATE_MODULE(template) \
39+
\
40+
static int ompi_osc_monitoring_## template ##_free(ompi_win_t *win) \
41+
{ \
42+
return OMPI_OSC_MONITORING_MODULE_VARIABLE(template).osc_free(win); \
43+
}
4044

41-
/* Define and set the ompi_osc_monitoring_## template ##_template
42-
* variable. The functions recorded here are linked to the original
43-
* functions of the original {template} module that weas replaced.
44-
*/
4545
#define MCA_OSC_MONITORING_MODULE_TEMPLATE_GENERATE(template) \
46-
static const ompi_osc_base_module_t OMPI_OSC_MONITORING_TEMPLATE_VARIABLE(template) = { \
47-
.osc_win_attach = ompi_osc_monitoring_## template ##_attach, \
48-
.osc_win_detach = ompi_osc_monitoring_## template ##_detach, \
49-
.osc_free = ompi_osc_monitoring_## template ##_free, \
46+
/* Generate template specific module initialization function: \
47+
* ompi_osc_monitoring_## template ##_set_template(ompi_osc_base_module_t*module) \
48+
*/ \
49+
static inline ompi_osc_base_module_t * \
50+
OSC_MONITORING_SET_TEMPLATE_FCT_NAME(template) (ompi_osc_base_module_t*module) \
51+
{ \
52+
/* Define the ompi_osc_monitoring_module_## template ##_init_done variable */ \
53+
static int32_t init_done = 0; \
54+
/* Define and set the ompi_osc_monitoring_## template \
55+
* ##_template variable. The functions recorded here are \
56+
* linked to the original functions of the original \
57+
* {template} module that was replaced. \
58+
*/ \
59+
static const ompi_osc_base_module_t module_specific_interception_layer = { \
60+
.osc_win_attach = ompi_osc_monitoring_## template ##_attach, \
61+
.osc_win_detach = ompi_osc_monitoring_## template ##_detach, \
62+
.osc_free = ompi_osc_monitoring_## template ##_free, \
5063
\
51-
.osc_put = ompi_osc_monitoring_## template ##_put, \
52-
.osc_get = ompi_osc_monitoring_## template ##_get, \
53-
.osc_accumulate = ompi_osc_monitoring_## template ##_accumulate, \
54-
.osc_compare_and_swap = ompi_osc_monitoring_## template ##_compare_and_swap, \
55-
.osc_fetch_and_op = ompi_osc_monitoring_## template ##_fetch_and_op, \
56-
.osc_get_accumulate = ompi_osc_monitoring_## template ##_get_accumulate, \
64+
.osc_put = ompi_osc_monitoring_## template ##_put, \
65+
.osc_get = ompi_osc_monitoring_## template ##_get, \
66+
.osc_accumulate = ompi_osc_monitoring_## template ##_accumulate, \
67+
.osc_compare_and_swap = ompi_osc_monitoring_## template ##_compare_and_swap, \
68+
.osc_fetch_and_op = ompi_osc_monitoring_## template ##_fetch_and_op, \
69+
.osc_get_accumulate = ompi_osc_monitoring_## template ##_get_accumulate, \
5770
\
58-
.osc_rput = ompi_osc_monitoring_## template ##_rput, \
59-
.osc_rget = ompi_osc_monitoring_## template ##_rget, \
60-
.osc_raccumulate = ompi_osc_monitoring_## template ##_raccumulate, \
61-
.osc_rget_accumulate = ompi_osc_monitoring_## template ##_rget_accumulate, \
71+
.osc_rput = ompi_osc_monitoring_## template ##_rput, \
72+
.osc_rget = ompi_osc_monitoring_## template ##_rget, \
73+
.osc_raccumulate = ompi_osc_monitoring_## template ##_raccumulate, \
74+
.osc_rget_accumulate = ompi_osc_monitoring_## template ##_rget_accumulate, \
6275
\
63-
.osc_fence = ompi_osc_monitoring_## template ##_fence, \
76+
.osc_fence = ompi_osc_monitoring_## template ##_fence, \
6477
\
65-
.osc_start = ompi_osc_monitoring_## template ##_start, \
66-
.osc_complete = ompi_osc_monitoring_## template ##_complete, \
67-
.osc_post = ompi_osc_monitoring_## template ##_post, \
68-
.osc_wait = ompi_osc_monitoring_## template ##_wait, \
69-
.osc_test = ompi_osc_monitoring_## template ##_test, \
78+
.osc_start = ompi_osc_monitoring_## template ##_start, \
79+
.osc_complete = ompi_osc_monitoring_## template ##_complete, \
80+
.osc_post = ompi_osc_monitoring_## template ##_post, \
81+
.osc_wait = ompi_osc_monitoring_## template ##_wait, \
82+
.osc_test = ompi_osc_monitoring_## template ##_test, \
7083
\
71-
.osc_lock = ompi_osc_monitoring_## template ##_lock, \
72-
.osc_unlock = ompi_osc_monitoring_## template ##_unlock, \
73-
.osc_lock_all = ompi_osc_monitoring_## template ##_lock_all, \
74-
.osc_unlock_all = ompi_osc_monitoring_## template ##_unlock_all, \
84+
.osc_lock = ompi_osc_monitoring_## template ##_lock, \
85+
.osc_unlock = ompi_osc_monitoring_## template ##_unlock, \
86+
.osc_lock_all = ompi_osc_monitoring_## template ##_lock_all, \
87+
.osc_unlock_all = ompi_osc_monitoring_## template ##_unlock_all, \
7588
\
76-
.osc_sync = ompi_osc_monitoring_## template ##_sync, \
77-
.osc_flush = ompi_osc_monitoring_## template ##_flush, \
78-
.osc_flush_all = ompi_osc_monitoring_## template ##_flush_all, \
79-
.osc_flush_local = ompi_osc_monitoring_## template ##_flush_local, \
80-
.osc_flush_local_all = ompi_osc_monitoring_## template ##_flush_local_all, \
81-
}
82-
83-
#define OSC_MONITORING_GENERATE_TEMPLATE_MODULE(template) \
84-
\
85-
static int ompi_osc_monitoring_## template ##_free(ompi_win_t *win) \
86-
{ \
87-
return OMPI_OSC_MONITORING_MODULE_VARIABLE(template).osc_free(win); \
89+
.osc_sync = ompi_osc_monitoring_## template ##_sync, \
90+
.osc_flush = ompi_osc_monitoring_## template ##_flush, \
91+
.osc_flush_all = ompi_osc_monitoring_## template ##_flush_all, \
92+
.osc_flush_local = ompi_osc_monitoring_## template ##_flush_local, \
93+
.osc_flush_local_all = ompi_osc_monitoring_## template ##_flush_local_all, \
94+
}; \
95+
if ( 1 == opal_atomic_add_fetch_32(&init_done, 1) ) { \
96+
/* Saves the original module functions in \
97+
* ompi_osc_monitoring_module_## template ##_template \
98+
*/ \
99+
memcpy(&OMPI_OSC_MONITORING_MODULE_VARIABLE(template), \
100+
module, sizeof(ompi_osc_base_module_t)); \
101+
} \
102+
/* Replace the original functions with our generated ones */ \
103+
memcpy(module, &module_specific_interception_layer, \
104+
sizeof(ompi_osc_base_module_t)); \
105+
return module; \
88106
}
89107

90108
#endif /* MCA_OSC_MONITORING_MODULE_H */

ompi/mca/osc/monitoring/osc_monitoring_template.h

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,28 @@
2727
* {template} parameter), we generate a set of every functions defined
2828
* in ompi_osc_base_module_t, the ompi_osc_monitoring_module_##
2929
* template ##_template variable recording the original set of
30-
* functions, and the ompi_osc_monitoring_## template ##_template
31-
* variable that record the generated set of functions. When a
32-
* function is called from the original module, we route the call to
33-
* our generated function that does the monitoring, and then we call
34-
* the original function that had been saved in the
30+
* functions, and the generated set of functions is recorded as a
31+
* static variable inside the initialization function. When a function
32+
* is called from the original module, we route the call to our
33+
* generated function that does the monitoring, and then we call the
34+
* original function that had been saved in the
3535
* ompi_osc_monitoring_module_## template ##_template variable.
3636
*/
3737
#define OSC_MONITORING_MODULE_TEMPLATE_GENERATE(template) \
3838
/* Generate the proper symbol for the \
3939
ompi_osc_monitoring_module_## template ##_template variable */ \
40-
OMPI_OSC_MONITORING_MODULE_GENERATE(template); \
41-
OMPI_OSC_MONITORING_MODULE_INIT_GENERATE(template); \
40+
OMPI_OSC_MONITORING_MODULE_GENERATE(template) \
4241
/* Generate each module specific functions */ \
4342
OSC_MONITORING_GENERATE_TEMPLATE_ACCUMULATE(template) \
4443
OSC_MONITORING_GENERATE_TEMPLATE_ACTIVE_TARGET(template) \
4544
OSC_MONITORING_GENERATE_TEMPLATE_COMM(template) \
4645
OSC_MONITORING_GENERATE_TEMPLATE_DYNAMIC(template) \
4746
OSC_MONITORING_GENERATE_TEMPLATE_MODULE(template) \
4847
OSC_MONITORING_GENERATE_TEMPLATE_PASSIVE_TARGET(template) \
49-
/* Set the mca_osc_monitoring_## template ##_template variable */ \
50-
MCA_OSC_MONITORING_MODULE_TEMPLATE_GENERATE(template); \
51-
/* Generate template specific module initialization function */ \
52-
static inline void* \
53-
ompi_osc_monitoring_## template ##_set_template (ompi_osc_base_module_t*module) \
54-
{ \
55-
if( 1 == opal_atomic_add_fetch_32(&(OMPI_OSC_MONITORING_MODULE_INIT(template)), 1) ) { \
56-
/* Saves the original module functions in \
57-
* ompi_osc_monitoring_module_## template ##_template \
58-
*/ \
59-
memcpy(&OMPI_OSC_MONITORING_MODULE_VARIABLE(template), \
60-
module, sizeof(ompi_osc_base_module_t)); \
61-
} \
62-
/* Replace the original functions with our generated ones */ \
63-
memcpy(module, &OMPI_OSC_MONITORING_TEMPLATE_VARIABLE(template), \
64-
sizeof(ompi_osc_base_module_t)); \
65-
return module; \
66-
}
67-
68-
#define OSC_MONITORING_SET_TEMPLATE(template, module) \
69-
ompi_osc_monitoring_## template ##_set_template(module)
48+
/* Generate template specific module initialization function: \
49+
* ompi_osc_monitoring_## template ##_set_template(ompi_osc_base_module_t*module) \
50+
*/ \
51+
MCA_OSC_MONITORING_MODULE_TEMPLATE_GENERATE(template)
7052

7153
#endif /* MCA_OSC_MONITORING_TEMPLATE_H */
7254

0 commit comments

Comments
 (0)