openssl s_time, speed: use monotime for absolute interval measurement

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

openssl s_time, speed: use monotime for absolute interval measurement

Scott Cheloha
Hi,

times(3) is okay for user CPU measurement but is inappropriate
for absolute interval measurement as its output is subject to
changes by both adjtime(2) and settimeofday(2).

The attached diff replaces it with getrusage(2) for user CPU
measurement and clock_gettime(2)'s CLOCK_MONOTONIC clock for
absolute interval measurement.

The attached diff also replaces time(3) in s_time with
clock_gettime's CLOCK_MONOTONIC clock.  This ensures that we
only measure for about as long as the user said to.

Neither timersub(2) nor timespecsub are standard, though many
systems have them.  Is this a problem for libressl-portable?

Thoughts and feedback?

--
Scott Cheloha

Index: usr.bin/openssl/apps.h
===================================================================
RCS file: /cvs/src/usr.bin/openssl/apps.h,v
retrieving revision 1.19
diff -u -p -r1.19 apps.h
--- usr.bin/openssl/apps.h 30 Aug 2016 14:34:59 -0000 1.19
+++ usr.bin/openssl/apps.h 10 Nov 2017 18:38:13 -0000
@@ -277,9 +277,8 @@ unsigned char *next_protos_parse(unsigne
 
 int app_isdir(const char *);
 
-#define TM_START 0
-#define TM_STOP 1
-double app_tminterval (int stop, int usertime);
+double real_interval(int new);
+double user_interval(int new);
 
 #define OPENSSL_NO_SSL_INTERN
 
Index: usr.bin/openssl/apps_posix.c
===================================================================
RCS file: /cvs/src/usr.bin/openssl/apps_posix.c,v
retrieving revision 1.2
diff -u -p -r1.2 apps_posix.c
--- usr.bin/openssl/apps_posix.c 13 Sep 2015 12:41:01 -0000 1.2
+++ usr.bin/openssl/apps_posix.c 10 Nov 2017 18:38:13 -0000
@@ -116,31 +116,39 @@
  * Functions that need to be overridden by non-POSIX operating systems.
  */
 
-#include <sys/times.h>
+#include <sys/resource.h>
 
-#include <unistd.h>
+#include <time.h>
 
 #include "apps.h"
 
 double
-app_tminterval(int stop, int usertime)
+real_interval(int new)
 {
- double ret = 0;
- struct tms rus;
- clock_t now = times(&rus);
- static clock_t tmstart;
-
- if (usertime)
- now = rus.tms_utime;
-
- if (stop == TM_START)
- tmstart = now;
- else {
- long int tck = sysconf(_SC_CLK_TCK);
- ret = (now - tmstart) / (double) tck;
+ static struct timespec elapsed, now, start;
+
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (new) {
+ start = now;
+ return 0.0;
  }
+ timespecsub(&now, &start, &elapsed);
+ return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0;
+}
 
- return (ret);
+double
+user_interval(int new)
+{
+ static struct timeval elapsed, start;
+ static struct rusage now;
+
+ getrusage(RUSAGE_SELF, &now);
+ if (new) {
+ start = now.ru_utime;
+ return 0.0;
+ }
+ timersub(&now.ru_utime, &start, &elapsed);
+ return elapsed.tv_sec + elapsed.tv_usec / 1000000.0;
 }
 
 int
Index: usr.bin/openssl/s_time.c
===================================================================
RCS file: /cvs/src/usr.bin/openssl/s_time.c,v
retrieving revision 1.18
diff -u -p -r1.18 s_time.c
--- usr.bin/openssl/s_time.c 2 Nov 2017 00:31:49 -0000 1.18
+++ usr.bin/openssl/s_time.c 10 Nov 2017 18:38:13 -0000
@@ -68,6 +68,7 @@
 #include <stdlib.h>
 #include <limits.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 #include <poll.h>
 
@@ -229,14 +230,9 @@ s_time_usage(void)
 /***********************************************************************
  * TIME - time functions
  */
-#define START 0
-#define STOP 1
-
-static double
-tm_Time_F(int s)
-{
- return app_tminterval(s, 1);
-}
+#define START 1
+#define STOP 0
+#define tm_Time_F(s) user_interval(s);
 
 /***********************************************************************
  * MAIN - main processing area for client
@@ -248,7 +244,7 @@ s_time_main(int argc, char **argv)
  double totalTime = 0.0;
  int nConn = 0;
  SSL *scon = NULL;
- time_t finishtime;
+ struct timespec finishtime, now;
  int ret = 1;
  char buf[1024 * 8];
  int ver;
@@ -330,10 +326,12 @@ s_time_main(int argc, char **argv)
  /* Loop and time how long it takes to make connections */
 
  bytes_read = 0;
- finishtime = time(NULL) + s_time_config.maxtime;
+ clock_gettime(CLOCK_MONOTONIC, &finishtime);
+ finishtime.tv_sec += s_time_config.maxtime;
  tm_Time_F(START);
  for (;;) {
- if (finishtime < time(NULL))
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (timespeccmp(&finishtime, &now, <))
  break;
  if ((scon = doConnection(NULL)) == NULL)
  goto end;
@@ -383,7 +381,7 @@ s_time_main(int argc, char **argv)
     nConn, totalTime, ((double) nConn / totalTime), bytes_read);
  printf("%d connections in %lld real seconds, %ld bytes read per connection\n",
     nConn,
-    (long long)(time(NULL) - finishtime + s_time_config.maxtime),
+    (long long)(now.tv_sec - finishtime.tv_sec + s_time_config.maxtime),
     bytes_read / nConn);
 
  /*
@@ -422,14 +420,16 @@ next:
  nConn = 0;
  totalTime = 0.0;
 
- finishtime = time(NULL) + s_time_config.maxtime;
+ clock_gettime(CLOCK_MONOTONIC, &finishtime);
+ finishtime.tv_sec += s_time_config.maxtime;
 
  printf("starting\n");
  bytes_read = 0;
  tm_Time_F(START);
 
  for (;;) {
- if (finishtime < time(NULL))
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (timespeccmp(&finishtime, &now, <))
  break;
  if ((doConnection(scon)) == NULL)
  goto end;
@@ -475,7 +475,7 @@ next:
  printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double) nConn / totalTime), bytes_read);
  printf("%d connections in %lld real seconds, %ld bytes read per connection\n",
     nConn,
-    (long long)(time(NULL) - finishtime + s_time_config.maxtime),
+    (long long)(now.tv_sec - finishtime.tv_sec + s_time_config.maxtime),
     bytes_read / nConn);
 
  ret = 0;
Index: usr.bin/openssl/speed.c
===================================================================
RCS file: /cvs/src/usr.bin/openssl/speed.c,v
retrieving revision 1.20
diff -u -p -r1.20 speed.c
--- usr.bin/openssl/speed.c 7 Oct 2017 06:16:54 -0000 1.20
+++ usr.bin/openssl/speed.c 10 Nov 2017 18:38:13 -0000
@@ -85,6 +85,7 @@
 #include <stdlib.h>
 #include <limits.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 
 #include "apps.h"
@@ -153,7 +154,6 @@ int run = 0;
 static int mr = 0;
 static int usertime = 1;
 
-static double Time_F(int s);
 static void print_message(const char *s, long num, int length);
 static void
 pkey_print_message(const char *str, const char *str2,
@@ -195,16 +195,11 @@ sig_done(int sig)
  run = 0;
 }
 
-#define START 0
-#define STOP 1
-
-
-static double
-Time_F(int s)
-{
- return app_tminterval(s, usertime);
-}
+#define START 1
+#define STOP 0
 
+static double (*interval_function)(int) = user_interval;
+#define Time_F(s) interval_function(s)
 
 static const int KDF1_SHA1_len = 20;
 static void *
@@ -947,8 +942,10 @@ speed_main(int argc, char **argv)
  if (doit[i])
  pr_header++;
 
- if (usertime == 0 && !mr)
+ if (usertime == 0 && !mr) {
  BIO_printf(bio_err, "You have chosen to measure elapsed time instead of user CPU time.\n");
+ interval_function = real_interval;
+ }
 
  for (i = 0; i < RSA_NUM; i++) {
  const unsigned char *p;
Reply | Threaded
Open this post in threaded view
|

Re: openssl s_time, speed: use monotime for absolute interval measurement

Jeremie Courreges-Anglas-2
On Sat, Nov 11 2017, Scott Cheloha <[hidden email]> wrote:
> Hi,

Hi,

> times(3) is okay for user CPU measurement but is inappropriate
> for absolute interval measurement as its output is subject to
> changes by both adjtime(2) and settimeofday(2).
>
> The attached diff replaces it with getrusage(2) for user CPU
> measurement and clock_gettime(2)'s CLOCK_MONOTONIC clock for
> absolute interval measurement.
>
> The attached diff also replaces time(3) in s_time with
> clock_gettime's CLOCK_MONOTONIC clock.  This ensures that we
> only measure for about as long as the user said to.
>
> Neither timersub(2) nor timespecsub are standard, though many
> systems have them.  Is this a problem for libressl-portable?

I doubt that timersub/timespecsub are a big problem to add to -portable,
they're just macros.  clock_gettime and getrusage seem to already be
used in libressl(-portable), there's autoconf glue for the former at
least.

> Thoughts and feedback?

More comment inline.

> --
> Scott Cheloha
>
> Index: usr.bin/openssl/apps.h
> ===================================================================
> RCS file: /cvs/src/usr.bin/openssl/apps.h,v
> retrieving revision 1.19
> diff -u -p -r1.19 apps.h
> --- usr.bin/openssl/apps.h 30 Aug 2016 14:34:59 -0000 1.19
> +++ usr.bin/openssl/apps.h 10 Nov 2017 18:38:13 -0000
> @@ -277,9 +277,8 @@ unsigned char *next_protos_parse(unsigne
>  
>  int app_isdir(const char *);
>  
> -#define TM_START 0
> -#define TM_STOP 1
> -double app_tminterval (int stop, int usertime);
> +double real_interval(int new);
> +double user_interval(int new);
>  
>  #define OPENSSL_NO_SSL_INTERN
>  
> Index: usr.bin/openssl/apps_posix.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/openssl/apps_posix.c,v
> retrieving revision 1.2
> diff -u -p -r1.2 apps_posix.c
> --- usr.bin/openssl/apps_posix.c 13 Sep 2015 12:41:01 -0000 1.2
> +++ usr.bin/openssl/apps_posix.c 10 Nov 2017 18:38:13 -0000
> @@ -116,31 +116,39 @@
>   * Functions that need to be overridden by non-POSIX operating systems.
>   */
>  
> -#include <sys/times.h>
> +#include <sys/resource.h>
>  
> -#include <unistd.h>
> +#include <time.h>
>  
>  #include "apps.h"
>  
>  double
> -app_tminterval(int stop, int usertime)
> +real_interval(int new)

I suggest you keep app_tminterval() as the entry point here.  As
mentioned by the comment, non-POSIX systems need to implement the same
interface, and indeed apps/openssl/apps_win.c in libressl-portable also
provides app_tminterval().

>  {
> - double ret = 0;
> - struct tms rus;
> - clock_t now = times(&rus);
> - static clock_t tmstart;
> -
> - if (usertime)
> - now = rus.tms_utime;
> -
> - if (stop == TM_START)
> - tmstart = now;
> - else {
> - long int tck = sysconf(_SC_CLK_TCK);
> - ret = (now - tmstart) / (double) tck;
> + static struct timespec elapsed, now, start;

Only "start" need to be static here.

> +
> + clock_gettime(CLOCK_MONOTONIC, &now);
> + if (new) {
> + start = now;
> + return 0.0;
>   }
> + timespecsub(&now, &start, &elapsed);
> + return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0;
> +}
>  
> - return (ret);
> +double
> +user_interval(int new)
> +{
> + static struct timeval elapsed, start;
> + static struct rusage now;

Same here.

> +
> + getrusage(RUSAGE_SELF, &now);
> + if (new) {
> + start = now.ru_utime;
> + return 0.0;
> + }
> + timersub(&now.ru_utime, &start, &elapsed);
> + return elapsed.tv_sec + elapsed.tv_usec / 1000000.0;
>  }
>  
>  int
> Index: usr.bin/openssl/s_time.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/openssl/s_time.c,v
> retrieving revision 1.18
> diff -u -p -r1.18 s_time.c
> --- usr.bin/openssl/s_time.c 2 Nov 2017 00:31:49 -0000 1.18
> +++ usr.bin/openssl/s_time.c 10 Nov 2017 18:38:13 -0000
> @@ -68,6 +68,7 @@
>  #include <stdlib.h>
>  #include <limits.h>
>  #include <string.h>
> +#include <time.h>
>  #include <unistd.h>
>  #include <poll.h>
>  
> @@ -229,14 +230,9 @@ s_time_usage(void)
>  /***********************************************************************
>   * TIME - time functions
>   */
> -#define START 0
> -#define STOP 1
> -
> -static double
> -tm_Time_F(int s)
> -{
> - return app_tminterval(s, 1);
> -}
> +#define START 1
> +#define STOP 0
> +#define tm_Time_F(s) user_interval(s);
>  
>  /***********************************************************************
>   * MAIN - main processing area for client
> @@ -248,7 +244,7 @@ s_time_main(int argc, char **argv)
>   double totalTime = 0.0;
>   int nConn = 0;
>   SSL *scon = NULL;
> - time_t finishtime;
> + struct timespec finishtime, now;
>   int ret = 1;
>   char buf[1024 * 8];
>   int ver;
> @@ -330,10 +326,12 @@ s_time_main(int argc, char **argv)
>   /* Loop and time how long it takes to make connections */
>  
>   bytes_read = 0;
> - finishtime = time(NULL) + s_time_config.maxtime;
> + clock_gettime(CLOCK_MONOTONIC, &finishtime);
> + finishtime.tv_sec += s_time_config.maxtime;
>   tm_Time_F(START);
>   for (;;) {
> - if (finishtime < time(NULL))
> + clock_gettime(CLOCK_MONOTONIC, &now);
> + if (timespeccmp(&finishtime, &now, <))
>   break;
>   if ((scon = doConnection(NULL)) == NULL)
>   goto end;
> @@ -383,7 +381,7 @@ s_time_main(int argc, char **argv)
>      nConn, totalTime, ((double) nConn / totalTime), bytes_read);
>   printf("%d connections in %lld real seconds, %ld bytes read per connection\n",
>      nConn,
> -    (long long)(time(NULL) - finishtime + s_time_config.maxtime),
> +    (long long)(now.tv_sec - finishtime.tv_sec + s_time_config.maxtime),
>      bytes_read / nConn);
>  
>   /*
> @@ -422,14 +420,16 @@ next:
>   nConn = 0;
>   totalTime = 0.0;
>  
> - finishtime = time(NULL) + s_time_config.maxtime;
> + clock_gettime(CLOCK_MONOTONIC, &finishtime);
> + finishtime.tv_sec += s_time_config.maxtime;
>  
>   printf("starting\n");
>   bytes_read = 0;
>   tm_Time_F(START);
>  
>   for (;;) {
> - if (finishtime < time(NULL))
> + clock_gettime(CLOCK_MONOTONIC, &now);
> + if (timespeccmp(&finishtime, &now, <))
>   break;
>   if ((doConnection(scon)) == NULL)
>   goto end;
> @@ -475,7 +475,7 @@ next:
>   printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double) nConn / totalTime), bytes_read);
>   printf("%d connections in %lld real seconds, %ld bytes read per connection\n",
>      nConn,
> -    (long long)(time(NULL) - finishtime + s_time_config.maxtime),
> +    (long long)(now.tv_sec - finishtime.tv_sec + s_time_config.maxtime),
>      bytes_read / nConn);
>  
>   ret = 0;
> Index: usr.bin/openssl/speed.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/openssl/speed.c,v
> retrieving revision 1.20
> diff -u -p -r1.20 speed.c
> --- usr.bin/openssl/speed.c 7 Oct 2017 06:16:54 -0000 1.20
> +++ usr.bin/openssl/speed.c 10 Nov 2017 18:38:13 -0000
> @@ -85,6 +85,7 @@
>  #include <stdlib.h>
>  #include <limits.h>
>  #include <string.h>
> +#include <time.h>
>  #include <unistd.h>
>  
>  #include "apps.h"
> @@ -153,7 +154,6 @@ int run = 0;
>  static int mr = 0;
>  static int usertime = 1;
>  
> -static double Time_F(int s);
>  static void print_message(const char *s, long num, int length);
>  static void
>  pkey_print_message(const char *str, const char *str2,
> @@ -195,16 +195,11 @@ sig_done(int sig)
>   run = 0;
>  }
>  
> -#define START 0
> -#define STOP 1
> -
> -
> -static double
> -Time_F(int s)
> -{
> - return app_tminterval(s, usertime);
> -}
> +#define START 1
> +#define STOP 0
>  
> +static double (*interval_function)(int) = user_interval;
> +#define Time_F(s) interval_function(s)
>  
>  static const int KDF1_SHA1_len = 20;
>  static void *
> @@ -947,8 +942,10 @@ speed_main(int argc, char **argv)
>   if (doit[i])
>   pr_header++;
>  
> - if (usertime == 0 && !mr)
> + if (usertime == 0 && !mr) {
>   BIO_printf(bio_err, "You have chosen to measure elapsed time instead of user CPU time.\n");
> + interval_function = real_interval;

It seems a bit overengineered to use a function pointer for this.  No
need to change this code if you just keep the app_tminterval()
interface.

> + }
>  
>   for (i = 0; i < RSA_NUM; i++) {
>   const unsigned char *p;
>

--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply | Threaded
Open this post in threaded view
|

Re: openssl s_time, speed: use monotime for absolute interval measurement

Scott Cheloha
On Sat, Nov 18, 2017 at 05:27:14PM +0100, Jeremie Courreges-Anglas wrote:
> On Sat, Nov 11 2017, Scott Cheloha <[hidden email]> wrote:
> > [...]
>
> I doubt that timersub/timespecsub are a big problem to add to -portable,
> they're just macros.  clock_gettime and getrusage seem to already be
> used in libressl(-portable), there's autoconf glue for the former at
> least.

Sounds good to me.

> > Thoughts and feedback?
>
> More comment inline.
>
> > [...]
> >
> >  double
> > -app_tminterval(int stop, int usertime)
> > +real_interval(int new)
>
> I suggest you keep app_tminterval() as the entry point here.  As
> mentioned by the comment, non-POSIX systems need to implement the same
> interface, and indeed apps/openssl/apps_win.c in libressl-portable also
> provides app_tminterval().

Okay, retained.

> > [...]
> >
> > + static struct timespec elapsed, now, start;
>
> Only "start" need to be static here.
>
> > [...]
> >
> > +double
> > +user_interval(int new)
> > +{
> > + static struct timeval elapsed, start;
> > + static struct rusage now;
>
> Same here.

Fixed and fixed.

> > [...]
> >
> > - if (usertime == 0 && !mr)
> > + if (usertime == 0 && !mr) {
> >   BIO_printf(bio_err, "You have chosen to measure elapsed time instead of user CPU time.\n");
> > + interval_function = real_interval;
>
> It seems a bit overengineered to use a function pointer for this.  No
> need to change this code if you just keep the app_tminterval()
> interface.

Yep.  Keeping the interface eliminates the need for changes in
speed.c and apps.h.

Also, you need <sys/time.h> to use timersub, timespecsub, etc, so
I added that to s_time.c and apps_posix.c.

--
Scott Cheloha

Index: usr.bin/openssl/apps_posix.c
===================================================================
RCS file: /cvs/src/usr.bin/openssl/apps_posix.c,v
retrieving revision 1.2
diff -u -p -r1.2 apps_posix.c
--- usr.bin/openssl/apps_posix.c 13 Sep 2015 12:41:01 -0000 1.2
+++ usr.bin/openssl/apps_posix.c 21 Nov 2017 23:48:12 -0000
@@ -116,31 +116,48 @@
  * Functions that need to be overridden by non-POSIX operating systems.
  */
 
-#include <sys/times.h>
+#include <sys/resource.h>
+#include <sys/time.h>
 
-#include <unistd.h>
+#include <time.h>
 
 #include "apps.h"
 
-double
-app_tminterval(int stop, int usertime)
+static double
+real_interval(int stop)
 {
- double ret = 0;
- struct tms rus;
- clock_t now = times(&rus);
- static clock_t tmstart;
-
- if (usertime)
- now = rus.tms_utime;
-
- if (stop == TM_START)
- tmstart = now;
- else {
- long int tck = sysconf(_SC_CLK_TCK);
- ret = (now - tmstart) / (double) tck;
+ static struct timespec start;
+ static struct timespec elapsed, now;
+
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (stop) {
+ timespecsub(&now, &start, &elapsed);
+ return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0;
  }
+ start = now;
+ return 0.0;
+}
 
- return (ret);
+static double
+user_interval(int stop)
+{
+ static struct timeval start;
+ static struct timeval elapsed;
+ static struct rusage now;
+
+ getrusage(RUSAGE_SELF, &now);
+ if (stop) {
+ timersub(&now.ru_utime, &start, &elapsed);
+ return elapsed.tv_sec + elapsed.tv_usec / 1000000.0;
+ }
+ start = now.ru_utime;
+ return 0.0;
+}
+
+double
+app_tminterval(int stop, int usertime)
+{
+ return (usertime) ? user_interval(stop) : real_interval(stop);
 }
 
 int
Index: usr.bin/openssl/s_time.c
===================================================================
RCS file: /cvs/src/usr.bin/openssl/s_time.c,v
retrieving revision 1.18
diff -u -p -r1.18 s_time.c
--- usr.bin/openssl/s_time.c 2 Nov 2017 00:31:49 -0000 1.18
+++ usr.bin/openssl/s_time.c 21 Nov 2017 23:48:12 -0000
@@ -63,11 +63,13 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <limits.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 #include <poll.h>
 
@@ -248,7 +250,7 @@ s_time_main(int argc, char **argv)
  double totalTime = 0.0;
  int nConn = 0;
  SSL *scon = NULL;
- time_t finishtime;
+ struct timespec finishtime, now;
  int ret = 1;
  char buf[1024 * 8];
  int ver;
@@ -330,10 +332,12 @@ s_time_main(int argc, char **argv)
  /* Loop and time how long it takes to make connections */
 
  bytes_read = 0;
- finishtime = time(NULL) + s_time_config.maxtime;
+ clock_gettime(CLOCK_MONOTONIC, &finishtime);
+ finishtime.tv_sec += s_time_config.maxtime;
  tm_Time_F(START);
  for (;;) {
- if (finishtime < time(NULL))
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (timespeccmp(&finishtime, &now, <))
  break;
  if ((scon = doConnection(NULL)) == NULL)
  goto end;
@@ -383,7 +387,7 @@ s_time_main(int argc, char **argv)
     nConn, totalTime, ((double) nConn / totalTime), bytes_read);
  printf("%d connections in %lld real seconds, %ld bytes read per connection\n",
     nConn,
-    (long long)(time(NULL) - finishtime + s_time_config.maxtime),
+    (long long)(now.tv_sec - finishtime.tv_sec + s_time_config.maxtime),
     bytes_read / nConn);
 
  /*
@@ -422,14 +426,16 @@ next:
  nConn = 0;
  totalTime = 0.0;
 
- finishtime = time(NULL) + s_time_config.maxtime;
+ clock_gettime(CLOCK_MONOTONIC, &finishtime);
+ finishtime.tv_sec += s_time_config.maxtime;
 
  printf("starting\n");
  bytes_read = 0;
  tm_Time_F(START);
 
  for (;;) {
- if (finishtime < time(NULL))
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (timespeccmp(&finishtime, &now, <))
  break;
  if ((doConnection(scon)) == NULL)
  goto end;
@@ -475,7 +481,7 @@ next:
  printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double) nConn / totalTime), bytes_read);
  printf("%d connections in %lld real seconds, %ld bytes read per connection\n",
     nConn,
-    (long long)(time(NULL) - finishtime + s_time_config.maxtime),
+    (long long)(now.tv_sec - finishtime.tv_sec + s_time_config.maxtime),
     bytes_read / nConn);
 
  ret = 0;

Reply | Threaded
Open this post in threaded view
|

Re: openssl s_time, speed: use monotime for absolute interval measurement

Scott Cheloha
In reply to this post by Jeremie Courreges-Anglas-2
Whoops, ignore that last patch, it lacked the
static changes in apps_posix.c

--
Scott Cheloha

Index: usr.bin/openssl/apps_posix.c
===================================================================
RCS file: /cvs/src/usr.bin/openssl/apps_posix.c,v
retrieving revision 1.2
diff -u -p -r1.2 apps_posix.c
--- usr.bin/openssl/apps_posix.c 13 Sep 2015 12:41:01 -0000 1.2
+++ usr.bin/openssl/apps_posix.c 22 Nov 2017 16:39:42 -0000
@@ -116,31 +116,48 @@
  * Functions that need to be overridden by non-POSIX operating systems.
  */
 
-#include <sys/times.h>
+#include <sys/resource.h>
+#include <sys/time.h>
 
-#include <unistd.h>
+#include <time.h>
 
 #include "apps.h"
 
-double
-app_tminterval(int stop, int usertime)
+static double
+real_interval(int stop)
 {
- double ret = 0;
- struct tms rus;
- clock_t now = times(&rus);
- static clock_t tmstart;
-
- if (usertime)
- now = rus.tms_utime;
-
- if (stop == TM_START)
- tmstart = now;
- else {
- long int tck = sysconf(_SC_CLK_TCK);
- ret = (now - tmstart) / (double) tck;
+ static struct timespec start;
+ struct timespec elapsed, now;
+
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (stop) {
+ timespecsub(&now, &start, &elapsed);
+ return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0;
  }
+ start = now;
+ return 0.0;
+}
 
- return (ret);
+static double
+user_interval(int stop)
+{
+ static struct timeval start;
+ struct timeval elapsed;
+ struct rusage now;
+
+ getrusage(RUSAGE_SELF, &now);
+ if (stop) {
+ timersub(&now.ru_utime, &start, &elapsed);
+ return elapsed.tv_sec + elapsed.tv_usec / 1000000.0;
+ }
+ start = now.ru_utime;
+ return 0.0;
+}
+
+double
+app_tminterval(int stop, int usertime)
+{
+ return (usertime) ? user_interval(stop) : real_interval(stop);
 }
 
 int
Index: usr.bin/openssl/s_time.c
===================================================================
RCS file: /cvs/src/usr.bin/openssl/s_time.c,v
retrieving revision 1.18
diff -u -p -r1.18 s_time.c
--- usr.bin/openssl/s_time.c 2 Nov 2017 00:31:49 -0000 1.18
+++ usr.bin/openssl/s_time.c 22 Nov 2017 16:39:42 -0000
@@ -63,11 +63,13 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <limits.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 #include <poll.h>
 
@@ -248,7 +250,7 @@ s_time_main(int argc, char **argv)
  double totalTime = 0.0;
  int nConn = 0;
  SSL *scon = NULL;
- time_t finishtime;
+ struct timespec finishtime, now;
  int ret = 1;
  char buf[1024 * 8];
  int ver;
@@ -330,10 +332,12 @@ s_time_main(int argc, char **argv)
  /* Loop and time how long it takes to make connections */
 
  bytes_read = 0;
- finishtime = time(NULL) + s_time_config.maxtime;
+ clock_gettime(CLOCK_MONOTONIC, &finishtime);
+ finishtime.tv_sec += s_time_config.maxtime;
  tm_Time_F(START);
  for (;;) {
- if (finishtime < time(NULL))
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (timespeccmp(&finishtime, &now, <))
  break;
  if ((scon = doConnection(NULL)) == NULL)
  goto end;
@@ -383,7 +387,7 @@ s_time_main(int argc, char **argv)
     nConn, totalTime, ((double) nConn / totalTime), bytes_read);
  printf("%d connections in %lld real seconds, %ld bytes read per connection\n",
     nConn,
-    (long long)(time(NULL) - finishtime + s_time_config.maxtime),
+    (long long)(now.tv_sec - finishtime.tv_sec + s_time_config.maxtime),
     bytes_read / nConn);
 
  /*
@@ -422,14 +426,16 @@ next:
  nConn = 0;
  totalTime = 0.0;
 
- finishtime = time(NULL) + s_time_config.maxtime;
+ clock_gettime(CLOCK_MONOTONIC, &finishtime);
+ finishtime.tv_sec += s_time_config.maxtime;
 
  printf("starting\n");
  bytes_read = 0;
  tm_Time_F(START);
 
  for (;;) {
- if (finishtime < time(NULL))
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (timespeccmp(&finishtime, &now, <))
  break;
  if ((doConnection(scon)) == NULL)
  goto end;
@@ -475,7 +481,7 @@ next:
  printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double) nConn / totalTime), bytes_read);
  printf("%d connections in %lld real seconds, %ld bytes read per connection\n",
     nConn,
-    (long long)(time(NULL) - finishtime + s_time_config.maxtime),
+    (long long)(now.tv_sec - finishtime.tv_sec + s_time_config.maxtime),
     bytes_read / nConn);
 
  ret = 0;

Reply | Threaded
Open this post in threaded view
|

Re: openssl s_time, speed: use monotime for absolute interval measurement

Jeremie Courreges-Anglas-2
On Wed, Nov 22 2017, Scott Cheloha <[hidden email]> wrote:
> Whoops, ignore that last patch, it lacked the
> static changes in apps_posix.c

This looks good to me.  I'm tempted to commit the apps_posix.c part
first: it seems to me that app_tminterval() could be reused in s_time.c,
leading to simpler code instead of inlining clock_gettime calls.

> --
> Scott Cheloha
>
> Index: usr.bin/openssl/apps_posix.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/openssl/apps_posix.c,v
> retrieving revision 1.2
> diff -u -p -r1.2 apps_posix.c
> --- usr.bin/openssl/apps_posix.c 13 Sep 2015 12:41:01 -0000 1.2
> +++ usr.bin/openssl/apps_posix.c 22 Nov 2017 16:39:42 -0000
> @@ -116,31 +116,48 @@
>   * Functions that need to be overridden by non-POSIX operating systems.
>   */
>  
> -#include <sys/times.h>
> +#include <sys/resource.h>
> +#include <sys/time.h>
>  
> -#include <unistd.h>
> +#include <time.h>
>  
>  #include "apps.h"
>  
> -double
> -app_tminterval(int stop, int usertime)
> +static double
> +real_interval(int stop)
>  {
> - double ret = 0;
> - struct tms rus;
> - clock_t now = times(&rus);
> - static clock_t tmstart;
> -
> - if (usertime)
> - now = rus.tms_utime;
> -
> - if (stop == TM_START)
> - tmstart = now;
> - else {
> - long int tck = sysconf(_SC_CLK_TCK);
> - ret = (now - tmstart) / (double) tck;
> + static struct timespec start;
> + struct timespec elapsed, now;
> +
> + clock_gettime(CLOCK_MONOTONIC, &now);
> + if (stop) {
> + timespecsub(&now, &start, &elapsed);
> + return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0;
>   }
> + start = now;
> + return 0.0;
> +}
>  
> - return (ret);
> +static double
> +user_interval(int stop)
> +{
> + static struct timeval start;
> + struct timeval elapsed;
> + struct rusage now;
> +
> + getrusage(RUSAGE_SELF, &now);
> + if (stop) {
> + timersub(&now.ru_utime, &start, &elapsed);
> + return elapsed.tv_sec + elapsed.tv_usec / 1000000.0;
> + }
> + start = now.ru_utime;
> + return 0.0;
> +}
> +
> +double
> +app_tminterval(int stop, int usertime)
> +{
> + return (usertime) ? user_interval(stop) : real_interval(stop);
>  }
>  
>  int
> Index: usr.bin/openssl/s_time.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/openssl/s_time.c,v
> retrieving revision 1.18
> diff -u -p -r1.18 s_time.c
> --- usr.bin/openssl/s_time.c 2 Nov 2017 00:31:49 -0000 1.18
> +++ usr.bin/openssl/s_time.c 22 Nov 2017 16:39:42 -0000
> @@ -63,11 +63,13 @@
>  
>  #include <sys/types.h>
>  #include <sys/socket.h>
> +#include <sys/time.h>
>  
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <limits.h>
>  #include <string.h>
> +#include <time.h>
>  #include <unistd.h>
>  #include <poll.h>
>  
> @@ -248,7 +250,7 @@ s_time_main(int argc, char **argv)
>   double totalTime = 0.0;
>   int nConn = 0;
>   SSL *scon = NULL;
> - time_t finishtime;
> + struct timespec finishtime, now;
>   int ret = 1;
>   char buf[1024 * 8];
>   int ver;
> @@ -330,10 +332,12 @@ s_time_main(int argc, char **argv)
>   /* Loop and time how long it takes to make connections */
>  
>   bytes_read = 0;
> - finishtime = time(NULL) + s_time_config.maxtime;
> + clock_gettime(CLOCK_MONOTONIC, &finishtime);
> + finishtime.tv_sec += s_time_config.maxtime;
>   tm_Time_F(START);
>   for (;;) {
> - if (finishtime < time(NULL))
> + clock_gettime(CLOCK_MONOTONIC, &now);
> + if (timespeccmp(&finishtime, &now, <))
>   break;
>   if ((scon = doConnection(NULL)) == NULL)
>   goto end;
> @@ -383,7 +387,7 @@ s_time_main(int argc, char **argv)
>      nConn, totalTime, ((double) nConn / totalTime), bytes_read);
>   printf("%d connections in %lld real seconds, %ld bytes read per connection\n",
>      nConn,
> -    (long long)(time(NULL) - finishtime + s_time_config.maxtime),
> +    (long long)(now.tv_sec - finishtime.tv_sec + s_time_config.maxtime),
>      bytes_read / nConn);
>  
>   /*
> @@ -422,14 +426,16 @@ next:
>   nConn = 0;
>   totalTime = 0.0;
>  
> - finishtime = time(NULL) + s_time_config.maxtime;
> + clock_gettime(CLOCK_MONOTONIC, &finishtime);
> + finishtime.tv_sec += s_time_config.maxtime;
>  
>   printf("starting\n");
>   bytes_read = 0;
>   tm_Time_F(START);
>  
>   for (;;) {
> - if (finishtime < time(NULL))
> + clock_gettime(CLOCK_MONOTONIC, &now);
> + if (timespeccmp(&finishtime, &now, <))
>   break;
>   if ((doConnection(scon)) == NULL)
>   goto end;
> @@ -475,7 +481,7 @@ next:
>   printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double) nConn / totalTime), bytes_read);
>   printf("%d connections in %lld real seconds, %ld bytes read per connection\n",
>      nConn,
> -    (long long)(time(NULL) - finishtime + s_time_config.maxtime),
> +    (long long)(now.tv_sec - finishtime.tv_sec + s_time_config.maxtime),
>      bytes_read / nConn);
>  
>   ret = 0;
>

--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply | Threaded
Open this post in threaded view
|

Re: openssl s_time, speed: use monotime for absolute interval measurement

Scott Cheloha
> On Nov 24, 2017, at 6:58 AM, Jeremie Courreges-Anglas <[hidden email]> wrote:
>
> On Wed, Nov 22 2017, Scott Cheloha <[hidden email]> wrote:
>> Whoops, ignore that last patch, it lacked the
>> static changes in apps_posix.c
>
> This looks good to me.  I'm tempted to commit the apps_posix.c part
> first: it seems to me that app_tminterval() could be reused in s_time.c,
> leading to simpler code instead of inlining clock_gettime calls.

I intend to refactor that module next.  One thing I was going to
do was abstract away the timer interface, so that works.

--
Scott Cheloha

Reply | Threaded
Open this post in threaded view
|

Re: openssl s_time, speed: use monotime for absolute interval measurement

Brent Cook
Thanks guys. This will make enabling this on the odder platforms in
portable easier.

On Fri, Nov 24, 2017 at 7:03 AM, Scott Cheloha <[hidden email]>
wrote:

> > On Nov 24, 2017, at 6:58 AM, Jeremie Courreges-Anglas <[hidden email]>
> wrote:
> >
> > On Wed, Nov 22 2017, Scott Cheloha <[hidden email]> wrote:
> >> Whoops, ignore that last patch, it lacked the
> >> static changes in apps_posix.c
> >
> > This looks good to me.  I'm tempted to commit the apps_posix.c part
> > first: it seems to me that app_tminterval() could be reused in s_time.c,
> > leading to simpler code instead of inlining clock_gettime calls.
>
> I intend to refactor that module next.  One thing I was going to
> do was abstract away the timer interface, so that works.
>
> --
> Scott Cheloha
>
>
Reply | Threaded
Open this post in threaded view
|

Re: openssl s_time, speed: use monotime for absolute interval measurement

Jeremie Courreges-Anglas-2
On Sat, Nov 25 2017, Brent Cook <[hidden email]> wrote:
> Thanks guys. This will make enabling this on the odder platforms in
> portable easier.

NB: if we want to able to mix app_tminterval() for real and user time, the
static storage used for "start" should be different.  This is not the
case for the Windows implementation, which *seems* to support only user
time:

  https://github.com/libressl-portable/portable/blob/master/apps/openssl/apps_win.c

Another approach, which would require more changes, would be to just
provide two seperate functions, possibly named app_timer_real() and
app_timer_user().  The Windows version of app_timer_real() could start
as a simple copy of app_timer_user(), marked with XXX...

> On Fri, Nov 24, 2017 at 7:03 AM, Scott Cheloha <[hidden email]>
> wrote:
>
>> > On Nov 24, 2017, at 6:58 AM, Jeremie Courreges-Anglas <[hidden email]>
>> wrote:
>> >
>> > On Wed, Nov 22 2017, Scott Cheloha <[hidden email]> wrote:
>> >> Whoops, ignore that last patch, it lacked the
>> >> static changes in apps_posix.c
>> >
>> > This looks good to me.  I'm tempted to commit the apps_posix.c part
>> > first: it seems to me that app_tminterval() could be reused in s_time.c,
>> > leading to simpler code instead of inlining clock_gettime calls.
>>
>> I intend to refactor that module next.  One thing I was going to
>> do was abstract away the timer interface, so that works.
>>
>> --
>> Scott Cheloha
>>
>>

--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply | Threaded
Open this post in threaded view
|

Re: openssl s_time, speed: use monotime for absolute interval measurement

Jeremie Courreges-Anglas-2
On Sun, Nov 26 2017, Jeremie Courreges-Anglas <[hidden email]> wrote:

> On Sat, Nov 25 2017, Brent Cook <[hidden email]> wrote:
>> Thanks guys. This will make enabling this on the odder platforms in
>> portable easier.
>
> NB: if we want to able to mix app_tminterval() for real and user time, the
> static storage used for "start" should be different.  This is not the
> case for the Windows implementation, which *seems* to support only user
> time:
>
>   https://github.com/libressl-portable/portable/blob/master/apps/openssl/apps_win.c
>
> Another approach, which would require more changes, would be to just
> provide two seperate functions, possibly named app_timer_real() and
> app_timer_user().  The Windows version of app_timer_real() could start
> as a simple copy of app_timer_user(), marked with XXX...

So here's a diff similar to what Scott proposed in his first diff.

The apps_win.c diff for portable would look like this
(untested):

  https://pbot.rmdir.de/sy3XxnKuTQHgotB35BJ6vQ

I resisted the temptation to make use of TM_START/TM_STOP instead of
local defines, this could be another TODO entry.  I don't like the
TM_START/TM_STOP names btw, TM_STOP doesn't actually stop the timer,
it's just a "get" operation.

Do you folks agree with this approach?


Index: apps.h
===================================================================
RCS file: /d/cvs/src/usr.bin/openssl/apps.h,v
retrieving revision 1.19
diff -u -p -r1.19 apps.h
--- apps.h 30 Aug 2016 14:34:59 -0000 1.19
+++ apps.h 26 Nov 2017 17:46:01 -0000
@@ -279,7 +279,8 @@ int app_isdir(const char *);
 
 #define TM_START 0
 #define TM_STOP 1
-double app_tminterval (int stop, int usertime);
+double app_timer_realtime(int stop);
+double app_timer_usertime(int stop);
 
 #define OPENSSL_NO_SSL_INTERN
 
Index: apps_posix.c
===================================================================
RCS file: /d/cvs/src/usr.bin/openssl/apps_posix.c,v
retrieving revision 1.3
diff -u -p -r1.3 apps_posix.c
--- apps_posix.c 24 Nov 2017 13:48:12 -0000 1.3
+++ apps_posix.c 26 Nov 2017 17:43:18 -0000
@@ -123,8 +123,8 @@
 
 #include "apps.h"
 
-static double
-real_interval(int stop)
+double
+app_timer_realtime(int stop)
 {
  static struct timespec start;
  struct timespec elapsed, now;
@@ -138,8 +138,8 @@ real_interval(int stop)
  return 0.0;
 }
 
-static double
-user_interval(int stop)
+double
+app_timer_usertime(int stop)
 {
  static struct timeval start;
  struct timeval elapsed;
@@ -152,12 +152,6 @@ user_interval(int stop)
  }
  start = now.ru_utime;
  return 0.0;
-}
-
-double
-app_tminterval(int stop, int usertime)
-{
- return (usertime) ? user_interval(stop) : real_interval(stop);
 }
 
 int
Index: s_time.c
===================================================================
RCS file: /d/cvs/src/usr.bin/openssl/s_time.c,v
retrieving revision 1.18
diff -u -p -r1.18 s_time.c
--- s_time.c 2 Nov 2017 00:31:49 -0000 1.18
+++ s_time.c 26 Nov 2017 17:40:54 -0000
@@ -233,9 +233,9 @@ s_time_usage(void)
 #define STOP 1
 
 static double
-tm_Time_F(int s)
+tm_Time_F(int op)
 {
- return app_tminterval(s, 1);
+ return app_timer_usertime(op);
 }
 
 /***********************************************************************
Index: speed.c
===================================================================
RCS file: /d/cvs/src/usr.bin/openssl/speed.c,v
retrieving revision 1.20
diff -u -p -r1.20 speed.c
--- speed.c 7 Oct 2017 06:16:54 -0000 1.20
+++ speed.c 26 Nov 2017 17:45:29 -0000
@@ -202,7 +202,10 @@ sig_done(int sig)
 static double
 Time_F(int s)
 {
- return app_tminterval(s, usertime);
+ if (usertime)
+ return app_timer_usertime(s);
+ else
+ return app_timer_realtime(s);
 }
 
 


--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply | Threaded
Open this post in threaded view
|

Re: openssl s_time, speed: use monotime for absolute interval measurement

Scott Cheloha
Hey,

Sorry for the delay.

On Sun, Nov 26, 2017 at 07:00:36PM +0100, Jeremie Courreges-Anglas wrote:

> On Sun, Nov 26 2017, Jeremie Courreges-Anglas <[hidden email]> wrote:
> > On Sat, Nov 25 2017, Brent Cook <[hidden email]> wrote:
> >> Thanks guys. This will make enabling this on the odder platforms in
> >> portable easier.
> >
> > NB: if we want to able to mix app_tminterval() for real and user time, the
> > static storage used for "start" should be different.  This is not the
> > case for the Windows implementation, which *seems* to support only user
> > time:
> >
> >   https://github.com/libressl-portable/portable/blob/master/apps/openssl/apps_win.c
> >
> > Another approach, which would require more changes, would be to just
> > provide two seperate functions, possibly named app_timer_real() and
> > app_timer_user().  The Windows version of app_timer_real() could start
> > as a simple copy of app_timer_user(), marked with XXX...
>
> So here's a diff similar to what Scott proposed in his first diff.
>
> The apps_win.c diff for portable would look like this
> (untested):
>
>   https://pbot.rmdir.de/sy3XxnKuTQHgotB35BJ6vQ

That looks fine to me, but I prefer the names you gave above,
"app_timer_real" and "app_timer_user".

> I resisted the temptation to make use of TM_START/TM_STOP instead of
> local defines, this could be another TODO entry.  I don't like the
> TM_START/TM_STOP names btw, TM_STOP doesn't actually stop the timer,
> it's just a "get" operation.

Agreed re. the operation names.  Can we call them TM_SET/TM_GET?
One does "set" a timer.

> Do you folks agree with this approach?

Assuming you feel the same way about what you wrote two weeks ago,
yeah I'm good with that.

I'll send a pull request with a mix of your changes and an
implementation for app_timer_user() on Windows to libressl-portable
today or tomorrow and reply here with the same.

A subsequent diff will expose the separate functions to the rest of
the modules via apps.h, and later diffs in, e.g., speed and s_time,
can make use of the now-distinct timer routines at their leisure.

--
Scott Cheloha

> Index: apps.h
> ===================================================================
> RCS file: /d/cvs/src/usr.bin/openssl/apps.h,v
> retrieving revision 1.19
> diff -u -p -r1.19 apps.h
> --- apps.h 30 Aug 2016 14:34:59 -0000 1.19
> +++ apps.h 26 Nov 2017 17:46:01 -0000
> @@ -279,7 +279,8 @@ int app_isdir(const char *);
>  
>  #define TM_START 0
>  #define TM_STOP 1
> -double app_tminterval (int stop, int usertime);
> +double app_timer_realtime(int stop);
> +double app_timer_usertime(int stop);
>  
>  #define OPENSSL_NO_SSL_INTERN
>  
> Index: apps_posix.c
> ===================================================================
> RCS file: /d/cvs/src/usr.bin/openssl/apps_posix.c,v
> retrieving revision 1.3
> diff -u -p -r1.3 apps_posix.c
> --- apps_posix.c 24 Nov 2017 13:48:12 -0000 1.3
> +++ apps_posix.c 26 Nov 2017 17:43:18 -0000
> @@ -123,8 +123,8 @@
>  
>  #include "apps.h"
>  
> -static double
> -real_interval(int stop)
> +double
> +app_timer_realtime(int stop)
>  {
>   static struct timespec start;
>   struct timespec elapsed, now;
> @@ -138,8 +138,8 @@ real_interval(int stop)
>   return 0.0;
>  }
>  
> -static double
> -user_interval(int stop)
> +double
> +app_timer_usertime(int stop)
>  {
>   static struct timeval start;
>   struct timeval elapsed;
> @@ -152,12 +152,6 @@ user_interval(int stop)
>   }
>   start = now.ru_utime;
>   return 0.0;
> -}
> -
> -double
> -app_tminterval(int stop, int usertime)
> -{
> - return (usertime) ? user_interval(stop) : real_interval(stop);
>  }
>  
>  int
> Index: s_time.c
> ===================================================================
> RCS file: /d/cvs/src/usr.bin/openssl/s_time.c,v
> retrieving revision 1.18
> diff -u -p -r1.18 s_time.c
> --- s_time.c 2 Nov 2017 00:31:49 -0000 1.18
> +++ s_time.c 26 Nov 2017 17:40:54 -0000
> @@ -233,9 +233,9 @@ s_time_usage(void)
>  #define STOP 1
>  
>  static double
> -tm_Time_F(int s)
> +tm_Time_F(int op)
>  {
> - return app_tminterval(s, 1);
> + return app_timer_usertime(op);
>  }
>  
>  /***********************************************************************
> Index: speed.c
> ===================================================================
> RCS file: /d/cvs/src/usr.bin/openssl/speed.c,v
> retrieving revision 1.20
> diff -u -p -r1.20 speed.c
> --- speed.c 7 Oct 2017 06:16:54 -0000 1.20
> +++ speed.c 26 Nov 2017 17:45:29 -0000
> @@ -202,7 +202,10 @@ sig_done(int sig)
>  static double
>  Time_F(int s)
>  {
> - return app_tminterval(s, usertime);
> + if (usertime)
> + return app_timer_usertime(s);
> + else
> + return app_timer_realtime(s);
>  }
>  
>  
>
>
> --
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply | Threaded
Open this post in threaded view
|

Re: openssl s_time, speed: use monotime for absolute interval measurement

Jeremie Courreges-Anglas-2
On Tue, Dec 05 2017, Scott Cheloha <[hidden email]> wrote:

> Hey,
>
> Sorry for the delay.
>
> On Sun, Nov 26, 2017 at 07:00:36PM +0100, Jeremie Courreges-Anglas wrote:
>> On Sun, Nov 26 2017, Jeremie Courreges-Anglas <[hidden email]> wrote:
>> > On Sat, Nov 25 2017, Brent Cook <[hidden email]> wrote:
>> >> Thanks guys. This will make enabling this on the odder platforms in
>> >> portable easier.
>> >
>> > NB: if we want to able to mix app_tminterval() for real and user time, the
>> > static storage used for "start" should be different.  This is not the
>> > case for the Windows implementation, which *seems* to support only user
>> > time:
>> >
>> >   https://github.com/libressl-portable/portable/blob/master/apps/openssl/apps_win.c
>> >
>> > Another approach, which would require more changes, would be to just
>> > provide two seperate functions, possibly named app_timer_real() and
>> > app_timer_user().  The Windows version of app_timer_real() could start
>> > as a simple copy of app_timer_user(), marked with XXX...
>>
>> So here's a diff similar to what Scott proposed in his first diff.
>>
>> The apps_win.c diff for portable would look like this
>> (untested):
>>
>>   https://pbot.rmdir.de/sy3XxnKuTQHgotB35BJ6vQ
>
> That looks fine to me, but I prefer the names you gave above,
> "app_timer_real" and "app_timer_user".

Fine with me.

>> I resisted the temptation to make use of TM_START/TM_STOP instead of
>> local defines, this could be another TODO entry.  I don't like the
>> TM_START/TM_STOP names btw, TM_STOP doesn't actually stop the timer,
>> it's just a "get" operation.
>
> Agreed re. the operation names.  Can we call them TM_SET/TM_GET?
> One does "set" a timer.

I'd suggest TM_RESET and TM_GET, "GET" and "SET" don't look very
different when reading the code.  Diff below.

>> Do you folks agree with this approach?
>
> Assuming you feel the same way about what you wrote two weeks ago,
> yeah I'm good with that.
>
> I'll send a pull request with a mix of your changes and an
> implementation for app_timer_user() on Windows to libressl-portable
> today or tomorrow and reply here with the same.
>
> A subsequent diff will expose the separate functions to the rest of
> the modules via apps.h, and later diffs in, e.g., speed and s_time,
> can make use of the now-distinct timer routines at their leisure.

I went ahead and committed the diff to make both functions available to
the cvs tree.  LibreSSL development happens in base, LibreSSL-portable
then uses that code, so you need only provide a patch for apps_win.c.
Maybe discuss this with Brent (cc'd).

With the diff below you should be able to focus on reusing
app_timer_user/real.

Thoughts?  oks?


Index: apps.h
===================================================================
--- apps.h.orig
+++ apps.h
@@ -277,8 +277,8 @@ unsigned char *next_protos_parse(unsigne
 
 int app_isdir(const char *);
 
-#define TM_START 0
-#define TM_STOP 1
+#define TM_RESET 0
+#define TM_GET 1
 double app_timer_real(int stop);
 double app_timer_user(int stop);
 
Index: apps_posix.c
===================================================================
--- apps_posix.c.orig
+++ apps_posix.c
@@ -124,13 +124,13 @@
 #include "apps.h"
 
 double
-app_timer_real(int stop)
+app_timer_real(int op)
 {
  static struct timespec start;
  struct timespec elapsed, now;
 
  clock_gettime(CLOCK_MONOTONIC, &now);
- if (stop) {
+ if (op == TM_GET) {
  timespecsub(&now, &start, &elapsed);
  return elapsed.tv_sec + elapsed.tv_nsec / 1000000000.0;
  }
@@ -139,14 +139,14 @@ app_timer_real(int stop)
 }
 
 double
-app_timer_user(int stop)
+app_timer_user(int op)
 {
  static struct timeval start;
  struct timeval elapsed;
  struct rusage now;
 
  getrusage(RUSAGE_SELF, &now);
- if (stop) {
+ if (op == TM_GET) {
  timersub(&now.ru_utime, &start, &elapsed);
  return elapsed.tv_sec + elapsed.tv_usec / 1000000.0;
  }
Index: s_time.c
===================================================================
--- s_time.c.orig
+++ s_time.c
@@ -229,9 +229,6 @@ s_time_usage(void)
 /***********************************************************************
  * TIME - time functions
  */
-#define START 0
-#define STOP 1
-
 static double
 tm_Time_F(int op)
 {
@@ -331,7 +328,7 @@ s_time_main(int argc, char **argv)
 
  bytes_read = 0;
  finishtime = time(NULL) + s_time_config.maxtime;
- tm_Time_F(START);
+ tm_Time_F(TM_RESET);
  for (;;) {
  if (finishtime < time(NULL))
  break;
@@ -377,7 +374,7 @@ s_time_main(int argc, char **argv)
  SSL_free(scon);
  scon = NULL;
  }
- totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
+ totalTime += tm_Time_F(TM_GET); /* Add the time for this iteration */
 
  printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n",
     nConn, totalTime, ((double) nConn / totalTime), bytes_read);
@@ -426,7 +423,7 @@ next:
 
  printf("starting\n");
  bytes_read = 0;
- tm_Time_F(START);
+ tm_Time_F(TM_RESET);
 
  for (;;) {
  if (finishtime < time(NULL))
@@ -470,7 +467,7 @@ next:
  fputc(ver, stdout);
  fflush(stdout);
  }
- totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
+ totalTime += tm_Time_F(TM_GET); /* Add the time for this iteration */
 
  printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double) nConn / totalTime), bytes_read);
  printf("%d connections in %lld real seconds, %ld bytes read per connection\n",
Index: speed.c
===================================================================
--- speed.c.orig
+++ speed.c
@@ -195,10 +195,6 @@ sig_done(int sig)
  run = 0;
 }
 
-#define START 0
-#define STOP 1
-
-
 static double
 Time_F(int s)
 {
@@ -1007,10 +1003,10 @@ speed_main(int argc, char **argv)
  if (doit[D_MD4]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
  EVP_Digest(&(buf[0]), (unsigned long) lengths[j], &(md4[0]), NULL, EVP_md4(), NULL);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_MD4, j, count, d);
  }
  }
@@ -1020,10 +1016,10 @@ speed_main(int argc, char **argv)
  if (doit[D_MD5]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
  EVP_Digest(&(buf[0]), (unsigned long) lengths[j], &(md5[0]), NULL, EVP_get_digestbyname("md5"), NULL);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_MD5, j, count, d);
  }
  }
