views:

67

answers:

3

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

+4  A: 

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.

llasram
+2  A: 

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

Jack Lloyd
+2  A: 

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

Cubbi
Thanks, this seems to be the most stable approach to what I want to achieve. I am fixed on a single architecture, so I _could_ in theory test out the parsing of /proc/interrupts, but this seems more stable to me (but of course more complex :)).
Martin C.