* MPC8xx: resolution of gettimeofday() ?
@ 2006-05-18 15:10 Steven Scholz
  2006-05-18 16:48 ` Eugene Surovegin
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Scholz @ 2006-05-18 15:10 UTC (permalink / raw)
  To: linuxppc-embedded
Hi all,
what is the resolution of gettimeofday() for an MPC8xx?
IIUC then the "decrementer" is used to generate the timer interrupts every 10ms.
This decrementer runs at cpuclk/16. Thus with 80MHz CPU clock has a
resolution of 16/80MHz = 200ns and overflows every 50000 ticks.
But is this decrementer used to update xtime?
Will gettimeofday() have a resolution of 200ns?
How about linux 2.4 where xtime is a "struct timeval" rather then "struct
timespec"?
This trivial test programm
	struct timeval first, next;
	double diff;
	gettimeofday(&first, NULL);
	do {
		gettimeofday(&next, NULL);
	} while (first.tv_usec == next.tv_usec &&
		 first.tv_sec == next.tv_sec);
	diff  = ((double)  next.tv_sec - (double) first.tv_sec) * 1e6;
	diff +=  (double) (next.tv_usec - first.tv_usec);
	printf ("Resolution gettimeofday() = %g µs\n", diff);
says it's between 13 - 16 µs on a linux-2.4.20. Could that be? how does this
relate to the decrementer frequency?
Thanks a million!
--
Steven
^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: MPC8xx: resolution of gettimeofday() ?
  2006-05-18 15:10 MPC8xx: resolution of gettimeofday() ? Steven Scholz
@ 2006-05-18 16:48 ` Eugene Surovegin
  2006-05-19  8:08   ` Steven Scholz
  0 siblings, 1 reply; 5+ messages in thread
From: Eugene Surovegin @ 2006-05-18 16:48 UTC (permalink / raw)
  To: Steven Scholz; +Cc: linuxppc-embedded
On Thu, May 18, 2006 at 05:10:40PM +0200, Steven Scholz wrote:
> Hi all,
> 
> what is the resolution of gettimeofday() for an MPC8xx?
> 
> IIUC then the "decrementer" is used to generate the timer interrupts every 10ms.
> 
> This decrementer runs at cpuclk/16. Thus with 80MHz CPU clock has a
> resolution of 16/80MHz = 200ns and overflows every 50000 ticks.
> 
> But is this decrementer used to update xtime?
> Will gettimeofday() have a resolution of 200ns?
> 
> How about linux 2.4 where xtime is a "struct timeval" rather then "struct
> timespec"?
> 
> This trivial test programm
> 
> 	struct timeval first, next;
> 	double diff;
> 
> 	gettimeofday(&first, NULL);
> 	do {
> 		gettimeofday(&next, NULL);
> 	} while (first.tv_usec == next.tv_usec &&
> 		 first.tv_sec == next.tv_sec);
> 
> 	diff  = ((double)  next.tv_sec - (double) first.tv_sec) * 1e6;
> 	diff +=  (double) (next.tv_usec - first.tv_usec);
> 
> 	printf ("Resolution gettimeofday() = %g ?s\n", diff);
> 
> says it's between 13 - 16 ?s on a linux-2.4.20. Could that be? how does this
> relate to the decrementer frequency?
Usually on PPC we use timebase to interpolate time between Decrementer 
interrupts. In this case gettimeofday resolution is determined by 
timebase resolution which is quite high (megahertz range).
-- 
Eugene
^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: MPC8xx: resolution of gettimeofday() ?
  2006-05-18 16:48 ` Eugene Surovegin
@ 2006-05-19  8:08   ` Steven Scholz
  2006-05-19 17:55     ` Eugene Surovegin
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Scholz @ 2006-05-19  8:08 UTC (permalink / raw)
  To: linuxppc-embedded
