Get jiffies?

This is a discussion on Get jiffies? within the Linux Programming forums, part of the Platform Specific Boards category; Hi, is it possible to get the current jiffies value with a program running in userspace? I found some source ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    15

    Get jiffies?

    Hi,

    is it possible to get the current jiffies value with a program running in userspace?
    I found some source code on the net using "#include <linux/jiffies.h>", but I don't have a /usr/include/linux/jiffies.h file on my system. Although there is a /usr/src/linux/include/linux/jiffies.h file that will generate lots of compiler errors when included:
    Code:
    /usr/src/linux/include/linux/jiffies.h:75: error: expected ‘,’ or ‘;’ before ‘jiffies_64’
    /usr/src/linux/include/linux/jiffies.h:79: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘get_jiffies_64’
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:225:31: error: division by zero in #if
    /usr/src/linux/include/linux/jiffies.h:274: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jiffies_to_clock_t’
    /usr/src/linux/include/linux/jiffies.h:276: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘jiffies_64_to_clock_t’
    /usr/src/linux/include/linux/jiffies.h:277: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘nsec_to_clock_t
    So is there a way to get the jiffies or am I doing something completely wrong?

    Peter

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,648
    Why do you want jiffies in user space? Do you need a timer?

    gg

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    15
    Yes, I need a timer for CPU frequency calculation - in my first try I used the TSC which works quite good, but does not work if running on a tickless Linux kernel because the TSC becomes unstable (disabled when CPU is in sleep states).
    The jiffies should do the trick although they don't tick periodically but AFAIK they get set to the value they should have if ticking periodically with every interrupt or cpu wakeup.
    The TSC just ticks while the cpu is running and does not get set to the value it should have on a non-tickless system on wakeups.

    Peter

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,648
    You can use gettimeofday for the timer....
    Or parse /proc/cpu for the CPU frequency.

    gg

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    15
    gettimeofday won't do me any good because it will only tell me what time it is or with a delta how much time has passed - I need a timer that counts the ticks of the CPU as well to calculate the CPU frequency.

    And because the TSC won't count CPU ticks on tickless systems the jiffies are the only way I can think of besides the TSC.
    Reading /proc/cpuinfo would be quite a trivial solution, so if possible, I want to avoid it.

    Is there no way to read the jiffies from userspace?

    Peter

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,648
    jiffies is just a counter of clock interrupts, and the number of clock interrupts per second is a kernel compile-time constant. It can't be used alone to calculate CPU freq.

    You can use it as a relative timer, just like gettimeofday() - but there's no access from user space that I know of.

    >> so if possible, I want to avoid it
    Why are you avoiding the easiest, and probably most correct solution? For fun ?

    gg

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by pgzh View Post
    And because the TSC won't count CPU ticks on tickless systems the jiffies are the only way I can think of besides the TSC.
    I'm with Codeplug on why you don't want to just read /proc/cpuinfo... But if you insist on producing a timing using the TSC, why not just fire up a little helper process which does an infinite loop, to prevent the processor from going into a sleep state? Then you can actually use the TSC for something. Of course on an SMP system this doesn't guarantee that you'll actually peg the processor. But on an SMP system reading the TSC is basically undefined anyway since you have no idea which CPU you are executing on. You could even switch in the middle of your computation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. interesting problem
    By RoshanX in forum C Programming
    Replies: 14
    Last Post: 02-26-2006, 06:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21