Skip to content

Commit b4bd007

Browse files
committed
add ompi_spc_value_diff() SPC utility function
revise spc_diff utility fn, now returns converted microseconds instead of cycles, and resets any highwater events Signed-off-by: Thomas Naughton <[email protected]>
1 parent d724c7d commit b4bd007

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

ompi/runtime/ompi_spc.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,73 @@ static void ompi_spc_dump(void)
399399
ompi_spc_comm->c_coll->coll_barrier(ompi_spc_comm, ompi_spc_comm->c_coll->coll_barrier_module);
400400
}
401401

402+
403+
/*
404+
* Helper function for checking diff with given SPC.
405+
*
406+
* Given a specific SPC name and prior value, we
407+
* get the new value and return the difference between
408+
* the prior and new values (diff = new - prev).
409+
* If do not care about the diff you can pass NULL for spc_diff,
410+
* and will simply get the new_value.
411+
*
412+
* Note: The value for timer events are converted to microseconds.
413+
* Note: Any highwater events are reset after being read.
414+
*
415+
* On success, return MPI_SUCCESS, otherwise return -1.
416+
*/
417+
int ompi_spc_value_diff(char *spc_name,
418+
long long prev_value,
419+
long long *cur_value,
420+
long long *diff)
421+
{
422+
int i;
423+
long long value = -1;
424+
int found = 0;
425+
426+
if (NULL == ompi_spc_events) {
427+
//fprintf(stderr, " #-- DBG: WARN: SPC system not setup/available\n");
428+
return -1;
429+
}
430+
431+
/* Find the index of given SPC. */
432+
for(i = 0; i < OMPI_SPC_NUM_COUNTERS; i++) {
433+
434+
/* If this is our requested counter */
435+
if( 0 == strcmp(ompi_spc_events_desc[i].counter_name, spc_name) ) {
436+
437+
value = (long long)ompi_spc_events[i].value;
438+
439+
/* If this is a timer-based counter, convert from cycles to microseconds */
440+
if( ompi_spc_events[i].is_timer_event ) {
441+
value = ompi_spc_cycles_to_usecs_internal(value);
442+
}
443+
444+
/* If this is a high watermark counter, reset it after it has been read */
445+
if( ompi_spc_events[i].is_high_watermark) {
446+
ompi_spc_events[i].value = 0;
447+
}
448+
449+
found = 1;
450+
break;
451+
}
452+
}
453+
454+
if (found != 1) {
455+
fprintf(stderr, "Error: Failed to find SPC counter '%s'\n", spc_name);
456+
return -1;
457+
}
458+
459+
*cur_value = value;
460+
461+
if (NULL != diff) {
462+
*diff = value - prev_value;
463+
}
464+
465+
return MPI_SUCCESS;
466+
}
467+
468+
402469
/* Frees any dynamically allocated OMPI SPC data structures */
403470
void ompi_spc_fini(void)
404471
{

ompi/runtime/ompi_spc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ typedef struct ompi_spc_s{
183183
void ompi_spc_init(void);
184184
void ompi_spc_fini(void);
185185
void ompi_spc_cycles_to_usecs(opal_timer_t *cycles);
186+
int ompi_spc_value_diff(char *name, long long prev_value, long long *cur_value, long long *diff);
186187

187188
/* An array of event structures to store the event data value, attachments, flags)
188189
* The memory is statically allocated to reduce the number of loads required.
@@ -214,6 +215,8 @@ ompi_spc_t ompi_spc_events[OMPI_SPC_NUM_COUNTERS] __opal_attribute_aligned__(siz
214215
#define SPC_UPDATE_WATERMARK(watermark_enum, value_enum) \
215216
ompi_spc_update_watermark(watermark_enum, value_enum)
216217

218+
#define SPC_VALUE_DIFF(name, prev_value, cur_value, diff) \
219+
ompi_spc_value_diff(name, prev_value, *cur_value, diff)
217220

218221
/* Records an update to a counter using an atomic add operation. */
219222
static inline
@@ -313,6 +316,9 @@ void ompi_spc_timer_stop(unsigned int event_id, opal_timer_t *cycles)
313316
#define SPC_UPDATE_WATERMARK(watermark_enum, value_enum) \
314317
((void)0)
315318

319+
#define SPC_VALUE_DIFF(name, prev_value, cur_value, diff) \
320+
((void)0)
321+
316322
#endif
317323

318324
#endif

0 commit comments

Comments
 (0)