initial commit to omit ftime usage based on the work from Calin Andrian

ftime is still used if gettimeofday or times is not available
This commit is contained in:
dwarning 2024-10-18 17:50:30 +02:00
parent 67df0c227b
commit 567cea1d86
5 changed files with 68 additions and 69 deletions

View File

@ -908,7 +908,7 @@ AC_STRUCT_TM
AC_STRUCT_TIMEZONE
AC_CHECK_FUNCS([localtime])
AC_CHECK_FUNCS([ftime gettimeofday])
AC_CHECK_FUNCS([gettimeofday times ftime])
# Do not use time or getrusage function for CPU time measurement under OpenMP
if test "x$enable_openmp" = xno; then
AC_CHECK_FUNCS([time getrusage])

View File

@ -22,7 +22,7 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
#include <inttypes.h>
#include "../misc/misc_time.h" /* timediff */
#include "../misc/misc_time.h" /* timebegin */
#ifdef XSPICE
/* gtri - add - 12/12/90 - wbk - include ipc stuff */
@ -81,15 +81,7 @@ init_rlimits(void)
void
init_time(void)
{
#ifdef HAVE_GETRUSAGE
#else
# ifdef HAVE_TIMES
# else
# ifdef HAVE_FTIME
ftime(&timebegin);
# endif
# endif
#endif
timebegin();
}

View File

@ -117,15 +117,17 @@
# include <sys/time.h>
# include <sys/resource.h>
# endif
#else
# ifdef HAVE_TIMES
# include <sys/times.h>
# include <sys/param.h>
# else
# ifdef HAVE_FTIME
# include <sys/timeb.h>
# endif
# endif
#endif
#ifdef HAVE_TIMES
# include <sys/times.h>
# include <sys/param.h>
#endif
#ifdef HAVE_GETTIMEOFDAY
# include <sys/time.h>
#endif
#ifdef HAVE_FTIME
# include <sys/timeb.h>
#endif
#ifdef HAVE_UNISTD_H

View File

@ -14,28 +14,6 @@ Copyright 1990 Regents of the University of California. All rights reserved.
#include <time.h>
#endif
#ifdef HAVE_GETRUSAGE
# include <sys/types.h>
# include <sys/time.h>
# include <sys/resource.h>
#else
# ifdef HAVE_TIMES
# include <sys/types.h>
# include <sys/times.h>
# include <sys/param.h>
# else
# ifdef HAVE_FTIME
/* default to ftime if we can't get real CPU times */
# include <sys/types.h>
# include <sys/timeb.h>
# endif
# endif
#endif
#ifdef HAVE_FTIME
# include <sys/timeb.h>
#endif
/* Return the date. Return value is static data. */
@ -70,8 +48,6 @@ datestring(void)
#ifdef HAVE_FTIME
struct timeb timebegin;
void timediff(struct timeb *now, struct timeb *begin, int *sec, int *msec)
{
@ -87,32 +63,60 @@ void timediff(struct timeb *now, struct timeb *begin, int *sec, int *msec)
#endif
/*
* How many seconds have elapsed in running time.
* This is the routine called in IFseconds
/* Initialize time */
#ifdef HAVE_GETTIMEOFDAY
struct timeval timezero;
void timebegin(void) {
gettimeofday(&timezero, NULL);
}
#else
#ifdef HAVE_TIMES
clock_t timezero;
void timebegin(void) {
struct tms ruse;
timezero = times(&ruse);
}
#else
#ifdef HAVE_FTIME
struct timeb timezero;
void timebegin(void) {
ftime(&timezero);
}
#endif /* FTIME */
#endif /* TIMES */
#endif /* GETTIMEOFDAY */
/*
* How many seconds have elapsed in running time.
* This is the routine called in IFseconds
*/
double
seconds(void)
{
#ifdef HAVE_GETRUSAGE
int ret;
struct rusage ruse;
#ifdef HAVE_GETTIMEOFDAY
struct timeval timenow;
int sec, msec, usec;
gettimeofday(&timenow, NULL);
sec = (int) timenow.tv_sec - (int) timezero.tv_sec;
usec = (int) timenow.tv_usec - (int) timezero.tv_usec;
msec = usec / 1000; // Get rid of extra accuracy
return(sec + (double) msec / 1000.0);
memset(&ruse, 0, sizeof(ruse));
ret = getrusage(RUSAGE_SELF, &ruse);
if(ret == -1) {
perror("getrusage(): ");
return 1;
}
return ((double)ruse.ru_utime.tv_sec + (double) ruse.ru_utime.tv_usec / 1000000.0);
#else
#ifdef HAVE_TIMES
struct tms ruse;
long long msec;
struct tms tmsbuf;
times(&tmsbuf);
return((double) tmsbuf.tms_utime / HZ);
clock_t timenow = times(&ruse);
double hz = (double) sysconf(_SC_CLK_TCK);
msec = (timenow - timezero) / hz * 1000.0; // Get rid of extra accuracy
return((double) msec / 1000.0);
#else
#ifdef HAVE_FTIME
@ -120,14 +124,16 @@ seconds(void)
int sec, msec;
ftime(&timenow);
timediff(&timenow, &timebegin, &sec, &msec);
sec = (int) timenow.time - (int) timezero.time;
msec = (int) timenow.millitm - (int) timezero.millitm;
return(sec + (double) msec / 1000.0);
#else /* unknown */
/* don't know how to do this in general. */
return(-1.0); /* Obvious error condition */
#endif /* !FTIME */
#endif /* !SYSV */
#endif /* !BSD */
return(-1.0); /* Obvious error condition */
#endif /* FTIME */
#endif /* TIMES */
#endif /* GETTIMEOFDAY */
}

View File

@ -8,11 +8,10 @@
char * datestring(void);
double seconds(void);
void timebegin(void);
#ifdef HAVE_FTIME
extern struct timeb timebegin;
void timediff(struct timeb *, struct timeb *, int *, int *);
#endif