@@ -1039,13 +1035,13 @@ speed_main(int argc, char **argv)
 
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
  HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
  HMAC_Update(&hctx, buf, lengths[j]);
  HMAC_Final(&hctx, &(hmac[0]), NULL);
  }
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_HMAC, j, count, d);
  }
  HMAC_CTX_cleanup(&hctx);
@@ -1055,10 +1051,10 @@ speed_main(int argc, char **argv)
  if (doit[D_SHA1]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
  EVP_Digest(buf, (unsigned long) lengths[j], &(sha[0]), NULL, EVP_sha1(), NULL);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_SHA1, j, count, d);
  }
  }
@@ -1066,10 +1062,10 @@ speed_main(int argc, char **argv)
  if (doit[D_SHA256]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
  SHA256(buf, lengths[j], sha256);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_SHA256, j, count, d);
  }
  }
@@ -1079,10 +1075,10 @@ speed_main(int argc, char **argv)
  if (doit[D_SHA512]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
  SHA512(buf, lengths[j], sha512);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_SHA512, j, count, d);
  }
  }
@@ -1093,10 +1089,10 @@ speed_main(int argc, char **argv)
  if (doit[D_WHIRLPOOL]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
  WHIRLPOOL(buf, lengths[j], whirlpool);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_WHIRLPOOL, j, count, d);
  }
  }
