From 66599452e727c8f60d659ce327385e7353e13a81 Mon Sep 17 00:00:00 2001 From: rosinski Date: Mon, 1 Jan 2007 03:44:02 +0000 Subject: [PATCH] Replace NUMERIC_TIMERS with sprintf from __cyg routines --- camwrappers.c | 18 +------- configure | 13 ++---- configure.ac | 4 -- f_wrappers.c | 18 +------- gptl.c | 124 ++++++++------------------------------------------ gptl.h | 9 +--- private.h | 3 +- 7 files changed, 27 insertions(+), 162 deletions(-) diff --git a/camwrappers.c b/camwrappers.c index 00ed07f4..7573e2be 100644 --- a/camwrappers.c +++ b/camwrappers.c @@ -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 */ @@ -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]; @@ -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); diff --git a/configure b/configure index 9c5bd43c..cdb09224 100755 --- a/configure +++ b/configure @@ -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 @@ -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 &5\"") >&5 @@ -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 @@ -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 @@ -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 diff --git a/configure.ac b/configure.ac index 436e1fff..2dc615ba 100644 --- a/configure.ac +++ b/configure.ac @@ -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" diff --git a/f_wrappers.c b/f_wrappers.c index 00831a89..6bffb5de 100644 --- a/f_wrappers.c +++ b/f_wrappers.c @@ -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 */ @@ -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]; @@ -126,8 +112,6 @@ int gptlstop (char *name, int nc1) return GPTLstop (cname); } -#endif - int gptlsetoption (int *option, int *val) { return GPTLsetoption (*option, *val); diff --git a/gptl.c b/gptl.c index d92ef325..e7ebaa70 100644 --- a/gptl.c +++ b/gptl.c @@ -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); @@ -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. @@ -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 @@ -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 */ @@ -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); @@ -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); @@ -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; @@ -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 */ @@ -533,11 +500,6 @@ 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'; @@ -545,7 +507,6 @@ int GPTLstop (const char *name) /* timer name */ 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); @@ -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. ** @@ -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. @@ -1166,12 +1078,9 @@ 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 @@ -1179,19 +1088,26 @@ extern "C" { 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 diff --git a/gptl.h b/gptl.h index 9171af30..c2d68f34 100644 --- a/gptl.h +++ b/gptl.h @@ -1,5 +1,5 @@ /* -$Id: gptl.h,v 1.12 2006-12-31 23:52:20 rosinski Exp $ +$Id: gptl.h,v 1.13 2007-01-01 03:44:02 rosinski Exp $ */ #ifndef GPTL_H #define GPTL_H @@ -24,15 +24,8 @@ typedef enum { extern int GPTLsetoption (const int, const int); extern int GPTLinitialize (void); - -#ifdef NUMERIC_TIMERS -extern inline int GPTLstart (const unsigned long); -extern inline int GPTLstop (const unsigned long); -#else extern int GPTLstart (const char *); extern int GPTLstop (const char *); -#endif - extern int GPTLstamp (double *, double *, double *); extern int GPTLpr (const int); extern int GPTLreset (void); diff --git a/private.h b/private.h index b4255b9e..2aa51ffc 100644 --- a/private.h +++ b/private.h @@ -1,5 +1,5 @@ /* -$Id: private.h,v 1.29 2006-12-25 04:15:30 rosinski Exp $ +$Id: private.h,v 1.30 2007-01-01 03:44:02 rosinski Exp $ */ #include @@ -54,7 +54,6 @@ typedef struct TIMER { unsigned int max_recurse; /* max recursion level */ unsigned long count; /* number of start/stop calls */ unsigned long nrecurse; /* number of recursive start/stop calls */ - unsigned long tag; /* used instead of "name" when NUMERIC_TIMERS set */ Wallstats wall; /* wallclock stats */ Cpustats cpu; /* cpu stats */ #ifdef HAVE_PAPI