Re: Monotonic clock

"David McClain (as dbm at refined-audiometrics dot com)" <[email protected]>
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
I could be mistaken, but from my reading of the Apple docs, it appears that he has the ratio upside down:

https://github.com/Shinmera/precise-time/blob/main/darwin.lisp
precise-time/darwin.lisp at main · Shinmera/precise-time
github.com


(define-constant MONOTONIC-TIME-UNITS-PER-SECOND
    (cffi:with-foreign-objects ((tb :uint32 2))
      (if (= 0 (cffi:foreign-funcall "mach_timebase_info" :pointer tb :int))
          (let ((ticks-to-nanos (/ (cffi:mem-aref tb :uint32 1) (cffi:mem-aref tb :uint32 0))))
            (floor (* 1000000000 ticks-to-nanos)))
          (error "Failed to get time scale for monotonic time."))))

On my M1 iMac, mach_timebase_info returns the ratio 125/3. info numerator is at index 0, and denominator is at index 1.



> On Oct 9, 2025, at 07:39, Yacin Nadji (as yacin at defmacro dot cc) <[email protected]> wrote:
> 
>> On Oct 9, 2025, at 5:11 AM, Eugene Zaikonnikov (as ez at norphonic dot com) <[email protected]> wrote:
>> 
>> Hello,
>> 
>> Just wonder before I do it with FFI, is there already any support for
>> reading monotonic clock? Or perhaps a library that covers LispWorks too?
> 
> isn’t that what get-internal-real-time does or am i mistaken? if i am or you want a library and more precision maybe check out shinmera’s precise time <https://shinmera.github.io/precise-time/> library. 
> 
> cheers
> 
> yacin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.