From 2c1badeff23fe6c6bd1e5f8911b0afdfb005497c Mon Sep 17 00:00:00 2001 From: Raymond Toy <toy.raymond@gmail.com> Date: Wed, 8 Oct 2014 17:32:58 -0700 Subject: [PATCH] Fix issue with negative value for lisp::cycles-per-tick. This causes negative cpu cyles with TIME. Basic issue is that a cpu frequency of 2.3 GHZ won't fit in an int. Use an unsigned int. We also take this opportunity to use a rounded value for clocks-per-tick instead of truncating. For this particular case the ratio is actual 68.99 which would truncated to 68. We should probably use 69 instead. --- src/lisp/Darwin-os.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lisp/Darwin-os.c b/src/lisp/Darwin-os.c index 5e8ddf98f..1f67b685f 100644 --- a/src/lisp/Darwin-os.c +++ b/src/lisp/Darwin-os.c @@ -66,8 +66,8 @@ void timebase_init(void) { int mib[2]; - int tbfrequency; - int cpufrequency; + unsigned tbfrequency; + unsigned cpufrequency; unsigned int miblen; size_t len; @@ -95,7 +95,7 @@ timebase_init(void) perror("Error getting HW_CPU_FREQ from sysctl: "); } - cycles_per_tick = cpufrequency / tbfrequency; + cycles_per_tick = 0.5 + (cpufrequency / (double) tbfrequency); } #endif -- GitLab