@@ -1106,10 +1102,10 @@ speed_main(int argc, char **argv)
  if (doit[D_RMD160]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
  EVP_Digest(buf, (unsigned long) lengths[j], &(rmd160[0]), NULL, EVP_ripemd160(), NULL);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_RMD160, j, count, d);
  }
  }
@@ -1118,11 +1114,11 @@ speed_main(int argc, char **argv)
  if (doit[D_RC4]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
  RC4(&rc4_ks, (unsigned int) lengths[j],
     buf, buf);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_RC4, j, count, d);
  }
  }
@@ -1131,23 +1127,23 @@ speed_main(int argc, char **argv)
  if (doit[D_CBC_DES]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
  DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
     &DES_iv, DES_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_CBC_DES, j, count, d);
  }
  }
  if (doit[D_EDE3_DES]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
  DES_ede3_cbc_encrypt(buf, buf, lengths[j],
     &sch, &sch2, &sch3,
     &DES_iv, DES_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_EDE3_DES, j, count, d);
  }
  }
@@ -1156,72 +1152,72 @@ speed_main(int argc, char **argv)
  if (doit[D_CBC_128_AES]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
  AES_cbc_encrypt(buf, buf,
     (unsigned long) lengths[j], &aes_ks1,
     iv, AES_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_CBC_128_AES, j, count, d);
  }
  }
  if (doit[D_CBC_192_AES]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
  AES_cbc_encrypt(buf, buf,
     (unsigned long) lengths[j], &aes_ks2,
     iv, AES_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_CBC_192_AES, j, count, d);
  }
  }
  if (doit[D_CBC_256_AES]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
  AES_cbc_encrypt(buf, buf,
     (unsigned long) lengths[j], &aes_ks3,
     iv, AES_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_CBC_256_AES, j, count, d);
  }
  }
  if (doit[D_IGE_128_AES]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
  AES_ige_encrypt(buf, buf2,
     (unsigned long) lengths[j], &aes_ks1,
     iv, AES_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_IGE_128_AES, j, count, d);
  }
  }
  if (doit[D_IGE_192_AES]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
  AES_ige_encrypt(buf, buf2,
     (unsigned long) lengths[j], &aes_ks2,
     iv, AES_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_IGE_192_AES, j, count, d);
  }
  }
  if (doit[D_IGE_256_AES]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
  AES_ige_encrypt(buf, buf2,
     (unsigned long) lengths[j], &aes_ks3,
     iv, AES_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_IGE_256_AES, j, count, d);
  }
  }
