summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjca <jca@openbsd.org>2017-11-24 13:48:12 +0000
committerjca <jca@openbsd.org>2017-11-24 13:48:12 +0000
commita08a5a782930f8f49624015f0927ef344fba7687 (patch)
tree3df6450959dffb259dcda0b8f6bb2345c1e956fb
parentrework transmit to get rid of ifq_deq_begin, and to improve speed. (diff)
downloadwireguard-openbsd-a08a5a782930f8f49624015f0927ef344fba7687.tar.xz
wireguard-openbsd-a08a5a782930f8f49624015f0927ef344fba7687.zip
Use clock_gettime and getrusage to compute real and user time.
Better handling of clock jumps, from Scott Cheloa.
-rw-r--r--usr.bin/openssl/apps_posix.c49
1 files changed, 33 insertions, 16 deletions
diff --git a/usr.bin/openssl/apps_posix.c b/usr.bin/openssl/apps_posix.c
index 67cd465088e..94c6d35f714 100644
--- a/usr.bin/openssl/apps_posix.c
+++ b/usr.bin/openssl/apps_posix.c
@@ -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;
+ 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;
+}
- if (usertime)
- now = rus.tms_utime;
+static double
+user_interval(int stop)
+{
+ static struct timeval start;
+ struct timeval elapsed;
+ struct rusage now;
- if (stop == TM_START)
- tmstart = now;
- else {
- long int tck = sysconf(_SC_CLK_TCK);
- ret = (now - tmstart) / (double) tck;
+ 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;
+}
- return (ret);
+double
+app_tminterval(int stop, int usertime)
+{
+ return (usertime) ? user_interval(stop) : real_interval(stop);
}
int