Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Nov 1995 12:37:26 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        Andres.Vega_Garcia@sophia.inria.fr, julian@ref.tfs.com
Cc:        hackers@FreeBSD.ORG
Subject:   Re: Notion of time in kernel + malloc
Message-ID:  <199511210137.MAA19964@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>the  variable structure (struct timeval) time;
>can be examined directly to give time to the nearest 'tick' (100hz usually)

It shouldn't be examined directly since direct access is not atomic.  You
must use

	int s = splclock();
	struct timeval temp_tv = time;
	splx(s);

>however, calling the "microtime()" function
>(in /sys/i386/i386/microtime.s) will give you the value in 'time'
>updated to the nearest microsecond (within a certain error or course)
>where just reading 'time' will give you the last time that
>variable was updated..

microtime() is more accurate and slower.  `time' is updated every 10 ms.
Thus `time' will be 0-10 ms behind the time given by microtime().

>using "microtime()" has of course the problem that it uses more cpu time..
>On a pentium, microtime uses the pentium's Usec timer and is a lot quicker..

On a pentium, microtime uses the pentium's cycle counter and is a lot
quicker than microtime on a non-pentium and a bit slower than directly
accessing `time'.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199511210137.MAA19964>