从代码中获取像 /proc/interrupts 这样的中断计数器?
我可能会错过显而易见的事情,但是如何/是否可以在不从 C/C++ 程序内部手动解析 /proc/interrupts
的情况下检索特定中断的中断计数器?
提前致谢!
最好的问候,马丁
I may miss the obvious, but how/is it possible to retrieve interrupt counters for a specific interrupt without manually parsing /proc/interrupts
from inside a C/C++ program?
Thanks in advance!
Best regards, Martin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
/proc/interrupts
和/proc/stat
通过调用内核函数kstat_irqs_cpu()
获取其数据。我认为,在不打开 /proc 中的文件的情况下读取它的唯一方法是编写自己的内核驱动程序,该驱动程序将调用相同的函数并通过 ioctl() 或其他方式返回结果。/proc/interrupts
and/proc/stat
obtain their data by calling the kernel functionkstat_irqs_cpu()
. The only way to read it without opening the files in /proc is, I think, writing your own kernel driver which would call the same function and return the results via ioctl() or some other way.在 Linux 上,
/proc
中的文本文件是它们提供的大部分信息的规范用户上下文接口。无论好坏,解析该文本文件都是实现这一点的方法。On Linux, the text files in
/proc
are the canonical user-context interface for most of the information they provide. For better or worse, parsing that text file is the way to do it.我做了一些快速检查,似乎此信息没有镜像到 /sys 下的任何位置,也没有列出任何看起来允许访问此信息的系统调用号,因此 /proc 文件可能是唯一的位置可见的。
您还应该注意,该格式是特定于体系结构的,有时是特定于内核配置的;这些行由函数 show_interrupts 生成,该函数通常在每个体系结构子目录中的 kernel/irq.c 中定义(例如 arch/x86/kernel/irq.c、arch/s390/kernel/irq.c)。因此,您可能必须非常小心地进行解析(或者将检查列入白名单,以仅在您能够测试它的架构上解析文件)。
I did some quick checking and it doesn't appear this information is mirrored anywhere under /sys, nor are there any listed syscall numbers which look like it would allow access to this information, so the /proc file is probably the only place it is visible.
You should also be aware that the format is architecture and sometimes kernel configuration specific; the lines are produced by the function show_interrupts, which is usually defined in kernel/irq.c within each architecture subdirectory (eg arch/x86/kernel/irq.c, arch/s390/kernel/irq.c). So you'll probably have to be pretty careful with the parsing (or alternately whitelist the check to only parse the file on architectures you've been able to test it on).