Skip to content

Commit

Permalink
Introduce additional statistics layer
Browse files Browse the repository at this point in the history
Introduce a new "mt" (Multi-Threaded) layer for statistics to abstract
multi-threaded isolation logic from the upper layers as well as from the
single-threaded statistics collection.

NOTE: this commit only introduces the layer and internally a 1-to-1
bypass to a single-threaded layer is performed.

Signed-off-by: Artem Polyakov <[email protected]>
  • Loading branch information
artpol84 committed Aug 29, 2019
1 parent 1627159 commit 3c03eca
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 36 deletions.
2 changes: 2 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ PC_LOOKUP_OBJ = $(PC_LOOKUP_FILE:.c=.o)
SRCS = diag_msgs.c \
mpiP-hash.c \
mpiP-stats.c \
mpiP-mt-stats.c \
mpiP-tslist.c \
glob.c \
wrappers.c \
Expand All @@ -52,6 +53,7 @@ SRCS = diag_msgs.c \
API_SRCS = diag_msgs_api.c \
mpiP-hash.c \
mpiP-stats.c \
mpiP-mt-stats.c \
glob.c \
mpiPi.c \
util.c \
Expand Down
8 changes: 4 additions & 4 deletions make-wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ def CreateWrapper(funct, olist):
olist.append("\n{\n")
olist.append( " int rc, enabledState;\n double dur;\n int tsize;\n double messSize = 0.;\n double ioSize = 0.;\n double rmaSize =0.;\n mpiPi_TIME start, end;\n void *call_stack[MPIP_CALLSITE_STACK_DEPTH_MAX] = { NULL };\n" )

olist.append("\nif (mpiPi_stats_thr_is_on(&mpiPi.task_stats)) {\n")
olist.append("\nif (mpiPi_stats_mt_is_on(&mpiPi.task_stats)) {\n")
if fdict[funct].wrapperPreList:
olist.extend(fdict[funct].wrapperPreList)

Expand All @@ -1067,7 +1067,7 @@ def CreateWrapper(funct, olist):
olist.append("}\n\n")

# Mark that we have already entered Profiler to avoid nested invocations
olist.append("mpiPi_stats_thr_enter(&mpiPi.task_stats);\n")
olist.append("mpiPi_stats_mt_enter(&mpiPi.task_stats);\n")

# call PMPI
olist.append("\nrc = P" + funct + "( " )
Expand All @@ -1088,8 +1088,8 @@ def CreateWrapper(funct, olist):
olist.append(");\n\n")

# Mark that we exited Profiler
olist.append("mpiPi_stats_thr_exit(&mpiPi.task_stats);\n")
olist.append("if (mpiPi_stats_thr_is_on(&mpiPi.task_stats)) {\n")
olist.append("mpiPi_stats_mt_exit(&mpiPi.task_stats);\n")
olist.append("if (mpiPi_stats_mt_is_on(&mpiPi.task_stats)) {\n")
olist.append("\n"
+ "mpiPi_GETTIME (&end);\n"
+ "dur = mpiPi_GETTIMEDIFF (&end, &start);\n")
Expand Down
98 changes: 98 additions & 0 deletions mpiP-mt-stats.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include "mpiP-stats.h"
#include "mpiP-mt-stats.h"

int mpiPi_stats_mt_init(mpiPi_mt_stat_t *stat)
{
mpiPi_stats_thr_init(&stat->st_stat);
}
void mpiPi_stats_mt_fini(mpiPi_mt_stat_t *stat)
{
mpiPi_stats_thr_fini(&stat->st_stat);
}

void mpiPi_stats_mt_cs_gather(mpiPi_mt_stat_t *stat,
int *ac, callsite_stats_t ***av )
{
mpiPi_stats_thr_cs_gather(&stat->st_stat, ac, av);
}

void mpiPi_stats_mt_cs_upd (mpiPi_mt_stat_t *stat,
unsigned op, unsigned rank, void **pc,
double dur, double sendSize, double ioSize,
double rmaSize)
{
mpiPi_stats_thr_cs_upd(&stat->st_stat,
op, rank, pc, dur,
sendSize, ioSize, rmaSize);
}

