|
22 | 22 | #define OMPI_OSC_MONITORING_MODULE_VARIABLE(template) \ |
23 | 23 | ompi_osc_monitoring_module_## template ##_template |
24 | 24 |
|
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 |
32 | 30 |
|
33 | | -/* Define the ompi_osc_monitoring_module_## template ##_template variable */ |
| 31 | +/* Define the ompi_osc_monitoring_module_## template ##_template |
| 32 | + * variable |
| 33 | + */ |
34 | 34 | #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); |
36 | 37 |
|
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 | + } |
40 | 44 |
|
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 | | - */ |
45 | 45 | #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, \ |
50 | 63 | \ |
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, \ |
57 | 70 | \ |
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, \ |
62 | 75 | \ |
63 | | - .osc_fence = ompi_osc_monitoring_## template ##_fence, \ |
| 76 | + .osc_fence = ompi_osc_monitoring_## template ##_fence, \ |
64 | 77 | \ |
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, \ |
70 | 83 | \ |
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, \ |
75 | 88 | \ |
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; \ |
88 | 106 | } |
89 | 107 |
|
90 | 108 | #endif /* MCA_OSC_MONITORING_MODULE_H */ |
|
0 commit comments