Global Time Stamp Code


sweetlilmre

Member
Joined
Jan 14, 2006
Messages
92
Hi,

I have been working on the Beagleboard (as a temporary Pandora target) trying to port LinuxSampler. I've got all the OE bitbake files up and running, various patches for GCC4.3 etc. but have run into a platform specific porting issue.

The code requires a function to return a (I am assuming highly accurate) time stamp, the code is below.
Do any of the gurus around here have a suggestion on how to implement this for the Beagle / Pandora?

CODE

/*
* Creates a real time stamp for the current moment. Out of efficiency this
* is implemented in inline assembly for each CPU independently; we currently
* don't use a generic solution for CPUs that are not yet covered by the
* assembly code, instead an error message is prompted on compile time, forcing
* the user to contact us.
*/
RTMathBase::time_stamp_t RTMathBase::CreateTimeStamp() {
#if defined(__i386__) || defined(__x86_64__)
uint64_t t;
__asm__ __volatile__ ("rdtsc" : "=A" (t));
return t >> 8;
#elif defined(__ia64__)
time_stamp_t t;
__asm__ __volatile__ ("mov %0=ar.itc" : "=r"(t));
return t;
#elif defined(__powerpc__)
time_stamp_t t;
__asm__ __volatile__ (
"98: mftb %0\n"
"99:\n"
".section __ftr_fixup,\"a\"\n"
" .long %1\n"
" .long 0\n"
" .long 98b\n"
" .long 99b\n"
".previous"
: "=r" (t) : "i" (0x00000100)
);
return t;
#elif defined(__alpha__)
time_stamp_t t;
__asm__ __volatile__ ("rpcc %0" : "=r"(t));
return t;
#elif defined(__APPLE__)
return GetMachTime();
#else // we don't want to use a slow generic solution
# error "Sorry, LinuxSampler lacks time stamp code for your system."
# error "Please report this error and the CPU you are using to the LinuxSampler developers mailing list!"
#endif
}



Thanks
-(e)
 
You could read the hardware timers of OMAP3, but that would be discouraged, as it could change between firmware versions.

Your best bet therefore (since there is no cpu specific function I know of) is gettimeofday()

Later 2.6.x kernels have high resolution timer patches, but I don't know if these will be present on the Pandora.
 
Squidge said:
You could read the hardware timers of OMAP3, but that would be discouraged, as it could change between firmware versions.

Your best bet therefore (since there is no cpu specific function I know of) is gettimeofday()

Later 2.6.x kernels have high resolution timer patches, but I don't know if these will be present on the Pandora.
Thanks for the info I'm not sure if gettimeofday() is going to be fine enough, but I'll check it out.

mru on irc suggested that CCNT Register might be a possibility, however at this point I do not know how to access this from usermode. Is there a linux specific way of setting the User Enable Register so that i can change CCNT access to user. Would I want to do that, or rather get into supervisor mode and read the register and if so, how?

Lots of questions, sorry :)
-(e)
 
Last edited by a moderator:
To read the CCNT you probably need to use a kernel module, so it's not that practical.

What does the program use the timestamp for, and why? If you can find out that, maybe we can devise a suitable function from what we have.
 
Squidge said:
To read the CCNT you probably need to use a kernel module, so it's not that practical.

What does the program use the timestamp for, and why? If you can find out that, maybe we can devise a suitable function from what we have.
The program is an audio sampler program, effectively the software equivalent of an Akai HW sampler box or similar.

The timestamp AFAIK is used for the mixing and output of the audio samples in a timeous manner.
i.e. audio buffer calculation, latency etc. is going to be run off the timestamp (along with MIDI sync etc) and hence the need for fast, high resolution.

-(e)
 
Last edited by a moderator:
I remember on the Z80 you had a register which counted clock ticks (or was it fetches?) which you could use for stuff like this. Don't ARMs have some kind of counter register you could make use of?
 
SteveM said:
I remember on the Z80 you had a register which counted clock ticks (or was it fetches?) which you could use for stuff like this. Don't ARMs have some kind of counter register you could make use of?
Yes, the Cycle Counter Register, but it is accessible only in privileged mode.
 
Last edited by a moderator:
Back
Top