void mpiPi_stats_mt_cs_lookup(mpiPi_mt_stat_t *stat,
callsite_stats_t *task_stats,
callsite_stats_t **task_lookup,
callsite_stats_t *dummy_buf,
int initMax)
{
mpiPi_stats_thr_cs_lookup(&stat->st_stat, task_stats, task_lookup,
dummy_buf, initMax);
}

void mpiPi_stats_mt_coll_upd(mpiPi_mt_stat_t *stat,
int op, double dur, double size,
MPI_Comm * comm)
{
mpiPi_stats_thr_coll_upd(&stat->st_stat, op, dur, size, comm);
}

void mpiPi_stats_mt_coll_gather(mpiPi_mt_stat_t *stat, double **_outbuf)
{
mpiPi_stats_thr_coll_gather(&stat->st_stat, _outbuf);
}

void mpiPi_stats_mt_cs_reset(mpiPi_mt_stat_t *stat)
{
mpiPi_stats_thr_cs_reset(&stat->st_stat);
}

void mpiPi_stats_mt_coll_binstrings(mpiPi_mt_stat_t *stat,
int comm_idx, char *comm_buf,
int size_idx, char *size_buf)
{
mpiPi_stats_thr_coll_binstrings(&stat->st_stat,
comm_idx, comm_buf,
size_idx, size_buf);
}

void mpiPi_stats_mt_pt2pt_upd (mpiPi_mt_stat_t *stat,
int op, double dur, double size,
MPI_Comm * comm)
{
mpiPi_stats_thr_pt2pt_upd(&stat->st_stat, op, dur, size, comm);
}

void mpiPi_stats_mt_pt2pt_gather(mpiPi_mt_stat_t *stat, double **_outbuf)
{
mpiPi_stats_thr_pt2pt_gather(&stat->st_stat, _outbuf);
}

void mpiPi_stats_mt_pt2pt_binstrings(mpiPi_mt_stat_t *stat,
int comm_idx, char *comm_buf,
int size_idx, char *size_buf)
{
mpiPi_stats_thr_pt2pt_binstrings(&stat->st_stat, comm_idx, comm_buf,
size_idx, size_buf);
}

int mpiPi_stats_mt_exit(mpiPi_mt_stat_t *stat)
{
mpiPi_stats_thr_exit(&stat->st_stat);
}

int mpiPi_stats_mt_enter(mpiPi_mt_stat_t *stat)
{
mpiPi_stats_thr_enter(&stat->st_stat);
}

int mpiPi_stats_mt_is_on(mpiPi_mt_stat_t *stat)
{
mpiPi_stats_thr_is_on(&stat->st_stat);
}
118 changes: 118 additions & 0 deletions mpiP-mt-stats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#ifndef MPIPMTSTATS_H
#define MPIPMTSTATS_H

#include "mpiP-stats.h"

/* Per-thread MPI status */
typedef struct {
union {
mpiPi_thread_stat_t st_stat;
};
} mpiPi_mt_stat_t;

int mpiPi_stats_mt_init(mpiPi_mt_stat_t *stat);
void mpiPi_stats_mt_fini(mpiPi_mt_stat_t *stat);
void mpiPi_stats_mt_cs_gather(mpiPi_mt_stat_t *stat,
int *ac, callsite_stats_t ***av );
void mpiPi_stats_mt_cs_upd (mpiPi_mt_stat_t *stat,
unsigned op, unsigned rank, void **pc,
double dur, double sendSize, double ioSize,
double rmaSize);
#define MPIPI_CALLSITE_MIN2MAX 1
#define MPIPI_CALLSITE_MIN2ZERO 0
void mpiPi_stats_mt_cs_lookup(mpiPi_mt_stat_t *stat,
callsite_stats_t *task_stats,
callsite_stats_t **task_lookup,
callsite_stats_t *dummy_buf,
int initMax);

