How to measure performance inside Kernel?

Jeff Haran jharan at bytemobile.com
Fri Feb 10 17:06:07 EST 2012


> -----Original Message-----
> From: kernelnewbies-bounces at kernelnewbies.org [mailto:kernelnewbies-
> bounces at kernelnewbies.org] On Behalf Of Peter Senna Tschudin
> Sent: Friday, February 10, 2012 1:48 PM
> To: kernelnewbies at kernelnewbies.org
> Subject: Re: How to measure performance inside Kernel?
> 
> Dear list,
> 
> As Michi suggested, I did some testing with ktime.h, but I found a
> simpler solution with time.h.
> 
> I'm not sure if it is correct, and I would like to have some help...
:-)
> 
> The code that I'm using for execution time measurement is:
> 
> #include <linux/time.h>
> 
> getnstimeofday (ts_start); /*stopwatch start*/
> 
> for (i = 0; i < q->num_buffers; ++i)
> 	q->bufs[i]->state = VB2_BUF_STATE_DEQUEUED;
> 
> 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?
> 
> The full module code is at: http://goo.gl/cCMIa
> 
> Thank you!
> 
> Peter

If you didn't disable interrupts before executing the above, the timing
of the above loop would include any time spent servicing interrupts.
Likewise if there were context switches or soft IRQs running. All would
inflate the perceived time to execute your loop.

Jeff Haran






More information about the Kernelnewbies mailing list