Get jiffies? [Archive] - C Board

PDA

View Full Version : Get jiffies?


pgzh
03-15-2008, 05:54 PM
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:
/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

Codeplug
03-15-2008, 06:23 PM
Why do you want jiffies in user space? Do you need a timer?

gg

pgzh
03-15-2008, 07:41 PM
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

Codeplug
03-15-2008, 08:10 PM
You can use gettimeofday for the timer....
Or parse /proc/cpu for the CPU frequency.

gg

pgzh
03-15-2008, 08:17 PM
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

Codeplug
03-15-2008, 11:29 PM
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

brewbuck
03-17-2008, 10:30 AM
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.