LinuxQuestions.org
Help answer threads with 0 replies.
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 06-04-2012, 12:50 AM   #1
sindhu4sind
Member
 
Registered: Apr 2012
Posts: 38

Rep: Reputation: Disabled
How to get Kernel space time and compare to userspace to calculate difference?


Hello Everyone,

I have implemented kernel module and a userspace app, I want to do following with that:

1. Get the time on kernel module during execution of a function
2. transfer that time to userspace (if using ioctl, then its fine i can do this)
3. get the time of userspace
4. calculate time difference in between userspace and kernel space.

can anyone please suggest me how to do this? what are the functions i can use to do this? If any example then it can save my time.
Thanks for always good response..

Rahee.
 
Old 06-05-2012, 12:09 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
"Time" is "Time."

Any "difference in time" is therefore going to be "merely a coincidence." "A trick of chance." The unpredictable amount of time that is consumed by the kernel-to-user transition on your particular hardware. In other words, "not a valuable number."

Also remember that, in order to get the time "in userspace," it's possible that a transition to kernel-mode and back could occur (and if it does occur, "for no good reason"). In other words, your result would be highly "tainted" no matter how you got it.

My recommendation: "simply measure the time-interval from user-space only." Yes, the result you will obtain is "fuzzed" by the fact that you're user-space, but then again, so is everything else that you do in user-space! (Indeed, the result could be "fuzzed" quite considerably, given the reality that you are not the only user-land process that might be running on this particular system at this particular time.) Instead of trying to measure that "fuzz," given that every measure of such things that you may deign to take will undoubtedly be different, simply "bill it off to overhead."

If what you are interested in measuring is "the time as perceived by a user-land program, then measure that time and nothing else. Now, measure it (say...) 10,000 times and take the average. The result that you will thus obtain is a "boots-on-the-ground, pragmatic, usable answer that you can run with."
 
  


Reply

Tags
kernelmodule, time, userspace



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] copy_from/to_user how to use it simply to get pid into kernel space from userspace? sindhu4sind Linux - Newbie 3 05-24-2012 04:10 AM
Taking keyboard driver from userspace to kernel space. sunr2007 Linux - Kernel 0 05-15-2009 04:25 AM
how to calculate time difference in milliseconds in C/C++ waqasdaar Programming 19 03-17-2009 04:02 PM
Can we register a userspace funtion as a callback to kernel space? duyuyang Linux - Kernel 0 12-20-2008 12:24 AM
calculate time difference between 2 formatted timestamps nickleus Linux - General 3 05-12-2006 10:08 PM

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

All times are GMT -5. The time now is 02:54 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