Subject: Re: Continual reading from the PowerPc time base register is not stable

From: "Chris Friesen" <[email-masked]>
Date: Thu, 25 Mar 2010 16:00:54 -0600

On 03/25/2010 09:00 AM, Csdncannon wrote:
> I am really sorry that the previously attached code is wrong, this one
> "timebase.c" is the right one, and the "log_timebase" file is the right log.
> 
> We are using FreeScale PowerPc 8378, kernel 2.6.28 and compiled as 32-bit.

volatile unsigned long long getTimeBase()
{
	unsigned long upper,lower,upper2;
	do {
		asm volatile("sync; isync":::"memory");
		asm volatile("mftbu %0" : "=r" (upper));
		asm volatile("sync; isync":::"memory");
		asm volatile("mftbl %0" : "=r" (lower));
		asm volatile("sync; isync":::"memory");
		asm volatile("mftbu %0" : "=r" (upper2));
		asm volatile("sync; isync":::"memory");
	}while(upper2!=upper);

	return (upper<<32)|lower;
}

Shouldn't "upper" be cast to 64-bit before shifting?

Chris