From 535f2737b1538210e92eb185dcd58488148f62cb Mon Sep 17 00:00:00 2001 From: Arthur Maciel Date: Fri, 5 Mar 2021 22:57:33 -0300 Subject: [PATCH] Cleaned-up timing code --- runtime.c | 8 ++++---- scheme/time.sld | 15 --------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/runtime.c b/runtime.c index 705bfc08..c80a64b7 100644 --- a/runtime.c +++ b/runtime.c @@ -96,12 +96,12 @@ void Cyc_check_bounds(void *data, const char *label, int len, int index) #ifdef CYC_HIGH_RES_TIMERS /* High resolution timers */ -#include +#include long long hrt_get_current() { - struct timeval tv; - gettimeofday(&tv, NULL); /* TODO: longer-term consider using clock_gettime instead */ - long long jiffy = (tv.tv_sec)*1000000LL + tv.tv_usec; + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + long long jiffy = (now.tv_sec)*1000000LL + now.tv_nsec/1000; // nano->microseconds return jiffy; } diff --git a/scheme/time.sld b/scheme/time.sld index 4ad54128..1c1230aa 100644 --- a/scheme/time.sld +++ b/scheme/time.sld @@ -26,21 +26,6 @@ make_double(box, 0.0); clock_gettime(CLOCK_MONOTONIC, &now); long long jiffy = (now.tv_sec)*1000000LL + now.tv_nsec/1000; // nano->microseconds - /* Future consideration: - mp_int bn_tmp, bn_tmp2, bn_tmp3; - mp_init(&bn_tmp); - mp_init(&bn_tmp2); - mp_init(&bn_tmp3); - Cyc_int2bignum(tv.tv_sec, &bn_tmp); - Cyc_int2bignum(1000000LL, &bn_tmp2); - Cyc_int2bignum(tv.tv_usec, &bn_tmp3); - alloc_bignum(data, box); - mp_mul(&bn_tmp, &bn_tmp2, &bn_tmp); - mp_add(&bn_tmp, &bn_tmp3, &bignum_value(box)); - mp_clear(&bn_tmp); - mp_clear(&bn_tmp2); - mp_clear(&bn_tmp3); - */ double_value(&box) = jiffy; return_closcall1(data, k, &box); ") (define-c jiffies-per-second