Skip to content

Commit eed770c

Browse files
committed
Fix the SPC initialization.
Use the PVAR ctx to save the SPC index, so that no lookup nor restriction on the SPC vars position is imposed. Make sure the PVAR are always registered. Signed-off-by: George Bosilca <bosilca@icl.utk.edu>
1 parent 7dab8c0 commit eed770c

File tree

1 file changed

+30
-44
lines changed

1 file changed

+30
-44
lines changed

ompi/runtime/ompi_spc.c

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*
2-
* Copyright (c) 2018 The University of Tennessee and The University
2+
* Copyright (c) 2018-2019 The University of Tennessee and The University
33
* of Tennessee Research Foundation. All rights
44
* reserved.
55
*
66
* Copyright (c) 2018 Cisco Systems, Inc. All rights reserved
77
* Copyright (c) 2018 Research Organization for Information Science
88
* and Technology (RIST). All rights reserved.
9+
* Copyright (c) 2019 Mellanox Technologies, Inc.
10+
* All rights reserved.
911
* $COPYRIGHT$
1012
*
1113
* Additional copyrights may follow
@@ -20,10 +22,8 @@ opal_timer_t sys_clock_freq_mhz = 0;
2022
static void ompi_spc_dump(void);
2123

2224
/* Array for converting from SPC indices to MPI_T indices */
23-
OMPI_DECLSPEC int mpi_t_offset = -1;
24-
OMPI_DECLSPEC bool mpi_t_enabled = false;
25-
26-
OPAL_DECLSPEC ompi_communicator_t *ompi_spc_comm = NULL;
25+
static bool mpi_t_enabled = false;
26+
static ompi_communicator_t *ompi_spc_comm = NULL;
2727

2828
typedef struct ompi_spc_event_t {
2929
const char* counter_name;
@@ -185,6 +185,8 @@ static int ompi_spc_notify(mca_base_pvar_t *pvar, mca_base_pvar_event_t event, v
185185
return MPI_SUCCESS;
186186
}
187187

188+
index = (int)(uintptr_t)pvar->ctx; /* Convert from MPI_T pvar index to SPC index */
189+
188190
/* For this event, we need to set count to the number of long long type
189191
* values for this counter. All SPC counters are one long long, so we
190192
* always set count to 1.
@@ -194,14 +196,10 @@ static int ompi_spc_notify(mca_base_pvar_t *pvar, mca_base_pvar_event_t event, v
194196
}
195197
/* For this event, we need to turn on the counter */
196198
else if(MCA_BASE_PVAR_HANDLE_START == event) {
197-
/* Convert from MPI_T pvar index to SPC index */
198-
index = pvar->pvar_index - mpi_t_offset;
199199
SET_SPC_BIT(ompi_spc_attached_event, index);
200200
}
201201
/* For this event, we need to turn off the counter */
202202
else if(MCA_BASE_PVAR_HANDLE_STOP == event) {
203-
/* Convert from MPI_T pvar index to SPC index */
204-
index = pvar->pvar_index - mpi_t_offset;
205203
CLEAR_SPC_BIT(ompi_spc_attached_event, index);
206204
}
207205

@@ -231,7 +229,7 @@ static int ompi_spc_get_count(const struct mca_base_pvar_t *pvar, void *value, v
231229
}
232230

233231
/* Convert from MPI_T pvar index to SPC index */
234-
int index = pvar->pvar_index - mpi_t_offset;
232+
int index = (int)(uintptr_t)pvar->ctx;
235233
/* Set the counter value to the current SPC value */
236234
*counter_value = (long long)ompi_spc_events[index].value;
237235
/* If this is a timer-based counter, convert from cycles to microseconds */
@@ -287,14 +285,6 @@ void ompi_spc_init(void)
287285
char **arg_strings = opal_argv_split(ompi_mpi_spc_attach_string, ',');
288286
int num_args = opal_argv_count(arg_strings);
289287

290-
/* Reset all timer-based counters */
291-
for(i = 0; i < OMPI_SPC_NUM_COUNTERS; i++) {
292-
CLEAR_SPC_BIT(ompi_spc_timer_event, i);
293-
}
294-
295-
/* If this is a timer event, set the corresponding timer_event entry */
296-
SET_SPC_BIT(ompi_spc_timer_event, OMPI_SPC_MATCH_TIME);
297-
298288
/* If there is only one argument and it is 'all', then all counters
299289
* should be turned on. If the size is 0, then no counters will be enabled.
300290
*/
@@ -304,47 +294,43 @@ void ompi_spc_init(void)
304294
}
305295
}
306296