@@ -1231,10 +1227,10 @@ speed_main(int argc, char **argv)
 
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
  CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_GHASH, j, count, d);
  }
  CRYPTO_gcm128_release(ctx);
@@ -1251,11 +1247,11 @@ speed_main(int argc, char **argv)
 
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_AES_128_GCM],c[D_AES_128_GCM][j],lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_AES_128_GCM][j]); count++)
  EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
     nonce_len, buf, lengths[j], NULL, 0);
- d=Time_F(STOP);
+ d=Time_F(TM_GET);
  print_result(D_AES_128_GCM,j,count,d);
  }
  EVP_AEAD_CTX_cleanup(&ctx);
@@ -1273,11 +1269,11 @@ speed_main(int argc, char **argv)
 
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_AES_256_GCM],c[D_AES_256_GCM][j],lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_AES_256_GCM][j]); count++)
  EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
     nonce_len, buf, lengths[j], NULL, 0);
- d=Time_F(STOP);
+ d=Time_F(TM_GET);
  print_result(D_AES_256_GCM, j, count, d);
  }
  EVP_AEAD_CTX_cleanup(&ctx);
@@ -1297,11 +1293,11 @@ speed_main(int argc, char **argv)
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CHACHA20_POLY1305],
     c[D_CHACHA20_POLY1305][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CHACHA20_POLY1305][j]); count++)
  EVP_AEAD_CTX_seal(&ctx, buf, &buf_len, BUFSIZE, nonce,
     nonce_len, buf, lengths[j], NULL, 0);
