LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Finding the exact Time Value for the Computer Programs with the aid of Kernel Timers (https://www.linuxquestions.org/questions/linux-newbie-8/finding-the-exact-time-value-for-the-computer-programs-with-the-aid-of-kernel-timers-4175448140/)

$u$hil_k$ 02-01-2013 06:24 AM

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?

chrism01 02-01-2013 06:26 AM

I guess you need to read these http://www.linuxtopia.org/online_boo...nel_index.html

jpollard 02-01-2013 02:46 PM

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".

syg00 02-01-2013 03:26 PM

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.

jpollard 02-01-2013 05:54 PM

Quote:

Originally Posted by syg00 (Post 4882570)
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.


All times are GMT -5. The time now is 06:01 AM.