Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 06-04-2012, 01:50 AM   #1
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..

Old 06-05-2012, 01:09 PM   #2
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,799
Blog Entries: 4

Rep: Reputation: 3081Reputation: 3081Reputation: 3081Reputation: 3081Reputation: 3081Reputation: 3081Reputation: 3081Reputation: 3081Reputation: 3081Reputation: 3081Reputation: 3081
"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."


kernelmodule, time, userspace

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:10 AM
Taking keyboard driver from userspace to kernel space. sunr2007 Linux - Kernel 0 05-15-2009 05:25 AM
how to calculate time difference in milliseconds in C/C++ waqasdaar Programming 19 03-17-2009 05:02 PM
Can we register a userspace funtion as a callback to kernel space? duyuyang Linux - Kernel 0 12-20-2008 01:24 AM
calculate time difference between 2 formatted timestamps nickleus Linux - General 3 05-12-2006 11:08 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:43 AM.

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