- d=Time_F(STOP);
+ d=Time_F(TM_GET);
  print_result(D_CHACHA20_POLY1305, j, count, d);
  }
  EVP_AEAD_CTX_cleanup(&ctx);
@@ -1311,36 +1307,36 @@ speed_main(int argc, char **argv)
  if (doit[D_CBC_128_CML]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
  Camellia_cbc_encrypt(buf, buf,
     (unsigned long) lengths[j], &camellia_ks1,
     iv, CAMELLIA_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_CBC_128_CML, j, count, d);
  }
  }
  if (doit[D_CBC_192_CML]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
  Camellia_cbc_encrypt(buf, buf,
     (unsigned long) lengths[j], &camellia_ks2,
     iv, CAMELLIA_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_CBC_192_CML, j, count, d);
  }
  }
  if (doit[D_CBC_256_CML]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
  Camellia_cbc_encrypt(buf, buf,
     (unsigned long) lengths[j], &camellia_ks3,
     iv, CAMELLIA_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_CBC_256_CML, j, count, d);
  }
  }
@@ -1349,12 +1345,12 @@ speed_main(int argc, char **argv)
  if (doit[D_CBC_IDEA]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
  idea_cbc_encrypt(buf, buf,
     (unsigned long) lengths[j], &idea_ks,
     iv, IDEA_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_CBC_IDEA, j, count, d);
  }
  }
