Skip to content

Commit

Permalink
Replace NUMERIC_TIMERS with sprintf from __cyg routines
Browse files Browse the repository at this point in the history
  • Loading branch information
rosinski committed Jan 1, 2007
1 parent 13876f3 commit 6659945
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 162 deletions.
18 changes: 1 addition & 17 deletions camwrappers.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: camwrappers.c,v 1.10 2006-12-31 23:52:20 rosinski Exp $
** $Id: camwrappers.c,v 1.11 2007-01-01 03:44:02 rosinski Exp $
**
** Fortran wrappers for timing library routines
*/
Expand Down Expand Up @@ -61,20 +61,6 @@ int t_stampf (double *wall, double *usr, double *sys)
return GPTLstamp (wall, usr, sys);
}

#ifdef NUMERIC_TIMERS

int t_startf (unsigned long tag)
{
return GPTLstart (tag);
}

int t_stopf (unsigned long tag)
{
return GPTLstop (tag);
}

#else

int t_startf (char *name, int nc1)
{
char cname[MAX_CHARS+1];
Expand All @@ -97,8 +83,6 @@ int t_stopf (char *name, int nc1)
return GPTLstop (cname);
}

#endif

int t_setoptionf (int *option, int *val)
{
return GPTLsetoption (*option, *val);
Expand Down
13 changes: 3 additions & 10 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ Optional Features:
--enable-debug Enable debugging
--enable-nanotime Replace gettimeofday with native IA32 or IA64
--enable-opt Optimize for speed
--enable-numeric Numeric rather than character timers ALSO adds __cyg_profile_func auto-instrumentation capability
--enable-openmp OpenMP threading (overrides pthreads)
--enable-pthreads pthreads threading
Expand Down Expand Up @@ -2139,7 +2138,7 @@ fi
# Provide some information about the compiler.
echo "$as_me:2142:" \
echo "$as_me:2141:" \
"checking for Fortran 77 compiler version" >&5
ac_compiler=`set X $ac_compile; echo $2`
{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version </dev/null >&5\"") >&5
Expand Down Expand Up @@ -2858,12 +2857,6 @@ if test "${enable_opt+set}" = set; then
CFLAGS="$CFLAGS -O3";FFLAGS="$FFLAGS -O"
fi;
# Check whether --enable-numeric or --disable-numeric was given.
if test "${enable_numeric+set}" = set; then
enableval="$enable_numeric"
CFLAGS="$CFLAGS -DNUMERIC_TIMERS"
fi;
if test "$F77" = xlf90 ; then
FFLAGS="$FFLAGS -qfixed"
fi
Expand Down Expand Up @@ -3452,7 +3445,7 @@ _ACEOF
# flags.
ac_save_FFLAGS=$FFLAGS
FFLAGS="$FFLAGS $ac_verb"
(eval echo $as_me:3455: \"$ac_link\") >&5
(eval echo $as_me:3448: \"$ac_link\") >&5
ac_f77_v_output=`eval $ac_link 5>&1 2>&1 | grep -v 'Driving:'`
echo "$ac_f77_v_output" >&5
FFLAGS=$ac_save_FFLAGS
Expand Down Expand Up @@ -3530,7 +3523,7 @@ _ACEOF
# flags.
ac_save_FFLAGS=$FFLAGS
FFLAGS="$FFLAGS $ac_cv_prog_f77_v"
(eval echo $as_me:3533: \"$ac_link\") >&5
(eval echo $as_me:3526: \"$ac_link\") >&5
ac_f77_v_output=`eval $ac_link 5>&1 2>&1 | grep -v 'Driving:'`
echo "$ac_f77_v_output" >&5
FFLAGS=$ac_save_FFLAGS
Expand Down
4 changes: 0 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ dnl Whether to enable optimization
AC_ARG_ENABLE(opt,[--enable-opt Optimize for speed],
[CFLAGS="$CFLAGS -O3";FFLAGS="$FFLAGS -O"],)

dnl Whether to use numeric rather than character timers
AC_ARG_ENABLE(numeric,[--enable-numeric Numeric rather than character timers ALSO adds __cyg_profile_func auto-instrumentation capability],
[CFLAGS="$CFLAGS -DNUMERIC_TIMERS"],)

dnl need to add -qfixed to FFLAGS for Fortran tests on AIX
if test "$F77" = xlf90 ; then
FFLAGS="$FFLAGS -qfixed"
Expand Down
18 changes: 1 addition & 17 deletions f_wrappers.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: f_wrappers.c,v 1.15 2006-12-31 23:52:20 rosinski Exp $
** $Id: f_wrappers.c,v 1.16 2007-01-01 03:44:02 rosinski Exp $
**
** Fortran wrappers for timing library routines
*/
Expand Down Expand Up @@ -90,20 +90,6 @@ int gptlstamp (double *wall, double *usr, double *sys)
return GPTLstamp (wall, usr, sys);
}

#ifdef NUMERIC_TIMERS

int gptlstart (unsigned long tag)
{
return GPTLstart (tag);
}

int gptlstop (unsigned long tag)
{
return GPTLstop (tag);
}

#else

int gptlstart (char *name, int nc1)
{
char cname[MAX_CHARS+1];
Expand All @@ -126,8 +112,6 @@ int gptlstop (char *name, int nc1)
return GPTLstop (cname);
}

#endif

int gptlsetoption (int *option, int *val)
{
return GPTLsetoption (*option, *val);
Expand Down
124 changes: 20 additions & 104 deletions gptl.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ static int init_mpiwtime (void);
static int init_clock_gettime (void);
static int init_gettimeofday (void);

static double utr_getoverhead (void);
static inline Timer *getentry (const Hashentry *, const char *, int *);

typedef struct {
const Funcoption option;
double (*func)(void);
Expand Down Expand Up @@ -113,15 +116,7 @@ static float get_clockfreq (void); /* cycles/sec */
static double ticks2sec = -1; /* init to bad value */
#endif

static double utr_getoverhead (void);

#ifdef NUMERIC_TIMERS
static const int tablesize = 16*16*16; /* 3 hex digits of input name */
static inline Timer *getentry (const Hashentry *, const unsigned long, int *);
#else
static const int tablesize = 128*MAX_CHARS; /* 128 is size of ASCII char set */
static inline Timer *getentry (const Hashentry *, const char *, int *);
#endif

/*
** GPTLsetoption: set option value to true or false.
Expand Down Expand Up @@ -254,17 +249,16 @@ int GPTLinitialize (void)
return GPTLerror ("GPTLinitialize: GPTL_PAPIinitialize failure\n");
#endif

#ifdef NUMERIC_TIMERS
/*
** start/stop routines sprintf an "unsigned long" into a string for later
** printing. The size of that string is MAX_CHARS (excluding null terminator).
** The following ensures that this size is sufficient.
** The following checks that this size is sufficient.
** A single byte can hold 2 hex digits.
*/

if (2*sizeof (long) > MAX_CHARS)
return GPTLerror ("GPTLinitialize: MAX_CHARS is too small\n");
#endif
if (2*sizeof (void *) > MAX_CHARS) {
printf ("GPTLinitialize: NOTE: MAX_CHARS may be too small for automatic profiling");
}

/*
** Call init routine for underlying timing routine (actually only required if
Expand Down Expand Up @@ -333,17 +327,12 @@ int GPTLfinalize (void)
** GPTLstart: start a timer
**
** Input arguments:
** name: timer name OR
** tag: number (e.g. maybe an address)
** name: timer name
**
** Return value: 0 (success) or GPTLerror (failure)
*/

#ifdef NUMERIC_TIMERS
inline int GPTLstart (const unsigned long tag) /* timer tag */
#else
int GPTLstart (const char *name) /* timer name */
#endif
{
double tp2; /* time stamp */
Timer *ptr; /* linked list pointer */
Expand Down Expand Up @@ -371,10 +360,6 @@ int GPTLstart (const char *name) /* timer name */
if ((t = get_thread_num (&nthreads, &maxthreads)) < 0)
return GPTLerror ("GPTLstart\n");

#ifdef NUMERIC_TIMERS
ptr = getentry (hashtable[t], tag, &indx);
#else

/* Truncate input name if longer than MAX_CHARS characters */

nchars = MIN (strlen (name), MAX_CHARS);
Expand All @@ -387,7 +372,6 @@ int GPTLstart (const char *name) /* timer name */
*/

ptr = getentry (hashtable[t], locname, &indx);
#endif

if (indx >= tablesize)
return GPTLerror ("GPTLstart: indx=%d must be < tablesize=%d\n", indx, tablesize);
Expand Down Expand Up @@ -425,18 +409,6 @@ int GPTLstart (const char *name) /* timer name */
ptr = (Timer *) GPTLallocate (sizeof (Timer));
memset (ptr, 0, sizeof (Timer));

#ifdef NUMERIC_TIMERS

/*
** Convert tag to a string for printing.
** nchars is guaranteed to be <= MAX_CHARS
*/

sprintf (locname, "%lx", tag);
nchars = strlen (locname);
ptr->tag = tag;
#endif

if (nchars > max_name_len[t])
max_name_len[t] = nchars;

Expand Down Expand Up @@ -484,17 +456,12 @@ int GPTLstart (const char *name) /* timer name */
** GPTLstop: stop a timer
**
** Input arguments:
** name: timer name OR
** tag: number (e.g. maybe an address)
** name: timer name
**
** Return value: 0 (success) or -1 (failure)
*/

#ifdef NUMERIC_TIMERS
inline int GPTLstop (const unsigned long tag) /* timer tag */
#else
int GPTLstop (const char *name) /* timer name */
#endif
{
double tp1; /* time stamp */
double delta; /* diff between 2 time stamps */
Expand Down Expand Up @@ -533,19 +500,13 @@ int GPTLstop (const char *name) /* timer name */
if ((t = get_thread_num (&nthreads, &maxthreads)) < 0)
return GPTLerror ("GPTLstop\n");

#ifdef NUMERIC_TIMERS
ptr = getentry (hashtable[t], tag, &indx);
if ( ! ptr)
return GPTLerror ("GPTLstop: timer for %lx had not been started.\n", tag);
#else
nchars = MIN (strlen (name), MAX_CHARS);
strncpy (locname, name, nchars);
locname[nchars] = '\0';

ptr = getentry (hashtable[t], locname, &indx);
if ( ! ptr)
return GPTLerror ("GPTLstop: timer for %s had not been started.\n", locname);
#endif

if ( ! ptr->onflg )
return GPTLerror ("GPTLstop: timer %s was already off.\n",ptr->name);
Expand Down Expand Up @@ -1042,54 +1003,6 @@ static inline int get_cpustamp (long *usr, long *sys)
#endif
}

#ifdef NUMERIC_TIMERS
/*
** getentry: find the entry in the hash table and return a pointer to it.
**
** Input args:
** hashtable: the hashtable (array)
** tag: value to be hashed on (keep only 3 hex digits)
** Output args:
** indx: hashtable index
**
** Return value: pointer to the entry, or NULL if not found
*/

static inline Timer *getentry (const Hashentry *hashtable, /* hash table */
const unsigned long tag, /* value to hash */
int *indx) /* hash index */
{
int i; /* loop index */
Timer *retval = 0; /* value to be returned */

/*
** Hash value is 3 hex digits. Shift off the trailing 2 (or 3) bits
** because "tag" is likely to be an address, which means a multiple
** of 4 on 32-bit addressable machines, and 8 on 64-bit.
*/

#ifdef BIT64
*indx = (tag >> 3) & 0xFFF;
#else
*indx = (tag >> 2) & 0xFFF;
#endif

/*
** If nument exceeds 1 there was a hash collision and we must search
** linearly through an array for a match
*/

for (i = 0; i < hashtable[*indx].nument; i++) {
if (tag == hashtable[*indx].entries[i]->tag) {
retval = hashtable[*indx].entries[i];
break;
}
}
return retval;
}

#else

/*
** getentry: find the entry in the hash table and return a pointer to it.
**
Expand Down Expand Up @@ -1125,7 +1038,6 @@ static inline Timer *getentry (const Hashentry *hashtable, /* hash table */

return 0;
}
#endif

/*
** These routines were moved from threadutil.c to here only to allow inlining.
Expand Down Expand Up @@ -1166,32 +1078,36 @@ static inline int get_thread_num (int *nthreads, int *maxthreads)

/*
** Add entry points for when -finstrument-functions was set on gcc compile
** line. Currently only usable when GPTL compiled with NUMERIC_TIMERS
** defined. Could do an sprintf of "this_fn" to a char var though when
** NUMERIC_TIMERS unset. This way is much more efficient.
** line.
*/

#ifdef NUMERIC_TIMERS
#ifdef __cplusplus
extern "C" {
#endif

void __cyg_profile_func_enter (void *this_fn,
void *call_site)
{
GPTLstart ((unsigned long) this_fn);
/* 64 is big enough to hold a 128-bit address */

char locname[64+1];
sprintf (locname, "%lx", this_fn);
(void) GPTLstart (locname);
}

void __cyg_profile_func_exit (void *this_fn,
void *call_site)
{
GPTLstop ((unsigned long) this_fn);
/* 64 is big enough to hold a 128-bit address */

char locname[64+1];
sprintf (locname, "%lx", this_fn);
(void) GPTLstop (locname);
}

#ifdef __cplusplus
};
#endif
#endif

#ifdef HAVE_NANOTIME
#ifdef BIT64
Expand Down
Loading

0 comments on commit 6659945

Please sign in to comment.