gettimeofday() and gethrtime() on Solaris x86

gettimeofday() and gethrtime() on Solaris x86

Post by r.. » Thu, 06 Jul 2000 04:00:00



I did a couple of quick experiments and it appears that on Solaris 7 x86
both gettimeofday() and gethrtime() return times that step by 10 ms.
I just tried the same experiment on Solaris 8 (on a different machine,
alas) and the times seem to increment by 1 ms or maybe even smaller.

Does anyone have experience with this on Solaris 7 or 8 and any insight
into whether Sun actually made changes in Solaris 8 on Intel to give
higher precision?  I don't have any current vintage SPARC hardware to
try the same experiment (a 40 line C program).

BTW, it appears that you can mess with hires_tick in /etc/system (eg.
set it to 1 for ms resolution), but I've not tried that for fear of
burning up all my CPU time servicing clock interrupts.

There is an interesting white paper at
http://www.sun.com/software/white-papers/wp-realtime/, which briefly
mentions high precision timing, although the paper is fuzzy on the
changes for Solaris x86.  It also implies that the gettimeofday() and
gethrtime() calls have the same precision as before, and that to get
higher precision one needs to use the CLOCK_HIGHRES timer (only as
root).

What I noticed is that Solaris 8 x86 appears to have higher precision
out of the box and I'd like to see somewhere written down (I believe
everything I read!) stating that clearly.  I'm not sure it is dependent
upon actual CPU (PIII vs PII vs Celeron for example), but if so, I'd
like to know the particular CPU required.

Thanks,
Ron

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

gettimeofday() and gethrtime() on Solaris x86

Post by Joachim Worringe » Thu, 06 Jul 2000 04:00:00



> I did a couple of quick experiments and it appears that on Solaris 7 x86
> both gettimeofday() and gethrtime() return times that step by 10 ms.
> I just tried the same experiment on Solaris 8 (on a different machine,
> alas) and the times seem to increment by 1 ms or maybe even smaller.

My experience (Solaris 7 x86) shows that both calls have a much higher
resolution, which for gethrtime() is about 1us. The overhead in
gettimeofday() is higher, but I'm sure the resolution it better than
1ms, too.

On x86-systems, you can use the following macro (gcc syntax - anyone can
offer a Sun cc version?) to have the probably fastest and most precise
time measurement by reading a CPU internal 64bit counter (thus, 't' must
be of type 'longlong'). It returns the number of clock cycles (ticks)
since some point in the past. Beware of overflows - but they occur quite
seldom...

