从代码中获取像 /proc/interrupts 这样的中断计数器?

发布于 2024-09-18 12:13:56 字数 127 浏览 4 评论 0原文

我可能会错过显而易见的事情,但是如何/是否可以在不从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

垂暮老矣 2024-09-25 12:13:56

/proc/interrupts/proc/stat 通过调用内核函数 kstat_irqs_cpu() 获取其数据。我认为,在不打开 /proc 中的文件的情况下读取它的唯一方法是编写自己的内核驱动程序,该驱动程序将调用相同的函数并通过 ioctl() 或其他方式返回结果。

/proc/interrupts and /proc/stat obtain their data by calling the kernel function kstat_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.

那小子欠揍 2024-09-25 12:13:56

在 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.

执手闯天涯 2024-09-25 12:13:56

我做了一些快速检查,似乎此信息没有镜像到 /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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文