@@ -1363,12 +1359,12 @@ speed_main(int argc, char **argv)
  if (doit[D_CBC_RC2]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
  RC2_cbc_encrypt(buf, buf,
     (unsigned long) lengths[j], &rc2_ks,
     iv, RC2_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_CBC_RC2, j, count, d);
  }
  }
@@ -1377,12 +1373,12 @@ speed_main(int argc, char **argv)
  if (doit[D_CBC_BF]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
  BF_cbc_encrypt(buf, buf,
     (unsigned long) lengths[j], &bf_ks,
     iv, BF_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_CBC_BF, j, count, d);
  }
  }
@@ -1391,12 +1387,12 @@ speed_main(int argc, char **argv)
  if (doit[D_CBC_CAST]) {
  for (j = 0; j < SIZE_NUM; j++) {
  print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
  CAST_cbc_encrypt(buf, buf,
     (unsigned long) lengths[j], &cast_ks,
     iv, CAST_ENCRYPT);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  print_result(D_CBC_CAST, j, count, d);
  }
  }
@@ -1424,7 +1420,7 @@ speed_main(int argc, char **argv)
  EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
  EVP_CIPHER_CTX_set_padding(&ctx, 0);
 
- Time_F(START);
+ Time_F(TM_RESET);
  if (decrypt)
  for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
  EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
