LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-25-2009, 10:45 AM   #1
10110111
Member
 
Registered: Jun 2008
Location: St.-Petersburg, Russia
Distribution: (B)LFS, Ubuntu, SliTaz
Posts: 403

Rep: Reputation: 51
How to accurately measure time intervals?


I have some machines on which glxgears seems to work very strangely: it turns the gears for very little angles for some time (typically for 0.5 seconds), then the angle is burst changed, and again slow, and so on. At first look it seemed to just show about 0.5 fps, while console output said about 300FPS. But, when i commented "#define BENCHMARK" out in glxgears source, i got normal turning, though with wrong speed. So, i put printf("%lf",dt) in every frame output code, and got that the time difference looked like about 200 times of 0.000015 seconds, then 0.45xxxx seconds, then again those little numbers, and so on, which resulted in incorrect turning speed. So, is it a kernel bug in gettimeofday, or something else? What function is better to use to accurately measure time?
 
Old 07-26-2009, 06:59 AM   #2
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 237

Rep: Reputation: 22
Linux is a multitasking system, so the kernel (initd) has also compute time and checks the system and also the other damons and threads.
A faster CPU, faster main memory,... can minimize that break, also less installed damons and running apps.

The delay times and the deviation seems normal to me.
 
Old 07-29-2009, 02:45 PM   #3
10110111
Member
 
Registered: Jun 2008
Location: St.-Petersburg, Russia
Distribution: (B)LFS, Ubuntu, SliTaz
Posts: 403

Original Poster
Rep: Reputation: 51
>The delay times and the deviation seems normal
Yes, it is normal. But the problem is not in delays - it is in measurement. glxgears calls gettimeofday with almost equal intervals (really - i checked and didn't see any bursts like 0.5 sec), i.e. computed delay should be about 1/200 of a second instead of 0.000015 sec, and is seen on machines which work right. Also, there is almost no process activity except of glxgears on these machines, and result is fully reproducible. It seems that the measurement is made in some strange way or gettimeofday is not the function to rely on for accurate measurement.
 
Old 07-30-2009, 05:34 PM   #4
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 237

Rep: Reputation: 22
In short:
Systemcheck is done 1/4 on older 1/3 second on newer kernels by default.
Each delay shorter than those will have a break. Because shorter delays are done by a software PLL that has also a break.
HPET/DMA and RTC/Timer can solve that break, but have to be programmed directly without system support. And they are also system dependend, so there can't be a standard library in c, c++ to support them.
Gears is an example and can only uses std-libs, to run on many computers as possible.
So you can even say that this is a hardware bug.
On RT- and multiprosessor-systems you won't see or detect such a break.
OpenGL is the answer to that hardware bug - it is also a multi-processor system, because it runs on the second processor called GPU.
So Gears with OpenGL support won't have that break and will turn very smoothly.
To mesure delays there is only one way:
Programming a timer RTC/IRQ or HPET/DMA directly.
Additional information:
Writing or reading to/from a RTC port takes allways 1/1000000 second.
Debugging times on a multitasking system exactly isn't possible.

Last edited by bastl; 07-30-2009 at 06:04 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Measure Time in Linux with Time Base LXer Syndicated Linux News 0 04-11-2007 06:46 AM
Splitting audio files at specific time intervals quickfix Linux - Software 2 08-26-2005 07:18 AM
Can I somehow accurately measure the time a operation takes? Like 'unzip -x foo.zip'? brynjarh Linux - Newbie 9 08-18-2004 09:26 PM
accurately measure time rasselin Programming 1 09-05-2003 05:18 PM
how to accurately measure processing time rasselin Programming 3 09-01-2003 11:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration