Hi,
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
Hi,
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
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.
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).
/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.