@@ -1435,7 +1431,7 @@ speed_main(int argc, char **argv)
  EVP_DecryptFinal_ex(&ctx, buf, &outl);
  else
  EVP_EncryptFinal_ex(&ctx, buf, &outl);
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  EVP_CIPHER_CTX_cleanup(&ctx);
  }
  if (evp_md) {
@@ -1443,11 +1439,11 @@ speed_main(int argc, char **argv)
  print_message(names[D_EVP], save_count,
     lengths[j]);
 
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++)
  EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
 
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  }
  print_result(D_EVP, j, count, d);
  }
@@ -1467,7 +1463,7 @@ speed_main(int argc, char **argv)
     rsa_c[j][0], rsa_bits[j],
     RSA_SECONDS);
 /* RSA_blinding_on(rsa_key[j],NULL); */
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
  ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
     &rsa_num, rsa_key[j]);
@@ -1479,7 +1475,7 @@ speed_main(int argc, char **argv)
  break;
  }
  }
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  BIO_printf(bio_err, mr ? "+R1:%ld:%d:%.2f\n"
     : "%ld %d bit private RSA's in %.2fs\n",
     count, rsa_bits[j], d);
@@ -1496,7 +1492,7 @@ speed_main(int argc, char **argv)
  pkey_print_message("public", "rsa",
     rsa_c[j][1], rsa_bits[j],
     RSA_SECONDS);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
  ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
     rsa_num, rsa_key[j]);