Eugene,
>> what is the resolution of gettimeofday() for an MPC8xx?
>>
>> IIUC then the "decrementer" is used to generate the timer interrupts every 10ms.
>>
>> This decrementer runs at cpuclk/16. Thus with 80MHz CPU clock has a
>> resolution of 16/80MHz = 200ns and overflows every 50000 ticks.
>>
>> But is this decrementer used to update xtime?
>> Will gettimeofday() have a resolution of 200ns?
>>
>> How about linux 2.4 where xtime is a "struct timeval" rather then "struct
>> timespec"?
>>
> 
> Usually on PPC we use timebase to interpolate time between Decrementer 
> interrupts. In this case gettimeofday resolution is determined by 
> timebase resolution which is quite high (megahertz range).
Sorry. I don't understand. What do you mean with "timebase"? Is there a
second timer/counter?
-- 
Steven
^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: MPC8xx: resolution of gettimeofday() ?
  2006-05-19  8:08   ` Steven Scholz
@ 2006-05-19 17:55     ` Eugene Surovegin
  2006-05-22 11:03       ` Steven Scholz
  0 siblings, 1 reply; 5+ messages in thread
From: Eugene Surovegin @ 2006-05-19 17:55 UTC (permalink / raw)
  To: Steven Scholz; +Cc: linuxppc-embedded
On Fri, May 19, 2006 at 10:08:26AM +0200, Steven Scholz wrote:
> Eugene,
> 
> >> what is the resolution of gettimeofday() for an MPC8xx?
> >>
> >> IIUC then the "decrementer" is used to generate the timer interrupts every 10ms.
> >>
> >> This decrementer runs at cpuclk/16. Thus with 80MHz CPU clock has a
> >> resolution of 16/80MHz = 200ns and overflows every 50000 ticks.
> >>
> >> But is this decrementer used to update xtime?
> >> Will gettimeofday() have a resolution of 200ns?
> >>
> >> How about linux 2.4 where xtime is a "struct timeval" rather then "struct
> >> timespec"?
> >>
> > 
> > Usually on PPC we use timebase to interpolate time between Decrementer 
> > interrupts. In this case gettimeofday resolution is determined by 
> > timebase resolution which is quite high (megahertz range).
> 
> Sorry. I don't understand. What do you mean with "timebase"? Is there a
> second timer/counter?
PowerPC has a facility called timebase. This is 64-bit counter which 
can be accessed using special instructions (mftb, mftbu on 32-bit PPC).
Counter resolution depends on particular chip implementation, some 
use core clock, other use bus clock...
It's similar to the time-stamp counter in Intel CPUs (accessed 
with rdtsc instruction).
Please, refer to PPC arch manuals for more information. Also, if you 
really interested in how gettimeofday() is implemented, why don't you 
look at the source code yourself?
-- 
Eugene
^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: MPC8xx: resolution of gettimeofday() ?
  2006-05-19 17:55     ` Eugene Surovegin
@ 2006-05-22 11:03       ` Steven Scholz
  0 siblings, 0 replies; 5+ messages in thread
From: Steven Scholz @ 2006-05-22 11:03 UTC (permalink / raw)
  To: linuxppc-embedded
Eugene,
>>> Usually on PPC we use timebase to interpolate time between Decrementer 
>>> interrupts. In this case gettimeofday resolution is determined by 
>>> timebase resolution which is quite high (megahertz range).
>> Sorry. I don't understand. What do you mean with "timebase"? Is there a
>> second timer/counter?
> 
> PowerPC has a facility called timebase. This is 64-bit counter which 
> can be accessed using special instructions (mftb, mftbu on 32-bit PPC).
> Counter resolution depends on particular chip implementation, some 
> use core clock, other use bus clock...
> 
> It's similar to the time-stamp counter in Intel CPUs (accessed 
> with rdtsc instruction).
Thanks very much for clearing this!
> Please, refer to PPC arch manuals for more information. Also, if you 
> really interested in how gettimeofday() is implemented, why don't you 
> look at the source code yourself?
I tried. But it's not obvious. Not for me anyway.
-- 
Steven
^ permalink raw reply	[flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-05-22 11:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-18 15:10 MPC8xx: resolution of gettimeofday() ? Steven Scholz
2006-05-18 16:48 ` Eugene Surovegin
2006-05-19  8:08   ` Steven Scholz
2006-05-19 17:55     ` Eugene Surovegin
2006-05-22 11:03       ` Steven Scholz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).