On Tue, Mar 06, 2012 at 01:01:57AM -0500, Woodchuck wrote:

> I.  The system call clock_getres(2) and clock_gettime(2) show strange
> results.
> 
> Consider this small program and its output on OpenBSD 5.0, amd64:
> 
> #include <stdio.h>
> #include <sys/time.h>
> 
> main()
> {
>         struct timespec tp;
>       int             i;
> 
>       clock_getres(CLOCK_REALTIME, &tp);
>       printf("Resolution:  %lu %lu\n", tp.tv_sec, tp.tv_nsec);
>       for (i = 0; i < 10; i++) {
>               clock_gettime(CLOCK_REALTIME, &tp);
>               printf("Performance: %lu %lu\n", tp.tv_sec, tp.tv_nsec);
>       }
>       return 0;
> }
> 
> Resolution:  0           10000000
> Performance: 1331012858 566149475
> Performance: 1331012858 566158834
> Performance: 1331012858 566164422
> Performance: 1331012858 566169031
> Performance: 1331012858 566173152
> Performance: 1331012858 566177202
> Performance: 1331012858 566181253
> Performance: 1331012858 566189075
> Performance: 1331012858 566195570
> Performance: 1331012858 566219945
> 
> Surely the clock is resolving better than 10 milliseconds?

Well, it gives values that suggest the resolution is better, but no
guarantee. It might bet that your clock is indeed better than stated.

> 
> II.  The man page asserts:
> 
> "clock_id can be one of four values: CLOCK_REALTIME for time that
> increments as a wall clock should, CLOCK_VIRTUAL for time ..."
> 
> How "should" a wall clock increment?  Differently from CLOCK_MONOTONIC?

Wall clock can be set forward (and backward depending on security
level). Monotonic always increments at a steady rate, independent of
the superuser setting the wall clock.


        -Otto
> 
> Thank you for your kind attention,
> 
> Dave

Reply via email to