307-
/* Turn on only the counters that were specified in the MCA parameter */
308297
for(i = 0; i < OMPI_SPC_NUM_COUNTERS; i++) {
309-
if(all_on) {
310-
found++;
311-
} else {
312-
matched = 0;
313-
/* Note: If no arguments were given, this will be skipped */
298+
/* Reset all timer-based counters */
299+
CLEAR_SPC_BIT(ompi_spc_timer_event, i);
300+
matched = all_on;
301+
302+
if( !matched ) {
303+
/* Turn on only the counters that were specified in the MCA parameter */
314304
for(j = 0; j < num_args; j++) {
315305
if( 0 == strcmp(ompi_spc_events_names[i].counter_name, arg_strings[j]) ) {
316-
found++;
317306
matched = 1;
318307
break;
319308
}
320309
}
321310
}
322311

323-
if (all_on || matched) {
312+
if (matched) {
324313
SET_SPC_BIT(ompi_spc_attached_event, i);
325314
mpi_t_enabled = true;
315+
found++;
316+
}
326317

327-
/* Registers the current counter as an MPI_T pvar regardless of whether it's been turned on or not */
328-
ret = mca_base_pvar_register("ompi", "runtime", "spc", ompi_spc_events_names[i].counter_name, ompi_spc_events_names[i].counter_description,
329-
OPAL_INFO_LVL_4, MPI_T_PVAR_CLASS_SIZE,
330-
MCA_BASE_VAR_TYPE_UNSIGNED_LONG_LONG, NULL, MPI_T_BIND_NO_OBJECT,
331-
MCA_BASE_PVAR_FLAG_READONLY | MCA_BASE_PVAR_FLAG_CONTINUOUS,
332-
ompi_spc_get_count, NULL, ompi_spc_notify, NULL);
333-
334-
/* Check to make sure that ret is a valid index and not an error code */
335-
if( ret >= 0 ) {
336-
if( mpi_t_offset == -1 ) {
337-
mpi_t_offset = ret;
338-
}
339-
}
340-
if( (ret < 0) || (ret != (mpi_t_offset + found - 1)) ) {
341-
mpi_t_enabled = false;
342-
opal_show_help("help-mpi-runtime.txt", "spc: MPI_T disabled", true);
343-
break;
344-
}
318+
/* Registers the current counter as an MPI_T pvar regardless of whether it's been turned on or not */
319+
ret = mca_base_pvar_register("ompi", "runtime", "spc", ompi_spc_events_names[i].counter_name, ompi_spc_events_names[i].counter_description,
320+
OPAL_INFO_LVL_4, MPI_T_PVAR_CLASS_SIZE,
321+
MCA_BASE_VAR_TYPE_UNSIGNED_LONG_LONG, NULL, MPI_T_BIND_NO_OBJECT,
322+
MCA_BASE_PVAR_FLAG_READONLY | MCA_BASE_PVAR_FLAG_CONTINUOUS,
323+
ompi_spc_get_count, NULL, ompi_spc_notify, (void*)(uintptr_t)i);
324+
if( ret < 0 ) {
325+
mpi_t_enabled = false;
326+
opal_show_help("help-mpi-runtime.txt", "spc: MPI_T disabled", true);
327+
break;
345328
}
346329
}
347330

331+
/* If this is a timer event, set the corresponding timer_event entry */
332+
SET_SPC_BIT(ompi_spc_timer_event, OMPI_SPC_MATCH_TIME);
333+
348334
opal_argv_free(arg_strings);
349335
}
350336

0 commit comments

Comments
 (0)