#define GETTICKS(t) asm volatile ("push %%esi\n\t" "mov %0, %%esi" : :
"r" (t)); \
                    asm volatile ("push %eax\n\t" "push %edx"); \
                    asm volatile ("rdtsc"); \
                    asm volatile ("movl %eax, (%esi)\n\t" "movl %edx,
4(%esi)"); \
                    asm volatile ("pop %edx\n\t" "pop %eax\n\t" "pop
%esi");

regards, Joachim

--
|  _      |  Joachim Worringen
|_|_`__   |  Lehrstuhl fuer Betriebssysteme, RWTH Aachen
  | |__)  |  http://www.lfbs.rwth-aachen.de/~joachim


 
 
 

gettimeofday() and gethrtime() on Solaris x86

Post by Casper H.S. Dik - Network Security Engine » Thu, 06 Jul 2000 04:00:00


[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


>I did a couple of quick experiments and it appears that on Solaris 7 x86
>both gettimeofday() and gethrtime() return times that step by 10 ms.
>I just tried the same experiment on Solaris 8 (on a different machine,
>alas) and the times seem to increment by 1 ms or maybe even smaller.

This depends on a cpu/device register which can be used  to interpolate
time between clockticks; available on SPARC since the SS1 or SS1+.

Perhaps not supported on all x86 PCs and eprhaps not until Solaris 8.

Quote:>BTW, it appears that you can mess with hires_tick in /etc/system (eg.
>set it to 1 for ms resolution), but I've not tried that for fear of
>burning up all my CPU time servicing clock interrupts.

Considering that 100Hz has been used from day 1 (with <10MHz clocks),
current x00 MHz systems shoudl have noproblem servicing 10 times
the number of clock interrupts.

Quote:>There is an interesting white paper at
>http://www.sun.com/software/white-papers/wp-realtime/, which briefly
>mentions high precision timing, although the paper is fuzzy on the
>changes for Solaris x86.  It also implies that the gettimeofday() and
>gethrtime() calls have the same precision as before, and that to get
>higher precision one needs to use the CLOCK_HIGHRES timer (only as
>root).
>What I noticed is that Solaris 8 x86 appears to have higher precision
>out of the box and I'd like to see somewhere written down (I believe
>everything I read!) stating that clearly.  I'm not sure it is dependent
>upon actual CPU (PIII vs PII vs Celeron for example), but if so, I'd
>like to know the particular CPU required.

I'd have to check on the actual implementation details.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

gettimeofday() and gethrtime() on Solaris x86

Post by Bruce Adle » Thu, 06 Jul 2000 04:00:00




> > I did a couple of quick experiments and it appears that on Solaris 7 x86
> > both gettimeofday() and gethrtime() return times that step by 10 ms.
> > I just tried the same experiment on Solaris 8 (on a different machine,
> > alas) and the times seem to increment by 1 ms or maybe even smaller.

> My experience (Solaris 7 x86) shows that both calls have a much higher
> resolution, which for gethrtime() is about 1us. The overhead in
> gettimeofday() is higher, but I'm sure the resolution it better than
> 1ms, too.

You're confusing resolution and quantization/granularity and accuracy.
They're not the same. The resolution is fixed and specified by the man
page for each function. The quantization/granularity of the actual
values returned is variable and differs on different platforms, different
releases, and/or can be modified on the fly by changing system parameters.
The amount of overhead in any function varies dynamically and is
determined by the instantaneous schedular overhead and/or dispatch
latency. High system loads and/or long latencies affect the accuracy of
the returned values but not the resolution or quantization.
 
 
 

gettimeofday() and gethrtime() on Solaris x86

Post by Joachim Worringe » Fri, 07 Jul 2000 04:00:00




> > My experience (Solaris 7 x86) shows that both calls have a much higher
> > resolution, which for gethrtime() is about 1us. The overhead in
> > gettimeofday() is higher, but I'm sure the resolution it better than
> > 1ms, too.

> You're confusing resolution and quantization/granularity and accuracy.
> They're not the same. The resolution is fixed and specified by the man
> page for each function. The quantization/granularity of the actual
> values returned is variable and differs on different platforms, different
> releases, and/or can be modified on the fly by changing system parameters.
> The amount of overhead in any function varies dynamically and is
> determined by the instantaneous schedular overhead and/or dispatch
> latency. High system loads and/or long latencies affect the accuracy of
> the returned values but not the resolution or quantization.

You are right - but where's the conclusion? What the user wants is the
most exakt way of measuring a period of time. This means lowest overhead
and highest resolution possible, resulting in highest accuracy. For this
reason, the assember macro (for x86, should be possible for Sparc, too)
is the optimum solution. And there we are.

And why do you think that the scheduling/dispatch overhead of the OS
does influence the measurement? The process is scheduled when he issues
the call, thus the scheduler has nothing to do with it. Of course, if
you take wall clock time (CPU cycles), you must be aware that the
process might have been descheduled between two calls. But for
high-resolution, short-period measurements, this should rarely happen.

BTW, nor the man page for gethrtime() neither the man page for
gettimeofday() specify the quantization - both state that it is
hardware-dependent. And if you don't know the quantization, the given
"resolution" is of no practical value - it just helps you to convert the
given value to seconds (or whatever).

 Joachim

--
|  _      |  Joachim Worringen
|_|_`__   |  Lehrstuhl fuer Betriebssysteme, RWTH Aachen
  | |__)  |  http://www.lfbs.rwth-aachen.de/~joachim