gettimeofday() revisited

Lex Spoon lex at cc.gatech.edu
Sun May 12 18:30:17 UTC 2002


Bergel Alexandre <bergel at iam.unibe.ch> wrote:
> > What makes you so sure that this is the result of calling gettimeofday()
> > repeatedly?! It could be _any_ system call, right?!
> 
> By using strace unix command.
> 
> -[-[-[-[-[-[-[-[-[-[-[-[
> $ strace bin/squeak image/myImage.image
> ...
> gettimeofday({1021179767, 195381}, NULL) = 0
> gettimeofday({1021179767, 195443}, NULL) = 0
> gettimeofday({1021179767, 195527}, NULL) = 0
> gettimeofday({1021179767, 195577}, NULL) = 0
> gettimeofday({1021179767, 195640}, NULL) = 0
> gettimeofday({1021179767, 195705}, NULL) = 0
> gettimeofday({1021179767, 195762}, NULL) = 0
> ...
> -]-]-]-]-]-]-]-]-]-]-]-]


No one thinks that calling the function more than necessary is a *good*
idea.  However, many of us think that it doesn't make much difference. 
There has been no good evidence provided to the contrary.

It has been established that there will be several thousand calls per
second to gettimeofday() in a normal setup.  However, it has also been
demonstrated that this can happen while CPU load is at 0.0% (ie, 0% to
the limits that top reports) on a not-that-awesome machine (I tried it
on a 1.3 Ghz Athlon).

Finally, let me provide some intuition.  While this is a large number of
calls, consider that the call is really fast.  All the OS does is copy
data from its data structures into Squeak's.


In summary, if anyone wants to get the itimers version working, then
they are welcome.   Especially, they should investigate an alternative
implementation for systems that don't have itimers available.  But it's
not actually very important in practice.  It would be much nicer, for
example, to be able to compile for either SDL or for XWindows from the
same codebase.  Or to have serial ports and sound supported on a wider
variety of systems.  Etc.


Oh, one last thing to consider: it is actually an OS flaw that
gettimeofday() is a system call at all.  Much better is to map a page
from the kernel into every process so that the current time can be
accessed with memory reads.  On OS's that do this (not Linux, but
probably others), then working around the implementation of
gettimeofday() is actually going to yield less precise time information
and worse CPU usage, in addition to having more complex code.  Thus,
it's not even completely clear that gettimeofday() is any worse than the
itimers implementation.


Lex



More information about the Squeak-dev mailing list