From mboxrd@z Thu Jan 1 00:00:00 1970 From: michi1@michaelblizek.twilightparadox.com (michi1 at michaelblizek.twilightparadox.com) Date: Sat, 11 Feb 2012 08:22:33 +0100 Subject: How to measure performance inside Kernel? In-Reply-To: References: Message-ID: <20120211072232.GA2232@grml> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org Hi! On 19:47 Fri 10 Feb , Peter Senna Tschudin wrote: ... > #include > > 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