void mpiPi_stats_mt_coll_upd(mpiPi_mt_stat_t *stat,
int op, double dur, double size,
MPI_Comm * comm);
void mpiPi_stats_mt_coll_gather(mpiPi_mt_stat_t *stat, double **_outbuf);
void mpiPi_stats_mt_cs_reset(mpiPi_mt_stat_t *stat);
void mpiPi_stats_mt_coll_binstrings(mpiPi_mt_stat_t *stat,
int comm_idx, char *comm_buf,
int size_idx, char *size_buf);

void mpiPi_stats_mt_pt2pt_upd (mpiPi_mt_stat_t *stat,
int op, double dur, double size,
MPI_Comm * comm);
void mpiPi_stats_mt_pt2pt_gather(mpiPi_mt_stat_t *stat, double **_outbuf);
void mpiPi_stats_mt_pt2pt_binstrings(mpiPi_mt_stat_t *stat,
int comm_idx, char *comm_buf,
int size_idx, char *size_buf);

int mpiPi_stats_mt_exit(mpiPi_mt_stat_t *stat);
int mpiPi_stats_mt_enter(mpiPi_mt_stat_t *stat);
int mpiPi_stats_mt_is_on(mpiPi_mt_stat_t *stat);

#endif // MPIPMTSTATS_H

/*
<license>
Copyright (c) 2019, Mellanox Technologies Inc.
Written by Artem Polyakov
All rights reserved.
This file is part of mpiP. For details, see http://llnl.github.io/mpiP.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the disclaimer below.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the disclaimer (as noted below) in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the UC/LLNL nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF
THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Additional BSD Notice
1. This notice is required to be provided under our contract with the
U.S. Department of Energy (DOE). This work was produced at the
University of California, Lawrence Livermore National Laboratory under
Contract No. W-7405-ENG-48 with the DOE.
2. Neither the United States Government nor the University of
California nor any of their employees, makes any warranty, express or
implied, or assumes any liability or responsibility for the accuracy,
completeness, or usefulness of any information, apparatus, product, or
process disclosed, or represents that its use would not infringe
privately-owned rights.
3. Also, reference herein to any specific commercial products,
process, or services by trade name, trademark, manufacturer or
otherwise does not necessarily constitute or imply its endorsement,
recommendation, or favoring by the United States Government or the
University of California. The views and opinions of authors expressed
herein do not necessarily state or reflect those of the United States
Government or the University of California, and shall not be used for
advertising or product endorsement purposes.
</license>
*/
2 changes: 1 addition & 1 deletion mpiP-stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void mpiPi_stats_thr_cs_lookup(mpiPi_thread_stat_t *stat,
callsite_stats_t *dummy_buf,
int initMax);

void mpiPi_stats_thr_coll_upd (mpiPi_thread_stat_t *stat,
void mpiPi_stats_thr_coll_upd(mpiPi_thread_stat_t *stat,
int op, double dur, double size,
MPI_Comm * comm);
void mpiPi_stats_thr_coll_gather(mpiPi_thread_stat_t *stat, double **_outbuf);
Expand Down
Empty file removed mpiP-threads.c
Empty file.
9 changes: 0 additions & 9 deletions mpiP-threads.h

This file was deleted.

18 changes: 9 additions & 9 deletions mpiPi.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ mpiPi_init (char *appName)
#endif
mpiPi_getenv ();

mpiPi_stats_thr_init(&mpiPi.task_stats);
mpiPi_stats_mt_init(&mpiPi.task_stats);

/* -- welcome msg only collector */
if (mpiPi.collectorRank == mpiPi.rank)
Expand Down Expand Up @@ -619,7 +619,7 @@ mpiPi_mergeResults ()
callsite_stats_t *rawCallsiteData = NULL;

/* gather local task data */
mpiPi_stats_thr_cs_gather(&mpiPi.task_stats, &ac, &av);
mpiPi_stats_mt_cs_gather(&mpiPi.task_stats, &ac, &av);

/* determine size of space necessary on collector */
PMPI_Allreduce (&ac, &totalCount, 1, MPI_INT, MPI_SUM, mpiPi.comm);
Expand Down Expand Up @@ -793,7 +793,7 @@ mpiPi_mergeCollectiveStats ()
coll_time_results = (double *) malloc (sizeof(mpiPi.coll_time_stats));
}

