How to measure performance inside Kernel?

michi1 at michaelblizek.twilightparadox.com michi1 at michaelblizek.twilightparadox.com
Sat Feb 11 02:22:33 EST 2012


Hi!

On 19:47 Fri 10 Feb     , Peter Senna Tschudin wrote:
...
> #include <linux/time.h>
> 
> getnstimeofday (ts_start); /*stopwatch start*/
...
> getnstimeofday (ts_end); /*stopwatch stop*/
> 
> diff = timespec_sub(end, begin);
> 
> printk ("%lu,", diff.tv_nsec );
> 
> Am I doing anything wrong? Can mysterious stuff like out of order
> execution engine, brake the stopwatch?

Why don't you print the tv_sec part?

You might also want to replace getnstimeofday with getrawmonotonic or any
other monotonic time source. If ntp or something else decides to change system
time during the measurement, you would probably get weird results.

	-Michi
-- 
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com



More information about the Kernelnewbies mailing list