Results 1 to 10 of 10
I'm getting
"warning: implicit declaration of function 'sleep' and 'rand'.
How can I track elapsed time (seconds, or milliseconds) in the kernal?
And generate psuedorandom #'s?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-01-2010 #1Just Joined!
- Join Date
- Jan 2010
- Location
- The Sillicon Valley, California
- Posts
- 28
how is 'sleep()' and rand() done in kernel module?
I'm getting
"warning: implicit declaration of function 'sleep' and 'rand'.
How can I track elapsed time (seconds, or milliseconds) in the kernal?
And generate psuedorandom #'s?
- 02-01-2010 #2Just Joined!
- Join Date
- Jul 2009
- Posts
- 49
time functions in the kernel
You want to look at the file kernel/time.c and in it you will find the various time functions available. They are usually centered around the "jiffie" which is the number of clock ticks since the system came up. There are all sorts of conversion functions like jiffies_to_timeval() jiffies_to_msec() etc...
Generating random numbers... you are on your own.
Cheers!!
- 02-01-2010 #3Just Joined!
- Join Date
- Jan 2010
- Location
- The Sillicon Valley, California
- Posts
- 28
Thanks.
These days, I have found that building a wrapper function a:
float elapsed_seconds( jiffies );
saves lots of development time, and reduces coding complexity substantially.
My client has a demo deadline this week, and I must get TCP and this other stuff running in the client's kernel module, where lives their app (don't ask me why -- "the customer is always right").
- 02-01-2010 #4Just Joined!
- Join Date
- Jul 2009
- Posts
- 49
The customer...
In fact, the real quote is:
"The customer is never wrong"
Which actually means something quite different.
Good Luck!
- 02-01-2010 #5Just Joined!
- Join Date
- Jan 2010
- Location
- The Sillicon Valley, California
- Posts
- 28
I'm an optimist -- I never use the word 'wrong' in same breath as 'customer.'
- 02-01-2010 #6Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,141
Actually, I think the quote should be "The customer is an idiot, but it never pays to let them know that."...
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 02-01-2010 #7Just Joined!
- Join Date
- Jan 2010
- Location
- The Sillicon Valley, California
- Posts
- 28
it's defined in asm-powerpc/time.h
Anyone already have any experience, or wrapper functions for this?
- 02-05-2010 #8Just Joined!
- Join Date
- Dec 2009
- Posts
- 9
sleep funtion in kernel is : msleep, //delay.h
- 02-07-2010 #9Just Joined!
- Join Date
- Jan 2010
- Location
- The Sillicon Valley, California
- Posts
- 28
The module fails to load for lack of a symbol when msleep() is used.
- 02-07-2010 #10Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,141
Try the mdelay(unsigned long ms) macro/inline function. It is defined in delay.h which has (on my RHEL/CentOS system) this comment:
In any case, when doing kernel-level coding, reading the headers is generally "a good thing" since they will help with comments/documentation like this, and they do change significantly depending upon the kernel you are using.Code:/* * Using udelay() for intervals greater than a few milliseconds can * risk overflow for high loops_per_jiffy (high bogomips) machines. The * mdelay() provides a wrapper to prevent this. For delays greater * than MAX_UDELAY_MS milliseconds, the wrapper is used. Architecture * specific values can be defined in asm-???/delay.h as an override. * The 2nd mdelay() definition ensures GCC will optimize away the * while loop for the common cases where n <= MAX_UDELAY_MS -- Paul G. */
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