mpiPi_stats_thr_coll_gather(&mpiPi.task_stats, &coll_time_local);
mpiPi_stats_mt_coll_gather(&mpiPi.task_stats, &coll_time_local);

/* Collect Collective statistic data were used */
size = sizeof(mpiPi.pt2pt_send_stats) / sizeof(double);
Expand Down Expand Up @@ -828,7 +828,7 @@ mpiPi_mergept2ptStats ()
if (mpiPi.collectorRank == mpiPi.rank){
pt2pt_send_results = (double *) malloc (sizeof(mpiPi.pt2pt_send_stats));
}
mpiPi_stats_thr_pt2pt_gather(&mpiPi.task_stats, &pt2pt_send_local);
mpiPi_stats_mt_pt2pt_gather(&mpiPi.task_stats, &pt2pt_send_local);

/* Collect Collective statistic data were used */
size = sizeof(mpiPi.pt2pt_send_stats) / sizeof(double);
Expand Down Expand Up @@ -1050,7 +1050,7 @@ mpiPi_finalize ()
if (mpiPi.disable_finalize_report == 0)
mpiPi_generateReport (mpiPi.report_style);

mpiPi_stats_thr_fini(&mpiPi.task_stats);
mpiPi_stats_mt_fini(&mpiPi.task_stats);

if (mpiPi.global_task_app_time != NULL)
free (mpiPi.global_task_app_time);
Expand Down Expand Up @@ -1085,24 +1085,24 @@ mpiPi_update_callsite_stats (unsigned op, unsigned rank, void **pc,
callsite_stats_t *csp = NULL;
callsite_stats_t key;

if (!mpiPi_stats_thr_is_on(&mpiPi.task_stats))
if (!mpiPi_stats_mt_is_on(&mpiPi.task_stats))
return;

mpiPi_stats_thr_cs_upd(&mpiPi.task_stats, op, rank, pc, dur,
mpiPi_stats_mt_cs_upd(&mpiPi.task_stats, op, rank, pc, dur,
sendSize, ioSize, rmaSize);
}

void
mpiPi_update_collective_stats (int op, double dur, double size,
MPI_Comm * comm)
{
mpiPi_stats_thr_coll_upd(&mpiPi.task_stats, op, dur, size, comm);
mpiPi_stats_mt_coll_upd(&mpiPi.task_stats, op, dur, size, comm);
}

void
mpiPi_update_pt2pt_stats (int op, double dur, double size, MPI_Comm * comm)
{
mpiPi_stats_thr_pt2pt_upd(&mpiPi.task_stats, op, dur, size, comm);
mpiPi_stats_mt_pt2pt_upd(&mpiPi.task_stats, op, dur, size, comm);
}

#endif /* } ifndef ENABLE_API_ONLY */
Expand Down
4 changes: 2 additions & 2 deletions mpiPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#endif

#include "mpiP-hash.h"
#include "mpiP-stats.h"
#include "mpiP-mt-stats.h"

#include "mpip_timers.h"

Expand Down Expand Up @@ -171,7 +171,7 @@ typedef struct _mpiPi_t
h_t *global_callsite_stats_agg;
h_t *global_MPI_stats_agg;

mpiPi_thread_stat_t task_stats;
mpiPi_mt_stat_t task_stats;

mpiPi_lookup_t *lookup;

Expand Down
2 changes: 1 addition & 1 deletion pcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static char *svnid = "$Id$";
void
mpiPi_reset_callsite_data ()
{
mpiPi_stats_thr_cs_reset(&mpiPi.task_stats);
mpiPi_stats_mt_cs_reset(&mpiPi.task_stats);

if (time (&mpiPi.start_timeofday) == (time_t) - 1)
{
Expand Down
Loading

0 comments on commit 3c03eca

Please sign in to comment.