@@ -1508,7 +1504,7 @@ speed_main(int argc, char **argv)
  break;
  }
  }
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  BIO_printf(bio_err, mr ? "+R2:%ld:%d:%.2f\n"
     : "%ld %d bit public RSA's in %.2fs\n",
     count, rsa_bits[j], d);
@@ -1541,7 +1537,7 @@ speed_main(int argc, char **argv)
  pkey_print_message("sign", "dsa",
     dsa_c[j][0], dsa_bits[j],
     DSA_SECONDS);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
  ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2,
     &kk, dsa_key[j]);
@@ -1553,7 +1549,7 @@ speed_main(int argc, char **argv)
  break;
  }
  }
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  BIO_printf(bio_err, mr ? "+R3:%ld:%d:%.2f\n"
     : "%ld %d bit DSA signs in %.2fs\n",
     count, dsa_bits[j], d);
@@ -1571,7 +1567,7 @@ speed_main(int argc, char **argv)
  pkey_print_message("verify", "dsa",
     dsa_c[j][1], dsa_bits[j],
     DSA_SECONDS);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
  ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2,
     kk, dsa_key[j]);
@@ -1583,7 +1579,7 @@ speed_main(int argc, char **argv)
  break;
  }
  }
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  BIO_printf(bio_err, mr ? "+R4:%ld:%d:%.2f\n"
     : "%ld %d bit DSA verify in %.2fs\n",
     count, dsa_bits[j], d);
@@ -1624,7 +1620,7 @@ speed_main(int argc, char **argv)
     test_curves_bits[j],
     ECDSA_SECONDS);
 
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(ecdsa_c[j][0]);
     count++) {
  ret = ECDSA_sign(0, buf, 20,
@@ -1637,7 +1633,7 @@ speed_main(int argc, char **argv)
  break;
  }
  }
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
 
  BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
     "%ld %d bit ECDSA signs in %.2fs \n",
@@ -1658,7 +1654,7 @@ speed_main(int argc, char **argv)
     ecdsa_c[j][1],
     test_curves_bits[j],
     ECDSA_SECONDS);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
  ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
  if (ret != 1) {
@@ -1668,7 +1664,7 @@ speed_main(int argc, char **argv)
  break;
  }
  }
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  BIO_printf(bio_err, mr ? "+R6:%ld:%d:%.2f\n"
     : "%ld %d bit ECDSA verify in %.2fs\n",
     count, test_curves_bits[j], d);
@@ -1745,7 +1741,7 @@ speed_main(int argc, char **argv)
     ecdh_c[j][0],
     test_curves_bits[j],
     ECDH_SECONDS);
- Time_F(START);
+ Time_F(TM_RESET);
  for (count = 0, run = 1;
      COND(ecdh_c[j][0]); count++) {
  ECDH_compute_key(secret_a,
@@ -1753,7 +1749,7 @@ speed_main(int argc, char **argv)
     EC_KEY_get0_public_key(ecdh_b[j]),
     ecdh_a[j], kdf);
  }
- d = Time_F(STOP);
+ d = Time_F(TM_GET);
  BIO_printf(bio_err, mr
     ? "+R7:%ld:%d:%.2f\n"
     : "%ld %d-bit ECDH ops in %.2fs\n",


--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE