C++ Accurate timing on BeagleBoard running Ångström

Hello.

I have to time some very small functions in a C++ program running on
the BeagleBoard which I need to time very accurate.
Due to the nature of the functions, running them n times in a loop and
dividing total time by n is not the best option.
I have tried both clock() (too coarse) and clock_gettime().

The latter is supposed to give ns precision ( i know this is hardware
dependent), but only gives results in multiples of about 30500 ns.

Is there an easy way to get close to ns precision without recompiling
the kernel?
Is it possible to access the CPU tick registers in C or asm?

Thank you.

By default, the kernel scheduling policy timer is configured to 250 Hz; which means that you have to expect as much as 4ms in delay due to the fact that the kernel is non-preemptive. It is also a function of the number of processes running on your system and their priority levels since it is based on a cooperative scheduling policy. Trying to get ns/uc precision in a user space application is impossible without changing the scheduling policy, and again it does not guarantee that precision level, since the best RESPONSIVE setting for the scheduler is 1000HZ; again, you’d loose performance if you change that parameter.

consider patching the kernel with REAL-TIME patch, and it would bring your maximum expected latency down to <100uS. What are you trying to do, why need this kind of precision in your app?

here is a chart depicting expected latency in kernel space/user space: http://bootloader.wikidot.com/linux:android:latency . It should give you a pretty good idea on this topic.

good luck,

-toan