简体   繁体   English

从linux内核模块访问cpu信息

[英]accessing cpu information from linux kernel module

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. 我需要从Linux内核模块访问每分钟的CPU空闲时间,并将其打印到kern.log,以便可以绘制统计图。 Please help. 请帮忙。

Thanks in advance. 提前致谢。

You don't need to write a kernel module for that, that information is already provided in /proc/stat : 您无需为此编写内核模块,该信息已在/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). 其中100是USER_HZ常数(在大多数系统上为100)。

If you still wish to write kernel module, than you can re-use /proc/stat code from here: fs/proc/stat.c . 如果仍然希望编写内核模块,则可以从以下位置重复使用/proc/stat代码: fs / proc / stat.c。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM