Skip to content

Commit

Permalink
Add gtod part. Better overhead est. for GPTL_PAPI.
Browse files Browse the repository at this point in the history
Additional tests in overhead.c
  • Loading branch information
rosinski committed Jun 23, 2005
1 parent 94450c7 commit 61f2110
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 65 deletions.
19 changes: 14 additions & 5 deletions gptl.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct {

static Settings cpustats = {GPTLcpu, "Usr sys usr+sys ", false};
static Settings wallstats = {GPTLwall, "Wallclock max min ", true };
static Settings overheadstats = {GPTLoverhead, "Overhead ", true };
static Settings overheadstats = {GPTLoverhead, "Overhead gtod part " , true };

static const int tablesize = 128*MAX_CHARS; /* 128 is size of ASCII char set */
static Hashentry **hashtable; /* table of entries hashed by sum of chars */
Expand Down Expand Up @@ -242,7 +242,11 @@ int GPTLstart (const char *name) /* timer name */
if ((t = get_thread_num (&nthreads, &maxthreads)) < 0)
return GPTLerror ("GPTLstart\n");

/* 1st calls to overheadstart and gettimeofday are solely for overhead timing */
/*
** 1st calls to overheadstart and gettimeofday are solely for overhead timing
** Would prefer to start overhead calcs before get_thread_num, but the
** thread number is required by PAPI counters
*/

if (overheadstats.enabled) {
#ifdef HAVE_PAPI
Expand Down Expand Up @@ -789,6 +793,7 @@ static void printstats (const Timer *timer, /* timer to print */
float sys; /* system time */
float usrsys; /* usr + sys */
float elapse; /* elapsed time */
float gtodportion; /* timer overhead due to gettimeofday only */

if ((ticks_per_sec = sysconf (_SC_CLK_TCK)) == -1)
(void) GPTLerror ("printstats: token _SC_CLK_TCK is not defined\n");
Expand Down Expand Up @@ -828,16 +833,20 @@ static void printstats (const Timer *timer, /* timer to print */

/*
** Add cost of gettimeofday to overhead est. Factor of 2 is because both
** start and stop were called.
** start and stop were called. Second factor of 2 is because gettimeofday
** was called a total of 4 times for each start/stop pair.
*/

if (overheadstats.enabled) {
fprintf (fp, "%9.3f ", timer->wall.overhead + timer->count * 2 * gtodoverhead);
gtodportion = timer->count * 2 * gtodoverhead;
fprintf (fp, "%9.3f %9.3f ",
timer->wall.overhead + gtodportion,
2*gtodportion);
}
}

#ifdef HAVE_PAPI
GPTL_PAPIpr (fp, &timer->aux);
GPTL_PAPIpr (fp, &timer->aux, t, timer->count);
#endif

fprintf (fp, "\n");
Expand Down
46 changes: 37 additions & 9 deletions gptl_papi.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static char papiname[PAPI_MAX_STR_LEN]; /* returned from PAPI_event_code_to_nam
static const int BADCOUNT = -999999; /* Set counters to this when they are bad */
static int GPTLoverheadindx = -1; /* index into counters array */
static long_long *lastoverhead; /* needed because aux not available for overhead */
static long_long *readoverhead; /* overhead due solely to reading PAPI counters */

/* Function prototypes */

Expand Down Expand Up @@ -230,11 +231,13 @@ int GPTL_PAPIinitialize (const int maxthreads) /* number of threads */
EventSet = (int *) GPTLallocate (maxthreads * sizeof (int));
papicounters = (long_long **) GPTLallocate (maxthreads * sizeof (long_long *));
lastoverhead = (long_long *) GPTLallocate (maxthreads * sizeof (long_long));
readoverhead = (long_long *) GPTLallocate (maxthreads * sizeof (long_long));

for (t = 0; t < maxthreads; t++) {
EventSet[t] = PAPI_NULL;
papicounters[t] = (long_long *) GPTLallocate (MAX_AUX * sizeof (long_long));
lastoverhead[t] = -1;
readoverhead[t] = -1;
}

/*
Expand Down Expand Up @@ -304,19 +307,21 @@ static int create_and_start_events (const int t) /* thread number */
{
int ret;
int n;
long_long counters1[MAX_AUX]; /* Temp counter for estimating PAPI_read overhead */
long_long counters2[MAX_AUX]; /* Temp counter for estimating PAPI_read overhead */

/* Create the event set */

if ((ret = PAPI_create_eventset (&EventSet[t])) != PAPI_OK)
return GPTLerror ("GPTL_PAPIstart: failure creating eventset: %s\n",
return GPTLerror ("create_and_start_events: failure creating eventset: %s\n",
PAPI_strerror (ret));

/* Add requested events to the event set */

for (n = 0; n < nevents; n++) {
if ((ret = PAPI_add_event (EventSet[t], eventlist[n].counter)) != PAPI_OK) {
printf ("%s\n", PAPI_strerror (ret));
return GPTLerror ("GPTL_PAPIstart: failure adding event: %s\n",
return GPTLerror ("create_and_start_events: failure adding event: %s\n",
eventlist[n].str);
}
}
Expand All @@ -326,6 +331,19 @@ static int create_and_start_events (const int t) /* thread number */
if ((ret = PAPI_start (EventSet[t])) != PAPI_OK)
return GPTLerror ("%s\n", PAPI_strerror (ret));

/* Estimate overhead of calling PAPI_read, to be used later in printing */

if (GPTLoverheadindx > -1) {
if ((ret = PAPI_read (EventSet[t], counters1)) != PAPI_OK)
return GPTLerror ("create_and_start_events: %s\n", PAPI_strerror (ret));
if ((ret = PAPI_read (EventSet[t], counters1)) != PAPI_OK)
return GPTLerror ("create_and_start_events: %s\n", PAPI_strerror (ret));
if ((ret = PAPI_read (EventSet[t], counters2)) != PAPI_OK)
return GPTLerror ("create_and_start_events: %s\n", PAPI_strerror (ret));

readoverhead[t] = counters2[GPTLoverheadindx] - counters1[GPTLoverheadindx];
}

return 0;
}

Expand Down Expand Up @@ -497,8 +515,8 @@ void GPTL_PAPIprstr (FILE *fp) /* file descriptor */
for (n = 0; n < nevents; n++)
fprintf (fp, "%16s ", eventlist[n].prstr);

if (lastoverhead[0] > -1)
fprintf (fp, "Overhead (cycles)");
if (GPTLoverheadindx > -1)
fprintf (fp, "Overhead (cyc) PAPI_read part ");
}

/*
Expand All @@ -511,9 +529,13 @@ void GPTL_PAPIprstr (FILE *fp) /* file descriptor */
*/

void GPTL_PAPIpr (FILE *fp, /* file descriptor to write to */
const Papistats *aux) /* stats to write */
const Papistats *aux, /* stats to write */
const int t, /* thread number */
const int count) /* number of invocations */
{
int n;
long_long papireadportion; /* overhead due just to PAPI_read */
long_long overhead ; /* overhead including PAPI_read */

for (n = 0; n < nevents; n++) {
if (aux->accum[n] < 1000000)
Expand All @@ -522,13 +544,19 @@ void GPTL_PAPIpr (FILE *fp, /* file descriptor to write to */
fprintf (fp, "%16.10e ", (double) aux->accum[n]);
}

/* The check on lastoverhead > -1 determines whether it was ever set */
/* Print overhead estimate. The check on lastoverhead > -1 determines
** whether it was ever set. Note similarity of overhead calc. to
** gettimeofday calc. in gptl.c.
*/

if (lastoverhead[0] > -1)
if (GPTLoverheadindx > -1) {
papireadportion = count * 2 * readoverhead[t];
overhead = aux->accum_cycles + papireadportion;
if (aux->accum_cycles < 1000000)
fprintf (fp, "%16ld ", (long) aux->accum_cycles);
fprintf (fp, "%16ld %16ld ", (long) overhead, (long) (2*papireadportion));
else
fprintf (fp, "%16.10e ", (double) aux->accum_cycles);
fprintf (fp, "%16.10e %16.10e ", (double) overhead, (double) (2*papireadportion));
}
}

/*
Expand Down
6 changes: 3 additions & 3 deletions private.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
$Id: private.h,v 1.22 2005-06-15 05:52:25 rosinski Exp $
$Id: private.h,v 1.23 2005-06-23 07:18:29 rosinski Exp $
*/

#include <stdio.h>
Expand All @@ -16,7 +16,7 @@
#define STRMATCH(X,Y) (strcmp((X),(Y)) == 0)

/* longest timer name allowed (probably safe to just change) */
#define MAX_CHARS 15
#define MAX_CHARS 31

/* max allowable number of PAPI counters (though most machines allow fewer */
#define MAX_AUX 8
Expand Down Expand Up @@ -81,7 +81,7 @@ extern int GPTL_PAPIinitialize (const int);
extern int GPTL_PAPIstart (const int, Papistats *);
extern int GPTL_PAPIstop (const int, Papistats *);
extern void GPTL_PAPIprstr (FILE *);
extern void GPTL_PAPIpr (FILE *, const Papistats *);
extern void GPTL_PAPIpr (FILE *, const Papistats *, const int, const int);
extern void GPTL_PAPIadd (Papistats *, const Papistats *);
extern int GPTL_PAPIoverheadstart (const int);
extern int GPTL_PAPIoverheadstop (const int, Papistats *);
Expand Down
Loading

0 comments on commit 61f2110

Please sign in to comment.