1

i need to access the cpu idle time for every one minute from a linux kernel module and print it to kern.log so that i can plot a graph for statistics. Please help.

Thanks in advance.

priya
  • 11
  • 1

1 Answers1

0

You don't need to write a kernel module for that, that information is already provided in /proc/stat:

$ awk ' /^cpu/ { print $1, $5 / 100; } ' /proc/stat
cpu 251908
cpu0 63149.6  <--- Total IDLE time in seconds 
cpu1 62053.2
...

Where 100 is USER_HZ constant (100 on most systems).

If you still wish to write kernel module, than you can re-use /proc/stat code from here: fs/proc/stat.c.

myaut
  • 11,174
  • 2
  • 30
  • 62