LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-01-2013, 06:24 AM   #1
$u$hil_k$
LQ Newbie
 
Registered: Jan 2012
Posts: 23

Rep: Reputation: Disabled
Finding the exact Time Value for the Computer Programs with the aid of Kernel Timers


Hello Guys, Basicaaly i am working no finding the exact time which is taken by a particular program or a sort of algorithm when executed....Although there are many inbuilt funtions for calculating for example : ( endvalue - startvalue ) / CLKS_PER_SEC
it doesn't give the exact value when executed by the processeor, in other words if there are 3 processes interleaved in the short term sheduler queue the above method gives me the time where in it includes the time slices of the other processes also the best example would be the turn around time of a Round Robin Scheduling Algorithm for 3 processes . Now my requirement is say suppose i want to mesure the execution time of a process 1 then i should get only its amount of time spent for execution with the processor not the other 2 processes time slices added with it, i heard using or setting kernel timers we can achive this so any one out there ready to help me with that?
 
Old 02-01-2013, 06:26 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I guess you need to read these http://www.linuxtopia.org/online_boo...nel_index.html
 
Old 02-01-2013, 02:46 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
It kind of depends on what you are actually looking for. If you want the CPU time a process takes, you can always install some process accounting, and get the pacct file that has that time.

If you are trying to time a function of a program (different subject) then you need to use the library function "clock" - which reports the CPU time used (man 3p clock). To use it to time a (quick) function, you get the cpu time when you start, then call the function 100 times, get the CPU time again - subtract first from the second, divide by 100. Use different iterations depending on the rough time it takes the function to run.

Another and better reference should be "info clock".

Last edited by jpollard; 02-01-2013 at 02:48 PM.
 
Old 02-01-2013, 03:26 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Your not going to get exact timings - for anything. Taking the measurement influences the environment. And possibly displaces the process being timed from the CPU it was running on.
For a reproducible environment, I'd disable hiper-threading and use cgroups to isolate the process to a particular CPU (no competing non-kernel processes). Run it enough times to get a reasonable average.
 
Old 02-01-2013, 05:54 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by syg00 View Post
Your not going to get exact timings - for anything. Taking the measurement influences the environment. And possibly displaces the process being timed from the CPU it was running on.
For a reproducible environment, I'd disable hiper-threading and use cgroups to isolate the process to a particular CPU (no competing non-kernel processes). Run it enough times to get a reasonable average.
That can happen.. but the kernel does switch counters when the process is idled for that purpose. The largest impact comes from short kernel interrupts - the counters don't get switched for those (it can take longer to switch the counters than it takes to service the interrupt).

Hyper-threading and cgroups will do nothing to change that. What it does affect is the elapsed time at test is running.
 
  


Reply

Tags
kernel, setting, timer



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
[SOLVED] Finding the Big and Exact Match of Sample Data hamijami Programming 20 05-31-2012 02:07 AM
How to make exact computer disk image? k-kid Linux - General 2 02-04-2005 10:44 AM
Time to mix some special REDHAT 9 (kool-aid) caleb star Linux - Newbie 10 12-29-2003 05:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:24 PM.

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