Continual reading from the PowerPc time base register is not stable

Chris Friesen cfriesen at nortel.com
Fri Mar 26 09:00:54 EST 2010


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


More information about the Linuxppc-dev mailing list