Find the answer to your Linux question:
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.
  1. #1
    Just 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?

  2. #2
    Just 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!!

  3. #3
    Just 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").

  4. $spacer_open
    $spacer_close
  5. #4
    Just 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!

  6. #5
    Just 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.'

  7. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,709
    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!

  8. #7
    Just 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?

  9. #8
    Just Joined!
    Join Date
    Dec 2009
    Posts
    9
    sleep funtion in kernel is : msleep, //delay.h

  10. #9
    Just 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.


  11. #10
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,709
    Try the mdelay(unsigned long ms) macro/inline function. It is defined in delay.h which has (on my RHEL/CentOS system) this comment:
    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.
     */
    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.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •