Timestamp in PowerPC 440

Jenkins, Clive Clive.Jenkins at xerox.com
Mon Jul 26 21:02:59 EST 2010


> I have ported Linux 2.6 to PowerPC 440. Could you tell me
> how it is possible to access the timebase register (TBU, TBL)
> from user space (in Linux) because I want to measure the time
> of an application that runs in Linux?

I just grabbed this code from the kernel (you can put the macro
expansions into the function if you like):

typedef unsigned long long u64;

#define mftbl() ({unsigned long rval; \
 asm volatile("mftbl %0" : "=r" (rval)); rval;})
#define mftbu() ({unsigned long rval; \
 asm volatile("mftbu %0" : "=r" (rval)); rval;})

static inline u64 get_tb(void)
{
	unsigned int tbhi, tblo, tbhi2;
	do {
		tbhi = get_tbu();
		tblo = get_tbl();
		tbhi2 = get_tbu();
	} while (tbhi != tbhi2);
	return ((u64)tbhi << 32) | tblo;
}

The timebase frequency is available in text form from
/proc/cpuinfo and in binary (as a 4-byte bigendian
integer)from /proc/device-tree/...

grep timebase /proc/cpuinfo

find /proc/device-tree -name timebase-frequency -print \
 -exec od -td -An '{}' \;

Clive


More information about the Linuxppc-dev mailing list