C9x <time.h> and clock precision
Markus.Kuhn at cl.cam.ac.uk
Wed Oct 7 10:35:13 UTC 1998
Paul Eggert wrote on 1998-10-07 09:01 UTC:
> you will never want to use anything like xtime_get() itself as a
> source of sub-nanosecond timing information.
> I'm not sure that I agree with the ``never'', as clocks will keep
> getting better and better, and eventually (I hope within my lifetime
> :-) places outside the PTB will break the 1ns barrier. And I would
> like the spec to be modified so that xtime_get(TIME_MONOTONIC) can be
> compiled to a single instruction accessing the hardware clock
> register directly, which will make sub-ns access more practical.
Don't forget that the old clock_t clock(void); is still available
and can be used to provide direct access to the internal bus cycle
counter. The xtime interface is intended for timestamps that have been
converted to the SI second scale. Raw hardware clock counter values
are outside its scope and are already supported by C89.
So no need to change the proposal here. Just make in your implementation
clock_t a 64-bit type, clock() a macro with inline assembler code to read
the counter, and CLOCKS_PER_SEC a global variable that contains the
current clock frequency.
Markus G. Kuhn, Security Group, Computer Lab, Cambridge University, UK
email: mkuhn at acm.org, home page: <http://www.cl.cam.ac.uk/~mgk25/>
More information about the tz