Finding the exact Time Value for the Computer Programs with the aid of Kernel Timers
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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".
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.