提交 0a39d8f2 编写于 作者: A Andy Polyakov

Collect timing procedures in apps/apps.c. It's a bit cruel patch, as it

temporarily[!] removes support for couple of esoteric platforms [well,
Netware, vxWorks and VMS].
上级 6852d1d8
......@@ -2307,6 +2307,9 @@ void policies_print(BIO *out, X509_STORE_CTX *ctx)
BIO_free(out);
}
/*
* Platform-specific sections
*/
#if defined(_WIN32)
# ifdef fileno
# undef fileno
......@@ -2363,7 +2366,98 @@ ok:
if (tfrom!=NULL && tfrom!=(TCHAR *)from) free(tfrom);
return ret;
}
#endif
/* app_tminterval section */
#if defined(_WIN32)
double app_tminterval(int stop,int usertime)
{
FILETIME now;
double ret=0;
static ULARGE_INTEGER tmstart;
#ifdef _WIN32_WINNT
static HANDLE proc=NULL;
if (proc==NULL)
{
if (GetVersion() < 0x80000000)
proc = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,
GetCurrentProcessId());
if (proc==NULL) proc = (HANDLE)-1;
}
if (usertime && proc!=(HANDLE)-1)
{
FILETIME junk;
GetProcessTimes(proc,&junk,&junk,&junk,&now);
}
else
#endif
{
SYSTEMTIME systime;
GetSystemTime(&systime);
SystemTimeToFileTime(&systime,&now);
}
if (stop==TM_START)
{
tmstart.u.LowPart = now.dwLowDateTime;
tmstart.u.HighPart = now.dwHighDateTime;
}
else {
ULARGE_INTEGER tmstop;
tmstop.u.LowPart = now.dwLowDateTime;
tmstop.u.HighPart = now.dwHighDateTime;
ret = (tmstop.QuadPart - tmstart.QuadPart)*1e-7;
}
return (ret);
}
#elif defined(_SC_CLK_TCK) /* by means of unistd.h */
#include <sys/times.h>
double app_tminterval(int stop,int usertime)
{
double ret = 0;
struct tms rus;
clock_t now = times(&rus);
static clock_t tmstart;
if (usertime) now = rus.tms_utime;
if (stop==TMSTART) tmstart = now;
else ret = (now - tmstart)/(double)sysconf(_SC_CLK_TCK);
return (ret);
}
#else
#include <sys/time.h>
#include <sys/resource.h>
double app_tminterval(int stop,int usertime)
{
double ret = 0;
struct rusage rus;
struct timeval now;
static struct timeval tmstart;
if (usertime) getrusage(RUSAGE_SELF,&rus), now = rus.ru_time;
else gettimeofday(&now,NULL);
if (stop==TMSTART) tmstart = now;
else ret = ( (now.tv_sec+now.tv_usec*1e-6)
- (tmstart.tv_sec+tmstart.tv_usec*1e-6) );
return ret;
}
#endif
/* app_isdir section */
#ifdef _WIN32
int app_isdir(const char *name)
{
HANDLE hList;
......@@ -2411,6 +2505,7 @@ int app_isdir(const char *name)
}
#endif
/* raw_read|write section */
#if defined(_WIN32) && defined(STD_INPUT_HANDLE)
int raw_read_stdin(void *buf,int siz)
{
......@@ -2436,4 +2531,3 @@ int raw_write_stdout(void *buf,int siz)
int raw_write_stdout(const void *buf,int siz)
{ return write(fileno(stdout),buf,siz); }
#endif
......@@ -314,4 +314,8 @@ void policies_print(BIO *out, X509_STORE_CTX *ctx);
int app_isdir(const char *);
int raw_read_stdin(void *,int);
int raw_write_stdout(const void *,int);
#define TM_START 0
#define TM_STOP 1
double app_tminterval (int stop,int usertime);
#endif
......@@ -85,54 +85,6 @@
#include OPENSSL_UNISTD
#endif
#if !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
#define TIMES
#endif
#ifndef _IRIX
#include <time.h>
#endif
#ifdef TIMES
#include <sys/types.h>
#include <sys/times.h>
#endif
/* Depending on the VMS version, the tms structure is perhaps defined.
The __TMS macro will show if it was. If it wasn't defined, we should
undefine TIMES, since that tells the rest of the program how things
should be handled. -- Richard Levitte */
#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
#undef TIMES
#endif
#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
#include <sys/timeb.h>
#endif
#if defined(sun) || defined(__ultrix)
#define _POSIX_SOURCE
#include <limits.h>
#include <sys/param.h>
#endif
/* The following if from times(3) man page. It may need to be changed
*/
#ifndef HZ
# ifdef _SC_CLK_TCK
# define HZ ((double)sysconf(_SC_CLK_TCK))
# else
# ifndef CLK_TCK
# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
# define HZ 100.0
# else /* _BSD_CLK_TCK_ */
# define HZ ((double)_BSD_CLK_TCK_)
# endif
# else /* CLK_TCK */
# define HZ ((double)CLK_TCK)
# endif
# endif
#endif
#undef PROG
#define PROG s_time_main
......@@ -372,63 +324,8 @@ bad:
static double tm_Time_F(int s)
{
static double ret;
#ifdef TIMES
static struct tms tstart,tend;
if(s == START) {
times(&tstart);
return(0);
} else {
times(&tend);
ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
return((ret == 0.0)?1e-6:ret);
return app_tminterval(s,1);
}
#elif defined(OPENSSL_SYS_NETWARE)
static clock_t tstart,tend;
if (s == START)
{
tstart=clock();
return(0);
}
else
{
tend=clock();
ret=(double)((double)(tend)-(double)(tstart));
return((ret < 0.001)?0.001:ret);
}
#elif defined(OPENSSL_SYS_VXWORKS)
{
static unsigned long tick_start, tick_end;
if( s == START )
{
tick_start = tickGet();
return 0;
}
else
{
tick_end = tickGet();
ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
return((ret == 0.0)?1e-6:ret);
}
}
#else /* !times() */
static struct timeb tstart,tend;
long i;
if(s == START) {
ftime(&tstart);
return(0);
} else {
ftime(&tend);
i=(long)tend.millitm-(long)tstart.millitm;
ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
return((ret == 0.0)?1e-6:ret);
}
#endif
}
/***********************************************************************
* MAIN - main processing area for client
......
......@@ -108,53 +108,8 @@
#include <signal.h>
#endif
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(OPENSSL_SYS_MACOSX)
# define USE_TOD
#elif !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
# define TIMES
#endif
#if !defined(_UNICOS) && !defined(__OpenBSD__) && !defined(sgi) && !defined(__FreeBSD__) && !(defined(__bsdi) || defined(__bsdi__)) && !defined(_AIX) && !defined(OPENSSL_SYS_MPE) && !defined(__NetBSD__) && !defined(OPENSSL_SYS_VXWORKS) /* FIXME */
# define TIMEB
#endif
#if defined(OPENSSL_SYS_NETWARE)
#undef TIMES
#undef TIMEB
#include <time.h>
#endif
#ifndef _IRIX
# include <time.h>
#endif
#ifdef TIMES
# include <sys/types.h>
# include <sys/times.h>
#endif
#ifdef USE_TOD
# include <sys/time.h>
# include <sys/resource.h>
#endif
/* Depending on the VMS version, the tms structure is perhaps defined.
The __TMS macro will show if it was. If it wasn't defined, we should
undefine TIMES, since that tells the rest of the program how things
should be handled. -- Richard Levitte */
#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
#undef TIMES
#endif
#ifdef TIMEB
#include <sys/timeb.h>
#endif
#if !defined(TIMES) && !defined(TIMEB) && !defined(USE_TOD) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
#error "It seems neither struct tms nor struct timeb is supported in this platform!"
#endif
#if defined(sun) || defined(__ultrix)
#define _POSIX_SOURCE
#include <limits.h>
#include <sys/param.h>
#ifdef _WIN32
#include <windows.h>
#endif
#include <openssl/bn.h>
......@@ -220,34 +175,6 @@
#include <openssl/ecdh.h>
#endif
/*
* The following "HZ" timing stuff should be sync'd up with the code in
* crypto/tmdiff.[ch]. That appears to try to do the same job, though I think
* this code is more up to date than libcrypto's so there may be features to
* migrate over first. This is used in two places further down AFAICS.
* The point is that nothing in openssl actually *uses* that tmdiff stuff, so
* either speed.c should be using it or it should go because it's obviously not
* useful enough. Anyone want to do a janitorial job on this?
*/
/* The following if from times(3) man page. It may need to be changed */
#ifndef HZ
# if defined(_SC_CLK_TCK) \
&& (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000)
# define HZ sysconf(_SC_CLK_TCK)
# else
# ifndef CLK_TCK
# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
# define HZ 100.0
# else /* _BSD_CLK_TCK_ */
# define HZ ((double)_BSD_CLK_TCK_)
# endif
# else /* CLK_TCK */
# define HZ ((double)CLK_TCK)
# endif
# endif
#endif
#if !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_OS2) && !defined(OPENSSL_SYS_NETWARE)
# define HAVE_FORK 1
#endif
......@@ -319,141 +246,46 @@ static SIGRETTYPE sig_done(int sig)
#define START 0
#define STOP 1
#if defined(OPENSSL_SYS_NETWARE)
#if defined(_WIN32)
/* for NetWare the best we can do is use clock() which returns the
* time, in hundredths of a second, since the NLM began executing
*/
static double Time_F(int s)
{
double ret;
static clock_t tstart,tend;
if (s == START)
{
tstart=clock();
return(0);
}
else
{
tend=clock();
ret=(double)((double)(tend)-(double)(tstart));
return((ret < 0.001)?0.001:ret);
}
}
#define SIGALRM
static unsigned int lapse,schlock;
static void alarm(unsigned int secs) { lapse = secs*1000; }
#else
static DWORD WINAPI sleepy(VOID *arg)
{
schlock = 1;
Sleep(lapse);
run = 0;
return 0;
}
static double Time_F(int s)
{
double ret;
#ifdef USE_TOD
if(usertime)
if (s == START)
{
static struct rusage tstart,tend;
getrusage_used = 1;
if (s == START)
{
getrusage(RUSAGE_SELF,&tstart);
return(0);
}
else
HANDLE thr;
schlock = 0;
thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
if (thr==NULL)
{
long i;
getrusage(RUSAGE_SELF,&tend);
i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec;
ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec))
+((double)i)/1000000.0;
return((ret < 0.001)?0.001:ret);
DWORD ret=GetLastError();
BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
ExitProcess(ret);
}
CloseHandle(thr); /* detach the thread */
while (!schlock) Sleep(0); /* scheduler spinlock */
}
else
{
static struct timeval tstart,tend;
long i;
gettimeofday_used = 1;
if (s == START)
{
gettimeofday(&tstart,NULL);
return(0);
}
else
{
gettimeofday(&tend,NULL);
i=(long)tend.tv_usec-(long)tstart.tv_usec;
ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0;
return((ret < 0.001)?0.001:ret);
}
}
#else /* ndef USE_TOD */
# ifdef TIMES
if (usertime)
{
static struct tms tstart,tend;
times_used = 1;
if (s == START)
{
times(&tstart);
return(0);
}
else
{
times(&tend);
ret = HZ;
ret=(double)(tend.tms_utime-tstart.tms_utime) / ret;
return((ret < 1e-3)?1e-3:ret);
}
}
# endif /* times() */
# if defined(TIMES) && defined(TIMEB)
else
# endif
# ifdef OPENSSL_SYS_VXWORKS
{
static unsigned long tick_start, tick_end;
if( s == START )
{
tick_start = tickGet();
return 0;
}
else
{
tick_end = tickGet();
ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
return((ret < 0.001)?0.001:ret);
}
}
# elif defined(TIMEB)
{
static struct timeb tstart,tend;
long i;
return app_tminterval(s,usertime);
}
#else
ftime_used = 1;
if (s == START)
{
ftime(&tstart);
return(0);
}
else
{
ftime(&tend);
i=(long)tend.millitm-(long)tstart.millitm;
ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
return((ret < 0.001)?0.001:ret);
}
}
# endif
#endif
static double Time_F(int s)
{
return app_tminterval(s,usertime);
}
#endif /* if defined(OPENSSL_SYS_NETWARE) */
#endif
#ifndef OPENSSL_NO_ECDH
......@@ -1508,7 +1340,9 @@ int MAIN(int argc, char **argv)
#else
#define COND(c) (run)
#define COUNT(d) (count)
#ifndef _WIN32
signal(SIGALRM,sig_done);
#endif
#endif /* SIGALRM */
#ifndef OPENSSL_NO_MD2
......@@ -2295,35 +2129,6 @@ show_res:
printf("%s ",BF_options());
#endif
fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
printf("available timing options: ");
#ifdef TIMES
printf("TIMES ");
#endif
#ifdef TIMEB
printf("TIMEB ");
#endif
#ifdef USE_TOD
printf("USE_TOD ");
#endif
#ifdef HZ
#define as_string(s) (#s)
{
double dbl = HZ;
printf("HZ=%g", dbl);
}
# ifdef _SC_CLK_TCK
printf(" [sysconf value]");
# endif
#endif
printf("\n");
printf("timing function used: %s%s%s%s%s%s%s\n",
(ftime_used ? "ftime" : ""),
(ftime_used + times_used > 1 ? "," : ""),
(times_used ? "times" : ""),
(ftime_used + times_used + gettimeofday_used > 1 ? "," : ""),
(gettimeofday_used ? "gettimeofday" : ""),
(ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""),
(getrusage_used ? "getrusage" : ""));
}
if (pr_header)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册